akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <utility>
#include <vector>
using namespace std;

#define W first
#define H second

bool compare(const pair<int, int>& a, const pair<int, int>& b) {
	return a.W * a.H < b.W * b.H;
}

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

	for(int n, w, h; cin >> n >> w >> h, w;) {
		vector<pair<int, int> > pieces(1, make_pair(w, h));
		for(int i = 0; i < n; ++i) {
			int p, s;
			cin >> p >> s;
			--p;

			const pair<int, int>& piece = pieces[p];
			s %= piece.W + piece.H;
			int w1, h1, w2, h2;
			if(s > piece.W) {
				s -= piece.W;
				h1 = min(piece.H - s, s);
				h2 = max(piece.H - s, s);
				w1 = w2 = piece.W;
			}
			else {
				w1 = min(piece.W - s, s);
				w2 = max(piece.W - s, s);
				h1 = h2 = piece.H;
			}

			pieces.erase(pieces.begin() + p);
			pieces.push_back(make_pair(w1, h1));
			pieces.push_back(make_pair(w2, h2));
		}

		sort(pieces.begin(), pieces.end(), compare);
		for(int i = 0; i < (int)pieces.size(); ++i)
			cout << pieces[i].W * pieces[i].H << (i + 1 == (int)pieces.size() ? "\n" : " ");
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1212
#ifdef BUILT_LOCAL

#include "niklib.h"

#endif

#include <iostream>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <string>
#include <cstdio>
#include <map>
#include <set>
#include <list>

using namespace std;

typedef long long ll;
constexpr ll mod = 1000000007;

class djikstra {
private:
    map<ll, set<pair<ll, ll>>> path; //src dst cost
    map<ll, ll> dist; //dst cost
public:
    void compute(ll start) {
        dist.clear();
        dist[start] = 0;
        priority_queue<pair<ll, ll>, deque<pair<ll, ll>>, greater<>> q;
        for (auto &e:path[start]) q.push(make_pair(e.second, e.first));
        while (!q.empty()) {
            auto c = q.top();
            q.pop();
            if (dist.find(c.second) != dist.end()) continue;
            dist[c.second] = c.first;
            for (auto &e:path[c.second]) {
                if (dist.find(e.first) != dist.end()) continue;
                q.push(make_pair(c.first + e.second, e.first));
            }
        }
    }

    void add_path(ll src, ll dst, ll cost) {
        path[src].insert(make_pair(dst, cost));
    }

    ll get_dist(ll dst) {
        if (dist.find(dst) == dist.end()) return -1;
        return dist[dst];
    }
};

int main() {
    int n, m, l, r, c;
    djikstra d;
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        cin >> l >> r >> c;
        d.add_path(l, r, c);
    }
    for (int i = 1; i < n; i++) {
        d.add_path(i + 1, i, 0);
    }
    d.compute(1);
    cout << d.get_dist(n) << endl;
}

Measured memory_bytes: 27776
from itertools import combinations

n = int(input())
A = [int(i) for i in input().split()]
q = int(input())
ms = [int(i) for i in input().split()]

numbers = set()
for i in range(1, n+1):
    for com in combinations(A, i):
        numbers.add(sum(com))

for j in ms:
    if j in numbers:
        print("yes")
    else:
        print("no")



Measured memory_bytes: 5720
# AGC 025 A - Digits Sum
n = int(input())

def DegitSum(x):
    ans = 0
    while x > 0:
        ans += x%10
        x = x // 10
    return ans
    
res = 10**8
for a in range(1, n//2+1):
    b = n - a
    if DegitSum(a) + DegitSum(b) < res:
        res = DegitSum(a) + DegitSum(b)
        
print(res)

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 998244353;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

ll gcd(ll a, ll b) {
	if (b == 0) { return a; }
	if (a < b) { return gcd(b, a); }
	return gcd(b, a%b);
}

ll lcm(ll a, ll b) {
	return a / gcd(a, b) *b;
}

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};


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



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

	vector<ll> a(N + 1);
	repn(i, N) cin >> a[i];

	sort(++a.begin(), a.end());

	if (a[N] - a[1] > 1) { cout << "No"; }
	else if (a[N] - a[1] == 1) {
		auto itr = upper_bound(++a.begin(), a.end(), a[1]);
		ll L = distance(a.begin(), itr) - 1;
		ll K = a[N];

		if (K > L&&N >= L + 2 * (K - L)) { cout << "Yes"; }
		else { cout << "No"; }
	}

	else {
		if (a[1] == N - 1 || 2 * a[1] <= N) { cout << "Yes"; }
		else { cout << "No"; }
	}


	system("PAUSE");
}


Measured memory_bytes: 1272
#include "bits/stdc++.h"

using namespace std;
typedef long long ll;
#define rep(i, j, n) for (int i = j; i < n; i++)
#define out(ans) cout << ans << endl;
const long long mod = 1e9 + 7;
typedef pair<int,int>P;

int main() {

  ll n;cin>>n;

  if(n==1){out(1);return 0;}

  for(ll i=1;i<=n;i++){
    if(i*i>n){
      out((i-1)*(i-1));
      return 0;
    }
  }

  return 0;
}


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

int main(){
  
  int n;
  cin >> n;
  
  vector<char> slimes(n);
  
  for(int i=0; i<n; i++){
    cin >> slimes.at(i);
  }
  
  int answer = slimes.size();
  
  for(int i=0; i<n-1; i++){
    if(slimes.at(i) == slimes.at(i+1)){
      answer -= 1;
    }
  }
  
  cout << answer << endl;
  
}

Measured memory_bytes: 384
n = int(input())
s = ""
t = 26
c = ['z','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y']
while n > 0:
    s += c[int(n%t)]
    n -= 1
    n //= 26
print(s[::-1])



Measured memory_bytes: 9188
K = int(input())
ans = []
def func(s):
    x = int(s)
    if x <= 3234566667:
        ans.append(x)
        tail = int(s[-1])
        for i in [-1, 0, 1]:
            p = i+tail
            if p not in list(range(10)):
                continue
            func(s+str(p))

for i in range(1, 10):
    func(str(i))

ans.sort()
print(ans[K-1])

Measured memory_bytes: 72284
#include <iostream>
#include <string>
#include <vector>
#include <iterator>  // std::prev(iter, n) n 個分デクリメントしたイテレータ
#include <tuple>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <stack>
#include <queue>
#include <algorithm>
#include <functional>  // std::greater<T>()
#include <utility>  // std::swap()
#include <numeric>  // accumulate(ALL(vec), 0)  0 は初期値
#include <bitset>  // static_cast<std::bitset<8>>
#include <sstream>  // std::stringstream
#include <cmath>
#include <climits>  // INT_MIN
#include <cctype>  // std::isdigit()
#include <iomanip>  // std::setprecision()
using namespace std;
using ll = long long;

#define REP(i, n) for (ll i=0; i < n; i++)  // 0 ~ n-1
#define MIN(vec) min_element(vec.begin(), vec.end())  // イテレータのため、値を取り出すときは * を先頭につける
#define MAX(vec) max_element(vec.begin(), vec.end())
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define SUM(vec) accumulate(vec.begin(), vec.end(), 0LL)  // 0 は初期値
#define pll pair<ll, ll>
#define F first
#define S second
const ll INF = 1LL<<60;  // 10^18

int main() {
    // input(sunippets: inpv, inpn, inps)
    ll N, M;
    cin >> N >> M;
    
    // calculation
    if (M%N == 0) cout << N+M << "\n";
    else cout << M-N << "\n";
    
    return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
from itertools import *
n = int(input())
s = list(accumulate(map(int,input().split())))
l,r,t = 0,2,s[-1]
a = t
for m in s[1:-2]:
    while abs(t-2*s[r]+m)>abs(t-2*s[r+1]+m):
        r += 1
    while abs(m-2*s[l])>abs(m-2*s[l+1]):
        l += 1
    x = sorted([s[l],m-s[l],s[r]-m,t-s[r]])
    a = min(a , x[3] - x[0])
print(a)

Measured memory_bytes: 26012
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

using namespace std;

int main() {
  long long int N, M;
  cin >> N >> M;

  vector<long long int> prime;
  long long int temp = M;
  for (int i = 2; i * i <= temp; i++) {
    if (temp % i == 0) {
      prime.push_back(i);
      while (temp % i == 0) {
        temp /= i;
      }
    }
  }
  prime.push_back(temp);

  long long int limit = M / N;
  map<long long int, bool> added;
  vector<long long int> queue;
  queue.push_back(1);
  added[1] = true;

  long long int ct = 0;
  long long int best = 1;
  while (ct < queue.size()) {
    long long int num = queue[ct];
    for(int i = 0; i < prime.size(); i++) {
      long long int target = num * prime[i];
      if (M % target == 0 && target <= limit && !added[target]) {
        added[target] = true;
        queue.push_back(target);
        if (best < target) {
          best = target;
        }
      }
    }
    ct++;
  }

  cout << best << endl;

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
int main() {
    int n, m; cin >> n >> m;
    vector<pair<int, int> > v(200001);
    int max = 0;
    for (int i = 0; i < m; ++i) {
        int a, b; cin >> a >> b;
        max = max < b ? b : max;
        if (a == 1) v[b].first = 1;
        if (b == n) v[a].second = 1;
    }
    for (int i = 1; i <= max; ++i) {
        //cout << v[i].first << " " << v[i].second << endl;
        if (v[i].first && v[i].second) {
            cout << "POSSIBLE" << endl;
            return 0;
        }
    }
    cout << "IMPOSSIBLE" << endl;
    return 0;
}


Measured memory_bytes: 1792
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
typedef long long int ll;
void swap(ll *x,ll *y){ll temp;temp=*x;*x=*y;*y=temp;}
ll asc(const void *a,const void *b){return *(ll*)a-*(ll*)b;}
ll desc(const void *a,const void *b){return *(ll*)b-*(ll*)a;}
ll max(ll x,ll y){return x>y?x:y;}
ll min(ll x,ll y){return x>y?y:x;}

int main(){
    char str[10];
    int list[26];

    for(int i=0;i<26;i++)list[i]=0;
    scanf("%s",str);
    for(int i=0;str[i]!='\0';i++){
        list[str[i]-0x41]++;
    }
    int cnt=0;
    for(int i=0;i<26;i++){
        if(list[i]==2)cnt++;
    }
    if(cnt==2)printf("Yes\n");
    else printf("No\n");
    return 0;
    


    
}

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

int main(void){
  int N;
  cin >> N;
  vector<int> A(N), B(N), C(N-1);
  int sum = 0;
  for(int i = 0; i < N; i++){
    cin >> A[i];
  }
  for(int i = 0; i < N; i++){
    cin >> B[i];
    sum += B[i];
  }
  for(int i = 0; i < N - 1; i++){
    cin >> C[i];
  }
  int before = -1;
  for(int i = 0; i < N; i++){
    if(A[i] - before == 1){
      sum += C[before - 1];
    }
    before = A[i];
  }
  cout << sum << endl;
  
  return 0; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int x;
int dp[100001];
int busquedad(int y){
    //cout<<y<<endl;
    if(y>x){
        return INT_MAX-1;
    }
    if(y==x){
        return 0;
    }
    if(dp[y]!=-1){
        return dp[y];
    }
    int mini=INT_MAX;
    if((x-y)<6){
        return (x-y);
    }
    int help=1;
    for(int i=1;i<10;i++){
        help*=6;
        mini=min(mini,busquedad(y+help)+1);
    }
    help=1;
    for(int i=1;i<10;i++){
        help*=9;
        mini=min(mini,busquedad(y+help)+1);
    }
    return dp[y]=mini;





}
int main(){
    memset(dp,-1,sizeof(dp));
    cin>>x;

    cout<<busquedad(0)<<endl;
    return 0;
}


Measured memory_bytes: 1408
use std::io;
use std::cmp;
use std::collections::BinaryHeap;
use std::collections::HashMap;
use std::collections::HashSet;
use std::f64::consts::PI;

fn read_line() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).ok();
    buf
}

fn main() {
    let line: Vec<usize> = read_line().split_whitespace().map(|s| s.parse().unwrap()).collect();
    let D = line[0];
    let cs: Vec<i64> = read_line().split_whitespace().map(|s| s.parse().unwrap()).collect();
    let mut s = Vec::with_capacity(26);
    for i in 0..D {
        let line: Vec<i64> = read_line().split_whitespace().map(|s| s.parse().unwrap()).collect();
        s.push(line);
    }

    let mut last = vec![0; 26];
    let mut ts = vec![0; D];
    for d in 0..D {
        let mut t = 0;    
        let mut score = 0i64;
        for i in 0..26 {
            let mut tmp = s[d][i];
            for j in 0..26 {
                if i!= j {
                    tmp -= cs[j] * ((d as i64) + 1 - last[j]);
                }
            }
            if score < tmp {
                score = tmp;
                t = i;
            }
        }
        last[t] = d as i64 + 1;
        ts[d] = t;
    }
    for i in 0..D {
        println!("{}", ts[i] + 1);
    }
}


Measured memory_bytes: 2300
#include<stdio.h>
int main(){
	int a,b,c,d,e,f;
	scanf("%d%d%d%d%d",&a,&b,&c,&d,&e);
	f=b%d;
	b-=f;
	b/=d;
	if(f!=0)b++;
	f=c%e;
	c-=f;
	c/=e;
	if(f!=0)c++;
	if(b>c){
		printf("%d\n",a-b);
	}
	else{
		printf("%d\n",a-c);
	}
}

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

int main(){
  int n;
  cin >> n;
  vector<int> a(n), b(n), c(n);
  rep(i,n) cin >> a[i] >> b[i] >> c[i];
  
  int dp[100000][3];
  dp[0][0] = a[0];
  dp[0][1] = b[0];
  dp[0][2] = c[0];

  rep(i,n) {
    if(i+1 >= n) break;
    dp[i+1][0] = max(dp[i][1]+a[i+1], dp[i][2]+a[i+1]);
    dp[i+1][1] = max(dp[i][0]+b[i+1], dp[i][2]+b[i+1]);
    dp[i+1][2] = max(dp[i][0]+c[i+1], dp[i][1]+c[i+1]);
  }
  cout << max(dp[n-1][0], max(dp[n-1][1], dp[n-1][2])) << endl;

}


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


int main(){
	int num[4];

	scanf("%d",&num[0]);
	scanf("%d",&num[1]);
	scanf("%d",&num[2]);
	scanf("%d",&num[3]);

	int a = num[1] - num[0];
	int b = num[2] - num[1];
	int c = num[2] - num[0]; 

	int d = num[3];
	int e = abs(a);
	int f = abs(b);
	int g = abs(c);
	
	if(e <= d && f <= d){
printf("Yes");


}else if(d >= g){
printf("Yes");

}else{
printf("No");

}


}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define FOR(i, m, n) for (int i = m; i < (n); i++)
#define RFOR(i, m, n) for (int i = (m - 1); i >= 0; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define print(ele) cout << ele << endl
#define print10(ele) cout << fixed << setprecision(10) << ele << endl

using namespace std;
typedef long long ll;
typedef vector<int> ivec;
typedef vector<string> svec;
typedef vector<ll> lvec;

const int mod = 1e9 + 7;
const ll INF = 1000000000000000000LL;

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  int ans = max(a * b, c * d);
  print(ans);
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
using P = pair<int,int>;
using pq = priority_queue<int>;
typedef long long ll;

int  main()
{
	int a,b; cin >> a >> b;
	int x = a - b;
	int y = a * b;
	int z = a + b;

	cout << max({x,y,z}) << endl;
	return (0);
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

#define MOD 1000000007
#define N 100005

int main(void)
{
  int n;
  char s[N];
  long long dp[N][13]; //先頭i文字を13で割ったあまりがjであるもののパターン数

  int i, j, k;
  scanf("%s", s);
  n = strlen(s);

  dp[0][0] = 1;

  for (i = 1; i <= n; i++)
  {
    if (s[i - 1] == '?')
    {
      for (j = 0; j < 10; j++)
        for (k = 0; k < 13; k++)
          dp[i][(k * 10 + j) % 13] += dp[i - 1][k];
    }
    else
    {
      for (k = 0; k < 13; k++)
        dp[i][(k * 10 + (s[i - 1] - '0')) % 13] += dp[i - 1][k];
    }

    for (j = 0; j < 13; j++)
      dp[i][j] %= MOD;
  }

  printf("%lld\n", dp[n][5]);
  return 0;
}


Measured memory_bytes: 10368
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T, class U> using Pa = pair<T, U>;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    ll sum = 0;
    for(int i=1;i<=N;i++){
        if(i%3!=0 && i%5!=0) sum += i;
    }
    cout << sum << "\n";
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define REP(i, m, n) for (ll(i) = (ll)(m); i < (ll)(n); ++i)
#define REP2(i, m, n) for (ll(i) = (ll)(n)-1; i >= (ll)(m); --i)
#define rep(i, n) REP(i, 0, n)
#define rep2(i, n) REP2(i, 0, n)
#define all(hoge) (hoge).begin(), (hoge).end()
#define en '\n'
using Edge = pair<int, long long>;
using Graph = vector<vector<Edge>>;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef pair<ll, ll> pll;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
const int MOD = 1000000007;
// constexpr long long MOD = (ll)1e9 + 7;
// constexpr long long MOD = 998244353LL;
using ld = long double;
static const ld pi = 3.141592653589793L;
template <class T> inline void print(T x) { cout << x << '\n'; }
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;
}

// ~~~~~~~~~~~~~~memo~~~~~~~~~~~~~~
// for (int i = 0; i < n; ++i)
// int型の2次元配列(h×w要素の)の宣言
// vector<vector<int>> data(h, vector<int>(w));
// rotate(s.begin(), s.begin() + 1, s.end());
// sort(all(a),greater<int>());
// s.substr(0,2) 先頭から2文字切り出す
// for (auto it = mp.rbegin();it != mp.rend(); ++it)
// vector<vector<vector<int>>> dp(n + 1, vector<vector<int>>(w + 1, vector<int>(k+1, 0)));
long long powmod(long long a, long long b) {
    long long res = 1;
    while (b > 0) {
        if (b % 2 == 1) {
            res *= a;
            res %= MOD;
        }
        a *= a;
        a %= MOD;
        b /= 2;
    }
    return res;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n;
    cin >> n;
    ll res = powmod(10, n) - 2 * powmod(9, n) + powmod(8, n);
    res %= MOD;
    res = (res + MOD) % MOD;
    print(res);

    return 0;
}


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

int main() {
  int n, k;
  cin >> n >> k;
  vector<vector<int>> v(n);
  for (int i = 0; i < n; i++) {
    int t, d;
    cin >> t >> d;
    v[t - 1].push_back(d);
  }
  vector<ll> a{0}, b{0};
  for (auto &e : v) {
    if (e.empty()) {
      continue;
    }
    sort(begin(e), end(e));
    a.push_back(e.back());
    for (auto it = begin(e); it != end(e) - 1; it++) {
      b.push_back(*it);
    }
  }
  sort(rbegin(a), rend(a) - 1);
  sort(rbegin(b), rend(b) - 1);
  for (int i = 0; i + 1 < a.size(); i++) {
    a[i + 1] += a[i];
  }
  for (int i = 0; i + 1 < b.size(); i++) {
    b[i + 1] += b[i];
  }
  ll r = 0;
  for (ll x = max(1, k - ((int)b.size() - 1)); x <= min(k, (int)a.size() - 1); x++) {
    r = max(r, a[x] + b[k - x] + x * x);
  }
  cout << r << endl;
}


Measured memory_bytes: 6904
N = int(input())
S = list(input() for i in range(N))

result = [0] * 4
char = ["AC", "WA", "TLE", "RE"]

for i in range(N):
    for j in range(4):
        if S[i] == char[j]:
            result[j] = result[j] + 1

for i in range(4):
    print(char[i] + " x " + str(result[i]))

Measured memory_bytes: 78460
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    int n;
    cin>>n;
    string s;
    cin>>s;


    for(int i=0;i<s.size();i++)
    {
        int x=s[i];
        if(x+n>90)
        {

            cout<<char('A'+(x+n-91));
        }
        else
        {
            cout<<char(s[i]+n);
        }
    }









    return 0;
}


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

int main(){
    int d,g;
    scanf("%d %d",&d,&g);
    int p[d],c[d];
    for(int i=0;i<d;i++) scanf("%d %d",&p[i],&c[i]);
    int ans=1000000;

    for(int bit=0;bit < (1<<d);bit++){
        int sum=0;
        int rest=0;
        int num=0;
        for(int i=0;i<d;i++){
            if(bit & (1<<i)){
                sum+=100*(i+1)*p[i]+c[i];
                num+=p[i];
            }
            else rest=i;
        }

        if(sum>=g){
            ans=min(ans,num);
            //break;
        }

        else if(sum<g){
            int sh = g-sum;
            int sum2=0;
            int num2=0;
            for(int j=0;j<p[rest];j++){
                sum2=100*(rest+1)*(j+1);
                num2++;
                if(j==p[rest]-1) sum2+=c[rest];

                if(sum2>=sh){
                    ans=min(ans, num+num2);
                    break;
                }
            }
        }
        
        
    }

    cout << ans << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<numeric>
#include<limits>
#include <cstdint>
using namespace std;
#define ll long long int
#define rep(N) for(ll i=0;i<N;i++)
#define rep2(N1,N2) for(ll i=0;i<N1;i++)for(ll j=0;j<N2;j++)
#define rep3(N1,N2,N3)for(ll i=0;i<N1;i++)for(ll j=0;j<N2;j++)for(ll k=0;k<N3;k++)
#define For(i,N) for(ll i=0;i<N;i++)

void yn(bool b) {
	if (b)printf("yes\n");
	else printf("no\n");
}

void Yn(bool b) {
	if (b)printf("Yes\n");
	else printf("No\n");
}

void YN(bool b) {
	if (b)printf("YES\n");
	else printf("NO\n");
}

int ctoi(char c) {
	return c - '0';
}

ll kai(ll x) {
	ll a = 1;
	if (x <= 0)
		return 1;
	else {
		for (ll i = 0; i < x; i++)
			a = a * (i + 1);
		return a;
	}
}

ll rui(ll x, ll y) {
	ll a = 1;
	for (ll i = 0; i < y; i++)
		a = a * x;
	return a;
}
const int nmax = 150;
int cccc[nmax][nmax];
ll comb(ll n, ll k) {
	if (n < k) {
		cout << "error n<k" << endl;
		return -1;
	}
	if (cccc[n][k] > 0)return cccc[n][k];
	if (k == 0 || n == k)return 1;
	return cccc[n][k] = comb(n - 1, k - 1) + comb(n - 1, k);
}

ll keta(ll a) {
	ll i = 1;
	while (1) {
		if (a < pow((ll)10, i))
			return i;
		i++;
	}
}
vector<ll> v;
ll n, m;
//m進数全探索
ll inc(ll a = n - 1) {
	if (a == 0 && v[0] == m) {
		v[0] = -1;
		return v[0];
	}
	if (v[a] == m) {
		v[a] = 0;
		inc(a - 1);
		return v[a];
	}
	else {
		++v[a];
		return v[a];
	}
}

int main() {
	cout.precision(20);
	ll H, A;
	cin >> H >> A;
	if (H%A == 0)
		cout << H / A;
	else
		cout << H / A + 1;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
using P = pair<int,int>;
using pq = priority_queue<int>;
typedef long long ll;
string yes = "Yes\n";
string no = "No\n";

int  main()
{
	int a,b; cin >> a >> b;
	if (a * b % 2)
		cout << "Odd\n";
	else
		cout << "Even\n";
	return (0);
}

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

int main() {
  int N, T, A, Ans=1;
  cin>>N>>T>>A;
  vector<double> H(N);
  vector<double> Ht(N);
  for (int i=0; i<N; i++)
    cin>>H.at(i);
  for (int i=0; i<N; i++){
    if (A-(T-H.at(i)*0.006)>=0)
      Ht.at(i)=A-(T-H.at(i)*0.006);
    else
      Ht.at(i)=-A+(T-H.at(i)*0.006);
  }
  double B=Ht.at(0);
  for (int i=1; i<N; i++){
    if (Ht.at(i)<B){
      B=Ht.at(i);
      Ans=i+1;
    }
  }
  cout<<Ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>

int arr[26];
std::string temp;

bool checkeven(int arr[]) {
    for (int i=0; i<26; ++i) {
        if (arr[i] % 2 != 0)
            return false;
    }
    return true;
}

void solve() {
    std::cin >> temp;
    for (int i=0; i<temp.length(); ++i) 
        ++arr[(int)temp[i]-97];
    if (checkeven(arr))
        std::cout << "Yes" << std::endl;
    else
        std::cout << "No" << std::endl;
}

int main() {
    solve();
    return 0;
}

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

Int n,ans=0;
void dfs(Int x,Int a,Int b,Int c){
  if(x>n) return; 
  if(a&&b&&c) ans++;
  dfs(x*10+3,1,b,c);
  dfs(x*10+5,a,1,c);
  dfs(x*10+7,a,b,1);
}
signed main(){
  cin>>n;
  dfs(0,0,0,0);
  cout<<ans<<endl;
  return 0;
}


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

#define int long long int
#define ff first
#define ss second
#define pb push_back
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const int mod = 1e9 + 7;
const int cmod = 998244353;
const int N = 1e7 + 5;
const int inf = 1e16 + 2;

int p[N];
void pre() {
    p[1] = 1;
    for(int i = 2 ; i < N ; i ++) {
        if(!p[i]) {
            for(int j = i ; j < N ; j += i) if(!p[j]) p[j] = i;
        }
    }
}
void solve(int Case) {
    pre();
    int n;
    cin >> n;
    int cnt = 0;
    //cout << p[2] << ' ';
    for(int i = 1 ; i <= n ; i ++) {
        int ans = 1 , t = i;
        map<int , int> m;
        while(t > 1) {
            m[p[t]] ++;
            t /= p[t];
        }
        if(t > 1) m[p[t]] ++;
        for(auto x : m) ans *= (x.ss + 1);
        cnt += i * ans;
    }
    cout << cnt << '\n';
}
/*
 */

int32_t main()
{
    fastio
    int testcase = 1;
    //cin >> testcase;
    int Case = 1;
    while(testcase --) {
        solve(Case ++);
    }
    return 0;
}
 



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

int main() {
  int n;
  cin >> n;
  vector<int> bunpu(100000);
  int64_t sum = 0;
  for(int i = 0; i < n; i++) {
    int a;
    cin >> a;
    sum += a;
    bunpu.at(a-1)++;
  }
  int q;
  cin >> q;
  for(int i = 0; i < q; i++) {
    int b, c;
    cin >> b >> c;
    int diff = c-b;
    sum += diff * bunpu.at(b-1);
    bunpu.at(c-1) += bunpu.at(b-1);
    bunpu.at(b-1) = 0;
    cout << sum << endl;
  }
  
  return 0;
}

Measured memory_bytes: 3764
from collections import deque

S = input()
Q = int(input())
ans = deque()
ans.append(S)
turncnt = 0
for i in range(Q):
    query = input().split()
    if (query[0] == "1"):
        turncnt = turncnt + 1
    if (query[0] == "2"):
        if (query[1] == "1"):
            if (turncnt % 2 == 0):
                ans.appendleft(query[2])
            else:
                ans.append(query[2])
        if (query[1] == "2"):
            if (turncnt % 2 == 0):
                ans.append(query[2])
            else:
                ans.appendleft(query[2])

anstr = "".join(ans)
if (turncnt % 2 == 1):
    anstr = anstr[::-1]
print(anstr)


Measured memory_bytes: 67928
#include<bits/stdc++.h>
using namespace std;
int arr_wield[100001],arr_throw[100001];
bool mycompare(const int & a,const int & b)
{
	return a>b;
}
int main()
{
	int n,h,i,pos_t=0,k=0;
	scanf("%d %d",&n,&h);
	for(i=0;i<n;i++)
	{
		scanf("%d %d",&arr_wield[i],&arr_throw[i]);
	}
	sort(arr_wield,arr_wield+n,mycompare);
	sort(arr_throw,arr_throw+n,mycompare);
	while(h>0)
	{
		if(arr_throw[pos_t]>arr_wield[0])
		{
			h-=arr_throw[pos_t++];
			k++;
		}
		else
		{
			k+=h/arr_wield[0];
			k+=h%arr_wield[0]==0?0:1;
			break;
		}
	}
	printf("%d",k);
	return 0;
}

Measured memory_bytes: 1024
import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
    	long input =0;
    	ArrayList<Integer> digits = new ArrayList<Integer>();
    	
        try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
            input = Long.parseLong(br.readLine());
        }
        
        int pow = String.valueOf(input).length();
        long currentval = input;
        for (int i=pow-1; i>=0; i--) {
        	int digit =  (int) (currentval/(long)Math.pow(10, i)) ;
        	digits.add(digit);
        	currentval = currentval - digit*(long)Math.pow(10, i);
        }
        
        ArrayList<Integer> candidates = new ArrayList<Integer>();
        int cand=0;
        for(int e:digits) {
        	cand=cand+e;
        }
        candidates.add(cand);
        for(int i = 0; i<pow; i++) {
        	cand =0;
        	if (digits.get(pow-i-1) !=0) {
	        	for(int j = 0; j<i; j++) {
	        		cand=cand+9;
	            	//System.out.println(String.format("add %d",9));
	        	}
	        	for(int j=i; j<pow ;j++) {
	        		cand = cand +digits.get(pow-j-1);
	        		//System.out.println(String.format("add %d",digits.get(pow-j-1)));
	        	}
	        	cand = cand -1;
        	}
        	candidates.add(cand);
        	//System.out.println(cand);
        }
        int maxcand = 0;
        for(int i=0; i<candidates.size();i++) {
        	if(maxcand<candidates.get(i)) maxcand = candidates.get(i);
        }
        System.out.println(maxcand);
    }
}

Measured memory_bytes: 21204
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <iomanip>

using namespace std;

const double INF = (1 << 29);
const double EPS = 1e-5;

struct State{
    double cost;
    int now, bef, speed;

    State(double c, int n, int b, int s):
        cost(c),now(n),bef(b),speed(s){}

    bool operator < (State s) const{
        return s.cost < cost;
    }
};

struct Edge{
    int to, dist, limit;
    Edge(int t, int d, int l):
        to(t), dist(d), limit(l){}
};

int n, m, s, g;
vector<Edge> edge[31];
double minCost[31][31][31];

double dijkstra(){
    for(int i = 0;i < 31;i++){
        for(int j = 0;j < 31;j++){
            for(int k = 0;k < 31;k++){
                minCost[i][j][k] = INF;
            }
        }
    }
    priority_queue<State> pq;
    pq.push(State(0,s,0,1));

    bool begin = true;
    while(!pq.empty()){
        State p = pq.top();
        pq.pop();

        if(p.now==g && p.speed==1){
            return p.cost;
        }

        if(minCost[p.now][p.bef][p.speed] <= p.cost + EPS){
            continue;
        }
        minCost[p.now][p.bef][p.speed] = p.cost;

        for(int j = 0 ; j < edge[p.now].size() ; j++){
	        Edge e = edge[p.now][j];
	        if(p.bef==e.to)continue;

            for(int k = -1 ; k <= 1 ; k++){
                if(k!=0 && begin)continue;
    
                if(0 < p.speed + k && p.speed + k < 31 && p.speed + k <= e.limit){
                    double t = e.dist / (double)(p.speed + k);
                    if(minCost[e.to][p.now][p.speed+k] > p.cost+t){
                        pq.push(State(p.cost+t, e.to, p.now, p.speed+k));
                    }
                }
            }
        }
        if(begin)begin = false;
    }
    return -1.0;
}

int main(){
    while(scanf("%d%d",&n,&m)){
        if(n==0 && m==0)break;

        for(int i = 0 ; i < 31;i++){
            edge[i].clear();
        }

        cin >> s >> g;
      
    for(int i = 0;i < m ; i++){
	    int x,y,d,c;
        cin >> x >> y >> d >> c;
	    edge[x].push_back(Edge(y,d,c));
	    edge[y].push_back(Edge(x,d,c));
        }
      
        double ans = dijkstra();
        if(ans==-1)cout << "unreachable" << endl;
        else cout << fixed << setprecision(10) << ans <<endl;
    }
    return 0;
}



Measured memory_bytes: 15496
#include"bits/stdc++.h"

using namespace std;


int main() {
    string s, t;
    cin >> s >> t;
    int n = s.size();
    if (s == t.substr(0, n )) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3596
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
using namespace std;
int main()
{
        char s[202];
        scanf("%s",s);
        int len=strlen(s)-1;
        //printf("%d\n",len);
        int n=len;
        for(int i=1;i<=len;i++)
        {
                int num=0;
                int flag=0;
                if(n%2==0)
                {
                        for(int j=0;j<n/2;j++)
                        {
                                if(s[j]==s[n/2+j])
                                        num++;
                                if(num==n/2)
                                {
                                        flag=1;
                                        printf("%d\n",n);
                                }
                        }
                }
                n--;
                if(flag)
                        break;
        }
        return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <set>
#include <string>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
using namespace std;

typedef long long int64;
typedef unsigned long long uint64;
typedef pair<int, int> ii;
typedef pair<int64, int64> int64int64;
typedef vector<int> vint;
typedef vector<int64> vint64;
typedef vector<uint64> vuint64;
typedef vector<vint> vvint;
typedef vector<vint64> vvint64;
typedef vector<vuint64> vvuint64;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;

#define mp make_pair
#define pb push_back
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
#define fori(n) for(int i = 0; i < n; ++i)
#define forj(n) for(int j = 0; j < n; ++j)
#define fork(n) for(int k = 0; k < n; ++k)

template<typename T>
void prinMatrix(string txt, vector<vector<T>> &a){
	cout << txt;
	fori(a.size()){
		forj(a[i].size())
			cout << a[i][j] << ' ';

		cout << endl;
	}
}

template<typename T>
void printVector(string txt, vector<T> &a){
	cout << txt;
	for (int i = 0; i < a.size(); ++i)
		cout << a[i] << ' ';
	cout << endl;
}


int main(){

	ios_base::sync_with_stdio(0);
	cin.tie();

	int n;
	vii a;
	cin >> n;
	a.resize(n);
	fori(n){
		cin >> a[i].first;
		a[i].second = i;
	}

	sort(ALL(a), [](ii &a, ii &b){return a.first < b.first; });
	fori(n)
		cout << a[i].second + 1 << ' ';

	return 0;
}


Measured memory_bytes: 1664
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
using ll = long long;
int main(){
    int a,b;
    cin >> a >> b;
    if(a==b) cout << a+b;
    else if(a>b)   cout << a+(a-1);
    else    cout << b+(b-1);
    return 0;
}

Measured memory_bytes: 256
import sys

def egcd(a, b):
    if a == 0:
        return b, 0, 1
    else:
        g, y, x = egcd(b % a, a)
        return g, x - (b // a) * y, y

def modinv(a, m):
    g, x, y = egcd(a, m)
    if g != 1:
        raise Exception('modular inverse does not exist')
    else:
        return x % m

def comb_num_mod(n, r, mod=10**9+7):
    r = min(r, n-r)
    res = 1
    for i in range(r):
        res = res * (n - i) * modinv(i+1, mod) % mod
    return res

def solver(x, y):


    if (x, y) == (0, 0):
        return 0
    if (x+y)%3 != 0:
        return 0
    k = (x+y)//3
    (xi, yi) = (k, 2*k)
    for i in range(k+1):
        if (xi, yi) == (x, y):
            return comb_num_mod(k, i) 
        else:
            (xi, yi) = (xi+1, yi-1)
    return 0

x, y = map(int, input().split())
res = solver(x, y)
print(res)

Measured memory_bytes: 3188
import java.util.*;

public class Main{
    void solve(){
        Scanner scan = new Scanner(System.in);
        int h = scan.nextInt();
        int w = scan.nextInt();
        char[][] map = new char[h][w];
        for(int i = 0; i < h; i++){
            String s = scan.next();
            for(int j = 0; j < w; j++){
                map[i][j] = s.charAt(j);
            }
        }
        char[][] out = new char[h][w];
        for(int i = 0; i < h; i++){
            for(int j = 0; j < w; j++){
                if(map[i][j] == '#'){
                    out[i][j] = '#';
                    continue;
                }
                int c = 0;
                for(int k = -1; k <= 1; k++){
                    for(int l = -1; l <= 1; l++){
                        int yp = i + k;
                        int xp = j + l;
                        if(0 <= yp && yp < h && 0 <= xp && xp < w && map[yp][xp] == '#'){
                            c++;
                        }
                    }
                }
                out[i][j] = Integer.toString(c).charAt(0);
            }
        }
        for(int i = 0; i < h; i++){
            for(int j = 0; j < w; j++){
                System.out.print(out[i][j]);
            }
            System.out.println();
        }
    }
    
    public static void main(String[] args){
        new Main().solve();
    }
}

Measured memory_bytes: 36604
import itertools

x = input().split(' ')
n = int(x[0])
m = int(x[1])
q = int(x[2])

abcd = []

for i in range(q):
  x = input().split(' ')
  tmp = []
  for j in range(4):
    tmp.append(int(x[j]))
    
  abcd.append(tmp)
  

a_candidates = itertools.combinations_with_replacement(list(range(1, m+1)), n)

score = 0

for candidate in a_candidates:
  score_tmp = 0
  for abcd_ in abcd:
    a = abcd_[0]-1
    b = abcd_[1]-1
    c = abcd_[2]
    d = abcd_[3]
    
    if (candidate[b]-candidate[a]) == c:
      score_tmp += d
      

  if score_tmp > score:
    score = score_tmp
    
print(score)

Measured memory_bytes: 9228
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <sstream>
#include <cstdio>
#include <complex>
#include <climits>
using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> dp(n, INT_MAX);
  int a;
  for (int i = 0; i < n; i++) {
    cin >> a;
    *lower_bound(dp.begin(), dp.end(), a) = a;
  }
  cout << lower_bound(dp.begin(), dp.end(), INT_MAX) - dp.begin() << endl;
}

Measured memory_bytes: 1532
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <functional>
#include <algorithm>
#include <climits>

using namespace std;

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

struct Edge
{
	int to;
	int cost;
};

struct Node
{
	int city_index;
	int total_cost;
	int current_life;
	int remain_can_regain;

	bool operator >(const Node &a) const
	{
		return total_cost > a.total_cost;
	}
};

int main()
{
	int city_count, initial_life, cooler_count, road_count, start_index, goal_index;
	while (cin >> city_count >> initial_life >> cooler_count >> road_count >> start_index >> goal_index,
		city_count)
	{
		// input
		vector<int> is_cooler(city_count, false);
		REP(i, cooler_count)
		{
			int cooler_index;
			cin >> cooler_index;
			is_cooler[cooler_index] = true;
		}
		vector<vector<Edge>> roads(city_count);
		REP(i, road_count)
		{
			int from, to, cost;
			cin >> from >> to >> cost;
			roads[from].push_back({ to, cost });
			roads[to].push_back({ from, cost });
		}

		// dijkstra
		vector<vector<int>> d(city_count, vector<int>(initial_life + 1, INT_MAX)); // [city_index][current_life] => total_cost
		d[start_index][initial_life] = 0;
		priority_queue<Node, vector<Node>, greater<Node> > pq;
		pq.push({ start_index, 0, initial_life, 0});
		while (true)
		{
			if (pq.empty())
			{
				cout << "Help!" << endl;
				break;
			}
			auto current_node = pq.top(); pq.pop();
			if (current_node.city_index == goal_index)
			{
				cout << current_node.total_cost << endl;
				break;
			}
			for (auto &road : roads[current_node.city_index])
			{
				int total_cost = current_node.total_cost + road.cost;
				int life = current_node.current_life - road.cost;
				int remain_can_regain = is_cooler[current_node.city_index] ? initial_life - current_node.current_life : current_node.remain_can_regain;
				if (life < 0)
				{
					int shortage = -life;
					remain_can_regain -= shortage;
					if (remain_can_regain < 0)
					{
						continue;
					}
					total_cost += shortage;
					life = 0;
				}
				auto &di = d[road.to][remain_can_regain];
				if (total_cost < di)
				{
					di = total_cost;
					pq.push({ road.to, total_cost, life, remain_can_regain });
				}
			}

		}
	}

	return 0;
}

Measured memory_bytes: 1456
#include<iostream>
#include<string>
using namespace std;
int main()
{
	string s,t;
	cin>>s>>t;
	int a,b;
	cin>>a>>b;
	string u;
	cin>>u;
	if(s==u) cout<<a-1<<" "<<b<<endl;
	else cout<<a<<" "<<b-1<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <string>
#include <cstdio>
#include <cmath>
using namespace std;
const int N = 2e5 + 100;
int x[N], n, k;
int main()
{
    int ans = 1e9;
    cin >> n >> k;
    for (int i = 1; i <= n; i++)
        scanf("%d", &x[i]);
    for (int i = 1; i <= n - k + 1; i++)
    {
        int l = i, r = i + k - 1;
        if (x[l] <= 0 && x[r] <= 0)
            ans = min(ans, -x[l]);
        else if (x[l] >= 0 && x[r] >= 0)
            ans = min(ans, x[r]);
        else
        {
            ans = min(ans, x[r] + x[r] - x[l]);
            ans = min(ans, -x[l] + x[r] - x[l]);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
h,w=gets.split.map &:to_i
a=[[-1]*(w+1)]
h.times{a<<[-1]+gets.chomp.chars.map{|c|c=='#'?-1:0}}
a[1][1]=1
(1..h).each{|i|(1..w).each{|j|a[i][j]=[a[i][j-1],0].max+[a[i-1][j],0].max if (i>1||j>1)&&a[i][j]>=0}}
p a[h][w]%(10**9+7)

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

int main() {
  int n;
  cin >> n;
  
  vector<int> x(n);
  rep(i, n) cin >> x[i];
  
  int x2 = 0;
  rep(i, n) x2 += pow(x[i], 2);
  
  int xp = 0;
  rep(i, n) xp += x[i];
  
  int mini = 1000000000;
  for(int i = 1; i <= 100; ++i) {
    mini = min(mini, (int)(x2 + (n * pow(i, 2)) - (2 * i * xp)));
  }
  
  cout << mini << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  string s;
  cin >> s;
  for(int i = 0;i < 3;i++){
    if(s[i] == '1')cout << 9;
    else if(s[i] == '9')cout << 1;
    else cout << s[i];
  }
  cout << endl;
}

Measured memory_bytes: 3604
#include<cstdio>
#include<iostream>
using namespace std;
int main()
{
	int sum=1,N,K,i;
	cin >> N >> K;
	for(i=0;i<N;i++)
	{
		if(i==0) sum*=K;
		else sum*=K-1;
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
#define ALL(v) (v).begin(), (v).end()


int main() {
    ll N;
    cin>>N;
    VVL A(N,VL(2,0));
    rep(i,0,N){
        cin>>A[i][1];
        A[i][0]=i+1;
    }
    sort(A.begin(),A.end(),
    [](const VL &alpha,const VL &beta)
    {return alpha[1]<beta[1];});
    rep(i,0,N){
        cout<<A[i][0];
        if(i!=N-1)cout<<" ";
        else if(i==N-1)cout<<endl;
    }
    return 0;
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

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

    ll N;
    cin >> N;
    vector<ll> x(N), y(N);
    REP(i, N) cin >> x[i] >> y[i];
    multiset<pll> st;
    REP(i, N)REP(j, N){
    	if(i>=j) continue;
    	st.insert({x[j]-x[i], y[j]-y[i]});
    }

    ll ma = 0;
    REP(i, N)REP(j, N){
    	ll p = x[i] - x[j];
    	ll q = y[i] - y[j];

    	ll tmp = 0;
    	tmp += st.count({p, q});
    	tmp += st.count({-p, -q});
    	ma = max(tmp, ma);
    }
    cout << N - ma << endl;
    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
const long long INF = 1e7 + 1;
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector < pair<ll, ll > > vp;
typedef vector <string> vs;
typedef vector <char> vc;
typedef list <ll> lst;

ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;

#define Endl endl


/*--------------------template--------------------*/

int main()
{
	vi v(4);
	REP(i, 4)
	{
		cin >> v[i];
	}
	cin >> n;
	ll a, b, c;
	a = v[0] * 4;
	b = v[1] * 2;
	c = v[2];
	ll one = min(min(a, b), c);
	ll two;
	if (one * 2 > v[3]) {
		two = v[3];
	} else {
		two = one * 2;
	}
	if (n % 2 == 0) {
		ans = n / 2 * two;
	} else {
		ans = n / 2 * two + one;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstddef>
#include <complex>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <array>
#include <list>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <limits>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <bitset>
#include <valarray>
#include <utility>
#include <tuple>
#include <cmath>
#include <memory>
#include <random>
#include <fstream>
#include <locale>

using ll = long long;
using ull = unsigned long long;

//vector
template <class T>
using vec = std::vector<T>;

template <class T>
using vvec = vec<vec<T>>;

constexpr std::size_t operator""_sz(ull n) { return std::size_t(n); }

int main()
{
	using namespace std;

	int n;
	cin >> n;

	vec<int> A(n), B(n), C(n-1);
	for (auto& e : A)
		cin >> e;
	for (auto& e : B)
		cin >> e;
	for (auto& e : C)
		cin >> e;

	int ans{};

	for (auto e : A)
		ans += B[e - 1];

	for (int i = 0; i < n - 1; ++i)
	{
		if (A[i + 1] - A[i] == 1)
			ans += C[A[i] - 1];
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int H,W;
  while(1){
    cin >> W >> H ;
    if (0<H&&0<W){
      for(int j=0; j<W; j++){
        for(int i=0; i<H; i++){
          if ((i+j)%2==0){
            cout << '#';
          }else {
            cout << '.';
          }
        }
        cout << endl;
      }
      cout << endl;
    }else if (H==0&&W==0){
      break;
    }
    
    
    
  }
  
  
}



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

#define NEW(p,n){p=malloc((n)*sizeof(p[0]));if(p==NULL){printf("not enough memory\n");exit(1);};}
//pの型の変数n個の要素分のメモリを確保し、そのアドレスをpに代入するマクロ

#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))

typedef struct{
    long point;
    int num;
    long comp_point;
}question;

int main(void){
    int D;
    long G;
    scanf("%d%ld",&D,&G);

    //Q[0]~Q[D-1]に格納する
    question* Q;
    NEW(Q,D);
    for(int i=0;i<D;i++){
        Q[i].point=(i+1)*100;
        scanf("%d%ld",&Q[i].num,&Q[i].comp_point);
    }

    int ans=1000000000;
    //tのiビット目が1→全部とく、0→全部はとかない
    for(int t=0;t<(1<<D);t++){
        int tmp=0;
        int pnt=0;
        //全部とくものを処理
        for(int i=0;i<D;i++){
            if(t&(1<<i)){
                tmp+=Q[i].num;
                pnt+=Q[i].point*Q[i].num+Q[i].comp_point;
            }
        }
        if(pnt>=G){
            ans=MIN(ans,tmp);
            continue;
        }

        //全部はとかないものを処理
        for(int i=D-1;i>=0;i--){
            if(!(t&(1<<i))){
                int q_num=(G-pnt)/Q[i].point;
                if((G-pnt)%Q[i].point!=0) q_num++;

                //その問題を全部解いてもG点にできないものはアウト
                if(q_num>=Q[i].num) continue;
                //OKな場合は処理
                else{
                    tmp+=q_num;
                    ans=MIN(ans,tmp);
                    break;
                }
            }
        }
    }
    printf("%d\n",ans);

    return 0;
}

Measured memory_bytes: 256