akhauriyash/Code-Regression huggingface dataset:
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

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

const ll INF = 1LL << 50;

int main() {
  ll h, w, k;
  cin >> h >> w >> k;

  vvll sposs(h);
  vvll ans(h, vll(w, 0));

  rep(i, h) {
    string s;
    cin >> s;
    rep(j, (ll)s.size()) if (s[j] == '#') sposs[i].push_back(j);
  }

  ll ii = 0;
  ll startii = 0;
  rep(i, h) {
    if (sposs[i].size() != 0) {
      ii = i;
      startii = i;
      break;
    }
  }

  ll curn = 1;
  while (ii < h) {
    ll nextii = h;
    for (ll jj = ii + 1; jj < h; jj++) {
      if (sposs[jj].size() != 0) {
        nextii = jj;
        break;
      }
    }  // jj

    for (ll sidx = 0; sidx < (ll)sposs[ii].size(); sidx++) {
      ll prev_spos = (sidx == 0) ? -1 : sposs[ii][sidx - 1];

      ll spossiisiz = (ll)sposs[ii].size();
      ll end_spos = (sidx == spossiisiz - 1) ? w - 1 : sposs[ii][sidx];
      for (ll yy = ii; yy < nextii; yy++) {
        for (ll xx = prev_spos + 1; xx <= end_spos; xx++) {
          ans[yy][xx] = curn;
        }  // xx
      }    // yy
      curn++;
    }  // sidx
    ii = nextii;
  }  // while

  for (ll yy = startii - 1; yy >= 0; yy--) {
    rep(xx,w) ans[yy][xx] = ans[yy+1][xx];
  }


  rep(i, h) {
    rep(j, w) cout << ans[i][j] << " ";
    cout << endl;
  }

  return 0;
}


Measured memory_bytes: 2688
#include<bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
 //freopen("input.txt", "r", stdin); 
 //freopen("output.txt", "w", stdout); 
 int n;
 long long sum =0;
 cin>>n;

 /*
 ..................
 This general solution to find the factors of num can be interchanged
 since both inner and outer loop are independent.
 ......................
 ### General Sol:
 for(int num=1;num<=n;num++)
 {
     for(int den=1;den <=n;den++)
     {
         if(num%den == 0)
         {
             sum += num;
         }
     }
 }

 #### Interchanging inner and outer loop:-

 for(int den=1;den<=n;den++)
 {
     for(int num=1;num <=n;num++)
     {
         if(num%den == 0)
         {
             sum += num;           //The result will be same but we can now interpret the 
                                   //question differently.
         }
     }
 }

 #### we are finding for every 'den' its multiples and the sum of it.
 thus g(x) = sum of multiples of x can be found easily using AP.

 and we have to find  sum of g(1 -> N)
 .......................
*/

for(long long i=1;i<=n;i++)
{
    long long y = floor(n/i); // highest multiple of i <= n
    sum +=  (i*y*(y+1))/2;
}


 cout<<sum<<endl;

return 0;
}

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

int n,ans=0,five=0,three=0;
vector<int> divs[101];
int cnt[101];
int q3=0,q5=0,q15=0,q25=0,q75=0;

int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		cnt[i]=0;
	}
	for(int i=2;i<=n;i++){
		int tmp=i;
		for(int j=2;j<=i;j++){
			while(tmp%j==0){
				cnt[j]++;
				tmp/=j;
			}
		}
	}
	for(int i=1;i<=n;i++){
		if(cnt[i]>=2){
			q3++;
		}
		if(cnt[i]>=4){
			q5++;
		}
		if(cnt[i]>=14){
			q15++;
		}
		if(cnt[i]>=24){
			q25++;
		}
		if(cnt[i]>=74){
			q75++;
		}
	}
	//cout<<q5<<" "<<q3<<endl;
	cout<<q75+q25*(q3-1)+q15*(q5-1)+q5*(q5-1)*(q3-2)/2<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(c) (c).begin(), (c).end()
#define pb push_back
#define eb emplace_back
using namespace std;
const long long INF = 1LL<<60; // 仮想的な無限大の値;
using ll = unsigned long long;
using P  = pair<int, int>;
#define vi vector<int>
#define vl vector<ll>
#define vs vector<string>
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; }

int main()
{
    ll x;
    cin >> x;

    int m = 2000;
    vl A(m);
    rep2(i, 0, m) {
        ll p = i;
        A[i] = p*p*p*p*p;
    }
    rep2(i, 0, m)rep2(j, 0, m)
    {
        ll y = A[i] - A[j];
        if(y == x)
        {
            cout << i << " " << j << endl;
            return 0;
        }
        y = A[i]+ A[j];
        if(y == x)
        {
            cout << i << " " << -j << endl;
            return 0;
        }
    }
    return 0;
}

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

using namespace std;

void fastio() {
	cin.tie(nullptr);
	cin.sync_with_stdio(false);
}

using LL = long long;
using LD = long double;

const LL MOD = 1e9+7;
const LL INF = LLONG_MAX;
const LL N = 1e6+1;

#define F first
#define S second

int main() {
	fastio();
	
	LL a, b, c, d;
	cin >> a >> b >> c >> d;

	cout << max({a*c, a*d, b*c, b*d}) << "\n";

}

Measured memory_bytes: 3652
import Control.Monad
import Data.List
import qualified Data.IntMap.Strict as IntMap

main :: IO ()
main = do
  (n:m:_) <- fmap (map read . words) getLine :: IO [Int]
  am <- replicateM m $ map read . words <$> getLine :: IO [[Int]]
  print $ solve n am

solve :: Int -> [[Int]] -> Int
solve n am = length . filter (\as -> isValid (toAdjList am) (1:as)) $ candidates n

type AdjList = IntMap.IntMap [Int]
toAdjList :: [[Int]] -> AdjList
toAdjList am = go am IntMap.empty
  where
    go :: [[Int]] -> AdjList -> AdjList
    go [] adjList = adjList
    go (s:ab) adjList = go ab $ if a == b then new else new2
      where
        (a:b:_) = s
        new = IntMap.insertWith (++) a [b] adjList
        new2 = IntMap.insertWith (++) b [a] new

candidates :: Int -> [[Int]]
candidates n = permutations [2..n]

isValid :: AdjList -> [Int] -> Bool
isValid adjList as = goAllNodes && validateEdge adjList as
  where
    goAllNodes = all (\i -> i `elem` as) [1..(length as)]
    validateEdge :: AdjList -> [Int] -> Bool
    validateEdge adjList (a:[]) = True
    validateEdge adjList (a:b:as) = b `elem` (adjList IntMap.! a) && validateEdge adjList (b:as)


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

int main()
{
	int n;
	cout << fixed << setprecision(6);
	while (cin >> n, n) {
		double ave = 0, res = 0;
		vector<int> s(n);
		for (int i = 0; i < n; i++) {
			cin >> s[i];
			ave += s[i];
		}
		ave /= n;
		for (int i = 0; i < n; i++) {
			res += (s[i] - ave) * (s[i] - ave);
		}
		cout << sqrt(res / n) << endl;
	}
	return 0;
}

Measured memory_bytes: 3252
#include <bits/stdc++.h> 
using namespace std; 
  
typedef long long ll; 
typedef pair<int, int> pii; 
typedef pair<ll, ll> pll; 
typedef pair<string, string> pss; 
typedef vector<int> vi; 
typedef vector<vi> vvi; 
typedef vector<pii> vii; 
typedef vector<ll> vl; 
typedef vector<vl> vvl; 
  
#define rep(a, b, c) for (int(a) = (b); (a) < (c); ++(a)) 
#define revrep(a, b, c) for (int(a) = (c-1); (a) >= (b); --(a)) 
#define fi first 
#define se second 
#define mp make_pair 
#define pb push_back 

int main() 
{ 
    ll x,xx,y,a,b,c,n,i,j,ans=0;
    cin>>xx>>y;
    cin>>a>>b>>c;
    vl red,green,less,res;
    rep(i,0,a){
        cin>>x;
        red.pb(x);
    }
    rep(i,0,b){
        cin>>x;
        green.pb(x);
    }
    rep(i,0,c){
        cin>>x;
        less.pb(x);
    }
    sort(red.rbegin(),red.rend());
    sort(green.rbegin(),green.rend());
    rep(i,0,xx){
        res.pb(red[i]);
    }
    rep(i,0,y){
        res.pb(green[i]);
    }
    rep(i,0,c){
        res.pb(less[i]);
    }
    sort(res.rbegin(),res.rend());
    rep(i,0,xx+y){
        //cout<<res[i]<<" ";
        ans+=res[i];
    }
    //cout<<endl;
    cout<<ans<<endl;
    return 0;
} 

Measured memory_bytes: 8304
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < n; i++)
 
using namespace std;
 
int main() {
  int A, B;
  cin >> A >> B;
  for(int i = 1; i < 10000; i++){
    int c = floor(i * 0.08);
    int d = floor(i * 0.1);
    if(A == c && B == d){
      cout << i << endl;
      return 0;
    }
  }
  cout << "-1" << endl;
  
}

Measured memory_bytes: 256
W,H,m,c[10][11];
DP[11][10][10][10][51];//cà[yÀW][xÀW][¶[][E[][_fcÊ]
#define Update(tgt,val) ((val)>(tgt)?tgt=(val):0)
CalcO(o,x,y){//_fcÊÌvZ
	if(c[x][y]>0){
		o+=c[x][y];
		if(o>m)
			o=m;
	}
	return o;
}
CalcF(f,x,y){//càÌvZ
	if(c[x][y]<0)
		f+=c[x][y];
	return f;
}
main(){
	int x,y,range,d,dx,f,o,xl,xr,fn,on,f0;
	for(;scanf("%d%d",&W,&H),W;){
		scanf("%d%d%d",&f0,&m,&o);
		for(y=1;y<=H;y++)
			for(x=0;x<W;x++)
				scanf("%d",&c[x][y]);
		f0++;//cà0ÅàDPÍ1ÆµÄANAÉÈéÌðh®
		for(y=0,x=0;x<W;x++)
			DP[y][x][x][x][o]=f0;
		for(y=0;y<H;y++){
			for(range=0;range<W;range++){//¶EÉ@éL³
				for(o=m;o>1;o--){
					for(d=0;d<2;d++){//»ÝÊuxð³¹é
						for(xl=0;xl<W-range;xl++){//¶[
							for(dx=0;dx<=range;dx++){//xÏÊ
								xr=xl+range;
								x=d?xl+dx:xr-dx;
								if(f=DP[y][x][xl][xr][o]){
									//ºÖ@é
									fn=CalcF(f,x,y+1);
									on=CalcO(o-1,x,y+1);
									Update(DP[y+1][x][x][x][on],fn);
									if(y>0){
										if(x>0){
											if(x==xl){//¶Ö@é
												fn=CalcF(f,x-1,y);
												on=CalcO(o-1,x-1,y);
												Update(DP[y][x-1][x-1][xr][on],fn);
											}else{//¶ÖiÞ
												Update(DP[y][x-1][xl][xr][o-1],f);
											}
										}
										if(x<W-1){
											if(x==xr){//EÖ@é
												fn=CalcF(f,x+1,y);
												on=CalcO(o-1,x+1,y);
												Update(DP[y][x+1][xl][x+1][on],fn);
											}else{//EÖiÞ
												Update(DP[y][x+1][xl][xr][o-1],f);
											}
										}
									}
								}
							}//dx
						}//xl
					}//d
				}//o
			}//range
		}//y
		fn=0;
		for(x=0;x<W;x++){
			//for(xl=0;xl<W;xl++)
				//for(xr=0;xr<W;xr++)
					for(o=m;o>0;o--){
						f=DP[H][x][x][x][o];
						if(f>fn)
							fn=f;
					}
		}
		printf(fn?"%d\n":"NA\n",f0-fn);
		memset(DP,0,sizeof(DP));
	}
	//puts("");
	exit(0);
}

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

int n;
int arr[100005][3];
int memo[100005][3];

int max(int a, int b, int c) {
	return max(a,max(b,c));
}

int dp(int i, int impos) {
	
	if(i>=n) return 0;
	if(i==n-1) 
	{
		int ret = -1;
		for(int j=0; j<3; ++j) if(impos!=j) ret = max(ret, arr[i][j]);
		return ret;
	}

	if(impos==-1) return max(dp(i+1,0)+arr[i][0], dp(i+1,1)+arr[i][1], dp(i+1,2)+arr[i][2]);

	if(memo[i][impos]==-1)
	{
		int ret = -1;
		for(int j=0; j<3; ++j) if(impos!=j) ret = max(ret, dp(i+1,j)+arr[i][j]);
		memo[i][impos] = ret;
	}

	return memo[i][impos]; 
}

int main() {

	cin >> n;

	int a, b, c;
	for(int i=0; i<n; ++i)
	{
		cin >> a >> b >> c;
		arr[i][0] = a;
		arr[i][1] = b;
		arr[i][2] = c;

		for(int j=0; j<3; ++j) memo[i][j] = -1;
	}

	cout << dp(0, -1) << endl;

	return 0;
}

Measured memory_bytes: 11904
#include <string>
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <math.h>
 
using namespace std;
int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
 
	string x;
    string abc = "ABC";
    string arc = "ARC";
	cin >> x;
    if(x == abc){
      cout << arc << "\n";
    }else{
      cout << abc << "\n";
    }
  
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pair<int, int>> vpii;
typedef pair<int, int> pii;
#define PB push_back
#define EB emplace_back
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

class st{
public:
	string s;
	int p;
	int i;

	bool operator<(const st& rhs){
		if(s!=rhs.s) return s<rhs.s;
		else return p>rhs.p;
	}
};

vector<st> v;

int main(){
	int n; cin>>n;
	REP(i, n){
		string s; int a;  cin>>s>>a;
		v.push_back({s, a, i+1});
	}
	sort(v.begin(), v.end());
	REP(i, n) printf("%d\n", v[i].i);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
        #define ll long long
        #define rep(i,a,b) for(i=a;i<b;i++)
        #define pb push_back
        #define all(v) v.begin(),v.end()
        #define F first
        #define S second
        #define hell 1000000007
        using namespace std;
        const int N=500;
        void solve()
        {
            ll i,j,k,n,m,c=0,ans=0;
            string s;
            cin>>n;
            rep(i,0,n)
            {
                cin>>k; c=0;
                while(k%2==0)
                {
                    k/=2;
                    c++;
                }
                ans+=c;
            }
cout<<ans;



    }

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


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

int n, m, degin[N], par[N];
vector<int> des[N];

int main() {
  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  cin >> n >> m;
  m += n - 1;
  for (int i = 1, u, v; i <= m; ++i) {
    cin >> u >> v;
    des[u].emplace_back(v);
    ++degin[v];
  }
  queue<int> q;
  for (int i = 1; i <= n; ++i) {
    if (degin[i] == 0) {
      q.push(i);
    }
  }
  while (!q.empty()) {
    int u = q.front(); q.pop();
    for (int v: des[u]) {
      if (--degin[v] == 0) {
        par[v] = u;
        q.push(v);
      }
    }
  }
  for (int i = 1; i <= n; ++i) cout << par[i] << "\n";
  return 0;
}

Measured memory_bytes: 7040
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc  = new Scanner(System.in);
		int[] data = new int[10];
		for(int i=0;i<10;i++){
			int h = Integer.parseInt(sc.nextLine());
			data[i] = h;
		}
		Arrays.sort(data);
		for(int i=9;i>6;i--){
			System.out.println(data[i]);
		}
	}
}

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

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

constexpr Int TEN(int n) { return n == 0 ? 1 : 10 * TEN(n-1); }

const int max_n = 100000+10;

class UnionFind {
    private:
        int par[max_n];
        int rank[max_n];
    public:
        UnionFind(int n) {
            for(int i = 1;i <= n;i++) {
                par[i] = i;
                rank[i] = 1;
            }
        }

        int root(int x) {
            return x == par[x] ? par[x] : par[x] = root(par[x]);
        }

        bool same(int x, int y) {
            return par[x] == par[y];
        }

        void merge(int x,int y) {
            x = root(x);
            y = root(y);
            if(same(x,y))
                return;
            if(rank[x] < rank[y]) {
                par[x] = y;
                rank[x]++;
            } else {
                par[y] = x;
                if(rank[x] == rank[y])
                    rank[y]++;
            }

            return;
        }

        int connect(int n) {
            int c = 0;
            for(int i = 1;i <= n;i++)
                if(par[i] == i)
                    c++;

            return c;
        }
};
int N,M;

int main(void) {
    cin>>N>>M;
    UnionFind ut(N);
    for(int i = 0;i < M;i++) {
        int a,b,c;
        cin>>a>>b>>c;
        ut.merge(a,b);
    }

    cout<<ut.connect(N)<<endl;
    return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
#include<string.h>

#define M 1046527
#define L 14

char H[M][L];

int Getchar(char);
long long Getkey(char[]);
int h1(int);
int h2(int);
int Find(char[]);
int Insert(char[]);

int main(){
    int i, n, h;
    char str[L], com[9];

    for (i = 0; i < M; i++) H[i][0] = '\0';

    scanf("%d", &n);

    for (i = 0; i < n; i++){
      scanf("%s %s",com,str);

  	if (com[0] == 'i'){
      Insert(str);
    }
    else{
      if (Find(str)){
        printf("yes\n");
      }
      else{
        printf("no\n");
      }
    }
  }

  return 0;
}

int Getchar(char c){
  if(c == 'A') return 1;
  else if(c == 'C') return 2;
  else if(c == 'G') return 3;
  else if(c == 'T') return 4;
}

long long Getkey(char str[]){
  long long sum = 0, p = 1, i;
  for(i = 0 ; i < strlen(str) ; i++){
    sum += p * (Getchar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int x){
  return x % M;
}

int h2(int x){
  return 1 + (x % (M - 1));
}

int Find(char str[]){
  long long k, i, h;

  k = Getkey(str);
  for(i = 0 ; ; i++){
    h = (h1(k) + i * h2(k)) % M;
    if(strcmp(H[h],str) == 0) return 1;
    else if(strlen(H[h]) == 0) return 0;
  }
  return 0;
}

int Insert(char str[]){
  long long k, i, h;

  k = Getkey(str);
  for(i = 0 ; ; i++){
    h = (h1(k) + i * h2(k)) % M;
    if(strcmp(H[h],str) == 0) return 1;
    else if(strlen(H[h]) == 0){
      strcpy(H[h],str);
      return 0;
    }
  }
  return 0;
}



Measured memory_bytes: 16100
#include <stdio.h>
 
int main(){
	int n, p[20], i, cnt=0;
 
	scanf("%d", &n);
 
	for(i=0; i<n; i++)
		scanf("%d", &p[i]);
 
	for(i=2; i<n; i++){
		if((p[i-2] < p[i-1] && p[i-1] < p[i]) || (p[i] < p[i-1] && p[i-1] < p[i-2]))
			cnt++;
	}
 
	printf("%d\n", cnt);
 
	return 0;
}

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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

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




void solve() {
    ll A, B, K; cin >> A >> B >> K;
    if(A >= K){
        cout << A-K << " " << B << endl;
    }else if(B >= K-A){
        cout << 0 << " " << B-K+A << endl;
    }else{
        cout << 0 << " " << 0 << endl;
    }
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(10);
  //init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}


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

int sgn(int n){
  if(n<0) return -n;
  else return n;
}
int main(){
  int n,sum=0,sum1=0,ans = 100000;
  cin >> n;
  int w[n];
  for(int i=0;i<n;i++)
    cin >> w[i];
  for(int i=0;i<n;i++)
    sum += w[i];
  for(int i=0;i<n;i++){
    sum1 +=w[i];
    int c = sum-sum1;
    ans = min(sgn(sum1-c),ans);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>

#define M 1046527
#define NIL -1
#define L 14

char H[M][L];

int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
}

long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key){ return key % M; }
int h2(int key){ return 1 + (key % (M-1)); }

int find(char str[]){
  long long key, i, h;
  key = getKey(str);
  for ( i = 0;; i++){
    h = (h1(key)+i*h2(key))%M;
    if( strcmp(H[h],str) == 0 ) return 1;
    else if ( strlen(H[h]) == 0 ) return 0;
  }
  return 0;
}

int insert(char str[]){
  long long key, i, h;
  key = getKey(str);
  for ( i = 0; ; i++ ){
    h = (h1(key)+i*h2(key))%M;
    if( strcmp(H[h],str) == 0 ) return 1;
    else if ( strlen(H[h]) == 0 ){
      strcpy(H[h], str);
      return 0;
    }
  }
 return 0;
}

main(){
  int i, n, h;
  char str[L], com[9];
  for ( i = 0; i < M; i++ ) H[i][0] = '\0';
  scanf("%d", &n);
  i=0;
  while(i<n){
    i++;
    scanf("%s %s", com, str);

    if ( com[0] == 'i' ){
      if (insert(str)){

      }
    } else {
      if (find(str) ){
        printf("yes\n");
      } else {
        printf("no\n");
      }
    }
  }
  return 0;
}






Measured memory_bytes: 16056
#include <stdio.h>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <iostream>
#include<math.h>
#include<bitset>
#include<iomanip>
#include<queue>
using namespace std;

int main() {
	int N; cin >> N;
	vector<pair<long long,long long>> x(N),z;
	map<pair<long long,long long>,int> y;
	for (int i = 0; i < N; i++) {
		long long a, b; cin >> a >> b;
		x[i] = { a,b };
	}
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			if (i == j)continue;
			z.push_back({ x[i].first - x[j].first, x[i].second - x[j].second });
			y[{ x[i].first - x[j].first, x[i].second - x[j].second}]++;
		}
	}
	int ans = 0;
	for (int i = 0; i < z.size(); i++) {
		ans = max(y[z[i]], ans);
	}
	cout << N-ans << endl;

}




Measured memory_bytes: 512
const input = require('fs').readFileSync('/dev/stdin', 'utf8');
const lines = input.split("\n").map(Number);

let count = 0;

for(var i = 1;i<lines[0]+1;i++){
    if(lines[i]===1){
        count=count+1;
    }else if(lines[i]>3){
        for(var k = 2;k<Math.sqrt(lines[i])+1;k++){
            if(lines[i]%k===0){
                count = count +1;
                break;     
            }
        }
    }
}
console.log(lines[0]-count);


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

int main() {
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());

    string w;
    cin >> w;

    vector<int> cnt(26,0);
    for (char c : w) {
        cnt[c - 'a']++;
    }

    bool allEven = true;
    for (int i : cnt) {
        if (i%2 != 0) {
            allEven = false;
            break;
        }
    }
    
    if (allEven) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    
}


Measured memory_bytes: 256
ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
import collections
import math
import itertools
import heapq as hq
n,k = ma()
A = list(ma())
A.sort(reverse=True)
if k==0:
    print(A[0])
    exit()

def isok(x):
    cnt=0
    for a in A:
        cnt+= (a-1)//x
    #print(cnt,x)
    return cnt>k
def bisect():
    ok = 0
    ng = 10**9+1
    x = (ok+ng)//2
    while ng-ok>1:
        if isok(x):
            ok = x
        else:
            ng=x
        x = (ok+ng)//2
    return ng
print(bisect())


Measured memory_bytes: 31752
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long int LL;
typedef int ll;
typedef string str;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef stringstream strs;
 
#define X first
#define Y second
#define PB push_back
#define For(i,a,b) for (int i=a;i<b;i++)
#define Ford(i,a,b) for (int i=a;i>=b;i--)
#define smax(a,b) a=max(a,b)
#define smin(a,b) a=min(a,b)
#define SZ(a) ((ll)a.size())
#define ER(a) cout << #a << ' ' << a << endl
#define LB(a,n,x) (lower_bound(a,(a)+(n),x)-(a))
 
const ll M=2e5+5,LG=19,SM=2000+5,inf=1e9+1;
ll mod=1e9+7;
 
ll n;
ll a[M]; 
str z[2]={"Yes","No"};
void ret(ll x)
{
    cout << z[x];
    exit(0);
}

bool n1,n2,e1,e2;

int main()
{
	ios::sync_with_stdio(0);
    str t;
    cin >> t;
    for (char c:t)
    {
        if (c=='N') n1=1;
        if (c=='S') n2=1;
        if (c=='E') e1=1;
        if (c=='W') e2=1;    
    }
    ret((n1^n2)||(e1^e2));
}

Measured memory_bytes: 256
#include <cstdio>
#define ll long long
const int maxn=100000*2+100;
ll n,m,i,xx[maxn],yy[maxn],to[maxn],root,x,y,last[maxn],next[maxn],next1[maxn],last1[maxn],to1[maxn],ans[maxn],fa[maxn],v[maxn],z,dis[maxn],from[maxn];
using namespace std;
inline void read(ll &k)
{
    ll f=1;char c=getchar();k=0;
    while (c<'0'||c>'9')c=='-'&&(f=-1),c=getchar();
    while (c>='0'&&c<='9')k=k*10+c-'0',c=getchar();
    k*=f;
}
inline ll gf(ll now)
{
    return fa[now]==now?now:fa[now]=gf(fa[now]);
}
void dfs(ll now)
{
    v[now]=1;
    for(ll cur=last[now];cur;cur=next[cur])
    {
        if (!v[to[cur]])
        {
        	from[to[cur]]=from[now]+dis[cur];
            dfs(to[cur]);
            fa[to[cur]]=now;
        }
    }
    for (ll cur=last1[now];cur;cur=next1[cur])
    if (v[to1[cur]])ans[(cur+1)>>1]=gf(to1[cur]);
}
int main()
{
    read(n);
    for (i=1;i<n;i++)
    {
        read(x);read(y);read(z);
        to[i*2-1]=y;
        dis[i*2-1]=z;
        next[i*2-1]=last[x];
        last[x]=i*2-1;
        to[i*2]=x;
        dis[i*2]=z;
        next[i*2]=last[y];
        last[y]=i*2;
    }
    read(m);read(root);
    for (i=1;i<=m;i++)
    {
        read(x);read(y);
        xx[i]=x;yy[i]=y;
        to1[i*2-1]=y;
        next1[i*2-1]=last1[x];
        last1[x]=i*2-1;
        to1[i*2]=x;
        next1[i*2]=last1[y];
        last1[y]=i*2;
    }
    for (i=1;i<=n;i++)fa[i]=i;
    dfs(root);
    for (i=1;i<=m;i++)
    printf("%lld\n",from[xx[i]]+from[yy[i]]);
}

Measured memory_bytes: 29568
from math import factorial
import copy
N = int(input())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
Mp = copy.copy(P)
Mq = copy.copy(Q)
Lp = 0
Lq = 0
for i in range(N):
  if P[i] == min(Mp) and i != N:
    Mp.remove(P[i])
  else:
    Lp += factorial(len(Mp)-1)*(sum(x<P[i] for x in Mp))
    Mp.remove(P[i]) 
  if Q[i] == min(Mq) and i != N:
    Mq.remove(Q[i])
  else:
    Lq += factorial(len(Mq)-1)*(sum(x<Q[i] for x in Mq))
    Mq.remove(Q[i])
print(abs(Lp-Lq))

Measured memory_bytes: 3444
package main

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

const (
	defaultBufferSize = 1024
	maxBufferSize     = 1e6
	Mod               = 1e9 + 7
)

var sc = bufio.NewScanner(os.Stdin)

// sc.Buffer(make([]byte, defaultBufferSize), maxBufferSize)

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

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

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

func readfloat64() float64 {
	sc.Scan()
	f, err := strconv.ParseFloat(sc.Text(), 64)
	if err != nil {
		panic(err)
	}
	return f
}

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

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 gcd(x, y int) int {
	if y == 0 {
		return x
	}
	return gcd(y, x%y)
}

func ModComb(n, k int) int {
	if k == 0 {
		return 1
	}
	x, y := n, k
	for i := 1; i < k; i++ {
		x = x * (n - i) % Mod
		y = y * (k - i) % Mod
	}
	inv := ModInv(y)
	return x * inv % Mod
}

func ModFact(x int) int {
	fact := 1
	for i := 1; i <= x; i++ {
		fact = fact * i % Mod
	}
	return fact
}

func ModInv(x int) int {
	return ModPow(x, Mod-2)
}

func ModPow(a, n int) int {
	res := 1
	for n > 0 {
		if n%2 != 0 {
			res = res * a % Mod
		}
		a = a * a % Mod
		n /= 2
	}
	return res
}

func pow(a, n int) int {
	if n == 0 {
		return 1
	}

	ans := 0
	if n%2 == 0 {
		ans = pow(a*a, n/2)
	} else {
		ans = a * pow(a*a, (n-1)/2)
	}
	return ans
}

func intSliceReverse(slice []int) []int {
	for i, j := 0, len(slice)-1; i < j; i, j = i+1, j-1 {
		slice[i], slice[j] = slice[j], slice[i]
	}
	return slice
}

func stringReverse(str string) string {
	runes := []rune(str)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}

func primeFactorization(x int) int {
	result := make(map[int]int, 0)
	for i := 2; i*i <= x; i++ {
		for x%i == 0 {
			result[i]++
			result[x]++
			x /= i
		}
	}
	if x != 1 {
		result[x]++
		x = 1
	}
	result[x]++
	fmt.Println(result)
	return len(result)
}

func isPrime(x int) bool {
	if x == 1 {
		return false
	}
	for i := 2; i*i <= x; i++ {
		if i == x {
			continue
		}
		if x%i == 0 {
			return false
		}
	}
	return true
}

func main() {
	sc.Split(bufio.ScanWords)
	n := readInt()
	primes := make([]int, n+1)
	for k := 1; k <= n; k++ {
		for i := k; i <= n; i += k {
			primes[i]++
		}
	}

	ans := 0
	for i, v := range primes {
		ans += i * v
	}
	fmt.Println(ans)
}


Measured memory_bytes: 82488
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int INF=1e9;

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


Measured memory_bytes: 256
from collections import deque

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

    p.sort()

    q = deque(p)

    ans = 0
    for _ in range(K):
        ans += q.popleft()

    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 9576
#include <bits/stdc++.h>
using namespace std;
#define __ <<" "<<
#define ___ <<" "
#define bash push_back
#define ALL(x) x.begin(),x.end()
//#define int long long

struct IoSetup {
    IoSetup() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout <<fixed<<setprecision(12);
        cerr <<fixed<<setprecision(12);
    }
}IoSetup;

typedef long long ll;
typedef pair < int , int >  pii;
static constexpr const signed int INF = 0x3f3f3f3f;
static constexpr const signed long long LINF = 0x3f3f3f3f3f3f3f3fLL;
static constexpr const signed int SMOD = 1000000007;
static constexpr const signed int dx[]={1,0,-1,0,1,1,-1,-1};
static constexpr const signed int dy[]={0,-1,0,1,-1,1,-1,1};

bool inside(int x,int y,int w,int h){return (x>=0 && y>=0 && x<w && y<h);}
template<class T>T abs(T &x){return x<0 ? -x : x;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}


signed main() {


    int r;
    cin >> r;
    cout << r*r << endl;

  
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)

using lint = long long;
using plint = pair<double, lint>;

int N;
lint L;

array<plint, 500000> deq;
int s = 0;
int t = -1;

double Qsum = 0;
lint Vnow = 0;

void trim()
{
    while (Vnow > L)
    {
        lint nuku = min(Vnow - L, deq[s].second);
        deq[s].second -= nuku;
        Vnow -= nuku;
        Qsum -= nuku * deq[s].first;
        if (deq[s].second == 0) s++;
    }
}

void add(double tadd, lint vadd)
{
    if (deq[t].first < tadd) // 追加するほうが高温の場合、先頭から余剰分を抜いていく
    {
        t++; deq[t] = plint(tadd, vadd);
        Qsum += tadd * vadd;
        Vnow += vadd;
        trim();
    }
    else // 低温の場合、うしろとくっつけていく
    {
        if (deq[t].second + vadd >= L)
        {
            Qsum = deq[t].first * (L - vadd) + tadd * vadd;
            Vnow = L;
            s = 0, t = -1;
            t++; deq[t] = plint(Qsum / L, L);
        }
        else
        {
            double Qaddnew = deq[t].first * deq[t].second + tadd * vadd;
            lint vaddnew = deq[t].second + vadd;
            Qsum -= deq[t].first * deq[t].second;
            Vnow -= deq[t].second;
            t--;
            add(Qaddnew / vaddnew, vaddnew);
        }
    }
}

array<double, 500000> res;

int main()
{
    cin.tie(0); ios::sync_with_stdio(0);
    cin >> N >> L;
    REP(i, N)
    {
        double tmp;
        lint v;
        cin >> tmp >> v;

        if (i == 0)
        {
            t++; deq[t] = plint(tmp, v);
            Qsum = tmp * v;
            Vnow = v;
        }
        else add(tmp, v);

        res[i] = Qsum / L;
    }
    REP(i, N) cout << setprecision(12) << res[i] << endl;
}


Measured memory_bytes: 18816
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <math.h>
using namespace std;

const int MAXN = 2000 + 10;
long long N, X, A[MAXN][MAXN], ans;

int main() {
	register int i, j;
	scanf("%lld%lld", &N, &X);
	for(i = 0; i < N; ++i)
		scanf("%lld", A[0] + i), ans += A[0][i];
	for(i = 1; i < N; ++i) {
		long long S = i * X;
		for(j = 0; j < N; ++j, S += A[i][j % N])
			A[i][(j + 1) % N] = min(A[i - 1][(j + 1) % N], A[i - 1][j]);
		ans = min(ans, S);
	}
	printf("%lld\n", ans);
	return 0;
}

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

namespace AtCoder
{
	class Program
	{
		static void Main(string[] args)
		{
			var Instance = new Question();
			Instance.Exec();
		}
	}

	public class Question
	{
		void swap(ref long x, ref long y)
		{
			long temp = y;
			y = x;
			x = temp;
		}

		public void Exec()
		{
			var array = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
			long a = array[0];
			long b = array[1];
			long c = array[2];

			if (a > b) {
				swap(ref a, ref b);
			}

			if (b > c) {
				swap(ref b, ref c);
			}

			if (a > b) {
				swap(ref a, ref b);
			}

			Console.WriteLine($"{a} {b} {c}");
			Console.Out.Flush();
			Console.ReadKey();
		}
	}
}


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

int H,W;

int main(){
    
    while(1){
        cin>>H>>W;
        if(H==0 && W==0)break;
        
        for(int i=0;i<H;++i){
            for(int j=0;j<W;++j){
                if((i+j)%2 == 0)cout<<"#";
                else cout<<".";
            }
            cout<<endl;
        }
        cout<<endl;
    }
    
    return 0;
}


Measured memory_bytes: 3100
#include <stdio.h>

int main(void)
{
  char s[200001];
  int i;
  int flag = -1;
  int start = 0;
  int end = 0;
  
  scanf("%s", &s);
  
  i = 0;
  while(s[i] != '\0') {
    if(s[i] == 'A') {
      if(flag == -1) {
	start = i;
	flag = 1;
      }
    }
    if(s[i] == 'Z') {
      if(flag != -1) {
	end = i;
      }
    }
    i++;
  }

  printf("%d\n", end-start+1);

  return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
#define FOR(i,k,n) for(int i=(k);i<(n);++i)

int main(){
    ll N; cin >> N;
    int res = to_string(N).size();
    for(ll i=1;i*i<=N;i++){
        if(N%i==0){
            res=min(res,(int)to_string(N/i).size());
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
// Problem : F - Contrast
// Contest : AtCoder - AtCoder Beginner Contest 178
// URL : https://atcoder.jp/contests/abc178/tasks/abc178_f
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")

#include <bits/stdc++.h>
using namespace std;

/* DEBUGGING */
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define deb(x...)
#endif

/* MACROS */ 
typedef long long int ll;
 
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
 
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

typedef map<int,int> mii;

#define  ff          first
#define  ss          second
#define  pb          push_back
#define  IOS         ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define  lb          lower_bound
#define  ub          upper_bound
#define  all(x)      (x).begin(), (x).end()
#define  lcm(x, y)   ((x) * (y) / __gcd(x, y))
#define  ps(x,y)     fixed<<setprecision(y)<<x
#define  setbit(x)   __builtin_popcountll(x)
#define  rep(i,a,b)  for(int i=a ; i<b ; ++i)
#define  repr(i,a,b) for(int i=a ; i>=b ; --i)

/* CONSTANTS */ 
#define PI 3.141592653589793
const ll MOD = 1e9 + 7;
const ll INF = 1000000000;
const ll MAX_N = 2e5 + 2;

// #define cerr if(false)cerr
/* CODE STARTS HERE */

void solve(){
    int n; cin >> n;
    
    vi v1(n),v2(n);
    
    rep(i,0,n) cin >> v1[i];
    rep(i,0,n) cin >> v2[i];
    
    reverse(all(v2));
    
    int bk = n-1,ft = 0;
    
    rep(i,0,n){
        int curr = v1[i];
        bk = n-1,ft = 0;
        
        while(i<n && v1[i]==curr){
            if(v1[i]==v2[i]){
                if(bk>i && v1[i]!=v2[bk] && v2[i]!=v1[bk]) swap(v2[i],v2[bk]), bk--;
                else if(ft<i && v1[i]!=v2[ft] && v2[i]!=v1[ft]) swap(v2[i],v2[ft]), ft++;
                else{cout << "No"; return;}
            }
            
            i++;
        }
        
        i--;
    }
    
    cout << "Yes\n";
    for(auto x:v2) cout << x << " ";
}

int main(){
    IOS;
    solve();
}

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

int main() {
  int N, T, A; cin >> N >> T >> A;
  vector<tuple<double, int>> v(N);
  double temp = 0;
  double dif = 10000000;
  for (int i = 0; i < N; i++) {
    int H; cin >> H;
    temp = T - H * 0.006;
    dif = abs(A - temp);
    v.at(i) = tie(dif, i);
  }
  sort(v.begin(), v.end());
  cout << get<1>(v.at(0)) + 1 << endl;
}

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

#define FOR(i,l,r) for(int i = (l);i < (r);i++)
#define ALL(x) (x).begin(),(x).end()
template<typename T> bool chmax(T& a,const T& b){return a < b ? (a = b,true) : false;}
template<typename T> bool chmin(T& a,const T& b){return b < a ? (a = b,true) : false;}
typedef long long ll;

int N;

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

	cin >> N;
	vector<int> A(N);
	FOR(i,0,N){
		cin >> A [i];
	}
	sort(ALL(A),greater<int>());

	int i = 0;
	while(i + 1 < N && i + 1 < A [i + 1]) i++;
	int j = i;
	while(j < N && i < A [j]) j++;
	if((A [i] - i) % 2 == 0 || (j - i) % 2 == 0){
		cout << "First" << endl;
	}
	else{
		cout << "Second" << endl;
	}

	return 0;
}


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

int main() {
    int N, H;
    cin >> N >> H;
    vector<long long> A(N), B(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i] >> B[i];
    }
    sort(A.rbegin(), A.rend());
    sort(B.rbegin(), B.rend());
    long long cut = A[0];
    long long ans = 0;
    for (int i = 0; i < N && B[i] >= cut && H > 0; i++) {
        H -= B[i];
        ans++;
    }
    if (H > 0) ans += ((H + cut - 1) / cut);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
#pragma GCC optimize("Ofast")
  
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <string>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <unordered_set>
#include <list>
#include <tuple>
#include <iomanip>
#include <climits>
#include <cstdlib>
#include <cassert>
#include <numeric>
#include <cmath>
#include <bitset>
#include <random>
#include <regex>

using namespace std;
  
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define Fixed fixed << setprecision(14)
#define int int64_t
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9+7; 
constexpr int mod2 = 998244353;
constexpr int dy[] = {0,1,0,-1,1,-1,-1,1};
constexpr int dx[] = {1,0,-1,0,1,1,-1,-1};
 
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class A, class B> inline A updiv(const A a,const B b){ return (a + b - 1) / b; }
template <class A, class B> inline A gcd(const A a,const B b){ return b ? gcd(b,a % b) : a; }
template <class A, class B> inline A lcm(const A a,const B b){ return a / gcd(a,b) * b; }

template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >;
template <class T> using max_heap = priority_queue<T>;
template <class A,class B> using umap = unordered_map<A,B>;


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

    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    long double sum = 0;

    rep(i,n){
        cin >> a[i];
        sum += a[i];
    }

    int cnt = 0;
    rep(i,n){
        cnt += (4 * a[i] >= sum / m);
    }

    cout << (cnt >= m ? "Yes\n" : "No\n");

    return 0;
}

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2019/01/06  Problem: EDU_DP Q / Link: __CONTEST_URL__  ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----

segtree?

----解説ここまで---- */


template<typename Monoid>
struct SegmentTreeFastAry {
	using nd = typename Monoid::type;
	const int ARY_SIZE;
	vector<nd> node;
public:
	SegmentTreeFastAry(int n) : ARY_SIZE(n), node(2 * ARY_SIZE, Monoid::id()) {}
	inline void update(int i, const nd val) {
		i += ARY_SIZE; node[i] = Monoid::upd(node[i], val);
		while (i > 1) { i >>= 1;	node[i] = Monoid::op(node[i << 1], node[(i << 1) + 1]); }
	}
	inline nd query(int l, int r) {
		if (l >= r) return Monoid::id(); nd vl = Monoid::id(), vr = Monoid::id();
		for (l += ARY_SIZE, r += ARY_SIZE; l != r; l >>= 1, r >>= 1) {
			if (l & 1) vl = Monoid::op(vl, node[l++]); if (r & 1) vr = Monoid::op(node[--r], vr);
		}	return Monoid::op(vl, vr);
	}
	nd operator[](int i) { return node[i + ARY_SIZE]; }
	void debugShow() { for (int i = ARY_SIZE; i < ARY_SIZE << 1; ++i) cerr << node[i] << " "; cerr << "\n"; }
};

struct Monoid {
	using type = LL;
	static type id() { return 0; }
	static type op(const type&l, const type&r) {
		return max(l, r);
	}
	static type upd(const type&l, const type&r) {
		return max(l, r);
	}
};

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

	LL N; cin >> N;
	VL h(N), a(N);
	FOR(i, 0, N) {
		cin >> h[i];
	}
	FOR(i, 0, N) {
		cin >> a[i];
	}
	SegmentTreeFastAry<Monoid> seg(N + 1);
	FOR(i, 0, N) {
		LL Mx = seg.query(0, h[i]);
		DD(de(h[i], Mx));
		seg.update(h[i], Mx + a[i]);
	}

	LL  ans = seg.query(0, N + 1);
	
	
	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 6528
#![allow(unused_imports)]
#![allow(unused_macros)]
use itertools::Itertools;
use std::cmp::{max, min};
use std::collections::*;
use std::i64;
use std::io::{stdin, Read};
use std::usize;

trait ChMinMax {
    fn chmin(&mut self, other: Self);
    fn chmax(&mut self, other: Self);
}
impl<T> ChMinMax for T
where
    T: PartialOrd,
{
    fn chmin(&mut self, other: Self) {
        if *self > other {
            *self = other
        }
    }
    fn chmax(&mut self, other: Self) {
        if *self < other {
            *self = other
        }
    }
}

#[allow(unused_macros)]
macro_rules! parse {
    ($it: ident ) => {};
    ($it: ident, ) => {};
    ($it: ident, $var:ident : $t:tt $($r:tt)*) => {
        let $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
    ($it: ident, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
    ($it: ident, $var:ident $($r:tt)*) => {
        let $var = parse_val!($it, usize);
        parse!($it $($r)*);
    };
}

#[allow(unused_macros)]
macro_rules! parse_val {
    ($it: ident, [$t:tt; $len:expr]) => {
        (0..$len).map(|_| parse_val!($it, $t)).collect::<Vec<_>>();
    };
    ($it: ident, ($($t: tt),*)) => {
        ($(parse_val!($it, $t)),*)
    };
    ($it: ident, u1) => {
        $it.next().unwrap().parse::<usize>().unwrap() -1
    };
    ($it: ident, $t: ty) => {
        $it.next().unwrap().parse::<$t>().unwrap()
    };
}

fn solve(s: &str) {
    let mut it = s.split_whitespace();
    parse!(it, n: usize, s: [usize; 1 << n]);
    let mut s: BTreeSet<(usize, usize)> = s.into_iter().enumerate().map(|(i, x)| (x, i)).collect();
    let si = *s.iter().rev().next().unwrap();
    let mut fixed = vec![si.0];
    s.remove(&si);
    for i in 0..n {
        for j in 0..(1 << i) {
            if let Some(&si) = s.range(..(fixed[j], 0)).rev().next() {
                s.remove(&si);
                fixed.push(si.0);
            } else {
                println!("{}", "No");
                return;
            }
        }
    }
    assert_eq!(fixed.len(), 1 << n);
    assert_eq!(s.len(), 0);
    println!("{}", "Yes");
}

fn main() {
    let mut s = String::new();
    stdin().read_to_string(&mut s).unwrap();
    solve(&s);
}

#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn test_input() {
        let s = "
        ";
        solve(s);
    }
}


Measured memory_bytes: 16176