akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>  // ver2.3.1
#define int long long
#define endl "\n"
#define ALL(v) (v).begin(),(v).end()
#define COUNT(a,k) upper_bound(ALL(a),k)-lower_bound(ALL(a),k)
#define BIGGER(a,k) a.end()-upper_bound(ALL(a),k)
#define SMALLER(a,k) lower_bound(ALL(a),k)-a.begin()
#define Vi vector<int>
#define VVi vector<Vi>
#define Vs vector<string>
#define Pii pair<int,int>
#define VPii vector<Pii>
#define Tiii tuple<int,int,int>
#define PQi priority_queue<int>
#define PQir priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define itos to_string
#define stoi stoll
#define FI first
#define SE second
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define cyes cout<<"yes"<<endl
#define cno cout<<"no"<<endl
#define _ <<' '<<
#define sortr(v) sort(v,greater<>())
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repeq(i,a,b) for(int i=a;i<=b;i++)
#define repreq(i,a,b) for(int i=a;i>=b;i--)
#define leng(n) (int)(log10(n)+1)
#define dem(a,b) ((a+b-1)/(b))
#define Vin(a) rep(iI,0,a.size())cin>>a[iI]
#define Vout(a) rep(lZ,0,a.size()-1)cout<<a[lZ]<<' ';cout<<a.back()<<endl
#define VVout(a) rep(lY,0,a.size()){if(!a[lY].empty()){Vout(a[lY]);}else cout<<endl;}
#define VPout(a) rep(lX,0,a.size())cout<<a[lX].FI<<' '<<a[lX].SE<<endl
#define Verr(a) rep(iZ,0,a.size()-1)cerr<<a[iZ]<<' ';cerr<<a.back()<<endl
#define VVerr(a) rep(J,0,a.size()){if(!a[J].empty()){Verr(a[J]);}else cerr<<'.'<<endl;}
#define VPerr(a) rep(iX,0,a.size())cerr<<a[iX].FI<<' '<<a[iX].SE<<endl
#define INF 3000000000000000000  //  3.0*10^18(MAXの1/3くらい)
#define MAX LLONG_MAX
#define PI 3.141592653589793238462
#define MOD 1000000007  //  10^9 + 7
using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm
int mypow(int x, int n, int m){  //  累乗x^n(mod m)  O(log(n))
if(n==0)return 1;if(n%2==0)return mypow(x*x%m,n/2,m);else return x*mypow(x,n-1,m)%m;}
int scomb(int n, int r){if((n-r)<r)r=n-r;  //  nCr (小さい場合)
int a=1;for(int i=n;i>n-r;--i){a=a*i;}for(int i=1;i<r+1;++i){a=a/i;}return a;}
int comb(int n, int r){if((n-r)<r)r=n-r;  //  nCr (%MOD)
int a=1;for(int i=n;i>n-r;--i){a=a*i%MOD;}for(int i=1;
i<r+1;++i){a=a*mypow(i,MOD-2,MOD)%MOD;}return a%MOD;}
int stpow(int n){  //  階乗(%MOD)
if(n==0)return 1;int a=1;rep(i,1,n+1)a=a*i%MOD;return a;}
Vi stpowV(){Vi a(100001);  //  階乗配列(%MOD)
a[0]=1;repeq(i,1,100000)a[i]=a[i-1]*i%MOD;return a;}
void press(auto &v){v.erase(unique(ALL(v)),v.end());}  //  圧縮



signed main() {
  cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(12);
  string s;
  cin >> s;
  int n = s.size();
  
  Vi a(0);
  
  rep(i,0,n-1) {
    if(s[i]!=s[i+1]){
      a.pb(max(i+1,n-i-1));
    }
  }
  if(a.size()!=0) cout << *min_element(ALL(a)) << endl;
  else cout << n << endl;
  return 0;
}

Measured memory_bytes: 972
#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif

#include <bits/stdc++.h>

using namespace std;

int main()
{
	std::ios::sync_with_stdio(false);
	string s;
	cin >> s;
	int r = 0;
	for (char c : s) {
		r += (c - '0');
	}
	cout << ((r % 9 == 0) ? "Yes" : "No") << endl;
	return 0;
}


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

#define     fast()              ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); 
#define     ll                  long long int
#define     test()              ll t; cin>>t; while(t--) 
#define     lp0(i,begin,end)    for(ll i=begin;i<end;i++)
#define     lp1(i,begin,end)    for(ll i=begin;i<=end;i++)
#define     rlp(i,begin,end)    for(ll i=end;i>=begin;i--)
#define     prec(n)             fixed<<setprecision(n)
#define     initial(a,i)        memset(a,i,sizeof(a))
#define     pb                  push_back
#define     PI                  3.1415926535897932384626433832795
#define     MOD                 1000000007
#define     F                   first
#define     S                   second
#define     all(a)              (a).begin(),(a).end()
#define     BPC(x)              __builtin_popcountll(x)
#define     gcd(a,b)            __gcd(a,b)

ll gcd(ll a,ll b) {if (a==0) return b;return gcd(b%a,a);}

ll power(ll x,ll n)
{
    ll result = 1;
    while (n)
    {
        if (n & 1)
            result = result * x;
        n = n / 2;
        x = x * x;
    }
    return result;
}
// Solution Function
void solution(ll compte)
{
    // cout<<compte<<"\n";
    ll n,a,b;
    cin>>n;
    if(n==1)cout<<"Hello World"<<endl;
    else
     {
        cin>>a>>b;
        cout<<a+b<<endl;
    }
}

// Driver Function
int main()
{
    ll compte = 1;
    //test()
    //{
        solution(compte);
        compte++;
    //}
    return 0;
}


Measured memory_bytes: 3608
#include <iostream>

#define REP(i, a, b) for ( int i = (a); i < (b); i++ )
#define REVREP(i, a, b) for ( int i = (a); i > (b); i--)
#define DEBUG_INT(var) printf("the value of "#var" is %d\n", var)

using namespace std;

int A, B;

int solve() {
	int ans = 0;
	int sum = 1;

	while ( sum < B ) {
		ans += 1;
		sum = sum + A - 1; 
	}
	return ans;

}

int main(void) {
	
    scanf("%d %d", &A, &B);

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

	return 0;
}


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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))
#define uniq(v) (v).erase(unique(all(v)), (v).end())

using namespace std;

using i32 = int;
using i64 = long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T power(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
template <typename T, typename S> istream& operator>>(istream &is, pair<T, S> &p) { is >> p.first >> p.second; return is; }
template <typename T, typename S> ostream& operator<<(ostream &os, pair<T, S> &p) { cout << p.first << ' ' << p.second; return os; }



void solve() {
  i64 n, s; cin >> n >> s;
  if (n == s) {
    cout << n + 1 << '\n';
    return;
  }

  function<i64(i64, i64)> f = [&](i64 b, i64 n) {
    if (n < b) return n;
    return f(b, n / b) + (n % b);
  };

  for (i64 b = 2; b * b <= n; b++) {
    i64 sum = f(b, n);
    if (sum == s) {
      cout << b << '\n';
      return;
    }
  }

  i64 ans = 1e18;
  for (i64 p = 1; p * p < n; p++) {
    i64 q = s - p;
    i64 b = (n - q) / p;
    if (b <= 1) continue;

    i64 sum = f(b, n);
    if (sum == s) amin(ans, b);
  }
  if (ans == 1e18) {
    cout << -1 << '\n';
    return;
  }
  cout << ans << '\n';
}


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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm( a, b ) (a)/__gcd((a),(b))*(b)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 200005;

const int dx[] = {0, -1, 1, 0};
const int dy[] = {-1, 0, 0, 1};

LL fac[SIZE], finv[SIZE], inv[SIZE];
void combInit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for( int i = 2; i < SIZE; ++i ) {
        fac[i] = (fac[i - 1] * i) % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = (finv[i - 1] * inv[i]) % MOD;

    }
}

LL comb(int n, int k) {
    if( n < k ) return 0;
    if( n < 0 || k < 0 ) return 0;
    return (fac[n] * (finv[k] * finv[n - k] % MOD)) % MOD;

}

vector< int > Div( int n ) {
    vector< int > ret;
    for( int i = 1; i * i <= n; ++i ) {
        if( n % i == 0 ) {
            ret.pb( i );

            if( i * i != n ) ret.pb( n / i );
        }
    }
    sort( all( ret ) );
    return ret;
}

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

    int r, d, x;
    cin >> r >> d >> x;
    for( int i = 1; i <= 10; ++i ) {
        x = r * x - d;
        cout << x << endl;

    }
    return 0;
}



Measured memory_bytes: 256
def f(a,b):
    x,y=a,b
    while b>0:
        a,b=b,a%b
    return (x//a)*y
s=1    
N=int(input())
for i in range(N):
    a=s
    b=int(input())
    s=f(a,b)
print(s)    
    

Measured memory_bytes: 2940
cnt = 0
while True:
    n = input()

    if n == 0:
        break

    if cnt > 0:
        print

    y10, y50, y100, y500 = map(int, raw_input().split())
    Sum = 10 * y10 + 50 * y50 + y100 * 100 + y500 * 500

    while Sum - 500 >= n:
        Sum -= 500
        y500 -= 1
    while Sum - 100 >= n:
        Sum -= 100
        y100 -= 1
    while Sum - 50 >= n:
        Sum -= 50
        y50 -= 1
    while Sum - 10 >= n:
        Sum -= 10
        y10 -= 1

    if y10 > 0:
        print 10, y10
    if y50 > 0:
        print 50, y50
    if y100 > 0:
        print 100, y100
    if y500 > 0:
        print 500, y500

    cnt += 1

Measured memory_bytes: 6292
//In The Name of Allah
#include <bits/stdc++.h>

using namespace std;

const int N = 1e5 + 10;

int c[N];
vector < pair < int , int > > adj[N];

void dfs(int v, int p, int h){
    c[v] = h;
    for (auto e : adj[v]){
        int u = e.first, w = e.second;
        if (u == p)
            continue;
        dfs(u, v, (h + w) % 2);
    }
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n;
    cin >> n;
    for (int i = 1; i < n; i ++){
        int u, v, w;
        cin >> u >> v >> w;
        adj[u].push_back(make_pair(v, w));
        adj[v].push_back(make_pair(u, w));
    }
    dfs(1, 0, 0);
    for (int i = 1; i <= n; i ++)
        cout << c[i] << '\n';
    return 0;
}

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

int main(){
    int k, s;
    cin>>k>>s;
    int ans=0;
    for(int i=0;i<=k;i++){
        for(int j=0;j<=k;j++){
            if(s-i-j<=k&&s-i-j>=0){ans++;}
        }
    }
    cout<<ans<<endl;
}


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

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

    vector<int> tim(510);//かかる時間
    vector<int> start(510);//開通式後の発車時間
    vector<int> ival(510);//発車間隔

    for(int i=0;i<N-1;i++){
        cin >> tim[i] >> start[i] >> ival[i];
    }
    
    int sumt;
    for(int i=0;i<N-1;i++){
        sumt=start[i]+tim[i];
        for(int j=i+1;j<N-1;j++){
           if(sumt<start[j])sumt=start[j];
           else if((sumt-start[j])%ival[j]!=0){
               sumt+=ival[j]-(sumt-start[j])%ival[j];
           }
           sumt+=tim[j];
        }
        cout << sumt << endl;
    }
    cout << 0 << endl;
    return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"strings"
)

func main() {
	var (
		height, width int
		row           string
		isAllBlank    bool
	)
	fmt.Scan(&height, &width)

	matrix := make([][]string, height)
	for h := 0; h < height; h++ {
		fmt.Scan(&row)
		matrix[h] = strings.Split(row, "")
	}

	// delete col is all blank
	for w := 0; w < width; w++ {
		isAllBlank = true
		for h := 0; h < height; h++ {
			if matrix[h][w] == "#" {
				isAllBlank = false
				break
			}
		}

		if isAllBlank {
			for h := 0; h < height; h++ {
				matrix[h][w] = ""
			}
		}
	}

	for h := 0; h < height; h++ {
		row = strings.Join(matrix[h], "")
		if strings.Count(row, "#") >= 1 {
			fmt.Println(row)
		}
	}
}


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

#define int long long int
#define double long double
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define rep(i,a,b) for (int i=a; i<b; ++i)
#define dbg(x) { cerr<<#x<<": "<<x<< endl; }
#define dbg2(x,y) { cerr<<#x<<": "<<x<<" , "<<#y<<": "<<y<<endl; }
#define dbg3(x,y,z) { cerr<<#x<<": "<<x<<" , "<<#y<<": "<<y<<" , "<<#z<<": "<<z<<endl; }
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
const int inf = INT_MAX;
const double eps = 0.0000001;
const double PI = acos(-1.0);
const int MOD = 1e9+7;
const int N  = 1e5+5;

int s[N],h[N];

signed main(){
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
    #endif  
    IOS;

    s[1] = 0;
    int n;
    cin >> n;
    for (int i = 1; i <= n; ++i)
    {
        cin >> h[i];
    }
    s[2] = abs(h[2]-h[1]);
    s[3] = abs(h[3]-h[1]);
    for (int i = 3; i <= n; i++) {
        s[i]=min(s[i-1]+abs(h[i]-h[i-1]),s[i-2]+abs(h[i]-h[i-2]));
    }
    cout << s[n];
    return 0;
}

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

vector<int> is_prime;

void sieve(int n) {
	is_prime=vector<int>(n);
	for (int i = 2; i < n; ++i)
		is_prime[i] = i;
	for (int i = 2; i*i < n; ++i)
		if (is_prime[i])
			for (int j = i*i; j < n; j+=i)
				is_prime[j] = 0;
}


//int map[1002][1002];//IDをいれる
vector<vector<int> > map;
int id_to_x[1000002];
int id_to_y[1000002];
const int dx[4]={0,-1,0,1};
const int dy[4]={-1,0,1,0};

const int next_dx[3]={-1,0,1};

pair<int,int> dp[1002][1002];

int m,n;

pair<int,int> calc(int x,int y){
	if(map[y][x]<0) return pair<int,int>(0,0);
	if(map[y][x]>m) return pair<int,int>(0,0);

	if(dp[y][x].first>0) return dp[y][x];

	int max_num=0,max_prime=0;
	for(int r=0;r<3;r++){
		pair<int,int> got=calc(x+next_dx[r],y+1);
		if(got.first>max_num){
			max_num=got.first;
			max_prime=got.second;
		}else if(got.first==max_num){
			max_prime=max(max_prime,got.second);
		}
	}
	if(map[y][x]<=1000000 && is_prime[map[y][x]]!=0){
		max_num++;
		if(max_prime==0) max_prime=map[y][x];
	}
	dp[y][x]=pair<int,int>(max_num,max_prime);
	return pair<int,int>(max_num,max_prime);
}

int main()
{
	map.resize(1002,vector<int>(1002));
	sieve(1000001);
	for(int y=0;y<1002;y++)for(int x=0;x<1002;x++){
		map[y][x]=-1;
		dp[y][x].first=-1;
	}
	int x=500,y=500;
	int id=1;
	map[y][x]=id;
	id_to_x[1]=x;
	id_to_y[1]=y;
	int d=0;
	id++;
	while(id<=1000000){
		for(int r=0;r<4;r++){
			int nd=d;
			if(r==0) nd--;
			else if(r==3) nd++;
			for(int k=0;k<nd;k++){
				if(id>1000000) break;
				x+=dx[r];
				y+=dy[r];
				map[y][x]=id;
				id_to_x[id]=x;
				id_to_y[id]=y;
				id++;
			}
		}
		d+=2;
	}
	while(cin>>m>>n){
		if(m==0 && n==0) return 0;
		for(int y=0;y<1002;y++)for(int x=0;x<1002;x++){
			dp[y][x].first=-1;
		}
		pair<int,int> got=calc(id_to_x[n],id_to_y[n]);
		cout<<got.first<<" "<<got.second<<endl;
	}
	return 0;
}

Measured memory_bytes: 24576
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var firstLine = int.Parse(Console.ReadLine());
            if (firstLine == 1)
            {
                Console.Write("Hello World");
            }
            else
            {
                var A = int.Parse(Console.ReadLine());
                var B = int.Parse(Console.ReadLine());
                Console.Write(A + B);
            }

        }
    }
}


Measured memory_bytes: 13140
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
long long int INF = 1001001001001001LL;
int inf = 1000000007;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;

template<typename T1,typename T2>inline void chmin(T1 &a,const T2 &b){if(a>b) a=b;}
template<typename T1,typename T2>inline void chmax(T1 &a,const T2 &b){if(a<b) a=b;}

#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()

/* do your best */

int main() {
 
  int n; cin >> n;
  int e = 1e9 + 1;
  int id = -1;
  for (int i = 1; i <= n; i++) {
    int a; cin >> a;
    if (a < e) {
      e = a;
      id = i;
    }
  }

  cout << id << endl;
  return 0;
}



Measured memory_bytes: 3072
n,m=map(int,input().split())
a=list()
b=list()
for i in range(n):
    a.append(list(input()))
for i in range(m):
    b.append(list(input()))

for g in range(n-m+1):
    for h in range(n-m+1):
        p=0
        for i in range(m):
            p+=a[g+i][h:h+m]==b[i]
        if p==m:
            print('Yes')
            exit()
print('No')

Measured memory_bytes: 3064
#include <queue>
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
struct state {
	int cost, pos, rem;
	state() : cost(0), pos(0), rem(0) {};
	state(int c, int p, int r) : cost(c), pos(p), rem(r) {};
};
bool operator<(const state& s1, const state& s2) {
	return s1.cost < s2.cost;
}
bool operator>(const state& s1, const state& s2) {
	return s1.cost > s2.cost;
}
int n, m, a, b;
int main() {
	cin >> n >> m;
	vector<int> c(n), t(n);
	vector<vector<int> > G(n);
	for (int i = 0; i < n; i++) cin >> c[i] >> t[i];
	for (int i = 0; i < m; i++) {
		cin >> a >> b; a--, b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	priority_queue<state, vector<state>, greater<state> > que; que.push(state(c[0], 0, t[0]));
	vector<vector<int> > dist(n, vector<int>(n + 1, 1999999999)); dist[0][t[0]] = c[0];
	while (!que.empty()) {
		state s = que.top(); que.pop();
		for (int i : G[s.pos]) {
			if (s.rem > 0) {
				if (dist[i][s.rem - 1] > s.cost) {
					dist[i][s.rem - 1] = s.cost;
					que.push(state(s.cost, i, s.rem - 1));
				}
				if (dist[i][t[i]] > s.cost + c[i]) {
					dist[i][t[i]] = s.cost + c[i];
					que.push(state(s.cost + c[i], i, t[i]));
				}
			}
		}
	}
	cout << *min_element(dist[n - 1].begin(), dist[n - 1].end()) << endl;
	return 0;
}

Measured memory_bytes: 101168
#include<bits/stdc++.h>
using namespace std;
#define int long long

#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif

signed main(){

  int n,a,b; cin >> n >> a >> b;
  vector<int> v(n);
  map<int,int> mp;
  for(int i = 0; i < n; i++){
    cin >> v[i];
    mp[v[i]]++;
  }
  sort(v.rbegin(),v.rend());

  int res = 0;
  for(int i = 0; i < a; i++){
    res += v[i];
  }
  printf("%.6f\n",(double)res/a);

  vector< vector<int> > dp; // dp[n][r] = nCr
  dp.resize(n+1,vector<int> (n+1));
  for(int i = 0; i <= n; i++){
    dp[i][0] = 1;
    for(int j = 1; j <= i; j++){
      dp[i][j] = dp[i-1][j-1] + dp[i-1][j];
    }
  }
  int ans = 0;
  for(int i = a; i <= b; i++){
    map<int,int> mp2;
    int res2 = 0;
    for(int j = 0; j < i; j++){
      mp2[v[j]]++;
      res2 += v[j];
    }
    if(res * i != res2 * a) continue;
    int res = 1;
    for(auto p : mp2){
      res *= dp[mp[p.first]][p.second];
    }
    ans += res;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define ll long long 
#define ret return
#define PB push_back
#define lc 2 * v
#define rc 2 * v + 1
#define mid (s + e) / 2
#define pii pair <int,  int>
#define pll pair <long long , long long>  
#define FAST ios::sync_with_stdio(false);cin.tie(0);
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2")

const int maxn = 2e6;

bool notprime[maxn + 100];
ll cnt[maxn + 100];
ll n;
vector <ll> divi;

inline void getdiv() {
    notprime[1] = 1;
    ll k = n;
    for (int i = 2; i < maxn; ++i) {
        if(!notprime[i]) {
            for (int j = i + i; j < maxn; j += i) {
                notprime[j] = 1;
            }
            if(k % i == 0) {divi.PB(i);}
            while(k % i == 0) {
                cnt[i]++;
                k /= i;
            }
        }
    }
    if(k > 1) {
        divi.PB(k);
    }
}

int main() {
    FAST
    cin >> n;
    getdiv();
    ll ans = 0;
    for (auto u : divi) {
        if(u >= maxn) {
            ans++;
        }
        else {
            ll val = cnt[u];
            ll cnt = 1;
            while(val >= cnt) {
                val -= cnt;
                cnt++; ans++;
            }
        }
    }
    cout << ans << endl;
}

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

int gcd(int x,int y){
  return y ? gcd(y,x%y) : x;
}

int main(){
  int n,i,co;
  cin >> n;
  vector<int> a(n);
  for(i=0;i<n;++i){
    cin >> a[i];
  }
  vector<int> l(n),r(n);

  for(i=0;i<n-1;++i){
    l[i+1]=gcd(l[i],a[i]);
  }
  for(i=n-1;i>=1;--i){
    r[i-1]=gcd(r[i],a[i]);
  }
  int ans=1;
  for(i=0;i<n;++i){
    ans=max(ans,gcd(l[i],r[i]));
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1000000007;
const ld PI = acos(-1);  
const ld EPS = 0.0000000001;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define REP(i, n) for(ll i=0; i<(ll)(n); i++)
#define REPD(i, n) for(ll i=n-1; 0<=i; i--)
#define FOR(i, a, b) for(ll i=a; i<(ll)(b); i++)
#define FORD(i, a, b) for(ll i=a; (ll)(b)<=i; i--)
#define ALL(x) x.begin(), x.end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main(){
    REP(i, 5){
        ll x;   cin >> x;
        if(x==0){
            cout << i+1 << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 3592
let readInt _ = stdin.ReadLine() |> int64

let modPown m x y =
    seq { 1 .. y }
    |> Seq.fold (fun a _ -> a * x % m) 1L

let mpown = modPown (int64 1e9 + 7L)

()
|> readInt
|> fun x ->
    if x = 1L then
        0L
    else if x = 2L then
        2L
    else
        let a = mpown 10L (int x)
        let b = mpown 9L (int x)
        let c = mpown 8L (int x)
        let ans = (a - b - b + c) % (int64 1e9 + 7L)
        (ans + (int64 1e9 + 7L)) % (int64 1e9 + 7L)
|> printfn "%d"


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

int main(){
    int a , b;
    scanf( "%d%d" , &a , &b );
    if( a >= 13 ) printf( "%d\n" , b );
    else if( a <= 5 ) puts( "0" );
    else printf( "%d\n" , (b/2) );
    return 0;
}

Measured memory_bytes: 256
/*
AizuOnline A2218
Title K poker
*/
#include <stdio.h>
#include <string.h>
//Global data section
int card_point[4][13];
int yaku_point[10];
char hand[20];
int n;
char *nums="A23456789TJQK";
char *suits="SCHD";
//
void print_hand(char *b)
{
        printf("%s\n",b);
}
int conv_num(char c)
{
        return(strchr(nums,c)-nums+1);
}
int conv_suit(char c)
{
        return(strchr(suits,c)-suits+1);
}

int calc_point(char * b)
{
        int x,y,i,p;
        p=0;
        for(i=0;i<5;i++)
        {
                x=conv_num(b[i*3]);
                y=conv_suit(b[i*3+1]);
                p += card_point[y-1][x-1];
        }
        return(p);
}
int calc_pair(char *b)
{
        int i,j,p;

        p=0;
        for(i=0;i<4;i++)
                for(j=i+1;j<5;j++)
                        p += ((b[i*3]==b[j*3])?1:0);
        return(p);
}
int is_flash(char *b)
{
        int i,j,p;

        p=0;
        for(i=0;i<4;i++)
                for(j=i+1;j<5;j++)
                        p += ((b[i*3+1]==b[j*3+1])?1:0);
        return(p==10);
}
comp_card(void * c1,void * c2)
{
        return(conv_num(((char *)c1)[0])>conv_num(((char *)c2)[0]));
}
is_straight(char * b)
{
        b[14]=' ';b[15]='\0';
        qsort(b,5,3,comp_card);

        //print_hand(b);
        //printf("** %d %d\n",conv_num(b[0]),conv_num(b[12]));
        if(conv_num(b[0])+4==conv_num(b[12]))
                return(1);
        
        if(conv_num(b[0])==1 && conv_num(b[3])==10)
                return(2);

        return(0);
}
int calc_yaku(char * b)
{
        int ret,ret1;

        ret=calc_pair(b);
        if(ret==1)
                return(yaku_point[0]);
        if(ret==2)
                return(yaku_point[1]);
        if(ret==3)
                return(yaku_point[2]);
        if(ret==4)
                return(yaku_point[5]);
        if(ret==6)
                return(yaku_point[6]);
        ret=is_straight(b);
        ret1=is_flash(b);
        if(ret==2 && ret1)
                return(yaku_point[8]);
        if(ret==1 && ret1)
                return(yaku_point[7]);
        if(ret1)
                return(yaku_point[4]);
        if(ret)
                return(yaku_point[3]);
        return(0); //no pair
}
main()
{
        int i,j,k,ret,flag;

        flag=0;

        while(EOF!=scanf("%d",&n) && n)
        {
                if(flag)
                        printf("\n");
                flag=1;
                for(i=0;i<4;i++)
                        for(j=0;j<13;j++)
                                scanf("%d",&card_point[i][j]);

                for(i=0;i<9;i++)
                        scanf("%d ",&yaku_point[i]);
                
                for(j=0;j<n;j++)
                {
                        fgets(hand,20,stdin);

                        //ret=calc_point(hand);
                        ret=calc_yaku(hand)*calc_point(hand);
                        printf("%d\n",ret);
                }
        }
return(0);
}

Measured memory_bytes: 628
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define repi(i, n) for (int i = 0; i <= (n); i++)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
using namespace std;

int main() {
	int N;
	cin >> N;
  vector<int> a(N);
	rep(i,N) cin >> a[i];
	int next = 1;
	int ans = 0;
	rep(i,N){
		if(a[i] == next) next++;
		else ans++;
	}
	cout << ((next == 1) ? -1 : ans) << endl;
}

Measured memory_bytes: 1152
a = gets.split.map(&:to_i)
until (a[0] == 0 && a[1] == 0)
puts "#"*a[1]
(a[0]-2).times{
	puts "#"+"."*(a[1]-2)+"#"
}
puts "#"*a[1]
puts ""
a = gets.split.map(&:to_i)
end

Measured memory_bytes: 6128
#include <stdio.h>

int main(void)
{
	int n;
	int i;
	long long ans;
	
	scanf("%d", &n);
	
	ans = 1;
	for (i = n; i >= 2; i--){
		ans *= i;
	}
	
	printf("%lld\n", ans);
	
	return (0);
}

Measured memory_bytes: 592
O = input()
E = input()
ans = O[0]
ans += E[0] 
if len(O) == len(E):
    for i in range(1, len(O)):
        ans += O[i]
        ans += E[i]
    print(ans)
else:
    for i in range(1, len(O)-1):
        ans += O[i]
        ans += E[i]
    ans += O[-1]
    print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<string>
#define rep(i,N) for(int i=0;i<N;i++)

long long  INF=1000000000000000000;
long long mod=1000000007;
using namespace std;
string s;
string sample[4]={"dream","erase","dreamer","eraser"};
int  s_size[4]={5,5,7,6};
bool ans=true;

bool check(string t,int k){
    bool res=true;
    for(int i=t.size()-1;i>-1;i--){
        if(s[k]!=t[i]){
            res=false;
            break;
            }
        k--;
    }
    return res;
}

void solve(){
    int k=s.size()-1;
    while(k>0){
        rep(i,4){
            if(check(sample[i],k)){
            k-=s_size[i];
            break;
            }
            if(i==3){
                cout<<"NO"<<endl;
                return;
            }
        }
    }
    cout<<"YES"<<endl;
    return;
}


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

 return 0;
}
/*
erasedream

YES


dreameraser

YES

dreamerer

NO
*/

Measured memory_bytes: 512
using System;
using System.IO;
using System.Linq;

namespace ABC121B
{
    class Program
    {
        static void Main(string[] args)
        {
            if (args.Length > 0)
            {
                Console.SetIn(new StreamReader(args[0]));
            }

            new Program().Solve();
        }

        void Solve()
        {
            var temp = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var N = temp[0];
            var M = temp[1];
            var C = temp[2];
            var B = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var count = 0;

            for (int i = 0; i < N; i++)
            {
                var A = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
                var sum = 0;

                for (int j = 0; j < M; j++)
                {
                    sum += A[j] * B[j];
                }

                sum += C;

                if (sum > 0)
                {
                    count++;
                }
            }

            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 13268
import java.util.*;
public class Main {
    public static void main(String[] args) {
        //data input
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();

        int[] list = new int[n];
        for (int i = 0; i < n; i++) {
            list[i] = sc.nextInt();
        }

        //sort
        Arrays.sort(list);

        //search
        long ct = 0;
        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j < n; j++) {
                for (int k = j + 1; k < n; k++) {
                    int a = list[i];
                    int b = list[j];
                    int c = list[k];
                    if (a < b + c && b < a + c && c < a + b) {
                        ct++;
                    } else {
                        break;
                    }
                }
            }// 1 2 3 4 5
        }

        System.out.println(ct);

    }
}

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

#define task "E"
#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i <= (r); ++i)
#define Rep(i, r, l) for (int i = (r); i >= (l); --i)
#define DB(X) { cerr << #X << " = " << (X) << '\n'; }
#define DB1(A, _) { cerr << #A << "[" << _ << "] = " << (A[_]) << '\n'; }
#define DB2(A, _, __) { cerr << #A << "[" << _ << "][" << __ << "] = " << (A[_][__]) << '\n'; }
#define DB3(A, _, __, ___) { cerr << #A << "[" << _ << "][" << __ << "][" << ___ << "] = " << (A[_][__][___]) << '\n'; }
#define PR(A, l, r) { cerr << '\n'; rep(_, l, r) DB1(A, _); cerr << '\n';}
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back
#define pf push_front
#define F first
#define S second
#define by(x) [](const auto& a, const auto& b) { return a.x < b.x; } // sort(arr, arr + N, by(a));
#define next ___next
#define prev ___prev
#define y1 ___y1
#define left ___left
#define right ___right
#define y0 ___y0
#define div ___div
#define j0 ___j0
#define jn ___jn

using ll = long long;
using ld = long double;
using ull = unsigned long long;
using namespace std;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vl;
const int N = 2e5 + 1;
int n;
vi A, B;
int main()
{
#ifdef ONLINE_JUDGE
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
#else
    freopen(task".in", "r", stdin);
    //freopen(task".out", "w", stdout);
#endif
    cin >> n;
    rep(i, 1, n)
    {
        int a, b;
        cin >> a >> b;
        A.eb(a);
        B.eb(b);
    }
    sort(ALL(A));
    sort(ALL(B));
    if (n & 1) cout << (B[n / 2] - A[n / 2] + 1);
    else cout << (B[n / 2 - 1] + B[n / 2] - A[n / 2 - 1] - A[n / 2] + 1);
    return 0;
}


Measured memory_bytes: 5064
fun main(args: Array<String>) {
    abc098c()
}

fun abc098c() {
    val n = readLine()!!.toInt()
    val s = readLine()!!.toCharArray()

    val wests = IntArray(n) { 0 }
    for (i in s.indices) {
        if (i == 0) {
            wests[i] = if (s[i] == 'W') 1 else 0
        } else {
            wests[i] = wests[i - 1] + if (s[i] == 'W') 1 else 0
        }

    }

    val easts = IntArray(n + 1) { 0 }
    for (i in s.size - 1 downTo 0) {
        easts[i] = easts[i + 1] + if (s[i] == 'E') 1 else 0
    }

    val answer = (0 until n).map {
        val left = if (it > 0) wests[it - 1] else 0
        val right = if (it < n) easts[it + 1] else 0
        left + right
    }.min()

    println(answer)
}


Measured memory_bytes: 50220
/**
 * @author      : omgursocute
 * @created     : 10/01/2020
 */

// ===== TEMPLATE STARTS HERE ===== //

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

#define FORa(i, a, b) for(ll i = (a); i <= (b); ++i)
#define FORb(i, a, b, c) for(ll i = (a); i <= (b); i += (c))
#define FORn(i, n) for(ll i = 0; i < (n); ++i)

#define FORra(i, a, b) for(ll i = (a); i >= (b); --i)
#define FORrb(i, a, b, c) for(ll i = (a); i >= (b); i -= (c))
#define FORrn(i, n) for(ll i = ((n)-1); i >= 0; --i)

#define CT(_1, _2, _3, _4, NAME, ...) NAME
#define FOR(...) CT(__VA_ARGS__, FORb, FORa, FORn)(__VA_ARGS__)
#define RFOR(...) CT(__VA_ARGS__, FORrb, FORra, FORrn)(__VA_ARGS__)

#define pll pair<ll, ll>
#define pii pair<int, int>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define pb push_back
#define mp make_pair

#define debug(x) cerr << '[' << #x << ']' << " = " << x << '\n';

namespace bmsk {
	void setbit(ll &x, ll n) {x |= (1 << n);}
	void clrbit(ll &x, ll n) {x &= ~(1 << n);}
	bool chkbit(ll &x, ll n) {return ((x >> n) & 1);}
}
namespace io {
	void openIn(string s) {freopen(s.c_str(), "r", stdin);}
	void openOut(string s) {freopen(s.c_str(), "w", stdout);}
	void setIO(string s = "") {
		ios::sync_with_stdio(false);
		cin.tie(NULL); cout.tie(NULL);
		if(s.size()) {openIn(s + ".inp"); openOut(s + ".out");}
	}
}
namespace fastscan {
#ifdef linux
#define getchar(x) getchar_unlocked(x)
#endif // linux
	template<typename T>
	void scint(T &result) {
		result = 0;
		bool neg = 0;
		char ch; ch = getchar();
		while(true) {
			if(ch == '-') break;
			if(ch >= '0' && ch <= '9') break;
			ch = getchar();
		}
		if(ch == '-') neg = 1;
		else result = ch-'0';
		while(true) {
			ch = getchar(); if(ch < '0' || ch > '9') break;
			result = (result << 3) + (result << 1) + (ch - '0');
		}
		if(neg) result = -result;
	}

	void scstr(string &s) {
		s = "";
		while(true) {
			char c = getchar(); if(c == '\n' || c == ' ') break;
			s += c;
		}
	}

	template<typename T>
	void scld(T &result) {
		char ch; result = 0.;
		bool seen = 0; bool sign = 0;
		char values[20]; bool beforeDot = 1;
		int beforeLength = 0; ld multiplier;

		while(ch = getchar()) {
			if(ch == '-') {sign = 1;continue;}
			if(ch == ' ' || ch == '\n') {if(seen) break;continue;}
			if(ch == '.') {
				beforeDot = 0; multiplier = 1.;
				while(beforeLength) {
					result += (ld)(values[--beforeLength] - '0') * multiplier;
					multiplier *= 10.;
				}
				multiplier = 10.;
			}
			else {
				if(!beforeDot) {
					result += ld(ch - '0') / multiplier;
					multiplier *= 10.;
				}
				else values[beforeLength++] = ch;
				seen = 1;
			}
		}
		if(beforeDot) {
			multiplier = 1;
			while(beforeLength) {
				result += (ld)(values[--beforeLength] - '0') * multiplier;
				multiplier *= 10.;
			}
		}

		if(sign) result *= -1.;
		return;
	}
}
using namespace io;
using namespace bmsk;
using namespace fastscan;

// ======= TEMPLATE ENDS HERE ======= //

int main() {
	setIO("");

	int k, x;
	scint(k); scint(x);
	cout << ((k*500 >= x) ? "Yes" : "No");

	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n , m , a[100005] , now;
long long dp[100005] , inf=1000000007;
signed main(){
  cin>>n>>m;
  for(int i=0;i<m;i++){
    cin>>a[i];
  }
  a[m]=n;
  dp[0]=1;
  for(int i=0;i<n;i++){
    if(i == a[now]){
      now++;
    } else {
      dp[i+1]+=dp[i];
      dp[i+2]+=dp[i];
      dp[i+1]=dp[i+1]%inf , dp[i+2]=dp[i+2]%inf;
    }
  }
  cout<<dp[n]<<endl;
  return(0);
}
  

Measured memory_bytes: 1280
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <complex>
#include <set>
#include <list>
#include <iomanip>
#include <map>
#include <memory.h>



using namespace std;
static const double EPS = 1e-9;
typedef long long ll;
typedef unsigned long long ull;
#define FOR(i,n) for(int i=0;i<(int)n;++i)
#define FORNUM(p, x) for (int num = p; num < (int)(x); ++num)
#define FORI(p, x) for (int i = p; i < (int)(x); ++i)
#define FORJ(p, x) for (int j = p; j < (int)(x); ++j)
#define FORK(p, x) for (int k = p; k < (int)(x); ++k)
#define FORL(p, x) for (int l = p; l < (int)(x); ++l)

typedef pair<int,int>P;
#define INF 1000000000
 
struct edge { 
	int from, to; 
	edge (int from, int to){
		this->from=from; this->to=to;
	}
};
 
int V,E;
typedef vector<edge> edges;
vector<edges> G;



int main(){
	ll n;
	cin >> n;
	ll ans;
	ans = (n / 11)*2;
	n -= (n/11)*11;
	if (n > 6)
		ans += 2;
	else if (n > 0)
		ans++;
		
	cout << ans << endl;
	return 0;
}


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

int main(){
    int n, x, i; cin >> n >> x;
    vector<int> a(n); rep(i,n) cin >> a.at(i);

    sort(a.begin(),a.end());

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

    if(x > 0){ i--;}
    else if(x < 0 && i == 1){ i = 0;}
    else if(x < 0){ i--;}

    cout << i << endl;
}

Measured memory_bytes: 256
def solve(fld)
  $h.times do |y|
    fld[y].each_cons(2).with_index do |(a, b), x|
      if a != b
        fld[y][x], fld[y][x+1] = fld[y][x+1], fld[y][x]
        return true if search(adjust(fld.transpose))
        fld[y][x], fld[y][x+1] = fld[y][x+1], fld[y][x]
      end
    end
  end
  false
end
 
def search(fld)
  return true if fld.flatten.all?{ |v| v == '.' }
  ret_x = count(fld, $w)
  ret_y = count(fld.transpose, $h)
  return false if ret_x.size == 0 && ret_y.size == 0
  ret_x.each do |y, x|
    $n.times{ |i| fld[y][x + i] = nil }
  end
  ret_y.each do |y, x|
    $n.times{ |i| fld[x + i][y] = nil }
  end
  search(adjust(fld))
end
 
def count(fld, r)
  ret = []
  r.times do |y|
    fld[y].each_cons($n).with_index do |ar, x|
      next if ar[0] == '.'
      ret << [y, x] if ar.all?{|v| v == ar[0] }
    end
  end
  ret
end
 
def adjust(fld)
  $w.times do |x|
    fld[x].map! { |v| v if /[A-Z]/ =~ v }.compact!
    ($h - fld[x].size).times{ fld[x].unshift('.') }
  end
  fld
end
 
$h, $w, $n = gets.split.map(&:to_i)
fld = $h.times.map{ gets.chomp.split('') }
puts solve(fld) ? 'YES' : 'NO'

Measured memory_bytes: 9620
N,M,C = map(int, input().split())
B = list(map(int, input().split()))

cnt = 0
for i in range(N):
  A_i = list(map(int, input().split()))
  if sum([x*y for (x,y) in zip(A_i,B)])+C > 0:
    cnt += 1
print(cnt)

Measured memory_bytes: 3064
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <limits.h>    
#define inf 100000000
#define INF 9223372036854775807
#define EPS 1e-10
#define sq(n) ((n)*(n))
#define rep(i,n) for(i=0;i<n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
#define sort(a,n) qsort(a,n,sizeof(TYPE),cmp)
#define sort_r(a,n) qsort(a,n,sizeof(TYPE),cmp_r);
#define chsort(s,n) qsort(s,n,sizeof(char),cmp)
#define chsort_r(s,n) qsort(s,n,sizeof(char),char_cmp_r);
#define TYPE int
#define MEMSET(a) memset(a,0,sizeof(a))
long long mod=(long long)1e09+7;

int in(void){
    int i;scanf("%d",&i);
    return i;
}
long long llin(void){
    long long i;scanf("%lld",&i);
    return i;
}
double din(void){
    double i;scanf("%lf",&i);
    return i;
}
void chin(char s[]){
    scanf("%s",s);
}
void print(int a){
    printf("%d\n",a);
}
void llprint(long long a){
    printf("%lld\n",a);
}
void dprint(double a){
    printf("%.10f\n",a);
}
void print2(int a,int b){
    printf("%d %d\n",a,b);
}
long long max(long long a,long long b){
    return a>b?a:b;
}
long long min(long long a,long long b){
    return a<b?a:b;
}
int cmp(const void *a,const void *b){
    return *(TYPE *)a-*(TYPE *)b;
}
int cmp_r(const void *a,const void *b){
    return *(TYPE *)b-*(TYPE *)a;
}
int char_cmp(const void *a,const void *b){
    return strcmp((char *)a,(char *)b);
}
int char_cmp_r(const void *a,const void *b){
    return strcmp((char *)b,(char *)a);
}
void swap(int *a,int *b){
    int t=*a;
    *a=*b;
    *b=t;
}
long long gcd(long long x,long long y){
    return x%y?gcd(y,x%y):y;
}
long long lcm(long long x,long long y){
    return x/gcd(x,y)*y;
}

// write codes below this
// when you use 'sort',
// make sure TYPE macro is correct
typedef struct{
    int x,y;
}data;

int main(void){
    int m,n,d,i,ax,ay,bx,by;
    data q[200];
    while(1){
        m=in();
        if(!m)break;
        ax=ay=bx=by=q[0].x=q[0].y=0;
        for(i=1;i<m;i++){
            n=in();
            d=in();
            switch(d){
                case 0:q[i].x=q[n].x-1;q[i].y=q[n].y;break;
                case 1:q[i].x=q[n].x;q[i].y=q[n].y-1;break;
                case 2:q[i].x=q[n].x+1;q[i].y=q[n].y;break;
                case 3:q[i].x=q[n].x;q[i].y=q[n].y+1;break;
            }
            ax=max(ax,q[i].x);
            ay=max(ay,q[i].y);
            bx=min(bx,q[i].x);
            by=min(by,q[i].y);
        }
        print2(ax-bx+1,ay-by+1);
    }
    return 0;
}



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

import sys
import copy

sys.setrecursionlimit(1000000)

# input = sys.stdin.readline

# ~~~~~~~~~~~~~~~~~~~~~_(＾～＾ ｣ ∠)_~~~~~~~~~~~~~~~~~~~~~

sx, sy, tx, ty = map(int, input().split())

ans = ""

for i in range(abs(ty - sy)):
    ans += 'U'

for i in range(abs(tx - sx)):
    ans += 'R'

for i in range(abs(ty - sy)):
    ans += 'D'

for i in range(abs(tx - sx)):
    ans += 'L'

ans += 'L'

for i in range(abs(ty - sy) + 1):
    ans += 'U'

for i in range(abs(tx - sx) + 1):
    ans += 'R'

ans += 'D'
ans += 'R'

for i in range(abs(ty - sy) + 1):
    ans += 'D'

for i in range(abs(tx - sx) + 1):
    ans += 'L'

ans += 'U'

print(ans)


Measured memory_bytes: 3444
# A = [list(map(int, input().split())) for _ in range(3)]
# k = int(input())
# B = [int(input()) for _ in range(n)]
# X = list(map(int, input().split()))
# a, b, c = map(int, input().split())
S = input()
n = len(S)
judge = True
if n % 2 != 0:
    print("No")
    exit()
for i in range(0, n, 2):
    if S[i] != "h" or S[i+1] != "i":
        judge = False
print("Yes") if judge else print("No")


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

int main() {
    long long q, h, s, d, n;
    cin >> q >> h >> s >> d >> n;

    if (2 <= n) {
        if (n % 2 == 0) {
            cout << n / 2 * min(min(q * 8, h * 4), min(s * 2, d)) << endl;
        }
        else {
            cout << n / 2 * min(min(q * 8, h * 4), min(s * 2, d)) + min(min(q * 4, h * 2), s) << endl;
        }
    }
    else {
        cout << min(min(q * 4, h * 2), s) << endl;
    }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
 
int main(void){
    int N;
    string C;
    cin >>N;
    cin >>C;
    int ans=0;
    int m=0,n=N-1;

    char ch=C[0];
    for(int i=0;i<N;i++){
        if(ch!=C[i]){
            break;
        }
        if(i==N-1){
            cout <<"0"<<endl;
            return 0;
        }
    }


    while(m<=n){
        for(int k=m;k<N-1;k++){
            if(C[k]=='W'){
                m=k;
                break;
            }
        }
        if(m>=n)break;
        for(int k=n;k>0;k--){
            if(C[k]=='R'){
                n=k;
                break;
            }
        }
        if(m>=n)break;
        if(n!=m){
            ans++;
            m++;n--;
            //C[m]='R';
            //C[n]='W';
        }
    }
    cout <<ans<<endl;
}


Measured memory_bytes: 3700
import java.io.BufferedReader
import java.math.BigDecimal
import java.util.*
import kotlin.system.exitProcess

fun main() = agc047a()

@OptIn(ExperimentalStdlibApi::class)
fun agc047a() = SimpleFastIOWithToken_agc047a().exec {
    val n = readInt()
    val aList = List(n) { readString() }

    tailrec fun Long.divCount(x: Long, count: Int = 0): Int {
        return when {
            x <= 1L -> error("unexpected")
            this % x == 0L -> (this@divCount / x).divCount(x, count + 1)
            else -> count
        }
    }

    val bd1e9 = BigDecimal.valueOf(1_000_000_000)
    val aMultiplied = aList.map { BigDecimal(it).setScale(100).multiply(bd1e9).longValueExact() }
    val appeared = mutableMapOf<Pair<Int, Int>, Long>().withDefault { 0L }

    for (am in aMultiplied) {
        val pair = am.divCount(2) to am.divCount(5)
        appeared[pair] = appeared.getValue(pair) + 1
    }

    val checked = mutableMapOf<Pair<Pair<Int, Int>, Pair<Int, Int>>, Boolean>().withDefault { false }
    var answer = 0L

    for ((key1, time1) in appeared) for ((key2, time2) in appeared) {
        if (key1.first + key2.first >= 18 && key1.second + key2.second >= 18) {
            if (key1 to key2 in checked || key2 to key1 in checked) continue
            answer += if (key1 == key2) time1 * (time1 - 1) / 2 else time1 * time2
            checked.merge(key1 to key2, true, Boolean::or)
        }
    }

    println(answer)
}

// region kokokara template dayo (^o^)
@Suppress("unused", "HasPlatformType", "MemberVisibilityCanBePrivate", "ClassName")
private class SimpleFastIOWithToken_agc047a(private val separator: String = System.lineSeparator()) {
    private val br: BufferedReader = System.`in`.bufferedReader()
    private var st: StringTokenizer = StringTokenizer("")
    private val sb: StringBuilder = StringBuilder()
    private fun prepareNext() = run { if (!st.hasMoreTokens()) st = StringTokenizer(br.readLine()) }

    fun readString(): String = run { prepareNext() }.run { st.nextToken() }
    fun readStringList(size: Int): List<String> = List(size) { readString() }
    fun readInt(): Int = Integer.valueOf(readString())
    fun readIntList(size: Int): List<Int> = List(size) { readInt() }
    fun readLong(): Long = java.lang.Long.valueOf(readString())
    fun readLongList(size: Int): List<Long> = List(size) { readLong() }
    inline fun <reified T> readArray(size: Int, init: () -> T) = Array(size) { init() }
    inline fun <T> readList(size: Int, init: () -> T) = List(size) { init() }

    fun println(): Unit = run { sb.append(separator) }
    fun print(any: Any): Unit = run { sb.append(any) }
    fun println(any: Any): Unit = run { sb.append(any.toString() + separator) }

    fun exec(action: SimpleFastIOWithToken_agc047a.() -> Unit) = run {
        Thread(null, { action() }, "(^o^)", 128 * 1024 * 1024)
            .apply { setUncaughtExceptionHandler { _, e -> e.printStackTrace(); exitProcess(1) } }
            .apply { start() }.join()
    }.run { kotlin.io.print(sb) }

    fun readLine(): Nothing = error("readLine is disabled.")
}
// endregion kokomade template dayo (^o^)


Measured memory_bytes: 85888
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <stdio.h>
using namespace std;

int main()
{
    string str, q, tmp;
    int n,a=0,b=0;
    cin>> str;
    cin >> n;
    for (int i =0; i<n; i++){
        cin >> q;
        cin >> a >> b;
        if(q=="print"){
            cout << str.substr(a,b-a+1) << "\n";
        }else if (q=="reverse")
        {
            tmp = str.substr(a,b-a+1);
            reverse(tmp.begin(), tmp.end());
            str.replace(a, b-a+1, tmp);

        }else{
            cin >> tmp;
            str.replace(a, b-a+1, tmp);

        }

    }
    // cout << t <<" "<<h<<"\n";

    return 0;
}


Measured memory_bytes: 3224