akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <utility>
#include <unordered_map>
using namespace std;
int GCD(int a,int b){
    if(b == 0)return a;
    return GCD(b,a%b);
}
int main(void){
    string S,T;
    cin >> S >> T;
    unordered_map<char,char> mp;
    unordered_map<char,bool> used;
    for(int i=0;i<S.size();i++){
        if(mp[T[i]]){
            if(mp[T[i]] != S[i]){
                cout << "No" << endl;
                return 0;
            }
        }
        else{
            if(used[S[i]]){
                cout << "No" << endl;
                return 0;
            }
            mp[T[i]] = S[i];
            used[S[i]] = true;
        }
    }
    cout << "Yes" << endl;
}


Measured memory_bytes: 3472
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		for(int i = 0; i * 4 <= 100; i++) {
			for(int j = 0; j * 7 <= 100; j++) {
				if(i * 4 + j * 7 == n) {
					System.out.println("Yes");
					return;
				}
			}
		}
		System.out.println("No");
	}
}


Measured memory_bytes: 21844
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<functional>
#include<map>
#include<cmath>
#include<iomanip>

using namespace std;

typedef long long ll;

int main()
{
  string s; cin >> s;
  int n = s.size();
  int ans = 0;
  
  if(n == 0) {
    cout << '0' << endl;
    return 0;
  }

  for (int i = 0; i < n - 1; i++)
  {
    if(s[i] == '0' && s[i] == s[i + 1]){
      s[i + 1] = '1';
      ans++;
      continue;
    }
    if(s[i] == '1' && s[i] == s[i + 1]){
      s[i + 1] = '0';
      ans++;
      continue;
    }
  }
  
  cout << ans << endl;
}


Measured memory_bytes: 512
while True:
    n, m = map(int, input().strip().split())
    if n == 0:
        break
    a = sorted(list(map(int, input().strip().split())))
    ans = 0
    pos = n - 1
    for i in range(n):
        while pos > i and a[i] + a[pos] > m:
            pos -= 1
        if pos <= i:
            break
        ans = max(ans, a[i] + a[pos])
    print(ans if ans > 0 else 'NONE')



Measured memory_bytes: 5632
#include <bits/stdc++.h>
#include <cassert>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define PI 3.14159265358979
using namespace std;
using ll = long long;
using P = pair<int, int>;
struct Edge
{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w) {}
};
// using Graph = vector<vector<Edge>>;
using Graph = vector<vector<int>>;

const long long INF = 1LL << 60;
const int INT_INF = 1000000000;

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

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int X, Y;
  cin >> X >> Y;
  for (int i = 0; i <= 1000; i++)
  {
    for (int j = 0; j <= 1000; j++)
    {
      if (2 * i + 4 * j == Y && i + j == X)
      {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
  return 0;
  return 0;
}


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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

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

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}

bool in(string s1, string s2) {
  int64 idx = 0;
  REP(i, s2.size()) {
    if (idx < s1.size() && s1[idx] == s2[i]) idx++;
  }
  return idx == s1.size();
}

int main(void) {
  string s[2];
  cin >> s[0] >> s[1];
  string t = "";
  for (int64 i = 0; i < s[1].size(); i+=2) {
    t += s[0][i];
  }
  if (in(t, s[1])) {
    cout << "Yes" << endl;
    return 0;
  }
  t = "";
  for (int64 i = 1; i < s[1].size(); i+=2) {
    t += s[0][i];
  }
  if (in(t, s[1])) {
    cout << "Yes" << endl;
    return 0;
  }
  cout << "No" << endl;
}


Measured memory_bytes: 3228
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<deque>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<iterator>
#include<complex>
#include<stack>
#include "stdio.h"
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const long long mod_const = 1e9+7;
using MIte = multimap<long, long, greater<long> >::iterator;

struct UnionFind {
	vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
	vector<int> ndata;
	set<int> rootlist;
	UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
		ndata.resize(N);
		for (int i = 0; i < N; i++) {
			par[i] = i;
			rootlist.insert(i);
			ndata[i] = 1;
		}
	}

	int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
		if (par[x] == x) return x;
		return par[x] = root(par[x]);
	}

	void unite(int x, int y) { // xとyの木を併合
		int rx = root(x); //xの根をrx
		int ry = root(y); //yの根をry
		if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
		par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
		ndata[ry] += ndata[rx];
		ndata[rx] = 0;
		rootlist.erase(rx);
	}

	bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}

	int rootsize(int n) {
		return ndata[root(n)];
	}
};

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

	long long N, M;
	cin >> N >> M;

	vector<int> vA(M);
	vector<int> vB(M);
	for (int i = M-1; i != -1; --i) {
		int a, b;
		cin >> a >> b;
		vA[i] = a - 1;
		vB[i] = b - 1;
 	}

	UnionFind island(N);
	long long combi = N * (N - 1) / 2;
	vector<long long> vResult;
	vResult.push_back(combi);

	for (int i = 0; i != M; ++i) {
		if (!island.same(vA[i], vB[i])) {
			combi -= island.rootsize(vA[i]) * island.rootsize(vB[i]);
		}
		island.unite(vA[i], vB[i]);
		vResult.push_back(combi);
	}

	for (int i = vResult.size() - 2; i != -1; --i) {
		cout << vResult[i] << endl;
	}



	return 0;
}

Measured memory_bytes: 8568
/*
Ta和Ao将在一棵树上玩游戏，该树有N个顶点，标号为1,2,...,N，
N-1条边的第i条边连接顶点ai和bi。
在游戏开始时，每个顶点有一个金币。
从Ta开始，两人交换进行下列操作：
  1、选择一个包含一个或多个金币的顶点v，从v中移除所有的金币。
  2、将树中剩余的每个金币移动到与该金币相邻且距离v最近的顶点
如果谁不能继续玩下去，则谁就输。
假设两人都采取最优策略，确定最后谁赢 
数据范围：
1<=N<=2*10^5 
*/ 
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;
#define N 200003
int n, m_dep, m_idx, dep[N];
vector<int>g[N];
void dfs(int cur){
	int i, x;
	for(i=0; i<g[cur].size(); i++){
		x = g[cur][i];
		if(dep[x])
			continue;		
		dep[x] = dep[cur]+1;
		if(dep[x]>m_dep){
			m_dep = dep[x];
			m_idx = x;
		}
		dfs(x);
	}
}
int main(){
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int i, x, y;
	cin>>n;
	for(i=1; i<n; i++){
		cin>>x>>y;
		g[x].push_back(y);
		g[y].push_back(x);
	}
	m_dep = 0, m_idx = 1, dep[1] = 0;
	dfs(1);
	memset(dep, 0, sizeof(dep));
	m_dep = 0;
	dep[m_idx] = 0;
	dfs(m_idx);
	if(m_dep%3==1)
		cout<<"Second"<<endl;
	else
		cout<<"First"<<endl;
	return 0;
}


Measured memory_bytes: 21376
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>

using namespace std;

int main(){
  string s;
  cin >> s;
  string str[]={"Sunny", "Cloudy", "Rainy"};
  for(int i=0;i<3;i++){
  	if(s==str[i]){
    	if(i==2) cout << str[0] << endl;
        else cout << str[i+1] << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 256
n =int(input())

t = list(map(int,input().split()))

m = int(input())

p = []

p = [[int(i) for i in input().split()] for _ in range(m)]

for ii in range(m):
    if p[ii][0] <= n:
        total_time = sum(t) - t[p[ii][0]-1] + p[ii][1]
    else:
        total_time = sum(t)
    
    print(total_time)
   

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using Map = map<ll,ll>;
using T = tuple<ll,ll,ll>;
using vvl = vector<vector<ll>>;
#define all(v) v.begin(), v.end()
#define print(v) cout<<v<<endl;
#define fi(v) get<0>(v)
#define se(v) get<1>(v)
#define th(v) get<2>(v)
template <typename T> bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template <typename T> bool chmin(T &a, const T &b){if (a>b){a=b;return 1;}return 0;}
const ll INF=1LL<<60;
const ll MOD=1000000007;

ll F(ll x){
    if(x<=0)return 1;
    if(x==1)return 2;
    if(x==2)return 3;
    if(x==3)return 5;
    if(x==4)return 8;
    if(x==5)return 13;
    if(x==6)return 21;
    if(x==7)return 34;
    if(x==8)return 55;
}


int main(){
    ll H;
    cin >> H;
    ll W;
    cin >> W;
    ll K;
    cin >> K;
    if(W==1){
        print(1)
        return 0;
    }
    vector<vector<ll>> dp(H+1, vector<ll>(W, 0));
    dp[0][0]=1;
    for(ll i=1;i<H+1;i++){
        //左端について
        dp[i][0]+=F(W-2)*dp[i-1][0];
        dp[i][0]+=F(W-3)*dp[i-1][1];
        for(ll j=1;j<W-1;j++){
            dp[i][j]+=F(j-2)*F(W-j-2)*dp[i-1][j-1];
            dp[i][j]+=F(j-1)*F(W-j-2)*dp[i-1][j];
            dp[i][j]+=F(j-1)*F(W-j-3)*dp[i-1][j+1];
        }
        //右端について
        dp[i][W-1]+=F(W-2)*dp[i-1][W-1];
        dp[i][W-1]+=F(W-3)*dp[i-1][W-2];
        for(ll j=0;j<W;j++)dp[i][j]%=MOD;
    }
    print(dp[H][K-1])

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define itr(x) for(__typeof((x).begin()) it=(x).begin();it!=(x).end();it++)
#define For(i,n) for (int i=1;i<=(int)(n);i++)
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define all(x) (x).begin(),(x).end()
#define PQ priority_queue
#define pii pair<int,int>
#define vi vector <int>
#define ll long long
#define pb push_back
#define mp make_pair
#define re return
#define se second
#define fi first
const int INF=0x7fffffff;
const int MAXN=+3;
const int MOD=1000000007;

int n,m,k,p[13];
ll f[10][103];

void pre(){
	int t[13][2];
	memset(t,0,sizeof(t));
	p[0]=1;
	t[1][0]=1;
	t[1][1]=1;
	p[1]=2;
	for (int i=2;i<13;i++){
		t[i][0]=t[i-1][0]+t[i-1][1];
		t[i][1]=t[i-1][0];
		p[i]=t[i][0]+t[i][1];
	}
}

ll calc(int x){
	re (ll)p[max(0,x-2)]*(ll)p[max(0,n-x-2)]%MOD;
}

ll calcm(int x){
	re (ll)p[max(0,x-2)]*(ll)p[max(0,n-x-1)]%MOD;
}

int main(){
	pre();
	cin>>m>>n>>k;
	f[1][0]=1;
	for (int i=1;i<=m;i++){
		for (int j=1;j<=n;j++){
			f[j][i]+=f[j-1][i-1]*calc(j-1);
			f[j][i]%=MOD;
			f[j][i]+=f[j][i-1]*calcm(j);
			f[j][i]%=MOD;
			f[j][i]+=f[j+1][i-1]*calc(j);
			f[j][i]%=MOD;
		}
	}
	cout<<f[k][m];
	re 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (1LL<<60)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
typedef unsigned long long int ull;
typedef long long lint;

int main(void){
    int dp[1000000];
    rep(i,1000000) dp[i]=INF;
    dp[0]=0;
    int N;
    cin >> N;
    rep(i,N+1){
        rep(j,5) dp[i+j+1]=min(dp[i+j+1],dp[i]+j+1);
        rep(j,6) dp[i+(int)pow(6,j+1)]=min(dp[i+(int)pow(6,j+1)],dp[i]+1);
        rep(j,5) dp[i+(int)pow(9,j+1)]=min(dp[i+(int)pow(9,j+1)],dp[i]+1);
    }
    cout << dp[N] << endl;
}

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

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int[] num = new int[3];
		num[0] = Integer.parseInt(in.next());
		num[1] = Integer.parseInt(in.next());
		num[2] = Integer.parseInt(in.next());
		Arrays.sort(num);
		
		System.out.println(num[0] + " " + num[1] + " " + num[2]);
	}
}	


Measured memory_bytes: 26280
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;

fn main() {
    input! {
        a: i32, b: i32,
        c: i32,mut k: i32,
    }
    let mut s = 0;
    use std::cmp::min;
    s += min(a, k);
    k -= min(a, k);
    k -= min(b, k);
    s -= min(c, k);
    // k -= min(c, k);
    println!("{}", s);
}


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

using namespace std;
using llong = long long;
using P = pair<llong, llong>;

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

const llong inf = llong(1e18)+7;
const llong mod = 1e9+7;

llong GCD(llong a, llong b){
	a = abs(a), b = abs(b);
	if(a < b) swap(a, b);
	if(b == 0) return a;
	while(b){
		a %= b;
		swap(a,b);
	}

	return a;
}

llong LCM(llong a, llong b){
	return a / GCD(a, b) * b;
}

int main(){
	int N;
	vector<P> h;

	cin >> N;
	h.resize(N);
	for(int i = 0; i < N; i++)
		cin >> h[i].first >> h[i].second;

	llong t = 1, a = 1;
	cerr << endl;
	for(int i = 0; i < N; i++){
		// cerr << t << " " << a << endl;

		llong nt, na;
		nt = h[i].first * (t/h[i].first) + (t%h[i].first ? h[i].first : 0);
		na = h[i].second * (a/h[i].second) + (a%h[i].second ? h[i].second : 0);

		llong tc = inf, ac = inf;
		if(nt/h[i].first*h[i].second >= a)
			tc = nt - t + nt/h[i].first*h[i].second - a;
		if(na/h[i].second*h[i].first >= t)
			ac = na/h[i].second*h[i].first - t + na - a;

		if(tc < ac)
			t = nt, a = nt/h[i].first*h[i].second;
		else
			t = na/h[i].second*h[i].first, a = na;

	}
	// cerr << t << " " << a << endl;

	cout << t + a << endl;

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>


int main(){
    int A,B,C,D;
    scanf("%d %d %d %d",&A,&B,&C,&D);
    while (1) {
        C-=B;
        if(C<=0){
            printf("Yes\n");
            return 0;
        }
        A-=D;
        if(A<=0){
            printf("No\n");
            return 0;
        }
    }
}

Measured memory_bytes: 1648
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#define repp(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define repm(i,a,b) for(int i=(int)a;i>(int)b;--i)
using ll=long long;
static const ll mod = 1e9 + 7;
static const ll INF = 1LL << 50;
using namespace std;

int main() {
	int n, m;
	cin >> n >> m;
	vector<bool>a(n+1,false);
	for (int i = 0; i < m; ++i) {
		int b;
		cin >> b;
		a[b] = true;
	}
	vector<ll>f(n+1,0);
	f[0] = f[1] = 1;
	if (a[1])f[1] = 0;
	for (int i = 2; i<=n; ++i) {
		f[i] = (f[i - 1] + f[i - 2])%mod;
		if (a[i])f[i] = 0;
	}
	cout << f[n] << endl;
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<iomanip>
#include<cmath>
#include<algorithm>
#include<queue>
#include<set>
#include<unordered_map>
#include<stack>
#include<map>
#include<bitset>
#include <cstdlib>
#include<cstring>
#define ll long long;
#define pb push_back
const int MOD = 1e9 + 7;
const int qq = 1e5 + 10;
const int INF = 1e9 + 10;
const double eps = 1e-11;
const double pi = acos(-1.0); 
using namespace std;
#define ma = 2147483647;
#define mi = -2147483647;
int main()
{
	ios::sync_with_stdio(0); cin.tie(0);
	int n;
	cin >> n;
	int t;
	t = n % 10;
	if (t == 2 || t == 4 || t == 5 || t == 7 || t == 9)
	{
		cout << "hon";
	}
	else if (t == 3)
	{
		cout << "bon";
	}
	else if (t == 0 || t == 1 || t == 6 || t == 8)
	{
		cout << "pon";
	}





	return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n; i >= 0; i--)
#define inf LLONG_MAX
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


int main()
{
    ll N, T; cin >> N >> T;
    vector<ll> t(N);
    rep(i, N) cin >> t[i];

    ll time = 0;
    rep(i, N) {
        if (i == N - 1) time += T;
        else {
            time += min(T, t[i+1] - t[i]);
        }
    }
    cout << time << endl;

    return 0;
}

Measured memory_bytes: 1792
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <queue>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

#define pb push_back
#define mk make_pair
#define f0(i,b) for(int i=0;i<(b);i++)
#define f1(i,b) for(int i=1;i<=(b);i++)
#define f2(i,a,b) for(int i=(a);i<=(b);i++)
#define sf(a) scanf("%d",&a);
#define sfl(a) scanf("%lld",&a);
#define pf(a) printf("%d\n",a);
#define pfl(a) printf("%lld\n",a);
#define TEST int test; cin >> test;while(test--)
#define ii pair<int,int>
#define iil pair<ll,ll>
#define loop(i,a,b) for(int i = a ; i < b ; i++)
#define INF 2147483647


int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};
const double pi = acos(-1.0);

ll power(ll x, unsigned long long y)
{
    ll res = 1;     // Initialize result

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res*x);

        // y must be even now
        y = y>>1; // y = y/2
        x = (x*x);  // Change x to x^2
    }
    return res;
}
map<ll,ll>mp;
void solve()
{
    int n;
    ll x,ans = 0;
    cin >> n ;
    ll a[n+1];
    for(int i = 1; i <= n ; i++)
    {
        cin >> a[i];
        mp[i+a[i]]++;
    }
    for(int i = 1; i <= n ; i++)
    {
        if(mp.count(i-a[i]))
            ans += mp[i - a[i]];
    }
    cout << ans << endl;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    //TEST
    solve();
    return 0;
}


Measured memory_bytes: 17592
import sys
import math
from collections import Counter
import itertools
import fractions
#from functools import reduce

# 入力を整数に変換して受け取る
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())
# 入力全てを整数に変換したものの配列を受け取る
def LI(): return list(map(int, sys.stdin.readline().split()))
# 入力全てを整数に変換して1引いたものの配列を受け取る
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SR(): return sys.stdin.readline().rstrip()

ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'
ascii_uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
ascii_uppercase2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ'

# リストを改行区切りで出力する
p2D = lambda x: print(*x, sep="\n")
p2E = lambda x: print(''.join(x))
p2S = lambda x: print(*x, sep=" ")

# ###########################################
 
N=II()
d=LI()

d.sort()

ans =0
x=d[int(N/2)]
y=d[int(N/2)-1]
if x==y:
    print(0)
else:
    print(x-y)


Measured memory_bytes: 15984
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define MP make_pair
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define PLI pair<ll, int>
#define PIL pair<int, ll>
#define STR string
#define Fst first
#define Snd second
#define SHN 1e9
#define LSHN 1e18
using namespace std;
int n,m;
vector<PII> v[500010];
bool isb[500010],vis[500010];
int Low[500010],dep[500010];
int tac; 
void dfs(int x,int par)
{
	vis[x]=1,dep[x]=++tac;
	Low[x]=dep[x];
	for (int i=0;i<v[x].size();i++)
	{
		int xi=v[x][i].Fst,yi=v[x][i].Snd;
		if (yi==par) continue;
		if (!vis[xi])
		{
			dfs(xi,yi);
			Low[x]=min(Low[x],Low[xi]);
		}
		else Low[x]=min(Low[x],dep[xi]);
	}
	//cout <<x<<" "<<dep[x]<<" "<<Low[x]<<" ##\n";
	if (x) isb[par]=(Low[x]==dep[x]);
}
int main()
{
	scanf("%d%d",&n,&m);
	for (int i=0;i<m;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		x--,y--;
		v[x].push_back(MP(y,i));
		v[y].push_back(MP(x,i));
	}
	dfs(0,-1);
	printf("%d",count(isb,isb+m,1));
	return 0;
} 

Measured memory_bytes: 15504
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>

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

using namespace std;
int main() {
	int x, a, b;
	cin >> x >> a >> b;
	if (abs(x - a) < abs(x - b))
		cout << "A" << endl;
	else
		cout << "B" << endl;

	return 0;
}

Measured memory_bytes: 256
n,x = map(int,input().split())
ans =0
while x > 0:
    if n==0:
        ans +=1
        break
    elif x == 1:
        break
    elif x >=2**(n+1)-1:
        ans += 2**n
        x -=2**(n+1)-1
        n -=1
    elif x == 2**(n+1)-2:
        ans += 2**n-1
        print(ans)
        exit()
    else:
        n -=1
        x -=1
print(ans)

Measured memory_bytes: 3064
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] dp = new int[100010];
		for(int i = 0 ; i < 100010 ; i++) dp[i] = -1;
		Queue<Integer> q = new LinkedList<>();
		q.add(0);
		dp[0] = 0;
		while(!q.isEmpty()) {
			int v = q.poll();
			for(int i = 1 ; i + v <= n ; i *= 6) {
				if(dp[i + v] == -1) {
					dp[i + v] = dp[v] + 1;
					q.add(i + v);
				}
			}
			for(int i = 1 ; i + v <= n ; i *= 9) {
				if(dp[i + v] == -1) {
					dp[i + v] = dp[v] + 1;
					q.add(i + v);
				}
			}
		}
		System.out.println(dp[n]);
	}
}


Measured memory_bytes: 26304
#include <bits/stdc++.h>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef pair<int, int> PII;
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(v, n) sort(v, v+n)
#define VSORT(v) sort(v.begin(), v.end())
#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define INF 999999999
const double EPS = 1e-10;
const double PI  = acos(-1.0);
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main(){
    cin.tie(0);
   	ios::sync_with_stdio(false);
    ll n,a,b;
    cin >>n>>a>>b;
    ll wru = n/(a+b);
    ll ama = n%(a+b);
    ll ans = wru*a+min(ama,a);
    cout <<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
)

var scanner = bufio.NewScanner(os.Stdin)

func nextString() string {
	scanner.Scan()
	return scanner.Text()
}

type Pair struct {
	key   string
	value int
}

func main() {
	scanner.Split(bufio.ScanWords)
	counts := map[string]int{}
	maxLen := 0
	maxLenWord := ""
	for {
		word := nextString()
		if word == "" {
			break
		}

		counts[word]++

		if len(word) > maxLen {
			maxLen = len(word)
			maxLenWord = word
		}
	}

	mapPairs := []Pair{}
	for k, v := range counts {
		mapPairs = append(mapPairs, Pair{k, v})
	}
	sort.Slice(mapPairs, func(i, j int) bool { return mapPairs[i].value > mapPairs[j].value })

	fmt.Println(mapPairs[0].key, maxLenWord)
}



Measured memory_bytes: 1108
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <iostream>
#include <map>
#include <set>
#include <math.h>
#include <ctype.h>
#include <string.h>
#include <string>
#include <stdlib.h>
#include <queue>
#include <limits.h>
using namespace std;

typedef long long ll;

const int N = 1e3, M = 1e9 + 7;
char g[N][N + 1];
int n, m, dp[N][N];

int calc(int i, int j) {
	if (i == n - 1 && j == m - 1)
		return 1;
	if (i == n || j == m || g[i][j] == '#')
		return 0;
	int &res = dp[i][j];
	if (res != -1)
		return res;
	return res = (calc(i + 1, j) + calc(i, j + 1)) % M;
}

int main(int argc, char **argv) {
	scanf("%d%d", &n, &m);
	for (int i = 0; i < n; ++i)
		scanf("%s", g[i]);
	memset(dp, -1, sizeof(dp));
	printf("%d\n", calc(0, 0));
	return 0;
}


Measured memory_bytes: 5248
#include<iostream>
using namespace std;
int32_t main()
{
    int n, k;
    cin >> n >> k;
    int a[n];
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    int dp[n];
    for (int i = 0; i < n; i++)
        dp[i] = INT_MAX;
    dp[n - 1] = 0;
    dp[n - 2] = abs(a[n - 2] - a[n - 1]);
    for (int i = n - 3; i >= 0; i--)
    {
        for (int j = 1; j <= k && (j + i) < n; j++)
        {
            dp[i] = min(dp[i], dp[i + j] + abs(a[i] - a[i + j]));
        }
        //cout << dp[i] << endl;
    }
    cout << dp[0];
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
using namespace std;
string s;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a=0,b,c,d;
  cin >>s;
  for(int n=0;n<s.size();n++){
    for(int m=n+1;m<s.size();m++){
      if(s[n]==s[m]){
	a++;
	break;
      }
    }
    if(a>0) break;
  }
  if(a==0) cout <<"yes\n";
  else cout <<"no\n";
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
import static java.lang.System.*;
public class Main{
    public static void main(String[]$){
        Scanner sc = new Scanner(in);

        int n=sc.nextInt();
        int m=sc.nextInt();
        int[] a=new int[m+1];
        int[] b=new int[m+1];
        for (int i = 1; i <=m ; i++) {
            a[i] = sc.nextInt();
            b[i] = sc.nextInt();
        }

        int[] node=new int[n+1];
        //頂点1,2,3,...,n
        //探索済み→node[i]=-1,未探索→node[i]=0
        //0はジャマなのではじめから探索済みにしておく
        node[0]=-1;

        //各頂点iに対し、そことつながっている頂点j,k,...をbridge[i]=j,k....で表す
        ArrayList<Integer>[] bridge=new ArrayList[n+1];

        //bridge[i]はそれぞれがリストなのですべて初期化する必要がある（bridge[0]は使わないので放置）
        for (int i = 1; i <=n ; i++) {
            bridge[i]=new ArrayList<>();
        }

        //辺の追加
        //頂点a[i],b[i]につながっている頂点をbridge[a[i]],bridge[b[i]]に追加していく（隣接リスト）
        for(int i=1;i<=m;i++){
            bridge[a[i]].add(b[i]);
            bridge[b[i]].add(a[i]);
        }

        int ans=0;

        //全探索
        for (int i = 1; i <=m; i++) {
            //i番目の辺を削除
            //Integerにキャストしないと「a[i]番目の要素を削除」となってしまいぬるぽを吐く
            bridge[a[i]].remove((Integer)b[i]);
            bridge[b[i]].remove((Integer)a[i]);
            //条件を満たすか確認（BFSでグラフが連結か判定）満たすなら++ans
            if(bfs(node,bridge))++ans;
            //i番目の辺を復元
            bridge[a[i]].add(b[i]);
            bridge[b[i]].add(a[i]);
        }

        out.println(ans);
    }
    //グラフをBFS（Queueを用いる）
    static boolean bfs(int[] node,ArrayList[] x){
        Queue<Integer> q=new ArrayDeque<>();

        //node[]の添え字は0～nなので配列長はn+1、よってnはnode[]の配列長-1
        int n=node.length-1;

        //初期化（全頂点を未探索にする）
        for(int i=1;i<=n;i++){
            node[i]=0;
        }

        //未探索→探索済みの回数（新たに到達した頂点の個数）をカウント(新たに頂点を探索したら++sum)
        //つまり、sumは「到達することができた頂点の個数」である
        //もし全体が連結ならば最終的にsum==nとなるはず
        int sum=0;

        //頂点1から探索開始
        q.add(1);

        //BFS
        while(q.size()>0) {
            int tempnode = q.poll();
            //未探索かどうか判定
            if (node[tempnode] == 0) {
                //探索済みにする
                node[tempnode] = -1;
                //新たに到達したので++sum
                ++sum;
                //隣接する頂点をQueueに入れる（BFSですね）
                for (Object k : x[tempnode]) {
                    q.add((Integer) k);
                }
            }
        }

        //グラフが非連結になっているかどうか判定（非連結になっていれば題意を満たします）
        return sum!=n;
    }
  //最後までお読みいただき、誠にありがとうございます。
}

Measured memory_bytes: 23764
n,k = map(int, input().split())

if k ==1:
    print(n**3)

elif k ==2:
    m = n % 2
    o = n//2
    print((o+m)**3+o**3)

elif k % 2==1:
    x = n//k
    print(x**3)

else:
    x = n//k
    y = n//(k//2)
    print(x**3+(y-x)**3)

Measured memory_bytes: 9096
import * as fs from 'fs';
 
const lines = fs.readFileSync('/dev/stdin', 'utf8').split("\n");
let [h,n] = lines[0].split(" ").map(Number);
let a = lines[1].split(" ").map(Number);

let s = 0;
for(let i = 0; i < n; i++){
    s += a[i];
}

if (s>=h){
    console.log("Yes");
}
else{
    console.log("No");
}


Measured memory_bytes: 16716
#include <iostream>
#include <string>
#include <set>

using namespace std;
typedef long long ll;

int main(){
    string s;
    cin >> s;
    ll k;
    cin >> k;

    set<string> x;
    for(int i = 0; i < s.size(); ++i){
        for(int j = 1; i + j <= s.size() && j <= k; ++j){
            x.insert(s.substr(i, j));
        }
    }

    auto it = x.begin();
    for(int i = 0; i < k - 1; ++i){ ++it; }
    cout << *it << endl;
    return 0;
}


Measured memory_bytes: 1152
############ ---- USER DEFINED INPUT FUNCTIONS ---- ############
def inp():
    return(int(input().rstrip()))
def inlt():
    return(list(map(int,input().rstrip().split())))
def insr():
    s = input().rstrip()
    return(s[:len(s) - 1])
def invr():
    return(map(int,input().rstrip().split()))
################################################################
n,k = invr()
if k >= 2*n:
    print(n)
elif k >= n:
    print(k - n)
else:
    need = n//k
    remain = n%k
    first = need *k
    print(min(n - first,abs(n - first - k)))
#print()


Measured memory_bytes: 3064
#include <algorithm>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <queue>
#include <stack>
#include <utility>
#include <vector>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;

void OutputError(std::string s) {
  cerr << "\033[93m" << s << "\033[m" << endl;
  return;
}

int main(void) {
  cout << std::fixed << std::setprecision(10);
  cin.tie(0);
  std::ios::sync_with_stdio(false);
  std::string x;
  int64_t result = 0;
  cin >> x;
  std::stack<char> stk;
  OutputError("hogee");
  for (auto c : x) {
    OutputError("hogee");
    if (c == 'S') {
      OutputError("push s");
      stk.push('S');
    } else {
      if (stk.size() > 0 && stk.top() == 'S') {
        OutputError("Pop");
        stk.pop();
      } else {
        OutputError("push T");
        stk.push('T');
      }
    }
  }
  cout << stk.size() << endl;

  return 0;
}


Measured memory_bytes: 832
#include <bits/stdc++.h>
#include <cassert>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep2(i, a, b) for(ll i = a; i <= b; ++i)
#define rep3(i, a, b) for(ll i = a; i >= b; --i)
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(c) begin(c), end(c)
#define ok() puts(ok?"Yes":"No");
template<class T> bool chmax(T &a, const T &b) { if(a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if(a > b) { a = b; return true; } return false; }
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using ii = pair<int, int>;
using vvi = vector<vi>;
using vii = vector<ii>;
using gt = greater<int>;
using minq = priority_queue<int, vector<int>, gt>;
using P = pair<ll,ll>;
const ll LINF = 1e18L + 1;
const int INF = 1e9 + 1;
//clang++ -std=c++11 -stdlib=libc++ 

ll a,b,c,d;
int main() {
  cin >> a >> b >> c >> d;
  ll ans = -LINF;
  chmax(ans, a*c);
  chmax(ans, a*d);
  chmax(ans, b*c);
  chmax(ans, b*d);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3648
#include <cstdio>
#include <cstdlib>
#include <algorithm>
using namespace std;
const int N=200010;
inline char get()
{
    static char buf[1024];
    static int pos=0,size=0;
    if(pos==size)
    {
        size=fread(buf,1,1024,stdin);
        pos=0;
        if(!size) return EOF;
        else return buf[pos++];
    }
    else return buf[pos++];     
}
int read()
{
    int sum=0,fh=1;
    char ch=get();
    while(!(ch>='0' && ch<='9'))
    {
        if(ch=='-') fh=-1;
        ch=get();
    }
    while(ch>='0' && ch<='9' && ch!=EOF) sum=sum*10+ch-48,ch=get();
    return sum*fh;
}
int n,d[N],ma[N][2];
int main()
{
	n=read();
	for(int i=1;i<=n;i++)
	{
		d[i]=read();
		ma[i][0]=max(ma[i-1][0],d[i]);
	}
	for(int i=n;i>=1;i--)
		ma[i][1]=max(ma[i+1][1],d[i]);
	for(int i=1;i<=n;i++)
		printf("%d\n",max(ma[i-1][0],ma[i+1][1]));
	return 0;
}

Measured memory_bytes: 3840
// --------------------<optimizations>--------------------
#pragma GCC optimize("O3")

//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)
#pragma GCC optimize("unroll-loops")
// -------------------</optimizations>--------------------
#include <iostream>
#include <bitset>
#include <algorithm>        // sort()
#include <vector>           // for vectors
#include <map>              // for ordered map
#include <unordered_map>
#include <list>             // for list
#include <iomanip>          // for setprecision()
#include <cmath>            // for pow(), sqrt(), log(), log10(), ....
#include <cstring>          // for memset()
#include <unordered_set>    // for unordered_set
#include <climits>          // for INT_MAX & INT_MIN
#include <set>              // for ordered set

#define C ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
typedef long long ll;
#define INF INT_MAX
#define NINF INT_MIN
#define MOD 1000000007
const double pi=acos(-1); // value of pi


bool isVowel(char ch) {
    if(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u') {
        return 1;
    }
    return 0;
}

bool compare(pair<ll, ll> a, pair<ll, ll> b) {
    return a.second<b.second;
}


bool isPrime(ll n) {
    if(n%2==0 && n!=2) {
        return false;
    }
    for(ll i=3; i*i<=n; i+=2) {
        if(n%i==0) {
            return false;
        }
    }
    return true;
}

ll binary_exp(ll x, ll n, ll mod)
{
    if (n == 0) {
        return 1;
    } else if (n == 1) {
        return x % mod;
    } else {
        ll temp = binary_exp(x, n / 2, mod);
        temp = (temp * temp) % mod;

        if (n % 2 == 0) {
            return temp;
        } else {
            return ((x % mod) * temp) % mod;
        }
    }
}

map<ll, ll> m;
// map<ll, ll> m;

int main() {
    C
//     freopen("input.txt","r",stdin);
// 	freopen("output.txt","w",stdout);
    int t=1;
    //cin >> t;
    while(t--) {
        ll n, x, y;
        cin >> n;
        vector<pair<ll, ll>> v;
        for(ll i=0; i<n; i++) {
            cin >> x >> y;
            v.push_back({x, y});
        }
        for(ll i=0; i<n-2; i++) {
            if(v[i].first==v[i].second && v[i+1].first==v[i+1].second && v[i+2].first==v[i+2].second) {
                cout << "Yes" << endl;
                return 0;
            }
        }
        cout << "No" << endl;
    }
}


Measured memory_bytes: 3164
N = int(input())
B = [int(x) - 1 for x in input().split()]
A = ['0'] * N
for i, b in enumerate(B):
  if b > i:
    print(-1)
    break
  else:
    A = A[:b] + [str(b + 1)] + A[b:]
else:
  print('\n'.join(A[:N]))

Measured memory_bytes: 3064
//khodaya khodet komak kon
#include <bits/stdc++.h>

#define F first
#define S second
#define pb push_back
#define all(x) x.begin(), x.end()
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")


using namespace std;

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

const int N = 5000 + 10;
const ll MOD = 1000000000 + 7;
const ll INF = 1000000010;
const ll LOG = 25;

int add(int a, int b){
	a += b;
	if (a >= MOD) a -=MOD;
	return a;
}

int minu(int a, int b){
	a -= b;
	if (a < 0) a += MOD;
	return a;
}

int mul(int a, int b){
	return (a * 1ll * b) % MOD;
}

int POW(int a, int b){
	int res = 1;
	while (b){
		if (b & 1) res = mul(res, a);
		b >>= 1;
		a = mul(a, a);
	}	
	return res;
}

int n, dp[N][N][2], sz[N], T[N], fac[N], inv;
vi G[N];



void pre(){
	inv = POW(2, MOD - 2);
	fac[0] = T[0] = 1;
//	cout << inv << '\n';
	for (int i = 1; i < N; i++) fac[i] = mul(fac[i - 1], i);
	for (int i = 2; i < N; i += 2) T[i] = mul(T[i - 2], mul(inv, mul(i, i - 1)));
	for (int i = 0; i < N; i += 2) T[i] = mul(T[i], POW(fac[i / 2], MOD - 2));
}

void DFS(int v, int p){
	sz[v] = 1;
	dp[v][1][0] = 1;
	int dp2[N][2];
	memset(dp2, 0, sizeof dp2);
	for (auto u:G[v]){
		if (u == p) continue;
		DFS(u, v);
		for (int l = 0; l <= sz[v]; l++) for (int r = 0; r <= sz[u]; r++){
			dp2[l][0] = add(dp2[l][0], mul(dp[v][l][1], mul(T[r], dp[u][r][0])));
			dp2[l][0] = add(dp2[l][0], mul(dp[v][l][0], mul(T[r], dp[u][r][1])));
			dp2[l][1] = add(dp2[l][1], mul(dp[v][l][1], mul(T[r], dp[u][r][1])));
			dp2[l][1] = add(dp2[l][1], mul(dp[v][l][0], mul(T[r], dp[u][r][0])));
			dp2[l + r][0] = add(add(dp2[l + r][0], mul(dp[v][l][0], dp[u][r][0])), mul(dp[v][l][1], dp[u][r][1]));
			dp2[l + r][1] = add(add(dp2[l + r][1], mul(dp[v][l][0], dp[u][r][1])), mul(dp[v][l][1], dp[u][r][0]));
		}
		sz[v] += sz[u]; 
		for (int i = 0; i <= sz[v]; i++) dp[v][i][0] = dp2[i][0], dp[v][i][1] = dp2[i][1], dp2[i][0] = dp2[i][1] = 0;
	}
}

int32_t main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	pre();
//	cout << T[4] << ' ' << T[2] << '\n';
	cin >> n;
	for (int i = 0; i < n - 1; i++){
		int v, u;
		cin >> v >> u;
		G[v].pb(u);
		G[u].pb(v);
	}
	DFS(1, 0);
	int ans = 0;
	for (int i = 0; i < N; i++){
		ans = add(ans, mul(T[i], dp[1][i][0]));
		ans = minu(ans, mul(T[i], dp[1][i][1]));
	}
	cout << ans;











	return 0;
}


Measured memory_bytes: 355200
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

from heapq import *

def solve():
    ll = set([""])
    rr = set()
    for s, c in sc:
        for i in range(len(s)):
            pre = s[:i + 1]
            suf = s[i:]
            ll.add(pre[::-1])
            rr.add(suf[::-1])
    #print(ll)
    #print(rr)

    ln = len(ll)
    rn = len(rr)
    ltou = {l: u for u, l in enumerate(ll)}
    rtou = {r: u + ln for u, r in enumerate(rr)}
    ispal = [False] * (ln + rn)
    for l, u in ltou.items(): ispal[u] = l == l[::-1]
    for r, u in rtou.items(): ispal[u] = r == r[::-1]
    #print("ltou", ltou)
    #print("rtou", rtou)

    to = [[] for _ in range(ln + rn)]
    for s, c in sc:
        c = int(c)
        for l in ll:
            u = ltou[l]
            v = -1
            if l == s: v = ltou[""]
            elif l[:len(s)] == s: v = ltou[l[len(s):]]
            elif l == s[:len(l)]: v = rtou[s[len(l):][::-1]]
            if v != -1: to[u].append((v, c))
        for r in rr:
            u = rtou[r]
            v = -1
            if r == s: v = ltou[""]
            elif r[-len(s):] == s: v = rtou[r[:-len(s)]]
            elif r == s[-len(r):]: v = ltou[s[:-len(r)][::-1]]
            if v != -1: to[u].append((v, c))
    #print(to)

    inf = 10 ** 16
    dist = [inf] * (ln + rn)
    hp = []
    for s, c in sc:
        u = rtou[s[::-1]]
        if dist[u]>int(c):
            heappush(hp, (int(c), u))
            dist[u] = int(c)
    while hp:
        d, u = heappop(hp)
        if d > dist[u]: continue
        for v, c in to[u]:
            if dist[v] <= d + c: continue
            dist[v] = d + c
            heappush(hp, (d + c, v))
    #print(dist)

    ans = min(dist[u] for u in range(ln + rn) if ispal[u])
    if ans == inf: print(-1)
    else: print(ans)

n = II()
sc = [SI().split() for _ in range(n)]
solve()


Measured memory_bytes: 9732
#include <stdio.h>
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>

using namespace std;

int main()
{

	int A = 0;
	int B = 0;

	std::cin >> A >> B;

	std::vector<int> vec(3);
	vec[0] = A + B;
	vec[1] = A - B;
	vec[2] = A * B;

	int max = *std::max_element(vec.begin(), vec.end());

	std::cout << max << std::endl;

	return 0;

}

Measured memory_bytes: 256
n, k = map(int, input().split())

mod = 10**9+7
a = [i for i in range(n+1)]
for i in range(n):
    a[i+1] += a[i]
b = [i for i in range(n, -1, -1)]
for i in range(n):
    b[i+1] += b[i]

ans = 0
for i in range(k-1, n+1):
    ans += b[i] - a[i] + 1
    ans %= mod

print(ans)


Measured memory_bytes: 30196
def main():
    H, W = map(int, input().split())
    s = [input() for _ in range(H)]

    dp = [[1 << 60] * W for _ in range(H)]

    dp[0][0] = int(s[0][0] == '#')

    for r in range(H):
        for c in range(W):
            t = dp[r][c]
            if r > 0:
                t = min(t, dp[r - 1][c] + int(s[r - 1][c] == '.' and s[r][c] == '#'))
            if c > 0:
                t = min(t, dp[r][c - 1] + int(s[r][c - 1] == '.' and s[r][c] == '#'))
            dp[r][c] = t

    print(dp[H - 1][W - 1])


if __name__ == '__main__':
    main()


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

const int RLEN=1<<18|1;
inline char nc() {
	static char ibuf[RLEN],*ib,*ob;
	(ib==ob) && (ob=(ib=ibuf)+fread(ibuf,1,RLEN,stdin));
	return (ib==ob) ? -1 : *ib++;
}
inline int rd() {
	char ch=nc(); int i=0,f=1;
	while(!isdigit(ch)) {if(ch=='-')f=-1; ch=nc();}
	while(isdigit(ch)) {i=(i<<1)+(i<<3)+ch-'0'; ch=nc();}
	return i*f;
}

const int N=5e5+50;
int n,A[N],sum;
char ch[N];
int main() {
	scanf("%s",ch); n=strlen(ch);
	for(int i=0;i<n;++i) A[n-i-1]=ch[i]-'0', sum+=A[n-i-1];
	sum*=9;
	for(int i=0;i<n;i++) A[i]*=9;
	for(int i=0;i<n;i++) {
		if(A[i]>=10) {
			sum-=A[i];
			sum-=A[i+1];
			A[i+1]+=A[i]/10;
			A[i]%=10;
			sum+=A[i];
			sum+=A[i+1];
			if(i+1>=n) ++n;
		}
	}
	for(int k=1;k<=n;++k) {
		A[0]+=9; sum+=9;
		for(int i=0;;++i) {
			if(A[i]>=10) {
				sum-=A[i];
				sum-=A[i+1];
				A[i+1]+=A[i]/10;
				A[i]%=10;
				sum+=A[i];
				sum+=A[i+1];
				if(i+1>=n) ++n;
			} else break;
		}
		if(sum<=9*k && sum%9==0) {cout<<k<<'\n'; return 0;}
	}
}

Measured memory_bytes: 2688
import math
import numpy as np

def cmb(n, r, mod):
  r = min(r, n-r)
  return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 
N = 10**6
g1 = [1, 1] 
g2 = [1, 1] 
inverse = [0, 1] 

for i in range( 2, N + 1 ):
  g1.append( ( g1[-1] * i ) % mod )
  inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
  g2.append( (g2[-1] * inverse[-1]) % mod )

x,y = map(int,input().split()) 

if (x+y) % 3 == 0:

  A = np.array([[1, 2],
                [2, 1]])

  b = np.array([x, y])

  N = np.linalg.solve(A, b)


  if N[0].is_integer() == True and N[1].is_integer() == True and N[0] >=0 and N[1] >=0:
        
      print(cmb(int(N[0]+N[1]),int(N[0]),mod))

  else:
      print(0)

else:
  print(0)

Measured memory_bytes: 132880
#include <algorithm>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
// const int INF = (1 << 30) - 1;
// const ll LL_INF = (1LL << 62) - 1;
// const ll MOD = 1e9 + 7;

string S;
int Q;
// vector<int> A;

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

  string ans = S;
  bool rev = false;
  for (int i = 0; i < Q; i++) {
    int t;
    cin >> t;
    if (t == 1) {
      rev = !rev;
    } else {
      int f;
      string c;
      cin >> f >> c;
      if ((f == 1 && rev) || (f == 2 && !rev)) {
        ans.append(c);
      } else {
        ans.insert(0, c);
      }
    }
  }

  if (rev) {
    reverse(ans.begin(), ans.end());
  }

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


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

// Type alias
using ll=long long;
using ld=double;

using pi=pair<int,int>;
using pll=pair<ll,ll>;
using pld=pair<ld,ld>;
using ti3=tuple<int, int, int>;

using vi=vector<int>;
using vll=vector<ll>;
using vld=vector<ld>;
using vpi=vector<pi>;
using vpll=vector<ll>;
using vpld=vector<ld>;
using vti3=vector<ti3>;

// Constants
const double EPS = 1e-9;
const int inf = numeric_limits<int>::max();

// Macro
#define rep(i,n) for(int i=0;i<int(n);++i)
#define rrep(i,n) for(int i=int(n-1);i>=0;--i)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define RREP(i,a,b) for(int i=int(b-1);i>=int(a);--i)
#define SHOW(a) cout << #a << " = " << a << endl
#define ARR(a,n) for(int i=0;i<int(n);++i) cout << #a << "[" << i << "]" << " = " << a[i] << endl

#define ALL(a) a.begin(),a.end()

// Funtcions
ll pow(ll base, ll i, ll mod){
  ll a = 1;
  while(i){
    if (i & 1) {
      a *= base;
      a %= mod;
    }
    base *= base;
    base %= mod;
    i >>= 1;
  }
  return a;
}
ll gcd(ll a, ll b){
  while(b){
    ll c = a % b;
    a = b;
    b = c;
  }
  return a;
}
ll lcm(ll a, ll b){
  return a / gcd(a, b) * b;
}
template<typename T> bool chmin(T& a, const T& b) {
  if (a > b) return a = b, true; else return false;
}

template<typename T> bool chmax(T& a, const T& b) {
  if (a < b) return a = b, true; else return false;
}

bool kaibun(string s){
  string t(s.rbegin(), s.rend());
  return s == t;
}


void solve(){
  string S;
  cin >> S;

  int N = S.size();
  bool res = kaibun(S) && kaibun(S.substr(0, (N-1) / 2));

  cout << (res ? "Yes" : "No") << endl;
}

int main(){
// FastIO
//ios_base::sync_with_stdio(false);
cin.tie(NULL);
  solve();
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main() {
  string s;
  cin >> s;
  if (s=="hi" || s=="hihi" || s=="hihihi" || s=="hihihihi" || s=="hihihihihi") cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
#define SUBMIT

#include <bits/stdc++.h>

using namespace std;

int main() {
#ifdef SUBMIT
    auto& in = cin;
#else
    stringstream in(R"(6 5 4
)");
#endif
    int a, b, c;
    in >> a >> b >> c;
    auto ans = (a <= c && c <= b) ? "Yes" : "No";
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <array>
#include <iostream>
#include <sstream>

class Dice {
 private:
  std::array<int, 6> inner_;

 public:
  Dice(std::string str) {
    std::istringstream stream(str);
    for(int i = 0; i != 6; ++i) {
      stream >> inner_[i];
    }
  }

  void roll(char dir) {
    std::array<int, 6> new_dice;
    switch(dir) {
    case 'N':
      new_dice[0] = inner_[1];
      new_dice[1] = inner_[5];
      new_dice[2] = inner_[2];
      new_dice[3] = inner_[3];
      new_dice[4] = inner_[0];
      new_dice[5] = inner_[4];
      break;
    case 'S':
      new_dice[0] = inner_[4];
      new_dice[1] = inner_[0];
      new_dice[2] = inner_[2];
      new_dice[3] = inner_[3];
      new_dice[4] = inner_[5];
      new_dice[5] = inner_[1];
      break;
    case 'W':
      new_dice[0] = inner_[2];
      new_dice[1] = inner_[1];
      new_dice[2] = inner_[5];
      new_dice[3] = inner_[0];
      new_dice[4] = inner_[4];
      new_dice[5] = inner_[3];
      break;
    case 'E':
      new_dice[0] = inner_[3];
      new_dice[1] = inner_[1];
      new_dice[2] = inner_[0];
      new_dice[3] = inner_[5];
      new_dice[4] = inner_[4];
      new_dice[5] = inner_[2];
      break;
    }
    inner_ = new_dice;
  }

  int get(int i) {
    return inner_.at(i);
  }

  friend std::ostream &operator<<(std::ostream &out, const Dice &dice) {
    for(int i = 0; i != 5; ++i) {
      out << dice.inner_.at(i) << " ";
    }
    out << dice.inner_.at(5);
    return out;
  }
};

int main() {
  std::string line;
  std::getline(std::cin, line);
  Dice dice(line);
  std::string dirs;
  std::getline(std::cin, dirs);
  for(const auto &dir : dirs) {
    dice.roll(dir);
  }

  std::cout << dice.get(0) << std::endl;

  return 0;
}

Measured memory_bytes: 3136