akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>
 
using namespace std;



int MOD=1000000007;
int main(void){
	int H,W,N;
	cin >> H >> W >> N;
	if(H>W){
		if(N%H==0){
			cout << N/H << endl;
		}else{
			cout << N/H+1 << endl;
		}
	}else{
		if(N%W==0){
			cout << N/W << endl;
		}else{
			cout << N/W+1 << endl;
		}
	}

}

Measured memory_bytes: 256
//{{{
#include<algorithm>
#include<cmath>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<random>
#include<set>
#include<sstream>
#include<sys/time.h>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printw) FUNC(printwe) FUNC(printb) FUNC(printbe) FUNC(printd) FUNC(printde) FUNC(printdu);
#endif
template <class S, class T>
istream& operator >> (istream& in, pair<S, T>& p){ return in >> p.first >> p.second; }
template <class T>
istream& operator >> (istream& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }
//}}}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vector<int> ss(n); cin >> ss;
    vector<int> ts(m); cin >> ts;
    vector<int> dp[2] = {vector<int>(m + 1, 1), vector<int>(m + 1)};
    // vector<vector<int>> dp(2, vector<int>(m + 1, 1));
    for(int i = 0; i < n; i++){
        int i1 = i & 1, i2 = !i1;
        dp[i2][0] = 1;
        for(int j = 0; j < m; j++){
            int& num = dp[i2][j + 1];
            int& num2 = dp[i1][j + 1];
            if(ss[i] == ts[j]){
                num = *(&num - 1) + num2;
                // num = dp[i2][j] + dp[i1][j + 1];
                if(num >= M){
                    num -= M;
                }
            }else{
                num = *(&num - 1) + num2 - *(&num2 - 1);
                // num = dp[i2][j] + dp[i1][j + 1] - dp[i1][j];
                if(num >= M){
                    num -= M;
                }else if(num < 0){
                    num += M;
                }
            }
        }
    }
    printde(dp);
    cout << dp[n & 1][m] << '\n';
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	int a,b,gra,grb;
	cin>>a>>b;
	if(a==1||a==3||a==5||a==7||a==8||a==10||a==12)gra=1;
	if(b==1||b==3||b==5||b==7||b==8||b==10||b==12)grb=1;
	if(a==4||a==6||a==9||a==11)gra=2;
	if(b==4||b==6||b==9||b==11)grb=2;
	if(a==2)gra=3;
	if(b==2)gra=3;
	if(gra==grb)cout<<"Yes";
	else cout<<"No";
	return 0;
}

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

using namespace std;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

vector<long long>vprime;

void SieveOfEratosthenes(int n)

{

    bool prime[n+1];

    memset(prime, true, sizeof(prime));

    for (int p=2; p*p<=n; p

    ++)

    {

        if (prime[p] == true)

        {

            for (int i=p*p; i<=n; i += p)

                prime[i] = false;

        }

    }

    for (int p=2; p<=n; p++)

       if (prime[p])

          vprime.push_back(p);

}

long long fact(long long n);

long long nCr(long long n, long long r)
{
    return fact(n) / (fact(r) * fact(n - r));
}

// Returns factorial of n
long long fact(long long n)
{
    long long res = 1;
    for (long long i = 2; i <= n; i++)
        res = res * i;
    return res;
}

int main()

{

    IOS;

    long long a,b,c,d,e,g,h,k,l,m,n,t,f,f1=0,flag2=0,flag=0,flag1=0,co=0,co1=0,co2=0,sum=0,sum1=0,ma=0,ma1=0,ma2=0,mi=100000000000,mi1=100000000000,mi2=100,mi3=1000;

    long long co3=0,co4=0,co5=0,co6=0,co7=0,co8=0,mul=1,sum2=0;

    long long arr[100001],arr1[100001]={0};

    long long a1,a2,b1,b2,c1,c2,a3,a4,b3,b4,b5,b6,m1,m2,k1,l1,m3,m4,d1,d2;

    double pi=2 * acos (0.0);



    char ch;

    //set<long long>::iterator it;

    //vector<long long>v;

    string str,str1,str2,str3;



    //vector<string>vs;

    //vector<string>vs1;

    //vector<pair<long long,pair<long long, long long> > >v;

    //set<string>s;

    set<long long>s1;

    set<long long>s2;

    set<long long>s3;

    //map< char,long long > mp1;

    stack<long long>st;

    //list<long long>li;

    int x[]={1,-1,1,-1,2,2,-2,-2};

    int y[]={2,2,-2,-2,1,-1,1,-1};

    //int x[]={1,0,0,-1};

    //int y[]={0,1,-1,0};

    //map< long long,long long > mp;

    //map< long long,long long>::iterator it;

    //vector<pair<long long,long long> >v3;

    cin>>str;
    a=str.size();
    b=(a-1)/2;
    c=(a+3)/2;
    for(int i=0; i<b; i++)
    {
        str1+=str[i];
    }
    for(int i=c-1; i<str.size(); i++)
    {
        str2+=str[i];
    }
    str3=str;
    reverse(str.begin(),str.end());
    if(str3==str)
    {
        str3.clear();
        str3=str1;
        reverse(str1.begin(),str1.end());
        if(str1==str3)
        {
            str3.clear();
            str3=str2;
            reverse(str2.begin(),str2.end());
            if(str2==str3)
            {
                cout<<"Yes"<<endl;
            }
            else cout<<"No"<<endl;
        }
        else
            cout<<"No"<<endl;
    }
    else cout<<"No"<<endl;

    return 0;

}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
    char number[1001];
    int i, sum;
    while(1){
        scanf("%s", number);
        if( number[0]=='0') break;
        sum = 0;
        for( i = 0; number[i]!='\0';i++ ){
            sum += number[i] - '0';
        }
        printf( "%d\n",sum );
    }
    return 0;
}


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

int cnt=0;
int x[50];
ll f(int n,int m){
  if(n==1){
    if(m!=0){
      if(x[0]==m)return 1;
      else return 0;
    }else{
      if(x[0]==m)return 2;
      else return 1;
    }
  }
  return f(n-1,m-x[n-1])+f(n-1,m);
}

int main(){
  int i,j;
  int n,a;
  cin>>n>>a;
  const int N=10000;
  for(i=0;i<n;i++)cin>>x[i];
  for(i=0;i<n;i++)x[i]-=a;
  ll b[n][N+1];
  for(i=0;i<n;i++){
    for(j=0;j<=N;j++){
      b[i][j]=0;
    }
  }
  for(i=0;i<=N;i++){
    if(i!=N/2){
      if(x[0]==i-N/2)b[0][i]=1;
      else b[0][i]=0;
      
    }else{
      if(x[0]==0)b[0][i]=2;
      else b[0][i]=1;
    }
  }
  for(i=1;i<n;i++){
    for(j=50;j<=N-50;j++){
      b[i][j]=b[i-1][j-x[i]]+b[i-1][j];
    }
  }
  cout<<b[n-1][N/2]-1<<endl;
}

Measured memory_bytes: 4096
//#pragma GCC optimize("03", "unroll-loops")
//#pragma GCC target("avx2")

#include <bits/stdc++.h>

#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define FOR(i,n) for(i=0;i<n;i++)
#define FORn(i,j,n) for(i=j;i<n;i++)
#define pb push_back
#define unique_sort(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define vli vector<lli>
#define vi vector<int>
#define vs vector<string>
#define vprint(v) for(auto t:v)cout<<t<<" "
#define endl "\n"

typedef long long int lli;
typedef long int li;

const lli mod=1000000007;
const lli limit=1000000;

using namespace std;

void fc(lli &x)
    {
        bool neg=false;
        register char c;
        x =0;
        c=getchar();
        if(c=='-')
        {
            neg = true;
            c=getchar();
        }
        for(;(c>47 && c<58);c=getchar())
            x = (x<<1) + (x<<3) +c -48;
        if(neg)
            x *=-1;
    }

int main() {

    fast()
    lli n,q,t;
    lli temp,temp1,temp2,temp3;
    lli i,j,k,m;
    cin>>n>>m;
    temp=(n*(n-1))/2 + (m*(m-1))/2;
    cout<<temp<<endl;
 
}

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

struct UnionFind {
    vector<ll> par;
    vector<ll> rnk;

    UnionFind(ll n) {
        par.assign(n, 0);
        rnk.assign(n, 1);
        for(ll i=0; i<n; i++) {
            par[i] = i;
        }
    }

    void unite(ll x, ll y) {
        x = find(x); y = find(y);
        if(x == y) return;
        if(rnk[x] < rnk[y]) swap(x, y);
        rnk[x] += rnk[y];
        par[y] = x;
    }

    ll find(ll x) {
        if(par[x] == x) return x;
        return par[x] = find(par[x]);
    }

    bool same(ll x, ll y) {
        return find(x) == find(y);
    }

    ll size(ll x) {
        return rnk[find(x)];
    }
};

int main() {
    ll N, M;
    cin >> N >> M;
    vector<ll> A(M), B(M);
    rep(i, M) {
        cin >> A[i] >> B[i];
        A[i]--; B[i]--;
    }
    UnionFind uf(N);

    vector<ll> res(M);
    res[M-1] = (N*(N-1))/2;
    for(ll i=M-2; i>=0; i--) {
        if(!uf.same(A[i+1], B[i+1])) {
            res[i] = res[i+1] - (uf.size(A[i+1]) * uf.size(B[i+1]));
            uf.unite(A[i+1], B[i+1]);
        } else {
            res[i] = res[i+1];
        }
    }

    rep(i, M) cout << res[i] << endl;
    return 0;
}

Measured memory_bytes: 5248
#include <bits/stdc++.h>
#define ll long long
#define INF 999999999
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<n;++i)

using namespace std;

typedef pair<int,int>P;

const int MAX_N = 2005;

ll dp[MAX_N][MAX_N];
int a[MAX_N];
int n;

int main()
{
	scanf("%d",&n);
	rep(i,n){
		scanf("%d",&a[i]);
	}
	rep(i,n){
		rep(j,n){
			dp[i][j] = 0;
		}
	}
	if(n%2==1){
		rep(i,n){
			dp[i][i] = a[i];
		}
	}
	for(int k=1;k<=n-1;k++){
		rep(i,n){
			int j = (i+k)%n;
			if(((j+n-i)%n)%2 != n%2){
				dp[i][j] = max(dp[(i+1)%n][j]+a[i],dp[i][(j+n-1)%n]+a[j]);
			}else{
				if(a[i] > a[j]){
					dp[i][j] = dp[(i+1)%n][j];
				}else{
					dp[i][j] = dp[i][(j+n-1)%n];
				}
			}
		}
	}
	ll ans = 0;
	rep(i,n){
		ans = max(ans,dp[(i+1)%n][(i+n-1)%n]+a[i]);
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 34528
#include<bits/stdc++.h>
using namespace std;
#define opt ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define lli long long int
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define mod		1000000007
#define inf     1000000000000000000
#define MX1		100005
#define MX2		10000004
#define pi		acos(-1)
#define pb      push_back
#define vlli    vector<lli>
#define plli    vector<pair<lli,lli> >
#define mp      make_pair
#define all(v)  v.begin(),v.end()
#define setbits(n) __builtin_popcount(n)
#define test    int t;cin>>t;
lli gcd(lli a, lli b){return b?gcd(b,a%b):a;}
lli power(lli a,lli b){lli ans=1;while(b){if(b&1){ans=(ans*a)%mod;}a=(a*a)%mod;b>>=1;}return ans;}
int main()
{
	opt;
	lli i,j,k,l;
	lli n;
	cin>>n>>k;
	if(k>=n)
	cout<<"0\n";
	else
	cout<<n-k<<"\n";

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(){
	int H;
	int A;
	int total;
	scanf ("%d %d",&H,&A);
	total = H/A;
	if (H%A==0){
		printf("%d",total);
	}
	else{
		printf("%d",total+1);
	}
	return 0;
}

Measured memory_bytes: 2028
#include<stdio.h>
#define MAX 100000
#define SENTINEL 2000000000

struct Card{
  char suit;
  int value;
};

struct Card L[MAX/2+2],R[MAX/2+2];

void merge(struct Card A[],int n,int left, int mid,int right){
 int i,j,k;
 int n1 = mid-left;
 int n2 = right-mid;
 for(i=0;i<n1;i++)L[i]=A[left+i];
 for(i=0;i<n2;i++)R[i]=A[mid+i];
 L[n1].value=R[n2].value=SENTINEL;
 i=j=0;
for(k=left;k<right;k++){
  if(L[i].value<=R[j].value){A[k]=L[i++];}
  else {A[k]=R[j++];}
}
}

void mergeSort(struct Card A[],int n,int left,int right){
    int mid;
    if(left+1<right){
      mid = (left + right)/2;
      mergeSort(A,n,left,mid);
      mergeSort(A,n,mid,right);
      merge(A,n,left,mid,right);
    }
  }
int partition(struct Card A[],int n,int p,int r){
int i,j;
struct Card t,x;
x=A[r];
i=p-1;
for(j=p;j<r;j++){
if(A[j].value<=x.value){
i++;
t=A[i];
A[i]=A[j];
A[j]=t;
}
}
t=A[i+1];
A[i+1]=A[r];
A[r]=t;
return i+1;
}
void quickSort(struct Card A[],int n, int p,int r){
int q;
if(p<r){
q=partition(A,n,p,r);
quickSort(A,n,p,q-1);
quickSort(A,n,q+1,r);
}
}
int main(){
int n,i,v;
struct Card A[MAX],B[MAX];
char S[10];
int stable=1;
scanf("%d",&n);
for(i=0;i<n;i++){
scanf("%s %d",S,&v);
A[i].suit=B[i].suit=S[0];
A[i].value=B[i].value=v;
}

mergeSort(A,n,0,n);
quickSort(B,n,0,n-1);

for(i=0;i<n;i++){
if(A[i].suit!=B[i].suit){stable=0;}
}
if(stable==1)printf("Stable\n");
else printf("Not stable\n");
for(i=0;i<n;i++){
printf("%c %d\n",B[i].suit,B[i].value);
}
return 0;
}




Measured memory_bytes: 4084
#include <iostream>
#include <vector>
#include <cstring>
#include <queue>
using namespace std;

inline vector<int> bfs(int n,vector<vector<int> > &g,int s)
{
	vector<int> d(n,1e9);d[s]=0;
	queue<int>q;q.push(s);
	while(!q.empty())
	{
		int cur=q.front();q.pop();
		for(auto v:g[cur])
			if(d[v]>d[cur]+1)
			{
				d[v]=d[cur]+1;
				q.push(v);
			}
	}
	return d;
}

int main()
{
	int n;
	cin>>n;
	vector<vector<int> > g(n);
	
	for(int i=0;i<n-1;i++)
	{
		int a,b;
		cin>>a>>b;
		a--;b--;
		g[a].push_back(b);g[b].push_back(a);
	}
	
	vector<int> a=bfs(n,g,0);
	vector<int> b=bfs(n,g,n-1);
	
	int f=0,s=0;
	for(int i=0;i<n;i++) if(a[i]<=b[i]) f++; else s++;
	cout<<(f>s?"Fennec":"Snuke");
	
	return 0;
}

Measured memory_bytes: 6528
using System;
using System.Collections.Generic;
using System.Linq;

namespace AGC013_A
{
    class Program
    {
        static void Main(string[] args)
        {
            int amount = int.Parse(Console.ReadLine());
            int[] numbers = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

            int split = 0;
            for (int i = 0; i < amount - 1; i++)
            {
                if (numbers[i] == numbers[i + 1])
                {
                    continue;
                }

                if (numbers[i] < numbers[i + 1])
                {
                    int a = i + 1;
                    while (a < amount - 1)
                    {
                        if (numbers[a] <= numbers[a + 1])
                        {
                            a++;
                        }
                        else
                        {
                            i += a - i;
                            break;
                        }
                    }
                    if (a == amount - 1)
                    {
                        break;
                    }
                    split++;
                }
                else if (numbers[i] > numbers[i + 1])
                {
                    int a = i + 1;
                    while (a < amount - 1)
                    {
                        if (numbers[a] >= numbers[a + 1])
                        {
                            a++;
                        }
                        else
                        {
                            i += a - i;
                            break;
                        }
                    }
                    if (a == amount - 1)
                    {
                        break;
                    }
                    split++;
                }
            }
            Console.WriteLine(split + 1);
        }
    }
}


Measured memory_bytes: 21728
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); ++i)

using namespace std;
using ll = long long;
using v1 = vector<int>;
using vl = vector<long long>;
using v2 = vector<vector<int>>;
using v3 = vector<vector<char>>;
int n;
ll k;
vl a(0);

int minuscheck(ll x, int i){
	ll left = -1;
	ll right = n;
	while(left + 1 < right){
		ll mid = (left+right)/2;
		 if(a[i]*a[mid] >= x) left = mid;
		 else right = mid;
	}
	return n-right;
}

int pluscheck(ll x, int i){
	ll left = -1;
	ll right = n;
	while(left + 1 < right){
		ll mid = (left+right)/2;
		if(a[i]*a[mid] >= x) right = mid;
		else left = mid;
	}
	return right;
}

const ll INF = ll(1e18+1);

int main(){
	cin >> n >> k;
	rep(i, n){
		int x;
		cin >> x;
		a.push_back(x);
	}
	sort(a.begin(), a.end());
	ll left = -INF;
	ll right = INF;
	ll answer;
	while(left+1<right){
		ll kr = 0;
		ll x = (left+right)/2;
		rep(i, n){
			if(a[i] < 0){
				kr += minuscheck(x, i);
			}else{
				kr += pluscheck(x, i);
			}
			if(a[i]*a[i]<x) kr--;
		}
		kr /= 2;
		if(kr < k) left = x;
		else right = x;
		answer = left;
	}
	cout << answer << endl;
}


Measured memory_bytes: 5236
#include <iostream>
#include <cstdio>
using namespace std;
int h, n, x, sum, i;
int main() {
	scanf("%d%d", &h, &n);
	for (i = 1; i <= n; i++) {
		scanf("%d", &x);
		sum += x;
	}
	if (sum >= h) printf("Yes");
	else printf("No");
	return 0;
}

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

using namespace std;

int main() {
	int L, R, d;
	cin >> L >> R >> d;

	int num = 0;
	for (int i = L; i <= R; i++) {
		if (i % d == 0) num++;
	}

	cout << num << endl;

	return 0;
}


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

int main()
{
    int n;
    cin >> n;
    vector<int> p(n), q(n), ref(n);
    rep(i, n) cin >> p[i];
    rep(i, n) cin >> q[i];

    rep(i, n) ref[i] = i + 1;
    int a = 0;
    do
    {
        ++a;
        bool t = false;
        rep(i, n) if (p[i] != ref[i]) t = true;
        if (!t)
            break;
    } while (next_permutation(ref.begin(), ref.end()));

    rep(i, n) ref[i] = i + 1;
    int b = 0;
    do
    {
        ++b;
        bool t = false;
        rep(i, n) if (q[i] != ref[i]) t = true;
        if (!t)
            break;
    } while (next_permutation(ref.begin(), ref.end()));

    cout << abs(a - b) << endl;
}

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

int main() {
 int a,b; cin >> a >> b;
 string joined = to_string(a) + to_string(b);
 int joinedInt = stoi(joined); 
  
 for(int i = 1; i*i <= joinedInt; i++) {
  if(joinedInt == i*i) {
    cout << "Yes" << endl;
    return 0;
  }
 }
   cout << "No" << endl;
  
 return 0; 
}

Measured memory_bytes: 3620
#include <iostream>
using namespace std;
int main(){

  int H,W;

  while(1){
    
    cin >>H>>W;
    
    if(H==0 && W==0)break;

    for(int i=0;i<H;i++){
      for(int j=0;j<W;j++){
	cout <<"#";
      }
      cout <<endl;
    }
    cout <<"\n";
  }
  return 0;
}

Measured memory_bytes: 1152
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<queue>
using namespace std;
char a[100005];
int main()
{
	scanf("%s",a);
	int len=strlen(a);
	if(a[0]==a[len-1])
	{
		if(len%2==1)
		printf("Second");
		else printf("First");
	}
	if(a[0]!=a[len-1])
	{
		if(len%2==1) 
		printf("First");
		else printf("Second");
	}
	return 0;
} 

Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<map>
using namespace std;
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; }
const long long INF = 1LL << 60;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main(){
    int64_t n;
    cin>>n;
    int64_t f=100;
    for(int64_t i=1;i*i<=n;i++){
        if(n%i==0){
            int64_t a=log10(n/i)+1;
            f=min(f,a);
        }
    }
    cout<<f<<endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
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; }

int main(){
    ll N,r=0,b=0,g=0;
    string S;
    cin >> N >> S;
    
    for (int i=0; i<N; i++){
        if (S[i]=='R') r++;
        if (S[i]=='G') g++;
        if (S[i]=='B') b++;
    }
    
    ll mis=0;
    ll sum=r*g*b;
    for (int i=0; i<N; i++){
        for (int j=i+1; j<N; j++){
            int k=j+(j-i);
            if (k<N && S[i]!=S[j] && S[i]!=S[k] && S[j]!=S[k]) mis++;
        }
    }
    cout << sum-mis << endl;
}


Measured memory_bytes: 3636
import java.util.Scanner;

public class Main {
	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		int n = sc.nextInt();
		int m = sc.nextInt();

		int[] a = new int[m * 2];

		for (int i = 0; i < m * 2; i++) {
			a[i] = sc.nextInt();
		}

		for (int i = 1; i <= n; i++) {
			int count = 0;
			for (int j = 0; j < m * 2; j++) {
				if (a[j] == i) {
					count++;
				}
			}
			System.out.println(count);
		}

	}
}

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

using namespace std;

/* g++ -g -fsanitize=address -lasan -std=c++11 -Dfoo_ */

/* freopen("input.txt", "rt", stdin); */
/* freopen("output.txt", "wt", stdout); */

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

const int maxn = 110;
int G[maxn][maxn];

int main()
{
#ifdef foo_
    freopen("foo", "rt", stdin);
#endif
    int n,k;
    while (cin >> n >> k) {
        memset(G,0,sizeof(G));
        FOR(i,2,n+1)
            G[1][i] = 1;
        int cnt = (n-1)*(n-2)/2;
        for (int i = 2; cnt > k && i <= n; i++) {
            for (int j = i+1; cnt > k && j <= n; j++) {
                cnt--; G[i][j] = 1;
            }
        }
        if (cnt < k)
            cout << -1 << endl;
        else {
            int m = 0;
            FOR(i,1,n+1) FOR(j,1,n+1) if (G[i][j])
                m++;
            cout << m << endl;
            FOR(i,1,n+1) FOR(j,1,n+1) if (G[i][j])
                cout << i << ' ' << j << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 256
//Name : Rupa Dey
  //Date : 17 September 2020
//joi sri gour hori gobindo...
//gobindo ja hobe vlor jonnoi hobe..
#include<bits/stdc++.h>
#define ll long long
#define d double
#define ld long double
#define vi vector<int>
#define vul vector<ull>
#define vl vector<ll>
#define pb push_back
#define si set<int>
#define sl set<ll>
#define yes cout<<"YES\n"<<endl
#define no cout<<"NO\n"<<endl
#define ys cout<<"Yes\n"<<endl
#define n0 cout<<"No\n"<<endl
#define test cin>>t; while(t--)
#define for(i,a,n) for(i=a;i<n;i++)
#define mp make_pair
#define ft first
#define sc second
#define gp ' ';
#define MAX 9999999
#define MOD 1000000007
#define nd endl
using namespace std;
int main()
{
   ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    string s;
    cin>>s;
    int i;
    for(i,0,s.size()) cout<<'x';

}
//hare krishna...
//hey gobindo kripa koro......
//only gobindo exists..^..


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

int main()
{
    int n;
    cin >> n;
    vector<vector<vector<int>>> dic(10,vector<vector<int>>(10,vector<int>()));

    for(int i = 1; i <= n; ++i)
    {
        int t = i;
        while(t >= 10)
        {
            t /= 10;
        }
        dic[t%10][i%10].push_back(i);
    }

    int ans = 0;
    for(int i = 1; i <= n; ++i)
    {
        int t = i;
        while(t >= 10)
        {
            t /= 10;
        }
        int head = t%10;
        int tail = i%10;
        ans += dic[tail][head].size();
    }

    cout << ans << endl;
}

Measured memory_bytes: 1536
# dp[i][w_sum]: i番目までの品物で重さがw_sumを超えないように選んだときの、価値の総和の最大値
N, W = map(int, input().split())
items = [tuple(map(int, input().split())) for i in range(N)]

dp = [[0 for w_sum in range(W+1)] for i in range(N+1)]

for i in range(N):
    for w_sum in range(W+1):

        # i-1番目の品物を選ぶ場合
        # 重量的に入れられるなら入れてみる
        if w_sum+items[i][0] <= W:
            dp[i+1][w_sum+items[i][0]] = max(dp[i+1][w_sum+items[i][0]],
                                             dp[i][w_sum]+items[i][1])

        # i-1番目の品物を選ばない場合
        dp[i+1][w_sum] = max(dp[i+1][w_sum], dp[i][w_sum])

ans = 0
for w in range(W+1):
    ans = max(ans, dp[N][w])
print(ans)


Measured memory_bytes: 171912
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <cmath>
#include <string>
#include <set>
#include <map>

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

int main()
{
	int N;
	scanf("%d",&N);
	for(int i=1;i<=3500;i++)
	{
		for(int j=1;j<=3500;j++)
		{
			ll A=4LL*(ll) i*(ll) j-(ll) N*(ll) (i+j);
			ll B=(ll) N*(ll) i*(ll) j;
			if(A>0&&B%A==0)
			{
				printf("%d %d %lld\n",i,j,B/A);
				return 0;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
 
#define lol long long
#define gcd(x,y) __gcd(x,y)
#define mt make_tuple
#define mp make_pair
#define fi first
#define se second
#define fixed(x) fixed<<setprecision(x)
using namespace std;
using pii=pair<int,int>;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
template <class A> inline lol abs(A &a) { return (a < 0 ? -a : a); }
bool inLine(int x,int y,int mx,int my){return (x>=0&&y>=0&&x<mx&&y<my);}
const lol inf=(1LL<<62);
const int MOD=(1e9)+7;
const int mod=998244353;
const int dx[]={1,0,-1,0,1,1,-1,-1};
const int dy[]={0,1,0,-1,1,-1,1,-1};
using namespace std;
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  string s;
  cin >>n>>s;
  lol ans=0;
  int w,r;
  w=r=0;
  for(int i=0;i<n;i++){
    if(s[i]=='W') w++;
    else r++;
  }
  for(int i=0;i<r;i++){
    if(s[i]=='W') ans++;
  }
  cout <<ans<<'\n';
  return (0);
}

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

#define NREP() for(ll i = 0; i < n; i++)
#define MREP() for(ll j = 0; j < m; j++)
#define REP(i, x, y) for(ll i = x; i < y; i++)
#define ALL(x) (x).begin(), (x).end()
#define MSG(x) cout << x << endl;
#define MSGF(x, n) MSG(fixed << setprecision(n) << x)
#define END(x) cout << x << endl; exit(0);
#define IPT(v, n) REP(i, 0, n){ cin >> v[i]; }
#define YN(x) x ? cout << "YES" << endl : cout << "NO" << endl;
#define Yn(x) x ? cout << "Yes" << endl : cout << "No" << endl;
#define yn(x) x ? cout << "yes" << endl : cout << "no" << endl;

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<ull> vul;
typedef vector<vector<ull>> vvul;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;

const static ll MOD = 1e9 + 7;
const static ll INF = 1LL << 30;

ll a, b, c, d, k, l, m, n, h, w, q, x, y;
string s, t;

ull ans = 0;
ll sum = 0;
ll cnt = 0;
ull cur = 0;
ll tmp = 0;
ll mini = INF;
ll maxi = 0;

double ave = 0.0;

bool can_make = false;

void dfs(string str) {
    if (str != s.substr(0, str.length())) return;

    if (str.length() >= s.length()) {
        if (str == s && !can_make) {
            can_make = true;
        }
        return;
    }

    if (s.at(str.size()) == 'd') {
        dfs(str + "dream");
        dfs(str + "dreamer");
    } else {
        dfs(str + "erase");
        dfs(str + "eraser");
    }
}

int main() {
    cin >> s;
    reverse(ALL(s));
    ll idx = 0;
    while (true) {
        if (s.substr(idx,  5) == "maerd" ||
            s.substr(idx,  5) == "esare") {
            idx += 5;
        } else if (s.substr(idx,  6) == "resare") {
            idx += 6;
        } else if (s.substr(idx,  7) == "remaerd") {
            idx += 7;
        } else {
            END("NO")
        }

        if (idx == s.size()) {
            END("YES")
        }
    }
}


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

using namespace std;

#define P(s) cout << s << endl;
#define DEBUG(x) cout << #x << ": " << x << endl;
#define INF (1 << 29)

vector<int> rs; // 巡回必要なもの全てRs
int Cs[201][201] = {0}; // 全パスの距離

int main() {

  int N, M, R;
  cin >> N >> M >> R;
  
  for (int i = 0; i < R; i++) {
    int r;
    cin >> r;
    rs.push_back(r);
  }

  for (int i = 1; i <= N; i++) { 
    for (int j = 1; j <= N; j++) { 
      if (i != j) {
        Cs[i][j] = INF;
      }
    }
  } // fill

  for (int i = 0; i < M; i++) {
    int A, B, C;
    cin >> A >> B >> C;
    Cs[A][B] = C;
    Cs[B][A] = C;
  }

  // cout << "---------" << endl;
  // for (int i = 1; i <= N; i++) { 
  //   for (int j = 1; j <= N; j++) { 
  //     DEBUG(i);
  //     DEBUG(j);
  //     DEBUG(Cs[i][j]);
  //   }
  // }
  // cout << "---------" << endl;

  // 1. ワーシャルフロイドですべての頂点の対の最小距離を求める
  for (int k = 1; k <= N; k++) {
    for (int i = 1; i <= N; i++) { 
      for (int j = 1; j <= N; j++) { 
        if(Cs[i][k] != INF && Cs[k][j] != INF) { // オーバーフロー対策!!!!
          Cs[i][j] = min(Cs[i][j], Cs[i][k] + Cs[k][j]);
        }
      }
    }
  }

  // for (int i = 1; i <= N; i++) { 
  //   for (int j = 1; j <= N; j++) { 
  //     DEBUG(i);
  //     DEBUG(j);
  //     DEBUG(Cs[i][j]);
  //   }
  // }

  // 2. rsのすべての順列組み合わせを作り、最短距離を使ってそれぞれの全コストを求め、最短を出力
  vector<int> paths = rs;
  int min = INF;
  sort(paths.begin(), paths.end()); // next_permutation は sortされている必要があった！
  do {
    int sum = 0;
    for (int i = 0; i < R - 1; i++) {
      int start = paths[i];
      int end = paths[i + 1];
      sum = sum + Cs[start][end];
      // cout << start << "->" << end << " ";
    }
    // cout << " : " << sum << endl;
    if (sum <= min) min = sum;
  } while (next_permutation(paths.begin(), paths.end()));

  cout << min << endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0; i<(n); i++)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
int main(){
    ll n,k; cin>>n>>k;
    vector<ll> x(n), y(n);
    vector<pair<ll,ll>> p(n);
    rep(i,n){
        cin>>x[i]>>y[i];
        p[i]={x[i], y[i]};
    }
    sort(p.begin(), p.end());
    ll res=5*1e18;
    for(ll left=0; left<n; left++){
        for(ll right=left; right<n; right++){
            if(right-left+1<k) continue;
            ll width=p[right].first-p[left].first;
            vector<ll> Y;
            for(ll i=left; i<=right; i++) Y.push_back(p[i].second);
            sort(Y.begin(), Y.end());
            ll tmp=1e15;
            for(ll i=0; i+k<=Y.size(); i++){
                chmin(tmp, Y[i+k-1]-Y[i]);
            }
            chmin(res, width*tmp);
        }
    }
    cout<<res<<endl;
    return 0;
}

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

using namespace std;

vector<string> item;
vector<int> cost;
vector<vector<string> > list;

map<string,int> name;

int saiki(int n){
	int cont=0;
	
	if(list[n].empty()==1){
		return cost[n];
	}
	
	for(int i=0;i<list[n].size();i++){
		cont+=saiki(name[list[n][i]]);
	}
	
	return min(cont,cost[n]);
}
int main(){
	while(1){
		int n;
		cin>>n;
		if(n==0){
			break;
		}
		item.clear();
		cost.clear();
		list.clear();
		for(int i=0;i<n;i++){
			string a;
			int b;
			cin>>a>>b;
			item.push_back(a);
			cost.push_back(b);
			name[a]=i;
		}
		int m;
		cin>>m;
		for(int i=0;i<n;i++){
			vector<string> kari;
			list.push_back(kari);
		}
		for(int i=0;i<m;i++){
			string a;
			int b;
			cin>>a>>b;
			vector<string> kari;
			kari.clear();
			for(int j=0;j<b;j++){
				string c;
				cin>>c;
				kari.push_back(c);
			}
			list[name[a]]=kari;
		}
		
		string a;
		cin>>a;
		cout<<saiki(name[a])<<endl;;
	}
}

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

int main() {
    int a, b;
    cin >> a >> b;
    cout << (a / b) << " ";
    cout << (a % b) << " ";
    cout << fixed << setprecision(5) << ((double)a / b) << endl;

    return 0;
}


Measured memory_bytes: 3292
# -*- coding: utf-8 -*-

N = int(input())

# 6**(i+1)を1回と6**iを6回は同じ金額分引き出せる
# 9も同様
# よって、6のグループと9のグループに分けて全探索すればよい

result = N
for i in range(N+1):
    ans = 0

    six_remain = i
    six_exp = 1
    while six_exp * 6 <= six_remain:
        six_exp *= 6
    # 6**i(<=i)から順に引き出していく
    while six_exp != 1:
        ans += six_remain // six_exp
        six_remain %= six_exp
        six_exp //= 6
    ans += six_remain

    nine_remain = N - i
    nine_exp = 1
    while nine_exp * 9 <= nine_remain:
        nine_exp *= 9
    # 9**i(<=N-i)から順に引き出していく
    while nine_exp != 1:
        ans += nine_remain // nine_exp
        nine_remain %= nine_exp
        nine_exp //= 9
    ans += nine_remain

    result = min(result, ans)

print(result)


Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());

        // 主処理
        int result = 0;
        for (int i = n; 0 < i; i--) {
            result += i;
        }

        // 出力
        System.out.println(result);
        sc.close();
    }
}


Measured memory_bytes: 21588
s = gets.chomp.chars
n = s.size

a = 0
b = 0
s.each_with_index do |ss, i|
  if i.odd? 
    if ss == "0"
      a += 1
    else
      b += 1
    end
  end
  if i.even? 
    if ss == "1"
      a += 1
    else
      b += 1
    end
  end
  
  # if i.odd? && ss == "1"
  #   b += 1
  # end
  # if i.even? && ss == "0"
  #   b += 1
  # end
end
puts [a, b].min

Measured memory_bytes: 11516
#include<stdio.h>


int main(void){


int a,b,d,r;


double f;


 scanf("%d %d",&a,&b);


 d=a/b;


r=a%b;


f=(double)a/(double)b;


 printf("%d %d %lf\n",d,r,f);


return 0;


}

Measured memory_bytes: 636
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <fstream>

using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007
#define P pair<ll, ll>

struct LazySegTree {
	ll sz;
	vector<ll> dat, lazy;
	LazySegTree(ll n) {
		sz = 1;
		while (sz < n)sz *= 2;
		dat.resize(2 * sz - 1);
		lazy.resize(2 * sz - 1);
	}
	void eval(ll k, ll l, ll r) {
		if (lazy[k] != 0) {
			dat[k] += lazy[k];
			if (r - l > 1) {
				lazy[k * 2 + 1] += lazy[k];
				lazy[k * 2 + 2] += lazy[k];
			}
			lazy[k] = 0;
		}
	}
	void update(ll a, ll b, ll x, ll k = 0, ll l = 0, ll r = -1) {
		if (r < 0)r = sz;
		eval(k, l, r);
		if (r <= a or b <= l) return;
		if (a <= l and r <= b) {
			lazy[k] += x;
			eval(k, l, r);
		}
		else {
			update(a, b, x, k * 2 + 1, l, (l + r) / 2);
			update(a, b, x, k * 2 + 2, (l + r) / 2, r);
			dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
		}
	}
	ll query(ll a, ll b, ll k = 0, ll l = 0, ll r = -1) {
		if (r < 0)r = sz;
		if (r <= a or b <= l)return INF;
		eval(k, l, r);
		if (a <= l and r <= b) return dat[k];
		ll q1, q2;
		q1 = query(a, b, k * 2 + 1, l, (l + r) / 2);
		q2 = query(a, b, k * 2 + 2, (l + r) / 2, r);
		return min(q1, q2);
	}
};
int main() {
	ll n, q;
	cin >> n >> q;
	LazySegTree s(n * 2);
	REP(i, q) {
		ll t;
		cin >> t;
		if (t == 0) {
			ll a, b, c;
			cin >> a >> b >> c;
			b++;
			s.update(a, b, c);
		}
		else {
			ll a, b;
			cin >> a >> b;
			b++;
			cout << s.query(a, b) << endl;
		}
	}
}



Measured memory_bytes: 11032
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 999999999
const int mod = 1000000007;
ll cnt = 0;
 
 int main(){
     int n; cin >> n;
     string s[n];
     string t;
     map<char,ll>mp;
     for(int i=0;i<n;i++){
        cin >> t;
        char c = t.at(0);
        mp[c]++;
     }

     ll ans = 0;
     ans += mp['M']*mp['A']*mp['R'];
     ans += mp['M']*mp['A']*mp['C'];
     ans += mp['M']*mp['A']*mp['H'];
     ans += mp['M']*mp['R']*mp['C'];
     ans += mp['M']*mp['R']*mp['H'];
     ans += mp['M']*mp['C']*mp['H'];
     ans += mp['A']*mp['R']*mp['C'];
     ans += mp['A']*mp['R']*mp['H'];
     ans += mp['A']*mp['C']*mp['H'];
     ans += mp['R']*mp['C']*mp['H'];
     
     cout << ans << endl;

 }

Measured memory_bytes: 1024
import sys
sys.setrecursionlimit(1000000)
 
N, u, v = map(int, input().split())
 
u -= 1
v -= 1
 
graph = [[] for i in range(N)]
for i in range(N - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    graph[a].append(b)
    graph[b].append(a)
 
lst = []
def calcDist(cur, par, dst):
    global lst
    lst[cur] = dst
    for neighbour in graph[cur]:
        if neighbour == par: continue
        calcDist(neighbour, cur, dst + 1)
        
uDist = [None for i in range(N)]
vDist = [None for i in range(N)]
lst = uDist
calcDist(u, -1, 0)
lst = vDist
calcDist(v, -1, 0)
 
best = 0
 
for node in range(N):
    if uDist[node] < vDist[node]: best = max(best, vDist[node] - 1)
print(best)

Measured memory_bytes: 101732
<?php


fscanf(STDIN, "%d", $n);
$rod = explode(" ", trim(fgets(STDIN)));

sort($rod);
$th = 0;
$maxno = 0;
$thmap = [];
$start = -1;
$goal = 0;
for($i=0;$i<=1000;$i++){
    if($rod[$th] == $i){
        $start = $th;
        while($rod[$th] == $i){
            $th++;
            if($th == $n){
                $thmap = $thmap +array_fill($i, 1002-$i, [$start, $n-1]);
                break 2;
            }
        }
        $goal = $th-1;
    }
    $thmap[$i] = [$start,$goal];
}
//$thmap[1001] = $n;

$ans = 0;

for($i=0;$i<$n-2;$i++){
    for($j=$i+1;$j<$n-1;$j++){
        $min = max(0, $rod[$j] - $rod[$i] + 1);
        $max = min($rod[$j] + $rod[$i] - 1, 1000);
        $start = max($thmap[$min][0], $j+1);
        $goal = $thmap[$max][1];
        $ans += max(0,($goal - $start) + 1 );
    }
}

echo $ans;


Measured memory_bytes: 4856
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define call(var) cout<<#var<<"="<<var<<endl;
#define dup(x,y) (((x)+(y)-1)/(y))
using ll=long long;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;
const int INTMAX = 2147483647;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

int main(){
    int k;cin >> k;
    queue<ll> q;
    vl con;
    for(int i=1;i<10;++i){
        q.push(i);
        con.push_back(i);
    }
    while(con.size()<=100000){
        ll v = q.front();
        q.pop();
        ll t = v%10;
        if(t==0){
            con.push_back(v*10);
            q.push(v*10);
            con.push_back(v*10+1);
            q.push(v*10+1);
        }else if(t==9){
            con.push_back(v*10+8);
            q.push(v*10+8);
            con.push_back(v*10+9);
            q.push(v*10+9);
        }else{
            for(int i=-1;i<=1;++i){
                con.push_back(v*10 + t+i);
                q.push(v*10 + t+i);
            }
        }
    }
    sort(con.begin(),con.end());
    cout << con[k-1] << endl;
}

Measured memory_bytes: 1620
a,b,c,x,y = map(int,input().split())
if (a+b <= 2*c) :
  print(a*x+b*y)
if (a+b > 2*c) :
  if (x == y) :
    print(2*c*x)
  if (x > y) :
    print(min([2*c*y + a*(x-y),2*c*x]))
  if (x < y) :
    print(min([2*c*x + b*(y-x),2*c*y]))


Measured memory_bytes: 3060
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <cmath>
#include <chrono>
using namespace std;

int main(int argc, const char * argv[]) {
    
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int N;
    cin >> N;
    
    int64_t power = 1;
    for (int i = 0; i < N; i++) {
        power *= (i + 1);
        power %= (int)1e+9 + 7;
    }
    
    cout << power <<endl;
    
    return 0;
}


Measured memory_bytes: 256
/*
神题
从叶结点向根贪心，每个点维护二进制集合，贪心合并子树
答案O(logn)-->O(n*logn)
*/
#include<cstdio>
#include<cstring>
#include<algorithm>
#define N 100010
using namespace std;

struct edge{int x, y, next;}a[N*2];
int n, bin[40], mx, f[N], sum[40], l, p[N], x, y;

inline void add(int x, int y){a[++l].x=x; a[l].y=y; a[l].next=p[x]; p[x]=l;}

inline void dfs(int x, int fa){
	for(int i=p[x]; i; i=a[i].next)if(fa!=a[i].y)dfs(a[i].y, x);
	memset(sum, 0, sizeof(sum));
	for(int i=p[x]; i; i=a[i].next)if(fa!=a[i].y){
		for(int j=0; j<=30; j++)if(f[a[i].y]&bin[j])sum[j]++;
	}
	int now=31; f[x]=0;
	for(int i=30; i>=0; i--){
		if(!sum[i]){for(int j=i+1; j<=now-1; j++)f[x]+=bin[j]; now=i;}
		if(sum[i]>=2)break;
	}
	f[x]+=bin[now];
}

int main(){
	scanf("%d", &n);
	bin[0]=1; for(int i=1; i<=30; i++)bin[i]=bin[i-1]<<1;
	l=0; memset(p, 0, sizeof(p));
	for(int i=1; i<=n-1; i++){scanf("%d%d", &x, &y); add(x, y); add(y, x);}
	dfs(1, 0);
	memset(sum, 0, sizeof(sum));
	for(int i=0; i<=30; i++)if(f[1]&bin[i])sum[i]++;
	mx=-1; for(int i=0; i<=30; i++)if(sum[i])mx=i;
	printf("%d", mx);
	return 0;
}

Measured memory_bytes: 4992
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????

		Scanner scan = new Scanner(System.in);

		int intSumNum = 0;

		int r = scan.nextInt();
		int c = scan.nextInt();
		int[][] ary = new int[r+1][c+1];

		//r*c
		for(int i =0; i < r ; i++){

			for(int j = 0; j < c; j++ ){

				ary[i][j] = scan.nextInt();
			}
		}
		for(int k = 0; k < r + 1; k++){
			for(int l = 0; l < c + 1; l++){
				//?????????????????????????????????????????????
				if(l != c && k != r){
					ary[k][c] += ary[k][l];
				}
				//???????????????????????????
				if(k != r){
					ary[r][l] += ary[k][l];
				}

				System.out.print(ary[k][l]);
				if(l != c){
					System.out.print(" ");
				}
			}
			System.out.println();
		}
	}
}

Measured memory_bytes: 39636
class UnionFind_PathCompression
  attr_reader :rank, :parent, :value
  attr_writer :rank, :parent

  def initialize(x)
    @value = x
    @rank = 0
    @parent = self
  end

  def ==(obj)
    @value == obj.value
  end

  def find
    return self if self.parent == self
    root = self.parent.find
    self.parent = root
    root
  end

  def union(y)
    xr = find; yr = y.find
    return self if xr == yr
    if xr.rank >= yr.rank
      yr.parent = xr
      xr.rank += 1
      self
    else
      y.union(self)
    end
  end
end

N,M = gets.split.map(&:to_i)
langs = (0..M).map{ nil }
UF = (1..N).map{ |n| UnionFind_PathCompression.new(n) }

(1..N).each { |k|
  ls = gets.split.map(&:to_i)[1..-1]
  u1 = UF[k-1]
  ls.each{ |l|
    if u2 = langs[l]
      u1.union(u2)
    end
    langs[l] = langs[l] ? langs[l].union(u1).find : u1
  }
}

puts UF.map{ |u| u.find.value }.uniq.size == 1 ? "YES" : "NO"


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

typedef pair<int,int> pint; // (w, d)
bool cmp(pint a, pint b) { return a.first * a.second < b.first * b.second; }

int main() {
  int N, W, D;
  while (cin >> N >> W >> D, W) {
	vector<pint> res; res.push_back(pint(W, D));
	for (int xxx = 0; xxx < N; ++xxx) {
	  int p, s; cin >> p >> s; --p;
	  pint cur = res[p]; res.erase(res.begin() + p);
	  pint ne[2];
	  for (int i = 0; i < 2; ++i) ne[i].first = cur.first, ne[i].second = cur.second;
	  s %= (cur.first + cur.second) * 2;
	  if (s <= cur.first) ne[0].first = s, ne[1].first = cur.first - ne[0].first;
	  else if (s - cur.first <= cur.second) ne[0].second = s-cur.first, ne[1].second = cur.second - ne[0].second;
	  else if (s-cur.first-cur.second <= cur.first) ne[0].first = cur.first - (s-cur.first-cur.second), ne[1].first = cur.first - ne[0].first;
	  else ne[0].second = (cur.first+cur.second)*2 - s, ne[1].second = cur.second - ne[0].second;
	  if (ne[0] < ne[1]) res.push_back(ne[0]), res.push_back(ne[1]);
	  else res.push_back(ne[1]), res.push_back(ne[0]);
	}
	sort(res.begin(), res.end(), cmp);
	for (int i = 0; i < res.size(); ++i) {
	  cout << res[i].first * res[i].second;
	  if (i != (int)res.size()-1) cout << " ";
	} 
	cout << endl;
  }
}



Measured memory_bytes: 3076
"""
l = input().split(" ")
w = int(l[0])
h = int(l[1])
n = int(l[2])

array = [[0 for i in range(h)] for j in range(w)]

for i in range(n):
	l = input().split(" ")
	x = int(l[0]) - 1
	y = int(l[1]) - 1
	for i in range(3):
		for j in range(3):
			if x+j-1 >=0 and x+j-1<w and y+i-1 >=0 and y+i-1<h:
				array[x+j-1][y+i-1] += 1

ans = [0 for i in range(10)]

for i in range(h-2):
	for j in range(w-2):
		ans[array[j+1][i+1]] += 1

for a in ans:
	print(a)

"""

l = input().split(" ")
w = int(l[0])
h = int(l[1])
n = int(l[2])

array = dict()

for i in range(n):
	l = input().split(" ")
	x = int(l[0])
	y = int(l[1])
	for i in range(3):
		if y-i < 1 or y-i > h-2:
			continue
		for j in range(3):
			if x-j < 1 or x-j > w-2:
				continue
			if (x-j, y-i) in array:
				array[(x-j, y-i)] +=1
			else:
				array[(x-j, y-i)] = 1

ans = [0] * 10
ans[0] = (h-2) * (w-2)
 
for i in array:
    ans[array[i]] += 1
    ans[0] -= 1

for i in range(10):
    print(ans[i])

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

string S;
int N;

void input() {
    cin >> N;
    cin >> S;
}

void solve() {
    input();
    string tmp = "No";
    int K = N / 2;
    if(N % 2 == 0 && S.substr(0, K) == S.substr(K, K)) tmp = "Yes";
    cout << tmp << endl;
    return;
}

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

Measured memory_bytes: 256
n,k=[int(x) for x in input().split()]
infy=float('inf')
arr=[int(x) for x in input().split()]

val=[infy]*(n)
val[0]=0
for i in range(0,n-1):
    for j in range(1,k+1):
        if i+j < n:
            val[i+j]=min(val[i+j],abs(arr[i+j]-arr[i])+val[i])


print(val[n-1])




Measured memory_bytes: 55264
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

const ll MOD = 1000000007;
ll H, W, K;
ll dp[2][10];

void add(ll &x, ll y) {
  x += y;
  x %= MOD;
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> H >> W >> K;
  if (W == 1) {
    cout << 1 << endl;
    return 0;
  }
  W--;
  dp[0][0] = 1;
  for (int i = 0; i < H; i++) {
    for (int ms = 0; ms < 1 << W; ms++) {
      int no = 0;
      for (int j = 0; j+1 < W; j++) {
        if ((ms >> j & 1) && ((ms >> (j+1)) & 1)) no = 1;
      }
      if (no) continue;
      // if (i == 0) cout << ms << endl;
      for (int j = 0; j <= W; j++) {
        if (j+1 <= W && ms >> j & 1) {
          add(dp[1][j+1], dp[0][j]);
        } else if (j && ((ms >> (j-1)) & 1)) {
          add(dp[1][j-1], dp[0][j]);
        } else {
          add(dp[1][j], dp[0][j]);
        }
      }
    }
    swap(dp[0], dp[1]);
    fill_n((ll*)dp[1], 10, 0);
  }
  cout << dp[0][K-1] << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
char memo1[256], memo2[256];
int main(void) {
  int n;
  string s[64];
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s[i];
    for (int j = 0; j < s[i].size(); j++) {
      if (i == 0)
        memo1[s[i][j]]++;
      else
        memo2[s[i][j]]++;
    }
    if (i != 0) {
      for (int j = 0; j < 256; j++) {
        memo1[j] = min(memo1[j], memo2[j]);
        memo2[j] = 0;
      }
    }
  }

  for (int i = 0; i < 256; i++) {
    for (int j = 0; j < memo1[i]; j++)
      cout << (char)i;
  }
  cout << '\n';
}


Measured memory_bytes: 384