akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18+7)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define mkt make_tuple
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;

/*--------Library Zone!--------*/

int n,a[114514];
vector<int>G[114514];
int dfs(int x){
	vector<int>v;
	for(int i:G[x]){
		v.push_back(dfs(i));
	}
	int ans=0;
	sort(all(v),greater<>());
	rep(i,v.size()){
		ans=max(ans,v[i]+i+1);
	}
	//cout<<x<<" "<<ans<<endl;
	return ans;
}
signed main(){
	cin>>n;
	REP(i,n){
		cin>>a[i];a[i]--;
		G[a[i]].push_back(i);
	}
	cout<<dfs(0)<<endl;
}


Measured memory_bytes: 14592
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		int n,q,i,j,key,ans=0;
		Scanner sc=new Scanner(System.in);
		n=sc.nextInt();
		int s[]=new int[n];
		for(i=0;i<n;i++){
			s[i]=sc.nextInt();
		}
		q=sc.nextInt();
		int t[]=new int[q];
		for(j=0;j<q;j++){
			t[j]=sc.nextInt();
		}

		for(j=0;j<q;j++){
			key=t[j];
			for(i=0;i<n;i++){
				if(s[i]==key){
					ans++;
					break;
				}

			}
		}
		System.out.println(ans);

	}

}

Measured memory_bytes: 31092
fun judge(ret: Boolean, ok: String, ng: String) = if (ret) println(ok) else println(ng)

fun main(args: Array<String>) {
  val n = readLine()!!.toInt()
  val a = readLine()!!.toInt()
  judge(if ((n % 500) <= a) true else false, "Yes", "No")
}


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

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define rep(i, k, n) for (int i = (int)(k); i < (int)(n); ++i)
#define rrep(i, k, n) for (int i = (int)(n) - 1; i >= (int)(k); --i)

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vv_ii;
typedef pair<int,ii> i_ii;
typedef vector<i_ii> vi_ii;

template <class T>
inline ostream& operator<<(ostream & o, vector<T> const& v) {
    for (int i = 0; i < (int)(v.size()) - 1; ++i)
        o << v[i] << ' ';
    if (!v.empty())
        o << v.back();
    return o;
}

template <class T, class Q>
inline ostream& operator<<(ostream & o, pair<T,Q> const& p) {
    o << "(" << p.fi << "," << p.se << ")";
    return o;
}


int main(){

    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);

    string s, t, u;
    int a, b;
    cin >> s >> t >> a >> b >> u;
    cout << a - (u == s) << ' ' << b - (u == t) << '\n';
    

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define PI acos(-1.0)
#define pb push_back
#define F first
#define S second
using namespace std;
typedef long long ll;
const int N=2e5+5;
const int MOD=1e9+7;
ll a[N],sum[N];
set<ll>st;
int main(void){
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);

    ll l,r,k;
    cin >> l >>r >> k;
    for(ll i=l;i<=l+k-1;i++)   st.insert(i);
    for(ll i=r;i>=r-k+1;i--)   st.insert(i);
    for(auto t:st)
        if(t>=l&&t<=r)  cout <<t << endl;

    return 0;
}


Measured memory_bytes: 256
N,Y = map(int, input().split())
A,B,C = -1,-1,-1
for a in range(N+1):
    for b in range(N-a+1):
        c = N-a-b
        T = 10000*a + 5000*b + 1000*c
        if T == Y:
            A = a
            B = b
            C = c
print("{} {} {}".format(A,B,C))

Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;

class Program
{
    static void Main()
    {
        FastScanner sc = new FastScanner(Console.OpenStandardInput());
        int N, M;
        N = sc.nextInt();
        M = sc.nextInt();
        int[] A = sc.intArray(M);
        int accum = 0;
        foreach (int Ai in A)
        {
            accum += Ai;
        }
        Console.WriteLine(N < accum ? -1 : N - accum);
        return;
    }
}

// FastScanner start
public class FastScanner
{
    public readonly Stream str;
    private readonly byte[] buf = new byte[1024];
    private int len, ptr;
    public bool isEof = false;
    public FastScanner(Stream stream)
    {
        str = stream;
    }
    private T[] enumerate<T>(int n, Func<T> f)
    {
        var a = new T[n];
        for (int i = 0; i < n; ++i) a[i] = f();
        return a;
    }
    public char nextChar()
    {
        byte b = 0;
        do
        {
            b = read();
        }
        while ((b < 33 || 126 < b) && !isEof);
        return (char)b;
    }
    public int nextInt()
    {
        return (isEof) ? int.MinValue : (int)nextLong();
    }
    public long nextLong()
    {
        if (isEof)
        {
            return long.MinValue;
        }
        long ret = 0;
        byte b = 0;
        var ng = false;
        do
        {
            b = read();
        }
        while (b != '-' && (b < '0' || '9' < b));
        if (b == '-')
        {
            ng = true;
            b = read();
        }
        for (; true; b = read())
        {
            if (b < '0' || '9' < b)
            {
                return ng ? -ret : ret;
            }
            else ret = ret * 10 + b - '0';
        }
    }
    public int[] intArray(int n)
    {
        return enumerate(n, nextInt);
    }
    public long[] longArray(int n)
    {
        return enumerate(n, nextLong);
    }
    public char[] charArray(int n)
    {
        return enumerate(n, nextChar);
    }
    public string Scan()
    {
        var sb = new StringBuilder();
        for (var b = nextChar(); b >= 33 && b <= 126; b = (char)read())
        {
            sb.Append(b);
        }
        return sb.ToString();
    }
    private byte read()
    {
        if (isEof)
        {
            return 0;
        }
        if (ptr >= len)
        {
            ptr = 0;
            if ((len = str.Read(buf, 0, 1024)) <= 0)
            {
                isEof = true;
                return 0;
            }
        }
        return buf[ptr++];
    }
}
// FastScanner end

Measured memory_bytes: 27356
// Try AtCoder
// author: Leonardone @ NEETSDKASU

fn main() {
	let mut stdin = String::new();
    std::io::Read::read_to_string(
    	&mut std::io::stdin(),
        &mut stdin).unwrap();
	let mut stdin = stdin.split_whitespace();
    let mut get = || stdin.next().unwrap();
    macro_rules! get {
    	($t:ty) => (get().parse::<$t>().unwrap());
        () => (get!(i64));
    }
    
    let n = get!(usize);
    let m = get!(usize);
    let mut xs = vec![];
    for _ in 0..m {
    	let x = get!();
        xs.push(x);
    }
    if n >= m {
    	println!("0");
        return;
    }
    xs.sort();
    let mut ys = vec![];
    for i in 0..xs.len()-1 {
    	ys.push(xs[i+1]-xs[i]);
    }
    ys.sort();
    let mut ans = 0;
    for i in 0..m-n {
    	ans += ys[i];
    }
    println!("{}", ans);
}

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

using namespace std;

using int64 = long long;
const int mod = 1e9 + 7;
const int inv2 = 5e8 + 4;

vector< int > g[100000];
vector< vector< int64 > > dp[100000];

void rec(int idx) {
  vector< vector< int64 > > sub(3, vector< int64 >(1));
  sub[0][0] = 1;
  for(auto &to : g[idx]) {
    rec(to);
    auto &ch = dp[to];
    vector< int64 > sub1(ch[0].size() + 1);
    for(int i = 0; i < ch[0].size(); i++) {
      (sub1[i + 1] += ch[0][i] * 2) %= mod;
      (sub1[i + 1] += ch[1][i]) %= mod;
    }

    vector< vector< int64 > > beet(3, vector< int64 >(sub[0].size() + ch[0].size()));
    for(int k = 0; k < 3; k++) {
      for(int i = 0; i < sub[k].size(); i++) {
        for(int j = 0; j <= ch[0].size(); j++) {
          if(j < ch[0].size()) {
            for(int l = 0; l < 3; l++) {
              (beet[k][i + j] += sub[k][i] * ch[l][j] % mod) %= mod;
            }
          }
          if(k == 0) (beet[1][i + j] += sub[k][i] * sub1[j]) %= mod;
          if(k == 1) (beet[2][i + j] += sub[k][i] * sub1[j] % mod * inv2) %= mod;
        }
      }
    }

    sub.swap(beet);
  }
  dp[idx].swap(sub);
}

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

  int64 fact[2002];
  fact[0] = 1;
  for(int i = 1; i < 2002; i++) {
    (fact[i] = fact[i - 1] * i) %= mod;
  }

  rec(0);

  int64 ret = 0;
  for(int i = 0; i < N; i++) {
    int64 add = 0;
    for(int j = 0; j < 3; j++) (add += dp[0][j][i]) %= mod;
    (add *= fact[N - i]) %= mod;
    if(i & 1) (ret += mod - add) %= mod;
    else (ret += add) %= mod;
  }

  cout << ret << endl;
}


Measured memory_bytes: 57856
#include<bits/stdc++.h>
#define lowbit(x) 	((x)&(-x))
#define randome_generate srand(std::chrono::high_resolution_clock::now().time_since_epoch().count())
using namespace std;
string s;
vector<int> v[200100];
bool vis[200100];
vector<pair<int,int> > prs;
int BIT[200100];
int endup[200100];
long long query(int x){
	long long ret=0LL;
	for(;x;x-=lowbit(x)){
		ret+=(long long)(BIT[x]);
	}
	return ret;
}
void add(int x,int val){
	for(;x<=200000;x+=lowbit(x))
		BIT[x]+=val;
}
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>s;
	int n=s.size();
	for(int i=0;i<s.size();i++){
		v[s[i]-'a'].push_back(i);
	}
	int cc=0;
	for(int i=0;i<26;i++){
		for(int j=0;j<v[i].size()/2;j++){
			prs.push_back(make_pair(v[i][j],v[i][v[i].size()-j-1]));
		}
		if(v[i].size()%2==1){
			cc++;
			prs.push_back(make_pair(n+2,v[i][v[i].size()/2]));
		}
	}
	if(cc>1){
		cout<<-1<<endl;
		return 0;
	}
	sort(prs.begin(),prs.end());
	for(int i=0;i<prs.size();i++){
		if(prs[i].first==n+2){
			endup[prs[i].second]=i;
		}
		else{
			endup[prs[i].first]=i;
			endup[prs[i].second]=n-i-1;
		}
	}
	//求出t,s的距离 
	//逆序对 
	long long res=0LL;
	for(int i=n-1;i>=0;i--){
		res+=query((endup[i]+1));
		add((endup[i]+1),1);
	}
	cout<<res<<endl;
	return 0;
}


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

void diceS(int []);
void diceE(int []);
void diceW(int []);
void diceN(int []);

int main(){
	int d[6];
	string str;
	for(int i=0;i<6;i++) cin >> d[i];
	cin >> str;
	for(int i=0;i<str.size();i++){
		switch(str[i]){
			case 'S':
				diceS(d);
				break;
			case 'E':
				diceE(d);
				break;
			case 'W':
				diceW(d);
				break;
			case 'N':
				diceN(d);
				break;
		}
	}
	cout << d[0] << endl;

	return 0;
}

void diceS(int a[6]){
	int w;
	w=a[0];
	a[0]=a[4];
	a[4]=a[5];
	a[5]=a[1];
	a[1]=w;
}


void diceE(int a[6]){
	int w;
	w=a[0];
	a[0]=a[3];
	a[3]=a[5];
	a[5]=a[2];
	a[2]=w;
}

void diceW(int a[6]){
	int w;
	w=a[0];
	a[0]=a[2];
	a[2]=a[5];
	a[5]=a[3];
	a[3]=w;
}

void diceN(int a[6]){
	int w;
	w=a[0];
	a[0]=a[1];
	a[1]=a[5];
	a[5]=a[4];
	a[4]=w;
}



 



Measured memory_bytes: 3208
#include <iostream>
#include <vector>
using namespace std;
int main(void){
    string s;
    cin >> s;
    int p[s.size()+1];
    p[0] = 0;
    for(int i=0;i<s.size();i++){
        if(s[i]=='\\'){
            p[i+1]=p[i]-1;
        }else if(s[i]=='/'){
            p[i+1]=p[i]+1;  
        }else{
            p[i+1]=p[i];  
        }
    }
    
    vector<int> stv,etv;
    
    for(int i=0;i<s.size();i++){
        if(s[i]=='/'){
            for(int j=i;j>=0;j--){
                if(p[i+1]==p[j]){
                    stv.push_back(j);
                    etv.push_back(i+1);
                    break;
                }
            }     
        }
    }    
    
    vector<int> sv,ev;
    for(int i=stv.size()-1;i>=0;i--){
        if(i==stv.size()-1 or sv[sv.size()-1]>stv[i]){
            sv.push_back(stv[i]);
            ev.push_back(etv[i]);
        }
    }
    
    int area=0;
    for(int i=0;i<sv.size();i++){
        for(int j=sv[i];j<ev[i];j++){
            area += (p[sv[i]]-p[j+1])*2;

        }
    }
    cout << area/2 << endl;
    cout << sv.size();
    for(int i=sv.size()-1;i>=0;i--){
        int tmp=0;
        for(int j=sv[i];j<ev[i];j++){
            tmp += (p[sv[i]]-p[j+1])*2;
        }
        cout << " " << tmp/2;
    }
    cout << endl;
}



Measured memory_bytes: 3388
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace C
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var n = int.Parse(Console.ReadLine());
            var hi = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
            var current = new int[hi.Length];

            Console.WriteLine(Dfs(current, hi, 0, hi.Length - 1));
        }

        static int Dfs(int[] current, int[] target, int left, int right)
        {
            if (left == right) return target[left];
            if (left > right) return 0;

            var min = 101;
            for (var i = left; i <= right; i++)
            {
                min = Math.Min(min, target[i]);
            }
            if (min == 101) return 0;

            var mid = -1;
            for (var i = left; i <= right; i++)
            {
                current[i] += min;
                target[i] -= min;
                if (target[i] == 0) mid = i;
            }

            var leftValue = Dfs(current, target, left, mid - 1);
            var rightValue = Dfs(current, target, mid + 1, right);
            return min + leftValue + rightValue;
        }
    }
}


Measured memory_bytes: 13396
#include<iostream>
#include<stdio.h>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>>
using namespace std;
#define maxn 105
int mp[maxn][maxn];
int a[maxn*maxn];

int main(){
    int H,W,N;
    scanf("%d%d",&H,&W);
    getchar();
    scanf("%d",&N);
    for(int i=1;i<=N;i++)
        scanf("%d",&a[i]);
    int index = 1;
    for(int i=1;i<=H;i++){
        if(i%2){
            for(int j=1;j<=W;j++){
                if(a[index]==0){
                    index ++;
                    mp[i][j] = index;
                    a[index] --;
                }
                else if(a[index] > 0){
                    mp[i][j] = index;
                    a[index] --;
                }
            }
        }
        else {
            for(int j=W;j>=1;j--){
                if(a[index]==0){
                    index ++;
                    mp[i][j] = index;
                    a[index] --;
                }
                else if(a[index] > 0){
                    mp[i][j] = index;
                    a[index] --;
                }
            }
        }
    }
    for(int i=1;i<=H;i++){
        for(int j=1;j<=W;j++){
            printf("%d ",mp[i][j]);
        }
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
using namespace std;

template<typename T>
ostream& operator << (ostream& os, vector<T>& v){
	rep(i,v.size()){ os << v[i] << (i == v.size() - 1 ? "" : " "); } return os;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& v){
	for(T& x: v){ is >> x; } return is;
}

vector<int> p;

const int kN = 55556;
void primeNumber(){
	bool prime[kN];
	rep(i,kN) prime[i] = 1;
	prime[0] = prime[1] = 0;
	rep(i,kN){
		if(prime[i]){
			if(i != 2) p.emplace_back(i);
			for(int j = i + i; j < kN; j+=i){
				prime[j] = 0;
			}
		}
	}
}

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

	primeNumber();

	vector<int> ans;
	rep(i,p.size()){
		if(ans.size() == n) break;
		if(p[i] % 10 == 1) ans.emplace_back(p[i]);
	}
	cout << ans << endl;
}


Measured memory_bytes: 384
n = gets.to_i
a = gets.chomp.split(" ").map(&:to_i)
sum = a.inject(:+)
x = a[0]
y = sum - a[0]
min = (x-y).abs
(n-2).times do |i|
  x += a[i+1]
  y -= a[i+1]
  min = (x-y).abs if min > (x-y).abs
end
puts min

Measured memory_bytes: 28452
s=input()
if s=="SUN":
    ans=7
elif s=="MON":
    ans=6
elif s=="TUE":
    ans=5
elif s=="WED":
    ans=4
elif s=="THU":
    ans=3
elif s=="FRI":
    ans=2
elif s=="SAT":
    ans=1
print(ans)

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

int main(){
int n,tmp=0,min_n = 10005;
int s1=0,s2=0;
vector<int> w;
cin >> n;
for(int i=0;i<n;i++) {
  cin >> tmp;
  w.push_back(tmp) ;
}
for(int i=0;i<n;i++){
  s1 = 0; s2=0; 
  int j=0;
  for(j=0;j <= i;j++){
    s1+= w[j];
  } 
  for(;j<n;j++){
    s2+=w[j];
  }
  min_n = min(abs(s1-s2),min_n);
}
  cout << min_n<< "\n";
}


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

int S[100],top=0;

void push(int );
int pop(void );

int main(){
  int x,a,b,keisango,hyouji;
  char s[100];

  while( scanf("%s", s) != EOF ){
    if ( s[0] == '+' ){

      a=pop();
      b=pop();
      keisango=(b+a);
      push(keisango);

    }
    else if ( s[0] == '-' ){

      a=pop();
      b=pop();
      keisango=(b-a);
      push(keisango);

    }
    else if ( s[0] == '*' ){

      a=pop();
      b=pop();
      keisango=(b*a);
      push(keisango);

    }
    else {
      x = atoi(s);
      push(x);
    }
  }

  hyouji=pop();

  printf("%d\n",hyouji);

  return 0;
}

void push(int x){

  top++;
  S[top]=x;

}

int pop(){

  top--;

  return S[top+1];

}

Measured memory_bytes: 548
#include <iostream>
#include <stdio.h>  
#include <stdlib.h>

using namespace std;

int main() {
    int N;
    cin >> N;
    for (int i=0; i<=9; i++) {
        for (int j=0; j<=9; j++) {
            if (i*j==N) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'

N = int(input().strip())
def shifttext(shift):
    S = str(input('').upper())
    data = []
    for i in S:
        if i.strip() and i in alphabet:
            data.append(alphabet[(alphabet.index(i) + shift) % 26])
        else:
            data.append(i) 
    output = ''.join(data)
    return output
print(shifttext(N))

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

void solve() 
{
    int a,b;
    cin>>a>>b;
    for(double i=1;i<=100000;i++){
        if((int)(i*0.08)==a&&(int)(i*0.1)==b){
            cout<<i<<endl;
            return;
        }
    }
    cout<<-1<<endl;
}

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ins insert
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
ll fac(ll a){
    ll ans=1;
    while(a>1){
        ans*=a;
        ans%=1000000007;
        a--;
    }
    return ans;
}
ll modinv(ll a,ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
}
struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) {}

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool same(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};
int main(){
    ll h,w;cin >> h >>w;
    vector<string> m(h);
    rep(i,h)cin >> m[i];
    ll ans=0;
    rep(i,h){
        rep(j,w){
            if(m[i][j]=='#')continue;
            vvl dist(h,vl(w,-1));
            dist[i][j]=0;
            queue<pl> que;
            que.push(mp(i,j));
            while(!que.empty()){
                pl cur = que.front();
                ll y = cur.fi;
                ll x = cur.se;
                que.pop();
                for(ll dir=0;dir<4;dir++){
                    ll nx=x+dx[dir];
                    ll ny=y+dy[dir];
                    if(nx<0||nx>=w||ny<0||ny>=h)continue;
                    if(m[ny][nx]=='#')continue;
                    if(dist[ny][nx]==-1){
                        que.push(mp(ny,nx));
                        dist[ny][nx]=dist[y][x]+1;
                        ans=max(ans,dist[ny][nx]);
                    }
                }
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
using namespace std;
int main(){
        int N;
        cin >> N;
        int s[100000];
        map <int ,int> sc;
        map <int ,int> ss;
        for(int i=0 ; i<N ; i++ ){
                cin >> s[i];
                sc[s[i]]++;
                ss[s[i]]++;
        }
        int count=0;
        for(int i=0 ; i<N ; i++ ){
                if(ss[s[i]]==-1)
                        continue;
                else{
                        ss[s[i]]=-1;
                        s[count]=s[i];
                        count++;
                }

        }
        int ans=0;
        for(int i=0 ; i<sc.size() ; i++ ){
                int tmp=sc[s[i]]-s[i];
                if(tmp==0)
                        continue;
                if(tmp>0)
                        ans+=tmp;
                else{
                        ans+=sc[s[i]];
                }
        }
        cout << ans << endl;
        return 0;
}

Measured memory_bytes: 11672
n=int(input())
H=list(map(int,input().split()))
H.append(0)

res=0

while sum(H)!=0:
	for i in range(n):
		if H[i]==0:
			continue
		else:
			if H[i+1]==0:
				H[i]-=1
				res+=1
			else:
				H[i]-=1

print(res)

Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<functional>
#include<iomanip>
#include<queue>
#include<cassert>
#include<tuple>
#include<set>
#include<map>
#include<list>
#include<bitset>

#define PB push_back
#define ALL(a)  (a).begin(),(a).end()
#define DWN(a)  (a).begin(),(a).end(), greater<int>()
#define rep(i, m) for (int i = 0; i < m; i++)
#define REP(i, n, m) for (int i = n; i < m; i++)

#define mod 1000000007

using namespace std;

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

const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
const int INF = (int)1e9;

int main()
{
	int n;
	cin >> n;
	string s, t;
	cin >> s >> t;
	vector<int> v;
	rep(i, n) {
		if (s[i] == t[i]) {
			v.push_back(0);
		}
		else {
			v.push_back(1);
			i++;
		}
	}
	ll ans = (v[0] ? 6 : 3);
	rep(i, v.size() - 1) {
		if (v[i] && v[i + 1]) ans *= 3;
		else if (v[i] && !v[i + 1]) ans *= 1;
		else if (!v[i] && v[i + 1]) ans *= 2;
		else if (!v[i] && !v[i + 1]) ans *= 2;
		ans %= mod;
	}
	cout << ans << endl;
	return 0;
}

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

int main(){
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;
    string s(ty - sy, 'U');
    s += string(tx - sx, 'R');
    s += string(ty - sy, 'D');
    s += string(tx - sx + 1, 'L');
    s += string(ty - sy + 1, 'U');
    s += string(tx - sx + 1, 'R');
    s += "DR";
    s += string(ty - sy + 1, 'D');
    s += string(tx - sx + 1, 'L');
    s += 'U';
    cout << s << "\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <map>
#include <numeric>
#include <random>
#include <queue>
#include <deque>
#include <tuple>
#include <iomanip>

using namespace std;
typedef long long ll;

const int INF = (1 << 30) - 1;
const ll INFLL= (1LL << 61) - 1;
const int MOD = 1000000007;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin>>N;
  vector<ll> dp(N+1,100000);
  vector<ll> pow6(10),pow9(10);
  dp[0]=0;
  pow6[0]=1;
  pow9[0]=1;
  for(int i=0;i<9;i++){
    pow6[i+1]=6*pow6[i];
    pow9[i+1]=9*pow9[i];
  }
  for(int i=1;i<=N;i++){
    for(int j=0;j<8;j++){
      if(i-pow6[j]>=0){
        dp[i]=min(dp[i],dp[i-pow6[j]]+1);
      }
      if(i-pow9[j]>=0){
        dp[i]=min(dp[i],dp[i-pow9[j]]+1);
      }
    }
  }
  cout<<dp[N]<<endl;
}


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		new Main().run();
	}

	private void run() {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			int n = scanner.nextInt();
			int m = scanner.nextInt();
			if ((n | m) == 0)
				break;
			double[][] map = new double[n][n];
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < n; j++) {
					map[i][j] = scanner.nextDouble();
				}
			}
			double[][] dp = new double[m][n];
			for (int i = 0; i < n; i++) {
				dp[0][i] = 1;
			}
			for (int i = 1; i < m; i++) {
				for (int j = 0; j < n; j++) {
					for (int k = 0; k < n; k++) {
						dp[i][j] = Math.max(dp[i][j], dp[i - 1][k] * map[k][j]);
					}
				}
			}
			double a = 0;
			for (int i = 0; i < n; i++) {
				a = Math.max(a, dp[m - 1][i]);
			}
			System.out.println(String.format("%.2f", a));
		}
	}

	private double slove(int s, int m, double[][] map, int[] maxmap) {
		double k = 1;
		int g = 1;
		while (g < m) {
			k *= map[s][maxmap[s]];
			s = maxmap[s];
			g++;
		}
		return k;
	}
}

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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define all2(a, b) (a).begin(), (a).begin() + (b)
#define debug(vari) cerr << #vari << " = " << (vari) << endl;

bool is_palindrome(int x)
{
    int tmp = x;
    int res = 0;
    if (x != 0 && x % 10 == 0)
    {
        return 0;
    }
    while (res < x)
    {
        res = res * 10 + x % 10;
        x /= 10;
    }
    return x == res || x == res / 10;
}

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

    int ans = 0;
    rep2(i, a, b + 1) ans += is_palindrome(i);

    cout << ans << endl;

    return 0;
}


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

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

using namespace std;
using lint=long long;

const lint INF=1LL<<61;

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

int n,d[100000];
lint x[100000],y[100000];

lint fx(lint t){
	lint xl=INF,xr=-INF;
	rep(i,n){
		xl=min(xl,x[i]+t*dx[d[i]]);
		xr=max(xr,x[i]+t*dx[d[i]]);
	}
	return xr-xl;
}

lint fy(lint t){
	lint yl=INF,yr=-INF;
	rep(i,n){
		yl=min(yl,y[i]+t*dy[d[i]]);
		yr=max(yr,y[i]+t*dy[d[i]]);
	}
	return yr-yl;
}

int main(){
	scanf("%d",&n);
	rep(i,n){
		char c; scanf("%lld%lld %c",x+i,y+i,&c);
		x[i]*=2;
		y[i]*=2;
		if     (c=='R') d[i]=0;
		else if(c=='U') d[i]=1;
		else if(c=='L') d[i]=2;
		else            d[i]=3;
	}

	vector<lint> T={0,INF};
	lint lo,hi;
	lo=0; hi=INF;
	while(hi-lo>1){
		lint mi1=(2*lo+hi+1)/3,mi2=(lo+2*hi)/3;
		if(fx(mi1)<=fx(mi2)) hi=mi2;
		else                 lo=mi1;
	}
	T.emplace_back(lo);

	hi=INF;
	while(hi-lo>1){
		lint mi1=(2*lo+hi+1)/3,mi2=(lo+2*hi)/3;
		if(fx(mi1)<fx(mi2)) hi=mi2;
		else                lo=mi1;
	}
	T.emplace_back(lo);

	lo=0; hi=INF;
	while(hi-lo>1){
		lint mi1=(2*lo+hi+1)/3,mi2=(lo+2*hi)/3;
		if(fy(mi1)<=fy(mi2)) hi=mi2;
		else                 lo=mi1;
	}
	T.emplace_back(lo);

	hi=INF;
	while(hi-lo>1){
		lint mi1=(2*lo+hi+1)/3,mi2=(lo+2*hi)/3;
		if(fy(mi1)<fy(mi2)) hi=mi2;
		else                lo=mi1;
	}
	T.emplace_back(lo);
	sort(T.begin(),T.end());

	double ans=1e30;
	rep(i,(int)T.size()-1){
		lo=T[i]; hi=T[i+1];
		while(hi-lo>1){
			lint mi1=(2*lo+hi+1)/3,mi2=(lo+2*hi)/3;
			double x1=fx(mi1);
			double x2=fx(mi2);
			double y1=fy(mi1);
			double y2=fy(mi2);
			if(x1*y1<x2*y2) hi=mi2;
			else            lo=mi1;
		}
		ans=min(ans,1.*fx(lo)*fy(lo));
		ans=min(ans,1.*fx(hi)*fy(hi));
	}
	ans/=4;
	printf("%.15f\n",ans);

	return 0;
}


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

void solve() {
  int a, b, c; cin >> a >> b >> c;
  cout << ((a - c) * (c - b) > 0 ? "Yes" : "No") << endl;
}

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


Measured memory_bytes: 3620
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	const inputLines = input.split("\n");
	const line0 = inputLines[0];
	const line0vars = line0.split(" ");

	const h1 = parseInt(line0vars[0], 10)
	const m1 = parseInt(line0vars[1], 10)
	const h2 = parseInt(line0vars[2], 10)
	const m2 = parseInt(line0vars[3], 10)
	const k = parseInt(line0vars[4], 10)

	// console.log({
	// 	h1: h1,
	// 	m1: m1,
	// 	h2: h2,
	// 	m2: m2,
	// 	k: k
	// });

	const result = h2 * 60 + m2 - h1 * 60 - m1 - k;
	console.log(result);

	// tmp = input[1].split(" ");
	// //文字列から10進数に変換するときはparseIntを使います
	// var a = parseInt(input[0], 10);
	// var b = parseInt(tmp[0], 10);
	// var c = parseInt(tmp[1], 10);
	// var s = input[2];

	//出力
	// console.log('%d %s',a+b+c,s);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

// node index.js
// 1
// 2 3
// test
// (Ctrl + D)

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

#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for (int i = (n); i >= 0; i--)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int main()
{
    double w, h, x, y;
    cin >> w >> h >> x >> y;

    printf("%.10f %d\n", w * h / 2, 2 * x == w && 2 * y == h);

    return 0;
}

Measured memory_bytes: 256
a,b,c=map(int,input().split())
K=int(input())
for i in range(K):
  if c<=a:
    c=2*c
  elif b<=a:
    b=2*b
  elif c<=b:
    c=2*c
if a<b and b<c:
  print("Yes")
  exit()
else:
  print("No")
    

Measured memory_bytes: 9196
#include <bits/stdc++.h>
#define pb push_back
typedef long long ll;
using namespace std;
ll T;
ll steps;
ll solve(ll a , ll b , ll c , ll d)
{
        if(b <= c+1) {
                if(d < b) return 0;
                return 1;
        }
        if((a%b) > c) return 0;
        ll g = __gcd(b , d);
        ll k = (b - (a%b) + g - 1) / g;
        k = k - 1;
        ll maxval = (a%b + (k * g)%b)%b;
        if(maxval <= c) return 1;
        return 0;

}
int main()
{
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
        cin >> T;
        while(T--) {

                ll A , B , C , D;
                cin >> A >> B >> C >> D;
                if(D < B) {
                        cout << "No\n"; continue;
                }else if(A < B || A%B > C) {
                        cout << "No\n"; continue;
                }
                steps = 0;
                ll ans = solve(A , B , C , D);
                ans == 1 ? cout << "Yes\n" : cout << "No\n";
        }
        return 0;
}


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

using namespace std;
long long dp[3005][3005];
long long calc(long long a[], int l, int r)
{
  if(l>r)
    return 0;
  if(dp[l][r]!=-1)
    return dp[l][r];
  return dp[l][r]=max(a[l]+min(calc(a,l+2,r),calc(a,l+1,r-1)),a[r]+min(calc(a,l+1,r-1),calc(a,l,r-2)));
}

int main()
{
  int n;
  cin>>n;
  long long a[n],s=0;
  for(int i=0;i<n;i++)
  {
    cin>>a[i];
    s+=a[i];
  }
  memset(dp,-1,sizeof(dp));
  cout<<2*calc(a,0,n-1)-s<<endl;
  return 0;
}


Measured memory_bytes: 74308
function Main(input) {
	input = input.split("\n");
  	var n = parseInt(input[0], 10);
  	A = input[1].split(" ");
  	var a = parseInt(A[0], 10);
  	var max = a;
  	var min = a;
  	for (var i=1; i<n; i++){
      a = parseInt(A[i], 10);
      if(a>max){
       max=a; 
      }else{
       if (a<min){
         min=a;
       }
      }
    }
  console.log('%d',max-min);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

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

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

//const value
//const ll MOD = 1e9 + 7;
//const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
//const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

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

typedef string::const_iterator State;
int expression(State &begin);
int number(State&);
int factor(State&);
int term(State&);
int expression(State&);

int number(State &begin){
  int ret = 0;
  while(isdigit(*begin)){
    ret *= 10;
    ret += *begin - '0';
    begin++;
  }
  return ret;
}

// 括弧か数をパースして、その評価結果を返す。
int factor(State &begin) {
    if (*begin == '(') {
        begin++;
        int ret = expression(begin);
        begin++;
        return ret;
    } else {
        return number(begin);
    }
    return -1;
}

int term(State & begin){
  int ret = factor(begin);
  while(true){
    if(*begin == '*'){
      begin++;
      ret *= factor(begin);
    } else if (*begin == '/') {
      begin++;
      ret /= factor(begin);
    } else {
      break;
    }
  }
  return ret;
}

int expression(State &begin){
  int ret = term(begin);
  while(true){
    if(*begin == '+'){
      begin++;
      ret += term(begin);
    } else if (*begin == '-') {
      begin++;
      ret -= term(begin);
    } else {
      break;
    }
  }
  return ret;
}

int main(){
  int N;
  cin >> N;
  rep(i,N){
    string s;
    cin >> s;
    if(s.size() > 0) s = s.substr(0,s.size()-1);
    State begin = s.begin();
    int ans = expression(begin);
    cout << ans << endl;
  }
  return 0;
}



Measured memory_bytes: 3004
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**9)
from bisect import bisect_left
n,q=map(int,input().split())
S=input()
A=[]
for i in range(len(S)-1):
    if S[i]=='A' and S[i+1]=='C':
        A.append(i)
for _ in range(q):
    l,r=map(int,input().split())
    left=bisect_left(A,l-1)
    right=bisect_left(A,r-1)
    print(right-left)

Measured memory_bytes: 59272
//                                ** ALLAH **
//                        who is Hussain? -> whoishussain.org

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

const int mod=1000000007;
const int N = 2e5 + 100, M = 2002;


int n, a[N], b[N], dpdpdp[3*M][3*M], fact[4*M+1];
int powm(int x, int p){
        int ret = 1;
        while( p ){
                if( p & 1 ) ret = 1ll * ret * x % mod;
                x = 1ll * x * x % mod;
                p>>=1;
        }
        return ret;
}

int &dp(int i, int j){
        return dpdpdp[i+M][j+M]; 
}

int32_t main(){
        cin >> n;
        for(int i =0;i < n;i ++) cin >> a[i] >> b[i], dp(-a[i],-b[i]) += 1;
         
        for(int i = -M+2; i < M; i++)
                for(int j = -M+2; j < M; j++)
                        dp(i,j) = (dp(i,j) + dp(i-1,j) + dp(i,j-1)) % mod;
        
        fact[0] = 1;
        for(int i= 1;i < 4*M;i ++) fact[i] = 1ll*fact[i-1] * i % mod;
        int ans = 0;
        for(int i = 0;i < n;i ++){
                ans = (ans + dp(a[i],b[i]))%mod;
                ans = (ans - 1ll * fact[2*(a[i]+b[i])] * powm(fact[2*a[i]],mod-2) % mod * powm(fact[2*b[i]],mod-2) % mod +mod ) %mod; 
        }
        ans = 1ll * ans * powm(2, mod-2) % mod; 
        cout << (ans+mod)%mod << endl;
         


}


Measured memory_bytes: 97280
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<map>
#include<queue>
#include<vector>
using namespace std;

string rev(string s) {
	reverse(s.begin(), s.end());
	return s;
}

int main() {
	int m; cin >> m;
	while (m--) {
		string s;
		cin >> s;

		set<string> S;
		for (int i = 1; i < s.size(); i++) {
			string a = s.substr(0, i),
				b = s.substr(i),
				c = rev(a),
				d = rev(b);
			S.insert(a + b);
			S.insert(b + a);
			S.insert(a + d);
			S.insert(d + a);
			S.insert(c + b);
			S.insert(b + c);
			S.insert(c + d);
			S.insert(d + c);
		}
		cout << S.size() << endl;
	}
	return 0;
}

Measured memory_bytes: 1292
from math import gcd
K = int(input())
ans = 0
for i in range(1, K+1):
    for j in range(i+1, K+1):
        for k in range(j+1, K+1):
            ans += gcd(gcd(i, j), k)*6

for i in range(1, K+1):
    for j in range(i+1, K+1):
        ans += gcd(i, j)*6

ans += K*(K+1)//2

print(ans)


Measured memory_bytes: 9104
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		List<Integer> list =new ArrayList<Integer>();
		do {
			list.add(n%k);
			n/=k;
		}while(n>0);
		System.out.println(list.size());
	}

}


Measured memory_bytes: 21844
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val h = sc.nextInt()
    val w = sc.nextInt()

    var cnt = 0
    for (i in 0 until h) {
        val a = sc.next()
        for (c in a) {
            if (c == '#') cnt++
        }
    }
    println(if (cnt == h + w - 1) "Possible" else "Impossible")
}


Measured memory_bytes: 31388
#include<bits/stdc++.h>
#define ll long long
#define inf 1010000000
#define infll 1010000000000000000ll
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mpr make_pair
#define fi first
#define se second
#define vi vector<int>
#define pb push_back
#define mod 1000000007
#define ad(x,y) (x=(x+(y))%mod)
#define up(x,y) (x<(y)?x=(y):0)
#define dn(x,y) (x>(y)?x=(y):0)
#define N 200009
using namespace std;

int n,m,dp[N][2][2],f[N]; char ch[N]; vi e;
void solve0(){
	int i,j,k,l; dp[1][0][0]=dp[1][1][1]=1;
	for (i=2; i<=n; i++)
		for (j=0; j<2; j++)
			for (k=0; k<2; k++)
				for (l=0; k+l<2; l++)
					ad(dp[i][j][l],dp[i-1][j][k]);
	printf("%d\n",((dp[n][0][0]+dp[n][0][1])%mod+dp[n][1][0])%mod);
}
int main(){
	scanf("%d%d%s",&n,&m,ch+1);
	int i;
	if (ch[1]=='B')
		for (i=1; i<=m; i++)  ch[i]=(ch[i]=='R'?'B':'R');
	for (i=2; i<=m; i++) if (ch[i]=='B') break;
	if (i>m){
		solve0(); return 0;			
	}
	memset(dp,0,sizeof(dp));
	for (i=m; i; i--) if (ch[i]=='B') break;
	int lim=n,now=0;
	for (; i>=0; i--){
		if (!i || ch[i]=='B'){
			if (now) e.pb(now);
			now=0;
		} else now++;
	}
	reverse(e.begin(),e.end());
	for (i=0; i<e.size(); i++){
		if (i==0 && !(e[i]&1)) dn(lim,e[i]+2);
		if (e[i]&1) dn(lim,e[i]+1);	
	}
	f[0]=f[2]=1;
	for (i=3; i<=n; i++)
		f[i]=((ll)f[i-2]-(i-2-lim>=0?f[i-2-lim]:0)+f[i-2]+mod)%mod;
	int ans=0;
	for (i=2; i<=lim; i+=2) ad(ans,(ll)f[n-i]*i);
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 4604
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  int N;

    cin >> N;
    int n = N,a,b,cnt =1;
    vector<int> v(N),P,Q;

 	while(n--) {
		int x;
		cin >> x;
		P.push_back(x);
	}

    n = N;

    while(n--) {
		int x;
		cin >> x;
		Q.push_back(x);
	}

    iota(v.begin(), v.end(), 1);       // v に 1, 2, ... N を設定

    do {

        if(equal ( v.begin(), v.end(), P.begin()) == true){
            a = cnt;
        }
        if(equal ( v.begin(), v.end(), Q.begin()) == true){
            b = cnt;
        }
        //for(auto x : v) cout << "v"<< x << " "; cout << "\n";    // v の要素を表示

        cnt++;
    } while( next_permutation(v.begin(), v.end()) );     // 次の順列を生成

        cout << abs(a-b)<< endl;

    return 0;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mp make_pair
#define eb emplace_back
#define fi first
#define se second
using namespace std;
using cd = complex <double>;
 
typedef pair <int, int> pii;
 
const long long INF = 1e15;
const int mod = 998244353;//1000000007;
const double Pi = acos(-1);
 
void Fastio()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
}

int s[10005];

long long f(long long n)
{
	if(n < 0)
	{
		return 0; 
	}
	if(n % 4 == 0)
	{
		return n;
	}
	else if(n % 4 == 2)
	{
		return n + 1;
	}
	else if(n % 4 == 3)
	{
		return 0;
	}
	else
	{
		return 1;
	}
}

int main()
{
	long long a, b;
	cin >> a >> b;
	long long temp = f(a - 1) ^ f(b);
	cout << temp;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define rep2(i,j,n) for(int j=i;j<n;j++)
#define rep3(i,j,n) for(int j=i;j<=n;j++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define sp(n) cout << fixed << setprecision(n)
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; }
typedef long long ll;
using namespace std;
int main(void){
    ll n,m;cin>>n>>m;
    vector<vector<ll>> t(n);
    rep(i,m){
        ll a,b;cin>>a>>b;a--;b--;
        t[a].push_back(b);
        t[b].push_back(a);
    }
    vector<bool> used(n,false);
    queue<int> que;
    que.push(0);
    vector<ll> tr;
    while(que.size()){
        int x=que.front();que.pop();
        tr.push_back(x);
        used[x]=true;
        bool ok=true;
        rep(i,t[x].size()){
            int y=t[x][i];
            if(used[y])continue;
            ok=false;
            que.push(y);
            break;
        }
        if(ok)break;
    }
    reverse(tr.begin(),tr.end());
    que.push(0);
    used[0]=false;
    while(que.size()){
        int x=que.front();que.pop();
        if(x!=0)tr.push_back(x);
        used[x]=true;
        bool ok=true;
        rep(i,t[x].size()){
            int y=t[x][i];
            if(used[y])continue;
            ok=false;
            que.push(y);
            break;
        }
        if(ok)break;
    }
    reverse(tr.begin(),tr.end());
    //経路復元
    cout<<tr.size()<<endl;
    rep(i,tr.size()) cout<<tr[i]+1<<" ";
    cout<<endl;
}

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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

int n;
string s;

int main() {
	cin >> n >> s;
	
	int ma = 0;
	incII(i, 0, n) {
		string t = s.substr(0, i);
		string u = s.substr(i);
		// cout << t << " " << u << endl;
		
		int c = 0;
		inc(j, 26) {
			if(count(ALL(t), 'a' + j) > 0 && count(ALL(u), 'a' + j)) { c++; }
		}
		setmax(ma, c);
	}
	
	cout << ma << endl;
	
	return 0;
}


Measured memory_bytes: 256
fn main() {
    proconio::input! {
        n: usize,
    }

    let m = 1000000007;

    let mut dp = vec![vec![0 as usize; 4]; n + 1];

    dp[0][0] = 1;

    for i in 0..n {
        dp[i + 1][0] = (dp[i][0] * 8) % m;

        dp[i + 1][1] = (dp[i][0] + dp[i][1] * 9) % m;
        dp[i + 1][2] = (dp[i][0] + dp[i][2] * 9) % m;

        dp[i + 1][3] = (dp[i][1] + dp[i][2] + dp[i][3] * 10) % m;
    }

    println!("{}", dp[n][3]);
}


Measured memory_bytes: 72180
def cal raw
  ar = raw.clone
  min_value = ar.shift
  max_value = -(10**9)

  ar.each_with_index { |n, i|
    max_value = [max_value, n - min_value].max
    min_value = [n, min_value].min
  }

  max_value

end

size = STDIN.gets.chomp.to_i
prefits = []
size.times{ 
  prefits.push STDIN.gets.chomp.to_i
}


puts cal prefits

Measured memory_bytes: 11192
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<ll,ll,ll> T;
const long long INF = 1LL<<60;
const int MOD = 1000000000+7;
#define rev(s) (string((s).rbegin(), (s).rend()))
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };
// cout << fixed << setprecision(10) << ans << endl;
// *min_element(c + l, c + r) *max_element(c + l, c + r)
// int dx[8]={1,1,0,-1,-1,-1,0,1};
// int dy[8]={0,1,1,1,0,-1,-1,-1};
// int dx[4]={1,0,-1,0};
// int dy[4]={0,1,0,-1};
// struct Edge {
//   int to, id;
//   Edge(int to, int id): to(to), id(id) {}
// };

int main() {
  int N, K; cin >> N >> K;
  vector<ll> a(N);
  rep(i, N) cin >> a[i];
  vector<ll> pre(K + 10, 0), now(K + 10,0);
  pre[0] = 1;
  rep(i, N) {
    now[0] = pre[0];
    rep(j, K + 1) {
      if(j == 0) continue;
      now[j] = (pre[j] + now[j - 1]) % MOD;
    }
    pre = now;
    rep(j, K + 1) {
      if(j - a[i] - 1 >= 0) {
	now[j] = (pre[j] - pre[j - a[i] - 1] + MOD) % MOD; 
      }
    }
    pre = now;
  }
  cout << now[K] << endl;
}

Measured memory_bytes: 4732
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")

N, M = list(map(int, sys.stdin.readline().split()))

# 1 回の期待値
a = (N - M) * 100 + M * 1900
# 終わるまでの回数の期待値
# 1 ケースが 1/2 なので 1 提出が 1/2**M で、その逆数
c = 1 / (1 / 2 ** M)

print(int(a * c))


Measured memory_bytes: 3060
from collections import Counter,defaultdict,deque
import sys
import bisect
import math
import itertools
import string
import queue
import copy
# import numpy as np
# import scipy
from itertools import permutations, combinations
from heapq import heappop, heappush
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
 
def inp(): # n=1
    return int(input())
def inpm(): # x=1,y=2
    return map(int,input().split())
def inpl(): # a=[1,2,3,4,5,...,n]
    return list(map(int, input().split()))
def inpls(): # a=['1','2','3',...,'n']
    return list(input().split())
def inplm(n): # x=[] 複数行
    return list(int(input()) for _ in range(n))
def inpll(n): # [[1,1,1,1],[2,2,2,2],[3,3,3,3]]
    return [list(map(int, input().split())) for _ in range(n)]

def main():
    k,x = inpm()
    if 500*k>=x:
        print('Yes')
    else:
        print('No')
        
          

if __name__ == "__main__":
    main()

Measured memory_bytes: 39148
n = int(input())
p = list(map(int, input().split(" ")))
count = 0
for i in range(n-2):
	if (p[i]<p[i+1] and p[i+1]<p[i+2]) or (p[i]>p[i+1] and p[i+1]>p[i+2]):
		count = count + 1
print(count)

Measured memory_bytes: 3060