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

	vector<int> a(n);

	for (i = 0; i < n; i++)
	{
		cin >> a.at(i);
	}

	for (i = 0; i < n - 1; i++)
	{
		for (j = i + 1; j < n; j++)
		{
			if (a.at(i) < a.at(j))
			{
				int tmp;
				tmp = a.at(i);
				a.at(i) = a.at(j);
				a.at(j) = tmp;
			}
		}
	}
	for (i = 0; i < n; i++)
	{
		if (i % 2 == 0)
		{
			al += a.at(i);
		}
		else
		{
			bo += a.at(i);
		}
	}
	cout << al - bo << endl;
}



/**/
/*#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>

#define PI 3.141592653589793

int main(void) {
	return 0;
}
*/

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

#define pb push_back
#define lli long long int

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

    int n , k ;
    cin >> n >> k ;
    int ans = 0 ;

    for (int i = 1 ; i <= n ; i++)
    {
        int at = pow(k , i) ;
        
        if (at <= n)
        {
            ans = i ;
        }
        else 
        {
            ans = i ;
            break ;
        }
    }

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

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
 
public class Coder
{

    public static int[] ReadArray()
    {
        return Array.ConvertAll(Console.ReadLine().Split(' '), m => Convert.ToInt32(m));
    }

    public static int ReadInt()
    {
        return Convert.ToInt32(Console.ReadLine());
    }

    public static string ReadStr()
    {
        return Console.ReadLine();
    }

    public static long ReadLong()
    {
        return Convert.ToInt64(Console.ReadLine());
    }

    public static long[] ReadLongArray()
    {
        return Array.ConvertAll(Console.ReadLine().Split(' '), m => Convert.ToInt64(m));

    }

    public static void Main()
    {

        var a = ReadInt();
        var s = ReadStr();

        if (a < 3200)
            Console.WriteLine("red");
        else
            Console.WriteLine(s);

    }

}


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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;++A)
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

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

ll H, W;
char S[22][22];

ll i, j;

const ll gx[] = {1, 0, -1, 0}, gy[] = {0, 1, 0, -1};

ll ck(ll ha,ll wa,ll hb,ll wb){
    if(ha==wa&&hb==wb)
        return 0;
    queue<pll> q;
    vector<vector<ll>> mk(H, vector<ll>(W, 1e9));
    q.push({ha, wa});
    mk[ha][wa] = 0;
    while(!q.empty()){
        auto qa = q.front();
        q.pop();
        if(hb==qa.first&&wb==qa.second){
            return mk[hb][wb];
        }
        ll i;
        fornum(i,0,4){
            ll y = qa.first + gy[i];
            ll x = qa.second + gx[i];
            if(0<=y&&y<H&&0<=x&&x<W){
                if(S[y][x]=='.'&&mk[y][x]>10000){
                    mk[y][x] = mk[qa.first][qa.second]+1;
                    q.push({y, x});
                }
            }
        }
    }
    return 0;
}
int main(){
    scanf("%lld%lld", &H, &W);
    fornum(i,0,H){
        scanf("%s", S[i]);
    }
    ll ha, wa, hb, wb,ans=0;
    fornum(ha,0,H){
        fornum(hb,0,H){
            fornum(wa,0,W){
                if(S[ha][wa]=='#')
                    continue;
                fornum(wb,0,W){
                    if(S[hb][wb]=='#')
                        continue;
                    ans = max(ans, ck(ha, wa, hb, wb));
                }
            }
        }
    }
    printf("%lld", ans);

    return 0;
}

Measured memory_bytes: 256
x,y=map(int,input().split())
#print(y-x,x-y+2,1+y+x,(-y-x)+1,y+x+1)

l=[]
if y-x>=0:
    l.append(y-x)
if x-y+2>=0:
    l.append(x-y+2)
if 1+y+x>=0:
    l.append(1+y+x)
if (-y-x)+1>=0:
    l.append((-y-x)+1)
if y+x+1>=0:
    l.append(y+x+1)
print(min(l))

'''
add=max(abs(x),abs(y))-min(abs(x),abs(y))
cnt=add
if x*y<0:
    cnt=cnt+1
elif ((abs(x)>abs(y))and(x>0)and(y>0))or((abs(x)<abs(y))and(x<0)and(y<0)):
    cnt=cnt+2
else:
    cnt=cnt
if y==0:
    cnt=cnt-1
print(cnt)
'''


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

#define REP(i,num) for(int i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

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

	int A=in(),B=in();
	if(A>9 || B>9) out(-1);
	else out(A*B);
	return 0;
}

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

using namespace std;
int main()
{
    int n, m;
    cin >> n >> m;
    long long ans1, ans2, ans;

    ans1 = (n*(n-1)) / 2;
    ans2 = (m * (m-1))/ 2;

    ans = ans1 + ans2;

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


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

int main() {
    string a,b,c;
    cin >> a >> b >> c;

    if(a.back() == b.front() && b.back() == c.front())
    cout << "YES";
    else
    cout << "NO";

    return 0; 
} 

Measured memory_bytes: 3556
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007, INF=(1LL<<60);
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    int n , k;
    cin >> n >> k;
    int a[n];
    for(int i =0;i<n;i++){
    	cin >> a[i];
    }
    sort(a,a+n);
    int ans =0;
    for(int i=0;i<k;i++){
    	ans += a[i];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3648
/*The woods are lovely, dark and deep,
But I have promises to keep,
And miles to go before I sleep,
And miles to go before I sleep.*/

//PRABHJOT SINGH A.K.A. PRABHI
//~~~~~conquizztador~~~~~


#include<bits/stdc++.h>
using namespace std;
using lli = long long int;
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
const int MOD = 1000000007;
const int MOD1 = 998244353;
const int maxn = 100010;
const int lim = (int)1e9;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	vector<int> f(10 * maxn);
	f[0] = 0; f[1] = 1;
	for (int i = 2; i < 10 * maxn; ++i)
		f[i] = i;
	for (int i = 4; i < 10 * maxn; i += 2)
		f[i] = 2;
	for (int i = 3; i * i < 10 * maxn; ++i)
		if (f[i] == i)
		{
			for (int j = i * i; j < 10 * maxn; j += i)
				if (f[j] == j)
					f[j] = i;
		}
	auto calc = [&](int x)
	{
		if (x == 1)
			return 1;
		int res = 1;
		int p = f[x], ct = 1, d = x / f[x];
		while (d != 1)
		{
			if (f[d] == p)
				++ct;
			else
			{
				p = f[d]; res = res * (ct + 1); ct = 1;
			}
			d /= f[d];
		}
		res = res * (ct + 1); return res;
	};
	int n = 0;
	cin >> n;
	int ans = 0;
	for (int i = 1; i < n; ++i)
		ans += calc(i);
	cout << ans << endl;
}

Measured memory_bytes: 7092
#include <iostream>
using std::cout;
using std::cin;
using std::endl;

int house[4][3][10] = {};

void populateHouse(int num)
{
	int i, b, f, r, v;
	for (i = 0; i < num; i++)
	{
		cin >> b >> f >> r >> v;
		house[b-1][f-1][r-1] += v;
	}
}

void drawHouse()
{
	int i, j, k, l;
	for (i = 0; i < 4; i++)
	{
		for (j = 0; j < 3; j++)
		{
			for (k = 0; k < 10; k++)
				cout << " " << house[i][j][k];
			cout << endl;
		}
		if (i < 3)
		{
			for (l = 0; l < 20; l++) cout << "#";
			cout << endl;
		}
	}
}

int main()
{
	int num;
	cin >> num;
	populateHouse(num);
	drawHouse();
	return 0;
}

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

#define ll              long long
#define pb              push_back
#define ppb             pop_back
#define endl            '\n'
#define mii             map<ll,ll>
#define pii             pair<ll,ll>
#define vi              vector<ll>
#define vs              vector<string>
#define all(a)          (a).begin(),(a).end()
#define F               first
#define S               second
#define sz(x)           (ll)x.size()
#define hell            1000000007
#define inf             (ll)1e18 + 5
#define PI              (double)3.14159265358979323844
#define DECIMAL(n)      cout << fixed << setprecision(n);
#define rep(i,a,b)      for (ll i=a;i<b;i++)
#define repr(i,a,b)     for (ll i=a-1;i>=b;i--)
#define bitcount(a)     (ll)__builtin_popcount(a)
#define lbnd            lower_bound
#define ubnd            upper_bound
#define mp              make_pair
#define ios             ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ordered_set     tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define trace(...)      __f(#__VA_ARGS__, __VA_ARGS__)

template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}

using namespace std;
using namespace __gnu_pbds;

/*----------------------Graph Moves----------------*/
//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*------------------------------------------------*/

//primes for hashing 937,991,1013,1409,1741

void solve() {
    ll n;
    cin>>n;
    string s;
    ll f1=0,f2=0,f3=0;
    cin>>s;
    rep(i,0,n){
    	if (s[i]=='R')f1++;
    	else if (s[i]=='G')f2++;
    	else f3++;

    }

    
    ll temp=0;
    rep(i,0,n-2){
    	for (ll j=i+2;j<n;j+=2){
    		ll meow=(i+j)/2;
    		if (s[i]!=s[j] && s[i]!=s[meow] && s[meow]!=s[j]){
    			temp++;
    		}
    	}
    }
    //trace(temp);
    cout<<(f1*f2*f3)-temp;
}

signed main() {
    ios
    ll test=1;
    //cin>>test;
    while (test--) solve();
    return 0;
}

Measured memory_bytes: 3652
import java.util.Scanner;

class Main
{
	public static void main(String[] args)
	{
		Scanner scanner = new Scanner(System.in);
		int S = scanner.nextInt();
                int h = S / 3600;
                int m = (S - (h * 3600)) / 60;
                int s = S - (h * 3600) - (m * 60);
		System.out.println(h + ":" + m + ":" + s);
	}
} 


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

int main(){
int N, sum, mi;
  cin>> N;
  sum = 0;
  mi = 100;
    
int a[N];
  for(int i = 0;i < N;i++){
    cin >> a[i];
    sum += a[i];
    if(a[i] % 10 != 0){
    mi = min(mi, a[i]);
    }
  } 
    
   if(mi == 100){
     cout << 0 << endl;
    }  
  
   else if((sum % 10 != 0) && (sum > 0)){
      cout << sum << endl;
    }
    
   else if((sum % 10 == 0) && (mi > 0) && (mi != 100)){
     sum -= mi;
     cout << sum << endl;
    }  
  
  return 0;
  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define lnode node*2,start,mid
#define rnode node*2+1,mid+1,end
#define rep(i,a,b) for(ll i=a;i<=(b);i+=1)
#define input freopen("in25.txt", "r", stdin)
#define out freopen("out25.txt", "w", stdout)
#define To_string(num,str) {stringstream ss;ss<<num;ss>>str;}
#define To_num(str,num) {stringstream ss;ss<<str;ss>>num;}
const double pi=acos(-1.0);
const int maxn=(1000+10);
const int inf=0x3f3f3f3f;
const ll mod=10000003;
using namespace std;
ll in()
{  ll x=0,f=0;char ch=getchar();
   while(ch<'0'||ch>'9') f|=ch=='-',ch=getchar();
   while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
   return f? -x:x;
}
int a[500005];
int sum[500005];
int main()
{   ios::sync_with_stdio(false);
    int n,maxx=-1;
    //input;
	//out; 
	cin>>n;
	memset(sum,0,sizeof(sum));
    for(int i=1;i<=n;i++)
	  cin>>a[i];
	for(int i=n-1;i>=1;i--)
	  if(a[i+1]<=a[i])
	    sum[i]=sum[i+1]+1;
	for(int i=1;i<=n;i++)
	  maxx=max(maxx,sum[i]);
	cout<<maxx;
	return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#pragma warning (disable: 4996)

vector<pair<int, int>> vec; vector<int> L;
long long N, A[300009], C[300009], s, mod = 998244353, V[300009]; bool used[300009];

void init() {
	vec.clear(); L.clear(); s = 0;
	for (int i = 0; i < 309; i++) { A[i] = 0; C[i] = 0; V[i] = 0; used[i] = false; }
}

long long solve_ans() {
	for (int i = 0; i < N; i++) { if (A[i] == 1) L.push_back(i); }
	if (L.size() == 0) {
		return 0;
	}
	else if (L.size() == N) {
		long long ans = 1;
		for (int i = 1; i <= N; i++) { ans *= i; ans %= mod; }
		return ans;
	}
	sort(L.begin(), L.end()); int I = -1;
	for (int i = 0; i < L.size(); i++) {
		int t1 = L[i], t2 = L[(i + 1) % L.size()]; if (i == L.size() - 1) t2 += N;
		if (t2 - t1 != 1) {
			if (I != -1) { return 0; }
			I = t2;
		}
	}
	for (int i = 0; i < N; i++) C[i] = A[(i + I) % N];

	vector<pair<int, int>>vec; int s = 0;
	for (int i = 0; i < N; i++) {
		if (C[i] != C[i + 1]) {
			if (used[C[s]] == true) {  return 0; }
			vec.push_back(make_pair(C[s], s)); used[C[s]] = true; s = i + 1;
		}
	}
	int Z = N; if (vec.size() >= 2) Z = vec[1].second;
	for (int i = 0; i < vec.size(); i++) {
		int p1 = vec[i].second, p2 = vec[(i + 1) % vec.size()].second; if (i == vec.size() - 1) p2 += N;
		if (p2 - p1 > Z) { return 0; }
	}

	long long FinalAns = 1;

	vector<pair<int, int>>vec2; vec2.push_back(make_pair(1, 0)); // (数, pos)
	for (int i = 1; i < vec.size(); i++) {
		int t1 = vec[i - 1].first, t2 = vec[i].first, t3 = vec[(i + 1) % vec.size()].first;

		if (t1 < t2 && t2 < t3) {
			int u = vec[i + 1].second; u -= Z;
			vec2.push_back(make_pair(t2, u));
		}
		if (t1 < t2 && t2 > t3) {
			int u = vec[i].second;
			int lens = vec[(i + 1) % vec.size()].second - vec[i].second; if (i == vec.size() - 1) lens += N;
			vec2.push_back(make_pair(t2, u));
			FinalAns *= (Z + 1LL - lens);
			FinalAns %= mod;
		}
		if (t1 > t2 && t2 < t3) {
			int lens = vec[i + 1].second - vec[i].second;
			if (lens != Z) {
				return 0;
			}
			vec2.push_back(make_pair(t2, vec[i].second));
		}
		if (t1 > t2 && t2 > t3) {
			int u = vec[i].second;
			vec2.push_back(make_pair(t2, u));
		}
	}
	vector<int>J;
	for (int i = 0; i < vec2.size(); i++) {
		int v1 = vec2[i].second + 1, v2 = vec2[(i + 1) % vec2.size()].second - 1; if (i == vec2.size() - 1) v2 += N;
		for (int j = v1; j <= v2; j++) J.push_back(max(vec2[i].first, vec2[(i + 1) % vec2.size()].first));
	}
	sort(J.begin(), J.end()); reverse(J.begin(), J.end());

	// 最後の数え上げ
	for (int i = 1; i <= N; i++) V[i] = 1;
	for (int i = 0; i < vec2.size(); i++) V[vec2[i].first] = 0;
	for (int i = N - 1; i >= 1; i--) V[i] += V[i + 1];

	for (int i = 0; i < J.size(); i++) {
		FinalAns *= (V[J[i]] - i);
		FinalAns %= mod;
	}
	return FinalAns;
}

int main() {
	//FILE *in = freopen("in1.txt", "r", stdin);
	cin >> N;
	for (int i = 0; i < N; i++) cin >> A[i];
	cout << solve_ans() << endl;
	return 0;
}

Measured memory_bytes: 17388
#include <iostream>
#include <climits>
#include <set>
#include <string>
#include <algorithm>
#include <vector>
#define MAX 1000000007


using namespace std;
#define ll long long
#define dbg if(0)
#define ISRANGE(val,lo,hi) ((lo<=val)&&(val<hi))

ll list[3][2];
void init(){
    for(int i=0;i<3;i++){
        list[i][0]=-1;
        list[i][1]=0;
    }
}
bool find(ll a){
    for(int i=0;i<3;i++){
        if(a==list[i][0]){
            list[i][1]++;
            return true;
        }else if(list[i][0]==-1){
            list[i][1]++;
            list[i][0]=a;
            return true;
        }

    }
    //４種類目が出た
    return  false;
}
bool check(){
    return (list[0][0]^list[1][0]^list[2][0]==0)&&list[0][1]==list[1][1]&&list[0][1]==list[2][1];
}


int main(){
    init();
    ll ans=0,n;
    cin >>n;
    ll a[n+1];
    a[0]=0;

    bool f=true;
    for(int i=1;i<=n;i++){
        ll t;
        cin>>t;
/*         if(!find(t)){
            f=false;
            break;
    }else*/
        {
            f=f&&find(t);
        }
        ans^=t;
    }
    f=f&&check();

    if(ans==0)cout <<"Yes"<<endl;
    else cout <<"No"<<endl;

    return 0;

}

Measured memory_bytes: 256
n = int(input())
monster = list(map(int, input().split()))
savers = list(map(int, input().split()))
first = sum(monster)
rest = []
for i in reversed(range(n)):
    monster_i = monster.pop()
    save_i = savers[i]
    # 倒したモンスター
    monster_ii = max(monster_i - save_i, 0)
    # 残り倒せるかず
    save_ii = save_i - (monster_i - monster_ii)
    rest.append(monster_ii)
    monster[-1] = max(monster[-1] - save_ii, 0)
ans = first - sum(rest) - monster[0]
print(ans)

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

using namespace std;

#ifdef DEBUG_MODE
	#define DBG(n) n;
#else
	#define DBG(n) ;
#endif
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007

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

ll n;
vector<vector<ll>> v(111111);
ll mp[111111];

ll dfs(ll s,ll pre){
	ll ret = 0;
	vector<ll> tmp;
	REP(i,v[s].size()){
		if(v[s][i] != pre){
			tmp.PB(dfs(v[s][i],s));
			ret |= tmp[tmp.size()-1];
		}
	}
	
	if(tmp.size() == 0){
		return mp[s] = 1;
	}
	ll cou = 60;
	for(;cou > 0;cou--){
		int flag = 0;
		REP(i,tmp.size()){
			if(tmp[i] & (1LL << cou))flag++;
		}
		if(flag > 1)break;
	}
	
	for(;;cou++){
		if(!(ret & (1LL <<cou))){
			ret |= (1LL << cou);
			ret &= ((1LL << 60)-1) - ((1LL << cou) - 1);
			break;
		}
	}
	return mp[s] = ret;
}

int main(){
	
	cin >> n;
	REP(i,n-1){
		int a,b;cin >> a >> b;
		a--;b--;
		v[a].PB(b);
		v[b].PB(a);
	}
		
	ll ans = dfs(0,-1);
	for(ll i = 60;i >= 0;i--){
		if(ans & (1LL << i)){
			cout << i << endl;
			//return 0;
			break;
		}
	}	
	
	/*
	REP(i,n){
		REP(j,10){
			cout << ((mp[i] & (1LL << j)) > 0) << ' ';
		}
		cout << endl;
	}
	*/
	return 0;
}


Measured memory_bytes: 13568
import java.util.Scanner;

public class Main
{
    public static void main(String args[])
    {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();

        for(int i = n; i > 0; i--) {
            int sq = (int)Math.sqrt(i);
            if(i == sq * sq) {
                n = i;
                break;
            }
        }

        System.out.println(n);
    }
}


Measured memory_bytes: 21844
def distance(p1, p2)
  distance = 0
  0.upto(p1.size - 1) do |i|
    distance += (p1[i] - p2[i]) ** 2
  end
  Math.sqrt(distance)
end

def good_distance(d)
  ans = 0
  0.upto(d.size - 2) do |i|
    (i + 1).upto(d.size - 1) do |j|
      dist = distance(d[i], d[j])
      ans += 1 if (dist - dist.to_i).zero?
    end
  end
  ans
end

n, d = gets.split.map(&:to_i)
d = []
n.times{ d << gets.split.map(&:to_i) }

puts good_distance(d)


Measured memory_bytes: 1788
#include <iostream>

int main()
{
    int x = 1;
    int i = 1;
    while (true) //trueだとbreakするまで、無限ループ
    {
        std::cin >> x;
        if (x == 0)
        {
            break;
        }
        std::cout << "Case " << i << ": " << x << std::endl;
        i++;
    }

    return 0;
}


Measured memory_bytes: 3088
#include <iostream>
 
int main(){
  int W, H, x, y, r;
  std::cin >> W >> H >> x >> y >> r;
  if(x + r <= W && y + r <= H && x >= 0 && y >= 0 )
    std::cout << "Yes" << std::endl;
  else
    std::cout << "No" << std::endl;
  return 0;
}

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

using namespace std;

#define pb push_back
#define mk make_pair
#define mod 1000000007
#define ff first
#define ss second

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

ll modpow(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(){

	int a,b,c,d;
    cin>>a>>b>>c>>d;

    int ans = min(b,d)-max(a,c);
    ans=max(0,ans);

    cout<<ans<<endl;

}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(){
  int a,b,c,l,i;
  char s[21];
  scanf("%s",s);
  l=strlen(s);
  for(i=a=b=c=0;i<s[i];i++){
    if('0'<=s[i]&&s[i]<='9')c=1;
    if('a'<=s[i]&&s[i]<='z')a=1;
    if('A'<=s[i]&&s[i]<='Z')b=1;
  }
  if(a&&b&&c&&l>5)printf("VALID\n");
  else            printf("INVALID\n");
  return 0;
}

Measured memory_bytes: 524
#include<bits/stdc++.h>
using namespace std;
 
#define int long long int
 
int32_t main()
{
   int n;
  cin>>n;
  multiset<char> set[n];
  for(int i=0;i<n;i++)
  {
    for(int j=0;j<10;j++)
    {
       char ch;
      cin>>ch;
       set[i].insert(ch);    
    }
  } 
  sort(set,set+n);
  int ans=0;int c=1;
  for(int i=0;i<n-1;i++)
  {
    if(set[i]==set[i+1])
    {  c++;
     }
    else
    {
       ans+=(c*(c-1))/2;c=1;  
    }
  }
  ans+=(c*(c-1))/2;  
  cout<<ans<<endl;
}

Measured memory_bytes: 53888
"use strict";
var input = require("fs").readFileSync("/dev/stdin", "utf8");
var cin = input.split(/ |\n/),
    cid = 0;

function next() {
    return +cin[cid++];
} // number一個取得
function nextstr() {
    return cin[cid++];
} // 文字列一個取得
function nextbig() {
    return BigInt(cin[cid++]);
} // BigInteger一個取得
// 長さnの配列として取得。aは文字列フラグ
function nexts(n, a) {
    return a ? cin.slice(cid, cid += n) : cin.slice(cid, cid += n).map(a => +a);
}
// 長さnのBigInt配列として取得。
function nextsbig(n) {
    return cin.slice(cid, cid += n).map(a => BigInt(a));
}
// w個ずつを組にして長さhの配列。aは文字列フラグ。
function nextm(h, w, a) {
    var r = [],
        i = 0;
    if (a)
        for (; i < h; i++) r.push(cin.slice(cid, cid += w));
    else
        for (; i < h; i++) r.push(cin.slice(cid, cid += w).map(a => +a));
    return r;
}
// 多次元配列。v,a1,a2,a3 なら、3次元。[[値vで長さa3の配列]をa2個並べた配列]をa1個並べた配列。
function xArray(v) {
    var a = arguments,
        l = a.length,
        r = "Array(a[" + --l + "]).fill().map(x=>{return " + v + ";})";
    while (--l) r = "Array(a[" + l + "]).fill().map(x=>" + r + ")";
    return eval(r);
}


console.log(main().toString());

function main() {
    let S = nextstr();
    return     '2018'+S.substr(4)

}

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

using namespace std;
#define all(x) (x).begin(), (x).end()
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<vector<bool>> vvb;
typedef vector<vector<int>> vvi;
typedef vector<vector<long long>> vvl;
typedef pair<int,int> pii;
typedef long long ll;
#define debug(x) cout << #x << "=" << x << endl;
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); cout << (i>0 ? " ":"") << v[i++]); cout << "\n"; return os;}


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll x, a, b;
    cin >> x;
    for(a = 1;;a++){
        ll pa = a*a*a*a*a;
        if(2*pa < x) continue;
        for(b=a-1;b>=-a;b--){
            ll pb = b*b*b*b*b;
            if(pa - pb > x) break;
            if(pa - pb == x){
                cout << a << " " << b << "\n";
                return 0;
            }
        }
        if(b == a-1) break;
    }
    
    return 0;
}

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

using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;
#define DEBUG freopen("in.txt", "r", stdin);

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;

string o, e, ans;
int main() {
    cin >> o >> e;
    int n = o.length();
    int m = e.length();
    for (int i = 0; i < m; ++i) {
        ans += o[i];
        ans += e[i];
    }
    if (n > m)
        ans += o[n - 1];
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3656
#include<cstdio>
#include<utility>
#include<queue>
#include<algorithm>
using namespace std;
long long n,k,ans,t,d,sum,cnt;
vector<pair<long long,long long> > p;
priority_queue<long long, vector<long long>, greater<long long> > pq;
long long flag[100001];
queue<long long> q;
int main(){
    scanf("%ld %ld",&n,&k);
    for(int i=0;i<n;i++){
        scanf("%ld %ld",&t,&d);
        p.push_back(make_pair(d,t));
    }
    sort(p.begin(),p.end());
    for(int i=0;i<n;i++){
        if(i<k){
            sum+=p[n-1-i].first;
            if(flag[p[n-1-i].second]==1){
                pq.push(p[n-1-i].first);
            }
            flag[p[n-1-i].second]=1;
        }
        else{
            if(flag[p[n-1-i].second]==0){
                q.push(p[n-1-i].first);
                flag[p[n-1-i].second]=2;
            }
        }
    }
    for(long i=1;i<=n;i++){
        if(flag[i]==1){
            cnt++;
        }
    }
    ans=sum+cnt*cnt;
    while(!q.empty()&&!pq.empty()){
        sum+=q.front();
        sum-=pq.top();
        cnt++;
        q.pop();
        pq.pop();
        ans=max(ans,sum+cnt*cnt);
    }
    printf("%ld\n",ans);
}

Measured memory_bytes: 3444
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/trie_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef trie<string, null_type, trie_string_access_traits<>, pat_trie_tag, trie_prefix_search_node_update> pref_trie;
typedef unsigned long long BITMASK; typedef long long ll; typedef long double ld;
#define smallest_on_bit(bit_mask) (__builtin_ctzint((bit_mask) & (-(bit_mask))))
#define CLOCK_START clock_t chrono_clk_beg = clock()
#define CLOCK_END clock_t chrono_clk_end = clock(); cerr << (double(chrono_clk_end - chrono_clk_beg) / CLOCKS_PER_SEC) << " sec"
#define bug(args ...) cerr << __LINE__ << ">> ", err(new istringstream(string(#args)), args), cerr << '\n'
#define toBinary(name, num) string name = bitset<8>(num).to_string();
#define toDecimal(name, binary) unsigned long name = bitset<8>(binary).to_ulong();
#define all(x) x.begin(), x.end()
#define mapfind(mp, x) (mp.find(x) != mp.end())
#define arrfind(arr, x) (find(all(arr), x) != arr.end())
#define removeDuplicates(vec) sort(vec.begin(), vec.end()); vec.erase(unique(vec.begin(), vec.end()), vec.end())
#define int ll
#define double ld
#define INF LONG_MAX
void err(istringstream *iss) {} template<typename T, typename ... Args> void err(istringstream *iss, const T &_val, const Args & ... args) { string _name; *iss >> _name; if (_name.back()==',') _name.pop_back(); cerr << _name << " = " << _val << "; ", err(iss, args ...); }
#define MOD 1000000007

int solve(int n)
{
    if (n == 1) return 3;
    return 2*solve(n-1) + 1;
}

signed main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int h;
    cin >> h;
    if (h == 1) cout << 1 << '\n';
    else cout << solve(log2(h)) << '\n';
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
//template<class T = ll> T in(){T x; cin >> x; return (x);}

ll num[26];

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

  ll H, W;
  cin >> H >> W;

  ll two=0, four=0, el=0;
  
  rep(i,H){
    string s ;cin >> s;
    rep(j,s.size()) num[s[j]-'a']++;
  }


  rep(i,26){
    if(num[i]==0) continue;
    four += (num[i]/4);num[i]%=4;
    two +=(num[i]/2); num[i] %= 2;
    el += num[i];
  }

  if(H==1 || W==1){
    if(el <= 1) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
  }

  ll f=0,t=0,e=0;
  t = (H%2)*(W/2) + (W%2)*(H/2);
  f = (H*W-2*t)/4;
  e = H*W-f*4-t*2;

  
  if(four < f) {
    cout << "No" << endl;
    return 0;
  }
  two += ((four-f)*2);
  
  
  if(two==t && el == e) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

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

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    string s;
    cin >> s;
    int n = s.size();
    int ans = 0;
    int g = 0, p = 0;
    rep(i,n){
        if(s[i]=='p'){
            if(p<g)p++;
            else g++,ans--;
        }else{
            if(p<g)p++,ans++;
            else g++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 512
import java.util.Scanner

import scala.collection.mutable.ArrayBuffer
import scala.util.control.Breaks

// [(a,b,c) | abc<=k]をソート
object Main {
  def read(): (Int, Int, Int, Int, IndexedSeq[Long], IndexedSeq[Long], IndexedSeq[Long]) = {
    val sc = new Scanner(System.in)
    val n1, n2, n3, k = sc.nextInt()
    val l1 = for (_ <- 0 until n1) yield sc.nextLong()
    val l2 = for (_ <- 0 until n2) yield sc.nextLong()
    val l3 = for (_ <- 0 until n3) yield sc.nextLong()
    (n1, n2, n3, k, l1, l2, l3)
  }


  def solve(n1: Int, n2: Int, n3: Int, k: Int, l1: IndexedSeq[Long], l2: IndexedSeq[Long], l3: IndexedSeq[Long]): IndexedSeq[Long] = {
    val indexBuf = new ArrayBuffer[(Int, Int, Int)]()
    for (i1 <- l1.indices) {
      for (i2 <- l2.indices) {
        val b = new Breaks
        b.breakable {
          for (i3 <- l3.indices) {
            // 1-origin化
            if ((i1 + 1) * (i2 + 1) * (i3 + 1) > k) b.break()
            else indexBuf.append((i1, i2, i3))
          }
        }
      }
    }
    val indexListRequirementOfTopk = indexBuf.toIndexedSeq
    val sortedL1 = l1.sorted.reverse
    val sortedL2 = l2.sorted.reverse
    val sortedL3 = l3.sorted.reverse
    indexListRequirementOfTopk.map { case (i1, i2, i3) => sortedL1(i1) + sortedL2(i2) + sortedL3(i3) }.sorted.reverse.take(k)
  }

  def printResult(result: IndexedSeq[Long]) = {
    result.foreach(println)
  }


  def main(args: Array[String]): Unit = {
    val (n1, n2, n3, k, l1, l2, l3) = read()
    printResult(solve(n1, n2, n3, k, l1, l2, l3))
  }
}

Measured memory_bytes: 84308
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0 ; i < n ; i++)
        cin >> a[i];

    for (int i = 0; i < n; i++)
    {
        if(i < n - 1)
            cout << a[n - i - 1] << " ";
        else
            cout << a[0] << endl;
    }
    
  
    return 0;
}


Measured memory_bytes: 3116
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>

template<typename T>inline void check_max(T a,T &b){if(a>b)b=a;}
template<typename T>inline void read(T &x)
{
	char c=x=0;
	for(c=getchar();!isdigit(c);c=getchar());
	for(;isdigit(c);c=getchar())x=(x<<3)+(x<<1)+(c^48);
}

namespace igg
{
	const int N=100010;
	int begin[N],next[N],to[N];
	int f[N];
	int n,e;
	void add(int x,int y)
	{
		to[++e]=y;
		next[e]=begin[x];
		begin[x]=e;
	}
	void initialize()
	{
		read(n);
		for(int i=2,x;i<=n;i++)
			read(x),add(x,i);
	}
	std::vector<int> s[N];
	void dfs(int p=1)
	{
		for(int i=begin[p];i;i=next[i])
			dfs(to[i]),s[p].push_back(f[to[i]]);
		std::sort(s[p].begin(),s[p].end());
		int cnt=s[p].size();
		f[p]=0;
		for(auto it:s[p])
			check_max(it+cnt,f[p]),cnt--;
	}
	void solve()
	{
		initialize();
		dfs();
		printf("%d\n",f[1]);
	}
}

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


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

int main() {
	int a, b;
	cin >> a >> b;

	while (a != 0 || b != 0) {
		if (a < b)
			cout << a << " " << b << endl;
		else
			cout << b << " " << a << endl;
		cin >> a >> b;
	}	
	return 0;
}

Measured memory_bytes: 3056
h, w = map(int, input().split())
canpas = [input() for _ in range(h)]

for h_i in range(h):
    for w_i in range(w):
        if canpas[h_i][w_i] == '#':
            if w_i - 1 < 0:
                c1 = False
            else:
                c1 = canpas[h_i][w_i-1] == '#'

            if h_i - 1 < 0:
                c2 = False
            else:
                c2 = canpas[h_i-1][w_i] == '#'

            if h_i + 1 >= h:
                c3 = False
            else:
                c3 = canpas[h_i+1][w_i] == '#'

            if w_i + 1 >= w:
                c4 = False
            else:
                c4 = canpas[h_i][w_i+1] == '#'

            if c1 or c2 or c3 or c4:
                continue
            else:
                print('No')
                break
    else:
        continue
    break
else:
    print('Yes')

Measured memory_bytes: 39280
def check(b,d,path):
    seq = False
    for s in path[b:d]:
        if s == '#':
            if seq:
                return False
            else:
                seq = True
        else:
            seq = False  

    return True  


n,a,b,c,d = map( int, input().split() ) 
npath = input()
path = []
for s in npath:
    path.append(s)

a -= 1
b -= 1
c -= 1
d -= 1


ans = True
if c < d:
    ans = check(b,d,path) and check(a,c,path)
else:
    triple = 0
    for s in path[b-1:d+2]:
        if triple == 3:
            break
        if s == '#':
            triple = 0
        else:
            triple += 1

    if triple == 3:
        ans = check(a,d,path) and check(b,c,path)
    else:
        ans = False



if ans:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 5964
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1000000010
#define EPS 1e-9
#define fst first
#define scd second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  int n,m;
  cin>>n>>m;
  string s;
  rep(i,n){
    rep(j,m){
      cin>>s;
      if(s=="snuke"){
        cout<<(char)('A'+j)<<i+1<<endl;
        return 0;
      }
    }
  }
  

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define inf 1000000000
#define infll 1000000000000000000ll
#define vi vector<int>
#define vll vector<ll>
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define mpr make_pair
#define fi first
#define se second
#define pq priority_queue<int>
#define pqll priority_queue<ll>
#define up(x,y) (x<(y)?x=(y):0)
#define dn(x,y) (x>(y)?x=(y):0)
#define ad(x,y) (x=(x+(y))%mod)
#define N 2000009
using namespace std;

int n,A,B,C,D; char ch[N];
void gg(){ puts("No"); exit(0); }
bool check(int x,int y){
	int i;
	for (i=x; i<y; i++) if (ch[i]=='#' && ch[i+1]=='#') return 0;
	return 1;	
}
int main(){
	scanf("%d%d%d%d%d%s",&n,&A,&B,&C,&D,ch+1);
	ch[0]=ch[n+1]='#';
	int i;
	if (!check(A,C)) gg(); if (!check(B,D)) gg();;
	if (C>D){
		for (i=B; i<=D; i++)
			if (ch[i]=='.' && ch[i-1]=='.' && ch[i+1]=='.'){ puts("Yes"); return 0; }
		gg();
	}
	puts("Yes");
	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <cstring>

using namespace std;

#define MAX_X 1000001
#define MAX_N 30

bool is_prime[MAX_X];

void init() {
    memset(is_prime, 1, sizeof(is_prime));
    is_prime[0] = is_prime[1] = false;
    for (int i = 2; i < MAX_X; i++) 
        if (is_prime[i]) 
            for (int j = i+i; j < MAX_X; j+=i) 
                is_prime[j] = false;
}

bool can_make[MAX_X];

int n, x;
int dish[MAX_N];
bool input() {
    cin >> n >> x;
    if (n == 0 && x == 0) return false;
    for (int i = 0; i < n; i++) 
        cin >> dish[i];

    memset(can_make, 0, sizeof(can_make));
    can_make[0] = true;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j <= x; j++) {
            if (j >= dish[i] && can_make[j-dish[i]])
                can_make[j] = true;
        }
    }
    return true;
}

int main() {
    init();
    while (input()) {
        bool found = false;
        while (x) {
            if (is_prime[x] && can_make[x]) {
                found = true;
                cout << x << endl;
                break;
            }
            x--;
        }
        if (!found) cout << "NA" << endl;
    }
    return 0;
}

Measured memory_bytes: 3120
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long a,b,c,d,e;
    cin>>a>>b>>c>>d>>e;
    int f=e/2*2;
    if(e%2==0){
        cout<<min({a*e*4,b*e*2,c*e,d*e/2})<<endl;
    }
    else{
        cout<<min({a*f*4,b*f*2,c*f,d*f/2})+min({a*4,b*2,c})<<endl;
    }
    return 0;
}

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

#define ll long long
const ll mod = 1e9+7;
int tc;
ll sum, n;
ll dp[2005];

ll func(ll x)
{
    if(x<=2)
        return 0;
    if(x>=3 && x<=5)
        return 1;
    if(dp[x]!=-1)
        return dp[x];
    ll ss=0;
    for(ll i=3; i<=x; i++){
        ss = (ss%mod + func(x-i)%mod)%mod;
    }
    if(x>2)
        ++ss;
    return dp[x] = ss;

}

void solve(int kk)
{
   memset(dp, -1, sizeof dp);
   cin >> n;
   cout << func(n) << "\n";
}

int main(){
  #ifndef ONLINE_JUDGE
freopen("D:\\Codings\\CPP\\input.in", "r", stdin);
freopen("D:\\Codings\\CPP\\output.in", "w", stdout);
#endif
	ios::sync_with_stdio(0), cin.tie(0);
	int t=1;
    //cin >> t;
    while(++tc<=t)
        solve(tc);
}


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

const int N = 1e5 + 5;

int ans;
string s;

int main(){



    cin >> s;
    for (int i = 0; i < s.size() / 2; ++i){
        if (s[i] != s[(int)s.size() - i - 1]) ++ans;
    }
    cout << ans;


}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
bool palindrome(string s)
{
    bool flag=true;
    int n=s.length();
    for(int i=0;i<n;i++)
    {
        if(s[i]!=s[n-1-i])
        {
            flag=false;
            return flag;
        }
        if(i>=n-1-i) break;
    }
    return flag;
}
int main()
{
    string s;cin>>s;
    bool flag=false;
    ll n=s.length();
    string a,b;
    for(int i=0;i<(n-1)/2;i++)
        a=a+s[i];
    for(int i=(((n+3)/2)-1);i<n;i++)
        b=b+s[i];

    // cout<<a<<" "<<b<<" "<<s<<endl;
    bool x=palindrome(a);
    bool y=palindrome(b);
    bool z=palindrome(s);
    //cout<<x<<" "<<y<<" "<<z<<" "<<endl;
    if(x && y && z)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <string>
#include <typeinfo>
#include <random>
#include <vector>
//#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<vector<bool>> vvb;
typedef vector<vector<int>> vvi;

#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define all(a) (a).begin(), (a).end()

int sum(vi &ary)
{
  int total = 0;
  rep(i, ary.size())
  {
    total += ary.at(i);
  }
  return total;
}

int main()
{
  int a,b;
  cin >> a >> b;
  vi arr(b - a - 1);
  rep(i,b-a-1){
    arr.at(i) = i + 1;
  }
  cout << sum(arr) - a << endl;
  return 0;
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::vec::Vec;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n: usize,
        s: [String; n],
    }
    // eprintln!("{:?}", s);
    let mut list = HashSet::new();
    for col in s {
        list.insert(col);
    }
    println!("{}", if list.len() == 3 { "Three" } else { "Four" })
}


Measured memory_bytes: 4352
#include <iostream>
#include <iomanip>
#include <cmath>
#include <complex>
#include <vector>

using namespace std;

#define all(x) begin(x), end(x)
#define rall(x) (x).regin(), (x).rend()
typedef long long ll;
typedef complex<int> P;
typedef pair<int, int> pii;
typedef tuple<int, int, int> tii;
const int INF = 1e+8;
const double EPS = 1e-8;
const double PI = acos(-1.0);


bool solve(){
	int n;
	cin>> n;
	if(!n) return false;

	vector<int> t0(n);
	vector<vector<int>> t(n, vector<int>(n));
	for(int i=0;i<n;i++) for(int j=-1;j<n;j++){
		if(j == -1){
			cin>> t0[i];
		}else{
			cin>> t[i][j];
		}
	}

	vector<int> dp(1<<n, INF);
	dp[0] = 0;
	for(int i=0;i<(1<<n);i++){
		for(int j=0;j<n;j++){
			if((i>>j) & 1 == 1) continue;

			int cost = t0[j];
			for(int k=0;k<n;k++) if((i>>k) & 1 == 1) cost = min(cost, t[j][k]);

			dp[i|(1<<j)] = min(dp[i|(1<<j)], dp[i] + cost);
		}
	}

	cout<< dp[(1<<n)-1]<< endl;
	return true;
}

int main(){
	cout.setf(ios::fixed); cout.precision(10);
	while(solve());
	return 0;
}

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

#define all(A) begin(A), end(A)
#define rall(A) rbegin(A), rend(A)
#define sz(A) int(A.size())
#define pb push_back
#define mp make_pair

using namespace std;

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

int main () {
  ios::sync_with_stdio(false); cin.tie(0);
  int a, b;
  cin >> a >> b;
  if (a > b) swap(a, b);
  int ans;
  if (1 != a and 1 != b) ans = 1;
  if (2 != a and 2 != b) ans = 2;
  if (3 != a and 3 != b) ans = 3;
  cout << ans << '\n';
  return (0);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define Would
#define you
#define please

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

	string S;
	cin >> S;

	int A, B, C, D;
	A = S[0] - '0';
	B = S[1] - '0';
	C = S[2] - '0';
	D = S[3] - '0';

	rep(i, 8) {
		int kekka = A;
		int kekkac[3] = {};
		int kari = i;
		if (kari % 2) kekka += B, kekkac[0] = 1;
		else kekka -= B;
		kari /= 2;
		if (kari % 2) kekka += C, kekkac[1] = 1;
		else kekka -= C;
		kari /= 2;
		if (kari % 2) kekka += D, kekkac[2] = 1;
		else kekka -= D;
		if (kekka == 7) {
			cout << A;
			if (kekkac[0]) cout << "+";
			else cout << "-";
			cout << B;
			if (kekkac[1]) cout << "+";
			else cout << "-";
			cout << C;
			if (kekkac[2]) cout << "+";
			else cout << "-";
			cout << D << "=7\n";
			please break;
		}
	}
	Would you please return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
	char str[4];
	scanf("%s", str);
	if (str[0] == 'S' && str[1] == 'U') printf("7");
	else if (str[0] == 'M' && str[1] == 'O') printf("6");
	else if (str[0] == 'T' && str[1] == 'U') printf("5");
	else if (str[0] == 'W' && str[1] == 'E') printf("4");
	else if (str[0] == 'T' && str[1] == 'H') printf("3");
	else if (str[0] == 'F' && str[1] == 'R') printf("2");
	else if (str[0] == 'S' && str[1] == 'A') printf("1");
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }

int main(){
  int N; cin>>N;
  int h[N]; CINA(h,N);
  int high = 0;
  int r = 0;
  REP(i,N){
    if(h[i]>=high){ high = h[i]; ++r;}
  }
  cout << r << "\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5;
int a[N];
int main(){
	//freopen("in.txt","r",stdin);
	int n;
	cin>>n;
	int tm;
	for(int i=0;i<n;i++){
		cin>>tm;
		a[tm]++;
	}
	int res = 0;
	for(int i=1;i<N;i++){
		res = max(res,a[i-1]+a[i]+a[i+1]);
	}
	cout<<res;
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(){
  long n;
  cin>>n;
  int min;
  for(int i=1;i<=n/2;i++){
    int sum=0;
    int x=i;
    int y=n-i;
    for(int j=0;j<5;j++){
      sum+=x%10;
      sum+=y%10;
      x=x/10;
      y=y/10;
    }
    if(i==1){
      min=sum;
    }
    else if(sum<min){
      min=sum;
    }
  }
  cout<<min<<endl;
    
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <string>
#include <iostream>
#include <stdio.h>
#include <queue>
#include <cmath>
#include <utility>
#include <map>

using namespace std;
typedef long long ll;
#define rep(i,a,b) for(int i=(a);i<(b);++i)

bool isSame(string S) {
	char c = S[0];
	for (int i = 0; i < S.size(); i++) {
		if (S[i] != c)
			return false;
	}
	return true;
}

int main() {
	string S,U;
	cin >> U;
	
	int ans = 100000000;
	for (char x = 'a'; x <='z' ; x++) {
		int score = 0;
		string T;		
		S = U;
		while (!isSame(S)) {
			T.clear();
			for (int j = 0; j < S.size() - 1; j++) {
				if (S[j] == x || S[j + 1] == x) {
					T.push_back(x);
				}
				else {
					T.push_back(S[j]);
				}
			}
			S = T;
			score++;
		}
		ans = min(ans, score);
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256