akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define int ll

ll gcd(ll m, ll n) {//最大公約数
    if (n == 0)return m;
    return gcd(n, m % n);
}//gcd

ll lcm(ll m, ll n) {//最小公倍数
    return m / gcd(m, n) * n;
}

main(){
  int n,m;
  cin>>n>>m;
  string s,t;
  cin>>s>>t;
  int l = lcm(n,m);
  map<int,char> mp_n,mp_m;
  for(int i = 0; i <= n - 1; i++){
    mp_n[l/n*i]=s[i];
  }
  for(int i = 0; i <= m - 1; i++){ 
    mp_m[l/m*i]=t[i];
  }
  bool ok=1;
  for(auto x : mp_n){
    if(x.second != mp_m[x.first] && ('a'<=mp_m[x.first] && mp_m[x.first]<='z') ) ok=0;
  }
  if(ok) cout<<l<<endl;
  else cout<<-1<<endl;
}



Measured memory_bytes: 18920
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::iter::FromIterator;
// input macro
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
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!{
        n: usize,
        k: i64,
        ab: [(usize, i64); n],
    }
    let mut v = vec![0; 100010];
    for (a, b) in ab {
        v[a] += b;
    }
    let mut cnt = 0;
    for i in (0..100010) {
        cnt += v[i];
        if cnt >= k {
            println!("{}", i);
            break;
        }
    }
}


Measured memory_bytes: 6396
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <iomanip>
#include <queue>
#include <numeric>


using namespace std;


int main() {
	long long int N, ans;

	cin >> N;

	for (int i = 1; i <= N; i++) {
		if (i == 1) {
			ans = 1;
		}
		else if (i != N) {
			ans += i;
		}
	}

	if (N == 1) {
		ans = 0;
	}

	cout << ans;

	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
int n, m, q;
int a[55], b[55], c[55], d[55];
int ans;
void dfs(vector<int> &v){
	if(v.size()==n){
		int s=0;
		for(int i=0; i<q; i++){
			if(v[b[i]]-v[a[i]]==c[i]) s+=d[i];
		}
		ans=max(ans, s);
		return;
	}
	int t=1;
	if(!v.empty()) t=v.back();
	for(int i=t; i<=m; i++){
		v.push_back(i);
		dfs(v);
		v.pop_back();
	}
}
int main()
{
	cin>>n>>m>>q;
	for(int i=0; i<q; i++){
		cin>>a[i]>>b[i]>>c[i]>>d[i];
		a[i]--; b[i]--;
	}
	vector<int> v;
	dfs(v);
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3628
#include<iostream>
#include<cstring>
using namespace std;
int main(){
    int a[3][3];
    for(int i=0;i<3;i++){
    	for(int j=0;j<3;j++){
    		cin>>a[i][j];
		}
	}
	int b,d[5][5];cin>>b;
	memset(d,0,sizeof(d));
	while(b--){
		int c;cin>>c;
		for(int i=0;i<3;i++){
    	for(int j=0;j<3;j++){
    		if(c==a[i][j]) d[i][j]=1;
		}
	}
	}
	int e=0,f=0;
	for(int i=0;i<3;i++){
		e+=d[i][i];f+=d[i][2-i];
		for(int j=0;j<3;j++){
			d[i][3]+=d[i][j];d[3][j]+=d[i][j];
		}
	}
	if(e==3||f==3) cout<<"Yes";
	else{
		for(int i=0;i<3;i++) {
			if(d[i][3]==3||d[3][i]==3) {
			cout<<"Yes";
			return 0;
			}
		}
		cout<<"No";
	}
}

Measured memory_bytes: 256
H,W = map(int,input().split())
grid = [input() for x in range(H)]

num_black = 0
for i in range(H):
    num_black += grid[i].count("#")

dx = [0,0,1,-1,1,1,-1,-1]
dy = [1,-1,0,0,1,-1,1,-1]
dist = [[-1 for x in range(W)] for x in range(H)]

q = []
dist[0][0] = 0
q.append((0,0))

while len(q) != 0:
    current = q[0]
    del q[0]
    x = current[0]
    y = current[1]
    for i in range(4):
        nx = x + dx[i]
        ny = y + dy[i]

        if nx < 0 or ny < 0:
            continue
        if nx >= H or ny >= W:
            continue
        if dist[nx][ny] != -1:
            continue
        if grid[nx][ny] == "#":
            continue
        dist[nx][ny] = dist[x][y] + 1
        q.append((nx,ny))

if dist[H-1][W-1] == -1:
    print(-1)
else:
    print(H * W - dist[H-1][W-1] - num_black - 1)


Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int main()
{	
	int a[5],k,i,j;
	int m = 0;
	for (i = 0; i < 5; ++i) {
		cin >> a[i];
	}
	cin >> k;
	for (i = 0; i < 5; ++i) {
		for (j = i + 1; j < 5; ++j) {
			if (a[j] - a[i] > k) { 
				m = 1;
				break;
			}
		}
		if (m == 1)break;
	}
	if (m == 1)cout << ":(" << "\n";
	else cout << "Yay!" << "\n";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <string.h>
#include <ctype.h>
#include <algorithm>

using namespace std;

int main() {
  long n,d,x[210000],y[210000];
  cin >> n >> d;

  for(int i = 0; i < n; i++)
    cin >> x[i] >> y[i];

  int sum = 0;
  
  for(int i = 0; i < n; i++) {
    if((x[i]*x[i] + y[i]*y[i]) <= d*d) sum++;
  }

  cout << sum << endl;
}

Measured memory_bytes: 6732
#include <stdio.h>

void FuncShowArray(int array[], int head, int num)
{
  int i;
  for (i = head; i <= num; i++){
	  if (i > head) putchar(' ');
      printf("%d", array[i]);
  }
  putchar('\n');
}


int main(void)
{
	int a[1024];
	int n;
	int key;
	int i, j;

	scanf("%d", &n);
	for (i = 1; i <= n; i++)
		scanf("%d", &a[i]);
	FuncShowArray(a, 1, n);
	for (i = 2; i <= n; i++) {
		key = a[i];

		/* insert a[i] into the sorted sequence a[1,...,i-1] */
		for (j = i - 1; j > 0 && a[j] > key; j--)
			a[j+1] = a[j];
		a[j+1] = key;

		FuncShowArray(a, 1, n);
	}

	return 0;
}

Measured memory_bytes: 608
#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>;
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 = 2e9;

ll dist[505][505];

void warchall_floyd(int N){
    rep(k,N)rep(i,N){
        if(dist[i][k] == INF) continue;
        rep(j,N){
            if(dist[k][j] == INF) continue;
	        chmin(dist[i][j], dist[i][k]+dist[k][j]);
        }
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h, w;
    cin >> h >> w;
    rep(i,10)rep(j,10) cin >> dist[i][j];
    warchall_floyd(10);
    ll ans = 0;
    rep(i,h)rep(j,w){
        int a;
        cin >> a;
        if(a == -1) continue;
        ans += dist[a][1];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python
from collections import Counter


def main():
    K, A, B = [int(a) for a in input().split()]
    if B <= A + 2:
        print(K + 1)
        return
    # A-1回叩いて(残り回数//2)*(B-A)稼いで、残り回数が奇数なら+1
    if A - 1 >= K:
        print(K + 1)
        return
    k2 = K - A + 1
    k3 = (k2 // 2) * (B - A)
    k4 = k2 % 2
    res = k3 + k4 + A
    print(res)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
#include<stdio.h>
#include<algorithm>
using namespace std;
int now[30];
int to[30];
int main(){
	int a,b;
	int T=0;
	while(scanf("%d%d",&a,&b),a){
		for(int i=0;i<30;i++)now[i]=0;
		now[0]=a;
		int t=0;
		while(1){
			t++;
			for(int i=0;i<a;i++){
				to[i]=0;
			}
			for(int i=0;i<a;i++){
				to[i+1]+=now[i]/2;
				to[i]+=now[i]%2;
				to[0]+=now[i]/2;
			}
			for(int i=0;i<a;i++)now[i]=to[i];
			if(to[b])break;
		}
		printf("Case %d: %d\n",++T,t);
	}
}

Measured memory_bytes: 1028
/**
 *    AUTHOR:    __SIGSEGV__                  
 *   CREATED:   12.08.2020 20:59:06  
**/

#include <bits/stdc++.h>

using namespace std;

int main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int x;
  cin >> x;
  if (x >= 30) {
    cout << "Yes\n";
  } else { 
    cout << "No\n";
  }
  return 0;
}

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

int pop();
void push( int data );

int top;
int place[100];


int main(){
  top = 0;
  int nai,yo;
  int x;
  char s[100];

  while( scanf("%s", s) != EOF ){
    if ( s[0] == '+' ){
      
      push(pop() + pop());
      

    } else if ( s[0] == '-' ){
      
      nai = pop();
      yo  = pop();

      push(yo - nai);

    } else if ( s[0] == '*' ){

      push(pop() * pop());
      

    } else {
      x = atoi(s);
      push(x);

    }
  }
  printf("%d\n",pop());

  return 0;
}

int pop()
{
  top--;
  return place[top+1];
}

void push(int data)
{
  top++;
  place[top] = data;
}




  



Measured memory_bytes: 2100
#include "bits/stdc++.h"
#define FI first.first
#define SE first.second
#define TH second
#define fi first
#define se second
#define th second

using namespace std;

template<typename T>
string to_string(const vector<T>& vc, int w) {
	if(vc.empty()) return "";
	if(w + 1 == vc.size()) return to_string(vc[w]);
	return to_string(vc[w]) + "," + to_string(vc, w + 1);
}

template<typename T>
string to_string(const vector<T>& vc) {
	return "{" + to_string(vc, 0) + "}";
}

void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
 
#ifdef DEBUG
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

class DebugStream {}LOG;
template <typename T>DebugStream &operator<<(DebugStream &s, const T&) { return s; }
#ifdef DEBUG
#define LOG clog
#endif

typedef long long ll;
typedef pair<ll, ll> ii;
typedef long double ld;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

const int maxN = 1e5 + 9, maxV = 1e6 + 9, MOD = 1e9 + 7, SQ = 335, lg = 20, bs = 29;

int bc[maxV], cn[maxV];

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	#ifdef DEBUG
	freopen("input.txt", "r", stdin);
	#endif

	int n;
	cin >> n;
	vector<int> arr(n);
	set<int> mys;
	for(auto& el: arr) {
		cin >> el;
		bc[el]++;
		mys.insert(el);
	}

	for(auto el: mys) {
		for(int j = el * 2; j < maxV; j += el)
			if(bc[j]) cn[j] = 1;
	}

	int ans = 0;
	for(auto el: arr) {
		debug(el, cn[el]);
		if(bc[el] == 1 && !cn[el]) ans++;
	}
	cout << ans << '\n';
}



Measured memory_bytes: 20312
#include <iostream>
#include <vector>
#include <algorithm>

int main() {
    int N;
    std::cin >> N;

    std::vector<int> A(N);
    for (int& a : A) {
        std::cin >> a;
    }

    std::sort(A.rbegin(), A.rend());
    int Alice = 0;
    int Bob = 0;
    for (int i = 0; i < N; i ++) {
        if (i % 2 == 0) {
            Alice += A[i];
        } else {
            Bob += A[i];
        }
    }
    std::cout << Alice - Bob << std::endl;
}


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

const int MAX = 100000;

int main ()
{
    vector<int> num(MAX + 1, 1);
    num[0] = num[1] = -1;
    for (int i = 2; i <= MAX / 2; i++) {
        for (int j = 2; i * j <= MAX; j++) {
            num[i*j] = -1;
        }
    }

    vector<int> prim;
    for (int i = 0; i < num.size(); i++) {
        if (num[i] == 1) {
            prim.push_back(i);
        }
        num[i] = prim.size() - 1;
    }

    int n;
    while (cin >> n) {
        if (prim[num[n]] == n)
            cout << prim[num[n]-1] << " " << prim[num[n]+1] << endl;
        else
            cout << prim[num[n]] << " " << prim[num[n]+1] << endl;
    }

    return 0;
}

Measured memory_bytes: 1528
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N ;

  vector<int> card(200);
  int scoreA=0;
  int scoreB=0;

  for (int i=0;i<N;i++){
    cin >> card.at(i);
  }

  sort(card.begin(),card.end());
  reverse(card.begin(),card.end());

  for(int i=0;i<N;i++){
    if((i%2)==0){
      scoreA += card.at(i);
    }else{
      scoreB += card.at(i);
    }
  }

  cout << scoreA-scoreB << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
int main(){
	int n,a[200];
	cin>>n;
	for (int i = 0; i < 2*n; i++){
		cin>>a[i];
	}
	sort(a,a+2*n);

	int sum=0;
	for (int i = 0; i < 2*n; i+=2){
		sum+=min(a[i],a[i+1]);
	}

	cout<<sum<<endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stdio.h>
#include <cstring>
#include <queue>
#include <stack>
#include <functional>
#include <math.h>
#include <iomanip>
using namespace std;
#define Would
#define you
const int INF = 999999999;
const int MOD = 1e9 + 7;

int a, b, k[1005], cap[1005], c, d, e, ans;
int main() {
	cin >> a;
	for (int i = 1; i <= a; ++i) { cin >> cap[i]; }
	cin >> b;
	for (int i = 0; i < b; ++i) {
		cin >> c >> d >> e;
		if (ans != 0) { break; }
		if (c == 1) {
			if (k[d] + e > cap[d]) { ans = d; }
			k[d] += e;
		}
		else {
			if (k[d] < e) { ans = d; }
			k[d] -= e;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 3132
#include <iostream>
#include <string>
using namespace std;
#define REP(i,n)    for(int i = 0; i < (int)n; i++)
#define MAX_N   100000
typedef long long ll;

void solve(){
    int a, b;
    cin >> a >> b;
    if(a > 9 || b > 9)
        cout << -1 << '\n';
    else
        cout << a * b << endl;
}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define vi vector<int>
#define vl vector<long long int>
#define vpdd vector<pair<double, double> >
#define vpii vector<pair<int, int> >
#define pii pair<int, int>
#define spll set<pair<ll, ll> >
#define sll set<long long int>
#define X first
#define Y second
#define pb push_back
#define mp make_pair
#define clstr cin.ignore(numeric_limits<streamsize>::max(), '\n')
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define rep(i, a, b) for(int i = a; i <= b; i++)
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define to(n) cout << fixed << setprecision(n);
#define tr(container, it) for(decltype(container.begin())it = container.begin(); it != container.end(); ++it)
#define mod 1e9+7
const double pi = 3.14159265359;
const int INF = 0x3f3f3f3f;
//const int MAX = 3001;
//bool memo[MAX];
using namespace std;
//void seive(){memo[1] = false;for(int i = 2; i*i <= MAX; i++){if(memo[i]){for(int j = i*i; j <= MAX; j += i)memo[j] = false;}}}
//ll int gcd(ll int a, ll int b){if(b == 0)return a;return gcd(b, a%b);}
int main(){
	long int n, m, a, b;
	scanf("%ld %ld", &n, &m);
	vector<pair<long int, long int>> memo;
	for(int i = 1; i <= n; i++){
		scanf("%ld %ld", &a, &b);
		memo.push_back(make_pair(a, b));
	}
  sort(memo.begin(), memo.end());
	ll int sum = m, ans = 0;
	tr(memo, it){
		if(sum <= it->Y){
			ans += sum * it->X;
			break;
		}
		ans += it->X * it->Y;
		sum -= it->Y;
	}
	cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 2420
const fi='c2.inp';
        fo='c2.out';
var d:array[1..100000] of boolean;
        a:array[1..100000] of longint;
        h,n,i,kq:longint;
begin

        readln(n);
        for i:=1 to n do read(a[i]);
        for i:=1 to n do d[a[i] div 400+1]:=true;
        kq:=0;h:=0;
        for i:=1 to 8 do
                if d[i] then inc(h);
        for i:=1 to n do
                if a[i] >=3200 then inc(kq);
        if h=0 then write(1) else write(h);
        writeln(' ',h+kq);

end.



Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
#define ll long long
#define INF LLONG_MAX/3
#define eps LDBL_EPSILON
#define moder 1000000007
#define pie 3.141592653589793238462643383279
#define P std::pair<int,int>
#define prique priority_queue
using namespace std;
string s;
signed main(){
	cin>>s;
	rep(i,s.size()){
		rep(j,s.size()-i){
			if(s.substr(0,i)+s.substr(i+j,s.size()-i-j)=="keyence"){
				puts("YES");
				return 0;
			}
		}
	}
	puts("NO");
	return 0;
}

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

typedef long long LL;

vector<LL> maketbl(const vector<int> &mp, const vector<int> &dmg, int mh){
	vector<LL> ret(mh + 1, 1LL << 50);
	ret[0] = 0;
	for(int i = 1; i <= mh; ++i){
		for(size_t j = 0; j < mp.size(); ++j){
			ret[i] = min(ret[i], ret[max(i - dmg[j], 0)] + mp[j]);
		}
	}
	return ret;
}

int main(){
	int n;
	while(scanf("%d", &n), n){
		vector<int> hp(n);
		int mh = 0;
		for(int i = 0; i < n; ++i){
			scanf("%d", &hp[i]);
			mh = max(mh, hp[i]);
		}
		vector<int> mps, dmgs, mpa, dmga;
		int m;
		scanf("%d", &m);
		for(int i = 0; i < m; ++i){
			int d, p;
			char c;
			scanf("%*s%d %c%*s%d", &p, &c, &d);
			if(d){
				if(c == 'S'){
					mps.push_back(p);
					dmgs.push_back(d);
				}
				else{
					mpa.push_back(p);
					dmga.push_back(d);
				}
			}
		}
		vector<LL> tbls = maketbl(mps, dmgs, mh);
		vector<LL> tbla = maketbl(mpa, dmga, mh);
		LL ans = 1LL << 50;
		for(int i = 0; i <= mh; ++i){
			LL s = tbla[i];
			for(int j = 0; j < n; ++j){
				s += tbls[max(hp[j] - i, 0)];
			}
			ans = min(ans, s);
		}
		printf("%lld\n", ans);
	}
}

Measured memory_bytes: 2492
#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>;

int main() {
  int k;
  string s;
  cin >> k >> s;
  if (s.size() <= k) cout << s << endl;
  else {
    rep(i,k) {
      cout << s.at(i);
    }
    cout << "..." << endl;
  }
}

Measured memory_bytes: 3628
using System;
using System.Collections.Generic;
using System.Linq;
using static Atcoder;
using System.Threading.Tasks;
using System.ComponentModel;

public class Hello
{

    public static void Main()
    {
        string s = Console.ReadLine();
        Console.WriteLine((s.Count(c => c == '+') - (s.Count(c => c == '-'))));
    }
}


public class Atcoder
{
    static void Swap<T>(ref T a, ref T b)
    {
        var t = a;
        a = b;
        b = t;
    }
    public static int LCM(int a, int b)
    {
        int c = a * b;
        if (a < b) Swap(ref a, ref b);
        int d = a % b;
        while (d != 0)
        {
            a = b;
            b = d;
            d = a % b;
        }
        return c / b;
    }
    public static string strReverce(string s)
    {
        return new string(s.Reverse().ToArray());
    }
    public static int intRead()
    {
        return int.Parse(Console.ReadLine());
    }
    public static bool IsPrime(int n)
    {
        if (n < 2) return false;
        if (n == 2) return true;
        if (n % 2 == 0) return false;

        //double sqrtNum = Math.Sqrt(n);
        for (int i = 3; i < n; i += 2)
        {
            if (n % i == 0) return false;
        }
        return true;
    }
    public static string[] SpRead(char c)
    {
        return Console.ReadLine().Split(c);
    }
    public static int[] SpIntRead(char c)
    {
        return Console.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();
    }

}


Measured memory_bytes: 11220
import sys

N, M = (int(i) for i in raw_input().split())
ans = 1                                                                                                                                                                                                                                                                     

if __name__ == '__main__':
    if N == (M + 1) or N == (M - 1):
        for n in range(1, N+1):
            ans *= n
            ans %= 1e9 + 7
        for m in range(1, M+1):
            ans *= m
            ans %= 1e9 + 7
    elif N == M:
        for n in range(1, N+1):
            ans *= n
            ans %= 1e9 + 7
        for m in range(1, M+1):
            ans *= m
            ans %= 1e9 + 7
        ans *= 2
        ans %= 1e9 + 7
    else:
        ans = 0

    print int(ans)

Measured memory_bytes: 5764
#include<stdio.h>
int main()
{
	int n,a[1000],p[1000],q[1000],r[1000],P,Q,R,C,i,f;
	while(scanf("%d",&n),n)
	{
		for(i=0;i<n;++i)scanf("%d%d%d%d",a+i,p+i,q+i,r+i);
		scanf("%d%d%d%d",&P,&Q,&R,&C);
		for(f=i=0;i<n;++i)
			if(p[i]<=P&&q[i]<=Q&&r[i]<=R&&p[i]*4+q[i]*9+r[i]*4<=C)
				f=printf("%d\n",a[i]);
		if(!f)puts("NA");
	}
	return 0;
}

Measured memory_bytes: 1056
import java.util.*;

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

        int val1 = sc.nextInt();

        int count = 0;
        for (int i = 9; i <= val1; i = i + 2) {
            int temp = 0;
            for (int n = 1; n <= i; n++) {
                if ((i % n) == 0) {
                    temp++;
                }
            }
            if (temp == 8) {
                count++;
            }
        }
        System.out.println(count);
    }
}

Measured memory_bytes: 21588
#include<bits/stdc++.h>
// __builtin_ctz : no of trailing zeros
#define int long long
#define ll long long
#define pp pair<int,int>
#define mod 1000000007
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl
#define trace2(x, y) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z) cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define sa(a,n) for(int i =0 ; i<n ; i++) cin>>a[i]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define scan() int n; cin>>n ; int a[n]; for(int i = 0 ; i<n ; i++) cin>>a[i]
#define print(a,n) for(int i = 0 ; i < n ; i++) cout<<a[i]<<' '
using namespace std;
int max(int x, int y)
{
    return x>y ? x : y;
}
int min(int x, int y)
{
    return x<y ? x : y;
}
void _(int&a , int b)
{
    a=(a%mod+b%mod)%mod;
    a=(a+mod)%mod;
}
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll s,w;cin >>s >> w;
    if(w>=s)cout << "unsafe";else cout << "safe";
    }

Measured memory_bytes: 3652
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<sstream>
#include<iomanip>
#include<limits>
#include<deque>
#include<map>
#include<list>
#include<set>
#include <unordered_set>
#include<vector>
#include<cmath>
#include<cstdio>
#include<memory>
#include<bitset>
#include<stack>
#include<functional>
#include<queue>
#include<regex>
#include<time.h>

using namespace std;


#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl

#define Tof(x) (x) ? Yes : No
#define TOF(x) (x) ? YES : NO
#define tof(x) (x) ? yes : no

using ll = long long;

constexpr ll MOD = 1000000007;
constexpr ll INF = 1050000000;


/*vectorの要素を全部確認するやつだよ。普通に拡張for文したほうがいいよ。

for (vector<int>::iterator itr = ans.begin(); itr != ans.end(); ++itr) {
	cout << *itr << " ";
}

*/


/*for文でx,yを上下左右確認するやつだよ。正直使いづらいよ。

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


for (int i = 0; i < 4; i++) {
	int ny = y + dy[i];
	int nx = x + dx[i];
}

*/


/*繰り返し二乗法だよ。modもとってくれるよ。n^kをmodで割った余りでやってくれるよ。

ll POW_MOD(ll n, ll k, ll mod) {
	ll r = 1;

	for (; k > 0; k >>= 1) {
		if (k & 1) {
			r = (r * n) % mod;
		}
		n = (n * n) % mod;
	}
	return r;
}

*/


/*実行開始からの経過時間を表すよ。

while (clock() < 1900000) {  }

*/


/*まだ使えないテクニックのメモだよ。

for (int bit = 0; bit < (1<<n); ++bit)//bit全探索用のfor文だよ

*/


/*2重for文書くのめんどくなった時用だよ。

for (int i = 0; i < h; ++i) {
	for (int j = 0; j < w; ++j) {

	}
}

*/

int main() {
	int n, x; cin >> n >> x;
	int l[100];

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

	int ans = 1;

	int check = 0;

	for (int i = 0; i < n; i++) {
		check += l[i];
		if (check <= x) { ans++; }
		else { break; }
	}

	cout << ans << endl;



	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int a, w[1000], n, i;

	scanf("%d", &n);

	for (i = 0; i < n; i ++)
	{
		scanf("%d", &a);

		w[i] = a;
	}
	for ( i = 0; i < n; i++)
	{
		printf("%d", w[n-i-1]);
		if (i + 1 != n)
		{
			printf(" ");
		}
	}
	printf("\n");
	return 0;
}


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

int main(void)
{
    char s[100002];
    int k;
    cin >> s;
    cin >> k;
    int i;
    for(i = 0; s[i] != '\0'; i++){

        int d;
        d = 123 - (int)s[i];
        if(s[i] == 'a') continue;
        if(d <= k){
            s[i] = 'a';
            k -= d;
        } 
        if(k == 0) break;
    }
    s[i-1] += k % 26;
    cout << s << endl;
    return 0;
}

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

#define fast_io ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define cout_precision cout.setf(ios::fixed); cout.precision(32);
#define clr(a) memset(a,0,sizeof(a))
#define umap unordered_map
#define uset unordered_set
#define fr first
#define sc second
#define pb push_back
#define M int(1e9+7)
#define endl '\n'
#define largest(a,b,c) (a>b?(a>c? a:c):(b>c? b:c))
#define smallest(a,b,c) (a<b?(a<c? a:c):(b<c? b:c))

using ll = int64_t; using vll = vector<ll>; using vvll = vector<vll>;
using pll = pair<ll, ll>; using vpll = vector<pll>; using vvpll = vector<vpll>;
int h, w;

bool valid(int x, int y) {
	return (x >= 1 && x <= h && y >= 1 && y <= w);
}

int main() {
	fast_io; cout_precision;
	cin >> h >> w;
	int sx, sy, dx, dy;	cin >> sx >> sy >> dx >> dy;
	int arr[h + 1][w + 1];
	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) {
			arr[i][j] = 0;
			char ch;	cin >> ch;
			if (ch == '.')	arr[i][j] = 1;
		}
	}
	int d[h + 1][w + 1];	for (int i = 1; i <= h;	i++)	for (int j = 1; j <= w; j++)	d[i][j] = INT_MAX;
	d[sx][sy] = 0;
	deque <pair<int, int>> q;
	q.push_front({sx, sy});
	//bool visited[h + 1][w + 1];	memset(visited , 0 , sizeof(visited));
	while (!q.empty()) {
		pair <int, int> p = q.front();	q.pop_front();
		int x =  p.fr , y = p.sc;

		int xd[] = {0, -1, 0, 1};	int yd[] = { -1, 0 , 1, 0};
		for (int i = 0; i < 4; i++) {
			int x1 = x + xd[i] , y1 = y + yd[i];
			if (	valid(x1, y1) && arr[x1][y1]  && d[x1][y1] > d[x][y]) {
				d[x1][y1] = d[x][y];
				q.push_front({x1, y1});
			}
		}
		for (int i = x - 2; i <= x + 2; i++) {
			for (int j = y - 2; j <= y + 2; j++) {
				if (valid(i, j) && arr[i][j] && d[i][j] > 1 + d[x][y]) {
					d[i][j] =  1 + d[x][y];
					q.push_back({i, j});

				}
			}
		}
	}
	int res  = d[dx][dy];
	if (res == INT_MAX)	res = -1;
	cout << res << endl;



	return 0;
}


Measured memory_bytes: 11508
N=int(input())


x=[list(map(int,input().split())) for i in range(N)]
width=[[x[i][0]-x[i][1],x[i][0]+x[i][1]] for i in range(N)]

width.sort(key=lambda x:x[1])

ans=0
thr=-10**9
for i in range(N):
    if thr<=width[i][0]:
        ans+=1
        thr=width[i][1]

print(ans)

Measured memory_bytes: 42792
#include <cstdio>
using namespace std;
main()
{
	long long a,b,c,n=1,flag=0;
	scanf("%lld%lld%lld",&a,&b,&c);
	if (a==b)
		printf("%d\n",c);
	if (a==c)
		printf("%d\n",b);
	if (b==c)
		printf("%d\n",a);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main()
{
     int a,b,c,d,e;
     scanf("%d %d %d %d %d",&a,&b,&c,&d,&e);
     if(a ==0)
        printf("1\n");
     else if(b==0)
        printf("2\n");
     else if(c==0)
        printf("3\n");
     else if(d==0)
        printf("4\n");
     else
        printf("5\n");

     return 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;

int main(int argc, char *argv[])
{
	int n, a;
	cin >> n >> a;

	if (n % 500 <= a) {
		cout << "Yes\n";
	} else {
		cout << "No\n";
	}

	return 0;
}


Measured memory_bytes: 256
import sys

bingo = [list(map(int,input().split())) for i in range(3)]
n = int(input())
hole = [[0,0,0] for i in range(3)]

for i in range(n):
    a = int(input())
    for j in range(3):
        for k in range(3):
            if(bingo[j][k] == a):
                hole[j][k] = 1


for i in range(3):
    if(hole[i][0] == 1 and hole[i][1] == 1 and hole[i][2] == 1):
        print('Yes')
        sys.exit()

for i in range(3):
    if(hole[0][i] == 1 and hole[1][i] == 1 and hole[2][i] == 1):
        print('Yes')
        sys.exit()


if(hole[0][0] == 1 and hole[1][1] == 1 and hole[2][2] == 1):
    print('Yes')
elif(hole[0][2] == 1 and hole[1][1] == 1 and hole[2][0] == 1):
    print('Yes')
else:
    print('No')


Measured memory_bytes: 9180
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define sz(x) int(x.size())
#define pb push_back
#define eb emplace_back
using ll=long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
const ll MOD=1000000007;



int main() {
    int N,D;
    cin>>N>>D;
    D=2*D+1;
    cout<<(N-1)/D+1<<endl;
}

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

int main() {
  int64_t  n;
  cin >> n;
  int64_t a, b;
  int f = 20;
  double s;
  s = sqrt((double)n);
  for (int i = 1; i < 100001; i++) {
    if (i > s) {
      break;
    }
    else if (i <= s) {
      a = i;
      if (n % a == 0) {
        b = n / a;
        int count = 1;
        while (b / 10) {
          b /= 10;
          count++;
        }
        f = min(f, count);
      }
    }
  }
  cout << f << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
#include<iomanip>
#include<math.h>
#include<vector>
#include<cctype>
#include<string>
#include<set>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
std::string line;
typedef long long ll;

int main(){
   int a[3];
   rep(i,3) cin >> a[i];

   sort(a, a+3,greater<int>());
   int ans = a[0]*10+a[1]+a[2];

   cout << ans << endl;




   return 0;
}

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

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> h(N + 1000);
    rep(i, N) cin >> h[i];
    vector<ll> dp(N + 1000);
    rep(i, N + 100) dp[i] = 1'000'000'000'000;
    dp[0] = 0;
    for (int i = 0; i < N; i++) {
        for (int j = 1; j <= K; j++) {
            dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i]));
        }
    }
    cout << dp[N - 1] << endl;
    return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define MODNum 1000000007
#define REP(type, i, a, b) for( type i = a; i < b; i++ )
typedef long long ll;

using namespace std;

int main (void) {
    ll N, ans;
    scanf("%lld", &N);
    vector<ll> A(N);
    map<ll,ll> mp;
    REP(ll,i,0,N){
        scanf("%lld", &A.at(i));
        mp[A.at(i)]++;
    }
    for ( auto& p : mp ) ans += (p.second - 1) * p.second / 2;
    REP(ll,i,0,N){
        printf("%lld\n", ans - mp[A.at(i)] + 1);
    }
    return 0;
}

Measured memory_bytes: 11008
#include <iostream>
#include <iomanip>
#include <random>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <sstream>
#include <bitset>
#include <cassert>
#include <fstream>
#include <queue>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
	#define DBG(X) cout << #X << "=" << (X) << '\n';
#else
	#define DBG(X)
#endif
 
using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld  = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int INT_INF = (int)(2e9);
const ll  LL_INF  = (ll)(2e18);

const int NIL = -1;
static mt19937 _g(time(nullptr));

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for(auto el: v) cout << el << " "; return os; }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for(auto& elem: ret) cin >> elem; return ret; }

const int MAXN = (int)4e3 + 210;

ll a[MAXN], x, answ = LL_INF;
int n;

ll D[MAXN];
int l = 0, r = 0;

void init() {
	l = r = 0;
}

void push_back(ll x) {
	D[r++] = x;
}

void pop_back() {
	--r;
}

void add(ll x) {
	while(l < r && D[r - 1] > x) {
		pop_back();
	}

	push_back(x);
}

void pop_front() {
	++l;
}

void erase(ll x) {
	if(l < r && D[l] == x) {
		pop_front();
	}
}

ll get_front() {
#ifdef __LOCAL
	assert(l < r);
#endif

	return D[l];
}

void solve() {
	cin >> n >> x;

	for(int i = 0; i < MAXN; ++i) {
		a[i] = LL_INF;
	}

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

	for(int shift = 0; shift < n; ++shift) {
		init();
		ll local = x * shift;

		for(int i = 0; i <= shift; ++i) {
			add(a[i]);
		}

		for(int i = 0; i < n; ++i) {
			local += get_front();
			add(a[i + shift + 1]);
			erase(a[i]);
		}

		answ = min(answ, local);
	}

	cout << answ << '\n';
}

int main() {
	fast_io();
	solve();

	return 0;
}


Measured memory_bytes: 384
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
#define For(i,a,b) for(i=a;i<(ll)b;i++)
#define bFor(i,a,b) for(i=a;i>=(ll)b;i--)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N-1,0)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define endl "\n"
#define pb push_back
#define output(v) do{bool f=0;for(auto outi:v){cout<<(f?" ":"")<<outi;f=1;}cout<<endl;}while(0)
const ll mod=1000000007;
const ll inf=1LL<<60;
const double PI = acos(-1);
const double eps = 1e-9;
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;} 
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;} 

void startupcpp(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(15);
}

double distance(ddatas& x,ddatas& y){
  double a=x.first-y.first,b=x.second-y.second;
  return sqrt(a*a+b*b);
}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

vec modncrlistp,modncrlistm;

ll modncr(ll n,ll r){
  ll i,size=modncrlistp.size();
  if(size<=n){
    modncrlistp.resize(n+1);
    modncrlistm.resize(n+1);
    if(!size){
      modncrlistp[0]=modncrlistm[0]=1;
      size++;
    }
    For(i,size,n+1){
      modncrlistp[i]=modncrlistp[i-1]*i%mod;
      modncrlistm[i]=modinv(modncrlistp[i]);
    }
  }
  return modncrlistp[n]*modncrlistm[r]%mod*modncrlistm[n-r]%mod;
}

ll modpow(ll a,ll n){
  ll res=1;
  while(n){
    if(n&1)res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

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

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}
void judgement(int a){
  if(a){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  if(a){
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;
  }
}

int main(){
  startupcpp();
  ll i,N;
  cin>>N;
  vec v(10);
  rep(i,10)v[i]=111*i;
  cout<<*lower_bound(all(v),N)<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int colo[10],choos,dif;
int N,u;
void smor(int x){
    for(int i=1;i<=8;i++){
        if(x<i*400){
            colo[i]++;
            return ;
        }
    }
    choos++;
}
int main()
{
    scanf("%d",&N);
    for(int i=0;i<N;i++){
        scanf("%d",&u);
        smor(u);
    }
    for(int i=1;i<9;i++){
        if(colo[i])
            dif++;
    }
    if(!dif)
        printf("1 ");
    else
        printf("%d ",dif);
    printf("%d",dif+choos);
    return 0;
}

Measured memory_bytes: 256
import collections
import sys
import numpy as np
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
MOD = 10**9+7
import itertools
import math

s = list(input())
t = input()
for i in range(len(s)):
    ans = ""
    cnt = 0
    for j in range(-1,len(s)-1):
        ans += s[j]
    res = ""
    for j in range(len(s)):
        s[j] = ans[j]
        res += s[j]
    if res == t:
        print("Yes")
        sys.exit()
print("No")

Measured memory_bytes: 12488
#include<iostream>
#include<string>
using namespace std;
int main(){
  string s;
  cin>>s;
  for(int i=0;i<5;++i){
    cout<<s[i];
  }
  cout<<" ";
  for(int i=6;i<13;++i){
    cout<<s[i];
  }
  cout<<" ";
  for(int i=14;i<19;++i){
    cout<<s[i];
  }
  cout<<"\n";
  return 0;
}


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


using namespace std;


#define ll long long
#define mk make_pair
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define sz(x) (int) (x).size()


ll sum(int n);

void go(){
	int n;cin>>n;
	vector<pair<int,int> > coors;
	for(int i=0;i<n;i++){
		int x,y;cin>>x>>y;
		coors.push_back(mk(x,y));
	}
	vector<int> idx;
	for(int i=0;i<n;i++) idx.pb(i);
	double ans=0;
	int cnt=0;
	do{
		cnt++;
		for(int i=0;i<n-1;i++){
			int x1=coors[idx[i]].fi,x2=coors[idx[i+1]].fi,y1=coors[idx[i]].se,y2=coors[idx[i+1]].se;
			ans+=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
		}
	}while(next_permutation(all(idx)));
	ans/=cnt;
	cout << fixed;
	cout << setprecision(10L) << ans;
}
int main(){
   
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);

   go();

   return 0;
}

ll sum(int n){                
   if(n == 0){
      return n;
   }else{
      return sum(n/10) + n%10;
   }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a) for(int i=0;i<a;i++)
#define all(v) v.begin(),v.end()
#define int long long
using namespace std;
signed main(){
    int n;
    cin>>n;
    int a[n];
    rep(i,n){
        cin>>a[i];
    }
    int crush=0;
    int now=1;
    rep(i,n){
        if(a[i]!=now) crush++;
        else now++;
    }
    if(now==1) cout<<-1<<endl;
    else cout<<crush<<endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <iomanip> //! for setprecision(10)
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>

using namespace std;

typedef long long LL;

#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define rep(i,n) for (int i = 0; i < (n); ++i)

const int MOD = 1000000007;

int main()
{
    int N, K;
    cin >> N >> K;

    LL ans = 0;

    if (K % 2 == 0) {
        K /= 2;
        LL b = N / K;
        LL o = b / 2;
        LL e = b - o;
        ans = o * o * o + e * e * e;
    } else {
        LL b = N / K;
        ans = b * b * b;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
import math


def chmax(a, b):
    if a >= b:
        return a
    return b


def chmin(a, b):
    if a <= b:
        return a
    return b


def main():
    nn,kk = list(map(int,input().split()))
    hh = list(map(int, input().split()))

    dp = [math.inf]*nn
    dp[0] = 0
    for i in range(1,nn):
        gg = min(i,kk)
        for j in range(1,gg+1):
            dp[i] = chmin(dp[i],dp[i-j]+abs(hh[i]-hh[i-j]))

    print(dp[nn-1])


main()


Measured memory_bytes: 85516
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	n := scanInt(sc)
	k := scanInt(sc)
	hs := make([]int, n)
	for i := 0; i < n; i++ {
		hs[i] = scanInt(sc)
	}

	costs := make([]int, n)
	costs[0] = 0
	costs[1] = abs(hs[1] - hs[0])

	for i := 2; i < n; i++ {
		minCost := math.MaxInt32
		for c := 1; c <= k && c <= i; c++ {
			cost := costs[i-c] + abs(hs[i]-hs[i-c])
			if cost < minCost {
				minCost = cost
			}
		}
		costs[i] = minCost
	}

	fmt.Println(costs[n-1])
}

func abs(n int) int {
	if n < 0 {
		return -n
	}
	return n
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	v, _ := strconv.Atoi(sc.Text())
	return v
}


Measured memory_bytes: 2816
#include <bits/stdc++.h>
using namespace std;
#define INF 100000005
#define MAX 200005

int main(){
	int n, m, a[101], b[101], t1, t2, v;
	pair<int, int> p[10002];
	while(cin >> n >> m, n){
		v = t1 = t2 = 0;
		for(int i = 0;i < n;i++)cin >> a[i], t1 += a[i];
		for(int i = 0;i < m;i++)cin >> b[i], t2 += b[i];
		int tt = t1-t2;
		for(int i = 0;i < n;i++){
			for(int j = 0;j < m;j++){
				if(2*(a[i]-b[j]) == tt){
					p[v].first = a[i];
					p[v++].second = b[j];
				}
			}
		}
		//cout << v << "*" << endl;
		int mm[3] = {-1, -1, INF};
		for(int i = 0;i < v;i++){
			if(p[i].first + p[i].second < mm[2]){
				mm[0] = p[i].first;
				mm[1] = p[i].second;
				mm[2] = mm[0]+mm[1];
			}
		}
		if(mm[2] == INF)cout << -1 << endl;
		else cout << mm[0] << " " << mm[1] << endl;
	}
	return 0;
}

Measured memory_bytes: 3160
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int main(void){
	int n; cin >> n;
	
	while(n --){
		vector<int> edge(3);
		for(int i = 0; i < 3; i ++) cin >> edge[i];

		sort(edge.begin(), edge.end());
		
		cout << ((pow(edge[0], 2) + pow(edge[1], 2) == pow(edge[2], 2)) ? "YES":"NO") << endl;
	}

	return 0;
}

Measured memory_bytes: 1204
#include <iostream>

using namespace std;

int main()
{
    int n, c=0;

    cin>>n;

    int a[n];
    for(int i=1; i<=n; i++){
        cin>>a[i];
    }
    for(int j=1; j<=n; j++){
        if(j%2 != 0 && a[j]%2 != 0){
            c++;
        }
    }
    cout<<c;
    return 0;
}


Measured memory_bytes: 3580
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	int n;
	cin >> n;
	if (400 <= n && n <= 599) cout << 8 << endl;
	if (600 <= n && n <= 799) cout << 7 << endl;
	if (800 <= n && n <= 999) cout << 6 << endl;
	if (1000 <= n && n <= 1199) cout << 5 << endl;
	if (1200 <= n && n <= 1399) cout << 4 << endl;
	if (1400 <= n && n <= 1599) cout << 3 << endl;
	if (1600 <= n && n <= 1799) cout << 2 << endl;
	if (1800 <= n && n <= 1999) cout << 1 << endl;
	return 0;
}

Measured memory_bytes: 3636
#include <stdio.h>
#include <string.h>
#define mod 1000000007

int main(void){
  char S[100005];
  scanf("%s",S);

  long long dp[strlen(S)+1][3];

  long long c = 1;
  dp[0][0] = 0;
  dp[0][1] = 0;
  dp[0][2] = 0;
  for(int i = 0;i < strlen(S);i++){
    for(int j = 0;j < 3;j++) dp[i+1][j] = dp[i][j];
    if(S[i] == 'A') dp[i+1][0] = (dp[i+1][0]+c)%mod;
    if(S[i] == 'B') dp[i+1][1] = (dp[i+1][1]+dp[i][0])%mod;
    if(S[i] == 'C') dp[i+1][2] = (dp[i+1][2]+dp[i][1])%mod;
    if(S[i] == '?'){
      dp[i+1][0] = (dp[i+1][0]*3+c)%mod;
      dp[i+1][1] = (dp[i+1][1]*3+dp[i][0])%mod;
      dp[i+1][2] = (dp[i+1][2]*3+dp[i][1])%mod;
      c = (c*3)%mod;
    }
  }
   
  printf("%lld\n",dp[strlen(S)][2]);

  return 0;
}

Measured memory_bytes: 2560
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>

using namespace std;

#define mod 1000000007

int main()
{
	string a, b, c;
	cin >> a >> b >> c;
	if(a[a.length() - 1] == b[0] && b[b.length() - 1] == c[0]) cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val s = sc.next()
    val t = sc.next()
    for (i in 0..2) {
        if (s[i] != t[2 - i]) {
            println("NO")
            return
        }
    }
    println("YES")
}

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

int main(){
  int n;
  vector<int> sort;
  cin >> n;

  for(int i=0; i<n; i++){
    int a;
    cin >> a;
    sort.push_back(a);
  }
  for(int i=0; i<n; i++){
    cout << sort[i];
    if (i != n-1){
      cout << " ";
    }
  }
  cout << endl;

  for(int i=1; i<n; i++){
    int v = sort[i];
    int j = i-1;
    while(j>=0 && sort[j] > v){
      sort[j+1] = sort[j];
      j--;
      sort[j+1] = v;
    }
    for(int k=0; k<n; k++){
      cout << sort[k];
      if(k != n-1){
        cout << " ";
      }
    }
    cout << endl;
  }

  return 0;
}



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

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


  int ans1 = 0;
  int ans2 = 0;
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
  for (int i = 0; i < n; i++){
    if (i % 2 == 0){
      ans1 += a.at(i);
    } else {
      ans2 += a.at(i);
    }
  }

  cout << ans1 - ans2<< endl;

}


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

def main():
    H, W, M = map(int, input().split())
    bomb = [list(map(int, input().split()))for i in range(M)]
    H_bomb = [0] * (H + 1)
    W_bomb = [0] * (W + 1)
    for b in bomb:
        H_bomb[b[0]] += 1
        W_bomb[b[1]] += 1
    max_h, max_w = max(H_bomb), max(W_bomb)
    cnt = H_bomb.count(max_h) * W_bomb.count(max_w)
    for b in bomb:
        if H_bomb[b[0]] == max_h and W_bomb[b[1]] == max_w:
            cnt -= 1
    print(max_h + max_w + bool(cnt) - 1)


if __name__ == "__main__":
    main()


Measured memory_bytes: 68336
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int a[]=new int[n];
        for(int i=0;i<n;i++){
            a[i]=sc.nextInt();
        }
        Arrays.sort(a);
        double ans=a[0];
        for(int i=1;i<n;i++){
            ans+=a[i];
            ans/=2;
        }
        
        System.out.println(ans);
    }
}


Measured memory_bytes: 23764
#include <iostream>
#include <vector>

using namespace std;

int main() {
	int n;
	string s, t;
	bool ok = false;

	cin >> n >> s >> t;

	for (int i = 0; i < n; i++) {
		ok = true;
		for (int j = 0; j < n - i; j++) {
			if (s.at(j + i) != t.at(j)) {
				ok = false;
				break;
			}
		}
		if (ok) {
			cout << n + i << endl;
			return 0;
		}
	}

	cout << n + n << endl;
	return 0;
}


Measured memory_bytes: 888
using System;

class Program {

  // 文字の出現回数をカウント
  public static int CountChar(string s, string c) {
    return s.Length - s.Replace(c, "XX").Length;
  }

  static void Main() {

    int n = int.Parse( Console.ReadLine() );
    string s = Console.ReadLine();

    Console.WriteLine(CountChar(s, "ABC")); // 出力：5
  }
}

Measured memory_bytes: 11092