akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int main() {
    int n, W, w, v, p, ans=0;
    long long t;
    vector<int> q[4];
    cin >> n >> W;
    for(int i=0;i<n;i++){
        cin >> w >> v;
        if(i == 0)p = w;
        q[w-p].push_back(v);
    }
    for(int i=0;i<4;i++){
        sort(q[i].begin(), q[i].end(), greater<int>());
        for(int j=1;j<q[i].size();j++){
            q[i][j] += q[i][j-1];
        }
    }
    for(int i=0;i<=q[0].size();i++){
        for(int j=0;j<=q[1].size();j++){
            for(int k=0;k<=q[2].size();k++){
                t = (long long)p*(i+j+k)+j+k*2;
                if(t <= W){
                    int u = (W - t)/(p+3);
                    u = min(u, (int)q[3].size());
                    int s=0;
                    if(i>0)s+=q[0][i-1];
                    if(j>0)s+=q[1][j-1];
                    if(k>0)s+=q[2][k-1];
                    if(u>0)s+=q[3][u-1];
                    ans=max(ans, s);
                }
            }
        }
    }
    cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cmath>
#include <string>
#include <vector>
#include <utility>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <numeric>
#include <array>
#include <float.h>
#include <memory>
#include <functional>
#include <iomanip>
#include <queue>
#include <random>
#include <map>
#include <set>

#pragma warning(disable:4996)

using namespace std;

int main() {
  string a, b, c;
  cin >> a >> b >> c;
  cout << (a.back() == b.front() && b.back() == c.front() ? "YES" : "NO") << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define ll long long
#define ld long double
#define MOD 1000000007
#define nl cout << bl
#define rt ll Q[100005] = {0}
#define mp make_pair
#define test() \
    ull t;     \
    cin >> t;  \
    while (t--)
#define pb push_back
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define s(ar, n) sort(ar, ar + n)
#define rs(ar, n) sort(ar, ar + n, greater<ll>())
#define oa(a, n)               \
    for (ll i = 0; i < n; i++) \
        cout << a[i] << " ";
#define cn(a, n)               \
    for (ll i = 0; i < n; i++) \
        cin >> a[i];
#define ov(a, n)                    \
    for (ll i = n - 1; i >= 0; i--) \
        cout << a[i] << " ";        \
    nl
#define ovp(a, n)              \
    for (ll i = 0; i < n; i++) \
        cout << a[i].ff << " " << a[i].ss << bl;
#define maxa(ar, N) *max_element(ar, ar + N)
#define mina(ar, N) *min_element(ar, ar + N)
#define present(c, x) ((c).find(x) != (c).end())
#define fastio()                  \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0)
typedef pair<int, int> pii;
ll fast_exp(ll base, ll exp)
{
    ll res = 1;
    while (exp > 0)
    {
        if (exp % 2 == 1)
            res = (res * base) % MOD;
        base = (base * base) % MOD;
        exp /= 2;
    }
    return res % MOD;
}
ll fib(ll n)
{
    if (n < 2)
        return n;
    ll a = 0, b = 1, pre;
    int i = 1;
    while (i < n)
    {
        pre = (a + b) % MOD;
        a = b;
        b = pre;
        i++;
    }
    return pre;
}
ll fac(ll n)
{
    if (n % 2 == 0)
        return 2;

    for (ll i = 3; i * i <= n; i += 2)
    {
        if (n % i == 0)
            return i;
    }

    return n;
}
ll fact(ll n)
{
    if (n > 1)
        return n * fact(n - 1);
    else
        return 1;
}
bool sortbysec(const tuple<int, int, int> &a,
               const tuple<int, int, int> &b)
{
    return (get<1>(a) < get<1>(b));
}

int main()
{
    map<string, int> mp;
    int n;
    cin >> n;
    while (n--)
    {
        string s;
        cin >> s;
        mp[s]++;
    }
    cout << "AC x " << mp["AC"] << "\n";
    cout << "WA x " << mp["WA"] << "\n";
    cout << "TLE x " << mp["TLE"] << "\n";
    cout << "RE x " << mp["RE"] << "\n";
}

Measured memory_bytes: 3632
#include<iostream>
#include<algorithm>
#include<vector>
#include <map>
#include<queue>
#include<climits>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
typedef queue<int> IntQueue;
//typedef std::pair<ll, int> pair;

const int MAX = 2*(1e6);
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}



void solve(){
  COMinit();
  double X,Y;
  cin>>X>>Y;
  if (max(X,Y)/min(X,Y)>2){
    cout<<0<<endl;
    return;
  }
  int i=0;
  int j=0;
  int cnt_x=0;
  int cnt_y=0;
  while(true){
    if(X==i &&Y==j)break;
    else if((X==i || Y==j)||(X-i==1&&Y-j==1)){
      cout<<0<<endl;
      return;
    }
    if (X-i>Y-j){
      i+=2;
      j++;
      cnt_x++;
    }
    else{
      i++;
      j+=2;
      cnt_y++;
    }
  }
  
  cout<<COM(cnt_x+cnt_y,cnt_x)<<endl;
  return;
}

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


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

int main(){
  long long N,K,p,r;
  cin >> N >> K;

  long long cnt = 0;

  if(K == 0) {
    cnt = N*N;
    cout << cnt << endl;
    return 0;
  }

  for(long long b = 1; b <= N; b++){
    p = N/b;
    r = N%b;

    cnt += p*max(b-K,(long long) 0) + max(r+1-K,(long long) 0);
  }

  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 256
h,w=map(int,input().split())
s=[input() for _ in range(h)]
ans=[[] for _ in range(h)]
for i in range(h):
    for j in range(w):
        if s[i][j]==".":
            cnt=0
            for x,y in [(0,1),(1,0),(0,-1),(-1,0),(1,1),(1,-1),(-1,1),(-1,-1)]:
                if 0<=i+x<h and 0<=j+y<w:
                    if s[i+x][j+y]=="#":
                        cnt+=1
            ans[i].append(str(cnt))
        else:
            ans[i].append("#")
for i in range(h):
    print("".join(ans[i]))

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

#define ll long long int
#define ri register int
#define endl "\n"

using namespace std;

int dp[3002][3002] = {};
int main()
{
	ios_base::sync_with_stdio(false);
	string s, t;
	cin >> s >> t;

	for (ri i = 1; i <= s.length(); i++)
	{
		for (ri j = 1; j <= t.length(); j++)
		{
			if (s[i - 1] == t[j - 1])
			{
				dp[i][j] = 1 + dp[i - 1][j - 1];
			}
			else
			{
				dp[i][j] = max(dp[i][j - 1], dp[i - 1][j]);
			}
		}
	}

	stack<char> st;
	int i = s.length(), j = t.length();
	while (i > 0 && j > 0)
	{
		if (dp[i][j] == dp[i][j - 1]) j--;
		else if (dp[i][j] == dp[i - 1][j]) i--;
		else if (dp[i][j] == 1 + dp[i - 1][j - 1])
		{
			st.push(s[i - 1]);
			i--;
			j--;
		}
	}

	string ans = "";
	while (!st.empty())
	{
		ans += st.top();
		st.pop();
	}

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


Measured memory_bytes: 35456
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;

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 (a>b) { a=b; return 1; } return 0; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()

template< typename T >
struct edge {
  int src, to;
  T cost;

  edge(int to, T cost) : src(-1), to(to), cost(cost) {}

  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

  edge &operator=(const int &x) {
    to = x;
    return *this;
  }

  operator int() const { return to; }
};

template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WeightedGraph = vector< Edges< T > >;
using UnWeightedGraph = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;

template< typename T >
vector< T > dijkstra(WeightedGraph< T > &g, int s) {
  const auto INF = numeric_limits< T >::max();
  vector< T > dist(g.size(), INF);

  using Pi = pair< T, int >;
  priority_queue< Pi, vector< Pi >, greater< Pi > > que;
  dist[s] = 0;
  que.emplace(dist[s], s);
  while(!que.empty()) {
    T cost;
    int idx;
    tie(cost, idx) = que.top();
    que.pop();
    if(dist[idx] < cost) continue;
    for(auto &e : g[idx]) {
      auto next_cost = cost + e.cost;
      if(dist[e.to] <= next_cost) continue;
      dist[e.to] = next_cost;
      que.emplace(dist[e.to], e.to);
    }
  }
  return dist;
}

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> a(m), b(m);
    rep(i, m) {
        cin >> a[i] >> b[i];
        a[i]--; b[i]--;
    }
    int ctr = 0;
    rep (i, m) {
        WeightedGraph<int> G(n);
        rep (j, m) {
            if (j == i) {
                continue;
            } else {
                G[a[j]].emplace_back(b[j], 1);
                G[b[j]].emplace_back(a[j], 1);
            }
        }
        auto res =dijkstra(G, 0);
        rep (j, res.size()) {
            if (res[j] > 1000) {
                break;
            } else if(j == res.size() - 1) {
                ctr++;
            }
        }
    }
    cout << m - ctr << endl;
}


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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long a, b, v, w, t;
  cin >> a >> v >> b >> w >> t;
  long long d = abs(a - b);
  if (v > w && d <= (v - w) * t)
    cout << "YES" << '\n';
  else
    cout << "NO" << '\n';
  
  return 0;
}

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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;

#define INF INT_MAX/3

#define MAX_N 1000

int n;
int t[1111],a[1111];

int main(){
	cin.sync_with_stdio(false);
	cin>>n;
	rep(i,n)cin>>t[i]>>a[i];
	ll x=t[0],y=a[0];
	repl(i,1,n){
		ll n=max(x/t[i],y/a[i]);
		if(t[i]*n<x||a[i]*n<y)n++;
		x=t[i]*n;
		y=a[i]*n;
		//dbg(x); dbg(y);
	}
	cout<<x+y<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream& operator<<(ostream& os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}
int main(){
    int n;
    cin >> n;
    vector<int>a(n+1),b(n);
    rep(i,n+1)cin >> a[i];
    rep(i,n)cin >> b[i];
    ll ans = 0;
    rep(i,n){
        ll t = min(a[i], b[i]);
        b[i] -= t;
        ans += t;
        ans += min(b[i], a[i+1]);
        a[i+1]-=min(b[i], a[i+1]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
#include<stdio.h>
int main()
{
	int N,ba,Player[10],T;
	char c[100];
	while(1){
		ba = 0;
		for(int i=0;i<10;i++) Player[i] = 0;

		scanf("%d",&N);
		if(N == 0) break;

			scanf("%s",c);
			for(int i = 0;i<100;i++){
			if(c[i] == 'M')
				Player[i%N]++;
			else if(c[i] == 'S'){
				Player[i%N]++;
				ba = ba + Player[i%N];
				Player[i%N] = 0;
			}
			else if(c[i] == 'L'){
				Player[i%N]++;
				Player[i%N] =  Player[i%N] + ba;
				ba = 0;
			}
		}
		for(int i=0;i<N-1;i++){
			for(int j=i+1;j<N;j++){
				if(Player[i] > Player[j]){
					T = Player[i];
					Player[i] = Player[j];
					Player[j] = T;
				}
			}
		}
		for(int i=0;i<N;i++){
			printf("%d ",Player[i]);
		
		}
		printf("%d\n",ba);
	}

	return 0;
}

Measured memory_bytes: 1032
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>

using namespace std;

#include <stdio.h>
#include <cmath>
#include <algorithm>

using namespace std;

struct Node{
	int data;
	Node* prev;
	Node* next;
};

class List{
public:
	List(){
		motherNode = new Node();
		motherNode->data = -1;
		motherNode->prev = motherNode;
		motherNode->next = motherNode;
		num_of_node = 0;
		current = 0;
	};

	void insertFromLast(int x){
		Node* tmpNode = motherNode->prev;
		if(tmpNode == motherNode){
			motherNode->next = new Node();
			motherNode->next->data = x;
			motherNode->next->next = motherNode;
			motherNode->next->prev = motherNode;
			motherNode->prev = motherNode->next;
			current = motherNode->next;
		}else{
			while(tmpNode != motherNode && tmpNode->data > x){
				tmpNode = tmpNode->prev;
			}
			Node* nextNode = tmpNode->next;
			tmpNode->next = new Node();
			tmpNode->next->data = x;
			tmpNode->next->next = nextNode;
			tmpNode->next->prev = tmpNode;
			nextNode->prev = tmpNode->next;
		}
		num_of_node++;
	}

	void upDist(int a){
		int to_move = a%num_of_node,count = 0;

		if(to_move > num_of_node-(to_move-3)){
			downDist(num_of_node-to_move);
			return;
		}

		Node* tmp = current;
		while(count < to_move){
			tmp = tmp->next;
			if(tmp != motherNode){
				count++;
			}
		}

		if(tmp->next == motherNode){
			current = motherNode->next;
		}else{
			current = tmp->next;
		}

		tmp->prev->next = tmp->next;
		tmp->next->prev = tmp->prev;
		delete tmp;
		num_of_node--;
	}

	void downDist(int a){

		if(a < 0){
			printf("BugBugBug!\n");
			return;
		}

		int to_move = a%num_of_node,count = 0;

		Node* tmp = current;
		while(count < to_move){
			tmp = tmp->prev;
			if(tmp != motherNode){
				count++;
			}
		}

		if(tmp->next == motherNode){
			current = motherNode->next;
		}else{
			current = tmp->next;
		}

		tmp->prev->next = tmp->next;
		tmp->next->prev = tmp->prev;
		delete tmp;
		num_of_node--;
	}

	void showList(){
		Node* tmpNode = motherNode->next;
		printf("%d",tmpNode->data);
		printf("\n");
	}

private:
	Node* motherNode;
	Node* current;
	int num_of_node;
};

void func(int n,int k,int m){

	List list;

	for(int i=0; i < n; i++){
		list.insertFromLast(i+1);
	}

	list.upDist(m-1);

	for(int i=0; i < n-2; i++){
		list.upDist(k-1);
	}

	list.showList();

}

int main(){

	int n,k,m;
	while(true){
		scanf("%d %d %d",&n,&k,&m);
		if(n == 0 && k == 0 && m == 0)break;

		func(n,k,m);
	}
    return 0;
}

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

#define FOR(a, b, c) for(int a = b; a <= c; ++a)
#define fi first
#define se second
#define pb push_back
#define int long long

typedef pair<int, int> ii;
typedef pair<int, ii> iii;

const int N = 2e5 + 10;
const int oo = 1e18;

set<int> st;

void load(int &x)   {
    st.insert(x);
    if(x % 2) x = x * 3 + 1;
    else x /= 2;
}
signed main()  {
//    freopen("test.inp", "r", stdin);
//    freopen("test.out", "w", stdout);
    ios_base::sync_with_stdio(false); cout.tie(0);
    int x; cin >> x;
    load(x); int cnt = 2;
    while(st.find(x) == st.end()) load(x), cnt ++;
    return cout << cnt, 0;
}


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

using namespace std;
#define MOD 1000000007
#define pi 3.1415926535897932384626433832795028841971693993751058209749445923078164062
#define ll long long
#define pb push_back
#define pf push_front
#define mp make_pair
#define mt make_tuple
#define ub upper_bound
#define lb lower_bound
#define popb pop_back()
#define popf pop_front()
#define ff first
#define ss second
#define vl vector<ll>
#define vi vector<int>
#define vs vector<string>
#define vll vector< pair<ll,ll> >
#define vii vector< pair<int,int> >
#define viii vector< tuple <int,int,int> >
#define vlll vector< tuple <ll,ll,ll> >
#define vvl vector<vector<ll>>
#define vv vector<vector<int>>
#define all(v) v.begin(),v.end()
#define sqrt sqrtl
#define cbrt cbrtl
#define pll pair<ll,ll>
#define pii pair<int,int>
#define mapcl map<char,ll>
#define mapci map<char,int>
#define mapll map<ll,ll>
#define mapii map<int,int>
#define seti set<int>
ifstream fin("input.txt");
ofstream fout("output.txt");
#define FOR(i, l, r) for (int i = int(l); i < int(r); ++i)

ll fast_exp(ll base, ll exp) {ll res=1;while(exp>0) {if(exp%2==1) res=(res*base)%MOD;base=(base*base)%MOD;exp/=2;}return res%MOD;}
int gcd(int a,int b){while (a&&b)a>b?a%=b:b%=a;return a+b;}
int val(char c){if (c >= '0' && c <= '9')return (int)c - '0';else return (int)c - 'A' + 10;}
ll pows(int a , int b){ll res=1;for(int i=0; i<b; ++i){res*=a;}return res;}
ll logx(ll base, ll num){int cnt=0;while(num!=1){num/=base; ++cnt;}return cnt;}
ll divisibles(ll a, ll b, ll m){if(a%m==0)return (b/m)-(a/m)+1;else return (b/m)-(a/m);}// in [a,b]
string bitstring(int n){string s;while(n){s+=(n%2)+'0';n/=2;}reverse(all(s));return s;} // only sufficient bits
// dsu start

vi root(200001,0);
vi size(200001,1);
int find(int x){while(x!=root[x])x = root[x];return x;}
bool same(int a,int b){return find(a)==find(b);}
void unite(int a, int b){a = find(a);b = find(b);if(size[a]<size[b])swap(a,b);size[a] += size[b];root[b] = a;}

// dsu end
vi vis(200001,0);
vi adj[200001];
set< pair<double,double> > setx;
vector < pair <double,double> >  vec;
vector <double> ans;
int n;
mapii mps;
void pathgen(int s, int len, double sum)
{
	if(len==n-1)
	{
		//cout<<"YAY";
		ans.pb(sum);
		return ;
	}
	for(int i=0; i<n; ++i)
	{
		if(!mps[i])
		{
			++mps[i];
			//cout<<s<<" "<<i<<"\n";
			double x = vec[s].ff-vec[i].ff;
			double y = vec[s].ss-vec[i].ss;
			double ans = sqrtl((pow(x,2)) + pow(y,2));
			//cout<<ans<<"\n";
			pathgen(i,len+1,sum+ans);
			--mps[i];
		}
	}


}
int main()
{	
    std::ios::sync_with_stdio(false);
    //string bitstring = std::bitset< 3 >( 7 ).to_string(); <bits> (num)
    //srand(time(0));
    //cin.tie(NULL);
    //cout.tie(NULL);
 	
 	cin>>n;
 	for(int i=0; i<n; ++i)
 	{
 		double x,y;
 		cin>>x>>y;
 		vec.pb(mp(x,y));
 	}
 	for(int i=0; i<n; ++i)
 	{
 		++mps[i];
 		pathgen(i,0,0);
 		--mps[i];
 	}
 	double sum = 0;
 	for(auto x : ans)
 		sum+=x;
 	//cout<<fixed<<sum<<"\n";
 	sum/=ans.size();
 	cout<<fixed<<sum<<"\n";

}

Measured memory_bytes: 7932
#include <stdio.h>
 
int main () {

	int N, A, B;
	
	scanf("%d%d%d", &N, &A, &B);
	
	int count;
	int total = 0;
	for(int i = 1; i <= N; i++) {
		int tmp = 0;
		count = i ;
		
		while (count > 0) {
			tmp += count % 10;
			count /= 10;
		}

		if (tmp >= A && tmp <= B) {
			total += i;
		}
		
	}
	

	printf("%d\n", total);

	return 0;

}

Measured memory_bytes: 1720
n, m = gets.split.map(&:to_i)
v = Array.new n
g = Array.new(n) { [] }
m.times do
  s, t = gets.split.map(&:to_i)
  g[s] << t
  g[t] << s
end
n.times do |u|
  next if v[u]
  v[u] = u
  stack = [u]
  until stack.empty?
    s = stack.pop
    v[s] = u
    g[s].each do |t|
      stack.push t unless v[t]
    end
  end
end
gets.to_i.times do
  s, t = gets.split.map(&:to_i)
  puts v[s] == v[t] ? 'yes' : 'no'
end

Measured memory_bytes: 18628
import java.util.Scanner;


public class Main {


//	final int MOD = 1000000007;

//	public static int max = 0;

	public static int[] a = {1, 2};

	public static void main(String[] args) {

		int ans = 0;
		Scanner sc = new Scanner(System.in);
		boolean f = false;

		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int k = sc.nextInt();
//		String s = sc.next();

//		int[] ans = new int[n];

//		ArrayList<Integer> list = new ArrayList<>();


		//-------------------------------------------------------------------------------------

		if(a >= k) {
			ans = k;
		} else {
			if(a + b >= k) {
				ans = a;
			} else {
				ans = a - (k - (a + b));
			}
		}

		//-------------------------------------------------------------------------------------

//		for(int i = 0; i < n; i++) {
//			System.out.println(ans[i]);
//		}

//		if(!f) {
//			System.out.println("Yes");
//		} else {
//			System.out.println("No");
//		}

		System.out.println(ans);

		sc.close();
	}
}

Measured memory_bytes: 35884
#include <stdio.h>
#include <math.h>

int main(void){
  double xp1,xp2,yp1,yp2,xp,yp;
  int q;
  scanf("%lf %lf %lf %lf",&xp1,&yp1,&xp2,&yp2);
  scanf("%d",&q);
  double v1x,v1y;
  v1x=(xp2-xp1)/sqrt((yp2-yp1)*(yp2-yp1)+(xp2-xp1)*(xp2-xp1));
  v1y=(yp2-yp1)/sqrt((yp2-yp1)*(yp2-yp1)+(xp2-xp1)*(xp2-xp1));
  double dot;
  for(int i=0;i<q;i++){
    scanf("%lf %lf",&xp,&yp);
    dot=(xp-xp1)*v1x+(yp-yp1)*v1y;
    printf("%.16f %.16f\n",xp1+dot*v1x,yp1+dot*v1y);
  }
  return 0;
}



Measured memory_bytes: 2148
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define popb pop_back
#define popf pop_front
#define all(v) v.begin(), v.end()
#define fori(i, j, k) for (int i = (j); i < (int)(k); i++)
#define forb(i, j, k) for (int i = (j); i >= (int)k; i--)
#define lchild(ind) 2 * ind + 1
#define rchild(ind) 2 * ind + 2
#define bug(val) cout << "# " << val << endl;
#define bugs(val) cout << '_' << val;
#define bugl(val) cout << "## " << val << endl;

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 long double ld;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef pair<int, pll> pip;
typedef pair<ll, pll> plp;
typedef pair<pll, int> ppi;
typedef pair<pll, ll> ppl;
typedef pair<pll, pll> ppp;
typedef vector<int> vi;
typedef vector<ll> vll;

const int maxn = 3e5 + 100;
const ll inf = 2e18, mod = 998244353;

ll fac[maxn], rfac[maxn];

ll c(ll n, ll k)
{
	if (k > n || k < 0)
		return 0;
	return (((fac[n] * rfac[k]) % mod) * rfac[n - k]) % mod;
}

ll poww(ll a, ll b)
{
	ll ans = 1;
	while(b)
	{
		if (b & 1)
			ans = (ans * a) % mod;
		a = (a * a) % mod;
		b = (b / 2);
	}
	return ans;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	fac[0]=1;
	rfac[0]=1;
	fori (i, 1, maxn)
	{
		fac[i] = (fac[i - 1] * i) % mod;
		rfac[i] = poww(fac[i],mod - 2);
	}
	ll n, a, b, k;
	cin >> n >> a >> b >> k;
	ll ans = 0;
	fori (i, 0, n + 1)
	{
		ll kk = k - a * i;
		if (kk >= 0 && kk % b == 0)
		{
			ll j = kk / b;
			ans += (c(n, i) * c(n, j)) % mod;
			ans %= mod;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 4992
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  a,b=LI()
  l=LI()

  c=1
  _b=b
  while True:
    if a<=_b:
      break
    else:
      _b+=b-1
      c+=1

  return c

print(main())


Measured memory_bytes: 16296
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << max(a * b, c * d) << endl;
    
}

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

vector<vector<ll>> G(100007, vector<ll>(0));

void dfs(ll x,vl &d){
    for(auto p: G[x]){
        if(d[p]==-1){
            d[p]=d[x]+1;
            dfs(p,d);
        }
    }
}


signed main(void){
    cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    vector<char> A(N);
    vector<char> B(N);
    for(ll i=0;i<N;++i)cin>>A[i];
    for(ll i=0;i<N;++i)cin>>B[i];
    vector<ll> vec(0);
    for(ll i=0;i<N;++i){
        if(A[i]==B[i])vec.emplace_back(1);
        else {
            vec.emplace_back(2);
            i++;
        }
    }
    ll ans;
    if(vec[0]==1)ans=3;
    else ans=6;
    for(ll i=1;i<vec.size();++i){
        ll &a=vec[i-1],&b=vec[i];
        if(a==1&&b==1)ans*=2;
        else if(a==1&&b==2)ans*=2;
        else if(a==2&&b==1)ans*=1;
        else if(a==2&&b==2)ans*=3;
        ans%=MOD;
    }
    prt(ans)
    return 0;
}


Measured memory_bytes: 2560
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> P;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
/*
vector<char>al(26);
al = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
vector<char>AL(26);
AL = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
*/

int main() {
	int N;
	cin >> N;
	int ans = 0;
	rep(i, 50000) {
		if ((i * 108)-(i*108)%100 == N * 100) {
			ans = i;
			break;
		}
	}
	if (ans == 0) {
		cout << ":(" << endl;
	}
	else {
		cout << ans << endl;
	}
}



Measured memory_bytes: 256
function Main(input){
  const [a, b] = input.split(' ');
  const result = a - b;
  result > 0 ? console.log('a > b'):
  result < 0 ? console.log('a < b'):
  result === 0 ? console.log("a == b"):
  console.log("I don't know.");  
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 15352
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Pranay2516
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BGoToJail solver = new BGoToJail();
        solver.solve(1, in, out);
        out.close();
    }

    static class BGoToJail {
        public void solve(int testNumber, FastReader in, PrintWriter out) {
            int n = in.nextInt(), cnt = 0;
            for (int i = 0; i < n; ++i) {
                int u = in.nextInt(), v = in.nextInt();
                if (u == v) cnt++;
                else cnt = 0;
                if (cnt >= 3) {
                    out.println("Yes");
                    return;
                }
            }
            out.println("No");
        }

    }

    static class FastReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private FastReader.SpaceCharFilter filter;

        public FastReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) throw new InputMismatchException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) return -1;
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}



Measured memory_bytes: 32400
#include<bits/stdc++.h>
using namespace std;
const int N=500005;
const long long M=998244353;
const long long iv2=499122177;
int n,t,i,v[N],w[N],l,q,j;
int dp[512][100005];
int dfs(int t,int l)
{
	if(t<512)
		return dp[t][l];
	int s=dfs(t/2,l);
	if(l>=w[t])
		s=max(s,dfs(t/2,l-w[t])+v[t]);
	return s;
}
int main()
{
	scanf("%d",&n);
	for(i=1;i<=n;++i)
		scanf("%d %d",&v[i],&w[i]);
	for(i=1;i<512&&i<=n;++i)
	{
		for(j=100000;j>=w[i];--j)
			dp[i][j]=max(dp[i/2][j],dp[i/2][j-w[i]]+v[i]);
		for(j=w[i]-1;j>=0;--j)
			dp[i][j]=dp[i/2][j];
	}
	scanf("%d",&q);
	while(q--)
	{
		scanf("%d %d",&t,&l);
		printf("%d\n",dfs(t,l));
	}
}

Measured memory_bytes: 205508
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <ctype.h>
#include <ios> 
#include <iomanip>
using namespace std;

#define N_MAX   (100000)
#define LL_MAX_NUM (1LL<<60)
#define INF 1e7

typedef long long ll;
typedef long long int lli;

int main() {
    int K, X; cin >> K >> X;
    vector<int> res;
    res.push_back(X);
    for (int i = 1; i <=K-1; i++)
    {
        res.push_back(X-i);
        res.push_back(X+i);
    }
    sort(res.begin(), res.end());
    for (int j = 0; j < res.size(); j++)
    {
        cout << res[j];
        cout << " ";
    }
    cout << endl;
	return 0;
}

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

int main()
{
    long long n, count=0, sum=0;
    cin >> n;

    vector<string> str(n);
    for (long long i = 0; i < n;i++){
        cin >> str.at(i);
        sort(str.at(i).begin(), str.at(i).end());
    }
    //cout << endl;
    sort(str.begin(), str.end());
    for (long long i = 0; i < n-1; i++)
    {
        if(str.at(i)==str.at(i+1)){
            count++;
            sum += count;
            //cout << count << " " << sum << endl;
        }
        else{
            count = 0;
        }
        //cout << str.at(i) << endl;
    }
    cout << sum << endl;

    /*
    vector<vector<char>> s(n, vector<char>(10));
    for (long long i = 0; i < n;i++){
        for (long long j =0 ; j < 10;j++){
            cin >> s.at(i).at(j);
        }
        sort(s.at(i).begin(), s.at(i).end());
    }


        cout << endl;
    sort(s.begin(), s.end());

    for (long long i = 0; i < n; i++)
    {
        for (long long j =0 ; j < 10; j++)
        {
            cout<< s.at(i).at(j);
        }
        cout << endl;
    }
    */
}

Measured memory_bytes: 7296
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define dup(x,y) (((x)+(y)-1)/(y))
#define v(T) vector<T>
#define vv(T) v(v(T))
using ll = int64_t;
using ull = uint64_t;
using uint = uint32_t;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using pil = pair<int,ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,v.size())i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,v.size())s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(v.size())o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
const double eps = 1e-6;
const ll LINF = 100200300400500600ll;
const int INF = 1001001001;
//--------------------------------------------------------
#define fastio cin.tie(nullptr); std::ios::sync_with_stdio(false);
#define myio ifstream iofi; if(argc>1){iofi.open(argv[1]); std::cin.rdbuf(iofi.rdbuf());}
#define myloopset int loop = 1; if(argc>2) loop =stoi(argv[2]); rep(i,loop)
//--------------------------------------------------------------
template <class T> T chmin(T &a,T b){if(a>b){a=b; return 1;}else return 0;}
template <class T> T chmax(T &a,T b){if(a<b){a=b; return 1;}else return 0;}
const int dx[4] = {0,1,0,-1};
const int dy[4] = {-1,0,1,0};
const int mod = 1000000007;

void Main(){
  int A,B,m;
  cin>>A>>B>>m;
  vi a(A),b(B);
  cin>>a;
  cin>>b;
  int ans=*min_element(rng(a))+*min_element(rng(b));
  rep(i,m){
    int x,y,c;
    cin>>x>>y>>c;
    chmin(ans,a[x-1]+b[y-1]-c);
  }
  cout<<ans<<endl;
} signed main(int argc,char** argv)
{fastio; myio; myloopset Main();}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  if((abs(a-b)<=d&&abs(b-c)<=d)||abs(c-a)<=d){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}


Measured memory_bytes: 256
import java.lang.reflect.Array;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        if(sc.nextInt() <=8 && sc.nextInt() <= 8)System.out.println("Yay!");
        else System.out.println(":(");

    }
}

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

// iterator
#define REP(i,init, n) for(lli i=init;i<n;i++)
#define REPE(i,init, n) for(lli i=init;i<=n;i++)
#define REPIT(it,container) for(auto it = container.begin(); it != container.end(); it++)
#define REPIT_R(it,container) for(auto it = container.rbegin(); it != container.rend(); it++)

// input
#define cin1(x)             cin >> x
#define cin2(x, y)          cin >> x >> y
#define cin3(x, y, z)       cin >> x >> y >> z
#define ncin1(n, x)         REP(i, 0, n) {cin1(x[i]);}
#define ncin2(n, x, y)      REP(i, 0, n) {cin2(x[i], y[i]);}
#define ncin3(n, x, y, z)   REP(i, 0, n) {cin3(x[i], y[i], z[i]);}

// output
#define cout1(x)         cout << #x << ": " << x << endl;
#define ncout1(n, x)     REP(i, 0, n) {cout << #x << "[" << i << "]: "<< x[i] << endl;}

// sort
#define sort_r(x, y)        sort(x, y, greater<lli>()); // 降順(5,4,3,,,)

#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

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

int main() {
    lli n;
    cin1(n);

    lli x = n;
    lli keta =0;
    while (x != 0) {
        x = x / 10;
        keta++;
    }
    lli ans = 0;
    for (lli i = keta; i >= 1; i--) {
        if (i % 2 == 1) {
            if (i == keta) {
                ans += n - pow(10, (i-1)) + 1;
                //cout << "1added: " << n - 10*(i-1) + 1 << endl;
            }
            else {
                ans += 9*pow(10, i-1);

                //cout << "2added: " << 9*i << endl;
            }

        }
    }
    cout << ans<<endl;
}


Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;

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

int main() {
        int n, m;
        cin >> n >> m;
        vector<int> g[202020];
        for (int i = 0; i < m; i ++) {
                int a, b;
                cin >> a >> b;
                a --, b --;
                g[a].push_back(b);
                g[b].push_back(a);
        }
        vector<int> ans;
        for (int i = 0; i < g[0].size(); i ++) {
                ans.push_back(g[0][i]);
        }
        bool ok = false;
        for (int i = 0; i < ans.size(); i ++) {
                for (int j = 0; j < g[ans[i]].size(); j ++) {
                        if (g[ans[i]][j] == n - 1) {
                                ok = true;
                                break;
                        }
                }
        }
        cout << (ok ? "POSSIBLE" : "IMPOSSIBLE") << endl;
        return 0;
}



Measured memory_bytes: 12784
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <string>
#include <utility>
#include <map>
#include <queue>
#include <list>
#include <functional>
#include <numeric>
#include <stack>
#include <tuple>

using namespace std;
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; }

int dx[4] = { -1,0,1,0 };
int dy[4] = { 0,1,0,-1 };
const int INF = 100000000;
const long long LINF = 1001001001001001LL;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-6;
using pii = std::pair<int, int>;
using pLL = std::pair<long long, long long>;
using ll = long long;
#define SORT(v) std::sort(v.begin(), v.end())
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    vector<vector<int>> S(N);
    for (int i = 0; i < N; ++i) {
        int t, d;
        cin >> t >> d;
        --t;
        S[t].push_back(d);
    }
    for (int i = 0; i < N; ++i) sort(S[i].rbegin(), S[i].rend());
    sort(S.rbegin(), S.rend());
    ll ans=0, s=0, t = 0;

    priority_queue<int> pq;
    for (int i = 0; i < min(N, K); ++i) {
        if (S[i].empty()) continue;
        s += S[i][0];
        while (i + 1 + pq.size() > K) {
            s += pq.top();
            pq.pop();
        }
        ans = max(ans, s + t + (ll)(i + 1)*(i + 1));
        for (int j = 1; j < (int)S[i].size(); ++j) {
            t += S[i][j];
            pq.push(-S[i][j]);
            if ((int)pq.size() > K - i - 1) t += pq.top(), pq.pop();
            ans = max(ans, s + t + (i + 1)*(i + 1));
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5760
import statistics as stat

def calc(p):
  count = 0
  for i in range(1, len(p) - 1):
    if p[i] == stat.median(p[i - 1:i + 2]):
      count += 1
  return count

_ = input()
p = list(map(int, input().split()))

print(calc(p))


Measured memory_bytes: 5468
#include <stdlib.h>
#include <stdio.h>
int compare(const void *a,const void *b){
    if(*(int *)a> *(int *)b) return -1;
    return 1;
}
int main()
{   int n;
    scanf("%d",&n);
    int a[n],b[n],c[n];
    long long takahashi=0,aoki=0;
    for(int i=0;i<n;i++){
        scanf("%d%d",&a[i],&b[i]);
        c[i]=a[i]+b[i];
        aoki+=b[i];
    }
    qsort(c,n,sizeof(int),compare);
    for(int i=0;i<n;i+=2){
            takahashi+=c[i];
    }
    printf("%lld",takahashi-aoki);
    return 0;
}


Measured memory_bytes: 1788
#include<bits/stdc++.h>
#define rep(i,a,b) for(register int i=a;i<=b;++i)
#define rpd(i,a,b) for(register int i=a;i>=b;--i)
#define rep1(i,x) for(register int i=head[x];i;i=nxt[i])
typedef long long ll;
const int N=300+5;
using namespace std;
inline int read(){
    int x=0,f=1;char ch=getchar();
    while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
    while(isdigit(ch)){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
string s;int n,m;int f[N][N][N];
void Max(int &x,int y){x=max(x,y);}
int main(){
    cin>>s;s=' '+s;
    n=s.length()-1;m=read();
    rep(i,1,n)rep(j,0,m)f[i][i][j]=1;
    rep(d,2,n)rep(i,1,n){
        int j=i+d-1;if(j>n)break;
        rep(k,0,m){
            if(k)Max(f[i][j][k],f[i][j][k-1]);
            Max(f[i][j][k],f[i+1][j][k]);
            Max(f[i][j][k],f[i][j-1][k]);
            if(s[i]==s[j])Max(f[i][j][k],f[i+1][j-1][k]+2);
            else if(k)Max(f[i][j][k],f[i+1][j-1][k-1]+2);
        }
    }
    printf("%d\n",f[1][n][m]);
    //system("pause");
    return 0;
}
/*

*/

Measured memory_bytes: 110464
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int MAXN = int(1e3);

void solve(long long X){
   
    for(ll i=0LL;i<=MAXN;i++){
        ll A = i*i*i*i*i;
        for(ll j=0LL;j<=MAXN;j++){
            ll B = j*j*j*j*j;
            if(A-B==X){
                cout <<i <<" "<<j<<endl;
                return;
            }
            if(A+B==X){
                cout <<i <<" "<<-j<<endl;
                return;
            }
        }
    }

}

int main(){
    long long X;
    scanf("%lld",&X);
    solve(X);
    return 0;
}


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

#define ln '\n'
#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 FORR(i, a, b) for(int i = (a); i >= (int)(b); --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef vector<P> VP;
typedef vector<PL> VPL;
typedef vector<string> VS;

int n;
int aim_a, aim_b, aim_c;
VI l;


int dfs(int i, int a, int b, int c) {
    if(i == n) {
        if(min({a, b, c}) > 0) 
            return abs(aim_a - a) + abs(aim_b - b) + abs(aim_c - c) - 30;
        else 
            return 1e9;
    }
    int ret0 = dfs(i + 1, a, b, c);
    int ret1 = dfs(i + 1, a + l[i], b, c) + 10;
    int ret2 = dfs(i + 1, a, b + l[i], c) + 10;
    int ret3 = dfs(i + 1, a, b, c + l[i]) + 10;
    return min({ret0, ret1, ret2, ret3});
}


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> aim_a >> aim_b >> aim_c;
    l.resize(n);
    REP(i, n) cin >> l[i];
    cout << dfs(0, 0, 0, 0) << ln;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define PRINT(x) cout << (x) << "\n"
using namespace std;
using ll = long long; using pint = pair<int, int>; using pll = pair<ll, ll>;
template<typename T> auto compare = [](T x, T y) -> bool{return (x < y);};
const int MOD = 1000000007;

int N, M, X;
int C[20], A[20][20], R[20];

int solve(int state){
    int ret = 0;
    REP(i, M) R[i] = 0;
    REP(i, N){
        if(state & (1 << i)){
            REP(j, M) R[j] += A[i][j];
            ret += C[i];
        }
    }
    REP(i, M){
        if(R[i] < X) return INT32_MAX;
    }
    return ret;
}

signed main(){
    cin >> N >> M >> X;
    REP(i, N){
        cin >> C[i];
        REP(j, M) cin >> A[i][j];
    }
    int ans = INT32_MAX;
    REP(i, 1 << N){
        ans = min(ans, solve(i));
    }
    if(ans == INT32_MAX){
        PRINT("-1");
    }else{
        PRINT(ans);
    }
    return 0;
}

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

#define vl vector<ll>
#define vs vector<string>
#define vll vector< vector<ll> >
#define pll pair<ll,ll>
#define pls pair<ll,string>
#define psl pair<string,ll>
#define tll tuple<ll, ll, ll>
#define vp vector< pair<ll,ll> >
#define vt vector< tuple<ll, ll, ll> >
#define all(c) c.begin(),c.end()

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
 
const ll inf = 1000000001;
const ll INF = 1e18;
const ll MOD = 1000000007;

//command
//c++ atcoder.cpp -std=c++14
//./a.out

//cout << setprecision(12) << ans << endl;

#define NN 2020202

int main(){
  string s;
  cin >> s;
  ll len, w, ans;
  if (s.length()%2 == 0){
    len = s.length()/2;
    w = 0;
    while (w<len && s[len-1-w] == s[len-w] && s[len+w-1] == s[len+w]) w += 1;
    ans = len + w;
  }
  else if (s.length()%2 == 1){
    len = (s.length()-1)/2;
    w = 1;
    while (w<=len && s[len-w] == s[len-w+1] && s[len+w-1] == s[len+w]) w += 1;
    ans = len + w;
  }

  cout << ans << endl;
}

Measured memory_bytes: 512
#include<iostream>

using namespace std;

int main(int argc, char const *argv[])
{
	string s;
	int a=0,b;
	cin>>s;

	if(s.length() % 2 != 0)
		cout<<"No"<<endl;
	else{
		for (int i = 0; i < s.length(); i+=2)
		{
			if(s[i] == 'h' && s[i+1] == 'i')
				a++;
		}
		//cout<<a<<" "<<s.length()<<" ";
		if(a==(s.length()/2))
			cout<<"Yes"<<endl;
		else 
			cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <tuple>
#include <cassert>

using namespace std;

#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define pb(e) push_back(e)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define mp(a,b) make_pair((a), (b))
#define mt(a,b,c) make_tuple((a),(b),(c))

typedef long long ll;
long long int gcd(long long int x,long long int y){
    long long int r;
    if(x == 0 || y == 0)  return 0;

    while((r = x % y) != 0) 
    {
         x = y;
        y = r;
    }
    return y;
}

int main(){
    long long int k; cin >> k;
    long long int ans = 0;
    for(int i=1;i<=k;i++)for(int j=1;j<=k;j++)for(int l=1;l<=k;l++){
        ans += gcd(gcd(i,j), l);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3588
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from itertools import accumulate #list(accumulate(A))

N = ii()
S = [input() for _ in range(2)]
mod = 10**9+7
pat = []
i = 0
ans = 1
while i < N:
    if S[0][i] == S[1][i]:
        if i > 0:
            if pat[-1] == 0:
                ans = (ans * 2) % mod
        else:
            ans *= 3
        pat.append(0)
        i += 1
    else:
        if i > 0:
            if pat[-1] == 0:
                ans = (ans * 2) % mod
            else:
                ans = (ans * 3) % mod
        else:
            ans *= 6
        pat.append(1)
        i += 2

print(ans)

Measured memory_bytes: 3064