akhauriyash/Code-Regression huggingface dataset:
N = int(input())

A = list(map(int, input().split()))
Asum = 0
for i in range(N):
    Asum += [1, -1][i%2]*A[i]*2

rain = Asum//2

ans = [0 for i in range(N)]
for i in range(N):
    ans[i] = rain
    rain = A[i]*2 - rain
print(*ans)

Measured memory_bytes: 14032
#include <bits/stdc++.h>
using namespace std;
void init()
{
    cin.tie(0);
    cin.sync_with_stdio(0);
}
int t;
vector<int>a;
vector<int>b;
vector<int>c;
long long arr[100000][4];
long long  mxvac(int i, int pre)
{
    if(i==t)
    {
        return 0;
    }
    long long &mx=arr[i][pre];
    if(arr[i][pre]!=0)
    {
        return mx;
    }
    mx=0;
    if(pre!=0)
        mx=max(mx,a[i]+mxvac(i+1,0));
    if(pre!=1)
        mx=max(mx,b[i]+mxvac(i+1,1));
    if(pre!=2)
        mx=max(mx,c[i]+mxvac(i+1,2));
    return mx;

}

int main()
{
    init();
    cin>>t;
    a.resize(t);
    b.resize(t);
    c.resize(t);
    for(int i=0; i<t; i++)
        cin>>a[i]>>b[i]>>c[i];
    memset(arr,0,sizeof(arr));
    cout<<mxvac(0,-1);



}


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

map<string,string> board;
map<string,string> word;

void config(){
  string w = "ABCDEFGHIJKLMNOPQRSTUVWXYZ .,-'?";
  string s = "00000";
  string h[] = {"100101","10011010","0101","0001","110","01001","10011011",
		"010000","0111","10011000","0110","00100","10011001",
		"10011110","00101","111","10011111","1000",
		"00110","00111","10011100","10011101",
		"000010","10010010","10010011","10010000",
		"101","010001","000011","10010001","000000","000001"};
  for(int i=0;i<w.size();i++){
    string tmp = "";
    tmp += w[i];
    board[tmp] = s;
    word[h[i]] = w[i];
    /*
    cout << tmp << " " << s << endl;
    cout << h[i] << " " << w[i] << endl << endl;
    */
    if(s[4] == '0') s[4] = '1';
    else {
      for(int j=4;j>=0;j--){
	if(s[j] == '0'){
	  s[j] = '1';
	  break;
	}
	else s[j] = '0';
      }
    }
  }
}

int main(){
  config();
  string str;
  while(getline(cin,str)){
    string next = "";
    for(int i=0;i<str.size();i++){
      string tmp = "";
      tmp += str[i];
      next += board[tmp];
    }
    string ans = "";
    string now = "";
    for(int i=0;i<next.size();i++){
      now += next[i];
      if(word[now] != word["AA"]){
	ans += word[now];
	now = "";
      }
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 1208
#include<bits/stdc++.h>
using namespace std;
#define Set(a,b) memset(a,b,sizeof(a))
template<class T>inline void init(T&x){
	x=0;char ch=getchar();bool t=0;
	for(;ch>'9'||ch<'0';ch=getchar()) if(ch=='-') t=1;
	for(;ch>='0'&&ch<='9';ch=getchar()) x=(x<<1)+(x<<3)+(ch-48);
	if(t) x=-x;return;
}
const int N=601,mod=1e9+7;
typedef long long ll;
template<class T>inline void Inc(T&x,int y){x+=y;if(x>=mod) x-=mod;}
int vis[N];
int a[N];
int dp[2][N][N];
int n;

int main()
{
	init(n);n<<=1;int n1=0,n2=0;
	for(int i=1;i<=n;++i) init(a[i]);
	for(int i=1;i<=n;i+=2){
		if(~a[i]&&~a[i+1]) vis[a[i]]=vis[a[i+1]]=2;
		else if(a[i]!=-1) vis[a[i]]=1,++n1;
		else if(a[i+1]!=-1) vis[a[i+1]]=1,++n1;
		else ++n2;
	}
	int cur=0;int half=n>>1;
	dp[0][0][0]=1;
	for(int i=n;i;--i) {
		if(vis[i]==2) continue;
		cur^=1;Set(dp[cur],0);
		for(int j=0;j<=half;++j){
			for(int k=0;k<=half;++k) {
				if(!dp[cur^1][j][k]) continue;
				int f=dp[cur^1][j][k];
				if(vis[i]==1) {
					if(k) Inc(dp[cur][j][k-1],f);
					Inc(dp[cur][j+1][k],f);
				}
				else {
					Inc(dp[cur][j][k+1],f);
					if(k) Inc(dp[cur][j][k-1],f);
					if(j) Inc(dp[cur][j-1][k],(ll)f*j%mod);
				}
			}
		}
	}
	int fac=1;
	while(n2) fac=(ll)fac*n2%mod,--n2;
	printf("%lld\n",(ll)dp[cur][0][0]*fac%mod);
}


Measured memory_bytes: 3072
#include<stdio.h>
int main(void)
{

  char a[3];
  int i,sum=0;
    
  for(i=0;i<3;i++)
  {
    scanf("%c",&a[i]);
    if(a[i] == 'R'){
    sum++;
    }
  }
  if(sum==2&&a[1]=='S'){sum=1;}
  printf("%d",sum);
   
  return 0;
}

Measured memory_bytes: 1664
from collections import deque
import copy
def bfs():
  H, W = map(int, input().split())
  maze = [list(input()) for i in range(H)]
  S = []
  for i in range(H):
    for j in range(W):
      if maze[i][j] == ".":
        maze[i][j] = float("inf")
        S.append([i, j])
      else:
        maze[i][j] = -1
  ans = 0
  for k in range(len(S)):
    maze1 = copy.deepcopy(maze)
    maze1[S[k][0]][S[k][1]] = 0
    q = deque([[S[k][0],S[k][1]]])
    while q:
      y, x = q.popleft()
      for i, j in [(1, 0), (0, 1), (0, -1), (-1, 0)]:
        nexty, nextx = y+i, x+j
        if nexty < 0 or nexty>=H or nextx < 0 or nextx>=W:
          continue
        dist1 = maze1[nexty][nextx]
        if dist1 != -1:
          if dist1 > maze1[y][x]+1:
            maze1[nexty][nextx] = maze1[y][x] + 1
            q.append([nexty, nextx])
            ans = max(ans, maze1[nexty][nextx])
  print(ans)
bfs()

Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
  #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #define int long long
  #define endl "\n"
  const int N = 200005;
  #define all(v) v.begin(),v.end()
  #define double long double
  #define trace1(x)                cerr<<#x<<": "<<x<<endl
  #define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
  #define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
  #define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
  #define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<< ": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
  #define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
  #define cases int testcases;cin>>testcases; while(testcases--)
const int MOD = 1000000007;
const int INF = (1LL << 62) - 1;

#define MAXN 200005

vector<int> segmnt(4*MAXN);
int compute(int x,int y)
{
  return max(x,y);
}
void build(vector<int> &v,int curr,int ss,int se)
{
  if(ss == se)
  {
    segmnt[curr] = v[ss];
  }
  else
  {
    int left = 2*curr;
    int right = 2&curr+1;
    int mid = ss + (se-ss)/2;

    build(v,left,ss,mid);
    build(v,right,mid+1,se);
    segmnt[curr] = compute(segmnt[left],segmnt[right]);  

  }
}

int query(int curr,int ss,int se,int l,int r)
{
  if(l > r or l > se or r < ss)return -INF;
  if(ss >=l and se <= r)return segmnt[curr];

  int left = 2*curr;
  int right = 2*curr+1;
  int mid = ss + (se-ss)/2;

  int leftanswer = query(left,ss,mid,l,min(r,mid));
  int rightanswer = query(right,mid+1,se,max(l,mid+1),r);
  return compute(leftanswer,rightanswer);
}

void update(int curr,int ss,int se,int pos,int new_value)
{
  if(ss == se)
  {
    segmnt[curr] = new_value;
  }
  else
  {
    int left = 2*curr;
    int right = 2*curr+1;
    int mid = ss +(se-ss)/2;

    if(pos <= mid)update(left,ss,mid,pos,new_value);
    else update(right,mid+1,se,pos,new_value);

    segmnt[curr] = compute(segmnt[left],segmnt[right]);
  }
}

int32_t main()
{



    IOS



    int n;
    cin >> n;

    vector<int> v(n+1,0),dp(n+1,0),h(n+1),a(n+1);

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

    for(int i = 1; i <= n; i++)
    {
      cin >> a[i];
    }




    build(dp,1,1,n);

    for(int i = 1; i <= n; i++)
    {
      dp[h[i]] = a[i];
      int ans;
      if(h[i]-1 < 1)ans =0;
      else ans = query(1,1,n,1,h[i]-1);
      dp[h[i]] = max(dp[h[i]],ans + a[i]);
      update(1,1,n,h[i],dp[h[i]]);
    }


    int ans = 0;

    for(int i = 0; i <= n; i++)
    {
      ans = max(dp[i],ans);
      //cout << dp[i] << " ";
    }

    cout << ans;




    
    return 0;
}



Measured memory_bytes: 12800
import math

def main():
  H = int(input())
  
  n = math.floor(math.log(H,2))
  
  Ans = 0
  
  for i in range(n+1):
    Ans += math.pow(2,i)
    
  print(int(Ans))
  return 0

if __name__ == "__main__":
  main()

Measured memory_bytes: 3060
#!/usr/bin/env python3


def solve(H, W, S):
    grid = [[0] * W for _ in range(H)]
    for y in range(H):
        count = 0
        start = 0
        for x in range(W):
            if S[y][x] == '#':
                for i in range(start, x):
                    grid[y][i] = count
                start = x + 1
                count = 0
            else:
                count += 1
        for i in range(start, W):
            grid[y][i] = count

    for x in range(W):
        count = 0
        start = 0
        for y in range(H):
            if S[y][x] == '#':
                for i in range(start, y):
                    grid[i][x] += count
                start = y + 1
                count = 0
            else:
                count += 1
        for i in range(start, H):
            grid[i][x] += count

    ans = 0
    for x in range(W):
        for y in range(H):
            if grid[y][x] > ans:
                ans = grid[y][x]
    return ans - 1


if __name__ == '__main__':
    H, W = map(int, input().split())
    S = [input().strip() for _ in range(H)]

    ans = solve(H, W, S)

    print(ans)


Measured memory_bytes: 98520
#include <iostream>
#include <cstdio>
#include <string>
using namespace std;
int main(){
    string s;
    int b;
    cin>>s;
    int k=0;
    for (int i=0; i<=s.length(); ++i)
        if (s[i]=='C'&& k==0){
            ++k; b=i;
            break;
        }
    for (int i=b; i<=s.length(); ++i)
        if (s[i]=='F'&& k==1){
            ++k;
            break;
        }
        if (k==2) printf("Yes\n");
        else
        printf("No\n");
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
long long int a,b;
int main(){
	scanf("%lld",&a);
	b=(a/11)*2;
	a=a%11;

	b=b+a/6;
		
	a=a%6;
	if(a>0)
		b=b+1;
	printf("%lld",b);
}

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

#define mod 1000000007

ll N, K;
vector<ll>A;

ll xu, iu;

// 開区間と判定関数を引数にして条件を満たす境界値を返す
ll BiSearch(ll ok, ll ng, function<bool(ll)> C){
    while (abs(ok - ng) > 1) {
        ll mid = (ok + ng) / 2;
        if (C(mid)) ok = mid;
        else ng = mid;
    }
    return ok;
}

// x以下がK個以上あるかどうか
bool C1(ll x){
    xu = x;
    ll cnt = 0;
    for (int i = 0; i < N - 1; ++i) {
        iu = i;
        if (A[i] > 0) {
            if (A[i] * A[i+1] > x) break;
            int k = BiSearch(i+1, N, [](ll j){ return A[iu] * A[j] <= xu;});
            cnt += k - i;
        } else if (A[i] == 0) {
            if (x >= 0) cnt += N - 1 - i;
        } else {
            if (A[i] * A[N-1] > x) break;
            int k = BiSearch(N-1, i, [](ll j){ return A[iu] * A[j] <= xu;});
            cnt += N - k;
        }
    }
    if (cnt >= K) return true;
    return false;
}


int main() {
    cin >> N >> K;
    A.resize(N);
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
    }
    sort(A.begin(), A.end());
    cout << BiSearch(1000000000000000001, -1000000000000000001, C1) << "\n";
    return 0;
}

Measured memory_bytes: 1792
#include<iostream>
using namespace std;
int main()
{
    long long int n,m,a[10002],i,j,s=0;
    cin>>n>>m;
    for(i=0;i<m;i++)
    {
        cin>>a[i];
        s+=a[i];
    }
    if(n-s>=0)
    {
        cout<<n-s<<endl;
    }
    else
    {
        cout<<-1<<endl;
    }
}


Measured memory_bytes: 3696
#include<bits/stdc++.h>
using namespace std;
#define f(i,a,b) for(int (i)=int (a);i<=int (b);i++)
#define F(i,a,b) for(int(i)=int (a);i>=int (b);i--)
#define pb push_back
#define ll long long
#define vt vector
int n,k;
ll a[1010];
ll s[1010];vt<ll> tmp;
vt<ll> v;
ll ans=0;
int main(){
	cin>>n>>k;
	f(i,1,n){
		cin>>a[i];s[i]=s[i-1]+a[i];
	}
	f(i,1,n){
		f(j,i,n){
			v.pb(s[j]-s[i-1]);
		}
	}
	F(i,40,0){
		tmp.clear();
		for(auto t:v){
			if(t >> i &1) tmp.pb(t);	
		}
		if(tmp.size()>=k){
			ans|=(1LL<<i);
			v.clear();v=tmp;
		}
	}cout<<ans;
}

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> L(M), R(M);
  for (int i = 0; i < M; i++)
    cin >> L.at(i) >> R.at(i);
  int maxL = 1, minR = N;
  for (int i = 0; i < M; i++) {
    maxL = max(maxL, L.at(i));
    minR = min(minR, R.at(i));
  }
  if (maxL > minR)
    cout << 0 << endl;
  else
    cout << minR - maxL + 1 << endl;
  return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<algorithm>
#include<cmath>
#include<queue>
#include<set>
#include<iomanip>
using namespace std;

const int MAX_V=1010;//頂点数の最大値
const double INF=999999999999.9;
double cost[MAX_V][MAX_V];//cost[u][v]は辺e=(u,v)のコスト、辺が無い場合はINF
double d[MAX_V];//頂点sからの最小距離
bool used[MAX_V];//既に使われたかのフラグ
int V;//頂点数

void dijkstra(int s){
    fill(d,d+V,INF);
    fill(used,used+V,false);
    d[s]=0.0;
    while(true){
        int v = -1;
        //まだ使われていない頂点のうち距離が最小のものを探す。
        for(int u=0;u<V;u++){
            if(!used[u] && (v==-1 || d[u]<d[v])){
                v=u;
            }
        }
        if(v==-1) break;
        used[v]=true;
        for(int u=0;u<V;u++){
            d[u] = min(d[u],d[v]+cost[v][u]);
        }
    }
}

double dist(double xi,double yi,double xj,double yj){
    double res = sqrt(1.0*(xi-xj)*(xi-xj)+1.0*(yi-yj)*(yi-yj));
    return res;
}

int main(){
    double xs,ys,xt,yt;
    int a,b,c,e;
    cin>>a>>b>>c>>e;
    xs=1.0*a; ys=1.0*b; xt=1.0*c; yt=1.0*e;
    int N;
    cin>>N;
    V=N+2;
    double x[1010],y[1010],r[1010];
    for(int i=0;i<N;i++){
        int xx,yy,rr;
        cin>>xx>>yy>>rr;
        x[i]=1.0*xx; y[i]=1.0*yy; r[i]=1.0*rr;
    }
    cost[N][N+1]=dist(xs,ys,xt,yt);
    cost[N][N]=0.0;
    cost[N+1][N]=dist(xs,ys,xt,yt);
    cost[N+1][N+1]=0.0;
    for(int i=0;i<N;i++){
        cost[i][N]=max(dist(x[i],y[i],xs,ys)-1.0*r[i], 0.0);
        cost[N][i]=max(dist(x[i],y[i],xs,ys)-1.0*r[i], 0.0);
        cost[i][N+1]=max(dist(x[i],y[i],xt,yt)-1.0*r[i], 0.0);
        cost[N+1][i]=max(dist(x[i],y[i],xt,yt)-1.0*r[i], 0.0);
        for(int j=0;j<N;j++){
            cost[i][j]=max(dist(x[i],y[i],x[j],y[j])-1.0*r[i]-1.0*r[j] , 0.0);
        }
    }
    dijkstra(N);
    cout<<setprecision(20)<<d[N+1]<<endl;
    return 0;
}


Measured memory_bytes: 8192
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#ifdef LOCAL
#define lout cout
#else
stringstream devnull;
#define lout devnull
#endif
#define AMULET \
  cin.tie(0);  \
  ios::sync_with_stdio(false);
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep3(i, f, n) for (int i = f; i < n; i++)
#define repr(i, n) for (int i = n - 1; i >= 0; i--)
typedef long long ll;
typedef pair<int, int> pi;
int main()
{
  AMULET
  int n;
  cin >> n;
  vector<pi> tasks;
  rep(i, n)
  {
    int a, b;
    cin >> a >> b;
    tasks.push_back(make_pair(b, a));
  }

  sort(tasks.begin(), tasks.end());

  for (auto e : tasks)
  {
    static long sum = 0;
    sum += e.second;
    if (sum > e.first)
    {
      puts("No");
      return 0;
    }
  }
  puts("Yes");
  return 0;
}


Measured memory_bytes: 2420
# include <iostream>
# include <math.h>

using namespace std;

int main()
{
	int K, A, B;
	cin >> K;
	cin >> A >> B;

	if (A / K < B / K || A%K==0 || B%K==0)
		cout << "OK";
	else
		cout << "NG";

	return 0;
}

Measured memory_bytes: 3632
use proconio::fastout;
use proconio::input;

#[fastout]
fn main() {
    input! { x: u32, }
    let ans = if x <= 599 {
        8
    } else if x <= 799 {
        7
    } else if x <= 999 {
        6
    } else if x <= 1199 {
        5
    } else if x <= 1399 {
        4
    } else if x <= 1599 {
        3
    } else if x <= 1799 {
        2
    } else {
        1
    };
    println!("{}", ans);
}


Measured memory_bytes: 2168
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <map>
#define pii pair<int,int>
#define pb push_back
using namespace std;
int n,m;
vector<vector<int> > edge;
int vis[10];
int dfs(int i,int num){

  if(vis[i]==1) return 0;
  if(num+1==n) return 1;
  vis[i]=1;

  int j,tmp;
  tmp=0;
  for(j=0;j<edge[i].size();j++){
    if(vis[edge[i][j]]==0) tmp+=dfs(edge[i][j],num+1);
  }
  vis[i]=0;
  return tmp;
}

int main(void){

  int i,a,b;

  cin>>n>>m;
  for(i=0;i<=n;i++){
    vector<int> v;
    edge.pb(v);
    vis[i]=0;
  }

  for(i=0;i<m;i++){
    cin>>a>>b;
    edge[a].pb(b);
    edge[b].pb(a);
  }
  cout<<dfs(1,0)<<endl;

  return 0;
}

Measured memory_bytes: 256
//Single Source Shortest Path II
#include <iostream>
#include <vector>
#include <queue>
#include <climits>

using namespace std;

static const int N = 10000;
static const int WHITE = 0;
static const int BLACK = 1;
int d[N];

void dijkstra(vector<vector<pair<int, int>>> G, int n) {
    int colors[n];
    for(int i = 0; i < n; i++) {
        colors[i] = WHITE;
        d[i] = INT_MAX;
    }

    priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > > pq;

    d[0] = 0;
    pq.push(make_pair(0, 0));
    while(!pq.empty()) {
        pair<int, int> f = pq.top();
        pq.pop();
        
        int u = f.second;
        if(d[u] < f.first) continue;
        if(colors[u] == BLACK) continue;
        for(int i = 0; i < G[u].size(); i++) {
            if(d[G[u][i].first] > f.first + G[u][i].second) {
                d[G[u][i].first] = f.first + G[u][i].second;
                pq.push(make_pair(d[G[u][i].first], G[u][i].first));
            }

        }
    }
}

int main() {
    int n, u, k, v, c;
    cin >> n;
    vector<vector<pair<int, int>>> G(n);

    for(int i = 0; i < n; i++) {
        cin >> u >> k;
        for(int j = 0; j < k; j++) {
            cin >> v >> c;
            G[u].push_back(make_pair(v, c));
        }
    }

    dijkstra(G, n);

    for(int i = 0; i < n; i++) cout << i << " " << d[i] << endl;

    return 0;
}



Measured memory_bytes: 11416
#include <bits/stdc++.h>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x)      begin(x),end(x)

using namespace std;
using vecint = vector<int>;
using ll = int64_t;
constexpr int INF = 1000000000;

struct UnionFind {
  vector<int> parent;
  UnionFind (int n) : parent(n, -1) {}
  int root(int x) { return parent[x] < 0 ? x : parent[x] = root(parent[x]); }
  bool merge(int x, int y) {
    x = root(x); y = root(y);
    if (x == y) return false;
    if (parent[y] < parent[x]) swap(x, y);
    if (parent[x] == parent[y]) --parent[x];
    parent[y] = x;
    return true;
  }
};

typedef int Weight;
struct Edge{
  int src, dest; Weight weight;
  bool operator < (const Edge &rhs) const {return weight > rhs.weight;}
};

typedef vector<Edge> Edges;

// Kruskal
// N, operator <
Edges kruskal(int V, Edges &es) {
  sort(es.rbegin(), es.rend());
  UnionFind uf(V);
  Edges res;
  REP(i, es.size()) {
    Edge e = es[i];
    if(uf.root(e.src) != uf.root(e.dest)) {
      uf.merge(e.src, e.dest);
      res.push_back(e);
    }
  }
  return res;
}

int main()
{
  int n;
  cin>>n;
  vector<tuple<int,int>> vx, vy;
  REP(i,n) {
    int x,y;
    cin>>x>>y;
    vx.emplace_back(x,i);
    vy.emplace_back(y,i);
  }
  sort(ALL(vx));
  sort(ALL(vy));
  Edges ve;
  REP(i,n-1) {
    int x1, j1, x2, j2;
    tie(x1, j1) = vx[i];
    tie(x2, j2) = vx[i+1];
    ve.push_back((Edge){j1, j2, abs(x1-x2)});
    int y1, y2;
    tie(y1, j1) = vy[i];
    tie(y2, j2) = vy[i+1];
    ve.push_back((Edge){j1, j2, abs(y1-y2)});
  }
  Edges res = kruskal(n, ve);
  int sum = 0;
  for(Edge e:res) sum += e.weight;
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 7652
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define zep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(int i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

int main(){
	cin.tie(0); ios::sync_with_stdio(false);
	
	ll k; cin >> k;
	string s; cin >> s;
	if(s.size() <= k){
		print(s)
	}
	else{
		print(s.substr(0, k)+"...")
	}
	
	return 0;
}

Measured memory_bytes: 3644
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
using namespace std;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
//cout<<setprecision(20)
const llint mod=1000000007;
const llint big=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>void mineq(T& a,U b){if(a>b){a=b;}}
template <class T,class U>void maxeq(T& a,U b){if(a<b){a=b;}}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
int LBI(vector<lldo>&ar,lldo in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
int UBI(vector<lldo>&ar,lldo in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
int main(void){
	int n,i;cin>>n;
	vector<multiset<pair<int,int>>>go(n);
	vector<int>ne(n);
	//pair<行先,Aかどうか>
	//goの向きをうまく決めればよい
	//AとBで反対の向きを決める
	//入次数=出次数 親は別
	//ans=「Aの」入次数-出次数
	int pla=-1,mai=-1;
	for(i=0;i<n;i++){
		int a;cin>>a;
		if(a>0){
			a--;go[i].ins(mp(a,1));
			go[a].ins(mp(i,1));
		}else{pla=i;ne[i]++;}
	}
	for(i=0;i<n;i++){
		int b;cin>>b;
		if(b>0){
			b--;go[i].ins(mp(b,0));
			go[b].ins(mp(i,0));
		}else{mai=i;ne[i]--;}
	}
	for(i=0;i<n;i++){
		if(((int)go[i].size()+ne[i])%2){cout<<"IMPOSSIBLE"<<endl;return 0;}
	}
	cout<<"POSSIBLE"<<endl;
	//cerr<<"pla="<<pla<<endl;
	ne[mai]=0;
	ne[pla]=1;
	
	//赤辺を通った時だけ数字の更新が起きる
	int sta=-1;
	while(sta<n){
		if(sta!=-1&&go[sta].size()==0){sta++;continue;}
		if(sta!=-1){pla=sta;mai=sta;}
		if(sta==-1&&pla==sta){sta++;continue;}
		//plaを移動させていく
		while(-1){
			auto itr=go[pla].begin();
			int ter=itr->fir;
			int col=itr->sec;
			go[pla].era(itr);
			go[ter].era(go[ter].lower_bound(mp(pla,col)));
			if(col){ne[pla]--;ne[ter]++;}
			pla=ter;
			if(pla==mai){break;}
		}
		if(sta==-1){sta++;}
	}
	for(i=0;i<n;i++){cout<<ne[i]<<" ";}cout<<endl;
	return 0;
}

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

int main(){
    int n;
    cin >> n;
    string s, t;
    cin >> s;
    cin >> t;
    int ans = 2*n;
    for(int i = 1; i <= n; i++){
        bool can = true;
        for(int j = 0; j < i; j++){
            if(s[n-i+j] != t[j]) can = false;
        }
        if(can) ans = min(ans,2*n-i);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
def f(x):
  return sum([(i-1)//x for i in a])<=k

def main():
  l,r=0,10**9
  while r-l>1:
    m=(l+r)//2
    if f(m): r=m;
    else: l=m;
  print(r)

if __name__=='__main__':
  n,k=map(int,input().split())
  a=list(map(int,input().split()))
  main()

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

int main(){
  while(1){
    int n,m,t,p;
    cin >> n >> m >> t >> p;

    if(n==0){
      break;
    }

    int o[64][64];
    for(int y=0; y<64; y++){
      for(int x=0; x<64; x++){
        if(y<m && x<n){
          o[y][x]=1;
        }else{
          o[y][x]=0;
        }
      }
    }

    for(int i=0; i<t; i++){
      int d,c;
      cin >> d >> c;

      if(d==1){
        for(int x=0; x<c; x++){
          for(int y=0; y<m; y++){
            o[y][2*c-1-x]+=o[y][x];
            o[y][x]=0;
          }
        }
        for(int x=0; x<n; x++){
          for(int y=0; y<m; y++){
            o[y][x]=o[y][x+c];
            o[y][x+c]=0;
          }
        }

      }else if(d==2){
        for(int y=0; y<c; y++){
          for(int x=0; x<n; x++){
            o[2*c-1-y][x]+=o[y][x];
            o[y][x]=0;
          }
        }
        for(int y=0; y<m; y++){
          for(int x=0; x<n; x++){
            o[y][x]=o[y+c][x];
            o[y+c][x]=0;
          }
        }
      }
    }

    for(int i=0; i<p; i++){
      int x,y;
      cin >> x >> y;
      cout << o[y][x] << endl;
    }

  }
  return 0;
}


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

int main(){
    string s;
    cin>>s;
    if(s.length()>=4){
        if(s[0]=='Y'&&s[1]=='A'&&s[2]=='K'&&s[3]=='I')
        cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }else cout<<"No"<<endl;
    
    return 0;
}

Measured memory_bytes: 256
import sys

def shellSort(data, cnt, g, n):
    for idx in range(g, n):
        j = idx - g
        v = data[idx]
        while j >= 0 and data[j] > v:
            data[j+g] = data[j]
            j -= g
            cnt += 1
        data[j+g] = v
    return data, cnt

n, gap = int(input()), []
a = ([int(i) for i in sys.stdin.readlines()], 0)
g = 0
while g <= n//9:
    g = 3 * g + 1
    gap.append(g)
m = len(gap)
for i in gap[::-1]:
    a = shellSort(a[0], a[1], i, n)
print(m)
print(" ".join(map(str, gap[::-1])))
print(a[1])
for i in range(n):
    print(a[0][i])



Measured memory_bytes: 116568
//Robs Code

/***********HEADER***************/
#include <iostream>
#include <bitset>
#include <deque>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <algorithm>
#include <list>
#include <vector>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <set>
#include <queue>
#include <map>
#include <iomanip>

/***********MACROS***************/
#define int long long int
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define endl "\n"
#define pb push_back
#define _1 first
#define _2 second
#define pii pair<int,int>

using namespace std;

const int N = 1e5 + 1;
int n,m,i,j,k,l,x,y,z,cnt[3],sum[3];

/***********MAIN**************/
struct BIT{//use one based indexing
	int N;
	vector<int> bit;

	void init(int n){
		N = n + 9;
		bit.assign(n + 10, 0);
	}

	void update(int idx, int val){
		while(idx <= N){
			bit[idx] += val;
			idx += idx & -idx;
		}
	}

	int pref(int idx){
		int ans = 0;
		while(idx > 0){
			ans += bit[idx];
			idx -= idx & -idx;
		}
		return ans;
	}

	int rsum(int l, int r){
		return pref(r) - pref(l - 1);
	}

	int kthOrder(int k){
		if(pref(N) < k){
			return -1;
		}
		int cur = 0,sum = 0, ExtraSize = N;
		int ln = log2(ExtraSize);
		for(int i = ln;i >= 0 ; --i){
			int temp = cur + (1 << i);
			if((temp < ExtraSize) && (sum + bit[temp]) < k){
				cur = temp;
				sum += bit[temp];
			}
		}
		return cur + 1;
	}

	//one based indexing
	int lower_bound(int val){
		return (pref(val - 1) + 1);
	}

	//one based indexing
	int upper_bound(int val){
		return (pref(val) + 1);
	}
};
signed main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	string s;
	cin >> n;
	cin >> s;
	s = "#" + s;
	BIT bt[2];
	bt[0].init(n + 1);
	bt[1].init(n + 1);
	//0 -> R
	for(int i = 1;i <= n;i++){
		if(s[i] == 'R'){
			bt[0].update(i,1);
		}
		if(s[i] == 'W'){
			bt[1].update(i,1);
		}
	}
	int ans = 1e9;
	for(int i = 1;i <= n;i++){
		int red = bt[0].rsum(i,n);
		int white = bt[1].rsum(1,i);
		// cout << i << " " << red << " " << white << "\n";
		if(s[i] == 'R') red--;
		if(s[i] == 'W') white--;
		ans = min(ans,min(red,white) + abs(red - white));
	}
	cout << ans;
}
//.........

Measured memory_bytes: 6580
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define pb push_back
#define sz(i) (int)(i.size())
#define F first
#define S second
#define L long double
#define P pair<int, int>
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}
const int N = 305;

int n, a[N], k;
int dp[N][N][N];

int solve(int idx, int rem, int prev){
   if(rem < 0)
      return inf;
   if(idx > n)
      return 0;
   int &ans = dp[idx][rem][prev];
   if(~ans)
      return ans;
   ans = inf;
   smin(ans, solve(idx+1, rem-1, prev));
   smin(ans, max(0LL, a[idx] - a[prev]) + solve(idx+1, rem, idx));
   return ans;
}

int32_t main(){_

   cin>>n>>k;

   for (int i = 1; i <= n; ++i)
   {
      cin>>a[i];
   }   
      
   memset(dp, -1, sizeof dp);
   cout<<solve(1, k, 0);

   return 0;
}

Measured memory_bytes: 221952
#include<stdio.h>

/*配列の要素を順番に出力*/
void trace(int A[],int N){
    int i;
    for(i=0;i<N;i++){
        /*隣接する要素の間に１つの空白を出力*/
        if(i>0)printf(" ");
        printf("%d",A[i]);
    }
    printf("\n");
}

/*挿入ソート（０オリジン配列）*/
void insertionSort(int A[],int N){
    int i,j,v;
    for(i=1;i<N;i++){
        v=A[i];
        j=i-1;
        while(j>=0 && A[j]>v){
            A[j+1]=A[j];
            j--;
        }
        A[j+1]=v;
        trace(A,N);
    }
}

int main(void){
    int N, i, j;
    int A[100];
    scanf("%d",&N);
    for(i=0;i<N;i++) scanf("%d",&A[i]);
    
    trace(A,N);
    insertionSort(A,N);
    return 0;
}


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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define sz size()
#define pb(x) push_back(x) 
#define bg begin()
#define ed end()
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define mp(x,y) make_pair(x,y)
const ll MOD=1000000007;

ll fac[200001],finv[200001],inv[200001];

void table() {
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<200001;i++){
        fac[i]= fac[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}

ll comb(int n, int k){
    if(n<k) return 0;
    if(n<0 || k<0) return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}

int main(){
    table();
	ll H,W,A,B; cin>>H>>W>>A>>B;
	ll ans=0;
	rep(i,H-A){
		ans=(ans+(comb(B-1+i,i)*comb(W-B-2+H-i,H-1-i))%MOD)%MOD;
	}
	cout<<ans;
}

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

using ll = long long;
const ll INF = 1e18L + 7;

int GetSumValue(vector<int> values)
{
    int sum_value = 0;
    for(int v:values)
        sum_value += v;

    return sum_value;
}

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

    int n, W;
    cin >> n >> W;

    vector<int> weight(n);
    vector<int> values(n);

    for(int i=0; i<n; ++i)
        cin >> weight[i] >> values[i];

    int sum_value = GetSumValue(values);

    vector<ll> dp(sum_value + 1, INF);

    // dp[i] : represents the minimum total weight of items with total value exactly i
    dp[0] = 0; // weight will be 0 for value 0
    for(int i=0; i<n; ++i)
    {
        for(int value_already = sum_value - values[i]; value_already >= 0; --value_already)
        {
            if (dp[value_already] != INF)
            {
                dp[value_already + values[i]] = min(dp[value_already + values[i]], dp[value_already] + weight[i]);
            }
        }
    }

    ll ans = 0;
    for(int i=sum_value; i>=0; --i)
    {
        if (dp[i] <= W)
        {
            ans = i;
            break;
        }
    }

    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 1024
n = int(input())
h = list(map(int,input().split()))
dp = [0]*n

dp[0] = 0
dp[1] = abs(h[1]-h[0])

for i in range(2,n):
    dp[i] = min((dp[i-1]+abs(h[i]-h[i-1])),dp[i-2]+abs(h[i]-h[i-2]))

print(dp[-1])

Measured memory_bytes: 20348
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cctype>
#include <functional>
#include <map>
#include <cmath>

using namespace std;
typedef long long ll;

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

int main(){
    vector<int> vec(3);
    rep(i,3) cin >> vec[i];

    sort(vec.begin(), vec.end());

    cout << abs(vec[2]-vec[1]) + abs(vec[1]-vec[0]) << endl;
    

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 5000000000000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;
vector<ll> C(26);
vector<vector<ll>> S;

ll change_evaluation(vector<ll>& T, ll t, ll day) {
  t -= 1;
  day -= 1;
  vector<ll> last(26, -1);
  vector<ll> next(26, T.size());
  ll old = T.at(day) - 1;
  for (ll i = 0; i < day; ++i) {
    last.at(T.at(i) - 1) = i;
  }
  for (ll i = T.size() - 1; i > day; --i) {
    next.at(T.at(i) - 1) =  i;
  }
  ll score = S.at(day).at(t) - S.at(day).at(old);
  score += (next.at(t) - day) * (day - last.at(t)) * C.at(t);
  score -= (next.at(old) - day) * (day - last.at(old)) * C.at(old);
  return score;
}

ll evaluation(vector<ll>& T) {
  ll D = T.size();
  vector<ll> last(26, 0);
  ll score = 0;
  for (ll i = 0; i < D; ++i) {
    ll contest = T.at(i) - 1;
    last.at(contest) = i + 1;
    score += S.at(i).at(contest);
    for (ll j = 0; j < 26; ++j) {
      score -= (i + 1 - last.at(j)) * C.at(j);
    }
  }
  return score;
}

int main() {
  //-----------input-------------
  ll D;
  cin >> D;
  vector<ll> T(D);
  S = vector<vector<ll>>(D, vector<ll>(26));
  for (ll i = 0; i < 26; ++i) {
    cin >> C.at(i);
  }
  for (ll i = 0; i < D; ++i) {
    for (ll j = 0; j < 26; ++j) {
      cin >> S.at(i).at(j);
    }
  }
  for (ll i = 0; i < D; ++i) {
    cin >> T.at(i);
  }
  //--------------------------------------
  // vector<ll> last(26, 0);
  // for (ll day = 0; day < D; ++day) {
  //   ll max_contest = 0;
  //   ll max_score = -INF;
  //   for (ll contest = 0; contest < 26; ++contest) {
  //     ll temp_score = evaluation(contest, day, last);
  //     if (temp_score > max_score) {
  //       max_score = temp_score;
  //       max_contest = contest + 1;
  //     }
  //   }
  //   last.at(max_contest - 1) = day;
  //   T.at(day) = max_contest;
  // }

  // for (ll i = 0; i < D; ++i) {
  //   cout << T.at(i) << "\n";
  // }

  ll score = evaluation(T);
  // cout << score << "\n";
  ll M;
  cin >> M;
  for (ll i = 0; i < M; ++i) {
    ll d, q;
    cin >> d >> q;
    score += change_evaluation(T, q, d);
    T.at(d - 1) = q;
    cout << score << "\n";
  }

  // vector<ll> ans = evaluation(C, S, T);
  // for (ll i = 0; i < ans.size(); ++i) {
  //   cout << ans.at(i) << "\n";
  // }
}


Measured memory_bytes: 3708
object Main {
    def step(s: (Int, Int, Int), i: Char) = i match {
        case 'N' => (s._2, 5-s._1, s._3)
        case 'E' => (5-s._3, s._2, s._1)
        case 'L' => (s._1, s._3, 5-s._2)
        case 'R' => (s._1, 5-s._3, s._2)
    }
 
    def main(args: Array[String]) = {
        val in = io.Source.stdin.getLines.map(_.split(" ").map(_.toInt))
        val first = in.next
        val a = "NELNELNELNERNELNELNELNE".scanLeft((0, 1, 2))(step).map(x => List(x._1, x._2, x._3, 5-x._3, 5-x._2, 5-x._1).map(first(_)))
        if (a contains in.next.toList) println("Yes") else println("No")
    }
}

Measured memory_bytes: 44288
//url:
//problem name: Brick Break

#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
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;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;

int main() {
    int A,B,T;
    cin >> A >> B >>T;
    int ans = 0;
    for(int i = 1; i <= T; i++) {
        if(i%A == 0) ans += B;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int x;
	cin >> x;
	if(x >= 30)
		cout << "Yes\n";
	else
		cout << "No\n";
}

Measured memory_bytes: 3608
import java.util.Scanner;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner (System.in);
        
        int a = sc.nextInt();
        int b = sc.nextInt();
        
        System.out.print(a*b+" "+2*(a+b));
        System.out.println();
//        System.out.print(" ");
//        System.out.print(2*(a+b)) ;
        }
}


Measured memory_bytes: 26104
using System;
using System.Text;
using System.Collections.Generic;
class Solve{
    int N,M;
    public Solve(){}
    StringBuilder sb;
    public static int Main(){
        new Solve().Run();
        return 0;
    }
    void Run(){
        sb = new StringBuilder();
        Read();
        Calc();
        Console.Write(sb.ToString());
    }
    void Calc(){
        long[,,] d = new long[M+1,N,N+1];
        for(int i=0;i<M+1;i++){
            for(int j=0;j<N;j++){
                for(int k=0;k<N+1;k++){
                    if(i == 0){
                        if(j == 0 && k == 0){
                            d[i,j,k] = 1;
                        }
                        else{
                            d[i,j,k] = 0;
                        }
                    }
                    else{
                        d[i,j,k] = 0;
                    }
                }
            }
        }
        for(int i=1;i<M+1;i++){
            for(int j=0;j<N;j++){
                for(int k=j;k<N+1;k++){
                    if(k != 0){
                        d[i,j,k] = (d[i,j,k] + (d[i-1,j,k] * (k-j-1) % Define.mod)) % Define.mod;
                        d[i,k-1,k] = (d[i,k-1,k] + (d[i-1,j,k] * (j+1) % Define.mod)) % Define.mod;
                    }
                    if(k != N){
                        if(k == 0){
                            d[i,j,k+1] = (d[i,j,k+1] + d[i-1,j,k]) % Define.mod;
                        }
                        else{
                            d[i,j,k+1] = (d[i,j,k+1] + (d[i-1,j,k] * (N-k) % Define.mod)) % Define.mod;
                        }
                    }
                }
            }
        }
        sb.Append(d[M,N-1,N]+"\n");
    }
    void Read(){
        string[] str = Console.ReadLine().Split(' ');
        N = int.Parse(str[0]);
        M = int.Parse(str[1])+1;
    }    
}
public static class Define{
    public const long mod = 1000000007;
}

Measured memory_bytes: 215768
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { 
  INIT(){cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


signed main() {
  int N = 5;

  vector<int> A(N);
  REP(i, N) cin >> A[i];

  int ans = 0;
  int MIN = 10;
  REP(i, N){
    ans += ((A[i]+10-1)/10)*10;
    if(A[i]%10 != 0) chmin(MIN, A[i]%10);
  }

  cout << ans-10+MIN << "\n";

  return 0;
}

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

#define ALL(v) v.begin(), v.end()
typedef long long ll;

using namespace std;
int main() {

	int n, t;
	cin >> n >> t;

	ll total = 0;
	bool OK = false;

	vector<int> ts(n);

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

	for (int i = 0; i < n; i++)
	{
		if (i == n - 1) {
			total += t;
			break;
		}


		if ((ts[i] + t) <= ts[i + 1]) {
			// かぶらない
			total += t;
		}
		else {
			//かぶる
			total += t - ((ts[i] + t) - ts[i + 1]);
		}
	}



	 cout << total << endl;
}

Measured memory_bytes: 1024
#include <iostream>
    #include <algorithm>
    #include <vector>
    #include <map>
    #include <set>
    #include <string>
    #include <cmath>
    #include <iomanip>
    #include <queue>
    #include <unordered_map>
    #include <unordered_set>
    #include <bitset>
    #include <cassert>
    #include <cstring>
    #include <climits>
    
     
    using namespace std;
     
    #define FOR(i, a, b) for (int i = (a); i < (b); i++)
    #define rep(i, n) FOR(i, 0, n)
    #define SORT(c) sort((c).begin(), (c).end())
    #define mp make_pair
    #define fi first
    #define se second
    #define pb push_back
     
    typedef long long ll;
    typedef pair<int, int> P;
    typedef vector<int> V;
    typedef map<int, int> M;
     
    constexpr ll INF = 1e18;
    constexpr ll MOD = 1e9 + 7;
    constexpr double PI = 3.14159265358979323846;
    constexpr int di[] = {0, 0, 1, -1};
    constexpr int dj[] = {1, -1, 0, 0};
     
    int main()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
        int a, b, k;
        cin >> a >> b >> k;
        int tmp = 0;
        int x[110];
        for (int i = 1; i <= 100;i++){
            if(a%i==0&&b%i==0){
                x[tmp] = i;
                tmp++;
            }
        }
        sort(x, x + tmp, greater<int>());
        cout << x[k - 1] << endl;
        return 0;
    }

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

#define ll long long
#define INF 99999999
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

int main()
{
    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i,a.size()) cin >> a[i];
    sort(all(a));
    ll ans = 0;
    
    ll tmp = 0;
    ll last = a[0];
    rep(i,a.size())
    {
        if(last != a[i] && last != tmp)
        {
            if( tmp > last) ans += tmp-last;
            else ans += tmp;
            tmp = 1;
            last = a[i];
        }
        else if(last != a[i])
        {
            last = a[i];
            tmp = 1;
        }
        else tmp++;
    }
    
    if(last != tmp)
    {
        if( tmp > last )ans += tmp-last;
        else ans += tmp;
    }

    cout << ans << endl;
}


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


using namespace std;


int main(void){

  int N,K;
  cin >> N >> K;

  vector<int>b[K];

  for(int i=0;i<K;i++){
    int m;
    cin >> m;
    b[i].resize(m);
    for(int j=0;j<m;j++)cin >> b[i][j];
  }

  int R;
  cin >> R;
  bool B[N+1];
  fill(B,B+N+1,false);
  int p,q;
  for(int i=0;i<R;i++){
    cin >> p >> q;
    for(int j=0;j<K;j++){
      bool fg1=false,fg2=false;
      for(int k=0;k<b[j].size();k++){
        if(b[j][k]==p)fg1=true;
        if(b[j][k]==q)fg2=true;
      }
      if(fg1 && fg2)B[p]=B[q]=true;
    }
  }

  int ans=0;
  for(int i=0;i<=N;i++)ans+=B[i];

  cout << ans << endl;


  return 0;
}

Measured memory_bytes: 1204
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	private static char[] a;
	private static int aIndex = 0;
	private static char[] b;
	private static int bIndex = 0;
	private static char[] c;
	private static int cIndex = 0;
	
	private static char winner;
	
	public static void main(String[] args) throws Exception {
		try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
			String line = reader.readLine();
			a = line.toCharArray();
			line = reader.readLine();
			b = line.toCharArray();
			line = reader.readLine();
			c = line.toCharArray();
		}
		char input = a[0];
		aIndex++;
		culculate(input);
		System.out.println(winner);
	}
	
	private static void culculate(char input) {
		char nextChar;
		switch (input) {
		case 'a' :
			if (aIndex == a.length) {
				winner = 'A';
				return;
			} else {
				nextChar = a[aIndex];
				aIndex++;
				culculate(nextChar);
				return;
			}
		case 'b' :
			if (bIndex == b.length) {
				winner = 'B';
				return;
			} else {
				nextChar = b[bIndex];
				bIndex++;
				culculate(nextChar);
				return;
			}
		case 'c' :
			if (cIndex == c.length) {
				winner = 'C';
				return;
			} else {
				nextChar = c[cIndex];
				cIndex++;
				culculate(nextChar);
				return;
			}
			default : throw new RuntimeException();
		}
	}
}


Measured memory_bytes: 22868
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF 1<<30
#define LINF 1LL<<60

int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	ll N, K; cin >> N >> K;
	vector<pair<ll,ll>> x(N);
	ll ans = 0;
	for (int i = 0; i < N;i++) {
		cin >> x[i].first >> x[i].second;
		if (K == (K | x[i].first)) { ans += x[i].second; }
	}

	for (ll i = 1; i <= K; i <<= 1) {
		if (!(i&K)) continue;
		ll temp = (K^i) | (i - 1);
		ll sum = 0;
		for (int j = 0; j < N;j++) {
			if (temp == (temp | x[j].first)) sum += x[j].second;
		}
		ans = max(ans, sum);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
#include <string.h>
#include <numeric>
using namespace std;

#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) rep(i,(n)+1)
#define repst(i,s,n) reps(i,s,(n)+1)
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(i,v) for(auto &(i):(v))
#define eachr(i,v) for(auto &(i)=(v).rbegin();(i)!=(v).rend();(i)++)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define bln(i,n) (((i)==(n)-1)?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln<<flush
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ')<<flush;}}
#define zero(a) memset(a,0,sizeof(a))
#define unq(a) sort(all(a)),a.erase(unique(all(a)),a.end())

//typedef complex<double> P;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

ll mop(ll a,ll b,ll m=mod) {ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r;}
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) {return a/gcd(a,b)*b;}
bool ool(int x,int y,int h,int w) {return((x<0)||(h<=x)||(y<0)||(w<=y));}
bool deq(double a,double b) {return abs(a-b)<eps;}

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;



string s;
int n, res, b;

signed main() {
	cin >> s;
	n = s.size();
	rep(i,n) {
		if (s[i]=='B') b++;
		else res += b;
	}
	cout << res << endl;
}

Measured memory_bytes: 720
list_w = []
flag = 0
N = int(input())
for i in range(N):
    W = input()
    list_w.append(W)
    if i >=1 and list_w[-2][-1] != W[0]:
        flag = 1
if len(set(list_w)) != N or flag == 1:
    print('No')
else:
    print('Yes')


Measured memory_bytes: 9068