akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<iomanip>
#include<set>
#include<queue>

using namespace std;


string s4[4]={	"abcc",
		"abdd",
		"eefg",
		"hhfg"};

string s5[5]={	"aabbc",
		"dee.c",
		"d..fg",
		"h..fg",
		"hiijj"};

string s6[6]={	"aabb.c",
		".d.eec",
		"fd...g",
		"f...hg",
		"ijj.h.",
		"i.kkll"};

string s7[7]={	"aa.bb.c",
		".d..eec",
		"gdhh...",
		"g...i.j",
		"....ikj",
		"lmm..k.",
		"l.nn.oo"};

int main()
{
	int n;
	cin >> n;
	if(n==2)
	{
		cout << -1 << endl;
		return 0;
	}

	if(n==3)
	for(int i=0;i<n;i++)
		for(int j=0;j<n;j++)
		{
			if(i==j)
			{
				if(i%3==0 or i%3==2)
					cout << "a";
				else
					cout << ".";
			}
			else if(i+1==j)
			{
				if(i%3==0)
					cout << "a";
				else if(i%3==1)
					cout << "b";
				else
					cout << ".";
			}
			else if(i+2==j)
			{
				if(i%3==0)
					cout << "b";
				else
					cout << ".";
			}
			else if(i-1==j)
			{
				if(i%3==0)
					cout << ".";
				else if(i%3==1)
					cout << "b";
				else
					cout << "a";
			}
			else if(i-2==j)
			{
				if(i%3==2)
					cout << "b";
				else
					cout << ".";
			}
			else
				cout << ".";
			cout << (j==n-1 ? "\n":"");
		}
	else
	{
		int x=n%4;
		x+=4;
		if(x==4)x=0;
		for(int i=0;i<n;i++)
		{
			if(n-x<=i)
				for(int j=0;j<n;j++)
				{
					if(x==5)
					{
						int xx=j-(i-i%4);
						if(j>=(n-5))
							cout << s5[i-(n-5)][j-(n-5)];
						else
							cout << ".";
					}
					if(x==6)
					{
						int xx=j-(i-i%4);
						if(j>=(n-6))
							cout << s6[i-(n-6)][j-(n-6)];
						else
							cout << ".";
					}
					if(x==7)
					{
						int xx=j-(i-i%4);
						if(j>=(n-7))
							cout << s7[i-(n-7)][j-(n-7)];
						else
							cout << ".";
					}

				}
			else
			{
				for(int j=0;j<n;j++)
				{
					int xx=j-(i-i%4);
					if(0<=xx and xx<4)
						cout << s4[i%4][j%4];
					else
						cout << ".";

				}
			}
			cout << endl;
		}
	}



}


Measured memory_bytes: 1280
/*  -*- coding: utf-8 -*-
 *
 * 2819.cc: Country in Distortion
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 500;
const int MAX_C = 50;
const long long LINF = 1LL << 61;

/* typedef */

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

struct Stat {
  ll d;
  int i, v;
  Stat() {}
  Stat(ll _d, int _i, int _v): d(_d), i(_i), v(_v) {}

  bool operator<(const Stat &s) const { return d > s.d; }
};

/* global variables */

vpii nbrs[MAX_N];
ll ds0[MAX_N][MAX_C], ds1[MAX_N][MAX_C];

/* subroutines */

/* main */

int main() {
  int n, m;
  scanf("%d%d", &n, &m);

  for (int i = 0; i < m; i++) {
    int x, y, t;
    scanf("%d%d%d", &x, &y, &t);
    x--, y--;
    nbrs[x].push_back(pii(y, t));
    nbrs[y].push_back(pii(x, t));
  }

  int v0, a, b, c;
  scanf("%d%d%d%d", &v0, &a, &b, &c);

  for (int i = 0; i < n; i++) {
    fill(ds0[i], ds0[i] + c, LINF);
    fill(ds1[i], ds1[i] + c, LINF);
  }

  int gl = n - 1;
  ds0[0][v0] = 0;
  priority_queue<Stat> q;
  q.push(Stat(0, 0, v0));

  while (! q.empty()) {
    Stat u = q.top(); q.pop();
    if (u.d != ds0[u.i][u.v]) continue;
    if (u.i == gl) continue;

    int vv = ((ll)a * u.v + b) % c;
    vpii &nbru = nbrs[u.i];
    for (vpii::iterator vit = nbru.begin(); vit != nbru.end(); vit++) {
      int &vi = vit->first;
      ll vd = u.d + (ll)u.v * vit->second;
      if (ds0[vi][vv] > vd) {
	ds0[vi][vv] = vd;
	q.push(Stat(vd, vi, vv));
      }
    }
  }
  //for (int j = 0; j < c; j++) printf("%lld ", ds0[gl][j]); putchar('\n');

  for (int j = 0; j < c; j++)
    if (ds0[gl][j] < LINF) {
      ds1[gl][j] = ds0[gl][j];
      q.push(Stat(ds0[gl][j], gl, j));
    }

  ll mind = LINF;
  while (! q.empty()) {
    Stat u = q.top(); q.pop();
    if (u.d != ds1[u.i][u.v]) continue;
    if (u.i == 0) {
      mind = u.d;
      break;
    }

    int vv = ((ll)a * u.v + b) % c;
    vpii &nbru = nbrs[u.i];
    for (vpii::iterator vit = nbru.begin(); vit != nbru.end(); vit++) {
      int &vi = vit->first;
      ll vd = u.d + (ll)u.v * vit->second;
      if (ds1[vi][vv] > vd) {
	ds1[vi][vv] = vd;
	q.push(Stat(vd, vi, vv));
      }
    }
  }

  printf("%lld\n", mind);
  return 0;
}



Measured memory_bytes: 5136
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        String[] s = reader.readLine().split(" ");
        for (int i = 0; i < s.length; i++) {
            if (s[i].indexOf('0') > -1) {
                System.out.println(i + 1);
                break;
            }
        }
    }
}

Measured memory_bytes: 32664
#include<stdio.h>

int main(){
    double W,H,x,y;
    double ans;
    int line=0;
    scanf("%lf %lf %lf %lf",&W,&H,&x,&y);
    ans=W*H/2;
    if(x==W/2&&y==H/2)line=1;
    printf("%.9f %d",ans,line);
    return 0;
}

Measured memory_bytes: 128
S = input()
first = 0
second = 0
if 0 < int(S[:2]) < 13:
  first = 1
if 0 < int(S[2:]) < 13:
  second = 1

if first == 1 and second == 1:
  print('AMBIGUOUS')
elif first == 1 and second == 0:
  print('MMYY')
elif first == 0 and second == 1:
  print('YYMM')
elif first == 0 and second == 0:
  print('NA')

Measured memory_bytes: 3064
#include<stdio.h>
#include<stdlib.h>

int main()
{
	int N,i,flag;
	int *data;
	int temp;
	int count=0;
	
	scanf("%d",&N);
	data=(int *)malloc(sizeof(int)*N);
	
	for(i=0;i<N;i++)scanf("%d",&data[i]);

	flag=1;
	while(flag)
	{
		flag=0;
		for(i=N-1;i>0;i--)
		{
			if(data[i]<data[i-1])
			{
				flag++;
				count++;
				temp=data[i];
				data[i]=data[i-1];
				data[i-1]=temp;
			}
		}
	}
	
	for(i=0;i<N-1;i++)printf("%d ",data[i]);
	printf("%d\n",data[N-1]);
	printf("%d\n",count);
	free(data);
	return 0;
}

Measured memory_bytes: 600
n = int(input())
pTrans = []
for _ in range(5):
        a = int(input())
        pTrans.append(a)
if n < min(pTrans) :
        print('5')
elif n%min(pTrans) == 0 :
        print(n//min(pTrans) + 4)
else :
        print(n//min(pTrans) + 5)

Measured memory_bytes: 3060
#include<iostream>
#include<iomanip>

using namespace std;

int main(void){
  long long N, K;
  double res = 0.0;

  cin >>  N >> K;

  for(int i=1; i <=N; i++){
    double tmp = i;
    double n = 1;
    while(K > tmp){
      tmp *= 2;
      n /= 2;
    }
    res += n/N;
  }

  cout  << setprecision(10) << res << endl;
}


Measured memory_bytes: 256
# D
S = input()
Q = int(input())

forward_flag = 1

front = ""
back = ""

for i in range(Q):
    n = list(map(str, input().split()))
#     print(n)
    
    if len(n)==1:
        if forward_flag==1:
            forward_flag = 0
        else:
            forward_flag = 1
    else:
        a, b, c = n
        if (forward_flag==1 and b=="1") or (forward_flag==0 and b=="2"):
            front += c
        else:
            back += c

if forward_flag==1:
    print(front[::-1], end="")
    print(S, end="")
    print(back)
else:
    print(back[::-1], end="")
    print(S[::-1], end="")
    print(front)




Measured memory_bytes: 4084
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long int64;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long  INFL = 1e18;
const int MOD = 1000000007;
const int MAX = 210000;
const int MAX_NUM = 999999999;
int n, m, q;
vector<int> a, b, c, d;
int64 ans = 0;
void dfs(vector<int> A) {
	if (A.size() == n + 1) {
		int64 cost = 0;
		for (int i = 0; i < q; ++i) {
			if (A[b[i]] - A[a[i]] == c[i]) {
				cost += d[i];
			}
		}
		ans = max(cost, ans);
		return;
	}
	A.push_back(A.back());
	while(A.back() <= m) {
		dfs(A);
		A.back()++;
	}
	return;
}

void solve() {
	cin >> n >> m >> q;
	a.resize(q); b.resize(q); c.resize(q); d.resize(q);
	for (int i = 0; i < q; ++i) {
		cin >> a[i] >> b[i] >> c[i] >> d[i];
	}
	dfs(vector<int>(1, 1));
	cout << ans << endl;
	return;
}
int main() {
	solve();
	return 0;
}

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

#define what_is(x)    cerr<<#x<<" is "<<x<<"\n";
#define rep(i,a,n)    for(int i=a; i<=n; ++i)
#define rep1(i,a,n)   for(int i=a; i>=n; --i)
#define pb            push_back
#define mp            make_pair
#define int           long long
#define fr            first
#define sc            second
#define vc            vector
#define sz(v)         (int)v.size()
#define all(x)        (x).begin(),(x).end()
#define rall(x)       (x).rbegin(),(x).rend()
#define M             1000000007
#define MM            998244353
#define PI            3.14159265358979
#define INF           1000000000000000

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef map<int,int> mii;

int n,m,ans; string str;

int solve(){
    cin>>n;
    cout<<3*n*n;
    return 0;
}

signed main() {
    ios::sync_with_stdio(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t=1;
    //cin>>t;
    while(t--) solve();
    return 0;
}

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


int n, a, l = -1, r = -1, rev[100010];
long long mod = 1000000007;
long long frac[100010];


long long pow(long long a, long long x){
    if(x == 0){
        return 1;
    }else if(x == 1){
        return a % mod;
    }
    a %= mod;
    long long tmp = pow(a*a%mod, x/2) % mod;
    if(x % 2 == 1){
        return a * tmp % mod;
    }else{
        return tmp % mod;
    }
}

long long inv(long long x){
    return pow(x, mod - 2) % mod;
}


long long C(long long n, long long k){
    if(n < k)return 0;
    return frac[n] * inv(frac[k]) % mod * inv(frac[n-k]) % mod;
}

int main(){
    for(int i = 0; i < 100010; i++){
        rev[i] = -1;
    }
    cin >> n;
    for(int i = 0; i < n+1; i++){
        cin >> a;
        if(rev[a] != -1){
            l = rev[a];
            r = i;
        }else{
            rev[a] = i;
        }
    }
    frac[0] = 1;
    for(int i = 1; i < 100010; i++){
        frac[i] = i * frac[i-1] % mod;
    }

    for(int k = 1; k <= n+1; k++){
        cout << (C(n+1, k) - C(n-r+l, k-1) + mod) % mod << endl;
    }

    
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
const double pi = 3.14159265358979323846;

#define all(s) s.begin(),s.end()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

void rw()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif // ONLINE_JUDGE
}

int main()
{
	speed;
	//rw();

	string s;
	ll c = 0, p = 0;
	cin >> s;

	for (int i = 0; i < 3; i++)
	{
		if (s[i] == 'R')
			c++;
		else
			p = max(p, c), c = 0;
	}
	p = max(c, p);
	cout << p;


	return 0;
}


Measured memory_bytes: 3608
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>
using namespace std;
long long n,a[333][333],ans=0;
bool ok=true,ck[333][333];
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			cin>>a[i][j];
		}
	}
	for(int k=0;k<n;k++)
	{
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<n;j++)
			{
				if(a[i][j]>a[i][k]+a[k][j])
				{
					ok=false;
				}
				if(a[i][j]==a[i][k]+a[k][j] && a[i][k] && a[k][j])
				{
					ck[min(i,j)][max(i,j)]=true;
				}
			}
		}
	}
	for(int i=0;i<n;i++)
	{
		for(int j=i+1;j<n;j++)
		{
			if(!ck[i][j])
			{
				ans+=a[i][j];
			}
		}
	}
	if(ok)
	{
		cout<<ans<<endl;
	}
	else
	{
		cout<<-1<<endl;
	}
	return 0;
}

Measured memory_bytes: 1152
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define N 100010
using namespace std;
struct node{double x,y;}b[N];
node O;
double R;
double sqr(double x){return x*x;}
double dis(node x,node y)
{
    return sqrt(sqr(x.x-y.x)+sqr(x.y-y.y));
}
bool incircle(node x)
{
    if(dis(O,x)<=R) return true;
    return false;
}
node solve(double a,double b,double c,double d,double e,double f)
{
    double y=(f*a-c*d)/(b*d-e*a);
    double x=(f*b-c*e)/(a*e-b*d);
    return (node){x,y};
}
int main()
{
    int n;
    scanf("%d",&n);
    int i,j,k;
    for(i=1;i<=n;i++)
    scanf("%lf%lf",&b[i].x,&b[i].y);
    random_shuffle(b+1,b+n+1);
    R=0;
    for(i=1;i<=n;i++)
    if(!incircle(b[i]))
    {
        O.x=b[i].x;O.y=b[i].y;R=0;
        for(j=1;j<i;j++)
        if(!incircle(b[j]))
        {
            O.x=(b[i].x+b[j].x)/2;
            O.y=(b[i].y+b[j].y)/2;
            R=dis(O,b[i]);
            for(k=1;k<j;k++)
            if(!incircle(b[k]))
            {
                O=solve(
                b[i].x-b[j].x,b[i].y-b[j].y,(sqr(b[j].x)+sqr(b[j].y)-sqr(b[i].x)-sqr(b[i].y))/2,
                b[i].x-b[k].x,b[i].y-b[k].y,(sqr(b[k].x)+sqr(b[k].y)-sqr(b[i].x)-sqr(b[i].y))/2 
                );
                R=dis(b[i],O);
            }
        }
    }
    printf("%.10lf\n",R);
    return 0;
}


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

int main(){
  int n;
  cin >> n;
  if(n == 2){
    cout << 2 << endl;
    return 0;
  }
  else{
    for(int i=n; i<1000000000; i++){
      bool isPrime = true;
      for(int j=2; j<i; j++){
        if(i % j == 0) {
          isPrime = false;
        }
      }
      if(isPrime){
        cout << i << endl;
        return 0;
      }
    }
  }
}

Measured memory_bytes: 256
import sys


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instr = lambda: sys.stdin.readline()
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

n = inint()
V = inintl()

V = sorted(V)

now = 0

for i in range(n-1):
    now = (V[i]+V[i+1])/2
    V[i+1] = now

print(now)

Measured memory_bytes: 62004
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include <limits.h>
#include <cinttypes>
#include <string.h>
#include <bits/stdc++.h>

#define countof(a) (sizeof(a)/sizeof(*a))

#define vi vector<int>
#define vvi vector<vector<int> >
#define pi pair<int,int>
#define fi first
#define se second

#define FOR(var, to)          for (register s64 var = 0; var < (s64)to; var++)
#define FROMTO(var, from, to) for (register s64 var = from; var <= (s64)to; var++)

#define INIT(var) FOR(i,countof(var)) var[i] = 0
#define INPUT(var) FOR(i,countof(var)) var[i] = ri()

#define SORT(v) qsort(v,countof(v),sizeof(*v),int_less)
#define SORTT(v) qsort(v,countof(v),sizeof(*v),int_greater)

#define MOD 1000000007
#define INF (1 << 30)

typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;
typedef int8_t s8;
typedef int16_t s16;
typedef int32_t s32;
typedef int64_t s64;

using namespace std;

static inline int ri() {
  int a;
  scanf("%d", &a);
  return a;
}

static inline s64 rs64() {
  s64 a;
  scanf("%" SCNd64, &a);
  return a;
}

static inline void wi(int a) {
  printf("%d", a);
}

static inline void wu64(u64 a) {
  printf("%" PRIu64, a);
}

static inline void ws64(s64 a) {
  printf("%" PRId64, a);
}

int int_less(const void *a, const void *b) {
  return (*((const int*)a) - *((const int*)b));
}
int int_greater(const void *a, const void *b) {
  return (*((const int*)b) - *((const int*)a));
}

int main() {
    int n = ri();
    
 int cnt = 0;
 vi pp;
 vi p;
 FROMTO(i,2,55555) {
     bool flag = true;
     for (auto j:p) if (!(i%j)) flag = false;
     if (flag) p.push_back(i);
     if (flag && i%5==1) pp.push_back(i), cnt++;
     if (cnt >= n) break;
 }
 FOR(i,n) {
     cout << pp[i] << endl;
 }
    
 return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long f[200001],c[20],a[200001],b[200001];
const int mod=998244353;
int main()
{
	int n,m;
	cin>>n>>m;
	for (int i=0;i<m;i++)
	 cin>>a[i]>>b[i];
	f[1]=1;
	for (int i=2;i<=n;i++)
	{
		for (int j=0;j<m;j++)
		 {
		 	c[j]+=(i-a[j]>=1?f[i-a[j]]:0)-(i-b[j]-1>=1?f[i-b[j]-1]:0);
		 	f[i]=(f[i]+c[j])%mod;
		 }
	}
	cout<<(f[n]+mod)%mod<<endl;
	return 0;
}

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

int main() {
  int N;
  cin>>N;
  bool x=0;
  for(int i=0;i<100;i+=4){
    for(int j=0;j<100;j+=7){
      if(N==i+j){
        x=1;
        break;  
      }
    }
  }
  if(x==1)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T,class U> using P = pair<T,U>;
template<class T> using vec = vector<T>;
template<class T> using vvec = vector<vec<T>>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    char c;
    cin >> c;
    c++;
    cout << c << endl;
}

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

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

const int maxr = 1e5 + 5;

int grid[3][3];
int visited[3][3];

bool possible() {
	for (int i = 0; i < 3; i++) {
		bool flag = false;
		for (int j = 0; j < 3; j++) {
			if (visited[i][j] == 0)
				flag = true;
		}
		if (flag == 0)
			return true;
	}
	for (int i = 0; i < 3; i++) {
		bool flag = false;
		for (int j = 0; j < 3; j++) {
			if (visited[j][i] == 0)
				flag = true;
		}
		if (flag == 0)
			return true;
	}
	bool flag = false;
	for (int i = 0; i < 3; i++) {
		if (visited[i][i] == 0) {
			flag = true;
		}
	}
	if (flag == false)
		return true;
	if (visited[0][2] == true and visited[1][1] == true and visited[2][0] == true)
		return true;

	return false;
}


int32_t main()
{
	GO;
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) {
			cin >> grid[i][j];
			visited[i][j] = 0;
		}
	}
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		for (int j = 0; j < 3; j++) {
			for (int k = 0; k < 3; k++) {
				if (visited[j][k] == 0 && grid[j][k] == a) {
					visited[j][k] = true;
				}
			}
		}
	}
	if (possible())
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}

//!

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

vector<int> a(4);

void abc079c() {
  for (int bit = 0; bit < (1 << 3); bit++) {
    int sum = a[0];
    char op[3];
    for (int i = 0; i < 3; i++) {
      if (bit & (1 << i)) {
        sum += a[i + 1];
        op[i] = '+';
      }
      else {
        sum -= a[i + 1];
        op[i] = '-';
      }
    }
    if (sum == 7) {
      for (int i = 0; i < 4; i++) {
        if (i < 3) {
          cout << a[i] << op[i];
        }
        else {
          cout << a[i] << "=7\n";
        }
      }
      return;
    }
  }
  return;
}

int main() {
  string s;
  cin >> s;
  for (int i = 0; i < 4; i++) {
    a[i] = s[i] - '0';
  }
  abc079c();
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

		int a=sc.nextInt();
		int b=sc.nextInt();

		if(a<b)	System.out.println("a < b");
		else if(a>b)	System.out.println("a > b");
		else System.out.println("a == b");
	}
}

Measured memory_bytes: 26220
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  vector<int> B(N);
  for(int i=0; i<N; i++){
    cin >> A[i];
  }
  for(int i=0; i<N; i++){
    cin >> B[i];
  }
  
  vector<int> ok(N+1);
  
  vector<int>::iterator pos;
  for(int i=0; i<N; i++){
    int a, b;
    pos = lower_bound(A.begin(),A.end(),B[i]);
    a = distance(A.begin(),pos);
    pos = upper_bound(A.begin(),A.end(),B[i]);
    b = distance(A.begin(),pos);
    b--;
    if(i < a){
      ok[0]++;
      ok[i+N-b]--; //i+N-b回でゾーン突入
      ok[i+N-a+1]++; //i+N-a回でゾーン脱出
      ok[N]--;
    }
    else if(i >= a && i <= b){
      ok[i-a+1]++;
      ok[N-(b-i)]--;
    }
    else{
      ok[0]++;
      ok[i-b]--;
      ok[i-a+1]++;
      ok[N]--;
    }
  }
  
  
  for(int i=0; i<N; i++){
    ok[i+1] += ok[i];
  }
  
  for(int i=0; i<N; i++){
    if(ok[i] == N){
      cout << "Yes" << endl;
      for(int j=0; j<N; j++){
        cout << B[(i+j)%N] << endl;
      }
      return 0;
    }
  }
  cout << "No" << endl;
}

Measured memory_bytes: 5624
from collections import defaultdict

n = int(input())
l = list(map(int, input().split()))
l.sort()

# 2辺の和リスト
d = [0] * (l[-1] * 3)
ans = 0

for i in range(n):
  for val in d[l[i] + 1:]:
    # 長さd[i]より小さい組み合わせはOK
    ans += val

  # 自身との組み合わせをdに追加
  for j in range(i):
    d[l[i] + l[j]] += 1

print(ans)


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


struct DisjointSet
{
  vector<int> p;
  vector<int> rank;

  DisjointSet(int n) : p(n), rank(n, 1) {
    for (int i=0; i < n; i++){
      p[i] = i;
    }
  }

  int findSet(int x) {
    if (x != p[x]) p[x] = findSet(p[x]);
    return p[x];
  }

  void unite(int x, int y) {
    int root_x, root_y;
    root_x = findSet(x);
    root_y = findSet(y);

    if (rank[root_x] > rank[root_y]) {
      p[root_y] = root_x;
    } else if (rank[root_x] < rank[root_y]) {
      p[root_x] = root_y;
    } else {
      p[root_y] = root_x;
      root_x++;
    }
  }

  bool same(int x, int y) {
    return findSet(x) == findSet(y);
  }

  int size(int x) {
    return rank[findSet(x)];
  }
};


struct Edge
{
  int a, b, cost;

  bool operator<(const Edge& o) const {
    return cost < o.cost;
  }
};

struct Graph
{
  int n;
  vector<Edge> ed;

  int kruskal() {
    sort(ed.begin(), ed.end());

    DisjointSet dj(n);
    int min_cost = 0;

    for (int i=0; i < ed.size(); i++) {
      Edge& e = ed[i];
      if (!dj.same(e.a, e.b)) {
        min_cost += e.cost;
        dj.unite(e.a, e.b);
      }
    }

    return min_cost;
  }
};

Graph input() {
  Graph g;
  int m;
  cin >> g.n >> m;
  for (int i=0; i < m; i++){
    Edge e;
    cin >> e.a >> e.b >> e.cost;
    g.ed.push_back(e);
  }
  return g;
}


int main()
{
  Graph g = input();
  cout << g.kruskal() << endl;
  return 0;
}



Measured memory_bytes: 4596
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
int64_t n,k,tmp;
void solve(){
    n=n-k*(n/k);
    while(true) {
        tmp=abs(n-k);
        if(n>tmp) {
            n=tmp;
        }else{
            break;
        }
    }
    cout<<n<<endl;
}

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

    solve();
    return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
using namespace std;
int n;
int ba[10];
bool bfs(int l,int r,int x)
{
	if(x==10) return true;
	if(ba[x]<l&&ba[x]<r) return false;
	if(l<ba[x]&&bfs(ba[x],r,x+1)) return true;
	if(r<ba[x]&&bfs(l,ba[x],x+1)) return true;
	return false;
}

int main()
{
	cin>>n;
	for(;n>0;n--){
		for(int i=0;i<10;i++){
			scanf("%d",&ba[i]);
		}
		if(bfs(0,0,0)) cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
}

Measured memory_bytes: 1232
#include<cstdio>
#include<algorithm>
int main(void){
    int i,w,n,a,b,*p;
    scanf("%d%d",&w,&n);
    p=new int[w];
    for(i=0;i<w;i++)p[i]=i+1;
    while(~scanf("%d,%d",&a,&b))std::swap(p[a-1],p[b-1]);
    for(i=0;i<w;i++) printf("%d\n",p[i]);
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
 
int main()
{
 
string s;
cin >> s;

if(s[0] == s[1] && s[1] == s[2]) cout << "Yes\n";
else if(s[1] == s[2] && s[2] == s[3]) cout << "Yes\n";
else cout << "No\n";
 
return 0;
}

Measured memory_bytes: 256
#include <cstdio>
using namespace std;
int main(){
    int A,B,C,D;
    scanf("%d %d %d %d",&A,&B,&C,&D);
    int s1 = A*B,s2 = C*D;
    if(s1>s2){
        printf("%d\n",s1);
    }
    else if(s2>s1){
        printf("%d\n",s2);
    }
    else{
        printf("%d\n",s1);
    }
    return 0;
}

Measured memory_bytes: 128
n=int(input())
a=list(map(int,input().split()))
s=sum(a)-a[0]
m=a[0]
ans=abs(s-m)
for i in range(1,n-1):
	m+=a[i]
	s-=a[i]
	ans=min(ans,abs(s-m))
print(ans)

Measured memory_bytes: 24936
// C++(GCC 9.2.1)
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define repex(i, a, b, c) for(int i = a; i < b; i += c)
#define repx(i, a, b) repex(i, a, b, 1)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)
LL a[202020];

int main(){
    
    // 1. 入力情報.
    int N, Xor = 0;
    scanf("%d", &N);
    rep(i, N){
        scanf("%lld", &a[i]);
        Xor ^= a[i];
    }
    
    // 2. 出力.
    rep(i, N){
        printf("%lld", a[i] ^ Xor);
        if(i < N - 1) printf(" ");
    }
    return 0;
    
}

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

enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;

enum mod = 1_000_000_007L;




void main() {
    string s;
    scan(s);

    bool first = (s.front == s.back) ^ (s.length % 2);

    writeln(first ? "First" : "Second");
}




void scan(T...)(ref T args) {
    auto line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront;
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args) if (x > arg) {
        x = arg;
        isChanged = true;
    }
    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args) if (x < arg) {
        x = arg;
        isChanged = true;
    }
    return isChanged;
}

void yes(bool ok, string y = "Yes", string n = "No") {
    return writeln(ok ? y : n);
}


Measured memory_bytes: 2456
#include<stdio.h>
#include<string.h>
int main()
{
	long long a,b,c,d,e,f,g,h,i,j,k,l;
	char s[200010];
	gets(s);
	a=strlen(s);
	for(b=c=0;b<a;b++)
	{
		c+=(int)(s[b]-'0');
	}
	if(c%9==0)printf("Yes\n");
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 1724
#include <stdio.h>
#include <stdlib.h>


typedef struct{
  int parent;
  int cnum;
  int *child;
} Node;

int main(){
  int n;
  int N;
  int num;
  Node A[100000];
  int i,j;
  int jag;
  int depth;
  
  
  
  scanf("%d",&n);
  for(i=0;i<n;i++) A[i].parent=-1;
  for(i=0;i<n;i++){
    scanf("%d",&num);
    scanf("%d",&A[num].cnum);
    A[num].child=(int *)malloc(A[num].cnum*sizeof(int));
    for(j=0;j<A[num].cnum;j++){
      scanf("%d",&A[num].child[j]);
      A[A[num].child[j]].parent=num;
    }
  }
  for(i=0;i<n;i++){
    printf("node %d: parent = %d, ",i,A[i].parent);
    jag=A[i].parent;
    depth=0;
    while(1){
      if(jag==-1){
	printf("depth = %d, ",depth);
	break;
      }
      else{
	depth++;
	jag=A[jag].parent;
      }
    }
    if(depth==0) printf("root, [");
    else if(A[i].cnum!=0) printf("internal node, [");
    else printf("leaf, [");
    if(A[i].cnum!=0){
      for(j=1;j<A[i].cnum;j++) printf("%d, ",A[i].child[j-1]);
      printf("%d",A[i].child[j-1]);
    }
    printf("]\n");
  }
  return 0;
}



Measured memory_bytes: 6872
#include <iostream>
#include <cstring>

using namespace std;

int n, m, field[11][11], si, sj, num;
 
int dfs(int x, int y){
  int ans = 0;
  if(num == 0){
    if(x == si || y == sj)return 1;
    else return 0;
  }

  field[x][y] = 0;
  for(int i = x + 1 ; i < m ; i++){
    if(field[i][y] == 1){
      num--;
      ans += dfs(i, y);
      num++;
      break;
    }
  }
  for(int i = x - 1 ; i >= 0 ; i--){
    if(field[i][y] == 1){
      num--;
      ans += dfs(i, y);
      num++;
      break;
    }
  }
  for(int i = y + 1 ; i < n ; i++){
    if(field[x][i] == 1){
      num--;
      ans += dfs(x, i);
      num++;
      break;
    }
  }
  for(int i = y - 1 ; i >= 0 ; i--){
    if(field[x][i] == 1){
      num--;
      ans += dfs(x, i);
      num++;
      break;
    }
  } 
  field[x][y] = 1;
  return ans;
}
 
int main(void){

  while(cin >> n >> m, n + m){
    
    memset(field, 0, sizeof(field));
    num = 0;
    for(int i = 0;i < m;i++){
      for(int j = 0;j < n;j++){
	cin >> field[i][j];
	if(field[i][j] == 2){
	  si = i;
	  sj = j;
	}
	else num += field[i][j];
      }
    }
    cout << dfs(si, sj) << endl;
  }
}

Measured memory_bytes: 1160
import math
N=int(input())
m=10**6+1
M=[0]*m
g=0
for i in map(int,input().split()):M[i]+=1;g=math.gcd(g,i)
if g>1:print('not coprime')
elif all(sum(M[i::i])<=1 for i in range(2,m)):print('pairwise coprime')
else:print('setwise coprime')


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

#define ll long long
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define pr(a, b) pair<a, b>
#define si set<int>
#define sl set<long long>
#define pq prioirty_queue
#define all(v) v.begin(),v.end()
#define left  (2*idx)+1
#define right (2*idx)+2
#define frt(i,a,b) for(ll i=a; i<b; i++)
#define rew(i,a,b) for(ll i=a; i>=b; i--)
#define fre(i,a,b) for(ll i=a; i<=b; i++)

#define mod %
#define N 100007
#define MOD (ll)(1e9 + 7)
#define test if(true)


int main()
{
	ll a, b;
	cin >> a >> b;

	if((a + b) mod 2 == 0)
	{
		cout << (a + b) / 2 << "\n";
	}
	else
	{
		cout << "IMPOSSIBLE\n";
	}
    return 0;
}


Measured memory_bytes: 256
while True:
    n, x = map(int, input().split())
    if n == 0 and x == 0:
        break
    else:
        count = 0
        for i in range ( 1, n + 1):
            for j in range ( i + 1, n + 1):
                for k in range ( j + 1, n + 1):
                    if i + j + k == x:
                        count += 1
    print(int(count))


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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vvvint = vector<vvint>;
using vdouble = vector<double>;
using vvdouble = vector<vdouble>;
using vvvdouble = vector<vvdouble>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;
constexpr int mod2 = 998244353;
template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return (a > b && (a = b, true)); }
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return (a < b && (a = b, true)); }
template<typename T>
bool isin(T y, T x, T h, T w) { return (0 <= y && 0 <= x && y < h && x < w); }
template<typename T>
bool isin1(T y, T x, T h, T w) { return (0 < y && 0 < x && y <= h && x <= w); }

template<typename T>
ostream& operator <<(ostream &os, vector<T> &v) {
	os << v[0];
	for (int i = 1; i < v.size(); i++) os << " " << v[i];
	return (os);
}

template<typename T>
istream& operator >>(istream &is, vector<T> &v) {
	for (auto &u : v) is >> u;
	return (is);
}

template<typename T1, typename T2>
istream& operator >>(istream &is, pair<T1, T2> &p) {
	return (is >> p.first >> p.second);
}


void Main() {
	ll X; cin >> X;
	for (ll A = -249; A <= 250; A++) {
		for (ll B = -250; B < A; B++) {
			if (A*A*A*A*A - B*B*B*B*B == X) {
				cout << A << " " << B << el;
				return;
			}
		}
	}
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout << fixed << setprecision(20);
	Main();
	return (0);
}


Measured memory_bytes: 3660
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <chrono>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef double db;

#define fr first
#define sc second
#define pb push_back
#define rep(i,x) for(ll i=0;i<x;i++)
#define rep1(i,x) for(ll i=1;i<=x;i++)
#define rrep(i,x) for(ll i=x-1;i>=0;i--)
#define rrep1(i,x) for(ll i=x;i>0;i--)

ll n;
ll a[100001];
vector<ll> win[100001];
const ll INF=0xffffffffff;
ll rec(ll x){//x番の木の深さの最大値(最小化)
	ll res=win[x].size();
	vector<ll> v;
	rep(i,win[x].size()){
		v.pb(rec(win[x][i]));
	}
	sort(v.begin(),v.end(),greater<ll>());
	rep(i,v.size()){
		res=max(res,v[i]+i+1);
	}
	return res;
}

int main()
{
	cin>>n;
	rep1(i,n-1){
		cin>>a[i+1];
		win[a[i+1]].pb(i+1);
	}
	cout<<rec(1)<<endl;
}

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

const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1; finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
  int n;
  cin>>n;
  int a[n+1];

  int p, q;
  map<int, int> m;
  for (int i=0; i<=n; i++) {
    cin>>a[i];
    if (m[a[i]] > 0) {
      p = m[a[i]] - 1;
      q = i;
    }
    m[a[i]] = i+1;
  }
  COMinit();
  for (int i=1; i<=n+1; i++) {
    long long ans = COM(n+1, i);
    ans -= COM(n+p-q, i-1);
    ans = (ans + MOD) % MOD;
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 18176
#include <bits/stdc++.h>
using namespace std;
long long n, ans = 0x7fffffffffffff;
long long sum[200010];
int main() {
    scanf("%lld", &n);
    for (int i = 1; i <= n; ++i) {
        scanf("%lld", &sum[i]);
        sum[i] += sum[i - 1];
    }
    for (int i = 1; i < n; ++i) {
        ans = min(ans, abs(sum[n] - sum[i] - sum[i]));
    }
    cout << ans << endl;
    return 0;
}


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

#ifdef _PRINTDEBUG
  #include "lib/printdebug.hpp"
#else
  #define printdebug(...) 1
#endif
#define MOD_1_000_000_007 (1000000007)
#define IINF (1<<28)
#define LINF (1LL<<60)
#define rep(i, n)      REP(i, 0, (n))
#define repc(i, n)     REPC(i, 0, (n))
#define REP(i, n, m)   for (int i = (int)(n); i <  (int)(m); i++)
#define REPC(i, n, m)  for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
#define yesno(cond)       YESNO((cond), "Yes", "No")
#define YESNO(cond, a, b) cout << ((cond) ? (a) : (b)) << "\n"

namespace solver {
  using namespace std;
  typedef long long ll;

  ll A, B, C, K;

  void init() {
    cin >> A >> B >> C >> K;
  }

  void solve() {
    ll ans = 0;
    if(K>0) {
      ans += min(A, K);
      K -= min(A, K);
    }
    if(K>0) {
      K -= min(B, K);
    }
    if(K>0) {
      ans -= min(C, K);
    }
    cout << ans << "\n";
  }
}

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  solver::init();
  solver::solve();
  return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define rep(i,e) for(int i= 0; i< (int)(e); i++)
#define reps(i,s,e) for(int i = s; i < (int)(e); i++)
#define repr(i,s,e) for(int i = s; i > (int)(e); i--)
#define pb push_back
typedef long long ll;
const ll INF = 1LL << 60;

int main()
{
    int a,b;
    cin >> a >> b;
    int h = 40;
    int w = 100;
    int nokori_siro = a-1;
    int nokori_kuro = b-1;
    cout << h << " " << w << endl;
    rep(i,h){
        rep(j,w){
            char ans;
            if(i<20){
                ans = '#';
                if(i%2==0 && j%2==0 && nokori_siro>=1){
                    nokori_siro--;
                    ans = '.';
                }
            }
            else{
                ans = '.';
                if(i%2==1 && j%2==1 && nokori_kuro>=1){
                    nokori_kuro--;
                    ans = '#';
                }
            }
            cout << ans;
        }
        cout << endl;
    }
}

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

using namespace std;

#define ALL(x) (x).begin(), (x).end()
#define ALLTRUE(xs) all_of(ALL(xs),[](bool x){return x;})
#define AND(x,y,z) set_intersection((x).begin(),(x).end(),(y).begin(),(y).end(),inserter((z),(z).end()))
#define ANYTRUE(xs) any_of(ALL(xs),[](bool x){return x;})
#define CONCAT(x,y) (x).insert((x).end(),(y).begin(),(y).end())
#define DUMP(xs) for (auto x:xs) cout<<x<<' ';cout<<endl
#define FOR(i,a,b) for (int i=(int)(a);i<(int)(b);++i)
#define OR(x,y,z) set_union((x).begin(),(x).end(),(y).begin(),(y).end(),inserter((z),(z).end()))
#define OUT(x) cout<<x<<endl
#define REP(i,n) FOR(i,0,n)

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

struct edge { int to,cost; };

int main() {
  int N;cin>>N;
  vector<int> as(N);
  vector<int> odd_as;
  vector<int> even_as;
  REP(i,N) {
    int a;cin>>a;
    if (i%2==0) even_as.push_back(a);
    else odd_as.push_back(a);
  }

  reverse(ALL(odd_as));
  CONCAT(odd_as,even_as);
  if (N%2==1) reverse(ALL(odd_as));

  DUMP(odd_as);

  return 0;
}

Measured memory_bytes: 4332
#include <bits/stdc++.h>
using namespace std;
const unsigned int MOD = 1000000007;
#define ll long long
#define PI 3.1416
string day[]={"SUN","MON","TUE","WED","THU","FRI","SAT"};
int main() {
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int a,b,c,d;
    while(cin>>a>>b>>c>>d){
        if(a+b==c+d)cout<<"Balanced"<<endl;
        else if(a+b>c+d)cout<<"Left"<<endl;
        else cout<<"Right"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define del(a,i) memset(a,i,sizeof(a))
#define ll long long
#define inl inline
#define il inl void
#define it inl int
#define ill inl ll
#define re register
#define ri re int
#define rl re ll
#define INF 0x3f3f3f3f
#define lowbit(x) (x&(-x))
#define mid ((l+r)>>1)
using namespace std;
template<class T>il read(T &x){
	x=0;int f=1;char k=getchar();
	for(;k>'9'||k<'0';k=getchar()) if(k=='-') f=-1;
	for(;k>='0'&&k<='9';k=getchar()) x=x*10+k-'0';
	x*=f;
}
template<class T>il _print(T x){
	if(x>9) _print(x/10);
	putchar(x%10+'0');
}
template<class T>il print(T x){
	if(x<0) putchar('-'),x=-x;
	_print(x);
}
const int N = 1e4+5;
int H,n,a,b,dp[N];
int main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	read(H),read(n);
	del(dp,0x3f),dp[0]=0;
	for(ri i=1;i<=n;++i){
		read(a),read(b);
		for(ri j=1;j<=H;++j){
			int tval=j-a<=0?0:dp[j-a];
			dp[j]=min(dp[j],tval+b);
		}
	}
	print(dp[H]);
	return 0;
}

Measured memory_bytes: 256
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列
using namespace std;

typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 10000007 //10^9+7
#define MAXR 100000 //10^5:最大のrange(素数列挙などで使用)

int main(void){
    string s;
    cin >> s;
    REP(i, 26) {
        auto pos = s.find('a'+i);
        if(pos == -1) {
            cout << char('a'+i) << endl;
            return 0;
        }
    }
    cout << "None" << endl;
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <unordered_map>
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define REP(i,a,b) for(int i=a; i<=b; i++)
using namespace std;

typedef long long int ll;

int main() {
    ll n;
    string ans="";
    cin >> n;
    while(n>0){
        n--;
        ans=(char)('a'+(n%26))+ans;
        n/=26;
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 3640
#include<cstdio>
#include<algorithm>
#include<vector>
#include<deque>
#include<string>
#include<iostream>
using namespace std;
//AOJ2199
bool solve(void){//?????°???????????????????????????
	int N,M,i,j,k,q;
	const long long int big=1919114514;// >20000*256*256
	long long int ans=big;
	vector<int>cod;
	long long int dp[256];
	long long int ddp[256];
	for(i=0;i<=127;i++){dp[i]=big;}
	dp[128]=0;
	for(i=129;i<256;i++){dp[i]=big;}
	scanf("%d %d",&N,&M);
	if(N*M==0){return false;}
	for(i=0;i<M;i++){
		scanf("%d",&q);
		cod.push_back(q);
	}
	for(i=0;i<N;i++){
		scanf("%d",&q);
		for(j=0;j<256;j++){
			for(k=0;k<cod.size();k++){
				ddp[min(255,max(j+cod[k],0))]=min(ddp[min(255,max(j+cod[k],0))],dp[j]);
			}
		}
		for(j=0;j<256;j++){
			dp[j]=ddp[j]+(q-j)*(q-j);
			ddp[j]=big;
		}
	}
	for(j=0;j<256;j++){
		ans=min(ans,dp[j]);
	}
	printf("%lld\n",ans);
	return true;
}
int main(void){while(solve()){}return 0;}

Measured memory_bytes: 3112
#include<bits/stdc++.h>
using namespace std;
int N,E,T;
int x[100005];
long long f[100005];
int main(){
	scanf("%d%d%d",&N,&E,&T);
	for(int i=1;i<=N;i++) scanf("%d",&x[i]);x[0]=x[1];
	long long ans=1e18,mn=1e18;
	for(int i=1,p=1;i<=N;i++){
		while(p<N&&(x[i]-x[p])>T/2) {
			mn=min(mn,f[p-1]-x[p]*2-x[p-1]);
			p++;
		}
		f[i]=min(f[p-1]+x[i]-x[p-1]+T,mn+x[i]*3LL);
	}
	ans=min(ans,f[N]+x[1]+E-x[N]);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
int main()
{
	long long a,b;
	scanf("%lld %lld",&a,&b);
	if(b-2*a<0){
		printf("%lld",b/2);
	}
	else if(b-2*a>=0){
		printf("%lld",a+(b-2*a)/4);
	}
	
	return 0;
}

Measured memory_bytes: 256
import sys
n=input()
s=input()
t=input()
count=0
flag=True
for i in range(len(s)):
    flag=True
    j=0
    for ii in range(i,len(s)):
        if t[j]!=s[ii]:
            flag=False
            break
        j+=1
        count+=1
    if flag:
        print(len(s)+i)
        sys.exit()
print(len(s+t))

Measured memory_bytes: 3064
///بِسْمِ الّٰلهِ الرَّحْمٰنِ الرَحِيْمِ7
#include<bits/stdc++.h>
#define ll long long
#define pi acos(-1.0)
int main()
{

    float r;
     scanf("%f",&r);
     float sd=2*pi*r;
     printf("%.5f",sd);
     return EXIT_SUCCESS;
}



Measured memory_bytes: 3828
import java.util.*;

public class Main
{
    public static void main(String[] args)
    {
        //long start = System.currentTimeMillis();
        final long MOD = (long)Math.pow(10,9)+7;
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        //----------------------------------------
        long ans = ( powmod(10,n) - powmod(9,n) )%MOD;
        ans = (ans - powmod(9,n) )%MOD;
        ans = ( ans + powmod(8,n))%MOD;

        ans = (ans+MOD)%MOD;
        System.out.println(ans);

        sc.close();
//        long end = System.currentTimeMillis();
//        System.err.println((end-start)+"ms");
    }

    public static long powmod(long x, long y)
    {
        long ret = 1;
        long MOD = (long)Math.pow(10,9)+7;
        for (int i = 0;i<y;++i)
        {
            ret = ret * x % MOD;
        }
        return ret;
    }
}

Measured memory_bytes: 27200
n = int(input())
inlist=[]
for j in range(n):
  s, i = input().split()
  inlist.append(s+"."+i)
x = input()


result = 0
flag = False
for j in inlist:
  smoji,number = j.split(".")
  if flag:
    result += int(number)
  if smoji == x:
    flag = True

print(result)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <cstring>
#include <climits>
#include <algorithm>
#include <map>

using namespace std;
typedef long long ll;

int main() {
    int n, m, h, k;
    while (cin >> n >> m >> h >> k, n) {
        vector<ll> s(n);
        for (int i=0; i<n; ++i) {
            cin >> s[i];
        }
        int a, b;
        vector<pair<int,int> > bar;
        for (int i=0; i<m; ++i) {
            cin >> a >> b;
            bar.push_back(make_pair(b, a-1));
        }
        sort(bar.begin(), bar.end());

        vector<int> id(n);
        for (int i=0; i<n; ++i) id[i] = i+1;

        vector<pair<int,int> > route(m);
        for (int i=0; i<m; ++i) {
            int x = bar[i].second;
            swap(id[x], id[x+1]);
            route[i] = make_pair(id[x], id[x+1]);
        }

        vector<ll> pt(n+1);
        for (int i=0; i<n; ++i) {
            pt[id[i]] = s[i];
        }

        ll base_score = 0;
        for (int i=1; i<=k; ++i) {
            base_score += pt[i];
        }

        ll res = base_score;
        for (int i=0; i<m; ++i) {
            if (route[i].first <= k && k < route[i].second) {
                res = min(res, base_score - pt[route[i].first] + pt[route[i].second]);
            } else if (k < route[i].first && route[i].second <= k) {
                res = min(res, base_score - pt[route[i].second] + pt[route[i].first]);
            }
        }

        cout << res << endl;
    }
    return 0;
}

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

bool check(vector<P> s){
    int h = 0;
    for(P p : s){
        int b = h + p.first;
        h += p.second;
        if(b < 0) return false;
    }
    return true;
}

int main(){
    int n;
    cin >> n;
    vector<P> ls, rs;
    int total = 0;
    rep(i,n){
        string s;
        cin >> s;
        int h = 0, b = 0;//h:終点、b:最下点
        for(char c: s){
            if(c == '(') h++; else h--;
            b = min(b, h);
        }
        if(h > 0) ls.emplace_back(b, h);
        else rs.emplace_back(b-h, -h);//折り返せばlsと考え方は同じ、終点から始点と最下点を見る
        total += h;
    }
    sort(ls.rbegin(), ls.rend());//最下点が小さいものからくっつける
    sort(rs.rbegin(), rs.rend());
    if(check(ls) && check(rs) && total == 0){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 18908
import sys
import os

def file_input():
    f = open('../Beginner_Contest_164/input.txt', 'r')
    sys.stdin = f

def main():
    #file_input()
    # A,B,C,D=map(int, input().split())
    N = int(input())

    # S = []
    # for i in range(N):
    #     str = input()
    #     if str not in S:
    #         S.append(str)
    #
    # print(len(S))

    S = set()
    for i in range(N):
        S.add(input())

    print(len(S))

    # S = {}
    # val=0
    # for i in range(N):
    #     str = input()
    #     if S.get(str) == None:
    #         S[val]=str
    #         val+=1
    #
    # print(val)

    # val = 0
    # str = ""
    # for i in range(N):
    #     in_str = input()
    #     if str.find(in_str):
    #         str += " "+in_str
    #         val += 1
    #
    # print(val)

if __name__ == '__main__':
    main()


Measured memory_bytes: 31156
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int64_t minn(int64_t a,int64_t b){
    if(a >= b) return b;
    else return a;
}
int main(){
    int A,B,C;
    cin >>A>>B>>C;
   bool check = 1;
   for(int i = 2;i < 100;i++){
       if(A%i == 0&& B%i == 0&&C%i != 0)check = 0;
   }
   if(check) cout << "YES" << endl;
   else cout << "NO" << endl;
   
}



Measured memory_bytes: 256
s = input()
n = len(s)
yn = "YES"

while(len(s) > 0):
    if(s.endswith("dream") or s.endswith("erase")):
        s = s[:(len(s)-5)]
    elif(s.endswith("eraser")):
        s = s[:(len(s)-6)]
    elif(s.endswith("dreamer")):
        s = s[:(len(s)-7)]
    else:
        yn = "NO"
        break

print(yn)

Measured memory_bytes: 3188
use std::io::stdin;

fn main() {
  let mut num = String::new();
  stdin().read_line(&mut num).unwrap();
  let vec: Vec<&str> = num.trim().split(" ").collect();
  let body: i32 = vec[0].parse().unwrap();
  let reg: i32 = vec[1].parse().unwrap();
  if(reg % 2 != 0 || body * 2 > reg || body * 4 < reg) {
    println!("No");
  } else {
    println!("Yes");
  }
}

Measured memory_bytes: 2144