akhauriyash/Code-Regression huggingface dataset:
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string>
#define rp(i,a,b) for(int (i)=(int)(a);i<(int)(b);++i)
 
using namespace std;
 
typedef long long ll;


int main(){
    int N;
    vector<int> a;
    cin>>N;
    rp(i,0,N){int A;cin>>A;a.push_back(A);}     


    vector<int> k(N+1);
    sort(a.begin(),a.end());
    int h;
    if(a[N-1]%2==0){
        h=a[N-1]/2;
    }
    else{
        h=(a[N-1]+1)/2;
    }
    int c=0;
    for(int i=0;i<N;i++){
        k[a[i]]++;
        if(a[i]<h){
            cout<<"Impossible"<<endl;
            return 0;
        }
    }
    for(int i=h+1; i<=a[N-1];i++){
        if(k[i]<2) {
            cout<<"Impossible"<<endl;
            return 0;
        }
    }

    if(a[N-1]%2==0){
        if (k[h]!=1) cout<<"Impossible"<<endl;
        else cout<<"Possible"<<endl;
    }
    else{
        if (k[h]!=2) cout<<"Impossible"<<endl;
        else cout<<"Possible"<<endl;

    }

        return 0;
};


Measured memory_bytes: 256
use std::io;
use std::cmp;

fn read_line() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).expect("failed to read a line");
    buf
}

fn is_dualstring(s: &str) -> bool {
    match s.len() & 1 {
        0 => {
            let sublen = s.len() / 2;
//            println!("compare {} and {}", &s[..sublen], &s[sublen..]);
            s[..sublen] == s[sublen..]
        },
        _ => false,
    }
}

fn main() {
    let line = read_line();
    let line = line.trim();
    let n = line.len();
    let end_ptr = (1..n).filter(|&p| is_dualstring(&line[..p])).fold(0, |a, b: usize| cmp::max(a, b));
    println!("{}", end_ptr);
}


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

int main() {
    int n,k;
    cin >> n >> k;
    vector<int> l(n);
    rep(i,n) cin >> l[i];
    sort(all(l),greater<int>());
    int ans = 0;
    rep(i,k) ans += l[i];
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define IFOR(i, m, n) for(int i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
const int MOD = 1000000007;
/* テンプレートここまで */

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

  int cur = 0;
  ll ans = 1;
  //prev = 1 : ひとつ前が縦棒，　2:横棒
  int prev = 1;

  while(cur < N){
    // 縦棒
    if(S[cur] == T[cur]){
      if(cur == 0){
        ans *= 3;
      } else {
        ans *= prev == 1 ? 2 : 1;
        ans %= MOD;
      }
      prev = 1;
      cur++;
    }else{
    //横棒
      if(cur == 0){
        ans *= 6;
      }else{
        ans *= prev == 1 ? 2 : 3;
        ans %= MOD;
      }
      prev = 2;
      cur += 2;
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
  int  a, b, i, j;
  char  p[100][101];
 
  scanf("%d %d", &a, &b);
 int w = b+2;
  for(i=0; i<a; i++) {
    scanf("%s", &p[i][0]);
  }
 
  for(j=0; j<w; j++){
    printf("#");
  }
  printf("\n");
  for(i=0; i<a; i++) {
    printf("#%s#\n", p[i]);
  }
  for(j=0; j<w; j++){
    printf("#");
  }
  printf("\n");
 
  return 0;
}

Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = "";

		int[] occur = new int[100];
		int max = 0;

		Arrays.fill(occur, 0);

		while ((line = br.readLine()) != null) {
			int i = Integer.parseInt(line);
			int j = occur[i - 1] += 1;
			max = j > max ? j : max;
		}
		for (int i = 0; i < 100; i++) {
			if (occur[i] == max)
				System.out.println(i + 1);
		}
	}
}

Measured memory_bytes: 16872
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define SORT(v) sort(v.begin(), v.end());
#define RSORT(v) sort(v.rbegin(), v.rend());
#define REVERSE(v) reverse(v.begin(), v.end());

template <typename T>
void printlnVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << endl;
  }
}

template <typename T>
void printVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << " ";
  }
  cout << endl;
}

int main()
{
  int K;
  cin >> K;
  set<long long> ans;
  ans.insert(1);
  ans.insert(2);
  ans.insert(3);
  ans.insert(4);
  ans.insert(5);
  ans.insert(6);
  ans.insert(7);
  ans.insert(8);
  ans.insert(9);

  while (ans.size() < K)
  {
    set<long long> temp = ans;
    for (long long s : temp)
    {
      long long back = s % 10;
      if (back == 0)
      {
        ans.insert(10 * s);
        ans.insert(10 * s + 1);
      }
      else if (back == 9)
      {
        ans.insert(10 * s + 8);
        ans.insert(10 * s + 9);
      }
      else
      {
        long long b1 = back - 1, b2 = back + 1;
        ans.insert(10 * s + b1);
        ans.insert(10 * s + back);
        ans.insert(10 * s + b2);
      }

      if (ans.size() >= K)
        break;
    }
  }

  int count = 0;
  for (long long n : ans)
  {
    count++;
    if (count == K)
    {
      cout << n << endl;
      return 0;
    }
  }
  return 0;
}

Measured memory_bytes: 8192
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <climits>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <cassert>
#include <unordered_map>

#define _(x) { cout << #x << " = " << x << " "; }

const double E = 1e-8;
const double PI = acos(-1);

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    string s;
    cin >> n >> s;
    int ans = 0;
    for (int i = 0; i < n-2;++i)
        if (s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C') ans++;

    cout << ans << '\n';
    return 0;
}



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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<vector<ll>> VV;
typedef vector<vector<int>> VVi;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF=1e18+18;
const ll MAX=100005;
const ll MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n,m,arr) rep(i,n){rep(j,m){cerr<<arr[i][j]<<" ";}cerr<<endl;}
#define dbgdp(n,arr) rep(i,n){cerr<<arr[i]<<" ";}cerr<<endl;
#define sum(v) accumulate(ALL(v),0)
#define fi first
#define se second

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

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

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<" ";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

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

    ll n,k,s;
    cin>>n>>k>>s;
    for(ll i=0; i<k; i++) {
        cout<<s<<" ";
    }
    if(s != 1){
        for(ll i=k; i<n; i++) {
            cout<<s-1<<" ";
        }
    }else{
        for(ll i=k; i<n; i++) {
            cout<<s+1<<" ";
        }
    }
    cout<<endl;
    return  0;
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll mod = 1000000007;
vector<ll> dp,h;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,k;
    cin>>n>>k;
    h.resize(n,0);
    dp.resize(n,INT_MAX);
    for(int i=0;i<n;i++)
        cin>>h[i];
    dp[0] = 0;
    for(int i=1;i<n;i++)
    {
        for(int j=1;j<=k;j++)
        {
            if(i-j >= 0)
            {
                dp[i] = min(dp[i], dp[i-j]+abs(h[i]-h[i-j]));
            }
        }
    }
    cout<<dp[n-1];
    
}

Measured memory_bytes: 1792
import math

r = 50001
sqrt = int(math.sqrt(r))
p = [1]*r
p[0] = 0
for i in range(1,sqrt):
    if p[i]:
        p[2*i+1::i+1] = [0 for x in range(2*i+1,r,i+1)]

prime = []
for i in range(len(p)):
    if p[i] == 1:
        prime.append(i+1)

while True:
    n = int(raw_input())
    if n == 0:
        break
    count = 0
    for i in prime:
        if i > n/2:
            break
        m = n - i
        if p[m-1] == 1:
                count += 1
    print count

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

using namespace std;

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

    cout << ans << endl;
    return 0;

    
}


Measured memory_bytes: 384
#include<cstdio>
#include<cctype>
#include<cstring>
#include<ctime>
#include<cstdlib>
#include<algorithm>
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define reg register
typedef long long ll;
template<typename T>inline T read(){
    reg T x=0;reg short f=1;reg char c=getchar();
    for(;!isdigit(c);f=c=='-'?-1:1,c=getchar());
    for(;isdigit(c);x=x*10+(c^48),c=getchar());
    return x*f;
}
#define mid (lt+rt>>1)
#define len (rt-mid-1)
char ch[10];
bool sex[100005];
//Male := 1
//Female := 0
inline void update(int id){
	printf("%d\n",id);fflush(stdout);scanf("%s",ch);
	if(ch[0]=='V')exit(0);sex[id]=(ch[0]=='M');
}
int main(){
	reg int n=read<int>(),lt=0,rt=n-1,pres,sufs;
	update(0);update(rt);
	while(rt-lt>1){
		update(mid);
		if(len&1)(sex[rt]==sex[mid])?rt=mid:lt=mid;
		else (sex[rt]!=sex[mid])?rt=mid:lt=mid;
	}
	return 0;
}

Measured memory_bytes: 852
n = int(input())
coordinate_list = []
t_init = 0
x_init = 0
y_init = 0
count = 0

for i in range(n):
    child_list = list(map(int, input().split()))
    coordinate_list.append(child_list)

for coordinate in coordinate_list:
    flag = True
    t, x, y = coordinate[0], coordinate[1], coordinate[2]
    t -= t_init
    x -= x_init
    y -= y_init
    t_init, x_init, y_init = coordinate[0], coordinate[1], coordinate[2]
    if t >= abs(x) + abs(y):
        if t % 2 == 0 and x % 2 == 0 and y % 2 == 0 or t % 2 == 0 and x % 2 == 1 and y % 2 == 1:
            flag = False
        elif t % 2 == 1 and x % 2 == 1 and y % 2 == 0 or t % 2 == 1 and x % 2 == 0 and y % 2 == 1:
            flag = False
    
    if flag:
        break
    count += 1

if n == count:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 27380
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<string>
#include<math.h>
#include<stdlib.h>
#include<time.h>
#include<map>
#include<queue>
#include<set>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
int n;
int main(){
	scanf("%d",&n);
	if (n%10==9||n/10==9) printf("Yes\n");else printf("No\n");
	return 0;
}

Measured memory_bytes: 128
// Crt. 2020-01-13  08:35:28
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#define N 100005
using namespace std;

int n, m, a[N], b[N], cnt;

inline bool cmp(int x, int y) {
    return x % 2 > y % 2;
}

int main() {
#ifdef LOCAL_JUDGE
    freopen(".in", "r", stdin);
    freopen(".out", "w", stdout);
#endif

    cin >> n >> m;
    for (int i = 1; i <= m; ++i)
        scanf("%d", a + i);

    if (m == 1) {
        if (a[1] == 1) cout << 1 << endl << 1 << endl << 1 << endl;
        else cout << a[1] << endl << 2 << endl << max(1, a[1] - 1) << " " << 1 << endl;
        return 0;
    }

    if (m == 2) {
        if (a[1] > a[2]) swap(a[1], a[2]);
        if (a[2] == 1) cout << a[1] << " " << a[2] << endl << 1 << endl << 2 << endl;
        else cout << a[1] << " " << a[2] << " " << endl << 2 << endl << a[1] + 1 << " " << a[2] - 1 << endl;
        return 0;
    }

    sort(a + 1, a + m + 1, cmp);

    int pos = 0;
    while (pos < m && a[pos + 1] % 2) ++pos;

    if (pos > 2) return puts("Impossible"), 0;

    if (pos == 2) swap(a[pos], a[m]);

    for (int i = 1; i <= m; ++i)
        printf("%d ", a[i]);
    puts("");

    if (a[1] == 1) b[++cnt] = a[2];
    else b[++cnt] = a[1] - 1, b[++cnt] = a[2];

    for (int i = 3; i < m; ++i)
        b[++cnt] = a[i];

    b[++cnt] = a[m] + 1;

    cout <<cnt << endl;
    for (int i = 1; i <= cnt; ++i)
        printf("%d ", b[i]);

	return 0;
}


Measured memory_bytes: 256
local mfl, mce = math.floor, math.ceil
local n = io.read("*n")
local a = {}
for i = 1, n do
  a[i] = io.read("*n")
end
local xor = 0
for i = 3, n do
  xor = xor ~ a[i]
end
local sum = a[1] + a[2]
if sum < xor then
  print(-1)
  os.exit()
end
local b_xor, b_sum = {}, {}
while 0 < sum do
  table.insert(b_sum, sum % 2)
  table.insert(b_xor, xor % 2)
  sum = mfl(sum / 2)
  xor = mfl(xor / 2)
end
local dig = #b_sum
local moveup = false
local state = {}
for i = 1, dig do state[i] = 0 end
-- state of bit of a[1] and a[2]
-- 1: [0, 0], 2: [1, 1], 3: [0, 1] or [1, 0]
for idig = dig, 1, -1 do
  if b_sum[idig] == 1 then
    if b_xor[idig] == 1 then
      if moveup then
        print(-1)
        os.exit()
      else
        state[idig] = 3
      end
    else
      if moveup then
        state[idig] = 2
      else
        state[idig] = 1
      end
      moveup = true
    end
  else-- sum = 0
    if b_xor[idig] == 1 then
      if moveup then
        state[idig] = 3
      else
        print(-1)
        os.exit()
      end
    else
      if moveup then
        state[idig] = 2
      else
        state[idig] = 1
      end
      moveup = false
    end
  end
end
if moveup then print(-1) os.exit() end
local alim = {}
do
  local tmp = a[1]
  for i = 1, dig do
    alim[i] = tmp % 2
    tmp = mfl(tmp / 2)
  end
end
local tbl = {}
for i = 1, dig do tbl[i] = 0 end

local function dfs(idig, limit)
  if idig == 0 then return true end
  if limit then
    if alim[idig] == 0 then
      if state[idig] == 2 then
        return false
      else
        tbl[idig] = 0
        return dfs(idig - 1, true)
      end
    else
      if state[idig] == 2 then
        tbl[idig] = 1
        return dfs(idig - 1, true)
      elseif state[idig] == 1 then
        tbl[idig] = 0
        return dfs(idig - 1, false)
      else
        tbl[idig] = 1
        local ret = dfs(idig - 1, true)
        if ret then
          return true
        else
          tbl[idig] = 0
          return dfs(idig - 1, false)
        end
      end
    end
  else
    if state[idig] == 1 then
      tbl[idig] = 0
      return dfs(idig - 1, false)
    else
      tbl[idig] = 1
      return dfs(idig - 1, false)
    end
  end
end

local ret = dfs(dig, true)
if not ret then
  print(-1)
  os.exit()
end
local ans = 0
local mul = 1
for i = 1, dig do
  ans = ans + mul * tbl[i]
  mul = mul * 2
end
if ans == 0 then
  print(-1)
else
  print(a[1] - ans)
end


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

#define ALL(obj) (obj).begin(),(obj).end()
#define SPEED cin.tie(0);ios::sync_with_stdio(false);

template<class T> using PQ = priority_queue<T>;
template<class T> using PQR = priority_queue<T,vector<T>,greater<T>>;

constexpr long long MOD = (long long)1e9 + 7;
constexpr long long MOD2 = 998244353;
constexpr long long HIGHINF = (long long)1e18;
constexpr long long LOWINF = (long long)1e15;
constexpr long double PI = 3.1415926535897932384626433L;

template <class T> vector<T> multivector(size_t N,T init){return vector<T>(N,init);}
template <class... T> auto multivector(size_t N,T... t){return vector<decltype(multivector(t...))>(N,multivector(t...));}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;}
void print(void) {cout << endl;}
template <class Head> void print(Head&& head) {cout << head;print();}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);}
template <class T> void chmax(T& a, const T b){a=max(a,b);}
template <class T> void chmin(T& a, const T b){a=min(a,b);}
void YN(bool flg) {cout << (flg ? "YES" : "NO") << endl;}
void Yn(bool flg) {cout << (flg ? "Yes" : "No") << endl;}
void yn(bool flg) {cout << (flg ? "yes" : "no") << endl;}

int main() {
    int H,W,K; cin >> H >> W >> K;
    vector<string> C(H);
    for(int i = 0; i < H; ++i) cin >> C[i];
    int ans = 0;
    for(int i = 0; i < (1<<H); ++i) {
        for(int j = 0; j < (1<<W); ++j) {
            auto D = C;
            for(int k = 0; k < H; ++k) {
                if(i&(1<<k)) continue;
                for(int l = 0; l < W; ++l) {
                    D[k][l]='@';
                }
            }
            for(int k = 0; k < W; ++k) {
                if(j&(1<<k)) continue;
                for(int l = 0; l < H; ++l) {
                    D[l][k]='@';
                }
            }
            int cnt = 0;
            for(int k = 0; k < H; ++k) {
                for(int l = 0; l < W; ++l) {
                    if(D[k][l]=='#') cnt++;
                }
            }
            ans += (cnt==K);
        }
    }
    cout << ans << endl;

    return 0;
}


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

int main(){

	int m,n,sum=0; cin >>n >>m;
	int a[n];
	for(int i =0;i<n;i++) {cin >> a[i];sum+=a[i];}
	sort(a,a+n);
	if(a[n-m] >=(1.0*sum)/(4*m)) cout << "Yes" ;
	else cout << "No";

	
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>
#include<queue>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	Int H, W, K;
	cin >> H >> W >> K;

	vector<vector<char>> s(H, vector<char>(W));

	char temp;
	for (Int i = 0; i < H; i++) {
		for (Int j = 0; j < W; j++) {
			cin >> temp;
			s[i][j] = temp;
		}
	}

	vector<vector<Int>> ans(H, vector<Int>(W));

	Int cnt = 1;
	Int flag;
	Int flag2 = 0;//既にイチゴが出ていれば1
	for (Int i = 0; i < H; i++) {

		if (flag2) {
			flag = 0;//行の中にイチゴが出てこれば1
			for (Int j = 0; j < W; j++) {
				if (flag == 0) {
					if (s[i][j] == '.') {
						ans[i][j] = cnt;
					}
					else {
						flag = 1;
						ans[i][j] = cnt;
					}
				}
				else {
					if (s[i][j] == '.') {
						ans[i][j] = cnt;
					}
					else {
						cnt++;
						ans[i][j] = cnt;
					}
				}
			}

			if (flag) {//もしその行にイチゴが一個でも出てこれば
				cnt++;
			}
			else {//イチゴが行に一個もないと前の行に合わせる
				for (Int j = 0; j < W; j++) {
					ans[i][j] = ans[i - 1][j];
				}
			}
		}
		else {//まだ一回もイチゴが出てきていない時
			for (Int j = 0; j < W; j++) {
				if (flag2 == 0&&s[i][j]=='.') {
					continue;
				}
				else if (flag2==0&&s[i][j]=='#') {
					flag2 = 1;
					for (Int k = 0; k <= j; k++) {
						ans[i][k] = cnt;
					}
				}
				else if (s[i][j] == '.') {
					ans[i][j] = cnt;
				}
				else {
					cnt++;
					ans[i][j] = cnt;
				}

			}

			if (flag2) {
				for (Int j = 0; j < W; j++) {
					for (Int k = i - 1; k >= 0; k--) {
						ans[k][j] = ans[i][j];
					}

				}
				cnt++;
			}

		}
	}

	for (Int i = 0; i < H; i++) {
		for (Int j = 0; j < W; j++) {
			cout << ans[i][j] << " ";
		}
		cout << "\n";
	}

}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const long long INF = 1LL<<60;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP2(i,m,n) for(int i=m;i<n;i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
static const double pi = 3.141592653589793;

int main(){
    int n,m;
    cin >> n>>m;
    int a,b;

    map<int,set<int>> mp;  

    REP(i,m){
        cin >>a>>b;
        mp[a].insert(b);
        mp[b].insert(a);
    }
    int ans[n+1]={};
    set<int> finish={1};
    queue<int> q1,q2;
    
    auto itr = mp[1].begin();
    REP(i,mp[1].size()){
        
        q1.push(*itr);
        ans[*itr]=1;
        finish.insert(*itr);
        ++itr;
    }
    
    
    
    do{
       
        int tmp=q1.front();
        // cout<<"pa "<< tmp<<endl;
        q1.pop();
        auto itr2 = mp[tmp].begin();
        REP(i,mp[tmp].size()){
            if(finish.count(*itr2)==0){
                // cout<<*itr2<<endl;
                q2.push(*itr2);
                ans[*itr2]=tmp;
                finish.insert(*itr2);
                
            }
            
            
            ++itr2;
        }

         if(q1.empty()){
            q1.swap(q2);
            // cout<<"wagi"<<endl;
        }

    }while(!(q1.empty()));


    bool flag=true;
    REP2(i,1,n){
        if(finish.count(i)==0){
            flag=false;
            break;
        }
    }
    if(flag){
        
        cout<<"Yes"<<endl;
        REP2(i,2,n+1){
           
            cout<<ans[i]<<endl;
        }
    }else{
         cout<<"No"<<endl;
    }
   
}

Measured memory_bytes: 37128
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

use std::collections::HashMap;

fn main() {
    let n: usize = read();
    let mut a: Vec<usize> = vec![];
    let mut sum: usize = 0;

    for _ in 0..n {
        let ai: usize = read();
        if ai % 10 != 0 {
            a.push(ai);
        }
        sum += ai;
    }
    a.sort();

    if sum % 10 == 0 {
        if a.len() == 0 {
            println!("0");
        } else {
            println!("{}", sum - a[0]);
        }
    } else {
        println!("{}", sum);
    }
}


Measured memory_bytes: 4352
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int ans = 0;
		int rem = 10;
		for (int i = 0; i < 5; i++) {
			int b = sc.nextInt();
			if(b%10==0) {
				ans += b;
			}else {
				ans += (b/10+1)*10;
				rem = Math.min(rem,b-b/10*10);
			}
		}
		System.out.println((rem==10)?ans:ans-(10-rem));
		sc.close();
	}
}

Measured memory_bytes: 22228
import sys

stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

n = ni()
li = na()
ans = float("inf")
for j in range(-100, 101):
    ct = 0
    for i in range(n):
        ct += (li[i] - j) ** 2
    ans = min(ans, ct)
print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
    
int main() {
  long long N;
  cin >> N;
  
  vector<long long> V(N);
  for (long long i = 0; i < N; i++)
    cin >> V.at(i);
   
  vector<long long> W(N,0);
  for (long long j = 0; j < N; j++)
    W.at(V.at(j) - 1)++;
  
  vector<long long> X(N);
  for (long long k = 0; k < N; k++)
    X.at(k) = W.at(V.at(k) - 1);
  
  long long sum = 0;
  for (long long l = 0; l < N; l++)
    sum += W.at(l)*(W.at(l) - 1)/2;
  
  for (long long m = 0; m < N; m++)
    cout << sum - X.at(m) + 1 << endl;
    
    
    
}


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

using namespace std;

int main(){
	long long int M, N; cin >> N >> M;
	long long int sum = 0, n;
	while(M--){
		cin >> n;
		sum += n;
		if(sum > N){
			cout << -1;
			return 0;
		}
	}
	cout << N - sum;	
	return 0;
}


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


int main(){
	int ctr[4] = {};
	
	for(int i=0; i<6; i++){
		int a;
		cin >> a;
		a--;
		ctr[a]++;
		if(ctr[a] >= 3){
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;
	return 0;
}

Measured memory_bytes: 256
r, c = [int(i) for i in input().split()]

data = []
sum_row = [0] * (c + 1)

for ri in range(r):
    data.append([int(i) for i in input().split()])
    data[ri].append(sum(data[ri]))
    print(" ".join([str(d) for d in data[ri]]))
    for ci in range(c + 1):
        sum_row[ci] += data[ri][ci]

print(" ".join([str(s) for s in sum_row]))

Measured memory_bytes: 7744
#include<iostream>

using namespace std;

int main(){
  int X,A,B,C,count=0;
  cin >> A >> B >> C >> X;
  for(int i=0;i<=A;i++){
    for(int j=0;j<=B;j++){
      for(int k=0;k<=C;k++){
        if(X==500*i+100*j+50*k){count++;}
      }
    }
  }
  cout << count << endl;
}


Measured memory_bytes: 256
import Control.Monad
import Data.List

answer::[Int]->[Int]->Int
answer ln rn = max 0 (minimum rn - maximum ln + 1)

getInts::IO[Int]
getInts = getLine >>= mapM readIO . words

main = do
  [n,m] <- map read . words <$> getLine
  [ln,rn] <- transpose <$> replicateM m getInts
  print $ answer ln rn

Measured memory_bytes: 63868
#include<stdio.h>

int main(void)
{
    int i,a,max,s1,s2;
    char ans[6]="ABCDE";

    while(scanf("%d%d",&s1,&s2)&&(s1+s2)!=0){
        max=s1+s2;
        i=0;
        a=i;
        for(i++;i<5;i++){
            scanf("%d%d",&s1,&s2);
            max<(s1+s2)?(max=(s1+s2),a=i):(max=max);
        }
        printf("%c %d\n",ans[a],max);
    }
    return 0;
}

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

vector<bool> init() {
  vector<bool> v(14, false);
  return v;
}

int main() {
  int N;
  cin >> N;
  map<char, vector<bool>> Map;
  vector<char> suits = {'S', 'H', 'C', 'D'};
  for (char suit: suits) {
    Map[suit] = init();
  }
  for (int i = 0; i < N; i++) {
    char c; int x;
    cin >> c >> x;
    Map[c][x] = true;
  }
  for (char suit: suits) {
    for (int i = 1; i < 14; i++) {
      if (!Map[suit][i]) cout << suit << ' ' << i << endl;
    }
  }
}


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

ll count(vector<ll> a, ll n, ll v) {
    ll tot = 0;
	for (ll i = 0; i < n; ++i) {
		tot += n - (lower_bound(a.begin(), a.end(), v - a[i]) - a.begin());
	}
	return tot;
}

int main() {
    ll n, m;
    cin >> n >> m;
    vector<ll> a(n,0);
    for (ll i = 0; i < n; ++i) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    vector<ll> s(n+1,0);
    for (ll i = 0; i < n; ++i) {
        s[i+1] = s[i] + a[n - 1- i];
    }

	ll mi = 0;
	for (ll i=40; i>=0; i--) {
        if (count(a, n, mi+(1LL<<i)) >=m ) {
            mi += 1LL<<i;
        }
    }

	ll num=0;
	ll ret=0;
    for (ll i = 0; i < n; ++i) {
		ll x = n - (lower_bound(a.begin(), a.end(), mi - a[i]) - a.begin());
		num += x;
		ret += a[i]*x + s[x];		
	}

	ret -= (num-m)*mi;
	cout<<ret<<endl;
}

Measured memory_bytes: 2572
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>

using namespace std;

int n, k;
int x[500000], y[500000];
int ans = 0;
int b[3000][3000];
int w[3000][3000];

int cW(int i, int j)
{
    int n = 2 * k, m = 2 * k;
    if (i < 0 || j < 0) return 0;
    int res = 0;
    if (i < n && j < m) return w[i][j];
    if (i >= n && j < m) return w[n - 1][j] + w[i - n][j];
    if (i < n && j >= m) return w[i][m - 1] + w[i][j - m];
    if (i >= n && j >= m) return w[n - 1][m - 1] + w[i - n][j - m] + w[n - 1][j - m] + w[i - n][m - 1];
}

int cB(int i, int j)
{
    int n = 2 * k, m = 2 * k;
    if (i < 0 || j < 0) return 0;
    int res = 0;
    if (i < n && j < m) return b[i][j];
    if (i >= n && j < m) return b[n - 1][j] + b[i - n][j];
    if (i < n && j >= m) return b[i][m - 1] + b[i][j - m];
    if (i >= n && j >= m) return b[n - 1][m - 1] + b[i - n][j - m] + b[n - 1][j - m] + b[i - n][m - 1];
}

int getW(int i1, int j1, int i2, int j2)
{
    return cW(i2, j2) - cW(i1 - 1, j2) - cW(i2, j1 - 1) + cW(i1 - 1, j1 - 1);
}

int getB(int i1, int j1, int i2, int j2)
{
    return cB(i2, j2) - cB(i1 - 1, j2) - cB(i2, j1 - 1) + cB(i1 - 1, j1 - 1);
}

int main()
{
    cin >> n >> k;
    for (int i = 0; i < n; i++)
    {
        char c;
        cin >> x[i] >> y[i] >> c;
        x[i] %= 2 * k;
        y[i] %= 2 * k;
        if (c == 'W')
            w[x[i]][y[i]]++;
        else
            b[x[i]][y[i]]++;
    }
    for (int i = 0; i < 2 * k; i++)
    {
        for (int j = 0; j < 2 * k; j++)
        {
            w[i][j] += (i > 0) ? w[i - 1][j] : 0;
            w[i][j] += (j > 0) ? w[i][j - 1] : 0;
            w[i][j] -= (i > 0 && j > 0) ? w[i - 1][j - 1] : 0;
            b[i][j] += (i > 0) ? b[i - 1][j] : 0;
            b[i][j] += (j > 0) ? b[i][j - 1] : 0;
            b[i][j] -= (i > 0 && j > 0) ? b[i - 1][j - 1] : 0;
        }
    }
    for (int i = 0; i < 2 * k; i++)
    {
        for (int j = 0; j < 2 * k; j++)
        {
            int res = getW(i, j, i + k - 1, j + k - 1) + getW(i + k, j + k, i + 2 * k - 1, j + 2 * k - 1);
            res += getB(i + k, j, i + 2 * k - 1, j + k - 1) + getB(i, j + k, i + k - 1, j + 2 * k - 1);
            ans = max(ans, res);
        }
    }
    cout << ans;
}


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

int main(void) {
	string S;
	cin >> S;

	string ans = "Yes";
	for (int i = 0; i < (int)S.length(); ++i) {
		if (i % 2 == 0) {
			if (S[i] == 'L') {
				ans = "No";
				break;
			}
		}
		else {
			if (S[i] == 'R') {
				ans = "No";
				break;
			}
		}
	}

	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//#define MOD 1000000007
#define MOD 998244353
#define INF 1145141919810893364
//#define INF 810114514
#define PI 3.141592653589
typedef long long ll;
typedef pair<ll,ll> PP;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << "0" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl
#define debug false
#define debug2 false




signed main(void){
    int N;
    cin >>N;
    N = N%10;
    if(N==2||N==4||N==5||N==7||N==9){
        cout << "hon" << endl;
    }else if(N==0||N==1||N==6||N==8){
        cout << "pon" << endl;
    }else{
        cout << "bon" << endl;
    }
    
    
    return 0;
}




Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define ll long long
#define pw (ll)pow 
#define MAX 1000005
using namespace std;

ll cl(ll n, ll k)	{
	if(n%k==0)	return n/k;
	return n/k+1;
}

string solve(ll n)	{
	string s;
	while(n>0)	{
		ll x=cl(n,26)-1;
		s.push_back(n-x*26+'a'-1);
		n=x;
	}
	reverse(s.begin(),s.end());
	return s;
}

int main()	
{
	ll n;
	cin >> n;
	string s = solve(n);
	cout << s << "\n";
	return 0;
}

Measured memory_bytes: 3652
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = sc.nextLong();
		long x = sc.nextLong();
		sc.close();
		long ans = b / x - a / x;
		if (a % x == 0)
			ans++;
		System.out.println(ans);
	}
}

Measured memory_bytes: 22996
#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 lli long long int
#define llu unsigned long long int
#define pb push_back
#define rt return 0
#define endln "\n"
#define all(x) x.begin(), x.end()
#define sz(x) (lli)(x.size())
const lli MOD = 1e9 + 7;
const double PI = 2 * acos(0.0);
// cout << fixed << setprecision(0) << pi <<endl;
// typedef tree<int, null_type, less<int>, rb_tree_tag,
//              tree_order_statistics_node_update>
//     new_data_set;
// for multiset
// typedef tree<int, null_type, less_equal<int>, rb_tree_tag,
//              tree_order_statistics_node_update>
//     new_data_set;
// order_of_key(val): returns the number of values less than val
// find_by_order(k): returns an iterator to the kth largest element (0-based)

void solve() {
    lli n, a;
    string st;
    cin >> st;
    lli cnt = 0, ans = 0;

    for (lli i = 0; i < st.length(); i++) {
        if (st[i] == 'S') {
            ans = max(ans, cnt);
            cnt = 0;
        } else {
            cnt++;
        }
    }

    ans = max(ans, cnt);

    cout << ans << endl;
}

int main(void) {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    // lli t; cin >> t; while(t--)
    solve();
    rt;
}

Measured memory_bytes: 3652
import java.util.Arrays;
import java.util.Scanner;

class Main {
	double[][] p = new double[2][6];

	void run() {
		Scanner sc = new Scanner(System.in);
		int Na = sc.nextInt();
		int Nb = sc.nextInt();
		long[] xa = new long[Na];
		long[] ya = new long[Na];
		long[] xb = new long[Nb];
		long[] yb = new long[Nb];
		for (int i = 0; i < Na; ++i) {
			xa[i] = sc.nextLong();
			ya[i] = sc.nextLong();
		}
		for (int i = 0; i < Nb; ++i) {
			xb[i] = sc.nextLong();
			yb[i] = sc.nextLong();
		}

		double ans = Double.MAX_VALUE / 3;
		for (int t = 0; t < 2; ++t) {
			for (int i = 0; i < Na; ++i) {
				for (int j = 0; j < Na; ++j) {
					if (cross(xa[0], ya[0], xa[i], ya[i], xb[0], yb[0], xb[1], yb[1])) {
						continue;
					}
					if (cross(xa[i], ya[i], xa[j], ya[j], xb[0], yb[0], xb[1], yb[1])) {
						continue;
					}
					if (cross(xa[j], ya[j], xa[1], ya[1], xb[0], yb[0], xb[1], yb[1])) {
						continue;
					}
					ans = Math.min(ans, dist(xa[0], ya[0], xa[i], ya[i]) + dist(xa[i], ya[i], xa[j], ya[j])
							+ dist(xa[j], ya[j], xa[1], ya[1]) + dist(xb[0], yb[0], xb[1], yb[1]));
				}
			}
			Na ^= Nb;
			Nb ^= Na;
			Na ^= Nb;
			long[] tmp = new long[Na];
			tmp = Arrays.copyOf(xa, xa.length);
			xa = Arrays.copyOf(xb, xb.length);
			xb = Arrays.copyOf(tmp, tmp.length);
			tmp = Arrays.copyOf(ya, ya.length);
			ya = Arrays.copyOf(yb, yb.length);
			yb = Arrays.copyOf(tmp, tmp.length);
		}
		System.out.println(ans >= Double.MAX_VALUE / 4 ? "-1" : ans);
	}

	double dist(long xa, long ya, long xb, long yb) {
		long dx = xa - xb;
		long dy = ya - yb;
		return Math.sqrt(dx * dx + dy * dy);
	}

	boolean cross(long xa1, long ya1, long xb1, long yb1, long xa2, long ya2, long xb2, long yb2) {
		long v = f(xa1, ya1, xb1, yb1, xa2, ya2) * f(xa1, ya1, xb1, yb1, xb2, yb2);
		long u = f(xa2, ya2, xb2, yb2, xa1, ya1) * f(xa2, ya2, xb2, yb2, xb1, yb1);
		return v <= 0 && u <= 0;
	}

	long f(long xa, long ya, long xb, long yb, long x, long y) {
		return (ya - yb) * (x - xa) - (y - ya) * (xa - xb);
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

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


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

const int mxN = 2e5;

int modpow(int base, int power, int mod) {
	int res = 1;
	while (power) {
		if (power % 2) {
			res = (1ll * res * base) % mod;
		}
		power /= 2;
		base = (1ll * base * base) % mod;
	}
	return res;
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	vector<int> dp(mxN + 1);
	for (int i = 1; i <= mxN; i++) {
		int count = 0;
		for (int bit = 1; bit <= mxN; bit *= 2) {
			if (i & bit) {
				count++;
			}
		}
		dp[i] = dp[i % count] + 1;
	}
	int n;
	string s;
	cin >> n >> s;
	int pc = 0;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == '1') {
			pc++;
		}
	}
	int c1 = 0, c2 = 0;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == '1') {
			if (pc >= 2) {
				c1 += modpow(2, n - 1 - i, pc - 1);
				c1 %= pc - 1;
			}
			c2 += modpow(2, n - 1 - i, pc + 1);
			c2 %= pc + 1;
		}
	}
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == '0') {
			int next = (c2 + modpow(2, n - 1 - i, pc + 1)) % (pc + 1);
			cout << dp[next] + 1 << '\n';
		} else {
			if (pc >= 2) {
				int next = ((c1 - modpow(2, n - 1 - i, pc - 1)) % (pc - 1) + (pc - 1)) % (pc - 1);
				cout << dp[next] + 1 << '\n';
			} else {
				cout << "0\n";
			}
		}
	}
}



Measured memory_bytes: 4380
a = list(map(int,list(input())))[::-1]
a.append(0)
ans = 0
for i in range(len(a)):
  if a[i] >= 6 or (a[i] == 5 and a[i+1] >= 5):
    a[i] = 10-a[i]
    a[i+1] += 1
print(sum(a))

Measured memory_bytes: 20708
inputs = STDIN.readlines.map{|line|line.strip.split()}
input = inputs.shift
n = input[0].to_i
m = input[1].to_i

counts = []
n.times do |ni|
    input = inputs.shift
    a = input[0].to_i
    b = input[1].to_i
    counts.push({
        :p => a,
        :c => b,
    })
end
counts.sort! do |a, b|
    a[:p] <=> b[:p]
end
sum = 0
c = 0
while m > 0
    count = counts.shift
    sum += [count[:c], m].min * count[:p]
    m -= count[:c]
end

puts(sum)

Measured memory_bytes: 50416
#include <iostream>
#include <string>
using namespace std;
int main(){
	string name[500];
	int a[500],b[500];
	int i=0;
	while(cin >> name[i] >> a[i] >> b[i] )
		i++;
	int n=i;
	for( i=0 ; i<n ; i++ )
		cout << name[i] <<" "<<a[i]+b[i]<<" "<<(a[i]*200)+(b[i]*300)<<endl;
	return 0;
}

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

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int n, k;
	cin>>n>>k;
	vector<ll> a(n+1), pref(n+1);
	for(int i=1; i<=n; ++i) {
		cin>>a[i];
		pref[i]=(pref[i-1]+a[i])%k;
	}
	map<ll, ll> cnt;
	ll ans=0;
	cnt[0]=1;
	if(k==1) {
		cout<<0;
		return 0;
	}
	for(int i=1; i<=n; ++i) {
		if(i>=k) {
			cnt[(pref[i-k]-i%k+k)%k]--;
		}
		ans += cnt[(pref[i]-i%k+k)%k];
		cnt[(pref[i]-i%k+k)%k]++;
	}
	cout<<ans;
}


Measured memory_bytes: 15872
N = int(input())
dp = [0]*100001
L = [1,6,36,216,1296,7776,46656,9,81,729,6561,59049]
for i in range(100001):
    for j in range(len(L)):
        if 1 <= i+L[j] <= 100000:
            if dp[i+L[j]] == 0:
                dp[i+L[j]] = dp[i]+1
            else:
                dp[i+L[j]] = min(dp[i]+1,dp[i+L[j]]) 
print(dp[N])

Measured memory_bytes: 3828
#include <iostream>
#include <cstring>

#define   offcin        ios::sync_with_stdio(false)
using namespace std;

const int maxn = 16;

int N, K;
long long a[maxn];

int main(int argc, char const *argv[]) {
    cin>>N>>K;
    
    for (int i = 0; i < N; i ++) cin>>a[i];
    long long ans = 1e18;
    for (int i = 0; i < (1 << N); i ++) {
        int tmp = 0;
        long long res = 1e18;
        for (int j = 0; j < N; j ++) if (i & (1 << j)) tmp ++;
        if (tmp == K) {
            res = 0;
            long long last = 0;
            for (int j = 0; j < N; j ++) {
                if (!(i & (1 << j)))
                    last = max(last, a[j]);
                if (i & (1 << j)) {
                    if (a[j] > last) {
                        last = a[j];
                        continue;
                    }
                    res += (last + 1 - a[j]);
                    last ++;
                }
            }
        }
        ans = min(ans, res);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define lp(i,n) for(int i=0;i<n;i++)
#define lps(i,j,n) for(int i=j;i<n;i++)
#define fordebug int hoge;cin>>hoge;
#define DEKAI 1000000007
#define INF 2000000000000
#define int long long
#define double long double
#define floot10 cout<<fixed<<setprecision(10)
#define Int long long
#define hogea pair<pair<int,int>,int>

pair<int,int> hoge(char c){
  if('A'<=c&&c<='M') return {1,0};
  if('N'<=c&&c<='Z') return {-1,0};
  if('a'<=c&&c<='m') return {0,1};
  return {0,-1};
}

signed main(){
  int n;
  cin>>n;
  string s;
  cin>>s;
  int x=0,y=0;
  lp(i,n){
    x+=hoge(s[i]).first;
    y+=hoge(s[i]).second;
  }
  char cx='A';
  if(x<0){
    x*=-1;
    cx='Z';
  }
  char cy='a';
  if(y<0){
    y*=-1;
    cy='z';
  }
  cout<<x+y<<endl;
  lp(i,x)cout<<cx;
  lp(i,y){
    cout<<cy;
  }
  cout<<endl;
  return 0;
}



Measured memory_bytes: 3292
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

#include <bits/stdc++.h>
using namespace std;

int main(){
  ll n,k;
  cin>>n>>k;
  
  ll x=n/k;
  ll y=(2*n+k)/(2*k);
  
  if(k%2==1){
    cout<<x*x*x<<endl;
  }
  else{
    cout<<x*x*x+y*y*y<<endl;
  }
  
  return 0;
}

Measured memory_bytes: 3524
#include <iostream>
#include <set>
#include <map>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <climits>
#include <math.h>
using namespace std;
#pragma warning(disable : 4996)




int main() {
#ifdef _DEBUG
	freopen("input1.txt", "r", stdin);
	freopen("output1.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	long long n;
	cin >> n;
	if (n % 2 == 1) {
		cout << 0;
		return 0;
	}
	n /= 2;
	long long ans = 0;
	long long now = 5;
	while (n / now > 0) {
		ans += n / now;
		now *= 5;
	}
	cout << ans;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc102/tasks/abc102_b
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define isvisiblechar(c) (0x21 <= (c) && (c) <= 0x7E)
#define cin scanner
#define cout printer
namespace {
class MaiScanner {
  public:
    template <typename T> void input_integer(T &var) {
        var = 0;
        T sign = 1;
        int cc = getchar_unlocked();
        for (; cc < '0' || '9' < cc; cc = getchar_unlocked())
            if (cc == '-')
                sign = -1;
        for (; '0' <= cc && cc <= '9'; cc = getchar_unlocked())
            var = (var << 3) + (var << 1) + cc - '0';
        var = var * sign;
    }
    inline int c() { return getchar_unlocked(); }
    inline MaiScanner &operator>>(int &var) {
        input_integer<int>(var);
        return *this;
    }
    inline MaiScanner &operator>>(long long &var) {
        input_integer<long long>(var);
        return *this;
    }
    inline MaiScanner &operator>>(string &var) {
        int cc = getchar_unlocked();
        for (; !isvisiblechar(cc); cc = getchar_unlocked())
            ;
        for (; isvisiblechar(cc); cc = getchar_unlocked())
            var.push_back(cc);
        return *this;
    }
    template <typename IT> void in(IT begin, IT end) {
        for (auto it = begin; it != end; ++it)
            *this >> *it;
    }
};
class MaiPrinter {
  public:
    template <typename T> void output_integer(T var) {
        if (var == 0) {
            putchar_unlocked('0');
            return;
        }
        if (var < 0)
            putchar_unlocked('-'), var = -var;
        char stack[32];
        int stack_p = 0;
        while (var)
            stack[stack_p++] = '0' + (var % 10), var /= 10;
        while (stack_p)
            putchar_unlocked(stack[--stack_p]);
    }
    inline MaiPrinter &operator<<(char c) {
        putchar_unlocked(c);
        return *this;
    }
    inline MaiPrinter &operator<<(int var) {
        output_integer<int>(var);
        return *this;
    }
    inline MaiPrinter &operator<<(long long var) {
        output_integer<long long>(var);
        return *this;
    }
    inline MaiPrinter &operator<<(char *str_p) {
        while (*str_p)
            putchar_unlocked(*(str_p++));
        return *this;
    }
    inline MaiPrinter &operator<<(const string &str) {
        const char *p = str.c_str();
        const char *l = p + str.size();
        while (p < l)
            putchar_unlocked(*p++);
        return *this;
    }
    template <typename IT> void join(IT begin, IT end, char sep = ' ') {
        for (bool b = 0; begin != end; ++begin, b = 1)
            b ? *this << sep << *begin : *this << *begin;
    }
};
} // namespace
MaiScanner scanner;
MaiPrinter printer;

int main(void) {
    int n, t, maxv = 0, minv = 1e9;
    cin >> n;
    REP(i, n) {
        cin >> t;
        maxv = max(maxv, t);
        minv = min(minv, t);
    }
    cout << maxv - minv << "\n";

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
#include <deque>
#include <complex>

using namespace std;

/*
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
*/

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<long long, long long> pll;
typedef vector<pll> vpll;

typedef long double ld;
typedef vector<ld> vld;

typedef vector<bool> vb;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, n) for (ll i = 1; i <= (n); i++)
#define rrep(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rreps(i, n) for (ll i = (n); i >= 1; i--)
#define all(v) (v).begin(), (v).end()

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

constexpr int INF = 1 << 30;
constexpr ll INFL = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr ld EPS = 1e-12;
ld PI = acos(-1.0);

void solve() {
    ll n;
    cin >> n;
    vll cnt(n + 1);
    ll ans = 0;
    for(ll i = 1; i <= n; i++) {
        for(ll j = i; j <= n; j += i) {
            cnt[j]++;
        }
        ans += i * cnt[i];
    }
    cout << ans << endl;
    return;
}

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

Measured memory_bytes: 81336
def main():
    s = int(input())
    an = list()
    a = 0
    for i in range(1000000):
        if i == 0:
            a = s
            an.append(a)
        else:
            if a % 2 == 0:
                a = int(a/2)
                an.append(a) 
            else:
                a = 3*a + 1
                an.append(a)
    for i in range(1000000):
        try:
            m = an.index(an[i], i+1)
            print(m+1)
            break
        except:
            continue
main()

Measured memory_bytes: 10904