akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <cmath>
#include <vector>

typedef long long ll;

using namespace std;

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

    vector<ll> a(n);

    ll p (k);
    ll _max (-0xF3F3F3F3);
    ll d (k-1);
    ll i (0);

    while (true)
    {
        _max = p + d * i;
        i++;

        if (_max >= n)
            break;

        //cout << ' ' << _max;
    }

    cout << i << endl;

    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using LL = long long; using PII = pair<LL, LL>; using VI = vector<LL>; using VVI = vector<VI>;
using VB = vector<bool>; using VS = vector<string>; using VP = vector<PII>;
#define VV(T)        vector<vector<T>>
#define PB           push_back
#define MP           make_pair
#define SZ(a)        LL((a).size())
#define EACH(x, c)   for (auto x : (c))
#define ALL(c)       (c).begin(), (c).end()
#define REVERSE(c)   reverse(ALL(c))
#define SORT(c)      stable_sort(ALL(c))
#define RSORT(c)     stable_sort((c).rbegin(), (c).rend())
#define FOR(i, a, b) for (LL i = (a); i < (b); ++i)
#define REP(i, n)    FOR(i, 0, n)
#define $(x)         {cout << #x << " = " << (x) << endl;}


int main() {
    string S;
    cin >> S;
    char prev = 'a';
    REP(i, SZ(S)) {
        if (S[i] == prev) {
            cout << "Bad" << endl;
            return 0;
        }
        prev = S[i];
    }
    cout << "Good" << endl;
	
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
template<typename T>inline T read(){
	T f=0,x=0;char c=getchar();
	while(!isdigit(c)) f=c=='-',c=getchar();
	while(isdigit(c)) x=x*10+c-48,c=getchar();
	return f?-x:x;
}
namespace run{
	const int N=4e4+9,mod=998244353;
	inline int add(int x,int y){return x+y>=mod?x-mod+y:x+y;}
	inline int sub(int x,int y){return x>=y?x-y:x+mod-y;}
	inline int qpow(int x,int y){
		int ret=1;
		while(y){
			if(y&1) ret=1LL*x*ret%mod;
			x=1LL*x*x%mod,y>>=1;
		}
		return ret;
	}

	int rev[N],limit,bit,Gi=qpow(3,mod-2);
	inline void prepare(int len){
		limit=1,bit=0;
		while(limit<len) limit<<=1,bit++;
		for(int i=1;i<limit;i++)
			rev[i]=(rev[i>>1]>>1)|((i&1)<<(bit-1));
	}
	inline void NTT(int *a,int inv){
		for(int i=1;i<limit;i++)
			if(i<rev[i]) swap(a[i],a[rev[i]]);
		for(int mid=1;mid<limit;mid<<=1){
			int tmp=qpow(~inv?3:Gi,(mod-1)/(mid<<1));
			for(int i=0,R=mid<<1;i<limit;i+=R)
				for(int j=0,omega=1;j<mid;j++,omega=1LL*omega*tmp%mod){
					int x=a[i+j],y=1LL*omega*a[i+j+mid]%mod;
					a[i+j]=add(x,y),a[i+j+mid]=sub(x,y);
				}
		}
		if(inv==-1){
			inv=qpow(limit,mod-2);
			for(int i=0;i<limit;i++) a[i]=1LL*a[i]*inv%mod;
		}
	}

	int n,m,fac[N],ifac[N],f[201][8009];
	inline int C(int _n,int _m){
		if(_n<0 || _m<0 || _n<_m) return 0;
		return 1LL*fac[_n]*ifac[_m]%mod*ifac[_n-_m]%mod;
	}
	int A[N],B[N];
	inline void dp(){
		for(int i=1;i<=n;i++) B[i]=ifac[i+2];
		prepare(n+n+1),NTT(B,1),f[0][0]=1;
		for(int j=1;j<=m;j++){
			for(int i=0;i<=n;i++) A[i]=1LL*f[j-1][i]*ifac[i]%mod;
			for(int i=n+1;i<limit;i++) A[i]=0;
			NTT(A,1);
			for(int i=0;i<limit;i++) A[i]=1LL*A[i]*B[i]%mod;
			NTT(A,-1);
			for(int i=1;i<=n;i++) f[j][i]=1LL*A[i]*fac[i+2]%mod;
			for(int i=1;i<=n;i++) f[j][i]=(1LL*(1+i+C(i,2))*f[j-1][i]+f[j][i])%mod;
			f[j][0]=1;

		//	for(int i=1;i<=n;i++) cout<<f[j][i]<<" ";
		//	cout<<endl;
		}
	}

	int main(){
		n=read<int>(),m=read<int>();
		fac[0]=ifac[0]=1;
		for(int i=1;i<=n+3;i++) fac[i]=1LL*fac[i-1]*i%mod;
		ifac[n+3]=qpow(fac[n+3],mod-2);
		for(int i=n+2;i>=1;i--) ifac[i]=1LL*ifac[i+1]*(i+1)%mod;
		dp();

		int ans=0;
		for(int i=0;i<=n;i++) ans=(1LL*C(n,i)*f[m][i]+ans)%mod;
		printf("%d\n",ans);
		return 0;
	}
}
int main(){
#ifdef my
	freopen(".in","r",stdin);
	freopen(".out","w",stdout);
#endif
	return run::main();
}

Measured memory_bytes: 10076
#include <iostream>
using namespace std;
typedef long long ll;
ll M = 1000000007LL;
ll inv(ll K) {
  ll A = M - 2;
  ll ret = 1;
  ll D = K;
  while (A > 0) {
    if (A % 2 == 1) {
      ret = (ret * D) % M;
    }
    D = (D * D) % M;
    A /= 2;
  }
  return ret;
}
ll F[2000005];
ll I[2000005];
int main() {
  ios::sync_with_stdio(false);
  ll r1, c1, r2, c2;
  cin >> r1 >> c1 >> r2 >> c2;
  ll ret = 0;
  F[0] = 1;
  I[0] = 1;
  for (ll i = 1; i <= r2+c2+1; i++) {
    F[i] = (F[i-1] * i) % M;
    I[i] = inv(F[i]);
  }
  for (ll i = c1; i <= c2; i++) {
    // sum(f(i+j, i)) = f(i+r2+1, i+1)
    // f(i+r2+1, i+1) = (i+r2+1)! / ((i+1)! * (r2)!)
    ll R = F[i+r2+1];
    //R = (R * inv(F[i+1])) % M;
    //R = (R * inv(F[r2])) % M;
    R = (R * I[i+1]) % M;
    R = (R * I[r2]) % M;
    // sum(f(i+j, i)) = f(r1, i+1)
    // f(i+r1, i) = (i+r1)! / ((i+1)! * (r1-1)!)
    ll L = F[i+r1];
    //L = (L * inv(F[i+1])) % M;
    //L = (L * inv(F[r1-1])) % M;
    L = (L * I[i+1]) % M;
    L = (L * I[r1-1]) % M;
    //cout << R << ' ' << L << endl;
    ret = (ret + R) % M;
    ret = ((ret - L) % M + M) % M;
  }
  cout << ret << endl;
}

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

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

	int ans = 0;
	for( int B = 0; B < N; B++ ) {
		vector<string> T( N, string( N, ' ' ) );
		for( int i = 0; i < N; i++ ) {
			for( int j = 0; j < N; j++ ) {
				T[i][j] = S[i][(j + B) % N];
			}
		}

		int flag = 0;
		for( int i = 0; i < N; i++ ) {
			for( int j = 0; j < N; j++ ) {
				if( T[i][j] != T[j][i] ) {
					flag = 1;
					break;
				}
			}
			if( flag ) break;
		}
		if( flag == 0 ) ans += N;
	}

	cout << ans << endl;
}


Measured memory_bytes: 3892
N, Z, W = map(int, input().split())
a_list = [i for i in map(int, input().split())]

if N == 1:
    print(abs(W-a_list[0]))
    exit()
    
max_a = max(a_list)
print(max(abs(a_list[-1]-W), abs(a_list[-2]-a_list[-1])))
    

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

using namespace std;

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

#define reps(i,f,n) for(int i = int(f); i <= int(n); i++)
#define rep(i,n) reps(i,0,int(n)-1)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)

#define all(x) (x).begin(),(x).end()
#define X first
#define Y second

#define sz size()
#define eb emplace_back
#define pb push_back

int main(void){
  int a, b, n;
  cin >> n >> a >> b;
  cout << min(n*a, b) << endl;
  return 0;
}


Measured memory_bytes: 768
import sys


def find_sum_of_digits(n):
    sum_of_digits = 0
    while n>0:
        sum_of_digits = sum_of_digits + n%10
        n = int(n/10)
    return sum_of_digits


n = int(input())
sum_of_digits = find_sum_of_digits(n)
if n % sum_of_digits == 0:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 2940
package main

import (
	"bufio"
	"errors"
	"fmt"
	"io"
	"math"
	"os"
	"sort"
	"strconv"
)

func main() {
	sc := NewScanner(os.Stdin)
	n, _ := sc.NextInt()
	a, b := make([]int, n), make([]int, n)
	for i := 0; i < n; i++ {
		a[i], _ = sc.NextInt()
		b[i], _ = sc.NextInt()
	}
	ans := solve(n, a, b)
	fmt.Println(ans)
}

func solve(n int, a []int, b []int) int {
	sort.Slice(a, func(i, j int) bool { return a[i] < a[j] })
	sort.Slice(b, func(i, j int) bool { return b[i] < b[j] })
	if n%2 == 0 {
		m1 := b[n/2-1] - a[n/2-1] + 1
		m2 := b[n/2] - a[n/2] + 1
		return m1 + m2 - 1
	}
	return b[n/2] - a[n/2] + 1
}

// Scanner is a wrapper of bufio.Scanner which is customized for competitive programing.
type Scanner struct {
	bufio.Scanner
}

// NewScanner is a constructor for Scanner.
func NewScanner(r io.Reader) *Scanner {
	sc := Scanner{*bufio.NewScanner(r)}
	sc.Buffer([]byte{}, math.MaxInt64)
	sc.Split(bufio.ScanWords)
	return &sc
}

// NextInt reads a integer from io stream.
func (sc *Scanner) NextInt() (int, error) {
	if !sc.Scan() {
		return -1, errors.New("failed to scan")
	}
	return strconv.Atoi(sc.Text())
}


Measured memory_bytes: 8352
import math

def abs(x):
  return x if x >= 0 else -x

a,b,h,m = (int(x) for x in input().split())

x = 30 * h + 0.5 * m
y = 6 * m

ang = abs(x - y)
  
print(math.sqrt(a**2 + b**2 - 2*a*b*math.cos(math.radians(ang))))

Measured memory_bytes: 9520
#include <iostream>
#include <utility>
#include <stdint.h>
#include <vector>
#include <algorithm>

using namespace std;

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

  vector<unsigned> A, sortedA;
  A.reserve(N);
  sortedA.reserve(N);

  for (int n=0; n<N; ++n) {
    unsigned a;
    cin >> a;
    A.push_back(a);
    sortedA.push_back(a);
  }

  sort(sortedA.begin(), sortedA.end());

  for (int n=0; n<N; ++n) {
    if (sortedA[N-1] != A[n])
      cout << sortedA[N-1] << endl;
    else
      cout << sortedA[N-2] << endl;
  }

  return 0;
}


Measured memory_bytes: 3200
#pragma GCC optimize ("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
using namespace std;
using Int = long long;
typedef pair<int,int> P; typedef pair<Int,Int> Pl;
const int mod = 1e9+7;
const Int Inf = 1e17;
#define END {cout<<ans<<'\n'; return 0;}
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
#define mp make_pair
#define Pr(t) priority_queue<t>
#define gPr(t) priority_queue<t,vector<t>,greater<t>>
#define V(t) vector<t>
#define rep(i,n) for(int(i)=0; i<n; i++)
#define rer(i,l,r) for(int i=l; i<=r; i++)
#define gnr(i,l,r) for(int i=r; i>=l; i--)
#define eb emplace_back
#define pri1(a) cout<<(a)<<'\n'
#define pri2(a,n) {rep(pri2i,n-1)cout<<a[pri2i]<<' '; cout<<a[n-1]<<'\n';}
#define prip(p) cout<<p.fi<<' '<<p.se<<'\n'
template<class T> inline bool cmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool cmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

Int n,m,_,x,y,q;
string s,sb;
bool ok;
char cf,cb;

Int l;

template< typename T >
struct edge {
  int src, to;
  T cost;

  edge(int to, T cost) : src(-1), to(to), cost(cost) {}

  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

  edge &operator=(const int &x) {
    to = x;
    return *this;
  }

  operator int() const { return to; }
};

template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WeightedGraph = vector< Edges< T > >;
using UnWeightedGraph = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;

template< typename T >
vector< T > dijkstra(WeightedGraph< T > &g, int s) {
  const auto INF = numeric_limits< T >::max();
  vector< T > dist(g.size(), INF);

  using Pi = pair< T, int >;
  priority_queue< Pi, vector< Pi >, greater< Pi > > que;
  dist[s] = 0;
  que.emplace(dist[s], s);
  while(!que.empty()) {
    T cost;
    int idx;
    tie(cost, idx) = que.top();
    que.pop();
    if(dist[idx] < cost) continue;
    for(auto &e : g[idx]) {
      auto next_cost = cost + e.cost;
      if(dist[e.to] <= next_cost) continue;
      dist[e.to] = next_cost;
      que.emplace(dist[e.to], e.to);
    }
  }
  return dist;
}

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

  cin>>n>>m>>l; WeightedGraph<Int>g(n),h(n); Int c;
  rep(i,m){
    cin>>x>>y>>c;
    if(c>l)continue;
    g[--x].eb(--y,c); g[y].eb(x,c);
  }
  V(Int)d1[n],d2[n];
  rep(i,n)d1[i]=dijkstra(g,i);
  rep(i,n)rer(j,i+1,n-1){
    if(i==j)continue;
    if(d1[i][j]<=l){h[i].eb(j,1); h[j].eb(i,1);}
  }
  rep(i,n)d2[i]=dijkstra(h,i);
  cin>>q;
  rep(i,q){
    cin>>x>>y;
    cout<<(d2[--x][--y]>Inf?-1:d2[x][y]-1)<<'\n';
  }
}

Measured memory_bytes: 6792
import java.security.KeyStore.TrustedCertificateEntry
import java.util
import java.util.{ArrayList, Collections, Comparator, List => JList}
import scala.math._

import scala.collection.mutable
import scala.collection.mutable.{ArrayBuffer, ListBuffer}
import scala.util.{Failure, Success, Try}

object Main{
  val LINE_SEPARATOR = "\n"
  def main(args: Array[String]): Unit = {
    if (sys.env.getOrElse("TEST", "")=="1"){
      println(test());
    }else{
      val input=io.Source.stdin.getLines().mkString(LINE_SEPARATOR);
      println(solve(input).trim());
    }
  }

  def init (nRows: Int, nCols: Int, default: Int) = Array.tabulate(nRows,nCols)( (x,y) =>  default)

  def sortIgnoreCase1(list: JList[String]): JList[String] = {
    val r = new ArrayList[String](list)
    Collections.sort(r, new Comparator[String] {
      override def compare(o1: String, o2: String): Int = o1.compareToIgnoreCase(o2)
    })
    r
  }

  def solve(input: String): String = {
    val s = input.split(LINE_SEPARATOR).head
    val t = input.split(LINE_SEPARATOR).tail.head
    if (t matches s"$s.") "Yes" else "No"
  }

  def divisors(n: Long): Vector[Long] = {
    val halfList = (1 to sqrt(n).toInt).toVector.filter(_ % n == 0).map(_.toLong)
    val reversedList = if (sqrt(n).floor == sqrt(n)) halfList.reverse.tail.map(n/_) else halfList.reverse.map(n/_)
    halfList ++ reversedList
  }

  def gcd(m: Long, n: Long): Long = n match {
    case 0 => m
    case _ => gcd(n, m % n)
  }
  def lcm(a: Long, b: Long): Long = a * b / gcd(a, b)

  val tests=List(
    """chokudai
      |chokudaiz""".stripMargin -> """Yes
                                         |""".stripMargin,
    """snuke
      |snekee""".stripMargin -> """No
                                      |""".stripMargin
  )

  def test():String= {
    return tests.map{case (i,o)=>(i.trim(),o.trim())}
      .zipWithIndex.map{
      case ((input,outputExpect),i)=>{
        val output=solve(input).trim();
        s"test${i+1}:"+(if(output==outputExpect){
          "Passed"
        }else{
          s"Failed\nexpect:\n${outputExpect}\noutput:\n${output}"
        })
      }}
      .mkString("\n");
  }
}

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

bool chmax(int& a, int b){
    if (a < b){
        a = b; return true;
    }
    else return false;
}

int main(){
    int N;
    string s;
    cin >> N >> s;
    int score=0, ans=0;
    for (int i=0; i<N; i++){
        if (s[i] == 'I') score++;
        else if (s[i] == 'D') score--;
        chmax(ans, score);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3572
from itertools import*
N,K,Q,*A=map(int,open(0).read().split())
l=len
s=sorted
print(min(c[Q-1]-Y for c,Y in zip((s(sum((v[:l(v)-K+1]for v in(s(v)for k,v in groupby(A,lambda a:a>=Y)if k)if l(v)>=K),[]))for Y in A),A)if l(c)>=Q))

Measured memory_bytes: 65116
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<int,int>;

int main(void){
    int n;
    cin >> n;
    int ans = 0;
    for(int i = 1; i <= n; i += 2){
        int yks = 0;
        for(int j = 1; j <= i; j++){
            if(i % j == 0) yks++;
        }
        if(yks == 8) ans++;
    }
    cout << ans << endl;
}

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

int main()
{
    //データ定義
    int numA;
    int numB;
    int numC;
    int divisor = 0;

    //3つの整数を読み込む
    cin >> numA >> numB >> numC;

    //約数の数を計算する
    for(int i = numA; i <= numB; i++){
        if(numC % i == 0){
            divisor++;
        } 
    }

    //結果出力
    cout << divisor << endl;

    return 0;
}


Measured memory_bytes: 3096
using System;
using System.Linq;
using System.Collections.Generic;

public class Program{
  public static void Main(){
    var abc = Array.ConvertAll(Console.ReadLine().Split(' '), UInt32.Parse);
    var flug = false;
    for(var i=1; i<abc[1]+1; i++){
      if((i*abc[0])%abc[1]==abc[2]){
        flug = true;
        break;
      }
    }
    Console.WriteLine(flug?"YES":"NO");
  }
}


Measured memory_bytes: 11092
n = int(input())
d = [list(map(int, input().split()))for _ in range(n)]

cnt = 0
for i, (p, q) in enumerate(d):
    if p == q:
        cnt += 1
    else:
        cnt = 0
    if cnt == 3:
        print("Yes")
        break
else:
    print("No")

Measured memory_bytes: 9172
#include <stdio.h>

int main(void) {
    char ch;

    while(1) {
      scanf("%c", &ch);
      if('a' <= ch && ch <= 'z') {
        printf("%c", ch-32);
      }
      else if('A' <= ch && ch <= 'Z') {
        printf("%c", ch+32);
      }
      else if(ch == ' ') {
        printf(" ");
      }
      else printf("%c", ch);

      if(ch == '\n') break;
    }

    return 0;
}


Measured memory_bytes: 2104
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <stack>
#include <deque>
#include <cmath>
#include <map>
using ll = long long;
using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  cout << (n-1) * (m-1) << endl;
}


Measured memory_bytes: 256
// C++ program to Replace every element
// by the bitwise xor of all other elements
#include <bits/stdc++.h>
using namespace std;

// Function to replace the elements
void ReplaceElements(int arr[], int n)
{
	int X = 0;

	// Calculate the xor of all the elements
	for (int i = 0; i < n; ++i) {
		X ^= arr[i];
	}

	// Replace every element by the
	// xor of all other elements
	for (int i = 0; i < n; ++i) {
		arr[i] = X ^ arr[i];
	}
}

// Driver code
int main()
{
    int n,i;cin>>n;
	int arr[n];
	for(i=0;i<n;i++)cin>>arr[i];

	ReplaceElements(arr, n);

	// Print the modified array.
	for (int i = 0; i < n; ++i) {
		cout << arr[i] << " ";
	}
	return 0;
}


Measured memory_bytes: 4312
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>
#include <bitset>
#include <cstdint>

using namespace std;
using lli = long long int;
using i64 = int64_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

int main() {
  i64 a, b, c, d;
  cin >> a >> b >> c >> d;
  cout << max(i64(0), min(b, d) - max(a, c)) << '\n';
  return 0;
}


Measured memory_bytes: 256
/* ex4_3
   shu_t */

#include<stdio.h>

//prototype declaration
int sub(int a,int b);
int add(int c);

int main(void){
  int west_mountain,east_mountain,dif_mountain,height,pile_up;
  //input no snow height 
  scanf("%d %d", &west_mountain,&east_mountain);
  //calculate difference of mountain
  dif_mountain = sub(west_mountain, east_mountain);
  //calculate true height of east_mountain
  height = add(dif_mountain);
  //calculate snow piled up mountain
  pile_up = sub(east_mountain,height);
  //output the answer
  printf("%d\n",pile_up);
  return 0;
}

int sub(int a,int b){//function of subtraction
  int dif;
  dif = b - a;
  return(dif);
}

int add(int c){//sum: from 1 to c
  int roop,sum;
  for(roop = 1; roop<=c; roop++){
    sum += roop;
  }
  return(sum);
}

Measured memory_bytes: 128
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
#define ln '\n'
constexpr long long MOD = 1000000007LL;
//constexpr long long MOD = 998244353LL;
typedef long long ll;
typedef unsigned long long ull; 
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
template<class T, class U> inline bool chmax(T &a, U b) { if (a < b) { a = b; return true;} return false; }
template<class T, class U> inline bool chmin(T &a, U b) { if (a > b) { a = b; return true;} return false; }
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


template <std::uint_fast64_t Modulus> 
struct ModInt {
    using u64 = std::uint_fast64_t;

    u64 a;

    constexpr ModInt(const long long x = 0) noexcept : a(x >= 0 ? x % Modulus : (Modulus - (-x) % Modulus) % Modulus) {}
    constexpr u64 &value() noexcept { return a; }
    constexpr const u64 &value() const noexcept { return a; }
    constexpr ModInt operator+(const ModInt rhs) const noexcept {return ModInt(*this) += rhs;}
    constexpr ModInt operator-(const ModInt rhs) const noexcept {return ModInt(*this) -= rhs;}
    constexpr ModInt operator*(const ModInt rhs) const noexcept {return ModInt(*this) *= rhs;}
    constexpr ModInt operator/(const ModInt rhs) const noexcept {return ModInt(*this) /= rhs;}
    constexpr ModInt operator^(const long long rhs) const noexcept {return ModInt(*this) ^= rhs;}
    constexpr ModInt &operator+=(const ModInt rhs) noexcept {
        a += rhs.a;
        if (a >= Modulus) {
            a -= Modulus;
        }
        return *this;
    }
    constexpr ModInt &operator-=(const ModInt rhs) noexcept {
        if (a < rhs.a) {
            a += Modulus;
        }
        a -= rhs.a;
        return *this;
    }
    constexpr ModInt &operator*=(const ModInt rhs) noexcept {
        a = a * rhs.a % Modulus;
        return *this;
    }
    constexpr ModInt &operator/=(ModInt rhs) noexcept {
        u64 exp = Modulus - 2;
        while (exp) {
            if (exp % 2) {
                *this *= rhs;
            }
            rhs *= rhs;
            exp /= 2;
        }
        return *this;
    }
    constexpr ModInt &operator^=(long long exp) noexcept {
        ModInt b = a;
        a = 1;
        while (exp) {
            if (exp&1) *this *= b;
            exp >>= 1;
            b *= b;
        }
        return *this;
    }

    bool operator==(const ModInt &p) const {return a == p.a;}
    bool operator!=(const ModInt &p) const {return a != p.a;}

};

using mint = ModInt<MOD>;

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    ll N,K; cin >> N >> K;

    mint ans = 0;
    for (ll i = K; i <= N+1; i++) {
        ll p = i*(i-1)/2;
        ll q = i*(N*2-i+1)/2;
        ans += (q-p+1);
    }

    cout << ans.a << ln;
}

Measured memory_bytes: 3652
# -*- coding: utf-8 -*-

N = int(input())
T, A = list(map(int, input().split()))
H = list(map(int, input().split()))

target = (T - A) / 0.006
sub = 10 ** 6
for i in range(N):
    if abs(H[i] - target) < sub:
        sub = abs(H[i] - target)
        ans_idx = i

print(ans_idx + 1)


Measured memory_bytes: 3060
from collections import defaultdict
def main():
    d = defaultdict(int)
    n = int(input())
    for _ in range(n):
        d[input()] += 1
    n = int(input())
    for _ in range(n):
        d[input()] -= 1
    print(max(0, *d.values()))

if __name__ == '__main__':
    main()


Measured memory_bytes: 9408
mod=10**9+7
import math
n=int(input())
ans=1
l=[0]*n
for ii in range(2,n+1):
  i=ii
  for j in range(2,int(math.sqrt(i))+1):
    if i%j==0:
      cnt=0
      while  i%j==0:
        cnt+=1;i//=j
      l[j-1]+=cnt
  if i!=1:
    l[i-1]+=1
for i in l:
  ans*=(i+1)
  ans%=mod
print(ans)


Measured memory_bytes: 3064
n = int(input())

l = 0
r = n-1

print(l)
seet = input()
if seet == 'Vacant':
    exit(0)

for _ in range(19):
    q = (l+r)//2

    # 区間が2つの時
    # 0-1 1//2=0
    if l == q:
        print(l+1)
        exit(0)

    print(q)
    tmp = input()
    if ((q-l) & 1 == 0 and tmp == seet) or ((q-l) & 1 == 1 and tmp != seet):
        l = q
        seet = tmp
    else:
        r = q-1


Measured memory_bytes: 3660
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static string InputPattern = "InputX";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("3 3");
            WillReturn.Add("1 2");
            WillReturn.Add("1 3");
            WillReturn.Add("2 3");
            //2
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("7 7");
            WillReturn.Add("1 3");
            WillReturn.Add("2 7");
            WillReturn.Add("3 4");
            WillReturn.Add("4 5");
            WillReturn.Add("4 6");
            WillReturn.Add("5 6");
            WillReturn.Add("6 7");
            //1
            //このテストケースは問題文の例と同じです
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    struct JyoutaiDef
    {
        internal int CurrNode;
        internal HashSet<int> VisitedSet;
        //internal string Log;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();

        int[] wkArr = { };
        Action<string> SplitAct = pStr =>
            wkArr = pStr.Split(' ').Select(X => int.Parse(X)).ToArray();

        SplitAct(InputList[0]);
        int N = wkArr[0];

        bool[,] EdgeArr = new bool[N + 1, N + 1];

        foreach (string EachStr in InputList.Skip(1)) {
            SplitAct(EachStr);
            EdgeArr[wkArr[0], wkArr[1]] = true;
        }

        var Stk = new Stack<JyoutaiDef>();
        JyoutaiDef WillPush;
        WillPush.CurrNode = 1;
        WillPush.VisitedSet = new HashSet<int>() { 1 };
        //WillPush.Log = "1";
        Stk.Push(WillPush);

        int AnswerCnt = 0;
        while (Stk.Count > 0) {
            JyoutaiDef Popped = Stk.Pop();

            //クリア判定
            if (Popped.VisitedSet.Count == N) {
                AnswerCnt++;
                //Console.WriteLine(Popped.Log);
                continue;
            }

            for (int I = 1; I <= N; I++) {
                //再訪不可
                if (Popped.VisitedSet.Contains(I)) continue;

                if (EdgeArr[Popped.CurrNode, I] || EdgeArr[I, Popped.CurrNode]) {
                    WillPush.CurrNode = I;
                    WillPush.VisitedSet = new HashSet<int>(Popped.VisitedSet);
                    WillPush.VisitedSet.Add(I);
                    //WillPush.Log = Popped.Log + "," + pNewNode.ToString();

                    Stk.Push(WillPush);
                }
            }
        }
        Console.WriteLine(AnswerCnt);
    }
}


Measured memory_bytes: 17628
#include <iostream>

using namespace std;

int main(int argc, char const *argv[])
{
    int S, W;
    cin >> S >> W;
    if (W >= S)
    {
        cout << "unsafe" << endl;
    }else
    {
        cout << "safe" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 3128
#include <stdio.h>
char S[100];
int N,K;
char temp;
int main()
{
	scanf("%d %d",&N,&K);
	scanf("%c",&temp);
	scanf("%[^\n]",S);
	S[K-1]=S[K-1]+32;
	printf("%s",S);
	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#include<algorithm>
using namespace std;
char in[510][510];
int v[510][510];
char ret[2][510][510];
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
int UF[1100000];
int FIND(int a){
	if(UF[a]<0)return a;
	return UF[a]=FIND(UF[a]);
}
void UNION(int a,int b){
	a=FIND(a);b=FIND(b);if(a==b)return;UF[a]+=UF[b];UF[b]=a;
}
int main(){
	int a,b;scanf("%d%d",&a,&b);
	for(int i=0;i<a;i++)scanf("%s",in[i]);
	for(int i=0;i<2;i++)for(int j=0;j<a;j++)for(int k=0;k<b;k++)
		ret[i][j][k]=in[j][k];
	for(int i=0;i<b;i++){
		ret[0][0][i]='#';
		ret[1][a-1][i]='#';
	}
	for(int i=1;i<a-1;i++)for(int j=0;j<b;j++){
		if(j%2==0)ret[0][i][j]='#';
		else ret[1][i][j]='#';
		if(in[i][j]=='#'){
			ret[0][i][j]=ret[1][i][j]='#';
		}
	}
	for(int i=0;i<a;i++)printf("%s\n",ret[0][i]);
	printf("\n");
	for(int i=0;i<a;i++)printf("%s\n",ret[1][i]);
	
}

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

using namespace std;

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

using ll = long long;

const int Inf = 1e9;
const double EPS = 1e-9;


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    ll m, res = 0;
    cin >> n >> m;
    vector<ll> a(n + 1);
    map<ll, int> mp;
    rep (i, n) cin >> a[i + 1];
    FOR (i, 1, n + 1) {
        a[i] += a[i - 1];
        a[i] %= m;
    }
    rep (i, n + 1) {
        res += mp[a[i]];
        mp[a[i]]++;
    }
    cout << res << endl;

    return 0;
}



Measured memory_bytes: 4992
/**In the name of Allah, the Most Merciful, the Most Merciful.**/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define INF 9223372036854775806
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define PI 2*acos(0.0)
#define EPS 1e-9
ll max(ll a,ll b) {if(a>b) return a; else return b;}
ll min(ll a,ll b) {if(a<b) return a; else return b;}

int a[1000005];

int main()
{
    for(int i=1;i<=1e6;i++) a[i]=1;
    for(int i=2;i<=1e6;i++){
        for(int j=i;j<=1e6;j+=i){
            a[j]++;
        }
    }

    int n;
    cin>>n;
    ll cnt=0;
    for(int i=1;i<n;i++){
        int x=n-i;
        //cout<<n<<" "<<i<<" "<<x<<" "<<a[x]<<endl;
        cnt+=(a[x]);
    }
    cout<<cnt<<endl;

    return 0;
}




Measured memory_bytes: 7540
from collections import Counter

N, K = map(int, input().split())
P = list(map(int, input().split()))
ans = 0
S = [0, ]
for i in range(1, 1001):
    S.append(S[-1]+i)
E = [s/(i+1) for i, s in enumerate(S[1:])]
E = [0, ] + E

ans = 0
before_ans = 0
for i, p in enumerate(P):
    #print(ans, before_ans)
    if i < K:
        ans += E[p]
        before_ans = ans - E[P[i-K+1]]
        continue
    tmp_ans = before_ans + E[p]
    ans = max(tmp_ans, ans)
    before_ans = tmp_ans - E[P[i-K+1]]
print(ans)


Measured memory_bytes: 71792
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <time.h>
#include <list>

using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define reps(x,c) for(auto x:c)
#define all(x) begin(x), end(x)
#define pb(a) emplace_back(a) 
#define mp(a,b) make_pair((a),(b))
#define pl pair<ll,ll>
#define INF 2147483600
#define MOD 1000000007
#define fi first
#define se second
#define dbg(x) cout << #x"="<< (x) << endl
#define dbgv(x) cout<<#x<<endl;reps(y,x){cout<<y<<" ";}cout<<endl

int main(){
  ll a,b;cin>>a>>b;
  string s;cin>>s;
  if(s.size()==a+b+1){
    rep(i,s.size()){
      if(i==a){
        if(s[i]=='-'){
          //pass
        }else{
          cout<<"No"<<endl;
          return 0;
        }
      }else{
        if(48<=s[i]&&s[i]<=57){
          //pass
        }else{
          cout<<"No"<<endl;
          return 0;
        }
      }
    }
  }else{
    cout<<"No"<<endl;
    return 0;
  }
  cout<<"Yes"<<endl;
  return 0;
}

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

bool isOK(int index, int key, vector<int> &a){
    if (a[index] >= key) return true;
    else return false;
}

int binary_search(int key, vector<int> &a){
    
    int ng = -1;
    int ok = (int)a.size();
    
    while (abs(ok - ng) > 1){
        
        int mid = (ok + ng) / 2;
        
        if (isOK(mid, key, a)) ok = mid;
        else ng = mid;
    }
    
    return ok;
}

int main(){
    int n;
    cin >> n;
    
    map<int, int> mp1;
    rep(i, n){
        int s;
        cin >> s;
        
        mp1[s]++;
    }
   
   int q;
   cin >> q;
   
   int ans = 0;
   
   rep(i, q){
       int t;
       cin >> t;
       
       if (mp1[t] > 0) ans++;
   }
   cout << ans << endl;
    
}






Measured memory_bytes: 10088
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstdint>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <chrono>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#include <random>
#include <utility>
#include <limits>
#include <list>
#include <type_traits>

/* template start */
 
#define rep(i, a, b) for (long long i = (a); (i) < (b); (i)++)
#define all(i) i.begin(), i.end()

#ifdef LOCAL
#define debug(...) std::cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

void debug_out(){std::cerr<<std::endl;}

template<typename Head,typename... Tail>
void debug_out(Head h,Tail... t){
  std::cerr<<" "<<h;
  if(sizeof...(t)>0)std::cout<<" :";
  debug_out(t...);
}
 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}

template<typename Num>
constexpr Num mypow(Num a, long long b) {
  if(b==0)return 1;
  if (a==0)return 0;
  Num x = 1;
  while (b > 0) {
    if(b & 1)x*=a;
    a*=a;
    b >>= 1;
  }
  return x;
}

/* template end */

using ll = long long;

int main() {
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  
  ll n,m;
  std::cin>>n>>m;

  std::vector<ll> a(m);
  for(auto&& e:a)std::cin>>e;

  std::sort(all(a),std::greater<ll>());


  constexpr ll INF=1e9;
  ll match[10]={INF,2,5,5,4,5,6,3,7,6};

  std::vector<ll> digits(n+1,-INF);

  digits[0]=0;

  rep(i,1,n+1){
    rep(j,0,m){
      ll tmp=match[a[j]];
      if(i-tmp>=0&&digits[i-tmp]!=-INF)chmax(digits[i],digits[i-tmp]+1);
    }
  }

  while(n>0){
    rep(i,0,m){
      if(n-match[a[i]]>=0&&digits[n]==digits[n-match[a[i]]]+1){
        std::cout<<a[i];
        n-=match[a[i]];
        break;
      }
    }
  }

  std::cout<<"\n";

  return 0;
}

Measured memory_bytes: 384
import math
while True:
    D,E = map(int,input().split())
    if D == 0: break
    ans = 10**5
    for x in range(0,D+1):
        y = D-x
        if x > y: break
        score = abs(E - math.sqrt(x*x + y*y))
        ans = min(score, ans)
    print(ans)

Measured memory_bytes: 5664
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<math.h>
#include<algorithm>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<queue>
#include<stack>
#define REP(i, N) for(ll i = 0; i < N; ++i)
#define REEP(i, N) for(ll i = N - 1; i >= 0; --i)
#define FOR(i,m,n) for(ll i = m; i < n; ++i)
#define RFOR(i,m,n) for(ll i = n - 1; i >= m; --i)
#define ALL(a) (a).begin(),(a).end()
#define pb push_back
#define PB push_back
#define KIRIAGE(a, b) a += (b - a % b) % b // a ??? b ????????°????????§?¢???????
#define CEIL(c, a, b) if(a % b == 0) { c = a / b;} else { c = a / b + 1;} // a / b ??\??????????°???´??°
#define sp(n) setprecision(n)
#define INF 1000000000
#define MOD 1000000007

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
int dx4[4] = {1, 0, -1, 0};
int dy4[4] = {0, 1, 0, -1};
int dx8[8] = {1, 1, 0, -1, -1, -1, 0, 1};
int dy8[8] = {0, 1, 1, 1, 0, -1, -1, -1};

int main(void) {
	while(true) {
		int n, r;
		cin>>n>>r;
		if(n==0&&r==0) return 0;
		vector<int> c(n, 0);
		int hav = 0;
		int pos = 0;
		int winner = -1;
		while(true) {
			if(r > 0) {
				++c[pos];
				if (c[pos] == 1) ++hav;
				--r;
				if(r == 0 && hav == 1) {
					winner = pos;
					break;
				}
			} else {
				if(c[pos] != 0) --hav;
				r = c[pos];
				c[pos] = 0;
			}
			if(pos < n - 1) ++pos;
			else pos = 0;
		}
		cout<<winner<<endl;
	}
}

Measured memory_bytes: 3112
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>

#define MAX 200010
#define MOD 1000000007

long long int fac[MAX]={0};
long long int inv[MAX]={0};
long long int finv[MAX]={0};
int i;

void comb_init()
{
    fac[0]=1;
    fac[1]=1;
    finv[0]=1;
    finv[1]=1;
    inv[1]=1;
    for(i=2;i<MAX;i++)
    {
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}


long long int comb(int n,int k)
{
    //printf("input %d C %d\n",n,k);
    if(n<k)return 0;
    if(n<0||k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}

int main() {
    long long int s;
    long long int ans=0;
    long long int dp[2010]={0};

    comb_init();
    scanf("%lld",&s);

    int j,m;
    for(j=1;j<s/3+1;j++)
    {
        m=s-(3*j);
        if(m<0)break;
        else
        {
            if(j==1)dp[j]=1;
            else dp[j]=comb(m+j-1,j-1);
            //printf("%lld\n",dp[j]);
        }
        ans = (ans + dp[j])%MOD;
    }

    printf("%lld",ans);
}


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

const int32_t MAX_N = 400;
const int64_t INF = 1e18;

int64_t prefSums[MAX_N + 5], dp[MAX_N + 5][MAX_N + 5];

int64_t GetSum(int32_t low, int32_t high) {
	return prefSums[high] - prefSums[low - 1];
}

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

	int32_t n;
	std::cin >> n;

	for(int32_t i = 1; i <= n; i++) {
		int32_t a;
		std::cin >> a;

		prefSums[i] = prefSums[i - 1] + (int64_t) a;
	}
	
	for(int32_t j = 2; j <= n; j++) {
		for(int32_t i = n - j + 1; i >= 1; i--) {
			dp[i][j] = INF;
		
			int32_t low = i, high = i + j - 1;	
			for(int32_t mid = low; mid < high; mid++) {
				int64_t aux = dp[low][mid - low + 1] + dp[mid + 1][high - mid] + GetSum(low, high); 
				dp[i][j] = std::min(dp[i][j], aux);
			}
		}
	}

	std::cout << dp[1][n] << '\n';
}



Measured memory_bytes: 1536
n=int(input())
ls_1 = []
for i in range(1,12):
  ls_1.append(int((26**i-1)/25))
#print(ls_1)
pos = 0
for i in ls_1:
  if n < i:
    pos = ls_1.index(i)-1
    break
  elif n > 146813779479511:
    pos = 10
n_ = n-ls_1[pos]
#print(n_)
ans = [97]*(pos+1)
#print(ans)
ls_2 = []
for i in range(pos+1):
  ls_2.append(n_%26)
  n_ //= 26
  if n_==0:
    ls_2 = ls_2+[0]*(pos-i)
    break
#print(ls_2)
ls_2=ls_2[::-1]
for i in range(len(ans)):
  ans[i] = chr(ans[i]+ls_2[i])
print("".join(ans))
  

Measured memory_bytes: 9216
def resolve():
    MOD = 10 ** 9 + 7
    N = int(input())

    dp = [0] * (N + 1)
    dp[0] = 1
    for n in range(N + 1):
        for i in range(3, N + 1):
            dp[n] += dp[n - i]
            dp[n] %= MOD

    print(dp[N])


if __name__ == "__main__":
    resolve()

Measured memory_bytes: 9068
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define all(x) (x).begin(), (x).end()

using namespace std;

void solve(int tc) {
	int r;
	cin>>r;
	cout<<6.283185*r<<endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t = 1;
    // cin>>t;
    for(int tc=1; tc<=t; ++tc) {
        solve(tc);
    }    
    return 0;
}

Measured memory_bytes: 3788
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
const int M = 2e5 + 5;
int a[27]={0},b[27]={0},c1[M],c2[M]; 
int main(){
	for(int i=0;scanf("%c",&c1[i])!=EOF && c1[i]!='\n';i++){
	}
	for(int i=0;scanf("%c",&c2[i])!=EOF && c2[i]!='\n';i++){
	}
	int f=0;
	for(int i=0;c1[i]!='\n' && c1[i]!='\0';i++){
		if(a[c1[i]-97]==0 && b[c2[i]-97]==0){
			a[c1[i]-97]=c2[i]-97;
			b[c2[i]-97]=c1[i]-97;
		}
		else{
			if( a[c1[i]-97]!=0 && a[c1[i]-97]!=c2[i]-97){
				f=1;
				break;
			}
			if(b[c2[i]-97]!=0 && b[c2[i]-97]!=c1[i]-97){
				f=1;
				break;
			}
		}
	} 
	if(f==1)
		cout<<"No"<<endl;
	else 
		cout<<"Yes"<<endl;
	return 0;
}

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

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n;
  cin >> n;
  
  vector<int> p(n), q(n);
  for(int i = 0; i < n; i++) cin >> p.at(i);
  for(int i = 0; i < n; i++) cin >> q.at(i);
  
  for(int i = 0; i < n; i++){
    if(p.at(i) > q.at(i)){
      swap(p, q);
      break;
    }
    else if(p.at(i) < q.at(i)) break;
  }
  
  int keep = 0;
  while(p != q){
    next_permutation(p.begin(), p.end());
    keep++;
  }
  
  cout << keep << '\n';
}

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

using ll= long long;
#define double long double
#define sz(x) (int)x.size()
#define all(x) (x).begin(),(x).end()
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define _set(x) __builtin_popcount(x)
#define _setl(x) __builtin_popcountll(x)
#define PI  3.14159265358979323846264338327950L
#define mod 1000000007LL

void debug(){
	cerr<<"]\n";
}
template<class H,class ... T> void debug(H h,T... t){
	cerr<<h;
	if(sizeof... (t)){
		cerr<<", ";
	}
	debug(t...);
}
#ifdef DEBUG
	#define dbg(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", debug(__VA_ARGS__)
	#define dpv(...) cerr<< "["#__VA_ARGS__ " : ";for(int i: (__VA_ARGS__)){cerr<<i<<" ";}cerr<<"]\n"
#else
	#define dbg(...) 0
	#define dpv(...) 0
#endif


void solve(){
	string s;
	cin>>s;
	if(s.back()=='s'){
		s.push_back('e');
	}
	s.push_back('s');
	cout<<s<<"\n";
}


int32_t main(){
	IOS
	// freopen("input.txt","r",stdin);
	int _;
	// cin>>_;
	_=1;
	for(int i=1;i<=_;i++){
		// cout<<"Case #"<<i<<": ";
		solve();
	}
	return 0;
}

/*
   check for overflows int long long
   correct mize of array
*/


Measured memory_bytes: 3652
/*       Rohan Balot
    NSIT, New Delhi, India  */
#include <algorithm>
#include <bitset>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <vector>
#include <queue>
#include <utility>
#include <unordered_set>

#include <cctype>
#include <cstdio>
#include <cmath>
#include <climits>
#include <cstring>
#include <ctime>
using namespace std;
 
#define ALL(t) (t).begin(), (t).end()
#define ALLR(t) (t).rbegin(), (t).rend()
#define MP make_pair
 
const int N = int( 1e5 ) + 1;
const int M = int( 1e6 ) + 1;
const int MOD = int( 1e9 ) + 7;
const double PI = acos(-1);
const double eps = 1e-6;

void __answer()
{
	int a, b, c;
	cin >> a >> b >> c;
	if(c >= a && c <= b)
		cout << "Yes\n";
	else cout << "No\n";
}
int main()
{
    ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    #ifdef LOCAL
        freopen("sample_input.txt", "r", stdin);
    #endif
    __answer();
    return 0;
}

Measured memory_bytes: 256
fn func(input_str: &str) -> usize {
    let mut iter = input_str.split_whitespace();
    let n: usize = iter.next().unwrap().parse().unwrap();
    let m: usize = iter.next().unwrap().parse().unwrap();
    let c: i32 = iter.next().unwrap().parse().unwrap();
    let b_s: Vec<i32> = iter.by_ref().take(m).map(|x| x.parse().unwrap()).collect();
    let mut ans = 0;
    for _ in 0..n {
        let a_s: Vec<i32> = iter.by_ref().take(m).map(|x| x.parse().unwrap()).collect();
        let sum = a_s.iter().zip(b_s.iter()).fold(c, |sum, (a, b)| sum + a * b);
        if sum > 0 {
            ans += 1;
        }
    }
    ans
}

use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    println!("{}", func(&buf[..]));
}

Measured memory_bytes: 4352
# https://atcoder.jp/contests/abc128/tasks/abc128_c
# なんかかすかに解いた記憶あるな？

# load data
N, M = list(map(int, input().split()))
S = []
for _ in range(M):
    S.append(list(map(int, input().split()))[1:])
P = list(map(int, input().split()))


def is_on(i, S, p):
    # bit表現 i のときSのスイッチの個数とpでonか返す
    cnt = 0
    for j in S:
        if (i >> (j - 1)) % 2:  # j番目のスイッチオン
            cnt += 1
    return cnt % 2 == p


ans = 0
# bit 全探索
for i in range(1 << N):  # N桁のbit全探索
    # 以下iの全パターンについて
    flg = True
    for s, p in zip(S, P):
        flg *= is_on(i, s, p)
    ans += flg
print(ans)


Measured memory_bytes: 42844
#include <iostream>

using namespace std ;

int main(){
    int a,b,c;
    int c1 = 0,c2 = 0;
    cin >> a >> b >> c ;

    if(a == 5)
        c1++;
    if(b == 5)
        c1++;
    if(c == 5)
        c1++;
    if(a == 7)
        c2++;
    if(b == 7)
        c2++;
    if(c == 7)
        c2++;
    if(c1 == 2 && c2== 1)
        cout << "YES";
    else cout << "NO";

return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
typedef long long ll;

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; }

const long long INF = 1LL << 60;

int main(){
  ll h, w;
  cin >> h >> w;

  if(h==1 || w==1){
    cout << 1 << endl;
    return 0;
  }

  cout << (h * w + 1) / 2 << endl;

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>



int bubblesort(int A[],int N ){
  int i,handan=1,j,n,cnt=0;
  
  for(i=0;i<N;i++){
    handan=0;
    for(j=N-1;j>=i+1;j--){
      
      if(A[j]<A[j-1]){
	n=A[j];
	A[j]=A[j-1];
	A[j-1]=n;
	handan=1;
	cnt++;
      }
    }
  }
  return cnt;
    
}


int main(){
  int n,i,cnt=0;

  scanf("%d",&n);

  int A[n];

  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }

  cnt=bubblesort(A,n);

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

  printf("\n");
  printf("%d\n",cnt);
}



Measured memory_bytes: 2128
vowels = 'aiueo'

while True:
    n = int(input())
    if n == 0:
        break
    codes = []
    for _ in range(n):
        name = input()
        codes.append(name[0] + ''.join(c for p, c in zip(name, name[1:]) if p in vowels))
    if len(set(codes)) != len(codes):
        print(-1)
        continue
    k = 1
    while True:
        shorten = [code[:k] for code in codes]
        if len(set(shorten)) == len(shorten):
            print(k)
            break
        k += 1

Measured memory_bytes: 7592
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<long long> v(n);
  for(int i = 0; i < n; i++) cin >> v[i];
  long long ans = 0;
  sort(v.begin(), v.end(), [](const int &lhs, const int &rhs) {return lhs > rhs;});
  for(int i = 0; i < n; i++) if(i % 2 == 0) ans += v[i];
  else ans -= v[i];
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
while True:
    n, m = map(int, input().split())
    if n == 0 and m == 0:
        break

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

    for i in range(n):
        tousen[i] = list(input().split())
        tousen[i][0] = list(tousen[i][0])
        tousen[i][1] = int(tousen[i][1])
    
    ans = 0    
    for _ in range(m):
        s = list(input())
        for i in range(n):
            flag = True
            for j in range(8):
                if tousen[i][0][j] != '*' and tousen[i][0][j] != s[j]:
                    flag = False
                    break
            if flag:
                ans += tousen[i][1]
                break
    
    print(ans)



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

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

  vector<pair<int,int>> r(n);
  vector<pair<int,int>> b(n);

  for (int i = 0; i < n; i++)
  {
    int x,y;
    cin >> x >> y;
    r[i]=make_pair(y,x);
  }
  for (int i = 0; i < n; i++)
  {
    int x,y;
    cin >> x >> y;
    b[i]=make_pair(x,y);
  }

  sort(b.begin(),b.end());
  sort(r.begin(),r.end(),greater<pair<int,int>>());

  int ans=0;
  for (int i = 0; i < n; i++)
  {
    for (auto itr = r.begin(); itr < r.end(); itr++)    
    {
      if(b[i].first>(*itr).second && b[i].second>(*itr).first){
        r.erase(itr);
        ans++;
        break;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <numeric>
#include <algorithm>
using namespace std;
int main(){
    while(true){
        int h,w;
        cin>>h>>w;
        if(h==0&&w==0){
            return 0;
        }
        for(int i=0;i<h;++i){
            for(int j=0;j<w;++j){
                if(i%2==0){
                    if(j%2==0){
                        cout<<"#";
                    } 
                    else{
                        cout<<".";
                    }
                }
                else{
                    if(j%2==1){
                        cout<<'#';
                    }
                    else{
                        cout<<".";
                    }
                }
            }
            cout<<endl;
        }
        cout<<endl;
    }
}



Measured memory_bytes: 3136