akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target("avx")
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;i<(n);i++)
#define rrep(i,n) for(int (i)=1;i<=(n);i++)
#define REP(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define MOD 1000000007
#define INF 1e18
#define fcout cout << fixed << setprecision(15)
#define int long long
#define endl "\n"
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
typedef long long ll;
typedef pair<int, int> P;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a/gcd(a,b)*b;};
int mod(int a,int b){return (a+b-1)/b;};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N],const T &val){std::fill((T*)array,(T*)(array+N),val);}
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;};



signed main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);
	
	int n;
	cin >> n;
	int a[n], b[n];
	rep(i, n) cin >> a[i] >> b[i];
	sort(a, a + n);
	sort(b, b + n);
	
	if(n % 2 == 1) cout << b[n/2] - a[n/2] + 1 << endl;
	else cout << (b[n/2-1] + b[n/2]) - (a[n/2-1] + a[n/2]) + 1 << endl;
	return 0;
}

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

#define rep(i, a, b) for (int i = int(a); i < int(b); i++)
#define rrep(i, a, b) for (int i = int(a) - 1; i >= b; i--)
#define sz(x) (int)(x).size()

using namespace std;
using ll = long long;

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

int main() {
  string s;
  cin >> s;
  for (int i = 0; i < sz(s); i += 2) {
    if (s[i] == 'h' && s[i + 1] == 'i') {
    } else {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
#define FOR(i,k,n) for(int i=(k);i<(n);++i)

int BIT[100005],N;

int sum(int i){
    int s=0;
    while(i>0){
        s+=BIT[i];
        i-=i&(-i);
    }
    return s;
}

void add(int i,int x){
    while(i<=N){
        BIT[i]+=x;
        i+=i&(-i);
    }
}

int main(){
    int q;cin>>N>>q;
    int c,x,y;
    FOR(i,0,q){
        cin>>c>>x>>y;
        if(c==0)add(x,y);
        if(c==1)cout<<sum(y)-sum(x-1)<<endl;
    }
    return 0;
}


Measured memory_bytes: 3444
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

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

  double ans;

  if(N % 2 == 0){
    ans = 0.5;
  } else {
    ans = (double)(N / 2 + 1) / (double)N;
  }

  printf("%.10lf\n", ans);
  return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"strconv"
)

func main() {
	for _, leftValue := range MultiplicationTableNum(9) {
		for _, rightValue := range MultiplicationTableNum(9) {
			strLeftVal, strRightVal, strMulti := strconv.Itoa(leftValue), strconv.Itoa(rightValue), strconv.Itoa(Multiplication(leftValue, rightValue))
			fmt.Println(strLeftVal + "x" + strRightVal + "=" + strMulti)
		}
	}
}

func MultiplicationTableNum(num int) []int {
	multiNum := []int{}
	for i := 1; i <= num; i++ {
		multiNum = append(multiNum, i)
	}
	return multiNum
}

func Multiplication(x, y int) int {
	return x * y
}



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

using namespace std;

int main(){
 
  int a,b,c,d;
 
  cin >> a >> b >> c >> d;
  
  if((a+b) > (c+d)){
    cout << "Left" << endl;
  }
  else if((a+b) == (c+d)){
    cout << "Balanced" << endl;
  }
  else
    cout << "Right" << endl;
  
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
using namespace std;

ll n,a[100010],aux,u=1,xi;

ll sig(ll p){
    return (p+1)%n;
}

ll prev(ll p){
    return (p+n-1)%n;
}

int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(0);

    cin >> n;
    for(ll i=0; i<n; i++) cin >> a[i],xi+=u*a[i],u*=-1;
    cout << xi << " ";
    for(ll i=1; i<n; i++) cout << a[i-1]+a[i-1]-xi << " " , xi=a[i-1]+a[i-1]-xi;

    return 0;
}


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

using namespace std;

using ll = long long;

int n, a, b, c;
vector<int> l;

int Solve(int idx, vector<int> &select) {
    if (idx == n) {
        int res = 0, tmp_a = 0, tmp_b = 0, tmp_c = 0;
        for (int i = 0; i < n; ++i) {
            const int s = select[i];
            if (s == 1) {
                if (tmp_a != 0) res += 10;
                tmp_a += l[i];
            }
            else if (s == 2) {
                if (tmp_b != 0) res += 10;
                tmp_b += l[i];
            }
            else if (s == 3) {
                if (tmp_c != 0) res += 10;
                tmp_c += l[i];
            }
        }
        if (tmp_a == 0 || tmp_b == 0 || tmp_c == 0) return INT_MAX;
        res += abs(a - tmp_a) + abs(b - tmp_b) + abs(c - tmp_c);
        return res;
    }

    int res = INT_MAX;
    for (int i = 0; i <= 3; ++i) {
        select[idx] = i;
        res = min(res, Solve(idx + 1, select));
    }
    return res;
}

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

    cin >> n >> a >> b >> c;

    l.resize(n);
    for (int i = 0; i < n; ++i) cin >> l[i];

    vector<int> select(n);
    cout << Solve(0, select) << endl;


    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
const int INF = 2147483647;
const ll MOD = 1000000007;

using namespace std;
template <std::uint_fast64_t MOD> class ModInt {
  using u64 = std::uint_fast64_t;

public:
  ModInt(const u64 val = 0) { value = val % MOD; }

  ModInt operator+(const ModInt rhs) const { return ModInt(*this) += rhs; }
  ModInt operator-(const ModInt rhs) const { return ModInt(*this) -= rhs; }
  ModInt operator*(const ModInt rhs) const { return ModInt(*this) *= rhs; }
  ModInt operator/(const ModInt rhs) const { return ModInt(*this) /= rhs; }

  ModInt &operator+=(const ModInt rhs) {
    value += rhs.value;
    if (value >= MOD) {
      value -= MOD;
    }
    return *this;
  }

  ModInt &operator-=(const ModInt rhs) {
    if (value < rhs.value) {
      value += MOD;
    }
    value -= rhs.value;
    return *this;
  }

  ModInt &operator*=(const ModInt rhs) {
    value = value * rhs.value % MOD;
    return *this;
  }

  ModInt &operator/=(ModInt rhs) {
    *this *= rhs.inv();
    return *this;
  }

  ModInt &operator++(int n) {
    value++;
    if (value >= MOD) {
      value -= MOD;
    }
    return *this;
  }

  ModInt &operator--(int n) {
    if (value == 0) {
      value += MOD;
    }
    value--;
    return *this;
  }

  ModInt inv() { return ModInt::pow(*this, MOD - 2); }

  static ModInt pow(ModInt base, long long int n) {
    ModInt res = ModInt(1);
    while (n) {
      if (n & 1) {
        res *= base;
      }
      base *= base;
      n /= 2;
    }
    return res;
  }

  static ModInt comb(ModInt n, ModInt r) { return comb(n.value, r.value); }

  static ModInt comb(int n, int r) {
    if (n < r)
      return ModInt(0);
    ModInt res = ModInt(1);
    ModInt el = ModInt(1);
    for (int i = 1; i < n + 1; i++) {
      res *= el;
      el++;
    }

    ModInt inv = ModInt(1);
    el = ModInt(1);
    for (int i = 1; i < r + 1; i++) {
      inv *= el;
      el++;
    }
    el = ModInt(1);
    for (int i = 1; i < n - r + 1; i++) {
      inv *= el;
      el++;
    }
    res *= inv.inv();
    return res;
  }

  u64 getValue() const { return value; }

private:
  u64 value;
};

// ここを問題ごとのMODに書き換える
using mint = ModInt<1000000007>;

std::ostream &operator<<(std::ostream &out, const mint &m) {
  out << m.getValue();
  return out;
};

std::istream &operator>>(std::istream &in, mint &m) {
  uint_fast64_t i;
  in >> i;
  m = mint(i);
  return in;
}

int ma = 2000002;
vector<mint> ex(ma), inv(ma);

mint g(int a, int b) {
  mint ret(0);
  REP(i, a + 1) { ret += ex[b + i + 1] * inv[b] * inv[i + 1]; }
  return ret;
}

int main() {

  mint tmp(1);
  ex[0] = mint(1);
  inv[0] = mint(1);
  FOR(i, 1, ma) {
    tmp *= mint(i);
    ex[i] = tmp;
    inv[i] = tmp.inv();
  }
  mint ans(0);
  int r1, r2, c1, c2;
  cin >> r1 >> c1 >> r2 >> c2;
  ans = g(r2, c2) - g(r2, c1 - 1) - g(r1 - 1, c2) + g(r1 - 1, c1 - 1);
  cout << ans << endl;

  return 0;
}


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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s, t;
  cin >> s >> t;
  int n = (int)s.size();
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] != t[i]) {
      ans++;
    }
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 3772
#include<cstdio>
#include<algorithm>
#include<vector>
#include<string>
#include<iostream>
#include<queue>
#include<map>
#include<set>
#include<complex>
#include<stack>

using namespace std;

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


int main(){
	
	int n;
	cin>>n;
	
	rep(loop,n){
		vector<int> ans;
		vector<int> a;
		vector<int> b;
		
		string c,d;
		cin>>c>>d;
		
		rep(i,c.size()){
			a.push_back(c[c.size()-1-i]-'0');
		}
		rep(i,d.size()){
			b.push_back(d[d.size()-1-i]-'0');
		}
		
		
		int kuri = 0;
		while(!a.empty() || !b.empty() || kuri!=0){
			int sum = kuri;
			kuri = 0;
			
			if(!a.empty()){
				sum += a[0];
				a.erase(a.begin());
			}
			
			if(!b.empty()){
				sum += b[0];
				b.erase(b.begin());
			}
			
			ans.push_back(sum%10);
			kuri += sum/10;
		}
		
		if(ans.size()>80)puts("overflow");
		else{
			rep(i,ans.size()){
				printf("%d",ans[ans.size()-1-i]);
			}puts("");
		}
	}
	
}

Measured memory_bytes: 1240
import java.util.*;

public class Main {

    static int gcd (int a, int b) {return b>0?gcd(b,a%b):a;}
    static int mod = 1000000007;

    public static void main(String[] args)  {
        Scanner sc = new Scanner(System.in);
        int R = sc.nextInt();

        System.out.println(2 * R * Math.PI);

    }

}









Measured memory_bytes: 35892
#include<bits/stdc++.h>
using namespace std;
#define ll int
int main()
{
  ll n;cin>>n;
  ll a[n];
  ll k;cin>>k;
  
  for(int i=0;i<n;i++)cin>>a[i];
  
  ll dp[n];
  dp[0]=0;
  dp[1]=abs(a[0]-a[1]);
  
for(ll i=2;i<n;i++)
{
  dp[i]=999999999;
  for (ll j=max(0,i-k);j<i;j++)
  	dp[i]=min(dp[j]+abs(a[i]-a[j]),dp[i]);
}
cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 4372
// AOJ 1129
#include<iostream>
#include<vector>
using namespace std;
#define REP(i,n) for(int i=0;i<(int)(n);i++)

const int NMAX = 100;
int card[NMAX];

int main() {
  int n, r;
  while (cin >> n >> r and n) {
    for (int i = 1; i <= n; i++) {
      card[i] = n + 1 - i;
    }

    REP (R, r) { 
      int p, c;
      cin >> p >> c;
      vector<int> temp1, temp2;
      for (int i = 1; i <= p - 1; i++) {
        temp1.push_back(card[i]);
      }

      for (int i = p; i < p + c; i++) {
        temp2.push_back(card[i]);
      }

      temp2.insert(temp2.end(), temp1.begin(), temp1.end());
      
      for (int i = 0; i < temp2.size(); i++) {
        card[i + 1] = temp2[i];
      }

    }
    cout << card[1] << endl;
  }
}

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

public class Main {

	private class DisjointSet {
		
		int[] p, rank;
		
		public DisjointSet(int size) {
			p = new int[size];
			rank = new int[size];
			for (int i = 0; i < size; i++) {
				makeSet(i);
			}
		}

		private void makeSet(int x) {
			p[x] = x;
			rank[x] = 0;
		}
		
		public boolean same(int x, int y) {
			return findSet(x) == findSet(y);
		}

		private int findSet(int x) {
			int parent = p[x];
			int v = x;
			while (parent != v) {
				parent = p[v];
				v = p[parent];
				p[x] = v;
			}
			return parent;
		}
		
		public void unite(int x, int y) {
			link(findSet(x), findSet(y));
		}

		private void link(int x, int y) {
			if (rank[x] > rank[y]) {
				p[y] = x;
			} else {
				p[x] = y;
				if (rank[x] == rank[y]) {
					rank[y]++;
				}
			}
		}
	}
	
	public static void main(String[] args) throws IOException {
		new Main().run();
	}
	
	private void run() throws IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(reader.readLine());
		int n = Integer.parseInt(st.nextToken());
		DisjointSet ds = new DisjointSet(n);
		int q = Integer.parseInt(st.nextToken());
		for (int i = 0; i < q; i++) {
			st = new StringTokenizer(reader.readLine());
			int c = Integer.parseInt(st.nextToken());
			int x= Integer.parseInt(st.nextToken());
			int y = Integer.parseInt(st.nextToken());
			if (c == 0) {
				ds.unite(x, y);
			} else {
				System.out.println(ds.same(x, y)?"1":"0");
			}
		}
		reader.close();
	}
}


Measured memory_bytes: 60764
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define ll long long
#define P pair<int,int>
#define fast_io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
const int MOD = 1000000007;
const int INF = 2002002002;
const ll LLINF = 9009009009009009009;
using namespace std;
class UnionFind {
    // 各ノードが根である時の高さ
    // ノードが根でないときは意味をなさない
    vector<int> rank;
    // 各ノードが属する木の根
    // findSetするときのみ更新される
    vector<int> p;
    // 二つの根を結合
    void link(int rx, int ry) {
        if (rx == ry) return;
        if (rank[rx] > rank[ry]) p[ry] = rx;
        else p[rx] = ry;
        if (rank[rx] == rank[ry]) rank[ry]++;
    }
public:
    //　根を作成
    // その木の高さは0
    void makeSet(int x) {
        p[x] = x;
        rank[x] = 0;
    }
    // 初期化
    // 入力サイズ分のノードを確保
    // それらのノードをそれぞれ根とする木を作成
    // ノードの値は 0 ~ size-1
    UnionFind(int size) {
        rank.resize(size, 0);
        p.resize(size, 0);
        rep(i,size) makeSet(i);
    }
    // あるノードの属する木の根を返す
    // 根を探す過程で途中のノードの親も更新
    int findSet(int x) {
        if (x != p[x]) p[x] = findSet(p[x]);
        return p[x];
    }
    // 二つのノードが同じ木にあるか判定
    bool same(int x, int y) {return findSet(x) == findSet(y);}
    // 二つのノードの属する木を結合
    void unite(int x, int y) {link(findSet(x), findSet(y));}
};
struct Edge {
    int from, to, cost;
    Edge(int f,int t, int c) {
        from = f;
        to = t;
        cost = c;
    }
    bool operator <(const Edge &e) const {return (cost < e.cost);}
    bool operator >(const Edge &e) const {return (cost > e.cost);}
};

ll kruskal(int v, const vector<Edge> &e) {
    UnionFind tree(v);
    ll ans = 0;
    for (auto edge: e) {
        if (!tree.same(edge.from, edge.to)) {
            ans += edge.cost;
            tree.unite(edge.from, edge.to);
        }
    }
    return ans;
}
int main() {
    fast_io
    int n;
    cin >> n;
    vector<P> x, y;
    int xtmp, ytmp;
    rep(i,n) {
        cin >> xtmp >> ytmp;
        x.emplace_back(xtmp, i);
        y.emplace_back(ytmp, i);
    }
    sort(x.begin(), x.end());
    sort(y.begin(), y.end());

    auto cost = [](int a, int b) {return abs(a - b);};
    
    vector<Edge> e;
    rep(i,n-1) {
        e.emplace_back(x[i].second, x[i+1].second, cost(x[i].first, x[i+1].first));
        e.emplace_back(y[i].second, y[i+1].second, cost(y[i].first, y[i+1].first));
    }
    sort(e.begin(), e.end());
    cout << kruskal(n, e) << endl;
    return 0;
}

Measured memory_bytes: 7144
def round(points)
  3.times.each_with_object([points]){ |_, obj| obj << obj[-1].map{ |p| [-p[1], p[0]] } }
end

def same(a, b)
  a.size == b.size && a.zip(b).map { |(xa, ya), (xb, yb)| [xb - xa, yb - ya] }.uniq.size == 1
end

while (n = gets.to_i) != 0
  target = gets.to_i.times.map{ gets.split.map(&:to_i) }
  cand = n.times.map{ gets.to_i.times.map{ gets.split.map(&:to_i) } }
  (1..n).each do |i|
    [target, target.reverse].flat_map{ |t| round(t) }.each do |t|
      if same(t, cand[i - 1])
        puts i
        break
      end
    end
  end
  puts '+++++'
end

Measured memory_bytes: 8756
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
vector<Int> divisors(Int x)
{
    vector<Int> ans;
    for (Int i = 1; i * i <= x; i++) {
        if (x % i == 0) {
            if (i * i == x) {
                ans.push_back(i);
            } else {
                ans.push_back(i); ans.push_back(x / i);
            }
        }
    }
    return ans;
}
int main()
{
    Int N; cin >> N;
    auto D = divisors(N);
    Int ans = 0;
    for (auto d : D) {
        Int m = N / d - 1;
        if (m > 0 && N / m == N % m) {
            ans += m;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
import sys
N = int(sys.stdin.readline().rstrip())
mod = 10**9+7

from collections import defaultdict
from itertools import product

A = [('A','G','C'),('G','A','C'),('A','C','G')]

for i in range(3,N+1):
    if i == 3:
        d = defaultdict(int)  # d[a] = aで終わる条件を満たす文字列の個数
        for a in list(product(['A','C','G','T'],repeat=3)):
            d[(a[0],a[1],a[2])] = 1
        for a in A:
            d[a] = 0
    else:
        new_d = defaultdict(int)
        for a in ['A','C','G','T']:
            for b in list(product(['A','C','G','T'],repeat=3)):
                if not ((b[1],b[2],a) in A or (b[0],b[1],a) == ('A','G','C') or (b[0],b[2],a) == ('A','G','C')):
                    new_d[(b[1],b[2],a)] += d[b]
                    new_d[(b[1], b[2], a)] %= mod
        d = new_d

print(sum(d.values()) % mod)

Measured memory_bytes: 75460
#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <cstring>
#include <functional>
#include <cmath>
#include <complex>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define rep1(i,n) for(int i=1;i<=(n);++i)
#define all(c) (c).begin(),(c).end()
#define fs first
#define sc second
#define pb push_back
#define show(x) cout << #x << " " << x << endl
int N,M;
bool dp[5001][1<<12];
bool b[5001][12];
string a[12];
int main(){
	while(true){
		cin>>N>>M;
		if(N==0) break;
		rep(i,N) cin>>a[i];
		string s;
		rep(i,M){
			string o;
			cin>>o;
			s+=o;
		}
		M=s.size();
		rep(i,M+1) rep(j,1<<N) dp[i][j]=0;
		rep(i,M+1) dp[i][0]=1;
		rep(i,M+1) rep(j,N){
			b[i][j]=0;
			if(i+a[j].size()<=M&&s.substr(i,a[j].size())==a[j]) b[i][j]=1;
		}
		rep(i,M){
			rep(j,1<<N){
				if(!dp[i][j]) continue;
				bool is[12];
				rep(k,N){
					if((j>>k)&1) continue;
					if(b[i][k]) dp[i+a[k].size()][j+(1<<k)]=1;
				}
			}
		}
		int ans=0;
		rep(i,M+1) if(dp[i][(1<<N)-1]) ans++;
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 21296
#include <bits/stdc++.h>
using namespace std;
#ifdef _DEBUG
#define dlog(str) cout << "====" << str << endl;
#else
#define dlog(str)
#endif
#define INF 999999999
#define MOD 1000000007
#define LLI long long int
#define REP(i, n) for(LLI i = 0, i##_l = (n); i < i##_l; i++)
#define FOR(i, s, e) for(LLI i = s, i##_l = (e); i < i##_l; i++)
#define _min(a, b) ((a < b) ? a : b)
#define _max(a, b) ((a < b) ? b : a)
#define chmax(a, b) a = _max(a, b)
#define chmin(a, b) a = _min(a, b)
#define bit(a, shift) ((a>>shift)&1))
#define pm(a) ((a) ? 1 : -1)
#define SORT(v) sort(v.begin(), v.end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
// int 2.14E±9    lli 9.2E±18    double 1.7E±380

std::vector<bool> p;

LLI mpow(LLI a, LLI b) {
    LLI ret = 1;
    REP(i, b) {
        ret *= a;
    }
    return ret;
}

void sieve(size_t max) {
    if(max + 1 > p.size()) {      // resizeで要素数が減らないように
        p.resize(max + 1, true);  // pに必要な要素数を確保
    }
    p[0] = false;  // 0は素数ではない
    p[1] = false;  // 1は素数ではない

    for(size_t i = 0; i <= max; ++i)              // 0からmaxまで全て調べる
        if(p[i])                                  // iが素数ならば
            for(size_t j = i + 1; j <= max; ++j)  //i+1からmaxまで全て調べる
                if(j % i == 0)                    // iの倍数は
                    p[j] = false;                 // 素数ではない
}

int main() {
    cout << fixed << setprecision(10);
    LLI n;
    cin >> n;

    sieve(10000);

    vector<LLI> list;
    REP(i, 10000) {
        if(p[i]) {
            list.push_back(i);
        }
    }

    vector<LLI> a(n);
    vector<LLI> pc(1000001);
    REP(i, n) {
        cin >> a[i];

        // 素因数分解
        LLI t = a[i];

        for(LLI pn : list) {
            if(t == 1) break;
            LLI tc = 0;
            while(t % pn == 0) {
                t /= pn;
                tc++;
            }
            chmax(pc[pn], tc);
        }
        if(t != 1) {
            chmax(pc[t], 1);
        }
    }

    LLI mnum = 1;

    vector<LLI> ml;
    REP(i, 1000001) {
        REP(j, pc[i]) {
            ml.push_back(i);
        }
    }

    //cout << mnum << endl;
    LLI ans = 0;
    REP(i, n) {
        int at  = a[i];
        int mul = 1;

        for(LLI fac : ml) {
            if(at % fac == 0) {
                at /= fac;
            } else {
                mul = (mul * fac) % MOD;
            }
        }

        ans += mul;
        ans %= MOD;
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 8320
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <fstream>
#include <array>
#include <map>
#include <queue>
#include <time.h>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#include <assert.h>
#include <unordered_set>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) (min(a,b) <= (x) && (x) <= max(a,b)) //hei
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MODU 998244353LL 
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int
#define PI 3.141592653589
 
 
#define izryt bool
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T & val) {
	std::fill((T*)array, (T*)(array + N), val);
}
 
//[a, b)
#define Getsum(ar, a,b) (ar[b] - ar[a])
#define INF 10000000000000000LL
#define chmax(a,b) a = max(a,b)
#define chmin(a,b) a = min(a,b)
 
struct Edge {
	int from, to;
	ll w;
	bool operator<(const Edge& rhs) const {
		return MP(w, MP(from, to)) < MP(rhs.w, MP(rhs.from, rhs.to));
	}
 
};
typedef vector<vector<Edge>> Graph;
typedef unsigned long long ull;
 
 
inline ll ksum(ll n, ll k){
  return k * (2*n - k - 1);
}

pii updtp2(pii p, int nw){
  if(p.first == -1) p.first = nw;
  else if(p.second == -1) p.second = nw;
  else if(p.first >= nw) {
    p.second = p.first;
    p.first = nw;
  }
  else if(p.second >= nw) p.second = nw;
  return p;
}
 
#define isValid(y,x) (y >=0 && y < n && x >= 0 && x < m)

const pii Dir[4] = {{-1,0}, {0,1}, {1,0}, {0,-1}};

int main(){
	int n,k;
    cin >> n >> k;
    vector<int> a(n);
    REP(i,n) cin >> a[i];

    REP(_,k){
        vector<int> na(n);
        REP(j, 2)
        {
            vector<int> s(n + 1);
            int sum = 0;
            REP(i, n)
            {
                if(j) na[i]--;
                sum++;
                sum += s[i];
                s[min(i + a[i] + 1, n)] += -1;

                na[i] += sum;
            }
            reverse(ALL(a));
            reverse(ALL(na));
        }
        a = na;
        bool f = true;
        REP(i, n) f &= a[i] == n;
        if(f) break;
        //cout << _ << endl;
    }
    REP(i,n) cout << a[i] << " ";
    cout << endl;
	return 0;
} 

Measured memory_bytes: 5572
s = input()
q = int(input())
reverse_now = 0
first = ""
latter = ""
for i in range(q):
    k = list(input().split())
    if k[0] == "1":
        reverse_now = 1 - reverse_now
    else:
        f,c = k[1], k[2]
        if f == "1" and reverse_now == 0:
            first = c + first
        if f == "1" and reverse_now == 1:
            latter += c
        if f == "2" and reverse_now == 0:
            latter +=  c
        if f == "2" and reverse_now == 1:
            first = c + first
if reverse_now == 1:
    ans = list(first + s + latter)
    ans.reverse()
    ans = "".join(ans)
else:
    ans = first + s + latter
print(ans)

Measured memory_bytes: 5912
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#define fr(i,a,b) for(int i=a;i<=b;i++)
#define N 100010
using namespace std;
string s;
int main(){
	int n,m;
	cin>>s;
	n=s.size();
	cout<<s[0]<<n-2<<s[n-1];
	return 0;
}

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

const int mod=1e9+7;
int modex(int b, int e){
	int h = 1;
	while(e){
		if(e&1)
			h=(long long)h*b %mod;
		b=(long long)b*b %mod;
		e>>=1;
	}
	return h;
}
int invs(int x){
	return modex(x, mod-2);
}
const int coefsEven[]={
	1024, 9984, 44032, 115920, 202380, 246047, 212681, 130923, 56485, 16445, 3003, 297, 11, 0, 0, 0
};
const int coefsOdd[]={
	1024, 10496, 48896, 136752, 255420, 335137, 316184, 215644, 105248, 35750, 8008, 1068, 68, 1, 0, 0
};
int main(){
	int t=1;
	scanf("%d", &t);
	while(t--){
		int n;
		scanf("%d", &n);
		if(n&1){
			n/=2;n++;
			long long ans=coefsOdd[0];
			for(int i = 1;i < 16;i ++){
				ans=ans*(n-16+i) %mod *invs(16-i) %mod;
				ans+=coefsOdd[i];
			}
			printf("%lld\n", ans);
		}else{
			n/=2;n++;
			long long ans=coefsEven[0];
			for(int i = 1;i < 16;i ++){
				ans=ans*(n-16+i) %mod *invs(16-i) %mod;
				ans+=coefsEven[i];
			}
			printf("%lld\n", ans);
		}
	}
}

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


int main(){
  int A,B,C;
  cin>>A>>B>>C;
  if(A==B&&B==C) cout<<"No"<<endl;
  else if(A==B||A==C||B==C) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;

}



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

N, A, B, C, D = map(int, input().split())
S = input()

if '##' in S[A:max(C, D)]:
    print('No')
elif C<D:
    print('Yes')
else:
    if '...' in S[B-2:D+1]:
        print('Yes')
    else:
        print('No')

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

using namespace std;
using int64 = long long;

struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;

int main() {
    int n;
    cin >> n;
    cout << (n%1000==0?0:1000-n%1000) << endl;
}


Measured memory_bytes: 3188
#include<iostream>
#include<string>
#include<vector>
#include <algorithm>
#include<deque>

//マクロ
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
#define REPS(i,n) for(int i=1; i<=(int)(n); ++i)
#define RREP(i,n) for(int i=(int)(n)-1; i>=0; --i)
#define RREPS(i,n) for(int i=(int)(n); i>0; --i)
#define FOR(i,s,e) for(int i=(int)(s); i<(int)(e); ++i)
#define RFOR(i,s,e) for(int i=(int)(e)-1; i>=(int)(s); --i)

#define All(a) (a).begin(),(a).end()

//定数
#define INF 1e9
#define MOD (int)(1e9+7)

typedef long long ll;
typedef unsigned long long ull;
using namespace std;

//とりあえず書いておく変数
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

//今回の変数

//使用する関数
template<class T>bool chmax(T &a, const T &b) {
	if (a < b) { a = b; return 1; }
	return 0;
}
template<class T>bool chmin(T &a, const T &b) {
	if (a > b) { a = b; return 1; }
	return 0;
}


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

	if (s == "Sunny"){
		cout << "Cloudy" << endl;
	}
	else if (s == "Cloudy") {
		cout << "Rainy" << endl;
	}else{
		cout << "Sunny" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
void init(){
  cin.tie(0);
  ios::sync_with_stdio(false);
}



template< typename T >
struct edge {
  int src, to;
  T cost;

  edge(int to, T cost) : src(-1), to(to), cost(cost) {}

  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

  edge &operator=(const int &x) {
    to = x;
    return *this;
  }

  operator int() const { return to; }
};

template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WG = vector< Edges< T > >;
using UG = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;

bool flag;

void dfs(int x,int y,int b[],UG es){


  for(auto e:es[x]){
    if(e==y) continue;
    if(b[e]==0){
      b[e]=-1*b[x];
      dfs(e,x,b,es);
    }else if(b[x]*b[e]!=-1){
     
      flag=false;
    }
  }

 }

void f(int n,int m){
  int b[1100]={};
  flag= true;
  UG es(n);
  rep(i,m){
    int x,y;
    cin>>x>>y;
    x--;y--;
    es[x].PB(y);
    es[y].PB(x);
  }
  b[0]=1;
  dfs(0,-1,b,es);

  if(!flag){
    cout<<0<<endl;
  }else{
    int x=0,y=0;
    rep(i,n){
      if(b[i]==1) x++;
      else if(b[i]==-1) y++;
    }
//    cout<<" "<<x<<' '<<y<<endl;
    if(x%2&&y%2){
      cout<<0<<endl;
    }else if(y%2){
      cout<<1<<endl;
      cout<<x/2<<endl;
    }else if(x%2){
      cout<<1<<endl;
      cout<<y/2<<endl;
    }else{

      cout<<1+(x!=y)<<endl;
      cout<<min(x/2,y/2)<<endl;
      if(x!=y)
        cout<<max(x/2,y/2)<<endl;
    }
  }

}


main(){
  int n,m;
  
  while(true){
    cin>>n>>m;
    if(n==0) break;
    f(n,m);
  }
}



Measured memory_bytes: 16160
n = int(input())
numberlist =  list(map(int, input().split()))
ans = 'APPROVED'
for i in range(n):
    if numberlist[i] % 2 == 0:
        if numberlist[i] % 3 == 0 or numberlist[i] % 5 == 0:
            ans = 'APPROVED'
        else:
            ans = 'DENIED'
            break
print(ans)

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

const int N = 415;

ll a[N], sum[N][N], cost[N][N];

int main() {
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    for (int i=0; i<n; i++) {
        cin >> a[i];
    }
    for (int i=0; i<n; i++) {
        sum[i][i] = a[i];
        for (int j=i+1; j<n; j++) {
            sum[i][j] = sum[i][j-1] + a[j];
        }
    }
    for (int d=1; d<n; d++) {
        for (int i=0, j=i+d; j<n; i++, j++) {
            cost[i][j] = 1ll << 60;
            for (int k=i; k<j; k++) {
                ll tmp = cost[i][k] + cost[k+1][j] + sum[i][k] + sum[k+1][j];
                cost[i][j] = min(cost[i][j], tmp);
            }
        }
    }
    cout << cost[0][n-1] << '\n';
}


Measured memory_bytes: 2816
n,x = (int(i) for i in input().split())
if x==1 or x==2*n-1: print("No")
else:
	print("Yes")
	for i in range((x+n-1)%(2*n-1),0,-1): print(i)
	for i in range(2*n-1,(x+n-1)%(2*n-1),-1): print(i)

Measured memory_bytes: 4636
use proconio::input;
use proconio::marker::Usize1;
use std::collections::BinaryHeap;
use std::cmp::{Reverse, min};

fn main()
{
    input! {
    n:usize,
    m:usize,
    (s,t):(Usize1,Usize1),
    edge:[(Usize1,Usize1,i64,i64);m],
    }
    let inf = 10i64.pow(15);
    let mut v = vec![vec![]; n];
    for (a, b, c, d) in edge {
        v[a].push((b, c, d));
        v[b].push((a, c, d));
    }

    let mut len_s = vec![inf; n];
    let mut len_t = vec![inf; n];

    len_s[s] = 0;
    let mut q = BinaryHeap::new();
    q.push(Reverse((0, s)));
    while let Some(Reverse((dist, idx))) = q.pop() {
        if len_s[idx] < dist {
            continue;
        }
        for &(nxt, cost, _) in v[idx].iter() {
            let dist = dist + cost;
            if len_s[nxt] <= dist {
                continue;
            }
            len_s[nxt] = dist;
            q.push(Reverse((dist, nxt)));
        }
    }
    len_t[t] = 0;
    let mut q = BinaryHeap::new();
    q.push(Reverse((0, t)));
    while let Some(Reverse((dist, idx))) = q.pop() {
        if len_t[idx] < dist {
            continue;
        }
        for &(nxt, _, cost) in v[idx].iter() {
            let dist = dist + cost;
            if len_t[nxt] <= dist {
                continue;
            }
            len_t[nxt] = dist;
            q.push(Reverse((dist, nxt)));
        }
    }

    let mut ans = vec![inf; n + 1];
    for i in (0..n).rev() {
        ans[i] = min(ans[i + 1], len_s[i] + len_t[i]);
    }

    for i in 0..n {
        println!("{}", inf - ans[i]);
    }
}

Measured memory_bytes: 17288
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

while True:
    n = inp()
    if n == 0:
        break
    else:
        aa = [inp() for i in range(n)]
        aa.sort()
        print(sum(aa[1:n-1])//(n-2))



Measured memory_bytes: 7460
#include<cstdio>
#include<vector>
#include<string>
#include<iostream>
#include<iomanip>
#include<algorithm>

using namespace std;

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

  int M, D;
  
  cin>>M>>D;

//  cout<<M<<" "<<D<<"\n";
  
  int count=0;
  int d1,d10;
  for(int i=22;i<=D;i++){
    d10=i/10;
    d1=i%10;
//    cout<<i<<" "<<count<<" "<<d10<<" "<<d1<<"\n";
    if(d1<2)
      continue;
    if(d10*d1<=M){
      count++;
    }
  }
  cout<<count<<"\n";
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i, a, b) for (int i = a; i < b; i++)
#define VREP(it, v) for (vector<int>::iterator it = v.begin(); it != v.end(); it++)
typedef pair<ll,ll> pi;
typedef vector<ll> vi;

template <typename T>
using pbds_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

template <typename K, typename V>
using pbds_map = tree<K, V, less<K>, rb_tree_tag, tree_order_statistics_node_update>;
ll n;
ll ans = 0;
ll a, b;
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> n;
	ans = n*n*n - n;
	ans /= 6;
	ans += (n*(n + 1))/2;
	REP(i, 0, n - 1){
		cin >> a >> b;
		if (b < a) swap(a, b);
		ans -= a*(n + 1 - b);
	}
	cout << ans << endl;
}

Measured memory_bytes: 3664
import sys
input = sys.stdin.readline
from collections import Counter

#intl = [1,1,1,2,2,2,2,2,2,2,3,3,3,3,4,4,4]
#print(ints[1]) # 3

n, k = map(int, input().replace("\n","").split())

snuke =  [0] * n
# print(snuke)

havelist = []

for i in range(k):
    d = int(input())
    a = list(map(int, input().replace("\n","").split()))

    havelist.extend(a)

have = len(list(set(havelist)))
print(n-have)

Measured memory_bytes: 67924
N = int(input())
P = [list(map(int,input().split())) for i in range(N)]

a=[P[0][0]]*N
b=[P[0][1]]*N
c=[P[0][2]]*N

for i in range (1, N):
	a[i] = max(b[i-1], c[i-1])+P[i][0]
	b[i] = max(a[i-1], c[i-1])+P[i][1]
	c[i] = max(a[i-1], b[i-1])+P[i][2]

print(max(a[N-1], b[N-1], c[N-1]))

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

int main()
{
  int n;
  cin >> n;
  vector<int64_t> as(n);
  for (int i = 0; i < n; i++)
  {
    cin >> as[i];
  }
  int64_t ans = as[0] / 2;
  as[0] %= 2;
  for (int i = 1; i < n; i++)
  {
    if (as[i - 1] && as[i])
    {
      ans++;
      as[i]--;
    }
    ans += as[i] / 2;
    as[i] %= 2;
  }
  cout << ans << endl;
}

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

int main(){
  int a,b,c,d,e,k;
  cin >> a >> b >> c >> d >> e >> k;
  
  if(e-a<=k){
    cout << "Yay!" << endl;
  }else{
    cout << ":(" << endl;
  }
}

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll n,a=0,b=0,mid=0;cin>>n;
  lvector v(n,0);rep(i,n) cin>>v[i];
  sort(v.begin(),v.end());a=v[n-1];
  ll l=0,r=n-2;
  while(r-l>1) {
    mid=(l+r)/2;
    if(v[mid]>=a/2) r=mid;
    else l=mid;
  }
  if(abs(v[r]-a/2)<=abs(v[l]-a/2)) b=v[r];else b=v[l];
  printf("%lld %lld\n",a,b);
  return 0;
}

Measured memory_bytes: 1024
n,m,k = map(int,input().split())
flag = False

for i in range(n+1):
    for j in range(m+1):
        temp = i*m + j*n -2*i*j
        if temp == k:
            # print(temp,i,j)
            flag = True
            break
    if flag:
        break

if flag:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3060
// -----------------------------------
// Author     : MatsuTaku
// Affiliation: Tokushima University
// Country    : Japan
// Date       : 04/04/2020
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

  int x,y,z; cin>>x>>y>>z;
  cout << z << " " << x << " " << y << endl;

  return 0;
}


Measured memory_bytes: 256
import sys
from itertools import permutations, combinations
  
def solve():
    input = sys.stdin.readline
    N = int(input())
    A = dict()
    for i in range(N):
        A[i] = dict()
        ain = [int(j) for j in input().split()]
        for j in range(N): A[i][j] = ain[j]

    length = 0
    possible = True
    for a, b in combinations(range(N), 2):
        Lab = A[a][b]
        create_pass = True
        for k in range(N):
            if k != a and k != b:
                if Lab >  A[a][k] + A[k][b]:
                    possible = False
                    break
                elif Lab ==  A[a][k] + A[k][b]:
                    create_pass = False
                    break
        if create_pass: length += Lab
        if not possible:
            print(-1)
            break
    else: print(length)
    
    return 0
  
if __name__ == "__main__":
    solve()


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

using std::cin;
using std::cout;
using LL = long long;
using pii = std::pair<int, int>;

const int mn = 1e5 + 5;
int n;
int a[mn];

int main() {
#ifdef trote
    freopen("../1.txt", "r", stdin);
#endif
    cin.sync_with_stdio(0);
    int sum=0;
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i],sum+=a[i];
    int d=1e9,who=0;
    for(int i=1;i<=n;i++){
        int delta=abs(a[i]*n-sum);
        if (delta<d){
            who=i;
            d=delta;
        }
    }
    printf("%d\n",who-1);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define F first
#define S second
#define mp make_pair
#define pb push_back
//#define ll __int128
#define ll long long
#define LEFT(a) ((a)<<1)
#define RIGHT(a) (LEFT(a) + 1)
#define MID(a,b) ((a+b)>>1)
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define y1 y122
#define int long long

/*
#pragma GCC optimize ("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx2,fma")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC target ("avx2")
#pragma GCC optimization ("unroll-loops")
/*
#pragma comment(linker, "/STACK: 20000000005")
*/


using namespace std;


const int N = 200005, MOD = 1e9 + 7;

int D, n;
int a[N];

main()
{
    ios_base::sync_with_stdio(0);
    cin >> D >> n;
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    int ans = 0;
    sort (a + 1, a + n + 1);
    a[n + 1] = a[1] + D;
    for (int i = 1; i <= n; i++)
        ans = max (ans, a[i + 1] - a[i]);
    cout << D - ans << endl;
    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
    using namespace std;
    int main()
    {	int n;
     	cin >> n;
     	float ans=0;
      for(int i=1;i<=n;i++)
      {	
        float temp;
        cin >>temp;
       ans = ans + (1/temp);
       //cout << ans << " ";

      }
      //cout << ans << " ";
     cout << (1/ans) << endl;
     return 0;
    }

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1000000010
#define EPS 1e-9
#define F first
#define S second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"

typedef pair<int,int> PII;
typedef pair<int,string> PIS;
typedef pair<string,int> PSI;


const int MAX=2500010;

int fac[MAX],finv[MAX],inv[MAX];
 
void t(){
  fac[0]=fac[1]=1;
  finv[0]=finv[1]=1;
  inv[1]=1;
  repi(i,2,MAX){
    fac[i]=fac[i-1]*i%MOD;
    inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
    finv[i]=finv[i-1]*inv[i]%MOD;
  }
}
 
int calc(int n,int k){
  if(n<k) return 0;
  if(n<0 || k<0) return 0;
  return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
 


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  t();
  int n,m;
  cin>>n>>m;
  int num=1;
  rep(i,n){
    num*=(m-i);
    num%=MOD;
  }
  int ans=num-1;
  int num2=1;//組み合わせ
  rep(i,n-1){
    num2*=(m-i-1);
    num2%=MOD;
  }
  //cout<<num2<<endl;
  int discount=0;
  int p=-1;
  rep(i,n-1){
    p*=(-1);
    int num3=calc(n,i+1);
    num3=num3*(num2-1)%MOD;
    num3*=p;
    discount+=num3;
    while(discount<MOD) discount+=MOD;
    discount%=MOD;
    num2*=inv[m-i-1];
    num2%=MOD;
    // cout<<discount<<endl;
  }
  discount=ans-discount;
  while(discount<MOD) discount+=MOD;
  cout<<(num*discount)%MOD<<endl;
  
  

  return 0;
}


Measured memory_bytes: 62244
#include<bits/stdc++.h>
#define lld long long int
#define ld long double
#define mod 1000000007
#define all(v) v.begin(),v.end()
#define rep(i,a,b)	for(lld i=a;i<=b;i++)
#define repr(i,a,b) for(lld i=a;i>=b;i--)
#define ar array
#define pb push_back
#define mp make_pair
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
lld n,m;
lld arr[300000];
string st;
int main()
{
     ios;
     lld TESTS,q,a,s,b,r,k,c,p,h,w,d,x,y,z,xs,ys,t;
     TESTS=1;
//     ans=0;
     //cin>>TESTS;
   //  memset(dpt,0,sizeof(dpt));memset(dput,0,sizeof(dput));
    // memset(dsu1,0,sizeof(dsu1));
     while(TESTS--)
     {
         cin>>st;
         (st[2]==st[3]&&st[4]==st[5])?cout<<"Yes":cout<<"No";
     }
    return 0;
}


Measured memory_bytes: 256
n = int(input())
s = input()

res = [None] * n

for i in range(n):
    l = s[:i]
    r = s[i:]
    cnt = 0
    chk_s = ""

    for j in range(i):
        if not l[j] in chk_s:
            chk_s += l[j]
            if l[j] in r:
                cnt += 1

    else:
        res[i] = cnt

print(max(res))


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n, m;
	cin >> n >> m;
	int a[110];
	for (int i = 0; i<n; i++) cin >> a[i]; //配列に入力を取り込み
	int sum = 0;  //投票合計
	for (int i=0; i<n; i++){
		sum += a[i];
	}
	double bl = (double)sum/(4*m);  //最低得票数
  //cout << bl << endl;
    int cnt = 0;
    sort(a, a + n, greater<int>());
	for (int j=0; j<m;j++){
		//大きいものから最低得票数より大きいかを判定する
		if (a[j] >= bl) cnt++;
	}
	if (cnt >= m) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
        int H,W,i,j;
        
        scanf("%d %d",&H,&W);
        
        while(1){
        	//HとWの値が0の時抜ける
        	if(H==0 && W==0){
        	   break;
        	}
        	//iがH以下の間
        	for(i=1;i<=H;i++){
        		//iが奇数の時
        		if(i%2==1){
        			for(j=1;j<=W;j++){
        				//jが奇数の時、#を出力
        				if(j%2==1){
        					printf("#");
        		        }
        			else  {
        				//jが偶数の時、.を出力
        				printf(".");
        			}
        		}
        				printf("\n");
        	}
        	//iが奇数の時
        	else {
        		for(j=1;j<=W;j++){
        			//jが奇数の時、.を出力
        			if(j%2==1){
        			 printf(".");
        		    }
        			else  {
        			//jが偶数の時、#を出力
        			 printf("#");
        			}
        		}
        		printf("\n");
        	}
        }
          printf("\n");
        //次の入力
          scanf("%d %d",&H,&W);
        }
        return 0;
}



Measured memory_bytes: 2044
N=int(input())
arr = [[] for i in range(N+1)]
bm = [0 for i in range(N+1)]
maxs = 0
cnt = 0

def slv(curInd):
  global N,arr,bm,maxs,cnt
  if curInd==N:
    good = True
    for i in range(N+1):
      if good == False:
        break
      if bm[i]:
        for el in arr[i]:
          if bm[el[0]]!=el[1]:
            good = False
            break
    if good == True:
      maxs = max(maxs,cnt)
    cnt += 1
    bm[curInd] = 1
    good = True
    for i in range(N+1):
      if good == False:
        break
      if bm[i]:
        for el in arr[i]:
          if bm[el[0]]!=el[1]:
            good = False
            break
    if good == True:
      maxs = max(maxs,cnt)
    bm[curInd] = 0
    cnt -= 1
  else:
    slv(curInd+1)
    cnt += 1
    bm[curInd] = 1
    slv(curInd+1)
    cnt -= 1
    bm[curInd] = 0

for i in range(N):
  A=int(input())
  for j in range(A):
    arr[i+1].append(list(map(int,input().split())))
slv(1)
print(maxs)

Measured memory_bytes: 3192
#include <iostream>
using namespace std;
int main () {
    int n, x;
    char c;
    bool a[51] = {false};
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> c >> x;
        switch (c) {
            case 'H':
                x += 12;
                break;
            case 'C':
                x += 25;
                break;
            case 'D':
                x += 38;
                break;
            default:
                x -= 1;
        }
        a[x] = true;
    }
    for (int j = 0; j < 52; ++j)
        if (!a[j]){
            switch (j / 13){
                case 0:
                    cout << "S ";
                    break;
                case 1:
                    cout << "H ";
                    break;
                case 2:
                    cout << "C ";
                    break;
                default:
                    cout << "D ";
            }
            cout << j % 13 + 1 <<"\n";
        } 
}


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

const int MAX = 100000;

vector<pair<int, int>> adj[MAX];
// |V|, |E|, starting node
int n, m, s;

bool visited[MAX];
int dist[MAX];

int main() {
    cin >> n >> m >> s;
    for (int i = 0; i < m; i++) {
	int src, dest, dist;
	cin >> src >> dest >> dist;
	adj[src].push_back(make_pair(dest, dist));
    }

    priority_queue<pair<int, int>, vector<pair<int, int>>,
		   greater<pair<int, int>>>
	pq;
    pq.push(make_pair(0, s));
    while (!pq.empty()) {
	int d = pq.top().first, node = pq.top().second;
	pq.pop();

	if (visited[node]) continue;
	visited[node] = true;
	dist[node] = d;

	for (auto v : adj[node]) {
	    pq.push(make_pair(d + v.second, v.first));
	}
    }

    for (int i = 0; i < n; i++) {
	if (visited[i])
	    cout << dist[i] << endl;
	else
	    cout << "INF" << endl;
    }
    return 0;
}



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

public class Main {
	public static void main(String[] args) throws IOException {
		InputStreamReader isr = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(isr);
		String buf = br.readLine();
		String[] input = buf.split(" ");
		int a = Integer.parseInt(input[0]);
		int b = Integer.parseInt(input[1]);
		
		String result = new String();
		if(a < b){
			result = "a < b";
		}else if(a > b){
			result = "a > b";
		}else{
			result = "a == b";
		}
		System.out.println(result);
	}
}

Measured memory_bytes: 24444
import sys
sys.setrecursionlimit(500000)

def dfs(v,d):
    memo[v] = d
    for i in graph[v]:
        if memo[i[0]] != -1:continue
        dfs(i[0],d+i[1])

n = int(input())
graph = [[] for _ in range(n)]
memo = [-1]*n
for i in range(n-1):
    x,y,z = map(int,input().split())
    graph[x-1].append([y-1,z])
    graph[y-1].append([x-1,z])
q,k = map(int,input().split())
ary = [list(map(int,input().split())) for _ in range(q)]
dfs(k-1,0)
for x,y in ary:
    print(memo[x-1]+memo[y-1])

Measured memory_bytes: 162312