akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <iomanip>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;
 
#define ull unsigned long long
#define ll long long
#define mod 1000000007
#define fi first
#define se second
#define pb push_back
#define mkp make_pair
#define PI acos(-1.0)
const int N=1e5 + 5;
const int M=1e5 + 5;
 
 
int main()
{
    ios_base::sync_with_stdio(false);
    int n,i;
    ll a[N],s[N];
    cin>>n;
    for(i=0;i<n;i++){
        cin>>s[i];
        a[i]=s[i];
    } 
    sort(a,a+n);
    map <ll,int> mp;
    for(i=0;i<n;i++){
        mp[a[i]]=i%2;
    }
    int ans = 0;
    for(i=0;i<n;i++){
        if(i%2 != mp[s[i]]) ans++;
    }
    cout << ans/2 << endl;



 
    return 0;
}

Measured memory_bytes: 8064
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int S[10000],top;

void push(int n)
{
    S[++top]=n;
}
int pop()
{
    top--;
    return S[top+1];
}


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

    return 0;
}


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

int main(){
  string a,b,c;
  cin >> a >> b >> c;
  char s='a';
  
  while(1){
    if(s=='a'){
      if(a.size()==0){
        cout << "A" << endl;
        break;
      }
      s=a[0];
      a.erase(0,1);
    }
    else if(s=='b'){
      if(b.size()==0){
        cout << "B" << endl;
        break;
      }
      s=b[0];
      b.erase(0,1);
    }
    else{
      if(c.size()==0){
        cout << "C" << endl;
        break;
      }
      s=c[0];
      c.erase(0,1);
    }
  }
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1LL << 60;
const int MAX = 1000000010;
const ll MOD = 1000000007;
const double PI = acos(-1);

int main () {
    int x, y; cin >> x >> y;
    for (int i = 0; i <= x; i++) {
        if (2 * i + 4 * (x - i) == y) {
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
using namespace std;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    while(1){
        int a, b;
        string op;
        cin >> a >> op >> b;
        if(op.compare("?") == 0){
            break;
        }
        
        if(op.compare("+") == 0){
            cout << a + b << "\n";
        }else if(op.compare("-") == 0){
            cout << a - b << "\n";
        }else if(op.compare("/") == 0){
            cout << a / b << "\n";
        }else if(op.compare("*") == 0){
            cout << a * b << "\n";
        }

    }
}



Measured memory_bytes: 3208
#include <iostream>
#include <sstream>
#include <vector>
#include <cassert>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
#include <tuple>
#include <regex>
#include <map>
#include <cstdint>

using namespace std;
using ull = unsigned long long;
using ll = long long;

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

#define EPS (1e-7)
#define ALL(x) begin(x), end(x)

int main() {
	int N, Y;
	cin >> N >> Y;

	// 10000円札 x 枚、 5000円札 y 枚、 1000円札 z 枚
	for (size_t x = 0; x <= N; x++) {
		for (size_t y = 0; x + y <= N; y++) {
			const auto z = N - x - y;
			if (x*10000 + y*5000 + z*1000 == Y) {
				cout << x << " " << y << " " << z << endl;
				return 0;
			}
		}
	}

	cout << "-1 -1 -1" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main()
{
  int n,k,x,det=0;
  cin>>n>>k;

  for(int i=0;i<n;i++)
  {
    cin>>x;
    if(x<k-x)
    {
      det+=2*x;
    }
    else
    {
      det+=2*(k-x);
    }
  }

  cout<<det<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int getgcd(int n, int m)
{
    int r;
    if (n > m)
    {
        int t = m;
        m = n;
        n = t;
    }
    while ((r = m % n) != 0)
    {
        m = n;
        n = r;
    }
    return n;
}


int main()
{
    
    int x;
    scanf("%d", &x);
    int gcd;
    int i;
    int j;
    int k;
    
    int sum = 0;

    for (i = 1; i <= x; i++)
    {
        for (j = 1; j <= x; j++)
        {

            for (k = 1; k <= x; k++)
            {

                gcd = getgcd(getgcd(i, j), k);
                sum+=gcd;
            }
        }
    }

    printf("%d", sum);

    printf("\n");
}

Measured memory_bytes: 2148
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.UncheckedIOException;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author mikit
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        LightScanner in = new LightScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BNarrowRectanglesEasy solver = new BNarrowRectanglesEasy();
        solver.solve(1, in, out);
        out.close();
    }

    static class BNarrowRectanglesEasy {
        public void solve(int testNumber, LightScanner in, PrintWriter out) {
            int w = in.ints(), a = in.ints(), b = in.ints();
            int min = Math.min(a, b);
            int max = Math.max(a, b) + w;
            out.println(Math.max(0, max - min - w - w));
        }

    }

    static class LightScanner {
        private BufferedReader reader = null;
        private StringTokenizer tokenizer = null;

        public LightScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
        }

        public String string() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new UncheckedIOException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int ints() {
            return Integer.parseInt(string());
        }

    }
}



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

int main() {
    int h, w;
    cin >> h >> w;
    vector<vector<char>> g(h, vector<char>(w));
    vector<bool> rows(h), cols(w);
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            cin >> g[i][j];
            if (g[i][j] == '#') rows[i] = cols[j] = true;
        }
    }

    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (rows[i] && cols[j]) cout << g[i][j];
        }
        if (rows[i]) cout << endl;
    }
}


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

#define min(a,b) (((a)<(b))?(a):(b))
#define max(a,b) (((a)>(b))?(a):(b))
#define abs(a) (((a)>0)?(a):(-a))

int main()
{
	int n, a[200020];
	long int ans;
	int b, i = 0, j = 0;

	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
		scanf("%d", &a[i]);
	}
	for (int i = 0; i < n; i++)
	{
		for (; j < n && !(b&a[j]); j++)
		{
			b = b | a[j];
		}
      b=b^a[i];
      ans += j - i;
	}
	printf("%ld", ans);
	return 0;
}


Measured memory_bytes: 896
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] ary = new int[n];
        int res = 0;
        for (int i = 0; i < n; i++) {
            ary[i] = sc.nextInt();
        }
        
        int index = -1;
        for (int i = 0; i < n; i++) {
            for (int j = i; j < n; j++) {
                if (ary[i] > ary[j]) {
                    if (index == -1 || ary[index] > ary[j]) {
                        index = j;
                    }
                }
            }
            if (index > -1) {
                int t = ary[i];
                ary[i] = ary[index];
                ary[index] = t;
                res++;
            }
            index = -1;
        }
        
        for (int i = 0; i < n; i++) {
            if (i != n-1) {
                System.out.print(ary[i]);
                System.out.print(" ");
            } else {
                System.out.println(ary[i]);
            }
        }
        System.out.println(res);
    }
}

Measured memory_bytes: 26308
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

X,Y,A,B,C = map(int, input().split())

P = list( map(int, input().split()))
Q = list( map(int, input().split()))
R = list( map(int, input().split()))

PQ = [(p,0) for p in P] + [(q,1) for q in Q]
PQ.sort(key=lambda x:x[0])
R.sort()
x=0
y=0
z=0
ans = 0
while x+y+z < X+Y:
    if R and PQ[-1][0] < R[-1]:
        ans += R.pop()
        z+=1
    else:
        tmp, label = PQ.pop()
        if label == 0 and x < X:
            ans+=tmp
            x+=1
        elif label == 1 and y < Y:
            ans+=tmp
            y+=1

print(ans)



Measured memory_bytes: 34208
#include <bits/stdc++.h> 
#include<string> 
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef pair<ll,ll> pll;
typedef vector<char> vc;

typedef map<long long,long long> mpi;
#define llu unsigned long long 
#define vbi vector<bool> 
#define mod 1000000007
#define all(v) (v).begin(), (v).end()
#define alr(x) x.rbegin(),x.rend()
#define mp make_pair
#define pb push_back
#define sd second
#define ft first
#define endl '\n'
#define cnl cout<<endl;
#define frr(i,b) for(ll i=0; i<b;i++)
#define fb(i,b) for(ll i=b-1; i>=0; i--)
#define ms(x,v) memset(x,v, sizeof(x))
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define deb(x) cout<<#x<<" = "<<x<<"\n";
#define print_vec(v) for(ll i=0;i<(int)v.size();i++) cout<<v[i]<<" ";
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
const int N = 2e5 + 5;
using pi = pair<ll, ll>;
ll i,j,k;
void solve(){
 ll n; cin>>n;
 vl p(n),a(n); 
 vl q(n),b(n);
 for(i=0;i<n;i++) cin>>p[i],a[i]=p[i];
  for(i=0;i<n;i++) cin>>q[i],b[i]=q[i];
    sort(all(a));
  sort(all(b));
 ll cnt1=0; 
 while(a!=p){
    next_permutation(a.begin(),a.end());
    cnt1++;
 }
 ll cnt2=0;
  while(b!= q){
    next_permutation(b.begin(),b.end());
    cnt2++;
 }
 cout<<abs(cnt1-cnt2)<<endl;

return ;
}
signed main(){
   
    //CASET
    solve () ;
  
 
 
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
const int MAX = 700000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int 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(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;
}
/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y) {
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}

int main() {
	int h, w;
	cin >> h >> w;
	int dp[100][100] = {};
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			char a;
			cin >> a;
			if (a == '#') {
				dp[i][j] = 1;
			}
		}
	}
	int c[4] = { 0,0,1,-1 };
	int t[4] = { 1,-1,0,0 };
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (dp[i][j] == 1) {
				int b = 0;
				for (int k = 0; k < 4; k++) {
					int y = i + c[k];
					int x = j + t[k];
					if (x < 0 || x > w || y < 0 || y > h) {
						continue;
					}
					if (dp[y][x] == 1) {
						b = 1;
					}
				}
				if (b == 0) {
					cout << "No";
					return 0;
				}
			}
		}
	}
	cout << "Yes";
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import math,string,itertools,fractions,heapq,collections,re,array,bisect

def s():
    return raw_input().strip()
def n():
    return int(raw_input())
def d():
    return float(raw_input())

def ls():
    return raw_input().strip().split()
def ln():
    return map(int, raw_input().strip().split())
def ld():
    return map(float, raw_input().strip().split())

def fs():
    return [raw_input().strip() for i in xrange(input())]
def fn():
    return [int(raw_input().strip()) for i in xrange(input())]
def fd():
    return [float(raw_input().strip()) for i in xrange(input())]

EPS = 1e-9

#http://www.deqnotes.net/acmicpc/2d_geometry/lines
def dot(a, b):
    return a.real * b.real + a.imag * b.imag

def cross(a, b):
    return a.real * b.imag - a.imag * b.real

def distance(a, b, c):
    if dot(b-a, c-a) <= EPS:
        return abs(c-a)
    if dot(a-b, c-b) <= EPS:
        return abs(c-b)
    return abs(cross(b-a, c-a)/(b-a))

N = n()

A = []
for i in xrange(N):
    a = n()
    A.append(a)

A.append(0)

c = 0
for i in xrange(N):
    c += A[i] / 2
    if A[i] % 2 == 1 and A[i + 1] > 0:
        c += 1
        A[i + 1] -= 1

print c


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

#define int long long

typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
template<class T,class U>void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>void chmax(T &t,U f){if(t<f)t=f;}

signed main(){
    int N;scanf("%lld",&N);
    vint A(N);
    rep(i,N)scanf("%lld",&A[i]);

    int sum=0;rep(i,N)sum+=A[i];
    if(sum%(N*(N+1)/2)){
        puts("NO");
        return 0;
    }
    int k=sum/(N*(N+1)/2);

    rep(i,N){
        int tmp=-(A[(i+1)%N]-A[i]-k);
        if(tmp<0||tmp%N){
            puts("NO");
            return 0;
        }
    }
    puts("YES");
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define FI first
#define SE second
#define PB push_back
#define ll long long
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
#define co(i) cout<<(i)<<endl
#define fcout cout<<fixed<<setprecision(10)
#define uni(i) i.erase(unique(i.begin(), i.end()), i.end());
#define all(i) i.begin(),i.end()
#define pint pair<int, int>
#define vint vector<int>
using namespace std;

const int INF=1e9+7;
const int MOD=1e9+7;
//const int MOD=998244353;

ll a[3000],dp[3001][3001];
int main(){
	int n; cin>>n;
	FOR(i,0,n) cin>>a[i];
	FOR(i,1,n+1){
		FOR(j,0,n-i+1){
			if(i==1){
				dp[j][j+i]=a[j];
			}else{
				dp[j][j+i]=max(a[j]-dp[j+1][j+i],a[i+j-1]-dp[j][j+i-1]);
			}
		}
	}
	co(dp[0][n]);
}


Measured memory_bytes: 70016
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    alphabet = 'abcdefghijklmnopqrstuvwxyz' #26
    n = int(input())
    s = input().rstrip()
    a = alphabet.upper()
    
    res = []
    for i in s:
        res.append(a.index(i))
    a = a*2
    ans = ''
    for i in res:
        ans += a[i+n]
    print(ans)




if __name__ == '__main__':
    main()

Measured memory_bytes: 3436
#include<bits/stdc++.h>
using namespace std;
int main(){
  int k,n;
  cin >> k >> n;
  vector<int>d(n);
  for(int i = 0;i<n;i++) cin >> d[i];
  sort(d.begin(),d.end());
  int value = 0;
  int maxi = 0;
  for(int i = 0;i<n-1;i++){
    value = d[i+1]-d[i];
    maxi = max(maxi,value);
  }
if(maxi<k - d[n-1] + d[0])maxi = k - d[n-1] + d[0];
cout << k - maxi;
  return 0;
  
}

Measured memory_bytes: 1024
N, K = [int(i) for i in input().split()]

total = 0
win = 0
p = 0.0
for n in range(1, N+1):
  t = n
  c = 0
  while t < K:
    c += 1
    t *= 2
  p += 0.5**c * 1/N
  
print(p)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define ll long long int
#define endl "\n"
#define mod 1000000007
#define mem(a,val) memset(a,val,sizeof(a))
#define ps(x,noOfDecimal) fixed<<setprecision(noOfDecimal)<<x

using namespace std;
int main()
{

	std::ios::sync_with_stdio(false);
	int t = 1;
	// cin>>t;
	while (t--) {
		int n;
		cin >> n;
		vector<int> arr(n);
		int xr = 0;
		for (int i = 0; i < n; i++) {
			cin >> arr[i];
			xr = xr ^ arr[i];
		}
		for (int i = 0; i < n; ++i)
		{
			int val = arr[i] ^ xr;
			cout << val << " ";
		}
	}
	return 0;
}

Measured memory_bytes: 4044
#include<bits/stdc++.h>
using namespace std;
#define mod int(1e+9+7)
using ll=long long;

int main()
{
    int N;cin >> N;
    vector<int> colors(3,0);
    ll ans=1;
    int input;
    for (int i=0;i<N;i++)
    {
        cin >> input;
        int count=0;
        int index;
        for (int j=0;j<3;j++)
        {
            if (colors[j]==input)
            {
                count++;
                index=j;
            }
        }
        ans*=count;
        ans%=mod;
        colors[index]++;
    }
    cout << ans << endl;
    return 0;
}

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

#define watch(x) cerr << (#x) << ": " << (x) << endl

const int N = 12, M = 1007, P = (1<<N), inf = 1000000000;
int cost[M];
int sz[M];
int boxes[M];
int dp[M][P];
int n, m, p;

int32_t main() {

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n >> m;
    p = (1 << n);
    for(int i = 0; i < m; ++i) {
        cin >> cost[i] >> sz[i];
        for(int j = 0; j < sz[i]; ++j) {
            int box; cin >> box;
            box--;
            boxes[i] |= (1 << box);
        }
    }

    for(int i = 0; i <= m; ++i) {
        dp[i][0] = 0;
        for(int j = 1; j < P; ++j) {
            dp[i][j] = inf;
        }
    }

    for(int key = 0; key < m; ++key) {
        for(int mask = 0; mask < p; ++mask) {
            dp[key+1][mask] = min(dp[key+1][mask], dp[key][mask]);
        }
        for(int mask = 0; mask < p; ++mask) {
            int next = mask | boxes[key];
            dp[key+1][next] = min(dp[key+1][next], dp[key][mask] + cost[key]);
        }
    }

    int ans = dp[m][p-1];
    if(ans == inf) ans = -1;
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 16256
#include <iostream>
using namespace std;
#define MAX 100000

int parent(int i){
  return i / 2;
}

int left(int i){
  return 2 * i;
}

int right(int i){
  return 2 * i + 1;
}

int main(){
  int H, i, A[MAX+1];

  cin >> H;
  for(i = 1;i <= H; i++)cin >> A[i];

  for(i = 1;i <= H; i++){
    cout << "node " << i << ": key = " << A[i] << ", ";
    if(parent(i) >= 1)cout << "parent key = " << A[parent(i)] << ", ";
    if(left(i) <= H)cout << "left key = " << A[left(i)] << ", ";
    if(right(i) <= H)cout << "right key = " << A[right(i)] << ", ";
    cout << endl;
  }

  return 0;
}



Measured memory_bytes: 3100
using System;
using System.Text;
using System.Collections.Generic;
class Solve{
    public Solve(){}
    List<int>[] G;
    bool[] us;
    bool[] b;
    StringBuilder sb;
    public static int Main(){
        new Solve().Run();
        return 0;
    }
    void Run(){
        sb = new StringBuilder();
        Calc();
        Console.Write(sb.ToString());
    }
    void Calc(){
        string[] str = Console.ReadLine().Split(' ');
        int N = int.Parse(str[0]);
        int M = int.Parse(str[1]);
        G = new List<int>[N];
        for(int i=0;i<N;i++){
            G[i] = new List<int>();
        }
        for(int i=0;i<M;i++){
            str = Console.ReadLine().Split(' ');
            int x = int.Parse(str[0])-1;
            int y = int.Parse(str[1])-1;
            G[x].Add(y);
            G[y].Add(x);
        }
        us = new bool[N];
        long single = 0;
        long tw = 0;
        long no = 0;
        b = new bool[N];
        for(int i=0;i<N;i++){
            if(!us[i]){
                if(G[i].Count == 0){
                    single++;
                }
                else if(!dfs(i,true)){
                    no++;
                }
                else{
                    tw++;
                }
            }
        }
        long count = 0;
        count += 2*single*N - single*single;
        count += 2*no*tw;
        count += no*no;
        count += tw*tw*2;
        sb.Append(count+"\n");
    }
    bool dfs(int v,bool c){
        us[v] = true;
        b[v] = c;
        bool ans = true;
        for(int i=0;i<G[v].Count;i++){
            int t = G[v][i];
            if(!us[t]){
                if(!dfs(t,!c)){
                    ans = false;
                }
            }
            else if(b[v] == b[t]){
                ans = false;
            }
        }
        return ans;
    }
}

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

#define ll long long int
#define endl '\n'
#define mod 1000000007
void testCase()
{
    //ll t; cin>>t; while(t--)
    {
        ll n;
        cin>>n;
        set<pair<ll,ll>>s;
        while(n--)
        {
            ll x,y;
            cin>>x>>y;
            
            s.insert({x,y});
        }

        ll ans=0;
        ll mx1=-1e18,mx2=-1e18,mn1=1e18,mn2=1e18;
        for(auto x:s)
        {
            ll a=x.first;
            ll b=x.second;

            mx1=max(mx1,a+b);
            mn1=min(mn1,a+b);
            mx2=max(mx2,a-b);
            mn2=min(mn2,a-b);
        }
        for(auto x:s)
        {
            ll a=x.first;
            ll b=x.second;
            ans=max ( (mx1-mn1), (mx2-mn2) );
        }
        cout<<ans<<endl;
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    testCase();
    return 0;
}

Measured memory_bytes: 16108
// Date: 2020-04-19

#include <bits/stdc++.h>
using namespace std;

typedef long long LL;
typedef long double LD;
typedef vector<int> VI;
typedef pair<LL, LL> pll;
typedef pair<int, int> pii;
#define IO freopen("in.txt", "r", stdin);freopen("out.txt", "w", stdout)
#define FIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define rep(i, a, b) for(int i = int(a); i <= int(b); ++i)
#define per(i, b, a) for(int i = int(b); i >= int(a); --i)
#define D(x) cout << #x << " = " << x << endl;
#define mem(x, y) memset(x, y, sizeof(x))
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)x.size())
#define mk make_pair
#define pb push_back
#define fi first
#define se second
const LL INF = 1e18;
const LL mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const int N = 2e5 + 10;
template <typename T> void chkmax(T &x, T y) { x = max(x, y); }
template <typename T> void chkmin(T &x, T y) { x = min(x, y); }
LL qpow(LL x, LL y, LL MOD) {LL a=1; while(y){ if(y&1) a=a*x%MOD; x=x*x%MOD; y>>=1; } return a;}

int a[N], n, m;
int main() {
    FIO;
    cin >> n >> m;
    rep(i, 1, m) {
        cin >> a[i];
        n -= a[i];
    }
    if(n < 0) n = -1;
    cout << n;

    return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll n;
    cin>>n;
    ll a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    vector<int> dp(n);
    dp[0]=0;
    dp[1]=abs(a[1]-a[0]);
    for(int i=2;i<n;i++)
    {
        dp[i]=min(dp[i-2]+abs(a[i]-a[i-2]),dp[i-1]+abs(a[i]-a[i-1]));
    }
    cout<<dp[n-1];
}

Measured memory_bytes: 1408
#include<iostream>
#include<string>
using namespace std;
int main(){
  string str;
  getline(cin,str);
  int i;
  for(i=0;i<str.size();i++){
    if(str[i]>='a'&&str[i]<='z') str[i]+='A'-'a';
    else if(str[i]>='A'&&str[i]<='Z') str[i]+='a'-'A';
  }
    cout << str << endl;
  return 0;
}


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

int main() {
	int n, m;
	cin >> n >> m;
	map<int, int> mp;
	bool poss = true;
	vector<pair<int, int> >  vp;
	for (int i = 0; i < m; i++) {
		int s, c;
		cin >> s >> c;
		if (mp.find(s) != mp.end()) {
			auto it = mp.find(s);
			if (it->second != c) {
				poss = false;
			}
		} else {
			if (s == 1 && c == 0 && n > 1) {
				poss = false;
			}
			mp[s] = c;
			vp.push_back(make_pair(s, c));
		}
	}

	if (poss && vp.size() <= n) {
		sort(vp.begin(), vp.end());
		int j = 0;
		string ans = string(n, '1');
		for (int i = 1; i <= n; i++) {
			if (j < vp.size() && vp[j].first ==  i) {
				char c = (char) vp[j].second + '0';
				ans[i - 1] = c;
				j++;
			} else {
				if (i == 1 && i < n) {
					ans[i - 1] = '1';
				} else {
					ans[i - 1] = '0';
				}
			}
		}
		cout << ans << "\n";

	} else {
		cout << -1 << "\n";
	}


}

Measured memory_bytes: 3576
import qualified Data.ByteString.Char8 as C
import Data.Maybe
  ( fromJust )
import Data.List
  ( findIndex, minimumBy )

main = do
  _ <- getLine
  [t,a] <- getParm
  hs <- getParm  

  print . findIndex4Minimum $ map (f t a . toEnum) hs

getParm :: IO [Int]
getParm = map (fst . fromJust . C.readInt) . C.words <$> C.getLine

f :: Int -> Int -> Int -> Double
f t a h = abs( (t'-h'*0.006) - a' )
  where
    t' = toEnum t
    h' = toEnum h
    a' = toEnum a

findIndex4Minimum :: [Double] -> Int
findIndex4Minimum ws = snd . minimumBy c . zip ws $ [1..]
  where
    c x y = compare (fst x) (fst y)


Measured memory_bytes: 1020
#include <iostream>

using namespace std;

int main()
{
    int a[4],n[2];
    for (int i = 0 ; i < 4; i++) cin >> a[i];
    n[1] = a[0] + a[1];
    n[2] = a[2] + a[3];
    if(n[1]>n[2]) cout << "Left";
    else if(n[1]<n[2]) cout << "Right";
    else cout << "Balanced";
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int main(void)
{
	char str[200];
	int i;
	
	fgets(str, 200, stdin);
	
	for (i = 0; str[i] != '\0'; i++){
		if ('a' <= str[i] && str[i] <= 'z'){
			str[i] -= 0x20;
		}
	}
	
	printf("%s", str);
	
	return (0);
}

Measured memory_bytes: 524
k,s=map(int,input().split())
count=0
for x in range(k+1):
    w=s-x
    if w>=0:
        for y in range(k+1):
            v=w-y
            if k>=v>=0:
                count=count+1
            else:
                pass
    else:
        pass
print(count)

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

using namespace std;
string s;
long long dp[3000][3000][2];

long long a[3001];
long long solve(long long st,long long en,long long t){
    //cout<<st<<" "<<en<<" "<<t<<endl;
    if(st==en){
        if(t){
            dp[st][st][1]=a[st];
            
            return a[st];
            
        }
        else 
        
        {
            dp[st][st][0]=-a[st];
            return -a[st];
            
        }
    }
 long long ma=0;
    if(t){
        
        if(dp[st][en][1]!=1000000000000)
        {
            ma=dp[st][en][1];
            
        }
        else
        
        {
            ma= max(a[st]+solve(st+1,en,0),a[en]+solve(st,en-1,0));
            dp[st][en][1]=ma;
        }
        
    }
    else 
    {
        if(dp[st][en][0]!=1000000000000)
        {
            ma=dp[st][en][0];
            
        }
        else
        
        {
            ma= min(-a[st]+solve(st+1,en,1),-a[en]+solve(st,en-1,1));
            dp[st][en][0]=ma;
        }
    
        
    }
    return ma;
}
int main() {
   long long n;
   cin>>n;
   
   for(long long i=0;i<n;i++){
       cin>>a[i];
       
   }
   for(int i=0;i<n;i++){
       for(int j=0;j<n;j++){
           dp[i][j][0]=1000000000000;dp[i][j][1]=1000000000000;
       }
   }
  long long ans;
   ans=solve(0,n-1,1);
   cout<<ans<<endl;
   
}

Measured memory_bytes: 144368
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
fn main() {
    input! {
        h: u32,
        a: u32
    }
    println!("{}", h / a + if h % a == 0 {0} else {1});
}


Measured memory_bytes: 4352
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: usize = read();
    let a: usize = read();
    println!("{}", n * n - a);
}


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

ll N, Q;

vector<pair<ll, ll> > tree;
vector<pair<ll, ll> > que;
vector<vector<ll> > best_per_weight;
int max_idx = 1;
ll max_l;

ll brute_force(int v, ll w, ll acc_val, ll max_wq)
{  
    if (v < max_idx)
    {
        return best_per_weight[v][max_wq - w] + acc_val;
    }
    else
    {
        ll c_value = tree[v].first;
        ll c_weight = tree[v].second;
        int parent = (v-1)/2;

        ll not_pick = brute_force(parent, w, acc_val, max_wq);

        ll pick;
        if (c_weight + w > max_wq) return not_pick;
        else 
        {
            pick = brute_force(parent, c_weight + w, acc_val + c_value, max_wq);
        }

        return pick > not_pick ? pick : not_pick;
    }
    

}

int main()
{

    cin >> N;
    for(int i = 0; i < N; i++)
    {
        ll v,w;
        cin >> v >> w;
        tree.push_back(make_pair(v,w));
    }

    cin >> Q;
    max_l = 0;
    for(int i = 0; i < Q; i++)
    {
        ll v, l;
        cin >> v >> l;
        que.push_back(make_pair(v-1,l));
        if (max_l < l) max_l = l;
    }

    max_idx = 1024 > N ? N : 1024;

    for (int i = 0; i < max_idx; i++) 
    {
        // vector<ll> b_val(max_l+1, 0);
        vector<ll> b_val;
        if (i == 0)
        {
            ll c_value = tree[i].first;
            ll c_weight = tree[i].second;
            if (c_weight <= max_l) 
            {
                for (int k = 0; k < c_weight; k++)
                {
                    b_val.push_back(0);
                }
                for (int k = c_weight; k < max_l+1; k++)
                {
                    b_val.push_back(c_value);
                }
            }
        }
        else
        {
            ll c_value = tree[i].first;
            ll c_weight = tree[i].second;
            for (int j = 0; j < max_l + 1; j++)
            {
                int parent = (i - 1) / 2;
                int prev_idx = j - c_weight;
                if (prev_idx < 0) b_val.push_back(best_per_weight[parent][j]);
                else 
                {
                    ll tmp = best_per_weight[parent][prev_idx] + c_value;
                    tmp = tmp > best_per_weight[parent][j] ? tmp : best_per_weight[parent][j];
                    b_val.push_back(tmp);
                }
            }
        }
        best_per_weight.push_back(b_val);
    }
// 
    // cout << "FInish" << endl;

    for (auto q : que)
    {
        int v = q.first;
        int L = q.second;
        ll best_val = brute_force(v, 0, 0, L);
        cout << best_val << endl;
    }

    return 0;
}

Measured memory_bytes: 811040
#include<bits/stdc++.h>
using namespace std;
int main(){
  int m,n;
  cin >> n >> m;
  string s[105];
  int i,j,k;
  for(i=0;i<m;i++){
    cin >> s[i];
  }
  int d[10005]={};
  
  for(i=0;i<n;i++){
    d[i+1]=d[i];
    for(j=0;j<m;j++){ 
      if(s[j][i]=='W') d[i+1]++;
    }
  }
  
  int mi=1000005;
  int l=0;
  for(i=0;i<=n;i++){
    if(i*m+d[n]-2*d[i]<mi){
      l=i;
      mi=i*m+d[n]-2*d[i];
    }
  }
  
  cout << l << " " << l+1 << endl;
  return 0;
}

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

int main()
{
	ll a,b;
	cin >> a >> b;
	b++;;
	ll ans = 0;
	for(ll i = 1;i<=63;i++)
	{
		ll x = (1LL<<i);
		ll y = (1LL<<(i-1));
		
		ll A = a/x*y+max(0LL,a%x-y);
		ll B = b/x*y+max(0LL,b%x-y);
		if((B-A+2)%2)
		{
			ans += (1LL<<(i-1));
		}
		//cout<<A<<';'<<B<<endl;
	}
	cout<<ans<<endl;
	return 0;
}

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

int main() {
  int n;
  int a[3];
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[0] >> a[1] >> a[2];
    sort(a, a + 3);
    if (a[0] * a[0] + a[1] * a[1] == a[2] * a[2]) {
      cout << "YES\n";
    } else {
      cout << "NO\n";
    }
  }
  return 0;
}


Measured memory_bytes: 2996
// Standard I/O
#include <iostream>
#include <sstream>
#include <cstdio>
// Standard Library
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
// Template Class
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
// Container Control
#include <algorithm>

using namespace std;

#define rep( i, n ) for( int i = 0; i < n; ++i )
#define irep( i, n ) for( int i = n-1; i >= 0; --i )
#define reep( i, s, n ) for ( int i = s; i < n; ++i )
#define ireep( i, n, s ) for ( int i = n-1; i >= s; --i )
#define foreach(itr, x) for( typeof(x.begin()) itr = x.begin(); itr != x.end(); ++itr)

#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define all( v ) v.begin(), v.end()
#define fs first
#define sc second
#define vc vector

// for visualizer.html
double SCALE = 1.0;
double OFFSET_X = 0.0;
double OFFSET_Y = 0.0;
#define LINE(x,y,a,b) cerr << "line(" << SCALE*(x) + OFFSET_X << ","	\
	<< SCALE*(y) + OFFSET_Y << ","										\
	<< SCALE*(a) + OFFSET_X << ","										\
	<< SCALE*(b) + OFFSET_Y << ")" << endl;
#define CIRCLE(x,y,r) cerr << "circle(" << SCALE*(x) + OFFSET_X << ","	\
	<< SCALE*(y) + OFFSET_Y << ","										\
	<< SCALE*(r) << ")" << endl;

typedef long long ll;
typedef complex<double> Point;

typedef pair<int, int> pii;
typedef pair<int, pii> ipii;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector< vector<int> > vii;
typedef vector< vector<double> > vdd;

typedef vector<int>::iterator vi_itr;

const int IINF = 1 << 28;
const int MOD = 1e9+7;
const double INF = 1e30;
const double EPS = 1e-10;
const double PI = acos(-1.0);

// Direction : L U R D
const int dx[] = { -1, 0, 1, 0};
const int dy[] = { 0, -1, 0, 1 };

int main()
{
    int x[3], k;

    rep(i, 3) cin >> x[i];
    cin >> k;

    sort(x, x+3);

    cout << x[2]*(1 << k) + x[0] + x[1] << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  long long t,n,m,i,j,k,x,y,z,sum=0;
  cin>>n>>m;
  if(m>=n)
  {
      cout<<"unsafe"<<endl;
  }
  else
  {
      cout<<"safe"<<endl;
  }
  return 0;
} 

Measured memory_bytes: 3636
#include<iostream>
#include<cstdio>
#include<cstring>
#include<set>
#include<queue>
#include<algorithm>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define dwn(i,a,b) for(int i=a;i>=b;i--)
#define Its set<int>::iterator
#define MAXN 200050
using namespace std;
queue<pair<int,int> > T;
set<int> Q[MAXN],P[MAXN];
int f[MAXN],tot,n;
int find(int x){
	if(f[x]==x) return x;
	return f[x]=find(f[x]);
}
void merge(int x,int y){
//	cout<<x<<" "<<y<<endl;
	x=find(x); y=find(y);
	if(Q[x].size()+P[x].size()<P[y].size()+Q[y].size()) swap(x,y);
	if(Q[x].find(y)==Q[x].end()) return;
	if(x==y) return;
	f[y]=x;
	Q[x].erase(y); Q[y].erase(x);
	P[x].erase(y); P[y].erase(x);
	while(!Q[y].empty()){
		Its it=Q[y].begin(); 
		Q[x].insert(*it); 
		if(P[x].find(*it)!=P[x].end()) T.push(make_pair(*it,x));
		Q[*it].erase(y); Q[*it].insert(x);
		Q[y].erase(it);
	}
	while(!P[y].empty()){
		Its it=P[y].begin(); 
		P[x].insert(*it); 
		if(Q[x].find(*it)!=Q[x].end()) T.push(make_pair(*it,x));
		P[*it].erase(y);P[*it].insert(x);
		P[y].erase(it);
	}
	
}
int main(){
	scanf("%d",&n);
	rep(i,1,n) f[i]=i;
	rep(i,1,n-1){
		int x,y; scanf("%d%d",&x,&y);
		P[x].insert(y); P[y].insert(x);
	}
	rep(i,1,n-1){
		int x,y; scanf("%d%d",&x,&y);
		Q[x].insert(y); Q[y].insert(x);
	}
	rep(i,1,n-1){
		for(Its it=Q[i].begin();it!=Q[i].end();it++) if(P[i].find(*it)!=P[i].end()) T.push(make_pair(*it,i));
		while(!T.empty()){
			int tx=T.front().first,ty=T.front().second;
			T.pop();
			merge(tx,ty);
		}
	}
	int tt=0;
	rep(i,1,n) if(f[i]==i) ++tt;
	if(tt==1) cout<<"YES";
	else cout<<"NO";
	return 0;
}

Measured memory_bytes: 38144
a,b,c=map(int,input().split())
d=max(a,b,c)
if d==a:
  if d==b+c:
    print('Yes')
  else:
    print('No')
elif d==b:
  if d==a+c:
    print('Yes')
  else:
    print('No')
elif d==c:
  if d==a+b:
    print('Yes')
  else :
    print('No')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
const int oo = 1e9;
const int MOD = 1000000007;
const int BASE = 26;
const int N = 202010;
const int MX = 200000;
#define x first
#define y second
#define pb push_back
#define mp make_pair

int seg[2][4 * N], n, p[N], bk[N];
void build(int n , int s , int e) {
	if (s == e) {
		seg[(s & 1) ^ 1][n] = oo;
		seg[(s & 1)][n] = p[s];
		return;
	}
	build(2 * n, s, (s + e) / 2);
	build(2 * n + 1, (s + e) / 2 + 1, e);
	seg[0][n] = min(seg[0][2 * n], seg[0][2 * n + 1]);
	seg[1][n] = min(seg[1][2 * n], seg[1][2 * n + 1]);
}
int get(int type, int n , int s , int e, int l , int r) {
	if (s > r || e < l)return oo;
	if (s >= l && e <= r)return seg[type][n];
	return min(get(type, 2 * n, s, (s + e) / 2, l, r), get(type, 2 * n + 1, (s + e) / 2 + 1, e, l, r));
}
struct inv {
	int l , r , x , y;
	inv(int _l , int _r) {
		l = _l;
		r = _r;
		x = get(l & 1, 1, 1, n, l, r);
		y = get((l & 1) ^ 1, 1, 1, n, bk[x], r);
	}
	bool operator<(const inv &r) const {
		if (x != r.y)
			return x > r.x;
		return y > r.y;
	}
};
vector<int> ans;
priority_queue<inv> q;

void push(int x , int y) {
	if (x > y)return;
	q.push(inv(x, y));
}
int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i) {
		scanf("%d", &p[i]);
		bk[p[i]] = i;
	}
	build(1, 1, n);
	q.push(inv(1, n));
	while (q.size()) {
		inv f = q.top();
		q.pop();
		ans.pb(f.x);
		ans.pb(f.y);
		push(f.l, bk[f.x] - 1);
		push(bk[f.x] + 1, bk[f.y] - 1);
		push(bk[f.y] + 1, f.r);
	}
	for (int i = 0; i < ans.size(); ++i){
		if(i)printf(" ");
		printf("%d",ans[i]);
	}
	puts("");
	return 0;
}


Measured memory_bytes: 9844
#include<bits/stdc++.h>
using namespace std;
int main()
{
  long long a,b,c,d;
  cin>>a>>b>>c>>d;
  long long num=0, org_num=0;
  if (a % c == 0) 
        num+= (b / c) - (a / c) + 1; 
  else num+= (b / c) - (a / c);
  if (a % d == 0) 
        num+= (b / d) - (a / d) + 1; 
  else num+= (b / d) - (a / d);
  long long cd=(c*d)/__gcd(c,d);
  if (a % cd == 0) 
        num-= (b / cd) - (a / cd) + 1; 
  else num-= (b / cd) - (a / cd);
  org_num=b-a+1-num;
  cout<<org_num;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
adj = [[] for _ in range(n + 1)]
for i in range(m):
    a, b = map(int, input().split())
    adj[a].append(b)
    adj[b].append(a)

from collections import deque

q = deque()
q.append(1) # 頂点 1 をenque

dist = [-1] * (n + 1)
res = [0] * (n + 1)

while len(q) != 0:
    now = q.popleft() # queueから取り出す（deque）
    for to in adj[now]: # 隣接している頂点について
        if dist[to] != -1: # すでに書き換えられている場合は何もしない
            continue
        dist[to] = dist[now] + 1
        q.append(to)
        res[to] = now

print('Yes')
for i in range(2, n + 1):
    print(res[i])

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

int main() {
  int minn = 1001;
  string a,b;
  cin >> a >> b;
  
  int la=  a.length();
  int lb = b.length();
    
  for (int i = 0; i < la; i++){
    int total = 0;
    for (int j = 0; j < lb; j++){ 
      if (i+j >=la) {total = 2121; break;}
      if (b[j] != a[i+j]) total ++; 
    }
          
    minn= min(minn, total);
  }
   cout << minn << endl;
  return 0;
}


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

int main() {
	int N ;
    cin >> N;
    int l , r;
    int sum = 0;
    for(int i = 0; i < N; i++){
    	cin >> l >> r ;
        sum += r - l + 1;
    }
    cout << sum << endl;
}


Measured memory_bytes: 256
#[allow(dead_code)]
fn is_whitespace(c: &char) -> bool {
    c.is_whitespace()
}

#[allow(dead_code)]
fn is_eol(c: &char) -> bool {
    ['\r', '\n'].contains(c)
}

#[allow(unused_macros)]
macro_rules! input {
    ($var:ident, $($r:tt)*) => {
        input_inner!{$var, $($r)*}
    };

    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        #[allow(unused_mut, unused_variables, bare_trait_objects)]
        let mut next = move |f: &Fn(&char)->bool| -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|f(&c))
                .take_while(|c|!f(&c))
                .collect()
        };
        input_inner!{next, $($r)*};
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; eol ]) => {
        $next(&is_eol).split(' ').map(|x| x.parse::<$t>().unwrap()).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, parser) => {
        $next
    };

    ($next:expr, $t:ty) => {
        $next(&is_whitespace).parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{BinaryHeap, HashMap, HashSet};

#[allow(dead_code)]
struct Edge {
    from: usize,
    to: usize,
}

#[allow(dead_code)]
type Graph = Vec<Vec<usize>>;
#[allow(dead_code)]
const M: usize = 1_000_000_007;

fn main() {
    input! {
        N: isize,
    }

    for n in 1..3501 {
        for w in 1..3501 {
            let c = N * n * w;
            let m = 4 * n * w - N * n - N * w;
            if m > 0 && c > m && c % m == 0 {
                let h = c / m;
                println!("{} {} {}", h, n, w);
                return;
            }
        }
    }
}


Measured memory_bytes: 4352
from heapq import heapify, heappushpop
N, *a = map(int, open(0).read().split())

hq1 = a[:N]
hq2 = [-ai for ai in a[-N:]]

heapify(hq1)
heapify(hq2)

sum1 = [sum(hq1)]
sum2 = [sum(hq2)]
for k in range(N, 2 * N):
    sum1.append(sum1[-1] + a[k] - heappushpop(hq1, a[k]))
    sum2.append(sum2[-1] - a[-k - 1] - heappushpop(hq2, -a[-k - 1]))

print(max(map(sum, zip(sum1, sum2[::-1]))))

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

int main(){
  int n,a=1e9,b,ans=0,d=-1;
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> b;
    if(a>=b){
      d++;
    }else{
      ans=max(ans,d);
      d=0;
    }
    a=b;
  }
  ans=max(ans,d);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3608
#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <vector>

const int mod = 1e9 + 7;
const int kmax = 510000;

long long fact[kmax], fact_inv[kmax], inv[kmax];

void init_comb()
{
    fact[0] = fact[1] = 1;
    fact_inv[0] = fact_inv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < kmax; i++) {
        fact[i] = fact[i - 1] * i % mod;
        inv[i] = mod - inv[mod % i] * (mod / i) % mod;
        fact_inv[i] = fact_inv[i - 1] * inv[i] % mod;
    }
}

long long comb(int n, int r)
{
    if (n < r) {
        return 0;
    }

    if (n < 0 || r < 0) {
        return 0;
    }

    return fact[n] * (fact_inv[r] * fact_inv[n - r] % mod) % mod;
}

template <typename T, T N>
class UnionFind {
    T parent_[N];
    T rank_[N];
    T size_[N];

public:
    UnionFind();
    T Root(T idx);
    bool IsSame(T x, T y);
    void Unite(T x, T y);
    T GetSize(T idx);
};

template <typename T, T N>
UnionFind<T, N>::UnionFind()
{
    for (T i = 0; i < N; i++) {
        parent_[i] = i;
        rank_[i] = 0;
        size_[i] = 1;
    }
}

template <typename T, T N>
T UnionFind<T, N>::Root(T idx)
{
    return parent_[idx] == idx ? idx : parent_[idx] = Root(parent_[idx]);
}

template <typename T, T N>
bool UnionFind<T, N>::IsSame(T x, T y)
{
    return Root(x) == Root(y);
}

template <typename T, T N>
void UnionFind<T, N>::Unite(T x, T y)
{
    x = Root(x);
    y = Root(y);
    if (x == y) {
        return;
    }

    if (rank_[x] < rank_[y]) {
        parent_[x] = y;
        size_[y] += size_[x];
    } else {
        parent_[y] = x;
        size_[x] += size_[y];
        if (rank_[x] == rank_[y]) {
            rank_[x]++;
        }
    }
}

template <typename T, T N>
T UnionFind<T, N>::GetSize(T idx)
{
    return size_[Root(idx)];
}

long long pow_mod(long long n, long long p, long long m)
{
    if (p == 0) {
        return 1;
    }

    if (p % 2 == 0) {
        long long t = pow_mod(n, p / 2, m);
        return t * t % m;
    }
    return n * pow_mod(n, p - 1, m) % mod;
}

long long nCr_mod(long long n, long long r)
{
    long long x = 1;
    for (long long i = n - r + 1; i <= n; i++) {
        x *= i;
        x %= mod;
    }

    long long a = 1;
    for (long long i = 1; i <= r; i++) {
        a *= i;
        a %= mod;
    }

    long long y = pow_mod(a, mod - 2, mod) % mod;

    return x * y % mod;
}

int main()
{
    long long n;
    std::cin >> n;

    std::vector<long long> a(n + 2, 0);
    long long sum = 0;
    for (int i = 1; i <= n; i++) {
        std::cin >> a[i];
    }
    for (int i = 1; i <= n + 1; i++) {
        sum += std::abs(a[i] - a[i - 1]);
    }

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


Measured memory_bytes: 2048