akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#define N 100005
#define NIL -1
 
struct Node{
  int p, left, right;
};

struct Node T[N];
int n;
 
int getDepth(int p){
  if(T[p].p == NIL) return 0;
  else{
    return getDepth(T[p].p) + 1; 
  }
}
 
int getHeight(int p){
  int count, max = 0,i;

  for(i = 0; i < n; i++){
    if(T[i].p == p){
    count = getHeight(i) + 1;
    if(max < count) max = count;
    }
  }
  return max;
}
 
main(){
  int c1, c2,i,id, tmp;
  int dep[N], hei[N], sib[N], deg[N];
 
  scanf("%d", &n);
  for(i = 0; i < n; i++){
    T[i].left = T[i].p = T[i].right = NIL;
    deg[i] = hei[i] = 0;
    sib[i] = deg[i] = NIL;
  }
  for(i = 0; i < n; i++){
    scanf("%d %d %d", &id, &c1, &c2);
 
    if(c1 == NIL && c2 == NIL){
      deg[id] = 0;
 
    }else if (c1 != NIL && c2 == NIL){
      T[c1].p = id;
      T[id].left = c1;
      deg[id] = 1;
 
    }else if(c1 == NIL && c2 != NIL){
      deg[id] = 1;
      T[c2].p = id;
      T[id].right = c2;
    }else{
      deg[id] = 2;
      T[c1].p = id;
      T[c2].p = id;
      T[id].left = c1;
      T[id].right = c2;
      sib[c1] = c2;
      sib[c2] = c1;
    }    
  }
  for(i = 0; i < n; i++){
    dep[i] = getDepth(i);
    hei[i] = getHeight(i);
  }
   
  for(i = 0; i < n; i++){
    printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, ", i, T[i].p, sib[i], deg[i], dep[i], hei[i]);
    if(T[i].p == -1){
      printf("root\n");
    }else if(T[i].left == NIL && T[i].right == NIL){
      printf("leaf\n");
    }else{
      printf("internal node\n");
    }
  }
  return 0;
}

Measured memory_bytes: 636
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair<ll, ll>
#define F first
#define S second
const int MOD = 1000000007;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }
//sort(all(x))とするとソートできるよ
// 10^x は pow(10,(x)) 
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main(){
    LL N,A;cin >> N >> A;
    vector<LL> x(N+1);
    rep(i,N)cin >> x[i];
    LL dp[52][52][52*(N+1)] = {0};
    rep(i,N+1) rep(j,N+1) for(LL k = 0;k<50*(N+1);k++){
        if(i == 0 && j == 0 && k == 0)dp[0][0][0] = 1;
        else if(i == 0)continue;
        else if(i < j)continue;
        dp[i+1][j][k] += dp[i][j][k];       // 次のカードを引かないとき
        dp[i+1][j+1][k+x[i]] += dp[i][j][k];    // 次のカードを引くとき
    }
    LL ans = 0;
    for(LL j = 1;j<N+1;j++){
        ans += dp[N][j][A*j];
    }
    cout << ans << endl;
}



Measured memory_bytes: 55936
import std.conv, std.functional, std.range, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;
import core.bitop;

class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }
int readInt() { return readToken.to!int; }
long readLong() { return readToken.to!long; }
real readReal() { return readToken.to!real; }

bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }
bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }

int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }
int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }
int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }


enum M = 360;

void main() {
  try {
    for (; ; ) {
      const X = readInt();
      
      const ans = M / gcd(X, M);
      writeln(ans);
    }
  } catch (EOFException e) {
  }
}


Measured memory_bytes: 3396
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>

using namespace std;
#define vsort(v) sort(v.begin(), v.end());

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int A, B, K;
	cin >> A >> B >> K;
	int i = A;
	int ii = B;
	vector<int> v;
	int k = 0;
	while(k < K){
		if(i <= B) v.push_back(i);
		//v.push_back(i);
		//cout << i << endl;
		k += 1;
		i += 1;
	}
	k = 0;
	i = B;
	while(k < K){
		//cou << i << endl;
		if(i >= A) v.push_back(i);
		k += 1;
		i -= 1;
	}
	vsort(v);
	v.erase(unique(v.begin(), v.end()),v.end());
	for(int i = 0;i < v.size();i++){
		cout << v[i] << endl;
	}
}


Measured memory_bytes: 256
from collections import defaultdict

n = int(input())
v = list(map(int, input().split()))

odd = defaultdict(lambda: 0)
even = defaultdict(lambda: 0)
odd[None] = 0
even[None] = 0
for i in v[0::2]:
    odd[i] += 1
for i in v[1::2]:
    even[i] += 1

odd = sorted(odd.items(), key=lambda x: x[1], reverse=True)
even = sorted(even.items(), key=lambda x: x[1], reverse=True)
if odd[0][0] != even[0][0]:
    count = n - odd[0][1] - even[0][1]
else:
    count = n - max(odd[0][1]+even[1][1], odd[1][1]+even[0][1])

print(count)


Measured memory_bytes: 18648
#include<bits/stdc++.h>
 
using namespace std;
 
int main(){
	int ans=0;
	long int N;
	cin >> N;
	if(N%10 == 0){
		cout << 10 << endl;
		return 0;
	}
	int k[5];
	int kake=10000;
	for(int i=0;i<5;i++){
		k[i] = N/kake;
		N -= k[i]*kake;
		kake /= 10;
		ans += k[i];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using longlong=long long;

int main(){
    std::cin.tie(nullptr);std::cin.sync_with_stdio(false);
    int h,w;std::cin>>h>>w;
    std::vector<std::vector<char>>g(h,std::vector<char>(w));
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            std::cin>>g[i][j];
        }
    }
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(g[i][j]=='#'){
                std::cout<<'#';
                continue;
            }
            int x=0;
            for(int di=-1;di<=1;di++){
                for(int dj=-1;dj<=1;dj++){
                    if(di==0&&dj==0)continue;
                    int ni=i+di,nj=j+dj;
                    if(ni<0||h<=ni||nj<0||w<=nj)continue;
                    x+=g.at(ni).at(nj)=='#';
                }
            }
            std::cout<<x;
        }
        std::cout<<std::endl;
    }
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
/*{{{*/
#include <bits/stdc++.h>
#ifdef LOCAL
int c_ = 0;
#define cout (c_?cerr:cout)
#define debug(...) \
{if(!c_++)cerr<<"\033[96;1m"; \
__VA_ARGS__; \
if(!--c_)cerr<<"\033[0m";}
#else
#define debug(...) {}
#endif
#define assrt(...) debug(\
if (not (__VA_ARGS__)) \
    exit((cerr << __LINE__ << ": " << #__VA_ARGS__ << '\n', 0));\
)
#define st first
#define nd second
#define all(...) (__VA_ARGS__).begin(), (__VA_ARGS__).end()
using namespace std; using ll = long long;
template < typename t > using V = vector< t >;
template < typename t, size_t s > using A = array< t, s >;
void print() {cout << '\n';}
template< typename t, typename... v >
void print(const t& a, const v&... b)
{cout << a << (sizeof...(b)?" ":""); print(b...);}
template< typename t > void print_range(t a, const t& b)
{ while (a != b) cout << (*a++) << ' '; cout << '\n';}
#define dump(...) debug(print(#__VA_ARGS__,'=',__VA_ARGS__))
#define dump_range(...) debug(cerr<<#__VA_ARGS__ << ": "; print_range(__VA_ARGS__))
/*}}}*/

constexpr int nax = 1e5;
constexpr ll inf = 1e18;

int n, tab[nax + 2];
ll dp[nax + 2][2];

int32_t main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    cin >> n;

    for (int i = 1; i <= n; ++i)
        cin >> tab[i];

    for (int i = 0; i <= n; ++i)
        for (int j = 0; j < 2; ++j)
            dp[i][j] = -inf;

    dp[0][0] = 0;

    for (int i = 1; i <= n; ++i)
        for (int j = 0; j < 2; ++j)
            for (int k = 0; k < 2; ++k)
                dp[i][j] = max(dp[i][j], dp[i - 1][k] + tab[i] * (j? -1 : 1) * (k? -1 : 1));

    print(dp[n][0]);
}

Measured memory_bytes: 2176
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SZ(x) ((int)x.size())
#define FOR(i,a,b) for (int i=a;i<=b;++i)
#define FORD(i,a,b) for (int i=a;i>=b;--i)
using namespace std;
typedef long long LL;
typedef pair<int,int> pa;
typedef vector<int> vec;
void getint(int &v){
    char ch,fu=0;
    for(ch='*'; (ch<'0'||ch>'9')&&ch!='-'; ch=getchar());
    if(ch=='-') fu=1, ch=getchar();
    for(v=0; ch>='0'&&ch<='9'; ch=getchar()) v=v*10+ch-'0';
    if(fu) v=-v;
}
int f[500010],n,nxt[500010],hed[500010],too[500010],nedge,x,y,ans;
void ae(int x,int y){
	nxt[++nedge]=hed[x];
	hed[x]=nedge;
	too[nedge]=y;
}
void dfs(int x,int l){
	int mx1=0,mx2=0;
	for (int i=hed[x];i;i=nxt[i]){
		int y=too[i];
		if (y==l) continue;
		dfs(y,x);
		if (f[y]+1>mx1) mx2=mx1,mx1=f[y]+1;
		else if (f[y]+1>mx2) mx2=f[y]+1;
	}
	ans=max(ans,mx1+mx2+1);
	f[x]=mx1;
}
int main(){
	cin>>n;
	FOR(i,2,n){
		getint(x),getint(y);
		ae(x,y),ae(y,x);
	}
	dfs(1,0);
	if (ans%3==2) puts("Second");
	else puts("First");
	return 0;
}


Measured memory_bytes: 21504
#include "bits/stdc++.h"
//#include "ext/pb_ds/assoc_container.hpp"
//#include "ext/pb_ds/tree_policy.hpp"
//using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
#define int long long
#define pb push_back
#define fi first
#define se second
#define fr(i, a, b) for(int i = a; i <= b; i++)
#define all(x) x.begin(), x.end()
#define IO ios :: sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define pii pair<int,int>
#define sz(x) (int)x.size()
const int mod = 1e9 + 7;
//const int mod1 = 998244353;
typedef long double f80;

#ifndef LOCAL
#pragma GCC optimize ("O2")
#define endl '\n'
#endif

//template<typename T>
//using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
//
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//int rand(int l, int r){
//    uniform_int_distribution<int> uid(l, r);
//    return uid(rng);
//}

ll pwr(ll a,ll b, ll mod){
    a %= mod;
    ll ans = 1;
    while(b){
        if(b & 1) ans = (ans * a) % mod;
        a = (a * a) % mod;
        b >>= 1;
    }
    return ans;
}

string to_string(string s) {
    return '"' + s + '"';
}

string to_string(const char* s) {
    return to_string((string) s);
}

string to_string(bool b) {
    return (b ? "true" : "false");
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for (const auto &x : v) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

map<pii,int> m;
int ans[10];

void solve(){
    int h, w, n;
    cin >> h >> w >> n;
    fr(i, 1, n) {
        int a, b;
        cin >> a >> b;
        fr(i, 0, 2) {
            fr(j, 0, 2) {
                int x = a + i, y = b + j;
                if(x - 2 >= 1 && x <= h && y - 2 >= 1 && y <= w) {
                    m[{x, y}]++;
                }
            }
        }
    }
    int tot = (h - 2) * (w - 2);
    for(auto x : m) {
        ans[x.se]++;
        tot--;
    }
    cout << tot << endl;
    fr(i, 1, 9) {
        cout << ans[i] << endl;
    }
}

signed main(){
    IO;
#ifdef LOCAL
    freopen("inp.txt","r", stdin);
#endif
    cout << setprecision(3) << fixed;
    //    srand(time(NULL));
    //    build();
    int t = 1;
//    cin >> t;
    fr(tt, 1, t){
//        cout << "Case #" << tt << ": ";
        solve();
    }
    return 0;
}


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

using namespace std;

int main() {
    int r, d, x;
    vector<int> v;
    cin >> r >> d >> x;
    v.push_back(r * x - d);
    for (int i = 1; i < 10; ++i) v.push_back(r * v.at(i - 1) - d);
    for (int i = 0; i < v.size(); ++i) cout << v.at(i) << endl;
}

Measured memory_bytes: 256
#from matplotlib import pyplot as plt
def binary_search(mn,mx,a,x,y):
    #リストlからaの値のインデックスをサーチする。
    #二分探索を可能にするためにはリストlはソートされていなければならない。
    z = (mx+1)//2
    low = mn
    high = mx+1
    while low <= high:
        temp = rule2(x,y,z)
        if temp == a:
            if z <= 0:
                return None
            return z
        elif temp < a:
            low = z + 1
        elif temp > a:
            high = z - 1

        z = (low + high) // 2
    return None

def rule2(x,y,z):
    return x ** 2 + y ** 2 + z**2 + x * y + y * z + z*x
def main():
    n = int(input())
    x = []
    y = []
    for i in range(1,n+1):
        #x.append(i)
        #y.append(f(i))
        print(f(i))
    #plt.scatter(x,y)
    #plt.show()


def f(n):
    counter = 0
    for x in range(1,n):
        if x ** 2 > n:
            break
        for y in range(x,n-x**2):
            if y < x:
                continue
            if x ** 2 + y ** 2 > n:
                break
            z = binary_search(y,n-x**2-y**2-x*y,n,x,y)
            if z == None:
                continue
            else:
                if rule2(x,y,z) == n:
                    if x == y and y == z and z == x:
                        counter += 1
                    elif x != y and y != z and z != x:
                        counter += 6
                    else:
                        counter += 3

    return counter


if __name__ == '__main__':
    main()

#6 24 54 96
#1  4  9 16
#18

Measured memory_bytes: 73260
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef vector<double> VD;
typedef vector<VD> VVD;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> days(n), earns(n);
    for (int i = 0; i < n; i++){
        cin >> days[i] >> earns[i];
    }
    vector<vector<int>> dead2earns(m);
    for (int i = 0; i < n; i++){
        int dead = m - days[i];
        if (dead >= 0){
            dead2earns[dead].push_back(earns[i]);
        }
    }
    priority_queue<int> pri_que;
    int ans = 0;
    for (int day = m - 1; day >= 0; day--){
        for (int earn : dead2earns[day]){
            pri_que.push(earn);
        }
        if (!pri_que.empty()){
            int x = pri_que.top();
            ans += x;
            pri_que.pop();
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 6400
#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 all(v) (v).begin(),(v).end()
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
constexpr ll INF = 1e18;

int main(void) {
    int N;
    string S;
    cin >> N >> S;
    int count = 0;
    for (int i = 0; i < N-2; i++) {
        if (S.substr(i, 3) == "ABC") count++;
    }
    cout << count << endl;
    return 0;
}



Measured memory_bytes: 888
#!/usr/bin/env python3
s = [input() for _ in range(3)]
pos = 0#a,b,c ordにして97からひく
idx = [0,0,0] #ABCそれぞれの現在のindex
for i in range(300):#大きめにとってもbreakするのでOK
	if idx[pos] == len(s[pos]):
		print(chr(65+pos))
		exit()
	idx[pos] += 1 #idxの更新
	pos = ord(s[pos][idx[pos] - 1]) - 97 # asciiの文字にして引く、更新する前のidx で次の文字列を判定して更新
	#print(pos)

Measured memory_bytes: 3064
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, m, n) for(int i=(m); i<(n); ++i)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define Cout(x) cout << (x) << endl
#define Cout2(x, y) cout << (x) << " " << (y) << endl
#define dump(x) cout << #x << " = " << (x) << endl;
#define forauto(i, a) for(auto i : a)cout << i << " "; puts("");
typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
const int inf = 1e9;
const double pi = acos(-1.0);

int main() {
	VS str = { "thu","fri","sat","sun","mon","tue","wed" };
	int x; cin >> x;
	Cout(str[x % 7]);
}


Measured memory_bytes: 3204
package main

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

const (
	initialBufSize = 1e4
	maxBufSize     = 1e8
)

var sc = bufio.NewScanner(os.Stdin)

func init() {
	buf := make([]byte, initialBufSize)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords)
}

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

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func main() {
	d := "Christmas"
	switch nextInt() {
	case 24:
		d += " Eve"
	case 23:
		d += " Eve Eve"
	case 22:
		d += " Eve Eve Eve"
	}
	fmt.Println(d)
}


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

int main(){
  double l, ans;

  cin >> l;

  ans = (l / 3) * (l / 3) * (l / 3);

  cout << fixed << setprecision(10);
  cout << ans << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _overload3(_1,_2,_3,_4,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n,s) for (int i=a;s>0?i<n:i>n;i+=s)
#define rep(...) _overload3(__VA_ARGS__,per,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
const int inf = 1e9+10, mod = 1e9+7; const long long llinf = 1e18;
// head

int main(){
  int count = 0;
  string s,C = "CODEFESTIVAL2016";
  cin >> s;
  rep(i,s.size()){
    if (s[i]!=C[i]) count ++;
  }
  cout << count << endl;
}

Measured memory_bytes: 256
N,A,B = map(int,input().split())

#結果格納用
result = 0

#分解 &リスト化
for i in range(N+1):
    list_N = list(int(n) for n in str(i))
    #条件判定
    if (A <= sum(list_N)) and (B >= sum(list_N)):
        result += i
print(result)


Measured memory_bytes: 3060
#include<iostream>
#define MAX 100
#define INFTY 1<<21
#define WHITE 0
#define GRAY 1
#define BLACK 2
#define NIL -1

int M[MAX][MAX];
int d[MAX], color[MAX];
int n;

// ダイクストラのアルゴリズムを用いて、最短経路上の各頂点まで道のりを求めて出力する。
void dijkstra()
{
	for (int i = 0; i < n; i++)
	{
		d[i] = INFTY;
		color[i] = WHITE;
	}

	d[0] = 0;
	color[0] = GRAY;

	while (true)
	{
		int u = NIL;
		int minv = INFTY;
		for (int i = 0; i < n; i++)
		{
			if (color[i] != BLACK && d[i] < minv)
			{
				u = i;
				minv = d[i];
			}
		}

		if (u == NIL) break;

		color[u] = BLACK;

		for (int v = 0; v < n; v++)
		{
			if (color[v] != BLACK && M[u][v] != INFTY)
			{
				if (d[u] + M[u][v] < d[v])
				{
					d[v] = d[u] + M[u][v];
					color[v] = GRAY;
				}
			}
		}
	}

	for (int i = 0; i < n; i++)
	{
		int x = d[i] == INFTY ? -1 : d[i];
		std::cout << i << " " << x << std::endl;
	}

}

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

	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < n; j++)
		{
			M[i][j] = INFTY;
		}
	}

	int u, k, v, c;
	for (int i = 0; i < n; i++)
	{
		std::cin >> u >> k;

		for (int j = 0; j < k; j++)
		{
			std::cin >> v >> c;

			M[u][v] = c;
		}
	}

	dijkstra();
}



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

namespace IO {
    template <typename Tp>
    inline Tp input() {
        Tp x = 0, y = 1;
        char c = getchar();
        while ((c < '0' || '9' < c) && c != EOF) {
            if (c == '-') y = -1;
            c = getchar();
        }
        if (c == EOF) return 0;
        while ('0' <= c && c <= '9') x = x * 10 + c - '0', c = getchar();
        return x *= y;
    }
    template <typename Tp>
    inline bool read(Tp& x) {
        x = input<Tp>();
    }
};  // namespace IO
using namespace IO;

namespace modular {
    const int MOD = 1000000007;
    inline int add(int x, int y) { return (x += y) >= MOD ? x -= MOD : x; }
    inline void inc(int& x, int y) { (x += y) >= MOD ? x -= MOD : 0; }
    inline int mul(int x, int y) { return 1LL * x * y % MOD; }
    inline int qpow(int x, int y) {
        int ans = 1;
        for (; y; y >>= 1, x = mul(x, x))
            if (y & 1) ans = mul(ans, x);
        return ans;
    }
};  // namespace modular

#define reg register
#define MAX_N 3007
#define FIN(s) freopen(s, "r", stdin)
#define FOUT(s) freopen(s, "w", stdout)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define rep(i, l, r) for (int i = l; i <= r; ++i)
#define lep(i, l, r) for (int i = l; i < r; ++i)
#define irep(i, r, l) for (int i = r; i >= l; --i)
#define ilep(i, r, l) for (int i = r; i > l; --i)
typedef long long ll;

int N;
double L, a[MAX_N], PI = acos(-1);

inline void solve() {
    double ax = 0, ay = 0;
    rep(i, 1, N) {
        lep(j, 1, i) {
            int cnt = i - j - 1;
            if (cnt) {
                ax += -cos((a[i] + a[j]) * PI / 2.0) * cnt;
                ay += -sin((a[i] + a[j]) * PI / 2.0) * cnt;
            }
            cnt = N - i + j - 1;
            if (cnt) {
                ax += cos((a[i] + a[j]) * PI / 2.0) * cnt;
                ay += sin((a[i] + a[j]) * PI / 2.0) * cnt;
            }
        }
    }
    double tot = 1.0 * N * (N - 1) * (N - 2) / 6.0;
    printf("%.10lf %.10lf\n", ax / tot, ay / tot);
}

int main() {
#ifdef LOCAL
    FIN("in");
#endif
    read(N), read(L);
    PI = PI * 2.0 / L;
    rep(i, 1, N) read(a[i]);
    solve();
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;

const int N = 1 << 17;
int n;
ll m, v[N], a[N];

ll lcm(ll x, ll y) {
	return x / __gcd(x, y) * y;
}

ll solve() {
	rep(i, 0, n) {
		v[i] = a[i] & (-a[i]);
		a[i] /= 2;
	}
	rep(i, 0, n)
		if (v[0] != v[i])
			return 0;
	ll x = 1;
	rep(i, 0, n) {
		if (x > m) return 0;
		x = lcm(x, a[i]);
	}
	return (m + x) / (2LL * x);
}

signed main() {
	cin.sync_with_stdio(0); cin.tie(0);
	cin.exceptions(cin.failbit);

	cin >> n >> m;
	rep(i, 0, n) cin >> a[i];
	cout << solve();
}

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

int main() {
	int N, K;
	cin >> N >> K;
	vector<int> a(K);
	for (int i = 0; i < N; ++i) ++a[i % K];
	cout << *max_element(a.begin(), a.end()) - *min_element(a.begin(), a.end());
}

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

int main()
{
  i64 n;
  cin >> n;
  i64 ans = 0;
  for (i64 i = 1; i <= n; i++)
    if (to_string(i).size() % 2 == 1)
      ans++;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int limit(int n) {
	int i = 1;
	while (i*i <= n) {
		i += 1;
	}
	return i - 1;
}

int main() {
	int n;
	while (std::cin >> n) {
		int *array = new int[n + 1];

		for (int i = 1; i <= n; i++) {
			array[i] = 0;
		}

		int num_max,count;
		num_max = limit(n);
		count = 0;
		for (int i = 2; i <= num_max; i++) {
			if (array[i] == 0) {
				for (int j = 2 * i; j <= n; j += i) {
					if (array[j] == 0) {
						array[j] = 1;
						count += 1;
					}
				}
			}
		}
		std::cout << n - (count+1) << std::endl;
	}
}


Measured memory_bytes: 60000
#include <stdio.h>
#include <stdlib.h>

int acs(const void* a, const void* b){
	long A = *(long *)a;
	long B = *(long *)b;
	if(A>B) return 1;
	else if(A<B) return -1;
	else return 0;	
}
int main(){
	int N,K;
	long int h[100100],i,ans=0;
	scanf("%d%d",&N,&K);
	for(i=0;i<N;i++)scanf("%ld",h+i);
	qsort(h,N,sizeof(long),acs);
	
	long min = 1000000010;
	for(i=0;i<=N-K;i++){
		if(min>h[i+K-1]-h[i]) min = h[i+K-1]-h[i]; 
	}
	printf("%ld\n",min);

	return 0;	
}

Measured memory_bytes: 1788
#include<bits/stdc++.h>
#define NAME "C"
#define vt vector
#define ll long long
#define fi first
#define se second
#define pb push_back
#define time ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

using namespace std;

void init()
{
    freopen(NAME".inp","r",stdin);
    freopen(NAME".out","w",stdout);
}

const int N=1e5+5;
int n,a[N][5];
ll f[N][5] {0};

void inp()
{
    cin>>n;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=3;j++) cin>>a[i][j];
}

void out()
{
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=3;j++)
        {
            for(int z=1;z<=3;z++)
            {
                if(z==j) continue;
                f[i][j]=max(f[i-1][z],f[i][j]);
            }
            f[i][j]+=a[i][j];
        }
    }
    ll Res=max(f[n][1],f[n][2]);
    Res=max(Res,f[n][3]);
    cout<<Res;
}

int main()
{
  //  init();
    inp();
    out();
}


Measured memory_bytes: 6144
N = int(input())
prime = [True] * 55556
prime[0] = False
prime[1] = False
for i in range(4,55556,2):
    prime[i] = False
for i in range(3,55556,2):
    if prime[i] == True:
        for j in range(i*2,55556,i):
            prime[j] = False
lis = []
for i in range(55556):
    if prime[i] == True and i % 5 == 1:
        lis.append(i)
    if len(lis) == N:
        break

print(' '.join(map(str,lis)))


Measured memory_bytes: 70140
#include <bits/stdc++.h>
 
#define rep(i,n) for(ll i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()

using namespace std;
using ll  = long long;
using pll = pair<ll, ll>;

const ll MOD  = 1e9 + 7;
const ll LINF = 1LL << 62;
const int INF = 1e9 + 7;

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

    if(s.size() == 2){
        if(s[0] == s[1]){
            cout << "1 2\n";
        }
        else {
            cout << "-1 -1\n";
        }
        return 0;
    }

    rep(i, s.size()-2){
        if(s[i] == s[i+1] || s[i] == s[i+2]){
            cout << i+1 << " " << i+3 << endl;
            return 0; 
        }
    }

    cout << "-1 -1\n";
}

Measured memory_bytes: 3756
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <queue>
#include <string>

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;

int main(){
    int n,k;
    cin >> n >> k;
    vector<int> vec(n);
    rep(i,n){
        cin >> vec[i];
    }
    sort(vec.begin(),vec.end());
    int sum = 0;
    rep(i,k){
        sum  += vec[i];
    }
    cout << sum << endl;


    return 0;
}

Measured memory_bytes: 3632
from itertools import count, product
s = input()
n = len(s)
split_indices = ([i*m for i, m in zip(count(1), ms) if m] for ms in product((0,1), repeat=n-1))
split_indices = ([0]+indices+[n] for indices in split_indices)
split_indices = (zip(indices, indices[1:]) for indices in split_indices)
split_indices = (map(lambda ix: int(s[ix[0]:ix[1]]), indices) for indices in split_indices)
print(sum(map(sum, split_indices)))

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

int main(){
  int N, Y; 
  cin >> N >> Y;
  bool goout= false;
  int a = -1;
  int b = -1;
  int c = -1;
  for(int i = 0; i <= N; i++){
    for(int j = 0; j <= N - i; j++){
      if(10000 * i + 5000 * j + 1000 * (N - i - j) == Y) {
        a = i;
        b = j;
        c = N - i - j;
        goout = true;
        break;
      }
    }
    if(goout) break;
  }
  cout << a << " " << b << " " << c << endl;
  return 0;
}

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

int main(){
	int a,b;
	char c;
	cin>>a>>c>>b;
	if(c=='+'){
		cout<<a+b<<endl;
	}else{
		cout<<a-b<<endl;
	}
	return 0;
}

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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;


li h, w;

li a[555][555];

vector<pair<PI, PI>> query;

int main() {
    cin >> h >> w;
    rep(i, h) {
        rep(j, w) {
            cin >> a[i][j];
        }
    }

    bool moving = false;
    rep(i, h) {
        li dx = (i % 2 == 0 ? 1 : -1);
        li now = (dx > 0 ? 0 : w - 1);
        if (moving) {
            query.pb({{i, now + 1}, {i + 1, now + 1}});
        }
        rep(j, w - 1) {
            if (a[i][now] % 2 > 0) {
                moving = !moving;
            }
            if (moving) {
                query.pb({{i + 1, now + 1}, {i + 1, now + 1 + dx}});
            }
            now += dx;
        }
        if (a[i][now] % 2 > 0) {
            moving = !moving;
        }
    }

    cout << sz(query) << endl;
    for (const auto& q : query) {
        cout << q.F.F << " " << q.F.S << " " << q.S.F << " " << q.S.S << endl;
    }

    return 0;
}

Measured memory_bytes: 8688
using System;
using System.Linq;

namespace B___Not_Found
{
    class Program
    {
        static void Main(string[] args)
        {
            var S = Console.ReadLine().Distinct().OrderBy(x => x).ToArray();
            var abc = "abcdefghijklmnopqrstuvwxyz".ToArray();

            Console.WriteLine(S.SequenceEqual(abc) ? "None" : abc.Except(S).First().ToString());
        }
    }
}


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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

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

ll N,M,a[202020];
bool mk[202020];
ll i, j, k,l,r;
ll ans;
bool bs(ll n){
    fornum(i,0,n){
        if(a[N*2-1-i]+a[(N-n)*2+i]<M){
            return false;
        }
    }
    return true;
}

int main(){
    scanf("%lld%lld", &N,&M);
    fornum(i,0,N*2){
        scanf("%lld", &a[i]);
    }
    sort(a, a + (N*2));
    l = 0;
    r = N;
    while(l<r){
        //printf("%lld,%lld\n", l, r);
        ll c = (l + r+1) / 2;
        if(bs(c)){
            l = c;
        }else{
            r = c - 1;
        }
    }
    fornum(i,0,l){
        //printf("%lld,%llda\n", N * 2 - 1 - i, (N - l) * 2 + i);
        ll aaa= (a[N * 2 - 1 - i] + a[(N - l) * 2 + i])%M;
        if(aaa>ans){
            ans = aaa;
        }
    }
    fornum(i,0,N-l){
        //printf("%lld,%lldb\n", (N-l) * 2 - 1 - i, i);
        ll aaa = (a[(N-l)*2-1-i] + a[i]);
        if(aaa>ans){
            ans = aaa;
        }
    }
    printf("%lld", ans);

    return 0;
}

Measured memory_bytes: 1920
fun main(args: Array<String>) {
    abc089d()
}

fun abc089d() {
    val (h, w, d) = readLine()!!.split(' ').map { it.toInt() }
    val grid = (1..h).map { readLine()!!.split(' ').map { it.toInt() - 1 } }
    val q = readLine()!!.toInt()
    val queries = (1..q)
        .map { readLine()!!.split(' ').map { it.toInt() - 1 }.let { Pair(it[0], it[1]) } }

    val gridSize = h * w
    val numberToId = mutableMapOf<Int, Pair<Int, Int>>()
    val minCosts = IntArray(gridSize)

    for (y in 0 until h) {
        for (x in 0 until w) {
            numberToId[grid[y][x]] = y to x
        }
    }

    for (i in 0 until gridSize - d) {
        val fromXy = numberToId[i] ?: error("なんで？")
        val toXy = numberToId[i + d] ?: error("なんで？")
        minCosts[i + d] = minCosts[i] +
                Math.abs(fromXy.first - toXy.first) + Math.abs(fromXy.second - toXy.second)
    }

    val answer = queries.map { minCosts[it.second] - minCosts[it.first] }.joinToString(System.lineSeparator())

    println(answer)
}


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

#define PrintLn(X) cout << X << endl
#define Rep(i, n) for(int i = 0; i < (int)(n); ++i)

int main(void)
{
	Rep(i, 3){
		char s[11];
		cin >> s;
		cout << (char)(s[0] + 'A' - 'a');
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 256
p = [[0] * 10 for _ in range(10)]
x, y, s = 0, 0, 0
while True:
    try:
        x, y, s = map(int, input().split(","))
    except:
        break

    if s >= 1:
        p[x][y] += 1
        for i in range(x-1, x+2, 2):
            if -1 < i < 10:
                p[i][y] += 1
        for i in range(y-1, y+2, 2):
            if -1 < i < 10:
                p[x][i] += 1

    if s >= 2:
        for i in range(x-1, x+2, 2):
            for j in range(y-1, y+2, 2):
                if -1 < i < 10 and -1 < j < 10:
                    p[i][j] += 1

    if s == 3:
        for i in range(x-2, x+3, 4):
            if -1 < i < 10:
                p[i][y] += 1
        for i in range(y-2, y+3, 4):
            if -1 < i < 10:
                p[x][i] += 1

cnt_0 = 0
max_inc = 0

for l in p:
    cnt_0 += l.count(0)
    max_inc = max(l + [max_inc])

print(cnt_0)
print(max_inc)



Measured memory_bytes: 5608
//84104971101048411497 - Can you guess what does this mean?
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef complex<double> point;
#define mapii map<int, int>
#define debug(a) cout << #a << ": " << a << endl
#define debuga1(a, l, r) fto(i, l, r) cout << a[i] << " "; cout << endl
#define fdto(i, r, l) for(int i = (r); i >= (l); --i)
#define fto(i, l, r) for(int i = (l); i <= (r); ++i)
#define forit(it, var) for(__typeof(var.begin()) it = var.begin(); it != var.end(); it++)
#define forrit(rit, var) for(__typeof(var.rbegin()) rit = var.rbegin(); rit != var.rend(); rit++)
#define ii pair<int, int>
#define iii pair<int, ii>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define maxN 1005
#define oo 1000000000000000007LL
#define sz(a) (int)a.size()

const double PI = acos(-1.0);

double fRand(double fMin, double fMax)
{
    double f = (double)rand() / RAND_MAX;
    return fMin + f * (fMax - fMin);
}

template <class T>
T min(T a, T b, T c) {
    return min(a, min(b, c));
}

template <class T>
T max(T a, T b, T c) {
    return max(a, max(b, c));
}

int main () {
    int n, res = 0;
    scanf("%d", &n);
    fto(i, 1, n) {
        int a, x;
        scanf("%d%d", &a, &x);
        while (a%x != 0) {
            int d = a/x+1, r = a%x;
            a = a-(r+d-1)/d * d;
        }
        res ^= a/x;
    }

    puts((res) ? "Takahashi" : "Aoki");

    return 0;
}


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

int main() {
    int N, M;
    cin >> N >> M;
    vi H(N);
    rep(i, N) {
        cin >> H[i];
    }
    vector<pair<int, int> > ab(M);
    vector<bool> check(N, true);
    rep(i, M) {
        cin >> ab[i].first >> ab[i].second;
        if(H[ab[i].first-1] < H[ab[i].second-1]){
            check[ab[i].first-1] = false;
        } else if(H[ab[i].first-1] > H[ab[i].second-1]) {
            check[ab[i].second-1] = false;
        } else {
            check[ab[i].second-1] = false;
            check[ab[i].first-1] = false;
        }
    }
    int CCC=0;
    rep(i, N) {
        if(check[i]){
            ++CCC;
        }
    }
    cout << CCC << endl;
}

Measured memory_bytes: 4588
n = int(input())

abl = [map(int, input().split()) for _ in range(n)]

from collections import defaultdict
dic = defaultdict(int)

# a,bの最大公約数
def gcd(a, b):
   while b:
       a, b = b, a % b
   return a

ab0 = 0
a0 = 0
b0 = 0
for a,b in abl:
    if a == 0 and b == 0:
        ab0 += 1
        continue
    elif a == 0:
        a0 += 1
        continue
    elif b == 0:
        b0 += 1
        continue
    gc = abs(gcd(a,b))
    if a < 0:
        a, b = -a // gc, -b // gc
    else:
        a, b = a // gc, b // gc
    dic[(a,b)] += 1
MOD = 1000000007
ans = 1
used = defaultdict(int)
for (a,b) in dic:
    if b > 0:
        target = (b, -a)
    else:
        target = (-b, a)
    if target in dic:
        if used[target] == 0:
            ans *= pow(2, dic[(a,b)], MOD) + pow(2, dic[target], MOD) - 1
            used[(a,b)] = 1
    else:
        ans *= pow(2, dic[(a,b)], MOD)
    ans %= 1000000007

ans *= pow(2, a0, MOD) + pow(2, b0, MOD) - 1
ans %= 1000000007

print((ans - 1 + ab0) % MOD)









Measured memory_bytes: 176144
import sys
input = sys.stdin.readline
def solve():
  n,wmax = (int(i) for i in input().split())
  query = []
  v = 101000
  for i in range(n):
    tw,tv = (int(i) for i in input().split())
    query.append((tw,tv))
  dp = [[-1]*(v+1) for _ in range(n+1)]
  for i in range(n):
    dp[i][0] = 0

  for i in range(n):
    nw,nv = query[i]
    for value in range(v-nv):
      if dp[i][value] == -1:
        a = 1
      if dp[i][value] > -1 and dp[i][value]+nw <=wmax:
         if dp[i+1][value+nv] == -1:
           dp[i+1][value+nv] = dp[i][value]+nw
         else:
           dp[i+1][value+nv] = min(dp[i][value]+nw,dp[i+1][value+nv])
      if dp[i][value] > -1:
        if dp[i+1][value] == -1:
          dp[i+1][value] = dp[i][value]
        else:
          dp[i+1][value] = min(dp[i+1][value],dp[i][value])

  ans = 0
  for value in range(v):
    if dp[n][value] <= wmax and dp[n][value]!= -1:
      ans = max(ans,value)
  print(ans)
solve()

Measured memory_bytes: 120688
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


h,w,k = map(int, input().split())
c = [None]*h
for i in range(h):
    c[i] = input()
ans = 0
for b1 in range(1<<h):
    for b2 in range(1<<w):
        val = 0
        for i in range(h):
            if b1>>i&1:
                continue
            for j in range(w):
                if b2>>j&1:
                    continue
                if c[i][j]=="#":
                    val += 1
        if val==k:
            ans += 1
print(ans)

Measured memory_bytes: 68188
#define _CRT_SECURE_NO_WARNINGS
#define REL

#pragma GCC target ("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <iomanip>
#include <cstdio>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <string>
#include <set>
#include <bitset>
#include <cstdint>
#include <cstring>
#include <cassert>
#include <complex>
#include <stack> 
#include <random>

using namespace std;

typedef int64_t i64;
typedef long long LL;
typedef long long ll;
typedef long double LD;
typedef complex <LD> cld;
typedef unsigned int uint;
typedef complex <double> cd;
typedef unsigned long long ULL;

#define endl "\n"
#define dendl "\n\n"
#define mp make_pair
#define mt make_tuple
#define size(v) (int)v.size()
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

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

template <typename T>
T sqr(T a) {
	return a * a;
}

template <typename T>
int sign(T a) {
	if (a == 0)
		return 0;
	return (a > 0 ? 1 : -1);
}

template <typename T>
bool uax(T& a, const T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

template <typename T>
bool uin(T& a, const T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}

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

template <typename T1, typename T2>
ostream& operator << (ostream& out, pair<T1, T2>& p) {
	out << p.first << ' ' << p.second;
	return out;
}

mt19937_64 rnd(0);

const int LOG = 64;
const int N = (int)2e5 + 7;
const int MAXN = (int)1e6 + 7;
const int MOD = (int)1e9 + 7;
const int INF = (int)2e9 + 7;
const int CONST = 450;
const LL LINF = (i64)1e18;
const LD PI = 3.1415926535897932384626433832795;
const LD EPS = 1;

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

void solve() {
	int n; cin >> n;
	for (int i = 1; i <= n; i++) {
		int res = 0;
		for (int x = 1; x <= 100; x++) {
			for (int y = 1; y <= 100; y++) {
				if (x * x + y * y + x * y > n)
					break;
				for (int z = 1; z <= 100; z++) {
					if (x * x + y * y + z * z + x * y + y * z + z * x == i)
						res++;
					if (x * x + y * y + z * z + x * y + y * z + z * x > i)
						break;
				}
			}
		}
		cout << res << endl;
	}
}

int main() {
	double start = clock();
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	cout << fixed << setprecision(20);
	cerr << fixed << setprecision(20);
#else
	cout << fixed << setprecision(20);
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	rnd.seed(time(0));
#endif

	int t = 1;
	for (int i = 0; i < t; i++) {
		solve();
	}

#ifdef _DEBUG
	cout << endl << "Time is " << (clock() - start) / 1000.0;
#endif
}

Measured memory_bytes: 3484
n, m = map(int, input().split())
s = []
for _ in range(m):
    _, *ss = map(int, input().split())
    s.append(ss)
p = list(map(int, input().split()))
ans = 0
for i in range(2**n):
    for j in range(m):
        tmp = 0
        for k in s[j]:
            tmp += i>>(k-1)&1
        if tmp%2!=p[j]:
            break
    else:
        ans += 1
print(ans)

Measured memory_bytes: 3064
import Data.List

main = interact $ show . sol . read

sol = sum . map (f . length) . group . primeFactors

f n = truncate $ sqrt (2*fromIntegral n+0.25) - 0.5

primes :: Integral a => [a]
primes = 2 : filter ((==1) . length . primeFactors) [3,5..]

primeFactors :: Integral a => a -> [a]
primeFactors 1 = []
primeFactors n = factor n primes

factor :: Integral a => a -> [a] -> [a]
factor n (p:ps) 
  | p*p > n      = [n]
  | n `mod` p==0 = p:factor (n `div` p) (p:ps)
  | otherwise    = factor n ps

Measured memory_bytes: 11828
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

const int dm = 1 << 20;
char dn[dm], * di = dn;
inline void putint(int X) {
	if (X == 0) {
		*di++ = '0';
		*di++ = '\n';
		return;
	}
	int keta = 0;
	char C[10];
	while (X) {
		*(C + keta) = '0' + X % 10;
		X /= 10;
		keta++;
	}
	for (int i = keta - 1; i >= 0; i--)* di++ = (*(C + i));
	*di++ = '\n';
}


int E[200001], ne[200001];
int H[100001];
int kotae[100001];
char Vis[100001];
void sagasu(int P, char D, int C) {
	if (D == 0 && kotae[P] == 0) kotae[P] = C;
	else if (Vis[P] < D) {
		Vis[P] = D;
		if (kotae[P] == 0) kotae[P] = C;
		for (int p = H[P]; p; p = ne[p]) {
			sagasu(E[p], D - 1, C);
		}
	}
}

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


	int N, M, Q;
	N = getint();
	M = getint();
	for (int i = 1; i < 2 * M;) {
		int a = getint(), b = getint();
		E[i] = a;
		ne[i] = H[b];
		H[b] = i++;
		E[i] = b;
		ne[i] = H[a];
		H[a] = i++;
	}
	Q = getint();
	int v[100000], d[100000], c[100000];
	rep(i, Q) {
		v[i] = getint();
		d[i] = getint();
		c[i] = getint();
	}
	for (int i = Q - 1; i >= 0; i--) {
		sagasu(v[i], d[i], c[i]);
	}
	rep1(i, N) {
		putint(kotae[i]);
	}

	fwrite_unlocked(dn, di - dn, 1, stdout);

	Would you please return 0;
}

Measured memory_bytes: 4736
#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<int, int>;

const ll INF = 2020202020;

int main() {
  int n;
  cin >> n;
  vector<ll> a(n), b(n + 1);
  b[0] = 0;
  rep(i, n) {
    cin >> a[i];
    b[i + 1] = b[i] + a[i];
  }
  // rep(i, n + 1) cerr << b[i] << ' ';
  // cerr << endl;

  ll min_cost = INF;
  for (int i = 1; i < n; i++) {
    // cerr << b[i] << ' ' << b[n] - b[i] << endl;
    ll cost = abs(b[i] - (b[n] - b[i]));
    min_cost = min(min_cost, cost);
  }
  cout << min_cost << endl;

  return 0;
}


Measured memory_bytes: 3328
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;
using llong = long long;
const int MOD=1000000007;

int main(int argc, char**argv){
    int n;
    double t, a;
    cin >> n;
    cin >> t >> a;
    vector<double> h(n);
    for (int i = 0; i < n; i++) cin >> h[i];

    for (int i = 0; i < n; i++){
        // h[i] = abs(t - h[i]*0.006 - a);
        h[i] = fabs(t - h[i]*0.006 - a);
    }
    // vector<int>::iterator result = min_element(h.begin(), h.end());
    // vector<double>::iterator result = min_element(h.begin(), h.end());
    // int *result = min_element(h.begin(), h.end());
    // cout << distance(h.begin(), result);

    int ans_idx = min_element(h.begin(), h.end()) - h.begin();
    cout << ans_idx+1 << endl;

    return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#define P(type,x) fprintf(stdout,"%"#type"\n",x)
#define S(type,x) fscanf(stdin,"%"#type,&x)
int main() {
	int n, q,d;
	char name[100]="kogakubu10gokan",s[100];
	S(d, n), S(d, q);
	while (n--) {
		scanf("%d %s", &d, s);
		if (d <= q) strcpy(name, s);
	}
	P(s,name);
	return 0;
}

Measured memory_bytes: 608