akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; }

const ll INF = 1LL << 60;

ll h[100010];

ll dp[100010];

int main() {
    int N,K; cin >> N >> K;
    for (int i = 0; i < N; ++i) cin >> h[i];

    for (int i = 0; i < 100010; ++i) dp[i] = INF;

    dp[0] = 0;
    
    for (int i = 0; i < N; ++i) {
        chmin(dp[i+1], dp[i] + abs(h[i] - h[i+1]));
        for (int j=1;j<=K;j++) chmin(dp[i+j],dp[i]+abs(h[i] - h[i+j]));
    }

    cout << dp[N-1] << endl;
}

Measured memory_bytes: 1792
#include<stdio.h>
#include<vector>

using namespace std;

int main(){
  int x,y,k=0,sum;
  scanf("%d%d", &x,&y);
  if(x%y==0){
    printf("-1\n");
    return 0;
  }
  while(true){
    sum = k*x;
    if(sum % y != 0){
      printf("%d\n",sum);
      return 0;
    }
    ++k;
  }
  return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
int main(void){
  
  int a, b, cy, d, m=0;
  
  while(1){
    d=0;
    scanf("%d %d", &a, &b);
    
    if(a==0 && b==0){
      
      goto S;//I¹ð
      
    }
    if(m!=0) printf("\n");
    
    for(cy=a; cy<=b; cy++){
      
      if(cy%4==0 && cy%100!=0){
	printf("%d\n", cy);
	d++;
      }
      
      else if(cy%400==0){
	printf("%d\n", cy);
	d++;
      }
    }
    
    
    if( d == 0){
      printf("NA\n");
      d=0;
    }
    m=1;
    // printf("\n");
    
  }
  
 S :
  return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
#include<cstdio>
#include<cstdlib>
using namespace std;
 
#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592
 
const double EPS = 1e-10;
 
using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;

int main(){
    string s; cin >> s;
    int n = s.size();
    if(s[n-1] == '3'){
        cout << "bon" << endl;
    }
    else if(s[n-1] == '0'||s[n-1] == '1'||s[n-1] == '6'|| s[n-1] == '8'){
        cout << "pon" << endl;
    }
    else cout << "hon" << endl;
}


Measured memory_bytes: 3628
#!/usr/bin/env python3


def cost(x, y):
    return (x - y) * (x - y)


def min_total_cost(xs):
    def total_cost(target):
        return sum(cost(x, target) for x in xs)
    ans = min(total_cost(t) for t in range(min(xs), max(xs) + 1))
    return ans


def main():
    _ = input()
    xs = list(map(int, input().split()))
    print(min_total_cost(xs))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3188
def gcd(x,y):
    r=x%y
    while r>0:
        r=x%y
        if r ==0: 
            return y
        else:
            q=y
            x=q
            y=r
    return y
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
  
a,b = list(map(int, input().split()))
c = gcd(a,b)



print(1+len(set(prime_factorize(c))))

Measured memory_bytes: 3064
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::io::{BufWriter, Write};

// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[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)*}
    };

    ($next:expr, mut $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, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

fn solve() {
    input!(
        n: usize,
        a: [usize; n],
    );

    let mut a: Vec<usize> = a;

    let mut b: Vec<(usize, usize)> = vec![];

    for (ind, aa) in a.into_iter().enumerate() {
        b.push((aa, ind));
    }

    b.sort_by(|&(a1, a2), &(b1, b2)| if a1 < b1 { Ordering::Less } else { Ordering::Greater });

    for (b1, b2) in b {
        print!("{} ", b2 + 1);
    }
}

fn main() {
    let stack_size = 1 << 28;
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 12664
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <deque>
#include <map>
#include <bits/stdc++.h>
#include <set>

#define ll long long
#define inf 0x3f3f3f3f
#define il inline

namespace io {

#define in(a) a = read()
#define out(a) write(a)
#define outn(a) out(a), putchar('\n')

#define I_int ll
inline I_int read() {
    I_int x = 0, f = 1;
    char c = getchar();
    while (c < '0' || c > '9') {
        if (c == '-') f = -1;
        c = getchar();
    }
    while (c >= '0' && c <= '9') {
        x = x * 10 + c - '0';
        c = getchar();
    }
    return x * f;
}
char F[200];
inline void write(I_int x) {
    if (x == 0) return (void) (putchar('0'));
    I_int tmp = x > 0 ? x : -x;
    if (x < 0) putchar('-');
    int cnt = 0;
    while (tmp > 0) {
        F[cnt++] = tmp % 10 + '0';
        tmp /= 10;
    }
    while (cnt > 0) putchar(F[--cnt]);
}
#undef I_int

}
using namespace io;

using namespace std;

#define N 100010

int main(){
	int y,m,d;
	scanf("%d/%d/%d",&y,&m,&d);
	if(m<=4) puts("Heisei");
	else puts("TBD");
	return 0;
}

Measured memory_bytes: 256
A,B,N = map(int,input().split())
k = N // B
if k == 0:
  x = N
else:
  x = (k*B)-1
t = (A*x)//B
u = A*(x//B)
s = t-u
if s < ((A*N)//B)-A*(N//B):
  s = ((A*N)//B)-A*(N//B)
print(s)

    

Measured memory_bytes: 61840
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <float.h>
 
#pragma region 定義
#define i_cin(X) scanf("%d", &X)
#define i_cin2(X,Y) scanf("%d %d",&X,&Y)
#define i_cin4(X,Y,Z,W) scanf("%d %d %d %d",&X,&Y,&Z,&W)
#define i_cin3(X,Y,Z) scanf("%d %d %d",&X,&Y,&Z)
#define l_cin(X) scanf("%ld",&X)
#define f_cin(X) scanf("%f",&X)
#define l_cin2(X,Y) scanf("%ld %ld",&X,&Y)
#define s_cin(X) scanf("%s",&X)
#define ll_cin(X) scanf("%lld", &X)
 
#define  i_cout(X) printf("%d\n",X)
#define  f_cout(X) printf("%g\n",X)
#define  i_cout2(X,Y) printf("%d %d\n",X,Y)
#define  l_cout(X) printf("%ld\n",X)
#define  s_cout(X) printf("%s\n",X)
#define  ll_cout(X) printf("%lld\n",X)
 
typedef long long  ll;
#define rept(x, s, n) for (int x = s; x < n; x++)
 
#define S_RTN(S)  s_cout(S);return 0
 
 
#define _itoa(A,N) sprintf(A, "%d", N);
 
int i_cins(int n, int* A);
int l_cins2(int n, long* A, long* B);
int s_dsort(const void* a, const void* b);
int s_asort(const void* a, const void* b);
 
int  _gcd(int a, int b);
int  _swp(int* a, int* b);
int _cknum(char* a, int n);
int _atoi(char* s, int len);
 
 
int s_asorts(const void* a, const void* b);
 
//昇順
int s_asorts(const void* a, const void* b) {
    return(strcmp((char*)a, (char*)b));
}
int s_dsort(const void* a, const void* b) {
    return(*(int*)b - *(int*)a);
}
int s_asort(const void* a, const void* b) {
    return(*(int*)a - *(int*)b);
}
int l_cins2(int n, long* a, long* b) {
    int i;
    rept(i, 0, n) {
        l_cin2(*(a + i), *(b + i));
    }
    return 0;
}
int i_cins(int n, int* a) {
    int i;
    for (i = 0; i < n; i++) {
        i_cin(*(a + i));
    }
 
    return 0;
}
int _gcd(int a, int b) {
    int r, tmp;
    if (a < b) { tmp = a; a = b; b = tmp; }
    r = a % b;
    while (r) {
        if (!r) break;
        a = b; b = r;
        r = a % b;
    }
    return(b);
}
 
long _max(long a, long b) {
    return a > b ? a : b;
}
long _min(long a, long b) {
    return a < b ? a : b;
}
int _swp(int* a, int* b)
{
    int tmp;
    tmp = *b; *b = *a; *a = tmp;
    return 0;
}


int main(){
    char a[4];
    scanf("%s",a);
    if(a[1]=='B'){
        printf("ARC");
        return 0;
    }else{
        printf("ABC");
    }
}

Measured memory_bytes: 2120
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  map<int,int> num;
  for(int i = 0; i < n; i++) {
    int x;
    cin >> x;
    if(num.count(x)) {
      cout << "NO";
      break;
    }
    else if(i == n-1) {
      cout << "YES";
    }
    else num[x] = 1;
  }
}




Measured memory_bytes: 9600
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

using std::string;
using std::vector;
using std::set;
using std::multiset;
using std::unordered_set;
using std::map;
using std::multimap;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

using boost::multiprecision::cpp_int;
using cpp_dec_float_1000 = boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000>>;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

constexpr char CRLF  = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;
constexpr int MOD = 1000'000'007;

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; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }
template<class T> T modinv(T a, T m) { T b = m, u = 1, v = 0; while (b) { T t = a / b; a -= t * b; boost::swap(a, b); u -= t * v; boost::swap(u, v); } u %= m; if (u < 0) u += m; return u; }

struct Tmp
{
public:
  Tmp(int N);
};

Tmp::Tmp(int N){}

void solve(void)
{
  int N, H; cin >> N >> H;
  vector<int> A(N), B(N);
  for (int _ = 0; _ < N; ++_) {
    cin >> A[_] >> B[_];
  }
  boost::sort(A, std::greater<int>());
  boost::sort(B, std::greater<int>());
  int ans{};
  auto itr_b = B.begin();
  auto itr = boost::lower_bound(B, A[0], [](auto b, auto a){
    return b > a;
  });
  while (H > 0 && itr_b != itr) {
    H -= *itr_b;
    ++itr_b;
    ++ans;
  }

  if (H > 0) {
    auto cnt = (H + A[0] - 1) / A[0];
    H -= cnt * A[0];
    ans += cnt;
  }

  cout << ans << CRLF;
  return;
}

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

  solve();

  return 0;
}


Measured memory_bytes: 1024
use std::io::*;
use std::str::*;

fn read<T: FromStr>() -> Option<T> {
    let stdin = stdin();
    let s = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok()
}

fn main() {
    let n: usize = read().unwrap();
    let mut a: Vec<i64> = Vec::new();

    for i in 0..n {
        a.push(read().unwrap());
    }

    let mut min = 100000;
    for ai in a.iter() {
        let mut k: i64 = *ai;
        let mut c = 0;
        while k % 2 == 0 {
            k = k / 2;
            c += 1;
        }
        min = std::cmp::min(min, c);
    }
    println!("{}", min);
}


Measured memory_bytes: 4352
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <climits>
#include <utility>
#include <map>
#include <set>
#include <complex>
#include <numeric>

#include <time.h>
#include <float.h>

#define loop(i, start, end) for(i = (start); i <= (end); i++)
#define loopIterators(it, vec) for(it = (vec).begin(); it != (vec).end(); it++)
#define loopIteratorsRev(it, vec) for(it = (vec).rbegin(); it != (vec).rend(); it++)
#define loopRev(i, start, end) for(i = (start); i >= (end); i--)
#define FLASH ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define testCases(t) cin >> t; while(t--)
#define PN(n) cout << (n)
#define PN1(n) cout << (n) << " "
#define PN2(a, b) cout << (a) << " " << (b) << " "
#define PNN1(n) cout << (n) << endl
#define PNN2(a, b) cout << (a) << " " << (b) << endl
#define PNN3(a, b, c) cout << (a) << " " << (b) << " " << (c) << endl
#define PrintArray(ar, n) for(i = 0; i < n; i++) cout << ar[i] << " "; cout << endl
#define PrintObject(ar, it) loopIterators(it, ar) cout << *it << " "; cout << endl
#define PrintMap(map, it) loopIterators(it, map) PNN2(it->first, it->second)
#define sz(a) sizeof(a)
#define IN1(n) cin >> n
#define IN2(a, b) cin >> a >> b
#define IN3(a, b, c) cin >> a >> b >> c
#define ALL(s) s.begin(), s.end()
#define SWAP(a, b, c) c = a; a = b; b = c
#define STRSP(s) scanf("%[^\n]%*c", s)
#define ENTER PNN1("");
#define MOD7 1000000007
#define MOD9 10000009
#define MAX 1000000000
#define llPair std::pair<lli, lli>
#define iiPair std::pair<int, int>
#define ONLINE_JUDGE

typedef long long int lli;
typedef long int li;
typedef unsigned long long int ulli;
typedef long double ld;

using namespace std;

int main(void){
	FLASH

	#ifndef ONLINE_JUDGE
		freopen("input-stream.txt", "r", stdin);
		freopen("output-stream.txt", "w", stdout);
	#endif

	int n, i;
	IN1(n);
	int ar[n];
	std::map<int, int> d;

	loop(i, 0, n - 1) IN1(ar[i]);
	loop(i, 0, n - 1) ++d[ar[i]];

	lli total = 0LL;
	for(auto cur: d) total += 1LL * cur.second * (cur.second - 1) / 2;

	// PNN1(total);
	loop(i, 0, n - 1) {
		lli now = d[ar[i]];
		lli cur = total - 1LL * now * (now - 1) / 2;
		--now;
		cur += 1LL * now * (now - 1) / 2;

		PNN1(cur);
	}

	#ifndef ONLINE_JUDGE
		fclose(stdin);
		fclose(stdout);
	#endif

	return 0;
}


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

int main(){
  int x;
  cin >> x ;
  if(x >=400 && x <= 599) cout << '8' << endl;
  else if(x >=600 && x <= 799) cout << '7' << endl;
  else if(x >=800 && x <= 999) cout << '6' << endl;
  else if(x >=1000 && x <= 1199) cout << '5' << endl;
  else if(x >=1200 && x <= 1399) cout << '4' << endl;
  else if(x >=1400 && x <= 1599) cout << '3' << endl;
  else if(x >=1600 && x <= 1799) cout << '2' << endl;
  else  cout << '1' << endl;
}


Measured memory_bytes: 3620
use proconio::{input, fastout};

#[fastout]
fn main() {
    input! {
        n: usize,
        xx: [usize; n],
    }

    let mut sorted = xx.clone();
    sorted.sort();

    for x in xx {
        if sorted[n/2-1] >= x {
            println!("{}", sorted[n/2]);
        } else {
            println!("{}", sorted[n/2-1]);
        }
    }
}


Measured memory_bytes: 7812
#include<bits/stdc++.h>
using namespace std;
long long n,m,a[100010];
int INF=INT_MAX;
int main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	  a[i]=INF;
	for(int i=0;i<m;i++)
	{
		int x;
		cin>>x;
		a[x]=0;
	}
	if(a[1]!=0)
	  a[1]=1;
	if(a[1]==0 && a[2]!=0)
	  a[2]=1;
	else
	  if(a[2]!=0)
	    a[2]=2;
	for(int i=3;i<=n;i++)
	{
		if(a[i]!=0)
		  a[i]=(a[i-1]+a[i-2])%1000000007;
		//cout<<a[i]<<endl;
	}
	//cout<<a[n]<<" ";
	cout<<a[n]%1000000007;
	return 0;
}


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

int main() {
  int n;
  cin>>n;
  string s;
  cin>>s;
  int t=s.size();
  int k=min(n,t);
  for(int i=0;i<k;i++){
    cout<<s.at(i);
  }
  if(n<s.size())cout<<"...";
  cout<<endl;
}


Measured memory_bytes: 3628
#include<stdio.h>

int main(){
  int n,q,i,j,count=0,left,right,mid;
  scanf("%d",&n);
  int A[n];
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  scanf("%d",&q);
  int B[q];
  for(i=0;i<q;i++){
    scanf("%d",&B[i]);
  }
 
  
  for(i=0;i<q;i++){
    left=0;
    right=n;
    while(left<right){
      mid=(left+right)/2;
      if(A[mid]==B[i]){
	count++;
	break;
      }
      else if(B[i]<A[mid]) right=mid;
      else left=mid+1;
    }
  }

  printf("%d\n",count);
  return 0;
}





Measured memory_bytes: 2364
#include<iostream>
#include<string>
#include<vector>

int main(void){
    int n;
    std::cin >> n;
    std::vector<int> h(n);
    for(int i = 0; i < n; i++){
        std::cin >> h.at(i);
    }

    int ans = 0;
    int cnt = 0;

    for(int i = 0; i < n - 1; i++){
        if(h.at(i) >= h.at(i+1)){
            cnt++;
        }
        else{
            cnt = 0;
        }
        ans = std::max(ans, cnt);
    }

    std::printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

const int maxn = 1e5 + 10;
class Edges{
public:
	int next , to;
};
Edges edge[maxn * 2];
int first[maxn] , n , m;
bool flag[maxn];
int ans1[maxn] , sum1 = 0 , te = 0;
int ans2[maxn] , sum2 = 0;

void go1(int x){
	ans1[++ sum1] = x;
	flag[x] = 1;
	for(int e = first[x] ; e ; e = edge[e].next){
		int to = edge[e].to;
		if(flag[to]) continue;
		go1(to);
		break;
	}
}
void go2(int x){
	ans2[++ sum2] = x;
	flag[x] = 1;
	for(int e = first[x] ; e ; e = edge[e].next){
		int to = edge[e].to;
		if(flag[to]) continue;
		go2(to);
		break;
	}
}
void add(int s , int t){
	++ te;
	edge[te].to = t;
	edge[te].next = first[s];
	first[s] = te;
}
int main(){
	ios::sync_with_stdio(0);
	cin >> n >> m;
	for(int i = 1 ; i <= m ; ++ i){
		int s , t;
		cin >> s >> t;
		add(s , t);
		add(t , s);
	}
	go1(1);
	go2(1);
	cout << sum1 + sum2 - 1 << endl;
	for(int i = sum2 ; i > 1 ; -- i)
		cout << ans2[i] << " ";
	for(int i = 1 ; i <= sum1 ; ++ i)
		cout << ans1[i] << " ";
	cout << endl;
	return 0;
}

Measured memory_bytes: 3200
import sys
#from collections import deque
#from functools import *
#from fractions import Fraction as f
from copy import *
from bisect import *	
#from heapq import *
#from math import ceil
#from itertools import permutations ,product
 
def eprint(*args):
    print(*args, file=sys.stderr)
zz=1
 
#sys.setrecursionlimit(10**6)
if zz:
	input=sys.stdin.readline
else:	
	sys.stdin=open('input.txt', 'r')
	sys.stdout=open('all.txt','w')
di=[[-1,0],[1,0],[0,1],[0,-1]]
def inc(d,c,x=1):
	d[c]=d[c]+x if c in d else x
def bo(i):
	return ord(i)-ord('A')	
def li():
	return [int(xx) for xx in input().split()]
def fli():
	return [float(x) for x in input().split()]	
def comp(a,b):
	if(a>b):
		return 2
	return 2 if a==b else 0		
def gi():	
	return [xx for xx in input().split()]
def fi():
	return int(input())
def pro(a): 
	return reduce(lambda a,b:a*b,a)		
def swap(a,i,j): 
	a[i],a[j]=a[j],a[i]	
def si():
	return list(input().rstrip())	
def mi():
	return 	map(int,input().split())			
def gh():
	sys.stdout.flush()
def isvalid(i,j):
	return 0<=i<n and 0<=j<m and a[i][j]!="."
def bo(i):
	return ord(i)-ord('a')	
def graph(n,m):
	for i in range(m):
		x,y=mi()
		a[x].append(y)
		a[y].append(x)
mod=10**9+7
t=1
while t>0:
	t-=1
	s=fi()

	dp=[1 for i in range(s+10)] 
	dp[0]=dp[1]=dp[2]=0
	for i in range(3,s+1):
		for j in range(3,i+1):
			dp[i]+=dp[i-j]
			dp[i]%=mod
	print(dp[s])		
		
		





Measured memory_bytes: 71912
#include <iostream>
#include <algorithm>

int main()
{
	int N, K, * p,num=0;
	std::cin >> N >> K;
	p = new int[N];
	for (int i = 0; i < N; i++)
	{
		std::cin >> p[i];
	}
	std::sort(p, p + N);
	for (int i = 0; i < K; i++)
	{
		num += p[i];
	}
	std::cout << num;
	delete[] p;
}

Measured memory_bytes: 3652
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b)for(int i=(a);i<=(b);i++)
#define repR(i,n) for(int i=n;i>=0;i--)
#define P pair<int, int>
#define sz(x) x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<int>
#define COUT(x) cout<<(x)<<endl
#define MA map<int,int>
#define SE set<int>
#define PQ priority_queue<int>
#define PQR priority_queue<int,VE,greater<int>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl

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

using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(ll n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}


const long long MOD = 1000000007;
const long long INF = 1e9;
const long long LINF = 1 << 50;
// pair -> vector<pair<int,int>> 
//		   AandB.push_back(make_pair(a[i],b[i]))



signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n; cin >> n;
	vector<P>r(n), b(n);
	rep(i, n)cin >> r[i].first >> r[i].second;
	rep(i, n)cin >> b[i].first >> b[i].second;
	sort(ALL(b));
	int ans = 0;
	rep(i, n) {
		int x = b[i].first; int y = b[i].second;
		int tmp = -1; int tmp2 = -1;
		rep(j, r.size()) {
			if (r[j].first < x&&r[j].second < y) {
				if (r[j].second > tmp) {
					tmp = r[j].second; tmp2 = j;
				}
			}
		}
		if (tmp2 >= 0) {
			ans++;
			r.erase(r.begin() + tmp2);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
 
typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2

using namespace std;
int MOD = 1000000007;

signed main(){
    int n,h,w;
    cin >> n >> h >> w;
    cout << (n-w+1)*(n-h+1);
    
    


    return 0;
}
// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl 
// rm -r -f test;oj dl http://arc074.contest.atcoder.jp/tasks/arc074_b

Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    k=input()
    len_k=len(k)
    d=int(input())
    mod=10**9+7
    dp_0=[[0]*d for _ in range(len_k+1)]
    dp_1=[[0]*d for _ in range(len_k+1)] 
    dp_0[0][0]=1
    for i in range(len_k):
        ni=int(k[i])
        for j in range(d):
            for dig in range(10):
                dp_1[i+1][(j+dig)%d]=(dp_1[i+1][(j+dig)%d]+dp_1[i][j])%mod
            for dig in range(ni):
                dp_1[i+1][(j+dig)%d]=(dp_1[i+1][(j+dig)%d]+dp_0[i][j])%mod
            dp_0[i+1][(j+ni)%d]=(dp_0[i+1][(j+ni)%d]+dp_0[i][j])%mod
    print((dp_0[len_k][0]+dp_1[len_k][0]-1)%mod)

if __name__=='__main__':
    main()

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

int main(){
int N;
cin >> N;
vector<double> A(N);
vector<double> B(N);
double ans = 0;
for (int i = 0; i < N; i++){
    cin >> A.at(i);
    B.at(i) = 1/A.at(i);
    ans += B.at(i);
}

cout << 1/ans << endl;
}

Measured memory_bytes: 256
a, b, k = map(int, input().split())

ans = set()
temp1 = a
temp2 = b
for i in range(k):
    ans.add(temp1)
    ans.add(temp2)
    temp1 += 1
    temp2 -= 1
    if not(a <= temp1 <= b):
        break

ans_p = sorted(ans)
for val in ans_p:
    print(val)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = INT32_MAX;
const ll INFL = INT64_MAX;
const int mod = 1e9 + 7;

template <typename T>
void print_vec(vector<T> v) {
  for (T i : v) cout << i << " ";
  cout << endl;
}

int main() {
  int a, b;
  cin >> a >> b;
  if (a < 6)
    cout << 0 << endl;
  else if (a < 13)
    cout << b / 2 << endl;
  else
    cout << b << endl;
  return 0;
}

Measured memory_bytes: 256
// ABC 155-C
// 2020.2.16 bal4u

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

typedef long long ll;

#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)

int in() {   // 非負整数の入力
	int n = 0; int c;
	do c = gc();
	while (isspace(c));
	do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0');
	return n;
}

ll ins() { // 文字列の入力　スペース以下の文字で入力終了
    ll n = 0;
	int c;
   	do c = gc();
	while (isspace(c));
    int w = 0;
	do n = (n << 5) + (c - 'a'+1), ++w;
    while ((c = gc()) > ' ');
    return n << 5*(10-w);
}

void outs(ll s) {
    int i;
    char a[20];
    i = 0; while (s) {
        if (s & 31) a[i++] = (s & 31) + 'a'-1;
        s >>= 5;
    }
    while (i--) pc(a[i]);
    pc('\n');
}

void Usort(ll *a, int n) {
	int i, k;
#define B 8
#define BMSK 255 // (1<<8)-1
	int t1[1 << B], t2[1 << B];

	ll *tmp = malloc(n * sizeof(ll));
	for (k = 0; k < 8; ++k) {  // for 64ビット
		memset(t1, 0, sizeof(t1)), memset(t2, 0, sizeof(t2));
		for (i = 0; i < n; ++i)	t1[(a[i] >> k*B) & BMSK]++;
		for (i = 0; i < BMSK; ++i) t1[i+1] += t1[i];
		i = n; while (i--) tmp[--t1[(a[i] >> k*B) & BMSK]] = a[i];
		k++;
		for (i = 0; i < n; ++i) t2[(tmp[i] >> k*B) & BMSK]++;
		for (i = 0; i < BMSK; ++i) t2[i+1] += t2[i];
		i = n; while (i--) a[--t2[(tmp[i] >> k*B) & BMSK]] = tmp[i];
	}
	free(tmp);
#undef B
}

#define MAX 200005
ll s[MAX]; int n[MAX];

int main()
{
	int i, j, k, N, ma;

    N = in();
	for (i = 0; i < N; ++i) s[i] = ins();
	Usort(s, N);

	j = 0, k = 1, ma = 0;
	for (i = 1; i < N; ++i) {
		if (s[i] == s[j]) ++k, n[i] = 0;
		else {
			n[j] = k;
			if (k > ma) ma = k;
			j = i, k = 1;
		}
	}
    n[j] = k;
    if (k > ma) ma = k;

	for (i = 0; i < N; ++i) {
		if (n[i] == ma) outs(s[i]);
	}
	return 0;
}


Measured memory_bytes: 4196
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if (abs(a-c) <= d || (abs(a-b) <= d && abs(b-c) <= d)) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
using namespace std;
float pi=3.141592653; 
int main(){
    int a;
    cin>>a;
    a=a%10;
    if(a==2||a==4||a==5||a==7||a==9)
        cout<<"hon";
    else if(a==3)
        cout<<"bon";
else cout<<"pon";
return 0;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
int main()
{
long long int a,b,c,d,i,j,k;
vector<long long int>v;
cin>>a;
for(i=1;i<=a;i++)
{
cin>>b;
v.push_back(b);
}
for(i=a-1;i>=0;i-=2)
{
cout<<v[i]<<" ";
}
if(a%2==0)
{
for(i=0;i<a;i+=2)
{
cout<<v[i]<<" ";
}
}
else
{
for(i=1;i<a;i+=2)
{
cout<<v[i]<<" ";}}
}

Measured memory_bytes: 3824
#include<stdio.h>

int main(void)
{
  int i,j,k,x,count;
  char A[1025];
  char number[10][6]={
    {".,!? "},
    {"abc"},
    {"def"},
    {"ghi"},
    {"jkl"},
    {"mno"},
    {"pqrs"},
    {"tuv"},
    {"wxyz"},
  };
  scanf("%d",&x);
  for(i=0;i<x;i++){
    count=0;
    scanf("%s",A);
    for(j=0;A[j]!='\0';j++){
      if(A[j]=='0'&& j>0){
	if(('2'<=A[j-1] && A[j-1]<='6') || A[j-1]=='8'){
	  printf("%c",number[A[j-1]-'1'][(count-1)%3]);
	} else if(A[j-1]=='1'){
	  printf("%c",number[A[j-1]-'1'][(count-1)%5]);
	} else if(A[j-1]=='0'){
        } else{
	  printf("%c",number[A[j-1]-'1'][(count-1)%4]);
	}
	count=0;
      } else if(A[j]!='0'){
	count++;
      }
    }
    puts("");
  }

  return 0;
}


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int A,B,C;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>A>>B>>C;
	C-=(A-B);
	cout<<max(C,0)<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 256
/*#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
string s,t;
ll rui[2500005][2],ss[2];
ll f[2500005][2];
vector<int>edge[500005];
int dist[500005];
int in[500005];
int rec(int v){
	if(dist[v] != -1) return dist[v];
	rep(i,edge[v].size()){
		dist[v] = max(dist[v],rec(edge[v][i]));
	}
	return ++dist[v];
}
int main(){
	cin >> s >> t; int  n = s.size();
	while(s.size() < 1100000) s = s+s;
	f[0][0] = f[0][1] = 1;
	rep(i,2500003){
		f[i+1][0] = f[i][0]*31LL%mod;
		f[i+1][1] = f[i][1]*37LL%mod;
	}
	rep(i,s.size()){
		rui[i+1][0] = rui[i][0]+f[i+1][0]*(s[i]-'0'+1)%mod;
		rui[i+1][1] = rui[i][1]+f[i+1][1]*(s[i]-'0'+1)%mod;
		rui[i+1][0] %= mod;
		rui[i+1][1] %= mod;
	}
	rep(i,t.size()){
		ss[0] += f[i+1][0]*(t[i]-'0'+1)%mod;
		ss[1] += f[i+1][1]*(t[i]-'0'+1)%mod;
		ss[0] %= mod; ss[1] %= mod;
	}
	rep(i,s.size()){
		if(i+t.size()-1 >= s.size()) continue;
		rep(j,2){
			ll x = rui[i+t.size()][j]-rui[i][j]; x = (x%mod+mod)%mod;
			ll y = ss[j]; y = y*f[i][j]%mod; y = (y%mod+mod)%mod;
			if(x != y) goto fail;
		}
		edge[i%n].pb((i+t.size())%n); in[(i+t.size())%n]++;
		fail:;
	}
	queue<int>que;
	rep(i,n) if(in[i] == 0) que.push(i);
	while(!que.empty()){
		int q = que.front(); que.pop();
		rep(i,edge[q].size()){
			in[edge[q][i]]--; if(in[edge[q][i]] == 0) que.push(edge[q][i]);
		}
	}
	rep(i,n) if(in[i]) { cout << -1 << endl; return 0; }
	int ans = 0; memset(dist,-1,sizeof(dist));
	rep(i,n) ans = max(ans,rec(i));
	cout << ans << endl;
}

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

int main() {
  int x,a,b,c,d;
  cin >> x;
   a = x / 1000;
   x = x % 1000;
   b = x / 100;
   x = x % 100;
   c = x / 10;
   x = x % 10;
   d = x;
  if (a == b && b == c) {
    cout << "Yes" << endl;
  }
  else if (b == c && c == d) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


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

int main() {
    int T;
    cin >> T;
    while (T--) {
        int N, K;
        cin >> N >> K;
        vector<int> v(N);
        for (auto& i : v) cin >> i;
        int ans = v[N-1] - v[0];
        vector<int> sub;
        for (int i = 1; i < N; i++) {
            sub.push_back(v[i] - v[i-1]);
        }

        sort(sub.begin(), sub.end());

        int c = 1;
        while (c + 1 <= N && c < K) {
            ans -= sub[N-c-1];
            c++;
        }

        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 4072
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define MOD 1000000007
using namespace std;
typedef long long ll;
ll kai[500001], inv[500001];
int n, k;
ll mod_pow(ll x, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) {
      res = res * x % mod;
    }
    x = x * x % mod;
    n /= 2;
  }
  return res;
}
void init() {
  kai[0] = 1LL;
  for (ll i = 1LL; i <= 500000; i++) {
    kai[i] = kai[i - 1] * i;
    kai[i] %= MOD;
  }
  inv[500000] = mod_pow(kai[500000], MOD - 2LL, MOD);
  for (ll i = 499999; i >= 0; i--) {
    inv[i] = inv[i + 1] * (i + 1);
    inv[i] %= MOD;
  }
}

ll comb(ll r, ll c) {
  ll res;
  res = kai[r];
  res *= inv[c];
  res %= MOD;
  res *= inv[r - c];
  res %= MOD;
  return res;
}
int main() {
  ll m, ans, x;
  cin >> n >> m;
  init();
  ans = comb(m, n) * kai[n] % MOD;
  x = ans;
  for (ll i = 1; i <= n; i++) {
    if (i % 2LL == 1LL) {
      x += (MOD - comb(m - i, n - i) * comb(n, i) % MOD * kai[n - i] % MOD);
      x %= MOD;
    } else {
      x += comb(m - i, n - i) * comb(n, i) % MOD * kai[n - i] % MOD;
      x %= MOD;
    }
  }
  cout << ans * x % MOD << endl;
}

Measured memory_bytes: 11448
import std.stdio;
import std.c.stdio;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;
import std.c.string;
import std.regex;
import std.typecons;

double pow(double x, int n) {
    if (n == 0) return 1.0;
    if (n % 2 == 1) return pow(x, n - 1) * x;
    return pow(x * x, n / 2);
}
 
void main() {
    int s, n, t, p, m;
    string weekday, time;

    bool input() {
        readf("%d %d %d %s %s %d %d\n", &s, &n, &t, &weekday, &time, &p, &m);
        //writeln([s, n, t, p, m]);
        //writeln([weekday, time]);
        return (weekday != "None");
    }

    void solve() {
        const W = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
        double Ans = 0.0;
        foreach (k; 0 .. 1440) {
            int ct = cast(int)k;
            int cw = 0;
            bool check() {
                if (weekday == "All") {
                    if (time == "All") return true;
                    if (time == "Day" && 360 <= ct && ct + s < 1080) return true;
                    if (time == "Night" && ((0 <= ct && ct + s < 360) || (1080 <= ct && ct + s < 1440 + 360))) return true;
                } else if (W[cw] == "Sun")  {
                    if (time == "All" && ct + s < 1440) return true;
                    if (time == "Day" && 360 <= ct && ct + s < 1080) return true;
                    if (time == "Night" && ((0 <= ct && ct + s < 360) || (1080 <= ct && ct + s < 1440))) return true;
                }
                return false;
            }
            int C = 0;
            foreach (_; 0 .. m) {
                //writeln([ct, cw]);
                if (check) {
                    C += n;
                }
                ct += t;
                if (ct >= 1440) {
                    ct -= 1440;
                    cw = (cw + 1) % 7;
                }
            }
            Ans = max(Ans, 1.0 - pow(1.0 - 1.0 / p, C));
        }
        writefln("%.10f", Ans);
    }

    while (input) solve;
}

Measured memory_bytes: 1152
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <cmath>
#include <set>
#include <bitset>
#include <limits>

using namespace std;

#define ll long long

int main(void){
    int n;
    cin >> n;

    for(int i = 0;;++i){
        if(i*1000 >= n){
            cout << -n + 1000*i << endl;
            break;
        }
    }

    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353

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

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

	ll n, m;cin >> n >> m;
	cout << (n + m) * (n + m - 1) / 2 - n * m << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mp(a, b) make_pair(a, b)
typedef long long ll;
typedef pair<int, int> pii;
const int maxn = 3e5 + 10;
multiset<int> S;
int cnt[maxn];
int ans;
int h, w, m;
pii a[maxn];
int main()
{
	scanf("%d%d%d", &h, &w, &m);
	for(int i = 1; i <= m; ++i) 
	{
		scanf("%d%d", &a[i].first, &a[i].second);
		++cnt[a[i].second];
	}
	sort(a + 1, a + m + 1);
	for(int i = 1; i < maxn; ++i)
		if(cnt[i])
			S.insert(cnt[i]);
	int j = 1;
	for(int i = 1; i <= m; i = j)
	{
		while(j <= m && a[i].first == a[j].first)
		{
			S.erase(S.find(cnt[a[j].second]));
			--cnt[a[j].second];
			S.insert(cnt[a[j].second]);
			++j;
		}
		ans = max(ans, j - i + *S.rbegin());
		for(int k = j - 1; k >= i; --k)
		{
			S.erase(S.find(cnt[a[k].second]));
			++cnt[a[k].second];
			S.insert(cnt[a[k].second]);
		}
	}
	printf("%d\n", ans);
	return 0;
}
	

Measured memory_bytes: 21388
import sys
input = sys.stdin.readline

n = list(input().strip())
ans = 0

carry = False
for i in range(len(n) - 1, -1, -1):
    p = int(n[i])
    if carry:
        p += 1
        carry = False
    if p == 10:
        carry = True
    elif p >= 6:
        carry = True
        ans += 10 - p
    elif p == 5:
        if i != 0 and int(n[i - 1]) >= 5:
            carry = True
            ans += 5
        else:
            carry = False
            ans += 5
    else:
        ans += p
if carry:
    ans += 1
print(ans)


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

int main() {
	int n,m;cin>>n>>m;
	vector<int> a(m),b(m);
	vector<long long> c(m);
	for(int i=0;i<m;i++){
		cin>>a[i]>>b[i]>>c[i];
		a[i]--;
		b[i]--;
		c[i]*=-1;
	}
	long long def=1;
	for(int i=0;i<13;i++)def*=10;
	vector<long long> d(n,def);
	d[0]=0;
	for(int i=0;i<n-1;i++){
		for(int j=0;j<m;j++){
			int u=a[j];
			int v=b[j];
			if(d[u]==def)continue;
			if(d[v]>d[u]+c[j]){
				d[v]=d[u]+c[j];
			}
		}
	}
	long long ans=-d[n-1];
	for(int i=0;i<n-1;i++){
		for(int j=0;j<m;j++){
			int u=a[j];
			int v=b[j];
			if(d[u]==def)continue;
			if(d[v]>d[u]+c[j]){
				d[v]=d[u]+c[j];
			}
		}
	}
	if(ans==-d[n-1]){
		cout<<ans<<endl;
	}else{
		cout<<"inf"<<endl;
	}
//	int flag=1;
//	for(int j=0;j<m;j++){
//		int u=a[j];
//		int v=b[j];
//		if(d[u]==def)continue;
//		if(d[v]>d[u]+c[j]){
//			flag=0;
//		}
//	}
//	if(flag){
//		cout<<-1*d[n-1]<<endl;
//	}else{
//		cout<<"inf"<<endl;
//	}
	return 0;
}

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

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

const int mod = 1000000007;
//const int mod = 998244353;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
    mint operator+(const mint a) const { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}


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

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

// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
    vector<mint> fact, ifact;
    combination(int n):fact(n+1),ifact(n+1) {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
    }
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[k]*ifact[n-k];
    }
};
int main() {
    int N;
    cin >> N;
    int m = 0;
    map<string, int> mp;
    rep(i, N) {
        string str;
        cin >> str;
        mp[str]++;
        chmax(m, mp[str]);
    }

    for (auto p: mp) {
        if (p.second == m) {
            cout << p.first << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 25216
H, W = map(int,input().split())
dp = [[None]*10 for _ in range(10)]
for i in range(10):
    ls = list(map(int,input().split()))
    for j in range(10):
        dp[i][j] = ls[j]
from collections import defaultdict
d = defaultdict(int)
for i in range(H):
    for a in map(int,input().split()):
        d[a] += 1
for k in range(10):
    for i in range(10):
        for j in range(10):
            dp[i][j] = min(dp[i][j], dp[i][k]+dp[k][j])
ans = 0
for i in range(10):
    if i == 1:
        continue
    ans += dp[i][1]*d[i]
print(ans)

Measured memory_bytes: 3316
//ProblemA

//#define USE_STDIO
//#define USE_LOG
//#define FILE_ERR

#ifdef _MYPC
#include "mypc.h"
#endif // _MYPC

#ifndef debug
#define debug(...)
#endif // !LOG

//include
#include <iostream>
#include <string>
#include <vector>
#include <bitset>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <algorithm>
#include <numeric>
#include <functional>
#include <memory>
#include <complex>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iomanip>

using namespace std;

//for
#define forn(i, n) for(int i = 0; i < (int)(n); i++)
#define forbe(i, begin, end) for(decltype(begin) i = (begin); i != (end); ++i)
#define forbes(i, begin, end, step) for(decltype(begin) i = (begin); i != (end); i += (step))

//int
using ll = long long;
using ull = unsigned long long;
using uint = unsigned;

//pair
using pii = std::pair<int, int>;
using pll = std::pair<ll, ll>;
#define fi first
#define se second

//vector
template <typename Value>
static inline void fillv(Value& x, const Value& val) { x = val; }
template <typename Vector, typename Value>
static inline void fillv(Vector& v, const Value& val) { for (auto& x : v) fillv(x, val); }

static inline void Solve();

int main(int argc, char* argv[]) {
#ifdef REDIRECT_STDIO
	REDIRECT_STDIO;
#endif // REDIRECT_STDIO

	Solve();
	return 0;
}

int get_sum(int n) {
	int ans = 0;
	while (n)
	{
		ans += n % 10;
		n /= 10;
	}
	return ans;
}

//ProblemA
void Solve() {
	int n;
	cin >> n;

	int minbits = 200;
	for (int i = 1; i <= n / 2; i++) {
		int j = n - i;
		int b = get_sum(i) + get_sum(j);
		minbits = min(minbits, b);
	}
	cout << minbits << endl;
}


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

char S1[1001];
char S2[1001];

int LCS(int, int);

int main(){
  int n, i, commonlength;
  int len1, len2;

  scanf("%d",&n);

  for(i = 0 ; i < n ; i++){
    scanf("%s",S1);
    scanf("%s",S2);
    len1 = strlen(S1);
    len2 = strlen(S2);

    commonlength = LCS(len1,len2);
    printf("%d\n",commonlength);
  }

  return 0;
}

int LCS(int x, int y){
  int i, j;
  int C[1001][1001];

  for(i = 0 ; i <= x ; i++) C[i][0] = 0;
  for(i = 0 ; i <= y ; i++) C[0][i] = 0;

  for(i = 1 ; i <= x ; i++){
    for(j = 1 ; j <= y ; j++){
      if(S1[i-1] == S2[j-1]){
	C[i][j] = C[i-1][j-1]+1;
      }
      else if(C[i-1][j-1] >= C[i][j-1]){
	C[i][j] = C[i-1][j];
      }
      else{
	C[i][j] = C[i][j-1];
      }
    }
  }

  if(i == 0 || j == 0) return 0;
  else if(i > 0 && j > 0 && x == y) return C[i-1][j-1];
  else if(i > 0 && j > 0 && x != y) return C[x][y];
}



Measured memory_bytes: 5612
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int[] d = in.nextIntArray(n);

            int m = in.nextInt();
            int[] t = in.nextIntArray(m);

            Arrays.sort(d);
            Arrays.sort(t);

            int indexD = 0;
            int indexT = 0;

            for (int i = 0; i < m; i++) {
                while (indexT < m && indexD < n && t[indexT] != d[indexD]) {
                    indexD++;
                    if (indexD == n) {
                        out.println("NO");
                        return;
                    }
                }
                indexT++;
                indexD++;
            }

            out.println("YES");
        }

    }

    static class InputReader {
        BufferedReader in;
        StringTokenizer tok;

        public String nextString() {
            while (!tok.hasMoreTokens()) {
                try {
                    tok = new StringTokenizer(in.readLine(), " ");
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
            }
            return tok.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(nextString());
        }

        public int[] nextIntArray(int n) {
            int[] res = new int[n];
            for (int i = 0; i < n; i++) {
                res[i] = nextInt();
            }
            return res;
        }

        public InputReader(InputStream inputStream) {
            in = new BufferedReader(new InputStreamReader(inputStream));
            tok = new StringTokenizer("");
        }

    }
}



Measured memory_bytes: 62476