akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define in insert
#define er erase
#define fr first
#define sc second
typedef long long ll;
const long long llinf=LLONG_MAX;
const int inf=INT_MAX;
const int nmax=1e5+5;
const int mod=1e9+7;
using namespace std;
int n,i;
ll a[nmax],sum,z;
int main()
{
    //freopen("sol.in","r",stdin);
	//freopen("sol.out","w",stdout);
	ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
    cin>>n,z=1LL*n*(n+1)/2;
    for(i=0;i<n;i++)cin>>a[i],sum+=a[i];
    if(sum%z)rc("NO");
    sum/=z;
    a[n]=a[0];
    for(i=0;i<n;i++)if(a[i]-a[i+1]+sum<0 || (a[i]-a[i+1]+sum)%n)rc("NO");
	rc("YES");
}

Measured memory_bytes: 1152
using System;

namespace atcoder135
{
    class Program
    {
        static void Main(string[] args)
        {
            string nm = Console.ReadLine();
            long[,] dp = new long[nm.Length + 1, 13];
            dp[0, 0] = 1;

            for (int i = 1; i <= nm.Length; ++i)
            {
                if (nm[i - 1] == '?')
                    for (int d = 0; d < 10; ++d)
                    {
                        for (int j = 0; j < 13; ++j)
                        {
                            int md = (j * 10 + d) % 13;
                            dp[i, md] = (dp[i, md] + dp[i - 1, j]) % ((int)1e9 + 7);
                        }
                    }
                else
                {
                    for (int j = 0; j < 13; ++j)
                    {
                        int md = (j * 10 + nm[i - 1] - '0') % 13;
                        dp[i, md] = (dp[i, md] + dp[i - 1, j]) % (int)(1e9 + 7);
                    }
                }
            }
            Console.WriteLine(dp[nm.Length, 5]);
        }
    }
}


Measured memory_bytes: 21472
from itertools import combinations

# input
antennas = []
a_append = antennas.append
for i in range(5):
    a_append(int(input()))

k = int(input())

# check
pattern = list(combinations(antennas, 2))
max_len = max(
    [
        abs(i - j)
        for i, j in pattern
    ]
)
if max_len <= k:
    print("Yay!")
else:
    print(":(")

Measured memory_bytes: 3060
#include<cstdio>
#include<cstring>
const long long mod = 998244353;
char s[400];
long long f[400][400][400];
int count[400], sum[400];
long long preSum[400][400];
const int offset = 310;
long long diaSum[800][400];

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

void preWork(int p,int n,int m){
    for(int i = 0; i <= n; i++){
        preSum[i][0] = f[p][i][0];
        for(int j = 1; j <= m; j++){
            preSum[i][j] = preSum[i][j-1]+f[p][i][j];
            if(preSum[i][j]>=mod) preSum[i][j] -= mod;
        }
    }
    for(int i = -m; i <= n; i++){
        int pos = i+offset;
        if(i>=0) diaSum[pos][0] = f[p][i][0];
        else diaSum[pos][0] = 0;
        for(int j = 1; j <= m; j++){
            diaSum[pos][j] = diaSum[pos][j-1];
            int last = i+j;
            if(last<=n && last>=0) diaSum[pos][j] += f[p][last][j];
            if(diaSum[pos][j]>=mod) diaSum[pos][j] -= mod;
        }
    }
}

long long getPreSum(int i,int j,int n,int m){
    if(i>n) return 0;
    else{
        if(j>m) j = m;
        return preSum[i][j];
    }
}

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

long long getDiaSum(int i,int j,int n,int m){
    if(i>n || i<(-m)) return 0;
    else{
        if(j>m) j = m;
        return diaSum[i+offset][j];
    }
}

int main(){
    int m;
    scanf("%s%d",s+1,&m);
    int len = strlen(s+1);
    s[++len] = '0';
    int p = 1, size = 0;
    sum[0] = 0;
    while(p<=len){
        int np = p;
        while(s[np]!='0') np++;
        size++;
        count[size] = np-p;
        sum[size] = sum[size-1]+count[size];
        p = np+1;
    }
    //for(int i = 1; i <= size; i++) printf("%d ",count[i]);
    //printf("\n");
    m = min(301,m);
    f[0][0][0] = 1;
    preWork(0,m,sum[size]);
    for(int i = 1; i <= size; i++){
        for(int j = 0; j <= m; j++){
            for(int k = 0; k <= sum[size]; k++){
                f[i][j][k] = 0;
                if(k>=sum[i]){
                    if(k-count[i]>=0){
                        long long add = getDiaSum(j+count[i]-k,k-count[i],m,sum[size]);
                        f[i][j][k] = f[i][j][k] + add;
                        if(f[i][j][k]>=mod) f[i][j][k] -= mod;
                    }
                    if(count[i]!=0){
                        long long add = getPreSum(j,k,m,sum[size])-getPreSum(j,k-count[i],m,sum[size]);
                        if(add<0) add += mod;
                        f[i][j][k] = f[i][j][k] + add;
                        if(f[i][j][k]>=mod) f[i][j][k] -= mod;
                    }
                }
                //if(f[i][j][k]<0) printf("f[%d][%d][%d] = %lld\n",i,j,k,f[i][j][k]);
            }
        }
        preWork(i,m,sum[size]);
    }
    long long ans = 0;
    for(int i = 0; i <= m; i++) ans = (ans+f[size][i][sum[size]])%mod;
    printf("%lld\n",ans);
    return 0;
}

/*for(int l = 0; l <= k-count[i]; l++){
    int u = k-l;
    int lastJ = j-max(u-count[i],0);
    if(lastJ>=0) f[i][j][k] = (f[i][j][k] + f[i-1][lastJ][l])%mod;
}*/



Measured memory_bytes: 146924
#!/usr/bin/env python
import sys
import re
from collections import deque, defaultdict
from itertools import combinations, combinations_with_replacement
import bisect
from math import factorial, sqrt, log, ceil, floor
sys.setrecursionlimit(1000000)


def main():
    #N, M = map(int, input().split())
    #N, K = map(int, input().split())
    #ps = list(map(int, input().split()))

    N, W = map(int, input().split())

    dp = [defaultdict(int)]
    dp[0][0] = 0
    for i in range(N):
        w, v = map(int, input().split())
        keys = sorted(list(dp[i].keys()))
        new_dp = defaultdict(int)
        for key in keys:
            new_dp[key] = max([new_dp[key], dp[i][key]])
            new_w = key + w
            if new_w <= W:
                new_dp[new_w] = max([new_dp[new_w], dp[i][key] + v])

        max_value = 0
        for key in sorted(new_dp.keys()):
            if max_value > new_dp[key]:
                del new_dp[key]
            else:
                max_value = new_dp[key]

        dp.append(new_dp)
    print(max(dp[N].values()))


if __name__ == '__main__':
    main()


Measured memory_bytes: 79892
while(True):
    (H,W)=[int(s) for s in input().split()]
    if (H,W) == (0,0):
        break
    print("#"*W)
    for j in range(H-2):
        print("#",end="")
        print("."*(W-2),end="")
        print("#")
    print("#"*W)
    print("")

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

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

#define pb push_back
#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, n) for(int i = a; i < (n); i++)
#define mod (ll)(1e9+7)
#define int ll
#define INF 100000000

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}
int w, h, c;
int gcdd(int a, int b) {
  if(a % b == 0) return b;
    return gcdd(b, a % b);
}
int lcmm(int a, int b) {
  return a * b / gcdd(a, b);
}
signed main() {
	cin >> w >> h >> c;
  cout << lcmm(w, h) / gcdd(w, h) * c << endl;
	return 0;
}


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

int main(void){
    int n,cnt=0;
    cin >>n;
    int d[n]; 
    for (int i = 0; i < n; ++i) cin >> d[i]; 
    std::sort(d, d + n);
    cout << d[n/2]-d[n/2-1] << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;
#define fast() ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define digit(N) cout << fixed << setprecision((N))

// 𝑂(N log log N)
vector<bool> eratosthenes(int N)
{
    vector<int> res;
    vector<bool> prime(N + 1, 1);
    prime[0] = prime[1] = false;
    for (int i = 2; i * i <= N; ++i)
    {
        if (prime[i] == true)
        {
            for (int j = 2 * i; j <= N; j += i)
            {
                prime[j] = false;
            }
        }
    }
    return prime;
}

int a, D, N;

int main()
{
    auto prime = eratosthenes(1000000);
    while (cin >> a >> D >> N)
    {
        if(a == 0)
            return 0;
        int cnt = 0, num = a;
        if (prime[a])
            cnt++;
        while (cnt < N)
        {
            num += D;
            if (prime[num])
                cnt++;
        }
        cout << num << "\n";
    }
}


Measured memory_bytes: 3220
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;

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

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

int main() {
  ll N, K;
  cin >> N >> K;

  if (K == 0) {
    cout << N * N << endl;
    return 0;
  }

  ll ans = 0;
  repp(b, K + 1, N) {
    ans += (N / b) * (b - K);
    ll temp = N % b;
    ans += max(0LL, temp - K + 1);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import numpy as np
N,K = map(int,input().split())
h = np.array(list(map(int,input().split())))
dp = np.zeros(N, dtype=int)
for i in range(1,N):
    start = max(0,i-K)
    dp[i] = np.min(dp[start:i]+np.abs(h[i]-h[start:i]))
print(dp[N-1])

Measured memory_bytes: 22900
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;


namespace AtCoderWorkspace
{
    class Program
    {
        static void Main(string[] args)
        {
            var cin = new Scanner();
            var n = cin.nextInt();
            var a = cin.nextInt();
            var b = cin.nextInt();

            var d = n * a;
            var t = b;

            var ans = d <= t ? d : t;
                       
            Console.WriteLine(ans);
        }

       
    }

    public static class Combination
    {
        public static IEnumerable<T[]> Enumerate<T>(IEnumerable<T> items, int k, bool withRepetition)
        {
            if (k == 1)
            {
                foreach (var item in items)
                    yield return new T[] { item };
                yield break;
            }
            foreach (var item in items)
            {
                var leftside = new T[] { item };
                var unused = withRepetition ? items : items.SkipWhile(e => !e.Equals(item)).Skip(1).ToList();

                foreach (var rightside in Enumerate(unused, k - 1, withRepetition))
                {
                    yield return leftside.Concat(rightside).ToArray();
                }
            }
        }
    }

    class Point
    {
        public int x { get; set; }
        public int y { get; set; }
    }


    class Scanner
    {
        string[] s;
        int i;

        char[] cs = new char[] { ' ' };

        public Scanner()
        {
            s = new string[0];
            i = 0;
        }

        public string next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            if (s.Length == 0) return next();
            i = 0;
            return s[i++];
        }

        public int nextInt()
        {
            return int.Parse(next());
        }
        public int[] ArrayInt(int N, int add = 0)
        {
            int[] Array = new int[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextInt() + add;
            }
            return Array;
        }

        public long nextLong()
        {
            return long.Parse(next());
        }

        public long[] ArrayLong(int N, long add = 0)
        {
            long[] Array = new long[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextLong() + add;
            }
            return Array;
        }

        public double nextDouble()
        {
            return double.Parse(next());
        }


        public double[] ArrayDouble(int N, double add = 0)
        {
            double[] Array = new double[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextDouble() + add;
            }
            return Array;
        }
    }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,m,i,j,k,o,p,a[50][50]={0};
    vector<long long int>uos;
    scanf("%lld",&n);
    for(i=0;i<n;i++)
    {
        scanf("%lld",&p);
        uos.push_back(p);
    }
    for(i=0,k=0;i<n;i++)
    {
        for(j=i+1;j<n;j++)
        {
            if(a[i][j]==0){k+=uos[i]*uos[j];}
            a[i][j]=1;
            a[j][i]=1;
        }
    }
    printf("%lld\n",k);
    uos.clear();





    return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;

namespace AtCoder {
    class Program {
        static void Main() {
            long[] input = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
            long n = input[0], a = input[1], b = input[2];
            long[] d = new long[3];
            d[0] = b - a;
            d[1] = (a - 1) + 1 + (b - 1);
            d[2] = (n - a) + 1 + (n - b);
            Console.WriteLine(d.Where(x => x % 2 == 0).Min() / 2);
        }
    }
}

Measured memory_bytes: 13396
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		List<String> ret = new ArrayList<String>();
		while (sc.hasNext()) {
			long A = sc.nextLong();
			long B = sc.nextLong();

			long a = A;
			long b = B;
			int i;
			long G = 1; // ?????§??¬?´???°
			boolean flg;
			do {
				flg = false;
				long max = (a >= b) ? a : b;
				for (i = 2; i < max; i++) {
					if (a % i == 0 && b % i == 0) {
						a = a / i;
						b = b / i;
						G = G * i;
						flg = true;
						break;
					}
				}
			} while (flg);
			long L = A * B / G;
			ret.add(G + " " + L);
		}
		for (String ans : ret) {
			System.out.println(ans);
		}
	}
}

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

void call(int n)
{
    for (int i = 1; i <= n; ++i) {
        int x = i;
        if (x % 3 == 0)
            cout << " " << i;
        else
            do {
                if (x % 10 == 3) {
                    cout << " " << i;
                    x = 0;
                }
                else x /= 10;
            } while (x);
    }
    cout << endl;
}

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

Measured memory_bytes: 1164
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
long double pi = 2 * acos(0.0);
const ll mod = 1e9 + 7;

void solve() {
    ll a, b, c, k;
    cin >> a >> b >> c;
    cin >> k;
    while(k && b <= a) {b *= 2; k--;}
    if(b > a) {
        while(k && c <= b) {c *= 2; k--;}
        if(c > b) {
            cout << "Yes\n";
        }
        else cout << "No\n";
    }
    else cout << "No\n";
}
           

int main() {
    ios_base :: sync_with_stdio(false); 
    cin.tie(nullptr);   
    ll t = 1;
    //cin >> t;
    while(t--) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
typedef vector<unsigned int>vec;
typedef vector<vec> mat;
typedef vector<vector<int>> Graph;

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll A, B;
    cin >> A >> B;
    if((A + B) % 2 == 0) cout << (A + B) / 2 << endl;
    else cout << "IMPOSSIBLE" << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n,x[1010],y[1010];
int ansa[40],ansb[40];
void work(int w,int ans[])
{
	int f=1;
	if(w<0)f=-1,w=-w;
	for(int i=30,j;i>=0;--i)
		if(!(w>>i&1))
		{
			j=i-1;
			while(~j&&!(w>>j&1))--j;
			if(~j)
			{
				for(int k=j;k<i;++k)ans[k]=-1;ans[i]=1;
			}
			else
			{
				for(int k=0;k<i;++k)ans[k]=-1;ans[i]=1;ans[31]=-1;
			}
			i=j;
		}
		else ans[i]=1;
	if(f==-1)for(int i=0;i<=31;++i)ans[i]=-ans[i];
}
int main()
{
	scanf("%d",&n);
	int a,b;
	for(int i=1;i<=n;++i)
	{
		scanf("%d %d",&a,&b);
		x[i]=a+b,y[i]=a-b;
	}
	for(int i=2;i<=n;++i)if((x[i]&1)!=(x[1]&1))return printf("-1"),0;
	int m=31+(x[1]%2==0);
	printf("%d\n",m);
	for(int i=0;i<=30;++i)printf("%d ",1<<i);
	if(x[1]%2==0)printf("%d ",1);
	printf("\n");
	for(int i=1;i<=n;++i)
	{
		work(x[i],ansa);
		work(y[i],ansb);
		for(int j=0;j<m;++j)
		{
			if(ansa[j]==1)
			{
				if(ansb[j]==1)putchar('R');
				else putchar('U');
			}
			else
			{
				if(ansb[j]==1)putchar('D');
				else putchar('L');
			}
		}
		putchar('\n');
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
#define Check system("pause")
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)



int main()
{
	ios::sync_with_stdio(false);
	string s;
	cin>>s;
	int b=s.length();
	if(b%2!=0) cout<<"No";
	else
	{
		for(int i=0;i<b;i+=2)
		{
			if(s[i]!='h' || s[i+1]!='i')
			{
				cout<<"No";
				return 0;
			}		
		}
		cout<<"Yes";
	}
	return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using pii = pair<int, int>;
const ll INF = 1LL << 60;
const ll MOD = (ll) 1e9 + 7;

int main(){
    ll n, m;
    cin >> n >> m;
    if (n >= m / 2) {
        cout << m / 2 << "\n";
    }
    else {
        cout << n + (m - 2 * n) / 4 << "\n";
    }
}

Measured memory_bytes: 256
S = input()
if S == "zyxwvutsrqponmlkjihgfedcba":
  print(-1)
  exit()
if len(S) != 26:
  L = [0]*26
  for i in range(len(S)):
    L[ord(S[i])-97] = 1
  for i in range(26):
    if L[i] == 0:
      print(S + chr(97+i))
      exit()
else:
  B = []
  for i in reversed(range(26)):
    if ord(S[i]) > ord(S[i-1]):
      U = i
      M = i-1
      B += [ord(S[i])]
      break
    else:
      B += [ord(S[i])]
  B.sort()
  for i in B:
    if chr(i) > S[M]:
      print(S[:M] + chr(i))
      exit()

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

#define INF 2147483647
#define LINF 9223372036854775807
#define MOD 1000000007
#define MOD2 998244353

template<class T,class U>bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U>bool chmin(T &a, const U &b){if(b<a){a=b;return 1;}return 0;}

#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define rep1(i,a,b) for(int a_=(a),b_=(b),i=a_;i<b_;++i)
#define repr(i,n) for(int _i=(n),i=_i;i>0;--i)

#define db(x) cerr<<#x<<" = "<<x<<" ";
#define db2(x,y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<") ";
#define db3(x,y,z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = ("<<x<<", "<<y<<", "<<z<<") ";
#define ln cout<<endl;

#define all(a)  (a).begin(),(a).end()
#define dig(n)  to_string(n).length()

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define se second
#define fi first

typedef long long ll;
typedef long double ld;

typedef pair<int,int> P;
typedef pair<int,P> iP;
typedef pair<P,P> PP;

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

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



int main(){

    bool flag=false;
    ll ans=0,sum=0;

    int n;
    cin>>n;
    vector<ll> a(n+1,0);
    a[n] = -1;

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

    int p = 0;
    int mode = 1;

    ll g=1000,k=0;

    while(1){
        if(mode == 1){

            while(a[p] >= a[p+1] && p<n)++p;
            mode = 0;

            if(p >= n)break;
            k += g/a[p];
            g -= (g/a[p])*a[p];
        
        } else {
        
            while(a[p] <= a[p+1] && p<n)++p;
            mode = 1;

            if(p >= n)break;
            g += k*a[p];
            k = 0;
        }

        //cout<<"day "<<p+1;
        //db2(g,k);ln;

        ++p;
    }

    cout<<g<<endl;
    //cout <<fixed<<setprecision(16)<< << endl;
    //if(flag)cout << "Yes" <<endl;
    //else cout << "No" <<endl;

    return 0;
}


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

class Dice{
private:
    void roll(int a, int b, int c, int d){
        swap(x[a],x[b]);
        swap(x[b],x[d]);
        swap(x[c],x[d]);
    }
public:
    int x[6];
    void roll_N(){ roll(0,1,4,5); }
    void roll_E(){ roll(0,3,2,5); }
    void roll_S(){ roll(0,4,1,5); }
    void roll_W(){ roll(0,2,3,5); }
};

int main(){
    Dice die;
    rep(i,6) cin >> die.x[i];
    
    char ch;
    while(cin >> ch){
        if(ch == 'N'){
            die.roll_N();
        } else if(ch == 'E'){
            die.roll_E();
        } else if(ch == 'S'){
            die.roll_S();
        } else if(ch == 'W'){
            die.roll_W();
        }
    }
    cout << die.x[0] << endl;
    return 0;
}


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

int main()
{

	int N, M;
	cin >> N >> M;
	vector<int> edge(N + 1, 0);

	for (int j = 0; j < M; j++)
	{
		int a, b;
		cin >> a >> b;
		edge.at(a)++;
		edge.at(b)++;
	}

	for (int i = 1; i < N + 1; i++)
	{
		cout << edge[i] << endl;
	}
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <vector>
#include <algorithm>
#include <map>


// aとbの最大公約数を求める
long long evalmod(long long a, long long b){
  long long maxval = std::max(a, b);
  long long minval = std::min(a, b);
  if (minval==0){
    return maxval;
  }
  long long tmpval = maxval%minval;
  return evalmod(minval, tmpval);
}

int main(){

  int N;
  scanf("%d",&N);
  std::vector<long long > A(N), L(N), R(N);
  for (int i=0; i<N; i++){
    scanf("%lld",&A[i]);
  }
  L[0]=A[0];
  for (int i=1; i<N; i++){
    L[i]=evalmod(L[i-1],A[i]);
  }
  R[0]=A[N-1];
  for (int i=1; i<N; i++){
    R[i]=evalmod(R[i-1],A[N-1-i]);
  }
  long long mod = A[0];
  for (int i=1; i<N; i++){
    mod = evalmod(mod, A[i]);
  }
  long long ans = 1;
  for (int i=0; i<N; i++){
    if (i==0){
      ans = std::max(ans, R[N-2]);
    } else if (i==N-1){
      ans = std::max(ans, L[N-2]);
    } else {
      ans = std::max(ans, evalmod(L[i-1], R[N-i-2]));
    }
  }

  printf("%lld\n",ans);
  return 0;
}


Measured memory_bytes: 2688
N,k,*A = $<.read.split.map{ _1.to_i-1 }
A.pop A.size-N-1
k += 1
C = [c=0]
R = [i=0]
R << i and C[i] = c+=1  until o=C[i=A[i]]
exit p(R[k]+1)&0  if k<=c
R.shift o
p R[(k-o)%R.size]+1

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}

int W, H;
string s[50];
int d[50][50];

int main2() {
  cin >> H >> W;
  REP(i, H) cin >> s[i];
  int dot = 0;
  REP(i, H) REP(j, W) if (s[i][j] == '.') ++dot;

  int INF = 1001001001;
  REP(i, 50) REP(j, 50) d[i][j] = INF;
  int dr[] = {0, -1, 0, +1};
  int dc[] = {1, 0, -1, 0};
  queue<int> q;
  q.push(0);
  q.push(0);
  d[0][0] = 0;
  while (q.size() > 0) {
    int r = q.front(); q.pop();
    int c = q.front(); q.pop();
    if (r == H-1 && c == W-1) break;
    REP(i, 4) {
      int nr = r + dr[i];
      int nc = c + dc[i];
      if (0 <= nr && nr < H && 0 <= nc && nc < W && s[nr][nc] == '.' && d[nr][nc] > d[r][c] + 1) {
        d[nr][nc] = d[r][c] + 1;
        q.push(nr);
        q.push(nc);
      }
    }
  }
  int ans = -1;
  if (d[H-1][W-1] != INF) ans = dot - d[H-1][W-1] - 1;
  cout << ans << endl;
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define max0(a,b,c) max(max(a,b),c)
#define min0(a,b,c) min(min(a,b),c)
#define ft first
#define sc second
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
using namespace std;
using Graph = vector<vector<int>>;
typedef long long lint;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldouble;
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<ull> ulvec;
typedef vector<double> dvec;
typedef vector<pair<int,int>> pvec;
typedef vector<pair<ll,ll>> plvec;
typedef vector<tuple<ll,ll,ll>> tvec;
typedef vector<string> svec;

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

int main(){
    ll a,b,c;
    cin>>a>>b;
    c=gcd(a,b);
    b/=c;
    cout<<a*b<<endl;
}

Measured memory_bytes: 256
import sys
read = sys.stdin.readline
import time
import math
import itertools as it
def inp():
    return int(input())
def inpl():
    return list(map(int, input().split()))
start_time = time.perf_counter()
# ------------------------------

A = inpl()
A.sort()
if A[0]!=A[2]:
    if A[0]==A[1]:
        print('Yes')
        sys.exit()
    if A[1]==A[2]:
        print('Yes')
        sys.exit()
print('No')


# -----------------------------
end_time = time.perf_counter()
print('time:', end_time-start_time, file=sys.stderr)

Measured memory_bytes: 9208
import Control.Applicative
import Control.Monad
import Data.List
import Data.Array
import Data.Char

main = do
  [n, k] <- map (read::String -> Int) . words <$> getLine
  arr <- map (read::String -> Int) . words <$> getLine
  print . length $ filter (\num -> num >= k) arr

Measured memory_bytes: 17916
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

class UnionFind {
  vector<int> par, rank, potential;
public:
  UnionFind(int n) {
    par.resize(n, -1);
    rank.resize(n, 0);
    potential.resize(n, 0);
  }
  int root(int x) {
    if (par[x] < 0)
      return x;
    int r = root(par[x]);
    potential[x] += potential[par[x]];
    return par[x] = r;
  }
  int size(int x) {
    return -par[root(x)];
  }
  int weight(int x) {
    root(x);
    return potential[x];
  }
  bool isSame(int x, int y) {
    return root(x) == root(y);
  }
  bool unite(int x, int y, int w = 0) {
    w += weight(x);
    w -= weight(y);
    x = root(x);
    y = root(y);
    if(x == y) {
      return false;
    }
    if(rank[x] < rank[y]) {
      swap(x, y);
      w = -w;
    }
    if(rank[x] == rank[y])
      rank[x]++;
    par[x] += par[y];
    par[y] = x;
    potential[y] = w;
    return true;
  }
  int diff(int x, int y) {
    return weight(y) - weight(x);
  }
};

int main(){
  int N, M;
  cin >> N >> M;
  if(M) {
    vector<int> L(M), R(M), D(M);
    rep(i, M) {
      cin >> L[i] >> R[i] >> D[i];
      L[i]--; R[i]--;
    }
    UnionFind uf(N);
    rep(i, M) {
      if(!uf.unite(L[i], R[i], D[i]) && uf.diff(L[i], R[i]) != D[i]) {
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>*/
 
#define pll              pair <long long,long long>
#define pb               push_back
#define ll               long long
#define ff               first
#define ss               second
#define D(x)             cerr<<#x " = "<<(x)<<endl
#define vll              vector <ll>
#define IOS              ios_base::sync_with_stdio(0); cin.tie(NULL);
#define endl             '\n'   
using namespace std;


ll cal(ll x,ll r)
{
    if(r==0||r<0)
    return 0;
    return r/x;
}

ll gcd (ll a, ll b) {
return b ? gcd (b, a % b) : a;
}

int main()
{
    IOS
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    ll dc =cal(c,b)-cal(c,a-1);
    ll dd =cal(d,b)-cal(d,a-1);
    ll com=(c*d)/gcd(c,d);
    ll dcd=cal(com,b)-cal(com,a-1);       //  cout<<dc<<" "<<dd<<" "<<dcd<<endl;
    cout<<b-a+1-(dc+dd-dcd)<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#include <iomanip>
//#pragma GCC optimize("Ofast")  //デバッグ時にoptimized-outされて邪魔だった
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define floatprec(dig) fixed << setprecision(dig)
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
#define invar(typ, var) typ var; cin >> var;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;

signed main(void) {
  cin.tie(0); ios::sync_with_stdio(false);
  
  invar(int, A1);
  invar(int, A2);
  invar(int, A3);
  
  if(A1 + A2 + A3 <= 21) {
    fin("win");
  } else {
    fin("bust");
  }
}

Measured memory_bytes: 256
N, A, B = map(int, input().split())
S = input()
decided = 0
foreign_decided = 0
for c in S:
    if c == "c":
        print("No")
    else:
        if decided < A + B:
            if c == "a":
                print("Yes")
                decided += 1
            else:
                if foreign_decided < B:
                    print("Yes")
                    decided += 1
                    foreign_decided += 1
                else:
                    print("No")
        else:
            print("No")

Measured memory_bytes: 4016
n=int(input())
p=list(map(int,input().split()))
q=list(map(int,input().split()))
P=["abcdefgh"[i-1] for i in p]
Q=["abcdefgh"[i-1] for i in q]
P=tuple(P)
Q=tuple(Q)
import itertools
R=list(itertools.permutations("abcdefgh"[:n]))
print(abs(R.index(P)-R.index(Q)))

Measured memory_bytes: 8052
using System;
using System.Linq;
 
class P{
  static void Main(){
    string S = Console.ReadLine();
    long K = long.Parse(Console.ReadLine());
    
    int count1 = 0;
    for(int i = 1; i <= S.Length; i++){
      if(S[i - 1] == '1') count1++;
      else break;
    }
    
    string ans = "";
    if(count1 > 0){
      if(K <= count1) ans = "1";
      else ans = S[count1].ToString();
    }else{
      ans = S[0].ToString();
    }
    Console.WriteLine(ans);
  }
}

Measured memory_bytes: 13140
#pragma comment(linker, "/STACK:10240000")
#include <bits/stdc++.h>

using namespace std;

long long num[10];
char s[10];

int main ()
{
    int n;
    scanf ("%d", &n);
    memset (num, 0, sizeof (num));
    for (int i = 1; i <= n; i ++)
    {
        scanf ("%s", &s);
        if (s[0] == 'M')
        {
            num[0] ++;
        }
        else if (s[0] == 'A')
        {
            num[1] ++;
        }
        else if (s[0] == 'R')
        {
            num[2] ++;
        }
        else if (s[0] == 'C')
        {
            num[3] ++;
        }
        else if (s[0] == 'H')
        {
            num[4] ++;
        }
    }
    long long ans = num[0] * num[1] * num[2] + num[0] * num[1] * num[3] + num[0] * num[1] * num[4] + num[0] * num[2] * num[3] + num[0] * num[2] * num[4] + num[0] * num[3] * num[4] + num[1] * num[2] * num[3] + num[1] * num[2] * num[4] +num[1] * num[3] * num[4] + num[2] * num[3] * num[4];
    printf ("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 256
<?php
    /*
        Problem URL : http://arc068.contest.atcoder.jp/tasks/arc068_b
        Score  :
        Result :
        Time   : ms
        Memory : KB
     */
 
    ini_set('error_reporting', E_ALL & ~E_NOTICE);
    ini_set('display_errors', 'On');
    // define('DEBUG', true);
    define('DEBUG', false);

    $kai = 0;

    fscanf(STDIN, "%d", $N);
    $a = explode(" ", trim(fgets(STDIN)));

    $a = array_unique($a);

    // var_dump($a);

    $ans = count($a);

    if ($ans % 2 == 0) {
        $ans--;
    }

    echo sprintf("%d\n", $ans);


Measured memory_bytes: 16756
#include <cstdio>
#include <cstdlib>
#include <algorithm>
using namespace std;
bool cmp(int x, int y)
{
    return x>y;
}
int ans,f[10005];
int main()
{
    int n,k;
    scanf("%d %d",&n,&k);
    for(int i=0; i<n; i++)
        scanf("%d",&f[i]);
    sort(f,f+n+1,cmp);
    for(int i=0; i<k; i++)
        ans+=f[i];
    printf("%d",ans);    
    return 0;
}



Measured memory_bytes: 128
// C - Be Together
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false);cin.tie(NULL)
using namespace std;
#define int long long
#define MOD 1000000007
typedef vector<int> vi;
typedef pair<int,int> pi;
#define inf INT_MAX
#define For(i,a,b) for (int i = a; i < b; i++)
#define Rep(i,a,b) for (int i = a; i <= b; i++)
#define ps(x,y) fixed << setprecision(y) << x 
#define pb push_back 
#define mp make_pair 

int a[105];
 
int32_t main()
{
    fast;
    int n, ans1 = 0, ans2 = 0, avg = 0; cin >> n;
    For(i, 0, n) {
        cin >> a[i];
        avg += a[i];
    }
    avg /= n;
    For(i, 0, n) {
        ans1 += (a[i] - avg) * (a[i] - avg);
        ans2 += (a[i] - avg - 1) * (a[i] - avg - 1);
    }

    cout << min(ans1, ans2);

    
    return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <algorithm>
#define SQ(x) ((x)*(x))
using namespace std;
int main(void){
  int a[3],b[4]={},c=0;
  while(cin>>a[0]>>a[1]>>a[2]){
    if(!c){
      sort(&a[0],&a[3]);
      if(!(a[0]+a[1]>a[2])){c=1;continue;}
      ++b[0];
      if(SQ(a[0])+SQ(a[1])>SQ(a[2])) ++b[2];
      else if(SQ(a[0])+SQ(a[1])==SQ(a[2])) ++b[1];
      else ++b[3];
    }
  }
  cout<<b[0]<<" "<<b[1]<<" "<<b[2]<<" "<<b[3]<<endl;
  return 0;
}

Measured memory_bytes: 1184
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i = 0; i < n; i++)
#define yes "yes"
#define Yes "Yes"
#define no "no"
#define No "No"

namespace mydef
{
  void say(string some){
    cout << some << "\n";
  }
} // namespace mydef
using namespace mydef;

typedef long long ll;


void solve(){
    
}

signed main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  
  ll a, b, c, k, ans;
  cin >> a >> b >> c >> k;

  ans = min(a, k) - max(k-a-b, 0ll);
    cout << ans << "\n";

  return 0;
}




Measured memory_bytes: 3636
#include<iostream>

using namespace std;
typedef unsigned long long ULL;
typedef long long LL;

int main(){
    int N,K;
    int i,j;
    ULL *p;
    ULL sum;
    ULL max;
    cin >> N >> K;
    p = new ULL[N];
    for(i=0;i<N;i++){
        cin >> p[i];
    }
    max = 0;
    sum = 0;
    for(i=0;i<K;i++){
        sum += p[i];
        max += p[i];       
    }
    for(;i<N;i++){
        sum += p[i];
        sum -= p[i-K];
        if( max < sum){
            max = sum;
        }
    }
    max += K;
    cout << max/2;
    if( max % 2 == 1){
        cout << ".5" << endl;
    }
}

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

int main(void) {
  int N;
  cin >> N;
  vector<int> H(N);
  for (int i = 0; i < N; i++) cin >> H.at(i);
  int count = 0;
  int countmax = 0;
  for (int i = 0; i < N-1; i++) {
    if (H.at(i) >= H.at(i+1)) {
      count++;
      if (countmax < count) countmax = count;
    } else {
      count = 0;
    }
  }
  cout << countmax << endl;
}

Measured memory_bytes: 3772
if __name__ == "__main__":
	N,K,Q = map(int,input().split())
	answerList = [input() for i in range(0,Q)]

	pointList = []
	for i in range(0,N):
		pointList.append(K)
		# print(pointList)

	for i in range(0,Q):
		pointList[int(answerList[i])-1] += 1
		# print(pointList)

	for i in range(0,N):
		pointList[i] = pointList[i] - (Q)
		# print(pointList[Q])

		if pointList[i] <= 0:
			pointList[i] = "No"
		else:
			pointList[i] = "Yes"

	[print(i) for i in pointList]

Measured memory_bytes: 12156
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> veci;
typedef vector<string> vecs;
template<class T,class U> using Hash=unordered_map<T,U>;

#define REP(i, a, n) for(ll i = a; i < n; i++)
#define RREP(i, a, n) for(ll i = n-1; i >= a; i--)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) RREP(i, 0, n)
#define MD 1000000007

template<class T> T read(){T a;cin >> a;return a;}
template<class T> void read(T& a){cin >> a;}
template<class T> void rarr(T a, int n){for(int i = 0; i < n; i++) {cin >> a[i];}}
template<class T> void write(T a){cout << a << endl;}
template<class T> void writes(vector<T> a, const char* c = " "){cout << a[0];for(int i = 1; i < (int)a.size(); i++)cout << c << a[i];cout << endl;;}
void write(double a){cout << fixed << setprecision(12) << a << endl;}
void write(long double a){cout << fixed << setprecision(12) << a << endl;}
template<class T> void warr(T a, int n, const char* c = " "){cout << a[0];for(int i = 1; i < n; i++)cout << c << a[i];cout << endl;}
void split(string s, string delim, veci& result){result.clear();string::size_type pos = 0;while(pos != string::npos){string::size_type p = s.find(delim, pos);if(p == string::npos){result.push_back(atoi(s.substr(pos).data()));break;}else {result.push_back(atoi(s.substr(pos, p - pos).data()));}pos = p + delim.size();}}
void split(string s, string delim, vecs& result){result.clear();string::size_type pos = 0;while(pos != string::npos){string::size_type p = s.find(delim, pos);if(p == string::npos){result.push_back(s.substr(pos));break;}else {result.push_back(s.substr(pos, p - pos));}pos = p + delim.size();}}
ll gcd(ll a, ll b){while(true){ll k = a % b;if(k == 0)return b;a = b;b = k;}}
ll comb(ll n, ll m){ll p=1;m=min(m,n-m);for(ll i=1;i<=m;i++){p*=n-i+1;p/=i;}return p;}

int main(void)
{
    int n,a[200];
    cin>>n;
    n*=2;
    rep(i,n)cin>>a[i];
    sort(a,a+n);
    int res=0;
    rep(i,n/2)res+=a[i*2];
    write(res);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stdio.h>
#include<cstring>
#include<math.h>
#include<map>
#include<bitset>
#include<iomanip>
#include<queue>
#include<functional>
#include<stack>
#include<tuple>
#include<cassert>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
using P = pair<int, int>;

int main() {
  int N;
  cin >> N;
  string s[200000];
  map<string, int> mp;
  rep(i, N) {
    string temp;
    cin >> temp;
    s[i] = temp;
    mp[temp]++;
  }
  int m = 0;
  rep(i, N) {
    string temp = s[i];
    m = max(m, mp[temp]);
  }
  vector<string> v;
  rep(i, N) {
    string temp = s[i];
    if(mp[temp] == m) {
      v.push_back(temp);
      mp[temp] = 0;
    }
  }
  sort(v.begin(), v.end());
  rep(i, v.size()) {
    cout << v[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 33524
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class MainClass
{
	public const long Giri = 1000000007;
	public const long DpInf = 99999999999999;
	
	public static void Main(string[] args)
	{
		var n = Console.ReadLine().ToInt();
		var a = Console.ReadLine().ToInt();
		Console.WriteLine(n*n-a);
	}

	
	static long GCD(long a, long b)
	{
		var v = new[] { a, b };
		while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
		return v[0];
	}
	public static string[] Input() { return Console.ReadLine().Split(); }
}

public static class Smarter
{
	public static int ToInt(this string str) { return int.Parse(str); }
	public static long ToLong(this string str) { return long.Parse(str); }
	public static int[] ToInt(this string[] str, int offset = 0)
	{
		var r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt() + offset;
		return r;
	}
}

Measured memory_bytes: 13140
// 
import java.math.*;
import java.util.*;
import java.io.*;
  
public class Main { 
  
    static BufferedReader in;
    static String file = "../in";

    static int test = 10;  // 0 for local testing, 1 for std input

    public static void main(String[] args) throws Exception
    {
        int _k = Integer.valueOf("1");
        if(test > 0) in = new BufferedReader(new InputStreamReader(System.in));
        else in = new BufferedReader(new FileReader(file));
        if(test < 0) {String[] str = in.readLine().split(" ");}
        
        /****************************************************/
        /****************************************************/
        /****************************************************/
        /****************************************************/
    
        new Main().c();
    }

    void c() throws Exception
    {
        int n = Integer.valueOf(in.readLine());
        String[] sp = in.readLine().split(" ");
        int[] a = new int[n], b = new int[n];
        for(int i = 0; i < n; i++) a[i] = Integer.valueOf(sp[i]);
        sp = in.readLine().split(" ");
        for(int i = 0; i < n; i++) b[i] = Integer.valueOf(sp[i]);
        
        int r1 = rank(n, a);
        int r2 = rank(n, b);
        
        // System.out.println(r1);
        // System.out.println(r2);
        System.out.println(Math.abs(r1 - r2));
    }

    int rank(int n, int[] a) throws Exception
    {
        Set<Integer> set = new HashSet<>();
        for(int i = 1; i <= n; i++) set.add(i);
        int[] f = new int[10];
        f[1] = 1;
        for(int i = 2; i < 10; i++) f[i] = i * f[i - 1];

        int rank = 0;
        for(int i = 0; i < n; i++)
        {
            // remove a[i]
            // count elements less than a[i]
            int count = 0;
            set.remove(a[i]);
            for(int k : set) if(k < a[i]) count++;
            // System.out.println(count);
            rank += count * f[n - 1 - i];
        }
        return rank;
    }

    void b() throws Exception
    {
        in.readLine();
        char[] chs = in.readLine().toCharArray();
        int n = chs.length;
        int re = 0;
        for(int i = 0; i < n - 2; i++)
        {
            if(chs[i] == 'A' && chs[i + 1] == 'B' && chs[i + 2] == 'C')
                re++;
        }
        System.out.println(re);
    }

    void a() throws Exception
    {
        String[] sp = in.readLine().split(" ");
        int a = Integer.valueOf(sp[0]);
        int b = Integer.valueOf(sp[1]);
        if(a * 500 >= b) System.out.println("Yes");
        else System.out.println("No");
    }
}

Measured memory_bytes: 21332
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int n = scan.nextInt();
		int k = scan.nextInt();

		int[] nCandyArray = new int[n];

		for (int i = 0; i < k; i++) {

			int d = scan.nextInt();

			for (int j = 0; j < d; j++) {

				int a = scan.nextInt();

				nCandyArray[a - 1]++;
			}
		}

		int count = 0;

		for (int candy : nCandyArray) {

			if (candy == 0) {
				count++;
			}
		}

		println(count);
	}

	public static void println(Object target) {
		System.out.println(target);
	}
}


Measured memory_bytes: 37360
#include <iostream>
#include <vector>
#include <algorithm>
#include <algorithm>

#define INF 1010101010

using namespace std;

int main()
{
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end());

	if (n % 2 == 0) {
		vector<int> ans(n);
		for (int i = 0; i * 2 < n; i++) {
			ans[i * 2] = a[n / 2 + i];
			ans[i * 2 + 1] = a[i];
		}

		long long sum = 0;
		for (int i = 1; i < n; i++) {
			sum += abs(ans[i] - ans[i - 1]);
		}
		cout << sum << endl;
	} else {
		vector<int> ans(n);
		ans[n - 1] = a[n / 2];
		for (int i = 0; i < n / 2; i++) {
			ans[i * 2] = a[n / 2 + i + 1];
			ans[i * 2 + 1] = a[i];
		}

		long long sum1 = 0, sum2 = 0;
		for (int i = 1; i < n; i++) {
			sum1 += abs(ans[i] - ans[i - 1]);
		}

		int tmp = ans[n - 1];
		for (int i = n - 1; i > 0; i--) {
			ans[i] = ans[i - 1];
		}
		ans[0] = tmp;

		for (int i = 1; i < n; i++) {
			sum2 += abs(ans[i] - ans[i - 1]);
		}
		
		cout << max(sum1, sum2) << endl;
	}

	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<vector>

#define F first
#define S second
#define PB push_back

using namespace std;

const int MAXN = 10005;
int sz[MAXN], par[MAXN];
vector<pair<int, pair<int, int> > > e;

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

bool add(int x, int y)
{
	x = getpar(x), y = getpar(y);
	if(x == y)
		return false;
	if(sz[x] < sz[y])
		swap(x, y);
	sz[x] += sz[y];
	par[y] = x;
	return true;
}

int main()
{
	int n, m;
	cin >> n >> m;
	fill(par, par + n, -1);
	fill(sz, sz + n, 1);
	for(int i = 0; i < m; i++)
	{
		int x, y, w;
		cin >> x >> y >> w;
		e.PB({w, {x, y}});
	}
	sort(e.begin(), e.end());
	int ans = 0;
	for(auto x : e)
		if(add(x.S.F, x.S.S))
			ans += x.F;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2776
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,K,X,Y;
  cin >> N >> K >> X >> Y;
  if (N<K){
    cout << N*X << endl;
  }
  else{
    cout << K*X+(N-K)*Y << endl;
  }
}

Measured memory_bytes: 256
// E - Count Median

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

int A[200001];
int B[200001];

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

	for (int i=0; i<N; i++) {
		cin >> A[i] >> B[i];
	}

	sort(A, A+N);
	sort(B, B+N);

	int ans;

	if (N % 2 == 1) {
		int m = N / 2;
		ans = B[m] - A[m] + 1;
	} else {
		int m1 = N / 2 - 1;
		int m2 = N / 2;
		ans = (B[m1] + B[m2]) - (A[m1] + A[m2]) + 1;
	}

	cout << ans << endl;

	return 0;
}

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


string f(ll n)
{if(n==0) return "";
 n--;
 return f(n/26)+string(1,(n%26)+'a'); 
}
//一番最初は26で割ったあまりを使うので下1桁めを求める
//次に、26で割った状態のものなので2桁めがもとまる
int main() {
  ll n;
  cin >> n;
  cout << f(n) << endl;
  return 0;
}


Measured memory_bytes: 3596