akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ok() puts(ok?"Yes":"No");
using namespace std;
using ll = long long;
using vi = vector<int>;
using ii = pair<int, int>;
using vvi = vector<vi>;
using vii = vector<ii>;
using gt = greater<int>;
using minq = priority_queue<int, vector<int>, gt>;
using P = pair<ll,ll>;
const ll LINF = 1e18L + 1;
const int INF = 1e9 + 1;

//clang++ -std=c++11 -stdlib=libc++ 

int main() {
  vi x(5);
  rep(i,5) cin >> x[i];
  rep(i,5) {
    if (x[i] == 0){
      cout << i+1 << endl;
      return 0;
    }
  }
  return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
int A[200005];

int main() {
    int n,k,q,x;
  cin>>n>>k>>q;
  for(int i=0;i<q;++i) {
    scanf("%d", &x);
    A[x]++;
  }

  int p=q-k;
  for(int i=1;i<=n;++i) {
    if(A[i]-p<=0) printf("No\n");
    else printf("Yes\n");
  }
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <numeric>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <functional>
#include <complex>
#include <stack>
#include <tuple>
#include <array>
using namespace std;
#define rep(i,n) for (int i=0; i < (n); i++)


typedef long long int ll;
typedef double D;      // ??§?¨?????????????double???long double?????????

const int INF = (1<<30) - 1;
const D EPS = 1e-9;

#define X real()
#define Y imag()
#define LE(n,m) ((n) < (m) + EPS)
#define GE(n,m) ((n) + EPS > (m))
#define EQ(n,m) (abs((n)-(m)) < EPS)

int K; double R, L;
double P, E, T;

double dfs(double r, double l, double k){
    if(T-E <= r && l <= T+E)
        return 1;
    if(l <= T-E || T+E <= r)
        return 0;
    if(k == 0){
        double h = (r + l) / 2;
        return (T-E <= h && h <= T+E);
    }
        
    double h = (r + l) / 2;
    if(T <= h){
        return dfs(r, h, k-1)*(1-P) + dfs(h, l, k-1)*P;
    }else{
        return dfs(r, h, k-1)*P + dfs(h, l, k-1)*(1-P);
    }
}

//g++ -std=c++0x -msse4.2 -O3
//#include <bits/stdc++.h>
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(16);
    cout.setf(ios::fixed);
    
    cin >> K >> R >> L;
    cin >> P >> E >> T;
    
    cout << dfs(R, L, K) << endl;
    
    return 0;
}

Measured memory_bytes: 1304
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.InputMismatchException;

public class Main {
	static InputStream is;
	static String INPUT = "";
	static void solve()
	{
		int n = ni();
		int M = 1000001;
		int W = (M>>>6)+1;
		long[] f1 = new long[W];
		long[] f2 = new long[W];
		long[] ex = new long[W];
		for(int i = 0;i < n;i++){
			int v = ni();
			if(f1[v>>>6]<<~v>=0){
				f1[v>>>6] |= 1L<<v;
				if(ex[v>>>6]<<~v>=0){
					for(int j = v*2;j < M;j+=v){
						ex[j>>>6] |= 1L<<j;
					}
				}
			}else{
				f2[v>>>6] |= 1L<<v;
			}
		}
		int ans = 0;
		for(int i = 0;i < W;i++){
			ans += Long.bitCount((f1[i]^f2[i])&~ex[i]);
		}
		System.out.println(ans);
	}

	public static void main(String[] args) throws Exception
	{
		long S = System.currentTimeMillis();
		is = System.in;
		
		solve();
		long G = System.currentTimeMillis();
		tr(G-S+"ms");
	}
	
	private static byte[] inbuf = new byte[1024];
	static int lenbuf = 0, ptrbuf = 0;
	
	private static int readByte()
	{
		if(lenbuf == -1)throw new InputMismatchException();
		if(ptrbuf >= lenbuf){
			ptrbuf = 0;
			try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
			if(lenbuf <= 0)return -1;
		}
		return inbuf[ptrbuf++];
	}
	
	private static boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
//	private static boolean isSpaceChar(int c) { return !(c >= 32 && c <= 126); }
	private static int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }
	
	private static double nd() { return Double.parseDouble(ns()); }
	private static char nc() { return (char)skip(); }
	
	private static String ns()
	{
		int b = skip();
		StringBuilder sb = new StringBuilder();
		while(!(isSpaceChar(b))){
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}
	
	private static char[] ns(int n)
	{
		char[] buf = new char[n];
		int b = skip(), p = 0;
		while(p < n && !(isSpaceChar(b))){
			buf[p++] = (char)b;
			b = readByte();
		}
		return n == p ? buf : Arrays.copyOf(buf, p);
	}
	
	private static char[][] nm(int n, int m)
	{
		char[][] map = new char[n][];
		for(int i = 0;i < n;i++)map[i] = ns(m);
		return map;
	}
	
	private static int[] na(int n)
	{
		int[] a = new int[n];
		for(int i = 0;i < n;i++)a[i] = ni();
		return a;
	}
	
	private static int ni()
	{
		int num = 0, b;
//		boolean minus = false;
//		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
//		if(b == '-'){
//			minus = true;
//			b = readByte();
//		}
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9')));
		
		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return num;
//				return minus ? -num : num;
			}
			b = readByte();
		}
	}
	
	private static void tr(Object... o) { if(INPUT.length() != 0)System.out.println(Arrays.deepToString(o)); }
}


Measured memory_bytes: 37220
import java.util.Scanner;

public class Main {
    static Scanner sc = new Scanner(System.in);


    public static void main(String[] args) {
        int s = sc.nextInt();
        int w = sc.nextInt();
        if (w >= s) {
            System.out.println("unsafe");
        } else {
            System.out.println("safe");
        }
    }
}


Measured memory_bytes: 27040
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        List<Integer> v = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            v.add(sc.nextInt());
        }
        sc.close();
        Collections.sort(v);

        double value = v.remove(0);
        for (int i = 0; i < n - 1; i++) {
            value = (value + v.remove(0)) / 2.0;
        }
        System.out.println(value);
    }

}


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

int main() {
  string s, t; cin >> s >> t;
  bool f = false;
  if (s.size() + 1 == t.size()) {
    if (s == t.substr(0, s.size()))
      f = true;
  }
  puts(f ? "Yes" : "No");
  return 0;
}

Measured memory_bytes: 3596
import string
chars = string.ascii_lowercase
def solve(S):
    if S == chars[::-1]:
        return -1
    for c in chars:
        if c in S:
            continue
        else:
            return S + c
    S = S[::-1]
    for i, c in enumerate(S):
        if i == len(S) - 1:
            continue
        c = S[i + 1]
        ans = S[i + 2:]
        if c == chars[-1]:
            continue
        n = chars[chars.find(c) + 1]
        while n in ans:
            if n == chars[-1]:
                n = -1
                break
            n = chars[chars.find(n)+1]
        if n == -1:
            continue

        ans = ans[::-1]
        ans += n
        return ans
    return -1

if __name__ == "__main__":
    print(solve(input()))


Measured memory_bytes: 3828
/*
これを入れて実行
g++ code.cpp
./a.out
 */

#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <tuple>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef long double ld;

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

const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;

bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}

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

//-----------------------ここから-----------

bool comp1(const tuple<int, int, int>& f, const tuple<int, int, int>& s){
    if(get<0>(f) == get<0>(s)){
        return get<1>(f) < get<1>(s);
    } else {
        return get<0>(f) < get<0>(s);
    }
}
bool comp2(const tuple<int, int, int>& f, const tuple<int, int, int>& s){
    return get<2>(f) < get<2>(s);
}

int main(void){
    int n, m;

    cin >> n >> m;

    vector<tuple<int, int, int>> l(m);

    for(int i = 0; i < m; i++){
        cin >> get<0>(l[i]) >> get<1>(l[i]);
        get<2>(l[i]) = i;
    }

    sort(l.begin(), l.end(), comp1);

    int counter = 1;

    for(int i = 0; i < l.size(); i++){
        int pref = get<0>(l[i]);
        int counter = 1;
        while(pref == get<0>(l[i])){
            get<1>(l[i]) = counter;
            counter++;
            i++;
        }

        if(pref != get<0>(l[i])){
            i--;
        }
    
    }

    sort(l.begin(), l.end(), comp2);

    for(int i = 0; i < l.size(); i++){
        cout << setw(6) << setfill('0') << get<0>(l[i]) << setw(6) << setfill('0') << get<1>(l[i])<< endl;
    }


}



Measured memory_bytes: 2688
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }

        static readonly long Mod = 1000000000 + 7;

        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            var N = Sarray()[0];
            var Ai = Sarray();
            var sum = Ai.Sum();
            var mid = 0L;
            var midpos = 0L;
            for (var i = 0; i < N; ++i)
            {
                mid += Ai[i];
                if (sum <= mid * 2)
                {
                    midpos = i;
                    break;
                }
            }
            //左側を中心にするのに必要なコスト
            var cstL = sum - 2 * (mid - Ai[midpos]);
            //右側を中心にするのに必要なコスト
            var cstR = 2 * mid - sum;
            WriteLine(Min(cstL, cstR));
            //Out.Flush();
        }
    }
}

Measured memory_bytes: 39424
import java.util.Scanner;

public class Main{

	public static void main(String[] args){
		Scanner scan=new Scanner(System.in);
		int i,j,n,min,swap,count=0;
		n=scan.nextInt();
		int arr[]=new int[n];
		for(i=0;i<n;i++) {
			arr[i]=scan.nextInt();
		}
		for(i=0;i<n;i++) {
			min=i;
			for(j=i;j<n;j++) {
				if(arr[min]>arr[j]) {
					min=j;
				}
			}
			if(min!=i) {
				swap=arr[min];
				arr[min]=arr[i];
				arr[i]=swap;
				count++;
			}
		}
		for(i=0;i<n;i++) {
			if(i<n-1) {
				System.out.print(arr[i]+" ");
			}
			else{
				System.out.println(arr[i]);
			}
		}
		System.out.println(count);
		scan.close();
	}
}


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

int main()
{
    long long N;
    cin >> N;

    vector<long long> A(N);
    map<long long, long long> m;
    for (long long &a : A)
    {
        cin >> a;
        m[a]++;
    }

    long long ans = 0;
    for (auto p : m)
    {
        ans += p.second * (p.second - 1) / 2;
    }
    for (long long a : A)
    {
        long long count = m[a];

        cout << ans - count * (count - 1) / 2 + (count - 1) * (count - 2) / 2 << endl;
    }
}


Measured memory_bytes: 11008
#include <iostream>
#include <numeric>
#include <vector>

int getMaxCandiesNum(const std::vector<int> upper_candies,
                     const std::vector<int> lower_candies) {
  const int lower_candies_total =
      std::accumulate(lower_candies.begin(), lower_candies.end(), 0);
  int current_upper_candies = 0;
  int current_lower_candies = lower_candies_total;
  int max_candies_num = 0;
  for (int i = 0; i < static_cast<int>(upper_candies.size()); ++i) {
    current_upper_candies += upper_candies[i];
    const int current_candies_num =
        current_upper_candies + current_lower_candies;
    max_candies_num = std::max(current_candies_num, max_candies_num);
    current_lower_candies -= lower_candies[i];
  }
  return max_candies_num;
}

int main() {
  int n;
  std::cin >> n;
  std::vector<int> upper_candies(n);
  std::vector<int> lower_candies(n);
  for (int i = 0; i < n; ++i) {
    std::cin >> upper_candies[i];
  }
  for (int i = 0; i < n; ++i) {
    std::cin >> lower_candies[i];
  }
  std::cout << getMaxCandiesNum(upper_candies, lower_candies) << std::endl;
  return 0;
}

Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

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

//sqrt
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define REPR(i, n) for(int i = n;i >= 0;i--)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

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


//#define EPS (1e-10)
//
//struct Point{
//    Point(double _x = 0, double _y = 0){
//        x = _x;
//        y = _y;
//    }
//    double x;
//    double y;
//
//    Point operator + (Point p){
//        return Point(x + p.x, y+ p.y);
//    }
//
//    Point operator - (Point p){
//        return Point(x - p.x, y - p.y);
//    }
//
//    Point operator * (double a){
//        return Point(a * x, a * y);
//    }
//
//    Point operator / (double a){
//        return Point(x / a, y / a);
//    }
//
//    double abs(){
//        return sqrt(norm());
//    }
//
//    double norm(){
//        return x * x + y * y;
//    }
//
//    bool operator < (const Point &p) const{
//        return x!=p.x ? x < p.x : y < p.y;
//    }
//
//    bool operator == (const Point &p) const{
//        return fabs(x - p.x) && fabs(y - p.y) < EPS;
//    }
//
//};
//
//typedef Point Vector;
//
//double dot(Vector a, Vector b){
//    return a.x * b.x + a.y * b.y;
//}

int main() {

    int N; scanf("%d", &N);
    int K; scanf("%d", &K);
    int sum = 0;

    VI lList(N);
    REP(i, N){
        scanf("%d", &lList[i]);
    }
    RSORT(lList);
    REP(i,K){
        sum += lList[i];
    }

    printf("%d", sum);

    return 0;

}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Created on Sun Sep 13 12:37:37 2020

@author: liang
"""

"""
フィボナッチ数列生成
【DP(?)】　: 配列を使用することで計算量が爆発するのを防ぐ
【小さいものから計算する】の原則

【方針】
　通常の配列を用いたフィボナッチ数列の生成方法の応用版
 壊れた階段のフィボナッチ数列の値を　0 にすることで、実質遷移を止めることが出来る。
"""
key = 10**9 + 7
N, M = map(int, input().split())
A = [int(input()) for _ in range(M)]+[-1]

fibs = [0]*(N+1)
index = 0
for i in range(N+1):
    #壊れたところの値を0にすれば良い
    if i == A[index]:
        fibs[i] = 0
        index += 1
    elif i == 0 or i == 1:
        fibs[i] = 1
    else:
        fibs[i] = (fibs[i-1] + fibs[i-2])%key
        

print(fibs[N])

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

int main() {
  string S;
  cin >> S;
  int N = S.size();
  vector<vector<int>> DP(20, vector<int>(N));
  for (int i = 0; i < N; i++) {
    if (S.at(i) == 'R') DP.at(0).at(i) = i + 1;
    if (S.at(i) == 'L') DP.at(0).at(i) = i - 1;
  }
  for (int i = 0; i + 1 < 20; i++) {
    for (int j = 0; j < N; j++) {
      DP.at(i + 1).at(j) = DP.at(i).at(DP.at(i).at(j));
    }
  }
  vector<int> ans(N);
  for (int i = 0; i < N; i++) {
    ans.at(DP.at(19).at(i))++;
  }
  for (int i = 0; i < N; i++) {
    if (i) cout << " ";
    cout << ans.at(i);
  }
  cout << "\n";
}

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

int A,B,C,K,d;
int main(){
	cin>>A>>B>>C>>K;
	d=max(A,max(B,C));
	for(int i=0; i<K; i++) {
		d=d*2;
	}
	cout<<A+B+C+d-max(A,max(B,C))<<endl;
}

Measured memory_bytes: 256
import sys
def main():
    input = sys.stdin.readline
    H,W = map(int, input().split())
    s = [list(input().rstrip()) for _ in range(H)]

    c = lambda i,j: i*W+j
    used = [False] * (H*W+1)
    def dfs(si, sj):
        depth = 0
        stack = [(si, sj, 0)]
        while stack:
            i, j, d = stack.pop()
            for di, dj in [(0,1),(0,-1),(1,0),(-1,0)]:
                ni, nj = i+di, j+dj
                if ni < 0 or ni >= H or nj < 0 or nj >= W: continue
                if s[ni][nj] != '#': continue
                if used[c(ni,nj)]: continue
                used[c(ni,nj)] = True
                stack.append((ni, nj, d+1))
                depth = max(depth, d+1)
        return depth

    for i in range(H):
        for j in range(W):
            if used[c(i,j)] == False and s[i][j] == '#':
                depth = dfs(i,j)
                if depth == 0: return False
    return True

if __name__ == '__main__':
    print('Yes' if main() else 'No')

Measured memory_bytes: 41328
#入力の取得
n = int(input())

values = []

for i in range(n):
    query = list(map(int, input().split()))
    operation = query[0]
    if operation == 0: #後ろに足す
        value = query[1]
        values.append(value)
    elif operation == 1: #表示
        position = query[1]
        print(values[position])
    else:
        values.pop(-1) #末尾を消す


Measured memory_bytes: 13364
import sys, math, itertools, collections, bisect, heapq
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1
dydx4 = ((-1,0),(0,-1),(0,1),(1,0))
def check(i,j):
  return 0 <= i < h and 0 <= j < w 
def on_block(i,j):
  return S[i][j] == "#"
h,w = map(int,input().split())
ci,cj = map(int,input().split())
ci-=1;cj-=1
gi,gj = map(int,input().split())
gi-=1;gj-=1
S = [list(input()) for i in range(h)]
grid = [[inf] * w for i in range(h)]
grid[ci][cj] = 0
que = collections.deque()
que.append((0,ci,cj))
while que:
  now,si,sj = que.popleft()
  if now > grid[si][sj]:continue
  for di,dj in dydx4:
    ni = si + di
    nj = sj + dj
    if not check(ni,nj):continue
    if on_block(ni,nj): continue
    else:
      if now < grid[ni][nj] :
        grid[ni][nj] = now
        que.appendleft((now,ni,nj))
        # heapq.heappush(que,(now,ni,nj))
  for i in range(si-2,si+3):
    for j in range(sj-2,sj+3):
      if not check(i,j):continue
      if on_block(i,j):continue
      else:
        if now + 1 < grid[i][j] :
          grid[i][j] = now + 1
          que.append((now+1,i,j))
          # heapq.heappush(que,(now+1,i,j))
print(grid[gi][gj] if grid[gi][gj] != inf else -1)
# print(*grid,sep = "\n")

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

using ll = long long int;
using P = std::pair<int, int>;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rag(con) std::begin(con), std::end(con)

std::vector<int> node;

constexpr int INF = 1e9 + 10;

int m; //leafのサイズ

void init(int rsiz)
{

    m = 1;

    while (m < rsiz)
        m *= 2;

    node.resize(2 * m - 1);
} //ここで初期化して

void debug()
{

    int x = 0;

    rep(i, 2 * m - 1)
    {
        std::cerr << node[i] << ' ';
        if (x == i)
        {
            std::cerr << std::endl;
            x = x * 2 + 2;
        }
    }
}

void upd(int idx, int val)
{

    idx += m - 1;

    node[idx] = val;

    while (idx > 0)
    {
        idx = (idx - 1) / 2;
        node[idx] = std::max(node[2 * idx + 1], node[2 * idx + 2]);
    }
}

int get(int a, int b, int k = 0, int l = 0, int r = m)
{ //上からだんだんと下へ//[a,b) [l,r)
    if (a < 0)
        a = 0;

    if (b > m)
        b = m;

    if (r <= a || b <= l)
        return -INF; //範囲外

    if (a <= l && r <= b)
        return node[k]; //完全に範囲内

    //部分的に範囲内

    int lv = get(a, b, 2 * k + 1, l, (l + r) / 2);
    int rv = get(a, b, 2 * k + 2, (l + r) / 2, r);

    return std::max(lv, rv);
}

constexpr int MAXA = 3 * 1e5 + 10;

int main()
{
    int n, k;

    std::cin >> n >> k;

    std::vector<int> a(n);

    rep(i, n)
            std::cin >>
        a[i];

    init(MAXA);

    rep(i, n)
    {

        upd(a[i], get(a[i] - k, a[i] + k + 1) + 1);
    }

    int ans = 0;

    rep(i, n)
    {
        ans = std::max(ans, node[a[i] + m - 1]);
    }

    std::cout << ans << std::endl;

    return 0;
}

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

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define MIN(a) *min_element(all(a))
#define MAX(a) *max_element(all(a))
#define SUM(a) accumulate(all(a), 0LL)
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define FOR(i, m, n) for(int (i)=(m); (i)<(n); i++)
#define FORR(i, m, n) for(int (i)=(n)-1; (i)>=(m); i--)
#define debug(x) cerr << #x << " = " << x << endl
//#define int long long

typedef long long ll;
//ll const MOD = 998244353;
ll const MOD = 1e9+7;
int const inf = 1e9;
ll const INF = 1e18;

inline void ios_(){cin.tie(0); ios::sync_with_stdio(false);}
template<typename T> int size(const T& a){return (int)a.size();}
template<typename T> T Div(T a, T b){return (a + b - 1) / b;}
template<typename T> bool chmin(T& a, const T& b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, const T& b){if(a < b){a = b; return true;} return false;}



signed main(){
    ll n, a, b;
    cin >> n >> a >> b;

    if((b - a) % 2 == 0){
        cout << (b - a) / 2 << endl;
        return 0;
    }

    ll ans = INF;

    ll a0 = a - 1, b0 = b - a0 - 1;
    chmin(ans, a + (b0 - 1) / 2);

    ll b1 = n - b, a1 = a + b1 + 1;
    chmin(ans, b1 + 1 + (n - a1) / 2);

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
D = int(input())
c = list(map(int,input().split()))
s = []
for i in range(D):
    s.append(list(map(int,input().split())))
t = [int(input()) for _ in range(D)]
def my_index(l,x,d,default=False):
    if x in l:
        return l.index(x)
    else:
        return d
def last(d,i):
    a= t[:d]
    a.reverse()
    day = -1*(my_index(a,i,d))+d
    return day
score = 0
for d in range(1,D+1):
    score += s[d-1][t[d-1]-1]
    for i in range(1,27):
        score -= c[i-1]*(d-last(d,i))
    print(score)

Measured memory_bytes: 9264
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

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

    static class Task {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            String n = in.next();
            int sumA = 0;
            for (int i = 0; i < n.length(); i++) sumA += Integer.parseInt(n.substring(i, i + 1));
            int sumB = Integer.parseInt(n.substring(0, 1)) - 1;
            for (int i = 1; i < n.length(); i++) sumB += 9;

            int ans = sumA > sumB ? sumA : sumB;
            out.println(ans);
        }

    }
}



Measured memory_bytes: 23892
#include <iostream>
#include <bitset>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <regex>
using namespace std;
using ll = long long int;
using dd = long double;
const ll MOD = 1e9 + 7;

vector<string> dfs(string s, ll depth, vector<char> symbol)
{
    vector<string> ret;
    if (depth == 0)
    {
        ret.push_back(s);
        return ret;
    }

    for (ll i = 0; i < symbol.size(); i++)
    {
        auto vec = dfs(s + symbol[i], depth - 1, symbol);
        for (auto &&e : vec)
        {
            ret.push_back(e);
        }
    }
    return ret;
}

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

int main()
{
    ll r, g, b;
    cin >> r >> g >> b;

    ll seisuu = 100 * r + 10 * g + b;

    if (seisuu % 4 == 0) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 256
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String S = sc.next();
		int ans = 1;
		for(int i = 0; i < N-1; i++)
			if(S.charAt(i+1) != S.charAt(i))
				ans++;
		System.out.println(ans);

	}

}


Measured memory_bytes: 24548
#include<iostream>
#include<cmath>
#include<string>
#include<utility>
#include<vector>
#include<array>

using namespace std;


int main(){
    int A,B,C,K;
    cin >> A >> B >> C >> K;
    if(K<A+1){
        cout << K << endl;
    }else if(K>A && K < A+B +1){
        cout << A << endl;
    }else if(K>A+B){
        cout << A-(K-A-B) << endl;
    }
    return 0;
}


Measured memory_bytes: 3196
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <climits>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int p_cnt = 0;
    int g_cnt = 0;
    int win = 0;
    int lose = 0;
    REP(i, s.size()) {
        if(s[i] == 'g') {
            if(p_cnt < g_cnt) {
                win++;
                p_cnt++;
            } else {
                g_cnt++;
            }
        } else { // p
            if(p_cnt < g_cnt) {
                p_cnt++;
            } else {
                lose++;
                g_cnt++;
            }
        }
    }
    cout << win - lose << endl;
    return 0;
}


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

using namespace std;

int main()
{
  int i,N;
  cin>>N;
  vector<int> vec(N);
  int n=N;
  for(i=0;i<n;i++)
  {
      int k;
      cin>>k;
      vec[i]=k;
  }
  int sum=0;
  for(i=0;i<n;i++)
  {
      sum=sum+vec[i];
  }
  int per_sum;
  per_sum=sum;
  int T;
  cin>>T;
  while(T--)
  {
      int k,m,temp,sumt;
      sum=per_sum;
      cin>>k>>m;
      temp=vec[k-1];
      sum=sum-temp+m;
      cout<<sum<<endl;
      
  }
    
    
    
    
    
}


Measured memory_bytes: 256
/* {{{ Shinobu kawaii */
/*
  ______   __        _                  __                 
.' ____ \ [  |      (_)                [  |                
| (___ \_| | |--.   __   _ .--.   .--.  | |.--.   __   _   
 _.____`.  | .-. | [  | [ `.-. |/ .'`\ \| '/'`\ \[  | | |  
| \____) | | | | |  | |  | | | || \__. ||  \__/ | | \_/ |, 
 \______.'[___]|__][___][___||__]'.__.'[__;.__.'  '.__.'_/ 
                                                           
*/
/* }}} */

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

// #define int long long

/* cpp template {{{ */

/* short */
#define pb push_back
#define mp make_pair
#define print(x) cout << x << '\n'
#define Fi first
#define Se second

/* REPmacro */
#define REPS(i, a, n) for (int i = (a); i < (n); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = 1; i <= (n); i++)
#define DEPS(i, a, n) for (int i = (a); i >= n; i--)
#define DEP(i, n) for (int i = (n); i >= 0; i--)

/* typedef */
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vector<int> > vii;
typedef pair<int, int> pii;

/* const */
const int INF = 999999999;
const int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};

/* func */
inline bool is_uruu(int y) {return (y % 4 == 0 && (y % 100 != 0 || y % 400 == 0));}
inline bool inside(int y, int x, int H, int W) {return (y >= 0 && x >= 0 && y < H && x < W);}

/* }}} */

signed main()
{
  ios::sync_with_stdio(false);
  int n;
  while (cin >> n, n){
    vi a(n);
    int ans = -99999999;
    REP(i, n) cin >> a[i];
    REP(i, n){
      int sum = 0;
      REPS(j, i, n){
        sum += a[j];
        ans = max(ans, sum);
      }
    }
    print(ans);
  }

  return (0);
}

Measured memory_bytes: 1208
n = input();print(n[0:4]+" "+n[4:12])

##
## Template
##

## map, filter, reduce

# map(lambda x: x*2, range(10))
# filter(lambda x: x % 2, range(10))
# from functools import reduce
# reduce(lambda sum,x: sum+x, range(10))
# [x * 2 for x in range(1, 10) if x % 3 == 1]
# => [2, 8, 14]


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} fast;
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
long long mod = 1000000007;

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

void yes() {
    cout << "Yes" << endl;
    exit(0);
}
void no() {
    cout << "No" << endl;
    exit(0);
}
#define REP(i, n) for (long long i = 0; i < (n); i++)
template <typename A, size_t N, typename T> void Fill(A (&array)[N], const T& val) {
    std::fill((T*)array, (T*)(array + N), val);
}
signed main() {
    int n, k;
    cin >> n >> k;
    vector<ll> as(n);
    REP(i, n) { cin >> as[i]; }
    map<ll, ll> cnt;
    sort(as.begin(), as.end());
    int cost = 0;
    REP(i, n) {
        if (k > 0) {
            cost += as[i];
            k = k - 1;
        }
    }
    cout << cost << endl;
}

Measured memory_bytes: 3664
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <deque>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

const int MAX = 100001;
const int MOD = 1000000007;

typedef long long ll;
typedef pair< int, int > pii;
typedef pair< ll, ll > pll;
typedef pair< ll, int > pli;
typedef pair< int, ll > pil;

int ceil(int x, int y){
  return (x % y == 0) ? x / y : x / y + 1;
}

int gcd(int x, int y){
  return y ? gcd(y, x % y) : x;
}

int lcm(int x, int y){
  return x / gcd(x, y) * y;
}

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

  string s, t;
  cin >> s;
  cin >> t;

  int count = 0;
  for(int i = 0; i < 3; i++){
    if(s[i] == t[i]) ++count;
  }

  cout << count << endl;

  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include<deque>
typedef long long int ll;

using namespace std;

int main()
{
    int N;
    cin>>N;
    deque<ll> p;
    while(N--)
    {
        int numhah;
        cin>>numhah;
        switch (numhah)
        {
            case 0:
            int opr;
            cin>>opr;
            ll num;
            cin>>num;
            if(opr==1)p.push_back(num);
            else p.push_front(num);
                break;
            case 1:
                int num1;
                cin>>num1;
                cout<<p.at(num1)<<endl;
                break;
            case 2:
                int num2;
                cin>>num2;
                if(num2==0)p.pop_front();
                else p.pop_back();
                break;
            default:break;
        }
    }
}



Measured memory_bytes: 6228
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<(n);i++)
#define loop(i,a,n) for(i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define int ll
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;

#define MAX_DAMAGE 2*100000

int dp1[MAX_DAMAGE];
//dp1[j]=(i番目のALL魔法を使って)ダメージをj与えたときの最小のMP消費量
int dp2[MAX_DAMAGE];
//dp2[j]=(i番目のsingle魔法を使って)ダメージをj与えたときの最小のMP消費量

signed main(void) {
  int i,j;
  int n;
  while(1){
    cin>>n;
    if(n==0)break;
    vi hp(n);
    rep(i,n)cin>>hp[i];
    int m;
    cin>>m;
    vector<pii> all,single;
    rep(i,m){
      string s,t;
      int mp,dmg;
      cin>>s>>mp>>t>>dmg;
      dmg=min(100000LL,dmg);
      if(t[0]=='S') single.push_back(pii(mp,dmg));
      else all.push_back(pii(mp,dmg));
    }

    rep(i,MAX_DAMAGE)//init
      dp1[i]=dp2[i]=INF;

    dp1[0]=dp2[0]=0;

    rep(i,all.size()){
      int mp=all[i].first;
      int dmg=all[i].second;
      rep(j,MAX_DAMAGE)
	if(j+dmg<MAX_DAMAGE)
	  dp1[j+dmg]=min(dp1[j+dmg],dp1[j]+mp);  
    }
    rep(i,single.size()){
      int mp=single[i].first;
      int dmg=single[i].second;
      rep(j,MAX_DAMAGE)
	if(j+dmg<MAX_DAMAGE)
	  dp2[j+dmg]=min(dp2[j+dmg],dp2[j]+mp);
    }
    for(i=MAX_DAMAGE-2;i>=0;i--)
      dp2[i]=min(dp2[i],dp2[i+1]);

    int ans=INF;

    rep(i,MAX_DAMAGE){

      int t=dp1[i];

      rep(j,n)
	t+=dp2[max(0LL,hp[j]-i)];

      ans=min(ans,t);

    }

    cout<<ans<<endl;

  }
}



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

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

using namespace std;

const int INF=1<<29;

int main(){
	string s; cin>>s;
	int n=s.length();

	map<int,int> dp;
	dp[0]=0;
	int cum=0;
	rep(i,n){
		cum^=1<<(s[i]-'a');

		int res=INF;
		if(dp.count(cum)>0) res=dp[cum]+1;
		rep(c,26){
			int cum2=cum^(1<<c);
			if(dp.count(cum2)>0) res=min(res,dp[cum2]+1);
		}

		if(dp.count(cum)==0){
			dp[cum]=res;
		}
		else{
			dp[cum]=min(dp[cum],res);
		}

		if(i==n-1) printf("%d\n",res);
	}

	return 0;
}


Measured memory_bytes: 13108
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
using namespace std;
char s[1001],t[1001];
string T,ST; 
int main() {
	cin>>(s+1);
	cin>>(t+1);
	int lens=strlen(s+1);
	for (int i=1; i<=lens; i++)
		s[i+lens]=s[i];
	lens*=2;
	int lent=strlen(t+1);
	for (int i=1; i<=lent; i++) T+=t[i]; 
	for (int i=1; i<=lens-lent+1; i++) {
		ST="";
		for (int j=i; j<=i+lent-1; j++)
			ST+=s[j];
		if (ST==T) {
			puts("Yes");
			return 0;
		}
	}
	puts("No");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(s,i, n) for (int i = (int)s; i < (int)(n); i++)
#define pb push_back
typedef long long ll;
  
int main(){
    ll x,y;
    cin>>x>>y;
    ll a,b,c;
    cin>>a>>b>>c;
    vector<ll> p(a);
    vector<ll> q(b);
    vector<ll> r(c);

    rep(i,a)cin>>p[i];
    rep(i,b)cin>>q[i];
    rep(i,c)cin>>r[i];

    sort(p.begin(),p.end(),greater<ll>());
    sort(q.begin(),q.end(),greater<ll>());
    sort(r.begin(),r.end(),greater<ll>());

    ll dx=0;
    ll dy=0;
    ll dz=0;
    ll da=0;
    ll db=0;
    ll dc=0;
    ll sum=0;

    ll nx=0;
    ll ny=0;
    ll nz=0;
    while(dx<x || dy<y){
        ll xx=(dx<x)?p[dx]:0;
        ll yy=(dy<y)?q[dy]:0;
        ll zz=(dz<c)?r[dz]:0;
        if(xx>yy && xx>zz){
            sum+=xx;
            dx+=1;
            nx+=1;
        }else if(xx<=yy && yy>=zz){
            sum+=yy;
            dy+=1;
            ny+=1;
        }else{
            sum+=zz;
            dz+=1;
            nz+=1;
        }
    }
    vector<ll> xyz;
    rep(i,nx)xyz.pb(p[i]);
    rep(i,ny)xyz.pb(q[i]);
    rep(i,nz)xyz.pb(r[i]);

    sort(xyz.begin(),xyz.end(),greater<ll>());

    sum=0;
    rep(i,x+y)sum+=xyz[i];
    
    
    /*
    while(nx+ny+nz>(x+y) || nx >x || ny>y){
        bool checkx=(nx==0)?false:true;
        bool checky=(ny==0)?false:true;
        bool checkz=(nz==0)?false:true;
        ll xx=(nx>1)?p[nx-1]:1000000000;
        ll yy=(ny>1)?q[ny-1]:1000000000;
        ll zz=(nz>1)?r[nz-1]:1000000000;
        if(checkx && xx<yy && (xx<zz|| !checkz)){
            sum-=xx;
            nx-=1;if(nx<0)nx=0;
        }else if(checky && xx>=yy && (yy<=zz|| !checkz)){
            sum-=yy;
            ny-=1;if(ny<0)ny=0;
        }else{
            if(checkz){
                sum-=zz;
                nz-=1;if(nz<0)nz=0;
            }
            
            
        }
    }
    */

    cout<<sum<<endl;


    
    return 0;
}

Measured memory_bytes: 8688
n = int(input())
num_list = list(map(int, input().split()))
 
ans = 'Yes'
 
for i in range(n - 1):
  if i == 0:
    if num_list[i] > num_list[i + 1]:
      num_list[i] -= 1
  
  if num_list[i] > num_list[i + 1]:
    ans = 'No'
    break
  
  if num_list[i] < num_list[i + 1]:
    num_list[i + 1] -= 1
    
print(ans)

Measured memory_bytes: 14224
/*
ID: alec3
LANG: C++14
PROG: highcard
*/


#include <bits/stdc++.h>

#define check(x) cout<<(#x)<<": "<<x<<" ";
#define io ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ss second
#define ff first
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define FOR(i, a, b) for (int i = a; i < b; i++)

typedef long long ll;
typedef unsigned long long ull;

int pct(int x) { return __builtin_popcount(x); }

using namespace std;

//ifstream fin("zerosum.in");
//ofstream fout("zerosum.out");

void solve(){
    ll k;
    cin >> k;
    if (k % 7 < 1){
        k /= 7;
    }
    if(k % 2 < 1 || k % 5 < 1){
        cout << -1 << endl;
        return;
    }
    k *= 9;
    int ans = 1;
    ll p = 10 % k;
    while (p != 1){
        p = p * 10 % k;
        ans ++;
    }
    cout << ans << endl;
    return;
}

int main() {
    io;
    solve();


    return 0;
}


Measured memory_bytes: 3636
///Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>

#define                           int                         long long
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<int,int>
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);




using namespace std;

const int inf=1e18;
const int mod=1e9+7;
const int M=100009;
inline int bigmod(int B,int P){int R=1;while(P>0){if(P&1){R=(R*B)%mod;}P>>=1;B=(B*B)%mod;}return R;}


 main()

{
    fast
    long double ses,r;
    cin>>r;
    ses=r*3.1416*2.00;
    cout<<fixed<<setprecision(15)<<ses<<endl;


















    return 0;

}













Measured memory_bytes: 3808
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <complex>
#include <iomanip>
//定数
#define MOD 1000000007
//マクロ
#define rep(i,n)    for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))

#define vsort(v) sort((v).begin(), (v).end());

typedef unsigned long long int ull;
typedef long long lint;

using namespace std;




int main(){
    int N;
    lint ans=0;


    //入力
    cin >> N;

    vector<int> A(N+1);
    vector<int> B(N);
    rep(i, N+1) cin >> A[i];
    rep(i, N) cin >> B[i];
    

    for(int i=0; i<N; i++) {
        if(A[i] >= B[i]) {
            ans += B[i];
            //cout << "brave " << i+1 << " killed " << B[i] << "enemy  in town " << i << endl;
        } else {
            ans += A[i];
            B[i] -= A[i];
            //cout << "brave " << i+1 << " killed " << A[i] << "enemy  in town " << i << endl;
            if(A[i+1] >= B[i]) {
                //cout << "brave " << i+1 << " killed " << B[i] << "enemy  in town " << i << endl;
                ans += B[i];
                A[i+1] -= B[i];
            } else {
                //cout << "brave " << i+1 << " killed " << A[i+1] << "enemy  in town " << i << endl;
                ans += A[i+1];
                A[i+1] = 0;
            }
        }
    }

    cout << ans << endl;

    return 0;
}

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

#define mod      1e9+7;
#define INF      1e9+9;
#define ps(x,y)  fixed<<setprecision(y)<<x
typedef long long ll;
typedef unsigned long long ull;
int n,m;
vector<int> v[100001];
int vis[100001];
int sig[100001];
void bfs(int root){
	queue<int> q;
	q.push(root);
	while(q.size()!=0){
		int si=q.size();
		while(si--){
			int ele=q.front();
			q.pop();
			for(int child: v[ele]){
				if(vis[child]==0){
					vis[child]=1;
					q.push(child);
					sig[child]=ele;
				}
			}
		}
	}

}
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
#endif
	int n,m,a,b;
	cin>>n>>m;
	for(int i=0;i<m;i++){
		cin>>a>>b;
		v[a].push_back(b);
		v[b].push_back(a);
	}
	sig[1]=1;
	vis[1]=1;
	bfs(1);
	for(int i=2;i<=n;i++){
		if(sig[i]==0){
			cout<<"No\n";
			return 0;
		}
	}
	cout<<"Yes\n";
	for(int i=2;i<=n;i++){
		cout<<sig[i]<<endl;
	}

	return 0;
}

Measured memory_bytes: 10856
#include <iostream>
#include <vector>
#include <unordered_map>
#include <map>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <deque>
#include <cmath>
#include <stack>
#include <queue>
#include <string>
#include <iomanip>
#include <cstring>
#include <climits>
#include <cstdio>

#define nl '\n'

using namespace std;
 
int n, a;

int main(){

    cin >> n;

    vector<int> v;

    for(int i = 0; i < n; i++){
        cin >> a;
        if(a%2==0 && (a%3!=0 && a%5!=0)){
            cout << "DENIED";
            return 0;
        }
    }

    cout << "APPROVED";
 
}
 
//g++ -std=c++14 comp.cpp -o b; ./b.exe
//g++ -std=c++14 comp.cpp && ./a.out

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		final Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		long m = sc.nextLong();
		if(n == 1 && m == 1) {
			System.out.println(1);
		} else if(n == 1) {
			System.out.println(m-2);
		} else if(m == 1) {
			System.out.println(n-2);
		} else {
			System.out.println((n-2)*(m-2));
		}
	}
}

Measured memory_bytes: 22740
#include "bits/stdc++.h"
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define FOR(i,init,a) for(int i=init; i<a; i++)
#define rep(i,a) FOR(i,0,a)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()
#define chmin(a,b) a=min(a,b);
#define chmax(a,b) a=max(a,b);

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

ll nums[59];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll K;
    cin>>K;
    
    rep(i,50) nums[i]=49-i;
    rep(i,50) nums[i]+=K/50;
    K%=50;
    rep(i,K) nums[i]++;
    
    cout1(50)
    rep(i,50){
        if(i) cout<<" ";
        cout<<nums[i];
    }
}

Measured memory_bytes: 256
from math import *
n=int(input())
l=floor(sqrt(n))+1
ans=[0]*n
def f(a,b,c):
    return a*a+b*b+c*c+a*b+b*c+c*a
for x in range(1,l+1):
    for y in range(1,l+1):
        for z in range(1,l+1):
            g=f(x,y,z)
            if g<=n:
                ans[g-1]+=1
for i in range(n):
    print(ans[i])

Measured memory_bytes: 69780
#include <stdio.h>

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

    char e = '\0';
    int res = 0;
    for(int ni=0; ni<N; ni++){
        char c;
        scanf("%c", &c);
        if(e != c){
            e = c;
            res ++;
        }
    }
    printf("%d\n", res);
    
    return 0;
}


Measured memory_bytes: 128
%:pragma GCC optimize(2)
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
using namespace std;

#define int long long

const int N = 1e5 + 5;

int n , m , x , y , cnt , ans , tot;
int pr[N] , a[N] , luck[N];
bool isp[N];

map<int , int>Map;

void prework(int n) {
	memset(isp , 1 , sizeof(isp));
	isp[1] = 0;
	for(int i = 2;i <= n;++ i) {
		if(isp[i]) pr[++ cnt] = i , luck[cnt] = i * i * i;
		for(int j = 1;j <= cnt && pr[j] * i <= n;++ j) {
			isp[pr[j] * i] = 0;
			if(i % pr[j] == 0) break;
		}
	}
}

vector< pair<int,int> > Vec;

#define mp(x , y) make_pair(x , y)
#define pb push_back

void chg(int x) {
	int a , b;
	a = 1; b = 1;
	for(int i = 1;i <= cnt;++ i) {
		int tot = 0;
		while(x % pr[i] == 0) {
			++ tot; x /= pr[i];
		} 
		tot %= 3;
		if(!tot) continue;
		int ano = 3 - tot;
		while(tot --) a *= pr[i];
		while(ano --) b *= pr[i];
		if(b > 1e10) {
			ans ++; return;
		}
	}
	int y = sqrt(a);
	y --; y = max(y , 0ll);
	while(y * y < x) ++ y;
	if(y * y != x) {
		a *= x;
		b *= x;
		if(b > (1e10) / (double)x - 5) {
			ans ++; return;
		}
		b *= x;
	}
	else {
		a *= x; b *= y;
		if(b > 1e10) {
			ans ++; return;
		}
	}
	Map[a] ++;
	Vec.push_back(mp(a , b));
}

void dance(void) {
	for(int i = 0;i < (int) Vec.size(); ++ i) {
		if(Vec[i].first == 1 && Map[1]) {
			ans ++; Map[1] = 0;
			continue;
		}
		if(Map[Vec[i].first]) {
			ans += max(Map[Vec[i].first] , Map[Vec[i].second]);
			Map[Vec[i].first] = Map[Vec[i].second] = 0;
		}
	}
	cout << ans << endl;
}

main(void) {
//	freopen("data.txt" , "r" , stdin);
	scanf("%lld" , &n);
	for(int i = 1;i <= n;++ i) scanf("%lld" , &a[i]);
	prework(3000);
	for(int i = 1;i <= n;++ i) {
		chg(a[i]);
//		if(i % 1000 == 0) cerr << i << endl;
	}
	dance();
}

Measured memory_bytes: 13040
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
using namespace std;
int main(){
  int n;
  cin >> n;
  pair< pair<string, int>, int> pa[110];

  for (int i = 0; i < n; i++){
    string s;
    int p;
    cin >> s >> p;
    pa[i] = make_pair(make_pair(s, -p), i);
  }

  sort(pa, pa+n);
  for (int i = 0; i < n; i++){
    cout << pa[i].second + 1 << endl;
  }
}


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

#define R register
#define ll long long
#define sum(a, b, mod) (((a) + (b)) % mod)

ll n, a[50];

ll f(ll l, ll r, ll x, ll y)
{
    ll ans = 1e18;
    if(r - l <= 1) return 0;
    for(int i = l + 1; i <= r - 1; i++)
        ans = std::min((f(l, i, x, x + y) + f(i, r, x + y, y) + a[i] * (x + y)), ans);
    return ans;
}

int main()
{   
    scanf("%lld", &n);
    for(int i = 1; i <= n; i++)
        scanf("%lld", &a[i]);
    printf("%lld\n", f(1, n, 1, 1) + a[1] + a[n]);
    return 0;
}


Measured memory_bytes: 384