akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;

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

// Self settings
// clang-format off
#define MAX_N 100000
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
#define SLN(i,N) (i == N-1 ? "\n" : " ")
// clang-format on

int n;
int v[MAX_N];

void solve()
{
  map<int, int> m[2];
  for (int i = 0; i < n; i++) {
    m[i % 2][v[i]]++;
  }
  priority_queue<P> q[2];
  for (int i = 0; i < 2; i++) {
    for (auto v : m[i]) {
      q[i].push(P(v.second, v.first));
    }
  }

  int d0, d1;
  // もしも同じ数字が一番数が多い場合条件2に反するので
  // 数が多い方をそのまま、数が少ない方を二番目に多い方に変える
  // ただし、二個同じcntのがある場合はそちらの pop を優先する
  P p0 = P(0, 0), p1 = P(0, 0);
  while (p0.second == p1.second) {
    p0 = q[0].top();
    q[0].pop();
    p1 = q[1].top();
    q[1].pop();

    // もし同じ数字なら違う数字に変える
    if (p0.second == p1.second) {
      // どっちに交換したほうがいいか調べてみる
      P p0sub, p1sub;
      if (!q[1].empty())
        p1sub = q[1].top();
      else
        p1sub = P(0, -1);
      if (!q[0].empty())
        p0sub = q[0].top();
      else
        p0sub = P(0, -1);

      if (p0.first - p0sub.first < p1.first - p1sub.first) {
        p0 = p0sub;
      }
      else {
        p1 = p1sub;
      }
    }
  }
  d0 = p0.first, d1 = p1.first;
  int ans = n / 2 - d0 + n / 2 - d1;
  cout << ans << endl;
}

int main(void)
{
  cin >> n;
  REP(i, n) cin >> v[i];
  solve();
  return 0;
}


Measured memory_bytes: 6524
#include <bits/stdc++.h>
using namespace std;
int main(){
	string S; cin >> S; 
	if(S == "hi" || S == "hihi" || S == "hihihi" || S == "hihihihi" || S == "hihihihihi") cout << "Yes" << endl; 
	else cout << "No" << endl; 
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;

namespace abc113_a
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int X = int.Parse(input[0]);
            int Y = int.Parse(input[1]);
            Console.WriteLine((X+Y/2));
        }
    }
}


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

int main()
{
  int N;
  cin >> N;
  vector<pair<int,int>> AB(N);
  for (int i = 0; i < N; i++){
    int A, B;
    cin >> A >> B;
    AB.at(i) = make_pair(B, A);
  }
  sort(AB.begin(), AB.end());
  int now = 0;
  bool ans = true;
  for (int i = 0; i < N; i++){
    now += AB.at(i).second;
    if (now > AB.at(i).first){
      ans = false;
      break;
    }
  }
  if (ans){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 1920
#include<type_traits>
#include<vector>
#include<array>
#include<iterator>
#include<numeric>
#include<algorithm>

template<typename RandomAccessIterator>
void radix_sort(RandomAccessIterator begin, RandomAccessIterator end){
    if constexpr (std::is_integral_v<typename RandomAccessIterator::value_type>){

        using integer_type = typename RandomAccessIterator::value_type;
        unsigned long now_shift = 0, byte_size = sizeof(integer_type);

        std::vector<integer_type> tmp(end - begin);

        for(unsigned long i{0}; i < byte_size; ++i){
            std::array<unsigned long, 256> count{{}};

            for(auto it = begin; it != end; ++it)++count[(*it >> now_shift) & 255];

            std::partial_sum(std::begin(count), std::end(count), std::begin(count));

            for(auto it = end; it-- != begin; )tmp[--count[(*it >> now_shift) & 255]] = *it;

            std::copy(std::begin(tmp), std::end(tmp), begin);

            now_shift += 8;
        }

        if constexpr (std::is_signed_v<integer_type>)std::rotate(begin, std::partition_point(begin, end, [](auto i){return i >= 0;}), end);

    } else if constexpr (std::is_integral_v<typename RandomAccessIterator::value_type::first_type>){

        using pair_type = typename RandomAccessIterator::value_type;
        using key_type = typename pair_type::second_type;

        unsigned long now_shift = 0, byte_size = sizeof(key_type);

        std::vector<pair_type> tmp(end - begin);

        for(unsigned long i{0}; i < byte_size; ++i){
            std::array<unsigned long, 256> count{{}};

            for(auto it = begin; it != end; ++it)++count[(it -> first >> now_shift) & 255];

            std::partial_sum(std::begin(count), std::end(count), std::begin(count));

            for(auto it = end; it-- != begin; )tmp[--count[(it -> first >> now_shift) & 255]] = *it;

            std::copy(std::begin(tmp), std::end(tmp), begin);

            now_shift += 8;
        }

        if constexpr (std::is_signed_v<key_type>)std::rotate(begin, std::partition_point(begin, end, [](auto i){return i.first >= 0;}), end);

    } else puts("guee radix sort muzukashi.");
}

#include<random>
#include<iostream>
#include<utility>
#include<string>

int main(){
    using namespace std;
    unsigned long N;
    cin >> N;
    vector<unsigned long> A(N);
    for(auto&& i : A)cin >> i;
    radix_sort(begin(A), end(A));
    if(A.front() == 0)return 0 & puts("0");
    unsigned long tmp{1};
    for(const auto& i : A){
        if(1000000000000000000 / i < tmp)return 0 & puts("-1");
        tmp *= i;
    }
    cout << tmp << endl;
}

Measured memory_bytes: 4768
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <list>
#include <string>
#include <numeric>
#include <math.h>
#include <set>
#include <map>
#include <fstream>
#include <sstream>
#include <iterator>
#include <complex>
using namespace std;

int main()
{
	int A,B;
	cin>>A>>B;
	int result;
	if(A>=13)
	{
		result = B;
	}
	else if(A>=6)
	{
		result = B/2;
	}
	else
	{
		result = 0;
	}
	cout<<result<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ar array
#define endl '\n'
#define ll long long
#define in insert
#define pb push_back
#define vt vector
#define P_Q(x) priority_queue<x>
#define p_q(x) priority_queue<x, vector<x>, greater<x>>
#define Rep(i,a,b) for(int i=a;i<=b;i++)
#define Rev(i,a,b) for(ll i=a;i>=b;i--)
#define FOR(m) Rep(i,1,m)
#define For(m) Rep(i,0,m-1)
#define Rbl(x,a) for(auto &x : a)
#define FIO ios::sync_with_stdio(0);   cin.tie(0);
#define F first
#define S second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define vpii vector<pii>
#define vpll vector<pll>
#define all(x) (x).begin(),(x).end()
#define sz(x) (int) (x).size()
const ll INF = 0x3f3f3f3f3f3f3f3fll;
#define mod 1000000007
 
const int mxN = 50;
//ll a[mxN];
ll n, k;
vt<vt<ll>> M(mxN, vt<ll>(mxN));
vt<vt<ll>> can(mxN, vt<ll>(mxN));

vt<vt<ll>> mul(vt<vt<ll>> A, vt<vt<ll>> B)
{
    vt<vt<ll>> C(n, vt<ll>(n, 0));
    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < n; j++)
        {
            for(int k = 0; k < n; k++)
            {
                C[i][k] += A[i][j] * B[j][k];
                C[i][k] %= mod;
            }
        }
    }
    return C;
}
 
 
int main()
{
FIO
 
    int t = 1;
    // cin >> t;
    while(t--)
    {
        cin >> n >> k;
        For(n) Rep(j,0,n-1) cin >> can[i][j];
        M = can;
        vt<vt<ll>> ans(n, vt<ll>(n, 0));
        for(int i = 0; i < n; i++)
            ans[i][i] = 1;
        while(k)
        {
            if(k&1)
                ans = mul(ans, M);
            M = mul(M, M);
            k >>= 1;
        }

        ll sum = 0;
        for(int i= 0; i < n; i++)
        {
            for(int j = 0; j < n; j++)
            {
                sum += ans[i][j];
                sum %= mod;
            }
        }

        cout << sum << endl;
    }

     
}

Measured memory_bytes: 3728
#include <stdio.h>
#include <math.h>

int main(){
	
	int x, a, b;
	scanf( "%d %d %d", &x, &a, &b );
	
	if( fabs((double)(x-a)) < fabs((double)(x-b)) ){
		printf("A");
	}else{
		printf("B");
	}
	
	return 0;
	
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <map>
#include <algorithm>

using namespace std;

int main() {
	string d;
	cin >> d;

	string A = "AIZUNYAN";
	string dA = "AIDUNYAN";
	int alen = (int)A.size();

	map<char, int> azu;
	for (int i=0; i<alen; i++) {
		azu[dA[i]]++;
	}

	int len = (int)d.size();
	for (int i = 0; i<len-alen+1; i++) {
		map<char, int> dzu;
		for (int j=0; j<alen; j++) {
			dzu[d[i+j]]++;
		}

		bool ok = true;
		for (int j=0; j<26 && ok; j++) {
			if (azu['A'+j]!=dzu['A'+j]) ok = false;
		}

		if (ok) {
			for (int j=0; j<alen; j++) {
				d[i+j] = A[j];
			}
			i = i+alen-1;
		}
	}

	cout << d << endl;

	return 0;
}

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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

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

    vec A(26, 0);
    REP(i,0,SZ(w)) ++A[w[i]-'a'];

    bool f = true;
    REP(i,0,26) {
        if(A[i] % 2 == 1) {
            f = false;
            break;
        }
    }

    if(f) PR("Yes");
    else PR("No");

    return 0;
}

/*



*/

Measured memory_bytes: 3616
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int main(){
  int N,M;cin>>N>>M;
  int i,j,k,l;
  int ans=0;
  int s[15][15];
  int K[M];
  rep(i,M){
    cin>>K[i];
    rep(j,K[i]) cin>>s[i][j];
  }
  vector<int> p;
  rep(i,M){
    int a;cin>>a;p.pb(a);
  }
  rep(i,1<<N){
    // cout<<i<<endl;
    bool ok=true;
    rep(j,M){
      int cnt=0;
      rep(k,K[j]){
        if( (i>> (s[j][k]-1) ) &1) cnt++;
       }
      if(cnt%2 != p.at(j)) ok = false;
    }
    if(ok) ans++;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
using namespace std;

int main() {
	const long long int mod = 1000000007;
	map<long long int, long long int>mp;
	//cout << fixed << setprecision(10);
	long long int n, k, a[200000], b[200000], num[200000] = {};
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		cin >> a[i] >> b[i];
		num[a[i]] += b[i];
	}
	for (int i = 1; i < 300000; i++) {
		k -= num[i];
		if (k <= 0) { cout << i << endl; return 0; }
	}
}


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

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

void main()
{
    auto s = sread();
    long t;
    foreach (e; s)
    {
        t += (e == '+' ? 1 : -1);
    }
    t.writeln();
}

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


Measured memory_bytes: 256
#
# Written by NoKnowledgeGG @YlePhan
# ('ω')
#
#import math
#mod = 10**9+7
#import itertools
#import fractions
#import numpy as np
#mod = 10**4 + 7
"""def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)"""

""" n! mod m 階乗
mod = 1e9 + 7
N = 10000000
fac = [0] * N
def ini():
  fac[0] = 1 % mod
  for i in range(1,N):
    fac[i] = fac[i-1] * i % mod"""

"""mod = 1e9+7
N = 10000000
pw = [0] * N
def ini(c):
  pw[0] = 1 % mod
  for i in range(1,N):
    pw[i] = pw[i-1] * c % mod"""

"""
def YEILD():
  yield 'one'
  yield 'two'
  yield 'three'
generator = YEILD()
print(next(generator))
print(next(generator))
print(next(generator))
"""
"""def gcd_(a,b):
  if b == 0:#結局はc,0の最大公約数はcなのに
    return a
  return gcd_(a,a % b) # a = p * b + q"""
"""def extgcd(a,b,x,y):
  d = a
  if b!=0:
    d = extgcd(b,a%b,y,x)
    y -= (a//b) * x
    print(x,y)
  else:
    x = 1
    y = 0
  return d"""

# 最大公約数 と 最小公倍数
"""def gcd(a,b):
  if b == 0:
    return a
  return gcd(b, a % b)
def lcm(a,b):
  g = gcd(a,b)
  return (a * b) // g"""

# 二分探索
"""import bisect # 二分探索
print(A,bisect.bisect_left(A,4))
print(C,n - bisect.bisect_right(C,4))
print(sum(bisect.bisect_left(A,b) * (n-bisect.bisect_right(C,b)) for b in B))"""

# 円周率 pi
"""import math
pi_ = math.pi"""

# エラトステネスの篩
"""def Erato(n):
    prime = []
    is_prime = [True] * (n+1)
    p = 0
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2,n+1):
      if is_prime[i] == True:
        prime.append(i)
        p += 1
        for j in range(2 * i,n+1,i):
          is_prime[j] = False
    return p"""

def readInts():
  return list(map(int,input().split()))
mod = 10**9 + 7
def main():
  n = int(input())
  s = input()
  t = s.count('R')*s.count('G')*s.count('B')
  for i in range(n):
    j = 1
    while i+j*2<n:
      # print(s[i],s[i+j],s[i+2*j])
      # R R G
	  # R G B こいつがあかん
      if s[i]!= s[i+j] and s[i+j]!=s[i+j*2] and s[i] != s[i+j*2]:
        t-=1
      j+=1
  print(t)

  

if __name__ == '__main__':
  main()


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int n,m;
char mp[125][125];
int ban[125][125];

int main(){
  scanf("%d%d",&n,&m);
  REP(i,n)scanf("%s",mp[i]);
  REP(i,m)ban[0][i]=1;
  REP(i,n)REP(j,m){
    if(mp[i][j]=='o'){
      ban[i][j]=1;
      if(j>0)ban[i][j-1]=1;
      if(j<m-1)ban[i][j+1]=1;
    }
    if(mp[i][j]=='x'){
      FOR(x,-1,2)FOR(y,-1,2){
        if(i+x>=0&&i+x<n&&j+y>=0&&j+y<m)ban[i+x][j+y]=1;
      }
    }
  }
  int ans = 0;
  REP(i,n)REP(j,m)ans+=1-ban[i][j];
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
int main(){
  int W,H,x,y,r;
  cin>>W>>H>>x>>y>>r;

  if((x - r) >= 0 && (y - r) >= 0 && (x + r) <= W && (y + r) <= H ) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;

  return 0;
}



Measured memory_bytes: 3116
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product, accumulate, combinations, product
#import bisect
import numpy as np
#from copy import deepcopy
#from collections import deque

INF = 1 << 50

def run():
    H, W = map(int, sysread().split())
    N = int(sysread())
    A = list(map(int, sysread().split()))
    MAP = np.zeros(H * W, dtype=np.int32)
    idx = 0
    for i, a in enumerate(A, 1):
        MAP[idx:idx+a] = i
        idx += a

    MAP = MAP.reshape(H,W)
    for i in range(1, len(MAP), 2):
        MAP[i, :] = MAP[i, ::-1]

    for row in MAP:
        for val in row:
            print(val, end=' ')
        print('')


if __name__ == "__main__":
    run()

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

int main(void)
{
    char s[101],i,ans=0,length;

    scanf("%s",s);

    length=strlen(s);

    for ( i = 0; i <= length/2-1; i++)
    {
        if(s[i]!=s[length-1-i]) ans++;
    }

    printf("%d",ans);

    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
using namespace std;

typedef long long ll;

#define INF 10e17 // 4倍しても(4回足しても)long longを溢れない
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<int>())

int main() {
  string s;
  int tt;
  cin >> tt;
  cin >> s;
  int a = 0,b = 0;
  for (auto itr : s) {
    if (itr == 'R') a +=1 ;
    else b += 1;

  }
      if (a > b) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"strings"
)

func main() {
	var n, k int
	var s []string

	fmt.Scan(&n, &k)
	var tmpS string
	fmt.Scan(&tmpS)
	s = strings.Split(tmpS, "")

	s[k-1] = strings.ToLower(s[k-1])
	fmt.Println(strings.Join(s, ""))
}


Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int hp = Integer.parseInt(sc.next());
        int atk = Integer.parseInt(sc.next());
        int count = 0;
        while (hp > 0) {
            hp -= atk;
            count++;
        }
        System.out.println(count);
        sc.close();
    }
}


Measured memory_bytes: 35596
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define ull unsigned long long
#define pb(a) push_back(a)
#define INF 999999999
#define print(a) cout << a << endl
using namespace std;
typedef vector<int> vint;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

int main(){
    int n;
    bool flag = true;
    cin >> n;
    int pt = 0;
    int px = 0;
    int py = 0;
    int t,x,y;
    FOR(i,0,n){
        cin >> t >> x >> y;
        if ((t-pt-abs(x-px)-abs(py-y))%2==1 || t-pt<abs(x-px)+abs(py-y)){
            flag = false;
        }
        pt = t;
        px = x;
        py = y;
    }
    
    if (flag){
        print("Yes");
    }else{
        print("No");
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const long double PI  = acos(-1.0L);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
#define chmax(a,b) a = (((a)<(b))?(b):(a))
#define chmin(a,b) a = (((a)>(b))?(b):(a))

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}


signed main(){
	int a,b; cin>>a>>b;
	cout<<(a-1)*(b-1)<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int maxn = 1e5 + 5;
int n;
vector<pair<int, int>> g[maxn];
bool mark[maxn];
int ans[maxn];
void dfs(int x, int d) {
	ans[x] = d % 2;
	mark[x] = true;
	for(auto i : g[x]) {
		int u = i.first;
		int s = i.second;
		if(!mark[u]) 
			dfs(u, d + s);
	}
}

int32_t main() {
	cin >> n;
	for(int i = 0; i < n - 1; i++) {
		int u, v, w;
		cin >> u >> v >> w;
		u--, v--;
		g[u].push_back({v, w});
		g[v].push_back({u, w});
	}
	dfs(0, 0);
	for(int i = 0; i < n; i++)
		cout << ans[i] << endl;
}

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

int main() {
	int n;
	cin >> n;
	vector<long long> l(n + 1);
	l[0] = 2;
	l[1] = 1;
	for (int i = 2; i <= n; i++)
		l[i] = l[i - 1] + l[i - 2];
	cout << l[n] << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <algorithm>
#include <tuple>
#include <cmath>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int> >
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
using namespace std;

const ll mod = 1000000000 + 7;

int H, W;
ll dp[1000 + 10][1000 + 10]; //dp[i][j]:(i,j)に至る場合の数
bool grid[1000 + 10][1000 + 10];

int main(void) {
    cin >> H >> W;
    for (int i=1; i<=H; i++) {
        for (int j=1; j<=W; j++) {
            grid[i][j] = true;
            dp[i][j] = 0;
            char tmp;
            cin >> tmp;
            if (tmp == '#') {
                grid[i][j] = false;
            }
        }
    }
    
    for (int i=1; i<=H; i++) {
        if (!grid[i][1]) {
            break;
        } else {
            dp[i][1] = 1;
        }
    }
    for (int i=1; i<=W; i++) {
        if (!grid[1][i]) {
            break;
        } else {
            dp[1][i] = 1;
        }
    }
    
    for (int i=2; i<=H; i++) {
        for (int j=2; j<=W; j++) {
            dp[i][j] = 0;
            if (grid[i-1][j]) {
                dp[i][j] += dp[i-1][j];
                dp[i][j] %= mod;
            }
            if (grid[i][j-1]) {
                dp[i][j] += dp[i][j-1];
                dp[i][j] %= mod;
            }
        }
    }
    
    cout << dp[H][W] << endl;
    return 0;
}



Measured memory_bytes: 9088
#include<algorithm>//sort(all(変数),greater<型名>())　で降順に
#include<bits/stdc++.h>
#include<cmath>//切り上げceil(値)
#include<deque>
#include<iomanip>//setprecision(数字)
#include<iostream>
#include<list>
#include<map>
#include<numeric> //xとyの最大公約数は__gcd(x,y),xとyの最小公倍数は(x*y)/__gcd
#include<queue>//priority_queue<型名> 変数：優先度付きキュー　最大値の探索が早い
#include<set>
#include<stack>
#include<string>
#include<vector>
#define rep0(i,n)  for(ll i=0; i<n; i++)
#define rrep0(i,n) for(ll i=n-1; 0<=i; i--)
#define vll vector<ll>
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define INF 1e18
using ll = long long;
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; }

int main(){
  int n;  cin >> n;
  string s;  cin >> s;
  if(n == 1 or n%2==1){
    cout << "No";
    return 0;
  }
  rep0(i,n/2){
    if(s[i] != s[i+n/2]){
      cout << "No";
      return 0;
    }
  }
  cout << "Yes";
}


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

#define ll long long
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define pr(a, b) pair<a, b>
#define si set<int>
#define sl set<long long>
#define pq prioirty_queue
#define all(v) v.begin(),v.end()
#define left  (2*idx)+1
#define right (2*idx)+2
#define frt(i,a,b) for(ll i=a; i<b; i++)
#define rew(i,a,b) for(ll i=a; i>=b; i--)
#define fre(i,a,b) for(ll i=a; i<=b; i++)

#define mod %
#define N 13
#define MOD (ll)(1e9 + 7)
#define test if(!true)


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

	vi v(n, 0);
	vi a(n, 0);

	frt(i, 0, n)
	{
		cin >> v[i];
		a[i] = v[i];
	}

	sort(all(v));
	reverse(all(v));
	frt(i, 0, n)
	{
		if(v[0] == a[i])
		{
			cout << v[1] << "\n";
		}
		else
		{
			cout << v[0] << "\n";
		}
	}
    return 0;
}




Measured memory_bytes: 3200
#include <stdio.h>
#include <string.h>
    
int A[2000001];
int heap_size;
void insert(int key){ 
  heap_size++;
  A[heap_size] = -1;
  hpIK(key);
}
  
void hpIK(int key){  
  int i = heap_size, tmp; 
  if(key < A[i]){
    return;
  }
  A[i] = key;
  while(i > 1 && A[parentNode(i)] < A[i]){
    tmp = A[parentNode(i)];
    A[parentNode(i)] = A[i];
    A[i] = tmp;
    i = parentNode(i);
  }  
}
  
int hpEM(void){
  int max;
  if(heap_size < 1) return;
  max = A[1];
  A[1] = A[heap_size];
  heap_size--;
  maxHp(1);
  return max;  
}
void maxHp(int i){
  int l = leftChild(i);
  int r = rightChild(i);
  int largest, tmp;       
  if(l <= heap_size && A[l] > A[i]){
    largest = l;    
  }else{
    largest = i;
  }
  if(r <= heap_size && A[r] > A[largest]){
    largest = r;    
  }
  if(largest != i){
    tmp = A[i];
    A[i] = A[largest];
    A[largest] = tmp;
    maxHp(largest);
  }
}
  
int parentNode(int i){
  return (int)i/2;
}
   
int leftChild(int i){
  return 2*i;
}
   
int rightChild(int i){
  return 2*i+1;
}

int main(){
  int i, key;
  char com[8];
  while(scanf("%s",com), strcmp(com,"end")){
    if(com[0]=='i'){
      scanf("%d",&key);
      insert(key);
    }
    if(com[0]=='e'){
      printf("%d\n",hpEM());
    }
  }
  return 0;
}

Measured memory_bytes: 4700
N, M = map(int, input().split())

ac_flg = [0]*N
wa_flg = [0]*N
wa_count = 0
ac_count = 0

for i in range(M):
    p, s = input().split()
    if s == 'WA' and ac_flg[int(p)-1] == 0:
        wa_flg[int(p)-1] += 1

    if s == 'AC' and ac_flg[int(p)-1] == 0:
        ac_count += 1
        ac_flg[int(p)-1] =1
        wa_count += wa_flg[int(p)-1]

print(ac_count, wa_count)

Measured memory_bytes: 53464
//Utkarsh-raj

#include<bits/stdc++.h>

#define ll long long int
#define vc vector
#define mod 1000000007
#define mp make_pair
#define pb push_back
#define nl cout<<endl;
#define ff first
#define ss second

using namespace std;

const int maskSize = 1<<21;

ll dp[21][maskSize];

ll solve(int **arr, int i, int mask, int n){
	// base case
	if(i == -1){
		if(mask == pow(2, n) - 1)
			return 1;
		else
			return 0;
	}

	if(dp[i][mask] != -1)
		return dp[i][mask];

	// rec case
	ll ans = 0;
	for(int j=0; j<n; j++){
		if(arr[i][j] == 1 && (mask&(1<<j)) == 0){
			ans = (ans + solve(arr, i-1, (mask|(1<<j)), n))%mod;
		}
	}
	return dp[i][mask] = ans;
}

int main()
{
	ifstream myFile("task.in");
    if(!myFile.fail())
    {
        assert(freopen("task.in", "r", stdin));
    }

    memset(dp, -1, sizeof(dp));

    int n;
    cin>>n;

    int **arr = new int*[n];
    for(int i=0; i<n; i++){
    	arr[i] = new int[n];
    }

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

    ll ans = solve(arr, n-1, 0, n);
    cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 344320
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define Max(a, b) (a > b ? a : b)
#define Min(a, b) (a < b ? a : b)
#define ii pair<int, int>
#define fi first
#define se second
const int MAX = 200000; //2 * 10^5
const int MOD = 1000000007; //10^9 + 7
const int OO = 0x3f3f3f3f; // 0x3f3f3f3f;

int32_t main()
{
	int n;
	cin >> n;
	int ans = 0;	
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= n; j++)
			for(int k = 1; k <= n; k++)
				ans += __gcd( i, __gcd(j, k) );
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3632
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String N = scan.next();
		char[] c = N.toCharArray();
		if(c[0]==c[1] && c[1] == c[2]){
			System.out.println("Yes");
		}else if(c[1]==c[2] && c[2] == c[3]){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}


	}

}


Measured memory_bytes: 22996
#include<iostream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<vector>
#include<array>
#include<string>
#include<stack>
#include<queue>
#include<algorithm>
#include<cassert>
#include<functional>
#include<random>
#include<complex>
#include<bitset>
#include<chrono>
//#include<boost/multiprecision/cpp_int.hpp>
#define int int64_t
#define uint uint64_t
#define REP(i, a, b) for (int64_t i = (int64_t)(a); i < (int64_t)(b); i++)
#define rep(i, a) REP(i, 0, a)
#define EACH(i, a) for (auto i: a)
#define ITR(x, a) for (auto x = a.begin(); x != a.end(); x++)
#define ALL(a) (a.begin()), (a.end())
#define HAS(a, x) (a.find(x) != a.end())
#define Min(x) *min_element(ALL(x))
#define Max(x) *max_element(ALL(x))
#define Unique(L) (L.erase(unique(ALL(L)), L.end()))
#define veccat(v1, v2) std::copy((v2).begin(),(v2).end(),std::back_inserter(v1)/*v1の後ろにv2を入れる*/)
#define intmax (std::numeric_limits<int64_t>::max() / 4)
using namespace std;
//typedef boost::multiprecision::cpp_int bigint;
const double EPS = 1e-9;
const double PI = acos(-1.0);

int S[2048][2048], sum[2048][2048], tate[2048][2048], yoko[2048][2048];
int N, M, Q;

void init() {
	REP(i, 1, 2048)REP(j, 1, 2048) {
		sum[i][j] = S[i][j] + sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1];
	}

	REP(i, 2, 2048)REP(j, 1, 2048) {
		tate[i][j] = tate[i - 1][j] + tate[i][j - 1] - tate[i - 1][j - 1] + ((S[i][j] && S[i - 1][j]) ? 1 : 0);
	}

	REP(i, 1, 2048)REP(j, 2, 2048) {
		yoko[i][j] = yoko[i][j - 1] + yoko[i - 1][j] - yoko[i - 1][j - 1] + ((S[i][j] && S[i][j - 1]) ? 1 : 0);
	}
}

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

	cin >> N >> M >> Q;

	rep(i, N) {
		string s;
		cin >> s;
		rep(j, M)S[i + 1][j + 1] = s[j] - '0';
	}

	init();
	
	rep(qq, Q) {
		int x1, y1, x2, y2;
		cin >> x1 >> y1 >> x2 >> y2;

		int b = sum[x2][y2] - sum[x1-1][y2] - sum[x2][y1-1] + sum[x1-1][y1-1];
		int t = tate[x2][y2] - tate[x1][y2] - tate[x2][y1-1] + tate[x1][y1-1];
		int y = yoko[x2][y2] - yoko[x1-1][y2] - yoko[x2][y1] + yoko[x1-1][y1];
		cout << b - t - y << endl;
	}


	return 0;
}

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

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

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

    if( num == 2 || num == 3){
      ++ans;
    }else{
      int work = pow(num,1/2.0);
      for(int k=2;k<=work;++k){
	if(num % k == 0) break;
	if(k == work) ++ans;
      }
    }
  }

  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 3276
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <tuple>
#include <utility>
#include <vector>
#define ll long long
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl
#define COYE cout<<"YES"<<endl
#define COYe cout<<"Yes"<<endl
#define COye cout<<"yes"<<endl
#define CONO cout<<"NO"<<endl
#define CONo cout<<"No"<<endl
#define COno cout<<"no"<<endl
#define FORE(i,a) for(auto &i:a)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define PB push_back
#define MP make_pair
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define EACH(V,i) for(typeof((V).begin()) i=(V).begin();i!=(V).end();++i)
#define equals(a,b) (fabs((a)-(b))<EPS)
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MMOD 998244353
#define MAX 2010101
using namespace std;
using Edge=pair<ll,ll>;
using Graph=vector<vector<int>>;
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T>inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
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;}
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef long long LL;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,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 main(){
  ll N;
  cin>>N;
  ll A[3*N+1];
  RREP(i,3*N) cin>>A[i];
  
  ll Fsum=0,Bsum=0;
  priority_queue<ll> F,FM,B,BM;
  for(int i=1; i<=N; ++i) F.push(A[i]),FM.push(-A[i]),Fsum+=A[i];
  for(int i=3*N; i>2*N; --i) B.push(-A[i]),BM.push(A[i]),Bsum+=A[i];
  
  ll FX[3*N+1]={},BX[3*N+1]={};
  FX[N]=Fsum;
  BX[2*N+1]=Bsum;
  
  for(int i=N+1; i<=2*N; ++i){
    F.push(A[i]);
    FM.push(-A[i]);
    Fsum+=A[i]+FM.top();
    FM.pop();
    FX[i]=Fsum;
  }
  
  for(int i=2*N; i>N; --i){
    B.push(-A[i]);
    BM.push(A[i]);
    Bsum+=A[i]-BM.top();
    BM.pop();
    BX[i]=Bsum;
  }
  
  ll ans=-INF;
  for(int i=N; i<=2*N; ++i){
    chmax(ans,FX[i]-BX[i+1]);
  }
  
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 15464
#include <cstdio>
#include <iostream>
#include <deque>
using namespace std;

int main(){
  deque<int> st;
  string s; cin >> s;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'B') {
      if (st.empty()) continue;
      st.pop_back();
    }
    else st.push_back(s[i]-'0');
  }

  for (int i = 0; i < st.size(); i++) {
    cout << st[i];
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.LinkedList; 
import java.util.Queue;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		Queue<String> qu = new LinkedList<>();
		Scanner scan = new Scanner(System.in);

		int amt = scan.nextInt();
		int quant = scan.nextInt();
		
		for(int i=0; i<amt; i++){
			qu.add(scan.next() + " " + scan.next());
			
		}
		
		int timer = 0;
		int q = quant;
		int i=0;
		String[] results = new String[amt];
		while(qu.size() > 0) {
			String[] temparr = qu.peek().split("\\s+");
			String name = temparr[0];
			int num = Integer.parseInt(temparr[1]);
			if(q>num) {
				timer += num;
				//q= q-num;
				num=0;

			} else if(num>q){
				timer += q;
				num = num - q;
				q=0;

			} else {

				timer += q;
				num=0;
				q=0;

			}

			if(num==0 && qu.size() > 0 && q==0) {
				results[i]=name + " " + timer;
				i++;
				q = quant;
				qu.remove();
			} else
			if(num==0 && qu.size() > 0) {
				results[i]= name + " " + timer;
				i++;
				qu.remove();

			} else
			if(q==0 && qu.size() > 0) {
				q = quant;
				qu.remove();
				qu.add(name + " " + num);
			}
			
		}
		for(int j=0; j<results.length;j++) {
			System.out.println(results[j]);
		}
		
	}
	
}



Measured memory_bytes: 118972
import sys


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


sys.setrecursionlimit(10 ** 9)


class UnionFind:
    # 初期化
    def __init__(self, n_nodes):
        self.n_nodes = n_nodes
        # 親要素のノード番号を格納する.初めは全て親ノード.
        # self.parent[x] == x の時，そのノードは根.
        self.parent = [i for i in range(n_nodes)]
        # 木の高さを格納する．
        self.rank = [1] * n_nodes
        # 自分と同じグループの要素数を格納．親要素を参照するようにする
        self.size = [1] * n_nodes

    # 検索. 根を返す.
    def find(self, x):
        if self.parent[x] == x:
            return x
        else:
            # 一度調べた値は，根に繋ぎ直す.
            self.parent[x] = self.find(self.parent[x])
            return self.parent[x]

    # 併合.
    # 木の高さが低くなるように.
    # 親要素の書き換えは少ない方がいい
    def unite(self, x, y):
        # 根を探す．
        x = self.find(x)
        y = self.find(y)
        # 根が同じ場合はそのまま
        if x == y:
            return
        # 木の高さを比較し，低い方を高い方の根に貼る.
        if self.rank[x] > self.rank[y]:
            self.parent[y] = x
            self.size[x] += self.size[y]
        else:
            self.parent[x] = y
            self.size[y] += self.size[x]
            if self.rank[x] == self.rank[y]:
                self.rank[y] += 1

    # 同じ集合に属するか判定
    def check(self, x, y):
        return self.find(x) == self.find(y)

    # 同一グループに所属する要素数を返す
    def get_size(self, x):
        return self.size[self.find(x)]

    # 親要素のリストを返す
    def get_parent_list(self):
        return [i for i in range(self.n_nodes) if self.find(i) == i]

    # グループの数を返す
    def get_n_groups(self):
        return len(self.get_parent_list())

    # 同じグループに所属する要素の集合を返す
    def get_members(self, x):
        parent = self.find(x)
        return [i for i in range(self.n_nodes) if self.find(i) == parent]

    # 全ての根に対する，グループのメンバーを返す．
    def get_members_dict(self):
        return {par: self.get_members(par) for par in self.get_parent_list()}


MOD = 10 ** 9 + 7


def main():
    N, M, K = map(int, input().split())
    UF = UnionFind(N)
    friend = [0] * N
    block = [0] * N
    for _ in range(M):
        a, b = map(int, input().split())
        UF.unite(a - 1, b - 1)
        friend[a - 1] += 1
        friend[b - 1] += 1

    for _ in range(K):
        c, d = map(int, input().split())
        if UF.check(c - 1, d - 1):
            block[c - 1] += 1
            block[d - 1] += 1
    answer = []
    for i in range(N):
        answer.append(UF.get_size(i) - friend[i] - block[i] - 1)
    print(*answer, sep=" ")


if __name__ == "__main__":
    main()


Measured memory_bytes: 13404
#include <cstdio>

#define MOD 1000000007

#define MAXN 2000
#define MAXT 2000*2000

int fact[MAXT+1], invFact[MAXT+1];
int dp[MAXN+1][MAXN+1];

inline int lgput(int a, int n){
    int r=1;
    while(n>0){
        if(n%2) r=1LL*r*a%MOD;
        n/=2;
        a=1LL*a*a%MOD;
    }
    return r;
}

inline int comb(int n, int k){
    return 1LL*fact[n]*invFact[k]%MOD*invFact[n-k]%MOD;
}

int main(){
    int n, k;
    scanf("%d%d", &n, &k);

    if(k==1){
        printf("1\n");
        return 0;
    }

    int t=n*k;

    fact[0]=1;
    for(int i=1; i<=t; i++)
        fact[i]=1LL*fact[i-1]*i%MOD;
    invFact[t]=lgput(fact[t], MOD-2);
    for(int i=t-1; i>=0; i--)
        invFact[i]=1LL*invFact[i+1]*(i+1)%MOD;

    dp[0][0]=1;
    for(int i=1; i<=n; i++){
        dp[i][0]=1LL*dp[i-1][0]*comb(i*(k-1)-1, k-2)%MOD;
        for(int j=1; j<=i; j++)
            dp[i][j]=(dp[i][j-1]+1LL*dp[i-1][j]*comb(j+i*(k-1)-1, k-2))%MOD;
    }

    int ans=1LL*dp[n][n]*fact[n]%MOD;
    printf("%d\n", ans);

    return 0;
}


Measured memory_bytes: 46208
#include <algorithm>
#include <iostream>
#include <vector>
#include <stack>
using namespace std;

int main() {
    string X; cin >> X;
    int cntS = 0;
    int kill = 0;
    for (char x : X) {
        if (x == 'S') {
            cntS++;
        } else {
            if (cntS) {
                cntS--; kill++;
            } else {
                // 何もしない
            }
        }
    }
    cout << X.size() - kill * 2 << endl;
    return 0;
}

Measured memory_bytes: 640
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <utility>
#include <numeric>

using namespace std;
typedef long long llong;
typedef unsigned long long ullong;

const ullong MOD = 1000000000 + 7;

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

	vector<int> a, b;
	int cnt = 0;
	for (int i = 0; i < m; i++)
	{
		int x, y;
		cin >> x >> y;

		a.push_back(x);
		b.push_back(y);

		if (x >= n)
		{
			cnt++;
		}
	}

	int v = 0;
	if (cnt < m - 1)
	{
		sort(a.begin(), a.end());
		reverse(a.begin(), a.end());

		
		for (int i = 0; i < m; i++)
		{
			if (a.at(i) < n)
			{
				v += n - a.at(i);
				cnt++;
				if (cnt >= m - 1)
				{
					break;
				}
			}
		}
	}

	cout << v << endl;
}


Measured memory_bytes: 3180
#include <bits/stdc++.h>
#include <cstdlib>  //abs()で絶対値を取得する（整数）
#include <cmath>    //abs()かfabs()で絶対値を取得する（少数）
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
int main(){
    int h, n, a;
    int b = 0;
    cin >> h >> n;
    rep (i,n){
        cin >> a;
        b = b + a;
    }
    if (b >= h){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3632
h,w,m=map(int,input().split())
hl=[0]*h
wl=[0]*w
s=set()
for i in range(m):
  hi,wi=map(int,input().split())
  hl[hi-1]+=1
  wl[wi-1]+=1
  s.add((hi-1)*w+wi-1)
mah=0
mahl=[]
for i in range(h):
  num=hl[i]
  if mah<num:
    mah=num
    mahl=[i]
  elif mah==num:
    mahl.append(i)
maw=0
mawl=[]
for i in range(w):
  num=wl[i]
  if maw<num:
    maw=num
    mawl=[i]
  elif num==maw:
    mawl.append(i)

frag=0
for hi in mahl:
  for wi in mawl:
    if not hi*w+wi in s:
      frag=1
      break
  if frag:break
if frag:
  print(mah+maw)
else:
  print(mah+maw-1)

Measured memory_bytes: 54952
#include <cstdio>
#include <cstring>
char str[2][30];
int main(){
	int n;
	scanf("%d",&n);
	while(n--){
		scanf("%s %s",&str[0],&str[1]);
		int a,b;
		a=strlen(str[0]);
		b=strlen(str[1]);
		int aa=0,bb=0;
		for(int i=0;i<a;i++){
			if(str[0][i]-'0'>=0 && str[0][i]-'0'<=9){
				if(str[0][i+1]=='m'){
					aa+=1000*(str[0][i]-'0');
					i+=1;
				}else if(str[0][i+1]=='c'){
					aa+=100*(str[0][i]-'0');
					i+=1;
				}else if(str[0][i+1]=='x'){
					aa+=10*(str[0][i]-'0');
					i+=1;
				}else{
					aa+=(str[0][i]-'0');
					i+=1;
				}
			}else{
				if(str[0][i]=='m'){
					aa+=1000;
				}else if(str[0][i]=='c'){
					aa+=100;
				}else if(str[0][i]=='x'){
					aa+=10;
				}else{
					aa+=1;
				}
			}
		}
		for(int i=0;i<b;i++){
			if(str[1][i]-'0'>=0 && str[1][i]-'0'<=9){
				if(str[1][i+1]=='m'){
					bb+=1000*(str[1][i]-'0');
					i+=1;
				}else if(str[1][i+1]=='c'){
					bb+=100*(str[1][i]-'0');
					i+=1;
				}else if(str[1][i+1]=='x'){
					bb+=10*(str[1][i]-'0');
					i+=1;
				}else{
					bb+=(str[1][i]-'0');
					i+=1;
				}
			}else{
				if(str[1][i]=='m'){
					bb+=1000;
				}else if(str[1][i]=='c'){
					bb+=100;
				}else if(str[1][i]=='x'){
					bb+=10;
				}else{
					bb+=1;
				}
			}
		}
		int sum=aa+bb;
		int w,x,y,z;
		w=sum/1000;
		x=(sum%1000)/100;
		y=(sum%100)/10;
		z=sum%10;
		if(w>1){
			printf("%dm",w);
		}else if(w==1){
			printf("m");
		}
		if(x>1){
			printf("%dc",x);
		}else if(x==1){
			printf("c");
		}
		if(y>1){
			printf("%dx",y);
		}else if(y==1){
			printf("x");
		}
		if(z>1){
			printf("%di",z);
		}else if(z==1){
			printf("i");
		}
		puts("");
	}
}

Measured memory_bytes: 1048
//Link : https://atcoder.jp/contests/arc072/tasks/arc072_c

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 500001

int d[N];

ll B[N],query[N];

ll dist(ll x,ll y) {
  ll t = abs(x-y);
  return min(x,t);
}
void solve() {
  int n,D;
  scanf("%d %d ", &n,&D);
  B[n] = 1;
  query[0] = D;
  for(int i=1;i<=n;++i) {
    scanf("%d ", &d[i]);
    query[i] = dist(query[i-1],d[i]);
  }
  for(int i=n-1;i;--i) {
    if(B[i+1]*2<=d[i+1]) {
      B[i] = B[i+1];
    } else {
      B[i] = B[i+1] + d[i+1];
    }
  }
  int q;scanf("%d ", &q);
  while(q--) {
    int x;scanf("%d ", &x);
    if(B[x]<=query[x-1]) {
      printf("YES\n");
    } else {
      printf("NO\n");
    }
  }
}

int main() {
    //freopen("input.txt","r",stdin);
    solve();
    return 0;
}


Measured memory_bytes: 11648
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#define INF 1e9
#define ALL(v) v.begin(), v.end()
#define REP(i, n) for(int i = 0; i < n; i++)
#define max(v) *max_element(v.begin(), v.end())
#define min(v) *min_element(v.begin(), v.end())
using namespace std;
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; }
const int MOD=1000000007;

void add(int &a, int b){
  a+=b;
  if(a >= MOD)
    a -=MOD;
}
int main(void){
  int h, w;
  vector<string> a;
  int dp[1100][1100]={0};
  cin>>h>>w;
  a.resize(h);
  REP(i, h){
    cin>>a[i];
  }
  dp[0][0]=1;
  REP(i, h){
    REP(j, w){
      if(i+1 < h && a[i+1][j]=='.')
        add(dp[i+1][j], dp[i][j]);
      if(j+1 < w && a[i][j+1]=='.')
        add(dp[i][j+1], dp[i][j]);
    }
  }
  cout<<dp[h-1][w-1]<<endl;
  return 0;
}

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

int mod = 1000000007;
int64_t large = 9223372036854775807;
double PI = 3.141592653589793;

int main()
{
    int64_t A;
    long double B;
    cin >> A >> B;
    cout << (int64_t)(A * B * 100) / 100;
}

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

int main(){
  int a,b;
  cin>>a>>b;
  if( a<= 0 && 0<= b ){
    cout<<"Zero"<<endl;
  }else{
    int cnt=0;
    
    if(b<0)a+=b;
    
    if(a<0 && (-a)%2==0 ){
      cout<<"Negative"<<endl;
    }else{
      cout<<"Positive"<<endl;
    }
    
  }
  return 0;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;

public class Main implements Runnable {

    private static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        new Thread(null, new Main(), "", 128 * 1024 * 1024).start();
    }

    public void run() {
        int n = sc.nextInt();
        String[] list = new String[n];
        for (int i = 0; i < n; i++) {
            list[i] = sc.next();
        }
        if (new HashSet<>(Arrays.asList(list)).size() != n) {
            System.out.println("No");
            return;
        }
        for (int i = 1; i < n; i++) {
            if (list[i - 1].charAt(list[i - 1].length()-1) != list[i].charAt(0)) {
                System.out.println("No");
                return;
            }
        }
        System.out.println("Yes");
    }
}

Measured memory_bytes: 24660
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define ld long double
#define pb push_back
 
#define mo 1000000007
#define inf 1e18
#define rep(i, s, n) for (ll i = s; i < n; i = i + 1)
#define rrep(i,s,n) for(ll i=s;i>=n;i--)
#define adiii \                               
  ios_base::sync_with_stdio(false); \                                      
  cin.tie(NULL);  \
  cout.tie(NULL);									
 
ll mod(ll n) { return (n % (ll)mo + (ll)mo)%(ll)mo;}
ll gcd(ll a,ll b) {if (b == 0) return a;return gcd(b, a % b);}

int main(){
	adiii
	ll n,k;cin>>n>>k;
	vector <bool> mark(n+1);
	rep(i,0,k){
		ll d;cin>>d;
		ll x;
		rep(i,0,d) cin>>x,mark[x] = true;
	}
	ll cnt=0;
	rep(i,1,n+1){
		if(mark[i] == false) cnt++;
		
	}
	
	cout<<cnt<<endl;



}


Measured memory_bytes: 3652
#include<iostream>
#include<stdio.h>
using namespace std;
int main(){
  double r,s,l;
  cin >> r ;
  s = r*r*3.141592653589;
  l = 2*r*3.141592653589;
  printf("%.7lf\n",s);
  printf("%.7lf\n",l);
  return 0;
}


Measured memory_bytes: 3188
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
#define N 110
int a[N];
int main()
{
    int i,j,k,n,m;
    scanf("%d%d",&n,&m);
    for(i=0;i<n;i++)
        scanf("%d",&a[i]);
    sort(a,a+n);
    k=0;
    for(i=0;i<n;i++)
    if(a[i]<=m)
    {
        if(i==n-1)
        {
            if(k==n-1)
            {
                if(a[i]==m)
                {
                    m=m-a[i];
                    k++;
                }
            }
            else
            {
                m=m-a[i];
                k++;
            }
        }
        else
        {
            k++;
            m=m-a[i];
        }
    }
    printf("%d\n",k);
    return 0;
}


Measured memory_bytes: 128