akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    int N;
    cin >> N;
    vector<int> p(N);
    for (int i = 0; i < N; i++) cin >> p[i];

    vector<int> p_sorted(N);
    copy(p.begin(), p.end(), p_sorted.begin());
    sort(p_sorted.begin(), p_sorted.end());

    int count = 0;
    for (int i = 0; i < N; i++) {
        if (p[i] != p_sorted[i]) count++;
        if (count > 2) break;
    }

    cout << (count > 2 ? "NO" : "YES") << endl;
}

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

int n;
int c[505] = {0};
int s[505] = {0};
int f[505] = {0};
int ans[505] = {0};

void solve();

int main() {
  cin >> n;
  for(int i = 0; i < n - 1; ++i)
    cin >> c[i] >> s[i] >> f[i];
  solve();
  for(int i = 0; i < n; ++i) cout << ans[i] << endl;
  return 0;
}

void solve() {
  for(int i = 0; i < n - 1; ++i) {
    int now = s[i] + c[i];
    for(int j = i + 1; j < n - 1; ++j) {
      if(now < s[j])
        now = s[j];
      else if(now % f[j] != 0)
        now += f[j] - now % f[j];
      now += c[j];
    }
    ans[i] = now;
  }
}

Measured memory_bytes: 256
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

int calc(string s) {

    int rec(int head) {
        int change = 0;
        for (int i = 0; i < s.length; i++) {
            if ((i % 2 == 0) ^ ((s[i] - '0') == head)) {
                change++;
            }
        }
        return change;
    }

    return min(rec(0), rec(1));
}

void main() {
    string s = read!string;
    writeln(calc(s));
}



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

using namespace std;

#define repeat(n) for(int _______ = (n); _______ > 0; --_______)
#define loop(i, l, r) for(auto i = (l), __r = decltype(i)(r); i <= __r; ++i)
#define iloop(i, l, r) for(auto i = (l), __r = decltype(i)(r); i < __r; ++i)
#define rloop(i, r, l) for(auto i = (r), __l = decltype(i)(l); i >= __l; --i)

using LL = long long;

template<typename Container>
inline
int size(const Container& x)
{ return x.size(); }

#ifdef CAI_WEI_HAN

#include "my_print.h"
#include "LOG.h"

#else

#define LOG(...)

#endif

struct P
{ LL x, y, i; };

P operator - (P a, P b)
{ return P{ a.x - b.x, a.y - b.y, 0 }; }

LL operator ^ (P a, P b)
{ return a.x * b.y - a.y * b.x; }

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	constexpr char endl = '\n';
#ifdef CAI_WEI_HAN
	freopen("test.in", "r", stdin);
	register auto program_start_time = clock();
	#define cout cerr
#endif
	
	int n, m;
	cin >> n >> m;
	
	if(m <= 1)
		cout << 0;
	else
		cout << (int)ceil((double)(m-1) / (n-1));
	
#ifdef CAI_WEI_HAN
	cout << "\n\n--------------------------------\n"
		 << "time:   " << double(clock() - program_start_time) / CLOCKS_PER_SEC;
#endif
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define F first
#define S second

using namespace std;
typedef pair<int,int> P;

const int MOD=1000000007;
int INF=100100100100100;

vector<int> v[30];
signed main(){
  string s,t;
  cin>>s>>t;
  for(int i=0;i<s.length();i++){
    int x=s[i]-'a';
    v[x].pb(i);
    //cout<<x<<endl;
  }
  int cur=-1,ko=0;
  for(int i=0;i<t.length();i++){
    int x=t[i]-'a';
    if(v[x].size()==0){
      cout<<-1<<endl;
      return 0;
    }
    int next=lower_bound(all(v[x]),cur+1)-v[x].begin();
    //cout<<next<<endl;
    if(next==v[x].end()-v[x].begin()){
      ko++;
      cur=v[x][0];
    }
    else cur=v[x][next];
  }
  cout<<ko*s.length()+cur+1<<endl;
  return 0;
}

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

vector<int> solve(int N) {
    vector<int> ret;
    vector<bool> flags(300100, true);
    for (long long i = 6; i <= N; i++) {
        if (i % 7 != 1 && i % 7 != 6) flags[i] = false;
        if (flags[i]) {
            flags[i] = false;
            // cout << i << endl;
            if (N % i == 0) ret.push_back(i);
            for (long long j = 2; j * i < flags.size(); j++) {
                flags[j * i] = false;
            }
        }
    }
    return ret;
}

int main() {
    int N;
    while (1) {
        cin >> N;
        if (N == 1) break;
        vector<int> ans = solve(N);

        cout << N << ": ";
        for (int i = 0; i < ans.size() - 1; i++) {
            cout << ans[i] << " ";
        }
        cout << ans[ans.size() - 1] << endl;
    }
}


Measured memory_bytes: 3096
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll n,cap,val[100005],dp[1000][100005],w[100005],w1;
ll kn(ll n,ll w1)
{
    if(n==0||w==0)return 0;
    if(dp[n][w1]!=-1)return dp[n][w1];
    if(w1-w[n]<0)return kn(n-1,w1);
    else
    {
        ll p=val[n]+kn(n-1,w1-w[n]);
        ll p1=kn(n-1,w1);
        dp[n][w1]=max(p,p1);
        return dp[n][w1];
    }
}
int main()
{
    cin>>n>>cap;
    memset(dp,-1,sizeof(dp));
    for(int i=1;i<=n;i++)cin>>w[i]>>val[i];
    cout<<kn(n,cap);
}


Measured memory_bytes: 781824
$N,$A,$B,$C = gets.split.map &:to_i
$l = []
$N.times{
    $l << gets.to_i
}
def dfs n,a,b,c,com
    if n == $N
        if [a,b,c].min != 0
            return  (a-$A).abs + (b-$B).abs + (c-$C).abs + com
        else
            return 10 ** 10
        end
    end
    return [dfs(n+1,a+$l[n],b,c, (a == 0 ? com :  com+10) ) ,dfs(n+1,a,b+$l[n],c,(b == 0 ? com :  com+10)) , dfs(n+1,a,b,c+$l[n],(c == 0 ? com :  com+10)),dfs(n+1,a,b,c,com)].min
end
p dfs(0,0,0,0,0)


Measured memory_bytes: 3836
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {		
		try (Scanner sc = new Scanner(System.in)){
			int n = sc.nextInt();
			int k = sc.nextInt();
			String s = sc.next();
			String array[] = new String[n];
			
			int i = 0;
			while(i < n) {
				array[i] = s.substring(i,i+1);
				i ++;
			}
			
			switch (array[k-1]) {
				case "A":
					array[k-1] = "a";
					break;
				case "B":
					array[k-1] = "b";
					break;
				case "C":
					array[k-1] = "c";
					break;
			}
			
			StringBuilder result = new StringBuilder();
			int j = 0;
			while (j < n) {
				result.append(array[j]);
				j ++;
			}
			System.out.println(result);
		}
	}
}


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

#define ll long long
#define mtv(kit) cout<<#kit<<" - "<<kit<<"\n";
#define ff first
#define ss second
#define pb push_back
#define rep(i,a,b) for(i=a;i<b;i++)
#define pii pair<ll , ll>
#define all(x) x.begin(),x.end()
#define nl "\n"
#define ump unordered_map

void doit(){
	vector<char>s(4);
	cin >> s[0] >> s[1] >> s[2];
	ll i,ans = 0;
	rep(i,0,3){
		if(s[i] == 'R')ans++;
	}
	if(ans == 3){
		cout << 3 << nl;
		return;
	}
	if(s[0] == s[1] and s[0] == 'R'){
		cout << 2 << nl;
		return;
	}
	if(s[2] == s[1] and s[2] == 'R'){
		cout << 2 << nl;
		return;
	}
	if(ans)ans = 1;
	cout << ans << nl;
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("input1.txt","r",stdin);
    freopen("output1.txt","w",stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t = 1;
   //  cin >> t;
    for(ll i = 1; i <= t; i++){
        doit();
    }
}


Measured memory_bytes: 3608
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next(), t = sc.next();
		char[] StoT = new char[26];
		char[] TtoS = new char[26];
		for (int i = 0; i < s.length(); i++) {
			// First Observation for every character in S they can only map to one unique
			// character of T
			if (StoT[s.charAt(i) - 'a'] != 0 && StoT[s.charAt(i) - 'a'] != t.charAt(i)) {
				System.out.println("No");
				return;
			}
			// Second Observation for every character in T they can only map to one unique
			// character of S
			if (TtoS[t.charAt(i) - 'a'] != 0 && TtoS[t.charAt(i) - 'a'] != s.charAt(i)) {
				System.out.println("No");
				return;
			}
			StoT[s.charAt(i) - 'a'] = t.charAt(i);
			TtoS[t.charAt(i) - 'a'] = s.charAt(i);
		}
		System.out.println("Yes");
	}
}

Measured memory_bytes: 32076
#include <iostream>
#include <stdio.h>
#include<string.h>
using namespace std;

int main()
{   
    string a;
    cin>>a;
    int b,i=1;
    b=strlen(a.c_str());
    if(b==1)
        printf("%c\n",a[0]);
    else
    {for(;i<=b&&a[i]=='9';i++);
    if(i>=b)
    printf("%d\n",a[0]-'0'+(b-1)*9);
    else
    printf("%d\n",a[0]-'0'-1+(b-1)*9);}
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vi2 = vector<vector<int>>;
using vb = vector<bool>;
using vb2 = vector<vector<bool>>;
using vc = vector<char>;
using vc2 = vector<vector<char>>;
using vs = vector<string>;
using vs2 = vector<vector<string>>;
using pii = pair<int, int>;
using mii = map<int, int>;
const int INF = 1e9;
const ll LINF = 1e18;
#define MP(a,b) make_pair((a),(b))
#define MT(...) make_tuple(__VA_ARGS__)

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)

#define ALL(x) (x).begin(),(x).end()
#define IN(type,a) type a;cin >> a
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define COUT(x) cout << (x) << endl
#define DCOUT(x,n) cout << fixed << setprecision(n) << (x) << endl
int gcd(int x, int y){
    if ((x==1)||(y==1)) return 1;
    if (x>y) {
        if (x%y==0) {
            return y;
        }else{
            return gcd(y, x%y);
        }
    }else{
        if (y%x==0) {
            return x;
        }else{
            return gcd(x, y%x);
        }
    }
}
int main() {
    IN(int, a);
    IN(int, b);
    REPS(i, 1009){
        if ((i*8/100==a) && (i*10/100==b)) {
            COUT(i);
            return 0;
        }
    }
    COUT(-1);
    return 0;
}


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

using namespace std;
#define LL long long

int k,a,b,x=0;

int main() {
	cin>>k>>a>>b;
	for(int i=a;i<=b;i++)if(i%k==0)x++;
	cout<<(x==0?"NG":"OK")<<endl;
	return 0;
}



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

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner in=new Scanner(System.in);
		int n;
		n=in.nextInt();
		int [] a = new int[n];
		int [] b = new int[8];
		for(int i=0;i<n;i++)
		{
			a[i]=in.nextInt();
		}
		int min=0,max=0;
		for(int i=0;i<n;i++)
		{
			if(a[i]>=1&&a[i]<=399) b[0]=1;
			else if(a[i]>=400&&a[i]<=799) b[1]=1;
			else if(a[i]>=800&&a[i]<=1199) b[2]=1;
			else if(a[i]>=1200&&a[i]<=1599) b[3]=1;
			else if(a[i]>=1600&&a[i]<=1999) b[4]=1;
			else if(a[i]>=2000&&a[i]<=2399) b[5]=1;
			else if(a[i]>=2400&&a[i]<=2799) b[6]=1;
			else if(a[i]>=2800&&a[i]<=3199) b[7]=1;
			else { max+=1;}
		}
		for(int j=0;j<8;j++)
		{ if(b[j]==1)min++;}
		max+=min;
		if(min==0)min=1;
		System.out.println(min+" "+max);
		
		
		
   
	}

	

	

}

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

int main()
{
  double n, m, d;
  cin >> n >> m >> d;

  if(d == 0) printf("%.10lf\n", (m-1)/n);
  else printf("%.10lf\n", 2*(n-d)*(m-1)/(n*n));
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int k;
    cin>>k;
    int a[100010];
    for(int i=0;i<k;i++)
    {
    	cin>>a[i];
	}
	sort(a,a+k);
	cout<<a[k/2]-a[k/2-1];
    return 0;
} 	

Measured memory_bytes: 640
# どんな和が作れるか
N,A = map(int,input().split())
X = [int(x) for x in input().split()]

import numpy as np

dp = np.zeros((N+1,3000),dtype=np.int64) # 枚数、目標数ごとに場合の数
dp[0,0] = 1

for x in X:
  dp[1:,x:] += dp[:-1,:-x].copy()
  
answer = 0
for n in range(1,N+1):
  answer += dp[n,n*A]
  
print(answer)


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

using namespace std;

#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, a, b) for(ll i = (a); i > (b); --i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define mp make_pair
#define bitcnt __builtin_popcount
#define SZ(x) ((ll)(x).size())
#define All(a) (a).begin(), (a).end()
template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
#define CINT(...)                                                              \
    int __VA_ARGS__;                                                           \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    ll __VA_ARGS__;                                                            \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Yes(a) cout << (a ? "Yes" : "No") << "\n"
#define YES(a) cout << (a ? "YES" : "NO") << "\n"
#define Printv(v)                                                              \
    {                                                                          \
        FOREACH(x, v) { cout << x << " "; }                                    \
        cout << "\n";                                                          \
    }

typedef long long ll;
typedef unsigned long long ul;
typedef vector<ll> VL;
typedef pair<ll, ll> PL;
typedef priority_queue<ll> PQ;
typedef priority_queue<ll, VL, greater<ll>> PQG;

const int INF = 1e9;
const int MOD = 1e9 + 7;
// const int MOD = 998244353;
const ll LINF = 1e18;
const ll dx[] = {1, -1, 0, 0};
const ll dy[] = {0, 0, 1, -1};

ll N, Q;
VL s;

int main() {
    cin >> N;
    REP(i, N) s.emplace_back(IN());
    ll res = 0;
    FOR(d, 1, N) {
        ll sum = 0;
        ll l = 0, r = N - 1;
        if((N - 1) % d) {
            while(l + d < N - 1) {
                sum += s[l] + s[r];
                res = max(sum, res);
                l += d;
                r -= d;
            }
        } else {
            while(l < r) {
                sum += s[l] + s[r];
                res = max(sum, res);
                l += d;
                r -= d;
            }
        }
    }
    cout << res << "\n";
    return 0;
}

Measured memory_bytes: 1528
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define All(a) (a).begin(),(a).end()

void solve(){
  int n,m;
  string s;
  cin >>s;
  auto a=s.end()-1;
  if(*a=='s')s+="es";

  else s+="s";
  cout << s<<endl;

}
int main(){
  /*
  int q;
  scanf("%d",&q);
  while(--q)solve();
  */
  solve();

  return 0;
}

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

int main(){
    int N;
    cin >> N;
    vector<vector<int>> C(N, vector<int>(N));
    long long minCost = 0;
    for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++){
            cin >> C[i][j];
        }
    }
    for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++){
            minCost += min(C[i][j], C[j][i]);
        }
    }
    cout << minCost/2LL << endl;
}


Measured memory_bytes: 3196
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007, INF=mod*mod*3LL;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll n, k;
    cin >> n >> k;
    ll t[n], d[n];
    multiset<pair<ll, int> > ms, tmp;
    set<ll> s, se;
    for(int i=0;i<n;i++){
    	cin >> t[i] >> d[i];
    	s.insert(t[i]);
    	ms.insert({d[i], i});
    }
    ll sum = 0;
    multiset<ll> a;
    for(auto itr = ms.end() ; itr != ms.begin();){
    	itr--;
    	if(se.count(t[itr->second]) || se.size() == k){
    		if(se.count(t[itr->second]) == 0) tmp.insert(*itr);
    		continue;
    	}
    	else{
    		se.insert(t[itr->second]);
    		tmp.insert(*itr);
    		a.insert(itr->first);
    		sum += itr->first;
    	}
    }
    for(auto& i: tmp) ms.erase(ms.find(i));
    ll maki = se.size();
    sum += maki * maki;
    ll idx = maki;
    tmp.clear();
    for(auto itr = ms.end();itr != ms.begin() && idx < k;idx++){
    	itr--;
    	sum += itr->first;
    	tmp.insert(*itr);
    }
    for(auto& i: tmp) ms.erase(ms.find(i));
    for(auto itr = ms.end();itr != ms.begin();){
    	itr--;
    	ll num = maki - 1;
    	if(itr->first + num * num - maki * maki > *(a.begin())){
    		num = itr->first + num * num - maki * maki - *(a.begin());
    		sum += num;
    		a.erase(a.begin());
    		maki--;
    	}
    }
    cout << sum << endl;
    return 0;
}


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

int relu(int x){
    if(x >= 0){
        return x;
    }else{
        return 0;
    }
}

int main(){
    int A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;
    int costs[3];
    costs[0] = X*A+Y*B;
    costs[1] = X*2*C+relu(Y-X)*B;
    costs[2] = relu(X-Y)*A+Y*2*C;
    sort(costs, costs+3);
    cout << costs[0];
    return EXIT_SUCCESS;
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>
using namespace std;
namespace adaptor = boost::adaptors;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
typedef long long ll;

void Main()
{
	int N, Y;
  	cin >> N >> Y;
    int A = Y/1000;
    // x + y + z = N
	// 10 * x + 5 * y + z = A
	// z%5 = A%5
	// B = (A-z)/5 とおくと
    // 2 * x + y = B
	
    // z: A%5 から max(A,N) まで 5 刻みに探索
    int z = A%5;
    int B = (A-z)/5;
    while(z<=max(A,N)) {
		int x = B-N+z;
        int y = -B+2*N-2*z;
        if(x>=0 && y >= 0){
			//OK
            cout << x << " " << y << " " << z << endl;
            return;
        }
				
        // z : 次の探索へ
        z += 5;
        B--;
	}

	cout << "-1 -1 -1" << endl;
	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; i++)
#define RFOR(i, a, n) for (ll i = (ll)n - 1; i >= (ll)a; i--)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) RFOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define bra(first, second) '(' << first << ',' << second << ')'
constexpr ll MOD = 1000000007;
//constexpr ll MOD = 998244353;
ll INF = 1001001001001001001;
long double EPS = 1e-9;
long double PI = 3.141592653589793238;
template <typename T>
void remove(std::vector<T> &vector, unsigned int index)
{
   vector.erase(vector.begin() + index);
}

using Graph = vector<vector<tuple<ll, ll, ll>>>;

// MOD確認

int main(){
   ll L,R,D;
   cin >> L >> R >> D;
   cout << R / D - (L - 1) / D << endl;
}

Measured memory_bytes: 3616
lst_1 = input().split()

x_1 = int(lst_1[0])
y_1 = int(lst_1[1])
x_2 = int(lst_1[2])
y_2 = int(lst_1[3])

x_3 = x_2 - (y_2 - y_1)
y_3 = y_2 + (x_2 - x_1)
x_4 = x_3 - (x_2 - x_1)
y_4 = y_3 - (y_2 - y_1)

print("{} {} {} {}".format(x_3, y_3, x_4, y_4))

Measured memory_bytes: 3064
"""
                            pppppppppppppppppppp
                         ppppp  ppppppppppppppppppp
                      ppppppp    ppppppppppppppppppppp
                      pppppppp  pppppppppppppppppppppp
                      pppppppppppppppppppppppppppppppp
                              pppppppppppppppppppppppp
       ppppppppppppppppppppppppppppppppppppppppppppppp  pppppppppppppppppppp
      pppppppppppppppppppppppppppppppppppppppppppppppp  ppppppppppppppppppppp
     ppppppppppppppppppppppppppppppppppppppppppppppppp  pppppppppppppppppppppp
    ppppppppppppppppppppppppppppppppppppppppppppppp    pppppppppppppppppppppppp
   pppppppppppppppppppppppppppppppppppppppppppppp     pppppppppppppppppppppppppp
  ppppppppppppppppppppppppppppppppppppppppppppp      pppppppppppppppppppppppppppp
  pppppppppppppppppppppppppppppppp               pppppppppppppppppppppppppppppppp
  pppppppppppppppppppppppppppp     pppppppppppppppppppppppppppppppppppppppppppppp
  ppppppppppppppppppppppppppp    pppppppppppppppppppppppppppppppppppppppppppppppp
    pppppppppppppppppppppppp  pppppppppppppppppppppppppppppppppppppppppppppppppp
     ppppppppppppppppppppppp  ppppppppppppppppppppppppppppppppppppppppppppppppp
      pppppppppppppppppppppp  ppppppppppppppppppppppppppppppppppppppppppppppp
       ppppppppppppppppppppp  ppppppppppppppppppppppppppppppppppppppppppppp
                              pppppppppppppppppppppppp
                              pppppppppppppppppppppppppppppppp
                              pppppppppppppppppppppp  pppppppp
                              ppppppppppppppppppppp    ppppppp
                                 ppppppppppppppppppp  ppppp
                                    pppppppppppppppppppp
"""


import sys
from functools import lru_cache, cmp_to_key
from collections import defaultdict as dd, deque, Counter as C
from bisect import bisect_left as bl, bisect_right as br, bisect
from heapq import heapify, heappop, heappush
from math import ceil, log, floor, sqrt
mod = pow(10, 9) + 7
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(var, end="\n"): sys.stdout.write(str(var)+end)
def outa(*var, end="\n"): sys.stdout.write(' '.join(map(str, var)) + end)
def L(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]


n = int(data())
a = L()
b = L()
i = 0
temp = 0
r = True
for j in range(n):
    if temp != a[j]:
        i = 0
    if a[j] == b[j]:
        while i < n:
            if a[i] != a[j] and b[i] != a[j]:
                b[i], b[j] = b[j], b[i]
                break
            i += 1
        if a[j] == b[j]:
            out("No")
            exit()
    temp = a[j]
out("Yes")
outa(*b)


Measured memory_bytes: 125720
open Batteries
open Printf
let () =
  let s = Scanf.scanf "%s " (fun a -> a) in
  
  let i18n str =
    let len = String.length str in
    if len < 3 then failwith "too small" else
    let fst = String.slice ~last:1 str in
    let mid = string_of_int (len-2) in
    let lst = String.slice ~first:(len-1) str in
    fst ^ mid ^ lst
  in

  Printf.printf "%s\n" @@
  i18n s


Measured memory_bytes: 3072
#include <iostream>
#include <cstdio>
#include <map>
using namespace std;

int main() {
    map<double, int> players[3];
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 8; j++) {
            int num;
            double time;
            cin >> num >> time;
            players[i].insert(make_pair(time, num));
        }
    }
    map<double, int> notWinPlayers;
    for (int i = 0; i < 3; i++) {
        map<double, int>::iterator it = players[i].begin();
        printf("%d %.2f\n", it->second, it->first);
        it++;
        printf("%d %.2f\n", it->second, it->first);
        it++;
        for ( ; it != players[i].end(); it++) {
            notWinPlayers.insert(make_pair(it->first, it->second));
        }
    }
    int count = 0;
    for (map<double, int>::iterator it = notWinPlayers.begin(); count < 2; it++, count++) {
        printf("%d %.2f\n", it->second, it->first);
    }
}

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

using Int = long long;
using ll = long long;

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

template<typename T> void drop(T x){cout<<x<<endl;exit(0);};

template<typename T, bool directed>
struct Dinic{
  struct edge{
    int to;
    T cap;
    int rev;
    edge(){}
    edge(int to, T cap, int rev):to(to), cap(cap), rev(rev){}
  };

  vector<vector<edge> > G;
  vector<int> level, iter;

  Dinic(){}
  Dinic(int n):G(n), level(n), iter(n){}

  int add_edge(int from, int to, T cap){
    G[from].emplace_back(to, cap, G[to].size());
    G[to].emplace_back(from, directed?0:cap, G[from].size() - 1);
    return G[to].back().rev;
  }

  void bfs(int s){
    fill(level.begin(), level.end(), -1);
    queue<int> que;

    level[s] = 0;
    que.emplace(s);

    while(!que.empty()){
      int v = que.front(); que.pop();
      for(int i=0;i<(int)G[v].size();i++){
        edge &e = G[v][i];
        if(e.cap > 0 && level[e.to] < 0){
          level[e.to] = level[v] + 1;
          que.emplace(e.to);
        }
      }

    }
  }

  T dfs(int v, int t, T f){
    if(v == t) return f;
    for(int &i=iter[v];i<(int)G[v].size();i++){
      edge &e = G[v][i];
      if(e.cap > 0 && level[v] < level[e.to]){
        T d = dfs(e.to, t, min(f, e.cap));
        if(d == 0) continue;
        e.cap -= d;
        G[e.to][e.rev].cap += d;
        return d;
      }
    }
    return 0;
  }

  T flow(int s, int t, T lim){
    T fl = 0;
    while(1){
      bfs(s);
      if(level[t] < 0 || lim == 0) break;
      fill(iter.begin(), iter.end(), 0);

      while(1){
        T f = dfs(s, t, lim);
        if(f == 0) break;
        fl += f;
        lim -= f;
      }
    }
    return fl;
  }

  T flow(int s, int t){
    return flow(s, t, numeric_limits<T>::max()/2);
  }
};

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

  int n,m,s,t,u,v;
  cin>>n>>m>>s>>t>>u>>v;
  s--;t--;u--;v--;

  Dinic<int, false> G(n+2),H(n+2);
  int S=n,T=n+1;
  for(int i=0;i<m;i++){
    int x,y;
    cin>>x>>y;
    x--;y--;
    G.add_edge(x,y,1);
    H.add_edge(x,y,1);
  }
  const int INF = 1e8;
  G.add_edge(S,s,INF);
  G.add_edge(S,u,INF);
  G.add_edge(t,T,INF);
  G.add_edge(v,T,INF);

  H.add_edge(S,s,INF);
  H.add_edge(S,v,INF);
  H.add_edge(t,T,INF);
  H.add_edge(u,T,INF);

  cout<<min(G.flow(S,T),H.flow(S,T))<<endl;
  return 0;
}



Measured memory_bytes: 16160
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
p = 10**9+7

n = int(input())
a = list( map(int, input().split()))
count = [0]*n

for i in range(n+1):
    count[a[i]-1] += 1
    if count[a[i]-1] == 2:
        right = i
        left = a.index(a[i])
        break

def nCr_mod_p(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

p = 10 ** 9 + 7
N = 10 ** 5  # N は必要分だけ用意する
fact = [1, 1]  # fact[n] = (n! mod p), 0! = 1! = 1
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p), 0! = 1! = 1
inv = [0, 1]  # inv[n] = n^(-1) mod p, 0! = 1　だけど便宜上inv[0]=0にしてる

for i in range(2, N + 2):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

for i in range(1,n+2):
    ans = nCr_mod_p(n+1,i,p) - nCr_mod_p(n-right+left,i-1,p)
    print(ans%p)


Measured memory_bytes: 22896
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using vec=vector<ll>;
using mat=vector<vec>;
#define For(i,a,b) for(ll i=a;i<b;i++)
#define bFor(i,a,b) for(ll i=a;i>=b;i--)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N-1,0)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define mod 1000000007
#define endl "\n"
#define output(v) do{bool f=0;for(auto i:v){cout<<(f?" ":"")<<i;f=1;}cout<<endl;}while(0)
using datas=pair<ll,ll>;
using tdata=pair<ll,datas>;

long mmid(long a,long b,long c){return a<b?(b<c?b:max(a,c)):(b>c?b:min(a,c));}

ll lpow(ll a,ll b){
  ll res=1;
  rep(i,b){
    res*=a;
  }
  cout<<res;
}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

ll modncr(ll n,ll r){
  ll plus=1;
  rep(i,r){
    plus=(plus*(n-i))%mod;
    plus=moddevide(plus,i+1);
  }
  return plus;
}

ll modncrlistp[200000],modncrlistm[200000];

ll modncrs(ll n,ll r){
  ll i,j;
  if(modncrlistp[n]==0){
    for(i=n;i>=0;i--){
      if(modncrlistp[i])break;
    }
    if(i<0){
      modncrlistp[0]=1;
      rep1(i,n+1){
        modncrlistp[i]=(modncrlistp[i-1]*i)%mod;
      }
    }else{
      For(j,i+1,n+1){
        modncrlistp[j]=(modncrlistp[j-1]*j)%mod;
      }
    }
  }
  if(modncrlistm[n]==0){
    for(i=n;i>=0;i--){
      if(modncrlistm[i])break;
    }
    if(i<0){
      modncrlistm[0]=1;
      rep1(i,n+1){
        modncrlistm[i]=(modncrlistm[i-1]*modinv(i))%mod;
      }
    }else{
      For(j,i+1,n+1)modncrlistm[j]=(modncrlistm[j-1]*modinv(j))%mod;
    }
  }
  return (((modncrlistp[n]*modncrlistm[r])%mod)*modncrlistm[n-r])%mod;
}

ll gcd(ll a,ll b){if(!b)return a;return (a%b==0)?b:gcd(b,a%b);}

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}

vec eratosthenes(ll N){
  vec ch(N+1,1),p;
  ch[0]=ch[1]=0;
  rep(i,N+1){
    if(ch[i]){
      p.push_back(i);
      for(ll j=2;i*j<=N;j++){
        ch[i*j]=0;
      }
    }
  }
  return ch;
}
int main(){
  ll N,K,Q,x;
  cin>>N>>K>>Q;
  vec v(N,0);
  rep(i,Q){
    cin>>x;x--;
    v[x]++;
  }
  rep(i,N){
    v[i]=K+v[i]-Q;
    if(v[i]>0){
      cout<<"Yes"<<endl;
    }else{
      cout<<"No"<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1536
require 'prime'
loop {
	n = n0 = gets.to_i
	break if n == 0
	a = []	
	Prime.each(Math.sqrt(n).to_i){|q|
		k = 0
		while n % q == 0
			n /= q
			k += 1
		end
		a << [q, k] if k > 0
	}
	a << [n, 1] if n > 1
	s = a.map{|q, k| (q**(k+1) - 1) / (q - 1)}.inject(1, :*) 
	puts s < 2 * n0 ? 'deficient number' :
		 s > 2 * n0 ? 'abundant number' :
		              'perfect number'
}

Measured memory_bytes: 6256
N = int(input())
edge = [[]*N for _ in range(N)]

for _ in range(N-1):
    go,to = map(int,input().split())
    go -= 1
    to -= 1
    edge[go].append(to)
    edge[to].append(go)
    
from collections import deque
que = deque(maxlen=N)
que.append([0,0])
dist0 = [None]*N
distn = [None]*N
while(que):
    v = que.popleft()
    c = v[0]
    d = v[1]
    for i in edge[c]:
        if dist0[i] is None:
            dist0[i] = d + 1
            que.append([i,d+1])
que.append([N-1,0])
while(que):
    v = que.popleft()
    c = v[0]
    d = v[1]
    for i in edge[c]:
        if distn[i] is None:
            distn[i] = d + 1
            que.append([i,d+1])
w = b = 0
for d1,dn in zip(dist0,distn):
    if d1<=dn:
        b += 1
    else:
        w += 1
print('Fennec' if b-w > 0 else 'Snuke')

Measured memory_bytes: 29428
//#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"

#define rep(i,n) for(ll (i)=0;(i)<(ll)(n);(i)++)
#define all(x) (x).begin(),(x).end()

#define MOD 1000000007LL
#define INF (1LL<<60LL)
#define int long long
#define MAX_N (100001)
typedef long long ll;

using namespace std;

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, a;
	cin >> n >> a;
	cout << n * n - a << endl;
}

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

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout.precision(12);
    cout.setf(ios_base::fixed, ios_base::floatfield);
    
    string s;
    int n, k;
    cin >> n >> k;
    cin >> s;
    s[k-1] += -'A'+'a';
    
    cout << s << endl;
    
    return 0;
}

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

using namespace std;

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

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

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

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

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

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

const ll mod = 1e9 + 7;
const ll IMF = 1e18;
const double PI = 3.14159265358979323846;


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



ll n;
ll x[100010][3];
ll dp[100010][3];

int main(){
        cin >> n;
        for(int i = 1; i <= n; i++)
                rep(j,3) cin >> x[i][j];

        rep(i,3) dp[1][i] = x[1][i];

        for(int i = 2; i <= n; i++){
                for(int j = 0; j < 3; j++){
                        for(int k = 0; k < 3; k++){
                                if(j == k) continue;
                                dp[i][j] = max(dp[i][j], dp[i-1][k] + x[i][j]);
                        }
                }
        }

        ll ans = 0;
        rep(i,3) ans = max(ans, dp[n][i]);

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























































Measured memory_bytes: 4992
#include "iostream"
using namespace std;
int main(){
	int a, b;
	cin >> a >> b;
	if (a == b){
		cout << "a == b" << endl;
	}else	if (a < b){
		cout << "a < b" << endl;
	}else	if (a > b){
		cout << "a > b" << endl;
	}
	return 0;
}

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

using namespace std;
typedef long long LL;
typedef pair<int,int> pii;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second

#ifdef OJ
#define debug(x)  do{cerr<<#x<<": "<<x<<"\n";}while(0)
#define debugv(x) do{cerr<<#x<<": ";for(auto&e: (x))cerr<<e<<" ";cerr<<"\n";}while(0)
#else
#define debug(x)
#define debugv(x)
#endif

#define all(x) (x).begin(), (x).end()
#define rsort(x) sort((x).rbegin(), (x).rend())
#define sz(x) ((int)x.size())
#define fori(i, n) for (int i = 0; i < (int)(n); ++i)
#define ford(i, n, e) for (int i = (int)(n); i >= (int)(e); --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
template<typename T> bool mmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool mmin(T &m, const T q) { if (m > q) {m = q; return true;} else return false; }
#define RETURN(x) do{cout << (x) << '\n'; return ;}while(0)

const int MOD = 1e9+7;
const int MAXN = 2e6+3;
const int INF = 1e9;

int solve() {
    int l,r,d; cin >> l >> r >> d;
    int c = 0;
    fore(i,l,r) c += (i%d) == 0;
    cout << c << '\n';
    return 0;
} 

int main(int argc, char **argv) {
#ifdef OJ
    freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);

    int ntest = 1;
    //cin >> ntest;
    fori(test, ntest) {
        solve();
    }

    return 0;
}



Measured memory_bytes: 3568
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

typedef long long ll;

int N;
int gap[50 + 10];
int cnt[13];

int calc(int bit) {
	int pos[24] = {};//真ん中は12で
	pos[12]++;//高橋くん
	for (int i = 0; i < 12; i++) {
		if (cnt[i + 1] == 2) {
			pos[12 - (i + 1)]++;
			pos[(12 + (i + 1)) % 24]++;
		}
		else if (cnt[i + 1] == 1) {
			if ((bit >> i) & 1)pos[12 - (i + 1)]++;
			else pos[(12 + (i + 1)) % 24]++;
		}
	}
	int ret = 114514;
	for (int i = 0; i < 24; i++) {
		if (pos[i] == 0)continue;
		int d = 114514;
		if (pos[i] >= 2)d = 0;
		else if(pos[i] == 1){
			for (int j = 0; j < 24; j++) {
				if (pos[j] && j != i) d = min(d, (24 + j - i) % 24);
			}
		}
		ret = min(ret, d);
	}
	return ret;
}

int main() {
	cin >> N;
	for (int i = 0; i < N; i++)cin >> gap[i], cnt[gap[i]]++;;

	int ans = 0;

	if (cnt[0] >= 1) {
		cout << 0 << endl;
		return 0;
	}
	
	for(int i = 0; i <= 12; i++)
		if (cnt[i] >= 3) {
			cout << 0 << endl;
			return 0;
		}

	for (int bit = 0; bit < (1 << 12); bit++) {
		ans = max(ans, calc(bit));
	}

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

Measured memory_bytes: 504
#include <bits/stdc++.h>
#define int long long
using pii=std::pair<int,int>;
using namespace std;

int n, d[2];
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    int cur = 0;
    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < 2; j++)
            cin >> d[j];
        if(d[0] != d[1])
            cur = 0;
        else
            cur++;
        if(cur > 2)
        {
            cout << "Yes\n";
            return 0;
        }
    }
    cout << "No\n";
    return 0;
}

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

long long LCS[3001][3001] ={};

int main() {
  string s, t; cin >> s; cin >> t;
  for (int i = 0; i < s.size()+1; i++) {
    for (int j = 0; j < t.size()+1; j++) {
      if (i == 0 || j == 0) {
        LCS[i][j] = 0;
      } else if (s[i-1] == t[j-1]) {
        LCS[i][j] = LCS[i-1][j-1] + 1;
      } else {
        LCS[i][j] = max(LCS[i][j-1], LCS[i-1][j]); 
      }
    }
  }
  
  string result = "";
  int i = s.size(); int j = t.size();
  while (i > 0 && j > 0) {
    if (LCS[i][j] == LCS[i][j-1]) {
      j--;
    } else if (LCS[i][j] == LCS[i-1][j]) {
      i--;
    } else {
      result = s[i-1] + result;
      i--; j--;
    }
  }
  cout << result << endl;
  return 0;
}

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

//#define int long long
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

/* cpp template {{{ */

/* short */
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define X real()
#define Y imag()

/* REPmacro */
#define REPS(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define rep(i, n) REPS(i, 0, n)
#define REP0(i,n) for (ll i = 0; i <= (ll)(n); ++i)
#define REP1(i,n) for (ll i = 1; i <= (ll)(n); ++i)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (ll i = (a); i >= (ll)(n); --i)
#define DEP(i, n) DEPS(i, n, 0)
#define EACH(i, n) for (auto&& i : n)

/* debug */
#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

/* alias */
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using D = double;
using P = complex<D>;
using vs = vector<string>;
template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;
const D EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

/* func */
inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
inline int in() {int x; cin >> x; return x;}
inline ll IN() {ll x; cin >> x; return x;}
inline vs split(const string& t, char c) {vs v; stringstream s(t); string b; while(getline(s, b, c)) v.eb(b); return v;}
template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
template <typename T, typename S> inline void print(const pair<T, S>& p) {cout << p.first << " " << p.second << endl;}
template <typename T> inline void print(const T& x) {cout << x << '\n';}
template <typename T, typename S> inline void print(const vector<pair<T, S>>& v) {for (auto&& p : v) print(p);}
template <typename T> inline void print(const vector<T>& v, string s = " ") {rep(i, v.size()) cout << v[i] << (i != (ll)v.size() - 1 ? s : "\n");}
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
  for(T& x: vec) is >> x;
  //for(int i=0; i<vec.size(); i++) is >> x[i]; とかでもいいです。
  return is;
}
template<typename T>
ostream& operator << (ostream& os, vector<T>& vec){
  for(int i=0; i<vec.size(); i++){
    os << vec[i] << ( i+1 == vec.size() ? "" : " " );
  }
  return os;
}
/* }}} */
signed main() 
{
  int n,m;
  cin>>n>>m;
  int a[n],b[n],c[m],d[m];
  rep(i,n)
  {
    cin>>a[i]>>b[i];
  }
  rep(i,m)
  {
    cin>>c[i]>>d[i];
  }
  rep(i,n)
  {
    int mindis=abs(a[i]-c[0])+abs(b[i]-d[0]),point=1;
    rep(j,m)
    {
      int tmpdis=abs(a[i]-c[j])+abs(b[i]-d[j]);
      if(mindis>tmpdis)
      {
        mindis=tmpdis;
        point=j+1;
      }
    }
    print(point);
  }

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define Fst first
#define Snd second
#define RG register
#define mp make_pair
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long LL;
typedef long double LD;
typedef unsigned int UI;
typedef unsigned long long ULL;
template<typename T> inline void read(T& x) {
	char c = getchar();
	bool f = false;
	for (x = 0; !isdigit(c); c = getchar()) {
		if (c == '-') {
			f = true;
		}
	}
	for (; isdigit(c); c = getchar()) {
		x = x * 10 + c - '0';
	}
	if (f) {
		x = -x;
	}
}
template<typename T, typename... U> inline void read(T& x, U& ... y) {
	read(x), read(y...);
}
const int N=1e5+10;
int n,p;
int head[N],In[N];
LL F[N],G[N],sum[N],A[N];
bool YES[N];
struct Edge {
  int to,last;
  Edge () {}
  Edge (int a,int b) :to(a),last(b) {}
}edge[N<<1];
void ADD(int a,int b) {
  edge[++p]=Edge(b,head[a]); head[a]=p;
  edge[++p]=Edge(a,head[b]); head[b]=p;
}
void DFS(int u,int f) {
  if(In[u]==1) {
    F[u]=A[u];
    return;
  }
  int g=0; LL a=0,b=0;
  for(int i=head[u];i;i=edge[i].last) {
    int v=edge[i].to;
    if(v!=f) {
      ++g;
      DFS(v,u);
      sum[u]+=F[v];
      LL t=min(a,F[v]);
      a+=F[v]-t; b+=t;
    }
  }
  if(g==1) {
    YES[u]=true;
    if(sum[u]!=A[u]) puts("NO"),exit(0);
  }
  if(sum[u]>=A[u]&&sum[u]<=A[u]*2&&sum[u]-A[u]<=b) F[u]=A[u]*2-sum[u];
  else puts("NO"),exit(0);
}
void SFD(int u,int f) {
  if(In[u]==1) return;
  if((sum[u]+G[f])==A[u]*2ll) puts("YES"),exit(0);
  for(int i=head[u];i;i=edge[i].last) {
    int v=edge[i].to;
    if(v!=f) {
      if(YES[u]) {
        if(G[f]==A[u]) G[u]=G[f],SFD(v,u);
      }
      else {
        LL t=G[f]+sum[u]-F[v];
        if(t>=A[u]&&t<=A[u]*2) G[u]=A[u]*2-t,SFD(v,u);
      }
    }
  }
}
//#define rua
int main() {
//	ios::sync_with_stdio(false);
#ifdef rua
	freopen("GG.in","r",stdin);
#endif
  read(n);
  for(int i=1;i<=n;++i) read(A[i]);
  if(n==1) return puts("NO"),0;
  if(n==2) return puts(A[1]==A[2]?"YES":"NO"),0;
  for(int i=1;i<n;++i) {
    int u,v; read(u,v);
    ADD(u,v);
    ++In[u]; ++In[v];
  }
  int root=1;
  for(int i=1;i<=n;++i) if(In[i]!=1) root=i;
  DFS(root,0); SFD(root,0);
  puts("NO");
  return 0;
}


Measured memory_bytes: 12928
S = input()
ans = 0
for k in range(2**(len(S)-1)):
    f = -1
    t = []
    for l in range(len(S)):
        if (k>>l)&1 == 1:
            t.append(S[f+1:l+1])
            f = l
    t.append(S[f+1:])
    for e in t:
        ans += int(e)
print(ans)


Measured memory_bytes: 40560
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <queue>
#include <deque>
using namespace std;



int main()
{
	
	int n;
	cin >> n;
	int x[101], y[101], h[101];
	for (int i = 0; i < n; i++) {
		cin >> x[i] >> y[i] >> h[i];
		if (h[i] > 0) {
			swap(x[i], x[0]);
			swap(y[i], y[0]);
			swap(h[i], h[0]);
		}
	}

	for (int i = 0; i <= 100; i++) {
		for (int j = 0; j <= 100; j++) {
			bool flag = true;
			int height = h[0] + abs(i - y[0]) + abs(j - x[0]);
			for (int k = 1; k < n; k++) {
				int tempHeight = max(height - abs(i - y[k]) - abs(j - x[k]),0);
				if (tempHeight != h[k]) {
					flag = false;
					break;
				}
				
			}
			if (flag) {
				cout << j << " "<< i << " "<< height << endl;
				return 0;
			}
		}
	}
	return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define REPR(i,n) for (ll i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (ll i = m; i < n; ++i)
#define FORR(i,m,n) for (ll i = n-1; i >= m; --i)
#define FORE(x,xs) for (const auto& x : xs)
#define ALL(v) v.begin(), v.end()
#define CHMIN(x,y) x = min(x, y)
#define CHMAX(x,y) x = max(x, y)

const int MAX = 1010;

int N, M, A[MAX];

string solve() {
    ll t = 0;
    REP (i, N) t += A[i];
    int m = 0;
    REP (i, N) if (4 * M * A[i] >= t) {
        m++;
    }
    if (m >= M) return "Yes";
    return "No";
}

int main() {
    cin >> N >> M;
    REP (i, N) cin >> A[i];
    cout << solve() << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FAST_IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
typedef long long ll;
using namespace std;

int solution(){
    int n; cin>>n;
    vector<int> h(n);
    for(int i = 0;i < n;i++) cin>>h[i];
    
    vector<int> dp(n, 0);
    dp[0] = 0;
    dp[1] = abs(h[1] - h[0]);
    for(int i = 2;i < n;i++)
        dp[i] = min( dp[i-1] + abs(h[i]-h[i-1]), dp[i-2] + abs(h[i]-h[i-2]) );
    
    cout<<dp[n-1]<<"\n"; 
    return 0;
}

int main(){
    FAST_IO;
    int T = 1; //cin>>T;
    while(T--)
        solution();
    return 0;
}

Measured memory_bytes: 3952
n,q = map(int,input().split())
r = [[] for i in range(n)]
v = [0 for i in range(n)]

for i in range(n-1):
    a,b = map(int,input().split())
    r[a-1].append(b-1)

for i in range(q):
    p,x = map(int,input().split())
    v[p-1] += x


for i in range(n):

    for y in r[i]:
        v[y] += v[i]

print(" ".join(map(str,v)))

Measured memory_bytes: 58976
/*
    Author:zeke
    
    pass System Test!
    GET AC!!
*/
#include <iostream>
#include <queue>
#include <vector>
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
#include <iomanip>
#include <utility>
#include <stack>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rep3(var, min, max) for (ll (var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll (var) = (max) - 1; (var) + 1 > (min); --(var))
#define Mp(a,b) make_pair((a),(b))
#define F first
#define S second
#define Icin(s) ll (s);cin>>(s);
#define Scin(s) ll (s);cin>>(s);
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll MOD = 1e9 + 7;
ll INF =1e18;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll x,y;
    cin>>x>>y;
    if(abs(x-y)<=1){
        cout<<"Brown"<<endl;
    }else{
        cout<<"Alice"<<endl;
    }
}


Measured memory_bytes: 256
import itertools
L,R = map(int,input().split())

l = L//2019
r = R//2019

if((r-l >= 1)or(L%2019 == 0)or(R%2019 == 0)):
  ans = 0
  
else:
 A = []
 ans = 2018
 judge = 0
 for i in range(L,R+1):
    i = i%2019
    if(i%673 == 0): judge += 673
    if(i%3 == 0): judge += 3 
    A.append(i)

 if(judge == 673+3): #3, 673(mod 2019) あり
   ans = 0
 else: #len(A) <673 (なぜならば0~672 or 673 ~ 1346 or ...)
   A_comb = list(itertools.combinations(A,2))
   for i in range(len(A_comb)):
     tmp = list(A_comb[i])
     ans = min(ans,(tmp[0]*tmp[1])%2019)
 
print(ans)

Measured memory_bytes: 148304
def main() -> None:
    num = [int(input()) for _ in range(5)]
    ans = 0
    m = [0]
    for i in num:
        if i % 10:
            ans += i + 10 - i % 10
            m.append(10 - i % 10)
        else:
            ans += i
    print(ans - max(m))


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940