akhauriyash/Code-Regression huggingface dataset:
fn read_stdin() -> String {
    use std::io::Read;
    let mut input = String::new();
    std::io::stdin().read_to_string(&mut input).unwrap();
    input
}

fn scan<'a, I: Iterator<Item = &'a str>, T: std::str::FromStr>(tokens: &mut I) -> T {
    tokens.next().unwrap().parse().ok().unwrap()
}

fn main() {
    let input = read_stdin();
    let tokens = &mut input.split_whitespace();
    let n: usize = scan(tokens);
    let mut a: Vec<usize> = vec![0; n + 1];
    for i in 1..n + 1 {
        a[i] = scan(tokens);
    }
    let mut b: Vec<usize> = Vec::new();
    for i in (1..n + 1).rev() {
        if a[i] == 1 {
            b.push(i);
            let mut d = 1;
            while d * d < i {
                if i % d == 0 {
                    a[d] ^= 1;
                    a[i / d] ^= 1;
                }
                d += 1;
            }
            if d * d == i {
                a[d] ^= 1;
            }
        }
    }
    println!("{}", b.len());
    for i in 0..b.len() {
        if i != 0 {
            print!(" ");
        }
        print!("{}", b[i]);
    }
    println!("");
}


Measured memory_bytes: 8828
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int x = sc.nextInt();
    int a = sc.nextInt();
    int b = sc.nextInt();
    int ax = 0;
    int bx = 0;
    ax=Math.max(a-x,x-a);
    bx=Math.max(b-x,x-b);
    if(ax<bx){
      System.out.println("A");
    }else{
      System.out.println("B");
    }
  }
  

  
}

Measured memory_bytes: 19924
#!/bin/bash
''':'
docker run --rm -it -v $(cd $(dirname $0) && pwd):/vo:ro pypy:3-2.4.0 \
   /bin/bash -c "pypy3 /vo/$(basename $0) < /vo/input.txt"
exit $?
'''
import sys

def _ia(): return map(int, sys.stdin.readline().strip().split())


def main():
    n, k = _ia()
    a = [ai-1 for ai in _ia()]
    d = [[0]*n for _ in range(60)]
    d[0] = a
    for i in range(59):
        now = d[i+1]
        prev = d[i]
        for j in range(n):
            now[j] = prev[prev[j]]

    now = 0
    for i in range(k.bit_length()):
        if k & 1:
            now = d[i][now]
        k >>= 1

    return now + 1

if __name__ == "__main__":
    print(main())


Measured memory_bytes: 174872
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<utility>
#include<array>
#include<cassert>
#include<list>
#include<experimental/any>
#include<cstring>
#include<cctype>
#include<ctime>
#include<cstdbool>
#include<cstdint>
#include<cstddef>
#include<set>
#include<unordered_set>
#include<bitset>
 
using namespace std;
using experimental::any;
 
#define SPEEDY cin.tie(0);ios::sync_with_stdio(false);
 
#define REP(i,n) for(int i=0;i<(n);i++)
#define ARREP(i,n,X) for(int i=0;i<(n);i++)cin>>X[i]
#define FOR(i,X,n) for(int i=(X);i<(n);i++)
#define EREP(i,n) for(int i=1;i<=n;i++)
#define BitFOR(N) REP(Bit,1<<(N))
 
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define DEB2(X) cout<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define TFDEB(f) (f)? cout<<"true ":cout<<"false ";
#define FORDEB(n,X) for(int i=0;i<(n);i++)ARDEB(i,X)
#define END cout<<endl;
#else
#define DEB(X) {}
#define DEB2(X) {}
#define ARDEB(i,X) {}
#define TFDEB(f) {}
#define FORDEB(n,X) {}
#define END {}
#endif
 
typedef long long int ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
#define ALL(X) X.begin(),X.end()
struct edge{int to,cost;};
//struct edge{int from,cost,to;};
struct P2{int x,y;};
#define BIT(Bit,n) bitset<n>(Bit)
#define Endl endl
 
const int MOD7=1000000007;
const int INF=100000000;
const int SET=1000;
 
int dp[4000][8000],dp2[4000][8000];
int F[4000],T[4000],F2=0,T2=0;
int X,Y;

int DP(int a,int b){
	if(dp[a][b]!=-1)return dp[a][b];
	if(a==F2){
		return dp[a][b]=(X==b);
	}
	return dp[a][b]=(DP(a+1,b+F[a])||DP(a+1,b-F[a]));
}

int DP2(int a,int b){
	if(dp2[a][b]!=-1)return dp2[a][b];
	if(a==T2){
		return dp2[a][b]=(Y==b);
	}
	return dp2[a][b]=(DP2(a+1,b+T[a])||DP2(a+1,b-T[a]));
}

int main(){
	int count=0,mode=0;
	string s;
	cin>>s>>X>>Y;
	REP(i,s.size()){
		if(s[i]=='T'){
			if(mode==0){
				F[F2]=count,F2++;
				count=0,mode=1;
			}
			else{
				T[T2]=count,T2++;
				count=0,mode=0;
			}
		}
		else{
			count++;
		}
	}
	if(mode==0){
		F[F2]=count,F2++;
		count=0,mode=1;
	}
	else{
		T[T2]=count,T2++;
		count=0,mode=0;
	}
	REP(i,4000)REP(j,8000){
		dp[i][j]=-1,dp2[i][j]=-1;
	}
	cout<<((DP(1,F[0])&&DP2(0,0))?"Yes":"No")<<endl;
	return 0;
}


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

int main(void){
    string S;cin>>S;
    if(S[0]!='A'){
        cout<<"WA"<<endl;
        return 0;
    }
    int C=0;
    for(int i=0;i<S.size();i++){
        if(i>=2&&i<=S.size()-2){
            if(S[i]=='C'){
                C++;
            }
        }
        else if(i!=0){
            if(S[i]<97||S[i]>122){
                cout<<"WA"<<endl;
                return 0;
            }
        }
    }
    if(C>1||C<1){
        cout<<"WA"<<endl;
        return 0;
    }
    cout<<"AC"<<endl;
    return 0;
}

Measured memory_bytes: 3576
#include<algorithm>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include  <stdio.h>
#include   <math.h>
#include   <time.h>
#include   <vector>
#include   <bitset>
#include    <queue>
#include      <set>
#include      <map>
using namespace std;

const int N=105;

char a[N];
int Num[N];

int main()
{
	int n,m;cin>>n>>m;
	for(int i=1;i<=n;i++)
	{
		cin>>a;
		for(int j=0;j<m;j++)
			Num[a[j]-'a']++;
	}
	int num2=0,num1=0;
	if(n&1)
		num2+=m/2;
	if(m&1)
		num2+=n/2;
	if((n&1)&&(m&1))
		num1++;
	int Num1=0,Num2=0;
	for(int i=0;i<26;i++)
		if(Num[i]%2==1)
			Num1++;
		else if(Num[i]/2%2==1)
			Num2++;
	if(Num1==num1&&num2>=Num2)
		puts("Yes");
	else
		puts("No");
	return 0;
}


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

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define ALL(v) v.begin(),v.end()
#define rALL(v) v.rbegin(),v.rend()
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cout<<v[i]<<" "

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<ll, ll> P;
struct Edge{ll from, to, cost;};
struct node{ll cost, to;
  bool friend operator>(node a, node b){
    return a.cost>b.cost;
  }
};

ll mod(ll a, ll mod){
  ll res = a%mod;
  if(res<0)res=res + mod;
  return res;
}

ll modpow(ll a, ll n, ll mod){
  ll res=1;
  while(n>0){
    if(n&1) res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll modinv(ll a, ll mod){
  return modpow(a, mod-2, mod);
}

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

bool is_prime(ll n){
  ll i = 2;
  if(n==1)return false;
  if(n==2)return true;
  bool res = true;
  while(i*i <n){
    if(n%i==0){
      res = false;
    }
    i = i+1;
  }

  //if(i==1)res = false;
  if(n%i==0)res=false;
  return res;
}


/**************************************
** A main function starts from here  **
***************************************/
int main(){
  ll N, H;
  cin >> N >> H;
  llvec A(N), B(N);
  rep(i, N){
    cin >> A[i] >> B[i];
  }

  sort(rALL(A));
  sort(rALL(B));
  ll i=0;
  while(B[i]>A[0] and i<N and H>0){
    H-=B[i];
    i++;
  }
  if(H<0)cout << i;
  else cout << i + (H+A[0]-1)/A[0];
  return 0;
}


Measured memory_bytes: 1792
import java.io.*;
import java.util.*;
public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		PrintWriter pw = new PrintWriter(System.out);
		String s=sc.next();
		String t=sc.next();
		int a=sc.nextInt();
		int b=sc.nextInt();
		String u=sc.next();
		boolean x=true;
		if(s.length()==u.length()&&t.length()!=u.length())
			x=true;
		else if(s.length()!=u.length()&&t.length()==u.length())
			x=false;
		else {
		for (int i=0;i<s.length();i++) {
			if(s.charAt(i)!=u.charAt(i)) {
				x=false;
			    break;
			}
		}
		}
		if(x==true)
			a--;
		else
			b--;
		pw.print(a+" "+b);
		pw.close();
	}
	static class Scanner {
		StringTokenizer st;
		BufferedReader br;
		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}
		public Scanner(String file) throws FileNotFoundException {
			br = new BufferedReader(new FileReader(file));
		}
		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
		public String nextLine() throws IOException {
			return br.readLine();
		}
		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
		public boolean ready() throws IOException {
			return br.ready();
		}
	}
}

Measured memory_bytes: 21460
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
 
int main(){
    int A, B;
    string op;
    cin >> A >> op >> B;
    if(op[0] == '+')
        cout << A + B << endl;
    else
        cout << A - B << endl;
    return 0;
}

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

int main() {
    string t, p; cin >> t >> p;
    for (int i = 0; i < t.size(); i++) {
        int c = 0;
        for (int j = 0; i + j < t.size() && j < p.size(); j++) {
            c += t[i+j] == p[j];
        }
        if (c == p.size()) cout << i << endl;
    }
}


Measured memory_bytes: 3164
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<queue>
#include<map>
#include<string>
#define all(x) (x).begin(),(x).end()
#define print(x) cout << (x) << endl
typedef long long ll;
typedef long double ld;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
 
using namespace std;

int main(){
    int n;  cin >> n;
    ll tmp, ans;
    ll a;   cin >> a;
    tmp = a;
    ans = 0;
    for(int i=1; i<n; i++){
        ll d;   cin >> d;
        ans += tmp*d;
        tmp += d;
        tmp %= MOD;
        ans %= MOD;
    }
    print((ans+MOD)%MOD);
}

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

#define endl '\n'
#define fi first
#define se second
#define pb push_back
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
const int MOD = 1e9 + 7;
const int maxn = 1e6 + 5;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-8;

int a[maxn];

int main() {
    memset(a, -1, sizeof(a));
    int n, m, f = 0;
    scanf("%d%d", &n, &m);
    if (n == 1 && !m) return puts("0"), 0;
    for (int i = 1, s, c; i <= m; i++) {
        scanf("%d%d", &s, &c);
        if (a[s] == -1) a[s] = c;
        else {
            if (a[s] != c) f = 1;
        }
    }
    if (f || (n != 1 && a[1] == 0)) return puts("-1"), 0;
    printf("%d", (a[1] == -1 ? 1 : a[1]));
    for (int i = 2; i <= n; i++) {
        printf("%d", (a[i] == -1 ? 0 : a[i]));
    }
    puts("");
    return 0;
}


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

int main() {
  int N,M;
  cin>>N>>M;
  
 vector<int>vec(M*2);
  for(int i;i<M*2;i++){
    cin>>vec.at(i);
  }
  
  
  
  for(int j=0;j<N;j++){
    int a=0;
    for(int i=0;i<M*2;i++){
      if(vec.at(i)==j+1){
        a++;}
      }
    cout<<a<<endl;
     
  }
}




Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
#include <algorithm>
#include <queue>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(x) (x).begin(), (x).end()

int main() {
    int n;
    cin>>n;
    vector<int>a(n);
    rep(i,n)cin>>a[i];
    sort(all(a),greater<int>());
    int b=1;
    rep(i,n){
        if(a[i]!=n-1-(i/2)*2)b=0;
    }
    if(b==0)cout<<0;
    else{
        int ans=1;
        int p=n/2;
        rep(i,p){
            ans*=2;
            ans%=1000000007;
        }
        cout<<ans;
    }
	return 0;
}


Measured memory_bytes: 3676
/************************************************
Author :PumpkinYing
Created Time :2017/12/2 11:31:02
File Name :2.cpp
************************************************ */
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <algorithm>
#include <string>
#include <math.h>
#include <cstdlib>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
typedef long long ll;
typedef pair<int,int> pii;

const int maxn = 200010;

char a[maxn];
ll num[30];

int main()
{
	scanf("%s",a);
	ll n = strlen(a);
	for(int i = 0;i < n;i++) num[a[i]-'a']++;
	ll ans = (n+1)*n/2;
	for(int i = 0;i < 26;i++) ans -= num[i]*(num[i]+1)/2;
	printf("%lld\n",ans+1);
	return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
long long cnt,n,m,k[20],s[20][20],ans,p[20];
int main()
{
	cin>>n>>m;
	for(int i=0;i<m;i++)
	{
		cin>>k[i];
		for(int j=0;j<k[i];j++)
		{
			cin>>s[i][j];
			s[i][j]--;
		}
	}
	for(int i=0;i<m;i++)
	{
		cin>>p[i];
	}
	for(int i=0;i<(1<<n);i++)
	{
		cnt=0;
		for(int j=0;j<m;j++)
		{
			long long now=0;
			for(int l=0;l<k[j];l++)
			{
				if((i>>s[j][l])&1)
				{
					now++;
				}
			}
			if(now%2==p[j])
			{
				cnt++;
			}
		}
		if(cnt==m)
		{
			ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
l = list(map(int, input().split()))
l.sort()
cnt = 0 
import bisect
for i in range(0,n-2):
    a = l[i]
    for j in range(i+1,n-1):
        b = l[j]
        target = a + b 
  #      print("#",a,b)
        f1 = bisect.bisect_left(l,target,j+1,n)
        cnt+= f1 - 1- j
   #     print("cnt: ",cnt)
print(cnt)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e3+5;
vector<ll> V;
int price[maxn],a[maxn][maxn];
int n,m,x;
bool cho[maxn];
ll ans=1e18;
void check(){
    ll now[20];memset(now,0,sizeof now);
    ll sum=0;
    for(int i=1;i<=n;i++){
        if(cho[i]) {
            for(int j=1;j<=m;j++) now[j]+=a[i][j]; 
            sum+=price[i];
        }
    }
    for(int j=1;j<=m;j++) if(now[j]<x) return;
    ans=min(ans,sum);
}
void dfs(int dep){
    if(dep==n+1){
        check();
        return;
    }
    cho[dep]=1;
    dfs(dep+1);
    cho[dep]=0;
    dfs(dep+1);
}
int main() {
    cin>>n>>m>>x;
    for(int i=1;i<=n;i++){cin>>price[i];for(int j=1;j<=m;j++) cin>>a[i][j];}
    dfs(1);
    if(ans==1e18) ans=-1;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3676
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <vector>
using ll = long long;
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;

int main() {
    int a, b;
    cin >> a >> b;
    cout << a * b << " " << 2 * (a + b) << endl;
}


Measured memory_bytes: 3120
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace aoj1160 {
	class Program {
		static void Main (string[] args) {
			while (true) {
				int w, h;
				var whstr = Console.ReadLine();
				var wh = whstr.Split(' ');
				w = int.Parse(wh[0]);
				h = int.Parse(wh[1]);
				if (w == 0)
					break;
				int[,] shima = new int[w, h];
				int i, j, numShima = 0;
				for (j = 0;j < h;j++) {
					var wstr = Console.ReadLine().Split(' ');
					for (i = 0;i < w;i++) {
						shima[i, j] = int.Parse(wstr[i]);
					}
				}
				for (i = 0;i < w;i++) {
					for (j = 0;j < h;j++) {
						if (judge(shima, i, j, w, h))
							numShima++;
					}
				}
				Console.WriteLine(numShima);
			}
		}

		static bool judge (int[,] map, int x, int y, int w, int h) {
			if (x < 0 || y < 0 || w - 1 < x || h - 1 < y)
				return false;
			if (map[x, y] == 0)
				return false;
			map[x, y] = 0;
			judge(map, x - 1, y - 1, w, h);
			judge(map, x - 1, y, w, h);
			judge(map, x - 1, y + 1, w, h);
			judge(map, x + 1, y - 1, w, h);
			judge(map, x + 1, y, w, h);
			judge(map, x + 1, y + 1, w, h);
			judge(map, x, y - 1, w, h);
			judge(map, x, y, w, h);
			judge(map, x, y + 1, w, h);

			return true;
		}
	}
}

Measured memory_bytes: 5940
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define per(i, n) for(ll i=((ll)(n))-1; i>=0; i--)
#define perf(i, n) for(ll i=((ll)(n)); i>0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

int main(){
    Init();
    string s; cin >> s;
    bool ac = true;
    ll cnt = 0;

    if(s[0] != 'A') ac = false;
    s[0] = tolower(s[0]);

    rep(i, s.size()){
        if(i >= 2 && i <= s.size()-2){
            //先頭から3文字目～末尾から2文字目ならば
            if(s[i] == 'C') cnt++;
            s[i] = tolower(s[i]);
        }
        if(isupper(s[i])) ac = false;
    }
    if(cnt != 1) ac = false;

    cout << ((ac) ? "AC" : "WA") << endl; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;
#define rep(i,n) for(ll i=0;i<n;i++)

int main(){
	int n,k;cin>>n>>k;
	int d[k];
	rep(i,k) cin>>d[i];

	for(int i=n;;i++){
		int j=i;
		bool chk=1;
		while(j){
			int k=j%10;
			for(auto p:d){
				if(p==k){
					chk=0;
					break;
				}
			}
			if(!chk) break;
			j/=10;
		}
		//cout<<i<<"\n";
		if(chk){
			cout<<i<<"\n";
			return 0;
		}
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REP1(i,n) for(ll i=1;i<=(ll)(n);i++)

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

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

ll power(ll a, ll n)
{
    if (n == 0)
        return 1;
    ll p = power(a, n / 2);
    p = (p * p);
    if (n % 2)
        return (p * a);
    else
        return p;
}

int main() {
    ios_base::sync_with_stdio(false);    //for fast I/O operation
    cin.tie(NULL);

    ll mod = 1000000007;

    ll n,k;
    cin >> n >> k;
    ll c = 0;

    ll s[n+1];
    s[0] = 0;
    REP(i,n){
        s[i+1] = s[i] + i + 1;
    }

    for(int i = k; i <= n+1; i++ ){
        ll min = 0;
        min = s[i-1] - s[0];
        ll max = 0;
        if( i != n+1 ){
            max = s[n] - s[n-i];
        } else {
            max = s[n];
        }
        c += max - min + 1;
        c = c % mod;
    }
    cout << c << endl;
   
}


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

int main() {
  int n;cin>>n;
  vector<int>p(n),q(n);
  rep(i,n)cin>>p[i];
  rep(i,n)cin>>q[i];
  vector<int> a(n);
  rep(i,n)a[i]=i+1;
  map<vector<int>,int> mp;
  do{
    mp[a]=mp.size();
  }while(next_permutation(all(a)));
  int ans=abs(mp[p]-mp[q]);
  cout<<ans<<endl;
}

Measured memory_bytes: 8672
# util functions

# debug
$debugFlag = ( ARGV[0] != nil )
p "==== DEBUG MODE ====" if $debugFlag

def pd(str)
  p str if $debugFlag
end

def printd(str)
  print str if $debugFlag
end

# input
inputs = []
lc = 0
nn = 0
while l = $stdin.gets do
  if lc == 0
    nn = l.chomp.to_i
  else
    inputs << l.chomp.split(" ").map(&:to_i)
  end
  lc += 1
end

# input check
if $debugFlag
  p "--- INPUT (begin) ---"
  inputs.each do |l_i|
    p l_i
  end
  p "--- INPUT (end) ---"
  print "\n"
end

# body
if $debugFlag
  p nn
  p inputs
end

if nn == 1
  puts 1
  exit
end

perm = [*(0..nn-1)].permutation(2).to_a

$statis = {}
perm.each do |c|
  pv = inputs[c[1]][0] - inputs[c[0]][0]
  qv = inputs[c[1]][1] - inputs[c[0]][1]

  if $statis["#{pv},#{qv}"] != nil
    $statis["#{pv},#{qv}"] += 1
  else
    $statis["#{pv},#{qv}"] = 1
  end
  
end

tmp_max = 0
$statis.each do |k, v|
  if v > tmp_max
    tmp_max = v
  end
end

puts (nn - tmp_max)


Measured memory_bytes: 14720
n, w = map(int, input().split())
ws = [0] * n
vs = [0] * n
for i in range(n):
    ww, vv = map(int, input().split())
    ws[i] = ww
    vs[i] = vv

dp = [[0] * (w + 1) for _ in range(n + 1)]
for i in range(n):
    for j in range(w + 1):
        if j - ws[i] >= 0:
            dp[i + 1][j] = max(dp[i + 1][j], dp[i][j - ws[i]] + vs[i])
        
        dp[i + 1][j] =  max(dp[i + 1][j], dp[i][j])

print(dp[n][w])
        

Measured memory_bytes: 120684
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;


const ll mod = 1e9+7;
long double pi = 3.141592653589793238;
ll mulmod(ll x,ll y)
{
  return (x%mod*y%mod)%mod;
}


ll addmod(ll x,ll y)
{
  return (x%mod+y%mod)%mod;
}
void testcases()
{
  ll n;cin >> n;
  map<int,int>MP;
  ll v;
  for(int i=1;i<=n-1;i++)
  {  cin >> v;
   MP[v]++;
  }
  for(int i=1;i<=n;i++)
    cout << MP[i] << endl;
}



int main()
{
    ll t;
     t = 1;
    while(t--)
      testcases();
}

Measured memory_bytes: 13012
using System;
using System.Collections;
using System.Collections.Generic;

namespace ABC127 {
  class ProblemB {
    static void Main(string[] args) {
      int[] input = Input.nums;
      int r = input[0], d = input[1], x = input[2];

      for (int i = 0; i < 10; i++) {
        x = foo(r, d, x); 
        System.Console.WriteLine(x);
      }

    }
    static int foo(int r, int d, int a) {
      return r * a - d;
    }
  }
  public class Input {
    public static string str => System.Console.ReadLine();
    public static string[] strs => str.Split(' ');
    public static char[] charArr => str.ToCharArray();
    public static int num => int.Parse(str);
    public static int[] nums => Array.ConvertAll(strs, int.Parse);
    public static long numL => long.Parse(str);
    public static long[] numLs => Array.ConvertAll(strs, long.Parse);
  }
}

Measured memory_bytes: 11092
#include <iostream>
#include <vector>
#include <cmath>
#include <typeinfo>
#include <set>
#include <bitset>
#include <map>
#include <numeric>
#include <algorithm>
using namespace std;
typedef long long ll;

int main(){
    int n;
    cin >> n;
    vector<int> l(n);
    for(int i=0; i<n; i++){
        cin >> l[i];
    }
    sort(l.begin(), l.end());
    int ans  = 0;
    for(int i = 0; i<n-1; i++){
        for(int j=i+1; j<n; j++){
            auto it1 = lower_bound(l.begin(), l.end(), l[j]);
            auto it2 = lower_bound(l.begin(), l.end(), l[i]+l[j]);
            while(it1-l.begin() <= j){
                it1++;
            }
            ans += it2-it1;
            //cout << "i=" << l[i] << " j=" << l[j] << " it1=" << it1-l.begin() << " it2=" << it2- l.begin() << endl;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <string>
#include <map>
#include <algorithm>
#include <iomanip>
using namespace std;
 
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = (int)(n-1); i >= 0; i--)
#define loop(i, l, r) for(int i = l; i < r; i++)
#define rloop(i, l, r) for(int i = l; i >= 0; i--)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vec_i;

const int dx[4] = {0, 0, 1, -1};
const int dy[4] = {1, -1, 0, 0};
const int INF = 1e9;
const int MOD = 1e9+7;

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

	vector<double> v(n);
	rep(i,n) cin>>v[i];

	vector<double> dp(n+1, 0.0);
	dp[0] = 1 - v[0];
	dp[1] = v[0];
	loop(i,1,n){
		rrep(j, n){
			dp[j+1] = dp[j]*v[i] + dp[j+1]*(1-v[i]);
		}
		dp[0] = dp[0] * (1-v[i]);
	}

	double ans = 0;
	loop(i,(n+1)/2,n+1) ans+=dp[i];
	cout << fixed << setprecision(12) << ans << endl;
}

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

#define ll long long

using namespace std;


int main(){
    int h,sum=0;
    cin>>h;
    int n;
    cin>>n;
    int a[n];
    for(int i=0; i<n; i++){
        cin>>a[i];
        sum=sum+a[i];
    }
    if(sum>=h){
        cout<<"Yes"<<endl;
    }   
    else{
        cout<<"No"<<endl;
    }
}



Measured memory_bytes: 640
function main()
    MOD = 1000000007
    s = chomp(readline())
    n = length(s)
    ans = 0
    a,b,c,z = zeros(Int, (n+1,)),zeros(Int, (n+1,)),zeros(Int, (n+1,)),zeros(Int, (n+1,))
    t = zeros(Int, (n+1,))
    t[1] = 1
    for i in 2:n+1
        t[i] = t[i-1]*3%MOD
    end
    for i in 1:n
        a[i+1], b[i+1], c[i+1], z[i+1] = a[i], b[i], c[i], z[i]
        if s[i] == 'A'
            a[i+1] += 1
        elseif s[i] == 'B'
            b[i+1] += 1
        elseif s[i] == 'C'
            c[i+1] += 1
        else
            z[i+1] += 1
        end
    end
    for i in 1:n
        if s[i] == 'B'
            ans = (ans + a[i]*(c[n+1]-c[i+1])*t[z[n+1]+1])%MOD
            ans = (ans + (z[i]*(c[n+1]-c[i+1])+a[i]*(z[n+1]-z[i+1]))*t[max(1,z[n+1])])%MOD
            ans = (ans + z[i]*(z[n+1]-z[i+1])*t[max(1,z[n+1]-1)])%MOD
        elseif s[i] == '?'
            ans = (ans + a[i]*(c[n+1]-c[i+1])*t[max(1,z[n+1])])%MOD
            ans = (ans + (z[i]*(c[n+1]-c[i+1])+a[i]*(z[n+1]-z[i+1]))*t[max(1,z[n+1]-1)])%MOD
            ans = (ans + z[i]*(z[n+1]-z[i+1])*t[max(1,z[n+1]-2)])%MOD
        end
    end
    print("$ans\n")
end

main()


Measured memory_bytes: 156264
#include <iostream>
#include <vector>
using namespace std;
using Graph = vector<vector<int>>;

// 深さ優先探索
vector<bool> seen;
void dfs(const Graph &G, int v) {
    seen[v] = true;
    for (auto next_v : G[v]) { 
        if (seen[next_v]) continue;
        dfs(G, next_v); 
    }
}

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

    Graph G(N);
    for (int i = 0; i < M; ++i) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    int count = 0;
    seen.assign(N, false);
    for (int v = 0; v < N; ++v) {
        if (seen[v]) continue; 
        dfs(G, v); 
        ++count;
    }
    cout << count-1 << endl;
}


Measured memory_bytes: 9592
a, b, c, d =map (int, input().split(' ')) 


s=0
e=0

if a > d or b < c:
    print(0)
    exit()

if a <= c:
    s=c
else:
    s=a

if b <= d:
    e=b
else:
    e=d

print(e-s)

Measured memory_bytes: 3060
# coding: utf-8

def solve(a, b, pressed):
    a += pressed
    d = a % b
    if d == 0:
        return pressed
    else:
        return pressed + (b - d)

N = int(input())
total = 0
A = [None] * N
B = [None] * N
for i in range(N):
    A[i], B[i] = map(int, input().split())
for i in range(N):
    total = solve(A[-i-1], B[-i-1], total)
print(total)


Measured memory_bytes: 10996
#include <iostream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int main(){

  stack <int> sa;
  string m;
  int cnt=0,result=0,high=0,tmp=0,h[20000],i;
  vector <int> amo;

  cin>>m;
  for(i=m.size()-1;i!=-1;i--){
    if(m[i]=='\\') tmp++;
    if(m[i]=='/') tmp--;
    high=max(high,tmp);
    h[i]=high;
  }

  for(i=0;i<m.size();i++){

    if(m[i]=='\\'){
      sa.push(i);
    } else if(m[i]=='/' && !sa.empty()) {
      cnt+=i-sa.top();
      sa.pop();
      if(sa.empty()){
        amo.push_back(cnt);
        result+=cnt;
        cnt=0;
      }
    }
    if(i<m.size()-1) if(h[i+1]-h[i]!=0) sa.pop();
  }
  /* if(cnt!=0){                                                                                                                                                                               
    amo.push_back(cnt);                                                                                                                                                                        
    result+=cnt;                                                                                                                                                                               
    } */
  if(amo.empty()) cout<<"0"<<endl<<"0"<<endl;
  else{
    cout<<result<<endl<<amo.size()<<" ";
    for(i=0;i<amo.size()-1;i++) cout<<amo[i]<<" ";
    cout<<amo[amo.size()-1]<<endl;
  }
  return 0;

}

Measured memory_bytes: 3288
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 num = int.Parse(Console.ReadLine());
            var nn = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
            Console.WriteLine(nn.Distinct().Count() == num ? "YES" : "NO");
        }
    }
}


Measured memory_bytes: 40756
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int n, t, a[100005] = {}, m = 0, x = 0, y = 0;
    cin >> n >> t;
    for (int i = 1; i <= n; i++) cin >> a[i];
    m = a[1];
    for (int i = 2; i <= n; i++) {
        if (a[i] - m > x) x = a[i] - m, y = 1;
        else if (a[i] - m == x) y++;
        m = min(m, a[i]);
    }
    cout << y;
}


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

struct UnionFind {
    vector<int> par;
    vector<int> sz;

    UnionFind(int n=0){ if(n>0) initialize(n); }
    void initialize(int n){
        par.resize(n);
        sz.assign(n, 1);
        for(int i=0; i<n; i++){
            par[i] = i;
        }
    }

    int find(int x){
        if(par[x] == x){
            return x;
        }else{
            return par[x] = find(par[x]);
        }
    }

    bool unite(int x, int y){
        x = find(x), y = find(y);
        if(x == y) return false;
        if(sz[x] > sz[y]) swap(x, y);
        par[x] = y;
        sz[y] += sz[x];
        return true;
    }

    bool same(int x, int y){ return find(x) == find(y); }
    int size(int x){ return sz[find(x)]; }
};

int main(){
    int N, M;
    cin >> N >> M;
    vector<pair<int, int>> AB(N);
    vector<int> A(N), B(N);
    for(int i=0; i<N; i++){
        int a, b;
        cin >> a >> b;
        AB[i] = {a, b};
    }
    sort(AB.begin(), AB.end());
    for(int i=0; i<N; i++){
        A[i] = AB[i].first;
        B[i] = AB[i].second;
    }

    UnionFind uf(N+1);
    vector<pair<int, int>> edges[100001];
    vector<int> deg(N+1);
    for(int i=0; i<M; i++){
        int l, r;
        cin >> l >> r;
        l = lower_bound(A.begin(), A.end(), l) - A.begin();
        r = upper_bound(A.begin(), A.end(), r) - A.begin();
        if(uf.unite(l, r)){
            edges[l].emplace_back(r, i);
            edges[r].emplace_back(l, i);
            deg[l]++;
            deg[r]++;
        }
    }

    map<int, vector<int>> mp;
    for(int i=0; i<=N; i++) mp[uf.find(i)].push_back(i);
    vector<int> R(N+1, -1);
    for(auto& p : mp){
        auto& v = p.second;
        int sz = v.size();
        for(int i=0; i<sz-1; i++) R[v[i]] = v[i+1];
    }

    vector<int> imos(N+1), use(N+1);
    for(int i=0; i<N; i++){
        B[i] ^= imos[i];
        if(B[i]){
            if(R[i] == -1){
                cout << -1 << endl;
                return 0;
            }
            use[i] ^= 1;
            use[R[i]] ^= 1;
            imos[i] ^= 1;
            imos[R[i]] ^= 1;
            B[i] = 0;
        }
        imos[i+1] ^= imos[i];
    }

    vector<int> ans;
    queue<int> que;
    bitset<100001> visited;
    for(int i=0; i<N; i++) if(deg[i] == 1) que.push(i);
    while(que.size()){
        int i = que.front(); que.pop();
        visited[i] = 1;
        for(auto& e : edges[i]) if(!visited[e.first]){
            int j = e.first, idx = e.second;
            deg[j]--;
            if(use[i]){
                use[i] ^= 1;
                use[j] ^= 1;
                ans.push_back(idx);
            }
            if(deg[j] == 1) que.push(j);
        }
    }
    sort(ans.begin(), ans.end());
    int sz = ans.size();
    cout << sz << endl;
    for(int i=0; i<sz; i++) cout << ans[i]+1 << " \n"[i==sz-1];
    return 0;
}


Measured memory_bytes: 12540
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ll long long
using namespace std;

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

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

int main(){
  ll n,m;
  cin >> n >> m;
  ll a[n];
  REP(i,n) cin >> a[i];
  ll ans = 0;
  
  REP(i,n) a[i] = a[i]/2;
  ll lcm_num = a[0];
  REP(i,n-1){
    lcm_num = lcm(lcm_num, a[i+1]);
    if(lcm_num > m) break;
  }
  ans = floor( (m-lcm_num) / (lcm_num*2) ) + 1;
  if(lcm_num > m) ans = 0;
  REP(i,n) if((lcm_num/a[i]) % 2 == 0) ans = 0;
  cout << ans;
  return 0;
}

Measured memory_bytes: 1024
'use strict'

function main(input) {
  input = input.split('\n')
  const a = input[0]
    .split('')
    .sort()
    .join('')
  const b = input[1]
    .split('')
    .sort()
    .reverse()
    .join('')
  if (a === b) {
    console.log('No')
    return
  }
  const dic = [a, b].sort()

  if (a === dic[0]) console.log('Yes')
  else console.log('No')
}
main(
  require('fs')
    .readFileSync('/dev/stdin', 'utf8')
    .trim()
)


Measured memory_bytes: 7500
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int,int>;
#define rep(i,n) for(int i=0; i<n; i++)
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてから使う
#define INF 2147483647
#define LLINF 9223372036854775807LL

int main() {
  int a,b,c;
  cin>>a>>b>>c;
  if (a+b>=c) cout << "Yes" << endl;
  else cout << "No" << endl;
}



Measured memory_bytes: 3576
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

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

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

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

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

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

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

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

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

void solve(long long N, long long D, std::vector <std::vector<long long> > X) {
  long long ans=0;
  REP(i, N-1){
    for(int j=i+1; j<N; j++){
      long long sum=0;
      REP(k, D){
        sum+=(X[i][k] - X[j][k])*(X[i][k] - X[j][k]);
      }
      double res = sqrt(sum);
      if(ceil(res)==floor(res))ans++;
    }
  }
  cout << ans<<endl;
}

int main() {
  long long N;
  scanf("%lld", &N);
  long long D;
  scanf("%lld", &D);
  std::vector<std::vector<long long> > X(N, std::vector<long long>(D));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < D; j++) {
      scanf("%lld", &X[i][j]);
    }
  }
  solve(N, D, std::move(X));
  return 0;
}


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

int main(){

    int A, B;
    string S;
    cin >> A >> B >> S;

    if (S.at(A) != '-'){
        cout << "No" << endl;
        return 0;
    }
    for (int i=0; i<S.size(); i++){
        if (S.at(i) == '-'){
            if (i != A){
                cout << "No" << endl;
                return 0;
            }
        }
    }

    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long int
#define fi first
#define se second
#define pub push_back
#define pi pair<int,int>
#define all(v) (v).begin(), (v).end()
#define rep(i, l, r) for(int i=(int)(l);i<(int)(r);i++)
#define repd(i, l, r) for (int i=(int)(l);i>=(int)(r);i--)
#define clrg(i, l, r) for(int i=(int)(l);i<(int)(r);i++)vis[i]=0,v[i].clear();
int power(int x, unsigned int y){int res = 1;while (y > 0){ if (y & 1){res = res*x;} y = y>>1;x = x*x;}return res;}
int powermod(int x, unsigned int y, int p){int res = 1;x = x % p;while (y > 0){if (y & 1){res = (res*x) % p;}y = y>>1; x = (x*x) % p;}return res;}
#define print2d(mat,n,m){for(int i=0;i<(int)(n);i++){for(int j=0;j<(m);j++){cout<<mat[i][j]<<" ";}cout<< endl;}}
#define clr(a,x) memset(a,x,sizeof(a))
#define rr(v) for(auto &val:v)
#define print(v) for (const auto itr : v){cout<<itr<<' ';}cout<<"\n";
#define ln length()
#define sz size()
#define mod 1000000007
#define elif else if
int32_t main(){
   string s,t;
   cin>>s>>t;
   int c=0;
   rep(i,0,s.ln){
	   if(s[i]!=t[i])c++;
   }
   cout<<c<<"\n";
   return 0;
}

Measured memory_bytes: 3916
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <set>

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,j) FOR(i,0,j)
#define mp std::make_pair

typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int,int> P;
typedef std::pair<int,P> State;

const int INF = 1001001001;

// S N E W(南北東西)
const int dx[8] = {0, 0, 1, -1, 1, 1, -1, -1}, dy[8] = {1, -1, 0, 0, 1, -1, 1, -1};

std::vector<std::string> ss = {
    "***",
    "**+",
    "**-",
    "*++",
    "*+-",
    "*--",
    "+++",
    "++-",
    "+--",
    "---"
};

bool can(const std::string &s){
    std::stack<int> stack;
    for(auto c : s){
        if(std::isdigit(c)){
            stack.push(c - '0');
        }else{
            if(stack.size() < 2){return false;}
            int a, b;
            b = stack.top(); stack.pop();
            a = stack.top(); stack.pop();
            
            if(c == '+'){
                stack.push(a + b);
            }else if(c == '-'){
                stack.push(a - b);
            }else if(c == '*'){
                stack.push(a * b);
            }
        }
    }

    if(stack.size() > 1){return false;}
    return stack.top() == 10;
}

std::string toInfix(const std::string& s){
    std::stack<std::string> stack;
    
    for(auto c : s){
        if(std::isdigit(c)){
            stack.push({c});
        }else{
            std::string a, b;
            b = stack.top(); stack.pop();
            a = stack.top(); stack.pop();

            stack.push('(' + a + ' ' + c + ' ' + b + ')');
        }
    }

    return stack.top();
}

std::string search(char A, char B, char C, char D){
    REP(i, 10){
        std::string s = ss[i] + A + B + C + D;
        std::sort(s.begin(), s.end());

        REP(j, 5040){
            if(can(s)){return toInfix(s);}
            std::next_permutation(s.begin(), s.end());
        }
    }
    return "0";
}

int main(){
    char A, B, C, D;
    while(std::cin >> A >> B >> C >> D, A != '0'){
        std::cout << search(A, B, C, D) << std::endl;
    }
}

Measured memory_bytes: 1196
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<iostream>
#include<vector>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<string>
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define ll long long 
using namespace std;
int main(){
  ll n,k;
  cin >>n>>k;
  ll b=1;
  rep(i,9){
    b=b*10;
  }
  ll ans=0;
  for(int i=k;i<n+2;i++){
    ans=ans+i*(n-i+1)+1;
    ans=ans%(b+7);
  }
  cout <<ans<<endl;
}
 

Measured memory_bytes: 3628
#include <stdio.h>
#include <iostream>
using namespace std;

#define int long long

signed main()
{
	int ret;
	long long N;
	int len;

	ret = scanf("%lld", &N);

	long long b = N / 1000000000;
	long long a = N % 1000000000;

	if (b == 1000000000) {
		int X1 = 0;
		int Y1 = 0;
		long long X2 = 0;
		long long Y2 = 1000000000;
		long long X3 = 1000000000;
		long long Y3 = 0;
		printf("%lld %lld %lld %lld %lld %lld", X1, Y1, X2, Y2, X3, Y3);
	}
	else if (b > 0) {
		int X1 = 0;
		int Y1 = 0;
		long long X2 = 1000000000 - a;
		long long Y2 = b + 1;
		long long X3 = 1000000000;
		long long Y3 = 1;
		printf("%lld %lld %lld %lld %lld %lld", X1, Y1, X2, Y2, X3, Y3);
	}
	else {
		int X1 = 0;
		int Y1 = 0;
		long long X2 = 0;
		long long Y2 = 1;
		long long X3 = a;
		long long Y3 = 0;
		printf("%lld %lld %lld %lld %lld %lld", X1, Y1, X2, Y2, X3, Y3);


	}

	return 0;
}


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

#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define INF 999999999
#define MOD 1000000007

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int iy[]={0, 0, 1, -1};
int ix[]={1, -1, 0, 0};

int n, m;

int main(){
	cin >> n >> m;
	if(n>=m*2-1) cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main()
{
	ios::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	vector<ll> a(n);
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		a[i] %= m;
	}

	vector<ll> aPrefSum(n);
	aPrefSum[0] = a[0];
	for (int i = 1; i < n; i++)
		aPrefSum[i] = (aPrefSum[i - 1] + a[i]) % m;
	map<ll, vector<int>> modToPos;
	modToPos[0].push_back(-1);
	for (int i = 0; i < n; i++)
		modToPos[aPrefSum[i]].push_back(i);

	ll result = 0;
	for (int i = 0; i < n; i++)
	{
		if (modToPos.count(aPrefSum[i]) == 0)
			continue;
		const vector<int>& v = modToPos[aPrefSum[i]];
		auto it = lower_bound(v.begin(), v.end(), i);
		result += (int)(it - v.begin());
	}
	cout << result << endl;
}

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

int main() {
  int A,B,a,b,c,d,e,f,g,h,i;
  cin>>A;
  a=A%10;
  b=(A%100-a)/10;
  c=(A%1000-10*b-a)/100;
  d=(A%10000-100*c-10*b-a)/1000;
  e=(A%100000-1000*d-100*c-10*b-a)/10000;
  f=(A%1000000-10000*e-1000*d-100*c-10*b-a)/100000;
  g=(A%10000000-100000*f-10000*e-1000*d-100*c-10*b-a)/1000000;
  h=(A%100000000-1000000*g-100000*f-10000*e-1000*d-100*c-10*b-a)/1000000;
  i=(A%1000000000-10000000*h-1000000*g-100000*f-10000*e-1000*d-100*c-10*b-a)/10000000;
  B=a+b+c+d+e+f+g+h+i;
  if(A%B==0)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
  }


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LL long long
#define MOD 1000000007
using namespace std;
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int N;
  cin >> N;
  string str;
  cin >> str;
  int red_cnt = 0;
  for (int i = 0; i < str.size(); ++i)
    if (str[i] == 'R') red_cnt++;
  int cnt_R = 0, cnt_W = 0;
  for (int i = 0; i < red_cnt; ++i)
    {
      if (str[i] == 'R') cnt_R++;
      else cnt_W++;
    }
  cout << cnt_W << endl;
  return 0;
}


Measured memory_bytes: 3756
#include<cstdio>
#include<iostream>
#include<cstring>
#define RG register
using namespace std;
const int N=2e5+10;
int n,x,ans[N],vis[N];
template<typename I> inline void read(I &ot){
	I ch=getchar(), x=0, f=1;
	while(ch<'0' || ch>'9'){if(ch=='-') f=-1; ch=getchar();	}
	while(ch>='0' && ch<='9'){x=x*10+ch-'0'; ch=getchar();	}
	ot=x*f;}
template<typename I, typename... U> inline void read(I &x,U&... y){read(x); read(y...);}
int main()
{ 
//	freopen("Median Pyramid Easy.in","r",stdin);
	read(n,x); n=2*n-1;
	if(x==1 || x==n) return printf("No\n"), 0;
	ans[n/2]=x; vis[x]=1;
	if(x==n-1) 
	{
		ans[n/2+1]=n; ans[n/2+2]=x-1; ans[n/2-1]=x-2;
		vis[n]=vis[x-1]=vis[x-2]=1;
	}
	else {
		ans[n/2+1]=x-1; ans[n/2+2]=x+1; ans[n/2-1]=x+2;
		vis[x-1]=vis[x+1]=vis[x+2]=1;
	}
	printf("Yes\n");
	for(RG int i=1,cnt=1;i<=n;i++)
	{
		if(ans[i]) 
		{
			printf("%d\n",ans[i]);
			continue;
		}
		while(vis[cnt]) cnt++;
		printf("%d\n",cnt++);
	}
	return 0;
}

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

using namespace std;
using ll = long long;

int main() {
    int n,k;
    cin>>n>>k;
    vector<ll> t(n);
    for(int i = 0;i < n;++i) {
        cin>>t[i];
    }
    int cnt=1;
    vector<ll> a;
    ll ans=n;
    for(int i = 0;i < n-1;++i) {
        if(t[i]+1<t[i+1]) {
            ++cnt;
            a.emplace_back(t[i+1]-t[i]-1);
        }
    }

    //cerr<<cnt<<endl;

    sort(a.begin(),a.end());
    for(int i = 0;i < cnt-k;++i) {
        ans+=a[i];
    }

    cout<<ans<<endl;

    return 0;
}



Measured memory_bytes: 4716
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i < (int)(n); i++)
#define Sort(a) sort(a.begin(), a.end())
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;} return false;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;} return false;}

int main(){
    ll h, w;
    cin >> h >> w;
    char s[100][100];
    rep(i, h){
        rep(j, w){
            cin >> s[i][j];
        }
    }
    string ans = "Yes";
    rep(i, h){
        rep(j, w){
            bool flag = false;
            if(s[i][j] == '.') continue;
            if(s[i+1][j] == '#') flag = true;
            if(s[i][j+1] == '#') flag = true;
            if(i-1 >= 0)
            if(s[i-1][j] == '#') flag = true;
            if(j-1 >= 0)
            if(s[i][j-1] == '#') flag = true;
            if(!flag) ans = "No";
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256