akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (long long  i=a;i<n;i++)
#define sz(A) (int)(A.size())
#define all(x) (x).begin(),(x).end()
#define get(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
typedef long long ll;
typedef pair<int, int> PII;
typedef vector<int> VI;

void solve() {
	int n;
	cin >> n;
	VI a(n);
	int res = 0;
	rep(i, 0, n)cin >> a[i];
	rep(i, 0, n) {
		rep(j, i + 1, n) {
			rep(k, j + 1, n) {
				VI ans;
				if (a[i] != a[j] && a[i] != a[k] && a[j] != a[k]) {
					ans.push_back(a[i]);
					ans.push_back(a[j]);
					ans.push_back(a[k]);
					sort(all(ans));
					if (ans[0] + ans[1] > ans[2]) {
						res++;
					}
				}
			}
		}
	}
	cout << res;
}
int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int T_ = 1;
	//cin >> T_;
	for (int i = 0; i < T_; i++)solve();
	return 0;
}



Measured memory_bytes: 3660
package main
import "fmt"
func main() {
  var s string
  fmt.Scan(&s)
  var n int = len(s)
  if (n%2 == 0) != (s[0:1] == s[n-1:n]) {
    fmt.Println("Second")
  } else {
    fmt.Println("First")
  }
}

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

#define loop(i,n) for(int i = 0;i < int(n);i++)
#define rloop(i,n) for(int i = int(n);i >= 0;i--)
#define range(i,a,b) for(int i = int(a);i <= int(b);i++)
#define SZ(c) int(c.size())
#define ALL(c) c.begin(), c.end()
#define RALL(c) c.rbegin(), c.rend()
#define PI acos(-1)
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define sfi1(v) scanf("%d",&v)
#define sfi2(v1,v2) scanf("%d %d",&v1,&v2)
#define sfi3(v1,v2,v3) scanf("%d %d %d",&v1,&v2,&v3)
#define sfll1(v) scanf("%I64d",&v);
#define sfll2(v1,v2) scanf("%I64d %I64d",&v1,&v2)
#define sfll3(v1,v2,v3) scanf("%I64d %I64d %I64d",&v1,&v2,&v3)
#define endl '\n'

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

const int N=2e5+5;
int a[N];

int main()
{

#ifndef ONLINE_JUDGE
	//freopen("in.in", "r", stdin);
	//freopen("out.in", "w", stdout);
#endif
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int n,k;
	cin>>n>>k;
	for(int i=0;i<n;i++)
        cin>>a[i];
    int ans=1e9+5;
    for(int i=0;i+k-1<n;i++)
    {
        int A=a[i],B=a[i+k-1];
        if(B<0)
            ans=min(ans,abs(A));
        else if(A>0)
            ans=min(ans,B);
        else ans=min(ans,min(B-2*A,2*B-A));
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long 

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
	int N; cin >> N;
	int A[N];
	rep(i, N) cin >> A[i];
	int sum[N + 1] = {};
	rep(i, N) {
		sum[i + 1] = sum[i] + A[i];
	}
	int ans = INF;
	int L = 1, R = 3;
	for (int mid = 2; mid <= N - 2; mid++) {

		while (L + 1 < mid && abs(2 * sum[L] - sum[mid])
			>= abs(2 * sum[L + 1] - sum[mid])) L++;
		while (R + 1 < N && abs(2 * sum[R] - sum[mid] - sum[N])
			>= abs(2 * sum[R + 1] - sum[mid] - sum[N])) R++;
		int B[4];
		B[0] = sum[L];
		B[1] = sum[mid] - sum[L];
		B[2] = sum[R] - sum[mid];
		B[3] = sum[N] - sum[R];
		//rep(i, 4) cout << B[i] << " ";
		//cout << "  " << B[0] + B[1] + B[2] + B[3] << " " << sum[N] << endl;
		sort(B, B + 4);
		ans = min(ans, B[3] - B[0]);
	}
	cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3328
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string>
#include <vector>
#include <queue>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

int main() {
    int M, D;
    cin >> M >> D;

    int count = 0;
    for(int m=1; m<=M; m++) {
        for(int d=1; d<=D; d++) {
            int d1 = (d%10);
            int d10 = (d/10);
            if(d1 >= 2 && d10 >= 2 && d1*d10==m)
                count++;
        }
    }

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip> // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple> // get<n>(xxx)
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set> // S.insert(M);
// if (S.find(key) != S.end()) { }
// for (auto it=S.begin(); it != S.end(); it++) { }
// auto it = S.lower_bound(M);
#include <random> // random_device rd; mt19937 mt(rd());
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib> // atoi(xxx)
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.
// insert #if<tab> by my emacs. #if DEBUG == 1 ... #end

typedef long long ll;

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

// const int C = 1e6+10;
// const ll M = 1000000007;

int main () {
  int N, K;
  cin >> N >> K;
  int l[51];
  for (auto i = 0; i < N; ++i) {
    cin >> l[i];
  }
  sort(l, l+N);
  reverse(l, l+N);
  int ans = 0;
  for (auto i = 0; i < K; ++i) {
    ans += l[i];
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
from heapq import heappop, heappush

X, Y, Z, K = map(int, input().split())
*A, = map(int, input().split())
*B, = map(int, input().split())
*C, = map(int, input().split())
A.sort(reverse=True)

# Bi+Cjの和を求め、降順にソートしておく(Dkとします)
D = [i+j for j in C for i in B]
D.sort(reverse=True)

# Ai+Bj+Ckの大きい順からK個を構成する要素としては、Aiの大きい順からK個とDkの大きい順からK個しか登場しないので
q = []
for i in A[:K]:
    for j in D[:K]:
        heappush(q, -(i+j))

for _ in range(K):
    print(-heappop(q))

Measured memory_bytes: 154692
from collections import deque

def dfs(maze, cnt, x, y):
    global H, W, count, can
    if x == H-1 and y == W-1:
        if cnt == count:
            can = "Possible"
    for dx, dy in ([1, 0], [0, 1]):
        new_x , new_y = x + dx, y + dy
        if new_x < 0 or new_x >= H or new_y < 0 or new_y >= W:
            continue
        elif maze[new_x][new_y] == '#':
            cnt += 1
            dfs(maze, cnt, new_x, new_y)
            cnt -= 1

if __name__ == "__main__":
    H, W = map(int, input().split())
    maze = []
    for _ in range(H):
        a = [c for c in input()]
        maze.append(a)
    count = 0
    for h in range(H):
        for w in range(W):
            if maze[h][w] == '#':
                count += 1
    cnt = 1 
    can = "Impossible"
    dfs(maze, cnt, 0, 0)
    print(can)


Measured memory_bytes: 3564
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
#define rep(i,n) for (int i=0; i<n;++i)
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;
float N, D;

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

  cin >> N >> D;
  int a = ceil(N / (2*D+1));

  cout << a << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main{
	public static void main(String args[]){
		int H, W;
		Scanner scan = new Scanner(System.in);

		while(true){
			H = scan.nextInt();
			W = scan.nextInt();
			
			if(H == 0 && W == 0){break;}

			for(int i=0; i<H; i++){
				for(int k=0; k<W; k++){
					System.out.print("#");
				}
				System.out.println("");
			}
			System.out.println("");
		}
	}
}

Measured memory_bytes: 33532
#include <bits/stdc++.h>
using namespace std;
int main(void)
{
    int A,B;
    cin >> A >> B;

    if (((A<0)&&(B==0))){
        cout << A*B <<endl;

    }else if ((A==0)&&(B<0)){
        cout << A-B << endl;
    }
    else if ((A==0)&&(B>0)||(A>0)&&(B==0)){
        cout << A+B <<endl;
    }else if ((A==1)||(B==1)){
        cout <<A+B <<endl;
}else if ((A<0)&&(B>0)){
    cout << A+B <<endl;
}
    else if ((A>0)&&(B<0)){
        cout <<A-B<<endl;
    }else if ((A<0)&&(B<0)){
        cout <<A*B<<endl;
    }else {
        cout <<A*B<<endl;
    }
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define each(it,v) for(auto &it : v)
#define mod 1000000007
#define All(v) (v).begin(),(v).end()
#define vi vector<int>
#define vl vector<long>
#define P pair<int,int>
#define Graph vector<vector<int>>
using namespace std;

main()
{
        double l; cin>>l;
        double x=l/3;

        printf("%.6lf\n",x*x*x);
}

Measured memory_bytes: 384
#include <iostream>
using namespace std;
int main() {
  int h , w ;
  while(1){
      cin >> h >> w;
      if ( h == 0 && w == 0) break;

      for (int i = 0 ; i < h ; i++){
          for (int j = 0; j < w; j++){
              cout <<'#';
          }
          cout << '\n';
      }
      cout << endl;
  }
  return 0;
}


Measured memory_bytes: 3108
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Linq.Enumerable;
using static System.Math;

class Program
{
    static void Main()
    {
        var (N, M) = ReadLine().Split(' ').Select(int.Parse).ToArray();
        var p = ReadLine().Split(' ').Select(int.Parse).ToArray();
        var xy = Range(0, M).Select(i => ReadLine().Split(' ').Select(int.Parse).ToArray());

        var uf = new UnionFind(N);
        foreach (var (x, y) in xy)
            uf.Unite(x - 1, y - 1);

        var ans = Range(0, N).Count(i => uf.Same(i, p[i] - 1));

        WriteLine(ans);
    }
}

class UnionFind
{
    private int[] d;
    public UnionFind(int n) => d = Enumerable.Repeat(-1, n).ToArray();
    public int Find(int x) => (d[x] < 0) ? x : d[x] = Find(d[x]);
    public bool Unite(int x, int y)
    {
        (x, y) = (Find(x), Find(y));
        if (x == y)
            return false;
        if (-d[x] < -d[y])
            (x, y) = (y, x);
        (d[x], d[y]) = (d[x] + d[y], x);
        return true;
    }
    public bool Same(int x, int y) => Find(x) == Find(y);
    public int Size(int x) => -d[Find(x)];
}

static class ArrayDeconstructExtensions
{
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2) => (i1, i2) = (a[0], a[1]);
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2, out T i3) => (i1, i2, i3) = (a[0], a[1], a[2]);
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2, out T i3, out T i4) => (i1, i2, i3, i4) = (a[0], a[1], a[2], a[3]);
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2, out T i3, out T i4, out T i5) => (i1, i2, i3, i4, i5) = (a[0], a[1], a[2], a[3], a[4]);
}


Measured memory_bytes: 50592
using System;
using static System.Console;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace atcoder
{
    class Program
    {
        //メイン関数
        static void Main(string[] args)
        {
            string[] reader = ReadLine().Split(' ');
            int k, s;
            k = int.Parse(reader[0]);
            s = int.Parse(reader[1]);

            int patterns = 0;

            for (int x = 0; x <= k; x++)
            {
                for (int y = 0; y <= k; y++)
                {
                    int z = s - (x + y);
                    if (z <= k && z >= 0) patterns++; 
                }
            }
            Write(patterns);
        }
    }
}


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

typedef struct node {
  int degree; /* 子の数 */
  int depth; /* 深さ */
  int height; /* 高さ */
  int parent; /* 親の値 */
  int sibling; /* 兄弟 */
  int left; /* 左側の子ノード */
  int right; /* 右側の子ノード */
} Node;

int cal_depth(Node *,int);
int cal_height(Node *,int);

Node T[30];

int main()
{
  int i,n,value = -1;
  scanf("%d",&n);

  /* 初期化 */
  for(i = 0;i < n;i++){
    T[i].depth = 0;
    T[i].height = 0;
    T[i].parent = -1;
    T[i].sibling = -1;
    T[i].left = -1;
    T[i].right = -1;
  }

  for(i = 0;i < n;i++){   
    scanf("%d",&value);
    scanf("%d",&T[value].left);
    scanf("%d",&T[value].right);
    if(T[value].left != -1){
      T[value].degree ++;
      T[T[value].left].sibling = T[value].right;   /* 存在したら、兄弟を入力する */
    }
    if(T[value].right != -1){
      T[value].degree ++;
      T[T[value].right].sibling = T[value].left;  /* 存在したら、兄弟を入力する */
    }
    T[T[value].left].parent = value;   /* 親を入力 */
    T[T[value].right].parent = value;
  }
  
  for(i = 0;i < n;i++){   /* ツリーを作ってから、高さと深さの計算をする */
    T[i].depth = cal_depth(T,i);
    T[i].height = cal_height(T,i);
  }
  

  /* 出力 */
  for(i = 0;i < n;i++){
    printf("node %d: parent = %d, sibling = %d, ",i,T[i].parent,T[i].sibling);     
    printf("degree = %d, depth = %d, height = %d, ",T[i].degree,T[i].depth,T[i].height);
    if(T[i].parent == -1) printf("root\n");
    else if((T[i].left == -1) && (T[i].right == -1)) printf("leaf\n");
    else printf("internal node\n");
  }

  return 0;
}

    
int cal_depth(Node *T,int now) /* 深さの計算 */
{ 
  if(T[now].parent != -1) return cal_depth(T,T[now].parent) + 1;
  return 0;
}

int cal_height(Node *T,int now) /* 高さの計算 */
{
  int sum_right = 0,sum_left = 0;

  if(T[now].left != -1) sum_left = cal_height(T,T[now].left) +1;
  if(T[now].right != -1) sum_right = cal_height(T,T[now].right) +1;

  if(sum_right >= sum_left) return sum_right;  /* 左と右の両方のパターンを計算し、大きいほうを返す */
  else return sum_left;
}

Measured memory_bytes: 612
// #include <bits/stdc++.h>
#include <algorithm>
#include <iostream> //入出力
#include <stdio.h>
#include <map>
#include <set>
#include <string>
#include <math.h> //算術演算子
#include <vector>
#include <cstdlib>
#include <queue>
#include <stack>
#include <list>
#include <iomanip> //小数点以下を表示させる(setprecision())
using namespace std;

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

    int N;
    string S, M = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    string ans = "";

    cin >>
        N >> S;

    for (int i = 0; i < S.size(); i++)
    {
        for (int j = 0; j < 26; j++)
        {
            if (S[i] == M[j])
            {
                if (j + N >= 26)
                {
                    ans += M[j + N - 26];
                    break;
                }
                else
                {
                    ans += M[j + N];
                    break;
                }
            }
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
#a = [input() for _ in range(n)]

n,y=map(int, input().split())

for a in range(n+1):
    for b in range(n+1):
        c = max(n - (a+b), 0)
        if (a+b+c == n):
            if (10000*a+5000*b+1000*c == y):
                print(a,b,c)
                exit()
print(-1,-1,-1)



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


using namespace std;
                                                                    

int main(){
  int n,h,w;
  cin >> n >> h >> w;
  int across = n-w + 1;
  int down = n-h + 1;
  cout << across * down<< endl;
	cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";

}

           	

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define nl                 "\n"
#define ll                 long long
#define pb                 push_back
#define pf                 push_front
#define np                 next_permutation
#define pp                 prev_permutation
#define sz(x)              x.size()
#define sqr(x)             ((x)*(x))
#define pi                 acos(-1)
#define setprecision(x)    fixed<<setprecision((int)(x))
#define mem1(x)            memset(x,0,sizeof(x))
#define mem2(x)            memset(x,-1,sizeof(x))
#define all(x)             (x).begin(),(x).end()
#define rev(x)             reverse(all(x))
#define iota(x,a)          iota(all(x),a)
#define sorta(x)           sort(all(x))
#define sortd(x)           sort(all(x),greater<int>())
#define csort(x,c)         sort(all(x),c)
#define rsort(x)           sort(x.rbegin(),x.rend())
#define faster_io          ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define count_time         cerr<<nl<<"Time elapsed : "<<clock()*1000.0/CLOCKS_PER_SEC<<"ms"<<nl;
#define all_ele(x)         for(auto i:(x)){cout<<i<<' ';}cout<<nl;
#define multiple_test      int t; cin>>t; while(t--){solve();}
#define multiple_test2     int t;cin>>t;for(int i=1; i<=t; i++){cout<<"Case #"<<i<<": "<<test()<<nl;}
#define single_test        solve();
using namespace std;
//vector<vector<int>>p(sz,vector<int>(sz,val));
/*
ll test()
{
    return value;
}
*/
void solve()
{
    int n;
    cin>>n;
    if(400<=n && n<=599)
        cout<<8<<nl;
    else if(600<=n && n<=799)
        cout<<7<<nl;
    else if(800<=n && n<=999)
        cout<<6<<nl;
    else if(1000<=n && n<=1199)
        cout<<5<<nl;
    else if(1200<=n && n<=1399)
        cout<<4<<nl;
    else if(1400<=n && n<=1599)
        cout<<3<<nl;
    else if(1600<=n && n<=1799)
        cout<<2<<nl;
    else
        cout<<1<<nl;
}
int main()
{
    faster_io //multiple_test2
    //multiple_test
    single_test
    //count_time
    return 0;
}




Measured memory_bytes: 3648
#include<iostream>
#include<bits/stdc++.h>
#include<iomanip>
#include<math.h>
#include<vector>
#include<cctype>
#include<string>
#include<set>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
std::string line;
typedef long long ll;

int main(){
   int a,b,c,ans;
   cin >> a >> b;

   bool flg = 0;
   for(int i=0;i<=3;i++){

      ans = a*b*i;
      if(ans %2 != 0) flg =1;
   }

   cout << (flg? "Yes":"No") << endl;




   return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i < (n + 1); ++i)
using namespace std;
using ll = long long;
const int INF = +100100100;
// typedef pair<int,int> P;
const int MAX = 1000000;

int main(){
    int r;
    cin >> r;
    cout << r*2* M_PI << endl;
    return 0;
}

Measured memory_bytes: 3780
#include <bits/stdc++.h>
#define mem(a,v) memset(a,v,sizeof a)
#define ll long long
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define max3(x,y,z) max(x,max(y,z))
#define min3(x,y,z) min(x,min(y,z))
#define f first
#define s second
#define fr(i,n) for(int j=i;j<n;j++)
#define rev(a) reverse(a.begin(),a.end())
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define lb(a,v) lower_bound(all(a),v)
#define ub(a,v) upper_bound(all(a),v)
#define ins(v) insert(v)
#define pb(v) push_back(v)
#define sz(x) (int)(x).size()
#define MOD 1000000007
#define sf1(a) scanf("%d",&a)
#define sf2(a,b) scanf("%d %d",&a,&b)
#define sf3(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define sf4(a,b,c,d) scanf("%d %d %d %d",&a,&b,&c,&d)
using namespace std;

int main() {
	int n,x,mx=0;
	sf1(n);
	map<int ,int>mp;
	for(int i=0;i<n;i++)
	{
		sf1(x);
		mp[x]++;
	}
	int s=0;
	for(auto y:mp)
		if(y.f>y.s)
			s+=y.s;	
		else if(y.f<y.s)
			s+=(y.s-y.f);
	printf("%d\n",s);
	return 0;
}

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

#define rp(i, k, n) for (int i = k; i < n; i++)
typedef long long ll;
typedef double ld;

ll mod = 1e9 + 7ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF = 1ll << 60;
const int MAX_V = 500009;

typedef pair<int, ll> P;
vector<P> d(MAX_V);  // 結果格納　intは親　到達不可能なら-1, inf
vector< vector <P> > graph(MAX_V);

void dijkstra(int s) {
    priority_queue< P, vector<P>, greater<P> > que;
    for(int i = 0; i < d.size(); ++i) {
        d.at(i) = P(-1, INF);
    }
    que.push(make_pair(s, 0ll));
    d.at(s) = P(s, 0);
    while(!que.empty()) {
        P p = que.top(); que.pop();
        int v = p.first;
        if(p.second > d.at(v).second) continue;
        for(int i = 0; i < graph.at(v).size(); ++i) {
            P edge = graph.at(v).at(i);
            if(d.at(edge.first).second > d.at(v).second + edge.second) {
                d.at(edge.first).second = d.at(v).second + edge.second;
                d.at(edge.first).first = v;
                que.push(make_pair(edge.first, d.at(edge.first).second));
            }
        }
    }
}

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

    rp(i, 0, m) {
        int u, v;
        scanf("%d%d", &u, &v);
        graph.at(u).push_back(P(v+n, 1ll));
        graph.at(u+n).push_back(P(v+2*n, 1ll));
        graph.at(u+2*n).push_back(P(v, 1ll));
    }
    int s, t;
    scanf("%d%d", &s, &t);
    dijkstra(s);
    if(d.at(t).first == -1) printf("-1\n");
    else printf("%d\n", int(d.at(t).second) / 3);
    return 0;

}








Measured memory_bytes: 32460
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;

int main()
{
	LL N;
	in >> N;
	std::vector<LL>b(N);
	rep(i, N) in >> b[i];

	std::vector<LL>ans;
	while (!b.empty())
	{
		bool flag = false;
		for (LL i = b.size() - 1; i >= 0; --i)
		{
			if (b[i] == i + 1)
			{
				ans.push_back(b[i]);
				b.erase(b.begin() + i);
				flag = true;
				break;
			}
		}
		if (!flag)
		{
			out << -1 << std::endl;
			return 0;
		}
	}

	std::reverse(ans.begin(), ans.end());
	rep(i, N) out << ans[i] << std::endl;
}


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

int main() {
  long N, K;
  cin >> N >> K;
  
  long rem = N % K;
  long rem2;
  if (rem - K < 0) {
    rem2 = K - rem;
  }
  else {
    rem2 = rem - K;
  }
  
  if (rem <= rem2) {
    cout << rem << endl;
  }
  else {
    cout << rem2 << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
using namespace std;
 
ll gcd(ll a,ll b){return (b==0) ? a:gcd(b,a%b);}

ll A,B;
int main(void){
    cin >> A >> B;
    cout << A*B/gcd(A,B) << endl;
}


Measured memory_bytes: 256
/* BISMILLAHIR RAHMANIR RAHIM */
#include<bits/stdc++.h>
using namespace std;
#define ll        long long
#define ull       unsigned long long
#define si(x)     scanf("%d", &x)
#define sll(x)    scanf("%lld", &x)
#define sd(x)     scanf("%lf", &x)
#define l0(i,n)   for(ll i=0; i<n; i++)
#define MAX       100000
#define maxn 	  200002
#define pb 		  push_back
#define mk 		  make_pair
#define endl	  "\n"
#define INF 	  1000000000
#define MOD		  1000000007
#define vi(a)	  vector<int>a

int main ()
{
		ios::sync_with_stdio(0);
		cin.tie(0);
		//CODE TONOY
		ll n;
		sll(n);
		string s;
		while(n--)
		{
			s+='a'+n%26;
			n/=26;
		}
		reverse(s.begin(),s.end());
		cout << s << endl;
		return 0;
}


Measured memory_bytes: 3612
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#define speed ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define eps 1e-8
#define inf INT_MAX
#define mod 1000000007
using namespace std;

int main() {
	speed;
	int n, m, a, b, v;
	cin >> n >> m;
	multiset<int>s;
	for (int i = 0; i < n; ++i){
		cin >> v;
		s.insert(v);
	}
	vector<pair<int,int>>mv(m);
	for (int i = 0; i < m; ++i)
		cin >> mv[i].second >> mv[i].first;
	sort(mv.rbegin(),mv.rend());
	for (int i = 0; i < m; ++i){
		a = mv[i].second, b = mv[i].first;
		auto e = s.lower_bound(b);
		for (auto i = s.begin(); i != e && a; --a){
			if (*i == b)
				break;
			s.insert(b);
			auto nit = i;
			++nit;
			s.erase(i);
			i = nit;
		}
	}
	ll ans = 0;
	for (auto i : s)
		ans += i;
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 5760
#include<stdio.h>
#define MAX 100005
#define NIL -1
  
struct Node{ int p, l, r;};
struct Node T[MAX];
int n, H, D[MAX];
  
int getDepth(int u){
  int d = 0;
  
  while(T[u].p >= 0){
    u = T[u].p; 
    d++;
  }
  
  return d;
}
  
void print(int u){
  if(T[u].p == NIL)
    printf("node %d: parent = %d, depth = %d, root, ",u,T[u].p,D[u]);
    
  else if(T[u].l == NIL)
    printf("node %d: parent = %d, depth = %d, leaf, ",u,T[u].p,D[u]);
    
    
  else printf("node %d: parent = %d, depth = %d, internal node, ",u,T[u].p,D[u]);
    
    
  printf("[");
  int t; 
  t = u;
  if(T[t].l  != NIL){
    printf("%d",T[t].l);
    if(T[T[t].l].r == NIL)
      printf("]\n");
    else printf(",");
    t =T[t].l;
    while(T[t].r != NIL){
      printf(" %d",T[t].r);
  
      if(T[T[t].r].r == NIL)
    printf("]\n");
      else printf(",");
      t =T[t].r;
    }
  }
  else  printf("]\n");
}
  
main(){
  int i, j, d, v, c,l,r;
    
  scanf("%d",&n);
    
  for ( i = 0; i < n; i++ ) {
    T[i].p = T[i].l = T[i].r = NIL;
  }
    
   for ( i = 0; i < n; i++ ){
    scanf("%d %d", &v, &d);
    for ( j = 0; j < d; j++ ){
      scanf("%d", &c);
      //make tree
      T[c].p = v;
        
      if(j == 0) T[v].l = c;
        
      else if (j >= 1)
    T[r].r = c;
      r = c;
      }
    }
    
  
  for ( i = 0; i < n; i++ ){
    D[i] = getDepth(i);
  }
  
  for ( i = 0; i < n; i++ ) print(i);
  return 0;
}

Measured memory_bytes: 2176
while True:
    H, W = map(int, input().split())
    if H != 0:
        for i in range(H):
            s = ""
            for j in range(W):
                if i%2==0 and j%2==0:
                    s += "#"
                elif i%2==0 and j%2==1:
                    s+= "."
                elif i%2==1 and j%2==0:
                    s += "."
                elif i%2==1 and j%2==1:
                    s += "#"
            print(s)
        print("")
    else:
        break



Measured memory_bytes: 5616
n = int(input())
s = list(int(input()) for i in range(n))

s.sort()

ans = sum(s)

if ans % 10 != 0:
    print(ans)
    exit()
else:
    for x in s:
        if x % 10 != 0:
            ans -= x
            print(ans)
            exit()
print(0)

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

int main() {
  int N; cin>>N;
  vector<int64_t> A(N);
  vector<int64_t> B(N);
  vector<pair<int64_t,int64_t>> dif;
  vector<int64_t> same;
  rep(i,N) cin>>A.at(i)>>B.at(i);
  if(N==1||N==2) cout<<1;
  else{
  for(int i=0;i<N-1;i++){
    for(int j=i+1;j<N;j++){
      int64_t a=A.at(i),b=A.at(j),c=B.at(i),d=B.at(j);
      dif.push_back(make_pair(a-b,c-d));
    }
  }
  int T=dif.size(), count=0;
  for(int i=0;i<T-1;i++){
    count=0;
    for(int j=i+1;j<T;j++){
      int64_t a=dif.at(i).first,b=dif.at(i).second,c=dif.at(j).first,d=dif.at(j).second;
      if(a==c&&b==d)count++;
      if(a==-1*c&&b==-1*d)count++;
    }
    same.push_back(count);
  }
  sort(same.begin(),same.end());
  reverse(same.begin(),same.end());
  cout<<N-1-same.at(0);
  }
}


Measured memory_bytes: 3680
#include<bits/stdc++.h>
using namespace std;
#define INF 1e9
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
const int MOD = 1000000007;

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

void solve() {
  ll n, x;
  cin >> n >> x;
  vector<ll> v(n + 1);
  v[n] = x;
  rep(i,n) cin >> v[i];
  sort(v.begin(), v.end());
  ll ans = v[1] - v[0];
  rep(i,n) {
    ans = gcd(ans, v[i+1] - v[i]);
  }
  cout << ans << endl;
}

int main() {
  solve();
  return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace         std;
#define                 int long long
#define                 pb push_back
#define                 mp make_pair
#define st(arr,a)       memset(arr,a,sizeof arr)
#define                 nl cout<<endl
#define                 real signed
#define                 endl '\n'              
#define bitcount(x)     __builtin_popcountll(x)
const int MOD = 1000000007ll;
#define forn(i,a,b)     for(int i=a;i<=b;i++)
#define rfor(i,a,b)     for(int i=a;i>=b;i--)
#define all(x)          x.begin() , x.end()
#define pi pair<int,int>
#define X first
#define Y second
#define N 1014159
#define  vi vector<int>
#define  v  vector




void solve()
{
    int a,b;
    cin>>a>>b;
    cout<<max({a+b,a-b,a*b});
    
}


signed main() 
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); 
    int t = 1;
    //cin>>t;
    while(t--)
    {
        solve();
    }



    return 0;

}

//       g++ -g c.cpp ; ./a.exe

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <math.h> // sqrt
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <iomanip> // setprecision
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vb = vector<bool>;
using vll = vector<long long>;
using pii = pair<int, int>;
using psi = pair<string, int>;

int main() {
    string S;
    cin >> S;
    string ans;
    for (char c : S) {
        if (c == 'B') {
            if (ans.size() != 0) {
                ans.pop_back();
            }
        }
        else {
            ans += c;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  int n,l,r;
  while(cin >> n >> l >> r && n) {
    int a[n];
    rep(i,n) R a[i];
    int ans=0;
    REP(x,l,r+1) {
      rep(i,n) {
        if(x%a[i]==0) {
          if(i%2==0) ans++;
          goto next;
        }
      }
      if(n%2==0) ans++;
    next:;
    }
    pr(ans);
  }
}

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



Measured memory_bytes: 3172
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <string>
using namespace std;
#define LL long long
#define lc c[x][0]
#define rc c[x][1]
#define pb push_back
const int N=5005,inf=2000000010;
struct PAT{
    int H,P;
}E[N];
bool cmp(PAT a,PAT b){
    return (a.H+a.P)<(b.H+b.P);
}
int f[N][N];
int main(){
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int i,j,n;
    scanf("%d",&n);
    for (i=1;i<=n;i++) scanf("%d%d",&E[i].H,&E[i].P);
    sort(E+1,E+n+1,cmp);
    for (j=1;j<=n;j++) f[0][j]=inf;f[0][0]=0;
    for (i=1;i<=n;i++){
        f[i][0]=0;
        for (j=1;j<=i;j++){
            f[i][j]=f[i-1][j];
            if (f[i-1][j-1]<=E[i].H) f[i][j]=min(f[i][j],f[i-1][j-1]+E[i].P);
        }
        for (;j<=n;j++) f[i][j]=inf;
    }
    for (i=n;i>=1;i--) if (f[n][i]<inf) break;
    cout<<i<<endl;
    return 0;
}


Measured memory_bytes: 98048
#include <bits/stdc++.h>
using namespace std;
string s;
int main()
{
	cin>>s;
	for(int i=0;i<s.size();i++){
		if(s[i]=='C'){
			for(int j=i;j<s.size();j++){
				if(s[j]=='F'){
					cout<<"Yes\n";
					return 0;
				}
			}
		}
	}
	cout<<"No\n";
	return 0;
}


Measured memory_bytes: 256
function main(lines) {
  const [N, M, K] = splitN(lines[0]);
  const A = splitN(lines[1]);
  const B = splitN(lines[2]);
  
  let t = K, i = 0;
  while (t-A[i] >= 0) {
    t -= A[i];
    i++;
  }

  let res = i, j = 0;
  while (true) {
    while (t-B[j] >= 0) {
      t -= B[j];
      j++;
    }
    res = Math.max(res, i+j);
    if (!i) break;
    t += A[i-1];
    i--;
  }
  
  console.log(res);
}


main( require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n") );



function splitN(s) {
  return s.split(' ').map(Number);
}

Measured memory_bytes: 56724
#include<bits/stdc++.h>
using namespace std;
 
int main(){
	int d,n;
	cin>>d>>n;

    int ans;
    if(n==100){
        ans=pow(100,d)*(n+1);
    }
    else 
        ans=pow(100,d)*n;
    
	
    cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#define NDEBUG
#include <cassert>

template <class Monoid, template <class> class Container> class segment_tree {
public:
	using value_structure = Monoid;
	using value_type = typename value_structure::value_type;
	using container_type = Container<value_type>;
	using const_reference = typename container_type::const_reference;
	using size_type = typename container_type::size_type;

private:
	size_type base_size;
	container_type c;
	static size_type getsize(const size_type size) {
		size_type ret = 1;
		while (ret < size)
			ret <<= 1;
		return ret;
	}
	void recalc(const size_type index) {
		c[index] = value_structure::operation(c[index << 1], c[index << 1 | 1]);
	}

public:
	segment_tree() : base_size(0), c() {}
	explicit segment_tree(const size_type size)
		: base_size(getsize(size)),
		c(base_size + size, value_structure::identity()) {}

	bool empty() const { return size() == 0; }
	size_type size() const { return c.size() - base_size; }

	const_reference operator[](const size_type index) const {
		assert(index < size());
		return c[index + base_size];
	}
	value_type fold(size_type first, size_type last) const {
		assert(first <= last);
		assert(first <= size());
		assert(last <= size());
		value_type ret_l = value_structure::identity(),
			ret_r = value_structure::identity();
		for (first += base_size, last += base_size; first < last;
			first >>= 1, last >>= 1) {
			if (first & 1)
				ret_l = value_structure::operation(ret_l, c[first++]);
			if (last & 1)
				ret_r = value_structure::operation(c[last - 1], ret_r);
		}
		return value_structure::operation(ret_l, ret_r);
	}
	template <class F> size_type search(const F &f) const {
		if (f(value_structure::identity()))
			return 0;
		if (!f(c[1]))
			return size() + 1;
		value_type acc = value_structure::identity();
		size_type i = 1;
		while (i < base_size)
			if (!f(value_structure::operation(acc, c[i <<= 1])))
				acc = value_structure::operation(acc, c[i++]);
		return i - base_size + 1;
	}

	void update(size_type index, const value_type &value) {
		assert(index < size());
		index += base_size;
		c[index] = value;
		while (index >>= 1)
			recalc(index);
	}
};

#include <algorithm>
#include <limits>
template <class T> class min_monoid {
public:
	using value_type = T;
	static value_type operation(const value_type &x, const value_type &y) {
		return ::std::min(x, y);
	}
	static value_type identity() {
		return 2147483647;
	}
	static value_type reverse(const value_type &x) { return x; }
};

#include <cstdio>
#include <vector>

template<class T> using vec_alias = ::std::vector<T>;

int main() {
	using uint = unsigned int;

	uint n, q;
	scanf("%u%u", &n, &q);

	segment_tree<min_monoid<uint>, vec_alias> seg(n);

	uint c, x, y;
	while (q--) {
		scanf("%u%u%u", &c, &x, &y);

		if (c)
			printf("%u\n", seg.fold(x, y + 1));
		else
			seg.update(x, y);
	}

	return 0;
}



Measured memory_bytes: 3132
class UnionFind():
    def __init__(self, n):
        self.parent = [-1 for _ in range(n)]

    def connect(self, a, b):
        a = self.root(a)
        b = self.root(b)

        if a == b: return False

        a, b = sorted([a, b], key=self.size, reverse=True)
        self.parent[a] += self.parent[b]
        self.parent[b] = a
        return True

    def size(self, a):
        return - self.parent[self.root(a)]

    def root(self, a):
        if self.parent[a] < 0:
            return a
        else:
            self.parent[a] = self.root(self.parent[a])
            return self.parent[a]


N,M = list(map(int,input().split()))

bridges = []
ans = [N * (N-1)//2]
uni = UnionFind(N)
for _ in range(M):
    bridges.append(list(map(lambda x: int(x)-1,input().split())))

for bridge in bridges[::-1]:
    a,b = bridge
    ans.append(ans[-1])
    if uni.root(a) != uni.root(b):
        ans[-1] -= uni.size(a)*uni.size(b)
        uni.connect(a,b)

for a in ans[:-1][::-1]:
    print(a)

Measured memory_bytes: 34840
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
typedef pair<lint,lint> pl;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
//問題文および制約はちゃんと確認しよう！
//サイズは10^5じゃなくて2×10^5とかかもしれないし、重要な制約・条件を見落としているかも
//とりあえずサンプルを読んでから解法を考えよう？
int h[110];
lint dp[110][110][110][2];
lint mo=1000000007,m2=(mo+1)/2;
vector<int> de;
lint zyo(lint x,lint y){
    lint ret=1,a=x;
    while(y>0){
    	if(y%2==1) ret=(ret*a)%mo;
    	a=(a*a)%mo;y/=2;
    }
    return ret;
}
pl cal(int l,int r,int d){
	int mi=114;
	REP(i,l,r) mi=min(mi,h[i]);
	vector<int> v;v.pb(l-1);
	REP(i,l,r){
		if(h[i]==mi) v.pb(i);
	}
	v.pb(r);
	lint r0=1,r1=1;
	if(v.size()==r-l+2){
		r0*=2;r1*=zyo(2,r-l);r1%=mo;
		r1-=r0;r1%=mo;r1+=mo;r1%=mo;
	}
	else{
		vector<pl> p;
		rep(i,(int)v.size()-1){
			if(v[i+1]>v[i]+1) p.pb(cal(v[i]+1,v[i+1],mi));
		}
		rep(i,p.size()){
			r0*=p[i].fi;r0%=mo;
			r1*=(p[i].fi*2+p[i].se);r1%=mo;
		}
		r0*=2;r0%=mo;
		r1*=zyo(2,v.size()-2);r1%=mo;
		r1-=r0;r1%=mo;r1+=mo;r1%=mo;
	}
	//cout<<l<<' '<<r<<' '<<d<<' '<<r0<<' '<<r1<<endl;
	dp[l][r][d][0]=r0*zyo(2,de[mi]-de[d]-1);dp[l][r][d][0]%=mo;
	dp[l][r][d][1]=r1;
	return mp(dp[l][r][d][0],dp[l][r][d][1]);
}
int main()
{
	int n;lint ba=1,out=0;
	cin>>n;
	rep(i,n){
		cin>>h[i];//de.pb(h[i]);
	}
	if(n==1){
		cout<<zyo(2,h[0])<<endl;return 0;
	}
	if(h[0]>h[1]){
		ba*=zyo(2,h[0]-h[1]);h[0]=h[1];ba%=mo;
	}
	if(h[n-1]>h[n-2]){
		ba*=zyo(2,h[n-1]-h[n-2]);h[n-1]=h[n-2];ba%=mo;
	}
	REP(i,1,n-1){
		int t=max(h[i-1],h[i+1]);
		if(h[i]>t){
			ba*=zyo(2,h[i]-t);h[i]=t;ba%=mo;
		}
	}
	//cout<<ba<<endl;
	//rep(i,n) cout<<h[i]<<' ';cout<<endl;
	rep(i,n) de.pb(h[i]);
	de.pb(0);sort(All(de));de.erase(unique(All(de)));
	rep(i,n) h[i]=lower_bound(All(de),h[i])-de.begin();
	memset(dp,-1,sizeof(dp));
	cal(0,n,0);
	out=(dp[0][n][0][0]+dp[0][n][0][1])*ba;
	cout<<out%mo<<endl;
}


Measured memory_bytes: 21120
#include <bits/stdc++.h>
#define ll long long;
using namespace std;
map<int,vector<int>> m;
int n,ma;
int main()
{
       ios_base::sync_with_stdio(false);
       cin.tie(NULL);
       cin>>n>>ma;
       for(int i=0;i<ma;i++)
       {
           int x,y;
           cin>>x>>y;
           m[x].push_back(y);
           m[y].push_back(x);
       }
       int pa[n+1]={0};
       int v[n+1]={0};
       v[1]=1;
       queue<int> q;
       q.push(1);
       while(q.size()!=0)
       {
           int h=q.front();
           q.pop();
           for(int i=0;i<m[h].size();i++)
           {
               if(v[m[h][i]]==0)
               {
                   pa[m[h][i]]=h;
                   v[m[h][i]]=1;
                   q.push(m[h][i]);
               }
           }
       }
       for(int i=2;i<=n;i++)
        {
            if(pa[i]==0)
             {
                 cout<<"No\n";
                 return 0;
             }
        }
        cout<<"Yes\n";
        for(int i=2;i<=n;i++)
         cout<<pa[i]<<"\n";
}

Measured memory_bytes: 16328
#include <bits/stdc++.h>
#include <fstream>
using namespace std;
typedef long long lint;
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(lint (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
#define all(x) (x).begin(),(x).end()
const lint MOD =998244353;
//const lint MAX = 1000000;
using Graph =vector<vector<lint>>;
typedef pair<lint,lint> P;
typedef map<lint,lint> M;

const int MAX = 15001000;
bool IsPrime[MAX];
int MinFactor[MAX];
vector<int> preprocess(int n = MAX) {
    vector<int> res;
    for (int i = 0; i < n; ++i) IsPrime[i] = true, MinFactor[i] = -1;
    IsPrime[0] = false; IsPrime[1] = false; 
    MinFactor[0] = 0; MinFactor[1] = 1;
    for (int i = 2; i < n; ++i) {
        if (IsPrime[i]) {
            MinFactor[i] = i;
            res.push_back(i);
            for (int j = i*2; j < n; j += i) {
                IsPrime[j] = false;
                if (MinFactor[j] == -1) MinFactor[j] = i;
            }
        }
    }
    return res;
}

vector<pair<int,int> > prime_factor(int n) {
    vector<pair<int,int> > res;
    while (n != 1) {
        int prime = MinFactor[n];
        int exp = 0;
        while (MinFactor[n] == prime) {
            ++exp;
            n /= prime;
        }
        res.push_back(make_pair(prime, exp));
    }
    return res;
}


// 最大公約数
int GCD(int x, int y) { return y ? GCD(y, x%y) : x; }


int main() {
    // 入力
    int n; scanf("%d", &n);
    vector<int> a(n);
    for (int i = 0; i < n; ++i) a[i]=i+1;

    long long ans=0;
    // 各素因子ごとに a に何個あるかをカウント
    preprocess();
    map<int,int> mp;
    rep(i,n){
        if(i==0)ans+=1;
        else {
            int f=MinFactor[i+1];
            int g=i+1;
            g/=f;
            mp.clear();
            mp[f]++;
            while(g!=1){
                f=MinFactor[g];
                g/=f;
                mp[f]++;
            }
            lint mul=1;
            for(auto x:mp){
            mul*=(x.second+1);
            }
            ans+=mul*(i+1);
        }
    }
  cout<<ans<<endl;
}

Measured memory_bytes: 119780
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = 1; i <= (int)(n); i++)
#define drep(i, n) for(int i = (n)-1; i >= 0; i--)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;

// Mod int
const int mod = 1000000007;
// const int mod = 998244353;
struct mint {
  ll x;
  mint():x(0){}
  mint(ll x):x((x%mod+mod)%mod){}
  // mint(ll x):x(x){}
  mint& fix() { x = (x%mod+mod)%mod; return *this;}
  mint operator-() const { return mint(0) - *this;}
  mint& operator+=(const mint& a){ if((x+=a.x)>=mod) x-=mod; return *this;}
  mint& operator-=(const mint& a){ if((x+=mod-a.x)>=mod) x-=mod; return *this;}
  mint& operator*=(const mint& a){ (x*=a.x)%=mod; return *this;}
  mint operator+(const mint& a)const{ return mint(*this) += a;}
  mint operator-(const mint& a)const{ return mint(*this) -= a;}
  mint operator*(const mint& a)const{ return mint(*this) *= a;}
  bool operator<(const mint& a)const{ return x < a.x;}
  bool operator==(const mint& a)const{ return x == a.x;}
};
istream& operator>>(istream&i,mint&a){i>>a.x;return i;}
ostream& operator<<(ostream&o,const mint&a){o<<a.x;return o;}
//



int main() {
  int k;
  cin >> k;
  int x = 7%k;
  rrep(i, k) {
    if (x == 0) {
      cout << i << endl;
      return 0;
    }
    x = (10*x + 7)%k;
  }
  cout << -1 << endl;
}

Measured memory_bytes: 3604
#include <stdio.h>
#include <vector>
#include <map>
#include <string>
#include <iostream>
#include <limits.h>
#include <algorithm>

using namespace std;

int main()
{
    int A, P;
    cin >> A >> P;

    cout << (A * 3 + P) / 2 << endl;

    return 0;
}

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

namespace Geometry{
    using namespace std;
    using ld=long double;
    using Point=complex<ld>;

    struct Line{
        Point a,b;
    };

    struct Circle{
        Point p;
        ld r;
    };
    const ld EPS=1e-6;
    inline bool EQ(Point a,Point b){return abs(a-b)<EPS;}
    ld dot(Point a,Point b){return real(a)*real(b)+imag(a)*imag(b);}
    ld cross(Point a,Point b){return real(a)*imag(b)-imag(a)*real(b);}

    const int CCW=1;
    const int CW=-1;
    const int BAC=2;
    const int ACB=-2;
    const int ABC=0;
    int ccw(Point a,Point b,Point c){
        b-=a,c-=a;
        if(cross(b,c)>EPS) return CCW; // counter clockwise
        if(cross(b,c)<-EPS) return CW; //clockwise
        if(dot(b,c)<-EPS) return BAC; //b-a-c
        if(abs(b)<abs(c)) return ACB; //a-c-b
        return ABC; //a-b-c (abs(b)>abs(c))
    }

    bool isis_ss(Line x,Line y){
        return ccw(x.a,x.b,y.a)*ccw(x.a,x.b,y.b)<=0 && ccw(y.a,y.b,x.a)*ccw(y.a,y.b,x.b)<=0;
    }

    ld dist_lp(Line l,Point p){
        Point x=l.b-l.a;
        Point y=p-l.a;
        return abs(cross(x,y))/abs(x);
    }

    ld dist_sp(Line l,Point p){
        if(dot(p-l.a,l.b-l.a)<EPS) return abs(p-l.a);
        if(dot(p-l.b,l.a-l.b)<EPS) return abs(p-l.b);
        return dist_lp(l,p);
    }

    ld dist_ss(Line x,Line y){
        if(isis_ss(x,y)) return 0;
        ld a=min(dist_sp(x,y.a),dist_sp(x,y.b));
        ld b=min(dist_sp(y,x.a),dist_sp(y,x.b));
        return min(a,b);
    }
}
using namespace Geometry;

const ld INF=1000;

ld solve(int n){
    Point s,e;
    ld sx,sy,ex,ey;
    cin>>sx>>sy>>ex>>ey;
    s={sx,sy},e={ex,ey};
    Line cource={s,e};
    ld xmin=min(sx,ex);
    ld xmax=max(sx,ex);
    ld ymin=min(sy,ey);
    ld ymax=max(sy,ey);
    ld res=INF;
    for(int i=0;i<n;i++){
        ld x[2];
        ld y[2];
        ld h;
        cin>>x[0]>>y[0]>>x[1]>>y[1]>>h;
        if(x[0]<=xmin && xmax<=x[1] && y[0]<=ymin && ymax<=y[1]){
            res=0;
        }
        for(int ix=0;ix<2;ix++){
            for(int iy=0;iy<2;iy++){
                Point p={x[ix],y[iy]};
                Point p0={x[(ix+1)&1],y[iy]};
                Point p1={x[ix],y[(iy+1)&1]};
                Line l[2]={Line{p,p0},Line{p,p1}};
                for(int k=0;k<2;k++){
                    ld d=dist_ss(cource,l[k]);
                    ld r=(h*h+d*d)/(2*h);
                    if(r<h){                        
                        r=d;
                    }              
                    res=min(res,r);
                }
                
            }
        }
    }
    return res;
}
int main(){
    int n;
    cout<<setprecision(10)<<fixed;
    while(cin>>n,n){
        cout<<solve(n)<<endl;
    }
    return 0;
}


Measured memory_bytes: 3264
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author TM
 */


#include <bits/stdc++.h>

using namespace std;

class CGreenBin {
public:
    void solve(std::istream &cin, std::ostream &cout) {
        int n;
        cin >> n;
        vector<string> s_vec(n);
        for (int i = 0; i < n; ++i) {
            string tmp;
            cin >> tmp;
            sort(tmp.begin(), tmp.end());
            s_vec[i] = tmp;
        }
        sort(s_vec.begin(), s_vec.end());

        string start = s_vec[0];
        long same = 1;
        long ans = 0;
        for (int j = 1; j < n; ++j) {
            if (s_vec[j] == start) {
                same += 1;
            } else {
                ans += (same * (same - 1)) / 2;
                same = 1;
                start = s_vec[j];
            }
        }
        ans += (same * (same - 1)) / 2;
        cout << ans << endl;
    }
};


int main() {
    CGreenBin solver;
    std::istream &in(std::cin);
    std::ostream &out(std::cout);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 5760