akhauriyash/Code-Regression huggingface dataset:
using System;

class A{
    static int top;
    static int[] s = new int[300];
    public static void Main() {
        string[] Stack = Console.ReadLine().Split(' ');
        foreach(string d in Stack) {
            int i;
            if (int.TryParse(d,out i)) {
                Push(i);
            } else {
                int a = Pop();
                int b = Pop();
                switch (d) {
                    case "+": {                            
                        Push(a+b);
                        break;
                    }
                    case "-": {
                        Push(b-a);
                        break;
                    }
                    case "*": {
                        Push(a*b);
                        break;
                    }
                    default: {
                        Console.Error.WriteLine("Can't Calcurate");
                        break;
                    }
                }
            }
        }
        Console.WriteLine(s[top]);
    }

    public static void Push(int x) {
        if (top > s.Length) {
            Console.Error.WriteLine("Stack OverFlow");
        }
        top++;
        s[top] = x;
    }

    public static int Pop() {
        if (top < 0) {
            Console.Error.WriteLine("Stack UnderFrow");
        }
        top--;
        return s[top + 1];
    }

}


Measured memory_bytes: 9232
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i, m, n) for (ll i = (ll)(m); i <= (ll)(n); i++)
#define FOR0(i, n) for (ll i = 0; i < (ll)(n); i++)
#define FOR1(i, n) for (ll i = 1; i <= (ll)(n); i++)

const ll MOD = 1000000007, Max = 200000;

ll power(ll a, ll b)
{
    ll res = 1;
    while (b > 0)
    {
        if (b & 1)
            res = (res * a) % MOD;
        a = (a * a) % MOD;
        b >>= 1;
    }
    return res;
}

int abs(int n)
{
    if (n >= 0)
        return n;
    else
        return -n;
}

int main()
{
    ll inv[Max + 1];
    FOR(i, 1, Max)
    {
        inv[i] = power(i, MOD - 2);
    }
    ll B, W;
    cin >> B >> W;
    ll S = B + W;

    ll b1[W + 1];
    ll w1[B + 1];
    b1[0] = 1;
    w1[0] = 1;
    FOR(i, 1, W)
    {
        b1[i] = (b1[i - 1] * (B - 1 + i)) % MOD;
        b1[i] = (b1[i] * inv[i]) % MOD;
    }
    FOR(j, 1, B)
    {
        w1[j] = (w1[j - 1] * (W - 1 + j)) % MOD;
        w1[j] = (w1[j] * inv[j]) % MOD;
    }
    // b1[i]=(B-1+i)Ci,w1[j]=(W-1+j)Cj
    ll b2[W + 1];
    ll w2[B + 1];
    b2[0] = power(2, B - 1);
    w2[0] = power(2, W - 1);
    FOR(i, 1, W)
    {
        b2[i] = (2 * b2[i - 1] - b1[i - 1] + MOD) % MOD;
    }
    FOR(j, 1, B)
    {
        w2[j] = (2 * w2[j - 1] - w1[j - 1] + MOD) % MOD;
    }
    // b2[i]=(B-1+i)C0+...+(B-1+i)C(B-1),w2[j]=(W-1+j)C0+...+(W-1+j)C(W-1)
    ll p1[B + W + 1];
    p1[0] = 1;
    FOR(i, 1, B + W)
    {
        p1[i] = (p1[i - 1] * 2) % MOD;
    }
    ll p2[B + W + 2];
    p2[0] = 1;
    FOR(i, 1, B + W + 1)
    {
        p2[i] = (p2[i - 1] * inv[2]) % MOD;
    }
    ll q[B + W + 1];
    ll r[B + W + 1];
    FOR(i, 1, B + W)
    {
        if (i <= B)
        {
            q[i] = p1[i - 1];
        }
        else
        {
            q[i] = b2[i - B];
        }
    }
    FOR(j, 1, B + W)
    {
        if (j <= W)
        {
            r[j] = p1[j - 1];
        }
        else
        {
            r[j] = w2[j - W];
        }
    }
    ll x[B + W + 1], y[B + W + 1], ans[B + W + 1];
    FOR(i, 1, B + W)
    {
        x[i] = p2[i];
        y[i] = (p1[i - 1] + q[i] - r[i] + MOD) % MOD;
        ans[i] = (x[i] * y[i]) % MOD;
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 17792
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

int main() {
 ll n;
  cin>>n;
  int m;
 ll c[12];rep(i,0,12) c[i]=0;
  rep(i,0,12){
   c[i]=n%26;
    
    if(c[i]==0&&n>0)c[i]=26;
    n=n-c[i];
    n/=26;
   // cout<<n<<endl;
    
  }
  
  string ans="";
  rep(i,0,12){
    if(c[i]>=1 &&c[i]<=26)
   ans+=c[i]+122-26; 
  }
  reverse(all(ans));
  cout<<ans<<endl;
  
  //rep(i,0,12) cout<<c[i]<<endl;
}



Measured memory_bytes: 3600
from fractions import gcd

lcm = lambda a, b: a * b // gcd(a, b)

N, M, *A = map(int, open(0).read().split())

Y = A[0]
for a in A[1:]:
    Y = lcm(a, Y)

if any((Y // a) % 2 == 0 for a in A):
    print(0)
    quit()

print(M // (Y // 2) - (M // Y))

Measured memory_bytes: 16088
#include <stdio.h>
int main(){
    int k = 0 ;
    
    scanf("%d",&k);
    
    int a = 0;
    a = k/2;
    
    if(k % 2 == 1)
    {
        printf("%d\n",a*(a+1));
        return 0;
    }
    else
    {
        printf("%d\n",a*a);
        return 0;
    }
}

Measured memory_bytes: 128
mod = 10**9+7

n,m = map(int, input().split())
a = sorted(map(int, input().split()), reverse=True) + [0]
b = sorted(map(int, input().split()), reverse=True) + [0]

ans = 1
# a,bのindexはしゃくとりのように一方向
ai = 0
bi = 0
for i in range(n*m, 0, -1):
    if a[ai] > i or b[bi] > i:
        ans = 0
        break
    tmp = 1
    if i == a[ai] and i == b[bi]:
        # 1通り
        ai += 1
        bi += 1
    elif i == a[ai]:
        tmp = bi
        ai += 1
    elif i == b[bi]:
        tmp = ai
        bi += 1
    else:
        tmp = ai*bi - (n*m - i)
        if tmp < 0:
            ans = 0
            break
    ans *= tmp
    ans %= mod

print(ans)

Measured memory_bytes: 3188
def solve(s):
    n = len(s)
    w = [0]*n
    e = [0]*n

    for i in range(1, n):
        w[i] = w[i-1] + (s[i-1]=="W")
    for i in range(n-2, -1, -1):
        e[i] = e[i+1] + (s[i+1]=="E")

    tot = [x+y for x, y in zip(w, e)]
    return min(tot)


input()
print(solve(input()))

Measured memory_bytes: 39200
#include<bits/stdc++.h>
using namespace std;
string s, t;

void print(int i, int j, vector<vector<int>>& dp) {
    if (i == 0 || j == 0) return;
    if (dp[i][j] == dp[i - 1][j]) print(i - 1, j, dp);
    else if (dp[i][j] == dp[i][j - 1]) print(i, j - 1, dp);
    else {
        print(i - 1, j - 1, dp);
        cout << s[i - 1];
    }
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

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

    cin >> s >> t;
    int n = s.size();
    int m = t.size();

    vector<vector<int>> dp(n + 1, vector<int>(m + 1));
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= m; j++) {
            if (i == 0 || j == 0) dp[i][j] = 0;
            else if (s[i - 1] == t[j - 1]) dp[i][j] = dp[i - 1][j - 1] + 1;
            else dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
        }
    }

//    cout << dp[n][m] << '\n';

    print(n, m, dp);
    cout << '\n';
}


Measured memory_bytes: 35712
import collections 
import numpy

def main():
	n, m = list(map(int,input().split()))
	xs = [0] + list(map(int,input().split()))

	cums = [x % m for x in numpy.cumsum(xs)]
	cnt = collections.Counter(cums)

	print(sum([cnt[x] * (cnt[x] - 1) // 2 for x in cnt]))

if __name__ == '__main__':
	main()

Measured memory_bytes: 26736
# -*- coding: utf-8 -*-
# kakomon toku
import math
import sys
import itertools
import numpy as np

n = int(input())
x = [int(i) for i in input().split()]

y = np.argsort(x)
x = np.sort(x)
#print(y)
a=[0]*n
for i in range(n//2):
    a[y[i]] = 1 # a[]=1ならば前半にいる
#print(a)
for i in range(n):
    if a[i] == 1 :
        print(x[n//2])
    else:
        print(x[n//2-1])



Measured memory_bytes: 34204
#include<stdio.h>
#include<algorithm>
using namespace std;
int a[100005];
int main(){
	int n,i;
	while(scanf("%d",&n)!=EOF){
		for(i=0;i<n;i++)
			scanf("%d",&a[i]);
		long long sum=0,ans1=0,ans2=0;
		for(i=0;i<n;i++){
			sum+=a[i];
			if((i%2&&sum>=0)||(!(i%2)&&sum<=0)){
				ans1+=abs(sum)+1;
				sum=(i%2)?-1:1;
			}
		}
		sum=0;
		for(i=0;i<n;i++){
			sum+=a[i];
			if((i%2&&sum<=0)||(!(i%2)&&sum>=0)){
				ans2+=abs(sum)+1;
				sum=(i%2?1:-1);
			}
		}
		printf("%lld\n",min(ans1,ans2));
	}
	return 0;
} 

Measured memory_bytes: 512
L = input()
MOD = 10**9 + 7

eq = 1
less = 0
for n in L:
    if n == '1':
        eq, less = eq * 2, eq + less * 3
    else:
        less = less * 3
    eq %= MOD
    less %= MOD

print((eq + less) % MOD)


Measured memory_bytes: 3188
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	C_fix
# CreatedDate:  2020-08-08 21:55:54 +0900
# LastModified: 2020-08-08 22:01:55 +0900
#


import os
import sys
# import numpy as np
# import pandas as pd
from itertools import permutations


def main():
    n = int(input())
    p = list(map(int, input().split()))
    q = list(map(int, input().split()))
    permu = list(map(list, permutations(range(1, n+1))))
    for index, per in enumerate(permu):
        if per == p:
            a = index
        if per == q:
            b = index
    print(abs(a-b))


if __name__ == "__main__":
    main()


Measured memory_bytes: 14408
//include
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;

// conversion
inline int
toInt(string s)
{
    int v;
    istringstream sin(s);
    sin >> v;
    return v;
}
template <class T>
inline string toString(T x)
{
    ostringstream sout;
    sout << x;
    return sout.str();
}

//change
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return true;
    }
    return false;
}

//math
template <class T>
inline T sqr(T x) { return x * x; }

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

//container util
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())

//repetition
#define FOR(i, a, b) for (int i = (a); i <= (int)(b); ++i)
#define REP(i, n) FOR(i, 0, n)

//constant
constexpr double EPS = 1e-10;
const double PI = acos(-1.0);
constexpr LL INF = 1e10;

//clear memory
#define CLR(a) memset((a), 0, sizeof(a))

//debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;

int main()
{
    string S;
    cin >> S;
    char a;
    a = S[0];
    char b = '!';
    int cnta = 0, cntb = 0;
    for (int i = 0; i < 4; ++i)
    {
        if (S[i] == a)
        {
            ++cnta;
            //dump(i);
            //dump(cnta);
        }
        else if (b == '!' && S[i] != a)
        {
            b = S[i];
            ++cntb;
            //dump(i);
            //dump(cntb);
            //dump(b);
        }
        else if (S[i] == b)
        {
            ++cntb;
            //dump(i);
            //dump(cntb);
        }
        else if (S[i] != b)
        {
            //dump(i);
            cout << "No" << endl;
            return 0;
        }
    }
    //dump(cnta);
    //dump(cntb);
    if (cnta == 2 && cntb == 2)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}

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

using namespace std;

int main() {
    long long a, b, c;
    
    scanf("%lld %lld %lld", &a, &b, &c);
    
    if (a % 2 == 0 || b % 2 == 0 || c % 2 == 0) {
        puts("0");
    } else {
        printf("%lld\n", min(a * b, min(b * c, c * a)));
    }
    
    return 0;
}


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

uint64_t modpow(uint64_t a, uint64_t p, const uint64_t& mod)
{
  if (p == 0) return 1;
  if (p % 2 == 0) {
    uint64_t h = modpow(a, p / 2, mod);
    return h * h % mod;
  } else {
    return a * modpow(a, p - 1, mod) % mod;
  }
}

uint64_t combination(uint64_t a, uint64_t b, const uint64_t& mod)
{
  if (a - b < b) return combination(a, a - b, mod);
  uint64_t ansmul = 1;
  uint64_t ansdiv = 1;
  for (uint64_t i = 0; i < b; i++) {
    ansmul *= a - i;
    ansdiv *= i + 1;
    ansmul %= mod;
    ansdiv %= mod;
  }
  uint64_t ans = ansmul * modpow(ansdiv, mod - 2, mod) % mod;
  return ans;
}

int main()
{
  const uint64_t mod = 1'000'000'007;
  uint64_t n, m;
  cin >> n >> m;
  uint64_t mm = m;
  uint64_t ans = 1;
  for (auto i = 2; i * i <= mm; i++) {
    if (mm % i == 0) {
      uint64_t count = 0;
      while (mm % i == 0) {
	count++;
	mm /= i;
      }
      ans *= combination(n + count - 1, count, mod);
      ans %= mod;
    }
  }
  if (mm != 1) {
    ans *= n;
    ans %= mod;
  }
  cout << ans << endl;
}


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

int main(){
    int n,k;
    cin >> n >> k;
    vector<int> x(n);
    for(int i=0; i<n; i++){
        cin >> x.at(i);
    }
    int comp = INT_MAX;
    int sum = 0;
    for(int i=0; i<=n-k; i++){
        
        if(abs(x.at(i+k-1)) + abs(x.at(i)-x.at(i+k-1)) < abs(x.at(i)) + abs(x.at(i)-x.at(i+k-1)) ){
            sum = abs(x.at(i+k-1)) + abs(x.at(i)-x.at(i+k-1));
        }else{
            sum = abs(x.at(i)) + abs(x.at(i)-x.at(i+k-1));
        }
        if(comp > sum){
            comp = sum;
        }
        sum = 0;
    }
    cout << comp << endl;
}

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

int main(){
  int k;
  cin >> k;
  string s;
  cin >> s;
  
  if(s.size() <= k){
    cout << s;
  }else{
  	for(int i = 0; i < k; i++){
      cout << s[i];
    }
    cout << "...";
  }
}

Measured memory_bytes: 3632
using System;

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

        string[] numbers = Console.ReadLine().Split();

        for ( int i = numbers.Length - 1; i > 0; --i ) {
            Console.Write( numbers[ i ] + " " );
        }

        Console.WriteLine( numbers[ 0 ] );
    }
}

Measured memory_bytes: 8772
A, B = list(map(int, input().split()))
a = []
b = []
ans = []
for i in range(1,1300):
  if(i*8//100 == A):
    a.append(i)
for i in range(1,1100):
  if(i*10//100 == B):
    b.append(i)
for i in range(len(a)):
  for j in range(len(b)):
    if(a[i] == b[j]):
      ans.append(b[j])
if(len(ans)==0):
  print(-1)
else:
  print(min(ans))

Measured memory_bytes: 3064
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define E "\n"

using namespace std;
const long long MOD = (long long)1e9 + 7;

long long n;

int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n;
	int cnt = 0;
	long long cur = 26, acc = 0, pre = 0;
	while (1) {
		pre = acc;
		acc = pre + cur;
		cur = cur * 26;
		cnt++;
		if (acc >= n) break;
	}
	n -= pre; n--;
	long long tmp = 1;
	for (int i = 0; i < cnt - 1; i++) tmp *= 26;
	for (int i = 0; i < cnt; i++) {
		int x = n / tmp;
		char c = 'a' + x;
		cout << c;
		n -= x * tmp;
		tmp /= 26;
	}
	cout << E;
	//system("pause");
	return 0;
}

Measured memory_bytes: 3688
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stdio.h>
#include <cmath>
#include <cctype>


using namespace std;

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

    int a = floor(log(n) / log(k));

    cout << a+1 << endl;

    return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a.at(i);
  map<int, int64_t> m;
  for (int i = 0; i < n; i++) {
    m[a.at(i)]++;
  }
  int64_t s = 0;
  for (auto x : m) {
    s += x.second * (x.second - 1) / 2;
  }
  for (int i = 0; i < n; i++) {
    cout << s - m[a.at(i)] + 1 << "\n";
  }
}


Measured memory_bytes: 10240
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.IO;

namespace AtCoder
{
    class Program
    {
        private const int M = 1000000007;
        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        private static long Solve(int N, long[] A)
        {
            long[] sums = new long[N];
            sums[0] = A[0];
            for (int i = 1; i < N; ++i) { sums[i] = sums[i - 1] + A[i]; }
            long min = long.MaxValue;
            for (int i = 0; i < N - 1; ++i)
            {
                min = Math.Min(Math.Abs(sums[N - 1] - sums[i] * 2), min);
            }
            return min;
        }
        static void Main(string[] args)
        {
            int N = ReadInt();
            long[] A = ReadLongs();
            Console.WriteLine(Solve(N, A));
        }
    }
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, pair<ll, ll> > P3;

const ll MOD = ll(1e9 + 7);
const ll LLINF = LLONG_MAX;
const int IINF = INT_MAX;
const int MAX_N = int(3e5) + 5;
const double EPS = 1e-8;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
string dir = "RDLU";
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define SORT(v) sort((v).begin(), (v), end())
#define SORTR(v) sort((v).rbegin(), (v), rend())
#define ALL(v) (v).begin(), (v).end()


int main() {
    int n, m, x, y, xmax = -1000, ymin = 1000;
    cin >> n >> m >> x >> y;
    REP(i,n){
        int a;
        cin >> a;
        xmax = max(xmax,a);
    }
    REP(i,m){
        int a;
        cin >> a;
        ymin = min(ymin,a);
    }
    if(xmax<ymin && x<ymin && xmax<y){
        cout << "No War" << endl;
    }
    else {
        cout << "War" << endl;
    }
    return 0;
}


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

const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (2e18)
#define PI (acos(-1))
#define EPS (1e-7)

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

int main(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << max(max((ll)a*c, (ll)a*d), max((ll)b*c, (ll)b*d)) << endl;
    return 0;
}


Measured memory_bytes: 3608
n = int(input())
a = list(map(int, input().split()))
b = []
total = 0
x = 0

while 1:
    cnt = 0
    for i in a:
        if i%2==0:
            a[cnt]=i/2
            cnt += 1
        else:
            x += 1
            break
    if x!=0:
        break
    total += 1

print(total)

Measured memory_bytes: 3064
# coding: utf-8
# Your code here!

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

tree = [[] for i in range(n)]

for _ in range(n-1):
    a,b = map(int,input().split())
    tree[a-1].append(b-1)
    tree[b-1].append(a-1)

kouho = [0]
used_tree = [0 for i in range(n)]
used_tree[0] = 1
ans = k
while kouho:
    head = kouho.pop()
    if head == 0:
        start = k-1
    else:
        start = k-2
    for tail in tree[head]:
        if used_tree[tail] == 0:
            ans *= start
            ans %= 1000000007
            start -= 1
            used_tree[tail] = 1
            kouho.append(tail)
print(ans)

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

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)
typedef long long ll;

using namespace std;

template <typename T> void output(T, int);
int gcd(int a, int b);
void prime_map(map<ll, ll> &, ll);

int main() {
    // source
    ll n, k;
    cin >> n >> k;
    ll a[n], b[n];
    rep(i, n) { cin >> a[i] >> b[i]; }
    vector<pair<ll, ll>> v(n);
    rep(i, n) { v[i] = make_pair(a[i], b[i]); }
    sort(v.begin(), v.end());

    ll num = 0;
    rep(i, n) {
        num += v[i].second;
        if (num >= k) {
            cout << v[i].first;
            break;
        }
    }
    return 0;
}

template <typename T> void output(T a, int precision) {
    if (precision > 0) {
        cout << setprecision(precision) << a << "\n";
    } else {
        cout << a << "\n";
    }
}

template <typename T> T min(T a, T b) {

    if (a < b) {
        return a;
    } else {
        return b;
    }
}

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

void prime_map(map<ll, ll> &m, ll num) {
    ll cache = num;
    repd(i, 2, sqrt(num) + 2) {
        if (num % i == 0) {
            if (m[i] == 0) {
                m[i] = 1;
            } else {
                m[i]++;
            }

            num /= i;
            break;
        }
    }

    if (cache == num) {
        if (m[num] == 0) {
            m[num] = 1;
        } else {
            m[num]++;
        }
        return;
    } else {
        prime_map(m, num);
    }
}


Measured memory_bytes: 3328
n = int(input())
A = list(map(int, input().split()))
import collections
c = collections.Counter(A)

M = 0
N = 0
for x in c.items():
    if x[1] >= 4 and x[0] > M:
        M = x[0]
        N = x[0]
    elif x[1] >= 2 and x[0] > M:
        N = M
        M = x[0]
    elif x[1] >= 2 and x[0] > N:
        N = x[0]
 
print(M*N)

Measured memory_bytes: 18316
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7

N = i()
A = l()
L = []
L2 = [0]*(10**6)
for i in range(N):
    if i+A[i]+1 < 10**6:
        L.append(i+A[i]+1)
    if i-A[i]+1 >= 0 and i-A[i]+1 < 10**6:
        L2[i-A[i]+1] += 1
ans = 0
for l in L:
    ans += L2[l]
print(ans)

Measured memory_bytes: 117252
#include <bits/stdc++.h>
using namespace std;
long long t,ac=0,wa=0,tle=0,re=0;
string s;
main()
{
	cin>>t;
	for(int i=1; i<=t; i++)
	{
		cin>>s;
		if(s=="AC") ac++;
		if(s=="WA") wa++;
		if(s=="TLE") tle++;
		if(s=="RE") re++;
	}
cout<<"AC x "<<ac<<'\n';
	cout<<"WA x "<<wa<<'\n';
	cout<<"TLE x "<<tle<<'\n';
	cout<<"RE x "<<re<<'\n';
}

Measured memory_bytes: 3672
#include <iostream>
#define int long long
using namespace std;

int f(int a, int b) {
	return a * a * a * a * a - b * b * b * b * b;
}

signed main() {
	int x;
	cin >> x;
	
	//a = b + iとおく
	for (int i = 1; i <= 240; i++) {
		//f(b) = (b + i)^5 - b^5 (b:実数, i:非負整数)を考えると、b = -i / 2のとき最小値を取る. 
		//(wolfram alphaというサイトで計算）
		//また、b <= -i / 2の範囲ではbを小さくするほどf(b)は大きくなる。
		//b > -i / 2の範囲ではbを大きくするほどf(b)は大きくなる。
		
		//b <= -i / 2の範囲 (について、f(b) <= x (解説にならえば右辺は10^9としてもよい）となる最小のbまで探索
		//c++の場合、-5 / 2 = -2になるらしい。つまり(負の数) / (正の数)は「小数切り上げ」になってしまう。
		//今回は、小数を切り下げたいので、-(i + 1) / 2からスタートにする。i = 5のときはb = -3からスタートということ。
		for (int b = -(i + 1) / 2; ; b--) {
			int res = f(b + i, b);
			if (res > x) break;
			if (res == x) { cout << b + i << " " << b << endl; return 0; }
		}
		
		//b >= i / 2の範囲について、f(b) <= 10^9 (解説にならえば右辺は10^9としてもよい）となる最大のbまで探索
		for (int b = -(i + 1) / 2 + 1; f(b + i, b) <= x; b++) {
			cerr << b + i << ", " << b << endl;
			int res = f(b + i, b);
			if (res > x) break;
			if (res == x) { cout << b + i << " " << b << endl; return 0; }
		}
	}
	return 0;
}

Measured memory_bytes: 3192
a = list(map(int,input().split()))
b=a[0]
c=a[1]
d=a[2]
e=0
f=0
e = (b//(c+d))*c
f= b % (c+d)
if c<=f:
  e=e+c
else:
  e=e+f

print(e)

Measured memory_bytes: 3060
//"I'll live the focused life, because it's the best kind there is" - Winifred Gallagher
#include<bits/stdc++.h>
using namespace std;
#define debug(a) cout << #a << ": " << a << endl

int main(){
	cin.tie(0);	ios::sync_with_stdio(false);
	vector<vector<int>> a(3, vector<int>(3, 0));
	for(int i = 0; i < 3; i++){
		for(int j = 0; j < 3; j++){
			cin>>a[i][j];
		}
	}
	int n; cin>>n;
	set<int> set;
	for(int i =0; i < n; i++){
		int x; cin>>x;
		set.insert(x);
	}
	
	if(set.count(a[0][0]) && set.count(a[1][1]) && set.count(a[2][2])){
		puts("Yes");
		return 0;
	}
	else if(set.count(a[0][2]) && set.count(a[1][1]) && set.count(a[2][0])){
		puts("Yes");
		return 0;
	}
	else{
		for(int col = 0; col < 3; col++){
			if(set.count(a[0][col]) && set.count(a[1][col]) && set.count(a[2][col])){
				puts("Yes");
				return 0;
			}
		}
		for(int row = 0; row < 3; row++){
			if(set.count(a[row][0]) && set.count(a[row][1]) && set.count(a[row][2])){
				puts("Yes");
				return 0;
			}
		}
	}
	puts("No");
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <set>
#include <iomanip>
#include <stack>
#include <fstream>
#include <cstdint>
#include <cmath>
#include <algorithm>
#include <utility>
#include <numeric>
#include <functional>
using namespace std;

constexpr int INF       = 1000000000;/* 1e+9a */
constexpr int MODULO    = 1000000007;

#define int int64_t

#define REP(i,f,n) for(int i=(f); i < (n); ++i)
#define PER(i,f,n) for(int i=(n-1); i >= f; --i)

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

template<typename STL> inline void print_STL(STL c, string ab = ""){
	cout << ab << '\n';
	for(auto t : c) cout << t << ' '; cout << '\n';}

template<typename VEC> inline void import_VEC(VEC& c, int n){
	typename VEC::value_type tmp;
	for(int i = 0; i < n; ++i){	cin >> tmp; c.push_back(tmp);} }

#define SPRE(x) setprecision(x) // 精度を指定

template<class T>	using Matrix = vector<vector<T>>;

signed main()
{
	cin.tie(0);
    ios::sync_with_stdio(false);
	int n, a, b;
	vector<int> x;
	cin >> n >> a >> b;
	import_VEC(x, n);

	int ans = 0;
	REP(i, 1, n)
	{
		int wal = x[i] - x[i-1];
		wal *= a;
		ans += min(wal, b);
	}
	cout << ans << '\n';
}



Measured memory_bytes: 1528
#include <iostream>
#include <algorithm>
#include <string.h>
#include <vector>
#include <math.h>
#include <queue>

using namespace std;

#define int_ int64_t
#define pb push_back
#define mp make_pair
#define ll long long
#define ull unsigned ll
#define db double
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define PII pair<int, int>

const int N=200010;

int n,a[N];

int main()
{
    scanf("%d",&n);
    for (int i=0;i<n;i++) {
        scanf("%d",a+i);
        a[i]-=(i+1);
    }
    sort(a,a+n);
    int ele=a[n/2];
    ll ans=0;
    for (int i=0;i<n;i++) ans+=abs(a[i]-ele);
    printf("%lld\n",ans);
}



Measured memory_bytes: 1024
import java.util.*;
public class Main{   
    public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      long a = sc.nextLong();
      long b = sc.nextLong();
      System.out.println(lcm(a,b));
    }
    public static long lcm(long x, long y){
      return x*y/gcd(x,y);
    }
    public static long gcd(long x, long y){
      if(x < y)return gcd(y,x);
      if(y==0)return x;
      return gcd(y,x%y);
    }
}
class Pair{
    int a,b;

    Pair(int a, int b){
      this.a = a;
      this.b = b;
    }
}

Measured memory_bytes: 21844
import math
n=int(input())
xy=[]
for i in range(n):
  xy.append(list(map(int,input().split())))
a=0
for i in range(n):
  for j in range(n):
    a+=math.factorial(n-1)*(math.sqrt((xy[i][0]-xy[j][0])*(xy[i][0]-xy[j][0])+(xy[i][1]-xy[j][1])*(xy[i][1]-xy[j][1])))
print(a/math.factorial(n))

Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using static Exter;
using System.Linq;
#if DEBUG
#else
using console = System.Console;
#endif

public class App
{
    public static void Main(string[] args)
    {
var v = console.ReadLine().Select(s=>s=='1').Select((w,i)=>i%2==1?w:!w);
cout = Min(v.Count(c=>c),v.Count(c=>!c)).ToString();
    }
}
public static class Exter
{
    public static int Max(params int[] p)=>p.Max();
    public static long Max(params long[] p)=>p.Max();
    public static int Min(params int[] p)=>p.Min();
    public static long Min(params long[] p)=>p.Min();
    public static string cout
    {
        set
        {
            console.WriteLine(value);
        }
    }
    public static int[] readarr
    {
        get 
        {
            return console.ReadLine().Split().Select(s=>int.Parse(s)).ToArray();
        }
    }
}


#if DEBUG
public static class console
        {
            static int cursorLine = 0;
            static int cursorChar = 0;
            static readonly string[] cin = new string[]
            {
                "101011"
            };
            static public string ReadLine()
            {
                string tmp = cin[cursorLine].Substring(cursorChar);
                cursorLine++;
                cursorChar = 0;
                return tmp;
            }
            static public void WriteLine()
            {
                Console.WriteLine();
            }
            static public void WriteLine<T>(T input)
            {
                Console.WriteLine(input);
            }
            static public void Write<T>(T input)
            {
                Console.Write(input);
            }
            static public void WriteLine(string s,params object[] arr)
            {
                Console.WriteLine(s,arr);
            }
        }
#endif

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

void print(vector<int> &A, int n) {
    for(int i=0; i<n-1; ++i) {
        printf("%d ", A[i]);
    }
    printf("%d\n", A[n-1]);
}

void insertion_sort(vector<int> &A, int n) {

    for(int i=1; i<n; ++i) {
        int v = A[i];
        int j = i-1;
        while (j >= 0 && A[j] > v) {
            A[j+1] = A[j];
            j--;
        }
        A[j+1] = v;
        print(A, n);
    }
}


int main() {
    ios::sync_with_stdio(false);
    vector<int> A;
    int n, x;
    cin >> n;
    for(int i=0; i<n; ++i) {
        cin >> x;
        A.push_back(x);
    }
    print(A, n);
    insertion_sort(A, n);

    return 0;
}

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

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

  if (s.at(k-1) == 'A')
    s.at(k-1) = 'a';
  else if (s.at(k-1) == 'B')
    s.at(k-1) = 'b';
  else
    s.at(k-1) = 'c';

  cout << s << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <utility>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
using namespace std;
#define INF 1000000007
#define LINF 1000000000000000007
#define MOD 1000000007
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
#define MODE 1
#ifdef MODE
#define DEB(X) cout << #X << ": " << X << " ";
#define ARDEB(i, X) cout << #X << "[" << i << "]: " << X[i] << " ";
#define END cout << endl;
#else
#define DEB(X) \
    {          \
    }
#define ARDEB(i, X) \
    {               \
    }
#define END \
    {       \
    }
#endif
typedef pair<int, int> P;
struct edge{int to,cost;};
typedef long long ll;

int ans;
signed main(){

    int n;
    cin>>n;
    cout<<180*(n-2)<<endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
int main(){
	int n; 
	cin>>n; 
	bool app = true;
	for(int i=0;i<n;i++){
		int x; 
		cin>>x; 
		if(x%2==0){
			if(x%3!=0 and x%5!=0){
				app = false;
			}
		}
	}
	if(app)cout<<"APPROVED\n";
	else cout<<"DENIED\n";
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define REP(X, Y, Z) for (ll(X) = (Y); (X) < (Z); (X)++)
#define REV(X, Y, Z) for (ll(X) = (Y); (X) > (Z); (X)--)

using namespace std;
using ll = long long;
using dll = deque<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using usll = unordered_set<ll>;
using umll = unordered_map<ll, ll>;
using sll = stack<int>;
using vll = vector<ll>;
using vvll = vector<vll>;

constexpr ll kMod = 1e9 + 7;

ll gcd(ll a, ll b) {
  if (a < b) {
    return gcd(b, a);
  }
  ll c = a % b;
  while (c != 0) {
    a = b;
    b = c;
    c = a % b;
  }
  return b;
}

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

void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

int main() {
  init();

  ll K;
  string S;
  cin >> K >> S;

  if (S.size() <= K) {
    cout << S << endl;
    return 0;
  }
  cout << S.substr(0, K) << "..." << endl;


  return 0;
}


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

using namespace std;

#define pb push_back

long long n, a[100005], dp[100005], ans, sum, x;

int main() {

    cin >> n;

    for(int i = 1; i <= n; ++i){
        cin >> a[i];
        sum += a[i];
    }

    sort(a + 1, a + 1 + n);
    reverse(a + 1, a + 1 + n);
    dp[1] = 1;
    for(int i = 1; i <= n; ++i){
        if((sum - x) * 2 >= a[i - 1] && dp[i - 1]) dp[i] = 1;
        x += a[i];
        ans += dp[i];
    }

    cout << ans;

    return 0;

}


Measured memory_bytes: 1792
/*                                  /   \                                                                   (Hello)//JSM//*/      
/*                                 /*****\                                                                              */
/*     Jai Shree Mataji           /       \ |\| |_| $ |-| K                                                            */
#include<vector>
#include<iostream>
#include<algorithm>                
#include<string.h>                 
#include<bits/stdc++.h>            
#include<cstring>                  
#include<map>                     
#include<cmath>                  
#include<set>
using namespace std;            
#define ll long long int        
#define ld long double
#define MOD 1000000007 
#define PI 3.1415926535897932384626433832795                                               
#define YY cout<<"YES"
#define NN cout<<"NO"
#define EE cout<<"\n"
#define ee cout<<"\n"
#define ne cout<<"-1"
#define pb push_back 
#define fi first
#define se second
#define mkp make_pair    
#define mkt make_tuple
#define sall(v ) sort(v.begin(), v.end())      
#define all(v )  v.begin(), v.end()      
#define rall(v )  reverse(v.begin(), v.end())      
#define fo(i , n) for(ll i = 0 ; i < n ; i++)
#define vl vector<ll>
#define vll vector< pair<ll,ll> > 
#define mpl map<ll, ll>
#define pr pair<ll,ll>
#define tpl tuple<ll,ll,ll>
bool sortbysec(const pair<int,int> &a,const pair<int,int> &b) {return (a.second < b.second); }
ll soltn(ll x, ll n) {if(x>=0) return x%n;    else return n+x%n;}
ll pd(ll x,ll y){if(x%y==0) return x/y;else return x/y+1;}
ll coda(ll n,ll d){ll count=0;while(n!=0){if(n%10==d)count++;n/=10;}return count;}
ll pow1(ll n,ll p){if(p==0)return 1;ll x=pow1(n, p/2);x=(x*x)%MOD;if(p%2==0) return x;else return (x*n)%MOD;}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);	
	  ll t=1;
      
//	   cin>>t;

	      while(t--)
{
/*
5
6 9 12 10 8*/
ll n,m,j,k,l,i;
cin>>n;
ll a[n],s=0;
fo(i,n)
{
	cin>>a[i];
	s+=a[i];
}
ll ini=0;
ll f=1;
ll N=((n)*(n+1))/2;
if(s%N!=0)
f=-1;
ini=(s/N);
fo(i,n)
{
	ll p=ini-(a[(i+1)%n]-a[i]);
	if(p<0||p%n!=0)
	f=-1;
}
if(f==1||n==1)
YY;
else
NN;
ee;
}
return 0;
}














Measured memory_bytes: 4400
#include <bits/stdc++.h>
#define LINF 1001001001001001001
typedef long long ll;
using namespace std;
int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < n; i++) {
		a[i] -= i + 1;
	}
	sort(a.begin(), a.end());
	int b;
	if (n % 2 == 0) {
		b = (a[n / 2] + a[n / 2 - 1]) / 2;
	} else {
		b = a[n / 2];
	}
	ll ans = 0;
	for (int j = 0; j < n; j++) {
		ans += abs(a[j] - b);
	}
	cout << ans << endl;
	return 0;
}

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

int main(){
    vector<int> vec(5);
    vector<int> vec2(5);
    int i,j;
    int t;
    int c=0;
    int c2=0;
    for(int i=0;i<5;i++){
        cin >> vec.at(i);
    }
    for(i=0;i<5;i++){
    if(vec.at(i)%10==0){
            vec2.at(i)=10;
        }
    else vec2.at(i)=vec.at(i)%10;
    }    
     for(i=0;i<4;i++){
        for(j=4;j>0;j--){
    /*    if(vec2.at(j)==0) {
            vec2.at(i)=0;
            break;    
        } */   
        if(vec2.at(j)<vec2.at(j-1)){
            t=vec2.at(j);
            vec2.at(j)=vec2.at(j-1);
            vec2.at(j-1)=t;
        }    
        }
    }
   /* for(i=0;i<5;i++){
        cout << vec2.at(i) <<" "<< endl;
    }*/
    for(i=0;i<5;i++){
        if(i==0) continue;
    c+=10-vec2.at(i);
    }
    for(i=0;i<5;i++){
        c2+=vec.at(i);
    }
    cout << c+c2 << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        if(N == M){
            System.out.println("Yes");
            return;
        }
        System.out.println("No");
    }
}


Measured memory_bytes: 21844
a=int(input())
b=list(map(int,input().split()))
counter=0
exist_odd=False
while True:
  count=0
  while count<=a-1:
    if b[count]%2==1:
      exist_odd=True
      break
    else:
      b[count]=b[count]//2
      count+=1
  if exist_odd:
    break
  else:
    counter+=1
print(counter)
    

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i = 0; i < (N); i++)
#define repo(i,N) for(int i = 1; i < (N); i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
//#define num 1000000007
#define pi acos(-1.0)
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//#define int long long


int main() {
  int a,b;
  cin >> a >> b;
  
  cout << (a<=8 && b<=8?"Yay!":":(") << endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LL long long
#define M 1000005 
using namespace std;
const int P=1e9+7; 
int  A[M];
int main(){
	int n,m;
	cin>>n;
	for(int i=1;i<=n;i++)scanf("%d",&A[i]),A[i]<<=1;
	LL a=A[1],b=-1;
	for(int i=2;i<n;i++){
		a=A[i]-a;
		b*=-1;
	}
	LL x1=(A[n]-a)/(b+1);
	printf("%lld",x1);
	for(int i=1;i<n;i++){
		x1=A[i]-x1;
		printf(" %lld",x1);
	}
	puts("");
	return 0;
}

Measured memory_bytes: 1664
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;

int main() {
	long long N,P;

	cin>>N>>P;

	vector<pair<long long,int>>prime;
	for (long long i = 2; i*i <= P; i++)
	{
		if (P%i == 0)
		{
			int cnt = 0;
			while (P%i == 0)
			{
				P/=i;
				cnt++;
			}

			prime.push_back(make_pair(i, cnt));
		}	
	}
	if(P != 1)prime.push_back(make_pair(P, 1));

	long long ans = 1;
	for (int i = 0; i < prime.size(); i++)
	{
		ans *= pow(prime[i].first, floor(prime[i].second/N));
	}

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

Measured memory_bytes: 512
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define pq priority_queue<ll>
#define pqg priority_queue<ll,vector<ll>,greater<ll>>
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end())
// #define int ll
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const ll mod = 998244353;
const ll MAX = 1100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[4] ={1,0,-1,0} , dy[4] ={0,1,0,-1};
 
 
struct Timer{
    chrono::system_clock::time_point start, end;
    Timer(){ start = chrono::system_clock::now(); }
    ~Timer(){
        end = chrono::system_clock::now();
        auto msec = chrono::duration_cast<chrono::milliseconds>(end - start).count();
        cerr<<"time : "<<msec<<" ms"<<endl;
    }
};
 
 
 
 
ll n;
ll a[200010]={};
ll cnt[200010]={};
vll G[200010];
ll ans[200010]={};
 

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Timer TM;
    

    ll n;
    ll ans=0;
    string s;
    unordered_map<string,ll> mp;
    cin>>n>>s;
    rep(bit,(1<<n)){
        string u="",t="";
        rep(i,n){
            if(bit&(1<<i)){
                u+=s[i];
            }
            else t+=s[i];
        }
        mp[u+'0'+t]++;
        // cout<<u+'0'+t<<endl;
    }
    rep(bit,(1<<n)){
        string u="",t="";
        rep(i,n){
            if(bit&(1<<i)){
                u=s[i+n]+u;
            }
            else t=s[i+n]+t;
        }
        if(mp[t+'0'+u]>0) ans+=mp[t+'0'+u];
    }
    cout<<ans<<endl;

    
    return 0;
}

Measured memory_bytes: 78196
L, R = map(int, input().split())
ans_l = []
if R-L<2019:
    for i in range(L,R):
        for j in range(i+1,R+1):
            ans = (i*j)%2019
            ans_l.append(ans)
    print(min(ans_l))
else:
    print(0)

Measured memory_bytes: 75332
#include<bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define vii vector<pair<int, int> >
#define fi first
#define se second
int x[100005];
int sps[100005][20];
signed main()
{
	int n, q, L;
	cin>>n;
	for(int i=1; i<=n; i++)
	{
		cin>>x[i];
//		for(int d=0; d<=19; d++) sps[i][d]=n+1;
	}
	cin>>L>>q;
	int p=n;
	for(int i=n; i>=1; i--)
	{
		while(x[p]-x[i]>L) p--;
		sps[i][0]=p;
//		cout<<i<<" "<<p<<endl;
	}
	for(int d=1; d<=19; d++)
	{
		for(int i=1; i+(1<<d)<=n; i++)
			sps[i][d]=sps[sps[i][d-1]][d-1];
	}
	while(q--)
	{
		int l, r, ans=0;
		cin>>l>>r;
		if(l>r) swap(l, r);
		for(int i=19; i>=0; i--)
		{
			if(sps[l][i]<r and sps[l][i]) 
			{
				l=sps[l][i];
				ans+=(1<<i);
			}
		}
		ans++;
		cout<<ans<<endl;
	}
}


Measured memory_bytes: 11756
N,M=map(int,input().split())
H=list(map(int,input().split()))
bads=set()
ans=N
for m in range(M):
  A,B=map(int,input().split())
  A-=1
  B-=1
  if A not in bads and H[A]<=H[B]:
    bads.add(A)
    ans-=1
  if B not in bads and H[A]>=H[B]:
    bads.add(B)
    ans-=1
print(ans)


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

int main() {
    int N; cin >> N;
    vector<string> W(N);
    for(int i=0; i<N; ++i) cin >> W[i];

    map<string, bool> m;
    m[W[0]] = true;
    for(int i=1; i<N; ++i) {
        if(m[W[i]] || W[i - 1].back() != W[i].front()) {
            cout << "No\n";
            return 0;
        }
        m[W[i]] = true;
    }
    cout << "Yes\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MAX_V 500
#define INF 1<<28
typedef pair<int,int> P;
struct edge{int to,cap,cost,rev;};

int V;
vector<edge> G[MAX_V];
int h[MAX_V];
int dist[MAX_V];
int prevv[MAX_V],preve[MAX_V];

void add_edge(int from,int to,int cap,int cost){
  G[from].push_back((edge){to,cap,cost,G[to].size()});
  G[to].push_back((edge){from,0,-cost,G[from].size()-1});
}

int min_cost_flow(int s,int t,int f){
  int res=0;
  fill(h,h+V,0);
  while(f>0){
    priority_queue<P,vector<P>,greater<P> > que;
    fill(dist,dist+V,INF);
    dist[s]=0;
    que.push(P(0,s));
    while(!que.empty()){
      P p=que.top();que.pop();
      int v=p.second;
      if(dist[v]<p.first) continue;
      for(int i=0;i<G[v].size();i++){
	edge &e=G[v][i];
	if(e.cap>0&&dist[e.to]>dist[v]+e.cost+h[v]-h[e.to]){
	  dist[e.to]=dist[v]+e.cost+h[v]-h[e.to];
	  prevv[e.to]=v;
	  preve[e.to]=i;
	  que.push(P(dist[e.to],e.to));
	}
      }
    }
    if(dist[t]==INF){
      return -1;
    }
    for(int v=0;v<V;v++) h[v]+=dist[v];

    int d=f;
    for(int v=t;v!=s;v=prevv[v]){
      d=min(d,G[prevv[v]][preve[v]].cap);
    }
    f-=d;
    res+=d*h[t];
    for(int v=t;v!=s;v=prevv[v]){
      edge &e=G[prevv[v]][preve[v]];
      e.cap-=d;
      G[v][e.rev].cap+=d;
    }
  }
  return res;
}

int main(){
  int e,f,u,v,c,d,i;
  cin>>V>>e>>f;
  for(i=0;i<e;i++){
    cin>>u>>v>>c>>d;
    add_edge(u,v,c,d);
  }
  cout << min_cost_flow(0,V-1,f) << endl;
  return 0;
}

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


int main(){
    bool ans = true;
    string S;
    cin >> S;
    for(int i = 0; i < S.size() / 2; i++){
        if(S[i] != S[S.size() - 1 - i]){
            ans = false;
            break;
        }
    }
    for(int i = 0; i < (S.size() - 1) / 4; i++){
        if(S[i] != S[S.size() / 2 - 1 - i]){
            ans = false;
            break;
        }
        if(S[S.size() / 2 + 1 + i] != S[S.size() - 1 - i]){
            ans = false;
            break;
        }
    }
    if(ans){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <map>
#include <algorithm>

template<long long sieve_N, long long prime_N>
struct primes
{
	bool sieve[sieve_N];
	long long prime[prime_N];
	long long counter;
	constexpr primes() : sieve(), prime()
	{
    	counter = 0;
		for (long long i = 2; i < sieve_N; ++i)
		{
			sieve[i] = true;
		}
		sieve[0] = sieve[1] = false;
		for (long long i = 2; i < sieve_N; ++i)
		{
			if (sieve[i])
			{
				prime[counter] = i;
            	++counter;
				if (counter > prime_N)
				{
					break;
				}
			}
			for (long long j = i * i; j < sieve_N; j += i)
			{
				sieve[j] = false;
			}
		}
	}
};

primes<1000, 1000> Ps;

int main()
{
  long long N;
  scanf("%lld", &N);
  std::map<long long, long long> r;
  for (int i = 0; Ps.prime[i] <= N; ++i)
  {
    const long long p = Ps.prime[i];
    for (long long q = p; q <= N; q *= p)
    {
      r[p] += N / q;
    }
  }
  
  long long c3, c5, c15, c25, c75;
  c3 = c5 = c15 = c25 = c75 = 0;
  for (auto &p : r)
  {
    if (p.second >= 2) ++c3;
    if (p.second >= 4) ++c5;
    if (p.second >= 14) ++c15;
    if (p.second >= 24) ++c25;
    if (p.second >= 74) ++c75;
  }
  printf("%lld\n", c75 + c25 * std::max(c3 - 1, 0LL) + c15 * std::max(c5 - 1, 0LL) + c5 * std::max(c5 - 1, 0LL) / 2 * std::max(c3 - 2, 0LL));
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define sc scanf
#define pr printf
#define pb push_back
#define ll long long int
int main()
{
   int a,b,c,i;
   vector<int>v1;
   cin>>a>>b>>c;
   int x=min(a,b);
   for(i=1;i<=x;i++)
   {
       if(a%i==0 && b%i==0)
        v1.pb(i);
   }
   sort(v1.rbegin(),v1.rend());
   cout<<v1[c-1]<<endl;

   return 0;
}

Measured memory_bytes: 256