akhauriyash/Code-Regression huggingface dataset:
use std::cmp::min;

#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

#[allow(unused_macros)]
macro_rules! max {
    ($x:expr) => {
      $x
    };
    ($x:expr, $($xs:tt)+) => {
      max($x,max!($($xs)+))
    };
  }

#[allow(unused_macros)]
macro_rules! min {
    ($x:expr) => {
      $x
    };
    ($x:expr, $($xs:tt)+) => {
      min($x,min!($($xs)+))
    };
  }

use std::ascii::AsciiExt;
use std::collections::VecDeque;
use std::io::Write;
use std::iter::Iterator;

fn main() {
    input! {
        h:usize,
        n:usize,
        a_b:[(usize, usize);n],
    }

    //dp[i+1][j+k*Ai] = min(...., d[i][j] + kBi)
    //→dp[i+1][j] = min(dp[i][j], dp[i+1][j-Ai] + Bi)

    let mut dp = vec![1001001001; h+1];
    dp[0] = 0;
    for i in 0..n{
        for j in 0..h {
          let nj = min!(j+a_b[i].0, h);
          dp[nj] = min!(dp[nj], dp[j] + a_b[i].1);
        }
    }
    println!("{}",dp[h]);
}


Measured memory_bytes: 4352
s=gets.chomp.split("")
dp = Array.new(s.size + 1).map{Array.new(4,0)}

MOD = 1000000007

dp[0][0] = 1
s.each_with_index do |c, i|
    case c
    when 'A'
        dp[i+1][0] += dp[i][0]
        dp[i+1][1] += dp[i][1]
        dp[i+1][2] += dp[i][2]
        dp[i+1][3] += dp[i][3]
        dp[i+1][1] += dp[i][0]
    when 'B'
        dp[i+1][0] += dp[i][0]
        dp[i+1][1] += dp[i][1]
        dp[i+1][2] += dp[i][2]
        dp[i+1][3] += dp[i][3]
        dp[i+1][2] += dp[i][1]
    when 'C'
        dp[i+1][0] += dp[i][0]
        dp[i+1][1] += dp[i][1]
        dp[i+1][2] += dp[i][2]
        dp[i+1][3] += dp[i][3]
        dp[i+1][3] += dp[i][2]
    when '?'
        dp[i+1][0] += dp[i][0] * 3 % MOD
        dp[i+1][1] += dp[i][1] * 3 % MOD
        dp[i+1][2] += dp[i][2] * 3 % MOD
        dp[i+1][3] += dp[i][3] * 3 % MOD
        dp[i+1][1] += dp[i][0]
        dp[i+1][2] += dp[i][1]
        dp[i+1][3] += dp[i][2]
    end
end
#p dp
puts dp[s.size][3] % MOD


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

public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in);) {
            new Main().solve(sc);
        }
    }

    void solve(Scanner sc) {
        int n = sc.nextInt();
        int c = sc.nextInt();
        int k = sc.nextInt();
        int[] ts = new int[n];
        for (int i = 0; i < n; i++) {
            ts[i] = sc.nextInt();
        }

        Arrays.sort(ts);

        int ans = 0;
        int departT = ts[0] + k;
        int count = 1;
        for (int i = 1; i < n - 1; i++) {
            if (ts[i] > departT) {
                ans++;
                count = 0;
                departT = ts[i] + k;
            }

            count++;
            if (count == c) {
                ans++;
                count = 0;
                departT = ts[i + 1] + k;
            }
        }

        if (ts[n - 1] > departT) {
            ans++;
            count = 0;
        }

        ans++;
        System.out.println(ans);
    }
}


Measured memory_bytes: 50384
#include <iostream>
#include <algorithm>
using namespace std;
int T[100000];
int main( void )
{
  ios::sync_with_stdio(false);
  int N, C, K;
  cin >> N >> C >> K;
  for( int i=0; i<N; i++ ){
    cin >> T[i];
  }
  sort( T, T+N );
  int ret = 0;
  int idx = 0;
  for( int i=1; i<N; i++ ){
    if( i - idx >= C ){
      ret++;
      idx = i;
    } else if( T[idx] + K < T[i] ){
      ret++;
      idx = i;
    }
  }
  ret++;
  cout << ret << endl;
}

Measured memory_bytes: 640
package main
import(
  "fmt"
)
func main(){
  var x, y, i, j int 
  fmt.Scan(&x, &y)
  for i=0;i<100;i++{
    for j=0;j<100;j++{
      if 2*i+4*j==y&&i+j==x{
        fmt.Println("Yes")
        return
      }
    }
  }
  fmt.Println("No")
}


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

int main(){
    int N;
    cin >> N;
    int A[N];
    int B[N];
    for(int i =0; i < N; i++){
        cin >> A[i];
        B[i] = A[i];
    }
    sort(B, B + N);
    int Max = B[N-1];
    int next = B[N - 2];
    for(int i =0; i < N; i++){
        if(A[i] == Max) cout << next << endl;
        else cout << Max << endl;
    }
    return 0;
}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll c,d,g,q;
ll gcd(ll a,ll b){
	if(b==0)return a;
	return gcd(b,a%b);
}
ll f(ll x){
	return x/c+x/d-x/q;
}
int main(){
	ll a,b;cin>>a>>b>>c>>d;
	g=gcd(c,d);
	q=c/g*d;
	cout<<b-a+1-f(b)+f(a-1);
	return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

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

      String[] line = br.readLine().split(" ");
      Point2D p1 = new Point2D(Double.parseDouble(line[0]), Double.parseDouble(line[1]));
      Point2D p2 = new Point2D(Double.parseDouble(line[2]), Double.parseDouble(line[3]));

      System.out.printf("%.8f",p1.distance(p2));
    }
  }
}

class Point2D {
  double x;
  double y;

  public Point2D(double x,double y) {
    this.x = x;
    this.y = y;
  }

  public double distance(Point2D p) {
    return Math.sqrt(Math.pow((p.x - this.x),2) + Math.pow((p.y - this.y), 2));
  }
}


Measured memory_bytes: 24956
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

//long longのシフト演算には気をつけよう

int dp[101][4][4][4];


int main(){
    int N; cin >> N;
    int mod = 1000000007;

    dp[0][3][3][3] = 1;

    for(int len=0; len<N; len++){
        for(int i=0; i<4; i++){
            for(int j=0; j<4; j++){
                for(int k=0; k<4; k++){
                    if(dp[len][i][j][k] == 0) continue;

                    for(int a=0; a<4; a++){
                        
                        if(j == 0 && k == 1 && a == 2) continue;
                        if(j == 1 && k == 0 && a == 2) continue;
                        if(j == 0 && k == 2 && a == 1) continue;
                        if(i == 0 && k == 1 && a == 2) continue;
                        if(i == 0 && j == 1 && a == 2) continue;

                        dp[len+1][j][k][a] += dp[len][i][j][k];
                        dp[len+1][j][k][a] %= mod;
                    }
                }
            }
        }
    }

    int ans = 0;

    for(int i=0; i<4; i++){
        for(int j=0; j<4; j++){
            for(int k=0; k<4; k++){
                ans += dp[N][i][j][k];
                ans %= mod;
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define pi pair<int, int>
#define F first
#define S second
#define PB push_back
#define EPB emplace_back
#define MP make_pair
#define d(x) cerr << #x << ":" << x << endl;
#define da(x) cerr << #x << endl; for (auto a : x) cerr << a << " "; cerr << endl;
const int MOD = 1000000007;


int main() {
	fastio();
	int a;
	cin >> a;
	cout << (a + a*a + a*a*a) << "\n";
	return 0;
}



Measured memory_bytes: 3624
#include<cstdio>
#include<algorithm>
using namespace std;

struct item{
    int weight;
    int value;
};

int n, m;
item przed[105];
long long valueDP[100005];

int main(){
    scanf("%d %d", &n, &m);
    for(int i = 1; i <= n; i++){
        scanf("%d %d", &przed[i].weight, &przed[i].value);
    }
    for(int i = 1; i <= 100000; i++){
        valueDP[i] = 1e18;
    }
    for(int i = 1; i <= n; i++){
        for(int j = 100000; j >= przed[i].value; j--){
            valueDP[j] = min(valueDP[j], valueDP[j - przed[i].value] + (long long)przed[i].weight);
        }
    }
    int wynik = 0;
    for(int i = 0; i <= 100000; i++){
        if(valueDP[i] <= (long long)m) wynik = i;
    }
    printf("%d", wynik);
    return 0;
}


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

int digits(long long x){
  ostringstream oss;
  oss << x;
  return oss.str().length();
}

int main(){
  long long n;
  cin >> n;
  int minV = 10;
  for ( long long i = 1; i <= floor(sqrt(n)); i++){
    if ( n % i == 0){
      minV = min(minV, digits(n/i));
    }
  }

  cout << minV << endl;

  return 0;
}

Measured memory_bytes: 256
N=int(input())
L=list(map(int,input().split()))
ans=0
for i in range(N):
    for j in range(i+1,N):
        for k in range(j+1,N):
            a,b,c=sorted([L[i],L[j],L[k]])
            if a!=b!=c:
                if c<a+b:
                    ans+=1
print(ans)

Measured memory_bytes: 9192
N, Y = map(int, input().split())

o_sum = Y//1000
o_1 = Y//1000
o_5 = 0
o_10 = 0

f = 0
while(1):
    #print(N, o_sum, o_10, o_5, o_1)                                                                                   
    if o_sum == N:
        break
    else:
        if o_sum - N >= 4:
            if o_1 >= 5:
                o_5 += 1
                o_1 -= 5
            elif o_5 >= 2:
                o_5 -= 2
                o_10 += 1
            else:
                f = 1
                break
        else:
            if o_5 >= 2:
                o_5 -= 2
                o_10 += 1
            else:
                f = 1
                break
    o_sum = o_1 + o_5 + o_10

if f == 0:
    print(o_10, o_5, o_1)
else:
    print(-1, -1, -1)


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

using namespace std;

int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  set<int> st;
  for (int i = 0; i < n; ++i) {
    st.insert(k + i);
  }
  vector<tuple<int, int, int>> ans;
  int c = k + 3 * n - 1;
  for (int i = n - 1; i >= 0; i -= 2) {
    int b = k + n + i;
    auto it = st.lower_bound(c - b + 1);
    if (it == st.begin()) {
      puts("-1");
      return 0;
    }
    --it;
    int a = *it;
    st.erase(it);
    ans.emplace_back(a, b, c);
    --c;
  }
  for (int i = n - 2; i >= 0; i -= 2) {
    int b = k + n + i;
    auto it = st.lower_bound(c - b + 1);
    if (it == st.begin()) {
      puts("-1");
      return 0;
    }
    --it;
    int a = *it;
    st.erase(it);
    ans.emplace_back(a, b, c);
    --c;
  }
  for (auto it : ans) {
    int a, b, c;
    tie(a, b, c) = it;
    printf("%d %d %d\n", a, b, c);
  }
  return 0;
}


Measured memory_bytes: 6520
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
const int IINF = INT_MAX;

int n;
bool semi[1005];
vector<vector<P> > g;

// 頂点curを残すときの最小値
int rec(int cur, int pre){
    if(semi[cur]) return IINF;

    int res = 0;
    for(auto e : g[cur]){
        int to = e.first, cost = e.second;
        if(to == pre)continue;
        res += min(cost, rec(to, cur));
    }
    return res;
}

int main() {
    cin >> n;
    g.resize(n);
    for(int i=0;i<n-1;i++){
        int c;
        cin >> c;
        semi[i+1] = c > 0;
    }
    for(int i=0;i<n-1;i++){
        int u, v, p;
        cin >> u >> v >> p;
        g[u].push_back({v,p});
        g[v].push_back({u,p});
    }
    cout << rec(0,-1) << endl;
    return 0;
}


Measured memory_bytes: 3172
#include <stdio.h>



//�Q����o�͂���
double pow_2(double a){
  return a*a;
}

int main(void){

  int N;
  scanf("%d",&N);
  int X[N], i,ans;
  for(i=0;i<N;i++)
    scanf("%d",&X[i]);
  
  int M=0,count=0;
  for(i=0;i<N;i++)
    M+=X[i];
  
  ans=(double)M/(double)N+0.5;

  for(i=0;i<N;i++){
    count+=pow_2(X[i]-ans);
  }
  printf("%d",count);
  return 0;
}


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

int main(){
   int n;
   cin >> n;
   vector<int> p(n);
   for (int i=0; i<n; i++)
      cin >> p.at(i);

   int cnt = 0;
   for (int i=1; i<n-1; i++)
      if (p.at(i-1) < p.at(i) && p.at(i) < p.at(i+1))
         cnt++;
      else if (p.at(i-1) > p.at(i) && p.at(i) > p.at(i+1))
         cnt++;

   cout << cnt << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
using namespace std;
using llong = long long;

llong x, y, a, b, c;
priority_queue<llong> red;
priority_queue<llong> green;
priority_queue<llong> alpha;
priority_queue<llong, vector<llong>, greater<llong>> pq;

int main() {

    cin >> x >> y >> a >> b >> c;
    for (int i = 0; i < a; i++) {
        llong x;
        cin >> x;
        red.push(x);
    }
    for (int i = 0; i < b; i++) {
        llong x;
        cin >> x;
        green.push(x);
    }
    for (int i = 0; i < c; i++) {
        llong x;
        cin >> x;
        alpha.push(x);
    }

    llong ans = 0;
    for (int i = 0; i < x; i++) {
        ans += red.top();
        pq.push(red.top());
        red.pop();
    }
    for (int i = 0; i < y; i++) {
        ans += green.top();
        pq.push(green.top());
        green.pop();
    }

    while (!alpha.empty() && !pq.empty() && alpha.top() > pq.top()) {
        ans -= pq.top();
        ans += alpha.top();
        pq.pop();
        alpha.pop();
    }
    
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 5876
H, W = map(int,input().split())
s = [list(input()) for j in range(H)]

def bfs(h, w):
    checked = [[False for i in range(W)] for j in range(H)]
    q = [(h, w, 0)] if s[h][w] == '.' else []
    checked[h][w] = True
    g_n = 0
    while q:
        h_, w_, n = q.pop(0)
        g_n = max(n, g_n)
        for i, j in zip([0,0,-1,1],[-1,1,0,0]):
            if (0 <= h_+i < H) and (0 <= w_+j < W):
                if checked[h_+i][w_+j]: continue
                checked[h_+i][w_+j] = True
                if s[h_+i][w_+j] == '.': q.append((h_+i, w_+j, n+1))
    return g_n

n = 0
for i in range(H):
    for j in range(W):
        n = max(n, bfs(i,j))

print(n)

Measured memory_bytes: 9260
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter
import kotlin.math.min

val br = BufferedReader(InputStreamReader(System.`in`))
val out = PrintWriter(System.out)

fun main() {
    br.use { out.use {
        solve()
        out.flush()
    } }
}

fun solve() {
    val (n, c) = readIntegerList()
    val changeCostArrays = Array(c) { readIntegerList() }
    val colorArrays = Array(n) { readIntegerList().map { it - 1 } }

    val changeCosts = Array(3) { IntArray(c) }
    for (h in 0 until n) {
        for (w in 0 until n) {
            val index = (h + w) % 3
            val currentColor = colorArrays[h][w]
            for (color in 0 until c) {
                changeCosts[index][color] += changeCostArrays[currentColor][color]
            }
        }
    }

    var ans = Int.MAX_VALUE
    for (c1 in 0 until c) {
        for (c2 in 0 until c) {
            for (c3 in 0 until c) {
                if (c1 != c2 && c2 != c3 && c3 != c1) {
                    ans = min(ans, changeCosts[0][c1] + changeCosts[1][c2] + changeCosts[2][c3])
                }
            }
        }
    }
    out.println(ans)
}

fun readInteger() = Integer.parseInt(br.readLine())
fun readLong() = java.lang.Long.parseLong(br.readLine())
fun readStringList() = br.readLine()!!.split(' ')
fun readIntegerList() = readStringList().map(Integer::parseInt)
fun readLongList() = readStringList().map(java.lang.Long::parseLong)
fun readDoubleList() = readStringList().map(java.lang.Double::parseDouble)


Measured memory_bytes: 59684
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_C main
#include "bits/stdc++.h"
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
using psi = pair<string, int>;
// functions

#endif


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

    int N;  cin >> N;

    vi A(N); 
    int lo = INF, hi = -INF;
    REP(i, N) {
        cin >> A[i];
        lo = min(lo, A[i]);
        hi = max(hi, A[i]);
    }

    int ans = INF;
    for(int i = lo; i <= hi; i++) {
        int cost = 0;
        REP(j,N) {
            cost += (A[j] - i)*(A[j] - i);
        }
        ans = min(ans, cost);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

const int N = (int)1e5 + 1;

int ce[N], co[N];

int main() {
  int n;
  cin >> n;
  rep(i, n/2) {
    int e, o;
    cin >> e >> o;
    ce[e]++;
    co[o]++;
  }

  int me1 = 0, ie, me2, mo1 = 0, io, mo2;
  rep(i, N) {
    if(me1 <= ce[i]) {
      me2 = me1;
      me1 = ce[i];
      ie = i;
    } else if (me2 <= ce[i]) {
      me2 = ce[i];
    }
    if(mo1 <= co[i]) {
      mo2 = mo1;
      mo1 = co[i];
      io = i;
    } else if (mo2 <= co[i]) {
      mo2 = co[i];
    }
  }

  int res;
  if(ie != io) res = n - (me1 + mo1);
  else res = n - max(me1 + mo2, me2 + mo1);
  
  cout << res << endl;
  return 0;
}


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

#define PI 3.14159265359
#define INF 1e9
#define LINF 1e18
#define IMOD 1000000007 
#define irep(i,n) for(int i = 0; i < (int)(n); i++)
#define irep2(i,a,n) for(int i = (int)(a); i <= (int)(n); i++)
#define lrep(i,n) for(long long  i = 0; i < (long long)(n); i++)
#define lrep2(i,a,n) for(long long i = (long long)(a); i <= (long long)(n); i++)

#define irrep(i,n) for(int i = (int)(n); i > -1; i--)
#define irrep2(i,a,n) for(int i = (int)(n); i >= (int)(a); i--)

typedef long long ll;
typedef std::vector<char> v_char;
typedef std::vector<double> v_double;
typedef std::vector<std::vector<double> > v2_double;
typedef std::vector<int> v_int;
typedef std::vector<std::vector<int> > v2_int;
typedef std::vector<ll> v_ll;
typedef std::vector<std::vector<ll> > v2_ll;
typedef std::vector<std::string> v_string;
typedef std::vector<std::vector<std::string> > v2_string;
typedef std::vector<bool> v_bool;
typedef std::vector<std::vector<bool> > v2_bool;
typedef std::pair<ll, ll> pll;
typedef std::pair<int, int> pii;

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

using namespace std; 

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


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

int cost[10][10];

int main(){
    int h,w;
    cin >> h >> w;
    rep(i,10) rep(j,10) cin >> cost[i][j];
    int a[h][w];
    rep(i,h) rep(j,w) cin >> a[i][j];
    rep(k,10){
        rep(i,10){
            rep(j,10){
                cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
            }
        }
    }
    int all_cost = 0;
    rep(i,h){
        rep(j,w){
            if(a[i][j] != -1) all_cost += cost[a[i][j]][1];
        }
    }
    cout << all_cost << endl;
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;;
#define ll long long
#define rep(i, n) for(int i = 0;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define INF 1<<30
#define LINF 1LL<<62
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define pb push_back
const int MOD = 1000000007;
 
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  long double w,h,x,y;
  cin >> w >> h >> x >> y;
  cout << w*h/2.0 << " ";
  if((x * 2 == w && y * 2 == h) || (x*2 == h && y *2 == w) )cout << 1 << endl;
  else cout << 0 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define print(x)cout<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

ll n;
vl ans;
void dfs(int k, ll x){
  if(x > n)return;
  string s = to_string(x);
  vi chk(3,0);
  rep(i,sz(s)){
    if(s[i] == '3')chk[0]++;
    if(s[i] == '5')chk[1]++;
    if(s[i] == '7')chk[2]++;
  }
  if(chk[0]>0 && chk[1]>0 &&chk[2]>0)
  {
    //print(x);
    ans.push_back(x);
  }
  
  ll a = 3*pow(10,k)+x;
  ll b = 5*pow(10,k)+x;
  ll c = 7*pow(10,k)+x;
  dfs(k+1,a);
  dfs(k+1,b);
  dfs(k+1,c);
}

int main() {
  cin >> n;
  dfs(1,3);
  dfs(1,5);
  dfs(1,7);
  //for(auto e: ans)print(e);
  print(sz(ans));
  return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define ll long long
#define int long long
#define sz(c) c.size()
#define fr first
#define sc second
#define pb push_back
#define sz(c) c.size()
#define ppb  pop_back
#define all(a)      (a).begin(),(a).end()
#define rep(i,a,n)   for( int i=a ; i<n ; i++)
#define U 1000000007
#define N 100005
#define ins insert
using namespace std;
signed main()
{
  ios_base::sync_with_stdio(false);
  int n;
  cin>>n;
  int a[n];
  rep(i,0,n) cin>>a[i];
  int dp[n];
  dp[0]=0;
  dp[1]=abs(a[1]-a[0]);
  rep(i,2,n) dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),
                      dp[i-2]+abs(a[i-2]-a[i]));

  cout<<dp[n-1];



}

Measured memory_bytes: 1792
N=int(input())
ans=1000000
for i in range(1,N):
    ans=min((i%10)+((i//10)%10)+((i//100)%10)+((i//1000)%10)+((i//10000)%10)+((i//100000)%10)+((i//1000000)%10)+((N-i)%10)+(((N-i)//10)%10)+(((N-i)//100)%10)+(((N-i)//1000)%10)+(((N-i)//10000)%10)+(((N-i)//100000)%10)+(((N-i)//1000000)%10),ans)
print(ans)

Measured memory_bytes: 3064
#include<iostream>
using namespace std;
int main()
{
    // 整数の入力
    int n;
    cin >> n;
    // スペース区切りの整数の入力
    int a[n] = {0};
    for(int i =0;i<n-1;i++){
        int b = 0;
        cin >> b;
        a[b - 1] += 1;
    }
    for(int i =0;i<n;i++){
        cout << a[i] << endl;;
    }
    return 0;
}


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

int n;
vector<vector<int> > x(15,vector<int>(15)),y(15,vector<int>(15));
vector<int> a(15);

bool judge(int bit){
    for(int i=0;i<n;i++){
        if( !(bit & (1<<i)))continue;
        for(int j=0;j<a[i];j++){
            int X = x[i][j]-1;
            int Y = y[i][j];
            //正直ではないのに正直者として仮定されている
            if(Y==0 && (bit & (1<<X)))return false;
            //正直なのに、正直者として仮定されていない
            if(Y==1 && !(bit & (1<<X)))return false;
        }
    }
    return true;
}

int main(void){
   cin >> n;
   for(int i=0;i<n;i++){
       cin>>a[i];
       for(int j=0;j<a[i];j++){
           cin >> x[i][j] >> y[i][j];
       }
   }

   int count = 0;
   //正直者を全探索する
   for (int bit = 0; bit < (1<<n); ++bit) {
       
       //矛盾チェック
       if(judge(bit)){
           int res =0;
           for(int i=0;i<n;i++){
               if (bit & (1 << i)) ++res;
           }
           count = max(res,count);
       }
    }
    cout << count << endl;
}


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

using namespace std;
typedef long long ll;
typedef long double ld;


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

    int k;
    string s;
    cin >> k >> s;
    if(s.size() <= k)
        cout << s;
    else{
        string ans = "";
        for(int i = 0; i < k; i++)
         ans += s[i];
        ans += "...";
        cout << ans;
    }


}

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

using namespace std;

long int a, b, c ,d;

void solve() {
    long int ans = a * c;
    if (a * d > ans){
        ans = a * d;
    }

    if (b * c > ans){
        ans = b * c;
    }

    if (b * d > ans){
        ans = b * d;
    }

    cout << ans;

}

int main(){
    cin >> a >> b >> c >> d;
    solve();

}

Measured memory_bytes: 3620
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MisteriousGems
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                int n = int.Parse(Console.ReadLine());
                if (n == 0) break;
                Field field = new Field();
                for (int i = 0; i < n; i++)
                {
                    string[] strs = Console.ReadLine().Split(' ');
                    field.CreateGem(int.Parse(strs[0]), int.Parse(strs[1]));
                }

                Robot robot = new Robot(field);
                n = int.Parse(Console.ReadLine());
                for (int i = 0; i < n; i++)
                {
                    string[] strs = Console.ReadLine().Split(' ');
                    robot.Operate(strs[0], int.Parse(strs[1]));
                }
                if (robot.IsComplete()) Console.WriteLine("Yes");
                else Console.WriteLine("No");
            }
        }
    }

    public class Robot
    {
        private Field field;
        private int x;
        private int y;

        public Robot(Field field)
        {
            x = 10;
            y = 10;
            this.field = field;
        }

        public void Operate(String way, int distance)
        {
            for (int i = 0; i < distance; i++)
            {
                FindGem();
                switch (way)
                {
                    case "N":
                        y ++;
                        break;
                    case "E":
                        x ++;
                        break;
                    case "S":
                        y --;
                        break;
                    case "W":
                        x--;
                        break;
                }
                FindGem();
            }
        }

        public bool IsComplete()
        {
            return field.IsComplete();
        }

        private void FindGem()
        {
            field.FindGem(x, y);
        }


    }

    public class Field
    {
        private bool[,] gemsMap;

        private const int SIZE = 21;

        public Field()
        {
            gemsMap = new bool[SIZE, SIZE];
        }

        public void FindGem(int x, int y)
        {
            gemsMap[x, y] = false;
        }

        public void CreateGem(int x, int y)
        {
            gemsMap[x, y] = true;
        }

        public bool IsComplete()
        {
            for (int y = 0; y < SIZE; y++)
            {
                for (int x = 0; x < SIZE; x++)
                {
                    if (gemsMap[x, y]) return false;
                }
            }
            return true;
        }
    }
}

Measured memory_bytes: 20036
// Template
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#include <map>
#include <set>
#include <algorithm>
#include <utility>
#include <cmath>
#include <complex>
#define rep(i, x) for (int i = 0; i < (x); ++i)
#define rng(i, x, y) for (int i = (x); i < (y); ++i)
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
constexpr int inf = 1001001001;
constexpr ll INF = 3003003003003003003;
template <typename T> inline bool chmin(T &x, const T &y) {if (x > y) {x = y; return 1;} return 0;}
template <typename T> inline bool chmax(T &x, const T &y) {if (x < y) {x = y; return 1;} return 0;}
void solve();
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    solve();
    return 0;
}

// Main Code
int fact_2_num(int x) {
    int ans = 0;
    rep(i, 30) ans += x / (1 << i);
    return ans;
}

int comb_mod2(int x, int y) {
    if (fact_2_num(x) == fact_2_num(y) + fact_2_num(x - y)) return 1;
    else return 0;
}

void solve() {
    int n;
    cin >> n;
    vector<char> a(n);
    rep(i, n) {
        cin >> a[i];
        --a[i];
    }
    
    int mod2 = 0;
    rep(i, n) {
        if (comb_mod2(n - 1, i)) mod2 += (a[i] - '0');
    }
    if (mod2 & 1) {
        cout << 1 << "\n";
        return;
    }
    
    
    vector<int> cnt(3, 0);
    rep(i, n) ++cnt[a[i] - '0'];
    if (cnt[0] == 0 || cnt[2] == 0) {
        cout << 0 << "\n";
        return;
    }
    if (cnt[1]) {
        cout << 0 << "\n";
        return;
    }
    
    mod2 = 0;
    rep(i, n) {
        if (comb_mod2(n - 1, i)) mod2 += (a[i] - '0') / 2;
    }
    mod2 %= 2;
    cout << mod2 * 2 << "\n";
    return;
}


Measured memory_bytes: 4260
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;

int main() {
    int ok = 0;
    string S;
    cin >> S;

    for (int i = 0; i < S.size(); i++) {
        if (i % 2 == 0) {
            if (S.at(i) == '0') {
                ok++;
            }
        }
        else {
            if (S.at(i) == '1') {
                ok++;
            }
        }
    }
    int a = S.size();
    cout << min(a - ok, ok) << endl;
}


Measured memory_bytes: 512
import sys, os

def f():
    args = list(map(int,input().split()))
    if len(args) > 1:
        return args
    return args[0]

if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    n,m,x = f()
    data = []
    for i in range(n):
        data.append(f())
    
    ans = 10**8
    for i in range(1<<n):
        cursummoney = 0
        curleve = [0] * m
        for j in range(n):
            if i&(1<<j):
                cursummoney += data[j][0]
                for k in range(m):
                    curleve[k] += data[j][1+k]
        ok = 1
        for j in range(m):
            if curleve[j] < x:
                ok = 0
        
        if ok:
            ans = min(ans, cursummoney)
    
    if  ans != 10**8:
        print(ans)
    else:
        print(-1)
    



solve()

Measured memory_bytes: 9244
// AOJ ALDS1_13_B 8 Puzzle
// 2018.5.8 bal4u

#include <stdio.h>

typedef unsigned char uchar;

#define HASHSIZ 543217
typedef struct { unsigned s; char x, v; } HASH;
HASH hash[HASHSIZ+3], *hashend = hash+HASHSIZ;

int lookup(unsigned s, int x)
{
	long long t = ((long long)x << 32) + s;
	HASH *hp = hash + (int)(t % HASHSIZ);
	while (hp->s) {
		if (hp->s == s && hp->x == x) return hp->v;
		if (++hp == hashend) hp = hash;
	}
	return -1;
}

void insert(unsigned s, int x, char v)
{
	long long t = ((long long)x << 32) + s;
	HASH *hp = hash + (int)(t % HASHSIZ);
	while (hp->s) {
		if (hp->s == s && hp->x == x) { hp->v = v; break; }
		if (++hp == hashend) hp = hash;
	}
	hp->s = s, hp->x = x, hp->v = v;
}

#define QMAX 50000
typedef struct { unsigned s; char x, v; } T;
T s[QMAX+3]; int top, end;
int hi[9] = {2,3,2,3,4,3,2,3,2};
int to[9][4] = {{1,3},{0,2,4},{1,5},{0,4,6},{1,3,5,7},{2,4,8},{3,7},{4,6,8},{5,7}};

void toArray(char *nine, unsigned s, int x)
{
	int i;
	
	for (i = 8; i >= 0; i--) {
		if (i == x) nine[i] = 0;
		else nine[i] = s & 0xf, s >>= 4;
	}
}

unsigned swap(char *nine, int zero, int nx)
{
	int i;
	unsigned res;
	
	res = 0;
	for (i = 0; i < 9; i++) {
		if      (i == zero) res <<= 4, res |= nine[nx];
		else if (i != nx)   res <<= 4, res |= nine[i];
	}
	return res;
}

int main()
{
	int i;
	int x, nx, v, nv, t;
	unsigned a, na;
	unsigned gs; int gx;	// goal
	char nine[9];
	
	gs = 0; for (i = 0; i < 9; i++) {
		scanf("%d", &t);
		if (t == 0) gx = i;
		else gs <<= 4, gs |= t;
	}
	s[0].s = 0x12345678, s[0].x = 8, s[0].v = 0;
	top = 0, end = 1;
	insert(s[0].s, s[0].x, 0);
	while (top != end) {
		a = s[top].s, x = s[top].x, v = s[top].v;
		if (++top == QMAX) top = 0; 
		if (x == gx && a == gs) break;

		toArray(nine, a, x);
		for (i = 0; i < hi[x]; i++) {
			nx = to[x][i];
			na = swap(nine, x, nx), nv = v+1;
			t = lookup(na, nx);
			if (t < 0 || nv < t) {
				s[end].s = na, s[end].x = nx, s[end].v = nv;
				if (++end == QMAX) end = 0;
				insert(na, nx, nv);
			}
		}
	}
	printf("%d\n", v);
	return 0;
}



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

class Item {
   int weight, val;
   public Item(int weight, int val) {
      this.weight = weight;
      this.val = val;
   }
}
public class Main {
  
  
  public static void main(String []abc) {
     Main sol = new Main();
	 long answer=sol.solve();
     System.out.println(answer);
  }
  
  private long solve() {
     Scanner sc = new Scanner(System.in);
     int N = sc.nextInt();
     int maxWeight = sc.nextInt();
     int maxValue = 1000*N;
     long [][] dp = new long[N+1][maxValue+1];
     long INF = (long) 1e9+1;
     for(int i=0;i<=maxValue;i++){
        dp[1][i] = INF;
     }
     Item []array = new Item[N+1];
     for(int i=1;i<=N;i++){
        array[i] = new Item(sc.nextInt(), sc.nextInt());
     }
     dp[1][array[1].val] = array[1].weight;
     dp[1][0] = 0;
     for(int i=2;i<=N;i++){
        for(int val=0;val<=maxValue;val++){
           dp[i][val] = dp[i-1][val];
           if (array[i].val > val) continue;
           dp[i][val] = Math.min( dp[i-1][val],
                                  array[i].weight +dp[i-1][val-array[i].val]);
        }       
     }
     long bestVal=0;
     for(int i=0;i<=maxValue;i++){
        if (dp[N][i]<=maxWeight) bestVal = Math.max(bestVal, i);
     }
     return bestVal;
  }
}


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

using namespace std;
// using P = pair<long, long>;
using P = pair<double, long>;

typedef long long int ll;

#define EPS (1e-7)
#define INF (1e18)
#define PI (acos(-1))

#define sortv(xs) sort(xs.begin(), xs.end())
#define sortvinv(xs) sort(xs.begin(), xs.end(), greater<long>())
#define lbv(xs, x) lower_bound(xs.begin(), xs.end(), x) - xs.begin()
#define ubv(xs, x) upper_bound(xs.begin(), xs.end(), x) - xs.begin()
#define bs(xs, x) binary_search(xs.begin(), xs.end(), x)
#define index_of(as, x) \
  distance(as.begin(), lower_bound(as.begin(), as.end(), x))
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define concat(xs, ys) (xs).insert((xs).end(), (ys).begin(), (ys).end())

const int mod = 1000000007;

struct Group {
  long base;
  vector<long> xs;
};

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

  int n;
  cin >> n;
  string s;
  cin >> s;

  rep(i, s.size()) {
    s[i] = (s[i] - 'A' + n) % 26 + 'A';
  }
  cout << s << endl;
}


Measured memory_bytes: 256
import math
a, b, h, m = map(int, input().split())

long = 360 * h / 12 + 360 / 12 * m / 60
short = 360 * m / 60
# long *= math.pi / 180
# short *= math.pi / 180
if True:
    theta = abs(long - short) * math.pi / 180
    B = a * math.cos(theta) - b
    A = a * math.sin(theta)
    print(math.sqrt(A*A + B*B))

Measured memory_bytes: 62332
#include "bits/stdc++.h"
using namespace std;
#define rep(i,a,b) for (int i = (a); i < (b); i++ )

int main() {
	string t;
	cin >> t;
rep(i,0,t.size()){
  if (t.at(i)=='?'){
    t.at(i)='D';
  }
	}
cout<< t<<endl;
}


Measured memory_bytes: 3756
#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 watch(x) cout<<(#x)<<"="<<(x)<<endl
#define mset(d,val) memset(d,val,sizeof(d))
#define setp(x) cout<<fixed<<setprecision(x)
#define forn(i,a,b) for(int i=a;i<b;i++)
#define fore(i,a,b) for(int i=a;i<=b;i++)
#define pb push_back
#define F first
#define S second
#define PI 3.14159265358979323846264338327
#define INF 2e14
#define MOD 998244353
#define pqueue priority_queue
#define fbo find_by_order
#define ook order_of_key
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef unsigned long long ull;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;

#define MAXN 100005

int n;
double arr[MAXN];

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	setp(6);
	
	cin>>n;
	forn(i,0,n) cin>>arr[i];
	
	double ans=0.0;
	forn(i,0,n){
		ans+=1.0/arr[i];
	}
	
	cout<<1.0/ans<<'\n';
	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <utility>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <queue>
using namespace std;

#define LL   long long
#define ld   long double
#define pii  pair<int,int>
#define pLL  pair<LL,LL>
#define vint vector<int>
#define vLL  vector<LL>

#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#define F first
#define S second
#define MP make_pair
#define PB push_back

#define Si(x) scanf("%d",&(x));
#define Sii(x,y) scanf("%d %d",&(x),&(y));
#define Siii(x,y,z) scanf("%d %d %d",&(x),&(y),&(z));
#define SL(x) scanf("%lld",&(x));
#define SLL(x,y) scanf("%lld %lld",&(x),&(y));
#define SLLL(x,y,z) scanf("%lld %lld %lld",&(x),&(y),&(z));

#define Pi(x) printf("%d\n",(x));
#define Pii(x,y) printf("%d %d\n",(x),(y));
#define Piii(x,y,z) printf("%d %d %d\n",(x),(y),(z));
#define Piiii(x,y,z,w) printf("%d %d %d %d\n",(x),(y),(z),(w));
#define Piiiii(a,b,c,d,e) printf("%d %d %d %d %d\n",(a),(b),(c),(d),(e));
#define Piiiiii(a,b,c,d,e,f) printf("%d %d %d %d %d %d\n",(a),(b),(c),(d),(e),(f));
#define PL(x) printf("%lld\n",(x)*1LL);
#define PLL(x,y) printf("%lld %lld\n",(x)*1LL,(y)*1LL);
#define PLLL(x,y,z) printf("%lld %lld %lld\n",(x)*1LL,(y)*1LL,(z)*1LL);
#define PLLLL(x,y,z,w) printf("%lld %lld %lld %lld\n",(x)*1LL,(y)*1LL,(z)*1LL,(w)*1LL);

#define Pi1(x) printf("%d",  (x));
#define PiL(x) printf("%lld",(x));
#define Pspace putchar(' ');
#define Pendl  puts("");

#define MEM0(x) memset( (x), 0, sizeof( (x) ) )
#define MEM1(x) memset( (x),-1, sizeof( (x) ) )
#define REP1(i,n)  for (int i = 1; (n) >= i ; ++i)
#define REP0(i,n)  for (int i = 0; (n) >  i ; ++i)
#define REP(L,R,k) for (int i = (L); (R) >= i; i+= (k) )

int myRnd(int L,int R) {
    return abs(( (rand()<<15)|rand() ) ) % (R-L+1) + L;
}

const int N = 1e5 + 6;
int dp[N];

int main () {
    srand(time(NULL));
    int k;
    Si(k);
    MEM1(dp);
    //REP0(i,k) {
    //    Pi1(dp[i]);
    //    Pspace;
    //}
    //Pendl;
    //dp[0] = 0;
    priority_queue<pii,vector<pii>,greater<pii> > pq;
    //pq.push({0,0});
    int ans=-1;
    for (int i=9;i>=1;i--) {
        dp[i%k] = i;
        pq.push({i,i%k});
    }
    while (!pq.empty()) {
        pii p=pq.top();
        pq.pop();
        //cout<<"p = ("<<p.F<<" , "<<p.S<<") "<<endl;
        if (dp[p.S] != p.F) continue;
        REP0(i,10) {
            int nxt=p.S*10+i;
            nxt %= k;
            //cout<<"nxt = "<<nxt<<" , p.F+i = "<<p.F+i<<endl;
            if (nxt == 0) {
                if (ans == -1) ans = p.F + i;
                else ans = min(ans,p.F+i);
            }
            else {
                if (dp[nxt] == -1) {
                    dp[nxt] = p.F + i;
                    pq.push({dp[nxt],nxt});
                }
                else if (p.F + i < dp[nxt]) {
                    dp[nxt] = p.F + i;
                    pq.push({dp[nxt],nxt});
                }
            }
        }
    }
    Pi(ans);
}



Measured memory_bytes: 2804
#include <bits/stdc++.h>
#include <unordered_set>
using namespace std;
#define printclock cerr << "Time : " << 1000 * (ld)clock() / (ld)CLOCKS_PER_SEC << "ms\n";
#define deb2(x, y) cout << #x << ": " << x << " | " << #y << ": " << y << endl
#define deb1(x) cout << #x << ": " << x << endl
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define prec(n) fixed << setprecision(n)
#define all(a) a.begin(), a.end()
#define fast                      \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0);
#define pii pair<int, int>
#define vii vector<int>
#define ld long double
#define int long long
#define MOD LLONG_MAX
#define mp make_pair
#define pb push_back
#define endl "\n";
inline void get(vector<int> &arr, int n)
{
    int a;
    for (int i = 0; i < n; i++)
    {
        cin >> a;
        arr.push_back(a);
    }
}
inline void print(vector<int> &arr, int n)
{
    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";
    cout << endl;
}
/*----------------------------------TEMPLATE------------------------------------*/
int32_t main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
    fast;
    /*----------------------------PEEPEEPOOPOO-------------------------------------*/
    int t;
    //cin >> t;
    t =1;
    while (t--)
    {
        int n;
        cin >> n;
        if(n==0)
        {
            cout << 1 << endl;
        }
        else
        {
            cout << 0 << endl;
        }
    }
    return 0;
}
/*--------------------------------PEEPEEPOOPOO-------------------------------------*/

Measured memory_bytes: 3632
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

namespace B_ABC163
{
    class MainClass
    {

        static int[] s,a;

        public static void Main(string[] args)
        {
            s = Array.ConvertAll(ReadLine().Split().ToArray(), int.Parse);
            a = Array.ConvertAll(ReadLine().Split().ToArray(), int.Parse);
            long sum = 0;
            for (int i = 0;i<s[1];i++){
                sum+=a[i];
            } 
            if(sum>s[0]){
                WriteLine(-1);
            }else{
                WriteLine(s[0]-sum);
            }
            
        }
    }
}


Measured memory_bytes: 29072
N, M = map(int,input().split())
A = list(map(int,input().split()))

#print(M)
A.sort()
#print(A)
limit = sum(A)/(4*M)
#print(limit)
count = 0
for i in range(N):
    if A[i] >= limit:
        count +=1

#print(count)

#print(N-n-1)
if count >= M:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <algorithm>
#include <set>

long sn(long n) {
  long sn = n%10;
  while (n / 10 != 0) {
    n/=10;
    sn += n%10;
  }
  return sn;
}

double nsn(long n) {
  return (double)n/(double)sn(n);
}

using namespace std;

int main() {
  long K;
  long delta = 1;
  long ans = 1;
  long count = 0;
  cin >> K;
  while (true) {
    cout << ans << endl;
    if (nsn(ans+delta) <= nsn(ans+delta*10)) {
      ans += delta;
    } else {
      delta *= 10;
      ans += delta;
    }
    count++;
    if (count >= K) {
      break;
    }
  }
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int H = sc.nextInt();
		int W = sc.nextInt();

		int[][] hw = new int[H][W];
		
		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) {
				hw[i][j] = sc.nextInt();
			}
		}
		
		List<String> ansList = new ArrayList<>();
		int counter = 0;
		for (int i = 0; i < H; i++) {
			if (i == H - 1) {
				for (int j = 0; j < W; j++) {
					if (hw[i][j] % 2 == 1) {
						if (j != W - 1) {
							hw[i][j+1]++;
							hw[i][j]--;
							counter++;
							ansList.add((i+1) + " " + (j+1) + " " + (i+1) + " " + (j+2));
						}
					}
				}
			} else {
				for (int j = 0; j < W; j++) {
					if (hw[i][j] % 2 == 1) {
						hw[i+1][j]++;
						hw[i][j]--;
						counter++;
						ansList.add((i+1) + " " + (j+1) + " " + (i+2) + " " + (j+1));
					}
				}
			}
		}
		
		System.out.println(counter);
		for (int i = 0; i < counter; i++) {
			System.out.println(ansList.get(i));
		}
		
		sc.close();
		
		
		
	}
}


Measured memory_bytes: 100268
F = [1, 1]
for i in range(7):
  F.append(F[i]+F[i+1])

h, w, k = map(int, input().split())
mod = 10**9 + 7
a = [[0 for i in range(w)] for i in range(h+1)]
a[0][0] = 1

if w == 1:
  print(1)
else:
  for i in range(h):
    for j in range(w):
      if j == 0:
        a[i+1][j] += F[w-1] * a[i][j] % mod
        a[i+1][j+1] += F[w-2] * a[i][j] % mod
      elif j==w-1:
        a[i+1][j] += F[w-1] * a[i][j] % mod
        a[i+1][j-1] += F[w-2] * a[i][j] % mod
      else:
        a[i+1][j] += F[j] * F[w-j-1] * a[i][j] % mod
        a[i+1][j+1] += F[j] * F[w-j-2] * a[i][j] % mod
        a[i+1][j-1] += F[j-1] * F[w-j-1] * a[i][j] % mod
        
  print(a[-1][k-1]%mod)

Measured memory_bytes: 3064
def solve():
    while True:
        N = int(input())
        if N==0:
            return
        firsts = [0]*(86401)
        lasts = [0]*(86401)
        for i in range(N):
            a,b = input().split()
            h,m,s = a.split(':')
            t = 0
            for i,n in enumerate([h,m,s]):
                if n[0]=='0':
                    n = n[1]
                t += int(n)*60**(2-i)
            firsts[t] += 1
            h,m,s = b.split(':')
            t = 0
            for i,n in enumerate([h,m,s]):
                if n[0]=='0':
                    n = n[1]
                t += int(n)*60**(2-i)
            lasts[t] += 1
        now = 0
        ans = 0
        for f,l in zip(firsts,lasts):
            now += f-l
            ans = max(ans,now)
        print(ans)
solve()



Measured memory_bytes: 8276
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

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


int main() {
	int a, b, c;
	string n,k;
	cin >> n;
	c = 0;
	a = n.size();
	rep(i, a) {
		k = n[i];
		b = atoi(k.c_str());
		c = c + b;
	}
	if (c % 9 == 0) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 3728