akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define bit(n) (1<<(n))
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define yn(x, ok, ng) cout << ((x)?(ok):(ng)) << endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
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;}
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
int const INF = 1001001001;

void err() {
    cout << -1 << endl;
    exit(0);
}

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

string s;
cin >> s;
deque<char> q;
rep(i,SZ(s)) {
    q.push_front(s[i]);
}
int cnt = 0;
while(q.size() >= 2) {
    char f = q.front();
    char b = q.back();
    if(f == b) {
        q.pop_front();
        q.pop_back();
    }
    else {
        if(f == 'x') {
            q.push_back('x');
            cnt++;
        }
        else if(b == 'x') {
            q.push_front('x');
            cnt++;
        }
        else err();
    }
}
cout << cnt << endl;
return 0;
}

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

int main(){
  int N;
  cin>>N;
  int A[1000010];
  int ans=0;
  int temp=0;
  map<int,int>mp;
  for(int i=0;i<N;i++){
    cin>>A[i];
    ans=gcd(ans,A[i]);
  }
  if(ans > 1){
    cout<<"not coprime"<<endl;
    return 0;
  }
  
  int flag=1;
  for(int i=0;i<N;i++){
    if(A[i] !=2){
      mp[A[i]]++;
    }
    temp=A[i];
    if(temp%2==0){
      mp[2]++;
      if(temp/2 != 2){
        mp[temp/2]++;
      }
    }
    for(int j=3;j*j<=A[i];j=j+2){
      if(temp%j==0){
        mp[j]++;
        if(temp/j != j){
          mp[temp/j]++;
        }
        if(mp[j]>1||mp[2]>1){
          flag=0;
          break;
        }
      }
      
    }
    if(flag !=1){
      break;
    }
  }
  
  for(auto itr=mp.begin();itr != mp.end();itr++){
    if(itr-> first != 1 && itr->second > 1){
      flag=0;
    }
    //cout<<itr->first<<" "<<itr->second<<endl;
  }
  
  if(flag){
    cout<<"pairwise coprime"<<endl;
    return 0;
  }
  else{
    cout<<"setwise coprime"<<endl;
    return 0;
  }
  
  return 0;
}



 

Measured memory_bytes: 7544
import java.util.stream.IntStream;
public class Main {
    public static void main(String[] args) {
        IntStream.of(1,2,3,4,5,6,7,8,9).forEach(n -> IntStream.of(1,2,3,4,5,6,7,8,9).forEach(m -> System.out.println(n + "x" + m + "=" + (n*m))));
    }
}

Measured memory_bytes: 30292
#include<stdio.h>

int main(void)
{
    char alf;

    if(scanf("%c",&alf) != 1){
        printf("アルファベットを入力してください\n");
        return -1;
    }

    if('A' <= alf && alf <= 'Z'){
        printf("A\n");
    } else if('a' <= alf && alf <= 'z'){
        printf("a\n");
    } else{
        printf("アルファベットを入力してください\n");
    }

    return 0;
}


Measured memory_bytes: 1600
import org.w3c.dom.ls.LSOutput;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.nio.Buffer;
import java.util.*;

public class Main {
    public static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }

    public static FastReader r=new FastReader();
    public static void main(String[] args){
        int n=r.nextInt();
        int k=r.nextInt();
        int []a=new int[n+5];
        for(int i=0;i<n;++i){
            a[i]=r.nextInt();
        }
        final int mod=1000000007;
        int []dp=new int[100005];
        dp[0]=1;
        for(int i=0;i<n;++i){
            int x=a[i];
            int []fake_add=new int[k+1];
            for(int sum=k;sum>=0;--sum){
                int add=dp[sum];
                int l=sum+1;
                int r=sum+Math.min(x,k-sum);
                if(l<=r){
                    fake_add[l]=(fake_add[l]+add)%mod;
                    if(r+1<=k) fake_add[r+1]=(fake_add[r+1]-add+mod)%mod;
                }
            }
            int tot=0;
            for(int j=0;j<=k;++j){
                tot=(tot+fake_add[j])%mod;
                dp[j]=(dp[j]+tot)%mod;
            }
        }
        System.out.println(dp[k]);
    }
}


Measured memory_bytes: 51368
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
#======================================================#
def main():
    n, k = MII()
    xx = MII()
    minv = 3*10**8
    for i in range(n-k+1):
        l = xx[i]
        r = xx[i+k-1]
        if l < 0 and r <= 0:
            minv = min(abs(l),minv)
            continue
        if l < 0 and r > 0:
            minv = min(min(abs(l),r)*2+max(abs(l),r), minv)
            continue
        if l >= 0:
            minv = min(r, minv)
            continue
    print(minv)


if __name__ == '__main__':
    main()

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

int main() {
	int A,B,C,D;
	int R,S,E;
	cin >> A >> B >> C >> D;
	
	if (A >= C){
		S = A;
	}else{
		S = C;
	}
	
	if (B <= D){
		E = B;
	}else{
		E = D;
	}
	R = E - S;
	if (R < 0){
		R = 0;
	}
	cout << R;
	return 0;
}

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

int main() {

	int i,N, M;
	vector<string> blue,red, check;
	string st;

	cin >> N;
	for (i = 0; i < N; ++i) {
		cin >> st;
		blue.emplace_back(st);
	}
	sort(blue.begin(), blue.end());
	cin >> M;
	for (i = 0; i < M; ++i) {
		cin >> st;
		red.emplace_back(st);
	}
	sort(red.begin(), red.end());
	check = blue;
	unique(check.begin(), check.end());
	check.shrink_to_fit();

	vector<int> ans(size_t(check.size()), 0);

	for (i = 0; i < size_t(check.size()); ++i) {
		for (auto r : red) {
			if (check[i] == r) {
				--ans[i];
			}
		}
		for (auto b : blue) {
			if (check[i] == b) {
				++ans[i];
			}
		}
		if (ans[i] < 0)ans[i] = 0;
	}

	cout << *max_element(ans.begin(), ans.end()) << endl;

	return 0;
}

Measured memory_bytes: 256
import fractions
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

A, B, C, D = map(int, input().split())
E = lcm(C, D)

def mulc(t) :
    return (B//t - (A-1)//t)

print((B-A+1) - mulc(C) - mulc(D) + mulc(E))


Measured memory_bytes: 5304
#include <stdio.h>

int main(){
  int debt,i,n;
  while(scanf("%d",&n)!=EOF){
	debt=100000;
	for(i=0;i<n;i++){
	  debt = (debt*1.05+999)/1000;
	  debt = debt*1000;
	}
	printf("%d\n", debt);
  }
  return 0;
}

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

using namespace std;

int n;
vector<double> p;
// vector<vector<double>> dp;
vector<double> dp;

int main(){
    cin>>n;
    p.assign(n+1, 0.0);
    // dp.assign(n+1, vector<double>(n+1, 0.0));
    dp.assign(n+1, 0.0);
    for(int i = 1; i <= n; i++){
        cin>>p[i];
    }
    double cur = 1.0;
    // for(int i = 0; i <= n; i++){
    //     cur *= (1.0 - p[i]);
    //     dp[i][0] = cur;
    // }
    // for(int i = 1; i <= n; i++){
    //     for(int j = 1; j <=n; j++){
    //         dp[i][j] = (dp[i-1][j-1] * p[i]) + (dp[i-1][j] * (1.0 - p[i]));
    //     }
    // }
    dp[0] = 1.0;
    for(int i = 1; i <= n; i++){
        cur *= (1.0 - p[i]);
        auto dpt = dp;
        for(int j = 1; j <=n; j++){
            dpt[j] = (dp[j-1] * p[i]) + (dp[j] * (1.0 - p[i]));
        }
        dpt[0] = cur;
        dp = dpt;
    }
    double res = 0.0;
    for(int i = n/2 + 1; i <= n; i++){
        res += dp[i];
    }
    cout<<setprecision(10);
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.math.BigInteger
import java.util.Scanner

import scala.annotation.tailrec

object Main extends App {
  val sc = new Scanner(System.in)
  val N = sc.nextInt
  val As = Seq.fill(N)(BigInt(sc.nextBigInteger))

  val limit = BigInt("1000000000000000000")

  if (As.contains(BigInt(BigInteger.ZERO))) {
    println(0)
  } else {
    println(loop(BigInt(BigInteger.ONE), As))
  }

  @tailrec def loop(acc: BigInt, li: Seq[BigInt]): BigInt = li match {
    case _ if acc > limit => BigInt(-1)
    case head +: tail => loop(acc * head, tail)
    case _ => acc
  }

}


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

 using namespace std;
 typedef long long ll;

 int main() {
   int N;
   cin >> N;
   vector<int> A(N);
   int minus = 1;

   for (int i = 0; i < N; i++) {
     cin >> A.at(i);
     if (A.at(i)  % 2 == 0) minus *= 2;
   }

   cout << pow(3, N) - minus << endl;
 }


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<vector>
#include<cmath>
#include<queue>
#include<string.h>
#include<map>
#include<set>
#include<algorithm>
#define ll long long
#define pi pair < ll,ll >
#define mp(a,b) make_pair(a,b)
#define rep(i,a,b) for(int i = a;i < b;i++)
#define N 100004

using namespace std;

ll n,ar[N],freq[N][2],ans;
ll max1[2],max2[2];

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

    cin >> n;

    rep(i,0,n)
    {
        cin >> ar[i];

        freq[ar[i]][i%2]++;
    }

    rep(j,0,2)
    {
        rep(i,0,N)
        {
            if(freq[max1[j]][j] <= freq[i][j])
            {
                max2[j] = max1[j];
                max1[j] = i;
            }
            else if(freq[max2[j]][j] <= freq[i][j])
            {
                max2[j] = i;
            }
        }
    }

    if(max1[0] == max1[1])
    {
        ans = min(n - freq[max1[0]][0] - freq[max2[1]][1],n - freq[max1[1]][1] - freq[max2[0]][0]);
    }
    else
    {
        ans = n - freq[max1[0]][0] - freq[max1[1]][1];
    }

    cout << ans;

    return 0;
}


Measured memory_bytes: 2560
import sys
# sys.setrecursionlimit(100000)


def input():
    return sys.stdin.readline().strip()


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():
    # 入力
    n, x = input_int_list()
    A = [0] + input_int_list() + [0]
    ans = 0
    # 方針
    # 貪欲にi+1を減らしていく
    for i in range(n + 1):
        if A[i] + A[i + 1] > x:
            dif = min(A[i + 1], A[i] + A[i + 1] - x)
            ans += dif
            A[i + 1] -= dif

    print(ans)
    return


if __name__ == "__main__":
    main()


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

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    int K; 
    cin >> K;

    int M = max(a, max(b, c));
    int S = a+b+c;

    for(int i=1; i<=K; i++){
        S += M;
        M *= 2;
    }

    cout << S << endl;
}


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

int main(){
	string S;
	string T;

	cin >> S ;
	cin >> T ;

	int atr = 0;

	for(int i; i < S.length(); i++){
		if(S[i] == T[i]){
		 atr ++ ;
		}
	}

	cout << atr << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

#define ll long long
#define INF 1<<31-1
#define LNF 9223372036854775807
#define PI 3.14159265358979
#define MIN(x,y) ((x)<(y)?(x):(y))
#define MAX(x,y) ((x)<(y)?(y):(x))
#define FOR(i,a,n) for(i=a;i<n;i++)
#define MOD 1000000007
//#define MOD 998244353
#define NUM 200010
 
void swap(int* a,int* b){int tmp=*a;*a=*b;*b=tmp;}
int abs(int a){if(a<0)return -a;return a;}
int dup(int a,int d){if(a%d==0)return a/d;else return a/d+1;}
int mod(int a,int m){if(a<0)return a%m+m;else return a%m;}

void swapl(ll* a,ll* b){ll tmp=*a;*a=*b;*b=tmp;}
ll absl(ll a){if(a<0)return -a;return a;}
ll dupl(ll a,ll d){if(a%d==0)return a/d;else return a/d+1;}
ll modl(ll a,ll m){if(a<0)return a%m+m;else return a%m;}

ll GCD(ll a,ll b){ll c=1,tmp=MAX(a,b);b=MIN(a,b);a=tmp;while(c!=0){c=a%b;a=b;b=c;}return a;}
ll LCM(ll a,ll b){return a*b/GCD(a,b);}

ll factorial(ll n, ll m) {return n < m ? 1 : n*factorial(n-1, m);}

int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}

// ll dp[]

int main(){
    ll n;


  scanf("%lld", &n);
  n = n % 10;

  if(n == 3){
      printf("bon\n");
  }else if (n == 0 || n == 1 || n== 6 || n == 8)
  {
      printf("pon\n");
  }
  else
  {
      printf("hon\n");
  }
  

  return 0;
}

Measured memory_bytes: 1660
S = input()
T = input()
len_S, len_T = len(S), len(T)
result = 10**8
for i in range(len_S-len_T+1):
  R = 0
  for j in range(len_T):
    if S[i+j] != T[j]:
      R += 1
  result = min(result, R)
print(result)

Measured memory_bytes: 9120
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n,k,s=LI()
  ans=[]

  for i in range(k):
    ans.append(s)

  for i in range(n-k):
    if s!=10**9:
      ans.append(s+1)
    else:
      ans.append(s-1)

  return ' '.join([str(x) for x in ans])

# main()
print(main())


Measured memory_bytes: 17812
import sys
def input():
    return sys.stdin.readline()[:-1]
n,m=map(int,input().split())
ab=[]
c=[]
li=[0]*n
for i in range(m):
    ab.append(list(map(int,input().split())))
    c.append(list(map(int,input().split())))
    for j in range(len(c[i])):
        li[c[i][j]-1]+=1
if min(li)==0:
    print(-1)
    exit()
dp=[[float('inf')]*(2**n) for i in range(2)]
for i in range(2):
    dp[i][0]=0

li=[]
for i in range(m):
    tmp=0
    for j in range(ab[i][1]):
        tmp+=2**(c[i][j]-1)
    li.append(tmp)
# print(li)
# print(dp)
# print(2**n)
for i in range(m):
    for j in range(2**n):
        # tmp=j|li[i]
        # print(i,j,li[i],tmp)
        dp[i+1][j|li[i]]=min(dp[i+1][j|li[i]],dp[i+1][j]+ab[i][0])
        dp.append(dp[-1])
print(dp[-1][-1])

Measured memory_bytes: 164684
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn read_n<T: FromStr>(n: u32) -> Vec<T> {
    read_n_logic::<T>(n, vec![])
}

fn read_n_logic<T: FromStr>(n: u32, mut a: Vec<T>) -> Vec<T> {
    match n {
        0 => a,
        _ => {
            a.push(read::<T>());
            read_n_logic(n - 1, a)
        }
    }
}

fn all_combinations(c: &Vec<u32>, r: u32) -> Vec<u32> {
    let mut queue: Vec<u32> = vec![];
    for i in 0..c.len() {
        for j in i + 1..c.len() {
            queue.push(c[i]);
            queue.push(c[j]);
        }
    }

    let mut result: Vec<u32> = vec![];
    let max = queue.len() as u32 / r;
    for _ in 0..max {
        let mut sum = 0;
        for _ in 0..r {
            sum += queue.pop().unwrap();
        }
        result.push(sum);
    }
    result
}

fn main() {
    let mut c = read_n::<u32>(3);
    c.sort();
    let largest = c.pop().unwrap();

    match all_combinations(&c, 2).iter().any(|i| *i == largest) {
        true => println!("Yes"),
        false => println!("No"),
    };
}


Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>

using namespace std;

int N;
int a[100000];
set<int> s;
vector<int> v;

int main(){
    cin >> N;
    for(int i=0;i<N;i++) cin >> a[i];
    for(int i=0;i<N;i++){
        if(s.find(a[i]) == s.end()){
            s.insert(a[i]);
        }else{
            s.erase(a[i]);
            v.push_back(a[i]);
        }
    }
    sort(v.begin(),v.end(),greater<int>());
    if(v.size()<2){
        cout << 0 << endl;
        return 0;
    }
    cout << (long long)v[0] * v[1] << endl;
    return 0;
}

Measured memory_bytes: 5376
/**
class cfmaster {
 public:
  struct code {
  	see the details down there !
  };
};
**/
#include <bits/stdc++.h>
 
using namespace std;
 
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int x, a;
  cin >> x >> a;
  if (x < a) {
    cout << 0;
  }
  else {
    cout << 10;
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

int main(){

  string s;
  unsigned long long k;
  cin >> s;
  cin >> k;
  int kl = log10(k)+1;

  string result;
  int rl = 0;

  for (size_t i = 0; i < s.size(); i++) {
    if (s[i] == '1'){
      result = s[i];
      rl += 1;
      if (k <= rl){
        break;
      }
    }
    else {
      result = s[i];
      break;
    }
  }
  cout << result << endl;

  /*
  if ((s[0] == '1') && (k == 1)){
    result = '1';
  }
  else {
    for (size_t i = 0; i < s.size(); i++) {
      if (s[i] == '1'){
        rl += 1;
        result = s[i];
      }
      else {
        rl += 16;
        result = s[i];
      }

      if (kl <= rl){
        break;
      }
    }
  }
  */

  /*
  for (size_t i = 0; i < s.size(); i++) {
    if (s[i] == '1'){
      rl += 1;
      result = s[i];
    }
    else {
      rl += 17;
      result = s[i];
    }
    if (kl < rl){
      break;
    }
  }

  cout << result << endl;
  */

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int main(void){
  char s[10], t[10];
  int a, b;
  char u[10];
  
  scanf("%s %s", s, t);
  scanf("%d %d", &a, &b);
  scanf("%s", u);
  
  if(strcmp(s, u) == 0){
    printf("%d %d", a-1, b);
  }else{
  	printf("%d %d", a, b-1);
  }
  return 0;
}

Measured memory_bytes: 128
import itertools
n=int(input())
l=sorted(list(map(int,input().split())))
ans=0
C=itertools.combinations(range(n),3)
for a,b,c in C:
    if l[a]+l[b]>l[c] and l[a]!=l[b] and l[b]!=l[c] and l[a]!=l[c]:
        ans+=1
print(ans)


Measured memory_bytes: 9212
#include<bits/stdc++.h>
using namespace std;
#define ll long long
namespace io{
	const int l=1<<20;
	char buf[l],*s,*t;
	inline char gc(){
		if(s==t){
			t=(s=buf)+fread(buf,1,l,stdin);
			return s==t?EOF:*s++;
		}
		return *s++;
	}
	char c;
	template<class IT>inline void gi(IT &x){
		x=0;c=gc();while(c<'0'||c>'9')c=gc();
		while('0'<=c&&c<='9'){x=(x<<1)+(x<<3)+(c^48);c=gc();}
	}
};
using io::gi;
template<class IT>inline void _int(      IT &a,      IT &b  ){if(a>b)swap(a,b);}
template<class IT>inline void cmin(      IT &a,const IT &b=0){if(a>b)a=b;}
template<class IT>inline void cmax(      IT &a,const IT &b=0){if(a<b)a=b;}
template<class IT>inline IT   _min(const IT &a,const IT &b=0){return a>b? b:a;}
template<class IT>inline IT   _max(const IT &a,const IT &b=0){return a<b? b:a;}
template<class IT>inline IT   _abs(const IT &a              ){return a<0?-a:a;}

const int N=200005;

struct qwq{
	int a,b;
	inline qwq(){}
	inline qwq(int a,int b):a(a),b(b){}
	inline bool operator<(const qwq &x)const{return a<x.a;}
};

int main(){
//	freopen("a.in","r",stdin);
//	freopen("a.out","w",stdout);
	int s,i;
	ll n;
	scanf("%lld",&n);s=sqrt(n);
	for(i=s;i;--i)if(!(n%i)){printf("%lld",n/i+(i-2));return 0;}
	return 0;
}

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

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

using ll = long long;

int dp[3100][3100];

int main() {
  string S, T;
  cin >> S >> T;
  int n = S.size();
  int m = T.size();
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (i==0 || j==0) dp[i][j] = 0;
      if (S.at(i) == T.at(j)) dp[i+1][j+1] = max(dp[i][j]+1, max(dp[i][j+1], dp[i+1][j]));
      else {
        dp[i+1][j+1] = max(dp[i+1][j], dp[i][j+1]);
      }
    }
  }
  int i = n;
  int j = m;
  string ans;
  while (i>0&&j>0) {
    if(dp[i][j] == dp[i-1][j]) {
      i--;
    }
    else if(dp[i][j] == dp[i][j-1]) {
      j--;
    }
    else {
      i--;
      j--;
      ans = S.at(i) + ans;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 37120
#include <iostream>
#include <algorithm>
#include <stdio.h>
using namespace std;
typedef long long ll;

ll Cc(ll n, ll m)
{
    if (m > n / 2)
        m = n - m;
    ll a = 1, b = 1;
    for (int i = 1; i <= m; i++)
    {
        a *= n + 1 - i;
        b *= i;
        if (a % b == 0)
        {
            a /= b;
            b = 1;
        }
    }
    return a / b;
}
const int maxn = 1e5 * 2 + 2;
int a[maxn], num[maxn];
ll c[maxn];
int main()
{
    int n;
    scanf("%d", &n);
    int mm = 0;
    for (int i = 1; i <= n; i++)
    {
        scanf("%d", &a[i]);
        mm = max(a[i], mm);
        num[a[i]]++;
    }
    for (int i = 2; i <= n; i++)
        c[i] = Cc(i, 2);
    ll ans = 0;
    for (int i = 1; i <= mm; i++)
        if (num[i])
            ans += c[num[i]];

    for (int i = 1; i <= n; i++)
    {
        // ll t = ans;
        // t -= c[num[a[i]]];
        // t += c[num[a[i]] - 1];

        ll ansn = ans;
        ansn -= c[num[a[i]]];
        ansn += c[num[a[i]] - 1];
        printf("%lld\n", ansn);
    }
    return 0;
}

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

int main() {
    int N; cin >> N;
    vector<ll> a(N, 0);
    ll maxf = 0, maxs = 0;
    rep(i, N) {
        cin >> a.at(i);
        if(a.at(i) <= maxf) maxs = max(maxs, a.at(i));        
        maxf = max(maxf, a.at(i));

    }
    
    rep(i, N){
        if(a.at(i) == maxf) cout << maxs << endl;
        else cout << maxf << endl;
    }

}

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

int gcd(int a, int b)  {
    while(b) {
        int tmp = a;
        a = b;
        b = tmp % b; 
    }

    return a;
}


int main(){

    int A, B;
    cin >> A >> B;

    int common = gcd(A, B);

    long long int total = (long long int)A * B;

    cout << total/common << endl;

    return 0;
}


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

using namespace std;
typedef long long int ll;
#define space " "
#define vi vector<int>
#define pb push_back

int main() {
    int k;
    cin >> k;
    queue<ll> q;
    for (int i = 1; i < 10; i++) q.push(i);
    ll ans = 0;
    while (k--) {
        ans = q.front();
        q.pop();
        int mod = ans % 10;
        if (mod > 0) {
            q.push(ans * 10 + (mod - 1));
        }
        q.push(ans * 10 + mod);
        if (mod < 9) {
            q.push(ans * 10 + mod + 1);
        }
    }
    cout << ans << endl;
    return 0;

}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double lb;
#define REP(i,j,n) for (int i=j;i<(n);i++)
#define RREP(i,j,n) for (int i = j; n<i;i--)
#define print(out) cout<< out  << "\n";
#define mod 1000000007
const int INF = 1e9;

bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}

int main(){
  int N;cin>>N;
  for(int i=N;;i++){
    if(IsPrime(i)){
      print(i);
      return 0;
    }
  }

}


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

struct edge{
    int u, v;
    double w;
    edge(){u=v=w=0;}
    edge(int uu, int vv, double ww){
        u=uu; v=vv; w=ww;
    }
    bool operator < (const edge& b) const {
        return w>b.w;
    }
};

struct point{
    int first, second;
    point(){first=second=0;}
    point(int xx, int yy){ first=xx; second=yy;}
};
const int MAX_N=10001;
//pair<int, int> points[MAX_N];
const int MAX_M=MAX_N*(MAX_N-1)/2;
//edge edges[MAX_M];
////point points[MAX_N];//start from point_1

int par[MAX_N];
int val[MAX_N];
void init(int n){
    for(int i=1; i<=n; i++){
        par[i]=i;
        val[i]=0;
    }
}

int find(int x){
    int root=x;
    while(root!=par[root]) root=par[root]; 
    while(x!=root){
        int t=par[x];
        par[x]=root;
        x=t;
    }
    return root;
}

bool same(int x, int y){
    x=find(x); y=find(y);
    return x==y;
}

void unite(int x, int y){
    x=find(x); y=find(y);
    if(x==y) return;
    if(val[x]<val[y]) par[x]=y;
    else par[y]=x;
    if(val[x]==val[y]) val[x]++;
}

int main(){
    int N, M; 
    cin>>N>>M;
    point* points=new point[2*N];
    edge* edges=new edge[M];
        for(int i=1; i<=N; i++){
            cin>>points[i].first>>points[i].second;
        }
        int p, q;
        int x1, x2, y1, y2;
        for(int i=0; i<M; i++){
            cin>>p>>q;
            edges[i].u=p; edges[i].v=q;
        	x1=points[p].first; x2=points[q].first;
        	y1=points[p].second; y2=points[q].second;
            edges[i].w=sqrt((x1-x2)*(x1-x2)
                          +(y1-y2)*(y1-y2));
        }
        sort(edges, edges+M);
        double res=0;
        init(N);
        for(int i=0; i<M; i++){
            int p=edges[i].u, q=edges[i].v;
            if(same(p,q)){
                res+=edges[i].w;
            }
            else{
                unite(p, q);
            }
        }
        printf("%.3lf", res);
    delete[] points;
    delete[] edges;
}


Measured memory_bytes: 3640
import java.util.Scanner;
     
class Main{
    public static void main(String arg[]) {
        Scanner sc = new Scanner(System.in);
        
        String S = sc.nextLine();
        sc.close();
        String[] ope = {"+","-"};
        int ans = 0;
        String[] s = S.split("");

        int A = Integer.parseInt(s[0]);
        int B = Integer.parseInt(s[1]);
        int C = Integer.parseInt(s[2]);
        int D = Integer.parseInt(s[3]);
       
        for(int i = 0; i < 2; i++) {    
            for(int j = 0; j < 2; j++) {
                for(int k = 0; k < 2; k++) {
                    int sum = A;
                    sum += (i == 0) ? 0 - B : B;
                    sum += (j == 0) ? 0 - C : C;
                    sum += (k == 0) ? 0 - D : D;
 
                    if (sum == 7) {
                        String ope1 = (i == 0) ? "-" : "+";
                        String ope2 = (j == 0) ? "-" : "+";
                        String ope3 = (k == 0) ? "-" : "+";
                        System.out.println(A + ope1 + B + ope2 + C + ope3 + D + "=7");
                        System.exit(0);
                    }
                }
            }
        }
    }
}

Measured memory_bytes: 23508
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<char> vchar;
typedef vector<vector<char>> vvchar;
typedef vector<int> vint;
typedef vector<vector<int>> vvint;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
typedef priority_queue<long long> prque;
#define ain(i,n,a) for(long long i=0;i<(long long)(n);i++){cin>>a[i];}
#define aout(i,n,a) for(long long i=0;i<(long long)(n);i++){if(i){cout<<" ";}cout<<a[i];if(i==n-1){cout<<endl;}}
#define rep(i,n) for(long long i=0;i<(long long)(n);i++)
#define vsort(v) sort((v).begin(),(v).end())
#define vrsort(v) sort((v).rbegin(),(v).rend())
#define vreverse(v) reverse((v).begin(),(v).end())
#define pf(a) push_front(a)
#define pb(a) push_back(a)
#define INF 1998021900
#define MOD 1000000007
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  //input
  ll k;cin>>k;cout<<3*k*k<<endl;
  //caricurate
  //output
}

Measured memory_bytes: 256
// OURL: https://atcoder.jp/contests/abc132/tasks/abc132_b
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define RREP(i,a,n) for(int i=(a),i##_len=(n);i<i##_len;++i)
#define MAT1D(V,T,a) vector<T> V (a)
#define MAT2D(V,T,a,b) vector<vector<T>> V (a, vector<T>(b))
#define MAT3D(V,T,a,b,c) vector<vector<vector<T>>> V (a, vector<vector<T>>(b, vector<T>(c)))


// http://beet-aizu.hatenablog.com/entry/2018/04/08/145516
template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){ return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...)); }

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}
template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){ for(auto &e:t) fill_v(e,v); }

template <typename A>
string to_string(A v) { bool first = true; string res = "{"; for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); } res += "}"; return res; }

string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string) s); }
string to_string(bool b) { return (b ? "true" : "false"); }
string to_string(vector<bool>::reference b) { return to_string(bool(b)); }
template <typename A, typename B>
string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A>
string to_string(vector<vector<A>> v) { string res; for(const auto &x : v) {res+="\n ";res += to_string(x);} return res;}

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); }

#ifdef LOCAL
#define debug(...) cerr << "[L" << to_string(__LINE__) << ":" <<#__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n,p1,p2,p3;
  cin >> n;
  cin >> p1 >> p2;
  int ans = 0;
  REP(i,n-2) {
    cin >> p3;
    if (p2 < p3 && p2 >= p1) ans++;
    else if(p2 < p1 && p2 >= p3) ans++;

    p1 = p2; p2 = p3;
  }
  cout << ans<< endl;
  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define ALL(x) x.begin(), x.end()
#define LEN(x) (int)x.size()
#define iostreamBooster() do{ cin.tie(nullptr); ios_base::sync_with_stdio(false); }while(0)
using namespace std;
typedef int64_t i64;
typedef pair<int,int> pii;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF = 0x3f3f3f3f;

signed main()
{
  int K, N;
  int a[105];
  priority_queue<pii> pq;

  cin >> K >> N;
  for (int i = 0; i < N; ++i) {
    cin >> a[i];
    pq.emplace(a[i], i);
  }

  int before = -1;
  int ans = 0;

  while(pq.size() >= 2) {
    auto p = pq.top(); pq.pop();
    auto q = pq.top(); pq.pop();

    if (p.second == before) ++ans;

    before = q.second;
    if (--p.first > 0) pq.emplace(p);
    if (--q.first > 0) pq.emplace(q);
  }

  int n = ( pq.empty() ? 0 : (pq.top().first - 1) );

  cout << ans+n << endl;


  return 0;
}



Measured memory_bytes: 256
n = int(input())
s = list(input())
r = 0
g = 0
b = 0
if (n==3):
    print(0)
    exit()


for i in range(n):
    if (s[i]=="R"):
        r += 1
    elif (s[i]=="G"):
        g += 1
    else:
        b += 1
da = r*g*b
count = 0
if (n%2==1):
    for i in range (0,n//2):
        for j in range(0,n-2*(i+1)):
            if (s[j]!=s[j+i+1] and s[j+i+1]!=s[j+2*(i+1)] and s[j+2*(i+1)]!=s[j]):
                count += 1
else:
    for i in range (0,n//2-1):
        for j in range(0,n-2*(i+1)):
            if (s[j]!=s[j+i+1] and s[j+i+1]!=s[j+2*(i+1)] and s[j+2*(i+1)]!=s[j]):
                count += 1
                      
print(da -count)

Measured memory_bytes: 9284
import sys
input = sys.stdin.readline

N, M = map(int, input().split())
L = [list(map(int, input().split())) for _ in range(N)]
ans = [0] * M

for i in range(N):
    v = L[i]
    s = v[1:v[0] + 1]
    
    for v in s:
        ans[v - 1] += 1
        
print(len([v for v in ans if v == N]))

Measured memory_bytes: 3064
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<memory>
using namespace std;

typedef struct Node {
    int key;
    Node *parent, *left, *right;
} Node;

Node *NIL, *root;

void inorder(Node *u) {
    if (u==NIL) return;
    inorder(u->left);
    printf(" %d", u->key);
    inorder(u->right);
}

void preorder(Node *u) {
    if (u==NIL) return;
    printf(" %d", u->key);
    preorder(u->left);
    preorder(u->right);
}

void insert(int k) {
    Node *y = NIL;
    Node *x = root;
    Node *z;

    z = new Node;
    z->key = k;
    z->left = NIL;
    z->right = NIL;
    while (x!=NIL) {
        y=x;
        if (z->key < x->key) {
            x = x->left;
        } else {
            x = x->right;
        }
    }
    z->parent = y;
    if (y==NIL) root = z;
    else {
        if (z->key < y->key) {
            y->left = z;
        } else {
            y->right = z;
        }
    }
}

Node *find(int k) {
    Node *x = root;
    while (x!=NIL) {
        if (x->key == k) return x;
        if (x->key > k) {
            x = x->left;
        } else {
            x = x->right;
        }
    }
    return NIL;
}

Node *getSuccessor(Node *z) {
    z = z->right;
    while (z->left!=NIL) z=z->left;
    return z;
}

void Delete(int k) {
    Node *x, *y, *z;
    z = find(k);
    y = z->parent;
    x = NIL;

    if (z->left==NIL && z->right==NIL) {
        if (y->left==z) y->left=NIL;
        else if (y->right==z) y->right=NIL;
    } else if (z->left==NIL || z->right==NIL) {
        if (z->left!=NIL) x=z->left;
        else x=z->right;
        x->parent=y;
        if (y->left==z) {
            y->left=x;
        } else if (y->right==z) {
            y->right=x;
        }
    } else {
        x = getSuccessor(z);
        if (x->parent==z) {
            if (y->left==z) y->left=x;
            else y->right=x;
            x->parent=y;
            x->left=z->left;
        } else {
            x->parent->left=x->right;
            x->right->parent=x->parent;
            if (z->parent->left==z) {
                z->parent->left=x;
            } else if (z->parent->right==z) {
                z->parent->right=x;
            }
            x->left=z->left;
            x->right=x->right;
        }
    }

    if (y==NIL) root=x;
    delete z;
}

int main() {
    int i, n, x;
    Node *t;
    string com;

    scanf("%d", &n);
    for (i=0; i<n; i++) {
        cin >> com;
        if (com=="insert") {
            scanf("%d", &x);
            insert(x);
        } else if (com=="find") {
            scanf("%d", &x);
            t = find(x);
            if (t!=NIL) printf("yes\n");
            else printf("no\n");
        } else if (com=="print") {
            inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");
        } else if (com=="delete") {
            scanf("%d", &x);
            Delete(x);
        }
    }

    return 0;
}


Measured memory_bytes: 22064
#include <stdio.h>

int main(void) {
    int DATA[31], N, i, M, num, j, tmp;
    for (i = 0; i < 31; i++) DATA[i] = 0;
    scanf("%d%d", &N, &M);
    for (i = 0; i < N; i++) {
        scanf("%d", &num);
        for (j = 0; j < num; j++) {
            scanf("%d", &tmp);
            DATA[tmp]++;
        }
    }
    num = 0;
    for (i = 0; i < 31; i++) {
        if (DATA[i] == N) {
            num++;
        }
    }

    printf("%d\n", num);
    return 0;
}


Measured memory_bytes: 128
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {x: usize};

    if x == 2 || x == 3 {
        println!("{}", x)
    } else {
        for i in x..10000000000 {
            let mut k = true;
            let mut j = 3;
            while j <= (i as f64).sqrt() as usize + 2 {
                if i % j == 0 || i % 2 == 0 {
                    k = false;
                    break;
                }
                j += 2;
            }
            if k {
                println!("{}", i);
                break;
            }
        }
    }
}


Measured memory_bytes: 2172
#define _USE_MATH_DEFINES

#include <iostream>
#include <cstdio>
#include <memory>
#include <string>
#include <cstdlib>
#include <set>
#include <utility>
#include <vector>
#include <list>
#include <algorithm>
#include <regex>
#include <cmath>
#include <map>
#include <iterator>
#include <climits>
#include <numeric>
#include <bitset>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <array>
#include <valarray>
#include <complex>
#include <random>
#include <functional>
#include <cassert>
#include <chrono>
#include <memory>

using namespace std;

#define int long long
//region TEMPLATE
////@formatter:off
#define double long double
typedef long long ll;
typedef unsigned long long ull;
template<typename T>void __read(T &a) { cin >> a; }
template<typename T, typename ... Args> void __read(T &a, Args &... args) { cin >> a;__read(args...);}
#define make(t, ...) t __VA_ARGS__; __read(__VA_ARGS__)
#define makev(a, n) VI a(n); FOR(n) cin >> a[i];
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define FORIT(p) for(auto it = p.begin(); it != p.end(); it++)
#define FOR(b) for(signed i = 0; i <(b); i++)
#define FORE(i, l, r) for(int i = (l); i < (r); i++)
#define NFOR(i, n) for(int i = (((int) n)-1); i >= 0; i--)
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef pair<pair<int, int>, int> PPII;
constexpr ll M7 = 1000000007ll;
constexpr ll M9 = 1000000009ll;
constexpr ll MFFT = 998244353ll;
template<class T> void outv(T &a) { for (auto &x : a) cout << x << ' '; }
static mt19937 rnd(static_cast<unsigned>(chrono::steady_clock::now().time_since_epoch().count())); // NOLINT(cert-err58-cpp)
auto __fast_io__ = (ios_base::sync_with_stdio(false), cin.tie(nullptr)); // NOLINT(cert-err58-cpp,cppcoreguidelines-interfaces-global-init)
////@formatter:on
//endregion

VI calc_dp(int c, string s) {
    int n = s.length();
    VI dp(n);
    for (int i = 0; i < n; ++i) {
        if (s[i] != 'x') {
            dp[i] = (i - c - 1 >= 0 ? dp[i - c - 1] : 0) + 1;
        }
        if (i > 0){
            dp[i] = max(dp[i], dp[i - 1]);
        }
    }
    return dp;
}

int32_t main() {
    make(int, n, k, c);
    make(string, s);
    VI dp_pr = calc_dp(c, s);
    reverse(ALL(s));
    VI dp_sf = calc_dp(c, s);
    reverse(ALL(dp_sf));
    for(int i = 0; i < n; ++i){
        int l = i > 0 ? dp_pr[i - 1] : 0;
        int r = i + 1 < n ? dp_sf[i + 1] : 0;
        if (l + r + 1 == k){
            cout << i + 1 << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 5072
#include <cstdio>
#include <iostream>

using namespace std;

int main(void)
{
    int a,b;
    cin >>a >>b;

    if(a == b){
        printf("%d\n", a*2 );
    }else if(a > b){
        printf("%d\n", a*2-1 );
    }else{
        printf("%d\n", b*2-1 );
    }

    return 0;
}

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

using namespace std;

#define lli long long int

lli BinomialCoeff(int n, int k)
{
	vector<lli> dp(k + 1);

	dp[0] = 1;

	for (int i = 1; i <= n; i++)
	{
		for (int j = min(i, k); j > 0; j--)
		{
			dp[j] = dp[j] + dp[j - 1];
		}
	}

	return dp[k];
}

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

	unordered_map<string, int> um;

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

		sort(s.begin(), s.end());

		um[s]++;
	}


	lli res = 0;
	for (auto it : um)
	{
		res += BinomialCoeff(it.second, 2);
	}

	cout << res << endl;
}

Measured memory_bytes: 10660
n = gets.to_i
a = gets.split.map(&:to_i)
b = gets.split.map(&:to_i)
count = 0
for i in 0..n - 1
  kill = [a[i], b[i]].min
  a[i] -= kill
  b[i] -= kill
  count += kill
  kill = [a[i + 1], b[i]].min
  a[i + 1] -= kill
  b[i] -= kill
  count += kill
end
puts count


Measured memory_bytes: 19596
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#include<algorithm>//next_permutation
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
#define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define small "abcdefghijklmnopqrstuvwxyz"
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

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

const ll MOD = 1000000007;
const ll MAX = 2000001;

ll mod(ll a){
  return a % MOD;
}

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

ll fac[MAX], finv[MAX], inv[MAX];

void nCrprep() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll nCr(ll n, ll r){
    if (n < r) return 0;
    if (n < 0 || r < 0) return 0;
    return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD;
}

ll nCrcheep(ll n,ll r){
  if(r == 0) return 1;
  else if(r == 1) return n;
  else return nCrcheep(n-1,r-1)*n/r;
}

vector<pair<ll,ll>> prime_factorize(ll n){
  vector<pair<ll,ll>> res;
  
  for(ll i=2; i*i <= n; i++){
    if(n % i != 0) continue;
    
    ll ex = 0;
    while(n % i == 0){
      ex++;
      n /= i;
    }
    
    res.push_back({i,ex});
  }
  
  if(n != 1) res.push_back({n,1});
  
  return res;
  
}




int main(){
  string s; cin >> s;
  
  ll n = s.size();
  
  ll sum = 0;
  
  rep(i,n){
    
    ll a = s[i] - '0'; 
    
    sum += a;
  }
  
  if(sum % 9 == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  
}

Measured memory_bytes: 3704
#include <iostream>

using namespace std;

int main() {
    int a, b, k;
    cin >> a >> b >> k;

    for (int i = a; ; i--) {
        if (a % i == 0 && b % i == 0) {
            k--;
            if (k == 0) {
                cout << i << endl;
                break;
            }
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<unordered_map>
#include<algorithm>
#include<cmath>
#include<climits>
#include<iomanip>
using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

typedef long long ll;

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

	int ans = 0;
	REP(x, k+1) {
		REP(y, k+1) {
			if (s - x - y >= 0 && s - x - y <= k) ans++;
		}
	}

	cout << ans << endl;

	//小数点以下の桁数表示;
	//cout << fixed << setprecision(15);

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
main(){
std::string l[9]={"',.!?","abcABC","defDEF","ghiGHI","jklJKL","mnoMNO","pqrsPQRS","tuvTUV","wxyzWXYZ"},s,a;
for(int i,c,t;std::cin>>s;std::cout<<a<<"\n"){
  for(s+=1,a="",c=i=0;++i<s.size();c++)
  if(s[i-1]-s[i]){
   if(s[i-1]-48){
    t=s[i-1]-49;
    a+=l[t][c%l[t].size()];
   }
   c=-1;
 }else if(s[i]==48)a+=32;
}
}

Measured memory_bytes: 0
p = [2, 3]
for i in range(5, 10 ** 5 + 1, 2):
  flag = True
  j = 0
  while p[j] * p[j] <= i:
    if i % p[j] == 0:
      flag = False
      break
    j += 1
  if flag:
    p.append(i)

tf = [False] * (10 ** 5 + 1)
for i in p:
  tf[i] = True

like = [0]
for i in range(1, 10 ** 5 + 1):
  if tf[i] and tf[(i + 1) // 2]:
    like.append(like[-1] + 1)
  else:
    like.append(like[-1])

ans = []
q = int(input())
for _ in range(q):
  i, j = map(int, input().split())
  i -= 1
  ans.append(like[j] - like[i])

for i in ans:
  print(i)

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

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

    if (N % 2) {
        cout << 0 << endl;
        return 0;
    }

    ll divisor = 10;
    ll res = 0;
    while (divisor <= N) {
        res += N / divisor;
        divisor *= 5;
    }

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<sstream>
using namespace std;
int main(){
  string s;
  while(cin >> s) {
    for(int i=0;i<s.size();i++) if(s[i]==',') s[i]=' ';
    stringstream ss(s);int id;double w,h;
    ss >> id >> w >> h;
    double bmi=w/(h*h);
    if(bmi>=25.0) cout << id << endl;
  }
}


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

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

        int N = Integer.parseInt(st.nextToken());
        int M = Integer.parseInt(st.nextToken());

        int[] h = new int[N];

        st  = new StringTokenizer(br.readLine());

        for (int i=0; i<N; i++) {
            h[i] = Integer.parseInt(st.nextToken());
        }

        List<List<Integer>> g = new ArrayList();

        for (int i=0; i<N; i++) {
        	g.add(new ArrayList());
        }

        for (int i=0; i<M; i++) {
        	st  = new StringTokenizer(br.readLine());

	        int A = Integer.parseInt(st.nextToken())-1;
	        int B = Integer.parseInt(st.nextToken())-1;

	        g.get(A).add(B);
	        g.get(B).add(A);
        }
        
        int ans=0;
        for (int i=0; i<N; i++) {
            boolean good=true;
            for (int x: g.get(i)) {
                if (h[i]<=h[x]) {
                    good=false;
                }
            }
            if (good) {
                ans++;
            }
        }

        System.out.println(ans);

    }

}

Measured memory_bytes: 66188
def gcd(a, b):
  if a < b:
    return gcd(b, a)
  elif b == 0:
    return a
  else:
    return gcd(b, a % b)

A, B = map(int, input().split())
g = gcd(A, B)
a = 1
for n in range(2, g+1):
  if g % n == 0:
    a += 1
    while g % n == 0:
      g //= n
  if n*n > g:
    break
if g > 1:
  a += 1
print(a)

Measured memory_bytes: 40172