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

#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define eb emplace_back
#define ins insert
#define ph push
#define f first
#define s second
#define cbr cerr << "hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ll(x.size())
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
inline long long rand(long long x, long long y) { return (rng() % (y+1-x)) + x; } //inclusivesss
string inline to_string(char c) {string s(1,c);return s;} template<typename T> inline T gcd(T a,T b){ return a==0?llabs(b):gcd(b%a,a); }

typedef long long ll; 
typedef long double ld;
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
typedef pair<ll,ll>pi; typedef pair<ll,pi>spi; typedef pair<pi,pi>dpi;

#define LLINF ((long long) 1e18)//1234567890987654321
#define INF 1234567890ll
// #define cerr if(0)cout
#define MAXN (500006)
ll n, d, A[MAXN], q, pos[MAXN], B[MAXN];
int main()
{
	FAST
	cin>>n>>d;
	FOR(i,1,n)cin>>A[i];
	pos[0]=d;
	FOR(i,1,n)pos[i]=pos[i-1]-A[i], pos[i]=llabs(pos[i]), pos[i]=min(pos[i], pos[i-1]); 
	B[n+1]=1;
	DEC(i,n,1) if(2*B[i+1] <= A[i]) B[i]=B[i+1]; else B[i]=B[i+1]+A[i];
	cin>>q;
	FOR(ii,1,q) {
		ll q; cin>>q;
		if(pos[q-1] > 0 && B[q+1] <= pos[q-1]) {
			cout<<"YES\n";
		} else cout<<"NO\n";
	}
}


Measured memory_bytes: 13696
#include <bits/stdc++.h>
 
using namespace std;
 
#define MAX_N 10
#define INF 1e9
typedef pair<int,int> pii;
typedef pair<string,int> psi;
 
struct Edge{
    int to,dist;
    Edge(int t,int d) : to(t),dist(d) {}
};
 
struct State{
    int cost,dist,v,S;
    State(int c,int d,int v,int S) 
	: cost(c),dist(d),v(v),S(S) {}
    bool operator < (const State &s)const{
	if(cost != s.cost){
	    return cost > s.cost;
	}else{
	    return dist > s.dist;
	}
    }
};
 
int V,E,K[MAX_N],q;
string shopping_list[15];
vector<psi> items[MAX_N];
vector<Edge> G[MAX_N+1];
 
void solve(){
    priority_queue<State> Q;
    Q.push(State(0,0,0,0));
    pii d[MAX_N+1][1<<15];
    for(int i = 0 ; i <= V ; i++){
	for(int j = 0 ; j < (1<<q) ; j++){
	    d[i][j] = pii(INF,INF);
	}
    }
    d[0][0] = pii(0,0);
   
    while(!Q.empty()){
	State s = Q.top(); Q.pop();
	int v = s.v,S = s.S;
	if(d[v][S] < pii(s.cost,s.dist)) continue;
	if(v == 0 && S == (1<<q)-1){
	    cout << s.cost << " " << s.dist << endl;
	    return;
	}   
	for(int i = 0 ; i < (int)G[v].size() ; i++){
	    Edge e = G[v][i];
	    pii next = pii(d[v][S].first,d[v][S].second+e.dist);
	    if(next < d[e.to][S]){
		d[e.to][S] = next;
		Q.push(State(d[e.to][S].first,d[e.to][S].second,e.to,S));
	    }
	    if(v == 0) continue;
	    for(int j = 0 ; j < q ; j++){
		if((S >> j) & 1) continue;
		for(int k = 0 ; k < K[v-1] ; k++){
		    if(shopping_list[j] == items[v-1][k].first){
			pii next = pii(s.cost + items[v-1][k].second,
				       s.dist + e.dist);
			int nS = S|(1<<j);
			if(next < d[e.to][nS]){
			    d[e.to][nS] = next;
			    Q.push(State(d[e.to][nS].first,d[e.to][nS].second,e.to,nS));
			}
			next.second -= e.dist;
			if(next < d[v][nS]){
			    d[v][nS] = next;
			    Q.push(State(d[v][nS].first,d[v][nS].second,v,nS));
			}
		    }
		}
	    }
	}
    }
    cout << "impossible" << endl;
}
 
int main(){
    while(cin >> V, V){
	string name;
	int value,a,b,d;
	for(int i = 0 ; i <= V ; i++){
	    G[i].clear();
	}
	for(int i = 0 ; i < V ; i++){
	    cin >> K[i];
	    items[i].clear();
	    for(int j = 0 ; j < K[i] ; j++){
		cin >> name >> value;
		items[i].push_back(psi(name,value));
	    }
	}
	cin >> q;
	for(int i = 0 ; i < q ; i++){
	    cin >> shopping_list[i];
	}
	cin >> E;
	for(int i = 0 ; i < E ; i++){
	    cin >> a >> b >> d;
	    G[a].push_back(Edge(b,d));
	    G[b].push_back(Edge(a,d));
	}
	solve();
    }
    return 0;
}

Measured memory_bytes: 7736
#include <iostream>
#include <vector>
#include<list>
#include <algorithm>
#include <string>
#include <math.h>
#include<map>
#include <utility>
#include <cstring>
#include <iomanip>
#include<queue>
#include<set>
#include<stack>
#include<fstream>
using namespace std;
#define REP(i,k,n) for(int i=k;i<n;i++)
 
#define INF 1844674407370955161
typedef long long int ll;
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
#define MOD 1000000007


int main()
{
	int H1,H2,M1,M2,K;
	cin>>H1>>M1>>H2>>M2>>K;

	int up=60*H1+M1;
	int down=60*H2+M2;

	int ans=down-K-up;
	ans=max(0,ans);
	cout<<ans<<endl;
	
	return 0;
	
}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
#define pb push_back
#define pf push_front
#define in insert
#define ff first
#define ss second
#define mp make_pair
#define int long long
#define uint unsigned long long
#define rep(i,x,m) for(int i=x;i<m;i++)
#define repr(i,x,m) for(int i=x;i>=m;i--)
#define MOD 1000000007
#define endl "\n"
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define vi vector<int>
#define vs vector<string>
#define print(v) for(int i=0;i<v.size();i++) cout<<v[i]<<" ";cout<<endl
using namespace std;
#define noob ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int fac[2000005]={0};
void factorial(){ fac[0]=1; fac[1]=1; for(int i=2;i<200005;i++) fac[i]=((i%MOD)*(fac[i-1]%MOD))%MOD;}
int power(int n,int m)
{int p=1;if(m==0)return 1;p=(power(n,m/2)%MOD);p=(p%MOD*p%MOD)%MOD;
return(m&1?((p%MOD*n%MOD)%MOD):(p%MOD));}
int ncr(int n,int r){return ((fac[n]*power(fac[r],MOD-2))%MOD*power(fac[n-r],MOD-2))%MOD;}

void ram5564()
{
    double pi=3.14159;
    int n;
    cin>>n;
    double c=2*pi*n*1.00;
    cout<<fixed<<setprecision(10)<<c;
}

signed main()
{
        noob
        // #ifndef ONLINE_JUDGE
        //  freopen("input.txt","r",stdin);
        //  freopen("output.txt","w",stdout);
        //  #endif   
        
        int t=1;
        //cin>>t;
        while(t--)
        ram5564();
        return 0;
}

Measured memory_bytes: 3808
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPLL(i, n) for (ll i = 0; i < (ll)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N; cin >> N;
  int ans = -1e9-7;
  int m = 1e9;
  REP(i, N){
    int a; cin >> a;
    if(i == 0){
      m = a;
      continue;
    }else if(i == 1){
      ans = a - m;
      m = min(m, a);
      continue;
    }
    ans = max(ans, a-m);
    m = min(m, a);
  }
  cout << ans << endl;
}


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

int dp[1001][1001];

int main() {
    string s, t;
    cin >> s >> t;
    for (int i = 0; i < 1001; i++) {
        for (int j = 0; j < 1001; j++) {
            if (i == 0) {
                dp[i][j] = j;
            } else if (j == 0) {
                dp[i][j] = i;
            } else {
                dp[i][j] = 1e9;
            }
        }
    }
    
    for (int i = 1; i <= s.size(); i++) {
        for (int j = 1; j <= t.size(); j++) {
            if (s[i - 1] == t[j - 1]) {
                dp[i][j] = dp[i - 1][j - 1];
            } else {
                dp[i][j] = min({dp[i - 1][j], dp[i][j - 1], dp[i - 1][j - 1]}) + 1;
            }
        }
    }
    
    cout << dp[s.size()][t.size()] << endl;
}


Measured memory_bytes: 7112
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const int MOD = (int)1e9 + 7;
const double PI = 3.14159265358979323846;
template <class T, class U>
void chmin(T& t, const U& u) {
  if (t > u) t = u;
}
template <class T, class U>
void chmax(T& t, const U& u) {
  if (t < u) t = u;
}

const ll INF = 1e20;
const int MX = 3009;
ll v[MX][MX];
ll dp[MX][MX][4];
int main(void) {
  int r, c, K;
  cin >> r >> c >> K;
  rep(i, r) rep(j, c) v[i][j] = 0;
  rep(i, K) {
    ll ri, ci, val;
    cin >> ri >> ci >> val;
    ri--, ci--;
    v[ri][ci] = val;
  }
  rep(i, MX) rep(j, MX) rep(k, 4) dp[i][j][k] = -INF;
  dp[0][0][0] = 0;
  rep(i, r) {
    rep(j, c) {
      for (int k = 2; k >= 0; --k) {
        if (dp[i][j][k] >= 0) chmax(dp[i][j][k + 1], dp[i][j][k] + v[i][j]);
      }
      rep(k, 4) {
        if (dp[i][j][k] >= 0) {
          if (i + 1 < r) chmax(dp[i + 1][j][0], dp[i][j][k]);
          if (j + 1 < c) chmax(dp[i][j + 1][k], dp[i][j][k]);
        }
      }
    }
  }
  ll ans = -INF;
  rep(k, 4) chmax(ans, dp[r - 1][c - 1][k]);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 357012
fun main(args: Array<String>) {
    val s = readString()
    if (
        s.isPalindrome() &&
        s.substring(0 until (s.length - 1) / 2).isPalindrome() &&
        s.substring((s.length + 3) / 2 - 1 until s.length).isPalindrome()
    ) {
        println("Yes")
    } else {
        println("No")
    }
}

fun String.isPalindrome(): Boolean {
    return if (this.length % 2 == 0) {
        val x = this.substring(0 until this.length / 2)
        val y = this.substring(this.length / 2 until this.length).reversed()
        x == y
    } else {
        val x = this.substring(0 until (this.length - 1) / 2)
        val y = this.substring((this.length + 3) / 2 - 1 until this.length).reversed()
        x == y
    }
}

// Tools
fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)

Measured memory_bytes: 33784
from collections import defaultdict, deque
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate
import sys


def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LIM(): return list(map(lambda x:int(x) - 1, sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def LIRM(n): return [LIM() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
mod = 1000000007


def main():
    s = S().strip()
    dp = [0] * 13
    dp[0] = 1
    trans_list = [i * 10 % 13 for i in range(13)]
    for i in s:
        nxt_dp = [0] * 13
        for j in range(13):
            if i == '?':
                for k in range(10):
                    nxt_dp[(trans_list[j] + k) % 13] += dp[j]
                    nxt_dp[(trans_list[j] + k) % 13] %= mod
            else:
                nxt_dp[(trans_list[j] + int(i)) % 13] += dp[j]
                nxt_dp[(trans_list[j] + int(i)) % 13] %= mod
        dp = nxt_dp

    return dp[5]


print(main())

Measured memory_bytes: 43500
/* 
 * Project: AtCoder Beginners Contest 175 B - Making Triangle
 * Author: toms74209200 <https://github.com/toms74209200>
 *
 * Created on 2020/08/29
 * Copyright (c) 2020 toms74209200
 * 
 * This software is released under the MIT License.
 * http://opensource.org/licenses/mit-license.php
 */
#include <cstdio>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

uint32_t n;
vector<uint32_t> l;

void solve() {

    sort(l.begin(), l.end());
    uint32_t cnt = 0;
    for (int i=0;i<n;i++) {
        for (int j=0;j<i;j++) {
            for (int k=0;k<j;k++) {
                if (l[i] != l[j] && l[j] != l[k]) {
                    if (l[k]+l[j] > l[i])
                        cnt++;
                }
            }
        }
    }
    printf("%d\n",cnt);
}

int main() {

    scanf("%d", &n);
    l.resize(n);
    for (int i=0;i<n;i++) {
        scanf("%d", &l[i]);
    }

    solve();

}

Measured memory_bytes: 3256
using System;
using System.Text;

namespace ALDS1_9_C {
    class Problem {
        const int MAX = 2000000;
        private int _H;
        private int[] _A;

        public Problem(int max = MAX) {
            _A = new int[max + 1];
        }

        public void Insert(int key) {
            int i = ++_H;
            _A[i] = key;
            while (i > 1) {
                int j = i / 2;
                if (_A[j] >= _A[i])
                    break;
                Swap(i, j);
                i = j;
            }
        }

        public int Extract() {
            int ret = _A[1];
            _A[1] = _A[_H--];
            MaxHeapify(1);
            return ret;
        }
        
        private void MaxHeapify(int i) {
            int l = 2 * i;
            int r = 2 * i + 1;
            int largest = (l <= _H && _A[l] > _A[i]) ? l : i;
            if (r <= _H && _A[r] > _A[largest])
                largest = r;

            if (largest != i) {
                Swap(i, largest);
                MaxHeapify(largest);
            }
        }

        private void Swap(int a, int b) {
            int temp = _A[a];
            _A[a] = _A[b];
            _A[b] = temp;
        }
    }

    class Program {
        static void Main(string[] args) {
            Problem p = new Problem();
            StringBuilder sb = new StringBuilder();
            bool inputEnd = false;
            while (!inputEnd) {
                string[] input = Console.ReadLine().Split(' ');
                switch (input[0]) {
                    case "insert":
                        p.Insert(int.Parse(input[1]));
                        break;
                    case "extract":
                        sb.AppendLine(p.Extract().ToString());
                        break;
                    case "end":
                        inputEnd = true;
                        break;
                }
            }
            Console.Write(sb);
        }
    }
}

Measured memory_bytes: 46884
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

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()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, D = MAP()

if N % (2*D+1) == 0:
	print(N//(2*D+1))
else:
	print(N//(2*D+1)+1)


Measured memory_bytes: 5784
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
typedef vector<int> vi;
#define sz(c) int((c).size())

vector<bool> primes(50100, true);
void build () {
  primes[0] = false;
  primes[1] = false;
  for (int i = 2; 2*i < sz(primes); i++) {
    primes[2*i] = false;
  }
  for (int i = 3; i*i <= sz(primes); i+=2) {
    if (primes[i]) {
      for (int j = 2; i*j < sz(primes); j++) {
        primes[i*j] = false;
      }
    }
  }
}

int gbc(int n)
{
  int res = 0;
  if (primes[n-2])
    res++;
  for (int i = 3; 2*i <= n; i+=2) {
    if (primes[i] && primes[n-i])
      res++;
  }
  return res;
}

int main(int argc, char **argv)
{
  int n;
  build();
  while (cin >> n) {
    if (!n)
      break;
    cout << gbc(n) << endl;
  }
  return 0;
}

Measured memory_bytes: 1200
from math import gcd
from functools import reduce
# import itertools
from collections import defaultdict

a=int(input())

sum=0


for x in range(1,a+1):
    for y in range(1,a+1):
        for z in range(1,a+1):
            sum+=gcd(gcd(x,y),z)


print(sum)


Measured memory_bytes: 9568
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

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

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 300010

int counter[SIZE];
int num[SIZE];
int A[SIZE];

int main(){
  int N;

  scanf("%d", &N);

  for (int i=0; i<N; i++) {
    scanf("%d", A+i);
  }

  vector<int> ans;

  for (int i=0; i<=N; i++) {
    counter[i] = 0;
    num[i] = 0;
  }

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

  int sum = N;
  for (int i=0; i<N; i++) {
    num[counter[i]]++;
  }

  int cc = 0;
  int t = N; //各
  for (int i=1; i<=N; i++) {
    while (t > sum / i) {
      cc += num[t];
      sum -= cc;
      t--;
    }

    printf("%d\n", sum / i);
  }

  return 0;
}


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

#define ll long long
#define INF pow(10,9)*5
typedef pair<pair<ll,ll>,ll> P;

ll pyramid[101][101];

int main(void){
    ll N;
    cin >> N;

    for(ll i=0;i<101;i++){
        for(ll j=0;j<101;j++){
            pyramid[i][j]=0;
        }
    }
    vector<P>v(N);
    for(int i=0;i<N;i++){
        cin >>v[i].first.second >> v[i].second >>  v[i].first.first;
    }
    sort(v.rbegin(),v.rend());

    ll ans_h, ans_x, ans_y;  
    bool flag;
    for(int i=0;i<101;i++){
        for(int j=0;j<101;j++){
            flag = true;
            for(int k=0;k<N;k++){
                ll h = v[k].first.first, x = v[k].first.second, y = v[k].second;
                ll tmp = h + abs(x-i) + abs(y-j);
                if(k==0){
                    ans_h = tmp;
                    ans_x = i;
                    ans_y = j;
                }else if(h == 0){
                    if(tmp < ans_h){
                        flag = false;
                        break;
                    }
                }else{
                    if(tmp != ans_h){
                        flag = false;
                        break;
                    }
                }
            }
            if (flag == true){
                cout << ans_x<< ' '<<ans_y << ' ' <<ans_h << endl;
                return 0;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1000000000000000009
//#define INF 9223372036854775807
typedef long long ll;
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define rollcall cout<<"I'm Sucu."<<endl;
#define YES(s) s?cout << "YES" << endl:cout << "NO" << endl
#define Yes(s) s?cout << "Yes" << endl:cout << "No" << endl
#define Taka(s) s?cout << "Takahashi" << endl:cout << "Aoki" << endl
#define out(s,t,u) s?cout << t << endl:cout << u << endl
#define int ll
#define Endl endl
//#define P pair<int,int>

signed main(){
    int N;
    string S,T;
    char r[2]={'S','W'};
    cin >> N;
    cin >> S;
    
    REP(j,4){
        T.clear();
        int p=j/2,q=j%2;
        //pは1番目,qは2番目
        T+=r[p];
        T+=r[q];
        REP(i,N-1){
            if(i==0)continue;
            if((S[i]=='x'&&T[i]=='S')||(S[i]=='o'&&T[i]=='W')){
                if(T[i-1]=='S'){
                    T+="W";
                }else{
                    T+="S";
                }
            }else{
               T+=T[i-1];
            }
        }
        //cout << T << endl;
        bool mujun=false;
        REP(i,N){
            if(T[i]=='S'){
                if((S[i]=='o'&&T[(i-1+N)%N]!=T[(i+1)%N])||(S[i]=='x'&&T[(i-1+N)%N]==T[(i+1)%N])){
                    mujun=true;
                }
            }else{
                if((S[i]=='o'&&T[(i-1+N)%N]==T[(i+1)%N])||(S[i]=='x'&&T[(i-1+N)%N]!=T[(i+1)%N])){
                    mujun=true;
                }
            }
        }
        if(mujun==false){
            cout << T << endl;
            return 0;
        }
    }
    cout << -1 << endl;
	return 0;
}

Measured memory_bytes: 640
// Template
#include <bits/stdc++.h>
#define rep_override(x, y, z, name, ...) name
#define rep2(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep3(i, l, r) for (int i = (int)(l); i < (int)(r); ++i)
#define rep(...) rep_override(__VA_ARGS__, rep3, rep2)(__VA_ARGS__)
#define per(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
constexpr int inf = 1001001001;
constexpr ll INF = 3003003003003003003LL;
template <typename T> inline bool chmin(T& x, const T& y) {if (x > y) {x = y; return 1;} return 0;}
template <typename T> inline bool chmax(T& x, const T& y) {if (x < y) {x = y; return 1;} return 0;}
struct IOSET {IOSET() {cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10);}} ioset;

// Union-Find
class UnionFind {
    vector<int> par;
public:
    UnionFind(int n) : par(n, -1) {}
    int root(int x) {
        if (par[x] < 0) return x;
        return par[x] = root(par[x]);
    }
    bool unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return false;
        if (par[rx] > par[ry]) swap(rx, ry);
        par[rx] += par[ry];
        par[ry] = rx;
        return true;
    }
    bool same(int x, int y) {
        return root(x) == root(y);
    }
    int size(int x) {
        return -par[root(x)];
    }
};

// Main
constexpr int MAX = 100000;

int main() {
    int n;
    cin >> n;
    vector<int> x(n), y(n);
    rep(i, n) {
        cin >> x[i] >> y[i];
        --x[i]; --y[i];
    }
    
    UnionFind uf(2 * MAX + n);
    rep(i, n) {
        uf.unite(x[i], 2 * MAX + i);
        uf.unite(MAX + y[i], 2 * MAX + i);
    }
    
    vector<int> xs(2 * MAX + n, 0), ys(2 * MAX + n, 0);
    rep(i, MAX) ++xs[uf.root(i)];
    rep(i, MAX) ++ys[uf.root(i + MAX)];
    
    ll ans = 0;
    rep(i, 2 * MAX + n) {
        if (uf.root(i) == i) ans += 1LL * xs[i] * ys[i] + xs[i] + ys[i] - uf.size(i);
    }
    cout << ans << "\n";
}


Measured memory_bytes: 7400
#!/usr/bin/env python3
#ABC79 C

a,b,c,d = list(map(int,list(input())))

for i in range(2**3):
    bit = [0]*3
    for j in range(3):
        if (i >> j) & 1:
            bit[j] = 1
    s = a
    ans = [a,None,b,None,c,None,d,'=',7]
    k = 0
    for j in range(3):
        if bit[j] == 1:
            if j == 0:
                s += b
            elif j == 1:
                s += c
            elif j == 2:
                s += d
            ans[2*k+1] = '+'
        else:
            if j == 0:
                s -= b
            elif j == 1:
                s -= c
            elif j == 2:
                s -= d
            ans[2*k+1] = '-'
        k += 1
    if s == 7:
        print(''.join(map(str,ans)))
        break


Measured memory_bytes: 38256
#include<iostream>
#include<list>
#include<string>
using namespace std;int main(){int i;string s;list<char> l;list<char>::iterator x;getline(cin,s);while(getline(cin,s)){l.clear();l.push_back(s[i=0]);x=l.begin();while(++i<s.size()){if(s[i++]=='<'&&*--x!=s[++i]){l.insert(++x,s[i]);x--;}if(s[i]=='>'&&*++x!=s[++i]){l.insert(x,s[i]);x--;}}for(x=l.begin();x!=l.end();)cout<<*x++;cout<<endl;}return 0;}

Measured memory_bytes: 0
using System;
using System.Collections.Generic;
using System.Linq;

namespace CsAtCoderSubmitExam
{
    class BeginnerContest157
    {
        static void Main(string[] args)
        {
            int N = -1;
            var AsList = new List<List<int>>();
            while (true)
            {
                var As = Console.ReadLine().Split(' ').Select(l => int.Parse(l));
                if (As.Count() == 1)
                {
                    N = As.First();
                    break;
                }

                AsList.Add(As.ToList());
            }

            var Bs = new List<int>();
            for (var i = 0; i < N; i++)
            {
                Bs.Add(int.Parse(Console.ReadLine()));
            }

            foreach (var b in Bs)
            {
                foreach (var As in AsList)
                {
                    for (var i = 0; i < As.Count(); i++)
                    {
                        if (As[i] == b)
                        {
                            As[i] = 0;
                        }
                    }
                }
            }

            if ((AsList[0][0] + AsList[1][0] + AsList[2][0] == 0) ||
                (AsList[0][0] + AsList[1][1] + AsList[2][2] == 0) ||
                (AsList[0][0] + AsList[0][1] + AsList[0][2] == 0) ||
                (AsList[1][0] + AsList[1][1] + AsList[1][2] == 0) ||
                (AsList[2][0] + AsList[1][1] + AsList[0][2] == 0) ||
                (AsList[0][1] + AsList[1][1] + AsList[2][1] == 0) ||
                (AsList[2][0] + AsList[2][1] + AsList[2][2] == 0) ||
                (AsList[0][2] + AsList[1][2] + AsList[2][2] == 0))
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}

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

int main(){
    int n;
    int y;
    bool flag = false;
    cin >> n >> y;

    for(int i=0;i<=n;i++){
        for(int j=0; j<=n-i;j++){
            for(int k=0;k<=n-i-j;k++){
                if(10000*i+5000*j+1000*k == y && i+j+k==n){
                    printf("%d %d %d\n", i, j ,k);
                    flag = true;
                    break;
                }
            }
            if(flag) break;
        }
        if(flag) break;
    }
    if(!flag)
        printf("-1 -1 -1\n");
}

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

int main()
{
  int N, K;
  cin >> N >> K;
  int res = 0;
  int right = 0;
  while (true)
  {
    if (res == 0)
      right += K;
    else
      right += K - 1;
    res++;

    if (right >= N)
      break;
  }
  cout << res << endl;
}




Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

    int ans = N;
    for (int s = 0; s <= N; ++s) {
        // s円を6^nで払う
        // N - s円を9^nで払う
        int cnt = 0;

        int ns = s;
        while (ns > 0) {
            cnt += ns % 6;
            ns /= 6;
        }

        ns = N - s;
        while (ns > 0) {
            cnt += ns % 9;
            ns /= 9;
        }

        ans = min(ans, cnt);
    }

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


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

// 整数a, bの最小公倍数を返す関数
int64_t kou_min (int64_t a, int64_t b) {

  // a1>=b1とする
  int64_t a1, b1, r;
  a1 = max(a, b);
  b1 = min(a, b);

  // ユークリッドの互除法を用いる, b1が最大公約数として返される。
  while (true) {
    r = a1%b1;
    if (r == 0) {
      break;
    }
    a1 = b1;
    b1 = r;
  }

  int64_t ans;
  ans = a/b1*b;

  return ans;
}

int main() {

  int N;
  cin >> N;
  int64_t ans;
  vector<int64_t> T(N);
  for (int i = 0; i < N; i++) {
    cin >> T.at(i);
  }
  if (N==1) cout << T.at(0) << endl;
  else {
    for (int i = 0; i < N-1; i++) {
      ans = kou_min(T.at(i), T.at(i+1));
      T.at(i+1) = ans;
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define PI 3.141592653589793
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int dp[1001][10001];

int main(){
    int H,N;
    cin >> H >> N;
    //vector<vector<ll> > dp(N,vector<ll> (H+1,INF));
    for(int i = 0; i < 1001; i++)
        for(int j = 0; j < 10001; j++)
            dp[i][j] = INF;
    
    vector<int> A(N),B(N);
    for(int i = 0; i < N; i++){
        cin >> A[i] >> B[i];
    }
    for(int i = 0; i < N; i++){
        for(int j = 0; j <= H; j++){
            if(j<=A[i]){
                dp[i+1][j] = min( dp[i][j], B[i] );
            }else{
                dp[i+1][j] = min( dp[i][j], dp[i+1][j-A[i]] + B[i] );
            }
            //cout << dp[i+1][j]<< endl;
        }
    }
    // for(int i = 0; i < N; i++){
    //     for(int j = 0; j <= H; j++){
    //         cout << dp[i][j] << ",";
    //     }
    //     cout << endl;
    // }


    cout << dp[N][H] << endl;
    

 
}

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

// int/long:		-2,147,483,648 - 2,147,483,647 (-2^31 <= int < 2^31)
// long/long long:	-9,223,372,036,854,775,808 - 9,223,372,036,854,775,807 (-2^63 <= long < 2^63)

#define	INF (1<<30)
//1,073,741,824
//= 536,870,912 *2

#define	MOD 1000000007

#define	Rep0(i, n)	for (auto i=0; i<n; i++)
#define	Rep1(i, n)	for (auto i=1; i<=n; i++)
#define Sort(P)	sort(P.begin(), P.end())
#define Rev(P)	reverse(P.begin(), P.end())

int	main() {
	ll N, K;
	cin >>N >>K;
	vector<ll> A(N+1, 0);
	Rep1(i, N)
		cin >>A.at(i);
	//
	vector<ll> B(N+1, -1);
	B.at(1)=0;
	ll IX=1;
	ll Step=1;
	for(;;) {
		IX=A.at(IX);
		if (-1==B.at(IX)) {
			B.at(IX)=Step;
			Step++;
		} else
			break;
	}
	ll Step0=B.at(IX);
	ll Loop=Step-Step0;
	if (K<=Step) {
		IX=1;
		Rep0(i, K)
			IX=A.at(IX);
	} else {
		K-=Step;
		K%=Loop;
		// IX=IX
		Rep0(i, K)
			IX=A.at(IX);
	}
	cout <<IX <<endl;
	return 0;
}



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

#define for_(i,a,b) for(int i=(a);i<(b);++i)
#define allof(a) (a).begin(),(a).end()

typedef struct Point {
	double x, y;
	
	Point() {}
	Point(double _x_, double _y_) : x(_x_), y(_y_) {}
	
	Point operator / (double d) const { return Point(x / d, y / d); }
	Point operator * (double d) const { return Point(x * d, y * d); }
	Point operator + (const Point& a) const { return Point(x + a.x, y + a.y); }
	Point operator - (const Point& a) const { return Point(x - a.x, y - a.y); }
	
	bool operator < (const Point& p) const {
		return (x == p.x) ? y < p.y : x < p.x;
	}
	
	bool operator == (const Point& p) const {
		return x == p.x && y == p.x;
	}
} Vector;

double abs(Point a) { return sqrt(a.x * a.x + a.y * a.y); }

Vector unit_vector(Vector a) { return a / abs(a); }

pair< Vector, Vector > normal_unit_vectors(Vector a) {
	return make_pair(unit_vector(Vector(a.x, -a.y)), unit_vector(Vector(-a.y, a.x)));
}

int n;
vector< Point > vp;

void solve() {
	sort(allof(vp));
	
	double ans = 0;
	
	for_(i,0,n) for_(j,0,n) {
		double dst = abs(vp[i] - vp[j]);
		
		pair< Vector, Vector > nuv = normal_unit_vectors(vp[i] - vp[j]);
		
		Vector a = nuv.first, b = nuv.second;
		
		//
		Point vpI = vp[i] + (a * dst), vpJ = vp[j] + (a * dst);
		
		if (binary_search(allof(vp), vpI) &&
			binary_search(allof(vp), vpJ)) {
			ans = max(ans, dst * dst);
		}
		
		//
		vpI = vp[i] + (b * dst), vpJ = vp[j] + (b * dst);
		
		if (binary_search(allof(vp), vpI) &&
			binary_search(allof(vp), vpJ)) {
			ans = max(ans, dst * dst);
		}		
	}
	
	if (ans == 0.0) cout << 0 << endl;
	else cout << int(ans + 0.5) << endl;//setprecision(9) << setiosflags(ios::fixed) << ans << endl;
}

int main() {
	while (cin >> n, n) {
		vp.clear();
		
		for_(i,0,n) {
			double x, y;
			cin >> x >> y;
			vp.push_back(Point(x, y));
		}
		
		solve();
	}
}

Measured memory_bytes: 3264
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<set>
 
using namespace std;
 
int main()
{
	int a[5];
	int  k = 0;
	int h = 0;
	int b[5];
	for (int i = 0; i < 5; i++)
	{
		cin >> a[i];
		int x = a[i];
		int m = 0;
		for (;;)
		{
			
			if (x % 10 == 0)
			{
				
				if (h < m)
				{
					h = m;
					k = i;
				}
				b[i] = x;
				break;
			}
          x ++ ;
			m++;
		}
		
	}
cout << b[0] + b[1] + b[3] + b[4] + b[2] - h << endl;
}

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


int n; 

void dfs(string s, char mx) {
  int l = s.length();
  if(l==n) {
    cout << s << endl;
    return;
  }
  for(char c = 'a'; c < mx; c++) dfs(s + c, mx);
  dfs(s + mx,(char)(mx + 1));

}

int main() {
  cin >> n;
  dfs("",'a');
  return 0;
}

Measured memory_bytes: 3596
def make_divisors(n: int) -> list:
    divisors = []

    for i in range(1, int(n**0.5) + 1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n // i)

    return sorted(divisors)


N = int(input())

ans = 0
divisors = make_divisors(N)

for x in divisors:
    m = N // x - 1
    if (m > 0) and (N // m == N % m):
        ans += m
print(ans)


Measured memory_bytes: 3296
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm>
#include <numeric>
#include <typeinfo>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define debug(n) cout<<__FILE__<<","<<__LINE__<<": #"<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int main()
{
	vi is_prime(10000,1);
	is_prime[0]=is_prime[1]=0;
	rep(i,is_prime.size()){
		if(is_prime[i])
			for(int j=i+i;j<is_prime.size();j+=i)
				is_prime[j]=0;
	}
	vi primes;
	rep(i,is_prime.size())
		if(is_prime[i])
			primes.push_back(i);
	
	vi psum(primes.size()+1);
	partial_sum(allof(primes),psum.begin()+1);
			
	for(int n;cin>>n,n;){
		int res=0;
		rep(i,psum.size())
			repi(j,i+1,psum.size())
				if(psum[j]-psum[i]==n)
					res++;
		cout<<res<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 960
/*#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <stack>
#include <functional>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <numeric>
*/
#include <bits/stdc++.h>
#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define rrep()
#define Sort(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define vi vector<int>
#define INF (int)1e9
#define INFL 1e18
#define MOD 1000000007
#define pb push_back
#define MP make_pair
typedef long long int ll;
typedef std::pair<int,int> P;
int D=1;
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

using namespace std;

int main(){
    int a;
    char c;
    string s;
    int v[4]={};
    
    while(cin>>a>>c>>s){
        if(s=="A")v[0]++;
        else if(s=="B")v[1]++;
        else if(s=="AB")v[2]++;
        else v[3]++;
    }
    rep(i,0,4)cout<<v[i]<<endl;
    
    
    
    return 0;
}



Measured memory_bytes: 3120
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int a, b, c;
		double s, l, h;

		a = sc.nextInt();
		b = sc.nextInt();
		c = sc.nextInt();

		h = b * Math.sin(Math.toRadians(c));
		s = a * h / 2;
		l = a + b + Math.sqrt(a * a + b * b - 2 * a * b * Math.cos(Math.toRadians(c)));
		System.out.println(s);
		System.out.println(l);
		System.out.println(h);

	}

}



Measured memory_bytes: 26192
S=list(map(lambda x:x,input()))

F=(S[0]=="A")
F&=(S[2:-1].count("C")==1)

if F:
    S.remove("A")
    S.remove("C")
    for s in S:
        F&=(s==s.lower())
if F:
    print("AC")
else:
    print("WA")


Measured memory_bytes: 61968
/*
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_4_D
??\????????????n????????´??°???????°????????????§??????????¨????????±???????.
 */

#include<iostream>
using namespace std;

int main(){
  int a, min, max, n, i;
  long long sum;
  cin >> n;
  cin >> a;
  min = max = sum = a;
  for(i = 1; i < n; i++){
    cin >> a;
    sum += a;
    if (a < min) {
      min = a;
      continue;
    }
    if (a > max) max = a;
  }
  cout << min << " " << max << " " << sum << endl;
  return 0;
}

Measured memory_bytes: 1168
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define ld long double
#define INF 1000000000000000000
typedef pair<ll, ll> pll;

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

    ll N, K;
    cin >> N >> K;
    vector<int> A(N);
    rep(i, N) {
        cin >> A[i];
        A[i]--;
    }

    ll cyrange = 0, cycnt = 0, s = 0;
    vector<ll> seen(N, -1);
    seen[s] = 0;
    while (1) {
        cycnt++;
        s = A[s];
        if (seen[s] != -1) {
            cyrange = seen[s];
            cycnt -= cyrange;
            break;
        }
        seen[s] = cycnt;
    }

    ll amari;
    if (K - cyrange > 0) {
        K -= cyrange;
        amari = K % cycnt;
    } else {
        s = 0;
        amari = K;
    }

    while (amari != 0) {
        amari--;
        s = A[s];
    }

    cout << s + 1 << endl;
}

Measured memory_bytes: 5576
#include <bits/stdc++.h>
#include <string>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <bitset>
typedef long long ll;
using namespace std;

const int MAX = 510000;
const int MOD = 1000000007;
const int MAX_N = 200000;

int ctoi(const char c){
  switch(c){
    case '0': return 0;
    case '1': return 1;
    case '2': return 2;
    case '3': return 3;
    case '4': return 4;
    case '5': return 5;
    case '6': return 6;
    case '7': return 7;
    case '8': return 8;
    case '9': return 9;
    default : return -1;
  }
}

int main(int argc, const char * argv[]) {
    int N,K; cin >> N >> K;
    vector<int> d(K);
    vector<int> cnt(N,0);
    
    for(int i=0;i<K;i++){
        int d; cin >> d;
        for(int j=0;j<d;j++){
            int temp; cin >> temp;
            temp--;
            cnt[temp]++;
        }
    }
    
    int ans=0;
    for(int i=0;i<N;i++){
        if(cnt[i]==0) ans++;
    }
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int n,m,dp[111][111][2];
char c[111][111]; 
int main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			cin>>c[i][j];
		}
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			dp[i][j][0]=1e9;
			dp[i][j][1]=1e9;
			if(i==1 && j==1)
			{
				if(c[i][j]=='#')
				{
					dp[i][j][0]=1;
					dp[i][j][1]=0;
				}
				else
				{
					dp[i][j][1]=1;
					dp[i][j][0]=0;
				}
			}
			else if(i==1 || j==1)
			{
				if(i==1)
				{ 
					if(c[i][j]=='.')
					{
						dp[i][j][0]=min(dp[i][j-1][0],dp[i][j-1][1]+1);
					}
					else
					{
						dp[i][j][1]=min(dp[i][j-1][0],dp[i][j-1][1]);
					} 
				}
				else
				{ 
					if(c[i][j]=='.')
					{ 
						dp[i][j][0]=min(dp[i-1][j][0],dp[i-1][j][1]+1);
					}
					else
					{
						dp[i][j][1]=min(dp[i-1][j][0],dp[i-1][j][1]);
					} 
				}
			}
			else
			{ 
				if(c[i][j]=='.')
				{ 
					dp[i][j][0]=min(dp[i-1][j][0],dp[i-1][j][1]+1);
					dp[i][j][0]=min(dp[i][j][0],min(dp[i][j-1][0],dp[i][j-1][1]+1));
				}
				else
				{
					dp[i][j][1]=min(dp[i-1][j][0],dp[i-1][j][1]);
					dp[i][j][1]=min(dp[i][j][1],min(dp[i][j-1][0],dp[i][j-1][1]));
				} 
			}
		}
	}/*
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			if(dp[i][j][0]==1e9)
			{
				cout<<-1<<' ';
			}
			else
			{
				cout<<dp[i][j][0]<<' ';
			}
			if(dp[i][j][1]==1e9)
			{
				cout<<-1<<' ';
			}
			else
			{
				cout<<dp[i][j][1]<<' ';
			}
		}
		cout<<endl; 
	}*/
	cout<<min(dp[n][m][0],dp[n][m][1]+1)<<endl;
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

string ar[100];

int main(){
    int n, l;
    cin >> n >> l;
    for(int i=0;i<n;i++) cin>>ar[i];
    sort(ar, ar+n);
    for(int i=0;i<n;i++){
        cout << ar[i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <limits>

struct Spell {
    int64_t damage{};
    int64_t cost{};
};

int main() {
    int64_t h{}, n{};
    std::cin >> h >> n;
    std::vector<Spell> spells(n);
    for (int64_t i = 0; i < n; i++) {
        std::cin >> spells[i].damage >> spells[i].cost;
    }

    std::vector<int64_t> dp(h + 1, std::numeric_limits<int64_t>::max());
    dp[0] = 0;
    for (int64_t i = 0; i < h; i++) {
        if (dp[i] == std::numeric_limits<int64_t>::max()) continue;
        for (int64_t j = 0; j < n; j++) {
            const auto total = std::min(h, i + spells[j].damage);
            dp[total] = std::min(dp[total], dp[i] + spells[j].cost);
        }
    }
    std::cout << dp.back() << std::endl;
    return 0;
}

Measured memory_bytes: 3708
#include<iostream>
using namespace std;
#define ll long long

ll all(ll n)
{
    if(n < 0) return 0;
    if(n == 0) return 1;
    else return all(n-1) * 2 + 3;
}

ll apy(ll n)
{
    if(n == 0) return 1;
    return apy(n-1) * 2 + 1;
}

ll pty(ll n, ll k)
{
    ll a = all(n-1);
    ll sum = (k > a+1);
    if(k <= 0 || k <= n) return 0;
    if(n == 0) return 1;
    if(k >= all(n)) return apy(n-1) * 2 + 1;
    if(k <= a) return pty(n-1, k-1);
    sum += apy(n-1);
    if(k > a + 2) sum += pty(n-1, k - (a+2));
    return sum;
}

int main()
{
    ll n, x;
    cin >> n >> x;
    cout << pty(n, x) << endl;
    return 0;
}

Measured memory_bytes: 256
def main():
    N, W = map(int, input().split())
    w = [0] * N
    v = [0] * N
    for i in range(N):
        w[i], v[i] = map(int, input().split())

    dp = [[0] * (W + 5) for _ in range(N + 5)]
    
    for i in range(N):
        for j in range(W):
            print
            if j + w[i] <= W:
                dp[i+1][j + w[i]] = max(dp[i+1][j + w[i]], dp[i][j] + v[i])
            dp[i+1][j] = max(dp[i+1][j], dp[i][j])
    
    print(max(dp[N]))


if __name__ == "__main__":
    main()

Measured memory_bytes: 118128
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i=0;i < (int)(n);i++)

ll dp[100100];
const ll mod = 1e9+7;

int main(){
  int n,m;
  cin >> n >> m;
  rep(i,m){
    int tmp;
    cin >> tmp;
    dp[tmp] = -1;
  }
  dp[0] = 1LL;
  rep(i,n+1){
    if (dp[i] == -1) continue;
    if (dp[i+1] != -1){
      dp[i+1] += dp[i];
      dp[i+1] %= mod;
    }
    if (dp[i+2] != -1){
      dp[i+2] += dp[i];
      dp[i+2] %= mod;
    }
    
  }
  cout << dp[n] << endl;
  

  return 0;
}


Measured memory_bytes: 4364
/*
ID: anonymo14
TASK: wormhole
LANG: C++                 
*/
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

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

#define MOD 1000000007

void solve(int test_case) {//223
	int n;
	cin>>n;
	int cnt=0;
	while(n>0) {
		if(n%10==2)cnt++;
		n/=10;
	}
	cout<<cnt;
}

int main() {
	
	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}	


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

#define all(v)			((v).begin()), ((v).end())
#define sz(v)			((int)((v).size()))
#define clr(v, d)		memset(v, d, sizeof(v))
#define rep(i, v)		for(int i=0;i<sz(v);++i)
#define lp(i, n)		for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n)	for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n)	for(int i=(j);i>=(int)(n);--i)
#define tc              int t;cin>>t
#define w               while(t--)
typedef long long ll;
typedef pair<int,int> pi;
bool vis[100009];
long long n;
int cnt=0,l=0,r=0;

int main() {
#ifndef ONLINE_JUDGE
	//freopen("test.txt", "rt", stdin);
#endif
int n,m;
cin>>n>>m;
vector<int> v;
lp(i,n)
{
    int x;
    cin>>x;
    v.push_back(x);
}
int s=accumulate(v.begin(),v.end(),0);
int c=0;double r=(1.0/(4*m))*s;
for(int i=0;i<n;i++)
    if(v[i]>=r)
        c++;
if(c>=m)
    cout<<"Yes";
else
    cout<<"No";


}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
const int RANDOM1 = chrono::high_resolution_clock::now().time_since_epoch().count();
struct chash {
    int operator()(int x) const { return hash<int>{}(x ^ RANDOM1); }
};
#define ll long long
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define deb(x) cout<<#x<<" : "<<x<<"\n";
#define debug(x,y) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<"\n";
#define ff first
#define ss second
#define ub upper_bound
#define lb lower_bound
#define all(a) (a).begin(),(a).end()
#define bs binary_search
#define sz size()
#define vi vector<int>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ld long double
#define clr fflush(stdout);
//#define clr cout.flush();
#define N 100001
#define fpr(i,a,b) for(int i=a;i<b;i++)
#define fdr(i,a,b) for(int i=a;i>b;i--)
#define repp(i,a,b,d) for(int i=a;i<b;i+=d)
#define repd(i,a,b,d) for(int i=a;i>b;i-=d)
#define LLMIN LLONG_MIN
#define LLMAX LLONG_MAX
#define AKASH_PATEL ios_base::sync_with_stdio(false);
#define SVNIT_SURAT cin.tie(NULL);cout.tie(NULL);
#define mset(x,a) memset(x,a,sizeof(x));
#define nl cout<<'\n';
#define print(c) cout<<c<<'\n';
#define setp(n) cout << fixed << setprecision(n)
#define take_arr(a,n) fpr(i,0,n) cin>>a[i];
#define print_arr(a,n) for(int i=0;i<n;i++) {cout<<a[i]<<" ";} cout<<'\n';
#define take_mat(mat,n,m) fpr(i,0,n) fpr(j,0,m) cin>>mat[i][j];
#define set_mat(mat,n,m,k) fpr(i,0,n) fpr(j,0,m) mat[i][j]=k;
#define print_mat(dist,n,m) for(int i=0;i<n;i++){for(int j=0;j<m;j++){cout<<dist[i][j]<<" ";}cout<<'\n';}
template< class T > bool inside(T a, T b, T c) { return a<=b && b<=c; }
int main()
{
    AKASH_PATEL;
    SVNIT_SURAT;
    int n;
    cin>>n;
    ll a[n];
    take_arr(a,n)
    ll f[2*N];
    mset(f,0)
    fpr(i,0,n)
    {
        f[a[i]]++;
    }
    ll ans=0;
    fpr(i,1,n+1)
    {
        if(f[i]>=2)
        {
            ans+=(f[i]*(f[i]-1))/2;
        }
    }
    fpr(i,0,n)
    {
        ll tmp=ans;
        tmp-=(f[a[i]]*(f[a[i]]-1))/2;
        ll c=f[a[i]];
        c--;
        tmp+=(c*(c-1))/2;
        print(tmp)
    }
    return 0;
}





Measured memory_bytes: 5760