akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()

int main() {
  string s;
  cin >> s;
  int N = s.size();

  if(s[0] != '1' || s[N - 1] != '0') {
    cout << -1 << endl;
    return 0;
  }
  s.pop_back();
  {
    string t = s;
    reverse(all(t));
    if(s != t) {
      cout << -1 << endl;
      return 0;
    }
  }



  vector<int> left;
  vector<int> right;
  vector<pair<int,int>> ans;
  int v = 1;
  left.push_back(v++);
  right.push_back(v++);
  int next = v;
  for(int i = 2;i <= N - i;i++) {
    if(s[i - 1] == '0') {
      left.push_back(next++);
      right.push_back(next++);
    }
    else {
      int LEFT = next++;
      int RIGHT = next++;
      v = next;
      for(auto x: left) {
        ans.push_back({ x, LEFT });
      }
      for(auto x: right) {
        ans.push_back({ x, RIGHT });
      }
      left.clear();
      right.clear();
      left.push_back(LEFT);
      right.push_back(RIGHT);
    } 
  }

  if(v == N + 1) {
    ans.push_back({ left.front(), right.front() });
  }
  else {
    int CENTER = v++;
    ans.push_back({ left.front(), CENTER });
    ans.push_back({ right.front(), CENTER });

    while(v <= N) {
      ans.push_back({ CENTER, v++ });
    }
  }

  for(auto p: ans) {
    cout << p.first << " " << p.second << endl;
  }
}


Measured memory_bytes: 2612
#include <bits/stdc++.h>
#include <stdio.h>
#include <cmath>

using namespace std;

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
//rep…「0からn-1まで」の繰り返し
#define rep2(i,s,n) for(long long i=s; i<=(long long)(n);i++)
//rep2…「sからnまで」の繰り返し
#define repr(i,s,n) for(long long i=s;i>=(long long)(n);i--)
//repr…「ｓからnまで」の降順の繰り返し

typedef long long ll;

const ll inf = 1e18+7;
const ll mod = 1e9+7;

//階乗
int factorial(int k){
    int result=1;
    for (int i=1;i<=k;++i){
        result*=i;
    }
    return result;
}

int main() {

    string s;
    cin>>s;

    int a=s[0]-'0',b=s[1]-'0',c=s[2]-'0',d=s[3]-'0';

    if(a+b+c+d==7)cout<<a<<'+'<<b<<'+'<<c<<'+'<<d<<"=7"<<endl;
    else if(a+b+c-d==7)cout<<a<<'+'<<b<<'+'<<c<<'-'<<d<<"=7"<<endl;
    else if(a+b-c+d==7)cout<<a<<'+'<<b<<'-'<<c<<'+'<<d<<"=7"<<endl;
    else if(a-b+c+d==7)cout<<a<<'-'<<b<<'+'<<c<<'+'<<d<<"=7"<<endl;
    else if(a-b-c+d==7)cout<<a<<'-'<<b<<'-'<<c<<'+'<<d<<"=7"<<endl;
    else if(a+b-c-d==7)cout<<a<<'+'<<b<<'-'<<c<<'-'<<d<<"=7"<<endl;
    else if(a-b+c-d==7)cout<<a<<'-'<<b<<'+'<<c<<'-'<<d<<"=7"<<endl;
    else if(a-b-c-d==7)cout<<a<<'-'<<b<<'-'<<c<<'-'<<d<<"=7"<<endl;


}


Measured memory_bytes: 256
n = int(input())
w = list(map(int,input().split()))

# sort_w = sorted(w)

wsum = sum(w)
amin = wsum
for i, a in enumerate(w):
    s_1 = sum(w[:i])
    s_2 = wsum - s_1
    tmp_min = abs(s_1 - s_2)
    if amin > tmp_min:
        amin = tmp_min

print(amin)

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

int main()
{
	ll N;
	cin >> N;
	ll res = 0;
	for (ll m = 1; m * m < N; m++) {
		if ((N - m) % m == 0) {
			ll x = (N - m) / m;
			if (N % x == N / x) {
				res += x;
			}
		}
	}
	cout << res << endl;
	return 0;
}


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

int main() {
    int A, B, M;
    cin >> A >> B >> M;
    int mina = 1e9;
    vector<int> a(A);
    for (int i = 0; i < A; i++) {
        cin >> a[i];
        mina = min(mina, a[i]);
    }
    int minb = 1e9;
    vector<int> b(B);
    for (int i = 0; i < B; i++) {
        cin >> b[i];
        minb = min(minb, b[i]);
    }
    int minv = 1e9;
    for (int i = 0; i < M; i++) {
        int x, y, c;
        cin >> x >> y >> c;
        x--;
        y--;
        minv = min(minv, a[x] + b[y] - c);
    }

    cout << min(minv, mina + minb) << endl;
}

Measured memory_bytes: 1024
import kotlin.math.*
import java.util.*

const val MOD = 1_000_000_007L

fun readI() = readLine()!!.toInt()
fun readL() = readLine()!!.toLong()
fun readD() = readLine()!!.toDouble()
fun readIs() = readLine()!!.split(' ').map(String::toInt)
fun readLs() = readLine()!!.split(' ').map(String::toLong)
fun readDs() = readLine()!!.split(' ').map(String::toDouble)

fun main() {
  val n = readI()
  val aa = readLs()
  val s = LongArray(n)
  s[0] = aa[0]
  for (i in 1 until n) {
    s[i] = (s[i - 1] + aa[i]) % MOD
  }
  var x = 0L
  for (i in 0 until n - 1) {
    var t = s[n - 1] - s[i]
    if (t < 0) t += MOD
    x += aa[i] * t % MOD
    x %= MOD
  }
  println(x)
}


Measured memory_bytes: 65024
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <utility>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <istream>
#include <ostream>

#include <cstdlib>
#include <cmath>
#include <cstdio>

using namespace std;

#define fi first
#define se second
#define mkp make_pair
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define rep(i,n) for(ll i=0; i < (n); ++i)
#define rrep(i,n) for(ll i=((n)-1); i >= 0; --i)

#define OPLT(T) bool operator<(const T & lop_, const T & rop_)
#define OPEQ(T) bool operator==(const T & lop_, const T & rop_)

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

istream& operator>>(istream& istr, __float128& obj) { double d; istr >> d; obj = d; return istr; };
ostream& operator<<(ostream& ostr, __float128& obj) { ostr << static_cast<double>(obj); return ostr; };

int main() {
	int N, T;
	cin >> N >> T;
	vector<int> A(N), B(N), C(N);
	rep(i,N) cin >> A[i];
	B[0] = A[0];
	for(int i = 1; i < A.size(); i++)
		B[i] = min(B[i-1], A[i]);
	C.back() = A.back();
	for(int i = (int)A.size() - 2; i >= 0; i--)
		C[i] = max(A[i], C[i+1]);
	int benefit = 0;
	rep(i,N) {
		benefit = max(benefit, C[i] - B[i]);
	}
	
	int mn = A[0];
	pii t(0,0);
	vector<pii> v;
	for(int i = 0; i < A.size(); i++) {
		if(A[i] < mn) {
			v.push_back(t);
			t = pii(0,0);
			mn = A[i];
		}

		if(A[i] == mn) {
			t.fi++;
		}
		if(A[i] == mn + benefit) {
			t.se++;
		}
	}
	v.push_back(t);

	int res = 0;
	rep(i,v.size())
		res += min(v[i].fi, v[i].se);
	cout << res << endl;

	return 0;
}


Measured memory_bytes: 2044
#include <stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
long long cmpfunc (const void * a, const void * b) {
   return ( *(long long*)a - *(long long*)b );
}



int main(void){
   
long long int test,i,j,n,count,flag=0,o1=0,o2=0,b1,x,m,l,max,sum2,min,f,c,r,o,sum1,sum=0,y,a,b,count1=0,a2,b2;

scanf("%lld %lld %lld",&r,&m,&n);
for(i=0;i<10;i++){
    n=(r*n)-m;
    printf("%lld\n",n);
}


return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<math.h>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<functional>
#include<map>
#include<set>
#include <string>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
map<int, int> mp;
map<int, int>mm;
#define ll long long
#define ld long double
#define PI 3.14159265358979l



int main() {
	int a, b;
	cin >> a >> b;
	if (b%a == 0)cout << a + b << endl;
	else cout << b - a << endl;




	return 0;
}

Measured memory_bytes: 764
import java.util.*;

class Main{
	public static void main(String[] args){
		int[] count = new int[26];		
		for(int i=0;i<26;i++){
			count[i]=0;
		}
		Scanner sc=new Scanner(System.in);
		while(sc.hasNextLine()){
			String line=sc.nextLine();
			for(int i=0;i<line.length();i++){
				String s =line.substring(i,i+1);
		if(s.equals("A") || s.equals("a")){
			count[0]+=1;
		}else if(s.equals("B") || s.equals("b")){
			count[1]+=1;
		}else if(s.equals("C") || s.equals("c")){
			count[2]+=1;
		}else if(s.equals("D") || s.equals("d")){
			count[3]+=1;
		}else if(s.equals("E") || s.equals("e")){
			count[4]+=1;
		}else if(s.equals("F") || s.equals("f")){
			count[5]+=1;
		}else if(s.equals("G") || s.equals("g")){
			count[6]+=1;
		}else if(s.equals("H") || s.equals("h")){
			count[7]+=1;
		}else if(s.equals("I") || s.equals("i")){
			count[8]+=1;
		}else if(s.equals("J") || s.equals("j")){
			count[9]+=1;
		}else if(s.equals("K") || s.equals("k")){
			count[10]+=1;
		}else if(s.equals("L") || s.equals("l")){
			count[11]+=1;
		}else if(s.equals("M") || s.equals("m")){
			count[12]+=1;
		}else if(s.equals("N") || s.equals("n")){
			count[13]+=1;
		}else if(s.equals("O") || s.equals("o")){
			count[14]+=1;
		}else if(s.equals("P") || s.equals("p")){
			count[15]+=1;
		}else if(s.equals("Q") || s.equals("q")){
			count[16]+=1;
		}else if(s.equals("R") || s.equals("r")){
			count[17]+=1;
		}else if(s.equals("S") || s.equals("s")){
			count[18]+=1;
		}else if(s.equals("T") || s.equals("t")){
			count[19]+=1;
		}else if(s.equals("U") || s.equals("u")){
			count[20]+=1;
		}else if(s.equals("V") || s.equals("v")){
			count[21]+=1;
		}else if(s.equals("W") || s.equals("w")){
			count[22]+=1;
		}else if(s.equals("X") || s.equals("x")){
			count[23]+=1;
		}else if(s.equals("Y") || s.equals("y")){
			count[24]+=1;
		}else if(s.equals("Z") || s.equals("z")){
			count[25]+=1;
		}
			}
		}
		System.out.println("a : "+count[0]);
		System.out.println("b : "+count[1]);
		System.out.println("c : "+count[2]);
		System.out.println("d : "+count[3]);
		System.out.println("e : "+count[4]);
		System.out.println("f : "+count[5]);
		System.out.println("g : "+count[6]);
		System.out.println("h : "+count[7]);
		System.out.println("i : "+count[8]);
		System.out.println("j : "+count[9]);
		System.out.println("k : "+count[10]);
		System.out.println("l : "+count[11]);
		System.out.println("m : "+count[12]);
		System.out.println("n : "+count[13]);
		System.out.println("o : "+count[14]);
		System.out.println("p : "+count[15]);
		System.out.println("q : "+count[16]);
		System.out.println("r : "+count[17]);
		System.out.println("s : "+count[18]);
		System.out.println("t : "+count[19]);
		System.out.println("u : "+count[20]);
		System.out.println("v : "+count[21]);
		System.out.println("w : "+count[22]);
		System.out.println("x : "+count[23]);
		System.out.println("y : "+count[24]);
		System.out.println("z : "+count[25]);
	}
}

Measured memory_bytes: 26552
import math
N = int(input())

def get_prime(n):
    if n <= 1:
        return []
    prime = [2]
    limit = int(math.sqrt(n))

    data = [i + 1 for i in range(2, n, 2)]
    while limit > data[0]:
        prime.append(data[0])
        data = [j for j in data if j % data[0] != 0]
    return prime + data

prime_list = get_prime(55555)
ans_list = []
for i in prime_list:
    if i % 5 == 1:
        ans_list.append(i)
    if len(ans_list) == N:
        break
for i in ans_list:
    print(i, end=' ')

Measured memory_bytes: 4340
#include <stdio.h>

int main(void)
{
	int n,x,i,j,k,c;

	while(1){
	scanf("%d %d", &n, &x);
	if(n==0 && x==0){
		break;
	}
	c = 0;
		for(i=1;i<n-1;i++){
			for(j=i+1;j<n;j++){
				for(k=j+1;k<n+1;k++){
					if(i+j+k == x){
					c++;
					}
				}
			}
		}
			printf("%d\n", c);
	}

		return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <string>

using namespace std;

int main(){
    string A, B; cin >> A >> B;
         if (A.size() > B.size()) cout << "GREATER" << endl;
    else if (A.size() < B.size()) cout << "LESS"    << endl;
    else {
         if (A        > B       ) cout << "GREATER" << endl;
    else if (A        < B       ) cout << "LESS"    << endl;
    else                          cout << "EQUAL"   << endl;
    }
    return 0;
}

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

typedef struct {
    char suit;
    int value;
} Card;

void merge(Card A[], int left, int mid, int right) {
    int i = 0;
    int j = 0;
    int k;
    int n1 = mid - left;
    int n2 = right - mid;
    Card *L = (Card *)malloc((n1 + 1) * sizeof(Card));
    Card *R = (Card *)malloc((n2 + 1) * sizeof(Card));
    memcpy(L, A + left, (n1 + 1) * sizeof(Card));
    memcpy(R, A + mid, (n2 + 1) * sizeof(Card));
    L[n1].value = 2000000000;
    R[n2].value = 2000000000;
    for (k = left; k < right; k++) {
        if (L[i].value <= R[j].value) {
            A[k] = L[i];
            i++;
        } else {
            A[k] = R[j];
            j++;
        }
    }
    free(R);
    free(L);
}

void mergeSort(Card A[], int left, int right) {
    if (left + 1 < right) {
        int mid = (left + right) / 2;
        mergeSort(A, left, mid);
        mergeSort(A, mid, right);
        merge(A, left, mid, right);
    }
}

int partition(Card A[], int p, int r) {
    Card x = A[r];
    int i = p - 1;
    int j;
    for (j = p; j < r; j++) {
        if (A[j].value <= x.value) {
            Card tmp = A[j];
            i++;
            A[j] = A[i];
            A[i] = tmp;
        }
    }
    A[r] = A[i + 1];
    A[i + 1] = x;
    return i + 1;
}

void quickSort(Card A[], int p, int r) {
    if (p < r) {
        int q = partition(A, p, r);
        quickSort(A, p, q - 1);
        quickSort(A, q + 1, r);
    }
}

void printarray(Card A[], int n) {
    int i;
    for (i = 0; i < n; i++) {
        printf("%c %d\n", A[i].suit, A[i].value);
    }
}

int equals(Card A[], Card B[], int n) {
    int i;
    for (i = 0; i < n; i++) {
        if (A[i].suit != B[i].suit) return 0;
    }
    return 1;
}

int main(void) {
    int n, i, q;
    Card A[100000];
    Card B[100000];
    scanf("%d", &n);
    for (i = 0; i < n; i++) {
        scanf(" %c %d", &A[i].suit, &A[i].value);
        B[i] = A[i];
    }
    quickSort(A, 0, n - 1);
    mergeSort(B, 0, n);
    if (equals(A, B, n)) printf("Stable\n");
    else printf("Not stable\n");
    printarray(A, n);
    return 0;
}



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

bool cmp(double a,double b){
    return a>b;
}

int main(){
    int n,k;
    double aa[1005];
    double bb[200005];
    double cc[200005]={0};
    cin>>n>>k;
    aa[1]=1;
    for(int i=2;i<=1000;i++){
        if(i%2==0)
            aa[i]=i/2+0.5;
        else
            aa[i]=i/2+1;
    }
    int t;
    for(int i=1;i<=n;i++){
        scanf("%d",&t);
        bb[i]=aa[t];
    }
    for(int i=1;i<=k;i++){
        cc[1]+=bb[i];
    }
    for(int i=2;i<=n-k+1;i++){
        cc[i]=cc[i-1]-bb[i-1]+bb[i+k-1];
    }
    sort(cc+1,cc+1+n-k+1,cmp);
    printf("%lf",cc[1]);
    return 0;
}


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

nodes_flag = [False for _ in range(n)]
count = 0
for i in range(n):
    # print("{}:{}".format(i, nodes_flag))
    if nodes_flag[i] is not True:
        count += 1
        nodes_flag[i] = True
        nodes_list = nodes[i]
        while len(nodes_list):
            new_nodes_list =[]
            for node in nodes_list:
                if nodes_flag[node]:
                    continue
                nodes_flag[node] = True
                for next_node in nodes[node]:
                    new_nodes_list.append(next_node)
            nodes_list = new_nodes_list
print(count-1)


Measured memory_bytes: 26908
#include <stack>
#include <queue>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <set>
#include <tuple>
#include <cmath>
#include <random>
#include <algorithm>
#include <vector>
#include <iostream>
#include <fstream>
#include <chrono>
#include <numeric>

#define fio ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr)
#define rng mt19937_64 rnd(chrono::system_clock::now().time_since_epoch().count())

#define ri(...) i64 __VA_ARGS__; rx(__VA_ARGS__)
#define rc(...) char __VA_ARGS__; rx(__VA_ARGS__)
#define rs(...) string __VA_ARGS__; rx(__VA_ARGS__)
#define rvi(x, n) vi x(n); cin >> x
#define rvvi(x, n, m) vvi x(n, vi(m)); cin >> x

#ifndef ONLINE_JUDGE
#define dbg(...) cerr << '[' << #__VA_ARGS__ << "]: "; dbg_log(__VA_ARGS__)
#else
#define dbg(...) ;;
#endif

#define fa(i, v) for (auto &i : v)
#define fi(i, n) for (i32 i = 0; i < n; i++)
#define fp(i, n) for (i32 i = 1; i < n; i++)
#define fr(i, n) for (i32 i = n - 1; i >= 0; i--)
#define fu(i) ri(_i); fi(i, _i)

#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

using namespace std;

typedef uint32_t u32;
typedef int32_t i32;
typedef uint64_t u64;
typedef int64_t i64;
#ifdef __SIZEOF_INT128__
typedef __uint128_t u128;
typedef __int128_t i128;
#endif
typedef vector<i64> vi;
typedef vector<vi> vvi;

template<typename T>
inline istream &operator>>(istream &in, vector<T> &v) {
    fa(x, v) in >> x;
    return in;
}

template<typename T>
inline ostream &operator<<(ostream &out, const vector<T> &v) {
    fa(x, v) out << x << ' ';
    return out;
}

template<typename T>
inline void rx(T &x) {
    cin >> x;
}

template<typename T, typename... R>
inline void rx(T &x, R &... l) {
    cin >> x;
    rx(l...);
}

template<typename T>
inline void dbg_log(const T &x) {
    cerr << x << '\n';
}

template<typename T, typename... R>
inline void dbg_log(const T &x, const R &... l) {
    cerr << x << ", ";
    dbg_log(l...);
}

template<typename T>
inline void wl(const T &x) {
    cout << x << '\n';
}

template<typename T, typename... R>
inline void wl(const T &x, const R &... l) {
    cout << x << ' ';
    wl<R...>(l...);
}

int main() {
    fio;

    ri(n);
    vi a(n);
    const i32 N = 2e6;
    vector<bool> seen(N + 1, false);
    vector<bool> twice(N + 1, false);
    vector<bool> good(N + 1, true);
    fa(x, a) {
        rx(x);
        if (seen[x]) twice[x] = true;
        seen[x] = true;
    }
    sort(all(a));

    i32 res = 0;
    fi(i, n) {
        auto x = a[i];
        if (good[x]) {
            dbg(x);
            if (!twice[x]) res++;
            if (x * x < N) {
                for (i32 j = i + 1; j < n; j++) {
                    if (a[j] % x == 0) good[a[j]] = false;
                }
            } else {
                for (i32 y = 2 * x; y <= N; y += x) good[y] = false;
            }
        }
    }
    wl(res);

    return 0;
}


Measured memory_bytes: 5576
#include <stdio.h>

int p;
int b0;
int A[3000];
int primes[11];
int ps;

int root;
int iroot;
int dlog[3000];

int modpow(int x, int n){
  int r=1;
  for(;n;n>>=1){
    if(n&1) r = r * x % p;
    x = x * x % p;
  }
  return r;
}



int main(){
  int i, j, x, q;
  scanf("%d", &p);
  if(p == 2) root = 1;
  else {
    q = p-1;
    for(i=2;i*i<=q;i++){
      if(q % i == 0){
        primes[ps++] = i;
        do {q /= i;} while(q % i == 0);
      }
    }
    if(q != 1) primes[ps++] = q;
    for(i=2;i<30;i++){
      for(j=0;j<ps;j++){
        if(modpow(i, (p-1)/primes[j]) == 1) break;
      }
      if(j == ps){
        root = i;
        break;
      }
    }
  }
  x = 1;
  for(i=0;i<p-1;i++){
    dlog[x] = i;
    x = x * root % p;
  }
  iroot = modpow(root, p-2);
  scanf("%d", &b0);
  for(i=1;i<p;i++){
    int x;
    scanf("%d", &x);
    A[dlog[i]] = (x + p - b0) * modpow(i, p-2) % p;
  }

  printf("%d ", b0);
  for(i=0;i<p-1;i++){
    int r=0;
    for(j=0;j<p-1;j++){
      r = (r + modpow(iroot, i*j) * A[j]) % p;
    }
    r = r * modpow(p-1, p-2) % p;
    printf("%d ", r);
  }

  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;

int main(){
	int a[4][4]={},aa[4]={},b[4]={};
	FOR(i,1,4){
		FOR(j,1,4){
			cin>>a[i][j];
		}
	}

	if(a[1][1]-a[1][2]!=a[2][1]-a[2][2]||a[2][1]-a[2][2]!=a[3][1]-a[3][2]
		||a[1][3]-a[1][2]!=a[2][3]-a[2][2]||a[2][3]-a[2][2]!=a[3][3]-a[3][2]
		||a[1][1]-a[2][1]!=a[1][2]-a[2][2]||a[1][2]-a[2][2]!=a[1][3]-a[2][3]
		||a[3][1]-a[2][1]!=a[3][2]-a[2][2]||a[3][2]-a[2][2]!=a[3][3]-a[2][3])
		cout<<"No"<<endl;
	else cout<<"Yes"<<endl;

    return 0;
}


Measured memory_bytes: 256
seq=input()
list=[]
for i in range(4):
    list.append(int(seq[i]))
ans=[]
brk=0
for a in range (2):
    for b in range (2):
        for c in range (2):
            if list[0]+(2*a-1)*list[1]+(2*b-1)*list[2]+(2*c-1)*list[3]==7:
                ans.append(a)
                ans.append(b)
                ans.append(c)
                brk+=1
                break
        if brk!=0:
            break
    if brk!=0:
        break
A=""
B=""
C=""
if a==0:
    A="-"
else:
    A="+"
if b==0:
    B="-"
else:
    B="+"    
if c==0:
    C="-"
else:
    C="+"
print(str(list[0])+A+str(list[1])+B+str(list[2])+C+str(list[3])+"=7")

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

const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
//const int MOD = 1000000007;
 const int MOD = 998244353;

// Lib
const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];

void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
//

int main(){
#ifdef MYLOCAL
    ifstream in("input.txt");
    cin.rdbuf(in.rdbuf());
#endif
    ll N, A, B, K;
    COMinit();

    cin >> N >> A >> B >> K;
    ll ans = 0;
    for (ll a = 0; a <= N; ++a) { // A の個数を全探索
        ll rem = K - a * A;
        if (rem % B != 0){
            continue;
        }

        ll b = rem / B;
        if (b > N){
            continue;
        }

        ll tmp = COM(N, a) * COM(N, b) % MOD;
        ans += tmp;
        ans %= MOD;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 12160
#include <iostream>
#include <cmath>

using namespace std;

int main(int argc, char* argv[]) {
  int N, K;
  cin >> N >> K;

  int a[N];
  int pos1;
  for (int i = 0; i < N; ++i) {
    cin >> a[i];
    if (a[i] == 1)
      pos1 = i;
  }

  if (K == N) {
    cout << "1" << endl;
    return 0;
  }

  double left = pos1;
  double right = N - pos1 - 1;

  cout << ceil((double)(N - 1)/ (K - 1)) << endl;

  return 0;

}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define test() ull t;cin>>t;while(t--)
#define pb push_back
#define mkp make_pair
#define nl cout<<endl
#define MOD 1000000007
#define loop(i,start,end) for(int i=start;i<end;i++)
#define N 100001
#define oa(a,n) for(int i=0;i<n;i++)cout<<a[i]<<" ";nl;
#define ov(a) for(int i=0;i<a.size();i++)cout<<a[i]<<endl;
#define pi M_PI
int main()
{
	fastio();
	int n;cin>>n;
	vector<pair<ll,ll> > v(n);
	ll a,b;
	loop(i,0,n)
	{
		cin>>b>>a;
		v[i] = {a,b};
	}
	ll time = 0;
	bool flag=0;
	sort(v.begin(), v.end());
	loop(i,0,n)
	{
		time+=v[i].second;
		if(time>v[i].first)
		{
			flag=1;
			break;
		}
	}
	if(flag)
		cout<<"No";
	else
		cout<<"Yes";
	return 0;
}	

Measured memory_bytes: 3328
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;
const double INF = (1e15), EPS = (1e-10);

struct P{
  double X, Y, Z;
};

P operator+(P a, P b){ return (P){a.X+b.X, a.Y+b.Y, a.Z+b.Z};}
P operator*(P a, double c){ return (P){a.X*c, a.Y*c, a.Z*c};}
P operator*(double c, P a){ return a*c;}
P operator/(P a, double c){ return a*(1/c);}
P operator/(double c, P a){ return a*(1/c);}
P operator-(P a){ return -1*a;}
P operator-(P a, P b){ return a+(-b);}

double dot(P a, P b){ return a.X*b.X + a.Y*b.Y + a.Z*b.Z;}
double len(P a){ return sqrt(dot(a,a));}
P projection(P a, P b){ return b/len(b)*dot(a, b/len(b));}
P line_symmetry(P x, P a, P b){ return 2*a + 2*projection(x-a,b-a) - x;}

int main(){
  int N;
  while(cin >> N, N){
    double u, v, w;
    cin >> u >> v >> w;
    P d = {u, v, w};
    vector<P> V;
    vector<double> R(N);
    for(int i = 0; i < N; ++i){
      double x, y, z, r;
      cin >> x >> y >> z >> r;
      V.push_back((P){x,y,z});
      R[i] = r;
    }
    P p = {0,0,0};
    while(1){
      int id = -1;
      double l = INF;
      for(int i = 0; i < N; ++i){
        if(dot(d,V[i] - p) < EPS) continue;
        P proj = projection(V[i]-p,d);
        double r = R[i];
        if(dot(V[i]-p,V[i]-p) - dot(proj,proj) > r*r + EPS) continue;
        double l_ = len(proj) - sqrt(r*r-dot(V[i]-p,V[i]-p)+dot(proj,proj));
        if(l_ > EPS && l_ < l){
          l = l_;
          id = i;
        }
      }
      if(id < 0) break;
      P q = p + l/len(d)*d;
      d = line_symmetry(p,V[id],q) - q;
      p = q;
    }
    printf("%.12f %.12f %.12f\n",p.X,p.Y,p.Z);
  }
  return 0;
}



Measured memory_bytes: 3092
#include<stdio.h>
#include<map>
#include<set>
#include<vector>
using namespace std;
long long a[121212], L[2154], ln, ck[121212],P[121212], pn, cnt[121212];
map<long long, int>Q, l1, l2;
long long GT(long long x) {
	vector<long long>L; long long res = 1;
	for (int i = 0; i < pn&&P[i] <= x; i++) while (x%P[i] == 0)x /= P[i], L.push_back(P[i]);
	if (l1.find(x) != l1.end())L.push_back(x), x = 1;
	if (l2.find(x) != l2.end())L.push_back(l2[x]), L.push_back(l2[x]), x = 1;
	if (x > 1)return -1;
	for (int i = 0; i < L.size(); i++) {
		if (i + 1 < L.size() && L[i] == L[i + 1])res *= L[i], i++;
		else res *= L[i] * L[i];
		if (res > 1e10 || res < 0)return -1;
	}
	return res;
}
int main() {
	long long n, i, j, ans=0;
	for (i = 1; i*i*i <= 1e10; i++)L[ln++] = i*i*i;
	for (i = 2; i*i <= 1e5; i++) if (!ck[i]) {
		for (j = i*i; j <= 1e5; j += i)ck[j] = 1;
	}
	for (i = 2; i <= 1e5; i++)if (!ck[i]) {
		if(i<2154) P[pn++] = i;
		else l1[i] = l2[i*i] = i;
	}
	scanf("%lld", &n);
	for (i = 0; i < n; i++) {
		scanf("%lld", &a[i]);
		for (j = 1; j < ln; j++) {
			while (a[i] % L[j] == 0)a[i] /= L[j];
		}
		Q[a[i]] = Q[a[i]] + 1;
	}
	for (i = 0; i < n; i++) {
		if (Q.find(a[i]) == Q.end())continue;
		if (a[i] == 1) { ans++; Q.erase(1); continue; }
		long long gt = GT(a[i]);
		if(Q.find(gt)!=Q.end()) ans += max(Q[a[i]], Q[gt]), Q.erase(gt);
		else ans += Q[a[i]];
		Q.erase(a[i]);
	}
	printf("%lld", ans);
	return 0;
}

Measured memory_bytes: 10624
# https://atcoder.jp/contests/abc145/tasks/abc145_c
import math
import copy

N = int(input())
x_y_list = []

for n in range(N):
    x, y = map(int, input().split())
    x_y_list.append([x, y])


visited = [False] * N
d_list = []
log_list = []

def dfs(distance, ex_coord, log):

    if all(visited):
        d_list.append(distance)
        log_list.append(copy.copy(log))

        return

    for i in range(N):
        if visited[i]:
            continue
        else:
            tmp = 0
            if ex_coord != []:
                tmp = (ex_coord[0] - x_y_list[i][0]) ** 2 + (ex_coord[1] - x_y_list[i][1]) ** 2
                tmp = math.sqrt(tmp)
                distance += tmp

            visited[i] = True
            log.append(i + 1)
            dfs(distance, x_y_list[i], log)
            del log[-1]
            visited[i] = False
            distance -= tmp

log_tmp = []
dfs(0, [], log_tmp)
print(sum(d_list) / len(d_list))



Measured memory_bytes: 12020
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AtCoder
{
	class Program
	{
		static void Main(string[] args)
		{
			var x = int.Parse(Console.ReadLine());

			if(x < 1200)
			{
				Console.WriteLine("ABC");
			}
			else
			{
				Console.WriteLine("ARC");
			}
        }
	}
}


Measured memory_bytes: 13140
#include <stdio.h>

int main(){
    int a,b,c,d;
    
    scanf("%d %d %d %d",&a,&b,&c,&d);
    
    if((a+b)>(c+d)){
        printf("Left\n");
    }
    else if((a+b)<(c+d)){
        printf("Right\n");
    }
    else{
        printf("Balanced\n");
    }
    
    return 0;
}

Measured memory_bytes: 128
import Main.{calPattern, choiceAFromN}

object Main extends App {

  import scala.io.StdIn._
  import scala.math._
  implicit val choiceMemo = Array.tabulate(10){i ⇒ Array.tabulate(i + 1){_ ⇒ None: Option[List[List[Boolean]]]}}
  def choiceAFromN(a: Int, n: Int)(implicit memo: Array[Array[Option[List[List[Boolean]]]]]): List[List[Boolean]] = {
    memo(n)(a) match {
      case None if a == 0 ⇒ List(List.tabulate(n){_ ⇒ false}).also{it ⇒ memo(n)(a) = Some(it)}
      case None if a == n ⇒ List(List.tabulate(n){_ ⇒ true}).also{it ⇒ memo(n)(a) = Some(it)}
      case None ⇒ List(choiceAFromN(a - 1, n - 1)(memo).map{it ⇒ true::it}, choiceAFromN(a, n - 1)(memo).map{it ⇒ false::it}).flatten.also{it ⇒ memo(n)(a) = Some(it)}
      case Some(r) ⇒ r
    }
  }
  implicit val memo = Array.tabulate(390625){_ ⇒ None:Option[Long]}
  def solve: Unit ={
    val n = readLine.trim.toInt
    if (n == 0) return
    val m = readLine.trim.toInt
    implicit val scoreGraph = Array.tabulate(n){_ ⇒ Array.tabulate(n){_ ⇒ 0}}
    for (_ ← 0 until m){
      val Array(x, y) = readLine.trim.split(' ').map(_.toInt)
      scoreGraph(x - 1)(y - 1) = 1
      scoreGraph(y - 1)(x - 1) = -1
    }
    implicit val winCount = scoreGraph.map{it ⇒ it.count(_ == 1)}
    implicit val unknownIndices = scoreGraph.indices.map{i ⇒ (i + 1 until scoreGraph.length).filter{idx ⇒ scoreGraph(i)(idx) == 0}.toList}.toArray
    memo.indices.foreach(it ⇒ memo(it) = None)
    println(
      calPattern(scoreGraph.length)
    )
    solve
  }
  solve
  implicit class ExpandList(val value: Array[Int]){
    def toIndex(digit: Int): Int = value.tail.foldLeft(0){case (a, b) ⇒ a * digit + b}
  }
  def calPattern(length:Int , team: Int = 0)(implicit winCount: Array[Int], unknownIndices: Array[List[Int]], memo: Array[Option[Long]]): Long = {
    if (team == length) {
      1L
    }
    else if (winCount.forall(it ⇒ it <= length / 2)){
      memo(winCount.toIndex(length / 2 + 1)) match {
        case None ⇒ {
          val unknown = unknownIndices(team)
          val win = winCount(team)
          if (unknown.length + win < length / 2 || winCount.exists(it ⇒ it > length / 2)) {
            0L
          }
          else {
            var sum = 0L
            for (pattern ← choiceAFromN(length / 2 - win, unknown.length)) {
              unknown.zip(pattern).foreach{
                case (i, false) ⇒ winCount(i) += 1
                case (i, true) ⇒
              }
              sum += calPattern(length, team + 1)
              unknown.zip(pattern).foreach{
                case (i, false) ⇒ winCount(i) -= 1
                case _ ⇒
              }
            }
            memo(winCount.toIndex(length / 2 + 1)) = Some(sum)
            sum
          }
        }
        case Some(r) ⇒ r
      }
    }else 0L
  }

  implicit class Extenion[T](val value :T){
    def also(func: T ⇒ Unit): T = {
      func(value)
      value
    }
    def let[R](func: T ⇒ R): R = func(value)
  }
}
/*
https://onlinejudge.u-aizu.ac.jp/challenges/sources/JAG/Prelim/2884
 */



Measured memory_bytes: 177336
fun main(args: Array<String>) {
    abc092b()
}

fun abc092b() {
    val n = readLine()!!.toInt()
    val (d, x) = readLine()!!.split(" ").map { it.toInt() }
    val aList = (1..n).map { readLine()!!.toInt() }

    val answer = x + (0 until d).map { day ->
        aList.count { day % it == 0 }
    }.sum()

    println(answer)
}


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

int main()
{
	string s;
	int k;
	
	cin>>k;
	cin>>s;
	
	if(k>=s.size()) cout<<s;
	 else
	 {
	 	for(int i=0;i<k;i++) 
		 cout<<s[i];  
		 cout<<"...";
	 } 
	
	
	return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
 
using namespace std;
 
int n;
int l[2010];
 
int main() {
    cin >> n;
    for (int i = 0; i < n; i++) cin >> l[i];
    sort(l, l + n);
    int cnt = 0;
    for (int i = 0; i < n - 2; i++) {
        for (int j = i + 1; j < n - 1; j++) {
            for (int k = j + 1; k < n; k++) {
                if (l[k] < l[i] + l[j]) cnt++;
            }
        }
    }
    cout << cnt << '\n';
}

Measured memory_bytes: 256
MOD=10**9+7
def factorization(n):
    arr=[]
    tmp=n
    for i in range(2,int(n**0.5)+1):
        if(tmp%i==0):
            cnt=0
            while tmp%i==0:
                cnt+=1
                tmp//=i
            arr.append([i,cnt])
    if(tmp!=1):
        arr.append([tmp,1])
    return arr
def com(n,k,mod):
    res=1
    tmp=1
    for i in range(1,k+1):
        res=res*(n-i+1)%mod
        tmp=tmp*i%mod
    a=pow(tmp,mod-2,mod)
    return res*a%mod
N,M=map(int,input().split())
a=1
arr=factorization(M)
for x,y in arr:
    a=(a*com(y+N-1,N-1,MOD))%MOD
print(a)

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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;

int main()
{
    int p[50000 + 1];
    rep(i, 50000 + 1) p[i] = 1;
    p[0] = 0, p[1] = 0;
    for (int i = 2; i <= (int)sqrt(50000); i++)
    {
        if (p[i] == 1)
        {
            for (int j = 2; i * j <= 50000; j++)
            {
                p[i * j] = 0;
            }
        }
    }

    vector<int> p_num;
    rep(i, 50000 + 1)
    {
        if (p[i] == 1)
        {
            p_num.push_back(i);
        }
    }
    int s = p_num.size();
    int dp[50000 + 1] = {};

    rep(i, s)
    {
        for (int j = i; j < s; j++)
        {
            if (p_num[i] + p_num[j] <= 50000)
                dp[p_num[i] + p_num[j]]++;
        }
    }

    int n;
    while (cin >> n, n)
    {
        OP(dp[n]);
    }

    return 0;
}


Measured memory_bytes: 3612
#include <cstdio>
#include <vector>
using namespace std;

int nextInt() {
	int x;
	scanf("%d", &x);
	return x;
}

const int N = 400;
int col[N][8];
long long hashes[N][4];
long long dp[16];
int ways[4];

long long calcHash(int a, int b, int c, int d) {
	long long h = 0;
	h = 1000 * h + a;
	h = 1000 * h + b;
	h = 1000 * h + c;
	h = 1000 * h + d;
	return h;
}

int main() {
	int n = nextInt();
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 4; j++) {
			col[i][j] = nextInt();
			col[i][j + 4] = col[i][j];
		}
		for (int rot = 0; rot < 4; rot++) {
			for (int j = 0; j < 4; j++) {
				hashes[i][rot] = 1000 * hashes[i][rot] + col[i][(rot + j) % 4];
			}
		}
	}
	long long ans = 0;
	for (int front = 0; front < n; front++) {
		int a = col[front][0];
		int b = col[front][1];
		int c = col[front][2];
		int d = col[front][3];
		for (int back = front + 1; back < n; back++) {
			rotLoop:
			for (int rotBack = 0; rotBack < 4; rotBack++) {
				int f = col[back][(rotBack + 0)];
				int e = col[back][(rotBack + 1)];
				int h = col[back][(rotBack + 2)];
				int g = col[back][(rotBack + 3)];
				long long h1 = calcHash(a, e, f, b);
				long long h2 = calcHash(b, f, g, c);
				long long h3 = calcHash(d, c, g, h);
				long long h4 = calcHash(e, a, d, h);
				vector<long long> hs = {h1, h2, h3, h4};
				for (int i = 0; i < 16; i++) {
					dp[i] = 0;
				}
				dp[0] = 1;
				for (int i = front + 1; i < n; i++) {
					if (i == back) {
						continue;
					}
					for (int j = 0; j < 4; j++) {
						ways[j] = 0;
					}
					for (int bit = 0; bit < 4; bit++) {
						for (int rot = 0; rot < 4; rot++) {
							if (hashes[i][rot] == hs[bit]) {
								++ways[bit];
							}
						}
					}
					/*
						for (int mask = 15; mask >= 0; mask--) {
							if (dp[mask] == 0) {
								continue;
							}
							for (int bit = 0; bit < 4; bit++) {
								int nmask = mask | (1 << bit);
								if (nmask != mask) {
									dp[nmask] += dp[mask] * ways[bit];
								}
							}
						}
					*/
					dp[15] += dp[14] * ways[0];
					dp[15] += dp[13] * ways[1];
					dp[15] += dp[11] * ways[2];
					dp[15] += dp[7] * ways[3];
					dp[14] += dp[12] * ways[1];
					dp[14] += dp[10] * ways[2];
					dp[14] += dp[6] * ways[3];
					dp[13] += dp[12] * ways[0];
					dp[13] += dp[9] * ways[2];
					dp[13] += dp[5] * ways[3];
					dp[12] += dp[8] * ways[2];
					dp[12] += dp[4] * ways[3];
					dp[11] += dp[10] * ways[0];
					dp[11] += dp[9] * ways[1];
					dp[11] += dp[3] * ways[3];
					dp[10] += dp[8] * ways[1];
					dp[10] += dp[2] * ways[3];
					dp[9] += dp[8] * ways[0];
					dp[9] += dp[1] * ways[3];
					dp[8] += dp[0] * ways[3];
					dp[7] += dp[6] * ways[0];
					dp[7] += dp[5] * ways[1];
					dp[7] += dp[3] * ways[2];
					dp[6] += dp[4] * ways[1];
					dp[6] += dp[2] * ways[2];
					dp[5] += dp[4] * ways[0];
					dp[5] += dp[1] * ways[2];
					dp[4] += dp[0] * ways[2];
					dp[3] += dp[2] * ways[0];
					dp[3] += dp[1] * ways[1];
					dp[2] += dp[0] * ways[1];
					dp[1] += dp[0] * ways[0];					
				}
				ans += dp[15];
			}
		}
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <math.h>
#include<bitset>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)

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

    int ans = a*b;
    if(a>9 || b>9){
        ans = -1;
    }
    cout << ans << endl;
    return 0;
}

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

int main()
{
    int num, i;
    string s, t, st;
    cin >> num;
    cin >> s >> t;

    size_t sizes = s.length();

    for(i=0;i<sizes;i++){
        st += s[i];
        st += t[i];
    }

    cout << st << endl;

    return 0;
}

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

unordered_map<int, int> appear;
int N, un[3], unc, tp, zero;

int main() {

  cin >> N;
  for(int i = 0; i < N; i++){
    cin >> tp;
    if(tp == 0)zero=1;
    if(!appear.count(tp)){
      if(unc == 3){cout << "No\n"; exit(0);}
      un[unc] = tp;
      unc++;
      appear[tp] = 1;
    }else appear[tp]++;
  }
  if(zero){
    if(unc>2){cout << "No\n"; exit(0);}
    if(unc == 2){
      if(!un[0])swap(un[0], un[1]);
      if(appear[un[0]]==appear[un[1]]<<1){cout << "Yes\n";}
      else cout << "No\n";
    }else cout << "Yes\n";
  }else {
    if(appear[un[1]] == appear[un[0]] && appear[un[0]] == appear[un[2]] && (un[1] ^ un[2]) == un[0])cout << "Yes\n";
    else cout << "No\n";
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define INF 0x3f3f3f3f
#define MAX (1<<20)
#define MOD 1000000007
#define i64 long long
#define all(x) (x).begin() , (x).end()
#define sz(x) (int)(x).size()
#define ii pair<int, int>
#define fs first
#define sc second
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vi>
#define vii vector<ii>
#define vvii vector<vii>
#define lsb(x) ((x) & (-x))
#define gcd(x,y) __gcd((x),(y))

using namespace std;

int n, m;
int u, v, resp;
queue<int> fila;
vi vis, ans;
vvi adj;

int main(){_
    cin >> n >> m;
    adj = vvi(n+1);
    while (m--){
        cin >> u >> v;
        adj[u].eb(v);
        adj[v].eb(u);
    }
    vis = vi(n+1,0);
    ans = vi(n+1,-1);
    
    vis[1] = 1; fila.push(1);
    while (!fila.empty()){
        u = fila.front(); fila.pop();
        
        for (int v : adj[u]){
            if (!vis[v]){
                ans[v] = u;
                vis[v] = 1;
                fila.push(v);
            }
        }
    }
    resp = 1;
    for (int i=2; i<=n; ++i){
        resp &= (ans[i]!=-1);
    }
    if (!resp){
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
    for (int i=2; i<=n; ++i){
        cout << ans[i]  << endl;
    }
    return 0;
}

Measured memory_bytes: 10648
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<string>
#include<iomanip>
#include<cstdio>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define MOD 1000000007
#define MAXS(x,y) (x = max(x,y))
#define MINS(x,y) (x = min(x,y))

using namespace std;

typedef long long int ll;

const ll INF=(ll)1e18;


int N;

ll memo[3001][3001];
ll a[3001];

ll dp(int l , int r, int t){
  if(memo[l][r] != INF)return memo[l][r];

  if(l==r){
    if(t%2==0){
      return memo[l][r] = a[l];
    }else{
      return memo[l][r] = -a[l];
    }
  }

  if(t%2==0){
    return memo[l][r] = max(dp(l+1, r, t+1) + a[l], dp(l, r-1, t+1) + a[r]);
  }else{
    return memo[l][r] = min(dp(l+1, r, t+1) - a[l], dp(l, r-1, t+1) - a[r]);
  }
}

int main(){
  cin >> N;

  REP(i,N)cin >> a[i];
  REP(i,3000)REP(j,3000)memo[i][j]=INF;

  ll ans = dp(0,N-1,0);

  cout << ans << endl;
}

Measured memory_bytes: 70784
// SeeAlso: https://atcoder.jp/contests/abc152/tasks/abc152_b

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define MAX 100000
#define NIL -1
#define MOD 1000000007

typedef int _loop_int;
#define rep(i,n) for(int i = 0; i < n; i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define debug(x) cout<<#x<<": "<<x<<endl
#define debig_vec(v) cout<<#v<<":";rep(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

// 最大公約数
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
// 最小公倍数
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}

#define print2D(h, w, arr) rep(i, h) { rep(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> void print(const T& x){cout << setprecision(12) << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }

int main() {
    int a, b;
    cin >> a >> b;
    
    int mi = min(a, b);
    int ma = max(a, b);

    rep(i, ma) {
        cout << mi;
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define register
#define N 500005
#define M 1000005
using namespace std;
#define G if(++ip==ie)if(fread(ip=ibuf,1,L,stdin))
const int L=1<<19;
char ibuf[L],*ie=ibuf+L,*ip=ie-1;
inline char nc(void){G;return *ip;}
#define getchar nc
inline int read(void){
	char opt;int flag=1,res=0;
	while((opt=getchar())<'0')if(opt=='-')flag=-1;
	while(opt>='0'){res=(res<<3)+(res<<1)+opt-'0';opt=getchar();}
	return res*flag;
}
typedef long long ll; 
int n,m,a[N],sum[M],belong[N],ans,Ans[N];
struct Block{int l,r,pos;}b[N];
inline char cmp_block(Block a,Block b){return (belong[a.l]==belong[b.l])?(belong[a.l]&1)?a.r<b.r:a.r>b.r:belong[a.l]<belong[b.l];}
inline void Add(int x,int dlt){(~dlt)?ans+=(++sum[a[x]]==1):ans-=!(--sum[a[x]]);}
inline void Read(void){
	int i,sz;
	n=read(),m=read();sz=n/sqrt(m);for(i=1;i<=n;++i)a[i]=read();
	for(i=1;i<=n;++i)belong[i]=(i-1)/sz+1;
	for(i=1;i<=m;++i)b[i]={read(),read(),i};
	sort(b+1,b+m+1,cmp_block);
}
inline void Solve(void){
	int i,l,r; 
	for(i=1,l=1,r=0;i<=m;++i){
		while(r<b[i].r)Add(++r,1);
		while(r>b[i].r)Add(r--,-1);
		while(l<b[i].l)Add(l++,-1);
		while(l>b[i].l)Add(--l,1);
		Ans[b[i].pos]=ans;
	}
	for(i=1;i<=m;++i)printf("%d\n",Ans[i]);
}
int main(void){
	Read();Solve();
	return 0;
}

Measured memory_bytes: 17944
// Template
#include <bits/stdc++.h>
#define rep_override(x, y, z, name, ...) name
#define rep2(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep3(i, l, r) for (int i = (int)(l); i < (int)(r); ++i)
#define rep(...) rep_override(__VA_ARGS__, rep3, rep2)(__VA_ARGS__)
#define per(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
constexpr int inf = 1001001001;
constexpr ll INF = 3003003003003003003;
template <typename T> inline bool chmin(T& x, const T& y) {if (x > y) {x = y; return 1;} return 0;}
template <typename T> inline bool chmax(T& x, const T& y) {if (x < y) {x = y; return 1;} return 0;}
struct IOSET {IOSET() {cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10);}} ioset;

// Mod-Int
constexpr int MOD = 1000000007;
struct ModInt {
    ll val;
    ModInt() = default;
    ModInt(ll x) : val(x % MOD + (x < 0 ? MOD : 0)) {}
    ModInt &operator+= (const ModInt &x) {if ((val += x.val) >= MOD) val -= MOD; return *this;}
    ModInt &operator-= (const ModInt &x) {if ((val -= x.val) < 0) val += MOD; return *this;}
    ModInt &operator*= (const ModInt &x) {(val *= x.val) %= MOD; return *this;}
    ModInt operator+ (const ModInt &x) const {return ModInt(*this) += x;}
    ModInt operator- (const ModInt &x) const {return ModInt(*this) -= x;}
    ModInt operator* (const ModInt &x) const {return ModInt(*this) *= x;}
    ModInt pow(ll t) const {
        if (!t) return ModInt(1);
        ModInt m = pow(t / 2);
        m *= m;
        if (t & 1) m *= *this;
        return m;
    }
    ModInt inv() const {return pow(MOD - 2);}
    ModInt &operator/= (const ModInt &x) {return *this *= x.inv();}
    ModInt operator/ (const ModInt &x) const {return ModInt(*this) /= x;}
    friend istream &operator>> (istream &is, ModInt &x) {is >> x.val; return is;}
    friend ostream &operator<< (ostream &os, const ModInt &x) {os << x.val; return os;}
};

// Main
int main() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    
    vector<ModInt> dp(k + 1, ModInt(0));
    dp[0] = ModInt(1);
    rep(i, n) {
        vector<ModInt> sum(k + 2, ModInt(0));
        rep(j, k + 1) sum[j + 1] = sum[j] + dp[j];
        rep(j, k + 1) {
            dp[j] = sum[j + 1] - sum[max(j - a[i], 0)];
        }
    }
    
    cout << dp[k] << "\n";
}


Measured memory_bytes: 4792
#include <iostream>
#include <stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
#define ll long long
int main()
{
    int n,k,s,t=0;
    scanf("%d%d%d",&n,&k,&s);
        while(t<k)
        {
            if(t!=0)
                printf(" %d",s);
            else
                printf("%d",s);
            t++;
        }
        for(int i=k; i<n; i++)
        {
            if(k==0)
            {
                if(s-1e9==0)
                    printf("%d",s-1);
                else
                    printf("%d",s+1);
                k=k+1;
            }
            else
            {
                if(s-1e9==0)
                    printf(" %d",s-1);
                else
                    printf(" %d",s+1);
            }

        }
        printf("\n");
    return 0;
}

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

int main(){
    int n; cin >> n;
    string s,t; cin >> s >> t;
    for(int i = 0; i < n; i++){
        bool f = true;
        for(int j = 0; i+j < n; j++){
            if(s[i+j] == t[j] ) continue;
            else {f = false; break;}
        }
        if(f){
            cout << n+i << endl; return 0;
        }
    }
    cout << 2*n << endl;
    return 0;
}

Measured memory_bytes: 256
fn main(){
    let mut input = "".to_string();
    std::io::stdin().read_line(&mut input).ok();
    let splitted = input.trim().split_whitespace().map(|c| {let i:usize = c.parse().unwrap(); i} ).collect::<Vec<usize>>();
    let count7 = splitted.iter().fold(0, |mut acc, x| {
     if *x == 7usize { acc += 1; }   
     acc });
    let count5 = splitted.iter().fold(0, |mut acc, x| {
     if *x == 5usize { acc += 1; }   
     acc });
    if count7 == 1 && count5 == 2 {
        println!("{}", "YES");
    } else {
        println!("{}", "NO");
    }
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
using ll = long long;
typedef long long lint;

int main() {
  int N;
  cin >> N;
  string s;
  cin >> s;
  int count = 0;
  for(int i = 0;i<N-1;i++){
    if(s.substr(i,3) == "ABC") count++;
  }
  cout << count << endl;
}

Measured memory_bytes: 256