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

int main(int argc, char **argv) {
  int i;

  int x, N;
  cin >> N;

  long ans = 0;
  int dignum = (int)log10(N);

  for (int i = 1; i <= dignum; i++) {
    if (i % 2 == 1) {
      ans += (pow(10, i) - 1) - pow(10, i - 1) + 1;
    }
  }

  if (dignum % 2 == 0) {
    ans += N - pow(10, dignum) + 1;
  }

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


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
using namespace std;
using lli = long long int;
int main()
{
    int n;
    cin >> n;
    int a, b;
    cin >> a >> b;
    int d = 4 * (n & 1) + 2 * (a & 1) + (b & 1);
    int w;
    if (d == 0) {
        w = 1;
    }
    if (d == 1) {
        w = 0;
    }
    if (d == 2) {
        w = 0;
    }
    if (d == 3) {
        w = 1;
    }
    if (d == 4) {
        w = 1;
    }
    if (d == 5) {
        w = 0;
    }
    if (d == 6) {
        w = 0;
    }
    if (d == 7) {
        w = 1;
    }
    cout << (w == 1 ? "Alice" : "Borys") << endl;
}


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

using namespace std;

int main() {
    string N;
    cin >> N;
    char f = N[0];
    char res[N.size()];
    bool ok = true;
    for (int i = 0; i < N.size(); i++) {
        res[i] = f;
        if (N[i] <= f) {
            continue;
        }
        ok = false;
    }
    if (!ok) {
        for (int i = 0; i < N.size(); i++) {
            res[i]++;
        }
    }
    string resstr(res, N.size());
    cout << resstr << "\n";
    return 0;
}

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

class TreeNode {
public:
    TreeNode *left;
    TreeNode *right;
    int val;
    TreeNode(int val) : left(nullptr), right(nullptr), val(val) {}
};

TreeNode* insert(TreeNode* root, int val)
{
    if (!root) return new TreeNode(val);
    TreeNode* curr = root;
    TreeNode* prev = nullptr;
    while (curr) {
        prev = curr;
        if (val < curr->val) {
            curr = curr->left;
        } else {
            curr = curr->right;
        }
    }
    if (val < prev->val)
        prev->left = new TreeNode(val);
    else
        prev->right = new  TreeNode(val);
    return root;
}

void inorder(TreeNode* root)
{
    if (!root) return;
    inorder(root->left);
    cout << " " << root->val;
    inorder(root->right);
}

void preorder(TreeNode* root)
{
    if (!root) return;
    cout << " " << root->val;
    preorder(root->left);
    preorder(root->right);
}

int main()
{
    int n;
    cin >> n;
    string s;
    int val;
    TreeNode* tree = nullptr;
    for (int i = 0; i < n; i++) {
        cin >> s;
        if (s == "insert") {
            cin >> val;
            tree = insert(tree, val);
        } else if (s == "print") {
            inorder(tree);
            cout << endl;
            preorder(tree);
            cout << endl;
        }
    }
}


Measured memory_bytes: 18788
//============================================================================
// Name        : ATcoder.cpp
// Author      : Akari Fujii
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cctype>
#include <string>
#include<algorithm>
using namespace std;
typedef long long ll;
int main() {

	int a,b;
	int d=0;
	string str1;


	cin>>a>>b;
	cin>>str1;

	for(int i=0; i<a; ++i){
		if(str1[i]=='-'){
			d+=1;
		}
		for(int j=a+1; j<str1.size(); ++j){
			if(str1[j]=='-'){
				d+=1;
			}
		}

	}
	if(str1[a]=='-'){

	}else{
		d+=1;
	}
	if(d>0){
		cout<<"No"<<endl;
	}else{
		cout<<"Yes"<<endl;
	}



	return 0;
}


Measured memory_bytes: 256
n = gets.to_i
a = gets.chomp.split(" ").map(&:to_i)
amax = a.max
amin = a.min
ans = n*(amax-amin)**2
for i in amin..amax
  tmp = 0
  a.each do |num|
    tmp += (num-i)**2
  end
  ans = [ans,tmp].min
end
puts ans

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
long  n,m,w[100000],v[1000000],kq=-5;
long long f[5000][5000];
string s,t;
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    cin>>s>>t;
    s=' ' + s;
    t=' ' + t;
    for (long i=1;i<s.size();i++)
    {
        for (long j=1;j<t.size();j++)
        {
            if (s[i]==t[j])
            {
                    f[i][j]=f[i-1][j-1]+1;
            }
            else
                f[i][j]=max(f[i-1][j],f[i][j-1]);
        }
    }
    string res="";
    long m=s.size()-1;
    long n=t.size()-1;
    while (m>0 && n>0)
    {
        if (s[m]==t[n])
        {
            res=s[m]+res;
            m--;
            n--;
            continue;
        }
        if (f[m][n]==f[m-1][n])
        {
            m--;
        }
        else n--;

    }
    cout<<res;

}


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

using namespace std;
typedef long long int ll;

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

#define KAZARI 2
#define INF 1 << 29

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

    vector<int> dp(n,INF);

    dp[0]=0;

    for(int i=0;i<n;i++){
        chmin(dp[i+1],dp[i]+abs(h[i]-h[i+1]));
        chmin(dp[i+2],dp[i]+abs(h[i]-h[i+2]));
        /*puts("");
        for(auto v : dp){
            cout << v << endl;
        }*/
    }

    cout << dp[n-1] << endl;

}

Measured memory_bytes: 1152
N = int(input())
Ss = [str(input()) for x in range(N)]
r = [0]*4
for s in Ss:
  if s == "AC":
    r[0] += 1
  elif s == "WA":
    r[1] += 1
  elif s == "TLE":
    r[2] += 1
  elif s == "RE":
    r[3] += 1
print("AC x " + str(r[0]))
print("WA x " + str(r[1]))
print("TLE x " + str(r[2]))
print("RE x " + str(r[3]))

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)

using namespace std;
typedef vector<vector<int>> vvi;
typedef vector<vector<bool>> vvb;

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

    int correct = 0;

    rep(i, 3) {
        if (S[i] == T[i]) {
            correct++;
        }
    }

    cout << correct << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define sc(x) scanf("%d", &x)
#define pr(x) printf("%d\n", x)
#define lowbit(x) (x & -x)
#define N 100010
#define memset(x) memset(x, 0, sizeof(x))
using namespace std;
int n, f[60][30] = {};
string ans;
int main()
{
	sc(n);
	for (int i = 1; i <= n; i++)
	{
		string s;
		cin >> s;
		for (int j = 0; j < s.size(); j++)
		f[i][s[j] - 'a' + 1]++; 
	}
	for (int i = 1; i <= 26; i++)
	{
		int minn = 50;
		for (int j = 1; j <= n; j++)
		minn = min(minn, f[j][i]);
		for (int j = 1; j <= minn; j++)
		ans = ans + (char)(i + 'a' - 1);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.math.*;

public class Main {

    int[] a;

    void solve() {
    	int A = sc.nextInt();
    	int B = sc.nextInt();
    	int C = sc.nextInt();

    	int max = Math.max(Math.max(A,B),C);

	BigInteger bA = BigInteger.valueOf(A);
	BigInteger bB = BigInteger.valueOf(B);
	BigInteger bC = BigInteger.valueOf(C);
	BigInteger tmp = bA.multiply(bB).multiply(bC);

    	BigInteger tmp2 = tmp.divide(BigInteger.valueOf(max));

    	if (tmp.remainder(BigInteger.valueOf(2)) == BigInteger.valueOf(0)) {
	    System.out.println(0);
    	} else {
	    System.out.println(tmp2);
    	}

    }

    void print(int[] a) {
    	out.print(a[0]);
    	for (int i = 1; i < a.length; i++) out.print(" " + a[i]);
    	out.println();
    }

    public static void main(String[] args) throws Exception {
    	new Main().run();
    }

    MyScanner sc = null;
    PrintWriter out = null;
    public void run() throws Exception {
    	sc = new MyScanner(System.in);
    	out = new PrintWriter(System.out);
    	for (;sc.hasNext();) {
    	    solve();
    	    out.flush();
    	}
    	out.close();
    }

    class MyScanner {
    	String line;
    	BufferedReader reader;
    	StringTokenizer tokenizer;

    	public MyScanner(InputStream stream) {
    	    reader = new BufferedReader(new InputStreamReader(stream));
    	    tokenizer = null;
    	}
    	public void eat() {
    	    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
    		try {
    		    line = reader.readLine();
    		    if (line == null) {
    			tokenizer = null;
    			return;
    		    }
    		    tokenizer = new StringTokenizer(line);
    		} catch (IOException e) {
    		    throw new RuntimeException(e);
    		}
    	    }
    	}
    	public String next() {
    	    eat();
    	    return tokenizer.nextToken();
    	}
    	public String nextLine() {
    	    try {
    		return reader.readLine();
    	    } catch (IOException e) {
    		throw new RuntimeException(e);
    	    }
    	}
    	public boolean hasNext() {
    	    eat();
    	    return (tokenizer != null && tokenizer.hasMoreElements());
    	}
    	public int nextInt() {
    	    return Integer.parseInt(next());
    	}
    	public long nextLong() {
    	    return Long.parseLong(next());
    	}
    	public double nextDouble() {
    	    return Double.parseDouble(next());
    	}
    	public int[] nextIntArray(int n) {
    	    int[] a = new int[n];
    	    for (int i = 0; i < n; i++) a[i] = nextInt();
    	    return a;
    	}
    }
}


Measured memory_bytes: 8396
//
// Created by yamunaku on 2020/01/10.
//

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repl(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perl(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD9 998244353
#define MOD1 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)
#define CST(x) cout<<fixed<<setprecision(x)

using ll = long long;
using ld = long double;
using vi = vector<int>;
using mti = vector<vector<int>>;
using vl = vector<ll>;
using mtl = vector<vector<ll>>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
template<typename T>
using heap = priority_queue<T, vector<T>, function<bool(const T, const T)>>;

int main(){
    // CFS;
    int n;
    cin >> n;
    string s;
    cin >> s;
    int ans = 0;
    rep(i, n - 2){
        if(s.substr(i, 3) == "ABC") ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<queue>
#include<deque>
#include<algorithm>
#include<stack>
#include<vector>
using namespace std;
long long n,a,ans;
int main()
{
	scanf("%lld",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&a);
		while(a%2==0&&a!=0)
		{
			a=a/2;
			ans++;
		}
	}
	printf("%lld",ans);
	return 0;
}

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

int n;
vector<int> et[200];	//0???99;????????¶???100???199;??????

int visitState[200];	//visitState[i] = 0???noVisit, 1???Searching, 2???Visited

bool find_cycle(int v) {
	if (visitState[v] == 2) { return false; }
	if (visitState[v] == 1) { return true; }
	
	visitState[v] = 1;
	for (int i = 0; i < et[v].size(); i++) {
		if (find_cycle(et[v][i])) { return true; }
	}
	visitState[v] = 2;
	return false;
}

int main() {
	int i, j;
	
	cin >> n;
	for (i = 0; i < n; i++) {
		int u, d;
		string state;
		
		cin >> u >> state >> d;
		u--; d--;
		
		if (state == "lock") {
			et[d + 100].push_back(u);
		}
		else {
			et[u].push_back(d + 100);
		}
	}
	
	for (i = 0; i < 200; i++) {
		if (find_cycle(i)) {
			cout << 1 << endl;
			return 0;
		}
	}
	cout << 0 << endl;
	return 0;
}

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

int main() {
    int X, A, B;
    cin >> X >> A >> B;

    if (0 <= (A - B)) {
        cout << "delicious" << endl;
    } else if (X < (B - A)) {
        cout << "dangerous" << endl;
    } else {
        cout << "safe" << endl;
    }
}

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

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define repf(i, f, l) for(int i = f; i < (int)l; ++i)
#define repit(it, t) for(__typeof((t).begin()) it = (t).begin(); it != (t).end(); it++)
#define endl "\n"
#define pb emplace_back
#define lb lower_bound
#define int long long
#define ul unsigned long
#define ull unsigned long long
#define ll long long
#define INF 1000000007
#define MOD 1000000007
#define fs first
#define sd second
#define DBG0(x) { cout << #x << ": " << x << "\t"; }
#define DBG(x) {DBG0(x); cout << endl;}
#define DBG2(x, y) {DBG0(x); DBG(y);}
#define DBG3(x, y, z) {DBG0(x); DBG2(y, z);}
#define DBG4(w, x, y, z) {DBG0(w); DBG3(x, y, z);}

typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<ul> vul;
typedef vector<ull> vull;
typedef vector<bool> vbl;
typedef pair<int, int> pii;

signed main(void){
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vint as = vint(n);
    vint bs = vint(n);
    rep(i, n) cin >> as[i];
    rep(i, n) cin >> bs[i];

    int suma = 0;
    rep(i, n) suma += as[i];

    int sumb = 0;
    rep(i, n) sumb += bs[i];
    if (sumb > suma) {
        cout << -1 << endl;
        return 0;
    }

    vint cs = vint(n);
    rep(i, n) cs[i] = bs[i];
    suma -= sumb;

    priority_queue<pii, vector<pii>, greater<pii>> que;
    rep(i, n) {
        if (cs[i] < as[i]) {
            que.push(pii(as[i] - cs[i], i));
        }
    }
    while(suma > 0) {
        pii p = que.top();
        que.pop();
        suma -= p.fs;
        if (suma < 0) break;
        int i = p.sd;
        cs[i] = as[i];
    }

    int ans = 0;
    rep(i, n) {
        if (as[i] != cs[i]) ans++;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3704
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<iomanip>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<vector>
#include<queue>
#include<set>
#define ll long long
using namespace std;
const int maxn=1e5+5;

int main()
{
    //freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
	int h[maxn]={0},flag[maxn]={0};
	int n,m,ans=0;
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		cin>>h[i];
	}
	int ai,bi;
	for(int i=1;i<=m;i++){
		cin>>ai>>bi;
		if(h[ai]==h[bi]){
			if(!flag[ai]){
				flag[ai]=1;ans++;
			}
			if(!flag[bi]){
				flag[bi]=1;ans++;
			}
			continue;
		}
		if(h[ai]>h[bi])ai=bi;
		if(!flag[ai]){
				flag[ai]=1;ans++;
			}
	}
	cout<<n-ans;
    return 0;
}



Measured memory_bytes: 4416
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cctype>
#include<utility>

using namespace std;
int main()
{
    int n=0;
    char s[4];
    scanf("%s",s);
    for(int i=0;i<4;i++)
    {
        if(s[i]=='+')
            n++;
        if(s[i]=='-')
            n--;
    }
    printf("%d\n",n);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
 	//一回目は座標0でバウンドする。D.at(0)=0
 	int ans =0;
	//とりあえずDiを全て求めちゃう？いいね
		int n , x;
	cin >> n >> x;
	vector<int> L(n);
	for (int i = 0 ; i < n ; i++){
	  cin  >> L.at(i) ;
	  }
	 vector<int> D(n+1);
	int a=0;//aは一個前の値をみるためのへんすう
	 for(int i = 0 ; i<n+1; i++){
	   if(i==0){
	     D.at(i)=0;
	     a=D.at(i);
	     //cout <<"a:"<<a<<endl;
	     }
	     else{
	       D.at(i)=a+L.at(i-1);
	       
	       a = D.at(i);
	       //cout<<"a:"<<a<<endl;
	       }}
	      //i+1回目は、座標D.at(i)で跳ねる。今、座標D.at(i)をkとすると、
	     // 座標kまでで跳ねる回数はi回である。
	     //n+1までfor回して、L.at(i)がxをこしたらbreak;で通せそう
	     for(int i = 0 ; i < n+1 ; i++){
	       if(D.at(i)<=x){
	         ans ++;
	         }
	         else if(D.at(i)>x){
	           break;
	           }
	           }
	           cout << ans << endl;	      
	     
	   
}

Measured memory_bytes: 256
import heapq
import math

n, m = map(int, input().split())
a = [int(x) for x in input().split()]
h = []

for i in a:
    heapq.heappush(h, -i)
#print(h)

for i in range(m):
    tmp = heapq.heappop(h)
    tmp = math.ceil(tmp/2)
    heapq.heappush(h, tmp)
#print(h)

print(-1*sum(h))

Measured memory_bytes: 14532
package main

import (
	"fmt"
	"math"
)

const inf = math.MaxInt64 / 2

func chmin(a *int, b int) {
	if *a > b {
		*a = b
	}
}

func pow(a, b int) int {
	ans := 1
	for i := 0; i < b; i++ {
		ans *= a
	}
	return ans
}

func main() {
	var n int
	fmt.Scan(&n)

	dp := make([]int, n+1)
	for i := range dp {
		dp[i] = inf
	}
	dp[0] = 0

	for i := 1; i < n+1; i++ {
		chmin(&dp[i], dp[i-1]+1)
	}
	for i := 0; i < n+1; i++ {
		for j := 1; i+pow(6, j) < n+1; j++ {
			chmin(&dp[i+pow(6, j)], dp[i]+1)
		}
		for j := 1; i+pow(9, j) < n+1; j++ {
			chmin(&dp[i+pow(9, j)], dp[i]+1)
		}
	}

	fmt.Println(dp[n])
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

const ll mod=1e9+7;
template< int mod >
struct ModInt {
  int x;

  ModInt() : x(0) {}

  ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}

  ModInt &operator+=(const ModInt &p) {
    if((x += p.x) >= mod) x -= mod;
    return *this;
  }

  ModInt &operator-=(const ModInt &p) {
    if((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }

  ModInt &operator*=(const ModInt &p) {
    x = (int) (1LL * x * p.x % mod);
    return *this;
  }

  ModInt &operator/=(const ModInt &p) {
    *this *= p.inverse();
    return *this;
  }

  ModInt operator-() const { return ModInt(-x); }

  ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }

  ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }

  ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }

  ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }

  bool operator==(const ModInt &p) const { return x == p.x; }

  bool operator!=(const ModInt &p) const { return x != p.x; }

  ModInt inverse() const {
    int a = x, b = mod, u = 1, v = 0, t;
    while(b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }

  ModInt pow(int64_t n) const {
    ModInt ret(1), mul(x);
    while(n > 0) {
      if(n & 1) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }

  friend ostream &operator<<(ostream &os, const ModInt &p) {
    return os << p.x;
  }

  friend istream &operator>>(istream &is, ModInt &a) {
    int64_t t;
    is >> t;
    a = ModInt< mod >(t);
    return (is);
  }

  static int get_mod() { return mod; }
};

using modint = ModInt< mod >;


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

  int n,m,k;
  cin >> n >> m >> k;
  modint nn,mm,kk;
  nn=n;mm=m;kk=k;
  modint sum=0;
  modint comb=1;

  rep(i,k-2){
    modint ii=i;
    comb*=(nn*mm-2-i)/(ii+1);
  }
  rep1(i,m-1){
    modint ii=i;
    sum += nn*nn*comb*(ii*ii+ii)/2;
  }
  rep1(i,n-1){
    modint ii=i;
    sum	+= mm*mm*comb*(ii*ii+ii)/2;
  }
  cout << sum << endl;
  return 0;
    

}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        SimpleKnapsack solver = new SimpleKnapsack();
        solver.solve(1, in, out);
        out.close();
    }

    static class SimpleKnapsack {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            long w = in.nextLong();

            long[] weights = new long[n];
            long[] values = new long[n];

            // i番目 | 選んだ個数 | 残 weight
            long[][][] dp = new long[n + 1][n + 1][3 * n + 1];
            for (int i = 0; i < n; i++) {
                weights[i] = Long.parseLong(in.next());
                ;
                values[i] = Long.parseLong(in.next());
                ;
            }

            for (int i = 0; i < n; i++) {
                long diff = weights[i] - weights[0];
                for (int j = 0; j <= i; j++) {
                    for (int k = 0; k <= 3 * n; k++) {
                        if (k - diff < 0) {
                            dp[i + 1][j + 1][k] = dp[i][j + 1][k];
                        } else {
                            dp[i + 1][j + 1][k] = Math.max(dp[i][j + 1][k], dp[i][j][(int) (k - diff)] + values[i]);
                        }
                    }
                }
            }
            long result = 0;
            for (int i = 0; i <= n; i++) {
                long zan = w - i * weights[0];
                if (zan >= 0) {
                    result = Math.max(result, dp[n][i][(int) Math.min(3 * n, zan)]);
                }
            }

            out.println(result);

        }

    }
}



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

int main(){
    // ll x = 1000000000000001;
    ll n;
    cin >> n;
    vector<ll> a;
    while(n > 0){
        a.push_back(n%26);
        n /= 26;
    }
    vector<char> results;
    rep(i,a.size()){
        if(a.at(i)<=0){
            if(i+1 < (int)a.size()){
                results.push_back('a'+a.at(i)+25);
                a.at(i+1)--;
            }
            continue;
        }
        char c = 'a' + a.at(i) - 1;
        results.push_back(c);
    }

    reverse(results.begin(),results.end());
    rep(i,results.size()){
        cout << results.at(i);
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 3628
import java.util.*;
import java.io.*;
public class Main extends PrintWriter {
    Main()
    {
        super(System.out);
    }
    public static void main(String args[]) {
      Main o=new Main();
      o.main();
      o.flush();
      o.close();
    }
    void main()
    {
        Scanner sc=new Scanner(System.in);
        long x=sc.nextLong();
        long k=sc.nextLong();
        long d=sc.nextLong();
        long rem=x%d;
        long quo=x/d;
        if(x<0)
        quo*=-1;
        if(k<quo)
        {
            if(x>0)
            {
                println(Math.abs(x-(k*d)));
            }
            else
            {
                println(Math.abs(x+(k*d)));
            }
        }
        else
        {
            if(x>=0)
            {
                long v1=rem-d;
                long rem1=k-quo;
                if(rem1%2==0)
                println(Math.abs(rem));
                else
                println(Math.abs(v1));
            }
            else
            {
                long v2=rem+d;
                long rem2=k-quo;
                if(rem2%2==0)
                println(Math.abs(rem));
                else
                println(Math.abs(v2));
            }
        }
        sc.close();
    }
}

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

signed main() {
    string xd;
    cin>>xd;
    if(xd=="MON"){
        cout<<6; return 0;
    }
    else if(xd=="TUE"){
        cout<<5; return 0;
    }
    else if(xd=="WED"){
        cout<<4; return 0;
    }
    else if(xd=="THU"){
        cout<<3; return 0;
    }
    else if(xd=="FRI"){
        cout<<2; return 0;
    }
    else if(xd=="SAT"){
        cout<<1; return 0;
    }
    else{
        cout<<7; return 0;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <array>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>

using namespace std;
using lli = long long int;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (lli i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

lli n;
vector<lli> a;
int main() {
  cin >> n; read_n(a, 3*n);
  vector<lli> lsum(n+1, 0); 
  auto comp = greater<lli>();
  priority_queue<lli, vector<lli>, decltype(comp)> lpq(comp);
  for (lli i=0; i<n; ++i) {
    lsum[0] += a[i];
    lpq.push(a[i]);
  }
  for (lli i=0; i<n; ++i) {
    lsum[i+1] = lsum[i];
    if (a[n+i] > lpq.top()) {
      lsum[i+1] += a[n+i] - lpq.top();
      lpq.pop();
      lpq.push(a[n+i]);
    }
  }

  vector<lli> rsum(n+1, 0);
  priority_queue<lli> rpq;
  for (lli i=0; i<n; ++i) {
    rsum[n] += a[2*n+i];
    rpq.push(a[2*n+i]);
  }
  for (lli i=n-1; i>=0; --i) {
    rsum[i] = rsum[i+1];
    if (a[n+i] < rpq.top()) {
      rsum[i] += a[n+i] - rpq.top();
      rpq.pop();
      rpq.push(a[n+i]);
    }
  }

  lli ans = -1e17;
  for (lli i=0; i<=n; ++i) {
    ans = max(ans, lsum[i] - rsum[i]);
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 6516
/*
解説AC.
*/
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<queue>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= (int)end; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

const ll INF = 1LL << 40;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    vector<ll> T(N), D(N);
    rep(i, 0, N) {
        cin >> T[i] >> D[i];
    }
    vector<vector<ll>> values(N);
    rep(i, 0, N) {
        values[T[i] - 1].push_back(D[i]);
    }
    rep(i, 0, N) {
        values[i].push_back(-INF);  // 番兵
        sort(all(values[i]));
        reverse(all(values[i]));
    }
    sort(all(values));
    reverse(all(values));
    ll ans = (ll)K * (ll)K;
    priority_queue<ll, vector<ll>, greater<ll>> que1;
    priority_queue<ll> que2;
    rep(i, 0, K) {
        ans += values[i].front();
        que1.push(values[i].front());
        rep(j, 1, values[i].size()) {
            que2.push(values[i][j]);
        }
    }
    rep(i, K, N) for (auto& v : values[i]) {
        que2.push(v);
    }
    ll sum = ans;
    rrep(x, K, 1) {
        ll now = que1.top();
        que1.pop();
        ll next = que2.top();
        que2.pop();
        sum += next - now + (ll)x * (ll)x - (ll)(x + 1) * (ll)(x + 1);
        if (now < next) {
            chmax(ans, sum);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 10352
#include<bits/stdc++.h>
using namespace std;
int main()
{
  long long int n,k;
  cin>>n>>k;
  long long int a[n+1]={0};
  for(int i=1;i<=n;i++)
    cin>>a[i];
  long long int dp[n+2]={0};
  int i=0,j=0,q=0;
  for(int i=2;i<=n;i++)
  { 
   long long int mi=1000000000;
   for(j=1;j<=k&&i-j>0;j++)
    {
      mi=min(mi,abs(a[i]-a[i-j])+dp[i-j]);
    }
   dp[i]=mi;
  }
  cout<<dp[n];
  return 0;
}



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

Measured memory_bytes: 3096
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
//-std=gnu++17
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int n, m;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n>>m;
    if(m>=n)cout<<"unsafe"<<"\n";
    else cout<<"safe"<<"\n";
}


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

int main() {
  
  int N, M; cin >> N >> M;
  
  int leftSide = 0; int rightSide = N + 1;
  
  for (int i = 0; i < M; i++) {
    
    int L, R; cin >> L >> R;
    
    leftSide = max(leftSide, L);
    
    rightSide = min(rightSide, R);
    
  }
  
  int ans = rightSide - leftSide + 1;
  
  cout << max(0, ans) << endl;
  
}

Measured memory_bytes: 256
from sys import stdin


# 素因数分解 -> tuple で返す
def prime_factorization_tuple(n):
    fct = []  # prime factor
    b, e = 2, 0  # base, exponent
    while b * b <= n:
        while n % b == 0:
            n = n // b
            e = e + 1
        if e > 0:
            fct.append((b, e))
        b, e = b + 1, 0
    if n > 1:
        fct.append((n, 1))
    return fct


def get_result(data):
    N = data[0]
    fct = prime_factorization_tuple(N)
    ans = 0
    for (_, exp) in fct:
        cnt = 0
        for i in range(1, 11):
            exp -= i
            if exp >= 0:
                cnt += 1
        ans += cnt
    return ans


if __name__ == '__main__':
    data = list(map(int, stdin.readline().rstrip().split(' ')))
    result = get_result(data)
    print(result)


Measured memory_bytes: 9180
import java.lang.reflect.Array;
import java.util.*;

/**
 * Created by Santa.
 */
public class Main {

  static int N;
  static int K;
  static long Q;
  static int A;
  static int B;
  static long C;
  static double min = 9999999;
  static long ans = 0;





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

    int N = scanner.nextInt();
    int M = scanner.nextInt();

    int C = scanner.nextInt();

    int[] map = new int[M];

    for (int i = 0; i < M; i++) {
      map[i] = scanner.nextInt();
    }

    int ans = 0;

    for (int i = 0; i < N; i++) {

      int cnt = 0;
      for (int j = 0; j < M; j++) {
        int temp = scanner.nextInt();

        cnt += temp * map[j];


      }
      if(cnt + C > 0)ans++;
    }


    System.out.println(ans);



//    System.out.println(getAns());





  }

//  static public int getAns(){
//    Scanner scanner = new Scanner(System.in);
//
//    int w = scanner.nextInt();
//
//
//
//
//    return (H - h) * (W - w);
//  }

}


Measured memory_bytes: 23252
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>

using namespace std;

int main(){
    int N;
    float T, A;
    cin >> N >> T >> A;
    vector<float> H(N);
    for(int i=0; i<N; i++) cin >> H[i];
    float T_min = max(A-(T-H[0]*0.006), (T-H[0]*0.006)-A);
    int ans = 0;
    if(N==1){
        cout << 1 << endl;
        return 0;
    }
    for(int i=1; i<N; i++){
        float kk = max(A-(T-H[i]*0.006), (T-H[i]*0.006)-A);
        if(T_min > kk){
            T_min = kk;
            ans = i;
        }
    }
    cout << ans+1 << endl;
    return 0;
}


Measured memory_bytes: 384
H,W,M=map(int,input().split())
height=[0]*H
width=[0]*W
#bomb=[0]*M
bset=set()
#for k in range(M):
    #bomb[k]=[0]*2
for j in range(M):
    h,w=map(int,input().split())
    bset.add((h-1,w-1))
    #bomb[j][0]=h-1
    #bomb[j][1]=w-1
    height[h-1]+=1
    width[w-1]+=1
#print(bomb)
#print(height)
#print(width)
hmax=max(height)
wmax=max(width)
hindex=0
windex=0
for i in range(H):
    if height[i]==hmax:
        #print(i)
        hindex+=1
for h in range(W):
    if width[h]==wmax:
        #print(h)
        windex+=1
kouho=hindex*windex
equalbomb=0
for p in bset:
    if height[p[0]]==hmax and width[p[1]]==wmax:
        #print(p)
        equalbomb+=1

if kouho==equalbomb:
    print(hmax+wmax-1)
else:
    print(hmax+wmax)

Measured memory_bytes: 130700
#include <algorithm>
#include <array>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

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

constexpr double EPS = 1e-7;
constexpr int INF = 1e9;
constexpr ll LINF = 1e18;
#define PI (acos(-1))

constexpr int MOD = 1e9 + 7;

int main(int argc, char const *argv[]) {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);

	map<string, int> m;

	int N;
	cin >> N;
	for (int i = 0; i < N; i++) {
		string s;
		cin >> s;
		if (m.count(s) > 0) {
			m[s]++;
		} else {
			m[s] = 1;
		}
	}

	int M;
	cin >> M;
	for (int i = 0; i < M; i++) {
		string s;
		cin >> s;
		if (m.count(s) > 0) {
			m[s]--;
		} else {
			m[s] = -1;
		}
	}

	int v_max = -INF;
	for (auto &&i : m) {
		if (i.second > v_max) {
			v_max = i.second;
		}
	}

	cout << max(v_max, 0)
		 << endl;
	return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
input:
8
insert 30
insert 88
insert 12
insert 1
insert 20
insert 17
insert 25
print

output: in_order + pre_order
1 12 17 20 25 30 88
30 12 1 20 17 25 88

def pre_order(node):
    if node is not None:
        print('', node.data, end='')
        pre_order(node.left)
        pre_order(node.right)
    return None


def in_order(node):
    if node is not None:
        in_order(node.left)
        print('', node.data, end='')
        in_order(node.right)
    return None

 def tree_data(self):
        stack = []
        node = self
        while stack or node:
            if node:
                stack.append(node)
                node = node.left
            else:
                node = stack.pop()
                yield node.data
                node = node.right
"""

import sys


class Node(object):
    def __init__(self, data):
        self.data = data
        self.left, self.right = None, None

    def insert(self, data):
        """
        insert data according to BST rules
        """
        if data < self.data:
            if self.left is None:
                self.left = Node(data)
            else:
                self.left.insert(data)
        else:
            if self.right is None:
                self.right = Node(data)
            else:
                self.right.insert(data)

        return None


def in_order(node):
    if node is not None:
        in_order(node.left)
        print('', node.data, end='')
        in_order(node.right)
    return None


def pre_order(node):
    if node is not None:
        print('', node.data, end='')
        pre_order(node.left)
        pre_order(node.right)
    return None


def action(command, content):
    if command[0] == 'i':
        tree_root.insert(data=int(content))

    elif command[0] == 'p':
        in_order(tree_root)
        print('')
        pre_order(tree_root)
        print('')

    return None


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    array_length = int(_input[0])
    command_list = list(map(lambda x: x.split(), _input[1:]))
    # assert len(command_list) == array_length
    # print(array_length, *command_list)

    flag, tree_root = False, None
    for each in command_list:
        command, content = each[0], each[-1]
        if (not flag) and command.startswith('in'):
            tree_root = Node(data=int(content))
            flag = True
            continue
        action(command=command, content=content)

Measured memory_bytes: 288632
#include<iostream>
#include<algorithm>

using namespace std;

#define MAXV 10
#define INF 100000000
int main(){

	int n;
	int v;
	int a,b,c;
	int d[MAXV][MAXV];
	int sum,ans,ans_i;

	while(1){

		cin>>n;
		if(n==0) break;

		for(int i=0;i<MAXV;i++){
			for(int j=0;j<MAXV;j++){
				if(i==j) d[i][j]=0;
				else d[i][j]=INF;
			}
		}

		v=-1;
		for(int i=0;i<n;i++){
			cin>>a>>b>>c;
			v=max(v,max(a,b));
			d[a][b]=c;
			d[b][a]=c;
		}

		for(int k=0;k<=v;k++){
			for(int i=0;i<=v;i++){
				for(int j=0;j<=v;j++){
					d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
				}
			}
		}

		ans=INF,ans_i=-1;
		for(int i=0;i<=v;i++){
			sum=0;
			for(int j=0;j<=v;j++){
				if(d[i][j]!=INF) sum+=d[i][j];
			}
			if(ans>sum&&sum!=0){
				ans=sum;
				ans_i=i;
			}
		}

		cout<<ans_i<<" "<<ans<<endl;

	}

}

Measured memory_bytes: 1160
using System;
using System.Linq;
using CompLib.Util;

public class Program
{
    private int H, W;
    private string[] S;

    private int[] Memo;

    public void Solve()
    {
        var sc = new Scanner();
        H = sc.NextInt();
        W = sc.NextInt();

        S = new string[H];
        for (int i = 0; i < H; i++)
        {
            S[i] = sc.Next();
        }

        // i->jに何回かかるか?
        Memo = new int[H * W];


        for (int i = 0; i < H * W; i++)
        {
            Memo[i] = -1;
        }

        Console.WriteLine(Search(0, 0) + (S[0][0] == '#' ? 1 : 0));
    }

    int Search(int y, int x)
    {
        if (y == H - 1 && x == W - 1) return 0;
        if (Memo[Conv(y, x)] != -1) return Memo[Conv(y, x)];
        // 下
        int res = int.MaxValue;
        if (y + 1 < H)
        {
            int d = Search(y + 1, x);
            if (S[y][x] == '.' && S[y + 1][x] == '#') d++;
            res = Math.Min(res, d);
        }

        if (x + 1 < W)
        {
            int r = Search(y, x + 1);
            if (S[y][x] == '.' && S[y][x + 1] == '#') r++;
            res = Math.Min(res, r);
        }

        Memo[Conv(y, x)] = res;
        return res;
    }

    int Conv(int y, int x) => y * W + x;


    public static void Main(string[] args) => new Program().Solve();
}

namespace CompLib.Util
{
    using System;
    using System.Linq;

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

Measured memory_bytes: 13268
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define ll long long 
#define FI first 
#define SE second
#define pb push_back 
#define eb emplace_back
#define mod 1000000007
#define all(c) (c).begin(),(c).end()
#define LB  lower_bound
#define UB  upper_bound
#define max3(a,b,c) max(c,max(a,b))
#define min3(a,b,c) min(c,min(a,b))
#define mems(s, n) memset(s, n, sizeof(s))
#define NINF INT_MIN 
#define INF INT_MAX 
#define MP make_pair
#define int ll int

typedef pair<int,int> PII;
typedef pair<pair<int,int>,int> PPII;
typedef map<int,int>MII;
typedef vector<int> VI;
const int MAX = 1e4 + 5;
template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

/*int power(int a, int b)
{int x=1,y=a;while(b>0){if(b%2){x =(x*y)%mod;}y =(y*y)%mod;b/=2;}return x%mod;}
*/
//int modInverse(int a, int m) {return power(a, m-2);} //gcd(a,m)=1 
//int root(int x){return x==f[x]?x:f[x]=root(f[x]);}
VI mr(10001,-1);VI dp(10001);int max1=0;vector<PII>ar;
int solve(int x)
{   if(x<=0)return 0;
      if(mr[x]==-1)
    {mr[x]=INF;
    for(auto it:ar)
    {
        mr[x]=min(it.SE+solve(x-it.FI),mr[x]);
    }
    }
    return mr[x];
    
}
signed main()
{
ios::sync_with_stdio(false); cin.tie(0);
int T=1,T1=0;//cin>>T;
while(T1++<T)
{
    int h,n;
    cin>>h>>n;
    ar.resize(n+1);
    for(int i=0;i<=n;i++){dp[i]=INT_MAX;mr[i]=-1;}
    for(int i=0;i<n;i++)
    {
        cin>>ar[i].FI>>ar[i].SE;max1=max(max1,ar[i].FI);
        dp[ar[i].FI]=min(dp[ar[i].FI],ar[i].SE);
    }
    dp[0]=0;
    mr[0]=0;
    cout<<solve(h)<<endl;
    
}


return 0;
}





Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int main(){
    int x,y,i,j;
    cin >> x >> y;
    while(x!=0 or y!=0){
        for(i=0;i<x;i++){
            for(j=0;j<y;j++){
                if((i+j)%2==0) cout << "#";
                else cout << ".";
            }
            cout << endl;
        }
        cout << endl;
        cin >> x >> y;
    }
    return 0;
}


Measured memory_bytes: 3068
# -*- coding: utf-8 -*-
n,t = map(int,input().split())
ans_cost = 10000
ans_time = t

for i in range(n):
    a,b = map(int,input().split())
    if b<=ans_time:
        if a<ans_cost:
            ans_cost = a


if ans_cost == 10000:
    print("TLE")
else:
     print(ans_cost)


Measured memory_bytes: 2940
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define pb push_back
#define pf push_front

namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

ll M = 1000000007;

int main()
{
	int n,k;
	cin>>n>>k;
	ll cnt=0;
	FOR(i,k+1,n+1){
		int tmp=i;
		int dis=tmp-k;
		while(1){
			if(tmp<=n){
				cnt+=dis;
			}else if(tmp-dis<=n){
				cnt+=n-(tmp-dis)+1;
				if(k==0){
					cnt--;
				}
			}
			else{
				break;
			}
			tmp+=i;
		}
	}
	cout<<cnt<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
#define pb push_back
#define pf push_front
#define eb emplace_back
using namespace std;
typedef long long ll;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}
template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;
using pi=pair<int,int>;
using vi=vc<int>;
void yes(){ cout << "Yes" << endl; }
void no(){ cout << "No" << endl; }
int SIZE(string s){return (int)s.size();}
const long long INF = 1LL << 60;

int main(){
    cout << fixed << setprecision(20);
    int k,a,b; cin >> k >> a >> b;
    rng(i,a,b+1){
        if(i % k == 0){
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG" << endl;
    return 0;
}


Measured memory_bytes: 3640
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>

using namespace std;
typedef long long ll;
int main() {
   int N;
   cin >> N;
   ll A[N];
   map<ll, ll> log;
   for (int i = 0; i < N; i++) {
      cin >> A[i];
      log[A[i]]++;
   }
   sort(A, A + N);
   int ans = 0;
   for (int i = N - 1; i >= 0; i--) {
      ll tmp = 1;
      if (log[A[i]] == 0) continue;
      log[A[i]]--;
      while (A[i] >= tmp) tmp *= 2;
      ll pair = tmp - A[i];
      if (log[pair] > 0) {
         ans++;
         log[pair]--;
      } 
   }
   cout << ans << endl;
   return 0;
}


Measured memory_bytes: 26752
//  Suraj Saste

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define pi pair<ll,ll>
#define mkp make_pair
#define in insert
#define fe first
#define se second
#define ms(x,i) memset(x,i,sizeof(x))
#define prec(x) cout<<std::setprecision(x)
#define mod 1000000007
#define all(x) x.begin(),x.end()
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
ll fpow(ll n, ll k, ll p=mod) {ll r=1; n=n%p; while(k>0){ if(k&1){ r=(r*n)%p; } k=k>>1; n=(n*n)%p; } return r;}
bool isPrime(ll n){ if(n<=1)return false;if(n<=3)return true;if(n%2==0 || n%3==0)return false;for(ll i=5;i*i<=n;i+=6){if(n%i==0||n%(i+2)==0)return false;}return true;}

int main()
{
	fast;
	ll n,k;cin>>n>>k;
	vector<bool> dp(k+1,false);
	ll a[n];
	for(ll i=0;i<n;i++)cin>>a[i];
	for(ll i=0;i<=k;i++)
	{
		for(ll j=0;j<n;j++)
		{
			if(i>=a[j]&&!dp[i-a[j]])
			{
				dp[i]=true;
			}
		}
	}
	if(dp[k])cout<<"First";
	else cout<<"Second";
	return 0;
}


Measured memory_bytes: 3684
def f(i, links, visited, nodes):
    t = 1 << i
    if t & visited != 0:
        return 0
    visited |= t
    if visited == (1 << nodes) - 1:
        return 1
    result = 0
    for j in links[i]:
        result += f(j, links, visited, nodes)
    return result


N, M = map(int, input().split())

links = [[] for _ in range(N)]
for _ in range(M):
    a, b = map(int, input().split())
    links[a - 1].append(b - 1)
    links[b - 1].append(a - 1)

result = 0
for i in links[0]:
    result += f(i, links, 1, N)
print(result)


Measured memory_bytes: 3064