akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include <cmath>
#include <limits>
#include<set>
#include <iomanip>
#include <queue>
#include <map>
#include <string>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
const long long INF=200000000000000;
const double inf=pow(10,10);
double pi=3.141592653589793;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const ll MOD = 1000000007;
void init(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout<<fixed;
}
	
int main(){
	init();
	ll N,K;
	cin>>N>>K;
	vector<pair<ll,ll>>v(N);
	for(int i=0;i<N;i++){
		ll a,b;
		cin>>a>>b;
		v[i]=make_pair(a,b);
	}
	sort(v.begin(),v.end());
	ll sum=0;
	for(int i=0;i<N;i++){
		sum+=v[i].second;
		if(K<=sum){
			cout<<v[i].first<<endl;
			return 0;
		}
	}
}


Measured memory_bytes: 1792
def main():
    mod = 10**9+7
    #n,a = get_input()
    n = int(input())
    a = [int(x) for x in input().split()]
    aa = [x**2 % mod for x in a]
    ans = 0
    asum = sum(a) 
    p = asum ** 2 % mod
    q = sum(aa) % mod
    ans = (p - q) % mod
    if ans < 0:
      ans += mod
    if ans % 2 == 1:
      ans += mod
    ans = ans // 2
    print(ans)
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 31452
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cmath>
#include<string>
#include<numeric>
#include<algorithm>
#include<limits.h>
#include<utility>
#define lp(i,n) for(int i=0;i<n;i++)
#define lpin(i,n,a) for(int i=0;i<n;i++)cin >> a[i]
using namespace std;

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    cout << (c / a) * b << endl;
    return 0;
}

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

#ifdef LOCAL
#include "dump.hpp"
#else
#define dump(...)
#define dumpv(...)
#endif

#define rep(i, n) for (int i = 0; i < (n); i++)
#define mins(x, y) (x = min(x, y))
#define maxs(x, y) (x = max(x, y))
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using P = pair<int, int>;
const int MOD = 1e9 + 7;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;

void solve() {
  int x;
  cin >> x;
  int d = 0;
  int ans = 0;
  rep(i, 360*180) {
    d = (d + x) % 360;
    dump(d);
    if (d == 0) {
      ans = i + 1;
      break;
    }
  }
  cout << ans << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  // freopen("temp.1", "r", stdin);
  solve();
  return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using Graph = vector<VecP>;
template <typename T>
using Vec1 = vector<T>;
template <typename T>
using Vec2 = vector<Vec1<T> >;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for(ll (i) = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m)-1; (i) >= (n); --(i))
#define REPNR(i, m, n) for(ll (i) = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}
template <typename T>
ll pow2(const T n){return (1LL << n);}
template <typename T>
void cosp(const T n){cout << n << ' ';}
template <typename T>
void co(const T n){cout << n << '\n';}
template <typename T1, typename T2>
void co(pair<T1, T2> p){cout << p.fs << ' ' << p.sc << '\n';}
template <typename T>
void co(const Vec1<T> &v){for(T i : v) cosp(i); cout << '\n';}
template <typename T>
void co(initializer_list<T> v){for(T i : v) cosp(i); cout << '\n';}
template <typename T>
void ce(const T n){cerr << n << endl;}
void sonic(){ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
const ll INF = 1e9+1;
const ll LINF = 1e18+1;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ld PI = acos(-1);
const ld EPS = 1e-11;

Vec fac, finv;

ll PowMod(ll a, ll n){
    if(n == 1) return a;
    if(n%2 == 0) return PowMod(a*a%MOD, n/2);
    return a*PowMod(a*a%MOD, n/2)%MOD;
}

ll combi(ll n, ll k){
    if(k>n) return 0;
    return fac[n]*finv[k]%MOD*finv[n-k]%MOD;
}

int main(){
    sonic();
    ll n;
    int ans = 0;
    cin >> n;
    unordered_map<int, ll> ump;
    rep(i, n){
        int a;
        cin >> a;
        ump[a]++;
    }
    for (auto x: ump) if (x.second % 2) ans ++;
    cout << ans;
}



Measured memory_bytes: 4388
#include<cstdio>
#include<string>
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

struct edge{
	int to;
	string str;
	edge(){}
	edge(int a,string b):to(a),str(b){}
};

vector<edge> G[44];

string dp[44][600];
bool exi[44][600];

int main(){
	while(true){
		int N,E,S,T;
		cin>>N>>E>>S>>T;
		if(N==0) break;
		for(int i=0;i<N;i++){
			G[i].clear();
			for(int j=0;j<600;j++){
				dp[i][j]="";
				exi[i][j]=false;
			}
		}
		for(int i=0;i<E;i++){
			int a,b;
			string c;
			cin>>a>>b>>c;
			G[a].push_back(edge(b,c));
		}
		exi[S][0]=true;
		for(int l=0;l<600;l++) for(int v=0;v<N;v++){
			if(exi[v][l]==false) continue;
			for(int i=0;i<G[v].size();i++){
				int nv=G[v][i].to;
				string str=G[v][i].str;
				string nstr=dp[v][l]+str;
				int nl=nstr.size();
				if(nl>600) continue;
				if(exi[nv][nl]==false||dp[nv][nl]>nstr){
					dp[nv][nl]=nstr;
					exi[nv][nl]=true;
				}
			}
		}
		string ans="";
		for(int i=1;i<=240;i++){
			if(exi[T][i]==false) continue;
			if(ans==""||ans>dp[T][i]) ans=dp[T][i];
		}
		bool ok=true;
		for(int i=241;i<600;i++){
			if(exi[T][i]==false) continue;
			if(ans>dp[T][i]) ok=false;
		}
		if(ok==false||ans=="") cout<<"NO\n";
		else cout<<ans<<"\n";
	}
	return 0;
}

Measured memory_bytes: 14176
import math

A,B,H,M = map(int, input().split())

degH = H*360/12 + M*360/12/60
degM = M*360/60

angle = abs(degH-degM)

dist = (A**2 + B**2 - 2*A*B * math.cos(math.radians(angle)))**(1/2)

print(dist)

Measured memory_bytes: 9500
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long n,cnt=1,x=0;
  cin >> n;
  long long a[n],b[2];
  for(long long i=0;i<n;i++){
  	cin >> a[i];
  }
  sort(a,a+n);
  reverse(a,a+n);
  for(long long i=0;i<n;i++){
  	if(a[i]==a[i+1]){
  		cnt++;
  	}else{
  		if(cnt>=2){
  			if(cnt>=4&&x==0){
  				cout << a[i]*a[i] << endl;
  				return 0;
  			}else if(cnt<4||(cnt>=4&&x==1)){
  				b[x]=a[i];
  				if(x==1){
  					cout << b[0]*b[1] << endl;
  					return 0;
  				}
  				x++;
  			}
  		}
  		cnt=1;
  	}
  }
  cout << 0 << endl;
  return 0;
}


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

int main(){
  int A, B, C;
  cin >> A >> B >> C;
  string yorn = "No";
  if(A == B){
    if(A == C) yorn = "No";
    else yorn = "Yes";
  }
  else if(A == C) yorn = "Yes";
  else if(B == C) yorn = "Yes";
  cout << yorn << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define mod 998244353
#define fi first
#define se second
#define mp make_pair
using ll=long long;

ll power(ll n,ll m)
{
    ll ans=1;
    for (int r=0;m>>r>0;r++)
    {
        if ((m>>r)&1) ans=ans*n%mod;
        n=n*n%mod;
    }
    return ans;
}

int main()
{
    int N,S;cin >> N >> S;
    vector<int> A(N);
    for (int i=0;i<N;i++)
    {
        cin >> A[i];
    }
    vector<vector<ll>> dp(N+1,vector<ll> (S+1,0)); 
    dp[0][0]=1;
    for (int i=1;i<N+1;i++)
    {
        for (int j=0;j<S+1;j++)
        {
            if (j-A[i-1]>=0)
            {
                dp[i][j]+=dp[i-1][j-A[i-1]];
                dp[i][j]%=mod;
            }
            dp[i][j]+=2*dp[i-1][j];
            dp[i][j]%=mod;
        }
    }
    cout << dp[N][S]%mod << endl;
    
    return 0;
}

Measured memory_bytes: 73588
#include <iostream>
#include <stdio.h>
#include <set>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <bitset>

typedef long long int lli;
#define rep(i,s,N) for(int i=s;i<N;i++)
#define MOD 1000000007
using namespace std;


int main(void)
{
	lli X; cin >> X;
	int ans = 0;
	while (X > 0) {
		ans++;
		X -= ans;
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>

using namespace std;
typedef long long ll;
#define rep(i, s, e) for (int(i) = (s); (i) <= (e); ++(i))
#define all(x) x.begin(),x.end()


int main()
{
	int n, k; cin >> n >> k;
	ll mCount, hCount;
	ll res;
	mCount = n / k;
	if (k % 2 == 1)
	{
		res = pow(mCount, 3);
		cout << res << endl;
		return 0;
	}
	hCount = (n + k / 2) / k;
	res = pow(mCount, 3) + pow(hCount, 3);
	cout << res << endl;
}

Measured memory_bytes: 384
// Aizu Vol0 0013: Switching Railroad Cars
// 2017.7.28

#include <stdio.h>

#define MAX 100

int main()
{
	int n;
	int stack[MAX + 5], top;
	
	top = 0;
	while (scanf("%d", &n) == 1) {
		if (n == 0) printf("%d\n", stack[--top]);
		else stack[top++] = n;
	}
	return 0;
}

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

int main() {
  int H,W;
  cin >> H >> W;
  
  string l = "##";
  for(int i = 0; i < W; i++){
    l += "#";
  }
  
  cout << l << endl;
  
  vector<string> line(H);
  for(int i = 0; i < H; i++){
    cin >> line.at(i);
    cout << "#" << line.at(i) << "#" << endl;
  }
  
  cout << l << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int abso(int a){
  if (a < 0){
    a = -1 * a;
  }
  return a;
}

int main() {
  int n; cin >> n;
  vector<int> w(n);
  rep(i, n) {
    cin >> w.at(i);
  }
  int total = 0;
  rep(i, n) {
    total += w.at(i);
  }
  int ans = 100000000;
  int s1;
  int s2;
  rep(i, n) {
    s1 = 0;
    rep(j, i) {
      s1 += w.at(j);
    }
    s2 = total - s1;
    if (abso(s1-s2) < ans) {
      ans = abso(s1-s2);
    }
  }
  cout << ans << endl;
}


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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    ll ans = 0;
    for (int x : a) {
        while (x > 0) {
            if (x%2 == 0) {
                ans++;
                x/=2;
            }
            else break;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    H, W = map(int, readline().split())
    A = [list(map(int, readline().split())) for _ in range(H)]
    B = [list(map(int, readline().split())) for _ in range(H)]

    M = 0
    G = [[0] * W for _ in range(H)]
    for i in range(H):
        for j in range(W):
            G[i][j] = abs(A[i][j] - B[i][j])
            if M < G[i][j]:
                M = G[i][j]

    M *= max(H, W)
    dp = [0] * W
    dp[0] = 1 << (M + G[0][0]) | 1 << (M - G[0][0])

    for i in range(H):
        for j in range(W):
            if j + 1 < W:
                dp[j + 1] |= (dp[j] >> G[i][j + 1]) | (dp[j] << G[i][j + 1])
            if i + 1 < H:
                dp[j] = (dp[j] >> G[i + 1][j]) | (dp[j] << G[i + 1][j])

    ans = INF
    for i in range(2 * M + 2):
        if dp[W - 1] & (1 << i) and ans > abs(i - M):
            ans = abs(i - M)

    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 69548
using System;
using System.Collections.Generic;
using System.Text;

namespace AtTest.EducationalDP
{
    class I
    {
        static void Main(string[] args)
        {
            Method(args);
            Console.ReadLine();
        }

        static void Method(string[] args)
        {
            int n = ReadInt();
            double[] ps = ReadDoubles();
            double[,] dp = new double[n, n + 1];//i個まででj個表の確率
            dp[0, 0] = 1 - ps[0];
            dp[0, 1] = ps[0];
            for(int i = 1; i < n; i++)
            {
                dp[i, 0] = dp[i - 1, 0] * (1 - ps[i]);
                for (int j = 1; j <= i + 1; j++)
                {
                    dp[i, j] = dp[i - 1, j] * (1 - ps[i])
                        + dp[i - 1, j - 1] * ps[i];
                }
            }
            double res = 0;
            for (int i = n / 2 + 1; i <= n; i++) res += dp[n - 1, i];
            Console.WriteLine(res);
        }

        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


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


int main()
{
	int n,k;
	cin>>n>>k;
	for(int i=0;i<=n;i++)
	{
		for(int j=0;j<=n-i;j++)
		{
			if(10000*i+5000*j+1000*(n-i-j)==k)
			{
				cout<<i<<" "<<j<<" "<<n-i-j<<endl;
				return 0;
			}
		}
	}
	cout<<-1<<" "<<-1<<" "<<-1<<endl;
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  
  vector<string> A(N);
  
  for (int i = 0; i < N; i++) cin >> A.at(i);
  
 
  int M;
  cin >> M;
  
  vector<string> B(M);
  
  for (int i = 0; i < M; i++) cin >> B.at(i);
  
  int ans = -100;
  
  for (int i = 0; i < N; i++) {
    int count = 0;
    for (int j = 0; j < N; j++) {
      if (A.at(i) == A.at(j)) count++;
    }
    for (int k = 0; k < M; k++){
      if (A.at(i) == B.at(k)) count--;
    }
    ans = max(ans,count);
  }
  if (ans < 0) {
    cout << 0 << endl;
  }
  else
    cout << ans << endl;
}
  

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

const string YES = "Yes";

const string NO = "No";

void solve(int X, int Y)
{
    if (2 * X <= Y && Y <= 4 * X && Y % 2 == 0)
        cout << YES << endl;
    else
        cout << NO << endl;
}

int main()
{
    int X;
    cin >> X;
    int Y;
    cin >> Y;
    solve(X, Y);
    return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <cstdio>
 
using namespace std;
 
int main(){
    int n, taro=0, hana=0;
 
    cin >> n;
    for(int i=0; i<n; ++i){
        string s1, s2;
        cin >> s1 >> s2;
         
        if(s1>s2) 
            taro+=3;
        else if(s1<s2)
            hana+=3;
        else{
            ++taro;
            ++hana;
        }
         
    }
    printf("%d %d\n", taro, hana);  
     
    return 0;
}


Measured memory_bytes: 3296
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>
using namespace std;
const int N=100010,M=N*2;
struct node
{
    int a,b;
    double w;
    bool operator<(const node&A)const
    {
        return w>A.w;
    }
}sz[M];
typedef pair<int,int>PII;
PII p[N];
int t[N];
int m,n;
int find(int a)
{
    if(t[a]!=a)t[a]=find(t[a]);
    return t[a];
}
double dist(int x,int y)
{
    double a=abs(p[x].first-p[y].first);
    double b=abs(p[x].second-p[y].second);
    return sqrt(a*a+b*b);
}
int main(void)
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
    {
        t[i]=i;
        int x,y;
        scanf("%d%d",&x,&y);
        p[i]={x,y};
    }
    double ans=0,res=0;
    for(int i=1;i<=m;i++)
    {
        int x,y;
        scanf("%d%d",&x,&y);
        ans+=dist(x,y);
        sz[i]={x,y,dist(x,y)};
    }
    sort(sz+1,sz+m+1);
    for(int i=1;i<=m;i++)
    {
        int a=sz[i].a,b=sz[i].b;
        double w=sz[i].w;
        int pa=find(a),pb=find(b);
        if(pa!=pb)
        {
            res+=w;
            t[pa]=pb;
        }
    }
    printf("%.3lf",ans-res);
    //system("pause");
    return 0;
}


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

typedef long long ll;

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

    int n, m;

    cin >> n >> m;

    cout << (n * (n - 1) + m * (m - 1)) / 2 << endl;

    return 0;
}



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

using namespace std;

//----------------------- Print Function ----------------------//

inline void print() {
    cout << '\n';
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest) {
    cout << first << ' ';
    print(rest...);
}

//------------------------- Libraries -------------------------//

template<class Monoid> struct SegTree {
    using Func = function<Monoid(Monoid, Monoid)>;
    const Func F;
    const Monoid UNITY;
    int SIZE_R;
    vector<Monoid> dat;
    
    SegTree(int n, const Func f, const Monoid &unity): F(f), UNITY(unity) { init(n); }
    void init(int n) {
        SIZE_R = 1;
        while (SIZE_R < n) SIZE_R *= 2;
        dat.assign(SIZE_R * 2, UNITY);
    }
    
    /* set, a is 0-indexed */
    void set(int a, const Monoid &v) { dat[a + SIZE_R] = v; }
    void build() {
        for (int k = SIZE_R - 1; k > 0; --k)
            dat[k] = F(dat[k*2], dat[k*2+1]);
    }
    
    /* update a, a is 0-indexed */
    void update(int a, const Monoid &v) {
        int k = a + SIZE_R;
        dat[k] = v;
        while (k >>= 1) dat[k] = F(dat[k*2], dat[k*2+1]);
    }
    
    /* get [a, b), a and b are 0-indexed */
    Monoid get(int a, int b) {
        Monoid vleft = UNITY, vright = UNITY;
        for (int left = a + SIZE_R, right = b + SIZE_R; left < right; left >>= 1, right >>= 1) {
            if (left & 1) vleft = F(vleft, dat[left++]);
            if (right & 1) vright = F(dat[--right], vright);
        }                                                                                                              
        return F(vleft, vright);
    }
    inline Monoid operator [] (int a) { return dat[a + SIZE_R]; }
    
    /* debug */
    void print() {
        for (int i = 0; i < SIZE_R; ++i) {
            cout << (*this)[i];
            if (i != SIZE_R-1) cout << ",";
        }
        cout << endl;
    }
};

long long gcd(long long a, long long b){
    if (a < b) swap(a, b);
    return b ? gcd(b, a % b) : a;
}

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

//--------------------------- Solve ---------------------------//

void solve() {
    int N; cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++) cin >> A[i];

    auto f = [](int a, int b) { return gcd(a, b) ;};
    SegTree<int> seg(N, f, 0);

    for (int i = 0; i < N; i++) {
        seg.set(i, A[i]);
    }
    seg.build();

    int ans = 1;
    for (int i = 0; i < N; i++) {
        int tmp = gcd(seg.get(0, i), seg.get(i+1, N));
        ans = max(ans, tmp);
    }

    cout << ans << '\n';
}

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

    solve();

    return 0;
}

Measured memory_bytes: 4760
#include<cstdio>

bool f[100005];
int c[100005];
int N, L, R;

int main(){
  for (int i =2; i <=100000; i++) if(!f [i]) for(int j = i + i ;j <=100000; j += i)f[j]= true;
  for (int i =3; i <=100000; i +=2) if (!f[i] && !f[(i+1)/2]) c[i]++;
  for ( int i =3; i <=100000; i ++) c[i] += c[i -1];
  scanf ("%d" ,& N );
  while (N--){ 
    scanf ("%d%d" , &L ,&R );
    printf ("%d\n" , c[R] - c[L -1]);
  }
}

Measured memory_bytes: 1024
n = int(input())

nums = [[0, 0] for _ in range(n)]

for i in range(n):
  nums[i][0], nums[i][1] = map(int, input().split())
  
if n % 2 == 0:
  # even
  nums.sort(key=lambda x: x[0])
  a = (nums[(n+1)//2 - 1][0] + nums[(n+1)//2][0])
  nums.sort(key=lambda x: x[1])
  b = (nums[(n+1)//2 - 1][1] + nums[(n+1)//2][1])
  print(b-a + 1)
  
else:
  # odd
  nums.sort(key=lambda x: x[0])
  a = nums[(n+1)//2 - 1][0]
  nums.sort(key=lambda x: x[1])
  b = nums[(n+1)//2 - 1][1]
  print(b-a + 1)


Measured memory_bytes: 42104
if __name__ == '__main__':
    while True:
        L, R = list(map(int, input().strip().split()))
        if L == 0 and R == 0:
            break
            
        arr = set([ 0 ])
        if L > 0:
            arr.update( list(map(int, input().strip().split(' '))) )
        if R > 0:
            arr.update( list(map(int, input().strip().split(' '))) )
        arr = sorted(list(arr))

        maxi = -9999999999
        for i in range(len(arr) - 1):
            maxi = max(maxi, arr[i + 1] - arr[i])

        print(maxi)


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

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

int N;
int A;

long long gcd(long long x,long long y){
	if(x==0) return y;
	return gcd(y%x, x);
}

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

	cin >> N;

	int now; cin >> now;

	for (int i = 1;i < N;i++){
		cin >> A;
		now = gcd(now,A);
	}

	cout << now << endl;

	return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,m,k,all,cnt; 
	cin >>  n >> m ;
			  	  vector<vector<int>> data(n, vector<int>(30));

	  for(int i=0;i<n;i++){
		  cin >> k ;
		  for(int j=0;j<k;j++){
			  cin >> data.at(i).at(j);
		  }
		  }

		  for(int i=1;i<=m;i++){
			  cnt=0;
			  for(int j=0;j<n;j++){
				  for(int l=0;l<30;l++){
					  if(data.at(j).at(l)==i)
					  cnt++;
				  }
			  }
			  if(cnt==n)
			  all++;
		  }

	cout << all << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import math
n = int(input())
a = list(map(int, input().split()))

c1 = 0
c2 = 0
t1 = int(math.ceil(sum(a)/n))
t2 = int(sum(a)//n)
for i in range(0,n):
  if a[i]!=t1:
    c1=c1+(t1-a[i])*(t1-a[i])
  if a[i]!=t2:
    c2=c2+(t2-a[i])*(t2-a[i])

print(min(c1,c2))


Measured memory_bytes: 3064
package main

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

func main() {
	n := intStdin()
	var total int
	for i := 0; i < n; i++ {
		customer := splitIntStdin(" ")
		l, r := customer[0], customer[1]
		total += r - l + 1
	}
	fmt.Println(total)
}

/* template */
var sc = bufio.NewScanner(os.Stdin)

// 文字列を1行取得
func strStdin() (stringInput string) {
	sc.Scan()
	stringInput = sc.Text()
	stringInput = strings.TrimSpace(stringInput)
	return
}

// 整数値1つ取得
func intStdin() (num int) {
	stringInput := strStdin()
	num, _ = strconv.Atoi(strings.TrimSpace(stringInput))
	return
}

// 空白や空文字だけの値を除去したSplit()
func splitWithoutEmpty(stringTargeted string, delim string) (stringReturned []string) {
	stringSplited := strings.Split(stringTargeted, delim)

	for _, str := range stringSplited {
		if str != "" {
			stringReturned = append(stringReturned, str)
		}
	}
	return
}

// デリミタで分割して文字列スライスを取得
func splitStrStdin(delim string) (stringReturned []string) {
	// 文字列で1行取得
	stringInput := strStdin()

	// 空白で分割
	stringReturned = splitWithoutEmpty(stringInput, delim)

	return
}

// デリミタで分割して整数値スライスを取得
func splitIntStdin(delimiter string) (intAry []int) {
	// 文字列スライスを取得
	strAry := splitStrStdin(delimiter)

	// 整数スライスに保存
	for i := range strAry {
		num, err := strconv.Atoi(strAry[i])
		if err != nil {
			panic(err)
		}
		intAry = append(intAry, num)
	}
	return
}

/* template */

Measured memory_bytes: 768
#include<bits/stdc++.h>
#define crap ios_base::sync_with_stdio(0);cin.tie(0)
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define endl "\n"
#define int ll

using namespace std;
const int N = 105;

int w[N];
int v[N];
int n,W;
int dp[105][100005];
int solve(int index,int cur_w){
	if(index>=n) return 0;
	int a=INT_MIN,b = INT_MIN;
	if(dp[index][cur_w]!=-1) return dp[index][cur_w];
	if(cur_w+w[index]<=W)
		a = max(a, v[index] + solve(index+1,cur_w+w[index]));
	b = max(b,solve(index+1,cur_w));
	return dp[index][cur_w] = max(a,b);
}

int32_t main()
{
    
   
    crap;
    memset(dp,-1,sizeof(dp));
    cin>>n>>W;
 
    for(int i=0;i<n;i++){
    	cin>>w[i]>>v[i];
    }
    int ans = solve(0,0);

    cout<<ans<<endl;
   
   
   
}

Measured memory_bytes: 82304
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
int main() {
  int64_t A;
  string B;
  cin>>A>>B;
  int c=(B[0]-'0')*100+(B[2]-'0')*10+(B[3]-'0');
  int64_t ans=A*c;
  cout<<ans/100<<endl;

  return 0;}

Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
#include <vector>
#include <unordered_map>

using namespace std;

typedef long long ll;

int main() {
    ll n, m, a , b;
    cin >> n >> m;
    
    vector<ll> x;
    vector<ll> y;
    
    
    for(ll i = 0; i < m; ++i) {
        cin >> a >> b;
        
        if(b == n)
            y.push_back(a);
        
        if(a == 1)
            x.push_back(b);
    }
    
    bool ans = false;
    
    sort(x.begin(), x.end());
    sort(y.begin(), y.end());
    
    ll index1 = 0;
    ll index2 = 0;
    
    while(index1 < x.size() && index2 < y.size()) {
        if(x[index1] == y[index2]) {
            ans = true;
            break;
        }
        else if(x[index1] < y[index2])
            ++index1;
        else
            ++index2;
    }
    
    if(ans)
        cout << "POSSIBLE" << endl;
    else
        cout << "IMPOSSIBLE" << endl;
  
    return 0;
}


Measured memory_bytes: 1984
<?php
  
  fscanf(STDIN,"%d",$n);


$b_li = explode(" ",trim(fgets(STDIN)));


$last = $b_li[count($b_li)-1];
$sum=0;
$count=0;

$max_left = $b_li[0];
$now = 0;

for($i=1;$i<$n-1;$i++){
  $now = $b_li[$i];
  if($max_left<$now){
    $b_li[$i] = $max_left;
    
  }
      $max_left = $now;


}

//print_r($b_li);

echo (array_sum($b_li)+$last)."\n";

Measured memory_bytes: 4856
#include <iostream>
  
using namespace std;
  
int main(){
 int a,b;
 cin >> a;
 cin >> b;
 if (a>b) {
  cout << "a > b" <<endl;
 } else if (a<b) {
  cout << "a < b" <<endl;
 } else {
  cout << "a == b" <<endl;
 }
 return 0;
}


Measured memory_bytes: 3076
// Enjoy your stay.

#include <bits/stdc++.h>

#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(auto it=(X).begin();it!=(X).end();it++)
#define ite iterator
#define mp make_pair
#define mt make_tuple
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define pb push_back
#define sec second
#define sz(x) ((int)(x).size())

using namespace std;

typedef istringstream iss;
typedef long long ll;
typedef pair<ll,ll> pi;
typedef stringstream sst;
typedef vector<ll> vi;

int m,n,obj[200];
int dp[180000];
int p3[12];

int f(int mask){
	int& res = dp[mask];
	if(res!=-1)return res;
	res = INF;

	int d[12];
	rep(i,m)d[i] = mask/p3[i]%3;

	int hit = 0;
	rep(i,n){
		int ok = 1;
		rep(j,m)if(d[j]!=2 && d[j] != (obj[i]>>j&1)){
			ok = 0;break;
		}
		if(ok)hit++;
	}

	if(hit <= 1)return res = 0;
	rep(i,m)if(d[i] == 2){
		res = min(res, 1 + max(f(mask - 2 * p3[i]), f(mask - 1 * p3[i])));
	}

	return res;
}

int main(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	
	p3[0] = 1;
	rep(i,11)p3[i+1] = p3[i] * 3;
	while(cin>>m>>n && m){
		rep(i,n){
			string s;
			cin>>s;
			obj[i] = 0;
			rep(j,m)obj[i] |= (s[j] - '0')<<j;
		}
		memset(dp,-1,sizeof(dp));
		cout<<f(p3[m]-1)<<endl;
	}
}

Measured memory_bytes: 1924
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;
#define rep(i,n) for(ll i=0;i<n;i++)

int main(){
	int n;cin>>n;
	string s;cin>>s;
	int l[n+1]={},r[n+1]={};

	rep(i,n){
		if(s[i]=='(') l[i+1]=l[i]+1;
		else l[i+1]=max(0,l[i]-1);
	}

	for(int i=n-1;i>=0;i--){
		if(s[i]==')') r[i]=r[i+1]+1;
		else r[i]=max(r[i+1]-1,0);
	}
/*
	rep(i,n+1) cout<<l[i]<<" ";
	cout<<"\n";

	rep(i,n+1) cout<<r[i]<<" ";
	cout<<"\n";
*/
	while(r[0]){
		cout<<'(';
		r[0]--;
	}
	cout<<s;
	while(l[n]){
		cout<<')';
		l[n]--;
	}
	cout<<"\n";

}

Measured memory_bytes: 256
#include <iostream>

typedef long long ll;

ll freq[2];

ll comb[102][102];

int main()
{
	comb[0][0] = 1;
	for(int i = 0; i < 101; i++)
	{
		for(int j = 0; j < 101; j++)
		{
			comb[i + 1][j] += comb[i][j];
			comb[i + 1][j + 1] += comb[i][j];
		}
	}
	int n, p;
	std::cin >> n >> p;
	for(int i = 0; i < n; i++)
	{
		int cur = 0;
		std::cin >> cur;
		cur %= 2;
		freq[cur]++;
	}
	ll ans = 0;
	if(p == 0)
	{
		for(int i = 0; i <= freq[1]; i+=2)
			ans += (1LL << freq[0]) * comb[freq[1]][i];
	}
	else
	{
		for(int i = 1; i <= freq[1]; i+=2)
			ans += (1LL << freq[0]) * comb[freq[1]][i];
	}
	std::cout << ans << "\n";
}

Measured memory_bytes: 384
//A.cpp
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <math.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b!=0?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
const ll mod=1e9+7;
// const int INF = 1000000;

int main(){
  int n;
  cin >> n;
  int p[n];
  int a;
  rep(i,n){
    cin >> a;
    p[i] = -a;
  }
  sort(p,p+n);
  int ans;
  ans = 0;
  ans -= p[0]/2;
  for(int i = 1; i < n; i++){
    ans -= p[i];
  }
  printf("%d\n", ans);
  return 0;
}


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

int main(void){
    int n;
    cin >> n;
    int h[n];
    for(int i=0; i<n; i++) cin >> h[i];

    int sum = 1,high = h[0];
    for(int i=1; i<n; i++){
        if(high <= h[i]){
            high = h[i];
            sum++;
        }
    }

    cout << sum << endl;
    
    return 0;
}

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

#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif

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

struct edge{ int to,cost; };
const int N = 2e5+10;
vector< edge > G[N];
int h,w;
int cnt;

void dikstra(int s){
  typedef pair<int, int> P;
  const int INF = 1 << 30;

  priority_queue<P,vector<P>,greater<P>> que;
  vector<int> d(N,INF); //sからの最短距離
  d[s] = 0;
  que.push({0,s}); //{最短距離,頂点}

  while( !que.empty() ){
    P p = que.top(); que.pop();
    int v = p.second;
    if(d[v] < p.first) continue;
    for(auto e : G[v]){
      if(d[e.to] > d[v] + e.cost){
        d[e.to] = d[v] + e.cost;
        que.push( {d[e.to],e.to} );
      }
    }
  }
  if(d[w*h-1] == INF) cout << -1 << endl;
  else cout << cnt-d[w*h-1]-1 << endl;
}

signed main(){

  cin >> h >> w;
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      char c; cin >> c;
      if(c == '.'){
        cnt++;
        if(j+1 < w) G[w*i+j].push_back({w*i+j+1,1});
        if(j-1 >= 0) G[w*i+j].push_back({w*i+j-1,1});
        if(i+1 < h) G[w*i+j].push_back({w*(i+1)+j,1});
        if(i-1 >= 0) G[w*i+j].push_back({w*(i-1)+j,1});
      }
    }
  }
  dikstra(0);

  return 0;
}


Measured memory_bytes: 6656
n, k = map(int, input().split())
s = [0]
for i in range(1,n+1):
    s.append(s[i-1] + i)

ans = 0
for i in range(k,n+1):
    ans += ((s[n]-s[n-i]) - s[i-1])+ 1
print((ans+1) % (10**9 + 7))


Measured memory_bytes: 19232
var
 a,b:ansistring;
 i:longint;
begin
 read(a);
 for i:=1 to length(a) do b:=a[i]+b;
 for i:=1 to length(a) do 
  if b[i]='b' then b[i]:='d'
   else if b[i]='d' then b[i]:='b'
    else if b[i]='p' then b[i]:='q'
     else b[i]:='p';
 if a=b then writeln('Yes')
  else writeln('No');
end.

Measured memory_bytes: 384
n,k = list(map(int,input().split()))
s = input()
count = 0
RL = 0

for i in range(n-1):
    if s[i] == s[i+1]:
        count = count + 1
    else:
        RL = RL + 1

for f in range(k):
    if n-1 == count:
        break
    elif RL < 2:
        count = count + 1
        break
    else:
        count = count + 2
        RL = RL - 2

print(count)

Measured memory_bytes: 39536
#include <bits/stdc++.h>
#define ll long long
using namespace std;
string s , t;
ll ch(string s, string t)
{
    ll p = 0;
    for(ll i = 0; i < s.size(); i++)
    {
        if(s[i] != t[i])
        {
            p++;
        }
    }
    return p;
}
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);

    cin >> s >> t;
    ll mx = 1050;
    for(ll i = 0; i < s.size(); i++)
    {
        string S = s.substr(i , t.size());
        if(S.size() == t.size())
        {
            ll aa = ch(S, t);
            mx = min(mx, aa);

        }
    }
    cout << mx;
}


Measured memory_bytes: 3660
N = int(input())
A = [int(input()) for _ in range(N)]

index = A.index(max(A))
A.sort()
max_ = A[-1]
second_max = A[-2]

if max_ == second_max:
    for _ in range(N):
        print(max_)
else:
    for i in range(N):
        if i == index:
            print(second_max)
        else:
            print(max_)


Measured memory_bytes: 12512
/*
题意是求一个序列中"所有子序列的中位数"所组成的序列的中位数 
看题解了，完全不会。https://www.cnblogs.com/quzhizhou/p/9535597.html  

首先我们先二分最后序列的中位数。设tot为中位数 >= mid的区间个数，若中位数序列的中位数 >= mid，
则有tot >= n(n+1)/4。
我们另外构造一个序列b[i], 当a[i]>=mid时b[i]=1, 否则bi=-1. 
那么若区间[l, r]的中位数 >= mid, 则b[l]+...+b[r] >= 0. 
于是我们求出序列b[i]的前缀和序列sum[i]，那么问题就变成了求满足l <= r且sum[r]-sum[l-1]>=0的数对(l,r)数量(0<=l,r<=n)，
这个问题可以用与求逆序对数量相似的方法解决. 树状数组即可. 
*/ 
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
typedef long long ll;

const int NN = 110000;
int a[NN], l, r, n, mid, ans;
int s[NN * 2];  
//树状数组，注意，[-n-1, n], 为了让每一个存的值都是>0, 都加上n即可（因为树状数组不能从0开始）
//所以开双倍空间给数组 

int lowbit(int x){
	return x & (-x);
} 

void add1(int x, int k){
	while (x <= n * 2){
		s[x] += k;
		x += lowbit(x);
	}
}

int getsum(int x){
	int sum = 0;
	while (x > 0){
		sum += s[x];
		x -= lowbit(x);
	}
	return sum;
}

int check(int mid){
	memset(s, 0, sizeof(s));  //树状数组清0 
	//for(int i=1;i<=2*n;i++)s[i]=0;
	//与求逆序对的方法相同 
	add1(n, 1);  //因为在每个数的基础上都加了n，所以这句话相当于在和等于0的点+1
	int sum = 0;
	ll tmp = 0;  //注意，tmp也不必须是ll，算清楚，以后要是不仔细想一律给ll 
	for (int i=1; i<=n; i++){
		if (a[i] >= mid) sum++;
		else sum--;
		tmp += getsum(sum + n);
		add1(sum + n, 1);
	} 
	long long nn = ((long long) n) * (n + 1) / 4; //注意！nn必须给long long, 右边的long long也必须打！！！！！！！不然wa！！！！ 
	if (tmp >= nn) return true;
	else return false; 
}

int main(){
	//freopen("atcoderarc101d.in", "r", stdin);
	
	scanf("%d", &n);
	l = 0x7fffffff; r = 0;
	for (int i=1; i<=n; i++){
		scanf("%d", &a[i]);
		if (a[i] >= r) r = a[i];
		if (a[i] <= l) l = a[i];
	}
	//printf("%d %d\n", l, r);
	while (l <= r){
		mid = (l + r) / 2;
		if (check(mid)){
			ans = mid; 
			l = mid + 1;
		} else r = mid-1;
	}
	printf("%d", ans);
	
	return 0;
} 

Measured memory_bytes: 1536
#include <stdio.h>
int main(void)
{
    int n,i,min,cnt = 0;
    scanf("%d",&n);
    int p[n];
    for(i = 0; i < n; i++)
    {
        scanf("%d",&p[i]);
    }
    min = p[0];
    for(i = 0; i < n; i++)
    {
        if(p[i] <= min)
        {
            cnt++;
            min = p[i];
        }
    }
    printf("%d\n",cnt);
    return 0;
}


Measured memory_bytes: 896
// " --- IN THE NAME OF ALLAH --- " // ;)
// ------------sphr_agz------------ // ;)
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;

typedef long double ld;
typedef long long int lli;
typedef pair <lli, lli> pii;
#define pb push_back
#define recout(x) return cout << (x), 0
#define f first
#define s second
#define fast ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define stp(x) cout << setprecision(x) << fixed
#define mk make_pair
#define all(x) x.begin(), x.end()
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
//#pragma GCC optimize("no-stack-protector,fast-math")
const lli N = 4e2 + 10, N2 = 2e5, delta = 46639, mod = 1e9 + 7, oo = 1e18, LOG = 20, SQ = 300;
const ld PI = 3.141592653589793;

lli a[N], ps[N], dp[N][N];

int32_t main() {
	fast;
	lli n, ans = 0;
	cin >> n;
	for (lli i = 0; i < n; i++) {
		cin >> a[i];
		memset (dp[i], 63, sizeof dp[i]);
		dp[i][i] = a[i];
		ps[i] = (i? ps[i - 1]: 0) + a[i];
	}
	for (lli j = 1; j < n; j++)
		for (lli i = j - 1; i >= 0; i--)
			for (lli k = i; k < j; k++)
				dp[i][j] = min (dp[i][j], dp[i][k] + dp[k + 1][j] + ps[j] - (i? ps[i - 1]: 0));
	cout << dp[0][n - 1] - ps[n - 1] << '\n';
	return 0;
}


Measured memory_bytes: 1536
def main():
    N, M = map(int, input().split())
    if N == 1 and M == 1:
        print(1)
        return
    if N == 1:
        print(M - 2)
        return
    if M == 1:
        print(N - 2)
        return
    ans = (N - 2) * (M - 2)
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
N = int(input())
L = sorted([int(l) for l in input().split()])
INF = 10**8
L.append(INF)
L.append(INF)

num = 0
for na in range(N-2):
    for nb in range(na+1, N - 1):
        r = N+1
        l = nb
        while r - l > 1:
            c = (l + r) // 2
            if L[c] < L[na] + L[nb]:
                l = c
            else:
                r = c
        num += l - nb

print(num)


Measured memory_bytes: 41964
#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, M; cin >> N >> M;
    vector<int> As(N); for (auto &Ai : As) cin >> Ai;
    // 累積和のmodを計算し，各余り値の数を数えておく：O(N~10^5)
    map<int, LLONG> mod2NumMap;
    int mod = As[0] % M;
    ++mod2NumMap[mod];
    for (int i = 1; i < N; ++i)
    {
        mod = (mod + As[i]) % M;
        ++mod2NumMap[mod];
    }
    LLONG ans = 0LL;
    // 余りがゼロのものはその箱単体を選べばよい
    auto zeroItr = mod2NumMap.find(0);
    if (zeroItr != mod2NumMap.end())
    {
        ans += zeroItr->second;
    }
    // 余りが非ゼロのもののうち，同じ余りをもつ箱の数nに対し
    // nC2通りの各ペアについて総和がMの倍数になる：O(N~10^5)
    for (const auto &kvp : mod2NumMap)
    {
        LLONG num = kvp.second;
        LLONG pairNum = num * (num - 1) / 2LL;
        ans += pairNum;
    }
    cout << ans << endl;
}



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

int main()
{
#ifndef ONLINE_JUDGE
    //freopen("A.in","r",stdin);
    //freopen("A.out","w",stdout);
#endif
	int a,b,c;
	cin >> a >> b >> c;
	int t=max(a,max(b,c));
	if(a+b+c-t==t)
		puts("Yes");
	else
		puts("No");
	return 0;
}


Measured memory_bytes: 256
from collections import defaultdict
from itertools import combinations
n=int(input())

c=defaultdict(int)
for _ in range(n):
    s=input()
    if s[0] in 'MARCH':
        c[s[0]]+=1
res=0
for comb in combinations('MARCH',3):
    res+=c[comb[0]]*c[comb[1]]*c[comb[2]]
print(res)

Measured memory_bytes: 3444
import sys
import bisect
from fractions import Fraction

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_s = lambda: readline().rstrip().decode('utf-8')
in_nl = lambda: list(map(int, readline().split()))
in_nl2 = lambda H: [in_nl() for _ in range(H)]
in_map = lambda: [s == ord('.') for s in readline() if s != ord('\n')]
in_map2 = lambda H: [in_map() for _ in range(H)]
in_all = lambda: map(int, read().split())


def main():

    A, B, C, D, E, F = in_nn()

    water = set()
    for i in range(31):
        for j in range(31):
            t = i * A * 100 + j * B * 100
            if t <= F:
                water.add(t)
            else:
                break
    water = list(sorted(water))

    sugar = set()
    for i in range(3001):
        for j in range(3001):
            t = i * C + j * D
            if t <= F:
                sugar.add(t)
            else:
                break
    sugar = list(sorted(sugar))

    max_f = 0
    ans = (100 * A, 0)
    for w in water:
        for s in sugar:
            if w + s <= F and s <= (w // 100) * E and w + s != 0:
                if max_f < Fraction(s, w + s):
                    max_f = Fraction(s, w + s)
                    ans = (s + w, s)

    print(ans[0], ans[1])


if __name__ == '__main__':
    main()


Measured memory_bytes: 10568
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <functional>

#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 62;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll conbinationMemo[100][100];

ll cmemoInit(){
    rep(i, 100){
        rep(j, 100){
            conbinationMemo[i][j] = -1;
        }
    }
}
 
ll nCr(ll n, ll r){
    if(conbinationMemo[n][r] != -1) return conbinationMemo[n][r];
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return conbinationMemo[n][r] = (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
 
//-----------------------ここから-----------
int dp[50][500][500] = {0};

int main(void){
    int n, ma, mb;
    cin >> n >> ma >> mb;
    vector<pair<pair<int,int>,int>> vec(n);

    rep(i, n){
        int a, b, c;
        cin >> a >> b >> c;

        vec[i] = {{a, b}, c};
    }

    rep(i, n + 1){
        rep(j, 501){
            rep(k, 501){
                dp[i][j][k] = 1e9;
            }
        }
    }

    dp[0][0][0] = 0;

    rep(i, n){
        rep(j, 501){
            rep(k, 501){
                dp[i + 1][j][k] = min(dp[i + 1][j][k], dp[i][j][k]);
                if(j - vec[i].first.first < 0) continue;
                if(k - vec[i].first.second < 0) continue;
                dp[i + 1][j][k] = min(dp[i + 1][j][k], dp[i][j - vec[i].first.first][k - vec[i].first.second] + vec[i].second);
            }
        }
    }

    int i = ma;
    int j = mb;
    int ans = 1e9;
    while(i < 501 && j < 501){
        ans = min(ans, dp[n][i][j]);
        i += ma;
        j += mb;
    }

    cout << (ans==(int)1e9?-1:ans) << endl;
}

Measured memory_bytes: 41344
def inp():
    return input()
def iinp():
    return int(input())
def inps():
    return input().split()
def miinps():
    return map(int,input().split())
def linps():
    return list(input().split())
def lmiinps():
    return list(map(int,input().split()))
def lmiinpsf(n):
    return [list(map(int,input().split()))for _ in range(n)]

n,a,b = miinps()

k = a+b
ans = 0

p = n//k
q = n%k
ans +=  p*a

if q < a:
  ans += q
else:
  ans += a

print(ans)

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

//  四方向へのベクトル
const int dx[4] = {-1,0,1,0};
const int dy[4] = {0,-1,0,1};

int h,w;
//探索用
//bool seen[1000][1000];
int MAX=0;
long long sum=0;
int seen[2000][2000];

int bfs(const vector<string> &G,int x,int y){
queue <int> q;//x,yの順に格納
   q.push(x);
   q.push(y);
   seen[y][x] = 1;

   while(true){
        int cc = q.front();
        q.pop();
        int rr = q.front();
        q.pop(); 
        
        
        for(int i=0;i<4;i++){
            int next_x = cc + dx[i];
            int next_y = rr + dy[i];

            if(next_x<=0 || next_x >w || next_y<=0 || next_y>h) continue;
            if(seen[next_y][next_x] != -1) continue;
            if(G[next_y-1][next_x-1]  == '#') continue;


            q.push(next_x);
            q.push(next_y);
            
             seen[next_y][next_x] = seen[rr][cc] +1; 
        }

        if(seen[h][w] != -1||q.size() == 0) break;
   }

  return 0;
}

int main(){
    cin >> h>> w;

    vector<string> G(h);
    for(int i=0;i<h;i++) cin >> G[i];
    memset(seen,-1,sizeof(seen));

    for(int i=0;i<h;i++){
        for(int k=0;k<w;k++){
            if(G[i][k] == '#'){
               MAX++;
            }
        }
    }


    bfs(G,1,1);

    if(seen[h][w] == -1) {
        cout << -1 <<endl;
        return 0;
    }
    int no_trans = MAX + seen[h][w];

    cout << h*w - no_trans << endl;
    return 0;
    
}



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

const int MOD = 1e9 + 7;
int add(int x, int y) { return (x += y) < MOD ? x : x - MOD; }
int sub(int x, int y) { return (x -= y) >= 00 ? x : x + MOD; }
int mul(int x, int y) { return (ll) x * y % MOD; }

int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  int n;
  string str;
  cin >> n >> str;
  int cnt[26] = {};
  for (int i = 0; i < n; ++i) {
    cnt[str[i] - 'a']++;
  }
  int sol = 1;
  for (int i = 0; i < 26; ++i) {
    sol = mul(sol, cnt[i] + 1);
  }
  cout << sub(sol, 1) << '\n';
}


Measured memory_bytes: 512
use std::io;

fn procon_read<T: std::str::FromStr>() ->  Vec<T> {
	let mut buf = String::new();
	io::stdin().read_line(&mut buf).expect("");
	let iter = buf.split_whitespace();
	let mut v: Vec<T> = Vec::new();
	for i in iter {
		v.push(i.parse().ok().unwrap());
	}
	v
}

fn main() {
	let mut v:Vec<i32> = procon_read();
	v.sort();
	if v[0] == 5 && v[1] == 5 && v[2] == 7 {
		println!("YES");
	}else{
		println!("NO");
	}
}


Measured memory_bytes: 4352
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        A solver = new A();
        solver.solve(1, in, out);
        out.close();
    }

    static class A {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int N = in.nextInt();
            out.println(N * (N + 1) / 2);
        }

    }
}



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

int ans;
char op[18] = "CODEFESTIVAL2016", ip[18];

int main()
{
	scanf("%s",ip);
	for(int i=0;i<16;i++) if(ip[i] != op[i]) ans++;
	printf("%d\n",ans);
}


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

int main(){
  string S; cin>>S;
  int A=(S[0]-'0')*10+(S[1]-'0');
  int B=(S[2]-'0')*10+(S[3]-'0');
  if(((1<=A)&&(A<=12))&&(B==0||13<=B&&B<=99)) cout<<"MMYY\n";
  else if((A==0||13<=A&&A<=99)&&((1<=B)&&(B<=12))) cout<<"YYMM\n";
  else if((1<=A)&&(A<=12)&&(1<=B)&&(B<=12)) cout<<"AMBIGUOUS\n";
  else cout<<"NA\n";
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
 
#define rep(i,n) for(ll i = 0;i < n;++i)
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
typedef pair<int,int> P;
 
const int INF = 1001001001;
const long double PI = (acos(-1));
const int mod = 1e9+7;
const int vx[6] = {0,1,0,-1,1,-1};
const int vy[6] = {1,0,-1,0,1,1};




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

    ll n,m;
    cin >> n >> m;
    priority_queue<int> a;
    rep(i,n) {
        int x;
        cin >> x;
        a.push(x);
    }
    rep(i,m){
        int tmp = a.top();
        a.pop();
        tmp /= 2;
        a.push(tmp);
    }
    ll ans = 0;
    rep(i,n){
        int x = a.top();a.pop();
        ans += x;
    }
    cout << ans << endl;

    cout << endl;
    return 0;
}


Measured memory_bytes: 892
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <unordered_map>
#include <iomanip>
#include <cmath>
#include <tuple>
using namespace std;
using ll = long long;
#define rep(i, j, n) for(int i = j; i < (int)n; ++i)
#define rrep(i, j, n) for(int i = (int)n - 1; j <= i; --i)

constexpr ll MOD = 0x3b9aca07;
constexpr int INF = 0x3f3f3f3f;
constexpr ll INFL = 0x3f3f3f3f3f3f3f3fLL;


int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	int a, b; cin >> a >> b;
	if (a <= 8 && b <= 8) cout << "Yay!";
	else cout << ":(";
	cout << endl;
	return 0;
}


Measured memory_bytes: 3608