akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

// macro
#define rep(i,n) for(i=0;i<n;i++)
#define ll long long
#define all(v) v.begin(), v.end()

// code starts
int main()
{
  int h,w;
  cin >> h >> w;
  vector<int> count(26,0);
  int i;
  rep(i,h*w)
  {
    char c;
    cin >> c;
    count[c-'a']++;
  }
  bool ok = true;
  if(h%2 == 0 && w%2 == 0)
  {
    rep(i,26)
    {
      if(count[i]%4 != 0) ok = false;
    }
  }
  else if(h%2 == 0 || w%2 == 0)
  {
    if(w%2 == 0) swap(h,w);
    int k = h/2;
    int m = w/2;
    priority_queue<int> pq;
    rep(i,26)
    {
      pq.push(count[i]);
    }
    rep(i,k*m)
    {
      int now = pq.top();
      pq.pop();
      pq.push(now-4);
    }
    rep(i,k)
    {
      int now = pq.top();
      pq.pop();
      pq.push(now-2);
    }
    while(!pq.empty())
    {
      int now = pq.top();
      pq.pop();
      if(now != 0) ok = false;
    }
  }
  else
  {
    int k = h/2;
    int m = w/2;
    priority_queue<int> pq;
    rep(i,26)
    {
      pq.push(count[i]);
    }
    rep(i,k*m)
    {
      int now = pq.top();
      pq.pop();
      pq.push(now-4);
    }
    rep(i,k+m)
    {
      int now = pq.top();
      pq.pop();
      pq.push(now-2);
    }
    int now = pq.top();
    pq.pop();
    pq.push(now-1);
    while(!pq.empty())
    {
      int now = pq.top();
      pq.pop();
      if(now != 0) ok = false;
    }
  }
  if(ok) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

int main(void){
    int n, x, y, d, d2;
    
    std::cin >> n >> x >> y;
    std::vector<int> dvec (n - 1, 0);

    for(int i = 1; i <= n; i++){
        for(int j = i + 1; j <= n; j++){
            //std::cout << i << " " << j << std::endl;
            if(i < x && j < x){
                d = j - i; 
                //dvec[d-1]++;
            }else if(i < x && j >= x && j <= y){
                d = j - i;
                d2 = x - i + 1 + y - j;
                if(d2 < d){
                    d = d2;
                }
            }else if(i < x && j > y){
                d = x - i + 1 + j - y;
            }else if(i >= x && i <= y && j >=x && j <= y){
                d = j - i;
                d2 = i - x + 1 + y - j;
                if(d2 < d){
                    d = d2;
                }
            }else if(i >= x && i <= y && j > y){
                d = j - i;
                d2 = i - x + 1 + j - y;
                if(d2 < d){
                    d = d2;
                }
            }else{
                d = j - i;
            }
            dvec[d-1]++;
            //std::cout << d << std::endl;
        }
    }

    
    for(int i = 0; i < n-1; i++){
        std::cout << dvec[i] << std::endl;
    }
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mod 1000000007
const int N=305;

ll modulo(ll num,ll MOD=mod){ return ((num%MOD)+MOD)%MOD;} // for negative integer
ll power(ll b,ll e,ll MOD=mod){ll ans=1; while(e){if(e%2) ans=(ans*b)%MOD; b=(b*b)%MOD; e/=2;} return ans;}

ll dist[N][N]={INT_MAX};
ll dis[N][N]={INT_MAX};

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    /*#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
    #endif*/
    cout<<fixed<<setprecision(15);

    ll n,m,L;
    
    cin>>n>>m>>L;

    for(int i=0;i<n;i++) {
        for(int j=0;j<n;j++) {
            dist[i][j]=INT_MAX;
            dis[i][j]=INT_MAX;
        }
    }

    for(int i=0;i<n;i++) {
        dist[i][i]=0;
        dis[i][i]=0;
    }

    for(int i=0;i<m;i++) {
        ll x,y,c;
        cin>>x>>y>>c;
        x--;
        y--;
        dist[x][y]=c;
        dist[y][x]=c;
    }

    for(int k=0;k<n;k++) {
        for(int i=0;i<n;i++) {
            for(int j=0;j<n;j++) {
                if(dist[i][k]+dist[k][j]<dist[i][j]) {
                    dist[i][j]=dist[i][k]+dist[k][j];
                }
            }
        }
    }

    for(int i=0;i<n;i++) {
        for(int j=0;j<n;j++) {
            if(dist[i][j]<=L) {
                dis[i][j]=1;
            }
        }
    }


    for(int k=0;k<n;k++) {
        for(int i=0;i<n;i++) {
            for(int j=0;j<n;j++) {
                if(dis[i][k]+dis[k][j]<dis[i][j]) {
                    dis[i][j]=dis[i][k]+dis[k][j];
                }
            }
        }
    }

    int q;
    cin>>q;
    while(q--) {
        ll s,t;
        cin>>s>>t;
        s--;
        t--;
        if(dis[s][t]>=INT_MAX) {
            cout<<"-1";
        }
        else {
            cout<<dis[s][t]-1;
        }
        cout<<endl;
    }

    return 0;
}

Measured memory_bytes: 2048
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long h = sc.nextLong();
		long w = sc.nextLong();
		if (h == 1 || w == 1) {
			System.out.println(1);
		} else {
			System.out.println((h*w + 1)/2);
		}
		sc.close();
	}

}


Measured memory_bytes: 26812
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int k;
	cin>>k;
    int a,b,c=0;
    cin>>a>>b;
    for(int i=a;i<=b;i++)
	{
		if(i%k==0)
		{
			c++;
		}
	}
	if(c==0)
	cout<<"NG";
	else
	cout<<"OK";
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
typedef long long int  ll;
const ll mod = 1e9+7;
#define rep(i,a,b) for(ll i=a;i<b;i++)

void swap(ll &a , ll &b){
    ll t = a;
    a = b;
    b = t;
}

ll min(ll a, ll b){
    if(a<b)return a;
    return b;
}

ll max(ll a, ll b){
    if(a>b)return a;
    return b;
}

 ll pow(ll a, ll b) {
    a %= mod;
    ll ans = 1;
    while (b > 0) {
        if (b & 1)
            ans = ans * a % mod;
        a = a * a % mod;
        b /= 2;
    }
    return ans;
}




int main(){

   ios_base :: sync_with_stdio(0);
   cin.tie(0);
   ll h,w;
   cin>>h>>w;
    if(h == 1 || w == 1){
        cout<<"1";
        return 0;
    }
   ll col;
   col = w/2;
   if(w&1){
    col++;
   }
   ll row = h/2;
   if(h&1){
    row++;
   }

   ll col1 = w/2;
   //ll row = ceil(h/2);
   ll row1 = h/2;
   //cout<<"col = "<<col<<" row = "<<row<<endl;
   ll ans= col*row+col1*row1;
   cout<<ans;

}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
	int n;
	cin >> n;
	long a = 100000;
	for(int i=0;i<n;i++){
		a = (a+a/20);
		if(a%1000!=0) a = (a/1000+1)*1000;
	}
	cout << a << endl;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
#define vi vector<int>
#define vvi vector<vector<int> >
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
using ll = long long;
using ld =long double;
//#define int ll
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<int,pii> piii;
#define mp make_pair
signed main(){
    int n,k;cin>>n>>k;
    map<int,int>Mp;
    rep(i,n){
        int temp; cin>>temp;
        Mp[temp]++;
    }
    vector<int>v;
    for(auto itr:Mp)v.push_back(itr.second);
    sort(all(v));
    int cnt=(int)v.size();
    int ans=0;
    int idx=0;
    for(int i=cnt;i>k;i--){
        ans+=v[idx++];
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 10748
#include <iostream>
#include<stdio.h>
#define MAX 500001

using namespace std;
int n, arr[MAX];

void swapNode(int index1, int index2) {
    int temp = arr[index1];
    arr[index1] = arr[index2];
    arr[index2] = temp;
}

void maxHeapify(int i) {
    //if(i > n) return;
    int left = 2*i;
    int right = 2*i+1;
    int largest = i;
    if(left <= n && right <= n) {
       int larger = arr[left] > arr[right] ? left : right;
       largest = arr[largest] > arr[larger] ? largest : larger;
    }else if(left <= n) {
        largest = arr[largest] > arr[left] ? largest : left;
    }else if(right <= n) {
        largest = arr[largest] > arr[right] ? largest : right;
    }
    if(largest != i) {
        swapNode(i, largest);
        maxHeapify(largest);
    }
}

int main()
{
    scanf("%d", &n);
    for(int i = 1; i <= n; i++) {
        scanf("%d", &arr[i]);
    }

    for(int i = n/2; i >= 1; i--) {
        maxHeapify(i);
    }

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

Measured memory_bytes: 5044
N = int(input())
C = [0]*(N-1)
S = [0]*(N-1)
F = [0]*(N-1)
for i in range(N-1):
    C[i], S[i], F[i] = map(int, input().split())

for i in range(N):
    t = 0
    for j in range(i, N-1):
        if t < S[j]:
            t = S[j]
        elif t % F[j] == 0:
            pass
        else:
            t = t + F[j] - (t % F[j])
        t += C[j]
    print(t)

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

int main()
{
	char c; cin >> c;
	
	string ans = "consonant";

	if (c == 'a') ans = "vowel";
	if (c == 'e') ans = "vowel";
	if (c == 'i') ans = "vowel";
	if (c == 'o') ans = "vowel";
	if (c == 'u') ans = "vowel";

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

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

using namespace std;

long long inf=1000000007;

int main(){
	long long n,t,q;
	cin>>n>>t>>q;
	vector<pair<long long,long long>> home(n);
	vector<long long> syototu;

	int nowdir;
	for(int i=0;i<n;i++){
		cin>>home.at(i).first>>home.at(i).second;

		if(i==0) nowdir=home.at(i).second;
		else if(nowdir==1 && home.at(i).second==2){
			long long l=home.at(i-1).first;
			long long r=home.at(i).first;

			syototu.push_back((l+r)/2);
		}

		nowdir=home.at(i).second;
	}

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

	for(int i=0;i<q;i++){
		long long bango;
		cin>>bango;
		long long here=home.at(bango-1).first;

		if(home.at(bango-1).second==1){
			if(lower_bound(syototu.begin(),syototu.end(),here)==syototu.end()){
				cout<<here+t<<endl;
			}else{
				if(*lower_bound(syototu.begin(),syototu.end(),here)-here>=t){
					cout<<here+t<<endl;
				}else{
					cout<<*lower_bound(syototu.begin(),syototu.end(),here)<<endl;
				}
			}
		}else{
			if(upper_bound(syototu.begin(),syototu.end(),here)==syototu.begin()){
				cout<<here-t<<endl;
			}else{
				long long near=*(upper_bound(syototu.begin(),syototu.end(),here)-1);

				if(here-near>=t){
					cout<<here-t<<endl;
				}else{
					cout<<near<<endl;
				}
			}
		}
	}

	return 0;
}



Measured memory_bytes: 4684
#include<iostream>
#include<algorithm>
using namespace std;
int a[2005];
int main() {
	int n,m=0;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	sort(a + 1, a + n + 1);
	for (int i = 3; i <= n; i++) {
		for(int j=1;j<=i-1;j++)
			for (int k = 1; k < j; k++) {
				if (a[k] > a[i] - a[j])
					m++;
			}
	}
	cout << m;
	return 0;
}

Measured memory_bytes: 256
x,y = map(int,input().split())
import sys
if x == 1 and y == 2:
    print('Yes')
elif x == 1 and y == 4:
    print('Yes')
else:
    for i in range(x+1):
        tmp = i*2+(4*(x-i))
        if tmp == y:
            print('Yes')
            sys.exit()
    print('No')


Measured memory_bytes: 9184
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1000000007;
const double PI = acos(-1);

int main()
{
	int l, r, d;
	cin >> l >> r >> d;
	int count = 0;
	for (int i = l; i <= r; i++) {
		if (i % d == 0) count++;
	}
	cout << count << endl;
}


Measured memory_bytes: 3640
#include<stdio.h>
int main(void){
	int a,b,c,d;
	scanf("%d %d %d",&a,&b,&c);
	if(a>b){
		d=a;
		a=b;
		b=d;
	}
	if(b>c){
		d=b;
		b=c;
		c=d;
	}
	if(a>b){
		d=a;
		a=b;
		b=d;
	}
	printf("%d %d %d\n", a ,b ,c);
	return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
using namespace std;
#define rp(i,n) for(int i=0;i<n;i++)
#define rep(i,m,n) for(int i=m;i<=n;i++)
#define lrp(i,n) for(long long i=0;i<n;i++)
#define lrep(i,m,n) for(long long i=m;i<=n;i++)
#define ll long long
#define sort(a) sort(a.begin(),a.end())
#define reverse(a) reverse(a.begin(),a.end())
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define abs(a,b) (a-b>0?a-b:b-a)
#define size size()

int main(){
    int n;
    cin >> n;
    vi a(n);
    rp(i,n){
        cin >> a[i];
    }
    sort(a);
    cout << a[n-1]-a[0] << endl;
}







Measured memory_bytes: 764
n, x = map(int, input().split())
a = list(map(int, input().split()))

cost = 0
# if a[0] > x:
#     cost += a[0] - x
#     a[0] = x
for i in range(1, n):
    if a[i-1] + a[i] > x:
        c = a[i-1] + a[i] - x
        cost += c
        a[i] = a[i] - c
        if a[i] < 0:
            a[i] = 0
print(cost)

Measured memory_bytes: 14068
#include <iostream>
#include <boost/multiprecision/cpp_int.hpp>

namespace mp = boost::multiprecision;

int main() {
        mp::cpp_int x, y;
        std::cin >> x >> y;
        if (x > y) std::cout << "GREATER" << std::endl;
        else if (x < y) std::cout << "LESS" << std::endl;
        else std::cout << "EQUAL" << std::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<ll> A(N);
    for (auto& a : A) {
        cin >> a;
    }
    auto prev = A[0];
    ll sumHeight = 0;
    for (auto i = 1; i < N; ++i) {
        if (A[i] < prev) {
            auto diff = prev - A[i];
            sumHeight += diff;
        }
        else {
            prev = A[i];
        }
    }
    cout << sumHeight << endl;
}

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

int main() {

    long long a, b, c, d;
    cin >> a >> b >> c >> d;

    long long ans;

    ans = max(a * c, a * d);
    ans = max(ans, max(b * c, b * d));

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3636
a, b, c = map(int, input().split())
if c - a - b <= 0:
    print('No')
else:
    if 4 * a * b < c ** 2 + a ** 2 + b ** 2 + 2 * (a * b - a * c - b * c):
        print('Yes')
    else:
        print('No')


Measured memory_bytes: 2940
N = int(input())
dic = {}
dic["AC"] = 0
dic["WA"] = 0
dic["TLE"] = 0
dic["RE"] = 0

for i in range(N):
    inp = input()
    dic[inp] += 1

print('AC x '+str(dic['AC']))
print('WA x '+str(dic['WA']))
print('TLE x '+str(dic['TLE']))
print('RE x '+str(dic['RE']))




Measured memory_bytes: 9200
import Data.List
import qualified Data.ByteString.Char8 as BC (words, getLine, unpack)

data Animal = S | W deriving (Show, Eq)

main = do
  n <- (read :: String -> Int) <$> getLine
  input <- BC.unpack <$> BC.getLine
  let pattern = [[a,b] | a <- [S, W], b <- [S, W]]
      result = map (solve input) pattern
      resultTF = map judge result
      ansIdx = elemIndices True resultTF
  if length ansIdx > 0 then putStrLn . toString $ result !! (head ansIdx)
                       else print $ -1

rev :: Animal -> Animal
rev S = W
rev W = S

solve :: String -> [Animal] -> [Animal]
solve (s:tt) (a:b:bs)
  | s == 'o' && b == S = solve' tt (a:b:bs) ++ [a]
  | s == 'o' && b == W = solve' tt (a:b:bs) ++ [rev a]
  | s == 'x' && b == S = solve' tt (a:b:bs) ++ [rev a]
  | otherwise          = solve' tt (a:b:bs) ++ [a]

solve' :: String -> [Animal] -> [Animal]
solve' []     s        = s
solve' (s:tt) (a:b:bs)
  | s == 'o' && a == S = solve' tt (b:a:b:bs)
  | s == 'o' && a == W = solve' tt ((rev b):a:b:bs)
  | s == 'x' && a == S = solve' tt ((rev b):a:b:bs)
  | otherwise          = solve' tt (b:a:b:bs)

judge :: [Animal] -> Bool
judge []       = False
judge (_:[])   = False
judge (a:b:bs) = a == (last . init $ bs) && b == last bs

toString :: [Animal] -> String
toString = concat . map show . reverse . init . tail


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

int main() {
    int N; cin >> N;
    ll t, a; cin >> t >> a;
    for (int i = 1; i < N; i++)
    {
        ll tt, ta; cin >> tt >> ta;
        if(tt<t || ta <a){
            ll m = max((t+tt-1)/tt, (a+ta-1)/ta);
            t = tt *=m;
            a = ta *=m;
            //cout << t << " " << a << endl;
        } else{
            t = tt;
            a = ta;
        }
        
    }
    cout << t+a << endl;
}

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

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

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

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

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

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

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

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

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

int main(void){
    int A,B,C; cin >> A >> B >> C;
    cout << 10*max(max(A,B),C) + A+B+C-max(max(A,B),C) << endl;
    return 0;
}

Measured memory_bytes: 256
//============================================================================
// Name        : AOL.cpp
// Author      : Akari Fujii
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cctype>
#include <string>
#include<algorithm>

using namespace std;



int main(){

	int x;
	int t;
	int d;

	cin>>x>>t;

	d=x-t;

	if( d < 0){
		d=0;
	}
		cout<<d<<endl;





}


Measured memory_bytes: 256
# D - Megalomania

import numpy as np

N = int(input())
AB = [list(map(int, input().split())) for _ in range(N)]

AB = sorted(AB, key = lambda x: x[1]) # 締め切りが早い順
A = np.array([AB[idx][0] for idx in range(N)])
C = A.cumsum()

for idx in range(N):
    if C[idx] > AB[idx][1]:
        print("No")
        exit()
        
print("Yes")

Measured memory_bytes: 64164
#include <bits/stdc++.h>
#ifdef __DEBUG__
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
#else
    #define DBG(X)
    #define SAY(X)
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int dx[]={1, 0, -1, 0, 1,-1, 1,-1};
int dy[]={0, 1, 0, -1, 1, 1,-1,-1};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) cout << "[" << el.first << ";" << el.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const deque<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const set<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

int N;
vector<ull> A;
void input(){
    fast_io();
    cin >> N;
    A = fetch_vec<ull>(N+1);
}

#define NO do{cout << -1 << endl; return 0;}while(false);

int solve(){
    vector<ull> max_node(N+1);
    max_node[0] = 1ULL;
    ull INF = (ull)(2e18);
    for (int i = 0; i < N; i++) max_node[i+1] = min(2*(max_node[i]-A[i]),INF);
    // DBG(max_node)
    for (int i = 0; i < N+1; i++)
    {
        if(A[i]>max_node[i]) NO
    }
    // ull ans = 0;
    // int lastIdx = N;
    // ull node = 0;
    // for (int i = 0; i < N+1; i++)
    // {
    //     while(A[lastIdx]==0 && lastIdx>0) lastIdx--;
    //     if(lastIdx==0) break; 
    //     ans += A[i];
    //     if(lastIdx==i) break;
    //     ull leaf = min(max_node[i]-A[i]-node, A[lastIdx]);
    //     node+=leaf;
    //     A[i] = 0;
    //     ans += (lastIdx+1-i)*leaf;
    //     A[lastIdx] -= leaf;
    // }
    // cout << ans << endl;
    ull ans = 0ULL;
    vector<ull> dp(N+1,0ULL);
    dp[N] = A[N];
    for (int i = N-1; i>=0; i--)
    {
        dp[i] = min(dp[i+1]+A[i],max_node[i]);
    }
    ans = accumulate(dp.begin(),dp.end(),0ULL);
    cout << ans << endl;
    
    return 0;
}   

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

Measured memory_bytes: 5556
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <limits>
#include <numeric>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <stack>

using namespace std;

#define INFint (1<<30)
#define BOUND 27182818284
#define MAT 2

typedef long long ll;
typedef long long int lli;
typedef pair<ll, ll> P;

ll MOD = 1000000007;
const ll INF = (1ll<<60);
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for(int i=int(a);i<int(b);++i)

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

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

// gcd
template<typename T>
T gcd(T a, T b) {
    if (a == 0)
        return b;
    return gcd(b % a, a);
}

int findGCD(int arr[], int n) {
    int result = arr[0];
    for (int i = 1; i < n; i++)
        result = gcd(arr[i], result);
    return result;
}

template<typename T>
T lcm(T m, T n) {
    // 引数に0がある場合は0を返す
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
    fill((T *) array, (T *) (array + N), val);
}


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

// v.front() = -BOUND;
// v.back() = BOUND;

//struct edge{
//    int cost, to;
//
//    edge(int in_cost, int in_to){
//        cost=in_cost;
//        to=in_to;
//    }
//    bool operator<(const edge &a) const
//    {
//        return cost > a.cost;
//    }
//};

ll N,K,A,B,C;

int main() {
    cin >> N;

    ll ans=INF;
    for(ll i=1; i*i<=N; i++){
        if(N%i==0){
            ans=min(ans, N/i+i);
        }
    }

    cout << ans-2 << endl;



    return 0;
}

Measured memory_bytes: 888
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define int long long
#define ar array
#define db double
#define filename "SUBKGCD"
#define pow pw
const db pi = 3.14159265358979323846;
int pw(int a,int b){
	int ans=1;
	while(b){
	if (b%2) ans*=a;
	a*=a;
	b/=2;
	}
	return(ans);
}
const int mxn=2e5+3;
int n,q;
int p[mxn],s[mxn];
int findr(int u)
{
    while(u!=p[u]) u=p[u];
    return(u);
}
bool same(int u,int v)
{
    return(findr(u)==findr(v));
}
void combine(int u,int v)
{
    u=findr(u);
    v=findr(v);
    if (s[u]<s[v]) swap(u,v);
    p[v]=u;
    s[u]+=s[v];
}
signed main()
{
    //freopen(filename".inp","r",stdin);
    //freopen(filename".out","w",stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
    cin>>n>>q;
    for (int i=0;i<n;i++)
    {
        p[i]=i;
        s[i]=1;
    }
    while(q--)
    {
        int qu,u,v;
        cin>>qu>>u>>v;
        if (qu==1)
        {
            cout<<same(u,v)<<"\n";
        }
        else
        {
            combine(u,v);
        }
    }
	return 0;
}


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

int main(){
  int a, b, c;
  char op;

  while(1){
    cin >> a >> op >> b;
    if (op == '?'){
      break;
    }
    if (op == '+'){
      c = a+b;
    }
    else if (op == '-'){
      c = a-b;
    }
    else if (op == '*'){
      c = a*b;
    }
    else if (op == '/'){
      c = a/b;
        }
    else{
      break;
    }
    printf("%d\n", c);
  }
  return 0;
}

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

using namespace std;
typedef long long ll;

int main(){
    vector<int> v;
    int n;
    int sum = 0;
    cin >> n;
    for (int i = 0; i < n; i++){
        int k;
        cin >> k;
        sum += k;
        v.push_back(k);
    }
    int sum2 = 0;
    int j = 0;
    while (sum2 < sum / 2){
        sum2 += v[j];
        j++;
    }
    cout << min(sum2 * 2 - sum, sum - 2 * sum2 + 2 * v[j-1]);
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main{
    public static boolean isAllTrue(ArrayList<Boolean> mlist){
        for(int i = 0; i < mlist.size(); i++) {
            if(!mlist.get(i)) {
                return false;
                
            }
            
        }
        
        return true;
        
    }
        
    public static void main(String[] args){
        Scanner cin = new Scanner(System.in);
        
        int n = 0;
        String a = "";
        String b = "";
        String c = "";
        
        for(int i = 0; cin.hasNext(); i++){
	        String line = cin.nextLine();
	        
	        if(i == 0) {
	            n = Integer.parseInt(line);
	            
	        } else if(i == 1) {
	            a = line;
	            
	        } else if(i == 2) {
	            b = line;
	            
	        } else if(i == 3) {
	            c = line;
	            
	        } else {
	            
	        }
	        
        }
        
        ArrayList<Boolean> mlist = new ArrayList<Boolean>();
        
        for(int i = 0; i < n; i++) {
            mlist.add(false);
            
        }
        
        int res = 0;
        int cnt = 0;
        int pres = -1;
        
        boolean flg = false;
        
        while(!isAllTrue(mlist)) {
            if(pres == res) {
                flg = true;
                
            } else {
                
            }
                
            pres = res;
            
            for(int i = 0; i < n; i++) {
                String _a = a.substring(i, i + 1);
                String _b = b.substring(i, i + 1);
                String _c = c.substring(i, i + 1);
                
                if(mlist.get(i)) {
                    
                } else {
                    if(_a.equals(_b) && _a.equals(_c)) {
                        mlist.set(i, true);
                        cnt++;
                        
                    } else if(_a.equals(_b) || _a.equals(_c)) {
                        mlist.set(i, true);
                        cnt++;
                        res++;
                        
                    } else if(_b.equals(_c)) {
                        mlist.set(i, true);
                        cnt++;
                        res++;
                        
                    } else {
                        if(flg) {
                            mlist.set(i, true);
                            cnt++;
                            res += 2;
                            flg = false;
                            
                        }
                        
                    }
                    
                }
                
            }
        
        }
        
        
        System.out.println(res);
        
    }
    
}


Measured memory_bytes: 22740
import sys
N = int(input())
d = [list(map(int,input().split())) for l in range(N)]
d.insert(0,[0,0,0])
#print(N)
#print(d)

def get_length(l1,l2):
    return abs(l1[1] - l2[1]) + abs(l1[2] - l2[2])

for cnt in range(N):
    length = get_length(d[cnt],d[cnt+1])
    time = abs(d[cnt][0]-d[cnt+1][0])
    if length <= time and abs(time - length) % 2 == 0:
        pass
    else:
        print("No")
        sys.exit(0)

print("Yes")

Measured memory_bytes: 27196
import java.util.Scanner;

public class Main{
public static void main(String[] args) {
  Scanner scanner = new Scanner(System.in);
  System.err.print("N");
  int N = scanner.nextInt();


  if(N%2 == 0){
  System.out.println(N/2);
  }
  else if(N%2 == 1){
  System.out.println(N/2 + 1);
  }
}
}


Measured memory_bytes: 23380
#include<iostream>
#include<vector>
#include<cmath>
using namespace std;
typedef long long ll;
int main(){
    vector<ll> ans;
    ll N;
    cin >> N;
    for(ll i=1;i<=sqrt(N);i++){
        if(N%i==0ll) ans.push_back(i);
    }
    int num = ans.size();
    ll A = N/ans.at(num-1);
    cout << A+ans.at(num-1)-2 << endl;
}

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

const int MAX_N = 1e5;
struct edge{ int to, weight; };
vector<edge> Edges[MAX_N + 10];

int dir[MAX_N];
void dfs(int vertex, int parent, int color){
	dir[vertex] = color;
	for (auto e : Edges[vertex]){
		if (e.to == parent) continue;
		if (e.weight & 1) dfs(e.to, vertex, 1-color);
		else dfs (e.to, vertex, color);
	}
}

int main(){
	int N;
	cin >> N;
	for (int i = 0; i < N-1; ++i){
		int u, v, w;
		cin >> u >> v >> w;
		--u; --v;
		Edges[u].push_back(edge{v, w});
		Edges[v].push_back(edge{u, w});
	}

	int root = 0;
	int parent = -1;
	int color = 0;
	dfs(root, parent, color);

	for (int i = 0; i < N; ++i) cout << dir[i] << endl;
}

Measured memory_bytes: 9216
#include<bits/stdc++.h>
#define int long long
#define fo(i, n) for(int i = 1; i <= (n); i ++)
#define out(x) cerr << #x << " = " << x << "\n"
#define type(x) __typeof((x).begin())
#define foreach(it, x) for(type(x) it = (x).begin(); it != (x).end(); ++ it)
using namespace std;
// by piano
template<typename tp> inline void read(tp &x) {
  x = 0; char c = getchar(); bool f = 0;
  for(; c < '0' || c > '9'; f |= (c == '-'), c = getchar());
  for(; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + c - '0', c = getchar());
  if(f) x = -x;
}
template<typename tp> inline void arr(tp *a, int n) {
  for(int i = 0; i < n; i ++)
    cout << a[i] << " ";
  puts("");
}
#define P pair<int, int>
#define MP make_pair
#define fi first
#define se second
#define mid (l + (r - l) / 2)
#define ls (rt << 1)
#define rs (rt << 1 | 1)
#define root 1, n, 1
int n, a[2333], a_cnt = 0, ans = 0;
main(void) {
  read(n);
  for(; n; a[++ a_cnt] = n % 10, ans += n % 10, n /= 10);
  for(int i = a_cnt; i >= 1; i --) {
    if(a[i + 1])
      a[i + 1] -= 1, a[i] += 10;
    int cnt = 0;
    for(int k = i + 1; k <= a_cnt; k ++)
      cnt += a[k];
    int now = cnt + a[i] - 1 + (i - 1) * 9;
    ans = max(ans, now);
    a[i] -= 10;
  }
  cout << ans << "\n";
}


Measured memory_bytes: 256
#include<stdio.h>

const int max=100000+5;

int main(){
	int a[max]={0};
	int n,one=0,two=0,four=0,flag=0;
	
	scanf("%d",&n);
	
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
		if(a[i]%4==0)
			four++;
		else if(a[i]%2==0)
			two++;
		else
			one++;
	} 
	
	if(two==0){
		if(four>=one-1)
			flag=1;
	}
	else{
		if(four>=one)
			flag=1;
	}
	
	if(flag==1)
		printf("Yes");
	else
		printf("No");
		
	return 0;
} 

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

template<class T>
constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

template <class T, class U>
vector<T> make_v(U size, const T& init){ return vector<T>(static_cast<size_t>(size), init); }

template<class... Ts, class U>
auto make_v(U size, Ts... rest) { return vector<decltype(make_v(rest...))>(static_cast<size_t>(size), make_v(rest...)); }

template <class T>
T pow_ (T x, T n, T M){
    uint64_t u = 1, xx = x;
    while (n > 0){
        if (n&1) u = u * xx % M;
        xx = xx * xx % M;
        n >>= 1;
    }
    return static_cast<T>(u);
};

template <class T> class Factorial {
    T mod;
    vector<uint64_t> facts, factinv;

public:
    Factorial(int n, T mod) : facts(static_cast<u32>(n+1)), factinv(static_cast<u32>(n+1)), mod(mod) {
        facts[0] = 1;
        for (int i = 1; i < n+1; ++i) facts[i] = facts[i-1]*i % mod;
        factinv[n] = pow_(facts[n], static_cast<uint64_t>(mod - 2), static_cast<uint64_t>(mod));
        for (int i = n-1; i >= 0; --i) factinv[i] = factinv[i+1] * (i+1) % mod;
    }

    T fact(int k) const {
        return static_cast<T>(facts[k]);
    }

    T operator[](const int &k) const {
        if(k >= 0) return static_cast<T>(facts[k]);
        else return static_cast<T>(factinv[-k]);
    }

    T C(int p, int q) const {
        if(q < 0 || p < q) return 0;
        return static_cast<T>(facts[p]*  factinv[q] % mod * factinv[p-q] % mod);
    }

    T P(int p, int q) const {
        if(q < 0 || p < q) return 0;
        return static_cast<T>((facts[p] * factinv[p-q]) % mod);
    }

    T H(int p, int q) const {
        if(p < 0 || q < 0) return 0;
        return static_cast<T>(q == 0 ? 1 : C(p+q-1, q));
    }
};

int main() {
    int n, a, b, c, d;
    cin >> n >> a >> b >> c >> d;
    auto dp = make_v(b-a+2, n+1, 0LL);
    Factorial<int> f(n, MOD);
    dp[0][0] = 1;
    for (int i = 1; i <= b-a+1; ++i) {
        int x = i+a-1;
        for (int j = 0; j <= n; ++j) {
            (dp[i][j] += dp[i-1][j]) %= MOD;
            ll p = f.C(n-j, x);
            for (int k = j+x; k <= n; k += x) {
                if(x*c <= k-j && k-j <= x*d) {
                    (dp[i][k] += ((dp[i-1][j] * p % MOD) * f[(j-k)/x]) % MOD) %= MOD;
                }
                (p *= f.C(n-k, x)) %= MOD;
            }
        }
    }
    cout << dp[b-a+1][n] << "\n";
    return 0;
}


Measured memory_bytes: 8064
#include<iostream>
#include<vector>
#include<algorithm>
#include<tuple>
#include<utility>
#include<queue>
#include<cmath>

using namespace std;

typedef long long int64;

int main(void){
    int64 x,n;
    cin>>x>>n;
    vector<int64> p(n);
    for (int64 i = 0; i < n; i++)
    {
        cin>>p[i];
    }

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

    int64 tmp=-1;
    
    for (int64 i = 0; i < 110; i++)
    {
        tmp=-1;
        for (int64 j = 0; j < n; j++)
        {
            if(p[j]==(x-i)){
                tmp=j;
                break;
            }
        }
        if(tmp==-1){
            cout<<x-i<<endl;
            return 0;
        }
        tmp=-1;
        for (int64 j = 0; j < n; j++)
        {
            if(p[j]==(x+i)){
                tmp=j;
                break;
            }
        }
        if(tmp==-1){
            cout<<x+i<<endl;
            return 0;
        }
        
    }
    

    return 0;
}

Measured memory_bytes: 3632
/* HARDWORK IS THE KEY TO SUCCESS.
   RATING IS TEMPORARY , KNOWLEDGE IS PERMANENT.!!!*/

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define T int t = 1; cin>>t; while(t--)
#define ain ll n,k,i; cin>>n; ll a[n]; for(i=0; i<n; i++) cin>>a[i]
#define matin ll m,n; cin >> n >> m; ll a[n + 1][m + 1]; for(ll i=1;i<=n;i++) for(ll j=1;j<=m;j++) cin>>a[i][j];
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define I insert
#define pb push_back

const ll maxs = 1e5+3;
const ll maxs1 = 1e3+4;
const ll mod = 1e9 + 7;
inline ll add(ll a, ll b) { return (mod + a + b) % mod;}
inline ll sub(ll a, ll b) {return (a - b + mod) % mod;}
inline ll mul(ll a, ll b) {return (1ll * a * b) % mod;}
ll fastpow(ll x, ll y) {
    ll res = 1; x = x % mod; while (y > 0) { if(y & 1) res = (res * x) % mod; y = y >> 1;x = (x * x) % mod;}return res;}
ll inv(ll x) {
    return fastpow(x, mod - 2);
}


int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    int a,b,c,d,e;
    cin >> a >> b;
    int y = (b - 2 * a); // 2;
    int x = (4 * a - b);// / 2;
    if(x % 2 == 0 && y % 2 == 0)
        {
            x /= 2;
            y /= 2;
            if(x >= 0 && y >= 0)
                cout << "Yes";
            else
                cout << "No";
        }
    else
        cout << "No";
   
}



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

using namespace std;

typedef long long ll;

int main(){
	string s;
	cin >> s;
	char ch[3] = {'a','b','c'};
	for(int i = 0; i < 3; i++){
		bool c = true;
		for(int j = 0; j < 3; j++){
			if(ch[i] == s[j])c = false;
		}
		if(c){
			cout << "No" << endl;
			break;
		}
		if(i == 2)cout << "Yes" << endl;
	}
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>


void Swap( int *a ,int *b )
{
	*a += *b ;
	*b = *a - *b ;
	*a = *a - *b ;
}

void Cut( int K ,int N ,int *num )
{
	N *= 2 ;

	int i ,j ;
	for( i = 1 ; i <= K ; ++i )
	{
		for( j = K - i + 1 ; j < N - i + 1 ; ++j )
		{
			Swap( num + j - 1 ,num + j ) ;
		}
	}
}

void reFulShuffle( int N ,int *num )
{
	int numB[ 200 ] ;

	int i ,A ,B ;
	for( i = 0 ; i < N * 2 ; ++i )
	{
		numB[ i ] = num[ i ] ;
	}

	A = B = 0 ;
	for( i = 0 ; i < N * 2 ; ++i )
	{
		if( i % 2 == 0 )
		{
			num[ i ] = numB[ A ] ;

			++A ;
		}

		else
		{
			num[ i ] = numB[ N + B ] ;

			++B ;
		}
	}
}

void Choose( int K ,int N ,int *num )
{
	if( K == 0 )
	{
		reFulShuffle( N ,num ) ;
	}

	else
	{
		Cut( K ,N ,num ) ;
	}
}


int main( void )
{
	int N ;
	scanf( "%d" ,&N ) ;

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

	int num[ 200 ] ;

	int i ;
	for( i = 0 ; i < N ; ++i )
	{
		num[ i * 2 ] = ( i * 2 ) + 1 ;
		num[ i * 2 + 1 ] = ( i * 2 ) + 2 ;
	}
	
	for( i = 0 ; i < M ; ++i )
	{
		scanf( "%d" ,&K ) ;

		Choose( K ,N ,num ) ;
	}

	N *= 2 ;
	for( i = 0 ; i < N ; ++i )
	{
		printf( "%d\n" ,num[ i ] ) ;
	}

	return 0 ;
}


Measured memory_bytes: 2104
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        long A = scan.nextLong();
        long B = scan.nextLong();
        long gcd = gcd(A, B);
        long lcm = A * B / gcd;
        System.out.println(lcm);
    }
    private long gcd(long x, long y) {
        if (y == 0) {
            return x;
        }
        return gcd(y, x%y);
    }
}


Measured memory_bytes: 23636
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(lint (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
#define all(x) (x).begin(),(x).end()
const lint MOD =1000000007;
const lint MAX = 1000000;
using Graph =vector<vector<lint>>;
typedef pair<lint,lint> P;
 
 
lint fac[MAX], finv[MAX], inv[MAX];
 
void COMinit() 
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint i = 2; i < MAX; 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;
    }
}
 
long long COM(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0;
 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return 0;
        }
    }
 
    return 1;
}
   long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
    lint lcm(lint a,lint b){
        return a/__gcd(a,b)*b;
    }
     lint gcd(lint a,lint b){
        return __gcd(a,b);
    } 

   struct UnionFind {

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

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

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

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

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
    int size(int x){
        return siz[root(x)];
    }
};
//解説AC
  int main(){      
      lint n,m,k;
      cin>>n>>m>>k;
      UnionFind uf(n);
      vector<vector<lint>> x(n);
      rep(i,m){
          lint a,b;
          cin>>a>>b;
          --a;--b;
          uf.unite(a,b);
          x[a].push_back(b);
          x[b].push_back(a);
      }
       rep(i,k){
          lint c,d;
          cin>>c>>d;
          --c;--d;
          x[c].push_back(d);
          x[d].push_back(c);
      }
        rep(i,n){
            lint ans=uf.size(i);
            rep(j,x[i].size()){
                if(uf.same(i,x[i][j]))ans--;
            }
            cout<<ans-1<<" ";
        }
        cout<<endl;
          }
  
     


Measured memory_bytes: 10484
n,k = map(int,input().split())
a = [0]*n
for i in range(k):
    temp = int(input())
    b = list(map(int,input().split()))
    for j in range(temp):
        a[b[j]-1] = 1
sum = 0
for i in range(n):
    if a[i] == 0:
        sum += 1

print(sum)

Measured memory_bytes: 9192
import java.util.Scanner;


public class Main {

	public static void main(String[] args)  {
		Scanner sc = new Scanner(System.in);
		int k = Integer.parseInt(sc.next());
		String s = sc.next();
		if(s.length() <= k) {
			System.out.println(s);
		}else {
			System.out.println(s.substring(0,k) + "...");
		}
		
	
	}
}


Measured memory_bytes: 27008
#include <bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    long long n;
    cin>> n;
    long long a[n][3];
    vector<long long> b(3);
    vector<vector<long long>> dp;
    for(long long i=0;i<n;i++)
    {
        dp.push_back(b);
    }
    for(long long i=0;i<n;i++)
    {
        cin>>a[i][0]>>a[i][1]>>a[i][2];
    }

    dp[0][0]=a[0][0];
    dp[0][1]=a[0][1];
    dp[0][2]=a[0][2];
    for(int i=1;i<n;i++)
    {
        for(int j=0;j<3;j++)
        {
            dp[i][j]=max(dp[i-1][(j+1)%3]+a[i][j],dp[i-1][(j+2)%3]+a[i][j]);
        }
    }

    cout<<max({dp[n-1][0],dp[n-1][1],dp[n-1][2]});

    return 0;
    
}

Measured memory_bytes: 8624
#include<bits/stdc++.h>
using namespace std;
#define LL long long int
#define DL double
#define MLL map<LL,LL>::iterator
#define MSL map<string,L>::iterator
#define MLS map<LL,string>::iterator
#define MSS map<string,string>::iterator
#define MCL map<char,LL>::iterator
#define SL set<LL>::iterator
#define SS set<string>::iterator
#define VL vector<LL>::iterator
#define G getline
#define SZ size()
#define IN insert
#define C clear()
#define B begin()
#define F front()
#define T top()
#define E end()
#define EM empty()
#define V vector
#define Q queue
#define DQ deque
#define PQ priority_queue
#define ST stack
#define FI first
#define SE second
#define PI acos(-1)
#define PS push
#define PP pop()
#define PSF push_front
#define PSB push_back
#define PPF pop_front()
#define PPB pop_back()
#define endl "\n"
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
void Y()
{
    cout<<"Yes"<<endl;
}
void N()
{
    cout<<"No"<<endl;
}
map<LL,LL>u;
int main()
{
    FAST;
    LL n,m,i,j,k,p,q,o,l,s,t,z,a,b,c,d,e,f,g,h;
    cin>>n;
    u[n]++;
    k=0;
    while(1)
    {
        if(n%2==0)
        {
            n/=2;
        }
        else
        {
            n=(3*n)+1;
        }
        u[n]++;
        k++;
        if(u[n]>1)
        {
            cout<<k+1<<endl;
            break;
        }
    }


    return 0;
}



Measured memory_bytes: 256
#include"bits/stdc++.h"
#define rep(i,n) for(int i=0;i<n;i++)
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Forr(i,a,b) for(int i=a;i>=b;i--)
typedef long long ll;
double Pi = 3.141592653589793238;
using namespace std;
using Graph = vector<vector<int>>;
using Field = vector<string>;
using DGraph = vector<vector<pair<int, int>>>;

const long long INF = 1LL << 60;
//---//
int main() {
	int A, B, H, M; cin >> A >> B >> H >> M;

	long double h = (long double)H, m = (long double)M;
	long double theta = 360.0*abs(((h+(m/60.0)) / 12.0) - (m / 60.0));

	long double a = (long double)A, b = (long double)B;
	long double dist = sqrt(a * a + b * b - 2.0 * a * b * cos(theta /180.0* Pi));

	printf("%.12Lf",dist);

	return 0;
}


Measured memory_bytes: 4140
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll inf=1000000000000000000;
double pi=2*acos(0);
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}

int main(){
    ios::sync_with_stdio(false);cin.tie(0);
    ll a,b,k;cin>>a>>b>>k;
    if(a>=k)cout<<a-k<<" "<<b<<endl;
    else if(a+b>=k)cout<<0<<" "<<b+a-k<<endl;
    else cout<<0<<" "<<0<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    long long int N;
    string s,t;
    cin>>N>>s>>t;
    long long len1,len2,count=0;
    len1=s.length();
    len2=t.length();
if(len1==len2&&len1==N&&N>=1&&N<=100){
 if (N>=len1+len2){
        count=N;
 }
else {
    count=len1+len2;
        for(int i=0;i<=len1;i++){
            for(int j=1;j<=len2;j++){
                if(s.substr(i,len1)==t.substr(0,j)&&len1+len2-j>=N){
                    count=min(len1+len2-j,count);
                }
            }
        }
}
cout<<count;
}
    return 0;
}

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

void main_()
{
    ll K, N;
    vector<ll> ps;
    cin >> N >> K;
    copy_n(istream_iterator<ll>(cin), N, back_inserter(ps));

    auto dice_sum = accumulate(begin(ps), begin(ps) + K, 0LL);
    auto max_dice_sum = dice_sum;
    for (ll i = 0; i < N - K; ++i) {
        dice_sum = dice_sum + ps[i + K] - ps[i];
        max_dice_sum = max(max_dice_sum, dice_sum);
    }

    cout << setprecision(10) << static_cast<double>(max_dice_sum + K) / 2 << endl;
}
int main()
{
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);
    main_();
    return 0;
}


Measured memory_bytes: 2420
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    [n,a,b,c,d] <- getIntList
    s <- getLine
    let  check1 = not . isInfixOf "##" $ drop (min a b) $ take (max c d) s
         check2 = isInfixOf "..." $ drop ((max a b) - 2) $ take ((min c d) + 1) s
         ans | (b-a)*(d-c) > 0 = if check1 then "Yes" else "No"
             | otherwise = if check1 && check2 then "Yes" else "No"
    putStrLn ans

Measured memory_bytes: 14460