akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstdint>
using namespace std;
typedef long long ll;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define mod 1000000007
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)

int main(){
    int n,k,s;
    cin >> n >> k >> s;
    vector<int>res(n);
    if(s==1000000000){
        if(k==0){
            rep(i,n)res[i] = 1;
        }else{
            rep(i,n){
                if(i<k)res[i] = s;
                else res[i] = 1;
            }
        }
    }else{
        rep(i,n){
            if(i<k)res[i] = s;
            else res[i] = 1000000000;
        }
    }
    rep(i,n){
        cout << res[i] << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 1664
N = int(input())
S = input()
c1 = [0] * N
c2 = [0] * N
ans = N
for i in range(N):
    c1[i] += c1[i - 1] + 1 * (S[i] == "#")
    c2[i] += c2[i - 1] + 1 * (S[i] == ".")
c1 = [0] + c1
c2 = [0] + c2
for i in range(N):
    ans = min(ans, c1[i] + c2[N] - c2[i + 1])
print(ans)

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

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

Measured memory_bytes: 256
score = []

# 提出用の入力
while True:
    m, f, r = map(int, input().split())
    if m == -1 and f == -1 and r == -1:
        break
    score.append((m, f, r))

# # 動作確認用の入力
# with open('input_itp1_7_a_1.txt', mode='r', encoding='utf8') as input:
#     while True:
#         m, f, r = map(int, next(input).split())
#         if m == -1 and f == -1 and r == -1:
#             break
#         score.append((m, f, r))
# print(score)

for i in range(len(score)):
    sum = score[i][0] + score[i][1]
    if score[i][0] == -1 or score[i][1] == -1 or sum < 30:
        print('F')
    elif sum >= 80:
        print('A')
    elif sum >= 65:
        print('B')
    elif sum >= 50:
        print('C')
    elif sum >= 30:
        if score[i][2] >= 50:
            print('C')
        else:
            print('D')



Measured memory_bytes: 5600
import sys

# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
import heapq
import decimal
# import statistics
import queue

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    n = ni()
    mat = [list(input()) for _ in range(2)]

    none, single, double = 0, 1, 2
    table = {(none, single): 3, (none, double): 6, (single, single): 2, (single, double): 2, (double, single): 1,
             (double, double): 3}
    prev = none
    ans = 1
    next_skip = False

    for i in range(len(mat[0])):
        if next_skip:
            next_skip = False
            continue

        current = single if mat[0][i] == mat[1][i] else double
        ans *= table[(prev, current)]
        ans %= MOD

        if current == double:
            next_skip = True
        prev = current

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 5052
#include <stdio.h>

int main()
{
    int A[100][100], B[100], C[100]={0};
    int i, j, n, m;
    scanf("%d %d", &n, &m);
    for(i = 0; i < n; i++)
    {
        for(j = 0; j < m; j++)
        {
            scanf("%d", &A[i][j]);
        }
    }
    for(j = 0; j < m; j++)
    {
        scanf("%d", &B[j]);
    }
    for(i = 0;i < n; i++)
    {
        for(j = 0;j < m; j++)
        {
            C[i] += A[i][j] * B[j];
        }
    }
    for(i = 0;i < n; i++)
    {
        printf("%d\n", C[i]);
    }
    return(0);
}



Measured memory_bytes: 2776
package main

import (
	"bufio"
	"fmt"
	"io"
	"log"
	"math"
	"os"
	"strconv"
)

func main() {
	a, b, h, m := readFloat64(), readFloat64(), readFloat64(), readFloat64()

	xx := a*a + b*b - 2*a*b*math.Cos(math.Abs((h+m/60)/12*2*math.Pi-m/60*2*math.Pi))

	fmt.Println(math.Sqrt(xx))
}

var (
	readString func() string
	readBytes  func() []byte
)

func init() {
	log.SetFlags(log.Lshortfile)
	readString, readBytes = newReadString(os.Stdin)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readInt() int {
	return int(readInt64())
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

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

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

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

func sum(a []int) int {
	var ret int
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumFloat64(a []float64) float64 {
	var ret float64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func gcd(m, n int) int {
	for m%n != 0 {
		m, n = n, m%n
	}
	return n
}

func lcm(m, n int) int {
	return m / gcd(m, n) * n
}


Measured memory_bytes: 1760
import java.io.*;
import java.util.*;
class Main{
	static final long MOD = 1_000_000_007; // 10^9+7
    static final int MAX = 2_147_483_646; // intMax 
    static final int INF = 1_000_000_000; // 10^9  
    public static void main(String[] args) throws Exception {
		hayami saori = new hayami();
		String[] n = saori.nextHayami().split("");
		int count = 0;
		if((n[0].equals(n[1]) && n[1].equals(n[2])) || (n[1].equals(n[2]) && n[3].equals(n[2]))){
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
		
		saori.close();
    }
}

class hayami implements Closeable {
	private final InputStream in = System.in;
	private final byte[] hayami = new byte[1024];
	private int Hayami = 0;
	private int saori = 0;
	private boolean HayamiSaori() {
		if (Hayami < saori) {
			return true;
		}else{
			Hayami = 0;
			try {
				saori = in.read(hayami);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (saori <= 0) {
				return false;
			}
		}
		return true;
	}
	private int SaoriHayami() { 
		if (HayamiSaori()) {
            return hayami[Hayami++];
         }else{
             return -1;
         }
	}
	private static boolean hayami_saori(int hayami) { 
		return 33 <= hayami && hayami <= 126;
	}
	public boolean hayamisaori() { 
		while(HayamiSaori() && !hayami_saori(hayami[Hayami])) Hayami++; return HayamiSaori();
	}
	public String nextHayami() {
		if (!hayamisaori()) throw new NoSuchElementException();
		StringBuilder hayamin = new StringBuilder();
		int saori = SaoriHayami();
		while(hayami_saori(saori)) {
			hayamin.appendCodePoint(saori);
			saori = SaoriHayami();
		}
		return hayamin.toString();
	}
	public long saorihayami() {//nextLong
		if (!hayamisaori()) throw new NoSuchElementException();
		long hayami = 0;
		boolean misao = false;
		int saori = SaoriHayami();
		if (saori == '-') {
			misao = true;
			saori = SaoriHayami();
		}
		if (saori < '0' || '9' < saori) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= saori && saori <= '9') {
				hayami *= 10;
				hayami += saori - '0';
			}else if(saori == -1 || !hayami_saori(saori)){
				return misao ? -hayami : hayami;
			}else{
				throw new NumberFormatException();
			}
			saori = SaoriHayami();
		}
	}
	public int saori_hayami() {//nextInt
		long hayami = saorihayami();
		if (hayami < Integer.MIN_VALUE || hayami > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) hayami;
	}
	public double Hayamin() { //nextDouble
		return Double.parseDouble(nextHayami());
	}
	public void close() {
		try {
			in.close();
		} catch (IOException e) {
		}
    }
    
}

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

int main(){
    int ans=0;
    int A,H;

    cin>>H>>A;

    if(H%A==0){
        ans=H/A;
    }
    else{
        ans=H/A+1;
    }

    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <algorithm>
#include <string>
#include <vector> 
#include <numeric>
#include <cmath>
#include <queue>
#include <iomanip>
#include <functional>


#define CHMAX(a,b) a = std::max(a,b)
#define CHMIN(a,b) a = std::min(a,b)
#define MAXMIN(a,b,c) std::max(a,min(b,c))
#define CHABS(a) a = std::abs(a) 
#define COUT(a) std::cout << a << std::endl
#define CERR(a) std::cerr << a << std::endl
#define FOR(n) for(lli i = 0; i < n; i++)

using namespace std;
using lli = long long int;
using pll = pair<lli, lli>;
using tlll = tuple<lli, lli, lli>;
using vll = vector<lli>;

lli mod197 = 1000000007LL;
lli INF = 10000000000000;

// ax + by = gcd(a,b) 最大公約数
template< typename T >
T extgcd(T a, T b, T& x, T& y) {
	T d = a;
	if (b != 0) {
		d = extgcd(b, a % b, y, x);
		y -= (a / b) * x;
	}
	else {
		x = 1;
		y = 0;
	}
	return d;
}

int main(void) {

	lli n, a, b;
	cin >> n >> a >> b;

	lli time = n / (a + b);

	cout << time * a + min(n % (a + b), a) << endl;


	return 0;
}

Measured memory_bytes: 256
n, y = map(int, input().split())
for i in range(n + 1):
    for j in range(n - i + 1):
        if i * 10000 + j * 5000 + (n - i - j) * 1000 == y:
            print(i, j, n - i - j)
            exit()
print("-1 -1 -1")

Measured memory_bytes: 65148
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define vecll vector<long long>
#define vec2ll vector<vector<long long>>
#define vecpairll vector<pair<long long,long long>>
#define forll(s,a,b) for(long long s = a;s < b;s++)
#define forllde(s,a) for(long long s = a;s > 0;s--)
 
template <typename A, typename B>
string to_string(pair<A, B> p);
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
 
string to_string(const string& s) {
  return '"' + s + '"';
}
 
string to_string(const char* s) {
  return to_string((string) s);
}
 
string to_string(bool b) {
  return (b ? "true" : "false");
}
 
string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}
 
template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}
 
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
 
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define debug(...) cerr << "<" << #__VA_ARGS__ << ">:", debug_out(__VA_ARGS__)
#define INF LLONG_MAX
 
 
int main()
{
  ll n, m, c, a, b;
  cin >> n >> m;
 
  map <ll, vecll> mym;
  vecll ans(n, 0);
 
  forll(i, 0, m){
	cin >> a >> b;
	mym[a].push_back(b);
	mym[b].push_back(a);
  }
  
  queue <ll> s;
  s.push(1);
  while (not s.empty()){
	ll next = s.front();
	s.pop();
	forll(i, 0, (ll)mym[next].size()){
	  if (ans[mym[next][i] - 1] == 0){
		ans[mym[next][i] - 1] = next;
		s.push(mym[next][i]);
	  }
	}
  }
  cout << "Yes" << endl;
  forll(i, 1, n){
	cout << ans[i] << endl;
  }
}

Measured memory_bytes: 22560
N = int(input())
H = list(map(int,input().split()))

k = 0
i = 0
list = [0]
for k in range(0,N-1):
    if H[k]<H[k+1]:
        list.append(k-i)
        i = k+1

list.append(N-1-i)
list.sort()
list.reverse()
print(list[0])


Measured memory_bytes: 14224
x1,y1,x2,y2=map(int,input().split())

import numpy as np
R=pow((x1-x2)**2+(y1-y2)**2,0.5)
x3=pow(2,0.5)*R/R*(x2-x1-(y2-y1))/pow(2,0.5)+x1
y3=pow(2,0.5)*R/R*(y2-y1+x2-x1)/pow(2,0.5)+y1
x3=int(x3)
y3=int(y3)
x4=-R*(y2-y1)/R+x1
y4=R*(x2-x1)/R+y1
x4=int(x4)
y4=int(y4)
print(x3,y3,x4,y4)

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

#define x first
#define y second

int main() {
  ios::sync_with_stdio(0); cin.tie(0);
  int n;
  cin >> n;
  vector<pair<int,int>> a(n), b(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i].x;
    a[i].y = i;
  }
  for (int i = 0; i < n; i++) {
    cin >> b[i].x;
    b[i].y = i;
  }
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  int ok = 1, swapok = 0;
  vector<int> p(n);
  for (int i = 0; i < n; i++) {
    if (a[i].x > b[i].x) ok = 0;
    if (i && a[i].x <= b[i-1].x) swapok = 1;
    p[a[i].y] = b[i].y;
  }
  int pos = 0;
  vector<int> done(n);
  for (int i = 0; i < n; i++) {
    if (done[pos]++) swapok = 1;
    pos = p[pos];
  }
  cout << (ok && swapok ? "Yes" : "No") << endl;
}


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

using namespace std;

#define int long long
// #define double long double
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, a, b) for(ll i = (a); i > (b); --i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define bitcnt __builtin_popcount
#define SZ(x) ((ll)(x).size())
#define fi first
#define se second
#define All(a) (a).begin(), (a).end()
#define rAll(a) (a).rbegin(), (a).rend()
template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
#define CCIN(...)                                                              \
    char __VA_ARGS__;                                                          \
    CIN(__VA_ARGS__)
#define DCIN(...)                                                              \
    double __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    ll __VA_ARGS__;                                                            \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Printv(v)                                                              \
    {                                                                          \
        REP(x, v.size()) { cout << v[x] << (x == v.size() - 1 ? "\n" : " "); } \
    }
template <typename T = string> inline void eputs(T s) {
    cout << s << "\n";
    exit(0);
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
    std::fill((T *)array, (T *)(array + N), val);
}
template <typename T> using PQG = priority_queue<T, vector<T>, greater<T>>;
template <typename T> using PQ = priority_queue<T>;

typedef long long ll;
typedef pair<ll, ll> PL;
typedef vector<PL> VPL;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<double> VD;

#define uni int;

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
const ll dx[] = {1, 0, -1, 0};
const ll dy[] = {0, 1, 0, -1};
#define PI 3.141592653589793238

VL x, y, a, b;
VL memo[26];

signed main() {
    int a;
    string s;
    cin >> a >> s;
    if(a >= 3200)
        cout << s;
    else
        cout << "red";
    return 0;
}


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

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, ll> l4;

#define mp make_pair
#define pb push_back

int n;
const int maxn = 1e5+1;
ll A[maxn];

int main()
{
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i)
    scanf("%lld", A+i);
  reverse(A+1, A+1+n);
  ll l = 2, r = 2;
  for (int i = 1; i <= n; ++i)
    {
      ll nl = (l+A[i]-1)/A[i]*A[i];
      ll nr = r/A[i]*A[i];
      if (nl > nr)
	{
	  puts("-1");
	  return 0;
	}
      l = nl, r = nr+A[i]-1;
    }
  printf("%lld %lld\n", l, r);
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define PI acos(-1)
typedef  long long ll;
ll gcd(ll x,ll y){
   if(y==0) return x;
   else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
   return x/gcd(x,y)*y;
}

int main(){
   int n;
   cin>>n;
   ll ans=0;
   rep(i,n){
      int x;
      cin>>x;
      ans+=x;
   }
   ans-=n;
   cout<<ans;
   return 0;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long int n,a,b,ans;
    cin>>n>>a>>b;
    if(a<b){
        long long int temp=a;
        a=b;
        b=temp;
    }
    if((a-b)%2){
        if(b-1>n-a){
            ans=n-a;
        }
        else{
            ans=b-1;
        }
        ans++;
        ans+=(a-b-1)/2;
        cout<<ans<<"\n";
    }
    else{
        cout<<(a-b)/2<<"\n";
    }
}

Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<cmath>
#include<list>
#include<set>
#include<map>

using namespace std;
long long MOD = 1000000007LL;

int main() {
	map<string, int> mp;
	string a, b;
	cin >> a >> b;
	int numA, numB;
	cin >> numA >> numB;

	mp[a] = numA;
	mp[b] = numB;

	string s;
	cin >> s;
	mp[s]--;
	cout << mp[a] << " " << mp[b] << endl;

	return 0;
}


Measured memory_bytes: 256
Edge = Struct.new(:from, :to, :cost)

N, M = gets.split.map(&:to_i)
edges = Array.new(M) { a, b, c = gets.split.map(&:to_i); Edge.new(a-1, b-1, -c) }

dist = Array.new(N, Float::INFINITY)
dist[0] = 0

count = 0
update = false
loop do
  count += 1
  update = false
  
  M.times do |i|
    e = edges[i]
    next if dist[e.from] == Float::INFINITY
    
    if dist[e.from] + e.cost < dist[e.to]
      dist[e.to] = dist[e.from] + e.cost
      update = true if e.to == N-1
    end
  end
  
  break unless update
  break if count >= M+1
end

puts update ? "inf" : -dist[N-1]

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

import sys

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 ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
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 = INT()
XYH = []
for i in range(N):
    x, y, h = MAP()
    XYH.append((x, y, h))

# 中心候補として全座標を試す
for y1 in range(101):
    for x1 in range(101):
        H = set()
        for x2, y2, h in XYH:
            # 各座標情報から、中心の高さ(仮)を出す
            tmph = abs(x1-x2) + abs(y1-y2) + h
            # 高さ0の情報は使えないので除く
            if h > 0:
                H.add(tmph)
        # 合ってるか再確認
        if len(H) == 1:
            ansh = list(H)[0]
            for x2, y2, h in XYH:
                tmph =  ansh - (abs(x1-x2) + abs(y1-y2))
                if tmph < 0:
                    continue
                if tmph != h:
                    break
            else:
                print(x1, y1, list(H)[0])
                exit()


Measured memory_bytes: 3192
import java.util.Scanner;

public class Main{
  static public void main(String args[]){
    int S = 0;
    int h,m,s = 0;

    Scanner sc = new Scanner(System.in);
    S = sc.nextInt();

    h = S/3600;
    m = (S%3600)/60;
    s = (S%3600)%60;
    System.out.println(h+":"+m+":"+s);
  }
}

Measured memory_bytes: 26008
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
//typedef long long ll;
int main(void)
{
  int a,b,c,k,ans=0;
  scanf("%d%d%d%d",&a,&b,&c,&k);
  if(k<=a) ans=k;
  else if(k<=(a+b)) ans=a;
  else if(k<=(a+b+c)) ans=a-(k-(a+b));
  printf("%d",ans);

  
  return 0;
}

Measured memory_bytes: 1736
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <cstdio>
#include <fstream>
#include <map>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <set>
#include <queue>
#include <list>

using namespace std;
bool ju[10][10];
bool k[10];
int n;
int co=0;
void bfs(int z)
{
    bool f=true;
    for(int i=2;i<=n;++i)
    {
        if(k[i]==false&&ju[z][i])
        {
            f=false;
            k[i]=true;
            bfs(i);
            k[i]=false;
        }
    }
    if(f)
    {
        bool ff=true;
        for(int i=2;i<=n;++i)
            if(k[i]==false)
        {
            ff=false;
            break;
        }
        if(ff) ++co;
    }
}
int main()
{
    int m,a,b;
    scanf("%d%d",&n,&m);
    while(m--)
    {
        scanf("%d%d",&a,&b);
        ju[a][b]=ju[b][a]=true;
    }
    k[1]=true;
    bfs(1);
    printf("%d",co);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = unsigned long long;
ll gcd(ll x, ll y)
{
    if(y == 0) return x;
    return gcd(y, x%y);
}
int main()
{
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    set<int> s;
    for(int i = 0; i < n; i++)
    {
        cin >> a[i];
        s.insert(a[i]);
    }
    ll x = 1;
    int count = 0;
    int tmp = *s.begin();
    while(tmp % 2 == 0)
    {
        tmp /= 2;
        count++;
    }
    bool flag = true;
    for(int cand : s)
    {
        int ttmp = cand;
        x = x / gcd(x, ttmp/2) * ttmp/2;
        int tc = 0;
        while(ttmp % 2 == 0)
        {
            ttmp /= 2;
            tc++;
        }
        if(tc != count) flag = false;
    }
    if(!flag)
    {
        cout << 0 << endl;
    }
    else
    {
        ll ans = m / (2*x);
        if(m % (2*x) >= x) ans++;
        cout << ans << endl;
    }
}



Measured memory_bytes: 640
#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <algorithm>

using namespace std;
#define lli long long int
#define numberofdigits(x) floor(log10(x)) + 1

int main()
{
    lli a,b,c,k,t;
    cin>>a>>b>>c;
    cin>>k;
    t=0;
    while(b<=a)
    {
        b<<=1;
        t++;
    }
    while(c<=b)
    {
        c<<=1;
        t++;
    }
    if(t<=k)
        cout<<"Yes\n";
    else
        cout<<"No\n";
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
using vec = vector<int>;
using intk = int64_t;

int main() {
int a,b,c,d;
  cin >>a>>b>>c>>d;
  cout <<c - (d-b) << " " << d - (a-c) << " " << a-d+b <<" "<<b-a+c<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, n) for(int i = 1; i < n; i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define P pair<int, int>
typedef long long ll;
const ll mod = 1e9+7;

//繰り返し自乗法による累乗計算
//a**n
ll pow(ll a, ll n){
  if(n == 0) return 1;
  if(n%2 == 0){
    ll res = pow(a, n/2);
    return res * res;
  }
  return a * pow(a, n-1);
}
//繰り返し自乗法によるmod累乗計算
//a**n (mod)
ll modpow(ll a, ll n){
  if(n == 0) return 1;
  if(n%2 == 0){
    ll res = modpow(a, n/2);
    return res * res % mod;
  }
  return a * modpow(a, n-1) % mod;
}
//組み合わせ
//nCa
ll com(ll n, ll a){
  ll x = 1, y = 1;
  rep(i,a){
    x *= n-i;
    y *= i+1;
  }
  ll res = x / y;
  return res;
}
//組み合わせ(mod)
//nCa (mod)
ll modcom(ll n, ll a){
  ll x = 1, y = 1;
  rep(i, a){
    x = x * (n-i) % mod;
    y = y * (i+1) % mod;
  }
  ll ans = x * modpow(y, mod-2) % mod;
  return ans;
}
//gcd 最大公約数
ll gcd(ll x, ll y){
  if(x % y == 0) return y;
  return gcd(y, x%y);
}
//lcm 最小公倍数
ll lcm(ll x, ll y){
  return x * y / gcd(x, y);
}
//ngcd n個の最大公約数
ll ngcd(vector<ll> a){
  ll res;
  res = a[0];
  for(ll i = 1; i < a.size() && res != 1; i++) {
    res = gcd(a[i], res);
  }
  return res;
}
//nlcm n個の最小公倍数
ll nlcm(vector<ll> a) {
  ll res;
  res = a[0];
  for (ll i = 1; i < a.size(); i++) {
    res = lcm(res, a[i]);
  }
  return res;
}
// 素数判定
bool isprime(ll x){
  ll i;
  if(x < 2) return false;
  else if(x == 2) return true;
  if(x % 2 == 0) return false;
  for(i = 3; i*i <= x; i += 2){
    if(x % i == 0) return false;
  }
  return true;
}
// 桁和
ll digsum(ll x){
  ll res = 0;
  while(x > 0){
    res += x % 10;
    x /= 10;
  }
  return res;
}


int main(){
  int n;
  cin >> n;
  int c = 4;
  int d = 7;
  for(int i = 0; i*c <= n;i++){
    if((n - i*c) % d == 0){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}



Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}

func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	n, s := iScan(), iScan()
	a := iSScan(n)
	dp := make([][]int, n+1)
	dp[0] = make([]int, 3001)
	dp[0][0] = 1
	mod = 998244353
	for i := 1; i < n+1; i++ {
		dp[i] = make([]int, 3001)
		dp[i][0] = dp[i-1][0] * 2 % mod
		for j := 1; j < a[i-1]; j++ {
			dp[i][j] = dp[i-1][j] * 2
			dp[i][j] %= mod
		}
		for j := a[i-1]; j < 3001; j++ {
			dp[i][j] = dp[i-1][j]*2 + dp[i-1][j-a[i-1]]
			dp[i][j] %= mod
		}
	}
	fmt.Println(dp[n][s])
}


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

using namespace std;

#define int long long
#define endl "\n"

const long long INF = (long long)1e18;
const long long MOD = 1'000'000'007; 

string yn(bool f){return f?"Yes":"No";}
string YN(bool f){return f?"YES":"NO";}



signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	string s;
	int ma = 0;
	
	cin>>s;
	
	for(int i = 0; i < s.size(); i++){
		for(int j = i; j < s.size(); j++){
			bool flag = true;
			for(int k = i; k <= j; k++){
				if(s[k] != 'A' && s[k] != 'C' && s[k] != 'T' && s[k] != 'G'){
					flag = false;
					break;
				}
			}
			
			if(flag){
				ma = max(ma, j-i+1);
			}
		}
	}
	
	cout<<ma<<endl;
	
	
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<time.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define rp(a) while(a--)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
int main(){
	int a,b;
	while(cin>>a>>b){
		map<int,vector<int> >in;
		in[a].pb(b);
		in[b].pb(a);
		while(cin>>a>>b,a||b){
			in[a].pb(b);
			in[b].pb(a);
		}
		bool h=true;
		for(map<int,vector<int> >::iterator it=in.begin();it!=in.end();it++){
			int d=it->first;
			//cout<<d<<" "<<in[d].size()<<endl;
			if(!(d==1||d==2)&&in[d].size()%2){h=false;break;}
			else if((d==1||d==2)&&in[d].size()%2==0){h=false;break;}
			
		}
		if(h)cout<<"OK"<<endl;
		else cout<<"NG"<<endl;
	}
}

Measured memory_bytes: 1212
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
void fast()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}
void solve()
{
  ll n;
  cin >> n;
  vector<ll>a(n);
  for(int i=0;i<n;i++) cin >> a[i];
   ll sum =0;
   ll mx = 0;
  for(int i=0;i<n;i++)
  {
      mx = max(mx,a[i]);
      sum += mx-a[i];
  }
  cout << sum << endl ;
}
int main()
{
  fast();
  solve();

return 0;
}


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

int main()
{
    // 入力
    ll N, K;
    cin >> N >> K;
    string S;
    cin >> S;

    // 連続した文字を数えて整数列を作成
    vector<ll> v;
    ll cnt = 1;
    char c = S[0];
    for(int i = 1; i < N; i++)
    {
        if(c == S[i])
        {
            cnt++;
        }
        else
        {
            v.push_back(cnt);
            c = S[i];
            cnt = 1;
        }
        if(i == N-1) v.push_back(cnt);
    }

    // 反転する前の幸福値を計算
    ll ans = 0;
    for(int i = 0; i < v.size(); i++) ans += v[i]-1;

    // 反転処理
    
    // 端っこではない文字の反転
    if(K <= v.size()-2) // K回だけ反転
    {
        ans += 2 * K;
        K = 0;
    }
    else // 端っこではない文字をすべて反転
    {
        ll times = max(0LL, (ll)(v.size()-2));
        ans += 2LL * times;
        K -= times;
    }

    // 端っこの文字を反転
    ans += min(2LL, K); //端っこは左端と右端の二つしかない

    // 最大値はN-1より大きくはならない
    ans = min(N-1, ans);

    // 出力
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1528
#include <bits/stdc++.h>
using intl = long long;
using itnl = long long;
using itn = int;
using ld = long double;
using namespace std;
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define rrep(i, n) for(intl i = (intl)(n) - 1; i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define rrepi(i, a, b) for(intl i = (intl)(a); i > (intl)(b); i--)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,1,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define alength(a) (sizeof(a) / sizeof(a[0]))
#define cin(i, a) rep(i, alength(a))cin >> a[i]
#define ccin(i, j, a) rep(i, alength(a))rep(j, alength(a[i]))cin >> a[i][j]
#define debug(x) cout << #x << ":" << x << endl
#define rdebug(i,x) rep(i, alength(x))cout << #x << "[" << i << "]:" << x[i] << endl
#define sqrt sqrtl
#define itn int
#define double ld
#define pb push_back
#define mp make_pair
const intl INF = 1e9;
const intl MOD = 1e9+7;
const ld eps = 1.0e-14;//-9
void fp(bool f){cout << (f ? "Yes" : "No") << endl;}
void fp(bool f, string s, string t){cout << (f ? s : t) << endl;}
intl kai(intl k){
    intl a = 1;
    for(int i = 2; i <= k; i++){
        a *= i;
    }
    return a;
}
intl gcd(intl a, intl b){
    if(!b)return a;
    return gcd(b, a % b);
}
intl lcm(intl a,intl b){
    return a / gcd(a, b) * b;
}
intl digit10(intl a){
    intl b = 0;
    do{
        a /= 10;
        b++;
    }while(a);
    return b;
}
signed main(){
    cout << fixed << setprecision(10);
    intl n;
    cin >> n;
    if(n < 1200)cout << "ABC" << endl;
    else if(n < 2800)cout << "ARC" << endl;
    else cout << "AGC" << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt(), b = sc.nextInt(), c = sc.nextInt(), d = sc.nextInt();
		sc.close();
		String ans[] = {"Left", "Balanced", "Right"};
		int an = 0;
		a += b;
		c += d;
		if(a == c)an = 1;
		else if(a < c)an = 2;
		System.out.println(ans[an]);
	}

}


Measured memory_bytes: 22740
t = list(map(int,input().split()))
a = list(map(int,input().split()))
s = sum(a)
count = 0

for i in range(t[0]):
    if a[i] >= s/(4 * t[1]):
        count += 1

if count >= t[1]:
    print("Yes")
else:
    print("No")

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

int main() {
	int n;
	cin>>n;
	int a[n], b[n];

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


	sort(a, a+n);


 

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

	if(c==2 || c==0) cout<<"YES";
	else cout<<"NO";


}


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

using namespace std;

int main()
{
     
     ios :: sync_with_stdio(false);
     cin.tie(0);
     
    string s, ans;
    
    cin>>s;
    
    for(int i=0;i<s.size();i++)
    {
        if(s[i]=='B')
        {
            if(ans.size())
            ans.pop_back();
        }
        
        else
        {
            ans=ans+s[i];
        }
    }
    cout << ans <<endl;
    
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int t = sc.nextInt();

		int[] c = new int[n];
		int[] time = new int[n];

		for(int i = 0; i < n; i++) {
			c[i] = sc.nextInt();
			time[i] = sc.nextInt();
		}

		int answer = 1001;

		for (int i = 0; i < n; i++) {
			if(time[i] <= t) {
				answer = Math.min(answer, c[i]);
			}
		}

		if(answer != 1001) {
			System.out.println(answer);
		}else {
			System.out.println("TLE");
		}
	}
}


Measured memory_bytes: 23892
#include <iostream>

int main() {
        int m, f, r;

        while(true){
                std::cin >> m >> f >> r;
                if (m==-1 && f==-1 && r==-1) break;

                if (m==-1 || f==-1) std::cout << 'F' << std::endl;
                else if (m+f >= 80) std::cout << 'A' << std::endl;
                else if (m+f >= 65) std::cout << 'B' << std::endl;
                else if (m+f >= 50 ) std::cout << 'C' << std::endl;
                else if (m+f >= 30) {
                        if (r >= 50) std::cout << 'C' << std::endl;
                        else std::cout << 'D' << std::endl;
                }
                else if (m+f < 30) std::cout << 'F' << std::endl;
        }
}

Measured memory_bytes: 3052
#include <iostream>
using namespace std;
int main (void)
{
    int a[200001];
    int b[200001];
    int n;
    int i;
    int k;
    cin >> n;
    for(i = 0; i < n; i++){
        cin >> a[i];
    }

    //偶数
    if (n % 2 == 0){
        for(i = 0; i <= (n-2)/2; i++){
            b[i] = a[n-2*(i+1)];
        }
        k = 1;
        for(i = (n-2)/2 + 1; i <= n-1; i++){
            b[i] = a[2*k-1];
            k++;
        }
    }


    //奇数
    if (n % 2 == 1){
        k = n - 2;
        for(i = 0; i <= (n-1)/2 - 1; i++){
            b[i] = a[k];
            k = k - 2;
        }
        k = 0;
        for (i = (n-1)/2; i <= n-1; i++){
            b[i] = a[2*k];
            k++;
        }

    }

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

    for(i = 0; i < n; i++){
        cout << c[i] << ' ';
    }
    cout << endl;

    return 0;
}

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

#define Int long long int
#define REP(i,n) for(int i=0;i<(n);i++)
#define REAP(i,a,n) for(int i=(a);i<(n);i++)
#define YES cout<<"Yes"<<endl
#define NO cout<<"No"<<endl
#define fr first
#define sc second
#define pb push_back
#define All(v) v.begin(),v.end()

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    if(a+b<c) NO;
    else YES;
}


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

int main() {
    int q;
    std::cin >> q;

    std::list<int> L;
    std::list<int>::iterator it = L.end();
    for (int i = 0; i < q; i++) {
        int op;
        std::cin >> op;
        if (op == 0) {
            int x;
            std::cin >> x;
            it = L.insert(it, x);
        } else if (op == 1) {
            int d;
            std::cin >> d;
            std::advance(it, d);
        } else if (op == 2) {
            it = L.erase(it);
        }
    }

    for (int e : L) {
        std::cout << e << std::endl;
    }
}



Measured memory_bytes: 18576
A =list(str(input()))
B =list(str(input()))
C =list(str(input()))
P=A
for i in range(len(A)+len(B)+len(C)+3):
    if P[0] == 'a':
        P.pop(0)
        P=A
        if len(A) ==0:
            print('A')
            break
    elif P[0] =='b':
        P.pop(0)
        P=B
        if len(B) ==0:
            print('B')
            break
    elif P[0] =='c':
        P.pop(0)
        P=C
        if len(C) ==0:
            print('C')
            break


Measured memory_bytes: 9144
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < n; i++)
static const long long INF = 1000000;
using p = pair<int,int>;

set<int> prime_judge(int n){
    set<int> ans;
    vector<int> vec(n + 1,1);
    double a = sqrt(n);
    int b = (int)a + 2;
    for (int i = 2;i < b;i++){
        if (vec[i]){
            for (int j = 2; i * j < n + 1; j++){
                vec[i*j] = 0;
            }
        }
    }
    for (int i = 3; i < n+1;i++){
        if (vec[i] and vec[(i + 1)/2]){
            ans.insert(i);
        }
    }
    return ans;
    
}

int main(){
    int q;
    cin >> q;
    vector<p> vec;
    rep(i,q){
        int l,r;
        cin >> l >> r;
        p pp;
        pp = {l,r};
        vec.push_back(pp);
    }
    set <int> st;
    st = prime_judge(100000);
    vector<int> im(100001,0);
    for (int i = 2; i < 100001; i++){
        if (st.count(i) != 0){
            im[i] = im[i-1] + 1;

        }
        else {
            im[i] = im[i-1];
        }
    }
    for (auto x : vec){
        int s = im[x.second] - im[x.first -1];
        cout << s << endl;
    }

}

Measured memory_bytes: 4636
A, B, C, X, Y = list(map(int, input().split()))
C *= 2
ans = 0

if A >= C and B >= C:
    ans += max(X, Y) * C
elif C >= A+B:
    ans += A*X + B*Y
elif C >= max(A,B):
    if X>Y:
        ans += Y*C + (X-Y)*A
    else:
        ans += X*C + (Y-X)*B
else:
    if A >= C:
        ans += X*C
        if Y-X>0:
            ans+=(Y-X)*B
    else:
        ans += Y*C
        if X-Y>0:
            ans+=(X-Y)*A

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define RFOR(i, start, end) for (int i = start; end <= i; i--)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1'000'000'007
#define INF32 1'050'000'000
#define INF64 4'000'000'000'000'000'000
using ll = long long;
using namespace std;
template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }

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

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

    int cnt = 0;
    for (int l=0; l<N; ++l) {
        while (h[l] > 0) {
            int r;
            for (r = l+1; r<N; r++) {
                if (h[r] == 0) break;
            }
            for (int j = l; j<r; ++j) {
                --h[j];
            }
            ++cnt;
        }
    }

    cout << cnt << '\n';

    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  map<int, int> mpa, mpb;
  int enf = 0;
  rep(i, n){
    cin >> a.at(i);
    mpa[a.at(i)]++;
    if(mpa[a.at(i)] > n/2) enf = a.at(i);
  }
  vector<int> b(n);
  int enfb = 0;
  rep(i, n){
    cin >> b.at(i);
    mpb[b.at(i)]++;
    if(mpb[b.at(i)] > n/2) enfb = b.at(i);
  }
  if(enfb > enf){
    if(mpa[enfb] > n - mpb[enfb]){
      cout << "No" << endl;
      return 0;
    }
  }else{
    if(mpb.count(enf) > 0 && mpb[enf] > n - mpa[enf]){
      cout << "No" << endl;
      return 0;
    }
  }
  reverse(ALL(b));
  int l = 0, r = 0, now = 0;
  rep(i, n){
    if(now != a.at(i)){
      l = 0, r = n-1;
      now = a.at(i);
    }
    if(a.at(i) == b.at(i)){
      bool f = false;
      BK:
      if(b.at(l) != a.at(i) && b.at(i) != a.at(l)){
        swap(b.at(i), b.at(l));
        l++;
      }else if(b.at(r) != a.at(i) && b.at(i) != a.at(r)){
        swap(b.at(i), b.at(r));
        r--;
      }else{
        if(r < l){
          if(f == true){
            cout << "No" << endl;
            return 0;
          }
          f = true;
          l = 0, r = n-1;
        }else{
          l++; r--;
        }
        goto BK;
      }
    }
  }
  cout << "Yes" << endl;
  rep(i, n){
    if(i != 0) cout << " ";
    cout << b.at(i);
  }
  cout << endl;


  return 0;
}

Measured memory_bytes: 23416
N = int(input())
As = list(map(int, input().split()))

first = sum([a*2 if i%2==0 else -a*2 for i, a  in enumerate(As)])//2
ans = [str(first)]
for i, a in enumerate(As[:-1]):
    ans.append(str((a*2)-first))
    first = (a*2)-first
print(' '.join(ans))

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

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

const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const int MOD = 1000000007;

// Library

//

int main() {
#ifdef MYLOCAL
    ifstream in("input.txt");
    cin.rdbuf(in.rdbuf());
#endif
    int n; cin >> n;
    vector<int> a(n);
    vector<int> b(n);
    vector<int> c(n);
    for(int i = 0; i < n; ++i){
        cin >> a[i];
    }
    for(int i = 0; i < n; ++i){
        cin >> b[i];
    }
    for(int i = 0; i < n; ++i){
        cin >> c[i];
    }
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    sort(c.begin(), c.end());

    ll ans = 0;
    for(int i = 0; i < n; ++i){
        int mid = b[i];

        auto iter_lower = lower_bound(a.begin(), a.end(), mid);
        ll a_num = distance(a.begin(), iter_lower);
        auto iter_upper = upper_bound(c.begin(), c.end(), mid);
        ll c_num = n - distance(c.begin(), iter_upper);

        ans += a_num*c_num;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 10000000007

int main() {
	ll n;
	cin>>n;
	vector<ll>ch;
	for(ll i=0;i<n;i++){
		ll now;
		cin>>now;
		ch.push_back(now);
	}
	sort(ch.begin(),ch.end());
	ll ans=0;
	for(ll i=n-1;i>=2;i--){
		for(ll j=i-1;j>=1;j--){
			ll las=ch[i]-ch[j]+1;
			auto itr=lower_bound(ch.begin(),ch.end(),las);
			ll ban=itr-ch.begin();
			ans+=max(ll(0),j-ban);
		}
	}
	cout <<ans;
	// your code goes here
	return 0;
}

Measured memory_bytes: 3564
#include<bits/stdc++.h>
#include <cstring>
#include <iostream>
#define pie acos(-1)
#define si(a) scanf("%d",&a)
#define sii(a,b) scanf("%d %d",&a,&b)
#define siii(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define sl(a) scanf("%lld",&a)
#define sll(a,b) scanf("%lld %lld",&a,&b)
#define slll(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define ss(st) scanf("%s",st)
#define sch(ch) scanf("%ch",&ch)
#define ps(a) printf("%s",a)
#define newLine() printf("\n")
#define pi(a) printf("%d",a)
#define pii(a,b) printf("%d %d",a,b)
#define piii(a,b,c) printf("%d %d %d",a,b,c)
#define pl(a) printf("%lld",a)
#define pll(a,b) printf("%lld %lld",a,b)
#define plll(a,b,c) printf("%lld %lld %lld",a,b,c)
#define pd(a) printf("%lf",a)
#define pdd(a,b) printf("%lf %lf",a,b)
#define pddd(a,b,c) printf("%lf %lf %lf",a,b,c)
#define pch(c) printf("%ch",c)
#define debug1(str,a) printf("%s=%d\n",str,a)
#define debug2(str1,str2,a,b) printf("%s=%d %s=%d\n",str1,a,str2,b)
#define debug3(str1,str2,str3,a,b,c) printf("%s=%d %s=%d %s=%d\n",str1,a,str2,b,str3,c)
#define debug4(str1,str2,str3,str4,a,b,c,d) printf("%s=%d %s=%d %s=%d %s=%d\n",str1,a,str2,b,str3,c,str4,d)
#define for0(i,n) for(i=0;i<n;i++)
#define for1(i,n) for(i=1;i<=n;i++)
#define forab(i,a,b) for(i=a;i<=b;i++)
#define forstl(i, s) for (__typeof ((s).end ()) i = (s).begin (); i != (s).end (); ++i)
#define NL puts("")
#define sd(a) scanf("%lf",&a)
#define sdd(a,b) scanf("%lf %lf",&a,&b)
#define sddd(a,b,c) scanf("%lf %lf %lf",&a,&b,&c)
#define SP printf(" ")
#define LL long long int
#define ULL unsigned long long int
#define N 1000007
#define MOD 100000009
#define pub(x) push_back(x)
#define pob(x) pop_back(x)
#define mem(ara,value) memset(ara,value,sizeof(ara))
#define INF INT_MAX
#define eps 1e-8
#define checkbit(n, pos) (n & (1<<pos))
#define setbit(n, pos) (n | (1<<pos))
#define para(a,b,ara)\
for(int i=a;i<=b;i++){\
    if(i!=0){printf(" ");}\
    printf("%d",ara[i]);\
}\
printf("\n");
#define pvec(vec)\
for(int i=0;i<vec.size();i++){\
    if(i!=0){printf(" ");}\
    printf("%d",vec[i]);\
}\
printf("\n");
#define ppara(n,m,ara)\
for(int i=0;i<n;i++){\
    for(int j=0;j<m;j++){\
        if(j!=0){printf(" ");}\
        printf("%d",ara[i][j]);\
    }\
    printf("\n");\
}
#define ppvec(n,vec)\
for(int i=0;i<n;i++){\
    for(int j=0;j<vec[i].size();j++){\
        if(j!=0){printf(" ");}\
        printf("%d",vec[i][j]);\
    }\
    printf("\n");\
}
#define sara(a,b,ara)\
for(int i=a;i<=b;i++){\
    scanf("%d",&ara[i]);\
}
using namespace std;
int n,ara[2010];
bitset <2010*2010> dp[2];
int sum=0;
void input(){
    int i,j,ans;
    si(n);
    for0(i,n){si(ara[i]);sum+=ara[i];}
    dp[0].set(0);
    for1(i,n){
        dp[i&1]=dp[(i-1)&1]|(dp[(i-1)&1]<<ara[i-1]);
    }
    ans=0;
    for(i=(sum+1)/2;i<2005*2005;i++){
        if(dp[n&1][i]){
            ans=i;
            break;
        }
    }
    pi(ans);NL;
}
int main(){
    input();
    return 0;
}


Measured memory_bytes: 2688
def check(A):
  check_result = []
  for i in range(1, len(A)):
    check_result.append(list(set(A[i-1])&set(A[i])))
  if len(check_result) != len(A):
    return check_result
  return False

N, M = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(N)]
for i in range(len(A)):
  A[i].pop(0)
while True:
  check_result = check(A)
  if check_result:
    A = check_result
  else:
    if not A[0]:
      print(0)
      break
    else:
      print(len(A[0]))
      break

Measured memory_bytes: 3064