akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <cctype>
#include <algorithm>
#include <functional>
#include <utility>
using ll = long long;
const ll ha = 1000000007LL;
const ll inv_2 = (ha >> 1) + 1LL;
const int maxn = 3005;
ll f[maxn][maxn];
int A[maxn];

int main() {
  int n, Q; scanf("%d%d", &n, &Q);
  for(int i = 1; i <= n; i ++) scanf("%d", &A[i]);
  for(int i = 1; i <= n; i ++) {
    for(int j = 1; j <= n; j ++) {
      if(A[i] < A[j]) f[i][j] = 1;
    }
  }
  for(int p = 0; p < Q; p ++) {
    int x, y; scanf("%d%d", &x, &y);
    f[x][y] = f[y][x] = (f[x][y] + f[y][x]) * inv_2 % ha;
    for(int j = 1; j <= n; j ++) {
      if(j != x && j != y) {
        f[j][y] = f[j][x] = (f[j][y] + f[j][x]) * inv_2 % ha;
        f[y][j] = f[x][j] = (f[x][j] + f[y][j]) * inv_2 % ha;
      }
    }
  }
  ll ans = 0;
  for(int i = 1; i <= n; i ++) {
    for(int j = 1; j < i; j ++) {
      ans = (ans + f[i][j]) % ha;
    }
  }
  for(int p = 0; p < Q; p ++) ans = (ans << 1) % ha;
  printf("%lld\n", ans);
  return 0;
}

Measured memory_bytes: 70656
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <math.h>
using namespace std;

double dis(int n,double p,int *x,int *y);

int main(){
	int n;
	cin >> n;
	int x[n],y[n],z = 0;
	
	for(int i = 0;i < n;i++)	cin >> x[i];
	for(int i = 0;i < n;i++)	cin >> y[i];
	
	for(int i = 0;i < n;i++){
		int a = abs(x[i] - y[i]);
		if(z < a)z = a;
	}
	
	
	cout << setprecision(18)
		 << dis(n,1,x,y) << "\n"
		 << dis(n,2,x,y) << "\n"
		 << dis(n,3,x,y) << "\n"
		 << z << "\n";
	return 0;
}

double dis(int n,double p,int *x,int *y){
	double ans = 0;
	for(int i = 0;i < n;i++){
		double ab;
		ab = abs(x[i] - y[i]);
		ans += pow(ab, p);
	}
	ans = pow(ans, 1/p);
	return ans;
}

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

int main() {
	int N, M,count=0;
	int x, y;
	cin >> N >> M;
	char a[60][60], b[60][60];
	for (int i = 0;i < N;++i) {
		for (int j = 0;j < N;++j)cin >> a[i][j];
	}
	for (int i = 0;i < M;++i) {
		for (int j = 0;j < M;++j)cin >> b[i][j];
	}
	for (int i = 0;i < M;++i) {
		for (int j = 0;j < M;++j) {
			if (b[i][j] == a[i][j]) {
				x = i;y = j;
				if (x + M <= N && y + M <= N) {
					for (int k = x;k < x + M;++k) {
						for (int h = y;h < y + M;++h) {
							if (b[k][h] == a[k][h])++count;
						}
					}if (count == M * M) {
						cout << "Yes" << endl;
						return 0;
					}
				}
			}
		}
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @author Pavel Mavrin
 */
public class Main {

    private void solve() throws IOException {
        int n = nextInt();
        int p = nextInt();
        int[]a = new int[n];
        for (int i = 0; i < n; i++) a[i] = nextInt();
        long[] d = new long[2];
        d[0] = 1;
        for (int i = 0; i <n ; i++) {
            long[] dd = new long[2];
            dd[0] = d[0];
            dd[1] = d[1];
            dd[a[i] % 2] += d[0];
            dd[(a[i] + 1) % 2] += d[1];
            d = dd;
        }
        out.println(d[p]);
    }

    // ------------------

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st;
    PrintWriter out = new PrintWriter(System.out);

    String next() throws IOException {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }

    int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

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

    private void run() throws IOException {
        solve();
        out.close();
    }

}


Measured memory_bytes: 21204
import java.lang.reflect.Array;
import java.util.*;
import java.io.*;
import java.lang.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        int r = sc.nextInt();

        if (r>=30)
            System.out.println("Yes");
        else
            System.out.println("No");
    }
}


Measured memory_bytes: 35620
import static java.lang.Integer.parseInt;
import static java.lang.System.out;
import java.io.File;
import java.util.Scanner;

public class Main extends BaseExe {

    public static int maxSize = 1000000;
    public static boolean[] prime = new boolean[maxSize];

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

    @Override
    protected void execute(Scanner scan) {
        setPrime();
        String inData = "";
        while (scan.hasNextLine() && !"".equals(inData = scan.nextLine())) {
            out.println(primeCount(parseInt(inData)));
        }
    }

    private void setPrime() {
        prime[2] = true;
        for (int i = 3; i < maxSize; i++) {
            if (i % 2 == 0) {
                continue;
            }
            setOddPrime(i);
        }
    }

    private void setOddPrime(int i) {
        boolean isPrime = true;
        for (int j = 1; j <= Math.sqrt(i); j++) {
            if (prime[j] && i % j == 0) {
                isPrime = false;
                break;
            }
        }
        prime[i] = (isPrime) ? true : false;
    }

    private int primeCount(int inData) {
        int count = 0;
        for (int i = 2; i <= inData; i++) {
            if (i != 2 && i % 2 == 0) {
                continue;
            }
            count = (prime[i]) ? ++count : count;
        }
        return count;
    }
}

abstract class BaseExe {

    public void exeSysIn() {
        try (Scanner scan = new Scanner(System.in)) {
            execute(scan);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void exeFileIn(String inDataPath) {
        try (Scanner scan = new Scanner(new File(inDataPath))) {
            execute(scan);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    protected abstract void execute(Scanner scan);
}

Measured memory_bytes: 27552
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=200005,M=800;
int read(){
	int f=1,g=0;
	char ch=getchar();
	for (;!isdigit(ch);ch=getchar()) if (ch=='-') f=-1;
	for (;isdigit(ch);ch=getchar()) g=g*10+ch-'0';
	return f*g;
}
int n,m,L,R,po[15],pos[M*M];
char ch[N];
int g[M],cur[M],a[M][M],b[M];
int get(int x){
	int y=0,t;
	for (int i=0;i<R;i++){
		t=x/po[i]%3;
		t=(t) ? (3-t) : t;
		y+=po[i]*t;
	}
	return y;
}
void salsa(int *a,int L){
	for (int i=0;i<po[L];i++)
	if (i<g[i]) swap(a[i],a[g[i]]);
}
void add(int *a,int L){
	int t=a[po[L]-1];
	for (int i=po[L]-2;i>=0;i--) a[i+1]=a[i];
	a[0]=t;
}
int main(){
	n=read();L=n/2;R=n-L;
	scanf(" %s",ch+1);
	m=strlen(ch+1);
	po[0]=1;
	for (int i=1;i<=n;i++) po[i]=po[i-1]*3;
	for (int i=0;i<po[L];i++)
	for (int j=0;j<po[R];j++) a[i][j]=i*po[R]+j;
	for (int i=0;i<po[L];i++) b[i]=i;
	for (int i=0;i<po[R];i++) g[i]=get(i),cur[i]=i;
	for (int i=1;i<=m;i++)
	if (ch[i]=='S'){
		salsa(b,L);
		salsa(cur,R);
	}
	else{
		add(cur,R);
		int t=a[b[po[L]-1]][cur[0]];
		for (int i=po[L]-2;i>=0;i--) a[b[i+1]][cur[0]]=a[b[i]][cur[0]];
		a[b[0]][cur[0]]=t;
	}
	for (int i=0;i<po[L];i++)
	for (int j=0;j<po[R];j++) pos[a[b[i]][cur[j]]]=i*po[R]+j;
	for (int i=0;i<po[n];i++) printf("%d ",pos[i]);
	printf("\n");
	return 0;
}

Measured memory_bytes: 8524
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1e18

using namespace std;

int main(void){
  ll n;
  string s;
  cin >> n >> s;
  
  ll r = 0, b = 0;
  for (int i = 0; i < s.size(); i++){
    if (s[i] == 'B')
      b++;
    else
      r++;
  }
  if (r > b)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
    

  
  

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include <map>
#include<math.h>
using namespace std;

unsigned long long cons = 1000000007;

unsigned long long nChoosek( unsigned long long n, unsigned long long k )
{
    if (k > n) return 0;
    if (k * 2 > n) k = n-k;
    if (k == 0) return 1;

    unsigned long long result = n;
    for( unsigned long long i = 2; i <= k; ++i ) {
        result *= (n-i+1);
        while (result%i!=0) result+=cons;
        result /= i;
        result %=cons;
    }
    return result;
}

int main()
{
  unsigned long long n,m,tmp=0,cnt=0,ans=1,prime,i;
  map<long long,long long> mp;
  cin >> n >> m;

  for(i=2;i*i<=m;)
  {
    if(m%i==0)
    {
      if(tmp!=i)
      {
        mp[i] = 1;
        tmp=i;
      }else{
        mp[i]++;
      }
      m/=i;
    }else{
      i++;
    }
  }

  if(m!=1)
  if(tmp!=m)
  {
    mp[m] = 1;
  }else{
    mp[m]++;
  }

  for(auto i = mp.begin();i!=mp.end();i++)
  {
    tmp = i->second;
    ans *= nChoosek(n+tmp-1,tmp);
    ans %= cons;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pb push_back
#define f first
#define s second
#define MOD 1000000007
#define PI 3.141592653
using namespace std;

void solve(){

	ll a,b; cin>>a>>b; cout<<a*b;

}

int main()
{ 
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cout<<fixed<<setprecision(12);

	int t =1; //cin>>t;
	for(int i=1; i<=t; i++){
		solve();
		cout<<"\n";
	}





	return 0;

}



Measured memory_bytes: 3600
import sys
input = sys.stdin.readline
INF = float("inf")


def main():
    s1 = input()[:-1]
    s2 = input()[:-1]
    S1 = len(s1)
    S2 = len(s2)

    dp = [[INF]*(S2 + 1) for _ in range(S1 + 1)]
    for i in range(S1 + 1):
        dp[i][0] = i
    for j in range(S2 + 1):
        dp[0][j] = j
    
    for i in range(S1):
        for j in range(S2):
            if s1[i:i+1]==s2[j:j+1]:
                dp[i+1][j+1] = min(dp[i+1][j+1], dp[i][j])
            else:
                dp[i+1][j+1] = min(dp[i+1][j+1], dp[i][j] + 1)
            dp[i+1][j+1] = min(dp[i+1][j+1], dp[i+1][j] + 1)
            dp[i+1][j+1] = min(dp[i+1][j+1], dp[i][j+1] + 1)
    
    # for i in range(S1 + 1):
    #     print(dp[i])
    print(dp[S1][S2])


if __name__ == '__main__':
    main()


Measured memory_bytes: 41976
package main

import (
        "fmt"
)

func main() {
        n := 0
        fmt.Scan(&n)

        y := 0
        fmt.Scan(&y)

        for ii := 0; ii <= n; ii++ {
                for jj := 0; jj <= n-ii; jj++ {
                        kk := n - ii - jj
                        sum := 10000*ii + 5000*jj + 1000*kk
                        if sum == y {
                                fmt.Println(ii, " ", jj, " ", kk)
                                return
                        }
                }
        }
        fmt.Println("-1 -1 -1")
}


Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<math.h>

using namespace std;

#define INF 1000000007
#define LINF (1LL << 62);

typedef long long i64;
typedef pair<i64,i64> P;


i64 n, a[303030], c[101010], x[101010], y[101010];
priority_queue<int, vector<int>, greater<int>> b;
priority_queue<int> d;

int main(){
	cin >> n;
	i64 cnt = 0, cnt2 = 0, ans = -LINF;
	for(int i = 0; i < n; i++){
		cin >> a[i];
		b.push(a[i]);
		cnt += a[i];
	}
	for(int i = n; i < 2*n; i++){
		cin >> a[i];
		c[i-n] = a[i];
	}
	for(int i = 2*n; i < 3*n; i++){
		cin >> a[i];
		d.push(a[i]);
		cnt2 -= a[i];
	}
	
	int l = 0, r = n;
	x[l] = cnt; y[r] = cnt2;
	for(int i = 0; i < n; i++){
		if(b.top() < c[l]){
			cnt += c[l] - b.top();
			b.pop();
			b.push(c[l]);
			l++;
		}
		else{
			l++;
		}
		if(d.top() > c[r-1]){
			cnt2 += d.top() - c[r-1];
			d.pop();
			d.push(c[r-1]);
			r--;
		}
		else{
			r--;
		}
		x[l] = cnt;
		y[r] = cnt2;
	}
	for(int i = 0; i <= n; i++){
		ans = max(ans, x[i]+y[i]);
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 5880
#include<iostream>
#include<string>
using namespace std;
using ll=long long;
int main(){

  string S;
  cin>>S;
  int A=S[0]-'0';
  int B=S[1]-'0';
  int C=S[2]-'0';
  int D=S[3]-'0';
  if(A+B+C+D==7){
  
    cout<<S[0]<<"+"<<S[1]<<"+"<<S[2]<<"+"<<S[3]<<"=7";
    return 0;
  }
  if(A+B+C-D==7){
  
    cout<<S[0]<<"+"<<S[1]<<"+"<<S[2]<<"-"<<S[3]<<"=7";
    return 0;
  }
  if(A+B-C+D==7){
        
    cout<<S[0]<<"+"<<S[1]<<"-"<<S[2]<<"+"<<S[3]<<"=7";
    return 0;
  }  
  if(A+B-C-D==7){
  
    cout<<S[0]<<"+"<<S[1]<<"-"<<S[2]<<"-"<<S[3]<<"=7";
    return 0;
  }
  if(A-B+C+D==7){

    cout<<S[0]<<"-"<<S[1]<<"+"<<S[2]<<"+"<<S[3]<<"=7";
    return 0;    
  }
  if(A-B+C-D==7){
  
    cout<<S[0]<<"-"<<S[1]<<"+"<<S[2]<<"-"<<S[3]<<"=7";
    return 0;  
  }
  if(A-B-C+D==7){
  
    cout<<S[0]<<"-"<<S[1]<<"-"<<S[2]<<"+"<<S[3]<<"=7";
    return 0;  
  }
  if(A-B-C-D==7){
  
    cout<<S[0]<<"-"<<S[1]<<"-"<<S[2]<<"-"<<S[3]<<"=7";
    return 0;    
  }
  return 0;
}

Measured memory_bytes: 3604
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<long long int> v;
    for (int i = 0; i < n; i++) {
        long long int t;
        cin >> t;
        v.push_back(t);
    }
    sort(v.begin(), v.end(), greater<int>());
    priority_queue<pair<long long int, long long int>> pq;
    long long int res = v[0];
    pq.push(make_pair(v[1], v[0]));
    pq.push(make_pair(v[1], v[0]));
    for (int i = 2; i < n; i++) {
        auto p = pq.top();
        pq.pop();
        res += p.first;
        pq.push(make_pair(v[i], p.first));
        pq.push(make_pair(v[i], p.second));
    }
    cout << res << endl;
}


Measured memory_bytes: 8952
// atcoder/abc169/C/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; for (auto& i: v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { for (auto& i: v) is >> i; return is; }
template<typename T> ostream& operator << (ostream& os, set<T> s) { os << "#{"; for (auto& i: s) os << i << ","; os << "}"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; for (auto& i: m) os << i << ","; os << "}"; return os; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

using lli = long long int;
using ull = unsigned long long;
using point = complex<double>;
using str = string;
template<typename T> using vec = vector<T>;

constexpr array<int, 8> di({0, 1, -1, 0, 1, -1, 1, -1});
constexpr array<int, 8> dj({1, 0, 0, -1, 1, -1, -1, 1});
constexpr lli mod = 1e9 + 7;

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.setf(ios_base::fixed);
  cout.precision(15);

  ull a;
  str s;
  while (cin >> a >> s) {
    str t;
    each (c, s) {
      if (c != '.') t += c;
    }
    ull b = stol(t);
    cout << (a * b) / 100 << endl;
  }


  return 0;
}


Measured memory_bytes: 3656
#include<cstdio>

int solve(){
  int a,b,c,n;
  int A[1000],B[1000],C[1000],bad = 0;
  bool ok[300],dame[300];
  for(int i=0;i<300;i++) ok[i] = false;
  for(int i=0;i<300;i++) dame[i] = false;
  scanf("%d %d %d",&a,&b,&c);
  if(a==0&&b==0&&c==0) return 0;
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    int res,x,y,z;
    scanf("%d %d %d %d",&x,&y,&z,&res);
    x--;
    y--;
    z--;
    if(res==1){
      ok[x] = true;
      ok[y] = true;
      ok[z] = true;
    }else{
      A[bad] = x;
      B[bad] = y;
      C[bad] = z;
      bad++;
    }
  }
  for(int i=0;i<bad;i++){
    int a[3] = {A[i],B[i],C[i]};
    int cnt = 1;
    for(int j=2;j<=4;j++) if(!ok[a[j-2]]) cnt*=j;
    if(cnt<6) dame[a[cnt-2]] = true;
  }
  for(int i=0;i<a+b+c;i++){
    if(ok[i]) printf("1\n");
    else if(dame[i]) printf("0\n");
    else printf("2\n");
  }
  return 1;
}

int main(){
  while(true){
    if(!solve()) return 0;
  }
}

Measured memory_bytes: 2508
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#include <math.h>
#include <bits/stdc++.h>
#define ull unsigned long long
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,j,n) for(int i = j; i < n; i++)
#define RFOR(i,j,n) for(int i = j-1; i >= n; i--)
#define PREC(n) fixed << setprecision(n)
#define print_array(v) REP(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
using namespace std;

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define all(x) x.begin(), x.end()
const ll MOD = 1e9 + 7;
const ll MAX = 700000;

long long fac[MAX], finv[MAX], inv[MAX];

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

ll COM(int n, int k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
  ll x, y, numX = 0, numY;
  cin >> x >> y;
  if ((x + y) % 3 != 0 || x > 2 * y || y > 2 * x)
    cout << 0 << endl;
  else {
    ll _x = x, _y = y;
    for (ll i = 0; i < x; i++) {
      if (_y * 2 == _x) {
        numY = _x / 2;
        break;
      } else {
        numX++;
        _x -= 1;
        _y -= 2;
      }
    }
    COMinit();
    cout << COM(numX + numY, numY) << endl;
  }
}

Measured memory_bytes: 16640
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll> 
#define rep(i,n) for(ll (i)=0; i<(n); ++(i))
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll n,m,ans=0;cin>>n>>m;
  if(n==1) {
    if(m==1) ans=1; if(m==2) ans=0; if(m>2) ans=m-2;
  }
  else if(n==2) ans=0;
  else {
    if(m==1) ans=n-2; if(m==2) ans=0; if(m>2) ans=(n-2)*(m-2);
  }
  print(ans);
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//----***やべーやつら***----
using namespace std;
#define int long long

//----***型定義***----
using ll = long long;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;
typedef long double lb;
typedef long double ld;
typedef pair<int,int> P;

//----***Like a Pythonista***----
#define REP(ii,jj,nn) for (ll ii=jj;ii<(nn);ii++)
#define RREP(ii,nn,jj) for (ll ii = nn; jj<ii;ii--)
#define each(i,...) for (auto&& i:__VA_ARGS__)
#define ALL(vec) (vec).begin(),(vec).end()
#define sum(...) accumulate(ALL(__VA_ARGS__),0LL)
#define dsum(...) accumulate(ALL(__VA_ARGS__),0.0L)
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
template<class T> inline auto max(const T& a){ return *max_element(ALL(a)); }
template<class T> inline auto min(const T& a){ return *min_element(ALL(a)); }
inline ll gcd(ll a,ll b){if(b == 0) return a;return  gcd(b,a%b);}
inline ll lcm(ll a,ll b){ll g = gcd(a,b);return a / g * b;}

//----***定数***----
const int MOD=1e9+7;
#define INF 1e12;
#define EPS 1e-9;

//----***入出力***---
#define print(out) cout<< out  << "\n";
#define debug(var)  do{std::cerr << #var << " ↓ "<<"\n";view(var);}while(0);
#define dbg cerr<<"🥺🥺🥺🥺🥺🥺"<<endl;
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

//----***初期時読み込み***----
struct initial{initial(){cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}initial_;


int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %=(int)MOD;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}


signed main(){

  int N,M;cin>>N>>M;
  if(abs(N-M)>1){
    print(0);
    return 0;
  }
  int c_dog=kai(N,N);
  int c_monkey=kai(M,M);
  // debug(c_dog)
  // debug(c_monkey)
  int ans=c_dog*c_monkey%(int)MOD;
  if(N==M){
    ans=ans*2%(int)MOD;
  }
  print(ans)



}


Measured memory_bytes: 256
def prime(n):
    p = dict([])
    i = 2
    while i*i <= n:
        while n % i == 0:
            n /= i
            if i in p:
                p[i] += 1
            else:
                p[i] = 1
        i += 1
    if n > 1:
        p[int(n)] = 1
    return p


n = int(input())

import math
ans = 0
for a in prime(n).values():
    ans += math.floor(math.sqrt(8*a+1) - 1)//2

print(ans)



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

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

  // 4桁の数値
  // 連続して3つ以上なので
  // 1桁目と2桁目と3桁目
  // 2桁目と3桁目と4桁目について調べる
  int n1 = N / 1000;
  int n2 = N / 100 % 10;
  int n3 = N / 10 % 10;
  int n4 = N % 10;

  if (n1 == n2 &&
      n2 == n3) {
    cout << "Yes" << endl;
    return 0;
  }
  if (n2 == n3 &&
      n3 == n4) {
    cout << "Yes" << endl;
    return 0;
  }
  cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define rep(i,a,b) for(long long i=a; i<b; i+=1)
#define repr(i,a,b) for(long long i=a; i<=b; i+=1)
#define vec vector<ll>
#define map map<string,int>
#define repa(p,A) for(auto p:A)
#define pb push_back
#define sort(a) sort(a.begin(),a.end())
#define reverse(a) reverse(a.begin(),a.end())

using namespace std;
int main() {
  ll N;
  cin>>N;
  vec A(N);
  rep(i,0,N) cin>>A[i];
  sort(A);
  ll D=1000000000;
  repr(i,A[0],A[N-1]) {
    ll B=0;
    rep(j,0,N) {
      B+=pow(A[j]-i,2);
    }
    D=min(D,B);
  }
  cout<<D<<endl;
  

}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<math.h>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<unordered_map>
#include<functional>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=2e18;
const ll MOD=1e9+7;

ll H,N;
int main(){
    cin>>H>>N;
    for(ll i=0;i<N;i++){
      ll a;
      cin>>a;
      H-=a;
    }
    cout<<((H<=0)?"Yes":"No")<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// #define int long long
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);++i)
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define FORD(i,a,b) for(int i=(a);i>=(b);--i)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
inline int msbp(int x) {return 31-__builtin_clz(x);}
inline int msb(int x) {return 1 << msbp(x);}
typedef long long ll;
typedef pair<int, int> pii;
// const ll INF = 0x3f3f3f3f3f3f3f3fLL;
const int INF = 0x3f3f3f3f;
// const int INF = INT_MAX;
// const int nINF = INT_MIN;
// const ll INF = LLONG_MAX;
// const ll nINF = LLONG_MIN;

/////////////////////////////////////////////////////////////////////

const int N = 2e5+10;

int n;
ll ans;

struct trie {
	trie *children[26] = {};
	int have[26] = {};
	bool word = false;
} head;

void insert(trie* itr, string& s, int& mask, int id = 0) {
	if(id < s.size()) {
		int c = s[id]-'a';
		if(itr->children[c] == nullptr) {
			itr->children[c] = new trie;
		}
		insert(itr->children[c], s, mask, id+1);
		mask |= (1 << c);
		if(id+1 < s.size()) {
			REP(i, 26) {
				if(mask & (1 << i)) ++itr->have[i];
			}
		}
		// cout << s << ' ' << id << endl;
		// REP(i, 26) cout << itr->have[i] << ' ';
		// cout << endl;
	} else {
		itr->word = true;
	}
}

void dfs(trie* itr) {
	REP(i, 26) {
		if(itr->children[i] == nullptr) continue;
		if(itr->children[i]->word) {
			ans += itr->have[i];
		}
		dfs(itr->children[i]);
	}
}

signed main() {
    ios::sync_with_stdio(false);
    //cout << fixed << setprecision(7);
    cin >> n;
    REP(i, n) {
    	string s;
    	cin >> s;
    	reverse(s.begin(), s.end());
    	int mask = 0;
    	insert(&head, s, mask);
    }
    dfs(&head);
    cout << ans << endl;

    return 0;
}

// Easy things to check:
// - LONG LONGS (WA)
// - const int N is correct (WA, RTE) CHECK IF IT SHOULD BE 2*N!!!!
// - .size()-k underflow (WA, RTE, TLE)
// - small n edge cases (WA)

// Rare mistakes made in the past:
// - division by 0 (WA)
// - negative arithmetic, ceiling division, modulo (WA)
// - setprecision (WA)
// - INF not big enough using ll (WA)
// - setting max to 0 instead of -INF/min to 0 instead of INF (WA)
// - outputting debug (WA)
// - allocating too much memory (locRTE, MLE)
// - stack size (locRTE)
// - round announcements (WA)
// - multiset::erase (WA)
// - forgetting to rename recursive call when copy/pasting recursive function (WA)
// - not clearing DS between test cases EVEN FOR INPUT (WA, RTE, TLE, MLE)


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

// マクロ //
#define rep(i,N) for(int i = 0; i < (int)(N); i++)
#define all(x) x.begin(), x.end()
#define sort(x) sort(all(x))
#define uniq(x) x.erase(unique(all(x)), x.end())
#define vsum(x) accumulate(all(x), 0)
#define cou(x) cout << x << endl
#define y() cout << "Yes" << endl
#define n() cout << "No" << endl
#define Y() cout << "YES" << endl
#define N() cout << "NO" << endl
#define x2(x) (x) * (x)
#define db(i) cout << #i << " = " << i;

// 型エイリアス //
using lint = long long;
using pii = pair<int, int>;
using vpii = vector<pii>;
using vi = vector<int>;
using vli = vector<lint>;
using vc = vector<char>;
using vs = vector<string>;
using vb = vector<bool>;
using vvi = vector<vi>;
using vvli = vector<vli>;
using vvb = vector<vb>;
using vvc = vector<vc>;
using vvs = vector<vs>;
using mii = map<int, int>;
using mili = map<int, lint>;
using mci = map<char, int>;
using mcli = map<char, lint>;
using msi = map<string, int>;
using msli = map<string, lint>;


// 関数 //
template<class T, class Q> lint gcd_(T a, Q b) {
    int t;
    while (b != 0) {
        t = a % b;
        a = b;
        b = t;
    }
    return a;
}

template<class T, class Q> lint lcm_(T a, Q b) {
    return a * b / gcd(a, b);
}

double distance(pii a, pii b) {
    double dist;
    dist = sqrt(x2(a.first - b.first) + x2(a.second - b.second));
    return dist;
}

lint perm(int a) {
    lint perm = 1;
    for (int i = a; i >= 1; i--) {
        perm *= i;
    }
    return perm;
}

lint combination(int n, int m) {
    long double c = 1;
    for (int i = n, k = 1; i > m; i--, k++) {
        c *= i;
        c /= k;
    }
    return (lint)c;
}

template<class T, class Q> inline bool chmin(T& a, Q b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template<class T, class Q> inline bool chmax(T& a, Q b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

// 定数 //
const double pi = acos(-1);
const int mod = 1000000007;
const int MOD = 998244353;
const int inf = 1045141919;
const lint linf = ((1LL << 62) - 1);


// キーワード //
#define elif else if

// End of Template //


int main() {

    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);

    int N;
    cin >> N;
    vi A(N - 1);
    rep(i, N - 1) cin >> A[i];
    mii ninzu;
    rep(i, N) {
        ninzu[i + 1] = 0;
    }
    rep(i, N - 1) {
        ninzu[A[i]]++;
    }
    for (auto x : ninzu) {
        cou(x.second);
    }
}

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

#define int long long
#define rep(i, a) for (int i = 0; i < (a); i++)
#define repd(i, a) for (int i = (a)-1; i >= 0; i--)
#define reps(i, a, j) for (int i = (j); i < (a); i++)
#define deb(x) cout << #x << " " << x << endl;
#define debs(x) cout << #x << " " << x << " ";
#define deba(x) for (auto _i:x) cout << _i << " "; cout << endl;
#define ms(a) memset(a,0,sizeof(a));
#define mp make_pair
#define eb emplace_back
#define pii pair < int , int >
#define all(a) a.begin(),a.end()

const int mod = 1e9+7;
void solve() {
    int n; cin >> n;
    int sum = 0,res = 0;
    rep(i,n) {
        int x; cin >> x;
        res = (res%mod + ((sum*x)%mod))%mod;
        sum = (sum%mod + x%mod)%mod;
    }
    cout << res << endl;
}

signed main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t; t=1;
    while (t--) solve();
}

Measured memory_bytes: 3648
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;

int main()
{
	long long X, sum = 0;
	cin >> X;
	for (int i = 0; ; i++) {
		sum += i;
		if (X <= sum) {
			cout << i << endl;
			break;
		}
	}
}

Measured memory_bytes: 256
n = gets.strip.to_i
as = gets.strip.split.map(&:to_i)

cum_s = [0]
cum_x = [0]
n.times do |i|
  cum_s.push(cum_s[i] + as[i])
  cum_x.push(cum_x[i] ^ as[i])
end

#p as
#p cum_s
#p cum_x

result = 0
l=r=1

until r == n+1 do
#  p [l,r]
  if (cum_s[r]-cum_s[l-1] == cum_x[r]^cum_x[l-1])
    result += r-l+1
    r+=1
  else
    l+=1
  end
end

p result


Measured memory_bytes: 20000
import java.util.Scanner;

public class Main {

    public static void main(String[] args){
	Scanner s = new Scanner(System.in);
	while(s.hasNext()){
	    int[] a = new int[5];
	    for(int i=0 ; i<5 ; i++)
		a[i] = s.nextInt();
	    int b = Math.min(a[0],a[1]);
	    b = Math.min(b,a[2]);
	    int c = Math.min(a[3],a[4]);
	    System.out.println(b+c-50);
	}
    }
}

Measured memory_bytes: 12000
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.Closeable;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
import java.util.Map.Entry;
import java.util.stream.IntStream;

public class Main {
    static ContestScanner in;
    static Writer out;
    public static void main(String[] args) {
        Main main = new Main();
        try {
            in = new ContestScanner();
            out = new Writer();
            main.solve();
            out.close();
            in.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    void solve() throws IOException {
        int n = in.nextInt();
        int p = in.nextInt();
        int odd = 0;
        int even = 0;
        for (int i = 0; i < n; i++) {
            if(in.nextInt() % 2 == 0) even++;
            else odd++;
        }
        long ans = 0;
        long[][] comb = pascalT(odd + 1);
        for (int i = 0; i <= odd; i++) {
            if(i % 2 != p) continue;
            ans += (1L << even) * comb[odd][i];
        }
        System.out.println(ans);
    }

    public static long[][] pascalT(int n){
        long[][] tri = new long[n][];
        for(int i=0; i<n; i++){
            tri[i] = new long[i+1];
            for(int j=0; j<i+1; j++){
                if(j == 0 || j == i){
                    tri[i][j] = 1;
                }else{
                    tri[i][j] = tri[i-1][j-1] + tri[i-1][j];
                }
            }
        }
        return tri;
    }
}


class Writer extends PrintWriter{
    public Writer(String filename)throws IOException
    {super(new BufferedWriter(new FileWriter(filename)));}
    public Writer()throws IOException{super(System.out);}
}
class ContestScanner implements Closeable{
    private BufferedReader in;private int c=-2;
    public ContestScanner()throws IOException
    {in=new BufferedReader(new InputStreamReader(System.in));}
    public ContestScanner(String filename)throws IOException
    {in=new BufferedReader(new InputStreamReader(new FileInputStream(filename)));}
    public String nextToken()throws IOException {
        StringBuilder sb=new StringBuilder();
        while((c=in.read())!=-1&&Character.isWhitespace(c));
        while(c!=-1&&!Character.isWhitespace(c)){sb.append((char)c);c=in.read();}
        return sb.toString();
    }
    public String readLine()throws IOException{
        StringBuilder sb=new StringBuilder();if(c==-2)c=in.read();
        while(c!=-1&&c!='\n'&&c!='\r'){sb.append((char)c);c=in.read();}
        return sb.toString();
    }
    public long nextLong()throws IOException,NumberFormatException
    {return Long.parseLong(nextToken());}
    public int nextInt()throws NumberFormatException,IOException
    {return(int)nextLong();}
    public double nextDouble()throws NumberFormatException,IOException
    {return Double.parseDouble(nextToken());}
    public void close() throws IOException {in.close();}
}


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

// #define multitest 1
#ifdef Debug
#define db(...) ZZ(#__VA_ARGS__, __VA_ARGS__);
#define pc(...) PC(#__VA_ARGS__, __VA_ARGS__);
template <typename T, typename U>
ostream &operator<<(ostream &out, const pair<T, U> &p)
{
	out << '[' << p.first << ", " << p.second << ']';
	return out;
}
template <typename Arg>
void PC(const char *name, Arg &&arg)
{
	std::cerr << name << " { ";
	for (const auto &v : arg)
		cerr << v << ' ';
	cerr << " }\n";
}
template <typename Arg1>
void ZZ(const char *name, Arg1 &&arg1)
{
	std::cerr << name << " = " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void ZZ(const char *names, Arg1 &&arg1, Args &&... args)
{
	const char *comma = strchr(names + 1, ',');
	std::cerr.write(names, comma - names) << " = " << arg1;
	ZZ(comma, args...);
}
#else
#define db(...)
#define pc(...)
#endif

using ll = long long;
#define f first
#define s second
#define pb push_back
const long long mod = 1000000007;
auto TimeStart = chrono::steady_clock::now();

const int nax = 2e5 + 10;

void solve()
{
	int n;
	cin >> n;
	string s;
	ll ans = 0;
	map<string, int> M;
	while (n--)
	{
		cin >> s;
		sort(s.begin(), s.end());
		ans += M[s];
		M[s]++;
	}
	cout << ans;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int t = 1;
#ifdef multitest
	cin >> t;
#endif
	while (t--)
		solve();
#ifdef WIN32
	cerr << "\n\nTime elapsed: " << chrono::duration<double>(chrono::steady_clock::now() - TimeStart).count() << " seconds.\n";
#endif
	return 0;
}

Measured memory_bytes: 11264
// #pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,a,b) for(int i=(a);i<(b);++i)

template<class T> inline void chmin(T& a, T b) {if (a > b) a = b;}
template<class T> inline void chmax(T& a, T b) {if (a < b) a = b;}



// vector<vector<int>> memo(1e5+1,vector<int> (1e5+1,0));
// long long gcd(long long a,long long b){
//   if (memo[a][b]) return memo[a][b];
//   else if (b) {
//     if (memo[b][a%b]) return memo[b][a%b]; 
//     else return gcd(b,a%b);
//     }
//   else return a;
//   }

ll mod = 1e9+7;
ll mypow(ll _x, ll _n) {
	ll ret = 1;
	while(0 < _n){
		if((_n % 2) == 0){
			_x *= _x;
      _x%=mod;
			_n >>= 1;
		}
		else{
			ret *= _x;
      ret%=mod;
			--_n;
		}
	}
	return ret;
}

int main() {
  ll N,K;
  cin >> N >> K;
  vector<ll> to(K+1);

  ll ans = 0,tmp;
  for(ll i=K;i>0;i--) {
    auto k = i;
    tmp=mypow(K/i,N)%mod;
    while (k+i<=K) {
      k+=i;
      tmp -= to[k];
    }
    to[i] = tmp;
    ans += i*tmp%mod;
    ans%=mod;
  }
  if (ans<0) {
    ans = ans-ans/mod*mod+mod;
  }
  cout << ans%mod << endl;
}

Measured memory_bytes: 4052
using System;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            MainStream();
        }
        static void MainStream()
        {
            int n = int.Parse(Console.ReadLine());

            if (n%2==0)
            {
                Console.WriteLine(n);
            }
            else
            {
                Console.WriteLine(n * 2);
            }
        }
    }
}


Measured memory_bytes: 11092
#!/usr/bin/env ruby

def solve
  n = gets
  ary = gets.split(' ').map &:to_i
  odd = []
  even = []

  ary.each_with_index do |e, i|
    if (i+1).even?
      even << e
    else
      odd << e
    end
  end

  if ary.length.even?
    puts (even.reverse + odd).join(' ')
  else
    puts (odd.reverse + even).join(' ')
  end
end

if $0 == __FILE__
  solve
end


Measured memory_bytes: 27672
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in)) {
            int secs = sc.nextInt();
            int hh = secs / (60 * 60);
            int hs = secs % (60 * 60);
            int mm = hs / 60;
            int ss = hs % 60;
            System.out.println(String.format("%d:%d:%d", hh, mm, ss));
        }
    }
}



Measured memory_bytes: 26504
#include <iostream>

using namespace std;

int main()
{
  int a, b;
  cin >> a >> b;
  if (a == 0) cout << "Zero" << endl;
  else if (a > 0) cout << "Positive" << endl;
  else {
    if (b >= 0) cout << "Zero" << endl;
    else {
      if ((b - a + 1) % 2 == 1) cout << "Negative" << endl;
      else cout << "Positive" << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[100001];
int main() {
	int n;
	cin>>n;
	int h[n+1];
	for(int i=1;i<=n;i++)
	{cin>>h[i];

	}
  a[1]=0;
  a[2]=abs(h[2]-h[1]);

  for (int i = 3; i <=n; ++i)
  {
  	a[i]=min(a[i-1]+abs(h[i]-h[i-1]),a[i-2]+abs(h[i]-h[i-2]));
  }
  cout<<a[n]<<endl;

}

Measured memory_bytes: 4364
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#define mp make_pair
#define int long long
#define INF 1e+9
using namespace std;

typedef pair<int,int> POS;
typedef pair<int,POS> P;
int dx[] = {0,1,0,-1},dy[] = {-1,0,1,0};

signed main(){
	int w,h,m,q,px[100],py[100],qx[100],qy[100];
	bool ng[210][210][4] = {};
	vector<int> xs,ys;
	cin >> w >> h >> m;
	for(int i = 0;i < m;i++){
		cin >> px[i] >> py[i] >> qx[i] >> qy[i];
		if(px[i] > qx[i]) swap(px[i],qx[i]);
		if(py[i] > qy[i]) swap(py[i],qy[i]);
		xs.push_back(px[i]);
		ys.push_back(py[i]);
		xs.push_back(qx[i]);
		ys.push_back(qy[i]);
	}
	xs.push_back(0);
	xs.push_back(w);
	ys.push_back(0);
	ys.push_back(h);
	sort(xs.begin(),xs.end());
	sort(ys.begin(),ys.end());
	xs.erase(unique(xs.begin(),xs.end()),xs.end());
	ys.erase(unique(ys.begin(),ys.end()),ys.end());
	for(int i = 0;i < xs.size() - 1;i++){
		for(int j = 0;j < ys.size() - 1;j++){
			for(int k = 0;k < m;k++){
				if(px[k] <= xs[i] && xs[i + 1] <= qx[k]){
					if(ys[j] == py[k]) ng[i][j][0] = true;
					else if(ys[j + 1] == py[k]) ng[i][j][2] = true;
				}else if(py[k] <= ys[j] && ys[j + 1] <= qy[k]){
					if(xs[i] == px[k]) ng[i][j][3] = true;
					else if(xs[i + 1] == px[k]) ng[i][j][1] = true;
				}
			}
		}
	}
	cin >> q;
	for(int i = 0;i < q;i++){
		int sx,sy,gx,gy,x1,y1,x2,y2,d[210][210];
		cin >> sx >> sy >> gx >> gy;
		for(int j = 0;j <= 200;j++){
			for(int k = 0;k <= 200;k++) d[j][k] = INF;
		}
		for(int j = 0;j < xs.size() - 1;j++){
			if(xs[j] <= sx && sx <= xs[j + 1]) x1 = j;
			if(xs[j] <= gx && gx <= xs[j + 1]) x2 = j;
		}
		for(int j = 0;j < ys.size() - 1;j++){
			if(ys[j] <= sy && sy <= ys[j + 1]) y1 = j;
			if(ys[j] <= gy && gy <= ys[j + 1]) y2 = j;
		}
		priority_queue<P,vector<P>,greater<P> > que;
		que.push(mp(0,mp(x1,y1)));
		d[x1][y1] = 0;
		while(!que.empty()){
			P p = que.top();que.pop();
			int x = p.second.first,y = p.second.second;
			for(int j = 0;j < 4;j++){
				int nx = x + dx[j],ny = y + dy[j];
				if(nx >= 0 && nx < xs.size() - 1 && ny >= 0 && ny < ys.size() - 1 && d[nx][ny] > d[x][y] + ng[x][y][j]){
					d[nx][ny] = d[x][y] + ng[x][y][j];
					que.push(mp(d[nx][ny],mp(nx,ny)));
				}
			}
		}
		cout << d[x2][y2] << endl;
	}
}

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

vector<int> adj[605];
vector<ii> edges;
double sum[605], p[605], e[605];


int main(){

    int n, m; cin >> n >> m;
    for(int i = 0; i < m; i++){
        int u, v; cin >> u >> v;
        edges.push_back({u, v});
        adj[u].push_back(v);
    }
    
    p[1] = 1;
    for(int u = 1; u <= n; u++)
        for(int v : adj[u])
            p[v] += p[u]/adj[u].size();
    e[n] = 1;
    for(int u = n; u >= 1; u--){
        for(int v : adj[u])
            sum[u] += e[v];
        if(adj[u].size())
            e[u] = sum[u]/adj[u].size() + 1;
    }
    
    double res = e[1];
    // printf("%.6f\n", res);
    // return 0;

    for(ii par : edges){
        int u = par.first, v = par.second;
        if(adj[u].size() == 1) continue;
        double aux = (sum[u] - e[v])/(adj[u].size() - 1) + 1;
        double delta = e[1] + (aux - e[u])*p[u];
        res = min(res, delta);
    }
    printf("%.6f\n", res-1);
	return 0;
}

Measured memory_bytes: 3180
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define repp(i, m, n) for(int i = m, i##_len = (n); i < i##_len; ++i)
#define reprev(i, n) for(int i = (n-1LL); i >= 0; --i)
#define all(x) (x).begin(), (x).end()
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; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vector<int> p(m);
    vector<string> s(m);
    rep (i, m) {
        cin >> p[i] >> s[i];
        p[i]--;
    }
    vector<bool> aced(n);
    vector<int> wa(n);
    rep (i, m) {
        if (s[i] == "AC") aced[p[i]] = true;
        if (s[i] == "WA" && aced[p[i]] == false) wa[p[i]]++;
    }
    int ans = 0, pen = 0;
    rep (i, n) {
        if (aced[i]) {
            ans++;
            pen += wa[i];
        }
    }
    rep (i, n) eprintf("%d %d\n", 1*aced[i], wa[i]);
    cout << ans << " " << pen << "\n";
    return 0;
}

Measured memory_bytes: 6528
import sys
#input = sys.stdin.readline
input = sys.stdin.buffer.readline

# mod=10**9+7
# rstrip().decode('utf-8')
# map(int,input().split())
#import numpy as np

from itertools import permutations
import math


def main():
	n=int(input())
	li=[list(map(int,input().split())) for _ in range(n)]

	nsum=math.factorial(n)

	ans=0
	tmp=0

	for i in permutations(range(n),n):
		tmp=0
		for j in range(n-1):
			x0=li[i[j]][0]
			x1=li[i[j+1]][0]
			y0=li[i[j]][1]
			y1=li[i[j+1]][1]
			tmp+=((x0-x1)**2+(y0-y1)**2)**0.5
		ans+=tmp/nsum
	print(ans)


if __name__ == "__main__":
	main()


Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

typedef long long ll;
const ll oo = 0x3f3f3f3f3f3f3f3fll;
const int maxn = 2020;
ll Min[maxn][maxn];
ll s[maxn];
ll a[maxn];
int n , m , X;
int main(){
	ios::sync_with_stdio(0);
	cin >> n >> X;
	m = 1;
	for(int i = 1 ; i <= n ; ++ i)
		cin >> a[i];
	for(int i = 1 ; i <= n ; ++ i){
		Min[i][i] = a[i];
		for(int j = i + 1 ; j <= n ; ++ j)
			Min[i][j] = min(Min[i][j - 1] , a[j]);
	}
	for(int i = 1 ; i <= n ; ++ i)
		for(int j = 1 ; j <= n ; ++ j){
			ll t;
			if(j < i)
				t = min(Min[1][j] , Min[n + 1 + j - i][n]);
			else
				t = Min[j - i + 1][j];
			s[i - 1] += t;
		}
	while(m --){
//		cin >> X;
		ll ans = oo;
		for(int i = 0 ; i < n ; ++ i)
			ans = min(1ll * X * i + s[i] , ans);
		cout << ans << endl;
	}
	return 0;
}

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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define FILLl(n,first_dimension_size,value) fill((ll*)n,(ll*)(n+first_dimension_size),value)
#define FILL(n,first_dimension_size,value) fill((int*)n,(int*)(n+first_dimension_size),value)
#define INF (1 << 30)
#define MOD 1000000007
//int dy[4] = {-1,0,0,1};
//int dx[4] = {0,1,-1,0};



int main(){
  
  int n;
  cin >> n;
  vector<ll> v(1000000,0),u(1000000,0);
  for(ll i= 1;i <= n;i++){
    ll a;cin >> a;
    if(a+i < 1000000)v[a+i]++;
    if(i-a >= 0 && i-a != a+i)u[i-a]++;
  }
  ll res = 0;
  rep(i,1000000)res += v[i]*u[i];
  cout << res << endl;

  
  


  

  return 0;
}

Measured memory_bytes: 18792