akhauriyash/Code-Regression huggingface dataset:
n,m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
cd = [list(map(int, input().split())) for _ in range(m)]

for i in range(n):
  s = 0
  t = float('inf')
  for j in range(m):
    p = abs(ab[i][0] - cd[j][0]) + abs(ab[i][1] - cd[j][1])
    if p < t:
      s = j+1
      t = p
  print(s) 

Measured memory_bytes: 9152
#include <bits/stdc++.h>
using namespace std;
const int N = 200005;

int n;
vector<int> a[N];
int g[N];

int ans[N];
void dfs(int x, int p, int gg)
{
    gg += g[x];
    ans[x] = gg;
    for (int i = 0; i < a[x].size(); ++i)
    {
        int h = a[x][i];
        if (h == p)
            continue;
        dfs(h, x, gg);
    }
}

int main()
{
    scanf("%d", &n);
    int q;
    scanf("%d", &q);
    for (int i = 0; i < n - 1; ++i)
    {
        int x, y;
        scanf("%d%d", &x, &y);
        a[x].push_back(y);
        a[y].push_back(x);
    }
    while (q--)
    {
        int x, y;
        scanf("%d%d", &x, &y);
        g[x] += y;
    }
    dfs(1, 1, 0);
    for (int i = 1; i <= n; ++i)
        printf("%d ", ans[i]);
    printf("\n");
    return 0;
}


Measured memory_bytes: 27136
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <climits>
#include <bitset>
#include <array>
#include <deque>
#include <queue>
#define all(x) (x).begin(),(x).end()

void solve(){

}
int main(){
    ll n,m;
    cin >> n >> m;
    if (n > m) swap(n,m);
    if (m == 1){
        cout << 1 << endl;
    }else if (n == 1){
        cout << m-2 << endl;
    }else {
        cout << (n-2) * (m-2) << endl;
    }
    return 0;
}


Measured memory_bytes: 256
//52
#include<iostream>
 
using namespace std;
 
int main(){
  for(int n;cin>>n;){
    int ans=0;
    for(int a=0;a<=9;a++){
      for(int b=0;b<=9;b++){
    for(int c=0;c<=9;c++){
      for(int d=0;d<=9;d++){
        ans+=a+b+c+d==n;
      }
    }
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}


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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define vec vector
#define ll long long

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

	vec<ll> x(n);
	rep(i, n) cin >> x[i];

	vec<vec<vec<ll>>> dp(n + 1, vec<vec<ll>>(n + 1, vec<ll>(3000, 0)));
	dp[0][0][0] = 1;
	rep(i, n) {
		rep(j, n) {
			rep(k, 2600) {
				dp[i + 1][j][k] += dp[i][j][k];
				dp[i + 1][j + 1][k + x[i]] += dp[i][j][k];
			}
		}
	}
	ll ans = 0;
	rep(i, n) ans += dp[n][i + 1][a * (i + 1)];
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 62592
n = gets.chop.to_i
t, a = gets.chop.split.map(&:to_i)
hs = gets.chop.split.map(&:to_i)

hs.map!{ |h| (a - (t.to_f - h.to_f * 0.006)).abs }
p hs.index(hs.min) + 1

Measured memory_bytes: 1788
/*                                  /   \                                                                   (Hello)//JSM//*/      
/*                                 /*****\                                                                              */
/*     Jai Shree Mataji           /       \ |\| |_| $ |-| K                                                            */
#include<vector>
#include<iostream>
#include<algorithm>                
#include<string.h>                 
#include<bits/stdc++.h>            
#include<cstring>                  
#include<map>                     
#include<cmath>                  
#include<set>
using namespace std;            
#define ll long long int        
#define ld long double
#define MOD 1000000007 
#define PI 3.1415926535897932384626433832795                                               
#define YY cout<<"YES"
#define NN cout<<"NO"
#define EE cout<<"\n"
#define ee cout<<"\n"
#define ne cout<<"-1"
#define pb push_back 
#define fi first
#define se second
#define mkp make_pair    
#define mkt make_tuple
#define sall(v ) sort(v.begin(), v.end())      
#define all(v )  v.begin(), v.end()      
#define fo(i , n) for(ll i = 0 ; i < n ; i++)
#define vl vector<ll>
#define vc vector<char> 
#define vll vector< pair<ll,ll> > 
#define mps map<string ,ll>
#define mpc map<char ,ll>
#define mpl map<ll, ll>
#define pr pair<ll,ll>
#define tpl tuple<ll,ll,ll>
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);	
	  ll t=1;
      
//	   cin>>t;
      

	      while(t--)
{
	/*
	3 3 2
1 4 3
2 5 7
8 9 6
1
4 8//-**/
ll n,m,k,d;
cin>>n>>m>>d;
map<ll,pr> L;
ll a[n+1][m+1];
fo(i,n)
{
	fo(j,m)
	{
	cin>>a[i+1][j+1];
	L[a[i+1][j+1]]={i+1,j+1};	
	}
}
map<ll,ll> M;
for(ll i=1;i<=n*m;i++)
{
	M[i]=M[i-d]+abs(L[i].first-L[i-d].first)+abs(L[i].second-L[i-d].second);
}
cin>>k;
while(k--)
{ll ans=0;
	ll l,r;
	cin>>l>>r;
	ans=M[r]-M[l];
//M[l][d]<<" "<<M[r][d]<<" "
	cout<<ans;
	ee;
}
}
return 0;
}















Measured memory_bytes: 26864
import java.util.*;

public class Main {
    public static void main(String[] args)  {
       Scanner sc = new Scanner(System.in);
       
       int n = sc.nextInt();
       int r[] = new int[n];
       for(int i=0;i<n;i++){
           r[i] = sc.nextInt();
       }
       
       int min = r[0];
       int max = r[1]-r[0];
       
       for(int i=1;i<n;i++){
             max = Math.max(max,r[i]-min);
             min = Math.min(min,r[i]);
       }
       
       System.out.println(max);
    }
}



Measured memory_bytes: 100884
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1e9+7;
const LL LINF=1LL<<62;

LL dp[303][303][303];
int l[301],r[301],x[301];

int main(){
    int N,M;
    cin >> N >> M;
    for(int i=0;i<M;i++){
        cin >> l[i] >> r[i] >> x[i];
    }
    dp[1][0][0]=1;
    dp[0][1][0]=1;
    dp[0][0][1]=1;
    for(int k=0;k<N;k++){
        for(int i=0;i<k;i++){
            for(int j=0;j<k;j++){
                dp[k+1][i][j]+=dp[k][i][j]%=mod;
                dp[k][k+1][j]+=dp[k][i][j]%=mod;
                dp[k][i][k+1]+=dp[k][i][j]%=mod;
                dp[k+1][k][j]+=dp[i][k][j]%=mod;
                dp[i][k+1][j]+=dp[i][k][j]%=mod;
                dp[i][k][k+1]+=dp[i][k][j]%=mod;
                dp[k+1][i][k]+=dp[j][i][k]%=mod;
                dp[j][k+1][k]+=dp[j][i][k]%=mod;
                dp[j][i][k+1]+=dp[j][i][k]%=mod;
            }
        }
        for(int s=0;s<M;s++){
            if(r[s]!=k+1) continue;
            for(int i=0;i<=k;i++){
                for(int j=0;j<=k;j++){
                    int cnt=1;
                    cnt+=(l[s]<=i)+(l[s]<=j);
                    if(cnt!=x[s]){
                        dp[k+1][i][j]=0;
                        dp[i][k+1][j]=0;
                        dp[j][i][k+1]=0;
                    }
                }
            }
        }
    }
    LL ans=0;
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            ans+=dp[N][i][j]+dp[i][N][j]+dp[j][i][N];
            ans%=mod;
        }
    }
    cout << ans%mod << endl;
    return 0;
}


Measured memory_bytes: 217344
# ITP1_5_B
x = []
while True:
    h, w = (int(y) for y in input().split())
    if h == 0 and w ==0:
        break
    x += [[h, w]]
for i in range(len(x)):
    print('#' * x[i][1])
    for j in range(x[i][0] - 2):
        print('#' +'.' * (x[i][1] - 2) + '#')
    print('#' * x[i][1])
    print('')


Measured memory_bytes: 5624
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b,c=0,d=0,e=0;
  cin >> a >> b;
  c += a+b;
  d += a-b;
  e += a*b;
  cout << max(c,max(d,e)) << endl;
}


Measured memory_bytes: 3608
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int k = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		sc.close();
		
		long biscket=1;
		
		if(a > b - 2) {
			System.out.println(k+1);
			return;
		}
		
		if(k < a) {
			System.out.println(k+1);
			return;
		}
		
		biscket += a-1;
		k -= a-1;
		
		if(k%2 == 1) {
			biscket++;
			k--;
		}
		for(int i=0;i<k;i=i+2) {
			biscket = biscket - a + b;
		}

		System.out.println(biscket);
	}

}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ordered_set tree<pair<int,int>, null_type,less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
using namespace __gnu_pbds;
#define int long long int
#define pb push_back
#define vec vector<int>
#define fo(i, n) for (int i = 0; i < n; i++)
#define foo(i, a, b) for (int i = a; i < b; i++)
#define mp make_pair
#define deb(x) cout << #x << " --> " << x << endl;

#define deb1a(v)                  \
    cout << #v << "--->" << endl; \
    for (auto it : v)             \
        cout << it << " ";        \
    cout << endl;
#define deb2a(v)                  \
    cout << #v << "--->" << endl; \
    for (auto it : v)             \
    {                             \
        for (auto it1 : it)       \
        {                         \
            cout << it1 << " ";   \
        }                         \
        cout << endl;             \
    }
#define deb3a(v) cout << #v << "-->" << endl; for(auto it:v){\
cout << it.fi << " " << it.se << endl;}


#define mod 1000000007
#define so(v) sort(v.begin(),v.end())
#define fi first
#define se second
//#define endl "\n"
int power(int x, unsigned int y, int p){ int res = 1;x = x % p;while (y > 0)  { if (y & 1)res = (res*x) % p;y = y>>1;  x = (x*x)% p;} return res;}
int mI(int a, int m)  {return power(a, m - 2, m);}



int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int i;
    while(1){
       if(i%2==0){
           c -= b;
       }
       else{
           a -= d;
       }
       if(c<=0||a<=0)
           break;
       i++;
    }
    if(i%2==0)
        cout << "Yes";
    else
    {
        cout << "No";
    }
    

   

}

Measured memory_bytes: 3652
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <ctype.h>
#include <stdint.h>
#include <string.h>
#include <wchar.h>

#define MOD_VAL (1000000007)

#define N_MAX (100)
#define P_MAX (100)
#define DP_ARRAY_SIZE (N_MAX * P_MAX / 32 + 1)

#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define ABS(a) ((a) < 0 ? -(a) : (a))
#define ABSS(a, b) ((a) > (b) ? (a) - (b) : (b) - (a))

int compare_f(const void *a, const void *b) {
	return *((int64_t *)a) < *((int64_t *)b) ? -1 : 1;
}

int compare_f2(const void *a, const void *b) {
	return *((uint64_t *)a) > *((uint64_t *)b) ? -1 : 1;
}

static size_t comb(const size_t n, const size_t r) {
	size_t result = 1;

	for (size_t i = 0; i < r; i++) {
		result *= n - i;
		result /= i + 1;
	}

	return result;
}

static uint64_t combU64(const uint64_t n, const uint64_t r) {
	uint64_t result = 1;

	for (uint64_t i = 0; i < r; i++) {
		result *= n - i;
		result /= i + 1;
	}

	return result;
}

static uint64_t gcd(uint64_t m, uint64_t n)
{
	uint64_t temp;

	while (m%n != 0) {
		temp = n;
		n = m % n;
		m = temp;
	}

	return n;
}

int main(void) {
	uint64_t N;

	scanf("%"PRIu64, &N);

	uint64_t result = 1;
	for (uint64_t i = 1; i <= N; i++) {
		result = (result * i) % MOD_VAL;
	}

	printf("%zu\n", result);

	return 0;
}


Measured memory_bytes: 128
import java.sql.Array;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        Arrays.sort(a);
        int[] high;
        int[] low = new int[n / 2];
        if (n % 2 == 0) {
            high = new int[n / 2];
        } else {
            high = new int[(n / 2) + 1];
        }
        for(int i = 0;i < n / 2;i ++){
            low[i] = a[i];
        }
        int j = 0;
        for(int i = n / 2;i < n;i ++){
            high[j] = a[i];
            j ++;
        }
        int[] answer = new int[n];
        answer[0] = high[0];
        if(n % 2 == 0){
            int k = 1;
            //奇数番目にlowを入れる
            for(int i = 0;i < n / 2;i ++){
                answer[k] = low[i];
                k += 2;
            }
            //偶数番目にhigh
            k = 2;
            for(int i = 1;i < n / 2;i ++){
                answer[k] = high[(n / 2) - i];
                k += 2;
            }
        }else{
            //問題あり
            int k = 2;
            //偶数番目にlowを入れる
            for(int i = 0;i < n / 2;i ++){
                answer[k] = low[i];
                k += 2;
            }
            //奇数番目にhigh
            k = 1;
            for(int i = 1;i < (n / 2) + 1;i ++){
            answer[k] = high[(n / 2) + 1 - i];
            k += 2;
            }
        }
        double ans = 0;
        for(int i = 0;i < n - 1;i ++){
            int sa = Math.abs(answer[i + 1] - answer[i]);
            ans += sa;
            //System.out.println(answer[i]);
        }
        //System.out.println(answer[n - 1]);
        if(n % 2 == 0){
            int k = 1;
            //奇数番目にlowを入れる
            for(int i = 0;i < n / 2;i ++){
                answer[k] = low[i];
                k += 2;
            }
            //偶数番目にhigh
            k = 2;
            for(int i = 1;i < n / 2;i ++){
                answer[k] = high[(n / 2) - i];
                k += 2;
            }
        }else{
            //問題あり
            int k = 1;
            //奇数番目にlowを入れる
            for(int i = 0;i < n / 2;i ++){
                answer[k] = low[i];
                k += 2;
            }
            //偶数番目にhigh
            k = 2;
            for(int i = 1;i < (n / 2) + 1;i ++){
            answer[k] = high[(n / 2) + 1 - i];
            k += 2;
            }
            double tmpans = 0;
            for(int i = 0;i < n - 1;i ++){
                int sa = Math.abs(answer[i + 1] - answer[i]);
                tmpans += sa;
                //System.out.println(answer[i]);
            }
            if(tmpans > ans){
                ans = tmpans;
            }
        }
        System.out.println(Math.round(ans));
    }
}

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

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

const int INF = 1e9;
const ll INFLL = 1e18;
const int MOD = 1e9 + 7;
const int NIL = -1;
const ld PI = acosl(-1);

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

int main(){
	string s;
	cin >> s;
	int Q; cin >> Q;
	string F = "";
	string B = "";
	bool isRev = false;
	rep(i, Q){
		int t; cin >> t;
		if(t == 1){
			isRev = !isRev;
		} else if(t == 2){
			int f; cin >> f;
			char c; cin >> c;
			if(f == 2 && !isRev) B.push_back(c);
			else if(f == 1 && isRev) B.push_back(c);
			else F.push_back(c);
		}
	}
	reverse(all(F));
	string ans = F + s + B;
	if(isRev) reverse(all(ans));

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

Measured memory_bytes: 1348
# coding: utf-8

# 14:29-14:34


def main():
    N = int(input())
    A = list(map(int, input().split()))
    ans = [0] * N

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


main()
# print(main())


Measured memory_bytes: 32372
from collections import Counter

N = int(input())
A = list(map(int, input().split()))
Q = int(input())
Ct = Counter(A)
ans = 0
for item in Ct.items():
    ans += item[0]*item[1]
for _ in range(Q):
    B, C = list(map(int, input().split()))
    B_n = Ct[B]
    ans += (C-B)*B_n
    print(ans)
    Ct[C] += Ct[B]
    Ct[B] = 0

Measured memory_bytes: 90252
#include <algorithm>
#include <cassert>
#include <climits>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;

const int INF = 1e9;
const long long LINF = 1e18;
const double PI=3.14159265358979323846;

typedef priority_queue<int, vector<int>, greater<int>> priority_queue_asc;

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

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

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

    int ans = 0;
    for (int i = 0; i < K; i++) {
        ans += p[i];
    }

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


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

int main() {
  int n;
  std::cin >> n;
  std::vector<int> a(n), elm(n, 0);
  for (int &e : a) {
    std::cin >> e;
    elm[e]++;
  }
  
  const int min = *std::min_element(a.begin(), a.end());
  const int max = min * 2 - (elm[min] == 2);
  
  bool ans = (elm[min] < 3);
  for (int i = min + 1; i <= max; i++) {
    ans &= (elm[i] > 1);
  }
  for (int i = max + 1; i < n; i++) {
    ans &= (elm[i] == 0);
  }
  
  std::cout << (ans ? "Possible" : "Impossible") << '\n';
  
  return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 10;
int a[MAXN];
int32_t main () {
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    a[n] = 0;
    a[n + 1] = 1e9 + 10;
    sort(a, a + n + 2);
    reverse(a, a + n + 2);
    int now = 0;
    while (a[now] > now)
        ++now;
    bool k = false;
    if (a[now] != now && ((a[now - 1] + now - 1) & 1))
        k = true;
    if (a[now] == now - 1 || a[now] == now) {
        while (a[now] == a[now + 1])    
            ++now;
        if ((now + a[now]) & 1)
            k = true;
    }
    cout << (k ? "First" : "Second");
    return 0;
}

Measured memory_bytes: 640
using namespace std;
#include <iostream>
#include <string>
#include <set>
#include <functional>
#include <vector>
#include <algorithm>
#include <stdio.h>
#define INF 1<<12
typedef pair<int,int> p;
int main()
{
	int n,d[10][10];
	while(cin>>n&&n){
		fill(d[0],d[10],INF);
		int a,b,c;
		for(int i=0;i<n;i++){
			cin>>a>>b>>c;
			d[a][b]=d[b][a]=c;
		}
		for(int i=0;i<10;i++)d[i][i]=0;
		for(int k=0;k<10;k++)
			for(int i=0;i<10;i++)
				for(int j=0;j<10;j++)
					d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
		int ans[10]={};
		vector<p> res;
		for(int i=0;i<10;i++)
			for(int j=0;j<10;j++)
				if(d[i][j]<INF)ans[i]+=d[i][j];
		for(int i=0;i<10;i++){
			if(ans[i]!=0)res.push_back(p(ans[i],i));
			//printf("ans[%d]:%d\n",i,ans[i]);
		}
		sort(res.begin(),res.end());
		cout<<res.front().second<<" "<<res.front().first<<endl;
	}

    return 0;
}

Measured memory_bytes: 1200
# -*- coding: utf-8 -*-

import sys
if sys.version_info.minor >= 5: from math import gcd
else: from fractions import gcd

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N, K = MAP()
A = LIST()

gcds = 0
for i in range(N):
    gcds = gcd(gcds, A[i])

if K <= max(A) and K % gcds == 0:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')


Measured memory_bytes: 16232
# -*- coding: utf-8 -*-
"""
Pasta
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0568

"""
import sys
from collections import Counter

def solve(n, decided):
    status = Counter({(0, 0, 0): 1})
    for d in range(1, n+1):
        u = Counter()
        pastas = range(1, 4)
        if decided and decided[-1][0] == d:
            pastas = [decided.pop()[1]]
        for k, v in status.items():
            _, d2, d3 = k
            for p in pastas:
                if not d2 == d3 == p:
                    u[(d2, d3, p)] += v
        status = Counter({k: v % 10000 for k, v in u.items()})
    return sum(status.values()) % 10000


def main(args):
    n, k = map(int, input().split())
    decided = sorted([list(map(int, input().split())) for _ in range(k)], reverse=True)
    ans = solve(n, decided)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])



Measured memory_bytes: 6012
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
# include <bitset>
# include <random>
# include <chrono>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
typedef pair<LL, LL> P;
constexpr int INF = 2000000000;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
# define ALL(x)      (x).begin(),(x).end()
# define UNIQ(c)     (c).erase(unique(ALL((c))),(c).end())
# define mp          make_pair
# define eb          emplace_back
# define FOR(i,a,b)  for(int i=(a);i<(b);i++)
# define RFOR(i,a,b) for(int i=(a);i>=(b);i--)
# define REP(i,n)    FOR(i,0,n)
# define INIT        std::ios::sync_with_stdio(false);std::cin.tie(0)

int n, x;

int main() {
	cin >> n >> x;
	if (x == 1 || x == n * 2 - 1) {
		cout << "No" << endl;
		return 0;
	}
	else {
		cout << "Yes" << endl;
		int d = n - x;
		n = 2 * n - 1;
		REP(i, n) {
			cout << (i - d + n) % n + 1 << endl;
		}
	}
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define rREP(i,m,n) for(ll i = (m); i >= (n); i--)
#define ALL(c) (c).begin(), (c).end()
#define print(x) cout << (x) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;

vector<ll> divisor(ll n)
{
    vector<ll> ret;
    for (ll i=1;i*i<=n;i++)
    {
        if (n%i==0)
        {
            ret.push_back(i);
            if (i*i!=n) ret.push_back(n/i);
        }
    }
    sort(ret.begin(), ret.end());
    return (ret);
}

ll solve(ll n, ll k)
{
    if (n%k==0)
    {
        while(n%k==0) n /= k;
        return n%k;
    }
    else
    {
        return n%k;
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll n;
    cin >> n;
    vector<ll> div = divisor(n);
    vector<ll> d = divisor(n-1);

    vector<ll> ans;
    for (auto itr=div.begin();itr!=div.end();++itr)
    {
        if (*itr==1) continue;
        if (solve(n, *itr)==1) ans.push_back(*itr);
    }
    for (auto itr=d.begin();itr!=d.end();++itr)
    {
        if (*itr==1) continue;
        if (solve(n, *itr)==1) ans.push_back(*itr);
    }
    cout << ans.size() << endl;
}




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

#define ll long long
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    int a,b,c;cin >> a >> b >> c;
    cout << c <<" " << a<<" " << b<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a[100][100];
	int d,b,c;
	cin>>d>>b>>c;
	a[1][1]=d;
	a[1][2]=b;
	a[2][2]=c;
	int s=a[2][2]*3;
	a[3][2]=s-a[2][2]-a[1][2];
	a[1][3]=s-a[1][1]-a[1][2];
	a[3][1]=s-a[1][3]-a[2][2];
	a[2][1]=s-a[1][1]-a[3][1];
	a[2][3]=s-a[2][2]-a[2][1];
	a[3][3]=s-a[1][3]-a[2][3];
	for(int i=1;i<=3;i++)
	{
		for(int j=1;j<=3;j++)
		{
			cout<<a[i][j]<<" ";
		}
		cout<<endl;
	}
	return 0;
}

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

int main(){
  
  int X,A,N;

  cin >> N >> X;

  vector<int> L(N,0);

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

  int length = 0;
  int count = 0;
  for(int i=0; i < N+1; i++){
    if(X >= length){
      count++;
      if(i != N){
        length += L[i];
      }
    }else{
      break;
    }
  }
  cout << count << endl;
  return(0);
}


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

using ll=long long;
#define int ll

#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
#define REP(i,b) FOR(i,0,b)
#define MP make_pair
#define PB push_back
#define ALL(x) x.begin(),x.end()
#define REACH cerr<<"reached line "<<__LINE__<<endl
#define DBG(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl

using pi=pair<int,int>;
using vi=vector<int>;
using ld=long double;

template<class T,class U>
ostream& operator<<(ostream& os,const pair<T,U>& p){
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator <<(ostream& os,const vector<T>& v){
	os<<"[";
	REP(i,(int)v.size()){
		if(i)os<<",";
		os<<v[i];
	}
	os<<"]";
	return os;
}

int read(){
	int i;
	scanf("%lld",&i);
	return i;
}

void printSpace(){
	printf(" ");
}

void printEoln(){
	printf("\n");
}

void print(int x,int suc=1){
	printf("%lld",x);
	if(suc==1)
		printEoln();
	if(suc==2)
		printSpace();
}

string readString(){
	static char buf[3341919];
	scanf("%s",buf);
	return string(buf);
}

char* readCharArray(){
	static char buf[3341919];
	static int bufUsed=0;
	char* ret=buf+bufUsed;
	scanf("%s",ret);
	bufUsed+=strlen(ret)+1;
	return ret;
}

template<class T,class U>
void chmax(T& a,U b){
	if(a<b)
		a=b;
}

template<class T,class U>
void chmin(T& a,U b){
	if(a>b)
		a=b;
}

template<class T>
T Sq(const T& t){
	return t*t;
}

const int inf=LLONG_MAX/3;

signed main(){
	int n=read(),m=read()/2;
	if(n>=m)cout<<m<<endl;
	else cout<<(n+m)/2<<endl;
}


Measured memory_bytes: 256
public class Main{
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
/*answer*/
    int n, q, m;
    int[] a;
    int i;

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

    q = sc.nextInt();
    for(i = 0;i < q;i++){
      m = sc.nextInt();
      if(isin(a, m, n))out.println("yes");
      else out.println("no");
    }

    sc.close();
  }
  public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  }
  private static boolean isin(int[] a, int m, int n){
    if(m == 0)return true;
    else if(n == 0)return false;
    else return (isin(a, m, n - 1) || isin(a, m - a[n - 1], n - 1));
  }
}

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

using namespace std;

int main() {

	bool h = false;

	int n;
	while (cin >> n) {
		if (n == 0) {
			break;
		}
		if (h) {
			cout << endl;
		}
		else {
			h = true;
		}
		vector<int> a(4);
		int sum = 0;
		for (int i = 0; i < 4; i++) {
			cin >> a[i];
			sum += a[i];
		}
		bool h2 = true;
		vector<int> b = a;
		
		for (int i = 0; i <= a[0]; i++) {
			for (int j = 0; j <= a[1]; j++) {
				for (int k = 0; k <= a[2]; k++) {
					for (int l = 0; l <= a[3]; l++) {
						int shiharai = i * 10 + j * 50 + k * 100 + l * 500;
						if (shiharai >= n) {
							int oturi = shiharai - n;
							vector<int> c(4, 0);
							c[3] = oturi / 500;
							oturi %= 500;
							c[2] = oturi / 100;
							oturi %= 100;
							c[1] = oturi / 50;
							oturi %= 50;
							c[0] = oturi / 10;
							oturi %= 10;
							if (oturi==0 && c[0] * i + c[1] * j + c[2] * k + c[3] * l == 0) {
								c[0] += a[0] - i;
								c[1] += a[1] - j;
								c[2] += a[2] - k;
								c[3] += a[3] - l;
								if (h2) {
									sum = c[0] + c[1] + c[2] + c[3];
									b = c;
									h2 = false;
								} else if (c[0] + c[1] + c[2] + c[3] < sum) {
									sum = c[0] + c[1] + c[2] + c[3];
									b = c;
								}
							}
						}
					}
				}
			}
		}

		int c2[4] = { 10,50,100,500 };

		for (int i = 0; i < 4; i++) {
			if (a[i]-b[i] > 0) {
				cout << c2[i] << ' ' << a[i]-b[i] << endl;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 3108
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

int main(){
	int n;
	cin >> n;
	cout << n * n * n << endl;
}


Measured memory_bytes: 3096
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <array>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <cstdint>
#include <unordered_set>
#include <ctime>
#include <numeric>
typedef long long int llint;

int main(void){

  std::string s;
  std::cin >> s;

  if(s.size()%2 != 0){
    std::cout << "No" << std::endl;
    return 0;
  }

  for(int i=0; i<s.size(); i+=2){
    if(s[i]!='h' || s[i+1]!='i'){
      std::cout << "No" << std::endl;
      return 0;
    }
  }

  std::cout << "Yes" << std::endl;
  return 0;
}


Measured memory_bytes: 256
//Bismillahir Rahmanir Rahim
//In the name of Allah the Most Merciful
//Astagfirullahil laji Rabbi Minkulli Jamio
#include<bits/stdc++.h>
#include<math.h>
using namespace std;
#define int   long long  int
#define double  long double
#define mod 1000000007
#define rp(i,a,b)  for (int i = a; i <= b; i++)
#define hi ios_base :: sync_with_stdio(false); cin.tie(0);cout.tie(0);RRSRRS
int i,j,k;
main()
{
   string s;
   cin>>s;
   int c=0;
   int a[4];
   k=0;
   for(i=0;i<=3;i++)

 {
     if(s[i]=='R') c++;
     else
     {
         a[k]=c;k++;
         c=0;
     }
 }
 // for(j=0;j<k;j++) cout<<a[j]<<' ';
  sort(a,a+k);
  cout<<a[k-1]<<endl;

}


Measured memory_bytes: 3584
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
#include <functional>
#include <array>

using namespace std;

bool comp(int a, int b) {
	return a < b;
}

int main(void)
{
	int n;
	cin >> n;
	vector<int> p(n);
	for (int i = 0; i < n; i++) {
		cin >> p[i];
	}
	
	sort(p.begin(), p.end(), comp);

	int temp = n / 2;
	cout << p[temp] - p[temp - 1] << endl;

	return 0;
}

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

int main(){
  int n,m,ans;
  ans=0;
  cin >> m >> n;
  vector<int> a(n,0);
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  for(int i=0;i<n;i++){
    ans=ans+a[i];
  }
  if(m>ans)
    cout << "No" << endl;
  else
    cout << "Yes" << endl;
}


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

#ifdef _DEBUG
    #include "/home/v-o_o-v/deb.h"
    #define deb(x...)cerr << "[" << #x << "] = [";_print(x);
#else
    #define deb(x...)
#endif

#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int cnt[55];

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    int n, m;
    cin >> n >> m;
    for(int i = 0; i < n; i++){
        int k;
        cin >> k;
        for(int i = 0; i < k; i++){
            int x;
            cin >> x;
            cnt[x]++;
        }
    }
    int ans = 0;
    for(int i = 1; i <= m; i++)if(cnt[i] == n)ans++;
    cout << ans << '\n';
    return 0;
}
// Write Here


Measured memory_bytes: 3568
#include <bits/stdc++.h>
using namespace std;
int n;
string s[100];
int cnt[26], cnt1[26];
int main() {
    memset (cnt1, 0x3f, sizeof(cnt1));
    cin >> n;
    for (int i = 1; i <= n; ++i) cin >> s[i];
    for (int i = 1; i <= n; ++i) {
        memset (cnt, 0, sizeof(cnt));
        for (int j = 0; j < s[i].size(); ++j)
                    ++cnt[s[i][j] - 'a'];
        for (int j = 0; j < 26; ++j)
            cnt1[j] = min(cnt1[j], cnt[j]);
    }
        

    for (int i = 0; i < 26; ++i) 
        for (int j = 0; j < cnt1[i]; ++j) putchar(i + 'a');
    
    return 0; 
}

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

#include<cstdio>
#include<cstring>
#include<cctype>
#include<cmath>
#include<cstdlib>

#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<bitset>
#include<complex>
using namespace std;

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


//4-side
//int xx[] = {0,0,-1,1};
//int yy[] = {-1,1,0,0};
//6-side hexagonal
//int xx[] = {2,-2,1,1,-1,-1};
//int yy[] = {0,0,1,-1,1,-1};

#define popc(a) (__builtin_popcount(a))
//ll bigmod(ll a,ll b,ll m){if(b == 0) return 1%m;ll x = bigmod(a,b/2,m);x = (x * x) % m;if(b % 2 == 1) x = (x * a) % m;return x;}
ll BigMod(ll B,ll P,ll M){ ll R=1%M; while(P>0) {if(P%2==1){R=(R*B)%M;}P/=2;B=(B*B)%M;} return R;} /// (B^P)%M

#define MX 100005
#define inf 100000000

const double pi = acos(-1.0);
const ll mod = 1000000007ll;

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    ll n;
    scanf("%lld", &n);
    if (n == 1) {
        printf("0\n");
        return 0;
    }
    printf("%lld\n", ((BigMod(10, n, mod) - 2 * BigMod(9, n, mod) + BigMod(8, n, mod))%mod + mod)%mod);
    return 0;
}


Measured memory_bytes: 3828
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  int a[100];
  cin>>n;
  for(int i=0;i<n;i++)cin>>a[i];

  int ans=1000000000;
  for(int i=-100;i<=100;i++){
    int sum=0;
    for(int j=0;j<n;j++){
      sum+=(a[j]-i)*(a[j]-i);
    }
    ans=min(sum,ans);
  }

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


Measured memory_bytes: 256
N = int(input())
S = ['AC', 'WA', 'TLE', 'RE']
a = 0
b = 0
c = 0
d = 0
for i in range(N):
    user = input()
    if user == 'AC':
        a += 1
    elif user == 'WA':
        b += 1
    elif user == 'TLE':
        c += 1
    elif user == 'RE':
        d += 1
print(f"AC x {a}\nWA x {b}\nTLE x {c}\nRE x {d}")

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

int main() {
  string S, T; cin >> S >> T;
  int A, B; cin >> A >> B;
  string U; cin >> U;
  if (S == U) A--;
  else B--;

  printf("%d %d\n", A, B);

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repeq(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define rep1(i,x,n) for(int (i)=(x);(i)<(int)(n);(i)++)
#define rep1eq(i,x,n) for(int (i)=(x);(i)<=(int)(n);(i)++)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
using namespace std;
using ll = long long;
using Int = long long;

const int MOD = 1000000007;
const ll INF = numeric_limits<ll>::max();
const int inf = 1e8;
typedef pair<int,int> P;
typedef std::priority_queue<int> IntPrioQueue;
typedef std::priority_queue<int, std::vector<int>, std::greater<int> > IntReversePrioQueue;

//少数点表示
//cout << std::fixed << std::setprecision(14) << 値

int main(){
    cin.tie( 0 ); ios::sync_with_stdio( false );
    int k;
    cin >> k;
    ll ans = 0;
    rep1eq(i,1,k){
        rep1eq(j,1,k){
            rep1eq(l,1,k){
                int gcd_ = __gcd(__gcd(i,j),l);
                ans += gcd_;
            }
        }
    }

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

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++i)
#define pb push_back
#define ALL(s) s.begin(),s.end()
#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define SZ(s) int(s.size())
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;

int main(){FIN;
	int x,n; cin>>x>>n;
	vector<int> a(n);
	fore(i,0,n) cin>>a[i];
	sort(ALL(a));
	int ans=1e9,wh=-1;
	fore(i,0,102){
		auto it=lower_bound(ALL(a),i);
		if(it!=a.end()&&*it==i)continue;
		if(abs(i-x)<ans) ans=abs(i-x),wh=i;
	}
	cout<<wh<<"\n";
}

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

const int MAXN = 20;
int H, W;
char S[MAXN][MAXN + 1];
int N;
int num[MAXN][MAXN];
int di[] = {0, 1, 0, -1};
int dj[] = {1, 0, -1, 0};

int main() {
    cin >> H >> W;
    for(int i = 0; i < H; ++i) cin >> S[i];
    // numbering (i, j) -> idx
    for(int i = 0; i < H; ++i) {
        for(int j = 0; j < W; ++j) {
            if(S[i][j] == '.') num[i][j] = N++;
        }
    }
    vector<vector<int>> dist(N, vector<int>(N, INT_MAX));
    for(int i = 0; i < N; ++i) dist[i][i] = 0;
    // make_edges for all (i, j)s
    for(int i = 0; i < H; ++i) {
        for(int j = 0; j < W; ++j) {
            if(S[i][j] == '#') continue;
            for(int k = 0; k < 4; ++k) {
                int ni = i + di[k], nj = j + dj[k];
                if(ni >= 0 && ni < H && nj >= 0 && nj < W && S[ni][nj] == '.') {
                    dist[num[i][j]][num[ni][nj]] = 1;
                }
            }
        }
    }
    // floyd-washal
    for(int k = 0; k < N; ++k) {
        for(int i = 0; i < N; ++i) {
            for(int j = 0; j < N; ++j) {
                if(dist[i][k] != INT_MAX && dist[k][j] != INT_MAX) {
                    dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
                }
            }
        }
    }
    int ans = 0;
    for(int i = 0; i < N; ++i) {
        for(int j = 0; j < N; ++j) {
            ans = max(ans, dist[i][j]);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 896
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <x86intrin.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define chmin(x,y) x = min(x, y)
#define chmax(x,y) x = max(x, y)
#define V vector
vector<int> dx = {-1, 1,  0, 0, -1, -1,  1, 1};
vector<int> dy = { 0, 0, -1, 1, -1,  1, -1, 1};

int main () {
    int x; cin >> x;
    if (x >= 30) puts("Yes");
    else puts("No");

    return 0;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main() {
 int N;
 cin>>N;
 int answer=0;
 if(N>9){
     answer+=9;
     if(N>999){
         answer+=900;
         if(N>9999){
             if(N!=100000)
             answer+=N-9999;
             else 
             answer+=N-10000;
         }
     }
     else if(N>99){
         answer+=N-99;
     }
     
 }
 else
 {
     answer=N;
 }
 cout<<answer<<endl;
 }


Measured memory_bytes: 256
N, M = map(int, input().split())

war = []

for _ in range(M) :
    A, B = map(int, input().split())
    war.append((A,B))

war.sort(key=lambda A : A[0])

ans = 1
left, right = war[0]

for i in range(1, M) :
    A, B = war[i]
    if right <= A :
        ans += 1
        left = A
        right = B
        continue
    left = A
    right = min(right, B)

print(ans)


Measured memory_bytes: 18212
#include<iostream>

using namespace std;

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

	if ((A + B) % 3 == 0 || A % 3 == 0 || B % 3 == 0) {
		cout << "Possible" << endl;
		return 0;
	}
	cout << "Impossible" << endl;

	return 0;
}

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

using namespace std;
typedef long long ll;

int main(){
  string S;
  cin >> S;
  if(S=="SUN") cout << 7 << endl;
  if(S=="MON") cout << 6 << endl;
  if(S=="TUE") cout << 5 << endl;
  if(S=="WED") cout << 4 << endl;
  if(S=="THU") cout << 3 << endl;
  if(S=="FRI") cout << 2 << endl;
  if(S=="SAT") cout << 1 << endl;
}


Measured memory_bytes: 3156
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
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;
}
template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}
int main()
{
    ll N;
    cin >> N;
    if(N==1)
    {
        cout<<"Yes"<<endl;
        cout<<"2\n1 1\n1 1\n";
        return 0;
    }
    for (ll i = 1; i <= N; i++)
    {
        if (i * (i - 1) == N * 2)
        {
            cout<<"Yes"<<endl;
            cout<<i<<endl;
            for (size_t k = 0; k < i-1; k++)
            {
                int cur = 1;
                int l=0;
                cout<<i-1<<" ";
                for (; l < k; l++)
                {
                    cur += l+1;
                }
                for (size_t s = 0; s < k; s++)
                {
                    cout<<cur<<" ";
                    cur++;
                }
                int num = i-1-k;
                for (size_t n = 0; n < num; n++)
                {
                    
                    cout<<cur<<" ";
                    l++;
                    cur += l;
                    
                }
                cout<<endl;
            }
            cout<<i-1<<" ";
            int cur = 1,cnt = 1;
            for (size_t j = 0; j < i-1; j++)
            {
                cout<<cur<<" ";
                cnt ++;
                cur += cnt;
            }
            
             return 0;
        }
       
    }

    cout << "No" << endl;
    return 0;
}

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

int main(){
    int n,q;
    cin >> n;

    vector<int> a(n),b(n);

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

    cin >> q;

    vector<int> x(q),y(q);

    for(int i=0;i<q;i++){
        cin >> x[i] >> y[i];
    }



    sort(b.begin(),b.end());
    int d = 0;

    for(int i=0;i<n;i++){
        if(a[i]!=b[i]){
            d++;
        }
    }

    if(d==0){
        cout << 0 << endl;
        return 0;
    }


    for(int i=0;i<q;i++){
        if(a[x[i]-1]!=b[x[i]-1]) d--;
        if(a[y[i]-1]!=b[y[i]-1]) d--;

        swap(a[x[i]-1],a[y[i]-1]);

        if(a[x[i]-1]!=b[x[i]-1]) d++;
        if(a[y[i]-1]!=b[y[i]-1]) d++;

        if(d==0){
            cout << i+1 << endl;
            return 0;
        }
    }

    cout << -1 << endl;
}


Measured memory_bytes: 7512
import java.util.*;

public class Main {

    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        Arrays.sort(a);
        int sum = 0;
        for (int i = 0; i < n - 1; i++) {
            sum += a[i];
        }
        if (sum > a[n - 1]) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }

}


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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;

#define INF INT_MAX/3

#define MAX_N 1000

string s;

int main(){
	cin.sync_with_stdio(false);
	cin>>s;
	stack<char> st;
	int res=0;
	rep(i,s.length()){
		if(s[i]=='S')st.push('S');
		else{
			if(!st.empty()){
				res++;
				st.pop();
			}
		}
	}
	cout<<s.length()-2*res<<endl;
	return 0;
}


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

int main() {
    int N;
    cin >> N;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];

    vector<ll> B(N);
    rep(i, N) B[i] = A[i] - (i + 1);
    sort(B.begin(), B.end());

    ll b = B[N/2];
    ll ans = 0;
    rep(i, N) {
        ans += abs(B[i] - b);
    }

    // if (b % 2 == 0) {
    //     b = B[N/2-1];
    //     int ans2 = 0;
    //     rep(i, N) {
    //         ans2 += abs(B[i] - b);
    //     }
    //     ans = min(ans, ans2);
    // }

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

Measured memory_bytes: 6388
#include<bits/stdc++.h>
#define F first
#define S second
#define endl '\n'

using namespace std;
typedef pair<int, int> P;
typedef long long LL;

static const int INF = INT_MAX;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int len = (s.size() - 1) / 2;

    while(len > 0) {
        bool flag = true;
        for(int i = 0; i < len; ++i) {
            if(s[i] != s[i + len]) { flag = false; break; }
        }
        if(flag) { cout << len * 2 << endl; break; }
    --len;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long int N,A,B;
  cin >> N >> A >> B;
  if(A>B){
    cout << 0 << endl;
  }
  if(A==B){
    cout << 1 << endl;
  }
  if(A<B){
    if(N == 1){
      cout << 0 << endl;
    }
    if(N == 2){
      cout << 1 << endl;
    }
    if(N >= 3){
      cout << (N-2)*(B-A)+1 << endl;
    }
  }
}

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

int main() {
	int N,mn=100,mx=-100,r=INF;
	cin >> N;
	vector<int> a(N);
	rep(i,N) {
		cin >> a.at(i);
		mn = min(a.at(i),mn);
		mx = max(a.at(i),mx);
	}

	rep(i,mx-mn+1) {
		int t=mn+i, s=0;
		rep(j,N)
			s += (a.at(j)-t)*(a.at(j)-t);
		r = min(r, s);
	}

	cout << r << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

int main(void){
  string s;
  cin >> s;
  if(s[2]==s[3]&&s[4]==s[5]) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

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

long H;

void maxHeapify(long A[], long i){
	long l = 2 * i;
	long r = 2 * i + 1;

	long largest;
	if (l <= H && A[l] > A[i]){
		largest = l;
	}
	else {
		largest = i;
	}
	if (r <= H && A[r] > A[largest]){
		largest = r;
	}

	if (largest != i){
		swap(A[i], A[largest]);
		maxHeapify(A, largest);
	}
}

void buildMaxHeap(long A[]){
	for (long i = H / 2; i > 0; i--){
		maxHeapify(A, i);
	}
}

int main(){
	cin >> H;
	long A[500000];
	for (long i = 1; i <= H; i++){
		cin >> A[i];
	}
	buildMaxHeap(A);
	for (long i = 1; i <= H; i++){
		cout << " " << A[i];
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 5064