akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <functional>
#include <algorithm>
#include <cmath>

using namespace std;

#define in(x) cin >> x
#define out(x) cout << x << endl

#define PI acos(-1)
#define pp push_back

#define Yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define No cout << "No" << endl
#define NO cout << "NO" << endl

#define vec2(type) vector<vector<type>>
#define vec3(type) vector<vector<vector<type>>>

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

template<typename T> void sort(vector<T> &ary){
	sort(ary.begin(), ary.end());
}

template<typename T> void rsort(vector<T> &ary){
	sort(ary.rbegin(), ary.rend());
}

void rstring(string &str){
	string temp = str;

	For(i, (int)str.size()){
		str[i] = temp[(str.size() - 1) - i];
	}
}

int main(){

	int n, k;
	int num;

	in(n);

	if(n == 2){
		No;
		return 0;
	}

	for(k = 1; k <= n; k++){
		if((long long)k * (k - 1) / 2 == n){
			break;
		}
		else if((long long)k * (k - 1) / 2 > n){
			No;
			return 0;
		}
	}

	Yes;

	out(k);
	for(int i = 1; i <= k; i++){
		cout << k - 1 << " ";
		num = 0;

		for(int j = 1; j <= i - 1; j++){
			num += k - j;
			cout << num - (k - i) << " ";
		}

		for(int j = i; j <= k - 1; j++){
			num++;
			cout << num << " ";
		}
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 1408
from collections import deque
import sys
readline = sys.stdin.readline
write = sys.stdout.write
def solve():
    N, K = map(int, readline().split())
    ES = [list(map(int, readline().split())) for i in range(K)]
    emp = {}
    sq = int(K**.5) + 1
    def root(x):
        if x == p[x]:
            return x
        p[x] = y = root(p[x])
        return y
    def unite(x, y):
        px = root(x); py = root(y)
        if px < py:
            p[py] = px
        else:
            p[px] = py
    que = deque()
    used = [0]*N
    lb = 0

    p = [0]*N
    for i in range(sq):
        s = set()
        for j in range(i*sq, min(i*sq+sq, K)):
            t, a, b = ES[j]
            if t == 3:
                continue
            e = (a, b)
            if emp.get(e, 0):
                s.add(e)
            emp[e] = 0

        p[:] = range(N)
        for (v, w), d in emp.items():
            if d == 1:
                unite(v, w)

        G0 = [[] for i in range(N)]
        emp0 = {}
        for a, b in s:
            pa = root(a); pb = root(b)
            if pa == pb:
                continue
            e = (pa, pb) if pa < pb else (pb, pa)
            if e in emp0:
                e1, e2 = emp0[e]
                e1[1] = e2[1] = e1[1] + 1
            else:
                e1 = [pb, 1]; e2 = [pa, 1]
                G0[pa].append(e1)
                G0[pb].append(e2)
                emp0[e] = e1, e2

        for j in range(i*sq, min(i*sq+sq, K)):
            t, a, b = ES[j]
            pa = root(a); pb = root(b)
            e = (pa, pb) if pa < pb else (pb, pa)
            if t == 1:
                emp[a, b] = 1
                if pa == pb:
                    continue
                if e not in emp0:
                    e1 = [pb, 1]; e2 = [pa, 1]
                    G0[pa].append(e1)
                    G0[pb].append(e2)
                    emp0[e] = e1, e2
                else:
                    e1, e2 = emp0[e]
                    e1[1] = e2[1] = e1[1] + 1
            elif t == 2:
                emp[a, b] = 0
                if pa == pb:
                    continue
                e1, e2 = emp0[e]
                e1[1] = e2[1] = e1[1] - 1
            elif t == 3:
                if pa == pb:
                    write("YES\n")
                else:
                    lb += 1
                    que.append(pa)
                    used[pa] = lb
                    while que:
                        v = que.popleft()
                        for w, d in G0[v]:
                            if d and used[w] != lb:
                                used[w] = lb
                                que.append(w)
                    if used[pb] == lb:
                        write("YES\n")
                    else:
                        write("NO\n")
solve()


Measured memory_bytes: 23064
#include<bits/stdc++.h>
using namespace std;
#define Mod(n) n % 1000000007
const int dx[8] = {1, 0, -1, 0, -1, 1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, -1, -1, 1};

bool isRound(string t)
{
    string r = t;
    bool is = true;
    for(int i = 0;i < (int)t.size();i++)
    {
        if(r[i] != t[t.size() - i - 1])
            is = false;
    }
    return is;
}

int main()
{
    string s;
    cin >> s;
    if(isRound(s))
    {
        string s1 = s.substr(0,(s.size() - 1)/2);
        string s2 = s.substr((s.size() + 3)/2 - 1);
        if(isRound(s1) and isRound(s2))
            cout << "Yes\n";
        else
            cout << "No\n";
    }
    else
    {
        cout << "No\n";
    }

}

Measured memory_bytes: 256
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
using namespace std;
typedef long long LL;
typedef pair<int,int> P;

int gcd(int a,int b){
	while(b){
		int t=a%b;
		a=b;
		b=t;
	}
	return a;
}
int main() {
	int a,b;
	while(cin >> a >> b){
		int g=gcd(a,b);
		cout << g << " " << a/g*b << endl;
	}
}

Measured memory_bytes: 1160
#include<iostream>
#include<string>
using namespace std;
string a, b, c;
int main(){
  cin >> a >> b >> c;
  cout << (char)toupper(*a.begin())
    << (char)toupper(*b.begin())
    << (char)toupper(*c.begin())
    << endl;
  return 0;
  }

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

bool f(string s) {
    for (int i = 0; i < s.size()/2; i++) {
        if (s[i] != s[s.size()-1-i])
            return false;
    }
    return true;
}

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

    string S; cin >> S;
    int N = S.size();
    if (f(S))
        if (f(S.substr(0, (N-1)/2)))
            if (f(S.substr((N+3)/2-1, N-(N+3)/2+1))) {
                cout << "Yes\n";
                return 0;
            }
    cout << "No\n";
}

Measured memory_bytes: 256
/*
verified on 2020/3/1
http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=4221855
*/

#include <iostream>
#include <vector>

using namespace std;

using ll = long long;

/* snippet starts */

#include <limits>

// ベルマンフォード法でstartから各点までの最短距離を計算する O(MN)
// 負のループとつながっている部分はd[i] = -INFとなる
template<typename dist_t>
class BellmanFord {
    
    struct edge {
        int from, to;
        dist_t dist;
    };

    int n; // 頂点数

    vector<edge> E;

public:

    static const dist_t INF;

    BellmanFord(int _n) : n(_n) {}

    BellmanFord(int _n, vector<edge> &_E) : n(_n), E(_E.begin(), _E.end()) {}

    inline void add_edge(int from, int to, dist_t dist=1) {
        E.push_back(edge{from, to, dist});
    }

    struct result {
        bool negloop = false; // 負のループがあるかどうか

        result(int _n, int k) : n(_n), d(new dist_t[(size_t)_n]) {
            fill(d, d+n, INF); 
            d[k] = 0;
        }
        auto &operator[](int i) { return d[i]; } 
        auto begin() { return d; }
        auto end()   { return d + n; }
        operator dist_t*() { return d; } // dist_t* へのキャスト

        bool unreachable(int i) { return d[i] == INF; }  // 視点から到達不可能かどうか
        bool in_negloop(int i)  { return d[i] == -INF; } // 負のループに入っているかどうか
    private:
        const int n;
        dist_t *d;
    };

    inline result operator()(int start) {
        result d(n, start);

        for (int i = 1; i < n; i++) {
            for (auto &e:E) {
                if (d[e.from] == INF) continue;
                if (d[e.to] > d[e.from] + e.dist) {
                    d[e.to] = d[e.from] + e.dist;
                    if (i == n - 1) d.negloop = true;
                }
            }
        }

        for (int i = 0; i < n; i++) {
            for (auto &e:E) {
                if (d[e.from] == INF) continue;
                if (d[e.to] > d[e.from] + e.dist) {
                    d[e.to] = -INF;
                } else if (d[e.from] == -INF)
                    d[e.to] = -INF;
            }
        }

        return d;
    }

    auto &operator[](int i) { return E[(size_t)i]; } 
    auto begin() { return E.begin(); }
    auto end()   { return E.end(); }
};


template<typename dist_t>
const dist_t BellmanFord<dist_t>::INF = numeric_limits<dist_t>::max();

/* Constructers
 *
 * BellmanFord(n) 
 * BellmanFord(n, E)
 */

/* snippet ends */

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

    BellmanFord<ll> bf(n);
    for (int i=0, u, v, d; i<m; i++) {
        cin >> u >> v >> d;
        bf.add_edge(u, v, (ll)d);
    }
    auto res = bf(r);

    if (res.negloop) cout << "NEGATIVE CYCLE" << '\n';
    else for (auto &ri:res) cout << (ri < BellmanFord<ll>::INF ? to_string(ri) : "INF") << '\n';

    return 0;
}


Measured memory_bytes: 3284
import bisect
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7



N = int(sys.stdin.readline())
L = list(map(int, sys.stdin.readline().split()))

L .sort()

a = sum(L[::2])
print(a)


Measured memory_bytes: 13584
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep2(i,a,b) for (int i = a; (i)<=(b);i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;

int main(){
  int n;
  scanf("%d",&n);
  int l = 3;
  vector<vector<int>> a(n,vector<int>(l,0));
  rep(i,n){
  	rep(j,l){
  		int b;
  		scanf("%d",&b);
  		a[i][j] = b;
  	}
  }
  vector<vector<int>> dp(n+1,vector<int>(l,0));
  rep(i,n){
    rep(j,l){//前の行動
      rep(k,l){//次の行動
        if (j == k) continue;
        dp[i+1][k] = max(dp[i+1][k],dp[i][j]+a[i][k]);
      }
    }
  }
  cout << *max_element(all(dp[n])) << endl;
  return 0;
}


Measured memory_bytes: 11136
program main
  implicit none
  integer(8) i, ans, frag, r, N
  integer(8),allocatable :: A(:)
  
  read(*, *) N
  allocate(A(N))
  read(*, *) (A(i), i = 1,N)
  call qsort(A)
  ans = 0
  r = N
  frag = 1
  do i = 1,N-1
    ans = ans + A(r)
    if (frag == 1) then
      frag = 0
      r = r-1
    else
      frag = 1
    end if
  end do

  write(*, *) ans
  
contains

recursive subroutine qsort(a)
implicit none
!integer(8),intent(in) :: n
integer(8),intent(inout) :: a(:)
integer(8)::i,j,toobig,toosmall,pv,n
n = size(a)
i = 1
j = n
pv = a((i+j)/2)
do
   do
     if (a(i) < pv) then
       i = i+1
     else
       exit
     end if
   end do
   do
     if(a(j) > pv) then
       j = j-1
     else
       exit
     end if
   end do
   if (i>=j) then
     exit
   else
     toobig = a(j)
     toosmall = a(i)
     a(i) = toobig
     a(j) = toosmall
     i = i+1
     j = j-1
   end if
 end do
 if (i > 2) then
   call qsort(a(1:i-1))
 end if
 if (j < n-1) then
   call qsort(a(j+1:n))
 end if
end subroutine qsort
end program main



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

#define rep(l, r) for (int i = (l); i < (r); i++)

typedef long long ll;
 
using namespace std;

int calc(int n) {
    int sum = 0;
    while (0 < n) {
        sum += n % 10;
        n /= 10;
    }

    return sum;
}

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

    int fx = calc(n);

    cout << (n % fx == 0 ? "Yes" : "No") << endl;
}

int main() {
    solve();

    return 0;
}


Measured memory_bytes: 256
x, y = map(int, input().split())

from operator import mul
from functools import reduce

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod


mod = 10**9+7 #出力の制限
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル

if (x+y) % 3 != 0:
    ans = 0

else:
    a = (x + y)//3
    b = x-a

    if x-a <0 or y-a <0:
        ans = 0
    else:
        mod = 10**9+7 #出力の制限
        N = a+b
        g1 = [1, 1] # 元テーブル
        g2 = [1, 1] #逆元テーブル
        inverse = [0, 1] #逆元テーブル計算用テーブル

        for i in range( 2, N + 1 ):
            g1.append( ( g1[-1] * i ) % mod )
            inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
            g2.append( (g2[-1] * inverse[-1]) % mod )

        ans = cmb(a, b, mod)

print(int(ans))


Measured memory_bytes: 127688
#include <iostream>
#include <string>
#include <vector>

using namespace std;
int main() {
    string num1, num2;
    cin >>num1 >>num2;
    int size1 = num1.size();
    int size2 = num2.size();
    if (size1 > size2 ) {
         cout << "GREATER" <<endl;
         return 0;
    }else if (size1 < size2) {
         cout <<"LESS"<<endl;
         return 0;
    }
    int i = 0;
    while (i < size1) {
        if (num1[i] == num2[i]) {
            i++;
        } else if (num1[i] - '0' > num2[i] - '0') {
            cout << "GREATER" <<endl;
            return 0;
        } else if (num1[i] - '0' < num2[i] - '0') {
             cout <<"LESS"<<endl;
         return 0;
        }
    }
    cout <<"EQUAL"<<endl;
    return 0;

}


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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x, y) CPP_CAT_I(x, y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x, y) x##y

#define ASSERT(expr...) assert((expr))

using i8 = int8_t;
using u8 = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;
// }}}

constexpr i64 INF = 1'010'000'000'000'000'017LL;

constexpr i64 MOD = 1'000'000'007LL;

constexpr f64 EPS = 1e-12;

constexpr f64 PI = 3.14159265358979323846;

#define M5 100007
#define M9 1000000000

// util {{{
#define FOR(i, start, end) for (i64 i = (start), CPP_CAT(i, xxxx_end) = (end); i < CPP_CAT(i, xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)

#define ALL(f, c, ...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ##__VA_ARGS__); })(c))
#define ll long long int
#define VI vector<int>
template <typename C>
i64 SIZE(const C &c)
{
    return static_cast<i64>(c.size());
}

template <typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }

template <typename T, typename U, typename Comp = less<>>
bool chmax(T &xmax, const U &x, Comp comp = {})
{
    if (comp(xmax, x))
    {
        xmax = x;
        return true;
    }
    return false;
}

template <typename T, typename U, typename Comp = less<>>
bool chmin(T &xmin, const U &x, Comp comp = {})
{
    if (comp(x, xmin))
    {
        xmin = x;
        return true;
    }
    return false;
}
// }}}

// init {{{
struct ProconInit
{
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit()
    {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if (AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;
// }}}

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

bool isOK(int mid, double key)
{
}

int binary_search(double key)
{
    int left = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
    int right = 2000000000;
    /* どんな二分探索でもここの書き方を変えずにできる！ */
    while (right - left > 1)
    {
        int mid = left + (right - left) / 2;

        if (isOK(mid, key))
            right = mid;
        else
            left = mid;
    }

    /* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている */
    return right;
}

bool isKaibun(string st)
{
    bool ans = true;
    int n = st.length();
    REP(i, n / 2)
    {
        if (st[i] != st[n - i - 1])
        {
            return false;
        }
    }
    return true;
}

int toInt(char a)
{
    return a - '0';
}

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

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

void solve()
{
    string S;
    cin >> S;
    if (S == "RRR")
    {
        cout << 3;
    }
    else if (S == "RRS" || S == "SRR")
    {
        cout << 2;
    }
    else if (S == "SSS")
    {
        cout << 0;
    }
    else
    {
        cout << 1;
    }
}

signed main()
{

    solve();

    return 0;
}


Measured memory_bytes: 3608
import fractions
import math

def trial_division(n):
    a = [1]
    for i in range(2,int(math.sqrt(n)) + 1):
        while n % i == 0:
            n //= i
            a.append(i)
    a.append(n)
    return a


A, B = map(int, input().split())
max_n = fractions.gcd(A,B)

ans = set(trial_division(max_n))
print(len(ans))

Measured memory_bytes: 66480
//#pragma GCC optimize "trapv"
#include<bits/stdc++.h>
#define  all(v)            v.begin(), v.end()
#define  sz(x)             (int)x.size()
#define  debug(x)          cout << #x << ':' << x << endl;
#define  rep(i,n)          for(int i = 0; i <  n ; i++)
#define  reps(i,n)         for(int i = 1; i <= n ; i++)
#define  make_unique(v)    sort(all(v));v.erase(unique(all(v)), v.end());
#define  REMOVE(v,a)       v.erase(remove(v.begin(),v.end(), a), v.end());
#define  pb                push_back
#define  mp                make_pair
#define  endl              '\n'
#define  fi                first
#define  se                second
#define  ajs(a)            (a<0)?(-1*a):a

using namespace std;
typedef long long          ll;
typedef vector<long long>  vll;
typedef pair<ll,ll>        pll;
typedef vector<int>        vi;
const ll MOD = 1e9+7;
const int dx4[4] = {0, 1, 0, -1};
const int dy4[4] = {-1, 0, 1, 0};
const int dx8[8] = { -1, -1, -1, 0, 1, 1, 1, 0};
const int dy8[8] = { -1, 0, 1, 1, 1, 0, -1, -1};
bool cmp(int X, int Y) {return X > Y;}

ll gcd(ll a, ll b) {return !b ? a : gcd(b, a % b);}
ll lcm(ll a, ll b) {return (a / gcd(a, b)) * b;}
ll modpow(ll a, ll b, ll m=MOD){a %= m; ll res = 1; while (b) {if (b & 1)res = (res * a) % m; a = (a * a) % m; b >>= 1;} return res;}
ll bpow(ll a, ll b){if(b<0){return 0;}ll res = 1; while (b) {if (b & 1)res = res * a; a = a * a; b >>= 1;} return res;}

const int N = 1e6+5;
vi adj[N];
ll present[N];


int main(){ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll n;cin>>n;
ll a[n];
rep(i,n){cin>>a[i];}

sort(a,a+n);
map<ll,ll>cnt;
rep(i,n){cnt[a[i]]++;}
for(ll i = 0; i<n-1 ; i++){
	for(ll j = a[i]*2; j<=a[n-1]; j=j+a[i]){
		present[j]=1;
		
		}
	
	
	}
ll ans = 0;
for(ll i = 0; i<n; i++){
	if(cnt[a[i]] == 1){
		if(present[a[i]] == 0){
			ans++;
			}
		}
	
	
}
cout<<ans;	
	


}


Measured memory_bytes: 47768
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
 
using namespace std;
typedef long long ll;

int Query[200001][3];

int main()
{
	char S[100001];
	int Q;
	
	scanf("%s", S);
	scanf("%d", &Q);
	
	for(int i = 0; i < Q; i++){
		scanf("%d", &Query[i][0]);
		
		if(Query[i][0] == 2){
			scanf("%d", &Query[i][1]);
		  char c[256];
			scanf("%s", c);
			Query[i][2] = (int)c[0];
		}
	}
	
	int len = strlen(S);
	string str = S;
	
	int mirror = 0;
	
	for(int i = 0; i < Q; i++){
		
		if(Query[i][0] == 1){
			mirror ++;
		}else{
			if((Query[i][1] + mirror) % 2 == 1){
				len++;
				str.insert(str.begin(), ((char)Query[i][2]));
			}else{
				len++;
				str += (char)Query[i][2];
			}
		}
	}
	
	if(mirror % 2 == 1){
		for(int j = 0; j < (len)/2; j++){
			char temp = str[len - j-1];
			str[len - j-1] = str[j];
			str[j] = temp;
		}
	}
	
	printf("%s\n", str.c_str());
	
	return 0;
}

Measured memory_bytes: 3384
n = gets.chomp.to_i
arr = gets.chomp.split(" ").map(&:to_i)

dict = {}
arr.each do |num|
  if dict[num].nil?
    dict[num] = 1
  else
    dict[num] += 1
  end
end

count = 0
dict.each do |h|
  count += h[1] - h[0] if h[0] < h[1]
  count += h[1] if h[0] > h[1]
end

puts count

Measured memory_bytes: 18180
#include <iostream>

int main()
{
	int A;
	std::string str;

	std::cin >> A;
	std::cin >> str;

	int C = 0; 
	int i = 0;
	while ((i = str.find("ABC", i)) >= 0) {
		C = C + 1;
		i = i + 1;
	}

	std::cout << C;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Numerics;

namespace AtCoder
{
    class Program
    {
        static int LoadInt() { return int.Parse(Console.ReadLine()); }
        static int[] LoadIntArray() { return Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); }
        static long[] LoadLongArray() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); }

        static void Main(string[] args)
        {
            var vals = LoadIntArray();
            var M = vals[0];
            var D = vals[1];
            var cnt = 0;
            foreach(var i in Enumerable.Range(1, M))
            {
                foreach(var j in Enumerable.Range(1, D))
                {
                    var d1 = j % 10;
                    var d2 = j / 10;
                    if (d1 <= 1 || d2 <= 1) continue;
                    if(i == d1*d2)
                    {
                        cnt++;
                    }
                }
            }
            Console.WriteLine(cnt);
        }

    }

}


Measured memory_bytes: 13396
N, *C = open(0).read().split()
N = int(N)
a = b = 0
for i in range(0, len(C), 2):
    c1 = C[i]
    c2 = C[i+1]
    if c1 == c2:
        a += 1
        b += 1
    elif c1 > c2:
        a += 3
    else:
        b += 3
print(a, b)


Measured memory_bytes: 5632
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;

void PRINT(string &S, int a, int b){
  cout << S.substr(a, b - a + 1) << endl;
}

void REVERSE(string &S, int a, int b){
  string T;
  T = S.substr(a, b - a + 1);
  reverse(T.begin(), T.end());
  S = S.substr(0, a) + T + S.substr(b + 1, S.size() - b - 1);
}

void REPLACE(string &S, int a, int b, string p){
  S = S.substr(0, a) + p + S.substr(b + 1, S.size() - b);
}


int main(){
  string str;
  cin >> str;
  int q;
  cin >> q;
  string od;
  int a, b;
  string p;
  for(int i = 0; i < q; i++){
    cin >>od;
    if(od == "print"){
      cin >> a >> b;
      PRINT(str, a, b);
    }
    else if(od == "reverse"){
      cin >> a >> b;
      REVERSE(str, a, b);  
    }
    else if(od == "replace"){
      cin >> a >> b >> p;
      REPLACE(str, a, b, p);      
    }
  }  
}



Measured memory_bytes: 3204
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class Main {
	private static List<Node> T = new ArrayList<Main.Node>();

	private static class Node {
		public int id;
		public int parent = -1;
		public int depth = 0;
		public List<Integer> children;

		@Override
		public String toString() {
			String type = "";
			if (parent == -1) {
				type = "root";
			}
			else if (children.size() == 0) {
				type = "leaf";
			}
			else {
				type = "internal node";
			}

			StringBuilder childrenStr = new StringBuilder();
			for (int id : children) {
				if (childrenStr.length() > 0) {
					childrenStr.append(", ");
				}
				childrenStr.append(id);
			}
			
			StringBuilder sb = new StringBuilder();
			sb.append("node ").append(id);
			sb.append(": parent = ").append(parent);
			sb.append(", depth = ").append(depth);
			sb.append(", ").append(type);
			sb.append(", [").append(childrenStr.toString()).append("]");
			return sb.toString();
		}
	}

	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int N = Integer.parseInt(br.readLine());
		for (int i = 0; i < N; i++) {
			createTree(br.readLine());
		}
		Collections.sort(T, new Comparator<Node>() {
			@Override
			public int compare(Node o1, Node o2) {
				return o1.id - o2.id;
			}
		});

		updateTree();

		for (Node n : T) {
			System.out.println(n);
		}

		if (br != null) {
			br.close();
			br = null;
		}
	}

	private static void createTree(String line) {
		String[] u = line.split(" ");
		int id = Integer.parseInt(u[0]);
		int k = Integer.parseInt(u[1]);
		List<Integer> c = new ArrayList<Integer>();
		for (int j = 0; j < k; j++) {
			c.add(Integer.parseInt(u[2 + j]));
		}

		Node node = new Node();
		node.id = id;
		node.children = c;
		T.add(node);
	}

	private static void updateTree() {
		for (Node node : T) {
			for (int id : node.children) {
				updateChildren(id, node.id);
			}
		}
	}

	private static void updateChildren(int cid, int pid) {
		Node key = new Node();
		key.id = cid;
		int idx = Collections.binarySearch(T, key, new Comparator<Node>() {
			@Override
			public int compare(Node o1, Node o2) {
				return o1.id - o2.id;
			}
		});
		Node node = T.get(idx);
		node.parent = pid;
		node.depth++;
		for (int id : node.children) {
			updateChildren(id, cid);
		}
	}
}

Measured memory_bytes: 127620
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000007
#define fi first
#define se second
#define pb push_back
ll power(ll x,ll y,ll p)
{
    ll res = 1;      // Initialize result

    x = x % p;  // Update x if it is more than or
                // equal to p

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res*x) % p;

        // y must be even now
        y = y>>1; // y = y/2
        x = (x*x) % p;
    }
    return res;
}
int main(){
  char a;
  cin >> a;
  cout << char(int(a) + 1) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,n) for(long long i=0;i<n;++i)
#define REPP(i,m,n) for(long long i=m;i<n;++i)
#define rep(i,n) for(long long i = n-1;i>=0;--i)
#define repp(i,n,m) for(long long i = n-1; i >= m; --i)
#define ALL(N) (N.begin(),N.end())
#define de cout << "line : " << __LINE__ << " debug" << endl;
#define pb push_back
#define pq priority_queue
#define Dcout(N) cout << setprecision(20) << N << endl
constexpr int INF = 2147483647;
constexpr long long INFF = 9223372036854775807;

//これは'a'を0に変える
//'a ~ z'を 0 ~ 26に
int ctoi(const char c){
    if('a' <= c && c <= 'z') return (c - 'a');
    else return -1;
}

signed main() {
    cin.tie(0);
	ios::sync_with_stdio(false);
    int H,W;cin >> H >> W;
    char C[H][W];REP(i,H) REP(j,W) cin >> C[i][j];
    int A[110] = {};
    REP(i,H) REP(j,W){
        int cnt = ctoi(C[i][j]);
        A[cnt]++;
    }
    vector<int> V,X;
    REP(i,110) if(A[i] != 0){
        V.pb(A[i]);
    }
    REP(i,V.size()){
        while(V[i] > 4){
            V.pb(4);
            V[i] -= 4;
        }
    }
    sort ALL(V);
    if(H % 2 == 0 && W % 2 == 0){
        REP(i,H/2*W/2) X.pb(4);
    }
    else if(H % 2 == 1 && W % 2 == 1){
        X.pb(1);
        REP(i,H/2) X.pb(2);
        REP(i,W/2) X.pb(2);
        int cnt = (H+1)/2*(W+1)/2 - 1 - H/2 - W/2;
        if(cnt > 0) REP(i,cnt) X.pb(4);
    }
    else{
        if(H % 2 == 1){
            REP(i,W/2) X.pb(2);
            int cnt = (H+1)/2*((W+1)/2) - W/2;
            if(cnt > 0) REP(i,cnt) X.pb(4);
        }
        else{
            REP(i,H/2) X.pb(2);
            int cnt = (H+1)/2*((W+1)/2) - H/2;
            if(cnt > 0) REP(i,cnt) X.pb(4);
        }
    }

    REP(i,X.size()){
        REP(j,V.size()){
            if(X[i] == 1){if(V[j] == 1 || V[j] == 3){
                V[j]--;break;
            }}
            else if(V[j] % 2 == 0 && V[j] - X[i] >= 0 && X[i] % 2 == 0){
                V[j] -= X[i];break;
            }
            else if(j == V.size() - 1){
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
}

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

#define nax 100009
#define FOR(i,n,m) for(int i =(n);i<(m);i++)
#define REP(i,n) FOR(i,0,n)
#define pb push_back

typedef long long ll;

int main(){
	int w,n;
	ll dp[nax],v[nax],we[nax];

	cin>>n>>w;
	REP(i,n){
		cin>>we[i]>>v[i];
	}

	//dp(i):maximo valor que se puede obtener en este peso
	REP(i,nax) dp[i] = 0;

	ll m = 0;
	REP(i,n){
		for(int j = w;j>=0;j--){
			if(j-we[i]<0) continue;
			dp[j] = max(dp[j],dp[j-we[i]]+v[i]);
			m = max(m,dp[j]);
		}
	}

	cout<<m<<endl;

	return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N;
    cin >>N;
    vector<int>vec(N);
    if(N==1){
        cout <<"Yes"<<endl;
        return 0;
    }
    for(int i=0;i<N;i++){
        cin >> vec.at(i);
    }
    long long stand=vec.at(0);
    
    for(int i=1;i<=N-1;i++){
        if(stand==vec.at(i)){
            continue;
        }
        if(stand<=vec.at(i)-1){
            stand =vec.at(i)-1;
            continue;
        }
        else {
            cout <<"No"<<endl;
            return 0;
        }
    }
    cout <<"Yes"<<endl;
}

Measured memory_bytes: 3772
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n=0;
	int m=0;
	string s;
	cin>>n>>m;
	if(n==m)
	{
		s="Yes";
	}
	else
	{
		s="No";
	}
	cout<<s<<endl;
	return 0;
}

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

int main(){
	int N;
	cin >> N;
	int A[N];
	for(int a = 0; a < N; a++)
		cin >> A[a];
	int x = 0;
	for(int a : A)
		x ^= a;
	for(int a : A)
		cout << (x ^ a) << " ";
	cout << endl;
}

Measured memory_bytes: 4308
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();// ボタンの数
        int[] button = new int[n];

        for (int i = 0; i < n; i++) {
            button[i] = sc.nextInt();
        }

        int count = 0;
        int nextButtonIndex = 0;
        while (n > 0) {
            count++;// ボタンをおす
            n--;
            if (button[nextButtonIndex] == 2) break;

            // 次のボタンへ遷移
            nextButtonIndex = button[nextButtonIndex]-1;
        }

        if (n == 0 && button[nextButtonIndex] != 2) count = -1;

        System.out.println(count);
    }
}


Measured memory_bytes: 51220
def larger(x, y):
	if x > y:
		return x
	return y

N = int(input())
A = list(map(int, input().split()))
dpp = [A[0]]
dpn = [-A[0]]
for i in range(1, N-1):
	nextdpp = larger(dpp[-1]+A[i], dpn[-1]-A[i])
	nextdpn = larger(dpp[-1]-A[i], dpn[-1]+A[i])
	dpp.append(nextdpp)
	dpn.append(nextdpn)
print(larger(dpp[-1]+A[N-1], dpn[-1]-A[N-1]))

Measured memory_bytes: 72608
#pragma GCC optimize("O2,Ofast,inline,unroll-all-loops,-ffast-math")
using namespace std;
#include <bits/stdc++.h>
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb(X) push_back(X)
#define x first
#define y second
#define all(x) (x).begin(), (x).end()
#define INIT std::ios::sync_with_stdio(false);std::cin.tie(0);
typedef long long ll;
typedef vector<int> VI;
typedef vector<long long> VL;
typedef pair<int, int> pii;
//ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}


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

int main() {
	INIT
	int n;
	cin >> n;
	if (n < 600) {
		cout << "8";
	} else if (n < 800) {
		cout << "7";
	} else if (n < 1000) {
		cout << "6";
	} else if (n < 1200) {
		cout << "5";
	} else if (n < 1400) {
		cout << "4";
	}  else if (n < 1600) {
		cout << "3";
	}  else if (n < 1800) {
		cout << "2";
	}  else {
		cout << "1";
	} 

	return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
//Author: Ezio Sam
/* Shorthands */
#define ll long long
#define pb push_back 
#define mp make_pair
#define sp ": "
#define cs "Case "
#define fi first
#define sn second 
#define po(x) x*x
/* STL */
#define vi vector<int>v
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mem(a,n) memset(a, n, sizeof(a));
#define all(x) x.begin(),x.end()
#define sz(x)  (int)x.size()
#define mx(v)  *max_element(v.begin(),v.end())
#define mxa(a) *max_element(a, a.size())
#define r(a) reverse(a.begin(),a.end())
/* loops */
#define fr(i,n)   for(__typeof(n) i=0;i<(n);i++)
#define fn(i,n)   for(__typeof(n)i=1;i<=(n);i++)
#define fa(i,a,n) for(__typeof(a)i=(a);i<=(b);i++)
/*Special*/
#define Ezio ios::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
#define db(something)   cerr<<#something<<" - "<<something<<"\n";         
int main()
{
  
   Ezio
   /*Variables*/
   /*Code*/
   string s;
   cin>>s;
   cout<<((s[4]==s[5] and s[3]==s[2])?"Yes":"No")<<endl;
   return 0;
}
    

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

namespace CSharpSample01
{


    class Program
    {

        const int INF = 1000000000;

        static void Show(int N, int[] d)
        {
            int ans = 0;
            for (int i = 0; i < N; i++) ans += d[i];
            Console.WriteLine(ans);
        }


        static void Prim(int N, int[,] g)
        {
            bool[] visit = new bool[N];

            int[] d = new int[N];
            for (int i = 0; i < N; i++) d[i] = INF;
            d[0] = 0;

            while (true)
            {
                int mincost = INF;
                int from = -1;

                for(int v = 0; v < N; v++)
                {
                    if(!visit[v] && d[v] < mincost)
                    {
                        mincost = d[v];
                        from = v;
                    }
                }

                if (from == -1) break;
                visit[from] = true;

                for (int to = 0; to < N; to++)
                {
                    if(!visit[to] && g[from, to] != -1 && g[from, to] < d[to])
                    {
                        d[to] = g[from, to];
                    }
                }

            }

            Show(N, d);
        }
        

        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());

            int[,] g = new int[N, N];

            for (int i = 0; i < N; i++)
            {
                string[] input = Console.ReadLine().Split(' ');
                for(int j = 0; j < N; j++)
                {
                    g[i, j] = int.Parse(input[j + 1]);
                }
            }            

            Prim(N, g);
        }
    }
}


Measured memory_bytes: 17992
def main():
    n = int(input())
    h = list(map(int, input().split()))
    for i in range(n-1):
        if h[i] < h[i+1]:
            h[i+1] -= 1
        elif h[i] > h[i+1]:
            print('No')
            exit()

    print('Yes')


if __name__ == "__main__":
    main()


Measured memory_bytes: 14224
#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 main(){
  int a,b,c;
  cin>>a>>b>>c;
  int ans;
  if(a==b)ans=c;
  if(b==c)ans=a;
  if(a==c)ans=b;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;

int main(){
  int n, a;
  while(cin>>n>>a){
    if(n%500<=a)
      cout<<"Yes"<<endl;
    else
      cout<<"No"<<endl;
  }
  return 0;
}




Measured memory_bytes: 256
import java.util.*;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		int[] A = new int[N];
		for(int i = 0; i < K; i++){
			int d = sc.nextInt();
			for(int j = 0; j < d; j++){
				A[sc.nextInt()-1]++;
			}
		}
		int count = 0;
		for(int r : A){
			if(r == 0){
				count++;
			}
		}
		System.out.print(count);
	}
}

Measured memory_bytes: 46132
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define BIG 1000000010
#define EPS 1e-9
#define first fst
#define second scd

#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long


signed main(){
  int a,b,t;
  cin>>a>>b>>t;
  cout<<((t/a)*b)<<endl;

  return 0;
}




Measured memory_bytes: 256
import java.io.PrintWriter;
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    PrintWriter pw = new PrintWriter(System.out);

    while (true) {
        int n = sc.nextInt();

        if (n == 0) break;

        int[] s = new int[n];
        for (int i = 0; i < n; i++) {
            s[i] = sc.nextInt();
        }

        double avg = IntStream.of(s).average().getAsDouble();
        double total = IntStream.of(s).mapToDouble(i -> Math.pow(i - avg, 2)).sum();
        double a = Math.sqrt(total / n);

        pw.println(a);
    }

    pw.flush();
  }
}


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

int64_t cub(int x)
{
	return 1ll * x * x * x;
}

int main()
{
	int N, K;
	cin >> N >> K;
	int64_t n = 0;
	if (K % 2 == 0) {
		int x = 0, y = 0;
		int k = K / 2;
		for (int i = k; i <= N; i += k) {
			if (i % K == 0)
				++x;
			if (i % K == k)
				++y;
		}
		cout << cub(x) + cub(y) << endl;
	}
	else {
		int x = N / K;
		cout << cub(x) << endl;
	}
	return 0;
}

Measured memory_bytes: 256
package main

import (
        "fmt"
)

func solution(x int) int {
        m := 100
        i := 0
        for m < x {
                t := float64(m) * 0.01
                m += int(t)
                i++
        }
        return i
}

func main() {
        var x int
        fmt.Scan(&x)
        fmt.Println(solution(x))
}

Measured memory_bytes: 1756
//** aman**/
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define dl          double
#define hell        1000000007
#define endl        '\n'
#define rep(i,a,b) for(int i=a;i<b;i++)
#define lb lower_bound
#define ub upper_bound
#define bs          binary_search
#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
int main(){
	int n;cin>>n;
	string a,b,c;int cnt=0;cin>>a>>b>>c;
	for(int i=0;i<n;i++){
		set<char> s;
		s.insert(a[i]);
		s.insert(b[i]);
		s.insert(c[i]);
		cnt+=s.size()-1;
	}
	cout<<cnt<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, n) for(int i = 1; i <= (int)(n); i++)
const long long INF = 1LL << 60;
const double PI=3.14159265358979323846;

int n,k;
long long T[100000];
int check(int P){
    int i=0;
    for(int j=0;j<k;j++){
        long long s=0;
        while(s+T[i] <= P){
            s += T[i];
            i++;
            if(i == n)return n;
        }
    }
    return i;
}

int search(){
    long long l = 0;
    long long r = 1000000000;
    while(l+1 < r){
        long long mid=(l+r)/2;
        int v = check(mid);
        if(v >= n)r=mid;
        else l=mid;
    }
    return r;
}



int main() 
{
    cin >> n >> k;
    rep(i,n){
        cin >> T[i];
    }
    long long ans = search();
    cout << ans << endl;
}


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

#define EB emplace_back
#define int long long
#define F first
#define S second
#define N 100005
#define ALL(x) x.begin(),x.end()
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)


using namespace std;


int32_t main()
{
    IOS;

    int tt=1;
    //cin>>tt;
    while(tt--)
    {
        int n; cin>>n;
        int a = n/500;
        int ans = 0;
        ans = a * 1000;
        n -= a * 500;
        ans  += n/5 * 5;
        
cout<<ans;

		
		cout<<endl;
    }
    return 0;

}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#define LENGTH_MAX 31
#define PAIR_MAX 101

struct pair{
	char word[LENGTH_MAX];
	int page;
	struct pair *next;
};

struct pair *insert(struct pair *head, struct pair *p){
	int state;
	if(head == NULL){return p;}
	state = strcmp(head->word, p->word);
	if(state < 0 || state == 0 && head->page < p->page){
		head->next = insert(head->next, p);
		return head;
	}else{
		p->next = head;
		head = p;
		return head;
	}
}

void print_list(struct pair *p, char prev[]){
	if(p == NULL){
		putchar('\n');
		return;
	}
	if(strcmp(p->word, prev) != 0){
		if(strcmp(prev, "") != 0){
			putchar('\n');
		}
		printf("%s\n",p->word);
	}else{
		putchar(' ');
	}
	printf("%d",p->page);
	print_list(p->next, p->word);
}

int main(void){
	int i;
	struct pair arr[PAIR_MAX];
	struct pair *head = NULL;

	for(
		i = 0;
		scanf("%s%d", arr[i].word, &arr[i].page) != EOF;
		i++
	){
		arr[i].next = NULL;
		head = insert(head, &arr[i]);
	}

	print_list(head, "");

	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define watch(x) cout<<(#x)<<"="<<(x)<<'\n'
#define mset(d,val) memset(d,val,sizeof(d))
#define setp(x) cout<<fixed<<setprecision(x)
#define forn(i,a,b) for(int i=(a);i<(b);i++)
#define fore(i,a,b) for(int i=(a);i<=(b);i++)
#define pb push_back
#define F first
#define S second
#define pqueue priority_queue
#define fbo find_by_order
#define ook order_of_key
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef long double ld;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;
void amin(ll &a, ll b){ a=min(a,b); }
void amax(ll &a, ll b){ a=max(a,b); }
void YES(){cout<<"YES\n";} void NO(){cout<<"NO\n";}
void SD(int t=0){ cout<<"PASSED "<<t<<endl; }
const ll INF = ll(1e18);
const int MOD = 1e9+7;

ll add(ll a, ll b)
{
	a+=b; a%=MOD;
	if(a<0) a+=MOD;
	return a;
}
void radd(ll &a, ll b)
{
	a=add(a,b);
}
ll mult(ll a, ll b)
{
	if(a>MOD) a%=MOD;
	if(b>MOD) b%=MOD;
	ll ans=(a*b)%MOD;
	if(ans<0) ans+=MOD;
	return ans;
}
ll pw(ll a, ll b)
{
	ll r=1;
	while(b){
		if(b&1) r=mult(r,a);
		a=mult(a,a);
		b>>=1;
	}
	return r;
}
ll inverse(ll a)
{
	return pw(a,MOD-2);
}

const bool DEBUG = 0;
const int MAXN = 22;

int n;
bool a[MAXN][MAXN];
ll dp[MAXN][1<<MAXN];

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	cin>>n;
	forn(i,0,n) forn(j,0,n) cin>>a[i][j];
	
	for(int i=0;i<n;i++)
	{
		for(int mask=0;mask<(1<<n);mask++)
		{
			if(__builtin_popcount(mask)!=i+1) continue;
			for(int j=0;j<n;j++)
			{
				if(!a[i][j]) continue;
				if(i)
				{
					if(!(mask&(1<<j))) continue;
					radd(dp[i][mask], dp[i-1][mask^(1<<j)]);
				}
				else
				{
					if(mask==(1<<j)) dp[i][mask]++;
				}
			}
		}
	}
	
	cout<<dp[n-1][(1<<n)-1]<<'\n';
	
	return 0;
}


Measured memory_bytes: 167228
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
//問題文および制約はちゃんと確認しよう！
//サイズは10^5じゃなくて2×10^5とかかもしれないし、重要な制約・条件を見落としているかも
//とりあえずサンプルを読んでから解法を考えよう？
int main()
{
	string s;cin>>s;
	rep(i,s.size()){
		if(s[i]=='?') s[i]='D';
	}
	cout<<s<<endl;
}


Measured memory_bytes: 3756
import itertools

X, Y, Z, K = (int(i) for i in input().split())
A = [int(i) for i in input().split()] 
B = [int(i) for i in input().split()] 
C = [int(i) for i in input().split()] 

A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

D = [a+b for a,b in itertools.product(A[:K], B[:K])]
D.sort(reverse=True)

E = [c+d for c,d in itertools.product(C[:K], D[:K])]
E.sort(reverse=True)

for i in range(K):
    print(E[i])

Measured memory_bytes: 207592
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repeq(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define rep1(i,x,n) for(int (i)=(x);(i)<(int)(n);(i)++)
#define rep1eq(i,x,n) for(int (i)=(x);(i)<=(int)(n);(i)++)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
using namespace std;
using ll = long long;
using Int = long long;

const int MOD = 1000000007;
const ll INF = numeric_limits<ll>::max();
const int inf = 1e8;
//typedef pair<int,int> P;

//少数点表示
//cout << std::fixed << std::setprecision(14) <<double値

int main(){
    cin.tie( 0 ); ios::sync_with_stdio( false );
    ll a,b,c;
    cin >> a >> b >> c;
    if(a%2 == 0 || b%2 == 0 || c%2 == 0){
        cout << 0 << endl;
    }else{
        ll min_ = min({a*b,b*c,c*a});
        cout << min_ << endl;
    }
    return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define SORT(a) sort((a).begin(), (a).end())
#define RSORT(a) reverse((a).begin(), (a).end())
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(a) ((a).begin(), (a).end())
typedef long long ll;
// const long long INF = 1LL << 60;
const int INF = 1010101010;
using Graph = vector<vector<int>>;
const int MOD = 1000000007;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> b(n);
  vector<int> c(n);
  rep(i, n) cin >> a[i];
  rep(i, n) cin >> b[i];
  rep(i, n) cin >> c[i];
  ll ans = 0;
  SORT(a);
  SORT(b);
  SORT(c);
  for (int i = 0; i < n; i++) {
    ans += (lower_bound(a.begin(), a.end(), b.at(i)) - a.begin()) *
           (c.end() - upper_bound(c.begin(), c.end(), b.at(i)));
  }

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

Measured memory_bytes: 1536
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;
#define mp make_pair
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll MOD = (ll)1e9 + 7;
ll mult(ll x, ll y) {
	return (x * y) % MOD;
}

const int N = 200200;
int n;
char s[N];
int a[N];

int main()
{
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	scanf("%d %s", &n, s);
	for (int i = 1; i <= 2 * n; i++)
		a[i] = s[i - 1] == 'W' ? 0 : 1;
	for (int i = 0; i <= 2 * n; i++)
		a[i] ^= a[i + 1];
	ll x = 0;
	ll ans = 1;
//	for (int i = 0; i <= 2 * n; i++)
//		eprintf("%d", a[i]);
//	eprintf("\n");
	for (int i = 0; i < 2 * n; i++) {
		if (a[i]) {
			x++;
		} else {
			a[i + 1] ^= 1;
			ans = mult(ans, x);
			x--;
		}
	}
	if (x != 0) ans = 0;
	for (int i = 1; i <= n; i++)
		ans = mult(ans, i);
	printf("%lld\n", ans);

	return 0;
}


Measured memory_bytes: 1280