akhauriyash/Code-Regression huggingface dataset:
/*
Cerberus97
Hanit Banga
*/

#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>

using namespace std;

#define pb push_back
#define fast_cin() ios_base::sync_with_stdio(false)

typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const int N = 2e5 + 5;

int a[N], p[N];
vector <int> g[N];
bool seen[N], cycle[N];

void dfs(int i);
bool solve(int st, int v);

int main()
{
	int n;
	cin >> n;
	for (int i = 1; i <= n; ++i)
	{
		cin >> p[i];
		g[p[i]].pb(i);
	}

	int cur = 1;
	for (int i = 0; i <= n; ++i)
		cur = p[cur];

	cycle[cur] = true;
	int st = cur;
	while (p[cur] != st)
	{
		cur = p[cur];
		cycle[cur] = true;
	}

	for (int i = 1; i <= n; ++i)
		if (!cycle[i] and !seen[i])
			dfs(i);

	int v = 0, w = 0;
	set <int> s;
	for (auto &i : g[st])
		if (!cycle[i])
			s.insert(a[i]);

	while (s.find(v) != s.end())
		++v;

	s.insert(v);
	while (s.find(w) != s.end())
		++w;

	if(solve(st, v) or solve(st, w))
		cout << "POSSIBLE\n";
	else
		cout << "IMPOSSIBLE\n";
}

void dfs(int i)
{
	seen[i] = true;
	set <int> s;
	for (auto &j : g[i])
	{
		if (!seen[j])
			dfs(j);

		s.insert(a[j]);
	}

	a[i] = 0;
	while (s.find(a[i]) != s.end())
		++a[i];
}

bool solve(int st, int v)
{
	a[st] = v;
	int cur = p[st];
	while (true)
	{
		set <int> s;
		for (auto &i : g[cur])
			s.insert(a[i]);

		a[cur] = 0;
		while (s.find(a[cur]) != s.end())
			++a[cur];

		if (cur == st)
			break;

		cur = p[cur];
	}

	return (a[st] == v);
}

Measured memory_bytes: 12160
#include<stdio.h>

int main(){
  int n;
  int cnt;

  for(;;){
    scanf("%d",&n);
    if(n==0)
      break;

    cnt=0;
    while(1){
      if(n==1)
	break;
      if(n%2==0)
	n/=2;
      else{
	n*=3;
	n++;
      }
      cnt++;
    }
    printf("%d\n",cnt);
  }
  return 0;
}

Measured memory_bytes: 0
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        
        int alpha[][] = new int[n][26];

        for (int i = 0; i < n; i++) {
            String s = in.next();
            Arrays.fill(alpha[i], 0);
            for (int j = 0; j < s.length(); j++) {
                int c = s.charAt(j) - 'a';
                alpha[i][c]++;
            }
        }

        int alphaCount[] = new int[26];
        for (int i = 0; i < 26; i++) {
            int min = Integer.MAX_VALUE;
            for (int j = 0; j < n; j++) {
                min = Math.min(alpha[j][i], min);
            }
            alphaCount[i] = min;
        }

        for (int i = 0; i < 26; i++) {
            for (int j = 0; j < alphaCount[i]; j++) {
                System.out.print((char)('a' + i));
            }
        }
        System.out.println();
    }
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  int sum = 0;

  for(int i = 0;i<N; i++){
    int l=0, r=0;
    cin >> l >> r;
    sum += r -l;
    sum += 1;
  }
 cout << sum << endl;
}


Measured memory_bytes: 256
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    A, B = map(int, readline().split())

    vec = [A, B, A-1, B-1]
    vec.sort(reverse=True)

    print(sum(vec[:2]))

    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 9028
n,k = [int(x) for x in input().split()]

w = []

for i in range(n):
        w.append(int(input()))

def f(p, k, w):
        tmpk = 0
        tmpw = 0
        cnt = 0

        for i in w:
                if tmpk < k - 1:
                        if tmpw + i <= p:
                                tmpw += i
                                cnt += 1
                        else:
                                if i <= p:
                                        tmpk += 1
                                        tmpw = i
                                        cnt += 1
                                else:
                                        break
                else:
                        if tmpw + i <= p:
                                tmpw += i
                                cnt += 1
                        else:
                                break
        return cnt

    
pmin = 1
pmax = sum(w)

while pmin < pmax:
        mid = (pmin + pmax) // 2
        tmp = f(mid, k , w)

        if tmp < n:
                pmin = mid + 1
        else:
                pmax = mid

print(pmin)

Measured memory_bytes: 11540
#include<stdio.h>
#include<stdlib.h>
int main()
{
    int l,r,d,i,n=0;
    scanf("%d %d %d",&l,&r,&d);
    for(i=0;i<=r;i++)
    {
        if(i%d==0&&i>=l)
            n++;
    }
    printf("%d",n);
    return 0;
}

Measured memory_bytes: 1728
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int n,x[1005];
vector<int>g[1005];
int m[5005];
bool c=true;
void dfs(int v){
    int p[5005];
    for(int i=0;i<=5001;i++)p[i]=5000001;
    p[0]=0;
    for(int i=0;i<g[v].size();i++){
        int u=g[v][i];
        dfs(u);
        int r[5005];
        for(int j=0;j<=5001;j++)r[j]=5000001;
        for(int j=0;j<=5001;j++){
            if(p[j]<5000001){
                r[min(j+x[u],5001)]=min(r[min(j+x[u],5001)],p[j]+m[u]);
                r[min(j+m[u],5001)]=min(r[min(j+m[u],5001)],p[j]+x[u]);
            }
        }
        for(int j=0;j<=5001;j++)p[j]=r[j];
    }
    m[v]=5000001;
    for(int i=x[v];i>=0;i--){
        m[v]=min(m[v],p[i]);
    }
    if(m[v]>=5000001)c=false;
}
int main(void){
    cin>>n;
    for(int i=1;i<n;i++){
        int a;
        cin>>a;
        g[--a].push_back(i);
    }
    for(int i=0;i<n;i++)cin>>x[i];
    dfs(0);
    if(c)cout<<"POSSIBLE\n";
    else cout<<"IMPOSSIBLE\n";
}


Measured memory_bytes: 17152
#include <cstdio>
#include <algorithm>
const long long MOD = 998244353;
int N, S, L = 1;
char _i[10001], _j[10001];
long long inv[10001], fc[10001], fi[10001], O;
long long ans[32768], bit[32768], Fbit[32768];
long long POWER(long long a, long long b)
{
	long long r = 1;
	for (; b; b >>= 1)
	{
		if (b & 1)
			r = r * a % MOD;
		a = a * a % MOD;
	}
	return r;
}
void FFT(long long *a, int f = 1)
{
	static int p[32768];
	for (int i = 1; i < L; i++)
		p[i] = i & 1 ? p[i - 1] | L >> 1 : p[i >> 1] >> 1;
	for (int i = 0; i < L; i++)
		if (i < p[i])
			std::swap(a[i], a[p[i]]);
	for (int i = 1; i < L; i <<= 1)
	{
		long long w, wn = POWER(3, (MOD - 1) / i / 2), x, y;
		if (f == -1)
			wn = POWER(wn, MOD - 2);
		for (int j = 0; j < L; j += i + i)
		{
			w = 1;
			for (int k = j; k < j + i; k++)
			{
				x = a[k];
				y = a[k + i] * w % MOD;
				a[k] = x + y < MOD ? x + y : x + y - MOD;
				a[k + i] = x - y < 0 ? x - y + MOD : x - y;
				w = w * wn % MOD;
			}
		}
	}
	if (f == -1)
	{
		long long d = POWER(L, MOD - 2);
		for (int i = 0; i < L; i++)
			a[i] = a[i] * d % MOD;
	}
}
void FFT(long long *i, long long *o, int f = 1)
{
	std::copy(i, i + L, o);
	FFT(o, f);
}
int main()
{
	fc[0] = fi[0] = inv[1] = 1;
	for (int i = 2; i <= 10000; i++)
		inv[i] = (MOD - MOD / i) * inv[MOD % i] % MOD;
	for (int i = 1; i <= 10000; i++)
	{
		fc[i] = fc[i - 1] * i % MOD;
		fi[i] = fi[i - 1] * inv[i] % MOD;
	}
	scanf("%s%s", _i, _j);
	for (int i = 0; _i[i]; i++)
	{
		if (_i[i] == '1')
		{
			N++;
			if (_j[i] == '1')
				S++;
		}
	}
	while (L <= S + S)
		L <<= 1;
	for (int i = 0; i <= S; i++)
		ans[i] = i == 0;
	if (S < N)
	{
		for (int i = 0; i <= S; i++)
			bit[i] = fi[i + 1];
		FFT(bit, Fbit);
		for (int _ = N - S; _; _ >>= 1)
		{
			if (_ & 1)
			{
				FFT(ans);
				for (int i = 0; i < L; i++)
					ans[i] = ans[i] * Fbit[i] % MOD;
				FFT(ans, -1);
				std::fill(ans + S + 1, ans + L, 0);
			}
			for (int i = 0; i < L; i++)
				Fbit[i] = Fbit[i] * Fbit[i] % MOD;
			FFT(Fbit, bit, -1);
			std::fill(bit + S + 1, bit + L, 0);
			FFT(bit, Fbit);
		}
	}
	for (int j = 0; j <= S; j++)
		O = (O + ans[j] * fc[S]) % MOD;
	printf("%lld\n", O * fc[N] % MOD * fc[N - S] % MOD);
	return 0;
}


Measured memory_bytes: 1280
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<string>

using namespace std;

bool func(const pair<int, int> &a, const pair<int, int> &b)
{
	return a.second < b.second;
}

int main()
{
	int n, m;
	vector<pair<int, int>> card;
	int i;
	int input1, input2;
	int cnt = 1, prev;
	int lmax = 0, rmin = 100000;

	scanf("%d %d", &n, &m);

	for (i = 0; i < m; i++)
	{
		scanf("%d %d", &input1, &input2);

		if (input1 > lmax)
		{
			lmax = input1;
		}

		if (input2 < rmin)
		{
			rmin = input2;
		}
	}

	printf("%d\n", lmax > rmin ? 0 : rmin - lmax + 1);

	return 0;
}

Measured memory_bytes: 128
// う　し　た　ぷ　に　き　あ　く　ん　笑
#include <algorithm>
#include <array>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
#define int long long

constexpr int MAXA = 100000 - 1;

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

    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];

    // valcount[i+1]: 操作するとiになる要素の数
    vector<int> valcount(MAXA + 1 + 2);

    for (int i = 0; i < n; i++) {
        valcount[a[i]]++;
        valcount[a[i] + 1]++;
        valcount[a[i] + 2]++;
    }

    const int ans = *max_element(valcount.begin(), valcount.end());
    cout << ans << endl;
}


Measured memory_bytes: 4752
#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
const long long mod = 1e9+7;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};
//////////////////////////////////

// O(n^2)
string LongestCommonSubsequence(string s, string t) {
    int n = s.size(); 
    int m = t.size();
    vector<vector<int>> x(n+1, vector<int>(m+1));
    vector<vector<int>> y(n+1, vector<int>(m+1));
    for(int i=0; i<n; i++) {
        for(int j=0; j<m; j++) {
            if(s[i] == t[j]) {
                x[i+1][j+1] = x[i][j] + 1;
                y[i+1][j+1] = 0;
            } else if (x[i+1][j] < x[i][j+1]) {
                x[i+1][j+1] = x[i][j+1];
                y[i+1][j+1]++;
            } else {
                x[i+1][j+1] = x[i+1][j];
                y[i+1][j+1]--;
            }
        }
    }

    string ret = "";
    for(int i=n, j=m; i>0 && j > 0;) {
        if(y[i][j] > 0) i--;
        else if(y[i][j] < 0) j--;
        else {
            ret += s[i-1];
            i--; j--;
        }
    }
    reverse(ret.begin(), ret.end());
    return ret;
}

int main() {
    string s, t; cin >> s >> t;
    cout << LongestCommonSubsequence(s, t) << endl;

    return 0;
}




// EOF


Measured memory_bytes: 70912
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); i++)
int main()
{
    int n;
    cin >> n;
    int l[100];
    int sum = 0, max_l = 0; 
    rep(i,n){
        cin >> l[i];
        sum += l[i];
        max_l = max(max_l, l[i]);
    }

    sum -= max_l;
    if(sum > max_l){
        cout << "Yes";
    }
    else{
        cout << "No";
    }

    return 0;
}

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

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

using ll = long long int;
const ll MOD = 1e9 + 7;

int main() {
  std::string S;
  std::cin >> S;

  std::string rS = std::string(S);
  std::reverse(rS.begin(), rS.end());

  int N = (int) S.length();
  std::string sub1, rsub1, sub2, rsub2;
  sub1 = S.substr(0, N / 2);
  rsub1 = std::string(sub1);
  std::reverse(rsub1.begin(), rsub1.end());

  sub2 = S.substr(N / 2 + 1);
  rsub2 = std::string(sub2);
  std::reverse(rsub2.begin(), rsub2.end());

  if(S == rS && sub1 == rsub1 && sub2 == rsub2) {
    std::cout << "Yes" << '\n';
  } else {
    std::cout << "No" << '\n';
  }


}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <set>
#include <queue>

using namespace std;
typedef long long ll;
#define MOD 1000000007

int main() {
    int N, K;
    string S;
    cin >> N >> K;
    cin >> S;

    int cnt=0;
    for(int i=0; i<S.length()-1; i++) {
        if(S[i] != S[i+1]) cnt++;
    }

    int ans = N - 1;
    if(cnt > 2*K) {
        ans -= (cnt - 2*K);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 512
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Numerics;

namespace AtCoderWorkspace
{
    public class Solver
    {
        public void Solve()
        {
            var cin = new Scanner();
            var s = cin.next();
            var lo = s.ToLower();
            Console.WriteLine(s == lo?"a":"A");
        }
    }

    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 int[] DPArrayInt(int N, int ex)
        {
            int[] Array = new int[N + ex];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextInt();
            }
            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 long[] DPArrayLong(int N, int ex)
        {
            long[] Array = new long[N + ex];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextLong();
            }
            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;
        }
    }

    class Program
    {
        static void Main(string[] s) => new Solver().Solve();
    }
}


Measured memory_bytes: 26044
#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>;

int main() {
    int m = 0;
    int ans = 0;
    rep(i,3) {
        int t;
        cin >> t;
        ans += t;
        m = max(m,t);
    }
    cout << ans-m << endl;
    return 0;
}


Measured memory_bytes: 3636
N = int(input())
Data = list(map(int,input().split()))
mind = min(Data)
maxd = max(Data)
ans = -1
for pos in range(mind,maxd+1):
    sum1 = 0
    for d in Data:
        sum1 += (pos-d)**2
    if ans == -1:
        ans = sum1
    else:
        ans = min(ans,sum1)
print(ans)

Measured memory_bytes: 3064
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product, accumulate, combinations, product
import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque
#from decimal import Decimal
#from numba import jit

INF = 1 << 50
EPS = 1e-8
mod = 10 ** 9 + 7


def run():
    N, *A = map(int, read().split())
    B = [a-k for k, a in enumerate(A, 1)]
    B.sort()
    Bsum = []
    v = 0
    for b in B:
        v += b
        Bsum.append(v)

    min_val = INF
    for k in range(N):
        c = B[k]
        #print(c)
        score = 0
        score -= Bsum[k]
        score += Bsum[-1] - Bsum[k]
        score += -N * c + 2 * c * (k+1)
        #print(score)
        min_val = min(min_val, score)

    print(min_val)


if __name__ == "__main__":
    run()


Measured memory_bytes: 37296
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
#include <map>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> pairs;

#define MOD 998244353


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

bool primeNumber(ll n){
    if(n < 2) return false;
    else{
        for(ll i = 2; i * i <= n; i++){
            if(n % i == 0) return false;
        }
        return true;
    }
}



int main(){
    while(1){
        ll a,b;
        string op;
        cin>>a>>op>>b;
        if(op == "+")cout<<a+b<<endl;
        else if(op == "-")cout<<a-b<<endl;
        else if(op ==  "*")cout<<a*b<<endl;
        else if(op == "/")cout<<a/b<<endl;
        else if(op == "?")break;
    }
    return 0;
}
 



Measured memory_bytes: 3160
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  int a,b,c,d,e;
  cin>>a>>b>>c>>d>>e;
  int ans=0;
  if(a<0) ans+=c*abs(a)+d,a=0;
  ans+=(b-a)*e;
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3088
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;
ll MOD = 1e9+7;
//LLONG_MIN

ll f(ll n){
	if(n==1)return 1;
	return n*f(n-1)%MOD;
}

int main(void){
	ll N,x,k=0,ans=1,robot=0;
	stack<ll> S;
	cin>>N;
	rep(i,N){
		cin>>x;
		k++;
		if(x>=k*2-1){
			robot++;
		}else{
			ans=ans*k%MOD;
			// cout<<ans<<endl;
			k--;
		}
	}
	if(robot>0)ans=ans*f(robot)%MOD;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long int
#define int long long
#define f(i,l,n) for(int i=l;i<n;i++) 
#define E "\n"
const int M=1e9+7;

int solve()
{

 
  int n;
  cin >> n;

  vector<int> graph[n+1];
  f(i,0,n-1)
  {
    int x,y;
    cin >> x >> y;
    graph[x].push_back(y);
    graph[y].push_back(x);
  }


  int dp[n+1][2]={0},visited[n+1]={0};


  function<void(int)> dfs=[&](int node)
  {
    dp[node][0]=dp[node][1]=1;
    visited[node]=1;
    for(auto x:graph[node])
    {
        if(visited[x]==0)
        {
            dfs(x);
            dp[node][1]=(dp[node][1]*dp[x][0])%M;
            dp[node][0]=(dp[node][0]*(dp[x][0]+dp[x][1])%M)%M;
        }
    }
    //cout<<node<<" "<<dp[node][0]<<" "<<dp[node][1]<<E;
  };

  dfs(1);

  cout<<(dp[1][0]+dp[1][1])%M<<E;

  return 0;  
}


int32_t main()
{

    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
     int t = 1;
     //cin >> t;
     while(t--)
     {
          solve();
     }
     return 0;
}

Measured memory_bytes: 18184
#include<iostream>
#include<string>
using namespace std;
int main(){
	int a,c=0;
	cin>>a;
	string b[100],e;
	cin>>b[0]>>b[1]>>b[2];
	for(int i=0;i<a;i++){
		for(int j=0;j<3;j++){
			e[j]=b[j][i];
		}
		if((e[0]==e[1]&&e[1]!=e[2])||(e[0]!=e[1]&&e[1]==e[2])||(e[0]!=e[1]&&e[0]==e[2])){
			c++;
		}
		if(e[0]!=e[1]&&e[1]!=e[2]&&e[2]!=e[0])
			c+=2;
	}
	cout<<c<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    ll a = 1;
    REP(i, 1, N) {
        a = (a * i) % mod;
    }
    cout << a << endl;

    return 0;
}


Measured memory_bytes: 3580
n = int(input())
a = []
b = []
for i in range(n):
  aa, bb = map(int, input().split())
  a.append(aa)
  b.append(bb)
a.sort()
b.sort()
ans = 0
if n%2 == 1:
  ans = b[n//2]-a[n//2]+1
else:
  ans = (b[n//2]-a[n//2])+(b[n//2-1]-a[n//2-1])+1
print (ans)

Measured memory_bytes: 25344
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using ull=unsigned long long int;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=1000000007;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int main(){
	int t;
	cin>>t;
	while(t--){
		ll n;
		cin>>n;
		ll ans=0;
		while(n>=10){
			ll res=0,a=0;
			ll tmp=n;
			int cnt=0;
			while(tmp){
				tmp/=10;
				cnt++;
			}
			tmp=n;
			for(int i=0;i<cnt-1;i++){
				a*=10;
				a+=tmp/(ll)pow(10,cnt-i-1);
				tmp%=(ll)pow(10,cnt-i-1);
				chmax(res,a*tmp);
			}
			n=res;
			ans++;
		}
		cout<<ans<<"\n";
	}
}


Measured memory_bytes: 3360
"use strict";

function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }

function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }

function _iterableToArrayLimit(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }

function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }

!function () {
  function splitNum(line) {
    return (Array.isArray(line) ? line : line.split(/\s+/)).map(function (n) {
      return parseInt(n);
    });
  }

  !function (input) {
    var lines = input.split("\n");

    var _splitNum = splitNum(lines[0]),
        _splitNum2 = _slicedToArray(_splitNum, 2),
        N = _splitNum2[0],
        K = _splitNum2[1];

    var S = lines[1].slice(0, N);

    var _ref = function () {
      var ones = [];
      var zeroes = [];
      var cur = 1;
      var num = 0;
      var _iteratorNormalCompletion = true;
      var _didIteratorError = false;
      var _iteratorError = undefined;

      try {
        for (var _iterator = S[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
          var c = _step.value;
          if (c === String(cur)) num++;else {
            (1 === cur ? ones : zeroes).push(num);
            num = 1;
            cur ^= 1;
          }
        }
      } catch (err) {
        _didIteratorError = true;
        _iteratorError = err;
      } finally {
        try {
          if (!_iteratorNormalCompletion && _iterator.return != null) {
            _iterator.return();
          }
        } finally {
          if (_didIteratorError) {
            throw _iteratorError;
          }
        }
      }

      (1 === cur ? ones : zeroes).push(num);
      if (1 == (cur ^= 1)) ones.push(0);
      return {
        ones: ones,
        zeroes: zeroes
      };
    }(),
        ones = _ref.ones,
        zeroes = _ref.zeroes;

    if (zeroes.length <= K) {
      console.log(N);
      return;
    }

    var acc = ones.slice(0, K + 1).concat(zeroes.slice(0, K)).reduce(function (a, b) {
      return a + b;
    }, 0);
    var max = acc;

    for (var i = K; i < zeroes.length; i++) {
      if (max < (acc = acc + ones[i + 1] - ones[i - K] + zeroes[i] - zeroes[i - K])) max = acc;
    }

    console.log(max);
  }(require("fs").readFileSync("/dev/stdin", "utf8"));
}();


Measured memory_bytes: 21064
qqtable =[1,2,3,4,5,6,7,8,9,10,12,14,15,16,18,20,21,24,25,27,28,30,32,35,36,40,42,45,48,49,54,56,63,64,72,81]

n = int(input())
if n in qqtable:
    print("Yes")
else:
    print("No")


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


using namespace std;

//#define push_back pb
int main()
{int n,k;
 cin>>n>>k;
 vector<int>v(n);
 for(int i=0;i<n;i++)
   cin>>v[i];
 vector<bool>dp(k+1);
 for(int stones=0;stones<=k;stones++)
  for(int x:v){
    if(stones>=x && !dp[stones-x])
      dp[stones]=1;
  }
 
    
 puts(dp[k]?"First":"Second");
  
     return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define forr(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define ALL(a) (a.begin()),(a.end())
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll, ll> LP;
const ll LINF = 1LL<<60;
const int INF = 1001001001;
const int MOD = 1000000007;

/* --------------------------------------------------- */

int main() {
    int n, t, a;
    cin >> n >> t >> a;
    double value = INF;
    int ans;
    rep(i, n) {
        int h;
        cin >> h;
        double avet = t - h * 0.006;
        if(value > abs(avet - a)) {
            ans = i + 1;
            value = abs(avet - a);
        }
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
import re

sp=input()
t=input()

strlst=[]

def makeStrLex(i):
    s=sp[:i]+t+sp[i+len(t):]
    s=s.replace('?','a')

    return s

for i in range(len(sp)-len(t)+1):
    spat=sp[i:i+len(t)].replace('?','.')
    repat=re.compile(spat)
    
    if repat.match(t):
        strlst.append(makeStrLex(i))

if len(strlst)>0:
    print(sorted(strlst)[0])
else:
    print('UNRESTORABLE')


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

int main() {
    int N, Y;
    cin >> N >> Y;
    int r10000 = -1, r5000 = -1, r1000 = -1;
    for (int a = 0; a <= N; ++a) {
        for (int b = 0; b + a <= N; ++b) {
            int c = N - a - b;
            int total = 10000 * a + 5000 * b + 1000 * c;
            if (total == Y) {
                r10000 = a;
                r5000 = b;
                r1000 = c;
            }
        }
    }
    cout << r10000 << " " << r5000 << " " << r1000 << endl;
}


Measured memory_bytes: 256
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
def main
  dat=[]
  fh=STDIN
  #fh=File.new("x.txt", "r")
  while fh.gets
    s=$_.chomp
    puts s.swapcase
  end

end

if $0 == __FILE__ then
  main
end


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

int main() {
	int n; cin >> n;
	vector<int>a(n); for (auto&& x : a)cin >> x;
	long long ans = 0; int right = 0, sum = 0;
	for (int left = 0; left < n; left++) {
		while (right < n && (sum ^ a[right]) == sum + a[right]) {
			sum += a[right++];
		}
		ans += right - left;
		if (left == right)right++;
		else sum -= a[left];
	}
	cout << ans << endl;

	return 0;
}

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

vector<ll> par;
vector<vector<ll>> tree;
vector<bool> used;
vector<ll> tour;

void dft(ll p){
  used[p]=true;
  for(ll pp:tree[p]){
    if(!used[pp]){
      if(par[pp]==-1)par[pp]=p;
      tour.push_back(pp);
      dft(pp);
      tour.push_back(pp);
    }
  }
}

int main(){
  ll n,q;
  cin>>n>>q;
  tree.assign(n,vector<ll>());
  used.assign(n,false);
  par.assign(n,-1);
  rep(i,n-1){
    ll a,b;
    cin>>a>>b;
    a--;b--;
    tree[a].push_back(b);
    tree[b].push_back(a);
  }
  tour.push_back(0);
  dft(0);
  tour.push_back(0);
  vector<ll> ans(n,0);
  rep(i,q){
    ll p,x;
    cin>>p>>x;
    p--;
    ans[p]+=x;
  }
  rep(i,n-1){
    ans[i+1]+=ans[par[i+1]];
  }
  rep(i,n)cout<<ans[i]<<" ";
}


Measured memory_bytes: 29932
/*
        _            _                  _            _       _     _         _   _          _          _             _        
       / /\         / /\               / /\         / /\    / /\  /\ \      /\_\/\_\ _     /\ \       /\ \     _    /\ \      
      / /  \       / /  \             / /  \       / / /   / / /  \ \ \    / / / / //\_\   \ \ \     /  \ \   /\_\ /  \ \     
     / / /\ \__   / / /\ \           / / /\ \__   / /_/   / / /   /\ \_\  /\ \/ \ \/ / /   /\ \_\   / /\ \ \_/ / // /\ \_\    
    / / /\ \___\ / / /\ \ \         / / /\ \___\ / /\ \__/ / /   / /\/_/ /  \____\__/ /   / /\/_/  / / /\ \___/ // / /\/_/    
    \ \ \ \/___// / /  \ \ \        \ \ \ \/___// /\ \___\/ /   / / /   / /\/________/   / / /    / / /  \/____// / / ______  
     \ \ \     / / /___/ /\ \        \ \ \     / / /\/___/ /   / / /   / / /\/_// / /   / / /    / / /    / / // / / /\_____\ 
 _    \ \ \   / / /_____/ /\ \   _    \ \ \   / / /   / / /   / / /   / / /    / / /   / / /    / / /    / / // / /  \/____ / 
/_/\__/ / /  / /_________/\ \ \ /_/\__/ / /  / / /   / / /___/ / /__ / / /    / / /___/ / /__  / / /    / / // / /_____/ / /  
\ \/___/ /  / / /_       __\ \_\\ \/___/ /  / / /   / / //\__\/_/___\\/_/    / / //\__\/_/___\/ / /    / / // / /______\/ /   
 \_____\/   \_\___\     /____/_/ \_____\/   \/_/    \/_/ \/_________/        \/_/ \/_________/\/_/     \/_/ \/___________/    
                                                                                                                              
*/
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for(int i = 0;i < (n);++i)

#define endl '\n'
#define pb emplace_back
#define mkp make_pair
#define p_q priority_queue
#define INF 2000000000
#define PI 3.1415926
#define coutdb cout << fixed << setprecision(13)

const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};
const int dx_8[]={1,1,0,-1,-1,-1,0,1}, dy_8[]={0,-1,-1,-1,0,1,1,1};
const long long MOD = 1e9+7;

// typedef long long ll;
#define int long long

template <typename T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <typename T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template <typename T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template <typename T> inline T nHr(T a,T b){return nCr(a+b-1,b);}

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

  int X, A; cin >> X >> A;
  if(X < A) cout << 0 << endl;
  else cout << 10 << endl;
}

Measured memory_bytes: 256
# Gauss
module Gauss
  def self.calc(a)
    a.length.times do |k|
      pivot = a[k][k]
      i = k

      i.upto(a[k].length - 1) do |j|
        a[k][j] /= pivot
      end

      a.length.times do |j|
        if (j != k)
          d = a[j][k]
          l = k
          l.upto(a[k].length - 1) do |m|
            a[j][m] -= d * a[k][m]
          end
        end
      end
    end

    a
  end
end

while line = gets
  a, b, c, d, e, f = line.chomp.split.map(&:to_f)
  g = [[a, b, c], [d, e, f]]
  answer = Gauss.calc(g)
  puts sprintf('%.3f %.3f', answer[0][2] + 0.0, answer[1][2] + 0.0)
end

Measured memory_bytes: 8688
h, w, k = map(int, input().split())
board = [list(input()) for _ in range(h)]

ans = 0
for i in range(1 << h):
    for j in range(1 << w):
        cnt = 0
        for y in range(h):
            for x in range(w):
                if i >> y & 1:
                    continue
                if j >> x & 1:
                    continue
                if board[y][x] == '#':
                    cnt += 1
        if cnt == k:
            ans += 1
print(ans)


Measured memory_bytes: 9204
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long a = sc.nextLong();
		long b = sc.nextLong();
		long d = (a - b);

		long[] h = new long[n];
		long hi = 0;
		for (int i = 0; i < n; i++) {
			h[i] = sc.nextLong();
			hi = Math.max(hi, h[i]);
		}

		long lo = -1;
		while ((hi - lo) > 1) {
			long m = (hi + lo) / 2;
			long count = 0;
			for (int i = 0; i < n; i++) {
				if (h[i] < m * b) continue;
				count += (h[i] - (m * b)) / d;
				count += ((h[i] - (m * b)) % d > 0) ? 1 : 0;
				if (count > m) break;
			}

			if (count <= m) {
				hi = m;
			} else {
				lo = m;
			}
		}

		System.out.println(hi);
	}
}


Measured memory_bytes: 50072
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
/*
 execution in cmd of windows:
 
 
  g++ p1.cpp -o p1
  
  
  p1
 
 */
typedef double dd;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define nl <<"\n"
#define con continue
#define br break
#define vll vector<ll>
#define vpll vector<pair<ll,ll> >
ll mx=INT_MAX;
ll mi=INT_MIN;
#define mem0(a)         memset(a,0,sizeof(a))
#define mem1(a)         memset(a,-1,sizeof(a))
#define all(v) v.begin(), v.end()
#define fsort(v) sort(all(v))  
#define rsort(v) sort(v.rbegin(),v.rend())
#define rev(v) reverse(all(v))
#define maxc(v) max_element(all(v))
#define minc(v) min_element(all(v))
#define sumv(v,x) accumulate(v.begin(),v.end(),x);
const ll mod = 1000000007;
const ll inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3fLL;
#define io { ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0); }
#define cer cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
#define cs ll t;cin>>t;while(t--)



int main()
{
	#ifndef ONLINE_JUDGE
		ifstream cin("in.in");
		ofstream cout("out.out");
	#endif
	
        io;
        //////////////////////////////////
        
        	ll i,j,k,p=0,q=0,l,r,d;
        	cin>>l>>r>>d;
        	cout<<(r/d)-(l-1)/d;
        
    	//////////////////////////////////
        cer;
}


Measured memory_bytes: 3712
#include<iostream>
#include<string>
#include<cstdio>
using namespace std;
int main(void){
    for(;;){
	int n,k;
	int sum=0,ans=0;
	int a[100010]={0};
	cin >> n;
	cin >> k;
	if(n==0&&k==0)break;
	for(int i=0;i<n;i++){
	    cin >> a[i];
        }
    for(int i=0;i<k;i++){
        sum+=a[i];
        }
    ans=sum;
    for(int i=k;i<n;i++){
        sum+=a[i];
        sum-=a[i-k];
        ans=max(ans,sum);

    }
    cout << ans << endl;

    }


	return 0;
}

Measured memory_bytes: 1556
// g++ -std=c++11 -O2 -Wall -Wl,--stack=268435456

#include <bits/stdc++.h>
using namespace std;

typedef long long          ll;
typedef vector<int>        vi;
typedef vector< vi >       vvi;
typedef pair<int, int>     pi;
typedef vector< pi >       vpi;

typedef vector<ll>         vl;
typedef vector< vector <ll> >   vvl;

#define LARGE_INT     1000000007
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for (int i = (int)(a); i < (int)(b); i++)


int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int  n, k;
    cin >> n >> k;
    vi a(n);
    vl ways(k+1,0); // ways[j]; number of ways to divide j candies among first i kids.
    vl ps(k+2,0);   // prefix sum of ways: ps[j] sum up to ways[j-1] 
    
    //vvl dp(n+1, vl(k+1, 0));  // dp[i][j]  number of ways to divide j candies among first i kids
    
    REP(j, 0, n) { cin >> a[j]; }
    ways[0] = 1;
    REP(i, 0, n) {  // adding a[i] into consideration
        // compute prefix sum
        REP(j, 0, k+1) { ps[j+1] = ps[j] + ways[j]; }
        REP(j, 0, k+1) {
            int bi = max(0, j-a[i]);
            ways[j] = (ps[j+1] - ps[bi]) % LARGE_INT;
        }
    }
    cout << ways[k];
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(),v.rend() //reverse
#define vl vector<long long>v(n);
#define mii unordered_map<ll,ll>
double pi = 2*acos(0.0);
//ll power(ll a,ll b){ ll res=1;while(b){if(b&1)res=res*a;b=b/2; a=(a*a); }return res;}
 
 
    
      
 int main()
 {
       ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
       ll tst;
       tst=1;
       //cin>>tst;
    
       while(tst--)
       {
         string s;
         cin>>s;
         if(s[0]>='a'&&s[0]<='z')
         {
             cout<<"a"<<endl;  
         }else
         {
               cout<<"A"<<endl;
         }
       }
       
 }

Measured memory_bytes: 3584
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define bit(n) (1<<(n))
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
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;}
int const INF = 1001001001;


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

int N; cin >> N;
int A = 0, B = 0, C = 0;
int cnt = 0;
rep(i,N) {
    string s;
    cin >> s;
    rep(i,SZ(s)-2) {
        if(s.substr(i,2) == "AB") cnt++;
    }
    if(s[0] == 'B' && s[SZ(s)-1] == 'A') {
        C++;
        continue;
    }
    if(s[0] == 'B') B++;
    if(s[SZ(s)-1] == 'A') A++;
}
if(A + B == 0 && C > 0) cout << cnt + C - 1 << endl;
else cout << cnt + min(A, B) + C << endl;
return 0;
}

Measured memory_bytes: 256
use proconio::{fastout, input};

#[fastout]
fn main() {
    input!(n: usize,k:usize,mut h:[usize;n]);

    h.sort();

    let mut min = 1_000_000_000;
    for i in 0..n - k + 1 {
        let sum: Vec<&usize> = h.iter().skip(i).step_by(k - 1).take(2).collect();
        min = std::cmp::min(min, sum[1] - sum[0]);
    }

    println!("{}", min);
}


Measured memory_bytes: 4212
def main():
    import sys
    from itertools import accumulate
    from collections import Counter

    n = int(input())
    a = list(map(int, sys.stdin.readline().split()))
    b = [0] + list(accumulate(a))
    c = Counter(b)

    ans = 0
    for v in c.values():
        ans += v * (v - 1) // 2

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 41448
n,a,b = map(int,input().split())
mod = 10**9+7
import sys
sys.setrecursionlimit(10**9)
ans = 1
now = n
def power(x, y):
  if   y == 0     : return 1
  elif y == 1     : return x % mod
  elif y % 2 == 0 : return power(x, y//2)**2 % mod
  else            : return power(x, y//2)**2 * x % mod
ans = power(2,n)
com = [0]*(b+1)
com[0]=1
N = b+1
inv_t = [0]+[1]
for i in range(2,N):
  inv_t += [inv_t[mod % i] * (mod - int(mod / i)) % mod]
for i in range(1,b+1):
  com[i] = ((com[i-1]*(n-i+1))%mod)*(inv_t[i])%mod
ans -= com[a]+com[b]+1
print(ans%mod)

Measured memory_bytes: 18892
#include <bits/stdc++.h>
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

int main() {
	std::vector<int> c = {0, 2, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0};
	int a, b; scanf("%d%d", &a, &b);
	
	if(c[a - 1] == c[b - 1]) printf("Yes\n");
	else printf("No\n");
	return 0;
}


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

int main(){
    for (int i=0;; i++){
        int H, W;
        cin >> H >> W;
        if (H==0 && W==0) break;
        for (int j=0; j<H; j++){
            for (int k=0; k<W; k++) {cout << "#";}
            cout << endl;
        }
        cout << endl;
    }
    return 0;
}


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


typedef long long ll;
#define FOR(i,a,b)   for(ll i = (a); i < (b); i++ )
#define REP(i, n)    FOR(i,0,n)
typedef pair< ll, ll >   cp2;
typedef pair< ll, cp2 >   cp3;
#define fi first
#define se second
#define sec  se.fi
#define thr  se.se
const ll mod = 1000000007;

int K;
string A[112];
string B[112];
int X = 0;
int Y = 0;
string ans = "Hikiwake-kun";

int main(){
    
    cin>>K;
    
    REP( i, K ) cin>>A[i];
    REP( i, K ) cin>>B[i];
    
    REP( i, K ){
        if( A[i] == "tameru" ){
            if( X < 5 ) X++;
        }
        if( B[i] == "tameru" ){
            if( Y < 5 ) Y++;
        }
        
        if( A[i] == "kougekida"){
            if( X == 0 ){
                if( B[i] == "kougekida" && Y == 0 ) continue;
                ans = "Nakajima-kun";
                break;
            }
            if( B[i] == "kougekida" ){
                if( X > Y ){
                    ans = "Isono-kun";
                    break;
                }
                else if( X < Y ){
                    ans = "Nakajima-kun";
                    break;
                }
                else{
                    X = 0;
                    Y = 0;
                }
            }
            else if( B[i] == "mamoru" ){
                if( X == 5 ){
                    ans = "Isono-kun";
                    break;
                }
                X = 0;
            }
            else if( B[i] == "tameru" ){
                ans = "Isono-kun";
                break;
            }
        }
        
        else if( B[i] == "kougekida" ){
            if( Y == 0 ){
                ans = "Isono-kun";
                break;
            }
            if( A[i] == "mamoru" ){
                if( Y == 5 ){
                    ans = "Nakajima-kun";
                    break;
                }
                Y = 0;
            }
            if( A[i] == "tameru" ){
                ans = "Nakajima-kun";
                break;
            }
        }
    }
    
    cout<<ans<<endl;
    
    return 0;
}



Measured memory_bytes: 3216
/*
 Templatka c++ Kacper Fis																							   																											   //
*/

#include <iostream>
#include <cstdio>
#include <limits>
#include <cstdlib>
#include <utility>
#include <iterator>
#include <bitset>
#include <list>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <cmath>
#include <string>
#include <time.h>
#include <iomanip>
#include <sstream>
#include <bits/stdc++.h>

using namespace std;

const int INF = 1000000001;
const float PI = 3.14;
typedef long long LL;

typedef vector<int> vi;
typedef list<int> li;
typedef queue<int> qi;
typedef pair<int,int> ii;
typedef map<string,int> msi; //np msi['nazwa'] = 'liczba'
typedef vector<ii> vii; //vector par<int>, do tworzenia tablicy dla grafów wagowych #dijkstra #Bellman_Ford
typedef priority_queue< ii, vector<ii>, greater<ii> > pq; //kolejka priorytetowa vectorów par(top()=min) #dijkstra


#define print_list(x) for(it = (x).begin(); it != (x).end(); it++) {cout << *it << " ";}
#define print_vector(x) for(it2 = (x).begin(); it2 != (x).end(); it2++) {cout << *it2 << " ";}
#define search_list(x) for(it = (x).begin(); it != (x).end(); it++)
#define search_vector(x) for(it2 = (x).begin(); it2 != (x).end(); it2++);
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define mp(x, y) make_pair(x, y)
///////////////////////////////////////////////GLOBAL DEFINITIONS////////////////////////////////////////////////////////

int tab[100005];

///////////////////////////////////////////////////FUNCTIONS/////////////////////////////////////////////////////////////



/////////////////////////////////////////////////////MAIN////////////////////////////////////////////////////////////////
int main(int argc, char* argv[])
{ios_base::sync_with_stdio(false); cin.tie(NULL);
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	
	int n, k;
	cin >> n >> k;
	for(int i = 0; i < n; i++){
		cin >> tab[i];
	}

	int ans = 0;
	for(int i = 0; i < n; i++){
		int temp = k - tab[i];
		if(temp < tab[i]){ //od prawej
			ans += 2*temp;
		}
		else{ //od lewej
			ans += 2*tab[i];
		}
	}

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


Measured memory_bytes: 256
from sys import exit
A = input()
B = input()
if len(A) > len(B):
  print("GREATER")
elif len(A) < len(B):
  print("LESS")
else:
  for a,b in zip(A,B):
    if a > b:
      print("GREATER")
      exit()
    elif a < b:
      print("LESS")
      exit()
  print("EQUAL")

Measured memory_bytes: 3060
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007


# 挿入dp
def solve():
    n,x = LI()
    s = LI()
    s.sort()
    dp = [[0]*(x+1) for i in range(n+1)] # dp[i][j] := スタート時点の値がjの時に最初のi個の順列すべてを試し、えられる総和
    for j in range(x+1):
        dp[0][j] = j # dpの定義より明らか
        for i in range(n):
            si = s[i]
            ni = i+1
            nd = dp[i][j%si] # 先頭にsiを挿入 (スタートの値がj%siとなる)
            nd += i*dp[i][j] # 先頭以外にsiを挿入 (スタートの値も間の値も変わらない)
            dp[ni][j] += nd
            if dp[ni][j] >= mod:
                dp[ni][j] %= mod
    print(dp[n][x])
    return

# 空間の節約
def solve_1():
    n,x = LI()
    s = LI()
    s.sort()
    #dp = [[0]*(x+1) for i in range(n+1)] # dp[i][j] := スタート時点の値がjの時に最初のi個の順列すべてを試し、えられる総和
    dp = [j for j in range(x+1)]
    for i in range(n):
        si = s[i]
        ndp = [0]*(x+1)
        for j in range(x+1):
            nd = dp[j%si] # 先頭にsiを挿入 (スタートの値がj%siとなる)
            nd += i*dp[j] # 先頭以外にsiを挿入 (スタートの値も間の値も変わらない)
            ndp[j] += nd
            if ndp[j] >= mod:
                ndp[j] %= mod
        dp = [j for j in ndp]
    print(dp[x])
    return

#Solve
if __name__ == "__main__":
    solve_1()


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

int main() {
	// your code goes here
	int x, y;
	bool doing = true;
	while(x+y){
	cin >> x >> y;
	
	if(x != 0 || y != 0){
		int s1 , s2;
		if (x < y) {s1 =x; s2 =y;}
		else {s1 = y; s2 = x;}
		cout << s1 << " " << s2 << endl;
	}
	}
	return 0;
}

Measured memory_bytes: 1160
n = int(input())
d = list(map(int, input().split()))
m = int(input())
t = list(map(int, input().split()))
dict = {}
for i in d:
  if i in dict:
    dict[i] += 1
  else:
    dict[i] = 1
for i in t:
  if dict.get(i, 0) > 0:
    dict[i] -= 1
  else:
    print("NO")
    exit()
print("YES")

Measured memory_bytes: 41316
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

"""
・2x2内の偶奇が不変量。これが偶数なら、そこは単色でとれる
・単色でとれる領域を調べる -> 色変更なしに大きい長方形をとる問題になる
・ベースラインを固定すると、ヒストグラムの長方形の問題（アリ本）
"""

H,W = map(int,readline().split())
grid = read().replace(b'\r',b'').replace(b'\n',b'')

H,W

# 左上に集める
cnt = [0]*(H*W)
for x in range(H*W):
    if grid[x]==ord('#'):
        # その場
        cnt[x]^=1
        # 左
        if x%W:
            cnt[x-1]^=1
        # 上
        if x>=W:
            cnt[x-W]^=1
        if x%W and x>=W:
            cnt[x-W-1]^=1

max_area = 0
height = [1]*(W-1)
for i in range(H-1):
    for j in range(W-1):
        if cnt[W*i+j]:
            height[j]=1
        else:
            height[j]+=1
    # 最大長方形の変種。
    stack=[]
    for j,h in enumerate(height+[0]):
        while stack:
            prev_h = height[stack[-1]]
            if prev_h < h:
                break
            stack.pop()
            left_end = -1 if not stack else stack[-1]
            area = (j-left_end)*prev_h
            if max_area < area:
                max_area = area
        stack.append(j)

# 幅1の長方形は2x2を素材としない
if max_area < max(W,H):
    max_area = max(W,H)
print(max_area)

Measured memory_bytes: 105004