akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <algorithm> 
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i,n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<"\n"
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define mp make_pair
#define sz(x) (ll)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using vc = vector<char>;
using vvc = vector<vc>;
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; 
}
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
int main(){
  ll x,k,d;
  cin>>x>>k>>d;
  if(x>0){
    ll cu=(x+d-1)/d;
    ll ne=x-cu*d;
    if(k<cu){
      COUT(abs(x-k*d));
    }
    else{
      k-=cu;
      if(k%2==1){
        COUT(abs(ne+d));
      }
      else{
        COUT(abs(ne));
      }
    }
  }
  else if(x==0){
    if(k%2==0) COUT(0);
    else{
      COUT(abs(d));
    }
  }
  else{
    ll cu=-(x-d+1)/d;
    ll ne=x+cu*d;
    if(k<cu){
      COUT(abs(x+k*d));
    }
    else{
      k-=cu;
      if(k%2==1){
        COUT(abs(ne-d));
      }
      else COUT(abs(ne));
    }
  }
}

Measured memory_bytes: 3632
a1,b1 = map(int,input().split())
a2,b2 = map(int,input().split())
a3,b3 = map(int,input().split())
a4,b4 = map(int,input().split())
a5,b5 = map(int,input().split())
a6,b6 = map(int,input().split())
a7,b7 = map(int,input().split())
print(a1-b1)
print(a2-b2)
print(a3-b3)
print(a4-b4)
print(a5-b5)
print(a6-b6)
print(a7-b7)


Measured memory_bytes: 5588
from collections import Counter
from collections import Counter
N, A, B = (list)(map(int, input().split()))
v = (list)(map(int, input().split()))

v = sorted(v, reverse=True)

sel_list = v[:A]
max_ave = sum(sel_list)/A
print(max_ave)

c = Counter(v)


def comb(n, r):
    r = min(r, n-r)
    ret = 1
    for i in range(r):
        ret *= (n-i)/(i+1)
    return ret


def ave_n(n):
    sel_list = v[:n]
    ave = sum(sel_list)/i
    if ave != max_ave:
        return 0
    last = sel_list[-1]
    use_last = sel_list.count(last)
    return comb(c[last], use_last)


ans = 0
for i in range(A, B+1):
    ret = ave_n(i)
    if ret == 0:
        break
    else:
        ans += ret
print((int)(ans))


Measured memory_bytes: 3316
using System;

namespace _3_2b
{
    class Program
    {
        static void Main(string[] args)
        {
            int piyo=0;
            string[] hoge=new string[100000];
            int[] nya = new int[100000];
            //Console.ReadLine();
            for (int i = 0; ; i++) {
                nya[i] = int.Parse(Console.ReadLine());
                if (nya[i]== 0)
                {
                    piyo = i;
                    break;
                }
                //Console.WriteLine("Case {0}: {1}", i, Console.ReadLine());//なんか毎行実行しちゃう→解決？たぶんifのReadLineが実行されて０がとばされ無限ループだった。
             
            }

            for(int j = 0; j<piyo; j++)//真ん中条件 int.Parse(hoge[j]) != 0だと無限ループフリーズの闇
            {
                Console.WriteLine("Case {0}: {1}", j+1, nya[j]);
            }

        }
    }
}



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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

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

const ll MOD = (ll)(1e9 + 7);

int f(ll x) {
  int k = 0;
  while (x > 0) {
    k++;
    x /= 10;
  }
  return k;
}


ll mod_pow(ll a, ll b, ll p) {
  ll res = 1;
  while (b > 0) {
    if (b & 1) res = (res * a) % p;
    a = (a * a) % p;
    b >>= 1;
  }
  return res;
}

// (10^n - 1) % MOD
ll nine(int n) {
  ll res = mod_pow(10, n-1, MOD);
  res = res * 9 % MOD;
  return res;
}

int main2() {
  ll S = nextInt();
  ll ans = 0;
  int l = 1;
  int r = 1;
  // [l, r]
  ll s = 0;
  while (l <= 9999999) {
    if (s == S) {
      ans++;
    }
    if (s < S) {
      s += f(r);
      r++;
    } else {
      s -= f(l);
      l++;
    }
  }
  ans %= MOD;

  for (int L = 1; L <= S; L++) {
    // 1種類
    if (S % L == 0) {
      const int v = S / L;
      if (v >= 8) {
        ans += ((nine(v) - L + 1) % MOD + MOD) % MOD;
        ans %= MOD;
      }
    }
    // 2種類
    if (L >= 2) {
      const int v = S / L;
      if (v >= 8 && S % L != 0) {
        ans++;
        ans %= MOD;
      }
    }
  }

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

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<string>
#include<cctype>
#include<cmath>
#include<queue>
#include<stack> 
#include<vector>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
//const int MAX_V=105;
const long long mod =1e9+7;


int main(){
  int A,B,C;
  cin >> A >> B >> C;
  if(A==B){
    cout << C << endl;
  }else if(B==C){
    cout << A << endl;
  }else if(C==A){
    cout << B << endl; 
  }

    return 0;
}
 

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

using namespace std;

typedef long long ll;

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    int N;
    cin >> N;
    vector <int> H(N);
    for (int i = 0; i < N; i++) {
        cin >> H[i];
    }
    int MaxH = 0;
    int Ans = 0;
    for (int i = 0; i < N; i++) {
        if (H[i] >= MaxH) {
            Ans++;
        }
        MaxH = max(MaxH, H[i]);
    }
    cout << Ans;
    return 0;
}



Measured memory_bytes: 256
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <functional>
#include <cassert>

#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll conbinationMemo[100][100];

void cmemoInit(){
    rep(i, 100){
        rep(j, 100){
            conbinationMemo[i][j] = -1;
        }
    }
}
 
ll nCr(ll n, ll r){
    if(conbinationMemo[n][r] != -1) return conbinationMemo[n][r];
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return conbinationMemo[n][r] = (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
//-----------------------ここから-----------
int main(void){
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    for(ll i = 0; i < n; i++){
        if(i >= k){
            if(a[i] > a[i - k]){
                cout << "Yes" << endl;
            } else {
                cout << "No" << endl;
            }
        }
    }
}



Measured memory_bytes: 4844
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Text;

public class Program
{

    public void Proc()
    {
        string inpt = Reader.ReadLine();
        int chokkaku = 0;
        int eikaku = 0;
        int donkaku = 0;
        while(inpt != null) {

            int[] numList = inpt.Split(' ').Select(a => int.Parse(a)).OrderByDescending(a=>a).ToArray();

            if(numList[0] >= numList[1] + numList[2]) {
                Console.WriteLine((chokkaku + eikaku + donkaku) + " " + chokkaku + " " + eikaku + " " + donkaku);
                return;
            }

            int sya = numList[0] * numList[0];
            int sonota = numList[1] * numList[1] + numList[2] * numList[2];

            if(sya > sonota) {
                donkaku++;
            } else if(sya < sonota) {
                eikaku++;
            } else {
                chokkaku++;
            }

            inpt = Reader.ReadLine();
        }
        Console.WriteLine((chokkaku + eikaku + donkaku) + " " + chokkaku + " " + eikaku + " " + donkaku);

    }




    public class Reader
    {
        static StringReader sr;
        public static bool IsDebug = false;
        public static string ReadLine()
        {
            if (IsDebug)
            {
                if (sr == null)
                {
                    sr = new StringReader(InputText.Trim());
                }
                return sr.ReadLine();
            }
            else
            {
                return Console.ReadLine();
            }
        }
        private static string InputText = @"



3 4 3
7 5 3
12 13 5
3 4 6
4 3 8
3 4 5


";
    }

    public static void Main(string[] args)
    {
#if DEBUG
        Reader.IsDebug = true;
#endif
        Program prg = new Program();
        prg.Proc();
    }
}


Measured memory_bytes: 10044
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<algorithm>
#include<cstdlib>
template<typename T>
void fin(T const& t){ std::cout << t << std::endl; exit(0); }

int main() {
  std::cin.tie(0); std::ios::sync_with_stdio(false);
  std::string S; std::cin >> S;
  int k = 0;
  for(int i = 0; i < S.size(); ++i) k ^= (1<<S[i]-'a');
  k -= (k&-k);
  if(k) fin(-1);
  std::map<char,int> n, c;
  for(char ch: S) ++n[ch];
  std::vector<int> left, right(S.size()/2);
  int mid = -1;
  std::map<char,std::vector<int>> p;
  for(int i = 0; i < S.size(); ++i) {
    char ch = S[i];
    ++c[ch];
    if(c[ch]*2 <= n[ch]) {
      p[ch].push_back(left.size());
      left.push_back(i);
    } else if(c[ch]*2 == n[ch]+1) mid = i;
    else {
      *(right.rbegin()+p[ch].back()) = i;
      p[ch].pop_back();
    }
  }
  
  if(mid >= 0) left.push_back(mid);
  left.insert(left.end(), right.begin(), right.end());
  
  auto merge_count = [](auto&& f, std::vector<int> &a)->int64_t {
    int n = a.size();
    if(n <= 1) return 0;
    int64_t res = 0, m = n/2;
    std::vector<int> b(a.begin(), a.begin()+m), c(a.begin()+m, a.end());
    res = f(f, b) + f(f, c);
    int ai = 0, bi = 0, ci = 0;
    while(ai < n) {
      if(bi < b.size() && (ci == c.size() || b[bi] <= c[ci])) a[ai++] = b[bi++];
      else {
        res += m - bi;
        a[ai++] = c[ci++];
      }
    }
    return res;
  };
  fin(merge_count(merge_count, left));
  return 0;
}


Measured memory_bytes: 3724
n,k=map(int, input().split())
r,s,p=map(int, input().split())
t=input()

ten=0
te=[]

for i in range(k):
    if t[i]=="r":
        ten+=p
        te.append("p")
    elif t[i]=="s":
        ten+=r
        te.append("r")
    elif t[i]=="p":
        ten+=s
        te.append("s")

for i in range(k,len(t)):
    if t[i]=="r" and te[i-k]=="p":
        te.append("a")
    elif t[i]=="s" and te[i-k]=="r":
        te.append("a")
    elif t[i]=="p" and te[i-k]=="s":
        te.append("a")
    else:
        if t[i]=="r":
            ten+=p
            te.append("p")
        elif t[i]=="s":
            ten+=r
            te.append("r")
        elif t[i]=="p":
            ten+=s
            te.append("s")

print(ten)

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

int main(){
    int N;
    cin >> N;
    int T, A;
    cin >> T >> A;
    int tmp;
    cin >> tmp;
    int tmp_tmp = 1000 * T - tmp * 6;
    int num = abs(tmp_tmp - A * 1000);
    int ans = 0;
    if(N > 1){
        for(int i = 1; i < N; i++){
            cin >> tmp;
            tmp_tmp = 1000 * T - tmp * 6;
            if(abs(tmp_tmp - A * 1000) < num){
                num = abs(tmp_tmp - A * 1000);
                ans = i;
            }
        }
    }
    cout << ans + 1 << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <complex>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <stack> 
#include <bitset>
#include <queue>
#include <assert.h>
#include <unordered_map>
using namespace std;

char s[10][10];

int main()
{
	int ans = 0;
	int n, m, p;
	scanf("%d%d%d", &n, &m, &p);
	for (int i = 0; i < n; i++)
		scanf("%s", s[i]);
	for (int i = 0; i < (1 << n); i++) {
		for (int j = 0; j < (1 << m); j++) {
			int tot = 0;
			for (int k = 0; k < n; k++) {
				if (i & (1 << k)) continue;
				for (int r = 0; r < m; r++) {
					if (j & (1 << r)) continue;
					if (s[k][r] == '#') tot++;
				}
			}
			if (tot == p) ans++;
		}
	}

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


Measured memory_bytes: 3224
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, K, X, Y = map(int, read().split())

    if N <= K:
        ans = X * N
    else:
        ans = X * K + (N - K) * Y

    print(ans)

    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 9180
from collections import defaultdict
from bisect import bisect_left
s = input()
t = input()

if not set(t) <= set(s):
    print(-1)
    exit()

inds = defaultdict(list)
inds_cnt = defaultdict(int)

for i in range(len(s)):
    inds[s[i]].append(i)
for i in range(97,97+26):
    inds_cnt[chr(i)] = len(inds[chr(i)])

k = 0
ans = 0
N = len(s)

for c in t:
    j = bisect_left(inds[c],k)
    if j == inds_cnt[c]:
        k = inds[c][0] + 1
        ans+=N
    else:
        k=inds[c][j] + 1
print(ans+k)



Measured memory_bytes: 52536
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef set<int> si;
typedef map<string, int> msi;
#define REP(i,a,b) \
for(int i=int(a);i<=int(b);i++)
#define DEP(i,a,b) \
for(int i=int(a);i>=int(b);i--)
#define TR(c, it) \
for (auto it = (c).begin(); it != (c).end(); it++)

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	int T;
	cin>>T;
	if(T%10==2||T%10==4||T%10==5||T%10==7||T%10==9)
      cout<<"hon";
  else if(T%10==0||T%10==1||T%10==6||T%10==8)
    cout<<"pon";
  else 
    cout<<"bon";
	return 0;
}


Measured memory_bytes: 3652
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
//#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
//#include<list>
#include<queue>
#include<deque>
#include<algorithm>
//#include<numeric>
#include<utility>
//#include<memory>
#include<functional>
#include<cassert>
#include<set>
#include<stack>
#include<random>

const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, -1, 0, 1};
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;

const ll INF = 1ll<<60;

pair<ll, ll> calc(ll T, ll A, ll t, ll a) {
    pair<ll, ll> ret(INF, INF);
    // t の方に合わせる
    {
        ll b = T/t;
        if (T%t) b++;
        ll nt = t*b;
        ll na = nt/t*a;
        if (nt >= T && na >= A) {
            ret.first = nt;
            ret.second = na;
        }
    }
    {
        ll b = A/a;
        if (A%a) b++;
        ll na = a*b;
        ll nt = na/a * t;
        if (nt >= T && na >= A) {
            ret = min(ret, pair<ll, ll>(nt, na));
        }
    }
    return ret;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    ll T = 1, A = 1;
    for (int i = 0; i < N; i++) {
        ll t, a;
        cin >> t >> a;
        auto p = calc(T, A, t, a);
        T = p.first, A = p.second;
    }
    cout << T+A << endl;
    return 0;
}


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

#define mod 1000000007

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

using namespace std;
typedef long long ll;
const long long INF = 1LL << 60;
 
int main(void){
	
	int A, B, K;
    cin >> A >> B >> K;

    int smaller = min(A, B);

    int count = 0;
    for(int i = smaller; i >= 1; i--){
        if(A % i == 0 && B % i == 0){
            count++;
            if(count == K){
                cout << i << endl;
                return 0;
            }
        }
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define lli long long int   //used int to avoid mle
#define ulli unsigned long long int 
#define ld long double
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define loop(i,a,b) for(lli i=a;i<b;i++)
#define initialize(array,size,value) for(lli i=0;i<size;i++) array[i]=value
#define couta(array,size) for(lli i=0;i<size;i++) cout<<array[i]<<" "
#define vl vector<lli>
#define vp vector< pair <lli,lli> >
#define sl set<lli>
#define spl set<pll>
#define msl multiset <lli>
#define msp multiset <pll>
#define pll pair<lli, lli>
#define mll map<lli, lli>              //for( map<lli, lli>::iterator i=temp.begin();i!=temp.end();i++)cout<<i->fi<<" "<<i->se<<endl;
#define mvl map<lli, vl>
#define umll unordered_map<lli, lli>
#define vt vector<pair<lli, pll >  >
#define vf vector<pair<pll,pll > >
#define qu queue<lli>
#define pq priority_queue<lli>
#define dq deque <lli>
#define ptr vector<lli>::iterator
#define bs(array,x) binary_search(array.begin(),array.end(),x)
#define lb(array,x) lower_bound(array.begin(),array.end(),x)
#define ub(array,x) upper_bound(array.begin(),array.end(),x)
#define nobw(array,i,j) upper_bound(array.begin(), array.end(), j)-lower_bound(array.begin(), array.end(), i) //number of numbers between i & j
#define vc clear()
#define endl '\n'
#define sp system("pause");
#define INF 9223372036854775807
#define MINF -9223372036854775808
#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); cerr << endl << "Time elapsed: " << (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms"; return 0
lli mod=1000000007;
//string s=bitset<32>(n).to_string();
string st1,st2;
lli ani1,ani2;
void nPermute(string str, long int n) 
{ 
    sort(str.begin(), str.end()); 
    long int i = 1; 
    do {
    	if(str==st1)ani1=i;
    	if(str==st2)ani2=i; 
       // if (i == n) 
         //   break; 
        i++; 
    }while(next_permutation(str.begin(), str.end())); 
    //cout << str; 
} 
lli fact(lli i){
	if(i==1)return 1;
	else return  (i*fact(i-1));
}
int main()
{
 	ios::sync_with_stdio(0);
    cin.tie(0);
    
	//string s;
	//s="123";
	//lli x;
    lli n;
    cin>>n;
    string s="";
    for(lli i=1;i<=n;i++){
    	s+=char(i+'0');
    }
    for(lli i=1;i<=n;i++){
    	lli x;
    	cin>>x;
    	st1+=char(x+'0');
    }
    
    for(lli i=1;i<=n;i++){
    	lli x;
    	cin>>x;
    	st2+=char(x+'0');
    }
	nPermute(s,fact(n));
	cout<<abs(ani1-ani2);


}

Measured memory_bytes: 256
from collections import deque

n,m = map(int,input().split())
ab = [list(map(int, input().split())) for _ in range(m)]
path = [[] for _ in range(n+1)]

for a,b in ab:
    path[a].append(b)
    path[b].append(a)

q = deque([1])
ans = [0] * (n+1)
while q:
    v = q.popleft()
    for w in path[v]:
        if ans[w] == 0:
            ans[w] = v
            q.append(w)

print('Yes')
print(*ans[2:], sep="\n")

Measured memory_bytes: 59460
/*  -*- coding: utf-8 -*-
 *
 * 2927.cc: Presents
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100000;
const int MAX_k = 17;

/* typedef */

typedef long long ll;

/* global variables */

ll dp[2][MAX_N + 1];

/* subroutines */

/* main */

int main() {
  int n, k;
  scanf("%d%d", &n, &k);

  if ((n >> (k - 1)) == 0) {
    puts("0");
    return 0;
  }

  fill(dp[0] + 1, dp[0] + n + 1, 1);
  int cur = 0, nxt = 1;

  for (int i = 1; i < k; i++) {
    memset(dp[nxt], 0, sizeof(dp[nxt]));
    int minj0 = 1 << (i - 1), maxj0 = n >> (k - i);
    int maxj1 = n >> (k - i - 1);

    for (int j = minj0; j <= maxj0; j++)
      for (int x = 2; j * x <= maxj1; x++)
	dp[nxt][j * x] += dp[cur][j];

    cur ^= 1, nxt ^= 1;
  }
  //for (int i = 1; i <= n; i++) printf("%lld ", dp[cur][i]); putchar('\n');

  ll sum = 0;
  for (int i = 1; i <= n; i++) sum += dp[cur][i];
  printf("%lld\n", sum);
  return 0;
}



Measured memory_bytes: 4792
# from collections import defaultdict
# N,M = list(map(int,input().split()))
# price_howmany = defaultdict(int)
import sys

stdin = sys.stdin

read_int = lambda : list(map(int,stdin.readline().split()))

N,M = read_int()
price_howmany = {}
price_list = []

for _ in range(N):
    tmp = read_int()
    price_list.append(tmp[0])
    if tmp[0] in price_howmany:
        price_howmany[tmp[0]] += tmp[1]
    else:
        price_howmany[tmp[0]] = tmp[1]
price_list = list(set(price_list))
price_list.sort()

def solve():
    price = 0
    global M
    for low_price in price_list:
        many = min(M,price_howmany.pop(low_price))
        price += many * low_price
        M -= many
        if M == 0: break
    print(price)

if __name__ == "__main__":
    solve()

Measured memory_bytes: 23172
cs = list(map(int,input().split()))
r = cs[0] + cs[1]
p = cs[2]

# 解毒剤のほうが多い
if r>=p:
    ans = cs[1] +  cs[2]
# 毒のほうが多い
else:
    ans = cs[1] + r + 1
print(ans)

Measured memory_bytes: 2940
#line 1 "/workspaces/compro/lib/template.hpp"


#line 1 "/workspaces/compro/lib/io/vector.hpp"
#include <iostream>
#include <vector>

#ifndef IO_VECTOR
#define IO_VECTOR

template <class T> std::ostream &operator<<(std::ostream &out, const std::vector<T> &v) {
  int size = v.size();
  for (int i = 0; i < size; i++) {
    std::cout << v[i];
    if (i != size - 1)
      std::cout << " ";
  }
  return out;
}

template <class T> std::istream &operator>>(std::istream &in, std::vector<T> &v) {
  for (auto &el : v) {
    std::cin >> el;
  }
  return in;
}

#endif
#line 4 "/workspaces/compro/lib/template.hpp"
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
#define MM << " " <<

using namespace std;

template <class T> void say(bool val, T yes, T no) { cout << (val ? yes : no) << "\n"; }

void say(bool val, string yes = "Yes", string no = "No") { say<string>(val, yes, no); }

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

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

// C++ 17に完全移行したら消す
// 最大公約数を求める
template <class T> T gcd(T n, T m) { return n ? gcd(m % n, n) : m; }

// 最小公倍数を求める
template <class T> T lcm(T n, T m) {
  int g = gcd(n, m);
  return n * m / g;
}

// 重複を消す。計算量はO(NlogN)
template <class T> void unique(std::vector<T> &v) {
  std::sort(v.begin(), v.end());
  v.erase(std::unique(v.begin(), v.end()), v.end());
}


#line 2 "abc174_a.cpp"

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

  int x;
  cin >> x;
  say(x >= 30);
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(x) ((x).begin()),((x).end())
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimization ("unroll-loops")
#define usecppio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using pii = pair<int, int>;
#define int ll
int mod = (ll)1e9+7;
ll modpow(ll x, ll y, ll p)
{
	ll res = 1;
	x = x % p;
	while (y > 0)
	{
		if (y & 1)
			res = (res*x) % p;
		y = y>>1;
		x = (x*x) % p;
	}
	return res;
}

int fact (int n)
{
	int f = 1;
	for (int i = 1; i<=n; i++)
	{
		f *= i;
		f %= mod;
	}
	return f;
}
int32_t main()
{
	int x, y;
	cin >> x >> y;
	int uu = x+y;
	if (uu%3)
	{
		cout << 0;
		return 0;
	}
	uu/=3;
	int b = x-uu, a = y-uu;
	if (a < 0 || b < 0)
	{
		cout << 0;
		return 0;
	}
	int fa = fact(a), fb = fact(b);
	int k = modpow(fa,mod-2,mod);
	int kk = modpow(fb, mod-2, mod);
	int fab = fact(a+b);
	int u = fab*k;
	u %= mod;
	u *= kk;
	u %= mod;
	cout << u << '\n';
}

Measured memory_bytes: 256
program abc156c
      implicit none
      integer::N,i,p
      integer(8)::sumX,sumA=100000000
      integer,allocatable,dimension(:)::X

      read *,N
      allocate(X(N))
      read *,X(1:N)

      do p=1,100
         sumX=0
         do i=1,N
            sumX=sumX+(X(i)-p)**2
         end do
         if (sumX<sumA) sumA=sumX
      end do
      print *,sumA
      stop

   end program abc156c

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

using namespace std;
#define ll long long
#define pb push_back
#define vi vector<int>
#define inf 1000000100

int main()
{
    int a, b;
    cin >> a >> b;
    if(a!= 1 && b!= 1)
    {
        if(a > b)
        {
            cout << "Alice" << endl;
        }
        else if (a < b)
        {
            cout << "Bob" << endl;
        }
        else
        {
            cout << "Draw" << endl;
        }
    }
    else
    {
        if(a == 1 && b != 1)
        {
            cout << "Alice" << endl;
        }
        else if (b == 1 && a != 1)
        {
            cout << "Bob" << endl;
        }
        else if (a == 1 && b == 1)
        {
            cout << "Draw" << endl;
        }
    }
}

Measured memory_bytes: 256
#define _USE_MAT_DEFINES
#include<iostream>
#include <iomanip>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include <queue>
#include <utility>
#include <map>
#include <set>
#include <deque>
#include <numeric>
#include <functional>
using namespace std;

int main() {
    int N;
    cin >> N;
    vector<vector<int>>A(2, vector<int>(N+1,0));
    for (int i = 0; i < 2; i++) {
        for (int j = 1; j <= N; j++) {
            cin >> A[i][j];
        }
    }

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

    int ans = 0;
    for (int i = 1; i <= N; i++) {
        int score = A[0][i] + A[1][N] - A[1][i - 1];
        ans = max(ans, score);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <stack>
using namespace std;

#define start first
#define end second

static const int NOT   = false;
static const int WHITE = 1;
static const int GRAY  = 2;
static const int BLACK = 3;
static const int N	   = 101;

int  n;
int  VisitedInfo[N];
bool Graph[N][N];
pair< int, int > Time[N];

void dfs( int u );
int  nextNode( int u );

int main()
{

	int u, k, v;

	for( int i = 0; i < N; i++ ) {
		for( int j = 0; j < N; j++ ) Graph[i][j] = NOT;
		VisitedInfo[i] = WHITE;
	}

	scanf( "%d", &n );
	for( int i = 0; i < n; i++ ) {
		
		scanf( "%d %d", &u, &k );
		for( int j = 0; j < k; j++ ) {

			scanf( "%d", &v );
			Graph[u][v] = true;

		}

	}

	dfs( 1 );

	for( int i = 1; i <= n; i++ ) printf( "%d %d %d\n", i, Time[i].start, Time[i].end );

	return 0;

}

void dfs( int u )
{

	int  time = 1, pos, ppos;
	bool brkUpNodeFlg = false;
	stack< int > dfsInfo;

	dfsInfo.push( u );
	Time[u].start  = time;
	VisitedInfo[u] = BLACK;

	while( !dfsInfo.empty() ) {

		ppos = dfsInfo.top();

		if( !brkUpNodeFlg ) pos = nextNode( ppos );

		brkUpNodeFlg = false;

		if( pos != 0 ) {
			if( VisitedInfo[pos] == WHITE ) {

				dfsInfo.push( pos );
				Time[pos].start  = ++time;
				VisitedInfo[pos] = BLACK;

			}
		}
		if( pos == 0 && VisitedInfo[ppos] != WHITE ){

			dfsInfo.pop();
			Time[ppos].end	  = ++time;
			VisitedInfo[ppos] = BLACK;


		}

		if( dfsInfo.empty() ) {
			for( int i = 1; i <= n; i++ ) {
				if( VisitedInfo[i] == WHITE ) {

					pos = i;
					dfsInfo.push( pos );
					Time[pos].start  = ++time;
					VisitedInfo[pos] = BLACK;
					brkUpNodeFlg     = true;
					break;

				}
			}
		}

	}

}

int nextNode( int now )
{

	for( int i = 1; i <= n; i++ ) {
		if( Graph[now][i] && VisitedInfo[i] == WHITE ) return i;
	}

	return 0;

}

Measured memory_bytes: 1044
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define len(x) ((long long)(x).size())
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using pll = pair<ll, ll>;
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U>bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U>bool isin(T el, U container) { return find(all(container), el) != container.end(); }
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; }
template<class T>bool even(T n) { return ! (n & 1); }
template<class T>bool odd(T n) { return n & 1; }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
ll intpow(ll a,ll n){ll p=1;while(n){if(n&1)p*=a;a*=a;n>>=1;}return p;}
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;

bool ok(ll x, ll y, ll z, ll n)
{
        return x*x + y*y + z*z + x*y + y*z + z*x == n;
}

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


        rep(i, 1, N+1) {
                ll lim = ceil(sqrt((ld)i / 6));
                ll ans = 0;
                rep(x, 1, inf) {
                        if (x*x > i) break;
                        rep(y, x, inf) {
                                if (y*y > i) break;
                                rep(z, y, inf) {
                                        if (z*z > i) break;
                                        ll tmp = x*x + y*y + z*z + x*y + y*z + z*x;
                                        if (x > lim+10 and tmp > i) goto e;
                                        if (tmp == i) {
                                                if (x == y and y == z and z == x) ++ans;
                                                else if (x != y and y != z and z != x) ans += 6;
                                                else ans += 3;
                                        }
                                }
                        }
                }
        e:
                printf("%lld\n", ans);
        }
}

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

#define maxn 200010
#define foru(i, l, r) for(int i = (l); i <= (r); ++i)
#define ford(i, l, r) for(int i = (l); i >= (r); --i)

int n;
ll k;
ll pre[maxn];
int fw[maxn];

void updatefw(int i) {
  for (; i < maxn; i += i & -i) fw[i]++;
}

int getfw(int i) {
  int ret = 0;
  for (; i > 0; i -= i & -i) ret = ret + fw[i];
  return ret;
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    /// PERSUBARR
    //freopen("PERSUBARR.inp", "r", stdin); freopen("PERSUBARR.out", "w", stdout);
    cin >> n >> k;
    ll ans = 0;
    vector<ll> com;
    com.push_back(0);
    for (int i = 1; i <= n; ++i) {
      ll x;
      cin >> x;
      x = x - k;
      pre[i] = pre[i-1] + x;
      com.push_back(pre[i]);
    }
    sort(com.begin(), com.end());

    for (int i = 0; i <= n; ++i) {
      pre[i] = lower_bound(com.begin(), com.end(), pre[i]) - com.begin() + 1;
    }
    updatefw(pre[0]);
    for (int i = 1; i <= n; ++i) {
      ans = ans + getfw(pre[i]);
      updatefw(pre[i]);
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 7356
A, B, C, K = map(int, input().split())
if A >= K:
    a = K
    b = 0
    c = 0
else:
    a = A
    if B >= K - a:
        b = K - a
        c = 0
    else:
        b = B
        c = K - a - b
print("{}".format(a-c))

Measured memory_bytes: 9196
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1e18+7;
const int inf=1e9+7;
using P=pair<int,int>;
vector<int> dx={0,1,-1,0};
vector<int> dy={1,0,0,-1};

vector<int> par(0),depth(0),siz(0);
void init(int n){
    par.resize(n);
    depth.resize(n,0);
    siz.resize(n,1);
    rep(i,n) par[i]=i;
}

int find(int n){
    if(par[n]==n) return n;
    return par[n]=find(par[n]);
}

void unite(int x,int y){
    x=find(x);
    y=find(y);
    if(par[x]==par[y]) return;
    siz[x]+=siz[y];
    siz[y]=siz[x];
    if(depth[x]<depth[y]) par[x]=par[y];
    else{
        par[y]=par[x];
        if(depth[x]==depth[y]) depth[x] ++;
    }
}

bool same(int x,int y){
    return find(x)==find(y);
}

int size(int x){
    return siz[find(x)];
}

int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cout << fixed << setprecision(10);
    int n,m;
    cin>>n>>m;
    int x,y,z;
    init(n);
    rep(i,m){
        cin>>x>>y>>z;
        x --,y --;
        unite(x,y);
    }
    rep(i,n) find(i);
    map<int,int> a;
    int cnt=0;
    rep(i,n){
        if(a[par[i]]==1) continue;
        a[par[i]]=1;
        cnt ++;
    }
    cout<<cnt<<endl;
}

Measured memory_bytes: 6144
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
using namespace std;

int main()
{
	int n;
	cin >> n;
	vector<char> s(n);
	for (int i = 0; i < n; i++) {
		cin >> s[i];
	}
	int sum = 0;
	for (int i = 1; i < n; i++) {
		if (s[i] == 'E') {
			sum++;
		}
	}
	int m = sum;
	for (int i = 1; i < n; i++) {
		if (s[i - 1] == 'E') {
			sum--;
		}
		if (s[i] == 'W') {
			sum++;
		}
		m = min(m, sum);
	}
	cout << m << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
#define fi first
#define se second
using namespace std;
typedef pair<int, int> P;

signed main(){
    int n;
    cin >> n;
    vector<int> a(n);
    int b4 = 0, b2 = 0, b = 0;
    rep(i, 0, n){
        cin >> a[i];
        if(a[i] % 4 == 0) b4++;
        else if(a[i] % 2 == 0) b2++;
        else b++;
    }
    bool f = false;
    if(b2 == 0){
        if(b4 >= b - 1) f = true;
    }else{
        if(b4 >= b) f = true;
    }
    cout << (f ? "Yes" : "No") << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef tuple<int,int, int> TP;
constexpr int INF = 2e9;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

int main(){ 
  int h, w;
  cin >> h >> w;
  int sx, sy, gx, gy;
  cin >> sx >> sy >> gx >> gy;
  sx--; sy--;
  gx--; gy--;

  vector<string> s(h);
  rep(i,h) cin >> s[i];

  vector<vector<int>> dp(h, vector<int>(w, INF));
  dp[sx][sy] = 0;

  priority_queue<P, vector<P>, greater<P>> que;
  que.push(make_pair(0, sx * w + sy));
  while (!que.empty()) {
    auto p = que.top(); que.pop();
    int cur = p.first;
    int i = p.second / w, j = p.second % w;
    if (dp[i][j] < cur) continue;

    for (int k = 0; k < 4; k++) {
      int x = i + dx[k], y = j + dy[k];
      if (x < 0 || y < 0 || x >= h || y >= w) continue;
      if (s[x][y] == '#') continue;
      if (dp[x][y] > cur) {
        dp[x][y] = cur;
        que.push(make_pair(cur, x * w + y));
      }
    }

    for (int a = -2; a <= 2; a++) {
      for (int b = -2; b <= 2; b++) {
        int x = i + a, y = j + b;
        if (x < 0 || y < 0 || x >= h || y >= w) continue;
        if (s[x][y] == '#') continue;
        if (dp[x][y] > cur + 1) {
          dp[x][y] = cur + 1;
          que.push(make_pair(cur + 1, x * w + y));
        }
      }
    }
  }
  cout << (dp[gx][gy] == INF ? -1 : dp[gx][gy]) << endl;
  return 0;
} 

Measured memory_bytes: 9492
#include <cassert>
#include <cstdio>
#include <functional>
#include <vector>

using namespace std;

#define int long long
#define dotimes(i, n) for (int i = 0, i##max__ = (n); i < i##max__; i++)
#define whole(f, x, ...) ([&](decltype((x)) c) { return (f)(begin(c), end(c), ## __VA_ARGS__); })(x)

int rint() {
  int x;
  scanf("%lld", &x);
  return x;
}

void wint(int x) {
  printf("%lld\n", x);
}

template<typename T> int size(T const& c) { return static_cast<int>(c.size()); }
template <typename T> bool maxs(T& a, T const& b) { return a < b ? a = b, true : false; }
template <typename T> bool mins(T& a, T const& b) { return a > b ? a = b, true : false; }
inline int lg(int x) { return 63 - __builtin_clzll(static_cast<unsigned int>(x)); }

signed main() {
  const int n = rint();
  vector<vector<int>> edges(n);
  dotimes(i, n)
    dotimes(j, rint())
      edges[i].emplace_back(rint());
  // doubling
  vector<pair<int, vector<int>>> p(n, pair<int, vector<int>>(0, vector<int>(lg(n - 1) + 1)));
  function<void(int, int)> rec;
  rec =
    [&](int u, int c) {
      for (int v : edges[u]) {
        p[v].first = c;
        p[v].second[0] = u;
        rec(v, c+1);
      }
    };
  rec(0, 1);
  dotimes(i, lg(n - 1))
    for (auto& pu : p)
      pu.second[i+1] = p[pu.second[i]].second[i];
  // query
  const int q = rint();
  dotimes(i, q) {
    int u = rint();
    int v = rint();
    if (p[u].first < p[v].first)
      swap(u, v);
    for (int j = 0, b = p[u].first - p[v].first; b; j++, b >>= 1)
      if (b & 1)
        u = p[u].second[j];
    assert(p[u].first == p[v].first);
    if (u == v) {
      wint(u);
      continue;
    }
    for (int j = lg(p[u].first); j >= 0; j--)
      if (p[u].second[j] != p[v].second[j]) {
        u = p[u].second[j];
        v = p[v].second[j];
      }
    assert(p[u].second[0] == p[v].second[0]);
    wint(p[u].second[0]);
  }
  return 0;
}



Measured memory_bytes: 32744
import bisect
import heapq
import math
import random
import sys
import collections
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub, or_

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1

def read_int():
    return int(input())

def read_int_n():
    return list(map(int, input().split()))

def read_float():
    return float(input())

def read_float_n():
    return list(map(float, input().split()))

def read_str():
    return input().strip()

def read_str_n():
    return list(map(str, input().split()))

def error_print(*args):
    print(*args, file=sys.stderr)

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

def main():
    n = read_int()
    f = factorization(n)
    count = 0
    for x in f:
        if x[0] == 1:
            continue
        lc = x[1]
        for i in range(1,INF):
            if i <= lc:
                lc = lc - i
                count+=1
            else:
                break
    print(count)

if __name__ == '__main__':
    main()

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

int main(){
  int N,W;
  cin >> N >> W;
  int w[N];
  int v[N];
  for(int i=0; i<N; i++){
    cin >> v[i] >> w[i];
  }

  int DP[N+1][W+1];

  for(int j=0; j<=W; j++){
    DP[0][j]=0;
  }

  for(int i=1; i<=N; i++){
    for(int j=0; j<=W; j++){
      if(j<w[i-1]){
        DP[i][j] = DP[i-1][j];
      }else{
        if(DP[i-1][j] > DP[i-1][j-w[i-1]]+v[i-1]){
          DP[i][j] = DP[i-1][j];
        }else{
          DP[i][j] = DP[i-1][j-w[i-1]]+v[i-1];
        }
      }
    }
  }

  cout << DP[N][W] << endl;

  return 0;
}


Measured memory_bytes: 6992
#include "bits/stdc++.h"
#include <set>

using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()
#define int long long
#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
#define mod 1000000007
#define INF 10e10
template <typename T>

void print(T x)
{
	std::cout << x << " ";
}

template <typename T>

void println(T x)
{
	std::cout << x << "\n";
}

bool compare_by_b(pair<int, int> a, pair<int, int> b) {
	if (a.second != b.second) {
		return a.second < b.second;
	}
	else {
		return a.first < b.first;
	}
}

signed main(void) {
	int h, w;
	char c[101][101];
	cin >> h >> w;
	rep(i, h) {
		rep(j, w) {
			cin >> c[i][j];
		}
	}
	rep(i, h) {
		rep(k, 2) {
			rep(j, w) {
				cout << c[i][j];
			}
			cout << ""<< endl;
		}
	}
}

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

#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for (int i = (n); i >= 0; i--)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

int main()
{
    int r, d, x;
    cin >> r >> d >> x;

    for (int i = 1; i <= 10; i++)
    {
        x = r * x - d;
        OP(x);
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=100010;
const ll mod=1e9+7;

int main(){
  vector<int> a(3);
  cin >> a[0] >> a[1] >> a[2];
  sort(a.begin(),a.end());
  if(a[0]==5&&a[1]==5&&a[2]==7){
    cout<<"YES"<<endl; return 0;
  }
  
  cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 256
use std::io::Read;
use std::collections::VecDeque;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).ok();
    let mut it = buf.split_whitespace();
    let h = it.next().unwrap().parse::<usize>().unwrap();
    let w = it.next().unwrap().parse::<usize>().unwrap();
    let s = (0..h).map(|_| it.next().unwrap().as_bytes()).collect::<Vec<_>>();
    let mut qu = VecDeque::new();
    let mut step = vec![vec![h*w; w]; h];
    let mut res = 0;
    for i in 0..h {
        for j in 0..w {
            if s[i][j] == b'#' {
                step[i][j] = 0;
                qu.push_back((i, j));
            }
        }
    }
    while !qu.is_empty() {
        let (x, y) = qu.pop_front().unwrap();
        res = step[x][y];
        for &(dx, dy) in [(1, 0), (0, 1), (!0, 0), (0, !0)].iter() {
            let nx = x.wrapping_add(dx);
            let ny = y.wrapping_add(dy);
            if nx >= h || ny >= w { continue }
            if step[nx][ny] <= step[x][y] + 1 { continue }
            step[nx][ny] = step[x][y] + 1;
            qu.push_back((nx, ny));
        }
    }
    println!("{}", res);
}


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second

typedef long long ll;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pii;

void Main()
{
	int n;
	cin >> n;
	cout << "ABC" << n << endl;  
	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds;   
#define ll long long
#define ull unsigned long long
// #define ordered_set tree<pair<ll, ll>, null_type, less<pair<ll, ll>>, rb_tree_tag, tree_order_statistics_node_update> 
ll mod=1e9+7;
#define PI 3.1415926535897932385
#define inf 9e18
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
typedef pair<long long, long long> ii;
#define S second
#define F first
ll max(ll a,ll b){if(a>b){return a;}return b;}
ll min(ll a,ll b){if(a<b){return a;}return b;}
#define MAXN 200005
// Comment this out for interactice problem
// #define endl '\n'
// string to integer stoi() Remember: it takes string not character
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
 
// To compile--> g++ -std=c++0x -o output one.cpp
// To run--> ./output

int main()
{ 
    fastio;
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);

    ll n;
    cin>>n;
    ll a[n];
    ll sum=0;
    for (int i = 0; i < n; ++i)
    {
        cin>>a[i];
        sum+=a[i];
    }

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

    for (int i = 0; i < n; ++i)
    {
        dp[i][i]=a[i];
    }
    for (int i = 0; i < n-1; ++i)
    {
        dp[i][i+1]=max(a[i], a[i+1]);
    }

    for (int l = 2; l<=n; ++l)
    {
        for (int i = 0; i < n-l+1; ++i)
        {
            ll j = i+l;
            dp[i][j] = max(a[i]+min(dp[i+2][j], dp[i+1][j-1]), a[j]+min(dp[i+1][j-1], dp[i][j-2]));
        }
    }

    ll x = dp[0][n-1];
    ll y = sum-x;
    cout<<x-y;

    return 0;
}


Measured memory_bytes: 73948
#include <iostream>
#include <vector>
using namespace std;
int main(){
    int N, M;
    cin >> N >> M;
    vector<int> cnt(M);
    for(int i =0 ; i < N; i++){
        int K;
        cin >> K;
        for(int i = 0; i < K; i++){
            int a;
            cin >> a;
            a--;
            cnt[a]++;
        }
    }
    int ans = 0;
    for(int i = 0; i < M; i++){
        if(cnt[i] == N) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
 
int main () {
    long long K;
    cin >> K;
    long long    res;
    queue<long long> q;
    for(int i = 1; i<=9; i++) q.push(i);
    for(int i = 0; i<K; i++) {
        res = q.front();
        if(res % 10 != 0) q.push(10 * res + (res % 10) - 1);
        q.push(10 * res + ( res % 10));
        if(res % 10 != 9) q.push(10 * res + (res % 10) + 1);
        q.pop();
    } 
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 1792