akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>

using namespace std;

vector <int>  cookie (int n, int m) {
  if (n % 2 == 1){
    n = n - 1;
  }
  int tmp = n/2;
  n = tmp;
  m = m + tmp;
  vector <int> v;
  v.push_back(n);
  v.push_back(m);
  return v;

}

int main () {
  int A; int B; int K;
  cin >> A;
  cin >> B;
  cin >> K;
  vector <int> v;
  for (int i = 1; i <= K; i++) {
    if (i % 2 == 1) {
      v = cookie(A, B);
      A = v[0];
      B = v[1];
    } if (i % 2 == 0) {
      v = cookie(B, A);
      B = v[0];
      A = v[1];
    }
  }
  cout << A << " " << B << endl;
  return 0;
}

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

using ll = long long;
using uint = unsigned int;
template <uint MOD>
struct ModInt {
  using M = ModInt;
  uint v;
  ModInt() : v(0) {}
  ModInt(ll _v) { norm(_v % MOD + MOD); }
  M& norm(uint _v) {
    v = (_v < MOD) ? _v : _v - MOD;
    return *this;
  }
  bool operator<(const M x) const { return this->v < x.v; }
  M operator+(const M x) const { return M().norm(v + x.v); }
  M operator-(const M x) const { return M().norm(v + MOD - x.v); }
  M operator*(const M x) const { return M().norm(ll(v) * x.v % MOD); }
  M operator/(const M x) const { return *this * x.inv(); }
  M& operator+=(const M x) { return *this = *this + x; }
  M& operator-=(const M x) { return *this = *this - x; }
  M& operator*=(const M x) { return *this = *this * x; }
  M& operator/=(const M x) { return *this = *this / x; }
  M& operator++() { return *this += 1; }
  friend istream& operator>>(istream& input, M& x) {
    input >> x.v, x.norm(x.v);
    return input;
  }
  friend ostream& operator<<(ostream& output, const M& x) {
    return output << x.v;
  }
  M pow(ll n) const {
    M x(v), res(1);
    while (n) {
      if (n & 1) res *= x;
      x *= x;
      n >>= 1;
    }
    return res;
  }
  M inv() const { return (*this).pow(MOD - 2); }

  static vector<M> fact, finv;
  static void build(int n) {
    fact.assign(n + 1, 1);
    finv.assign(n + 1, 1);
    for (int i = 1; i < n + 1; i++) fact[i] = fact[i - 1] * M(i);
    for (int i = 0; i < n + 1; i++) finv[i] = fact[i].inv();
  }
  static M comb(int n, int k) {
    if (n < k || k < 0) return M(0);
    return fact[n] * finv[n - k] * finv[k];
  }
};
template <uint MOD>
vector<ModInt<MOD>> ModInt<MOD>::fact = vector<ModInt<MOD>>();
template <uint MOD>
vector<ModInt<MOD>> ModInt<MOD>::finv = vector<ModInt<MOD>>();
using mint = ModInt<uint(1e9 + 7)>;

int main() {
  mint n, m, k;
  cin >> n >> m >> k;
  mint x = 0;
  for (mint i = 1; i < m; ++i) {
    x += i * (m - i) * n * n;
  }
  mint y = 0;
  for (mint i = 1; i < n; ++i) {
    y += i * (n - i) * m * m;
  }
  mint sum = x + y;
  mint::build(n.v * m.v);
  cout << sum * mint::comb(n.v * m.v - 2, k.v - 2) << endl;
}


Measured memory_bytes: 1792
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,copy
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

x = inpl()
a,b,c = sorted(x)
n = c-a; m = c-b
res = n//2 + m//2
if n%2 != m%2:
    res += 2
elif n%2 == 1 and n%2 == 1:
    res += 1
print(res)

Measured memory_bytes: 5504
#include <bits/stdc++.h>
using namespace std;
 
 
int main()
{
 
    int64_t w,h;
    cin>>w>>h;

    vector<vector<char>> grid(w, vector<char>(h));
    for(int i=0;i<w;i++){
        for(int j=0;j<h;j++){
            cin>>grid.at(i).at(j);
        }
    }

    bool flg=true;
    for(int i=0;i<w;i++){
        for(int j=0;j<h;j++){
            if(grid.at(i).at(j)=='#'){
                if(i==0&&j==0){//top-left
                    if(grid.at(i+1).at(j)=='.'&&grid.at(i).at(j+1)=='.')
                        flg=false;
                }
                else if(i==0&&j==h-1){//top-right
                    if(grid.at(i+1).at(j)=='.'&&grid.at(i).at(j-1)=='.')
                        flg=false;
                }
                else if(i==w-1&&j==0){//bottom-left
                    if(grid.at(i-1).at(j)=='.'&&grid.at(i).at(j+1)=='.')
                        flg=false;
                }
                else if(i==w-1&&j==h-1){//bottom-left
                    if(grid.at(i-1).at(j)=='.'&&grid.at(i).at(j-1)=='.')
                        flg=false;
                }
                else if(i==0){//top
                    if(grid.at(i+1).at(j)=='.'&&grid.at(i).at(j-1)=='.'&&grid.at(i).at(j+1)=='.')
                        flg=false;
                }
                else if(i==w-1){//bottom
                    if(grid.at(i-1).at(j)=='.'&&grid.at(i).at(j-1)=='.'&&grid.at(i).at(j+1)=='.')
                        flg=false;
                }
                else if(j==0){//left
                    if(grid.at(i-1).at(j)=='.'&&grid.at(i+1).at(j)=='.'&&grid.at(i).at(j+1)=='.')
                        flg=false;
                }
                else if(j==h-1){//right
                    if(grid.at(i-1).at(j)=='.'&&grid.at(i+1).at(j)=='.'&&grid.at(i).at(j-1)=='.')
                        flg=false;
                }
                else{
                    if(grid.at(i-1).at(j)=='.'&&grid.at(i+1).at(j)=='.'&&grid.at(i).at(j-1)=='.'&&grid.at(i).at(j+1)=='.')
                        flg=false;
                }
            }
        }
    }

    if(flg)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
 
    return 0;
}   

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <cstdlib>
#include <utility>
#include <cstdio>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <map>
using ll = long long;
using itn = int;
using namespace std;
int GCD(int a, int b){
    return b ? GCD(b, a%b) : a;
}
int main() {
    string s;
    cin >> s;
    int value=700;
    for(int i=0; i<3; i++){
        if(s[i]=='o'){
            value+=100;
        }
    }
    cout << value << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
void swap(int *x,int *y){
    int tmp;
    tmp=*x;
    *x=*y;
    *y=tmp;
}
int part(int box[],int left,int right){
    int i,j,pivot;
    i=left;
    j=right+1;
    pivot=left;
    do{
        do{i++;}while(box[i]<box[pivot]);
        do{j--;}while(box[pivot]<box[j]);
        if(i<j){
            swap(&box[i],&box[j]);
        }
    }while(i<j);
    swap(&box[pivot],&box[j]);
    return j;
}
void quicksort(int box[],int left,int right){
    int pin;
    if(left<right){
        pin=part(box,left,right);
        quicksort(box,left,pin-1);
        quicksort(box,pin+1,right);
    }
}
int main(void){
    int num_Q;
    int *difficulty;
    scanf("%d",&num_Q);
    difficulty=(int *)malloc(sizeof(int)*num_Q);
    int i;
    for(i=0;i<num_Q;i++){
        scanf("%d",&difficulty[i]);
    }
    quicksort(difficulty,0,num_Q-1);
    if(difficulty[num_Q/2]==difficulty[num_Q/2-1]){
        printf("0");
        free(difficulty);
        return 0;
    }
    printf("%d",difficulty[num_Q/2]-difficulty[num_Q/2-1]);
    free(difficulty);
    return 0;

}

Measured memory_bytes: 512
from itertools import combinations
n = int(input())
l = list(map(int,input().split()))

count = 0
for i,j,k in combinations(range(n),3):
    if i != j and j != k and i != k and l[i] + l[j] > l[k] and l[j] + l[k] > l[i] and l[k]+l[i] > l[j] and l[i] != l[j] and l[j] != l[k] and l[k] != l[i]:
        count += 1
print(count)

Measured memory_bytes: 9196
#include <bits/stdc++.h>
using namespace std;
#define print(var) std::cout<<#var"="<<var<<std::endl
using Graph = vector<vector<int>>;

int main()
{
    string s;
    cin >> s;
    vector<int> output(s.size());
    int prev_renzoku = 1;
    char prev = 'R';
    int recent_rl = 0;
    for(int i=1; i<s.size(); i++){
        if(s[i]==prev){
            prev_renzoku += 1;
        }
        if(s[i] != prev){
            if(s[i] == 'L'){ //RからL
                output.at(i) += floor(float(prev_renzoku)/2); //Lに加算
                output.at(i-1) += ceil(float(prev_renzoku)/2); //Rに加算
                recent_rl = i;
            }
            if(s[i] == 'R'){ //LからR
                output.at(recent_rl-1) += floor(float(prev_renzoku)/2);//Rに加算
                output.at(recent_rl) += ceil(float(prev_renzoku)/2);
            }
            prev_renzoku = 1;
            prev = s[i];
        }
        if(i == s.size()-1){
                output.at(recent_rl-1) += floor(float(prev_renzoku)/2);//Rに加算
                output.at(recent_rl) += ceil(float(prev_renzoku)/2);
        }

    }
    for(auto elem:output){cout << elem << " ";}
}

//状態の表示
//debug関数（単純な表示＋endl）
//文字列の比較

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

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> sunuke(N);
  while (K--) {
    int D;
    cin >> D;
    for (int i = 0; i < D; i++) {
      int A;
      cin >> A;
      sunuke.at(--A)++;
    }
  }
  int ans = 0;
  for (int i = 0; i < N; i++) if (!sunuke.at(i)) ans++;
  cout << ans << "\n";
}

Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
#include <string>
#include <queue>
#include <cmath>
#include <map>
#include <iomanip>
#include <unordered_map>
#include <stack>
#include <cstring>
#include <cctype>
#include <random>

using namespace std;
typedef long long  ll;
const ll INF = 1000000007;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (n); ++i)


int main() {
	string s;
	cin >> s;
	if (s[s.length() - 1] == 's') {
		s += "es";
	}
	else {
		s += "s";
	}
	cout << s << endl;
	return 0;
}

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

int main(){

    ll X, Y;
    cin >> X >> Y;

    ll temp = X, cnt = 0;
    while (temp<=Y){
        cnt++;
        temp *= 2;
    }

    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long int ll;
 
#define pii pair<int, int>
#define F first
#define S second
#define pb push_back
 
const int N = 5e5 + 5;
const int mod = 1e9+7;
const ll INF = (ll)1e18;

int main(){
    ios_base :: sync_with_stdio(0);
    cin.tie(0);
 
    int n;
    cin >> n;
    int a = 0, b = 0, c = 0;
    for(int j = 1; j <= n; j++){
        int x, y, z;
        cin >> x >> y >> z;
        int a1 = x+max(b, c), b1 = y+max(a, c), c1 = z+max(a, b);
        a = a1, b = b1, c = c1;
    }
    cout << max(a, max(b, c));
    return 0;
}

Measured memory_bytes: 256
import scala.io.{StdIn => in}
import scala.collection.{mutable => mu}

object Main extends App {
  import MapHelper._

  val Array(n, m) = in.readLine.split(" ").map(_.toInt)
  val map = mu.HashMap.empty[Long,Int]

  in.readLine.split(" ").map(_.toLong).foreach(map.addOrUpdate(_,1))
  Iterator.continually(in.readLine)
    .take(m)
    .map(_.split(" ").map(_.toInt))
    .foreach(e => map.addOrUpdate(e(1), e(0)))

  val keys = map.keys.toArray.sorted(Ordering[Long].reverse)
  def rec(acc:Long, cnt:Int, i:Int):Long = {
    val v = keys(i)
    val p =  map(keys(i))
    if(cnt + p >= n) acc + v * (n - cnt)
    else rec(acc + v * p, cnt + p, i + 1)
  }

  val ans = rec(0, 0, 0)
  println(ans)

  object MapHelper {
    implicit class AddOrUpdate[A](map:mu.HashMap[Long,Int]) {
      def addOrUpdate(key:Long, value:Int):mu.HashMap[Long,Int] =
      {
        if(map.contains(key)) map(key) += value
        else map += (key -> value)
        map
      }
    }
  }
}

Measured memory_bytes: 98152
N,M=map(int,input().split())

C=[[] for i in range(N)]

for i in range(M):
    a,b=map(int,input().split())
    C[a-1].append(b-1)
    C[b-1].append(a-1)

cnt=0
f=True
while f:
    f=False
    for i in range(N):
        if len(C[i])==1:
            cnt+=1
            idx=C[C[i][0]].index(i)
            C[C[i][0]].pop(idx)
            C[i].pop()
            f=True
print(cnt)




Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define ll long long
#define pli pair<ll, int>
#define fir first
#define sec second
using namespace std;
const int MAXN = 1e5 + 7;
const int mod = 1e9 + 7;
const ll INF = 1e17;
inline ll add(ll x, ll y) {return (x + y) % mod;}
inline ll mul(ll x, ll y) {return (x * y) % mod;}
inline ll sub(ll x, ll y) {return (x - y + mod) % mod;}
vector<pli>G[MAXN];
bool vis[MAXN];
int n, m;
void dijkstra(int s, ll *dis, ll *f)
{
    priority_queue<pli, vector<pli>, greater<pli> >pq;
    for (int i = 1; i <= n; i++) vis[i] = 0, dis[i] = INF;
    pq.push({dis[s] = 0, s}); f[s] = 1;
    while (pq.size())
    {
        int u = pq.top().sec; pq.pop();
        if (vis[u]) continue;
        vis[u] = 1;
        for (pli e : G[u])
        {
            int v = e.sec, w = e.fir;
            if (dis[v] > dis[u] + w)
            {
                pq.push({dis[v] = dis[u] + w, v});
                f[v] = f[u];
            }
            else if (dis[v] == dis[u] + w) f[v] = add(f[v], f[u]);
        }
    }
}

ll dis[2][MAXN], f[2][MAXN];
int main()
{
    scanf("%d%d", &n, &m); 
    int S, T; scanf("%d%d", &S, &T);
    for (int i = 1, u, v, w; i <= m; i++)
    {
        scanf("%d%d%d", &u, &v, &w);
        G[u].emplace_back(w, v);
        G[v].emplace_back(w, u);
    }
    dijkstra(S, dis[0], f[0]);
    dijkstra(T, dis[1], f[1]);
    ll len = dis[0][T]; 
    ll ans = mul(f[0][T], f[0][T]); 
    for (int i = 1; i <= n; i++)
        if (dis[0][i] + dis[1][i] == len && dis[0][i] == dis[1][i]) 
            ans = sub(ans, mul(mul(f[0][i], f[1][i]), mul(f[1][i], f[0][i])));
    for (int u = 1; u <= n; u++)
        for (pli e : G[u])
        {
            int v = e.sec; ll w = e.fir;
            if (dis[0][u] + w + dis[1][v] == len && dis[0][u] + w > dis[1][v] && dis[1][v] + w > dis[0][u])
                ans = sub(ans, mul(mul(f[0][u], f[1][v]), mul(f[1][v], f[0][u])));
        }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 18900
#include <bits/stdc++.h>
using namespace std;
using ll =long long ;
ll gcd(ll p,ll q){
  if(p%q==0)return q;
  return gcd(q,p%q);
}
int main() {
  ll a,b,c;
  cin>>a>>b>>c;
  if(a+b+c>=22){
    cout<<"bust"<<endl;
    return 0;
  }
  cout<<"win"<<endl;
  return 0;
}

Measured memory_bytes: 3636
n, m = map(int,input().split())
l = sorted(list(map(int,input().split())) for i in range(n))
ans = 0
for i in range(n):
  if l[i][1] <= m:
    ans += l[i][0] * l[i][1]
    m -= l[i][1]
  elif m >= 0 and l[i][1] >= m:
    ans += l[i][0] * m
    break
print(ans)

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

dp=[False for i in range(k+1)]

for i in range(min(a),k+1):
    dp[i]=any(not dp[i-j] for j in a if i>=j)

print('First' if dp[k] else 'Second')

Measured memory_bytes: 3864
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <iomanip>
#include <assert.h>

using namespace std;

const int MAXN = 200005;

int n,m,q;
int MAX[MAXN];

pair<int,int> c[MAXN];

void update(int p,int x)
{
	while (p <= m)
	{
		MAX[p] = max(MAX[p],x);
		p += (p & -p);
	}
}

int query(int p)
{
	int res = -(1 << 30);
	while (p >= 1)
	{
		res = max(res,MAX[p]);
		p -= (p & -p);
	}
	return res;
}

int main()
{
	scanf("%d%d%d",&n,&m,&q);
	for (int i = 1;i <= q;i++)
		scanf("%d%d",&c[i].first,&c[i].second);
	sort(c + 1,c + q + 1);
	for (int i = 1;i <= m;i++)
		MAX[i] = -(1 << 30);
	for (int i = 1;i <= q;i++)
	{
		if (c[i].first < c[i].second)
			continue;
		if (c[i].first == c[i].second)
		{
			update(c[i].second,0);
			continue;
		}
		if (c[i].first - c[i].second > query(c[i].second) + 1)
		{
			cout << c[i].first - 1 << endl;
			return 0;
		}
		else
			update(c[i].second,c[i].first - c[i].second);
	}
	cout << n << endl;
	return 0;
}

Measured memory_bytes: 2560
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define str to_string
#define endl "\n"
#define PI 3.141592653589
using namespace std;
using lint = long long;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

//AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC
int main(){
    int h,w,m,x,y;cin>>h>>w>>m;
    vector<int> bh(0);
    vector<int> bw(0);
    vector<int> height(h);
    vector<int> width(w);
    for(int i=0;i<m;i++){
        cin>>x>>y;
        height[x-1]++;
        width[y-1]++;
        bh.pb(x-1);
        bw.pb(y-1);
    }
    int hbest=*max_element(all(height)),wbest=*max_element(all(width));
    lint cross=count(all(height),hbest)*count(all(width),wbest);
    for(int i=0;i<m;i++){
        if(height[bh[i]]==hbest&&width[bw[i]]==wbest)cross--;
    }
    int ans=hbest+wbest;
    if(cross==0)ans--;
    cout<<ans<<endl;
}


Measured memory_bytes: 8764
"use strict";
// import bigInt from 'big-integer'

const Main = input => {
  input = input.trim().split("\n");
  const num500 = input[0];
  const num100 = input[1];
  const num50 = input[2];
  const target = parseInt(input[3], 10);

  const tries = [];
  let count = 0;

  // 500
  for (let i = 0; i < num500; i++) {
    const num = (i + 1) * 500;
    if (target === num) count++;
    else if (target < num) break;
  }
  // 500, 100
  for (let i = 0; i < num500; i++) {
    for (let j = 0; j < num100; j++) {
      const num = (i + 1) * 500 + (j + 1) * 100;
      if (target === num) count++;
      else if (target < num) break;
    }
  }
  // 500, 100, 50
  for (let i = 0; i < num500; i++) {
    for (let j = 0; j < num100; j++) {
      for (let k = 0; k < num50; k++) {
        const num = (i + 1) * 500 + (j + 1) * 100 + (k + 1) * 50;
        if (target === num) count++;
        else if (target < num) break;
      }
    }
  }
  // 500, 50
  for (let i = 0; i < num500; i++) {
    for (let j = 0; j < num50; j++) {
      const num = (i + 1) * 500 + (j + 1) * 50;
      if (target === num) count++;
      else if (target < num) break;
    }
  }
  // 100
  for (let i = 0; i < num100; i++) {
    const num = (i + 1) * 100;
    if (target === num) count++;
    else if (target < num) break;
  }
  // 100, 50
  for (let i = 0; i < num100; i++) {
    for (let j = 0; j < num50; j++) {
      const num = (i + 1) * 100 + (j + 1) * 50;
      if (target === num) count++;
      else if (target < num) break;
    }
  }
  // 50
  for (let i = 0; i < num50; i++) {
    const num = (i + 1) * 50;
    if (target === num) count++;
    else if (target < num) break;
  }

  console.log(count);
};

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 17152
#include<bits/stdc++.h>
using namespace std;
 
#define INF 1000000000000000000LL
#define ll long long

int N;
string s[51];
ll C[51];
ll dp[51][20][20][2];

ll f(int n, int l, int r, int d)
{
	ll &ret = dp[n][l][r][d];
	if (ret != -1) return ret;
	ret = INF;

	string S = s[n].substr(l, r-l+1);
	// S 자체가 팰린드롬이어도 성공이다. 틀린 이유
	int flag = 0;
	for(int i=0; i<S.size() && i < (int)S.size()-1-i; i++)
	{
		if (S[i] != S[(int)S.size()-1-i])
		{
			flag = 1;
			break;
		}
	}
	if (flag == 0) return ret = 0;

	for(int i=1; i<=N; i++)
	{
		if (d == 0) // S의 앞과 s[i]의 뒤를 비교
		{
			int die = 0;
			for(int j=0; j<min(S.size(), s[i].size()); j++)
			{
				if (S[j] != s[i][(int)s[i].size()-1-j])
				{
					die = 1;
					break;
				}
			}
			if (die) continue;
			if (abs((int)S.size()-(int)s[i].size()) <= 1) ret = min(ret, C[i]);
			else if (S.size() > s[i].size()) ret = min(ret, f(n, l+(int)s[i].size(), r, d) + C[i]);
			else if (S.size() < s[i].size()) ret = min(ret, f(i, 0, (int)s[i].size()-1-(int)S.size(), 1-d) + C[i]);
		}
		else if (d == 1) // S의 뒤와 s[i]의 앞을 비교
		{
			int die = 0;
			for(int j=0; j<min(S.size(), s[i].size()); j++)
			{
				if (S[(int)S.size()-1-j] != s[i][j])
				{
					die = 1;
					break;
				}
			}
			if (die) continue;
			if (abs((int)S.size()-(int)s[i].size()) <= 1) ret = min(ret, C[i]);
			else if (S.size() > s[i].size()) ret = min(ret, f(n, l, r-(int)s[i].size(), d) + C[i]);
			else if (S.size() < s[i].size()) ret = min(ret, f(i, (int)S.size(), (int)s[i].size()-1, 1-d) + C[i]);
		}
	}
	return ret;
}

int main()
{
	memset(dp, -1, sizeof(dp));
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> N;
	for(int i=1; i<=N; i++)
		cin >> s[i] >> C[i];

	ll res = INF;
	for(int i=1; i<=N; i++)
	{
		res = min(res, f(i, 0, (int)s[i].size()-1, 0) + C[i]);
		res = min(res, f(i, 0, (int)s[i].size()-1, 1) + C[i]);
	}
	if (res == INF) res = -1;
	cout << res;
	return 0;
}

Measured memory_bytes: 3896
N = int(input())
S = input()
 
 
r = 1
ans = 0
for l in range(N):
 
    while True:
        #print(S.rfind(S[l:r+1]), S[l:r+1], l, r)
 
        if S.rfind(S[l:r+1]) >= r+1:
            r += 1
            ans = max(ans, r-l)
        else:
            break
 
print(ans)

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

using namespace std;

#define LL long long
#define N 300
#define INF 0x3f3f3f3f3f3f3f3fLL
#define B 233

const LL mod=1000000007;
LL n,p,mx,ans,a[N],c[N];
map<LL,vector< pair<LL,LL> > > mp;
struct node{LL b,c,i;}b[N];

bool cmp(node x,node y){return x.b<y.b;}

LL popcount(LL x,LL y){
	if (x>=y) return INF;
	LL ret=0;
	for (LL i=60;i>=0;i--)
		if (((x>>i)&1)!=((y>>i)&1)){
			ret++;
			return ret;
		}
		else ret+=(x>>i)&1;
	return INF;
}

int main(){
	scanf("%lld%lld",&n,&p);
	for (LL i=1;i<=n;i++) scanf("%lld",&a[i]);
	for (LL i=0;i<=60;i++){
		memset(b,0,sizeof b);
		for (LL j=1;j<=n;j++) b[j].b=a[j]%(1LL<<i),b[j].c=a[j]/(1LL<<i),b[j].i=j;
		sort(b+1,b+n+1,cmp);
		for (LL j=0;j<=n;j++){
			LL k=((j==0)?0:popcount(b[j].b,b[j+1].b)),hsh=0;
			LL mn=p-k-i; bool fl=0;
			b[j].c--;
			for (LL k=1;k<=n;k++){
				if (b[k].c<0){fl=1; break;}
				mn=min(mn,b[k].c);
			}
			if (mn<0 || fl) continue;
			for (LL k=1;k<=n;k++) c[b[k].i]=b[k].c;
			for (LL k=2;k<=n;k++) hsh=((hsh*B+(c[k]-c[k-1]))%mod+mod)%mod;
			mp[hsh].push_back(make_pair(c[1]-mn,c[1]));
		}
	}
	for (map<LL,vector< pair<LL,LL> > >::iterator i=mp.begin();i!=mp.end();i++){
		vector< pair<LL,LL> > &vec=i->second;// puts("-----");
		sort(vec.begin(),vec.end()); mx=0;
		for (LL j=0;j<(LL)vec.size();j++){ 
			if (mx<=vec[j].second){ans=(ans+vec[j].second-max(vec[j].first,mx)+1)%mod; mx=vec[j].second+1;}
		}
	}
	printf("%lld\n",ans);
	
	return 0;
}
			


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

#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define RFOR(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define LL long long
#define INF INT_MAX/3

const double EPS = 1e-14;
const double PI  = acos(-1.0);


int main(){
  int a, b, c, d;
  scanf("%d %d %d %d", &a, &b, &c, &d);

  string str;
  if (a + b > c + d) str = "Left";
  else if (a + b == c + d) str = "Balanced";
  else str = "Right";

  cout << str << endl;
}


Measured memory_bytes: 256
#include<stdio.h>

void swap(int *a,int *b){
    int temp;
    temp = *a;
    *a = *b;
    *b = temp;
}

int selectionSort(int *A,int N){
    int i,j,minj;
    int count=0;
    for(i=0;i<N-1;i++){//i?????´??????????????°
        minj=i;
        for(j=i;j<N;j++){//????°???????????????????
            if(A[j]<A[minj]){
                minj=j;
            }
        }
        if(A[minj]!=A[i]){
            swap(&A[i],&A[minj]);
            count++;
        }
    }
    return count; 
}

int main(){
    int A[100];
    int i,N,count;
    scanf("%d",&N);
    for(i=0;i<N;i++){
        scanf("%d",&A[i]);
    }
    count = selectionSort(A,N);
    for(i=0;i<N;i++){
        if(i==0){
            printf("%d",A[i]);
        }else{
            printf(" %d",A[i]);
        }
    }
    printf("\n%d\n",count);
    return 0;
}

Measured memory_bytes: 1816
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;

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

int main() {
	long long int n;
	cin >> n;
	vector<P> x(n);
	for (long long int i = 0; i < n; i++) {
		cin >> x[i].first;
		x[i].second = i;
	}
	sort(x.begin(), x.end());
	long long int m = n / 2;
	vector<P> x2(n);
	for (long long int i = 0; i < n; i++) {
		if (i < m) {
			x2[i].second = x[m].first;
		}
		else {
			x2[i].second = x[m-1].first;
		}
		x2[i].first = x[i].second;
		//cout << x2[i].first << ' ' << x2[i].second << endl;
	}
	sort(x2.begin(), x2.end());

	for (long long int i = 0; i < n; i++) {
		cout << x2[i].second << endl;
	}
	return 0;
}

Measured memory_bytes: 8448
/*
[abc168] D - .. (Double Dots)
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
#define ALL(c) (c).begin(), (c).end()

const int MAX_N = 2e5;

int N, M;
vector<int> g[MAX_N];
bool visited[MAX_N];
int ans[MAX_N];

bool solve() {
    queue<int> q;

    q.push(0);
    visited[0] = true;
    while (!q.empty()) {
        int v = q.front();
        q.pop();
        for (int to : g[v]) {
            if (!visited[to]) {
                visited[to] = true;
                q.push(to);
                ans[to] = v;
            }
        }
    }

    return true;
}

int main() {
    cin >> N >> M;
    for (int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        g[a - 1].push_back(b - 1);
        g[b - 1].push_back(a - 1);
    }

    if (solve()) {
        cout << "Yes" << endl;
        for (int i = 1; i < N; i++) {
            cout << ans[i] + 1 << endl;
        }
    } else {
        cout << "No" << endl;
    }

    return 0;
}


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

int main(){
    int x,y;
    cin >> x >> y;
    if(y%2 == 0 && x*2<=y && x*4 >= y) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3636
/* author   : mpily :-()
title : Competing.cpp
time :Sun Jun 14 13:11:23 2020

*/
#include<climits>
#include<random>
#include<cassert>
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<algorithm>
#include<utility>
#include<cstdint>
#include<queue>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstdio>
//4611686018427387903
using namespace std;
void solve(int cnum){	
	int h,w,k;
	cin >> h >> w >> k;
	vector<vector<char>>arr(h,vector<char>(w));
	for(int i = 0; i < h; ++i){
		for(int j = 0; j < w; ++j){
			cin >> arr[i][j];
		}
	}
	int ans = 0;
	for(int mask = 0; mask < 1<<(h+w); ++mask){
		int count = 0;
		for(int i = 0; i < h; ++i){
			if((1 << i)&mask)continue;
			for(int j = 0; j < w; ++j){
				if((1 <<(h+j))&mask)continue;
				count+=(arr[i][j]=='#'?1:0);
			}
		} 
		if(count == k)
			ans++;
	}
	cout << ans <<"\n";
	
}
int main(){
	
	//ios_base::sync_with_stdio(false);
	//cin.tie(nullptr);
	//cout.tie(nullptr);
	//initprime();
	int t;
	int count = 1;
	for(t = 1;t--; solve(count),count++);
	return 0;
}

Measured memory_bytes: 3624
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue> //priority_queue 优先队列
#include <map>
#include <set> //multiset  set<int>::reverse_iterator rit; for(rit=s.rbegin();rit!=s.rend();rit++)
#include <vector>
#include <stack>
#include <cmath>
#include <utility>
#include <sstream>
#include <string>
#define mod 1000000007
#define mod9 998244353
typedef unsigned long long ull;
typedef long long ll;
typedef double db;
const db eps=1e-6;
const int INF = 0x3f3f3f3f;
const ll inf=0x3f3f3f3f3f3f3f3f;
const int N=1e6+8;
inline ll read(){ll s=0,w=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();return s*w;}
using namespace std;

int t,n,m,k,ans=0;
int a[N]={0},b[N]={0},p[N]={0};
int main(){
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
        p[i]=i+1;
    }
    for(int i=0;i<n;i++){
        scanf("%d",&b[i]);
    }
    int time=1,ans1=0,ans2=0;
    do{
        int flag1=0,flag2=0;
        for(int i=0;i<n;i++){
            if(a[i]!=p[i]) flag1=1;
            if(b[i]!=p[i]) flag2=1;
        }
        if(flag1==0) ans1=time;
        if(flag2==0) ans2=time;
        if(ans1&&ans2) break;
        time++;
    }while(next_permutation(p,p+n));
    printf("%d\n",abs(ans1-ans2));
    return 0;
}


Measured memory_bytes: 4352
#coding utf-8
import fractions
import math
a, b = map(int,input().split())
ans = 0
g = fractions.gcd(a,b)
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

ans = len(factorization(g)) + 1
if a == 1 or b == 1:
    ans = 1
print(ans)

Measured memory_bytes: 5176
import numpy as np
n = int(input())

h_list = list(map(int, input().split()))

dp = [0] * n
dp[1] = np.abs(h_list[1] - h_list[0])
for ashiba_index in range(2, n):
    dp[ashiba_index] = min(dp[ashiba_index-1]+np.abs(h_list[ashiba_index] - h_list[ashiba_index-1]),
                           dp[ashiba_index-2] + np.abs(h_list[ashiba_index]-h_list[ashiba_index-2]))
print(dp[n-1])

Measured memory_bytes: 22760
import sys
import fractions
from collections import Counter, deque, defaultdict
from math import factorial
import heapq, bisect
import math
import itertools
sys.setrecursionlimit(10 ** 5 + 10)
INF = 10**15 +5
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))

a, b = MAP()
gcd = fractions.gcd(a,b)

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

prime = prime_factorize(gcd)
print(len(set(prime))+1)

Measured memory_bytes: 65516
require 'set'

def main(str)
  as = str.split("\n")[1].split(" ").map(&:to_i).sort
  sets = Set.new
  nmax = 10 ** 6
  as.each.with_index.count do |a, i|
    next if sets.include?(a)
    x = a
    loop do
      sets << x
      x += a
      break if x > nmax
    end
    as[i + 1] != a
  end
end

unless ENV["TEST"]
  puts(main($stdin.read.chomp))
  exit(0)
end

require 'minitest/autorun'

class TestA < Minitest::Test
  def test_main
    assert_equal(3, main("5
24 11 8 3 16"))
    assert_equal(0, main("4
5 5 5 5"))
    assert_equal(5, main("10
33 18 45 28 8 19 89 86 2 4"))
  end
end





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

using namespace std;

int num_components = 0;
vector<int> component_idx, color;
vector< vector<int> > adj_matrix;

bool bipartite(int current_v) {
    // current_v is already colored and assigned a component index
    int n = adj_matrix[current_v].size();
    for (int next_v = 1; next_v <= n; ++next_v) {
        if (!adj_matrix[current_v][next_v]) continue;
        if (color[next_v] != -1) {
            if (color[next_v] == color[current_v]) return false;
        } else {
            color[next_v] = (color[current_v] ^ 1);
            component_idx[next_v] = component_idx[current_v];
            if (!bipartite(next_v)) return false;
        }
    }
    return true;
}

int main() {
    // Inputs
    int n;
    cin >> n;
    component_idx = vector<int>(n + 1, -1);
    color = vector<int>(n + 1, -1);
    adj_matrix = vector< vector<int> >(n + 1, vector<int>(n + 1, 0));
    for (int i = 1; i <= n; ++i) {
        string str;
        cin >> str;
        for (int j = 1; j <= n; ++j) {
            adj_matrix[i][j] = (str[j - 1] == '1');
        }
    }
    
    // Check if the graph is bipartite
    // Assign component numbers for each vertex
    for (int i = 1; i <= n; ++i) {
        if (component_idx[i] == -1) { // This vertex, or component to which this vertex belongs, is not visited yet.
            component_idx[i] = num_components++;
            color[i] = 0;
            if (!bipartite(i)) {
                cout << -1 << endl; 
                return 0;
            }
        }        
    }    
    
    // Perform BFS starting from each vertex.
    //     If BFS is successful, update the answer for that component 
    vector<int> max_partitions(num_components, 2);  
    for (int i = 1; i <= n; ++i) {
        vector<bool> visited(n + 1, false);
        vector<int> depth(n + 1, 1e9);
        queue<int> q;
        q.push(i);
        depth[i] = 0;
        int max_depth = 0;
        while (!q.empty()) {
            int current_v = q.front();
            q.pop();
            for (int next_v = 1; next_v <= n; ++next_v) {
                if (!adj_matrix[current_v][next_v]) continue;
                if (depth[next_v] == 1e9) {
                    depth[next_v] = depth[current_v] + 1;
                    max_depth = max(max_depth, depth[next_v]);
                    q.push(next_v);
                }
            }
        }
        int &max_p = max_partitions[component_idx[i]];
        max_p = max(max_p, max_depth + 1);
    }
    
    int ans = 0;
    for (int i = 0; i < num_components; ++i) {
        ans += max_partitions[i];
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<(n);++i)
#define rep2(i,a,b) for (ll i=(a);i<(b);++i)
#define debug(x) cout << #x << '=' << x << endl
#define all(v) (v).begin(),(v).end()
const ll MOD=1e9+7;
//const ll MOD=998244353;
const ll INF=1e9;
const ll IINF=1e18;
const double EPS=1e-8;
const double pi=acos(-1);

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,M; cin >> N >> M;
    vector<int> p(M),q(M),c(M);
    vector<Pii> stas;
    rep(i,N) stas.push_back({i,-1});
    rep(i,M){
        cin >> p[i] >> q[i] >> c[i];
        --p[i],--q[i];
        stas.push_back({p[i],c[i]});
        stas.push_back({q[i],c[i]});
    }
    sort(all(stas));
    stas.erase(unique(all(stas)),stas.end());
    map<Pii,int> m;
    int sz=stas.size();
    rep(i,sz) m[stas[i]]=i;
    vector<vector<Pii>> G(sz);
    rep(i,sz){
        if (stas[i].second==-1) continue;
        int s=stas[i].first,t=m[{s,-1}];
        G[i].push_back({t,0});
        G[t].push_back({i,1});
    }
    rep(i,M){
        int a=m[{p[i],c[i]}],b=m[{q[i],c[i]}];
        G[a].push_back({b,0});
        G[b].push_back({a,0});
    }
    int s=m[{0,-1}],t=m[{N-1,-1}];
    vector<int> dist(sz,INF);
    dist[s]=0;
    deque<int> dq;
    dq.push_back(s);
    while (!dq.empty()){
        int v=dq.front(); dq.pop_front();
        for (auto p:G[v]){
            int nv=p.first,cost=p.second;
            if (chmin(dist[nv],dist[v]+cost)){
                if (cost==0) dq.push_front(nv);
                else dq.push_back(nv);
            }
        }
    }
    if (dist[t]==INF) cout << -1 << endl;
    else cout << dist[t] << endl;
}

Measured memory_bytes: 69996
N = int(input())
Alist = list(map(int, input().split()))

n_dic = {}
for a in Alist:
    if a in n_dic.keys():
        n_dic[a] += 1
    else:
        n_dic[a] = 1

base = 0
for k, v in n_dic.items():
    base += v * (v-1) // 2


for k in range(N):
    n = n_dic[Alist[k]] - 1
    print(base - n)


Measured memory_bytes: 32328
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int L;
  cin >> L;
  int n2 = 2;
  int keta = 1;
  while (n2 <= L) {
    n2 = n2 * 2;
    keta++;
  }
  vector<bool> t2(keta,false);
  int num1 = -3;
  for (int i=0; i<keta; i++) {
    if (L%2 == 1) {
      t2[keta-1-i] = true;
      num1++;
    }
    L = L/2;
  }
  int maxx = n2/4;
  cout << keta << ' ' << keta * 2 + num1 << endl;
  int i = 1;
  while (maxx != 0) {
    cout << i << ' ' << i+1 << ' ' << maxx << endl;
    cout << i << ' ' << i+1 << ' ' << 0 << endl;
    maxx = maxx/2;
    i++;
  }
  int size = n2/2;
  n2 = size/2;
  for (int i=1; i<keta; i++) {
    if (t2[i]) {
      cout << 1 << ' ' << i+1 << ' ' << size << endl;
      size += n2;
    }
    n2 = n2 / 2;
  }
}

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

#define ll long long
#define ull unsigned long long
#define ld long double
#define pb push_back
#define pf push_front
#define pof pop_front
#define pob pop_back
#define pll pair<ll,ll>
#define pii pair<int,int>
#define pdd pair<double,double>
#define all(s) s.begin(),s.end()
#define vll vector<ll>
#define vi vector<int>
#define vpii vector<pii>
#define vpll vector<pll>
#define vull vector<ull>
#define vvi vector<vector<int>>
#define vvll vector<vector<ll>>
#define fi first
#define se second
#define sz(x) x.size()
#define cinarr(n,a) for(int i = 0; i < n; i++) cin >> a[i];
#define coutarr(n,a) for(int i = 0; i < n; i++) cout << a[i] << (i+1==n?'\n':' ');
#define fori(i,a,b,x) for(int i = a; i <= b; i+=x)
#define ford(i,a,b,x) for(int i = a; i >= b; i-=x)
#define tc int tt; scanf("%d",&tt); for(int cs = 1; cs <= tt; cs++)
#define IOS ios_base::sync_with_stdio(0); cin.tie(NULL);
#define reset(x,y) memset(x,y,sizeof x);
#define EPS 1e-10
#define INF 2000000000
#define mod 1000000007
#define debug(val) cerr << "The value of " << #val << " is = " << val << endl;
#define testing cerr << "--------------------------\n";
vi ada(200005,0);
int ans=-1;
int main() { 
	IOS
	int n;
	cin>>n;
	ada[0]=1;
	for(int i = 0,x; i < n; i++) {
		cin>>x;
		ada[x]=ada[x-1];
		if(ada[x]) {
			ans=max(ans,x);
		}
	}
	if(ans==-1) {
		cout<<"-1\n";
	} else {
		cout<<n-ans<<endl;
	}
}


Measured memory_bytes: 3884
// ALDS1_10_B Matrix Chain Multiplication
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#define INF 900000000
bool debug = false;
std::vector<std::vector<int>> dp;

void MatrixChainMultiplication(std::vector<std::pair<int,int>> sequence) {
    dp.resize(sequence.size());
    for (int i=0; i<dp.size(); i++) dp.at(i).resize(sequence.size());

    /*
    example:
        aN is a matrix. 
        ... a3 (a4 a5 a6)*(a7 a8) a9 ...
        i = 5, j = 4, k = 3
    */

    /* i = length of set */
    for (int i=2; i<dp.size(); i++) {
        /* j = front point */
        for (int j=1; j<=dp.at(i).size()-i; j++) {
            /* initialization of dp.at(i).at(j) */
            dp.at(i).at(j) = INF;
            /* k = dividing point */
            for (int k=1; k<i; k++) {
                if (i == 2) {
                    dp.at(i).at(j) = sequence.at(j).first*sequence.at(j).second*sequence.at(j+1).second;
                } else {
                    dp.at(i).at(j) = std::min(dp.at(i).at(j),
                                              dp.at(k).at(j)+dp.at(i-k).at(j+k)+sequence.at(j).first*sequence.at(j+k-1).second*sequence.at(i+j-1).second);
                    
                }
            }
            if (debug) {
                std::cout << "dp.at(" << i << ").at(" << j << ") = " << dp.at(i).at(j) << ":";
                for (int n=j; n<i+j; n++) std::cout << " " << n;
                std::cout << "\n";
            }
        }
    }
    std::cout << dp.back().at(1) << "\n";
}

int main() {
    int total; std::cin >> total;
    std::vector<std::pair<int,int>> sequence;
    sequence.resize(total+1);
    for (int i=1; i<sequence.size(); i++) {
        std::cin >> sequence.at(i).first >> sequence.at(i).second;
    }
    MatrixChainMultiplication(sequence);
}   


Measured memory_bytes: 3116
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> P;
typedef vector<P> vp;
typedef vector<string> vs;
typedef vector<bool> vb;

const ll mod=1e9+7;
const ll inf=1e16;

#define rep(i,m,n) for(ll i=m;i<n;i++)
#define repr(i,m,n) for(ll i=m-1;i>=n;i--)
#define fi first
#define se second
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
#define eb(x) emplace_back(x)
#define pb(x) pop_back(x)
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define sum(x) accumulate(all(x),0)
#define pc(x) __builtin_popcount(x)
#define gll greater<ll>()

ll mod_pow(ll x, ll n){
 if(n==0) return 1;
ll res=mod_pow(x*x%mod,n/2);
if(n&1) res=res*x%mod;
return res;
}


void solve(){
 ll n;
  cin >> n;
 vll x(n);
  rep(i,0,n) cin >> x[i];
 
 ll fac=1;
 rep(i,1,n) {
   fac*=i; 
   fac%=mod;
 }
  
 vll p(n+1,0);
 rep(i,1,n+1){
   p[i]=(fac*mod_pow(i,mod-2))%mod;
   p[i]+=p[i-1];
   p[i]%=mod;
 }
  
 ll ans=0;
  rep(i,0,n-1) {
    ans+=((x[i+1]-x[i])*p[i+1])%mod;
   ans%=mod;
  }
  cout << ans << endl;
}

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

Measured memory_bytes: 4732
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <iomanip>
#include <numeric>
using namespace std;


main()
{
    int s,w ; cin>>s>>w;
    if(s>w) cout << "safe" << "\n";
    else cout << "unsafe" << "\n";
}

Measured memory_bytes: 3596
//Littleboy123 Template 1.0

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

typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long long int ll;
typedef unsigned long long int ull;

#define FOR(a,b,c) for(ll (a)=(b);(a)<(c);++(a))
#define FORE(a,b,c) for(ll (a)=(b);(a)<=(c);++(a))
#define FORN(a,b,c) for(ll (a)=(b);(a)>(c);--(a))
#define FORNE(a,b,c) for(ll (a)=(b);(a)>=(c);--(a))
#define COUT(a) cout << (a) << '\n'
#define MEM(a,b) memset((a), (b), sizeof((a)));
#define nl '\n'
#define fi first
#define se second
#define mp make_pair
#define pb push_back

void init(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
}

//End of template

int main(){
	init();
	int n, d;
	cin >> n >> d;
	long double arr[n][d];
	FOR(i, 0, n){
		FOR(j, 0, d){
			cin >> arr[i][j];
		}
	}
	int count = 0;
	FOR(i, 0, n){
		FOR(j, i+1, n){
			long double sum = 0;
			FOR(k, 0, d){
				sum += pow(arr[i][k] - arr[j][k], 2);
			}
			if(sqrt(sum) == ceil(sqrt(sum))){
				count++;
			}
		}
	}
	cout << count << nl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<math.h>
#include<algorithm>
#include<iomanip>
#include<list>
using namespace std;

int main() {

	long N, K;
	cin >> N >> K;

	vector<long> tree(N, 0);

	for (long i = 0; i < tree.size(); i++) {
		cin >> tree[i];
	}

	sort(tree.begin(), tree.end(), greater<long>());

	long diff = 0;
	long min = tree[0];
	for (long i = 0; i <= N - K; i++) {
		diff = tree[i] - tree[i + K - 1];
		if (diff < min) {
			min = diff;
		}
	}

	cout << min << endl;

	return 0;
}



Measured memory_bytes: 1024
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
using std::cin; using std::cout;
using std::endl;
using std::bitset; using std::map;
using std::queue; using std::priority_queue;
using std::set; using std::string;
using std::stringstream; using std::vector;
using std::pair; using std::make_pair;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
typedef pair<ULL, ULL> puu;
#ifdef DEBUG
using std::cerr;
#define pass cerr << "[" << __FUNCTION__ << "] : line = " << __LINE__ << endl;
#define display(x) cerr << #x << " = " << x << endl;
#define displaya(a, st, n)                      \
	{                                           \
		cerr << #a << " = {";                   \
		for (int qwq = (st); qwq <= (n); ++qwq) \
			if (qwq == (st))                    \
				cerr << a[qwq];                 \
			else                                \
				cerr << ", " << a[qwq];         \
		cerr << "}" << endl;                    \
	}
#define displayv(a) displaya(a, 0, (int)(a.size() - 1))
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#include <ctime>
class MyTimer {
	clock_t st;
public:
	MyTimer() { cerr << std::fixed << std::setprecision(0); reset(); }
	~MyTimer() { report(); }
	void reset() { st = clock_t(); }
	void report() {  cerr << "Time consumed: " << (clock() - st) * \
		1e3 / CLOCKS_PER_SEC << "ms" << endl; }
} myTimer;
#else
#define cerr if(false) std::cout
#define pass ;
#define display(x) ;
#define displaya(a, st, n) ;
#define displayv(a) ;
#define eprintf(...) if(0) fprintf(stderr, __VA_ARGS__)
class MyTimer {
public: void reset() {} void report() {}
} myTimer;
#endif

template<typename A, typename B>
std::ostream& operator << (std::ostream &cout, const pair<A, B> &x) {
	return cout << "(" << x.first << ", " << x.second << ")";
}
template<typename T1, typename T2>
inline bool chmin(T1 &a, const T2 &b) { return a > b ? a = b, true : false; }
template<typename T1, typename T2>
inline bool chmax(T1 &a, const T2 &b) { return a < b ? a = b, true : false; }

vector<int> a, b;

int main() {
	std::ios::sync_with_stdio(false);
	int n; cin >> n;
	b.assign(n, 0);
	for(int i = 0; i < n; ++i) cin >> b[i];
	while(b.size()) {
		int p = -1;
		for(int i = 0; i < (int)b.size(); ++i) {
			if(b[i] == i + 1) p = i;
		}
		if(p == -1) {
			cout << -1 << endl; return 0;
		}
		b.erase(b.begin() + p);
		a.push_back(p + 1);
	}
	std::reverse(a.begin(), a.end());
	for(int x : a) cout << x << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LL long long
#define MOD 1000000007
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define print(a, n) for(LL e=0; e<n; e++) cout<<a[e]<<" "; cout<<endl
#define read(a, n) for(LL e=0; e<n; e++) cin>>a[e];
using namespace std;

int main()
{
	fastio;
	int n, k;
	cin>>n>>k;

	set<int> s;
	for(int i=0; i<k; i++){
		int d;
		cin>>d;
		while(d--){
			int a;
			cin>>a;
			s.insert(a);
		}
	}

	cout<<n-s.size()<<"\n";

	return 0;
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
int N;
void dfs(string s) {
   if (s.length() == N) {
      cout << s << endl;
      return;
   }
   char moji = 'a';
   for(char c : s) {
      moji = max(c, moji);
   }
   
   for(char str = 'a'; str <= moji + 1; str++) {
      
      dfs(s + str);
   }
}
int main() {
   cin >> N;
   string s = "a";
  dfs(s);
 return 0;

}

Measured memory_bytes: 1536
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		// A, B, Cの入力
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		
		// 結果の出力
		System.out.println(C-(A-B) > 0 ? C-(A-B) : 0);
		
		sc.close();
	}
}


Measured memory_bytes: 23892
//#define		FILE_INPUT_DEFINE
#ifdef		FILE_INPUT_DEFINE
#include	<fstream>
#endif		// FILE_INPUT_DEFINE

#include	<iostream>
#include	<string>
#include	<algorithm>

using namespace std;

#define			MAX		1000
#define			ind(x)		((x) - 1)

int C[MAX + 1][MAX + 1];

int LCS(string &X, string &Y)
{
	int			Xlen = X.length();
	int			Ylen = Y.length();

	for (int i = 0; i <= Xlen; ++i)
	{
		C[i][0] = 0;
	}

	for (int i = 0; i <= Ylen; ++i)
	{
		C[0][i] = 0;
	}

	for (int i = 1; i <= Xlen; ++i)
	{
		for (int j = 1; j <= Ylen; ++j)
		{
			if (X[ind(i)] == Y[ind(j)])
			{
				C[i][j] = C[i - 1][j - 1] + 1;
			}
			else
			{
				C[i][j] = max(C[i - 1][j], C[i][j - 1]);
			}
		}
	}

	return (C[Xlen][Ylen]);
}

int main()
{
#ifdef		FILE_INPUT_DEFINE
	// input from txt
	std::ifstream in(R"(C:\Temp\input.txt)");
	std::cin.rdbuf(in.rdbuf());
#endif		// FILE_INPUT_DEFINE

	string	X, Y;
	int		n;

	cin >> n;
	cin.clear();
	cin.ignore();

	for (int i = 0; i < n; ++i)
	{
		getline(cin, X);
		getline(cin, Y);

		cout << LCS(X, Y) << endl;
	}

	return 0;
}

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

int main() {
	int n;
	unsigned long long int t = 0;
	cin >> n;
	vector<pair<int, int>> p(n);
	for (int i = 0; i < n; ++i) cin >> p[i].second >> p[i].first;
	sort(p.begin(), p.end());
	for (int i = 0; i < n; ++i) {
		t += p[i].second;
		if (p[i].first < t) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 1792