akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

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

  int x; cin >> x;
  int y; cin >> y;
  ll ans = 1e10;
  
  int s[] = {-1, 1};
  for (int i = 0; i < 2; i++) {
    for (int j = 0; j < 2; j++) {
      int s1 = s[i], s2 = s[j];
      int x1 = x, y1 = y;
      ll temp = 0;
      if (s1 == -1) {
        x1 *= -1;
        temp++;
      }
      if (s2 == -1) {
        y1 *= -1;
        temp++;
      }
      if (x1 <= y1) temp += (y1 - x1);
      else temp = 1e10;
      ans = min(ans, temp);
    }
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define hell 1000000007
#define PI 3.14159265358979323846
#include <fstream>
using namespace std;


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    //cin>>t;
    while(t--) {
     ll n,m,c,i,j,x,y;
     cin>>n>>m>>c;
     vector<pair<ll,ll> >v;
     map<ll,ll> mp1,mp2,t1,t2;
     for(i=0;i<c;i++)
     {
         cin>>x>>y;
         v.pb({x,y});
         mp1[x]++;
         mp2[y]++;
     }
     map<ll,ll> :: iterator it;
     ll mx=0,r,col;
     for(it=mp1.begin();it!=mp1.end();it++)
     {
        if(it->second>mx)
        {
            mx=it->second;
            r=it->first;
        }
     }

     for(i=0;i<c;i++)
     {
         if(v[i].first!=r)
            ++t1[v[i].second];
     }
     ll ans=mx;
     mx=0;
     for(it=t1.begin();it!=t1.end();it++)
        mx=max(mx,it->second);
        ans+=mx;
        mx=0;
        for(it=mp2.begin();it!=mp2.end();it++)
        {
            if(it->second>mx)
            {
                mx=it->second;
                col=it->first;
            }
        }
        for(i=0;i<c;i++)
        {
            if(v[i].second!=col)
                ++t2[v[i].first];
        }
        ll mx2=0;
        for(it=t2.begin();it!=t2.end();it++)
            mx2=max(mx2,it->second);
        ans=max(ans,mx+mx2);
        cout<<ans;
    }
}


Measured memory_bytes: 82952
using System;
using System.Collections.Generic;

namespace ABC127 {
	class Program {
		struct Rule : IComparable<Rule>
		{
			public int b,
			c;
			public Rule(int i_b, int i_c)
			{
				b = i_b;
				c = i_c;
			}
			public int CompareTo(Rule other)
			{
				// intと降順と昇順を逆にしたいので工夫する
				int cCompareTo = this.c.CompareTo(other.c);
				if (cCompareTo != 0)
				{
					return -cCompareTo;
				}
				int bCompareTo = this.b.CompareTo(other.b);
				return -bCompareTo;
			}
		}
		static void Main (string[] args) {
			// 入力
			int N, M;
			int[] firstArray = Array.ConvertAll (Console.ReadLine ().Split (' '), int.Parse);
			N = firstArray[0];
			M = firstArray[1];
			int[] secondArray = Array.ConvertAll (Console.ReadLine ().Split (' '), int.Parse);
			List<int> A = new List<int> (N);
			for (int i = 0; i < N; i++) {
				A.Add (secondArray[i]);
			}
			List<Rule> rules = new List<Rule> (M);
			for (int i = 0; i < M; i++) {
				int[] array = Array.ConvertAll (Console.ReadLine ().Split (' '), int.Parse);
				rules.Add (new Rule (array[0], array[1]));
			}
			// 処理・出力
			/*	正攻法はこう
				- 0~M-1に対して以下の処理
					- A[]をソート
					- A[0]~A[B[i]]のうち、C[i]以下のものをC[i]に書き換え(これのせいでO(n^2)となる)
				- これで最大の時の結果が出る。あとは和を求めればよい。
				こいつの非効率なところは「同じ値を書き換えまくる」である。
				A[i]は１回しか書き換えないようなアルゴリズムは、こう。
				- A[]をソート
				- B[i],C[i]をC[i]が大きい順にソート
				- A[]を上から順に「B[i]個だけC[i]に書き換える、ただしA[j]>=C[i]となったらもう書き換えない」をする
			 **/
			// Aをソート
			A.Sort ();
			// B,Cをソート
			rules.Sort ();
			// Aを書き換え
			int rulesIndex = 0;
			int aIndex = 0;
			while (aIndex < N && rulesIndex < M) {
				for (int i = aIndex; i < aIndex + rules[rulesIndex].b; i++) {
					if (i >= N) {
						// 書き換え終了
						aIndex = N;
						break;
					}
					if (A[i] < rules[rulesIndex].c) {
						A[i] = rules[rulesIndex].c;
					} else {
						// 書き換え終了
						aIndex = N;
						break;
					}
				}
				aIndex += rules[rulesIndex].b;
				rulesIndex++;
			}
			// 合計値の計算
			Int64 total = 0;
			for (int i = 0; i < N; i++) {
				total += A[i];
			}
			Console.WriteLine (total);
		}
	}
}

Measured memory_bytes: 30268
#include "bits/stdc++.h"

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

const ll INF = 1LL << 60;
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
	string s;
	vector<ll> v[26];
	string ss = "abcdefghijklmnopqrstuvwxyz";

	cin >> s;

	REP(i, s.size()) {
		v[s[i] - 'a'].push_back(i);
	}

	vector<ll> vv(26, 0);
	stack<pair<ll, ll>> st;
	ll e = s.size() - 1;
	ll now = 1;
	ll c = 0;
	ll k = 0;

	RREP(i, s.size()) {
		if (vv[s[i] - 'a'] != now) {
			vv[s[i] - 'a']++;
			c++;
		}

		if (c == 26) {
			st.push(make_pair(i, e));
			e = i - 1;
			now++;
			c = 0;
			k++;
		}

		if (i == 0) {
			st.push(make_pair(0, e));
			break;
		}
	}

	ll point = -1;

	REP(i, k + 1) {
		pair<ll, ll> p = st.top();
		st.pop();
		REP(j, 26) {
			vector<ll>::iterator it = upper_bound(v[j].begin(), v[j].end(), point);
			if (it == v[j].end() || *it < p.first || *it > p.second) {
				cout << ss[j];
				if (it != v[j].end()) {
					point = *it;
				}
				break;
			}
		}
	}

	cout << endl;
}

Measured memory_bytes: 2436
/**
 *   Author: Praveen Ojha
 *   Created: 14 April 2019
 *   Time: 07:06:53
**/
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define mod 1000000007
#define inf 1e18+5
#define PI 3.141592653589793238510
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define __ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define vi vector<int>
#define vpii vector<pair<int,int> > 
#define vvi vector<vector<int> >
#define PRINT_TIME cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s." <<endl;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename   enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
typedef long double ld;
typedef pair<int,int> pii;
/////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////

int32_t main(){__
	int n;
	cin>>n;
	vi a(n);
	for(int i=0;i<n;i++)
		cin>>a[i];
	int cnt=0;
	for(int i=0;i<n;i++){
		int flag=1;
		for(int j=0;j<i;j++){
			if(a[j]>a[i])
				flag=0;
				
		}
		if(flag)
			cnt++;
	}
	cout<<cnt<<"\n";
return 0;
}

Measured memory_bytes: 256
n=int(input())
s=input()
r=g=b=0
for i in s:
  if i=="R":r+=1
  elif i=="G":g+=1
  else:b+=1
ans=r*g*b
for i in range(1,n//2+2):
  for j in range(n):
    if j+i+i>=n:break
    if not(s[j]==s[j+i] or s[j+i]==s[j+i+i] or s[j]==s[j+i+i]):ans-=1
print(ans)

Measured memory_bytes: 9216
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;


int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	Int N, M;
	cin >> N >> M;

	vector<Int> L(M);
	vector<Int> R(M);

	for (Int i = 0; i < M; i++) {
		cin >> L[i] >> R[i];
	}

	Int l = 0;
	Int r = INF;

	for (int i = 0; i < M; i++) {
		l = max(l, L[i]);
		r = min(r, R[i]);
	}

	Int ans = max(0LL, r - l + 1);

	cout << ans;

}

Measured memory_bytes: 1792
# Problem D - Alter Altar
# input
N = int(input())
c_list = list(input())

# initialization
red_count = 0
white_count = 0
swap_count = 0

# count
for c in c_list:
    if c=="R":
        red_count += 1
    else:
        white_count += 1

# swap count
w_i = 0
r_i = N-1
while r_i>w_i:
    if c_list[r_i]=="R":
        find_white = False
        # white search
        while r_i>w_i and w_i<=N-1:
            if c_list[w_i]=="W":
                find_white = True
                break
            w_i += 1
        # swap
        if find_white:
            tmp = c_list[r_i]
            c_list[r_i] = c_list[w_i]
            c_list[w_i] = tmp
            swap_count += 1
    else:
        r_i -= 1

# output
ans = min(red_count, white_count, swap_count)
print(ans)


Measured memory_bytes: 10840
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws NumberFormatException,
			IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(
				System.in));
		StringBuilder builder = new StringBuilder();
		StringTokenizer to;
		char[] cs = reader.readLine().toCharArray();
		for(int i=cs.length-1;i>=0;i--){
			builder.append(cs[i]);
		}
		System.out.println(builder);

	}

}

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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFやMODの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const ll MOD = 1000000007;

int main() {
  string s, t;
  cin >> s >> t;
  int a, b;
  cin >> a >> b;
  map<string, int> m;
  m[s] = a;
  m[t] = b;
  string u;
  cin >> u;
  m[u]--;

  cout << m[s] << ' ' << m[t] << endl;
}


Measured memory_bytes: 256
def main():

    N, M = map(int, input().split())
    S = input()
    T = input()
    p = gcd(N, M)
    n = N // p
    m = M // p
    for i in range(p):
        if S[i*n] != T[i*m]:
            return "-1"
    return p*n*m


def gcd(a, b):
    if a > b:
        a, b = b, a
    if a == 0:
        return b
    else:
        return gcd(b % a, a)

if __name__ == '__main__':
    print(main())

Measured memory_bytes: 3316
#include <iostream>

#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
#define FILL0(x) memset(x,0,sizeof(x))

using namespace std;

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

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

int main()
{
    ll N;
 
    cin >> N;
    ll ans=0;
    rep(i, N)
    {
        if(((i+1)%3)!=0&&((i+1)%5)!=0)
        {
            //cout << i+1 << endl;
            ans+=i+1;
        }
    }

 
    cout << ans << endl;
 

    return 0;
}
 

//cout << setprecision(13);
//next_permutation();
//__gcd();
//reverse();
//set ,tuple ,pair;
//bitset
//vector.find



Measured memory_bytes: 3632
#include <string>
#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <set>
typedef long long ll;
const int mod=1e9+7;
#define lol(i,n) for(int i=0;i<n;i++)

using namespace std;
int n,a[110],ans=0;
int main() {
    cin >>n;
    lol(i,n){
        cin >> a[i];
        if(a[i]%2==0)ans++;
    }
    cout << ans << endl;
}



Measured memory_bytes: 3124
def main():
    n = int(input())
    s = input()
    r,g,b = 0,0,0
    for i in s:
        if i == 'R': r += 1
        elif i == 'G': g += 1
        elif i == 'B': b += 1
    ans = r*g*b
    for j in range(n):
        sj = s[j]
        for i in range(j):
            k = j+(j-i)
            if k < n:
                si = s[i]
                sk = s[k]
                if si == sj or si == sk or sk == sj:
                    continue
                ans -= 1
    print(ans)
if __name__ == "__main__":
    main()

Measured memory_bytes: 9204
#include<bits/stdc++.h>
using namespace std;
int main(){
	int x,y;
	cin>>x>>y;
	if(x==y||((x>y)&x%y==0)){
		cout<<"-1"<<endl;
	}else{
		for(int i=2;(long long)i*x<(long long)1e18;i++){
			if(i*x%y){
				cout<<(long long)i*x<<endl;
				break;
			}
		}
	}
	return 0;
}

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

#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()

using namespace std;
typedef long long  ll; typedef vector<int> VI; typedef pair<int,int> pii; typedef vector<ll> VL; const int MD = 1e9 + 7;
void dbg(){cerr<<"\n";} template <class F,class ...S> void dbg(const F& f, const S&...s){cerr <<f <<": "; dbg(s...);}



int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n, k;
	cin >>n >>k;
	VI a(n);
	rep(i, n) cin >>a[i];
	
	ll mx = *max_element(all(a));
	auto fnc=[&](ll m){
		int rtn =0;
		rep(i, n){
			rtn += (a[i]+m-1)/m -1;
		}
		return rtn;
	};
	
	ll lf = 0, rg = mx;
	while(rg - lf >1){
		ll md = (rg + lf) >> 1;
		ll ww=fnc(md);
		//dbg(md, ww, k);
		if(  ww<= k ) rg = md; else lf = md; 
	}

	cout << rg <<"\n";
	return 0;
}



Measured memory_bytes: 3900
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
typedef long long ll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000001
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
int main()
{
    int n,h;
    cin >> n >> h;
    char x[105][25];
    int t[105];
    int len[105];
    for(int i=0;i<n;i++)
    {
        scanf("%s%d",x[i],&t[i]);
        len[i] = strlen(x[i]);
    }
    int ok=0,sum=0;
    for(int i=0;i<n;i++)
    {
        int nx = 0,miss = 0;
        while(1)
        {
            printf("? %s\n", x[i]);
            fflush(stdout);
            char c[2];
            scanf("%s", c);
            int q,w;
            if(x[i][nx] >= 'a' && x[i][nx] <= 'z') q = x[i][nx]-'a';
            else q = x[i][nx]-'A';
            if(c[0] >= 'a' && c[0] <= 'z') w = c[0]-'a';
            else w = c[0]-'A';
            sum++;
            if(q == w)
            {
                x[i][nx] = '_'; nx++; ok++;
                if(nx == len[i]) break;
            }
            else
            {
                miss++;
                if(miss > t[i])
                {
                    h--;
                    if(h == 0)
                    {
                        printf("! Game Over\n"); fflush(stdout); return 0;
                    }
                    break;
                }
            }
        }
    }
    double xx = (double)ok/(double)sum*1000;
    int s = floor(xx);
    printf("! Game Clear %.1lf\n", (double)s/10.0); fflush(stdout); return 0;
}

Measured memory_bytes: 1300
#include <iostream>
using namespace std;
int main(void){
   int H,W;
   while(true){
       cin >> H >> W;
       for(int i=0;i<H;i++){
           for(int j=0;j<W;j++){
               cout << "#";
           }
       cout << endl;
       }if(W == 0 && H == 0){
           break;
       }
       cout << endl;
   }
}


Measured memory_bytes: 3088
//---------------------------------------------------------------
#include <bits/stdc++.h>
using namespace std;
#include <iostream>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <math.h>
#include <sstream>
#include <numeric>
#include <cctype>
#include <bitset>
#include <cassert>
#include<algorithm>
//---------------------------------------------------------------
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define SIZE 100005
#define INF 1000000000000000LL
#define all(x) x.begin(),x.end()
using pint = pair<int,int>;
using vec = vector<int>;
using ll=long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
//---------------------------------------------------------------
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
//---------------------------------------------------------------

//↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓


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

    int n;cin>>n;
    vector<string> s(n);
    rep(i,n){
        cin>>s[i];
    }

    sort(s.begin(),s.end());
    int cnt=0;
    rep(i,n-1){
        if(s[i]==s[i+1]) cnt++; 
    }

    cout<<n-cnt<<endl;
}

Measured memory_bytes: 9536
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC omodtimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
using namespace __gnu_pbds;
using namespace std;
 
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<long long ,long long> ii; 	
typedef complex<long double> com;
 
const ll mod = 1e9+7;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	vector <ll> arr = {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};
	ll k;
	cin >> k;
	cout << arr[k-1] << endl;
}

Measured memory_bytes: 256
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iostream>
#include <iostream>
#include <fstream>
#include <numeric>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <cmath>
#include <set>
#include <map>
#include <functional>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <cstdint>
#include <chrono>

using namespace std;
#define     loop(n,i,a)     for(ll i=a;i<n;i++)
#define     loopR(n,i,a)    for(ll i=a-1;i>=n;i--)
#define     all(arr,n)      arr,arr+n
#define     allv(v)         (v).begin(),(v).end()
#define     rallv(v)        (v).rbegin(),(v).rend()
#define     m_p             make_pair
#define     ll              long long
#define     pii             pair<ll,ll>
#define     vi              vector<int>
#define     vll             vector<ll>
#define     vii             vector<pii>
#define     sz(x)           (int)x.size()
#define     pb              push_back
#define     endl            "\n"
#define     Endl            "\n"
#define     f               first
#define     s               second
#define     mem(dp,n)       memset(dp,n,sizeof dp)
template<typename T>void max_self(T &a,T b){a=max(a,b);}
template<typename T>void min_self(T &a,T b){a=min(a,b);}
int dx[] = { 1 , 0 ,-1 , 0 ,-1 ,-1 , 1 , 1 };
int dy[] = { 0 , 1 , 0 ,-1 ,-1 , 1 ,-1 , 1 };
int KnightI[] = { 2, 1, -1, -2, -2, -1, 1, 2 };
int KnightJ[] = { 1, 2, 2, 1, -1, -2, -2, -1 };
void fast(){
    std::ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
}
vector<string> vec_splitter(string s) {
    s += ',';
    vector<string> res;
    while(!s.empty()) {
        res.push_back(s.substr(0, s.find(',')));
        s = s.substr(s.find(',') + 1);
    }
    return res;
}
void debug_out(
        vector<string> __attribute__ ((unused)) args,
        __attribute__ ((unused)) int idx,
        __attribute__ ((unused)) int LINE_NUM) { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
    if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
    stringstream ss; ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, LINE_NUM, T...);
}
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
const ll mxN=3e5+10,oo=0x3f3f3f3f,MOD=998244353;
const long double PI = acos(-1),eps=1.0e-14;

void solve(){
    string s;
    cin>>s;
    cout<<(s.front()==s.back()?"Yes":"No")<<endl;
}
int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    fast();
    solve();

}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define pow(x,y) modpow(x,y)
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REPS(i,n) for(ll (i)=1;(i)<=(n);(i)++)
#define RREP(i,n) for(ll (i)=(n-1);(i)>=0;(i)--)
#define RREPS(i,n) for(ll (i)=(n);(i)>0;(i)--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());

template <class T = int>T in(){
    T x;
    cin >> x;
    return (x);
}

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

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

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    int N = in(), M = in();
    vector<pair<int,int>> S(N);
    vector<pair<int,int>> C(M);
    REP(i,N){
        S[i].F = in();
        S[i].S = in();
    }
    REP(i,M){
        C[i].F = in();
        C[i].S = in();
    }
    REP(i,N){
        int dist = INT32_MAX;
        int num = INT32_MAX;
        REP(l,M){
            if(abs(S[i].F - C[l].F) + abs(S[i].S - C[l].S) < dist){
                dist = abs(S[i].F - C[l].F) + abs(S[i].S - C[l].S);
                num = l;
            }
        }
        cout << num+1 << "\n";
    }
}

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

void solve() {
  int n, m;
  cin >> n >> m;
  int l = 1;
  int r = n;
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    l = max(l, a);
    r = min(r, b);
  }
  if (r-l<0) cout << 0 << endl;
  else cout << r-l+1 << endl;
}

int main() {
  solve();
  return 0;
}

Measured memory_bytes: 256
//_nebula_
#include<bits/stdc++.h>
using namespace std;
#define int long  long
#define double long double
int t;
const int M=1e9+7;
const int inf=INT64_MAX;
int max(int a,int b,int c){
    return max(a,max(b,c));
}
int min(int a,int b,int c){
    return min(a,min(b,c));
}
int fspow(int x,int y){
    int ans;
    if(y==0) return 1;
    ans=fspow(x, y/2);
    if(y%2==0) return ((ans*ans)%M);
    return (x*((ans*ans)%M))%M;
}
int gcd(int x,int y){
    if(x<y) swap(x,y);
    if(y==0) return x;
    return gcd(x%y,y);
}
int p2(int x){
    int ans=0;
    while(x>1){
        ans++;
        x/=2;
    }
    return ans;
}
vector<int>grp[100005];
bool vis[100005];
void dfs(int s){
    if(vis[s]) return;
    vis[s]=1;
    for(auto i:grp[s]) dfs(i);
}
signed main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    t=1;
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
   //  cin>>t;
    //int tmp=t;
    while(t--){
        int n,m;
        cin>>n>>m;
        for(int i=0;i<m;i++){
            int u,v;
            cin>>u>>v;
            grp[u].push_back(v);
            grp[v].push_back(u);
        }
        int ans=0;
        for(int i=1;i<=n;i++){
            if(vis[i]) continue;
            ans++;
            dfs(i);
        }
        cout<<ans-1<<"\n";
    }
}


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

int main(void)
{
	int A, B, C, D;
	cin >> A >> B >> C >> D;

	while (1) {
		C -= B;
		if (C <= 0) {
			cout << "Yes" << endl;
			break;
		}
		A -= D;
		if (A <= 0) {
			cout << "No" << endl;
			break;
		}
	}

	return 0;
}


Measured memory_bytes: 3560
#include <bits/stdc++.h>
#define INF (1<<30)
#define INFLL (1ll<<60)
#define EPS (1e-10)
using namespace std;
map <int,int> mp;
typedef pair<int, int> P;
typedef long long ll;
static const int MAX=100000;
static const int NMAX=50;
static const int MMAX=50;
string s;
int main(){
    cin>>s;
    if(s.size()==4) cout<<"ABD"<<"\n";
    else cout<<"ABC"<<"\n";
    return 0;
}


Measured memory_bytes: 256
//#pragma warning disable

using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;

public class Test
{
    public static void Main()
    {
        var line1 = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
        var N = line1[0];
        var K = line1[1];

        var a = new long[N];
        var b = new long[N];

        for (var i = 0; i < N; i++)
        {
            var line2 = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
            a[i] = line2[0];
            b[i] = line2[1];
        }

        var sorted = Enumerable.Range(0, (int)N).Select(i => Tuple.Create(a[i], b[i])).OrderBy(x => x.Item1).ToArray();

        long sum = 0;

        foreach (var tuple in sorted)
        {
            sum += tuple.Item2;

            if (sum >= K)
            {
                Console.WriteLine(tuple.Item1);
                return;
            }
        }
    }
}

Measured memory_bytes: 29872
#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>;

int main()
{
    int h, w, k;
    cin >> h >> w >> k;
    vector<string> c(h);
    rep(i, h) {
        cin >> c[i];
    }

    int black_org = 0;
    rep(i, h) {
        rep(j, w) {
            if (c[i][j] == '#') ++black_org;
        }
    }
    int ans = 0;
    rep(i, 1 << h) {
        rep(j, 1 << w) {
            int black = black_org;
            rep(k, h) {
                rep(l, w) {
                    if (i & (1 << k) && c[k][l] == '#') {
                        --black;
                    } else if (!(i & (1 << k)) && j & (1 << l) && c[k][l] == '#') {
                        --black;
                    }
                }
            }
            if (black == k) ++ans;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i,n) for(int i=0;i<n;++i)
#define all(v) v.begin(), v.end()
#define PI 3.141592653589793238462643383279
typedef long long int ll;
typedef unsigned long long ull;
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
typedef pair<ll,ll> P;
const long long MOD = 1e9+7;
const ll INF = 1LL << 60;


string moji(int i,int j,int k){
    string s;
    s += to_string(i)+to_string(j)+to_string(k);
    return s;
}

int main(){
    int n;
    string s;
    cin >> n >> s;
    int cnt = 0;

   for(int i = 0; i < 10; i++){
       for(int j = 0; j < 10; j++){
           for(int k = 0; k < 10; k++){
               string a = moji(i,j,k);

                int index = 0;
                for(int i = 0; i < s.size(); i++){
                    if(s[i] == a[index]){
                        index++;
                    }
                    if(index == a.size()){
                        cnt++;
                        break;
                    }
                }
           }
       }
   }

    cout << cnt << endl;

    



}

Measured memory_bytes: 3724
#include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>

using ll = long long int;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int n;
int a[225816],segtree[816225],ans[225816];
std::vector<int> g[225816],x;

void update(int p, int v, int i=0, int l = 0, int r=n){
	if(!(l<=p && p<r)){
		return;
	}else if(r-l>1){
		update(p,v,i*2+1,l,(l+r)/2);
		update(p,v,i*2+2,(l+r)/2,r);
		segtree[i] = std::max(segtree[i*2+1],segtree[i*2+2]);
	}else{
		segtree[i] = v;
	}
}

int query(int p, int q, int i=0, int l=0, int r=n){
	if(r<=p||q<=l){
		return 0;
	}else if(p<=l && r<=q){
		return segtree[i];
	}else{
		return std::max(query(p,q,i*2+1,l,(l+r)/2),query(p,q,i*2+2,(l+r)/2,r));
	}
}

void solve(int v, int p){
	int i,q,before,u;
	q = (int)(lower_bound(x.begin(),x.end(),a[v])-x.begin());
	before = query(q,q+1);
	ans[v] = query(0,q)+1;
	update(q,std::max(ans[v],before));
	for(i=(g[v].l_ength()-1); i>=0; --i){
		u = g[v][i];
		if(u==p){
			continue;
		}
		solve(u,v);
	}
	update(q,before);
}

void solve2(int v, int p){
	int i,u;
	for(i=(g[v].l_ength()-1); i>=0; --i){
		u = g[v][i];
		if(u==p){
			continue;
		}
		ans[u] = std::max(ans[v],ans[u]);
		solve2(u,v);
	}
}

int main(void){
	int u,v,i;
	std::cin >> n;
	for(i=0; i<n; ++i){
		std::cin >> a[i];
		x.push_back(a[i]);
	}
	std::sort(x.begin(),x.end());
	for(i=1; i<n; ++i){
		std::cin >> u >> v;
		--u; --v;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	solve(0,-1);
	solve2(0,-1);
	for(i=0; i<n; ++i){
		std::cout << ans[i] << std::endl;
	}
	return 0;
}


Measured memory_bytes: 33648
a = []
op = []
b = []

while True:
    a1, op1, b1 = input().split()
    a1 = int(a1)
    b1 = int(b1)
    if op1 == '?':
        break
    elif op1 == '+':
        print(a1+b1)
    elif op1 == '-':
        print(a1-b1)
    elif op1 == '*':
        print(a1*b1)
    elif op1 == '/':
        print(a1//b1)



Measured memory_bytes: 5596
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 100000000
using namespace std;

int T,N;
int t[30],ti[101];
int dp[101][30];

int main(){
	while(cin>>T,T){
		rep(i,T)cin>>t[i];
		rep(i,101)ti[i]=INF;
		rep(i,101)rep(j,30)dp[i][j]=INF;
		dp[1][0]=0;
		cin>>N;
		rep(i,N){
			int d,m;
			cin>>d>>m;
			ti[d]=min(ti[d],m);
		}
		int ans=INF;
		for(int i=2;i<=100;i++){
			if(ti[i]==INF){
				rep(j,T)dp[i][(j+1)%T]=dp[i-1][j];
				rep(j,T)dp[i][0]=min(dp[i][0],dp[i-1][j]+1);
				continue;
			}
			rep(j,T){
				dp[i][0]=min(dp[i][0],dp[i-1][j]+1);
				if(ti[i]>=t[(j+1)%T]){
					dp[i][(j+1)%T]=min(dp[i][(j+1)%T],dp[i-1][j]);
				}
			}
		}
		rep(i,T)ans=min(ans,dp[100][i]);
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 1172
class BinaryIndexedTree():
    def __init__(self, max_n):
        self.size = max_n + 1
        self.tree = [0] * self.size
        self.depth = self.size.bit_length()
 
    def initialize(self, seq):
        for i, x in enumerate(seq[1:], 1):
            self.tree[i] += x
            j = i + (i & (-i))
            if j < self.size:
                self.tree[j] += self.tree[i]
 
    def __repr__(self):
        return self.tree.__repr__()
 
    def get_sum(self, i):
        s = 0
        while i:
            s += self.tree[i]
            i -= i & -i
        return s
 
    def add(self, i, x):
        while i < self.size:
            self.tree[i] += x
            i += i & -i
 
    def find_kth_element(self, k):
        x, sx = 0, 0
        dx = (1 << self.depth)
        for i in range(self.depth - 1, -1, -1):
            dx = (1 << i)
            if x + dx >= self.size:
                continue
            y = x + dx
            sy = sx + self.tree[y]
            if sy < k:
                x, sx = y, sy
        return x + 1



n = int(input())
s = ["!"]+list(input())
q = int(input())
bit = [BinaryIndexedTree(n+1) for i in range(26)]

for i in range(n):
    ind = ord(s[i+1])-97
    bit[ind].add(i+1,1)

for i in range(q):
    a,b,c = input().split()
    b = int(b)
    if a == "1":
        ind = ord(s[b])-97
        bit[ind].add(b,-1)
        ind = ord(c)-97
        bit[ind].add(b,1)
        s[b] = c
    else:
        ans = 0
        c = int(c)
        for i in range(26):
            if bit[i].get_sum(c)-bit[i].get_sum(b-1):
                ans += 1
        print(ans)

Measured memory_bytes: 207244
n=int(input())
COM=[[] for i in range(n)]

for i in range(n):
    a=int(input())
    for q in range(a):
        x,y=map(int,input().split())
        COM[i].append((x-1,y))

ans=0
for i in range(2**n):
    sco=bin(i).count("1")
    if sco<=ans:
        continue
    end=False
    #print(i)
    for q in range(n):
        if (i>>q)&1==1:
            for que in COM[q]:
                #print(que,que[0],(i>>que[0])&1,que[1])
                if (i>>que[0])&1!=que[1]:
                    end=True
                    break
            if end:
                break
    if end:
        continue
    #print("!")
    ans=sco
print(ans)
    

Measured memory_bytes: 74160
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <algorithm>
#include <string>
#include <numeric>
using namespace std;
int gcd(int a, int b);
int main()
{
    int n, w;
    cin >> n >> w;
    pair<int, int> vw[n];
    int calc[w + 1][n];
    for (int i = 0; i < n; i++)
    {
        cin >> vw[i].first >> vw[i].second;
    }
    for (int j = 0; j <= w; j++)
    {
        if (vw[0].second > j)
        {
            calc[j][0] = 0;
        }
        else
        {
            calc[j][0] = vw[0].first;
        }
    }
    for (int i = 1; i < n; i++)
    {
        for (int j = 0; j <= w; j++)
        {
            if (vw[i].second > j)
            {
                calc[j][i] = calc[j][i - 1];
            }
            else
            {
                calc[j][i] = max(calc[j - vw[i].second][i - 1] + vw[i].first, calc[j][i - 1]);
            }
        }
    }
    cout << calc[w][n - 1] << endl;
    return 0;
}

int gcd(int a, int b)
{
    int c;
    if (a < b)
    {
        c = a;
        a = b;
        b = c;
    }
    if (a % b == 0)
        return b;
    else
        return gcd(b, a % b);
}


Measured memory_bytes: 6992
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
#define PI 3.14159265358979
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repp(i, s, e) for(int i = (s); i <= (e); ++i)
#define sz(x) ((int)x.size())
#define all(x) x.begin(), x.end()
#define FAST_IO() ios::sync_with_stdio(0); cin.tie(0)
template<typename T>
ostream& operator<<(ostream &os, const vector<T> &v) { for (auto x : v) os << x << " "; return os << "\n"; }
template<class U, class V>
ostream& operator<<(ostream &os, const pair<U, V> &p) { return os << "(" << p.first << "," << p.second << ")";}

const int MAXN = 2e5 + 5;
vector<int> adj[MAXN];
int add[MAXN];
int vis[MAXN];

void dfs(int curr) {
	vis[curr] = true;
	for(auto &next : adj[curr]) {
		if(vis[next]) continue;
		add[next] += add[curr];
		dfs(next);
	}
}


int main() {
	int N, Q; cin >> N >> Q;
	rep(i, N - 1) {
		int u, v; cin >> u >> v;
		adj[u - 1].push_back(v - 1);
		adj[v - 1].push_back(u - 1);
	}
	int root = 0;
	rep(i, Q) {
		int p, x; cin >> p >> x;
		add[p - 1] += x;
	}
	dfs(root);
	rep(i, N) cout << add[i] << " ";
}

Measured memory_bytes: 21120
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}

template<unsigned int mod_>
struct ModInt{
	using uint = unsigned int;
	using ll = long long;
	using ull = unsigned long long;

	constexpr static uint mod = mod_;

	uint v;
	ModInt():v(0){}
	ModInt(ll v):v(normS(v%mod+mod)){}
	explicit operator bool() const {return v!=0;}
	static uint normS(const uint &x){return (x<mod)?x:x-mod;}		// [0 , 2*mod-1] -> [0 , mod-1]
	static ModInt make(const uint &x){ModInt m; m.v=x; return m;}
	ModInt operator+(const ModInt& b) const { return make(normS(v+b.v));}
	ModInt operator-(const ModInt& b) const { return make(normS(v+mod-b.v));}
	ModInt operator-() const { return make(normS(mod-v)); }
	ModInt operator*(const ModInt& b) const { return make((ull)v*b.v%mod);}
	ModInt operator/(const ModInt& b) const { return *this*b.inv();}
	ModInt& operator+=(const ModInt& b){ return *this=*this+b;}
	ModInt& operator-=(const ModInt& b){ return *this=*this-b;}
	ModInt& operator*=(const ModInt& b){ return *this=*this*b;}
	ModInt& operator/=(const ModInt& b){ return *this=*this/b;}
	ll extgcd(ll a,ll b,ll &x,ll &y) const{
		ll u[]={a,1,0},v[]={b,0,1};
		while(*v){
			ll t=*u/ *v;
			rep(i,3) swap(u[i]-=t*v[i],v[i]);
		}
		if(u[0]<0) rep(i,3) u[i]=-u[i];
		x=u[1],y=u[2];
		return u[0];
	}
	ModInt inv() const{
		ll x,y;
		extgcd(v,mod,x,y);
		return make(normS(x+mod));
	}
	bool operator==(const ModInt& b) const { return v==b.v;}
	bool operator!=(const ModInt& b) const { return v!=b.v;}
	friend istream& operator>>(istream &o,ModInt& x){
		ll tmp;
		o>>tmp;
		x=ModInt(tmp);
		return o;
	}
	friend ostream& operator<<(ostream &o,const ModInt& x){ return o<<x.v;}
};
using mint = ModInt<1000000007>;

const int MAX_N=300,MAX_M=300;
typedef bitset<MAX_N> Bs;
typedef vector<Bs> mat;
int getrank(int N, mat a){
	int ans=0;
	bool used[MAX_N]={};
	rep(j,N){
		int i=0;
		while( (i < N) && (used[i] || !a[i][j]) ) i++;
		if(i == N) continue;
		ans++;
		used[i] = 1;
		rep(k,N) if(!used[k]&&a[k][j]){
			a[k]^=a[i];
		}
	}
	return ans;
}

mint dp[301][301][301];

mint p2[100001];

int main(){
	int N;
	cin>>N;
	p2[0] = 1;
	rep1(i,100000) p2[i] = p2[i-1]*2;
	mat Cm(N);
	rep(i,N){
		rep(j,N){
			int c;
			cin>>c;
			Cm[i][j] = c;
		}
	}
	int C = getrank(N,Cm);

	dp[0][0][0] = 1;
	rep(i,N) rep(a,N) rep(c,N) if(dp[i][a][c]){
		dp[i+1][a][c] += dp[i][a][c] * p2[a];	//already added
		if(C>c) dp[i+1][a+1][c+1] += dp[i][a][c] * (p2[C+a-c]-p2[a]);	//new in C
		dp[i+1][a+1][c] += dp[i][a][c] * (p2[N]-p2[C+a-c]);	//otherwise
	}

	mint ans = 0;
	rep(a,N+1){
		ans += dp[N][a][C] * p2[(N-a)*N];
	}
	cout<<ans<<endl;
}


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

#define ll long long 
#define inf 0x3f3f3f3f
#define infll 0x3f3f3f3f3f3f3f3f
#define all(x) (x).begin(),(x).end()
#define f(i, a, b) for (int i=a; i<(signed)(b); ++i)
#define pc __builtin_popcount // counts number of 1's in bin(num)

const double pi = 2*acos(0.0);
//__gcd(n1, n2);
//cout << fixed;
//cout << setprecision(6); //fixes # of dp



int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	string s; int n;
	cin >> s >> n;
	vector <char> front;
	vector<char> back;
	bool rev = false;
	f(i, 0, n){
		int x; cin >> x;
		if(x == 1){
			rev = !rev;
		}
		else{
			int y; char z;
			cin >> y >> z;
			if(y == 1 && !rev){
				front.push_back(z);
			} else if(y == 1 and rev){
				back.push_back(z);
			} else if(y == 2 && !rev){
				back.push_back(z);
			} else{
				front.push_back(z);
			}
		}
	}
	string a(all(front));
	string b(all(back));
	reverse(all(a));
	s = a + s + b;

	if(rev){
		reverse(all(s));
	}
	cout << s;
}








Measured memory_bytes: 1348
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int H, W;
  cin >> H >> W;
  
  //二次元配列宣言
 vector<vector<char>> data(H+2, vector<char>(W+2));
  
  //枠の流し込み
  for (int i = 0; i < H+2; i++){
    for (int j = 0; j < W+2; j++){
      data.at(i).at(j) = '#';
    }
  }
  
  //置き換え作業
  for (int k = 1; k < H+1; k++){
    for (int l = 1; l < W+1; l++){
      cin >> data.at(k).at(l);
    }
  }
  
  //出力
   for (int i = 0; i < H+2; i++){
    for (int j = 0; j < W+2; j++){
      cout << data.at(i).at(j);
    }
     cout << endl;
   }
  
}

Measured memory_bytes: 256
#include <atcoder/all>
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using namespace atcoder;
using lint = long long int;
long long int INF = 1001001001001001LL;
int inf = 1000000007;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;

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

#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()

/* do your best */


struct UnionFind{
    
    vector<int> M_par;
    vector<int> M_rank;
    vector<int> M_size;

private:
    void init(int n = 1){
        M_par.resize(n);
        M_rank.resize(n);
        M_size.resize(n);
        for(int i = 0; i < n; i++){
            M_par[i] = i;
            M_rank[i] = 0;
            M_size[i] = 1;
        }
    }

public:

    UnionFind(size_t n = 1){
        init(n);
    }

    size_t find(size_t x){
        if(M_par[x] == x) return x;
        size_t r = find(M_par[x]);
        return M_par[x] = r;
    }
    
    bool same(size_t x, size_t y){
        return find(x) == find(y);
    }

    bool unite(size_t x, size_t y){
        x = find(x);
        y = find(y);
        if(x == y) return false;
        if(M_rank[x] < M_rank[y]) swap(x, y);
        if(M_rank[x] == M_rank[y]) M_rank[x]++;
        M_par[y] = x;
        M_size[x] = M_size[x] + M_size[y];
        return true;
    }

    size_t size(size_t x){
        return M_size[find(x)];
    }

};

int main() {
  
  int n, m; cin >> n >> m;
  UnionFind uf(n);
  for (int i = 0; i < m; i++) {
    int a, b; cin >> a >> b;
    a--;
    b--;
    uf.unite(a, b);
  }

  lint ans = 0;
  for (int i = 0; i < n; i++) {
    if (i == uf.find(i)) ans++;
  }
  ans--;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3984
n = int(input())
lis = list(map(int,input().split()))
if sum(lis) % sum([i for i in range(1,n+1)]) != 0:
    print("NO")
    exit()
key = sum(lis) // sum([i for i in range(1,n+1)])
li = [-lis[i]+lis[i-1]+key for i in range(n)]
for num in li:
    if num < 0 or num % n != 0:
        print("NO")
        exit()
print("YES")

Measured memory_bytes: 14292
# coding: utf-8
# Your code here!
import sys
read = sys.stdin.read
readline = sys.stdin.readline

n,k,*a = map(int, read().split())

from collections import Counter

d = Counter(a)
d = sorted(d.values())

L = len(d)
if L >= k:
    print(sum(d[:L-k]))
else:
    print(0)


Measured memory_bytes: 36232
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
 
public class Main {
 
    public static final int BIG_NUM  = 2000000000;
    public static final int MOD  = 1000000007;
 
    public static void main(String[] args) {
 
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
 
        try {
 
            String str[] = br.readLine().split("\\s+");
            int array[] = new int[str.length];
 
            for(int i = 0; i < str.length; i++){
                array[i] = Integer.parseInt(str[i]);
            }
 
            Dice dice = new Dice();
            dice.setNumber(array[0], array[1], array[2], array[3], array[4], array[5]);
 
            String order = br.readLine();
 
            for(int i = 0; i < order.length(); i++){
                dice.roll(order.charAt(i));
            }
 
            System.out.println(dice.getTop());
 
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
 
 
class Dice{
 
    private int number[];
    private int work[];
 
    Dice(){
        number = new int[6];
        work = new int[6];
    }
 
 
    public void roll(char dst){
        for(int i = 0; i < 6; i++) work[i] = number[i];
        switch(dst){
        case 'E':
            setNumber(work[3],work[1],work[0],work[5],work[4],work[2]);
            break;
        case 'N':
            setNumber(work[1],work[5],work[2],work[3],work[0],work[4]);
            break;
        case 'S':
            setNumber(work[4],work[0],work[2],work[3],work[5],work[1]);
            break;
        case 'W':
            setNumber(work[2],work[1],work[5],work[0],work[4],work[3]);
            break;
        }
    };
 
    public int getTop(){
        return number[0];
    }
 
    public void setNumber(int n0,int n1,int n2,int n3,int n4,int n5){
        number[0] = n0;
        number[1] = n1;
        number[2] = n2;
        number[3] = n3;
        number[4] = n4;
        number[5] = n5;
    }
};


Measured memory_bytes: 24480
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
using namespace std;
#define inf 1000000009
int graf[105][105];
int a[1001], b[1001], c[1001];

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

	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++)if(i!=j)graf[i][j] = inf;
	for (int i = 0; i < m; i++) {
		cin >> a[i] >> b[i] >> c[i];
		graf[a[i] - 1][b[i] - 1] = c[i];
		graf[b[i] - 1][a[i] - 1] = c[i];
	}

	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++)
			for (int k = 0; k < n; k++)graf[j][k] = min(graf[j][k], graf[j][i] + graf[i][k]);

	int ans = m;
	for (int i = 0; i < m; i++) {
		int f = 0;
		for (int j = 0; j < n; j++) {
			if (graf[j][a[i] - 1] + c[i] == graf[j][b[i] - 1]) {
				f++;
			}
		}
		if (f)ans--;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i=0; i<n; i++) cin >> a[i];
    int ans = 1;
    for (int i=0; i<n; i++) ans *= 3;

    int d = 1;
    for (int i=0; i<n; i++) {
        if (a[i]%2 == 0) d*=2;
    }
    ans -= d;
    cout << ans << endl;
}


Measured memory_bytes: 504
#include <stdio.h>

int min(int a, int b) {
  return a < b ? a : b;
}

int main(void) {
  int i, j, k, n;
  scanf("%d%d", &n, &k);
  for(i = 0; i < k; ++i) {
    int a, b, num;
    scanf("%d%d", &a, &b);
    num = min(min(a, n + 1 - a), min(b, n + 1 - b));
    num %= 3;
    if(!num) num = 3;
    printf("%d\n", num);
  }
  return 0;
}


Measured memory_bytes: 2716
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define BUF_SIZE 15

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

int main(void) {
  FILE *fp = stdin;
  char line[BUF_SIZE];
  if(!fgets(line, BUF_SIZE, fp)) return 0;
  int num;
  sscanf(line, "%d", &num);

  int i, j;
  int *arr = malloc(sizeof(int)*num);
  for(i = 0; i < num; i++) {
    if(!fgets(line, BUF_SIZE, fp)) return 0;
    sscanf(line, "%d", &arr[i]);
  }
  qsort(arr, num, sizeof(int), comp);

  int res = 0;
  for(i = 0; i < num;) {
    j = i;
    int cnt = 0;
    while(arr[j] == arr[i]) {
      cnt++;
      i++;
    }
    res += (cnt&1);
  }
  printf("%d\n", res);
  return 0;
}

Measured memory_bytes: 1020