akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

#define MAX 305
typedef long long ll;

vector<pair<ll, ll>> adj[MAX];
vector<int> nadj[MAX];
vector<vector<int>> res(MAX, vector<int>(MAX, 500));

void dfs(int st, int n){
    queue<int> qu;
    qu.push(st);
    res[st][st] = 0;
    vector<bool> vis(n, false);
    vis[st] = true;
    while(!qu.empty()){
        auto nd = qu.front();
        qu.pop();
        for(int nei : nadj[nd])
            if( !vis[nei] )
                qu.push(nei), res[st][nei] = res[st][nd]+1, vis[nei] = true;
    }
}
int main(){

    int n, m, l;
    cin >> n >> m >> l;
    ll a, b, c;
    vector<vector<ll>> dp(n, vector<ll>(n, 1e16));
    for(int i = 0; i < m; i++){
        cin >> a >> b >> c;
        a--, b--;
        dp[a][b] = c;
        dp[b][a] = c;
    }

    for(int i = 0; i < n; i++)
        dp[i][i] = 0;

    for(int k = 0; k < n; k++)
        for(int i = 0; i < n; i++)
            for(int j = 0; j < n; j++)
                if( dp[i][k] + dp[k][j] < dp[i][j] )
                    dp[i][j] = dp[i][k] + dp[k][j];

    for(int i = 0; i < n; i++)
        for(int j = 0; j < n; j++)
            if(dp[i][j] <= l)
                nadj[i].push_back(j), nadj[j].push_back(i);


    for(int i = 0; i < n; i++)
        dfs(i, n);

    int q;
    cin >> q;
    while(q--){
        cin >> a >> b;
        a--, b--;
        if( res[a][b] == 500 )
            cout << -1 << endl;
        else
            cout << res[a][b]-1 << endl;

    }
    return 0;
}

Measured memory_bytes: 2816
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sn = new Scanner(System.in);
    
    int cnt = 0;
    String str = null;
    str = sn.nextLine();
    
    char[] c = str.toCharArray();
    
    if(c[2] == c[3]) {
      cnt++;
    } else {
      System.out.print("No");
      return;
    }
       
    if(c[4] == c[5]) {
      cnt++;
    } else {
      System.out.print("No");
      return;
    }
    
    if(cnt == 2) {
		System.out.print("Yes");
    }
  }
}

Measured memory_bytes: 23124
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import (division, absolute_import, print_function,
                        unicode_literals)
from sys import stdin

for line in stdin:
    s = a = float(line)
    for i in xrange(2, 11):
        if i % 2 == 0:
            a *= 2.0
        else:
            a /= 3.0
        s += a
    print(s)

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

using namespace std;
using ll = long long;

int N, W;

ll dp[105][100005];
ll w[105], v[105];

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

    cin>>N>>W;
    for(int i=0;i<N;i++){
        cin>>w[i]>>v[i];
    }
    memset(dp, -1, sizeof(dp));

    dp[0][0] = 0;
    dp[0][w[0]] = v[0];
    for(int i=1;i<N;i++){
        for(int j=0;j<=W;j++){
            dp[i][j] = max(dp[i][j], dp[i-1][j]);
            if(j-w[i]>=0 && dp[i-1][j-w[i]] != -1){
                dp[i][j] = max(dp[i][j], dp[i-1][j-w[i]] + v[i]);
            }
        }
    }

    ll ans = -1;
    for(int i=0;i<=W;i++){
        ans = max(ans, dp[N-1][i]);
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 82304
import java.util.*;

public class Main {

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int[] arr = new int[3];
		for (int i = 0; i < 3; i++) {
			arr[i] = sc.nextInt();
		}
		Arrays.sort(arr);
		int count = 0;
		if ((arr[1] - arr[0]) % 2 != 0) {
			count++;
			arr[1]++;
			arr[2]++;
		}
		count += (arr[1] - arr[0]) / 2;
		count += arr[2] - arr[1];
		System.out.println(count);
	}
}


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

using namespace std;

const int N = 1e5 + 3;

long long h[N], dp[N];                  

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    for (int i = 1; i <= n; ++i)
        cin >> h[i];
    for (int i = 2; i <= n; ++i) {
        dp[i] = dp[i-1] + abs(h[i]-h[i-1]);
        if (i > 2)
            dp[i] = min(dp[i], dp[i-2] + abs(h[i]-h[i-2]));
    }
    cout << dp[n];
    return 0;
}

Measured memory_bytes: 1792
import java.math.BigInteger

fun main(args: Array<String>) {
    val (W, A, B) = readLine()!!.split(" ").map { it.toInt() }
    val a = Math.min(A, B)
    val b = Math.max(A, B)
    println(Math.max(0, b - (a + W)))
}

Measured memory_bytes: 36080
x, y, na, nb, nc = map(int, input().split()) 
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]
a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)
a = a[:x]
b = b[:y]

ai = len(a) - 1
bi = len(b) - 1

for i in c:
    if a[ai] < b[bi]:
        if i > a[ai] and ai >= 0:
            a[ai] = i
            ai -= 1
        elif i > b[bi] and bi >= 0:
            b[bi] = i
            bi -= 1
        else:
            break
    else:
        if i > b[bi] and bi >= 0:
            b[bi] = i
            bi -= 1
        elif i > a[ai] and ai >= 0:
            a[ai] = i
            ai -= 1
        else:
            break
print(sum(a)+sum(b))

Measured memory_bytes: 23232
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,K;
  cin >> N >> K;
  
  int subanswer = 1;
  if(N>1){
  for(int i = 0; i < N-1 ;i++){
    subanswer *= (K-1);
  }
  }
  int answer = K * subanswer;
  
  cout << answer << endl;
}

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

using namespace std;

#define ll long long 

const int INF = 1e9+5;

int main(){
	//freopen("tree.in","r",stdin);
    //freopen("tree.out","w",stdout);
    //freopen("input.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    ios_base::sync_with_stdio(0);
    //cin.tie(0);

	int n;
	cin >> n;

	vector<int> dp(3);
	
	for(int day = 0; day < n; ++day){
		vector<int> new_dp(3, 0);
		vector<int> act(3);

		for(int i = 0; i < 3; ++i){
			cin >> act[i];
		}

		for(int i = 0; i < 3; ++i){
			for(int j = 0; j < 3; ++j){
				if(i != j){
					new_dp[j] = max(new_dp[j], dp[i]+act[j]); // avoiding consecutive activities
				}
			}
		}		
		//cout << new_dp[0] << " " << new_dp[1] << " " << new_dp[2] << endl;
		dp = new_dp;
	}
	cout << max(dp[0], max(dp[1], dp[2])) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int N;
vector<pair<int,int>> A;
ll memo[2000][2000];
bool visited[2000][2000];
ll f(int p, int q) {
	if (p == N) return 0;
	if (visited[p][q]) return memo[p][q];
	visited[p][q] = true;
	ll Ax = A[p].first;
	int x = A[p].second;
	ll r1 = f(p+1, q+1) + Ax * abs(x-q);
	int y = N-1-(p-q);
	ll r2 = f(p+1, q) + Ax * abs(x-y);
	return memo[p][q] = max(r1, r2);
}
int main() {
	cin >> N;
	for (int i = 0; i < N; ++ i) {
		int ai;
		cin >> ai;
		A.push_back({ai, i});
	}
	sort(A.rbegin(), A.rend());
	cout << f(0, 0) << endl;
}


Measured memory_bytes: 30368
#include<iostream>
using namespace std;
int n;
main()
{
	while(cin>>n,n)
	{
		int lx=0,rx=0,ly=0,ry=0;
		int x[200]={},y[200]={};
		for(int i=0;i<n-1;i++)
		{
			int a,d;cin>>a>>d;
			x[i+1]=d%2?x[a]:d?x[a]+1:x[a]-1;
			y[i+1]=d%2?d==1?y[a]-1:y[a]+1:y[a];
			lx=lx<x[i+1]?lx:x[i+1];
			ly=ly<y[i+1]?ly:y[i+1];
			rx=rx<x[i+1]?x[i+1]:rx;
			ry=ry<y[i+1]?y[i+1]:ry;
		}
		cout<<rx-lx+1<<" "<<ry-ly+1<<endl;
	}
}



Measured memory_bytes: 3088
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
int main() {
	int a,b;
	cin>>a>>b;
	int t=a*b;
	if(t%2==1)cout<<"Odd\n";
	else cout<<"Even\n";
	return 0;
}

Measured memory_bytes: 256
/*input
211 5
31 41 59 26 53
*/
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define f first
#define s second
#define watch(x) cout << (#x) << " is " << (x) << endl
#define N 100002

using namespace std;
int main()
{
	fastio
	ll T=1,n,m;string str;
	// cin>>T;
	// cin.ignore(); put after cin, just b4 a getline(cin, s) to avoid getline() directly getting \n
	while(T--)
	{
		ll p=0,q=0,tmp=0,sum=0,count=0; //tmp variable
		int flag=0;
		
		cin>>n>>m;
		ll a[m];
		for (int i = 0; i < m; ++i)
		{
			cin >> a[i];
		}
		sort(a,a+m);
		for (int i = 0; i < m; ++i)
		{
			n-=a[m-1-i];
			if(n<=0)
			{
				cout << "Yes" << endl;
				return 0;
			}	
		}
		cout << "No" << endl;

	}
	return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>

int main(void)
{
	int X,A,B;
	
	scanf("%d %d %d",&X,&A,&B);
	if(B<=A)printf("delicious\n");
	else if(A<B && B<=X+A) printf("safe");
	else printf("dangerous\n");
	
	return 0;
}

Measured memory_bytes: 128
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n, k = map(int, readline().split())
    ans = 0

    for x in range(1, n + 1):
        p = n // x
        q = n % x
        ans += p * max(0, x - k)
        if k == 0:
            ans += q
        else:
            ans += max(0, q - k + 1)
    print(ans)


if __name__ == '__main__':
    main()


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

int main(){
    int n,c;
    cin>>n>>c;
    int s,t,ch;
    vector<tuple<int,int,int>> v;
    for(int i=0;i<n;i++){
        cin>>s>>t>>ch;
        v.push_back(make_tuple(s,t,ch));
    }
    int ans=0;
    sort(v.begin(),v.end());
    for(int i=1;i<=c;i++){
        vector<pair<int,int>> vv(i);
        for(int j=0;j<i;j++){
            vv[j]=make_pair(0,0);
        }
        bool ok=true;
        int c=0;
        for(int j=0;j<n;j++){
            c=0;
            //cerr<<j<<endl;
            bool okok=false;
            for(int k=0;k<i;k++){
                c++;
                okok=false;
                if(vv[k].first < get<0>(v[j])){
                    vv[k].first=get<1>(v[j]);
                    vv[k].second=get<2>(v[j]);
                    cerr<<k<<" "<<vv[k].first<<endl;
                    okok=true;
                    break;
                }
                else if(vv[k].first == get<0>(v[j]) && vv[k].second == get<2>(v[j])){
                    vv[k].first=get<1>(v[j]);
                    okok=true;
                    break;
                }
            }
            if(!okok) ok=false;
            if(ok==false) {
                break;
            }
        }
        if(ok){
            cout<<i<<endl;
            return 0;
        }
    }

}

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;

int main(){
    int n;
    cin >> n;
    map<string, int> mp;
    string s;
    for (int i = 0; i < n; ++i) {
        cin >> s;
        mp[s]++;
    }

    int mx = 0;
    for (auto i = mp.begin(); i != mp.end(); ++i){
        mx = max(mx, i->second);
    }

    for (auto i = mp.begin(); i != mp.end(); ++i){
        if(mx == i->second){
            cout << i->first << endl;
        }
    }

}

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

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);

  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }

  vector<pair<long long, long long>> stock(n + 1);
  vector<long long> money(n + 1);
  money[0] = 1000;

  for (int i = 0; i < n; i++) {
    money[i + 1] = max(money[i], stock[i].first * a[i] + stock[i].second);
    stock[i + 1] = max(stock[i], {money[i] / a[i], money[i] % a[i]});
  }

  cout << money[n] << '\n';

  return 0;
}



Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
//#include <atcoder/all>
//using namespace atcoder;
template <typename T> bool chmax(T &u, const T z) { if (u < z) {u = z; return true;} else return false; }
template <typename T> bool chmin(T &u, const T z) { if (u > z) {u = z; return true;} else return false; }
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
typedef pair<ll, ll> P;
const ll INF = 1LL << 60;
const int MOD = 1000000007;
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

int main(){
    int x;
    cin>>x;
    if(x==1)cout<<0<<endl;
    else cout<<1<<endl;
    return 0;
}

Measured memory_bytes: 3620
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/errno.h>
#include <limits.h>

#define READ_BUF_SIZE 10000000
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define ABS(a) ((a) > (-a) ? (a) : (-a))

static int
read_num (FILE *fp, long *out, long max)
{
  char format[128];
  char buf[READ_BUF_SIZE];
  long i = 0;
  char *p;

  sprintf (format, "%%%d[^\n]%%*[^\n]", READ_BUF_SIZE);
  if (fscanf (fp, format, buf) == EOF)
    {
      fseek (fp, 0L, SEEK_SET);
      return -1;
    }
  getc (fp);

  for (p = strtok (buf, "  "); p; p = strtok (NULL, " "))
    {
      char *endptr;
      long num = strtol (p, &endptr, 10);
      if (*endptr != '\0' || errno == ERANGE)
	continue;
      out[i++] = num;
      if (i >= max)
	break;
    }
  return i;
}

long
low_search (long *array, long array_size, long key)
{
  long left = -1;
  long right = array_size;

  while (ABS (right - left) > 1)
    {
      long mid = (right + left) / 2;
      if (array[mid] >= key)
	right = mid;
      else
	left = mid;
    }
  return right;
}

long
upper_search (long *array, long array_size, long key)
{
  long left = -1;
  long right = array_size;

  while (ABS (right - left) > 1)
    {
      long mid = (right + left) / 2;
      if (array[mid] > key)
	right = mid;
      else
	left = mid;
    }
  return right;
}

static int
cmp (const void *a, const void* b)
{
  long A = *(long *) a;
  long B = *(long *) b;
  if (A > B) 
    return 1;
  if (A < B)
    return -1;
  return 0;
}

int
main (int argc, char *argv[])
{
  long i, count = 0;
  long N;
  read_num (stdin, &N, 1);
  long *A = (long *) malloc (sizeof (long) * N);
  long *B = (long *) malloc (sizeof (long) * N);
  long *C = (long *) malloc (sizeof (long) * N);

  read_num (stdin, A, N); 
  read_num (stdin, B, N); 
  read_num (stdin, C, N); 

  qsort (A, N, sizeof (long), cmp);
  qsort (C, N, sizeof (long), cmp);

#if 0
  for (i = 0; i < N; i++)
  {
    printf ("%ld ", A[i]);
  }
  printf ("\n");

  for (i = 0; i < N; i++)
  {
    printf ("%ld ", C[i]);
  }
  printf ("\n");
#endif
  
  for (i = 0; i < N; i++)
  {
    long a = low_search (A, N, B[i]);
    long c = upper_search (C, N, B[i]);
    count += a * (N - c);
  }

  printf ("%ld\n", count);
  return 0;
}



Measured memory_bytes: 5848
#include<stdio.h>
int main()
{
	int i,n;
	scanf("%d", &n);
	int array[100];
	for (i = 0; i < n; i++) {
		scanf("%d", &array[i]);
	}
	for (i = n - 1; i >= 0; i--) {
		if (i > 0) printf("%d ", array[i]);
		else printf("%d\n", array[i]);
	}
	return 0;
}

Measured memory_bytes: 596
n = int(input())

p = [int(i) for i in input().split()]

cout = 0
temp_cout = 0

for i in range(len(p)):
    num = i+1
    if num == p[i]:
        cout +=1
        temp_cout +=1
    else:
        temp_cout = 0
        
    if temp_cout == 2:
        temp_cout = 0
        cout -= 1
        
print(cout)

Measured memory_bytes: 13880
#include<bits/stdc++.h>
#define ll long long 
#define ld long double
#define pb push_back
#define vl vector
#define ff first
#define ss second
using namespace std;
int main()
{
    ll a,b,i,j,n,t;
    cin>>n;
    ll arr[n],brr[n]={0};
    for(i=0;i<n;i++) cin>>arr[i];
    for(i=0;i<n-1;i++) if(arr[i]>=arr[i+1]) brr[i]=1;
    ll count=0,mx=0;
    for(i=0;i<n;i++)
    {
        if(brr[i]==1) count++;
        else count=0;
        mx=max(count,mx);
    }
    cout<<mx;
}

Measured memory_bytes: 5104
import java.io.*;

class Main{
    public static void main(String[] args)throws IOException{
	BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
	long n=Integer.parseInt(br.readLine());
	System.out.println(factorial(n));
    }
    public static long factorial(long n){
	if(n<=1)
	    return 1;
	else
	    return n*factorial(n-1);
    }
}

Measured memory_bytes: 9364
N,K = gets.split.map(&:to_i)
e = (N-1)*(N-2)/2
if K > e
  p -1
  exit
end
ans = []
(N-1).times do |i|
  ans << [i+1,N]
end
a,b = 1,2
while e != K
  ans << [a,b]
  if b == N-1
    a += 1
    b = a + 1
  else
    b += 1
  end
  e -= 1
end
p ans.length
ans.each do |t|
  puts t.join(" ")
end

Measured memory_bytes: 2300
#include<bits/stdc++.h>
//#include<boost/multiprecision/cpp_int.hpp>
using namespace std;
//namespace mp=boost::multiprecision;
#define ll long long
ll solve(ll ind,ll w,vector<vector<ll> > &v,vector<vector<ll> > &dp)
{
    //if(ind==0)
     //   return 0;
    if(dp[ind][w]!=(-1))
        return(dp[ind][w]);
    ll cost=long LONG_LONG_MIN;
    if(v[ind-1][0]<=w)
        cost=max(cost,v[ind-1][1]+solve(ind-1,w-v[ind-1][0],v,dp));
    cost=max(cost,solve(ind-1,w,v,dp));
    dp[ind][w]=cost;
    return(dp[ind][w]);
}
int main()
{
    ll n,w;cin>>n>>w;
    vector<vector<ll> > v(n,vector<ll> (2));
    for(ll i=0;i<n;i++)
    {
        for(ll j=0;j<2;j++)
            cin>>v[i][j];
    }
    vector<vector<ll> > dp(n+1,vector<ll> (w+1,-1));
    for(ll i=0;i<=n;i++)
        dp[i][0]=0;
    for(ll i=0;i<=w;i++)
        dp[0][i]=0;
    cout<<solve(n,w,v,dp);
}


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

const int MAX_N	= 50;
int L[ MAX_N + 5 ];

int main( int argc, char *argv[] )
{
int i;
int N;
int K;
int iSum;

	ios::sync_with_stdio( false );
	cin.tie( 0 );

	cin >> N;
	cin >> K;
	for( i = 0; i < N; i++ )
	{
		cin >> L[ i ];
	}

	sort( L, L + N );

	iSum = 0;
	for( i = N - K; i < N; i++ )
	{
		iSum += L[ i ];
	}

	cout << iSum << endl;

	return 0;
}




Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int dp[102][5][5],f[102];
int main(){
	int i,j,n,k,x,y;
	scanf("%d%d",&n,&k);
	memset(f,0,sizeof(f));
	memset(dp,0,sizeof(dp));
	for(i=0;i<k;i++){
		scanf("%d%d",&x,&y);
		f[x]=y;
	}
	if(f[1]!=0)dp[1][f[1]][1]=1;
	else dp[1][1][1]=dp[1][2][1]=dp[1][3][1]=1;
	for(i=2;i<=n;i++){
		if(f[i]==0){
			dp[i][1][1]=(dp[i-1][2][1]+dp[i-1][2][2]+dp[i-1][3][1]+dp[i-1][3][2])%10000;
			dp[i][1][2]=dp[i-1][1][1]%10000;
			
			dp[i][2][1]=(dp[i-1][1][1]+dp[i-1][1][2]+dp[i-1][3][1]+dp[i-1][3][2])%10000;
			dp[i][2][2]=dp[i-1][2][1]%10000;
			
			dp[i][3][1]=(dp[i-1][2][1]+dp[i-1][2][2]+dp[i-1][1][1]+dp[i-1][1][2])%10000;
			dp[i][3][2]=dp[i-1][3][1]%10000;
			
		}else{
			dp[i][f[i]][2]=dp[i-1][f[i]][1]%10000;
			for(j=1;j<=3;j++){
				if(j!=f[i])dp[i][f[i]][1]+=(dp[i-1][j][1]+dp[i-1][j][2])%10000;
			}
		}
	}
	printf("%d\n",(dp[n][1][1]+dp[n][1][2]+dp[n][2][1]+dp[n][2][2]+dp[n][3][1]+dp[n][3][2])%10000);
	return 0;
}

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

struct UnionFind {
    //自身が親であれば、その集合に属する頂点数に-1を掛けたもの
    //そうでなければ親のid
    vector<int> r;
 
    UnionFind(int N) {
        r = vector<int>(N, -1);
    }
 
    int root(int x) {
        if (r[x] < 0) return x;
        return r[x] = root(r[x]);
    }
 
    bool unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (r[x] > r[y]) swap(x, y);
        r[x] += r[y];
        r[y] = x;
        return true;
    }
 
    int size(int x) {
        return -r[root(x)];
    }

    int same(int x, int y) {
        return root(x) == root(y);
    }
};

int main() {
    int N, M;
    cin >> N >> M;
 
    //友達集合を作る
    UnionFind UF(N);
    for (int i = 0; i < M; i++)
    {
        int A, B;
        cin >> A >> B;
        A -= 1; B -= 1;
        UF.unite(A, B);
    }
 
    //最大の友達集合を求める
    int ans = 0;
    for (int i = 0; i < N; i++)
    {
        ans = max(ans, UF.size(i));
    }
 
    cout << ans << endl;
}

Measured memory_bytes: 3956
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
const int INF = 1e9;

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

    // 最初は未使用 1 口で、そこから B-1 口増やしたい。
    // Aひとつ追加するたびに、A-1 口が増える。
    a--;
    b--;
    int ans;
    if (b % a == 0) {
        ans = b / a;
    } else {
        ans = b / a + 1;
    }

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

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

int n,ans;
int a[3],b[3];
long long dp[N*N*2];

int main()
{
	
	cin>>n;
	cin>>a[0]>>a[1]>>a[2];
	cin>>b[0]>>b[1]>>b[2];
	for(int i=0;i<=n;i++)
		dp[i]=i;
	for(int i=0;i<=n;i++)
	for(int j=0;j<3;j++)
		if(i+a[j]<=n) dp[i+a[j]]=max(dp[i+a[j]],dp[i]+b[j]);
	long long mx=0;
	for(int i=0;i<=n;i++)
		mx=max(mx,dp[i]+n-i);
	
	n=mx;
	for(int i=0;i<=n;i++)
		dp[i]=i;
	for(int i=0;i<=n;i++)
	for(int j=0;j<3;j++)
		if(i+b[j]<=n) dp[i+b[j]]=max(dp[i+b[j]],dp[i]+a[j]);
	long long mx2=0;
	for(int i=0;i<=n;i++)
		mx2=max(mx2,dp[i]+n-i);
	cout<<mx2<<'\n';
	
	return 0;
}

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



int main() {
    int n, k;
    cin >> n >> k;
    
    vector<double> p(n);
    rep(i,n) {
        cin >> p[i];
    }
    
    rep(i,n) {
        p[i] = (p[i] - 1) / 2 + 1;
    }
    
    vector<double> sum(n-k+1);
    rep(i,k) {
        sum[0] += p[i];
    }
    
    double mx = sum[0];
    for(int i = 1; i < n-k+1; i++) {
        sum[i] = sum[i-1] + p[i+k-1] - p[i-1];
        mx = max(mx, sum[i]);
    }
    
    cout << fixed << setprecision(7) << mx << endl;
    
    
    return 0;
}


Measured memory_bytes: 6356
#include "bits/stdc++.h"

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 1145141919454519;

int main(){

    ll N;
    cin >> N;

    vector<bool > f(N, false);

    map<ll, ll > mp;
    for(ll i = 0; i < N; i++){
        ll A; cin >> A;
        mp[i] = A-1;
    }

    ll idx = 0;
    ll cn = 0;
    while(cn <= 100019){
        idx = mp[idx];
        cn++;
        if(idx == 1){
            cout << cn << endl;
            return 0;
        }
    }

    cout << -1 << endl;

}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
#define lli long long int
using namespace std;
#define mod 1000000007
#define MOD 1000000037
#define mod1 998244353
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 
#define INF 1e18

int n,n0=0,n1=0,n2=0,n3=0;
double dp[301][301][301];
int main()
{
    cin >> n;
    for(int i=0;i<n;i++)
    {
        int x;
        cin >> x;
        if(x==1)
            n1+=1;
        else if(x==2)
            n2+=1;
        else
            n3+=1;
    }
    double con=1.000;
    for(int i=0;i<=n3;i++)
    {
        for(int j=0;j<=n2+n3;j++)
        {
            for(int k=0;k<=n1+n2+n3;k++)
            {
                //cout << i << " " << j << " " << k << endl;
                if(i==0 and j==0 and k==0)
                {
                    dp[i][j][k]=0;
                    continue;
                }
                int t=i+j+k;
                double nm=(n*con)/(t*con);
                double p3=(i*con)/(i+j+k),p2=(j*con)/(i+j+k),p1=(k*con)/(i+j+k);
                dp[i][j][k]=nm;
                if(p1>0.0)
                    dp[i][j][k]+=p1*dp[i][j][k-1];
                if(p2>0.0)
                    dp[i][j][k]+=p2*dp[i][j-1][k+1];
                if(p3>0.0)
                    dp[i][j][k]+=p3*dp[i-1][j+1][k];
            }
        }
    }
    double ans=dp[n3][n2][n1];
    //cout << ans << endl;
    cout <<  fixed << setprecision(12) << ans << endl;
}


Measured memory_bytes: 213248
H,W = map(int,input().split())
grid = []
for i in range(H):
    a = input()
    l = []
    for i in a:
        l.append(i)
    grid.append(l)
grid_1 = []
delete = []
for i,job in enumerate(grid):
    count = 0
    for j in job:
        if(j == "."):
            count += 1
    if(count != W):
        grid_1.append(job)
count = 0
for i in delete:
    grid.pop(i-count)
    count += 1
grid_3 = []
for Row in zip(*grid_1):
    w = len(Row)
    count = 0
    for j in Row:
        if(j == "."):
            count += 1
    if(count != w):
        grid_3.append(Row)
for Row in zip(*grid_3):
    ans = ""
    for j in Row:
        ans += j
    print(ans)

Measured memory_bytes: 39920
import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();
        PrintWriter pw = new PrintWriter(System.out);

        int n = sc.nextInt();
        int[] ans = new int[n];

        for (int i = 0; i < n; i++) {
            int a = sc.nextInt();
            ans[a-1] = i+1;
        }

        for (int i : ans)
            pw.print(i + " ");

        pw.close();
    }

    static class MyScanner {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 1 << 15);
        StringTokenizer tokenizer;

        String next() {
            try {
                while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                    tokenizer = new StringTokenizer(reader.readLine());
                }
            } catch (IOException ignored) {
            }
            return tokenizer.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }
    }
}

Measured memory_bytes: 39580
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
using namespace std;
#define DEBUG(x) cout<<#x<<"="<<x<<endl
#define DEBUG2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl
typedef long long ll;
// #define LOCAL
const int MAXN=1e5+10;
const ll MOD=1e9+7;
ll _gcd(ll a,ll b){if(b==0)return a;return _gcd(b,a%b);}
ll gcd(ll a,ll b){a=abs(a),b=abs(b);if(a<b)swap(a,b);return _gcd(a,b);}
ll qpow(ll a,ll n){ll rt=1;while(n){if(n&1)rt=(rt*a)%MOD;a=a*a%MOD;n>>=1;}return rt;}
ll factor[MAXN];
void cal_factor(){factor[0]=1;for(int u=1;u<MAXN;u++){factor[u]=(factor[u-1]*u)%MOD;}}
ll C(ll n,ll k){return factor[n]*qpow(factor[n-k],MOD-2)%MOD*qpow(factor[k],MOD-2)%MOD;}
int fa[MAXN];
void init()
{
    for(int u=0;u<MAXN;u++)fa[u]=u;
}
int mfind(int r)
{
    if(fa[r]==r)return r;
    int x=mfind(fa[r]);
    fa[r]=x;
    return x;
}
void munion(int a,int b)
{
    int ra=mfind(a),
    rb=mfind(b);
    if(ra==rb)return;
    fa[b]=a;
}
struct edge{
    int u,v,w;
};
struct point{
    int idx,x,y;
};
bool cmpx(point p1,point p2)
{
    return p1.x<p2.x;
}
bool cmpy(point p1,point p2)
{
    return p1.y<p2.y;
}
bool cmplen(edge e1,edge e2)
{
    return e1.w<e2.w;
}
ll kruskal(vector<edge>&edges)
{   
    sort(edges.begin(),edges.end(),cmplen);
    ll ans=0;
    for(edge e:edges){
        int ra=mfind(e.u),
        rb=mfind(e.v);
        if(ra==rb)continue;
        ans+=e.w;
        fa[rb]=ra;
    }
    return ans;
}
void solve()
{
    init();
    int N;
    vector<point>pts;
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>N;
    for(int u=0;u<N;u++){
        int x,y;
        cin>>x>>y;
        pts.push_back({u,x,y});
    }
    vector<edge>edges;
    sort(pts.begin(),pts.end(),cmpx);
    for(int u=1;u<N;u++){
        edges.push_back({pts[u].idx,pts[u-1].idx,
        pts[u].x-pts[u-1].x});
    }
    sort(pts.begin(),pts.end(),cmpy);
    for(int u=1;u<N;u++){
        edges.push_back({pts[u].idx,pts[u-1].idx,
        pts[u].y-pts[u-1].y});
    }
    cout<<kruskal(edges);
}
int main()
{
#ifdef LOCAL
    freopen("in.txt","r",stdin);
#endif
    solve();
}

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

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rept(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(int)(n);(i)++)
#define repst(i,s,n) for(int (i)=(s);(i)<=(int)(n);(i)++)
#define repr(i,n) for(int (i)=(n);(i)>=0;(i)--)
#define each(itr,v) for(auto (itr):(v))
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp(x,y) make_pair((x),(y))
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln "\n"
#define show(x) cout << #x << " = " << x ln
#define dbg(x) cout<<#x"="<<x ln

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

const int inf = (int)1e9;
const ll linf = (ll)1e18;
const int mod = (int)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

string s;
int l;

int main() {
	cin >> s;
	l = (int)s.length();
	
	while (l>0) {
		if (l>=7 && s.substr(l-7,7)=="dreamer") l -= 7;
		else if (l>=6 && s.substr(l-6,6)=="eraser") l -= 6;
		else if (l>=5 && (s.substr(l-5,5)=="erase" || s.substr(l-5,5)=="dream")) l -= 5;
		else {
			cout << "NO" << ln;
			return 0;
		}
	}
	cout << "YES" << ln;
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>

using namespace std;

typedef long long ll;


int main() {
    int n;  cin >> n;
    ll *a = new ll[n]; 
    for (int i= 0; i < n; i++) 
        cin >> a[i];

    ll l = 0, r = a[0]+1;    //真のx_0はl以上rより小さい
    ll *x = new ll[n];
    while (r-l > 1) {
        bool flag = true;
        ll mid = (l+r)/2;
        x[0] = mid;
        
        for (int i = 0; i < n-1; i++) {
            x[i+1] = a[i]-x[i];
            if ((i+1)%2 == 1 && x[i+1] < 0) { //真の値より大きい
                flag = false;
                
                r = mid;
                break;
            }
            else if (x[i+1] < 0) { //真の値より小さい
                flag = false;
                
                l = mid+1;
            }
            if (!flag)
                break;
        }
        if (!flag)
            continue;
        if (x[0]+x[n-1] > a[n-1]) {
            
            r = mid;
            continue;
        }
        else if (x[0]+x[n-1] < a[n-1]) {
            
            l = mid+1;
            continue;
        }
        
            for (int i = 0; i < n; i++)
                cout << 2*x[i] << " ";
            cout << endl;
            return 0;

    }
    x[0] = l;
    cout << 2*x[0] << " ";
    for (int i = 0; i < n-1; i++) {
        x[i+1] = a[i]-x[i];
        cout << 2*x[i+1] << " ";
    }
    cout << endl;

            return 0;
}

Measured memory_bytes: 2944
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#define REP(i,a) for(int i = 0; i < (a); i++)
using namespace std;

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

Measured memory_bytes: 256
import sys

input = sys.stdin.readline


def main():
    A, B = map(int, input().split())

    cnt = 1
    ans = 0
    while True:
        if cnt >= B:
            break
        cnt += (A - 1)
        ans += 1
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
// ABC 117 C

#include <algorithm>
#include <cstdint>
#include <iostream>
#include <vector>

using namespace std;

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

  if (N >= M) {
    cout << 0 << endl;
    return 0;
  }

  vector<int> X(M);
  vector<int> d(M - 1);
  for (int i = 0; i < M; ++i) cin >> X[i];
  sort(X.begin(), X.end());

  int64_t ans = 0;
  for (int i = 0; i < M - 1; ++i) {
    d[i] = X[i + 1] - X[i];
    ans += d[i];
  }
  partial_sort(d.begin(), d.begin() + N - 1, d.end(), greater<int>());
  for (int i = 0; i < N - 1; ++i) {
    ans -= d[i];
  }
  cout << ans << endl;

  return 0;
}


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

int main() {
    ll h;
    cin >> h;
    cout << fixed << setprecision(0) << pow(2, floor(log2(h)) + 1) - 1 << endl;
    return 0;
}

Measured memory_bytes: 4228
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll GCD(ll x,ll y){
    if(y == 0) return x;
    else return GCD(y,x%y);
}
const int MOD = 1000000007;



int main() {
    int n; cin >> n;
    int a[n];
    for(int i = 0;i < n;i++){
        cin >> a[i];
    }
    ll g = GCD(a[0],a[1]);
    for(int i = 2;i < n;i++){
        g = GCD(a[i],g);
    }
    cout << g;
}




Measured memory_bytes: 3992
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#define debug(x) cerr<<#x<<": "<<(x)<<endl
#define INF      (int)1e9
#define EPS      (double)1e-9
#define MOD      ((int)1e9+7)
using namespace std;
typedef long long     llong;
typedef vector<int>   vi;
typedef vector<vi >   vvi;
typedef vector<vvi >  vvvi;
typedef pair<int,int> pii;
template<class Type> void line(const Type &a){int cnt=0;for(const auto &elem:a){if(cnt++)cout<<' ';cout<<elem;}cout<<endl;}

//解説参考.
int main(){
	int n;
	cin>>n;
	
	vi a(n),b(n);
	REP(i,n) cin>>a[i]>>b[i];
	sort(ALL(a));
	sort(ALL(b));
	
	int ans;
	if(n&1){
		int l=a[n/2];
		int r=b[n/2];
		ans=r-l+1;
	}else{
		double l=(a[n/2-1]+a[n/2])/2.0;
		double r=(b[n/2-1]+b[n/2])/2.0;
		ans=(r-l)/0.5+1;
	}
	
	cout<<ans<<endl;
}

Measured memory_bytes: 4788
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.ArrayList;


class Main{
    public static void main(String[] args){
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

	HashMap<String, Integer> hs = new HashMap<String, Integer>();
	ArrayList<String> list_yn = new ArrayList<String>();

	try{
	    int n = Integer.parseInt(br.readLine());
	    for(int i=0;i<n;i++){
		String line = br.readLine();
		String[] com_val = line.split(" ",0);
		
		if(com_val[0].equals("insert")){
		    hs.put(com_val[1],0);
		}else if(com_val[0].equals("find")){
		    //System.out.println("a");
		    if(hs.get(com_val[1])==null){
			list_yn.add("no");
		    }else{
			list_yn.add("yes");
		    }
		}
	    }
	}catch(Exception e){
	    
	}

	for(int i=0;i<list_yn.size(); i++){
	    System.out.println(list_yn.get(i));
	}
    }
}



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

int main() {
  string s, t;
  cin >> s >> t;
  bool cond = true;
  int n = s.size();
  if(n == 1){
    cout << "Yes" << endl;
    return 0;
  }
  vector<int> alpha_s(26, -1);
  vector<int> alpha_t(26, -1);
  vector<vector<int>> compose_s(n);
  vector<vector<int>> compose_t(n);
  rep(i, n){
    int s_i = s[i] - 'a';
    int t_i = t[i] - 'a';
    if(alpha_s[s_i] == -1){
      alpha_s[s_i] = i;
    }
    if(alpha_t[t_i] == -1){
      alpha_t[t_i] = i;
    }
    compose_s[alpha_s[s_i]].push_back(i);
    compose_t[alpha_t[t_i]].push_back(i);
  }
  if(compose_s == compose_t){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 15268
import sys
import math
input = sys.stdin.readline


def main():
    sc = Scan()
    N = sc.intarr()[0]
    P = sc.intarr()
    Q = sc.intarr()
    p_idx = -1
    q_idx = -1
    roop = 0
    array = []
    for i in range(1, N+1):
        array.append(i)
    pp = perm(array)
    for p in pp:
        if p == P:
            p_idx = roop
        if p == Q:
            q_idx = roop
        roop += 1

    print(abs(p_idx-q_idx))


def perm(p):
    if len(p) == 1:
        return [p]
    else:
        s = []
        for i in range(len(p)):
            q = p[i]
            r = perm(p[:i]+p[i+1:])
            for t in r:
                s.append([q] + t)
        return s


class Scan():

    def intarr(self):
        num_array = list(map(int, input().split()))
        return num_array

    def intarr_ver(self, n):
        return [int(input()) for _ in range(n)]

    def strarr(self):
        line = input()
        array = line.split(' ')
        array[-1] = array[-1].strip('\n')
        return array


def display(array):
    for a in range(len(array)):
        if len(array) - a != 1:
            print(array[a], end=' ')
        else:
            print(array[a])


def gcd(a, b):  # 最大公約数
    while b:
        a, b = b, a % b
    return a


def lcm(a, b):  # 最小公倍数
    return a * b // gcd(a, b)


main()


Measured memory_bytes: 9972
#include <iomanip>
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
int N;

void dfs(int n, string s) {
  if (n == N) {
    cout << s << endl;
    return;
  }

  vector<bool> used(26, false);
  for (int i = 0; i < n; ++i) {
    if (used[s[i] - 'a'] == false) {
      string t = s;
      t += s[i];
      dfs(n + 1, t);
      used[s[i] - 'a'] = true;
    }
  }
  string t = s;
  for (int i = 0; i < 26; ++i) {
    if (used[i] == false) {
      t += char(i + 'a');
      dfs(n + 1, t);
      break;
    }
  }
}

int main(void) {
  ios::sync_with_stdio(false);
  cin >> N;
  dfs(1, "a");
  return 0;
}


Measured memory_bytes: 1536
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE NumDecimals #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}

import Control.Applicative
import Control.Arrow
import Control.Monad
import Control.Monad.ST

import Data.Char
import Data.List
import Data.Maybe

import qualified Data.ByteString.Char8 as B

import Data.Array.ST.Safe
import Data.STRef

import Debug.Trace
import Text.Printf

readInt = readLn :: IO Int
readInteger = readLn :: IO Integer
readInts = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine
readIntegers = map ( fst . fromJust . B.readInteger ) . B.words <$> B.getLine

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

modifyArray a i f = writeArray a i =<< f <$> readArray a i

main = do
	[ a, b ] <- readInts
	if a < 10 && b < 10
		then print $ a * b
		else print (-1)

Measured memory_bytes: 380
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>
#include <tuple>

#define DEBUG(x) cout<<#x<<": "<<x<<endl

using namespace std;

int main(){

	long long N, K;

	cin >> N >> K;

	double ans = 0;

	for(long long l = 1; l <= N; l++){
		int i;
		double x;
		for(x = 1 , i = l; i < K; i*=2){
			x *= 0.5;
		}
		ans += x;
	}

	printf("%.12f", ans/N);

	return 0;
}



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

using namespace std;


int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, x;
  cin >> n >> x;
  if (1 < x && x < n + n - 1) {
    cout << "Yes\n";
    vector<int> ans(n + n + 1, -1);
    x--;
    if (x == 1) {
      ans[n - 1] = x;
      ans[n - 2] = x + 1;
      ans[n] = x - 1;
      ans[n + 1] = x + 2;
      int m = 0;
      for (int i = 0; i < n + n - 1; i++) {
        while (x - 1 <= m && m <= x + 2) {
          m++;
        }
        if (ans[i] == -1) {
          ans[i] = m++;
        }
      }
    } else {
      ans[n - 1] = x;
      ans[n - 2] = x - 1;
      ans[n] = x + 1;
      ans[n + 1] = x - 2;
      int m = 0;
      for (int i = 0; i < n + n - 1; i++) {
        while (x - 2 <= m && m <= x + 1) {
          m++;
        }
        if (ans[i] == -1) {
          ans[i] = m++;
        }  
      }
    }
    for (int i = 0; i < n + n - 1; i++) {
      cout << ans[i] + 1 << '\n';
    }
  } else {
    cout << "No\n";
  }
  return 0;
}

Measured memory_bytes: 2304
str = gets.chomp.split('')
t = 0
l_t = [0]
str.each do |s| 
    if s == '<'
        t += 1
    else
        t = 0
    end
    l_t << t
end
t = 0
r_t = [0]
str.reverse.each do |s|
    if s == '>'
        t += 1
    else
        t = 0
    end
    r_t.unshift(t)
end
ans = 0
0.upto(str.size) do |i|
    
    ans += [l_t[i], r_t[i]].max
end

puts ans

Measured memory_bytes: 57936
#include<iostream>
#include<math.h>
using namespace std;
int main() {
    int n, k;
    cin >> n >> k;
    int a = 1;
    n -= k;
    while (n > 0) {
        ++a;
        n -= (k - 1);
    }
    cout << a << endl;
    return 0;
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class BBiteEating {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int l = in.nextInt();

            int desired = 0;
            for (int i = 1; i <= n; i++) {
                desired += l + i - 1;
            }

            int min = Integer.MAX_VALUE;
            int answer = desired;
            for (int i = 1; i <= n; i++) {
                int x = Math.abs(l + i - 1);
                if (x < min) {
                    min = x;
                    answer = desired - (l + i - 1);
                }
            }

            out.println(answer);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



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

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

const int MC = 100010;
int K;
int d[MC];
priority_queue<P2 , vector<P2> , greater<P2> > Q;

int main(){
	cin >> K;
	fill(d,d+MC,123456789);
	repm(i,9,0){
		d[i%K] = i;
		Q.push(MP(d[i%K],i%K));
	}
	while(!Q.empty()){
		int x = Q.top().second;
		Q.pop();
		repp(i,0,10){
			int y = (x*10+i)%K;
			if(d[y] > d[x]+i){
				d[y] = d[x]+i;
				Q.push(MP(d[y],y));
			}
		}
	}
	cout << d[0] << endl;
	return 0;
}


Measured memory_bytes: 2804
#include<iostream>
#include<cmath>
#include<algorithm>
#include <cassert>
#include<string>
using namespace std;
int main() {
	int a = 0, b = 0, c = 0, d[100000], e[100000], f = 0, g = 0, h = 0, count = 0;
	char rikka, toka[100000];
	string saya, homu, kyok, mami,mado[50];
	bool gg = false;
	int manji, nk[26] = {false};
	cin >> a >> b;
	for (int i = 0; i < a; i++) {
		cin >> d[i];
	}
	sort(d, d + a);
	for (int j = 0; j < b; j++) {
		count += d[a-j-1];
	}
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 256
def main():
    A, B, K = map(int, input().split())

    result_list = []
    for i in range(1, min(A, B)+1):
        if A % i == 0 and B % i == 0:
            result_list.append(i)

    print(result_list[-1*K])


if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
N, K = map(int, input().split())
d = [0] * K
A = [[0, 0]] * K
for i in range(K):
    tmp = int(input())
    d[i] = tmp
    A[i] = list(map(int, input().split()))

ans = [False] * N
for i in range(K):
    for j in range(d[i]):
        ans[A[i][j] - 1] = True

res = 0
for i in range(N):
    if not ans[i]:
        res += 1;

print(res)


Measured memory_bytes: 9220
def C():
    #from numpy import sum, min
    N = int(input())
    s = []
    pos = []
    neg = []
    for _ in range(N):
        s.append(int(input()))
    for i in s:
        if i % 10 == 0:
            pos.append(i)
        else:
            neg.append(i)
    possum = sum(pos)
    negsum = sum(neg)
    if negsum % 10 == 0:
        negsum -= min(neg) if neg else 0
    print(0 if 0 == negsum else negsum + possum)

if __name__ == '__main__':
    C()

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

int main() {
    string S;
    cin >> S;
    
    int a = 0, b = 0;
    int n = S.size();
    for(int i = 0; i < n; i++) {
        if(S[i] == '0') {
            a++;
        } else {
            b++;
        }
    }
    
    cout << 2 * min(a, b);
    
    return 0;
}


Measured memory_bytes: 3760
N,A,B=map(int,input().split())
P=[int(i) for i in input().split()]
s=1e19
d=[s]*(N+1)
d[0]=0
for i in range(N):
    e=[s]*(N+1)
    for j in range(N+1):
        if j < P[i]:
            e[P[i]]=min(e[P[i]],d[j])
            e[j]=min(e[j],d[j]+A)
        else:
            e[j]=min(e[j],d[j]+B)
    d=e
print(min(d))


Measured memory_bytes: 87900
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#define MAX(X, Y) (((X) > (Y))? (X) : (Y))
#define MIN(X, Y) (((X) < (Y))? (X) : (Y))
int compare_int(const void *a, const void *b){
  return *(long int*)b - *(long int*)a; // 大きい順
}
int compare_int_small(const void *a, const void *b){
  return *(long int*)a - *(long int*)b; // 小さい順
}
// 公約数
long int gcd(long int a, long int b){
  if(b == 0){
    return a;
  }else{
    return gcd(b, a % b);
  }
}
// 最小公倍数 = a * b / 最大公約数
// 公倍数
long int lcm(long int a, long int b){
  return a * b / gcd(a, b);
}



// min
int main(void){
  char s[5];

  scanf("%s", s);
  
  if(s[0] == s[1] && s[0] == s[2] && s[0] == s[3]){
    printf("No\n");
  }else if(s[0] == s[1] && s[2] == s[3]){
    printf("Yes\n");
  }else if(s[0] == s[2] && s[1] == s[3]){
    printf("Yes\n");
  }else if(s[0] == s[3] && s[1] == s[2]){
    printf("Yes\n");
  }else{
    printf("No\n");
  }

  return 0;
}


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


int main() {
  int a, b;
  cin >> a >> b;
  int ans = a+b;
  if (ans >= 10) cout << "error" << endl;
  else cout << ans << endl;
  return 0;
}

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

l = []

if n == 1:
	print(*L)
	exit()

if n%2 == 0:
	for i in range (0,n//2):
		l.append(L[n-1-2*i])
	for i in range (0,n//2):
		l.append(L[2*i])
else:
	for i in range (0,n//2+1):
		l.append(L[n-1-2*i])
	for i in range (0,n//2):
		l.append(L[2*i+1])

print(*l)

Measured memory_bytes: 26180
import heapq

N, M = map(int, input().split())
A = list(map(int, input().split()))
A = list(map(lambda x:x*(-1), A))
heapq.heapify(A)
for i in range(M):
    t = heapq.heappop(A)*(-1)
    heapq.heappush(A, t//2*(-1))
print (sum(A)*(-1))

Measured memory_bytes: 14180
import java.util.Scanner;

public class Main {
	public static void main(String[] args)
	{
		Scanner stdIn = new Scanner(System.in);
		
		int s = stdIn.nextInt();
		
		int h = s/3600;
		int m = (s-h*3600)/60;
		
		System.out.println(h+":"+m+":"+(s-h*3600-m*60));
	}

}

Measured memory_bytes: 17164