akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;

struct union_find{
    union_find(int n){
        parent = vector<int>(n, -1);
        weight = vector<int>(n, 0);
    }
    int find(int x){
        if(parent[x] < 0) return x;
        else return parent[x] = find(parent[x]);
    }
    bool isSame(int x, int y){
        return find(x) == find(y);
    }
    void unite(int x, int y){
        x = find(x);
        y = find(y);
        if(x == y){
            weight[x]++;
            return;
        }
        if(parent[x] < parent[y]) swap(x,y);
        parent[x] += parent[y];
        parent[y] = x;
        weight[x] += weight[y] + 1;
    }
    int getSize(int x){
        return -parent[find(x)];
    }
    int getWeight(int x){
        return weight[find(x)];
    }

    private:
        vector<int> parent;
        vector<int> weight;
};

int main(){
    int N, M;  cin >> N >> M;
    vector<ll> a(N);
    for(int i=0; i<N; i++){
        cin >> a[i];
    }

    union_find u = union_find(N);
    for(int i=0; i<M; i++){
        int x, y;  cin >> x >> y;
        u.unite(x, y);
    }

    if(N < 2*(N-M-1)){
        cout << "Impossible" << endl;
        return 0;
    }else if(M == N-1){
        cout << 0 << endl;
        return 0;
    }

    map<int, vector<int>> mp;
    for(int i=0; i<N; i++){
        mp[u.find(i)].push_back(i);
    }

    priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> que;
    int X = 0;
    ll ans = 0;
    for(auto p : mp){
        int r = 0;
        int minCost = 1e9 + 1;
        for(auto v : p.second){
            if(a[v] < minCost){
                minCost = a[v];
                r = v;
            }
        }
        ans += minCost;
        X++;
        // cout << r << endl;
        for(auto v : p.second){
            if(v != r){
                que.push({a[v], v});
            }
        }
    }

    for(int i=0; i<2*(N-M-1)-X; i++){
        ans += que.top().first;
        que.pop();
    }
    cout << ans << endl;
}


Measured memory_bytes: 8572
from collections import defaultdict

mod = 10 ** 9 + 7


def cmb(n, r):
    if n < r:
        return 0  # <-直した
    if r > n - r:
        return cmb(n, n - r)
    if r == 0:
        return 1
    if r == 1:
        return n
    res = f[n]
    res *= invs[r]
    res %= mod
    res *= invs[n - r]
    res %= mod
    return res


N, M = map(int, input().split())
if M == 1:
    print(1)
    exit()

d = defaultdict(int)

x = M
i = 2
while i * i <= M:
    t = 0
    while x % i == 0:
        x //= i
        t += 1
    if t > 0:
        d[i] = t
    i += 1
if x > 1:  # 同じものを表す変数のうち変化するものとしないものがあるとき、変数入れ違いに気を付ける（M>0でエラー）
    d[x] = 1

max_v = max(d.values())

f = [-1] * (N - 1 + max_v + 1)
f[0] = 1
t = 1
for i in range(1, N - 1 + max_v + 1):
    t *= i
    t %= mod
    f[i] = t

# print(d)

inv = pow(t, mod - 2, mod)
invs = [-1] * (N - 1 + max_v + 1)
invs[N - 1 + max_v] = inv
for i in range(N - 1 + max_v - 1, 0, -1):
    inv *= (i + 1)  # <-直した
    inv %= mod
    invs[i] = inv

ans = 1
for cnt in d.values():
    ans *= cmb(N - 1 + cnt, cnt)
    ans %= mod
print(ans)


Measured memory_bytes: 11892
#include <iostream>
int main(void)
{
    int h, m, s;
    std::cin >> s;
    h = s / 3600;
    m = (s / 60) % 60;
    s = s % 60;
    std::cout << h << ":" << m << ":" << s << std::endl;
    return 0;
}


Measured memory_bytes: 3112
g = [
  [1,3,5,7,8,10,12],
  [4,6,9,11],
  [2]
  ]

def get_group(n):
  for i, gg in enumerate(g):
    if n in gg:
      return i


x, y = list(map(int, input().split()))

if get_group(x) == get_group(y):
  print('Yes')
else:
  print('No')


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

bitruiseki = [[0]*21 for i in range(n+1)]

for i in range(n):
    ref = a[i]
    for j in range(20,-1,-1):
        if ref >= (1 << j):
            bitruiseki[i+1][j] = bitruiseki[i][j] + 1
            ref %= (1 << j)
        else:
            bitruiseki[i+1][j] = bitruiseki[i][j]

def check(l,r):
    for i in range(21):
        if bitruiseki[r][i] - bitruiseki[l][i] <= 1:
            pass
        else:
            return False
    return True

# 尺取り
ans = 0
right = 1
for i in range(n+1):
    right = max(right,i)
    if right < n:
        while (check(i,right+1) and right < n):
            right += 1
            if right == n:break
    ans += right - i
print(ans)

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

void solve()
{
	ll a,b;
	cin>>a>>b;
	ll h,m;
	cin>>h>>m;
	double q,w;
	q = 30*h+30*((double)m/60);
	w = m*6;
	double pi = 3.14159265358979323846;
	double ans = a*a + b*b - 2*a*b*cos(abs(q-w)*(2*pi)/360);
	cout<<fixed<<setprecision(10)<<sqrt(ans)<<endl;
}

int main()
{
	ll t = 1;
	// cin>>t;
	while(t--)
	{
		solve();
	}
}

Measured memory_bytes: 4192
#include <algorithm>
#include <bits/stdc++.h>
#include <climits>
#include <cmath>
#include <functional>
#include <iomanip>
#include <math.h>
#include <numeric>
#include <queue>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
//#define local
#ifdef local
    #include "dbg-macro/dbg.h"
#endif
//#define hacks
#ifdef hacks
    #include <boost/multiprecision/cpp_int.hpp>
#endif
#define p std::pair
#define ll long long
#define ld long double
#define ull unsigned long long
#define pi std::pair<int, int>
#define stdabs std::abs
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (unsigned long long i = 0; i < (unsigned long long)(n); ++i)
#define vec std::vector
#define oreq |=
#define npm next_permutation
using namespace std;
std::vector<unsigned ll> genprimevec(const unsigned ll N);
ll extgcd(ll a, ll b, ll& x, ll& y);
ll nCr(ll n, ll r);
void stat();
template <typename T> T fact(T num);
constexpr ll mod = 1000000000 + 7;
int main()
{
    stat();
    int n;
    cin>>n;
    vec<int> h(n);
    rep(i, n) { cin >> h[i]; }
    int ans = 0;
    int ac = 0;
    rep(i, n)
    {
        if (ac >= h[i]) { ac = h[i]; }

        else {
            ans += h[i] - ac;
	    ac=h[i];
        }
    }
    cout<<ans<<endl;
    return 0;
}
ll extgcd(ll a, ll b, ll& x, ll& y)
{
    if (b == 0) {
        x = 1, y = 0;
        return a;
    }
    ll d = extgcd(b, a % b, y, x);
    y -= a / b * x;
    return d;
}


std::vector<unsigned ll> genprimevec(const unsigned ll N)
{
    std::vector<bool> is_prime(N + 1);
    for (unsigned ll i = 0; i <= N; i++) {
        is_prime[i] = true;
    }
    std::vector<unsigned ll> P;
    for (unsigned ll i = 2; i <= N; i++) {
        if (is_prime[i]) {
            for (unsigned ll j = 2 * i; j <= N; j += i) {
                is_prime[j] = false;
            }
            P.emplace_back(i);
        }
    }
    return P;
}

void stat(){
#ifdef local
    rep(i, 2){std::cout << "local enable" << std::endl;
}
#endif
#ifdef hacks
rep(i, 2) { std::cout << "boost enable" << std::endl; }
#endif
}

ll nCr(ll n, ll r)
{
    ll num = 1;
    for (ll i = 1; i <= r; i++) {
        num = num * (n - i + 1) / i;
    }
    return num;
}

template <typename T> T fact(T num)
{
    if (num == 1) { return 1; }
    return num * fact(num - 1);
}


Measured memory_bytes: 3628
from collections import deque
import sys
input=sys.stdin.readline
n=int(input())
a=[deque(list(map(int,input().split()))) for _ in range(n)]
def find(cand):
  s=set()
  for i in cand:
    if a[i] and a[a[i][0]-1]:
      if i==a[a[i][0]-1][0]-1:
        s.add(i)
        s.add(a[i][0]-1)
  for i in s:
    a[i].popleft()
  return len(s),s
cand=set(range(n))
game=n*(n-1)//2
ans=0
while 1:
  num,cand=find(cand)
  if num==0:
    print(-1)
    break
  ans+=1
  game-=num//2
  if game==0:
    print(ans)
    break

Measured memory_bytes: 71388
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define ii pair<int,int>
#define F first
#define S second
#define pb push_back
#define pf push_front
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fore(i,a,b) for(int i = a;i < b; i+= 1)
#define forr(i,a) for(int i = a; i >= 0; i--)
#define fori(i,m) for(auto i = m.begin(); i != m.end(); i++) 
#define sz(s) int(s.size())
#define cls(a,car) memset(a,car,sizeof (a))
using namespace std;
typedef long long ll;
const int N = 1 * 1e5 + 5;
const ll mod = 1e9 + 7;
const int INF = INT_MAX;
const ll INFCAD  = ll(INT_MAX) * 2 + 1;
int n;
int v[N];
int dp[N];
int f(int i){
    if(i > n)
        return 1e9;
    if(i == n - 1)
        return 0;
    if(dp[i] != -1)return dp[i];
    int &ans = dp[i];
    ans = 1e9;
    ans = min(ans,f(i + 1) + abs(v[i] - v[i + 1]));
    ans = min(ans,f(i + 2) + abs(v[i] - v[i + 2]));
    return ans;
}

int main(){/*
    freopen("in","r",stdin);
    freopen("out","w",stdout);*/
    fast;
    cls(dp, -1);
    cin >> n;
    fore(i, 0, n)cin >> v[i];
    cout << f(0) << '\n';
    return 0;   
}

Measured memory_bytes: 4224
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n) ; ++i)
#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define emb emplace_back
#define fcout cout << fixed << setprecision(15)

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

template<typename T> void pv(vector<T> vec) {
  cout << "[";
  for(auto& v : vec) { cout << v << ","; }
  cout << "]" << endl;
}

template<>
void pv(vector<P> vec) {
  cout << "[";
  for(auto& v : vec) {
    cout << "<" << v.fi << ","<< v.se << ">" << ",";
  }
  cout << "]" << endl;
}

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

  bool flag = true;
  if(s[0] != 'A') flag = false;
  string ss = s.substr(2,s.size()-3);
  int cnt = 0;
  rep(i,ss.size()) if(ss.at(i) == 'C') cnt++;
  if(cnt!=1)flag = false;
  rep(i,s.size()) {
    char c = s.at(i);
    if(c == 'A') continue;
    if(c == 'C') continue;
    if(isupper(c)) flag = false;
  }
  if(s.at(1) == 'C') flag = false;
  if(s.at(s.size()-1) == 'C') flag = false;
  if(flag) cout << "AC" << endl;
  else cout << "WA" << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <queue>
#include <algorithm>
using namespace std;
typedef long long ll;

ll a, b;
ll n, h;
ll a_max = 0;
ll ans = 0;
priority_queue<ll> p_que;

int main()
{
    cin >> n >> h;
    for (int i = 0; i < n; i++) {
        cin >> a >> b;

        a_max = max(a, a_max);
        p_que.push(b);
    }

    while (!p_que.empty() && p_que.top() > a_max && h > 0) {
        h = h - p_que.top();
        p_que.pop();
        ans++;
    }

    if (h > 0) {
        ans += (h + a_max - 1) / a_max;
    }
    
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1400
def submit():
    n, a, b = (int(e) for e in input().split())
    h = [int(input()) for _ in range(n)]

    # t回で倒せるか否かを判定する処理を実施し、
    # tについて2分探索する

    def judge(t):
        base_damage = b * t
        add_attack = 0
        for hi in h:
            if hi <= base_damage:
                continue
            res = hi - base_damage
            q, r = divmod(res, a - b)
            add_attack += q
            if r:
                add_attack += 1
        return add_attack <= t

    max_attack = 0
    for hi in h:
        max_attack += hi // a + 1
    min_attack = 0
    while True:
        mid = (min_attack + max_attack) // 2
        if mid == min_attack:
            break
        else:
            if judge(mid):
                max_attack = mid
            else:
                min_attack = mid

    print(max_attack)

             
if __name__ == "__main__":
    submit()

Measured memory_bytes: 7072
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class MainClass
{
	public const long Giri = 1000000007;
	public const long DpInf = 99999999999999;
	
	public class Station
	{
		public int Start {get;set;}
		public int Cycle {get;set;}
		public int Cost {get;set;}
	}
	public static void Main(string[] args)
	{
		var n = Console.ReadLine().ToInt();
		var stations = new Station[n-1];
		for(int i = 0; i < n-1; i++)
		{
			var p = Input().ToInt();
			var st = new Station(){ Cost = p[0], Start = p[1], Cycle = p[2]};
			stations[i] = st;
		}
		for(int j = 0; j < n; j++)
		{
			long time = 0;
			for(int i = j; i < n-1; i++)
			{
				if(time < stations[i].Start)
				{
					time = stations[i].Start;
				}
				else if(time % stations[i].Cycle != 0)
				{
					time += (stations[i].Cycle - time % stations[i].Cycle);
				}
				
				time += stations[i].Cost;
			}
			Console.WriteLine(time);
			
		}
	}
	
	static long GCD(long a, long b)
	{
		var v = new[] { a, b };
		while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
		return v[0];
	}
	public static string[] Input() { return Console.ReadLine().Split(); }
}

public static class Smarter
{
	public static int ToInt(this string str) { return int.Parse(str); }
	public static long ToLong(this string str) { return long.Parse(str); }
	public static int[] ToInt(this string[] str, int offset = 0)
	{
		var r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt() + offset;
		return r;
	}
}

Measured memory_bytes: 11220
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define dup(x,y) (((x)+(y)-1)/(y))
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const double EPS = 1e-10;
const int INF = 1e9;
const ll LINF = 1e15;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

struct mint {
	ll x;
	mint(ll x=0):x((x%MOD+MOD)%MOD){}
	mint operator-() const { return mint(-x);}
	mint& operator+=(const mint a) {
	if ((x += a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += MOD-a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator*=(const mint a) { (x *= a.x) %= MOD; return *this;}
	mint operator+(const mint a) const { return mint(*this) += a;}
	mint operator-(const mint a) const { return mint(*this) -= a;}
	mint operator*(const mint a) const { return mint(*this) *= a;}
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t>>1);
		a *= a;
		if (t&1) a *= *this;
		return a;
	}

	mint inv() const { return pow(MOD-2);}
	mint& operator/=(const mint a) { return *this *= a.inv();}
	mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main() {
	int n;
	cin >> n;
	vector<ll> a(n);
	rep(i,n) cin >> a[i];
	vector<mint> v(n+1, 0);
	rep(i,n) v[i+1] = v[i] + a[i];
	mint ans = 0;
	for (int i = 0; i < n-1; i++) {
		mint x = a[i];
		mint y = v[n] - v[i+1];
		mint t = x * y;
		ans += t;
	}
	cout << ans << endl;
}

Measured memory_bytes: 6348
#include <stdio.h>

int gcd(int x, int y);
int gcdRe(int x, int y);
void swap(int *x, int *y);

int main(void){
  int x, y;
  scanf("%d %d", &x, &y);
  x = gcd(x, y);
  printf("%d\n", x);
  return 0;
}

int gcd(int x, int y){
  if (x < y)
    swap(&x, &y);
  return gcdRe(x, y);
}

int gcdRe(int x, int y){
  if (y <= 0)
    return x;
  else
    return gcdRe(y, x % y);
}

void swap(int *x, int *y){
  int tmp;
  tmp = *x;
  *x = *y;
  *y = tmp;
  return;
}

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

int main(){
    int n; cin >> n;
    vector<int>p(n);
    rep(i,n)cin>>p[i];
    int ans = 0 ;
    int curMin = 1e9;
    rep(i,n){
        curMin = min(curMin,p[i]);
        if(curMin == p[i])ans ++;
    }
    cout << ans << endl;
    return 0;
}


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

int main() {
  long N;
  cin >> N;
  vector<long> A(N);
  for (long i = 0; i < N; i++) cin >> A.at(i);
  sort(A.rbegin(), A.rend());
  
  long a = 0, b = 0;
  for (long i = 0; i + 1 < N; i++) {
    if (A.at(i) == A.at(i + 1)) {
      if (!a) a = A.at(i++);
     
      else b = A.at(i++);
        
      if (b) break;
    }
  }
  cout << a * b << "\n";
}


Measured memory_bytes: 4012
#include <bits/stdc++.h>
using namespace std;
int a1[2005];
int main()
{
	int a,b,c,x,y,n;
	cin>>n>>x>>y;
	for(int i=1; i<=n; i++)
		for(int j=1; j<=n; j++)
		{
			a=abs(i-x)+1+abs(j-y);
			b=abs(i-y)+1+abs(j-x);
			c=abs(i-j);
			int k=min(a,min(b,c));
			a1[k]++;
		}
	for(int i=1; i<n; i++)
		cout<<a1[i]/2<<endl;
	return 0;
}

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

int main() {
  int N, An;
  cin >> N;                 //黒板に書かれた要素の数を取得
  int mindiv = 0;     //2で割り切れる回数の最小値を保存

  for(int i = 0; i < N; i++){
    cin >> An;

    if(i == 0){                                  //はじめは基準となる回数を取得
      while (An % 2 == 0){       //2で割り切れる回数をmindivに保存
        An /= 2;
        mindiv += 1;
      }
   
    }else{
        int div = 0;                          //Anが2で割り切れた回数
        while (An % 2 == 0){     //div+1回は割り切れるということ
          if(div == mindiv)           //もしdivがmindivと等しいなら後の計算は無駄
            break;
          An /= 2;
          div += 1;
        }
        mindiv = div;                     //divは、div <= mindivを必ず満たしているので...
    }

  }            //forのブロックの終了

  cout << mindiv << endl;

}

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

int main() {
    int D;
    cin >> D;
    if (D == 25) cout << "Christmas" << endl;
    else if (D == 24) cout << "Christmas Eve" << endl;
    else if (D == 23) cout << "Christmas Eve Eve" << endl;
    else if (D == 22) cout << "Christmas Eve Eve Eve" << endl;
}

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

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;
using lint=long long;

int main(){
	string s; cin>>s;
	int n=s.length();

	lint hist[128]={};
	rep(i,n) hist[s[i]]++;

	lint ans=1;
	for(int c='a';c<='z';c++) for(int d=c+1;d<='z';d++) {
		ans+=hist[c]*hist[d];
	}
	cout<<ans<<'\n';

	return 0;
}


Measured memory_bytes: 640
N=int(input())
S=input()
c1,c2=0,0
for s in S:
    if s=='(': c1+=1
    elif c1>0: c1-=1
for s in reversed(S):
    if s==')': c2+=1
    elif c2>0: c2-=1
print('('*c2 + S + ')'*c1)

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int H, W;
  cin >> H >> W;
  
  vector<vector<char>> figure(H, vector<char>(W));
  
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> figure.at(i).at(j); 
    }
  }
  
  vector<bool> row(H, false);
  vector<bool> column(W, false);
  
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (figure.at(i).at(j) == '#') {
        row.at(i) = true;    
        column.at(j) = true;
      }
    }
  }
  
  for (int i = 0; i < H; i++) {
    if (row.at(i)) {
      for (int j = 0; j < W; j++) {
		if (column.at(j)) {
          cout << figure.at(i).at(j);
        }
      }
      cout << endl;
    }
  }
  
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int n,x[3000],y[3000];
	while(true){
	cin>>n;
	if(n==0)
		break;
	for(int i=0;i<n;i++)
		cin>>x[i]>>y[i];
	for(int i=0;i<n-1;i++){
		for(int j=n-1;j>i;j--){
			if(x[j]<x[j-1]||(x[j]==x[j-1]&&y[j]<y[j-1])){
				int tmp=x[j];
				x[j]=x[j-1];
				x[j-1]=tmp;
				tmp=y[j];
				y[j]=y[j-1];
				y[j-1]=tmp;
			}
		}
	}
	int ans=0;
	for(int f=0;f<n;f++){
		for(int g=0;g<n;g++){
			bool t=true;
			int xx=x[f]+(y[f]-y[g]),yy=y[f]+(x[g]-x[f]);
			int left=0,right=n,mid;
			bool e=false;
			while(true){
				if(left>=right-1)
					break;
				mid=(left+right)/2;
				if(x[mid]==xx&&y[mid]==yy){
					e=true;
					break;
				}
				if(x[mid]<xx||(x[mid]==xx&&y[mid]<yy))
					left=mid;
				else
					right=mid;
			}
			if(e==false)
				t=false;

			xx=x[g]+(y[f]-y[g]),yy=y[g]+(x[g]-x[f]);
			left=0,right=n,mid;
			e=false;
			while(true){
				if(left>=right-1)
					break;
				mid=(left+right)/2;
				if(x[mid]==xx&&y[mid]==yy){
					e=true;
					break;
				}
				if(x[mid]<xx||(x[mid]==xx&&y[mid]<yy))
					left=mid;
				else
					right=mid;
			}
			if(e==false)
				t=false;

			if(t==true)
				ans=max(ans,(x[f]-x[g])*(x[f]-x[g])+(y[f]-y[g])*(y[f]-y[g]));
		}
	}
	cout<<ans<<endl;
	}
	return 0;
}

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

#define ll          long long
#define ull         unsigned long long
#define pb          push_back
#define pii         pair<int,int>
#define pll         pair<long,long>
#define vi          vector<int>
#define vll         vector<ll>
#define vii         vector<pii>
#define Mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define rall(a)      (a).rbegin(),(a).rend()
#define ff           first
#define ss           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define mod        1000000007
//#define mod        998244353
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define rem(i,a,b)  for(int i=a;i>b;i--)
#define mp(a,b)     make_pair(a,b)
#define INF         numeric_limits<ll>::max();
#define NINF        numeric_limits<ll>::min();
#define vvi(a,b,name)    vector<vector<double>> name(a,vector<double>(b,-1))
//const ld pi=3.14159265359;

inline ll add(ll a,ll b,ll m){
    if((a+b)>=m)return (a+b)%m;
    return a+b;
}
inline ll mul(ll a,ll b,ll m){
    if((a*b)<m)return a*b;
    return (a*b)%m;
}

void solve(){
    int n,m;cin>>n>>m;
    int mat[n+1][n+1];
    int a,b;
    rep(i,0,n+1){
        rep(j,0,n+1){
            mat[i][j]=0;
        }
    }
    rep(i,0,m){
        cin>>a>>b;
        mat[a][b]=1;
        mat[b][a]=1;

    }
    vector<int> v;
    rep(i,2,n+1){
        v.pb(i);
    }
    int path=0;
    do{
        int cnt=0;
        a=1;
        b=v[0];
        int i=0;
        while(i<v.size()){
            if(mat[a][b]==1)cnt++;
            else break;
            i++;
            a=b;
            b=v[i];
        }
        if(i==v.size())path++;

    }while(next_permutation(all(v)));
    cout<<path<<endl;

}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    long t=1;
    //cin>>t;
    while(t--){
        solve();
    }
    return 0;
}


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

#define pow(n) (n)*(n)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

using namespace std;

/* function */
//  - none - 


/* code */
int main (void) 
{

  /* Variable_Proclamation */
  int A, B;    // input
  int C, D;    // input

  int ans_min;


  /* Input, Array_Proclamation */
  cin >> A >> B;
  cin >> C >> D;

  int A_begin, A_end;
  int B_begin, B_end;
  A_begin = A;
  A_end   = B;
  B_begin = C;
  B_end   = D;

  // vector<int> times(4);
  // times.at(0) = A;
  // times.at(1) = B;
  // times.at(2) = C;
  // times.at(3) = D;


  /* Initialize */
  //  - none - 


  /* Calculation */
  ans_min = min(A_end, B_end) -max(A_begin, B_begin);
  if(ans_min < 0)
  {
    ans_min = 0;
  }



  // sort( all(times) );

  // if(times.at(1) == A_end && times.at(2) == B_begin)
  // {
  //   ans_min = 0;
  // }
  // else if(times.at(1) == B_end && times.at(2) == A_begin)
  // {
  //   ans_min = 0;
  // }
  // else
  // {
  //   ans_min = times.at(2) -times.at(1);
  // }


  /* Output */
  cout << ans_min << endl;


  return 0;

}


/* entity */
//  - none -




Measured memory_bytes: 256
n=int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
m=0
for i in a:
    m+=b[i-1]
for i in range(n-1):
    if a[i]+1==a[i+1]:
        m+=c[a[i]-1]
print(m)

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

using i64 = long long;
using f64 = double;
using f80 = long double;
using pii = pair<int, int>;
using pll = pair<i64, i64>;
using ptx = pair<f64, f64>;

map<int, int> mp;
vector<int> v;
int ant, n;

int main() {
#ifdef HOME
	freopen("cf.in", "r", stdin);
	freopen("cf.out", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);

	cin >> n;
	v.resize(n);
	for (auto &i: v)
		cin >> i;

	sort(begin(v), end(v));
	reverse(begin(v), end(v));
	for (int i = 0; i < n; ++i) {
		bool flag = true;
		for (int lg = 30; lg >= 0; --lg) if ((1 << lg) >= v[i]) {
			if (mp[(1 << lg) - v[i]]) {
				mp[(1 << lg) - v[i]]-= 1;
				ant+= 1;
				flag = false;
				break; } }
		if (flag)
			mp[v[i]]+= 1; }

	cout << ant << endl;

	return 0; }



Measured memory_bytes: 29824
import sys
[Alice, Bob] = sys.stdin.readline().split()
if Alice == Bob:
	print('Draw')
	sys.exit()
if Alice == '1':
	print('Alice')
	sys.exit()
if Bob == '1':
	print('Bob')
	sys.exit()
if int(Alice) < int(Bob):
	print('Bob')
else:
	print('Alice')

Measured memory_bytes: 3060
n,m,c=map(int,input().split())
b=list(map(int,input().split()))
ans=0
for i in range(n):
	a=list(map(int,input().split()))
	xx=0
	for i in range(len(a)):
		xx+=(a[i]*b[i])
	xx+=c
	if xx>0:
		ans+=1
print(ans)

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

using ll = int64_t;
#define int ll

#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(i, 0, b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(), x.end()

using pi = pair<int, int>;
using vi = vector<int>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  REP(i, (int)v.size()) {
    if (i) os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

ll read() {
  ll i;
  scanf("%" SCNd64, &i);
  return i;
}

void printSpace() { printf(" "); }

void printEoln() { printf("\n"); }

void print(ll x, int suc = 1) {
  printf("%" PRId64, x);
  if (suc == 1) printEoln();
  if (suc == 2) printSpace();
}

string readString() {
  static char buf[3341000];
  scanf("%s", buf);
  return string(buf);
}

char *readCharArray() {
  static char buf[3341000];
  static int bufUsed = 0;
  char *ret = buf + bufUsed;
  scanf("%s", ret);
  bufUsed += strlen(ret) + 1;
  return ret;
}

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

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

template <class T>
T Sq(const T &t) {
  return t * t;
}

signed main() {
  int A, B, ans = 0;
  cin >> A >> B;
  ans = A + B;
  chmax(ans, A - B);
  chmax(ans, A * B);
  print(ans);
}


Measured memory_bytes: 256
s= str(input())

for i in range(len(s)):
    if (i+1)%2==1:
        if s[i] not in "RUD":
            print('No')
            exit(0)
        else:
            pass
    else:
        if s[i] not in "LUD":
            print('No')
            exit(0)
        else:
            pass
print("Yes")

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

typedef long long ll;
ll mod=998244353;
ll inv2=499122177;

ll dp[310][90010];
ll half[310][90010];

ll modpow(ll a,ll b){
  ll ans=1;
  a%=mod;
  while(b){
    if(b&1) ans=ans*a%mod;
    a=a*a%mod;
    b>>=1;
  }
  return ans;
} 
  
int main(){
  ll n;
  cin >> n;
  ll a[n];
  for(ll i=0;i<n;i++) cin >> a[i];
  ll sum=0;
  for(ll i=0;i<n;i++) sum+=a[i];
  ll ans=modpow(3,n);
  dp[0][0]=modpow(2,n);
  for(ll i=1;i<=n;i++){
    for(ll j=0;j<=sum;j++){
      if(j>=a[i-1]) dp[i][j]=(dp[i-1][j]+dp[i-1][j-a[i-1]]*inv2)%mod;
      else dp[i][j]=dp[i-1][j];
    }
  }
  for(ll i=(sum+1)/2;i<=sum;i++){
    ll over=3*dp[n][i]%mod;
    ans=(ans-over+mod)%mod;
  }
  if(sum%2==0){
    half[0][0]=1;
    for(ll i=1;i<=n;i++){
      for(ll j=0;j<=sum;j++){
        if(j>=a[i-1]) half[i][j]=(half[i-1][j]+half[i-1][j-a[i-1]])%mod;
        else half[i][j]=half[i-1][j];
      }
    }
    ll extra=(half[n][sum/2]*3)%mod;
    ans=(ans+extra)%mod;
  }
  cout << ans << endl;
}

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

using namespace std;

typedef long long ll;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    set <pair <int, int> > last;
    int ans = 0;
    int len = 0;
    for (int i = 0; i < n; i++) {
        if (s[i] == '0') {
            if (i == 0 || s[i] != s[i - 1]) {
                last.insert({i, len});
            }
            len = 0;
        } else {
            len++;
        }
        if ((int) last.size() > k) {
            last.erase(last.begin());
        }
        if (!last.empty()) {
            ans = max(ans, i - last.begin()->first + 1 + last.begin()->second);
        } else {
            ans = max(ans, i + 1);
        }
    }
    cout << ans << '\n';
    return 0;
}


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

int main(){
    int n;
    cin >> n;
    
    long long ans = 0;
    for(int i = 1; i <= n; i++){
        if(i % 3 != 0 && i % 5 != 0) ans += i;
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3636
n, k=map(int, input().split())

if k==0:
    ans=n**2
else:
    ans=0
    for i in range(k+1, n+1):
        div=n//i
        mod=n%i
        ans+=div*(i-k)
        ans+=max(0, mod-k+1)
print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include<queue>
#include<set>
#include<climits>
using namespace std;

int main()
{
  int count = 0;
  string v;
  cin >> v;

  for (int i = 0; i < v.size(); i++)
  {
    if (v[i] == 'o')
    {
      count++;
    }
  }

  cout << 700 + count * 100 << endl;

}


Measured memory_bytes: 256
D = gets.chomp.to_i
c = [0] + gets.chomp.split.map(&:to_i)
s = [0]
D.times{
  s.push ([0] + gets.chomp.split.map(&:to_i))
}

last_t = [0]
(1..26).each{
  last_t.push 0
}

score = 0

(1..D).each{ |d|
  scores = []
  (1..26).each{ |i|
    tmp_score = score
    tmp_score += s[d][i]
    (1..26).each{ |j|
      next if i == j
      tmp_score -= (c[j] * (d - last_t[j]))
    }
    scores.push ([i, tmp_score])
  }
  i = scores.sort{|a,b| a[1] <=> b[1]}[-1][0]
  last_t[i] = d
  puts i
}


Measured memory_bytes: 14400
#include<stdio.h>
 
int main()
{
  int N;
  int i;
  int A;
  int shain[200000] = {0};
 
  scanf("%d", &N);
  
  for(i = 1; i < N; i++) {
    scanf("%d", &A);
    shain[A - 1] += 1;
  }
 
  for(i = 0; i < N; i++) {
    printf("%d\n", shain[i]);
  }
 
  return 0;
}


Measured memory_bytes: 2484
N, M, X = map(int, input().split())
lis = []

for i in range(N):
    CA = list(map(int, input().split()))
    lis.append(CA)

ans = 1e9
for i in range(2 ** N):
    check = [0 for i in range(M + 1)]
    for j in range(N):
        if i >> j & 1:
            for k in range(M + 1):
                check[k] += lis[j][k]
        if min(check[1:]) >= X:
            ans = min(ans, check[0])
if ans == 1e9:
    print(-1)
else:
    print(ans)


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

typedef long long ll;

const int mxN = 1010, mxW = 20005;
int N;
ll dp[mxN][mxW];

struct block {
    int w, s, v;

    void input() {
        cin >> w >> s >> v;
    }
    int para() const {
        return (w + s);
    }
};

block a[mxN];

bool comp(const block& b1, const block& b2) {
    return (b1.para() < b2.para());
}

ll rec(int idx, int wt) {
    if (idx == N) {
        return 0;
    }
    if (dp[idx][wt] != -1) {
        return dp[idx][wt];
    }
    dp[idx][wt] = rec(idx + 1, wt);
    if (a[idx].s >= wt) {
        dp[idx][wt] = max(dp[idx][wt], a[idx].v + rec(idx + 1, wt + a[idx].w));
    }
    return dp[idx][wt];
}

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

    cin >> N;
    for (int i = 0; i < N; i++) {
        a[i].input();
    }
    sort(a, a + N, comp);
    memset(dp, -1, sizeof(dp));
    ll ans = rec(0, 0);
    cout << ans;

    return 0;
}

Measured memory_bytes: 161548
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>

#define rep(i, a) REP(i, 0, a)
#define REP(i, a, b) for(int i = a; i < b; ++i)

typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int, int> P;
typedef std::pair<P, int> PP;
const double esp = 1e-9;
const int infi = (int)1e+9 + 10;
const ll infll = (ll)1e+17 + 10;

int n;
int a[10001];

int main(){
	std::cin >> n;
	rep(i, n)std::cin >> a[i];
	std::cout << *std::min_element(a, a + n) << " " << *std::max_element(a, a + n) << " " << std::accumulate(a, a + n, 0ll) << std::endl;
	return 0;
}

Measured memory_bytes: 1204
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long k = sc.nextLong();
        
        long a = n / k;
        
        System.out.println(Math.min(n, Math.min(Math.abs(n-k*(a+1)), Math.abs(n-k*a))));
    }
}


Measured memory_bytes: 23380
#include <iostream>
using namespace std;
int main(void){
    int x;
    for(int i=1; i<=10000; i++){
        cin>>x;
        if(x !=0){
            cout << "Case " << i << ": " << x << endl;
        }
        else{
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 3000
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define vi vector<int>
#define vl vector<long long>
#define vvi vector<vector<int>>
#define fin(ar,k,n) for(int i=k;i<n;i++) cin>>ar[i]
#define fout(ar,k,n) for(int i=k;i<n;i++) cout<<ar[i]<<' '
#define all(z) z.begin(),z.end()
#define mcc ((int)1e9+7)
#define mcf 998244353
#define mi map<int,int>
#define mem(a,n) memset(a,n,sizeof(a))
#define pii pair<int,int>
#define mp(a,b) make_pair(a,b)

using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> fst;

const int N=307;
double dp[N][N][N];
int n,c[4];
void solve()
{
	cin>>n;
	for (int i=0;i<n;i++)
	{
		int x; cin>>x;
		c[x]++;
	}
	for (int k=0;k<=c[3];k++)
	{
		for (int j=0;j<=c[3]+c[2]-k;j++)
		{
			for (int i=0;i<=c[3]+c[2]+c[1]-j-k;i++)
			{
				if (i+j+k==0) continue;
				if(i) dp[i][j][k]+=i*1.0*dp[i-1][j][k];
				if(j) dp[i][j][k]+=j*1.0*dp[i+1][j-1][k];
				if(k) dp[i][j][k]+=k*1.0*dp[i][j+1][k-1];
				dp[i][j][k]+=n+0.0;
				dp[i][j][k]/=1.0*(i+k+j);
			}
		}
	}
	printf("%.12lf",dp[c[1]][c[2]][c[3]]);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t=1;
    //cin>>t;
    while(t--) solve();
    return 0;
}

Measured memory_bytes: 221440
#include <bits/stdc++.h>
using namespace std;
#define uint unsigned int
#define llong long long int
#define ullong unsigned long long int
#define rep(i, n) for (int i = 0; i < n; ++i)
const static long long int MOD = 1000000000 + 7;
const static int dy[] = {0, 1, 0, -1};
const static int dx[] = {1, 0, -1, 0};

int main(){
	int n, m, x, y, a[105], b[105];
	cin >> n >> m >> x >> y;
	for(int i = 1; i <= n; i++) cin >> a[i];
	for(int i = 1; i <= m; i++) cin >> b[i];
 
	sort(a + 1, a + 1 + n);
	sort(b + 1, b + 1 + m);
	if(a[n] >= b[1]) printf("War\n");
	else {
		bool flag = 0;
		for(int i = a[n] + 1; i <= b[1]; i++){
			if(i <= y && i > x) flag = 1;
		}
		if(flag) printf("No War\n");
		else printf("War\n");
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define forr(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define ALL(a) (a.begin()),(a.end())
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll, ll> LP;
const ll LINF = 1LL<<60;
const int INF = 1001001001;
const int MOD = 1000000007;

/* --------------------------------------------------- */

int main() {
    int x;
    cin >> x;
    int ans, cnt = 0, a = x % 100;
    for(int i = 5; i > 0; i--) {
        cnt += a / i;
        a = a % i;
    }
    if(cnt <= x / 100) ans = 1;
    else ans = 0;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast,unroll-loops")
#include<bits/stdc++.h>
#define int long long
#define F first
#define S second
#define P pair
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define V vector
#define RE return
#define ALL(a) a.begin(),a.end()
#define MP make_pair
#define PB push_back
#define PF push_front
#define FILL(a,b) memset(a,b,sizeof(a))
using namespace std;
int dp[200005],a[200005],n,h[200005],res[200005]; 
int get(int x){
	int re=0;
	while(x>0){
		re=max(re,res[x]);
		x-=x&-x;
	}
	RE re;
}
void up(int p,int x){
	p++;
	while(p<=200001){
		res[p]=max(res[p],x);
		p+=p&-p;
	}
}
signed main(){
	ios::sync_with_stdio(0);
    cin.tie(0);
	cin>>n;
	FOR(i,1,n){
		cin>>h[i];
	}
	FOR(i,1,n){
		cin>>a[i];
	}
	FOR(i,0,200000)dp[i]=-1e9;
	FOR(i,0,200001)res[i]=-1e9;
	up(0,0);dp[0]=0;
	FOR(i,1,n){
		dp[h[i]]=max(dp[h[i]],get(h[i])+a[i]);
		up(h[i],dp[h[i]]);
	}
	cout<<get(n+1);
	RE 0;
}




Measured memory_bytes: 6528
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

int c[15];
int a[15][100005];

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int n, m, x;
	cin >> n >> m >> x;
	rep(i, n){
		cin >> c[i];
		rep(j, m) cin >> a[i][j];
	}
	int ans = 1e9;
	rep(i, 1 << n){
		int cost = 0;
		vi cur(m, 0);
		rep(j, n) if(i & (1 << j)){
			cost += c[j];
			rep(k, m) cur[k] += a[j][k];
		}
		int f = 1;
		rep(k, m) if(cur[k] < x){
			f = 0;
			break;
		}
		if(f) ans = min(ans, cost);
	}
	if(ans == 1e9) ans = -1;
	cout << ans << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


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

map<char,char>mp[26][26];
int main(){
	for(int i=1;i<26;i+=2){
		rep(j,26){
			rep(k,26){
				mp[i/2][j][(k*i+j)%26+'a']=k+'a';
			}
		}
	}
	int n;scanf("%d\n",&n);
	rep(i,n){
		p:;
		string s;getline(cin,s);
		rep(i,26/2){
			rep(j,26){
				string copy=s;
				for(char&c:copy){
					if(isalpha(c)){
						c=mp[i][j][c];
					}
				}
				if((int)copy.find("this")>=0||(int)copy.find("that")>=0){
					cout<<copy<<endl;
					goto p;
				}
			}
		}
	}
}

Measured memory_bytes: 3728
/*
ID: Nipun Paul
LANG: C++
PROB: God knows
*/

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

int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	if (a * b <= c)
	{
		cout << a * b << endl;
	}
	else

	{
		cout << c << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pi 3.14159
using namespace std;
typedef long long LL;
const LL MOD = 1e9 + 7;
const int N = 2e7 + 9, M = 1e7, OO = 0x3f3f3f3f;
#define AC ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin.sync_with_stdio(0);
int main()
{
AC;
int n,i,answer=OO;
char s[10];
scanf("%s",s);
n=strlen(s);
for(i=0;i<n-2;++i){
    int x=0;
    x+=(s[i]-'0')*100;
    x+=(s[i+1]-'0')*10;
    x+=(s[i+2]-'0');
    if(abs(x-753)<answer){
            answer=abs(x-753);
    }
}
printf("%d",answer);




    return 0;
}


Measured memory_bytes: 256
if __name__ == '__main__':
	n = int(input())
	lists = list()

	for i in range(n):
		a = int(input())
		lists.append(a)

	S = None
	while len(lists) > 1:
		mini = min(lists)
		mini_ind = lists.index(mini)
		l = len(lists)

		if mini_ind + 1 == l:
			if S is None or S < lists[mini_ind] - lists[mini_ind - 1]:
				S = lists[mini_ind] - lists[mini_ind - 1]
			lists.pop(mini_ind)
			continue


		maxi = max(lists[mini_ind : l])
		T = maxi - mini

		if S is None or S < T:
			S = T

		lists = lists[0 : mini_ind]
		continue

	print(S)


Measured memory_bytes: 14904
<?php
fscanf(STDIN, '%d', $n);
for ($i=0; $i<$n; $i++) {
  fscanf(STDIN, '%s', $strings[$i]);
}
$counted_strings = array_count_values($strings);
$result = array_keys($counted_strings, max($counted_strings));
sort($result);
$imploded_result = implode("\n", $result);
echo $imploded_result;

Measured memory_bytes: 43500
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
int main(void){
    int n, m;
    long long ans = 0;
    priority_queue<int> q;
    cin >> n >> m;
    for(int i=0;i<n;i++){
        int a;
        cin >> a;
        q.push(a);
    }
    while(m > 0 && !q.empty()){
        int x = q.top(); q.pop();
        q.push(x/2);
        m--;
    }
    while(!q.empty()){
        int x = q.top(); q.pop();
        ans += x;
    }
    cout << ans << endl;
}


Measured memory_bytes: 892
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

// 内部変数 - テスト用
#ifdef D_TEST
	static int siRes;
	static FILE *szpFpT, *szpFpA;
#endif

// 実行メイン
int
fMain(
	int piTNo					// <I> テスト番号 1～
)
{
	int i, liRet;
	char lc1Buf[1024], lc1Out[1024];

	// テストファイルオープン
#ifdef D_TEST
	sprintf(lc1Buf, ".\\Test\\T%d.txt", piTNo);
	szpFpT = fopen(lc1Buf, "r");
	sprintf(lc1Buf, ".\\Test\\A%d.txt", piTNo);
	szpFpA = fopen(lc1Buf, "r");
	siRes = 0;
#endif

	// 移動回数取得
	int liMCnt;
#ifdef D_TEST
	fgets(lc1Buf, sizeof(lc1Buf), szpFpT);
#else
	fgets(lc1Buf, sizeof(lc1Buf), stdin);
#endif
	sscanf(lc1Buf, "%d", &liMCnt);

	// 現在位置
	int liNt = 0;
	int liNx = 0;
	int liNy = 0;

	// 移動回数でループ
	liRet = 0;
	for (i = 0; i < liMCnt; i++) {

		// 移動先取得
		int liTt, liTx, liTy;
#ifdef D_TEST
		fgets(lc1Buf, sizeof(lc1Buf), szpFpT);
#else
		fgets(lc1Buf, sizeof(lc1Buf), stdin);
#endif
		sscanf(lc1Buf, "%d%d%d", &liTt, &liTx, &liTy);

		// 移動距離
		int liLen = abs(liNx - liTx) + abs(liNy - liTy);

		// 残り時間
		int liZt = liTt - liNt - liLen;
		if (liZt < 0) {
			liRet = -1;
			break;
		}
		if (liZt % 2 != 0) {
			liRet = -1;
			break;
		}

		// 現在位置更新
		liNt = liTt;
		liNx = liTx;
		liNy = liTy;
	}

	// 結果セット
	if (liRet == 0) {
		sprintf(lc1Out, "Yes\n");
	}
	else {
		sprintf(lc1Out, "No\n");
	}

	// 結果表示
#ifdef D_TEST
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, lc1Out)) {
		siRes = -1;
	}
#else
	printf("%s", lc1Out);
#endif

	// テストファイルクローズ
#ifdef D_TEST
	fclose(szpFpT);
	fclose(szpFpA);
#endif

	// テスト結果
#ifdef D_TEST
	if (siRes == 0) {
		printf("OK %d\n", piTNo);
	}
	else {
		printf("NG %d\n", piTNo);
	}
#endif

	return 0;
}

int
main()
{

#ifdef D_TEST
	int i;
	for (i = D_TEST_SNO; i <= D_TEST_ENO; i++) {
		fMain(i);
	}
#else
	fMain(0);
#endif

	return 0;
}



Measured memory_bytes: 128
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
#define P pair<int,int>
const int MOD=1e9+7;
const int INF=2e9;
const double PI=acos(-1);


int main() {
    ios_base::sync_with_stdio(false);

    int n;
    cin >> n;
    vector<ll> a(n);
    ll k=0;
    rep(i,n) {
        cin >> a[i];
        k=k^a[i];
    }
    rep(i,n) {
        ll b=a[i]^k;
        cout << b << ' ';
    }
    cout << endl;
   
    return 0;   
}

Measured memory_bytes: 4656
import java.io.PrintWriter
import java.util.ArrayDeque

fun main() {
    PrintWriter(System.out).use { out ->
        solve(out)
        out.flush()
    }
}

fun solve(out: PrintWriter) {
    val (n, k) = readLongList()
    val aList = readIntegerList().map { it - 1 }
    val count = IntArray(n.toInt()) { -1 }
    var cur = 0
    var i = 0
    while (true) {
        if (count[cur] != -1) {
            break
        }

        count[cur] = i
        i++
        cur = aList[cur]
    }

    if (k - count[cur] < 0) {
        cur = 0
        repeat(k.toInt()) {
            cur = aList[cur]
        }
        println(cur + 1)
    } else {
        val tmp = i - count[cur]
        val tmp2 = (k - count[cur]) % tmp

        repeat(tmp2.toInt()) {
            cur = aList[cur]
        }
        println(cur + 1)
    }
}

fun readInteger() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntegerList() = readStringList().map(String::toInt)
fun readLongList() = readStringList().map(String::toLong)
fun readDoubleList() = readStringList().map(String::toDouble)


Measured memory_bytes: 64116
#include <atcoder/all>
#include <bits/stdc++.h>

using namespace std;
using namespace atcoder;

#define REP(i,m,n) for(int i=(m);i<(n);++i)
#define rep(i,n) REP(i,0,n)

int main(){
  int N,M;
  scanf("%d%d",&N,&M);
  vector<int> a,b;
  int tmp;
  rep(i,N){
    scanf("%d",&tmp);
    a.push_back(tmp);
  }
  rep(i,M){
    scanf("%d",&tmp);
    b.push_back(tmp);
  }
  vector<int> c;
  c=convolution(a,b);
  rep(i,N+M-2){
    cout << c[i] << " ";
  }
  cout << c[N+M-2] << endl;
  return 0;
}

Measured memory_bytes: 19060
from functools import reduce
from fractions import gcd

def main():
    n = int(input())
    a = sorted(int(i) for i in input().split())
    a0 = a[0]
    if a0 == 1:
        print(reduce(gcd, a[1:]))
        return
    c = []
    for i in range(2, int(a0**0.5) + 1):
        while a0 % i == 0:
            c.append(i)
            a0 //= i
    if a0 != 1:
        c.append(a0)
    d = [0] * len(c)
    for ai in a[1:]:
        for i, ci in enumerate(c):
            if ai % ci == 0:
                ai //= ci
            else:
                d[i] += 1
    e = []
    g = 1
    for k, v in zip(c, d):
        if v == 0:
            g *= k
        elif v == 1:
            e.append(k)
    f = [1] * (n - 1)
    for i, ai in enumerate(a[1:]):
        for ei in e:
            if ai % ei == 0:
                ai //= ei
            else:
                f[i] *= ei
    print(max(g * max(f), reduce(gcd, a[1:])))

if __name__ == '__main__':
    main()

Measured memory_bytes: 16152
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#include <deque>
#include <iterator>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
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 ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

/*
a, bのそれぞれのbitのとりかたを(a, b) = (0,0), (1,0), (1,1)だけにする((0,1)は(1,0)と同じなので)
a+b <= n
a^b <= n
b \in a
これを一般化して
a+b<=s, a^b<=x, b \in aとし、これを満たすa+b, a^bの組み合わせを考える
abの偶奇で場合分け
*/

map<P<ll, ll>, ll> memo;

ll f(ll s, ll x) {
  if ((s==0&&x==0)||(s==1&&x==0)||(s==0&&x==1)) return 1;
  if (memo.find(make_pair(s, x)) != memo.end()) return memo[make_pair(s, x)];
  ll tmpf = f(s/2, x/2);
  if (s>=1 && x>=1) tmpf = (tmpf + f((s-1)/2, (x-1)/2)) % MOD;
  if (s>=2) tmpf = (tmpf + f((s-2)/2, x/2)) % MOD;
  return memo[make_pair(s, x)] = tmpf;
}

int main() {
  ll n; cin >> n;
  cout << f(n, n) << endl;
  return 0;
}


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

N = int(input())
B = list(map(int, input().split()))

ans = 0
tmp = B[N-2]
for i in range(N-2, -1, -1):
    ans += min(tmp, B[i])
    tmp = B[i]

print(ans+B[0])

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

int main() {
	int a[100];
	int b; cin >> b;
	int sum = 0;
	for (int c = 0; c < b; c++) {
		scanf("%d", &a[c]); sum += a[c];
	}
	int e; cin >> e;
	for (int f = 0; f < e; f++) {
		int g, h; cin >> g >> h;
		g--;
		cout << sum - (a[g] - h) << endl;
	}
}

Measured memory_bytes: 256