akhauriyash/Code-Regression huggingface dataset:
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))
## dp ##
def DD2(d1,d2,init=0): return [[init]*d2 for _ in range(d1)]
def DD3(d1,d2,d3,init=0): return [DD2(d2,d3,init) for _ in range(d1)]
## math ##
def to_bin(x: int) -> str: return format(x, 'b') # rev => int(res, 2)
def to_oct(x: int) -> str: return format(x, 'o') # rev => int(res, 8)
def to_hex(x: int) -> str: return format(x, 'x') # rev => int(res, 16)
MOD=10**9+7
def divc(x,y) -> int: return -(-x//y)
def divf(x,y) -> int: return x//y
def gcd(x,y):
    while y: x,y = y,x%y
    return x
def lcm(x,y): return x*y//gcd(x,y)
def enumerate_divs(n):
    """Return a tuple list of divisor of n"""
    return [(i,n//i) for i in range(1,int(n**0.5)+1) if n%i==0]
def get_primes(MAX_NUM=10**3):
    """Return a list of prime numbers n or less"""
    is_prime = [True]*(MAX_NUM+1)
    is_prime[0] = is_prime[1] = False
    for i in range(2, int(MAX_NUM**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i*2, MAX_NUM+1, i): is_prime[j] = False
    return [i for i in range(MAX_NUM+1) if is_prime[i]]
def prime_factor(n):
    """Return a list of prime factorization numbers of n"""
    res = []
    for i in range(2,int(n**0.5)+1):
        while n%i==0: res.append(i); n //= i
    if n != 1: res.append(n)
    return res
## libs ##
from itertools import accumulate as acc, combinations as combi, product, combinations_with_replacement as combi_dup
from collections import deque, Counter
from heapq import heapify, heappop, heappush
from bisect import bisect_left
import string
#======================================================#

def main():
    s = IS()
    t = IS()
    tidx = {a: [] for a in string.ascii_lowercase}
    sidx = {a: [] for a in string.ascii_lowercase}
    for i, ti in enumerate(t):
        tidx[ti].append(i)
    for i, si in enumerate(s):
        sidx[si].append(i)
    for k, idx in tidx.items():
        tmp = set()
        for i in idx:
            tmp.add(s[i])
        if len(tmp) > 1:
            print('No')
            return None
    for k, idx in sidx.items():
        tmp = set()
        for i in idx:
            tmp.add(t[i])
        if len(tmp) > 1:
            print('No')
            return None
    print('Yes')

if __name__ == '__main__':
    main()

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

int main(){
    int n,k,q;
    cin >> n >> k >> q;
    vector<int> a(q);
    rep(i,q) cin >> a[i];
    vector<int> p(n);
    rep(i,q){
        p[a[i]-1]++;
    }
    rep(i,n){
        if(p[i]+k -q >0) puts("Yes");
        else puts("No");
    }
    
    return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b;
    cin >> a >> b;
    if ((a * b) % 2 == 0) cout << "Even" << endl;
    else cout << "Odd" << endl;

    return 0;
}


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

int main()
{
    double x1,y1,x2,y2;
    cin >> x1 >> y1 >> x2 >> y2;
    cout << fixed << setprecision(5) << sqrt(pow(x1-x2,2)+pow(y1-y2,2)) << endl;
    return 0;
}



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

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;
using lint=long long;

int main(){
	int n;
	lint k; scanf("%d%lld",&n,&k);
	vector<int> a(n);
	rep(i,n) scanf("%d",&a[i]);

	vector<int> next(n);
	{
		vector<int> first(2e5+2,-1);
		rep(i,n) if(first[a[i]]==-1) first[a[i]]=i;

		vector<int> nearest(2e5+2,-1);
		for(int i=n-1;i>=0;i--){
			if(nearest[a[i]]==-1){
				next[i]=first[a[i]];
			}
			else{
				next[i]=nearest[a[i]];
			}
			nearest[a[i]]=i;
		}
	}

	int per=1;
	{
		int p=0;
		do{
			if(p>=next[p]) per++;
			p=(next[p]+1)%n;
		}while(p!=0);
	}

	if(k%per==0) return 0;

	k=(k-1)%per;

	int p=0;
	while(k>0){
		if(p>=next[p]) k--;
		p=(next[p]+1)%n;
	}

	// simulate
	vector<int> ans;
	vector<bool> used(2e5+2);
	for(;p<n;p++){
		if(!used[a[p]]){
			ans.emplace_back(a[p]);
			used[a[p]]=true;
		}
		else{
			while(1){
				int x=ans.back();
				ans.pop_back();
				used[x]=false;
				if(x==a[p]) break;
			}
		}
	}
	rep(i,ans.size()) printf("%d%c",ans[i],i+1<ans.size()?' ':'\n');

	return 0;
}


Measured memory_bytes: 4832
n=int(input())
a=list(map(int,input().split()))
ans=[]
if n%2==1:
    i=n
    while i>=1:
        ans.append(str(a[i-1]))
        i-=2
    i=2
    while i<=n:
        ans.append(str(a[i-1]))
        i+=2
    print(" ".join(ans))
else:
    i = n
    while i >= 1:
        ans.append(str(a[i - 1]))
        i -= 2
    i = 1
    while i <= n:
        ans.append(str(a[i - 1]))
        i += 2
    print(" ".join(ans))

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

typedef long long ll;
typedef long double ld;
#define pi 3.14159265359;
#define inf (1 << 21);
#define mod 1000000007;

int f(int n) {
    if (n % 2 == 0) {
        return n / 2;
    }
    else {
        return 3 * n + 1;
    }
}

int main() {
    int s; cin >> s;
    vector<bool> J(10000, false);
    int now = s, next, cnt = 1;
    J.at(s - 1) = true;
    while (true) {
        next = f(now);
        cnt++;
        if (J.at(next - 1) == false) {
            J.at(next - 1) = true;
            now = next;
        }
        else {
            break;
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define F first
#define S second

using namespace std;
typedef long long ll;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    vector<int> b(n - 1);
    for (int i = 0; i < n - 1; ++ i) {
        cin >> b[i];
    }
    int ans = b[0];
    for (int i = 0; i < n - 2; ++ i) {
        ans += min(b[i], b[i + 1]);
    }
    ans += b[n - 2];
    cout << ans;

}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <bitset>
using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl

#define INF 1<<30

int main(){
    int n;
    cin>>n;
    vector<int> vec(2*n);
    rep(i,2*n) scanf("%d", &vec[i]);

    sort(all(vec));
    int res=0;
    rep(i,n) res += vec[i*2];

    cout<<res<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;

int main()
{
	int n, m;
	cin >> n >> m;
	int c = 0;
	for (int i = 0; i < m; i++) {
		int a;
		cin >> a;
		c += a;
	}
	cout << ((n - c < 0) ? -1 : n - c) << endl;
	return 0;
}


Measured memory_bytes: 3624
def main():
    cnt = 0
    for _ in range(m):
        x, y = map(int, input().split())
        unite(x, y)
    for i in range(1, n+1):
        if same(i, p[i]):
            cnt += 1
    print(cnt)
        
def root(x):
    if parent[x] == x:
        return x
    parent[x] = root(parent[x])
    return parent[x]

def same(x, y):
    return root(x) == root(y)

def unite(x, y):
    x = root(x)
    y = root(y)
    if x != y:
        if rank[x] < rank[y]:
            parent[x] = y
        elif rank[x] > rank[y]:
            parent[y] = x
        else:
            parent[y] = x
            rank[x] += 1

if __name__ == "__main__":
    n, m = map(int, input().split())
    p = [0] + list(map(int, input().split()))
    parent = list(range(n+1))
    rank = [0]*(n+1)
    main()


Measured memory_bytes: 14004
W, H, N = map(int, input().split())
plot_infos = [list(map(int, input().split())) for _ in range(N)]

def calcArea(M, H, N, plot_infos):
  pointA = [M, H]
  pointB = [0, 0]
  for i in range(N):
    plot_info = plot_infos[i]
    if plot_info[2] == 1:
      pointB[0] = max(plot_info[0], pointB[0])
    elif plot_info[2] == 2:
      pointA[0] = min(plot_info[0], pointA[0])
    elif plot_info[2] == 3:
      pointB[1] = max(plot_info[1], pointB[1])
    elif plot_info[2] == 4:
      pointA[1] = min(plot_info[1], pointA[1])
      
  if pointA[0] < pointB[0] or pointA[1] < pointB[1]:
      return 0
      
  return (pointA[0] - pointB[0]) * (pointA[1] - pointB[1])

print(calcArea(W, H, N, plot_infos))

Measured memory_bytes: 3064
n = int(input())
a = list(map(int, input().split(" ")))

colors=[]
if list(filter(lambda x:x<3200, a)):
    f=lambda x:x<400
    colors.append(1 if list(filter(f, a)) else 0)
    f=lambda x:400<=x<800
    colors.append(1 if list(filter(f, a)) else 0)
    f=lambda x:800<=x<1200
    colors.append(1 if list(filter(f, a)) else 0)
    f=lambda x:1200<=x<1600
    colors.append(1 if list(filter(f, a)) else 0)
    f=lambda x:1600<=x<2000
    colors.append(1 if list(filter(f, a)) else 0)
    f=lambda x:2000<=x<2400
    colors.append(1 if list(filter(f, a)) else 0)
    f=lambda x:2400<=x<2800
    colors.append(1 if list(filter(f, a)) else 0)
    f=lambda x:2800<=x<3200
    colors.append(1 if list(filter(f, a)) else 0)

    print(sum(colors), sum(colors)+len(list(filter(lambda x:3200<=x, a))))

else:
    print(1, n)


Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
int n,m,k;
int L[100];
int D[16];
int G[100][100];
int dp[1<<16];
main()
{
	cin>>n>>m>>k;
	for(int i=0;i<1<<m;i++)dp[i]=1e9;
	for(int i=0;i<m;i++)
	{
		cin>>D[i];D[i]--;
		L[D[i]]=i+1;
	}
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<k;j++)
		{
			int v;cin>>v;v--;G[i][j]=v;
		}
	}
	dp[(1<<m)-1]=0;
	queue<pair<int,int> >P;
	P.push(make_pair((1<<m)-1,0));
	while(!P.empty())
	{
		int i=P.front().first,c=P.front().second;
		P.pop();
		if(dp[i]<c)continue;
		for(int j=0;j<k;j++)
		{
			int next=0;
			for(int l=0;l<m;l++)
			{
				if(!(i&1<<l))continue;
				int u=G[D[l]][j];
				if(L[u]==0)continue;
				next|=1<<L[u]-1;
			}
			if(dp[next]>c+1)
			{
				dp[next]=c+1;
				P.push(make_pair(next,c+1));
			}
		}
	}
	cout<<dp[0]<<endl;
}



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

int main() {
  int N,Z=0;
  cin>>N;
  vector<char> p(N);
  for(int i=0;i<N;i++){
    cin>>p[i];
  }
  int l=0,r=N-1;
  while(l<r){
    while(l<r){
      if(p[l]=='W'){
        break;
      }
      else{
        l++;
      }
    }
    while(l<r){
      if(p[r]=='R'){
        break;
      }
      else{
        r--;
      }
    }
    if(l<r){
      l++;
      r--;
      Z++;
    }
  }
  cout<<Z<<endl;
    
}



Measured memory_bytes: 3628
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;

void main()
{
  auto n = readln.chomp.to!int;
  auto s = readln.chomp;
  long rc, gc, bc;
  foreach (i; 0..n) {
    if (s[i] == 'R') rc++;
    else if (s[i] == 'G') gc++;
    else bc++;
  }

  auto cnt = rc * gc * bc;
  foreach (int i; 0..n) {
    foreach (int j; i+1..n) {
      if (s[i] == s[j]) continue;
      auto k = 2*j - i;
      if (k >= n) continue;
      if (s[i] == s[k] || s[j] == s[k]) continue;
      cnt--;
    }
  }
  cnt.writeln;
}


Measured memory_bytes: 2728
n=int(input())
d=[input().split()for _ in range(n)]
c=0
for i in range(n-2):
    if d[i][0]==d[i][1]:
        if d[i+1][0]==d[i+1][1]:
            if d[i+2][0]==d[i+2][1]:
                c+=1
                print("Yes")
                break
            else:
                pass
        else:
            pass
    else:
        pass
if c==0:
    print("No")
else:
    pass

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

#define ll long long
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rep(i,n) for(int i = 0; i < int(n); i++)
#define MAX(a,b) (a > b ? a : b)
#define MIN(a,b) (a < b ? a : b)
const int MOD = 1000000007;
int N;
ll a[401];
ll prefix[401];
ll dp[401][401];
int main() {
    IOS;
    cin >> N;
    for(int i = 1; i <= N; i++) cin >> a[i];
    for (int i = 1; i <= N; ++i) {
        prefix[i] = prefix[i - 1] + a[i];
    }
    for(int i = 0; i <= 400; i++) {
        for(int j = 0; j <= 400; j++) {
            dp[i][j] = 10e14 + 1;
        }
        dp[i][i] = 0;
    }
    for(int i = 1; i < N; i++) {
        for(int j = 1; j <= N - i; j++) {
            for(int k = 1; k <= i; k++) {
                ll left = prefix[j + k - 1] - prefix[j - 1];
                ll right = prefix[j + i] - prefix[j + k - 1];
                dp[j][j + i] = MIN(dp[j][j + i], left + right + dp[j][j + k - 1] + dp[j + k][j + i]);
            }
        }
    }
    cout << dp[1][N];
    return 0;
}

Measured memory_bytes: 1536
A, B = map(int, input().split())
import collections

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

A_list = list(collections.Counter(prime_factorize(A)).keys())

B_list = list(collections.Counter(prime_factorize(B)).keys())

A_B_and = set(A_list) & set(B_list)
print(len(A_B_and) + 1)

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

int main()
{
  string s;
  while(cin>>s)
  {
      int num0=0,num1=0;
      for(int i=0;i<s.size();i++)
      {
          if(s[i]=='0')  num0++;
          else num1++;
      }
      cout<<min(num0,num1)*2<<endl;
  }
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define ll  long long int
#define pb push_back
#define sx 200007
int main()
{
   ll a,b,k;
   cin>>a>>b>>k;
   ll mini=min(a,k);
   k=k-mini;
   a=a-mini;
   mini=min(b,k);
   b=b-mini;
   k=k-mini;
   cout<<a<<" "<<b<<endl;
   return 0;
}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
#include <array>
using namespace std;
using ULL = unsigned long long;
using UL = unsigned;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

struct Problem {

	void Solve() {
		UL N; cin >> N;
		LL C; cin >> C;
		vector<pair<LL, LL>> X(N);
		rep(i, N) cin >> X[i].first >> X[i].second;
		auto rX = X;
		reverse(rX.begin(), rX.end());
		rep(i, N) rX[i].first = C - rX[i].first;
		rep(i, N - 1) {
			X[i + 1].second += X[i].second;
			rX[i + 1].second += rX[i].second;
		}

		LL ans = 0;
		LL M = 0;
		rep(i, N) {
			ans = max(ans, M + rX[N - i - 1].second - rX[N - i - 1].first);
			M = max(M, X[i].second - 2 * X[i].first);
		}
		M = 0;
		rep(i, N) {
			ans = max(ans, M + X[N - i - 1].second - X[N - i - 1].first);
			M = max(M, rX[i].second - 2 * rX[i].first);
		}
		cout << ans << endl;
	}


	Problem();
};
int main() {
	unique_ptr<Problem> p(new Problem());
	p->Solve();
	return 0;
}
Problem::Problem() {
	cout << fixed << setprecision(10);
}


Measured memory_bytes: 3328
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv,
    std.functional, std.math, std.numeric, std.range, std.stdio, std.string,
    std.random, std.typecons, std.container;

ulong MAX = 100_100, MOD = 1_000_000_007, INF = 1_000_000_000_000;
alias sread = () => readln.chomp();
alias lread(T = long) = () => readln.chomp.to!(T);
alias aryread(T = long) = () => readln.split.to!(T[]);
alias Pair = Tuple!(long, "x", long, "y");
alias PQueue(T, alias less = "a>b") = BinaryHeap!(Array!T, less);

void main()
{
    long w, h, n;
    scan(w, h, n);
    auto square = new long[][](h, w);
    foreach (i; iota(n))
    {
        long x, y, a;
        scan(x, y, a);
        switch (a)
        {
        case 1:
            draw(square, 0, x, 0, h);
            break;
        case 2:
            draw(square, x, w, 0, h);
            break;
        case 3:
            draw(square, 0, w, 0, y);
            break;
        case 4:
            draw(square, 0, w, y, h);
            break;
        default:
            assert(0);
        }
    }
    long cnt;
    foreach (i; iota(h))
    {
        foreach (j; iota(w))
        {
            if (square[i][j] == 0)
                cnt++;
        }
    }
    cnt.writeln();
}

void draw(T)(ref T wall, long right, long left, long lower, long upper)
{
    foreach (i; iota(lower, upper))
    {
        foreach (j; iota(right, left))
        {
            wall[i][j]++;
        }
    }
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}


Measured memory_bytes: 2836
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <iostream>
#include <locale>
#include <numeric>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

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

    int ans  = 0;
    int keep = n;
    // cout << "test";
    // cout << 1 / 3 << "ans";
    while (n / 3 != 0) {
        keep = n / 3;
        if (n % 3 != 0) keep++;
        n = keep;
        ans++;
    }

    if (n != 1) ans++;

    cout << ans << endl;
}


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

int main() {
    int N, L;
    cin >> N >> L;
    int sum = 0;

    sum = N*(2*L + N - 1)/2;
    int dist = 0;
    int min_dist = 10000;
    int index;
    for(int i = 1;i < N + 1; i++)
    {  
        int apple_aji = L + i - 1;
        int pie_aji = sum - apple_aji;
  
        dist = sum - pie_aji;
        dist = abs(dist);
        if(min_dist > dist)
        {
            min_dist = min(min_dist, dist);
            index = i;
        }
    }
    cout << sum - ( L + index - 1) << endl;
    return 0;
}



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

typedef long long ll;

int main(){
  int n; cin >> n;
  ll a[n+1], b[n+1];
  for(int i=1; i<=n; i++) cin >> a[i];

  for(int i=1; i<=n; i++){
    b[n/2+1+(i/2)*(int)pow(-1, i-1)*(int)pow(-1, n%2)] = a[i];
  }

  for(int i=1; i<=n; i++){
    cout << b[i];
    if(i!=n) cout << " " ;
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 5504
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace Tasks
{
    public class C
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var (N, M) = Scanner.Scan<int, int>();
            var H = Scanner.ScanEnumerable<int>().ToArray();
            var list = new List<int>();
            var checker = new bool[N];
            for (var i = 0; i < M; i++)
            {
                var (A, B) = Scanner.Scan<int, int>();
                A--;
                B--;
                if (H[A] < H[B]) checker[A] = true;
                else if (H[A] > H[B]) checker[B] = true;
                else checker[A] = checker[B] = true;
            }
            var answer = checker.Count(x => !x);
            Console.WriteLine(answer);
        }

        public static class Scanner
        {
            private static Queue<string> queue = new Queue<string>();
            public static T Next<T>()
            {
                if (!queue.Any()) foreach (var item in Console.ReadLine().Trim().Split(" ")) queue.Enqueue(item);
                return (T)Convert.ChangeType(queue.Dequeue(), typeof(T));
            }
            public static T Scan<T>() => Next<T>();
            public static (T1, T2) Scan<T1, T2>() => (Next<T1>(), Next<T2>());
            public static (T1, T2, T3) Scan<T1, T2, T3>() => (Next<T1>(), Next<T2>(), Next<T3>());
            public static (T1, T2, T3, T4) Scan<T1, T2, T3, T4>() => (Next<T1>(), Next<T2>(), Next<T3>(), Next<T4>());
            public static (T1, T2, T3, T4, T5) Scan<T1, T2, T3, T4, T5>() => (Next<T1>(), Next<T2>(), Next<T3>(), Next<T4>(), Next<T5>());
            public static IEnumerable<T> ScanEnumerable<T>() => Console.ReadLine().Trim().Split(" ").Select(x => (T)Convert.ChangeType(x, typeof(T)));
        }
    }
}


Measured memory_bytes: 51432
#include <bits/stdc++.h> 
using namespace std; 
  
// Driven Program 
int main() 
{ 
    long long int n;
    cin>>n;
    int a[n];
    long long int h[n+1]={0};
    for(long long int i=0;i<n;i++)
    {
        cin>>a[i];
        h[a[i]]++;
    }
    
    
    long long int l=0;
    for(long long int i=0;i<n+1;i++)
    l+=(h[i]*(h[i]-1))/2;
    for(long long int i=0;i<n;i++)
    cout<<l-(h[a[i]]-1)<<endl;
    
    return 0; 
} 

Measured memory_bytes: 4992
n = gets.chomp.to_i
arr = Array.new(5, 0) # m, a, r, c, h

n.times do
    s = gets.chomp
    case s[0]
    when "M" then
        arr[0] += 1
    when "A" then
        arr[1] += 1
    when "R" then
        arr[2] += 1
    when "C" then
        arr[3] += 1
    when "H" then
        arr[4] += 1
    end
end

res = 5 - arr.count(0)
ans = 0

if res >= 3
    filterArr = arr.select{|num| num != 0}
    com = filterArr.combination(3).to_a
    com.each do |c|
        ans += c.inject(:*)
    end
end

puts ans

Measured memory_bytes: 2044
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<int, int>;
using VI = vector<int>;

int main() {
#ifdef LOCAL_EXEC
//	freopen("sample.in", "r", stdin);
//	freopen("sample.out", "w", stdout);
#else
  ios_base::sync_with_stdio(false); cin.tie(NULL);
#endif

  int n; cin >> n;
  map<string, int> f;
  while (n--) {
    string s; cin >> s;
    f[s]++;
  }

  for (auto s: {"AC", "WA", "TLE",  "RE"}) {
    cout << s << " x " << f[s] << '\n';
  }

  return 0;
}


Measured memory_bytes: 3604
#include <math.h>

#include <algorithm>
#include <iostream>
#include <vector>

using ll = long long;
#define rep(inc, bgn, end) for (int inc = bgn; inc < end; ++inc)
#define repe(inc, bgn, end) for (int inc = bgn; inc <= end; ++inc)

using namespace std;

int main() {
    int l, r;
    cin >> l >> r;
    int div = 2019;
    // int x   = l % div;
    // int y   = r % div;

    int ans = 2020;
    if (((r - l) < div)) {
        repe(i, l, r) {
            repe(j, i + 1, r) {
                ans = min(ans, ((i % div) * (j % div)) % div);
            }
        }
    } else {
        ans = 0;
    }
    cout << ans << endl;
    return 0;
}


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

int main(void){
    int n,q;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)cin>>a[i];
    cin>>q;
    int x,y,z;
    while(q--){
        cin>>x>>y>>z;
        cout<<count(a+x,a+y,z)<<endl;
    }
}


Measured memory_bytes: 3064
import java.util.*;

class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.nextLine());
        String[] line = sc.nextLine().split(" ");
        int[] arr = new int[n];
        int temp;
        int count = 0;
        for(int x = 0; x < n; x++){
            arr[x] = Integer.parseInt(line[x]);
        }

        for(int i = 0;i < n; i++){
            for(int j = n-1; j > i; j--){
                if(arr[j] < arr[j-1]){
                    temp = arr[j-1];
                    arr[j-1] = arr[j];
                    arr[j] = temp;
                    count++;
                }
            }
        }
        for(int x = 0; x < n; x++){
            if(x == n-1){
                System.out.println(arr[x]);
            }else{
                System.out.print(arr[x]);
                System.out.print(" ");
            }
        }
        System.out.println(count);
    }
}

Measured memory_bytes: 26128
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V)) //小さい方からソート
#define REV(V) reverse(ALL(V)) //リバース
#define RSORT(V) SORT(V);REV(V) //大きい方からソート
#define NPN(V) next_permutation(ALL(V)) //順列
#define pb(n) push_back(n)
#define endl '\n'
#define Endl '\n'
#define DUMP(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define yes(n) cout << ((n) ? "yes" : "no"  ) << endl
#define Yay(n) cout << ((n) ? "Yay!": ":(") << endl
#define RAPID cin.tie(0);ios::sync_with_stdio(false)
#define VSUM(V) accumulate(ALL(V), 0)
#define MID(a,b,c) (a) < (b) && (b) < (c)
#define MIDe(a,b,c) (a) <= (b) && (b) <= (c)
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c 
#define IN4(a,b,c,d) cin >> a >> b >> c >> d
#define VIN(V) for(int i = 0; i < (V).size(); i++) {cin >> (V).at(i);}
#define OUT(n) cout << n << endl
#define VOUT(V) REP(i, (V).size()) {cout << (V)[i] << endl;}
#define VOUT2(V) REP(i, (V).size()) {cout << (V)[i] << " ";} cout<<endl;
#define FIX cout << fixed << setprecision(15)

// 型マクロ定義
#define int long long
#define P pair<ll,ll>
#define Vi vector<ll>
#define VVi vector<vector<ll>>
#define Vd vector<double>
#define Vb vector<bool>
#define Vs vector<string>
#define Vc vector<char>
#define M map<ll,ll>
#define S set<ll>
#define PQ priority_queue<ll>
#define PQG priority_queue<ll,V,greater<ll>
//

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;}

const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int gcd(int a,int b){return b != 0 ? gcd(b, a % b) : a;} //最大公約数
int lcm(int a, int b){return a * b / gcd(a, b);}
string toStrUp(string str){char diff = 'A'-'a';REP(i,str.size()) str[i] += diff;return str;}
string gCh(string str, int key){return str.substr(key,1);}

signed main() {
  RAPID;
  // デフォルト変数定義
  int n=0,m=0,a=0,b=0,c=0,d=0,x=0,y=0,z=0;
  string s="",t="";
  //

  // ここから
  IN2(x,y);
  if(x+y==15) OUT("+");
  else if(x*y==15) OUT("*");
  else OUT("x");
}

Measured memory_bytes: 256
import re
import numpy as np

N, Q = [int(item) for item in re.split(r"\s", input())]
S = input()

l = [0] * Q
r = [0] * Q
for i in range(Q):
    l[i], r[i] = [int(item) for item in re.split(r"\s", input())]

# ACの場所を探す
p_list = [0] * N
i = 0
while i < N - 1:
    if S[i:i + 2] == "AC":
        p_list[i] = 1
        i += 2
    else:
        i += 1


cumsum = np.cumsum(p_list)

out_list = []
for q in range(Q):
    # qに答える
    l_i = l[q] - 2
    r_i = r[q] - 2

    if l_i < 0:
        c_l = 0
    else:
        c_l = cumsum[l_i]
    if r_i < 0:
        c_r = 0
    else:
        c_r = cumsum[r_i]
    out_list.append(str(c_r - c_l))

print("\n".join(out_list))


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

using namespace std;

int main(){
  int n;
  std::cin >> n;
  vector<int> p(n);
  for(int i=0; i<n; i++) std::cin >> p[i];

  vector<int> mins(n, p[0]);
  for(int i=1; i<n; i++){
    mins[i] = min(p[i], mins[i-1]);
    // std::cerr << min(p[i], mins[i-1]) << '\n';
  }

  int ans = 0;
  for(int i=0; i<n; i++){
    if( mins[i] >= p[i] ){
      ans += 1;
    }
  }
  std::cout << ans << '\n';
  return 0;
}


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

using namespace std;

int main()
{
    int n;
    string s;

    set <string> items;

    cin >> n;

    while (n--)
    {
        cin >> s;

        items.insert(s);
    }

    cout << items.size() << "\n";

    return 0;
}

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

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            string S = Console.ReadLine();
            string T = Console.ReadLine();
            int ans = 0;
            for(int i = 0; i < S.Length; i++)
            {
                if(S.Substring(i , 1) != T.Substring(i , 1))
                {
                    ans++;
                }
            }
            Console.WriteLine(ans);
        }
    }
}
//int[] N = Console.ReadLine().Split(" ").Select(x => int.Parse(x)).ToArray();

Measured memory_bytes: 36720
#include <iostream>
#include <vector>
using namespace std;
int main(void){
    int N;
    cin >> N;
    vector<long long int> a(N+1), x(N+1);
    for(int i=1; i<=N; i++) {
        cin >> a[i];
        x[1] += a[i] * (i%2==0 ? -1 : 1);
    }
    x[1] = x[1]/2;
    for(int i=2; i<= N; i++) {
        x[i] = a[i-1] - x[i-1];
    }
    
    for(int i=1; i<N; i++) cout << x[i]*2 << " ";
    cout << x[N]*2 << endl;
    return 0;
}


Measured memory_bytes: 2944
import itertools
import bisect
N = int(input())
L = sorted(list(map(int,input().split())))
ans = 0
for i in range(N-2):
    a = L[i]
    for j in range(i+1,N-1):
        b = L[j]
        ind_cmin = j+1
        ind_cmax = bisect.bisect_left(L,a+b)-1
        ans += ind_cmax - ind_cmin + 1
print(ans)

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define lli  long long int   //used int to avoid mle
#define ulli unsigned long long int 
#define ld long double
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define loop(i,a,b) for(lli i=a;i<b;i++)
#define initialize(array,size,value) for(lli i=0;i<size;i++) array[i]=value
#define couta(array,size) for(lli i=0;i<size;i++) cout<<array[i]<<" "
#define vl vector<lli>
#define vp vector< pair <lli,lli> >
#define sl set<lli>
#define spl set<pll>
#define msl multiset <lli>
#define msp multiset <pll>
#define pll pair<lli, lli>
#define mll map<lli, lli>              //for( map<lli, lli>::iterator i=temp.begin();i!=temp.end();i++)cout<<i->fi<<" "<<i->se<<endl;
#define mvl map<lli, vl>
#define umll unordered_map<lli, lli>
#define vt vector<pair<lli, pll >  >
#define vf vector<pair<pll,pll > >
#define qu queue<lli>
#define pq priority_queue<lli>
#define dq deque <lli>
#define ptr vector<lli>::iterator
#define bs(array,x) binary_search(array.begin(),array.end(),x)
#define lb(array,x) lower_bound(array.begin(),array.end(),x)
#define ub(array,x) upper_bound(array.begin(),array.end(),x)
#define nobw(array,i,j) upper_bound(array.begin(), array.end(), j)-lower_bound(array.begin(), array.end(), i) //number of numbers between i & j
#define vc clear()
#define fbo find_by_order //returns iterator
#define fok order_of_key //return index
#define endl '\n'
#define sp system("pause");
#define INF 9223372036854775807
#define MINF -9223372036854775808
#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); cerr << endl << "Time elapsed: " << (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms"; return 0
lli mod=998244353;
lli inf=9223372036854775807;
//string s=bitset<32>(n).to_string();
typedef tree<lli,null_type,less<lli>,rb_tree_tag, // change both to lli if set is req insted of multiset
tree_order_statistics_node_update> indexed_set;
#define UNASSIGNED 0  
//&& + - ! ~ ++ - - () *
lli ani;
int main()
{
	lli n,sum=0;
	cin>>n;
	lli a[n];
	mll freq;
	for(lli i=0;i<n;i++){
		cin>>a[i];
		sum+=a[i];
		freq[a[i]]++;
	}
	lli q;
	cin>>q;
	while(q--){
		lli b,c;
		cin>>b>>c;
		sum+=(c-b)*freq[b];
		freq[c]+=freq[b];
		freq[b]=0;
		cout<<sum<<endl;
		
		
		
	}
	
	
	
	
	
 
    return 0;
}

Measured memory_bytes: 10224
#include<bits/stdc++.h>
using namespace std;
 
int main() {
 
  int w, h;
  while( cin >> h >> w, w+h ) {
    char room[101][101];
    bool flag[101][101];
    int now_x = 0, now_y = 0;
 
    for(int i=0; i<h; i++) {
      for(int j=0; j<w; j++) {
    cin >> room[i][j];
    flag[i][j] = false;
      }
    }
 
    while(1) {
      if( flag[now_y][now_x] || room[now_y][now_x] == '.' ) break;
      char c = room[now_y][now_x];
      flag[now_y][now_x] = true;
      
 
      if( c == '>' ) {
    while( room[now_y][now_x] == c ) {
      now_x++;
    }
      }
      if( c == '<' ) {
    while( room[now_y][now_x] == c ) {
      now_x--;
    }
      }
      if( c == 'v' ) {
    while( room[now_y][now_x] == c ) {
      now_y++;
    }
      }
      if( c == '^' ) {
    while( room[now_y][now_x] == c ) {
      now_y--;
    }
      }
    }
 
    if( room[now_y][now_x] != '.' ) cout << "LOOP" << endl;
    else cout << now_x << " " << now_y << endl;
  }
}

Measured memory_bytes: 1184
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;

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

const int INF = 1e9;
const int MOD = 1e9 + 7;

// 4近傍、8近傍
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main() {
  // 入力
  string s;
  cin >> s;

  int ans = 0;
  int l = 0, r = s.size() - 1;
  while (l < r) {
    if (s[l] != s[r]) {
      if (s[l] == 'x') {
        ans++;
        l++;
      } else if (s[r] == 'x') {
        ans++;
        r--;
      } else {
        ans = -1;
        break;
      }
    } else {
      l++, r--;
    }
  }

  // 解答
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<string>
using namespace std;
 
int main(){
		int a[] = {0,0,2,0,1,0,1,0,0,1,0,1,0};
		int b,c;
		cin >> b >> c;
		cout << (a[b] == a[c] ? "Yes" : "No");
		// cin>>a>>b>>c;
		// cout << a[0] << b[0] << c[0];
		// char d[] = {a[0],b[0],c[0],'\0'};
		// cout << d;
		// const char *a = "dabfab";
		// char a[] = "si"; 
		// int a[2]={1,4};
		//cout << &a[0]<< &a[1] << &a[2];
    return 0;
}


Measured memory_bytes: 256
n=input()
hon=['2', '4', '5', '7', '9']
pon=['0', '1', '6', '8']
bon=['3']
if (n[-1]) in hon:
    print('hon')
elif (n[-1]) in pon:
    print('pon')
elif (n[-1]) in bon:
    print('bon')


Measured memory_bytes: 8948
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define vb vector<bool>
#define pii pair<int,int>
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*b)/gcd(a,b)
#define F first
#define S second
#define inf (long long) 1e18
#define f(i,n)  for(int i=0;i<n;i++)
#define f(i,n) for(int i=n-1;i>=0;i--)
#define f(i,n) for(int i=1;i<=n;i++)

const int MOD = 1e9 + 7;

void solve()
{
    ll h,w;
    cin >> h >> w;
    if(h==1 || w==1)
        cout << "1";
    else
        cout << (h*w+1)/2 << "\n";

}


int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t=1;
  //cin>>t;
  while(t--)
  {
      solve();
  }
}


Measured memory_bytes: 3620
#include "bits/stdc++.h"
using namespace std;
int main(){
    string T;
    cin >> T;
    int i,n=0,w=0,s=0,e=0,ans =1;
    for(i=0;i<T.length();i++){
        switch(T.at(i)){
            case 'S':
                s = 1;
                break;
            case 'N':
                n = 1;
                break;
            case 'W':
                w = 1;
                break;
            case 'E':
                e = 1;
                break;
        }
    }
    if(s+n>0 && s*n == 0) ans = 0;
    if(w+e>0 && w*e == 0) ans = 0;
    if(ans) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define ALL(a) (a).begin(), (a).end()
const ll mod = 1e9 + 7;

int main() {
  int n;
  cin >> n;
  for (int i = 1; i < 10; i++) {
    for (int j = 1; j < 10; j++) {
      if (i * j == n) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
  return 0;
}

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

#define print cout <<
#define printl(s) cout << s << endl;
#define rep(i,n) for (int i = 0; i < (n); ++i)

template <typename T>
vector<T> getValues(int num){
    vector<T> values(num);
    for(int i=0;i<num;i++){
        cin >> values.at(i);
    }
    return values;
}

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

    auto inputs = getValues<string>(N);
    int ac = 0;
    int wa = 0;
    int tle = 0;
    int re = 0;
    rep(i,inputs.size()){
      if(inputs.at(i)=="AC"){
        ac++;
      }else if(inputs.at(i)=="WA"){
        wa++;
      }else if(inputs.at(i)=="TLE"){
        tle++;
      }else if(inputs.at(i)=="RE"){
        re++;
      }
    }
    print "AC x ";
    printl(ac);
    print "WA x ";
    printl(wa);
    print "TLE x ";
    printl(tle);
    print "RE x ";
    printl(re);
}


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

int main(){
    int a,b,d,r;
    double f;
    scanf("%d %d",&a,&b);
    d=a/b;
    r=a%b;
    f=1.0*a/b;
    printf("%d %d %.8lf\n",d,r,f);

    return 0;
}


Measured memory_bytes: 3204
#include <iostream>
#include <string>

using namespace std;

int main()
{
/*
	
*/
	int x;
	cin >> x;

	for (int i = 1; i <= 9; i++) {
		if (x%i == 0 && x/i < 10) {
			cout << "Yes" << endl;
			return 0;
		}
	}

	cout << "No" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long
#define Mod 1000000007
#define Max 100001
#define vt vector<long long>

void func(){
    ll n,d;
    cin>>n>>d;
    ll cnt=0;
    while(n--){
        ll a,b;
        cin>>a>>b;
        if(sqrt((a*a)+(b*b))<=d)
            cnt++;
    }
    cout<<cnt<<endl;
}   
 
int main(){
 
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
 
// 
//int t;
//cin >> t;
//for(ll i=1; i<=t; i++)
//{
    
    func();
//    cout<<endl;
//cout<<func()<<endl;
 
//if(func())
//    cout<<"Yes"<< endl;
//else
//    cout <<"No"<<endl; 
//cout<<"Case"<<" "<<"#"<<i<<":"<<" "<<func()<<endl;
//}
return 0;
}

Measured memory_bytes: 3688
t_point, h_point = 0, 0

n = int(input())
for i in range(n):
    t_card, h_card = input().split()
    if t_card == h_card:
        t_point += 1
        h_point += 1
    elif t_card > h_card:
        t_point += 3
    else:
        h_point += 3
print(t_point, h_point)

Measured memory_bytes: 6724
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<int,int> P;
const ll MOD=1000000007;
const ll MAX_N=500010;
const ll INF=1<<18;

int main(){
    int n;
    cin>>n;
    vector<ll> a(n);
    for(int i=0;i<n;i++) cin>>a[i];
    ll ans=0;
    int now=a[0];
    for(int i=1;i<n;i++){
        if(now<a[i]){
            now=a[i];
        }else{
            ans+=now-a[i];
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 4684
#include "bits/stdc++.h"
using namespace std;

int main(void) {
    string s;
    cin >> s;
    long long ans = 0;
    for (long long i = 1; i < s.length(); ++i) {
        if (s[i] == s[i - 1]) {
            if (s[i] == '0') {
                s[i] = '1';
            }
            else {
                s[i] = '0';
            }
            ++ans;
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 512
#103a
import itertools
a1,a2,a3 = map(int, input().split())

#任意の 1 個のタスクをコスト 0で完了できます。
#また、i番目のタスクを完了した直後にコスト |Aj−Ai| で j番目のタスクを完了できます。
#全てのタスクを完了するのに要する合計コストの最小値を求めてください。
seq = [a1,a2,a3]
ans = a1+a2+a3

for perm in list(itertools.permutations(seq)):
    cost = 0 + abs(perm[1]-perm[0]) + abs(perm[2]-perm[1])
    if cost < ans:
        ans = cost
        
print(ans)

Measured memory_bytes: 3060
# ABC169 B Multiplication 2

from collections import deque

n = int(input())

a_list = [int(x) for x in input().split()]

if min(a_list) == 0:
    print("0")
else:
    a_dq = deque(a_list)
    ans = 1
    for i in range(n):
        ans *= a_dq.popleft()
        if ans > 10**18:
            break

    if ans > 10**18:
        print("-1")
    else:
        print(ans)

Measured memory_bytes: 84388
#include<cstdio>
using namespace std;
const int md=1e9+7;
int n,fac[100010],ifac[100010],sum[100010],x,ans;
int read() {
	int tmp=0, fh=1; char c=getchar();
	while (c<'0'||c>'9') {if (c=='-') fh=-1; c=getchar();}
	while (c>='0'&&c<='9') tmp=tmp*10+c-48, c=getchar();
	return tmp*fh;
}
int main() {
	n=read(); fac[0]=1; ifac[n]=1;
	for (int i=1;i<=n;i++) fac[i]=1ll*fac[i-1]*i%md;
	for (int i=n-1;i;i--) ifac[i]=1ll*ifac[i+1]*(i+1)%md;
	for (int i=1;i<=n;i++) sum[i]=(sum[i-1]+1ll*fac[i-1]*ifac[i])%md;
	for (int i=1;i<=n;i++)
		ans=(ans+1ll*read()*((sum[i]-sum[1]+md)%md+sum[n-i+1])%md)%md;
	printf("%d\n",ans);
}

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

using namespace std;


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

    int n, m;
    cin >> n >> m;
    vector<int> cnts(m + 1, 0);

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

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

    cout << res << '\n';

    return 0;
}

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

const double EPS = 1e-9;

typedef struct
{
  double L, a, b;
} LCS;

int main()
{
  int N, M;
  while (cin >> N >> M) {
    vector<LCS> lcs(N);
    for (int i = 0; i < N; ++i)
      cin >> lcs[i].L >> lcs[i].a >> lcs[i].b;

    double ans = 0.0;
    for (int i = 0; i < (1 << N); ++i) {
      if (__builtin_popcount(i) == M) {
	vector<int> idx;
	for (int j = 0; j < N; ++j) {
	  if (i & (1 << j))
	    idx.push_back(j);
	}

	double tmp = 0.0;
	for (unsigned int j = 0; j < idx.size(); ++j) {
	  for (unsigned int k = j+1; k < idx.size(); ++k) {
	    tmp += (lcs[idx[j]].L-lcs[idx[k]].L)*(lcs[idx[j]].L-lcs[idx[k]].L)
	      + (lcs[idx[j]].a-lcs[idx[k]].a)*(lcs[idx[j]].a-lcs[idx[k]].a)
	      + (lcs[idx[j]].b-lcs[idx[k]].b)*(lcs[idx[j]].b-lcs[idx[k]].b);
	  }
	}

	ans = max(ans, tmp);
      }
    }
    printf("%.20f\n", ans);
  }
  return 0;
}

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

ans_str = " 3"
for i in range(4, n+1):
    if (i % 3) == 0:
        ans_str += " " + str(i)
    else:
        tho = i // 1000
        cto = (i % 1000) // 100
        ten = ((i % 1000) % 100) // 10
        one = ((i % 1000) % 100) % 10
        if tho == 3 or cto == 3 or ten == 3 or one == 3:
            ans_str += " " + str(i)

print(ans_str)



Measured memory_bytes: 5624
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
//#define stop system("pause") //comment out this on AOJ.
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
const ld pi = acos(-1);
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; }return 0; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; }return 0; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

int main() {
    init();

    int n, q; cin >> n >> q;
    VI a(n); cin >> a;
    SORT(a);
    auto solve = [&]() {
        int l, r; cin >> l >> r;
        cout << upper_bound(all(a), r) - lower_bound(all(a), l) << "\n";
    };
    FOR(i, 0, q)solve();
}



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

template<typename T, typename U> bool chmin(T &a, const U &b) {
	return (a > b ? a = b, true : false);
}
template<typename T, typename U> bool chmax(T &a, const U &b) {
	return (a < b ? a = b, true : false);
}

typedef long long ll;

#define writeln(n) cout<<n<<"\n";

typedef pair<int, int> P;
typedef pair<string, int> Psi;

int d[101];
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int n;
	cin>>n;

	for(int i=0; i<n; i++){
		int tmp;
		cin>>tmp;

		d[i] =tmp;
	}
	int mi =1000000000;
	for(int i=1; i<=100; i++){
		int sum=0;
		for(int j=0; j<n; j++){

			sum += (i-d[j])*(i-d[j]);

		}

		mi = min(mi,sum);
	}

	cout<<mi<<endl;

}


Measured memory_bytes: 256
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, n) for (int i = 0; i < n; i++)

int main() {
  int A, B;
  cin >> A >> B;

  int result = 0;
  if (A > B) {
    result += A;
    A--;
  } else {
    result += B;
    B--;
  }
  if (A > B) {
    result += A;
    A--;
  } else {
    result += B;
    B--;
  }

  cout << result << endl;

  return 0;
}


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

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

int main(){
  //入力受け取り
  int H, W; 
  cin >> H >> W;
  vector<string> field(H);
  rep(i,H) cin >> field.at(i);
  
  //壁の数を数える
  int wall = 0;
  rep(i,H)rep(j,W) if(field.at(i).at(j) == '#') wall++;
  
  //BFSの準備
  vector<vector<int>> dist(H, vector<int>(W, -1));
  queue<pint> que;
  dist.at(0).at(0) = 0;
  que.push(make_pair(0,0));
  
  //BFS
  while(!que.empty()){
    pint p = que.front();
    que.pop();
    rep(i,4){
      int nh = p.first + dx[i];
      int nw = p.second + dy[i];
      if(nh < 0 || nh >= H || nw < 0 || nw >= W) continue;
      if(field.at(nh).at(nw) == '#') continue;
      if(dist.at(nh).at(nw) == -1){
        dist.at(nh).at(nw) = dist.at(p.first).at(p.second) + 1;
        que.push(make_pair(nh, nw));
      }else if(dist.at(nh).at(nw) > dist.at(p.first).at(p.second) + 1){
        dist.at(nh).at(nw) = dist.at(p.first).at(p.second) + 1;
        que.push(make_pair(nh, nw));
      }
    }
  }

  if(dist.at(H-1).at(W-1) == -1) cout << -1 << endl;
  else cout << H*W - dist.at(H-1).at(W-1) -1 -wall << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
     int N;
     cin >> N;
     double x;
     string u;
     double ans = 0.0;
     
     for(int i = 0; i < N; i++){
          cin >> x >> u;
          if(u == "BTC"){
               ans += x*380000;
          }else{
               ans += x;
          }
     }

     cout << ans << endl;
}

Measured memory_bytes: 256