akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef complex<double> P;
typedef pair< P , P > Pair;
P inf=P( 1e30 , 1e30 );

P reflect(P a,P b,P c){
  b-=a;c-=a;
  return a+conj(c/b)*b;
}

P intersect(P a,P b,P c,P d){
  a-=d;b-=d;c-=d;
  return d+a+(b-a)*imag(-a/c)/imag(b/c-a/c);
}

string s;
int p,len;

Pair calc(Pair a,Pair b){
  if(a.second==inf && b.second==inf){
    return Pair( a.first , b.first );
  }
  if(a.second==inf){
    return Pair( reflect( b.first , b.second , a.first ) , inf );
  }
  if(b.second==inf){
    return Pair( reflect( a.first , a.second , b.first ) , inf );
  }
  return Pair( intersect( a.first , a.second , b.first , b.second ) , inf );
}

Pair solve();

Pair func(){
  if(s[p]=='(' && s[p+1]=='('){
    p++;
    Pair res=solve();
    p++;
    return res;
  }else{
    p++;
    int x=0,y=0;

    bool xf=false;
    if(s[p]=='-')xf=true,p++;
    while( '0'<=s[p] && s[p]<='9'){
      x=x*10+(s[p]-'0');
      p++;
    }
    if(xf)x*=-1;
    
    p++;

    bool yf=false;
    if(s[p]=='-')yf=true,p++;
    while( '0'<=s[p] && s[p]<='9'){
      y=y*10+(s[p]-'0');
      p++;
    }
    if(yf)y*=-1;
    p++;
    return Pair( P(x,y) , inf );
  }
}


Pair solve(){
  Pair a=func();
  while(p<len && s[p]=='@' ){
    p++;
    Pair b=func();
    a=calc(a,b);
  }
  return a;
}

int main(){
  while(1){
    cin>>s;
    if(s=="#")break;
    p=0;
    len=s.size();
    Pair pair=solve();
    P ans=pair.first;
    printf("%.8f %.8f\n",real(ans),imag(ans));
  }
  return 0;
}

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

using ll = long long int;
using P = pair<int, int>;
using P3 = pair<ll,P>;
using PP = pair<P, P>;
constexpr int INF = 1 << 30;
constexpr ll MOD = ll(1e9) + 7;
constexpr int di[] = {0, 1, 0, -1};
constexpr int dj[] = {1, 0, -1, 0};
constexpr double EPS = 1e-8;

bool solve(){
    string s;
    cin >> s;
    int n = s.size(), ans = 0;
    for(int i=0;i<n;i++){
        if(i<n-1 && s[i] == '0') continue;
        int a, b;
        a = (i>0 ? stoi(s.substr(0,i)) : 0);
        b = stoi(s.substr(i,n-i));
        if((a+b)%2==0 && b-a>=0 && (b-a)%2==0){
            ans++;
        }
    }
    cout << ans << endl;
    return false;
}

int main(){
    solve();
    // while(!solve());
    // int t; cin >> t; for(;t>0;t--) solve();
    return 0;
}


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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define ALPHABET    (26)
#define INF         INT_MAX
#define MOD         (1000000007LL)

using LL  = long long;
// }}}

int imos[200005];
int time_[100005][30];

int main() {
    std::ios::sync_with_stdio(false);
    int n, C;cin >> n >> C;
    memset(imos, 0, sizeof(imos));
    memset(time_, 0, sizeof(time_));
    for(int i=0;i<n;i++){
        int s, t, c;cin >> s >> t >> c;c--;
        imos[s*2-1]++;
        imos[t*2]--;
        if(time_[s][c] == 1){
            imos[s*2-1]--;
            imos[s*2]++;
        }
        if(time_[t][c] == 1){
            imos[t*2-1]--;
            imos[t*2]++;
        }
        time_[s][c] = 1;
        time_[t][c] = 1;
    }
    int now = 0;
    int ans = 0;
    for(int i=0;i<200005;i++){
        now += imos[i];
        ans = max(ans, now);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 12800
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;

vector<int> updown;
vector<int> leftright;
int lef[16005][2];
int up[16005][2];
int main(){
    ios::sync_with_stdio(0);
    string s;

    cin >> s;
     int x;cin >> x;
    int y;cin >> y;
    int au=0;
    int coun=0;
    bool flag=0;
    for(int i=0;i<=s.size();++i){
        if(!au){
            if(s[i]=='F'){
                ++coun;
            }
            else{
                au^=1;
                if(coun && flag)
                    leftright.push_back(coun);
                else{
                    x-=coun;flag=1;
                }
                coun=0;

            }
        }
        else{
            if(s[i]=='F'){
                ++coun;
            }
            else{
                au^=1;
                if(coun)
                    updown.push_back(coun);
                coun=0;

            }
        }
    }
    lef[8000][1]=1;
    int si=s.size()+8000;
    for(int i=0;i<leftright.size();++i){
        int coun=leftright[i];
        int u=i%2;int prev=u^1;

        for(int j=0;j+coun<=si;++j){
            lef[j+coun][u]=(lef[j+coun][u] | lef[j][prev]);
        }
        for(int j=0;j+coun<=si;++j){
            lef[j][u]=(lef[j][u] | lef[j+coun][prev]);
        }
        for(int j=0;j<=si;++j){
            lef[j][prev]=0;
        }
    }
    int qw=leftright.size()-1;
    qw%=2;qw+=2;qw%=2;

    if(!lef[8000+x][qw]){
        cout << "No" << endl;return 0;
    }
    up[8000][1]=1;
    //si=2*s.size();
    for(int i=0;i<updown.size();++i){
        int coun=updown[i];
        int u=i%2;int prev=u^1;
        for(int j=0;j+coun<=si;++j){
            up[j+coun][u]=(up[j+coun][u] | up[j][prev]);
        }
        for(int j=0;j+coun<=si;++j){
            up[j][u]=(up[j][u] | up[j+coun][prev]);
        }
        for(int j=0;j<=si;++j){
            up[j][prev]=0;
        }
    }
     qw=updown.size()-1;
    qw%=2;qw+=2;qw%=2;
    if(!up[8000+y][qw]){
        cout << "No" << endl;return 0;
    }
    cout << "Yes" << endl;

    return 0;
}


Measured memory_bytes: 512
#include<stdio.h>

#define MAX 100

int main(void){

  int array[MAX] = {0};
  int i;
  int count = 0;

  while(scanf("%d",&i) != EOF){
    array[i]++;

    if(array[i] > count)
      count = array[i];
  }

  for(i=0;i<MAX;i++){
    if(array[i] == count)
      printf("%d\n",i);
  }
  return 0;
}

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

using namespace std;

#define fore(i, s, e) for(int i = s; i < e; i++)
#define pb push_back
#define fst first
#define snd second

typedef long long ll;

ll mulmod(ll a, ll b, ll m) {
	ll r=a*b-(ll)((long double)a*b/m+.5)*m;
	return r<0?r+m:r;
}
ll expmod(ll b, ll e, ll m){
	if(!e)return 1;
	ll q=expmod(b,e/2,m);q=mulmod(q,q,m);
	return e&1?mulmod(b,q,m):q;
}

const int M = 1e9 + 7;

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

    map<char, int> m;

    ll res = 0;

    fore(i, 0, n) {
        ll y = 1;
        for(auto x : m) if(x.fst != s[i]) {
            y *= (x.snd + 1);
            y %= M;
        }
        res += y;
        res %= M;
        m[s[i]]++;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 512
N=int(input())
A=[]

for i in range(N):
    a = int(input())
    A.append(a)

sorted_a = sorted(A)
max_a = sorted_a[-1]
max_i = A.index(max_a)

second_a = sorted_a[-2]
second_i = A.index(second_a)

for i in range(N):
    if i == max_i:
        print(second_a)
    else:
        print(max_a)

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

int main(){
    int n, k, x;
    cin >> n >> k;

    vector<int> l;
    for(int i = 0; i < n; i++){
        cin >> x;
        l.push_back(x);
    }

    sort(l.rbegin(), l.rend());
    int sum = 0;
    for(int i = 0; i < k; i++)  sum += l[i];

    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
#define LOCAL
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rrep(i, n) for(int i=(n-1); i>=0; --i)
#define rep2(i, s, n) for(int i=s; i<(n); ++i)
#define ALL(v) (v).begin(), (v).end()
#define memr(dp, val) memset(dp, val, sizeof(dp))
using namespace std;
typedef long long ll;
static const int INTINF = (INT_MAX >> 1); // 10^9 + 10^7
static const ll LLINF = (LLONG_MAX >> 1);
static const int MAX = 1e5+1;
static const ll MOD = 1e9+7;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
string to_string(string s) { return '"' + s + '"'; }
string to_string(bool b) { return b ? "true" : "false"; }
template <size_t N> string to_string(bitset<N> bs) {
  string res;
  for (size_t i = 0; i < N; ++i) res += '0' + bs[i];
  return res;
}
string to_string(vector<bool> v) {
  string res = "{";
  for (bool e : v) res += to_string(e) + ", ";
  return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p);
template <class C> string to_string(C c) {
  string res = "{";
  for (auto e : c) res += to_string(e) + ", ";
  return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
void debug() { cerr << '\n'; }
template <class Head, class... Tail> void debug(Head head, Tail... tail) {
  cerr << '\t' << to_string(head), debug(tail...);
}
#ifdef LOCAL
#define DEBUG(...) cerr << "[" << #__VA_ARGS__ << "]:", debug(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

ll dp[MAX];

int main(int argc, const char * argv[]) {
	std::cout << std::fixed << std::setprecision(15);

	int N, W; cin >> N >> W;
	memr(dp, -1);
	ll ans = 0;
	dp[0] = 0;
	rep(i, N){
		int v, w; cin >> v >> w;
		rrep(j, MAX){
			if(dp[j] != -1){
				if(j + w > W) continue;
				chmax(dp[j + w], dp[j] + v);
				chmax(ans, dp[j+w]);
			}
		}
	}

	cout << ans << endl;
}



Measured memory_bytes: 3876
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <limits>
#include <list>
#include <string>
#include <queue>
#include <deque>
#include <tuple>
#include <map>
#include <sstream>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort(ALL(x))
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const long double PI  = acos(-1.0L);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
#define chmax(a,b) a = (((a)<(b))?(b):(a))
#define chmin(a,b) a = (((a)>(b))?(b):(a))

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

struct edge{int to; ll cost;};
typedef pair<ll,int> P;

const int MAX_V = 100005;
int V;
vector<edge> G[MAX_V];
ll d[MAX_V];

void dijkstra(int s){
  priority_queue<P, vector<P>, greater<P> > que;
  fill(d,d+V,LINF);
  d[s] = 0;
  que.push(P(0,s));

  while(!que.empty()){
    P p = que.top(); que.pop();
    int v = p.second;
    if(d[v] < p.first) continue;
    rep(i,G[v].size()){
      edge e = G[v][i];
      if(d[e.to] > d[v]+e.cost){
        d[e.to] = d[v]+e.cost;
        que.push(P(d[e.to],e.to));
      }
    }
  }
}

signed main(){
  int n,m; cin>>n>>m;
	V = n;
	rep(i,m){
		int l,r; ll c; cin>>l>>r>>c; l--; r--;
		G[l].PB({r,c});
	}
	rep(i,n-1){
		G[i+1].PB({i,0L});
	}
	dijkstra(0);
	if(d[n-1]==LINF) cout<<-1<<endl;
	else cout<<d[n-1]<<endl;

  return 0;
}


Measured memory_bytes: 9464
#include<stdio.h>
int sum(int index,int n,int x[]){
    int sum=0;
    for(int i=0;i<n;i++){
        if(i==index) continue;
        sum+=x[i];
    }
    if(sum==0) return 1;
    else return 0;
}
int main(void){
    int i,n,p;
    while(1){
        scanf("%d%d",&n,&p);
        if(n+p==0) break;
        int cand[50]={0},box=p,ans=0;
        for(i=0;;i++){
            if(box==1&&sum(i%n,n,cand)){
                ans=i%n;
                break;
            }
            else if(box>0){
                box-=1;
                cand[i%n]+=1;
            }
            else{
                box+=cand[i%n];
                cand[i%n]=0;
            }
        }
        printf("%d\n",ans);
    }
}


Measured memory_bytes: 1920
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
    n, k = LI()
    h = [I() for _ in range(n)]
    h.sort()
    ans = float("inf")

    for i in range(n-(k-1)):
        ans = min(ans, h[i+k-1]-h[i])
    
    print(ans)
main()


Measured memory_bytes: 78396
#include <stdio.h>
#include <iostream>
#define Re register int
#define mod int(1e9+7)

int N,K,A[105];
long long s[100005],f[105][100005];

template <typename T> inline void read(T &var)
{
	T x=0; int w=0; char ch=0;
	while (!isdigit(ch)) w|=ch=='-',ch=getchar();
	while (isdigit(ch)) x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	var=w?-x:x;
}
int main(int argc, char const *argv[])
{
	read(N),read(K); f[0][0]=1;
	for (Re i=1; i<=N; ++i) read(A[i]);
	for (Re i=1; i<=N; ++i)
	{
		s[0]=0; for (Re j=0; j<=K; ++j)
			s[j+1]=s[j]+f[i-1][j];
		for (Re j=0; j<=K; ++j)
			(f[i][j]=s[j+1]-s[std::max(0,j-A[i])])%=mod;
	}
	printf("%lld\n",f[N][K]);
	return 0;
}

Measured memory_bytes: 80128
#include <iostream>
#include <stdio.h>
#include <sstream>
using namespace std;

int main() {
	string a,b;
	cin >> a >> b;
	if (a.size() < b.size()) {
		cout << "LESS" << endl;
		return 0;
	} else if (a.size() > b.size()) {
		cout << "GREATER" << endl;
		return 0;
	} else {
		for (int i = 0;i < a.size();i++) {
			istringstream e,f;
			e = istringstream(a.substr(i,1));
			f = istringstream(b.substr(i,1));
			int c;
			e >> c;
			int d;
			f >> d;
			if (c < d) {
				cout << "LESS" << endl;
				return 0;
			} else if (c > d) {
				cout << "GREATER" << endl;
				return 0;
			}
		}
		cout << "EQUAL" << endl;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;
int main(){
	int H,W;
	char l;
	cin >> H >> W;
vector<vector<char>> v(H,vector<char>(W));

	for (int i = 0;i< H;i++){
		for (int j = 0;j < W;j++){
			cin >> l;
			v[i][j] = l;
		}
	}
	for (int i = 0;i< H;i++){
		int flag = 0;
		for (int j = 0;j < W;j++){
			if (v[i][j] == '#'){
				flag = 1;
				break;
			}
		}
		if (flag == 0){
			for (int j = 0;j < W;j++){
				v[i][j] = '0';
			}
		}
	}

	for (int i = 0;i< W;i++){
		int flag = 0;
		for (int j = 0;j < H;j++){
			if (v[j][i] == '#'){
				flag = 1;
				break;
			}
		}
		if (flag == 0){
			for (int j = 0;j < H;j++){
				v[j][i] = '0';
			}
		}
	}
	for (int i = 0;i< H;i++){
		int flag = 0;
		for (int j = 0;j < W;j++){
			if (v[i][j] != '0'){
				cout  << v[i][j];
			}
		}
		for (int j = 0;j < W;j++){
			if (v[i][j] == '0'){
				continue;
			}
			else{
				flag = 1;
				break;
			}
		}
		if (flag == 1){
			cout << endl;

		}
	}
	return 0;
}

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

int main()
{
	double x1, y1, x2, y2;
	double e;
	
	scanf("%lf%lf%lf%lf", &x1, &y1, &x2, &y2);
	e = (x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
	printf("%.8lf\n", sqrt(e));
	return 0;
}


Measured memory_bytes: 2148
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>
#include <functional>
#include <cfloat>
#include <math.h>
#include <numeric>
#include <string.h>
#include <sys/time.h>
#include <random>


#define fs first
#define sc second

using namespace std;

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


class Graph{
    struct edge{
        int vertice;
        ll weight;
    };

    vector<vector<edge>> g;
    unsigned int n;

public:
    Graph(unsigned int n): n{n}{
        g.resize(n);
    }

    void add_edge(int u, int v){
        g[u].emplace_back(edge{v, 1});
    };

    void add_edge(int u, int v, ll w){
        g[u].emplace_back(edge{v, w});
    }

    vector<edge>& get_edge(int v){
        return g[v];
    }

    unsigned int get_num_vertices() const{
        return n;
    }

    unsigned int size() const{
        return n;
    }

    vector<edge>& operator[](int v){
        return get_edge(v);
    }
};


/**
 * prim法 (O(|E|log(|V|))のアルゴリズム)
 * @param g 連結グラフ
 * @return 連結グラフの最小域木をグラフとして返す
 */
Graph prim2_g(Graph g){
    // Ptmp.fsが今の部分木からのコスト、Ptmp.ｓｃ.fsが次の頂点、Ptmp.sc.scが次の頂点に辺を伸ばす部分木の頂点
    typedef pair<ll, pair<int, int>> Ptmp;

    unsigned int n = g.size();

    Graph mst(n);   // minimum spanning tree
    vector<ll> used(n, false);
    priority_queue<Ptmp, vector<Ptmp>, greater<Ptmp> > que;

    used[0] = true;
    for(auto e: g[0]){
        que.push(Ptmp(e.weight, pair<int, int>(e.vertice, 0)));
    }

    while(!que.empty()){
        Ptmp p = que.top(); que.pop();
        int to = p.second.first, from = p.second.second;
        if(used[to]) continue;

        used[to] = true;
        mst.add_edge(from, to, p.first);
        mst.add_edge(to, from, p.first);

        for(auto e: g[to]){
            if(!used[e.vertice]){
                que.push(Ptmp(e.weight, pair<int, int>(e.vertice, to)));
            }
        }
    }

    return mst;
}


ll prim2(Graph g){
    unsigned int n = g.size();
    Graph mst = prim2_g(g);

    ll res = 0;
    for(int i = 0; i < n; i++){
        for(auto e: mst[i]){
            res += e.weight;
        }
    }

    return res / 2;
}



int main(){
    int n, m;   cin >> n >> m;
    Graph g(n);
    for(int i = 0; i < m; i++){
        int s, t; ll w;
        cin >> s >> t >> w;
        g.add_edge(s, t, w);
        g.add_edge(t, s, w);
    }

    cout << prim2(g) << endl;

    return 0;
}



Measured memory_bytes: 17532
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;

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

    vector<int> k(n);
    vector<vector<int> > s(n), h(n);
    for(int i=0; i<n; ++i){
        cin >> k[i];
        s[i].resize(k[i]);
        h[i].resize(k[i]);
        for(int j=0; j<k[i]; ++j)
            cin >> s[i][j] >> h[i][j];
    }

    vector<double> dp(m+1, 0);
    for(int a=0; a<n; ++a){
        vector<double> nextDp = dp;

        for(int i=0; i<k[a]; ++i){
            for(int j=0; j<h[a][i]; ++j){
                vector<double> dp2(m+1, -DBL_MAX);
                for(int b=0; b<=m; ++b){
                    for(int c=1; c<s[a][i]; ++c){
                        if(c <= b)
                            nextDp[b-c] = max(nextDp[b-c], dp[b] + c / (double)s[a][i]);
                    }
                    if(s[a][i] <= b){
                        dp2[b-s[a][i]] = max(dp2[b-s[a][i]], dp[b] + 1);
                        nextDp[b-s[a][i]] = max(nextDp[b-s[a][i]], dp[b] + 1);
                    }
                }
                dp.swap(dp2);
            }
        }

        dp.swap(nextDp);
    }
    printf("%.10f\n", dp[0]);

    return 0;
}

Measured memory_bytes: 1260
#include <bits/stdc++.h> 
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;
typedef pair<ll,ll> pll;
#define MOD 1000000007
#define INF 1000000000
#define mp make_pair
#define pb push_back
#define ss second
#define ff first
#define endl '\n'
#define pl cout<<endl;
void fast() { ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL); }
const long long INFll=1ll*INF*INF;
const long double PI=3.141592653589793238462643383279502884197169399375105820974944;
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define debug(x) cout << x << endl;
#define sz(a) int((a).size())
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
 
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
long long genrand(long long L,long long R)
{
	return uniform_int_distribution<long long>(L, R)(rng);
}
//use brackets before operations if taking MOD
//use map only when necessary
//give long long to arrays and variables properly
int mul(int a, int b,int mod = MOD) {
	return int(a * 1ll * b % mod);
}
int norm(int a,int mod = MOD) {
	while(a >= mod) a -= mod;
	while(a < 0) a += mod;
	//a = (a%mod+mod)%mod;
	return a;
}
int powmod(int x,int y,int mod = MOD){
	int res = 1;
	while(y>0)
	{
		if(y&1)
			res = mul(res,x,mod);
		x = mul(x,x,mod);
		y=y>>1;
	}
	return res;
}
int inv(int a,int mod = MOD) {
	return powmod(a, mod - 2);
}
int main() {
	fast();
	int k; cin>>k;
	queue<long long> q;
	for(int i = 1; i<10; i++){
		q.push(i);
	}
	long long e;
	while(k>0){
		e = q.front(); q.pop();
		k--;
		if(e%10!=0){
			q.push(10*1ll*e + e%10 - 1);
		}
		q.push(10*e + e%10);
		if(e%10!=9){
			q.push(10*1ll*e + e%10 + 1);
		}
	}
	cout<<e<<endl;
	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
const lint mod=1e9+7;

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

  string res = "No";
  if(s[2] == s[3] && s[4] == s[5]) res = "Yes";

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int INT_INF = 1 << 30;
#define MOD 1000000007LL
#define endl "\n"

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll N, W;
  cin >> N >> W;
  vll w(N), v(N);
  vll w0(0), w1(0), w2(0), w3(0);
  for(int i = 0; i < N; i++){
    cin >> w.at(i) >> v.at(i);
    if(i == 0) w0.push_back(v.at(i));
    else if(w.at(i) == w.at(0)) w0.push_back(v.at(i));
    else if(w.at(i) == w.at(0) + 1) w1.push_back(v.at(i));
    else if(w.at(i) == w.at(0) + 2) w2.push_back(v.at(i));
    else if(w.at(i) == w.at(0) + 3) w3.push_back(v.at(i));
  }
  sort(ALL(w0), greater<ll>());
  sort(ALL(w1), greater<ll>());
  sort(ALL(w2), greater<ll>());
  sort(ALL(w3), greater<ll>());
  ll n0 = w0.size(), n1 = w1.size(), n2 = w2.size(), n3 = w3.size();
  vll sum0(n0+1, 0), sum1(n1+1, 0), sum2(n2+1, 0), sum3(n3+1, 0);
  for(int i = 0; i < n0; i++) sum0.at(i+1) = sum0.at(i) + w0.at(i);
  for(int i = 0; i < n1; i++) sum1.at(i+1) = sum1.at(i) + w1.at(i);
  for(int i = 0; i < n2; i++) sum2.at(i+1) = sum2.at(i) + w2.at(i);
  for(int i = 0; i < n3; i++) sum3.at(i+1) = sum3.at(i) + w3.at(i);

  ll ww = w.at(0);
  ll ans = 0LL;
  for(int i = 0; i <= n0; i++){
    if(ww * i > W) break;
    for(int j = 0; j <= n1; j++){
      if(ww * i + (ww+1) * j > W) break;
      for(int k = 0; k <= n2; k++){
        if(ww * i + (ww+1) * j + (ww+2) * k > W) break;
        ll d = W - (ww * i + (ww+1) * j + (ww+2) * k);
        ll l = min(n3, d/(ww+3));
        ll wt = sum0.at(i) + sum1.at(j) + sum2.at(k) + sum3.at(l);
        chmax(ans, wt);
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int

using namespace std;

const ll mod=1000000007;
const ll inf=1e18;

int main(){

  ll n,k;
  cin >> n >> k;
  ll s=0;
  for(int i=0;i<n;i++){
    ll h;
    cin >> h;
    if(h>=k)s++;
  }
  cout << s << endl;


}

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

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

using namespace std;

int main() {
  int n,w,h;
  cin>>n>>w>>h;
  vector<int> x(w+1);
  vector<int> y(h+1);
  REP(i,n){
    int a,b,c;
    cin>>a>>b>>c;
    ++x[max(0,a-c)];
    --x[min(w,a+c)];
    ++y[max(0,b-c)];
    --y[min(h,b+c)];
  }
  REP(i,w) x[i+1] += x[i];
  REP(i,h) y[i+1] += y[i];
  bool ok = true;
  REP(i,w) if(x[i] == 0) ok = false;
  bool ok2 = true;
  REP(i,h) if(y[i] == 0) ok2 = false;
  if (ok || ok2) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

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

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

const int maxn = 1e6 + 5;
int n,k;
vector<int> v;

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
cin>>n>>k;
  v.resize(n);
  for (int i=0; i<n; i++) cin>>v[i];
  sort(v.rbegin(), v.rend());
  v.resize(k);
  int ans=0;
  for (int x: v) ans+=x;
  cout<<ans<<endl;
  

  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cmath>
#include<algorithm>
#include<queue>
#include<string.h>

const int MAXN = 10000 + 5;
int n, q;
int uset[MAXN];

void init() {
	memset(uset, -1, sizeof(uset));
}

int find_root(int x) {
	if (uset[x] == -1) {
		return x;
	}
	else {
		int root = find_root(uset[x]);
		uset[x] = root;
		return root;
	}
}

void unite(int x, int y) {
	int rx = find_root(x);
	int ry = find_root(y);
	if (rx != ry) {
		uset[rx] = ry;
	}
}

bool same(int x, int y) {
	if (find_root(x) == find_root(y)) {
		printf("1\n");
		return true;
	}
	else {
		printf("0\n");
		return false;
	}
}

int main() {
	scanf("%d%d", &n, &q);
	init();
	for (int i = 0; i < q; i++) {
		int op, x, y;
		scanf("%d%d%d", &op, &x, &y);
		if (op == 0) {
			unite(x, y);
		}
		else {
			same(x, y);
		}
	}

	return 0;
}


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


long long int bruteforce(std::vector<std::pair<long long int, long long int>>& points) {
    int n = points.size();
    long long int max = 0;
    for (int i = 0; i < n - 1; i++) {
        long long int xi = points[i].first, yi = points[i].second;
        for (int j = 1; j < n; j++) {
            long long int dist = std::abs(xi - points[j].first) + std::abs(yi - points[j].second);
            max = std::max(max, dist);
        }
    }
    return max;
}


long long int answer(std::vector<std::pair<long long int, long long int>> & points) {
    int n = points.size();
    std::vector<long long int> xs(n);
    std::vector<long long int> ys(n);

    long long int maxx = -1e9, maxy = -1e9, minx = 1e9, miny = 1e9;
    for (int i = 0; i < n; i++) {
        auto pt = points[i];
        long long int x = pt.first + pt.second;
        long long int y = pt.first - pt.second;
        maxx = std::max(x, maxx);
        minx = std::min(x, minx);
        maxy = std::max(y, maxy);
        miny = std::min(y, miny);
    }
    return std::max(maxx - minx, maxy - miny);
}


int main() {
    int N;
    std::cin >> N;

    std::vector<std::pair<long long int, long long int>> points(N);
    for (int i = 0; i < N; i++) {
        std::cin >> points[i].first >> points[i].second;
    }

    std::cout << answer(points) << std::endl;
}


Measured memory_bytes: 9584
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1001001001
#define LINF 1001001001001001001
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

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

int main() {

    int A, B;
    cin >> A >> B;
    if (A == 1) A = 14;
    if (B == 1) B = 14;

    if (A > B) cout << "Alice" << endl;
    else if (A < B) cout << "Bob" << endl;
    else cout << "Draw" << endl;
    
    return 0;
}

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

int main (){
    int M, N;
    cin>>M>>N;
  	bool a=false;
    for(int i=0; i<2*M-1; i++){
        int num=N-M+1+i;
        if(num>-1000001&&num<1000001){
          if(a){
            cout<<' ';
        	}
          a=true;
            cout<<num;
        }
    }
}
    

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include <string.h>
using ll = long long;

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define reps(i,x) for(ll i=1;i<=(ll)(x);i++)
#define rrep(i,x) for(ll i=((ll)(x)-1);i>=0;i--)
#define rreps(i,x) for(ll i=(ll)(x);i>0;i--)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>
#define mod 1000000007 
using namespace std;
int a[1000];
int b[1000];
vector<bool> IsPrime;

void sieve(size_t max){
    if(max+1 > IsPrime.size()){     // resizeで要素数が減らないように
        IsPrime.resize(max+1,true); // IsPrimeに必要な要素数を確保
    } 
    IsPrime[0] = false; // 0は素数ではない
    IsPrime[1] = false; // 1は素数ではない

    for(size_t i=2; i*i<=max; ++i) // 0からsqrt(max)まで調べる
        if(IsPrime[i]) // iが素数ならば
            for(size_t j=2; i*j<=max; ++j) // (max以下の)iの倍数は
                IsPrime[i*j] = false;      // 素数ではない
}
int main() {
  long n,p;
  cin >> n >> p;
  int sq = floor(sqrt(p));
  sieve(sq);
  long q = p;
  vector<long> el;
  if(n == 1){
    cout << p << endl;
    return 0;
  }
  for(long i = 2; i <= sq; i++){ 
    if(IsPrime[i]){
      if(q % i == 0) {
        if(q > 1){
          while(q>1 && (q % i ==0)){
            q /= i;
            el.push_back(i);
          }
        }
      }
    }
    if(i == sq && q > 1)
      el.push_back(q);
  }
  int i = 0;
  long pre = -1;
  vector<int> ans;
  for(auto e: el){
    if(!i){
      pre = e;
      i++;
    }else if(pre == e){
      i++;
      if(i % n == 0)
        ans.push_back(e);
    }else{
      i = 1;
      pre = e;
    }
  }
  long as = 1;
  for(auto e: ans){
    as *= e;
  }
  cout << as << endl;
  
}


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

int main() {
	// your code goes here
	char s[4];
	cin>>s;
    if(s[0]==s[1] || s[1]==s[2] || s[2]==s[3])
    {
      cout<<"Bad";
    }
	else
    {
      cout<<"Good";
    }
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
typedef pair<string,string> Ps;
const ll INF=1000000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};
struct pos{
	// 1 変数を入れる;
	int x,y,sx,sy,cost;
};

int main() {

	ll n;
	cin>>n;
	ll m,ans=1;
	cin>>m;
	rep(i,n-1){
		ll a;
		cin>>a;
		if(m>=a)ans++;
		m=min(m,a);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

using namespace std;

#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i <= b; i++)
#define all(a)  begin((a)),end((a))
#define uniq(c) (c).erase(unique(all((c))), end((c)))

int main()
{
    string s; cin >> s;
    cout << s.substr(0, 4) << " " << s.substr(4, 8) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define Vp vector<pair<ll, ll>>
using ll = long long;
#define ALL(v) (v).begin(),(v).end()
#define endl "\n"
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define co(x) cout << x << endl
#define coel cout << endl
#define pb push_back
#define sz(v) ((ll)(v).size())
using namespace std;  
const double pi = acos(-1.0);
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define pp pair<ll, pair<ll, ll>> 
#define fi first
#define se second

////////////////////////////////////////////////////////


int main() {
    ll l, r, d;
    cin >> l >> r >> d;
    ll cnt = 0;
    Rep(i, l, r){
        if(i%d == 0) cnt++;
    }
    co(cnt);

    return 0;
}




Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <map>

using namespace std;

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

    long long nums[5] = {};
    for(int i=0;i<n;i++){
        string s;
        cin >> s;
        char c = s[0];
        if(c == 'M')
            nums[0]++;
        else if(c == 'A')
            nums[1]++;
        else if(c == 'R')
            nums[2]++;
        else if(c == 'C')
            nums[3]++;
        else if(c == 'H')
            nums[4]++;
    }
    long long res = 0;

    for(int i=0;i<5;i++)
        for(int j=i+1;j<5;j++)
            for(int k=j+1;k<5;k++){
                res += nums[i] * nums[j] * nums[k];
            }
    cout << res << endl;



    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		double x1 = sc.nextDouble();
		double y1 = sc.nextDouble();
		double x2 = sc.nextDouble();
		double y2 = sc.nextDouble();

		double distance = Math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));

		System.out.println(distance);

		sc.close();

	}

}



Measured memory_bytes: 27856
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
int main()
{
    int n;
    cin >> n;
    vector<ll> x(n), y(n), h(n);
    rep(i, n) cin >> x[i] >> y[i] >> h[i];

    ll maxH = *max_element(all(h));
    ll maxX, maxY;
    rep(i, n) if (h[i] == maxH) {
        maxX = x[i];
        maxY = y[i];
        break;
    }

    rep(Cx, 101) rep(Cy, 101) {
        ll H = maxH + abs(maxX - Cx) + abs(maxY - Cy);
        // if (Cx == 2 && Cy == 2) {
        //     cout << "//" << H << endl;
        // }

        bool ok = true;
        rep(i, n) {
            if (max(0LL, H - abs(x[i] - Cx) - abs(y[i] - Cy)) != h[i]){
                ok = false;
                break;
            }
        }   

        if (ok) {
            cout << Cx << " " << Cy << " "<< H << endl;
        }
    }

    

    return 0;
}

Measured memory_bytes: 3644
N = int(input())
A = list(map(int, input().split()))

negative_count = 0
for a in A:
    if a < 0:
        negative_count += 1

A_positive = [abs(a) for a in A]

if negative_count % 2 == 0:
    # すべてプラスにできる
    print(sum(A_positive))
else:
    # 1つマイナス
    print(sum(A_positive) - min(A_positive) * 2)


Measured memory_bytes: 14252
#123 a
z=[]
ans=0
for i in range(5):
    z.append(int(input()))
k=int(input())

for i in range(4):
    for j in range(i+1,5):
        if k<(z[j]-z[i]):
            ans+=1
if ans:
    print(":(")
else:
    print("Yay!")

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.nextLine();
		long answer = (long) s.length() * (long) (s.length() - 1) / 2;

		for (int i = 0; i < 26; i++) {
			long c = 0;
			for (int j = 0; j < s.length(); j++) {
				if ((int) (s.charAt(j) - 'a') == i) {
					c++;
				}
			}
			answer -= c * (c - 1) / 2;
		}

		System.out.println(answer + 1);
	}
}


Measured memory_bytes: 28924
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main()
{
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];

    sort(all(A));
    ll ans = 0;
    if (N % 2 == 0) {
        vector<int> check;
        rep(i, (N - 2) / 2) check.push_back(-2);
        check.push_back(-1);
        check.push_back(1);
        rep(i, (N - 2) / 2) check.push_back(2);
        rep(i, N) ans += check[i] * A[i]; 
    }
    else {
        vector<int> check1;
        rep(i, (N - 2) / 2) check1.push_back(-2);
        rep(i, 2) check1.push_back(-1);
        rep(i, ((N - 2) / 2) + 1) check1.push_back(2);
        vector<int> check2;
        rep(i, ((N - 2) / 2) + 1) check2.push_back(-2);
        rep(i, 2) check2.push_back(1);
        rep(i, (N - 2) / 2) check2.push_back(2);

        ll tmp1 = 0, tmp2 = 0;
        rep(i, N) tmp1 += check1[i] * A[i];
        rep(i, N) tmp2 += check2[i] * A[i];

        ans = max(tmp1, tmp2); 
    }

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

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

double r, pi = 3.1415926536;

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

    cin >> r;
    cout << fixed << setprecision(6) << pi * r * 2 << "\n";

    return 0;
}


Measured memory_bytes: 3764
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main(){
  ll N; cin >> N;
  ll res = 0;
  for(ll i = 5; i <= N; i *= 5){
    res += (N / i) / (i % 2 == 0 ? 1 : 2);
  }
  cout << (N % 2 == 0 ? res : 0) << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){

  int n,x,y,h,w,sum,i;
  while(1){
    scanf("%d",&n);
    if(n==0)break;
    sum=0;
    for(i=0;i<n;i++){
      scanf("%d%d%d%d",&x,&y,&h,&w);
      if(x+y+h<=60 && w<=2)sum += 600;
      else if(x+y+h<=80 && w<=5)sum += 800;
      else if(x+y+h<=100 && w<=10)sum += 1000;
      else if(x+y+h<=120 && w<=15)sum += 1200;
      else if(x+y+h<=140 && w<=20)sum += 1400;
      else if(x+y+h<=160 && w<=25)sum += 1600;
    }
    printf("%d\n",sum);
  }
  return 0;
}

Measured memory_bytes: 600
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		int N = S.length();
		String firstHalf = S.substring(0, N / 2);
		String reverseFirst = new StringBuffer(firstHalf).reverse().toString();

		String finalHalf = S.substring(N / 2 + 1);
		String reverseFinal = new StringBuffer(finalHalf).reverse().toString();

		//		System.out.println(firstHalf);
		//		System.out.println(finalHalf);
		//		System.out.println(reverseFirst);
		//		System.out.println(reverseFinal);

		if (firstHalf.equals(reverseFirst)
				&& finalHalf.equals(reverseFinal)
				&& firstHalf.equals(reverseFinal)
				&& finalHalf.equals(reverseFirst)) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}

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

using namespace std;

typedef long long ll;

int main(){
  ll H, N, a, b;
  cin >> H >> N;
  vector<vector<ll>> dp;
  vector<pair<ll, ll>> M;
  for (ll i=0; i<N; i++){
    dp.emplace_back(vector<ll>(H+1, 1e9));
    cin >> a >> b;
    M.emplace_back(pair<ll, ll>(a, b));
  }
  for (ll i=0; i<N; i++){
    for (ll j=H; j>=0; j--){
      if (j == H) dp[i][j] = 0;
      else if (j != 0){
        if (i > 0) {
          dp[i][j] = min(dp[i-1][j], dp[i][j]);
        }
        if (j <= H - M[i].first){
          dp[i][j] = min(dp[i][j], dp[i][j+M[i].first] + M[i].second);

        }
      }
      else{
        ll tmp = 1e9;
        for (ll k=M[i].first; k>0; k--){
          tmp = min(tmp, dp[i][k]);
        }
        dp[i][0] = (i > 0 ? min(dp[i-1][0], tmp + M[i].second) : tmp + M[i].second);
      }
    }
  }

  cout << dp[N-1][0] << "\n";
  return 0;
}


Measured memory_bytes: 78464
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <string>
#include <cmath>
#include <map>
#include <iomanip>
#include <utility>
#define INF 1000000009
#define LINF 1000000000000000009
#define double long double
#define all(a) a.begin(),a.end()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<P, ll> PP;
typedef pair<ll, double> PD;
//ll mod = 1000000007;
//ll mod = 998244353;

int main() {
	ll h, w;
	cin >> h >> w;
	vector<vector<ll>> c(10, vector<ll>(10));
	for (int i = 0; i < 10; i++) {
		for (int j = 0; j < 10; j++) {
			cin >> c[i][j];
		}
	}
	for (int k = 0; k < 10; k++) {
		for (int i = 0; i < 10; i++) {
			for (int j = 0; j < 10; j++) {
				c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
			}
		}
	}
	ll ans = 0;
	vector<vector<ll>> a(h, vector<ll>(w));
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cin >> a[i][j];
			if (a[i][j] != -1) {
				ans += c[a[i][j]][1];
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define foru(i, a, b) for(int i = (a); i <= (b); i++)
#define ford(i, a, b) for(int i = (a); i >= (b); i--)
using namespace std;
typedef long long llong;

const int N = 300005;

int n, a[N], b[N], v[N], pos[N];
///fenwick
llong treea[N], treedd[N];
///copmare function
bool cmpa(int x, int y) {
    return a[x] < a[y];
}
bool cmpb(int x, int y) {
    if (b[x] < b[y]) return 1;
    if (b[x] > b[y]) return 0;
    return a[x] > a[y];
}
///fenwick tree
void update(llong tree[], int i, llong value) {
    while (i < N) {
        tree[i] += value;
        i += (i & (-i));
    }
}
llong get(llong tree[], int i) {
    llong res = 0LL;
    while (i > 0) {
        res += tree[i];
        i -= (i & (-i));
    }
    return res;
}
///solve
bool check(int position, int B) {
    llong sum = get(treea, position);
    llong sl = get(treedd, position);
    return llong(B) * sl >= sum;
}
int main() {
    //freopen("a.txt", "r", stdin);
    scanf("%d", &n);
    foru(i, 1, n) scanf("%d%d", &a[i], &b[i]);

    foru(i, 1, n) v[i] = i;
    sort(v + 1, v + n + 1, cmpa);
    foru(i, 1, n) pos[v[i]] = i;

    foru(i, 1, n) v[i] = i;
    sort(v + 1, v + n + 1, cmpb);

    int ans = 0;
    ford(i, n, 1) {
        int id = v[i];
        update(treedd, pos[id], 1LL);
        update(treea, pos[id], llong(a[id]));
        int low = 1, high = n, mid;
        while (low < high) {
            mid = (low + high + 1) /2;
            if (check(mid, b[id])) low = mid;
            else high = mid - 1;
        }
        if (check(low, b[id]))
            ans = max(ans, (int)get(treedd, low));
    }
    printf("%d\n", ans);
    return 0;

}

Measured memory_bytes: 10580
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;

int main(){
    int n,flag=0;;
    cin>>n;
    for(int i=n;flag==0;i++){
    	for(int j=2;j<=i+1;j++){
    		if(i%j==0&&i!=j){
    			break;
    		}
    		else if(j==i){
    			flag=i;
    			break;
    		}
    	}
    }
    cout<<flag<<endl;
   return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		long H = sc.nextLong();
		long W = sc.nextLong();
		if (H == 1 || W == 1) {
			System.out.println(1);
			System.exit(0);
		}
		if (H * W % 2 == 1) {
			System.out.println(H * W / 2 + 1);
		} else {
			System.out.println(H * W / 2);
		}
	}
}

Measured memory_bytes: 35884
MOD=10**9+7
L=input()

def powmod(a,p):
  if p==0:
    return 1
  elif p==1:
    return a
  else:
    pow2=powmod(a,p//2)
    if p%2==0:
      return (pow2**2)%MOD
    else:
      return (a*pow2**2)%MOD

sum=0
cnt_2=1
for i in range(len(L)):  
  if L[i] == "1":
    sum += cnt_2*powmod(3,len(L)-i-1)
    sum %= MOD
    cnt_2 = (cnt_2*2)%MOD
    
sum += cnt_2
sum %= MOD
print(sum)

Measured memory_bytes: 3188
import bisect
import copy
import heapq
import math
import sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
sys.setrecursionlimit(500000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

k=int(input())

if k%2==0 or k%5==0:
    print(-1)
else:
    if k%7==0:
        k//=7
    tmp=1
    cnt=1
    k*=9
    while (tmp*10-1)%k:
        tmp*=10
        tmp%=k
        cnt+=1
    print(cnt)

Measured memory_bytes: 68324
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#include<map>

using namespace std;

const int maxx = 1e5 + 5;
typedef long long ll;

map<char, char> p;

string s;
int a[maxx];
int sum[maxx];

int main(){
	int n, m, i, j, t, k, ans;
	while(scanf("%d %d", &n, &m) == 2){
		memset(a, 0, sizeof(a));
		memset(sum, 0, sizeof(sum));
		cin >> s;
		for(i = 0; i < s.size() - 1; i++){
			if(s[i] == 'A' && s[i + 1] == 'C') a[i + 1] = 1;
		}
		k = 0;
		for(i = 0; i < s.size(); i++){
			k += a[i + 1];
			sum[i + 1] += k;
		}
//		for(i = 1; i <= s.size(); i++) cout << sum[i] << ' ';
//		cout << endl;
		int l, r;
		for(i = 0; i < m; i++){
			scanf("%d %d", &l, &r);
			if(sum[r] - sum[r - 1] == 1) printf("%d\n", sum[r] - sum[l - 1] - 1);
			else printf("%d\n", sum[r] - sum[l - 1]);
		}
	}
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define endl '\n'
#define ALL(V) V.begin(), V.end()
#define L_B lower_bound
#define U_B upper_bound
#define pb push_back
#define ll long long
#define rep(i,n) for (i = 0; i < n; ++i) 
#define REP(i,k,n) for (i = k; i <= n; ++i) 
#define REPR(i,k,n) for (i = k; i >= n; --i)
using namespace std;
template<class T, class T1> int chkmin(T &x, const T1 &y) { return x > y ? x = y, 1 : 0; }
template<class T, class T1> int chkmax(T &x, const T1 &y) { return x < y ? x = y, 1 : 0; }
const int MAXN = (1 << 20);


int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  #ifndef ONLINE_JUDGE
 freopen("input.txt", "r", stdin);
 freopen("output.txt", "w", stdout);
#endif  
 // taskkill -im new.exe -f
  ll n,k ,ans=0;
  cin>>n>>k;
  while(n)
  {
    n = n/k;
    ans++;
  }
  cout<<ans<<endl;
  return 0;
}

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

int main()
{
  int n;
  cin>> n;
  vector<int> v(n);
  for (int i=0;i<n;i++){
    int a;
    cin>> a;
    v.at(i)=a;
  }
  
  sort(v.begin(), v.end(), greater<int>());
  int b=0,c=0;
  for (int i=0;i<v.size();i++){
    if(i%2==0){
      b+=v.at(i);
    }else{
      c+=v.at(i);
    }
  }
  cout<< b-c <<endl;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  for (int i = 0; i < N; i++) cin >> vec.at(i);
  sort(vec.begin(), vec.end());
  
  int ans = 1;
  int pre_r = vec.at(0);
  for (int i = 1; i < N; i++) {
    if(vec.at(i) == pre_r) {
      continue;
    }
    pre_r = vec.at(i);
    ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import math

steps=[1, 1, 2, 4]+ [0]*27
for i in range(4, 31):
  steps[i]=steps[i-1]+steps[i-2]+steps[i-3]

while True:
  n=input()
  if n==0:break
  print int(math.ceil(steps[n]/3650.0))

Measured memory_bytes: 4364