akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <vector>
 
using namespace std;
 
struct Node{
    Node(){
        brother = parent = -1;
        height = depth = num_of_children = 0;
    }
    int parent,brother,depth,num_of_children,height;
    vector<int> children;
};
 
void calcDepth(Node nodes[],int root_id){
    for(int i = 0;i < nodes[root_id].num_of_children;i++){
        nodes[nodes[root_id].children[i]].depth = nodes[root_id].depth+1;
        calcDepth(nodes,nodes[root_id].children[i]);
    }
}
 
void calcHeight(Node nodes[],int height,int parent){
    nodes[parent].height = max(nodes[parent].height,height+1);
    if(nodes[parent].parent != -1) calcHeight(nodes,height+1,nodes[parent].parent);
}
 
int main(){
    int n,id,left_id,right_id,root_id;
    scanf("%d",&n);
    Node nodes[n];
 
    for(int i = 0; i < n; i++){
        scanf("%d %d %d",&id,&left_id,&right_id);
        if(left_id != -1){
            nodes[id].children.push_back(left_id);
            nodes[id].num_of_children++;
            nodes[left_id].parent = id;
        }
        if(right_id != -1){
            nodes[id].children.push_back(right_id);
            nodes[id].num_of_children++;
            nodes[right_id].parent = id;
        }
        if(left_id != -1 && right_id != -1){
            nodes[left_id].brother = right_id;
            nodes[right_id].brother = left_id;
        }
    }
 
    for(root_id = 0; root_id < n; root_id++){
        if(nodes[root_id].parent == -1) break;
    }
 
    if(n > 1){
        calcDepth(nodes,root_id);
 
        for(int i = 0; i < n; i++){
            if(nodes[i].num_of_children == 0) calcHeight(nodes,0,nodes[i].parent);
        }
    }
 
    for(int i = 0; i < n; i++){
        printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d,"
                ,i,nodes[i].parent,nodes[i].brother,nodes[i].num_of_children,nodes[i].depth,nodes[i].height);
        if(nodes[i].parent == -1){
            printf(" root\n");
        }else if(nodes[i].num_of_children == 0){
            printf(" leaf\n");
        }else{
            printf(" internal node\n");
        }
 
    }
}


Measured memory_bytes: 2808
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>



#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

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 (b<a) { a=b; return 1; } return 0; }

typedef long long ll;

using namespace std;


class UnionFind
{
public:
  UnionFind(int n)
  {
    parent=vector<int>(n,-1);
  }
  int root(int a)
  {
    if(parent[a]<0)return a;
    return parent[a]=root(parent[a]);
  }
  int size(int a)
  {
    return -parent[root(a)];
  }
  bool connect(int a,int b)
  {
    int A=root(a);
    int B=root(b);
    if(A==B)return false;
    if(size(A)>size(B))swap(A,B);
    parent[B]+=parent[A];
    parent[A]=B;
    return true;
  }
private:
  vector<int> parent;

};
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n,m;cin>>n>>m;
  int res=0;
  vector<int>to(m),from(m);
  rep(i,m)
  {
    cin>>from[i]>>to[i];
    from[i]--;
    to[i]--;
  }
  rep(i,m)
  {
    UnionFind uf(n);
    rep(j,m)
    {
      if(i==j)continue;
      uf.connect(from[j],to[j]);
    }
    if(uf.root(from[i])!=uf.root(to[i]))res++;
  }
  cout<<res<<endl;


  return 0;

}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int k = sc.nextInt();
		int sum = 0;
		for (int a = 1; a <= k ; a++) {
			for (int b = 1; b <= k; b++) {
				for (int c = 1; c <= k; c++) {
					sum += gcd(a, b, c);
				}
			}
		}
		System.out.println(sum);
	}
	
	static int gcd(int a, int b, int c) {
		return gcd(gcd(a, b), c);
	}
	
	static int gcd(int a, int b) {
		if (b == 0) {
			return a;
		}
		
		return gcd(b, a % b);
	}
}


Measured memory_bytes: 27268
n=int(input())
ac=0
wa=0
tle=0
re=0
for _ in range(n):
    s=input()
    if s=="AC":
        ac+=1
    elif s=="WA":
        wa+=1
    elif s=="TLE":
        tle+=1
    else:
        re+=1
print("AC x ",ac)
print("WA x ",wa)
print("TLE x ",tle)
print("RE x ",re)

Measured memory_bytes: 9208
N = int(input())
limit = [int(input()) for _ in range(5)]
min_limit = min(limit)

# ボトルネックにかかる時間 + それ以外の経路にかかる時間
# 切り上げテクニック
# result = (N / min_limit) + 4
result = int(((N + min_limit - 1) / min_limit) + 4)
print(result)


Measured memory_bytes: 2940
using System;
using System.Collections.Generic;
using System.Linq;
using static Input;

public class Prog
{
    public struct Pair { public int x, y; public Pair(int x, int y) { this.x = x; this.y = y; } }
    public static void Solve()
    {
        int N = NextInt(), Q = NextInt();
        Node[] node = new Node[N + 1];
        for (int i = 1; i <= N; i++) node[i] = new Node(i);
        //頂点は1
        for (int i = 1; i < N; i++)
        {
            int a = NextInt(), b = NextInt();
            node[a].relate.Add(new Edge(b));
        }
        for (int i = 0; i < Q; i++)
        {
            int p = NextInt(), x = NextInt();
            node[p].cost += x;
        }
        Queue<int> Que = new Queue<int>();
        Que.Enqueue(1);
        while (Que.Count() != 0)
        {
            int n = Que.Dequeue();
            foreach (var e in node[n].relate)
            {
                node[e.to].cost += node[n].cost;
                Que.Enqueue(e.to);
            }
        }
        for (int i = 1; i <= N; i++) { Console.Write(node[i].cost + " "); }
        Console.WriteLine();
    }
    public static void Main()
    {
        var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(sw);
        Solve();
        Console.Out.Flush();
    }
}
public class Node
{
    public List<Edge> relate = new List<Edge>();
    public int name = 0;
    public bool visit = false;
    public long cost = 0;
    public Node(int name) { this.name = name; }
}
public class Edge
{
    public int to;
    public long cost;
    public Edge(int to, int cost = 0) { this.to = to; this.cost = cost; }
}
public class Input
{
    public const long MOD = 1000000007;
    public const int INF = 1000000007;
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}


Measured memory_bytes: 59048
#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <set>
#include <utility>

template <typename Tp>
class interval_set {
public:
  using value_type = Tp;

private:
  std::set<std::pair<Tp, Tp>> ranges;

public:
  void insert(Tp x) { Tp y = x; insert(x, ++y); }
  void erase(Tp x) { Tp y = x; erase(x, ++y); }

  void insert(Tp lb, Tp ub) {
    if (ranges.empty()) {
      ranges.emplace(lb, ub);
      return;
    }

    auto it = ranges.upper_bound({lb, lb});
    if (it != ranges.begin() && !(std::prev(it)->second < lb)) {
      if (!(std::prev(it)->second < ub)) return;
      lb = std::prev(it)->first;
      ranges.erase(std::prev(it));
    }
    while (it != ranges.end() && !(ub < it->first)) {
      if (ub < it->second) ub = it->second;
      it = ranges.erase(it);
    }
    ranges.emplace(lb, ub);
  }

  void erase(Tp lb, Tp ub) {
    if (ranges.empty()) return;

    auto it = ranges.upper_bound({lb, lb});

    if (it != ranges.begin() && !(std::prev(it)->second < lb)) {
      if (!(std::prev(it)->second < ub)) {
        // [ ...* [ ...+ ) ...* )
        --it;
        Tp lb0 = it->first;
        Tp ub0 = it->second;
        ranges.erase(it);
        if (lb0 < lb) ranges.emplace(lb0, lb);
        if (ub < ub0) ranges.emplace(ub, ub0);
        return;
      }

      // [ ...+ )      [ ...+ )*
      //      [ ...+ ) <- erase this
      Tp lb0 = std::prev(it)->first;
      ranges.erase(std::prev(it));
      ranges.emplace(lb0, lb);
    }

    while (it != ranges.end() && !(ub < it->first)) {
      if (ub < it->second) {
        Tp ub0 = it->second;
        ranges.erase(it);
        ranges.emplace(ub, ub0);
        break;
      }
      it = ranges.erase(it);
    }
  }

  size_t num_ranges() const { return ranges.size(); }

  std::pair<Tp, Tp> suprange(Tp x) const {
    if (ranges.empty()) return {x, x};
    auto it = ranges.upper_bound({x, x});

    if (it != ranges.end())
      if (!(x < it->first) && x < it->second) return *it;

    if (it == ranges.begin() || !(x < (--it)->second)) return {x, x};
    return *it;
  }

  bool contains(Tp x) const { return (suprange(x).second != x); }
};

int main() {
  size_t N;
  int H, W;
  scanf("%zu %d %d", &N, &W, &H);

  interval_set<int> ws, hs;
  for (size_t i = 0; i < N; ++i) {
    int x, y, w;
    scanf("%d %d %d", &x, &y, &w);
    ws.insert(x-w, x+w);
    hs.insert(y-w, y+w);
  }

  if (ws.suprange(0) == ws.suprange(W-1)) return puts("Yes"), 0;
  if (hs.suprange(0) == hs.suprange(H-1)) return puts("Yes"), 0;
  puts("No");
}



Measured memory_bytes: 3380
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		string[] str = Console.ReadLine().Split();
		long N = long.Parse(str[0]);
		long X = long.Parse(str[1]);
		long[] C = new long[N];
		string[] str2 = Console.ReadLine().Split();
		long suma = 0;
		long[] D = new long[N];
		for(var i=0;i<N;i++){
			C[i] = long.Parse(str2[i]);
			suma += C[i];
			D[i] = suma;
		}
		long min = -1;
		for(var i=1;i<=N;i++){
			long sumt = 0;
			long aat = N-1;
			long at = 1;
			long ak = 5;
			while(true){
				if(at>=3){
					ak = at*2+1;
				}
				if(aat-i<0){
					sumt += ak * D[aat];
					break;
				} else {
					sumt += ak * (D[aat] - D[aat - i]);
				}
				if(sumt >= Math.Pow(10,17)){
					break;
				}
				aat -= i;
				at += 1;
			}
			sumt += X * i;
			if(min == -1){
				min = sumt;
			} else {
				min = Math.Min(min,sumt);
			}
		}
		min += N * X;
		Console.WriteLine(min);
	}
}

Measured memory_bytes: 35876
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <chrono>
#include <forward_list>
#include <initializer_list>
#include<random>
#include <ratio>
#include <regex>
#include <system_error>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
#if __cplusplus >= 201402L
#include <shared_mutex>
#endif

#include "atcoder/all"
using namespace atcoder;
using namespace std;
typedef long long ll;
#define pb push_back
#define rep(i, n) for(int i=0;i<(n);i++)
#define P pair<int,int>
template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }

namespace ori{
    template <typename T>
    void erase(std::vector<T> &v)
    {
        std::sort(v.begin(),v.end());
        v.erase(std::unique(v.begin(),v.end()),v.end());
        return;
    }

    template<typename T>
    int find_index(std::vector<T> v, T find, string key)
    {
        std::sort(v.begin(),v.end());
        if(key=="left")
        {
            return (std::distance(v.begin(),lower_bound(v.begin(),v.end(),find)));
        }
        if(key=="right")
        {
            return (std::distance(v.begin(),upper_bound(v.begin(),v.end(),find))-1);
        }
        else
        {
            return -1;
        }
    }
}

const int x8[] = {0, 0, 1, -1, -1, 1, -1, 1};
const int y8[] = {-1, 1, 0, 0, -1, -1, 1, 1};
const int x4[] = {1, -1, 0, 0};
const int y4[] = {0, 0, -1, 1};
const int MOD = 1000000007;

void task() {
    int n,m; cin >> n >> m;
    dsu d(n);
    rep(i,m){
        int a,b; cin >> a >> b;
        --a; --b;
        d.merge(a,b);
    }

    cout << d.groups().size()-1 << endl;
}




int main() {
    //ios::sync_with_stdio(false); cin.tie(nullptr);
    task();
    return 0;
}


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

using namespace std;

typedef long long ll;

const ll M=1e9+7;
const int N=2e3+10;

ll myPow(ll a,ll n)
{
    ll ans=1;
    while(n>0)
    {
        if(n&1)
        {
            ans=ans*a%M;
        }
        a=a*a%M;
        n>>=1;
    }
    return ans;
}

ll fac[N],inv[N];

void init()
{
    fac[0]=1;
    for(int i=1;i<N;i++)
    {
        fac[i]=fac[i-1]*i%M;
    }
    inv[N-1]=myPow(fac[N-1],M-2);
    for(int i=N-2;i>=0;i--)
    {
        inv[i]=inv[i+1]*(i+1)%M;
    }
}

int main()
{
    init();
    int n,k;
    while(cin>>n>>k)
    {
        cout<<fac[n+k-1]*inv[k-1]%M*inv[n]%M<<endl;
    }

    return 0;
}



Measured memory_bytes: 3136
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		String S[] = new String[N];
		int P[] = new int[N];

		for (int i=0; i<N; i++){
			S[i] = sc.next();
			P[i] = sc.nextInt();
		}

		Set<Integer> printed = new HashSet<Integer>();
		for (int i=0; i<N; i++){
			String tempS = "zzzzzzzzzz";
			int tempP = 0;
			int tempIndex = 0;
			for (int j=0; j<N; j++){
				if (!printed.contains(j)) {
					if (tempS.compareTo(S[j]) > 0 || (tempS.compareTo(S[j]) == 0 && tempP < P[j])){
						tempS = S[j];
						tempP = P[j];
						tempIndex = j;
					}
				}
			}
			System.out.println(tempIndex + 1);
			printed.add(tempIndex);
		}


	}
}

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

using namespace std;

int main(){
  long long  a,b,c;
  cin>>a>>b>>c;
  if ( a%2==0 || b%2==0 || c%2==0) {
    cout<<0;
    return 0;
  }
  long long  tab[3];
  tab[0]=a;
  tab[1]=b;
  tab[2]=c;
  sort(tab,tab+3);
  cout<<tab[1]*tab[0];
}


Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()
ll MOD = 1000000007;
ll INF = 1e18;
#define def 0

int main() {
  ll x, y;
  cin >> x >> y;
  if (x > 0 && y > 0) {
    if (x <= y) {
      cout << y - x << endl;
    } else {
      cout << 2 + x - y << endl;
    }
  } else if (x > 0 && y < 0) {
    if (x > abs(y)) {
      cout << 1 + x - abs(y) << endl;
    } else {
      cout << 1 + abs(y) - x << endl;
    }
  } else if (x < 0 && y > 0) {
    if (abs(x) > y) {
      cout << 1 + abs(x) - y << endl;
    } else {
      cout << 1 + y - abs(x) << endl;
    }
  } else if (x < 0 && y < 0) {
    if (abs(x) >= abs(y)) {
      cout << abs(x) - abs(y) << endl;
    } else {
      cout << 2 + abs(y) - abs(x) << endl;
    }
  } else if (x == 0) {
    if (y < 0) {
      cout << 1 - y << endl;
    } else {
      cout << y << endl;
    }
  } else {
    if (x > 0) {
      cout << 1 + x << endl;
    } else {
      cout << -x << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    long long n,k,ans=0;
    cin >> n >>k;
    for(int i=k;i<=n+1;i++){
        ans+=i*(n-i+1)%1000000007+1;
        if(ans>=1000000007){
            ans%=1000000007;
        }
    }
    
    cout << ans <<endl;
}


Measured memory_bytes: 3608
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <iterator>
#include <numeric>
#include <cstdint>
#include <cmath>
#include <bitset>
#include <string>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>

#define N_TIMES(i, n)     for ( uint64_t i = 0;     i <  n; ++i )
#define N_TIMES_REV(i, n) for (  int64_t i = n - 1; i >= 0; --i )

using namespace std;

namespace State { enum { Unknown = 0, Vacant = 1, Male, Female }; };

int query(uint64_t x)
{
  cout << x << endl;

  string y;
  cin >> y;

  if (y == "Vacant") { return State::Vacant; } else
  if (y == "Male")   { return State::Male;   } else
  if (y == "Female") { return State::Female; } else
  return State::Unknown;
}

uint64_t search(int S, int T, uint64_t L, uint64_t R)
{
  auto length_is_odd = [](uint64_t L, uint64_t R) {
    return ((R - L + 1) & 1) == 1;
  };

  uint64_t X = (L + R) >> 1;
  if (R - L <= 1) { return L; }

  int status = query(X);
  if (status == State::Vacant) {
    return X;
  }

  // [L, X]
  if (length_is_odd(L, X)) {
    if (S != status) {
      return search(S, status, L, X);
    }
  } else {
    if (S == status) {
      return search(S, status, L, X);
    }
  }

  // [X, R]
  if (length_is_odd(X, R)) {
    if (T != status) {
      return search(status, T, X, R);
    }
  } else {
    if (T == status) {
      return search(status, T, X, R);
    }
  }

  return static_cast<uint64_t>(-1);
}

uint64_t solve(uint64_t N)
{
  int status_L = query(0), status_R = query(N - 1);
  if (status_L == State::Vacant) { return 0; }
  if (status_R == State::Vacant) { return N - 1; }

  return search(status_L, status_R, 0, N - 1);
}

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

  cout << solve(N) << endl;

  return 0;
}

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

using namespace std;

int main()
{
    string S;

    cin >> S;

    int num = 0;
    for (int i = 0; i < 3;i++)
    {
        if(S[i] == 'o')
        {
            num++;
        }
    }
    cout << 700 + num * 100 << endl;

    return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(a)-1;i>=b;i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(_v) for(auto _x:_v){cout<<_x<<" ";}cout<<endl
#define printVS(_vs) for(auto _x : _vs){cout << _x << endl;}
#define printVV(_vv) for(auto _v:_vv){for(auto _x:_v){cout<<_x<<" ";}cout<<endl;} cout << endl;
#define printP(_p) cout << _p.first << " " << _p.second << endl
#define printVP(_vp) for(auto _p : _vp) printP(_p);

typedef long long ll;
typedef pair<int, int> Pii;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<Pii> vp;
const int inf = 1e9;
const int mod = 1e9 + 7;

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

    int H, W;
    cin >> H >> W;
    int N = max(H, W);
    vvi a(N + 1, vi(N + 1));
    rep(i, N) rep(j, N) cin >> a[i + 1][j + 1];

    vvi b(2 * N + 1, vi(N + 1));
    rep(i, N + 1) {
        rep(j, N + 1) {
            b[i + j][j] = a[i][j];
        }
    }

    vvvi dp(2 * N + 1, vvi(N + 1, vi(N + 1)));
    rep2(i, 1, 2 * N + 1) {
        rep2(j, 1, N + 1) {
            rep2(k, 1, N + 1) {
                dp[i][j][k] = max({dp[i-1][j][k],
                                    dp[i-1][j][k-1],
                                    dp[i-1][j-1][k],
                                    dp[i-1][j-1][k-1]});
                dp[i][j][k] += (j != k ? b[i][j] + b[i][k] : b[i][j]);
            }
        }
    }
    cout << dp.back().back().back() << endl;
}


Measured memory_bytes: 130688
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define pdi pair<db,int>
#define mp make_pair
#define pb push_back
#define enter putchar('\n')
#define space putchar(' ')
#define eps 1e-8
#define mo 974711
#define MAXN 100005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;char c = getchar();T f = 1;
    while(c < '0' || c > '9') {
	if(c == '-') f = -1;
	c = getchar();
    }
    while(c >= '0' && c <= '9') {
	res = res * 10 + c - '0';
	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
	out(x / 10);
    }
    putchar('0' + x % 10);
}
int A[(1 << 18) + 5],N;
vector<int> e[2][(1 << 18) + 5];
int d[2][(1 << 18) + 5];
int L[(1 << 18) + 5],R[(1 << 18) + 5];
int que[2][(1 << 18) + 5],ql,qr,ans[(1 << 18) + 5];
vector<int> st[(1 << 18) + 5],ed[(1 << 18) + 5];
struct cmp {
    bool operator () (const int &a,const int &b) const {
	return R[a] < R[b] || (R[a] == R[b] && a < b);
    }
};
set<int,cmp> S;
void Init() {
    read(N);
    for(int i = 0 ; i < (1 << N) ; ++i) {
	read(A[i]);--A[i];
	for(int j = 0 ; j < N ; ++j) {
	    if(!(i >> j & 1)) {
		e[0][i].pb(i + (1 << j));
		d[0][i + (1 << j)]++;
		e[1][i + (1 << j)].pb(i);
		d[1][i]++;
	    }
	}
	L[i] = 0;R[i] = (1 << N) - 1;
    }
}
void Solve() {
    L[0] = R[0] = 0;
    for(int i = 0 ; i < (1 << N) ; ++i) {
        if(A[i] != -1) L[i] = A[i];
        int u = i;
    	for(auto v : e[0][u]) {
    	    L[v] = max(L[v],L[u] + 1);
    	}
    }
    R[(1 << N) - 1] = L[(1 << N) - 1] = (1 << N) - 1;

    for(int i = (1 << N) - 1 ; i >= 0 ; --i) {
        if(A[i] != -1) R[i] = A[i];
    	int u = i;
    	for(auto v : e[1][u]) {
    	    R[v] = min(R[u] - 1,R[v]);
    	}
    }
    for(int i = 0 ; i < (1 << N) ; ++i) {
    	st[L[i]].pb(i);
    }
    for(int i = 0 ; i < (1 << N) ; ++i) {
        for(auto t : st[i]) S.insert(t);
        if(S.empty()) {puts("NO");return;}
        int t = *S.begin();
        S.erase(S.begin());
        if(R[t] < i) {puts("NO");return;}
        ans[t] = i;
    }

    puts("YES");
    for(int i = 1 , j = (1 << N - 1) ; i < (1 << N) - 1 ; ++i) {
    	if(i < j) swap(ans[i],ans[j]);
    	int k = (1 << N - 1);
    	while(j >= k) {
    	    j -= k;
    	    k >>= 1;
    	}
    	j += k;
    }
    for(int i = 0 ; i < (1 << N) ; ++i) {
    	out(ans[i] + 1);space;
    }
    enter;
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Init();
    Solve();
    return 0;
}


Measured memory_bytes: 81664
# def makelist(n, m):
#     return [[0 for i in range(m)] for j in range(n)]

N = int(input())
F = [0]*N
P = [0]*N

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


def calc(lst):
    res = 0
    for n in range(N):
        cnt = 0
        for i in range(10):
            if lst[i] + F[n][i] == 2:
                cnt += 1
        res += P[n][cnt]
    return res

def func(acc):
    if len(acc) == 10:
        if 1 in acc:
            return calc(acc)
        else:
            return -2e9
    else:
        return max(func(acc + [0]), func(acc + [1]))

print(func([]))


Measured memory_bytes: 43628
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;
using VB = vector<bool>;
using VVB = vector<VB>;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
	//i=m -> n-1(昇順)
#define RREP(i,m,n) for(int i=(m);i>=(n);i--)
	//i=m -> n(降順)

int main(){
  int n,m;
  cin >> n >> m;
  VI a(m),b(m),sign(n+1,-1);
  VVI g(n+1, VI());
  REP(i,0,m){
    cin >> a[i] >> b[i];
    g[a[i]].push_back(b[i]);
    g[b[i]].push_back(a[i]);
  }
  
  queue<PII> q; // x = 現在地, y = 道標
  q.push(make_pair(1,0));
  
  while(!q.empty()){
    PII cur = q.front();
    q.pop();
    int x = cur.first;
    int y = cur.second;
    
    for(int z : g[x]){
      if(sign[z] == -1){
        q.push(make_pair(z,x));
        sign[z] = x;
      }
    }
  }
  
  cout << "Yes" << endl;
  REP(i,2,n+1){
    cout << sign[i] << endl;
  }
  
  
  return 0;
}


Measured memory_bytes: 15252
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

using namespace std;

#define REP(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define pb(a) push_back(a)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

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

int main(){
	int s;
	cin >> s;
	int a=s;
	vector<int> as;
	as.pb(a);
	int res;
	for(int i=2;i<1000001;i++){
		int a2;
		if(a%2==0){
			a2  = a/2;
		}else{
			a2 = 3*a+1;
		}
		if(as.end()!=find(all(as),a2)){
			res = i;
			break;
		}else{
			a = a2;
			as.pb(a);
		}
	}
	cout << res << endl;
}

Measured memory_bytes: 256
N = int(input())
d = {'AC': 0, 'WA': 0, 'TLE': 0, 'RE': 0}
for _ in range(N):
    d[input()] += 1
print('AC x', d['AC'])
print('WA x', d['WA'])
print('TLE x', d['TLE'])
print('RE x', d['RE'])

Measured memory_bytes: 9196
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(x,y) (x=min(x,y))
#define chmax(x,y) (x=max(x,y))
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}

int main(){
	string a, b;
  cin>>a>>b;
  int res;
  if(a.size()<b.size()) res = -1;
  else if(a.size()>b.size()) res = 1;
  else if(a<b) res = -1;
  else if(a>b) res = 1;
  else res = 0;
  cout<<(res==1?"GREATER":res==0?"EQUAL":"LESS")<<endl;
  
	return 0;
}


Measured memory_bytes: 256
import qualified Data.ByteString.Char8 as B
import qualified Data.Vector.Unboxed as UV

a#b = abs$a-b

main = do
    [n,k] <- map read.words<$>getLine
    hr <- UV.unfoldr(B.readInt.B.dropWhile(<'!'))<$>B.getLine
    print $ f n k hr

inf = 10^18
f n k h = UV.last $ UV.foldl' proc (UV.singleton 0) $ UV.enumFromTo (1::Int) (n-1) where
    proc v0 dhi
        | dhi < k = UV.snoc v0 $ UV.foldl' m inf $ UV.zip v0 h
        | otherwise = UV.tail $ UV.snoc v0 $ UV.foldl' m inf $ UV.zip v0 $ UV.slice (dhi-k) k h
        where
            m a (sv,sh) = min a (sv+sh# (h UV.! dhi))

Measured memory_bytes: 5116
#include <bits/stdc++.h>
#define fo(a,b,c) for (a=b; a<=c; a++)
#define fd(a,b,c) for (a=b; a>=c; a--)
#define ll long long
using namespace std;

struct type{int id,len;} x,y;
bool operator < (type a,type b) {return a.len>b.len;}

int n,i,j,k,l,Find,len;
char ask[129],a[129],st[63][129],ch;
priority_queue<type> heap;

int turn(char ch) {if (ch>='a' && ch<='z') return ch-'a'+1; if (ch>='A' && ch<='Z') return ch-'A'+27;return ch-'0'+53;}
void Ask()
{
	int i;
	
	printf("? ");
	fo(i,1,len) putchar(ask[i]);putchar('\n');
	fflush(stdout);
	scanf("%d",&Find);
}

void merge(int x,int y,int n,int m)
{
	int i,j,k,l,Len=0;
	
	j=1;
	fo(i,1,m)
	{
		if (j<=n)
		{
			do{
				a[++Len]=st[x][j];len=Len;
				memcpy(ask,a,Len+1);
				fo(k,i,m) ask[++len]=st[y][k];
				Ask();
				++j;
			}while (Find==(::n)-m-(j-1) && j<=n);
			
			if (Find!=(::n)-m-(j-1)) --j,--Len;
		}
		a[++Len]=st[y][i];
	}
	while (j<=n) a[++Len]=st[x][j++];
	
	memcpy(st[x],a,n+m+1);
}

int main()
{
	len=128;
	fo(ch,'a','z') {memset(ask,ch,129); Ask();n+=128-Find; if (Find<128) {memset(st[turn(ch)],ch,129-Find); heap.push({turn(ch),128-Find});}}
	fo(ch,'A','Z') {memset(ask,ch,129); Ask();n+=128-Find; if (Find<128) {memset(st[turn(ch)],ch,129-Find); heap.push({turn(ch),128-Find});}}
	fo(ch,'0','9') {memset(ask,ch,129); Ask();n+=128-Find; if (Find<128) {memset(st[turn(ch)],ch,129-Find); heap.push({turn(ch),128-Find});}}
	
	while (heap.size()>1)
	{
		x=heap.top();heap.pop();
		y=heap.top();heap.pop();
		
		merge(x.id,y.id,x.len,y.len);
		heap.push({x.id,x.len+y.len});
	}
	
	x=heap.top();
	printf("! ");
	fo(i,1,x.len) putchar(st[x.id][i]);putchar('\n');
	fflush(stdout);
	
	fclose(stdin);
	fclose(stdout);
	return 0;
}

Measured memory_bytes: 3808
import heapq

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def main():
    N, M = mi()
    A = list(map(lambda x: -int(x), input().split()))
    heapq.heapify(A)
    for i in range(M):
        t = heapq.heappop(A)
        heapq.heappush(A, -(-t//2))
    print(-sum(A))

if __name__ == '__main__':
    main()


Measured memory_bytes: 72088
#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() {
  int n,m;
  cin >> n >> m;
  vector<int> a(n,0);
  int tot = 0;
  rep(i,n) {
    cin >> a.at(i);
    tot += a.at(i);
  }

  sort(all(a));
  reverse(all(a));
  bool flag = true;
  rep(i,m) {
    if(4*m*a.at(i) < tot) flag = false;
  }
  if(flag) cout <<"Yes" << endl;
  else cout << "No" <<endl;



  return 0;
}


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

int main() {
    ll people;
    ll a, b, c, d, e;
    cin >> people >> a >> b >> c >> d >> e;

    ll req;
    if (people % min(a, min(b, min(c, min(d, e)))) != 0) req = people / min(a, min(b, min(c, min(d, e)))) + 5;
    else req = people / min(a, min(b, min(c, min(d, e)))) + 4;

    cout << req << endl;
}


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

class Main {

	void solve() {
		
		int n = inint(), a = inint();
		out.println(n*n-a);
		
	}

	public static Scanner in = new Scanner(System.in);
	public static PrintWriter out = new PrintWriter(System.out);

	public static void main(String[] args) {
		new Main().solve();
		out.flush();
	}

	public int inint() {
		return in.nextInt();
	}

	public long inlong() {
		return in.nextLong();
	}
	
	public String instr() {
		return in.next();
	}

	public char inchar() {
		return in.next().charAt(0);
	}
	
	public int[] inintar(int num) {
		int[] a = new int[num];
		for (int i=0; i<num; i++) {
			a[i] = in.nextInt();
		}
		return a;
	}

	public char[] incharar() {
		return in.next().toCharArray();
	}

}

Measured memory_bytes: 23380
#include <bits/stdc++.h>
using namespace std;
template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,a,b;
  int ans = 0;
  string num;
  cin >> n >> a >> b;
  for(int i=1;i<=n;i++){
    num = to_string(i);
    int sum = 0;
    for(int j=0;j<num.size();j++) sum += ctoi(num[j]);
    if (a <= sum && sum <= b) ans += i;
  }
  cout << ans << endl;
  return 0;
}


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

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

	int cnt=0;
	for(int i=a;i<=b;i++){
		if(c%i==0)cnt++;
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 1160
#pragma region template
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vld = vector<ld>;
using vvld = vector<vld>;
using vvvld = vector<vvld>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
template <typename T>
using pqrev = priority_queue<T, vector<T>, greater<T>>;
#define rep(i, n) for (ll i = 0, i##_end = (n); i < i##_end; i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repr(i, a, b) for (ll i = (a), i##_end = (b); i < i##_end; i++)
#define reprb(i, a, b) for (ll i = (b)-1, i##_end = (a); i >= i##_end; i--)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const ll INF = 1e+18;
const ld EPS = 1e-12L;
const ld PI = acos(-1.L);
inline ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
inline ll LCM(ll a, ll b) { return a / GCD(a, b) * b; }
template <typename S, typename T>
inline bool chmax(S &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename S, typename T>
inline bool chmin(S &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif
template <typename T>
bool print_(const T &a) {
  cout << a;
  return true;
}
template <typename T>
bool print_(const vector<T> &vec) {
  for (auto &a : vec) {
    cout << a;
    if (&a != &vec.back()) {
      cout << " ";
    }
  }
  return false;
}
template <typename T>
bool print_(const vector<vector<T>> &vv) {
  for (auto &v : vv) {
    for (auto &a : v) {
      cout << a;
      if (&a != &v.back()) {
        cout << " ";
      }
    }
    if (&v != &vv.back()) {
      cout << "\n";
    }
  }
  return false;
}
void print() { cout << "\n"; }
template <typename Head, typename... Tail>
void print(Head &&head, Tail &&... tail) {
  bool f = print_(head);
  if (sizeof...(tail) != 0) {
    cout << (f ? " " : "\n");
  }
  print(forward<Tail>(tail)...);
}
#pragma endregion

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  ll n;
  cin >> n;
  vll ans;
  if(n >= 6){
    rep(i, min(n/6, 2500ll)){
      ans.emplace_back(i*12+2);
      ans.emplace_back(i*12+3);
      ans.emplace_back(i*12+4);
      ans.emplace_back(i*12+8);
      ans.emplace_back(i*12+9);
      ans.emplace_back(i*12+10);
    }
    repr(i, 1, 30002){
      if(SZ(ans) == n){
        break;
      }
      if(i%6==0){
        ans.emplace_back(i);
      }
    }
  }else{
    if(n == 3) ans = {2, 5, 63};
    if(n == 4) ans = {2, 5, 20, 63};
    if(n == 5) ans = {2, 5, 20, 63, 90};
  }
  print(ans);
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>


using namespace std;


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

int main() {
  int a, b;
  cin >> a >> b;

  cout << gcd(a, b) << endl;
}

Measured memory_bytes: 1164
#include <stdio.h>
#include <limits.h>

#ifndef KOTAISUU
#define KOTAISUU 12
#endif
#ifndef SEDAISUU
#define SEDAISUU 15000
#endif
#ifndef KAKURITU
#define KAKURITU 30 /* * 0.01 % */
#endif

static unsigned int x=123456789;
static unsigned int y=362436069;
static unsigned int z=521288629;
static unsigned int w=88675123;

void seed(unsigned int a,unsigned int b,unsigned int c,unsigned int d) {
	if((a|b|c|d)==0)return;
	x=a;y=b;z=c;w=d;
}

unsigned int randint(void) {
	unsigned int t;
	t=(x^(x<<11));
	x=y;y=z;z=w;
	w=(w^(w>>19))^(t^(t>>8));
	return w;
}

unsigned int randint2(unsigned int max) {
	unsigned int amari = ((UINT_MAX % max) + 1) % max;
	unsigned int ret;
	do {
		ret = randint();
	} while (ret < amari);
	return ret % max;
}

#define KIND 26
#define MAX 365

struct horieyui {
	int mamegu[MAX];
};

int D;
int c[KIND];
int s[MAX][KIND];

int mizuhasu(const struct horieyui* kitaeri) {
	int sumipe = 0;
	int i, j;
	int last[KIND] = {0};
	for (i = 0; i < D; i++) {
		sumipe += s[i][kitaeri->mamegu[i]];
		last[kitaeri->mamegu[i]] = i + 1;
		for (j = 0; j < KIND; j++) {
			sumipe -= c[j] * ((i + 1) - last[j]);
		}
	}
	return sumipe;
}

int main(void) {
	int i, j;
	struct horieyui otehon;
	struct horieyui saikyou;
	int saikyou_score = 0;
	if (scanf("%d", &D) != 1) return 1;
	for (i = 0; i < KIND; i++) {
		if (scanf("%d", &c[i]) != 1) return 1;
	}
	for (i = 0; i < D; i++) {
		for (j = 0; j < KIND; j++) {
			if (scanf("%d", &s[i][j]) != 1) return 1;
		}
	}

	for (i = 0; i < KIND; i++) {
		int score;
		for (j = 0; j < D; j++) otehon.mamegu[j] = (i + j) % KIND;
		score = mizuhasu(&otehon);
		if (i == 0 || score > saikyou_score) {
			saikyou = otehon;
			saikyou_score = score;
		}
	}
	otehon = saikyou;

	for (i = 0; i < SEDAISUU; i++) {
		struct horieyui saituyo;
		int saituyo_score = 0;
		for (j = 0; j < KOTAISUU; j++) {
			struct horieyui kore = otehon;
			int k;
			int score;
			for(k = 0; k < D; k++) {
				if (randint2(10000) < KAKURITU) {
					kore.mamegu[k] = randint2(KIND - 1);
					if (kore.mamegu[k] >= otehon.mamegu[k]) kore.mamegu[k]++;
				}
			}
			score = mizuhasu(&kore);
			if (j == 0 || score > saituyo_score) {
				saituyo = kore;
				saituyo_score = score;
			}
		}
		otehon = saituyo;
		if (saituyo_score > saikyou_score) {
			saikyou = saituyo;
			saikyou_score = saituyo_score;
		}
	}
	for (i = 0; i < D; i++) {
		printf("%d\n", saikyou.mamegu[i] + 1);
	}
#ifdef PRINT_SCORE
	printf("score = %d\n", saikyou_score < -1000000 ? 0 : 1000000 + saikyou_score);
#endif
	return 0;
}


Measured memory_bytes: 1772
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
	int existCount = 0;
	int answer = 0;
	int N;
	int K;

	cin >> N >> K;

	vector<int> num(N);
	vector<int> A(N);    // 1 <= A() <= N

	for (int i = 0; i < N; i++) {
		cin >> A.at(i); 
		num.at( A.at(i) -1 )++;
	}

	// 0でない要素の個数を求める
	for (int i = 0; i < N ; i++) {

		if (num.at(i) != 0) existCount++;

	}


	if (existCount <= K) {	}
	
	else {  // K < existCount
		
		sort(num.begin(), num.end());  // 昇順にソート
		
		for (int i = N - existCount ; i < N - K ; i++ ) {
			
			answer += num.at(i);
		
		}
	}
	
	cout << answer << endl;

	return 0;
}

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

typedef long long ll;

// (a^b)%m
ll exp(ll a, ll b, ll m) {
	ll r=1;
	while(b) {
		if(b%2) r=(r*a)%m;
		a=(a*a)%m;
		b/=2;
	}
	return r;
}

// a^-1 %m, prime m
ll invp(ll a, ll m) {
	return exp(a, m-2, m);
}

const int mx=1e5+77;
const int mod=1e9+7;

ll fact[mx];

int main() {
	fact[0]=1;
	for (int i=1; i<mx; i++)
		fact[i]=(fact[i-1]*i)%mod;
	ll inv[mx];
	int N; cin>>N;
	for (int i=1; i<=N-1; i++)
		inv[i]=(fact[N-1]*invp(i,mod))%mod;
	vector<int> x(N+1);
	for (int i=1; i<=N; i++)
		cin>>x[i];
	ll ret=0;
	for (int i=1; i<=N-1; i++)
		ret=(ret+inv[i]*(x[N]-x[i]))%mod;
	cout<<ret<<"\n";
	return 0;
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll a;
	ll b;
	ll c;
	cin>>a;
	cin>>b;
	cin>>c;
	if((a==b)&&(b==c))
	{
		cout<<"No"<<"\n";
	}
	else if((a!=b)&&(b!=c)&&(c!=a))
	{
		cout<<"No"<<"\n";
	}
	else
	{
		cout<<"Yes"<<"\n";
	}
	return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
using ll = long long;
using namespace std;
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 (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}

int main(){
  string S, T; cin >> S >> T;
  int N = sz(S);
  if(T.substr(0,N) == S) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 3632
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
//#include <atcoder/all>
//using namespace atcoder;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

template<typename T>
ostream& operator<<(ostream& os,const vector<T>& v){
    if(v.empty()){
        os<<"{ }";
        return os;
    }
    os<<"{"<<v.front();
    for(auto itr=++v.begin();itr!=v.end();itr++){
        os<<", "<<*itr;
    }
    os<<"}";
    return os;
}

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

ll exgcd(ll a,ll b,ll &x,ll &y){
    if(b==0){
        x=1; y=0;
        return a;
    }
    ll d=exgcd(b,a%b,y,x);
    y-=(a/b)*x;
    return d;
}

int main(){
    ll n; cin>>n;
    map<ll,int> mp;
    ll N=n;
    for(ll i=2;i*i<=N;i++){
        while(N%i==0){
            mp[i]++;
            N/=i;
        }
    }
    if(N>1) mp[N]++;
    mp[2]++;
    int prcnt=mp.size();
    vector<ll> pr(prcnt,1);
    int idx=0;
    for(auto p:mp){
        rep(i,p.second) pr[idx]*=p.first;
        idx++;
    }
    ll ans=INF;
    rep(i,(1<<prcnt)){
        ll a=1,b=1,x,y;
        rep(j,prcnt){
            if(i&(1<<j)) a*=pr[j];
            else b*=pr[j];
        }
        exgcd(a,b,x,y);
        x=(b+x%b)%b;
        y=(a+y%a)%a;
        if(min(x,y)==0){
            ans=min(max(a,b)-1,ans);
            continue;
        }
        ans=min(a*x-1,ans);
        ans=min(b*y-1,ans);
        //cout<<x<<" "<<y<<endl;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3632
#include <iostream> // cin, cout, cerr, clog
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota, gcd, lcm 
#include <cstdio> // printf, scanf
#include <climits> // INT_MIN, LLONG_MIN
#include <cmath> // long, trig, pow
#include <string> // string
#include <vector> // vector
#include <queue> // queue
#include <stack> // stack
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <unordered_map> // hashed by keys
#include <unordered_set> // hashed by keys
#include <iomanip> // cout<<setprecision(n)
#include <cstdint> // int64_t, int_fast64_t

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

typedef std::int_fast64_t ll; // at least int64 > 9*10^18
typedef std::uint_fast64_t ull; // at least uint64

#define int ll

#define INF 10101010

signed main() {
  int n;
  std::cin >> n;
  std::vector<int> weights(n);
  rep(i,n) std::cin >> weights[i];
  std::vector<int> weight_sum(n);
  rep(i,n) {
    if(i==0) weight_sum[i] = weights[0];
    else {
      weight_sum[i] = weight_sum[i-1] + weights[i];
    }
  }
  int absmin = INF;
  rep(i,n-1) {
    absmin = std::min(absmin,std::abs(2*weight_sum[i]-weight_sum[n-1]));
  }
  std::cout << absmin << ENDL;
  return 0;
}

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

int main(){
  int m;
  string s;
  cin >> s;
  m=s.at(6)-'0'+(s.at(5)-'0')*10;
  if(m>4){
    cout << "TBD" << endl;
  }else{
    cout << "Heisei" << endl;
  }
}

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

int n, A, B;

int seq[1<<17];
void solve(int A, int B, int l, int r, int S) {
  if (r - l == 2) {
    seq[l] = A, seq[r - 1] = B;
  }
  else {
    int m = l + r >> 1;
    int lb = (A^B)&-(A^B);
    for (int SS = S; SS; SS = (SS - 1)&S) {
      int target = A^SS;
      if ((target&lb) == (A&lb)) {
        if (__builtin_parity(target^A) % 2 and __builtin_popcount(target^A) <= r - m - 1 and
            __builtin_parity(target^lb^B) % 2 and __builtin_popcount(target^lb^B) <= r - m - 1) {
          return solve(A, target, l, m, S^lb), solve(target^lb, B, m, r, S^lb);
        }
      }
    }
  }
}

int main() {
  cin >> n >> A >> B;
  if (__builtin_parity(A^B) % 2) {
    cout << "YES\n";
    solve(A, B, 0, 1<<n, (1<<n) - 1);
    for (int i = 0; i < (1<<n); ++i) cout << seq[i] << " \n"[i == (1<<n) - 1];
  }
  else cout << "NO\n";
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;

constexpr ll mod = 1e9 + 7;

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

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

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

    ll n, x, d;
    cin >> n >> x >> d;

    if(d == 0) {
        cout << (x ? n + 1 : 1) << endl;
        return 0;
    }

    if(d < 0) x = -x, d = -d;

    map<int, vector<pair<ll, ll>>> mp;
    rep(i, n + 1) {
        ll a = i * x, mn = i * (i - 1) / 2, mx = i * (2 * n - i - 1) / 2;
        mp[a % d].push_back({mn + a / d, mx + a / d});
    }
    ll ans = 0;
    for(auto &x : mp) {
        sort(ALL(x.second));
        ll r = -1LL << 60;
        for(const auto &v : x.second) {
            ans += max(v.second - max(v.first, r) + 1, 0LL);
            chmax(r, v.second + 1);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 22144
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <map>
#include <cmath>
#include <cstring>

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;

const ll LINF = 1001002003004005006LL;
const int INF = 1001001001;

const int mod = 1000000007;

int main() {
    int n, m, x; cin >> n >> m >> x;
    vector<int> c(n);
    vector<vector<int>> a(n);
    rep(i,n) {
        cin >> c[i];
        rep(j,m) {
            int aij; cin >> aij;
            a[i].push_back(aij);
        }
    }
    vector<int> u(m);
    int ans = INF;
    for (int bit = 1; bit < (1<<n); ++bit) {
        rep(i,m) u[i] = 0;
        int tot = 0;
        rep(i,n) {
            if (bit & (1 << i)) {
                rep(j,m) u[j] += a[i][j];
                tot += c[i];
            }
        }
        bool ok = true;
        rep(i,m) if (u[i]<x) ok = false;
        if (ok) ans = min(ans, tot);
    }
    if (ans == INF) cout << "-1" << endl;
    else cout << ans << endl;
    return 0;
}


















Measured memory_bytes: 3636