akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

template<unsigned P> struct ModInt {
  using M = ModInt;
  unsigned v;
  ModInt() : v(0) {}
  ModInt(auto x) : v(x >= 0 ? x % P : (P - -x % P) % P) {}
  constexpr ModInt(unsigned v, int) : v(v) {}
  static constexpr unsigned p() { return P; }
  M operator+() const { return *this; }
  M operator-() const { return {v ? P - v : 0, 0}; }
  explicit operator bool() const noexcept { return v; }
  bool operator!() const noexcept { return !(bool) *this; }
  M operator*(M r) const { return M(*this) *= r; }
  M operator/(M r) const { return M(*this) /= r; }
  M operator+(M r) const { return M(*this) += r; }
  M operator-(M r) const { return M(*this) -= r; }
  bool operator==(M r) const { return v == r.v; }
  bool operator!=(M r) const { return !(*this == r); }
  M& operator*=(M r) { v = (uint64_t) v * r.v % P; return *this; }
  M& operator/=(M r) { return *this *= r.inv(); }
  M& operator+=(M r) { if ((v += r.v) >= P) v -= P; return *this; }
  M& operator-=(M r) { if ((v += P - r.v) >= P) v -= P; return *this; }
  M inv() const {
    int a = v, b = P, x = 1, u = 0;
    while (b) {
      int q = a / b;
      swap(a -= q * b, b);
      swap(x -= q * u, u);
    }
    assert(a == 1);
    return x;
  }
  M pow(auto n) const {
    if (n < 0) return pow(-n).inv();
    M res = 1;
    for (M a = *this; n; a *= a, n >>= 1) if (n & 1) res *= a;
    return res;
  }
  friend M operator*(auto l, M r) { return M(l) *= r; }
  friend M operator/(auto l, M r) { return M(l) /= r; }
  friend M operator+(auto l, M r) { return M(l) += r; }
  friend M operator-(auto l, M r) { return M(l) -= r; }
  friend ostream& operator<<(ostream& os, M r) { return os << r.v; }
  friend istream& operator>>(istream& is, M& r) { lint x; is >> x; r = x; return is; }
  friend bool operator==(auto l, M r) { return M(l) == r; }
  friend bool operator!=(auto l, M r) { return !(l == r); }
};
using Mint = ModInt<(unsigned) 1e9 + 7>;
V<Mint> fact, ifact, inv, powB;
void init(int n, int B = 2) {
  fact.resize(n + 1);
  fact[0] = 1;
  for (int i = 1; i <= n; ++i) {
    fact[i] = i * fact[i - 1];
  }
  ifact.resize(n + 1);
  ifact[n] = fact[n].inv();
  for (int i = n; i > 0; --i) {
    ifact[i - 1] = i * ifact[i];
  }
  inv.resize(n + 1);
  inv[1] = 1;
  for (int i = 2; i <= n; ++i) {
    int q = Mint::p() / i;
    inv[i] = -q * inv[Mint::p() - i * q];
  }
  powB.resize(n + 1);
  powB[0] = 1;
  for (int i = 0; i < n; ++i) {
    powB[i + 1] = powB[i] * B;
  }
}
Mint comb(int n, int r) {
  if (r < 0 or r > n) return 0;
  return fact[n] * ifact[r] * ifact[n - r];
}


int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int n; cin >> n;
  init(2 * n);
  Mint p, q, r; cin >> p >> q >> r;
  p /= 100, q /= 100, r /= 100;
  Mint s = p + q;
  p /= s, q /= s;
  Mint res;
  for (int m = 0; m < n; ++m) {
    res += comb(n + m - 1, m) * p.pow(n) * q.pow(m) * (n + m);
    res += comb(n + m - 1, m) * q.pow(n) * p.pow(m) * (n + m);
  }
  res /= 1 - r;
  cout << res << '\n';
}

Measured memory_bytes: 3456
import Control.Applicative
import Control.Monad

match :: Int -> Int -> Int -> Int -> Int -> Bool
match a b c x y = (a == x && b == y) || (b == x && c == y) || (c == x && a == y)

solve :: [Int] -> [Int] -> Int
solve [a, b, c, d, e, f] [x, y]
    | match a b c x y = a + b + c - x - y
    | match a c e x y = a + c + e - x - y
    | match a d b x y = a + d + b - x - y
    | match a e d x y = a + e + d - x - y
    | match f c b x y = f + c + b - x - y
    | match f e c x y = f + e + c - x - y
    | match f b d x y = f + b + d - x - y
    | match f d e x y = f + d + e - x - y

main :: IO ()
main = do
    d  <- map read <$> words <$> getLine
    n  <- readLn
    ls <- replicateM n getLine
    putStr $ unlines $ map (show . solve d) $ map (map read . words) ls

Measured memory_bytes: 4028
#include <iostream>

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

const int MAX = 2000;
int a[MAX][MAX];

int main() {
  int n, x, y;
  std::cin >> n >> x >> y;

  int d[MAX] = {0};

  rep(i, n) for (int j = i + 1; j < n; ++j) {
    a[i][j] = std::min(std::abs(j - i),
                       std::abs(x - 1 - i) + 1 + std::abs(y - 1 - j));
    d[a[i][j]]++;
  }

  for (int k = 1; k < n; ++k) {
    std::cout << d[k] << '\n';
  }
  return 0;
}


Measured memory_bytes: 15360
INF = 10 ** 10
N, A, B, C = [int(x) for x in input().split()]
L = [int(input()) for _ in range(N)]


def solve(index, ma, mb, mc):
    if index == N:
        if len(ma) == 0 or len(mb) == 0 or len(mc) == 0:
            return INF
        cost = (len(ma) + len(mb) + len(mc) - 3) * 10
        cost += abs(sum(ma) - A)
        cost += abs(sum(mb) - B)
        cost += abs(sum(mc) - C)
        return cost
    t0 = solve(index + 1, ma, mb, mc)
    ta = solve(index + 1, ma + [L[index]], mb, mc)
    tb = solve(index + 1, ma, mb + [L[index]], mc)
    tc = solve(index + 1, ma, mb, mc + [L[index]])
    return min(t0, ta, tb, tc)


res = solve(0, [], [], [])
print(res)


Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<vector>
#define ll long long 
using namespace std;
ll gcd(ll a,ll b){
	return b==0?a:gcd(b,a%b);
}
int main(){
	ll A;
	ll ans=0;
	cin>>A;
	for(int i=1;i<=A;i++)
	{
		for(int j=1;j<=A;j++)
		{
			for(int k=1;k<=A;k++)
			{
				ans+=(gcd(gcd(i,j),k));
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3596
package main

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

func solve() {
	m := make(map[rune][]rune)
	for r := 'a'; r <= 'c'; r++ {
		m[r] = getRunes()
	}

	now := 'a'
	for len(m[now]) > 0 {
		next := m[now][0]
		m[now] = m[now][1:]
		now = next
	}

	ans := string(now - 'a' + 'A')
	fmt.Fprintln(wr, ans)
}

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

const (
	inf = 1 << 60
	// mod = 1000000007
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wr = bufio.NewWriter(os.Stdout)
)

func main() {
	// buf := 200001
	// sc.Buffer(make([]byte, buf), buf)
	sc.Split(bufio.ScanWords)
	solve()
	wr.Flush()
}

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

func getIntSlice(n int) []int {
	is := make([]int, n)
	for i := range is {
		is[i] = getInt()
	}
	return is
}

func getString() string {
	sc.Scan()
	s := sc.Text()
	return s
}

func getRunes() []rune {
	return []rune(getString())
}


Measured memory_bytes: 640
#include <stdio.h>
#include <string.h>

int main() {
	char s[200001];
	scanf("%s", s);
	int i = 0, j = strlen(s);
	while (s[i] != 'A') {
		i++;
	}
	while (s[j] != 'Z') {
		j--;
	}
	printf("%d\n", j - i + 1);
	return 0;
}

Measured memory_bytes: 384
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<cmath>
#include<cstring>
#include<climits>
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
#define LL long long
//#define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1++)
//char buf[(1 << 21) + 1], *p1 = buf, *p2 = buf;
inline int read() {
	bool f=0;int x=0;char c=getchar();
	while(c<'0'||'9'<c){if(c==EOF)exit(0);if(c=='-')f=1;c=getchar();}
	while('0'<=c&&c<='9') x=(x<<3)+(x<<1)+(c^48),c=getchar();
	return !f?x:-x;
}
#define MAXN 15
#define INF 0x3f3f3f3f
#define Mod (int)(1e9+7)
int G[MAXN+5];
LL f[(1<<MAXN)+5];
int bitcnt(int x){
	int ret=0;
	while(x)
		ret++,x-=(x&(-x));
	return ret;
}
int main(){
	int n=read(),m=read();
	for(int i=1;i<=m;i++){
		int u=read()-1,v=read()-1;
		G[u]|=(1<<v);
	}
	f[0]=1;
	for(int U=0;U<=(1<<n)-1;U++)
		if((U&1)==((U>>1)&1)){
			for(int S=U;S;S=(S-1)&U)
				if((S&1)==((S>>1)&1)){
					int T=U^S;
					LL cnt=1;
					for(int i=0;i<n;i++)
						if((U>>i)&1){
							if((S>>i)&1)
								cnt=(1ll<<bitcnt(G[i]&T))*cnt%Mod;
							else cnt=((1ll<<bitcnt(G[i]&S))-1)*cnt%Mod;
						}
					f[U]=(f[U]+cnt*f[T]%Mod)%Mod;
				}
		}
	LL sum=1;
	for(int i=1;i<=m;i++)
		sum=(sum<<1)%Mod;
	printf("%lld\n",(sum-f[(1<<n)-1]+Mod)%Mod);
	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int d1,d2,cnt,t;
int main(){
    cin>>t;
    while(t--){
        scanf("%d%d",&d1,&d2);
        if(d1==d2)cnt++;
        else cnt=0;
        if(cnt>=3){cout<<"Yes"<<endl;return 0;}
    }
    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 3760
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (ll)(n); i++)

int main() {
  ll n; cin >> n;
  vector <ll> v(5, 0);
  rep(i, n) {
    string s; cin >> s;
    if (s.at(0) == 'M') v.at(0)++;
    else if (s.at(0) == 'A') v.at(1)++;
    else if (s.at(0) == 'R') v.at(2)++;
    else if (s.at(0) == 'C') v.at(3)++;
    else if (s.at(0) == 'H') v.at(4)++;
  }
  ll res = 0;
  for (ll bit = 0; bit < (1 << 5); bit++) {
    if (__builtin_popcount(bit) != 3) continue;
    ll tmp = 1;
    rep(i, 5) {
      if (bit&(1<<i)) tmp *= v.at(i);
    }
    res += tmp;
  }
  cout << res << endl;
}

Measured memory_bytes: 3616
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

using ll = long long;

ll n, m;

vector<vector<int>> g;

vector<ll> dp;
vector<vector<ll>> ch_vs;
vector<vector<ll>> cumprod_left, cumprod_right;
vector<ll> ans;

void b2t(int i, int p = -1) {
    for (int j = 0; j < g[i].size(); j++) {
        if (g[i][j] == p) {
            swap(g[i][j], g[i].back());

            g[i].pop_back();

            break;
        }
    }
    
    int k = g[i].size();

    ch_vs[i].reserve(k);

    for (int to : g[i]) {
        b2t(to, i);

        ch_vs[i].push_back(dp[to] + 1);
    }

    dp[i] = 1;
    for (int j = 0; j < k; j++) {
        dp[i] = (dp[i] * ch_vs[i][j]) % m;
    }

    cumprod_left[i].resize(k + 1, 1);
    cumprod_right[i].resize(k + 1, 1);

    for (int j = 0; j < k; j++) {
        cumprod_left[i][j + 1] = (cumprod_left[i][j] * ch_vs[i][j]) % m;
        cumprod_right[i][k - j - 1] = (cumprod_right[i][k - j] * ch_vs[i][k - j - 1]) % m;
    }
}

void t2b(int i, ll x = 0) {
    ans[i] = dp[i] * (x + 1) % m;

    int k = g[i].size();
    for (int j = 0; j < k; j++) {
        t2b(g[i][j], (x + 1) * cumprod_left[i][j] % m * cumprod_right[i][j + 1] % m);
    }
}

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

    g.resize(n);

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

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

    dp.resize(n);
    ch_vs.resize(n);
    cumprod_left.resize(n);
    cumprod_right.resize(n);
    ans.resize(n);

    b2t(0);

    t2b(0);

    for (int i = 0; i < n; i++) {
        cout << ans[i] << endl;
    }
}


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

typedef long long ll;

int main() {
    int N;
    cin >> N;
    vector<ll>a(N);
    bool check = true;
    for (int i = 0; i < N; i++) {
        cin >> a[i];
        if (check && a[i] % 2 == 0) {
            continue; 
        } else {
            check = false;
        }
    }
    if (check) {
        cout << "second" << endl;
    } else {
        cout << "first" << endl;
    }
}


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

int main() {
  int H,W;
  cin >> H >> W;
  vector<string> A(100);

  for (int i=0; i < H; i++) {
     cin >> A.at(i);
  }

  for (int i=0; i < H; i++) {
    if (i==0) {for (int k=0; k < W+2; k++) {cout << '#';}cout << endl; }
    cout << '#' << A.at(i) << '#' << endl;
    if (i==H-1) {for (int k=0; k < W+2; k++) {cout << '#';}cout << endl; }
  } 
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
#define int long long
#define R register
int a[20];
int n;
inline int dfs(int l,int r,int cl,int cr)
{
	if(r-l<2) return 0;
	int res=(1ll<<60);
	for(R int i=l+1;i<=r-1;i++)
		res=min(res,dfs(l,i,cl,cl+cr)+dfs(i,r,cl+cr,cr)+(cl+cr)*a[i]);
	return res;
}
signed main()
{
	cin>>n;
	for(R int i=1;i<=n;i++) cin>>a[i];
	cout<<dfs(1,n,1,1)+a[1]+a[n]<<endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <climits>
#include <vector>
#include <stack>
#include <cmath>
#include <queue>
#include <set>
#include <map>
using namespace std;

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

    double cc = (double)stoi(c);
    int ccc = (int)sqrt(cc);
    if(ccc * ccc == cc) {
        cout << "Yes";
    } else cout << "No";
    cout << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <iomanip>
#include <set>
#include <ctime>
#include <tuple>
#include <bitset>
#include <assert.h>
using namespace std;

/*
sort(sp.begin(), sp.end(), [](PAIR l, PAIR r){
        return l.first<r.first || (l.first==r.first && l.second > r.second);
        });
*/

typedef long long ll;

#define fi first
#define se second

using Graph = vector<vector<int>>;

struct UnionFind
{
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N)
    { //最初は全てが根であるとして初期化
        for (int i = 0; i < N; i++)
            par[i] = i;
    }

    int root(int x)
    { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x)
            return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y)
    {                     // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry)
            return;   //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y)
    { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

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

    UnionFind tree(n);
    for (int i = 0; i < m; i++)
    {
        int x, y, z;
        cin >> x >> y >> z;
        x--;
        y--;
        tree.unite(x, y);
    }
    set<int> st;
    for (int i = 0; i < n; i++)
    {
        st.insert(tree.root(i));
    }
    cout << st.size() << endl;

    return 0;
}

Measured memory_bytes: 5376
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main(void){
	char s[51];
	char t[51];
	char min[51]={'0'};
	char save[51];
	int i,j,k;
	int flag = 0;
	int cflag = 0;
	int cnt = 0;
	scanf("%s",s);
	scanf("%s",t);
	j = 0;
	for(i=0;i<strlen(s);i++){
		if(s[i] == t[j]){
			j++;
			if(j == strlen(t))break;
		}else{
			j = 0;
		}
	}
	if(j == strlen(t)){
		for(i=0;i<strlen(s);i++){
			if(s[i] == '?'){
				s[i] = 'a';
			}
		}
		printf("%s",s);
		return 0;
	}
	if(flag == 0){
		for(i=0;i<strlen(s);i++){
			strcpy(save,s);
			cflag = 0;
			cnt = 0;
			for(j=0;j<strlen(t);j++){
				if(s[i+j] == t[j] || s[i+j] == '?'){
					cnt++;
				}
			}
			if(cnt == strlen(t)){
				for(k=0;k<strlen(t);k++){
					save[i+k] = t[k];
				}
				for(k=0;k<strlen(save);k++){
					if(save[k] == '?'){
						save[k] = 'a';
					}
				}
				if(min[0] == '0')strcpy(min,save);
				if(strcmp(save,min)<0){
					strcpy(min,save);
				}
			}
		}
	}
	if(min[0] == '0'){
			printf("UNRESTORABLE");
			return 0;
	}
	printf("%s",min);
	return 0;
}

Measured memory_bytes: 128
//S.G.N.//
#include <bits/stdc++.h>
using namespace std;
typedef vector< long long > vi;
typedef long long ll;
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define endl "\n"
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define fr(n) for(ll i=0;i<n;i++)
#define tr(a) for(auto it=a.begin();it!=a.end();it++)
#define N 998244353445 
#define PI 3.1415926535897932384
#define F first
#define S second
#define mp make_pair
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mod 1000000007
vector<ll> v[100001];
ll vis[100001]={0};
ll dp[100001];
ll dfs(ll i)
{
  vis[i]=1;
  ll temp=0;
  tr(v[i])
  {
    if(vis[*it]==0)
    {
      temp=max(temp,dfs(*it));
    }
    else
      temp=max(temp,dp[*it]);
  }
  dp[i]=temp+1;
  //cout<<i<<" "<<temp+1<<endl;
  return temp+1;
}
void solve()
{
 ll n,m;
 cin>>n>>m;
 fr(m)
 {
  ll a,b;
  cin>>a>>b;
  v[a].pb(b);
 }
 ll mx=0;
 fr(n)
 {
  if(vis[i+1]==0)
    mx=max(mx,dfs(i+1));
 }
 cout<<mx-1;
}
int main()
{
  
  #ifndef ONLINE_JUDGE
     * freopen("input.txt", "r", stdin);
      freopen("output.txt", "w", stdout);
  #endif
  FAST
  ll test;
test=1;
  //cin>>test;
  while(test--)
  {
    solve();
  }
  return 0;
}

Measured memory_bytes: 13260
#include <stdio.h>
#include <stdlib.h>

void Function(int *,char *,int *);

void Function(int *Aarray,char *OParray,int *Barray)
{
    int j;
    for(j=0;j<100;j++)
    {
        switch (OParray[j]) {
            case '+':
                printf("%d\n",Aarray[j]+Barray[j]);
                break;
            case '-':
                printf("%d\n",Aarray[j]-Barray[j]);
                break;
            case '*':
                printf("%d\n",Aarray[j]*Barray[j]);
                break;
            case '/':
                printf("%d\n",Aarray[j]/Barray[j]);
                break;
        }

    }
}


int main()
{
    int a[100];
    int b[100];
    char op[100];
    int i;

    for(i=0;i<100;i++)
    {
     scanf("%d %c %d",&a[i],&op[i],&b[i]);
     if( (a[i]<0 || a[i]>20000) || (b[i]<0 || b[i]>20000) ) return 1;
     if(op[i] == '?') break;
    }

    Function(a,op,b);

    return 0;
}

Measured memory_bytes: 600
//shan61916
#include <bits/stdc++.h>
  using namespace std;
typedef   long long ll;
typedef   unsigned long long ull ;
typedef   double dll ;

#define   mp make_pair
#define   pb push_back
#define   ff first 
#define   ss second
#define   IOS ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define   endl "\n" 
#define   pll pair<ll, ll>
#define   all(x) x.begin(), x.end()
#define   vll vector<ll> 

const ll inf = (ll)(1e17 + 17);
const ll mod = (ll)(1e9 + 7);


int main(){
 IOS
#ifdef SHAN
    freopen("input.txt" , "r" , stdin);  
#endif
  ll x;
  cin >> x;
  x >= 30 ? cout << "Yes" : cout << "No";
  return 0;
} //good night.

Measured memory_bytes: 3656
#include "bits/stdc++.h"

#define SORT(vec) sort(vec.begin(), vec.end());


using namespace std;
int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
//  --------------------------------------

	int a; cin >> a;
	string s; cin >> s;

	if(a >= 3200){
		cout << s << "\n";
	}else{
		cout << "red" << "\n";
	}

}

Measured memory_bytes: 256
from itertools import *
n,*s=open(0).read().split()
st=[[min(accumulate(s_,lambda a,b: a+(1 if b=="(" else -1),initial=0)),2*s_.count("(")-len(s_)] for s_ in s]
now=0
for c,d in chain(sorted([x for x in st if x[1]>=0])[::-1],sorted([x for x in st if x[1]<0],key=lambda z:z[1]-z[0])[::-1]):
    if now+c<0:
        print("No");break
    now+=d
else:
    print("No" if now else "Yes")

Measured memory_bytes: 119316
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
INF = float("inf")

EPS = 1e-8


def main():
    N = int(input())
    A = list(map(int, input().split()))

    T = 0
    for a in A:
        T ^= a
    print(" ".join([str(T ^ a) for a in A]))

    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 104444
#include <iostream>
#include <iomanip>
#include <string>
typedef long long ll;
using namespace std;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
#define repi(i, n, init) for (ll i = init; i < (n); i++)

int main()
{
    string s, t;
    cin >> s >> t;
    int n = s.size();
    int m = t.size();
    if (n < m)
    {
        cout << "UNRESTORABLE" << endl;
    }
    else
    {
        bool ok = false;
        repi(i, n - m + 1, 0)
        {
            if (s[i] == t[0])
            {
                int cnt = 1;
                repi(j, m, 1)
                {
                    if (s[i + j] == t[j])
                        cnt++;
                }
                if (cnt == m)
                    ok = true;
            }
        }
        if (!ok)
        {
            for (int i = n - m; i >= 0; i--)
            {
                if (s[i] == t[0] || s[i] == '?')
                {
                    int cnt = 1;
                    repi(j, m, 1)
                    {
                        if (s[i + j] == t[j] || s[i + j] == '?')
                            cnt++;
                    }
                    if (cnt == m)
                    {
                        ok = true;
                        repi(j, m, 0)
                        {
                            s[i + j] = t[j];
                        }
                    }
                }
                if (ok)
                    break;
            }
            if (!ok)
            {
                cout << "UNRESTORABLE" << endl;
                return 0;
            }
        }
        repi(i, n, 0)
        {
            if (s[i] == '?')
                s[i] = 'a';
        }
        cout << s << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<stack>
#include<queue>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<vector>
#include<math.h>
#include<tuple>
#include<string.h>
#include <numeric> 
#include<unordered_map>
using namespace std; 
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define pp(...) "\033[94m [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "]\033[0m"
#define pp1(...) "\033[1;47;35m" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "]\033[0m"
#define dg(x) debug() << pp1(x)
#define dg1(x) debug() << "[line : " << __LINE__ <<"]"<< pp(x)
#define dg2(x,y) debug() << "[line : " << __LINE__ <<"]"<< pp(x) pp(y)
#define dg3(x,y,z) debug() << "[line : " << __LINE__ <<"]"<< pp(x) pp(y) pp(z)
#define dg4(w,x,y,z) debug() << "[line : " << __LINE__ <<"]"<< pp(w) pp(x) pp(y) pp(z)
#define int long long
#define all(x) x.begin() , x.end()
#define clr(x , y) memset(x , y , sizeof x);
#define sz(x) (int)x.size()
template<typename T> void db(T x ){ debug() <<">>> " <<  x; }
template<typename T> void db(T x , T y){ debug() <<">>> " <<  x <<" , "<< y; }
template<typename T> void db(T x , T y , T z){ debug() <<">>> "<< x <<" , "<< y <<" , "<< z; }
template<typename T> void db(T x , T y , T z , T a){ debug() <<">>> "<< x <<" , " << y <<" , "<< z <<" , "<< a; }
const int xx = 2e5;
const int Mod = 1e9 + 7;
const int inf = 1e18;
const int Maxn = 20010;

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int ans = 0;
  for(int i = 0; i + 1 < n; i ++) {
    for(int j = i + 1; j < n; j++) {
      ans += (a[i] * a[j]);
    }
  }
  cout << ans << '\n';

}

Measured memory_bytes: 3664
//#include "debug.h"
#include <string.h>
#include <limits.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
using namespace std;

#define MAXN 200000

int n;
long a[MAXN];

int input() {
	if (scanf("%d", &n) < 0) return 0;
	for (int i=0; i<n; i++) scanf("%ld", &a[i]);
	return 1;
}

void init() {
}

long solve() {
	for (int i=0; i<n; i++) a[i] -= i+1;
	sort(a, a+n);
	long r = 0;
	long x = a[n/2];
	for (int i=0; i<n; i++) r += abs(a[i]-x);
	return r;
}

void output(long ans) {
	printf("%ld\n", ans);
}

void cleanup() {
}

int main() {
	while (input()) {
		init();
		output(solve());
		cleanup();
		//break;
	}
}





Measured memory_bytes: 1664
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
using namespace std;
#define DEBUG(x) cout<<#x<<"="<<x<<endl
#define DEBUG2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl
typedef long long ll;
class RollingHash{
    public:
    int n;
    const int b1=31,b2=37;
    const ll m1=1e9+7,m2=1e9+9;
    vector<ll>hash1,hash2,power1,power2;
    RollingHash(){}
    RollingHash(string &s){
        n=s.size();
        hash1.assign(n+1,0);
        hash2.assign(n+1,0);
        power1.assign(n+1,1);
        power2.assign(n+1,1);
        for(int u=0;u<n;u++){
            hash1[u+1]=(hash1[u]*b1+s[u]-'a')%m1;
            hash2[u+1]=(hash2[u]*b2+s[u]-'a')%m2;
            power1[u+1]=(power1[u]*b1)%m1;
            power2[u+1]=(power2[u]*b2)%m2;
        }
    }
    pair<ll,ll> getHash(int i,int j){
        ll h1=(hash1[j]-hash1[i]*power1[j-i]%m1+m1)%m1;
        ll h2=(hash2[j]-hash2[i]*power2[j-i]%m2+m2)%m2;
        return {h1,h2};
    }
    int getLcp(int u,int v){
        int l=0,r=min(n+1-u,n+1-v),lstp=-1;
        while(l<=r){
            int mid=(l+r)>>1;
            if(getHash(u,u+mid)==getHash(v,v+mid))lstp=mid,l=mid+1;
            else r=mid-1;
        }
        return lstp;
    }
};

class Solver{
    public:
    int n;
    RollingHash *rh;
    Solver(){}
    bool check(int d){
        map<pair<ll,ll>,int>ma;
        for(int u=0;u+d<=n;u++){
            auto h=rh->getHash(u,u+d);
            if(ma.count(h)){
                if(u-ma[h]>=d)return true;
            }
            else ma[h]=u;
        }
        return false;
    }
    void solve(){
        ios::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        string s;
        cin>>n;
        cin>>s;
        rh=new RollingHash(s);
        int l=0,r=n/2+1,lstp=-1;
        while(l<=r){
            int mid=(l+r)>>1;
            if(check(mid)){
                l=mid+1;
                lstp=mid;
            }
            else r=mid-1;
        }
        lstp=max(0,lstp);
        cout<<lstp;
    }
};
int main()
{
    // freopen("in.txt","r",stdin);
    Solver().solve();
}

Measured memory_bytes: 768
/*  -*- coding: utf-8 -*-
 *
 * 1622.cc: Go around the Labyrinth
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_H = 50;
const int MAX_W = 50;
const int MAX_N = MAX_H * MAX_W * 2;
const int INF = 1 << 30;

const int dxs[] = { 1, 0, -1, 0 }, dys[] = { 0, -1, 0, 1 };

/* typedef */

typedef pair<int,int> pii;
typedef vector<pii> vpii;

/* global variables */

vpii nbrs[MAX_N];
int minfs[MAX_N], flows[MAX_N][MAX_N], prvs[MAX_N];
char flds[MAX_H][MAX_W + 4];

/* subroutines */

inline int xy2p(int x, int y, int w) { return y * w + x; }

int maxflow(int st, int gl) {
  memset(flows, 0, sizeof(flows));
  int max_flow = 0;

  for (;;) {
    //printf("max_flow = %d, limit = %d\n", max_flow, limit);

    memset(prvs, -1, sizeof(prvs));
    prvs[st] = st;
    minfs[st] = INF;

    queue<int> q;
    q.push(st);

    while (! q.empty()) {
      int ui = q.front(); q.pop();

      if (ui == gl) break;
      vpii& nbru = nbrs[ui];
      for (vpii::iterator vit = nbru.begin(); vit != nbru.end(); vit++) {
        int vi = vit->first;
        int vc = vit->second - flows[ui][vi];
        if (prvs[vi] < 0 && vc > 0) {
          prvs[vi] = ui;
          minfs[vi] = (minfs[ui] < vc) ? minfs[ui] : vc;
          q.push(vi);
        }
      }
    }
    if (prvs[gl] < 0) break;

    int min_flow = minfs[gl];
    for (int j = gl; j != st;) {
      int i = prvs[j];
      flows[i][j] += min_flow;
      flows[j][i] -= min_flow;
      j = i;
    }

    max_flow += min_flow;
  }

  return max_flow;
}

/* main */

int main() {
  for (int h, w; scanf("%d%d", &h, &w) == 2 && h > 0;) {
    for (int y = 0; y < h; y++) scanf("%s", flds[y]);

    int n = h * w, n2 = n * 2;
    int st = xy2p(0, 0, w) + n;
    int gl0 = xy2p(w - 1, 0, w);
    int gl1 = xy2p(0, h - 1, w);
    int gl2 = xy2p(w - 1, h - 1, w);

    for (int i = 0; i < n2; i++) nbrs[i].clear();
    
    for (int y = 0; y < h; y++)
      for (int x = 0; x < w; x++)
	if (flds[y][x] == '.') {
	  int u0 = xy2p(x, y, w), u1 = u0 + n;
	  nbrs[u0].push_back(pii(u1, 1));
	  nbrs[u1].push_back(pii(u0, 0));

	  for (int di = 0; di < 4; di++) {
	    int vx = x + dxs[di], vy = y + dys[di];
	    if (vx >= 0 && vx < w && vy >= 0 && vy < h &&
		flds[vy][vx] == '.') {
	      int v0 = xy2p(vx, vy, w), v1 = v0 + n;
	      nbrs[v1].push_back(pii(u0, 1));
	      nbrs[u0].push_back(pii(v1, 0));
	      nbrs[u1].push_back(pii(v0, 1));
	      nbrs[v0].push_back(pii(u1, 0));
	    }
	  }
	}

    bool ok =
      (maxflow(st, gl0) >= 2 &&
       maxflow(st, gl1) >= 2 &&
       maxflow(st, gl2) >= 2);

    if (ok) puts("YES");
    else puts("NO");
  }
  
  return 0;
}



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

int main() {
  int a, b;
  cin >> a >> b;
  string A, B;
  for (int i = 0; i < b; i++) A += char('0' + a);
  for (int i = 0; i < a; i++) B += char('0' + b);
  cout << ((A < B) ? A : B) << "\n";
}

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

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

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

int CountOfDigits(int n, int k) {
  int sum = 0;
  while (n > 0) {
    sum ++;
    n /= k;
  }
  return sum;
}

int main() {
	int N, K;
  	cin >> N >> K;
  
  int ans = CountOfDigits(N, K);
  cout << ans << endl;
  
}

Measured memory_bytes: 256
def d_pairs():
    # 参考: https://maspypy.com/atcoder-参加感想-2019-02-16abc-155
    import numpy as np
    N, K = [int(i) for i in input().split()]
    A = np.array([int(i) for i in input().split()], np.int64)

    A = np.sort(A)
    zero = A[A == 0]
    positive = A[A > 0]
    negative = A[A < 0]

    def f(c):
        """数列 A から 2 要素を選んで積を取ったとき、c 以下となるようなペアの選び方"""
        count_pair = 0

        # a (数列の要素) == 0 かつ c >= 0 なら、a * x <= c となる x は数列の任意の要素
        if c >= 0:
            count_pair += len(zero) * N
        # a > 0 の場合
        count_pair += np.searchsorted(A, c // positive, side='right').sum()
        # a < 0 の場合 (全体から引くようにすると、見通しがよい)
        count_pair += (N - np.searchsorted(A, (-c - 1) // (-negative), side='right')).sum()
        # 添字の順序に制約があることを反映する
        count_pair -= np.count_nonzero(A * A <= c)  # 「添字が同じ要素を 2 度選んだ場合」を引く
        return count_pair // 2

    # 数列から要素を 2 個選んで積を取ったとき、制約からあり得る値の範囲
    lower, upper = -10 ** 18, 10 ** 18
    while upper - lower > 1:
        x = (lower + upper) // 2
        if f(x) >= K:
            upper = x
        else:
            lower = x
    return upper

print(d_pairs())

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

int main() {
    int n;
    cin >> n;
    switch (n) {
        case 22:
        cout << "Christmas Eve Eve Eve" << endl;
        break;
        case 23:
        cout << "Christmas Eve Eve" << endl;
        break;
        case 24:
        cout << "Christmas Eve" << endl;
        break;
        case 25:
        cout << "Christmas" << endl;
        break;
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cout << #x << " = " << (x) << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//#define int long long

void solve() {
	string s; cin >> s;
    if(s == "SUN") {
        cout << 7 << endl;
    } else if(s == "MON") {
        cout << 6 << endl;
    } else if(s == "TUE") {
        cout << 5 << endl;
    } else if(s == "WED") {
        cout << 4 << endl;
    } else if(s == "THU") {
        cout << 3 << endl;
    } else if(s == "FRI") {
        cout << 2 << endl;
    } else if(s == "SAT") {
        cout << 1 << endl;
    }
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//init();
	solve();
	//cout << "finish" << endl;
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize(3)
#pragma comment(linker,"/stack:96777216")
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<list>
#include<stack>
#include<queue>
#include<deque>
#include<functional>
#include<utility>
#include<algorithm>
#include<sstream>
#include<cstring>
#include<cmath>
#include<cctype>
#include<exception>
#include<climits>
#include<cfloat>
#include<iomanip>
#include<bitset>
#include<streambuf>
#include<cstdlib>
#include<ctime>
//#include"functions.h"
//#include"highprecision.h"
#define pb push_back
#define pf push_front
#define ppb pop_back
#define mp make_pair
#define np next_permutation
#define fi first
#define sc second
#define vi vector<int>
#define vll vector<long long>
#define vvi vector<vector<int> >
#define vpi vector<pair<int,int> >
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pff pair<float,float>
#define pdd pair<double,double>
#define psi pair<string,int>
#define pis pair<int,string>
#define ppi pair<pii,int>
#define pdi pair<pii,pii>
#define LN 84757
#define INF 1e9
#define LLINF 1e18
#define MAXINT 0x7fffffff
#define MAXLL 0x7fffffffffffffff
#define EPS 1e-5
#define DEPS 1e-9
#define LDEPS 1e-13
#define MOD 1000000007
#define E 2.7182818284
#define PI 3.1415926535
#define rep(a,b) for(int a=0;a<b;a++)
#define forn(a,n) for(int a=1;a<=n;a++)
#define forr(a,n) for(int a=n;a>=1;a--)
#define repn(a,n,p) for(int a=0;a<n;a+=p)
#define repr(a,n) for(int a=n-1;a>=0;a--)
#define foreach(a,b) for(__typeof(b.begin())a=b.begin();a!=b.end();a++)
#define fillemp(a) memset(a,0,sizeof(a))
#define fillinf(a) memset(a,0x3f,sizeof(a))
#define frestream freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define stdf(a,b) freopen(a,"r",stdin);freopen(b,"w",stdout);
#define inputf(a) freopen(a,"r",stdin);
#define outputf(a) freopen(a,"w",stdout);
#define sz(a) a.size()
#define all(a) a.begin(),a.end()
#define MOD 1000000007
typedef long long ll;
typedef long double ld;
using namespace std;

struct min_segment_tree{
	int n,seg[1<<19-1];
	void init(int n_){
		n=1;
		while(n<n_)n*=2;
		rep(i,2*n-1)seg[i]=INF;
	}
	void upd(int k,int a){
		k+=n-1;
		seg[k]=a;
		while(k){
			k=(k-1)/2;
			seg[k]=min(seg[k*2+1],seg[k*2+2]);
		}
	}
	int que(int a,int b,int k,int l,int r){
		if(r<=a||b<=l)return INF;
		if(a<=l&&r<=b)return seg[k];
		else{
			int vl=que(a,b,k*2+1,l,(l+r)/2);
			int vr=que(a,b,k*2+2,(l+r)/2,r);
			return min(vl,vr);
		}
	}
};
struct max_segment_tree{
	int n,seg[1<<19-1];
	void init(int n_){
		n=1;
		while(n<n_)n*=2;
		rep(i,2*n-1)seg[i]=-INF;
	}
	void upd(int k,int a){
		k+=n-1;
		seg[k]=a;
		while(k){
			k=(k-1)/2;
			seg[k]=max(seg[k*2+1],seg[k*2+2]);
		}
	}
	int que(int a,int b,int k,int l,int r){
		if(r<=a||b<=l)return -INF;
		if(a<=l&&r<=b)return seg[k];
		else{
			int vl=que(a,b,k*2+1,l,(l+r)/2);
			int vr=que(a,b,k*2+2,(l+r)/2,r);
			return max(vl,vr);
		}
	}
};
int main(){
	ll n;
	cin>>n;
	for(ll i=-300ll;i<=300ll;i++)for(ll j=-300ll;j<=300ll;j++){
		ll x=i*i*i*i*i,y=j*j*j*j*j;
		if(x-y==n){
			cout<<i<<" "<<j<<endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 3632
N,K=map(int,input().split())
A=list(map(int,input().split()))
l=0
r=10**9
while l+1<r:
    m=(r-l)//2+l
    c=0
    for i in A:
        c+=(i-1)//m
    if c<=K:
        r=m
    else:
        l=m
print(l+1)

Measured memory_bytes: 94252
#include <bits/stdc++.h>
#define pb          emplace_back
#define ll          long long
#define fi          first
#define se          second
#define mp          make_pair
#define int         int64_t

using namespace std;

typedef pair<int, int> pii;
const int N = int(5e3 + 2);
const int mod = 998244353;

int cnt[N], p[N], c[N][N], f[N][N], n, k, ans, res;

int nCk(int n, int k) {
    if(c[n][k] != -1) return c[n][k];
    if(n * k == 0 || k == n) return 1;
    if(k > n) return c[n][k] = 0;
    if(n < 0 || k < 0) return 0;
    return c[n][k] = (nCk(n - 1, k - 1) + nCk(n - 1, k)) % mod;
}

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    #define Task        "test"
    if(fopen(Task".inp", "r")) {
        freopen(Task".inp", "r", stdin);
        freopen(Task".out", "w", stdout);
    }
    memset(&c, -1, sizeof c);
    cin >> k >> n; p[0] = 1, p[1] = 2;
    for(int i = 2; i <= 2 * k; ++i) { p[i] = p[i - 1] * 2ll % mod;
        for(int j = 1; j <= k; ++j)
            if(i - j <= k && i - j > 0 && 2 * j != i) ++cnt[i];
        cnt[i] >>= 1;
    }
    for(int i = 0; i <= k; ++i) f[0][i] = 1;
    for(int i = 1; i <= n; ++i) {
        for(int j = 1; j <= k; ++j) {
            f[i][j] = f[i - 1][j] + f[i][j - 1];
            if(f[i][j] >= mod) f[i][j] -= mod;
        }
    }
    for(int i = 2; i <= 2 * k; ++i) {
        int rem = k - 2 * cnt[i];
        if(i % 2 == 0) --rem; res = ans = 0;
        for(int j = 0; j <= cnt[i]; ++j) {
            if(n - j >= 0) {
                res += 1ll * nCk(cnt[i], j) * p[j] % mod * f[n - j][j + rem] % mod;
                if(res >= mod) res -= mod;
            }
            if(n - j > 0) {
                ans += 1ll * nCk(cnt[i], j) * p[j] % mod * f[n - j - 1][j + rem] % mod;
                if(ans >= mod) ans -= mod;
            }
        }
        if(i % 2 == 0) cout << (res + ans) % mod << '\n';
        else cout << res << '\n';
    }
}


Measured memory_bytes: 275584
#include<bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60;

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

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

	vector<int> h(n);
	for(int i=0;i<n;i++)cin >> h[i];
	
	long long dp[1000000];
	for(int i=0;i<n;i++){
		dp[i]=INF;
	}
	dp[0]=0;

	for(int i=1;i<n;i++){
		for(int j=1;j<=i;j++){
			if(k-j>=0)chmin(dp[i],dp[i-j]+abs(h[i]-h[i-j]));
			else break;
		}
	}
	cout << dp[n-1] << endl;
	
	return 0;
}


Measured memory_bytes: 3200
N, M = map(int, input().split())
count = [0] * (N+1)
for _ in range(M):
    a, b = map(int, input().split())
    count[a] += 1
    count[b] += 1
ans = 'YES'
for i in range(1, N+1):
    if count[i] % 2 == 1:
        ans = 'NO'
        break
print(ans)


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

int main(){
	// sengen
	int d,n;
	// nyuryoku
	cin >> n >> d;
	// keisan
	int ans = 0,a = 0;
	while(a < n){
		a += 2*d + 1;
		ans++;
	}
	// syutsuryoku
	cout << ans;
}

Measured memory_bytes: 3468
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define All(a) (a).begin(),(a).end()
#define N 100001
int *par;
int *rrank;

int root(int x){
  if(par[x]==x)return x;
  else return par[x]=root(par[x]);
}

void init(int n){
  for(int i=0; i <= n; i++){
    par[i]=i;
    rrank[i]=0;
  }
}
bool same(int x,int y){
  return root(x)==root(y);
}

void link(int x,int y){
  int xx,yy;
  xx=root(x);
  yy=root(y);
  if(xx==yy)return;

  if(rrank[xx]<rrank[yy]) par[xx]=yy;
  else if(rrank[xx]>rrank[yy]){
    par[yy]=xx;
  }else{
    par[yy]=xx;
    rrank[xx]++;
  }
  return;
}

int main(){ 
  int n,m,a,b;
  cin>>n>>m;
  int ans=n-1;
  par=new int[n+1];
  rrank=new int[n+1];

  init(n);

  for (int i = 0; i < m; i++){
    cin >> a>>b;
    if(!same(a,b)){
      link(a,b);
      ans--;
    }
  }
  cout << ans <<endl;
  return 0;
}

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())

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

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007;

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

int main(void){
    ll N; cin >> N;
    vector<ll> A(N); REP(i,N) cin >> A[i];
    vector<ll> S(N+1); S[0] = 0;
    REP(i,N) S[i+1] = S[i] + A[i];
    SORT(S);
    vector<pair<ll,ll>> p;
    p.emplace_back(S[0], 1);
    REP(i,N){
        if(p.back().first == S[i+1]) p.back().second++;
        else p.emplace_back(S[i+1],1);
    }
    ll ans = 0;
    REP(i,p.size()){
        ans += p[i].second*(p[i].second-1)/2;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 8176
<?php
$N = (int)trim(fgets(STDIN));
//$S = trim(fgets(STDIN));
//list($a,$b,$c,$d) = array_map('intval',explode(" ",trim(fgets(STDIN))));
//$A = array_map('intval',explode(" ",trim(fgets(STDIN))));

for($i=0;$i<$N;$i++) {
  echo "ACL";
}
printf("\n");


Measured memory_bytes: 16260
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)
int main(){
    ll n;
    cin >> n;
    vector<ll> x(n);
    vector<ll> y(n);
    vector<ll> h(n);
    tuple<ll, ll, ll> h_exp_set;
    rep(i, n) {
        cin >> x[i] >> y[i] >> h[i];
        if ( h[i] >= 1 ) {
            h_exp_set = make_tuple(x[i], y[i], h[i]);
        }
    }
    rep(i, 101) rep(j, 101) {
        ll h_exp = max(0LL, get<2>(h_exp_set) + abs(get<0>(h_exp_set) - i) + abs(get<1>(h_exp_set) - j));
        bool ok = true;
        rep(k, n) {
            ll tmp_h = max(0LL, h_exp - abs(x[k] - i) - abs(y[k] - j));
            if ( h[k] !=  tmp_h ) {
                ok = false;
            }
        }
        if ( ok ) {
          cout << i << " " << j << " " << h_exp << endl;
        }
    }
    return 0;
}

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

int main(){
	int W,H,N;
    cin >> W >> H >> N;
    int b = 0;
    int c = 0;
    int d = 0;
    int e = 0;
    for(int i = 0; i < N; i++) {
        int x,y,a;
        cin >> x >> y >> a;
        if(a == 1) {
            b = max(b,x);
        }
        if(a == 2) {
            c = max(c,W-x);
        } 
        if(a == 3) {
            d = max(d,y);
        }
        if(a == 4) {
            e = max(e,H-y);
        }
    }
    cout << max(W-b-c,0)*max(H-d-e,0) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stdio.h>
#include<cstring>
#include<math.h>
#include<map>
#include<bitset>
#include<iomanip>
#include<queue>
#include<functional>
#include<stack>
#include<tuple>
#include<cassert>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
using P = pair<int, int>;

int N;
int visited[100000] = {0};
vector<int> a[100000];
P b[100000];
map<P, int> mp;

int main() {
  cin >> N;
  rep(i, N-1) {
    int x, y;
    cin >> x >> y;
    x--;y--;
    a[x].push_back(y);
    a[y].push_back(x);
    b[i] = {x, y};
  }
  queue<int> que;
  que.push(0);

  while(que.size()) {
    int p = que.front();
    que.pop();
    int bef = visited[p];
    int color = 1;
    rep(i, a[p].size()) {
      int np = a[p][i];
      if(np == 0 || visited[np] != 0) continue;
      que.push(np);
      if(color == bef){
        color++;
      }
      // cout << p << " " << np << " " << color << endl;
      visited[np] = color;
      mp[{p, np}] = color;
      mp[{np, p}] = color;
      color++;
    }
  }

  // cout << endl;
  int ans = 0;
  rep(i, N) {
    ans = max(ans, visited[i]);
  }
  cout << ans << endl;
  rep(i, N-1) {
    int x, y;
    x = b[i].first;
    y = b[i].second;
    cout << mp[{x, y}] << endl;
  }
  return 0;
}

Measured memory_bytes: 22740
n,k = map(int, input().split())
h = list(map(int, input().split()))

dp = [0] * n
dp[0] = 0

for i, j in enumerate(h):
    s = 0 if i < k else i - k
    if i == 0:
        continue
    dp[i] = min([abs(j - h_k) + dp_k for h_k, dp_k in zip(h[s:i], dp[s:i])])
print(dp[-1])

Measured memory_bytes: 13980
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(__typeof((X).begin()) it=(X).begin();it!=(X).end();it++)
#define ite iterator
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define pb push_back
#define sec second
#define sz(x) ((int)x.size())

using namespace std;

typedef istringstream iss;
typedef long long ll;
typedef pair<int,int> pi;
typedef stringstream sst;
typedef vector<int> vi;

int N,M;
double P;
int u[111],v[111];
double dp[1<<14];

struct timer{
	time_t start;
	timer(){
		start=clock();
	}
	~timer(){
		cout<<1.*(clock()-start)/CLOCKS_PER_SEC<<" secs"<<endl;
	}
};

int main(){
	//timer TIMER;
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	
	cin>>N>>M>>P;
	P/=100;
	rep(i,M)cin>>u[i]>>v[i],u[i]--,v[i]--;
	
	rep2(mask,1,1<<N){
		
		if(__builtin_popcount(mask)==1){
			dp[mask]=1;
			continue;
		}
		
		dp[mask]=1;
		int par=N-1;
		while(!(mask>>par&1))par--;
		int sub=mask,e;
		
		while(1){
			sub=(sub-1)&mask;
			e=0;
			rep(i,M){
				if((mask>>v[i]&1) && (mask>>u[i]&1) && (sub>>u[i]&1)^(sub>>v[i]&1))e++;
			}
			//cout<<mask<<" - "<<dp[sub]<<" * "<<pow(P,e)<<endl;
			dp[mask]-=dp[sub]*pow(P,e);
			if(sub==(1<<par))break;
		}
		
		//cout<<mask<<" "<<dp[mask]<<endl;
	}
	//cout<<setprecision(16)<<dp[(1<<N)-1]<<endl;
	printf("%.16f\n",dp[(1<<N)-1]);
}

Measured memory_bytes: 1396
import sys
input = sys.stdin.readline
from collections import defaultdict

def bs(tl, i, l, r):
  while l < r:
    mid = (l + r) // 2
    if tl[mid] <= i:
      l = mid + 1
    else:
      r = mid
  return r


def main():
  s = input().strip()
  t = input().strip()
  sd = defaultdict(lambda: [])
  for i, _s in enumerate(s):
    sd[_s].append(i)

  for k, v in sd.items():
    sd[k] = list(sorted(v))

  ans = 0
  prev = -1
  for _t in t:
    if _t not in sd:
      break
    else:
      idx = bs(sd[_t], prev, 0, len(sd[_t]))
      if idx == len(sd[_t]):
        idx = sd[_t][0]
      else:
        idx = sd[_t][idx]
      if idx <= prev:
        ans += len(s) - prev + idx
      else:
        ans += idx - prev
      prev = idx
  else:
    print(ans)
    sys.exit(0)

  print(-1)


if __name__ == '__main__':
  main()


Measured memory_bytes: 47344