akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;

#define rep(a,n) for(ll a = 0;a < n;a++)

static const ll INF = 1e18;

template<typename T>
static inline void chmin(T& ref, const T  value) {
    if (ref > value) ref = value;
}

template<typename T>
static inline void chmax(T& ref, const T value) {
    if (ref < value) ref = value;
}

struct edge {
	int from;
	int to;
	ll cost;
	edge(int from, int to, ll cost) :from(from), to(to), cost(cost){}
};

struct UnionFind {
public:
	vector <ll> par; // 
	vector <ll> siz; // 

	UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
		for (ll i = 0; i < sz_; ++i) par[i] = i;
	}
	void init(ll sz_) {
		par.resize(sz_);
		siz.assign(sz_, 1LL);
		for (ll i = 0; i < sz_; ++i) par[i] = i;
	}

	ll root(ll x) {
		while (par[x] != x) {
			x = par[x] = par[par[x]];
		}
		return x;
	}

	bool merge(ll x, ll y) {
		x = root(x);
		y = root(y);
		if (x == y) return false;
		if (siz[x] < siz[y]) swap(x, y);
		siz[x] += siz[y];
		par[y] = x;
		return true;
	}

	bool issame(ll x, ll y) {
		return root(x) == root(y);
	}

	ll size(ll x) {
		return siz[root(x)];
	}
};

struct KruskalRunner {
	//コストの取り方で最大全域木も計算可能
	static bool orderByCost(const edge& e1, const edge& e2) {
		return e1.cost < e2.cost;
	}

	ll solve(int vCount, vector<edge>& edges) {
		sort(edges.begin(), edges.end(), orderByCost);
		UnionFind uf = UnionFind(vCount);
		ll sum = 0;
		for (int i = 0; i < edges.size(); ++i) {
			edge e = edges[i];
			if (!uf.issame(e.from, e.to)) {
				uf.merge(e.from, e.to);
				sum += e.cost;
			}
		}
		return sum;
	}
};

int main() {
	ll n;
	cin >> n;
	vector<P> xs(n);
	vector<P> ys(n);
	rep(i, n){
		ll x, y;
		cin >> x >> y;
		xs[i] = { x,i };
		ys[i] = { y,i };
	}
	sort(xs.begin(), xs.end());
	sort(ys.begin(), ys.end());

	vector<edge> e;
	for (int i = 0; i < n - 1; i++) {
		e.emplace_back(xs[i].second, xs[i + 1].second, abs(xs[i + 1].first - xs[i].first));
		e.emplace_back(ys[i].second, ys[i + 1].second, abs(ys[i + 1].first - ys[i].first));
	}
	KruskalRunner r;
	auto a = r.solve(n, e);
	cout << a << endl;
	return 0;
}


Measured memory_bytes: 11076
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pqueue priority_queue
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N;
  cin>>N;
  string S[N];
  for(int i=0;i<N;++i) cin>>S[i];
  bool can;
  int ans = 0;
  for(int x=-N;x<=N;++x) {
    can = true;
    for(int i=0;i<N;++i) {
      for(int j=0;j<N;++j) {
        if(S[i][j]!=S[(j-x+N)%N][(i+x+N)%N]) can = false;
      }
    }
    if(can) {
      ans += min(N-x, N)-max(0, -x);
    }
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 3772
def main():
    N = int(input())
    lst_B = [float("INF")] + list(map(int, input().split())) + [float("INF")] 

    ans = sum(min(lst_B[i - 1], lst_B[i]) for i in range(1, len(lst_B)))

    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
 
using namespace std;
 
#define lli long long int
#define REP(i,s,l) for(lli i=s;i<l;i++)
#define DEBUG 0
#define INF (1LL<<50)
 
signed main(){
 
	lli w,h,x,y;
	cin>>w>>h>>x>>y;

	cout<<w*h/2.0<<" ";
	if(w/2.0 == x && h/2.0 == y){
		cout<<1<<endl;
	}
	else cout<<0<<endl;

	return 0;
}

Measured memory_bytes: 256
import sys, time, random
ts = time.time()
import numpy as np

input = sys.stdin.readline

D = int(input())
c = np.array(list(map(int, input().split())), dtype=int)
S = np.array([list(map(int, input().split())) for _ in range(D)], dtype=int)
T = np.zeros(D, dtype=int)
dissatisfactions = np.zeros((D+1, 26), dtype=int)
v = 0


def findzero(a, after):
    try:
        return after+np.where(a[after:]==0)[0][0]
    except IndexError:
        return len(a)


for i, s in enumerate(S):
    dissatisfactions[i+1] = dissatisfactions[i] + c
    t = np.argmax(s+dissatisfactions[i+1])
    dissatisfactions[i+1, t] = 0
    T[i] = (t+1)
    v += s[t]
    v -= np.sum(dissatisfactions[i+1])

while time.time()-ts<1.8:
    # find d, q
    d = np.random.randint(1, D)
    q = np.random.randint(1, 26)
    # update
    pre = T[d - 1]
    new = q
    pre0 = findzero(dissatisfactions[:, pre - 1], d + 1)
    new0 = findzero(dissatisfactions[:, new - 1], d + 1)

    # 値の更新
    diff = S[d - 1, new - 1] - S[d - 1, pre - 1] +(dissatisfactions[d, new - 1]) * (new0 - d) \
           - (dissatisfactions[d - 1, pre - 1] + c[pre - 1]) * (pre0 - d)
    if diff < 0:
        continue
    v += diff
    # 配列書き換え
    T[d - 1] = new
    dissatisfactions[d:new0, new - 1] -= dissatisfactions[d, new - 1]
    dissatisfactions[d:pre0, pre - 1] += dissatisfactions[d - 1, pre - 1] + c[pre - 1]


print('\n'.join([str(int(t)) for t in T]))


Measured memory_bytes: 27736
// ABC139A2.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

//#include "pch.h"
#include <iostream>
#include <string> // 文字列を使う
using namespace std;
int main()
{
	string S, T;
	cin >> S >> T;
	int ans = 0;
	for (int i = 0; i < 3; i++)
	{
		if (S.at(i)==T.at(i))
		{
			ans++;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fuck 2000000000
#define hell 2000000000000000000
#define ff first
#define ss second 
#define forn(i,n) for (int i=0;i<int(n);i++)
#define nfor(i,n) for (int i=int(n)-1;i>=0;i--)
#define N 100010
#define M 1000010
using namespace std;
const int MOD = 1000000007;
const double PI = acos(-1.0);
int gcd(int a,int b){return (b==0) ? a : gcd(b,a%b);}
int n;
int ar[N];
int ans=0;
int main(){
	
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	if (abs(a-b)<abs(a-c))
		printf("A");
	else 
		printf("B");
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;

class D
{
	static void Main()
	{
		Func<int[]> read = () => Console.ReadLine().Split().Select(int.Parse).ToArray();
		var h = read();
		var ps = new int[h[0]].Select(_ => read()).ToArray();

		var dp = Enumerable.Repeat(-1L, h[1] + 1).ToArray();
		dp[0] = 0;
		foreach (var p in ps)
			for (int i = h[1]; i >= 0; i--)
				if (dp[i] != -1 && i + p[0] <= h[1])
					dp[i + p[0]] = Math.Max(dp[i + p[0]], dp[i] + p[1]);
		Console.WriteLine(dp.Max());
	}
}


Measured memory_bytes: 13920
from bisect import bisect_right
from collections import defaultdict

S = input()
S_set = set(S)
d = defaultdict(list)
for i,s in enumerate(S):
    d[s].append(i)
# print(d)

T = input()
T_set = set(T)
for t in T_set:
    if t not in S_set:
        print(-1)
        exit()

cnt = 0
loop = 0
prev = -1

for t in T:
    num = d[t]
    a = bisect_right(num,prev)
    # print(prev,a,num)
    
    if a >= len(num):
        loop += 1
        a = 0
    prev = num[a]

print(prev+1+(loop)*len(S))

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

int main()
{
	int x;
	stack<int> st;
	while (cin >> x) {
		if (x) {
			st.push(x);
		}
		else {
			cout << st.top() << endl;
			st.pop();
		}
	}
    return 0;
}

Measured memory_bytes: 1204
#include <bits/stdc++.h>
#define range(i, l, r) for(long long int (i) = (l); (i) < (r); (i)++)
#define reversed_range(i, l, r) for (long long int (i) = (r) - 1; (i) >= l; (i)--)
using namespace std;
template <typename T>
using vec = vector<T>;
using lint = long long;
using ulint = unsigned long long;
using pint = pair<int, int>;
using plint = pair<lint, lint>;

template <typename S, typename T>
ostream& operator <<(ostream& os, pair<S, T> p) {
    os << "(";
    os << p.first << ", " << p.second;
    return os << ")";
}

template <typename T>
ostream& operator <<(ostream& os, vec<T> v) {
    os << "[";
    if (v.size() == 0) return os << "]";
    for (int i = 0; i < v.size() - 1; i++) {
        os << v.at(i) << ", ";
    }
    return os << v.at(v.size() - 1) << "]";
}

template <typename T>
ostream& operator <<(ostream& os, set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    os << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        os << ", " << *it;
    }
    return os << "}";
}

template <typename T>
ostream& operator <<(ostream& os, unordered_set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    os << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        os << ", " << *it;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    os << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        os << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, unordered_map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    os << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        os << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

lint pow(lint num, lint e, lint MOD) {
    lint res = 1;
    lint cur_num = num;
    while (e) {
        if (e & 1) {
            res *= cur_num;
            res %= MOD;
        }
        cur_num *= cur_num;
        cur_num %= MOD;
        e >>= 1;
    }
    return res;
}

int main() {
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    lint N; cin >> N;
    unordered_map<lint, lint> count;
    range(i, 1, N) {
        lint boss; cin >> boss;
        boss -= 1;
        count[boss] += 1;
    }
    range(i, 0, N) cout << count[i] << "\n";
}

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

int main() {
    int N; cin >> N;
    int cntk = 0;
    int cnt4 = 0;
    rep(i, N){
        int a; cin >> a;
        if(a % 4 == 0){
            cnt4++;
        } else if(a % 2 == 1){
            cntk++;
        }
    }

    if(cnt4 + cntk == N){
        if(cntk-1 <= cnt4){
            cout << "Yes" << endl;
            return 0;
        } else {
            cout << "No" << endl;
            return 0;
        }
    }

    if(cntk <= cnt4){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 50;
typedef long long ll;
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
int a[N];
int main()
{
    int n, x;
    scanf("%d%d", &n, &x);
    for (int i = 0; i < n; i++)
        scanf("%d", a + i), a[i] = abs(a[i] - x);
    int g = *a;
    for (int i = 0; i < n; i++)
        g = gcd(g, a[i]);
    printf("%d", g);
    return 0;
}

Measured memory_bytes: 640
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring> 
#include <sstream>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
 
using namespace std;
 
#define pai 3.14159265359
#define mod 1000000007

int main()
{
    int n, l;
    string s[101];
    cin >> n >> l;
    for(int i = 0; i < n; i++){
        cin >> s[i];
    }
    sort(s, s + n);
    string ans = "";
    for(int i = 0; i < n; i++){
        ans += s[i];
    }
    cout << ans << endl;
    return 0;
}

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

void solve(std::istream &in, std::ostream &out);

int main() {
#ifdef LOCAL
  freopen("../IO/a.in", "r", stdin);
//  freopen("../IO/a.in", "w", stdout);
#else
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);
  std::cout.tie(nullptr);
#endif
  solve(std::cin, std::cout);
  return 0;
}

void solve(std::istream &in, std::ostream &out) {
  int n, W;
  in >> n >> W;
  vector<int> w(n), v(n);
  for (int i = 0; i < n; ++i) {
    in >> w[i] >> v[i];
  }
  vector<int64_t> dp(1000 * n + 5, numeric_limits<int>::max());
  dp[0] = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 1000 * n - v[i]; j >= 0; --j) {
      dp[v[i] + j] = min(dp[v[i] + j], dp[j] + w[i]);
    }
  }
  int a = -1;
  for (int i = 0; i <= 1000 * n; ++i)  {
    if (dp[i] <= W) {
      a = i;
    }
  }
  out << a << '\n';
}


Measured memory_bytes: 1024
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define N 1001
  
void count(char *A,char *B){
  int i,j,x[N][N];
  
  for(i=0; i<N; i++){
    for(j=0; j<N; j++){
      x[i][j]=0;
    }
  }
  for(i=0; i<strlen(A); i++){
    for(j=0; j<strlen(B); j++){
      if(A[i]==B[j])x[i+1][j+1]=x[i][j]+1;
      else if(x[i][j+1]>x[i+1][j]) x[i+1][j+1]=x[i][j+1];
      else x[i+1][j+1]=x[i+1][j];
    }
  }
  printf("%d\n",x[strlen(A)][strlen(B)]);
}
  
int main(){
  int n,i,j;
  char A[N],B[N];
  scanf("%d",&n);

for(i=0;i<n;i++){
    scanf("%s",A);
    scanf("%s",B);
    count(A,B);
  }
  return 0; 
}

Measured memory_bytes: 4520
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
const int MOD=1000000007;

int main(){
    ll x,y,z;
    cin>>x>>y>>z;
    cout<<z<<" "<<x<<" "<<y<<endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<string>
#include<vector>
#include<algorithm>
#include<set>
#include<stack>
#include<queue>
#include<map>
#include<cstring>
#include<functional>

using namespace std;

int main()
{
	//freopen("input.txt", "r", stdin);

	int n;

	scanf("%d", &n);

	if (n >= 30)
	{
		printf("Yes\n");
	}

	else
	{
		printf("No\n");
	}

	return 0;
}

Measured memory_bytes: 1648
#include <bits/stdc++.h>
#define int long long
#define N 100011

using namespace std;
const int MOD = (int)1e9 + 7;

int n, cnt[2][N];
vector<int> adj[N];

int dfs(int v, int p, int x) {
	if(cnt[x][v] != -1) return cnt[x][v];
	cnt[x][v] = 1;
	for(int u : adj[v]) {
		if(u == p) continue;
		cnt[x][v] = (cnt[x][v] * (dfs(u,v,0) + (x ? 0 : dfs(u,v,1))) % MOD) % MOD;
	}
	return cnt[x][v];
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	memset(cnt, -1, sizeof cnt);
	cin >> n;
	for(int i=1; i<n; i++) {
		int x, y;
		cin >> x >> y;
		x--; y--;
		adj[x].push_back(y);
		adj[y].push_back(x);
	}
	cout << (dfs(0,0,0) + dfs(0,0,1)) % MOD << endl;
	return 0;
}

Measured memory_bytes: 15616
#pragma warning (disable:4996)
#include"bits/stdc++.h"
#include<cassert>
#define int long long
#define MRE assert(0);
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
const long long mod = 998244353;
const long long inf = 1ll<<61;
typedef pair<int, int> P;
typedef pair<int, P > PP;
struct segtree {
	vector<int>node; int n;
	void init(int N) {
		n = 1;
		while (n < N) {
			n *= 2;
		}
		node.resize(2 * n, -inf);
	}
	void upd(int a, int x) {
		a += n - 1;
		node[a] = x;
		while (a > 0) {
			a = (a - 1) / 2;
			node[a] = max(node[2 * a + 1], node[2 * a + 2]);
		}
	}
	int calc(int a, int b, int k, int l, int r) {
		if (r <= a || b <= l)return -inf;
		if (a <= l&&r <= b)return node[k];
		int vl = calc(a, b, k * 2 + 1, l, (l + r) / 2);
		int vr = calc(a, b, k * 2 + 2, (l + r) / 2, r);
		return max(vl, vr);
	}
	int get(int a, int b) {
		return calc(a, b, 0, 0, n);
	}
};

segtree seg;
int n;
int x[200006], d[200006];
int nxt[200006];
vector<P>V;
int dp[200006];
signed main() {
	cin >> n;
	rep(i, n) {
		cin >> x[i] >> d[i];
		V.push_back(P(x[i], x[i]+d[i]));
	}
	sort(V.begin(), V.end());
	vector<int>v;
	rep(i, n)v.push_back(V[i].first);
	seg.init(n);
	rep(i, n)seg.upd(i, i);
	for (int i = n - 1; i >= 0; i--) {
		int pos = (lower_bound(v.begin(), v.end(), V[i].second)-v.begin());

		seg.upd(i, seg.get(i, pos));
	}
	rep(i, n)nxt[i] = seg.get(i, i + 1);
	dp[0] = 1;
	rep(i, n) {
		dp[i + 1] += dp[i];
		dp[nxt[i] + 1] += dp[i];
		dp[i + 1] %= mod;
		dp[nxt[i] + 1] %= mod;
	}
	cout << dp[n] << endl;
}

Measured memory_bytes: 18156
k = int(input())

lunlun = [1, 2, 3, 4, 5, 6, 7, 8, 9]


def generate_lunlun(x):
    mod = x % 10

    if mod - 1 >= 0:
        yield x*10 + mod-1

    yield x*10 + mod

    if mod + 1 <= 9:
        yield x*10 + mod + 1


p = 0

while len(lunlun) < k:
    for i in generate_lunlun(lunlun[p]):
        lunlun.append(i)

    p += 1

print(lunlun[k-1])


Measured memory_bytes: 7140
/* 拡張BFS */
#include <bits/stdc++.h>
using namespace std;

#define REP(i, n) for (ll (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n) for (ll (i) = m ; (i) < (ll)(n) ; ++(i))
#define REP_REV(i, n) for (ll (i) = (ll)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (ll (i) = (ll)(n) - 1 ; (i) >= m ; --(i))

#define INF             2e9
#define INF_LL          1LL<<60
#define ll              long long
#define Ceil(x, n)      (((((x))+((n)-1))/n))
#define CeilN(x, n)     (((((x))+((n)-1))/n)*n)
#define FloorN(x, n)    ((x)-(x)%(n))
#define ALL(x)          (x).begin(),(x).end()
typedef pair<ll, ll>    P;

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

    vector<ll> g[n];
    REP(i, m) {
        int u, v;
        cin >> u >> v;
        u--, v--;
        g[u].push_back(v);
    }

    int s, t;
    cin >> s >> t;
    s--, t--;

    /* 頂点に状態を持たせる（0: ぴったり, 1: 1歩あまり, 2: 2歩あまり） */
    ll dist[n][3];  /* dist[i][j]: iにjの状態で着くまでの最短経路 */
    REP(i, n) REP(j, 3) {
        dist[i][j] = -1;
    }

    /* bfs */
    dist[s][0] = 0;
    queue<P> que;
    que.push({s, 0});

    while(!que.empty()) {
        P tmp = que.front();
        que.pop();

        for(auto next_place: g[tmp.first]) {
            int next_stat = (tmp.second + 1) % 3;
            if(dist[next_place][next_stat] == -1) {
                dist[next_place][next_stat] = dist[tmp.first][tmp.second] + 1;
                que.push({next_place, next_stat});
            }
        }
    }

    if(dist[t][0] == -1) {
        cout << -1 << endl;
    } else {
        cout << dist[t][0] / 3 << endl;
    }

    return 0;
}

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

int main()
{
    string S;
    cin >> S;
    int now = S[0]-'0';
    string tmp;
    for (int bit = 0; bit < (1 << 3); bit++)
    {
        now = S[0]-'0';
        tmp = S[0];
        for (int i = 0; i < 3; i++)
        {
            if (bit & (1 << i))
            {
                tmp += "+";
                now += S[i + 1]-'0';
            }
            else
            {
                tmp += "-";

                now -= S[i + 1]-'0';
            }
            tmp += S[i+1];
        }
        if (now == 7)
        {
            cout << tmp << "=7" << endl;
            return 0;
        }
    }
    return 0;
}

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

using namespace std;
const long long INF = (long long) (1e18)+1;

int main() {
  string s;
  // int w;
  cin >> s;
  int last_i = s.size()-1;
  for (int i=0; i < s.size()/2; ++i) {
    if (s[i] != s[last_i-i]) {
      cout << "No" << endl;
      return 0;
    }
  }

  int start_i = ((s.size()+3)/2 ) - 1;
  // cout << s.size()/4 << endl;
  int count = 0;
  for (int i=0; i < s.size()/4; ++i) {
    // cout << i << " " << last_i-i << endl; 
    // cout << s[i+start_i] << " " << s[last_i-i] << endl; 
    if (s[i+start_i] != s[last_i-count]) {
      cout << "No" << endl;
      return 0;
    }
    count++;
  }
  last_i = (s.size()-1)/2 - 1;
  // cout << last_i << endl;
  for (int i=0; i < s.size()/4; ++i) {
    // cout << s[i] << " " << s[last_i-i] << endl; 
    if (s[i] != s[last_i-i]) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 256
# coding: utf-8
import sys

# from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
printout = sys.stdout.write
sprint = sys.stdout.flush
# from heapq import heappop, heappush
# from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
# import math
# from itertools import product, accumulate, combinations, product
# import bisect
# import numpy as np
# from copy import deepcopy
#from collections import deque
# from decimal import Decimal
# from numba import jit

INF = 1 << 50
EPS = 1e-8
mod = 998244353


def intread():
    return int(sysread())
def mapline(t=int):
    return map(t, sysread().split())
def mapread(t=int):
    return map(t, read().split())


def run():
    N, K = mapline()
    G = []
    for i in range(K):
        l, r = mapline()
        G.append((l, r))

    dp = [0]* N
    dp[0] = 1
    a = [0] * N
    a[1] = -1
    for k in range(0, N):
        if k >= 1:
            dp[k] = (dp[k-1] + a[k]) % mod
        for l, r in G:
            if k+l <= N-1:
                a[k+l] = (a[k+l] + dp[k]) % mod
            if k+r+1 <= N-1:
                a[k+r+1] = (a[k+r+1] - dp[k]) % mod

    print(dp[N-1])




if __name__ == "__main__":
    run()


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

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

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	ll N;
	cin>>N;
	int ret=0;
	for(i=2;1LL*i*i<=N;i++) if(N%i==0) {
		j=0;
		while(N%i==0) j++, N/=i;
		for(x=1;x<=10;x++) {
			if(j>=x) ret++, j-=x;
		}
	}
	if(N>1) ret++;
	cout<<ret<<endl;
}


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


Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
using LL = long long;

int main(){
    LL N;
    cin >> N;
    vector<LL> a(N+1), d(N);
    LL sum = 0;
    bool f = true;
    for(int i = 0;i < N;i++){
        cin >> a[i];
        sum += a[i];
    }
    a[N] = a[0];
    for(int i = 0;i < N;i++)  d[i] = a[i+1]-a[i];
    LL ns = N*(N+1)/2;
    LL m = sum/ns;
    if(sum%ns != 0) f = false;
    LL ksum = 0;
    for(int i = 0;i < N;i++){
        ksum += (m-d[i])/N;
        if(m-d[i] < 0 || (m-d[i])%N != 0) f = false;
    }
    if(ksum != m)   f = false;
    if(f)   cout << "YES" << endl;
    else    cout << "NO" << endl;
}

Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
using namespace std;
int m,f,r;
int main() {
	while(scanf("%d %d %d",&m,&f,&r)!=EOF&&!(m==-1&&f==-1&&r==-1)) {
		if(m==-1||f==-1)
			cout<<'F'<<endl;
		else if(m+f>=80)
			cout<<'A'<<endl;
		else if(m+f>=65)
			cout<<'B'<<endl;
		else if(m+f>=50||r>=50)
			cout<<'C'<<endl;
		else if(m+f>=30)
			cout<<'D'<<endl;
		else
			cout<<'F'<<endl;
	}
	return 0;
}


Measured memory_bytes: 3156
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;

int main() {
    int n;
    int m;
 
   cin >> n >> m;
  
   int a = n - 1;
   int b = m - 1;
   
  
   cout << a*b << endl;
 
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#ifdef LOCAL_DEBUG
#define DEBUG 1
#define CERR if(DEBUG) cerr
#define MACRO(_1,_2,_3,_4,_5,_6,_7,_8,_9,_10,NAME,...) NAME
#define pr(...) CERR<<MACRO(__VA_ARGS__,pr10,pr9,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__)<<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define pr9(a,b,c,d,e,f,g,h,i) pr1(a)<<pr8(b,c,d,e,f,g,h,i)
#define pr10(a,b,c,d,e,f,g,h,i,j) pr1(a)<<pr9(b,c,d,e,f,g,h,i,j)
#define prArr(a){CERR<<(#a)<<"={";int i=0;for(auto t:(a))CERR<<(i++?", ":"")<<t;CERR<<"}"<<endl;}
#else
#define DEBUG 0
#define pr(...)
#define prArr(a)
#endif
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}
//INSERT ABOVE HERE


signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  Int N;
  cin>>N;

  Int ans = INF;
  const Int M = (1e7) + 10;
  for(Int a=1;a<=M;a++){
    if(N%a) continue;
    Int b = N / a;
    Min(ans, a - 1 + b - 1);
  }

  cout<<ans<<endl;


  return 0;
}


Measured memory_bytes: 256
object Main extends App {

  import scala.io.StdIn._

  val Array(n, a) = readLine().split(' ').map(_.toInt)
  val values = readLine().split(' ').map(_.toInt).map(_ - a).toList
  def table : Map[Int, Long] ={
    def hoge(current: Map[Int, Long], values: List[Int]): Map[Int, Long]= {

      def withValue(n: Int) = {
        val newKeys = current.keySet ++ current.keySet.map(_ + n)
        newKeys.map{k => k -> (current.getOrElse(k , 0L) + current.getOrElse(k - n, 0L))}.toMap
      }

      values match  {
        case Nil => current
        case x :: remain =>  hoge(withValue(x),remain)
      }
    }
    hoge(Map(0 -> 1L), values)
  }
  val answer = table(0) - 1

  println(answer)
}

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

int main(){
  int N, K;
  cin >> N >> K;
  
  vector<int> h(N);
  for(int i=0; i<N; i++) cin >> h[i];
  
  sort(h.begin(), h.end());
  int ans=h[K-1] - h[0];
  for(int i=1; i<(N-(K-1)); i++){
    if(ans > (h[i+K-1]-h[i])){
      ans = (h[i+K-1]-h[i]);
    }
  }
  
  cout << ans << endl;

  return 0;
}




Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <climits>
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define srep(i, begin, end) for (__typeof(end) i = begin; i != end; i++)
#define si(x) int x = scanInt();
#define sll(x) LL x = scanLong();
#define sci(x) int x; scanf("%d", &x);
#define scll(x) LL x; scanf("%lld", &x);
#define pi(x) printf("%d ", x)
#define pll(x) printf("%lld ", x)
#define nl printf("\n")
#define clr(a) memset(a, 0, sizeof(a))
#define PB push_back
#define MP make_pair
using namespace std;
typedef unsigned int UI; // 32 bit integer
typedef long int LI; // 32 bit integer
typedef unsigned long int ULI; // 32 bit unsigned integer
typedef long long int LL; // 64 bit integer
typedef unsigned long long int ULL; // 64 bit unsigned integer
typedef long double LD;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef deque<int> DI;
typedef deque<LL> DLL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
const LL MOD = 1e9+7;

/* Fast I/O */
inline int scanInt() {
	int n = 0;
	char ch = getchar();
	int sign = 1;
	while(ch < '0' || ch > '9') {
		if(ch == '-')	sign = -1;
		ch = getchar();
	}
	while(ch >= '0' && ch <= '9') {
		n = (n<<1)+(n<<3)+(int)(ch-'0');
		ch = getchar();
	}
	return n*sign;
}

inline LL scanLong() {
	LL n = 0;
	char ch = getchar();
	LL sign = 1;
	while(ch < '0' || ch > '9') {
		if(ch == '-')	sign = -1;
		ch = getchar();
	}
	while(ch >= '0' && ch <= '9') {
		n = (n<<1)+(n<<3)+(LL)(ch-'0');
		ch = getchar();
	}
	return n*sign;
}

int main() {
	sll(n); sll(m);
	LL dp[n+1];
	rep(i, 0, n+1)	dp[i] = 0;
	rep(i, 0, m)	dp[scanLong()] = -1;
	dp[0] = 1;
	rep(i, 1, n+1) {
		if(dp[i] == -1)	continue;
		if(i-1 >= 0 && dp[i-1] != -1)	dp[i] = (dp[i] + dp[i-1])%MOD;
		if(i-2 >= 0 && dp[i-2] != -1)	dp[i] = (dp[i] + dp[i-2])%MOD;
	}
	pll(dp[n]%MOD); nl;
}


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

#define dump(x) cout << (x) << '\n'
#define Int int64_t
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()

Int INF = 1e18;
int inf = 1e9;
Int mod = 1e9+7;

typedef struct {
    bool L, R;
} p_t;

Int cost[2001][2001];

int main() {
    Int n, x;
    cin >> n >> x;
    vector<Int> a(n);
    for (Int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (Int i = 0; i < n; i++) {
        cost[i][0] = a[i];
        for (Int j = 1; j < n; j++) {
            cost[i][j] = min(cost[i][j - 1], a[(i - j + n) % n]);
        }
    }
    Int res = INF;
    for (Int i = 0; i < n; i++) {
        Int c = i * x;
        for (Int j = 0; j < n; j++) {
            c += cost[j][i];
        }
        res = min(res, c);
    }
    dump(res);
    return 0;
}


Measured memory_bytes: 31488
c(int*l,int*r){return *l-*r;}x[4<<17];*y;*z;i;main(j){for(;~scanf("%d",x+i);y[i]=x[i++])y=x+*x+1;for(qsort(x+1,*x,4,c);j<=*x;printf("%d\n",y[j++]>*z?*z:z[1]))z=x+*x/2;}

Measured memory_bytes: 3692
#include<bits/stdc++.h>
using namespace std;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
#define _GLIBCXX_DEBUG
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
const int INF = 1 << 30;
const int dx[] = {1,0,-1,0,1,1,-1,-1};
const int dy[] = {0,-1,0,1,1,-1,-1,1};
#define stp(x)  setprecision(x)
int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin>>n;
  vector<string> s(n);
  int count=1,max=0,count2=0;
  vector<pint> flag;
  rep(i,n){
    cin>>s[i];
  }
  sort(all(s));
  rep(i,n){
    if(i==0){
    }
    else if(s[i]==s[i-1]){
      count++;
    }
    else{
      count=1;
    }
    if(count>=max){
      flag.emplace_back(count,i);
      max=count;
    }
  }
  int si=flag.size();
  for(int i=0;i<si;i++){
    if(flag[i].first==max){
      cout<<s[flag[i].second]<<'\n';
    }
  }
  return(0);
}


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

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

int main() {
    int N,K;
    cin >> N >> K;
    vector<int> A(N);
    for(int i=0; i<N; ++i) cin >> A[i];
    
    sort(A.begin(), A.end());
    int M = A[N-1];
    int G = A[0];
    for(int i=1; i<N; ++i) G = gcd(A[i], G);

    if(K <= M && (K % G) == 0) cout << "POSSIBLE" << endl;
    else cout << "IMPOSSIBLE" << endl;
}

Measured memory_bytes: 640
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int a = sc.nextInt();
		int b = sc.nextInt();
		
		// 計算
		int result = 0;
		for(int i = a; i < b+1; i++){
		    String s = String.valueOf(i);
		    boolean chk = true;
		    for(int j = 0; j < s.length()/2; j++){
		        if(s.charAt(j) != s.charAt(s.length() - j - 1)){
		            chk = false;
		            break;
		        }
		    }
		    if(chk) result++;
		}
		
		// 出力
		System.out.println(result);
	}
}




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

int n;
int dim[1010 * 1010];
vector<int> edge[1010 * 1010];
int hsh(int x, int y) {
	return x + y * n;
}
bool used[1010 * 1010];

void dfs(stack<int> &st, vector<int> &rec) {
	while(st.size()) {
		int from = st.top();
		rec.push_back(from);
		st.pop();
		if(used[from]) continue;
		used[from] = true;
		for(int to : edge[from]) {
			--dim[to];
			if(dim[to] == 0) st.push(to);
		}
	}
}

int main() {
	cin >> n;
	for(int i = 0; i < n; ++i) {
		int px = i, py; cin >> py; py--;
		if(px > py) swap(px, py);
		for(int j = 0; j < n - 2; ++j) {
			int nx = i, ny; cin >> ny; ny--;
			if(nx > ny) swap(nx, ny);
			edge[hsh(px, py)].push_back(hsh(nx, ny));
			++dim[hsh(nx, ny)];
			px = nx;
			py = ny;
		}
	}
	stack<int> st;
	for(int i = 0; i < n; ++i) {
		for(int j = i + 1; j < n; ++j) {
			if(dim[hsh(i, j)] == 0) st.push(hsh(i, j));
		}
	}
	vector<int> rec;
	dfs(st, rec);
	if(rec.size() != n * (n - 1) / 2) {
		cout << -1 << '\n';
		return 0;
	}
	int dp[n * n] = {};
	int ans = 0;
	for(int i = (int)rec.size() - 1; i >= 0; --i) {
		int from = rec[i];
		for(int to : edge[from]) {
			dp[from] = max(dp[from], dp[to] + 1);
			ans = max(ans, dp[from]);
		}
	}
	cout << ans + 1 << '\n';
	return 0;
}

Measured memory_bytes: 50676
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include <time.h>
typedef long long ll;
typedef long double ld;
#define INF (1LL<<60)
/*swap 交換*/
void swap(ll *a, ll *b){ll c;c=*b;*b=*a;*a=c;}
/*2つのうち大きい数を返す*/
ll max2(ll a,ll b){return a>=b?a:b;}
/*2つのうち小さい数を返す*/
ll min2(ll a,ll b){return a>=b?b:a;}
/*絶対値*/
ll ABS(ll a){return a>=0?a:(-a);}
typedef struct{
    ll aa;
    ll bb;
}frequent;
// 小大
int compare(const void *a, const void *b){return *(ll *)a - *(ll *)b;}
ll trainticket(ll a, ll b, ll i){
    switch(i){
        case 0:
        return a+b;
        case 1:
        return a-b;
    }
    return 0;
}

int main(void){
    ll n,i,j,k,a,b,c,d,x,y,z;
    scanf("%lld",&n);
    a=n/1000;
    b=(n/100)%10;
    c=(n%100)/10;
    d=n%10;
    for(i=0;i<2;i++){
        x = trainticket(a,b,i);
        for(j=0;j<2;j++){
            y = trainticket(x,c,j);
            for(k=0;k<2;k++){
                z = trainticket(y,d,k);
                // printf("%lld\n",z);
                if(z==7) break;
            }
            if(k!=2) break;
        }
        if(j!=2) break;
    }
    printf("%lld",a);
    if(i==0){
        printf("+");
    }else{
        printf("-");
    }
    printf("%lld",b);
    if(j==0){
        printf("+");
    }else{
        printf("-");
    }
    printf("%lld",c);
    if(k==0){
        printf("+");
    }else{
        printf("-");
    }
    printf("%lld",d);
    printf("=7\n");
    return 0;
}


Measured memory_bytes: 128
// #define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <locale>
#include <cctype>
#include <sstream>
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef map<int, int> MAPII;
typedef vector<pair<int, int> > VPII;
typedef multimap<int, string, greater<int> > MuMIS;

#define MP make_pair
#define fastIO	cin.tie(0); ios::sync_with_stdio(false);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
//for gcc (未test)
// #define FOREACH_IT(it,c)	for(typeof(c)::iterator it=(c).begin(); it!=(c).end(); ++it)
//for Visual Studio
#define foreach_it(type,it,c) for(type::iterator it=c.begin(), c_end=c.end(); it!=c_end; ++it)

// ------------------- include, typedef, define END. -------------------

LL gcd(LL a, LL b){ return (b > 0) ? gcd(b, a%b) : a; }
LL lcm(LL a, LL b){ return a / gcd(a, b) * b; }

LL solve(LL a, LL now, LL m){
	return ((a*now) % m);
}

int main(){
	// 参考：http://d.hatena.ne.jp/otaks/20120301/1330610350
	// 参考：http://d.hatena.ne.jp/nanikaka/20110829/1314605899
	fastIO;
	LL a1, a2, a3, m1, m2, m3;
	while (cin >> a1 >> m1 >> a2 >> m2 >> a3 >> m3,a1,a2,a3,m1,m2,m3){
		LL nowx = 1, nowy = 1, nowz = 1;
		LL countx = 0, county = 0, countz = 0, ans = 0;
		while (1){
			nowx = solve(a1, nowx, m1);
			countx++;
			if (nowx == 1)	break;
		}
		while (1){
			nowy = solve(a2, nowy, m2);
			county++;
			if (nowy == 1)	break;
		}
		while (1){
			nowz = solve(a3, nowz, m3);
			countz++;
			if (nowz == 1)	break;
		}
		ans = lcm(lcm(countx, county), countz);
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1188
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

//code by lynmisakura.wish to be accepted!
#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>

#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>

/***************************/
using namespace std;

typedef long long ll;
typedef vector<ll> vi;
typedef vector<long long> vl;
typedef pair<ll, ll> pi;
typedef vector<pair<ll, ll>> vpi;

//const long long INF = 1LL << 55;

#define itn ll
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ss second
#define ff first
#define dup(x,y) ((x) + (y) - 1)/(y)
#define mins(x,y) x = min(x,y)
#define maxs(x,y) x = max(x,y)
#define all(x) (x).begin(),(x).end()
#define Rep(n) for(ll i = 0;i < n;i++)
#define rep(i,n) for(ll i = 0;i < n;i++)
#define flush fflush(stdout)
#define rrep(i,n) for(ll i = n - 1;i >= 0;i--)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define ioboost cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20)
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll qp(ll a, ll b) { ll ans = 1; do { if (b & 1)ans = 1ll * ans*a; a = 1ll * a*a; } while (b >>= 1); return ans; }
ll qp(ll a, ll b, ll mo) { ll ans = 1; do { if (b & 1)ans = 1ll * ans*a%mo; a = 1ll * a*a%mo; } while (b >>= 1); return ans; }

#define _GLIBCXX_DEBUG
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

class BPowersOfTwo {
public:
    static constexpr int kStressIterations = 0;
    static void generateTest(std::ostream& test) {
    }

    void solve(std::istream& cin, std::ostream& cout) {

        int n;cin >> n;
        multiset<ll,greater<ll>> m;
        rep(i,n){
            ll x;cin >> x;
            m.insert(x);
        }
        int ans = 0;
        while(!m.empty()){
            ll x = *m.begin();m.erase(m.begin());
            int i = 0;
            while(1LL << i <= x)i++;

            ll l = (1 << i) - x;
            if(m.find(l) != m.end()){
                m.erase(m.find(l));
                ans++;
            }
        }
        cout << ans << endl;
    }
};

int main() {
	BPowersOfTwo solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 9600
package main

import (
	"fmt"
	"os"
)

func main() {
	x := readInt64()
	cnt := int64(x/11) * 2
	if x%11 == 0 {
		fmt.Println(x / 11 * 2)
		os.Exit(0)
	}

	x = x % 11
	if x <= 6 {
		fmt.Println(cnt + 1)
	} else {
		fmt.Println(cnt + 2)
	}
}

func readInt64() int64 {
	var a int64
	fmt.Scan(&a)
	return a
}


Measured memory_bytes: 512
#include<iostream>
using namespace std;
int sum=0;
int n;
void dfs(long ans,int a3,int a5,int a7)
{
	if(a3>0&&a5>0&&a7>0&&ans<=n)sum++;
	if(ans*10<n)
	{
		dfs(ans*10+3,a3+1,a5,a7);
		dfs(ans*10+5,a3,a5+1,a7);
		dfs(ans*10+7,a3,a5,a7+1);
	}
}
int main()
{
	cin>>n;
	dfs(0,0,0,0);
	cout<<sum;
	return 0;
	
}

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

#ifdef LOCAL
#define debug(var) cerr << #var << " = " << var << endl;
#else
#define debug(var)
#endif

void init() {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
}

string s[56];

void solve() {
	int n; cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> s[i];
	}
	map<char, int> ans;
	for (char c: s[0]) {
		++ans[c];
	}
	for (int i = 1; i < n; ++i) {
		map<char, int> cur;
		for (char c: s[i]) {
			++cur[c];
		}
		for (const auto &e: ans) {
			ans[e.first] = min(ans[e.first], cur[e.first]);
		}
	}
	for (const auto &e: ans) {
		if (e.second) {
			for (int i = 0; i < e.second; ++i) cout << e.first;
		}
	}
}

int main() {
	init();
	int t = 1; //scanf("%d", &t);
	while (t--) {
		solve();
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++) 
#define FOR(i, a, b) for(int (i) = a; (i) < (int)b; i++)
#define RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=(int)a; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define NIL -1
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define SZ(x)  (int)x.size()
#define SP(x)  setprecision((int)x)


using namespace std ;
typedef long long ll;
using Graph = vector<vector<int>>;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<string> vstr;
typedef pair<int, int> pii;
const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;} //最小公倍数

//-------------------------------------------------
// 
void yes(){
  cout <<"YES"<<endl ;
}
void no(){
  cout <<"NO"<<endl ;
}


//-------------------------------------------------
// メモ
/*






*/
//-------------------------------------------------


int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s ;
  cin >> s ;
  int n = SZ(s) ;
  int a, b, c ;
  a = b = c = 0 ;
  REP(i,n){
    if(s[i]=='a'){
      a++ ;
    }
    else if(s[i]=='b'){
      b++ ;
    }
    else{
      c++ ;
    }
  }
  if(max({a,b,c})-min({a,b,c})<=1){
    yes() ;
  }
  else{
    no() ;
  }
  
  
  
  
  return 0 ;
}



Measured memory_bytes: 512
main = do
  n <- readLn::IO Int
  if n == 0 then return ()
  else do
    v <- (return . map (read::String->Double) . words) =<< getLine
    print $ stdv v
    main
mean v = (sum v) / ((fromIntegral::Int->Double) (length v))
stdv v = (mean $ map ((**2.0) . subtract (mean v)) v)**0.5


Measured memory_bytes: 5036
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	ar := make([]int, 3*n)
	for i := range ar {
		ar[i] = nextInt()
	}
	sort.Ints(ar)
	sum := 0
	for i := 0; i < n; i++ {
		sum += ar[3*n-(i+1)*2]
	}
	fmt.Println(sum)
}

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}


Measured memory_bytes: 5248
#include <bits/stdc++.h>
using std::cout;
using std::endl;
using std::cin;

int main(){
	int n; cin >> n; std::vector<int> a(3 * n);
	for(int i = 0; i < 3 * n; i++) cin >> a[i];
	sort(begin(a), end(a)); reverse(begin(a), end(a));
	
	long ans = 0;
	for(int i = 0; i < n; i++) ans += a[i * 2 + 1];
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
long long a[233];
int b[3]={3,5,7};
int vis[3];
int ans;
long long t ;
void dfs(int i)
{
    long long  num=0;
    memset(vis,0,sizeof(vis));
    for(int j=1;j<i;j++)
    {
        num=num*10+a[j];
        if(a[j]==3) vis[0]=1;
        if(a[j]==5) vis[1]=1;
        if(a[j]==7) vis[2]=1;
    }

    int flag= vis[0]*vis[1]*vis[2];
    if(num > t ) return ;

    if(flag) {ans++;
    }
    for(int j = 0 ;j<3;j++)
    {
        a[i]=b[j];
        dfs(i+1);
    }
}
int main()
{

  scanf("%d",&t);
   ans=0;
  dfs(1);

  printf("%d\n",ans);
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>

int main(void){

    char N[4];

    scanf("%s", N);

    if(N[0] == N[2]){
        printf("Yes\n");
    }else{
        printf("No\n");
    }

    return 0;
}

Measured memory_bytes: 1644
n,m=map(int,input().split())
lr=[list(map(int,input().split())) for i in range(m)]

min_num=0
max_num=10**5
for l,r in lr:
    if l>min_num:min_num=l
    if r<max_num:max_num=r

print(max(max_num-min_num+1,0))

Measured memory_bytes: 27328
from queue import Queue

n, m = map(int, input().split())

E = [[] for i in range(n + 1)]
ind = [0] * (n + 1)
dp = [0] * (n + 1)
Q = Queue()
for i in range(m):
    x, y = map(int, input().split())
    E[x].append(y)
    ind[y] += 1

for i in range(1, n + 1):
    if not ind[i]:
        Q.put(i)

while not Q.empty():
    u = Q.get()
    for i in E[u]:
        ind[i] -= 1
        dp[i] = max(dp[i], dp[u] + 1)
        if not ind[i]:
            Q.put(i)

print(max(dp))


Measured memory_bytes: 23596
n,m=map(int,input().split())
a=list(map(int,input().split()))
ans=[]
s=sum(a)
for i in range(n):
    if a[i]>=s*1/(4*m):
        ans.append(a[i])
if len(ans)>=m:
    print("Yes")
else:
    print("No")

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

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

template<class T> bool umin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool umax(T &a, T b) { return a < b ? (a = b, true) : false; }

using namespace std;

int main(int argc, char** argv)
{
#ifdef HOME
	if (IsDebuggerPresent())
	{
		freopen("../in.txt", "rb", stdin);
		freopen("../out.txt", "wb", stdout);
	}
#endif
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.precision(10);
	cout << fixed;
	int H, W;

	cin >> H >> W;
	vector<string> a(H);
	forn(i, H)
		cin >> a[i];

	vector<vector<bool> > used(H, vector<bool>(W));
	vector<pair<int, int> > v, w;
	forn(i, H) forn(j, W) if (a[i][j] == '#')
	{
		v.push_back(make_pair(i, j));
		used[i][j] = true;
	}
	int res = 0;
	while (true)
	{
		w = v;
		v.clear();
		forn(i, w.size())
		{
			fore(j, -1, 1) fore(k, -1, 1) if (k*j == 0 && k + j)
			{
				pair<int, int> cand = w[i];
				cand.first += j;
				cand.second += k;
				if (cand.first >= 0 && cand.first < H &&
					cand.second >= 0 && cand.second < W &&
					!used[cand.first][cand.second])
				{
					used[cand.first][cand.second] = true;
					v.push_back(cand);
				}
			}
		}
		if(v.empty())
			break;
		++res;
		w.clear();
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 17256