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

// template {{{
#define  range(i, l, r) for (int i = (int)(l); i < (int)(r); (i) += 1)
#define rrange(i, l, r) for (int i = (int)(r) - 1; i >= (int)(l); (i) -= 1)

#define  whole(f, x, ...) ([&](decltype((x)) container) { return (f)(  begin(container),  end(container), ## __VA_ARGS__); })(x)
#define rwhole(f, x, ...) ([&](decltype((x)) container) { return (f)( rbegin(container), rend(container), ## __VA_ARGS__); })(x)

#define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl

using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;

// constexpr i32 mod   = 998244353;
constexpr i32 mod   = 1e9 + 7;
constexpr i32 inf   = 1001001001;
constexpr i64 infll = 1001001001001001001ll;

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

struct IoSetup { IoSetup(int x = 15){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(x); cerr << fixed << setprecision(x); } } iosetup;

template <typename T = i64> T input() { T x; cin >> x; return x; }

template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { range(i, 0, v.size()) { os << v[i] << (i + 1 != v.size() ? " " : ""); } return os; }
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }

template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }

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

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
// }}}

void solver() {
    char a, b;
    cin >> a >> b;

    if (a == b) {
        cout << "H" << endl;
    } else {
        cout << "D" << endl;
    }
}

signed main(int argc, char *argv[]) {
    solver();
}


Measured memory_bytes: 3556
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) FOR(i,0,n)
#define repr(i,n) for(int i=(n)-1;0<=i;--i)
#define each(e,v) for(auto&& e:(v))
#define all(v) begin(v),end(v)
#define dump(x) cerr<<#x<<": "<<(x)<<endl
#define INF 100000000
#define IINF 9999999999999;
using vint = std::vector<int>;
using ll = long long;
using vll = std::vector<ll>;
template <class T> void chmin(T& a, const T& b) { a = std::min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = std::max(a, b); }

int main() {
    int N, K;
    cin >> N >> K;
    if(N % K == 0) cout << 0 << endl;
    else cout << 1 << endl;

    return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

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

  ll K, Q;
  cin >> K >> Q;
  vector<ll> D(K);
  rep(i, K) cin >> D[i];
  while(Q--) {
  	ll N, X, M;
  	cin >> N >> X >> M;
  	vector<ll> d(K);
  	rep(i, K) d[i] = D[i] % M;

  	ll zcnt = 0;
  	rep(i, K) if(d[i] == 0) zcnt++;
  	zcnt *= (N - 1) / K;
  	rep(i, (N - 1) % K) if(d[i] == 0) zcnt++;

  	ll sum = X;
  	ll dsum = 0;
  	rep(i, K) dsum += d[i];
  	sum += dsum * ((N - 1) / K);
  	rep(i, (N - 1) % K) sum += d[i];
  	ll cnt = sum / M;
  	cnt -= X / M;

  	ll res = N - 1 - zcnt - cnt;
  	cout << res << "\n";
  }

  return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define loop(i, a, b) for(li i=a; i<=b; i++)
#define stuff ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long li;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<li, li> lii;
typedef vector<int> vi;
typedef vector<li> vli;
typedef vector<ii> vii;
typedef vector<lii> vlii;
li mod = 1e9+7;
li expo(li base, li exponent)
{
	li ans=1;
	while(exponent)
	{
		if(exponent&1) ans = (ans*base)%mod;
		base = (base*base)%mod;
		exponent >>= 1;
	}
	return ans;
}
li gcd(li x, li y)
{
	if(y==0) return x;
	return gcd(y, x%y);
}


typedef tree<li, null_type, less<li>,
rb_tree_tag, tree_order_statistics_node_update> ordered_set;

int main()
{
	stuff;
	// #ifndef ONLINE_JUDGE 
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	// freopen("error.txt", "w", stderr);
	// #endif

	li n, k;
	cin >> n >> k;
	vector<bool> vis(n+1, 0);
	for(int i=0; i<k; i++)
	{
		int d;
		cin >> d;
		for(int j=0, x; j<d; j++)
		{
			cin >> x;
			vis[x] = 1;
		}
	}
	int cnt=0;
	for(int i=1; i<=n; i++) if(!vis[i]) cnt++;
	cout << cnt;
	return 0;
}


Measured memory_bytes: 3644
#include <iostream>
using namespace std;
#define rep(i,x,to) for(int i-x;i<to;i++)

int main() {
	string s,p;
	cin>>s>>p;
	s = s + s;
	if(s.find(p)==-1) cout << "No" << endl;
	else cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 3216
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const long double EPS=1e-9;
const long double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
long double ABS(long double a){return max(a,-a);}
int p[110000];
int main(){
	int a,b;scanf("%d%d",&a,&b);
	int cur=0;

	for(int i=0;i<a;i++){
		int c;scanf("%d",&c);
		p[i]=cur;
		cur=(cur+c)%b;
	}
	p[a]=cur;
	std::sort(p,p+a+1);
	long long ret=0;
	for(int i=0;i<=a;i++){
		ret+=(upper_bound(p,p+a+1,p[i])-lower_bound(p,p+a+1,p[i]))-1;
	}
	ret/=2;
	printf("%lld\n",ret);
}

Measured memory_bytes: 512
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

template <typename T>
static inline void ArrayInput(vector<T>& A) {
  for (auto itr = A.begin(); itr < A.end(); ++itr) cin >> *itr;
}

template <typename T>
static inline void ArrayPut(const vector<T>& A) {
  for (auto itr = A.begin(); itr < A.end(); ++itr) cout << *itr << " ";
  cout << endl;
}

int main() {
  uint64_t N, res = 0;
  cin >> N;
  vector<uint32_t> d(N);
  ArrayInput(d);
  for (uint32_t i = 0; i < N - 1; ++i) {
    for (uint32_t j = i + 1; j < N; ++j) {
      res += d[i] * d[j];
    }
  }
  cout << res;
  return 0;
}


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

#ifdef _DEBUG
#define debug(x) cerr << "line: " << __LINE__ << ", func: " << __func__ << " ->  " << #x << " = " << x << endl
#else
#define debug(x)
#endif

#define all(s) begin(s), end(s)
#define rall(s) rbegin(s), rend(s)
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = ((a)-1); i >= (b); i--)
#define pb push_back
#define sz(a) int((a).size())
#define put(a) ((cout) << (a) << (endl))
#define putf(a, n) ((cout) << (fixed) << (setprecision(n)) << (a) << (endl))

using namespace std;

using ll = long long;
using ull = unsigned long long;
using i_i = pair<int, int>;
using ll_ll = pair<ll, ll>;
using d_ll = pair<double, ll>;
using ll_d = pair<ll, double>;
using d_d = pair<double, double>;

static constexpr ll LL_INF = 1LL << 60;
static constexpr int I_INF = 1 << 28;
static constexpr double PI = static_cast<double>(3.14159265358979323846264338327950288);
static constexpr double EPS = numeric_limits<double>::epsilon();

static map<type_index, const char* const> scanType = {
    {typeid(int), "%d"}, {typeid(ll), "%lld"}, {typeid(double), "%lf"}, {typeid(char), "%c"}};

template <class T> static void scan(vector<T>& v);
[[maybe_unused]] static void scan(vector<string>& v, bool isWord = true);
template <class T> static inline bool chmax(T& a, T b);
template <class T> static inline bool chmin(T& a, T b);
template <class T> static inline T gcd(T a, T b);
template <class T> static inline T lcm(T a, T b);
template <class A, size_t N, class T> static void Fill(A (&arr)[N], const T& val);

ll dfs(int n, string s) {
  if (sz(s) == 10) return 0;

  int counter[]{0, 0, 0};
  for (char c : s) {
    if (c == '3') counter[0]++;
    if (c == '5') counter[1]++;
    if (c == '7') counter[2]++;
  }
  ll ans = (counter[0] > 0 && counter[1] > 0 && counter[2] > 0 && stoll(s) <= n);

  for (char c : {'3', '5', '7'}) ans += dfs(n, s + c);
  return ans;
}

int main(int argc, char* argv[]) {
  long long N;
  scanf("%lld", &N);

  ll ans = dfs(N, "");
  put(ans);
  return 0;
}

template <class T> static void scan(vector<T>& v) {
  auto tFormat = scanType[typeid(T)];
  for (T& n : v) {
    scanf(tFormat, &n);
  }
}

static void scan(vector<string>& v, bool isWord) {
  if (isWord) {
    for (auto& n : v) {
      cin >> n;
    }
    return;
  }

  int i = 0, size = v.size();
  string s;
  getline(cin, s);

  if (s.size() != 0) {
    i++;
    v[0] = s;
  }

  for (; i < size; ++i) {
    getline(cin, v[i]);
  }
}

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 T> inline T gcd(T a, T b) { return __gcd(a, b); }

template <class T> inline T lcm(T a, T b) { return (a * b) / gcd(a, b); }

template <class A, size_t N, class T> void Fill(A (&arr)[N], const T& val) {
  std::fill((T*)arr, (T*)(arr + N), val);
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
  int n;
  cin>>n;
  double a[n];
  double sum=0;
  for(int i=0;i<n;i++)
  {
    cin>>a[i];
    sum=sum+(1/a[i]);
  }
  sum=1/sum;
  cout<<sum<<endl;
  return 0;
}


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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define pb push_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define BiSearchRangeNum(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y)
#define deg_to_rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad_to_deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)

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

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

// x^n mod Mを計算する
long long modpow(long long x, long long n, long long M) {
  long long res = 1;
  if (n > 0) {
    res = modpow(x, n / 2, M);
    if (n % 2 == 0) res = (res * res) % M;
    else res = (((res * res) % M) * x) % M;
  }
  return res;
};

int main() {
  int m, n;
  cin >> m >> n;
  int Mod = 1e9+7;
  cout << modpow(m, n, Mod) << endl;
};


Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
int n, m;
int w[100020];
int v[100020];
map<int, int>g[101];
int main() {
	scanf("%d%d", &n, &m);
	g[0][0] = 0;
	int ans = 0;
	for (int i = 0; i < n; i++) {
		scanf("%d%d", &w[i], &v[i]);
		g[i + 1] = g[i];
		for (pair<int, int> j: g[i]) {
			if (j.first + w[i] <= m) {
				 int t = max(g[i + 1][j.first + w[i]], j.second + v[i]);
				 g[i + 1][j.first + w[i]] = t;
				 ans = max(ans, t);
			}
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 4864
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a,b,c=0;
  cin >> a >> b;
  if(b == 100){
   c=a*1000+b;
  }
  else if (b<100 && b>=10){
   c=a*100+b; 
  }
  else {
   c=a*10+b;
  }
  
  for (int i=0;i<324;i++){
   if (c==i*i){
   cout << "Yes" << endl;
     break;
   } 
    if (i == 323){
    cout << "No" << endl;
    }
  }
}

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

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n,x;
  cin >> n>>x;
  int input, count=0;
  vector<int> a(n);
  rep(i, n) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  rep(i,n) {
	if(x >= a[i]) {
      x-=a[i];
      count++;
    }else{
      cout << count << endl;
      return 0;
    }
  }
  if(x > 0 && count > 0) count--;
  cout << count << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define MOD 1000000007
#define PI 3.141592653589793

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

    int ans = n;
    int y = 1001;
    while(n--){
        int m;
        cin >> m;
        x -= m;
        y = min(y, m);
    }
    ans += x / y;
    cout << ans << endl;
}


Measured memory_bytes: 256
import sys
# input = sys.stdin.buffer.readline
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getlist():
    return list(map(int, input().split()))
import math
import heapq
from collections import defaultdict, Counter, deque
MOD = 10**9 + 7
INF = 10**15

def main():
    ans = 0
    s = input().strip()
    tmp = 0
    for c in s:
        if c in ["A", "C", "T", "G"]:
            tmp +=1
            ans = max(tmp, ans)
        else:
            tmp = 0
    print(ans)
if __name__ == '__main__':
    main()

"""
9999
3

2916
"""

Measured memory_bytes: 38256
#include <stdio.h>

int main(){

    long long a, b, c, d;

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

    long long x[4];

    x[0] = a*c;
    x[1] = a*d;
    x[2] = b*c;
    x[3] = b*d;

    long long max = x[0];

    for(int i=0;i<4;i++){
        if(max<x[i]){
            max = x[i];
        }
    }

    printf("%lld\n", max);

    return 0;
}

Measured memory_bytes: 2180
while(1):
    hoge = input().split()
    a,op,b = int(hoge[0]),hoge[1],int(hoge[2])
    if op == '?':
        break
    if op == "+":
        print(a+b)
    elif op == "-":
        print(a-b)
    elif op == "/":
        print(a//b)
    else:
        print(a*b)




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

int main() {
  long long int n, m;
  cin >> n >> m;

  if(n > m / 2) {
    cout << m / 2 << endl;
  } else {
    long long int remainder = m - 2 * n;
    cout << n + remainder / 4 << endl;
  }
}

Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <cmath>
#include <iostream>
#include <utility>
#include <vector>

#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(a) (a).begin(), (a).end()

#define CEIL_DIV(v1, v2) (v1 % v2 ? v1 / v2 + 1 : v1 / v2)

using namespace std;

int main() {
    int H, W, D;
    cin >> H >> W >> D;

    vector<pair<int, int>> map(H * W);

    REP(i, H) {
        REP(j, W) {
            int a;
            cin >> a;
            a--;
            map[a] = make_pair(i, j);
        }
    }

    vector<vector<unsigned long long>> costs(D);

    REP(start, D) {
        int prev = 0;
        for (int i = start; i + D < H * W; i += D) {
            prev += abs(map[i].first - map[i + D].first) + abs(map[i].second - map[i + D].second);
            costs[start].push_back(prev);
        }
    }

    int Q;
    cin >> Q;

    REP(i, Q) {
        int l, r;
        cin >> l >> r;

        l--;
        r--;

        int start_mod = l % D;
        int start = (l - start_mod) / D;
        int distance = (r - l) / D;

        if (distance == 0) {
            cout << 0 << endl;
        } else {
            int res = costs[start_mod][start + distance - 1];

            if (start != 0) {
                res -= costs[start_mod][start - 1];
            }

            cout << res << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 3200
#include <stdio.h>

int main(void){
    int H,W,i,j;
    scanf("%d %d",&H,&W);
    while(H || W){
        for(i = 0;i<H;i++){
            for(j = 0;j < W;j++){
                printf("#");
            }
            printf("\n");
        }
        printf("\n");
        scanf("%d %d",&H,&W);
    }
    return 0;
}

Measured memory_bytes: 572
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer([]byte{}, 1000000)

	N := getInt()
	a := make([]byte, 0)
	for N != 0 {
		r := N % 2
		if r < 0 {
			r += 2
		}
		N = (N - r) / (-2)

		a = append(a, byte(r))
	}
	// out(a)
	if len(a) == 0 {
		out(0)
		return
	}
	for i := len(a) - 1; i >= 0; i-- {
		fmt.Print(string(a[i] + '0'))
	}
	out()
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
const ll INF = 1001001001;
const ll MOD = 1e9 + 7;

int main(){
  int n, m;
  cin >> n >> m;
  P p[100000];
  rep(i, n){
    int a, b;
    cin >> a >> b;
    p[i] = P(b, a);
  }
  sort(p, p + n);
  reverse(p, p + n);
  vector<int> vec(n);
  rep(i, m) vec.push_back(i+1);
  int ans = 0;
  for(int i = 0; i < n; i++){
    int a = p[i].second, b = p[i].first;
    auto it = lower_bound(all(vec), a);
    if(it == vec.end()) continue;
    vec.erase(it);
    ans += b;
      
  }
  cout << ans << endl;
}

Measured memory_bytes: 4840
from __future__ import annotations

import itertools
import unittest
from dataclasses import dataclass, field, InitVar
from typing import List


def create_order_patterns(n: int):
    return itertools.product(range(2), repeat=n)


@dataclass
class Book:
    id: int
    cost: int
    skill_points: List[int]


@dataclass
class SingleResult:
    border_line: int
    dim: InitVar[int]
    cost: int = 0
    skill_points: List[int] = field(init=False)

    def __post_init__(self, dim: int):
        self.skill_points = [0 for _ in range(dim)]

    def register(self, book: Book):
        self.cost += book.cost

        self.skill_points = [p1 + p2 for p1, p2 in zip(self.skill_points, book.skill_points)]

    def has_item(self) -> bool:
        return self.cost > 0

    def is_satisfy(self) -> bool:
        return all([p >= self.border_line for p in self.skill_points])


@dataclass
class Results:
    values: List[SingleResult] = field(default_factory=list)

    def add(self, single_result: SingleResult) -> None:
        self.values.append(single_result)  # メモリ優先

    def min_cost_ok(self) -> int:
        satisfied_books = [book for book in self.values if book.is_satisfy()]

        if not satisfied_books:
            return -1

        return min([book.cost for book in satisfied_books])

    @staticmethod
    def create(dim: int, border_line: int, book_lineup: List[Book], order_patterns) -> Results:
        results = Results()

        for order in order_patterns:
            single_result = SingleResult(border_line, dim)

            for idx, is_buy in enumerate(order):
                if is_buy == 1:
                    single_result.register(book_lineup[idx])

            if single_result.has_item():
                results.add(single_result)

        return results


def actual(N, M, X, books_info):
    book_lineup = []

    for idx, book_info in enumerate(books_info, start=1):
        book = Book(id=idx, cost=book_info[0], skill_points=book_info[1:])
        book_lineup.append(book)

    results = Results.create(N, X, book_lineup, order_patterns=create_order_patterns(N))

    return results.min_cost_ok()


N, M, X = [int(x) for x in input().split()]

books_info = []
for _ in range(N):
  book_info = list(map(int, input().split()))
  books_info.append(book_info)

print(actual(N, M, X, books_info))

Measured memory_bytes: 19552
#include <iostream>
#include <algorithm>
#include <queue>
#include <map>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <climits>
using namespace std;

const int MAXN = 17;
const int SSIZE = 15000000;
const int INF = INT_MAX;

const int W = 3;
int N, M;

int three[MAXN];
bool vis[SSIZE];

void init() {
  three[0] = 1;
  for(int i = 1; i < MAXN; ++i) three[i] = three[i-1] * 3;
}

int get3(int s, int i) {
  return s/three[i]%3;
}

int getTop(int s, int pos) {
  int maxi = -1;
  for(int i = 0; i < N; ++i) {
    if(s % W == pos) maxi = i;
    s /= W;
  }
  return maxi;
}

int move(int s, int from, int to) {
  int a = getTop(s, from);
  int b = getTop(s, to);
  if(a == -1) return INF;
  if(a < b) return INF;
  s -= three[a] * from;
  s += three[a] * to;
  return s;
}

void show(int s) {
  for(int i = 0; i < N; ++i) {
    cout << s%3;
    s /= 3;
  }
  cout << endl;
}

int bfs(int s) {
  queue<pair<int, int> > que;
  fill(vis, vis+SSIZE, false);
  que.push(make_pair(s,0));
  vis[s] = true;

  int goal1, goal2;
  goal1 = goal2 = 0;
  for(int i = 0; i < N; ++i) goal2 += three[i]*2;
  if(s == goal1 || s == goal2) {
    return 0;
  }

  while(!que.empty()) {
    s = que.front().first;
    int cost = que.front().second;
    que.pop();
    if(cost == M) continue;
    for(int i = 0; i < W; ++i) {
      for(int j = 0; j < W; ++j) {
	if(abs(i-j) != 1) continue;
	int ns = move(s, i, j);
	if(ns == INF) continue;
	if(vis[ns]) continue;
	if(ns == goal1 || ns == goal2) {
	  return cost+1;
	}
	vis[ns] = true;
	que.push(make_pair(ns, cost+1));
      }
    }
  }
  return INF;
}

int main() {
  init();
  while(cin >> N >> M && (N|M)) {
    int sum = 0;
    for(int i = 0; i < W; ++i) {
      int k;
      cin >> k;
      while(k--) {
	int a;
	cin >> a;
	--a;
	sum += three[a] * i;
      }
    }
    int ans = bfs(sum);
    if(ans <= M) {
      cout << ans << endl;
    } else {
      cout << -1 << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 15864
package main

import (
	"bufio"
	_ "container/heap"
	"fmt"
	"os"
	_ "sort"
	"strconv"
)

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func lcm(a, b int) int {
	return a / gcd(a, b) * b
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
const MOD = int(1e+9) + 7
const INF = 1 << 60

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	defer wtr.Flush()
	N := sc.nextInt()
	S := sc.nextStr()
	ok := [][]int{[]int{0, 0}, []int{1, 1}, []int{0, 1}, []int{1, 0}}
	ng := [][]int{[]int{0, 1}, []int{1, 0}, []int{0, 0}, []int{1, 1}}
	isTrue := false
	var ans []int
	for i := 0; i < 4; i++ {
		var first int
		switch i {
		case 0, 1:
			first = 0
		case 2, 3:
			first = 1
		}
		var next int
		var last int
		if S[0] == 'o' {
			next = ok[i][1]
			last = ok[i][0]
		} else {
			next = ng[i][1]
			last = ng[i][0]
		}

		arr := []int{first}
		now := first
		for i := 1; i < N; i++ {
			tmp := next
			if S[i] == 'o' {
				if next == 0 {
					if now == 0 {
						next = 0
					} else {
						next = 1
					}
				} else {
					if now == 0 {
						next = 1
					} else {
						next = 0
					}
				}
			} else {
				if next == 0 {
					if now == 0 {
						next = 1
					} else {
						next = 0
					}
				} else {
					if now == 0 {
						next = 0
					} else {
						next = 1
					}
				}
			}
			now = tmp
			arr = append(arr, now)
		}
		if next == first && now == last {
			isTrue = true
			ans = arr
		}
	}
	if !isTrue {
		fmt.Fprintln(wtr, "-1")
	} else {
		for i := 0; i < N; i++ {
			if ans[i] == 0 {
				fmt.Fprint(wtr, "S")
			} else {
				fmt.Fprint(wtr, "W")
			}
		}
		fmt.Fprintln(wtr)
	}
}


Measured memory_bytes: 14080
import java.util.*;

public class Main {

	public static void main(String[] args) throws Exception {
		final Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();

		PriorityQueue<int[]> pq = new PriorityQueue<>((a, b) -> Integer.compare(a[1], b[1]));

		SegmentTree st = new SegmentTree(n);
		int[][] xs = new int[m][3];
		for (int i = 0; i < m; i++) {
			xs[i][0] = sc.nextInt();
			xs[i][1] = sc.nextInt();
			xs[i][2] = sc.nextInt();
		}
		Arrays.sort(xs, (a, b) -> Integer.compare(a[0], b[0]));
//		for (int[] a : xs)
	//		System.out.println(Arrays.toString(a));
		long answer = 0;
		for (int i = 1, p = 0; i <= n; i++) {
			while (p < m && i == xs[p][0]) {
				st.add(0, xs[p][0], xs[p][2]);
				pq.offer(xs[p++]);
			}

			long v = st.query(0, i);
			st.add(i, i + 1, v);
			answer = Math.max(answer, v);

			while (!pq.isEmpty() && pq.peek()[1] == i) {
				int[] u = pq.poll();
				st.add(0, u[0], -u[2]);
			}
		}

		System.out.println(answer);
	}

	static class SegmentTree {
		 static final long MIN = -1_000_000_000_000_000L;
		 final int n;
		 long[] data;
		 long[] add;

		public SegmentTree(int n) {
			int t = 1;
			while (t < n)
				t <<= 1;
			this.n = t;
			this.data = new long[t * 2 - 1];
			this.add = new long[t * 2 - 1];
		}

		// [l, r)
		public long query(int a, int b) {
			return query(a, b, 0, 0, n);
		}

		private long query(int a, int b, int k, int l, int r) {
			if (b <= l || r <= a)
				return MIN;
			if (a <= l && r <= b)
				return data[k];
			long vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
			long vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
			return Math.max(vl, vr) + add[k];
		}

		// [a, b) v
		public void add(int a, int b, long v) {
			add(a, b, v, 0, 0, n);
		}

		private void add(int a, int b, long v, int k, int l, int r) {
			if (b <= l || r <= a)
				return;
			if (a <= l && r <= b) {
				add[k] += v;
				data[k] += v;
				return;
			}
			add(a, b, v, k * 2 + 1, l, (l + r) / 2);
			add(a, b, v, k * 2 + 2, (l + r) / 2, r);
			data[k] = Math.max(data[k * 2 + 1], data[k * 2 + 2]) + add[k];
		}
	}
}

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

ll power3(ll x){
    return x * x * x;
}


int main() {
    ll N, K;
    cin >> N >> K;
    /* Kが奇数の時，a,b,cの全てがKで割り切れる必要がある
     * Kが偶数の時，a,b,cの全てがKで割り切れる，もしくはa,b,cがK/2である必要がある
     */
    if(K % 2 == 1){
        ll kk = N / K;
        cout << power3(kk) << endl;
        return 0;
    }else if(K % 2 == 0){
        ll kk = N / K;
        ll ff = 0;
        if(N % K >= K / 2){
            ff = kk + 1;
        }else{
            ff = kk;
        }
        cout << power3(kk) + power3(ff) << endl;
        return 0;
    }
}


Measured memory_bytes: 256
from collections import Counter
mod = 998244353

n = int(input())
dl = list(map(int, input().split()))
c = Counter(dl)

if dl[0]!=0:
    print(0)
    exit()

if c[0]!=1:
    print(0)
    exit()

res = 1
for x in range(max(dl)):
    res *= pow(c[x],c[x+1],mod)
    res %= mod

print(res)

Measured memory_bytes: 19936
n=int(input())
s=input()

e=0
w=0

all_e=s.count("E")
ans=float('inf')
for i in range(n):

  ans=min(all_e-e+w,ans)

  if s[i]=="E":
    e+=1
  else:
    w+=1

ans=min(ans,all_e-e+w,ans)
print(ans)

Measured memory_bytes: 9512
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <tuple>
#include <set>

using namespace std;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
#define out(S) cout<<(S)<<endl;
#define REP(i,b) for(size_t i=0;i<(b);i++)
#define rREP(i,b) for(int i=(b)-1;i>=0;i--)
#define FOR(i,a,b) for(size_t i=(a);i<(b);i++)
#define rFOR(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define Foreach(item,collection) for(auto item:collection)
#define mod(i) ((i) % (ll)(1e9 + 7))
ll modpow(ll i, ll j) { ll tmp = 1; while (j) { if (j % 2)tmp = mod(tmp*i); i = mod(i*i); j /= 2; }return tmp; }
#define divmod(a,b) (mod(a * modpow((ll)b,(ll)(1e9 + 5))))
#define Yes out("Yes")
#define No out("No")
#define NO out("NO")
#define YES out("YES")
#define INF 1e10;
#define ShowAll(collection) for(auto i:collection){out(i);}
#define IfOut(condition,text) if((condition)){out(text);return 0;}
#define IfeOut(condition,itext,etext) if(condition){out(itext);return 0;}else{out(etext);return 0;}
#define Select(collection,condition,result) Foreach(i,collection){result+=condition;}
#define GetAuto(_N,vect) {cin>>_N;vect.resize(_N);REP(i,_N){cin>>vect[i];}}
#define beginend(vec) (vec).begin(),(vec).end()
#define pb(item) push_back(item)
#define removeAll(vec,deleg) auto itr=remove_if(beginend(vec),deleg);vec.erase(itr,vec.end());
void removeAt(string& s, int index) { s.erase(index, 1); }
template<typename T> void removeAt(vector<T>& v, int index) { v.erase(v.begin() + index); }
ll manhattanDistance(ll x1, ll y1, ll x2, ll y2) { return (abs(x2 - x1) + abs(y2 - y1)); }
vector<ll> sieveOfEratosthenes(int max) {ll prime;double sqrtmax = sqrt(max);vector<ll> primeVec, searchVec;FOR(i, 2, max + 1) searchVec.push_back(i);do{prime = searchVec[0];primeVec.push_back(prime);auto itr = remove_if(beginend(searchVec), [=](ll x)->bool {return x%prime == 0; });searchVec.erase(itr, searchVec.end());} while (prime < sqrtmax);primeVec.reserve(primeVec.size() + searchVec.size());primeVec.insert(primeVec.end(), beginend(searchVec));return primeVec;}


int main() {
	ll N, M;
	cin >> N>> M;
	IfOut(!(N == M || N - 1 == M || M - 1 == N), "0");
	if (N == M) {
		ll ans = mod(N);
		ans = mod(ans*N);

		rFOR(i, N, 2) {
			ans = mod(ans*i);
			ans = mod(ans*i);
		}
		out(mod(ans*2));
	}
	else {
		ll ans = mod(N);
		ans = mod(ans*M);

		if (N < M) swap(N, M);
		rFOR(i, N, 2) {
			ans = mod(i*ans);
			ans = mod((i - 1)*ans);
		}
		out(mod(ans));
	}
	return 0;
}

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

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;
typedef vector<double> vd;
typedef vector<vd> vdd;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)
#define RFOR(i,x,y) for(ll i=(ll)x; i>=(ll)y; --i)
#define RREP(i,x) RFOR(i, x, 0)
#define ALL(a) a.begin(), a.end()
#define pb push_back
#define debug_print(x...) cerr << "line " << __LINE__ << " : "; debug_print_in(x);

template <typename First>
void debug_print_in(First first){
  cerr << first << endl;
  return;
}

template <typename First, typename... Rest>
void debug_print_in(First first, Rest... rest){
  cerr << first << " ";
  debug_print_in(rest...);
  return;
}

void IN(void){
  return;
}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
  cin >> first;
  IN(rest...);
  return;
}

template <typename First>
void OUT(First first){
  cout << first << endl;
  return;
}

template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
  cout << first << " ";
  OUT(rest...);
  return;
}

template<class t, class u> void chmax(t&a,u b){if(a<b)a=b;};
template<class t, class u> void chmin(t&a,u b){if(a>b)a=b;};
int popcount(int t){return __builtin_popcount(t);} //GCC
int popcount(ll t){return __builtin_popcountll(t);} //GCC

template <typename T>
void vec_print(vector<T> VEC){
  REP(i, VEC.size()){
    cerr << VEC[i] << " ";
  }
  cerr << endl;
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  REP(i,MAT.size()){
    REP(j,MAT[i].size()){
      cerr << MAT[i][j] << " ";
    }
    cerr << endl;
  }
};

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9)+7);

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  ll N;
  IN(N);
  vll A(N), B(N), C(N);
  REP(i,N){
    IN(A[i]);
    B[i] = A[i]+i;
    C[i] = A[i]-i;
  }
  sort(ALL(C));

  ll ans = 0;
  REP(i,N){
    ll B_tmp = B[i];
    ans += (ll)(upper_bound(ALL(C), -B_tmp) - lower_bound(ALL(C), -B_tmp));
  }

  OUT(ans);


  return 0;
}

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

int main() {
  int N,M;
  cin >> N >> M;
  int answer1 = 0;
  int answer2 = 1000000;
  for(int i = 0;i < M;i++) {
    int A,B;
    cin >> A >> B;
    if(answer1 < A) {
      answer1 = A;
    }
    if(answer2 > B) {
      answer2 = B;
    }
  }
  if(answer2 - answer1 + 1 >= 0) {
    cout << answer2 - answer1 + 1 << endl;
  }
  else {
    cout << 0 << endl;
  }
}

Measured memory_bytes: 256
s = input().split()

h = int(s[0])
w = int(s[1])

line = []
row = []

a = [''] * h

for i in range(h):
    a[i] = input()

for i in range(h):
    line.append(False)
for i in range(w):
    row.append(False)

for i in range(h):
    for j in range(w):
        if a[i][j] == '#':
            line[i] = True
            row[j] = True

for i in range(h):
    if line[i]:
        for j in range(w):
            if row[j]:
                print(a[i][j], end='')
        print('')



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

int main (void)
{
  int n;
  int a[100];
  int b[100];
  int c[100];
  cin >> n;
  for(int i = 0; i < n; ++i) {
    cin >> a[i+1];
  }
  for(int i = 0; i < n; ++i) {
    cin >> b[i+1];
  }
  for(int i = 0; i < n - 1; ++i) {
    cin >> c[i+1];
  }
  int sum = 0;
  int previous_dish = -200;
  for (int i = 0; i < n; ++i){
    sum+=b[a[i+1]];
    if (previous_dish >= 0 && previous_dish+1==a[i+1]) sum+=c[previous_dish];
    previous_dish = a[i+1];
  }
  cout << sum;
}

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

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define per(i,n) for(int i = (n)-1; i >= 0; --i)
#define rng(i,a,b) for(int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define _GLIBCXX_DEBUG
#define DEBUG(x) cerr<<__LINE__<<": "<<#x<<" = "<<x<<"\n"

int main() {
    string str; cin >> str;
    int n = str.size();
    vvl alp(26);
    rep(i,n) alp[str[i]-'a'].push_back(i);

    vl ss(1,n);
    set<char> S;
    per(i,n) {
        S.insert(str[i]);
        if (S.size() == 26) {
            ss.push_back(i);
            S.clear();
        }
    }
    reverse(all(ss));

    string ans = "";
    rep(c,26) {
        if (S.find(c+'a') == S.end()) {
            ans += c+'a';
            break;
        }
    }
    int pre = 0;
    while (ss[pre] < n) {
        int pre_c = ans[pre]-'a';
        int pos = *lower_bound(all(alp[pre_c]), ss[pre]);
        rep(c,26) {
            auto p = lower_bound(all(alp[c]), pos+1);
            if (p == alp[c].end() or *p >= ss[pre+1]) {
                ans += c+'a';
                pre++;
                break;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2436
#include <bits/stdc++.h>
#define INF 0x3f3f3f3f3f3f3f3f
#define MOD 1000000007
typedef long long ll;
using namespace std;
ll n,sum1,sum2;
vector<ll>tot;
int main(){
	//freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    cin>>n;
    vector<pair<ll,ll> >v(n);
    for(ll i=0;i<n;i++){
    	cin>>v[i].first>>v[i].second;
    	tot.push_back(v[i].first);
    	tot.push_back(v[i].second);
	}
	for(auto x : v){
		sum1+=x.first;
		sum2+=x.second;
	}
	ll ans=min(sum1,sum2);
	ll sum=0;
	sort(tot.begin(),tot.end());
	for(ll i=0;i<n;i++)
	sum+=tot[i];
	for(ll i=0;i<n;i++){
		ll mx=max(v[i].first,v[i].second);
		ll mn=min(v[i].first,v[i].second);
		if(mn>tot[n-1] || mx<tot[n-1]){
			cout<<sum;
			return 0;
		}
		ll tmp=sum;
		tmp+=mx-tot[n-1]+max(0ll,mn-tot[n-2]);
		ans=min(ans,tmp);
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3956
#include <iostream>
#include <algorithm>
#include <string>
#include <queue>
#include <cstring>
#include <utility>
#include <vector>
#include <functional>
using namespace std;
 
#define DEBUG(x) cerr << #x << " = " << x << endl
 
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
 
int cost[502][502][4];
int d[501][501];
 
// x, y
typedef pair<int, int> P;
// cost, to
typedef pair<int, P> Node;
 
int main() {
	int W, H, N; cin >> W >> H >> N;
	P S, G;
	cin >> S.first >> S.second >> G.first >> G.second;
	memset(cost, 0, sizeof(cost));
	for(int iN = 0; iN < N; iN++) {
		P p; cin >> p.first >> p.second;
		int times; string move_;
		cin >> times >> move_;
		while(times--) {
		for(int i = 0; i < (int)move_.length(); i++) {
			char c = move_[i];
			int dir;
			if(c == 'R') dir = 0;
			if(c == 'D') dir = 1;
			if(c == 'L') dir = 2;
			if(c == 'U') dir = 3;
 
			int nx = p.first + dx[dir];
			int ny = p.second + dy[dir];
 
			if(0 <= nx && nx < W && 0 <= ny && ny < H) {
				if(dir == 0) {
					cost[p.first + 1][p.second    ][1] += 1;
					cost[p.first + 1][p.second + 1][3] += 1;
				}
				if(dir == 1) {
					cost[p.first    ][p.second + 1][0] += 1;
					cost[p.first + 1][p.second + 1][2] += 1;
				}
				if(dir == 2) {
					cost[p.first    ][p.second    ][1] += 1;
					cost[p.first    ][p.second + 1][3] += 1;
				}
				if(dir == 3) {
					cost[p.first][p.second][0] += 1;
					cost[p.first + 1][p.second][2] += 1;
				}
				p.first = nx; p.second = ny;
			}
		}
		}
	}
#if 0
	for(int iH = 0; iH <= H; iH++) {
	for(int iW = 0; iW <= W; iW++) {
	for(int dir = 0; dir < 4; dir++) {
		cout << "(" << iW << "," << iH << "," << dir << ") = " << cost[iW][iH][dir] << endl;
	}
	}
	}
#endif
	for(int iW = 0; iW <= W; iW++) {
	for(int iH = 0; iH <= H; iH++) {
		d[iW][iH] = (int)1e9;
	}
	}
	priority_queue<Node, vector<Node>, greater<Node> > Q;
	Q.push(Node(0, S));
	d[S.first][S.second] = 0;
	while(!Q.empty()) {
		Node node = Q.top(); Q.pop();
		int curX = node.second.first;
		int curY = node.second.second;
		if(node.first > d[curX][curY]) continue;
		for(int i = 0; i < 4; i++) {
			int nx = curX + dx[i];
			int ny = curY + dy[i];
			if(0 <= nx && nx <= W && 0 <= ny && ny <= H && d[nx][ny] > node.first + cost[curX][curY][i]) {
		// DEBUG(nx);
		// DEBUG(ny);
				d[nx][ny] = node.first + cost[curX][curY][i];
				Q.push(Node(d[nx][ny], P(nx, ny)));
			}
		}
	}
#if 0
	for(int iH = 0; iH <= H; iH++) {
	for(int iW = 0; iW <= W; iW++) {
		cout << "(" << iW << "," << iH << ") = " << d[iW][iH] << endl;
	}
	}
#endif
	cout << d[G.first][G.second] << endl;
}

Measured memory_bytes: 10084
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1e18

int main() {
    int k, q;
    cin >> k >> q;
    vector<ll> d0(k);
    for (int i = 0; i < k; i++) cin >> d0[i];

    for (int i = 0; i < q; i++) {
        ll ans, c0 = 0, c1 = 0;
        vector<ll> d = d0, c(k);
        ll n, x, m, ah, at;
        cin >> n >> x >> m;

        ans = n - 1;
        ah = at = x;
        for (int j = 0; j < k; j++) {
            d[j] %= m;
            c[j] = (n - 2) / k + (j <= (n - 2) % k);
            if (d[j] == 0) c0 += c[j];
            at = at + d[j] * c[j];
        }
        c1 = at / m - ah / m;
        ans -= (c0 + c1);
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 384
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#define REP(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 1
#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR
#endif


//改造
typedef long long int ll;
using namespace std;


//ここから編集する


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

    stack<char> st;

    REP(i,0,x.size()){
        if(st.empty()){
            st.push(x[i]);
        }else if(st.top() == 'S'){
            if(x[i] == 'T'){
                st.pop();
            }else{
                st.push(x[i]);
            }
        }else if(st.top() == 'T'){
            st.push(x[i]);
        }
    }

    cout << st.size() << endl;

    return 0;
}


Measured memory_bytes: 644
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy, copy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
#import numpy as np
#from decimal import *

N = INT()
s = [str(sorted(list(input()))) for _ in range(N)]

dic = Counter(s)
ans = 0
for v in dic.values():
	ans += v*(v-1)//2

print(ans)



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


using namespace std;

#define SZ(x) (int)(x.size())

using ll = long long;
#define int ll
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const ll MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

template<typename T1, typename T2>
ostream& operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}


template<typename T>
T mypow(T x, T n, const T &p) {
  T ret = 1;
  while(n) {
    if(n&1) {
      ret *= x;
      ret %= p;
    }
    x *= x;
    x %= p;
    n>>=1;
  }
  return ret;
}

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

  int n; cin >> n;
  vi a(n);
  vi su0(n+1, 0);
  vi sux(n+1);
  for(int i=0;i<n;++i) {
    cin >> a[i];
  }

  for(int i=0;i<n;++i) {
    sux[i+1] = a[i] ^ sux[i];
    su0[i+1] = su0[i] + (sux[i+1] == 0);
  }

  //printv(sux);
  //printv(su0);

  map<int, vi> mp;
  for(int i=0;i<n;++i) {
    mp[sux[i+1]].push_back(i+1);
  }

  ll res = 0;
  for(auto &e1: mp) {
    int val = e1.first;
    vi v = e1.second;
    //cout << val << endl;

    if(sux[n] != 0 && val != sux[n]) continue;

    if(val == 0) {
      if(su0[n] >= 1) res += mypow<int>(2, su0[n]-1, (int)MOD);
      res %= MOD;
      //cout << res << endl;
      continue;
    }
    
    //cout << "val:" << val << endl;;
    //cout << "v:";
    //printv(v);

    int sz = SZ(v);
    vll st1(sz+1), st2(sz+1);
    
    for(int i=0;i<sz;++i) {
      ll now = 1;
      ll tmp = su0[v[i]-1];
      now += tmp * st1[i] % MOD;
      now += MOD - st2[i] % MOD;
      now %= MOD;
      st1[i+1] = (st1[i] + now) % MOD;
      st2[i+1] = (st2[i] + now * tmp % MOD) % MOD;
      //cout << now << endl;
      if(i == sz-1 || sux[n] == 0) res += now;
      res %= MOD;
    }
    //cout << res << endl;
  }
  cout << res << endl;
  //cout << (1<<30) % MOD << endl;
}


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

using namespace std;

int main(void){
	
	int i;
	char a;
	vector<char> str;
	
	while(scanf("%c",&a)!=EOF){
		if('a'<=a&&a<='z'||a==' '||a=='.'){
			a=toupper(a);	
			str.push_back(a);
		}
	}
	
	for(i=0;i<(str.size());i++){
		cout<<str[i];
	}
	puts("");
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 1;i<n;i++)
int main(){
int n, m;
m = 0;
cin >> n;
rep(i,10){
    if(n/i <10 && n%i == 0)m = 1;
}
if(m == 1){
    cout << "Yes" << endl;
}else{
    cout << "No" << endl;
}

}

Measured memory_bytes: 256
import sys
import bisect
input = sys.stdin.readline

def main():
    n, q = map(int, input().split())

    ans = 0
    min1, min2 = n-2, n-2
    judge1 = [-n-1]
    judge2 = [-n-1]
    dict1 = dict()
    dict2 = dict()
    dict1[-n-1] = n-2
    dict2[-n-1] = n-2

    for i in range(q):
        query, x = map(int, input().split())

        if query == 1:
            index = bisect.bisect(judge1, -x)-1
            key = dict1[judge1[index]]
            ans += key
            if min1 > x-2:
                min1 = x-2
                judge1.append(-x)
                dict1[-x] = key
                dict2[judge2[-1]] = min1
        else:
            index = bisect.bisect(judge2, -x)-1
            key = dict2[judge2[index]]
            ans += key
            if min2 > x-2:
                min2 = x-2
                judge2.append(-x)
                dict2[-x] = key
                dict1[judge1[-1]] = min2

    print((n-2)**2 - ans)
    
    
    
    
if __name__ == "__main__":
    main()


Measured memory_bytes: 38152