akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

// エイリアス
using  ll = long signed long;
using ull = long unsigned long;
using  ld = long double;
using   P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;

// 汎用マクロ
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOREACH(i,q) for (auto &i : q)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
#define SZ(x) ((int)(x).size())
template <class T>inline bool chmin(T &a, const T b) {if (a > b) { a = b; return true;} return false;}
template <class T>inline bool chmax(T &a, const T b) {if (a < b) { a = b; return true;} return false;}
template <class T>inline void line_out(const vector<T> vec) {int n = SZ(vec); rep(i, n) { cout << vec[i]; if(i < n-1) cout << " ";}cout << endl;}
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 60;
const int mod = 1000000007;
//const int mod = 998244353;
struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};



int main()
{
  int n; cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];

  deque<ll> b;
  rep(i, n) {
    if(i%2==0) b.push_back(a[i]);
    else b.push_front(a[i]);
  }
  if(n%2==1) reverse(ALL(b));

  for(auto x : b) cout << x << " ";
  cout << endl;
}


Measured memory_bytes: 6376
//Greatest Common Divisor
#include <iostream>
#include <cmath>

using namespace std;

int greatestCommonDivisor(int a, int b) {
    if(a > b) swap(a, b);
    while(b % a != 0) {
        int t = b % a;
        b = a;
        a = t;
    }
    return a;
}

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

    cout << greatestCommonDivisor(a, b) << endl;
}


Measured memory_bytes: 3096
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stdio.h>
#include <list>
#include <numeric>
#include <stack>
#include <queue>
#include <tuple>
#include <bitset>
#include <map>
#include <math.h>
//　ceil(a/b)   (a + (b - 1))/ b
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int,int> P;
const int inf=1000000007;
const int mod=1000000007;
const double PI=3.14159265358979323846;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};

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


// ll memo[2020][2020];
// int pascal_triangle(){
//   for(int i = 0; i < 2020; i++){
//     for(int j = 0; j < i+1; j++){
//       if(j == 0 || j == i) memo[i][j] = 1;
//       else{
// 	memo[i][j] = (memo[i-1][j-1]+memo[i-1][j]);
//       }
//     }
//   }
//   return 0;
// }


int factorial(int n){
  if(n == 0) return 1;
  return n*factorial(n-1);
}

int divisor(int a){
  int cnt = 0;
  for(int i=1; i <= a; i++) if(a%i == 0) cnt++;
  return cnt;
}

int comb(int n, int k){
  return factorial(n) / (factorial(n-k)*factorial(k));
}

int answer(bool f){
  if(f) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}



int main(){
  int a,b;
  cin >> a >> b;
  int c = b-a;
  int n=0;
  for(int i = 1; i<=c; i++){
    n+=i;
  }
  cout << n - b << endl;
  return 0;
}







Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef set<int> si;
typedef pair<int,int> pii;
#define rep(i,a,b) for(int i=(a); i<(b); ++i)
#define per(i,a,b) for(int i=(b)-1; i>=(a); --i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define F first
#define S second

ll solve(ll n, vl& a, vl& b) {
	vector<pair<ll, ll> > p;
	rep(i,0,3) {
		if(a[i] < b[i]) {
			p.pb(mp(a[i],b[i]));
		}
	}
	if(sz(p) == 0) return n;
	if(sz(p) == 1) {
		return n % p[0].F + (n / p[0].F) * p[0].S;
	}
	if(sz(p) == 2) {
		ll ret = 0;
		for(ll x = 0; x * p[0].F <= n; ++x) {
			ll y = (n - x * p[0].F)/p[1].F;
			ll r = n - x * p[0].F - y * p[1].F;
			ret = max(ret, r + x * p[0].S + y * p[1].S);
		}
		return ret;
	}
	if(sz(p) == 3) {
		ll ret = 0;
		for(ll x = 0; x * p[0].F <= n; ++x) {
			for(ll y = 0; x * p[0].F + y * p[1].F <= n; ++y) {
				ll z = (n - x * p[0].F - y * p[1].F)/p[2].F;
				ll r = n - x * p[0].F - y * p[1].F - z * p[2].F;
				ret = max(ret, r + x * p[0].S + y * p[1].S + z * p[2].S);
			}
		}
		return ret;
	}
	return -1;
}

int main(void) {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	//freopen("in.txt", "r", stdin);
	ll n;
	cin >> n;
	vl a(3), b(3);
	rep(i,0,3) {
		cin >> a[i];
	}
	rep(i,0,3) {
		cin >> b[i];
	}
	n = solve(n, a, b);
	n = solve(n, b, a);
	cout << n << '\n';
}

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



int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	ll n;
	cin >> n;
	vector<ll> v(n);

	
	for(int i = 0; i < n; i++){
		cin >> v[i];
	}
	ll g = v[0];

	for(int i = 1; i < n; i++){
		g = __gcd(g,v[i]);
	}

	ll bound = 1e6 + 5;
	int *arr = new int[bound];

	for(int i = 2; i < bound; i++){
		if(arr[i] != 0)
			continue;
		for(int j = 2*i; j < bound; j+= i){
			arr[j] = i;
		}
	}

	for(int i = 0; i < bound; i++){
		if(arr[i] == 0){
			arr[i] = i;
		}
	}
	
	map<ll,ll> mp;
	for(int i = 0; i < n; i++){
		ll val = arr[v[i]];
		//cout << v[i] << ":" << val << "\n";
		mp[val]++;
	}

	bool ok = 1;
	for(auto val : mp){
		if(val.second > 1 && val.first != 1){
			ok = 0;
			break;
		}
	}

	if(ok && g == 1){
		cout << "pairwise coprime\n";
	}
	else if(g == 1){
		cout << "setwise coprime\n";
	}
	else{
		cout << "not coprime\n";
	}
}

Measured memory_bytes: 19784
from bisect import bisect_left, bisect_right

def main():
    n, k = [int(s) for s in input().strip().split()]
    A = [int(s) for s in input().strip().split()]
    
    P = sorted(a for a in A if a > 0)
    N = sorted(a for a in A if a < 0)
    pp, nn = len(P), len(N)
    negpair = pp * nn
    pospair = pp * (pp - 1) // 2 + nn * (nn - 1) // 2

    if negpair < k <= n * (n - 1) // 2 - pospair:
        print(0)
        return
    
    if k <= negpair:
        lo, hi = -(10 ** 18), -1
        while lo < hi:
            x = (lo + hi) // 2

            j = 0
            cnt = 0
            for i in range(pp):
                while j < nn and P[i] * N[j] <= x:
                    j += 1
                cnt += j

            if cnt >= k:
                hi = x
            else:
                lo = x + 1
        print(lo)
    
    else:
        class Helper:
            def __getitem__(self, x):
                j = pp - 1
                cnt = 0
                for i in range(pp):
                    while j > i and P[i] * P[j] > x:
                        j -= 1
                    cnt += max(j - i, 0)
                j = nn - 1
                for i in range(nn):
                    while j > i and N[i] * N[j] <= x:
                        j -= 1
                    cnt += nn - 1 - max(i, j)
                return cnt
        
        x = bisect_left(Helper(), k - (n * (n - 1) // 2 - pospair), lo=1, hi=10 ** 18)
        print(x)


main()


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

int main(){
    int j, s, nums[1000005], tmp, num, ans = 0;
    cin >> s;
    tmp = s;
    for(int i = 0; i < 1000005; ++i){
        if(tmp % 2 == 0){
            num = tmp / 2;
        }else{
            num = 3 * tmp + 1;
        }
        nums[i] = num;
        tmp = nums[i];
        if(s == 1 || s == 2){
            ans = 4;
        }else if(s == 4){
            ans = 4;
        }else if(nums[i] == 4){
            ans = i + 5;
            break;
        }
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define pb push_back
#define fi first
#define se second

int main(){
    int i,j;
    
    ll a,b,c;
    cin>>a>>b>>c;
    cout<<b+min(c,a+b+1)<<endl;
    return 0;
}

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

/**
 * Created by fcdkbear on 15.10.16.
 */
public class Main {

    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        new Task().solve(in, out);
        out.close();
    }


    static class Task {

        public void solve(InputReader in, PrintWriter out) {

            int n = in.nextInt();
            int[] t = new int[n];
            for (int i = 0; i < n; ++i) {
                t[i] = in.nextInt();
            }
            int[] a = new int[n];
            for (int i = 0; i < n; ++i) {
                a[i] = in.nextInt();
            }
            int[] l = new int[n];
            int[] r = new int[n];
            for (int i = 0; i < n; ++i) {
                l[i] = 1;
                r[i] = Integer.MAX_VALUE;
            }
            l[0] = r[0] = t[0];
            for (int i = 1; i < n; ++i) {
                if (t[i] < t[i - 1]) {
                    out.println(0);
                    return;
                }
                if (t[i] == t[i - 1]) {
                    r[i] = t[i];
                } else {
                    l[i] = t[i];
                    r[i] = t[i];
                }
            }
            l[n - 1] = Math.max(l[n - 1], a[n - 1]);
            r[n - 1] = Math.min(r[n - 1], a[n - 1]);
            for (int i = n - 2; i >= 0; --i) {
                if (a[i] < a[i + 1]) {
                    out.println(0);
                    return;
                }
                if (a[i] == a[i + 1]) {
                    r[i] = Math.min(r[i], a[i]);
                } else {
                    r[i] = Math.min(r[i], a[i]);
                    l[i] = Math.max(l[i], a[i]);
                }
            }
            long res = 1;
            int mod = 1000000007;
            for (int i = 0; i < n; ++i) {
                res *= Math.max(0, r[i] - l[i] + 1);
                res %= mod;
            }
            out.println(res);

        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

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

    }

}


Measured memory_bytes: 33004
ll=gets.to_i
arr1=gets.split.map(&:to_i)
arr2=gets.split.map(&:to_i)


i=0
max=arr2.inject(:+)+arr1[0]
arr=[max]

(ll-1).times{
    
    arr<<arr[i]-arr2[i]+arr1[i+1]
    
    
    
    
    
  
   i+=1 
}

puts arr.max

Measured memory_bytes: 1788
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
#define DBG(X) cout << #X << "=" << (X) << '\n';
#define SAY(X) cout << (X) << '\n';
#else
#define DBG(X)
#define SAY(X)
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

const int NIL = -1;
static mt19937 _g(time(nullptr));

std::string pad(int num)
{
    char buffer[4];
    std::snprintf(buffer, sizeof(buffer), "%03d", num);
    return buffer;
}

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

#ifdef _MSC_VER
#  include <intrin.h>
#  define __builtin_popcount __popcnt
#endif

string solve()
{
    int a , b , c, d;

    std::cin >> a >> b >> c >> d;

    while (a > 0 && c > 0) {
        c -= b;

        if (c <= 0)
            return "Yes";

        a -= d;

        if (a <= 0)
            return "No";
    }

    return "";
}

int main()
{
    std::cout << solve() << std::endl;
//    solve();

    return 0;
}

Measured memory_bytes: 3636
#include<stdio.h>


int main()
{
	int a, b, con = 0;
	scanf("%d%d", &a, &b);
	for (int i = 1; i <= a; i++)
	{
		for (int j = 1; j <= 31; j++)
		{
			if (i == j) con++;
			if (i == a && j == b) break;
		}
	}
	printf("%d\n", con);
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
typedef long long ll;

using ipair = pair<int, int>;

ll INF = 1e16+7;

bool operator>(const ipair a,const ipair b){return a.first > b.first;}



int main(){
  map<string, int> mp;

  int N;
  cin >> N;
  rep(i, N){
    string s;
    cin >> s;
    mp[s]++;
  }
  int M;
  cin >> M;
  rep(i, M){
    string t;
    cin >> t;
    mp[t]--;
  }

  int ans = 0;
  for(pair<string, int> p: mp){
    ans = max(ans, p.second);
  }

  cout << ans << endl;

  return 0;
}


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


int main(){
    string str; cin >> str;
    string ans = "";
    rep(i, str.length()){
        if(str[i] == 'B'){
            if(ans.length() != 0) ans.pop_back();
        }else ans.push_back(str[i]);
    }
    cout << ans << endl;
}

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

int max(int a, int b) {
    return a > b ? a : b;
}

int min(int a, int b) {
    return a < b ? a : b;
}

int main(int argc, const char * argv[]) {
    // insert code here...
    int W, H, N;
    cin >> W >> H >> N;
    int left = 0;
    int right = W;
    int down = 0;
    int up = H;
    for (int n = 1; n <= N; n++) {
        int x, y, a;
        cin >> x >> y >> a;
        if (a == 1)
            left = max(left, x);
        if (a == 2)
            right = min(right, x);
        if (a == 3)
            down = max(down, y);
        if (a == 4)
            up = min(up, y);
    }
    int result;
    if (left >= right || up <= down)
        result = 0;
    else
        result = (right - left) * (up - down);
    cout << result << endl;
    return 0;
}

Measured memory_bytes: 256
while 1:
	ans = 0
	try: l=list(map(int,input().split(',')))
	except: break
	s2,s1=l.pop(),l.pop()
	t=sum(l)/(s1+s2)
	x=s1*t
	for i in range(10):	
		ans = ans + l[i]
		if ans >= x: break
	print(i+1)


Measured memory_bytes: 5600
#include<iostream>
using namespace std;
int main()
{
	int n;cin>>n;
	int x=n%10;
	if(x==2||x==4||x==5||x==7||x==9) cout<<"hon";
	else if(x==0||x==1||x==6||x==8) cout<<"pon";
	else cout<<"bon";
}

Measured memory_bytes: 3060
import sys
A = input()
B = input()
C = input()
A = list(A)
A.append("end")
B = list(B)
B.append("end")
C = list(C)
C.append("end")
i = 1
j = 0
k = 0
cur = A[0]
while i < len(A) and j < len(B) and k < len(C) :
    if cur == "a":
        cur = A[i]
        if cur == "end":
            print("A")
            sys.exit()
        i += 1
    elif cur == "b":
        cur = B[j]
        if cur == "end":
            print("B")
            sys.exit()
        j += 1
    elif cur == "c":
        cur = C[k]
        if cur == "end":
            print("C")
            sys.exit()
        k += 1

Measured memory_bytes: 3064
#include <stdio.h>
#define STOI(a) ((a-'1')+1)
#define SUM(a,b) (a+b)
int main(void){
    char x[1001];
    int res[1000]={0},su=0,n=0,i=0,j;
    while(1){
        n=0, su=0;
        scanf("%s",x);
        if(x[0]=='0' && x[1]==NULL) break;
        while(1){
            if (x[n] == NULL) break;
            su=SUM(su,STOI(x[n]));
            n++;
        }
        res[i]=su, i++;
    }
    for(j=0;j<i;j++) printf("%d\n",res[j]);
    return 0;
}


Measured memory_bytes: 2100
import java.util.Scanner;

public class Main{
	public static void main(String [] args){
		Scanner sc = new Scanner(System.in);
		String input = sc.nextLine();
		String work = "";
		for(int i = 0; i < input.length(); i++){
			work = input.substring(i,i+1);
			if(Character.isUpperCase(work.charAt(0))){
				System.out.print(work.toLowerCase());
			}else{
				System.out.print(work.toUpperCase());
			}
		}
		System.out.println("");
	}
}

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

int main() {
  char c;
  cin >> c;
    if ( c == 'a' || c== 'e' || c=='i' ||c== 'o' || c=='u'){
      cout << "vowel"<<endl;
    }
    else {
      cout << "consonant"<<endl;
    }
  
}


Measured memory_bytes: 256
<?php /*atcoder.php*/

$at = new Atcoder();
$at->main();
unset($at);

class Atcoder{
	private function lineIn(){
		$buf = fgets(STDIN);
		return $this->killNewLine($buf);
	}
	private function killNewLine($buf = null){
		$buf = str_replace("\r\n", "", $buf);
		$buf = str_replace("\n", "", $buf);
		$buf = str_replace("\r", "", $buf);
		return $buf;
	}

	public function main(){
		$s = $this->lineIn();
		
		switch ($s){
			case ("ooo"):
				echo "1000\n";
			break;
			case ("oox"):
			case ("oxo"):
			case ("xoo"):
				echo "900\n";
			break;
			case ("oxx"):
			case ("xox"):
			case ("xxo"):
				echo "800\n";
			break;
			case ("xxx"):
				echo "700\n";
			break;
			default:
				echo "700\n";
			break;
		}
	}
}
?>


Measured memory_bytes: 3828
n = input()
l = ["0"]*3
l[0] = "9" if n[0] == "1" else "1"
l[1] = "9" if n[1] == "1" else "1"
l[2] = "9" if n[2] == "1" else "1"
r = "".join(l)
print(r)


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

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

  multiset<long> buy;
  for(int i=0; i<n; i++){
    long a;
    cin >> a;
    buy.insert(a);
  }
  for(int i=0; i<m; i++){
    long tmp;
    tmp = *(--buy.end()) / 2;
    buy.erase(--buy.end());
    buy.insert(tmp);
  }
  unsigned long sum = 0;
  for(auto itr = buy.begin(); itr != buy.end(); ++itr){
    sum += *itr;
  }
  cout << sum << endl;
}

Measured memory_bytes: 4992
let () =
  let s = read_line () in
  Array.init (String.length s) (fun i -> s.[i])
  |> Array.to_list
  |> List.sort compare
  |> ( = ) ['a'; 'b'; 'c']
  |> (function true -> "Yes" | false -> "No")
  |> print_endline 


Measured memory_bytes: 384
#include <iostream>
#include <stdio.h>

using namespace std;

int main() {

	double r;
	double menseki, enshu;

	cin >> r;

	menseki = 3.141592653589*r*r;
	enshu = 2 * 3.141592653589*r;

	printf("%.6lf %.6lf\n", menseki, enshu);

	return 0;

}

Measured memory_bytes: 3192
N,M=map(int,input().split())
words=[[] for _ in range(N)]
for _ in range(M):
    p,S=input().split()
    p=int(p)-1
    words[p].append(S)
AC=0
WA=0
for a in words:
    if a.count('WA') != 0 and len(a) == a.count('WA'):
        continue
    for b in a:
        if b=='AC':
            AC+=1
            break
        elif b=='WA':
            WA+=1
print(AC,WA)


Measured memory_bytes: 58016
// ????¨??????????

#include <cstdio>
#include <cmath>

typedef long long ll;

ll F0[100], X0[100], Y0[100], A0[100], T0[100];

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

    for(int i=0;i<N;i++){
        scanf("%lld %lld %lld %lld %lld", F0+i, A0+i, T0+i, X0+i, Y0+i);
    }

    ll longest[2] = {-1, -1}, shortest[2] = {-1, -1};
    for(int i=0;i+1<N;i++){
        if(T0[i] != T0[i+1] || A0[i] == A0[i+1]){continue;}

        ll df = F0[i+1] - F0[i],
            dx = X0[i+1] - X0[i],
            dy = Y0[i+1] - Y0[i],
            dist2 = dx * dx + dy * dy;

        if(dist2 > longest[T0[i]]){
            longest[T0[i]] = dist2;
            shortest[T0[i]] = df;
        }else if(dist2 == longest[T0[i]] && df < shortest[T0[i]]){
            shortest[T0[i]] = df;
        }
    }

    for(int i=0;i<2;i++){
        if(longest[i] == -1){
            puts("-1 -1");
        }else{
            printf("%.6f %.6f\n", std::sqrt(longest[i]), 1. * shortest[i] / 60);
        }
    }

}

Measured memory_bytes: 1060
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define RT return
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;

int N;
ll K;
const int MA = (int)2e5 + 1;
int kth[MA], A[MA], from, to, loopID;
vi pos[MA];
vi ans;

pii f(int id, int k) {
    auto it = lower_bound(all(pos[A[id]]), id + 1);
    if (it == pos[A[id]].end()) {
        id = pos[A[id]][0] + 1;
        k++;
    } else {
        id = *it + 1;
    }
    if (id == N) {
        id = 0;
        k++;
    }
    return { id,k };
}

void jump(int id, int k) {
    if (kth[id] != -1) {
        from = kth[id];
        to = k;
        loopID = id;
        return;
    }
    kth[id] = k;

    int next_id, next_k;
    tie(next_id, next_k) = f(id, k);
    jump(next_id, next_k);
}

void g(int id, int k, int length) {
    if (k >= length)return;
    
    int next_id, next_k;
    tie(next_id, next_k) = f(id, k);
    if (next_k >= length && (next_id != 0 || next_k != length)) {
        ans.push_back(A[id]);
        if (++id == N) {
            id = 0;
            k++;
        }
        g(id, k, length);
    } else {
        g(next_id, next_k, length);
    }
}

void solve() {
    MEM(kth, -1);

    cin >> N >> K;
    rep(i, N) {
        cin >> A[i];
        pos[A[i]].push_back(i);
    }

    jump(0, 0);
    assert(loopID == 0);

    g(0, 0, (int)(K%to));
    rep(i, sz(ans)) {
        cout << ans[i] << (i == sz(ans) - 1 ? '\n' : ' ');
    }
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}

Measured memory_bytes: 16248
import java.util.*;

public class Main {
    public static void main(String... args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int n = Integer.valueOf(s);
        int cnt = 0;
        for (int i = 0 ; i < s.length() ; i++) {
            cnt += Character.getNumericValue(s.charAt(i));
        }
        System.out.println(n % cnt == 0 ? "Yes" : "No");
    }
}

Measured memory_bytes: 23252
#include <algorithm>
#include <cstdint>
#include <iostream>
#include <string>
#include <vector>
#include <unordered_map>
#include <set>

using namespace std;

int main() {  
  int64_t N;
  cin >> N;
  if (N < 3) {
    cout << 0 << endl;
    return 0;
  }
  vector<int64_t> bars(N);
  for (int64_t n = 0; n < N; ++n) {
    cin >> bars[n];
  }
  sort(bars.begin(), bars.end());
  int64_t res = 0;
  for (size_t i = 0; i < N - 2; ++i) {
    for (size_t j = i + 1; j < N - 1; ++ j) {
      if (bars[i] == bars[j]) continue;
      for (size_t k = j + 1; k < N; ++k) {
        if (bars[j] == bars[k]) continue;
        if (bars[i] + bars[j] > bars[k]) {
          ++res;
        }
      }
    }
  }
  
  cout << res << endl;

  return 0;
}


Measured memory_bytes: 3640
n,m = list(map(int,input().split()))
a = [0]*m
for i in range(m):
    a[i] = int(input())
dp = [0]*(n+2)
for i in a:
    dp[i] = -1
dp[0] = 1

for i in range(n):
    if dp[i]<0:
        continue
    dp[i] %= 10**9+7
    if dp[i+1]>=0:
        dp[i+1] += dp[i]
    if dp[i+2]>=0:
        dp[i+2] += dp[i]
print(dp[n]%(10**9+7))

Measured memory_bytes: 7668
// "include" {{{
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
#include <iomanip>
#include <tuple>
// }}}

using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define pii pair<int,int> 
#define int long long
#define setout(n,x) setw(n) << setfill(x)
#define Fixed fixed << setprecision(10)
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const long long mod = 1e9+7;

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

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,a,b;
	cin >> n >> a >> b;
	vector<int> x(n);
	rep(i,n){
		cin >> x[i];
	}
	int sum = 0;
	reps(i,n-1){
		sum += min((x[i]-x[i-1]) * a,b);
	}
	cout << sum << '\n';
	return 0;	
}


Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <climits>
#include <cassert>
#include <algorithm>
#include <utility>

using namespace std;
using Int = long long int;
using UInt = unsigned long long int;
using VI = vector<long long int>;
using VVI = vector<vector<long long int> >;

struct Coord {
    Int x;
    Int y;
};
double CalcDist(Coord first, Coord second);
double CalcDistSum(vector<Coord>& coords, vector<Int>& coordId);
Int Factorial(Int n);


void PermutationLoop(Int n, vector<Coord>& coords) {
    vector<Int> v(n);
    for (Int i = 0; i < n; ++i) {
        v[i] = i;
    }

    //double (*const calcDistSum[])(vector<Coord>&, vector<Int>&) = {CalcDistSum}; // 関数ポインタ
    /*
    // 関数オブジェクト(ラムダ式使用) ver.1
    auto calcDistSum = [&coords, &v]() {
        return CalcDistSum(coords, v);
    };
    */
    // 関数オブジェクト(ラムダ式使用) ver.2
    auto calcDistSum = [&v](vector<Coord>& coords) {
        return CalcDistSum(coords, v);
    };

    double sum = 0;
    do {
        //sum += calcDistSum[0](coords, v); // 関数ポインタ
        //sum += calcDistSum(); // 関数オブジェクト ver.1
        sum += calcDistSum(coords); // 関数オブジェクト ver.2
    } while (std::next_permutation(v.begin(), v.end()));
    cout << fixed << setprecision(10) << sum / (double)Factorial(n) << endl;
    return;
}


int main(void) {
    Int n;
    cin >> n;
    vector<Coord> coords(n);
    for (Int i = 0; i < n; ++i) {
        cin >> coords[i].x >> coords[i].y;
    }
    PermutationLoop(n, coords);
    return 0;
}

double CalcDist(Coord first, Coord second) {
    return sqrt((first.x - second.x) * (first.x - second.x) + (first.y - second.y) * (first.y - second.y));
}
double CalcDistSum(vector<Coord>& coords, vector<Int>& coordId) {
    Int size = (Int)coordId.size();
    double ret = 0;
    for (Int i = 0; i < size - 1; ++i) {
        ret += CalcDist(coords[coordId[i]], coords[coordId[i + 1]]);
    }
    return ret;
}
Int Factorial(Int n) {
    if (n == 1) {
        return 1;
    } else {
        return n * Factorial(n - 1);
    }
}



Measured memory_bytes: 3768
#include <iostream>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <vector>
#include <utility>
#include <numeric>
#include <string>
#include <set>
#include <map>
#include <tuple>
#include <queue>
#include <stack>
#include <deque>
#define rep(i, a, n) for(int (i) = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int (i) = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int (i) = (int)(a);(x);++(i))
#define repr(i, a, n) for(int (i) = (int)(a);(i) > (int)(n);--(i))
#define reper(i, a, n) for(int (i) = (int)(a);(i) >= (int)(n);--(i))
#define SIZE(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define RNG(x, n) &((x)[0]), &((x)[n])
#define ADD(a, b) ((((a)%MOD)+((b)%MOD))%MOD)
#define MUL(a, b) ((((a)%MOD)*((b)%MOD))%MOD)
#define FLOOR(x) ((int)floor(((double)x)))
#define CEIL(x) ((int)ceil(((double)x)))
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl;
#define no cout << "no" << endl;
#define fcout cout << fixed << setprecision(10)
#define pb push_back
#define pf push_front
#define mt make_tuple
#define fi first
#define se second
#define EPS (1e-20)
#define INF 2147483647
#define MOD 1000000007
using llint = long long;
using VI = std::vector<int>;
using PII = std::pair<int, int>;
using SI = std::set<int>;
using MII = std::map<int, int>;
using TIII = std::tuple<int, int, int>;
using VLL = std::vector<llint>;
using MCI = std::map<char, int>;
using namespace std;


int N, M;
int p[100010];
int par[100010];


int root(int x){
	if(par[x] == -1) return par[x] = x;
	if(par[x] == x) return x;
	return par[x] = root(par[x]);
}


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


void unite(int x, int y){
	 x = root(x);
	 y = root(y);
	 if(x == y) return;
	 par[x] = y;
}


int solve(){
	int ans = 0;
	rep(i, 0, N)
		if(same(i, p[i])) ans++;
	return ans;
}


signed main(){
	cin >> N >> M;
	fill(RNG(par, N), -1);
	rep(i, 0, N) cin >> p[i], p[i]--;
	rep(i, 0, M){
		int x, y;
		cin >> x >> y, x--, y--;
		unite(x, y);
	}

	cout << solve() << endl;

	return 0;
}

Measured memory_bytes: 1152
#include <algorithm>
#include <cstdint>
#include <iostream>
#include <vector>

using namespace std;

int main()
{
    int64_t n, m;
    cin >> n >> m;
    vector<pair<int64_t, int64_t>> vs(n);
    for (auto& v : vs)
    {
        cin >> v.first >> v.second;
    }
    sort(vs.begin(), vs.end());

    int64_t sum = 0;
    int64_t num = 0;
    for (auto v : vs)
    {
        int64_t buy_num = min(v.second, m - num);
        sum += buy_num * v.first;
        num += buy_num;
        if (num == m)
        {
            break;
        }
    }
    cout << sum << endl;
}

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

#define H 500000

void maxHeapify(int *, int);
void buildMaxHeap(int *);

int h;

int main(){

  int A[H];
  int i;

  scanf("%d",&h);
  if(h>H) exit(0);

  
  for(i=1; i<=h ; i++){

    scanf("%d",&A[i]);
  }


    buildMaxHeap(A);
  

 for(i=1; i<=h ; i++){
   printf(" %d",A[i]);
 }

 printf("\n");

  return 0;
}

void maxHeapify(int *A, int i){
  int l,r,largest,temp;

  l=i*2;
  r=i*2+1;

  if(l<=h && A[l]>A[i])largest = l;
  else largest = i;

  if(r<=h && A[r]>A[largest]) largest=r;

  if(largest != i){
    temp = A[i];
    A[i] = A[largest];
    A[largest] = temp;

    maxHeapify(A, largest);  
  }

}


void buildMaxHeap(int *A){
  int i;

  for(i=h/2 ; i>=1 ; i--){
    maxHeapify(A, i);
  }
}

Measured memory_bytes: 2552
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <map>
const int MOD = 1e9+7;
typedef long long ll;
using namespace std;

char get_max(string t){
	int temp = 0;
	string s = "abcdefghijklmnopqrstuvwxyz";
	for (int i = 0; i < t.length(); i++){
		for (int j = 0; j < s.length(); j++){
			if (t[i] == s[j]) temp = max(temp, j);
		}
	}
	return s[temp];
}

int main(){
	int n;
	cin >> n;
	string s = "abcdefghijklmnopqrstuvwxyz";
	vector<string> num[11];
	num[1].push_back("a");
	for (int i = 2; i <= n; i++){
		for (int k = 0; k < num[i-1].size(); k++){
			for (int j = 0; j < i; j++){
				if (get_max(num[i-1][k]) + 2 == s[j]) break;
				num[i].push_back(num[i-1][k]+s[j]);
			}	
		}
	}
	for (int j = 0; j < num[n].size(); j++){
			cout << num[n][j] << endl;
		}
	return 0;
 }



Measured memory_bytes: 9588
/* ＵＴＦ－８ */
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <array>
#include <queue>
#include <stack>
#include <algorithm>
#include <tuple>
#include <numeric>
#include <type_traits>
#include <limits>

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>

#define USE_COLORED 1

#ifdef USE_COLORED
static const char stdout_pre[]  = "\033[1m"; // bold black
static const char stderr_pre[]  = "\033[31;1m"; // bold red
static const char stdxxx_post[] = "\033[m";

// 当然ながら GCC(g++)/libstdc++ 依存
#include <ext/stdio_filebuf.h>
using stdio_filebuf = __gnu_cxx::stdio_filebuf<char>;
class colored_stdio_filebuf : public stdio_filebuf {
private:
	const char* const pre_;
	const char* const post_;

public:
	colored_stdio_filebuf(FILE* fp, const char* pre, const char* post) : stdio_filebuf(fp, std::ios_base::out), pre_(pre), post_(post)
	{
	}

protected:
	std::streamsize xsputn(const char* s, std::streamsize count) override
	{
		stdio_filebuf::xsputn(pre_, strlen(pre_));
		auto ret = stdio_filebuf::xsputn(s, count);
		stdio_filebuf::xsputn(post_, strlen(post_));
		return ret;
	}
};
#endif

int main()
{
#ifdef USE_COLORED
	if (getenv("DEBUG")) {
		std::cout.rdbuf(new colored_stdio_filebuf(stdout, stdout_pre, stdxxx_post));
		std::cerr.rdbuf(new colored_stdio_filebuf(stderr, stderr_pre, stdxxx_post));
	} else
#endif
	{
		int fd = open("/dev/null", O_WRONLY);
		dup2(fd, 2);
		close(fd);
	}
	
	std::string s1, s2, s3;
	std::cin >> s1 >> s2 >> s3;
	std::cout << (char)toupper(s1[0]) << (char)toupper(s2[0]) << (char)toupper(s3[0]) << "\n";
}


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

template<class Monoid>
class SegmentTree {

public:
    /**
     * @param N size
     * @param e identity element
     * @param operation operation to merge `data`
     * @param updater operation to update `data`
     */
    SegmentTree(size_t N, Monoid e, function<Monoid(Monoid, Monoid)> operation,
                function<Monoid(Monoid, Monoid)> updater)
            : e(e), operation(operation), updater(move(updater)) {
        n = 1;
        while (n < N) {
            n *= 2;
        }
        data = vector<Monoid>(2 * n - 1, e);
        for (int i = n - 2; i >= 0; i--) {
            data[i] = operation(data[2 * i + 1], data[2 * i + 2]);
        }
    }

    /**
     * iの値をxに更新 ( 0-indexed )
     */
    void update(int i, Monoid x) {
        i += n - 1;
        data[i] = updater(data[i], x);
        while (i > 0) {
            i = (i - 1) / 2;
            data[i] = operation(data[i * 2 + 1], data[i * 2 + 2]);
        }
    }

    /**
     * [a, b)の区間でクエリを実行
     */
    Monoid query(int a, int b) {
        return query(a, b, 0, 0, n);
    }

    /**
     * 添字でアクセス( 0-indexed )
     */
    Monoid operator[](int i) {
        return data[i + n - 1];
    }

private:
    int n;
    vector<Monoid> data;
    Monoid e;
    function<Monoid(Monoid, Monoid)> operation;
    function<Monoid(Monoid, Monoid)> updater;

    Monoid query(int a, int b, int k, int l, int r) {
        // 交差しない
        if (r <= a || b <= l) return e;
        // 区間 [a, b) に l, r が含まれる
        if (a <= l && r <= b) return data[k];
        // 左の子
        Monoid c1 = query(a, b, 2 * k + 1, l, (l + r) / 2);
        // 右の子
        Monoid c2 = query(a, b, 2 * k + 2, (l + r) / 2, r);
        return operation(c1, c2);
    }
};

void Main() {
    ll N, L;
    cin >> N >> L;
    SegmentTree<ll> segmentTree(N, INF, [](ll a, ll b) { return min(a, b); }, [](ll a, ll b) { return b; });
    rep(i, N) {
        ll a;
        cin >> a;
        segmentTree.update(i, a);
    }
    rep(i, N - L + 1) {
        ll ans = segmentTree.query(i, i + L);
        cout << ans;
        if (i != N - L) {
            cout << ' ';
        }
    }
    cout << '\n';
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}



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

enum {A, B, C, ACT_N};

constexpr int MAX_N = 1e5;

int dp[MAX_N][ACT_N];

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

  cin >> dp[0][A] >> dp[0][B] >> dp[0][C];

  for (int i{1}; i < N; ++i) {
    int a, b, c;
    cin >> a >> b >> c;
    dp[i][A] = a + max(dp[i-1][B], dp[i-1][C]);
    dp[i][B] = b + max(dp[i-1][C], dp[i-1][A]);
    dp[i][C] = c + max(dp[i-1][A], dp[i-1][B]);
  }

  cout << max({dp[N-1][A], dp[N-1][B], dp[N-1][C]}) << endl;
  return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define srt(x) sort((x).begin(), (x).end());
#define rsrt(x) sort((x).rbegin(), (x).rend());
#define deb(x) cout<<#x<<" = "<<(x)<<" (L"<<LINE<<")"<<endl;
#define vdeb(x) {cout<<#x<<" = { "; rep(i, x.size()) cout<<x[i]<<' '; cout <<'}'<<" (L"<<LINE<<")"<<endl;}
using namespace std;
using ll = long long;
using vi = vector<int>;
using vivi = vector<vi>;
using vll = vector<long long>;
using vllvll = vector<vll>;
using vs = vector<string>;
using um = unordered_map<long long, long long>;

int main()
{
    ll X;
    cin >> X;
    ll R = 3000;
    for (ll i = -R; i <= R; ++i) {
        for (ll j = -R; j <= R; ++j) {
            if (i*i*i*i*i - j*j*j*j*j == X) {
                cout << i << ' ' << j << endl;
                goto end;
            }
        }
    }
end:
    ;
}

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

int main(){
	// sengen
	int h,a;
	// nyuryoku
	cin >> h >> a;
	// keisan
	if(h%a == 0){
		cout << h/a;
	}else{
		cout << h/a + 1;
	}
	// syutsuryoku
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define pow(x,y) modpow(x,y)
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REPS(i,n) for(ll (i)=1;(i)<=(n);(i)++)
#define RREP(i,n) for(ll (i)=(n-1);(i)>=0;(i)--)
#define RREPS(i,n) for(ll (i)=(n);(i)>0;(i)--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());

template <class T = int>T in(){
    T x;
    cin >> x;
    return (x);
}

template<class T> inline void chmin(T& a, T b){
    if (a > b){
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b){
    if (a < b){
        a = b;
    }
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    int N = in();
    vector<int> A(N);
    REP(i,N){
        A[i] = in();
    }
    sort(ALL(A));
    UNIQUE(A);
    cout << (N - A.size() ? "NO" : "YES") << "\n";
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <utility>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define mp make_pair
typedef long long Int;

int n, a[16];

Int pack(int *a) {
    Int b = 0;
    rep (i, n) b = b*16+a[i];
    return b;
}

void unpack(Int b, int *a) {
    rep (i, n) {
        a[n-1-i] = b%16;
        b /= 16;
    }
}

int solve() {
    static int b[16];
    queue<pair<int, Int> > q;
    const Int beg = pack(a);
    rep (i, n) b[i] = i+1;
    const Int end = pack(b);
    map<Int, int> rt;
    q.push(mp(0, beg));
    rt[beg] = 0;
    while (!q.empty()) {
        pair<int, Int> vv = q.front();
        q.pop();
        unpack(vv.second, b);
        if (vv.first <= 3) rep (i, n) rep (j, i) {
            reverse(b+j, b+i+1);
            const Int p = pack(b);
            if (rt.count(p) == 0) {
                if (vv.first < 3) q.push(mp(vv.first+1, p));
                rt[p] = vv.first+1;
            }
            reverse(b+j, b+i+1);
        }
    }
    set<Int> vis;
    q.push(mp(0, end));
    while (!q.empty()) {
        pair<int, Int> vv = q.front();
        q.pop();
        if (vis.count(vv.second)) continue;
        vis.insert(vv.second);
        if (rt.count(vv.second)) return vv.first+rt[vv.second];
        unpack(vv.second, b);
        rep (i, n) rep (j, i) {
            reverse(b+j, b+i+1);
            q.push(mp(vv.first+1, pack(b)));
            reverse(b+j, b+i+1);
        }
    }
    return -1;
}

int main() {
    scanf("%d", &n);
    rep (i, n) scanf("%d", a+i);
    printf("%d\n", solve());
    return 0;
}

Measured memory_bytes: 206036
//ツ暗。ツつ、ツづァツつオツつ「
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <utility>
using namespace std;
struct road{
	int a,b,l;
	road(int a_,int b_,int l_):a(a_),b(b_),l(l_){}
};
typedef pair<int,int> pii;
int main(){
	int n,m,k,a,b,l,s;
	vector<road> rd;
	vector<pii> town[3001];
	int len[3001];
	priority_queue<pii,vector<pii>,greater<pii> > qu;
	int inf = 1e9;

	for(cin>>n>>m>>k;m--;rd.push_back(road(a,b,l))){
		cin>>a>>b>>l;
		town[a].push_back(make_pair(b,l));
		town[b].push_back(make_pair(a,l));
	}
	for(;k--;qu.push(make_pair(0,s)))
		cin>>s;

	for(fill(len,len+n+1,-1);!qu.empty();){
		pii pi = qu.top();
		qu.pop();
		if( len[pi.second] == -1 ){
			len[pi.second] = pi.first;
			for(
				vector<pii>::iterator it=town[pi.second].begin();
				it != town[pi.second].end();
				++it
			){
				qu.push(make_pair(pi.first+it->second,it->first));
			}
		}
	}
	
	s=0;
	for(vector<road>::iterator it = rd.begin(); it != rd.end();	++it ){
		s = max(max( s, len[a] ),
				max( len[b], (len[it->b] + it->l - len[it->a] + 1)/2 + len[it->a] )
		);
	}
	cout << s << endl;
}

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

int main(){
    int N[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int K;
    cin >> K;
    cout << N[K-1] << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include<cstdio>
#include<string>
#include<vector>
using namespace std;
int main() {
	int n, kkk;
	cin >> n >> kkk;
	long long int b[51][9][4] = { 0 };
	long long int x[105] = { 0 }, y[105] = { 0 }, z[105] = { 0 };
	for (int i = 0; i < n; i++) {
		int x1, y1, d1, x2, y2, d2;
		cin >> x1 >> y1 >> d1 >> x2 >> y2 >> d2;
		x[i * 2] = x1;
		x[i * 2 + 1] = x2;
		y[i * 2] = y1;
		y[i * 2 + 1] = y2;
		z[i * 2] = d1;
		z[i * 2 + 1] = d2;
		for (int j = 0; j < 8; j++) {
			if (j == 0 || j == 2 || j == 3 || j == 6) {
				b[i][j][0] = x1;
			}
			else {
				b[i][j][0] = x2;
			}
			if (j == 0 || j == 1 || j == 3 || j == 5) {
				b[i][j][1] = y1;
			}
			else {
				b[i][j][1] = y2;
			}
			if (j == 0 || j == 1 || j == 2 || j == 4) {
				b[i][j][2] = d1;
			}
			else {
				b[i][j][2] = d2;
			}
		}
	}
	for (int i = 0; i < 2 * n; i++) {
		for (int j = 2*n - 1; j > i; j--) {
			if (x[j] < x[j - 1]) {
				swap(x[j], x[j - 1]);
			}
			if (y[j] < y[j - 1]) {
				swap(y[j], y[j - 1]);
			}
			if (z[j] < z[j - 1]) {
				swap(z[j], z[j - 1]);
			}
		}
	}
	
	long long int ts = 0;
	for (int i = 0; i < 2*n -1; i++) {
		for (int j = 0; j < 2 * n -1; j++) {
			for (int k = 0; k < 2 * n-1 ; k++) {
				int ae = 0;
				for (int l = 0; l < n; l++) {
					if (b[l][0][0] <= x[i] && b[l][7][0] >= x[i + 1]) {
						if (b[l][0][1] <= y[j] && b[l][7][1] >= y[j + 1]) {
							if (b[l][0][2] <= z[k] && b[l][7][2] >= z[k + 1]) {
								ae++;
								if (ae == kkk) {
									ts += (x[i + 1] - x[i])*(y[j + 1] - y[j])*(z[k + 1] - z[k]);
									break;
								}

							}
						}

					}

				}
			}
		}
	}
	cout << ts << endl;
	return 0;
}

Measured memory_bytes: 3112
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <chrono>
#include <random>

const int INF = 1000000009;
const long LINF = 1123456789012345678;

const long MOD = 1000000007;

long n, m;
std::map<long, long> fac;
long ans = 1;

/* * * * */
/*  nCr  */
/* * * * */

//mod MOD

//nCr = ((factorial[n] % MOD) * modinv[r] % MOD) * modinv[n-r] % MOD;

long N = 300010; // N = 300010, change on your own
long factorial[300010];//[i]: i!
long modinv[300010];//[i]: 1/(i!) mod MOD


//power, num1^num2
long power(long num1, long num2){
	if(num2 == 1){
		return num1 % MOD;
	}else if(num2 % 2){
		return num1 * power(num1, num2-1) % MOD;
	}else{
		long result = power(num1, num2/2);
		return result * result % MOD;
	}
}

	

	

int main(){
	factorial[0] = 1;
	factorial[1] = 1;
	for(long i = 2; i <= N; i++){
		factorial[i] = factorial[i-1] * i % MOD;
	}
	for(int i = 0; i <= N; i++){
		modinv[i] = power(factorial[i], MOD-2);
	}
	scanf("%ld %ld", &n, &m);
	long b = 2;
	while(b*b <= m){
		if(m%b == 0){
			fac[b] = fac[b] + 1;
			m /= b;
		}else{
			b++;
		}
	}
	if(m != 1){
		fac[m] = fac[m] + 1;
	}
	//nCr = ((factorial[n] % MOD) * modinv[r] % MOD) * modinv[n-r] % MOD;
	long p = 1;
	do{
		//printf("  ans:%ld\n", ans);
		p = fac.upper_bound(p)->first;
		long b = fac[p];
		//printf("%ld %ld\n", p, b);
		//printf("  %ld\n", ((factorial[n+b-1] % MOD) * modinv[b] % MOD) * modinv[n-1] % MOD);
		ans *= ((factorial[n+b-1] % MOD) * modinv[b] % MOD) * modinv[n-1] % MOD;
		ans %= MOD;
	}while(fac.upper_bound(p) != fac.end());
	printf("%ld\n", ans);
	/*
	for(int i = 1; i < 100; i++){
		printf("%d %d\n", i, fac[i]);
	}
	//*/
	return 0;
}


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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,a=0,b=0,mi=1000000;
	string s;
	cin>>n>>s;;
	if(n==2){
		if(s.substr(0,1)=="W" && s.substr(1,1)=="E"){
			cout<<1<<endl;
		}else{
			cout<<0<<endl;
		}return 0;
	}
	vector<pair<int,int>>v(n);
	for(int i=0;i<n;i++){
		if(s[i]=='W'){
			a++;
		}else {
			b++;
		}
		v.at(i).first=a;
		v.at(i).second=b;
	}
	for(int i=0;i<n-1;i++){
		if(i==0){
			if(v.at(0).second==1){
				mi=b-1;
			}else if(v.at(0).second==0){
				mi=b;
			}
		}else{
			mi=min(v.at(i-1).first+b-v.at(i).second,mi);
		}
	}
	if(s.substr(n-1,1)=="W")a--;
	mi=min(a,mi);
	cout<<mi<<endl;
	return 0;
}


Measured memory_bytes: 2964