akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ", "; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ", "; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << ", " << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << ": " << v.second << ", "; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << ": " << v.second << ", "; os << "}"; return os; }
template<typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); }
template<typename T, typename... Args> void ndarray(vector<T> &vec, int len, Args... args) { vec.resize(len); for (auto &v : vec) ndarray(v, args...); }
template<typename T> bool chmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool chmin(T &m, const T q) { if (q < m) {m = q; return true;} else return false; }
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first - r.first, l.second - r.second); }
#define f first
#define s second

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int p, len;
    cin >> p >> len;
    int ans = INT_MAX;
    vector<int> arr(len);
    for(int i = 0; i < len; i++) {
        cin >> arr[i];
        if(i > 0)
            ans = min(ans, p - arr[i] + arr[i - 1]);
        //cout << ans << endl;
    }
    ans = min(ans, arr[len - 1] - arr[0]);
    cout << ans;
}



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

#define ll long long
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rep(i,n) for(int i = 0; i < int(n); i++)

#define MAX(a,b) (a > b ? a : b)
#define MIN(a,b) (a < b ? a : b)
const int MOD = 1000000007;

int n;
int matrix[21][21];
std::vector<std::vector<int> > dp;

int fun(int i, int num) {
    if(i == n) {
        if(num == (1 << n) - 1) return 1;
        return 0;
    }
    if(dp[i][num] != -1) return dp[i][num];
    ll ans = 0;
    for(int j = 0; j < n; j++) {
        if(matrix[i][j] && !(num & (1 << j))) {
            ans += fun(i + 1, (num | (1 << j)));
            ans %= MOD;
        }
    }
    return dp[i][num] = ans;
}

int main() {
    IOS;
    cin >> n;
    dp.resize(n);
    rep(i, n) dp[i].resize((1 << n),-1);
    rep(i, n) rep(j, n) cin >> matrix[i][j];
    cout << fun(0, 0);
    return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> d(n);
  for (int i = 0; i < n; i++) {
    cin >> d.at(i);
  }
  
  int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i+1; j < n; j++) {
      ans += d.at(i) * d.at(j);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#ifdef DEMETRIO
#define deb(...) fprintf(stderr,__VA_ARGS__)
#define deb1(x) cerr << #x << " = " << x << endl
#else
#define deb(...) 0
#define deb1(x) 0
#endif
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++i)
#define SZ(x) ((int)x.size())
using namespace std;
typedef long long ll;

ll r[100005];
bool vis[100005];
int n,m;
vector<pair<int,int> > g[100005];
bool can=true;

void dfs(int x){
	for(auto p:g[x]){
		int y=p.fst,d=p.snd;
		if(!vis[y]){
			vis[y]=true;
			r[y]=r[x]+d;
			dfs(y);
		}
		else if(r[y]!=r[x]+d)can=false;
	}
}

int main(){
	scanf("%d%d",&n,&m);
	fore(_,0,m){
		int x,y,d;
		scanf("%d%d%d",&x,&y,&d);x--;y--;
		g[x].pb(mp(y,d));
		g[y].pb(mp(x,-d));
	}
	memset(r,-1,sizeof(r));
	fore(i,0,n)if(!vis[i])r[i]=0,vis[i]=true,dfs(i);
	puts(can?"Yes":"No");
	return 0;
}

Measured memory_bytes: 11520
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<cstdlib>
#include<string>
#include<algorithm>
#include<functional>
#include<map>
#include<iomanip>
#include<limits>
#include<queue>
#include<set>
#include<cstdio>
#include<climits>
#include<cstring>

using namespace std;


int N;
map<int,int>mp;
vector<int>v;

int main(){
    cin >> N;
    while(N--){
    	int x;
    	cin >> x;
    	mp[x]++;
    	if(mp[x] == 2)v.push_back(x);
    	if(mp[x] == 4)v.push_back(x);
    }

    sort(v.begin(),v.end(),greater<int>());

    if(v.size() < 2){
    	cout << 0 << endl;
    }else{
    	cout << 1LL*v[0]*v[1] << endl;
    }

	return 0;

}


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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<long long, long long> pl;
 
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define speedhack() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define form(i, n) for (size_t i = 0; i < size_t(n); ++i)
#define forn(i, n) for (size_t i = 1; i <= size_t(n); ++i)
template<class T> using ordered_set=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
ll mod(ll a, ll b) { return (a%b+b)%b; }
ll gcd(ll x, ll y) { return __gcd(x, y); }
ll lcm(ll x, ll y) { return x * 1ll * y / gcd(x, y); }
 
 
const ll MAXN = 1e18;
const ll SIZE = 2e5 + 5;
const ll MOD  = 1e9 + 7;

#define PI 3.14159265

ll a, b, h, m;
double res, angle, mi, ho;

int main() { speedhack()

	cin >> a >> b >> h >> m;

	mi = m * 6;
	ho = h * 30 + (double(m) / 60) * 30;

	angle = abs (mi - ho);

	if (angle > 180)
		angle = 360 - angle;
	
	res = sqrt(a * a + b * b - 2 * a * b * cos (angle * M_PI / 180.0));
	cout << fixed << setprecision(20) << res;
	


	return 0;
}


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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ll long long
#define mm 1000000007
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define siz(x) (int)x.size()

#define show(x) cout<<#x<<" "<<x<<'\n'
#define iosbase ios_base::sync_with_stdio(false); cin.tie(NULL);
#define oset tree<int , null_type, less_equal<int> , rb_tree_tag, tree_order_statistics_node_update>

using namespace std;
using namespace __gnu_pbds;

ll a[100005][4];
ll dp[100005][4];
ll n;

ll fun(ll x,ll i)
{
    if(x<1) return 0;
    
    if(dp[x][i]==-1)
    {
        if(i==1) dp[x][i]=a[x][i]+max(fun(x-1,2),fun(x-1,3));
        if(i==2) dp[x][i]=a[x][i]+max(fun(x-1,1),fun(x-1,3));
        if(i==3) dp[x][i]=a[x][i]+max(fun(x-1,1),fun(x-1,2));
    }
    
    return dp[x][i];
}

int main()
{
    iosbase;
    ll i;
    cin>>n;
    memset(dp,-1,sizeof(dp));
    for(i=1;i<=n;i++)
    {
        for(ll j=1;j<=3;j++)
            cin>>a[i][j];
    }
    
    ll ans=max(fun(n,1),max(fun(n,2),fun(n,3)));
    cout<<ans<<endl;
}

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

using namespace std;

typedef long long ll;
#define endl '\n'

int n;
ll r[111],c[111],d[111];
ll dp[111][111];
const ll oo = 1000000000000000LL;

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

	cin >> n;
	for(int i = 1; i <= n; i++)
		cin >> r[i] >> c[i];
	d[0] = r[1];
	for(int i = 1; i <= n; i++)
		d[i] = c[i];
	for(int size = 1; size <= n;size++){
		for(int i = 1; i <= n - size; i++){
			int j = i + size;
			dp[i][j] = oo;
			for(int k = i; k <= j - 1;k++){
				ll cost = dp[i][k] + dp[k + 1][j] + d[i - 1]*d[k]*d[j];
				dp[i][j] = min(dp[i][j],cost);
			}
		}
	}
	
	cout << dp[1][n] << endl;

	return 0;
}


Measured memory_bytes: 3272
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(int i = 0; i < n; ++i)
#define rep2(i,start,end) for(ll i = start; i < end; ++i)
#define dwn(i,n) for(int i = n; i >= 0; --i)
#define dwn2(i,start,end) for(ll i = start; i >= end; --i)
#define pll pair<ll,ll>
#define mk(x,y) make_pair(x,y)
#define pdl pair<double, ll>
const ll N = 4e5 + 200;
const ll INF = 0x3f3f3f;
const ll mod = 1e9 + 7;


int main(){
	int n;
	cin>>n;
	if(n % 2 == 0){
		cout<<1.0/2<<endl;
	}else{
		cout<<((n+1)/2.0)/n<<endl;
	}


	return 0;
}








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

int main()
{
    int n;
    cin>>n;
  string s,t1,t2;
  cin>>s;
  
  int x= s.size()/2;
  
  for(int i=0;i<s.size();i++)
  {
    if(i<x){
    t1 = t1 + s[i];
    }
    
    else{
      t2 = t2 + s[i];
    }
  }
  
  if(t1.compare(t2)==0)
  {
    cout<<"Yes"<<endl;
  }
  
  else {
    cout<<"No"<<endl;
  }
  
  return 0;
  
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;

const int INF = (1<<26);
const int segN=(1<<20);

struct data{
  P value;
  data* ch[2];

  void clear(){
    for(int i=0;i<2;i++){
      if(ch[i]->ch[0]!=NULL)ch[i]->clear();
      free(ch[i]);
    }
  }
  
  void init(){
    value=P(-INF,-1);
    ch[0]=(data*)malloc(sizeof(data));
    ch[1]=(data*)malloc(sizeof(data));
    ch[0]->ch[0]=NULL;
    ch[1]->ch[0]=NULL;
  }
  
  void set(int a,int b,P x,int l,int r){
    int m=(l+r)/2;
    if(ch[0]==NULL)init();
    
    if(b<=l || r<=a)return; 
    else if(a<=l && r<=b){
      value=(x>value?x:value);
    }else{
      ch[0]->set(a,b,x,l,m);
      ch[1]->set(a,b,x,m,r);
    }
  }
   
  void set(int a,int b,P x){
    set(a,b,x,0,segN);
  }
  
  P max(int i,int l,int r){
    
    int m=(l+r)/2;
    if(ch[0]==NULL)init();
    if(i<l || r<=i)return P(-INF,-1);
   
    if(r-l==1){
      return value;
    }
    
    P res=value;
    P lc=ch[0]->max(i,l,m);
    res=(lc>res?lc:res);
    P rc=ch[1]->max(i,m,r);
    res=(rc>res?rc:res);
    return res;
  }
 
  P max(int i){
    return max(i,0,segN);
  }
};

#define MAX 100005
int n,m,a;
char str[2];
vector<int> vec;
vector<int> G[MAX];
int l[MAX],r[MAX],depth[MAX];
data T;

void init(){
  T.init();
  vec.clear();
  for(int i=0;i<n;i++){
    depth[i]=0;
    l[i]=INF;
    r[i]=0;
    G[i].clear();
  }
}

int main(){
  while(1){
    scanf("%d %d",&n,&m);
    if(n==0&&m==0)break;
    init();
    for(int i=1;i<n;i++){
      scanf("%d",&a);
      a--;
      G[a].push_back(i);
    }

    stack<int> st;
    st.push(0);
    while(!st.empty()){
      int pos=st.top();st.pop();
      l[pos]=min(l[pos],(int)vec.size());
      r[pos]=max(r[pos],(int)vec.size());
      vec.push_back(pos);
      if(G[pos].empty())continue;
      st.push(pos);
      st.push(G[pos].back());
      depth[G[pos].back()]=depth[pos]+1;
      G[pos].pop_back();
    }

    /*
    for(int i=0;i<(int)vec.size();i++)
      cout<<vec[i]<<' ';cout<<endl;

    for(int i=0;i<n;i++){
      cout<<i<<' '<<l[i]<<' '<<r[i]<<' '<<depth[i]<<endl;
    }
    */
    T.set(l[0],r[0]+1,P(0,0));
    
    long long sum=0;
    for(int i=0;i<m;i++){
      scanf("%s %d",str,&a);
      a--;
      if(str[0]=='Q'){
        sum+=(T.max(l[a]).second+1LL);
      }else{
        T.set(l[a],r[a]+1,P(depth[a],a));
      }
    }
    cout<<sum<<endl;
    T.clear();
  }
  return 0;
}

Measured memory_bytes: 28452
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
typedef long long LL;
map<int,int>m;
int N;
int main(){
	cin>>N;
	REP(i,N){
		int d;
		cin>>d;
		m[d]++;
	}
	cout<<m.size()<<endl;
	return(0);
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
#include <map>
#include <string>
#include <vector>
#define FOR(i, a, b)  for(int i=a; i<b; ++i)
#define rFOR(i, a, b) for(int i=a-1; i>=b; --i)
#define REP(i, n) for(int i=0; i<n; ++i)
#define rREP(i, n) for(int i=n-1; i>=0; --i)
#define all(a)  a.begin(), a.end()
#define MAXNUM 5000
using namespace std;
typedef long long ll;

int main(){
  while(true){
    int a, d, n;  cin >> a >> d >> n;
    if(a+d+n == 0)  break;
    int num;
    vector<int> prime;
    REP(i, MAXNUM){
      bool judge = true;
      num = a + (i * d);
      FOR(j, 2, sqrt(num)+1){
        if(num%j == 0){
          judge = false;
          break;
        }
      }
      if((judge || num == 2) && num!=0 && num!=1) prime.push_back(num);
    }
    cout << prime[n-1] << endl;
  }
  return 0;
}



Measured memory_bytes: 3112
main :: IO ()
main = interact $ solve . map read . words

solve :: [Int] -> String
solve (w:h:x:y:r:_)
	| y + r > h = "No\n"
	| x + r > w = "No\n"
	| y - r < 0 = "No\n"
	| x - r < 0 = "No\n"
	| otherwise = "Yes\n"


Measured memory_bytes: 3712
#include <bits/stdc++.h>
#define pb push_back
#define rep(i,n) for(int i = 0;i < (n); ++i)
#define all(v) sort(v.begin(),v.end())
#define ALL(v) sort(v.begin(),v.end(),greater<ll>())
typedef long long ll;
typedef long double la;
using namespace std;

int f(int x){
    if(x%2 != 0) return 0;
    return f(x/2) + 1;
}

int main(){
    int n,ans=0;
    cin >> n;
    vector<int> a(n);
    rep(i,n){
        cin >> a[i];
        ans += f(a[i]);
    }
    cout << ans << endl;

}

Measured memory_bytes: 256
n=int(input())
l=list(map(int,input().split()))
mod=10**9+7
if n%2==0:
    d={i:2 for i in range(1,n,2)}
else:
    d={i:2 for i in range(0,n,2)}
    d[0]=1
for a in l:
    if a in d:
        d[a]-=1
    else:
        print(0)
        exit()
for i in d.values():
    if i!=0:
        print(0)
        exit()
print((2**(n//2))%mod)


Measured memory_bytes: 20520
use proconio::{input, fastout};
// use std::cmp::max;

#[fastout]
fn main() {
    input! {
        n: usize,
        mut hp: [(i32, i32, i32); n],
    }

    hp.insert(0, (0, 0, 0));
    let mut dp = vec![vec![0;3]; n+1];

    for day in 1..dp.len() {
        dp[day][0] = dp[day-1][1].max(dp[day-1][2]) + hp[day].0;
        dp[day][1] = dp[day-1][0].max(dp[day-1][2]) + hp[day].1;
        dp[day][2] = dp[day-1][0].max(dp[day-1][1]) + hp[day].2;
        // for act in 0..3 {
        //     let oa = (0..3).filter(|&n| n != act).collect::<Vec<usize>>();
        //     dp[day][act] = max(dp[day-1][oa[0]], dp[day-1][oa[1]]) + hp[day][act];
        // }
    }

    println!("{:?}", dp[n].iter().max().unwrap());
}


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

typedef int INT_;

#define int long long

const int MAX = 1e4 + 10;

INT_ main()
{
	int n,a,b; cin>>n>>a>>b;
	int ans=0;

	int prev; cin>>prev;

	for(int i=1;i<n;i++){
		int cur; cin>>cur;
		ans += min(b,(cur-prev)*a);
		prev = cur;
	}

	cout<<ans;

}

Measured memory_bytes: 256
#include<stdio.h>
#define N 101
#define WHITE 0
#define GRAY 2
#define BLACK 1
typedef struct{
  int v[N];
  int dis;
  int fin;
  int color;
  int next;
} Graph;
Graph g[N];
int time,n;
int s[N],top=0;

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

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

void visit(int r)
{
  int ver,u,x;
  push(r);
  g[r].color = GRAY;
  g[r].dis = ++time;
  while(top!=0) {
    x = s[top];
    ver = g[x].v[g[x].next++];
    if(ver!=0) {
      if(g[ver].color == WHITE) {
	      push(ver);
	      g[ver].color = GRAY;
	      g[ver].dis = ++time;
      }
    }
    else {
      u = pop();
      g[x].color = BLACK;
      g[x].fin = ++time;
    }
  }
}

void dfs()
{
  int i;
  for(i=1; i<=n; i++)
    g[i].color = WHITE;
  for(i=1; i<=n; i++)
    if(g[i].color == WHITE)
      visit(i);
}

int main()
{
  int i,j,u,k;

  scanf("%d",&n);
  for(i=0; i<n; i++) {
    scanf("%d%d",&u,&k);
    for(j=0; j<k; j++) {
      scanf("%d",&g[u].v[j]);
    }
  }
  dfs();
  for(i=1; i<=n; i++)
    printf("%d %d %d\n",i,g[i].dis,g[i].fin);
  return 0;
}

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

using namespace std;


int main() {
  
    string s;
    cin>>s;
    int num1=(s.length()-1)/2;
    int num2=(s.length()+3)/2;
    
    int i;
    string s1=s;

    reverse(s.begin(),s.end());
    
    
    
    if(s1!=s)
       printf("No");
       
    else
    {
        int j=num1-1;
       for(i=0;i<=j;++i,--j)
        {
           if(s1[i]==s1[j])
              continue;
              
           else
              break;
       }
       
       if(i>j)
          {
              j=s1.length()-1;
             for(i=num2-1;i<=j;++i,--j)
            {
              if(s1[i]==s1[j])
                  continue;
              
              else
                 break;
             } 
             
             if(i>j)
                 printf("Yes");
                 
             else
                printf("No");
          }
          
        else
          printf("No");
       
    }
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using datas=pair<ll,ll>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
#define For(i,a,b) for(i=a;i<b;i++)
#define bFor(i,a,b) for(i=a;i>=b;i--)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N-1,0)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define mod 1000000007
#define endl "\n"
#define output(v) do{bool f=0;for(auto i:v){cout<<(f?" ":"")<<i;f=1;}cout<<endl;}while(0)

struct unionfind{
  vec par,treesize;
  unionfind(ll N) :par(N){
    ll i;
    rep(i,N)par[i]=i;
    treesize.resize(N);
    rep(i,N)treesize[i]=1;
  }
  ll root(ll x){
    ll r;
    if(par[x]==x)return x;
    r=root(par[x]);
    if(par[x]!=r){
      treesize[r]+=treesize[x];
      treesize[x]=0;
      par[x]=r;
    }
    return r;
  }
  void unite(ll x,ll y){
    ll px=root(x);
    ll py=root(y);
    if(px!=py){
      par[px]=py;
      treesize[py]+=treesize[px];
      treesize[px]=0;
    }
  }
  bool parcheck(ll x,ll y){
    ll px=root(x);
    ll py=root(y);
    return px==py;
  }
  ll size(ll x){
    ll px=root(x);
    return treesize[px];
  }
  void clear(){
    ll i;
    rep(i,(ll)par.size()){
      par[i]=i;
      treesize[i]=1;
    }
  }
};

int main(){
  ll i,N,ans=0;
  cin>>N;
  pvec a(N),b(N);
  rep(i,N){
    cin>>a[i].first>>b[i].first;
    a[i].second=b[i].second=i;
  }
  vsort(a);
  vsort(b);
  vector<tdata> v;
  rep1(i,N){
    v.push_back(tdata(a[i].first-a[i-1].first,datas(a[i-1].second,a[i].second)));
    v.push_back(tdata(b[i].first-b[i-1].first,datas(b[i-1].second,b[i].second)));
  }
  vsort(v);
  unionfind tree(N);
  rep(i,(ll)v.size()){
    if(!tree.parcheck(v[i].second.first,v[i].second.second)){
      tree.unite(v[i].second.first,v[i].second.second);
      ans+=v[i].first;
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 11632
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<climits>
#include<string>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<cstring>
#include<stack>
#include<functional>
using namespace std;

void rotate90(char fld[8][8]){
	char fld_c[8][8]; memcpy(fld_c,fld,sizeof(fld_c));
	for(int i=0;i<8;i++){
		for(int j=0;j<8;j++){
			fld[j][7-i] = fld_c[i][j];
		}
	}
}

int main(){
	char fld[8][8];
	for(int i=0;i<8;i++){
		for(int j=0;j<8;j++){
			scanf(" %c",&fld[i][j]);
		}
	}
	for(int i=90;i<=270;i+=90){
		rotate90(fld);
		printf("%d\n",i);
		for(int j=0;j<8;j++){
			for(int k=0;k<8;k++){
				printf("%c",fld[j][k]);
			}puts("");
		}
	}
	return 0;
}

Measured memory_bytes: 1148
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 0x3f3f3f3f
const int N=3e3+10;
double p[N],dp[N][N];
int main()
{
	int n,i,j;
	double ans=0;
	scanf("%d",&n);
	for(i=1;i<=n;i++) scanf("%lf",&p[i]);
	dp[0][0]=1;
	for(i=1;i<=n;i++)
	{
		dp[i][0]=dp[i-1][0]*(1-p[i]);
		for(j=1;j<=i;j++)
		{
			dp[i][j]=dp[i-1][j-1]*p[i]+dp[i-1][j]*(1-p[i]);
		}
	}
	for(i=1;i<=n;i++)
	{
		if(i>n-i) ans+=dp[n][i];
	}
	printf("%.10lf\n",ans);
	return 0;
}

Measured memory_bytes: 69248
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#include <algorithm>
#include <bitset>
#include <complex>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#include <cassert>
#include <functional>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template<typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template<typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010

/* UnionFind */

struct UnionFind {
  vector<int> data;
  UnionFind(int s): data(s, -1) {}

  int root(int x) {
    if (data[x] < 0) return x;
    return data[x] = root(data[x]);
  }

  bool set(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) return false;
    if (data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return true;
  }

  bool check(int x, int y) {
    return root(x) == root(y);
  }

  int size(int x) {
    return -data[root(x)];
  }
};

int main() {
  int N, M, K;
  int ans[SIZE] = {};
  int A[SIZE], B[SIZE], C[SIZE], D[SIZE];

  scanf("%d%d%d", &N, &M, &K);

  UnionFind uf(N);

  for (int i = 0; i < M; i++) {
    scanf("%d%d", A + i, B + i);
    A[i]--;
    B[i]--;
    uf.set(A[i], B[i]);
    ans[A[i]]--;
    ans[B[i]]--;
  }

  for (int i = 0; i < N; i++) {
    ans[i] += uf.size(i) - 1;
  }

  for (int i = 0; i < K; i++) {
    scanf("%d%d", C + i, D + i);
    C[i]--;
    D[i]--;
    if (uf.check(C[i], D[i])) {
      ans[C[i]]--;
      ans[D[i]]--;
    }
  }

  for (int i = 0; i < N; i++) {
    printf("%d%c", ans[i], " \n"[i + 1 == N]);
  }

  return 0;
}


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

#define INF (INT64_MAX)
#define MOD (1000000000+7)
#define MAX 3000

int N;
string s;

long long acc[MAX * 2 + 1];

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

	int h = N;
	int l = N;
	acc[N] = 1;
	for( int i = 0; i < N - 1; i++ ) {
		if( s[i] == '<' ) {
			for( int j = l; j <= h; j++ ) {
				acc[j] = (acc[j] + acc[j - 1]) % MOD;
			}
			l--;
		}
		else {
			for( int j = h; j >= l; j-- ) {
				acc[j] = (acc[j] + acc[j + 1]) % MOD;
			}
			h++;
		}
	}
	long long ans = 0;
	for( int i = 0; i < N * 2 + 1; i++ ) {
		ans = (ans + acc[i]) % MOD;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
using namespace std;
using ll = long long;
using pii = pair<int,int>;
template<typename T, typename S>
ostream &operator<<(ostream &os, pair<T, S> a){
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template<typename T>
ostream &operator<<(ostream &os, vector<T> v){
    for(auto x:v)os << x << ' ';
    return os;
}
void debug(){cerr << '\n';}
template<typename H, typename... T>
void debug(H a, T... b){
    cerr << a;
    if(sizeof...(b))cerr << ", ";
    debug(b...);
}
int a[505][505];
void solve(int l, int r,int k){
    if(r - l <= 1)return;
    int mid = (l + r) / 2;
    solve(l,mid,k+1);
    solve(mid,r,k+1);
    for(int i = l; i < mid; i++){
        for(int j = mid; j < r; j++){
            a[i][j] = a[j][i] = k;
        }
    }

}
int main(){
    int n;
    cin >> n;
    solve(0,n,1);
    for(int i = 0; i < n; i++){
        for(int j = i + 1; j < n; j++){
            cout << a[i][j] << " ";
        }
        cout << endl;
    }
}

Measured memory_bytes: 1408
MOD = 10**9 + 7
n, m = [int(item) for item in input().split()]
a = [int(item) for item in input().split()]
b = [int(item) for item in input().split()]

cumsum = [[1] * 410 for _ in range(410)]
for order in range(405):
    for i in range(1, 405):
        cumsum[order][i] = pow(i, order, MOD) + cumsum[order][i-1]
        cumsum[order][i] %= MOD

dp = [[0] * (m + 1) for _ in range(n + 1)]
dp[0][0] = 1
for i in range(1, n+1):
    for j in range(0, m+1):
        for k in range(j+1):
            l = a[i - 1]
            r = b[i - 1]
            x = (cumsum[j-k][r] - cumsum[j-k][l-1] + MOD) % MOD
            dp[i][j] += dp[i-1][k] * x 
        dp[i][j] %= MOD

print(dp[-1][-1])

Measured memory_bytes: 60796
/*input
1
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

#define rep(i,j,n) for(i=j;i<n;i++)
#define repi(i,j,n) for(i=j;i>n;i--)
#define inf 100001
#define M 1000000007
#define ll long long
#define ld long double
#define vll vector<long long>
#define vi vector<int>
#define pll pair<long long,long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define vpll vector<pair<long long,long long> >
#define pb push_back
#define pf pop_front
#define F first
#define S second
#define endl '\n'

using namespace std;
using namespace __gnu_pbds; 

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


ll power(ll a,ll m,ll mod){
    ll ans=1;
    while(m){
        if(m%2){
            ans*=a;
            ans%=(mod);
        }
        a=(a*a)%(mod);
        m>>=1;
    }
    return ans;
}


void init(ll* a,ll n,ll val){
    for(ll i=0;i<n;i++)
        a[i]=val;
}



int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL); 
    ll t=1,i,j;
    ll x;
    cin>>x;
    rep(i,0,2000){
    	ll k=pow(i,5)-x;
    	ll y=pow(abs(k),1.0/5);
    	if(k<0)y=-y;
    	//cout<<k<<" "<<y<<endl;
    	if(pow(y,5)==k){
    		cout<<i<<" "<<y<<endl;
    		return 0;
    	}
    }
    return 0;
}




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

/*
  Ide : cari longest subsequence yang isinya x, x+1, ..., x+K-1
  N-K elemen selain subsequence ini bisa dipindahin ke belakang atau depan

  Misal : 
  6 3 1 2 7 4 8 5
  ^       ^   ^
  Pindahin 5 ke depan, 4 ke depan, 3 ke depan, 2 ke depan, 1 ke depan    
*/

int main(){

  int n;
  cin >> n;
  
  int p[n+5], pos[n+5];
  for(int i=1; i<=n; i++){
    cin >> p[i];
    pos[p[i]] = i;
  }

  int len = 1, maxlen = 1;
  for(int i=1; i<n; i++){
    if(pos[i] < pos[i+1]){
      len++;
      maxlen = max(maxlen, len);
    }
    else len = 1;
  }

  cout << n - maxlen << endl;
  return 0;
}

Measured memory_bytes: 5208
#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
#define MAXVAL 200000
using namespace std;

bool visited[10002];
int father[10002];

class Road{
public:
    int val=MAXVAL;
    int u=0;
    int v=0;
    Road(int val,int u,int v){
        this->val=val;
        this->u=u;
        this->v=v;
    }
    Road(){
    }
    bool operator < (Road &r){
        return this->val<r.val;
    }
};

int findP(int i){
    while(father[i]!=i){
        i=father[i];
    }
    return i;
}

void mergeP(int a,int b){
    int fa=findP(a);
    int fb=findP(b);
    father[fb]=fa;
}

int kruskal(int n,vector<Road> &M){
    int ans=0;

    sort(M.begin(),M.end());
    int num=0;
    for(int i=0;i<M.size();i++){
        if(num>=n-1) break;
        if(findP(M[i].u)!=findP(M[i].v)){
            ans+=M[i].val;
            mergeP(M[i].u,M[i].v);
        }
    }
    return ans;
}

int main(){
    int n,q;
    vector<Road> M;
    cin>>n>>q;
    for(int i=0;i<n;i++){
        visited[i]=false;
        father[i]=i;
    }
    for(int i=0;i<q;i++){
        int s,t,val;
        cin>>s>>t>>val;
        M.push_back(Road(val,s,t));
    }
    cout<<kruskal(n,M)<<endl;
}



Measured memory_bytes: 4528
#include <iostream>

using namespace std;

#define MAX 5000001

int A[MAX], H;

void maxfi(int x){
	int large,left, right;
	large = x;
	left = 2*x;
	right = 2*x+1;

	if(left<=H && A[large]<A[left]) large = left;
	if(right<=H && A[large]<A[right]) large = right;


	if(large!=x){
		swap(A[x], A[large]);
		maxfi(large);
	}
}

int main(){
	cin>>H;
	for(int i=1; i<=H; i++){
		cin>>A[i];
	}

	for(int j=H/2; j>=1; j--){
		maxfi(j);
	}

	for(int i=1; i<=H; i++){
		cout<<" "<<A[i];
	}
	cout<<endl;
	return 0;
}


Measured memory_bytes: 5044
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
constexpr char ln = '\n';

const int mx=100010;
const ll mod=1e9+7;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint& operator+=(const mint a) { if ((x += a.x) >= mod) x -= mod; return *this; }
    mint& operator-=(const mint a) { if ((x += mod-a.x) >= mod) x -= mod; return *this; }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
    mint operator+(const mint a) const { mint res(*this); return res+=a; }
    mint operator-(const mint a) const { mint res(*this); return res-=a; }
    mint operator*(const mint a) const { mint res(*this); return res*=a; }
    mint pow(ll t) const { if (!t) return 1; mint a = pow(t>>1); a *= a; if (t&1) a *= *this; return a; }
    // for prime mod
    mint inv() const { return pow(mod-2); }
    mint& operator/=(const mint a) { return (*this) *= a.inv(); }
    mint operator/(const mint a) const { mint res(*this); return res/=a; }
};


int main(){
  int n;
  cin >> n;
  vector<int> a(n),b(n);
  rep(i,n){
    cin >> a[i];
  }
  rep(i,n){
    cin >> b[i];
  }
  if(a[n-1]!=b[0]){cout << 0 << ln; return 0;}

  mint ans = 1;
  rep(i,n){
    int ha = -1, hb = -1;
    if(i==0 || a[i]!=a[i-1]){
      ha = a[i];
    }
    if(i==n-1 || b[i]!=b[i+1]){
      hb = b[i];
    } 
    if(ha==-1 && hb==-1){ ans *= min(a[i],b[i]); continue; }
    if(ha!=-1 && hb==-1 && ha<=b[i]){  continue; }
    if(ha==-1 && hb!=-1 && hb<=a[i]){  continue; }
    if(ha==hb){ continue; }
    ans = 0; break;
  }
  cout << ans.x << ln;
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<ii> vii;
const int MN = 305;
ll dp[MN][MN][MN];
const ll M = 1e9+7;
vii q[MN];
int main() {
	ios::sync_with_stdio(0);cout.tie(0);cin.tie(0);
	ll n,m;
	cin >> n >> m;
	for(int i=0;i<m;i++) {
		ll a,b,c;
		cin >> a >> b >> c;
		q[b].push_back({a,c});
	}
	memset(dp,0,sizeof(dp));
	dp[1][0][0] = dp[0][1][0] = dp[0][0][1] = 1;
	for(int i=0;i<=n;i++) {
		for(int j=0;j<i;j++) {
			for(int k=0;k<i;k++) {
				for(int l=0;l<q[i].size();l++) {
					int ct = 1;
					int st = q[i][l].first;
					if(j >= st) {ct++;}
					if(k >= st) {ct++;}
					if(q[i][l].second != ct) {
						dp[i][j][k] = dp[j][i][k] = dp[j][k][i] = 0;
					}
				}
			}
		}
		for(int j=0;j<i;j++) {
			for(int k=0;k<i;k++) {
				dp[i+1][j][k] += dp[i][j][k];
				dp[i][i+1][k] += dp[i][j][k];
				dp[i][j][i+1] += dp[i][j][k];
				dp[i+1][i][k] += dp[j][i][k];
				dp[j][i+1][k] += dp[j][i][k];
				dp[j][i][i+1] += dp[j][i][k];
				dp[i+1][k][i] += dp[j][k][i];
				dp[j][i+1][i] += dp[j][k][i];
				dp[j][k][i+1] += dp[j][k][i];
			}
		}
		for(int j=0;j<=i;j++) {
			for(int k=0;k<=i;k++) {
				dp[i+1][j][k] %= M;
				dp[j][i+1][k] %= M;
				dp[j][k][i+1] %= M;
			}
		}
	}
	ll tot = 0;
	for(int i=0;i<n;i++) {
		for(int j=0;j<n;j++) {
			//printf("%lld %d %d\n",dp[i][j][n],i,j);
			tot += dp[n][i][j];
			tot += dp[i][j][n];
			tot += dp[i][n][j];
		}
	}
	tot %= M;
	cout << tot << '\n';
}


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

#define _GLIBCXX_DEBUG
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())




// ループ系
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)

#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)

// #define fou(i,a,n) for(int i=a;i<n;i++)
#define elif(c) else if(c)


// 出力系
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}

ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}

const ll MAX=1000000007,MAXL=1LL<<61,dx[8]={-1,-1,-1,0,0,1,1,1},dy[8]={-1,0,1,-1,1,-1,0,1};

typedef pair<int,int> P;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> VP;
typedef vector<PL> VPL;
typedef vector<string> VS;





void Main() {
    int n, a;

    cin >> n >> a;
    if (n%500 <= a) pr("Yes");
    else pr("No");

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

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

const double PI = 3.14159265358979323846;
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
//typedef pair<ll, ll> P;
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

std::istream &operator>>(std::istream &in, set<int> &o) {
    ll a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

//const ll mod = 1e10;
typedef priority_queue<string, vector<string>, greater<string> > PQ_ASK;

#include <iostream>
#include <vector>

using namespace std;

const int mod = 1000000007;


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

    vector<ll> shrine(a), temples(b);
    rep(i, a) cin >> shrine[i];
    rep(i, b) cin >> temples[i];

    auto f = [](vector<ll> &v, ll x) {
        P p;
        auto it = lower_bound(v.begin(), v.end(), x);
        if (it == v.end()) {
            it--;
            p.first = x - *it;
            p.second = INF;
            return p;
        }
        if (it == v.begin()) {
            p.first = INF;
            p.second = *it - x;
            return p;
        }
        p.second = *it - x;
        it--;
        p.first = x - *it;
        return p;
    };

    rep(i, q) {
        ll x;
        cin >> x;
        P s = f(shrine, x);
        P t = f(temples, x);
        assert(s.first >= 0);
        assert(s.second >= 0);
        assert(t.first >= 0);
        assert(t.second >= 0);

        ll ans = INF;
        cmin(ans, max(s.second, t.second));
        cmin(ans, max(s.first, t.first));
        cmin(ans, min(s.first, t.second) * 2 + max(s.first, t.second));
        cmin(ans, min(s.second, t.first) * 2 + max(s.second, t.first));

        cout << ans << endl;
    }

}


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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

typedef long long ll;
typedef long double R;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

// Problem Specific Parameter:

int main() {
  int H, W; cin >> H >> W;
  int h, w; cin >> h >> w;
  int d = min(h, w) * min(h,w);
  cout << (H*W) - (H*w+W*h-w*h) << endl;

  return 0;
}


Measured memory_bytes: 256
from collections import deque
N = int(input())
A = list(map(int,input().split()))
balls = [[] for _ in range(N+1)]
for i in range(N):
  balls[A[i]].append(i)
  
K = 0  
for i in range(N+1):
  if len(balls[i]) < 2:
    continue
  else:
    u = len(balls[i])
    K += int(u*(u-1)/2)
  
t = 0
q = deque()
for i in range(N):
  s = A[i]
  a = len(balls[s])
  if a >=2:
    d = a-1
  else:
    d = 0
  q.append(K-d)


while q:
  v = q.popleft()
  print(v)

  

Measured memory_bytes: 46140
#include <stdio.h>
int main(void) {
  int a[10000], n, i, min, max;
  long long sum = 0;
  scanf("%d\n", &n);
  for(i=0; i<n; i++){
    scanf("%d", &a[i]);
    sum += a[i];
    }
    max = min = a[0];
    for(i = 1; i < n; i++){
      if(a[i] > max)max = a[i];
	if(a[i] < min)min = a[i];
    }
    printf("%d %d %lld\n", min, max, sum);

    return 0;
}


Measured memory_bytes: 2120
#include<bits/stdc++.h>
using namespace std;
#define N 111116

int n,k,a[N],d[N],f[N],ans;
queue<int> q;

int read(){
	int x=0,f=1;char ch=getchar();
	for (;!isdigit(ch);ch=getchar()) if (ch=='-')  f=-f;
	for (;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
	return x*f;
}

int main(){
	n=read();k=read();
	for (int i=1;i<=n;i++) a[i]=read();
	for (int i=2;i<=n;i++) d[a[i]]++;
	if (a[1]!=1) ans++;
	for (int i=1;i<=n;i++) if (!d[i]) q.push(i);
	while (!q.empty()){
		int t=q.front();q.pop();
		if (f[t]==k-1&&t!=1&&a[t]!=1) ans++;
		else f[a[t]]=max(f[a[t]],f[t]+1);
		if (--d[a[t]]==0) q.push(a[t]);
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<cstdlib>
#include<cmath>
#define ll long long
#define int long long

using namespace std;

int x;

signed main()
{
	cin >> x;
	int y;
	y = x;
	int j = 0;

	for (int i = 0; y > 0;i++) {
		y = y/10;
		j++;
	}

	int M = 1000000000;

	for (int i = 0; i < j - 2; i++) {
		int z;
		z = x;
		int a,b,c;
		b = z / pow(10, i);
		c = 1000;
		a = abs(b % c - 753);

		if (a < M) {
			M = a;
		}
	}


	cout << M << endl;


    return 0;
}



Measured memory_bytes: 384
n, q = map(int, input().split())
s = input()
li_lr = list()

li_flg = [0] * len(s)

for i in range(q):
    li_lr.append(list(map(int, input().split())))


for idx, v in enumerate(s):
    if v == 'C' and idx != 0 and s[idx - 1] == 'A':
        li_flg[idx] = li_flg[idx - 1] + 1
    else:
        li_flg[idx] = li_flg[idx - 1]

for l in li_lr:
    print(li_flg[l[1] - 1] - li_flg[l[0] - 1])



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

#define FOR(i,N) for(int i=0;i<N;i++)

int main(){
    long long H,W,Q,M,X,K,N,x,cnt=0,min=-1,max=0,sum=0;
    cin >> N >> M >> X;
    vector<long>C(N),lv(M,0);
    vector<vector<long>>A(N,vector<long>(M));
    FOR(i,N){
        cin >> C[i];
        FOR(j,M){
            cin >> A[i][j];
        }
    }
    FOR(is,1<<N){
        long value=0;
        FOR(i,N){
            if(is & (1<<i)){
                FOR(k,M){
                    lv[k] += A[i][k];
                }
                value += C[i];
            }
        }
        FOR(i,M){
            if(lv[i]<X)break;
            if(i==M-1){
                if(min == -1 || (min > value))min=value;
            }
        }
        FOR(i,M)lv[i]=0;
    }
    cout << min;
}


Measured memory_bytes: 3636
using System;
using static System.Console;
using static System.Math;
using System.IO;
using System.Collections.Generic;
namespace I_am_the_green_coder{
    class Inonoa{
        static void Main(){
            char[] yosou = IChars();
            char[] jissai = IChars();
            int ans = 0;
            for(int i=0;i<3;i++){
                if(yosou[i]==jissai[i])ans ++;
            }
            WriteLine(ans);
        }

        static readonly long MOD = 1000000007;

        ///<summary>a_1, a_2, a_3, ...みたいなの</summary>
        static long[] ILongs(){
            string[] s = ReadLine().Split();
            long[] re = new long[s.Length];
            for(long i=0;i<s.Length;i++){
                re[i] = long.Parse(s[i]);
            }
            return re;
        }

        ///<summary>xooxoxoxxoxo...みたいなの</summary>
        static char[] IChars(){
            return ReadLine().ToCharArray();
        }

        ///<summary>n m とかをちょっとはやくかくだけ</summary>
        static string[] IStrings(){
            return ReadLine().Split();
        }

        ///<summary>n行の入力を取ったり</summary>
        static long[][] ILongLongs(long n){
            long[][] re = new long[n][];
            for(long i=0;i<n;i++){
                string[] s = ReadLine().Split();
                re[i] = new long[s.Length];
                for(long j=0;j<s.Length;j++){
                    re[i][j] = long.Parse(s[j]);
                }
            }
            return re;
        }

        ///<summary>n行の文字列を取ったり</summary>
        static char[][] ICharsChars(long n){
            char[][] re = new char[n][];
            for(long i=0;i<n;i++){
                re[i] = ReadLine().ToCharArray();
            }
            return re;
        }
    }
}

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

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
#define rep2(i,s,n) for(long long i=(s); i<(long long)(n);i++)
#define mod 1000000007
typedef long long ll;

int main() {
    ll n,p;cin>>n>>p;
    bool jdg=true;

    rep(i,n){
        ll a;cin>>a;
        if(a%2!=0){
            jdg=false;
        }
    }

    if(jdg){
        if(p==0){
            ll ans=pow(2,n);
            cout<<ans<<endl;
        }
        else {
            cout<<0<<endl;
        }
    }
    else {
        ll ans=pow(2,n-1);
        cout<<ans<<endl;
    }
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long int
void solve(){
  int N, X, T;
  cin>>N>>X>>T;
  int ans = (N/X) + (N%X!=0);
  cout<<ans*T<<endl;
}
signed main(){
  // int t;
  // cin>>t;
  // while(t--)
    solve();
}


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

int main() {
    int a, b;
    cin >> a >> b;
    int ans = 0;
    if(a > b) {
        ans += a;
        a--;
    } else {
        ans += b;
        b--;
    }
    if(a > b) {
        ans += a;
        a--;
    } else {
        ans += b;
        b--;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define BPhuong "vsteps"
#define maxn 1000009
#define maxm
#define bit(x, i) ((x>>i)&1)
#define fid(i,a,b) for(int i = a; i>=b; i--)
#define fi(i,a,b) for(int i=a;i<=b;i++)
#define pii pair<int, int>
#define ll long long
#define f first
#define se second
#define pb push_back
using namespace std;
int n, k, a[maxn], q[maxn];
ll f[maxn];
void nhap(){
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);cout.tie(NULL);
    srand(time(NULL));
      cin >> n >> k;
    fi(i, 1, n) cin >> a[i];
}
void xuli(){
    fi(i, 2, n) f[i] = 2e9;
    f[1] = 0;
    fi(i, 2, n){
        fid(j, i-1, max(1, i-k)){
            f[i] = min(f[i], f[j]+ abs(a[i]-a[j]));
        }
    }
    cout << f[n];
}
int main(){
    nhap();
    xuli();
}


Measured memory_bytes: 4796
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long int
#define rep(i, n) for(int i = 0; i < n; i++)
#define sort(v) sort((v).begin(), (v).end())
using vi = vector<int>;
using vs = vector<string>;
using vll = vector<ll>;
const int MOD = 1e9+7;

int main() {
	int H,W;
  	cin >> H >> W;
  	vs a(H);
  	rep(i,H){
      	cin >> a[i];
    	a[i] = "#" + a[i];
      	a[i] = a[i] + "#";
    }
  	string s="";
  	rep(i,W+2) s = s + "#";
  	cout << s << endl;
  	rep(i,H) cout << a[i] << endl;
  	cout << s << endl;
}

Measured memory_bytes: 256
from collections import *
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def main():
    def dfs(u=0,pu=-1,pc=-1):
        c=1
        for i,cu in to[u]:
            if cu==pu:continue
            if c==pc:c+=1
            ans[i]=c
            dfs(cu,u,c)
            c+=1

    to=defaultdict(list)
    n=int(input())
    for i in range(n-1):
        a,b=map(int1,input().split())
        to[a].append([i,b])
        to[b].append([i, a])
    ans=[-1]*(n-1)
    dfs()
    print(max(ans))
    print(*ans,sep="\n")

main()

Measured memory_bytes: 93148
#include <iostream>
#include <vector>
#include <cstring>

int main(void) {
  int N;
  std::cin >> N;

  // 入力の受け取り
  std::vector<int> a(N), b(N), c(N);
  for (int i = 0; i < N; i++) {
    std::cin >> a[i] >> b[i] >> c[i];
  }

  // DP
  int dp[100002][3];
  memset(dp, 0, sizeof(dp));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < 3; j++) {
      dp[i + 1][0] =
        std::max({
          dp[i + 1][0],
          dp[i][1] + a[i],
          dp[i][2] + a[i] 
        });

      dp[i + 1][1] =
        std::max({
          dp[i + 1][1],
          dp[i][0] + b[i],
          dp[i][2] + b[i] 
        });

      dp[i + 1][2] =
        std::max({
          dp[i + 1][2],
          dp[i][0] + c[i],
          dp[i][1] + c[i]
        });
    }
  }
  std::cout << std::max({dp[N][0], dp[N][1], dp[N][2]}) << std::endl;

  return 0;
}

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

#define REP(i,n) for(int i=0;i<(n);++i)
#define ll long long
const long long INF = 1LL<<60;
const long long mod = 1e9 + 7;

int main(){
    string S;
    cin >> S;
    int ans = 0;
    REP(i,S.size()){
        if(S[i] == '-') ans--;
        else ans++;
    }
    cout << ans << endl;
}

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

int main(){
    int n;
    cin >> n;
    string s;
    switch(n % 10){
        case 2:
        case 4:
        case 5:
        case 7:
        case 9:
            s = "hon";
            break;
        case 0:
        case 1:
        case 6:
        case 8:
            s = "pon";
            break;
        case 3:
        s = "bon";
        break;
    }
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 3132