akhauriyash/Code-Regression huggingface dataset:
use std::cmp::*;
use std::io::*;
const MOD: u64 = 1_000_000_007;

mod enumeration {
    pub struct Enumeration {
        fact: Vec<u64>,
        finv: Vec<u64>,
        modulo: u64,
    }
    impl Enumeration {
        pub fn new(n: usize, modulo: u64) -> Enumeration {
            let mut fact: Vec<u64> = vec![1; n];
            let mut inv: Vec<u64> = vec![1; n];
            let mut finv: Vec<u64> = vec![1; n];
            for i in 2..n {
                fact[i] = fact[i - 1] * (i as u64) % modulo;
                inv[i] = modulo - (modulo / (i as u64)) * inv[(modulo as usize % i)] % modulo;
                finv[i] = inv[i] * finv[i - 1] % modulo;
            }
            Enumeration {
                fact: fact,
                finv: finv,
                modulo: modulo,
            }
        }
        pub fn c(&self, n: usize, k: usize) -> u64 {
            if n < k {
                return 0;
            }
            self.fact[n] * self.finv[n - k] % self.modulo * self.finv[k] % self.modulo
        }
    }
}
fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: usize = itr.next().unwrap().parse().unwrap();
    let k: usize = itr.next().unwrap().parse().unwrap();

    let en = enumeration::Enumeration::new(n + n, MOD);
    // i: 0人の部屋の数
    let mut ans = 0;
    for i in 0..min(n, k + 1) {
        ans = (ans + en.c(n, i) * en.c(n - 1, (n - i) - 1) % MOD) % MOD;
    }
    println!("{}", ans);
}


Measured memory_bytes: 16636
import java.util.Scanner;

public class Main {
	static int A,P;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		A = sc.nextInt();
		P = sc.nextInt();
		int a = A * 3;
		int b = a + P;
		int ans = b / 2;
		System.out.println(ans);
	}
}

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

// calculate |gcd|.
// if  ether num is 0, return 0
long long GCD(long long left, long long right) {
  if(left == 0 || right == 0) return 0;
  if(left < 0) left *= -1;
  if(right < 0) right *= -1;
  if(left < right) swap(left, right);
  long long nextnum, ansgcd = -1;
  while(ansgcd == -1) {
    nextnum = left % right;
    if(nextnum == 0) ansgcd = right;
    left = right;
    right = nextnum;
  }
  return ansgcd;
}

long long LCM(long long left, long long right) {
  return left / GCD(left, right) * right;
}

long long p, q, a, n, ans = 0, pq = 0;

void solve(long long child, long long mother,
           long long maxnum, long long now);

int main() {
  while(1) {
    cin >> p >> q >> a >> n;
    if(p + q + a + n == 0) break;
    ans = 0;
    pq = GCD(p, q);
    p /= pq;
    q /= pq;
    solve(0, 1, 1, 0);
    cout << ans << endl;
  }
  return 0;
}

void solve(long long child, long long mother,
           long long maxnum, long long now) {
  // check ans
  long long momq = mother * q, momp = mother * p,
            chilq = child * q, x;
  if(momq % (momp - chilq) == 0) {
    x = momq / (momp - chilq);
    if(x * mother <= a && x >= maxnum) ++ans;
  }
  if(now == n - 1) return;
  // dfs
  long long fin = (n - now) * (momq + momp - chilq - 1) /
                  (momp - chilq);
  for(int i = maxnum; i <= fin && mother * i <= a; ++i) {
    long long nextchil = child * i + mother,
              nextmom = mother * i;
    if(nextmom * p <= nextchil * q) continue;
    solve(nextchil, nextmom, i, now + 1);
  }
}


Measured memory_bytes: 3076
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#ifndef ONLINE_JUDGE
#define dbg(x...) do { cout << "the " << #x << " -> "; err(x); } while (0)
void err() { cout << "" << endl; }
template<template<typename...> class T, typename t, typename... A>
void err(T<t> a, A... x) { for (auto v: a) cout << v << ' '; err(x...); }
template<typename T, typename... A>
void err(T a, A... x) { cout << a << ' '; err(x...); }
#else
#define dbg(...)
#endif
int main()
{
    ll n;
    cin>>n;
    ll ans=0;
    for(ll l=1,r=0;l<=n;l=r+1)
    {
        r=min(n,n/(n/l));
        ll cur=n/l;
        ll num=n/cur-1;
        if(num>=l&&num<=r&&cur==n%num)
            ans+=num;
        //dbg(l,r,num);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
//
#include <vector>
#include <set>
#include <map>
#include <array>
#include <iostream>
#include <algorithm>
#include <numeric>
#include <bitset>
#include <cstdio>
#include <cstdint>
#include <cmath>
//
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);++i)
inline void yes(bool cond) { cond ? puts("Yes") : puts("No"); }
template<typename Type> inline void chmin(Type& a, Type b) { if (a > b) a = b; }
template<typename Type> inline void chmax(Type& a, Type b) { if (a < b) a = b; }
template<typename Type> inline void sort(Type& arr) { std::sort(arr.begin(), arr.end()); }
template<typename Type> inline Type nth(vector<Type>& arr, size_t pos) { std::nth_element(arr.begin(), arr.begin() + pos, arr.end()); return arr[pos]; }
constexpr ll BIGP = 1000000007L;
constexpr ll INF_I = std::numeric_limits<ll>::max();
constexpr ld INF_F = std::numeric_limits<float>::infinity();
constexpr ld PI = 3.14159265358979323846L;
//
int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    string S;
    cin >> S;
    cout << (S == "ABC" ? "ARC" : "ABC");

    return 0;
}

Measured memory_bytes: 3032
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#pragma warning(disable:4996)


int main() {
	//入力変数の宣言
	int N, L[100] = {};


	//値の代入
	scanf("%d", &N);
	for (int i = 0; i < N; i++) {
		scanf("%d", &L[i]);
	}


	//値に不適切なものが入力されたときにエラーを返す
	if (N <= 0 || N > 100) return 1;
	for (int i = 0; i < N; i++) {
		if (L[i] < 0 || L[i] > pow(10,9))return 1;
	}


	//関数プロトタイプ
	//出力変数の宣言
	int way (int, int*);


	//出力
	printf("%d", way(N, L));
}


//条件を満たす組の個数を計算するプログラム
int way(int N, int* L) {
	int calc_way = 0;
	for (int i = 0; i < N; i++) {
		for (int j = i + 1; j < N; j++) {
			for (int k = j + 1; k < N; k++) {
				if (L[i] + L[j] > L[k] && L[j] + L[k] > L[i] && L[k] + L[i] > L[j]) {
					if (L[i] != L[j] && L[j] != L[k] && L[k] != L[i])calc_way++;
				}
			}
		}
	}
	return calc_way;
}

/* 実行時間制限: 2 sec / メモリ制限: 1024 MB
配点 : 200点

問題文
1,⋯,Nの番号がついた N 本の棒があります。棒 i(1≤i≤N) の長さは L_iです。
このうち、三角形を作ることのできるような長さの異なる3本の棒を選ぶ方法は何通りあるでしょうか。
つまり、3つの整数 1≤i<j<k≤N の組であって次の 2つの条件の両方を満たすものの個数を求めてください。
・L_i,L_j,L_kがすべて異なる
・3辺の長さが L_i,L_j,L_kであるような三角形が存在する

制約
1≤N≤100
1≤L_i≤10^9
入力は全て整数である

入力
入力は以下の形式で標準入力から与えられる。
N
L_1 L_2 ⋯ L_N

出力
三角形を作ることのできるような、長さの異なる 3本の棒を選ぶ方法の個数を出力せよ。

入力例 1
5
4 4 9 7 5

出力例 1
5

条件を満たすような (i,j,k)は、(1,3,4),(1,4,5),(2,3,4),(2,4,5),(3,4,5) の 5個があります。

入力例 2
6
4 5 4 3 3 5

出力例 2
8

長さ 3,4,5の棒が 2 本ずつあります。1 つ目の条件を満たすためにはそれぞれから 1本ずつ選ぶしかありません。
3辺の長さが 3,4,5 の三角形は存在するので、条件を満たすような (i,j,k) は 2^3=8個あります。

入力例 3
10
9 4 6 1 9 6 10 6 6 8

出力例 3
39

入力例 4
2
1 1

出力例 4
0

1≤i<j<k≤Nを満たす (i,j,k) が存在しないので、0 を出力してください。*/

Measured memory_bytes: 1704
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<stdio.h>
#include<utility>//swapでaとbの値を入れ替える
#define rep(i,n) for(int i=0;i<(n);i++)
#define ll long long
#define sort(s) sort(s.begin(),s.end())
#define r(s) reverse(s.begin(),s.end())
using namespace std;


int main() {
	int a;
	cin >> a;
	cout << 3 * a * a << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#define pb push_back
#define mp make_pair

vector<int> v;

int main(){
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int n, x;
    LL res = 0;
    scanf("%d %d", &n, &x);
    for(int i = 0; i < n; i++){
        int temp;
        scanf("%d", &temp);
        v.pb(temp);
        if(temp <= x){
            res++;
            x -= temp;
        }
    }
    int mn = min_element(v.begin(), v.end()) - v.begin();
    while(v[mn] <= x){
        res++;
        x -= v[mn];
    }
    printf("%lld\n", res);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    ll B[110];
    cin >> N;
    rep(i,0,N) cin >> B[i];
    vector<ll> v;
    ll pos[110] = {};
    rep(i,1,N+1) pos[i] = B[i-1];
    bool ok = true;
    vector<ll> ans;
    rep(t,0,N){
        ll pp = -1;
        rrep(i,N-t,1){
            if(i == pos[i]){
                pp = i;
                break;
            }
        }
        if(pp == -1){
            ok = false;
            break;
        }
        ans.push_back(pp);
        rep(i,pp+1,N-t+1){
            pos[i-1] = pos[i];
        }
    }
    reverse(ans.begin(), ans.end());
    if(!ok){
        print(-1);
        return 0;
    }
    rep(i,0,N){
        print(ans[i]);
    }
    // rep(i,0,N) v.push_back(B[i]);
    // rep(t,0,N){

    // }
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")

#define rep(i,n) for(int i = 0;i<n;i++)
const long long MOD = 1000000007;

int main(){
  long long n; cin >> n;
  long long ans = MOD*1000;
  for(long long i = 1; i<=sqrt(n)+1;i++){
    if(n % i == 0){
      long long j = n/i;
      long long tmp = (i-1)+(j-1);
      ans = min(ans, tmp);
    }
  }
  cout << ans << "\n";
}


Measured memory_bytes: 256
def resolve():
    N, K = map(int, input().split())

    BL = [False]*N
    for _ in range(K):
        d = int(input())
        for i in input().split():
            i = int(i)-1
            BL[int(i)] = True

    print(sum([1 for x in BL if x==False]))

if __name__ == "__main__":
    resolve()

Measured memory_bytes: 9196
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  for(int i=0;i<n;i++){
    string s;
    cin >> s;
    if(s=="Y"){
      cout << "Four" << endl;
      break;
    }
    if(i==n-1){
      cout << "Three" << endl;
    }
  }
}

Measured memory_bytes: 256
#include <fstream>
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <sstream>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <cmath>
#include <queue>
#include <random>

using namespace std;

#define INT_MAX_VALUE 2147483647
#define LONG_LONG_MAX_VALUE 9223372036854775807
#define ll long long

template <class T>
T mymax(T a,T b){
    if(a>=b) return a;
    return b;
}
template <class T>
T mymin(T a,T b){
    if(a<=b) return a;
    return b;
}

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

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

struct XX{
    int a;
    int b;
    int z;
    int i;
};

class xxGreater {
public:
    bool operator()(const XX& riLeft, const XX& riRight) const {
        //第2条件
        if((riLeft.b) == (riRight.b)){
            return riLeft.i < riRight.i;//<:昇順(小さいものから順番)、>:降順(大きいものから順番)
            //プライオリティキューの場合は > で、top()すると値の小さいものがとれる
        }
        //第1条件
        return (riLeft.b) > (riRight.b);
    }
};

//map<long long,long long> prime_f(long long n){
//    map<long long,long long>res;
//    for(int i=2;i*i<=n;i++){
//        while(n%i==0){
//            ++res[i];
//            n/=i;
//        }
//    }
//    if(n!=1)res[n]=1;
//    return res;
//}


int main(int argc, const char * argv[])
{
    //std::ios::sync_with_stdio(false);
    //scanf("%s",S);
    //scanf("%d",&N);
    //sscanf(tmp.c_str(),"%dd%d%d",&time[i], &dice[i], &z[i]);
    //getline(cin, target);
    //cin >> x >> y;
    //テスト用
    //ifstream ifs( "1_06.txt" );
    //ifs >> a;
    //ここから
    
    //入力高速化
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    ll K;
    cin >> K;
    ll a[100000];
    for(int i=0;i<K;i++){
        cin >> a[i];
    }
    
    ll shoki=0;
    ll shoki2=2;
    for(int i=0;i<K;i++){
        if(shoki<=a[K-1-i]){
            shoki=a[K-1-i];
        }else{
            ll tmp=shoki/a[K-1-i];
            if(shoki%a[K-1-i]!=0){
                tmp++;
            }
            shoki=a[K-1-i]*(tmp);
        }
        ll tmp=shoki2/a[K-1-i];
        shoki2=a[K-1-i]*(tmp+1)-1;
    }

    ll ans1=shoki;
    ll ans2=shoki2;
    
    ll tmp1=ans1;
    ll tmp2=ans2;
    for(int i=0;i<K;i++){
        tmp1=(tmp1/a[i])*a[i];
        tmp2=(tmp2/a[i])*a[i];
    }
    if(tmp1==2 && tmp2==2){
        cout << ans1 << " " << ans2 << endl;
    }else{
        cout << -1 << endl;
    }
    
    //ここまで
    //cout << "debug" << endl;
    //cout << "ans" << endl;改行含む
    //printf("%.0f\n",ans);//小数点以下表示なし
    //printf("%.7f\n",p);
    //printf("%f\n",pow(2,ans.size()));
    
    return 0;
}




Measured memory_bytes: 1024
Public Class Program
  Shared Sub Main()
    Dim ab As Long() = Cin.LngArr()
    Dim a As Long = ab(0)
    Dim b As Long = ab(1)
    Console.WriteLine(Lcm(a, b).ToString())
  End Sub

  ' 最大公約数
  Shared Function Gcd(x As Long, y As Long) As Long
    Return If(x < y, Gcd(y, x), If(y > 0, Gcd(y, x Mod y), x))
  End Function

  ' 最小公倍数
  Shared Function Lcm(x As Long, y As Long) As Long
    Return x / Gcd(x, y) * y
  End Function
End Class

Public Class Cin
  Public Shared Function Str() As String
    Return Console.ReadLine().Trim()
  End Function
  Public Shared Function Int() As Integer
    Return Integer.Parse(Str())
  End Function
  Public Shared Function Lng() As Long
    Return Long.Parse(Str())
  End Function
  Public Shared Function Dbl() As Double
    Return Double.Parse(Str())
  End Function
  Public Shared Function StrArr(Optional separator As String = " ") As String()
    Return Str().Split(separator)
  End Function
  Public Shared Function IntArr(Optional separator As String = " ") As Integer()
    Return Array.ConvertAll(Of String, Integer)(StrArr(separator), AddressOf Integer.Parse)
  End Function
  Public Shared Function LngArr(Optional separator As String = " ") As Long()
    Return Array.ConvertAll(Of String, Long)(StrArr(separator), AddressOf Long.Parse)
  End Function
  Public Shared Function DblArr(Optional separator As String = " ") As Double()
    Return Array.ConvertAll(Of String, Double)(StrArr(separator), AddressOf Double.Parse)
  End Function
End Class

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

int main() {
  string S; cin >> S;
  int Q; cin >> Q;
  int rc = 0;
  deque<char> q;
  for(int i = 0; i < S.size(); i++) q.push_back(S[i]);
  for(int i = 0; i < Q; i++) {
    int qi; cin >> qi;
    if(qi == 1) rc++;
    else {
      int f; char c; cin >> f >> c;
      if(rc % 2 == 0) {
        if(f == 1) q.push_front(c);
        else q.push_back(c);
      } else {
        if(f == 1) q.push_back(c);
        else q.push_front(c);
      }
    }
  }
  if(rc % 2 == 1) reverse(q.begin(), q.end());
  string ans;
  for(char c : q) ans += c;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1412
let arr=readLine()!.characters.split{$0==" "}.map{Int(String($0))!}

var carry = 0
var tak = arr[0] - arr[2]
if( tak < 0 ) {
  carry = tak
  tak = 0
}

var aok = arr[1] + carry
if( aok < 0 ) {
  aok = 0
}
print(tak,aok)

Measured memory_bytes: 4080
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree < pairs ,  null_type , greater<pairs>,  rb_tree_tag ,  tree_order_statistics_node_update > 
#define ll long long
#define lld long double
#define vc vector<ll>
const ll MOD=(1e9 +7);
typedef pair<ll,ll>pairs;
ll power(ll a, ll b){ll res=1;a=a%MOD;while(b>0){if(b&1){res=(res*a)%MOD;b--;}a=(a*a)%MOD;b>>=1;}
    return res;}

int main() {
	// your code goes here
	std::ios::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	ll t,n,i,j,k,l,c,f,x;
	cin>>n>>x>>t;
	cout<<(n/x)*t+((bool)(n%x!=0))*t;
	return 0;
}


Measured memory_bytes: 3648
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string.h>

int main(void)
{
	int a = 1,n = 0,flag = 0,flag2 = 0,flag3 = 0;
	char moji[110],ans[7] = "keyence";
	scanf("%s", moji);
	for (int i = 0; i < strlen(moji); i++)
	{
		if (moji[i] == ans[n])
		{
			if (n == 6) { flag = 1; break; }
			n++;
		}
		else
		{
			for (int m = 6; n <= m; m--)
			{
				if (moji[strlen(moji) - a] != ans[m])
				{
					flag3 = 1;
					break;
				}
				a++;
			}
			if (flag3 == 1) { break; }
			else { flag = 1; break; }
		}
	}

	if (flag == 0) { printf("NO"); }
	else { printf("YES"); }

	return 0;
}

Measured memory_bytes: 128
use std::io::*;

// const SP: u8 = b' ';
const LF: u8 = b'\n';

struct CharacterInput<'a> {
    locked_stdin: StdinLock<'a>,
    bytes_buffer: Vec<u8>,
}

impl<'a> CharacterInput<'a> {
    fn read(&mut self, delimiter: u8) -> &[u8] {
        self.bytes_buffer.clear();

        let len = self
            .locked_stdin
            .read_until(delimiter, &mut self.bytes_buffer)
            .unwrap();

        let end_index = match self.bytes_buffer.last() {
            Some(byte) => {
                if *byte == delimiter {
                    len - 1
                } else {
                    len
                }
            }
            None => len,
        };

        &self.bytes_buffer[0..end_index]
    }

    fn scan_u(&mut self, delimiter: u8) -> u32 {
        self.read(delimiter)
            .into_iter()
            .fold(0, |accumulator, byte| {
                (byte - b'0') as u32 + accumulator * 10
            })
    }

    fn scan_s(&mut self, delimiter: u8) -> &str {
        unsafe { std::str::from_utf8_unchecked(self.read(delimiter)) }
    }

    fn scan_string(&mut self, delimiter: u8) -> String {
        self.scan_s(delimiter).into()
    }
}

fn create_cin<'a>(input: StdinLock<'a>, buffer_capacity: usize) -> CharacterInput {
    CharacterInput {
        locked_stdin: input,
        bytes_buffer: Vec::with_capacity(buffer_capacity),
    }
}

fn println<T: std::string::ToString>(s: T) {
    println!("{}", s.to_string());
}

// ------------------------------------------------------------------------

fn combination(n: usize) -> usize {
    if n <= 1 {
        return 0;
    }

    let mut count = 0;
    for i in 0..n - 1 {
        for _k in i + 1..n {
            count += 1;
        }
    }
    count
}

fn main() {
    let cin = stdin();
    let cin = &mut create_cin(cin.lock(), 64);

    let n = cin.scan_u(LF) as usize;
    let mut s: Vec<String> = (0..n).map(|_| cin.scan_string(LF)).map(|s| {
            let s_slice: &str = &s[..];
            let mut chars: Vec<char> = s_slice.chars().collect();
            chars.sort();
            chars.into_iter().collect::<String>()
        }
    ).collect();
    s.sort();

    let mut dup: Vec<usize> = Vec::with_capacity(n);
    let mut current_count = 0;
    for slice in s.windows(2) {
        if slice[0] == slice[1] {
            current_count += 1;
        } else {
            dup.push(current_count);
            current_count = 0;
        }
    }
    if current_count > 0 {
        dup.push(current_count);
    }

    let total_count: usize = dup.into_iter().map(|count| combination(count + 1)).sum();

    println(total_count);
}


Measured memory_bytes: 10492
#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
int main(){
    
    lli n,m;
    cin >> n >>m;
    vector < pair <lli,lli> > v(n);
    for(int i = 0;i<n;i++){
        lli x;
        cin >> x;
        v[i].first = x;
        cin >> x;
        v[i].second = x;
    }
    vector <lli> dp(m+1);
    for(int i =0;i<n;i++){
        for(int j =m;j>=0;j--){
            if(j-v[i].first>=0)
                dp[j]  = max(dp[j],dp[j-v[i].first]+v[i].second);
        }
    }
    cout << dp[m] << endl;
}


Measured memory_bytes: 1024
#include<cstdio>

int main() {
    double r, p, area, cir;
    scanf("%lf", &r);
    
    area = r * r * 3.141592653589; 
    cir = 2 * r * 3.141592653589;

    printf("%f %f\n", area, cir);

    return 0;
}


Measured memory_bytes: 2700
#include<bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i,n) for(int i=0;i<n;++i)
#define all(v) v.begin(), v.end()
#define PI 3.141592653589793238462643383279
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
typedef long long int ll;
typedef unsigned long long ull;
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;}
typedef pair<ll,ll> P;
const long long MOD = 1e9+7;
const ll INF = 1LL << 60;
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};

int main(){
    int n;
    cin >> n;
    ll cnt = 0;
    if(n == 1){
        cout << 0 << endl;
        return 0;
    }
    for(int i = 0; i < n-1; i++){
        cnt += i+1;
    }

    cout << cnt << endl;


}

Measured memory_bytes: 3636
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Main2();
            Console.ReadLine();
        }

        static void Main2()
        {
            string[] s = Console.ReadLine().Split(' ');
            int H = int.Parse(s[0]);
            int W = int.Parse(s[1]);
            string Wabc = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
            for (int i = 0; i < H; i++)
            {
                s = Console.ReadLine().Split(' ');

                for (int j = 0; j < W; j++)
			    {
                    if (s[j] == "snuke")
                    {
                        Console.WriteLine(Wabc[j].ToString() + (i+1));
                        return;
                    }
			    }
            }

        }
    }
}


Measured memory_bytes: 2772
#include <iostream>

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

  // read 1st element
  int a_min;
  std::cin >> a_min;
  int a_max = a_min;

  for(int i=1; i<N; i++) {
    int a;
    std::cin >> a;
    a_min = std::min(a_min, a);
    a_max = std::max(a_max, a);
  }

  std::cout << a_max - a_min << std::endl;

  return 0;
}


Measured memory_bytes: 3532
#include "bits/stdc++.h"
#include <sys/timeb.h>
#include <fstream>

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 replrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) replrev(i,0,n)
#define repi(itr,ds) for(auto itr=ds.begin();itr!=ds.end();itr++)
#define all(a) a.begin(),a.end()
#define mp make_pair
#define mt make_tuple
#define INF 2000000000
#define INFL 1000000000000000000LL
#define EPS (1e-8)
#define MOD 1000000007
#define PI 3.141592653589793
#define RMAX 4294967295
#define equals(a,b)(fabs((a)-(b))<EPS)

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<P> vP;
typedef vector<vector<int> > vvi;
typedef vector<vector<bool> > vvb;
typedef vector<vector<ll> > vvll;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<double> > vvd;
typedef vector<vector<P> > vvP;
typedef complex<double> comp;
typedef vector<complex<double>> vcomp;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<ll, vector<ll>, greater<ll> > pqlll;
typedef priority_queue<P, vector<P>, greater<P> > pqlP;
typedef string::const_iterator State;
class ParseError {};
struct Edge {
	int from, to, cost;
	bool operator<(Edge e) {
		return cost < e.cost;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;



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

	string N;
	cin >> N;
	if (N[0] == N[2]) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}

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

int main(){
  long n;
  scanf("%ld", &n);
  long a[n];
  for(int i = 0; i < n; i++)
  scanf("%ld", &a[i]);
  
  int zerocount = 0;
  int minuscount = 0;
  
  for(int i = 0; i < n; i++){
    if(a[i] == 0)
      zerocount++;
    else if(a[i] < 0)
      minuscount++;
  }
  
  long ans = 0;
  
  if(zerocount > 0 || minuscount % 2 == 0){
    long b[n];
    for(int i = 0; i < n; i++){
      if(a[i] < 0)
        b[i] = -a[i];
      else
        b[i] = a[i];
    }
    
    for(int i = 0; i < n; i++)
      ans += b[i];
  }
  else{
    long min = 10000000000;
    for(int i = 0; i < n; i++){
      if(abs(a[i]) < min)
        min = abs(a[i]);
    }
    
    long b[n];
    for(int i = 0; i < n; i++){
      if(a[i] < 0)
        b[i] = -a[i];
      else
        b[i] = a[i];
    }
    
    for(int i = 0; i < n; i++)
      ans += b[i];
    ans -= min*2;
  }
  
  printf("%ld", ans);
  return 0;
}

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

int main(){
  char *s;
  int k = 700;
  s = new char(3);
  for(int i = 0; i < 3;i++){
    cin >> s[i];
    if(s[i] == 'o') k += 100;
  }
  cout << k << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,a,b) for(int i=(a),_end_=(b);i<=_end_;i++)
#define DREP(i,a,b) for(int i=(a),_end_=(b);i>=_end_;i--)
#define EREP(i,a) for(int i=start[(a)];i;i=e[i].next)
template<class T>inline void chkmax(T &a,T b){ if(a<b)a=b;}
template<class T>inline void chkmin(T &a,T b){ if(a>b)a=b;}
#define fi first
#define se second
#define mkr(a,b) make_pair(a,b)
inline int read()
{
	int sum=0,p=1;char ch=getchar();
	while(!(('0'<=ch && ch<='9') || ch=='-'))ch=getchar();
	if(ch=='-')p=-1,ch=getchar();
	while('0'<=ch && ch<='9')sum=sum*10+ch-48,ch=getchar();
	return sum*p;
}

int main()
{
	ll k=read(),a=read(),b=read();
	ll ans=0;
	if(b-a<=2)printf("%lld\n",k+1);
	else {
		k-=a-1; ans+=a;
		ans+=(k/2)*(b-a);
		ans+=k&1;
		printf("%lld\n",ans);
	}
	return 0;
}



Measured memory_bytes: 256
/*
 * ID: ITP2_10_C
 * Problem: Bit Flag
 */

#include <stdio.h>

int main(void)
{
    unsigned long a = 0;
    unsigned long mask[10] = {0};
    const unsigned long fullbit = -1; // 0xffffffffffffffff
    int i, n_mask, n_query;

    scanf("%d", &n_mask);

    for (i = 0; i < n_mask; i++) {
        int j, n_bit, bit;
        scanf("%d", &n_bit);
        for (j = 0; j < n_bit; j++) {
            scanf("%d", &bit);
            mask[i] |= (1L << bit);
        }
    }

    scanf("%d", &n_query);
    for (i = 0; i < n_query; i++) {
        int query, imask;
        int j, count;
        scanf("%d %d", &query, &imask);
        switch (query) {
            case 0: // test(i)
                printf("%d\n", (a & (0x01L << imask)) == 0 ? 0 : 1);
                break;
            case 1: // set(i);
                a |= mask[imask];
                break;
            case 2: // clear(i);
                a &= fullbit ^ mask[imask];
                break;
            case 3: // flip(i);
                a ^= mask[imask];
                break;
            case 4: // all(i)
                printf("%d\n", (a & mask[imask]) == mask[imask] ? 1 : 0);
                break;
            case 5: // any(i)
                printf("%d\n", (a & mask[imask]) >= 1 ? 1 : 0);
                break;
            case 6: // none(i)
                printf("%d\n", (a & mask[imask]) == 0 ? 1 : 0);
                break;
            case 7: // count(i)
                for (j = 0, count = 0; j < 64; j++) {
                    if ((a & mask[imask]) & (0x01L << j))
                        count++;
                }
                printf("%d\n", count);
                break;
            case 8: // val(i)
                printf("%lu\n", a & mask[imask]);
                break;
            //case 9: // val by hex
            //    printf("%lx\n", a);
            //    break;
        }
    }

    return 0;
}



Measured memory_bytes: 2108
#include<bits/stdc++.h>
using namespace std;
long long ans = (-1)*1E10;
int main(){
  int n;
  cin >> n;
  int f[n][10],p[n][10];
  for(int i=0;i<n;i++){
    for(int j=0;j<10;j++){
      cin >> f[i][j];
    }
  }
  for(int i=0;i<n;i++){
    for(int j=0;j<11;j++){
      cin >> p[i][j];
    }
  }
  for(int i=1;i<(1<<10);i++){
    bitset<10> s(i);
    int cnt=0;
    for(int j=0;j<n;j++){
      int cnt1=0;
      for(int k=0;k<10;k++){
        if(s.test(k)==1&&f[j][k]==1) cnt1++;
      }
      cnt+=p[j][cnt1];
    }
    if(ans<cnt) ans = cnt;
  }
    cout << ans << endl;
}


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

template <typename T>
class BinaryTree{
public:
	struct Node{
		T val;
		Node *lch,*rch;
	};
	BinaryTree():root(NULL){}
	
	Node* root;
	Node* insert(T x){ return root = insert(root, x);}
	bool find(T x){ return find(root, x); }
	Node* erase(T x){ return root = erase(root, x); }
	void inorderPrint(){ inorderPrint(root); cout<<endl;}
	void preorderPrint(){ preorderPrint(root); cout<<endl;}

private:
	Node* insert(Node* p,T x){
		if(p == NULL){
			Node* q = new Node;
			q->val = x;
			q->rch = q->lch = NULL;
			return q;
		}else{
			if( x < p->val )p->lch = insert(p->lch, x);
			else p->rch = insert(p->rch, x);
			return p;
		}
	}

	bool find(Node* p,T x){
		if( p == NULL )return false;
		else if( x == p->val )return true;
		else if( x < p->val )return find(p->lch, x);
		else return find(p->rch, x);
	}

	Node* erase(Node* p,T x){
		if( p == NULL )return NULL;
		else if( x < p->val )p->lch = erase(p->lch, x);
		else if( x > p->val )p->rch = erase(p->rch, x);
		else if( p->lch == NULL ){
			Node* q = p->rch;
			delete p;
			return q;
		}else if( p->rch == NULL ){
			Node* q = p->lch;
			delete p;
			return q;
		}else{
			Node* q = p->lch;
			if(q->rch == NULL){
				q->rch = p->rch;
				delete p;
				return q;
			}else{
				while(q->rch->rch != NULL) q = q->rch;
				Node* r = q->rch;
				q->rch = r->lch;
				r->lch = p->lch;
				r->rch = p->rch;
				delete p;
				return r;
			}
		}
		return p;
	}
	void inorderPrint(Node* p){
		if(p == NULL)return;
		inorderPrint(p->lch);
		cout << " " << p->val;
		inorderPrint(p->rch);
	}
	void preorderPrint(Node* p){
		if(p == NULL)return;
		cout << " " << p->val;
		preorderPrint(p->lch);
		preorderPrint(p->rch);
	}
};


int main(void){

	BinaryTree<int> bt;
	int n;
	cin >> n;
	for(int i=0;i<n;i++){
		string s;
		cin >> s;
		if(s == "insert"){
			int a;
			cin >> a;
			bt.insert(a);
		}
		else if(s == "print"){
			bt.inorderPrint();
			bt.preorderPrint();
		}
	}

	return 0;
}

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

using namespace std;

#define db(...) ZZ(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void ZZ(const char* name, Arg1&& arg1){std::cerr << name << " = " << arg1 << endl;}
template <typename Arg1, typename... Args>void ZZ(const char* names, Arg1&& arg1, Args&&... args)
{
	const char* comma = strchr(names + 1, ',');
	std::cerr.write(names, comma - names) << " = " << arg1;
	ZZ(comma, args...);
}

#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#define endl '\n'

int n, x;
int a[500], b[500];

int main()
{
	IOS;
	cin >> n >> x;
	int ans = 0;
	for (int i = 0; i < n; i++) {
		cin >> b[i];
	}
	a[0] = 0;
	for (int i = 1; i <= n; i++) {
		a[i] = a[i-1] + b[i-1];
		if (a[i] <= x)
			ans++;
		//db(a[i], ans);
	}
	cout << ans+1 << endl;
	return 0;
}



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

int n;
int num[5];

inline int read()
{
	int x = 0;char c = getchar();
	while(c > '9' || c < '0') c = getchar();
	while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return x;
}

void pre()
{
	n = read();
	for(R i = 1; i <= n; i ++)
	{
		int a = read();
		if(!(a % 4)) ++ num[4];
		else if(!(a & 1)) ++ num[2];
		else ++ num[1]; 
	}	
}

void work()
{
	if(num[4] >= num[1]) printf("Yes\n");
	else if(num[4] >= num[1] - 1 && !num[2]) printf("Yes\n");
	else printf("No\n");
}

int main()
{
	//freopen("in.in", "r", stdin);
	pre();
	work();
	//fclose(stdin);
	return 0;
}

Measured memory_bytes: 256
#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 a,b;
  cin >> a >> b;
 
  int h = max(a,b), l = min(a,b);
  
  REP(i,h-1) {
    l *= 10;
    l += min(a,b);
  }
   
  cout << l << endl;
}

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

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

bool  solve(){
    int n;
    cin >> n;
    if(!n) return false;
    vector<ll> d(n), v(n);
    for (int i = 0; i < n; ++i) {
        cin >> d[i] >> v[i];
        int g = __gcd(d[i], v[i]);
        d[i] /= g; v[i] /= g;
    }
    ll a = v[0], b = d[0];
    for (int i = 1; i < n; ++i) {
        a = __gcd(a, v[i]);
        b = b/__gcd(b, d[i])*d[i];
    }
    for (int i = 0; i < n; ++i) {
        cout << b*v[i]/a/d[i] << "\n";
    }
    return true;
}

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


Measured memory_bytes: 3004
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.run();
    }
    
    // 変数一覧
    double r;

    public void run() {
        // 入力情報取得
        Scanner sc = new Scanner(System.in);
        r = sc.nextInt();
        sc.close();

        // 解答処理
        solve();
    }
    
    private void solve() {
        double c = 2 * r * Math.PI;
        System.out.println(c);
    }
}

Measured memory_bytes: 35864
#include<bits/stdc++.h>
#define PI 3.141592653589793238462
using namespace std;
typedef long long ll;
typedef long double db;
int main(){
    string s,t;cin>>s>>t;
    int ans=2e9;
    for(int i=0;i+t.length()<=s.length();i++){
        int k=i+t.length()-1,now=0,num=0;
        for(int j=i;j<=k;j++){
            if(s[j]!=t[now]) num++;now++;
        }
        ans=min(ans,num);
    }
    cout<<ans<<endl;
} 

Measured memory_bytes: 3628
use proconio::*;
#[allow(unused_imports)]
use proconio::marker::*;

#[allow(unused_macros)]
macro_rules! echo {
    ($ x : expr ) => {
        println!("{}", $x);
    };
}

macro_rules! YesNo {
    ($ flag : expr ) => {
        if $flag {
            "Yes"
        } else {
            "No"
        }
    };
}

#[fastout]
#[allow(non_snake_case)]
fn main() {
    input! {
        N: Chars,
    }
    echo!(YesNo!(N.iter().map(|&x| x as u128 - '0' as u128).sum::<u128>() % 9 == 0));
}


Measured memory_bytes: 2968
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc= new Scanner(System.in);
        int N = sc.nextInt();
      int one = N % 10;
      String ans = "hon";
      if (one == 0 || one == 1 || one == 6 || one ==8) ans = "pon";
      if (one == 3) ans = "bon";
        System.out.println(ans);
    } 
}

Measured memory_bytes: 35744
#line 2 "../../library/template.hpp"
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using pl = pair<ll, ll>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0; i < (ll)n; i++)
#define rep3(i, l, r) for(ll i = l; i < (ll)r; i++)
#define per(i, n) for(ll i = n-1; i >= 0; i--)
#define per3(i, l, r) for(ll i = r-1; i >= (ll)l; i--)
#define all(v) begin(v), end(v)
template<class T, class U>
inline void cmax(T& a, U b) { if (a < b) a = b; }
template<class T, class U>
inline void cmin(T& a, U b) { if (a > b) a = b; }

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
  }
} io_setup;

constexpr char el = '\n';
#line 2 "a.cpp"

int main() {
  ll n, m;
  cin >> n >> m;

  cout << n*(n-1)/2 + m*(m-1)/2 << el;
  cout << flush;
}


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

using namespace std;

void solve()
{
	string s;
	cin >> s;
	if(s.size() < 6)
	{
		cout << "INVALID" << endl;
		return;
	}
	bool num_flag = false;
	bool capital_flag = false;
	bool small_flag = false;
	for(int i = 0; i < s.size(); ++i)
	{
		if('0' <= s[i] && s[i] <= '9')
		{
			num_flag = true;
		}
		if('A' <= s[i] && s[i] <= 'Z')
		{
			capital_flag = true;
		}
		if('a' <= s[i] && s[i] <= 'z')
		{
			small_flag = true;
		}
	}
	if(num_flag && capital_flag && small_flag)
	{
		cout << "VALID" << endl;
	}
	else
	{
		cout << "INVALID" << endl;
	}
}

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

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

int main(){
    int n;
    cin >> n;
    int ans[55][55];
    for(int i=0;i<55;i++){
        for(int j=0;j<55;j++){
            ans[i][j]=0;
        }
    }
    for(int i=0;i<n;i++){
        string s;
        cin >> s;
        map<char,int> ma;
        for(int j=0;j<s.size();j++){
            ma[s[j]]++;
        }
        for(auto it=ma.begin();it!=ma.end();it++){
            ans[i][it->first-'a']=it->second;
        }
    }
    for(int i=0;i<='z'-'a';i++){
        int tmp=60;
        for(int j=0;j<n;j++){
            tmp=min(tmp,ans[j][i]);
        }
        char ans=i+'a';
        for(int k=0;k<tmp;k++){
            cout << ans;
        }
    }
    cout << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<iomanip>
#include<math.h>
#include<bitset>
#include<cassert>
#include<random>
#include<time.h>
#include<functional>
using namespace std;
using ll=long long;
using ld=long double;
using pint=pair<int,int>;
using pll=pair<ll,ll>;
#define MOD 1000000007LL
#define INF 1000000000LL
#define EPS 1e-10
#define FOR(i,n,m) for(ll i=n;i<(ll)m;i++)
#define REP(i,n) FOR(i,0,n)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v)  sort(ALL(v));v.erase(unique(ALL(v)),v.end());
#define pb push_back

vector<vector<vector<ld>>> dp(334, vector<vector<ld>>(334, vector<ld>(334, -1)));
ll n;

ld dfs(ll a, ll b, ll c) {
	if(dp[a][b][c] >= 0 - EPS) return dp[a][b][c];
	if(a == 0 && b == 0 && c == 0) return 0;
	ld ret = 0;
	ll d = n - (a + b + c);
	if(a) ret += a * (dfs(a - 1, b, c) + 1);
	if(b) ret += b * (dfs(a + 1, b - 1, c) + 1);
	if(c) ret += c * (dfs(a, b + 1, c - 1) + 1);
	ret += d;
	ret /= (ld)(n - d);
	return dp[a][b][c] = ret;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> n;
	vector<ll> a(n);
	REP(i, n) cin >> a[i];
	ll b = 0, c = 0, d = 0;
	REP(i, n) {
		if(a[i] == 1) b++;
		if(a[i] == 2) c++;
		if(a[i] == 3) d++;
	}
	cout << fixed << setprecision(39) << dfs(b, c, d) << endl;
	return 0;
}

/* --------------------------------------- */


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

#define int long long
#define itn int
#define For(i, a, b) for (int i = (a); i <= static_cast<int>(b); i++)
#define Forr(i, a, b) for (int i = (a); i >= static_cast<int>(b); i--)
#define rep(i, n) For(i, 0, n - 1)
#define repall(i, arr) for (auto& i : (arr))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define dump(x) cerr << #x << " = " << (x) << '\n'
#define dump2(x, y) \
    cerr << #x << " = " << (x) << " " << #y << " = " << (y) << '\n'
#define SZ(x) ((int)(x).size())
#define bit(n) (1LL << (n))
constexpr int MOD = 1e9 + 7;

template <typename T>
using pq = priority_queue<T>;
template <typename T>
using pqr = priority_queue<T, vector<T>, greater<T>>;
const int INF = LLONG_MAX / 2;
using P = pair<int, int>;
using vec = vector<int>;
template <typename T>
using mat = vector<vector<T>>;

// clang-format off
template <typename T1, typename T2>
ostream& operator<<(ostream& stream, const pair<T1, T2>& p) { return stream << p.first << "," << p.second; }
template <typename T>
void print(const vector<T> vec) { rep (i, vec.size() - 1) cout << vec[i] << ' '; cout << vec[vec.size() - 1] << '\n'; }
template <typename Arg>
void print(const Arg arg) { cout << arg << '\n'; }
template <typename Head, typename... Args>
void print(const Head head, const Args... args) { cout << head << " "; print(args...); }
template <typename T, typename U>
void init(vector<T>& v, vector<U>& w) { rep (i, v.size()) cin >> v[i] >> w[i]; }
template <typename T>
void init(vector<T>& v) { rep (i, v.size()) cin >> v[i]; }
template <typename T>
T sum_(vector<T> vec, T init = 0) { return std::accumulate(all(vec), T(init)); }
template<typename T>
bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }
template<typename T>
bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
template <typename T>
int index(const T& vec, const typename T::iterator it) { return distance(vec.begin(), it); }
template <typename T = int>
mat<T> mmat(int n, int m=0) { return mat<T>(n, vector<T>(m)); }
template <typename T = int>
vector<T> ivec(int n) { vector<T> v(n); init(v); return v; }
// clang-format on

void yn(bool tf) { print(tf ? "Yes" : "No"); }
void YN(bool tf) { print(tf ? "YES" : "NO"); }

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
// -------------------------------------------------------------------
// sort 1 2 3 4
// pqr 1 2 3 must impl >

signed main() {
    cin.tie(0), cout.tie(0), ios::sync_with_stdio(false);
    int n;
    cin >> n;
    string s;
    cin >> s;
    vector<bool> memo1(10);
    vector<bool> memo2(100);
    vector<bool> memo3(1000);

    for (char c : s) {
        int nn = c - '0';
        rep (i, 100) {
            if (memo2[i]) {
                memo3[i * 10 + nn] = true;
            }
        }
        rep (i, 10) {
            if (memo1[i]) memo2[i * 10 + nn] = true;
        }
        memo1[nn] = true;
    }

    int cnt = 0;
    rep (i, 1000)
        if (memo3[i]) cnt++;
    print(cnt);

    return 0;
}


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

using ll = long long;

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

  // Sを使い切れない場合
  if(2 * N > M) {
    cout << M / 2 << endl;
    return 0;
  }
  // Sを使い切れる場合
  ll ans = 0;
  ans += N;               // Sを消費
  ans += (M - 2 * N) / 4; // Sを消費して残ったcでいくつくれるか
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
import heapq

n, m = map(int, input().split())
if m == n-1:
  print(0)
  exit()
if n < 2*(n-m-1):
  print("Impossible")
  exit()
A = tuple(map(int, input().split()))
G = [[] for _ in range(n)]
for _ in range(m):
  x, y = map(int, input().split())
  G[x].append(y)
  G[y].append(x)
ans = 0
L = []
seen = [False]*n
def dfs(v):
  global ans
  K = []
  stack = [v]
  while stack:
    v = stack.pop()
    heapq.heappush(K, A[v])
    seen[v] = True
    for nv in G[v]:
      if seen[nv]:
        continue
      stack.append(nv)
  ans += heapq.heappop(K)
  for k in K:
    heapq.heappush(L, k)
for i in range(n):
  if not seen[i]:
    dfs(i)
for _ in range(n-m-2):
  ans += heapq.heappop(L)
print(ans)

Measured memory_bytes: 104344
#include<bits/stdc++.h>
#define rep(i, n) for (int i=0;i<(n);i++)
using namespace std;
#define vecout(V) for(int i=0;i<V.size();i++) {cout<<V[i]<<endl;}
typedef long long ll;

int main(void){
    int n;
    cin>>n;
    string s;
    cin>>s;
    if(n%2==1){
        cout<<"No"<<endl;
    }
    else {
        int flag=0;
        rep(i, n/2){
            if(s[i]!=s[i+n/2]) {
                flag=1;
                break;
            }
        }
        if(flag==0) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
    return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <queue>
#include <cstring>
using namespace std;
#define MAX 1005

char JOI[MAX][MAX];
int h,w,n;
int dx[]={0,-1,0,1};
int dy[]={1,0,-1,0};

pair<int, int> goal[10];
bool check(int a,int b){
    return (a>=1&&a<=h&&b>=1&&b<=w);
}

int step[MAX][MAX];
int bfs(pair<int, int> st,pair<int, int> en){
    queue<pair<int,int> > q;
    q.push(st);
    memset(step, -1, sizeof(step));
    step[st.first][st.second]=0;
    int stp=0;
    while(!q.empty()){
        pair<int, int> S=q.front(); q.pop();
        int x=S.first;  int y=S.second;
        stp=step[x][y];
        for(int i=0; i<4; i++){
            int cx=x+dx[i]; int cy=y+dy[i];
            if(check(cx, cy)){
                if(JOI[cx][cy]!='X'&&step[cx][cy]==-1){
                    if(cx==en.first&&cy==en.second) return stp+1;
                    q.push(make_pair(cx, cy));
                    step[cx][cy]=stp+1;
                }
            }
        }
    }
}
int main(){
    cin>>h>>w>>n;
    for(int i=1; i<=h; i++){
        for(int j=1; j<=w; j++){
            cin>>JOI[i][j];
            if(JOI[i][j]=='S') goal[0]=make_pair(i, j);
            else if(JOI[i][j]>='0'&&JOI[i][j]<='9'){
                int x=JOI[i][j]-'0';
                goal[x]=make_pair(i, j);
            }
        }
    }
    int ans=0;
    for(int i=0; i<n; i++){
        ans+=bfs(goal[i],goal[i+1]);
    }
    cout<<ans<<endl;
}

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

class Main{
    public static void main(String[] args){
        FastScanner fsc=new FastScanner();
        int m=fsc.nextInt();
        long[] d=new long[m];
        long[] c=new long[m];
        long numSum=0;
        long digSum=0;
        for(int i=0;i<m;i++){
            d[i]=fsc.nextLong();
            c[i]=fsc.nextLong();
            numSum+=c[i]*d[i];
            digSum+=c[i];
        }
        fsc.close();
        long ans=(digSum-1l)+numSum/9l;
        if(numSum%9==0) ans-=1;
        System.out.println(ans);
    }
    static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;
        private boolean hasNextByte(){
            if(ptr<buflen) return true;
            else{
                ptr = 0;
                try{
                    buflen = in.read(buffer);
                }
                catch(IOException e){
                    e.printStackTrace();
                }
                if(buflen<=0) return false;
            }
        return true;
        }
        private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
        private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
        public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while(isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }
        public long nextLong() {
            if (!hasNext()) throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) throw new NumberFormatException();
            while(true){
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                }
                else if(b == -1 || !isPrintableChar(b)) return minus ? -n : n;
                else throw new NumberFormatException();
                b = readByte();
            }
        }
        public int nextInt() {
            long nl = nextLong();
            if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
            return (int) nl;
        }
        public double nextDouble() { return Double.parseDouble(next());}
        public void close(){
            try{in.close();}
            catch(IOException e){e.printStackTrace();}
        }
    }
}

Measured memory_bytes: 26708