akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
const int inf = 1e9 + 7;
const ll INF = 1e18;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
const int mod = 1000000007;
ll modpow(ll a, int b) { return b ? modpow(a * a % mod, b / 2) * (b % 2 ? a : 1) % mod : 1; }
template<class T> ostream& operator<<(ostream& os, const vector<T>& vec) { for (auto &vi: vec) os << vi << " "; return os; }
template<class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> inline void add(T &a, int b) { a += b; if (a >= mod) a -= mod; }



void solve();

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

    int T;
    // cin >> T;
    T = 1;

    while (T--) {
        solve();
    }
}


void solve() {
  string s;
  cin >> s;
  reverse(all(s));
  s += '0';

  int n = sz(s);
  int dp[n + 1][2]; // 繰り下がりが発生しているか
  fill_n(*dp, (n + 1) * 2, inf);
  dp[0][0] = 0;

  rep(i, n) rep(j, 2) {
    // cout << endl << i << " " << j << endl;
    rep(a, 10) {
      int x = s[i] - '0';

      int c = 0;

      int a2 = a;
      if (j) {
        a2--;
      }
      int nj = 0;
      if (a2 == -1) {
        a2 = 9;
        nj = 1;
      }

      int b;
      if (a2 >= x) b = a2 - x;
      else {
        b = 10 + a2 - x;
        nj = 1;
      }
      // cout << i << " " << j << " " << a2 << " " << b << " " << c << endl;
      chmin(dp[i + 1][nj], dp[i][j] + a + b); // deguged, a2 to a
    }
  }
  // rep(i, n + 1) { rep(j, 2) cout << dp[i][j] << " "; cout << endl; }
  cout << dp[n][0] << endl;
}


Measured memory_bytes: 9244
#include <stdio.h>

int T[255];

int main()
{
    int i, j, N;
    scanf("%d", &N);
    for (i = 0; i < N; i++) {
        scanf("%d", &T[i]);
    }
 
    for (i = 0; i < N; i++) {
        printf("node %d: key = %d, ", i+1, T[i]);
        if ((i-1)/2 >= 0 && i != 0) {
            printf("parent key = %d, ", T[(i-1)/2]);
        }
        if ((i+1)*2-1 < N) {
            printf("left key = %d, ", T[(i+1)*2-1]);
        }
        if ((i+1)*2 < N) {
            printf("right key = %d, ", T[(i+1)*2]);
        }
        puts("");
    }
    
    return 0;
}

Measured memory_bytes: 608
#include <stdio.h>

int main(void) {
	int a, b, c, aa, bb, cc;
	scanf("%d%d%d", &a, &b, &c);
	if (a > b)
	{
		aa = b;
		bb = a;
	}
	else
	{
		aa = a;
		bb = b;
	}
	if (bb > c)
	{
		b = c;
		cc = bb;
	}
	else
	{
		b = bb;
		cc = c;
	}
	if (aa > b)
	{
		a = b;
		bb = aa;
	}
	else
	{
		a = aa;
		bb = b;
	}
	printf("%d %d %d\n", a, bb, cc);
	return 0;
}

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

int main () {
	string s;
	string t;
	getline(cin, s);
	getline(cin, t);
	int n = s.length();
	int c = 0;
	for (int i =0; i < n; i++){
		if (s[i] != t[i]) c++;
	}
	cout << c;
	return 0;
}


Measured memory_bytes: 3408
n, m = map(int, input().split())

ss = [list(map(int, input().split())) for _ in range(n)]
p = [list(map(int, input().split())) for _ in range(m)]

INF = 10 ** 8 * 4
for s in ss:
    dist = INF
    c_point = 0
    a, b = s
    for i, v in enumerate(p):
        c, d = v
        manhattan = abs(a - c) + abs(b - d)
        if manhattan < dist:
            c_point = i + 1
            dist = manhattan
    print(c_point)


Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
using namespace std;
typedef long long ll;
int main(){
  int k = 0;
  string n;
  cin >> n >> k;
  ll dp[10005][2][5];
  dp[0][0][0] = 1;
  int kazu = n.size();
  //cout << kazu << endl;
  for(int i = 0;i <= kazu - 1;i++){
    for(int j = 0;j <= k;j++){
      dp[i + 1][1][j + 1] += dp[i][1][j] * 9;
      dp[i + 1][1][j] += dp[i][1][j];
      int num = 0;
      num = n[i] - '0';
      //cout << num << endl;
      if(num > 0){
        dp[i + 1][1][j + 1] += dp[i][0][j] * (num - 1);
        dp[i + 1][1][j] += dp[i][0][j];
      }
      if(num > 0){
        dp[i + 1][0][j + 1] += dp[i][0][j];
      }
      else{
        dp[i + 1][0][j] += dp[i][0][j];
      }
    }
  }
  cout << dp[kazu][0][k] + dp[kazu][1][k] << endl;
  return 0;
}

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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007



int main(){
  
  int r;
  cin >> r;
  if(r < 1200)cout << "ABC" << endl;
  else if(r < 2800)cout << "ARC" << endl;
  else cout << "AGC" << endl;



  

  return 0;
}

Measured memory_bytes: 256
/*بسم الله الرحمن الرحيم*/
/*“Dengan menyebut nama Allah yang Maha Pengasih lagi Maha Penyayang”*/
/*“In the name of Allah, Most Gracious, Most Merciful”*/
/********************************************************************************************************\__
                                                                                                          |
        author  :   Althafa Dhia Syauqi   ||    email   :    daltafa@gmail.com                              ||
        SMAN 10 Samarinda, Kalimantan Timur.                                                    ||
                                                                                                          ||
/********************************************************************************************************/
#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define rep_k(i,n) for(int x=i;x<n;x++)
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep_n(i,n) for(int i=1;i<=(n);i++)
#define rep_all(k) for(auto x:k)
#define endl '\n'
#define mod 1e9+7
#define pb push_back
#define READ(f)         freopen(f, "r", stdin)
#define WRITE(f)        freopen(f, "w", stdout)
#define maxSort         sort(all(v),greater<int>())
#define rSort           sort(v.rbegin(),v.rend())
#define FOREACH(i,c) for (typeof((c).end()) i = (c).begin(); i != (c).end(); ++i)
#define RESET(c,v) memset(c, v, sizeof(c))
#define sqr(x)          ((x)*(x))
#define qube(x)         ((x)*(x)*(x))
using namespace std;
void optimization()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}
ll n,m,t;
int main()
{
	optimization();
    	ll a,b,c,ans;
  		cin >> a>>b>>c;
  	if(a>=c)
    	cout << b+c<<endl;
  else
  {
   	ans=a;
    c-=a;
    if(c==b||b>c)
      cout <<ans+(b+c)<<endl;
    else 
      cout <<ans+(b*2)+1<<endl;
  }
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull  unsigned long long ;
#define _CRT_SECURE_NO_WARNINGS 
const double  pai= acos(-1.0);
int main()
{
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	int a,b,sum=0,i;
	cin>>a>>b;
	if(b==1)cout<<0<<endl;
	else
	if(a<b)
	{
		for(i=1;;i++)
		{
		if(sum>=b)break;
		sum=i*a-i+1;
		if(sum>=b)break;
		}
		cout<<i<<endl;
	}
	else
	if(a>=b)
	cout<<1<<endl;
	return 0;
 }

Measured memory_bytes: 256
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")

using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(int i=num, i##_len=(n); i<i##_len; ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define print(x) (cout << (x) << endl)
#define pb push_back
#define mp make_pair
#define sz(x) int(x.size())
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
#define fs first
#define sc second
// 多倍長
#include <boost/rational.hpp>
#include <boost/multiprecision/cpp_int.hpp>
using boost::rational;
using boost::multiprecision::cpp_int;

const int INF = 1e9;
const ll LLINF = 1e16;
const ll MOD = 1e9+7;
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}
 
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
 

// 指定した文字cが文字列に何文字入ってるか
ll stringcount(string s, char c) {
    return count(s.cbegin(), s.cend(), c);
}


// 割り算の切り上げ処理
template<typename T>
T rp(T a, T b) {
  return (a + b - 1) / b;
}

// 桁和
template<typename T>
T digsum(T n) {
    T res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

// 回文判定
bool kai (string s) {
    string t{s};
    reverse(begin(t), end(t));
    return s == t;
}

using pint = pair<int, int>;
using pll = pair<ll, ll>;


vector<string> split(const string &s, char delim) {
    vector<string> elems;
    string item;
    for (char ch: s) {
        if (ch == delim) {
            if (!item.empty())
                elems.push_back(item);
            item.clear();
        }
        else {
            item += ch;
        }
    }
    if (!item.empty())
        elems.push_back(item);
    return elems;
}



int main(void)
{
    cout.tie(0);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    ll n;
    cin >> n;
    vector<ll> a(n);
    map<ll, ll> mp;
    ll ans = 0;
    rep(i, n){
        cin >> a[i];
        ans += a[i];
        mp[a[i]]++;
    }
    ll q;
    cin >> q;
    rep(i, q){
        ll b,c;
        cin >> b >> c;
        ans -= b * mp[b];
        ans += c * mp[b];
        mp[c] += mp[b];
        mp[b] = 0;
        print(ans);
    }
}


Measured memory_bytes: 9952
package main

import (
	"fmt"
	"strings"
)

func main() {
	var n,k,r,s,p int
	var t string
	fmt.Scan(&n,&k,&r,&s,&p,&t)


	var score = 0
	tslice := strings.Split(t,"")
	for i := 0; i < n; i++ {
		if i < k {
			switch tslice[i] {
			case "s":
				score += r
			case "p":
				score += s
			case "r":
				score += p
			}
		} else {
			if tslice[i] == tslice[i-k] {
				tslice[i] = "x"
			} else {
				switch tslice[i] {
				case "s":
					score += r
				case "p":
					score += s
				case "r":
					score += p
				}
			}
		}
	}
	fmt.Println(score)
}

Measured memory_bytes: 2944
#include "bits/stdc++.h"
#define fi first
#define se second
#define all(x) x.begin(), x.end()
using namespace std;
using ull = unsigned long long;
using ll = long long;
constexpr int I_INF = INT_MAX;
constexpr ll L_INF = LLONG_MAX;

struct __INIT {
    __INIT() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(15);
    }
} __init;

int digsum(int a){
    int sum = 0;
    while(a > 0){
        sum += a % 10;
        a /= 10;
    }
    return sum;
}

int main(){
    int N;
    cin >> N;
    if(N % 10) cout << digsum(N) << endl;
    else puts("10");
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.io.BufferedInputStream;
import java.lang.Math;

public class Main{
    static long tmp = 10000 * 10000;
    static long MAX_COUNT = tmp * tmp + 999;

    public static void main(String [] args) {
        Scanner sc = new Scanner(new BufferedInputStream(System.in));
        long K = sc.nextLong();
        for(int N = 2; N <= 50; N++) {
            if(solve(K,N)) {
                break;
            }
        }
    }

    static boolean solve(long K, int N) {
        long C = K / N + N - 1;
        long [] A = new long [N];
        for(int i = 0; i < N; i++) {
            A[i] = C;
        }
        for(int i = 0; i < (K % N); i++) {
            long max = 0;
            int p = 0;
            for(int j = 0; j < N; j++) {
                if(A[j] > A[p]) {
                    p = j;
                    max = A[j];
                }
            }

            for(int j = 0; j < N; j++) {
                if((A[j] + N + 1 > max) && (A[j] < A[p])) {
                    p = j;
                }
            }

            for(int j = 0; j < N; j++) {
                A[j] = A[j] - 1;
            }
            A[p] = A[p] + N + 1;
        }

        for(int i = 0; i < N; i++) {
            if(A[i] < 0) {
                return false;
            }
            if(A[i] > MAX_COUNT) {
                return false;
            }
        }

        System.out.println(N);
        for(int i = 0; i < N; i++) {
            System.out.println(A[i] + " ");
        }

        return true;
    }
}
// n = 50 : 50 round -> max-=1
// final max = 49


Measured memory_bytes: 23124
#include<stdio.h>
int main(void)
{
   int a, b, k, i;

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

   for(i=a;i<=b;i++){
      if((i <= a+k-1)||( b-k+1<= i)) 
         printf("%d\n", i);
}
   return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;

bool cmp(const pair<pii, pair<int, pii>>& a, const pair<pii, pair<int, pii>>& b) {
    return a.second.first < b.second.first;
}

int main() {
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    #ifdef DEBUG
        freopen("in.txt", "r", stdin);
    #endif
    
    pair<pii, pair<int, pii>> p[100001];
    int cnt[100001] = {0, };
    
    int n, m; scanf("%d %d", &n, &m);
    for (int i = 0; i < m; i++) {
        int a, b; scanf("%d %d", &a, &b);
        p[i].first = make_pair(a, b);
        p[i].second.first = i;
    }
    
    sort(p, p + m);
    
    for (int i = 0; i < m; i++) {
        p[i].second.second = make_pair(p[i].first.first, ++cnt[p[i].first.first]);
    }
    
    sort(p, p + m, cmp);
    
    for (int i = 0; i < m; i++) {
        printf("%06d%06d\n", p[i].second.second.first, p[i].second.second.second);
    }
    
    return 0;
}


Measured memory_bytes: 3840
r = [
[1,399],
[400,799],
[800,1199],
[1200,1599],
[1600,1999],
[2000,2399],
[2400,2799],
[2800,3199],
]

field = [0 for x in range(len(r))]

ok = 3200
oknum = 0

n = int(input())

a = list(map(int, input().split()))

for x in a:
    if x >= ok:
        oknum += 1
        continue
    for i, v in enumerate(r):
        if v[0] <= x <= v[1]:
            field[i] = 1


sumf = sum(field)

print(sumf if sumf != 0 else 1, min(sumf + oknum, sumf + oknum))


Measured memory_bytes: 3064
#include<stdio.h>
int a,b;
int main(void){
scanf("%d%d",&a,&b);
if(a-b >= 2){
    printf("%d",a+a-1);
}else if(b-a >= 2){
    printf("%d",b+b-1);
}else{
    printf("%d",a+b);
}
}


Measured memory_bytes: 128
#include<iostream>

int main(){

    size_t n, m;
    std::cin >> n >> m;

    if(n * 2 > m){
        std::cout << m / 2 << std::endl;
    }else{
        std::cout << n + (m - n * 2) / 4 << std::endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i < n; ++i)
#define repe(i, n) for(int i=0; i <= n; ++i)
#define repr(i, n) for(int i=n-1; i > 0; --i)
#define all(x) (x).begin(), (x).end()
#define pb(x) push_back(x)
using namespace std;
template <class T> bool chmax(T &a, const T &b) {if (a<b) {a = b; return 1;} return 0;}
template <class T> bool chmin(T &a, const T &b) {if (b<a) {a = b; return 1;} return 0;}
template <class T> using V=vector<T>;
typedef long long ll;
const int INF = 1e9;
const ll mod = 1000000007;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
void foreach_permutation(int n, std::function<void(int *)> f) {
  int indexes[n];
  for (int i = 0; i < n; i++) indexes[i] = i;
  do {
    f(indexes);
  } while (std::next_permutation(indexes, indexes + n));
}

int main() {
    int n,h;
    cin >> n;
    vector<int> H;
    int cnt = 1;
    rep(i,n) {
        cin >> h;
        H.pb(h);
        if (i>0 &&  h == *max_element(all(H))) {
            cnt++;
        }
    }
    cout << cnt << "\n";
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int n,i,j;
    scanf("%d",&n);
    int a[n],b[n];
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        b[a[i]-1]=i+1;
    }
    for(i=0;i<n;i++)
    {
        printf("%d ",b[i]);
    }
}


Measured memory_bytes: 1536
#include <cmath>
#include <iomanip>
#include <iostream>


#define EPSILON 1e-9


class vector_t {
public:
  double x;
  double y;
  double z;

public:
  vector_t(double x = 0, double y = 0, double z = 0) : x(x), y(y), z(z) {};

public:
  double operator*(const vector_t& v) const {
    return x * v.x + y * v.y + z * v.z;
  };

  vector_t operator^(const vector_t& v) const {
    return vector_t(y * v.z - z * v.y,
                    z * v.x - x * v.z,
                    x * v.y - y * v.x);
  };

public:
  double length() const {
    return sqrt(*this * *this);
  };
};


class point_t {
public:
  double x;
  double y;
  double z;
  double w;

public:
  point_t(double x = 0, double y = 0, double z = 0, double w = 1) : x(x), y(y), z(z), w(w) {};
  
public:
  vector_t operator-(const point_t& p) const {
    return vector_t(x - p.x, y - p.y, z - p.z);
  };
};


int main(int argc, char** argv)
{
  int x, h;

  while (1) {
    std::cin >> x >> h;

    if (x == 0 && h == 0)
      break;

    point_t p1(x / 2.0, 0, x / 2.0), p2(x / 2.0, 0, -x / 2.0), p3(0, h);

    std::cout <<
      std::setprecision(12) << ((p2 - p1) ^ (p3 - p1)).length() * 2 + x * x << std::endl;
  }
}

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

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

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

int main()
{
    ll K, A, B;
    cin >> K >> A >> B;

    ll s = std::min(K, A - 1);
    ll n = s + 1;
    K -= s;

    n += (K / 2) * std::max((ll)2, B - A) + K % 2;
    cout << n << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int a[100001],b[100001];
int main(){
	int n,x;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>x;
		if(i%2==1)a[x]++;
		else b[x]++;
	}
	int mxa=0,mxb=0,mx1,mx2;
	for(int i=0;i<=100001;i++)if(a[i]>mxa)mxa=a[i],mx1=i;
	for(int i=0;i<=100001;i++)if(b[i]>mxb)mxb=b[i],mx2=i;
	if(mx1==mx2){
		int mxc=0,mxd=0;
		for(int i=0;i<=100001;i++)if(i!=mx1&&a[i]>mxc)mxc=a[i];
	    for(int i=0;i<=100001;i++)if(i!=mx2&&b[i]>mxd)mxd=b[i];
		mxa=max(mxc,mxd);
	}	
	cout<<n-mxa-mxb;
 	return 0;
}


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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define abs(a) max((a),-(a))
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repe(i,n) rep(i,(n)+1)
#define per(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define pere(i,n) rep(i,(n)+1)
#define all(x) (x).begin(),(x).end()
#define SP <<" "<<
#define RET return 0
#define MOD 1000000007
#define INF 1000000000000000000

typedef long long LL;
typedef long double LD;

int main(){
  while(1){
    int h,w,c;
    cin >> h >> w >> c;
    if(h==0) return 0;
    vector<vector<int>> p(h,vector<int>(w)),f(h,vector<int>(w));
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
        cin >> p[i][j];
        p[i][j]--;
      }
    }
    vector<int> hen(5);
    queue<pair<int,int>> bfs;
    pair<int,int> now;
    int sc;
    int ans=0,count;
    int nx,ny;
    int hou[5]={0,1,0,-1,0};
    for(hen[0]=0;hen[0]<6;hen[0]++){
      for(hen[1]=0;hen[1]<6;hen[1]++){
        for(hen[2]=0;hen[2]<6;hen[2]++){
          for(hen[3]=0;hen[3]<6;hen[3]++){
            hen[4]=c-1;
            for(int i=0;i<h;i++){
              for(int j=0;j<w;j++){
                f[i][j]=p[i][j];
              }
            }
            for(int i=0;i<5;i++){
              sc=f[0][0];
              if(sc!=hen[i]){
                bfs.push({0,0});
                f[0][0]=hen[i];
                while(!bfs.empty()){
                  now=bfs.front();
                  bfs.pop();
                  for(int j=0;j<4;j++){
                    nx=now.first+hou[j];
                    ny=now.second+hou[j+1];
                    if(0<=nx&&nx<w&&0<=ny&&ny<h){
                      if(f[ny][nx]==sc){
                        bfs.push({nx,ny});
                        f[ny][nx]=hen[i];
                      }
                    }
                  }
                }
              }
            }
            sc=f[0][0];
            bfs.push({0,0});
            count=1;
            f[0][0]=-1;
            while(!bfs.empty()){
              now=bfs.front();
              bfs.pop();
              for(int j=0;j<4;j++){
                nx=now.first+hou[j];
                ny=now.second+hou[j+1];
                if(0<=nx&&nx<w&&0<=ny&&ny<h){
                  if(f[ny][nx]==sc){
                    bfs.push({nx,ny});
                    f[ny][nx]=-1;
                    count++;
                  }
                }
              }
            }
            ans=max(ans,count);
          }
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}



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

using namespace std;

using ll = long long;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<ll> a(n + 2, 0);
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }

    vector<ll> l(n + 2, 0), r(n + 2, 0);
    for (int i = 2; i <= n; i++) {
        l[i] = l[i - 1] + abs(a[i - 2] - a[i - 1]);
    }

    for (int i = n - 1; i >= 1; i--) {
        r[i] = r[i + 1] + abs(a[i + 1] - a[i + 2]);
    }

    for (int i = 1; i <= n; i++) {
        cout << l[i] + r[i] + abs(a[i - 1] - a[i + 1]) << endl;
    }
    return 0;
}

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

int main(){
    string s;
    cin >> s;
    for(int bit = 0; bit < (1<<3); bit++){
        int ans = (s[0] - '0');
        string out;
        for(int i = 0; i < 3; i++){
            out.push_back(s[i]);
            if(bit & (1<<i)){
                ans += (s[i+1] - '0');
                out.push_back('+');
            }else{
                ans -= (s[i+1] - '0');
                out.push_back('-');
            }
        }
        out.push_back(s[3]);
        cerr << out << "=" <<  ans << endl;
        if(ans == 7){
            cout << out << "=7" << endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	int[][] parent;
	
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String[] nrs = in.nextLine().split(" "); // nrs stands for nodes and relations
		int nodes = Integer.parseInt(nrs[0]);
		int rels = Integer.parseInt(nrs[1]);
		Main graph = new Main(nodes);
		for (int i = 0; i < nodes; i++) {
			graph.set(i);
		}
		
		for (int i = 0; i < rels; i++) {
			String[] holder = in.nextLine().split(" ");
			int num1 = Integer.parseInt(holder[0]);
			int num2 = Integer.parseInt(holder[1]);
			graph.union(num1, num2);
		}
		int q = in.nextInt();
		String lastSeen = "";
		for (int i = 0; i < q; i++) {
			
			int q1 = in.nextInt();
			int q2 = in.nextInt();
			if (graph.find(q1) == graph.find(q2)) {
				System.out.println("yes");
			}
			else {
				System.out.println("no");
			}
		}
		
	}
	
	public Main(int n) {
		// Each node will have a degree to which indicates the length of its subtree
		parent = new int[n][2];
	}
	
	
	public void set(int x) {
		parent[x] = new int[] {x, 0};
		
	}
	
	// Union function
	public void union(int x, int y) {
		int[] r1 = find(x);
		int[] r2 = find(y);
		// If r1 is the smaller tree 
		if (r1[1] < r2[1] ) {
			parent[r1[0]] = r2;			
		}
		else if (r1[1] > r2[1]) {
			parent[r2[0]] = r1;
		}
		else {
			parent[r2[0]] = r1;
			parent[r1[0]][1] += 1;
		}
	}
	
	// Find parent function
	public int[] find(int x) {
		int[] curr = parent[x];
		while(parent[curr[0]][0] != curr[0]) {
			curr = parent[curr[0]];
		}
		return curr;
	}
	
}



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

int main() 
{
	int n,a,max,cou=1;
	cin >> n;
	cin >> a;
	max = a;
	n--;
	while(n--){
		cin >> a;
		if(a>=max){
			cou++;
			max = a;
		}
	}
	cout << cou <<endl;
    return 0;
}

Measured memory_bytes: 256
let n, _ = Scanf.scanf "%d %d\n" (fun x y -> x, y)

let mkls i =
  Array.init i (fun _ -> Scanf.scanf "%s\n" (fun s -> s))
  |> Array.to_list

let cat ls =
  let rec aux tmp = function
    | [] -> tmp
    | h :: t -> aux (tmp ^ h) t
  in
  aux "" ls

let () = mkls n |> List.sort String.compare |> cat |> print_endline

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

using namespace std;

using i64 = int64_t;

const i64 INF = 1e18 + 7;
const i64 MOD = 1e9 + 7;

template <i64 mod = MOD>
struct ModInt{
    i64 p;

    ModInt() : p(0){}
    ModInt(i64 x){p = x >= 0 ? x % mod : x + (-x + mod - 1) / mod * mod;}

    ModInt& operator+=(const ModInt& y){p = p + *y - ((p + *y) >= mod ? mod : 0); return *this;}
    ModInt& operator-=(const ModInt& y){p = p - *y + (p - *y < 0 ? mod : 0); return *this;}
    ModInt& operator*=(const ModInt& y){p = (p * *y) % mod; return *this;}
    ModInt& operator%=(const ModInt& y){if(y)p %= *y; return *this;}

    ModInt operator+(const ModInt& y) const{ModInt x = *this; return x += y;}
    ModInt operator-(const ModInt& y) const{ModInt x = *this; return x -= y;}
    ModInt operator*(const ModInt& y) const{ModInt x = *this; return x *= y;}
    ModInt operator%(const ModInt& y) const{ModInt x = *this; return x %= y;}

    friend ostream& operator<<(ostream& stream, const ModInt<mod>& x){
        stream << *x;
        return stream;
    }

    friend ostream& operator>>(ostream& stream, const ModInt<mod>& x){
        stream >> *x;
        return stream;
    }

    ModInt& operator++(){p = (p + 1) % mod; return *this;}
    ModInt& operator--(){p = (p - 1 + mod) % mod; return *this;}

    bool operator==(const ModInt& y) const{return p == *y;}
    bool operator!=(const ModInt& y) const{return p != *y;}

    const i64& operator*() const{return p;}
    i64& operator*(){return p;}

};

using mint = ModInt<>;


signed main(){
    int n;
    cin >> n;
    vector<int> a(n, 0);
    for(auto& x : a){
        char s;
        cin >> s;
        if(s == 'U')
            x = 2;
        if(s == 'D')
            x = 1;
    }

    vector<mint> dp(n + 1, 0);
    dp[0] = 1;
    for(int i = 0; i < n; ++i){
        if(!a[i])
            continue;
        vector<mint> nex(n + 1, 0);
        for(int j = 0; j < n; ++j){
                if(dp[j] == mint(0))
                    continue;
                // up
                if(a[i] == 1){
                    // umeru
                    nex[j] += dp[j] * j;
                    // umenai
                    if(j)
                        nex[j - 1] += dp[j] * j * j;
                }
                // down
                else{
                    // umeru
                    nex[j] += dp[j] * j;
                    // umenai
                    nex[j + 1] += dp[j];
                }
        }
        dp = move(nex);
    }

    cout << dp[0] << endl;

}


Measured memory_bytes: 3136
n = int(raw_input())
mod = (10 ** 9 )+ 7

def f(a,n):
	mod = (10 ** 9 )+ 7
	
	if n == 0:
		return 1
	t = f(a,n/2) % mod
	return ((t ** 2) * (a if n%2 else 1)) %mod

print (f(10,n) - f(9,n) - f(9,n) + f(8,n)) %mod

Measured memory_bytes: 64332
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	vector<int> A(N);
	int res = 0;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	int INF = (int)1 << 60;
	vector<int> dp(N, INF);
	dp[0] = 0;
	for (int i = 0; i < N; i++) {
		if (i + 2 < N)dp[i + 2] = min(dp[i + 2], dp[i] + abs(A[i] - A[i + 2]));
		if (i + 1 < N)dp[i + 1] = min(dp[i + 1], dp[i] + abs(A[i] - A[i + 1]));
	}
	cout << dp.back() << endl;
}

Measured memory_bytes: 1792
def counting_sort():
    input()
    C = [0]*(10000+1)
    b = []
    for a in map(int, input().split()):
        C[a] += 1
    for i, c in enumerate(C):
        b += [str(i)]*c
    print(' '.join(b))
        
if __name__ == "__main__":
    counting_sort()


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

using namespace std;

long long  n,x,ans=0,a[405],s[405];
long long f[405][405];

main()
{
    cin>>n;
    for (int i=1; i<=n; i++)
    {
        cin>>a[i];
        f[i][i]=0;
        s[i]=s[i-1]+a[i];
    }
    for (long long l=2;l<=n;l++)
    {
        for (long long i=1;i<=n-l+1;i++)
        {
            f[i][i+l-1]=1000000000000000000;
            for (long long k=1;k<=l;k++)
            {
                f[i][i+l-1]=min(f[i][i+k-1]+f[i+k][i+l-1]+s[i+l-1]-s[i-1],f[i][i+l-1]);
            }
        }
    }
    cout<<f[1][n];
    return 0;
}


Measured memory_bytes: 1536
s = input()
n = len(s)
i = 0
ans = [0] * n
for i in range(n - 1):
    if s[i] == 'R' and s[i + 1] == 'L':
        j = 0
        while i - j >= 0 and s[i - j] == 'R':
            if j % 2:
                ans[i + 1] += 1
            else:
                ans[i] += 1
            j += 1
        j = 1
        while i + j < n and s[i + j] == 'L':
            if j % 2:
                ans[i + 1] += 1
            else:
                ans[i] += 1
            j += 1
print(' '.join(map(str, ans)))

Measured memory_bytes: 51952
#include <iostream>
#include "string.h"
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>

using namespace std;
#define MAX_N 2000000
#define ll long long
ll N;


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

unsigned long long lcm(unsigned long long a,unsigned long long b){
	if(a == b) return a;
	return  a / gcd(a,b) * b;
}


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> N;
	int ans = INT_MAX;
	for(ll i = 1LL;i*i <= N;++i){
		if(N % i == 0){
			string aa = to_string(N / i);
			string bb = to_string(i);
			int a = aa.length();
			int b = bb.length();
			ans = min(ans,max(a,b));
		}
	}
	cout << ans << endl;



	return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        long l = sc.nextLong();
        long k = l / 11;
        if(l == k * 11){
            System.out.println(k * 2);
        }
        else if(l - k * 11 <= 6){
            System.out.println(k * 2 + 1);
        }
        else System.out.println(k * 2 + 2);

    }

}

Measured memory_bytes: 21716
#include<iostream>
#include<set>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
#define N 200

int d,a[N],b[N]={0};

int main(){
    int n,i,k,j,ans=0;
    cin>>n>>k;
    for(i=1;i<=k;i++){
        cin>>d;
        for(j=1;j<=d;j++){
            cin>>a[j];
            b[a[j]]=1;
        }
            
    }
    for(i=1;i<=n;i++)
        ans+=!b[i];
    cout<<ans;
    return 0;
}



Measured memory_bytes: 3632
from collections import deque
N, M = map(int, input().split())
graph = [[] for _ in range(3*N)]
for _ in range(M):
  u, v = map(lambda x:int(x)-1, input().split())
  graph[3*u] += [3*v+1]
  graph[3*u+1] += [3*v+2]
  graph[3*u+2] += [3*v]

S, T = map(lambda x:int(x)-1, input().split())

def bfs(s):
  q = deque([s])
  dist = [float('inf')]*(3*N)
  dist[s] = 0

  while q:
    u = q.popleft()
    for v in graph[u]:
      if dist[v] == float('inf'):
        q += [v]
        dist[v] = dist[u] + 1

  return dist

d = bfs(3*S)
if d[3*T] == float('inf'):
  print(-1)
else:
  print(d[3*T]//3)

Measured memory_bytes: 87536
nx = list(map(int,input().split()))
n,x = nx[0],nx[1]
m = []
msum = 0
for i in range(n):
    m.append(int(input()))
    msum += m[i]
xnew = x - msum
m.sort()
ans = n
while(1):
    xnew -= m[0]
    if xnew >= 0:
        ans += 1
    else:
        break
print(ans)

Measured memory_bytes: 3064
# util functions

# debug
$debugFlag = ( ARGV[0] != nil )
p "==== DEBUG MODE ====" if $debugFlag

def pd(str)
  p str if $debugFlag
end

# input
inputs = []
lc = 0
while l = $stdin.gets do
  if false
    inputs << l.chomp.split(" ").map(&:to_s)
  else
    inputs << l.chomp.split(" ").map(&:to_i)
  end
  lc += 1
end

aa = inputs[0][0]
bb = inputs[0][1]

# input check
if $debugFlag
  p "--- INPUT (begin) ---"
  inputs.each do |l_i|
    p l_i
  end
  p "--- INPUT (end) ---"
  print "\n"
end

# body
if $debugFlag
end

if aa <= 8 and bb <= 8
  puts "Yay!"
else
  puts ":("
end


Measured memory_bytes: 1788
#include<iostream>
#include<string>
using namespace std;
int main()
{
    int a=0;
    string s;
    for(int i=0;i<4;i++){
        cin>>s;
        if(s[i]=='+')
            a++;
        else
            a--;
    }
    cout<<a<<endl;
    return 0;
}

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

int main() {
 string s;
  int q;
  cin>>s>>q;
  int sw=0;
  vector<vector<string>> p(2);
  for(int i=0;i<q;i++){
    int t;
    cin>>t;
    if(t==1) {
      if(sw==1) sw=0;
      else sw=1;
    }
    if(t==2){
      int f;
      string c;
      cin>>f>>c;
      if((f==1&&sw==0)||(f==2&&sw==1)) p[0].push_back(c);
      if((f==2&&sw==0)||(f==1&&sw==1)) p[1].push_back(c);
    }
  }
  if(sw==0){
    for(int i=p[0].size()-1;i>=0;i--){
      cout<<p[0][i];
    }
    cout<<s;
    for(int i=0;i<p[1].size();i++){
      cout<<p[1][i];
    }
  }
  if(sw==1){
    for(int i=p[1].size()-1;i>=0;i--){
      cout<<p[1][i];
    }
    for(int i=s.size()-1;i>=0;i--){
      cout<<s[i];
    }
    for(int i=0;i<p[0].size();i++){
      cout<<p[0][i];
    }
  }
}

Measured memory_bytes: 11760
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const auto INF = (ll)1e9+7;  
using  p = pair<int,int>;
using  v = vector<int>;

ll acc(ll i){
   if(i==1) return 1;
   return i*acc(i-1)%INF;
}


int main(){
  int n,m;
  cin >> n >> m;
  if(n==m){
  	cout << acc(n)*2%INF*acc(m)%INF;
  }else if(abs(n-m)==1){
  	cout << acc(n)*acc(m)%INF;
  }else{
  	cout << 0;
  }
}
  

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxx = 1e6 + 7;
const int Inf = 1 << 30;
const LL INF = 1LL << 60;
int n, m;
int a[maxx];

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

Measured memory_bytes: 3676
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <utility>
using namespace std;
typedef pair<long long, long long> P;
int main(){
  int N, M;
  cin >> N >> M;
  vector<long long> A(N);
  long long ans = 0;
  priority_queue<long long, vector<long long>, greater<long long>> q;
  for(int i = 0; i < N; i++){
    cin >> A[i];
    q.push(A[i]);
  }
  vector<P> B(M);
  for(int i = 0; i < M; i++){
    long long a, b;
    cin >> a >> b;
    B[i] = P(b, a);
  }
  sort(B.begin(), B.end());
  reverse(B.begin(), B.end());
  long long sum = 0;
  for(int i = 0; i < M; i++){
    long long t = B[i].second;
    while(!q.empty() && t > 0){
      if(q.top() < B[i].first){
      	sum += B[i].first;
      	t--;
        q.pop();
      }
      else break;
    }
  }
  while(!q.empty()){
    sum += q.top();
    q.pop();
  }
  cout << sum << endl;
}

Measured memory_bytes: 6412
def play():
    N, A, B, C = map(int, input().split())
    S = [input() for i in range(N)]
    p = []
    for i in range(N):
        s = S[i]
        if s == "AB":
            if A + B == 0:
                print("No")
                return 0
            elif A == 1 and B == 1 and i != N-1:
                t = S[i+1]
                if t == "AC":
                    A += 1
                    B -= 1
                    p.append("A")
                else:
                    A -= 1
                    B += 1
                    p.append("B")
            elif A >= B:
                A -= 1
                B += 1
                p.append('B')
            else:
                A += 1
                B -= 1
                p.append('A')
        if s == "AC":
            if A + C == 0:
                print("No")
                return 0
            elif A == 1 and C == 1 and i != N-1:
                t = S[i+1]
                if t == "AB":
                    A += 1
                    C -= 1
                    p.append("A")
                else:
                    A -= 1
                    C += 1
                    p.append("C")
            elif A >= C:
                A -= 1
                C += 1
                p.append('C')
            else:
                A += 1
                C -= 1
                p.append('A')
        if s == "BC":
            if B + C == 0:
                print("No")
                return 0
            elif B == 1 and C == 1 and i != N-1:
                t = S[i+1]
                if t == "AB":
                    B += 1
                    C -= 1
                    p.append("B")
                else:
                    B -= 1
                    C += 1
                    p.append("C")
            elif B >= C:
                B -= 1
                C += 1
                p.append('C')
            else:
                B += 1
                C -= 1
                p.append('B')
    print('Yes')
    for i in range(N):
        print(p[i])
    return 0


if __name__ == '__main__':
    play()


Measured memory_bytes: 17004
import java.util.*;

public class Main{
	Scanner sc = new Scanner(System.in);
	
	private void doit(){
		while(sc.hasNext()){
			solve();
		}
	}

	private void solve() {
		int n = sc.nextInt();
		int [] freq = new int[6];
		while(n-- > 0){
			double weight = sc.nextDouble();
			if(weight < 165.0){
				freq[0]++;
			}
			else if(weight < 170.0){
				freq[1]++;
			}
			else if(weight < 175.0){
				freq[2]++;
			}
			else if(weight < 180.0){
				freq[3]++;
			}
			else if(weight < 185.0){
				freq[4]++;
			}
			else{
				freq[5]++;
			}
		}
		for(int i = 0; i < 6; i++){
			System.out.print((i + 1) + ":");
			for(int j = 0; j < freq[i]; j++){
				System.out.print("*");
			}
			System.out.println();
		}
	}

	private void debug(Object... o) { System.out.println("debug = " + Arrays.deepToString(o)); }

	public static void main(String[] args) {
		new Main().doit();
	}
}

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

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

#include <string>
#include <vector>
#include <algorithm>
int main(){
    string str; cin >> str;
    for(int i=0; i<str.size(); i++){
        if(str[i] == ( ((i+1)%2) ?'L':'R')) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 3572
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {

        Scanner input = new Scanner(System.in);
        double numberOf = input.nextDouble();
        double numberAtATime = input.nextDouble();
        double timeToMake = input.nextDouble();
        double result;


        result = timeToMake * Math.ceil(numberOf / numberAtATime);
        System.out.println((int)result);

    }
}


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

#define rep(i,n) for(int (i)=0; (i)<(int)(n); (i)++)
#define all(x) (x).begin(), (x).end()
#define sqr(x) (x)*(x)
#define CEIL(a,b) ((a)+(b)-1) /(b)

typedef long long ll;
const int INF = 1001001001;

void sort_second(vector<pair<ll, ll>> &A, int N); //A:array of pair, N:size of array

int main() {
    string S, T;
    cin >> S >> T;
    int a,b;
    cin >> a >> b;
    string U;
    cin >> U;
    if(S == U) {
        cout << a-1 << ' ' << b << endl;
    } 
    else cout << a << ' ' << b-1 << endl;
    return 0;
}

void sort_second(vector<pair<ll, ll>> &A, int N) {
    rep(i, N) swap(A.at(i).first, A.at(i).second);
    sort(all(A));
    rep(i, N) swap(A.at(i).first, A.at(i).second);
}

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

int main()
{
  int N;scanf("%d",&N);
  char S[N];
  for(int i=0;i<N;i++)cin>>S[i];
  int XY[26];fill(XY,XY+26,0);
  bool counted[26];fill(counted,counted+26,false);
  for(int i=0;i<N;i++)XY[S[i]-'a']++;
  int ans=0,current=0;
  for(int i=0;i<N;i++)
  {
    int num=S[i]-'a';
    if(XY[num]>=2&&!counted[num])ans=max(ans,current++),counted[num]=true;
    if(XY[num]==1&&counted[num])ans=max(ans,current--);
    XY[num]--;
  }
  printf("%d",ans);
}

Measured memory_bytes: 3828
inf = float('inf')
N = int(input())
MRp = -inf
MR = -inf
MRm = -inf
mRp = inf
mR = inf
mRm = inf
MUp = -inf
MU = -inf
MUm = -inf
mUp = inf
mU = inf
mUm = inf

for i in range(N):
	x, y, d = input().split()
	x, y = int(x), int(y)
	if d == 'R':
		MRp = max(MRp, x)
		mRp = min(mRp, x)
		MU = max(MU, y)
		mU = min(mU, y)
	elif d == 'L':
		MRm = max(MRm, x)
		mRm = min(mRm, x)
		MU = max(MU, y)
		mU = min(mU, y)
	elif d == 'U':
		MUp = max(MUp, y)
		mUp = min(mUp, y)
		MR = max(MR, x)
		mR = min(mR, x)
	else:
		MUm = max(MUm, y)
		mUm = min(mUm, y)
		MR = max(MR, x)
		mR = min(mR, x)

t = [0]
if MR > max(MRp, MRm):
	t.append(MR - MRp)
elif MRm + MRp >= 2 * MR and MRm > MRp:
	t.append((MRm - MRp) / 2)
elif MRm > MRp:
	t.append(MRm - MR)
	t.append(MR - MRp)	
if mR < min(mRp, mRm):
	t.append(mRm - mR)
elif mRm + mRp <= 2 * mR and mRm > mRp:
	t.append((mRm - mRp) / 2)
elif mRm > mRp:
	t.append(mRm - mR)
	t.append(mR - mRp)
if MU > max(MUp, MUm):
	t.append(MU - MUp)
elif MUm + MUp >= 2 * MU and MUm > MUp:
	t.append((MUm - MUp) / 2)
elif MUm > MUp:
	t.append(MUm - MU)
	t.append(MU - MUp)
if mU < min(mUp, mUm):
	t.append(mUm - mU)
elif mUm + mUp <= 2 * mU and mUm > mUp:
	t.append((mUm - mUp) / 2)
elif mUm > mUp:
	t.append(mUm - mU)
	t.append(mU - mUp)

ans = inf
for i in t:
	dx = max(MRp + i, MR, MRm - i) - min(mRp + i, mR, mRm - i)
	dy = max(MUp + i, MU, MUm - i) - min(mUp + i, mU, mUm - i)
	ans = min(ans, dx * dy)
print(ans)

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

int main(){
    char ch;
    int counter[26]={};
    int num;
    while(cin>>ch){
        ch= tolower(ch);
        if(isalpha(ch)){
            num = ch - 'a'; 
            counter[num]++;
        }
    }
    for(int i=0;i<26;i++){
        printf("%c : %d\n",i+'a',counter[i]);
    }
    return 0;
}


Measured memory_bytes: 3192
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int[] array = new int[n];
        for (int i = 0; i < n; i++) {
            array[i] = sc.nextInt();
        }
        
        // ans: 連続部分列の和がmod kで要素数になるi, jのパターン数
        long ans = 0;
        
        // 式変形
        // ・連続部分列の和がmod kで要素数になるi, j
        // -> (s[j+1] - s[i]) % k = j+1 - i
        // -> s[j+1]%k - s[i]%k = j+1 - i
        // -> (左辺はmod kの世界、0～k-1の値しか取らない)
        // -> (移項はmod kにならないと無理)
        // -> s[j+1]%k - (j+1)%k = s[i]%k - i%k (j+1-iはk未満)
        // -> s2[j+1] = s2[i] (j+1-iはk未満) のパターン数
        
        // s: 累積和 (mod k)
        long[] s = new long[n+1];
        for (int i = 0; i < n; i++) {
            s[i+1] = (s[i] + array[i]) % k;
        }
        // System.out.println(Arrays.toString(s));
        
        // s2: 累積和 - 要素番号 (mod k)
        long[] s2 = new long[n+1];
        for (int i = 0; i <= n; i++) {
            s2[i] = (s[i] - i) % k;
            if (s2[i] < 0) s2[i] += k;
        }
        // System.out.println(Arrays.toString(s2));
        
        // i, jのパターン数を数え上げる
        Map<Long, Integer> map = new HashMap<Long, Integer>();
        for (int i = 0; i <= n; i++) {
            // 「条件:j+1-iはk未満」
            // -> 区間の長さk-1分までしか見れない
            // -> k個前の要素は随時捨てる
            if (i - k >= 0) {
                long outkey = s2[i - k];
                int val = map.getOrDefault(outkey, 0);
                map.put(outkey, --val);
            }
            
            // 捨ててから要素iを見る
            long key = s2[i];
            int cnt = map.getOrDefault(key, 0);
            
            ans += cnt;
            map.put(key, ++cnt);
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 81820
#include <bits/stdc++.h>
#include<math.h>
#include<algorithm> 
#define rep(i,n) for (int i = 0; i < (n) ; ++i)
using namespace std;
using ll = long long ;
using P = pair<int, int> ;
#define PI 3.14159265358979323846264338327950
#define INF 1e18
vector<int> mx = {1,0,-1,0} ;
vector<int> my = {0, 1, 0, -1} ;


int main () {
    int n, k ;
    cin >> n >> k ;
    vector<double> p (n) ;
    rep(i, n) cin >> p[i] ;
    double mx = 0 ;
    int st = 0 ;
    double pos = 0 ;
    rep(i, k){
        pos += p[i] ;
    }
    rep(i, n - k + 1){
        if(i == 0) continue ;
        pos -= p[i - 1] ;
        pos += p[i + k - 1] ;
        if(pos > mx){
            mx = pos ;
            st = i ;
        }
    }
    double ans = 0 ;
    for(int i = st; i < st + k; i++){
        double sum = (1 + p[i])*p[i]/ 2 ;
        double f = sum * (1/p[i]) ;
        ans += f ;
    }
    cout << fixed << setprecision(10) ;
    cout << ans << endl ;
}

Measured memory_bytes: 4824
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < n; i++)

using namespace std;

void solve() {
  string N;
  cin >> N;
  if (
      (N[0] == N[1] and N[0] == N[2]) or
      (N[1] == N[2] and N[1] == N[3])
  ) cout << "Yes" << endl;
  else cout << "No" << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  solve();
  return 0;
}


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

int n, m;

ll bfs(vector<vector<ll>>& g, ll src, ll dest) {
    ll n = g.size();
    vector<ll> dist(n, INT_MAX);
    vector<bool> vis(n);
    queue<ll> q;
    q.push(src);
    dist[src] = 0;
    vis[src] = true;
    while (!q.empty()) {
        ll u = q.front();
        if (u == dest) {
            return dist[u];
        }
        q.pop();
        for (auto v : g[u]) {
            if (vis[v]) {
                continue;
            }
            q.push(v);
            vis[v] = true;
            dist[v] = min(dist[v], dist[u] + 1);
        }
    }
    return dist[dest];
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin >> n >> m;
    vector<string> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    ll ans = 0;
    vector<vector<ll>> g(n * m);
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            int node = i * m + j;
            if (i > 0 && a[i - 1][j] == '.') {
                g[node].emplace_back(node - m);
            }
            if (i < n - 1 && a[i + 1][j] == '.') {
                g[node].emplace_back(node + m);
            }
            if (j < m - 1 && a[i][j + 1] == '.') {
                g[node].emplace_back(node + 1);
            }
            if (j > 0 && a[i][j - 1] == '.') {
                g[node].emplace_back(node - 1);
            }
        }
    }
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            if (a[i][j] == '#') {
                continue;
            }
            for (int p = 0; p < n; ++p) {
                for (int q = 0; q < m; ++q) {
                    if (a[p][q] == '#') {
                        continue;
                    }
                    ll temp = bfs(g, i * m + j, p * m + q);
                    if (temp != INT_MAX) {
                        ans = max(ans, temp);
                    }
                }
            }
        }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 256