akhauriyash/Code-Regression huggingface dataset:
/*Floyd算法，求解多源最短路，临界矩阵存图，三个大for跑遍天下*/
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
const ll inf=1LL<<32;  //inf得足够大！不然会wa。。。
ll dis[110][110],i,j,k,n,m,a,b,w,flag;//要用long long
void Floyd()
{
	for(k=0; k<n; k++)
		for(i=0; i<n; i++)
			for(j=0; j<n; j++)
				if(dis[i][k]<inf&&dis[k][j]<inf) //必须写这个判断条件
					dis[i][j]=min(dis[i][j],dis[i][k]+dis[k][j]);
}
int main()
{
	while(scanf("%lld%lld",&n,&m)!=EOF)
	{
		flag=0;
		for(i=0; i<n; i++)
			for(j=0; j<n; j++)
				if(i==j) dis[i][j]=0;
				else dis[i][j]=inf;
		for(i=0; i<m; i++)
		{
			scanf("%lld%lld%lld",&a,&b,&w);
			if(dis[a][b]>w)
			{
				dis[a][b]=w;
				//dis[b][a]=w;  //注意这个题是有向图,不用双向输入！
			}
		}
		Floyd();
		for(i=0; i<n; i++)
			if(dis[i][i]<0)//说明存在负环！
			{
				flag=1;
				break;
			}
		if(flag)
		{
			printf("NEGATIVE CYCLE\n");
			continue;
		}
		for(i=0; i<n; i++)
		{
			for(j=0; j<n; j++)
			{
				if(j) printf(" ");//emmmm...PE
				if(dis[i][j]==inf) printf("INF");
				else printf("%lld",dis[i][j]);
			}
			printf("\n");
		}
	}
	return 0;
}


Measured memory_bytes: 2812
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef priority_queue<int> PQ;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;



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

	int N, K;
	cin >> N >> K;
	string S;
	cin >> S;

	int ans = 0;

	REP(i, N - 1) {
		if (S[i] == S[i + 1])ans++;
	}
	cout << min(ans + 2 * K, N - 1) << endl;
	return 0;
}



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

typedef long long ll; 
const int up=1000005; 

int main(){
	string s; ll k; cin>>s>>k; 
	int p=1; while(p<=s.size() && s[p-1]=='1') p++;
	if(k<p) cout<<1; 
	else cout<<s[p-1];  
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
a,b,k=map(int,input().split())
ans=[]
for i in range(k):
    if a+i<=b:
        ans.append(a+i)
for i in range(k):
    if ans[-1]<b-k+i+1<=b:
        ans.append(b-k+i+1)
for i in ans:
    print(i)


Measured memory_bytes: 38384
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
using namespace std;
int main() {
	int n;
	double v[50];
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> v[i];
	}
	sort(v, v + n);
	for (int j = 0; j < n - 1; j++) {
		v[0] = (v[0] + v[1]) / 2;
		v[1] = 1001;
		sort(v, v + n);
	}
	cout << fixed;
	cout << setprecision(5) << v[0] << endl;
	return 0;
}


Measured memory_bytes: 256
import java.io.File;
import java.io.FileInputStream;
import java.util.Scanner;
import java.util.Map.Entry;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.NoSuchElementException;

public class Main {
	
	public static void main(String[] args) throws IOException {
		FastScanner sc = new FastScanner(System.in);
		
		int N = sc.nextInt();
		int[] a = new int[N];
		for(int i = 0; i < N; i++){
			a[i] = sc.nextInt();
		}
		
		long min = Long.MAX_VALUE;
		for(int x = -100; x <= 100; x++){
			long m = 0;
			for(int i = 0; i < N; i++) m += (a[i] - x) * (a[i] - x);
			min = Math.min(min, m);
		}
		System.out.println(min);
	}
}

class FastScanner {
    private InputStream in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    public FastScanner(InputStream in) {
		this.in = in;
	}
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() {
    	if (hasNextByte()) return buffer[ptr++];
    	else return -1;
    }
    private static boolean isPrintableChar(int c){
    	return 33 <= c && c <= 126;
    }
    public boolean hasNext() {
    	while(hasNextByte() && !isPrintableChar(buffer[ptr]))
    		ptr++; return hasNextByte();
    }
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() {
    	return Double.parseDouble(next());
    }
}

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

using ll = long long;

#define dump(x) cerr << #x << "=" << x << endl
#define dump2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define dump3(x, y, z)                                                     \
  cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z \
       << endl
#define check(s) cerr << s << endl

#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define unique(v) v.erase(unique(v.begin(), v.end()), v.end());

vector<int> dx = {0, 1, 0, -1};
vector<int> dy = {1, 0, -1, 0};

const ll LINF = 2e18;
const int INF = 1e9;

void solve(ll N, std::vector<ll> A) {
  ll cnt = 0;

  sort(all(A));
  ll mx = A.at(N - 1);
  vector<bool> dp(mx + 1, true);

  set<ll> dup;
  rep(i, N - 1) {
    if (A.at(i) == A.at(i + 1)) {
      dup.insert(A.at(i));
    }
  }

  rep(i, N) {
    ll j = 2;
    while (j * A.at(i) <= mx) {
      dp.at(j * A.at(i)) = false;
      j++;
    }

    if (!dup.count(A.at(i)) && dp.at(A.at(i))) cnt++;
  }

  cout << cnt << endl;
}

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


Measured memory_bytes: 5908
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pl = pair<ll,ll>;
using pi = pair<int,int>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
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; }
//(a+b-1)/b
//priority_queue<ll, vector<ll>, greater<ll>> q;


template<int MOD> struct Fp {  
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) val += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr Fp operator - () const noexcept {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
        return os << x.val;
    }
    friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
};
using mint = Fp<MOD>;

mint C(ll n ,ll k){
	mint ret = 1;
	mint div = 1;
	for(ll i = 0; i < k; i++){
		ret *= (n - i);
		div *= (k - i);
	}
	ret /= div;
	return ret;
}

signed main(){
	//cout << fixed << setprecision(10);
    ll n; cin >> n;
	ll cnt = 1;
	mint ans = 0;
	while(true){
		if(cnt * 3 > n)break;
		ans += C(n - 3 * cnt + cnt - 1 , cnt - 1);
		cnt++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3632
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <stdlib.h>

typedef long double ld;
typedef long long ll;

using namespace std;

#define MOD 1000000007

int f(ll n, ll k) {
	ll low = (k * (k - 1)) / 2;
	low %= MOD;
	ll up = (n * (n + 1) - (n - k) * (n - k + 1)) / 2;
	up %= MOD;
	int ret = (up - low  + 1 + MOD) % MOD;
	return ret;

}

int main() {
	int n, k;
	cin >> n >> k;
	int ret = 0;
	for (int i = k; i <= n + 1; i++) {
		ret += f(n, i);
		ret %= MOD;
	}
	cout << ret << endl;
	return 0;
}


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

int main() {
  int n, x, y;
  cin >> n >> x >> y;
  x --, y --;

  vector<int> a(n);
  for (int i = 0; i < n; i ++) {
    for (int j = i + 1; j < n; j ++) {
      int t = min({j - i, abs(j - x) + 1 + abs(y - i), abs(j - y) + 1 + abs(x - i)});
      a[t] ++;
    }
  }

  for (int i = 1; i < n; i ++) {
    cout << a[i] << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr<<#x<<": "<<x<<endl


struct edge{
    int to;
    int cost;
};

vector<vector<edge>> graph(100005);
vector<int> bw(100005,-1);

void addEdge(int from, int to, int cost) {
    edge e;
    e.to = to;
    e.cost = cost;
    graph[from].push_back(e);
}

void dfs(int is_black, int from){
    bw[from] = is_black;
    for(int i = 0; i < graph[from].size(); i++){
        if(bw[graph[from][i].to] == -1){
            if(graph[from][i].cost%2==0){
                dfs(is_black, graph[from][i].to);
            }else{
                dfs((is_black+1)%2, graph[from][i].to);
            }
        }
    }
    return;
}

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

    for(int i = 0; i < n-1; i++){
        int u, v, w;
        cin >> u >> v >> w;
        u--;
        v--;
        addEdge(u,v,w);
        addEdge(v,u,w);
    }

    dfs(0, 0);
    for(int i = 0; i < n; i++){
        cout << bw[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 8448
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
 
#define pb push_back
#define fs first
#define se second
#define M 1000000007
ll exp(ll a,ll p)
{
	if(p==1)
		return a;
	if(p==0)
		return 1;
	ll st=exp(a,p/2);
	st=(st*st)%M;
	if(p%2 != 0)
		st=(st*a)%M;
	return st;
} 
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll a,b,c;
	cin>>a>>b;
	c=6;
	cout<<c-a-b<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)

#define PB push_back
#define MP make_pair
#define ALL(a) (a).begin(),(a).end()
#define PII pair<int,int>
#define VS vector<string>
#define VI vector<int>
#define ll long long
#define ull unsigned long long
#define FST first
#define SEC second
int main(){
  while(1){
    int d,e;
    cin>>d>>e;
    if(d+e==0)break;
    vector<double>V;
    REP(i,d+1)V.PB(abs(sqrt(i*i+(d-i)*(d-i))-(double)e));
    sort(ALL(V));
    printf("%.5f\n",V[0]);
  }
  return 0;
}

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

int main(){
  int a, b;
  cin >> a >> b;
  if(a%3==0||b%3==0||(a+b)%3==0){
    cout << "Possible";
  }
  else{
    cout << "Impossible";
  }
  cout << endl;
  return 0;
}

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

using namespace std;

typedef long long ll;
#define INF 100000000
#define MOD 1000000007

int main()
{
	int a, n, black;
	
	cin >> n >> a;

	black = (n * n) - a;

	cout << black << endl;

	return (0);
}

Measured memory_bytes: 256
#pragma Grem optimize ("O3")
#include <bits/stdc++.h>

using namespace std ;

#define sz(v) (int)v.size()
#define ll long long
#define all(v)  v.begin() , v.end()
#define rall(v)  v.rbegin() , v.rend()
#define pf push_front
#define pb push_back
#define fast FastInputOutput() ;
#define Clear( container , value ) memset( container , value , sizeof container )
#define PI acos( -1.0 )
#define forn( t , v , be , n ) for( t v = be ; v < n ; v++ )
#define fore( x , j ) for( auto x : j )
#define se second
#define fr first
//#define c_b fflush(stdin);

const ll Long_max = numeric_limits < ll > :: max() ;
const int Int_max = numeric_limits < int > :: max() ;

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

void File_input( string pathIn ) {
    freopen( pathIn.c_str(), "r", stdin ) ;
}

void File_output( string pathOut ) {
    freopen( pathOut.c_str(), "w", stdout ) ;
}

int msg() {
    srand( time( 0 ) ) ;
    vector < string > st = {
        "Wish everyone high ratings!",
        "Good luck!",
        "Have fun!",
        "Please, read all the problems!",
        "Go Go fight!"
    } ;
    cerr << st[ rand() % sz( st ) ] ;
    return 0 ;
}


void FastInputOutput() {
    ios_base :: sync_with_stdio( 0 ) ;
    cin.tie( 0 ) ;
    cout.tie( 0 ) ;
}

int init ;
string sm ;

int main(){
   cin >> sm ;
   fore( i , sm ){
     if( i == '+' ) init++ ;
     else if( i == '-' ) init-- ;
   }
   cout << init ;
   return 0 ;
}




Measured memory_bytes: 256
func solve(_ arr: [Int], _ n: Int, _ k: Int) -> [String] {
    var left = 0, right = k
    var res = [String]()
    while right < n {
        if arr[left] >= arr[right] {
            res.append("No")
        } else {
            res.append("Yes")
        }
        left += 1
        right += 1
    }
    return res
}



let nk = readLine()!.split(separator: " ").map { Int($0)! }
let n = nk[0], k = nk[1]
let arr = readLine()!.split(separator:" ").map { Int($0)! }

print(solve(arr, n, k).joined(separator: "\n"))


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

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

#define int long long
#define endl '\n'
const int N = 100001;
int n;
int h[N];
signed main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cin >> n;
	for(int i = 1 ; i <= n ; i ++)
		cin >> h[i];
	for(int i = 1 ; i <= n ; i ++){
		if(h[i] > h[i - 1]) h[i] --;
		else if(h[i] == h[i - 1]) continue;
		else return cout << "No", 0;
	}
	cout << "Yes";
}


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

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define INF  numeric_limits<int>::max()
#define NINF numeric_limits<int>::min()

#define N_MAX 2000000
#define M_MAX 2000000

using namespace std;
using ll = long long;

int n, m;

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

    std::cin >> n >> m;
    set<int> or_s;
    vector<int> and_v;
    REP(i, n) {
        int a;
        std::cin >> a;
        or_s.insert(a);
    }
    REP(i, m) {
        int b;
        std::cin >> b;
        auto itr = or_s.find(b);
        if(itr != or_s.end()) {
            and_v.push_back(b);
        }
        or_s.insert(b);
    }

    std::cout << and_v.size()
              << " "
              << or_s.size() << std::endl;
    REP(i, and_v.size()) {
        std::cout << and_v[i] << std::endl;
    }
    for(auto s : or_s) {
        std::cout << s << std::endl;
    }

    return 0;
}



Measured memory_bytes: 13280
#include<iostream>
#include<string>
#include<algorithm>
#include<functional>
#include<cctype>

using namespace std;

int main()
{
	string s1;
	getline(cin, s1);
	for (int i = 0; i < s1.length(); i++) {
		if (islower(s1[i])) cout << static_cast<char>(toupper(s1[i]));
		else if (isupper(s1[i])) cout << static_cast<char>(tolower(s1[i]));
		else cout << s1[i];
	}
	cout << "\n";
}

Measured memory_bytes: 1180
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
//ll mod = 998244353;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main() {
    double a, b, x;
    cin >> a >> b >> x;
    if (a * a * b / (double)2 == x) {
        printf("%.7lf\n", atan(b/a) * (double)360 / ((double)2 * M_PI));
    }
    else if (a * a * b / (double)2 > x) {
        double h = x * (double)2 / b / a;
        printf("%.7lf\n", atan(b/h) * (double)360 / ((double)2 * M_PI));
    }
    else {
        double c = x * (double)2 / a / a - b;
        printf("%.7lf\n", atan((b-c)/a) * (double)360 / ((double)2 * M_PI));
    }
    return 0;
}


Measured memory_bytes: 4092
from collections import deque
import copy
H,W = map(int, input().split())
s=[list(input()) for i in range(H)]
#H,W=3,3
#s=[['.', '.', '#'], ['#', '.', '.'], ['.', '.', '.']]

ss=copy.deepcopy(s)
q=deque([[0,0]])#(H,W)
ss[0][0]=0
move=[[1,0],[0,1],[0,-1],[-1,0]]
num=0
t=False
while q:
    num+=1
    for i in range(len(q)):
        b=q.popleft()
        #print(b)
        if b==[H-1,W-1]:
            t=True
            num-=1
            break
        for m in move:
         #  print(m)
            if 0<=b[0]+m[0]<=H-1 and 0<=b[1]+m[1]<=W-1 and ss[b[0]+m[0]][b[1]+m[1]]=='.':
                ss[b[0]+m[0]][b[1]+m[1]]=num
                q.append([b[0]+m[0],b[1]+m[1]])
    else:
        continue
    break
if not t :
    print('-1')
else:
    x=num
    b=H-1,W-1
    ss[b[0]][b[1]]='#'
    while x!=0:
        for m in move:
            if 0<=b[0]+m[0]<=H-1 and 0<=b[1]+m[1]<=W-1 and ss[b[0]+m[0]][b[1]+m[1]]==x-1:
                x=x-1
                ss[b[0]+m[0]][b[1]+m[1]]='#'
                b=b[0]+m[0],b[1]+m[1]
                break
    ans=0
    for h in range(H):
        for w in range(W):
            if ss[h][w]!='#':
                ans+=1
    print(ans)

Measured memory_bytes: 9624
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pli pair<ll,int>
#define fi first
#define se second
#define inf (INT_MAX/2-1)
#define infl (1LL<<60)
#define vi vector<int>
#define vl vector<ll>
#define vvl vector<vl>
#define pb push_back
#define sz(a) (int)(a).size()
#define all(a) begin(a),end(a)
#define y0 y5656
#define y1 y7878
#define aaa system("pause");
#define dbg(x) cerr<<(#x)<<": "<<(x)<<'\n',aaa
#define dbga(x,n) cerr<<(#x)<<"[]: ";for(int _=0;_<n;_++)cerr<<x[_]<<' ';cerr<<'\n',aaa
#define dbgs(x) cerr<<(#x)<<"[stl]: ";for(int _:x)cerr<<_<<' ';cerr<<'\n',aaa
#define dbgp(x) cerr<<(#x)<<": "<<x.fi<<' '<<x.se<<'\n',aaa

using namespace std;

const ll mod = 1000000007;
vvl v;
vvl p2[63];

vvl mul (vvl a, vvl b) {
  int n = sz(a), i, j, z;
  vvl c(n);
  for (i = 0; i < n; i++) c[i].resize(n);
  for (i = 0; i < n; i++)
    for (j = 0; j < n; j++)
      for (z = 0; z < n; z++) c[i][j] = (c[i][j] + (a[i][z]*b[z][j])%mod) % mod;
  return c;
}

int main () {
  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  int n; ll k; cin >> n >> k;
  int i, j, z;
  v.resize(n);
  for (i = 0; i < n; i++) v[i].resize(n);
  for (i = 0; i < n; i++)
    for (j = 0; j < n; j++) cin >> v[i][j];
  p2[0] = v; int m = 1;
  while ((1LL<<m) <= k) {
    p2[m] = mul(p2[m-1], p2[m-1]);
    m++;
  }
  vvl u;
  while (m >= 0 && (k & (1LL<<m)) == 0) m--;
  for (u = p2[m--]; m >= 0; m--)
    if (k & (1LL<<m)) u = mul(u, p2[m]);
  ll ans = 0;
  for (i = 0; i < n; i++)
    for (j = 0; j < n; j++) ans = (ans + u[i][j]) % mod;
  cout << ans;
  return 0;
}


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

int n;
string s;
bool ans[100010];

bool is_ok(bool is_sheep1,bool is_sheep2) {
    ans[0]=is_sheep1;
    ans[1]=is_sheep2;
    for (int i=1;i<=n;i++) {
        bool flag=((s[i%n]=='o') ^ ans[i]);
        if (flag) ans[i+1]=!ans[i-1];
        else ans[i+1]=ans[i-1];
    }
    if (ans[0]==ans[n] && ans[1]==ans[n+1]) return 1;
    else return 0;
}

int main() { 
    cin >> n;
    cin >> s;
    bool is_sheep1[4] = {true,true,false,false};
    bool is_sheep2[4] = {true,false,true,false};
    for (int i=0;i<4;i++) {
        bool flag=is_ok(is_sheep1[i],is_sheep2[i]);
        if (flag) {
            for (int j=0;j<n;j++) {
                if (ans[j]) cout << 'S';
                else cout << 'W';
            }
            cout << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 764
var lines = [];

var readline = require('readline');

var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
});

rl.on('line', function (x) {
    lines.push(x);
});

rl.on('close', function () {
    var N = Number(lines[0]);
    lines.shift();

    var S = lines.map(i => i.split(""));
    var count = {};
    var ans = 0;

    for (var i = 0; i < N; i++) {
        if (S[i][0] === "M" || S[i][0] === "A" || S[i][0] === "R" || S[i][0] === "C" || S[i][0] === "H") {
            if (count[S[i][0]] === undefined) { count[S[i][0]] = 1; }
            else { count[S[i][0]]++; }
        }
    }

    var m = (count["M"] === undefined ? 0 : count["M"]);
    var a = (count["A"] === undefined ? 0 : count["A"]);
    var r = (count["R"] === undefined ? 0 : count["R"]);
    var c = (count["C"] === undefined ? 0 : count["C"]);
    var h = (count["H"] === undefined ? 0 : count["H"]);
    

    ans += m * a * r; ans += m * a * c; ans += m * a * h;
    ans += m * r * c; ans += m * r * h;
    ans += m * c * h;
    ans += a * r * c; ans += a * r * h;
    ans += a * c * h;
    ans += r * c * h;

    console.log(ans);
});


Measured memory_bytes: 51724
X, Y = input().split(' ')
lis = ['A', 'B', 'C', 'D', 'E', 'F']
X_num = lis.index(X)
y_num = lis.index(Y)

if X_num == y_num:
    print('=')
elif X_num < y_num:
    print('<')
else:
    print('>')

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
typedef long long LL;
int N;

int main(){
	string T;
	cin>>T;
	REP(i,T.size()){
		if(T[i]=='?'){
			cout<<"D";
		}else{
			cout<<T[i];
		}
	}
	cout<<endl;
}

Measured memory_bytes: 3724
#include <iostream>
#include <vector>
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if( a > b ){ a=b; return 1; } return 0; }
template<class T> inline bool chmax(T& a, T b) { if( a < b ){ a=b; return 1; } return 0; }

int main() {
    // INPUT
    int N=0, W=0;
    cin >> N >> W;
    vector<vector<long long>> product(N, vector<long long>(2));
    for(int i=0; i<N; i++) {
        cin >> product[i][0] >> product[i][1];
    }

    // SOURCE
    vector<vector<long long>> dp_value(N+1, vector<long long>(W+1, 0));
    for(int i=1; i<N+1; i++) {
        for(int j=0; j<W+1; j++) {
            long long weight = j + product[i-1][0];
            if(W >= weight) chmax(dp_value[i][weight], dp_value[i-1][j]+product[i-1][1]);
            chmax(dp_value[i][j], dp_value[i-1][j]);
        }
    }

    // OUTPUT
    cout << dp_value[N][W] << endl;

    return 0;
}

Measured memory_bytes: 80256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int h,w,n;
int a[10005];
int ans[105][105];
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
bool check(int x,int y){
    return x>=1&&x<=h&&y>=1&&y<=w&&!ans[x][y];
}
int main(){
    scanf("%d%d%d",&h,&w,&n);
    for(int i=1;i<=n;i++)scanf("%d",a+i);
    int now=1;
    int x=1,y=1,o=0;
    while(now<=n){
        while(now<=n&&a[now]==0)now++;
        if(now>n)break;
        ans[x][y]=now;a[now]--;
        if(!check(x+dx[o],y+dy[o]))o=(o+1)%4;
        x+=dx[o],y+=dy[o];
    }
    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++)printf("%d ",ans[i][j]);
        printf("\n");
    }
    return 0;
}

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

int main(){
    cout<<fixed<<setprecision(10);
    int n; cin >> n;
    double A[n]; for(int i = 0; i < n; i++) cin >> A[i];
    double sum = 0;
    for(int i = 0; i < n; i++){
        sum += 1 / A[i];
    }
    cout << 1 / sum;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using System.Numerics;
namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var N = long.Parse(Console.ReadLine());
            long sum = 0;
            long i = 1;
            if(N%2 == 0)
            {
                while (true)
                {
                    if (N / (long)Math.Pow(5, i) > 0) { sum += N / (long)Math.Pow(5, i) / 2; }
                    else { break; }
                    i++;
                }
                Console.WriteLine(sum);
            }
            else { Console.WriteLine("0"); }
        }
        
    }

}

Measured memory_bytes: 11092
import java.util.*

fun main(args: Array<String>) {
    Scanner(System.`in`).use { sc ->
        val n = sc.nextInt()
        val a = sc.nextInt()
        val b = sc.nextInt()

        println((1..n).asSequence().filter{it.toString().toCharArray().map { c -> c.toString().toInt() }.sum() in a..b }.sum())
    }
}


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

int main() {
    int A, B, C, D, E, F;
    std::cin >> A >> B >> C >> D >> E >> F;

    double max_den = -1;
    int max_w = 0, max_s = 0;
    for (int i = 0; i <= F / (100 * A); ++i) {
        for (int j = 0; j <= F / (100 * B); ++j) {
            for (int k = 0; k <= F / C; ++k) {
                for (int l = 0; l <= F / D; ++l) {
                    const int w = 100 * A * i + 100 * B * j;
                    const int s = C * k + D * l;

                    if (((w * E / 100.0) < s) || ((w + s) > F)) {
                        continue;
                    } 

                    const double den = 100.0 * s / (w + s);
                    if (max_den < den) {
                        max_den = den;
                        max_w = w;
                        max_s = s;  
                    }
                }
            }    
        }
    }

    std::printf("%d %d\n", max_w + max_s, max_s);
    
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

		while (true) {
			int total = 0;
			String str = scanner.next();
			if (str.equals("0")) {
				break;
			}
			for (int i = 0; i < str.length(); i++) {
				total = total + Character.getNumericValue(str.charAt(i));
			}
			System.out.println(total);

		}
	}
}



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

struct vec{
	long double x , y;
	vec(long double _x = 0 , long double _y = 0){x = _x; y = _y;}
	friend vec operator +(vec a , vec b){return vec(a.x + b.x , a.y + b.y);}
	friend vec operator -(vec a , vec b){return vec(a.x - b.x , a.y - b.y);}
	friend long double operator *(vec a , vec b){return a.x * b.x + a.y * b.y;}
	friend vec operator *(vec a , long double b){return vec(a.x * b , a.y * b);}
	long double len(){return sqrt(x * x + y * y);}
};

vec getvec(){int x , y; cin >> x >> y; return vec(x , y);}

int main(){
	vec A = getvec() , B = getvec(); B = B - A; int Q;
	for(cin >> Q ; Q ; --Q){
		vec Q = getvec() - A;
		long double T = Q * B / B.len();
		vec ans = (A + B * (T / B.len())) * 2 - (A + Q);
		cout << fixed << setprecision(10) << ans.x << ' ' << ans.y << endl;
	}
	return 0;
}



Measured memory_bytes: 3256
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <utility>

using namespace std;

int main() {
  int R, C, K;
  cin >> R >> C >> K;
  map <pair <int, int>, long long> value;
  for (int i = 0; i < K; ++i) {
    int r, c;
    long long v;
    cin >> r >> c >> v;
    r--;
    c--;
    value[make_pair(r, c)] = v;
  }
  
  vector <vector <vector <long long> > > dp(R, 
    vector <vector <long long> >(C, 
      vector <long long> (4, -1)
    )
  );

  dp[0][0][0] = 0;
  if (value.find(make_pair(0, 0)) != value.end()) {
    dp[0][0][1] = value[make_pair(0, 0)];
  }
  
  for (int r = 0; r < R; ++r) { 
    for (int c = 0; c < C; ++c) {
      pair <int, int> coord = make_pair(r, c);
      for (int k = 0; k < 4; ++k) {
        if (c - 1 >= 0) 
          dp[r][c][k] = max(dp[r][c][k], dp[r][c - 1][k]);
        if (c - 1 >= 0 && k - 1 >= 0 && dp[r][c - 1][k - 1] >= 0 && 
            value.find(coord) != value.end())
          dp[r][c][k] = max(dp[r][c][k], dp[r][c - 1][k - 1] + value[coord]);
        if (r - 1 >= 0)
          dp[r][c][0] = max(dp[r][c][0], dp[r - 1][c][k]);
        if (r - 1 >= 0 && dp[r - 1][c][k] >= 0 && value.find(coord) != value.end())
          dp[r][c][1] = max(dp[r][c][1], dp[r - 1][c][k] + value[coord]);
      }
    }
  }
  long long ans = 0;
  for (int k = 0; k < 4; ++k) {
    ans = max(dp[R - 1][C - 1][k], ans);
  }
    
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 648832
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cerr << #x << ": " << x << endl

const ll INF = 100000000005;
int main() {
  int a, b, q;
  cin >> a >> b >> q;

  vector<ll> S, T;
  S.push_back(-INF);
  T.push_back(-INF);
  rep(i, a) {
    ll s;
    cin >> s;
    S.push_back(s);
  }
  rep(j, b) {
    ll t;
    cin >> t;
    T.push_back(t);
  }
  S.push_back(INF);
  T.push_back(INF);

  vector<ll> x(q);
  rep(k, q) cin >> x[k];

  rep(k, q) {
    auto lbs = upper_bound(all(S), x[k]);
    auto lbt = upper_bound(all(T), x[k]);

    ll ans = INF;
    for(ll s : {*(lbs - 1), *lbs})
      for(ll t : {*(lbt - 1), *lbt}) {
        ll D[2] = {abs(s - x[k]) + abs(t - s),
                   abs(t - x[k]) + abs(s - t)};
        for(ll d : D) ans = min(ans, d);
      }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 3828
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <stack>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;
template<class T> inline bool chmax(T& a, T b){ if(a < b) { a=b; return 1; }return 0;}
template<class T> inline bool chmin(T& a, T b){ if(a > b) { a=b; return 1; }return 0;}
const long long INF = 1LL << 60;

// --------write my code!!!!!----------//

int main(){
    int N; cin >> N;
    if(N==1) cout << "Hello World";
    else{
        int A,B; cin>>A>>B;
        cout << A+B << endl;
    }
}


Measured memory_bytes: 256
#![allow(non_snake_case)]
#![allow(unused_variables)]
#![allow(dead_code)]

fn main() {
    let N: usize = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().parse().unwrap()
    };
    let p: Vec<usize> = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|x| x.parse().unwrap())
            .collect()
    };

    let c = (0..N).filter(|&i| p[i] != i + 1).count();
    let ans = if c <= 2 { "YES" } else { "NO" };

    println!("{}", ans);
}


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

#define int long long
#define rep(i, n) for (int i = 0; i < (int) (n); i++)
#define reps(i, n) for (int i = 1; i <= (int) (n); i++)
#define all(x) (x).begin(), (x).end()
#define uniq(x) (x).erase(unique(all(x)), (x).end())
#define bit(n) (1LL << (n))
#define cdiv(a, b) (((a) - 1) / (b) + 1)
#define dump(x) cerr << #x " = " << (x) << endl
using vint = vector<int>;
using vvint = vector<vint>;
using pint = pair<int, int>;
using vpint = vector<pint>;
template<typename T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
constexpr double PI = 3.1415926535897932384626433832795028;
constexpr int DY[9] = {0, 1, 0, -1, 1, 1, -1, -1, 0};
constexpr int DX[9] = {1, 0, -1, 0, 1, -1, -1, 1, 0};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
int sign(int x) { return (x > 0) - (x < 0); }
template<typename T> void fin(T mes) {
    cout << mes << endl;
    exit(0);
}
template<typename T, typename U> bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const deque<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const set<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
template<typename T, typename U> ostream &operator<<(ostream &os, const map<T, U> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct setup {
    static constexpr int PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

int N;
int A[110000];
signed main() {
    cin >> N;
    rep(i, N) { cin >> A[i]; }
    sort(A, A + N);
    int s = 0, ans = 0;
    rep(i, N) {
        if (s * 2 < A[i]) { ans = 0; }
        s += A[i];
        ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 4436
#include <stdio.h>
#include <memory.h>
#include <queue>
using namespace std;

queue<int> Q;
char a[22][22];
int h, w, visit[22][22], dy[4] = { -1, 0, 1, 0 }, dx[4] = { 0, 1, 0, -1 };

void bfs(int sy, int sx)
{
	int i, j;

	memset(visit, -1, sizeof(visit));

	Q.push(sy);
	Q.push(sx);
	visit[sy][sx] = 0;
	while (!Q.empty())
	{
		int yy = Q.front(); Q.pop();
		int xx = Q.front(); Q.pop();

		for (i = 0; i < 4; i++)
		{
			int ty = yy + dy[i];
			int tx = xx + dx[i];

			if (ty >= 1 && ty <= h && tx >= 1 && tx <= w && a[ty][tx] == '.' && visit[ty][tx] == -1)
			{
				Q.push(ty);
				Q.push(tx);
				visit[ty][tx] = visit[yy][xx] + 1;
			}
		}
	}
}

int main(void)
{
	int i, j, k, l, ans = 0;

	scanf("%d %d", &h, &w);
	for (i = 1; i <= h; i++)
		scanf("%s", &a[i][1]);

	for (i = 1; i <= h; i++)
		for (j = 1; j <= w; j++)
		{
			if (a[i][j] == '#')
				continue;

			bfs(i, j);

			int max = 0;
			for (k = 1; k <= h; k++)
				for (l = 1; l <= w; l++)
					if (max < visit[k][l])
						max = visit[k][l];

			if (ans < max)
				ans = max;
		}

	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 256
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
using namespace std;
const int N=20,INF=1e9;
int a1[N],a2[N],n,c[N],d[N];
bool b[N];
int slo() {
	for(int i=1;i<=n;i++)
		if(b[i]==1)
			c[i]=a2[i];
		else
			c[i]=a1[i];
	
	for(int i=1;i<=n;i++)
		d[i]=c[i];

	sort(c+1,c+1+n);
	
	int ans=0;
	for(int i=1;i<=n;i++) {
		bool flag=1;
		for(int j=i;j<=n;j++) {
			if(d[j]==c[i] && (j-i+b[j])%2==0) {
				flag=0;
				ans+=j-i;
				for(int k=j;k>i;k--) {
					b[k]=!b[k-1];
					d[k]=d[k-1];
				}
				break;
			}
		}
		if(flag)return -1;
	}
	return ans;
}
int main(){
	
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a1[i];
	for(int i=1;i<=n;i++)
		cin>>a2[i];
	int s=(1<<n)-1;
	int ans=INF;
	for(int i=0;i<=s;i++) {	//1代表翻面 
//		i=6;
		int fl=0;
		for(int j=0;j<n;j++)
			if(i&(1<<j))
				b[j+1]=1,fl++;
			else 
				b[j+1]=0;
		if(fl&1)continue;
		int al=slo();
		if(al!=-1)
			ans=min(ans,al);
	}
	if(ans!=INF)
		printf("%d\n",ans);
	else
		printf("%d\n",-1);
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const long long int M = 1e9 + 7;
int main() {
    long long int n , k , i , j;
    cin >> n >> k;
    long long int a[n+1];
    for(i = 0 ; i < n ; i++) {
        cin >> a[i];
    }
    long long int ans = 0;
    for(i = 0 ; i < n ; i++) {
        long long int c = 0 , d = 0;
        for(j = 0 ; j < i ; j++) {
            if(a[j] > a[i]) {
                c++;
            }
        }
        for(j = 0 ; j < n ; j++) {
            if(a[j] > a[i]) {
                d++;
            }
        }
        ans += c * k +(k*(k-1)/2)%M*d%M;
        ans = ans%M;
    }
    cout << ans << "\n";
}

Measured memory_bytes: 256
# ABC058C - 怪文書 / Dubious Document (ARC071C)
from functools import reduce


def main():
    N = int(input())
    if N == 1:
        print(*sorted(input()), sep="")
        return
    S = tuple(input() for _ in range(N))
    ch = sorted(reduce(lambda a, b: set(a) & set(b), S))
    ans = ""
    for i in ch:
        ans += i * min(s.count(i) for s in S)
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N,M,rs;
    rs = 0;
    vector<int> a,b;
    cin >> N >> M;
    for (int i = 0; i < M; i++){
        int inA,inB;
        cin >> inA >> inB;
        a.emplace_back(inA);
        b.emplace_back(inB);
    }
    //頂点の配列
    vector<int> one_case;
    for (int i = 2; i <= N; i++) { // one_case = {2,3,...N} とする
        one_case.emplace_back(i);
    }
    int ca,cb;
    bool isFind;
    do {
        one_case.emplace_back(1);
        for (int i = 0; i < N-1; i++){
            isFind = false;
            ca = min(one_case.at(i),one_case.at(i+1));
            cb = max(one_case.at(i),one_case.at(i+1));
            for (int j = 0; j<M; j++) {
                if(a.at(j) == ca && b.at(j) == cb){
                    isFind = true;
                    break;
                }
            }
            if (isFind == false){
                break;
            }
            if(i == N-2){
                rs++;
            }
        }
        
        one_case.pop_back();
    } while (next_permutation(one_case.begin(), one_case.end()));
    // 順列の最後になるまで one_case を並び替えながらループ
    cout << rs << endl;
 
    return 0;
}
 


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,C;
int L[10];
int D[10];

double dp[303][32];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>C;
	FOR(i,N) cin>>L[i], D[i]=i;
	sort(L,L+N);
	
	double ret=0;
	do {
		ZERO(dp);
		dp[N*L[N-1]][0]=1;
		FOR(i,N*C) if(i%N) {
			x=D[(i-1)%N];
			for(int mask=0;mask<1<<(N-1);mask++) if((mask&(1<<x))==0) {
				for(y=i;y<=N*C;y++) {
					dp[min(N*C,max(y,i+L[x]*N))][mask ^ (1<<x)] += dp[y][mask];
				}
			}
		}
		
		ret += dp[N*C][(1<<(N-1))-1] ;
	} while(next_permutation(D,D+(N-1)));
	
	FOR(i,N-1) ret/=i+1;
	_P("%.12lf\n",ret/pow(C,N-1));
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 384
#include <iostream>
using namespace std;
int main(void){
	int n;
	int a,b;
	int a1;
	int a2;
	a=0;
	a1=0;
	a2=0;
	cin>>n;
	for(int i=0;i<n;i++){
		cin >> a;
		cin >> b;
		if(a>a1){
			a1=a;
			a2=b;
		}
	}
	cout<<a1+a2;
}

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

int main() {
    vector<int> x(5);
    for (int i = 0; i < 5; i++) cin >> x.at(i);
    for (int i = 0; i < 5; i++){
        if (x.at(i) == 0) cout << i + 1;
    }
    cout << endl;
}


Measured memory_bytes: 3592
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

n, m = map(int, input().split())
abc = [tuple(map(int,input().split())) for i in range(m)]
es = []
for a,b,c in abc:
    a,b = a-1,b-1
    es.append((a,b,c))

INF = float('inf')

def find_negative_loop(n,es,s):
    #負の経路の検出
    #n:頂点数, es[i]: [辺の始点,辺の終点,辺のコスト], s:始点
    dist = [-INF] * n
    dist[s] = 0

    for i in range(n):
        for a,b,c in es:
            if dist[b] < dist[a]+c:
                dist[b] = dist[a]+c
                # if i == n-1: # n回目にも更新が行われている場合，ループが存在する
                if i == n-1 and b==n-1: # 終点に影響を及ぼすループが存在する
                        return INF
    return dist[n-1]

ans = find_negative_loop(n,es,0)

if ans == INF:
    print('inf')
    exit()

print(ans)


Measured memory_bytes: 3572
import math, heapq
from operator import itemgetter as ig
from collections import defaultdict as dd
# 定数
INF = float("inf")
MOD = int(1e9 + 7)
# ヒープ
class heapque:
    def __init__(self, *args):
        self.que = []
        for arg in args:
            self.push(arg)
    def push(self, v):
        heapq.heappush(self.que, v)
    def pop(self):
        return heapq.heappop(self.que)
# 最大公約数 / 最小公倍数
def gcd(v1, v2):
    if v2 == 0:
        return v1
    return gcd(v2, v1 % v2)
def lcm(v1, v2):
    return (v1 // gcd(v1, v2)) * v2
# 二分探索
def bsr(a, v, lo=0, hi=None):
    if hi == None:
        hi = len(a) - 1
    if hi < lo:
        return lo
    mi = (lo + hi) // 2
    if v < a[mi]:
        return bsr(a, v, lo, mi - 1)
    else:
        return bsr(a, v, mi + 1, hi)
# Union-Find木
class uft:
    def __init__(self, n):
        self.height = [1] * n
        self.group = [-1] * n
    def root(self, v):
        if self.group[v] < 0:
            return v
        self.group[v] = self.root(self.group[v])
        return self.group[v]
    def size(self, v):
        return - self.group[self.root(v)]
    def merge(self, v1, v2):
        v1, v2 = self.root(v1), self.root(v2)
        if v1 == v2:
            return
        if self.height[v1] < self.height[v2]:
            self.group[v2] += self.group[v1]
            self.group[v1] = v2
            self.height[v2] = max(self.height[v1] + 1, self.height[v2])
        else:
            self.group[v1] += self.group[v2]
            self.group[v2] = v1
            self.height[v1] = max(self.height[v1] , self.height[v2] + 1)
# グラフ
class graph:
    def __init__(self, n):
        self.n = n
        self.graph = [[] for _ in range(n)]
    def append(self, v1, v2, cost=1):
        self.graph[v1].append((v2, cost))
    # 最短経路：ダイクストラ法(Dijkstra's Algorithm)
    def dks(self, v):
        costs = [INF] * self.n
        costs[v] = 0
        done = [False] * self.n
        heap = heapque((0, v))
        while heap.que:
            c_cost, c_index = heap.pop()
            if done[c_index]:
                continue
            done[c_index] = True
            for n_index, n_cost in self.graph[c_index]:
                if c_cost + n_cost < costs[n_index]:
                    costs[n_index] = c_cost + n_cost
                    heap.push((costs[n_index], n_index))
        return costs

def main():
    N, M = map(int, input().split())
    ab = dd(list)
    for _ in range(N):
        a, b = map(int, input().split())
        ab[a].append(b)

    heap = heapque()
    v = 0
    for m in range(1, M + 1):
        if m in ab:
            for b in ab[m]:
                heap.push(-b)
        if heap.que:
            v += -heap.pop()
    print(v)

main()


Measured memory_bytes: 27656
#include<queue>
#include<cmath>
#include<ctime>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define mem(a,b) memset(a,b,sizeof a)
#define  For(i,a,b) for(int i=a,i##end=b;i<=i##end;++i)
#define rFor(i,a,b) for(int i=a,i##end=b;i>=i##end;--i)
using namespace std;
typedef long long LL;
const int N=100010;
template<typename T>inline T chkmax(T _A,T _B){return _A>_B?_A:_B;}
template<typename T>inline T chkmin(T _A,T _B){return _A<_B?_A:_B;}
template<typename T>void read(T&x)
{
    x=0;int _f(0);char ch=getchar();
    while(!isdigit(ch))_f|=(ch=='-'),ch=getchar();
    while( isdigit(ch))x=x*10+ch-'0',ch=getchar();
    x=_f?-x:x;
}
inline void file()
{
#ifdef ztzshiwo
    freopen("in.txt","r",stdin);
    freopen("out.txt","w",stdout);
#endif
}
int A[N],B[N],C[N],n;
LL s1[N],s2[N],s3[N],ans;
int main()
{
	file();
	read(n);
	For(i,1,n)read(A[i]);
	For(i,1,n)read(B[i]);
	For(i,1,n)read(C[i]);
	sort(A+1,A+n+1);
	sort(B+1,B+n+1);
	sort(C+1,C+n+1);
	For(i,1,n)s1[i]=i;
	int now1=0;
	For(i,1,n)
	{
		while(now1<n&&A[now1+1]<B[i])now1++;
		s2[i]=s2[i-1]+s1[now1];
	}
	int now2=0;
	For(i,1,n)
	{
		while(now2<n&&B[now2+1]<C[i])now2++;
		s3[i]=s3[i-1]+s2[now2];
	}
	printf("%lld\n",s3[n]);
	return 0;
}



Measured memory_bytes: 3840
//p[i]!=i
#include<cstdio>
using namespace std;
int n,a[100010],i,ans,t,l,r;
int main()
{
	scanf("%d",&n);
	for (i=1;i<=n;i++) scanf("%d",&a[i]);
	ans=0;
	l=1;r=n;
	while (l<r)
	{
		if (a[l]==l)
		{
			ans++;
			t=a[l];
			a[l]=a[l+1];
			a[l+1]=t;
		}
		if (a[r]==r)
		{
			ans++;
			t=a[r];
			a[r]=a[r-1];
			a[r-1]=t;
		}
		l++;r--;
	}
	if (l==r&&a[l]==l) ans++;
	printf("%d\n",ans);
}
//p[1]=1,need to swap once
//p[1]!=1,no swap is needed.


Measured memory_bytes: 512