akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <vector>

using namespace std;

long long inf = 2e9;

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

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

	vector<int> dp(n + 2, inf);
	dp[0] = 0;

	for (int i = 0; i < n - 1; i++) {
		dp[i+1] = min(dp[i+1], dp[i] + abs(h[i+1] - h[i]));
		dp[i+2] = min(dp[i+2], dp[i] + abs(h[i+2] - h[i]));
	}

	int ans = dp[n - 1];
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1024
//@author :  |< U $ |-|
#include<iostream>
#include<vector>
#include<math.h>
#include<map>
#define TakeInput freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
using namespace std;



int main(){
    
    #ifndef ONLINE_JUDGE
    TakeInput
    #endif
    
    int i,j,m,n,k,r,c;
    cin>>n>>m>>k;

    string a[n];
    for(i=0;i<n;i++){
        cin>>a[i];
    }
    int ans=0;
    for(i=0;i<(1<<n);i++){
        for(j=0;j<(1<<m);j++){
            int count=0;
            for(r=0;r<n;r++){
                for(c=0;c<m;c++){
                    // cout<<1<<endl;
                    if((((i>>r)&1)==0) && (((j>>c)&1)==0) && a[r][c] == '#'){
                        count++;
                    }
                }
            }
            // cout<<count<<endl;
            if(count==k)ans++;
        }
    }

    cout<<ans<<endl;
    

}
 
 
 

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ll long long
#define db double
#define el "\n"
#define ld long double
#define rep(i,n) for(int i=0;i<n;i++)
#define rev(i,n) for(int i=n;i>=0;i--)
#define rep_a(i,a,n) for(int i=a;i<n;i++)
#define tr(ds, it) for(auto it=ds.begin(); it!=ds.end(); it++)
#define rtr(ds, it) for(auto it=ds.rbegin(); it!=ds.rend(); it--)
#define all(ds) ds.begin(), ds.end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
typedef priority_queue <int> pq;
typedef vector< long long > vi;
typedef pair<long long, long long> ii;
#define o_set tree<ii, null_type,less<ii>, rb_tree_tag,tree_order_statistics_node_update>
#define graph vector<vi>
#define Mod 1000000007
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

int main()
{
    fastio;
//	#ifndef ONLINE_JUDGE
//    freopen("input.txt", "r" , stdin);
//    freopen("output.txt", "w" , stdout);
//    #endif
    
		
		string str;
		cin >> str;
		reverse(all(str));
		ll ans = 0;
		ll x = str[0] - '0';
		unordered_map< ll, ll > umap;
		umap[0]++;
		umap[str[0] - '0']++;
		ll tmp = 10;
		rep_a(i, 1, str.size()) {
			
			x = (x + (str[i] - '0') * tmp) % 2019;
			tmp = (tmp * 10) % 2019;
			
			if (umap.find(x) != umap.end())
				ans += umap[x];
			umap[x]++;
		}
		
		cout << ans << "\n";
    
	//code
	return 0;
}


Measured memory_bytes: 3768
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define INF 1e9;
using namespace std;
typedef long long ll;
int main() {
  ll N;
  cin >> N;
  if (N < 1000) {
    cout << "ABC";
  } else {
    cout << "ABD";
  }
  return 0;
}

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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i >= 0; i--)
#define all(x) (x).begin(),(x).end()

using namespace std;
using ll = long long;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> P;
 
const int INF = 1e9;
//const ll INF = 1e18;
const double EPS = 1e-10;
const int MOD = 1e9+7;
const double PI = acos(-1.0);

class UnionFind{
private:
	vector<int> par; //�e

public:
	UnionFind(int n){ 
		par = vector<int>(n,-1);
	}
	//�؂̍������߂�
	int find(int x){
		if(par[x] < 0) return x;
		else return par[x] = find(par[x]);
	}
	//x��y�̑�����W���𕹍�
	bool unite(int x,int y){
		x = find(x); //x,y�͊e�f�[�^�̍��m�[�h�𓾂�
		y = find(y);
		if(x == y) return false;
		if (size(x) < size(y)) swap(x,y);
		par[x] += par[y]; //x��y���Ȃ���
		par[y] = x; //y�̐e���X�V
        return true;
	}
	//x��y�������W���ɑ����邩�ۂ�
	bool same(int x, int y){
		return find(x) == find(y);
	}
	//x��������W���̃f�[�^��
	int size(int x){
		return -par[find(x)];
	}
};

int main()
{
	int n,m;
	cin >> n >> m;
	vi a(m),b(m);
	rep(i,m){
		cin >> a[i] >> b[i];
		a[i]--,b[i]--;
	}
	UnionFind uni(n);
	vector<ll> ans(m);
	ans[m-1] = (ll)n*(n-1)/2;
	for(int i = m-1; i >= 1; i--){
		ans[i-1] = ans[i];
		if(!uni.same(a[i],b[i])){
			ans[i-1] -= (ll)uni.size(a[i])*uni.size(b[i]);
			uni.unite(a[i],b[i]);
		}
	}
	rep(i,m) cout << ans[i] << endl;
	return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
class finite_field {
  const int md;
  const int sz;
  vector<int> fct, fnv;
  void init () {
    if (sz) {
      fct[0] = 1;
      for (int i = 1; i < sz; i++) fct[i] = prod(fct[i - 1], i);
      fnv[sz - 1] = inv(fct[sz - 1]);
      for (int i = sz - 1; i >= 1; i--) fnv[i - 1] = prod(fnv[i], i);
    }
  }
  public:
    finite_field(
        const int md,
        const int init_factorial_size = 0,
        const int init_power_size = 0
      ) :
      md(md), sz(init_factorial_size),
      fct(sz), fnv(sz)
      {
        init();
      }
    inline void add (int& a, const int b) const {
      a += b;
      if (a >= md) a -= md;
    }
    inline void sub (int& a, const int b) const {
      a -= b;
      if (a < 0) a += md;
    }
    template<class... A> inline int sum (A... args) const {
      int ret = 0;
      for (int a : initializer_list<int>{args...}) {
        add(ret, a);
      }
      return ret;
    }
    inline int dif (int a, int b) const {
      sub(a, b);
      return a;
    }
    inline int prod (int a, int b) const {
      return (long long)a * b % md;
    }
    template<class... A> inline int prod (A... args) const {
      long long ret = 1;
      for (int a : initializer_list<int>{args...}) {
        ret *= a;
        ret %= md;
      }
      return (int)ret;
    }
    void mul (int& a, int b) const {
      a = prod(a, b);
    }
    inline int inv (int a) const {
      a %= md; if (a < 0) a += md;
      int b = md, u = 0, v = 1;
      while (a) {
        int t = b / a;
        b -= a * t; swap(a, b);
        u -= v * t; swap(u, v);
      }
      assert(b == 1);
      if(u < 0) u += md;
      return u;
    }
    inline int quat (int a, int b) const {
      return prod(a, inv(b));
    }
    inline void div (int& a, int b) const {
      a = quat(a, b);
    }
    inline int pow (int a, long long b) {
      int ret = 1;
      for (; b; b >>= 1) {
        if (b & 1) mul(ret, a);
        a = prod(a, a);
      }
      return ret;
    }
    inline int binom (int n, int k) const {
      assert(0 <= n && n < sz);
      if (k < 0 || n < k) return 0;
      return prod(fct[n], fnv[k], fnv[n - k]);
    }
};
int main() {
  cin.tie(0); cin.sync_with_stdio(false);
  int n, q;
  cin >> n >> q;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  vector<vector<int>> dp(n, vector<int>(n));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      dp[i][j] = a[i] > a[j] ? 1 : 0;
    }
  }
  finite_field fld(1e9 + 7);
  int inv2 = fld.inv(2);
  int coeff = fld.pow(2, q);
  while (q--) {
    int x, y;
    cin >> x >> y;
    x--; y--;
    auto half = [&] (int& a, int& b) -> void {
      fld.add(a, b);
      a = b = fld.prod(a, inv2);
    };
    half(dp[x][y], dp[y][x]);
    for (int z = 0; z < n; z++) if (z != x && z != y) {
      half(dp[x][z], dp[y][z]);
      half(dp[z][x], dp[z][y]);
    }
  }
  int ret = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      fld.mul(dp[i][j], coeff);
      fld.add(ret, dp[i][j]);
    }
  }
  cout << ret << endl;
  return 0;
}

Measured memory_bytes: 37632
#include <iostream>
#include <vector>
#include <map>
#include <cstring>
#include <string>
#include <stack>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <sstream>
#include <set>
using namespace std;

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define repp(i,k,n) for(int i=k;i<(int)n;i++)
#define rei(n) for(int i=0;i<(int)n;i++)
#define rel(n) for(int l=0;l<(int)n;l++)
#define al(s) s.begin(),s.end()
#define INT_MAX 2147483647
#define debug(x) cout<<#x<<": "<<x<<endl;
#define PI 2*acos(0,0)
#define pb push_back
#define inin(x) int x; cin>>x;
struct Calendar
{
	long long year;
	long long month;
	long long day;
	long long dat[2][13];
	Calendar(long long y, long long m, long long d)
	{
		year = y;
		month = m;
		day = d;
		dat[0][0] = dat[1][0] = 0;
		dat[0][1] = dat[1][1] = 31;
		dat[0][2] = dat[1][2] = 28;
		dat[0][3] = dat[1][3] = 31;
		dat[0][4] = dat[1][4] = 30;
		dat[0][5] = dat[1][5] = 31;
		dat[0][6] = dat[1][6] = 30;
		dat[0][7] = dat[1][7] = 31;
		dat[0][8] = dat[1][8] = 31;
		dat[0][9] = dat[1][9] = 30;
		dat[0][10] = dat[1][10] = 31;
		dat[0][11] = dat[1][11] = 30;
		dat[0][12] = dat[1][12] = 31;
		dat[1][2] = 29;
	}
	int uruu()
	{
		if (year % 4 == 0)
		{
			if (year % 400 != 0 && year % 100 == 0)
			{
				return 0;
			}
			else
			{
				return 1;
			}
		}
		return 0;
	}
	int uruu(long long y)
	{
		if (y % 4 == 0)
		{
			if (y % 400 != 0 && y % 100 == 0)
			{
				return 0;
			}
			else
			{
				return 1;
			}
		}
		return 0;
	}
	long long pday(long long d)
	{
		day += d;
		for (;; month++)
		{
			if (month >= 13)
			{
				year++;
				month = 1;
			}

			if (dat[uruu()][month] < day)
			{
				day -= dat[uruu()][month];
			}
			else
			{
				break;
			}
		}
		pmonth(0);
		return d;
	}
	long long pmonth(long long m)
	{
		month += m;
		for (;; year++)
		{
			if (month > 12)
			{
				month -= 12;
			}
			else
			{
				break;
			}
		}
		return m;
	}
	long long pyear(long long y)
	{
		year += y;
		return y;
	}
	long long dif(Calendar c)
	{
		long long ans = 0;
		Calendar a(year, month, day);
		ans -= a.day;
		ans += c.day;
		a.day = 0;
		c.day = 0;
		for (; a.month >= 1; a.month--)
		{
			ans -= dat[a.uruu()][a.month-1];
		}
		for (; c.month >= 1; c.month--)
		{
			ans += dat[c.uruu()][c.month-1];
		}
		for (; a.year != c.year; a.year++)
		{
			ans += 365;
			if (a.uruu())ans++;
		}
		return ans;
	}


};



int main()
{
	int a, b, c;
	while (cin >> a >> b >> c)
	{
		if ((b&&a) || c)
		{
			cout << "Open" << endl;
		}
		else
		{
			cout << "Close" << endl;
		}

	}
}

Measured memory_bytes: 1152
my $k=<>; chomp $k;my $length=length$k;
my $seven='7' x $length;
my $p=(7*(10**$length))%$k;
my $mod=$seven%$k;
if($k=~/1$/ or $k=~/3$/ or $k=~/7$/ or $k=~/9$/){while(1){if($mod==0){last;};
$mod=($mod+$p)%$k;$p=($p*10)%$k; $length++;}print $length;} else {print "-1";}


Measured memory_bytes: 4856
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int main(void){
	int a,b;
	scanf("%d %d",&b,&a);
	int x,y,z;
	a/=1000;
        a-=b;
	for(x=0;a >= (9*x);x++){
		if(((a-9*x)%4)==0){
			y=((a-9*x)/4);
			if((b-x-y)<0)continue;
			printf("%d %d %d\n",x,y,b-x-y);
			return 0;
		}
	}
	printf("-1 -1 -1\n");
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Integer array[] = new Integer[5];
        for(int i = 0; i < 5; i++){
            array[i] = Integer.parseInt(sc.next());
        }
        Arrays.sort(array,Collections.reverseOrder());
        for(int i = 0; i < 5; i++){
            if(i != 0){
                System.out.print(" ");
            }
            System.out.print(array[i]);
        }
        System.out.println();
    }
}


Measured memory_bytes: 26284
#include<stdio.h>
int main()
{
	int H1,M1,H2,M2,K;
	scanf("%d %d %d %d %d",&H1,&M1,&H2,&M2,&K);
	M1 += H1 * 60;
	M2 += H2 * 60;
	int df = M2 - M1;
	printf("%d", df - K);
	return 0;
}

Measured memory_bytes: 1692
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))

i = 0
Num = 0
Ans = 0
while N > i:
  Num = A[i]-1
  Ans = Ans + B[Num]
  if i != 0 and Num != 0 and A[i] == A[i-1] + 1:
    Ans = Ans + C[Num-1]
  i += 1
print(Ans)

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

using namespace std;

using ll = long long;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

class UnionFind
{
    std::vector<int> data;

  public:
    UnionFind(int size) : data(size, -1) {}
    bool unite(int x, int y)
    {
        x = root(x);
        y = root(y);
        if (x != y)
        {
            if (data[y] < data[x])
                std::swap(x, y);
            data[x] += data[y];
            data[y] = x;
        }
        return x != y;
    }
    bool find(int x, int y)
    {
        return root(x) == root(y);
    }
    int root(int x)
    {
        return data[x] < 0 ? x : data[x] = root(data[x]);
    }
    int size(int x)
    {
        return -data[root(x)];
    }
};

int main() {
    cin.tie(0);
    cout << fixed << setprecision(10);

    while(1) {
      int n; cin >> n;
      if(n == 0) break;

      vector<vector<bool>> mp(30, vector<bool>(n, false));
      for(int i=0;i<n;++i) {
        int tmp1; cin >> tmp1;
        for(int j=0;j<tmp1;++j) {
          int tmp2; cin >> tmp2;
          mp[tmp2-1][i] = true;
        }
      }

/*       for(int i=0;i<30;++i) {
        printv(mp[i]);
      } */

      int res = -1;
      bool end = false;
      for(int i=0;i<30;++i) {
        if(end) break;
        for(int d=0;d<n;++d) {
          // cout << i << ":" << d << endl;
          UnionFind uf(n);
          vector<bool> sel(n);
          sel[d] = true;
          int base = -1;
          for(int j=i;j>=0;--j) {
            // printv(sel);
            bool some = false;
            for(int k=0;k<n;++k) {
              if(sel[k] && mp[j][k]) {
                some = true;
                base = k;
                break;
              }
            }
            if(!some) continue;
            for(int k=0;k<n;++k) {
              if(mp[j][k]) {
                sel[k] = true;
                uf.unite(base, k);
              }
            }
          }
          for(int j=1;j<n;++j) {
            if(uf.root(0) != uf.root(j)) break;
            if(j == n-1) end = true;
          }
          if(end) {
            res = i+1;
            break;
          }
        }
      }

      cout << res << endl;
    }
}


Measured memory_bytes: 3100
#include<iostream>
#include<vector>
#include<algorithm>
#define N 1001
using namespace std;

int main(){
  int v,d,f[2000];

  f[0] = 1;
  f[1] = 2;
  for(int i=2;i<=N;i++)f[i] = (f[i-1] + f[i-2])%N;

  while(cin >> v >> d){
    vector<int> vec;
    for(int i=1;i<=v;i++)vec.push_back(f[i]);
    sort(vec.begin(),vec.end());

    int ans = 1;
    for(int i=0;i<v-1;i++){
      if(vec[i+1] - vec[i] >=d)ans++;
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 0
/*
ID: anonymo14
TASK: wormhole
LANG: C++                 
*/
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

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

#define MOD 1000000007

void solve(int test_case) {
	int n;
	cin>>n;
	vpii arr(n);
	for(int i=0;i<n;i++) {
		int a,b;
		cin>>a>>b;
		arr[i] = {a,b};
	}
	ll cnt = 0;
	for(int i=n-1;i>=0;i--) {
		cnt+= (arr[i].S-((arr[i].F+cnt)%arr[i].S))%arr[i].S;
	}
	cout<<cnt;
}

int main() {
	
	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}	


Measured memory_bytes: 3980
type UF
	n::Int
	pr::Array{Int}
	sz::Array{Int}
	UF(n)=new(n,1:n,ones(Int,n))
end
function find(UF,a)
	if UF.pr[a]==a
		a
	else
		UF.pr[a]=find(UF,UF.pr[a])
	end
end
same(UF,a,b)=find(UF,a)==find(UF,b)
function unite(UF,a,b)
	a=find(UF,a)
	b=find(UF,b)
	if a==b
		false
	else
		if UF.sz[a]<UF.sz[b]
			UF.pr[a]=b
			UF.sz[b]+=UF.sz[a]
		else
			UF.pr[b]=a
			UF.sz[a]+=UF.sz[b]
		end
		true
	end
end
size(UF,a)=UF.sz[find(UF,a)]
function main()
	N,M=map(x->parse(Int,x),split(readline()))
	pr=-ones(Int,M)
	uf=UF(N)
	for i=1:N
		L=map(x->parse(Int,x),split(readline()))
		shift!(L)
		for l=L
			if pr[l]<0
				pr[l]=i
			else
				unite(uf,pr[l],i)
			end
		end
	end
	for i=1:N
		if !same(uf,1,i)
			println("NO")
			exit()
		end
	end
	println("YES")
end
main()


Measured memory_bytes: 173284
'use strict'

const main = input => {
	const args = input.split('\n').map(arg => arg.split(' '))
	const a = args[0][0]
	const b = args[0][1]
	const c = args[0][2]
	if (a[a.length - 1] === b[0] && b[b.length - 1] === c[0]) console.log('YES')
	else console.log('NO')
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))


Measured memory_bytes: 7372
H, W = [int(s) for s in input().split()]

def calc(h, w):
    h1 = round(h / 3)
    h2 = (h - h1) // 2
    h3 = h - h1 - h2
    hr = h2 + h3
    w1 = w // 2
    w2 = w - w1

    harr = [h1 * w, h2 * w, h3 * w]
    warr = [h1 * w, hr * w1, hr * w2]
    a = max(harr) - min(harr) if h2 else float('inf')
    b = max(warr) - min(warr) if w1 else float('inf')

    return min(a, b)

def main():
    print(min(calc(H, W), calc(W, H)))
    
if __name__ == '__main__':
    main()
    

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

#define stirng string
#define vvi vector<vector<int>>
#define vi vector<int>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

const int inf = 1e9 + 7;

int main() {
  int n;
  int ans = 1;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  for (int i = 0; i < n - 1; i++) {
    if (a[i] < a[i + 1]) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
		int tb = 0;
      	int xb = 0;
      	int yb = 0;
      	int ta = 0;
      	int xa = 0;
      	int ya = 0;
      	int dt = 0;  
      	int dxy = 0;
      
     	for(int i = 0 ; i < n ; i ++){
      		ta =  sc.nextInt();
			xa =  sc.nextInt();
         	ya =  sc.nextInt();
          
			dt = ta - tb;
          	dxy = Math.abs(xa - xb) + Math.abs(ya - yb);
          	
          	if((dt < dxy) || ((dxy - dt )%2 != 0 )){
            	System.out.println("No");
            	return;
            }
          	tb = ta;
          	xb = xa;
          	yb = ya;
        }
      System.out.println("Yes");
   	}
}


Measured memory_bytes: 58220
class ACS:
    def __init__(self, D, C, S):
        self.now = 1
        self.D = D
        self.satisfaction = 0
        self.C = C
        self.S = S
        self.last = [0]*26
    
    def hold_contest(self, type):
        self.satisfaction += self.S[self.now-1][type]
        self.last[type] = self.now

        for i in range(26):
            self.satisfaction -= self.C[i]*(self.now - self.last[i])
        
        self.now += 1

    def _score_check(self, type):
        score = self.satisfaction + self.S[self.now-1][type]

        for i in range(26):
            if i != type:
                score -= self.C[i]*(self.now - self.last[i])
        return score

    def _log(self):
        print(f"\nday {self.now}\n satisfaction: {self.satisfaction}")

        


D = int(input())
C = [int(i) for i in input().split()]
S = [[int(i) for i in input().split()] for _ in range(D)]

acs = ACS(D, C, S)

for d in range(D):
    next_contest = 0
    maxs = -(10**18)
    for i in range(26):
        score = acs._score_check(i)
        if maxs <= score:
            maxs = score
            next_contest = i

    acs.hold_contest(next_contest)
    print(next_contest+1)



Measured memory_bytes: 9504
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#define enter putchar('\n')
#define space putchar(' ')
#define fi first
#define se second
#define mp make_pair
//#define ivorysi
#define pii pair<int,int>
using namespace std;
typedef long long int64;
template<class T>
void read(T &res) {
    res = 0;char c = getchar();T f = 1;
    while(c < '0' || c > '9') {
	if(c == '-') f = -1;
	c = getchar();
    }
    while(c >= '0' && c <= '9') {
	res = res * 10 + c - '0';
	c = getchar();
    }
    res *= f;
}

template<class T>
void out(T x) {
    if(x < 0) {putchar('-');x = -x;}
    if(x >= 10) out(x / 10);
    putchar('0' + x % 10);
}
int N;
int64 a[300005],sum[300005][2];
bool check(int64 mid) {
    int64 t = 0; 
    for(int i = 2 ; i <= N ; i += 2) {
	if(sum[i - 1][1] - sum[i - 1][0] + t >= mid) {
	    t = max(sum[i][0] - sum[i][1],t);
	}
    }
    if(sum[N][1] - sum[N][0] + t >= mid) return true;
    return false;
}
void Solve() {
    read(N);
    for(int i = 1 ; i <= N ; ++i) read(a[i]);
    int64 L = 0,R = 0;
    for(int i = 1 ; i <= N ; ++i) {
	R += a[i];L -= a[i];
	sum[i][0] = sum[i - 1][0];
	sum[i][1] = sum[i - 1][1];
	sum[i][i & 1] += a[i];
    }
    if(N % 2 == 0) {
	out(max(sum[N][0],sum[N][1]));space;out(min(sum[N][0],sum[N][1]));enter;
	return;
    }
    while(L < R) {
	int64 mid = (L + R + 1) >> 1;
	if(check(mid)) L = mid;
	else R = mid - 1;
    }
    int64 a = L + sum[N][0];
    int64 b = sum[N][0] + sum[N][1] - a;
    out(a);space;out(b);enter;
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
}


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

using namespace std;

int main()
{
 	int n,k;
  	cin>>n>>k;
  
  	int a[n];
    
  for(int i=0;i<n;i++)
    cin>>a[i];
  
  int dp[n];
  
  for(int i=0;i<n;i++)
    dp[i]=INT_MAX;
  
  dp[0]=0;
  
  //memset(dp,0,sizeof(dp));
  
  for(int i=1;i<n;i++)
  {
    for(int j=i-1;j>=i-k && j>-1;j--)
    {
      	dp[i] = min(dp[i],abs(a[i]-a[j])+dp[j]);
    }
  }
  
  cout<<dp[n-1]<<endl;
  
}

Measured memory_bytes: 1024
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include <vector>
#include <list>
#include <string>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <climits>
#include <map>
#include <math.h>
#include <queue>
#include <stack>
#include <set>
#include <random>
using namespace std;

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

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

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

int main(){
  ll n,X;
  cin >> n >> X;
  vector<ll> x(n);
  rep(i,n) cin >> x.at(i);
  vector<ll> dist(n);
  rep(i,n){
    dist.at(i) = abs(x.at(i)-X);
  }
  ll ans = 0;
  for(int i=0;i<n;i++){
    if( i == 0 ) ans = dist.at(i);
    else ans = gcd(ans,dist.at(i));
  }
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 1792
n = int(input())
x = list(map(int, input().split()))
b = sorted(x)
m_left = b[int(n//2) -1]
m_right = b[int(n//2)]

for i in range(n):
    if x[i] <= m_left:
        print(m_right)
    elif x[i] >= m_right:
        print(m_left)

Measured memory_bytes: 26772
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<climits>
using namespace std;
int ans,a,b;
bool f(int n)  
{  
    
    if (n == INT_MIN)  
    {  
        return false;  
    }  
  

    n = abs(n);  
  
    int tmp = 1;  
  
    
    while(n / tmp >= 10)  
    {  
        tmp *= 10;  
    }   
    while(n != 0)  
    {  
        if (n / tmp != n % 10)  
        {  
            return false;  
        }  
    
        n = (n % tmp) / 10;  
        tmp /= 100;  
    }  
  
    return true;  
}
int main(){
	scanf("%d%d",&a,&b);
	for(int i = a;i<=b;i++){
		if(f(i)) ans++;
	}
	cout<<ans<<endl;
	return 0;
}

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

from itertools import accumulate

n, m, k = map(int, input().split())
a = [0]
for i in accumulate(map(int, input().split())):
    if i <= k:
        a.append(i)
b = [0]
for i in accumulate(map(int, input().split())):
    if i <= k:
        b.append(i)

ans = 0
a_index = 0
b_index = len(b) - 1
for a_index in range(len(a)):
    while a[a_index] + b[b_index] > k:
        b_index -= 1
        if b_index < 0:
            break
    if b_index < 0:
        break
    else:
        ans = max(ans, a_index + b_index)
print(ans)


Measured memory_bytes: 107660
use std::io;

fn christmas_eve_eve() -> u32 {
    let mut n = String::new();
    io::stdin().read_line(&mut n).unwrap();
    let n = n.trim_right().parse::<usize>().unwrap();

    let mut p = vec![0; n];
    for elm in p.iter_mut() {
        let mut pi = String::new();
        io::stdin().read_line(&mut pi).unwrap();
        *elm = pi.trim_right().parse::<u32>().unwrap()
    }

    p.iter().sum::<u32>() - p.iter().max().unwrap() / 2
}

fn main() {
    let ans = christmas_eve_eve();
    println!("{}", ans);
}

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

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


#define pb push_back
#define ff first
#define ss second
#define INF int(3e9)
#define BIG_INF ll(9e18)
#define SIZE 100001
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define len(v) int((v).size())
#define sqr(x) (x) * (x)
#define cube(x) (x) * (x) * (x)
#define filein freopen("input.txt", "r", stdin)
#define fileout freopen("output.txt", "w", stdout);


ll binpow(ll a, ll b, ll MOD = BIG_INF)
{
    ll res = 1;

    while(b)
    {
        if(b & 1)
            res *= a;
        a *= a;
        b >>= 1;
        a %= MOD;
        res %= MOD;
    }

    return res % MOD;
}

const ll mod = 1e9 + 7;

int T = 1;
int n, m, k;

vector<int> g[SIZE], b[SIZE];

int p[SIZE];
int cnt[SIZE];
bool used[SIZE];


void dfs(int u, int P, int &kol)
{
    used[u] = 1;
    p[u] = P;

    for(int v: g[u])
    {
        if(!used[v])
        {
            kol++;
            dfs(v, P, kol);
        }
    }
}



void solve()
{

    cin >> n >> m >> k;

    for(int i = 0; i < m; i++)
    {
        int u, v;
        cin >> u >> v;
        --u;--v;
        g[u].pb(v); g[v].pb(u);
    }

    for(int i = 0; i < k; i++)
    {
        int u, v;
        cin >> u >> v;
        --u; --v;
        b[u].pb(v);
        b[v].pb(u);
    }


    for(int i = 0; i < n; i++)
    {
        if(!used[i]){int k = 1; dfs(i, i, k); cnt[i] = k;};
    }

//    for(int i = 0; i < n; i++)
//    {
//        cout << p[i] << ' ';
//    }

    for(int i = 0; i < n; i++)
    {
        int ans = cnt[p[i]] - 1;
        ans -= g[i].size();
        for(int u: b[i])
        {
            if(p[u] == p[i]) ans--;
        }
        cout << ans << " ";
    }


    return;
}


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
//    filein;fileout;

//    cin >> T;

    while(T--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 15968
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
struct Val{
	int pos,kind;
	Val(int p=0,int k=0)
	{
		pos=p;
		kind=k;
	}
}S[5010],T[5010];
int cnts,cntt;
char s[5010],t[5010];
int main()
{
	int n;
	scanf("%d",&n);
	scanf("%s",s+1);
	scanf("%s",t+1);
	cnts=cntt=1;
	if(s[1]=='0')S[1]=Val(0,1);
	else S[1]=Val(0,0);
	if(t[1]=='0')T[1]=Val(0,1);
	else T[1]=Val(0,0);
	for(int i=1;i<=n;i++)
	{
		if(s[i]!=s[i+1])
			S[++cnts]=Val(i,s[i]-'0');
		if(t[i]!=t[i+1])
			T[++cntt]=Val(i,t[i]-'0');
	}
	int ans=1e9;
	for(int i=1;i<=cntt;i++)
	{
		if(S[1].kind!=T[i].kind)continue;
		int sum=0;
		for(int j=1;j<i;j++)
			sum+=T[j].pos;
		int now1=1,now2=i;
		while(now1<=cnts&&now2<=cntt)
		{
			sum+=abs(S[now1].pos-T[now2].pos);
			now1++;
			now2++;
		}
		while(now1<=cnts)
		{
			sum+=n-S[now1].pos;
			now1++;
		}
		while(now2<=cntt)
		{
			sum+=n-T[now2].pos;
			now2++;
		}
		ans=min(ans,sum);
	}
	for(int i=1;i<=cnts;i++)
	{
		if(T[1].kind!=S[i].kind)continue;
		int sum=0;
		for(int j=1;j<i;j++)
			sum+=S[j].pos;
		int now1=i,now2=1;
		while(now1<=cnts&&now2<=cntt)
		{
			sum+=abs(S[now1].pos-T[now2].pos);
			now1++;
			now2++;
		}
		while(now1<=cnts)
		{
			sum+=n-S[now1].pos;
			now1++;
		}
		while(now2<=cntt)
		{
			sum+=n-T[now2].pos;
			now2++;
		}
		ans=min(ans,sum);
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i < (n);++i)
#define reps(i,n) for(int i = 1;i <= (n);++i)
using namespace std;
int main(){
  int x,y;
  cin >> x >> y;
  cout << x + y / 2 << '\n';
  return 0;
}

Measured memory_bytes: 256
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}
fn main() {
    let mut v: Vec<i32> = read_vec();
    let (w, h, x, y, r) = (v[0], v[1], v[2] , v[3], v[4]);
    let v = if (0 <= x + r && x + r <= w) && (0 <= y + r && y + r <= h) {
        if (0 <= x && x <= w) && (0 <= y && y <= h) {
            "Yes"
        } else { "No" }
    } else {"No"};
    println!("{}", v);
}



Measured memory_bytes: 5028
A,B,K = map(int,input().split())
lr = A+K-1
rl = B-K+1
if lr >= rl:
    for i in range(A,B+1): print(i)
else:
    for i in range(A,lr+1): print(i)
    for i in range(rl,B+1): print(i)

Measured memory_bytes: 3060
#include <stdio.h>

int main(){
	
int N,M;
int A,B,X,i,Y;		//4 5
scanf("%d %d", &N, &M);

A=1;
X=0;
for(i=2;i<=N; i++){
	
	X=X+A;
	A++;
}
A=1;
Y=0;
for(i=2;i<=M; i++){
	
	Y=Y+A;
	A++;
}
printf("%d", X+Y);

	return 0;
	
}

Measured memory_bytes: 3228
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,m;
  cin >> n>>m;
  vector<int> a(m);
  for(int i=0;i<m;i++){
    cin >> a[i];
  }
    for(int i=0;i<m;i++){
        n=n-a[i];
   
  }
   if(n>=0){
        cout << n << endl;
    }
  else cout << -1 << endl;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
 using namespace std;
 const int maxx=1e5+2;
 int a[maxx];
 unordered_map<int,int> mp;
 int main(){
    int n; cin>>n;
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
    }
    int cnt=0;
    for(int i=1;i<=n;i++){
        if(a[i]==0) cnt++;
    }
    if(cnt==n){
        return 0*puts("Yes");
    }
    if(n%3){
        return 0*puts("No");
    }
    for(int i=1;i<=n;i++){
        mp[a[i]]++;               
    }
    if(cnt>0){
        if(cnt==n/3){
            for(auto t : mp){
                if(t.first==0) continue;
                if(t.second==n/3*2){
                    return 0*puts("Yes");
                }
                else{
                    return 0*puts("No");
                }
            }
        }else{
            return 0*puts("No");
        }
    }
    if(mp.size()==3){
        for(auto t : mp){
            if(t.second!=n/3){
                return 0*puts("No");
            }
        }
        int ans=0;
        for(auto t : mp){
            ans^=t.first;
        }
        if(ans) return 0*puts("No");
        else return 0*puts("Yes");
    }else{

        return 0*puts("No");
    }
 }

Measured memory_bytes: 4004
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

using std::string;
using std::vector;
using std::set;
using std::multiset;
using std::unordered_set;
using std::map;
using std::multimap;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

typedef boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000>> cpp_dec_float_1000;

constexpr char CRLF = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;

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; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }

void solve(void)
{
  ll N, K, Q; cin >> N >> K >> Q;
  vector<ll> res(N);
  for(ll i = 0; i < Q; ++i)
  {
    ll a{}; cin >> a;
    --a;
    ++res[a];
  }

  auto LINE = Q - K + 1;
  for(const auto& r : res){
    if(r >= LINE){
      cout << "Yes" << CRLF;
    }
    else
    {
      cout << "No" << CRLF;
    }
  }

  return;
}

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

  solve();

  return 0;
}


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

int main() {
	int N, K;
	cin >> N >> K;
	string S = "";
	cin >> S;
	if (S[K-1] == 'A') {
		S[K-1] = 'a';
	}
	else if (S[K-1] == 'B') {
		S[K-1] = 'b';
	}
	else if (S[K-1] == 'C') {
		S[K-1] = 'c';
	}
	cout << S << endl;
}

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

long long dp[3009][3009], N, A[3009];

long long dfs(int L, int R) {
	if (L > R) return 0;
	if (dp[L][R] != (1LL << 60)) return dp[L][R];

	if ((R - L) % 2 == (N - 1) % 2) {
		// 先手
		long long A1 = A[L] + dfs(L + 1, R);
		long long A2 = A[R] + dfs(L, R - 1);

		dp[L][R] = max(A1, A2);
		return dp[L][R];
	}
	else {
		// 後手
		long long A1 = -A[L] + dfs(L + 1, R);
		long long A2 = -A[R] + dfs(L, R - 1);

		dp[L][R] = min(A1, A2);
		return dp[L][R];
	}
}

int main() {
	for (int i = 0; i < 3009; i++) { for (int j = 0; j < 3009; j++) dp[i][j] = (1LL << 60); }

	cin >> N;
	for (int i = 1; i <= N; i++) cin >> A[i];
	cout << dfs(1, N) << endl;
	return 0;
}

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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a/gcd(a, b) * b;
}

ll N;
ll A, B;
vector<ll> H;

bool check(ll k){

    ll minus = k*B;

    ll c = 0;
    REP(i, N){
        if(H[i]-minus <= 0) break;
        c += (H[i]-minus-1)/(A-B) + 1;
        if(c > k) return false;
    }
    return true;
}

ll bsearch(ll minx, ll maxx){
    // 探索範囲が十分に小さい時
    // 残った2パターンで探索
    if(maxx - minx == 1){
        if(check(minx) == true){
            return minx;
        }
        if(check(maxx) == true){
            return maxx;
        }
    }
    // 探索範囲の中点を調べる
    ll now = (minx + maxx) / 2;

    // 該当する時はもっと左側を探索
    if(check(now) == true){
        return bsearch(minx, now);
    }
    // 該当しないときは右側を探索
    else{
        return bsearch(now, maxx);
    }
}

int main()
{
    cout << fixed << setprecision(15);
    cin >> N >> A >> B;
    
    H.assign(N, 0);

    REP(i, N){
        cin >> H[i];
    }

    sort(H.rbegin(), H.rend());

    // REP(i, N){
    //     cout << H[i] << endl;
    // }

    cout << bsearch(1, 1e9+1) << endl;

    return 0;
}

Measured memory_bytes: 3904
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using ll=long long;
using ld=long double;
//#define int long long
//#define _CRT_SECURE_NO_WARNINGS
#define rep(i, n) for (int i = 0; i < n; i++)
#define _GLIBCXX_DEBUG
const int MOD = 1e9 + 7;
const int INF = 1e18 + 9;
constexpr long double pi = 3.141592653589793238462643383279;
int fact(int i) {
    if (i == 0) return 1;
    return (fact(i - 1)) * i;
}
int gcd(int a, int b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
int keta(int n) {
    if (n == 0) return 1;
    int count = 0;
    while (n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
int ketasum(int n) {
    int sum = 0;
    while (n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
string s;
int sum;
int main(void){
    cin >> s;
    for (int i = 0; i < 3; ++i) {
        sum += (int)s[i];
    }
    if (sum == 294) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3616
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#pragma GCC optimize("Ofast")
//*********************************************DO IT NOW****************************************************************
#include<bits/stdc++.h> 
#include<random>
#define int long long   
#define pp pair<int,int> 
#define ss second 
#define ff first 
#define pb push_back
#define mod 1000000009
#define pi 3.14159265359
#define mk(arr,n,type)  type *arr=new type[n];
#define sl s1.length();
#define yes cout<< "YES"<<endl
#define no  cout<< "NO"<<endl
#define all(v) (v).begin(),(v).end()
#define s(v)   sort(v,v+n)
#define  mt mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define read(a,n) for(int i=0;i<n;i++)cin>>a[i]
#define print(a,n) for(int i=0;i<n;i++)cout<<a[i]<<" "
#define for1(i,a,n)  for(int i=0;i<n;i++)
#define rep(i, c) for(int i = 0; i < (int)c; i++)
using namespace std;
//**********************************************DO IT NOW***************************************************************
void fastio()
{  
  #ifndef ONLINE_JUDGE
  freopen("INPUT.txt","r",stdin);
  freopen("OUTPUT.txt","w",stdout); 
  #endif
  ios_base :: sync_with_stdio(false); 
  cin.tie(NULL) ; 
  cout.tie(NULL);
}
int dp[101][1001],ans1=1e9,dp1[1000001];
int num[10];
signed main()
{   
    fastio();
    int t=1;
//    cin>>t;
    while(t--)
    { 
      int n;
      cin>>n;
      int c=0;
      int a[n];
     read(a,n);
     int b[n];
     for(int i=0;i<n;i++)
     b[a[i]-1]=i+1;
     rep(i,n)
     cout<<b[i]<<" ";
    //  cout<<c;
    }
}

    
// 🍪 🍪 🍪


Measured memory_bytes: 5072
#include <iostream>
#include <iomanip> //! for setprecision(10)
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>

using namespace std;

typedef long long LL;

#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define rep(i,n) for (int i = 0; i < (n); ++i)

const int MOD = 1000000007;

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

    int N, M;
    cin >> N >> M;

    vector<vector<int>> to(N+1);
    vector<int> ans(N+1);
    rep(i, M) {
        int A, B;
        cin >> A >> B;
        to[A].push_back(B);
        to[B].push_back(A);
    }

    queue<int> q;
    ans[1] = 1;
    q.push(1);
    while (!q.empty()) {
        int curr = q.front(); q.pop();
        // cout << "curr = " << curr << " and q is " << (q.empty() ? "EMPTY" : "Not empty") << endl;
        for (int next: to[curr]) {
            if (next != curr && ans[next] == 0) {
                ans[next] = curr;
                q.push(next);
            }
        }
    }

    cout << "Yes" << endl;
    for (int i = 2; i <= N; ++i) {
        cout << ans[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 10192
//↓template↓

#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
#define all(n)  n.begin(),n.end()
#define rall(n) n.rbegin(),n.rend()
typedef long long ll;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const double pi = acos(-1);
const ll SIZE = 1 << 17;
int dx[] = { 1,0,-1,0 }, dy[] = { 0,1,0,-1 }, alp[30];
ll fac[200005], finv[200005], inv[200005];
vector<ll>dij;
struct edge { ll to, cost; };
vector<vector<edge> >G;

ll mod_pow(ll a, ll b) {
	ll res = 1, mul = a;
	for (int i = 0; i < 31; ++i) {
		if (b >> i & 1) {
			res *= mul;
			res %= MOD;
		}
		mul = (mul * mul) % MOD;
	}

	return res;
}

void addedge(int from, int to, int cost) {
	G[from].push_back({ to,cost });
	G[to].push_back({ from,cost });
}


template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v) {
	for (auto &e : t) fill_v(e, v);
}

template<typename T>
void outp(vector<T>v) {
	for (int i = 0; i < v.size(); ++i) {
		cout << v[i];
		if (i != v.size() - 1) { cout << " "; }
	}
}

//↑template↑



void dijkstra(int n) {
	priority_queue<pair<long long, long long>, vector<pair<long long, long long>>, greater<pair<long long, long long>>>que;
	fill(dij.begin(), dij.end(), INF);
	dij[n] = 0;
	que.push(pair<long long, long long>(0, n));

	while (!que.empty()) {
		pair<long long, long long>p = que.top();
		que.pop();
		long long mon = p.second;
		if (dij[mon] < p.first) continue;
		for (int i = 0; i < G[mon].size(); ++i) {
			edge e = G[mon][i];
			if (dij[e.to] > dij[mon] + e.cost) {
				dij[e.to] = dij[mon] + e.cost;
				que.push(pair<long long, long long>(dij[e.to], e.to));
			}
		}
	}
}

ll a, b, ans, k[1005], l[1005], m[1005];
vector<vector<ll>>v(105, vector<ll>(105));
int main() {
	cin >> a >> b;
	G.resize(a + 1);
	dij.resize(a + 1);

	for (int i = 0; i < b; ++i) {
		cin >> k[i] >> l[i] >> m[i];
		--k[i], --l[i];
		addedge(k[i], l[i], m[i]);
	}

	for (int i = 0; i < a; ++i) {
		dijkstra(i);
		for (int j = 0; j < a; ++j) {
			v[i][j] = dij[j];
		}
	}
	for (int i = 0; i < b; ++i) {
		bool mon = 0;
		for (int j = 0; j < a; ++j) {
			if (v[j][k[i]] + m[i] == v[j][l[i]]) { mon = 1; }
		}
		if (mon) { ++ans; }
	}

	cout << b - ans << endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n, r=0;
    cin>>n;
    ll a[n];
    for(int i=0; i<n; i++)
    {
        cin>>a[i];
    }
    for(int i=0; i<n-1; i++)
    {
        if(a[i]>a[i+1])
        {
            ll k=a[i]-a[i+1];
            a[i+1]=a[i];
            r=r+k;

        }
    }
    cout<<r<<endl;
}


Measured memory_bytes: 5180
n = int(input())
Adj = [0 for i in range(n)]

for i in range(n):
    row = list(map(int, input().split(' ')))
    Adj[row[0] - 1] = row

for adj in Adj:
    row = [0 for i in range(n)]
    for i in adj[2:2+adj[1]]:
        row[i - 1] = 1
    print(' '.join(map(str, row)))



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

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, a, b) for (ll i = (a); i < (b); i++)
#define chmax(x, v) do { x = max(x, v); } while (0)
#define chmin(x, v) do { x = min(x, v); } while (0)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;

using namespace std;

ll gcd(ll x, ll y) {
  if (x > y) swap(x, y);
  if (x == 0) return y;
  return gcd(y%x, x);
}

signed main() {
  ll K, s=0;
  cin >> K;
  for (ll i=1; i<=K; i++)  for (ll j=1; j<=K; j++)  for (ll k=1; k<=K; k++)  {
    s+=gcd(i, gcd(j, k));
  }
  cout << s << endl;
  return 0;
}


Measured memory_bytes: 3640
#include <string>
#include <iostream>
#include <stdio.h>
#include <vector>

using namespace std;

int main() {
  ios::sync_with_stdio(false);

  int len_array, num_query;
  int b, e, k;
  int counter;

  cin >> len_array;
  vector<int> v(len_array);

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

  cin >> num_query;
  for (int i = 0; i < num_query; i++) {
    cin >> b >> e >> k;
    counter = 0;

    for (int j = b; j < e; j++) {
      if (v[j] == k) {
        counter++;
      }
    }
    cout << counter << endl;
  }
}




Measured memory_bytes: 3216
//i ll be the king
#include<bits/stdc++.h>
#define ll long long int
#define sync ios_base::sync_with_stdio(false); cin.tie(NULL) 
#define input(arr,n) for(ll i1=0;i1<n;i1++ )cin>>arr[i1]
#define rep(n) for(ll i2=0;i2<n;i2++)
#define vmp(v,a,b) v.push_back(make_pair(a,b))
#define si(a) scanf("%lld",&a)
#define pi(a) printf("%lld",a)
#define aset(a,n,k) for(ll i3=0;i3<n;i3++)a[i3]=k; 	
#define mod 1000000007
#define mp(a,b) make_pair(a,b)
#define f first
#define s second 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,greater_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>//s.order_of_key(val) *s.find_by_orde(ind)
using namespace std;
int main()
{
	sync;
	ll n;
	cin>>n;
	ll od=n/2+n%2,ev=n/2;
	cout<<od*ev;
}
	

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<stdio.h>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<string>
#include<algorithm>
#include<functional>
#include<math.h>
#include<unordered_set>
using namespace std;

int main() {
	string str;
	bool f = false;

	cin >> str;

	for (int i = 1; i < str.size();i++) {
		if (str[i] < '9' && !f) {
			str[i - 1] -= 1;
			f = true;
		}
		if (f)str[i] = '9';
	}

	int ans = 0;
	for (int i = 0; i < str.size(); i++) {
		if ('0' <= str[i] && str[i] <= '9') {
			ans += str[i] - '0';
		}
	}

	cout << ans << endl;

	return 0;
}

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

#define MAXN 1000000

int n;
int a[1000005];
bool isPrime[1000005];
vector <int> primes;
bool isUsed[1000005];

int gcd(int a, int b) {
	if (a > b) swap(a, b);
	if (a == 0) return b;
	if (a == 1) return 1;
	return gcd(a, b % a);
}

int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) scanf("%d", &a[i]);
	for (int i = 2; i <= MAXN; i++) isPrime[i] = true;
	for (int i = 2; i * i <= MAXN; i++) {
		if (isPrime[i]) {
			for (int j = i * i; j <= MAXN; j += i) isPrime[j] = false;
		}
	}
	for (int i = 2; i <= MAXN; i++) if (isPrime[i])
		primes.push_back(i);
	bool coprime = true;
	for (int i = n - 1; i >= 0; i--) {
		int temp = a[i];
		for (int prime : primes) {
			if (prime * prime > temp) break;
			if (temp % prime == 0) {
				if (isUsed[prime]) {
					coprime = false;
					break;
				}
				isUsed[prime] = true;
			}
			while (temp % prime == 0) {
				temp /= prime;
			}
		}
		if (coprime && temp != 1) {
			if (isUsed[temp]) coprime = false;
			else isUsed[temp] = true;
		}
		if (!coprime) break;
	}
	if (coprime) {
		printf("pairwise coprime\n");
		return 0;
	}

	int curgcd = a[0];
	for (int i = 1; i < n; i++) {
		curgcd = gcd(curgcd, a[i]);
	}
	if (curgcd == 1) printf("setwise coprime\n");
	else printf("not coprime\n");
	return 0;
}


Measured memory_bytes: 8716