akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>

using namespace std;

struct Edges
{
    int u,v;
};

struct Sub
{
    int p, r; // p for parent, r for rank
};

Edges e[100002]; //Sub s[1000000];
int n, m, a[100002], c,x,y;
int d, j = 0, father[1000000];
long long res = 0;
bool visited[1000000];
vector <int> forest;
vector <int> part[1000000], g[1000000];

void init()
{
    for (int i=0;i<n;++i)
        visited[i] = false;
}

void read()
{
    cin >> n >> m;
    for (int i=0;i<n;++i) cin >> a[i];
    for (int i=1;i<=m;++i)
    {
        cin >> x >> y;
        g[x].push_back(y);
        g[y].push_back(x);
    }
}

void scan(int x)
{
    visited[x] = true; part[d].push_back(a[x]);
    for (int i=0; i<(int)g[x].size(); ++i)
    {
        if (!visited[g[x][i]]) scan(g[x][i]);
    }
}

void solve()
{
    for (int i = 0; i<n;++i)
        if (!visited[i]) { d++; scan(i);}
    for (int i = 1; i<=d;++i)
    {
        sort(part[i].begin(),part[i].end());
        for (int j=1;j<(int)part[i].size();++j)
            forest.push_back(part[i][j]);
        res += part[i][0];
    }
    if (d==1) {res = 0; return;}
    if ((int)forest.size()<d-2) {res = - 1; return;}
    sort(forest.begin(), forest.end());
    for (int i=0; i< d-2; ++i)
        res += forest[i];
}

void print()
{
    if (res == -1) cout << "Impossible";
    else cout << res;
}

int main()
{
    read();init();solve();print();
    return 0;
}

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

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

int H, W;

int dh[4] = {0, 0, -1, 1};
int dw[4] = {-1, 1, 0, 0};

bool is_in_field(int i, int j){
    return i >= 0 && i < H && j >= 0 && j < W;
}

int sh, sw, th, tw;
char S[1000][1000];
int dist[1000][1000];
bool used[1000][1000];

int to_idx(int h, int w){
    return h*W+w;
}

int to_h(int idx){
    return idx/W;
}

int to_w(int idx){
    return idx%W;
}

const int INF = 1e9;

void solve(){
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            dist[i][j] = INF;
        }
    }
    priority_queue<P, vector<P>, greater<P>> que;
    dist[sh][sw] = 0;
    que.push(P(0, to_idx(sh, sw)));
    while(!que.empty()){
        P p = que.top();
        que.pop();
        int idx = p.second;
        int h = to_h(idx);
        int w = to_w(idx);
        for(int i = 0; i < 4; i++){
            int h_to = h+dh[i];
            int w_to = w+dw[i];
            if(is_in_field(h_to, w_to)){
                if(S[h_to][w_to] == '.'){
                    if(dist[h_to][w_to] > dist[h][w]){
                        dist[h_to][w_to] = dist[h][w];
                        que.push(P(dist[h_to][w_to], to_idx(h_to, w_to)));
                    }
                }
            }
        }
        for(int i = -2; i <= 2; i++){
            for(int j = -2; j <= 2; j++){
                int h_to = h+i;
                int w_to = w+j;
                if(is_in_field(h_to, w_to)){
                    if(S[h_to][w_to] == '.'){
                        if(dist[h_to][w_to] > dist[h][w]+1){
                            dist[h_to][w_to] = dist[h][w]+1;
                            que.push(P(dist[h_to][w_to], to_idx(h_to, w_to)));
                        }
                    }
                }
            }
        }
    }
    if(dist[th][tw] == INF){
        cout << -1 << endl;
    }else{
        cout << dist[th][tw] << endl;
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    cin >> H >> W;
    cin >> sh >> sw; sh--; sw--;
    cin >> th >> tw; th--; tw--;
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            cin >> S[i][j];
        }
    }
    solve();
    // for(int i = 0; i < H; i++){
    //     for(int j = 0; j < W; j++){
    //         cout << dist[i][j] << ' ';
    //     }
    //     cout << endl;
    // }
}

Measured memory_bytes: 8544
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define all(v) begin(v), end(v)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int const MOD = 1000000007;

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

signed main() {
    int sum[1010] = {};
    rep(i,1,1010) {
        sum[i] = i;
        sum[i] += sum[i-1];
    }

    int rec[600000] = {};
    repq(i,2,1000) {
        repq(j,1,1000-(i-1)) {
            int num = sum[j+i-1] - sum[j-1];
            rec[num]++;
        }
    }

    int n;
    while(cin >> n, n) {
        cout << rec[n] << endl;
    }
    return 0;
}

Measured memory_bytes: 7768
#include<iostream>
#include<string>
#include<typeinfo>
#include<vector>
#include<algorithm>
#include<map>
#include<iomanip>
typedef long long int ll;
using namespace std;
int main()
{
	int n;
	cin >> n;
	string s;
	cin >> s;
	vector<int> abc(26,0);
	for(int i=0; i<n; i++){
		abc.at(s.at(i)-'a')++;
	}

	ll ans=1;
	for(int i=0; i<26; i++){
		if(abc.at(i)){
			ans *= (abc.at(i) + 1);
		}
		if(ans > 1000000007){
			ans%=1000000007;
		}
	}
	ans --;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 512
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)*}
    };
}

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)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

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

fn main() {
    input!{
        c: [chars; 3],
    }
    println!("{}{}{}", c[0][0], c[1][1], c[2][2]);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long int m1,m2,d1,d2,ans=0,ans1=0;
  	cin >> m1 >> d1;
  	cin >> m2 >> d2;
  	if(m1==1 && d1==31)	ans=1;
  	else if(m1==2 && d1==28)	ans=1;
  	else if(m1==3 && d1==31)	ans=1;
  	else if(m1==4 && d1==30)	ans=1;
  	else if(m1==5 && d1==31)	ans=1;
  	else if(m1==6 && d1==30)	ans=1;
  	else if(m1==7 && d1==31)	ans=1;
  	else if(m1==8 && d1==31)	ans=1;
  	else if(m1==9 && d1==30)	ans=1;
  	else if(m1==10 && d1==31)	ans=1;
  	else if(m1==11 && d1==30)	ans=1;
  	else if(m1==12 && d1==31)	ans=1;
  	if(ans)	cout << "1" << endl;
  	else	cout << "0" << endl;
  	return 0;
}

Measured memory_bytes: 256
//~ while (clock()<=69*CLOCKS_PER_SEC)
//~ #pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
//~ #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 __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define shandom_ruffle random_shuffle

using ll=long long;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using vi=vector<int>;
using vll=vector<ll>;
const int nax=1000*1007;

int n;

int tab[nax];

vector <pii> wek;

int check(int v)
{
	wek.clear();
	wek={{0, 0}};
	for (int i=1; i<=n; i++)
	{
		if (tab[i]>tab[i-1])
			continue;
		while(wek.back().first>tab[i])
			wek.pop_back();
			
		int r=tab[i];
		while(wek.back().first==r && wek.back().second==v-1)
		{
			wek.pop_back();
			r--;
		}
		if (!r)
			return 0;
		if (wek.back().first==r)
			wek.back().second++;
		else
			wek.push_back({r, 1});
			
	}
	return 1;
}

int main()
{
	scanf("%d", &n);
	for (int i=1; i<=n; i++)
		scanf("%d", &tab[i]);
	int czy=1;
	for (int i=2; i<=n; i++)
		if (tab[i]<=tab[i-1])
			czy=0;
	if (czy)
	{
		printf("1\n");
		return 0;
	}
	int bsa=2;
	int bsb=n;
	while(bsa<bsb)
	{
		int bss=(bsa+bsb)>>1;
		if (check(bss))
			bsb=bss;
		else
			bsa=bss+1;
	}
	printf("%d\n", bsa);
	return 0;
}


Measured memory_bytes: 1024
n = int(input())
l = [list(map(int,input().split())) for i in range(n)]

dp = [[0 for i in range(3)] for i in range(n)]

dp[0] = l[0]

for i in range(1,n):
    dp[i][0] = max(dp[i-1][1]+l[i][0], dp[i-1][2]+l[i][0])
    dp[i][1] = max(dp[i-1][0]+l[i][1], dp[i-1][2]+l[i][1])
    dp[i][2] = max(dp[i-1][0]+l[i][2], dp[i-1][1]+l[i][2])

print(max(dp[-1]))

Measured memory_bytes: 76632
#include "bits/stdc++.h"
using namespace std;

bool di(char f) {
	return f >= '0' && f <= '9';
}

int main() {
    
    int a, b;
    cin >> a >> b;
    string s;
    cin >> s;
    bool ye = true;
    for (int i=0; i<a; i++) if (!di(s[i])) ye = false;
    for (int i=a+1; i<a+b+1; i++) if (!di(s[i])) ye = false;
    ye = ye && s[a] == '-';
    if (ye) cout << "Yes" << endl;
    else cout << "No" << endl;
    
}


Measured memory_bytes: 256
n, m = map(int, input().split())
h = list(map(int, input().split()))

obs = [0]*n

for _ in range(m):
    a, b = map(lambda x: int(x)-1, input().split())
    if h[a] > h[b]:
        obs[b] = 1;
    elif h[b] > h[a]:
        obs[a] = 1;
    else:
        obs[a] = 1;
        obs[b] = 1;

print(obs.count(0))


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

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

  for(i = 1; i <= n; i++){
    if(i % 3 == 0 || i % 10 == 3 || (i / 10) % 10 == 3 || (i / 100) % 10 == 3 || (i / 1000) % 10 == 3){
     cout << " " << i;
   }
  }
  cout << endl;
  return 0;
}

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

int main(){
	int n;
	string s;
	
	cin >> n;
	cin.ignore();
	for(int i=0 ; i<n  ; i++){
		getline( cin , s );
		
		while( s.find("Hoshino",0) != string::npos){
			unsigned i = s.find("Hoshino",0);
			s.replace( i , 7 , "Hoshina" );
		}
		cout << s << endl;
	}
	
	return 0;
}

Measured memory_bytes: 0
#include<stdio.h>
int main()
{
    int H,W,n,i,x,t,j,p=0,v=1;
    scanf("%d %d",&H,&W);
    int a[H][W];
    int b[H*W];
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d",&x);
        for(j=0;j<x;j++)
        {
            b[p]=v;
            p++;
        }
        v++;
    }
    p=0;
    printf("\n");
    for(i=0;i<H;i++){
    if(i%2!=1){
        for(j=0;j<W;j++)
        a[i][j]=b[p++];
    }
    else {  for(j=W-1;j>=0;j--)
        a[i][j]=b[p++];
    }}
    for(i=0;i<H;i++)
      {
        for(j=0;j<W;j++)
        printf("%d ",a[i][j]);
        printf("\n");}
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
 int i,k,n;
 long long int s;
 s=0;
 cin >> n >> k;
 int a[n];
 for(i=0;i<n;i++)
 cin >> a[i];
 sort(a,a+n,greater<int>());
 for(i=k;i<n;i++)
 s+=a[i];
 cout << s;
 return 0;
}

Measured memory_bytes: 1152
#include<iostream>
#include<string>
#include<algorithm>
#include <vector>

using namespace std;
int main(void){
    int n,l;
    string str,out("");
    vector<string> s;

    cin >> n >> l;
    for(int i=0;i<n;i++){
        cin >> str;
        s.push_back(str);
    }
    
    sort(s.begin(),s.end());
    for(int i=0;i<n;i++){
        out+=s.at(i);
    }

    cout << out << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
main()
{
	long long int n;
	long long int a[5], i, ans = 0;
	for(i=0;i<5;i++)
	{
	cin >> a[i];
	if(a[i] == 0)
	cout << i+1 << " ";
}
 	
	
	return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> i_i;

#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define ALL(v) v.begin(), v.end()
#define SZ(x) ((int)(x).size())
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
    int N, M;
    int sum = 0, A;
    cin >> N >> M;
    //vector<int> A(M);
    rep(i, M){
        cin >> A;
        sum += A;
    }
    cout << max(-1, N - sum);
    
    return 0;
}


Measured memory_bytes: 3636
s = input()
akiba = 'AKIHABARA'
s_i = 0
aki_i = 0
while (s_i < len(s)) & (aki_i < len(akiba)):
    if s[s_i] == akiba[aki_i]:
        s_i += 1
        aki_i += 1
    else:
        if akiba[aki_i] == "A":
            aki_i += 1
        else:
            print("NO")
            exit()
if ((s_i == len(s)) & (aki_i >= 8)):
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3064
#include <iostream>                                             
using namespace std;                                            
                                                                
int main(void) {                                                
  int W, H, x, y, r;                                            
  cin >> W >> H >> x >> y >> r;                                 
  if (x>=r && y>=r && W-x>=r && H-y>=r) {                       
    cout << "Yes" << endl;                                      
  } else {                                                      
    cout << "No" << endl;                                       
  }                                                             
  return 0;                                                     
}                                                               
                                                                
                    

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

int main(){
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    long int n;
    
    cin >> n;

    set<string> st;

    while(n--){
        string str;

        cin >> str;
        st.insert(str); 
    }

    int size = st.size();

    cout << size << "\n";

    return 0;
}


Measured memory_bytes: 19212
#include<bits/stdc++.h>
using namespace std;
const int N = 20;
int n, m, M[N][N], P[N], C[N];
int main()
{
    scanf("%d%d", &n, &m);
    for (int i = 0; i < m; i++)
    {
        int d, a;
        scanf("%d", &d);
        for (; d; d --)
            scanf("%d", &a), M[a - 1][i] = 1;
    }
    for (int i = 0; i < m; i++)
        scanf("%d", &P[i]);
    int cnt = 0;
    for (int i = 0; i < (1 << n); i++)
    {
        memset(C, 0, sizeof(C));
        for (int j = 0; j < n; j++)
            if ((i >> j) & 1)
                for (int h = 0; h < m; h++)
                    if (M[j][h])
                        C[h] ^= 1;
        int bad = 0;
        for (int j = 0; j < m; j++)
            if (C[j] != P[j])
                bad = 1;
        if (!bad) cnt ++;
    }
    return !printf("%d\n", cnt);
}

Measured memory_bytes: 256
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define REPR(i,n) for(int i=n-1;i>=0;i--)
#define FORR(i,n,m) for(int i=n-1;i>=m;i--)
#define ARR(array) for(int i=0;i<array.size();i++)
#define all(in) in.begin(),in.end()
#define ALL(in,K) in,in+K
#define INF 1e18
#define MOD 100000007
#define SIZE 10005
#define PI 	3.14159265358979323846

unsigned euclidean_gcd(unsigned a, unsigned b) {
  if(a < b) euclidean_gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

char input(){
  char a;
  cin >> a;
  return a;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    ll ans = 0;
    ll a[100000] ;
    REP(i,n)cin >> a[i];
    sort(a,a+n);
    ll roop=0;
    REP(i,n-1){
      roop++;
      if(a[i]!=a[i+1]){
        if(roop%2)ans++;
        roop=0;
      }
    }
    roop++;
    if(roop%2)ans++;
    cout << ans << endl;
}

Measured memory_bytes: 1024
icase=0
if icase==0:
    n=int(input())
    v=list(map(int,input().split()))
    c=list(map(int,input().split()))
    tmax=0
    for i in range(n):
        total = 0
        for j in range(n):
            total = total+max(0,v[j]-c[j])   
        tmax=max(tmax,total)
    print(tmax)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define ll long long
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(i, n) for(int i=0; i<=n; i++)
#define repr(i, n) for(int i=n; i>0; i--)
#define REPR(i, n) for(int i=n; i>=0; i--)
const ll INF = 1LL<<60;
const int INT_INF = 1e9;
const ll MOD = 1e9+7;
template<class T> void puts(T x) { std::cout << x << std::endl; }
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; }
using namespace std;

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

    // エラトステネスの篩
    bool is_prime[1010];
    vector<int> prime_numbers;
    rep(i, 1010) is_prime[i] = true;
    for (int i = 2; i <= n; i++) {
        if (is_prime[i]) {
            for (int j = 2*i; j <= n; j += i) {
                is_prime[j] = false;
            }
            prime_numbers.emplace_back(i);
        }
    }

    map<int, int> m;
    for (int p: prime_numbers) m[p] = 0;

    for (int x = 1; x <= n; x++) {
        int num = x;
        for (int p: prime_numbers) {
            while (num % p == 0) {
                num /= p;
                m[p] += 1;
            }
        }
    }

    ll ans = 1;
    for (auto elem: m) {
        ans *= elem.second + 1;
        ans %= MOD;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
def takahashi():
    N = int(input())
    L = [input() for _ in range(N)]
    if len(L) != len(set(L)):
        print("No")
        return
    for i in range(N - 1):
        if L[i][-1] != L[i + 1][0]:
            print("No")
            return
    print("Yes")


takahashi()


Measured memory_bytes: 3060
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

a1 = (a + 9) //10 * 10
b1 = (b + 9) //10 * 10
c1 = (c + 9) //10 * 10
d1 = (d + 9) //10 * 10
e1 = (e + 9) //10 * 10

tmax = 0
if tmax < a1 - a:
	tmax =a1 - a
if tmax < b1 - b:
	tmax =b1 - b
if tmax < c1 - c:
	tmax =c1 - c
if tmax < d1 - d:
	tmax =d1 - d
if tmax < e1 - e:
	tmax =e1 - e
print(a1+b1+c1+d1+e1-tmax)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
const int N = 150;
const int M = 1e4 + 1000;
int h,w;
int n;
int ans[N][N];
int a[M];
int main() {
	//freopen("in.txt","r",stdin);
	cin>>h>>w;
	cin>>n;
	for(int i=0;i<n;i++)scanf("%d",&a[i]);
	
	int r = 0, c = 0, ad = 1;
	int col;
	for(int i=0;i<n;i++) {
		col = i + 1;
		for(int j=0;j<a[i];j++) {
			ans[r][c] = col;
			c = c + ad;
			if(c == w || c == -1) {
				if(ad == 1)ad = -1;
				else ad = 1;
				r ++; c = c + ad;
			}
		}
	}
	
	for(int i=0;i<h;i++) {
		for(int j=0;j<w;j++) {
			printf("%d%c",ans[i][j],(j==w-1)?'\n':' ');
		}
	}
}

Measured memory_bytes: 384
[K,N] = [int(s) for s in input().rstrip().split(' ')]
L_A = [int(s) for s in input().rstrip().split(' ')]
s = L_A[0] + K - L_A[-1]
for i in range(N-1):
  if s < L_A[i+1] - L_A[i]:
    s = L_A[i+1] - L_A[i]
print(K-s)

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

int decreasingSubArray(vector<int> &a) {
    int n = a.size();

    int res = 0, cur = 0;

    for(int i = 1; i < n; i++) {
        if(a[i] <= a[i - 1]) {
            cur++;
        }
        else cur = 0;

        res = max(res, cur);
    }

    return res;
}

int main() {
    ios_base::sync_with_stdio(false);

    int n;
    cin >> n;

    vector<int> a(n);

    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }

    int ans = decreasingSubArray(a);

    cout << ans << endl;
}


Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = scanner.nextInt();
            a[i]--;
        }

        int res = 0;
        int prev = -1;
        for (int i = 0; i < n; i++) {
            if (i == a[i]) {
                if (prev >= 0 && prev + 1 == i) {
                    res++;
                    prev = -1;
                } else if (prev >= 0) {
                    res++;
                    prev = i;
                } else {
                    prev = i;
                }
            }
        }
        if (prev >= 0) res++;
        System.out.println(res);
    }
}


Measured memory_bytes: 52648
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define maxn 1005
#define inf 1e9
#define pb push_back
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
using namespace std;

inline ll read()
{
	ll x=0,w=1; char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}
	while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
	return w==1?x:-x;
}

int main()
{
    string s,t;
    cin>>s>>t;
    int flag=0;
    int len=s.size();
    for(int i=1;i<=len+1&&!flag;++i){
        if(s==t) flag=1;
        s=s.substr(s.size()-1,1)+s.substr(0,s.size()-1);
        //cout<<s<<endl;
    }
    printf("%s\n",flag?"Yes":"No");

    return 0;
}


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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

int main() {
	int n = ri();
	int a[n];
	for (int i = 0; i < n; i++) a[i] = ri();
	int res = 1000000000;
	for (int i = 0; i <= n; i++) {
		int sum1 = 0;
		for (int j = 0; j < i; j++) sum1 += a[j];
		int sum2 = 0;
		for (int j = i; j < n; j++) sum2 += a[j];
		res = std::min(res, std::abs(sum1 - sum2));
	}
	std::cout << res << std::endl;
	return 0;
}


Measured memory_bytes: 764
#include "stdio.h"

int dpw[100][2];
int dph[111][2];

int dpww[100][2];
int dphw[111][2];

int main()
{
	while(1)
	{
		int h,w;
		scanf("%d %d",&h,&w);
		if(h == 0 && w == 0)
		{
			break;
		}
		h--;
		w--;
		for(int i = 0; i < w; i++)
		{
			dpw[i][0] = 1;
			dpw[i][1] = 0;
		}
		for(int i = 0; i <= w; i++)
		{
			dph[i][0] = 0;
			dph[i][1] = 0;
		}
		for(int i = 0; i < h; i++)
		{
			dphw[0][0] = 1;
			dphw[0][1] = 0;
			for(int i = 0; i < w; i++)
			{
				dphw[i + 1][0] = dph[i + 1][0] + dph[i + 1][1];
				dphw[i + 1][1] = dpw[i][0];
			}
			for(int i = 0; i <= w; i++)
			{
				dph[i][0] = dphw[i][0] % 100000;
				dph[i][1] = dphw[i][1] % 100000;
			}
			int now = 0;
			for(int i = 0; i < w; i++)
			{
				dpww[i][0] = now;
				now += (dpww[i][1] = dph[i][0]);
			}
			for(int i = 0; i < w; i++)
			{
				dpw[i][0] = dpww[i][0] % 100000;
				dpw[i][1] = dpww[i][1] % 100000;
			}
		}
		printf("%d\n",(dpw[w - 1][0] + dpw[w - 1][1] + dph[w][0] + dph[w][1]) % 100000);
	}
	return 0;
}

Measured memory_bytes: 1024
s = int(input())
a = []
count = 1
finish = 0

a.append(s)
while finish == 0:
    if s % 2 == 0:
        s = int(s/2)
    else:
        s = (3 * s) + 1

    a.append(s)
    
    count = count + 1

    for i in range(count -1):
        if a[i] == s:
            finish = 1

print(count)

Measured memory_bytes: 3064
A,B = map(int,input().split())

S = input()

num = "0123456789"

ans = "Yes"

if len(S) != A+B+1:
    ans = "No"

for i in range(len(S)):

    if i != A and S[i] not in num:
        ans = "No"

    if i == A and S[i] != "-":
        ans = "No"

print (ans)


Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String str;
		String[] arr = null;
		int a;
		int b;

		do {
			str = sc.nextLine();
			arr = str.split(" ");
			a = Integer.parseInt(arr[0]);
			b = Integer.parseInt(arr[2]);

			if (arr[1].equals("?")) {
				break;
			} else {
				switch (arr[1]) {
				case "+": {
					System.out.println(a + b);
					break;
				}
				case "-": {
					System.out.println(a - b);
					break;
				}
				case "*": {
					System.out.println(a * b);
					break;
				}
				case "/": {
					System.out.println(a / b);
					break;
				}
				}
			}
		} while (!arr[1].equals("?"));
		sc.close();
	}
}



Measured memory_bytes: 26208
/**
 *    Creator :  bizarre
 *    Date : 3/2020
 *    Problem Number : 390
**/
#include <bits/stdc++.h>
using namespace std;
#define bizarre     ios_base::sync_with_stdio( false ), cin.tie( nullptr ), cout.tie( nullptr );
/*
const int inf = 2e9, mod = 1e9 + 7,N=1e6+5;
long long fact[N], inv[N];

void move1step(long long& a, long long& b, long long q)
{
    long long c= a-q*b;
    a=b;
    b=c;
}
long long egcd(long long r0,long long r1,long long& x0,long long& y0)
{
    long long x1=0,y1=1;
    x0=1;
    y0=0;
    while(r1)
    {
        long long q=r0/r1;
        move1step(r0,r1,q);
        move1step(x0,x1,q);
        move1step(y0,y1,q);
    }
    return r0;
}
bool  solve (long long a, long long b, long long c,long long&x, long long& y)
{
    long long g=egcd(a,b,x,y);
    int m=c/g;
    x*=m;
    y*=m;
    return c%g==0;
}
int npr(long long n, long long r)
{
    return (fact[n] * inv[n - r]) % mod;
}

int gcd(int a, int b)
{
    if(b==0)
        return a;
    return gcd(b,a%b);
}
int ncr(long long n, long long r)
{
    return (((fact[n] * inv[n - r]) % mod) * inv[r]) % mod;
}
void pre(long long n)
{
    fact[0] = 1;
    inv[0] = 1;
    for (long long i = 1; i <= n; i++)
    {
        fact[i] = (i * fact[i - 1]) % mod;
        inv[i] = fp(fact[i], mod - 2);
    }
}
long long fp(long long base, long long exp)
{
    if (exp == 0)
        return 1;
    long long ans = fp(base, exp / 2);
    ans = (ans * ans) % mod;
    if (exp % 2 != 0)
        ans = (ans * (base % mod)) % mod;
    return ans;
}
void PrimeFactorization(int n)
{
    for(int i=2; i*i<=n; i++)
    {
        int c=0;
        if(n%i==0)
        {
            while(n%i==0)
            {
                n/=i;
                c++;
            }

        }
    }

}
*/
const long long N=2e5+5;
vector<long long>v;
int main()
{
    long long n,k;
    cin>>n>>k;
    for(int i=0; i<n; i++)
    {
        int x;
        cin>>x;
        v.push_back(x);
    }
    sort(v.begin(),v.end());
    long long s=-1e18,e=1e18,mid;
    while(s+1!=e)
    {
        mid=(s+e)/2;
        long long cntr=0;
        for(int i=0; i<n; i++)
        {
            if(v[i]<0)
            {
                long long lo=i,hi=n,m;
                while(lo+1!=hi)
                {
                    m=(lo+hi)/2;
                    if(v[i]*v[m]<=mid)
                        hi=m;
                    else
                        lo=m;
                }
                cntr+=n-hi;
            }
            else
            {
                long long lo=i,hi=n,m;
                while(lo+1!=hi)
                {
                    m=(lo+hi)/2;
                    if(v[i]*v[m]<=mid)
                        lo=m;
                    else
                        hi=m;
                }
                cntr+=lo-i;
            }
        }
        if(cntr<k)
            s=mid;
        else
            e=mid;
    }
    cout << e;
    return 0;
}


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

using namespace std;

long long n, s, mn = LLONG_MAX;

long long check(long long base, long long num){
    if(num < base)
        return num;
    else
        return check(base, num / base) + num % base;
}

int main() {
    cin.tie(0), ios::sync_with_stdio(0);
    cin >> n >> s;
    if(n == s){
        cout << n + 1 << "\n";
        return 0;
    }
    for(long long i = 1; i <= sqrt(abs(n - s)); i++){
        if(abs(n - s) % i == 0){
            if(check(i + 1, n) == s)
                mn = min(mn, i + 1);
            long long sum = abs(n - s) / i;
            if(check(sum + 1, n) == s)
                mn = min(mn, sum + 1);
        }
    }
    if(mn == LLONG_MAX){
        cout << "-1\n";
        return 0;
    }
    cout << mn << "\n";
}


Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <limits.h>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string>
#include <vector>
#include <cstdio>
#include <iomanip>
#define ll long long
#define rep2(i,a,b) for(int i=a;i<=b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define rep3(i,a,b) for(int i=a;i>=b;i--)
#define REP(e,v) for(auto e:v)
#define queint queue<int>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue<int>//大きい順
#define pqg priority_queue<int,vec,greater<int>>//小さい順
#define pb push_back
#define vec vector<int>
#define vecvec vector<vector<int>>
#define vecll vector<ll>
#define vecvecll vector<vector<ll>>
#define bs binary_search
#define All(c) (c).begin(),(c).end()
#define mp make_pair
using namespace std;
int in(){int x;scanf("%d",&x);return x;}
string stin(){string s;cin>>s;return s;}
ll lin(){ll x;scanf("%lld",&x);return x;}
ll mod=1000000007;
ll modpow(ll a,ll p){
    if(p==0)return 1;
    if(p%2==0){
        ll d=modpow(a,p/2);
        return d*d%mod;
    }
    return a*modpow(a,p-1)%mod;
}

ll divide(ll a,ll b){
    return a*(ll)modpow(b,mod-2)%mod;
}
vecll perm;
void make_perm(ll m){
    perm.resize(m+1);
    perm[0]=1;
    rep2(i,1,m){
        perm[i]=perm[i-1]*i%mod;
    }
    return;
}
ll comb(ll a,ll b){
    return divide(divide(perm[a],perm[b]),perm[a-b])%mod;
}
int main(){
    int n=in(),k=in();
    make_perm(2*n+1);
    rep2(i,1,k)
        if(i>n-k+1)cout<<0<<endl;
        else cout<<comb(k-1,i-1)*comb(n-k+1,n-k-i+1)%mod<<endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
n, a, b = map(int, input().split())
ans = 0

for i in range(1, n + 1):
    arr = [int(c) for c in str(i)]
    sumarr = sum(arr)
    if sumarr >= a and sumarr <= b:
        ans += i

print(ans)


Measured memory_bytes: 9116
// atcoder/abc170/A/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;

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 << "("; for (auto& i: v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { for (auto& i: v) is >> i; return is; }
template<typename T> ostream& operator << (ostream& os, set<T> s) { os << "#{"; for (auto& i: s) os << i << ","; os << "}"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; for (auto& i: m) os << i << ","; os << "}"; return os; }

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); }

using lli = long long int;
using ull = unsigned long long;
using point = complex<double>;
using str = string;
template<typename T> using vec = vector<T>;

constexpr array<int, 8> di({0, 1, -1, 0, 1, -1, 1, -1});
constexpr array<int, 8> dj({1, 0, 0, -1, 1, -1, -1, 1});
constexpr lli mod = 1e9 + 7;

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

  vec<int> v(5);
  while (cin >> v) {
    for (int i = 0; i < v.size(); ++i) {
      if (v[i] == 0) cout << i+1 << endl;
    }
  }


  return 0;
}


Measured memory_bytes: 3656
#include<iostream>
using namespace std;
static const int MAX=100;
static const int INFTY=(1<<21);
static const int WHITE=0;
static const int GRAY=1;
static const int BLACK=2;

int n,m[MAX][MAX];

int prim(){
  int u,minv;
  int d[MAX],p[MAX],color[MAX];

  for(int i=0;i<n;i++){
    d[i]=INFTY;
    p[i]=-1;
    color[i]=WHITE;
  }

  d[0]=0;

  while(1){
    minv=INFTY;
    u=-1;
    for(int i=0;i<n;i++){
      if(minv>d[i]&&color[i]!=BLACK){
	u=i;
	minv=d[i];
      }
    }
    if(u==-1) break;
    color[u]=BLACK;
    for(int v=0;v<n;v++){
      if(color[v]!=BLACK&&m[u][v]!=INFTY){
	if(d[v]>m[u][v]){
	  d[v]=m[u][v];
	  p[v]=u;
	  color[v]=GRAY;
	}
      }
    }
  }
  int sum=0;
  for(int i=0;i<n;i++){
    if(p[i]!=-1) sum+=m[i][p[i]];
  }
  return sum;
}

int main(){
  cin>>n;
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      int e;
      cin>>e;
      m[i][j]=(e==-1)?INFTY:e;
    }
  }
  cout<<prim()<<endl;

  return 0;
}



Measured memory_bytes: 3120
n = int(input())
s = input()
w = 0
b = 0

for i in s:
    if i == ".":
        w += 1

m = w + b

for i in range(0, n):
    if s[i] == ".":
        w -= 1
    else:
        b += 1
    if w + b < m:
        m = w + b

print(m)

Measured memory_bytes: 3500
#include <iostream> // cout, endl, cin
#include <cmath> //sqrt pow
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
 
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define mod 1000000007
using ll = long long;
using namespace std;
int main(){
  int a,b;
  cin >> a >> b;
  cout << (a - 1) * (b - 1) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
 
    int A,B,C,X;

    cin >> A>>B>>C;

    X = A+B;

    if(X>=C){
        cout << "Yes"<<endl;
    }else{
        cout << "No" <<endl;
    }
    

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
using namespace std;

const int INF = 1e+8;
int N, M, L;

struct edge{
	int to, d, cost;
	edge(int to_, int d_, int cost_){
		to = to_; d = d_; cost = cost_;
	}
};
struct State{
	int cost, l, v;
	State(int cost_, int l_, int v_){
		cost = cost_; l = l_; v = v_;
	}
};
bool operator<(const State &a, const State &b){
	return a.cost > b.cost;
}
vector<edge> G[101];

void add_edge(int u, int v, int d, int cost){
	G[u].push_back( edge(v, d, cost) );
	G[v].push_back( edge(u, d, cost) );
}

// dp[l][v] := 使った予算が l で頂点が v のときの襲われた敵の数
int dp[101][101];

int dijkstra(){
	for(int i=0 ; i < 101 ; i++ ){
		for(int j=0 ; j < 101 ; j++ ){
			dp[i][j] = INF;
		}
	}
	priority_queue<State> q;
	q.push( State(0, 0, 0) );
	dp[0][0] = 0;
	
	int res = INF;
	while( !q.empty() ){
		int cost = q.top().cost, l = q.top().l, v = q.top().v;
		q.pop();
		if( v == N-1 ){
			res = min(res, cost);
			continue;
		}
		
		for(int i=0 ; i < G[v].size() ; i++ ){
			int to = G[v][i].to, d = G[v][i].d;
			
			// お金を使う
			if( l + d <= L ){
				int next_l = l + d;
				int next_cost = cost;
				if( next_cost < dp[next_l][to] ){
					dp[next_l][to] = next_cost;
					q.push( State(next_cost, next_l, to) );
				}
			}
			// お金を使わない
			int next_cost = cost + G[v][i].cost;
			if( next_cost < dp[l][to] ){
				dp[l][to] = next_cost;
				q.push( State(next_cost, l, to) );
			}
		}
	}
	return res;
}

int main(){
	while( cin >> N >> M >> L , N || M || L ){
		for(int i=0 ; i < 101 ; i++ ) G[i].clear();
		
		for(int i=0 ; i < M ; i++ ){
			int A, B, C, D;
			cin >> A >> B >> C >> D;
			A--; B--;
			add_edge(A, B, C, D);
		}
		cout << dijkstra() << endl;
	}
}

Measured memory_bytes: 1736
n,a = map(int,input().split())
l = list(map(int,input().split()))

dp = [[[0]*(2501) for i in range(n+1)] for j in range(n+1)]
dp[0][0][0] = 1



for i in range(n):    
    for j in range(i+1):
        for k in range(2501):

            dp[i+1][j][k] += dp[i][j][k]
            if k+l[i] < 2501:
                dp[i+1][j+1][k+l[i]] += dp[i][j][k]


ans = 0
for j in range(1,n+1):
    ans += dp[-1][j][j*a]
print(ans)


Measured memory_bytes: 92380
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>
#include <bitset>
#include <cstdint>

using namespace std;
using lli = long long int;
using i64 = int64_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (lli i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (lli i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

i64 a[5];
int main() {
  read_n(a, 5);
  i64 ans = 0, d = 0;
  for (i64 x : a) {
    ans += (x + 9) / 10 * 10;
    d = max(d, (10 - x % 10) % 10);
  }
  cout << ans - d << '\n';
  return 0;
}


Measured memory_bytes: 384
<?php

$array=array_fill(0,pow(10,6),1);
$array[0]=$array[1]=0;

for($i=2;$i<=pow(10,6)/2;$i++){
    if(!$array[$i]) continue;
    for($j=$i*2;$j<=pow(10,6);$j+=$i){
            $array[$j]=0;
    }
}

while(1){
    fscanf(STDIN,"%d %d %d\n",$a,$d,$n);
    if($a==0 && $d==0 && $n==0)
        break;
    $sum=0;
    for($i=$a;$i<=pow(10,6);$i+=$d){
        $sum+=$array[$i];
        if($sum==$n){
            echo $i."\n";
            break;
        }
    }
}


?>

Measured memory_bytes: 143804
#include <bits/stdc++.h>
using namespace std;
bitset<4000005> dp;
int a[2005], n, s;
int main() {
	scanf("%d", &n);
	for(int i = 1; i <= n; i++) scanf("%d", a + i), s += a[i];
	dp[0] = 1;
	for(int i = 1; i <= n; i++) dp |= dp << a[i];
	for(int i = (s + 1) / 2; i <= s; i++) {
		if(dp[i]) return printf("%d\n", i), 0;
	}
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
int A[501],V[501];
struct node{
	int v,p;
	bool operator<(node a)const{
		return v>a.v;
	}
}nw;
priority_queue<node>Q;
int main(){
	int i,j,a,b,p,w=0,v,r,t,m=0,q;
	cin>>a>>b;
	for(i=1;i<=a;i++)cin>>A[i],w+=A[i];
	p=sqrt(w);
	for(i=1;i<=p;i++)if(w%i==0){
		t=v=0;
		while(!Q.empty())Q.pop();
		for(j=1;j<=a;j++)r=A[j]/i,Q.push({A[j]-r*i,j}),V[j]=(r+1)*i-A[j],v+=V[j];
		for(j=1;j<=a;j++){
			nw=Q.top(),Q.pop();
			t+=nw.v,v-=V[nw.p];
			if(t==v)break;
		}
		if(t<=b)m=max(m,i);
		t=v=0,q=w/i;
		while(!Q.empty())Q.pop();
		for(j=1;j<=a;j++)r=A[j]/q,Q.push({A[j]-r*q,j}),V[j]=(r+1)*q-A[j],v+=V[j];
		for(j=1;j<=a;j++){
			nw=Q.top(),Q.pop();
			t+=nw.v,v-=V[nw.p];
			if(t==v)break;
		}
		if(t<=b)m=max(m,q);
	}
	cout<<m;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
typedef long long TYPE;
const TYPE mod=1E9+7;
const int MAXN=5E5+10;
const int INF=~0U>>1;
int input() {
	int x;scanf("%d",&x);
	return x;
}
int arr[100],tong[10],a[MAXN];
int main() {
	TYPE K,A,B;
	K=input();
	A=input();
	B=input();
	if(B-A>2) {
		if(A-1 >=K) {
			printf("%lld\n",K+1);
		}else {
			K-=(A-1);
			TYPE ans=0;
			ans=A+(K/2)*(B-A);
			K-=TYPE(K/2)*2;
			printf("%lld\n",ans+K);
		}
	}else {
		printf("%lld\n",K+1);
	}
	return 0;
}


Measured memory_bytes: 256
// SeeAlso: https://atcoder.jp/contests/abc126/tasks/abc126_b

#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <limits>

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

using namespace std;

int main() {
    int S; 
    cin >> S;
  
    int a = S / 100;
    int b = S % 100;

    if(1 <= a && a <= 12){
        if(1 <= b && b <= 12) {
            cout << "AMBIGUOUS" <<endl;
        } else {
            cout << "MMYY" << endl;
        }
    } else {
        if(1 <= b && b <= 12) {
            cout<< "YYMM" <<endl;
        } else {
            cout<< "NA" <<endl;
        }
    }
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <iomanip>
using namespace std;
long long n,a,b,c,d,i,j,now;
int main()
{
	cin>>n>>a>>b>>c>>d;
	d-=c;
	n-=1;
	for (i=0;i<=n;i++)
	{
		j=n-i;
		now=b-a-i*c+j*c;
		if (now>=-d*j&&now<=d*i)
		{
			cout<<"YES";
			return 0;
		}
	} 
	cout<<"NO";
	return 0;
}

Measured memory_bytes: 256
n, x = map(int, input().split())
a = list(map(int, input().split()))
num = len(a)


ans = 0

for i in range(num - 1):
    tar = a[i] + a[i + 1]
    if (tar <= x):
        continue
    else:
        dif = tar - x
        if (a[i + 1] >= dif):
            ans += dif
            a[i + 1] -= dif

        else:
            ans += a[i + 1]
            dif -= a[i + 1]
            a[i + 1] = 0

            a[i] -= dif
            ans += dif


print(ans)


Measured memory_bytes: 14068
import java.util.*;
class Main {

	public static int getCvalue(int n, int m) {
			if(n < 2) {
				return 0;
			}
			else {
				int k = n - m;
				int a = 1;
				while(n > k) {
					a *= (n--);
					//System.out.println("a " + a);
				}
				return a/2;
			}
	}
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();

		int res = 0;
		res += getCvalue(n, 2);
		//System.out.println(res);
		res += getCvalue(m, 2);

		System.out.println(res);
	}
}

Measured memory_bytes: 21844
N, X = map(int, input().split())
ans = 0
while N >= 0:
    if N == 0:
        ans += 1
        break
    s = 2 ** (N + 2) - 3
    # V = 2 ** (N + 1) - 1
    if X == 1:
        # ans += 1
        break
    elif X < (s + 1) // 2:
        X -= 1
    elif X == (s + 1) // 2:
        ans += 2 ** N
        break
    elif X > (s + 1) // 2:
        ans += 2 ** N
        X -= (s + 1) // 2
    elif X == s:
        ans += 2 ** (N + 1) - 1
        break
    N -= 1
print(ans)


Measured memory_bytes: 3060
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    n,m=map(int,readline().split())
    a=[0]*m
    b=[0]*m
    c=[0]*m
    for i in range(m):
        a[i],b[i]=map(int,readline().split())
        li=list(map(int,readline().split()))
        for j in range(len(li)):
            c[i]|=1<<(li[j]-1)

    inf=10**9
    dp=[[inf]*(1<<n) for _ in range(m+1)]
    dp[0][0]=0
    for i in range(1,m+1):
        for j in range(1<<n):
            #i番目の鍵を使わない
            dp[i][j]=min(dp[i-1][j],dp[i][j])

            #i番目の鍵を使う
            dp[i][j|c[i-1]]=min(dp[i][j|c[i-1]],dp[i-1][j]+a[i-1])

    ans=dp[m][(1<<n)-1]
    print(ans if ans<inf else -1)

if __name__=="__main__":
    main()

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

int main(){
  int n;
  cin >> n;
  double ans = 0;
  if(n%2) ans = (n+1)/2;
  else ans = (double)n/2;
  ans /= n;
  printf("%.10f", ans);
  return 0;
}

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

using namespace std;
using ll = long long;

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	int n;
	cin >> n;
	vector<int> a(n);
	for (auto &el : a) {
		cin >> el;
	}
	vector<int> ans(n, 0);
	for (int b = 0; b < 31; b++) {
		int cnt = 0;
		for (int i = 0; i < n; i++) {
			cnt += (a[i] >> b) & 1;
		}
		for (int i = 0; i < n; i++) {
			ans[i] += ((cnt % 2 ^ ((a[i] >> b) & 1)) << b);
		}
	}
	for (auto &el : ans) {
		cout << el << ' ';
	}
}

Measured memory_bytes: 4704
f=1
a=0
b=0
c=0

for i in range(int(input())):
  s=input()
  if s[0]=="B":
    b+=1
  if s[-1]=="A":
    a+=1
  if (not(s[0]=="B" and s[-1]=="A"))and(s[0]=="B" or s[-1]=="A"):
    f=0
  for j in range(len(s)-1):
    if s[j:j+2]=="AB":
      c+=1
if min(a,b)==0:
  f=0
print(min(a,b)+c-f)


Measured memory_bytes: 75852
N,K = list(map(int, input().split()))
h = list(map(int, input().split()))

dp = {}
dp[0] = 0
dp[1] = abs(h[0] - h[1])

for i in range(2, N):
    tm = []
    for j in range(1, min(K+1, i+1)):
        tm.append(dp[i-j] + abs(h[i-j] - h[i]))
    dp[i] = min(tm)

print(dp[N-1])

Measured memory_bytes: 62688
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, A, ans;
  string op;
  cin >> N >> A;
 
  if (N < 500 && A < N) {
    cout << "No" << endl;
  }
  else if (N < 500 && A > N) {
    cout << "Yes" << endl;
  }
  else if (N >= 500) {
    if (N % 500 == 0) {
      cout << "Yes" << endl;
    }
    else if (N % 500 <= A) {
      cout << "Yes" << endl;
    } 
    else {
      cout << "No" << endl;
    }
  }
}

Measured memory_bytes: 256