akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)

int main(){
  int a,b;
  cin >> a >> b;
  int x;
  
  x = a*b;
  if(x%2 == 1) cout << "Odd" << endl;
  else cout << "Even" << endl;
  
  return 0;
}


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

#define ll long long
#define endl "\n"

inline int D()
{
    int m ;
    cin>>m;
    return m ;
}
inline ll lD()
{
    ll m ;
    cin>>m;
    return m ;
}
inline double dD()
{
    double m;
    cin>>m;
    return m;
}
void fast()
{
    ios_base :: sync_with_stdio( 0 ) ;
    cin.tie( 0 ) ;
    cout.tie( 0 ) ;
}
int a[105];
int main()
{
    fast();
    int n=D();
    for(int i=0;i<n;++i)a[i]=D();
    ll ans=10000000000;
    for(int i=1;i<=101;i++){
        ll t=0;
        for(int j=0;j<n;++j){
            t+=(a[j]-i)*1ll*(a[j]-i);
        }
        ans=min(t,ans);
    }
    cout<<ans<<endl;
}


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

struct activity {
    int a,b,c;
};


int solve(vector<activity>& ht,int n) {
    vector<activity>dp(n);
    dp[0].a=ht[0].a;
    dp[0].b=ht[0].b;
    dp[0].c=ht[0].c;

    for(int i=1; i<n; i++) {

            dp[i].a=ht[i].a+max(dp[i-1].b,dp[i-1].c);
            dp[i].b=ht[i].b+max(dp[i-1].a,dp[i-1].c);
            dp[i].c=ht[i].c+max(dp[i-1].b,dp[i-1].a);

    }
    return max(dp[n-1].a,max(dp[n-1].b,dp[n-1].c));
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    if (fopen("input.txt", "r")) {
        freopen("input.txt", "r", stdin);
    }
    int n;
    cin>>n;
    vector<activity>ht;

    for(int i=0; i<n; i++) {
        int a,b,c;
        cin>>a>>b>>c;
        ht.push_back({a,b,c});

    }


    cout<<solve(ht,n)<<endl;

}


Measured memory_bytes: 2676
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

int main() {
	int ct = 0, ans = 0;
	int n;
	string str;
	cin >> n >> str;
	for (int i = 0; i < str.size(); i++) {
		if (str[i] == 'I')ct++;
		else ct--;
		ans = max(ans, ct);
	}
	cout << ans << endl;
	return 0;
}

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

typedef long long LL;

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(x) (x).begin(),(x).end()
const int IINF = 1e9;
const LL LINF = 1e18;
const LL MOD = 1e9+7;

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> A(N);
    REP(i, N) {
        cin >> A[i];
    }
    FOR(i, K, N) {
        if(A[i - K] < A[i]) {
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }
    return 0;
}


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

#define MAX 7200 //テープの容量（秒）

//nは何倍録画かを指定する。
void solve(int time, int n) {
	int ans = (MAX - time) * n;
	int h, m, s;
	h = ans / 3600;
	ans -= h * 3600;
	m = ans / 60;
	ans -= m * 60;
	s = ans;
	
	printf("%02d:%02d:%02d\n", h, m, s);
}

int main(void) {
	int T, H, S;
	int time;
	int ans;
	
	while(cin >> T >> H >> S) {
		if(T == -1 && H == -1 && S == -1) break;
		
		time = T * 3600 + H * 60 + S;
		
		solve(time, 1);
		solve(time, 3);
	}
	
	return 0;
}


Measured memory_bytes: 3132
#include <bits/stdc++.h>
#include <iostream>
#include <string.h>
using namespace std;
int main()
{
	string s,x="...";
	int n;
	cin>>n>>s;
	int k=s.size();
	if (k>n)
	{
		for (int i = 0; i < n; i++) {
			cout<<s[i];
		}
		cout<<x<<endl;
	}
	else
		cout<<s<<endl;
}

Measured memory_bytes: 3636
N, K = map(int, input().split())
p = list(map(int, input().split()))
pp = []
total = 0
for i in range(1, 1001):
    total += i
    pp.append(total/i)
p = [pp[i-1] for i in p]
ans = sum(p[:K])
total = ans
for i in range(N - K):
    total -= p[i]
    total += p[i+K]
    ans = max(ans, total)
print(ans)

Measured memory_bytes: 25060
n,k=map(int,input().split())
a=[int(input()) for _ in range(n)]
l=[[] for i in range(n)]

l[0].append(a[0])
ans=0
for ai in a[1:]:
  for i in reversed(range(ans+1)): # if can a_i put backword, add l[i+1]. because of maximum length answer 
    for li in l[i]:
      if -k<=(li-ai)<=k:
        ans=max(ans,i+1)
        l[i+1].append(ai)
        break
    else:
      continue
    break
  else:
    l[0].append(ai)

print(ans+1)

Measured memory_bytes: 126072
fun main(args: Array<String>) {
    var n = readLine()!!
    var c = false
    for (i in 0..n.length-1){
        if(!(n[i] == 'U'||n[i] == 'D' || i % 2 == 0 && n[i] == 'R'  || i % 2 == 1 && n[i] == 'L'))c = true
    }
    println(if (!c) "Yes" else "No")
}


Measured memory_bytes: 31648
#include<bits/stdc++.h>
using namespace std;
 
int main(){
    unordered_set<string>a;
    int b;
    cin>>b;
    for(int c=0;c<b;c++){
	string d;
	cin>>d;
	a.insert(d);
	}
    bool e=false;
    int f;
    cin>>f;
    for(int g=0;g<f;g++){
	string h;
	cin>>h;
	if(a.find(h)!=a.end()){
	    if(e){e=false;cout<<"Closed by "<<h<<endl;}
	    else {e=true;cout<<"Opened by "<<h<<endl;}
	    }
	   else cout<<"Unknown "<<h<<endl;
	}
    }

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

#define INF 10000000000
#define fi                    first
#define se                    second
#define mp                    make_pair
#define pb                    push_back
#define clr(ara)              memset(ara, 0, sizeof(ara))
#define dp(ara)               memset(ara, -1, sizeof(ara))
#define White                 0
#define Grey                  1
#define Black                 2

#define sf                    scanf
#define pf                    printf

#define test_case(a)          for(int cs = 1; cs <= t; cs++)
#define rep(i, a, b)          for(int i=a;i<b;i++)
#define loop(i,n)             for(int i=0;i<n;i++)

#define READ                  freopen("input.txt", "r", stdin);
#define WRITE                 freopen("output.txt", "w", stdout);

int fx[] = { -1, 1, 0, 0 };
int fy[] = { 0, 0, -1, 1 };

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

int kx[] = { 1, 1, -1, -1, 2, 2, -2, -2 }; // Knight Moves.
int ky[] = { 2, -2, 2, -2, 1, -1, 1, -1 };

typedef  long long            ll;

typedef  map <int,int>	           mii;
typedef  map <int,string>	       mis;
typedef  map <ll, ll>              mll;
typedef  map <char,int>            mci;
typedef  map <string,int>          msi;
typedef  map <string, string>      mss;

typedef  pair <int,int> 	       pii;
typedef  pair <ll, ll>             pll;
typedef  pair <char,int>           pci;
typedef  pair <string,int>         psi;
typedef  pair <string, string>     pss;

typedef  vector<int> 	           vi;
typedef  vector<string> 	       vs;
typedef  vector<char>	           vc;
typedef  vector<bool>              vb;
typedef  vector < pii>             vii;

bool cmp(const pii &a, const pii &b)
{
    return a.fi > b.fi;
}

/*
int values[] = { 40, 10, 100, 90, 20, 25 }; for stl qsort

int compare (const void * a, const void * b)
{
  return ( *(int*)a - *(int*)b );
}
*/

int main()
{
    //qsort (values, 6, sizeof(int), compare); for stl qsort
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll q, h, s, d;
    ll n;

    cin >> q >> h >> s >> d >> n;

    ll qOneL = q * 4;
    ll hOneL = h * 2;
    ll sOneL = s * 1;
    ll dTwoL = d;

    ll mini;

    if(qOneL <= hOneL)
        mini = qOneL;
    else
        mini = hOneL;

    if(mini > sOneL)
        mini = sOneL;

    ll best1 = mini*n;

    ll div =  n / 2;
    ll rem = 0LL;

    if(n % 2) {
        rem = n % 2;
    }

    ll best2 = div*d + rem*mini;

    if(best1 < best2)
        cout << best1 << endl;
    else
        cout << best2 << endl;

    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 998244353;
const ll INF = mod * mod;
typedef pair<int, int>P;
typedef pair<int, bool> sP;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef pair<ll, ll> LP;
typedef vector<ll> vec;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-6;
const ld pi = acos(-1.0);
typedef vector<vector<ll>> mat;
typedef vector<ll> vec;

int trans(string &s) {
	if (s == "SUN")return 0;
	if (s == "MON")return 1;
	if (s == "TUE")return 2;
	if (s == "WED")return 3;
	if (s == "THU")return 4;
	if (s == "FRI")return 5;
	if (s == "SAT")return 6;
}
void solve() {
	string s; cin >> s;
	int id = trans(s);
	cout << 7 - id << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(7);
	//init();
	solve();
	//stop
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define dump(x) cout << #x << " = " << (x) << endl;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

bool cmp(const tuple<string, int, int> &a, const tuple<string, int, int> &b) {
  if(get<0>(a) != get<0>(b)) {
    return get<0>(a) < get<0>(b);
  } else {
    return get<1>(a) > get<1>(b);
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<tuple<string, int, int>> V;
  for(int i = 1; i <= N; i++) {
    string s;
    int p;
    cin >> s >> p;
    V.emplace_back(s, p, i);
  }
  sort(all(V), cmp);
  for(auto x : V) {
    cout << get<2>(x) << endl;
  }
  return 0;
}

Measured memory_bytes: 256
N, M=map(int, input().split())
LR=list(sorted([list(map(int, input().split())) for _ in range(M)]))
a=LR[-1][0]
LR=list(sorted(LR,  key=lambda x: x[1]))
b=LR[0][1]
print(b-a+1 if b>=a else 0)

Measured memory_bytes: 67672
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <iomanip>

#define FOR(i, a, b) for(decltype(b) i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;

using namespace std;

const double pi = 3.14159265358979323846;

vector<pair<double, double>> update(vector<pair<double, double>> v, double l, double r)
{
	vector<pair<double, double>> ov;
	if (r < l)
	{
		ov.push_back(make_pair(l, pi));
		ov.push_back(make_pair(-pi, r));
	}
	else
		ov.push_back(make_pair(l, r));

	vector<pair<double, double>> rs;
	for (const auto& src : v)
		for (const auto& dst : ov)
		{
			pair<double, double> p(max(src.first, dst.first), min(src.second, dst.second));
			if (p.first < p.second)
				rs.push_back(p);
		}
	return rs;
}

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

	vector<pair<int, int>> vv;
	for (int i = 0; i < n; ++i)
	{
		int x, y;
		cin >> x >> y;
		vv.push_back(make_pair(x, y));
	}

	vector<vector<pair<double, double>>> rr(n, vector<pair<double, double>>(1, make_pair(-pi, pi)));

	for (int i = 0; i < n; ++i)
	{
		for (int j = i + 1; j < n; ++j)
		{
			double l = atan2(vv[i].first - vv[j].first, vv[j].second - vv[i].second);
			double r = atan2(vv[j].first - vv[i].first, vv[i].second - vv[j].second);
			rr[i] = update(rr[i], l, r);
			rr[j] = update(rr[j], r, l);
		}
	}

	for (int i = 0; i < n; ++i)
	{
		double p = 0.;
		for (const auto& v : rr[i])
			p += v.second - v.first;

		cout << setprecision(10) << (p / pi / 2.) << endl;

	}

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>

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

#ifdef DEBUG_ON
    freopen("input", "r", stdin);
#endif

    std::string s, t;
    std::cin >> s >> t;
    int maxSame = 0;
    for (int i = 0; i <= s.length() - t.length(); ++i) {
        int curSame = 0;
        for (int j = 0; j < t.length(); ++j) {
            if (s[i + j] == t[j]) {
                ++curSame;
            }
        }
        maxSame = std::max(curSame, maxSame);
    }
    std::cout << t.length() - maxSame;
    return 0;
}

Measured memory_bytes: 3652
N,A,B,C,D=map(int,input().split())
if N//A*B<=N//C*D and N%A==0 and N%C==0:
    print(N//A*B)
elif N//A*B<=(N//C+1)*D and N%A==0:
    print(N//A*B)
elif N//C*D<=(N//A+1)*B and N%C==0:
    print(N//C*D)
elif N//A*B>=(N//C+1)*D and N%A==0:
    print((N//C+1)*D)
elif N//C*D>=(N//A+1)*B and N%C==0:
    print((N//A+1)*B)
elif (N//A+1)*B>=(N//C+1)*D:
    print((N//C+1)*D)
else:
    print((N//A+1)*B)


Measured memory_bytes: 5604
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
typedef long long ll;
const int INF = 1e+9+7;

int main(){
    ll N,K,ans,num;
    cin >>N >> K;
    if(K%2!=0){
        num=N/K;
        ans = pow(num,3);
    }else{

        num=(N/(K/2))/2;
        ans = pow(num,3);
        num=N/(K/2) -num;
        ans += pow(num,3);
    
    }
    cout << ans << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 10;
int a[N];

int main() {
  int n, k;
  scanf("%d%d", &k, &n);
  if(k % 2 == 0) {
    printf("%d ", k / 2);
    for(int i = 2; i <= n; ++i)
      printf("%d ", k);
  } else {
    for(int i = 1; i <= n; ++i) 
      a[i] = k / 2 + 1;
    int yu = n / 2, now = n;
    for(; yu--; ) {
      a[now]--;
      if(a[now]) {
        for(int i = now + 1; i <= n; ++i)
          a[i] = k;
        now = n;
//        printf("yu = %d\n", yu);
//        for(int i = 1; i <= n; ++i)
//          printf("%d ", a[i]);
//        puts("");
      } else {
        now--;
      }
    }
    for(int i = 1; i <= n; ++i)
      if(a[i]) printf("%d ", a[i]);
    puts("");
  }
  return 0;
}

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

int main() {
	int n, m;
	while(true) {
		cin >> n;
		cin >> m;
		
		if(n == 0 && m == 0)
			break;
		
		vector<int> taro;
		vector<int> hanako;
		int taroTotal = 0;
		int hanakoTotal = 0;
		
		
		for(int i = 0; i < n; i++) {
			int p;
			cin >> p;
			taroTotal += p;
			taro.push_back(p);
		}
		for(int i = 0; i < m; i++) {
			int p;
			cin >> p;
			hanakoTotal += p;
			hanako.push_back(p);
		}
		
		int transFromTaro = -1;
		int transFromHanako = -1;
		int transSum = 100000;
		
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < m; j++) {
				int taroP = taro[i];
				int hanakoP = hanako[j];
				if(taroTotal - taroP + hanakoP == hanakoTotal - hanakoP + taroP
						&& taroP + hanakoP < transSum) {
					transFromTaro = taroP;
					transFromHanako = hanakoP;
					transSum = taroP + hanakoP;
				}
			}
		}
		
		if(transFromTaro == -1)
			cout << -1 << endl;
		else
			cout << transFromTaro << " " << transFromHanako << endl;
	}
	
	return 0;
}

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

long long modpow(long long a, long long n, long long mod){
	long long ans = 1;

	while(n > 0){
		if(n & 1){
			ans = ans * a % mod;
		}
		a = a * a % mod;
		n >>= 1;
	}

	return ans;
}

const int modnum = 1000000007;

int main(){
	int n, k, x;
	long long ans = 0;

	cin >> n >> k;

	vector<long long> memo(k+5, 0);
	for(x=k; x>0; x--){
		long long div =  k / x;
		memo[x] = modpow(div, n, modnum);
		for(int i=2; i*x <= k; i++){
			memo[x] -= memo[i*x];
		}
		ans = (ans + x * memo[x] % modnum) % modnum;
	}

	while(ans < 0){
		ans += modnum;
	}

	cout << ans << endl;
}



Measured memory_bytes: 3988
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <set>
#include <list>

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)

using namespace std;

int i,j,k,l,m,n;
/////////////////////////////////////////////////////
#define INF 1010101010101010101;

int N,K;
ll x[101010];
int lnum,hnum,firsth;
int lmin,hmax;
ll lx[101010],hx[101010];
ll ref,ans;

int main(){
    cin>>N>>K;
    for(i=0;i<N;i++){
        cin>>x[i];
    }

    for(i=0;i<N;i++){
        if(x[i]>=0){
            break;
        }
    }

    lnum=i;
    lx[0]=0;
    for(j=lnum;j>0;j--){
        lx[j]=-x[lnum-j];
    }

    if(i<N&&x[i]==0){
        K-=1;
        i++;
    }

    hnum=N-i;
    hx[0]=0;
    for(j=0;j<hnum;j++){
        hx[j+1]=x[i+j];
    }
    if(lnum>=K){
        lnum=K;
        i=0;
    }else{
        i=K-lnum;
    }
    if(hnum>K){
        hnum=K;
    }
    
    ref=INF;
    for(;i<=hnum;i++){
        ans=hx[i]+lx[K-i]+(hx[i]>lx[K-i]?lx[K-i]:hx[i]);
        //cout<<(K-i)<<","<<hx[i]<<","<<lx[K-i]<<" "<<ans <<endl;
        if(ans<ref){
            ref=ans;
        }
    }
    cout<<ref <<endl;
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
using namespace std;
int a[3][3]; 
int main()
{
    //freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
    cin >> a[0][0] >> a[0][1] >> a[1][1];
    int m = a[1][1] * 3;
    a[0][2] = m - a[0][0] - a[0][1];
    a[2][2] = m - a[0][0] - a[1][1];
    a[1][2] = m - a[0][2] - a[2][2];
    a[1][0] = m - a[1][1] - a[1][2];
    a[2][0] = m - a[0][0] - a[1][0];
    a[2][1] = m - a[1][1] - a[0][1];
    for (int i = 0; i <= 2; ++i)
    {
		for (int j = 0; j <= 2; ++j)
			cout << a[i][j] << " ";
		cout << endl; 
	}
    system("pause");
    return 0;
}


Measured memory_bytes: 504
#include <bits/stdc++.h>
using namespace std;
// define
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define SUB(a, b) a = (a+mod-b)%mod
#define MUL(a, b) a = (a * b) % mod
#define rollcall cout << "I'm Sucu." << endl;
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define fi first
#define se second
// debug
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p){
  os << "(" << p.first << "," << p.second << ")";return os;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v){
  for (auto it = v.begin();it != v.end();++it){
    if(it != v.begin())os << " ";os << *it;
      }return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &mp){
  for(auto x: mp)os << "(" << x.first << "," << x.second << ")" << endl;
  return os;
}
template<typename T, int SIZE>
int array_length(const T (&)[SIZE]){return SIZE;}
template<typename T, int N>
void PRINTF(const T (&a)[N], int s = N, int t = -1, bool f = true){
	if(t == -1){rep(i,s){if(i)cout << " ";cout << a[i];}}
	else repi(i,s,t){if(i!=s)cout << " ";cout << a[i];}
	if(f)cout << "\n";
}
template<typename T, int N1, int N2>
void PRINTF(const T (&a)[N1][N2], int h = N1, int w = N2){
	rep(i,h){rep(j,w){cout << a[i][j] << " \n"[j==w-1];}}
}
// typedef
typedef complex<double> Point;
typedef pair<int, int> P;
typedef pair<int, P> PP;
typedef pair<P, int> Pi;
typedef vector<int> vi;
typedef deque<int> dq;
const int inf = 1e9+7;
const int INF = 1e18+7;
const int MAX = 2e5;

int a[MAX], b[MAX], c[MAX];
vector<PP> vec;
int n, sum = 0;
int solve(bool flag){
  int f[] = {1, 1, 0};
  fill(c, c+MAX, 0);
  rep(i,n){
    if(flag and i == n-1)i = n;
    if(vec[i].se.se == 1)f[0] = 0;
    if(vec[i].se.se == 0)f[1] = 0;
  }
  rep(i,n){
    if(flag and i == n-1)i = n;
    if(c[vec[i].se.fi])f[2] = 1;
    c[vec[i].se.fi]++;
  }
  if(f[0] or f[1] or f[2])return 1;
  return 0;
}

signed main(){
  scanf("%lld", &n);
  rep(i,n)scanf("%lld%lld", &a[i], &b[i]);
  rep(i,n){
    vec.push_back(PP(a[i], P(i, 0)));
    vec.push_back(PP(b[i], P(i, 1)));
  }
  sort(all(vec));
  rep(i,n-1)sum += vec[i].fi;
  if(solve(false))printf("%lld\n", sum+vec[n-1].fi);
  else if(solve(true))printf("%lld\n", sum+vec[n].fi);
  else printf("%lld\n", min(sum+vec[n+1].fi, sum-vec[n-2].fi+vec[n-1].fi+vec[n].fi));
  
  
  return 0;
}










Measured memory_bytes: 10992
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
using namespace std;

int main()
{
  	int n,k;
  	cin>>n;
  	cin>>k;
  	int ans=1;
  	for(int i=1;i<=n;i++){
  	   if(ans*2>ans+k)
		   ans=ans+k;
		else
		   ans=2*ans;	
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
s = list(input())
t = list(input())
ans = []
ok = -1
f = -1
if len(s)<len(t):
    print('UNRESTORABLE')
    exit()

for i in range(len(s)-len(t)+1):
    # print(s[i])
    a = 0
    if s[i] == '?' or s[i] == t[0]:
        if f is -1:
            f=i
        for j in range(len(t)):
            # print(i,j,s[i+j],t[j])
            if s[i+j] != '?' and s[i+j] != t[j]:
                break
            a = j
        if a == len(t)-1:
            ok = i
if ok == -1:
    print('UNRESTORABLE')
    exit()
else:
    for i in range(len(s)):
        if s[i] == '?':
            s[i] = 'a'
        if  ok<= i <= ok+len(t)-1:
            s[i] = t[i-ok]

print(''.join(s))


Measured memory_bytes: 3064
w,h,n = map(int,input().split())
wmax = w
wmin = 0
hmax = h
hmin = 0
for i in range(n):
    x,y,a = map(int,input().split())
    if a == 1:
        if wmin < x:
            wmin = x
    elif a == 2:
        if wmax > x:
            wmax = x
    elif a == 3:
        if hmin < y:
            hmin = y
    elif a == 4:
        if hmax > y:
            hmax = y

ver = hmax - hmin if hmax > hmin else 0
hor = wmax - wmin if wmax > wmin else 0

print(ver*hor)

Measured memory_bytes: 3064
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
public class Main {
	public static void main(String[] args)throws IOException {
		FastReader sc = new FastReader();
		PrintWriter pw = new PrintWriter(System.out);
		char s = sc.next().charAt(0);
		if (Character.isLowerCase(s)) {
			System.out.println("a");
		} else
			System.out.println("A");

	}

}





class FastReader {
	BufferedReader br;
	StringTokenizer st;

	public FastReader() {
		br = new BufferedReader(new
		                        InputStreamReader(System.in));
	}

	String next() {
		while (st == null || !st.hasMoreElements()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (IOException  e) {
				e.printStackTrace();
			}
		}
		return st.nextToken();
	}

	int nextInt() {
		return Integer.parseInt(next());
	}

	long nextLong() {
		return Long.parseLong(next());
	}

	double nextDouble() {
		return Double.parseDouble(next());
	}

	String nextLine() {
		String str = "";
		try {
			str = br.readLine();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return str;
	}
}

Measured memory_bytes: 33000
#include <iostream>                                                       
                                                                          
using namespace std;                                                      
                                                                          
int W, H, x, y, r;                                                        
                                                                          
bool judgment(void) {                                                     
                                                                          
   return (x >= r && y >= r && x <= W-r && y <= H-r);                   
                                           
}                                                                         
                                                                          
int main(void) {                                                          
  cin >> W >> H >> x >> y >> r;                                           
  cout << (judgment() ? "Yes" : "No") << endl;                            
}                                                                         
                                          

Measured memory_bytes: 3096
#include <iostream>

using namespace std;

int main() {
    int H, W;
    char S[50][50];
    char tmp;

    cin >> H >> W;

    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            cin >> tmp;
            S[i][j] = tmp;
        }
    }

    bool flag = true;
    for (int j = 0; j < H; j++) {
        for (int i = 0; i < W; i++) {
            if (S[i][j] == '#') {
                if (S[i + 1][j] == '#' || S[i - 1][j] == '#' || S[i][j + 1] == '#' || S[i][j - 1] == '#') {
                    flag = true;
                } else {
                    flag = false;
                    break;
                }
            }
        }
        if (!flag) {
            break;
        }
    }

    if (flag) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

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


// bool isPrime(int n) {
// 	if (n <= 1) {
// 		return false;
// 	}

// 	// Check from 2 to n-1
// 	for (int i = 2; i < n; i++) {
// 		if (n % i == 0) {
// 			return false;
// 		}
// 	}

// 	return true;
// }
int main()
{
	// string S, T;
	// cin >> S >> T;
	// cout << T << S << endl;

	long long A, B, K;
	cin >> A >> B >> K;
	long long ans_A, ans_B;
	if (A <= K) {
		ans_A = 0;
		if (B <= K - A) {
			ans_B = 0;
		} else {
			ans_B = B - (K - A);
		}
	} else {
		ans_A = A - K;
		ans_B = B;
	}
	cout << ans_A << " " << ans_B << endl;
	// int X;
	// cin >> X;

	// while (true) {
	// 	if (isPrime(X)) {
	// 		break;
	// 	}
	// 	X++;
	// }
	// cout << X << endl;
}


Measured memory_bytes: 256
#include<iostream>

int main(){
	int res;
	std::cin >> res;
	char o;
	while(std::cin >> o, o != '='){
		int n;
		std::cin >> n;
		if(o == '+')res += n;
		else if(o == '-')res -= n;
		else if(o == '*')res *= n;
		else if(o == '/')res /= n;
	}
	std::cout << res << std::endl;
}

Measured memory_bytes: 1160
s=[]
while True:
    N=int(input())
    if N==0:
        break
    else:
        tmp=[int(input()) for _ in range(N)]
        tmp.sort()
        tmp=tmp[1:-1]
        s.append(tmp)

for si in s:
    N=len(si)
    ans=0
    for sij in si:
        ans+=sij
    ans//=N
    print(ans)



Measured memory_bytes: 5600
package main

import (
	"fmt"
)

// go run ./main.go < in

func main() {
	var a, b int
	fmt.Scan(&a, &b)

	var houses []int
	for i := 0; i < b; i++ {
		var x int
		fmt.Scan(&x)
		houses = append(houses, x)
	}

	distance := houses[len(houses)-1] - houses[0]
	for i, v := range houses {
		if i == 0 {
			continue
		}
		tmp := a + houses[i-1] - v
		if tmp < distance {
			distance = tmp
		}
	}
	fmt.Println(distance)

}

Measured memory_bytes: 8832
#include <bits/stdc++.h>
#define rep2(i,m,n) for (int i = (int)(m); i < (int)(n); i++)
#define rep(i,n) rep2(i,0,n)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define pb push_back
#define bg begin()
#define ed end()
#define fi first()
#define se second()
using namespace std;
using ll = long long;
using vint = vector<int>;
using pint = pair<int,int>;
using vpint = vector<pint>;
template <typename T>
T sq(T x){
  return x * x;
}
ll mod = 1e9 + 7;

signed main (){
  int N,K;
  cin >> N >> K;
  vint l(N);
  rep(i,N){
cin >> l.at(i);
  }
sort(all(l),greater<int>());
int ans = 0;
rep(i,K){
ans += l.at(i);
}
cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    int ans;
    ans = 0;
    for(int i = 1;i <= n;i++){
        if(1 <= i && i < 10)ans += 1;
        else if(100 <= i && i < 1000)ans += 1;
        else if(10000 <= i && i < 100000)ans += 1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
#include<stdio.h>
#include<string.h>
int decode(char roman)
{
	static const int n[] = {1, 5, 10, 50, 100, 500, 1000};
	static const char* const c = "IVXLCDM";
	return n[strchr(c, roman)-c];
}
int main()
{
	int c, nc, n = 0, pnc = 1000;
	while (c=fgetc(stdin), c!=EOF) {
		if (c == '\n') {
			printf("%d\n", n);
			n = 0;
			pnc = 1000;
		} else {
			nc = decode(c);
			if (pnc < nc)
				n += nc - pnc*2;
			else
				n += nc;
			pnc = nc;
		}
	}
	return 0;
}

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP1(i,n) for(int i=1, i##_len=(n); i<i##_len; ++i)
#define ll long long
static const int MAX = 10000;
static const ll INFTY = 1e12;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const ll MRINF = 5000000000000000;

int main() {

  int X; cin >> X;
  if(X >= 400 && X <= 599){
    cout << 8 << endl;
    return 0;
  }
  if(X >= 600 && X <= 799){
    cout << 7 << endl;
    return 0;
  }
  if(X >= 800 && X <= 999){
    cout << 6 << endl;
    return 0;
  }
  if(X >= 1000 && X <= 1199){
    cout << 5 << endl;
    return 0;
  }
  if(X >= 1200 && X <= 1399){
    cout << 4 << endl;
    return 0;
  }
  if(X >= 1400 && X <= 1599){
    cout << 3 << endl;
    return 0;
  }
  if(X >= 1600 && X <= 1799){
    cout << 2 << endl;
    return 0;
  }
  if(X >= 1800 && X <= 1999){
    cout << 1 << endl;
    return 0;
  }
    

}
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         pass System Test!
*/

Measured memory_bytes: 3648
#include <bits/stdc++.h>
  
using namespace std;
  
template<class T> void ckmin(T &a, T b) { a = min(a, b); }
template<class T> void ckmax(T &a, T b) { a = max(a, b); }
  
#define pb push_back
#define mp make_pair
#define cotu cout
#define itn int
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repr(i,n) for(int i = n - 1; i >= 0; --i)
#define Rep(i, a, n) for(int i = (a); i <=(n); ++i)
#define repst(i, n) for(auto it = n.begin(); it != n.end(); ++it)
#define Repr(i, a, n) for(int i = (n); i >= (a); --i)
#define setp(x) fixed << setprecision(x)
#define ordered_set tree<int , null_type,less<int >, rb_tree_tag,tree_order_statistics_node_update> 
  
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
  
const int inf = int(1e9);
const int mod = inf + 7;
const int N = 3e5 + 555; // TL MB
const double PI = acos(-1.0);
void mul(ll &x, ll y){
	x *= y;
	if(x >= mod) x %= mod;
}
 
void add(ll &x, ll y){
	x += y;
	if(x >= mod) x -= mod;
	if(x < 0) x += mod;
}
ll bp(ll a, ll n){
	ll r = 1;
	while(n){
		if(n & 1) mul(r, a);
		mul(a, a);
		n >>= 1;
	}
	return r; 
}
int vals[N];
int used[N];
vector<int> ord;
vector<pii> g[N], gr[N];
void dfs(int v){
	used[v] = 1;
	for(pii to : g[v]){
		if(!used[to.F]) dfs(to.F);
	}
	ord.pb(v);
}
void solve()
{
	int n, m;
	cin >> n >> m;
	vector<pair<int, pii> > Q;
	rep(i, m){
		int x, y, z;
		cin >> x >> y >> z;
		--x, --y;
		g[x].pb({y, z});
		Q.push_back({x, {y, z}});
	}
	rep(i, n) if(!used[i]) dfs(i);
	reverse(all(ord));
	for(int v : ord){
		for(pii to : g[v]){
			// cout << v << " " << to.F << " " << to.S << '\n';
			vals[to.F] = vals[v] + to.S;
		}
	}
	rep(i, sz(Q)){
		if(vals[Q[i].S.F] - vals[Q[i].F] != Q[i].S.S){
			cout << "No";
			return;
		}
	}
	cout << "Yes";

}
int main()
{
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
    // Red;
  	int T = 1;
  	// cin >> T;
  	for(int i = 1; i <= T; ++i){
  		solve();
  	}
  	return 0;

}

Measured memory_bytes: 27624
s = input()
print('AMBIGUOUS' if 1 <= int(s[0]+s[1]) <= 12 and 1 <= int(s[2]+s[3]) <= 12 else 'YYMM' if 0 <= int(s[0]+s[1]) <= 99 and 1 <= int(s[2] + s[3]) <= 12 else 'MMYY' if  0 <= int(s[2]+s[3]) <= 99 and 1 <= int(s[0] + s[1]) <= 12 else 'NA')

Measured memory_bytes: 3060
n = gets.to_i
s = gets.to_i

if s > n
  puts -1
  exit
elsif s == n
  puts n + 1
  exit
end

def f(b, n)
  return 0 if n == 0
  return f(b, n / b) + (n % b)
end

ans = 1e12

(2..(n ** 0.5)).each do |b|
  ans = b if s == f(b, n) && b < ans
end

(1..(n ** 0.5)).each do |a|
  if (n - s) % a == 0 && (n - s) / a != 0
    b = (n - s) / a + 1
    ans = b if s == f(b, n) && b < ans
  end
end

p ans == 1e12 ? -1 : ans


Measured memory_bytes: 1916
a=input()
for i in range(len(a)):
	if a[i]=='+':
		a1=int(a[:i])
		a2=int(a[i+1:])
		print(a1+a2)
	elif a[i]=='-':
		a1=int(a[:i])
		a2=int(a[i+1:])
		print(a1-a2)

		


Measured memory_bytes: 2940
#include <iostream>
#include <stdio.h>
#include <math.h>
#define MAX 1010
#define PI 3.141592
using namespace std;
int main(){
  int n,i;
  //float x[MAX],y[MAX];
  double rad[MAX]={};
  for(i=2;i<MAX;i++){
    rad[i]=rad[i-1]+atan(1.0/sqrt(i-1));
    if(rad[i]>2*PI) rad[i]-=2*PI; 
    
  }
  cin >> n;
  while (n!=-1){
    printf("%.2f\n%.2f\n",sqrt(n)*cos(rad[n]),sqrt(n)*sin(rad[n]));
    cin >> n;
  }
  
  return 0;
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
#define db double
#define RE register
#define ll long long
#define P 1000000007
#define INF 1000000000
#define get(x) x=read()
#define PLI pair<ll,int>
#define PII pair<int,int>
#define pb(x) push_back(x)
#define ull unsigned long long
#define put(x) printf("%d\n",x)
#define getc(a) scanf("%s",a+1)
#define putl(x) printf("%lld\n",x)
#define rep(i,x,y) for(RE int i=x;i<=y;++i)
#define fep(i,x,y) for(RE int i=x;i>=y;--i)
#define go(x) for(int i=link[x],y=a[i].y;i;y=a[i=a[i].next].y)
using namespace std;
int n;
string s;
map<string,bool>mp;
inline int read()
{
	int x=0,ff=1;
	char ch=getchar();
	while(!isdigit(ch)) {if(ch=='-') ff=-1;ch=getchar();}
	while(isdigit(ch)) {x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
	return x*ff;
}
inline int ceil(int a,int b)
{
	if(a%b==0) return a/b;
	else return a/b+1;
}
int main()
{
	get(n);
	int sum=0;
	rep(i,1,n)
	{
		cin>>s;
		if(mp.find(s)==mp.end())
		{
			mp[s]=true;
			sum++;
		}
	}
	cout<<sum<<endl;
	return 0;
}





Measured memory_bytes: 19216
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <string>

using namespace std;

#define LL long long

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

LL mod(LL x, LL md) {
	return ((x % md) + md) % md;
}

class Mint {
public:
	static LL md;
	LL x;
	Mint(LL _x) {
		x = mod(_x, md);
	}
	Mint(const Mint &y) {
		x = mod(y.x, md);
	}
};

void MintMyExgcd(LL a, LL b, LL &x, LL &y) {
	// solve equation ax + by = 1 (mod m)
	LL md = Mint::md;
	if (b == 0) {
		y = 0;
		x = 1;
		return ;
	}
	MintMyExgcd(b, a % b, x, y);
	LL t = y;
	y = mod(x - (a / b) * y, md);
	x = t;
}

LL MintNY(LL x) {
	if (x == 0) {
		return 1;
	}
	LL md = Mint::md;
	LL a, b;
	MintMyExgcd(x, md, a, b);
	while (a < 0) {
		a += md;
	}
	return a;
}

/* LL gcd(LL a, LL b) {
	if (b == 0) {
		return a;
	}
	return gcd(b, a % b);
} */

Mint operator+(Mint a, Mint b) {
	return Mint(mod(a.x + b.x, Mint::md));
}
Mint operator-(Mint a, Mint b) {
	return Mint(mod(a.x - b.x, Mint::md));
}
Mint operator*(Mint a, Mint b) {
	return Mint(mod(a.x * b.x, Mint::md));
}
Mint operator/(Mint a, Mint b) {
	Mint c = Mint(MintNY(b.x));
	return Mint(mod(a.x * c.x, Mint::md));
}

Mint operator-(Mint a) {
	return Mint(-a.x);
}
bool operator==(Mint a, Mint b) {
	return a.x == b.x;
}
bool operator!=(Mint a, Mint b) {
	return a.x != b.x;
}
bool operator>(Mint a, Mint b) {
	return a.x > b.x;
}
bool operator<(Mint a, Mint b) {
	return a.x < b.x;
}
bool operator>=(Mint a, Mint b) {
	return a.x >= b.x;
}
bool operator<=(Mint a, Mint b) {
	return a.x <= b.x;
}

void operator+=(Mint &a, Mint b) {
	a = a + b;
}
void operator-=(Mint &a, Mint b) {
	a = a - b;
}
void operator*=(Mint &a, Mint b) {
	a = a * b;
}
void operator/=(Mint &a, Mint b) {
	a = a / b;
}

ostream& operator<<(ostream &out, Mint a) {
	out << a.x;
	return out;
}

istream& operator>>(istream &in, Mint &a) {
	in >> a.x;
	return in;
}

Mint factorial(LL n) {
	if (n == 0) {
		return Mint(1);
	}
	Mint res = 1;
	for (LL i = 1; i <= n; ++i) {
		res *= i;
	}
	return res;
}
Mint multiRange(LL s, LL t) {
	Mint res = 1;
	for (LL i = s; i <= t; ++i) {
		res *= i;
	}
	return res;
}

Mint getC(LL n, LL k) {
	if (n - k < k) {
		return getC(n, n - k);
	}
	return multiRange(n - k + 1, n) / factorial(k);
}

Mint getA(LL n, LL k) {
	return multiRange(n - k + 1, n);
}

Mint countNonNegativeDivision(LL n, LL k) {
	return getC(n + k - 1, k - 1);
}
Mint countPositiveDivision(LL n, LL k) {
	if (n < k) {
		return 0;
	}
	if (k <= 0) {
		return 0;
	}
	return getC(n - 1, k - 1);
}
Mint quickMod(Mint a, LL b) {
	Mint res = 1;
	while (b > 0) {
		if (b % 2) {
			res *= a;
		}
		a *= a;
		b /= 2;
	}
	return res;
}

LL Mint::md = 1000000007;

int main() {
		int k;
	int a[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	cin >> k;
	cout << a[k - 1] << endl;
	return 0;
}

Measured memory_bytes: 256
N=int(input())
ls=[input() for i in range(N)]
org_num=0
XA_num=0
BA_num=0
BX_num=0

for i in ls:
    org_num+=i.count('AB')
    listed_word=list(i)
    if listed_word[0]=='B' and listed_word[-1]=='A':
        BA_num+=1
    elif listed_word[0]=='B':
        BX_num+=1
    elif listed_word[-1]=='A':
        XA_num+=1
#print("組み合わせ前のAB個数は",org_num,'個')
#print("X~Aは",XA_num,"個.B~Aは",BA_num,"個.B~Xは",BX_num,"個")

if BX_num:
    BX_num_addition=1
else:
    BX_num_addition=0

if XA_num:
    answer=org_num+BA_num+BX_num_addition
elif BA_num:
    answer=org_num+BA_num+BX_num_addition-1
else:
    answer=org_num

XA_num-=1
BX_num-=1

shiage=min(XA_num,BX_num)
if shiage<0:
    shiage=0

answer+=shiage
print(answer)

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

const int INF = 1001001001;

int main() {
  int n, x, y;
  cin >> n >> x >> y;
  --x; --y;
  vector<int> ans(n);
  rep(sv, n) {
    vector<int> dist(n, INF);
    queue<int> q;
    auto push = [&](int v, int d) {
      if (dist[v] != INF) return;
      dist[v] = d;
      q.push(v);
    };
    push(sv, 0);
    while (!q.empty()) {
      int v = q.front(); q.pop();
      int d = dist[v];
      push(v-1, d+1);
      if (v-1 >= 0) push(v-1, d+1);
      if (v+1 < n) push(v+1, d+1);
      if (v == x) push(y, d+1);
      if (v == y) push(x, d+1);
    }
    rep(i, n) ans[dist[i]]++;
  }
  rep(i,n) ans[i] /= 2;
  for (int i = 1; i <= n-1; ++i) {
    cout << ans[i] << endl;
  }
  return 0;
};

Measured memory_bytes: 256
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef pair<ll,ll> P;
#define fi first
#define se second
#define all(v) (v).begin(),v.end()
set<string> c;
const ll mod=1000000007;
const ll mod2=998244353;
const ll inf=100000000000000000;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
int dp[3500][3500];
int main(){
string s,t;
cin>>s>>t;
int n=s.size(),m=t.size();
for(int i=0;i<n;i++){
    for(int j=0;j<m;j++){
        if(s.at(i)==t.at(j)){
            dp[i+1][j+1]=dp[i][j]+1;
        }
        else{
            dp[i+1][j+1]=max(dp[i+1][j],dp[i][j+1]);
    }
}
}
int d=dp[n][m];
string ans={};
while(1){
    if(d==0)break;
    if(n>0&&dp[n-1][m]==d)n--;
    else if(m>0&&dp[n][m-1]==d)m--;
    else if(n>0){
        ans.push_back(s.at(n-1));
       n--;m--;d--;
    }
}
reverse(all(ans));
cout<<ans<<endl;
}



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

int main(){
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++){
		if (i % 3 == 0){
			cout << " " << i;
		}
		else{
			for (int x = i; x != 0; x /= 10){
				if (x % 10 == 3){
					cout << " " << i;
					break;
				}
			}
		}
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 1160
#include<stdio.h>

int main(void) {
	int A, B, C;
	scanf("%d%d%d", &A, &B, &C);
	if (A == 5 && B == 5 && C == 7) {
		printf("YES\n");

	}
	else if (A == 5 && B == 7 && C == 5) {
		printf("YES\n");

	}
	else if (A == 7 && B == 5 && C == 5) {
		printf("YES\n");
	}
	else {
		printf("NO\n");
	}



	return 0;
}



Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
//using System.Text;
//using System.Text.RegularExpressions;
//using System.Globalization;
//using System.Diagnostics;
using static System.Console;
//using System.Numerics;
//using static System.Math;
//using pair = Pair<int, int>;

class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑
    readonly int mod = 1000000007;
    void chmax<T>(ref T a, T b) where T : IComparable<T> { a = a.CompareTo(b) < 0 ? b : a; }
    void chmin<T>(ref T a, T b) where T : IComparable<T> { a = a.CompareTo(b) < 0 ? a : b; }

    void solve()
    {
        int N = cin.nextint;
        var A = cin.scanlong;
        Array.Sort(A);

        long min = int.MaxValue;
        long ans = -1;
        for (int i = 0; i < N - 1; i++)
        {
            var diff = A[N - 1] - A[i];
            if (Math.Abs(A[i] - diff) < min)
            {
                min = Math.Abs(A[i] - diff);
                ans = A[i];
            }
        }
        WriteLine(A[N - 1] + " " + ans);
    }

}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan { get { return ReadLine().Split(); } }
    public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } }
    public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } }
    public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } }
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint { get { return int.Parse(next); } }
    public long nextlong { get { return long.Parse(next); } }
    public double nextdouble { get { return double.Parse(next); } }
}

Measured memory_bytes: 20320
#include<iostream>
#include<algorithm>
using namespace std;
static const int MAX=200000;

 int main(){
  
  int R[MAX],n;

  cin >> n;

  for(int i=0; i<n ; i++) cin >> R[i];

  int maxv=-2000000000;
  int minv=R[0];

  for(int i=1;i<n;i++){

   maxv=max(maxv,R[i]-minv);
   minv=min(minv,R[i]);

 
}

  cout << maxv << endl; 



 return 0;
}

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

using namespace std;

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

Measured memory_bytes: 3836
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
#define rep(i,n) for(int i=0;i<n;++i)
#define rep2(i,x,n) for(int i=x;i<n;++i)

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

    int m = s.size();
    string ans;
    rep(i,m)
    {
        char c = s[i];
        int idx = c - 'A';
        char rot_c = 'A' + (idx + n) % 26;
        ans += rot_c;
    }

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

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

int main(){
	int n;
	cin >> n;
	vector<int> v(n);
	vector<bool> touched(n);
	for(int i = 0; i < n; i++){
		cin >> v[i];
		touched[i] = false;
	}

	int now = 0;
	int cnt = 0;
	while(!touched[now]){
		touched[now] = true;
		now = v[now] - 1;
		cnt++;
		if(now == 1){
			cout << cnt << endl;
			return 0;
		}
	}
	cout << -1 << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const ll nmax = 8;
const ll INF = 1e9;
bool graph[nmax][nmax];
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}

class UnionFind
{
  public:
    vector<ll> Parent;

    UnionFind(ll N)
    {
        Parent = vector<ll>(N, -1);
    }
    ll find(ll A)
    {
        if (Parent[A] < 0)
            return A;
        return Parent[A] = find(Parent[A]);
    }

    ll size(ll A)
    {
        return -Parent[find(A)];
    }

    bool Union(ll A, ll B)
    {
        A = find(A);
        B = find(B);
        if (A == B)
        {
            return false;
        }
        if (size(A) < size(B))
            swap(A, B);

        Parent[A] += Parent[B];
        Parent[B] = A;

        return true;
    }
};

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

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a / g * b;
}

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}

ll ceil(ll a, ll b)
{
    return (a + b - 1) / b;
}


void solve(std::vector<long long> A){
    if(A[0]+A[1]+A[2] >= 22){
        cout << "bust" << endl;
    }else{
        cout << "win" << endl;
    }
}

int main(){
    std::vector<long long> A(3);
    for(int i = 0 ; i < 3 ; i++){
        scanf("%lld",&A[i]);
    }
    solve(std::move(A));
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi M_PI
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main() {
    string s, t;
    cin >> s >> t;
    s += s;
    REP(i,s.length()/2){
        if (s.substr(i,t.length()) == t){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3208