akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#define LL long long
#define PP std::pair<LL,LL>
LL N, Q, K;
LL D[100010];
struct edge {
	LL to, cost;
};
std::vector<edge> E[100010];

void dik() {
	std::fill(D, D + N + 1, 100000000000000000);
	std::priority_queue<PP, std::vector<PP>, std::greater<PP>> pq;
	pq.push({ 0,K });
	while (!pq.empty()) {
		PP p = pq.top();
		pq.pop();
		if (p.first > D[p.second])continue;
		for (auto u : E[p.second]) {
			if (D[u.to] > p.first + u.cost) {
				D[u.to] = p.first + u.cost;
				pq.push({ D[u.to],u.to });
			}
		}
	}
}

int main() {
	std::cin >> N;
	for (int i = 1; i < N; i++) {
		LL a, b, c;
		std::cin >> a >> b >> c;
		E[a].push_back(edge{ b,c });
		E[b].push_back(edge{ a,c });
	}
	std::cin >> Q >> K;
	dik();
	for (int i = 0; i < Q; i++) {
		int a, b;
		std::cin >> a >> b;
		std::cout << D[a] + D[b] << std::endl;
	}
	return 0;
}

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

using namespace std;

#define ll  long long
#define ld  double

#define sz(x)   (int)x.size()
#define all(x)  x.begin(),x.end()

#define pb  emplace_back
#define X   first
#define Y   second

const int   N   = 2e5 + 5;

typedef pair<int,int>   ii;

vector<int> g[N];

int d[N];

int dfs(int u,int p)    {
    int R = u;

    for(int v : g[u])   if (v != p) {
        d[v] = d[u] + 1;

        int x = dfs(v,u);

        if (d[R] < d[x])
            R = x;
    }
    return  R;
}

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

    int n;  cin >> n;

    for(int i = 1 ; i < n ; ++i)    {
        int x;  cin >> x;
        int y;  cin >> y;

        g[x].pb(y);
        g[y].pb(x);
    }

    int L = dfs(1,0);   d[L] = 0;
    int R = dfs(L,0);

    if (d[R] % 3 == 1)
        cout << "Second";
    else
        cout << "First";
}

Measured memory_bytes: 24448
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

#define ll long long int

using namespace std;

int main(void)
{
	string s;
	cin >> s;
	if (s[0] == '9' || s[1] == '9') {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return (0);
}

Measured memory_bytes: 256
//
//  main.c
//  Calc
//
//  Created by k19031kk on 2020/06/27.
//  Copyright © 2020 AIT. All rights reserved.
//

#include <stdio.h>

int main(int argc, const char * argv[]) {
    int a;
    int sum = 0;
    scanf("%d",&a);
    
    sum = a + (a * a) + (a * a * a);
    printf("%d\n",sum);
    return 0;
}


Measured memory_bytes: 1684
#include<iostream>
#include<algorithm>

using namespace std;
int main(){
  int A[5],k;
  for(int i=0 ; i<5;i++)
  cin >> A[i] ;

  cin >> k ;
  int distance,possible=0;
for(int l=0 ; l<5;l++)
  for(int i=1 ; i+l<5;i++){
      distance=A[i+l]-A[l];
      if(distance>k)possible++;
    }
    
if(possible==0){
  cout << "Yay!" <<endl;
}
  else
  {
    cout << ":(" <<endl;/* code */
  }
  
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define MAX 100000

int A[MAX],n;

int partition(int,int);

int main(){
  int i,q;

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

  q=partition(0,n-1);

  for(i=0;i<n;i++){
    if(i>0) printf(" ");
    if(i==q) printf("[");
    printf("%d",A[i]);
    if(i==q) printf("]");
  }
  printf("\n");
  return 0;
}

int partition(int p,int r){
  int x,i,j,t;
  x=A[r];
  i=p-1;
  for(j=p;j<r;j++){
    if(A[j]<=x){
      i++;
      t=A[i];
      A[i]=A[j];
      A[j]=t;
    }
  }
  t=A[i+1];
  A[i+1]=A[r];
  A[r]=t;

  return i+1;

}


Measured memory_bytes: 2088
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cassert>

using namespace std;
typedef long long LL;
template <typename F, typename S> std::ostream& operator<<(ostream& os, const pair<F,S>& p) {
    os << "(" << p.first << "," << p.second << ")"; return os; }
template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "["; for(const T& a: v){ os << a << ", "; } os << "]"; return os; }
template <typename K, typename V> ostream& operator<<(ostream& os, const map<K,V>& m) {
    os << "{"; for(const auto& p: m){ os << p.first <<":"<< p.second << ", "; } os << "}"; return os; }

vector<LL> prime_list(LL max_val){
    vector<LL> memo(max_val+1);
    vector<LL> res;
    for(LL v = 2; v <= max_val; ++v){
        if(memo[v]) continue;
        res.push_back(v);
        for(LL k = v; k <= max_val; k += v) memo[k] = 1;
    }
    return res;
}

map<LL,LL> factorize(LL val, vector<LL>& primes){
    map<LL,LL> factor;
    for(LL p: primes){
        LL val2 = val;
        while(val % p == 0){
            ++factor[p];
            val /= p;
        }
        if(p*p > val2) break;
    }
    if(val > 1) ++factor[val];
    return factor;
}


int main(){
    LL n, M;
    cin >> n >> M;
    vector<LL> primes = prime_list(1000000);
    map<LL,LL> max_factors;
    bool flag = true;
    LL bin = 0;
    for(LL i = 0; i < n; ++i){
        LL a;
        cin >> a;
        a /= 2;
        for(auto p: factorize(a, primes)){
            if(p.first == 2){
                if(i == 0) bin = p.second;
                else if(bin != p.second) flag = false;
            }
            max_factors[p.first] = max(max_factors[p.first], p.second);
        }
    }
    if(!flag){
        cout << 0 << endl;
        return 0;
    }
    LL base = 1;
    for(auto p: max_factors){
        for(LL i = 0; i < p.second; ++i){
            base *= p.first;
            if(base > M){
                base = 0;
            }
        }
    }
    
    LL ans = 0;
    if(base > 0){
        ans = (M + base) / (base*2);
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 12132
//#define _CRT_SECURE_NO_WARNINGS
//#include <bits/stdc++.h>
#include "bits/stdc++.h"

#define rep(i,n) for(ll (i)=0;(i)<(ll)(n);(i)++)
#define all(x) (x).begin(),(x).end()

#define MOD 1000000007LL
#define INF (1LL<<60LL)
#define int long long
#define MAX_N (100001)
typedef long long ll;

using namespace std;


signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, k; cin >> n >> k;
	vector<bool> v(n+1, false);
	int ans = n;
	rep(i, k) {
		int q; cin >> q;
		rep(j, q) {
			int a; cin >> a;
			if (!v[a]) {
				v[a] = true;
				ans--;
			}
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
#define P pair<int,int>
#define fr first
#define se second
using namespace std;
typedef long long ll;
const int maxx=1e5+10;
const ll mod=1e9+7;
int main(){
    int n; cin>>n;
    ll ans=0;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            for(int k=1;k<=n;k++){
                ans+=__gcd(i,__gcd(j,k));
            }
        }

    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
const int INF = 1001001001;

int main() {
int N,X;
cin >> N >> X;
vector<int> L(N);
vector<int> D(N+1);
D.at(0) = 0;
for (int i = 0;i < N;i++) {
    cin >> L.at(i);
    D.at(i+1) = D.at(i) + L.at(i); 
    
}
int cnt = 0;
for (int i = 0;i < N+1;i++) {
    if (X >= D.at(i)) cnt++;
}
cout << cnt << endl;


return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int a,b,c;
	int n;
	
	scanf("%d %d %d",&a,&b,&c);
	
	if(a!=b)
	{
		if(a!=c)
		{
			n=a;
		}
		else
		{
			n=b;
		}
	}
	else
	{
		n=c;
	}
	
	printf("%d",n);
	
	
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define GET_ARRAY_SIZE(a)   (sizeof(a)/sizeof(a[0]))
#define LL long long
LL facctorialMethod(int k);
int main(){
    double r;
    cin >> r;
    cout << (r+r)*M_PI << endl;

    return 0;
}

LL facctorialMethod(int k){
    int sum = 1;
    for (int i = 1; i <= k; ++i){
        sum *= i;
    }
    return sum;
}


Measured memory_bytes: 3724
#include <stdio.h>

int main(void){
    int n,k,q;
    int A[100001]={};
    int B[100001]={};
    int i;
    scanf("%d%d%d",&n,&k,&q);
    for(i=1; i<=q; i++)scanf("%d",&A[i]);
    for(i=1; i<=q; i++){
        B[A[i]]++;
    }
    for(i=1; i<=n; i++){
        if((k-(q-B[i])) > 0){
            printf("Yes\n");
        }else{
            printf("No\n");
        }
    }
}

Measured memory_bytes: 1280
N=int(input())
a=list(map(int,input().split()))
sum = int(0)
arai = int(0)
ans = int(0)
mini = float('inf')

for i in range(N):
	sum+=a[i]
for i in range(N-1):
	ans+=a[i]
	arai=sum-ans
	mini=min(mini,float(abs(ans-arai)))

print(int(mini))

Measured memory_bytes: 24832
#include<stdio.h>
int main(){
  char s[11],t[11];
  int i,i1;
  scanf("%s",s);
  scanf("%s",t);
  for(i=0; s[i]!='\0'; ++i);
  for(i1=0; t[i1]!='\0'; ++i1);
  if(i1!=(i+1)){
        printf("No\n");
        return 0;
  }
	for(int j=0;j<i;j++){
      if(s[j]!=t[j]){
        printf("No");
        return 0;
      }
    }
  printf("Yes");
}

Measured memory_bytes: 1732
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdlib>
#include<iomanip>
#include<iostream>
#include<numeric>
#include<string>
using namespace std;

long gcd(long x, long y) { if (x > y) { return gcd(y, x); } long r; while (y != 0) { r = x % y; x = y; y = r; }return x; }
long lcm(long x, long y) { return(x / gcd(x, y)) * y; }
void indexsort(long* first, long* last, long* func) { sort(first, last, [&](long a, long b) {return func[a] < func[b]; }); }
//--------------------

int main() {

	string s; cin >> s;
	int K; cin >> K;
	string sub[100009] = {};
	long subp = 0;//次のsubのインデックス
	long mylen = s.length();

	for (int i = 1; i <= K; i++) {//i文字までの部分文字列。
	
		for (int j = 0; j < mylen - i + 1; j++) {//j文字目から
			sub[subp] = s.substr(j, i);
			subp++;
		}
	}

	sort(sub, sub + subp);
	unique(sub, sub + subp);

	cout << sub[K - 1] << endl;

}

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

using ll = long long;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int K;
    cin >> K;
    int a[] = {1, 1, 1, 2, 1, 2, 1, 5,  2, 2, 1, 5, 1, 2, 1, 14,
               1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    cout << a[K - 1] << endl;
}

Measured memory_bytes: 256
//be name khoda

#include <iostream>
#include <string>
using namespace std;

int a[101000];

int main()
{
	int n,ans=0;
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>a[i];
	for(int i=0;i<n;i++)
		if(a[a[i]-1]-1==i)
			ans++;
	cout<<ans/2<<endl;
	return 0;
}

Measured memory_bytes: 640
/* 

И пусть меня погубит, то к чему я
Бегу, не жалея ног.
И если мне суждено сгореть на восходе,
Я буду идти вперёд.

*/

#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x).size()
#define S second
#define F first
#define all(x) (x).begin(), (x).end()

using namespace std;

const bool dbg_flg = 0;
#define debug(x) if (dbg_flg) cerr << #x << ' ' << x << '\n'
#define debug_pair(x) if (dbg_flg) cerr << #x << ' ' << x.F << ' ' << x.S << '\n' 

const int inf = 1e9 + 7;
const int MAXN = 1e5 + 5;

string s, t, u;
ll a, b;

void solve() {
	cin >> s >> t >> a >> b >> u;

	if (s == u) a--;
	if (t == u) b--;

	cout << a << ' ' << b;
}

int main() {
	
	//~ freopen(".in", "r", stdin);
	//~ freopen(".out", "w", stdout);
	
	ios_base::sync_with_stdio(NULL);
	cin.tie(NULL);
	cout.tie(NULL);

	int tt = 1;
	// cin >> tt;
	while (tt--) {
		solve();
	}

	return 0;
}

Measured memory_bytes: 256
s = input()

s_list = list(s)
ans = 'Yes'

for i in range(len(s_list)):
    if i % 2 != 0:
        if s_list[i] == 'R':
            ans = 'No'
            break
    else:
        if s_list[i] == 'L':
            ans = 'No'
            break
print(ans)

Measured memory_bytes: 38384
$n = <>;chomp $n;

for my $i (0..$n-1) {
    my $input = <>;
    chomp $input;

    my ($t, $x, $y) = split / /, $input;

    my $sum = $x + $y;
    if ($t % 2 == 0) {
        unless  ($t >= $sum && $sum % 2 == 0) {
            print "No";
            exit;
        }
    }
    else {
        unless  ($t >= $sum && $sum % 2 != 0) {
            print "No";
            exit;
        }

    }
}

print "Yes";


Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define RREP(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define FOR(i, s, n) for (int i = s; i < (int)n; ++i)
#define RFOR(i, s, n) for (int i = (int)n - 1; i >= s; --i)
#define ALL(a) a.begin(), a.end()
#define IN(a, x, b) (a <= x && x < b)
template<class T>inline void out(T t){cout << t << "\n";}
template<class T,class... Ts>inline void out(T t,Ts... ts){cout << t << " ";out(ts...);}
template<class T>inline bool CHMIN(T&a,T b){if(a > b){a = b;return true;}return false;}
template<class T>inline bool CHMAX(T&a,T b){if(a < b){a = b;return true;}return false;}
constexpr int INF = 1e18;



signed main(){
	int h,m,H,M,K;
	cin>>h>>m>>H>>M>>K;
	int t = h * 60 + m;
	int T = H * 60 + M;
	out((T - t) - K);
}

Measured memory_bytes: 3636
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.*;
import java.util.*;

public class Main {

	public static void main(String[] args) throws IOException {
		FastReader in = new FastReader(System.in);
		PrintWriter out = new PrintWriter(System.out);
		int n = in.nextInt();
		int t = in.nextInt();
		int a = in.nextInt();
		double x = 0.006;
		int ans = 0;
		double min = Integer.MAX_VALUE;
		for (int i = 0; i < n; i++) {
			int y = in.nextInt();
			 double r = t - y * x;
			double b = 0;
			// out.println(r);
			if (r < 0 && a < 0) {
				b = Math.abs(a - r);
			} else if (a < 0 && r > 0) {
				b = Math.abs(Math.abs(a) + r);
			} else if (a > 0 && r < 0) {
				b = Math.abs(a + Math.abs(r));
			} else {
				b = Math.abs(a - r);
			}
			if (b < min) {
				
				min = b;
				ans = i + 1;
			}
		}
		out.println(ans);

		out.flush();
		out.close();

	}

	static class FastReader {
		StringTokenizer st;
		BufferedReader br;

		public FastReader(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

		public FastReader(FileReader fileReader) {
			br = new BufferedReader(fileReader);
		}

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

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

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public boolean ready() throws IOException {
			return br.ready();
		}
	}

}

Measured memory_bytes: 22868
#include "bits/stdc++.h"
using namespace std;

string a;
map <string,int> m;
int n;

int main()
{
	cin>>n;
	while(n--) cin>>a,m[a]++;

	cout<<"AC x "<<m["AC"]<<endl;
	cout<<"WA x "<<m["WA"]<<endl;
	cout<<"TLE x "<<m["TLE"]<<endl;
	cout<<"RE x "<<m["RE"];
}

Measured memory_bytes: 3624
import functools

def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    c = a % b
    return gcd(b, c)
def lcm_base(x, y):
    return (x * y) // gcd(x, y)

def lcm(*numbers):
    return functools.reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return functools.reduce(lcm_base, numbers, 1)



n=int(input())
t=[]
for i in range(n):
    t.append(int(input()))
print(lcm_list(t))


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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;cin>>s;
    bool fumi = true;
    rep(i,s.size()){
        if(i%2==0){
            fumi = fumi && (s[i]=='R'||s[i]=='U'||s[i]=='D');
        }
        else
        {
            fumi = fumi && (s[i]=='L'||s[i]=='U'||s[i]=='D');
        }
        
    }
    if(fumi)cout<<"Yes";
    else cout<<"No";
    return 0;
}

Measured memory_bytes: 256
/*
 * 6/14 8:54 ~
 */
#include <iostream>
#include <algorithm>
#include <queue>
#define INF 1000000

using namespace std;

struct edge {
  int to, cost, dis;
};
typedef pair<int, int> P;

vector<edge> G[101];

// init

// input
int iN; // 0 <= N <= 100,000
int iM; // 1 <= P <= 100
int iL; // 1 <= P <= 100

// manage
int d[101][101];

// ú»
void init() {
}

// üÍ
bool input() {
  int i;
  edge e;
  int a, b, d, c;

  scanf("%d %d %d", &iN, &iM, &iL);
  if (iN == 0 && iM == 0 && iL == 0) return false;

  for (i = 0; i < iN; i++) {
    G[i].clear();
  }
  for (i = 0; i < iM; i++) {
    scanf("%d %d %d %d", &a, &b, &d, &c);
    e.cost = c;
    e.dis = d;
    e.to = b;
    G[a].push_back(e);
    e.to = a;
    G[b].push_back(e);
  }

  return true;
}

// 
void manage(){
  priority_queue<P, vector<P> , greater<P> > que;

  fill(d[0], d[0] + 101 * 101, INF);
  d[1][iL] = 0;
  que.push(P(0, 1 * 101 + iL));

  while (!que.empty()) {
    P p = que.top();
    que.pop();
    int v = p.second / 101;
    int c = p.second % 101;
    if (d[v][c] < p.first)
      continue;
    for (int i = 0; i < (int) G[v].size(); i++) {
      edge e = G[v][i];
      if (e.dis <= c && d[e.to][c - e.dis] > d[v][c]) {
        d[e.to][c - e.dis] = d[v][c];
        que.push(P(d[e.to][c - e.dis], e.to * 101 + (c - e.dis)));
      }
      if (d[e.to][c] > d[v][c] + e.cost) {
        d[e.to][c] = d[v][c] + e.cost;
        que.push(P(d[e.to][c], e.to * 101 + c));
      }
    }
  }
}

// oÍ
void output(){
  int i, out;
  out = d[iN][0];
  for (i = 1; i <= iL; i++) {
    out = min(out, d[iN][i]);
  }
  printf("%d\n", out);
}

// mizoSâ¤Ê
int main() {
  init(); // ú»
  while(1) {
    if (!input()) break; // üÍ + I¹»è
    manage(); // 
    output(); // oÍ
  }
  return 0;
}

Measured memory_bytes: 1408
#include <stdio.h>

int main(void)
{
  int a, b;
  char op;

  while (1) {
    scanf("%d %c %d", &a, &op, &b);

    if (op == '?') {
      break;
    } else if (op == '+') {
      a += b;
    } else if (op == '-') {
      a -= b;
    } else if (op == '*') {
      a *= b;
    } else if (op == '/') {
      a /= b;
    }

    printf("%d\n", a);
  }

  return 0;
}

Measured memory_bytes: 600
# お札の枚数及び合計金額を入力
N, Y = map(int, input().split())
# それぞれのお札の枚数の初期値を設定
A = -1 # 10000円札
B = -1 # 5000円札
C = -1 # 1000円札
# お札の合計金額を計算する関数を定義
def amount(A, B, C):
    return A * 10000 + B * 5000 + C * 1000
# 10000円札を1枚ずつ増やす
for a in range(0, N + 1):
    # 他が全て1000円札でもYを超えてしまう場合、繰り返し終了
    if amount(a, 0, N - a) > Y:
        break
    # 他が全て5000円札でもYに届かない場合、5000円札の繰り返しには進まない
    if amount(a, N - a, 0) < Y:
        continue
    for b in range(0, N - a + 1):
        # お札の合計金額がYと一致した場合、お札の枚数を更新し、繰り返しを終了する
        if amount(a, b, N - a - b) == Y:
            A = a
            B = b
            C = N - a - b
            break
    else:
        continue
    break
# 出力する
print("{} {} {}".format(A, B, C))

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
    int a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;

    int xy_min = min(x, y);
    int a_min = min(a, 2 * c);
    int b_min = min(b, 2 * c);
    int ab_min = min(a + b, 2 * c);

    int result = 0;

    result += xy_min * ab_min;
    result += (x - xy_min) * a_min;
    result += (y - xy_min) * b_min;

    cout << result << endl;

    return 0;
}



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

using namespace std;
#define _for(i,j,N) for(int i = (j); i < (N);i++)
#define _rep(i,j,N) for(int i = (j); i <= (N);i++)
#define _dec(i,j,N) for(int i = (N-1);i >= 0;i--)
#define _dep(i,j,N) for(int i = (N); i>= 0;i--)
#define ALL(x) x.begin(),x.end()
#define LL long long
#define ULL unsigned LL
#define PB push_back

int a,b,c;
int ans;

void solve(string &s){
    int sz = s.size();
    _for(i,0,sz-1){
        if(s[i] == 'A' && s[i+1]=='B') ++ans;
    }
    if(s[0] == 'B' && s[sz-1] == 'A') c++;
    else if(s[0] == 'B') b++;
    else if(s[sz-1] == 'A') a++;
}

int main()
{
    a = (b = (c = (ans = 0)));
    int N;cin >> N;
    while(N--){
        string s;
        cin >> s;
        solve(s);
    }

    if(a == 0 && b == 0){
        ans += max(c-1,0);
        cout << ans << endl;
        return 0;
    }

    if(a > b) swap(a,b);
    if(c >= a){
        ans += 2*a + (c-a);
    }
    else{
        ans += 2*c + (a-c);
    }

    cout << ans << endl;

    return 0;
}


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

using namespace std;

int main() {
	int a, b, c, n = 1;
    while(cin >> a >> b >> c){
        int is = 0;
        if(a==1){
            cout << "YES" << endl;
        }else if(a%b==0&&c%b==0){
            cout << "YES" << endl;
        }else if(a%b!=0&&c%b==0){
            cout << "NO" << endl;
        }else if(a%b==0&&c%b!=0){
            cout << "NO" << endl;
        }else{
            while((n*a)%b != c%b){
                n++;
                if(n>b){
                    cout <<"NO" << endl;
                    is = 1;
                    break;
                }
            }
            if(!is){
                cout << "YES" << endl;
            }
        }
//        while((n*a)%b != c%b){
//            n++;
//        }
//        cout << n <<endl;
    }
//    while(cin >> a >> b >> c){
//
//    }

		

	return 0;
}

Measured memory_bytes: 256
/*g++ main.cpp -o main.out*/
/*./main.out*/

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

#define LL long long
#define LD long double
#define Mod 1000000007
#define L_Mod 17100000013

const double eps = 1e-9;
const int INF = 0x3f3f3f3f;
const double PI = 3.1415926535;

#define NO_TLE std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

#define ree(a,n) memset(a,n,sizeof(a));

#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define red(i,l,u) for(int (i)=(int)(l);(i)>=(int)(u);--(i))

map<string,int> m;
set<string> st;
int cnt=1;

int main()
{
    int n;
    cin>>n;
    while(n--)
    {
        string s;
        cin>>s;
        m[s]++;
    }
    int mx=0;
    string t;
    for(auto it:m)
    {
        if(it.second>mx)
        {
            mx=it.second;
            string t=it.first;
        }
    }
    for(auto it:m)
    {
        if(it.second==mx)
        {
            cnt++;
            st.insert(it.first);
        }
    }
    for(auto it:st)cout<<it<<endl;
    return 0;
}




Measured memory_bytes: 34560
#include <bits/stdc++.h>
#include<algorithm>
#include<math.h>
#include<string>
#include<iostream>
#include <vector>
#include <cstdlib>
using namespace std;
 
template <class T> using V = vector<T>;

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

const long long INF = 1LL << 60;
 
using ll = long long;
using db = double;
using st = string;
using ch = char;
using bl = bool;
using vll = V<ll>;
using vpll =V<pair<ll,ll>>;
using vst = V<st>;
using vdb = V<db>;
using vch = V<ch>;
using vbl = V<bl>;
 
 
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define rFOR(i,a,b) for(ll i=(a);i>(b);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(b);i+=2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define M(a,b) max(a,b)
#define rM(a,b) min(a,b)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define co(a) cout<<a<<endl;
#define ci(a) cin>>a;
 
 
ll sum(ll n) {
  ll m=0;
  FOR(i,0,20){
    m+=n%10;
    n/=10;
    if(n==0){
      break;
    }
  }
  return m;
}
 
 
ll combi(ll n,ll m) {
  ll ans=1;
  rFOR(i,n,n-m){
    ans*=i;
  }
  FOR(i,1,m+1){
    ans/=i;
  }
  return ans;
}
 
 
ll lcm(ll a,ll b){
  ll n;
  n=a/gcd(a,b)*b;
  return n;
}
 
 
/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/
 
 
signed main() {
  ll n; ci(n);
  vll dp(6000000);
  FOR(i,1,6000000){
    dp[i]=i;
  }
  FOR(i,0,n){
    FOR(j,0,8){
      ll a=pow(6,j);
      ll b=pow(9,j);
      chmin(dp[i+a],dp[i]+1);
      chmin(dp[i+b],dp[i]+1);
    }
  }
  co(dp[n])
}

Measured memory_bytes: 47488
n = int(input())
a = list(map(int, input().split()))

b = [-1] * n
for i in range(n, 0, -1):
    cnt = sum(b[j - 1] for j in range(i + i, n + 1, i))
    b[i - 1] = int(a[i - 1] != cnt % 2)

print(sum(b))
if sum(b) > 0:
    print(*[i + 1 for i in range(n) if b[i] == 1])


Measured memory_bytes: 100012
#include<iostream>
#include<fstream>
#include<sstream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<cmath>
#include<cstdio>
#include<cassert>

using namespace std;

#define REP(i,m,n) for(int i=(m); i<(int)(n); i++)
#define RREP(i,m,n) for(int i=(int)(n-1); i>=m; i--)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) RREP(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aut(r,v) __typeof(v) r = (v)
#define each(it,o) for(aut(it,(o).begin()); it!=(o).end(); ++it)
#define reach(it,o) for(aut(it,(o).rbegin()); it!=(o).rend(); ++it)
#define fi first
#define se second
#define debug(...) {cerr<<"[L"<<__LINE__<<"] "; _debug(__VA_ARGS__);}

template<typename T1, typename T2> ostream& operator<<(ostream& o, const pair<T1, T2>& p)
{return o<<"("<<p.first<<", "<<p.second<<")";}
template<typename T>string join(const vector<T>&v, string del=", ")
{stringstream s;rep(i,v.size())s<<del<<v[i];return s.str().substr(del.size());}
template<typename T>ostream& operator<<(ostream& o, const vector<T>&v)
{if(v.size())o<<"["<<join(v)<<"]";return o;}
template<typename T>ostream& operator<<(ostream& o, const vector<vector<T> >&vv)
{int l=vv.size();if(l){o<<endl;rep(i,l){o<<(i==0?"[ ":",\n  ")<<vv[i]<<(i==l-1?" ]":"");}}return o;}
template<typename T>ostream& operator<<(ostream& o, const set<T>& st)
{vector<T> v(st.begin(),st.end());o<<"{ "<<join(v)<<" }";return o;}
template<typename T1, typename T2>ostream& operator<<(ostream& o, const map<T1, T2>& m)
{each(p,m){o<<(p==m.begin()?"{ ":",\n  ")<<*p<<(p==--m.end()?" }":"");}return o;}
inline void _debug(){cerr<<endl;}
template<class First, class... Rest>
void _debug(const First& first, const Rest&... rest){cerr<<first<<" ";_debug(rest...);}

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

const double PI = (1*acos(0.0));
const double INF = 0x3f3f3f3f;
const double INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;
const double mod = 1e9 + 7;

inline void finput(string filename) {
    freopen(filename.c_str(), "r", stdin);
}

string s,t;
int dp[3010][3010];

string back_trace(int i, int j, string ss){
    if(i == 0 || j == 0) return ss;
    if(s[i-1] == t[j-1]){
        return back_trace(i-1,j-1,s[i-1]+ss);
    }else{
        if(dp[i-1][j] >= dp[i][j-1])
            return back_trace(i-1,j,ss);
        else
            return back_trace(i,j-1,ss);
    }
}

int main(){
    ios_base::sync_with_stdio(0);
    // finput("./input");

    cin >> s >> t;
    int ls = s.size(), lt = t.size();

    rep(i,ls){
        rep(j,lt){
            if(s[i] == t[j]){
                dp[i+1][j+1] = dp[i][j] + 1;
            } else {
                dp[i+1][j+1] = max(dp[i][j+1], dp[i+1][j]);
            }
        }
    }

    cout << back_trace(ls,lt,"") << endl;
    return 0;
}

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

#define fi first
#define se second
#define be begin
#define en end
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ALL(a) (a).be() , (a).en()
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)        //repeat n times
#define REP2(i,s,n) for(int (i)=(s);(i)<(n);(i)++)   //repeat from s to n 
#define REPD(i,n) for(int (i)=(n);(i)>=0;(i)--)      //repeat from n to 0
#define REPD2(i,s,e) for(int (i)=(s);(i)>=(e);(i)--) //repeat from s to e
#define RANGE(i,v) for(auto &(i):v)                  //repeat range
#define ASIZE(a) (sizeof(a) / sizeof(a[0]))          //array size

using LL = long long;

template<typename T> using V = vector< T >;
using Vi = V<int>;
using Vll = V<LL>;
using Vs = V<string>;

LL GCD(LL a,LL b){
    LL t; LL r;
    if(a<b){t=a;a=b;b=t;}
    if(b==0){return a;}
    while(a%b!=0){r=a%b;a=b;b=r;}
    return b;
}

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

    Vi a(n),c(n);
    REP(i,n) cin>>a[i];

    Vi L(n+1);
    REP(i,n){
        L[i+1] = GCD(L[i],a[i]);
    }

    Vi R(n+1);
    REPD(i,n-1){
        R[i] = GCD(R[i+1],a[i]);
    }

    LL max_gcd = 0;
    REP(i,n){
        max_gcd = max(max_gcd,GCD(L[i],R[i+1]));
    }

    cout<<max_gcd<<endl;

    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    char a,b,c,d;
    a=s[2];
    b=s[3];
    c=s[4];
    d=s[5];
    if(a==b && c==d)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
}


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

using namespace std;

#define pb push_back
#define F first
#define S second
#define ALL(v) v.begin(),v.end()
#define fast_cin() ios_base::sync_with_stdio(0)
#define smid ((i + j) >> 1)
#define lc (sidx * 2)
#define rc (lc + 1)

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

#define TRACE
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

bool bit(int n, int i) { return (n >> i) & 1; }
int ceil(int a, int b) { return ceil(((ld)a) / b); }

int faltu;

const int mod = 1e9+7;
const ll inf = 4e18;
const ll ninf = -inf;
const int imax = 2e9 + 100;


int main()
{
	time_t t1, t2;
	t1 = clock();

	int n, a, b;
	cin >> n >> a >> b;
	if(abs(b - a) % 2 == 0) {
		cout << "Alice\n";
	} else {
		cout << "Borys\n";
	}



	t2 = clock();
	cerr << "time taken: " << t2 - t1 << endl;
	return 0;
}

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

#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define repi(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define uniqueV(x)          \
  sort(x.begin(), x.end()); \
  x.erase(unique(x.begin(), x.end()), x.end());
#define debug(x) cerr << #x << ": " << x << '\n'
#define debug2(x, y) cerr << "(" << #x << ", " << #y << ") = " \
                          << "(" << x << ", " << y << ")" << '\n'

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

const long long INF = 3e18 + 12;
const int inf = 1e9;

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

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

  string a, b;
  cin >> a >> b;

  int n = a.length();
  rep(i, n) {
    if (a == b) {
      cout << "Yes" << endl;
      return 0;
    }

    string s = ""s + a[n - 1];

    a.insert(0, s);
    a.erase(n);
  }

  cout << "No" << endl;

  return 0;
}

Measured memory_bytes: 256
#公約数を求める
def cf(x1,x2):
    cf=[]
    for i in range(1,min(x1,x2)+1):
        if x1 % i == 0 and x2 % i == 0:
            cf.append(i)
    return cf

# 初期入力
import sys
input = sys.stdin.readline  #文字列では使わない
A,B,K = map(int, input().split())

#公約数
div =cf(A,B)


print(div[-K])

Measured memory_bytes: 9032
w = int(input())
list1 = []

for i in range(w):
  s,p = input().split()
  p = 100 - int(p)
  list1.append("%s %03d %03d" % (s,p,i+1))

sorted_list = sorted(list1)
for i in range(w):
  id = int(sorted_list[i][-3:])
  print(id)

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

int main() {
  int A, B, C;
  cin >> A >> B >> C;

  if (A+B+C == 17 && A*B*C == 175){
    cout << "YES" << endl;
  }
  else {
    cout << "NO" << endl;
  }
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func readInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)
	n, k, q := readInt(), readInt(), readInt()

	a := make([]int, n+1)
	for i := 1; i <= q; i++ {
		ans := readInt()
		a[ans]++
	}

	for i := 1; i <= n; i++ {
		if a[i]-q+k > 0 {
			fmt.Println("Yes")
		} else {
			fmt.Println("No")
		}
	}
}


Measured memory_bytes: 3968
# -*- coding:utf-8 -*-

if __name__ == "__main__":
    N = int(input())
    Cs = []
    Ss = []
    Fs = []
    for i in range(N-1):
        C, S, F = list(map(int, input().split()))
        Cs.append(C)
        Ss.append(S)
        Fs.append(F)

    for i in range(N-1):
        ans = 0
        for j in range(i, N-1):
            if ans <= Ss[j]:
                # 駅の最初の出発時間になっていないなら待つ
                ans = Ss[j] + Cs[j]
            else:
                # 最初の出発時間はすでに過ぎているならば
                if (ans - Ss[j]) % Fs[j] == 0:
                    # すぐに出発できる
                    ans += Cs[j]
                else:
                    # 出発時間まで待つ
                    ans += Cs[j] + Fs[j] - (ans - Ss[j]) % Fs[j]
        print(ans)
    print(0)


Measured memory_bytes: 3188
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int a[100010];
int main()
{
	int n;
	while(~scanf("%d", &n))
	{
		for(int i=1;i<=n;i++)
		scanf("%d", &a[i]);
		
		int ans = 0;
		for(int i=1;i<=n;i++)
		{
			if(i == n)
			ans++;
			
			else 
			{
				int j=i+1,k=i+1;
				while(j<=n&&a[j]>=a[j-1])j++;
				while(k<=n&&a[k]<=a[k-1])k++;
				ans++;
				i = max(j, k) - 1;
			}
		}
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 512
def main():
    n = [x for x in input().split(' ')]
    s = []
    for i in n:
        if i == '+':
            a = s.pop()
            b = s.pop()
            s.append(a + b)
        elif i == '-':
            b = s.pop()
            a = s.pop()
            s.append(a - b)
        elif i == '*':
            a = s.pop()
            b = s.pop()
            s.append(a * b)
        else:
            s.append(int(i))
    print(s.pop())


if __name__ == '__main__':
    main()

Measured memory_bytes: 7736
// Original macro is in 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 = || -> 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)*}
    };
    
    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $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, [$t:tt]) => {
        {
            let len = read_value!($next, usize);
            (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")
    };
}

// for adhoc read (ex. https://atcoder.jp/contests/abc112/tasks/abc112_a)
#[allow(dead_code)]
fn read_line() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}
fn main() {
    input!{ n: usize, a: [i32;n] }
    let mut b = vec![0;n];

    for i in (1..n+1).rev() {
        let mut j = 2*i;
        let mut sum = 0;
        while j <= n {
            sum += b[j-1];
            j += i;
        }
        if a[i-1] != sum%2 {
            b[i-1] = 1;
        }
    }

    let mut ans = Vec::new();
    for i in 0..n {
        if b[i] == 1 {
            ans.push(i+1);
        }
    }
    println!("{}", b.iter().filter(|x| **x == 1).count());
    for (i,v) in ans.iter().enumerate() {
        if i > 0 {
            print!(" ");
        }
        print!("{}", v);
    }
}


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

ll inf=9223372036854775806;

int main()
{
	//freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
	ios_base::sync_with_stdio(false); cin.tie(0);
	ll n,i,j,k;
	bool q=false;
	cin>>n;
	for (i=0;i<26;i++){
		for (j=0;4*i+j*7<=100;j++){
			if (n==4*i+7*j){
				q=true;
				break;
			}
		}
		if (q==true){
			break;
		}
	}
	if (q==true){
		cout<<"Yes";
	}
	else {
		cout<<"No";
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
  long n, d;
  cin >> n >> d;
  long cnt = 0;
  for (int i = 0; i < n; ++i) {
    long x, y;
    cin >> x >> y;
    if (x * x + y * y <= d * d) cnt++;
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#include <numeric>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep1(i,n) for (int i = 1; i <= n; ++i)
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
const long long MOD = 1e9+7;
#define precout(val) cout << std::fixed << std::setprecision(20) << val;
const string alphabet = "abcdefghijklmnopqrstuvwxyz";
const int dy[4] = { 0, 1, 0, -1 };
const int dx[4] = { 1, 0, -1, 0 };

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

  map<long long, long long> table;
  for(long long i = 0; i < (long long)500000; ++i) {
    table[pow(i, (long long)5)] = i;
  }

  long long x; cin >> x;
  for(auto t : table) {
    if(table.find(x - t.first) != table.end()) {
      cout << table.find(x - t.first)->second << " " << t.second * -1 << endl;
      return 0;
    }
    if(table.find(t.first - x) != table.end()) {
      cout << t.second << " " << table.find(t.first - x)->second << endl;
      return 0;
    }
  }

  return 0;
}


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

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<ll, ll> P;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;
struct Edge {
	ll u;
	ll v;
	ll cost;
};
using Graph = vector<vector<Edge>>;

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
/***** define constant start *******/
const ll MOD = 1000000007;
const double PI = 2.0 * asin(1.0);
const ll INF = 1L<<60;
string abc = "abcdefghijklmnopqrstuvwxyz";
string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const ll MAX = 10000000;
/****** define constant end ********/
/****** define variable start ******/
ll n, m;
vl a, b;
vll G;
ll ans = 0;
/******* define variable end *******/
// 深さ優先探索
vector<bool> seen;
void dfs(const vll &G, ll v, ll count) {
	if(seen[v]) return;
	count++;
	if(count == n){
		ans++;
		return;
	}
    seen[v] = true;
    for (auto next_v : G[v]) {
        dfs(G, next_v, count);
    }
	seen[v] = false;
	return;
}
int solve() {
	cin >> n >> m;
	seen.resize(n);
	a.resize(m);
	b.resize(m);
	G.resize(n);
	REP(i, m){
		cin >> a[i] >> b[i];
		G[a[i]-1].push_back(b[i]-1);
		G[b[i]-1].push_back(a[i]-1);
	}
	dfs(G, 0, 0);
	cout << ans << endl;
	return 0;
}

int main() {
	//clock_t start = clock();
	cout << std::fixed << std::setprecision(10);
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int end_solve = solve();
	/*
	clock_t end = clock();
	const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC *
	1000.0; printf("time %lf[ms]\n", time);
	*/

	return end_solve;
}


Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#include <algorithm>
#include <bitset>
#include <complex>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#include <cassert>
#include <functional>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(...) ;
#else
#define debug(...) cerr << __LINE__ << " : " << #__VA_ARGS__ << " = " << _tostr(__VA_ARGS__) << endl;

template<typename T>
ostream &operator<<(ostream &out, const vector<T> &v);

template<typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template<typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}

void _tostr_rec(ostringstream &oss) {
  oss << "\b\b \b";
}

template<typename Head, typename... Tail>
void _tostr_rec(ostringstream &oss, Head &&head, Tail &&... tail) {
  oss << head << ", ";
  _tostr_rec(oss, forward<Tail>(tail)...);
}

template<typename... T>
string _tostr(T &&... args) {
  ostringstream oss;
  int size = sizeof...(args);
  if (size > 1) oss << "{";
  _tostr_rec(oss, forward<T>(args)...);
  if (size > 1) oss << "}";
  return oss.str();
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 210

// {a, {b, c}} : a = gcd(p, q) = bp + cq
pair<ll, pair<ll, ll>> ext_gcd(ll p, ll q) {
  if (q == 0) return {p, {1, 0}};
  auto r = ext_gcd(q, p % q);
  return {r.first, {r.second.second, r.second.first - p / q * r.second.second}};
}

/* 中国剰余定理 */

pair<ll, ll> CRT(ll a1, ll m1, ll a2, ll m2) {
  auto eg = ext_gcd(m1, m2);
  ll d = eg.first;
  if ((a2 - a1) % d) return {0, -1};
  ll m = m1 / d * m2;
  ll r = ((a1 + m1 * ((__int128_t)(a2 - a1) / d * eg.second.first % (m2 / d))) % m + m) % m;
  return {r, m};
}

int N, M, D, A[SIZE], R[SIZE][20];


int main() {
  scanf("%d%d%d", &N, &M, &D);

  for (int i = 0; i < M; i++) {
    scanf("%d", A + i);
  }

  ll now = N;

  for (int i = 0; i < D; i++) {
    pair<ll, ll> x = {INF, INF};
    for (int j = 0; j < M; j++) {
      scanf("%d", R[i] + j);
      if (R[i][j] == -1) continue;
      if (x.first == INF)
        x = {R[i][j], A[j]};
      else if (x.second != -1) {
        x = CRT(x.first, x.second, R[i][j], A[j]);
      }
    }

    if (x.first == INF) continue;

    if (x.second == -1) {
      puts("-1");
      return 0;
    }

    ll next = now / x.second * x.second + x.first;
    while (next > now) next -= x.second;

    debug(x, now);

    if (next < 0) {
      puts("-1");
      return 0;
    }

    now = next;
  }

  printf("%lld\n", now);


  return 0;
}


Measured memory_bytes: 3224
H, W, D = gets.chomp.split.map(&:to_i)
px = Array.new(90001, 0)
py = Array.new(90001, 0)
d = Array.new(90001, 0)
H.times do |i|
  gets.chomp.split.map(&:to_i).each_with_index do |a, j|
    px[a] = i
    py[a] = j
  end
end
((D + 1)..(H * W)).each do |i|
  d[i] = d[i - D] + (px[i] - px[i - D]).abs + (py[i] - py[i - D]).abs
end
Q = gets.to_i
Q.times do
  l, r = gets.chomp.split.map(&:to_i)
  puts(d[r] - d[l])
end

Measured memory_bytes: 5500
#include<stdio.h>
#include<stdlib.h>
typedef struct Node{
  int id;
  int k;
  struct Node *p;
  struct Node *c;
}node;

int getdepth(node);
char* gettype(node);
void drowchildren(node);

int main(){

  int i,j;
  int a,n;
  int id,k;

  //input
  scanf("%d",&n);
  node tree[n];
  for(i=0;i<n;i++){
    tree[i].p=NULL;
  }
  for(i=0;i<n;i++){
    scanf("%d%d",&id,&k);
    tree[id].id=id;
    tree[id].k=k;  
    tree[id].c=(node*)malloc(tree[id].k*sizeof(node));
    for(j=0;j<tree[id].k;j++){
      scanf("%d",&tree[id].c[j].id);
      tree[tree[id].c[j].id].p=&tree[id];
    }
  }
  //output
  for(i=0;i<n;i++){
    printf("node %d: ",i);
    if(tree[i].p==NULL) printf("parent = -1, ");
    else printf("parent = %d, ",tree[i].p->id);
    printf("depth = %d, ",getdepth(tree[i]));
    printf("%s, ",gettype(tree[i]));
    drowchildren(tree[i]);
  }
  
  //free 
  for(i=0;i<n;i++){
    free(tree[i].c);
  }
  return 0;
}

int getdepth(node tree){

  int count=0;
  node *q;
  
  if(tree.p==NULL) return 0;
  q=&tree;
  while(q->p!=NULL){
    q=q->p;
    count++;
  }
  return count;
}
char* gettype(node tree){
  if(tree.p==NULL) return "root";
  if(tree.k>=1) return "internal node";
  else return "leaf";
}
void drowchildren(node tree){

  int i;
 
  if(tree.k==0){
    printf("[]\n");
  }
  else{
    printf("[");
    for(i=0;i<tree.k;i++){
      if(i==tree.k-1) printf("%d]\n",tree.c[i].id);
      else printf("%d, ",tree.c[i].id);
    }
  }
}



Measured memory_bytes: 9400
#include <iostream>
#include <algorithm>
#include <math.h>
using namespace std;
// #define int long long
void read(int &x)
{
    int r = 0, ne = 1;
    char c;
    while (c < '0' || c > '9')
    {
        if (c == '-')
            ne = -1;
        c = getchar();
    }
    while (c >= '0' && c <= '9')
    {
        r = r * 10 + c - '0';
        c = getchar();
    }
    x = r * ne;
}
struct  Edge
{
    /* data */
    int i,nxt;
};
/* 链表 */
int h[100002],tot;
Edge e[200002];
inline void _add(int x,int y){
    e[++tot].i=y;
    e[tot].nxt=h[x];
    h[x]=tot;
    e[++tot].i=x;
    e[tot].nxt=h[y];
    h[y]=tot;
}
/* 输入 */
int n,m,x,y;
/* 偶环-求解 */
int s[100002],top,mid;
/* dfs */
bool odd;/* 奇环 */
int A,B;/* 环两个连接点 */
int w[100002];/* 点绿色权值(1,-1) */ /* 第二遍扫时存的是子树总权值 */
int k[100002];/* 偶环时标记多余边到LCA的点 */
int sum;/* 权值总和 */
long long ans;/* 答案 */
void dfs(int x,int fa){/* 染色 */
    for(int i=h[x];i;i=e[i].nxt){      
        int o=e[i].i;
        if(o==fa)continue;
        if(w[o]){
            if(w[o]==w[x])
                odd=true;
            A=x,B=o;
        }else{
            w[o]=-w[x];
            // sum+=w[o];
            dfs(o,x);
        }
    }
}
void Dfs(int x,int fa){/* 求解 */
    for(int i=h[x];i!=0;i=e[i].nxt){
        int o=e[i].i;
        if(o==fa||(o==A&&x==B)||(o==B&&x==A))continue;/* 排除基环树的干扰 */
        Dfs(o,x);
        w[x]+=w[o];
        k[x]+=k[o];
    }
}
signed main(){
    read(n),read(m);
    for(register int i=0;i<m;++i){
        read(x),read(y);
        _add(x,y);
    }
    // if(n%2){
    //     puts("-1");
    //     return 0;
    // }
    w[1]=1;
    // sum=1;
    dfs(1,0);
    for(int i=1;i<=n;++i)sum+=w[i];    
    if(m+1==n)/* 树 */{
        if(sum){
            puts("-1");
           return 0;
        }
    }else{
        if(odd)/* 奇环 */{
            if(sum&1){
                puts("-1");
                return 0;
            }
            ans+=abs(sum>>1);
            w[A]-=sum>>1,w[B]-=sum>>1;
        }else/* 偶环 */{
            if(sum){
                puts("-1");
                return 0;
            }else 
                k[A]=1,k[B]=-1;
        }
    }
    Dfs(1,0);
    for(register int i=1;i<=n;++i){
        if(k[i])
            s[++top]=k[i]*w[i];
        else
            ans+=abs(w[i]);
    }
    s[++top]=0;
    sort(s+1,s+top+1);
    mid=s[(top+1)>>1];
    for(register int i=1;i<=top;++i)
        ans+=abs(s[i]-mid);
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 14644