akhauriyash/Code-Regression huggingface dataset:
#include <algorithm> //STLÍ¨ÓÃËã·¨
#include <cmath> //¶¨ÒåÊýÑ§º¯Êý
#include <cstdio> //¶¨ÒåÊäÈë/Êä³öº¯Êý
#include <iostream> //Êý¾ÝÁ÷ÊäÈë/Êä³ö
#include <cstring> //×Ö·û´®´¦Àí
#include <string> //×Ö·û´®Àà
#include <ctime> //¶¨Òå¹ØÓÚÊ±¼äµÄº¯Êý
#define itn int
#define fro for
#define ll long long
#define reg register
#define inf 1234567890
#define rep(i,a,b,c) for (int i=a;i<=b;i+=c)
/*#include <bitset> //STLÎ»¼¯ÈÝÆ÷
#include <cstype> //×Ö·û´¦Àí
#include <cerrno> //¶¨Òå´íÎóÂë
#include <complex> //¸´ÊýÀà
#include <clocale> //¶¨Òå±¾µØ»¯º¯Êý
#include <cstdlib> //¶¨ÒåÔÓÏîº¯Êý¼°ÄÚ´æ·ÖÅäº¯Êý
#include <deque> //STLË«¶Ë¶ÓÁÐÈÝÆ÷
#include <exception> //Òì³£´¦ÀíÀà
#include <fstream> //ÎÄ¼þÊäÈë/Êä³ö
#include <functional> //STL¶¨ÒåÔËËãº¯Êý(´úÌæÔËËã·û)
#include <limits> //¶¨Òå¸÷ÖÖÊý¾ÝÀàÐÍ×îÖµ³£Á¿
#include <list> //STLÏßÐÔÁÐ±íÈÝÆ÷
#include <map> //STLÓ³ÉäÈÝÆ÷
#include <iomanip> //²ÎÊý»¯ÊäÈë/Êä³ö
#include <ios> //»ù±¾ÊäÈë/Êä³öÖ§³Ö
#include <iosfwd> //ÊäÈë/Êä³öÏµÍ³Ê¹ÓÃµÄÇ°ÖÃÉùÃ÷
#include <istream> //»ù±¾ÊäÈëÁ÷
#include <ostream> //»ù±¾Êä³öÁ÷
#include <queue> //STL¶ÓÁÐÈÝÆ÷
#include <set> //STL¼¯ºÏÈÝÆ÷
#include <sstream> //»ùÓÚ×Ö·û´®µÄÁ÷
#include <stack> //STL¶ÑÕ»ÈÝÆ÷
#include <stdexcept> //±ê×¼Òì³£Àà
#include <streambuf> //µ×²ãÊäÈë/Êä³öÖ§³Ö
#include <utility> //STLÍ¨ÓÃÄ£°åÀà
#include <vector> //STL¶¯Ì¬Êý×éÈÝÆ÷
#include <cwchar.h>//¿í×Ö·û´¦Àí¼°ÊäÈë/Êä³ö
#include <cwctype.h> //¿í×Ö·û·ÖÀà*/

using namespace std;

int ans;

int max(int x,int y){return x>y?x:y;}

int min(int x,int y){return x<y?x:y;}

int abs(int x){return x>0?x:-x;}

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

void exgcd(int a,int b,int &d,int &x,int &y){if (!b){d=a,x=1,y=0;}else{exgcd(b,a%b,d,y,x);y-=x*(a/b);}}

int quick_power(ll a,int b){ll r=1;for (;b;b>>=1,a=a*a)if (b&1) r=r*a;return r;}

inline char read() {
	static const int IN_LEN = 1000000;
	static char buf[IN_LEN], *s, *t;
	return (s == t ? t = (s = buf) + fread(buf, 1, IN_LEN, stdin), (s == t ? -1 : *s++) : *s++);
}
template<class T>
inline void read(T &x) {
	static bool iosig;
	static char c;
	for (iosig = false, c = read(); !isdigit(c); c = read()) {
		if (c == '-') iosig = true;
		if (c == -1) return;
	}
	for (x = 0; isdigit(c); c = read()) x = x * 10 + (c ^ '0');
	if (iosig) x = -x;
}

char sr[10000000],z[20];int C=-1,Z=0;
void Ot(){fwrite(sr,1,C+1,stdout),C=-1;}
void print(int x){
	if (x<0) sr[++C]='-',x=-x;
    while(z[++Z]=x%10+48,x/=10);
    while(sr[++C]=z[Z],--Z);sr[++C]='\n';
}
//int find(int x){return fa[x]=fa[x]==x?x:find(fa[x]);}

//void add(int x,int y,int z){to[++cnt]=y;v[cnt]=z;Next[cnt]=head[x];head[x]=cnt;}
int main()
{
	int n,k;
	read(n);read(k);
	cout<<n-k+1;
	return 0;
}








Measured memory_bytes: 2304
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;

public class Main {
    static String INPUT = "";

    public static void main(String[] args) {
        InputStream is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());

        Scanner scanner = new Scanner(is);

        final int n = scanner.nextInt();

        List<Integer> mochi = new ArrayList<>(n);
        for (int i = 0; i < n; i++) {
            mochi.add(scanner.nextInt());
        }
        System.out.println(solve(mochi));
    }

    static int solve(List<Integer> mochiList) {
        return new HashSet<>(mochiList).size();
    }

}


Measured memory_bytes: 21844
def getlist():
	return list(map(int, input().split()))

N = int(input())
A = getlist()
A = sorted(A)

if A[0] >= 0:
	M = sum(A) - 2 * A[0]
	print(M)
	x = A[0]
	for i in range(N - 2):
		y = A[i + 1]
		print(x, y)
		x -= y
	print(A[-1], x)

elif A[-1] <= 0:
	M = -sum(A) + 2 * A[-1]
	print(M)
	x = A[-1]
	for i in range(N - 2):
		y = A[-2 - i]
		print(x, y)
		x -= y
	print(x, A[0])

else:
	M = 0
	for i in range(N):
		M += abs(A[i])
	print(M)

	for i in range(N):
		if A[i] > 0:
			n = i
			break

	Ll = []
	Rl = []
	for i in range(N):
		if A[i] < 0:
			Ll.append(A[i])
		else:
			Rl.append(A[i])
	ln = len(Ll)
	rn = len(Rl)
	x = Ll[0]
	for i in range(rn - 1):
		y = Rl[i]
		print(x, y)
		x -= y
	Ll[0] = x
	x = Rl[-1]
	for i in range(ln):
		y = Ll[i]
		print(x, y)
		x -= y

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

char s[2020],t[2020];
int n,pre[2020],nex[2020],pd[2020],nd[2020],p,ans,x[2020],y[2020];
vector<int>v[2020];

void f__k(){
	int fl=0; for (int i=0;i<n;i++) fl|=s[i]-'0';
	exit(0*puts(fl?"-1":"0")); 
}
int fix(int x) { return (x%n+n)%n; }

int cal(){
	for (int i=0;i<n;i++) v[i].clear();
	for (int i=0;i<n;i++) v[x[i]].push_back(i);
	int mx=0,res=1e6;
	for (int i=n-1;i>=0;i--){
		res=min(res,i+mx);
		for (int j:v[i]) mx=max(mx,y[j]);
	}
	return res;
}

int doit(int c){
	int res=abs(c); for (int i=0;i<n;i++) res+= s[i]!=t[fix(i+c)];
	memcpy(x,pd,sizeof x); memcpy(y,nd,sizeof y);
	for (int i=0;i<n;i++) c<0? x[i]=max(x[i]+c,0): y[i]=max(y[i]-c,0);
	return res+2*cal();
}

int main(){
	scanf("%s%s",s,t); n=strlen(s);
	for (p=0;t[p]=='0';p++);
	if (p==n) f__k();
	nex[n-1]= t[n-1]=='1'? n-1: p;
	for (int i=n-2;i>=0;i--) nex[i]= t[i]=='1'? i: nex[i+1];
	for (p=n-1;t[p]=='0';p--);
	pre[0]= t[0]=='1'? 0: p;
	for (int i=1;i<n;i++) pre[i]= t[i]=='1'? i: pre[i-1];
	for (int i=0;i<n;i++) pd[i]=s[i]=='1'? fix(i-pre[i]): 0, nd[i]=s[i]=='1'? fix(nex[i]-i): 0;
	ans=1e6; for (int i=1-n;i<=n-1;i++) ans=min(ans,doit(i));
	cout<<ans;
}

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

#define rep(i, n) for(long long i=0;i<(long long)(n);i++)
#define rep2(i, s, n) for(long long i=(s);i<(long long)(n);i++)
#define repi(i, n) for(int i=0;i<(int)(n);i++)
#define rep2i(i, s, n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(), v.end()

#define deg2rad(deg) (((deg)/360)*2*M_PI)
#define rad2deg(rad) (((rad)/2/M_PI)*360)

using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;

const ll INF = (1LL<<60);
const int INFi = (1<<29);

/*素数判定*/
bool is_prime(ll n){
    if(n==1) return false;
    for(ll i=2;i*i<=n;i++){
        if(n%i==0) return false;
    }
    return true;
}

/*約数列挙*/
vll enum_divisors(ll n){
    vll l;
    for(ll i=1;i*i<=n;i++){
        if(n%i==0){
            l.push_back(i);
            if(n/i != i) l.push_back(n/i);
        }
    }
   sort(all(l));
   return l;
}

/*素因数分解*/
vector<P> prime_factorize(ll n){
    vector<P> l;
    for(ll i=2;i*i<=n;i++){
        if(n%i!=0) continue;
        ll e = 0;
        while(n%i==0){
            e++;
            n /= i;
        }
        l.push_back({i, e});
    }
    if(n!=1) l.push_back({n, 1});
    return l;
}

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

/*最大公約数*/
ll gcd(ll a, ll b){
    return __gcd(a,b);
}

int main(){

    ll n; cin>>n;
    ll in, in2;
    cin >> in;
    rep(i, n-1){
        cin >> in2;
        in = gcd(in, in2);
    }

    cout << in << endl;

    return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
 
 
using namespace std;
 
#define ll long long
#define ul unsigned long long
#define snd second
#define fst first
 

ll a,b,c,d,e,f,n,m;

int main(){
    std::ios::sync_with_stdio(false);
    cin >> a >> b;
    if(a % b == 0) cout << a/b;
    else cout << (a/b + 1);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define int long long
#define double long double
#define mod 1000000007
#define F first
#define S second
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
#define INF 1000000000000000
#define endl '\n'
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;

signed main(){
    int n; cin>>n;
    string s; cin>>s;
    vector<int> b(n,0),w(n,0);
    int B=0, W=0;
    rep(i,n){
        if(s.at(i)=='#') W++;
        w.at(i)=W;
    }
    for(int i=n-1; i>=0; i--){
        if(s.at(i)=='.') B++;
        b.at(i)=B;
    }
    int ans=INF;
    chmin(ans, w.back());
    chmin(ans, b.front());
    rep(i,n-1){
        chmin(ans, w.at(i)+b.at(i+1));
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3716
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace ConsoleApplication2 {
    class Program {
        static void Main(string[] args) {

            TextReader input = Console.In;

            string str = input.ReadLine();

            for (int ii = str.Length - 1; ii >= 0; ii--) {
                Console.Write(str[ii]);
            }

            Console.WriteLine();
        }
    }
}

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


namespace Test1 {

    


    class ClassMain {

        static bool[,] remainJ = new bool[21,21];
        static int robX = 10, robY = 10;

        public static void roboMv(string dir, int n) {
            char ch = dir[0];
            for (int i = 0; i < n; i++) {
                if (ch == 'N') { robY++; }
                else if (ch == 'E') { robX++; }
                else if (ch == 'S') { robY--; }
                else if (ch == 'W') { robX--; }
                if (remainJ[robY, robX]) { remainJ[robY, robX] = false; }
                //Console.WriteLine(robX + "x y" + robY);
            }
        }

        public static bool takeAllJ() {
            for (int i = 0; i <= 20; i++) {
                for (int j = 0; j <= 20; j++) {
                    if (remainJ[i, j]) { return false; }
                }
            }
            return true;
        }

        public static void Main(String[] args) {
            string line;
            while ((line = Console.ReadLine()) != null) {
                int n = int.Parse(line);
                if (n == 0) { break; }
                remainJ = new bool[21, 21];
                robX = 10; robY = 10;
                for (int i = 0; i < n; i++) {
                    int[] ints = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
                    remainJ[ints[1], ints[0]] = true;
                }
                int m = int.Parse(Console.ReadLine());
                for (int i = 0; i < m; i++) {
                    string[] strs = Console.ReadLine().Split(' ');
                    roboMv(strs[0], int.Parse(strs[1]));
                }
                if (takeAllJ()) {
                    Console.WriteLine("Yes");
                }
                else {
                    Console.WriteLine("No");
                }

            }
        }

        
    }



    
}

Measured memory_bytes: 5896
#!/usr/bin/env python3
# Generated by https://github.com/kyuridenamida/atcoder-tools
from typing import *
import collections
import functools
import itertools
import math
import sys

INF = float("inf")


def solve(N: int, M: int, p: "List[int]", S: "List[str]"):
    ac = [0 for _ in range(N)]
    for i in set(x[0] for x in zip(p, S) if x[1] == "AC"):
        ac[i - 1] = 1
    wa = 0
    for x in zip(p, S):
        ac[x[0] - 1] &= x[1] == "WA"
        wa += ac[x[0] - 1]
    return f'{len(set(x[0] for x in zip(p,S) if x[1] == "AC"))} {wa}'


def main():

    sys.setrecursionlimit(10 ** 6)

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    p = [int()] * (M)  # type: "List[int]"
    S = [str()] * (M)  # type: "List[str]"
    for i in range(M):
        p[i] = int(next(tokens))
        S[i] = next(tokens)
    print(f"{solve(N, M, p, S)}")


if __name__ == "__main__":
    main()


Measured memory_bytes: 101752
#include<bits/stdc++.h>
using namespace std;
#define ff          first
#define ss          second
#define ll         	long long int
#define pb          push_back
#define ar 			array
#define mp 			make_pair
#define f(i,n)   	for(ll i =0;i<n;i++)
#define inf 		INT_MAX
#define pll 		pair<ll,ll>
const ll INF = 1e18;
void init(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE 
		freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#endif
}
const ll N = 1e5 + 10;
void solve(){

	ll x,y;
	
	cin>>x>>y;

	ll temp = 4*x - y;
	if(temp < 0){
		cout<<"No"<<endl;
		return;
	}
	if(temp %2 != 0){
		cout<<"No"<<endl;
		return;
	}
	else if(temp / 2 > x){
		cout<<"No"<<endl;
		return;
	}
	else{
		cout<<"Yes"<<endl;
		return;
	}
}
int main(){
	
	init();
	ll t = 1;
	//cin>>t;
	for(ll i=1;i<=t;i++){
		//cout<<"Case #"<<i<<": ";
		solve();
	}
}


Measured memory_bytes: 3656
#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
N = int(input())
an = list(map(int, input().split()))

ans = 0
right = 0
arith_sum = 0
for left in range(N):
    while right < N and arith_sum ^ an[right] == arith_sum + an[right]:
        arith_sum += an[right]
        right += 1
    ans += right - left
    if left == right:
        right += 1
    else:
        arith_sum -= an[left]

print(ans)

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

int main()
{
    int n,a,b;
    long ans = 0;
    cin >> n >> a >> b;
    for(int i =1; i<=n; i++){
        int t = i;
        int sum = 0;
        while(t != 0){
            sum += t%10;
            t = t/10;
        }
        if(sum>=a && sum <=b)
            ans += i;
    }
    cout << ans << endl;    
    return 0;
}

Measured memory_bytes: 256
N = int(input())
line = input().split()
B = [0] * (N-1)
for i in range(N-1):
    B[i] = int(line[i])

ans = 0
for i in range(N):
    if i == 0:
        ans += B[i]
    elif i == N-1:
        ans += B[i-1]
    else:
        ans += min(B[i], B[i-1])
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>

int main()
{
    int a, b;
    std::cin >> a >> b;

    int n = b - a;
    std::vector<int> h(n);

    h[0] = 1;
    for (int i = 1; i < n; i++) {
        h[i] = h[i-1] + i + 1;
    }

    int ans = h[n-1] - b;
    
    std::cout << ans << std::endl;

    return 0;
}

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

using namespace std;
typedef pair <int, int> pii;
#define pb push_back
#define mp make_pair
#define ll long long
#define PI acos(-1)

int main() {
    int n, m, sum = 0;
    cin >> n >> m;
    int a[m];
    for(int i = 0; i < m; i++){
        cin >> a[i];
        sum += a[i];
    }
    if(sum > n) cout << -1;
    else
    cout << n - sum;

    return 0;
}


Measured memory_bytes: 3636
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long[] a = new long[n];
		long judge = (long) Math.pow(10, 18);
		for(int i = 0; i < n; i++) {
			a[i] = sc.nextLong();
		}
		Arrays.sort(a);
		if(a[0]==0) {
			System.out.println(0);
			return;
		}
		long ans = 1;
		for(int i = 0; i < n; i++) {
			if(ans>judge/a[i]) {
				System.out.println(-1);
				return;
			}
			ans*=a[i];
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 61892
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <complex>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
#include <assert.h>
#include <array>
#include <cstdio>
#include <cstring>
#include <random>
#include <functional>
#include <numeric>
#include <bitset>
#include <fstream>
 
using namespace std;
 
#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { cout << #a << " = " << a << endl; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }
 
typedef long long ll;
int const inf = 1<<29;
 
constexpr int MOD = 1e9+7;
 
namespace graph { // not verified
 
constexpr int MaxV = 1010;
 
struct scc {
 
  int V = MaxV;
  vector<int> G[MaxV];
  vector<int> rG[MaxV];
  vector<int> vs;
  vector<bool> used;
  vector<int> comp;
  int SCCGraphSize;
 
  scc(): V(MaxV) { comp.resize(MaxV); }
  scc(int V_): V(V_) { comp.resize(MaxV); }
 
  void add_edge(int from, int to) {
    G[from].push_back(to);
    rG[to].push_back(from);
  }
 
  void dfs(int v) {
    used[v] = 1;
    for(auto e: G[v]) {
      if(!used[e]) dfs(e);
    }
    vs.push_back(v);
  }
 
  void rdfs(int v, int k) {
    used[v] = 1;
    comp[v] = k;
    for(auto e: rG[v]) {
      if(!used[e]) rdfs(e, k);
    }
  }
 
  void solve() {
    used.clear(); used.resize(MaxV);
    vs.clear();
    for(int i = 0; i < V; i++) {
      if(!used[i]) dfs(i);
    }
    used.clear(); used.resize(MaxV);
    int k = 0;
    for(int i = vs.size() - 1; i >= 0; i--) {
      if(!used[vs[i]]) rdfs(vs[i], k++);
    }
    SCCGraphSize = k;
  }
 
};
 
}
 
vector<vector<int>> tree;
 
ll solve(int curr, int par, vector<bool>& vis) {
  ll ret = 1;
  vis[curr] = 1;
  for(auto e: tree[curr]) {
    if(e == par) continue;
    ret *= solve(e, curr, vis);
    ret %= MOD;
  }
  return ret + 1;
}
 
int main() {
 
  int N, M; cin >> N >> M;
  graph::scc scc_graph(N);
  rep(i, M) {
    int S, D; cin >> S >> D; S --, D --;
    scc_graph.add_edge(S, D);
  }
 
  scc_graph.solve();
 
  auto& K = scc_graph.SCCGraphSize;
  auto& g = scc_graph.G;
  auto& comp = scc_graph.comp;
 
  tree.resize(K);
  int deg[1010] = {};
 
  rep(i, N) {
    for(auto e: g[i]) {
      if(comp[i] == comp[e]) continue;
      tree[comp[e]].push_back(comp[i]);
      deg[comp[i]] ++;
    }
  }
 
  rep(i, K) {
    sort(tree[i].begin(), tree[i].end());
    tree[i].erase(unique(tree[i].begin(), tree[i].end()), tree[i].end());
  }
 
  ll ans = 1;
  vector<bool> vis(K);
  rep(i, K) if(deg[i] == 0 && !vis[i]) {
    vis[i] = 1;
    ans *= solve(i, -1, vis);
    ans %= MOD;
  }
 
  cout << ans << endl;
   
  return 0;
}

Measured memory_bytes: 3272
#include <bits/stdc++.h>
using namespace std;
using ll = int_fast64_t;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;
#define fast() ios::sync_with_stdio(false), cin.tie(nullptr)
#define digit(N) cout << fixed << setprecision((N))
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

ll N, ans;

int main()
{
	fast();
	cin >> N;
	for (ll i = 2, M = N; i * i <= M && N != 1; i++)
	{
		ll z = i;
		while (N % z == 0)
			ans++, N /= z, z *= i;
		while (N % i == 0)
			N /= i;
	}

	cout << ans + (N != 1) << "\n";
}

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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
typedef double DOUBLE;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define file "I1"

const double EPS = 1e-9;
const double PI = acos(-1.);
const ll LL_INF = 1e17 + 10;
const int INF = 1e9 + 10;
const ll MOD = 1e9 + 7;

const int MAXN = 2e5 + 5;

pii pp[MAXN];
vector<pii> vv;

pii intersect(pii &a, pii &b) {
	return mp(max(a._1, b._1), min(a._2, b._2));
}

int get_len(pii &p) {
	return max(0, p._2 - p._1 + 1);
}

bool cmp(const pii &a, const pii &b) {
	return a._1 != b._1 ? a._1 < b._1 : a._2 > b._2;
}

void solve(){
	int n;
	scanf("%d", &n);
	REP(i, 0, n) {
		scanf("%d%d", &pp[i]._1, &pp[i]._2);
	}
	int mx = 0;
	pii ppl = mp(0, INF), ppr = mp(0, INF);
	REP(i, 0, n) {
		mx = max(mx, get_len(pp[i]));
		if (pp[i]._1 > ppl._1 || pp[i]._1 == ppl._1 && pp[i]._2 < ppl._2) {
			ppl = pp[i];
		}
		if (pp[i]._2 < ppr._2 || pp[i]._2 == ppr._2 && pp[i]._1 > ppr._1) {
			ppr = pp[i];
		}
	}
	swap(ppl, ppr);
	if (ppl == ppr) {
		printf("%d\n", mx + get_len(ppl));
		return;
	}
	int ans0 = mx + max(0, ppl._2 - ppr._1 + 1);
	
	REP(i, 0, n) {
		if (ppl._2 < pp[i]._1 && pp[i]._2 < ppr._1) {
			printf("%d\n", ans0);
			return;
		}
		if (ppl._2 < pp[i]._1) {
			ppr._2 = min(ppr._2, pp[i]._2);
		} else if (pp[i]._2 < ppr._1) {
			ppl._1 = max(ppl._1, pp[i]._1);
		}
	}
	
	int lim_l = min(ppl._2, ppr._1 - 1);
	int lim_r = max(ppl._2 + 1, ppr._1);
	vv.pb(mp(lim_l - ppl._1 + 1, 0));
	vv.pb(mp(0, ppr._2 - lim_r + 1));
	REP(i, 0, n) {
		if (ppl._1 < pp[i]._1 && pp[i]._1 <= lim_l 
			&& ppr._1 <= lim_r && pp[i]._2 < ppr._2) {
			vv.pb(mp(lim_l - pp[i]._1 + 1, pp[i]._2 - lim_r + 1));
		}
	}
	sort(vv.begin(), vv.end(), cmp);
	/*REP(i, 0, SZ(vv)) {
		printf("%d %d\n", vv[i]._1, vv[i]._2);
	}*/
	int ans1 = 0;
	int m = SZ(vv);
	int mn = vv[0]._2, cur = vv[1]._1;
	REP(i, 1, m) {
		mn = min(mn, vv[i - 1]._2);
		cur = vv[i]._1;
		//printf("-> %d + %d = %d\n", mn, cur, mn + cur);
		ans1 = max(ans1, mn + cur); 
	}
	ans1 += 2 * max(0, ppl._2 - ppr._1 + 1);
	//printf("mx %d %d\n", ans0, ans1);
	printf("%d\n", max(ans0, ans1));
}   

int main(){

    //freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();    
    }
}


Measured memory_bytes: 2168
import sys
sys.setrecursionlimit(2147483647)
input=sys.stdin.readline

def main():
  S = input()
  T = input()
  count = 0
  for i in range(len(S)):
    if(S[i] != T[i]):
      count+=1
  print(count)

if __name__=='__main__':
  main()

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

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;
typedef vector<double> vd;
typedef vector<vd> vdd;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)
#define RFOR(i,x,y) for(ll i=(ll)x; i>=(ll)y; --i)
#define RREP(i,x) RFOR(i, x, 0)
#define ALL(a) a.begin(), a.end()
#define pb push_back
#define debug_print(x...) cerr << "line " << __LINE__ << " : "; debug_print_in(x);

template <typename First>
void debug_print_in(First first){
  cerr << first << endl;
  return;
}

template <typename First, typename... Rest>
void debug_print_in(First first, Rest... rest){
  cerr << first << " ";
  debug_print_in(rest...);
  return;
}

void IN(void){
  return;
}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
  cin >> first;
  IN(rest...);
  return;
}

template <typename First>
void OUT(First first){
  cout << first << endl;
  return;
}

template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
  cout << first << " ";
  OUT(rest...);
  return;
}

template<class t, class u> void chmax(t&a,u b){if(a<b)a=b;};
template<class t, class u> void chmin(t&a,u b){if(a>b)a=b;};
int popcount(int t){return __builtin_popcount(t);} //GCC
int popcount(ll t){return __builtin_popcountll(t);} //GCC

template <typename T>
void vec_print(vector<T> VEC){
  REP(i, VEC.size()){
    cerr << VEC[i] << " ";
  }
  cerr << endl;
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  REP(i,MAT.size()){
    REP(j,MAT[i].size()){
      cerr << MAT[i][j] << " ";
    }
    cerr << endl;
  }
};

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9)+7);

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  string S;
  IN(S);
  if(S[1]=='B'){
    OUT("ARC");
  }else{
    OUT("ABC");
  }

  return 0;
}

Measured memory_bytes: 3652
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

// Acknowledgement: Special thanks to kyomukyomupurin, who developed this
// template.
template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) {
  return os << '(' << p.first << ", " << p.second << ')';
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) {
  int n = 0;
  for (auto e : vec) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::set<T>& st) {
  int n = 0;
  for (auto e : st) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) {
  int n = 0;
  for (auto e : mp) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T>
std::istream& operator>>(std::istream& is, std::vector<T>& vec) {
  for (T& e : vec) is >> e;
  return is;
}

#ifdef LOCAL
#define debug(...) \
  std::cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}
using namespace std;
using int64 = long long;

int main() {
  int64 a, b, c, d;
  cin >> a >> b >> c >> d;
  vector<int64> v = {a * c, a * d, b * c, b * d};
  cout << *max_element(v.begin(), v.end()) << endl;
  return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define lli long long int

int main() {
    int n,m,k;
    cin>>n>>m>>k;
    char arr[n][m];
    int ans[n][m];
    vector<pair<int,int>> v;
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            cin>>arr[i][j];
            if(arr[i][j] == '#'){
                v.push_back(make_pair(i, j));
            }
            ans[i][j] = -1;
        }
    }
    
    int type = 1;
    for(auto i : v){
        int x = i.first;
        int y = i.second;
        ans[x][y] = type;
        for(int j=y-1;j>=0;j--){
            if(arr[x][j] != '#' && ans[x][j] == -1){
                ans[x][j] = type;
            }else break;
        }
        for(int j=y+1;j<m;j++){
            if(arr[x][j] != '#' && ans[x][j] == -1){
                ans[x][j] = type;
            }else break;
        }
        type++;
    }
    for(int j=0;j<m;j++){
        int pos = -1;
        for(int i=0;i<n;i++){
            if(ans[i][j] != -1){
                pos = i;
                break;
            }
        }
        int val = ans[pos][j];
        for(int i=pos-1;i>=0;i--){
            if(ans[i][j] == -1){
                ans[i][j] = val;
            }else{
                val = ans[i][j];
            }
        }
        val = ans[pos][j];
        for(int i=pos+1;i<n;i++){
            if(ans[i][j] == -1){
                ans[i][j] = val;
            }else{
                val = ans[i][j];
            }
        }
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            cout<<ans[i][j]<<" ";
        }
        cout<<"\n";
    }
    return 0;
}


Measured memory_bytes: 2036
a=input()
b=a.split(" ")
c=list(map(int,b))
w=c[0]
h=c[1]
x=c[2]
y=c[3]
r=c[4]
if((x-r)<0 or (x+r)>w or (y-r)<0 or (y+r)>h):
    str="No"
else :
    str="Yes"
print(str)

Measured memory_bytes: 7704
import java.util.ArrayList;
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		
		// テキスト入力
		Scanner sc = new Scanner(System.in);
		StringBuilder all_out = new StringBuilder();
		StringBuilder out= new StringBuilder();;

		// 
		while (true) {

			int height = sc.nextInt();
			int width = sc.nextInt();

			if (height == 0 && width == 0){
				break;
			}
			// #を出す処理
			// 行の数
			for (int h = 0; h < height; h++) {

				// 列の数
				for (int w = 0; w < width; w++) {
					out = out.append("#");
				}
				out = out.append("\n");
			}
			all_out = all_out.append(out+"\n");
			out.delete(0, out.length());
		}
		System.out.print(all_out);
	}
}

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

int main(){
	int n,k; cin >> n >> k; 
	vector<int>v(n);
	for(int i=0; i<n; i++){
		cin >> v[i];
	}
	sort(v.begin(),v.end());
	int sum = 0;
	for(int i=0; i<k; i++){
		sum += v[i];
	}
	cout << sum << endl;
}


Measured memory_bytes: 3604
n,m,l = gets.split.map(&:to_i)
m1 = []
m2 = []
m3 = []

for i in 1..n
m1.push(gets.split.map(&:to_i))
end

for i in 1..m
m2.push(gets.split.map(&:to_i))
end


for i in 1..n
temp = []
for j in 1..l

sum = 0
for k in 1..m
sum += (m1[i-1][k-1])*(m2[k-1][j-1])
end

temp.push(sum)

end

m3.push(temp)

end

for i in 1..n

puts m3[i-1].join(" ")

end


Measured memory_bytes: 8932
///////////////////////////////////////////////////////////////////////////////

#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <cmath>
#include <typeinfo>
#include <sys/time.h>

#include <bits/stdc++.h>

using namespace std;

///////////////////////////////////////////////////////////////////////////////

#define pb push_back

int uf_parent[100004];
int uf_count[100004];
int uf_rank[100004];

void uf_init(int n)
{
        for (int i = 0; i < n; ++i) {
                uf_parent[i] = i;
                uf_count[i] = 1;
                uf_rank[i] = 0;
        }
}

int uf_root(int i)
{
        if (uf_parent[i] == i) return i;
        return uf_parent[i] = uf_root(uf_parent[i]);
}

void uf_unite(int i, int j)
{
        i = uf_root(i);
        j = uf_root(j);

        if (i == j) return;

        if (uf_rank[j] < uf_rank[i]) {
                uf_parent[j] = i;
                uf_count[i] += uf_count[j];
        }
        else {
                uf_parent[i] = j;
                uf_count[j] += uf_count[i];
                if (uf_rank[j] == uf_rank[i]) uf_rank[j]++;
        }
}

bool uf_same(int i, int j)
{
        return uf_root(i) == uf_root(j);
}

struct T2 {
        long t0;
        long t1;
};

void longin(long &a)
{
        cin >> a;
}

void longinl2(auto &v, long count)
{
        for (long i = 0; i < count ; ++i) {
                long a, b;
                cin >> a >> b;
                v.push_back({a, b});
        }
}

long combination(long x, long y)
{
        if (y > x / 2L) y = x - y;

        long ret = 1;
        for (int i = 0; i < y; ++i) {
                ret *= x--;
                ret /= (i + 1);
        }

        return ret;
}

///////////////////////////////////////////////////////////////////////////////

int main()
{
        long n, m;
        longin(n); longin(m);

        vector<T2> ablist;
        longinl2(ablist, m);

        uf_init(n);

        vector<long> anslist;
        long now = (n * (n - 1)) / 2;
        anslist.pb(now);
        int a;
        int b;
        int root_a;
        int root_b;

        for (int i = m - 1; i >= 0; --i) {
                a = ablist[i].t0;
                b = ablist[i].t1;

                root_a = uf_root(a);
                root_b = uf_root(b);

                if (root_a != root_b) {
                        now -= uf_count[root_a] * uf_count[root_b];
                        uf_unite(a, b);
                }

                anslist.pb(now);
        }

        reverse(anslist.begin(), anslist.end());
        for (int i = 1; i < anslist.size(); ++i)
                cout << anslist[i] << endl;

        return 0;
}

///////////////////////////////////////////////////////////////////////////////


Measured memory_bytes: 5872
import java.util.*;

class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int x = sc.nextInt();
        int ans = 0;

        for(int i = 0;i <= a;i++)
            for(int j = 0;j <= b;j++)
                for(int k = 0;k <= c;k++)
                    if(500*i + 100*j + 50*k == x)
                        ans++;

        System.out.println(ans);
    }
}

Measured memory_bytes: 23892
N,K = map(int, input().split())
A = list(map(int, input().split()))

# K以上のものはAから省く
B = []
for a in A:
    if a<K:
        B.append(a)

B.sort(reverse=True)

isNeeded = [False]*(len(B))
# iをスタックに入れる
for i in range(len(B)-1):
    res = B[i]
    stack = [i]
    for j in range(i+1,len(B)):
        res += B[j]
        stack.append(j)
        if res >= K:
            for s in stack:
                isNeeded[s] = True
            stack.pop()
            res -= B[j]
            
noNeed = len(B) - sum(isNeeded)
print(noNeed)

Measured memory_bytes: 45532
gets
s = gets.split

l = []
if s.length % 2 == 1
    (s.length - 1).step(0, -2) do |i|
        l.push s[i]
    end
    1.step(s.length - 1, 2) do |i|
        l.push s[i]
    end
else
    (s.length - 1).step(0, -2) do |i|
        l.push s[i]
    end
    0.step(s.length - 1, 2) do |i|
        l.push s[i]
    end
end

puts l.join(' ')

Measured memory_bytes: 19900
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  // ABC128C - Switches
  // 問題文と入力をよく理解して、データ構造を考える。
  // 入力は電球がどのスイッチと繋がっているか与えられるが、スイッチがどの電球と繋がっているかでデータを保持
  // スイッチで全探索→電球ごとのオンのスイッチ数→pと比較→全てtrueでans++
  // bit全探索で全ての条件が満たされるときにansをインクリメント
  int N, M; cin >> N >> M;
  vector<vector<int> > sw(N, vector<int>());
  REP(i, M){
    int K; cin >> K;
    REP(j, K){
      int s; cin >> s; s--;
      sw[s].push_back(i);
    }
  }  
  vector<int> p(M, 0);
  REP(i, M){
    cin >> p[i];
  }

  int ans = 0;
  REP(i, 1 << N){
    vector<int> on(M, 0); // 電球ごとのオン・スイッチ数。初期化を忘れずに
    REP(j, N){
      if((i >> j) & 1){
        for(int light : sw[j]) on[light]++;
      }
    }
    bool flag = true;
    REP(j, M){
      if(on[j] % 2 != p[j]) flag =false;
    }
    if(flag) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int X = input.nextInt();
		int ure500=0;
		int ure5=0;
		int j=0;
		int k=0;
		
		j=X/500;
		X-=500*j;
		
		k=X/5;
		
		ure500=j*1000;
		ure5=k*5;
		
		System.out.println(ure500+ure5);
		
	}
}


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

int N, Q;
string s;

int check(int n, vector<char> t, vector<char> d){
    for(int i = 0; i < Q; i++)
    {
        if(s.at(n) == t.at(i)){
            if(d.at(i) == 'L')n--;
            else n++;
        }

        if(n == -1 || n == N)return n;
    }

    return n;
}

int main() {

    cin >> N >> Q;
    cin >> s;

    vector<char> t(Q);
    vector<char> d(Q);

    for(int i = 0; i < Q; i++){
        cin >> t.at(i) >> d.at(i);
    }

    int ans1, ans2;

    int a, b;
    a = 0; b = N;

    while( b-a >= 1){
        int i = (a+b)/2;
        if(check(i, t, d) == -1)a = i+1;
        else b = i;
    }
    ans1 = a;

    a = 0; b = N;
    
    while( b-a >= 1){
        int i = (a+b)/2;
        if(check(i, t, d) == N)b = i;
        else a = i+1;
    }
    ans2 = a;

    cout <<  ans2 - ans1 << endl;
}

Measured memory_bytes: 1320
"""
author : halo2halo
date : 12, Jan, 2020
"""

import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

N, K = map(int, readline().split())
S = read().decode('utf8')
print(S[:K-1]+S[K-1].lower()+S[K:])


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll= long long;
using vi= vector<int>;
using vvi= vector<vi>;
using vd= vector<double>;
using vvd= vector<vd>;
using vc= vector<char>;
using vb= vector<bool>;
using vl= vector<ll>;
using vs= vector<string>;
#define rep(i,x,n) for(int i=x; i<n; i++)
#define all(x) x.begin(), x.end()

int main(){
  char a,b,c;
  cin >> a >> b >> c;
  if(a==b && a==c){
    cout << "No";
  }else{
    cout << "Yes";
  }
  
  return 0;
}


Measured memory_bytes: 256
W=input()
check=0
S=[]
while check==0:
    s=input().split()
    if s!=["END_OF_TEXT"]:
        ls = len(s)
        for i in range(ls):
            S.append(s[i])
    else:
        check=1
count=0
l=len(S)
for i in range(l):
    if S[i].upper()==W.upper():
        count+=1
print(count)



Measured memory_bytes: 5564
#include <bits/stdc++.h>
#define int long long
#define double long double
#define rep(i, a, n) for(int i = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int i = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int i = (int)(a);(x);++(i))
#define repr(i, a, n) for(int i = ((int)(a)-1);(i) >= (int)(n);--(i))
#define reper(i, a, n) for(int i = (int)(a);(i) >= (int)(n);--(i))
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x), end(x)
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), end(x))
#define gcd(x, y) __gcd(x, y)
#define lcm(x, y) ((x)/gcd(x,y)*(y))
#define isin(x, l, r) ((l) <= (x) and (x) < (r))
#define fcout cout << fixed << setprecision(10)
#define rcout(n) cout << right << setw(n)
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define PI (acos(-1))
#define EPS (1e-10)
#define INF LLONG_MAX
#define INF32 INT32_MAX
#define MOD 1000000007LL
using namespace std;
using VI = vector<int>;
using PII = pair<int, int>;
using TIII = tuple<int, int, int>;
using VPII = vector<PII>;
using VTIII = vector<TIII>;
using Complex = complex<double>;
template<typename T, template<typename> typename C = less> using PQ = priority_queue<T, vector<T>, C<T>>;
template<typename T> bool chmax(T& a, const T& b, bool t = false){ if(a<b or (t and a == b)){ a=b; return true; } return false; }
template<typename T> bool chmin(T& a, const T& b, bool t = false){ if(a>b or (t and a == b)){ a=b; return true; } return false; }


int n;
int d[60];


signed main(){
    cin >> n;
    rep(i, 0, n) cin >> d[i];

    int ans = 0;
    rep(i, 0, n) rep(j, i+1, n) ans += d[i]*d[j];

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
process.stdin.resume();

var lines = [];
var reader = require("readline").createInterface({
  input: process.stdin,
  output: process.stdout
});

reader.on("line", line => {
  var num = parseInt(line);
  var odd = 0;
  for (var i = 1; i <= num; i++) {
    if (i % 2 !== 0) {
      odd++;
    }
  }
  p = odd / num;
  console.log(p);
});


Measured memory_bytes: 7628
import sys
import itertools
import numpy as np
from collections import Counter
import math

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, M = map(int, input().split(' '))
G = [[] for _ in range(N+1)]
ans = [0]*(N+1)
count = 0
for i in range(M):
    A, B = map(int, input().split(' '))
    G[A].append(B)
    G[B].append(A)

s = [1]
for i in range(N):
    ne = []
    for i in s:
        for j in G[i]:
            if ans[j] == 0:
                ans[j] = i
                count += 1
                ne.append(j)
    s = ne
if 0 in ans[1:]:
    print('No')
    exit()
else:
    print('Yes')
    for i in ans[2:]:
        print(i)


Measured memory_bytes: 52348
#include <bits/stdc++.h>
#define mem(ar,num) memset(ar,num,sizeof(ar))
#define me(ar) memset(ar,0,sizeof(ar))
#define lowbit(x) (x&(-x))
#define Pb push_back
#define  FI first
#define  SE second
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define IOS ios::sync_with_stdio(false)
#define DEBUG cout<<endl<<"DEBUG"<<endl;
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int    prime = 999983;
const int    INF = 0x7FFFFFFF;
const LL     INFF = 0x7FFFFFFFFFFFFFFF;
const double pi = acos(-1.0);
const double inf = 1e18;
const double eps = 1e-6;
const LL     mod = 1e9 + 7;
LL qpow(LL a, LL b) {LL s = 1; while (b > 0) {if (b & 1)s = s * a % mod; a = a * a % mod; b >>= 1;} return s;}
LL gcd(LL a, LL b) {return b ? gcd(b, a % b) : a;}
int dr[2][4] = {1, -1, 0, 0, 0, 0, -1, 1};
typedef pair<int, int> P;
int main(void)
{
	int A, B;
	cin >> A >> B;
	for (int i = 0; i < 100; ++i) {
		if ((A - 1)*i + 1 >= B) {
			cout << i  << endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main(void)
{
  int a,b,c,n;
  vector<int> triangle;

  cin >> n;
  
  for(int i=0;i<n;i++){

    cin >> a >> b >> c;
    
    triangle.push_back(a);
    triangle.push_back(b);
    triangle.push_back(c);

    sort(triangle.begin(),triangle.end(),greater<int> () );

    a=triangle[0];
    b=triangle[1];
    c=triangle[2];

    if(a*a==b*b+c*c)
      cout << "YES" << endl;

    else
      cout << "NO" << endl;

    triangle.clear();

  }

  return 0;
  
}



Measured memory_bytes: 3060
#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;


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, m;
    set<int> s;
    cin >> n >> m;
    vii v(n);
    range(i, 1, m)s.insert(i);
    for (auto &p : v)cin >> p.fr >> p.sc;
    sort(ALL(v), [](const pii &a, const pii &b) {
        return a.sc > b.sc;
    });


    ll ans = 0;
    for (auto p : v) {
        auto it = s.lower_bound(p.fr);
        if (it != s.end()) {
            s.erase(it);
            ans += p.sc;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 5760
#include <iostream>

int main(void){
    long long b = 0, ans = 0;
    std::string S;
    std::cin >> S;

    for (char c: S){
        if (c == 'B'){
            ++b;
        } else {
            ans += b;
        }
    }

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

    return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>

using namespace std;

#define MAX_N 100
#define INF 100000 * 100 + 1

int cost[MAX_N][MAX_N];
int d[MAX_N];
bool used[MAX_N];
int V;

void dijkstra(int s) {
	fill_n(d, V, INF);
	fill_n(used, V, false);
	d[s] = 0;

	while (1) {
		int v = -1;
		for (int u = 0; u < V; u++)
			if (!used[u] && (v == -1 || d[u] < d[v]))
				v = u;

		if (v == -1)
			break;

		used[v] = true;

		for (int u = 0; u < V; u++)
			d[u] = min(d[u], d[v] + cost[v][u]);
	}
}

int main() {
	int n;
	cin >> n;
	V = n;
	for (int i = 0; i < n; i++) {
		int u, k;
		cin >> u >> k;
		fill_n(cost[u], n, INF);
		for (int j = 0; j < k; j++) {
			int v, c;
			cin >> v >> c;
			cost[u][v] = c;
		}
	}
	dijkstra(0);
	for (int i = 0; i < n; i++) {
		cout << i << " " << d[i] << endl;
	}
	
	return 0;
}

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

using namespace std;

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,n) for(int i=1;i<=(int)(n);i++)
#define rep3(i,n) for(int i=0;i<=(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
#define repll(i,n) for(ll i=0;i<(ll)(n);i++)
#define repll2(i,n) for(ll i=1;i<=(ll)(n);i++)
#define REPLL(i,m,n) for(ll i=m;i<(ll)(n);i++)
#define INF (int)1e9  //
#define LINF (ll)4e18  //
#define MOD (int)(1e9)+7
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define yes(n) cout << ((n) ? "yes" : "no"  ) << endl
#define PI 3.1415926535898

//------------------------------------------------------

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



Measured memory_bytes: 256
// 未解決

#include <bits/stdc++.h>

#include <iostream>
using namespace std;

#define EACH(i, a) for (auto &&i : a)
#define FOR(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RFOR(i, a, b) for (int i = (int)b - 1; i >= (int)a; --i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FOR(i, 1, int(n) + 1)
#define RREP(i, n) RFOR(i, 0, n)
#define RREPS(i, n) RFOR(i, 1, int(n) + 1)
#define ALL(x) (x).begin(), (x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define debug(x) cout << #x << ": " << x << endl

#define pb push_back
#define mp make_pair
#define F first
#define S second

#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define INF (1L << 30)
#define MOD (1000000007)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

template <class T>
void pv(T a, T b) {
  for (T i = a; i != b; ++i) cout << *i << " ";
  cout << endl;
}
template <class T>
void pvp(T a, T b) {
  for (T i = a; i != b; ++i)
    cout << "(" << i->first << ", " << i->second << ") ";
  cout << endl;
}
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int in() {
  int x;
  scanf("%d", &x);
  return x;
}

using ll = long long;
#define int ll

template <typename Sequence, typename BinaryPredicate>
struct IndexCompareT {
  IndexCompareT(const Sequence &seq, const BinaryPredicate comp)
      : seq_(seq), comp_(comp) {}
  bool operator()(const size_t a, const size_t b) const {
    return comp_(seq_[a], seq_[b]);
  }
  const Sequence seq_;
  const BinaryPredicate comp_;
};

template <typename Sequence, typename BinaryPredicate>
IndexCompareT<Sequence, BinaryPredicate> IndexCompare(
    const Sequence &seq, const BinaryPredicate comp) {
  return IndexCompareT<Sequence, BinaryPredicate>(seq, comp);
}

template <typename Sequence, typename BinaryPredicate>
std::vector<size_t> ArgSort(const Sequence &seq, BinaryPredicate func) {
  std::vector<size_t> index(seq.size());
  for (int i = 0; i < index.size(); i++) index[i] = i;

  std::sort(index.begin(), index.end(), IndexCompare(seq, func));

  return index;
}
//**********

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

  int n;
  cin >> n;
  int a[200010], a_p[200010], a_m[200010];
  REP(i, n) {
    cin >> a[i];
    a_p[i] = (i + 1) + a[i];
    a_m[i] = (i + 1) - a[i];
  }

  int ans = 0;

  sort(a_p, a_p + n);
  sort(a_m, a_m + n);
  // REP(i, 6) { debug(a_p[i]); }

  REP(i, n) {
    int key = a_m[i];
    ans += (upper_bound(a_p, a_p + n, key) - lower_bound(a_p, a_p + n, key));
  }

  cout << ans << endl;
  return 0;
};


Measured memory_bytes: 8364
#include<cstdio>
#include<algorithm>
#include<cstring>
#define ll long long
using namespace std;
int a[10005],x[105][105];
int h,w,n;
int main(){
	scanf("%d%d",&h,&w);
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	int t=1;
	for (int i=1;i<=h;i++){
		if (i%2) {
			for (int j=1;j<=w;j++) {
				if (!a[t]) t++;
				x[i][j]=t,a[t]--;
			}
		}
		else for (int j=w;j>=1;j--) {
				if (!a[t]) t++;
				x[i][j]=t,a[t]--;
			}
	}
	for (int i=1;i<=h;i++){
		for (int j=1;j<=w;j++) printf("%d ",x[i][j]);
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 256