akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int> >;
#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(int i = m; i < (int)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum accumulate
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
typedef long long ll;
const int INF = 2000000000;
const ll INF64 = 9223372036854775806ll;
const int mod = 1000000007ll;
const ll  MOD = 1000000007LL;
/*メモ 
*/
int main(){
    int n;
    std::cin >> n;
    std::vector<int> a;
    a.pb(0);
    rep(i,n){
        int du;
        std::cin >> du;
        a.pb(du);
    }
    n+=2;
    int sum=0;
    rep(i,n-1)sum+=abs(a[i+1]-a[i]);
    rrep(i,1,n-1){
        std::cout << sum-abs(a[i+1]-a[i])-abs(a[i-1]-a[i])+abs(a[i+1]-a[i-1]) << std::endl;
    }
        
}

Measured memory_bytes: 1784
#include <stdio.h>
int main (void){
        int a,b,c,max,middle,little;
        scanf("%d",&a);
        scanf("%d",&b);
        scanf("%d",&c);
        if (a > b){
                max = a;
                little = b;
        } else {
                max = b;
                little = a;
        }
        if (max > c && c > little)
                middle = c;
        else if(max < c) {
                middle = max;
                max = c;
        } else if(little > c){
                middle = little;
                little = c;
        }
        printf("%d %d %d\n",little,middle,max);
        return 0;
}


Measured memory_bytes: 2052
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

type item struct {
	a, b, c, d int
}

var ans int

func f(n, N, M int, a []int, nn []item) {
	if len(a) == N {
		cost := 0
		Q := len(nn)
		// out(a)
		for j := 0; j < Q; j++ {
			f := nn[j].a - 1
			t := nn[j].b - 1
			if a[t]-a[f] == nn[j].c {
				cost += nn[j].d
			}
		}
		// out(cost)
		ans = max(ans, cost)
		return
	}

	for i := n; i <= M; i++ {
		f(i, N, M, append(a, i), nn)
	}
}

func main() {
	sc.Split(bufio.ScanWords)
	N, M, Q := getInt(), getInt(), getInt()
	nn := make([]item, Q)
	for i := 0; i < Q; i++ {
		a, b, c, d := getInt(), getInt(), getInt(), getInt()
		nn[i] = item{a, b, c, d}
	}

	a := make([]int, 0)

	f(1, N, M, a, nn)

	out(ans)
}


Measured memory_bytes: 5876
#include<bits/stdc++.h>
using namespace std;
const int nmax=22;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int d[nmax+2][nmax+2];
char s[nmax+2][nmax+2];
void dfs(int p,int q){
  queue<pair<int,int>> qu;
  for(int i=1;i<=nmax;i++){
    for(int j=1;j<=nmax;j++){
      d[i][j]=-1;
    }
  }
  d[p][q]=0;
  qu.push(make_pair(p,q));
  while(!qu.empty()){
    pair<int,int> r=qu.front();
    qu.pop();
    int u=r.first,v=r.second;
    if(s[u][v]=='#'){
      continue;
    }
    for(int i=0;i<4;i++){
      for(int j=0;j<4;j++){
        int x=u+dx[i],y=v+dy[i];
        if(d[x][y]==-1&&s[x][v]=='.'){
          d[x][y]=d[u][v]+1;
          qu.push(make_pair(x,y));
        }
      }
    }
  }
}
int main(){
  int h,w;cin >> h >> w;
  for(int i=0;i<=h+1;i++){
    for(int j=0;j<=w+1;j++){
      if(i>=1&&i<=h&&j>=1&&j<=w){
        cin >> s[i][j];
      }
      else{
        s[i][j]='#';
      }
    }
  }
  int ans=0;
  for(int i=1;i<=h;i++){
    for(int j=1;j<=w;j++){
      if(s[i][j]=='.'){
        dfs(i,j);
      for(int k=1;k<=h;k++){
        for(int l=1;l<=w;l++){
          if(s[k][l]=='.'){
          ans=max(ans,d[k][l]);
          }
        }
      }
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
int main(){

  int n,a;
  std::cin>>n;

  int Adj[100][100],adj[100][100]={0},find[100][2],back[100][100],depth[100]={0},endflag[100]={0},flag;
	int u[n],k[n],kcou=0,timenow=0,v,pred,prev,firstv,backcount[100]={0},flag1=0;
  for(int i=0;i<n;i++){
    std::cin>>u[i];
    std::cin>>k[i];
    for(int j=0;j<k[i];j++){
      std::cin>>Adj[i][j];
    }
  }
	
	/*
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
    	std::cout<<Adj[i][j]<<" ";
    }
  	std::cout<<"\n";
  }*/
	
	v=0;
	firstv=0;
	while(timenow<n*2){
		flag=0;
		if(find[firstv][0]!=NULL&&find[firstv][1]!=NULL){
			for(int i=0;i<n;i++){
				if(find[i][0]==NULL){
					//std::cout<<i<<"\n";
					firstv=i;
					v=i;
					break;
				}
			}
		}
		
		// std::cout<<"v="<<v+1<<" ";
		//std::cout<<find[v][0]<<" "<<find[v][1];
		// std::cout<<" endflag="<<endflag[v]<<" ";
		if(find[v][0]==NULL){
			timenow++;
			find[v][0]=timenow;
			// std::cout<<v+1<<"[0]= '"<<timenow<<"' ";
			flag=1;
			//std::cout<<flag<<" 1";
		}else if(find[v][1]==NULL){
			if(endflag[v]==1){
				if(backcount[v]<=1){
				timenow++;
				find[v][1]=timenow;
				// std::cout<<v+1<<"[1]= '"<<timenow<<"' ";
				}
				flag=2;
			}
			//std::cout<<flag;
		}else{
			backcount[v]--;
			v=back[v][backcount[v]];
			//backcount[v]--;
			flag=3;
			//std::cout<<flag<<" 0";
		}

		if(flag==0){
				pred=depth[v];
				depth[v]++;
				prev=v;
				v=Adj[v][pred]-1;
				back[v][backcount[v]]=prev;
				backcount[v]++;
				//std::cout<<flag<<"\n";
		}else if(flag==1){
			if(endflag[v]==0){
				if(Adj[v][depth[v]]-1!=v){
					while(find[Adj[v][depth[v]]-1][0]!=NULL && k[v]-1!=depth[v]){
						depth[v]++;
					}
					if(find[Adj[v][depth[v]]-1][0]==NULL){
						pred=depth[v];
						depth[v]++;
						prev=v;
						v=Adj[v][pred]-1;
						back[v][backcount[v]]=prev;
						backcount[v]++;
					}else{
						depth[v]++;
					}
				}else{
					pred=depth[v];
					depth[v]++;
				}
			}
		}else if(flag==2){
			backcount[v]--;
			v=back[v][backcount[v]];
			//backcount[v]--;
			//std::cout<<flag<<"\n";
		}
		if(depth[v]>k[v]-1){
			endflag[v]=1;
		}
		// std::cout<<"flag="<<flag<<"\n";
	}
	
	
	
	
  for(int i=0;i<n;i++){
     std::cout<<i+1<<" "<<find[i][0]<<" ";
     std::cout<<find[i][1]<<"\n";
    //std::cout<<"\n";
  }

  return 0;
}



Measured memory_bytes: 3140
import java.util.*;

public class Main {
    public static void main(String[] args) {
        try (final Scanner sc = new Scanner(System.in)) {
            final String line = sc.nextLine();
            final int players = Integer.parseInt(line.split(" ")[0]);
            final int initScore = Integer.parseInt(line.split(" ")[1]);
            final int rounds = Integer.parseInt(line.split(" ")[2]);
            final int[] scores = new int[players];
            for (int i = 0; i < rounds; i++) {
                final int player = sc.nextInt() - 1;
                scores[player]++;
            }
            for (int playerScore : scores) {
                final String result = initScore - (rounds - playerScore) > 0 ? "Yes" : "No";
                System.out.println(result);
            }
        }
    }
}

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

int main() {
    int N, count = 0;
    cin >> N;
    char pre = 'o';
    while (count < N) {
	char now;
	cin >> now;
	if (pre == 'x' && now == pre) break;
	count++;
	pre = now;
    }

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 3108
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
using namespace std;

#define rep(i,j,n) for(int (i)=(j);(i)<(n);(i)++)
#define rep2(i,j,n) for(int (i)=(j);(i)<=(n);(i)++)
#define all(i) (i).begin(),(i).end()

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef long long i64;

int main() {
	int n;
	cin >> n;
	vector<i64> sum(n + 1, 0);
	rep(i, 0, n) {
		cin >> sum[i + 1];
		sum[i + 1] += sum[i];
	}
	i64 ans = 1e18;
	rep(i, 1, n) {
		ans = min(ans, abs(sum[i] - (sum[n] - sum[i])));
	}
	cout << ans << endl;
}

Measured memory_bytes: 1792
# 2019-11-27 15:57:35(JST)
import sys
from string import ascii_lowercase as alphabet
from bisect import bisect_left as bi_l

index = dict((a, i) for i, a in enumerate(alphabet))

def main():
    s = sys.stdin.readline().rstrip()
    n = len(s)
    used = set(s)
    not_used = sorted(set(alphabet) - used)

    if not_used:
        ans = s +  not_used[0]
    else:
        cand = []
        for i in range(n-1, 0, -1):
            cand.append(s[i])
            if s[i-1] > s[i]:
                continue
            else:
                ans = s[:i-1] + cand[bi_l(cand, s[i-1])]
                break
        else:
            ans = -1
    
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3772
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,M,toshinum;
  cin >> N >> M;
  vector<int> kotae(N);
  
  for (int i = 0; i < 2*M; i++) {
    cin >> toshinum;
    kotae.at(toshinum-1)++;
  }
  
  for (int i = 0; i < N; i++) {
    cout << kotae.at(i) << endl;
  }
}

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

using namespace std;
typedef long long ll;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int h,w;
    cin>>h>>w;

    vector<vector<char>> grid(h,vector<char>(w));

    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++)
            cin>>grid[i][j];
    }

    vector<vector<long>> dp(h,vector<long>(w));
    dp[0][0]=1;
    for(int i=1;i<w;i++){
        if(grid[0][i]=='.'&&dp[0][i-1]==1)
            dp[0][i]=1;
        else
            dp[0][i]=0;
    }
    for(int i=1;i<h;i++){
        if(grid[i][0]=='.'&&dp[i-1][0]==1)
            dp[i][0]=1;
        else
            dp[i][0]=0;
    }
    for(int i=1;i<h;i++){
        for(int j=1;j<w;j++){
            if(grid[i][j]=='.'){
                dp[i][j]=(dp[i-1][j]+dp[i][j-1])%1000000007;
            }
        }
    }
    cout<<dp[h-1][w-1];
    return 0;
}


Measured memory_bytes: 12120
import bisect

N = int(input())
A = sorted(map(int, input().split()))
B = map(int, input().split())
C = sorted(map(int, input().split()))

ans = 0
for second in B:
    ai = bisect.bisect_left(A, second)
    ci = bisect.bisect_right(C, second)

    ans += (ai*(N-ci))

print(ans)

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

int main(void) {
    string S;
    cin >> S;
    int i, T[200010], v[2050] = {0}, num = 0, N = S.size(), digit = 1;
    T[N] = 0;
    for (i = N - 1; i >= 0; --i) {
        num = (num + digit * (S[i] - '0')) % 2019;
        T[i] = num;
        digit = digit * 10 % 2019;
    }
    v[0] = 1;
    for (i = 0; i < N; ++i) {
        v[T[i]]++;
    }
    int ans = 0;
    for (i = 0; i < 2020; ++i) {
        if (v[i] == 0) {
            continue;
        }
        ans += v[i] * (v[i] - 1) / 2;
    }
    printf("%d\n", ans);

    return 0;
}


Measured memory_bytes: 4608
# C - Walk on Multiplication Table
# https://atcoder.jp/contests/abc144/tasks/abc144_c

n = int(input())

ans = 10 ** 12
for i in range(1, 10 ** 6 + 1):
  if n % i == 0:
    ans = min(ans, n // i + i)

print(ans - 2)

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

using namespace std;

typedef long long int ll;
typedef pair<int,int> P;

#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<(b);i++)
#define repr(i,b,a) for(int i=int(b);i>=(a);i--)
#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool valid(int lx,int ux,int ly,int uy,int x,int y){
	return lx<=x&&x<ux&&ly<=y&&y<uy; 
}
ll power(ll x,ll p){
	if(p==0)return 1;
	ll res=power(x*x%mod,p/2);
	if(p%2==1)res=res*x%mod;
	return res;
}

int main()
{
	int n;
	cin>>n;
	vector<double> p(n);
	rep(i,n)cin>>p[i];

	vector<vector<double>> dp(n+1,vector<double>(n+1,0));
	dp[0][0]=1;
	repi(i,1,n+1)dp[i][0]=dp[i-1][0]*(1-p[i-1]);
	repi(i,1,n+1)repi(j,1,n+1){
		if(i<j)continue;

		dp[i][j] = dp[i-1][j]*(1-p[i-1]) + dp[i-1][j-1]*p[i-1];
	}

	double ans=0;
	rep(i,n+1)if(i>n/2)ans+=dp[n][i];

	cout<<setprecision(15)<<ans<<endl;

	return 0;
}

Measured memory_bytes: 73680
//A.cpp
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <math.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b!=0?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
const ll mod=1e9+7;

int main(){
  int n;
  cin >> n;
  vector<pair<ll,ll>> a;
  map<ll,ll> map;
  int cnt = 0;
  rep(i,n){
    int c,d;
    cin >> c >> d;
    if(map[d] == 0) cnt++;
    map[d] += c;
  }

  for(auto x: map){
    a.push_back(make_pair(x.first,x.second));
  }

  sort(a.begin(),a.end());

  ll time = 0;
  rep(i,cnt){
    if(time + a[i].second > a[i].first){
      printf("No\n");
      return 0;
    }else{
      time += a[i].second;
    }
  }

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


Measured memory_bytes: 18800
#[allow(unused_imports)]
use std::{cmp::Reverse, collections::*};

#[allow(unused_imports)]
use proconio::{fastout, input, marker::Chars};

#[allow(unused_imports)]
use itertools::Itertools;

#[allow(unused_imports)]
use num::Integer;

#[fastout]
pub fn main() {
    input! {
        x1: i32, x2: i32, x3: i32, x4: i32, x5: i32
    }
    if x1 == 0 {
        println!("1");
    }
    if x2 == 0 {
        println!("2");
    }
    if x3 == 0 {
        println!("3");
    }
    if x4 == 0 {
        println!("4");
    }
    if x5 == 0 {
        println!("5");
    }
}


Measured memory_bytes: 2120
#include<stdio.h>
#include<math.h>
int main()
{
    int n,d,i,x,y,c=0;
    double sum=0;
    scanf("%d %d",&n,&d);
    for(i=0;i<n;i++)
    {
        double root=0;
        scanf("%d %d",&x,&y);
        sum=((double)x*(double)x+(double)y*(double)y);
        root=sqrt(sum);
        if(root<=d)
        {
            c++;
        }
    }
    printf("%d\n",c);
    return 0;
}


Measured memory_bytes: 2152
using System;
using System.Collections.Generic;
using System.Linq;


namespace AtC
{
    class Program
    {
        static void Main(string[] args)
        {
            var abt = ReadIntArray();
            int A = abt[0], B = abt[1], T = abt[2];
            Out((int) ((int) ((T + .5) / A) * B));
        }

        static int[] ReadIntArray()
        {
            return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        }

        static int ReadInt()
        {
            return int.Parse(Console.ReadLine());
        }

        static long[] ReadLongArray()
        {
            return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
        }

        static long ReadLong()
        {
            return long.Parse(Console.ReadLine());
        }

        static string ReadString()
        {
            return Console.ReadLine();
        }

        static void Out(object o)
        {
            Console.WriteLine(o);
        }
    }

    static class EnumerableExtension
    {
        public delegate void Function<in T>(T val);

        public static void ForEach<T>(this IEnumerable<T> enumerable, Function<T> function)
        {
            foreach (var x in enumerable)
            {
                function(x);
            }
        }
    }
}

Measured memory_bytes: 13268
N=int(input())
s=input()
R=s.count("R")
G=s.count("G")
B=s.count("B")
ans=R*G*B
 
#全探索する
for i in range(N-2):
  a=s[i]
  for j in range(i+1,N-1):
    if a==s[j]:
      continue
    b=s[j]
    k=2*j-i
    if k>=N:
      continue
    if s[k]!=a and s[k]!=b:
      ans-=1
print(ans)


Measured memory_bytes: 9136
import java.util.Scanner;

public class Main {
	void run() {
		Scanner sc = new Scanner(System.in);
		
		int[] a = new int[101];
		while (sc.hasNext()) {
			a[sc.nextInt()]++;
		}
		
		int max = 1;
		for (int i = 1; i < 101; i++) {
			if (max < a[i]) {
				max = a[i];
			}
		}
		
		for (int i = 1; i < 101; i++) {
			if (a[i] == max) {
				System.out.println(i);
			}
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

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

using namespace std;

#define fi first
#define se second

#define pb push_back
#define sz(x) ((int)(x).size())

typedef long long ll;
typedef long double ld;

const int base = 1000 * 1000 * 1000;

const int N = (int)2e5 + 2;
const int INF = (int)1e9 + 7;

const ld pi = acos(-1);
const ll linf = (ll)1e18;

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

int n, a[N], x, y, used[N];
int main(){
    scanf ("%d %d %d", &n, &x, &y);
    for (int i = 1; i <= n; ++i){
        scanf ("%d", a + i);
    }
    sort (a + 1, a + n + 1);
    int ans = 0;
    for (int i = 1; i <= n; ++i){
        for (int j = i + 1; j <= n; ++j){
            for (int k = j + 1; k <= n; ++k){
                if (a[i] <= x && a[j] >= x + 1 && a[j] <= y && a[k] >= y + 1 && !used[i] && !used[j] && !used[k]){
                    ans++;
                    used[i] = 1;
                    used[j] = 1;
                    used[k] = 1;
                }
            }
        }
    }
    printf ("%d\n", ans);
    return 0;
}


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

#define ll long long
#define ld long double
#define COIN const int
#define ite iterator
#define PII pair<int,int>
#define PSI pair<string,int>
#define PIS pair<int,string>

#define REP(i,n) for((i)=0;(i)<(int)(n);(i)++)
#define REPD(i,n) for((i)=(n)-1;(i)>=0;(i)--)

#define ALL(c) (c).begin(), (c).end()
#define sz(s) (s).size()
#define CLEAR(x) memset(x,0,sizeof x);

#define MP make_pair
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define X first
#define Y second

#define VI vector<int>
#define VS vector<string>
#define VII vector<PII>
#define VVI vector<VI>

#define PIII 3.1415926
#define PI 3.14
/*****************************************************************************/
const ll mod=1e9+7;
const ll INF=1e18;
/*****************************************************************************/

using namespace std;

int main()
{
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ll a,b,c,k,i,ans=0; cin >>a >>b >>c >>k;
	ans=a; k-=a;
	if (k<=0) {
		ans+=k;
		cout <<ans;
		return 0;
	}
	k-=b;
	if (k<=0) {
		cout <<ans;
		return 0;
	}
	ans-=k;
	cout <<ans;
	return 0;
}
/******************************************************************************
******************************************************************************/


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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int N, u, v;
vector <int> Graph[int(1e5+5)];
int U[int(1e5+5)], V[int(1e5+5)];

int Solve(){
  fill(U, U + N + 1, -1);
  U[u] = 0;
  queue <int> que; que.push(u);
  while(!que.empty()){
    int Q = que.front(); que.pop();
    for (int next:Graph[Q]){
      if (U[next] != -1) continue;
      U[next] = U[Q] + 1;
      que.push(next);
    }
  }

  fill(V, V + N + 1, -1);
  que.push(v); V[v] = 0;
  while (!que.empty()){
    int Q = que.front(); que.pop();
    for (int next:Graph[Q]){
      if (V[next] != -1) continue;
      V[next] = V[Q] + 1;
      que.push(next);
    }
  }

  return 0;
}

int main(){
  cin >> N >> u >> v;
  for (int i = 0; i < N-1; i++){
    int A, B; cin >> A >> B;
    Graph[A].push_back(B);
    Graph[B].push_back(A);
  }
  Solve();

  int ans = 0;
  for (int i = 1; i <= N; i++){
    if (U[i] <= V[i]) ans = max(ans, V[i] - 1);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 10048
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
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;
}

using ll = long long;
using ull = unsigned long long;
const int INF = 2100100100;
// const int MOD = 1e9 + 7;
using P = pair<int, int>;
int main() {
    int N, Ma, Mb;
    cin >> N >> Ma >> Mb;
    vector<int> a(N), b(N), c(N);
    for (int i = 0; i < N; i++) {
        cin >> a.at(i) >> b.at(i) >> c.at(i);
    }

    vector<P> A;
    for (int bit = 0; bit < (1 << (N / 2)); bit++) {
        int ma = 0;
        int mb = 0;
        int sum = 0;
        for (int i = 0; i < (N / 2); i++) {
            int mask = 1 << i;
            if (bit & mask) {
                ma += a[i];
                mb += b[i];
                sum += c[i];
            }
        }
        A.push_back(P(Ma * mb - ma * Mb, sum));
    }
    sort(A.begin(), A.end());

    int ans = INF;
    for (int bit = 0; bit < (1 << (N - N / 2)); bit++) {
        int ma = 0;
        int mb = 0;
        int sum = 0;
        for (int i = 0; i < (N - N / 2); i++) {
            int mask = 1 << i;
            if (bit & mask) {
                ma += a[i + N / 2];
                mb += b[i + N / 2];
                sum += c[i + N / 2];
            }
        }
        int C = ma * Mb - Ma * mb;

        auto it = lower_bound(ALL(A), P(C, 0));
        int l = it - A.begin();
        int num = upper_bound(ALL(A), P(C, INF)) - it;
        /*
        debug(l);
        debug(num);
        debug(ma);
        debug(mb);
        debug(sum);
        */
        for (int i = l; i < l + num; i++) {
            if (A[i].second + sum == 0) continue;
            chmin(ans, A[i].second + sum);
            break;
        }
    }
    if (ans == INF) {
        cout << -1 << endl;
    } else {
        cout << ans << endl;
    }
}


Measured memory_bytes: 10092
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoderContest
{
    class Program
    {
        static void Main()
        {
            Console.ReadLine();
            var ln = Console.ReadLine().Split(" ")
                            .Select(int.Parse)
                            .ToArray();

            var combiantions = EnumerateTrioCombinations(ln);
            var answer = combiantions.Count(TriangleCondition);
            Console.WriteLine(answer);
        }

        private static IEnumerable<(int, int, int)> EnumerateTrioCombinations(int[] ln)
        {
            var length = ln.Length;
            for (var i = 0; i < length - 2; i++)
            {
                for (var j = i + 1; j < length - 1; j++)
                {
                    for (var k = j + 1; k < length; k++)
                    {
                        yield return (ln[i], ln[j], ln[k]);
                    }
                }
            }
        }

        private static bool TriangleCondition((int, int, int) sides)
        {
            (var a, var b, var c) = sides;

            if (a == b || a == c || b == c)
            {
                return false;
            }

            if (a + b > c && b + c > a && a + c > b)
            {
                return true;
            }

            return false;
        }
    }
}


Measured memory_bytes: 28160
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5+1e3;
int h[N],dp[N];
int main(){
    int n,k; cin >> n >> k;
    for(int i = 1; i <= n; i++)cin >> h[i];
    for(int i = 0; i <= n; i++)dp[i] = 1e9;
    dp[1] = 0;
    for(int i = 2; i <= n; i++){
        for(int j = max(1,i-k); j < i; j++){
            dp[i] = min(dp[i],abs(h[j]-h[i])+dp[j]);
        }
    }
    cout << dp[n];
}


Measured memory_bytes: 4380
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <list>
#include <string>
#include <numeric>
#include <math.h>
#include <set>
#include <map>
#include <functional>
#include <fstream>
#include <complex>
using namespace std;

int main()
{
	int N;
	cin>>N;
	vector<string> s(N);
	int start_a = 0;
	int end_b = 0;
	int ab = 0;

	int sum = 0;

	

	for(int i=0; i<N; i++)
	{
		cin>>s[i];

		int s_size = s[i].size();
		for(int j=0; j<s_size-1; j++)
		{
			if(s[i][j] == 'A' && s[i][j+1] == 'B')
			{
				sum++;
			}
		}

		if(s[i][0] == 'B' && s[i][s_size-1] == 'A')
		{
			ab++;
		}
		else if(s[i][0] == 'B')
		{
			start_a++;
		}
		else if(s[i][s_size-1] == 'A')
		{
			end_b++;
		}
	}

	int pair1 = min(start_a,end_b);
	sum += pair1;
	start_a -= pair1;
	end_b -= pair1;
	
	int remain = max(start_a,end_b);
	int pair2 = min(remain,ab);

	remain -= pair2;
	ab -= pair2;

	sum+=pair2;


	if(pair1 > 0 || pair2 >0)
	{
		sum += ab;
	}
	else
	{
		sum += max(0,(ab-1));
	}

	cout<<sum<<endl;
	
	return 0;
}

Measured memory_bytes: 768
A, B, C, X, Y = gets.split.map(&:to_i)

if C * 2 <= A || C * 2 <= B then
  if X >= Y && C * 2 <= A then
    ans = (X * 2) * C
  elsif Y >= X && C * 2 <= B then
    ans = (Y * 2) * C
  elsif Y >= X && C * 2 <= A then
    tmp = (X * 2) * C
    ans = tmp + (Y - X) * B
  elsif X >= Y && C * 2 <= B then
    tmp = (Y * 2) * C
    ans = tmp + (X - Y) * A
  end
elsif (A + B) / 2 >= C then
  if X >= Y then
    tmp = C * (Y * 2)
    ans = tmp + A * (X - Y)
  elsif Y >= X then
    tmp = C * (X * 2)
    ans = tmp + B * (Y - X)
  end
else
  ans = A * X + B * Y
end

puts ans


Measured memory_bytes: 1788
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
// #include "prettyprint.hpp"

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

  int next[N];
  map<int, int> nextPos;
  for (int i = N - 1; i >= 0; i--) {
    if (nextPos.find(A[i]) != nextPos.end()) {
      next[i] = nextPos[A[i]];
      nextPos[A[i]] = i;
    } else {
      next[i] = -1;  // last
      nextPos[A[i]] = i;
    }
  }

  // cout << "next:" << endl;
  // for (int i = 0; i < N; i++) //cout << next[i] << " ";
  // cout << "" << endl;

  map<int, int> nextNum;
  int first = 0;
  while (first < N && next[first] != -1) {
    first = next[first] + 1;
    // cout << "first: " << first << endl;
  }
  nextNum[0] = (first < N) ? A[first] : 0;

  for (int i = 0; i < N; i++) {
    if (nextNum.find(A[i]) != nextNum.end()) continue;

    // cout << "i: " << i << endl;
    int j = i + 1;
    // cout << "j: " << j << endl;

    while (j < N && next[j] != -1) {
      j = next[j] + 1;
    }
    // cout << "final j: " << j << endl;

    if (j < N) {
      nextNum[A[i]] = A[j];
    } else {
      nextNum[A[i]] = 0;
    }
  }

  // cout << "nextNum: " << nextNum << endl;
  vector<int> loop;
  int current = 0;
  loop.push_back(current);
  while (nextNum[current] != 0) {
    current = nextNum[current];
    loop.push_back(current);
  }

  // cout << loop << endl;

  int index = (K - 1) % loop.size();
  int startNum = loop[index];
  // cout << "startNum: " << startNum << endl;
  bool started = (startNum == 0) ? true : false;
  int i = 0;
  while (i < N) {
    if (!started) {
      if (A[i] == startNum) {
        started = true;
      }
      i++;
    } else {
      // cout << "started, i:" << i << endl;
      if (next[i] == -1) {
        cout << A[i] << " ";
        i++;
      } else {
        i = next[i] + 1;
      }
    }
  }

  cout << endl;

  return 0;
}

Measured memory_bytes: 22776
H,W,K = map(int, input().split())
fields = []
for i in range(H):
    rows = list(map(int,list(input())))
    fields.append(rows)

Acum = [[0] * (W+1) for i in range(H+1)]
for i in range(H):
    for j in range(W):
        Acum[i+1][j+1] = Acum[i][j+1] + Acum[i+1][j] - Acum[i][j] + fields[i][j]
"""
# 実験
h1,h2,w1,w2 = 1,3,1,5 #(1,1)->(2,3)までの累積和
ans = Acum[h2][w2] - Acum[h1][w2] - Acum[h2][w1] + Acum[h1][w1]
print("aaa",ans)
for i in range(H+1):
    print(Acum[i])
"""
# 縦方向は区切り方が2**(H-1)通りを全探索
# 横方向に区切りながらすすめていく(なるべく大きくとっていく)
ans = 10**10
for i in range(2**(H-1)):
    # print("XXXXXXXXXXXXXXXXXXXXXX")
    s = bin(i)[2:]
    s_zero = s.zfill(H-1)
    # print(s_zero)
    # 横区切り線の位置
    a = [0]+[i+1 for i,s in enumerate(s_zero) if int(s) == 1]
    a += [H]
    # 縦区切り線の位置
    w_cnt = 0
    w1 = 0
    w = 1
    m = 0
    while w <= W:
        m = 0
        for j in range(1,len(a)):
            h1 = a[j-1]
            h2 = a[j]
            cnt = Acum[h2][w] - Acum[h1][w] - Acum[h2][w1] + Acum[h1][w1]
            # print(h1,w1,h2,w,cnt)
            m = max(m,cnt)
        if m > K:
            if w - 1 == w１:
                w_cnt = 10**10
                break
            w_cnt += 1
            w1 = w -1         
        w += 1
    # print(s_zero,a,sum(map(int,list(s))),w_cnt)
    ans = min(ans,sum(map(int,list(s)))+w_cnt)
print(ans)


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

using namespace std;
using ll = long long;
const ll INF = 1 << 30;

int lwns(){
    ll n, W;
    cin >> n >> W;
    vector<ll> w(n+1), v(n+1);
    for(int i = 0; i < n; i++) {
        cin >> w.at(i) >> v.at(i);
    }

    vector<vector<ll> > lwnsdp(n+1,vector<ll>(1000*n + 11,INF));
    lwnsdp.at(0).at(0) = 0;
    for(int i = 0; i < n; i++) {
        for(int j = 0; j <= 1000*n + 10; j++) {
            if (v.at(i) > j)
            {
                lwnsdp.at(i+1).at(j) = min(lwnsdp.at(i).at(j),w.at(i));
            }
            else
            {
                lwnsdp.at(i+1).at(j) = min(lwnsdp.at(i).at(j),lwnsdp.at(i).at(j - v.at(i))+w.at(i));
            }
            
        }
    }
    
    int ans = 0;
    for(int i = 1000*n + 10; i >= 0; i--) {
        if(lwnsdp.at(n).at(i) <= W) {
            return i;
        }
    }
    return ans;


}

int main() {
    cout << lwns() << endl;

    return 0;
}

Measured memory_bytes: 83236
#include<iostream>
#include<algorithm>
using namespace std;main(){int i,n,k,h[9<<14],m=1e9,x;cin>>n>>k;for(i=n;i--;)cin>>h[i];sort(h,h+n);for(i=n-k+1;i--;m=m>x?x:m)x=h[i+k-1]-h[i];cout<<m;}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef pair<ll, ll> P;

const int mod =  1000000007;  //出力は (ans % mod + mod) % mod  (負の剰余を正にする)
const int inf = 1e9;
const long long INF = 1LL << 60;   // INF = 11

int main()
{
    ll d,t,s; cin >> d >> t >> s;
    if(d <= t*s){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()
template <class T> inline bool chmin(T &a, T b) {if (a > b){a = b;return true;}return false;}
template <class T> inline bool chmax(T &a, T b) {if (a < b){a = b;return true;}return false;}

template <typename T> string toString(const T& input) { ostringstream oss; oss << input; return oss.str(); }

// vector<string> candidate;
vector<int> candidate;
set<int> likes = {1,2,3,4,5,6,7,8,9,0};
int n,k;

int digsize(int t){
    return(toString(t).size());
}

void dfs(string str){
    if(str.size() == digsize(n)){
        if(str[0] != '0')
            candidate.push_back(stoi(str));
    }
    if(str.size() == digsize(n)+1){
        if(str[0] != '0')
            candidate.push_back(stoi(str));
        return;
    }
    for(auto a : likes){
        dfs(str + toString(a));
    }
    return;
}


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin>>n>>k;
    vector<int> d(n);
    rep(i, k) {
        int t; cin>>t;
        likes.erase(t);
    }

    dfs("");
    sort(all(candidate));
    for(auto a : candidate){
        if(a >= n){
            cout<<a<<endl;
            break;
        }
    }
    return 0;
}

// arc058_a

Measured memory_bytes: 892
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>

using ll = long long;

int main(){
    ll n;
    std::cin >> n;
    std::vector<ll> xAy(n), xMy(n);
    for(int i = 0; i < n; i++){
        ll x, y;
        std::cin >> x >> y;
        xAy[i] = x + y;
        xMy[i] = x - y;
    }

    std::sort(xAy.begin(), xAy.end());
    std::sort(xMy.begin(), xMy.end());
    std::cout << std::max(xAy[n - 1] - xAy[0], xMy[n - 1] - xMy[0]) << std::endl;
    return 0;
}


Measured memory_bytes: 6420
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long x, y, z;
    cin >> x >> y >> z;
    long long c = 0;
    x -= z;
    while (x >= y+z) {
        c++;
        x -= (y+z);
    }
    cout << c << endl;
    return 0;   
}




Measured memory_bytes: 256
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())


N,K,Q = MI()

X = [0]*(N+1)  # 各参加者の正解数
for _ in range(Q):
    a = I()
    X[a] += 1

for i in range(1,N+1):
    x = X[i]
    print('Yes' if K-(Q-x) > 0 else 'No')


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

using namespace std;
#define BUF (100005)
#define ll long long 

ll n;
ll m;
static ll N;
ll p[BUF]; //parentp
ll d[BUF]; //depth
ll g[BUF]; //number of node
ll ans[BUF];

void uf_init(ll n){
	N=n;
	for(ll i=1;i<=n;i++) p[i]=i,d[i]=0, g[i]=1;
}

ll find(ll x){
	if(p[x]==x) return x;
	else{
		p[x] = find(p[x]);
		return p[x];
	}
}

ll get_group_num(ll x){
	x = find(x);
	return g[x];
}

void unite(ll x, ll y){
	x=find(x);
	y=find(y);

	if(x==y)return;

	if(d[x]<d[y]){
		p[x]=y;
		g[y] += g[x];
	}else if(d[x]>d[y]){
		p[y]=x;
		g[x] += g[y];
	}else{
		p[y]=x;
		g[x] += g[y];
		d[x]++;
	}
}

bool same(ll x, ll y){
	return find(x)==find(y);
}

pair<ll,ll> v[BUF];

int main(void){
	cin >> n >> m;
	for(ll i=1;i<=m;i++){
		pair<ll,ll> tmp;
		cin >> tmp.first >> tmp.second;
		v[i] = tmp;
	}

	ans[m] = n*(n-1)/2;
	uf_init(n);
	for(ll i=m;i>0;i--)
	{
		ll tmp;
		if(same(v[i].first, v[i].second)){
			tmp = 0;
		}else{
			tmp = get_group_num(v[i].first) * get_group_num(v[i].second);
			unite(v[i].first, v[i].second);
		}

		ans[i-1] = ans[i]-tmp;
	}
	for(ll i=1;i<=m;i++) cout << ans[i] << "\r\n";
	
	return 0;
}


Measured memory_bytes: 6144
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline

##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)

##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順

# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))

def main():
	S = input()
	S = S[:-1]

	flg = True

	for i in range(0,len(S),2):
		if S[i] == "R" or S[i] == "U" or S[i] == "D":
			continue
		else:
			print("No")
			sys.exit()

	for i in range(1,len(S),2):
		if S[i] == "L" or S[i] == "U" or S[i] == "D":
			continue
		else:
			print("No")
			sys.exit()

	print("Yes")



if __name__ == "__main__":
	main()


Measured memory_bytes: 38384
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC081_B
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            int[] array = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

            bool is_exit = false;
            int count = 0;
            while (!is_exit)
            {
                for (int i = 0; i < N; i++)
                {
                    if (array[i] % 2 != 0)
                    {
                        is_exit = true;
                        break;
                    }
                    array[i] /= 2;
                }
                if (!is_exit)
                {
                    count++;
                }
            }

            Console.WriteLine(count);
        }
    }
}


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

int main() {
    long long x, y, z;
    cin >> x;
    y = x / 11LL;
    z = x % 11LL;
    if (z == 0) {
        cout << 2 * y << endl;
    }else if (z <= 6){
        cout << 2 * y + 1 << endl;
    }else{
        cout << 2 * y + 2 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second

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

const ll INF = 1e9;
const ll MOD = 1e9 + 7;
const double EPS = 1e-8;

template<typename T> T chmax(T& a, const T& b){return a = (a > b ? a : b);}
template<typename T> T chmin(T& a, const T& b){return a = (a < b ? a : b);}

int main(){
    int h, w;
    cin >> h >> w;
    int n;
    cin >> n;
    vi a(n);
    rep(i, n) cin >> a[i];
    vector<vi> ans(h, vi(w));
    vector<int> y(h*w);
    vector<int> x(h*w);
    {
        int cur = 0;
        rep(i, h) {
            if(i&1) repr(j, w) {y[cur] = i; x[cur] = j; ++cur;}
            else rep(j, w) {y[cur] = i; x[cur] = j; ++cur;}
        }
    }
    int cur = 0;
    rep(i, n) rep(j, a[i]) {
        ans[y[cur]][x[cur]] = i+1;
        ++cur;
    }
    rep(i, h) rep(j, w) {
        cout << ans[i][j] << (j+1 == w ? '\n' : ' ');
    }
    return 0;
}

Measured memory_bytes: 384
/* ex3_2
  terakura */

#include <stdio.h>

int main(void){

  int n;
  scanf("%d", &n);

//10で割った余りで分類
  if(n % 10 == 3 ){
    printf("bon\n"); //10で割った余りが３の時”bon”

  }else if(n % 10 == 0 || n % 10 == 1 || n % 10 == 6 || n % 10 == 8){
    printf("pon\n"); //10で割った余りが0,1,6,8の時”pon”

  }else{
    printf("hon\n"); //10で割った余りが0,1,6,8の時”pon”
  }

  return 0;
}


Measured memory_bytes: 1660
n, m, x = map(int, input().split())
c = []
a = []
for i in range(n):
  inp = list(map(int, input().split()))
  c_, a_ = inp[0], inp[1:]
  c.append(c_)
  a.append(a_)

ans = float('inf')
for bit in range(1<<n):
  cost = 0
  skill = [0]*m
  for i in range(n):
    if bit & 1<<i:
      cost += c[i]
      for j in range(m):
        skill[j] += a[i][j]
  if min(skill) >= x:
    ans = min(ans, cost)

if ans == float('inf'):
  print(-1)
else:
  print(ans)

Measured memory_bytes: 9236
N = int(input())
#A = [int(x) for x in input().split()]
A = list(map(int, input().split()))
mod = 10**9+7

partial_sum = A.copy()
sum_now = A[N-1]
for j in range(N-2,-1,-1):
    sum_now = int((sum_now+A[j])%mod)
    partial_sum[j] = sum_now
res = 0
for i in range(N-1):
    res = (res + (A[i]*partial_sum[i+1])%mod) %mod
print(int(res))


Measured memory_bytes: 31440
#define IO std::ios::sync_with_stdio(false);
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,k;
int main(){
	IO;
	cin>>n>>k;
	int h=0;
	for(int i=1;i<=n;i+=2){
		h++;
	}
	if(k<=h)cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N=1e7+5;
bool jay;
int l,r,n,m,opt,x;
int a[N];
char str[N];
int main()
{
	scanf("%s",str+1);
	l=1e6+1; r=1e6;
	n=strlen(str+1);
	for (register int i=1; i<=n; ++i)
	{
		r++;
		a[r]=str[i]-'a';
	}
	int jay=1;
	scanf("%d",&m);
	while (m--)
	{
		scanf("%d",&opt);
		if (opt==1) jay^=1;
		else
		{
			scanf("%d",&x);
			char ch;
			cin>>ch; 
			if (jay)
			{
				if (x==1) l--,a[l]=ch-'a';
				else r++,a[r]=ch-'a';
			}
			else
			{
				if (x==1) r++,a[r]=ch-'a';
				else l--,a[l]=ch-'a';
			}
		}
	}
	if (jay) for (register int i=l; i<=r; ++i) putchar((char)a[i]+'a');
	else for (register int i=r; i>=l; --i) putchar((char)a[i]+'a');
	return 0;
}
/////

Measured memory_bytes: 4736
pr = Array.new(1000000,1)
(2..1000).each{|i|
	next if pr[i] == 0
	j = i * i
	while j < 1000000
		pr[j] = 0
		j += i
	end
}
pr[0] = pr[1] = 0
(2..1000000).each{|i|
	pr[i] = pr[i] == 1 ? pr[i-1]+1 : pr[i-1]
}
while gets
	p pr[$_.to_i]
end

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

using namespace std;

int main()
{
    int n, m, t;
    cin >> n >> m >> t;
    vector<int> v;
    for (int i = 0; i < n; ++i) {
        int a;
        cin >> a;
        v.push_back(a);
    }

    int count = 0;
    count += v[0] - m;
    for (int i = 0; i < n - 1; ++i) {
        if (v[i + 1] - v[i] > 2 * m) {
            count += v[i + 1] - v[i] - 2 * m;
        }
    }
    count += max(t - v.back() - m, 0);
    cout << count << endl;
}


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

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader input =new BufferedReader (new InputStreamReader (System.in));
		String str = input.readLine( );
		String[] list = str.split(" ");
		int start = Integer.parseInt(list[0]);
		int end = Integer.parseInt(list[1]);
		int answer = start + end;
		if(start+end >=24){
			answer = answer - 24;
		}
		System.out.println(answer);

	}

}


Measured memory_bytes: 21332
#include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < n; ++i)
#define FOR(i, b, n) for (ll i = b; i < n; ++i)

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

void solve(ll N) {
  cout << N * 180 - 360 << endl;
}

int main(){
  // int 3E4  long 2E9  ll 9E18
  cin.tie(0);
  ios::sync_with_stdio(false);

  ll N;
  cin >> N;

  solve(N);

  return 0;
}


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

int func(int x ,int y){
  if( y == 0 ) return x;
  return func(y,x%y);
}

int main() {
  int64_t a,b;
  cin >> a >> b;
  int64_t g; //最大公約数
  if( a > b ){
    g = func(a,b);
  }else{
    g = func(b,a);
  }
  cout << (a*b)/g << endl;
  
  return 0;
  
}

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

int main(){
	double r;
	cin >> r;
	double area,cf,pai = 3.14159265358979;
	area = r*r*pai;
	cf = 2*r*pai;
	cout << fixed << setprecision(6) << area <<" " << cf << endl;

}


Measured memory_bytes: 3264
a,b=map(int,input().split())

n = int((a/0.08)//1)
ans = -1

for i in range(n,n+10**2):
  if int((i*0.08)//1) == a and int((i*0.1)//1) == b:
    ans = i
    break
  else:
    continue

print(ans)

Measured memory_bytes: 38384
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int inf = 1001001001;

int main(){
    int x, n;
    cin >> x >> n;
    
    vector<int> a(102);
    for(int i = 0; i <= 101; i++) a.at(i) = i;
    for(int i = 0; i < n; i++) {
        int p; cin >> p;
        a.at(p) = 0;
    }
    
    int m = inf;
    for(int i = 0; i <= 101; i++) {
        m = min(m, abs(x-a.at(i)));
    }
    
    int ans1 = x + m;
    int ans2 = x - m;
    
    for(int i = 0; i <= 101; i++) {
        if(a.at(i) == ans1) {
            cout << ans1 << endl;
            break;
        }
        if(a.at(i) == ans2) {
            cout << ans2 << endl;
            break;
        }
    }
    
    
    
    
}


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

using namespace std;

int main()
{
	string str;
	int N;
	cin >> str;
	cin >> N;
	bool change = false;
	for (int i = 0; i < str.size() - 1; i++)
	{
		char ch = str[i] - 'a';
		if (26 - (int)ch <= N && ch != 0)
		{
			int toChange = 26 - (int)ch;
			change = true;
			str[i] = 'a';
			N -= toChange;
		}
	}
	str[str.size() - 1] = (((str[str.size() - 1] - 'a') + N) % 26) + 'a';
	cout << str << endl;
	return 0;
}

Measured memory_bytes: 640
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int W = sc.nextInt();
        int H = sc.nextInt();
        int x = sc.nextInt();
        int y = sc.nextInt();
        int r = sc.nextInt();
        if (x - r < 0 || x + r > W || y - r < 0 || y + r > H){
            System.out.println("No");
        }else{
            System.out.println("Yes");
        }
    }
}


Measured memory_bytes: 26316
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
int main(int argc, char const *argv[])
{
	int a[3],k;
	cin>>a[0]>>a[1]>>a[2]>>k;
	sort(a,a + 3);
	int ret = a[2];
	for(int i = 0;i < k; ++i)
	{
		ret *= 2;
	}
	printf("%d\n",a[0] + a[1] + ret);
	return 0;
}

Measured memory_bytes: 256
#include <utility>
#include <stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#define REP(i, n) for (signed long long i = 0; i < (n); i++)
#define YES(b) std::cout<< ((bool)b ? "Yes" : "No")
using namespace std;
int main() {
	int n, m, c;
	int64_t k;
	cin >> n >> m >> c >> k;
	if (k % 2 == 0) {
		cout << n - m;
		return 0;
	}
	cout << m - n;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
 
public class Main{
	public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int k = sc.nextInt();
        int[] a = new int[n];
        for(int i = 0; i < n; i++){
            a[i] = sc.nextInt();
        }

        Arrays.sort(a);
        int ans = 0;
        for(int i = 0; i < k; i++){
            ans += a[i];
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 38884
n, m = map(int, input().split())

class UnionFind:
    def __init__(self, n):
        self.pare = [-1] * n
        self.size = [1] * n
    def root(self, x):
        if self.pare[x] < 0:
            return x
        r = self.root(self.pare[x])
        self.pare[x] = r
        return r
    def unite(self, x, y):
        rx = self.root(x)
        ry = self.root(y)
        if rx == ry:
            return
        self.pare[rx] = ry
        self.size[ry] += self.size[rx]
        return

uf = UnionFind(n)

for i in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    uf.unite(a, b)

print(max(uf.size))

Measured memory_bytes: 83236