akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=5e18;
 
int main() {
  ll n;
  string s;
  cin >> n >> s;
  string a,b;
  a=s.substr(0,n);
  b=s.substr(n,n);
  reverse(b.begin(),b.end());
  map<pair<string,string>,ll> cnta,cntb; 
  for(ll i=0;i<(1<<n);i++) {
    bitset<20> bita(i);
    string ea="",oa="";
    for(ll j=0;j<n;j++) {
      if(bita.test(j)) {
        ea=ea+a[j];
      }
      else {
        oa=oa+a[j];
      }
    }
    cnta[{ea,oa}]++;
  }
  for(ll i=0;i<(1<<n);i++) {
    bitset<20> bita(i);
    string ea="",oa="";
    for(ll j=0;j<n;j++) {
      if(bita.test(j)) {
        ea=ea+b[j];
      }
      else {
        oa=oa+b[j];
      }
    }
    cntb[{ea,oa}]++;
  }
  ll ans=0;
  for(auto p:cnta) {
    ans+=p.second*cntb[p.first];
  }
  cout << ans << endl;
}

Measured memory_bytes: 104192
#include<stdio.h>

int main(void){

    int n;
    scanf("%d", &n);
    int d[4][3][10]={0};
    int i,T,K,H,t,k,h,D;

    for(i=0;i<n;i++){
        scanf("%d %d %d %d", &T, &K, &H, &D);
        d[T-1][K-1][H-1]+=D;
        //printf("->%d %d %d %d\n",T,K,H,D);
        //printf("-->%d\n",d[T-1][K-1][H-1]);
    }

    for(t=0;t<4;t++){
        for(k=0;k<3;k++){
            for(h=0;h<10;h++){
                printf(" %d",d[t][k][h]);
            }
            printf("\n");
        }
        if(t==3) break;
        printf("####################\n");
    }

    return 0;
}


Measured memory_bytes: 2108
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;
#define fast() ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define digit(N) cout << fixed << setprecision((N))

ll a, b, k;

int main()
{
    cin >> a >> b >> k;
    if (a > 0)
    {
        if (a < k)
            k -= a, a = 0;
        else
        {
            a -= k;
            k = 0;
        }
    }
    if (k > 0)
    {
        if (b < k)
        {
            k -= b, b = 0;
        }
        else
        {
            b -= k, k = 0;
        }
    }

    cout << a << " " << b << endl;
}

Measured memory_bytes: 256
def root(list_parent, x):
    if(list_parent[x] == x):
        return x
    else:
        list_parent[x] = root(list_parent, list_parent[x])
        return list_parent[x]

def unite(list_parent, x, y):
    x = root(list_parent, x)
    y = root(list_parent, y)

    if(x == y):
        return list_parent

    if x > y:
        list_parent[y] = x
    else:
        list_parent[x] = y

    return list_parent

def main():
    N, M = map(int, input().split())

    list_parent = []
    for i in range(N):
        list_parent.append(i)

    for i in range(M):
        A, B = map(int, input().split())
        list_parent = unite(list_parent, A-1, B-1)

    set_root = set()
    for i in list_parent:
        root_i = root(list_parent, i)
        if root_i not in set_root:
            set_root.add(root_i)

    print(len(set_root) - 1)

if __name__ == "__main__":
    main()

Measured memory_bytes: 18440
#include<bits/stdc++.h>
using namespace std;
int N,C,i,j,s,t,c,cs[100001],sum,ans,len;
vector<pair<int,int>>vii[31];
vector<pair<int,int>>tmp;
int main(){
  cin>>N>>C;
  for(i=0;i<N;i++){
    cin>>s>>t>>c;
    vii[c].push_back(make_pair(s,t));
  }
  for(i=1;i<=C;i++){
    sort(vii[i].begin(),vii[i].end());
    tmp.clear();
    len=vii[i].size();
    for(j=0;j<len;j++)
      if(tmp.empty()||tmp.back().second<vii[i][j].first)tmp.push_back(vii[i][j]);
      else tmp.back().second=vii[i][j].second;
    len=tmp.size();
    for(j=0;j<len;j++){
      cs[tmp[j].first]++;
      cs[tmp[j].second+1]--;
    }
  }
  for(i=0;i<100001;i++){
    sum+=cs[i];
    ans=max(ans,sum);
  }
  cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 1920
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int s[100];
int s_num=0;

void push(int x){
	s_num++;
	s[s_num] = x;
}

int pop(){
	s_num--;
	return s[s_num+1];
}

int main(){
	int p, q;
	char a[100];
	while(scanf("%s", a) != EOF){
		if(a[0]=='+'){
			p = pop();
			q = pop();
			push(q+p);
		}else if(a[0]=='-'){
			p = pop();
			q = pop();
			push(q-p);
		}else if(a[0]=='*'){
			p = pop();
			q = pop();
			push(q*p);
		}else if(a[0]=='/'){
			p = pop();
			q = pop();
			push(q/p);
		}else{
			push(atoi(a));
		}
	}

	printf("%d\n", pop());

	return 0;
}

Measured memory_bytes: 548
#include <bits/stdc++.h>
using namespace std;
int main(){
  int A, B, C;
  cin >> A >> B >> C;
  int K;
  cin >> K;
  int cnt = 0;
  while (B <= A){
    B *= 2;
    cnt++;
  }
  while (C <= B){
    C *= 2;
    cnt++;
  }
  if (cnt <= K){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3564
import java.io.*;
import java.util.*;
public class Main {
	static final int N=100005;

	public static void main(String[] args){
		InputReader in = new InputReader(System.in);
	    PrintWriter out = new PrintWriter(System.out);
	    int n=in.nextInt();
	    int c1=0,c2=0,c3=0,c4=0,x;
	    for(int i=0;i<n;i++) {
	    	x=in.nextInt();
	    	if(x%4==0) c1++;
	    	else if(x%2==0) c2++;
	    	else c3++;
	    }
        if(c2>0) c2=1;
	    if(c1-c2+1>=c3) out.println("Yes");
	    else out.println("No");
	    out.flush();
	}
	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: 37016
#include <bits/stdc++.h>
typedef long long LL;
#define SORT(c) sort((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

using namespace std;
int main(void)
{
  int n;
  cin >> n;
  LL tmp=0;
  if(!n) return 0;
  REP(i,n){
    int m;
    string s;
    cin >> m >> s >> m;
    tmp+=s=="("?m:-m;
    cout << (tmp?"No":"Yes") << endl;
  }
}

Measured memory_bytes: 3148
def max_diff(*abc)
  min, max = abc.minmax
  max - min  
end

H,W = gets.split.map(&:to_i)

if H % 3 == 0 || W % 3 == 0
  puts 0
else
  puts [ W, H,
        (0 .. H).map{|h| max_diff(W * (H - h), (W + 1) / 2 * h, W / 2 * h) }.min,
        (0 .. W).map{|w| max_diff(H * (W - w), (H + 1) / 2 * w, H / 2 * w) }.min,
        ].min
end

Measured memory_bytes: 3452
/// Containers Start
#include <algorithm>
#include <bitset>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
/// C Header Files
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <math.h>
#include <stdio.h>
/// Containers End

using namespace std;

/// Math Start
#define PI acos(-1.0)
#define Pi 3.141592653589793
#define EPS (1e-7)
#define INF (0x3f3f3f3f)
/// Math End

/// Extra Start
#define nn '\n'
#define pb push_back
#define ull unsigned long long
#define ll long long
#define MOD 1000000007
#define sz(a) int((a).size())
#define space " "
#define All(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
/// Extra End

#define rep(i, n) for (int i = 0; i < n; i++)
#define Cini(a)                                                                \
    int a;                                                                     \
    cin >> a;
#define Cinii(a, b)                                                            \
    int a, b;                                                                  \
    cin >> a >> b;
#define Ciniii(a, b, c)                                                        \
    int a, b, c;                                                               \
    cin >> a >> b >> c;
#define Cins(s)                                                                \
    string s;                                                                  \
    cin >> s;
#define Cinss(s1, s2)                                                          \
    string s1, s2;                                                             \
    cin >> s1 >> s2;
#define Cinc(c)                                                                \
    char c;                                                                    \
    cin >> c;
/// Functions End


/// Debug Start
#define deb(x) cout << #x << ": " << x << endl
#define deb2(x, y) cout << #x << ": " << x << '\t' << #y << ": " << y << endl;
#define deb3(x, y, z)                                                          \
    cout << #x << ": " << x << '\t' << #y << ": " << y << '\t' << #z << ": "   \
         << z << endl;
/// Debug End

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

/**>>>>>>>>>>>>>>>>>>> END <<<<<<<<<<<<<<<<<<**/

/// template


signed main(void) {
    cin.sync_with_stdio(false);
    cin.tie(0);
    Cins(s);
    int ansOdd=0,ansEven=0;
    //0start
    rep(i,s.length()){
        if(i%2==0){
            if(s[i]=='1')ansEven++;
        }
        if(i%2==1){
            if(s[i]=='0')ansEven++;
        }
    }
    //1start
    rep(i,s.length()){
        if(i%2==0){
            if(s[i]=='0')ansOdd++;
        }
        if(i%2==1){
            if(s[i]=='1')ansOdd++;
        }
    }
    cout << min(ansOdd,ansEven) << nn;
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <iomanip>

using namespace std;

int main() {
	int N, M;
	cin >> N >> M;
	vector<int> food(M, 0);
	for (int i = 0; i < N; i++) {
		int K;
		cin >> K;
		for (int j = 0; j < K; j++) {
			int A;
			cin >> A;
			A--;
			food[A]++;
		}
	}
	int count = 0;
	for (int i = 0; i < M; i++) {
		if (food[i] == N) count++;
	}
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 3604
#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <bitset>
#include <functional>
#include <random>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(a) ({REP(__i,1,n) cout<<a[__i]<<',';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;}
//head



#ifdef ONLINE_JUDGE
const int N = 1e6+50;
#else
const int N = 1e2+10;
#endif




int main() {
	ll a,b,c;
	cin>>a>>b>>c;
	printf("%lld\n",b+min(a+b+1,c));
}








Measured memory_bytes: 256
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, std.bitmanip;

const long MOD = 10^^9 + 7;
const long INF = 1L << 59;

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto M = s[1];
    auto Q = new Tuple!(int, int, long)[](M);
    auto G = new Tuple!(int, long)[][](N);
    auto uf = new UnionFind(N);

    foreach (i; 0..M) {
        s = readln.split.map!(to!int);
        auto L = s[0] - 1;
        auto R = s[1] - 1;
        auto D = s[2].to!long;
        uf.unite(L, R);
        G[L] ~= tuple(R, -D);
        G[R] ~= tuple(L, D);
    }

    auto ans = new long[](N);
    ans.fill(INF);
    foreach (i; 0..N) {
        if (uf.table[i] < 0) {
            ans[i] = 0;
        }
    }


    auto used = new bool[](N);

    bool dfs(int n, long d) {
        if (ans[n] != INF && d != ans[n]) return false;
        if (used[n]) return true;
        used[n] = true;
        ans[n] = d;
        foreach (m; G[n]) {
            if (!dfs(m[0], d+m[1])) return false;
        }
        return true;
    }

    foreach (i; 0..N) {
        if (uf.table[i] >= 0) continue;
        if (!dfs(i, 0)) {
            writeln("No");
            return;
        }
    }

    "Yes".writeln;
}

class UnionFind {
    int N;
    int[] table;

    this(int n) {
        N = n;
        table = new int[](N);
        fill(table, -1);
    }

    int find(int x) {
        return table[x] < 0 ? x : (table[x] = find(table[x]));
    }

    void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) return;
        if (table[x] > table[y]) swap(x, y);
        table[x] += table[y];
        table[y] = x;
    }
}


Measured memory_bytes: 32764
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
''' 
------------------------
author : iiou16
------------------------
'''

def main():
    N, K = list(map(int, input().split()))
    S = list(input())

    output = S

    if S[K - 1] == "A":
        output[K - 1] = "a"
    elif S[K - 1] == "B":
        output[K - 1] = "b"
    elif S[K - 1] == "C":
        output[K - 1] = "c"
    print("".join(output))

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
n = int(input())
ans = [0] * 10000

for i in range(1, 101):
    for j in range(1, 101):
        for k in range(1, 101):
            m = ((i ** 2) + (j ** 2) + (k ** 2) + (i * j) + (j * k) + (k * i))
            if m < 10001:
                ans[m-1] += 1

for i in range(n):
    print(ans[i])

Measured memory_bytes: 9224
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)
    a, b, c, d = [int(x) for x in input().strip().split()]
    print(max(a*c, a*d, b*c, b*d))

if __name__ == '__main__':
    main()

Measured memory_bytes: 9172
N, M = list(map(int, input().split()))
A_list = list(map(int, input().split()))

card = []
card_num = []

for a in A_list:
    card.append(a)
    card_num.append(1)
        
for _ in range(M):
    B, C = list(map(int, input().split()))
    card.append(C)
    card_num.append(B)
    
union = zip(card, card_num)
sorted_union = sorted(union, key=lambda x:x[0])[-1::-1]
sorted_card, sorted_card_num = zip(*sorted_union)

ans = 0
current_num = 0
for c, c_num in zip(sorted_card, sorted_card_num):
    if current_num + c_num < N:
        current_num += c_num
        ans += c * c_num
    else:
        ans += c * (N - current_num)
        current_num = N
        break
print(ans)

Measured memory_bytes: 48460
N=int(input())
R=[[0,0,0] for _ in range(N)]
B=[[0,0,0] for _ in range(N)]
for i in range(N):
    R[i][0],R[i][1]=map(int,input().split())
for i in range(N):
    B[i][0],B[i][1]=map(int,input().split())
R.sort(key=lambda x:x[1],reverse=True)
B.sort()
cnt=0
for b in B:
    for r in R:
        if b[0]>r[0] and b[1]>r[1] and r[2]==0:
            cnt+=1
            r[2]=1
            break
print(cnt)

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

namespace ABC066A
{
    class Program
    {
        static void Main(string[] args)
        {
            int a, b, c, d;

            var word = Console.ReadLine().Split(' ');

            a = int.Parse(word[0]);
            b = int.Parse(word[1]);
            c = int.Parse(word[2]);

            d = a + b;

            if (d > a+c) d = a+c;
            if (d > b+c) d = b+c;


            Console.WriteLine(d);

            Console.ReadKey();

        }
    }
}



Measured memory_bytes: 13140
#include <iostream>
#include <vector>
#include <queue>
using namespace std;

int main()
{
	int n, x, y;
	cin >> n >> x >> y;
	vector<int> ret(n,0);

	for (int i = 1; i <= n; ++i) {
		vector<bool> check(n+1,false);
		queue<pair<int,int>> q;
		q.push({ i,0 });
		check[i] = true;
		while (!q.empty())
		{
			pair<int,int>& qf = q.front();
			int f = qf.first;
			int s = qf.second;
			++s;

			if (f != n && !check[f + 1]) {
				++ret[s];
				q.push({ f + 1, s });
				check[f + 1] = true;
			}
			if (f != 1 && !check[f - 1]) {
				++ret[s];
				q.push({ f - 1,s });
				check[f - 1] = true;
			}
			if (f == x && !check[y]) {
				++ret[s];
				q.push({ y,s });
				check[y] = true;
			}
			if (f == y && !check[x]) {
				++ret[s];
				q.push({ x,s });
				check[x] = true;
			}

			q.pop();
		}
	}

	for (int i = 1; i < n; ++i) {
		cout << ret[i] / 2 << endl;
	}

	return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
s=input().rstrip()
ls=len(s)
L=[0]*(ls+1)

pre,n='<',0
for i,c in enumerate(s):
    if c=='<':
        if pre == '<':
            n+=1
            L[i+1]=n
        else:
            n=1
            L[i+1]=1
            pre='<'
    else:
        pre='>'

pre,n='>',0
for i,c in enumerate(s[::-1]):
    if c=='>':
        if pre == '>':
            n+=1
            L[ls-1-i]=max(n,L[ls-1-i])
        else:
            n=1
            L[ls-1-i]=max(n,L[ls-1-i])
            pre='>'
    else:
        pre='<'
print(sum(L))

Measured memory_bytes: 50760
#include<bits/stdc++.h>
#define int long long

using namespace std ;

char a[1005][1005] ;
int dp[1005][1005] ;

int mod = 1e9 + 7 ;
signed main()
{
    ios_base::sync_with_stdio(false) ;
    cin.tie(NULL)  ;

    int h ,w  ;
    cin >> h >>  w ;
    for(int i = 0 ; i < h ; ++i)
    {
        for(int j = 0 ; j < w ; ++j )
        {
            cin >> a[i][j] ;
        }
    }
    dp[0][0] =1 ;

    for(int i = 1 ; i <1005 ; ++i )
    {
        if(a[i][0] != '#')
            dp[i][0] = dp[i-1][0] ;
        if (a[0][i] != '#')
            dp[0][i] = dp[0][i-1]  ;
    }
    for(int i =1 ; i < h ; ++i)
    {
        for(int j =1 ; j < w ; ++j)
        {
            if(a[i][j] != '#')
                dp[i][j] = dp[i-1][j] + dp[i][j-1] ;
            if(dp[i][j] >= mod )
                dp[i][j] %= mod ;
         }
    }
    cout << dp[h-1][w-1] << endl;


}


Measured memory_bytes: 12448
#include <stdio.h>

int main(void) {
  int a, b;

  while (scanf("%d %d", &a, &b) != EOF) {

    int t = a + b;
    int i = 0;

    while (t) {
      t /= 10;
      i++;
    }

    printf("%d\n", i);
  }

  return 0;
}

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

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

  for (int i = 1; i<=9; i++) {
    for (int j = 1; j<=9; j++) {
      if (i * j == N) {
        cout << "Yes";
        return 0;
      }
    }
  }
  cout << "No";
  return 0;
}

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

int main(){
  string s;
  cin >> s;
  int flag = 0;
  int c_count = 0;

  if(s[0] != 'A')
    flag = 1;

  if((s[1]>= 'A') && (s[1]<='Z'))
    flag = 1;

  int last;
  last = s.length() - 1 ;
  if((s[last]>= 'A') && (s[last]<='Z'))
    flag = 1;


  for(int i = 2; i < s.length(); i++){
    if(s[i] == 'C') c_count++;
    if((s[i] >= 'A') && (s[i] < 'C') && (s[i] > 'C')&& (s[i]<='Z'))
      flag = 1;
  }

  if(flag == 0 && c_count == 1){
    cout << "AC";
  } else
    cout << "WA";
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <set>
#include <utility>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <cstdio>
#include <map>

using namespace std;

using ll = long long;
using P = pair<ll,ll>;

#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = ((ll)(x) - 1); i >= 0; i--)

#define _upgrade ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define all(x) (x).begin(), (x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

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

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

const ll mod = 1e9 + 7;
const ll INF = 1LL << 60;
const double PI = 3.14159265358979323846;


// ****************************************CODE***************************************//









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

        double ans = 0;
        for(int i = 1; i <= n; i++){
                double tmp = 1;
                double cnt = i;
                while(cnt < k){
                        tmp *= 1.0/2.0;
                        cnt *= 2;
                }
                ans += (1.0/n) * tmp;
        }

        printf("%.14f\n", ans);
}


















Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;

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

#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const int N = 56;
const int K = 2501;
const ll inf = (ll)1e14;
ll dis[N][K];

struct Edge{
  int nex;
  int tim;
  int cost;
};

struct Pos{ 
  ll tim;
  int coins;
  int pos;
  bool operator< (const Pos &V) const {
    return tim > V.tim;
  }
};

vector<Edge> T[N];
int c[N];
ll d[N];

int main(){
  fastIO;
  int n, m, s;
  cin >> n >> m >> s;
  int u, v, a, b;
  for(int i = 0 ; i < m ; i ++ ){
    cin >> u >> v >> a >> b;
    T[u].push_back({v, b, a});
    T[v].push_back({u, b, a});
  }
  for(int i = 1; i <= n; i ++ ){
    for(int j = 0 ; j < K; j ++ ){
      dis[i][j] = inf;
    }
  }
  for(int i = 1; i <= n; i ++ ){
    cin >> c[i] >> d[i];
    c[i] = min(c[i], K-1);
  }
  dis[1][min(s,K-1)] = 0;
  priority_queue<Pos> ff;
  ff.push({0,min(s,K-1),1});
  int curc;
  int node;
  ll tm;
  int take;
  int nxc;
  int cnt = 0;
  while(!ff.empty()){
    node = ff.top().pos;
    curc = ff.top().coins;
    tm = ff.top().tim;
    if(tm != dis[node][curc]){
      ff.pop();
      continue;
    }
    ff.pop();
    take = 1;
    for(auto x : T[node]){
      if(x.cost <= curc){
        if(dis[x.nex][curc - x.cost] > dis[node][curc] + x.tim){
          dis[x.nex][curc - x.cost] = dis[node][curc] + x.tim;
          ff.push({dis[x.nex][curc-x.cost],curc-x.cost,x.nex});
        }
      }
    }
    while(1){ 
      nxc = min(curc + take * c[node], K - 1);
      if(dis[node][nxc] > dis[node][curc] + take * d[node]){
        dis[node][nxc] = dis[node][curc] + take * d[node];
        ff.push({dis[node][nxc],nxc,node});
      }
      if(nxc >= K-1) break;
      take ++;
    }
  }
  ll ans;
  for(int i = 2; i <= n; i ++ ){
    ans = inf;
    for(int j = 0 ; j < K; j ++ ) 
      ans = min(ans, dis[i][j]);
    cout << ans << "\n";
  }
  return 0;
}

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

int main() {
    ll n;
    std::cin >> n;
    string c;
    std::cin >> c;
    ll rc,wc;
    rc = wc = 0;
    for (int i = 0; i < n; i++) {
        if(c[i]=='R'){
            rc++;
        }else{
            wc++;
        }
    }
    ll tr,tw;
    tr = tw = 0;
    
    ll ans = n+10;

    for (int i = 0; i <= n; i++) {
        // rで有るべき数 = i;
        // wであるべき数 = n-i;
        // 左でrの数 tr
        // 左でwの数 tw
        // i-tw 余分なw
        // n-i-(rc-tr)
        ll yw = tw;
        ll yr = rc-tr;
        ans = min(ans, max(yw,yr));
        if(c[i]=='R'){
            tr++;
        }else{
            tw++;
        }
    }
    std::cout << ans << std::endl;
}


Measured memory_bytes: 3752
from collections import Counter

def main():
    N,X,Y = list(map(int,input().split()))

    counter = Counter()
    for i in range(1,N):
        for j in range(i+1,N+1):
            d = min(j-i,abs(X-i)+abs(Y-j)+1)
            counter[d]+=1
    for i in range(1,N):
        print(counter[i])

if __name__ == "__main__":
    main()

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

string S;
vector<int> v[26];

int main() {
	cin >> S;
	for (int i = 0; i < S.length(); i++) v[S[i] - 'a'].push_back(i);
	int ans = 2000000000;
	for (int i = 0; i < 26; i++) {
		if (v[i].size() == 0) continue;
		int mx = 0;
		mx = max(mx, v[i][0]);
		mx = max(mx, ((int)S.length() - v[i].back() - 1));
		for (int j = 0; j < (int)v[i].size() - 1; j++) {
			mx = max(mx, (v[i][j + 1] - v[i][j] - 1));
		}
		ans = min(ans, mx);
	}
	printf("%d\n", ans);
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
//#pragma GCC target("avx2")
//#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << "\n";
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (ll i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (ll i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    int n, k; cin >> n >> k;
    vi l(n); REP(i, n) cin >> l[i];

    sort(ALL(l), greater<>());
    int ans = accumulate(l.begin(), l.begin() + k, 0);

    print(ans);
}

Measured memory_bytes: 3536
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    import queue
    mod=10**9+7
    N,M=MI()
    adj=[[]for _ in range(N)]
    for i in range(M):
        s,t=MI()
        s-=1
        t-=1
        adj[s].append(t)
    
    """    
    逆向きに見ればO(M)，全ての通路で試すとO(M^2)
    切るルートをある程度まとめたい，i番目から出る通路のなかで一番でかいやつを無視する，というのをN回
    """
    
    ans=10**10
    
    for i in range(N-1):#i番目から出る辺を切る
        dp=[0]*N
        for j in range(N-2,-1,-1):#j番目の部屋から出るための期待値を求める．
            cnt=0#通り数
            if j!=i:
                for k in adj[j]:#jからkへ伸びる辺を考える
                    dp[j]+=dp[k]+1
                    cnt+=1
                dp[j]/=cnt
                    
            else:
                max_d=0
                for k in adj[j]:#jからkへ伸びる辺を考える
                    dp[j]+=dp[k]+1
                    cnt+=1
                    max_d=max(max_d,dp[k])
                
                #出る道が1本なら何もしない
                if cnt==1:
                    pass
                else:#一番でかいところをつぶす
                    cnt-=1
                    dp[j]-=(max_d+1)
                    dp[j]/=cnt
        # print(dp)
        if dp[0]!=0:
            ans=min(ans,dp[0])
            
    print(ans)
        

                
        
        
        
        
        
        
            
            
    
    

main()


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

using namespace std;

struct Process
{
	string name;
	int time;
};

int main()
{
	int n, quantum, sumTime = 0;
	Process p, temp;
	
	scanf("%d %d", &n, &quantum);
	
	queue<Process> q1;
	queue<Process> q2;
	
	for(int i = 0; i < n; i++)
	{
		cin >> p.name >> p.time;
		q1.push(p);
	}
	
	while(!(q1.empty()))
	{
		if(q1.front().time <= quantum)
		{
			temp = q1.front();
			q1.pop();
			sumTime += temp.time;
			temp.time = sumTime;
			q2.push(temp);
		}
		else
		{
			temp = q1.front();
			temp.time -= quantum;
			q1.pop();
			q1.push(temp);
			sumTime += quantum;
		}
	}
	
	for(int i = q2.size(); i > 0; i--)
	{
		cout << q2.front().name << " " << q2.front().time << "\n";
		q2.pop();
	}
	
	return 0;
}


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

#define ll long long
#define deb(x) cerr << #x << ":" << x << "\n"
#define all(x) x.begin(),x.end()

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

#define int ll

void solve()
{
    int n;
    cin>>n;
    vector<multiset<int>> v(4);
    for(int i=0;i<4;i++)v[i]=multiset<int>();
    for(int i=0;i<n;i++){
        int x,y;
        cin>>x>>y;
        v[0].insert(x+y);
        v[1].insert(x-y);
        v[2].insert(-x+y);
        v[3].insert(-x-y);
    }
    int ans=*(v[0].rbegin());
    ans-=*(v[0].begin());
    ans=max(ans,(*(v[1].rbegin()))-(*(v[1].begin())));
    ans=max(ans,(*(v[3].rbegin()))-(*(v[3].begin())));
    ans=max(ans,(*(v[2].rbegin()))-(*(v[2].begin())));
    cout<<ans<<"\n";
}

int32_t main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 41120
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

int main() {
  ll m;
  cin >> m;
  ll keta = 0, sum = 0;
  REP(i, m) {
    ll d, c;
    cin >> d >> c;
    keta += c;
    sum += d * c;
  }
  cout << (ll)keta - 1 + (sum + 8) / 9 - 1 << endl;
}

Measured memory_bytes: 256
N, X, T = map(int, input().split())
count = 1
check = X
if X > 1:
    while True:
        value = int(N / X)
        re = N % X
        if re == 0:
            count = value
            TotalTime = T * count
            break
        else:
            count += value
            TotalTime = T * count
            break
else:
    TotalTime = T * N
print(TotalTime)

Measured memory_bytes: 9144
#include <cstdio>
#include <vector>

int main() {
  int N;
  long long K;
  scanf("%d %lld", &N, &K);

  std::vector<long long> A(100010);
  for (int i=0; i<N; ++i) {
    int a, b;
    scanf("%d %d", &a, &b);
    A[a] += b;
  }

  for (int i=1; i<=100000; ++i)
    if ((K -= A[i]) <= 0)
      return !printf("%d\n", i);

  return 0;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
using namespace std;
using ll = long long;
#define MAX_N 1000001
#define MAX_M 100010
const long long mod = 1e9 + 7;
#define vec vector<int>
#define vecll vector<ll>
#define vecllvec vector<vector<ll>>
#define vecb vector<bool>
#define vecBvec vector<vector<bool>>
#define vecst vector<string>
#define veche vector<char>
#define vecd vector<double>
#define vecvec vector<vector<int>>
#define vecDvec vector<vector<double>>
#define vecHvec vector<vector<char>>
#define all(x) (x).begin(),(x).end()
#define ent cout<<endl
#define printvec(vec) for(int aqw=0;aqw<vec.size();aqw++){cout<<vec[aqw]<<" ";}ent;
#define rep1(n) for(ll i = 0; i < (n); ++i)
#define rep2(i, n) for(ll i = 0; i < (n); ++i)
#define rep3(i, a, b) for(ll i = (a); i < (b); ++i)
#define rep4(i, a, b, c) for(ll i = (a); i < (b); i += (c))
template<class T> inline bool chmax(T & a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T & a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define INF 1e+9
#define print(x) cout<<x<<endl;
using P = pair<int, int>;
#define PLL pair<ll, ll>;
#define MAX_V 1000
#define PI 3.141592653589793
#define vecP vector<P>
// cout << setprecision(15) << std::fixed;


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




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

#define GO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int

const int maxr = 1e5 + 5;

int M;
int powerr(int a, int b) {
	if (b == 0)
		return 1;
	int sm = powerr(a, b / 2);
	int ans = (sm * sm) % M;
	if (b % 2 == 0) {
		return ans;
	}
	return (ans * a) % M;
}

int32_t main()
{
	GO;
	int n;
	cin >> n;
	string s;
	cin >> s;
	int count = 0;
	for (int i = 0; i < n; i++)
		if (s[i] == '1')
			count++;

	int ans = 0;
	int power = 1, sum1 = 0;
	if (count > 1) {
		for (int i = n - 1; i >= 0; i--) {
			sum1 += power * (s[i] - '0');
			power *= 2;
			sum1 %= (count - 1);
			power %= (count - 1);
		}
	}
	power = 1; int sum2 = 0;
	for (int i = n - 1; i >= 0; i--) {
		sum2 += power * (s[i] - '0');
		power *= 2;
		sum2 %= (count + 1);
		power %= (count + 1);
	}
	for (int i = 0; i < n; i++) {
		if (s[i] == '1')
			s[i] = '0';
		else
			s[i] = '1';
		if (s[i] == '1')
			count++;
		else
			count--;
		if (count == 0) {
			cout << 0 << endl;
			if (s[i] == '1')
				s[i] = '0';
			else
				s[i] = '1';

			if (s[i] == '1')
				count++;
			else
				count--;
			continue;
		}
		int sum;
		if (s[i] == '1') {
			M = count;
			sum = sum2;
			sum = sum + powerr(2, n - i - 1);
			sum %= count;
		}
		else {
			sum = sum1;
			M = count;
			sum = sum - powerr(2, n - i - 1);
			sum = (sum + count * 10) % count;
		}
		int ans = 1;
		while (sum > 0) {
			sum = sum % __builtin_popcount(sum);
			ans++;
		}
		cout << ans << endl;
		if (s[i] == '1')
			s[i] = '0';
		else
			s[i] = '1';

		if (s[i] == '1')
			count++;
		else
			count--;
	}
	return 0;
}

//!

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

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
void tostr(ll x,string& res){while(x)res+=('0'+(x%10)),x/=10; reverse(ALL(res)); return;}
template<class T> inline bool chmax(T& a,T b){ if(a<b){a=b;return 1;}return 0; }
template<class T> inline bool chmin(T& a,T b){ if(a>b){a=b;return 1;}return 0; }
//template end

template<unsigned mod>struct mint {
   static int get_mod(){return mod;}
   int val;
   int inv() const{
      int tmp,a=val,b=mod,x=1,y=0;
      while(b)tmp=a/b,a-=tmp*b,swap(a,b),x-=tmp*y,swap(x,y);
      if(x<0)x+=mod; return x;
   }
   mint():val(0){}
   mint(ll x):val(x>=0?x%mod:mod+(x%mod)){}
   mint pow(ll t){mint res=1,b=*this; while(t){if(t&1)res*=b;b*=b;t>>=1;}return res;}
   mint& operator+=(const mint& x){if((val+=x.val)>=mod)val-=mod;return *this;}
   mint& operator-=(const mint& x){if((val+=mod-x.val)>=mod)val-=mod; return *this;}
   mint& operator*=(const mint& x){val=(ll)val*x.val%mod; return *this;}
   mint& operator/=(const mint& x){val=(ll)val*x.inv()%mod; return *this;}
   mint operator+(const mint& x)const{return mint(*this)+=x;}
   mint operator-(const mint& x)const{return mint(*this)-=x;}
   mint operator*(const mint& x)const{return mint(*this)*=x;}
   mint operator/(const mint& x)const{return mint(*this)/=x;}
   bool operator==(const mint& x)const{return val==x.val;}
   bool operator!=(const mint& x)const{return val!=x.val;}
};
using Mint=mint<1000000007>;
struct factorial {
   vector<Mint> Fact, Finv;
public:
   factorial(int maxx){
      Fact.resize(maxx+1),Finv.resize(maxx+1); Fact[0]=Mint(1); rep(i,0,maxx)Fact[i+1]=Fact[i]*(i+1);
      Finv[maxx]=Mint(1)/Fact[maxx]; rrep(i,maxx,0)Finv[i-1]=Finv[i]*i;
   }
   Mint fact(int n,bool inv=0){if(inv)return Finv[n];else return Fact[n];}
   Mint nPr(int n,int r){if(n<0||n<r||r<0)return Mint(0);else return Fact[n]*Finv[n-r];}
   Mint nCr(int n,int r){if(n<0||n<r||r<0)return Mint(0);else return Fact[n]*Finv[r]*Finv[n-r];}
};

int main(){
   int n; scanf("%d",&n);
   vector<int> a(n);
   rep(i,0,n)scanf("%d",&a[i]);
   map<int,int> mp;
   rep(i,0,n){
      int sub=a[i];
      for(int p=2;p*p<=sub;p++)if(sub%p==0){
         int cur=0;
         while(sub%p==0){
            cur++; sub/=p;
         }
         chmax(mp[p],cur);
      }
      if(sub!=1)chmax(mp[sub],1);
   }
   Mint mul=1;
   for(auto ps:mp)mul*=Mint(ps.first).pow(ps.second);
   Mint res=0;
   rep(i,0,n)res+=mul/a[i];
   printf("%d\n",res.val);
   return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
#define fatafat                                                                \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define int long long
#define MOD ((long long)(1e9) + 7)
#define excl(i, a, b) for (int i = a; i < b; i++)
#define incl(i, a, b) for (int i = a; i <= b; i++)
#define mp(a, b) make_pair(a, b)
#define ff first
#define ss second
#define PII pair<int, int>

using namespace std;

int binexp(int a, int b) {
  if (b) {
    if (b % 2)
      return a * binexp(a * a, b / 2);
    return binexp(a * a, b / 2);
  }
  return 1;
}

int modexp(int a, int b, int m) {
  if (b) {
    if (b % 2)
      return (a * modexp((a * a) % m, b / 2, m)) % m;
    return modexp((a * a) % m, b / 2, m);
  }
  return 1;
}

int mygcd(int a, int b) {
  if (b == 0)
    return a;
  return mygcd(b, a % b);
}

int euclidgcd, euclidx, euclidy;

void exteuclid(int a, int b) {
  if (b == 0) {
    euclidgcd = a;
    euclidx = 1;
    euclidy = 0;
  } else {
    exteuclid(b, a % b);
    int temp = euclidx;
    euclidx = euclidy;
    euclidy = temp - euclidy * (a / b);
  }
}

int modinv(int a, int m) {
  exteuclid(a, m);
  return (euclidx % m + m) % m;
}

int pmodinv(int a, int m) { return modexp(a, m - 2, m); }

bool checkprime(int a) {
  for (int i = 2; i * i <= a; i++)
    if (a % i == 0)
      return false;
  return true;
}

vector<bool> seive(int n) {
  vector<bool> ret(n + 1, true);
  ret[0] = ret[1] = false;
  for (int i = 2; i * i <= n; i++)
    if (ret[i])
      for (int j = i * i; j <= n; j += i)
        ret[j] = false;
  return ret;
}

vector<bool> seivelims(int l, int r) {
  vector<bool> ret(r - l + 1, true);
  for (int i = 2; i * i <= r; i++) {
    for (int j = max(i * i, ((l + i - 1) / i) * i); j <= r; j += i) {
      ret[j - l] = false;
    }
  }
  return ret;
}

vector<int> rootnfact(int n) {
  vector<int> ret;
  for (long i = 2; i * i <= n; i++)
    while (n % i == 0) {
      ret.push_back(i);
      n /= i;
    }
  if (n != 1)
    ret.push_back(n);
  return ret;
}

vector<int> prelognfact(int n) {
  vector<int> minprime(n + 1, 0);
  minprime[0] = minprime[1] = 0;
  for (int i = 2; i * i <= n; i++) {
    if (minprime[i] == 0) {
      for (int j = i * i; j <= n; j += i) {
        if (minprime[j] == 0)
          minprime[j] = i;
      }
    }
  }
  for (int i = 2; i <= n; i++)
    if (minprime[i] == 0)
      minprime[i] = i;
  return minprime;
}

vector<int> lognfact(int n, vector<int> minprime) {
  vector<int> ret;
  while (n != 1) {
    ret.push_back(minprime[n]);
    n /= minprime[n];
  }
  return ret;
}

int temp, temp1, temp2;

signed main() 
{ 
    fatafat; 
    int a,b;
    cin>>a>>b;
    if (a==b)
        cout<<2*a;
    else
        cout<<max(a,b)*2-1;
}

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

#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll>
#define vpii vector<pair<int,int>>
#define vpll vector<pair<ll,ll>>
#define fr(i,k,n) for (int i = k; i < n; ++i)
#define fri(i,k,n) for (int i = k; i >= n; --i)
#define INF (int)1e9
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define all(arr) arr.begin(),arr.end()

void boost(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

void solve(){
	int n;
	cin>>n;
	vi a(n),b(n);
	fr(i,0,n)
	cin>>a[i];
	fri(i,n-1,0)
	cin>>b[i];
	bool poss=true;
	int l=0,r=n-1;
	fr(i,0,n){
		if(a[i]==b[i]){
			if(l<n && a[l]!=a[i] && b[l]!=a[i]){
				swap(b[l],b[i]);
				l++;
			}
			else if(r>=0 && a[r]!=a[i] && b[r]!=a[i]){
				swap(b[r],b[i]);
				r--;
			}
			else{
				poss=false;
				break;
			}
		}
	}
	if(!poss){
		cout<<"No"<<endl;
		return;
	}
	cout<<"Yes"<<endl;
	fr(i,0,n)
	cout<<b[i]<<" ";
	return;
}

int main()
{
	boost();
	
	int tc=1;
	//cin>>tc;
	while(tc--)
		solve();
	return 0;
}

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

using namespace std;

const int MAX = 3010 ;
int dp[MAX][MAX] ;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    string s , s1 ;
    cin>>s>>s1 ;
    int n = s.size() , m = s1.size() ;
    for(int i = 0 ; i <= n ; ++i)
    {
        for(int j = 0 ; j <= m ; ++j)
        {
            if(i == 0 || j == 0)
                dp[i][j] = 0 ;
            else if(s[i-1] == s1[j-1])
                dp[i][j] = dp[i-1][j-1] + 1 ;
            else
                dp[i][j] = max(dp[i-1][j] , dp[i][j-1]);
        }
    }
    int idx = dp[n][m];
    string lcs = "";
    for(int i = 0 ; i < idx ; ++i)
        lcs += 'z' ;
    int i = n , j = m ;
    while(i > 0 && j > 0)
    {
        if(s[i-1] == s1[j-1])
        {
            lcs[idx-1] = s[i-1] ;
            i--;
            j--;
            idx--;
        }
        else if(dp[i-1][j] > dp[i][j-1])
            i--;
        else
            j--;
    }
    return cout<<lcs , 0 ;
}


Measured memory_bytes: 35584
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define FIO ios_base::sync_with_stdio(false); cin.tie(0);
#define trav(x,a) for (auto& x: a)
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define mem(a,v) memset((a), (v), sizeof (a))
#define endl "\n"
#define case(t) cout << "Case #" << (t) << ": "
#define reada(a, n) for (int _i = 0; _i < (n); _i++) read(a[_i])
#define pii pair<int, int>
#define pll pair<long long, long long>
#define vii vector<pii>
#define vll vector<pll>
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define mp make_pair
#define st first
#define nd second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef cc_hash_table<int,int,hash<int>> ht;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;
const double pi = acos(-1);
const int mod = 1e9 + 7;
const int inf = 1e9 + 7;
const int N = 1e6 + 5;
const double eps = 1e-9;

template<class T> void read(T& x) { cin >> x; }
template<class X, class Y> void read(pair<X,Y>& a) { read(a.first), read(a.second); }
template<class T> void read(vector<T>& x) { trav(y, x) read(y); }
template<class T, class... O> void read(T& x, O&... y) { read(x), read(y...); }

string to_string(const char& x) { return string(1,x); }
string to_string(const char*& x) { return (string)x; }
string to_string(const string& x) { return x; }
template<class T, class U> string to_string(const pair<T,U>& x) { return to_string(x.first) + " " + to_string(x.second); }
template<class T> string to_string(const vector<T>& x) { string ret = ""; bool f = 0; trav(y, x) ret += (!f ? "" : " ") + to_string(y), f = 1; return ret; }
void print() { cout << endl; }
template<class T> void pr(const T& x) { cout << to_string(x); }
template<class T, class... O> void print(const T& x, const O&... y) { pr(x); if (sizeof...(y)) pr(" "); print(y...); }

vector<pii> a;
int ind[N], nx[N], par[N], s[N];

int qry(int x) { return x == par[x] ? x : par[x] = qry(par[x]); }
void join(int x, int y) {
  if ((x = qry(x)) == (y = qry(y)))
    return;
  par[x] = y;
  s[y] += s[x];
}

int main() {
  FIO
  int n; read(n); a.resize(n); read(a);
  iota(ind, ind+n, 0), iota(par, par+n, 0), fill(s, s+n, 1);
  sort(ind, ind+n, [](int l, int r) {
    return a[l].st < a[r].st;
  });
  stack<int> sta;
  for (int i = n-1; ~i; i--) {
    int c = sz(sta) ? sta.top() : -1;
    int ok = 0;
    while (sz(sta) && a[sta.top()].nd > a[ind[i]].nd) {
      // print("join", ind[i], sta.top());
      join(ind[i], sta.top()), sta.pop(), ok = 1;
    }
    // print(c, ok, sz(sta));
    if (c != -1 && ok == 1)
      sta.push(c);
    else
      sta.push(ind[i]);
  }
  for (int i = 0; i < n; i++) {
    print(s[qry(i)]);
  }
  return 0;
}


Measured memory_bytes: 7148
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const int N = 1e5 + 5;


vector< pair < int , int > > v ;
ll mod = 1e9 + 7 ;

int main()
{
    int n ;
    cin >> n ;
    for(int i =0 ; i < n ; i ++){
        int x;
        scanf("%d",&x);
        v.push_back({x,1});
    }
    for(int i =0 ; i < n ; i ++){
        int y ;
        scanf("%d",&y);
        v.push_back({y,0});
    }
    ll res = 1;
    int x = 0 ;

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

    // x x y
    for(int i =0 ; i < v.size() ; i ++){

        if(v[i].second == 1){

            if(x < 0 )
                res = ( res * -x ) % mod ;
            x ++ ;
        }else{

            if(x > 0 )
                res = (res * x ) %mod ;
            x -- ;
        }
    }
    cout << res << endl ;


    return 0;
}


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

using namespace std;

int main() {
    // 入力値
    int N;
    cin >> N;

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

    // 重複を排除するため、set（コンテナ型）に値を入れていく。
    set<int> unique_d;
    for (int i = 0; i < N; i++) {
        unique_d.insert(d.at(i));
    }

    // 出力値
    cout << unique_d.size() << endl;

    return 0;
}


Measured memory_bytes: 256
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>

auto& in = std::cin;
auto& out = std::cout;

int32_t M;
int32_t V[20];
int32_t dp[20][50002];
int func(int i, int max)
{
	if (max == 0) {
		return 0;
	}
	if (max<0||i >= M) {
		return 500000;
	}
	auto& memo = dp[i][max];
	if (memo != 0) {
		return memo;
	}
	return memo = std::min(func(i + 1, max), func(i, max-V[i])+1);
}
int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);

	int32_t N;
	in >> N>>M;
	for (int32_t i = 0; i < M; i++)
	{
		in >> V[i];
	}
	std::cout << func(0, N)<<std::endl;
	return 0;
}
#endif

Measured memory_bytes: 9364