akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define mod 1000000007
#define int long long
#define ll long long
#define EPS 0.00000000000001
#define ld long double
#define inf 1e6
#define N 100004
int fact[N],ifact[N];

ll fastexpom(ll a,ll b,ll m)
{
  ll res=1;
      while(b>0)
      {
        if(b%2==1)
          res=(((res)%m)*((a)%m))%m;
        a=(((a)%m)*((a)%m))%m;
        b/=2;
      }
      return res;
}
ll modinv(ll a, ll m=1000000007)
{
  return fastexpom(a,m-2,m);
}
void preprocess()
{
    fact[0] = 1;
    ifact[0] = 1;
    for(int i = 1;i < N;i++)
    {
        fact[i] = (fact[i-1] * i)%mod;
        ifact[i] = modinv(fact[i]);
    }
}
int nCr(int n,int r)
{
    if(n == 0 and r == 0)
        return 1;
    if(r > n or r < 0 or n == 0)
        return 0;
    int ans = (fact[n] * ifact[n-r])%mod;
    ans = (ans * ifact[r])%mod;
    return ans;
}
int32_t main()
{
    IOS;

    preprocess();
    int n,k;
    cin >> n >> k;
    int minsum = 0;
    int maxsum = 0;
    vector<int> v(n);
    for(int i = 0;i < n;i++)
    {
        cin >> v[i];
    }
    sort(v.begin(),v.end());
    int p = 0;
    for(int i = 0;i < n;i++)
    {
        int j = i;
        p = i;
        for(;j < n;j++)
        {
            if(v[i] == v[j])
            {
                int y = j - i;
                if(p + y < k - 1)
                    ;
                else
                {
                    maxsum = (maxsum + (v[i] * nCr(p + y, k - 1))%mod)%mod;
                    if(maxsum < 0)
                        maxsum += mod;
                    if(maxsum >= mod)
                        maxsum -= mod;
                }
            }
            else
                break;
        }
        i = j - 1;
    }
    for(int i = n - 1;i >= 0;i--)
    {
        p = n - i - 1;
        int j = i;
        for(;j >= 0;j--)
        {
            if(v[i] == v[j])
            {
                int y = i - j;
                if(p + y < k - 1)
                    ;
                else
                {
                    minsum = (minsum +  (v[i] * nCr(p + y, k - 1))%mod)%mod;
                    if(minsum < 0)
                        minsum += mod;
                    if(minsum >= mod)
                        minsum -= mod;
                }
            }
            else
                break;
        }
        i = j + 1;
    }
    cout << (maxsum - minsum + mod) % mod;


    return 0;

}
 


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

int main(){
    string s;
    cin >> s;

    int n = s.length();

    int che[26];
    for(int i = 0; i < 26; i++){
        che[i] = 0;
    }

    for(int i = 0; i < n; i++){
        che[s[i] - 'a']++;
    }
    int flag = 0;
    for(int i = 0; i < 26; i++){
        if(che[i] != 0){
            flag++;
        }
    }

    int ans = 100;
    if(flag != 1){
        for(int i = 0; i < 26; i++){
            if(che[i] != 0){
                int now = n - 1;
                string a = s;
                while(1){
                    string k;
                    int cou = 0;
                    for(int j = 0; j < now; j++){
                        if(a[j] == (char)(i + 'a') || a[j + 1] == (char)(i + 'a')){
                            if(s[j] == (char)(i + 'a')){
                                k += a[j];
                            }else{
                                k += a[j + 1];
                            }
                            cou++;
                        }else{
                            k += a[j];
                        }
                    }

                    if(cou == now){
                        break;
                    }else{
                        a = k;
                        now--;
                    }
                }

                if(ans > n - now){
                    ans = n - now;
                }
            }
        }

        cout << ans << endl;
    }else{
        cout << 0 << endl;
    }
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
//#include "MyMath.h"
//#include "MyDisjointset.h"
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <functional>
#include <stdio.h>
#include <math.h>
#include <string.h>
using namespace std;
typedef pair<int, int> P; typedef long long int ll; typedef vector <int> vecint; typedef vector <vecint> dvecint; typedef vector <dvecint> vecdvecint; typedef vector <vector <dvecint> > dvecdvecint;
const ll INF = 2000000000;
struct edge {
	int to, cap, cost, rev;
	edge(int t, int ca, int co, int re) {
		to = t;
		cap = ca;
		cost = co;
		rev = re;
	}
};
vector <edge> G[100];
int prv[100], pre[100], d[100];
int v, e, flow;
void addedge(int from, int to, int cap, int cost) {
	G[from].push_back(edge(to, cap, cost, G[to].size()));
	G[to].push_back(edge(from, 0, -cost, G[from].size() - 1));
}
int minimumcost(int s, int t, int f) {
	int res = 0;
	while (f > 0) {
		fill(d, d + v, INF);
		d[s] = 0;
		bool ud = true;
		while (ud) {
			ud = false;
			for (int i = 0; i < v; i++) {
				if (d[i] == INF) continue;
				for (int j = 0; j < G[i].size(); j++) {
					edge &e = G[i][j];
					if (e.cap > 0 && d[e.to] > d[i] + e.cost) {
						d[e.to] = d[i] + e.cost;
						prv[e.to] = i;
						pre[e.to] = j;
						ud = true;
					}
				}
			}
		}
		if (d[t] == INF) return -1;
		int dis = f;
		for (int w = t; w != s; w = prv[w]) {
			dis = min(dis, G[prv[w]][pre[w]].cap);
		}
		f -= dis;
		for (int w = t; w != s; w = prv[w]) {
			G[prv[w]][pre[w]].cap -= dis;
			G[w][G[prv[w]][pre[w]].rev].cap += dis;
		}
		res += dis * d[t];
	}
	return res;
}
int main() {
	cin >> v >> e >> flow;
	for (int i = 0; i < e; i++) {
		int s, t, c, d; cin >> s >> t >> c >> d;
		addedge(s, t, c, d);
	}
	cout << minimumcost(0, v - 1, flow) << endl;
	return 0;
}

Measured memory_bytes: 3156
#[allow(unused_imports)]
use std::cmp::{min, max};
#[allow(unused_imports)]
use std::collections::{HashSet,HashMap};
#[allow(unused_imports)]
use std::collections::{BTreeSet, BTreeMap};
#[allow(unused_imports)]
use std::collections::BinaryHeap;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    }};

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
fn main() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }
    input!{
        n: i32, a:i32, b:i32,
    }
    println!("{}", min(n * a, b));
    
}

Measured memory_bytes: 4352
#include<stdio.h>
main(){
  int a,b,ans;
  double c;
  int i;
  
  while(scanf("%d %d",&a,&b)!=EOF){
    
    c=a+b;
    
    for(i=1;i<=7;i++){
      c=c/10.0;
      if(c<1.0){
	ans=i;
	break;
      }
    }
    
    printf("%d\n",ans);
    
  }
  
  return 0;
  
}

Measured memory_bytes: 1028
DBG = true
a,b,k = gets.split.map{|z| z.to_i}
cnt = 0
#for i in 1..a
a.downto(1) { |i|
  if a%i == 0 && b%i == 0
    cnt += 1
    if cnt == k
      puts "#{i}"
      exit 0
    end
  end
}


Measured memory_bytes: 1788
n, k = map(int, input().split())
candidOdd = 0
candidEven = 0
candidEven2 = 0
for i in range(1, n+1):
    if k % 2 == 1:
        if i % k == 0:
            candidOdd += 1
    else:
        if i % k == 0:
            candidEven += 1
        elif i % k == (k/2):
            candidEven2 += 1
print(candidOdd**3 + candidEven**3 + candidEven2**3)

Measured memory_bytes: 9104
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
# include <bitset>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
typedef pair<LL, LL> P;
constexpr int INF = 2000000000;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
constexpr long long MMOD = 500000004;
const double PI = acos(-1);
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
# define ALL(x)      (x).begin(),(x).end()
# define UNIQ(c)     (c).erase(unique(ALL((c))), end((c)))
# define mp          make_pair
# define eb          emplace_back
# define FOR(i,a,b)  for(int i=(a);i<(b);i++)
# define RFOR(i,a,b) for(int i=(a);i>=(b);i--)
# define REP(i,n)    FOR(i,0,n)
# define INIT        std::ios::sync_with_stdio(false);std::cin.tie(0)

LL a, b;

int main() {
	cin >> a >> b;
	for (int i = 1; i <= 10000000; i++) {
		if (a*i%b != 0) {
			cout << a*i << endl;
			return 0;
		}
	}
	cout << -1 << endl;
}

Measured memory_bytes: 764
//  Suraj Saste

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define pi pair<ll,ll>
#define mkp make_pair
#define in insert
#define fe first
#define se second
#define ms(x,i) memset(x,i,sizeof(x))
#define prec(x) cout<<std::setprecision(x)
#define mod 1000000007
#define all(x) x.begin(),x.end()
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
ll fpow(ll n, ll k, ll p=mod) {ll r=1; n=n%p; while(k>0){ if(k&1){ r=(r*n)%p; } k=k>>1; n=(n*n)%p; } return r;}
bool isPrime(ll n){ if(n<=1)return false;if(n<=3)return true;if(n%2==0 || n%3==0)return false;for(ll i=5;i*i<=n;i+=6){if(n%i==0||n%(i+2)==0)return false;}return true;}

const ll maxx=405;
ll dp[maxx][maxx];

int main()
{
	fast;
	ll n;cin>>n;
	vector<ll> a(n+1);
	for(ll i=0;i<n;i++)cin>>a[i];
	for(ll l=n-1;l>=0;l--)
	{
		for(ll r=l;r<n;r++)
		{
			if(l==r)dp[l][r]=0;
			else
			{
				dp[l][r]=1e18;
				ll sum=0;
				for(ll i=l;i<=r;i++)sum+=a[i];
				for(ll i=l;i<r;i++)
				{
					dp[l][r]=min(dp[l][r],dp[l][i]+dp[i+1][r]+sum);
				}
			}
		}
	}
	// for(ll i=0;i<n;i++)
	// {
	// 	for(ll j=0;j<n;j++)
	// 	{
	// 		cout<<dp[i][j]<<" ";
	// 	}
	// 	cout<<"\n";
	// }
	cout<<dp[0][n-1];
	return 0;
}


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

typedef long long ll;

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define ANS(n) cout << (n) << endl

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(a);i>=(b);i--)

#define ALL(obj) (obj).begin(),(obj).end()

#define pii pair<int,int>

#define pb(a) push_back(a)
#define mp make_pair

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


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#define LEN 100005
 
typedef struct pp{
  char name[100];
  int t;
}P;
 
P Q[LEN+1];
int head, tail, n;
P temp;
 
void enqueue(P x){ //push
 
  Q[tail]=x;
  if(tail==LEN)
    tail=1;
  else
    tail++;
 
}
 
P dequeue(){ //pop
  P x;
  x=Q[head];
   
  if(head==LEN)
    head=1;
  else
    head++;
 
  return x;
 
}
 
 
int main(){
  int elaps = 0, c;
  int i, q,remain,total=0;
  P u;
  scanf("%d %d", &n, &q);
 
  for ( i = 1; i <= n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }
 
  head=1;
  tail=n+1;
 
  while(head!=tail){
    temp=dequeue();
    remain=temp.t-q;
    if(remain>0) {
      total+=q;
      temp.t=remain;
      enqueue(temp);
    }
    else {
      total+=temp.t;
      printf("%s %d\n",temp.name,total);
    }
 
  }
 
   
   
    return 0;
}

Measured memory_bytes: 11820
#include<iostream>
using namespace std;
int main()
{
  int a,b;
  cin>>a>>b;
  if(a==1){
    if(b==1){
      cout<<"Draw";
    }
    else{
    cout<<"Alice";
    }
  }
  else{
    if(b==1){
      cout<<"Bob";
    }
    else if(a>b){
      cout<<"Alice";
    }
    else if(a<b){
      cout<<"Bob";
    }
    else{
      cout<<"Draw";
    }
  }
}

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

using namespace std;

typedef long long ll;

const ll MOD = 1000000007;
const ll INF = 1LL<<60;
//int INF = numeric_limits<int>::max();

int main(int, char**) {
	int n; cin >> n;
	vector<vector<int>> G(n);
	vector<pair<int, int>> p;
	for (int i=0; i<n-1; i++) {
		int a, b; cin >> a >> b;
		a--; b--;
		G[a].push_back(b);
		G[b].push_back(a);
		p.push_back(make_pair(a, b));
	}
	int K=0;
	map<pair<int, int>, int> I;
	vector<int> C(n, 0);
	queue<int> que;

	vector<int> visit(n, 0);
	visit[0] = 1;
	que.push(0);
	while(!que.empty()) {
		int now = que.front();
		que.pop();
		if (K < G[now].size()) K = G[now].size();
		int cl = 1;
		for (int u:G[now]) {
			if (visit[u]) continue;
			if (cl == C[now]) cl++;
			C[u] = I[make_pair(u, now)] = I[make_pair(now,u)] = cl++;
			visit[u] = 1;
			que.push(u);
		}
	}
	cout << K << endl;
	for (auto x:p) cout << I[x] << endl;
	return 0;
}

Measured memory_bytes: 20084
# https://kmjp.hatenablog.jp/entry/2020/05/10/0900
# 数学的な問題


mod = 998244353

class COM:
    def __init__(self, n, MOD):
        self.n = n
        self.MOD = MOD
        self.fac = [0] * (n+1)
        self.finv = [0] * (n+1)
        self.inv = [0] * (n+1)
        self.fac[0] = self.fac[1] = 1
        self.finv[0] = self.finv[1] = 1
        self.inv[1] = 1
        for i in range(2, n+1):
            self.fac[i] = self.fac[i-1] * i % MOD
            self.inv[i] = MOD - self.inv[MOD % i] * (MOD // i) % MOD
            self.finv[i] = self.finv[i-1] * self.inv[i] % MOD

    def calc(self, k):
        if k < 0:
            return 0
        return self.fac[self.n] * (self.finv[k] * self.finv[self.n-k] % self.MOD) % self.MOD

def main():
    N, M, K = map(int,input().split())

    # 隣り合う組がK以下のパターンを総当たりして解く
    if N > 1:
        cmbclass = COM(N-1, mod)
        cmb = cmbclass.calc
    else:
        cmb = lambda x:1
    res = 0
    for i in range(K+1):
        res += M * cmb(i) % mod * pow(M-1, N-i-1, mod)


    print(res % mod) 


if __name__ == "__main__":
    main()


Measured memory_bytes: 72848
import java.io.*;
import java.util.*;


public class Main {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
		int n = sc.nextInt();
		int m = sc.nextInt();

		pr.println((n - 1) * (m - 1));
	}

	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		pr = new Printer(System.out);

		solve();

		pr.close();
		sc.close();
	}

	private static class Printer extends PrintWriter {
		Printer(PrintStream out) {
			super(out);
		}
	}
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
const int N=1000000000;
int main() {
	int n, m;
	cin>>n>>m;
	int cost[m];
	int mask[m];
	for(int i=0; i<m; i++){
		int a, b;
		cin>>a>>b;
		cost[i]=a;
		int num=0;
		for(int j=0; j<b; j++){
			int x;
			cin>>x;
			x--;
			num+=(1<<x);
		}
		mask[i]=num;
	}
	
	int dp[m][(1<<n)];
	for(int i=0; i<m; i++){
		for(int j=0; j<(1<<n); j++){
			dp[i][j]=N;
		}
	}
	dp[0][0]=0;
	dp[0][mask[0]]=cost[0];
	
	for(int i=1; i<m; i++){
		for(int j=0; j<(1<<n); j++){
			if(dp[i-1][j]==N){
				continue;
			}
			
			dp[i][j]=min(dp[i-1][j], dp[i][j]);
			
			dp[i][(j|(mask[i]))]=min(dp[i][(j|(mask[i]))], dp[i-1][j]+cost[i]);
			
		}
	}
	if(dp[m-1][(1<<n)-1]==N){
		cout<<-1;
		return 0;
	}
	cout<<dp[m-1][(1<<n)-1];
	return 0;
}

Measured memory_bytes: 19520
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	string s;
	int n, k;
	cin >> n >> k;
	for (int i = 0; i < k; i++)
	{
		char c;
		cin >> c;
		s += c;
	}
	while (1)
	{
		string x;
		int am = n;
		while (am)
			x += '0' + (am % 10), am /= 10;
		bool ok = 1;
		for (int i = 0; i < s.size(); ++i)
			if (x.find(s[i]) != -1)
				ok = 0;
		if (ok)
			break;
			++n;
	}
	cout << n << endl;
}

Measured memory_bytes: 256
A = int(input())
B = int(input())
C = int(input())
X = int(input())

ans = 0

#　これだとダメ
# for a in range(A+1):
#     x = X - a*500
#     for b in range(B+1):
#         x -= b*100
#         for c in range(C+1):
#             x -= c*50
#             print(a,b,c,x)
#             if x == 0:
#                 ans += 1

# これはOK
# for a in range(A+1):
#     for b in range(B+1):
#         for c in range(C+1):
#             if 500*a+100*b+50*c == X:
#                 ans += 1


# こう書くとfor文一回省ける

for a in range(A+1):
    for b in range(B+1):
        x = X - 500*a -100*b

        if x%50 == 0 and x >=0:
            if x//50 <= C:
                ans += 1

print(ans)

#


Measured memory_bytes: 9172
def LI():
  return list(map(int,input().split()))
h,n=LI()

a=[]
b=[]
for _ in range(n):
  x,y=LI()
  a.append(x)
  b.append(y)
  
INF=10**15
dp=[INF]*(h+max(a)+10)
dp[0]=0
for i in range(0,h+1):
  for j,k in zip(a,b):
    dp[i+j]=min(dp[i+j],dp[i]+k)

ans=INF
for i in dp[h:]:
  ans=min(ans,i)
print(ans)

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

using namespace std;

int main() {
    string s;
    cin >> s;
    bool test = true;
    for (int i = 0; i < 3; ++i) {
        if (s.at(i) == s.at(i + 1)) {
            test = false;
            break;
        }
    }
    if (test) {
        cout << "Good" << endl;
    } else {
        cout << "Bad" << endl;
    }
}


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

int main() {
    int N,M,cnt=0,flag=1;
    cin >> N >> M;
    vector<int> A(N);
    for(int i=0;i<N;i++){
        cin >> A.at(i);
        cnt+=A.at(i);
    }
    sort(A.begin(),A.end());
    reverse(A.begin(),A.end());
    double av=cnt/(4.0*M);
    for(int i=0;i<M;i++){
        if(A.at(i)<av){
            flag=0;
            break;
        }
    }
    if(flag){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}


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

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

	string t;
	cin >> t;

	if(t == "zyxwvutsrqponmlkjihgfedcba"){
		cout << -1 << endl;
		return 0;
	}
	if(t.size() < 26){
		int siz = t.size();
		while(siz > 0){
			for(char i = 'a'; i <= 'z'; i++){
				// if(siz < t.size() and i <= t[siz]) continue;
				bool y = 1;
				for(int j = 0; j < siz; j++){
					if(t[j] == i) y = 0;
				}

				if(y){
					for(int j = 0; j < siz; j++){
						cout << t[j];
					}
					cout << i << endl;
					return 0;
				}
			}

			siz--;
		}
	} else {
		// cout << 26 << endl;
		int bk = 2;
		while(bk <= 26){
			char end = '{';
			for(int i = 1; i < bk; i++){
				if(t[26-i] > t[26-bk] and t[26-i] < end){
					end = t[26-i];
				}
			}

			if(end != '{'){
				for(int i = 0; i < 26-bk; i++){
					cout << t[i];
				}
				cout << end << endl;
				return 0;
			}

			bk++;
		}
	}

	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define MOD 1000000007
#define INF 11234567890
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

int n, x[3123], y[3123];
bool flag[5123][5123];
int ans;

int main()
{
	while (true)
	{
		n = 0;
		memset(x, 0, sizeof(x));
		memset(y, 0, sizeof(y));
		memset(flag, false, sizeof(flag));
		ans = 0;

		in >> n;
		if (n == 0) { break; }
		rep(i, n)
		{
			in >> x[i] >> y[i];
			flag[x[i]][y[i]] = true;
		}

		rep(i, n)
		{
			rep(j, n)
			{
				auto dis_x = x[i] - x[j];
				auto dis_y = y[i] - y[j];
				if ((0 <= x[i] + dis_y && x[i] + dis_y <= 5000)
					&& (0 <= y[i] - dis_x && y[i] - dis_x <= 5000)
					&& (0 <= x[j] + dis_y && x[j] + dis_y <= 5000)
					&& (0 <= y[j] - dis_x && y[j] - dis_x <= 5000))
				{
					if (flag[x[i] + dis_y][y[i] - dis_x]
						&& flag[x[j] + dis_y][y[j] - dis_x])
					{
						ans = std::max(ans, dis_x*dis_x + dis_y*dis_y);
					}
				}
			}
		}

		out << ans << std::endl;
	}
	return 0;
}

Measured memory_bytes: 28652
import java.util.HashSet;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        HashSet<String> dic = new HashSet<>();
        int n = scanner.nextInt();
        for (int i = 0; i < n; i++) {
            String command = scanner.next();
            String str = scanner.next();
            switch (command) {
                case "insert":
                    dic.add(str);
                    break;
                case "remove":
                    dic.remove(str);
                    break;
                case "find":
                    if (dic.contains(str)) {
                        System.out.println("yes");
                    } else {
                        System.out.println("no");
                    }
                    break;
            }
        }
    }
}

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

using namespace std;

#define F first
#define S second
#define modulo ll (1e9 + 7)

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

void init(){
    cin.tie(0);
    cin.sync_with_stdio(0);
}

const int N = 1e5 + 9, M = 2e3 + 9, OO = 0x3f3f3f3f;
const ll llOO = 0x3f3f3f3f3f3f3f3f;

ll n, a, b, x[N];

int main(){
    init();


    cin >> n >> a >> b;
    for(int i = 0;i < n;i++)    cin >> x[i];

    ll ans = 0;
    for(int i = 1;i < n;i++){
        ans += min((x[i] - x[i - 1]) * a, b);
    }

    cout << ans;
}

Measured memory_bytes: 1024
#include <iostream>
#define endl '\n'
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    string s ;
    cin >> s;
    if(s=="ABC"){
        cout << "ARC";
    }else{
        cout << "ABC";
    }

    return 0;
}



Measured memory_bytes: 3612
#-swank
(unless (member :child-sbcl *features*)
  (quit
   :unix-status
   (process-exit-code
    (run-program *runtime-pathname*
                 `("--control-stack-size" "128MB"
                   "--noinform" "--disable-ldb" "--lose-on-corruption" "--end-runtime-options"
                   "--eval" "(push :child-sbcl *features*)"
                   "--script" ,(namestring *load-pathname*))
                 :output t :error t :input t))))
(defmacro dp (name args memo-size &body body)
  (let ((memo (gensym)))
    `(let ((,memo (make-array ,memo-size :initial-element nil)))
       (defun ,name ,args
         (or (aref ,memo ,@args)
             (setf (aref ,memo ,@args)
                   ,@body))))))

(defun split (x str)
  (let ((pos (search x str))
        (size (length x)))
    (if pos
      (cons (subseq str 0 pos)
            (split x (subseq str (+ pos size))))
      (list str))))

(defmacro collect-times (time body)
  `(loop repeat ,time collect ,body))

(defun read-times (time)
  (collect-times time (read)))

(defun main (n strs)
  (loop for i from 0 below n
        sum
        (1- (length (remove-duplicates
                     (loop for str in strs
                           collect (aref str i)))))))

(let ((n (read))
      (strs (collect-times 3 (read-line))))
  (print (main n strs)))


Measured memory_bytes: 9532
package main

import "fmt"

func main() {
	var n, a, b int
	fmt.Scan(&n, &a, &b)

	s1 := b + (n-1)*a
	s2 := a + (n-1)*b
	ans := s2 - s1 + 1
	if ans < 0 {
		ans = 0
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<map>
#include<string>
#include<utility>
#include<algorithm>
#include<cstdio>
#include<iomanip>
#define ll int64_t
#define REP(i, n) for (ll i=0; i<n; i++)
using namespace std;

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
    vector<int> size;

    UnionFind(int N) : par(N), size(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) {
            par[i] = i;
            size[i] = 1;
        }
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        if (size[rx] <size[ry]) swap(rx, ry);
        par[ry] = rx; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
        size[rx] += size[ry];
    }

    int getsize(int x) {
        return size[root(x)];
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

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

    // input
    ll N, M;
    cin >> N >> M;
    vector<pair<int, int>> input(M);
    REP (i, M) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        input[i] = make_pair(a, b);
    }

    // 逆からunionしていく
    reverse(input.begin(), input.end());
    // cout << endl;
    // for (auto e: input) {
    //     cout << e.first << " " << e.second << endl;
    // }
    UnionFind tree(N);
    vector<ll> ans;
    ll temp = N * (N-1) / 2;
    ans.push_back(temp);

    for (auto e : input) {
        // cout << e.first << " " << e.second << endl;
        // cout << tree.same(e.first, e.second) << endl;
        // cout << tree.getsize(e.first) << " " << tree.getsize(e.second) << endl;
        // cout << endl;
        if (!tree.same(e.first, e.second)) {
            temp -= tree.getsize(e.first) * tree.getsize(e.second);
            ans.push_back(temp);
            tree.unite(e.first, e.second);
        } else {
            ans.push_back(temp);
        }
    }

    ans.pop_back();
    reverse(ans.begin(), ans.end());
    for (auto e : ans) cout << e << "\n";
}

Measured memory_bytes: 3828
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#define MOD 1000000007
typedef long long ll;
using namespace std;

int main(){
  int n;
  cin>>n;
  vector<int> a;
  for(int i=0;i<n;i++){
      int x;
      cin>>x;
      a.push_back(x);
  }
  sort(a.begin(),a.end());
  bool suc=false;
  if(a[0]==1){
      if(n==2){
          if(a[1]==1) suc=true; 
      }else{
          if(a[1]==2&&a[n-1]==2) suc=true;
      }
  }else{
      int now=0;
      for(int i=0;i<n;i++){
          if(a[i]==a[0]) now++;
          else break;
      }
      if(now<=2){
          int cost=a[0]+a[0]-1;
          if(now==1) cost++;
          if(a[n-1]!=cost);
          else{
          int tmp=1;
          for(int i=now+1;i<n;i++){
              if(a[i]!=a[i-1]){
                  if(tmp==1||a[i-1]+1!=a[i]) break;
                  tmp=1;
              }else tmp++;
              if(i==n-1) suc=true;
          }
          }
      }
  }

  if(suc) cout<<"Possible"<<endl;
  else cout<<"Impossible"<<endl;

  return 0;
}


Measured memory_bytes: 256
#n = int(input())
n,k = map(int,input().split())
#a_L = list(map(int,input().split()))

def Base_10_to_n(X, n):
    X_dumy = X
    out = ''
    while X_dumy>0:
        out = str(X_dumy%n)+out
        X_dumy = int(X_dumy/n)
    return out

print(len(Base_10_to_n(n,k)))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int x;
  cin >> x;
  
  int a,b,c,d;
  
  a = x % 10;
  b = x / 10 % 10;
  c = x / 10 / 10 % 10;
  d = x / 10 / 10 / 10 % 10;
  

  
  int count = 0;
 
  if(a == b && a == c){
  	  count = 1;
  }
  
  if(b == c && b == d){
  	  count = 1;
  }
  
  if(count == 1){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;

  }

}

Measured memory_bytes: 3396
import itertools 
import math
N=int(input())

#S = [[0 for j in range(3)] for i in range(2)]　2行3列の場合
S = [[0 for j in range(2)] for i in range(N)]
for i in range(N):
    X,Y=map(int,input().split())
    S[i][0]=X
    S[i][1]=Y
    

goukei=0

divide=1
for i in range(N):
    divide*=(i+1)


T=[]
for i in range(N):
    T.append(i)


D=list(itertools.permutations(T))
for Z in D:

    for j in range(N-1):
        goukei+=math.sqrt((S[Z[j]][0]-S[Z[j+1]][0])**2+(S[Z[j]][1]-S[Z[j+1]][1])**2)
print(goukei/divide)


Measured memory_bytes: 7972
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
int main(void){
	char a[200010];
	long long b[100];
	int c, d;
	int k;
	int n, m;
	int s, t;
	long long w, x, y, z;
	long long ans;
	for (int i = 0; i < 200010; i++)a[i] = 0;
	for (int i = 0; i < 100; i++)b[i] = 0;
	scanf("%s", a);
	x = strlen(a);
	for (int i = 0; i < x; i++){
		b[a[i] - 97]++;
	}
	ans = x*(x - 1);
	ans = ans / 2;
	for (int i = 0; i < 26; i++){
		y = b[i] * (b[i] - 1);
		y = y / 2;
		ans = ans - y;
	}
	ans++;
	printf("%lld\n", ans);


	return 0;

}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
  ll n,d,k;
  cin >> n >> k >> d;
  n = abs(n);
  if(d>=n)
  {
      if(k%2)
      cout << d-n << endl;
      else cout << n << endl;
  }
  else
  {
      ll ans,r = n/d;
      if(k<=r)
      {
          ans = n - d*k ;
      }
      else
      {
          ans = n-d*r;
          ll rest = k - r;
          if(rest%2==0)
          {
              ans = ans;
          }
          else
          {
              ans = abs(min(ans + d,ans-d));
          }

      }
      cout << ans << endl;
  }

}


Measured memory_bytes: 3636
k = int(input())

if k == 1 or k == 7:
    print(1)

elif k % 2 != 0 and k % 5 != 0:
    if k % 7 == 0:
        l = 9 * k // 7
    else:
        l = 9 * k

    m = 10 % l
    for i in range(1,k + 3):
        if m * 10 % l == 1:
            print(i + 1)
            break
        else:
            m = m * 10 % l

else:
    print(-1)

Measured memory_bytes: 63064
#[allow(unused_macros)]
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( stdin . lock ( ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , mut $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let mut $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

fn main() {
    input! {
        a: u64, b: u64, c: u64
    }
    println!("{}", if a+b==c || a+c==b || b+c==a {"Yes"} else {"No"});
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#include <cmath>
#include <iomanip>
#include <iterator>
#include <unordered_map>

using namespace std;

using LL = long long;
using ULL = unsigned long long;
using PII = pair<int, int>;
using PIL = pair<int, LL>;
using PLL = pair<LL, LL>;
// const LL mod = 1e9 + 7;

#define mem(a, b) memset(a, b, sizeof(a))
#define REP(i, a) for (int i = 0; i < a; ++i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define ALL(a) a.begin(), a.end()

inline void quickread() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cout << fixed << setprecision(10);
}

inline void print_vector(vector<int> &A){
    for (auto&& x : A){
        cout << x << " ";
    }
    cout << endl;
}

inline void print_array(const int A[], int n) {
    REP(i, n) {
        if (i < n - 1) {
            cout << A[i] << " ";
        } else {
            cout << A[i] << endl;
        }
    }
}

bool fac(set<int>& visit, int x) {
    int i = 2;

    set<int> f;

    int origin = x;

    while(x > 1 && i < (int)(sqrt(origin)) + 1) {
        while (x % i == 0) {
            x = x / i;
            f.insert(i);
        }
        i++;
    }

    if (x > 1) f.insert(x);

    for (auto&& x : f) {
        if (visit.find(x) == visit.end()) {
            visit.insert(x);
        } else {
            return false;
        }
    }

    return true;
}

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

inline void solve() {
    int n;
    cin >> n;

    int A[n];

    REP(i, n) cin >> A[i];

    bool pc = true;
    set<int> visit;

    int cur = A[0];
    fac(visit, A[0]);

    for (int i = 1; i < n; ++i) {
        bool test;
        if (pc) {
            test = fac(visit, A[i]);
            if (!test) pc = false;
        }
        cur = gcd(cur, A[i]);
    }

    if (pc) {
        cout << "pairwise coprime" << endl;
        return;
    }
    else {
        if (cur == 1) cout << "setwise coprime" << endl;
        else cout << "not coprime" << endl;
    }
}

int main() {
    // freopen("input.txt", "r", stdin);
    quickread();
    int t = 1;
    // cin >> t;

    for (int _ = 0; _ < t; _++) {
        solve();
    }

    return 0;
}


Measured memory_bytes: 7568
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};

int main() {
  int h, w; cin>>h>>w;
  int si, sj; cin>>si>>sj;
  int ti, tj; cin>>ti>>tj; --si; --sj; --ti; --tj;
  vector<string> s(h); rep(i,h) cin>>s[i];

  const int INF = 1e9;
  vector<vector<int>> dist(h,vector<int>(w,INF));
  dist[si][sj] = 0;
  deque<P> q;
  q.emplace_back(si,sj);

  while (!q.empty()) {
    int i = q.front().first;
    int j = q.front().second;
    int d = dist[i][j];
    q.pop_front();
    // if (dist[i][j] != d) continue;

    rep(v,4) {
      int ni = i+di[v], nj = j+dj[v];
      if (ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
      if (s[ni][nj] == '#') continue;
      if (dist[ni][nj] <= d) continue;
      dist[ni][nj] = d;
      q.emplace_front(ni,nj);
    }

    for (int ei = -2; ei <= 2; ++ei) {
      for (int ej = -2; ej <= 2; ++ej) {
        int ni = i+ei, nj = j+ej;
        if (ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
        if (s[ni][nj] == '#') continue;
        if (dist[ni][nj] <= d+1) continue;
        dist[ni][nj] = d+1;
        q.emplace_back(ni,nj);
      }
    }

  }

  int ans = dist[ti][tj];
  if (ans == INF) ans = -1;
  cout << ans << endl;
}


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

const int N = 55;

int n, k, A[N];

vector <int> P;

int main() {
  cin >> n >> k;
  for(int i = 1; i <= n; ++ i) {
    scanf("%d", &A[i]);
  }
  int lst = 0;
  for(int i = 1; i <= k + 1; ++ i) {
    int now = (lst == 1) ? 2 : 1;
    for(int j = now; j <= n; ++ j) {
      if(j != lst && A[j] < A[now]) now = j;
    }
    for(int j = 1; j <= n; ++ j) if(j != now && j != lst) {
	P.push_back(j); -- A[j];
    }
    -- A[now]; P.push_back(now);
    lst = now;
  }
  for(int i = 1; i <= n; ++ i) if(A[i] < 0) {
      puts("-1");
      return 0;
    }
  cout << P.size() << endl;
  for(int i = 0; i < (int) P.size(); ++ i) cout << P[i] <<" ";
  cout << endl;
}


Measured memory_bytes: 256
package main

import (
        "fmt"
)

func solution(s, t string) string {
        l := len(s)
        for i := 0; i < l; i++ {
                if s == t {
                        return "Yes"
                }
                s = string(s[l-1]) + s[:l-1]
        }
        return "No"
}

func main() {
        var s, t string
        fmt.Scan(&s, &t)
        fmt.Println(solution(s, t))
}

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

int H, W, N;
vector<int> arr;
vector<int> col;
vector<vector<int> > vis;

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

int main() {
    scanf("%d %d %d", &H, &W, &N);
    arr.resize(N);
    for(int i = 0; i < N; i++) {
        scanf("%d", &arr[i]);
    }
    for(int i = 0; i < N; i++) for(int j = 0; j < arr[i]; j++) {
        col.push_back(i);
    }
    int r = 0, c = 0, cnt = 0, dir = 0;
    vis = vector<vector<int> >(H, vector<int>(W, -1));
    while(cnt < H*W) {
        vis[r][c] = col[cnt++];
        if(r + dy[dir] < 0 || H <= r + dy[dir] || c + dx[dir] < 0 || W <= c + dx[dir]) dir = (dir + 1) % 4;
        else if(vis[ r + dy[dir] ][ c + dx[dir] ] != -1) dir = (dir + 1) % 4;
        r += dy[dir];
        c += dx[dir];
    }
    for(int i = 0; i < H; i++) {
        for(int j = 0; j < W; j++) {
            printf("%d ", vis[i][j] + 1);
        }
        printf("\n");
    }
}


Measured memory_bytes: 384
#include <iostream>

using namespace std;

int query(int i){
    string S;
    cout<<i<<endl;
    cin>>S;
    if(S=="Vacant") return -1;
    if(S=="Male") return 0;
    else return 1;
}

int main(){
    int l,r,lc,rc;
    int N;
    cin>>N;
    l=0;r=N;
    lc=rc=query(0);
    if(lc==-1) return 0;

    while(true){
        int m=(l+r)/2;
        int mc=query(m);
        if(mc==-1) return 0;
        if((l+lc)%2!=(m+mc)%2){
            r=m;rc=mc;
        }else{
            l=m;lc=mc;
        }
    }

    return 0;
}

Measured memory_bytes: 852
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int[] num = new int[10000];
		for(int i = 0; i < num.length; i++) {
			num[i] = scan.nextInt();
			if(num[i] == 0) break;
		}
		for(int i = 0; i < num.length; i++) {
			if(num[i] == 0) break;
			int j = i + 1;
			System.out.println("Case " + j + ": " + num[i]);
		}
	}
}


Measured memory_bytes: 44888
N = int(input())
A = [int(i) for i in input().split()] 
mod = 10**9 + 7

b = [0]*N 
b[0] = A[0]
for n in range(1,N):
    b[n] = A[n] ^ b[n-1]
#print('累積論理和',b)
m = max(b)
dp = [[0]*(m+1) for j in range(2)]
dp[0] = [1]*(m+1)
cnt = [0]*(m+1)
z = 0 #zero_count

for i in range(N):
    if b[i] == 0:
        z +=1
    dp[0][b[i]] += dp[1][b[i]]*(z-cnt[b[i]])
    dp[0][b[i]] %= mod
    dp[1][b[i]] += dp[0][b[i]]
    dp[1][b[i]] %= mod
    cnt[b[i]] = z
    #print('i=',i,',bi=',b[i],',dp=',dp,'zero',z)


if b[N-1]:
    print(dp[0][b[N-1]])
else:
    ans = pow(2, z-1, mod) #2^(z-1)%mod
    for i in range(1,m+1):
        ans += dp[1][i]
        ans %= mod
    print(ans)

Measured memory_bytes: 128848
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <iterator>
#include <algorithm>
#include <map>
#include <string>
#include <vector>

using namespace std;

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

  int a, b; cin >> a >> b;
  for(int i = 1; i <= 1e4; i++){
    int c = i * 8 / 100, d = i * 10 /100;
    if(c==a&&d==b){
      cout << i;
      return 0;
    }
  }
  cout << -1;
}


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

int main(void){
	int N;
	cin >> N;
	vector<int> A(N);
	for (int i = 0; i < N; i++){
		cin >> A[i];
	}


	for (int k = 0; k < N; k++){
		cout << A[k];
		if (k == N - 1){
			cout << endl;
		}
		else{
			cout << " ";
		}
	}

	for (int i = 1; i < N; i++){
		int v = A[i];
		int j = i - 1;

		while (j >= 0 && A[j] > v){
			A[j + 1] = A[j];
			j--;
		}
		A[j + 1] = v;

		for (int k = 0; k < N; k++){
			cout << A[k];
			if (k == N - 1){
				cout << endl;
			}
			else{
				cout << " ";
			}
		}
	}


	return 0;
}

Measured memory_bytes: 1196
import itertools
n,m=map(int,input().split())
e=[set() for _ in range(n+1)]
for _ in range(m):
    a,b=map(int,input().split())
    e[a].add(b)
    e[b].add(a)
count=0
for i in itertools.permutations(range(2,n+1)):
    if i[0] not in e[1]:
        continue
    f=True
    for j in range(n-2):
        if i[j+1] not in e[i[j]]:
            f=False
            break
    if f:
        count+=1
print(count)

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

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

	int cards[4][13];
	for (int i = 0; i < 4; i++){
		for (int j = 0; j < 13; j++){
			cards[i][j] = 0;
		}
	}

	for (int i = 1; i <= n; i++){
		char k;
		int x;
		cin >> k >> x;
		
		if (k == 'S') cards[0][x-1] = 1;
		if (k == 'H') cards[1][x-1] = 1;
		if (k == 'C') cards[2][x-1] = 1;
		if (k == 'D') cards[3][x-1] = 1;

	}

	for (int i = 0; i < 4; i++){
		for (int j = 0; j < 13; j++){
			if (cards[i][j] == 0){
				if (i == 0) cout << 'S' << " " << j+1 << endl;
				if (i == 1) cout << 'H' << " " << j+1 << endl;
				if (i == 2) cout << 'C' << " " << j+1 << endl;
				if (i == 3) cout << 'D' << " " << j+1 << endl;

			}
		}
	}


	return 0;
	}





Measured memory_bytes: 3080
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

const long long INF = 1e18;
const ll mod = 998244353;
ll dp[3005][3005];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, S;
    cin >> N >> S;
    vector<ll> A(N);
    for(int i = 0; i < N; i++) cin >> A[i];
    dp[0][0] = 1;
    for(int i = 0; i < N; i++) {
        for(int j = 0; j <= S; j++) {
            dp[i+1][j] += dp[i][j] * 2;
            dp[i+1][j] %= mod;
            if(j + A[i] <= S) {
                dp[i+1][j+A[i]] += dp[i][j];
                dp[i+1][j+A[i]] %= mod;
            }
        }
    }
    cout << dp[N][S] << endl;
    return 0;
}


Measured memory_bytes: 74036
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

const long long mod = 1000000007;
const long long inf = 1e18;

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    vector<char> p,q;
    string s,t;
    cin>>s>>t;
    for(int i=0;i<s.length();i++){
        char c=s[i];
        p.pb(c);
    }
    for(int i=0;i<t.length();i++){
        char c=t[i];
        q.pb(c);
    }
    sort(p.begin(),p.end());
    sort(q.rbegin(),q.rend());

    int ans=1;
    if(s.length()<t.length()){
        for(int i=0;i<s.length();i++){
            int a=p[i]-'a';
            int b=q[i]-'a';
            if(a>b){
                ans=0;
                break;
            }
            if(a<b){
                ans=1;
                break;
            }
        }
    }
    else{
        ans=0;
        for(int i=0;i<t.length();i++){
            int a=p[i]-'a';
            int b=q[i]-'a';
            if(a<b){
                ans=1;
                break;
            }
        }
    }
    if(ans){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
function bomb(x,y,z){
   max=Math.max(max,z);
   if(max==n)return;
   var dx=[-1,0,1,-2,2,-2,2,-2,2,-1,0,1];
   var dy=[-2,-2,-2,-1,-1,0,0,1,1,2,2,2];
   var Safe={};
   for(var i=-1;i<=1;i++){
      for(var j=-1;j<=1;j++){
         Safe[(water[z*2]+i)+" "+(water[z*2+1]+j)]=true;
      }
   }
   for(var i=0;i<12;i++){
      var xx=x+dx[i];
      var yy=y+dy[i];
      if(xx<0 || yy<0 || xx>=10 || yy>=10)continue;
      if(Safe.hasOwnProperty(xx+" "+yy))bomb(xx,yy,z+1);
   }
}
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
while(true){
   var xy=(Arr.shift()).split(" ").map(Number);
   if(xy[0]==0 && xy[1]==0)break;
   var map=[[],[],[],[],[],[],[],[],[],[]];
   var n=Arr.shift()-0;
   var water=(Arr.shift()).split(" ").map(Number);
   var max=0;
   bomb(xy[0],xy[1],0);
   console.log((max==n)?"OK":"NA");
}

Measured memory_bytes: 8732
import java.util.*;

public class Main{
  public static void main(String[] args) {
    Scanner sc=new Scanner(System.in);
    String s=sc.next();
    int n=s.length();
    String answer = "Yes";

    if (n%2==0) {
      answer = "No";
    }else{
      String s1=s.substring(0,n/2);
      String s2=s.substring(n/2+1);

      if (s1.equals(s2)) {
        answer = "Yes";
        char[] chars = s1.toCharArray();
                for (int i = 0; i < chars.length / 2; i++) {
                    if (chars[i] != chars[chars.length - (i + 1)]) {
                        answer = "No";
                        break;
                    }
                }
      }else{
        answer = "No";
      }

    }


    System.out.println(answer);


  }
}


Measured memory_bytes: 21972
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	private static String[] chara;

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str = br.readLine();
		Boolean isEnd = str.equals("-");
		while (!isEnd) {
			String defaultstr = str;
			str = br.readLine();
			int count = Integer.parseInt(str);
			int[] shuffleamount = new int[count];
			for (int i = 0; i < count; i++) {
				str = br.readLine();
				shuffleamount[i] = Integer.parseInt(str);
			}
			chara = defaultstr.split("", 0);
			int length = chara.length;
			for (int j = 0; j < count; j++) {
				Shuffling(shuffleamount[j], length);
			}
			for (String charac : chara) {
				System.out.print(charac);
			}
			System.out.println();
			str = br.readLine();
			isEnd = str.equals("-");
		}
	}

	private static void Shuffling(int h, int l) {
		String[] temporary = new String[h];
		for (int k = 0; k < h; k++) {
			temporary[k] = chara[k];
		}
		for (int m = 0; m < l - h; m++) {
			chara[m] = chara[h + m];
		}
		for (int n = 0; n < h; n++) {
			chara[l - h + n] = temporary[n];
		}
	}
}

Measured memory_bytes: 24304
class City:
  def __init__(self, born):
    self.born = born
    self.id = ''

class Pref:
  def __init__(self, id):
    self.id = str(id).zfill(6)
    self.cities = []
  
  def add_city(self, city):
    self.cities.append(city)
  
  def issue_ids(self):
    self.cities.sort(key=lambda c:c.born)
    for i, c in enumerate(self.cities):
      c.id = self.id + str(i+1).zfill(6)

      
prefs = dict()
cities = []
n, m = map(int, input().split())
for _ in range(m):
  p, y = map(int, input().split())
  city = City(y)
  cities.append(city)
  if p in prefs:
    prefs[p].add_city(city)
  else:
    pref = Pref(p)
    pref.add_city(city)
    prefs[p] = pref

for p in prefs.values():
  p.issue_ids()

for c in cities:
  print(c.id)


Measured memory_bytes: 73692