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

#define task "D"
#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i <= (r); ++i)
#define Rep(i, r, l) for (int i = (r); i >= (l); --i)
#define DB(X) { cerr << #X << " = " << (X) << '\n'; }
#define DB1(A, _) { cerr << #A << "[" << _ << "] = " << (A[_]) << '\n'; }
#define DB2(A, _, __) { cerr << #A << "[" << _ << "][" << __ << "] = " << (A[_][__]) << '\n'; }
#define DB3(A, _, __, ___) { cerr << #A << "[" << _ << "][" << __ << "][" << ___ << "] = " << (A[_][__][___]) << '\n'; }
#define PR(A, l, r) { cerr << '\n'; rep(_, l, r) DB1(A, _); cerr << '\n';}
#define SZ(x) ((int)(x).size())
#define pb push_back
#define pf push_front
#define F first
#define S second
#define by(x) [](const auto& a, const auto& b) { return a.x < b.x; } // sort(arr, arr + N, by(a));
#define next nextalscjaowjico
#define prev prevoua0wucckjsl
#define y1 y1kscj9u20cjeijc
#define left leftljascjljl
#define right rightsocjolkjl
#define y0 y0cqu3jioajc

using ll = long long;
using ld = long double;
using ull = unsigned long long;
using namespace std;
typedef pair<int,int> ii;
typedef pair<ii,int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vl;
string s;
int q;
int main()
{
#ifdef ONLINE_JUDGE
    ios_base::sync_with_stdio(false);cin.tie(nullptr);
#else
   // freopen(task".in","r",stdin);
    //freopen(task".out","w",stdout);
#endif
    cin >> s >> q;
    bool rev = 0;
    deque<char> d;
    rep(i, 0, SZ(s) - 1) d.pb(s[i]);
    while (q--)
    {
        int t;
        cin >> t;
        if (t == 1) rev ^= 1;
        else
        {
            int f;
            char c;
            cin >> f >> c;
            if (f == 1)
            {
                if (rev) d.pb(c);
                else d.pf(c);
            } else
            {
                if (rev) d.pf(c);
                else d.pb(c);
            }
        }
    }
    if (!rev) rep(i, 0, SZ(d) - 1) cout << d[i];
    else Rep(i, SZ(d) - 1, 0) cout << d[i];
    return 0;
}


Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
void dfs(int root,vector<int> adj[],vector<int> &dp,vector<bool> &vis)
{
	vis[root]=true;
	for(auto it:adj[root])
	{
		if(vis[it]==false)
		{
			dfs(it,adj,dp,vis);
		}
		dp[root]=max(dp[root],1+dp[it]);
	}
}
int main()
{
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	int N,M;
	cin>>N>>M;
	vector<int> adj[N+1];
	while(M--)
	{
		int x,y;
		cin>>x>>y;
		adj[x].push_back(y);
	}
	vector <int>  dp(N+1,0);
	vector <bool> vis(N+1,false);
	for(int i=1;i<=N;i++)
	{
		if(vis[i]==false)
		{
			dfs(i,adj,dp,vis);
		}
	}
	int ans=INT_MIN;
	for(int i=0;i<=N;i++)
	{
		ans=max(dp[i],ans);
	}
	cout<<ans;
}

Measured memory_bytes: 9472
from math import sqrt


def main():
    n = int(input())

    mn = float("inf")
    for i in range(1, int(sqrt(n)) + 1):
        q, r = divmod(n, i)
        if r == 0:
            mn = min(mn, i + q - 2)

    print(mn)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()

def bisection(l,r,f,left=True,discrete=True):
    eps=1 if discrete else 10**-12
    if((not left)^f(r)): return r if left else r+1
    elif(left^f(l)): return l-1 if left else l
    while(r-l>eps):
        h=(l+r)//2 if discrete else (l+r)/2
        if((not left)^f(h)): l=h
        else: r=h
    return (l+r)/2 if not discrete else l if left else r

from math import ceil

def resolve():
    n,a,b=map(int,input().split())
    a=a-b
    H=[int(input()) for _ in range(n)]

    def check(x):
        cnt=0
        for i in range(n):
            cnt+=ceil(max(0,H[i]-b*x)/a)
        return cnt<=x

    print(bisection(0,max(H),check,left=False))
resolve()

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

#define M 1046527
#define L 14

char H[M][L]; /* Hash Table */

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;
}

/* convert a string into an integer value */
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;
}

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;
}



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

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

    ll a[n];
    ll ans[n];
    for(int i = 0; i < n; i++){
        cin >> a[i];
        a[i] *= 2;
        ans[i] = 0;
    }

    int flag = 0;
    ll now = a[0];
    for(int i = 1; i < n; i++){
        if(flag == 0){
            flag = 1;
            now -= a[i];
        }else{
            flag = 0;
            now += a[i];
        }
    }

    ans[0] = now / 2;
    for(int i = 1; i < n; i++){
        ans[i] = a[i - 1] - ans[i - 1];
    }

    for(int i = 0; i < n; i++){
        if(i != n - 1){
            cout << ans[i] << " ";
        }else{
            cout << ans[i] << endl;
        }
    }
}

Measured memory_bytes: 2944
from bisect import bisect_left
 
n = int(input())
l = sorted(list(map(int,input().split())))

ans = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        k = bisect_left(l,l[i]+l[j])
        ans += k - j - 1

print(ans)

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

#define ll long long

void swap (int *x, int *y) {
  int temp;

  temp = *x;
  *x = *y;
  *y = temp;

  return;
}


int gcd(int a, int b){
  int c;

  while (b > 0){
    c = a % b;
    a = b;
    b = c;
  }

  return a;
}

int upll(const void*a, const void*b){
  return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;
}

int downll(const void*a, const void*b){
  return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;
}

void sortup(ll*a,int n){
  qsort(a,n,sizeof(ll),upll);
}

void sortdown(ll*a,int n){
  qsort(a,n,sizeof(ll),downll);
}

long int modpow(long int a,long int n,long int mod){
  long int ans=1;
  while(n>0){
    if(n & 1){
      ans=ans*a%mod;
    }
    a=a*a%mod;
    n/=2;
  }
  return ans;
}

long int modinv(long int a,long int mod){
  return modpow(a,mod-2,mod);
}

int max(int a,int b){
  if(a<b){
    return b;
  }
  else{
    return a;
  }
}

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

void chmax(int *a,int b){
  if(*a < b){
    *a = b;
  }

  return;
}

void chmin(int *a,int b){
  if(*a > b){
    *a =b;
  }

  return;
}

/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/

int main(void){
  int x,y,z;
  scanf("%d%d%d",&x,&y,&z);

  x-=z;

  printf("%d\n",x/(y+z));

  return 0;
}

Measured memory_bytes: 1712
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#define debug(x) cerr << #x << ':' << x << endl
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define ALL(c) (c).begin(), (c).end()
using namespace std;
typedef long long ll;

int main(){
    int n;
    cin >> n;
    int allmity=0;
    set<int> colors;
    rep(i,n){
        int tmp;
        cin >> tmp;
        if(tmp<400) colors.insert(1);
        else if (tmp<800) colors.insert(2);
        else if (tmp<1200) colors.insert(3);
        else if (tmp<1600) colors.insert(4);
        else if (tmp<2000) colors.insert(5);
        else if (tmp<2400) colors.insert(6);
        else if (tmp<2800) colors.insert(7);
        else if (tmp<3200) colors.insert(8);
        else allmity++;
    }

    int mi, ma; 
    if(colors.size()==0){
        mi = 1;
        ma = min(allmity, 8);
    }
    else{
        mi = colors.size();
        ma = int(colors.size())+allmity;
    }
    cout << mi << " " << ma << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
void solve_B() {
	int N;
	std::cin >> N;

	long long int sum = 0;
	for (int i = 1; i <= N; i++) {
		if (i % 3 != 0 && i % 5 != 0 && i % 15 != 0) {
			sum += i;
		}
	}
	std::cout << sum;
}

int main()
{

	//solve_A();
	solve_B();
    return 0;
}

Measured memory_bytes: 3616
nmc = list(map(int,input().split()))
b = list(map(int,input().split()))
cnt = 0
for i in range(nmc[0]):
    a = list(map(int,input().split()))
    #print(a)
    t = 0
    for j in range(len(a)):
        t += a[j]*b[j]        
    #print(t)
    if t + nmc[2] >0:
        cnt += 1
print(cnt)

Measured memory_bytes: 3064
#include<stdio.h>
#include<algorithm>
using namespace std;
int n,b[100],a[100]={999999},sum;
main()
{
  scanf("%d",&n);for(register int i=0;i<n-1;++i)scanf("%d",b+i);
  for(register int i=0;i<n-1;++i)
  {
    a[i]=min(a[i],b[i]);
    a[i+1]=b[i];
  }
  for(register int i=0;i<n;++i)sum+=a[i];
  printf("%d\n",sum);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
 
int main()
{
    int n;
    std::cin >> n;
    std::map<int,int> v[2];
    for (int i = 0; i < n; i+=2) {
        int o,e;
        std::cin >> o >> e;
        v[0][o]++;
        v[1][e]++;
    }
 
    int key[2][2] = {};
    int val[2][2] = {};

    for (auto x : v[0]) {
        if (x.second > val[0][0]) {
            key[0][1] = key[0][0];
            val[0][1] = val[0][0];
            key[0][0] = x.first;
            val[0][0] = x.second;
        } else if (x.second > val[0][1]) {
            key[0][1] = x.first;
            val[0][1] = x.second;
        }
    }
    for (auto x : v[1]) {
        if (x.second > val[1][0]) {
            key[1][1] = key[1][0];
            val[1][1] = val[1][0];
            key[1][0] = x.first;
            val[1][0] = x.second;
        } else if (x.second > val[1][1]) {
            key[1][1] = x.first;
            val[1][1] = x.second;
        }
    }

    if (key[0][0] != key[1][0]) {
        std::cout << n - val[0][0] - val[1][0] << std::endl;
        return 0;
    }
 
    std::cout << n - std::max(val[0][0]+val[1][1], val[1][0]+val[0][1]) << std::endl;
 
    return 0;
}


Measured memory_bytes: 4992
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            // 解答はココに書く
            var N = cin.ReadInt;
            var M = cin.ReadInt;
            var loadNumberList = Enumerable.Range(1, N).ToArray();
            int[] allLoadList = new int[M *2];
            
            for (int i = 0; i < M*2 ; i++){
                allLoadList[i] = cin.ReadInt;
            }

            for(int j = 0 ; j<N; j++){
                var ans = allLoadList.Where(value => value ==loadNumberList[j]).Count();
                WriteLine(ans);
            }
            
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); }}
        public int ReadInt { get { return int.Parse(Read); }}
        public long ReadLong { get { return long.Parse(Read); }}
        public double ReadDouble { get { return double.Parse(Read); }}
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret;}
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret;}
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret;}
    }
}

Measured memory_bytes: 13524
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#include<map>

#define INF 1000000007
#define LINF 1000000000000000007

using namespace std;

typedef long long Int;
typedef pair<Int, Int> P;

Int gcd(Int x, Int y){
	if(y == 0)
		return x;
	return gcd(y, x % y);
}

Int lcm(Int x, Int y){
	return x * y / gcd(x, y);
}

bool sosuu(int x){
	bool b = 1;
	if(x == 1) b = 0;
	for(int i = 2; i * i <= x; i++){
		if(x % i == 0) {
			b = 0;
			break;
		}
	}
	return b;
}

int n;

int main(){
	cin >> n;
	Int ans = 1;
	for(int i = 2; i <= n; i++){
		bool b = sosuu(i);
		if(b){
			Int a = 0;
			for(int j = n; j > 0; j /= i){
				a += j / i;
			}
			ans *= (a + 1);
			ans %= INF;
		}
	}
	cout << ans << endl;
	
	return 0;
}

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

using namespace std;

typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = (ll)1e9 + 7;

int cal(vector<int>& freqs, int color, vector<vector<int>>& D, int C)
{
  int ret = 0;
  for (int i = 1; i <= C; ++i) {
    ret += freqs[i] * D[i][color];
  }
  return ret;
}

int main()
{
  int N, C; scanf("%d %d", &N, &C);
  vector<vector<int>> D(C + 5, vector<int>(C + 5, 0));
  vector<vector<int>> G(N + 5, vector<int>(N + 5, -1));
  for (int i = 1; i <= C; ++i) {
    for (int j = 1; j <= C; ++j) {
      scanf("%d", &D[i][j]);
    }
  }

  for (int i = 1; i <= N; ++i) {
    for (int j = 1; j <= N; ++j) {
      scanf("%d", &G[i][j]);
    }
  }

  vector<vector<int>> freqs(3, vector<int>(C + 1, 0));
  for (int i = 1; i <= N; ++i) {
    for (int j = 1; j <= N; ++j) {
      int m = (i + j) % 3;
      ++freqs[m][G[i][j]];
    }
  }
  int ans = INF;
  for (int i = 1; i <= C; ++i) {
    for (int j = 1; j <= C; ++j) {
      if (j == i) { continue; }
      for (int k = 1; k <= C; ++k) {
        if (k == i or k == j) { continue; }
        int cnt = cal(freqs[0], i, D, C) +
                  cal(freqs[1], j, D, C) +
                  cal(freqs[2], k, D, C);
        ans = min(ans, cnt);
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 1280
//Jai Bhole Ki
#include <bits/stdc++.h>
using namespace std;
#define fast int fvariable = []() { std::ios::sync_with_stdio(false); cin.tie(NULL); return 0; }();
#define ll long long
#define LL unsigned ll
#define pb push_back
#define pi pair<ll,ll>
#define debug(x) cout<<x<<"\n";
#define debug cout<<"debugged\n";
#define minval -2e9
#define maxval 2e9
long double PI =3.14159265358979323846;
 
const ll M=1e9+7;
const ll inf=1e18;
const ll ms=2e5+5;
fast;
ll ans;
double x;
void solve()
{
    cin>>x;
    while(x>100)
    {
        x/=1.01;
        x=ceil(x);
        ans++;
    }
    cout<<ans<<endl;
}
int main()
{
 // freopen("input.txt","r",stdin);
//  freopen("output.txt","w",stdout);
    //int t;cin>>t;while(t--)
    {
        solve();
    }
    return 0;
}

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

int main(){
    int m;
    cin >> m;
    cout << 48-m << endl;
    
    return 0;
}


Measured memory_bytes: 256
N,M=list(map(int, input().split()))
graph=[]
for i  in range(M):
  graph.append(list(map(int, input().split())))

dist=[[10000000 for i in range(N)] for j in range(N)]

#print(graph,dist)

for n in range(N):
  dist[n][n] = 0

for n in range(N):

  for time in range(N):
    judge = 0
    for m in range(M):
      if dist[n][graph[m][0]-1]-dist[n][graph[m][1]-1] > graph[m][2]:
        dist[n][graph[m][0]-1]=dist[n][graph[m][1]-1]+graph[m][2]
        judge=1
      elif dist[n][graph[m][1]-1]-dist[n][graph[m][0]-1] > graph[m][2]:
        dist[n][graph[m][1]-1]=dist[n][graph[m][0]-1]+graph[m][2]
        judge=1
    if judge == 0:
      break

num = 0

for m in range(M):
  if dist[graph[m][0]-1][graph[m][1]-1] < graph[m][2]:
    num+=1
    
#print(dist)
  
    
print(num)
      

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

int main(void){

    int n, m;
    cin >> n >> m;
    
    set<int> first;
    set<int> second;
    
    for(int i=0; i<m; i++) {
        int temp1, temp2;
        cin >> temp1 >> temp2;
        if(temp1 == 1) first.insert(temp2);
        if(temp2 == n) second.insert(temp1);
    }
    
    for(auto itr=first.begin(); itr!=first.end(); itr++) {
        if(second.find((*itr)) != second.end()) {
            cout << "POSSIBLE" << endl;
            return 0;
        }
    }

    cout << "IMPOSSIBLE" << endl;

    return 0;
}


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


int main()
{
  int n, W;
  cin >> n >> W;
  vector<int> w(n), v(n);
  rep(i, n)
    cin >> w[i] >> v[i];
  int vmx = 100001;
  vector<ll> dp(vmx, W + 1);
  dp[0] = 0;
  rep(i, n)
    for (int j = vmx; j >= v[i]; j--)
      if (dp[j-v[i]] != W + 1)
        dp[j] = min(dp[j], dp[j-v[i]] + w[i]);
  int i = vmx - 1;
  while (dp[i] > W)
    i--;
  cout << i << endl;
  return 0;
}

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

using namespace std;

int cnt[3];

main() {
    //freopen("input.txt", "r", stdin);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, x, ans = 0;
    cin >> n;
    vector < pair < int, int > > a;
    for (int i = 1; i <= n; ++i) {
        cin >> x;
        a.push_back({x, i});
    }
    sort(a.begin(), a.end());
    for (int i = 0; i < n; ++i) {
        //cout << (a[i].second - i - 1) << '\n';
        if (abs(a[i].second - i - 1) % 2 == 1) {
            cnt[a[i].second % 2]++;
        }
    }
    cout << max(cnt[0], cnt[1]) << '\n';
    return 0;
}



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

int main() {
  int N, l, r, x;
  x =0;
  cin >> N;
  for (int i =0; i < N; i++) {
	cin >> l >> r;
    x += r - l + 1;
  }
  cout << x << endl;
}


Measured memory_bytes: 256
// https://atcoder.jp/contests/abc126/tasks/abc125_a

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <tuple>
#include <vector>
using namespace std;

typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define INF (1e9)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
// int gcd(long a, long b) { return b ? gcd(b, a % b) : a; }
// int lcm(long a, long b) { return a * b / gcd(a, b); }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    string s;
    cin >> n >> k;
    cin >> s;
    char c = s[k - 1];
    s[k - 1] = c - ('A' - 'a');

    cout << s << endl;

    return 0;
}

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

using namespace std;

int main()
{
    int n,k,p=0;
    char s[100000];
    cin>>n>>k>>s;
    for(int i=0;i<n-1;i++)
    {
        if(s[i]==s[i+1])
            p++;
    }
    cout<<min(n-1,p+2*k);
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = (ll)(x)-1;0 <= i; i--)
#define reps(i,x) for(ll i = 1; i < (ll)(x)+1; i++)
#define rreps(i,x) for(ll i = (ll)(x); 1 <= i; i--)
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const int n_max = 1e5+10;
#define int ll

signed main(){
    ll w,h; cin >> w >> h;
    ll ans = 0;
    priority_queue<Pll, vector<Pll>, greater<Pll>> pq;
    rep(i,w){
        ll p; cin >> p;
        pq.emplace(p, 0);
    }
    rep(i,h){
        ll q; cin >> q;
        pq.emplace(q, 1);
    }
    h++;w++;
    while(!pq.empty()){
        auto p = pq.top();pq.pop();
        if(p.second == 0){
            ans += h * p.first;
            w--;
        }
        if(p.second == 1){
            ans += w * p.first;
            h--;
        }
    }
    cout << ans << endl;
}

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

const ll MOD = 1e9+7;

int main(void){
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  ll ans = 0, sum = 0;
  for(int i = 0; i < n-1; i++){
    sum += a[i];
    sum %= MOD;
    ans += sum * a[i+1];
    ans %= MOD;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4052
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int s=0;
	int m=n;
	int t;
	while(n)
	{
		t=n%10;
		s+=t;
		n/=10;
	}
	if(m%s==0)
	cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i=0;i<n;i++) cin >> a[i];
    long long ans=0;
    sort(a.begin(), a.end());
    for(int i=0;i<n;i++){
        ans+=a[i];
    }
    cout << a[0] << " " << a[n-1] << " " << ans << endl;
    return 0;
}


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

int n,k;
ll solve(vector<ll>x){
    ll ans=1LL<<60;
   rep(i,n-k+1){
      int j=i+k-1;
      ll l=abs(x[i])+abs(x[j]-x[i]);
      ll r=abs(x[j])+abs(x[j]-x[i]);
      chmin(ans,l);
      chmin(ans,r);
   }
   return ans;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    cin>>n>>k;
    vector<ll>x(n);
    rep(i,n)cin>>x[i];
    cout<<solve(x)<<endl;
    return 0;
}


Measured memory_bytes: 1792
/******************
 *AUTHOR: speckrel*
 ******************/

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

#define ll long long

//Function to read int array
void read(ll arr[], ll n){
    for(ll i=0;i<n;i++){
        cin>>arr[i];
    }
}

void solve(){
    static int i=1;
    //cout<<"This is a test code "<<i<<"\n";
    i++;
}

int main(){
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll k;
    cin>>k;
    ll ans = 1;
    ll rem = 7%k;
    while(rem){
        rem = (10*rem + 7)%k;
        ans++;
        if(ans>1000000){ans = -1;break;}
    }
    cout<<ans;
    return 0;
}



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

int main(){
    char c;
    int alf[26]={};
    while( cin >> c ){
        if(c>='a'&&c<='z')alf[c-'a']++;
        if(c>='A'&&c<='Z')alf[c-'A']++;
    }
    for(int i=0; i<26; ++i){
        cout<<char('a'+i)<<" : "<<alf[i]<<endl;
    }
}


Measured memory_bytes: 3092
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> Pll;
typedef pair<P,P> PP;
#define rep(i,a,n) for(int i = a;i < n;i++)
#define LINF (ll)1e17
#define INF 1e9
#define MOD 1e9+7
#define sMOD 1e5
#define fs first
#define sc second


signed main(){
	string s,t;
	cin >> s;
	
	int r,l;
	
	rep(i,0,s.size()-1){
		rep(j,i,s.size()-1){
			
			t = "";
			rep(k,0,s.size()){
				if(i <= k && k <= j) continue;
				t += s[k];
			}
			
			if(t == "keyence"){
				cout << "YES" << endl;
				return 0;
			}
			
		}
	}
	
	if(s == "keyence")cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cctype>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <stdio.h>
#include <string.h>
#include <cstdlib>
#include <math.h>
#include <bitset>
#include <iterator>
#include <iomanip>
#include <sstream>
#include <numeric>
#define INF 2000000000
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
long long gcd(long long a,long long b){if(a%b==0){return b;}else return gcd(b,a%b);}
long long lcm(long long a,long long b){if(a==0){return b;} return a/gcd(a,b)*b;}
long long MOD; template<class T> void mod(T &n){MOD=n;}
#define sym cout<<"---------"<<endl;
#define ll long long
#define PL pair<long long, long long>
#define P pair<int,int>
#define mk make_pair
#define en endl
#define WHITE 1
#define BLACK 2
#define GRAY 1
#define RE return 0
#define int ll

bool prime[1000005]={true};

signed main(){
  int n;
  while(cin>>n){
    if(n==1){cout<<0<<en; continue;}
    for(int i=2; i<=n; i++) prime[i]=true;
    int ans=0;
    for(int i=2; i<=n; i++){
      if(prime[i]) {
        ans++;
        for(int j=2*i; j<=n; j+=i) prime[j]=false;
      }
    }
    cout<<ans<<en;
  }
}





Measured memory_bytes: 4072
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define repr(e,x) for(auto& e:x)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

string s;
string ans;

int main(){
    cin>>s;

    rep(i,s.size()){
        if(s[i]!='B'){
            ans+=s[i];
        }else{
            if(ans.size()) ans.pop_back();
        }
    }

    cout<<ans<<endl;
}

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

using namespace std;

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define PB push_back
#define MP make_pair
#define ll long long

inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}

struct UnionFind {
    vector<int> par;
    UnionFind(int N) : par(N) { 
        for(int i = 0; i < N; i++) par[i] = i;
    }

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

    void unite(int x, int y) { 
        int rx = root(x); 
        int ry = root(y);
        if (rx == ry) return;
        par[rx] = ry;
    }

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

int main(){
    std::ios::sync_with_stdio(false);
    ll n, m;
    cin >> n >> m;
    UnionFind uf(m+1);
    ll k, tmp, prev = -1;
    ll need_bridge[m+1] = {};
    for(int i=0;i<n;++i)
    {
        cin >> k;
        prev = -1;
        for(int j=0;j<k;++j)
        {
            cin >> tmp;
            if(prev != -1)
            {
                uf.unite(prev, tmp);
            }
            need_bridge[tmp] = 1;
            prev = tmp;
        }
    }

    ll root = -1;
    bool ret = true;
    // for(int i=1;i<=m;++i)
    // {
    //     cerr << uf.root(i) << endl;
    // }
    for(int i=1;i<=m;++i)
    {
        if(need_bridge[i] == 1)
        {
            if(root == -1)
            {
                root = uf.root(i);
            }
            else
            {
                if(root != uf.root(i)) ret = false;
            }
            
        }
    }

    cout << (ret ? "YES" : "NO") << endl;
}


Measured memory_bytes: 1408
/*************************************************************************
	> File Name: 1.cpp
	> Author: ralph
	> Mail: 1694487365@qq.com
	> Created Time: 2018年12月22日 星期六 19时03分59秒
 ************************************************************************/

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b;
    while(cin>>a>>b) cout<<a+b<<endl;
}



Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
#ifdef ENABLE_DEBUG_OUTPUT
#define DEBUG_LOG(s) cout << s << endl;
#else
#define DEBUG_LOG(s) void();
#endif

class UnionFindTree {
private:
    vector<int> parent;
    vector<int> count;
public:
    UnionFindTree(int n) : parent(n), count(n, 1) {
        // 最初は全てを根として初期化
        for(int i = 0; i < n; i++) parent[i] = i;
    }

    int get_root(const int x) {
        // データxが属する木の根を取得する
        if (parent[x] == x) return x;
        // 取得したものは直接木の根をつなぐ(経路圧縮)
        return parent[x] = get_root(parent[x]);
    }

    void unite(const int x, const int y) {
        // xとyの木を併合する
        int rx = get_root(x);
        int ry = get_root(y);
        // 元から同じ木に属している場合は何もしない
        if (rx == ry) return;
        // xの属する木をyの属する木につける
        parent[rx] = ry;
        count[ry] += count[rx];
        count[rx] = 0;
    }

    bool is_same_root(const int x, const int y) {
        return get_root(x) == get_root(y);
    }

    int get_size(const int x) {
        return count[get_root(x)];
    }

    void print() {
        for(auto elm : parent) cout << elm << " ";
        cout << endl;
        for(auto elm : count) cout << elm << " ";
        cout << endl;
    }
};

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

    vector<pair<int, int>> x(n);
    vector<pair<int, int>> y(n);
    for (auto i = 0; i < n; i++) {
        int a, b; cin >> a >> b;
        x[i] = {a, i}; y[i] = {b, i};
    }
    sort(x.begin(), x.end());
    sort(y.begin(), y.end());

    UnionFindTree tree(n);
    map<int64_t, vector<pair<int, int>>> g;
    for (auto i = 0; i < n - 1; i++) {
        int64_t cost = abs(x[i].first - x[i + 1].first);
        g[cost].emplace_back(x[i].second, x[i + 1].second);
        cost = abs(y[i].first - y[i + 1].first);
        g[cost].emplace_back(y[i].second, y[i + 1].second);
    }

    int64_t ans = 0;
    for (auto &a : g) {
        for (auto &b : a.second) {
            if (not tree.is_same_root(b.first, b.second)) {
                tree.unite(b.first, b.second);
                ans += a.first;
            }
        }
    }

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

Measured memory_bytes: 8064
#include <iostream>
#include <math.h>
#include <algorithm>
#include <queue>
#include <map>
#include <list>
//#include <bits/stdc++.h>


using namespace std;

#define FOR(i,a,b) for(int i=(a),i##formax=(b);i<i##formax;i++)
typedef long long ll;

int main(){
    ll N, K;
    cin >> N >> K;
    ll mod = N % K;
    if(mod > K - mod){
        mod = K - mod;
    }
    cout << mod << endl;
    return 0;
}

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

#define REP(i, x) REPI(i, 0, x)
#define REPI(i, a, b) for (int i = int(a); i < int(b); ++i)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
using namespace std;

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

  int N, M;
  int wa = 0;
  int ac = 0;
  map<int, bool> aced;

  cin >> N >> M;
  vector<int> waed(N + 1, 0);
  REPI(i, 1, N + 1) { aced.insert(make_pair(i, false)); }

  int p;
  string s;
  REP(i, M) {
    cin >> p >> s;
    if (!aced.at(p)) {
      if (s == "WA") {
        ++waed.at(p);
      }

      if (s == "AC") {
        ++ac;
        wa += waed.at(p);
        aced.at(p) = true;
      }
    }
  }

  cout << ac << " " << wa << endl;

  return 0;
}

Measured memory_bytes: 5376
N = int(input())
A = [0]*N
x = [0]*N
y = [0]*N
for _ in range(N):
    a = int(input())
    A[_] = a
    x[_] = [0]*a
    y[_] = [0]*a
    for __ in range(a):
        x[_][__],y[_][__] = map(int,input().split())
        x[_][__] -= 1

def bi(x):
    i = 0
    o = [0]*N
    while x > 0:
        o[i] = x % 2
        x //= 2
        i += 1
    return o

def b(o):
    for i in range(N):
        # 不親切な人間の証言は真偽不明なので無視する
        if o[i] == 0:
            continue
        # 正直者の証言は矛盾がなければ確実に正しい
        for j in range(A[i]):
            k = x[i][j]
            if o[k] != y[i][j]:
                return -1
    return sum(o)

a = 0
for i in range(2 ** N):
    # 2**N通りのそれぞれについて矛盾がないか確かめる
    o = bi(i)
    a = max(a,b(o))

print(a)

Measured memory_bytes: 44508
#include<iostream>
#include<vector>
using namespace std;
using P = pair<int,int>;

int main(){
	int X,N;
	cin >> X >> N;
	vector<int> d(102);
	for(int i=0;i < N;i++){
		int p;
		cin >> p;
		d[p] = 1;
	}

	P ans(99999,-1);
	for(int i=0;i <= 101;i++){
		if(d[i] == 1) continue;
		int dif;
		dif = abs(X - i);
		ans = min(ans,P(dif,i));
	}
	cout << ans.second << endl;
}


Measured memory_bytes: 3164
import java.util.*;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		int x=sc.nextInt();
		int t=sc.nextInt();
		if(x>t){
			System.out.println(x-t);
		}else{
			System.out.println(0);
		}
  }
}


Measured memory_bytes: 22612
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//clock_t start=clock();clock_t end=clock();cout<<(double)(end-start)/CLOCKS_PER_SEC<<endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
typedef pair<double,double> pdd;
typedef vector<vector<ll>> mat;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll mod5=1000000009;
ll inf=1LL<<60;
double pi=3.141592653589793238462643383279L;
double eps=1e-14;
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
#define srep(itr,st) for(auto itr=st.begin();itr!=st.end();itr++)
#define mrep(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define Max(a,b) a=max(a,b)
#define Min(a,b) a=min(a,b)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
ll beki(ll n,ll k,ll md){
  ll ret=1;
  ll now=n;
  while(k>0){
    if(k%2==1){
      ret*=now;
      ret%=md;
    }
    now*=now;
    now%=md;
    k/=2;
  }
  return ret;
}
ll gyaku(ll n,ll md){
  return beki(n,md-2,md);
}
ll popcount(ll n){
    ll ret=0;
    ll u=n;
    while(u>0){
        ret+=u%2;
        u/=2;
        
    }
    return ret;
}

int main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int h,w;cin>>h>>w;
    int n;cin>>n;
    int a[n];rep(i,0,n)cin>>a[i];
    int ans[h][w];
    int nh=0,nw=0;
    int now=0;
    for(;;){
        if(nh==h)break;
        if(a[now]==0){
            now++;
        }
        else{
            ans[nh][nw]=now+1;
            a[now]--;
            if(nh%2==0){
                nw++;
                if(nw==w){
                    nw--;
                    nh++;
                }
            }
            else{
                nw--;
                if(nw==-1){
                    nw++;
                    nh++;
                }
            }
        }
    }
    rep(i,0,h){
        rep(j,0,w)cout<<ans[i][j]<<" ";
        cout<<endl;
    }
}


Measured memory_bytes: 384
#include <cstdio>
using namespace std;

int a[2001];
int minimize(int a[], int z, int w, int k, int n);

int abs(int z, int w) {
	if (z > w) {
		return z - w;
	}
	else {
		return w - z;
	}
}

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

int min(int a, int b) {
	if (a > b) {
		return b;
	}
	else {
		return a;
	}
}

int maximize(int a[], int z, int w, int k, int n) {
	if (k == n) {
		return abs(a[n], w);
	}
	else {
		int m = abs(a[n],w);
		for (int i = k; i < n; i++) {
			m = max(m, minimize(a, a[i], w, i + 1, n));
		}
		return m;
	}
}

int minimize(int a[], int z, int w, int k, int n) {
	if (k == n) {
		return abs(z, a[n]);
	}
	else {
		int m = abs(z, a[n]);
		for (int i = k; i < n; i++) {
			m = min(m, maximize(a, z, a[i], i + 1, n));
		}
		return m;
	}
}

int main() {
	int n,z,w,i,j;
	scanf("%d %d %d", &n, &z, &w);
	for (i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
	}
	j = maximize(a, z, w, max(1,n-2), n);
	printf("%d", j);
	return 0;
}

Measured memory_bytes: 128
package main

import "fmt"

var n, m, q, ans int
var a, b, c, d []int

func calc(nums []int) int {
	ret := 0
	for i := 0; i < q; i++ {
		if nums[b[i]]-nums[a[i]] == c[i] {
			ret += d[i]
		}
	}
	return ret
}

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

func dfs(a []int, step int) {
	if step == n {
		// fmt.Println("a", a, "score", calc(a))
		ans = max(ans, calc(a))
		return
	}
	var s int
	if step == 0 {
		s = 1
	} else {
		s = a[len(a)-1]
	}
	for i := s; i <= m; i++ {
		dfs(append(a, i), step+1)
	}
}

func main() {
	fmt.Scan(&n, &m, &q)
	a = make([]int, q)
	b = make([]int, q)
	c = make([]int, q)
	d = make([]int, q)
	for i := 0; i < q; i++ {
		fmt.Scan(&a[i], &b[i], &c[i], &d[i])
		a[i]--
		b[i]--
	}
	dfs([]int{}, 0)
	fmt.Println(ans)
}


Measured memory_bytes: 5976
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef vector<pair<ll,ll>> vp;
#define rep(i,n) for(ll i = 0; i < ll(n); i++)
#define MMOD(i) ((i%MOD)+MOD)%MOD;
#define all(v) v.begin() , v.end()
#define vec(i,j) vector<vector<ll>>(i,vector<ll>(j,0))
const ll INF=99999999999999;
const ll MOD=1000000007;
const ll MAX_N=100010;
ll a,b,c,d,e,f,x,y,z,k,m,n,l,q,h,w,t,ans=0;
vl v,v1,v2;
vp p;
string s;
priority_queue<ll> q1;
priority_queue<ll,vector<ll>,greater<ll>> q2;
ll solve(){
   if(w==x*2&&h==y*2)return 1;
 
   return 0;
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin>>w>>h>>x>>y;
    cout<<float(w)*float(h)/2<<" "<<solve()<<endl;
}

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

using namespace std;

#define ll long long

//iostream::sync_with_stdio(false);

int main()
{
    int sum = 0;
    string s1, s2;
    cin >> s1;
    cin >> s2;
    for(int i = 0; i < s1.size(); i++)
    {
        if(s1[i] != s2[i])sum++;
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 3924
x = gets.chomp.to_i

if x >= 400 && x <= 599
  puts "8"
elsif x >= 600  && x <= 799
  puts "7"
elsif x >= 800  && x <= 999
  puts "6"
elsif x >= 1000  && x <= 1199
  puts "5"
elsif x >= 1200  && x <= 1399
  puts "4"
elsif x >= 1400  && x <= 1599
  puts "3"
elsif x >= 1600  && x <= 1799
  puts "2"
else
  puts "1"
end

Measured memory_bytes: 14388
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
constexpr int INF = 0x3f3f3f3f;
constexpr ll LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr double EPS = 1e-8;
constexpr int MOD = 1000000007;
// constexpr int MOD = 998244353;
constexpr int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
constexpr int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

int main() {
  int n; cin >> n;
  vector<int> a(n), b(n);
  REP(i, n) cin >> a[i];
  REP(i, n) cin >> b[i];
  int k = 0;
  set<int> st;
  REP(i, n) st.emplace(i);
  auto era = [&](int l, int r) {
    for (auto it = st.lower_bound(l); it != st.end() && *it <= r; it = st.erase(it));
  };
  for (int i = 0; i < n;) {
    int j = i + 1;
    while (j < n && a[i] == a[j]) ++j;
    while (k < n && b[k] < a[i]) ++k;
    while (k < n && b[k] == a[i]) {
      if (k < i) {
        era(k + n - j + 1, n - (i - k));
      } else if (i <= k && k < j) {
        era(0, k - i);
        era(k + n - j + 1, n - 1);
      } else {
        era(k - j + 1, k - i);
      }
      ++k;
    }
    i = j;
  }
  if (st.empty()) {
    cout << "No\n";
  } else {
    cout << "Yes\n";
    rotate(b.begin(), b.begin() + *st.begin(), b.end());
    REP(i, n) cout << b[i] << " \n"[i + 1 == n];
  }
  return 0;
}


Measured memory_bytes: 14296
#include<bits/stdc++.h>
#define prArr(Arr,n) for(int _=0;_<n;_++)   cout<<(Arr)[_]<<" ";
using namespace std;
const int INF=(int)1e9+10;
const int MOD=998244353;
long long diff[200005],id[200005],iDone[200005];
vector<vector<int>> adj(200005);
vector<int> euler;
void dfs(int,int);
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n,q,a,b,p,x;
    cin>>n>>q;
    for(int i=1;i<n&&cin>>a>>b;i++)
        adj[a].push_back(b),
        adj[b].push_back(a);
    dfs(1,0);
    for(int i=0;i<q&&cin>>p>>x;i++)
        diff[id[p]]+=x,
        diff[iDone[p]]-=x;
    for(int i=1;i<=200000;i++)
        diff[i]+=diff[i-1];
    for(int i=1;i<=n;i++)
        cout<<diff[id[i]]<<" ";
    return 0;
}

void dfs(int u,int last)
{
    id[u]=euler.size();
    euler.push_back(u);
    for(auto v:adj[u])
        if(v!=last)
            dfs(v,u);
    iDone[u]=euler.size();
    return;
}


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

using namespace std;

typedef long long ll;

const int NMAX = 105;

int n, W;
ll  w[NMAX], v[NMAX], dp[100005][NMAX];

int main(){
    //freopen("KNAPSACK1.INP", "r", stdin);

    cin >> n >> W;
    for (int i = 1; i <= n; i++){
        cin >> w[i] >> v[i];
    }
    for (int m = 1; m <= W; m++){
        for (int i = 1; i <= n; i++){
            if (m < w[i]){
                dp[m][i] = dp[m][i - 1];
            }
            else {
                dp[m][i] = max(dp[m][i - 1], dp[m - w[i]][i - 1] + v[i]);
            }
        }
    }
    cout << dp[W][n];

    return 0;
}


Measured memory_bytes: 82304
#include<stdio.h>

int main(){
  int n,m;
  int a,b,c;
  scanf("%d", &n);
  a=n%10;
  b=(n/10)%10;
  c=(n/100)%10;
  if(c>b) m=c+10*c+100*c;
  else{
    if(c<b) m=c+1+10*(c+1)+100*(c+1);
    else{
      if(b>=a) m=b+10*b+100*b;
      else m=b+1+10*(b+1)+100*(b+1);
    }
  }
  printf("%d\n" ,m);

  return 0;
}


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

#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

using int64 = int64_t;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int h, n;
  cin >> h >> n;
  int mx = h + 10010;
  const int INF = (int)1e8;
  vector<vector<int>> dp(n + 1, vector<int>(mx, INF));
  dp[0][0] = 0;
  rep(i, n) {
    int a, b;
    cin >> a >> b;
    rep(j, mx) {
      if (j - a >= 0) {
        dp[i + 1][j] = min(dp[i][j], dp[i + 1][j - a] + b);
      } else {
        dp[i + 1][j] = dp[i][j];
      }
    }
  }
  int ans = INF;
  for (int i = h; i < mx; i++) {
    ans = min(ans, dp[n][i]);
  }
  cout << ans;
  return 0;
}

Measured memory_bytes: 81592
#include <cstdio>

using namespace std;

int main(){
    char op;
    int a, b;
    
    while(scanf("%d %c %d", &a, &op, &b), op != '?'){
        
        switch(op){
        case '+':
            printf("%d\n", a + b);
            break;
        
        case '-':
            printf("%d\n", a - b);
            break;
        
        case '*':
            printf("%d\n", a * b);
            break;
        
        case '/':
            printf("%d\n", a / b);
            break;
        }
    }
    
    return 0;
}

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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

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

  ll n;
  cin >> n;

  ll ans = 1;
  ll now = 1;
  while(now <= n){
    ans = now;
    now *= 2;
  }
  cout << ans << endl;

  
  
}


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

template <typename T>
class Board {
public:
	Board<T>() {};
	Board<T>(int h, int w) {
		_h = h;
		_w = w;
		_data.resize(h);
		for (int i = 0; i < _h; i++) {
			_data[i].resize(w);
		}
	}
	~Board() {
	}
	int GetH() const { return _h; };
	int GetW() const { return _w; };
	bool IsInvalid(int i, int j) const {
		return (i < 0 || _h <= i || j < 0 || _w <= j);
	};
	T Get(int i, int j) const {
		if (IsInvalid(i, j)) {
			throw "範囲外";
		}
		return _data[i][j];
	}
	void Set(const T value, int i, int j) {
		if (IsInvalid(i, j)) {
			throw "範囲外";
		}
		_data[i][j] = value;
	}
	bool IsEqual(const T value, int i, int j) const {
		return Get(i, j) == value;
	}
	// [(si,sj),(ei,ej)]で指定される矩形範囲からvalueと等しいデータの個数を返す．(両端含む)
	int Count(const T value, int si, int sj, int ei, int ej) const {
		// 範囲の決定
		int tsi = 0, tsj = 0, tei = _h - 1, tej = _w - 1;
		tsi = max(tsi, si);
		tsj = max(tsj, sj);
		tei = min(tei, ei);
		tej = min(tej, ej);
		// 範囲がはみ出ていた場合
		if (IsInvalid(tsi, tsj) || IsInvalid(tei, tej)) {
			return 0;
		}
		// カウント
		int count = 0;
		for (int i = tsi; i <= tei; i++) {
			for (int j = tsj; j <= tej; j++) {
				if (IsEqual(value, i, j)) {
					count++;
				}
			}
		}
		return count;
	}
	// (i,j)を含む周囲9マスの範囲からvalueと等しいデータの個数を返す．
	int CountAround(const T value, int i, int j) const {
		return Count(value, i - 1, j - 1, i + 1, j + 1);
	}
protected:
	int _h;
	int _w;
	vector<vector<T>> _data;
};

int main() {
	// Boardを初期化
	int H = 0, W = 0;
	cin >> H >> W;
	Board<char> bd(H,W);
	for (int h = 0; h < bd.GetH(); h++) {
		string s;
		cin >> s;
		for (int w = 0; w < bd.GetW(); w++) {
			bd.Set(s[w], h, w);
		}
	}

	// カウントと結果出力
	for (int h = 0; h < bd.GetH(); h++) {
		for (int w = 0; w < bd.GetW(); w++) {
			// 爆弾だったら
			if (bd.IsEqual('#', h, w)) {
				cout << '#';
			}
			else {
				cout << bd.CountAround('#', h, w);
			}
		}
		cout << '\n';
	}
	cout << flush;
}


Measured memory_bytes: 256