akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
#define mk make_pair
#define int long long
using namespace std;
string s[110];
vector<pair<pair<int,int>,char> >v;
int h,w,l,x,y,syuki,pp;
char t;
int used[101][101][25];
void dig(){
  int sum=1;
  while(1){
    int p=0;
    if(used[y][x][(int)t-'C']){
      syuki=sum-used[y][x][t-'C'];
      pp=sum-syuki;
      break;
    }
    used[y][x][t-'C']=sum;
    if(t=='N'){
      if(s[y-1][x]=='#')t='E',p++;
      else y--;
    }
    else if(t=='E'){
      if(s[y][x+1]=='#')t='S',p++;
      else x++;
    }
    else if(t=='S'){
      if(s[y+1][x]=='#')t='W',p++;
      else y++;
    }
    else{
      if(s[y][x-1]=='#')t='N',p++;
      else x--;
    }
    if(!p)v.push_back(mk(mk(y,x),t)),sum++;
    
  }
}
main(){
  while(cin>>h>>w>>l,w){
    r(i,h+2)s[i]="";
    r(i,h)cin>>s[i+1];
    r(i,w+2)s[0]+='#',s[h+1]+='#';
    r(i,h)s[i+1]='#'+s[i+1]+'#';
    v.clear();
    memset(used,0,sizeof(used));
    r(i,h+2)r(j,w+2)if(isalpha(s[i][j]))x=j,y=i,t=s[i][j];
    dig();
    int a=syuki;
    if(l<v.size())cout<<v[l-1].first.first<<' '<<v[l-1].first.second<<' '<<v[l-1].second<<endl;
    else{
      while((int)v.size()>syuki)v.erase(v.begin());

      cout<<v[(l-pp)%a].first.first<<' '<<v[(l-pp)%a].first.second<<' '<<v[(l-pp)%a].second<<endl;
    }
  }
}

Measured memory_bytes: 5264
#include<stdio.h>

int main()
{
	int a[4],b[4];
	int i,j,en=0,a1,a2;
	char c;

	while(1)
	{
		for(i=0;i<4;i++)
		{
			if(scanf("%d%c",a+i,&c) == EOF)
			{
				en=1;
				break;
			}
		}
		for(i=0;i<4;i++)
		{
			if(scanf("%d%c",b+i,&c) == EOF)
			{
				en=1;
				break;
			}
		}
		if(en)
			break;
		a1=0;
		a2=0;
		for(i=0;i<4;i++)
		{
			for(j=0;j<4;j++)
			{
				if(b[i]==a[j])
				{
					if(i==j)
						a1++;
					else
						a2++;
				}
			}
		}
		printf("%d %d\n",a1,a2);
		en=0;
	}
	return 0;
}

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

using ll = long long;
using ld = long double;
using vl = vector<ll>;
using ml = map<ll,ll>;

#define ff first
#define ss second
#define endl '\n'
#define ins insert
#define eb emplace_back
#define sz(c) (ll) c.size()
#define all(c) begin(c), end(c)
#define rall(c) rbegin(c), rend(c)
#define itr(x,c) for(auto &x : c)
#define tc ll t; cin >> t; while(t--)
#define rep(i,a,n) for(ll i = a ; i < n ; ++i)
#define per(i,a,n) for(ll i = n-1 ; i >= a ; --i)
#define dx(x) cout << #x << ": " << x << endl;
#define dc(c) itr(x,c) cout << x << " "; cout << endl;
#define dm(m) itr(x,m) cout << x.ff << " -> " << x.ss << endl;
#define godspeed cin.tie(0) -> sync_with_stdio(0);

int main() {
    godspeed;
    ll n; cin >> n; 
    if(n >= 30) cout << "Yes"; else cout << "No";
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef string str;
const long long INF = INT64_MAX;

#define REP(i, n) for(ll i=0;i<n;i++)
#define ASC(v) sort((v).begin(), (v).end())
#define DESC(v) sort((v).rbegin(), (v).rend())
#define INV(v) reverse((v).rbegin(), (v).rend())
#define FOLDL(src, dst, lambda) partial_sum((src).begin(), (src).end(), (dst).begin(), lambda)
#define FOLDR(src, dst, lambda) INV(src);partial_sum((src).begin(), (src).end(), (dst).begin(), lambda);INV(dst)
#define CUMSUML(src, dst) FOLDL(src, dst, [](auto a, auto b) {return a+b;})
#define CUMSUMR(src, dst) FOLDR(src, dst, [](auto a, auto b) {return a+b;})
#define ACCUM(v, d0, lambda) accumulate((v).begin(), (v).end(), d0, lambda)
#define SUM(v, d0) ACCUM(v, d0, [](auto a, auto b) {return a+b;})
#define DESC(v) sort((v).rbegin(), (v).rend())
#define ERASE(v, i) v.erase(v.begin() + i)
#define UNIQ(v) ASC(v);erase(unique(v.begin(), v.end()), v.end())
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);

void solve() {
    ll N;
    cin >> N;
    vll A(N);
    for(auto &a:A) cin >> a;
    cout << (SUM(A, 0) % 2 == 0 ? "YES" : "NO") << endl;
}

int main() {
    FIO;
    solve();
    return 0;
}


Measured memory_bytes: 1024
// Crt. 2020-01-09  11:20-12:10,14:20-
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#define lowbit(S) (S & (-S))
#define N 15
using namespace std;
typedef long long ll;

template <typename T> inline void cmin(T &x, const T &y) {
    if (y < x) x = y;
}

template <typename T> inline void cmax(T &x, const T &y) {
    if (x < y) x = y;
}

inline int highbit(int x) {
    int res = 0;
    while (x) x -= (res = lowbit(x));
    return res;
}

int n, m, sz, l2[1 << N], dis[N][N];
ll f[1 << N][N], g[1 << N];

int main(){
#ifdef LOCAL_JUDGE
    freopen("work.in", "r", stdin);
    freopen("work.out", "w", stdout);
#endif

    cin >> n >> m, sz = 1 << n;

    for (int i = 2; i < sz; ++i)
        l2[i] = l2[i / 2] + 1;

    ll sum = 0;
    for (int i = 1, u, v, w; i <= m; ++i)
        scanf("%d%d%d", &u, &v, &w), --u, --v, sum += dis[u][v] = dis[v][u] = w;

    for (int S = 1; S < sz; ++S)
        for (int i = 0; i < n; ++i) if ((S >> i) & 1)
            for (int j = i + 1; j < n; ++j) if ((S >> j) & 1)
                g[S] += dis[i][j];

    memset(f, -0x3f, sizeof f);
    f[1][0] = 0;
    for (int S = 1; S < sz; ++S) {
        for (int Ss = S, i; Ss; Ss -= lowbit(Ss)) {
            i = l2[lowbit(Ss)];
            for (int T = S; T; T = (T - 1) & S)
                if ((T >> i) & 1) cmax(f[S][i], f[(S ^ T) | (1 << i)][i] + g[T]);
            for (int j = 0; j < n; ++j) if (!((S >> j) & 1))
                if (dis[i][j]) cmax(f[S | (1 << j)][j], f[S][i] + dis[i][j]);
        }
    }

    ll ans = f[0][0]; 
    for (int i = 1; i < sz; ++i)
        if ((i >> (n - 1)) & 1) cmax(ans, f[i][n - 1]);

    cout << sum - ans << endl;

    return 0;
}


Measured memory_bytes: 4480
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "iomanip"
#include "cmath"

using namespace std;

const long long int MOD = 1000000007;

long long int N, M, K, H, W, L, R;

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

	cin >> N;
	vector<int>range(N+1);
	vector<int>speed(N+1);
	for (int i = 1; i <= N; i++) {
		cin >> range[i];
		M += range[i];
	}
	for (int i = 1; i <= N; i++) {
		cin >> speed[i];
	}
	speed.push_back(0);
	vector<vector<long double>>dp(N + 1, vector<long double>(101,-10000000));
	dp[0][0] = 0;
	for (int i = 1; i <= N; i++) {
		for (int j = 0; j <= min(speed[i], speed[i + 1]);j++) {
			for (int k = 0; k <= min(speed[i - 1], speed[i]); k++) {
				if (abs(j - k) > range[i]) {
					continue;
				}
				long double add = 0;
				add += (j + k)*abs(j - k) * 2;
				add += (4 * max(k,j) + range[i] - abs(j - k))*(range[i] - abs(j - k));
				if (2 * speed[i] < 2 * max(k,j) + range[i] - abs(j - k)) {
					add -= (2 * max(k,j) + range[i] - abs(j - k) - 2 * speed[i])*(2 * max(k,j) + range[i] - abs(j - k) - 2 * speed[i]);
				}
				add /= 4;
				dp[i][j] = max(dp[i][j], dp[i - 1][k] + add);
			}
		}
	}
	cout <<setprecision(15)<< dp[N][0] << endl;
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++ (i))
#define REP_R(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define REP3R(i, m, n) for (int i = (int)(n) - 1; (i) >= (int)(m); -- (i))
#define REPP(i, n) for (int i = 1; (i) < (int)(n+1); ++ (i))
#define REPR(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i=(m)-1; i>=(n); i--)
#define ALL(v) v.begin(), v.end()
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())
#define SORTR(c) sort((c).begin(),(c).end(),greater<int>());
#define BIT(n) (1LL<<(n))
#define PCNT(x) __builtin_popcountll(x)
#define GCD(x,y) __gcd(x,y)
#define LCM(x,y) x/__gcd(x,y)*y
#define PB push_back
#define MP make_pair
#define endl "\n"
#define pa cout << ans << endl
#define p(x) cout << x << endl
#define pall(x) for(auto iter : x) p(iter)
#define yes cout << "Yes" << endl
#define no cout << "No" << endl
#define yn(x) cout << (x ? "Yes" : "No") << endl
using namespace std;
using Graph = vector<vector<int> >;
using WeightedGraph = vector<vector<pair<int, int> > >;
typedef long double LD;
typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
const int INF = 2000000000;
const long double PI = acosl(-1);
const int MOD = 1000000007;
void print() {cout << endl;}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head; if (sizeof...(tail) != 0) cout << " ";print(forward<Tail>(tail)...);}
template <class T> void print(vector<T> &vec) {for (auto& a : vec) {cout << a; if (&a != &vec.back()) cout << " ";} cout << endl;}
template <class T> void print(vector<vector<T>> &df) { for (auto& vec : df) { print(vec);}}


signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout << fixed << setprecision(10);
    int ans = 0;
    
    int H, W, K;
    cin >> H >> W >> K;
    vector<vector<char> > c(H, vector<char>(W));

    REP (i, H) {
        REP (j, W) {
            cin >> c[i][j]; 
        }
    }

    int count = 0;

    REP(bit, 1<<(H+W)) {
        count = 0;
            REP(i,H) {
                if (bit & (1<<i)) {
                    REP(j,W) {
                        if ((bit>>H) & (1<<j)) {
                            if (c[i][j] == '#') count++;
                        }
                    }
                }
            }
        if (count == K) ans++;
    }

    cout << ans << endl;


    
    
    
    return 0;
}

/*
cd ~/Desktop/Programming/AtCoder/contest/abc173/abc173_c && sh shellscripts/test_cpp.sh
cd ~/Desktop/Programming/AtCoder/contest/abc173/abc173_c && sh shellscripts/etest_cpp.sh
cd ~/Desktop/Programming/AtCoder/contest/abc173/abc173_c && sh shellscripts/submit_cpp.sh
*/


Measured memory_bytes: 3644
#include <bits/stdc++.h>
 
using namespace std;
 
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define fileio freopen("in.in", "r", stdin),freopen("out.out", "w", stdout);
#define ll long long int
#define FF first
#define SS second
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<long long int,long long int>
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d\n",x)
#define plld(x) printf("%lld\n",x)
#define pss printf
#define MOD 1000000007
#define INF 1e18
#define eps 0.00001
#define endl '\n'
#define debug(n1) cout<<n1<<endl
ll n,c,k;
ll a[100005];
int main() {
slld(n);slld(c);slld(k);
for(int i=1;i<=n;i++)
slld(a[i]);
sort(a+1,a+n+1);
ll ans=1,cur=1;
for(int i=2;i<=n;i++)
{
	if(i-cur+1>c||a[i]>a[cur]+k)
	{
		ans++;
		cur=i;
	}
}
plld(ans);



	return 0;
           } 

Measured memory_bytes: 1024
#include <stdio.h>

int A[1000000], n;

/* 二分探索 */
int binarySearch(int key) {
  int left = 0;
  int right = n;
  int mid;
  while(left < right) {
    mid = (left + right) / 2;
    if(key == A[mid]) return 1; /* keyを発見 */
    if(key > A[mid]) left = mid + 1; /* 後半を探索 */
    else if(key < A[mid]) right = mid; /* 前半を探索 */
  }
  return 0;
}

int main(void) {
  int i, q, k, sum = 0;
  scanf("%d",&n);
  for(i=0; i<n; i++) {
    scanf("%d",&A[i]);
  }
  scanf("%d",&q);
  for(i=0;i<q;i++) {
    scanf("%d",&k);
    if(binarySearch(k))
      sum++;
  }
  printf("%d\n",sum);
  return 0;
}


Measured memory_bytes: 2104
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.WebSockets;

namespace AtCoderApp
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ');
            var S = int.Parse(input[0]);
            var W = int.Parse(input[1]);

            if (W >= S)
            {
                Console.WriteLine("unsafe");
            }
            else
            {
                Console.WriteLine("safe");
            }
        }
    }
}


Measured memory_bytes: 27524
package main

import "fmt"

func main() {
	// 下3桁の場合 下三桁だけとったら111で割り切れる
	// 上3桁の場合 上三桁だけとったら同上
	var n int
	fmt.Scan(&n)
	simo := (n - (n / 1000)) % 111
	kami := (n / 10) % 111
	if simo == 0 || kami == 0 {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 512
#include<string>
#include<iostream>
#include<algorithm>
#include<set>
using namespace std;
int main(){
  std::ios_base::sync_with_stdio(false);
  set<string> st;
  int n;
  cin >> n;
  while(n--){
    string BUFF,c;
    cin >> BUFF >> c;
    if(BUFF=="insert") st.insert(c);
    else cout << (st.find(c)!=st.end()?"yes":"no") << endl;
  }
}

Measured memory_bytes: 27056
#include <iostream>
#include <fstream>
#include <numeric>
#include <stdio.h>
#include <cmath>
#include <queue>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <deque>
#include <bitset>
#include <cstring>
#include <sstream>
#include <complex>
 
#define f first
#define s second
#define ll long long
#define ld double
#define pb push_back
#define all(x) x.begin(),x.end()
#define mp make_pair
#define y0 eto
#define y1 mezhdy
#define y2 nami
#define left extermination
#define right dismemberment
 
using namespace std;
 
void runtime(){cout<<fixed<<setprecision(5)<<1.0*clock()/CLOCKS_PER_SEC<<endl;}

typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

template <class T>void read(vector<T> &a,int n){T x; a.clear();for(int i=0;i<n;i++){cin>>x;a.pb(x);}}
template <class T>void write(vector<T> &a){for(T x : a) cout<<x<<' ';cout<<'\n';}

const int N=200005;

int n,m;
vector<int> g[N];
int p[N];


int main()
{
    ios_base::sync_with_stdio(0);
//    freopen("INPUT.txt","r",stdin);
    
    memset(p,-1,sizeof(p));
    
    cin>>n>>m;
    
    for(int i=0;i<m;i++)
    {
        int a,b;
        cin>>a>>b;
        g[a].pb(b);
        g[b].pb(a);
    }
    
    queue<int> q;
    q.push(1);
    p[1]=0;
    
    while(q.size())
    {
        int u=q.front();
        q.pop();
        
        for(int i=0;i<g[u].size();i++)
            if(p[g[u][i]]==-1)
            {
                p[g[u][i]]=u;
                q.push(g[u][i]);
            }
    }
    
    cout<<"Yes\n";
    for(int i=2;i<=n;i++)
        cout<<p[i]<<'\n';
}


Measured memory_bytes: 12692
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include<algorithm>

using namespace std;



int main() {
	int n;
	cin >> n;
	vector<int> h(n);
	for (int i = 0; i < n; i++) {
		cin >> h[i];
	}

	h.emplace_back(0);
	int h_r = 0;
	int cnt = 0;
	for (int i = 0;i <=n; i++) {
		if (h[i] < h_r) {
			cnt += h_r - h[i];
		}
		h_r = h[i];
	}

	cout << cnt << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int n,i;
  long long m=0,a=0,r=0,c=0,h=0,count=0;
  scanf("%d",&n);
  char s[n+1][11];
  for(i=0;i<n;i++){
    scanf("%*c%s",s[i]);
    if(s[i][0]=='M') m++;
    if(s[i][0]=='A') a++;
    if(s[i][0]=='R') r++;
    if(s[i][0]=='C') c++;
    if(s[i][0]=='H') h++;
  }
  count=m*a*(r+c+h)+m*r*(c+h)+m*c*h+a*r*(c+h)+a*c*h+r*c*h;
  printf("%lld\n",count);
  return 0;
}


Measured memory_bytes: 2772
def upperbound(ar, value):
    low = 0
    high = len(ar)
    while low < high:
        mid = (low + high) >> 1
        if value > ar[mid]:
            low = mid + 1
        else:
            high = mid
    return low


s = input()
t = input()
data = {}
for index, val in enumerate(s):
    if val not in data:
        data[val] = [index]
    else:
        data[val].append(index)
ok = True
index = 0
mod = len(s)
pos = [0] * (len(t))
for i, c in enumerate(t):
    if c not in data:
        ok = False
        break
    else:
        curr_index = upperbound(data[c], index)
        if curr_index >= len(data[c]):
            pos[i] = data[c][0]
        else:
            pos[i] = data[c][curr_index]
        index = (pos[i] + 1) % mod
if ok:
    result = pos[0] + 1
    for i in range(1, len(t)):
        if pos[i] > pos[i - 1]:
            result = result + (pos[i] - pos[i - 1])
        else:
            result = result - (pos[i - 1] + 1) + mod + pos[i] + 1
    print(result)
else:
    print(-1)

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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using P = pair<int, int>;

const int INF = 1e9;
const ll INFLL = 1e18;
const int MOD = 1e9 + 7;
const int NIL = -1;
const ld PI = acosl(-1);

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

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

int main()
{
	ios::sync_with_stdio(false); cin.tie(nullptr);
	//cout << fixed << setprecision(6);
	int n, m;
	cin >> n >> m;

	cout << (n == m ? "Yes" : "No") << endl;
	return 0;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc117/tasks/abc117_d

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define REP(i,n)   for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)
#define DUMP(a, n) REP(_i, n) printf("%d%c", a[_i], _i + 1 == n ? '\n' : ' ')
#define DUMP2D(a, n, m) REP(_i, n) REP(_j, m) printf("%d%c", a[_i][_j], _j + 1 == m ? '\n' : ' '); puts("")
#define DUMPLL(a, n) REP(_i, n) printf("%lld%c", a[_i], _i + 1 == n ? '\n' : ' ')
#define DUMP2DLL(a, n, m) REP(_i, n) REP(_j, m) printf("%lld%c", a[_i][_j], _j + 1 == m ? '\n' : ' '); puts("")

const int N_MAX = 1e5;
const ll K_MAX = 1e12;
const ll A_I_MAX = 1e12;
const int BIT_LEN = 40;

int N;
ll K;
ll A[N_MAX];

int bs[BIT_LEN];
ll cs[2];
ll us[BIT_LEN + 1];
ll ms[BIT_LEN];
ll ds[BIT_LEN + 1];

void solve() {
  REP(i, BIT_LEN) {
    bs[i] = K >> i & 1;
    cs[0] = cs[1] = 0;
    REP(k, N) {
      if (A[k] >> i & 1) cs[1]++;
      else cs[0]++;
    }
    us[i + 1] = us[i] + (cs[1 - bs[i]] << i);
    ms[i] = cs[1] << i;
    ds[i + 1] = ds[i] + (max(cs[0], cs[1]) << i);
  }

  // printf("bs: "); DUMP(bs, BIT_LEN);
  // printf("us: "); DUMPLL(us, BIT_LEN + 1);
  // printf("ms: "); DUMPLL(ms, BIT_LEN);
  // printf("ds: "); DUMPLL(ds, BIT_LEN + 1);

  ll ans = us[BIT_LEN];
  REP (i, BIT_LEN) {
    if (bs[i]) {
      // printf("i=%d: %lld + %lld + %lld\n", i, us[BIT_LEN] - us[i + 1], ms[i], ds[i]);
      ans = max(ans, us[BIT_LEN] - us[i + 1] + ms[i] + ds[i]);
    }
  }

  printf("%lld\n", ans);
}

void input() {
  scanf("%d%lld", &N, &K);
  REP(i, N) scanf("%lld", A + i);
}

int main() {
  input();
  solve();
  return 0;
}


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

using namespace std;

#define int int64_t

const int maxn = 1e5 + 42;

int n;
vector<pair<int, int>> g[maxn];
int sz[maxn], cnt[maxn], pr[maxn], mn[maxn];

void dfs_sz(int v = 1, int p = 1)
{
    cnt[v] = v;
    sz[v] = 1;
    mn[v] = 1e9;
    for(auto it: g[v])
    {
        int u = it.first;
        int c = it.second;
        mn[v] = min(mn[v], c);
        if(u == p)
            continue;
        pr[u] = c;
        dfs_sz(u, v);
        sz[v] += sz[u];
        if(2 * sz[u] >= n)
            cnt[v] = cnt[u];
    }
}

int ans = 0;

void dfs_h(int v, int p, int h = 0)
{
    ans += 2 * h;
    for(auto it: g[v])
    {
        int u = it.first;
        int c = it.second;
        if(u == p)
            continue;
        dfs_h(u, v, h + c);
    }
}

signed main()
{
    //freopen("input.txt", "r", stdin);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    for(int i = 0; i < n - 1; i++)
    {
        int a, b, c;
        cin >> a >> b >> c;
        g[a].push_back({b, c});
        g[b].push_back({a, c});
    }
    dfs_sz();
    dfs_h(cnt[1], cnt[1]);
    if(2 * sz[cnt[1]] == n)
        ans -= pr[cnt[1]];
    else
        ans -= mn[cnt[1]];
    cout << ans << endl;
}


Measured memory_bytes: 14976
#include<iostream>
#include<algorithm>
using namespace std;
static const int MAX = 200000;

int main()
{
	int R[MAX],n;
	cin >> n;
	for(int i=0;i<n;i++)
		cin >> R[i];
		
	int maxv = -2000000000;  //?????????????¶?????°????????§????
	int minv = R[0];
	
	for(int i=1;i<n;i++){
		maxv = max(maxv,R[i] - minv);  //??´??°?????§???
		minv = min(minv,R[i]);  //????????°??¶??????????°???? 
	} 
	cout << maxv << endl;
	return 0;
}

Measured memory_bytes: 3868
// aribon1-6_d
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define debug(x) cout << #x << ": " << (x) << endl
#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define all(x) x.begin(), x.end()
#define INF ((1 << 16)-1)
#define MOD (1000000007)
#define print(arr, n) REP(i, n) cout << arr[i] << " ";

struct PreMain {PreMain(){std::cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    std::ifstream in("../arg.txt");
    std::cin.rdbuf(in.rdbuf());
#endif

    int N,Y;
    cin >> N >> Y;
    Y /= 1000;

    REP(x, N+1){
        int y = Y - N - 9 * x;
        if (y % 4 != 0 || y / 4  > N || y < 0) continue;
        int z = -Y + 5 * N + 5 * x;
        if (z % 4 != 0 || z / 4  > N || z < 0) continue;
        cout << x << " " << (y / 4) << " " << (z / 4) << endl;
        exit(0);
    }
    cout << -1 << " " << -1 << " " << -1 << endl;

    return 0;
}




Measured memory_bytes: 256
#include<bits/stdc++.h> 
using namespace std;
using ll = long long;
 
int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i=0;i<n;i++){
    cin >> a.at(i);
  }
  sort( a.begin(),a.end() );
  for(int i=0;i<n-1;i++){
    if( a.at(i) == a.at(i+1) ){
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
#include<string>
#include <numeric>
#include <queue>
#include <sstream>
#include <bitset>

using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;

template<typename T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }

template<typename T>
map<T, T> primeFactor(T n) {
	map<T, T> res;
	for (T i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			res[i] ++;
			n /= i;
		}
	}
	if (n != 1) res[n] = 1;
	return res;
}

template<typename T>
bool IsPrimeNumber(T num)
{
	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;
}

long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}


#define in(x) cin >> x
#define out(x) cout << x
#define outn(x) cout << x << '\n'
#define outs(x) cout << x << ' '
#define rep(i,s,e) for(ll i=s;i<e;i++)
#define repeq(i,s,e) for(ll i=s;i<=e;i++)

int main() {
	ll n, k,p,ans=0;
	std::cin >> n >> k;

	vll a(n);
	rep(i, 0, n) {
		std::cin >> a[i];
		if (a[i] == 1) {
			p = i;
		}
	}

	if (n <= k) {
		outn(1);
		return 0;
	}

	if (p > 0) {
		ans += p / (k - 1);
		ll tmp = p % (k - 1);
		if (tmp > 0) {
			ans++;
			p = ans*(k-1);
		}
	}

	ans += (n - p-1) / (k - 1);
	if ((n - p-1) % (k - 1) > 0) {
		ans++;
	}
	outn(ans);

	return 0;
}


Measured memory_bytes: 1024
def solve(S):
    dp = [0]*(2000+1)
    dp[0] = 1
    dp[3] = 1
    MOD = 10**9+7
    for n in range(4, S+1):
        answer = 0
        for c in range(3, n+1):
            answer = (answer + dp[n-c]) % MOD
        dp[n] = answer 
    return dp[S]
print(solve(int(input())))


Measured memory_bytes: 9172
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int mod = 1e9+7;

int main(){
//	Code goes here
	LL n;
	cin>>n;
//	int yen[] = {500, 5, 100,  }
	LL res = 0;
	while(n>=500){
		res+=1000;
		n-=500;	
	}
	while(n>=5){
		res+=5;
		n-=5;
	}
	cout<<res;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>

int main()
{
    std::string S;
    std::cin >> S;

    int ans = 1'000'000'000;
    for (int i = 0; i < S.length() - 2; i++)
    {
        int a = S[i] - '0';
        int b = S[i + 1] - '0';
        int c = S[i + 2] - '0';
        ans = std::min(std::abs(a * 100 + b * 10 + c - 753), ans);
    }

    std::cout << ans << std::endl;
}

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

using namespace std;

template <typename T> T gcd(T x, T y) {
  if (y == 0)
    return x;
  return gcd(y, x % y);
}

template <typename T> T lcm(T x, T y) {
  if (x == 0 || y == 0)
    return 0;
  return x / gcd(x, y) * y;
}

int main() {
  vector<int> ABC(3);
  for (int i = 0; i < 3; i++) cin >> ABC[i];
  int ans = 0;
  while (ABC[0] != ABC[1] || ABC[1] != ABC[2]){
    sort(ABC.begin(), ABC.end());
    if (ABC[1] == ABC[2]){
        ABC[0] += 2;
    }else{
      ABC[0]++;
      ABC[1]++;
    }
    ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
from math import sqrt
n, d = map(int, input().split())
X = []
ans = 0
for _ in range(n):
    x = [int(i) for i in input().split()]
    X.append(x)

for i in range(n):
    for j in range(i+1,n):
        Y = X[i]
        Z = X[j]
        d = sqrt(sum([(y-z)**2 for y,z in zip(Y, Z)]))
        if divmod(d,1)[-1] == 0:
            ans += 1
            
print(ans)

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

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

    int kazu[9][9] = {};
    for(int i = 1; i <= n; i++){
        int x = i, y = i % 10;
        if(y == 0) continue;
        while(x >= 10){
            x /= 10;
        }
        kazu[x-1][y-1]++;
    }

    ll ans = 0;
    for(int i = 0; i < 9; i++){
        for(int j = 0; j < 9; j++){
            ans += kazu[i][j] * kazu[j][i];
        }
    }

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

Measured memory_bytes: 256
fun main(args: Array<String>) {
    readLine()
    val h = readLine()!!.split(' ').map(String::toInt)
    var hmax = 0
    var cnt = 0
    h.forEach {
        if (hmax <= it) {
            hmax = it
            cnt++
        }
    }
    println(cnt)
}


Measured memory_bytes: 38236
#include<bits/stdc++.h>
using namespace std;
long long a, b, c, d;
int main(){
	cin>>a;
	for(int i=0;i<a;i++){
		cin>>b>>c>>d;
		
		if(b>c&&b>d){
			if(((d*d)+(c*c))==(b*b))	
				cout<<"YES"<<endl;
			else
				cout<<"NO"<<endl;
		}
		else if(d>c&&d>b){
			if(((b*b)+(c*c))==(d*d))	
				cout<<"YES"<<endl;
			else
				cout<<"NO"<<endl;
		}
		else if(c>d&&c>b){
			if(((d*d)+(b*b))==(c*c))	
				cout<<"YES"<<endl;
			else
				cout<<"NO"<<endl;
		}
		else
			cout<<"NO"<<endl;
	}
}

Measured memory_bytes: 3076
#include <bits/stdc++.h>
#define ll unsigned long long
using namespace std;
class Graph 
{ 
    int V;    
    list<int> *adj;    
public: 
    Graph(int V);  // Constructor 
  
    // function to add an edge to graph 
    void addEdge(int v, int w);  
  
    // prints BFS traversal from a given source s 
    void BFS(int s);   
}; 
  
Graph::Graph(int V) 
{ 
    this->V = V; 
    adj = new list<int>[V]; 
} 
  
void Graph::addEdge(int v, int w) //How to add edge
{ 
    adj[v].push_back(w); 
} 
  
void Graph::BFS(int s) //BFS 
{ 
   
    bool *visited = new bool[V]; 
    for(int i = 0; i < V; i++) 
        visited[i] = false; 
 
    list<int> queue; 
    visited[s] = true; 
    queue.push_back(s); 
    list<int>::iterator i; 
  
    while(!queue.empty()) 
    { 
        s = queue.front(); 
        cout << s << " "; 
        queue.pop_front(); 
  
        for (i = adj[s].begin(); i != adj[s].end(); ++i) 
        { 
            if (!visited[*i]) 
            { 
                visited[*i] = true; 
                queue.push_back(*i); 
            } 
        } 
    } 
} //To create a graph
//Graph g(4); 
    //g.addEdge(0, 1); 
    //g.addEdge(0, 2); 
int gcd(int x, int y) {
        if (x == 0) {
            return y;
        }
        
        return gcd(y % x, x);
    }


int main()
{
 ll n,a,b;
 cin>>n>>a>>b;
 ll res=(n/(a+b))*a;
 n%=a+b;
 if(n<a)
 res+=n;
 else
 res+=a;
 cout<<res<<"\n";
 
}


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

typedef long long ll;
const int maxn = 3e5 + 9;

int n, m, ans;
vector<int> a[maxn];
int tree[maxn << 2], lazy[maxn << 2];

void PushUp(int p)
{
	tree[p] = tree[p << 1] + tree[p << 1 | 1];
}

void PushDown(int p, int ln, int rn)
{
	lazy[p << 1] += lazy[p];
	lazy[p << 1 | 1] += lazy[p];
	tree[p << 1] += lazy[p] * ln;
	tree[p << 1 | 1] += lazy[p] * rn;
	lazy[p] = 0;
} 
void Modify(int p, int l, int r, int ql, int qr, int val)
{
	if (l >= ql && r <= qr)
	{
		tree[p] += val * (r - l + 1);
		lazy[p] += val;
		return;
	}
	int mid = (l + r) >> 1;
	PushDown(p, mid - l + 1, r - mid);
	if (ql <= mid) Modify(p << 1, l, mid, ql, qr, val);
	if (qr > mid) Modify(p << 1 | 1, mid + 1, r, ql, qr, val);
	PushUp(p);
}
int Query(int p, int l, int r, int ql, int qr)
{
	if (l >= ql && r <= qr)
	{
		return tree[p];
	}
	int mid = (l + r) >> 1;
	PushDown(p, mid - l + 1, r - mid);
	int ans = 0;
	if (ql <= mid) ans += Query(p << 1, l, mid, ql, qr);
	if (qr > mid) ans += Query(p << 1 | 1, mid + 1, r, ql ,qr);
	return ans;
}
int main()
{
	cin>>n>>m;
	for (int i=1;i<=n;i++)
	{
		int l, r;
		cin>>l>>r;
		a[r - l + 1].push_back(l);
	}
	for (int i=1;i<=m;i++)
	{
		ans = n;
		for (int j=i;j<=m;j+=i)
		{
			ans += Query(1, 1, m, j, j);
		}
		for (int j=0;j<a[i].size();j++)
		{
			Modify(1, 1, m, a[i][j], a[i][j] + i - 1, 1);
			n--;
		}
		cout<<ans<<endl;
	}
	return 0;
}


Measured memory_bytes: 15360
#include<bits/stdc++.h>
using namespace std;
#define M 100005
char s[M],t[M];
int sk[26][M],r[26];
int main(){
	scanf("%s%s",s+1,t+1);
	int n=strlen(s+1),m=strlen(t+1);
	for(int i=1;i<=n;++i)sk[s[i]-'a'][++r[s[i]-'a']]=i;
	long long ans=0;
	for(int i=1,st=0;i<=m;++i){
		int p=t[i]-'a';
		if(!r[p]){
			puts("-1");
			return 0;
		}else{
			int v=upper_bound(sk[p]+1,sk[p]+r[p]+1,st)-sk[p];
			if(v<=r[p])ans+=sk[p][v]-st,st=sk[p][v];
			else ans+=n-st+sk[p][1],st=sk[p][1];
		}
	}
	printf("%lld",ans);
}

Measured memory_bytes: 8960
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007

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

int main() {

  int A,B;
  cin >> A >> B;

  int d = gcd(A,B);
  long long ans = (long long)A * B / d;
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
signed main()
{
    int n,m,f=1;
    cin>>n>>m;
    int a[n];
    for(int i=0;i<n;i++)
    {
        a[i]=-1;
    }
    for(int i=0;i<m;i++)
    {
        int s,c;
        cin>>s>>c;
        if(a[s-1]==-1 || a[s-1]==c)
        {
            a[s-1]=c;
        }
        else
        {
            f=-1;
        }
    }
    if(f==-1)
    {
        cout<<-1;
        return 0;
    }
    if(a[0]==0 && n!=1)
    {
        cout<<-1;
        return 0;
    }
    if(a[0]==-1 && n!=1)
    {
        a[0]=1;
    }
    else if(a[0]==-1 && n==1)
    {
        a[0]=0;
    }
    cout<<a[0];
    for(int i=1;i<n;i++)
    {
        if(a[i]==-1)
        {
            a[i]=0;
        }
        cout<<a[i];
    }
}

Measured memory_bytes: 256
def solve():
    x, y = map(int, input().split())
    ans = 0
    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
    if x == 1 and y == 1:
        ans += 400000
    print(ans)



if __name__ == '__main__':
    solve()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
//const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
//const ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
const ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll divceil(ll A, ll B) {return (A + (B - 1)) / B;}
ll myctoi(char C) {return C - '0';}
char myitoc(ll N) {return '0' + N;}
#define FINALANS(A) {cout << (A) << '\n'; exit(0);}

int main()
{
  ll N;
  cin >> N;
  vector<ll> A(N);
  for (ll i = 0; i < N; i++)
  {
    cin >> A.at(i);
  }

  vector<vector<ll>> dp(N + 1, vector<ll>(N + 1));
  for (ll i = 0; i < N; i++)
  {
    dp.at(i).at(i) = 0;
  }

  for (ll len = 1; len <= N; len++)
  {
    for (ll i = 0; i < N; i++)
    {
      ll j = i + len;
      if (j < 0 || N < j)
        continue;

      if ((N - len) % 2 == 0)
      {
        dp.at(i).at(j) = -INF;
        chmax(dp.at(i).at(j), dp.at(i + 1).at(j) + A.at(i));
        chmax(dp.at(i).at(j), dp.at(i).at(j - 1) + A.at(j - 1));
      }
      else
      {
        dp.at(i).at(j) = INF;
        chmin(dp.at(i).at(j), dp.at(i + 1).at(j) - A.at(i));
        chmin(dp.at(i).at(j), dp.at(i).at(j - 1) - A.at(j - 1));
      }
    }
  }

  ll ans = dp.at(0).at(N);
  cout << ans << endl;
}

Measured memory_bytes: 70784
s = input()
n = len(s)

ans = 'Yes'
for i in range(n//2):
  if s[i] != s[-i-1] or s[i] != s[-i-1+int((n-1)/2)] or s[i+int((n+1)/2)] != s[-i-1]:
  	ans = 'No'

print(ans)

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		// スペース区切りの整数の入力
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = a + b;
        if((c >= 10)){
			// 出力
			System.out.println("error");
        }else{
			// 出力
			System.out.println(c);
        }
	}

}


Measured memory_bytes: 22868
import java.io.*;
import java.math.*;
import java.util.*;

public class Main {
    private static boolean debug = false;
    private static boolean elapsed = false;

    private static PrintWriter _out = new PrintWriter(System.out);
    private static PrintWriter _err = new PrintWriter(System.err);

    private void solve(Scanner sc) {
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();

        int ans = Math.min(b, d) - Math.max(a, c);
        if (ans < 0) {
            ans = 0;
        }
        _out.println(ans);
    }
    private static BigInteger C(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        for (long i = r; i > 1; --i) {
            res = res.divide(BigInteger.valueOf(i));
        }
        return res;
    }
    private static BigInteger P(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        return res;
    }
    /*
     * 10^10 > Integer.MAX_VALUE = 2147483647 > 10^9
     * 10^19 > Long.MAX_VALUE = 9223372036854775807L > 10^18
     */
    public static void main(String[] args) {
        long S = System.currentTimeMillis();

        Scanner sc = new Scanner(System.in);
        new Main().solve(sc);
        _out.flush();

        long G = System.currentTimeMillis();
        if (elapsed) {
            _err.println((G - S) + "ms");
        }
        _err.flush();
    }
}

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

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(aa, (v).size()) { cout << v[aa]; if (aa != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	map<int, int> mp;
	REP(i, n) {
		int a;
		cin >> a;
		mp[a]++;
	}
	int m;
	cin >> m;
	REP(i, m) {
		int a;
		cin >> a;
		mp[a]--;
	}
	int f = 1;
	for (auto a : mp) {
		if (a.second < 0)f = 0;
	}
	if (f)cout << "YES" << endl;
	else cout << "NO" << endl;

}


Measured memory_bytes: 9600
//raja1999
 
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2")
 
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string> 
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip> 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
//setbase - cout << setbase (16)a; cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 <<endl;prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val
 
using namespace std;
using namespace __gnu_pbds;
#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >
//#define int ll
 
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
 
 
//std::ios::sync_with_stdio(false);
 int arr[200005];
 vi v;
 int k;
int main(){
	std::ios::sync_with_stdio(false); cin.tie(NULL);
	int n=100000,i,t,l,r,fl=0,x;
	cin>>n>>k;
	rep(i,n){
		cin>>x;
		v.pb(x);
	}
	t=k;
	while(t--){	
		fl=0;
		rep(i,v.size()){
			l=max(0,i-v[i]);
			r=min(n-1,i+v[i]);
			arr[l]++;
			arr[r+1]--;
		}
		rep(i,n){
			arr[i]=i>0?arr[i-1]+arr[i]:arr[i];
			v[i]=arr[i];
			if(v[i]!=n){
				fl=1;
			}
		}
		rep(i,n){
			arr[i]=0;
		}
		if(fl==0){
			break;
		}
	}
	rep(i,n){
		cout<<v[i]<<" ";
	}
	cout<<endl;
	return 0;
} 

Measured memory_bytes: 5044
#include<bits/stdc++.h>
using namespace std;
int main() {
	int a, b, c; cin >> a >> b >> c;
	int d[10000];
	for (int e = 0; e < b; e++)scanf("%d", &d[e]);
	sort(d, d + b);
	int mincost = d[b-1]-d[0] + min({abs(d[b-1]-c),abs(c-d[0]),abs(a-(d[b-1]-c)),abs(a-(c-d[0]))});
	for (int i = 0; i < b - 1; i++) {
		mincost = min(mincost, a - (d[i + 1] - d[i]) + min({ abs(d[i] - c),abs(d[i+1]-c),a-(abs(d[i] - c)),a-(abs(d[i + 1] - c))}));
	}
	cout << mincost*100<< endl;
}

Measured memory_bytes: 3220
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <math.h>
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) > (b) ? (b) : (a))
#define Abs(x) ((x) > 0 ? (x) : -(x))
#define REP(i, n) for(int i = 0; i < n; i++)
#define INF 1000000000000 //10^12
#define MOD 1000000007 //10^9 + 7
typedef long long ll;

int
main(int argc, char *argv[])
{
  int h, w, d;
  scanf("%d %d %d", &h, &w, &d);

  int co[90010][2], a;
  REP(i, h)REP(j, w){
    scanf("%d", &a);
    co[a][0] = i;
    co[a][1] = j;
  }

  int u[90010] = {}, p, qq;
  for(int i = 1; i <= d; i++){
    for(int j = 1; i + j * d <= h * w; j++){
      p = i + j * d; qq = p - d;
      u[i + j * d] = u[i + (j - 1) * d]
	+ Abs(co[p][0] - co[qq][0])
	+ Abs(co[p][1] - co[qq][1]);
    }
  }

  int q;
  scanf("%d", &q);
  int l, r, ans;
  REP(i, q){
    scanf("%d %d", &l, &r);
    printf("%d\n", u[r] - u[l]);
  }

  return 0;
}
    


Measured memory_bytes: 2048
#include<stdio.h>
int main()
{
	long long A, B;
	int K;
	scanf("%lld%lld%d", &A, &B, &K);
	for (int i = 0; i < K; i++) {
		if (i % 2 == 0) {
			if (A % 2 == 0) {
				A /= 2;
				B += A;
			}
			else {
				A -= 1;
				A /= 2;
				B += A;
			}
		}
		else {
			if (B % 2 == 0) {
				B /= 2;
				A += B;
			}
			else {
				B -= 1;
				B /= 2;
				A += B;
			}
		}
	}
	printf("%lld %lld", A, B);
}

Measured memory_bytes: 128
s = input().strip()
n = len(s)

ss = []
prev = s[0]
count = 1
for i in range(1, n + 1):
    if i < n:
        c = s[i]
        if c == prev:
            count += 1
            continue
    ss.append(count)
    prev = c
    count = 1

res = []
for r, l in zip(ss[::2], ss[1::2]):
    res += [0] * (r - 1)

    a = (r + l) // 2
    b = r + l - a
    if r % 2 == 0:
        res += [a, b]
    else:
        res += [b, a]
    res += [0] * (l - 1)
print(' '.join(map(str, res)))

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

int main() {
  int N, K;
  cin >> N >> K;
  vector<ll> A(N);
  for (int i = 0; i < N; i++)
  {
    cin >> A[i];
  }

  // if (A[0] < A[K]) {
  //   cout << "Yes" << endl;
  // } else {
  //   cout << "No" << endl;
  // }
  
  for(int i = 0; i < N - K; i++){
    // cerr << i << " "<<A[K+i] * A[i+1] << " " << A[K+i+1] * A[i] << endl;
    if (A[i] < A[K+i])
    {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }  
  }
  
  return 0;
}


Measured memory_bytes: 4840
using System;
using System.Linq;

namespace testes
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');
            int K = int.Parse(str[0]);
            int S = int.Parse(str[1]);

            int ans = 0;
            for(int i = 0; i <= K; i++)
            {
                for(int j = 0; j <= K; j++)
                {
                    int tmp = S - i - j;
                    if (0 <= tmp && tmp <= K) ans++;
                }
            }
            Console.WriteLine(ans);
        }

        public static void func(int L, int R,bool x, bool y)
        {
        }
        public static int LIS(int[] c)
        {
            // 部分数列和
            int count = 1;
            int N = c.Length;
            int[] array = new int[N];
            array[0] = c[0];

            for (int i = 1; i < N; i++)
            {
                //for (int p = 0; p < N; p++) Console.Write($"{array[p]},");
                // Console.WriteLine("");
                if (array[count - 1] < c[i])
                {
                    array[count] = c[i];
                    count++;
                    continue;
                }
                for (int j = count - 2; j >= 0; j--)
                {
                    if (array[j] < c[i])
                    {
                        array[j + 1] = c[i];
                        break;
                    }
                }
                if(array[0] > c[i])array[0] = c[i];
            }
            return count;
        }
        public static void Rotation(char[] array, int l, int r)
        {
           
            
        }


       

    }

    
}

/*
int a, b, c;
a = int.Parse(Console.ReadLine()); //標準入力
string[] str = Console.ReadLine().Split(' ');//2つ以上のスペース区切り入力の取得
b = int.Parse(str[0]);  //数値で受け取りたい場合は変換する
c = int.Parse(str[1]);
string S = Console.ReadLine();
char[] C = new char[N];
C = S.ToCharArray();
Console.Write("改行なし a = {0} b = {1} c = {2}", a, b, c)//改行なし出力
Console.WriteLine("改行あり a = {0} b = {1} c = {2}", a, b, c);//改行付き出力

string[] str = Console.ReadLine().Split(' ');
int[] a = new int[N];
for(int i = 0; i < N; i++) a[i] = int.Parse(str[i]);
 */


Measured memory_bytes: 13140
// https://atcoder.jp/contests/abc116/tasks/abc116_a

#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
#define max(a, b) (((a) > (b)) ? (a) : (b))
#define min(a, b) (((a) < (b)) ? (a) : (b))

int main() {
    int ab, bc, ca;
    cin >> ab >> bc >> ca;

    cout << ab * bc / 2 << endl;

    return 0;
}


Measured memory_bytes: 256
import sys

input = sys.stdin.readline
import fractions


def main():
    N = int(input())
    A = [int(x) for x in input().split()]
    MOD = 10 ** 9 + 7

    x = 1
    for a in A:
        x = (a * x) // fractions.gcd(a, x)

    ans = 0
    for a in A:
        ans += x // a

    print(ans % MOD)


if __name__ == '__main__':
    main()


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

int main() {
	ios::sync_with_stdio(false);
	int n; cin >> n;
	vector<int> a (n);
	for (int i = 0; i < n; ++i) cin >> a[i];
	sort(a.begin(), a.end());
	int low = 0, high = n - 1;
	while (low < high) {
		int mid = (low + high) / 2;
		long long size = a[mid];
		bool ok = true;
		for (int i = 0; ok && i < n; ++i) if (i != mid) {
			if (a[i] > 2 * size) ok = false;
			size += a[i];
		}
		if (ok) high = mid;
		else low = mid + 1;
	}
	cout << n - low << '\n';
	return 0;
}


Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;
int a[1000001];
int main()
{
	long long n, p, lim, gcd = 1ll;
	scanf("%lld%lld", &n, &p);
	if(n == 1)
	{
		printf("%lld\n", p);
		return 0;
	}
	lim = sqrt(p);
	for(long long i = 2; i <= lim && i <= p; )
	{
		if(p % i)
		{
			++i;
		}
		else
		{
			p /= i;
			++a[i];
		}
	}
	for(long long i = 2; i <= lim; ++i)
	{
		for(long long j = a[i] / n; j; --j)
		{
			gcd *= i;
		}
	}
	printf("%lld\n", gcd);
}

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

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
#define int ll

const ll MOD = 1000000007;
const ll INF_LL = (ll)1000000007 * 1000000007;
const int INF_INT = (int)1000000007;
const double PI = 3.14159265358979323846;

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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define irep(itr, st) for (auto itr = (st).begin(); itr != (st).end(); ++itr)
#define irrep(itr, st) for (auto itr = (st).rbegin(); itr != (st).rend(); ++itr)

#define m0(x) memset((x), 0, sizeof((x)))
#define m1(x) memset((x), -1, sizeof((x)))

// xにはvectorなどのコンテナ
#define ALL(x) (x).begin(), (x).end()  // sortなどの引数を省略したい
#define RALL(x) (x).rbegin(), (x).rend()  // sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())     // sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))  //最大値を求める
#define MIN(x) *min_element(ALL(x))  //最小値を求める
#define all(x) (x).begin(), (x).end()

//略記
#define pb emplace_back  // vectorヘの挿入
#define mp make_pair     // pairのコンストラクタ
#define F first          // pairの一つ目の要素
#define S second         // pairの二つ目の要素

#define BITCOUNT __builtin_popcount
#define BITCOUNT_LL(x) __builtin_popcountll(x)

#define perm(c)             \
  sort(all(c));             \
  for (bool c##p = 1; c##p; \
       c##p = next_permutation(all(c)))  //順列 123 132 213 231 312 321

#define BIT(n) (1LL << (n))

#ifdef DEBUG
#define PRINT(A) std::cout << (#A) << ": " << (A) << std::endl;
#else
#define PRINT(A)
#endif

//入力高速化
struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

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

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

signed main() {
  int N;
  cin >> N;
  map<int, int> m;
  rep(i, N) {
    int a;
    cin >> a;
    m[a]++;
  }
  int Q;
  cin >> Q;
  vector<int> ans(Q + 1);

  irep(itr, m) { ans[0] += (*itr).first * (*itr).second; }
  rep(i, Q) {
    int b, c;
    cin >> b >> c;
    ans[i + 1] = ans[i] + m[b] * c - m[b] * b;
    m[c] += m[b];
    m.erase(b);
  }

  rep(i, Q) { cout << ans[i + 1] << endl; }
}

Measured memory_bytes: 7928