akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

typedef long long ll;
typedef long double ld;

const int Inf = 1e9;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    int h, w, n;
    cin >> h >> w >> n;
    cout << (n + max(h, w) - 1) / max(h, w) << endl;
    
    return 0;
}



Measured memory_bytes: 256
import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); } bool DEBUG = 0; 
void log(A ...)(lazy A a){ if(DEBUG) print(a); }
void print(){ writeln(""); } void print(T)(T t){ writeln(t); } void print(T, A ...)(T t, A a){ write(t, " "), print(a); }
string unsplit(T)(T xs){ return xs.array.to!(string[]).join(" "); }
string scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T scan(T)(){ return scan.to!T; } T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; }
T lowerTo(T)(ref T x, T y){ if(x > y) x = y; return x; } T raiseTo(T)(ref T x, T y){ if(x < y) x = y; return x; }

// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //

void solve(){
	Finite.mod = 998244353;
    int a = scan!int, b = scan!int, c = scan!int, d = scan!int;
    auto sf = new Finite[][](c + 1, d + 1);

    foreach(i; a .. c + 1) foreach(j; b .. d + 1){
        if(i == a && j == b) sf[i][j] = 1;
        else sf[i][j] = sf[i][j - 1] * i + sf[i - 1][j] * j
          - sf[i - 1][j - 1] * (i - 1) * (j - 1);
    }
    sf[c][d].print;
}

struct Finite{
	long value; static long mod = 1_000_000_007;
	this(long v){ value = val(v); }
	static long val(long v){ return (v + mod  - (v / mod) * mod) % mod; }
	bool opCast(T: bool)(){ return value != 0; }
	bool opEquals(Finite b){ return(value == b.value); }
	string toString(){ return value.to!string; }
 
	Finite opUnary(string s){ long v;
		if(s == "+") v = value;
		else if(s == "-") v = mod - value;
		else if(s == "++") v = value + 1;
		else if(s == "--") v = value + mod - 1;
		else assert(0, "Operator unary " ~ s ~ " not implemented");
		return Finite(v);
	}
 
	Finite opBinary(string s)(Finite b){ return opBinary!s(b.value); }
	Finite opBinary(string s)(long u){ long v;
		if(s == "+") v = value + u;
		else if(s == "-") v = value + mod - u;
		else if(s == "*") v = value * u;
		else if(s == "/") v = value * inv(u);
		else assert(0, "Operator " ~ s ~ " not implemented");
		return Finite(v);
	}
	Finite opBinaryRight(string s)(long u){ long v;
		if(s == "+") v = u + value;
		else if(s == "-") v = u + mod - value;
		else if(s == "*") v = u * value;
		else if(s == "/") v = u * invvalue;
		else assert(0, "Operator " ~ s ~ " not implemented");
		return Finite(v);
	}
	Finite opAssign(long v){ value = v; return this; }
 
	Finite opOpAssign(string s)(Finite b){ return opOpAssign!s(b.value); }
	Finite opOpAssign(string s)(long v){
		if(s == "+") value = (value + v) % mod;
		else if(s == "-") value = (value + mod - v) % mod;
		else if(s == "*") value = (value * v) % mod;
		else if(s == "/") value = (value * inv(v)) % mod;
		else assert(0, "Operator " ~ s ~ "= not implemented");
		return this;
	}
	
	private static long[] _inv = [0, 1];
	long invvalue(){ return inv(value); }
	long inv(long v){ int i = val(v).to!int;
		while(i >= _inv.length){
			_inv ~= _inv[(mod % $).to!int] * (mod - mod / _inv.length) % mod;
		}
		return _inv[i];
	}
	
}

Measured memory_bytes: 75356
//03
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

bool d[128][128];
bool a[128];

void dfs(char v){
  if(a[v]){
    a[v]=false;
    for(int i=0;i<128;i++){
      if(d[v][i]){
	dfs(i);
      }
    }
  }
}

int main(){
  for(int n;cin>>n,n;){
    char sv;
    int io[128]={};
    fill(d[0],d[128],false);
    fill(a,a+128,false);
    while(n--){
      string s;
      cin>>s;
      sv=s[0];
      io[s[0]]--;
      io[s.end()[-1]]++;
      d[s[0]][s.end()[-1]]=true;
      a[s[0]]=true;
    }
    bool ans=true;
    for(int i=0;i<128;i++){
      ans&=io[i]==0;
    }
    dfs(sv);
    for(int i=0;i<128;i++){
      ans&=!a[i];
    }
    cout<<(ans?"OK":"NG")<<endl;
  }
  return 0;
}

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

int main() {

	int n;
	cin >> n;
	map<string, long long> f;
	for (int i=0; i<n; i++) {
		string s;
		cin >> s;
		sort(s.begin(), s.end());
		f[s]++;
	}
	
	long long pairs = 0;
	
	for (map<string,long long>::iterator x=f.begin(); x!=f.end(); ++x) {
		long long c = x->second;
		pairs += (c * (c - 1));
	}
	
	cout << pairs / 2 << endl;
	
}


Measured memory_bytes: 11136
#if __has_include("../library/Basic/Debug.hpp")

#include "../library/Basic/Debug.hpp"

#else

/* ----- Header Files ----- */
// IO
#include <cstdio>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm
#include <algorithm>
#include <cmath>
#include <numeric>

// container
#include <vector>
#include <string>
#include <tuple>
#include <complex>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>

// others
#include <random>
#include <limits>
#include <functional>
#include <ctime>
#include <cassert>
#include <cstdint>


/* ----- Type Alias ----- */
using Bool = bool;
using Int = long long int;
using Real = long double;
using Char = char;
using String = std::string;
template <class T, class U>
using Pair = std::pair<T, U>;
template <class... Ts>
using Tuple = std::tuple<Ts...>;

template <class T>
using Vector = std::vector<T>;
template <size_t N>
using Bits = std::bitset<N>;
template <class T>
using Queue = std::queue<T>;
template <class T>
using Stack = std::stack<T>;
template <class T>
using Deque = std::deque<T>;

template <class T>
using MaxHeap = std::priority_queue<T>;
template <class T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;
template <class T>
using Set = std::set<T>;
template <class T, class U>
using Map = std::map<T, U>;

template <class T, class... Us>
using Func = std::function<T(Us...)>;

template <class T>
T genv(T v) { return v; }

template <class T, class... Ts>
auto genv(size_t l, Ts... ts) {
    return Vector<decltype(genv<T>(ts...))>(l, genv<T>(ts...));
}

template <class Cost = Int>
struct Edge {
    Int src, dst;
    Cost cost;
    Edge(Int src = -1, Int dst = -1, Cost cost = 1)
        : src(src), dst(dst), cost(cost){};

    bool operator<(const Edge<Cost>& e) const { return this->cost < e.cost; }
    bool operator>(const Edge<Cost>& e) const { return this->cost > e.cost; }
};

template <class Cost = Int>
using Edges = Vector<Edge<Cost>>;
template <class Cost = Int>
using Graph = Vector<Vector<Edge<Cost>>>;

#endif

/* ----- Misc ----- */
void fastio() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
}

struct Fout {
    Int precision;
    Fout(Int precision) : precision(precision) {}
};
std::ostream& operator<<(std::ostream& os, const Fout& fio) {
    os << std::fixed << std::setprecision(fio.precision);
    return os;
}


/* ----- Constants ----- */
// constexpr Int INF = std::numeric_limits<Int>::max() / 3;
// constexpr Int MOD = 1000000007;
// constexpr Real PI = acos(-1);
// constexpr Real EPS = 1e-10;
// std::mt19937 mt(int(std::time(nullptr)));

int main() {
    Int n;
    std::cin >> n;

    Vector<Int> a(n), b(n), c(n - 1);
    for (auto& x : a) {
        std::cin >> x;
        --x;
    }
    for (auto& x : b) std::cin >> x;
    for (auto& x : c) std::cin >> x;

    Int ans = 0;
    for (Int i = 0; i < n; ++i) {
        ans += b[a[i]];
        if (i + 1 < n && a[i + 1] == a[i] + 1) {
            ans += c[a[i]];
        }
    }

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


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

using namespace std;

#define llong long long int
#define ldouble long double
#define ternary(condition, x, y) ((condition) ? x : y) 
#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 llong MOD = 1000000000 + 7;
const static int dy[] = {0, 1, 0, -1};
const static int dx[] = {1, 0, -1, 0};

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

    int n, m;
    cin >> n >> m;

    llong sub_ans_x = 0;
    for (int i = 1; i <= n; ++i) {
        llong x;
        cin >> x;
        sub_ans_x += (i - 1) * x - (n - i) * x;
        sub_ans_x %= MOD;
    }

    llong sub_ans_y = 0;
    for (int i = 1; i <= m; ++i) {
        llong y;
        cin >> y;
        sub_ans_y += (i - 1) * y - (m - i) * y;
    }

    llong ans = (sub_ans_x % MOD) * (sub_ans_y % MOD);

    cout << ans % MOD << endl;

    return 0;
}

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

int n, k;
vector<ll> x, y;
vector<P> v;

bool check(int x1, int x2, int y1, int y2){
	int cnt = 0;
	rep(i, n){
		if(v[i].first < x[x1] || x[x2] < v[i].first) continue;
		if(v[i].second < y[y1] || y[y2] < v[i].second) continue;
		cnt++;
	}
	return cnt >= k;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> n >> k;
	x.resize(n);
	y.resize(n);
	rep(i, n){
		cin >> x[i] >> y[i];
		v.emplace_back(x[i], y[i]);
	}
	sort(x.begin(), x.end());
	sort(y.begin(), y.end());
	ll ans = 1e20;
	for(int x1 = 0; x1 < n; x1++){
		for(int x2 = x1; x2 < n; x2++){
			for(int y1 = 0; y1 < n; y1++){
				for(int y2 = y1; y2 < n; y2++){
					if(check(x1, x2, y1, y2)){
						ll s = (y[y2]-y[y1])*(x[x2]-x[x1]);
						ans = min(ans, s);
					}
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,k;
    cin>>n>>k;
    int arr[n+1];
    for(int i=1;i<=n;i++)
    cin>>arr[i];
    int dp[k+1];
    for(int i=0;i<=k;i++)
    dp[i]=0;
    for(int i=1;i<=k;i++)
    {
        for(int j=1;j<=n;j++)
        {
            if(arr[j]>i)
            continue;
            if(dp[i-arr[j]]==0)
            dp[i]=1;
        }
    }
    if(dp[k]==1)
    cout<<"First\n";
    else
    cout<<"Second\n";
    return 0;
}

Measured memory_bytes: 640
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author champon
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
#define se cout << "test ok" << endl;
#define sp << " " <<
#define enl "\n";
using namespace std;
using ll=long long;
using ld=long double;
ll mod = ll(1e9)+7;
ll inf = ll(1e18);
void bl(bool b, ostream& out=cout){ out << (b ? "Yes" : "No") << endl; }
void bl2(bool b, ostream& out=cout){ out << (b ? "YES" : "NO") << endl; }
template<typename T> inline bool chmax(T &a, T b){ if(a<b){a=b; return true;} return false; }
template<typename T> inline bool chmin(T &a, T b){ if(a>b){a=b; return true;} return false; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){ fill((T*)array, (T*)(array+N), val); }
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};

#ifndef INCLUDE_DEBUG_HPP
#define INCLUDE_DEBUG_HPP

#include <iostream>
#include <vector>
#include <map>
using namespace std;

namespace dbg {
    using ll = long long;

    class Debug {
    public:
        Debug(){}
        template<typename T>
        void vd(vector<T> vec);
        template<typename T>
        void vd2(vector<vector<T>> vec);
        template<typename T>
        void ad(T *arr, ll n);
        template<typename T, size_t N>
        void ad2(T (&arr)[N], ll n);
        template<typename T>
        void md(T mp);
    };

    template<typename T>
    void Debug::vd(vector<T> vec) {
        for (auto vv : vec) cout << vv << " ";
        cout << endl;
    }

    template<typename T>
    void Debug::vd2(vector<vector<T>> vec) {
        for (auto vv : vec) for (auto vvv : vv) cout << vvv << " ";
        cout << endl;
    }

    template<typename T>
    void Debug::ad(T *arr, ll n) {
        for (int i = 0; i <= n; i++) cout << arr[i] << " ";
        cout << endl;
    }

    template<typename T, size_t N>
    void Debug::ad2(T (&arr)[N], ll n) {
        for (int i = 0; i <= N; i++) for (int j = 0; j <= n; j++) cout << arr[i][j] << " ";
        cout << endl;
    }

    template<typename T>
    void Debug::md(T mp) {
        cout << "key : value" << endl;
        for (auto const &m : mp) cout << m.first << " : " << m.second << endl;
        cout << endl;
    }

}

#endif //INCLUDE_DEBUG_HPP

using dbg::Debug;
Debug debug;

class ESequenceDecomposing {
public:
	void solve(std::istream& in, std::ostream& out) {
        int n;
        in >> n;
        vector<ll> a(n);
        for(int i=0; i<n; i++){
            in >> a[i];
        }

        vector<int> head;
        for(int i=n-1; i>=0; i--){
            if(head.empty()){
                head.push_back(a[i]);
                continue;
            }

            int it = upper_bound(head.begin(), head.end(), a[i]) - head.begin();
            if(it == head.size()){
                head.push_back(a[i]);
            }else{
                head[it] = a[i];
            }
        }

        out << head.size() << endl;
	}
};


int main() {
	ESequenceDecomposing solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;

  int res;
  res = min(B, D) - max(A, C);
  if (res < 0) res = 0;
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
k = []
for i in range(1,40):
  for j in range(2,30):
    if i**j <= 1000:
      k.append(i**j)
L = set(k)
P = list(L)
P.sort()
X = int(input())
ans = 0
if X == 1000:
  print(1000)
else:
  for i in range(len(P)):
    if X<P[i]:
      print(ans)
      break
    else:
      ans = P[i]

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

int main(){
  int k, x;
  cin >> k >> x;

  for(int i=x-k+1; i<=x+k-1; i++){
    if(i==-10e6 || i==10e6) continue;
    cout << i << endl;
  }
  return 0;
}

Measured memory_bytes: 256
from sys import stdin, setrecursionlimit
#input = stdin.buffer.readline
setrecursionlimit(10 ** 7)

from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
from collections import deque, defaultdict, Counter
from itertools import combinations, permutations, combinations_with_replacement
from itertools import accumulate
from math import ceil, sqrt, pi, radians, sin, cos

MOD = 10 ** 9 + 7
INF = 10 ** 18

N = int(input())
#N, M = map(int, input().split())
#A = list(map(int, input().split()))
#A = [int(input()) for _ in range(N)]
#ABC = [list(map(int, input().split())) for _ in range(N)]
#S = input()
#S = [input() for _ in range(N)]

print(1 - N)

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

using namespace std;
using ll = int64_t;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using mii = map<int, int>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
using tpi = tuple<int, int, int>;

using vqi = vector<queue<int>>;
using vpi = vector<pii>;
using bs = bitset<60>;
using vbi = vector<bs>;

ll gcd(ll a, ll b) {
  if (a < b) {
    swap(a, b);
  }

  /* ユークリッドの互除法 */
  ll r = a % b;
  while (r != 0) {
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}

ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

constexpr int64_t __pow_mod(int64_t n, int64_t p, int64_t mod) noexcept {
  if (p == 0) {
    return 1;
  }
  if (p % 2 == 0) {
    int64_t t = __pow_mod(n, p / 2, mod);
    return (t * t) % mod;
  }
  return (n * (__pow_mod(n, p - 1, mod) % mod)) % mod;
}

constexpr int64_t pow_mod(int64_t n, int64_t p, int64_t mod) noexcept {
  int64_t res = __pow_mod(n, p, mod);
  if (res == 0) {
    res = mod;
  }
  return res;
}

const string YES = "Yes";
const string NO = "No";

void solve(long long H, long long N, std::vector<long long> A) {
    ll sum=0;
    for(auto item :A){
        sum+=item;
    }
    if(sum>=H){
        cout<<YES<<endl;
    }else{
        cout<<NO<<endl;
    }

}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You
// use the default template now. You can remove this line by using your custom
// template)
int main() {
  long long H;
  std::cin >> H;
  long long N;
  std::cin >> N;
  std::vector<long long> A(N);
  for (int i = 0; i < N; i++) {
    std::cin >> A[i];
  }
  solve(H, N, std::move(A));
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <stack>
#include <algorithm>
#include <string>
#include <map>
#include <iterator>
#include <set>
#include <queue>

using namespace std;

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

    bool vs[100 + 2];

    for (int i = 0; i < 100 + 2; ++i) {
        vs[i] = true;
    }

    for (int i = 0; i < N; ++i) {
        int p;
        cin >> p;
        vs[p] = false;
    }


    if (vs[X]) {
        cout << X << endl;
        return 0;
    }


    int m1 = -1;
    for (int i = X; i >= 0; --i) {
        if (vs[i]) {
            m1 = i;
            break;
        }
    }
    int m2 = -1;
    for (int i = X; i < 102; ++i) {
        if (vs[i]) {
            m2 = i;
            break;
        }
    }

    int am1 = abs(X - m1);
    int am2 = abs(X - m2);

    if (am1 > am2) {
        cout << m2 << endl;
    } else {
        cout << m1 << endl;
    }

    return 0;

}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb(x) push_back(x)
#define all(x) x.begin(), x.end()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = 1e9;
const ll INF = 1e18;
const ld EPS = 1e-10;

int main(){
    int N, K;
    cin >> N >> K;
    ll a[N];
    rep(i, N) cin >> a[i];
    vector<ll> v;
    ll sum[N+1];
    sum[0] = 0;
    rep2(i, 1, N) sum[i] = sum[i-1]+a[i-1];
    rep(i, N+1){
        rep2(j, i+1, N) v.pb(sum[j]-sum[i]);
    }
    ll ans = 0;
    rep3(i, 40, 0){
        int cnt = 0;
        for(auto &e: v) if(e & (1ll<<i)) cnt++;
        if(cnt < K) continue;
        ans |= 1ll<<i;
        for(auto &e: v) if(!(e & (1ll<<i))) e = 0;
    }
    cout << ans << endl;
}

Measured memory_bytes: 6384
#include <stdio.h>
#include<math.h>
#include <stdbool.h>
bool xprime(int x){
    
    int j=3;
    if(x==2){
        return true;
    }
    
    if(x<2||x%2==0){
        return false;
    }
    
    while(j<=sqrt(x)){
        if(x%j==0){
            return false;
        }
        j+=2;
    }
    return true;
}
int main(void){
    // Your code here!
    int n,x[10000],cnt=0;
    bool b;
    scanf("%d",&n);
    
    for(int i=0;i<n;i++){
        scanf("%d",&x[i]);
        b=xprime(x[i]);
        if(b){
            cnt++;
        }
    }
    
    
    
    
    
    
        
    printf("%d\n",cnt);
}



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

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

int main(){
    while(true){
        int w, h; cin >> w >> h;
        if(w == 0 && h == 0) break;
        int sx, sy; //スタート地点の場所
        vector<vector<char>> mp(h, vector<char>(w)); //入力を受け取る二次元配列
        for(int i = 0; i < h; i++){
            for(int j = 0; j < w; j++){
                cin >> mp[i][j];
                if(mp[i][j] == '@'){
                    sx = j;
                    sy = i;
                }
            }
        }
        vector<vector<int>> ok(h, vector<int>(w)); //到達可能なら1を代入する
        queue<pair<int, int>> que;
        que.push({sx, sy});
        ok[sy][sx] = 1;
        while(!que.empty()){
            int x = que.front().first, y = que.front().second; //現在地を取得する
            que.pop();
            for(int i = 0; i < 4; i++){
                if(x + dx[i] < 0 || x + dx[i] >= w || y + dy[i] < 0 || y + dy[i] >= h) continue; //mapの範囲外はcontinue
                if(mp[y+dy[i]][x+dx[i]] == '#' || ok[y+dy[i]][x+dx[i]] == 1) continue; //障害物で行けないor一度行ったところはスルー
                //それ以外の場合
                ok[y+dy[i]][x+dx[i]] = 1; //okに1を代入する
                que.push({x+dx[i], y+dy[i]}); //現在地からまだ行ってない場所のうち,行ける場所を新たに追加
            }
        }
        int ans = 0; 
        for(int i = 0; i < h; i++){
            for(int j = 0; j < w; j++){ //okの要素を全て足すと行ける場所の個数がわかる
                ans += ok[i][j];
            }
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 3180
#include <stdio.h>
 
int main(void){
  	int a,b,c;
  	int t;
  
  	scanf("%d %d %d", &a, &b, &c);
  
  	if(a>b){
    	t=a;
      	a=b;
      	b=t;
    }
  
  	if(a<=c&&c<=b){
    	printf("Yes\n");
    }else{
    	printf("No\n");
    }
  
	return 0; 
}


Measured memory_bytes: 128
num=int(input())
mm=[int(s) for s in input().split()]
total=sum(mm)


count=0
for j,i in enumerate(mm):
  count+=i
  if count>=total//2:
    flag=j
    break

q=sum(mm[flag+1:])

p=count-q


mm.reverse()

count=0
for j,i in enumerate(mm):
  count+=i
  if count>=total//2:
    flag=j
    break

q=sum(mm[flag+1:])
p2=count-q

if p>=p2:
  print(p2)
else:
  print(p)

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

int main() {
	string s;
	int a = 0,b = 0,c = 0;
	cin >> s;
	for(int i = 0; i <= 2; i++) {
		if(s[i] == 'a')a++;
		if(s[i] == 'c')c++;
		if(s[i] == 'b')b++;
	}
	if(a == 1 && b == 1 && c == 1) printf("Yes\n");
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(), k = sc.nextInt();//,b=sc.nextInt();
		//int x=sc.nextInt();//,k=sc.nextInt();
		long sum=0,count=0,flag=0,max=-999999,min=99999;
		long[] array=new long[n];
		//String s=sc.next(),t=sc.next();
		String buff;
		//String[] arrays = new String[a];
		for(int i=0;i<n;i++) {
			flag=sc.nextLong();
			if(flag>=Math.abs(flag-k)) {
				sum+=Math.abs(flag-k)*2;
			}else {
				sum+=flag*2;
			}
		}
		System.out.println(sum);



	}
	public static int sample(int n) {
		return n;
	}

}


Measured memory_bytes: 21844
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <map>
#include <vector>

const int MAXN = 40;
const int MAXS = 150000;
const int MOD = 1000000007;

inline int Add(int x, const int &y) {
	x += y; if (x >= MOD) x -= MOD; return x;
}

const int P = 23;
const int HASH_MOD = 100003;

int N, X, Y, Z, S;
int Dp[MAXN + 5][MAXS +5][2];

void Debug(const std::vector<int> &T) {
	puts("");
	for (int i = 0; i < int(T.size()); i++)
		printf("%d ", T[i]);
	puts("");
}

std::vector<std::pair<std::vector<int>, int> > Hash[HASH_MOD + 5];

int Key(const std::vector<int> &T) {
	int ret = 0;
	for (int i = 0; i < int(T.size()); i++)
		ret = (ret * P + T[i]) % HASH_MOD;
	return ret;
}

int Find(const std::vector<int> &T) {
	int pos = Key(T);
	for (int i = 0; i < int(Hash[pos].size()); i++)
		if (Hash[pos][i].first == T)
			return Hash[pos][i].second;
	return 0;
}

int Tot;
bool Good[MAXS + 5];
int Next[MAXS + 5][12];
std::vector<int> cur, State[MAXS +5];

void Dfs(int num, int sum) {
	if (num > N || sum > X + Y + Z)
		return;
	State[++Tot] = cur;
	Hash[Key(cur)].push_back(std::make_pair(cur, Tot));
	if (sum == X + Y + Z) {
		int cnt = 0, tmp = 0;
		for (int i = 0; i < int(cur.size()); i++) {
			tmp += cur[i];
			if ((1 << tmp) & S)
				cnt++;
		}
		Good[Tot] = cnt == 3;
		return;
	}
	for (int i = 1; i <= 10; i++) {
		cur.push_back(i);
		Dfs(num + 1, sum + i);
		cur.pop_back();
	}
}

int main() {
	scanf("%d%d%d%d", &N, &X, &Y, &Z);
	S = (1 << X) | (1 << (X + Y)) | (1 << (X + Y + Z));
	Dfs(0, 0);
//	for (int i = 1; i <= Tot; i++)
//		printf("[%d]", i), Debug(State[i]);
	for (int i = 1; i <= Tot; i++) {
		for (int j = 1; j <= 10; j++) {
			cur = State[i];
			cur.push_back(j);
			int sum = 0, k = cur.size() - 1;
			while (k >= 0 && sum + cur[k] <= X + Y + Z)
				sum += cur[k--];
			for (int t = 0; t <= k; t++)
				cur.erase(cur.begin());
			Next[i][j] = Find(cur);
		}
	}
//	for (int i = 1; i <= Tot; i++, puts(""))
//		for (int j = 1; j <= 10; j++)
//			printf("%d ", Next[i][j]);
	Dp[0][1][0] = 1;
	for (int i = 0; i < N; i++)
		for (int j = 1; j <= Tot; j++)
			if (Dp[i][j][0] || Dp[i][j][1]) {
//				printf("-- %d, %d --", i, j), Debug(State[j]);
				for (int k = 1; k <= 10; k++) {
					int s = Next[j][k];
//					if (s == 1)
//						continue;
//					printf("(%d)-> [%d]", k, s), Debug(State[s]);
					Dp[i + 1][s][0] = Add(Dp[i + 1][s][0], Dp[i][j][0]);
					if (Good[s])
						Dp[i + 1][s][1] = Add(Dp[i + 1][s][1], Dp[i][j][0]);
					else
						Dp[i + 1][s][1] = Add(Dp[i + 1][s][1], Dp[i][j][1]);
				}
			}
	int Ans = 0;
//	for (int i = 0; i <= N; i++)
//		for (int j = 1; j <= Tot; j++)
//			if (Dp[i][j][0] || Dp[i][j][1])
//				printf("[%d][%d] %d %d\n", i, j, Dp[i][j][0], Dp[i][j][1]);
	for (int i = 1; i <= Tot; i++) {
//		if (Dp[N][i][1]) {
//			printf("\n[%d]", i);
//			Debug(State[i]);
//			printf("Dp = %d\n", Dp[N][i][1]);
//		}
		Ans = Add(Ans, Dp[N][i][1]);
	}
//	puts("");
	printf("%d", Ans);
	return 0;
}



Measured memory_bytes: 71124
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline void rd(char &c){
  int i;
  for(;;){
    i = getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c = i;
}
inline int rd(char c[]){
  int i;
  int sz = 0;
  for(;;){
    i = getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c[sz++] = i;
  for(;;){
    i = getchar_unlocked();
    if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF){
      break;
    }
    c[sz++] = i;
  }
  c[sz]='\0';
  return sz;
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(long long x){
  int s=0;
  int m=0;
  char f[20];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
int N;
char S[200002];
int main(){
  int i;
  int j = 0;
  long long res = 0;
  N = rd(S);
  for(i=N-1;i>=0;i--){
    if(S[i]=='W'){
      j++;
    }
    else{
      res += j;
    }
  }
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190925-1

// --- original code ---
// int N;
// char S[200002];
// {
//   int i, j = 0;
//   ll res = 0;
//   rd(S@N);
//   for(i=N-1;i>=0;i--){
//     if(S[i]=='W') j++; else res += j;
//   }
//   wt(res);
// }


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#define init() \
  cin.tie(0);  \
  ios::sync_with_stdio(false)
#define debug(x) cerr << "[debug] " << #x << ": " << x << endl;
#define debugV(v)                       \
  cerr << "[debugV] " << #v << ":";     \
  rep(i, v.size()) cerr << " " << v[i]; \
  cerr << endl;
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using P = pair<ll, ll>;
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr ld PI = 3.141592653589793238462643383279;
ll get_digit(ll x) {
  return to_string(x).size();
}

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

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

vll divisor(ll n) {
  vll ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  SORT(ret);
  return (ret);
}

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

signed main() {
  init();
  ll N;
  cin >> N;

  map<ll, ll> m;
  rep(i, N) {
    ll a;
    cin >> a;
    m[a]++;
  }

  ll m_a = 0;
  ll m_b = 0;

  for (auto mm : m) {
    if (m_a <= mm.first && mm.second >= 4) {
      m_b = mm.first;
      m_a = mm.first;
      continue;
    }

    if (m_a <= mm.first && mm.second >= 2) {
      m_b = m_a;
      m_a = mm.first;
    }
  }
  COUT(m_a * m_b);

  return 0;
}

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

int main(void){
    vector<int> H(10010),W(10010);
    for(int i=0;i<10010;i++){
        cin>>H.at(i)>>W.at(i);
        if(H.at(i)==0 && W.at(i)==0)break;
        for(int j=0;j<H.at(i);j++){
            for(int k=0;k<W.at(i);k++){
                cout<<'#';
            }
            cout<<endl;
        }
        cout<<endl;
    }
}



Measured memory_bytes: 3160
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    string S[51], T[51];
    rep(i, N) cin >> S[i];
    rep(i, M) cin >> T[i];
    rep(i, N) {
        rep(j, N) {
            bool ok = true;
            rep(s, M) {
                rep(t, M) {
                    if(i + s >= N || j + t >= N || S[i + s][j + t] != T[s][t])ok = false;
                }
            }
            if(ok) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_ll.hpp>
//typedef boost::multiprecision::cpp_ll ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E18;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define endl "\n"
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);


int main(){fastio
    ll s,w;cin>>s>>w;
    if(s<=w){
        cout<<"unsafe"<<endl;
    }else{
        cout<<"safe"<<endl;
    }
    
    
}


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

int main(){
    string S,T;
    cin>>S>>T;

    for(int i=0; i<S.size(); i++){
        if(S == T){
            cout<<"Yes"<<endl;
            return 0;
        }

        S = S.back()+S.substr(0,S.size()-1);
    }

    cout<<"No"<<endl;

    return 0;
}

Measured memory_bytes: 256
public class Main{
  static int N = 4001;
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
    int[] ab, cd;
    int i, j, n, sum;

    ab = new int[N]; cd = new int[N];

    for(i = 0;i <= 1000;i++)for(j = 0;j <= 1000;j++)ab[i + j]++;
    for(i = 0;i < N;i++)cd[i] = ab[i];

    for(;sc.hasNext();){
      n = sc.nextInt();
      sum = 0;
      for(i = 0;i <= n;i++)sum += ab[i] * cd[n - i];
      out.println(sum);
    }

    sc.close();
  }
  public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  }
}

Measured memory_bytes: 20540
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define inf 10e17
#define rep(i,n) for(long long i=0; i<n; i++)
#define repr(i,n,m) for(long long i=m; i<n; i++)
#define mod 1000000007
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<long long>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto&& itr : x) { cerr << (itr) << " "; }

template <class T> inline void chmax(T &ans, T t) { if (t > ans) ans = t;}
template <class T> inline void chmin(T &ans, T t) { if (t < ans) ans = t;}

int main() {
  ll n,k;
  cin >> n >> k;
  int ans = 0;
  while (n > 0) {
    n /= k;
    ans ++;
  }

  cout << ans << endl;
}

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

int main() {
    int N, M;
    cin >> N >> M;
    int sum = 0;
    for (int i = 0; i < M; i++) {
        int Ai;
        cin >> Ai;
        sum += Ai;
    }
    if (sum > N) {
        cout << -1 << endl;
    } else {
        cout << N - sum << endl;
    }
}

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

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

  if((a+b) > (c+d)) cout << "Left" << endl;
  else if((a+b) == (c+d)) cout << "Balanced" << endl;
  else cout << "Right" << endl;

  return 0;
}

Measured memory_bytes: 256
const input = require('fs').readFileSync('/dev/stdin', 'utf8');
const lines = input.trim().split('\n');

while (line = lines.shift()) {
    const numbers = line.split(' ').map(Number);

    // Edit from here
    let a = numbers[0];
    let b = numbers[1];

    if ( a === 0 && b === 0 ) { break; }

    if ( a > b ) {
        const tmp = a;
        a = b;
        b = tmp;
    } 

    const output = a + ' ' + b;
    // to here
    
    console.log(output);
    
}


Measured memory_bytes: 19116
#include <stdio.h>

int main(void)
{
	long long int x,ans=0;
	scanf("%lld",&x);
	ans=2*(x/11);
	if(x%11>=7){
		ans+=2;
	}else if(x%11>=1){
		ans+=1;
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 128
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。
long long getDigit(long long n);      // 数字の桁数を取得する。
string upper(string str);       // 英字を大文字に変換する。
string lower(string str);       // 英字を小文字に変換する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>
#define GCD(a,b)      __gcd((a),(b))
#define LCM(a,b)      ((a)/GCD((a),(b))*(b))
#define kiriage(a,b)  ((a)+(b)-1)/(b)

const int INF = 1e9;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;

// code
// ------------------------------------------------
int main()
{
  string s;
  cin >> s;

  ll ans = 0;
  ll w_num = 0;

  reverse(all(s));

  rep(i,sz(s))
  {
    if(s[i] == 'W')
    {
      w_num++;
    }

    if(s[i] == 'B')
    {
      ans += w_num;
    }
  }

  cout << ans << endl;

  return 0;
}
// funcの実体
// ------------------------------------------------
ll getDigit(ll n)
{
  int i = 1;
  while(1)
  {
    n = n / 10;
    if(n == 0)
      break;
    i++;
  }
  return i;
}
ll CalcSumOfDigit(ll n)
{
  ll s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

string upper(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(97 <= *itr && *itr <= 122)
    {
      *itr = *itr - 32;
    }
  }
  return str;
}

string lower(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(65 <= *itr && *itr <= 90)
    {
      *itr = *itr + 32;
    }
  }
  return str;
}


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

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

Measured memory_bytes: 256
from bisect import bisect_left

N = int(input())
L = list(map(int, input().split()))

L.sort()

ans = 0
for i in range(N - 2):
  a = L[i]
  for j in range(i + 1, N - 1):
    b = L[j]
    c = bisect_left(L, a + b)
    ans += c - j - 1

print(ans)


Measured memory_bytes: 3188
package main

import "fmt"

func sumArray(a []int) int {
	var s int
	for i := 0 ; i < len(a) ; i++ {
		s += a[i]
	}
	return s
}

func main(){
	var n,k,max,max_i int
	fmt.Scan(&n,&k)
	p := make([]int, n)
	sort := make([]int, k)
	for i := 0 ; i < k ; i++ {
		fmt.Scan(&p[i])
	}
	m := sumArray(p[0:k])
	for i := k ; i < n ; i++{
		fmt.Scan(&p[i])
		m += (p[i]-p[i-k])
		if m > max {
			max = m
			max_i = i
		}
	}
	if k == n {
		sort = p
	} else {
		sort = p[max_i-k+1:max_i+1]
	}
//fmt.Println(sort)
	var sum float64
	for i := 0 ; i < k ; i++ {
		sum += float64((float64(sort[i])+1.0)/2.0)
//fmt.Println(sum)
	}
	fmt.Println(sum)
}


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

#ifdef _DEBUG
inline void dump() { cerr << endl; }
template<typename Head> void dump(Head&& head) { cerr << head; dump(); }
template<typename Head, typename... Tail> void dump(Head&& head, Tail&&... tail) { cerr << head << ", "; dump(forward<Tail>(tail)...); }
#define debug(...) do {cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; dump(__VA_ARGS__); } while (false)
#else
#define dump(...)
#define debug(...)
#endif

template<typename T>
struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }
  operator int() const { return to; }
};
template<typename T>
using Edges = vector<edge<T>>;
template<typename T>
using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template<typename T>
using Matrix = vector<vector<T>>;

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

const ll inf = 1LL<<60;

ll f(ll n, ll p) {
  ll ret = 0;
  if (n == 0) return 0;
  ll t = n%p;
  ret += f(t, __builtin_popcountll(t));
  return ret + 1;
}

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

  ll d = 0;
  for (int i=0; i<n; i++) {
    if (s[i] == '1') d++;
  }

  vector<vector<ll>> a(n, vector<ll>(2));
  for (int j=0; j<2; j++) {
    ll e = d;
    if (j == 0) e++;
    else e--;
    if (e <= 0) continue;
    ll t = 1;
    for (int i=0; i<n; i++) {
      a[n-i-1][j] = t % e;
      t = (t*2) % e;
    }
  }

  vector<ll> sum(2);
  for (int j=0; j<2; j++) {
    ll e = d;
    if (j == 0) e++;
    else e--;
    if (e <= 0) continue;
    for (int i=0; i<n; i++) {
      if (s[i] == '1') sum[j] += a[i][j];
    }
  }

  for (int i=0; i<n; i++) {
    ll e = d;
    ll idx = s[i] - '0';
    ll t = sum[idx];
    if (idx) {
      e--;
      if (e <= 0) {
        cout << 0 << endl;
        continue;
      }
      t = (t + e - a[i][idx]) % e;
    } else {
      e++;
      t = (t + a[i][idx]) % e;
    }
    cout << f(t, __builtin_popcountll(t))+1 << endl;
  }

  return 0;
}


Measured memory_bytes: 14404
#include <iostream>

int main() {
  int n, a[10][3][4] = {};
  std::cin >> n;
  for (int i = 0; i < n; i++) {
    int b, f, r, v;
    std::cin >> b >> f >> r >> v;
    a[r - 1][f - 1][b - 1] += v;
  }
  for (int i = 0; i < 4; i++) {
    for (int j = 0; j < 3; j++) {
      for (int k = 0; k < 10; k++) {
        std::cout << ' ' << a[k][j][i];
      }
      std::cout << '\n';
    }
    if (i != 3)
      std::cout << "####################" << std::endl;
  }
  return 0;
}



Measured memory_bytes: 3112
from itertools import product

N,M = map(int,input().split())
value = [list(map(int,input().split())) for _ in range(N)]

ans = 0
for a,b,c in product([1,-1],repeat = 3):
    tmp = []
    for i in range(N):
        tmp.append(a*value[i][0] + b*value[i][1] + c*value[i][2])
    tmp.sort(reverse=True)
    ans = max(ans, sum(tmp[:M])) 
print(ans)

Measured memory_bytes: 3384
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define sf scanf
#define pf printf
#define pb push_back
#define MP make_pair
#define llu unsigned long long
#define U unsigned int
#define ff first
#define ss second
#define SIZE 100005
#define pie 3.14159265358979323
#define minuss 1e-6
#define pair pair<ll,ll>
#define fast_cin ios_base::sync_with_stdio(false);cin.tie(NULL)
#define BIG 1000000000
#define INF 1000000000000005
#define N 10000
vector<ll>vec;
map<string,ll> mps;
map<ll,string> mpss;
set<ll>s1;
set<string>s2;
map<string,ll>::iterator str;
set<ll>::iterator itr;
/*
std::cout << std::fixed;
std::cout << std::setprecision(1);
std::cout << VALUE NAME<<endl;
*/
ll tra[100006],tra1[100006];


int main()
{
    fast_cin;
    ll t;
  

        map<ll,ll>mp;
        map<ll,ll>::iterator it;
        string s,s1;
        ll lock=0,sum=0,co=0;
        ll n,m,k;
        cin>>n;
        sum=n+(n*n)+(n*n*n);
        cout<<sum<<endl;







        s1.clear();
        vec.clear();

}



Measured memory_bytes: 3652
#include<iostream>
using namespace std;
int main() {
  int h, w, ci;
  string chars[] = {"#", "."};
  while (true) {
    cin >> h >> w;
    if (h == 0 && w == 0) break;
    for (int i = 0; i < h; i++) {
      ci = i % 2;
      for (int j = 0; j < w; j++) {
        cout << chars[ci];
        ci = (ci + 1) % 2;
      }
      cout << endl;
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 1192
#include <iostream>
using namespace std;
int main(){
   int a , b , c , y;
    
   cin >> a >> b >> c;
    
   if(a > b){
      y = a;
      a = b;
      b = y;
       
   }
    
   if(b > c){
      y = b;
      b = c;
      c = y;
 
   }
    
   if(a > b){
      y = a;
      a = b;
      b = y;
       
   }
    
   cout << a << " " << b << " " << c << endl;
    
   return 0;
}

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

#define int long long
typedef pair<int, int> P;
#define mod 1000000007
#define INF (1LL<<60)

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define YES puts("YES\n")
#define Yes puts("Yes\n")
#define NO  puts("NO\n")
#define No  puts("No\n")
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }



signed main() {

	string s;
	cin >> s;

	if (s == "Sunny") cout << "Cloudy" << endl;
	else if (s == "Cloudy") cout << "Rainy" << endl;
	else cout << "Sunny" << endl;


	return 0;
}


Measured memory_bytes: 764
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    class BIT:
        '''
        0-indexed
        '''
        def __init__(self, N):
            self.size = N
            self.tree = [0] * (N + 1)
            self.depth = N.bit_length()

        def _bitsum(self, i):
            ret = 0
            while i:
                ret += self.tree[i]
                i ^= i & -i
            return ret

        # [l,r)の和
        def sum(self, l, r=None):
            if r is None:
                return self._bitsum(l)
            else:
                return self._bitsum(r) - self._bitsum(l)

        # i番目にxを追加
        def add(self, i, x):
            i += 1
            while i <= self.size:
                self.tree[i] += x
                i += i & -i
            return

        def lower_bound(self, x):
            sum_ = 0
            pos = 0
            v = 1 << self.depth
            for i in range(self.depth, -1, -1):
                k = pos + v
                if k <= self.size and sum_ + self.tree[k] < x:
                    sum_ += self.tree[k]
                    pos += v
                v >>= 1
            return pos + 1, sum_
        
    N,Q=MI()
    bit=BIT(N)
    A=LI()
    for i in range(N):
        bit.add(i,A[i])
    
    for _ in range(Q):
        t,p,x=MI()
        if t==0:
            bit.add(p,x)
        else:
            print(bit.sum(p,x))
            
            

main()


Measured memory_bytes: 127968
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007


using namespace std;


int fact(int n){
  if (n == 0)
    return 1;

  else
    return n * fact(n-1);
}

int main(void){
  int n;
  cin >> n;
  vector<double> x(n), y(n), vec(n);

  for (int i = 0; i < n; i++){
    cin >> x[i] >> y[i];
    vec[i] = i;
  }


  double sum = 0;
  do{
    for (int i = 0; i < n - 1; i++){
      sum += sqrt(pow((x[vec[i]] - x[vec[i+1]]), 2) + pow((y[vec[i]] - y[vec[i+1]]), 2));
    }
  } while (next_permutation(vec.begin(), vec.end()));


  printf("%.7lf\n", sum/fact(n));

  return 0;
}


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

public class Main {
    public static void main(final String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final int n = scanner.nextInt();
        final String s = scanner.next();
        final List<Character> slimes = new ArrayList<>();

        for (int i = 0; i < n; i++) {
            slimes.add(s.charAt(i));
        }

        for (int i = 0; i < slimes.size() - 1; i++) {
            if (slimes.get(i) == slimes.get(i + 1)) {
                slimes.remove(i);
                i--;
            }
        }

        System.out.println(slimes.size());
    }
}


Measured memory_bytes: 26236
import sys
input = sys.stdin.readline
n, m = [int(x) for x in input().strip().split()]
g = [[0] * n for _ in range(n)]
for i in range(m):
    a, b = [int(x) for x in input().strip().split()]
    g[a-1][b-1] = 1
    g[b-1][a-1] = 1

flags = [False] * n
def dfs(flags, v):
    if flags.count(False) == 1:
        return 1
    flags[v] = True
    ret = 0
    for i, f in enumerate(g[v]):
        if f == 0 or flags[i]:
            continue
        ret += dfs(flags[:], i)
    return ret

print(dfs(flags[:], 0))

Measured memory_bytes: 3064