akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define rep2(i,n) for(int i = 1; i <= (n); ++i)
#define rrep2(i,n) for(int i = (n); i > 0; --i)
#define srep(i,s,n) for(int i = s; i < (n); ++i)
#define rsrep(i,s,n) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { int n = (__VA_ARGS__).size(); rep(i, n) printf("%d%s", (__VA_ARGS__)[i], i != n-1 ? " " : "\n"); }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;


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

    vint a(n);
    rep(i, n) cin >> a[i];

    int id;
    rep(i, n) if (a[i] == 1) id = i;

    int ans = (id + ((k-1) - 1)) / (k-1);
    int l = n-ans*(k-1)-1;
    ans += (l + ((k-1) - 1)) / (k-1);

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

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

int main()
{
	int n;
	int count = 0;
	char *s;
	scanf("%d", &n);
	s = (char *)malloc(sizeof(char) * n);
	scanf("%s", s);
	for(int i = 0; i < n; i++){
		if(s[i] == 'A'){
			if(s[i + 1] == 'B'){
				if(s[i + 2] == 'C'){
					count++;
				}
			}
		}
	}
	printf("%d\n", count);
	
	return 0;
}


Measured memory_bytes: 128
import sys
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt, ceil, floor
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
INF = float("inf")
sys.setrecursionlimit(10**7)

# 4近傍（右, 下, 左, 上）
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]


def inside(y: int, x: int, H: int, W: int) -> bool: return 0 <= y < H and 0 <= x < W


def main():
    N, A, B = list(map(int, input().split()))
    print(min(A * N, B))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3832
#include <iostream>

using namespace std;
using ll = long long;

int main() {
    ll X, Y;
    cin >> X >> Y;

    ll mx = Y/X;
    int ans = 0;
    while (mx > 0) {
        ans++;
        mx /= 2;
    }

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

Measured memory_bytes: 256
//B - Snake Toy 2017/07/15
#include <bits/stdc++.h>
using namespace std;

void i_sort(int *a,int b){
    for(int i=0;i<b;++i){
        int j=i-1;int tmp;
        while(j>=0){
            if(a[j]>a[j+1]){tmp=a[j];a[j]=a[j+1];a[j+1]=tmp;}
            --j;
        }
    }
}

int main(){
    int N,K; cin >> N >> K;
    int l[N];
    for(int i=0;i<N;++i) cin >> l[i];
    i_sort(l,N);
    int ans=0;
    for(int i=N-1;;--i){
        if(K!=0) ans+=l[i];
        else break;
        --K;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#pragma region RegionDefs
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include "boost/multi_array.hpp"
#define rep(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define reps(i,j,n) for(int i=(j),i##_len=(n);i<i##_len;++i)
#define repr(i,n) for(int i=(n);i>=0;--i)
#define all(x) begin(x),end(x)
using namespace std;
template<class T=int> using P  = pair<T, T>;
template<class T=int> using V  = vector<T>;
template<class T=int> using PQ = priority_queue<T>;
template<class T=int> using PQG = priority_queue<T, V<T>, greater<T>>;
typedef long long ll;
const int INF = 1e9;
const ll MOD = 1000000007LL;
void in() {}
template<class Head, class... Tail>
void in(Head&& head, Tail&&... tail)
{
    cin >> head;
    in(move(tail)...);
}
#define IN(...) ll __VA_ARGS__; in(__VA_ARGS__)
//時間が厳しいとき使う
#define INI(...) int __VA_ARGS__; in(__VA_ARGS__)
#define INS(T, ...) T __VA_ARGS__; in(__VA_ARGS__)
#define VIN(T, v, n) V<T> v(n); for(auto& _elem:v)cin>>_elem
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 (a>b) {a=b; return 1;} return 0;}
#define y0 y__0
#define y1 y__1
#define j0 j__0
#define j1 j__1
#pragma endregion RegionDefs

#include <boost/multiprecision/cpp_int.hpp>

namespace mp = boost::multiprecision;

void solve()
{
    string *a = new string[7]{"SUN","MON","TUE","WED","THU","FRI","SAT"};
    string s;
    cin >> s;
    rep(i, 7)
    {
        if (a[i] == s)
        {
            cout << 7 - i << endl;
        }
    }
}

int main()
{
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(numeric_limits<double>::max_digits10);

    solve();

    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
  int A = sc.nextInt();
  String op = sc.next();
  int B = sc.nextInt();
  if(op.charAt(0) == '+')System.out.println(A+B);
  else System.out.println(A-B);
}
}


Measured memory_bytes: 21844
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
#include <map>
typedef  long long ll;
using namespace std;

int main(void) {
	string W, T;
	cin >> W;
	for (int i = 0; i < W.length(); i++)
	{
		W[i] = tolower(W[i]);
	}

	int cnt = 0;
	while (cin >> T)
	{		
		for (int i = 0; i < T.length(); i++)
		{
			T[i] = tolower(T[i]);
		}
		if (W == T) cnt++;
	}

	cout << cnt << endl;

	return 0;
}


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

using namespace std;
using ll = long long;
 
#define rep(i, n)      for (int i = 0; i < (n); i++)
#define repr(i, n)     for (int i = (n) - 1; i >= 0; i--)
#define repe(i, l, r)  for (int i = (l); i < (r); i++)
#define reper(i, l, r) for (int i = (r) - 1; i >= (l); i--)
#define repi(i, l, r)  for (int i = (l); i <= (r); i++)
#define repir(i, l, r) for (int i = (r); i >= (l); i--)
#define range(a) a.begin(), a.end()
void initio() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }

enum { RED, BLUE, NONE };

#ifdef DEBUG
string s = "RRBRRBBRBB";
int query(vector<bool> a) {
  int x = 0;
  rep(i, a.size()) {
    if (a[i]) {
      if (s[i] == 'R') x++;
      else x--;
    }
  }
  return x > 0 ? RED : BLUE;
}
#else
int query(vector<bool> a) {
  cout << "?";
  for (int i = 0; i < a.size(); i++) {
    if (a[i]) {
      cout << " " << i + 1;
    }
  } 
  cout << endl;
  string s; cin >> s;
  return s == "Red" ? RED : BLUE;
}
#endif

int main() { initio();
#ifdef DEBUG
  int N = 5;
#else
  int N; cin >> N;
#endif
  auto seq = [&](int k) {
    vector<bool> a(2*N);
    rep(i, N) a[i + k] = true;
    return a;
  };
  int fst = query(seq(0));
  int l = 0;
  int r = N;
  while (r - l > 1) {
    int m = (l + r) / 2;
    if (query(seq(m)) == fst) {
      l = m;
    } else {
      r = m;
    }
  }
  auto eq1 = seq(l);
  auto eq2 = seq(l);
  rep(i, 2 * N) eq2[i] = !eq2[i];
  eq1[l] = false;
  eq2[l + N] = false;
  vector<int> ans(2*N);
  rep(i, 2*N) {
    if (eq1[i]) {
      eq2[i] = true;
      ans[i] = query(eq2);
      eq2[i] = false;
    } else {
      eq1[i] = true;
      ans[i] = query(eq1);
      eq1[i] = false;
    }
  }
  cout << "! ";
  rep(i, 2*N) cout << "RB"[ans[i]];
  cout << endl;
}


Measured memory_bytes: 724
//内容さっきと同じだけどatcoder problemsの反映がおかしかったので。
#include <bits/stdc++.h>
using namespace std;

int main() {
  int n, k;
  int64_t M_score = -2000000000LL;
  scanf("%d %d", &n, &k);
  vector<int> p(n + 1), c(n + 1);
  for (int i = 1; i <= n; i++) cin >> p[i];
  for (int i = 1; i <= n; i++) cin >> c[i];
  for(int i = 1; i <= n; i++) {
    int move = 0, masu = i;//開始時
    int64_t sum = 0LL, sub_max = -20000000000LL;
    vector<int64_t> v;//添え字ずれます
    bool syukai = false;
    while(move < k) {
      move++;
      masu = p[masu];
      sum += c[masu];
      v.push_back(sum);
      sub_max = max(sub_max, sum);
      if(masu == i) {
        syukai = true;
        break;
      }
    }
    //この段階でsyukai == trueならsumは一周して得られるscore
    if(syukai && sum > 0) {
      for(int j = 0; j < move; j++) {
        M_score = max(M_score, v[j] + sum * (int64_t)((k - (j + 1)) / move));
      }
    }else {
      M_score = max(M_score, sub_max);
    }
  }
  cout << M_score;
}


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

using namespace std;

static vector<int> M(44, 0);

static inline int fibonacci(int n) {
  if (n == 0 || n == 1) {
    return 1;
  } 

  if (M[n] != 0) {
    return M[n];
  } 
  M[n] = fibonacci(n - 2) + fibonacci(n - 1);
  return M[n];
}

int main() {
  int n;
  cin >> n;
  
  cout << fibonacci(n) << endl;
 
  return 0;
}



Measured memory_bytes: 3084
#include <string>
#include <iostream>
#include <algorithm>

int main()
{
  std::string S;
  std::getline(std::cin, S);
  std::sort(S.begin(), S.end());
  if (S[0] == S[1] && S[2] == S[3] && S[1] != S[2])
    std::cout << "Yes" << std::endl;
  else
    std::cout << "No" << std::endl;
}

Measured memory_bytes: 256
from itertools import accumulate
from functools import reduce
N,x,*A = map(int, open(0).read().split())
dp =[list(accumulate((A[i-j] for j in range(N)),min)) for i in range(N)]
ans = reduce(min, (i*x+sum(a) for i,a in enumerate(zip(*dp))))
print(ans)

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

int main() {
  long long N; cin >> N;
  long long tmp = 1;
  for (long long p = 2; p*p <= N; p++) {
    if (N % p == 0) {
      tmp = max(tmp, p);
    }
  }
  long long x = tmp;
  long long y = N / tmp;
  cout << x + y - 2 << endl;
}

Measured memory_bytes: 256
s = list(str(input()))

kekka = []

for i in range(len(s)):
    
    if s[0]=="B":
        pass
            
    if s[i]=="B" :
        if not kekka==[]:
            kekka.pop()
    else:
        kekka.append(s[i])

print(''.join(kekka))

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

int main(){
	int a,b,c,d;
	int A[4];
	cin >> a>>b>>c>>d;
	A[0]=a;
	A[1]=b;
	A[2]=c;
	A[3]=d;
	sort(A,A+4);
	if(A[0]==A[1]&&A[2]==A[3]){
		cout << "yes"<<endl;
	}
	else {
		cout << "no"<<endl;
	}
	return 0;
}


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


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    cout << 800 * N - N / 15 * 200 << endl;

    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <fstream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
using namespace std;

#define DEBUG 1
#define ll         long long
#define REP(i, n) for (long long i = 0; i < (n); i++) 
static const ll INF = 1000000000000000000LL;
static const int MOD = 1000000007;


int N;
string s;

bool findNum(string num)
{
    int t = 0;
    for(int i = 0; i < N; ++i)
    {
        if(t == 3)break;
        if(s[i] == num[t])++t;
    }
    return t == 3;
}

int main(){
    //その暗証番号が使用できるか

    string numList = "0123456789";

    cin >> N;
    cin >> s;
    int res = 0;

    for(int i = 0; i < 10; ++i)
    {
        for(int j = 0; j < 10; ++j)
        {
            for(int k = 0; k < 10; ++k)
            {
                string num = "";
                num += numList[i];
                num += numList[j];
                num += numList[k];
                if(findNum(num))++res;
            }
        }
    }


    cout << res << endl;
    return 0;

}

Measured memory_bytes: 256
from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations # (string,3) 3回
from collections import deque
from collections import defaultdict
import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))

def main():
    n = int(input())
    # 一番大きいものは何か、それを保存してdfs
    def dfs(cnt, s):
        if cnt == n:
            print(s)
            return
        biggest = 'a'
        c = 0
        while c < len(s):
            if s[c] == biggest:
                biggest = chr(ord(biggest)+1)
                c += 1
            else:
                c += 1
        for i in range(0,ord(biggest) - ord('a') + 1):
            sc = chr(ord('a')+i)
            s += sc
            dfs(cnt + 1, s)
            s = s[:-1]
    dfs(0,"")
if __name__ == '__main__':
  main()


Measured memory_bytes: 6504
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,n) for(int i=1;i<(int)(n);i++)

typedef long long ll;
using namespace std;
int main()
{
  ll n,k;
  cin>>n>>k;

  cout<<k*(ll)pow(k-1,n-1)<<endl;
  return 0;
}


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

const int64_t MOD = 998244353;
void add(int64_t& a, int64_t b){
    a = (a+b) % MOD;
}
void mul(int64_t& a, int64_t b){
    a = a*b % MOD;
}
int64_t power_mod(int64_t num, int64_t power){
    int64_t prod = 1;
    num %= MOD;
    while(power > 0){
        if(power&1) prod = prod * num % MOD;
        num = num * num % MOD;
        power >>= 1;
    }
    return prod;
}

template<typename T>
struct BIT {
    int n;
    vector<T> dat;

    BIT(int n=0){
        initialize(n);
    }

    void initialize(int nin){
        n = nin;
        dat.resize(n, 0);
    }

    T sum(int i){
        T s = 0;
        while(i >= 0){
            s += dat[i];
            i = (i & (i+1)) - 1;
        }
        return s;
    }

    T sum_between(int i, int j){
        return sum(j) - sum(i-1);
    }

    void plus(int i, T x){
        while(i < n){
            dat[i] += x;
            i |= i+1;
        }
    }

    // a[0]+...+a[ret] >= x
    int lower_bound(T x){
        int ret = -1;
        int k = 1;
        while(2*k <= n) k <<= 1;
        for( ;k>0; k>>=1){
            if(ret+k < n && dat[ret+k] < x){
                x -= dat[ret+k];
                ret += k;
            }
        }
        return ret + 1;
    }
};

int main(){
    int N, X[200000], Y[200000];
    cin >> N;
    map<int, int> xs, ys;
    for(int i=0; i<N; i++){
        cin >> X[i] >> Y[i];
        xs[X[i]] = 0;
        ys[Y[i]] = 0;
    }
    int sz = 0;
    for(auto p : xs) xs[p.first] = sz++;
    sz = 0;
    for(auto p : ys) ys[p.first] = sz++;
    for(int i=0; i<N; i++){
        X[i] = xs[X[i]];
        Y[i] = ys[Y[i]];
    }
    vector<int> order(N);
    for(int i=0; i<N; i++) order[i] = i;
    sort(order.begin(), order.end(), [&](int i, int j){ return X[i] < X[j]; });

    BIT<int> bit_bef(N), bit_aft(N);
    for(int i=0; i<N; i++) bit_aft.plus(i, 1);

    int64_t ans = 0;
    for(int i : order){
        int y = Y[i];
        bit_aft.plus(y, -1);
        int A = bit_bef.sum_between(0, y), B = bit_bef.sum_between(y, N-1);
        int C = bit_aft.sum_between(0, y), D = bit_aft.sum_between(y, N-1);

        add(ans, power_mod(2, N-1));
        add(ans, (power_mod(2, A)-1) * (power_mod(2, D)-1) % MOD * power_mod(2, B) % MOD * power_mod(2, C) % MOD);
        add(ans, power_mod(2, A) * power_mod(2, D) % MOD * (power_mod(2, B)-1) % MOD * (power_mod(2, C)-1) % MOD);
        add(ans, MOD - (power_mod(2, A)-1) * (power_mod(2, D)-1) % MOD * (power_mod(2, B)-1) % MOD * (power_mod(2, C)-1) % MOD);
        bit_bef.plus(y, 1);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 24960
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
typedef vector<string> vstring;
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
const int INF = 1 << 30;
const int dx[] = {1,0,-1,0,1,1,-1,-1};
const int dy[] = {0,-1,0,1,1,-1,-1,1};
#define stp(x)  setprecision(x)
const long double PI=3.14159265358979323846264338327950;
int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin>>n;
  vlong a(n*3);
  rep(i,n*3){
    cin>>a[i];
  }
  priority_queue<long long> pq1;
  priority_queue<long long> pq2;
  ll sum=0,sum2=0;
  rep(i,n){
    sum+=a[i];
    pq1.push(-a[i]);
  }
  REP(i,n*2,n*3){
    sum2+=a[i];
    pq2.push(a[i]);
  }

  vector<ll> max(n*3);
  max[n-1]=sum;
  REP(i,n,n*2){
    ll tmp=a[i];
    pq1.push(-a[i]);
    sum+=a[i];
    sum-=-pq1.top();
    pq1.pop();
    max[i]=sum;
    
  }
  ll ans=max[n*2-1]-sum2;
  for(int i=n*2-1;i>=n;i--){
    ll tmp=a[i];
    pq2.push(a[i]);
    sum2+=a[i];
    sum2-=pq2.top();
    pq2.pop();
    chmax(ans,max[i-1]-sum2);
  }
  cout<<ans<<'\n';
  return(0);
}

Measured memory_bytes: 9468
#include<bits/stdc++.h>
using namespace std;
int n,m,x;
int a[105][105],c[105],now[105];
int cal(int state)
{
    int res=0;
    for(int i=1;i<=m;i++)now[i]=0;
    for(int i=0;i<n;i++)
    {
        if(state&(1<<i))
        {
            res+=c[i];
            for(int i0=1;i0<=m;i0++)
            {
                now[i0]+=a[i][i0];
            }
        }
    }
    for(int i0=1;i0<=m;i0++)
    {
        if(now[i0]<x)return INT_MAX;
    }
    return res;
}
int main()
{
    scanf("%d %d %d",&n,&m,&x);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&c[i]);
        for(int i0=1;i0<=m;i0++)
        {
            scanf("%d",&a[i][i0]);
        }
    }
    int ans=INT_MAX;
    for(int i=0;i<(1<<n);i++)
    {
        ans=min(ans,cal(i));
    }
    if(ans==INT_MAX)ans=-1;
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 3832
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#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 <utility>
#include <vector>
#include <tuple>

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define co(x) cout << (x) << "\n"
#define pb push_back
#define Never
#define To

using namespace std;
long S[12][12];

int main(){

	cin.tie(0);
	ios::sync_with_stdio(false);

	int N, M;

	cin >> N >> M;

	for(int m = 0; m < M; m++){
		int K ;
		cin >> K;
		for (int k = 0; k < K; k++){
			int s;
			cin >> s;
			S[m][s-1] = 1;
		}
	}

	int P[M];
	for(int m = 0; m < M; m++){
		cin >> P[m];
	}

	long num, ans;
	num = pow(2, N);
	ans = 0;

	for(long i = 0; i < num; i++){
		bool ok = true;
		for(int m = 0; m < M; m++){
			long count;
			count = 0;
			for(long s = 0; s < N; s++){
				if((S[m][s] == 1) && (((long)pow(2L, s) & i) != 0)) count++;
			}
			if(count % 2 != P[m]){
				ok = false;
				break;
			}
		}
		if(ok) ans++; 
	}
	cout << ans << endl;

	Never To return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <ccomplex>
#include <unordered_map>
#include <cstring>
#include <iostream>
#include <numeric>
#include <sstream>
#include <set>
#include <map>
#include <iomanip>

using namespace std;
#define MAX 1LL << 60
#define MOD 1000000007

typedef long long ll;

#define rep(i, s, e) for(ll i = s; i < e; i++)
#define repR(i, s, e) for(ll i = s; i > e; i--)
#define reft0(i, j) setfill('0') << setw(i) << j

template<class T> inline bool chMax(T& a, T b){ if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chMin(T& a, T b){ if (a > b) { a = b; return true; } return false; }

int main(){
    double a, b, x;
    cin >> a >> b >> x;

    double max = a * a * b;
    double rad, ans;

    if (x <= (max / 2)){
        rad = atan(a * b * b / 2 / x);
    }
    else{
        rad = atan(2 * (max - x) / a / a / a);
    }
    ans = rad / M_PI * 180;
    cout << fixed << setprecision(10) << ans << endl;

    return 0;
}


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

#define FOR(i, a, b) for(long long int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LLINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979

using namespace std;
typedef long long int ll;
typedef pair< long long int, long long  int> P;

vector<string> c(20);

int dfs(int x, int y,int h,int w) {
	int point = 1;
	if (c[y][x] == '#') {
		return 0;
	}
	c[y][x] = '#';
	if (y + 1 <= h - 1) {
		point+=dfs(x, y + 1, h, w);
	}
	if (y - 1 >= 0) {
		point+=dfs(x, y - 1, h, w);
	}
	if (x + 1 <= w - 1) {
		point+=dfs(x + 1, y, h, w);
	}
	if (x - 1 >= 0) {
		point+=dfs(x - 1, y, h, w);
	}
	return point;
}

int main(void) {
	
	while (1) {
		int h, w;
		int posx = -1, posy = -1;
		int count = 0;

		cin >> w >> h;
		if (h == 0) {
			break;
		}
		

		FOR(i, 0, h - 1) {
			cin >> c[i];
		}
		FOR(i, 0, h - 1) {
			FOR(t, 0, w - 1) {
				if (c[i][t] == '@') {
					posx = t;
					posy = i;
					break;
				}
			}
			if (posx != -1) {
				break;
			}
		}
		
		cout << dfs(posx, posy, h, w) << endl;
	}

}


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


int main() {

  int64_t n;
  cin>>n;

  string s;
  cin>>s;

  int cnt_r=0,cnt_b=0;
  for(int i=0;i<n;i++){
    if(s.at(i)=='R')
      cnt_r++;
    else
      cnt_b++;
  }

  if(cnt_r>cnt_b)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
ll a[10000][10000],p;
int main ()
{
    ll n,i,j;

    for(i=0; i<3; i++)
    {
        for(j=0; j<3; j++)
        {
            cin>>a[i][j];
        }

    }
    cin>>n;

    ll r1=0,r2=0,r3=0;
    ll c1=0,c2=0,c3=0;
    ll d1=0,d2=0;

    for(ll k=0; k<n; k++)
    {
        cin>>p;

        for(i=0; i<3; i++)
        {
            for(j=0; j<3; j++)
            {
                if(a[i][j]==p)
                {
                    a[i][j]=-999999;
                }
            }

        }
    }
    ll x=-999999;

    if((a[0][0]==x)&&(a[1][1]==x)&&(a[2][2]==x))
    {
        d1=1;
    }
    if((a[0][2]==x)&&(a[1][1]==x)&&(a[2][0]==x))
    {
        d2=1;
    }
    if((a[0][0]==x)&&(a[0][1]==x)&&(a[0][2]==x))
    {
        r1=1;
    }
    if((a[1][0]==x)&&(a[1][1]==x)&&(a[1][2]==x))
    {
        r2=1;
    }
    if((a[2][0]==x)&&(a[2][1]==x)&&(a[2][2]==x))
    {
        r3=1;
    }


    if((a[0][0]==x)&&(a[1][0]==x)&&(a[2][0]==x))
    {
        c1=1;
    }
    if((a[0][1]==x)&&(a[1][1]==x)&&(a[2][1]==x))
    {
        c2=1;
    }
    if((a[0][2]==x)&&(a[1][2]==x)&&(a[2][2]==x))
    {
        c3=1;
    }



    if((r1==1)||(r2==1)||(r3==1)||(c1==1)||(c2==1)||(c3==1)||(d1==1)||(d2==1))
    {
        cout<<"Yes\n";
    }
    else
    {
        cout<<"No\n";
    }


    return 0;
}


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

int main()
{
  string s;
  cin >> s;
  int ans = 0;
  for (int i = 0; i < s.length(); i++) {
    int cnt = 0;
    for (int j = i; j < s.length(); j++) {
      char c = s[j];
      if (c == 'A' || c == 'C' || c == 'G' || c == 'T') {
        cnt++;
        ans = max(ans, cnt);
      } else {
        break;
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll INF = 1e15;
int main(){
  ll N;
  cin >> N;
  vector<ll> h(N);
  for(int i=0;i<N;i++)
    cin >> h[i];
  vector<ll> dp(N, INF);
  dp[0] = 0;
  for(int from = 0;from < N-1;from++){
    for(int to = from+1;to<=from+2 && to < N;to++){
      dp[to] = min(dp[to], dp[from] + abs(h[from] - h[to]));
    }
  }
  cout << dp[N-1] << endl;
}

Measured memory_bytes: 1792
import java.util.Scanner;
class Main {
	int n,i,x,y,z,b,f,r,v;
	int[][][] count = new int[5][4][11];
	public void suzuki(){
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		for(i = 0;i < n;i++){
			b = sc.nextInt();
			f = sc.nextInt();
			r = sc.nextInt();
			v = sc.nextInt();
			count[b][f][r] += v;
		}
		for(x = 1;x <= 4;x++){
			for(y = 1;y < 4;y++){
				for(z = 1;z < 11;z++){
					System.out.print(" " + count[x][y][z]);
				}
				System.out.println();
			}
			if(x < 4){
				System.out.println("####################");
			}
		}
	}
	public static void main(String[] args){
		new Main().suzuki();
	}
}

Measured memory_bytes: 21080
// 00:15

#include <iostream>

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

int main() {
  int n, q;
  std::cin >> n;
  int S[n];
  rep(i, n) std::cin >> S[i];
  std::cin >> q;
  int T[q];
  rep(i, q) std::cin >> T[i];

  int cnt = 0;
  rep(i, q) {
    rep(j, n) {
      if (T[i] == S[j]) {
        cnt++;
        break;
      }
    }
  }

  std::cout << cnt << '\n';
  return 0;
}


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

int main()
{
        int a,b,c,d;
        cin>> a>> b>> c>>d;
        int one;
        if(a%d == 0)
        {
                one = a/d;
        }

        else
        {
                one = a/d + 1;
        }
        int two;
        if(c%b==0)
        {
                two = c/b;
        }
        else
        {
                two = c/b + 1;
        }
        if(one < two)
        {
                cout << "No" << endl;
        }
        else
        {
                cout << "Yes" << endl;
        }
}

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

int main(void) {
  int a, b, h, m;
  scanf("%d %d %d %d", &a, &b, &h, &m);
  printf("%.20lf\n", sqrt(a*a+b*b-2*a*b*cos(2*M_PI*fabs(60*h-11*m)/720)));
  return 0;
}

Measured memory_bytes: 2596
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    
	    Scanner sc = new Scanner(System.in);  //標準入力の宣言

		int N = sc.nextInt();        //標準入力(入力人数)をNに代入

		int[] intArray;          //int型の1次元配列intArrayを宣言
		intArray = new int[N];   //N個1次元配列intArrayを宣言

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

	//配列を順番に読む
	int sum;          //一時計算用変数を宣言
	int kotae = 0;    //答えの変数を宣言
	for(int i=0; i<N; i++) {
		sum = 0;
		for(int j=i+1; j<N; j++) {
			sum = sum + intArray[j];
		}
		kotae = kotae + intArray[i] * sum;
	}
			
		System.out.println(kotae);

  }
}


Measured memory_bytes: 35716
#include <iostream>
#define ll long long
using namespace std;

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

  if(k>a && a>=1)
  {
      k-=a;
      a=0;

  }
  else if(a>=k && a>=1)
  {
      a-=k;
      k=0;
 }



  if(k>b && b>=1)
  {
      k-=b;
      b=0;

  }
  else if(k<=b)
  {
      b-=k;
      k=0;
    }

  cout<<a<<" "<<b<<endl;


    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main (void) {
  char *s;
  int n, k;
  
  scanf("%d%d", &n, &k);
  
  s = new char[n + 1];
  scanf("%s", s);
  
  if (s[k-1] == 'A') {
    s[k-1] = 'a';
  } else if (s[k-1] == 'B') {
    s[k-1] = 'b';
  } else {
    s[k-1] = 'c';
  }
  
  printf("%s\n", s);
  
  return 0;
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;
 
/* 
The read function reads a string according to each one. 
*/
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

//main function
fn main() {
    let a: i32 = read();
    let b: i32 = read();
    if a>9 || b>9{
	println!("-1");
    }else {
	println!("{}",a*b);
    }
}


Measured memory_bytes: 4352
H, W, ch, cw, dh, dw, *S = open(0).read().split()
H, W, ch, cw, dh, dw = [int(_) - 1 for _ in [H, W, ch, cw, dh, dw]]
H += 1
W += 1

stack = [[ch, cw]]
d = 0
INF = 10**10
dists = [[INF] * W for _ in range(H)]
dists[ch][cw] = 0


def valid(x, y):
    return 0 <= x < H and 0 <= y < W


while stack:
    se = set()
    while stack:
        x, y = stack.pop()
        for dx, dy in ((1, 0), (0, 1), (-1, 0), (0, -1)):
            nx, ny = x + dx, y + dy
            if valid(nx, ny) and dists[nx][ny] == INF:
                if S[nx][ny] == '.':
                    dists[nx][ny] = d
                    stack += [[nx, ny]]
                else:
                    se.add((x, y))
    stack2 = []
    d += 1
    for x, y in se:
        for dx in range(-2, 3):
            for dy in range(-2, 3):
                nx, ny = x + dx, y + dy
                if valid(nx, ny) and dists[nx][ny] == INF and S[nx][ny] == '.':
                    stack2 += [[nx, ny]]
                    dists[nx][ny] = d
    stack = stack2

ans = dists[dh][dw]
print(ans if ans < INF else -1)


Measured memory_bytes: 91724
/* Bismillahirrahmanirrahim */
/* Author : Jehian Norman Saviero (@Reiva5) */
#include <bits/stdc++.h>
 
// MACROS SAMPAH
#define Jehian using
#define Norman namespace
#define Saviero std
 
Jehian Norman Saviero;
 
// MACROS TYPE
typedef long l;
typedef long long ll;
typedef unsigned long ul;
typedef unsigned long long ull;
typedef double ld;
typedef pair<int,int> pi;
typedef pair<l,l> pl;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<l> vl;
typedef vector<ll> vll;
 
// MACROS FOR PRINT
#define nl printf("\n")
#define sp printf(" ")
 
// MACROS FOR ATTRIBUTE
#define fi first
#define se second
 
// MACROS FOR FUNCTION AND METHOD
#define eb emplace_back
#define mp make_pair
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define ALL(x) (x).begin(), (x).end()
#define ALLN(x,n) (x), (x)+(n)
#define CUBE(x) (SQR(x)*(x))
#define SET(x,y) for (int _qwe = sizeof(x)/sizeof(x[0]); _qwe; ) x[--_qwe] = (y)
#define SQR(x) ((x)*(x))
#define SSORT(x,sz) sort(ALLN(x,sz))
#define RESET(x) memset((x), 0, sizeof(x))
#define VSORT(x) sort(ALL(x))
 
// MACROS READ INPUT
#define sci(x) scanf("%d", &x)
#define scl(x) scanf("%ld", &x)
#define scll(x) scanf("%lld", &x)
#define scul(x) scl(x)
#define scull(x) scll(x)

int main() {
	ll A, B, N;
	scll(A), scll(B), scll(N);
	if (N >= B) {
		N = B-1;
	}
	ll kiri = (A * N) / B;
	ll kanan = A * (N / B);
	printf("%lld\n", kiri - kanan);
	return 0;
}

Measured memory_bytes: 3824
n,k,q = map(int,input().split())
l = [0 for _ in range(n)]
for _ in range(q):
	a = int(input()) - 1
	l[a] += 1

for i in range(n):
	if q - l[i] >= k:
		print('No')
	else:
		print('Yes')


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

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

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <stdlib.h>
#include <math.h>
using namespace std;
const int INF=1000000007;

int main (void){
    long long int k,i,n,h[100001],a[100001];
    cin >> n >> k;
    for(i=0;i<n;i++) cin >> h[i];
    sort(h,h+n);
    for(i=0;i<=n-k;i++) a[i]=h[i+k-1]-h[i];
    sort(a,a+n-k+1);
    cout << a[0] << endl;
    return 0;
}

Measured memory_bytes: 1792
List=[int(input()) for i in range(5)]
num=[10,20,30,40,50,60,70,80,90,100,110,120,130]
time=0
table=[]
for i in range(5):
    subtract=0
    for j in range(len(num)):
        if List[i]<=num[j]: 
            subtract=num[j]
            break
    table.append([subtract-List[i],List[i]])
table.sort()
for i in range(5):
    time+=table[i][0]+table[i][1]
time-=table[4][0]
print(time)

Measured memory_bytes: 9144
#include <algorithm>
#include <functional>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <climits>

#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const int INF=100000000;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
using namespace std;
typedef pair<int ,int > P;
typedef long long ll;
typedef vector<string> Board;

bool reverse_rec(Board& board, char stone,int x,int y, int dx,int dy) {
    if(x>7 || y>7) return false;
    if(x<0 || y<0) return false;
    if(board[y][x]=='.') return false;
    if(board[y][x]==stone) return true;

    bool flag = reverse_rec(board, stone, x+dx,y+dy,dx,dy);

    if(flag) {
        board[y][x]=stone;
    }
        
    return flag;
}
int count(Board& board, char stone) {
    int res=0;
    rep(i,board.size()) rep(j,board[i].size()) if(board[i][j]==stone) res++;
    return res;
}
void plot(Board& board) {
    rep(i,board.size()) {
        rep(j,board[i].size()) {
            cout<<board[i][j];
        }
        cout<<endl;
    }

}
void reverse(Board &board, char stone, int x, int y) {
    if(board[y][x]!='.') return;
    for(int dx=-1;dx<=1;dx++) {
        for(int dy=-1;dy<=1;dy++) {
            if(!(0<=x+dx&&x+dx<8)) continue;
            if(!(0<=y+dy&&y+dy<8)) continue;
            // cout<<dx<<","<<dy<<endl;

            if(board[dy+y][dx+x]!=stone && reverse_rec(board,stone,x+dx,y+dy,dx,dy)) {
                board[y][x]=stone;

            }
        }
    }

}

bool mami(Board &board) {
    int maxi = count(board, 'o');
    bool flag = false;
    Board res = board;
    rep(i,8) {
        rep(j,8) {
            Board tmp = board;
            reverse(tmp, 'o', j, i);
            if(maxi < count(tmp,'o')) {
                maxi = count(tmp,'o');
                res = tmp;
                flag = true;

            }
        }
    }
    board = res;
    return flag;
}
bool majo(Board &board) {
    int maxi = count(board, 'x');
    bool flag = false;
    Board res = board;
    for(int i=7;i>=0;i--) {
        for(int j=7;j>=0;j--) {
            Board tmp = board;
            reverse(tmp, 'x', j, i);
            if(maxi < count(tmp,'x')) {
                maxi = count(tmp,'x');
                res = tmp;
                flag = true;
            }
        }
    }
    board = res;
    return flag;
}

int main() {
    Board board;
    rep(i,8) {
        string str;
        cin>>str;
        board.pb(str);
    }

    while(1) {
        bool f = mami(board);
        f |= majo(board);
        if(!f) {
            plot(board);
            break;
        }

    }
    return 0;
}

Measured memory_bytes: 1188
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main(void) {
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<int> X(N);
  rep(i, N) cin >> X[i];
  sort(X.begin(), X.end());
  int ans = 1000000000;
  for (int p = X[0]; p <= X[N - 1]; p++) {
    int ans0 = 0;
    rep(i, N) { ans0 += (X[i] - p) * (X[i] - p); }
    ans = min(ans, ans0);
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;
typedef long long int lli;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef pair <lli,lli> pii;
#define ff first
#define ss second
#define MOD 1000000007
#define pb push_back

int main(){
	fast;
	lli n;
	cin>>n;
	map <string,int> mp;
	string s;
	for (int i=0;i<n;i++){
		cin>>s;
		mp[s]++;
	}
	cout<<mp.size()<<endl;
}

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

using namespace std;

const int N = 1e5 + 8;
long long a[N] , lst , t , ans = 1 , n;

int main()
{
	ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
	cin >> n;
	for(int i = 0 ; i < n ; i++)
		cin >> a[i];
	for(int i = 1 ; i < n ; i++)
	{
		t = a[i] - a[i - 1];
		if((lst < 0 && t > 0) || (lst > 0 && t < 0))
		{
			ans++;
			lst = 0;
		}
		else if(t)
			lst = t;
	}
	cout << ans;
}

Measured memory_bytes: 1024
from collections import defaultdict
from copy import deepcopy
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))


class UnionFind():
    def __init__(self, n):
        self.n = n
        # 各要素の親要素 親は -(その集合の要素数)
        self.parents = [-1] * n

    def find(self, x):
        '''要素 x の親要素の番号を返す'''
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        '''要素 x が属する集合と要素 y が属する集合を併合する'''
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        '''要素 x が属する集合の要素数を返す'''
        return -self.parents[self.find(x)]

    def same(self, x, y):
        '''要素 x と要素 y が同じ集合に属するかを返す'''
        return self.find(x) == self.find(y)

    def members(self, x):
        '''要素 x が属する集合の要素をリストを返す'''
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


def main():
    n, m = LI()
    edges = [LI() for _ in range(m)]
    ans = 0
    for remove_u, remove_v in edges:
        uf = UnionFind(n)
        for u, v in edges:
            if u == remove_u and v == remove_v:
                continue
            u, v = u - 1, v - 1
            uf.union(u, v)
        if len(uf.roots()) > 1:
            ans += 1
    print(ans)


main()


Measured memory_bytes: 74804
using System;

namespace B___AtCoder_Alloy
{
    class Program
    {
        static void Main(string[] args)
        {
            var inputFirstLine = Console.ReadLine().Split(' ');
            int result = 0;

            // 素材の枚数
            int n = int.Parse(inputFirstLine[0]);

            // ほしい板の縦の長さ
            int h = int.Parse(inputFirstLine[1]);

            // ほしい板の横の長さ
            int w = int.Parse(inputFirstLine[2]);

            for (int i = 0; i < n; i++)
            {
                var inputLine = Console.ReadLine().Split(' ');

                // i 番目の素材の縦の長さ
                int ai = int.Parse(inputLine[0]);

                // i 番目の素材の横の長さ
                int bi = int.Parse(inputLine[1]);

                if (ai >= h && bi >= w)
                {
                    result++;
                }
            }

            Console.WriteLine(result.ToString());
        }
    }
}

Measured memory_bytes: 11092
n = gets.to_i
ps = gets.split(' ').map(&:to_i)
qs = gets.split(' ').map(&:to_i)

ans_1 = 0
ans_2 = 0
[*1..n].permutation(n).each.with_index(1) do |a, i|
  ans_1 = i if ps == a
  ans_2 = i if qs == a
end

puts (ans_1 - ans_2).abs

Measured memory_bytes: 2172
if __name__ == "__main__":
    nums = map( int, raw_input().split())
    nlen = len( nums )
    nlast = nlen - 1
    while 0 < nlast:
        j = 0
        while j < nlast:
            if nums[j] > nums[j+1] :
                d = nums[j+1]
                nums[j+1] = nums[j]
                nums[j] = d
            j += 1
        nlast -= 1

    nlast = nlen - 1
    i = 0
    while i < nlen:
        if i != nlast:
            print nums[i],
        else:
           print nums[i]
        i += 1

Measured memory_bytes: 4228
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn dfs_depth(g: &Vec<Vec<usize>>, cur: usize, parent: usize) -> (usize, usize) {
    let mut max_depth = 0;
    let mut max_vertex = cur;
    for &ci in g[cur].iter() {
        if ci == parent {
            continue;
        }
        let (depth, vertex) = dfs_depth(g, ci, cur);
        if max_depth < depth {
            max_depth = depth;
            max_vertex = vertex;
        }
    }
    (1 + max_depth, max_vertex)
}

fn tree_diameter(g: &Vec<Vec<usize>>) -> usize {
    let (_, vertex1) = dfs_depth(&g, 0, g.len());
    let (depth, _) = dfs_depth(&g, vertex1, g.len());
    depth
}

fn main() {
    let n = read::<usize>();
    let mut g = vec![vec![]; n];
    for i in 0..n - 1 {
        let v = read_vec::<usize>();
        let (a, b) = (v[0] - 1, v[1] - 1);
        g[a].push(b);
        g[b].push(a);
    }
    let diameter = tree_diameter(&g);
    debug!(diameter);
    if (diameter + 1) % 3 == 0 {
        println!("Second");
    } else {
        println!("First");
    }
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 35324
import collections
import sys

n,m = map(int,input().split())

a = list(map(int,input().split()))

a.sort()

l = collections.Counter()

for i in a:
    l[i] += 1

co = 0
su = 0
l = l.most_common(m)
for i in l:
    if co < m:
        co += 1
        n -= i[1]

print(n)



Measured memory_bytes: 32668
#include <cstdio>
#include <algorithm>

using namespace std;

char s[100][101];
int dp[100][100];

int main() {
    int h, w, i, j;
    
    scanf("%d %d", &h, &w);
    
    for (i = 0; i < h; i++) scanf("%s", s[i]);
    
    for (i = 0; i < h; i++) {
        for (j = 0; j < w; j++) {
            dp[i][j] = 1e9;
        }
    }
    
    if (s[0][0] == '.') {
        dp[0][0] = 0;
    } else {
        dp[0][0] = 1;
    }
    
    for (i = 0; i < h; i++) {
        for (j = 0; j < w; j++) {
            if (i + 1 < h) {
                int c = 0;
                
                if (s[i][j] == '.' && s[i + 1][j] == '#') c = 1;
                
                dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + c);
            }
            
            if (j + 1 < w) {
                int c = 0;
                
                if (s[i][j] == '.' &&  s[i][j + 1] == '#') c = 1;
                
                dp[i][j + 1] = min(dp[i][j + 1], dp[i][j] + c);
            }
        }
    }
    
    printf("%d\n", dp[h - 1][w - 1]);
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=200005;
//int a[N];
int n,L ;
struct node
{
	int id;
	int A,B;
}a[N];
bool cmp(node x,node y)
{
	if(x.B==y.B)
		return x.A<y.A;
	return x.B<y.B;
}
int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
	{
		cin>>a[i].A>>a[i].B;
		a[i].id=i;
	}
	sort(a+1,a+n+1,cmp);
	int t=0;
	for(int i=1;i<=n;i++)
	{
	//	cout<<a[i].A<<" "<<a[i].B<<" "<<t<<endl;
		if(t+a[i].A<=a[i].B)
		{
			t+=a[i].A;
		}
		else
		{
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl;
	return 0;
 
}

Measured memory_bytes: 2560
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cctype>

using namespace std;

#define ll long long

int n, m;
int a[1000001];

int main() {
    string s;
    cin >> s;
    if (s[s.length() - 1] == 's') {
        cout << s + "es" << endl;
    } else cout << s + "s" << endl;
    return 0;
}

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

#define INF 1000010000
#define nl '\n'
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
#define pdd pair<double,double>
#define all(c) (c).begin(), (c).end()
#define SORT(c) sort(all(c))
#define sz(c) (c).size()
#define rep(i,n) for( int i = 0; i < n; ++i )
#define repi(i,n) for( int i = 1 ; i <= n; ++i )
#define repn(i,n) for( int i = n - 1 ; i >= 0 ; --i )
#define repf(j,i,n) for( int j = i ; j < n ; ++j )
#define die(s) {std::cout << s << nl;}
#define dier(s) {std::cout << s; return 0;}
#define dbg(var) {std::cout << #var << "  = " << var << nl;}
#define vi vector<int>
typedef long long ll;

using namespace std;

constexpr int MOD = 1e9 + 7;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.precision(0); 
	
	int n , k;
	cin >> n >> k;
	
	vector<int> v(istream_iterator<int>{cin} , istream_iterator<int>());
	
	vector<vi> dp(n + 1 , vi(k + 1));
	dp[0][0] = 1;
	
	repi(i , n)
	{
		int cur = 0;
		rep(j , k + 1)
		{
			if(i > 0)
			{
				cur += dp[i - 1][j];
				cur %= MOD;
				if(j - v[i - 1] - 1 >= 0)
					cur -= dp[i - 1][j - v[i - 1] - 1];
			}
			cur = (cur + MOD) % MOD;
			dp[i][j] = cur;
		}
	}
	
	cout << dp[n][k] << endl;


	return 0;
}

Measured memory_bytes: 40192
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <array>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>
#include <stack>
#include <utility>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <bitset>
#include <random>
#include <functional>
#include <sstream>
#include <iomanip>

using namespace std;

#define _CRT_SECURE_NO_WARNINGS
#define rep(i, n) for(int i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define REVE(x) reverse((x).begin(),(x).end())
#define MP make_pair
#define PB push_back

typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef long long LL;

int cnt(int n, int x) {
	int ans = 0;
	for (int a = 1; a < min(n, x / 3 + 1); a++) {
		for (int b = a + 1; b < min(n, x - a + 1); b++) {
			int c = x - a - b;
			if (0 < c&&c <= n && b < c)ans++;
		}
	}
	return ans;
}
int main() {
	VI ans;
	while (true) {
		int n, x;
		cin >> n >> x;
		if (n == 0 && x == 0)break;
		ans.PB(cnt(n, x));
	}
	for (auto i : ans) {
		cout << i << endl;
	}
}


Measured memory_bytes: 3152
S = list(input())
if S == ['>'] or S == ['<']:
    print(1)
    exit()
m = 0
n = 0
s = 0
l = []
if S[0] == '>':
    l.append(0)
    p = '>'
else:
    p = '<'
c = 1
for i in range(1, len(S)):
    if S[i] == p:
        c += 1
    else:
        l.append(c)
        c = 1
        p = S[i]
if c != 0:
    l.append(c)
if S[-1] == '<':
    l.append(0)
# print(l)
ans = 0

def calc(x):
    if x == 0:
        return 0
    elif x == 1:
        return 1
    else:
        return (1 + x) * x // 2

for i in range(0, len(l), 2):
    # print(l[i], l[i+1])
    ans += calc(l[i]) + calc(l[i + 1]) - min(l[i], l[i + 1])
print(ans)


Measured memory_bytes: 9776
#include<iostream>
using namespace std;
int main(){
	int a;
	int b;
	cin >> a >> b;
	if (a < b){
		cout << "a < b" << endl;
	}
	else if (a>b){
		cout << "a > b" << endl;
	}
	else if (a == b){
		cout << "a == b" << endl;
	}
	return 0;
}


Measured memory_bytes: 3092