akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iostream>
#include <map>
#include <stack>
#include <queue>
#include <vector>

static const int IINF = 1 << 30;
static const long long LINF = 1LL << 60;
static const long long MOD = 1.0e+9 + 7;

template <typename T> std::vector<T> vectors(std::size_t n, T val) {
  return std::vector<T>(n, val);
}

template <typename T, typename... Args>
auto vectors(std::size_t n, Args... args) {
  return std::vector<decltype(vectors<T>(args...))>(n, vectors<T>(args...));
}

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

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

template <class T> inline void chadd(T &a, const T &b) {
  a += b, a %= MOD;
  // TODO minus case
}

template <class T>
std::ostream &operator<<(std::ostream &s, const std::vector<T> &v) {
  if (v.empty())
    return s;
  s << *v.begin();
  for (auto iter = v.begin() + 1; iter != v.end(); ++iter)
    if (std::is_fundamental<T>::value)
      s << " " << *iter;
    else
      s << std::endl << *iter;
  return s;
}

int main() {
  int n;
  std::cin >> n;
  std::string s;
  std::cin >> s;

  std::vector<std::vector<int>> dp(n, std::vector<int>(n, 0));

  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      if (i == 0 and s[i] == s[j])
        dp[i][j] = 1;
      else if (j == 0 and s[i] == s[j])
        dp[i][j] = 1;
      else if (s[i] == s[j])
        dp[i][j] = dp[i-1][j-1] + 1;
    }
  }

  int res = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n; ++j) {
      chmax(res, std::min(dp[i][j], j - i));
    }
  }

  std::cout << res << std::endl;

  return 0;
}


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

template<typename T>
vector<T> bellman_ford(const vector<vector<pair<int, T>>> &graph, int root) {
  int n = graph.size();
  vector<T> dists(n, numeric_limits<T>::max());
  dists[root] = 0;
  for (int i = 0; i < n-1; ++i) {
    for (int j = 0; j < n; ++j) {
      if (dists[j] == numeric_limits<T>::max()) continue;
      for (auto e : graph[j]) {
        int nx; T cost;
        tie(nx, cost) = e;
        if (dists[nx] > dists[j] + cost) dists[nx] = dists[j] + cost;
      }
    }
  }

  queue<int> q;
  for (int i = 0; i < n; ++i) if (dists[i] != numeric_limits<T>::max()) q.push(i);
  while (!q.empty()) {
    int i = q.front(); q.pop();
    for (auto e : graph[i]) {
      int nx; T cost;
      tie(nx, cost) = e;
      if (dists[nx] == numeric_limits<T>::min()) continue;
      if (dists[i] == numeric_limits<T>::min() or dists[nx] > dists[i] + cost) {
        dists[nx] = numeric_limits<T>::min();
        q.push(nx);
      }
    }
  }
  return dists;
}

int main() {
  int n, m, p; cin>>n>>m>>p;
  vector<vector<pair<int, int>>> g(n);
  for (int i = 0; i < m; i++) {
    int a, b, c; cin>>a>>b>>c;
    --a; --b;
    g[a].emplace_back(b, -c+p);
  }

  auto dists = bellman_ford(g, 0);
  if (dists[n-1] == numeric_limits<int>::min()) {
    cout << -1 << endl;
  } else {
    cout << max(0, -dists[n-1]) << endl;
  }

  return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
#include<string.h>
int main(void){
	int i,n,joi,ioi;
	char string[10000];
	while(scanf("%s",string)!=EOF){
		joi=0;
		ioi=0;
		n=strlen(string);
		n-=2;
		for(i=0; i<n; i++){
			if( string[i]=='J' && string[i+1]=='O' && string[i+2]=='I' ){
				joi++;
			}else if( string[i]=='I' && string[i+1]=='O' && string[i+2]=='I' ){
				ioi++;
			}
		}
		printf("%d\n%d\n",joi,ioi);
	}
	return 0;
}

Measured memory_bytes: 556
#include <bits/stdc++.h>
#define FIO ios_base::sync_with_stdio(false); //cin.tie(NULL); cout.tie(NULL)
#define mp make_pair
#define pb push_back
#define fs first
#define sc second

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

/* BIEN CUC BO BEGIN*/
	int t, n, A[100002];
	
	int DD[100002];
/* BIEN CUC BO END*/

int main(){ FIO;
	int n; cin >> n;
	DD[1] = 0;
	for (int i=1; i<=n; ++i){
		if(i > 1) DD[i] = INT_MAX;
		cin >> A[i];
		if (i-1 >= 1){
			DD[i] = min(DD[i], DD[i-1] + abs(A[i]-A[i-1]));
		}
		if (i-2 >= 1){
			DD[i] = min(DD[i], DD[i-2] + abs(A[i]-A[i-2]));
		}
	}
	cout << DD[n];
return 0;}	

Measured memory_bytes: 1024
import bisect,collections,copy,heapq,itertools,math,string
import sys
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

s = input()
ans = math.inf
for x in s:
    t = s.split(x)
    tmp = 0
    for i in range(len(t)):
        tmp = max(tmp, len(t[i]))
    ans = min(ans, tmp)
print(ans)

Measured memory_bytes: 9952
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long int

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int  N;
    cin >> N;
    int ans = 1;
    rep(i, N) {
        ans *= (i + 1);
        ans = ans % mod;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
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;
}

using ll = long long;
using ull = unsigned long long;
const int INF = 1e9;
// const int MOD = 1e9 + 7;

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


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

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

	vector<int>a(N+1);
	a[0] = -M;
	for (int i = 0; i < N; i++) {
		cin >> a[i+1];
	}
	a.push_back(T+M);

	int ans = 0;
	for (int i = 1; i < a.size(); i++) {
		ans += max(0, (a[i] - a[i - 1]) - 2 * M);
	}

	cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3160
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

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

    int n;
    cin >> n;
    int a = 2, b = 1;
    if (n == 1)
    {
        cout << b << endl;
        return 0;
    }
    for (int i = 2; i <= n; i++)
    {
        int c = a + b;
        a = b;
        b = c;
    }
    cout << b << endl;
}


Measured memory_bytes: 256
#[macro_use]
mod input {

use std;
use std::io;

const SPLIT_DELIMITER: char = ' ';

#[macro_export]
#[allow(unused_macros)]
macro_rules! input {
    ( $($x:expr ),*) => {
        {
            let temp_str = input_line_str();
            let mut split_result_iter = temp_str.split_whitespace();
                $(
                let buf_split_result = split_result_iter.next();
                let buf_split_result = buf_split_result.unwrap();
                    ($x) = buf_split_result.parse().unwrap();
                )*
        }
    };
}

#[allow(dead_code)]
pub fn input_line_str() -> String {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

#[allow(dead_code)]
pub fn p<T>(t: T)
where
    T: std::fmt::Display,
{
    println!("{}", t);
}

#[allow(dead_code)]
pub fn input_vector2d<T>(line: usize) -> Vec<Vec<T>>
where
    T: std::str::FromStr,
{
    let mut v: Vec<Vec<T>> = Vec::new();

    for _ in 0..line {
        let vec_line = input_vector();
        v.push(vec_line);
    }
    v
}

#[allow(dead_code)]
pub fn input_vector<T>() -> Vec<T>
where
    T: std::str::FromStr,
{
    let mut v: Vec<T> = Vec::new();

    let s = input_line_str();
    let split_result = s.split(SPLIT_DELIMITER);
    for z in split_result {
        let buf = match z.parse() {
            Ok(r) => r,
            Err(_) => panic!("Parse Error"),
        };
        v.push(buf);
    }
    v
}

#[allow(dead_code)]
pub fn str2vec(s: &str) -> Vec<char> {
    let mut v: Vec<char> = Vec::new();
    for c in s.chars() {
        v.push(c);
    }
    v
}

}

use input::*;

use std::collections::HashSet;

fn main() {
    let s = str2vec(&input_line_str());
    let mut map = HashSet::new();
    for z in s {
        if map.contains(&z) {
            println!("no");
            return;
        }
        map.insert(z);
    }
    println!("yes");
}


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

typedef long long ll;
typedef pair<int,int> P;

#define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

typedef unsigned long long ull;

mt19937_64 r(std::chrono::high_resolution_clock::now().time_since_epoch().count());

ull const MASK30 = (1<<30)-1;
ull const MASK31 = INT_MAX;
ull const MOD = (1LL<<61)-1;
ull const MOD5 = MOD*5;
ull const base = r()%MOD;

struct RollingHash {
private:
    vector<ull> power,hash;
public:
    inline ull mul(ull a,ull b) {
        ull au = a>>31;
        ull ad = (a&MASK31);
        ull bu = b>>31;
        ull bd = (b&MASK31);
        ull mid = au*bd+ad*bu;
        return ((au*bu)<<1)+ad*bd+(mid>>30)+((mid&MASK30)<<31);
    }

    inline ull calcmod(ull a) {
        a = (a&MOD)+(a>>61);
        if (a > MOD) a -= MOD;
        return a;
    }

    RollingHash(string& s) {
        int n = s.size();
        power.resize(n+1);
        hash.resize(n+1);
        power[0] = 1;
        hash[0] = 0;
        for (int i = 0;i < n;++i) power[i+1] = calcmod(mul(power[i],base));
        for (int i = 0;i < n;++i) hash[i+1] = calcmod(mul(hash[i],base)+s[i]);
    }

    ull get(int l, int r)  {
        if (l) return calcmod(hash[r]+MOD5-mul(hash[l],power[r-l]));
        return hash[r];
    }

    ull connect(ull h1,int l,int r) {
        ull h2 = get(l,r);
        return calcmod(mul(h1,power[r-l])+h2);
    }

    // [l,r)
    int LCP(int l1,int r1,RollingHash& rh,int l2,int r2) {
        int ok = 0,ng = min(r1-l1,r2-l2)+1;
        while (ng-ok > 1) {
            int mid = (ok+ng)/2;
            if (get(l1,l1+mid) == rh.get(l2,l2+mid)) ok = mid;
            else ng = mid;
        }
        return ok;
    }
};

int main() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    int ans = 0;
    RollingHash rh(s);
    int ok = 0,ng = n/2+1;
    while (ng-ok > 1) {
        unordered_map<ull,int> mp;
        mp.reserve(5000);
        int mid = (ok+ng)/2;
        bool f = false;
        for (int i = 0;i < n-mid+1;++i) {
            ull key = rh.get(i,i+mid);
            auto it = mp.find(key);
            if (it != mp.end()) {
                if (it->second < i+2-mid) {
                    f = true;
                    break;
                }
            } else mp[key] = i+1;
        }
        (f ? ok : ng) = mid;
    }
    cout << ok << endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
using namespace std;

int main() {
    int n; cin >> n;
    vector<int> v(n);
    for (int i=0; i<n; i++) cin >> v[i];
    sort(v.begin(), v.end());
    double ans = v[0];
    for (int i=1; i<n; i++) {
        ans = (ans + v[i]) / 2;
    }
    cout << fixed << setprecision(10);
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int n = 0, m = 0;
vector<vector<int>> g;
vector<bool> vi;
vector<int> comp;
stack<int> post;
vector<pair<int, int>> q;
void input() {
    cin >> n >> m;
    g = vector<vector<int>>(n, vector<int>());
    vi = vector<bool>(n, false);
    comp = vector<int>(n, -1);
    q = vector<pair<int, int>>(0);
    while (m--) {
        int a = 0, b = 0;
        cin >> a >> b;
        g[a].push_back(b);
    }
    int Q = 0;
    cin >> Q;

    while (Q--) {
        int q1 = 0, q2 = 0;
        cin >> q1 >> q2;
        q.push_back({q1, q2});
    }
}

void dfs1(int i) {
    vi[i] = true;
    for (auto nig : g[i]) {
        if (vi[nig] == false) {
            dfs1(nig);
        }
    }
    post.push(i);
}
void reverseG() {
    vector<vector<int>> rev(n, vector<int>(0));
    for (int i = 0; i < g.size(); i++) {
        for (int j = 0; j < g[i].size(); j++) {
            int node = g[i][j];
            rev[node].push_back(i);
        }
    }
    g = rev;
}
void dfs2(int i, int comp_n) {
    comp[i] = comp_n;
    for (auto nig : g[i]) {
        if (comp[nig] == -1) {
            dfs2(nig, comp_n);
        }
    }
}
void compute() {
    for (int i = 0; i < n; i++) {
        if (vi[i] == false) dfs1(i);
    }
    reverseG();
    int comp_n = 0;
    while (!post.empty()) {
        int curr = post.top();
        post.pop();
        if (comp[curr] == -1) dfs2(curr, ++comp_n);
    }
    for (auto qq : q) {
        if (comp[qq.first] == comp[qq.second])
            cout << "1" << endl;
        else
            cout << "0" << endl;
    }
}

int main() {
    input();
    compute();
    return 0;
}


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

public class Main {

  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    long n = scanner.nextLong();
    long k = scanner.nextLong();
    long number = n % k;

    while (true) {
      long next=  Math.abs(number - k);
      if (number > next) {
        number = next;
      } else {
        break;
      }
    }
    System.out.println(number);
  }
}


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

using namespace std;


int n,d,x[12][12];

bool check(int a,int b){
	int dist = 0;
	for(int i = 0;i < d;i++){
		dist += (x[a][i] - x[b][i]) * (x[a][i] - x[b][i]);
	}
	int now = 1;
	while(now * now <= dist){
		if(now * now == dist){
			return true;
		}
		now++;
	}
	return false;
}

int main(){
	cin >> n >> d;
	for(int i = 0;i < n;i++){
		for(int j = 0;j < d;j++){
			cin >> x[i][j];
		}
	}
	int ans = 0;
	for(int i = 0;i < n;i++){
		for(int j = i+1;j < n;j++){
			if(check(i,j))ans++;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
<?php

$alphabet = range('a', 'z');
while (($line = trim(fgets(STDIN))) !== '') {
    for ($i = 0; $i < 26; $i++) {
        $str = '';
        for ($j = 0, $len = strlen($line); $j < $len; $j++) {
            $c = $line[$j];
            if (!in_array($c, $alphabet)) {
                $str .= $c;
                continue;
            }

            $k = array_search($c, $alphabet) - $i;
            $k = $k < 0 ? 26 + $k : $k;
            $str .= $alphabet[$k];
        }

        $arr = str_word_count($str, 2);
        if (in_array('the', $arr) || in_array('this', $arr) || in_array('that', $arr)) {
            echo $str, PHP_EOL;
            break;
        }
    }
}

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

string arr[55];
int t[55];
int main()
{
    int n;
    string x;
    cin >> n;
    string temp;
    for(int i = 0 ; i < n;++i)
    {
        cin >> arr[i] >> t[i];
    }

    cin >> x;
    int sum = 0;
    int finds = 0;
    for(int i = 0 ; i < n;++i)
    {
        if(x == arr[i])
        {
            finds = 1;
            continue;
        }
        else if(finds)
        {
            sum += t[i];
        }
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 256
import math

def eratosthenes():
    limit = 100001
    A = [i for i in range(2, limit)]
    B = [False for _ in range(limit + 1)]
    C = [0 for i in range(limit + 1)]
    while True:
        a = min(A)
        if a > math.sqrt(limit):
            break
        B[a] = True
        i = 0
        while len(A) > i:
            if A[i] % a == 0:
                A.pop(i)
                continue
            i += 1
    for a in A:
        B[a] = True
    for i in range(3, limit + 1, 2):
        if B[i] and B[(i + 1) // 2]:
            C[i] += 1
    for i in range(3, limit + 1):
        C[i] += C[i - 1]
    return C


def main():
    Q = int(input())
    C = eratosthenes()
    ans = []
    for _ in range(Q):
        l, r = map(int, input().split())
        ans.append(C[r] - C[l - 1])
    for c in ans:
        print(c)


main()


Measured memory_bytes: 10764
#include <bits/stdc++.h>
#define BIT(n) (1LL << (n))
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = 0; i < BIT(n); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); 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 FORA(i, n) for (auto &&i : n)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define DEBUG(x) cerr << #x << ": " << x << "\n"
#define PRINTALL(V)    \
  for (auto v : (V)) { \
    cerr << v << " ";  \
  }                    \
  cerr << "\n";
#define ALL(v) v.begin(), v.end()
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define epb emplace_back
#define int long long
using namespace std;
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 (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> using vec = std::vector<T>;
template <class T> void print(const T &x) { cout << x << "\n"; }
const int MOD = 1000000007, INF = 1061109567;
const double EPS = 1e-10, PI = acos(-1.0);
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
signed main() {
  cin.tie(0), ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  int H, W;
  cin >> H >> W;
  vec<vec<int>> d(10, vec<int>(10));
  REP(i, 10) {
    REP(j, 10) { cin >> d[i][j]; }
  }
  vec<int> a(11, 0);
  REP(i, H) {
    REP(j, W) {
      int p;
      cin >> p;
      if (p == -1) p = 10;
      a[p]++;
    }
  }
  REP(k, 10) {
    REP(i, 10) {
      REP(j, 10) { chmin(d[i][j], d[i][k] + d[k][j]); }
    }
  }
  // REP(i, 10) { DEBUG(d[i][1]); }
  int ans = 0;
  REP(i, 10) { ans += a[i] * d[i][1]; }
  print(ans);
}

Measured memory_bytes: 256
from sys import stdin

def main():
    N, *LR = map(int, stdin.buffer.read().split())
    L, R = LR[::2], LR[1::2]

    Lp = max(L)
    Rq = min(R)

    A, B = zip(*sorted((max(0, r - Lp + 1), -max(0, Rq - l + 1)) for l, r in zip(L, R)))

    mi = float("inf")
    ma = max(r - l + 1 for l, r in zip(L, R)) + max(0, Rq - Lp + 1)

    for a, b in zip(A[1:], B):
        mi = min(mi, -b)
        ma = max(ma, mi + a)

    print(ma)


main()


Measured memory_bytes: 34608
#include "iostream"
#include "algorithm"
#include "string"
#include "vector"
#include "cmath"
#include "bitset"
#include "queue"
#include "functional"
#include "map"
#include "unordered_map"
#include "set"
#include "stack"
#include "tuple"

#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define llmax 92233720368547758070
#define nyan "(=^･ω･^=)"
#define mkp make_pair
#define mkt make_tuple
#define P pair<ll, ll>
#define iP pair<int,int>
typedef long long ll;
using namespace std;

int H,W,a[200][200],dp[400][200][200]={};

int main(){
	cin>>H>>W;
	if(H==1||W==1){
		int ans=0;
		for(int i=0;i!=H;++i)
			for(int j=0;j!=W;++j){
				cin>>a[i][j];
				ans+=a[i][j];
			}
		cout<<ans<<endl;
		return 0;
	}
	for(int i=0;i!=H;++i)
		for(int j=0;j!=W;++j)
			cin>>a[i][j];
	for(int i=1;i!=H+W-2;++i){
		for(int j=max(0,i-W+1);j!=min(i,H-1);++j){
			for(int k=j+1;k!=min(i+1,H);++k){
				if(j)
					dp[i][j][k]=max({dp[i-1][j][k],dp[i-1][j-1][k],dp[i-1][j][k-1],dp[i-1][j-1][k-1]})+a[j][i-j]+a[k][i-k];
				else
					dp[i][j][k]=max(dp[i-1][j][k],dp[i-1][j][k-1])+a[j][i-j]+a[k][i-k];
			}
		}
	}
	cout<<a[0][0]+a[H-1][W-1]+dp[H+W-3][H-2][H-1]<<endl;
	return 0;
}

Measured memory_bytes: 59904
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define zep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(ll i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

ll h, w, k, cnt[10];
string s[20];

bool hantei(){
	zep(i, 0, 10){
		if(cnt[i] > k){
			return false;
		}
	}
	return true;
}

void update(ll bit, ll j){
	ll at = 0;
	zep(i, 0, h){
		if(s[i][j] == '1'){
			cnt[at]++;
		}
		
		if(bit & (1LL << i)){
			at++;
		}
	}
}

int main(){
	cin.tie(0); ios::sync_with_stdio(false);
	
	cin >> h >> w >> k;
	zep(i, 0, h){
		cin >> s[i];
	}
	
	ll ans = INF;

	zep(bit, 0, (1LL << h-1)){
	//zep(bit, 2, 3){
		memset(cnt, 0, sizeof(cnt));
		ll buf = __builtin_popcount(bit);
		
		zep(j, 0, w){
			if(!hantei()){
				buf = INF;
				break;
			}
			
			update(bit, j);
			
			if(!hantei()){
				//cout << j << endl;
				buf++;
				
				memset(cnt, 0, sizeof(cnt));
				update(bit, j);
			}
		}
		//cout << bit << " " << buf << endl;
		ans = min(ans, buf);
	}
	print(ans)
	return 0;
}

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

struct Benri {
    Benri() {
        std::cin.tie(0); ios::sync_with_stdio(false);
        cout << fixed << setprecision(12);
    }
} benri;
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; }

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vll = vector<long long>;
using pll = pair<ll, ll>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define MOD 1000000007
#define MOD2 998244353
const ll INF = 1e10;

struct UnionFind {
    vector<int> par, rank;

    UnionFind(int n) : par(n , -1), rank(n, 0) { }
    void init(int n) { par.assign(n, -1), rank.assign(n, 0); }

    int root(int x) {
        if (par[x] == -1) return x;
        else return par[x] = root(par[x]); 
    }

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

    bool unite(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        return true;
    }
};

const int MAXN = 100000;

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

    UnionFind tree(2*MAXN + 5);
    rep(i,N) {
        ll x,y; cin >> x >> y;
        x--; y--;
        tree.unite(x,MAXN + y);
    }

    vector<pll> hash(2*MAXN + 5,pll(0,0));

    rep(i,MAXN){
        hash[tree.root(i)].F++; 
    }
    rep(i,MAXN){
        hash[tree.root(MAXN + i)].S++; 
    }

    ll ans = - N;

    rep(i,2*MAXN){
        ans += hash[i].F * hash[i].S;
    }

    cout << ans << endl;



}




Measured memory_bytes: 4992
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws java.lang.Exception {
       //????????¬?????°?????????????????????????????????
     Scanner reader = new Scanner(System.in);
     
     //???????????????????????\?????????????¬??????°???????????°???????´?
     int a = reader.nextInt();
     int b = reader.nextInt();
     reader.close();

    //a??????b?????°????????§????????´???  
    if(a<b){
        System.out.println("a < b");
    }
    //b??????a?????°????????§????????´???
    else if (a>b){
         System.out.println("a > b");
     }
     //a??¨b?????°?????????????????´???
    else if(a==b){
         System.out.println("a == b");
     }
    }
}

Measured memory_bytes: 26216
store_num,bottle_num = map(int,input().split())

drink_dict = {}

for i in range(store_num):
    pay,num = map(int,input().split())
    drink_dict.setdefault(pay,0)
    drink_dict[pay] += num
    

drink_sorted = sorted(drink_dict.items(),key=lambda x:x[0])


cost = 0

for i in range(store_num):
    value = drink_sorted[i][0]
    num = drink_sorted[i][1]
    cost += value * min(num,bottle_num)
    bottle_num -= num
    
    if bottle_num <= 0:
        print(cost)
        break

Measured memory_bytes: 28912
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#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 SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 99999999

using namespace std;


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




ll m = 1000000007;

ll gcd(ll x, ll y) {
	ll m = max(x, y), n = min(x, y);
	if (m%n == 0)return n;
	else return gcd(m%n, n);
}

ll myPow(ll x, ll n, ll m) {
	if (n == 0)
		return 1;
	if (n % 2 == 0)
		return myPow(x * x % m, n / 2, m);
	else
		return x * myPow(x, n - 1, m) % m;
}


bool dp[110];

int main() {
	int N; cin >> N;
	REP(i, 100)dp[i] == false;
	dp[0] = true;
	REP(i, N) {
		if (dp[i]) {
			dp[i + 4] = true; dp[i + 7] = true;
		}
	}
	if (dp[N])cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define inc( i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec( i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

template<typename T> void swap(T & x, T & y) { T t = x; x = y; y = t; return; }
template<typename T> T abs(T x) { return (0 <= x ? x : -x); }
template<typename T> T max(T a, T b) { return (b <= a ? a : b); }
template<typename T> T min(T a, T b) { return (a <= b ? a : b); }
template<typename T> bool setmin(T & a, T b) { if(a <= b) { return false; } else { a = b; return true; } }
template<typename T> bool setmax(T & a, T b) { if(b <= a) { return false; } else { a = b; return true; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

int n;

int main() {
	scanf("%d", &n);
	
	if(n <= 2) { printf("%d\n", n); }
	
	inc(i, n) {
		LL sum = i * (i + 1) / 2;
		if(sum >= n) {
			inc1(j, i) {
				if(j != sum - n) { printf("%d\n", j); }
			}
			return 0;
		}
	}
	
	return 0;
}


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

int const N = 100000;
int a[N], b[N], c[N], d[N];
pair<int, int> e[N];
map<int, int> go;

void no() { printf("No\n"); exit(0); }
void yes() { printf("Yes\n"); exit(0); }

set<int> vis;
int up(int x = a[0]){
	if (vis.find(x) != vis.end())return 0;
	vis.insert(x);
	return 1 + up(go[x]);
}

int main(){
	int n;
	scanf("%d", &n);
	f(i, 0, n)scanf("%d", a + i);
	f(i, 0, n)c[i] = a[i];
	f(i, 0, n)scanf("%d", b + i);
	f(i, 0, n)d[i] = b[i];
	f(i, 0, n)e[i] = make_pair(b[i], a[i]);
	sort(c, c + n);
	sort(d, d + n);
	sort(e, e + n);
	f(i, 0, n)if (c[i] > d[i])no();
	f(i, 1, n)if (c[i] <= d[i - 1])yes();
	
	f(i, 0, n)go[c[i]] = e[i].second;
	if (up() == n)no();
	yes();
}

Measured memory_bytes: 18176
import sys
from collections import defaultdict
from math import gcd

def input(): return sys.stdin.readline().strip()

K = 10**9
L = 10**18
D = defaultdict(int)
for _ in range(int(input())):
    D[gcd(round(float(input()) * K), L)] += 1

D = tuple(D.items())
ans = 0
for i, (k1, v1) in enumerate(D):
    if k1*k1 % L == 0:
        ans += v1*(v1-1) // 2
    for k2, v2 in D[i+1:]:
        if k1*k2 % L == 0:
            ans += v1 * v2
print(ans)


Measured memory_bytes: 9492
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>
using namespace std;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
/*
cout<<fixed<<setprecision(20);
cin.tie(0);
ios::sync_with_stdio(false);
*/
const llint mod=1000000007;
const llint big=2.19e18+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
int main(void){
	int n,i;cin>>n;
	int dp[26];
	for(i=0;i<26;i++){dp[i]=mod;}
	for(i=0;i<n;i++){
		string st;cin>>st;
		int s=(st[0]-'a'),e=(st.back()-'a');
		if(i==0){dp[s]=0;}
		if(i==n-1){cout<<dp[s]+1<<endl;}
		mineq(dp[e],dp[s]+1);
	}
	return 0;
}


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

int main(){
  int n, S;
  int t[20002];

  while(cin >> n >> S, n || S){
    for(int i = 0; i < n; i++){
      cin >> t[i];
    }

    int res = 0;

    for(int i = 0; i < n; i++){
      for(int j = i + 1; j < n; j++){
	int sum = t[i] + t[j];

	if(sum > S){
	  res++;
	}
      }
    }

    cout << res << endl;
  }
}

Measured memory_bytes: 1204
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <string>
#include <utility>
#include <map>
#include <queue>
#include <list>
#include <functional>
#include <numeric>
#include <stack>
#include <tuple>

using namespace std;
int dx[4] = { -1,0,1,0 };
int dy[4] = { 0,1,0,-1 };
const int INF = 100000000;
const long long LINF = 1000000000000000000;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-6;
using pii = std::pair<int, int>;
using ll=long long;  
using pLL = std::pair<ll, ll>;
#define SORT(v) std::sort(v.begin(), v.end())
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
	ll N,K;
    cin >> N >>K;
    ll temp=pow(K-1,N-1);
    temp*=K;
    cout << temp <<endl;
    return 0;
}


Measured memory_bytes: 384
S = input()
T = input()

flag = False

def rotate_string(string):
  return "".join((string[-1], string[:-1]))

# print(S)
# print(rotate_string(S))
if S == T:
  print("Yes")
  flag = True

for i in range(len(S)):
  S = rotate_string(S)
  if S == T:
    if not flag:
      print("Yes")
      flag = True
      break
    
if not flag:
  print("No")


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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define TR(X) ({ if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	ll n; cin >> n;
	vl a(n+1), b(n);
	FOR(i,0,n+1) cin >> a[i];
	FOR(i,0,n) cin >> b[i];
	
	ll res = 0;
	FOR(i,0,n) {
		ll take = min(a[i],b[i]);
		a[i] -= take, b[i] -= take, res += take;
		take = min(a[i+1],b[i]);
		a[i+1] -= take, b[i] -= take, res += take;
	}
	cout << res << endl;

}



Measured memory_bytes: 1792
import sys
import numpy as np
import random
import math
from decimal import Decimal
import itertools
import re
import bisect
from collections import deque, Counter
from functools import lru_cache

sys.setrecursionlimit(10**9)
INF = 10**13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
def SERIES(n): return np.fromstring(sys.stdin.buffer.read(), dtype=np.int32, sep=' ')
def GRID(h,w): return np.fromstring(sys.stdin.buffer.read(), dtype=np.int32, sep=' ').reshape(h,-1)[:,:w]
def GRIDfromString(h,w): return np.frombuffer(sys.stdin.buffer.read(), 'S1').reshape(h,-1)[:,:w]
MOD = 1000000007

def main():
	n = I()
	x, y = 1, 1
	for _ in range(n):
		t, a = LI()
		m = max((x+t-1)//t,(y+a-1)//a)
		x, y = m*t, m*a
	print(x+y)


if __name__ == '__main__':
    main()

Measured memory_bytes: 27016
#include<bits/stdc++.h>
#define N 200005
#define M 4005
#define p 1000000007
using namespace std;

inline bool rd(int &X)
{
    X=0;int w=0;char ch=0;
    while(!isdigit(ch))w|=ch=='-',ch=getchar();
    while( isdigit(ch))X=(X<<3)+(X<<1)+(ch^48),ch=getchar();
    X=w?-X:X; return 1;
}

int n,ans;
int fac[N],inv[N];
int a[N],b[N],f[M][M];

int POW(int a,int b,int ans=1){
    for(;b;b>>=1,a=1ll*a*a%p)
        if(b&1) ans=1ll*ans*a%p;
    return ans;
}
int C(int n,int m){
    return 1ll*fac[n]*inv[m]%p*inv[n-m]%p;
}
signed main()
{
    rd(n);
    for(int i=1;i<=n;i++)
        rd(a[i]),rd(b[i]),f[2001-a[i]][2001-b[i]]++;
    fac[0]=inv[0]=1;
    for(int i=1;i<=8000;i++)
        fac[i]=1ll*fac[i-1]*i%p,inv[i]=POW(fac[i],p-2);
    for(int i=1;i<=4001;i++)
        for(int j=1;j<=4001;j++)
            f[i][j]+=(f[i-1][j]+f[i][j-1])%p;
    for(int i=1;i<=n;i++)
        (ans+=f[2001+a[i]][2001+b[i]])%=p;
    for(int i=1;i<=n;i++)
        (ans-=C(a[i]+a[i]+b[i]+b[i],a[i]+a[i]))%=p;
    ans=(ans+p)%p;
    cout<<1ll*ans*POW(2,p-2)%p;
}


Measured memory_bytes: 65792
###==================================================
### import
#import bisect
#from collections import Counter, deque, defaultdict
#from copy import deepcopy
#from functools import reduce, lru_cache
#from heapq import heappush, heappop
#import itertools
#import math
#import string
import sys
### stdin
def input(): return sys.stdin.readline()
def iIn(): return int(input())
def iInM(): return map(int, input().split())
def iInM1(): return map(int1, input().split())
def iInLH(): return list(map(int, input().split()))
def iInLH1(): return list(map(int1, input().split()))
def iInLV(n): return [iIn() for _ in range(n)]
def iInLV1(n): return [iIn()-1 for _ in range(n)]
def iInLD(n): return [iInLH() for _ in range(n)]
def iInLD1(n): return [iInLH1() for _ in range(n)]
def sInLH(): return list(input().split())
def sInLV(n): return [input().rstrip('\n') for _ in range(n)]
def sInLD(n): return [sInLH() for _ in range(n)]
### stdout
def OutH(lst, deli=' '): print(deli.join(map(str, lst)))
def OutV(lst): print('\n'.join(map(str, lst)))
### setting
sys.setrecursionlimit(10 ** 6)
### utils
int1 = lambda x: int(x) - 1
### constants
INF = int(1e9)
MOD = 1000000007
dx = (-1, 0, 1, 0)
dy = (0, -1, 0, 1)
###---------------------------------------------------

M = iIn()

ans = 24 + (24 - M)

print(ans)

Measured memory_bytes: 62304
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n,i;
	cin>>n;
	int a[n+1];
	for(i=0;i<n;i++)
	{
	    cin>>a[i];
	}
	int dp[n+1];
	dp[0]=0;
	dp[1]=abs(a[0]-a[1]);
	for(i=2;i<n;i++)
	{
	    dp[i]=min(abs(a[i]-a[i-2])+dp[i-2],abs(a[i]-a[i-1])+dp[i-1]);
	}
	cout<<dp[n-1]<<"\n";
	return 0;
}


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

using namespace std;

int n;

int main() {
  cin >> n;
  if(n % 10 == 7 || (n / 10) % 10 == 7 || n / 100 == 7) cout << "Yes\n";
  else cout << "No\n";
  return 0;
}


Measured memory_bytes: 3624
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <bitset>
#include <string>
#define pb push_back
#define sz(V) ((int)(V).size())
#define allv(V) ((V).begin()),((V).end())
#define befv(V) ((V)[(sz(V)-2)])
#define sorv(V) sort(allv(V))
#define revv(V) reverse(allv(V))
#define univ(V) (V).erase(unique(allv(V)),(V).end())
#define clv(V) (V).clear()
#define upmin(a,b) (a)=min((a),(b))
#define upmax(a,b) (a)=max((a),(b))
#define rb(x) ((x)&(-(x)))
#define INF (1100000099)
#define INFLL (1100000000000000099ll)
#define MOD (1000000007)
#define MAXN (55)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;

string S;
char str[MAXN][55];
int cnt[MAXN][26];
int N;

int main() {
	scanf("%d", &N);
	for(int i = 1; i <= N; i++) scanf(" %s", str[i]);
	for(int i = 1; i <= N; i++) for(int j = 0; str[i][j]; j++)
		cnt[i][str[i][j] - 'a']++;
	for(int i = 2; i <= N; i++) for(int j = 0; j < 26; j++)
		upmin(cnt[1][j], cnt[i][j]);
	for(int i = 0; i < 26; i++) for(int j = 0; j < cnt[1][i]; j++)
		S += ('a' + i);
	if(S.empty()) { putchar(' '); return 0; }
	puts(S.c_str());
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x)          (x).begin(), (x).end()
#define rep(i, s, n)    for (i64 i = (s), i##_limit = (n); i < i##_limit; ++i)
#define repr(i, s, t)   for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define var(type, ...)  type __VA_ARGS__; read(__VA_ARGS__);
#ifndef DBG
#define dump(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U> inline bool chmax(T &a, const U &b) { return b > a && (a = b, true); }
template <class T, class U> inline bool chmin(T &a, const U &b) { return b < a && (a = b, true); }
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> makeV(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeV(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeV<T>(initValue, args...))>(sz, makeV<T>(initValue, args...));
}

template <class T>
inline istream& operator>> (istream &is, vector<T> &vec) {
    for (auto &e : vec) is >> e;
    return is;
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail&... tail) { cin >> head; read(tail...); }

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<< (ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = { " ", "" };
    for (const auto &e : vec) os << e << delim[&e == &vec.back()];
    return os;
}

template <class Container>
struct Rev {
    Container &x_;
    inline Rev(Container &x): x_(x) {}
    inline auto begin() { return rbegin(x_); }
    inline auto end() { return rend(x_); }
};
// }}} End Header

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr);

    using ld = long double;

    var(int, N, K);

    vector<ld> a(N);
    rep(i, 0, N) {
        var(int, p);
        a[i] = ld(p * (p + 1) / 2) / p;
    }

    vector<ld> cum(N + 1);
    rep(i, 0, N) {
        cum[i + 1] = cum[i] + a[i];
    }

    ld ans = 0;
    rep(i, 0, N - K + 1) {
        chmax(ans, cum[i + K] - cum[i]);
    }

    cout << fixed << setprecision(12);
    print(ans);

    return 0;
}


Measured memory_bytes: 6528
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <limits>
#include <cassert>
#include <map>
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REPI(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
#define INF numeric_limits<double>::infinity()
#define ll long long
constexpr ll MOD = 1e9 + 7;
ll gcd(ll a, ll b) {return b % a ? gcd(b % a, a) : a;}
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
using namespace std;
using P = pair<ll, ll>;
using VI = vector<ll>;

bool contain(VI v, int k) {
    for (auto a: v) {
        if (a == k) return true;
    }
    return false;
}

int main() {
    long n, m, x;
    cin >> n >> m >> x;
    x--;
    VI as;
    REP(i,m) {
        long a;
        cin >> a;
        a--;
        as.push_back(a);
    }
    long p = 0, q = 0;
    for (int i = 0; i < x; i++) {
        if (contain(as, i)) p++;
    }
    for (int i = x + 1; i < n; i++) {
        if (contain(as, i)) q++;
    }
    cout << min(p, q) << endl;
}


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

using namespace std;
using ll = long long;

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

void assignGroup(int u, int *group, int g, vector<vector<int>> &t) {
  if (group[u] != -1) return;
  group[u] = g;
  for (auto v : t[u]) { assignGroup(v, group, g, t); }
}

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

  vector<vector<int>> t(n);
  rep(i, m) {
    int x, y, z;
    cin >> x >> y >> z;
    --x;
    --y;
    t[x].push_back(y);
    t[y].push_back(x);
  }

  int g = 0;
  int group[n];
  rep(i, n) group[i] = -1;
  rep(i, n) {
    if (group[i] == -1) {
      assignGroup(i, group, g, t);
      ++g;
    }
  }

  set<int> s;
  rep(i, n) { s.insert(group[i]); }

  cout << s.size() << '\n';

  return 0;
}


Measured memory_bytes: 10752
#include<stdio.h>
#include<stdlib.h>
#define N 10000

int main(){
  int n,i,j,k=0;
  unsigned short *A, *B;
  int C[N+1];
  
  scanf("%d",&n);

  A = malloc(sizeof(short) * n + 1);
  B = malloc(sizeof(short) * n + 1);

  for(i=1;i<=n;i++){
    scanf("%d",&A[i]);
  }

  for(i=1;i<=n;i++){
    if(k < A[i]){
      k = A[i];
    }
  }

  for(i=0;i<k;i++){
    C[i] = 0;
  }
  
  for(j=1;j<=n;j++){
    C[A[j]] = C[A[j]] + 1;
  }
  
  for(i=1;i<=N;i++){
    C[i] = C[i] + C[i-1];
  }
  
  for(j=n;j>=1;j--){
    B[C[A[j]]] = A[j];
    C[A[j]] = C[A[j]] - 1;
  }

  for(i=1;i<=n;i++){
    printf("%d",B[i]);
    if(i < n ){
      printf(" ");
    }
  }
  printf("\n");

  return 0;
}


    
  



Measured memory_bytes: 9596
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (long long i = m; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PL = pair<long long, long long>;
using Pxy = pair<double, double>;
using T = tuple<int, int, bool>;
const int INF = 1001001007;
const int mod = 1000000007;
//const int MOD = 998244353;
const ll inf = 1e18;
template <typename AT>
void printvec(vector<AT> &ar){
    rep(i,ar.size()-1) cout << ar[i] << " ";
    cout << ar[ar.size()-1] << endl;
}
template <typename Q>
void printvvec(vector<vector<Q>> &ar){
    rep(i,ar.size()){
        rep(j,ar[0].size()-1) cout << ar[i][j] << " ";
        cout << ar[i][ar[0].size()-1] << endl;
    }
}
template <typename S>
bool range(S a, S b, S x){
    return (a <= x && x < b);
}

int main() {
    int n; cin >> n;
    vector<pair<string,P>> ar(n);
    rep(i,n){
        string s; cin >> s;
        int a; cin >> a;
        ar[i].first = s;
        ar[i].second.first = 100 - a;
        ar[i].second.second = i+1;
    }
    sort(ar.begin(),ar.end());
    rep(i,n) cout << ar[i].second.second << endl;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  vector<long long> a(n);
  long long ans = 0;
  for(int i = 0; i < n; i++) cin >> a.at(i);
  
  long long sum = 0;
  for(int i = 0; i < n; i++) sum += a.at(i);
  for(int i = 0; i < n-1; i++){
    sum -= a.at(i);
  	ans += (a.at(i) * (sum%1000000007))%1000000007;
  }
  cout << ans%1000000007 << endl;
  
}

Measured memory_bytes: 4784
// atcoder/abc137/B/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int k, x;
  while (cin >> k >> x) {
    vector<int> v;
    for (int i = 1; i < k; ++i) {
      v.push_back(x - i);
      v.push_back(x + i);
    }
    v.push_back(x);
    sort(v.begin(), v.end());
    for (int i = 0; i < v.size(); ++i) {
      if (i) cout << ' ';
      cout << v[i];
    }
    cout << endl;
  }

  return 0;
}


Measured memory_bytes: 256
from collections import defaultdict

def bfs(i, V, E, Ec):
    V[i] = 1
    Q = [(i, 0)]
    while(True):
        Qi = []
        for q, cq in Q:
            c = 1
            for j, idx in E[q]:
                if V[j] == 0:
                    if cq == c:
                        c += 1

                    V[j] = 1
                    Qi.append((j, c))
                    Ec[idx] = c
                    c += 1
        if len(Qi) == 0:
            break
        else:
            Q = Qi
    return V, Ec


n = int(input())
E = defaultdict(list)
for i in range(n - 1):
    a, b = map(int, input().split())
    E[a].append((b, i))
    E[b].append((a, i))
Ec = [None for _ in range(n - 1)]
V = [0 for _ in range(n + 1)]
_, Ec = bfs(1, V, E, Ec)
print(max(Ec))
for c in Ec:
    print(c)


Measured memory_bytes: 46444
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
int main(){
	string s;cin >> s;
	int si = stoi(s);
	int cnt = 0;
	for(int i = 1; i <= si; i++){
		s = to_string(i);
		if(s.size()%2 != 0)cnt++;
	}
	cout << cnt << endl;
}

Measured memory_bytes: 256