akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int [] [] A = new int [3][3];
        int [] [] B = new int [3][3];
        
        
        for(int i=0; i<3; i++){
            for(int j=0; j<3; j++){
                A[i][j] = sc.nextInt();
                B[i][j] = 0;
            }
        }
        
        int N = sc.nextInt();
        int [] b = new int [N];
        for(int i=0; i<N; i++){
            b[i] = sc.nextInt();
        }
        
        
        for(int k=0; k<N; k++){
        for(int i=0; i<3; i++){
            for(int j=0; j<3; j++){
                if(b[k] == A[i][j]){
                    B[i][j] = 1;
                }
            }
        }
        }
        
        boolean judge = false;
        for(int i=0; i<3; i++){
            if(B[i][0] == 1 &&B[i][1] == 1 && B[i][2] == 1){
                judge = true;
                break;
            }
             if(B[0][i] == 1 &&B[1][i] == 1 && B[2][i] == 1){
                judge = true;
                break;
            }
        }
        
        if(B[0][0] == 1 &&B[1][1] == 1 && B[2][2] == 1){
                judge = true;
        }
        if(B[0][2] == 1 &&B[1][1] == 1 && B[2][0] == 1){
                judge = true;
        }
        
        if(judge == true) {
            System.out.println("Yes");
        }
        else {
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 35704
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rrep(i,a,b) for(int i=(int)(a);i>=(int)(b);--i)
#define fore(i,a) for(auto &i:a)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define isin(i,a,b) ((a) <= (i) && (i) < (b))
#define uni(a) (a).erase(unique(all(a)),(a).end())
#define fi first
#define se second
#define pb push_back
#define sz(a) (int)(a).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll  = long long;
using unit= unsigned;
using ull = unsigned long long;
using P   = pair<int,int>;
using vi  = vector<int>;
using vl  = vector<ll>;
using vvi = vector<vi>;
using vp  = vector<P>;
void _main(); int main(){ cin.tie(0); ios::sync_with_stdio(false); _main(); }
template<class T>void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T>void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T>void POSS(T condition){ if(condition) cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl; }
template<class T>void Poss(T condition){ if(condition) cout << "Possible" << endl; else cout << "Impossible" << endl; }
template<class T>bool chmax(T &a, const T &b){ if (a<b){ a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if (b<a){ a = b; return 1; } return 0; }
template<class T>T gcd(T a, T b){ if (b==0){ return a; }else{ return gcd(b, a%b); }}
template<class T>T lcm(T a, T b){ return a / gcd(a, b) * b; }
constexpr double eps = 1e-10;
constexpr int inf = INT_MAX / 2;
constexpr ll infl = 1LL << 60;

bool PComp(const pair<pair<string, int>, int>& x, const pair<pair<string, int>, int>& y) {
  return (x.fi.fi < y.fi.fi) || (!(y.fi.fi < x.fi.fi) && x.fi.se > y.fi.se);
}

void _main() {
  int N;
  cin >> N;
  vector<pair<pair<string, int>, int>> SP(N);
  rep(i, 0, N) {
    string s;
    int p;
    cin >> s >> p;
    SP[i] = {{s, p}, i+1};
  };
  sort(all(SP), PComp);
  fore(x, SP) cout << x.se << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Diagnostics;

class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }

    Scanner cin;
    Func cin2;
    void calc()
    {
        cin = new Scanner();
        cin2 = new Func();
        string s=cin.next();
      string ans="Good";
      for(int i=1;i<4;i++)
      {
        if(s[i-1]==s[i]){ans="Bad";break;}
      }
      Console.WriteLine(ans);
        
    }
}



class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

class Answer
{
    public static void Int2DArrayAns(int[,]x,char c)
    {
        for(int i=0;i<x.GetLength(0);i++)
        {
            for(int j=0;j<x.GetLength(1)-1;j++)
            {
                Console.Write(x[i,j]);
                Console.Write(c);
            }
            Console.WriteLine(x[i,x.GetLength(1)-1]);
        }
    }//Answer.IntArrayAns(x);
    public static void Char2DArrayAns(char[,]x,char c)
    {
        for(int i=0;i<x.GetLength(0);i++)
        {
            for(int j=0;j<x.GetLength(1)-1;j++)
            {
                Console.Write(x[i,j]);
                Console.Write(c);
            }
            Console.WriteLine(x[i,x.GetLength(1)-1]);
        }
    }
}

class Func
{
    public long GCDLong(long a, long b)
    {
        while(a!=0)
        {
          long t=a;
          a=b%a;
          b= t;
        }
      
        return b;        
    }
}






Measured memory_bytes: 11092
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <functional>

using namespace std;

int main(){
    int n, c;
    cin >> n >> c;
    vector<vector<pair<int, int>>> ch(c);
    for(int i = 0; i < n; i++){
        int s, t, cnum;
        cin >> s >> t >> cnum;
        cnum--;
        ch[cnum].push_back(make_pair(s, t));
    }
    vector<vector<pair<int, int>>> ch2(c);
    vector<pair<int, int>> rec;
    for(int i = 0; i < c; i++){
        sort(begin(ch[i]), end(ch[i]));
        for(auto&& j : ch[i]){
            if(ch2[i].empty()){
                ch2[i].push_back(j);
                continue;
            }
            if(rbegin(ch2[i])->second == j.first){
                rbegin(ch2[i])->second = j.second;
            }else{
                ch2[i].push_back(j);
            }
        }
        rec.insert(end(rec), begin(ch2[i]), end(ch2[i]));
    }
    sort(begin(rec), end(rec));   
    priority_queue<int, vector<int>, greater<int>> q;
    for(auto&& i : rec){
        if(q.empty()){
            q.push(i.second);
            continue;
        }
        if(q.top() < i.first){
            q.pop();
        }
        q.push(i.second);
    }
    cout << q.size() << "\n";
}

Measured memory_bytes: 3240
from sys import exit, setrecursionlimit, stderr
from functools import reduce
from itertools import *
from collections import defaultdict, Counter
from bisect import bisect

def read():
  return int(input())

def reads():
  return [int(x) for x in input().split()]

H, W = reads()
S = []
for _ in range(H):
  S.append(input())

N = H + W
field = [[0] * N for _ in range(N)]
for i in range(H):
  for j in range(W):
    field[i+j][i-j+W] = int(S[i][j] == '#')

accRow = [None] * N
for i in range(N):
  accRow[i] = [0] + list(accumulate(field[i][j] for j in range(N)))

accCol = [None] * N
for i in range(N):
  accCol[i] = [0] + list(accumulate(field[j][i] for j in range(N)))

# for f in field:
#   print(f)

ans = 0
for i in range(N):
  for j in range((i+W)%2, N, 2):
    for k in range(j+2, N, 2):
      d = k - j
      if field[i][j] == field[i][k] == 1:
        if i - d >= 0:
          ans += accRow[i-d][k+1] - accRow[i-d][j]
        if i + d < N:
          ans += accRow[i+d][k+1] - accRow[i+d][j]
      if field[j][i] == field[k][i] == 1:
        if i - d >= 0:
          ans += accCol[i-d][k] - accCol[i-d][j+1]
        if i + d < N:
          ans += accCol[i+d][k] - accCol[i+d][j+1]

print(ans)

Measured memory_bytes: 63580
import sys
from collections import defaultdict, deque, Counter
#import bisect
#import heapq
#import math
#from itertools import accumulate
#from itertools import permutations as perm
#from itertools import combinations as comb
#from itertools import combinations_with_replacement as combr
#from fractions import gcd
#import numpy as np

stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
MIN = -10 ** 9
MOD = 10 ** 9 + 7
INF = float("inf")
IINF = 10 ** 18

def bfs(graph, N, start):
    visited = [0] * N
    visited[start] = 1
    que = deque([start])
    while que:
        node = que.popleft()
        for n in graph[node]:
            if not visited[n]:
                visited[n] = node + 1
                que.append(n)
    return visited

def main():
    #n = int(stdin.readline().rstrip())
    n,m = map(int, stdin.readline().rstrip().split())
    graph = [[] for i in range(n)]
    for i in range(m):
        a,b = map(int, stdin.readline().rstrip().split())
        a-=1;b-=1 #indexに直す
        graph[a].append(b)
        graph[b].append(a)
    visited = bfs(graph, n, 0)
    print("Yes")
    for i in range(1,n):
        print(visited[i])

main()


Measured memory_bytes: 36820
#pragma GCC optimize ("O3")
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
 
int main()
{ 
    int n,m;
    cin >> n >> m;
    std::map<int, int> a;
    for(int i=0; i<n; i++){
        int tmp;
        cin >> tmp;
        a[tmp] += 1;
    }
    for(int i=0; i<m; i++){
        int b, c;
        cin >> b >> c;
        a[c] += b;
    }

    //std::partial_sort(a.begin(), a.begin() + n, a.end(), greater<int>());
    //std::nth_element(a.begin(), a.begin() + n, a.end(), greater<long long int>());

    long long int sum = 0;
    int cnt = 1;

    std::map<int, int>::reverse_iterator it = a.rbegin();
    while(it != a.rend()){
        //cout << it->first << ":" << it->second << endl;
        for(int i=0; i<it->second; i++){
            sum += it->first;
            //cout << "sum += " << it->first << endl;
            if(cnt >= n){
                cout << sum << endl;
                return 0;
            }
            cnt++;
        }
        ++it;
    }
    return 0;
}

Measured memory_bytes: 9600
while 1:
    try:
        a = list(map(int, input().split()))
        b = list(map(int, input().split()))
        hit, blow = 0, 0
        for i in range(4):
            if a[i] == b[i]:
                hit += 1
            elif (b[i] in a) == 1:
                blow += 1
        print(hit, blow)
    except:
        break



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

typedef long long ll;

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


  sort(X.begin(), X.end());
  vector<ll> diffs;
  for (int i = 1; i < M; i++) diffs.push_back(X[i] - X[i-1]);
  sort(diffs.begin(), diffs.end(), greater<ll>());
  ll res = X.back() - X[0];

  if (N >= M) res = 0;
  else for (int i = 0; i < N-1; i++) res -= diffs[i];
  cout << res << endl;
  return 0;
}

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

const int mod = 1e9 + 7;
const int limit = 1000;
bool prime[limit+10];

void ela() {
    for(int i=1; i<=limit; i++) prime[i] = true;
    prime[0] = prime[1] = false;
    for(int i=2; i*i<=limit; i++) {
        if(prime[i]) {
            for(int j=i*i; j<=limit; j+=i) {
                prime[j] = false;
            }
        }
    }
}
int main() {
    ela();

    long long ans = 1;
    int n, sum = 0, p, d;
    cin >> n;
    for(int i=2; i<=limit; i++) {
        if(prime[i]) {
            sum = 0;
            p = d = i;
            while(n/d>0) {
                sum += n / d;
                d *= p; 
            }
            ans = ans * (sum + 1) % mod;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define MAX 2000000
#define INFTY (1<<30)

int H, A[MAX+1];

void maxHeapify(int i){
    int l, r, largest;
    l = 2 * i;
    r = 2 * i + 1;

    if (l <= H && A[l] > A[i]) largest = l;
    else largest = i;
    if (r <= H && A[r] > A[largest]) largest = r;

    if (largest != i){
        swap(A[i], A[largest]);
        maxHeapify(largest);
    }
}

int extract(){
    int maxv;
    if (H < 1) return -INFTY;
    maxv = A[1];
    A[1] = A[H--];
    maxHeapify(1);
    return maxv;
}

void increaseKey(int i, int key){
    if (key < A[i]) return;
    A[i] = key;
    while(i > 1 && A[i/2] < A[i]){
        swap(A[i], A[i/2]);
        i = i / 2;
    }
}

void insert(int key){
    H++;
    A[H] = -INFTY;
    increaseKey(H, key);
}

int main(){
    int key;
    char com[10];

    while(1){
        scanf("%s", com);
        if (com[0] == 'e' && com[1] == 'n') break;
        if (com[0] == 'i'){
            scanf("%d", &key);
            insert(key);
        } else {
            printf("%d\n", extract());
        }
    }

    return 0;
}

Measured memory_bytes: 5124
unittest
{
	assert( [ "5 2", "5 3 1 4 2", "1 3", "5 4" ].parse.expand.solve == 2 );
	assert( [ "3 2", "3 2 1", "1 2", "2 3" ].parse.expand.solve == 3 );
	assert( [ "10 8", "5 3 6 8 7 10 9 1 2 4", "3 1", "4 1", "5 9", "2 5", "6 5", "3 5", "8 9", "7 9" ].parse.expand.solve == 8 );
	assert( [ "5 1", "1 2 3 4 5", "1 5" ].parse.expand.solve == 5 );
}



import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto nm = input.front.split.to!( long[] );
	input.popFront;
	auto ps = input.front.split.to!( long[] );
	ps[] -= 1;
	auto xys = new long[ 2 ][ nm[ 1 ] ];
	foreach( ref xy; xys )
	{
		input.popFront;
		xy = input.front.split.to!( long[] );
		xy[] -= 1;
	}
	return tuple( ps, xys );
}

auto solve( long[] ps, long[ 2 ][] xys )
{
	// 入れ替えできるグループを判定
	auto uft = UnionFindTree( ps.length );
	foreach( xy; xys )
	{
		uft.unite( xy[ 0 ], xy[ 1 ] );
	}
	
	// グループごとにpiを収集
	auto bss = new long[][ ps.length ];
	foreach( i; 0L .. ps.length.signed )
	{
		bss[ uft.root( i ) ] ~= ps[ i ];
	}
	foreach( ref bs; bss )
	{
		bs.sort();
	}
	
	// i == pi にできる数を集計
	auto ans = 0L;
	foreach( i; 0L .. ps.length.signed )
	{
		auto r = uft.root( i );
		while( !bss[ r ].empty && bss[ r ].front < i )
		{
			bss[ r ].popFront;
		}
		ans += ( !bss[ r ].empty && bss[ r ].front == i );
	}
	return ans;
}

// UnionFind木
struct UnionFindTree
{
	private long[] ps;
	private long[] rs;
	
	// 重み無し初期化
	public this( long n )
	{
		ps.length = n;
		ps[] = -1;
		rs.length = n;
	}
	
	public long root( long i )
	{
		if( ps[ i ] < 0 ) return i;
		else              return ps[ i ] = root( ps[ i ] );
	}
	
	public bool same( long i, long j )
	{
		return root( i ) == root( j );
	}
	
	public void unite( long i, long j )
	{
		i = root( i );
		j = root( j );
		if( i == j ) return;
		if( rs[ i ] < rs[ j ] )
		{
			ps[ j ] += ps[ i ];
			ps[ i ] = j;
		}
		else
		{
			ps[ i ] += ps[ j ];
			ps[ j ] = i;
			if( rs[ i ] == rs[ j ] ) rs[ i ]++;
		}
	}
}


Measured memory_bytes: 14012
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;
#define REP(i, a, n) for(int i=a; i<n; i++)
#define ll long long

int main()
{
	ll n, h;
	vector<pair<ll, ll>> vp;
	cin >> n >> h;
	REP(i, 0, n) {
		int a, b;
		cin >> a >> b;
		vp.emplace_back(b, a);
	}

	ll maxrep = 0;
	for (auto itr : vp) {
		if (itr.second > maxrep) maxrep = itr.second;
	}
	sort(vp.begin(), vp.end());
	reverse(vp.begin(), vp.end());

	ll cnt = 0;
	for (auto itr : vp) {
		if (itr.first < maxrep) break;

		h -= itr.first;
		cnt++;

		if (h <= 0) break;
	}
	if (h > 0) {
		if (h%maxrep == 0) cnt += (h / maxrep);
		else cnt += (h / maxrep + 1);
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 2420
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define MOD 1000000007
#define PI 3.141592653589793
const int INF = 100000000;
int dx[] = {0,1,-1,0,1,-1,1,-1};
int dy[] = {1,0,0,-1,1,-1,-1,1};

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    int ans = min(b / a, c);
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int sz = 1e6+5;

bitset <sz> done;

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

   int x = 7, ans = 1;
   while(1) {
      x %= n;
      if(done[x]) break;
      done[x] = 1;
      if(!x) {
         cout << ans << endl;
         exit(0);
      }
      ans++;
      x = x * 10 + 7;
   }
   puts("-1");
}


Measured memory_bytes: 3752
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
const ll INF=1e18;
const int MOD=1e9+7;
const double pi=acos(-1);

int main(){
  ll h,w;
  cin >> h >> w;
  ll ans=INF;
  if(h*w%3==0)ans=0;
  for(ll i=1;i<h;i++){
    ll s1=i*w;
    ll s2=(h-i)*(w/2);
    ll s3=(h-i)*((w+1)/2);
    ans=min(ans,max({s1,s2,s3})-min({s1,s2,s3}));
  }
  for(ll i=1;i<h;i++){
    ll s1=i*w;
    ll s2=((h-i)/2)*w;
    ll s3=((h-i+1)/2)*w;
    ans=min(ans,max({s1,s2,s3})-min({s1,s2,s3}));
  }
  for(ll i=1;i<w;i++){
    ll s1=i*h;
    ll s2=(w-i)*(h/2);
    ll s3=(w-i)*((h+1)/2);
    ans=min(ans,max({s1,s2,s3})-min({s1,s2,s3}));
  }
  for(ll i=1;i<w;i++){
    ll s1=i*h;
    ll s2=((w-i)/2)*h;
    ll s3=((w-i+1)/2)*h;
    ans=min(ans,max({s1,s2,s3})-min({s1,s2,s3}));
  }
  cout << ans << endl;
    
  
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using static System.Console;
using static System.Math;


namespace AtCodeeeer
{
    class AtCOOOOOOOOOOOder
    {
        static void Main(string[] args)
        {
            int[] s = ReadLine().Split(' ').Select(int.Parse).ToArray();
            int K = s[0];
            int S = s[1];

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


Measured memory_bytes: 13268
#include <cstdio>
#include <climits>
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stack>
#include <algorithm>
#include <iomanip>
#include <map>
#include <queue>
#include <functional>
#include <numeric>
#include <chrono>
#include <cstdlib>
using ll = long long;
using namespace std;

const ll MOD = 1e9 + 7;
const double pi = acos(-1);
#define REP(i, n) for (int(i) = 0; (i) < (n); ++(i))
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define EPS 1e-4
// bool operator<(const pair<int, int> &a, const pair<int, int> &b)
// {
//     if (a.first == b.first)
//         return a.second < b.second;
//     return a.first < b.first;
// };

/*unsigned int xor128(void)
{
    static unsigned int x = 123456789, y = 362436069, z = 521288629, w = 88675123;
    unsigned int t = (x ^ (x << 11));
    x = y;
    y = z;
    z = w;
    return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}
unsigned int xor128rnd(unsigned int m)
{
    return xor128() % m;
}*/

/*bool operator<(const pair<int, int> &a, const pair<int, int> &b)
{
    if (a.first == b.first)
    {
        return a.second < b.second;
    }
    return a.first < b.first;
}*/

int arr[110];
bool dumped[110];
int ans = 0;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    //cout << fixed << setprecision(8);

    int N;
    cin >> N;
    int ans = 0;
    int stt = 0;
    for (int i = 0; i < N; ++i)
        cin >> arr[i];
    for (int i = 0; i < N; ++i)
    {
        if (arr[i] < stt)
        {
            stt = 0;
        }
        if (arr[i] <= arr[i + 1])
        {
            ans += arr[i] - stt;
            stt += arr[i] - stt;
        }
        else if (arr[i] > arr[i + 1])
        {
            ans += arr[i] - stt;
            stt = 0;
            stt += arr[i + 1];
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

#define MAX 100000

int parent(int);
int left(int);
int right(int);

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

  scanf("%d",&H);

  for( i = 1 ; i <= H ; i++ ) {
    scanf("%d",&A[i]);
  }

  for( i = 1 ; i <= H ; i++ ) {

    printf("node %d: key = %d, ",i,A[i]);

    if( parent(i) != 0 ) printf("parent key = %d, ",A[parent(i)]);

    if( left(i) <= H ) printf("left key = %d, ",A[left(i)]);

    if( right(i) <= H ) printf("right key = %d, ",A[right(i)]);

    printf("\n");

  }

  return 0;
}

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

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

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

Measured memory_bytes: 608
A, B, N = map(int, input().split())

res = 0
if N < B:
    res = (A * N) // B
else:
    left = B - 1
    right = 10 ** 15
    while right - left > 1:
        mid = (right + left) // 2
        a = ((A * mid) // B) - (A * (mid // B))
        if res > a:
            right = mid
        else:
            res = a
            left = mid

print(res)

Measured memory_bytes: 9196
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import static java.lang.Integer.parseInt;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = "";

		while ((line = br.readLine()) != null && !line.isEmpty()) {
			int n, m;
			int[][] vote;
			n = parseInt(line.substring(0, line.indexOf(' ')));
			m = parseInt(line.substring(line.indexOf(' ') + 1));
			vote = new int[n][2];
			for (int i = 0; i < n; i++) {
				vote[i][0] = parseInt(br.readLine());
			}
			for (int i = 0; i < m; i++) {
				int cost = parseInt(br.readLine());
				for (int j = 0; j < n; j++) {
					if (vote[j][0] <= cost) {
						vote[j][1]++;
						break;
					}
				}
			}
			int event = 0, max = 0;
			for (int i = 0; i < n; i++) {
				if (vote[i][1] > max) {
					max = vote[i][1];
					event = i;
				}
			}
			System.out.println(event + 1);
		}

	}

}

Measured memory_bytes: 20168
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
using namespace std;

typedef long long ll;
typedef double db;
typedef long double ldb;

template<class T> inline void checkmin(T &a,const T &b){if(b<a) a=b;}
template<class T> inline void checkmax(T &a,const T &b){if(b>a) a=b;}

const int inf=1e9+10;
const int maxn=1e5+10;

ll dp[maxn][2],mod;
int n,father[maxn];
vector <int> g[maxn];

void dfs1(int x,int fa){
	father[x]=fa;
	ll ret=1ll;
	for(int i=0;i<g[x].size();i++){
		int to=g[x][i];
		if(to==fa) continue;
		dfs1(to,x);
		ret=ll(ret*ll(dp[to][0]+1ll)%mod)%mod;
	}
	dp[x][0]=ret;
}

void dfs2(int x,int fa){
	vector <ll> v1,v2; 
	for(int i=0;i<g[x].size();i++){
		int to=g[x][i];
		if(to==fa){
			v1.pb(1ll);
			continue;
		}
		v1.pb(ll(dp[to][0]+1ll)%mod);
	}
	for(int i=1;i<g[x].size();i++) v1[i]=ll(v1[i-1]*v1[i])%mod;
	for(int i=0;i<g[x].size();i++){
		int to=g[x][i];
		if(to==fa){
			v2.pb(1ll);
			continue;
		}
		v2.pb(ll(dp[to][0]+1ll)%mod); 
	}
	for(int i=g[x].size()-2;i>=0;i--) v2[i]=ll(v2[i+1]*v2[i])%mod;
	for(int i=0;i<g[x].size();i++){
		int to=g[x][i];
		if(to==fa) continue;
		ll res=1ll;
		if(i>0) res=ll(res*v1[i-1])%mod;
		if(i<g[x].size()-1) res=ll(res*v2[i+1])%mod;
		res=ll(res*dp[x][1])%mod;
		res=ll(res+1ll)%mod;
		dp[to][1]=res;
		dfs2(to,x);
	}
}

int main(){
	scanf("%d%d",&n,&mod);
	for(int i=0;i<n-1;i++){
		int u,v;
		scanf("%d%d",&u,&v);
		u--; v--;
		g[u].pb(v);
		g[v].pb(u);
	}
	dfs1(0,-1);
	dp[0][1]=1ll; dfs2(0,-1); 
	for(int i=0;i<n;i++){
		ll ret=dp[i][1];
		for(int j=0;j<g[i].size();j++){
			int to=g[i][j];
			if(to==father[i]) continue;
			ret=(ll(dp[to][0]+1ll)%mod*ret)%mod;
		}
		printf("%d\n",ret);
	} 
	return 0;
}


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,M;
ll dp[303][303][303];
ll mo=1000000007;
void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>M;
	if(M<N) return _P("0\n");
	dp[0][1][1]=1; // as, tot
	FOR(i,M) {
		FOR(x,N+1) FOR(y,N+1) if(dp[i][x][y]) {
			ll t=dp[i][x][y];
			// loop
			(dp[i+1][y][y] += t*x)%=mo;
			// already
			(dp[i+1][x][y] += t*(y-x))%=mo;
			// new
			if(y<N) (dp[i+1][x][y+1] += t*(N-y))%=mo;
		}
	}
	
	cout<<dp[M][N][N]<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


Measured memory_bytes: 108032
#include <iostream>
using namespace std;
int main(void){
    int s,a,b,c,f;
    s=0;
    f=0;
    cin>>a>>b>>c;
    while(1){
        f=c-b;
        if(a%c==0){
            s++;
        }
        if(f<=0){
            break;
        }
        c--;
    }
    cout<<s<<endl;
}



Measured memory_bytes: 3104
import java.util.*;
public class Main { 
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        String o="";
        long n=sc.nextLong();
		while(n>0){
          	long a=n%26;
          	if(a!=0)o=(char)(96+a)+o;
          	else o="z"+o;
          	n=n/26;
          	if(a==0)n--;
        }
        
      System.out.println(o);
    }
    
}

Measured memory_bytes: 39480
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
using P = pair<ll,ll>;
constexpr ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REPS(i,n) for(ll (i)=1;(i)<=(n);(i)++)
#define RREP(i,n) for(ll (i)=(n-1);(i)>=0;(i)--)
#define RREPS(i,n) for(ll (i)=(n);(i)>0;(i)--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());

template<class T> inline void chmin(T& a, T b){
    if (a > b){
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b){
    if (a < b){
        a = b;
    }
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(12);
    ll D,T,S;
    cin >> D >> T >> S;
    cout << (D <= T*S ? "Yes" : "No") << "\n";
}

Measured memory_bytes: 3644
import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int N = Integer.parseInt(scanner.nextLine());
		Set<String> Ss = new TreeSet<>();
		for(int i = 0; i < N; i++) Ss.add(scanner.nextLine());
		System.out.println(Ss.size());
	}
}


Measured memory_bytes: 72088
#include<stdio.h>

#define MAX 10000

int OnlyN(int x);

int main(void) {
  int N[MAX];
  int n, i, c = 0;
  scanf("%d", &n);

  for(i=0; i<n; ++i) {
    scanf("%d", &N[i]);
    if(OnlyN(N[i]) == 1) {
      c++;
    }
  }

  printf("%d\n", c);

  return 0;
}

int OnlyN(int x) {
  if(x == 2) {
    return 1;
  }

  if(x < 2 || x%2 == 0) {
    return 0;
  }

  int i = 3;
  while(i*i <= x) {
    if(x%i == 0) {
      return 0;
    }
    i += 2;
  }

  return 1;
}



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

long long attackCount(long long H)
{
    if (H == 1)
        return 1;
    return attackCount(H / 2) * 2 + 1;
}

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

    std::cout << attackCount(H) << std::endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(int argc, char* argv[]) {
  int a, b, c; cin >> a >> b >> c;
  int ans = 0;
  for (int i = a; i <= b; i++) {
    if (c%i == 0) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1164
import sys

input = sys.stdin.readline

ri = lambda: int(input())
rs = lambda: input().rstrip()
ril = lambda: list(map(int, input().split()))
rsl = lambda: input().rstrip().split()
ris = lambda n: [ri() for _ in range(n)]
rss = lambda n: [rs() for _ in range(n)]
rils = lambda n: [ril() for _ in range(n)]
rsls = lambda n: [rsl() for _ in range(n)]


class UnionFind:
    def __init__(self, n):
        self.n = n
        self.parents = list(range(n))
        self.ranks = [0 for _ in range(n)]

    def get_root(self, x):
        if self.parents[x] == x:
            return x
        self.parents[x] = self.get_root(self.parents[x])
        return self.parents[x]

    def merge(self, x, y):
        x = self.get_root(x)
        y = self.get_root(y)
        if x != y:
            if self.ranks[x] < self.ranks[y]:
                self.parents[x] = y
            else:
                self.parents[y] = x
                if self.ranks[x] == self.ranks[y]:
                    self.ranks[x] += 1


n, m = ril()
ps = ril()
ls = rils(m)

uf = UnionFind(n)
for a, b in ls:
    uf.merge(a - 1, b - 1)
res = 0
for i in range(n):
    p0 = uf.get_root(i)
    p1 = uf.get_root(ps[i] - 1)
    if p0 == p1:
        res += 1
print(res)

Measured memory_bytes: 36040
#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 ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;

int dp[105][2];
int cnd[105][2];

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  REP(i,2){
    REP(j,n) cin >> cnd[j][i];
  }
  dp[0][0] = cnd[0][0];
  dp[0][1] = dp[0][0] + cnd[0][1];
  REP(i,n-1){
    dp[i+1][0] = dp[i][0] + cnd[i+1][0];
    dp[i+1][1] = max(dp[i+1][0], dp[i][1]) + cnd[i+1][1];
  }
  cout << dp[n-1][1] << endl;
  return 0;
}

Measured memory_bytes: 256
import collections
# Nの入力
N = int(input())

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

c = collections.Counter(prime_factorize(N))
result = 0
for i in list(c.values()):
    j = 1
    if i == 1:
        result += 1
    else:
        while i >= j:
            i = i - j
            result += 1
            j += 1
print(result)

Measured memory_bytes: 9468
#include <bits/stdc++.h>
 
using namespace std;
 
#define int long long int
 
int32_t main(){
 
	unordered_map <int, int> m;
	unordered_map <int, int>:: iterator itr;
	int n, i,sum = 0;
	cin >> n;
	vector<int> v(n);
 
	for(i=0; i<n; i++){
 
		cin >> v[i];
		itr  = m.find(v[i]);
		if(itr == m.end())
			m.insert({v[i], 1});
		else
			itr->second++;
	}
 
	for(itr = m.begin(); itr != m.end(); itr++){
		if(itr->second > 1)
			sum += itr->second * (itr->second - 1) / 2;
	}
 
	for( i=0; i<n; i++){
 
		itr = m.find(v[i]);
 
		if(itr->second > 1)
			cout<< sum - (itr->second - 1) ;
		else
			cout<<sum;
		cout<<endl;
	}
 
	return 0;
}


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

using namespace std;


int main(){
	int n,w,d,p,s,w1,d1;
	vector<pair<int,pair<int,int> > > v;
	pair<int,pair<int,int> > cut;

	while(1){
		cin >> n >> w >> d;
		if(n==0&&w==0&&d==0)break;
		v.clear();
		v.push_back(make_pair(w*d,make_pair(w,d)));
		for(int i=0;i<n;i++){
			cin >> p >> s;
			cut = v[p-1];
			v.erase(v.begin()+p-1);
			w1 = cut.second.first;
			d1 = cut.second.second;
			s = s%(w1+d1);
			if(w1>s){
				if(s<w1-s){
					v.push_back(make_pair(d1*s,make_pair(s,d1)));
					v.push_back(make_pair(d1*(w1-s),make_pair(w1-s,d1)));
				}else{
					v.push_back(make_pair(d1*(w1-s),make_pair(w1-s,d1)));
					v.push_back(make_pair(d1*s,make_pair(s,d1)));
				}
			}else{
				if(s-w1<d1+w1-s){
					v.push_back(make_pair(w1*(s-w1),make_pair(w1,s-w1)));
					v.push_back(make_pair(w1*(d1+w1-s),make_pair(w1,d1+w1-s)));
				}else{
					v.push_back(make_pair(w1*(d1+w1-s),make_pair(w1,d1+w1-s)));
					v.push_back(make_pair(w1*(s-w1),make_pair(w1,s-w1)));
				}
			}
		}
		sort(v.begin(),v.end());
		for(int i=0;i<v.size()-1;i++){
			cout << v[i].first << " ";
		}
		cout << v[v.size()-1].first << endl;
	}
	return 0;
}

Measured memory_bytes: 2992
using System;

namespace AOJ.ITP
{
    public class StructuredProgramming
    {
        public static void Main()
        {
            int n = int.Parse(Console.ReadLine());

            string output = "";
            string tmp;
            // 3の倍数または"3"が含まれる数字を出力
            for (int i = 1; i <= n; i++)
            {
                if (i % 3 == 0) { output += " " + i; }
                else
                {
                    tmp = i.ToString();
                    if (tmp.Contains("3")) { output += " " + i; }
                }
            }

            Console.WriteLine(output);
        }
    }
}

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

const ll LINF = 1e18;
const int INF = 1e9;
const ll MOD = 1000000007;


int main(){

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

    if(d >= abs(c-a)) cout << "Yes" << endl;
    else if((d >= abs(b - a)) && (d >= abs(c - b))) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    return 0;
}


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

int main()
{
    int n;
    double sum;
    cin >> n;
    vector<double> a(n);
    for (int i=0; i<n; i++) cin >> a[i];
    for (int i=0; i<n; i++) {
        sum += 1 / a[i];
    }
    cout << 1 / sum << endl;

    return 0;
}

Measured memory_bytes: 256
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

    s = input().rstrip()
    res = 0
    for i in range(len(s)-1):
        if s[i] != s[i+1]:
            res += 1
    print(res)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3572
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const long double EPS = 1e-9;
const ll mod = 1e9 + 7;
const ll INF = 1e9;

#define rep(i, n) for(ll i = 0; i < n ; i++ )
#define For(i, a, b) for(ll i = (a); i < (b) ; i++ )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

const ll MAX_N = 100000;

int main(void){
    ll a,b,c,d;
    
    cin >> a >> b >> c >> d;

    if (abs(a - c) <= d) cout << "Yes" << endl;
    else if (abs(a - b) <= d && abs(b - c) <= d) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;
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 long long INF = 1LL << 60;
long long dp[100010];

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

	// 初期化 (最小化問題なので INF に初期化)
	for (int i = 0; i < 100010; ++i) dp[i] = INF;

	// 初期条件
	dp[0] = 0;

	// ループ
	for (int i = 1; i < N; ++i) {
		chmin(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]));
		if (i > 1) chmin(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));
	}

	// 答え
	cout << dp[N-1] << endl;
}

Measured memory_bytes: 1792
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;
#define BIG_NUM 2000000000
#define MOD 1000000007
using namespace std;

struct Info{
	Info(){
		length = 0;
	}

	bool operator<(const struct Info &arg) const{
			return length < arg.length;
	};

	char buf[51],number[51];
	int length;
};

struct Data{
	Data(){
		index = 0;
		output[0] = '\0';
	}
	char input[310],output[610];
	int index;
};

char calc(char ch){
	switch(ch){
	case 'a':
	case 'b':
	case 'c':
		return '2';
	case 'd':
	case 'e':
	case 'f':
		return '3';
	case 'g':
	case 'h':
	case 'i':
		return '4';
	case 'j':
	case 'k':
	case 'l':
		return '5';
	case 'm':
	case 'n':
	case 'o':
		return '6';
	case 'p':
	case 'q':
	case 'r':
	case 's':
		return '7';
	case 't':
	case 'u':
	case 'v':
		return '8';
	case 'w':
	case 'x':
	case 'y':
	case 'z':
		return '9';
	}
	return -1;
}

bool strCmp(char* base, char* comp){
	int length1 = 0,length2 = 0;
	for(int i=0;base[i] != '\0'; i++)length1++;
	for(int i=0;comp[i] != '\0'; i++)length2++;
	if(length1 != length2)return false;

	for(int i=0;base[i] != '\0'; i++){
		if(base[i] != comp[i])return false;
	}
	return true;
}

void strcpy(char* to,char* str){
	for(int i=0;str[i] != '\0';i++){
		to[i] = str[i];
		to[i+1] = '\0';
	}
}

void addcpy(char* to,char* str){
	int index,second_index;
	for(index = 0; to[index] != '\0';index++);
	for(second_index = 0; str[second_index] != '\0';second_index++){
		to[index+second_index] = str[second_index];
	}
	to[index+second_index] = '\0';
}

void func(int N){

	char buf[51],blank[2];
	blank[0] = ' ';
	blank[1] = '\0';
	Info info[N];
	int max_length = -1;

	for(int i = 0; i < N; i++){
		scanf("%s",buf);

		strcpy(info[i].buf,buf);

		for(int k = 0; buf[k] != '\0';k++){
			info[i].number[k] = calc(buf[k]);
			info[i].number[k+1] = '\0';
			info[i].length++;
		}
		max_length = max(max_length,info[i].length);
	}

	sort(info,info+N);

	Data first;
	scanf("%s",first.input);

	int length;
	char tmp[51];

	for(length = 0;first.input[length] != '\0'; length++);

	queue<Data> Q;
	Data current;

	Q.push(first);

	while(!Q.empty()){
		current = Q.front();
		Q.pop();

		if(current.index >= length){
			printf("%s.\n",current.output);
			continue;
		}

		for(int i = 1; current.index + i <= length && i <= max_length; i++){
			for(int k = 0; k < i; k++){
				tmp[k] = current.input[current.index+k];
				tmp[k+1] = '\0';
			}

			for(int k = 0; k < N && info[k].length <= i; k++){
				if(i == info[k].length && strCmp(info[k].number,tmp)){
					Data new_data;
					strcpy(new_data.input,current.input);
					new_data.index = current.index + info[k].length;
					strcpy(new_data.output,current.output);
					if(current.index != 0){
						addcpy(new_data.output,blank);
					}
					addcpy(new_data.output,info[k].buf);
					Q.push(new_data);
				}
			}
		}
	}
	printf("--\n");
}

int main(){
	int N;

	while(true){
		scanf("%d",&N);
		if(N == 0)break;

		func(N);
	}
}

Measured memory_bytes: 2804
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <stdlib.h>
#include <queue>
#include <stack>


typedef long double ld;
typedef long long ll;

using namespace std;

int main() {
	int n, m;
	cin >> n >> m;
	if (m >= n) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
	return 0;
}


Measured memory_bytes: 3016
N = int(input())
S = [list(map(int, input())) for _ in range(N)]

adj_dict={i:[] for i in range(N)}

for i in range(N):
  for j in range(i,N):
    if S[i][j]:
      adj_dict[i].append(j)
      adj_dict[j].append(i)

ans = 0
for i in range(N):
  #頂点iから開始
  l=0
  visited = set([i])
  prev_layer = set()
  cur_layer = set([i])
  next_layer = set()
  
  #visited管理しなくてもN回でよい
  while len(visited)<N:
    l+=1
    for v in cur_layer:
      visited.add(v)
      for u in adj_dict[v]:
        if u in cur_layer:
          print(-1)
          exit()
        next_layer.add(u)
    prev_layer = cur_layer
    cur_layer = next_layer
    next_layer = set()
  ans = max(ans,l)
  
print(ans)

Measured memory_bytes: 3828
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
#include <numeric>
#include <queue>
using namespace std;
typedef long long int ll;

vector<int> g[100100];

struct UnionFind{
    vector<int> par,num;
    vector<bool> done;
    UnionFind(int n):par(n),num(n,1),done(n,false){
        iota(par.begin(),par.end(),0);  //include<numeric>
    }
    int find(int v){
        return (par[v]==v)?v:(par[v]=find(par[v]));
    }
    void unite(int u,int v){
        u=find(u),v=find(v);
        if(u==v)return;
        if(num[u]<num[v])swap(u,v);
        num[u]+=num[v];
        par[v]=u;
        done[u]=done[u]|done[v];
    }
    bool same(int u,int v){
        return find(u) == find(v);
    }
    bool ispar(int v){
        return v=find(v);
    }
    int size(int v){
        return num[find(v)];
    }
};

int res[100100];

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,m; cin >> n >> m;
    UnionFind uf(n);
    while(m--){
        int x,y; cin >> x >> y;
        x--; y--;
        g[x].push_back(y);
        g[y].push_back(x);
        uf.unite(x,y);
    }
    if(uf.size(1)!=n){
        printf("No\n");
    }
    else{
        printf("Yes\n");
        queue<int> q;
        q.push(0);
        while(q.size()){
            int p=q.front();
            q.pop();
            for(int t:g[p]){
                if(res[t]!=0||t==0){
                    continue;
                }
                else{
                    res[t]=p+1;
                    q.push(t);
                }
            }
        }
        for(int i=1;i<n;i++){
            printf("%d\n",res[i]);
        }
    }
}


Measured memory_bytes: 11028
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define MOD (1000000007)
#define INF (1e9)
#define INFL (1e12)
 
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
template<class T>using arr=vector<vector<T>>;
template<class T>void pr(T x){cout << x << endl;}
template<class T>void prvec(vector<T>& a){rep(i, a.size()-1){cout << a[i] << " ";} cout << a[a.size()-1] << endl;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
 
int main()
{
    int n; cin >> n;
    vector<int> a(n);
    unordered_map<int, int> m;
    rep(i, n){
        cin >> a[i];
        m[a[i]]++;
    }
    ll sel=0;
    for(auto mi: m){
        sel += ((ll)mi.second * (mi.second - 1)) / 2;
    }

    rep(i, n){
        pr(sel - m[a[i]] + 1);
    }
    return 0;}

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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

int mpow3[100010];
int mpow2[100010];

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

	mpow2[0] = 1;
	mpow3[0] = 1;
	rep(i, 0, 100010 - 1)
	{
		mpow2[i + 1] = (mpow2[i] * 2) % MOD;
		mpow3[i + 1] = (mpow3[i] * 3) % MOD;
	}

	string L;
	cin >> L;
	//reverse(all(L));

	int ans = 0;
	int c = 0;
	rep(i, 0, SZ(L))
	{
		if (L[i] == '1')
		{
			ans += mpow2[c] * mpow3[SZ(L) - i - 1];
			ans %= MOD;
			c++;
		}
	}
	ans += mpow2[c];

	cout << ans % MOD << endl;

	return 0;
}

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

int main() {

	int n, k; cin >> n >> k;
	
	int is_1_Index;
	for (int i = 0; i < n; i++) {
		int tmp_a; cin >> tmp_a;
	}

	cout << ceil((double)(n - 1) / (k - 1)) << endl;
	return 0;
}

Measured memory_bytes: 256
if __name__ == '__main__':
    N, M, X = map(int, input().split())
    A = map(int, input().split())
    cost_map = {}
    for i in A:
        cost_map[i] = 1
    cost_to_0 = [0 for i in range(N+1)]
    cost_to_N = [0 for i in range(N+1)]
    for i in range(1, N+1):
        if i in cost_map:
            cost_to_0[i] = cost_to_0[i-1] + 1
        else:
            cost_to_0[i] = cost_to_0[i-1]

    for i in range(0, N)[::-1]:
        if i in cost_map:
            cost_to_N[i] = cost_to_N[i+1] + 1
        else:
            cost_to_N[i] = cost_to_N[i+1]
    print(min(cost_to_0[X], cost_to_N[X]))


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0; i < (n); ++i)
#define repA(i, a, n) for(ll i = a; i <= (n); ++i)
#define repD(i, a, n) for(ll i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (long long) (x).size()
#define fill(a) memset(a, 0, sizeof(a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define endl '\n'
#define MAXN 5000000
const long double PI = 3.141592653589793238462643383;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long int> vll;
typedef vector<double> vd;
typedef vector<pii> vii;
const long long mod = 998244353;
int Ceil(int a, int b){
    if(a%b==0) return a/b;
    else return (a/b)+1;
}

ll power(ll a,ll b){
    ll ans = 1;
    while(b){
        if(b&1)
            ans*= a;
        ans%=mod;
        a*= a;
        a%=mod;
        b/=2;
    }
    return ans;
}
int main(){
 
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);   
    freopen("output.txt", "w", stdout);
    #endif
    cin.sync_with_stdio(0); cin.tie(0);
    cin.exceptions(cin.failbit);
    int s,w;
    cin>>s>>w;
    if(w>=s)
        cout<<"unsafe";
    else
        cout<<"safe";
    return 0;
}

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

using namespace std;

int main()
{
	string S, T;
	cin >> S;
	cin >> T;
	int cont = 0;
	for( int i = 0; i < 3; ++i )
	{
		if (S[i] == T[i]) cont++;
	}
	cout << cont;
}

Measured memory_bytes: 256