akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

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

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }

#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }

template<class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template<class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template<class T, class V>
typename enable_if<is_class<T>::value == 0>::type fill(T &t, const V &v) {
    t = v;
}
template<class T, class V>
typename enable_if<is_class<T>::value != 0>::type fill(T &t, const V &v){
    for (auto &e : t) fill(e, v);
}




long long solve(long long N) {
    if (N == 0) return 0;
    if (N == 1) return 1;

    long long res = 1;
    res += solve(N/2) * 2;
    return res;
}

int main() {
    //ios::sync_with_stdio(false);
    //cin.tie(0);
    long long N;
    while (cin >> N) {
        cout << solve(N) << endl;
    }
}


















Measured memory_bytes: 256
def main():
    N = int(input())
    num = [int(input()) for _ in range(5)]
    num.sort()
    temp = 0
    temp = N // num[0]
    if N%num[0] == 0:
        ans = temp
    else:
        ans = temp + 1

    ans += 4
    return ans

print(main()) 



Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int N, M, a[100], b[100];

int e[10][10];
vector<int > V;

int CHECK(void) {

	int cur = 1;

	for (int i = 0; i <= N - 2; i++) {
		int next = V[i];
		if (e[cur][next] == 0) { return -1; }
		cur = next;
	}
	return 1;
}

int main(void) {

	cin >> N >> M;

	for (int i = 1; i <= M; i++) {
		cin >> a[i] >> b[i];
		e[a[i]][b[i]] = 1;
		e[b[i]][a[i]] = 1;
	}

	

	for (int i = 2; i <= N; i++) { V.push_back(i); }
	int ans = 0;
	do {
		if (CHECK() == 1) { ans++; }
	} while (next_permutation(V.begin(), V.end()));

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

Measured memory_bytes: 256
a,b,c,x,y = map(int,input().split())
print(min((min(x,y)*min(a+b,2*c) + (max(x,y)-min(x,y))*(max(x,y)==y)*b + (max(x,y)-min(x,y))*(max(x,y)==x)*a), max(x,y)*2*c))
  


Measured memory_bytes: 8864
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int N = 1e5 + 10;
const int MAX = 1e5 + 10;

inline int max(int a, int b) { return a > b ? a : b; }
inline int min(int a, int b) { return a > b ? b : a; }

int main() {
    int a, b;
    cin >> a >> b;
    int x = a * 25 / 2;
    for (int i = x;; ++i) {
        if (int(i * 0.08) == a && int(i * 0.1) == b) {
            cout << i;
            return 0;
        }
        if (int(i * 0.1) > b) {
            break;
        }
    }
    cout << -1;
}

Measured memory_bytes: 256
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;

class Solution {
public:
    int solve(string& s) {
        int n = s.length();
        const int INF = 1 << 24;
        vector<int> dp(2, INF);
        dp[0] = 0;
        vector<int> ndp(2, INF);

        for (int i = n - 1; i >= 0; --i) {
            fill(ndp.begin(), ndp.end(), INF);

            for (int j = 0; j < 2; ++j) {
                for (int k = 0; k < 2; ++k) {
                    for (int d = 0; d < 10; ++d) {
                        int cnt = dp[k] + d + j - k;
                        int rem = d + j * 10 - k;
                        rem -= s[i] - '0';
                        // cout << i << " " << d << " " << k << " " << rem << " " << j << " " << cnt + rem << endl;
                        if (rem >= 0 && rem < 10) {
                            ndp[j] = min(ndp[j], cnt + rem);
                            // cout << "ndp " << j << " " << ndp[j] << endl;

                        }
                    }
                }
            }
            swap(ndp, dp);
            // cout << i << " " << dp[0] << " " << dp[1] << endl;
        }
        // cout << dp[0] << " " << dp[1] << endl;
        int res = min(dp[0], dp[1]);
        return res;
    }
};

int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    string s;
    cin >> s;
    Solution sol;
    cout << sol.solve(s) << "\n";

    return 0;
}

Measured memory_bytes: 1948
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define endl '\n'
#define debug(x) std::cerr << #x << " = " << (x) << endl;

using ll = long long;
using P = std::pair<ll, ll>;

constexpr ll INF = 1ll<<60;

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

template<class S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

ll A, B, K;

int main() {
  std::cin >> A >> B >> K;

  A -= K;

  if( A < 0 )
    K = -A, A = 0;
  else
    K = 0;

  B -= K;

  chmax( B, 0ll );

  std::cout << A << ' ' << B << endl;

  return 0;
}

Measured memory_bytes: 3604
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;
int main() {

	string s;
	cin >> s;
	int count = 0;
	for (int i = 0; i < 4; i++) {
		if (s[i] == '+')
			count++;
		else
			count--;
	}

	cout << count << endl;

	return 0;
}

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

using namespace std;

int main()
{
  int R, G, B, N;
  cin >> R;
  cin >> G;
  cin >> B;
  cin >> N;

  int ans = 0;
  int maxR = N / R;
  for (int r = 0; r <= maxR; r++) {
    int maxG = (N - R * r) / G;
    for (int g = 0; g <= maxG; g++) {
      if ((N - R * r - G * g) % B == 0) {
        ans += 1;
      }
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
import sys
import math
sys.setrecursionlimit(10**6)
from collections import defaultdict

n,k=map(int,input().split())
ans=0
for i in range(1,n+1):
    if i>=k:
        ans+=1/n
    else:
        ans+=1/(n*2**int(1-1/(10**9)+math.log((k/i),2)))
#print(i,2**int(math.log((k/i),2)),ans)
print(ans)


Measured memory_bytes: 38768
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int arr[100000];
int main() {
	int n; cin >> n;
	int mid = n / 2 - 1;
	int count = 0;
	for (int i = 0; i < n; i++) {
		cin >> arr[i];
	}
	sort(arr, arr + n);
	if (arr[mid] == arr[mid + 1]) { cout << 0 << endl; }
	else { cout << arr[mid + 1] - arr[mid] << endl; }
	return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

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

typedef unsigned long long ul;
ul a,b;

int main(){
  cin >> a >> b;
  ul tmp=a;
  int ans = 0;
  while(tmp<=b){
    tmp *= 2;
    ans += 1;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (ll i=0; i<(n); ++i)
typedef long long ll;
bool debug=false;
string yes = "Yes";
string no = "No";
const int MAX = 1000000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; 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;
    }
}

// 二項係数計算
long long COM(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;
}

int main(){
  ll x,y; cin >> x >> y;
  if((x+y)%3!=0){
    cout << 0 << endl;
    return 0;
  }
  COMinit();
  ll n=(2*y-x)/3, m=(2*x-y)/3;
  if(n<0||m<0){
    cout << 0 << endl;
    return 0;
  }
  cout << COM(n+m, n) << endl;
  return 0;
}



Measured memory_bytes: 23680
#include <bits/stdc++.h>
#define rep(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
using namespace std;
using ll = int64_t;
const int MOD = 1000000007; // 10^9+7

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

    rep(i, 0, s.size())
        cout << 'x';
    cout << endl;
}


Measured memory_bytes: 256
A,B,K=$<.read.split.map(&:to_i)

if B-K+1 <= A+K-1
    A.upto(B) do |n|
        puts n
    end
else
    A.upto(A+K-1) do |n|
        puts n
    end
    (B-K+1).upto(B) do |n|
        puts n
    end
end

# A.upto([A+K-1,B].min) do |n|
#     puts n
# end
# [B-K+1,A+K].max.upto(B) do |n|
#     puts n
# end


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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main() {
  int m1, m2, d1, d2;
  cin >> m1 >> d1 >> m2 >> d2;

  cout << ((m1 == m2) ? 0 : 1) << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<list>
#include<vector>
#include<algorithm>
#include<string>
#include<stdio.h>
#include<math.h>
#include<unordered_map>
#include<map>
#include<set>

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using lst = list<ll>;

ll MOD = 1000000007;




int  main()
{
	int N;
	string S;

	cin >> N >> S;

	int lb = -1, ub = N;

	while (ub - lb > 1)
	{
		int mid = (lb + ub) / 2;
		//cout << lb << " " << ub << endl;
		//cout << mid << endl;
		map<string, int> mp;

		for (int i = 0; i < N - mid + 1; ++i)
		{
			string sub = S.substr(i, mid);
			//cout << sub << endl;
			if (mp.count(sub))
			{
				if (mp[sub] + mid <= i)
				{
					lb = mid;
					break;
				}
			}
			else
			{
				mp[sub] = i;
			}
		}
		if (lb != mid)
		{
			ub = mid;
		}
	}
	//cout << lb << " " << ub << endl;
	cout << ub-1 << endl;

	return 0;
}

Measured memory_bytes: 6672
kaibunkai = input()
n = len(kaibunkai)
zenhan = kaibunkai[:(n-1)//2]
kouhan = kaibunkai[(n+3)//2-1:]


def kaibun_desuka(bun):
  s = len(bun)
  for x in range(s//2):
    if bun[x] != bun[-x-1]:
      return False
  return True

if kaibun_desuka(kaibunkai) and kaibun_desuka(zenhan) and kaibun_desuka(kouhan):
  print("Yes")

  
else:
  print("No")
    
  

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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vs = vector<string>;
using vvs = vector<vs>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "(" << p.first << "," << p.second << ")";
    return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "{";
    rep(i, (int)v.size()) {
        if (i)
            os << ",";
        os << v[i];
    }
    os << "}";
    return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
    for (auto val : array)
        std::cout << val << ", ";
    std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << std::setprecision(10);

    int h, w; std::cin >> h >> w;
    int ch, cw; std::cin >> ch >> cw; ch--, cw--;
    int dh, dw; std::cin >> dh >> dw; dh--, dw--;
    vs grid(h); rep (i, h) std::cin >> grid[i];
    vvi cost(h, vi(w, 1e9));
    vvi visited(h, vi(w, 0));

    deque<pi> dq;
    cost[ch][cw] = 0;
    dq.emplace_back(ch, cw);
    while (dq.size()) {
        int y = dq.front().fi, x = dq.front().se; dq.pop_front();
        if (visited[y][x]) continue;
        visited[y][x] = true;
        srep(dy, -2, 3) srep(dx, -2, 3) if (dy*dy + dx*dx != 0) {
            int ny = y + dy, nx = x + dx;
            if (ny < 0 || ny >= h || nx < 0 || nx >= w) continue;
            if (grid[ny][nx] == '#') continue;
            bool isWarp = (dy*dy + dx*dx > 1);
            if (cost[ny][nx] <= cost[y][x]+isWarp) continue;
            cost[ny][nx] = cost[y][x] + isWarp;
            if (isWarp) dq.emplace_back(ny, nx);
            else dq.emplace_front(ny, nx);
        }
    }

    std::cout << (cost[dh][dw] != 1e9 ? cost[dh][dw] : -1) << "\n";
}


Measured memory_bytes: 12620
n,w = map(int,input().split())
wv = [list(map(int,input().split())) for _ in range(n)]
dp = [[0]*(w+1) for _ in range(n+1)]
for i in range(n):
    wi, vi = wv[i]
    for j in range(w+1):
        if j<wi:
            dp[i+1][j] = dp[i][j]
        else:
            dp[i+1][j] = max(dp[i][j], dp[i][j-wi]+vi)
            
print(dp[n][w])

Measured memory_bytes: 119916
A,B,K=map(int,input().split())
if B-A>=2*K:
    for i in range(A,A+K-1+1):
        print(i)
    for i in range(B-K+1,B+1):
        print(i)
    exit()
else:
    for i in range(A,B+1):
        print(i)

Measured memory_bytes: 9088
#include<iostream>
using namespace std;
int main(){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    if(abs(c - a) <= d || (abs(a - b) <= d && abs(b -c) <= d)){
        cout << "Yes" << endl;
    }else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val s = sc.next()
    println(problem146b(n, s))
}

fun problem146b(n: Int, s: String): String {
    val alphabets = listOf(
        'A',
        'B',
        'C',
        'D',
        'E',
        'F',
        'G',
        'H',
        'I',
        'J',
        'K',
        'L',
        'M',
        'N',
        'O',
        'P',
        'Q',
        'R',
        'S',
        'T',
        'U',
        'V',
        'W',
        'X',
        'Y',
        'Z',
        'A',
        'B',
        'C',
        'D',
        'E',
        'F',
        'G',
        'H',
        'I',
        'J',
        'K',
        'L',
        'M',
        'N',
        'O',
        'P',
        'Q',
        'R',
        'S',
        'T',
        'U',
        'V',
        'W',
        'X',
        'Y',
        'Z'
    )
    var result = ""
    for (i in 0 until s.length) {
        result += alphabets[alphabets.indexOf(s[i]) + n]
    }
    return result
}

Measured memory_bytes: 120244
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    int n, q;
    cin >> n >> q;
    vector<int> a(n);
    for (int i = 0; i < n; i++)cin >> a[i];
    sort(a.begin(), a.end());
    for (int i = 0; i < q; i++) {
        int l, r;
        cin >> l >> r;
        cout << upper_bound(a.begin(), a.end(), r) - lower_bound(a.begin(), a.end(), l) << endl;
    }
    return 0;
}



Measured memory_bytes: 3164
n=int(input())
arr=[int(i) for i in input().split()]
if 0 in arr:
    print(0)
    exit()
f=1 
prod=1 
for i in arr:
    prod*=i 
    if prod>10**18:
      f=0 
      break
        
print(prod if f else -1)

Measured memory_bytes: 21784
import Data.List

fiftyFifty :: String -> Bool
fiftyFifty (a:b:c:d:_)
    | a == b && c == d && a /= c = True
    | a == c && b == d && a /= b = True
    | a == d && b == c && a /= b = True
    | otherwise = False

main = do
  s <- getLine
  putStrLn $ if fiftyFifty s then "Yes" else "No"


Measured memory_bytes: 380
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

int main(){
  ll N, K;
  cin >> N >> K;
  vl H(N);
  rep(i, N) cin >> H[i];

  if(N <= K){
    cout << 0 << "\n";
    return 0;
  }

  stable_sort(H.begin(), H.end(), greater<ll>());

  ll ans = 0;

  rep2(i, K, N) ans += H[i];

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


Measured memory_bytes: 5536
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>

#define pb push_back
#define mp make_pair

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef unsigned long long ull;
typedef long long ll;

int main() {
  int n;
  vector<ll> a;

  cin >> n; n*= 3;
  while (n--) {
    ll k;
    cin >> k;

    a.pb(k);
  }

  sort(a.begin(), a.end(), greater<ll>());

  // 5 2 8 5 1 5
  // 8 5 5 5 2 1
  ll res = 0;
  for (int i = 0; i < a.size()/3; ++i) {
  	res += a.at(i*2+1);
  } 

  cout << res << endl;
  return 0;
}


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

using namespace std;

int main(void){
    map<string, int> ball;

    string s, t, u;
    int a,b;

    cin >> s >> t >> a >> b >> u;

    ball[s] = a;
    ball[t] = b;

    ball[u]--;
    
    cout << ball[s] << " " << ball[t] << endl;

    return 0;
}

Measured memory_bytes: 256
N, M, K = map(int, input().split())
A_temp = [int(i) for i in input().split()]
B_temp = [int(i) for i in input().split()]

A, B = [0]*(N+1), [0]*(M+1)
for i in range(1, N+1):
    A[i] = A[i-1] + A_temp[i-1]
for i in range(1, M+1):
    B[i] = B[i-1] + B_temp[i-1]

ans = 0
b = M
for a in range(N+1):
    if A[a] > K:
        break
    while B[b] > K - A[a]:
        b -= 1
    ans = max(ans, a + b)
print(ans)

Measured memory_bytes: 48600
//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin, output: process.stdout
});
var obj; var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  console.error("\n");
  var start = Date.now();
  Main();
  var end = Date.now() - start;
  myerr("time : " + end + "ms");
  myerr("memory : " + Math.round(process.memoryUsage().heapTotal / 1024) + "KB");
});
function makeClone(obj){return JSON.parse(JSON.stringify(obj));}
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){  
  return {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw "ArrayIndexOutOfBoundsException ‚There is no more input";}}
  };
}
function myout(s){console.log(s);}
function myerr(s){console.error("debug:" + require("util").inspect(s,false,null));}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map(Number);case 6:return i.split("");case 7:return i.split("").map(Number);case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
  var one = nextStrArray().map(BigInt);
    var n = one[0];
    var a = one[1];
    var b = one[2];
    if(a>b||(n==1n&&a!=b)){
        console.log(0);
    }else{
        console.log(BigInt((b-a)*(n-2n)+1n).toString());
    }
}


Measured memory_bytes: 29980
import math

def koch(d,x1,y1,x2,y2):
    if d == 0:
        return

    xs = (2*x1+x2)/3
    ys = (2*y1+y2)/3
    xt = (x1+2*x2)/3
    yt = (y1+2*y2)/3

    xu = (xt-xs)*math.cos(math.pi/3) - (yt-ys)*math.sin(math.pi/3) + xs
    yu = (xt-xs)*math.sin(math.pi/3) + (yt-ys)*math.cos(math.pi/3) + ys


    koch(d-1,x1,y1,xs,ys)
    print(xs,ys)
    koch(d-1,xs,ys,xu,yu)
    print(xu,yu)
    koch(d-1,xu,yu,xt,yt)
    print(xt,yt)
    koch(d-1,xt,yt,x2,y2)
    
n = int(input())
print(0.00000000,0.00000000)
koch(n,0.0,0.0,100.0,0.0)
print(100.00000000,0.00000000)

Measured memory_bytes: 8056
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
typedef long long ll;

using namespace std;

int main()
{
	int n,m;
	ll x,y;
	ll ans=0;
	
	cin>>n>>m;
	x = m*1900+(n-m)*100;
	y = pow(2,m);
	ans = x*y;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
const int MAX = 510000;

int main() {
  ll N;
  cin >> N;
  if (N%2==1) cout << 0 << endl;
  else {
    ll res = 0, den = 10;
    while (den<=N) {
      res += N/den;
      den *= 5;
    }
    cout << res << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
  int A, B;
  int result[3];

  scanf("%d %d", &A, &B);

  result[0] = A + B;
  result[1] = A - B;
  result[2] = A * B;

  sort(result, result + 3);

  printf("%d\n", result[2]);

  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <map>
#define ONLINE_JUDGE
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdio>
#define pii pair<int, int>
#define makep make_pair
#define pb push_back
#define fi first
#define se second
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

int main0 ();
int main () {
	#ifndef ONLINE_JUDGE
		freopen("C:\\Users\\98497\\Desktop\\code\\file.in", "r", stdin);
	#endif
	ios::sync_with_stdio(false);
	main0();
	#ifndef ONLINE_JUDGE
		fclose(stdin);
	#endif
	return 0;
}

const int INF = 0x3f3f3f3f;
const int N = 1e3;
const int M = 1e6;

ll c[N], v[N];
ll dp[M];

int main0 () {
	int n, w;
	cin >> n >> w;
	for (int i = 1;i <= n;i++) {
		cin >> c[i] >> v[i];
	}
	
	memset(dp, 0, sizeof dp);
	for (int j = 1;j <= n;j++)
		for (int i = w;i >= c[j];i--)
			dp[i] = max(dp[i], dp[i - c[j]] + v[j]);
	cout << dp[w] << endl;
}


Measured memory_bytes: 8064
N, K = [int(i) for i in input().split()]
A = [0] + [int(i) for i in input().split()]
B = [1]
s = set()
s.add(1)
while(True):
    tmp = A[B[-1]]
    if not tmp in s:
        B.append(tmp)
        s.add(tmp)
    else:
        head = B.index(tmp)
        break
if K >= len(B[:head]):
    K = (K - len(B[:head]))  % len(B[head:])
    print(B[head:][K])
else:
    print(B[K])

Measured memory_bytes: 128032
#-*- coding: utf-8 -*-
n = int(input())
ans = [0 for _ in range(10050)]
for i in range(1,105):
  for j in range(1,105):
    for k in range(1,105):
      v = i*i+j*j+k*k+i*j+j*k+k*i
      if v<10050:
        ans[v]+=1

for i in range(n):
  print(ans[i+1])

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

int main()
{
    int N, S;
    cin >> N >> S;
    vector<vector<string>> data;
    vector<bool> AryY(S);

    for (int i = 0; i < S; i++)
    {
        AryY.at(i) = false;
    }
    
    for (int i = 0; i < N; i++)
    {
        vector<string> A(S);
        bool flg = false;
        string str;
        cin >> str;
        for (int j = 0; j < S; j++){
            if (str[j] == '#') {
                flg = true;
                AryY.at(j) = true;
            }
            A.at(j) = str[j];
        }
        if (flg) data.push_back(A);
    }

    for (int i = AryY.size() - 1; i >= 0; i--)
    {
        if (!AryY.at(i)) {
            for (int j = 0; j < data.size(); j++)
            {
                data.at(j).erase(data.at(j).begin()+i);
            }
        }
    }

    for (int i = 0; i < data.size(); i++)
    {
        for (int j = 0; j < data.at(i).size(); j++)
        {
            cout << data.at(i).at(j);
        }
        cout << endl;
    }
}


Measured memory_bytes: 768
program abc40
 implicit none
 integer::N,ia,ib,ic,id,c=0
 integer,allocatable::L(:)
 read(*,*)N
 allocate(L(N))
 read(*,*)(L(ia),ia=1,N)
 do ib=1,N-2
  do ic=ib+1,N-1
   do id=ic+1,N
    if(iabs(L(ib)-L(ic))<L(id).and.L(ib)+L(ic)>L(id).and.L(ib)/=L(ic).and.L(ic)/=L(id).and.L(ib)/=L(id))then
     c=c+1
    end if
   end do
  end do
 end do
 print'(i0)',c
 deallocate(L)
end program abc40

Measured memory_bytes: 2928
#include <iostream>
#define N 100000
using namespace std;

int A[N];

int Partition(int n)
{
    int x = A[n - 1];
    int j = 0;
    for (int i = 0; i < n - 1; i++)
    {
        if (A[i] <= x)
        {
            swap(A[i], A[j]);
            j++;
        }
    }
    swap(A[j], A[n - 1]);
    return j;
}

int main()
{
    int n;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> A[i];
    }

    int t = Partition(n);

    for (int i = 0; i < n; i++)
    {
        if (i == t)
        {
            cout << '[';
        }
        cout << A[i];
        if (i == t)
        {
            cout << ']';
        }
        if (i != n - 1)
        {
            cout << ' ';
        }
    }
    cout << endl;

    return 0;
}


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


int main() {
	
	int N,cnt=0;
	cin >> N;
	vector<int> p(N);
	for(auto &i:p) cin >> i;
	for(int i=0; i<N-2; i++){
		if((p.at(i)<p.at(i+1))&&(p.at(i+1)<p.at(i+2))) cnt++;
		if((p.at(i)>p.at(i+1))&&(p.at(i+1)>p.at(i+2))) cnt++;
	}
	cout << cnt << endl;
	
	
	
	return 0;
}

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

int main()
{
  int n, time;
  cin >> n >> time;
  vector<int> c(n);
  vector<int> t(n);
  int i;
  int cmin = 1001;
  for(i = 0; i < n; i++)
  {
    cin >> c.at(i) >> t.at(i);
    if(t.at(i) <= time && c.at(i) < cmin)
    {
      cmin = c.at(i);
    }
  }
  if(cmin == 1001) cout << "TLE" << endl;
  else cout << cmin << endl;
}

Measured memory_bytes: 256
//Contains functions for implementing a disjoint set union
#include<bits/stdc++.h>
using namespace std;
//#define num 1000000007
#define num 998244353
#define inf 1000000000000000000ll
#define REP(i,a,n) for(ll i=a;i<n;i++)
#define inarr(i,a,n,A) for(ll i=a;i<n;i++) { cin>>A[i]; }
#define vll vector<long long>
#define pi pair <int,int>
#define pll pair<long long, long long>
#define vpii vector< pair <int,int>>
#define vpll vector< pair<long long, long long>>
#define max(a,b) (a>b)?a:b
//#define min(a,b) (a>b)?b:a
#define max3(a,b,c) (a>b)?(a>c)?a:c:(b>c)?b:c
#define min3(a,b,c) (a<b)?(a<c)?a:c:(b<c)?b:c
#define avg(a,b) ((a)+(b))/2
//#define push push_back
//#define pop pop_back
#define mp make_pair
#define sf int flag=0     //Remember semicolon
#define assmin(a,b) if(b<=a) { a=b; }
#define assmax(a,b) if(b>=a) { a=b; }
#define fir first
#define sec second
#define mod(a) ((a)>0)?(a):(-(a))
 
 
typedef long long ll;
 
ll next(ll a, ll n)
{
    return (a==n-1)?0:a+1;
}
ll parent[1000005],size[1000005],  tail[300005];
set<ll> cur_par;
ll n,m,q;
ll pos(ll x,ll y)
{
    return (m*(x-1))+y;
}
void init_parent(ll n)
{
    memset(parent,-1,sizeof(parent[0])*n);
}
void make_set(ll v)
{
    parent[v]=v;
    ::size[v]=1;
    tail[v]=v;
}
ll find_set(ll v)
{
    if(parent[v]==v)
    return v;
    return parent[v]=find_set(parent[v]);
}
void union_sets(ll a,ll b, ll A[])
{
    a=find_set(a);
    b=find_set(b);
    if(a==b)
    return;
    if(::size[a]<::size[b])
    {
        swap(a,b);
    }
    parent[b]=a;
    ::size[a]+=::size[b];
    A[a] = min(A[a], A[b]);
}
ll prev(ll a,ll n)
{
    if(a==0)
    return n-1;
    return a-1;
}
ll nex(ll a,ll n)
{
    if(a==n-1)
    return 0;
    else
    return a+1;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll k;
    cin>>k;
    ll tot=0;
    REP(i,1,k+1)
    {
        REP(j,1,k+1)
        {
            REP(p,1,k+1)
            {
                ll g= __gcd(i,j);
                g= __gcd(g,p);
                tot+=g;
            }
        }
    }
    cout<<tot<<endl;
    return 0;
}

Measured memory_bytes: 3696
package main

import (
	"bufio"
	"fmt"
	"io"
	"log"
	"os"
	"strconv"
	"strings"
)

// Node  ノード
type Node struct {
	id     int
	parent *Node
	left   *Node
	right  *Node
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	n := eGetInt(reader)

	nodes := make([]*Node, n)
	for i := 0; i < n; i++ {
		nodes[i] = &Node{i, nil, nil, nil}
	}

	for i := 0; i < n; i++ {
		ints := eGetInts(reader)
		current := nodes[ints[0]]

		if ints[1] != -1 {
			left := nodes[ints[1]]
			current.left = left
			left.parent = current
		}
		if ints[2] != -1 {
			right := nodes[ints[2]]
			current.right = right
			right.parent = current
		}
	}
	printNode(nodes)
}

func (n *Node) parentNum() int {
	if n.parent == nil {
		return -1
	}
	return n.parent.id
}
func (n *Node) siblingNum() int {
	if n.parent == nil {
		return -1
	}
	if n.parent.left == nil || n.parent.right == nil {
		return -1
	}
	if n.parent.left == n {
		return n.parent.right.id
	}
	return n.parent.left.id
}
func (n *Node) degree() int {
	if n.left == nil && n.right == nil {
		return 0
	}
	if n.left != nil && n.right != nil {
		return 2
	}
	return 1
}
func (n *Node) name() string {
	if n.parent == nil {
		return "root"
	}
	if n.left == nil && n.right == nil {
		return "leaf"
	}
	return "internal node"
}
func (n *Node) depth() int {
	p := n.parent
	d := 0
	for p != nil {
		p = p.parent
		d++
	}
	return d
}

func (n *Node) height() int {
	if n.left == nil && n.right == nil {
		return 0
	}
	if n.left != nil && n.right != nil {
		l := n.left.height()
		r := n.right.height()
		if l > r {
			return 1 + l
		}
		return 1 + r
	}
	if n.left != nil {
		return 1 + n.left.height()
	}
	return 1 + n.right.height()
}

func printNode(nodes []*Node) {
	for _, v := range nodes {
		fmt.Printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, %s\n", v.id, v.parentNum(), v.siblingNum(), v.degree(), v.depth(), v.height(), v.name())
	}
}

func eGetLine(r *bufio.Reader) string {
	s, err := r.ReadString(byte('\n'))
	if err != nil {
		if err != io.EOF {
			log.Fatal(err.Error())
		}
		return s
	}
	return strings.TrimRight(s, "\r\n")
}
func eGetInt(r *bufio.Reader) int {
	line := eGetLine(r)
	return eAtoi(line)
}
func eGetInts(r *bufio.Reader) []int {
	line := eGetLine(r)
	fields := strings.Split(line, " ")
	var ints []int
	for _, f := range fields {
		ints = append(ints, eAtoi(f))
	}
	return ints
}
func eAtoi(s string) int {
	n, err := strconv.Atoi(s)
	if err != nil {
		log.Fatal(err)
	}
	return n
}



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

#define int long long
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
template<class T,class U>inline void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>inline void chmax(T &t,U f){if(t<f)t=f;}

int N;
int dp[1<<16];

void solve(){
    memset(dp,0,sizeof(dp));
    rep(i,N){
        int S,L;cin>>S>>L;
        int b=0;
        rep(j,S){
            int x,y;
            cin>>x>>y;x-=6;y-=6;
            reps(k,x,y)b|=(1<<k);
        }
        for(int i=(1<<16)-1;i>=0;i--){
            if(i&b)continue;
            chmax(dp[i|b],dp[i]+L);
        }
    }
    cout<<*max_element(dp,dp+(1<<16))<<endl;
}

signed main(){
    while(cin>>N,N)solve();
    return 0;
}

Measured memory_bytes: 3620
mod = 1000000007
MOD = 998244353
ii = lambda :  int(input())
si = lambda :  input()
dgl = lambda : list(map(int, input()))
f = lambda :   map(int, input().split())
il = lambda :  list(map(int, input().split()))
it = lambda :  tuple(map(int, input().split()))
ls = lambda :  list(input())
n=ii()
print(((n+1)//2)/n)

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

int z(int a, int b){
    int c = a - b;
    if(c < 0) c = -c;

    return c;
}


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

    vector<int> A;
    rep(i, n){
        int tmp;
        cin >> tmp;
        A.push_back(tmp);
    }

    int ans = 100;

    int s1, s2=0;
    s1 = A[0];
    rep(i, n) s2+=A[i];
    s2 -= A[0];

    ans = z(s1, s2);

    for(int i=1;i<n;i++){
        s1 += A[i];
        s2 -= A[i];
        if(ans > z(s1, s2))
            ans = z(s1, s2);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <limits>
#include <numeric>
#include <set>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<string> vs;

#define PI 3.14159265359
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repz(i,n) rep(i,0,n)


int main() {
	string a, b;
	cin >> a >> b;
	cout << b + a << endl;



	return 0;
}

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

int main() {
	string a;
	priority_queue<int> S;
	while (cin >> a, "end" != a) {
		if ("extract" == a) {
			cout << S.top() << endl;
			S.pop();
		}
		else {
			int k;
			cin >> k;
			S.push(k);
		}
	}
}


Measured memory_bytes: 6968
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;
typedef long long ll;
#define REP(i,n) for (int i = 0; i < n; i++)

int main ()
{
    ll N,M;
    cin >> N >> M;

    vector < ll > A(N);
    REP(i,N) cin >> A[i];

    priority_queue < pair < ll, int > > que;
    REP(i,N) que.push(make_pair(A[i], i));

    REP(i,M) {
        pair < ll,int > t = que.top();
        que.pop();
        t.first /= 2;
        que.push(t);
    }

    ll ans = 0;
    while (que.size() > 0) {
        ans += que.top().first;
        que.pop();
    }

    cout << ans << endl;

    return 0;
}


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

using namespace std;

#define llong long long int
#define ldouble long double
#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) x.begin(), x.end()
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)

const static int MOD = 1000000000 + 7;
const static llong INF = 1LL << 60;
const static int dy[] = {0, 1, 0, -1};
const static int dx[] = {1, 0, -1, 0};

template<typename T> T my_gcd(T a, T b) {
    return (a ? my_gcd(b % a, a) : b);
}

template<typename T> T my_lcm(T a, T b){
	return a * b / my_gcd(a, b);	
}

struct UF {
    vector<int> par, sz;

    UF(int n) {
        par.resize(n);
        sz.resize(n);
        for (int i = 0; i < n; ++i) {
            par[i] = i;
            sz[i] = 1;
        }
    }

    int find_root(int x) {
        return par[x] == x ? x : par[x] = find_root(par[x]);
    }

    bool same(int x, int y) {
        return find_root(x) == find_root(y);
    }

    void unite(int x, int y) {
        x = find_root(x);
        y = find_root(y);
        if (x == y) return;
        
        if (sz[x] < sz[y]) swap(x, y);
        sz[x] += sz[y];
        par[y] = x;
    }
};

signed main (int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n, m;
    cin >> n >> m;
    vector<int> ball(n, 1);
    vector<bool> possibility(n, false);
    possibility[0] = true;
    rep(i, m) {
        int x, y;
        cin >> x >> y;
        --ball[x - 1];
        ++ball[y - 1];
        if (possibility[x - 1]) possibility[y - 1] = true;
        if (ball[x - 1] == 0) possibility[x - 1] = false;
    }

    int ans = 0;
    rep(i, n) {
        if (possibility[i]) ++ans;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 640
# B - Ordinary Number

def main():
	n = int(input())
	p = list(map(int,input().split()))
	count = 0
	for i in range(1, n-1):
		if check(p, i):
			count += 1
	print(count)

def check(p, i):
	if ((p[i -1] < p[i]) and (p[i] < p[i + 1])) or ((p[i -1] > p[i]) and (p[i] > p[i + 1])):
		return True
	else:
		return False

main()

Measured memory_bytes: 3060
<?php

while (true) {
    list($x, $y) = array_map("intval", explode(' ', trim(fgets(STDIN))));

    if ($x == 0 and $y == 0) {
        break;
    } else {
        if ($x > $y) {
            echo "{$y} {$x}\n";
        } else {
            echo "{$x} {$y}\n";
        }
    }
}




Measured memory_bytes: 9240
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF 1e18
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define PI (acos(-1))

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


int main() {
    int N;
    cin >> N;
    int tmp, tmp1 = 0, s = 0;
    REP(i, N){
        cin >> tmp;
        tmp1 = max(tmp1, tmp);
        s += tmp;
    }
    s -= tmp1 / 2;

    cout << s << endl;


    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 30;

string s;

int dfs(string t) {
  if (t.size() > s.size() || (t.size() == s.size() && t > s))
    return 0;
  int res = 1;
  for (auto x : {'7', '5', '3'})
    if (!count(t.begin(), t.end(), x))
      res = 0;
  return res + dfs(t + "7") + dfs(t + "5") + dfs(t + "3");
}

int main() {
  cin >> s;
  cout << dfs("") << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

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

		@SuppressWarnings("resource")
		Scanner scan = new Scanner(System.in);

		int r = scan.nextInt();
		int g = scan.nextInt();
		int b = scan.nextInt();

		int ans;
		
		ans =100*r+10*g+b;
		
		if(ans % 4 == 0){
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}
}


Measured memory_bytes: 21460
#include <bits/stdc++.h>
using namespace std;
const int64_t MOD = 1e9 + 7;
int main() {
    #ifdef DEBUG
    std::ifstream in("/home/share/inputf.in");
    std::cin.rdbuf(in.rdbuf());
    #endif
    int N;
    string S;
    map<char, int64_t> m;
    cin >> N;
    cin >> S;
    for(int i = 0; i < N; i++) {
        if(m.count(S[i]) == 0) {
            m[S[i]] = 0;
        }
        m[S[i]]++;
    }
    int64_t ans = 1;
    for(auto itor = m.begin(); itor != m.end(); itor++) {
        // "選ばない" も選択肢
        ans *= (*itor).second + 1;
        ans %= MOD;
    }
    // 空文字は除く
    ans--;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
h, w = map(int, input().split())
a = []
for i in range(h):
    a.append(input())
x = []
x.append("#"*(w+2))
for i in range(h):
    x.append("#"+a[i]+"#")
x.append("#"*(w+2))

for i in range(h+2):
    print(x[i])

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define show(x) for(auto i: x){cout << i << " ";}
typedef long long ll;

int nummap[10][10] = {0};

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


    rep(i, n){
        int sento;
        int matu;
        int ip = i+1;
        matu = ip % 10;

        sento = ip;
        while(sento >= 10){
            sento /= 10;
        }
        nummap[sento][matu]++;
    }

    ll ans = 0;
    rep(i, 10){
    rep(j, 10){
        ans += nummap[i][j] * nummap[j][i];
        //cout << nummap[i][j] << " ";
    }
    //cout << endl;
    }
    cout << ans << endl;

}


Measured memory_bytes: 256
import math, itertools

L, A, B, mod = [int(_) for _ in input().split()]


def sum_ri(r, n, mod):
    #1,r,...,r**(n-1)
    if r == 1:
        return n % mod
    else:
        #(r**n-1)/(r-1)=Q*mod+R
        #R**n-1=Q*mod*(r-1)+R*(r-1)
        return (pow(r, n, mod * (r - 1)) - 1) // (r - 1) % mod


def sum_iri(r, n, mod):
    #0,1*r,...,(n-1)*r**(n-1)
    if r == 1:
        return n * (n - 1) // 2 % mod
    else:
        r1 = r - 1
        p = pow(r, n, mod * r1**2)
        ret = (n - 1) * p * r1 + r1 - (p - 1)
        ret //= r1**2
        ret %= mod
        return ret


ans = 0

for digit in range(1, 20):
    #digit桁の総和
    #10**(digit-1)<=A+B*i<10**digit
    #(10**(digit-1)-A-1)//B+1<=i<=(10**digit-A-1)//B
    ileft = max(0, (10**(digit - 1) - A - 1) // B + 1)
    iright = min(L - 1, (10**digit - A - 1) // B)
    if L <= ileft:
        break
    if ileft > iright:
        continue
    idiff = iright - ileft + 1
    #ileft<=i<=iright
    #sum(ileft,iright) (A+B*i)10**(digit*(iright-i))
    #sum(0,iright-ileft)(A+B*iright-B*j))*(10**digit)**j
    pow10digit = pow(10, digit, mod)
    now = (A + B * iright) * sum_ri(pow10digit, idiff, mod)
    now -= B * sum_iri(pow10digit, idiff, mod)
    ans *= pow(10, digit * idiff, mod)
    ans += now
    ans %= mod
print(ans)


Measured memory_bytes: 9196
////////////////////////////////////
//          ,.                    //
//         (_|,.                  //
//        ,' /, )_______   _      //
//     __j o``-'        `.'-)'    //
//    (")                 \'      //
//     `-j                |       //
//        `-._(           /       //
//           |_\  |--^.  /        //
//          /_]'|_| /_)_/         //
//             /_]'  /_]'         //
//                                //
//           PIGMEISTER™          //
//                                //
////////////////////////////////////

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ull unsigned long long
#define mod (ll)1000000007
#define sidha(i, x, n) for(ll i=(ll)(x);i<(ll)(n);i++)
#define ulta(i, x, n) for(ll i=(ll)(x);i>=(ll)(n);i--)
#define mii map<ll, ll>
#define vi vector<ll>
#define pii pair<ll, ll>
#define pb push_back
#define mp make_pair
#define modInv(x) powah(x, mod-2)
#define test ll t;cin>>t;while(t--)
#define jaldi ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define endl '\n'
//ll powah(ll, ll);

vi dp(100005, -1), h;

ll minCost(ll n, ll k) {
    if (dp[n] > -1) return dp[n];

    if (n == 1)
        dp[n] = 0;
    else {
        ll miin = LLONG_MAX, limit = min(k+1, n);
        sidha (i, 1, limit)
            if (miin > minCost(n-i, k) + abs(h[n] - h[n-i]))
                miin = minCost(n-i, k) + abs(h[n] - h[n-i]);
        dp[n] = miin;
    }
    return dp[n];
}

int main()
{
    jaldi;
    
    ll n, k, a;
    cin >> n >> k;
    h.pb(0);
    sidha (i, 0, n) {
        cin >> a;
        h.pb(a);
    }
    cout << minCost(n, k) << endl;
    
    return 0;
}

// ll powah(ll x, ll y) { 
//     ll res = 1;
//     x = x % mod;
//     while (y > 0) { 
//         if (y & 1) 
//             res = (res*x) % mod; 
//         y = y>>1;
//         x = (x*x) % mod; 
//     } 
//     return res; 
// }

Measured memory_bytes: 8180
#include <iostream>
#include <string.h>
#include <vector>

int main () {
  int N;
  std::cin >> N;
  char s[N];
  std::cin >> s;

  // left = {WEST, EAST} right = {WEST, EAST}
  std::vector<char> left(2);
  std::vector<char> right(2);
  for (int i = 0; i < 2; i++) {
    left[i] = 0;
    right[i] = 0;  
  }


  int answer = 0;
  int answer_sub = 0;
  
  // for文で全体を見ていく.
  if ( N == 1 ) {
    std::cout << 1 << std::endl;
    return 0;  
  }


    // 最初に初期値について
  for (int i = 0; i < N; i++) {
    if (i == 0){
      (s[i] == 'W') ? left[0]++ : left[1]++ ;
    }
    else {
      (s[i] == 'W') ? right[0]++ : right[1]++ ;
      
      // 右側で右を向いている人を答える
      if (s[i] == 'E') {
        answer_sub++;
        answer++;  
      }  
    }  
  }
    // 右に切断箇所をずらしていく．
  for (int i = 1; i < N; i++) {
    
    // ずらしたことによるanswerの変更については，
    // s[i-1]とs[i]についてWW,WE,EW,EEの4通りある．

    if (s[i - 1] == 'E' && s[i] == 'E') {
      answer_sub --;
      if (answer_sub <= answer) {
        answer = answer_sub;
      }  
    }
    if (s[i-1] == 'W' && s[i] == 'W') {
      answer_sub++;  
    }

  }
  
  // answerを出力
  std::cout << answer << std::endl;

}


Measured memory_bytes: 512
#include<iostream>
#include<fstream>
#include<string>
#include<cstring>
#include<stdio.h>
#include<algorithm>
#include<functional>
#include<vector>
#include<set>
#include<queue>
#include<list>
#include<stdio.h>
#include<stdlib.h>
#include<map>
#include<cstdio>
#include <iomanip>
 
using namespace std;
 
typedef long long ll;
int N, M;
vector<pair<int, int>> E[201010];
vector<pair<int, int>> EE[201010];
int vis[201010], col[201010];
//---------------------------------------------------------------------------------------------------
#define no "No"
#define yes "Yes"
 
#define rep(i,a,b) for(int i=a;i<b;i++)
#define fore(i,a) for(auto &i:a)
 
string solve() {
	rep(i, 0, N) if (!vis[i]) {
		col[i] = 0;
		vis[i] = 1;
		queue<int> que;
		que.push(i);
		while (!que.empty()) {
			int q = que.front(); que.pop();
 
			fore(p, E[q]) {
				if (vis[p.first]) {
					if (col[q] + p.second != col[p.first]) return no;
				}
				else {
					col[p.first] = col[q] + p.second;
					vis[p.first] = 1;
					que.push(p.first);
				}
			}
 
			fore(p, EE[q]) {
				if (vis[p.first]) {
					if (col[q] - p.second != col[p.first]) return no;
				}
				else {
					col[p.first] = col[q] - p.second;
					vis[p.first] = 1;
					que.push(p.first);
				}
			}
		}
	}
 
	return yes;
}
//---------------------------------------------------------------------------------------------------
int main() {
	cin >> N >> M;
	rep(i, 0, M) {
		int a, b, c;
		cin >> a >> b >> c;
		a--; b--;
		E[a].push_back({ b, c });
		EE[b].push_back({ a, c });
	}
	cout << solve() << endl;
 
	return 0;
}

Measured memory_bytes: 17908