akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<vector>
#include<map>
#include<string>
#include<sstream>
#include<cmath>
#include<climits>
#include<algorithm>
#include<bitset>
#include<set>
#include<stack>
#include<queue>
#include<iomanip>
#include<memory.h>
#include<complex>
using namespace std;  
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef tuple<int,int> tii;
#define rep(i,n) for(ll i=0;i<(n);i++)  
#define pb push_back
#define mt make_tuple
#define ALL(a) (a).begin(),(a).end()
#define FST first
#define SEC second  
const int INF = (INT_MAX/2);
const ll LLINF = (LLONG_MAX/2);
const double eps = 1e-8;
const double PI = M_PI;  
#define DEB cerr<<"!"<<endl
#define SHOW(a,b) cerr<<(a)<<" "<<(b)<<endl
#define SHOWARRAY(ar,i,j) REP(a,i)REP(b,j)cerr<<ar[a][b]<<((b==j-1)?((a==i-1)?("\n\n"):("\n")):(" "))
#define DIV int(1e9+7)
inline ll pow(ll x,ll n,ll m){ll r=1;while(n>0){if((n&1)==1)r=r*x%m;x=x*x%m;n>>=1;}return r%m;}
inline ll lcm(ll d1, ll d2){return d1 / __gcd(d1, d2) * d2;}
 
/* Coding Space*/
int d[200][200];
int main(){
  fill_n(d[0],200*200,INF);
  int n,m,r; cin >> n >> m >> r;
  vi route(r);
  rep(i,r) cin >> route[i],route[i]--;
  sort(ALL(route));
  rep(i,n)d[i][i] = 0;
  rep(i,m){
    int a,b,c; cin >> a >> b >> c;a--,b--;
    d[a][b] = c;
    d[b][a] = c;
  }
  rep(k,n)rep(i,n)rep(j,n)
    d[i][j] = min(d[i][j],d[i][k] + d[k][j]);
  ll ans = LLINF;
  do{
    ll t_ans = 0;
    rep(i,r-1)
      t_ans += d[route[i]][route[i+1]];
    //cerr<<t_ans<<endl;
    ans = min(ans,t_ans);
  }while(next_permutation(ALL(route)));
  cout << ans << endl;
}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int num = scan.nextInt();
		int yen = scan.nextInt();
		scan.close();
		
		int[] array = new int[3];
		array[0] = yen / 10000;
		array[1] = yen % 10000 / 5000;
		array[2] = yen % 10000 % 5000 / 1000;

		while (true) {
			int dif = num - (array[0] + array[1] + array[2]);
			if (dif == 0) {
				System.out.println(array[0] + " " + array[1] + " " + array[2]);
				break;
			} else if (dif < 0 || array[0] < 0) {
				System.out.println("-1 -1 -1");
				break;
			}

			if (dif % 4 == 0 && dif / 4 <= array[1]) {
				array[1] -= dif / 4;
				array[2] += dif / 4 * 5;
			} else {
				array[0]--;
				array[1] += 2;
			}
		}
	}
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std ;
typedef long long  ll;
typedef long double ld;
const ll inf = 1e18 + 10;
const ll N = 1e5 + 10;
ll n , k , x , y ;
ll dp[110][N];
ld f;
vector<pair<ll , ll>> v;
ll check(ll ind , ll x)
{
    ll cost = 0;
    if(dp[ind][x] != -1)   return dp[ind][x];
    if(ind == v.size()) return 0;
    if(v[ind].second <= x)
    {
        cost = max(v[ind].first + check(ind + 1 , x - v[ind].second) , check(ind + 1 , x));
    }else
    {
        cost = check(ind + 1 , x);
    }
    dp[ind][x] = cost;
    return cost;
    
}
void solve()
{
    cin >> n >> k;
    for(ll i = 1 ; i <= n ; i ++)
    {
        cin >> x >> y;
        v.push_back(make_pair(y , x));
    }
    memset(dp , -1 , sizeof dp);
    cout << check(0 , k);
}
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    ll t;
    t = 1;
    //cin >> t ;
    while(t --)
        solve();
    return 0;
}

Measured memory_bytes: 89596
#include<stdio.h>

#define max 101

int main(){
  int i,j,num,count = 0;
  int array[max][max],color[max],data[max],pi[max],min,kai;

  scanf("%d",&num);

  for(i = 0;i < num;i++){
    for(j = 0;j < num;j++){
      scanf("%d",&array[i][j]);
    }
  }
  
  for(i = 0;i < num;i++){
    color[i] = 0;
    pi[i] = -1;
    data[i] = 2001;
  }
  data[0] = 0;

  while(1){
    min = 2001;

    for(i = 0;i < num;i++){
      if(color[i] != 2 && data[i] < min){
        min = data[i];
        kai = i;
      }
    }
    if(min == 2001){
      break;
    }
    color[kai] = 2;

    for(i = 0;i < num;i++){
      if(array[kai][i] != -1 && color[i] != 2 && array[kai][i] < data[i]){
        pi[i] = kai;
        data[i] = array[kai][i];
        color[i] = 1;
      }
    }
  }

  for(i = 0;i < num;i++){
    if(pi[i] != -1){
      count += array[i][pi[i]];
    }
  }
  printf("%d\n",count);
  return 0;
}



Measured memory_bytes: 2032
#include <stdio.h>

#define N 20
#define true 1
#define false 0

int solve(int,int);

int n,A[N];

int main(){

  int m,i,j,p;

  scanf("%d",&n);

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

  scanf("%d",&p);
  
  for(i=0;i<p;i++){
    scanf("%d",&m);
    if( solve(0,m) == true) printf("yes\n");
    else printf("no\n");
  }
  return 0;
}


int solve(int i,int m){
  int res;

    if(m == 0) return true;

    if(i >= n) return false;

    res = solve(i+1,m) || solve(i+1,m-A[i]);

    return res;

  }


Measured memory_bytes: 2144
using System;

class Program
{
  static void Main()
  {
    int n = int.Parse(Console.ReadLine());
    if (n <= 0) return;

    int[] a = new int[n];

    string[] s = Console.ReadLine().Split(' ');
    for (int i = 0; i < n; i++) a[i] = int.Parse(s[i]);


    Console.Write(a[n - 1]);

    for (int i = n - 2; i >= 0; i--) Console.Write(" {0}", a[i]);

    Console.WriteLine();
  }
}

Measured memory_bytes: 9176
N, M = list(map(int, input().split()))
S = [tuple(map(int, input().split())) for _ in range(N)]
P = [tuple(map(int, input().split())) for _ in range(M)]

for sx, sy in S:
    m = 10**9
    for i, (px, py) in enumerate(P):
        d = abs(px-sx)+abs(py-sy)
        if d<m:
            im = i
            m = d
    print(im+1)

Measured memory_bytes: 3064
//                          **********  YATIN KWATRA  ********** 

//AC bakshi Rabha

#include <iostream>
#define ll                      long long 
#define ull                     unsigned long long 
#define FIO                     ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl                    "\n"
#define fo(i,a,b)               for(int i = a; i<=b ; i++)
#define rfo(i,a,b)              for(int i = a; i>=b ; i--)
#define vii                      vector<int>
#define vll                     vector<ll>
#define pq                      priority_queue
#define uo                      unordered_map                
#define all(v)                  v.begin(),v.end()
#define mp                      make_pair
#define pb                      push_back
#define pob                     pop_back
#define ff                      first
#define ss                      second
#define pii                     pair<int,int> 
#define pll                     pair<long,long>
#define mll                     map<long,long>
#define mii                     map<int,int>
#define vvii                    vector<vii>
#define mod                     1000000007
// #define node                    Node

using namespace std;

void INPUT() {
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

}


void solve()
{ 
  int n,m;
  cin >> n >> m;

  ll ans = 0;

  if(n>1) ans += (n*(n-1))/2;
  if(m>1) ans += (m*(m-1))/2;

  cout << ans << endl;      
}
int main() {
    
    FIO
   // INPUT();
    
    int t;
    t = 1;
    //cin >> t;
    
    while(t--)
    {
       solve();
    }
    return 0;
}


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

const int mod=1e9+7;
long f[100010], g[100010], a[100010], b[100010];

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

int nCr(int n, int r) { return n<r ? 0 : f[n]*g[n-r]%mod*g[r]%mod; }

int main()
{
    int n; cin>>n;
    int L, R;
    for(int i=0; i<n+1; ++i) {
        cin>>a[i];
        if (b[a[i]]) { L=b[a[i]]; R=i+1; }
        b[a[i]]=i+1;
    }

    f[0]=g[0]=1;
    for(int i=1; i<=n+1; ++i) {
        f[i]=f[i-1]*i%mod;
        g[i]=modpow(f[i], mod-2)%mod;
    }

    for(int k=1; k<=n+1; ++k) {
        cout<<(nCr(n+1, k)-nCr(L+n-R, k-1)+mod)%mod<<'\n';
    }
}

Measured memory_bytes: 4352
def ss(s):
    # 文字ソート
    res = s[0]
    for i in s[1:]:
        flg = False
        for j, e in enumerate(res):
            if e > i:
                res = res[:j] + i + res[j:]
                flg = True
                break

        if not flg:
            res += i
    return res


def poe(n):
    return sum([i - 1 for i in range(2, n + 1)])


def main():
    n = int(input())
    slist = {}
    for i in range(n):
        s = ss(input())
        if s in slist:
            slist[s] += 1
        else:
            slist[s] = 1

    ans = 0
    for k, v in slist.items():
        a = poe(v)
        ans += a
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 17924
#include <bits/stdc++.h>
//#define int long long

using namespace std;
using LL = long long;
using P = pair<int, int>;

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

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e15;
const int MOD = 1e9 + 7;

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

/*************** using variables **************/
int n, x;
/**********************************************/

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

    cin >> n >> x;
    if(x == 1 || x == 2*n-1){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
        vector<int> a(2*n-1);
        REP(i, 2*n-1){
            a[(n+i-1)%(2*n-1)] = (x+i-1)%(2*n-1)+1;
        }

        REP(i, 2*n-1) cout << a[i] << endl;
    }
}


Measured memory_bytes: 2304
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string>
#include <queue>
#include <map>
using namespace std;
map<char, int> mp;
map<int, string> mpp;
int n, ans;
char a, b, c;
int main() {
	cin >> n;
	for (int i = 1; i <= n; ++i) {
		cin >> a;
		mp[a] = 1;
	}
	mpp[3] = "Three";
	mpp[4] = "Four";
	ans += mp['G'] + mp['W'] + mp['P'] + mp['Y'];
	cout << mpp[ans];
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LL long long
using namespace std;
inline int read(){
    int x=0; bool f=1; char c=getchar();
    for(;!isdigit(c);c=getchar()) if(c=='-') f=0;
    for(; isdigit(c);c=getchar()) x=(x<<3)+(x<<1)+(c^'0');
    if(f) return x;
    return -x;
}
const int N = 500;
LL a[N+3][N+3],s[2][N+3][N+3],f[N+3][N+3];
int n;
void update(LL &x,LL y) {x = x<y?x:y;}
LL sum(int t,int lx,int rx,int ly,int ry){
    return s[t][rx][ry]-s[t][lx-1][ry]-s[t][rx][ly-1]+s[t][lx-1][ly-1];
}
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        for(int j=1; j<=n; j++){
            if(j==i) continue;
            scanf("%lld",&a[i][j]);
        }
    }
    for(int i=1; i<=n; i++){
        for(int j=1; j<=n; j++){
            if(i<j) s[0][i][j]=a[i][j];
            s[0][i][j]+=s[0][i][j-1];
        }
        for(int j=1;j<=n;j++)s[0][i][j]+=s[0][i-1][j];
    }
    for(int i=1; i<=n; i++){
        for(int j=1; j<=n; j++){
            if(i>j)s[1][i][j]=a[i][j];
            s[1][i][j]+=s[1][i][j-1];
        }
        for(int j=1;j<=n;j++)s[1][i][j]+=s[1][i-1][j];
    }
    memset(f,42,sizeof(f)); 
    f[0][0]=0ll;
    for(int i=0;i<=n; i++)
        for(int j=0;j<max(i,1);j++)
            for(int k=i+1;k<=n;k++){
                LL tmp=f[i][j]+sum(1,k+1,n,j+1,i)+sum(0,i+1,k,i+1,k);
                update(f[k][i],tmp);
            }
    LL ans=f[n][1];
    for(int i=1;i<=n;i++)update(ans,f[n][i]);
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 8192
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define int long long
#define double long double
#define all(a) a.begin(), a.end()
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; }
using namespace std;

int mod;
struct mint{ //modint
    int x;
    mint(int x = 0): x((x % mod + mod) % mod) {}
    friend istream& operator >> (istream &s, mint& m){ return s >> m.x; }
    friend ostream& operator << (ostream &s, mint m){ return s << m.x; }
    inline mint& operator += (mint a){ if((x += a.x) >= mod)x -= mod; return *this; }
    inline mint& operator -= (mint a){ if((x += mod - a.x) >= mod)x -= mod; return *this; }
    inline mint& operator *= (mint a){ (x *= a.x) %= mod; return *this; }
    inline mint& operator /= (mint a){ return (*this) *= a.inv(); }
    inline mint operator + (mint a){ mint res(*this); return res += a; }
    inline mint operator - (mint a){ mint res(*this); return res -= a; }
    inline mint operator * (mint a){ mint res(*this); return res *= a; }
    inline mint operator / (mint a){ mint res(*this); return res /= a; }
    inline bool operator == (mint a){ return x == a.x; }
    inline bool operator != (mint a){ return x != a.x; }
    inline bool operator < (mint a){ return x < a.x; }
    inline bool operator > (mint a){ return x > a.x; }
    inline bool operator <= (mint a){ return x <= a.x; }
    inline bool operator >= (mint a){ return x >= a.x; }
    inline void takemod(){ x = ((x % mod) + mod) % mod; }
    mint inv(){ return pow(mod - 2); }
    mint pow(int p){
        mint res(1), tmp(x);
        for(; p; p >>= 1){ if(p & 1)res *= tmp; tmp *= tmp; }
        return res;
    }
};

struct mfact{ //modfact
    vector<mint> fact, ifact;
    mfact(int size = 200010) : fact(size + 1), ifact(size + 1) {
        fact[0] = mint(1);
        for(int i = 1; i <= size; i++)fact[i] = fact[i - 1] * mint(i);
        ifact[size] = fact[size].inv();
        for(int i = size; i > 0; i--)ifact[i - 1] = ifact[i] * mint(i);
    }
    inline mint operator [] (int i){ return fact[i]; }
    inline mint nPr(int n, int r){ return fact[n] * ifact[r]; }
    inline mint nCr(int n, int r){ return fact[n] * ifact[n - r] * ifact[r]; }
};

//ABC137
signed main(void){

    int P; cin >> P; mod = P;
    vector<mint> ans(P, mint(0));
    mfact fact(P - 1);

    rep(i, P){
        int a; cin >> a;
        if(a == 1){
            // f(x) に (1 - (x - i) ^ (p - 1)) を足す
            ans[0] += 1;
            mint now(1);
            for(int j = P - 1; j >= 0; j--){
                ans[j] -= now * fact.nCr(P - 1, j);
                now *= mint(-i);
            }
        }
    }

    rep(i, P){
        if(i)cout << ' ';
        cout << ans[i];
    }
    cout << endl;
    return 0;



}

Measured memory_bytes: 512
use std::str::FromStr;

fn get_one<T : FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    return s.trim().parse().ok().unwrap();
}

fn get_vec<T : FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    return s.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect();
}

fn get_vec_by_lines<T : FromStr>(n : usize) -> Vec<T> {
    let mut v : Vec<T> = Vec::new();
    for _i in 0..n {
        let x : T = get_one();
        v.push(x);
    }
    return v;
}

fn gcd(mut x : u64, mut y : u64) -> u64 {
    while y != 0 {
        let tmp = y;
        y = x % y;
        x = tmp;
    }
    return x;
}

fn lcm(x : u64, y : u64) -> u64 {
    return (x / gcd(x,y)) * y
}

fn main() {
    let n : usize = get_one();
    let v : Vec<u64> = get_vec_by_lines(n);
    let mut ans = 1;
    for x in v {
        ans = lcm(ans, x);
        //println!("{} {}", ans, x)
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;

map<ll, ll> prime_factorization(ll num)
{
    auto sqrtNum = static_cast<ll>(sqrt(num));
    map<ll, ll> prime_factors;
    for (ll i = 2; i <= sqrtNum;) {
        if (num % i == 0) {
            num /= i;
            prime_factors[i]++;
        } else {
            i++;
        }
    }
    prime_factors[num]++;
    return prime_factors;
}

void main_()
{
    ll N, P;
    cin >> N >> P;

    auto pfs = prime_factorization(P);

    // 結果からN個以上存在する素数を得る
    // 同じ素数で複数のN個のグループをつくれる場合もある
    vector<ll> gcd_primes;
    for (auto&& pf : pfs) {
        gcd_primes.insert(end(gcd_primes), pf.second / N, pf.first);
    }

    auto ans = accumulate(begin(gcd_primes), end(gcd_primes), 1LL,
        [](auto acc, auto p) { return acc * p; });

    cout << ans << endl;
}
int main()
{
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);
    main_();
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <math.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 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;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int PS(int a1, int a2, int a3, int a4) {
  return abs(a1-a3)+abs(a2-a4);
}
int main() {
  int N;
  int M;
  cin >>N>>M;
  vector<int> a(N);
  vector<int> b(N);
  rep(i,N) {
cin >>a.at(i)>>b.at(i);
  }
  
  vector<int> c(M);
  vector<int> d(M);
  rep(i,M) {
cin >>c.at(i)>>d.at(i);
  }
  vector<int> finale(N);
  rep(i,N) {
    vector<pair<int,int>> V(M);
    rep(j,M) {
      V.at(j).first=PS(a.at(i),b.at(i),c.at(j),d.at(j));
      V.at(j).second=j+1;
    }
    sort(all(V));
    finale.at(i)=V.at(0).second;
  }
  
  rep(i,N) {
cout<<finale.at(i)<<endl;
  }

  
  
  
}
    


Measured memory_bytes: 256
#include <iostream>

using namespace std;

long long gcd(long long a, long long b);
long long lcm(long long a, long long b);

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

	cout << lcm(2, n) << endl;

	return 0;
}

long long gcd(long long a, long long b)
{
	if (a < b) {
		long long t = a;
		a = b;
		b = t;
	}

	long long r = a % b;
	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}

	return b;
}

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

Measured memory_bytes: 256
import java.util.Scanner;

class Main{


	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);			//文字の入力
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		
		int ans = 3;
		if(a == b){
			ans--;
		}
		if( b == c){
			ans--;
		}
		if(c == a){
			ans--;
		}
		if( a == b&& b == c){
			ans++;
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 23252
#include<cstdio>
#include <cstring>
#include<cstdlib>
#include <stack>

using namespace std;

int dat[100005],n;


int main(void){

	while(1){
		scanf("%d",&n);
		if(n==0)break;
		for(int i=1;i<=n;i++){
			scanf("%d",&(dat[i]));
		}
		
		stack<int> st;
		st.push(1);
		int topcl=dat[1];
		for(int i=2;i<=n;i++){
			if(i%2==1){
				if(topcl==dat[i]){
					int p=st.top();
					st.pop();
					st.push(p+1);
				}
				else{
					st.push(1);
					topcl=1-topcl;
				}
			}
			else{
				if(topcl==dat[i]){
					int p=st.top();
					st.pop();
					st.push(p+1);
				}
				else{
					int p=st.top();
					st.pop();
					if(!st.empty()){
						int q=st.top();
						st.pop();
						st.push(p+q+1);
					}
					else{
						st.push(p+1);
					}
					topcl=1-topcl;
				}
			}
		}
		
		int ans=0;
		while(!st.empty()){
			if(topcl==0){
				ans+=st.top();
			}
			st.pop();
			topcl=1-topcl;
		}
		
		printf("%d\n",ans);

	}
	return 0;
}

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

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

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
typedef priority_queue<int> HEAP;
typedef priority_queue<int, vector<int>, greater<int> > RHEAP;

const int N = 300010, M = 3 * N;

int n, m;
int h[N], e[M], ne[M], idx;
int dist[N], q[M];

void add(int a, int b)
{
	e[idx] = b, ne[idx] = h[a], h[a] = idx ++ ;
}

int bfs(int st, int ed)
{
	memset(dist, -1, sizeof dist);
	int hh = 0, tt = -1;
	dist[st * 3] = 0;
	q[ ++ tt] = st * 3;
	
	while (hh <= tt)
	{
		int t = q[hh ++ ];
		
		for (int i = h[t]; ~i; i = ne[i])
		{
			int j = e[i];
			if (dist[j] != -1) continue;
			
			dist[j] = dist[t] + 1;
			q[ ++ tt] = j;
		}
	}
	
	if (dist[ed * 3] == -1) return -1;
	else return dist[ed * 3] / 3;
}

int main()
{
	memset(h, -1, sizeof h);
	scanf("%d%d", &n, &m);
	
	for (int i = 0; i < m; i ++ )
	{
		int a, b;
		scanf("%d%d", &a, &b);
		add(3 * a, 3 * b + 1);
		add(3 * a + 1, 3 * b + 2);
		add(3 * a + 2, 3 * b);
	}
	
	int st, ed;
	scanf("%d%d", &st, &ed);
	printf("%d\n", bfs(st, ed));
    return 0;
}

Measured memory_bytes: 9588
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i16 = int16_t;
using i32 = int32_t;
using i64 = int64_t;

constexpr char newl = '\n';
constexpr double eps = 1e-10;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
#define fi first
#define se second
#define debug(x) cout << #x << ": " << x << '\n';
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
template<class T> void Print(vector<T> v) {
  F0R(i, v.size()) {
    cout << v[i] << ' ';
  }
  cout << newl;
}

#if 1


// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N, A, B;
  cin >> N >> A >> B;
  cout << min(A * N, B);

}
#endif


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

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    if(a > b){
        int dump;
        dump = a;
        a = b;
        b = dump;
    }
    if(b > c){
        int dump;
        dump = b;
        b = c;
        c = dump;
    }
    if(a > b){
        int dump;
        dump = a;
        a = b;
        b = dump;
    }
    cout << a << " " << b << " " << c << "\n";
}


Measured memory_bytes: 2992
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
char s[110];

ll k, n, ans;


int main() {
	scanf("%s%lld", s + 1, &k);
	n = strlen(s + 1);
	for(int i = 1 ; s[i] ; ++ i) {
		if(i >= k || s[i] != '1') return printf("%d\n", s[i] - '0'), 0;
	}
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <set>
#include <map>
#include <iostream>
#include <cstring>
#include <cmath>
#include <queue>
#define ull unsigned long long
#define ll long long
#define INF 0x3f3f3f3f
using namespace std;
void close(){
       std::ios::sync_with_stdio(false);
       std::cin.tie(0);
}
ll a[10][10];
ll find(ll x){
	while(x){
		if(x/10==0) return x;
		x/=10;
	}
}
int main(){
	ll n;
	cin>>n;
	for(ll i=1;i<=n;i++){
		a[find(i)][i%10]++;
	}
	ll ans=0;
	for(ll i=1;i<=9;i++){
		for(ll j=1;j<=9;j++){
			ans+=(a[i][j]*a[j][i]);
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <iomanip>
//#include <utility>
//#include <memory>
//#include <functional>
//#include <deque>
//#include <cctype>
//#include <ctime>
//#include <numeric>
//#include <list>
//#include <iomanip>

//#if __cplusplus >= 201103L
//#include <array>
//#include <tuple>
//#include <initializer_list>
//#include <forward_list>
//
//#define cauto const auto&
//#else

//#endif

using namespace std;


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

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()
#define DEBUG
#ifdef DEBUG
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#else
#define dump(x) 
#define debug(x) 
#endif
#define LDcout(x,n) fixed<<setprecision(n)<<x

#define MOD 1000000007LL
#define EPS 1e-8
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)

void mainmain(){
    int a[5];
    while(1){
        cin>>a[0];
        if(a[0]==0) break;
        rep(i,4) cin>>a[i+1];
        vint v(5);
        rep(i,5){
            v[i]=a[i];
        }
        sort(ALL(v));
        if(v[0]==v[4]){
            rep(i,5){
                cout<<3<<endl;
            }
            continue;
        }
        bool f=false;
        rep(i,5){
            if(v[i]==2) f=true;
        }
        if(f&&v[0]==1&&v[4]==3){
            rep(i,5){
                cout<<3<<endl;
            }
            continue;
        }
        int b[]={2,3,1};
        reep(i,1,4){
            bool f=true;
            rep(j,5){
                if(a[j]==i) f=false;
            }
            if(f){
                rep(j,5){
                    if(a[j]==b[i-1]) cout<<1<<endl;
                    else cout<<2<<endl;
                }
                break;
            }
        }
    }
}


signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
      cout<<fixed<<setprecision(20);
    mainmain();
}

Measured memory_bytes: 1208
#include <cstdio>
#include <iostream>
#define P 1000000007
using namespace std;
int n,m;
int main(){
    scanf("%d%d",&n,&m);
    if(n>m)swap(n,m);
    if(n==m){
        long long ans=2;
        for(int i=2;i<=n;++i)ans=ans*i%P*i%P;
        cout<<ans<<endl;
    }
    else if(n+1==m){
        long long ans=1;
        for(int i=2;i<=n;++i)ans=ans*i%P*i%P;
        ans=ans*m%P;
        cout<<ans<<endl;
    }
    else puts("0");
}


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

int main()
{
    int n;
    cin>>n;
    set<string> s;
    for(int i=0; i<n; i++)
    {
        string c;
        cin>>c;
        s.insert(c);
    }
    cout<<s.size()<<endl;
    return 0;
}


Measured memory_bytes: 19176
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++) 

using namespace std;

int main() {
  int n;
  cin>>n;
  vector<tuple<string,int,int>> vec;
  for(int i=1;i<=n;i++){
    string s;
    int a;
    cin>>s>>a;
    a=-a;
    vec.push_back(tie(s,a,i));
  }
  sort(vec.begin(),vec.end());
   rep(i,n){
     string s;
     int a;
     int b;
     tie(s,a,b)=vec[i];
     cout<<b<<endl;
   }
}
                                   

Measured memory_bytes: 3624
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(long long i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,n-1,0)
#define RREPS(i,n) RFOR(i,n,1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true; }return false; }
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true; }return false; }
const int INF = 1e18;

int dep(int n){
    int ret = 0;
    while(n >= 2){
        n /= 2;
        ret++;
    }
    return ret;
}

int func(int n,int j){
    while(j--) n /= 2;
    return n;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    //input
    int n; cin >> n;
    int v[n+1],w[n+1];
    REPS(i,n) cin >> v[i] >> w[i];
    int q; cin >> q;
    int M_L = 0;
    int t[q], l[q];
    REP(i,q){
        cin >> t[i] >> l[i];
        chmax(M_L,l[i]);
    }
    //半分全列挙
    int V = min((1ll << 9)-1, n);
    vector<vector<int>> dp(V+1,vector<int>(M_L+1,0));
    REPS(i,V) REP(j,M_L+1){
        chmax(dp[i][j], dp[i/2][j]);
        if(j - w[i] > -1) chmax(dp[i][j], dp[i/2][j-w[i]] + v[i]);
    }
    int z, o, ans, hoge[9];
    REP(i,q){
        if(t[i] <= V) cout << dp[t[i]][l[i]] << '\n';
        else{
            z = dep(t[i]) - 8;
            o = func(t[i],z);
            ans = 0;
            REP(j,z) hoge[j] = func(t[i],j);
            for(int b = 0; b < (1ll << z); b++){
                int sumw = 0;
                int sumv = 0;
                REP(j,z) if((b >> j) & 1){
                    sumw += w[hoge[j]];
                    sumv += v[hoge[j]];
                }
                if(l[i]-sumw > -1) chmax(ans, dp[o][l[i]-sumw] + sumv);
            }
            cout << ans << '\n';
        }
    }
}


Measured memory_bytes: 411016
#include<bits/stdc++.h>
using namespace std;
char s[1111111];
int n,mx,pre[1111111],suf[1111111];
int f(int x)
{
	int num=0,mn=0;
	for (int i=1;i<=n;i++)
	{
		if (s[i-1]=='?') 
		{
			if (suf[i]+(num+1)*2<=x) num++;
		}
		mn=min(mn,num*2+pre[i]);
	}
	return mn;
}
int main()
{
	scanf("%s",s);
	n=strlen(s);mx=0;
	for (int i=1;i<=n;i++)
	{
		if (s[i-1]=='?' || s[i-1]=='0') pre[i]=pre[i-1]-1;
		else pre[i]=pre[i-1]+1;
		mx=max(mx,pre[i]);
	}
	suf[n+1]=-1e9;
	for (int i=n;i>=1;i--) suf[i]=max(suf[i+1],pre[i]);
	printf("%d\n",min(mx-f(mx),mx+1-f(mx+1)));
	return 0;
}

Measured memory_bytes: 12580
#include <stdio.h>
#include <math.h>

double stddev(int s[],size_t n){
	int i,v;
	double sum=0,sqsum=0;
	for(i=0;i<n;i++){
		v = s[i];
		sum += v;
		sqsum += v*v;
	}
	return sqrt(sqsum/n - (sum/n)*(sum/n));
}

int main(){
	int i,n,s[1000];
	while(1){
		scanf("%d",&n);
		if(!n)break;
		for(i=0;i<n;i++){
			scanf("%d",&s[i]);
		}
		printf("%f\n",stddev(s,n));
	}
	return 0;
}

Measured memory_bytes: 636
#include<iostream>

using namespace std;

int main(){
    int N;
    int A[3][3];

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

    cin >> N;

    int b[N];

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

    for(int k=0;k<N;k++){
        for(int i=0;i<3;i++){
            for(int j=0;j<3;j++){
                if(b[k]==A[i][j]){
                    A[i][j] = 0;
                }
            }
        }
    }

    int frag;
    for(int i=0;i<3;i++){
        frag=0;
        for(int j=0;j<3;j++){
            if(A[i][j]==0){
                frag++;
                if(frag==3){
                    cout << "Yes" << endl;
                    return 0;
                }
            }
        }
    }

    for(int i=0;i<3;i++){
        frag=0;
        for(int j=0;j<3;j++){
            if(A[j][i]==0){
                frag++;
                if(frag==3){
                    cout << "Yes" << endl;
                    return 0;
                }
            }
        }
    }

    frag=0;
    for(int i=0;i<3;i++){
        if(A[i][i]==0){
            frag++;
        }
        if(frag==3){
            cout << "Yes" << endl;
            return 0;
        }
    }

    if(A[0][2]==0 && A[1][1]==0 && A[2][0]==0){
        cout << "Yes" << endl;
        return 0;
    }

    cout << "No" << endl;

    return 0;



}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

class LazySegmentTree
{
 private:
    int n;
    vector<int> node,lazy;
 public:
    LazySegmentTree(int sz){
        n=1;
        while(n<sz) n*=2;
        node.assign(2*n-1,0LL);
        lazy.assign(2*n-1,0LL);
    }
    void update(int a,int b,int x,int k,int l,int r){
        if(a<=l and r<=b){
            node[k]+=x*(r-l);
            lazy[k]+=x;
        }else{
            if(lazy[k]!=0) push(k,l,r),lazy[k]=0;
            if(check(a,b,l,(l+r)/2)) update(a,b,x,2*k+1,l,(l+r)/2);
            if(check(a,b,(l+r)/2,r)) update(a,b,x,2*k+2,(l+r)/2,r);
            node[k]=node[2*k+1]+node[2*k+2];
        }
    }
    int get(int a,int b,int k,int l,int r){
        if(a<=l and r<=b){
            return node[k];
        }else{
            if(lazy[k]!=0) push(k,l,r),lazy[k]=0;
            int res=0;
            if(check(a,b,l,(l+r)/2)) res+=get(a,b,2*k+1,l,(l+r)/2);
            if(check(a,b,(l+r)/2,r)) res+=get(a,b,2*k+2,(l+r)/2,r);
            return res;
        }
    }
    void push(int k,int l,int r){
        node[2*k+1]+=lazy[k]*(r-l)/2; lazy[2*k+1]+=lazy[k];
        node[2*k+2]+=lazy[k]*(r-l)/2; lazy[2*k+2]+=lazy[k];
    }
    bool check(int a,int b,int l,int r){
        return max(a,l)<min(b,r);
    }
    void update(int a,int b,int x){ update(a,b,x,0,0,n); }
    int get(int a,int b){ return get(a,b,0,0,n); }
};

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

    int N,Q; cin>>N>>Q;
    LazySegmentTree seg(N);
    while(Q--){
        int q; cin>>q;
        if(q==0){
            int s,t,x; cin>>s>>t>>x;
            s--;
            seg.update(s,t,x);
        }else{
            int s,t; cin>>s>>t;
            s--;
            cout<<seg.get(s,t)<<endl;
        }
        // for(int i=0;i<4;i++) cout<<seg.get(i,i+1)<<' '; cout<<endl;
    }
    return 0;
}


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

const int EDGE_CASE = 1e9;

int main(){
    int N, K, S;
    scanf("%d%d%d", &N, &K, &S);

    if(S == EDGE_CASE){
        for(int i = 0; i < K; i ++){
            printf("%d", EDGE_CASE);
            if(i != N-1){
                printf(" ");
            }
        }

        for(int i = K; i < N; i ++){
            printf("1");
            if(i != N-1){
                printf(" ");
            }
        }

        return 0;
    }else if(S == 1){
        for(int i = 0; i < K; i ++){
            printf("1");
            if(i != N-1){
                printf(" ");
            }
        }

        for(int i = K; i < N; i ++){
            printf("%d", EDGE_CASE);
            if(i != N-1){
                printf(" ");
            }
        }
    }else if(K == N){
        for(int i = 0; i < N; i ++){
            printf("%d", S);
            if(i != N-1){
                printf(" ");
            }
        }
    }else{
        for(int i = 0; i <= K; i ++){
            if(i%2 == 0){
                printf("1");
            }else{
                printf("%d", S-1);
            }
            if(i != N-1){
                printf(" ");
            }
        }

        for(int i = K+1; i < N; i ++){
            printf("%d", EDGE_CASE);
            if(i != N-1){
                printf(" ");
            }
        }
    }
}




Measured memory_bytes: 1280
class WeightedUnionFindTree():
    '''ランク付きUnionFind木'''
    def __init__(self, n):
        ''' 初期化 '''
        self.par = list(range(n))#自分自信を根とする
        self.rank = [0] * n # 木の高さ 最初は0
        self.w = [0] * n # 重み

    def root(self, x):
        ''' 木の根を求める '''
        if self.par[x] == x:#自分が根ノードなら
            return x

        root = self.root(self.par[x])
        self.w[x] += self.w[self.par[x]]# 累積和をとる
        self.par[x] = root
        return root
    def relate(self, x, y, weight=0):
        # x と y の root へ (x と y が既につながっていたらreturn
        root_x, root_y = self.root(x), self.root(y)
        if root_x == root_y: return;
        #木の高さ-ランクが低い方に繋げる
        if self.rank[root_x] < self.rank[root_y]:
            self.par[root_x] = root_y # 低いroot_xにroot_yを繋げ、低い方が根なのでひく
            self.w[root_x] = weight - self.w[x] + self.w[y]
        else:
            self.par[root_y] = root_x # 逆
            self.w[root_y] = -weight + self.w[x] - self.w[y]
            if self.rank[root_x] == self.rank[root_y]:
                self.rank[root_x] += 1

    def same(self, x, y):
        #xとyが同じ集合に属するか
        return self.root(x) == self.root(y)

    def diff(self, x, y):
        if self.same(x, y):
            return self.w[x] - self.w[y]
        else:
            return "?"

def querying(queries, uft):
    for query in queries:
        if query[0] == 0:#unite
            uft.relate(query[1], query[2], query[3])
        else:
            print(uft.diff(query[1], query[2]))

if __name__ == '__main__':
    # https://onlinejudge.u-aizu.ac.jp/courses/library/3/DSL/all/DSL_1_B
    n, q = map(int, input().split())
    queries = [list(map(int, input().split())) for i in range(q)]
    uft = WeightedUnionFindTree(n)#instant UnionFindTree
    querying(queries, uft)#Querying



Measured memory_bytes: 52264
#include<iostream>

int main(){
	
	char a;
	int w,n,tate[30],b,c,d,i;

	std::cin>>w;
	for(i=1;i<=w;i++){
		tate[i]=i;
		}
	std::cin>>n;
	
	for(i=0;i<n;i++){
		std::cin>>b>>a>>c;
		d=tate[b];
		tate[b]=tate[c];
		tate[c]=d;
		}
		
	for(i=1;i<=w;i++){
		std::cout<<tate[i]<<std::endl;
		}

	return 0;
	
	}

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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main()
{
    cout << fixed << setprecision(15);

    int A, P;
    cin >> A >> P;

    cout << (3*A + P) / 2 << endl;
    return 0;
}

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

int main(){
    int N;
    cin >> N;
    vector<ll> a(N);
    for(int i(0);i<N;++i) cin >> a[i];
    ll xor_product(a[0]);
    for(int i(1);i<N;++i) xor_product = xor_product ^ a[i];
    if(xor_product == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

map<int,int> m;
vector<int> v;

int main()
{
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	
	for(int i=1;i<=n;i++){
		int x;
		cin >> x;
		if(m[x]==0) v.push_back(x);
		m[x]++;
	}
	
	int ans=0;
	for(int i=0;i<v.size();i++)
	  if(v[i]>m[v[i]]) ans+=m[v[i]];
	  else if(v[i]<m[v[i]]) ans+=m[v[i]]-v[i];
	  
	cout<<ans;
	return 0;
}

Measured memory_bytes: 5112
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))
## dp ##
def DD2(d1,d2,init=0): return [[init]*d2 for _ in range(d1)]
def DD3(d1,d2,d3,init=0): return [DD2(d2,d3,init) for _ in range(d1)]
## math ##
def to_bin(x: int) -> str: return format(x, 'b') # rev => int(res, 2)
def to_oct(x: int) -> str: return format(x, 'o') # rev => int(res, 8)
def to_hex(x: int) -> str: return format(x, 'x') # rev => int(res, 16)
MOD=10**9+7
def divc(x,y) -> int: return -(-x//y)
def divf(x,y) -> int: return x//y
def gcd(x,y):
    while y: x,y = y,x%y
    return x
def lcm(x,y): return x*y//gcd(x,y)
def enumerate_divs(n):
    """Return a tuple list of divisor of n"""
    return [(i,n//i) for i in range(1,int(n**0.5)+1) if n%i==0]
def get_primes(MAX_NUM=10**3):
    """Return a list of prime numbers n or less"""
    is_prime = [True]*(MAX_NUM+1)
    is_prime[0] = is_prime[1] = False
    for i in range(2, int(MAX_NUM**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i*2, MAX_NUM+1, i):
            is_prime[j] = False
    return [i for i in range(MAX_NUM+1) if is_prime[i]]
## libs ##
from itertools import accumulate as acc
from collections import deque, Counter
from heapq import heapify, heappop, heappush
from bisect import bisect_left
#======================================================#

def main():
    q,h,s,d = MII()
    n = II()
    print(int((n//2)*min(8*q, 4*h, 2*s, d) + (n%2)*min(4*q, 2*h, s)))

if __name__ == '__main__':
    main()

Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

const ll MOD = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

using namespace std;

int N, M;
vector<int> A, B;

long long solve()
{
    ll res = 1;
    int biggerX_a = 0, biggerX_b = 0; // A,B でxより大きい数値の個数

    for (int x = N * M; x >= 1; x--)
    {
        /*if (A[biggerX_a] > x)
            return 0;
        if (B[biggerX_b] > x)
            return 0;
        */
        long long tmp = 1;
        if (A[biggerX_a] == x && B[biggerX_b] == x)
        {
            tmp = 1;
            ++biggerX_a, ++biggerX_b;
        }
        else if (A[biggerX_a] == x)
        {
            tmp = biggerX_b;
            ++biggerX_a;
        }
        else if (B[biggerX_b] == x)
        {
            tmp = biggerX_a;
            ++biggerX_b;
        }
        else
        {
            tmp = biggerX_a * biggerX_b - (N * M - x);
            if (tmp <= 0)
                return 0;
        }
        res = (res * tmp) % MOD;
    }
    return res;
}
int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> N >> M;
    A.resize(N+1);
    B.resize(M+1);
    rep(i, N) cin >> A[i];
    rep(i, M) cin >> B[i];
    sort(ALL(A), greater<int>());
    sort(ALL(B), greater<int>());
    cout << solve() << endl;
}

Measured memory_bytes: 384
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;

void main() {
    readln;
    readln.split.to!(int[]).count!"a % 2 == 0".writeln;
}



void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}


void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}


Measured memory_bytes: 2464
#include<iostream>
#include <algorithm>
#include<string>
#include <bitset>
#include <vector>
#include <functional>
#include <climits>
#include <iomanip>
#include <utility>
#include <stack>
#include <queue>
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <numeric>
using namespace std;
using ll = long long;

typedef pair <int, int> pii;

int main()
{

	ll a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, g = 0, h = 0, ans = 0;
	//cout << LONG_MAX << endl;
	//long long n, A[1000000000];
	//ll n, m, q;
	string s, t;
	ll n, m;
	cin >> n;
	double x[1000] = {};
	for (int i = 0; i < n; i++)
	{
		cin >> a;
		x[i] = a;
	}
	double sum = 0;
	for (int i = 0; i < n; i++)
	{
		sum += x[i];
	}
	sum /= n;
	double mini = 100000000;
	double diff = 0;
	for (int i = 0; i < n; i++)
	{
		diff = sum - x[i];
		if (diff<0)
		{
			diff *= -1;
		}
		if (mini > diff)
		{
			mini = min(diff, mini);
			b = i;
		}

	}

	cout << b << endl;
	//cout <<  << endl;

	////std::cout << std::fixed;
	//cout << std::setprecision(20) << << endl;
	//cout << d+1 << endl;
	//cout << "" << endl;

	return 0;
}
//accumulate(x, x + a, 0);
//memcpy(x, visited, sizeof(ll)*n);
//void kansuu(ll num, ll visited[10]) {}
//kansuu(1, zz);
//cout << setprecision(15) << v << endl;
//cout << char(z - 'a');
//log10(i) + 1 //10進数の桁数を取得

//int temp;
//for (int i = 0; i < n - 1; i++) {
//	for (int j = n - 1; j > i; j--) {
//		if (w[j - 1] < w[j]) {  /* 前の要素の方が大きかったら */
//			temp = w[j];        /* 交換する */
//			w[j] = w[j - 1];
//			w[j - 1] = temp;
//		}
//	}
//}

//最小公倍数
//ll x = a * b;
//ll tmp;
///* 自然数 a > b を確認・入替 */
//if (a<b) {
//	tmp = a;
//	a = b;
//	b = tmp;
//}
///* ユークリッドの互除法 */
//ll r = a % b;
//while (r != 0) {
//	a = b;
//	b = r;
//	r = a % b;
//}
//a = x / b;//答え


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

typedef long long int ll;

#define FOR(i,n,m) for(ll i=(ll)(m);i<(ll)(n);++i)
#define REP(i,n) FOR(i,n,0)
#define IREP(i,n) for(ll i=(ll)(n);i>=0;--i)

const ll MOD = 1000000007;

using namespace std;

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

	if (abs(N - M) > 1)
	{
		cout << 0 << endl;
		return 0;
	}

	ll ans = 0;

	ll dt = 1;
	REP(i, N)
	{
		dt *= (N - i)*(M - i) % MOD;
		dt %= MOD;
	}
	ans += dt;

	ll mt = 1;
	REP(i, M)
	{
		mt *= (N - i)*(M - i) % MOD;
		mt %= MOD;
	}
	ans += mt;

	ans %= MOD;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
template<class T> inline bool chmin(T&a, T b){if(a > b){a = b; return true;}else{return false;}}
template<class T> inline bool chmax(T&a, T b){if(a < b){a = b; return true;}else{return false;}}
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1.0)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

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

Measured memory_bytes: 3588
// while( !(succeed == try()) );

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

// Alpha // Alpha // Alpha // Alpha // Alpha // Alpha // Alpha // Alpha // Alpha // Alpha


#define int long long int
#define loop(i,s,e) for(int i=s; i<e; i++)
#define endl '\n'
#define vii vector<int>
#define pii pair<int, int>
#define ff first
#define ss second
#define N 100001
#define pb push_back
#define INF LLONG_MAX
#define inf INT_MAX

void INP();

#define bug(...)        __f (#__VA_ARGS__, __VA_ARGS__)
#define rtn                                       if(0)return;
template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { rtn cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{     rtn 
     const char* comma = strchr (names + 1, ',');
     cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}

// Alpha // Alpha // Alpha // Alpha // Alpha // Alpha // Alpha // Alpha // Alpha // Alpha


void alpha()
{	
	int n;
	cin>>n;

	int arr[n] = {0};
	int ans[n+1] = {0};

	loop(i,0,n) 
	{
		cin>>arr[i];
		ans[arr[i]]++;
	}

	loop(i,1,n+1) cout<<ans[i]<<endl;
}	

int32_t main(){

	ios_base:: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	//INP();
    int t=1;
	//cin>>t;

  	while(t--) alpha();

	return 0;

}






















inline void INP()
{
      #ifndef ONLINE_JUDGE
          freopen("input.txt",  "r",  stdin);
          freopen("output.txt", "w", stdout);
      #endif
}
 
 

Measured memory_bytes: 6800
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) for(int i = 0; i < (n); ++i)

#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))

#define endl "\n"
#define pb push_back
#define rtn return
#define elif else if

#define MOD 1000000007
 
const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};
const int dx_8[]={1,1,0,-1,-1,-1,0,1}, dy_8[]={0,-1,-1,-1,0,1,1,1};

typedef long long ll;
typedef unsigned long long ull;

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

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

	int n, m, X, Y, x[100], y[100];
	cin >> n >> m >> X >> Y;
	REP(i, n) cin >> x[i];
	REP(i, m) cin >> y[i];

	sort(x, x+n);
	sort(y, y+m);
	int pos = -110;
	string ans = "War";
	while(1){
		if(pos > 110) break;
		if(pos > X and pos <= Y and x[n-1] < pos and y[0] >= pos) ans = "No War";
		pos++;
	}
	cout << ans << endl;
	rtn 0;
}

Measured memory_bytes: 256