akhauriyash/Code-Regression huggingface dataset:
// Author: HarshKumar

#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
const ll N = 1e6 + 6, M = 1e9 + 7;
ll in(ll a, ll b = M - 2, ll m = M)
{
    ll r = 1;
    while (b)
    {
        if (b % 2)
            r = r * a % m;
        a = a * a % m;
        b /= 2;
    }
    return r;
}
int main()
{
    ios::sync_with_stdio(false), cin.tie(nullptr);
    ll n, s = 0, ss = 0;
    cin >> n;
    vector<ll> a(n);
    for (ll &e : a)
        cin >> e, s = (s + e) % M, ss = (ss + e * e % M) % M;
    cout << ((s * s % M - ss + M) % M * in(2) % M) % M;
}

Measured memory_bytes: 4708
#include <iostream>
#include <string>

using namespace std;

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

    int price = 700;
    for (int i = 0; i < s.length(); ++i) {
        if (s[i] == 'o')
            price += 100;
    }

    cout << price << '\n';
}


Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
#define REP(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define rep(i,n) REP((i),0,(n))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using tp3 = tuple<int, int, int>;
using Mat = vector<vector<ll>>;
constexpr int INF = 1 << 28;
constexpr ll INFL = 1ll << 60;
constexpr int dh[4] = { 0,1,0,-1 };
constexpr int dw[4] = { -1,0,1,0 };
bool isin(const int H, const int W, const int h, const int w) {
    return 0 <= h && h < H && 0 <= w && w < W;
}
template<typename T>
T minch(T& l, T r) {
    return l = min(l, r);
}
template<typename T>
T maxch(T& l, T r) {
    return l = max(l, r);
}
template<typename T>
void output(const T& val) {
    cout << val << endl;
}
template<typename T>
void output(const vector<T>& vec, const bool newline = false) {
    for (const T& val : vec)cout << val << (newline ? '\n' : ' '); cout << endl;
}
template<typename T>
void output(const vector<vector<T>>& mat) {
    for (const auto& row : mat)output(row);
}
// ============ template finished ============

vector<int> dijkstra(const vector<vector<int>>& edges, const int start) {
    const int N = edges.size();
    vector<int> d(N, INF);
    priority_queue<pii, vector<pii>, greater<pii>> pq;
    d[start] = 0;
    pq.push({ 0, start });
    while (!pq.empty()) {
        int now, score;
        tie(score, now) = pq.top(); pq.pop();
        for (int next : edges[now]) {
            if (score + 1 < d[next]) {
                d[next] = score + 1;
                pq.push({ d[next],next });
            }
        }
    }
    return d;
}

int main()
{
    int N, X, Y;
    cin >> N >> X >> Y;
    X--, Y--;
    vector<vector<int>> edges(N);
    rep(i, N - 1) {
        edges[i].push_back(i + 1);
        edges[i + 1].push_back(i);
    }
    edges[X].push_back(Y);
    edges[Y].push_back(X);

    map<int, int> mp;
    rep(i, N) {
        auto ds = dijkstra(edges, i);
        for (auto d : ds)mp[d]++;
    }
    REP(i, 1, N)output(mp[i]/2);
    return 0;
}


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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);  
	
	int n; cin >> n;
	string preb; cin >> preb;
	set<string> already; already.insert(preb);
	for(int i = 0; i < n - 1; i++){
		string tmp; cin >> tmp;
		if(already.find(tmp) != already.end() || tmp.front() != preb.back()) {
			cout << "No" << endl; return 0;
		}
		preb = tmp; already.insert(tmp);
	}
	cout << "Yes" << endl;
	return 0;	
}


Measured memory_bytes: 256
s = input()
n = len(s)
t = input()
m = len(t)

dp = [[0 for _ in range(m+1)] for _ in range(n+1)]

for i in range(n):
    for j in range(m):
        if t[j]!=s[i]:
            dp[i+1][j+1]=max(dp[i+1][j],dp[i][j+1])
        else :
            dp[i+1][j+1]=dp[i][j]+1

ans = ''

i = len(s)
j = len(t)
while (i>0  and j>0):
    if dp[i][j] == dp[i-1][j]:
        i -= 1
    elif dp[i][j] == dp[i][j-1]:
        j -= 1
    else:
        ans += s[i-1]
        i -= 1
        j -= 1

print(ans[::-1])

Measured memory_bytes: 119772
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;
int main(void){
int N,K;
cin>>N>>K;
int ans=K;
for(int i=0;i<N-1;i++){
    ans*=K-1;
}
cout<<ans;
return 0;
}



Measured memory_bytes: 256
//Code by 27.
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<math.h>
#include<vector>
#include<queue>
#include<map>
#include<stack>
#include<fstream>
#include<stdlib.h>
#include<set>
#include<climits>
#include<cmath> 
#include<memory.h> 
#include<sstream>
#include<time.h>
using namespace std;
const unsigned long long BIGEST=1000000000000000000+1000000000000000000;
const long long BIGER=1000000000000000000;
const int BIG=1000000000;
const long long MOD=19260817;
int c[505],f[505],s[505];
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<n;i++)
	{
		scanf("%d%d%d",&c[i],&f[i],&s[i]);
	}
	int sum;
	for(int i=1;i<n;i++)
	{
		sum=0;
		for(int j=i;j<n;j++)
		{
			if(sum<f[j])sum=f[j];
			if(sum%s[j]!=0)sum+=(s[j]-sum%s[j]);
			sum+=c[j];
		}
		cout<<sum<<endl;
	}
	cout<<0;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long n,k,v[105],w[105],f[105][100005];
int main()
{
    cin>>n>>k;
    for(int i=1; i<=n; i++)
    {
        cin>>w[i]>>v[i];
    }
    for(int i=1; i<=n; i++)
        for(int j=1; j<=k; j++)
        {
            if(w[i]<=j)

                f[i][j]=max(f[i-1][j],f[i-1][j-w[i]]+v[i]);
            else
                f[i][j]=f[i-1][j];
        }
    cout<<f[n][k];
// for(int i=1; i<=n; i++){
//        for(int j=1; j<=k; j++)
//            cout<<f[i][j]<<" ";
//        cout<<endl;
// }
}

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

step=[]

for i in range(n-1):
  if h[i]<h[i+1]:
    step.append(0)
  else:
    step.append(1)

a=[i for i, x in enumerate(step) if x==0]

ans=[]

for i in range(len(a)):
  if i==0:
    d=a[0]
    ans.append(d)
  else:
    b=a[i]-a[i-1]
    ans.append(b)
    

if not a:
  print(n-1)
else:
  ans.append((n-1)-a[-1])
  print(max(ans)-1)

Measured memory_bytes: 20576
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)

typedef struct edge{ll x,y;}E;

int sort(const void*a,const void*b){
	ll ax=(*(E*)a).x,bx=(*(E*)b).x;
	ll ay=(*(E*)a).y,by=(*(E*)b).y;
	if(ax+ay>bx+by)return -1;
	if(ax+ay<bx+by)return 1;
}

ll a[100010],b[100010];
E p[100010];
int main(){
	ll n;
	scanf("%lld",&n);
	rep(i,0,n){
		scanf("%lld%lld",a+i,b+i);
		p[i].x=a[i];
		p[i].y=b[i];
	}
	qsort(p,n,sizeof(E),sort);

	ll ans=0;
	rep(i,0,n){
		if(i%2==0)ans+=p[i].x;
		else ans-=p[i].y;
	}
	printf("%lld\n",ans);
}

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

int main() {
  int n;
  cin >> n;
  if (n%10 == 2 || n%10 == 4 || n%10==5 || n%10==7 || n%10==9){
    cout << "hon" << endl;
  }
  else if (n%10 == 0 || n%10 == 1 || n%10==6 || n%10==8){
    cout << "pon" << endl;
  }
  else{
    cout << "bon" << endl;
  }
}


Measured memory_bytes: 3644
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int top, S[1000];

void push(int x) {
  S[++top] = x;
}

int pop() {
  top--;
  return S[top+1];
}

int main() {
  int a,b;
  top = 0;
  char s[100];
  while( scanf("%s", s) != EOF) {
    if ( s[0] == '+') {
      a = pop();
      b = pop();
      push( a + b);
    } else if ( s[0] == '-') {
      b = pop();
      a = pop();
      push( a - b);
    } else if (s[0] == '*') {
      a = pop();
      b = pop();
      push (a * b);
    } else {
      push(atoi(s));
    }
  }

  printf("%d\n", pop());

  return 0;
}



Measured memory_bytes: 2720
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        sc.close();
        int n = s.length();
        System.out.println("" + s.charAt(0) + (n - 2) + s.charAt(n - 1));
    }
}

Measured memory_bytes: 38832
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m,s,g1,g2;
  while(cin>>n>>m>>s>>g1>>g2,n){
    int d[1001][1001]={};
    for(int i=1;i<=n;i++)
      for(int j=1;j<=n;j++)if(i!=j)d[i][j]=1e8;
    for(int i=0,a,b,c;i<m;i++)
      cin>>a>>b>>c,d[a][b]=c;
    for(int i=1;i<=n;i++)
      for(int j=1;j<=n;j++)
	for(int k=1;k<=n;k++)d[j][k]=min(d[j][k],d[j][i]+d[i][k]);
    int ans=1e9;
    for(int i=1;i<=n;i++)ans=min(ans,d[s][i]+d[i][g1]+d[i][g2]);
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 6896
#include <bits/stdc++.h>
using namespace std;
#define all(x) begin(x), end(x)

string inp;
string::iterator it;

struct Rec;

struct Yaml {
  int ind;
  vector<Rec> rec;
};

struct Rec {
  string key;
  string val;
  Yaml ch;
};

char nxt(char c) { return *it == c ? *it++ : 0; }
char nxt(bool (*p)(char)) { return p(*it) ? *it++ : 0; }
template <class P>
string proc(P p) {
  string res;
  for (char c; (c = nxt(p));) res.push_back(c);
  return res;
}
bool key_c(char c) { return islower(c) or isdigit(c); }
bool val_c(char c) { return islower(c) or isdigit(c) or c == ' '; }
string key() { return proc(key_c); }
string val() { return proc(val_c); }
void indent() { while (nxt(' ')); }
int indent_forward() {
  auto it0 = it;
  int cnt = 0;
  while (nxt(' ')) cnt++;
  it = it0;
  return cnt;
}

Yaml yaml(int);

Rec rec() {
  Rec ret;
  indent();
  ret.key = key();
  assert(nxt(':'));
  if (nxt('\n'))
    ret.ch = yaml(indent_forward());
  else
    nxt(' '), ret.val = val(), nxt('\n');
  return ret;
}

Yaml yaml(int n) {
  Yaml ret;
  ret.ind = n;
  while (*it != '$' and indent_forward() == n) ret.rec.push_back(rec());
  return ret;
}

vector<string> member() {
  vector<string> ret;
  while (nxt('.')) ret.push_back(key());
  return ret;
}

int main() {
  string query;
  getline(cin, query); query.push_back('$');
  string s;
  while (getline(cin, s)) inp.insert(inp.end(), all(s)), inp.push_back('\n');
  inp += "$\n";
  it = inp.begin();

  Yaml result = yaml(0);
  Yaml *y = &result;
  string val;
  swap(inp, query); it = inp.begin();
  for (auto k : member()) {
    auto iter = find_if(all(y->rec), [&](const Rec& rec) { return rec.key == k; });
    if (iter == y->rec.end()) {
      cout << "no such property\n";
      return 0;
    }
    val = move(iter->val);
    y = &iter->ch;
  }
  if (val.empty()) {
    cout << "object\n";
  } else {
    cout << "string \"" << val << "\"\n";
  }
}


Measured memory_bytes: 3364
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int INF = 1 << 30;

ll mod_pow(ll a, ll n) {
	if (n == 0) return 1;
	if (n % 2 == 0) {
		ll tmp = mod_pow(a, n / 2);
		return (tmp * tmp) % MOD;
	}
	return (a * mod_pow(a, n - 1)) % MOD;
}
ll cnt[10001];
int main() {
	int N, K;
	cin >> N >> K;
	vector<ll> div;
	for (ll i = 1; i*i <= N; i++) {
		if (N%i == 0) {
			div.push_back(i);
			if (i != N / i) div.push_back(N / i);
		}
	}
	sort(div.begin(), div.end());
	ll ans = 0;
	for (int i = 0; i < div.size(); i++) {
		cnt[i] = mod_pow(K, (div[i] + 1) / 2);
		for (int j = 0; j < i; j++) {
			if (div[i] % div[j] == 0) (cnt[i] += MOD - cnt[j]) %= MOD;
		}
		ll add = (cnt[i] * div[i]) % MOD;
		if (div[i] % 2 == 0) (add *= mod_pow(2, MOD - 2)) %= MOD;
		(ans += add) %= MOD;
	}
	cout << ans << endl;
}


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

int main() {
  int N;
  cin >> N;
  vector<char> S(N);
  int x=0, y;
  
  for(int i=0; i<N; i++) {
    cin >> S[i];
    if(S[i] == y && i != 0)
      x++;
    y = S[i];
  }
  
  for(int l=0; l<x; l++) {
    S.pop_back();
  }
  
  cout << S.size() << endl;    
      
}

Measured memory_bytes: 3720
#include <bits/stdc++.h>
#define gc() getchar()
using namespace std;

int in()
{
    int n = 0, c = 0;
    do {n = 10*n + (c & 0xf); c = gc();} while ('0'<=c && c<='9');
    return n;
}

int main()
{
    int count = 0;
    int l = in(), r = in(), d = in();

    for (int i=l; i<=r; i++)
    {
        if (i % d == 0) count++;
    }

    printf("%d\n", count);
}


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

const int Maxn = 200005;

int n, k;
int a[Maxn];
int delt[Maxn];

int main()
{
    scanf("%d %d", &n, &k);
    for (int i = 1; i <= n; i++)
        scanf("%d", &a[i]);
    bool rep = true;
    while (rep && k > 0) {
        k--; rep = false;
        fill(delt, delt + Maxn, 0);
        for (int i = 1; i <= n; i++) {
            int l = i - a[i], r = i + a[i] + 1;
            delt[max(1, l)]++;
            if (r <= n) delt[r]--;
        }
        int cur = 0;
        for (int i = 1; i <= n; i++) {
            cur += delt[i];
            a[i] = cur;
            if (a[i] < n) rep = true;
        }
    }
    for (int i = 1; i <= n; i++)
        printf("%d%c", a[i], i + 1 <= n? ' ': '\n');
    return 0;
}


Measured memory_bytes: 5320
import math
import numpy as np
N = int(input())
xy = [list(map(int,input().split())) for _ in range(N)]
d = [[0 for _ in range(N)] for _ in range(N)]
s = 0
for i in range(N):
    for j in range(N):
        if i != j:
            xi,yi = xy[i]
            xj,yj = xy[j]
            d[i][j] = math.sqrt((xj-xi)**2+(yj-yi)**2)
print(np.sum(d)/ N)

Measured memory_bytes: 21572
// Problem : C - Walking Takahashi
// Contest : AtCoder - AtCoder Beginner Contest 175
// URL : https://atcoder.jp/contests/abc175/tasks/abc175_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

/*

WINNERS NEVER QUIT AND QUITTERS NEVER WIN!!

*/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<long,long> pl;
typedef pair<ll,ll> pll;
typedef vector<long> vl;
typedef vector<bool> vb;
typedef vector<ll> vll;
typedef vector<vl> vvl;
typedef vector<vb> vvb;
typedef vector<vll> vvll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef unordered_map<ll,ll> umll;

#define FOR(i,a,b) for(long long i=a;i<b;++i)
#define REV(i,a,b) for(long long i=a;i>=b;i--)
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define tc ll tests;cin>>tests;while(tests--)
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define coutv(v) for(auto it: (v))cout<<it<<" ";newl;
#define cout2d(v) for(auto it: (v)) {for(auto j:it) cout<<j<<" ";newl;}
#define cinv(v,n) vll (v)(n);FOR(i,0,(n)){cin>>v[i];}
#define cinvg(v,n) (v).resize(n);FOR(i,0,(n)){cin>>v[i];}
#define cin2d(v,n,m) vvll (v)(n,vll(m,0));FOR(i,0,n){FOR(j,0,m){cin>>v[i][j];}}
#define cin2dg(v,n,m) (v).resize(n,vll(m));FOR(i,0,n){FOR(j,0,m){cin>>v[i][j];}}
#define newl cout<<"\n"
#define mod 1000000007
#define INF LLONG_MAX/2

int main()
{
    ll X, K, D;
    cin >> X >> K >> D;
    X = abs(X);
 
    ll straight = min(K, X / D);
    K -= straight;
    X -= straight * D;
 
    if (K % 2 == 0) {
        cout << X << endl;
    } else {
        cout << D - X << endl;
    }
    
    return 0;
}



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

int taste(int L,int i){
  return L + i -1;
}


int main(){
  int N,L,j;
  cin >> N >> L;
  if(L-1<=-N){
    j=N;
  }else if(L-1>-1){
    j=1;
  }else{
    j=-L+1;
  }
  cout << (int)(N*(L-1)+0.5*N*(N+1))-(L+j-1)<< endl;
  return 0;
}
  
    


Measured memory_bytes: 256
num = gets
num = num.to_i

all_sum = 0


(1..num).each do |i|
    if i % 3 == 0 && i % 5 == 0
        next
    elsif i % 3 == 0
        next
    elsif i % 5 == 0
        next
    else
        all_sum = all_sum + i
    end
end

puts all_sum

Measured memory_bytes: 14356
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;
#define ll long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n, x;
    cin >> n >> x;
    ll a[100001];
    ll tmp;
    rep(i, n){
        cin >> tmp;
        a[i] = tmp;
    }
    ll ans;
    ans  = abs(a[0] - x);
    rep(i, n){
        ans = __gcd(ans, abs(a[i] - x));
        //cout << ans << endl;

    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1024
#include<queue>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define rnt re int
#define re register
#define I inline int
#define V inline void
#define ll long long int
#define isnum(ch) ('0'<=ch&&ch<='9')
#define FOR(i,a,b) for(rnt i=a;i<=b;i++)
#define ROF(i,a,b) for(rnt i=a;i>=b;i--)
#define REP(u) for(rnt i=h[u],v;v=e[i].t,i;i=e[i].n)
#define gc (_op==_ed&&(_ed=(_op=_buf)+fread(_buf,1,100000,stdin),_op==_ed)?EOF:*_op++)
char _buf[100000],*_op(_buf),*_ed(_buf);
I getint(){
	rnt _s=0;re char _ch=gc;
	while(!isnum(_ch))_ch=gc;
	while(isnum(_ch))_s=_s*10+_ch-48,_ch=gc;
	return _s;
}
I min(const int&x,const int&y){return x<y?x:y;}
I max(const int&x,const int&y){return x>y?x:y;}
const int N=3e2;
int n,ans=-1;
char a[N][N];
V input(){
	scanf("%d",&n);
	FOR(i,1,n)scanf("%s",a[i]+1);
}
int h[N],tot;
struct edge{int t,n;}e[N*N];
V add_edge(rnt x,rnt y){
	e[++tot]=(edge){y,h[x]},h[x]=tot;
}
V init(){
	FOR(i,1,n)FOR(j,1,n)if(a[i][j]=='1')
		add_edge(i,j);
}
int dep[N],flag;
queue<int>q;
V bfs(rnt u){
	FOR(i,1,n)dep[i]=0;flag=1;
	dep[u]=1,q.push(u);
	while(!q.empty()){
		u=q.front(),q.pop();
		REP(u)
			if(!dep[v])dep[v]=dep[u]+1,q.push(v);
			else if(abs(dep[u]-dep[v])^1)
				flag=0;
	}
}
V work(){
	FOR(i,1,n){
		bfs(i);
		if(flag)FOR(j,1,n)ans=max(ans,dep[j]);
	}
	cout<<ans;
}
int main(){
//	freopen("test.in","r",stdin);
//	freopen(".out","w",stdout);
	input();
	init();
	work();
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(a) a.begin(), a.end()
#define P pair<int, int>
#define F first
#define S second
#define prime 1000000007
#define INF 40000000000000000
int dx8[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
int dy8[8] = {1, 1, 1, 0, -1, -1, -1, 0};
int dx4[4] = {-1, 0, 1, 0};
int dy4[4] = {0, -1, 0, 1};
signed main(void) {
    while(true) {
        int N, M;
        cin >> N >> M;
        if(N == 0 && M == 0) break;
        int Code[M], X[N];
        rep(i, M) cin >> Code[i];
        rep(i, N) cin >> X[i];
        vector<vector<int>> dp(20010, vector<int>(256, INF));
        dp[0][128] = 0;
        rep(i, N) rep(j, 256) {
            rep(k, M) {
                int next = j + Code[k];
                next = max(next, (int)0);
                next = min(next, (int)255);
                dp[i + 1][next] = min(dp[i + 1][next], dp[i][j] + (next - X[i]) * (next - X[i]));
            }
        }
        int ans = INF;
        rep(i, 256) ans = min(ans, dp[N][i]);
        cout << ans << endl;
    }
}



Measured memory_bytes: 43752
#include <iostream>
#include <string>
#include <algorithm>
int main(){
	std::string KUPC;
	std::cin>>KUPC;	
	int K=0,U=0,P=0,C=0;
	for(int i=0;i<KUPC.size();i++){
		if(KUPC[i]=='K'){
			K++;
		}else if(KUPC[i]=='U'){
			U++;
		}else if(KUPC[i]=='P'){
			P++;
		}else if(KUPC[i]=='C'){
			C++;
		}
	}
	std::cout<<std::min(K,std::min(U,std::min(P,C)))<<std::endl;
}

Measured memory_bytes: 1188
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
#include<stdio.h>
#include <cstdint>
#include <stdlib.h> 
#include <time.h>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define all(a) a.begin(), a.end()
#define fi first
#define se second
#define RNG(x, a, n) &((x)[a]), &((x)[n])
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
typedef long long ll;
typedef pair<ll, ll> Pll;
typedef vector<ll> Vl;
template<typename T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }
template<typename T> bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;
const long double PI = (acos(-1));
const long double EPS = 0.0000000001;


int k, n, ans;
int a[200005];

int main() {

	cin >> k >> n;

	rep(i, n) {
		cin >> a[i];
	}

	rep(i, n - 1) {
		ans = max(ans, a[i + 1] - a[i]);
	}

	ans = max(ans, ((k - a[n - 1]) + a[0]));

	cout << k - ans << endl;

	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <cassert>
#include <iomanip>

using namespace std;

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

    int t = 250;

    vector<vector<int>> x(a, vector<int>(b, t));

    for (int i = 0; i + c - 1 < a; i += c) {
        for (int j = 0; j + d - 1 < b; j += d) {
            x[i + c - 1][j + d - 1] = -t * (c * d - 1) - 1;
        }
    }

    long long s = 0;

    for (int i = 0; i < a; i++) {
        for (int j = 0; j < b; j++) {
            s += x[i][j];
        }
    }

    if (s <= 0) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;

        for (int i = 0; i < a; i++) {
            for (int j = 0; j < b; j++) {
                cout << x[i][j] << " \n"[j + 1 == b];
            }
        }
    }
}


Measured memory_bytes: 2304
//----------------------------templates
    #pragma GCC optimize ("Ofast")
    #pragma GCC target ("tune=native")
    #pragma GCC target ("avx")
    //----------------------------
    #include <bits/stdc++.h>
    using namespace std;

    typedef long long ll;
    typedef unsigned long long ull;
    #define int ll

    #define FOR(i,j,n) for (int i=(int)(j);i<(n);i++)
    #define REP(i,n) for (int i=0;i<(int)(n);i++)
    #define REPS(i,n) for (int i=1;i<=(int)(n);i++)
    #define REPN(i,n) for (int i=(int)(n)-1;i>=0;i--)
    #define REPNS(i,n) for (int i=(int)(n);i>0;i--)

    #define I(n) scanf("%lld", &(n))
    #define LL(n) scanf("%lld", &(n))
    #define pb(n) push_back((n))
    #define mp(i,j) make_pair((i),(j))
    #define eb(i,j) emplace_back((i),(j))
    #define y0 y3487465
    #define y1 y8687969
    #define j0 j1347829
    #define j1 j234892
    #define uniq(v) v.erase( unique(v.begin(), v.end()), v.end() )

    #define all(x) (x).begin(),(x).end()
    #define sz(x) ((int)(x).size())

    typedef vector<int> vi;
    typedef pair<int,int> pi;
    typedef vector<pi> vpi;
    typedef vector<vi> vvi;
    typedef vector<vpi> vvpi;
    typedef vector<vvi> vvvi;

    const int mod = 1000000007;

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

int n,w;
vpi item;
int dp[101][103010];
int width;

int decode(int wi){
    return width * (wi/1000) + wi % 1000;
}
int encode(int rw){
    return (rw/width) * 1000 + rw % width;
}

signed main(){
    I(n); I(w);
    REP(i,n){
        int wi,vi;
        I(wi); I(vi);
        item.eb(wi,vi);
    }

    width = item[0].first;
    int ret = 0;
    if (width > 1000){
        REP(i,n){
            FOR(wi, 1000, 1000*(i+3)){
                if(wi%1000 >= item[i].first - width){
                    // cerr << encode(decode(wi) - item[i].first) << endl;
                    dp[i+1][wi] = max(dp[i][wi], dp[i][ encode(decode(wi) - item[i].first) ] + item[i].second);
                } else {
                    dp[i+1][wi] = dp[i][wi];
                }
            }
        }
        for(int wi = 0; decode(wi) <= w; wi++) ret = max(ret, dp[n][wi]);
    } else {
        REP(i,n) REP(wi,100001){
            if (wi >= item[i].first){
                dp[i+1][wi] = max(dp[i][wi], dp[i][wi-item[i].first] + item[i].second);
            } else {
                dp[i+1][wi] = dp[i][wi];
            }
        }
        REP(i,w+1) ret = max(ret, dp[n][i]);
    }
    cout << ret << endl;
}

Measured memory_bytes: 80640
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int n,a[200005];
bool flag[200005];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	  scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	int nowr=n;
	int ans=0;
	for(long long s=1ll<<31;s>0;s>>=1)
	{
		while(nowr>1&&(a[nowr]>=s||flag[nowr]))nowr--;
		int now=nowr;
		for(int i=1;i!=now;i++)
		{
			if(flag[i])continue;
			while(i<now&&((long long)a[i]+a[now]>s||flag[now]))now--;
			if(i==now)break;
			if((long long)a[i]+a[now]==s)
			{
				flag[i]=1;
				flag[now]=1;
				ans++;
			}
		}
	}
	printf("%d\n",ans);
	return 0;
	return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
	// your code goes here
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n,i,j,k,W,w,v;
	
	cin>>n>>W;
	int dp[W+1]={0};
	for(i=0;i<n;i++)
	{
		cin>>w>>v;
		for(j=W-w;j>=0;j--)
		{
			dp[j+w]=max(dp[j+w],dp[j]+v);
		//	cout<<j+w<<" "<<dp[j+w]<<endl;
		}
	}
	k=0;
	for(i=0;i<W+1;i++)
	{
		k=max(k,dp[i]);
	}
	cout<<k;
	return 0;
}


Measured memory_bytes: 1024
#define MAX 10000
#define NIL -1

typedef struct {
	int p, l, r;
} Node;

Node T[MAX];
int n, D[MAX], H[MAX];

void setDepth(int u, int d) {
	if (u == NIL) return;
	D[u] = d;
	setDepth(T[u].r, d + 1);
	setDepth(T[u].l, d + 1);
}

int setHeight(int u){
	int h1 = 0, h2 = 0;

	if (T[u].l != NIL) h1 = setHeight(T[u].l) + 1;
	if (T[u].r != NIL) h2 = setHeight(T[u].r) + 1;
	return H[u] = (h1 > h2 ? h1 : h2);
}

int getSibling(int u) {
	if (T[u].p == NIL) return NIL;
	if (T[T[u].p].l != u && T[T[u].p].l != NIL) {
		return T[T[u].p].l;
	}
	if (T[T[u].p].r != u && T[T[u].p].r != NIL) {
		return T[T[u].p].r;
	}
	return NIL;
}

void print(int u) {
	printf("node %d: ", u);
	printf("parent = %d, ", T[u].p);
	printf("sibling = %d, ", getSibling(u));

	int deg = 0;
	if (T[u].l != NIL) deg++;
	if (T[u].r != NIL) deg++;
	printf("degree = %d, ", deg);
	printf("depth = %d, ", D[u]);
	printf("height = %d, ", H[u]);

	if (T[u].p == NIL)	printf("root\n");
	else if (T[u].l == NIL && T[u].r == NIL) printf("leaf\n");
	else printf("internal node\n");
}

int main() {
	int i, v, l, r, root = 1;

	scanf("%d", &n);
	for (i = 0; i < n; i++) T[i].p = NIL;

	for (i = 0; i < n; i++) {
		scanf("%d %d %d", &v, &l, &r);
		T[v].l = l;
		T[v].r = r;
		if (l != NIL) T[l].p = v;
		if (r != NIL) T[r].p = v;
	}

	for (i = 0; i < n; i++) {
		if (T[i].p == NIL) root = i;
	}

	setDepth(root, 0);
	setHeight(root);

	for (i = 0; i < n; i++) {
		print(i);
	}

	return 0;
}


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

int main() {
	int n,m,k;
	bool found = false;
	cin >> n >> m >> k;
	
	for(int i=0;i<n+1;i++){
		for(int j=0;j<m+1;j++){
			if((i*m+j*n-2*i*j)==k){
				cout << "Yes" << endl;
				found = true;
				break;
			}
		}
		if(found == true) break;
	}
	
	if(found==false) cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1e+9
#define debug(x) cerr << #x << ": " << x << "\n";
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main(void){
    int N;
    cin >> N;
    int a[100000];
    for(int i = 0; i < N; i++){
        cin >> a[i];
    }

    queue<int> que;
    ll res = 0;

    sort(a, a+N, greater<int>());
    for(int i = 0; i < N-1; i++){
        if(a[i] == a[i+1]){
            que.push(a[i]);
            a[i] = a[i+1] = -1;
        }
    }

    if(que.size() >= 2){
        ll a = que.front();
        que.pop();
        ll b = que.front();
        res = a * b;
    }
    cout << res << '\n';
    return 0;
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
#define mo 1000000007
#define pi 3.1415926535898
#define eps 1e-9 
using namespace std;
long long read(){
    long long xx=0,flagg=1;
    char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-')
        ch=getchar();
    if(ch=='-'){
        flagg=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        xx=xx*10+ch-'0';
        ch=getchar();
    }
    return xx*flagg;
}
void pus(long long xx,long long flagg){
    if(xx<0){
        putchar('-');
        xx=-xx;
    }
    if(xx>=10)
        pus(xx/10,0);
    putchar(xx%10+'0');
    if(flagg==1)
        putchar(' ');
    if(flagg==2)
        putchar('\n');
    return;
}
int w,h,n,i,j,k,yy,ans,a[300005],b[300005],xia,shang,head,tail,zhan[300005];
struct nyh{
	int x,y;
}o[300005];
bool cmp(nyh u,nyh v){
	return u.x<v.x||u.x==v.x&&u.y<v.y;
}
int maxx(int u,int v){
	return u>v?u:v;
}
int minn(int u,int v){
	return u<v?u:v;
}
void gb(int u,int v){
	int mid=((u+v)>>1);
	if(u==v)
		return;
	gb(u,mid);
	gb(mid+1,v);
	for(i=mid,xia=0,shang=h;i>=u;i--){
		a[i]=xia;
		b[i]=shang;
		if(o[i].y>=yy) shang=minn(shang,o[i].y);
		if(o[i].y<=yy) xia=maxx(xia,o[i].y);
	}
	for(i=mid+1,xia=0,shang=h;i<=v;i++){
		a[i]=xia;
		b[i]=shang;
		if(o[i].y>=yy) shang=minn(shang,o[i].y);
		if(o[i].y<=yy) xia=maxx(xia,o[i].y);
	}
	head=1;tail=0;
	for(i=mid,j=mid;i>=u;i--){
        while(j<=v&&a[j]<=a[i]){
            while(head<=tail&&b[zhan[tail]]+o[zhan[tail]].x<=b[j]+o[j].x)
            	tail--;
            tail++;
            zhan[tail]=j;
            j++;
        }
        while(head<tail&&b[i]+o[zhan[head]].x<=b[zhan[head+1]]+o[zhan[head+1]].x)
        	head++;
    	ans=maxx(ans,(o[zhan[head]].x-o[i].x+min(b[i],b[zhan[head]])-a[i])<<1);
    }
    head=1;tail=0;
	for(i=mid,j=mid;i<=v;i++){
        while(j>=u&&a[j]<=a[i]){
            while(head<=tail&&b[zhan[tail]]-o[zhan[tail]].x<=b[j]-o[j].x)
            	tail--;
            tail++;
            zhan[tail]=j;
            j--;
        }
        while(head<tail&&b[i]-o[zhan[head]].x<=b[zhan[head+1]]-o[zhan[head+1]].x)
        	head++;
    	ans=maxx(ans,(o[i].x-o[zhan[head]].x+min(b[i],b[zhan[head]])-a[i])<<1);
    }
}
void work(){
	sort(o+1,o+n+1,cmp);
	yy=(h>>1);
	o[0].x=0;
	o[0].y=yy;
	o[n+1].x=w;
	o[n+1].y=yy;
	gb(0,n+1);
}
int main(){
	//freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
	w=read();h=read();n=read();
	for(i=1;i<=n;i++){
		o[i].x=read();
		o[i].y=read();
	}
	ans=max(w,h)*2+2;
	work();
	swap(w,h);
	for(i=1;i<=n;i++)
		swap(o[i].x,o[i].y);
	work();
	pus(ans,2);
	return 0;
}

Measured memory_bytes: 6144
#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(){
    
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int x;
    cin >> x;
    
    int ans = 0;
    int sum = 0;
    int i = 1;
    
    while(true){
        sum += i;
        i++;
        ans++;
        if(sum>=x){
            break;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
n = int(input())
p = [int(x) for x in input().split()]
count = 0

#それぞれの3要素の比較において, 昇順または降順にソートしても変化が無ければ真ん中の要素が2番>目に大きいことになる
for i in range(1,n-1):
    p_3list = [p[i-1],p[i],p[i+1]]

    if p_3list == sorted(p_3list):
        count += 1
    elif p_3list == sorted(p_3list,reverse=True):
        count += 1

print(count)

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

int main(){
	int n;
	cin >> n;
	vector<int> a;
	int c = 0;
	for ( int i = 0; i < n; i++ ) {
		a.push_back(i);
		cin >> a[i];
	}
	for ( int i = 0; i < n - 1; i++ ) {
		for ( int t = n - 2; t >= i; t-- ) {
			if ( a[t] > a[t+1] ) {
				int b;
				b = a[t];
				a[t] = a[t+1];
				a[t+1] = b;
				c++;
			}
		}
	}
	for ( int i = 0; i < n; i++ ) {
		cout << a[i];
		if ( i < n - 1 ) {
			cout << " ";
		}else {
			cout << endl;
		}
	}
	cout << c << endl;
	return 0;
}

Measured memory_bytes: 1220
#include <bits/stdc++.h>
using namespace std;
const int Match[10]={0,2,5,5,4,5,6,3,7,6};
int n,m,a[9],dp[20000];
int main(){
    cin>>n>>m;
    for(int i=1;i<=n;i++)dp[i]=-1e9;
    for(int i=0;i<m;i++)cin>>a[i];
    for(int i=0;i<=n;i++){
        for(int j=0;j<m;j++){
            int x=Match[a[j]];
            dp[i+x]=max(dp[i+x],dp[i]+1);
        }
    }
    sort(a,a+m,greater<int>());
    int x=dp[n];
    for(int i=0;i<x;i++){
        for(int j=0;j<m;j++){
            if(n-Match[a[j]]>=0&&dp[n-Match[a[j]]]+1==dp[n]){
                n-=Match[a[j]];
                cout<<a[j];
                break;
            }
        }
    }
    cout<<endl;
}

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

using namespace std;
#define ll long long 
#define REP(i, n) for(int i = 0; i < (int)(n); i++)

int main() {
  string s;
  cin >> s;
 
  for(int i = 0; i < s.size(); i++){
    if(i % 2 == 0){
      if(s[i] == 'R' || s[i] == 'U' || s[i] == 'D')
        continue;
      else{
      cout << "No" << endl;
      return 0;
      }
    }else{
      if(s[i] == 'L' || s[i] == 'U' || s[i] == 'D')
        continue;
      else{
      cout << "No" << endl;
      return 0;
      }
    }
  }
  
  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 256
x, y = list(map(int, input().split()))
ans = 0
if x  == 1 and y == 1:
  ans += 400000
if x == 1:
  ans += 300000
elif x == 2:
  ans += 200000
elif x == 3:
  ans += 100000
if y == 1:
  ans += 300000
elif y == 2:
  ans += 200000
elif y == 3:
  ans += 100000
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const ll mod = 1000000007;
const ll INF = 1001001001;
const ll LINF = 1001001001001001001;

void prvec(vector<ll> vec){ //for debug
    ll n = vec.size();
    cout << "------------------------------------\n" ;
    rep(i,n) cout << i << " " << vec.at(i) << "\n";
    cout << "------------------------------------\n" ;
}

void pr2d(vector<vector<ll>> vec){ // for debug
    ll h = vec.size();
    ll w = vec.at(0).size();
    cout << "------------------------------------\n" ;
    rep(i,h){
        rep(j,w){
            cout << vec.at(i).at(j) << " ";
        }
        cout << "\n";
    }
    cout << "------------------------------------\n" ;
}

ll n;
vector<vector<ll>> hen,dp;
vector<ll> dist;


ll f(ll num, ll col){
    if(dp[num][col]!=-1) return dp[num][col];
    ll ret = 1;
    ll now = dist[num];
    if(col == 0){ //col==black
        for(auto i:hen[num]){
            if(dist[i]<now) continue;
            ret = (ret*f(i,1)%mod);            
        }
    }else{ //col==1==white
        for(auto i:hen[num]){
            if(dist[i]<now) continue;
            ret = (ret*((f(i,0)+f(i,1))%mod)%mod);            
        }
    }
    dp[num][col] = ret;
    return ret;
}


int main(){
    cin >> n;
    hen.resize(n,vector<ll>(0));
    dp.resize(n,vector<ll>(2,-1));
    dist.resize(n,-1);
    rep(i,n-1){
        ll x,y; cin >> x >> y;
        x--; y--;
        hen.at(x).emplace_back(y);
        hen.at(y).emplace_back(x);
    }
    dist[0] = 0;
    queue<ll> q;
    q.push(0);
    while(q.size()){
        ll x = q.front();
        q.pop();
        for(auto i:hen.at(x)){
            if(dist[i]!=-1) continue;
            dist[i] = dist[x]+1;
            q.push(i);
        }
    }
    //prvec(dist);
    cout << (f(0,0) + f(0,1))%mod << endl;
    return 0;
}

Measured memory_bytes: 18944
D=int(input())
clist=list(map(int,input().split()))
smat=[[int(x) for x in input().split()] for _ in range(D)]
#print(clist)
#print(smat)

index_set=set(range(26))
for d in range(D):
  max_index=-1
  max_sd=-1
  for i in index_set:
    if max_sd<smat[d][i]:
      max_index=i
      max_sd=smat[d][i]
      
  max_index2=-1
  max_sd2=-1
  for i in range(26):
    if max_sd2<smat[d][i]:
      max_index2=i
      max_sd2=smat[d][i]
      
  if max_index==max_index2:
    print(max_index+1)
    index_set.remove(max_index)
  else:
    if max_sd2>4*max_sd:
      print(max_index2+1)
    else:
      print(max_index+1)
      index_set.remove(max_index)      
      
  if not index_set:
    index_set=set(range(26))
  else:
    sum_c=0
    for i in index_set:
      sum_c+=clist[i]
    if sum_c==0:
      index_set=set(range(26))

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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }

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

struct UnionFind {
  vector<int> par; vector<ll> s; 
  UnionFind(int N) : par(N), s(N) { rep(i,N) { par[i] = i; s[i] = 1; } }
  int root(int x) { return par[x]==x ? x : par[x] = root(par[x]); }
  ll size(int x) { return par[x]==x ? s[x] : s[x] = size(root(x)); }
  void unite(int x, int y) { int rx=root(x), ry=root(y); if (rx!=ry) { s[rx] += s[ry]; par[ry] = rx; } }
  bool same(int x, int y) {  int rx=root(x), ry=root(y); return rx==ry; }
};

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


struct edge { ll from; ll to; ll v; ll i; };
vector<vector<edge>> adj;
vector<bool> used_v, used_e;

void dfs(int n, ll v) {
  used_v[n] = true;
  for (auto x: adj[n]) {
    if (x.v<=v) {
      used_e[x.i] = true;
      if (used_v[x.to]) continue;
      dfs(x.to,v);
    }
  }
}

int main() {
  int N, M; cin >> N >> M;
  UnionFind uf(N); rep(i,N) { ll X; cin >> X; uf.s[i] = X; }
  edge e[M]; adj.resize(N);
  rep(i,M) { 
    ll A, B, Y; cin >> A >> B >> Y; A--; B--; e[i] = {A,B,Y,i}; 
    adj[A].push_back({A,B,Y,i}); adj[B].push_back({B,A,Y,i});
  }

  sort(e,e+M,[](const edge &x, const edge &y){return x.v<y.v;});
  used_v.resize(N,false); used_e.resize(M,false); 
  rep(i,M) {
    uf.unite(e[i].from, e[i].to);
    if (uf.size(e[i].from)>=e[i].v) used_e[e[i].i] = true;
  }

  per(i,M) if (used_e[e[i].i]) dfs(e[i].from, e[i].v);
  // debug(all(used_e));

  ll result = 0; rep(i,M) result += !used_e[i];
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 20096
N = int(input())
A = list(map(int, input().split()))

ans = {}
for a in A:
    tmp = ans.get(a)
    # print(tmp)
    if tmp == None:
        ans[a] = 1
    else:
        ans[a] = tmp + 1

# print(ans)

for i in range(N):
    tmp = ans.get(i + 1)
    if tmp == None:
        tmp = 0
    print(tmp)

# for a in list(ans.keys()):
#     print()
# for a in ans:
#     print(a)

Measured memory_bytes: 111984
N, K= map(int, input().split())
li = [list(map(int, input().split())) for i in range(N)]
xx = [p[0] for p in li]
yy = [p[1] for p in li]
xx.sort()
yy.sort()
Min = (xx[N-1]-xx[0])*(yy[N-1]-yy[0])
for xi in range(N-1):
    for xj in range(xi+1, N):
        for yi in range(N-1):
            for yj in range(yi+1, N):
                cnt = 0
                for p in li:
                    [x, y] = p
                    if xx[xi] <= x <= xx[xj] and yy[yi] <= y <= yy[yj]:
                        cnt += 1
                if cnt >= K:
                    Min = min(Min, (xx[xj]-xx[xi])*(yy[yj]-yy[yi]))
print(Min)
        

Measured memory_bytes: 47196
#include<bits/stdc++.h>
#define ll long long int
#define pii pair<int,int >
#define F first
#define S second
#define mod 1000000007
///cout <<"Case #"<<it<<": ";
using namespace std;

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

    ll a,b,n; cin >> a >> b >> n;
    ll x=min(b-1,n);
    ll ans=(a*x)/b;
    ans-=a*(x/b);
    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 3576
#include "bits/stdc++.h"
using namespace std;

// #include "debug.h"
// #define debug(...) 42

using ll = long long;

vector <int> get(int n) {
   vector <int> ret;
   if(n <= 0) return ret;
   for(int i = 0; ; i++) {
      if((i * (i + 1)) / 2 >= n) {
         ret.push_back(i);
         auto t = get(n - i);
         ret.insert(ret.end(), t.begin(), t.end());
         break;
      }
   }
   return ret;
}


void solve() {
   int n;
   cin >> n;

   auto v = get(n);
   for(auto x: v) {
      cout << x << endl;
   }
} 

int main() {
   cin.tie(0);
   cin.sync_with_stdio(0);
   int testcase = 1;
   // cin >> testcase;

   for(int i = 0; i < testcase; i++) {
      solve();
   } 
   return 0;
}


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

bool IsPrime(ll num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }
    return true;
}

void solve(long long X){
    ll i=X;
    while(true){
        if(IsPrime(i)==true){
            cout<<i<<endl;
            return;
        }
        else i++;
    }
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long X;
    scanf("%lld",&X);
    solve(X);
    return 0;
}


Measured memory_bytes: 256
var input= require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=input.split(" ");
var a=Arr[0]-0;
var b=Arr[1]-0;
var str="";
if(a==b)str+="a == b";
if(a>b)str+="a > b";
if(a<b)str+="a < b";
console.log(str);

Measured memory_bytes: 7384
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

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

    while(--n >= 0)
        cout << "ACL";
    cout << endl;

    return 0;
}


Measured memory_bytes: 3592
import sys
sys.setrecursionlimit(10**5)
total=0
def bfs(ind,num):
    kouho=friends[ind]
    
    for i in kouho:
        if sans[i]!=-1:
            continue
        num+=1
        sans[i]=sans[ind]
        l[sans[ind]].add(i)
        num+=bfs(i,0)
    return num
n,m,k=list(map(int,input().split()))
f=[list(map(int,input().split())) for _ in range(m)]
friends=[set() for _ in range(n)]
friends_num=list(map(lambda x:len(x),friends))
bl=[list(map(int,input().split())) for _ in range(k)]
l=[{i} for i in range(n)]

for each in f:
    a,b=each
    friends[a-1].add(b-1)
    friends[b-1].add(a-1)

block=[set() for _ in range(n)]
for each in bl:
    a,b=each
    block[a-1].add(b-1)
    block[b-1].add(a-1)

sans=[-1 for _ in range(n)]
sans[0]=0
total=bfs(0,total)
for i in range(n):
    if sans[i]!=-1:
        continue
    sans[i]=i
    total=bfs(i,total)
ans=[0 for _ in range(n)]


for i in range(n):
    l[i]=set(l[i])


for i in range(n):
    tmp=l[sans[i]]
    ans[i]+=len(tmp)-len(friends[i])-1
    for j in block[i]:
        if sans[i]==sans[j]:
            ans[j]-=1

ans=" ".join(map(str,ans))
#print("total:",total)
print(ans)


Measured memory_bytes: 165776
#include <bits/stdc++.h>
using namespace std;
int main(){
	int L; cin >> L; 
	long long A[200010] = {}; 
	for(int i = 1; i <= L; i++) cin >> A[i]; 
	long long dp[200010][5] = {}; 
	for(int i = 1; i <= L+1; i++){
		dp[i][0] = dp[i-1][0] + A[i]; 
		dp[i][1] = min(dp[i-1][1], dp[i-1][0]) + (A[i] ? (A[i] % 2) : 2); 
		dp[i][2] = min({dp[i-1][2], dp[i-1][1], dp[i-1][0]}) + 1 - A[i] % 2; 
		dp[i][3] = min({dp[i-1][3], dp[i-1][2], dp[i-1][1], dp[i-1][0]}) + (A[i] ? (A[i] % 2) : 2); 
		dp[i][4] = min({dp[i-1][4], dp[i-1][3], dp[i-1][2], dp[i-1][1], dp[i-1][0]}) + A[i]; 
	}
	cout << dp[L+1][4] << endl; 
}

Measured memory_bytes: 9600
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<tuple>


#define MOD 1000000007
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back

typedef long long ll;

using namespace std;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main(){
    ll N;
    ll K,R,S,P;
    cin>>N>>K>>R>>S>>P;

    string T;
    cin>>T;
    ll dp[3][100005]={};
    
    rep(i,0,K){
        int now = i;
        if(T[now]=='r'){
            dp[2][now] = P;
        }
        else if(T[now]=='s'){
            dp[0][now] = R;
        }
        else{
            dp[1][now] = S;
        }
        now += K;
        while (now<N){
            if(T[now]=='r'){
                dp[2][now] = max(P+dp[0][now-K],P+dp[1][now-K]);
                dp[0][now] = max(dp[1][now-K],dp[2][now-K]);
                dp[1][now] = max(dp[0][now-K],dp[2][now-K]);

            }
            else if(T[now]=='s'){
                dp[0][now] = max(R+dp[1][now-K],R+dp[2][now-K]);
                dp[1][now] = max(dp[0][now-K],dp[2][now-K]);
                dp[2][now] = max(dp[1][now-K],dp[0][now-K]);
            }
            else{
                dp[1][now] = max(S+dp[0][now-K],S+dp[2][now-K]);
                dp[0][now] = max(dp[1][now-K],dp[2][now-K]);
                dp[2][now] = max(dp[1][now-K],dp[0][now-K]);
            }
            now +=K;
        }
        

    }
    ll ans = 0;

        for(int i=N-1;i>=N-K;i--){
            ll max_dp=0;
            rep(j,0,3){
                max_dp=max(max_dp,dp[j][i]);
            }
            ans += max_dp;
        }


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

Measured memory_bytes: 2816
n = int(input())
a = [int(input()) for _ in range(n)]

a.sort()
count = 0
temp = a[0]
tempcount = 1
for i in range(1,n):
    if a[i]==temp:
        tempcount += 1
    else:
        if not tempcount%2 == 0:
            count += 1
        tempcount = 1
    temp = a[i]
    #print(i,tempcount)
if tempcount%2 == 1:
    count += 1
print(count)

Measured memory_bytes: 13344
#include <stdio.h>
#define min(a, b) ((a) < (b)) ? (a) : (b)
#define max(a, b) ((a) > (b)) ? (a) : (b)
int main(int argc, const char *argv[])
{
  int l, r;
  int m = 1<<29;
  scanf("%d%d", &l, &r);
  int gl = l / 2019;
  int ml = l % 2019;
  int gr = r / 2019;
  int mr = r % 2019;
  if ( (gr - gl) > 1) {
    printf("%d\n", 0);
    return 0;
  }
  int gap = r - l;
  int minv = 1<<29;
  for (int i = 0; i < gap; i++) {
    for (int j = 0; j < gap; j++) {
      int left = ml + i;
      int right = mr - j;
      minv = min(minv, left * right % 2019);
    }
  }
  printf("%d\n", minv);

  return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <limits.h>
#include <math.h>
int acs(const void *a, const void *b){return *(int*)a - *(int*)b;} /* 1,2,3,4.. */
int des(const void *a, const void *b){return *(int*)b - *(int*)a;} /* 8,7,6,5.. */
int cmp_char(const void *a, const void *b){return *(char*)a - *(char*)b;} /* a,b,c,d.. */
int cmp_str(const void *a, const void *b){return strcmp(*(const char **)a, *(const char **)b);} /* aaa,aab.. */
#define min(a,b) (a < b ? a: b)
#define max(a,b) (a > b ? a: b)
#define rep(i, l, r) for (int i = l; i < r; i++)
#define MAX 200001
#define MOD 1000000007

typedef long long int lli;

int main(void) {
  int n;
  scanf("%d", &n);
  int a[MAX];
  rep(i, 0, n) scanf("%d", &a[i]);

  int cmp = 1;
  rep(i, 0, n) {
    if (a[i] != cmp) continue;
    cmp++;
  }
  int ans;
  if (cmp == 1) ans = -1;
  else ans = n - (cmp - 1);
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 896