akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define itn int

int main(void){
    string s,t = "AKIHABARA";
    cin >> s;
    
    if(s.size() > t.size())cout << "NO";
    else if(s == t)cout << "YES";
    else {
        if(s.size() == 5){
            if(s == "KIHBR")cout << "YES";
            else cout << "NO";
        } else if(s.size() == 6){
            if(s == "AKIHBR" || s == "KIHABR" || s == "KIHBAR" || s == "KIHBRA")cout << "YES";
            else cout << "NO";
        } else if(s.size() == 7){
            if(s == "AKIHABR" || s == "AKIHBAR" || s == "AKIHBRA" || s == "KIHABAR" || s == "KIHABRA" || s == "KIHBARA")cout << "YES";
            else cout << "NO";
        } else {
            if(s == "AKIHABAR" || s == "AKIHBARA" || s == "KIHABARA")cout << "YES";
            else cout << "NO";
        }
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<stdio.h>
#include<queue>
#include<stack>

using namespace std;

typedef long long ll;
typedef double db;
typedef vector<int> vint;
typedef vector<ll> vll;

int main(){
    int a,b,n;
    cin>>n;
    vector<pair<int, int> > pairs(n);

    for (int i = 0; i < n; i++) {
        cin>>a>>b;
        pairs[i] = make_pair(a, b);
    }
    sort(pairs.begin(), pairs.end());
    cout<<pairs[n-1].first+pairs[n-1].second<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
string s;
bool flag=false;

int main()
{
	cin>>s;
	if(s[0]=='A'&&s[1]=='C')flag=true;
	if(s[1]=='A'&&s[2]=='C')flag=true;
	if(s[2]=='A'&&s[3]=='C')flag=true;
	if(s[3]=='A'&&s[4]=='C')flag=true;
	if(flag==true)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,H[101];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(i,N) cin>>H[i];
	int ret=0;
	for(i=100;i>=1;i--) {
		FOR(j,N) {
			if(H[j] && H[j+1]==0) ret++;
			if(H[j]) H[j]--;
		}
	}
	cout<<ret<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


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

using namespace std;
#define int int64_t

int32_t main() {
    int ans = 0, n;
    cin >> n;
    vector<int> a(n);
    map<int, int> counter;
    for(int i = 0; i < n; i++) {
        cin >> a[i];
        counter[a[i]]++;
    }
    for(auto i: counter)
        ans += i.second * (i.second - 1) / 2;
    for(int i: a)
        cout << ans - counter[i] + 1 << '\n';
}


Measured memory_bytes: 11008
#include<iostream>
#include<string>
#include<vector>
#define int long long
using namespace std;
signed main(void){
    string n;
    cin>>n;
    int ans=0;
    for(int i=0;i<n.size();i++)
        ans+=n[i]-'0';
    cout<<(ans%9==0?"Yes":"No")<<endl;
}

Measured memory_bytes: 3752
A = [[0] * 3 for i in range(3)]
for i in range(3):
  A[i][0], A[i][1], A[i][2] = map(int, input().split())

n = int(input())
S = []
for _ in range(n):
  S.append(int(input()))
  
for i in range(3):
  for j in range(3):
    if A[i][j] in S:
      A[i][j] = 0
  
ans = False
for i in range(3):
  if A[i][0] == 0 and A[i][1] == 0 and A[i][2] == 0:
    ans = True
  if A[0][i] == 0 and A[1][i] == 0 and A[2][i] == 0:
    ans = True
    
if A[0][0] == 0 and A[1][1] == 0 and A[2][2] == 0:
  ans = True
if A[0][2] == 0 and A[1][1] == 0 and A[0][2] == 0:
  ans = True
  
if ans:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 3064
#include<cstdio> 
#include<cstring>
const int MAX=110;
char maze[MAX][MAX];
int d[MAX][MAX];
int n,m;
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
void dfs(int x,int y,char c)
{
	if(x>=0 && x<n && y>=0 && y<m && maze[x][y]==c && !d[x][y])
		{
			d[x][y]=1;
			for(int i=0;i<4;i++)
			{
				int nx=x+dx[i],ny=y+dy[i];
				dfs(nx,ny,c);
			}
		}
		else
		return;
}
int main()
{
	while(~scanf("%d %d",&n,&m) && (n||m))
	{
		int sum=0;
		memset(d,0,sizeof(d));
		for(int i=0;i<n;i++)
			scanf("%s",maze[i]);
		for(int i=0;i<n;i++)
			for(int j=0;j<m;j++)
				{
				if(!d[i][j])
					{
						char c=maze[i][j];
						dfs(i,j,c),sum++;
					}
				else
				continue;
				}
		printf("%d\n",sum);
	}
	return 0;
 } 

Measured memory_bytes: 1560
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
 
        int n = sc.nextInt();
         
        int min = 2000000000;
        int ans = -2000000000;
        for(int i = 0; i < n; i++) {
            int r = sc.nextInt();
            ans = Math.max(ans, r - min);
            min = Math.min(min, r);
        }
 
        System.out.println(ans);
    }
}


Measured memory_bytes: 100884
//A.cpp
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <math.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b!=0?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
const ll mod=1e9+7;

int main(){
  int n,r;
  cin >> n >> r;
  if(n >= 10){
    printf("%d\n", r);
  }else{
    printf("%d\n", r+(100*(10-n)));
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0;i<(n);++i)
#define per(i, n) for(int i=(n)-1;i>=0;--i)
#define repa(i, n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
using namespace std;
using ll = long long;
const ll MOD = (ll)1e9+7;
//const ll MOD = 998244353;
//const ll MOD = 924844033;
const int INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
const double EPS = 1e-5;
using namespace std;
template<class t>
using vvector = vector<vector<t>>;
template<class t>
using vvvector = vector<vector<vector<t>>>;
template<class t>
using priority_queuer = priority_queue<t, vector<t>, greater<t>>;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}

#ifdef DEBUG
#define OUTPUT(x) (output(x), outendl())
#else
#define OUTPUT(x) (void)0
#endif

ll modpow(ll x, ll b){
	ll res = 1;
	while(b){
		if(b&1)res = res * x % MOD;
		x = x * x % MOD;
		b>>=1;
	}
	return res;
}

ll modinv(ll x){
	return modpow(x, MOD-2);
}

bool was_output = false;
template<class t>
void output(t a){
	if(was_output)cout << " ";
	cout << a;
	was_output = true;
}
void outendl(){
	was_output = false;
	cout << endl;
}

int main(){
	int n;
	cin >> n;
	string s,t;
	cin >> s >> t;
	rep(i,n){
		cout << s[i] << t[i];
	}
	cout << endl;

	return 0;
}


Measured memory_bytes: 256
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
#include<numeric>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using TP = tuple<ll,ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(18);
}
signed main(){
  init_io();
  ll x,p=360;
  cin >> x;
  cout << 360 / gcd(360,x) << endl;
}


Measured memory_bytes: 3636
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<functional>
#include<cmath>
#include<set>
#include<random>
#include<map>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define F first
#define S second
const long long mod = 1000000007;
const long long inf = 1145141919810;
typedef pair<int, int> P;
typedef pair<P, P> PP;
struct edge {int to, cost;};
int dp[200005], a[200005]; vector<P>V;
int L[200005];
signed main() {
	int n; cin >> n; rep(i, n)cin >> a[i]; int s = 0;
	fill(dp, dp + n, mod);
	rep(i, n) {
		V.push_back(P(a[i], i));
	}
	sort(V.begin(), V.end());
	rep(i, n)L[i] = V[i].second;
	int c = 1, mc = 0, l = L[0];
	for (int i = 1; i <= n; i++) {
		if (l < L[i]) {
			c++;
			l = L[i];
		}
		else {
			mc = max(mc, c);
			c = 1;
			l = L[i];
		}
	}
	mc = max(mc, c);
	cout << n - mc << endl;
}

Measured memory_bytes: 9584
#include<bits/stdc++.h>
#define _LIBCPP_DEBUG 0
using namespace std;
typedef long long int ll;
ll MOD = 1e9 + 7;
int INF = 1 << 20;

int main(void){

    string S; cin>>S;
    int S_len = S.length();
    ll ans=0;
    for (int i = 0; i < (1 << (S_len-1)); ++i) {
        ll sum=0;
        for (int j = 0; j < S_len; ++j) {
            sum*=10;
            sum+=S[j]-'0';
            if(i & (1<<(S_len-2-j))){
                ans += sum;
                sum = 0;
            }
        }
        ans += sum;
        sum=0;
    }

    cout<<ans<<endl;

    return 0;
}


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

int main() {
  string S,T;
  cin >> S >> T;
  sort(S.begin(),S.end());
  sort(T.begin(),T.end());
  vector<int> s(26), t(26);
  int p=0;
  s.at(0)=1;
  for(int i=1;i<S.size();i++){
    if(S.at(i)!=S.at(i-1)){
      p++;
    }
    s.at(p)++;
  }
  p=0;
  t.at(0)=1;
  for(int i=1;i<T.size();i++){
    if(T.at(i)!=T.at(i-1)){
      p++;
    }
    t.at(p)++;
  }
  sort(s.begin(),s.end());
  sort(t.begin(),t.end());
	
  if(s==t){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 776
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include <numeric>
 
 
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
 
typedef long long int ll;
#define ARRAY_MAX 100005


int main(){

    ll n;
    cin >> n;
    vector<ll> arr(n+1,0);
    REP(i,n){
        cin >> arr[i];
    }

    ll ans = 0;
    ll tmp = 0;
    REP(i,n){
        if(arr[i] == 0){
            ans += tmp/2;
            tmp = 0;
        }else{
            tmp += arr[i];
        }
    }
    ans += tmp/2;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		if(n==m){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}

	}

}


Measured memory_bytes: 22996
n = int(input())
A = list(map(int,input().split()))
A.append(-float("inf"))
n = len(A)

A.sort()
s = 2
while s <= A[-1]+A[-2]:
    s *= 2
s //= 2

U = [0] * n

ans = 0
while s > 0:
    ll = 0
    rr = n-1
    while rr >= 1 and s <= A[rr]:
        rr -= 1
    while rr >= 1 and rr-ll >= 2:
        # print("rr",rr,"ll",ll)
        t = s - A[rr]

        # print("s",s,"t",t)
        l = ll
        r = rr-1
        m = (r+l)//2
        while r-l > 1:
            # print("r",r,"l",l,"m",m)
            if A[m] >= t:
                r = m
            else:
                l = m
            m = (r+l)//2
        if A[l+1] == t:
            ans += 1
            U[l+1] = 1
            U[rr] = 1
            # print(ans)
            A[l+1] = -float("inf")
        ll = l
        rr -= 1
        # print(A)
    s //= 2

    B = []
    for i in range(len(A)):
        if U[i] == 0:
            B.append(A[i])
    A = B
    n = len(A)
    U = [0] * n
print(ans)


Measured memory_bytes: 142544
#include <bits/stdc++.h>
using namespace std;
const int MN = 111;
int a[MN];
int main() {
    int n,m;
    cin>>n>>m;
    vector<int> odd;
    vector<int> even;
    for(int i = 0; i < m; ++i) {
        cin>>a[i];
        if(a[i]%2 == 1) odd.push_back(a[i]);
        else even.push_back(a[i]);
    }
    if(n == 1) {
        cout<<a[0]<<'\n'<<1<<'\n'<<1<<'\n';
        return 0;
    }
    if(odd.size() == 0) {
        for(int i = 0; i < m; ++i) cout<<even[i]<<' ';
        cout<<'\n';
        cout<<m+1<<'\n';
        cout<<even[0]-1<<' ';
        for(int i = 1; i < m; ++i) {
            cout<<even[i]<<' ';
        }
        cout<<1<<'\n';
    }
    else if(odd.size() == 2) {
        vector<int> b;
        if(even.size() == 0) {
            cout<<odd[0]<<' '<<odd[1]<<'\n';
            sort(odd.begin(), odd.end());
            if(odd[1] == 1) {
                cout<<1<<'\n';
                cout<<2<<'\n';
            }
            else {
                cout<<2<<'\n';
                cout<<odd[0]+1<<' '<<odd[1]-1<<endl;
            }
        }
        else {
            cout<<odd[0]<<' ';
            for(int i = 0; i < even.size(); ++i) cout<<even[i]<<' ';
            cout<<odd[1]<<'\n';
            b.push_back(odd[0]+1);
            for(int i = 0; i < even.size(); ++i) b.push_back(even[i]);
            if(odd[1] != 1) b.push_back(odd[1]-1);
            cout<<b.size()<<'\n';
            for(int x: b) cout<<x<<' ';
            cout<<'\n';
        }
    }
    else if(odd.size() == 1) {
        cout<<odd[0]<<' ';
        for(int i = 0; i < even.size(); ++i) cout<<even[i]<<' ';
        cout<<'\n';
        if(even.size()) {
            cout<<m<<'\n';
            cout<<odd[0]+1<<' ';
            for(int i = 0; i+1 < even.size(); ++i) {
                cout<<even[i]<<' ';
            }
            cout<<even.back()-1<<'\n';
        }
        else {
            cout<<2<<'\n'<<odd[0]-1<<' '<<1<<'\n';
        }
    }
    else {
        cout<<"Impossible\n";
    }
}


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

int main()
{
    int n,i,j,flag=0;
    string s;
    cin>>n>>s;
    if(n%2!=0)
        cout<<"No"<<endl;
    else
    {
        for(i=0,j=n/2; i<n/2; i++,j++)
        {
            if(s[i]!=s[j])
            {
                flag=1;
                break;
            }
        }
        if(flag==0)
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <algorithm>
#include <stdio.h>
#include <cstring>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <numeric>
#include <regex>
#include <locale>
#include <fstream>
#include <stdlib.h>
#include <cctype>

//#include <map>

using namespace std;

class cDise
{

	vector<int> X;
	vector<int> Y;
	vector<int> vLabel;

public:

	cDise(string l)
	{
		X = { 1, 3 };
		Y = { 1, 2 };

		istringstream iss(l);
		while (!iss.eof())
		{
			int t;
			iss >> t;
			vLabel.push_back(t);
			iss.ignore();
		}
	}

	void rotateDise(string dir)
	{
		istringstream iss(dir);
		vector<char> vc;
		int char_size = 1;

		for (string::iterator it = dir.begin(); it != dir.end(); it += char_size)
		{
			int t;

			switch (*it)
			{
				case 'N':
					t = X[0];
					X[0] = Y[0] = Y[1];
					Y[1] = 7 - t;
					break;
				case 'S':
					t = Y[1];
					Y[1] = Y[0];
					X[0] = Y[0] = 7 - t;
					break;
				case 'W':
					t = X[0];
					X[0] = Y[0] = X[1];
					X[1] = 7 - t;
					break;
				case 'E':
					t = X[1];
					X[1] = X[0];
					X[0] = Y[0] = 7 - t;
					break;
				default:break;
			}
		}
	}

	int getCurrentTop()
	{
		if (X[0] == Y[0])
		{
			return vLabel.at(X[0] - 1);
		}
		return -1;
	}
};

int main()
{
	string lb,dir;
	getline(cin, lb);
	getline(cin, dir);

	cDise cd(lb);
	cd.rotateDise(dir);

	cout << cd.getCurrentTop() << endl;

	return 0;
}

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

int main(){
    int n; cin >> n;
    int def_n = n;
    int cnt = 0;
    while(n > 0){
        cnt++;
        n -= 1000;
        if(n <= 0) break;
    }
    cout << (cnt*1000 - def_n) << endl;

    return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
const ll INF=0x3f3f3f3f;
ll ans[2000050];
void solve(int T){
	ll n,fin;
	int siz=0;
	scanf("%lld",&n);
	for(ll i=1;i*i<=n;i++){
		if(n%i==0)ans[++siz]=i;
	}
	fin=ans[siz]+n/ans[siz]-2;
	printf("%lld",fin);
}
signed main(){
	int t=1;
	//scanf("%d",&t);
	for(int i=1;i<=t;i++){
		solve(i);
	}
}

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

string a,b;

int cal(int n){
    for(int i = n; i < 2 * n;i++){
        int len =  2 * n - i;
        if(a.substr(n - len,len) == b.substr(0,len)) return i;
    }
    return 2 * n;
}

int main(){
    int n;
    cin>>n;
    cin>>a>>b;
    cout<<cal(n)<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string S;
  cin >> S;
  int ans=999;
  int N=S.size();
  for(int i=0;i<=N-3;i++){
    int num = (S[i] - '0')*100 + (S[i+1]-'0')*10 + (S[i+2]-'0');
    ans = min(ans,abs(num-753));
  }
  cout << ans << endl;
}

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

#define TRACE(x) x
#define WATCH(x) TRACE(cout << #x" = " << x << endl)
#define WATCHR(a, b) TRACE(for (auto it=a; it!=b;) cout << *(it++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end());})

#define all(x) (x).begin(), (x).end()

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

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

    string S;
    cin >> S;

    ll ans = 0, bl = 0;
    for (char c : S) {
        if (c == 'W') ans += bl;
        else bl++;
    }
    cout << ans << endl;

    return 0;
}



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

public class Main {
	public static void main(String[] args) {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		
		try {
			String word = in.readLine();
			
			int count = 0;
			String line = "";
			while ((line = in.readLine()).equals("END_OF_TEXT") == false) {
				String words[] = line.split(" ");
				for (int i = 0; i < words.length; i++) {
					String str = words[i].toLowerCase();
					if (word.equals(str) == true) {
						count++;
					}
				}
			}
			System.out.println(count);
		} catch (NumberFormatException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}

Measured memory_bytes: 24316
#include <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
using ld = long double;
template <typename T> using lim = numeric_limits<T>;
template <typename T> istream& operator>>(istream& is, vector<T>& a) { for(T& x : a) { is >> x; } return is; }
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<ll> x(n), y(n), h(n), nx(n), ny(n);
    for(int i = 0; i < n; i++) {
        cin >> x[i] >> y[i] >> h[i];
    }
    for(int cx = 0; cx <= 100; cx++) {
        for(int cy = 0; cy <= 100; cy++) {
            for(int i = 0; i < n; i++) {
                nx[i] = abs(x[i] - cx);
                ny[i] = abs(y[i] - cy);
            }
            for(int i = 0; i < n; i++) {
                if(h[i] != 0) {
                    ll H = h[i] + nx[i] + ny[i];
                    bool can = true;
                    for(int j = 0; j < n and can; j++) {
                        can &= h[j] == max(H - nx[j] - ny[j], 0ll);
                    }
                    if(can) {
                        cout << cx << " " << cy << " " << H << endl;
                        return 0;
                    }
                }
            }
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>

int days_of_month(int y, int m) {
    return y % 3 == 0 or m % 2 == 1 ? 20 : 19;
}
int main() {
    int n; scanf("%d", &n);
    while (n --) {
        int y, m, d; scanf("%d%d%d", &y, &m, &d);
        int result = 0;
        result += days_of_month(y, m) - d;
        ++ m;
        for (; y < 1000; ++ y) {
            for (; m <= 10; ++ m) {
                result += days_of_month(y, m);
            }
            m = 1;
        }
        result += 1;
        printf("%d\n", result);
    }
    return 0;
}

Measured memory_bytes: 2692
# Minimum Cost Sort
# 交換に重みwぶんコストがかかる

# N <= 1000
# a <= 10000

N = int(input())
A = list(map(int, input().split()))
origin = list(range(N))

B = sorted(zip(A, origin), key=lambda x: x[0])


class UnionFind():
    def __init__(self, n):
        self.g = [[i] for i in range(n)]

    def root(self, x):
        if self.is_root(x):
            return x

        self.g[x] = self.root(self.g[x])
        return self.g[x]

    def unite(self, x, y):
        x = self.root(x)
        y = self.root(y)

        if x == y:
            return False

        # yにxをくっつける
        if x < y:
            x, y = y, x
        self.g[y] += self.g[x]
        self.g[x] = y

        return True

    def size(self, x):
        return -self.root(x)

    def is_root(self, x):
        if type(self.g[x]) is list:
            return True
        return False


G = UnionFind(N)
for i, b in enumerate(B):
    G.unite(i, b[1])


min_g = min(A)
cost = 0
for i in range(N):
    if G.is_root(i):
        W = [A[j] for j in G.g[i]]
        n_w = len(W)
        sum_w = sum(W)
        min_w = min(W)

        cost1 = sum_w + min_w*(n_w-2)
        cost2 = cost1 + 2*(min_w + min_g) - (min_w-min_g)*(n_w-1)
        cost += min(cost1, cost2)

print(cost)



Measured memory_bytes: 5892
inputted = input().split()
S = inputted[0]
T = inputted[1]
inputted = list(map(int, input().split()))
A = inputted[0]
B = inputted[1]
U = input()

A2 = A - 1 if U == S else A
B2 = B - 1 if U == T else B

output = "{} {}".format(A2, B2)

print(output)


Measured memory_bytes: 3064
#line 1 "/workspaces/compro/lib/template.hpp"


#line 1 "/workspaces/compro/lib/io/vector.hpp"
#include <iostream>
#include <vector>

#ifndef IO_VECTOR
#define IO_VECTOR

template <class T> std::ostream &operator<<(std::ostream &out, const std::vector<T> &v) {
  int size = v.size();
  for (int i = 0; i < size; i++) {
    std::cout << v[i];
    if (i != size - 1)
      std::cout << " ";
  }
  return out;
}

template <class T> std::istream &operator>>(std::istream &in, std::vector<T> &v) {
  for (auto &el : v) {
    std::cin >> el;
  }
  return in;
}

#endif
#line 4 "/workspaces/compro/lib/template.hpp"
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
#define MM << " " <<

using namespace std;

template <class T> void say(bool val, T yes, T no) { cout << (val ? yes : no) << "\n"; }

void say(bool val, string yes = "Yes", string no = "No") { say<string>(val, yes, no); }

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

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

// C++ 17に完全移行したら消す
// 最大公約数を求める
template <class T> T gcd(T n, T m) { return n ? gcd(m % n, n) : m; }

// 最小公倍数を求める
template <class T> T lcm(T n, T m) {
  int g = gcd(n, m);
  return n * m / g;
}

// 重複を消す。計算量はO(NlogN)
template <class T> void unique(std::vector<T> &v) {
  std::sort(v.begin(), v.end());
  v.erase(std::unique(v.begin(), v.end()), v.end());
}


#line 2 "abc174_c.cpp"

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

  int k;
  cin >> k;
  int ans = 1;
  int mod = 7 % k;
  bool ok = false;
  REP(i, k) {
    if (mod == 0) {
      ok = true;
      break;
    }
    mod = (((10 * mod) % k) + 7) % k;
    ans++;
  }

  if (ok)
    cout << ans << endl;
  else
    cout << -1 << endl;
}


Measured memory_bytes: 3652
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;


class Program
{
    static void Main(string[] args)
    {
        // 入力
        //var s = Console.ReadLine();
        int n = int.Parse(Console.ReadLine());
        //long[] n = Console.ReadLine().Split().Select(long.Parse).ToArray();

        long[] t = new long[n];
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
        {
            long[] input = Console.ReadLine().Split().Select(long.Parse).ToArray();
            t[i] = input[0];
            a[i] = input[1];
        }

        long[] anst = new long[n];
        long[] ansa = new long[n];
        anst[0] = t[0];
        ansa[0] = a[0];
        long k = 1;
        for (int i = 1; i < n; i++)
        {
            k = Math.Max((a[i - 1] * k + a[i] - 1) / a[i], (t[i - 1] * k + t[i] - 1) / t[i]);
            anst[i] = t[i] * k;
            ansa[i] = a[i] * k;
        }

        long ans = ansa[ansa.Length - 1] + anst[anst.Length - 1];

        // 出力
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 13396
n = int(input())
a = list(map(int, input().split()))
ans_l = [0]*n
for i in reversed(range(1,n)):
    if sum(ans_l[(i)::(i+1)])%2 != a[i]:
        ans_l[i] += 1
if sum(ans_l)%2 != a[0]:
    ans_l[0] += 1
ans = []
for i in range(n):
    if ans_l[i]==1:
        ans.append(i+1)
print(len(ans))
if len(ans)>0:
    print(" ".join(map(str, ans)))

Measured memory_bytes: 19892
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
#ifdef DEBUG
#define line() cerr << "[" << __LINE__ << "] ";
#define dump(i) cerr << #i ": " << i << " ";
#define dumpl(i) cerr << #i ": " << i << endl;
#else
#define line(i)
#define dump(i)
#define dumpl(i)
#endif
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 argc, char const *argv[])
{

    COMinit();
    ll n, k;
    cin >> n >> k;
    rep(i, k)
    {
        cout << (COM(n - k + 1, i + 1) * COM(k - 1, i)) % MOD << endl;
    }
    return 0;
}


Measured memory_bytes: 12160
#!/usr/bin/env python3

import itertools

N = int(input())
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))

st = sorted(P)
x = list(itertools.permutations(st, N))
num_p = x.index(P)
num_q = x.index(Q)
print(abs(num_p - num_q))

Measured memory_bytes: 8052
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include <cmath>
#include <limits>
#include<set>
#include <iomanip>
#include <queue>
#include <map>
#include <string>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
const long long INF=(1LL<<62);
const double inf=pow(10,10);
double pi=3.141592653589793;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const ll MOD = 1000000007;
void init(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
}

int main(){
	init();
	ll N,M;cin>>N>>M;
	vector<ll>G[N+1];
	for(int i=0;i<M;i++){
		ll a,b;cin>>a>>b;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	
	set<ll>set;
	for(int i=0;i<G[1].size();i++){
		set.insert(G[1][i]);
	}
	for(int i=0;i<G[N].size();i++){
		if(set.find(G[N][i])!=set.end()){
			cout<<"POSSIBLE"<<endl;
			return 0;
		}
	}
	cout<<"IMPOSSIBLE"<<endl;
}


Measured memory_bytes: 17512
#include<stdio.h>
#define MAX 100005
#define NIL -1

struct Node{int p,l,r;};
struct Node T[MAX];
int n,H,D[MAX];

int getDepth(int u){
  int d=0;
  for(;T[u].p!=NIL;d++)u=T[u].p;
  return d;
}

void print(int u){
  int i,c;
  printf("node %d: ", u);
  printf("parent = %d, ", T[u].p);
  printf("depth = %d, ", D[u]);

  if(T[u].p==NIL)printf("root, ");
  else if(T[u].l==NIL)printf("leaf, ");
  else printf("internal node, ");

  printf("[");
  for(i=0,c=T[u].l;c!=NIL;i++,c=T[c].r){
    if(i)printf(", ");
    printf("%d", c);
  }
  printf("]\n");
}

main(){
  int i,j,d,v,c,l;
  scanf("%d",&n);
  for(i =0;i<n;i++)T[i].p=T[i].l=T[i].r=NIL;

  for(i=0;i<n;i++){
    scanf("%d %d",&v,&d);
    for(j=0;j<d;j++){
      scanf("%d", &c);
      if(j==0)T[v].l=c;
      else T[l].r=c;
      l=c;
      T[c].p=v;
    }
  }
  
  H=0;
  for(i=0;i<n;i++){
    D[i]=getDepth(i);
    if(D[i]>H)H=D[i];
  }

  for(i=0;i<n;i++)print(i);
  return 0;
}



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

int main() {
    while (true) {
        int n;
        cin >> n;
        if (n==0) {
            break;
        }
        pair<char,char> data[n];
        for (int i=0; i<n; i++) {
            cin >> data[i].first >> data[i].second;
        }
        int m;
        cin >> m;
        char str;
        while (m--) {
            cin >> str;
            for (int i=0; i<n; i++) {
                if (data[i].first==str) {
                    str=data[i].second;
                    break;
                }
            }
            printf("%c",str);
        }
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 3024
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

template <typename T>
using vector2 = vector<vector<T>>;
template <typename T>
vector2<T> initVec2(size_t n0, size_t n1, T e = T()){
    return vector2<T>(n0, vector<T>(n1, e));
}

template <typename T>
using vector3 = vector<vector<vector<T>>>;
template <typename T>
vector3<T> initVec3(size_t n0, size_t n1, size_t n2, T e = T()){
    return vector3<T>(n0, vector2<T>(n1, vector<T>(n2, e)));
}

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

    int a, b, k;
    cin >> a >> b >> k;

    for(int x = min(a, b); x > 0; x--){
        if(a % x == 0 && b % x == 0){
            k--;
            if(k == 0){
                cout << x << endl;
                return 0;
            }
        }
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
 
int main() {
  string S;
  int target;
  int counter = 0;
 
  cin >> S;
 
  target = S.size() / 2;
  int right = S.size() - 1;
 
  for (int i = 0; i < target; i++) {
    if (S[i] != S[right]) {
      counter++;
    }
    right--;
  }
 
  cout << counter << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int x,y;
    for (int i=0;i<2999;i++) {
        cin >> x >> y;
        if ( x > y ) {
            cout << y << " " <<  x << endl;
        } else if ( y > x ) {
            cout << x << " " << y << endl;
        } else if ( x == y && x != 0 && y != 0 ) {
            cout << x << " " << y << endl;
        } else if ( x==0 && y==0 ) {
            break;
        }
    }
}



Measured memory_bytes: 3080
import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce


def input(): return sys.stdin.readline().strip()


def INT(): return int(input())


def MAP(): return map(int, input().split())


def LIST(): return list(map(int, input().split()))


def ZIP(n): return zip(*(MAP() for _ in range(n)))


sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def main():
    A, B, H, M = MAP()
    alpha = 30*H + M/2 - 6*M
    alpha = min(alpha, 360 - alpha)
    # print(alpha)
    C2 = A*A + B*B - 2*A*B*cos(radians(alpha))
    print(sqrt(C2))


if __name__ == '__main__':
    main()


Measured memory_bytes: 10924
// warm heart, wagging tail,and a smile just for you!
//                                                                     ███████████
//                                                                   ███╬╬╬╬╬╬╬╬╬╬███
//                                                                ███╬╬╬╬╬████╬╬╬╬╬╬███
//                                            ███████████       ██╬╬╬╬╬████╬╬████╬╬╬╬╬██
//                                      █████████╬╬╬╬╬████████████╬╬╬╬╬██╬╬╬╬╬╬███╬╬╬╬╬██
//                               ████████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████████╬╬╬╬╬╬██╬╬╬╬╬╬╬██
//                             ████╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████████╬╬╬╬╬╬╬╬╬╬╬██
//                           ███╬╬╬█╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬███╬╬╬╬╬╬╬█████
//                         ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬████████╬╬╬╬╬██
//                       ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬╬╬╬╬╬███
//                     ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬██
//                 ████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████╬╬╬╬╬████
//     █████████████╬╬╬╬╬╬╬╬██╬╬╬╬╬████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬██████
//   ████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬██████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██████╬╬╬╬╬╬╬███████████╬╬╬╬╬╬╬╬██╬╬╬██╬╬╬██
// ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████╬╬╬╬╬╬╬╬╬╬╬█╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬██
// ██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬▓▓▓▓▓▓╬╬╬████╬╬████╬╬╬╬╬╬╬▓▓▓▓▓▓▓▓██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬███
// ██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██████▓▓▓▓▓▓▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓▓▓▓▓▓▓██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬█████
// ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████████
//   ███╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██
//       ██████████████  ████╬╬╬╬╬╬███████████████████████████╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████
//                         ███████                           █████  ███████████████████
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
const double EPS = 1e-9;
#define INF (1LL<<60)
#define D double
#define fs first
#define sc second
#define int long long
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i = (b-1);i>=a;i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SP << " " << 
typedef pair<int,int> P;
typedef vector<vector<P> > Graph;
typedef vector<int> vec;
typedef vector<vector<int>> mat;

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

  int n;
  cin >> n;

  int ans = 0;
  vec v(n);
  REP(i,n) cin >> v[i];

  vec c(n);
  REP(i,n) cin >> c[i];

  REP(i,n) if(v[i]-c[i] > 0) ans += v[i]-c[i];

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
N,K = list(map(int,input().split()))
V = list(map(int,input().split()))
out = 0
for left in range(0,K+1):
    for right in range(0,K-left+1):
        if left==0 and right==0:
            continue
        if left + right <= N:
            if right!=0:
                box = V[0:left] + V[N-right:N]
            else:
                box = V[0:left]
            S = sum(box)
            box.sort(reverse=True)
            t = -1
            Life = K-(left+right)
            while Life>0 and abs(t)<=len(box) and box[t]<0:
                S = S-box[t]
                Life += -1
                t += -1
            if S>out:
                out = S
print(max(out,0))

Measured memory_bytes: 41320
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def main():
	s = input()
	K = INT()

	strings = set()
	for i in range(1, K+1):
		for j in range(len(s)-i+1):
			strings.add(s[j:j+i])
	print(sorted(strings)[K-1])


if __name__ == "__main__":
	main()


Measured memory_bytes: 6636
K,N = list(map(int,input().split()))
A = list(map(int,input().split()))
A = sorted(A)
m_list = []
for i in range(N):
  if i == N-1:
    m_list.append(A[0]+K-A[i])
  else:
    m_list.append(A[i+1]-A[i])
print(K-max(m_list))

Measured memory_bytes: 26436
#include<bits/stdc++.h>
using namespace std;
int main(){
  char s[3];
  int sum=0;
  for (int i=0; i<3; i++){
    cin>>s[i];
    if( atoi(&s[i]) == 1) sum++;
  }
  cout<<sum<<endl;
  return 0;
}

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

class Vector2d{
  public:
  double x,y;
  Vector2d(){}
  Vector2d(double x, double y) : x(x),y(y) {}
  Vector2d operator+(Vector2d v){
    return Vector2d(x+v.x, y+v.y);
  }
  Vector2d operator-(Vector2d v){
    return Vector2d(x-v.x, y-v.y);
  }
  bool operator==(Vector2d v){
    return x == v.x && y == v.y;
  }
  double abs(){
  return pow(norm(), 0.5);
  }
  double norm(){
  return x*x + y*y;
  }

  };

double dist[8][8];


int main(){

  int n;
  int total = 0;
  double totalcost=0;
  vector<Vector2d> towns;
  vector<int> order;
  cin >> n;
  towns.resize(n);
  order.resize(n);
  rep(i,n){
    cin >> towns[i].x >> towns[i].y;
    order[i] = i;
  }

  for(int i=0; i<n;i++){
    dist[i][i] = 0;
    for(int j=0; j<i; j++){
      dist[i][j] = dist[j][i] = (towns[i]-towns[j]).abs();
    }
  }

  do{
    for(int i=1;i<n;i++){
      totalcost +=(towns[order[i]]-towns[order[i-1]]).abs();
    }
    total++;
  }while(next_permutation(order.begin(),order.end()));
  
  totalcost /= total;
  cout << setprecision(10) << totalcost << endl;
  return 0;
}

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

int main()
{
	int n;
	long long ans = 0;
	map<pair<int,int>, long long> m;
	cin >> n;
	while(n > 0){
		int cur = n, st, end;
		n--;
		st = cur % 10;
		if(st == 0)
			continue;
		while(cur > 0){
			end = cur%10;
			cur /= 10;
		}
		ans += m[{end, st}] * 2;
		++m[{st, end}];
		if(st == end)
			++ans;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<sstream>
#include<vector>
#include<algorithm>
#include<string>
#include<stdexcept>
#include<stdio.h>
using namespace std;

int main(){
  int N[5]; int res=0; int ans=0; int max=0;
  for(int i=0;i<5;i++) cin >> N[i];
  for(int j=0;j<5;j++) ans += ((N[j]+9)/10)*10;
  for(int k=0;k<5;k++){
  if(((N[k]+9)/10)*10-N[k]>max) max=((N[k]+9)/10)*10-N[k];
  }   
  cout << ans-max <<endl; 
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<iomanip>
#include<math.h>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<functional>
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
typedef queue<P> Q;

int N,A,B,C;
int a[10]={};
int b[10]={};
int func(int n){
    if(n==N){
        int c[4]={};
        int MP[4]={};
        for(int i=0;i<N;i++){
            c[b[i]]+=a[i];
            MP[b[i]]+=10;
        }
        for(int i=1;i<=3;i++){
            MP[i]-=10;
            if(MP[i]<0){
                return 100000000;
            }
        }
        sort(c+1,c+3);
        return abs(c[3]-A)+MP[3]+abs(c[2]-B)+MP[2]+abs(c[1]-C)+MP[1];
    }   
    int ans=100000000;
    for(int i=0;i<=3;i++){
        b[n]=i;
        ans=min(func(n+1),ans);
    }
    return ans;
}
int main(){
    cin>>N>>A>>B>>C;
    for(int i=0;i<N;i++){
        cin>>a[i];
    }
    cout<<func(0);
    return 0;
}

Measured memory_bytes: 256
N,M,X = map(int,input().split())

C = []
A = []
for i in range(N):
    tmp = list(map(int,input().split()))
    C.append(tmp[0])
    A.append(tmp[1:])

ans = 10**9+7

for bit in range(2**N):
    rikai = [0]*M
    money = 0
    for i in range(N):
        if (bit >> i) & 1 == 1:
            for j in range(M):
                rikai[j] += A[i][j]
            money += C[i]
    if min(rikai) >= X:
        ans = min(ans,money)
        
if ans == 10**9+7:
    print(-1)
else:
    print(ans)
            

Measured memory_bytes: 68588
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <functional>
#include <iostream>
#define INF 1000000007
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

typedef pair<int,int> P;
struct edge{
	int to,cap,cost,rev;
	edge(){}
	edge(int tt,int cc,int co,int re){
		to=tt;
		cap=cc;
		cost=co;
		rev=re;
	}
};

int V;
vector<edge> G[3005];
int h[3005];
int dist[3005];
int prevv[3005],preve[3005];

void add_edge(int from,int to,int cap,int cost){
	G[from].push_back(edge(to,cap,cost,G[to].size()));
	G[to].push_back(edge(from,0,-cost,G[from].size()-1));
}

int min_cost_flow(int s,int t,int f){
	int res=0;
	fill(h,h+V,0);
	while(f>0){
		priority_queue<P,vector<P>,greater<P> > que;
		fill(dist,dist+V,INF);
		dist[s]=0;
		que.push(P(0,s));
		while(que.size()){
			P p=que.top();
			que.pop();
			int v=p.second;
			if(dist[v]<p.first)continue;
			for(int i=0;i<G[v].size();i++){
				edge &e=G[v][i];
				if(e.cap>0 && dist[e.to]>dist[v]+e.cost+h[v]-h[e.to]){
					dist[e.to]=dist[v]+e.cost+h[v]-h[e.to];
					prevv[e.to]=v;
					preve[e.to]=i;
					que.push(P(dist[e.to],e.to));
				}
			}
		}
		if(dist[t]==INF)return -1;
		for(int v=0;v<V;v++){
			h[v]+=dist[v];
		}
		int d=f;
		for(int v=t;v!=s;v=prevv[v]){
			d=min(d,G[prevv[v]][preve[v]].cap);
		}
		f-=d;
		res+=d*h[t];
		for(int v=t;v!=s;v=prevv[v]){
			edge &e=G[prevv[v]][preve[v]];
			e.cap-=d;
			G[v][e.rev].cap+=d;
		}
	}
	return res;
}

int n;
int a[2001],b[2001];
vector<int> vec;

int main(void){
	scanf("%d",&n);
	int maxi=0;
	for(int i=0;i<n;i++){
		scanf("%d%d",&a[i],&b[i]);
		maxi=max(maxi,a[i]);
		maxi=max(maxi,b[i]);
		vec.push_back(a[i]);
		vec.push_back(b[i]);
	}
	sort(vec.begin(),vec.end());
	vec.erase(unique(vec.begin(),vec.end()),vec.end());
	int s=vec.size()+n,t=vec.size()+n+1;
	V=t+1;
	for(int i=0;i<n;i++){
		a[i]=lower_bound(vec.begin(),vec.end(),a[i])-vec.begin();
		b[i]=lower_bound(vec.begin(),vec.end(),b[i])-vec.begin();
		add_edge(s,vec.size()+i,1,0);
		add_edge(vec.size()+i,a[i],1,maxi-vec[b[i]]);
		add_edge(vec.size()+i,b[i],1,maxi-vec[a[i]]);
	}
	for(int i=0;i<vec.size();i++){
		add_edge(i,t,1,0);
	}
	int res=0;
	int now=0;
	for(int i=0;i<n;i++){
		int v=min_cost_flow(s,t,1);
		if(v==-1)break;
		now+=maxi-v;
		res=max(res,now);
	}
	printf("%d\n",res);
	return 0;
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
//#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rev(i,b,a) for (ll i = b - 1; i >= a; i--)
#define all(v) v.begin(), v.end()
#define maxe(v) *max_element(v.begin(), v.end())
#define mine(v) *min_element(v.begin(), v.end())
#define pb push_back
#define pf push_front
//#define rem 1000000007
#define cont continue
#define PI 3.141592653589793238462643383279502
#define debug(n1) cout<<"debug... "<<n1<<"\n"
const ll INF=(1ll<<60)-1;//ll ans = 3e18 + 5;
/////////////////////////

int main() {
	//code
	int tc=1;
	//cin>>tc;
	while(tc--)
	{
        ll n,d;
        cin>>n>>d;
        ll ans=0;
        ll x,y;
        rep(i,0,n)
        {
            cin>>x>>y;
            if( x*x + y*y <= d*d )
            ans++;
        }
        cout<<ans;
	}
	return 0;
}


Measured memory_bytes: 3620
a, b, c = map(int, input().split())
k = int(input())
n = 0

while a >= b:
  b = b*2
  n += 1
while b >= c:
  c = c*2
  n += 1

if a < b < c and n <= k:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 9128
#include <cassert>
#include <algorithm>
#include <iostream>
#include <vector>
#include <set>
#include <atcoder/all>
using namespace std;
using namespace atcoder;


struct Town { int id, x, y; };
int main() {
  int n; cin >> n;
  vector<Town> towns;
  vector<int> tid(n+1);
  for (int i = 0; i < n; ++i) {
    int x, y; cin >> x >> y;
    towns.push_back((Town){i,x,y});
    tid[y] = i;
  }
  sort(towns.begin(),towns.end(), [&](auto& l, auto&r){
    return l.x < r.x;
  });
  dsu uf(n);
  set<int> ly;
  for (auto &t: towns) {
    auto pos = ly.lower_bound(t.y);
    int d = distance(ly.begin(), pos);
    if (d > 0) {
      auto it = ly.begin();
      uf.merge(t.id, tid[*it]);
      ++it;
      while (it != pos) {
        // cerr << d << " " << t.y << " " << t.id << " " << *it << " " << tid[*it] << endl;
        uf.merge(t.id, tid[*it]);
        it = ly.erase(it);
      }
    }
    else {
      ly.insert(t.y);
    }
  }
  for (int i = 0; i < n; ++i) {
    cout << uf.size(i) << endl;
  }
}



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

using namespace std;

int main(void){
	int n,m;
	cin>>n>>m;
	int i,p[m],s[m],wa[n+1],co[n+1];
	int c_list[m];
	char w[2];
	for(i=0; i < m; i++){
		cin>>p[i]>>w;
		if(w[0] == 'A'){
			s[i] = 1;
		}
		else if(w[0]=='W'){
			s[i] = 2;
		}
		c_list[i] = 0;
	}
	for(i=0;i<n+1;i++){
		wa[i] = 0;
		co[i] = 0;
	}
	//cout<<s<<endl;
	int corect = 0;
	int miss = 0;
	int c_list_num = 0;
	int j;
	//printf("apple\n");
	for(i = 0; i < m; i++){
		if(s[i] == 1 && co[p[i]] == 0){
			co[p[i]]++;
			corect++;
			miss+=wa[p[i]];
			//printf("i = %d, p[i] = %d, wa[p[i]] = %d\n",i,p[i],wa[p[i]]);
		}
		else if(s[i] == 2){
			wa[p[i]]++;
			//printf("i = %d, p[i] = %d, wa[p[i]] = %d\n",i,p[i],wa[p[i]]);
		}
	}
	cout<<corect<<" "<<miss<<endl;
	return 0;
}




Measured memory_bytes: 2176
R=["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]
N=int(input())
A=list(input())
for i in range(len(A)):
  A[i]=R[(R.index(A[i])+N)%26]
print("".join(A))

Measured memory_bytes: 3064