akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
int main(void)
{
    int f=0, x, y[]={10, 50, 100, 500};
    while (scanf("%d", &x)) {
        int c[4], i, k[4], n, res[4]={0};
        if (!x) break;
        if (f) puts("");
        f=1;
        for(n=i=0;i<4;++i) scanf("%d", c+i);
        n=1<<30;
#define REP(x) for(k[x]=0;k[x]<=c[x];++k[x])
        REP(0) REP(1) REP(2) REP(3) {
            int s=0;
            for(i=0;i<4;++i) s+=y[i]*k[i];
            if (s>=x) {
                int m=0;
                int p=s-x;
                int c2[4]={0};
                int ok=1;
                for(i=3;i>=0;--i) {
                    c2[i]=p/y[i];
                    p%=y[i];
                    if (c2[i] && k[i]) ok=0;
                    m+=c[i]-k[i]+c2[i];
                }
                if (n>m && ok) {
                    for(i=0;i<4;++i) res[i]=k[i];
                    n=m;
                }
            }
        }
        for(i=0;i<4;++i) if (res[i]) printf("%d %d\n", y[i], res[i]);
    }
    return 0;
}

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

int main() {
  string s;
  cin >> s;
  for (ll i=0;i<s.size()-1;i++) {
    if(s[i]==s[i+1]) {
      cout << i+1 << " " << i+2 << endl;
      return 0;
    }
  }
  for (ll i=0;i<s.size()-2;i++) {
    if(s[i]==s[i+2]) {
      cout << i+1 << " " << i+3 << endl;
      return 0;
    }
  }
  cout << "-1 -1" << endl;
}

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

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

int main() {
  int const N = 51000;
  vector<int> prime(N,1);
  prime[0] = prime[1] = 0;
  for(int i=0; i*i<N; i++)
    if (prime[i])
      for(int j=i*2; j<N; j+=i)
        prime[j] = 0;
  vector<int> p;
  for (int i=0; i<N; i++)
    if (prime[i])
      p.push_back(i);
  int n;
  while(cin>>n) {
    vector<int>::iterator it = upper_bound(ALL(p),n);
    int f = 1;
    if (*(it-1) == n) f++;
    printf("%d %d\n",*(it-f), *it);
  }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
const int mod =1000000007;
int main(){
	//freopen("input.txt","r",stdin);// <--Remove Before Submit
	char s1[53],s2[53];
	int i,n,p,flage;
	ll sum;
	cin >> n;
	cin >> s1 >> s2;
	if(s1[0]==s1[1])	{
		p=2;
		sum=6;
		flage=2;
	}
	else {
		p=1;
		sum=3;
		flage=1;
	}
	while(p<n)	{
		if(s1[p]!=s1[p+1])	{
			if(flage==1)	{
				sum=(sum*2)%mod;
				p++;
			}
			else {
				flage=1;
				p++;
			}
		}
		else {
			if(flage==1)	{
				flage=2;
				p+=2;
				sum=(sum*2)%mod;
			}
			else {
				sum=(sum*3)%mod;
				p+=2;
			}
		}
	}
	cout << sum << endl;
	return 0;
}

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

class VectorAdd {
private:
    std::vector<std::vector<int>> data;

public:
    void add(int x,int y);
    int getListCount();
    std::vector<int> getResultList();
};

void VectorAdd::add(int x,int y){
    std::vector<int> tmpvec = {x, y};
    data.push_back(tmpvec);
}

int VectorAdd::getListCount(){
    return data.size();
}

std::vector<int> VectorAdd::getResultList(){
    std::vector<int> resultList;
    for(int i = 0;i < data.size();i++){
        resultList.push_back(data[i][0] + data[i][1]);
    }
    return resultList;
}

const int MIN_INPUT_NUMBER = -1000;
const int MAX_INPUT_NUMBER = 1000;

bool imputNumberDecision(int num){
    if(MIN_INPUT_NUMBER <= num && num <= MAX_INPUT_NUMBER){
        return true;
    }
    return false;
}

int main(){
  
    VectorAdd va = VectorAdd();

    std::cin.tie(0);
    std::ios::sync_with_stdio(false);

    int a, b;
    while(std::cin >> a >> b){
        if(imputNumberDecision(a) && imputNumberDecision(b)){
            va.add(a, b);
        }else{
            std::cout << "Out of Range!" << std::endl;
        }
    }

    for(int i : va.getResultList()){
        std::cout << i << std::endl;
    }
    
    return 0;
}

Measured memory_bytes: 3116
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cassert>
#include <vector>

using namespace std;

int N, M;
const int K = 4;

struct Node {
  int n;
  int adj[K];
  int edge[K];

  void Add(int a, int e) {
    if (n < K) {
      adj[n] = a;
      edge[n] = e;
    }
    ++n;
  }

  int Next() const;
};

Node node[100020];
int color[100020];
bool visit[100020];

int D = 0;
int R = 0;

int Node::Next() const {
  for (int i = 0; i < n; ++i) {
    int ii = (i+D)%n;
    if (R > 0) ii = n-ii-1;
    if (color[edge[ii]] < 0) {
      return ii;
    }
  }
  return -1;
}

int Solve() {
  int cnt = 0;
  vector<int> up{0};
  int lv = 1;
  while (!up.empty()) {
    vector<int> st{up.back()};
    up.pop_back();
    while (true) {
      int p = st.back();
      if (visit[p]) {
	do {
	  if (node[st.back()].Next() >= 0) {
	    up.push_back(st.back());
	  }
	  visit[st.back()] = false;
	  st.pop_back();
	} while (st.back() != p);
	++cnt;
      }
      const Node& nd = node[p];
      int k = nd.Next();
      if (k < 0) {
	st.pop_back();
	assert(st.empty());
	break;
      }
      visit[p] = true;
      st.push_back(nd.adj[k]);
      color[nd.edge[k]] = lv;
    }
  }
  return cnt >= 3;
}

bool SolveK() {
  for (int r = 0; r < 2; ++r) {
    R = r;
    for (int i = 0; i < K; ++i) {
      D = i;
      memset(color, -1, sizeof(color));
      memset(visit, 0, sizeof(visit));
      if (Solve()) {
	return true;
      }
    }
  }
  return false;
}

int main() {
  while (cin >> N >> M) {
    memset(node, 0, sizeof(node));
    for (int i = 0; i < M; ++i) {
      int a, b;
      cin >> a >> b;
      --a; --b;
      node[a].Add(b, i);
      node[b].Add(a, i);
    }
    bool odd = false;
    bool quick = false;
    for (int i = 0; i < N; ++i) {
      odd = odd || (node[i].n % 2 == 1);
      quick = quick || node[i].n > K;
    }
    if (!odd && (quick || SolveK())) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }
}


Measured memory_bytes: 5100
n = int(input())
p = list(map(lambda x: int(x), input().split(" ")))
cnt = 0
for i in range(1, n - 1):
  if p[i-1] < p[i] < p[i+1] or p[i-1] > p[i] > p[i+1]:
    cnt += 1
print(cnt)

Measured memory_bytes: 9180
N, M, C = gets.split.map(&:to_i)
B = gets.split.map(&:to_i)
ans = 0

N.times do
  A = gets.split.map(&:to_i)
  sum = 0
  M.times do |i|
    sum += A[i] * B[i]
  end
  ans += 1 if sum + C > 0
end

puts ans


Measured memory_bytes: 1788
using System;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            char[] c = Console.ReadLine().ToCharArray();

            if(N == 1)
            {
                Console.WriteLine("0");
                return;
            }

            int[] white = new int[N];

            if (c[0] == '.')
                white[0] = 1;
            else
                white[0] = 0;

            for(int i=1;i<N;i++)
            {
                if (c[i] == '.')
                    white[i] = white[i - 1] + 1;
                else
                    white[i] = white[i - 1];
            }

            int allw = white[N - 1];
            int ans = allw;

            for(int i=0;i<N;i++)
            {
                int temp = i + 1 + allw - white[i] * 2;
                if (ans > temp)
                    ans = temp;
            }


            Console.WriteLine(ans.ToString());
        }
    }
}


Measured memory_bytes: 13200
#include <bits/stdc++.h>
using std::cout;
using std::endl;
using std::cin;

int main(){
	long k; cin >> k;
	std::vector<long> vec(50, 49);
	
	long A = k / 50, B = k % 50;
	for(int i = 0; i < 50; i++) vec[i] += A;
	
	while(B--){
		vec[0] += 50;
		for(int i = 1; i < 50; i++) vec[i]--;
		sort(begin(vec), end(vec));
	}
	
	cout << 50 << endl;
	for(int i = 0; i < 50; i++) cout << vec[i] << " ";
	cout << endl;
	return 0;
}


Measured memory_bytes: 256
//****** @mdazmat9 **********
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define UB upper_bound
#define LB lower_bound
#define BS binary_search
#define EB emplace_back
#define endl "\n"
#define MOD 1000000007
#define F first
#define S second
#define ALL(a) (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
int fast_pow(int x, int y, int p);
char diff(char a,char b){
    for(char x='a';x<='z';x++){
        if(x!=a && x!=b)return x;
    }
}
void solve() {
    int n;cin>>n;
    int a[n];
    for(int i=0;i<n;i++)cin>>a[i];
    int ans=1;
    int mx=a[0];
    for(int i=1;i<n;i++){
        if(a[i]<=mx){
            ans++;
        }
        mx=min(mx,a[i]);
    }
    cout<<ans<<endl;


}
int32_t main() {
    IOS;
    int test = 1;
    //cin >> test;
    while (test--) {
        solve();
    }
    return 0;
}
int fast_pow(int x, int y, int p) {
    int res = 1;
    x = x % p;
    while (y > 0) {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}

Measured memory_bytes: 1792
#
# File    : B.rb
# Author  : Kazune Takahashi
# Created : 12/9/2018, 10:29:31 PM
# Powered by Visual Studio Code
#

s = gets.chomp

hash = {}

s.chars{|c|
  if hash.has_key?(c)
    hash[c] += 1
  else
    hash[c] = 1
  end
}

hash.each{|key, val|
  if val % 2 != 0
    puts "No"
    exit
  end
}

puts "Yes"

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

#define MAX_DATA_NUM 10000000

int Q[MAX_DATA_NUM];
int head, tail;

void enqueue(int num){
  Q[tail] = num;
  tail++;
  if(tail == MAX_DATA_NUM)tail = 0;
}

int dequeue(){
  int res = Q[head];
  head++;
  if(head == MAX_DATA_NUM - 1)head = 0;
  return res;
}

int main(){
  int n, q;
  cin >> n >> q;
  vector<string> name(n);
  vector<int> name_num(n);
  for(int i = 0; i < n; i++){
    int tmp;
    cin >> name[i] >> tmp;
    name_num[i] = i;
    enqueue(tmp);
  }
  int cnt = 0, num = 0;
  while(1){
    int i;
    for(i = 0; i < n - num; i++){
      int s = dequeue() - q;
      if(s <= 0){
        cnt += s + q;
        cout << name[name_num[i]] << " " << cnt << endl;
        name_num.erase(name_num.begin() + i);
        i--;
        num++;
      }else {
        cnt += q;
        enqueue(s);
      }
    }
    if(num == n)break;
  }
}

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

int n;
std::priority_queue<double,std::vector<double>,std::greater<double>> que;

void input(){
    std::cin>>n;
    for(int i=0;i<n;i++){
        double tmp;
        std::cin>>tmp;
        que.push(tmp);
    }
}


int main(){

    input();

    for(int i=0;i<n-1;i++){
        double smaller = que.top();
        que.pop();
        double bigger = que.top();
        que.pop();
        que.push((smaller+bigger)/2.0);
    }
    std::cout<<std::setprecision(10)<<que.top()<<std::endl;
    return 0;
}

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
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 int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

struct edge{
    ll to;
    ll cost;
};

using Graph = vector<vector<edge>>;

vector<ll> dijkstra(const Graph &G, int s, int v){
    vector<ll> d(v, LINF);

    priority_queue<pll, vector<pll>, greater<pll>> que;
    d[s] = 0;
    que.push(pll(0, s));

    while(!que.empty()){
        pll p = que.top();
        que.pop();
        ll nv = p.second;
        if(d[nv] < p.first) continue;

        for (int i = 0; i < G[nv].size(); ++i) {
            edge e = G[nv][i];
            if(d[e.to] > d[nv] + e.cost){
                d[e.to] = d[nv] + e.cost;
                que.push(pll(d[e.to], e.to));
            }
        }
    }

    return d;
}

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

    int u, v, a, b;
    const int smax = 2500;
    if (s > smax) s = smax - 1;
    Graph G(n * smax);
    for (int i = 0; i < m; ++i) {
        cin >> u >> v >> a >> b;
        u--; v--;
        for (int j = 0; j < smax; ++j) {
            if (j - a < 0) continue;
            G[u * smax + j].push_back(edge{v * smax + (j - a), b});
            G[v * smax + j].push_back(edge{u * smax + (j - a), b});
        }
    }

    int c, d;
    for (int i = 0; i < n; ++i) {
        cin >> c >> d;
        for (int j = 0; j + c < smax; ++j) {
            G[i * smax + j].push_back(edge{i * smax + (j + c), d});
        }
    }

    vector<ll> dis = dijkstra(G, s, n * smax);
    for (int i = 1; i < n; ++i) {
        ll res = LINF;
        for (int j = 0; j < smax; ++j) {
            chmin(res, dis[i * smax + j]);
        }
        cout << res << endl;
    }
}

Measured memory_bytes: 23888
#include <bits/stdc++.h>
using namespace std;
int n,k,a[100010],f[100010]; 
int main()
{
	cin>>n>>k;
	for(int i=0;i<n;i++)
		f[i]=1e9;
	f[0]=0;
	for(int i=0;i<n;i++)
		cin>>a[i];
	for(int i=1;i<n;i++)
		for(int j=1;j<=i && j<=k;j++)
			f[i]=min(f[i],f[i-j]+abs(a[i]-a[i-j]));
	cout<<f[n-1]<<endl;
	return 0;
}


Measured memory_bytes: 1024
N, M = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(M)]

ab.sort()

ans = 0
for i, (ai, bi) in enumerate(ab):
    if i == 0:
        ans += 1
        l = ai
        r = bi
    else:
        l_tmp = max(l, ai)
        r_tmp = min(r, bi)
        if l_tmp < r_tmp:
            l = l_tmp
            r = r_tmp
        else:
            ans += 1
            l = ai
            r = bi

print(ans)

Measured memory_bytes: 27884
#include <bits/stdc++.h>
#include <iomanip>
#include <math.h>
//#include <unistd.h>
//#include <stdio.h>
#define rep(i,x) for(ll i = 0;i<x;i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;
using dou = double;
const ll INF = 1LL << 60;
const ll mod = 1000000007;
typedef pair<ll,ll> P;
using graph = vector<vector<ll>>;
template<class T> inline bool chmax(T& a, T b){if(a < b){a = b; return true;}return false;}
template<class T> inline bool chmin(T& a, T b){if(a > b){a = b; return true;}return false;}
ll gcd(ll a,ll b){
    if(a < b)swap(a,b);
    if(a % b == 0)return b;
    else return gcd(b,a%b);
}
bool isp(ll n){
    bool res = true;
    if(n == 1)return false;
    else{
        for(ll i = 2;i * i <= n;i++){
            if(n % i == 0){
                res = false;
                break;
            }
        }
        return res;
    }
}
const int MAX = 510000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
/*
int main() {
    // 前処理
    COMinit();

    // 計算例
    cout << COM(100000, 50000) << endl;
}*/

//printf("%.10f\n", N);
/*
ll fibo(ll n){
    if(memo[n] != 0)return memo[n];
    if(n <= 1)return n;
    else return memo[n] = fibo(n - 1)+ fibo(n - 2);
}*/
/*  vector<ll> vec = {1,2,5,6,8,9,10};
    cout << binary_search(all(vec),5) << endl; -> true*/
/*
    vector<ll> vec = {1,2,5,6,8,9,10};
    auto n = upper_bound(all(vec),4);
    cout << *n << endl; -> 5*/
/*
    cout << fixed << setprecision(15);
*/

int main(){
    ll X,Y,Z;
    cin >> X >> Y >> Z;
    X-=Z;
    cout << X / (Y + Z) << endl;
}

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

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

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

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

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

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

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

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::HashMap;

fn main() {
    input!(n: usize, csf: [(usize, usize, usize); n - 1]);

    for i in 0..n {
        let mut time = 0;
        for j in i..n - 1 {
            let (c, s, f) = csf[j];
            if time < s {
                time = s;
            } else if time % f == 0 {
                ;
            } else {
                time += f - (time % f);
            }
            time += c;
        }
        println!("{}", time);
    }
}


Measured memory_bytes: 4352
#include <iostream>
#include <sstream>
#include <iomanip>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <algorithm>
#include <climits>
using namespace std;

void solve(int a)
{
	vector<int> answer;
	int b = 1;
	while(b <= a){
		if(b % 7 == 1)
			b += 5;
		else
			b += 2;
		if(a % b == 0){
			unsigned i;
			for(i=0; i<answer.size(); ++i)
				if(b % answer[i] == 0)
					break;
			if(i == answer.size())
				answer.push_back(b);
		}
	}

	cout << a << ':';
	for(unsigned i=0; i<answer.size(); ++i)
		cout << ' ' << answer[i];
	cout << endl;
}

int main()
{
	for(;;){
		int a;
		cin >> a;
		if(a == 1)
			break;

		solve(a);
	}
}

Measured memory_bytes: 904
n, k = map(int, input().split())
modulo = 10 ** 9 + 7
*arr, = map(int, input().split())
inverses = [pow(v, modulo - 2, modulo) for v in arr]
neg_cnt = 0
for v in arr:
    if v < 0:
        neg_cnt += 1

def min_pos(arr):
    pass


if k == n:
    res = 1
    for v in arr:
        res *= v
        res %= modulo
    print(res)
elif neg_cnt == n and k % 2 == 1:
    res = 1
    arr.sort(reverse=True)
    for i in range(k):
        res *= arr[i]
        res %= modulo
    print(res)
else:
    pos = []
    neg = []
    for i, v in enumerate(arr):
        if v < 0:
            neg.append(i)
        else:
            pos.append(i)

    neg.sort(key=lambda v: abs(arr[v]), reverse=True)
    pos.sort(key=lambda v: abs(arr[v]), reverse=True)


    if k % 2:
        res = arr[pos[0]]
        i = 1
    else:
        res = 1
        i = 0
    j = 0
    while i + j < k and (i < len(pos) - 1 or j < len(neg) - 1):
        if j >= len(neg) - 1 or i < len(pos) - 1 and arr[pos[i]] * arr[pos[i + 1]] > arr[neg[j]] * arr[neg[j + 1]]:
            res *= arr[pos[i]]
            res *= arr[pos[i + 1]]
            i += 2
        else:
            res *= arr[neg[j]]
            res *= arr[neg[j + 1]]
            j += 2
        res %= modulo

    while i + j < k:
        res *= arr[pos[i]]
        i += 1
        res %= modulo

    print(res)




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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void solve() {
    ll H, W;
    cin >> H >> W;
    P s, t;
    cin >> s.first >> s.second;
    cin >> t.first >> t.second;
    vector<string> grid(H);
    rep(i, H) cin >> grid[i];
    deque<pair<P, ll>> que;
    que.push_back({{s.first - 1, s.second - 1}, 0});
    vector<vector<ll>> dist(H, vector<ll>(W, -1));
    while (!que.empty()) {
        auto X = que.front();
        que.pop_front();
        P p = X.first;
        ll d = X.second;
        if (dist[p.first][p.second] == -1) {
            dist[p.first][p.second] = d;
        } else {
            continue;
        }
        rep(j, 4) {
            ll x = p.first + dx[j];
            ll y = p.second + dy[j];
            if (x >= 0 && x < H && y >= 0 && y < W && grid[x][y] == '.' && dist[x][y] == -1) {
                que.push_front({{x, y}, d});
            }
        }
        rep2(i, -2, 3) {
            rep2(j, -2, 3) {
                ll x = p.first + i;
                ll y = p.second + j;
                if (x >= 0 && x < H && y >= 0 && y < W && grid[x][y] == '.' && dist[x][y] == -1) {
                    que.push_back({{x, y}, d + 1});
                }
            }
        }
    }
    cout << dist[t.first - 1][t.second - 1] << '\n';
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    return 0;
}


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

if N ==100000:
    ans=90909
elif N > 9999:  
    ans=N-9999 +909
elif N > 999:
    ans=909
elif N > 99:
    ans=N-99 +9
elif N > 9:
    ans= 9
else :
    ans=N
print(ans)    

Measured memory_bytes: 3060
def inpf() a=gets.chomp.split(" ").map(&:to_f)end

def inps() a=gets.chomp.split(" ")end

def copy(a) Marshal.load(Marshal.dump(a)) end

def kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end

def na(n,d=0) Array.new(n,d)end

def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end

def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end

def inp() a=gets.chomp.split(" ").map(&:to_i)end

def r_up(a, b) (a+b-1)/b end

def sum(a) a.inject(:+) end

n,k = inp
x = []
n.times{x << inp}
t = []
h = {}
x.sort_by!{|u|-1*u[1]}
ft = na(n,false)
x.each.with_index do |a, i|
  if(h[a[0]] == nil)
    h[a[0]] = i
    ft[i]    = true
    t.push(a[1])
  end
end
t = t[0...([t.size,k].min)]

ans = t.size ** 2 + sum(t)
ind = 0
g = []
  g = 0
now = ans
while(ind < n)
  break if(t.size == 0)
  if(ft[ind])
    ind += 1
    next
  end
  if(g + t.size < k)
    now += x[ind][1]
    ans = [now,ans].max
    ind += 1
    g += 1
    next
  end
  now -= t.size**2
  now -= t.pop
  g += 1
  now += t.size**2
  now += x[ind][1]
  ans = [now,ans].max
  ind += 1
end
p ans

Measured memory_bytes: 17892
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=200010,INF=2000000000;
ll a[N];
ll dp[N][3];
ll n;
template<class T>
T mx(T a,T b){
	if(a>b) return a;
	return b;
}
int main()
{
	//freopen("in.txt","r",stdin);
	scanf("%lld",&n);
	for(ll i=1;i<=n;++i) scanf("%lld",&a[i]);
	for(ll i=0;i<=n;++i){
		for(ll j=0;j<3;++j){
			dp[i][j]=-(ll)INF*INF;
		}
	}
	if(n&1){
		dp[1][0]=a[1];
		for(ll i=3;i<=n;i+=2) dp[i][0]=dp[i-2][0]+a[i];
		dp[2][1]=a[2];
		for(ll i=4;i<=n;i+=2) dp[i][1]=mx(dp[i-2][1],dp[i-3][0])+a[i];
		dp[3][2]=a[3];
		for(ll i=5;i<=n;i+=2) dp[i][2]=mx(mx(dp[i-2][2],dp[i-3][1]),dp[i-4][0])+a[i];
		printf("%lld",mx(mx(dp[n][2],dp[n-1][1]),dp[n-2][0]));
	}
	else{
		dp[1][0]=a[1];
		for(ll i=3;i<=n;i+=2) dp[i][0]=dp[i-2][0]+a[i];
		dp[2][1]=a[2];
		for(ll i=4;i<=n;i+=2) dp[i][1]=mx(dp[i-2][1],dp[i-3][0])+a[i];
		printf("%lld",mx(dp[n][1],dp[n-1][0]));
	}
}

Measured memory_bytes: 10004
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S, T;
  cin >> S >> T;
 int C = 0;
  
  if(S.size() + 1 == T.size()){
    for (int i = 0; i < S.size(); i++){
    
      if(S.at(i) != T.at(i))C ++;
    
    }
    if(C == 0)cout << "Yes" << endl;
    else cout << "No" << endl;
    
  }else cout << "No" << endl;
  
  
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

int main()
{
int n,m;
cin>>n>>m;
vector<int> X(m,0);
vector<int> Y(m-1,0);
for(int i=0; i<m; i++)
{
    cin>>X[i];
}
sort(X.begin(),X.end());
for(int i=0; i<m-1; i++)
{
    Y[i]=X[i+1]-X[i];
}
sort(Y.begin(),Y.end());
int ans=0;
for(int i=0; i<m-n; i++)
{
    ans+=Y[i];
}
cout<<ans<<endl;
}

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

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(lol i=0;i<lol(n);i++)
#define REPD(i,n) for(lol i=n-1;i>=0;i--)
#define FOR(i,a,b) for(lol i=a;i<=lol(b);i++)
#define FORD(i,a,b) for(lol i=a;i>=lol(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) x.begin(),x.end() //sortなどの引数を省略したい
#define SIZE(x) lol(x.size()) //sizeをsize_tからllに直しておく
//定数
#define PI 3.1415926535897932385 //pi
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//最大値最小値
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main()
{
    lol result{0}, sum{0};
    lol n; cin >> n;
    lol m; cin >> m;
    
    vector<lol> a(n);
    REP(i, n)
    {
        cin >> a[i];
        sum += a[i];
    }
    double k = (double)sum/(4*m); 
    result = n;
    REP(i, n)
    {
        if((double)a[i] < k)
        {
            result--;
            //cout << "* ";
        }
    }
    //cout << endl << sum << endl << k << endl;;
    if(result >= m)
        cout << "Yes" << '\n';
    else
        cout << "No" << '\n';

    //cout << result << endl;
    return 0;
}

Measured memory_bytes: 3580
# 電車　通常切符A円、乗り放題B円
# バス　通常切符C円、乗り放題D円
a = int(input())
b = int(input())
c = int(input())
d = int(input())

total_fare = (min(a, b) + min(c, d))

print(total_fare)

Measured memory_bytes: 8980
import std.stdio,std.string,std.conv;

int prime[1000000];

int main()
{
	prime[0] = prime[1] = 0;
	
	foreach(i;2..1000000)
	{
		prime[i] = 1;
	}
	foreach(i;2..1000000)
	{
		if(prime[i])
		{
			for(int j = i*2; j < 1000000 ;j += i)
			{
				prime[j] = 0;
			}
		}
	}

	int n;
	while((n = readln.chomp.to!int) != 0)
	{
		int count = 0;
		foreach(i;0..(n/2)+1)
		{
			if(prime[i] == 1 && prime[n-i] == 1)
			{
				count++;
			}
		}
		count.writeln;
	}

	return 0;
}

Measured memory_bytes: 4952
process.stdin.resume();
process.stdin.setEncoding('utf8');
// ???????????????????¨??????§
// Let's ?????£??¬????????????
process.stdin.on('data', function (chunk) {
  var line = chunk.split(' ');
  var a = Number(line[0]);
  var b = Number(line[1]);
  
  if (a > b){
  console.log("a > b");
} else if (a < b){
  console.log("a < b");
} else {
  console.log("a == b")
}
});

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

int main(){
  int height,width;
  cin >> height>>width;
  for (int i=0;i<width+2;i++){
    cout<<"#";
  }
  cout<<endl;
  for (int i=0;i<height;i++){
    string value;
    cin >> value;
    cout<<"#"<<value<<"#"<<endl;
  }
  for (int i=0;i<width+2;i++){
    cout<<"#";
  }
  cout<<endl;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.util.InputMismatchException;

public class Main {

	public static void main(String[] args) {
		Task task = new Task();
		task.solve();
	}

	public static class Task {
		static final long MOD = (long) 1e9 + 7;

		public void solve() {
			Scan sc = new Scan();
			int n = (int) sc.scanLong();
			int k = (int) sc.scanLong();
			long[] modCnts = new long[k];
			for (int i = 1; i <= n; ++i) {
				modCnts[i % k]++;
			}
			long res = modCnts[0] * modCnts[0] * modCnts[0];
			if (k % 2 == 0) {
				res += modCnts[k / 2] * modCnts[k / 2] * modCnts[k / 2];
			}
			System.out.println(res);
		}
	}

	public static class Scan {
		private byte[] buf = new byte[1024];
		private int index;
		private InputStream in;
		private int total;

		public Scan() {
			in = System.in;
		}

		public int scan() {
			if (total < 0)
				throw new InputMismatchException();
			if (index >= total) {
				index = 0;
				try {
					total = in.read(buf);
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
				if (total <= 0)
					return -1;
			}
			return buf[index++];
		}

		public long scanLong() {
			long integer = 0;
			int n = scan();
			while (isWhiteSpace(n))
				n = scan();
			int neg = 1;
			if (n == '-') {
				neg = -1;
				n = scan();
			}
			while (!isWhiteSpace(n)) {
				if (n >= '0' && n <= '9') {
					integer *= 10;
					integer += n - '0';
					n = scan();
				} else
					throw new InputMismatchException();
			}
			return neg * integer;
		}

		public double scanDouble() throws IOException {
			double doub = 0;
			int n = scan();
			while (isWhiteSpace(n))
				n = scan();
			int neg = 1;
			if (n == '-') {
				neg = -1;
				n = scan();
			}
			while (!isWhiteSpace(n) && n != '.') {
				if (n >= '0' && n <= '9') {
					doub *= 10;
					doub += n - '0';
					n = scan();
				} else
					throw new InputMismatchException();
			}
			if (n == '.') {
				n = scan();
				double temp = 1;
				while (!isWhiteSpace(n)) {
					if (n >= '0' && n <= '9') {
						temp /= 10;
						doub += (n - '0') * temp;
						n = scan();
					} else
						throw new InputMismatchException();
				}
			}
			return doub * neg;
		}

		public String scanString() {
			StringBuilder sb = new StringBuilder();
			int n = scan();
			while (isWhiteSpace(n))
				n = scan();
			while (!isWhiteSpace(n)) {
				sb.append((char) n);
				n = scan();
			}
			return sb.toString();
		}

		public char scanChar() {
			int n = scan();
			while (isWhiteSpace(n))
				n = scan();
			return (char) n;
		}

		private boolean isWhiteSpace(int n) {
			if (n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1)
				return true;
			return false;
		}
	}
}


Measured memory_bytes: 33848
#include<algorithm>
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
int dy[200];
int ju[200][200];
int link[200];
struct point{
	int x;
	int y;
};
int compare(point a,point b){
	 if(a.x<b.x)
	 return 1;
	 if(a.x==b.x)
	 {
	 	if(a.y<=b.y) return 1;
	 	else return 0;
	 }
	 else return 0;
	 
}
int Judge(point r,point b){
	if(r.x<b.x&&r.y<b.y) return 1;
	else return 0;
}
int dfs(int x,int n){
	int sum = 0;
	int max = 0;	
	for(int i=0;i<n;i++){
		max = 0;
		if(dy[i]==0&&ju[x][i]==1){
			dy[i]=1;
			max = 1+dfs(x+1,n);
			dy[i]=0;
		}
		sum = max>sum? max:sum;
	}
	return sum;
}
bool find(int v,int n){
	int i;
    for(i=0;i<n;i++)
    {
        if(ju[v][i]&&!dy[i])
        {
            dy[i]=true;
            if(link[i]==-1||find(link[i],n))
            {
                link[i]=v;
                return true;
            }
        }
    }
    return false;
}
int main(){
	int n;
	while(scanf("%d",&n)==1){
		
		point r[n];
		point b[n];
		for(int i = 0;i<n;i++){
			cin>>r[i].x;
			cin>>r[i].y;
		}
		for(int i = 0;i<n;i++){
			cin>>b[i].x;
			cin>>b[i].y;
		}
		for(int i = 0 ;i<n;i++){
			for(int j=0;j<n;j++){
				ju[i][j]=0;
			}
		}
		sort(r,r+n,compare);
		sort(b,b+n,compare);
		for(int i = 0 ;i<n;i++){
			for(int j=0;j<n;j++){
				if(Judge(r[i],b[j])){
					ju[i][j] = 1;
				}
			}
		}
//		for(int i = 0 ;i<n;i++){
//			cout<<r[i].x<<" "<<r[i].y<<endl;
//		}
//		int max[n];
//		for(int i= 0 ;i<n;i++) max[i]=0;
//		for(int i = 0 ;i<n;i++){
//			for(int j=0;j<n;j++){
//				cout<<ju[i][j]<<",";
//				max[i]++;
//				}
//				cout<<endl;
//			}
		int sum = 0;
//		for(int i = n-1 ;i>=0;i--){
//			for(int j=n-1;j>=0;j--){
//				if(ju[i][j]==1){
//						for(int k = i-1;k>=0;k--){
//							ju[k][j] = 0;
//						}
//						sum++;
//						break;
//					}
//				}
//			}
	int ans = 0;
	for(int j=0;j<n;j++) link[j]=-1;
    	for(int i=0;i<n;i++)
    	{	for(int j=0;j<n;j++) dy[j]=0;
        	if(find(i,n)) ans++;
    	}
		cout<<ans<<endl;
	}
} 

Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N; cin >> N;
	unordered_map<int, int> cnt;
	vector<int> b;
	vector<int> a(N); rep(i, 0, N) {
		cin >> a[i];
		cnt[a[i]]++;
		if (cnt[a[i]] % 2 == 0) {
			b.emplace_back(a[i]);
		}
	}
	sort(all(b));
	if (b.size() < 2) {
		cout << 0 << endl;
	}
	else {
		int m = b.size();
		cout << b[m - 1] * b[m - 2] << endl;
	}
	return 0;
}

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

int main(){
    int r,g,b;
    cin >> r >> g >> b;
    int ans = r * 100 + g * 10 + b;

    if ((ans%4) == 0){
        cout << "YES";
        return 0;
    }

    else{
        cout << "NO";
    }

    return 0;
}

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

int main()
{
	int n, k, l, c;
	int P[20];
	c = 0;
	scanf("%d", &n);
	for (k = 1; k < n + 1; k++)
	{
		scanf("%d", &P[k]);
	}
	P[0] = 0;
	for (l = 1; l < n - 1; l++)
	{
		if (P[l] < P[l + 1])
		{
			if (P[l + 1] <= P[l + 2])
			{
				c++;
			}
		}
		else if (P[l + 1] >= P[l + 2] && P[l] != P[l + 2]) 
		{
			c++;
		}
	}
	printf("%d", c);
	return 0;
}

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

from pprint import pprint
from collections import deque, defaultdict
import itertools
import math
import sys

sys.setrecursionlimit(10 ** 6)
INF = float('inf')


N, K = map(int, input().split())
P = list(map(int, input().split()))
P = sorted(P)

res = 0
for i in range(K):
    res += P[i]
print(res)


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

int main(int argc, char **argv)
{
    int N;
    std::cin >> N;
    std::vector<int> B(N-1);
    std::vector<int> A(N);
    for(int i = 0; i < N-1; i++){
        std::cin >> B.at(i);
    }
    
    A.at(0) = B.at(0);
    for(int i = 0; i < N-2; i++){
        A.at(i+1) = std::min(B.at(i), B.at(i+1));
    }
    A.at(N-1) = B.at(N-2);

    int sum = 0;
    for(int i = 0; i < N; i++){
        sum += A.at(i);
    }
    
    std::cout << sum << std::endl;
    
}


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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





typedef long long ll;
const ll mod = 1e9+7;
const int maxn = 1e6 + 5;





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

    cout<<fixed<<setprecision(15);
    double l; cin>>l;
    double ans = (l/3)*(l/3)*(l/3);
    cout<<ans<<endl;

    return 0;
}


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

using namespace std;

int main(){
	int n, num[200][3];
	vector<int> game[3];
 
 	cin >> n;
 	for(int i = 0; i < n; i++){
 		for(int j = 0; j < 3; j++){
 			cin >> num[i][j];
 			game[j].push_back(num[i][j]);
 		}
 	}
 	int score[200];
 	fill_n(score, 200, 0);
 	for(int i = 0; i < n; i++){
 		for(int j = 0; j < 3; j++){
 			if(count(game[j].begin(), game[j].end(), num[i][j]) == 1) score[i] += num[i][j];
 		}
 	}

 	for(int i = 0; i < n; i++) cout << score[i] << endl;
	return 0;
}


Measured memory_bytes: 3156
/**
*    author:  yuya1234
*    created: 25.06.2020 14:29:35
**/

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

#define SORT(s) sort((s).begin(),(s).end())
#define SORTD(s) sort((s).rbegin(),(s).rend())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define SZ(x) ((int)(x).size())
#define MEMSET(v, h) memset((v), h, sizeof(v))

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

    int w,h,n;
    cin>>w>>h>>n;

    int tx,ty,ta;
    int d[4]={0,0,w,h};

    REP(i,n)
    {
        cin>>tx>>ty>>ta;
        switch (ta)
        {
        case 1:
            if(d[0]<tx)d[0]=tx;
            break;
        case 2:
            if(d[2]>tx)d[2]=tx;
            break;
        case 3:
            if(d[1]<ty)d[1]=ty;
            break;
        case 4:
            if(d[3]>ty)d[3]=ty;
            break;
        }
    }
    
    if(d[0]<d[2] && d[1]<d[3])
    {
        cout<<(d[2]-d[0])*(d[3]-d[1])<<endl;
    }
    else
    {
        cout<<0<<endl;
    }
    


    return 0;
}

Measured memory_bytes: 3648
require 'pp'
$DEBUG ? define_method(:dpp){|e|pp e} : define_method(:dpp){|e|}

# 入力値を数値で返却する
def gets_i()
  gets.chomp.to_i
end

# 空白区切の入力値を数値の配列で返却する
def gets_s_list()
  gets.chomp.split(" ")
end

n = gets_i
list = []
n.times do |i|
  s, p = gets_s_list
  list.push [i+1, s, p.to_i]
end

list.sort_by{|x| [x[1], -x[2]]}.each{|x| puts x[0]}

Measured memory_bytes: 14612
/*  ex9_1
    takafumi_ueki */
#include <stdio.h>
#include <stdlib.h>
#define SIZE 11
typedef struct {
    int size;
    int count;
    char data[SIZE];
    char *top;
}stack;
void initialize_stack(stack *stk);//初期化
void print_stack(stack *stk);
void push(stack *stk, char key);
void pop(stack *stk);

int main(void){
    int i;
    char input[SIZE];
    stack string;
    //入力する
    scanf("%s",input);
    initialize_stack(&string);
    //0か1だったらその数字をプッシュし、Bが出たらpopする
    for(i=0;i<SIZE;i++){
        if(input[i] == '0'){
            push(&string,'0');
        }
        else if(input[i] == '1'){
            push(&string,'1');
        }
        else if(input[i]=='B'){
            pop(&string);
        }
    }
    //結果を出力する
    print_stack(&string);
    return 0;
}

void initialize_stack(stack *stk){
    stk->count = 0;
    stk->size = SIZE;
    stk->top = &(stk->data[SIZE]);
}

void push(stack *stk, char key){
    if(stk->count < stk->size){
        //トップをひとつ上にあげる
        stk->top--;
        //データを格納する
        *(stk->top) = key;
        //現在のデータ数をひとつ増やす
        stk->count++;
    }
}
void pop(stack *stk){
    if(stk->count > 0){
        //topをひとつ下に下げる
        stk->top++;
        //データ数をひとつ減らす
        stk->count--;
    }
}
void print_stack(stack *stk){
    char *ptr;
    int i;
    //一番上の位置
    ptr = stk->top;
    //古いデータからtopに向かってprintする
    while(i<stk->count-1){
        ptr++;
        i++;
    }
    for(int i=0;i<stk->count;i++){
        printf("%c", *ptr--);
    }
    printf("\n");
}

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

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

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

typedef long long llt;

const int MAXN = 5000;
const llt Mod = 1000000007;

int N, len;
char str[MAXN+1];
llt dp[MAXN+1][MAXN+1];

void init()
{
    memset( dp, 0, sizeof dp );
    scanf( "%d\n", &N );
    scanf( "%s", str );
    len = strlen( str );
}

llt fast_pow( llt low, int high )
{
    llt ans = 1;
    while ( high )
    {
        if ( high & 1 ) ans = ans * low % Mod;
        high >>= 1;
        low = low * low % Mod;
    }
    return ans;
}

llt Mod_inverse( llt x ) { return fast_pow( x, Mod - 2 ); }

void solve()
{
    dp[0][0] = 1;
    for ( int i = 1; i <= N; ++i )
    {
        dp[i][0] = ( dp[i - 1][1] + dp[i - 1][0] ) % Mod;
        dp[i][i] = dp[i - 1][i - 1] * 2 % Mod;
        for ( int j = 1; j < i; ++j )
            dp[i][j] = ( dp[i - 1][j - 1] * 2 + dp[i - 1][j + 1] ) % Mod;
    }
    llt ans = dp[N][len] * Mod_inverse( fast_pow( 2, len ) ) % Mod;
    printf( "%lld\n", ans );
}

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

Measured memory_bytes: 195584
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int n = in.nextInt();
		int m = in.nextInt();
		int[] s = new int[m];
		int[] c = new int[m];
		for (int i = 0; i < m; i++) {
			s[i] = in.nextInt() - 1;
			c[i] = in.nextInt();
		}
		int r = solve(n, m, s, c);
		System.out.println(r);
		in.close();
	}

	private static int solve(int n, int m, int[] s, int[] c) {
		int[] r = new int[n];
		for (int i = 0; i < n; i++)
			r[i] = -1;
		for (int i = 0; i < m; i++)
			if (r[s[i]] == -1)
				r[s[i]] = c[i];
			else if (r[s[i]] != c[i])
				return -1;
		if (n > 1 && r[0] == 0)
			return -1;
		if (r[0] == -1)
			if (n > 1)
				r[0] = 1;
			else
				r[0] = 0;
		for (int i = 1; i < n; i++)
			if (r[i] == -1)
				r[i] = 0;
		int ans = 0;
		for (int i = 0; i < n; i++) {
			ans *= 10;
			ans += r[i];
		}
		return ans;
	}

}


Measured memory_bytes: 21844
// Bismillahirrahmanirrahim
#include<bits/stdc++.h>
using namespace std;
#define int long long

int arr[3005][3005];
vector<pair<int, int>> vec;
int n, t;
int KS(int index, int current_time) {
  if(current_time >= t || index >= n) return 0;
  if(arr[index][current_time] ) return arr[index][current_time];
  int result = 0;
  result = max(result, KS(index+1,current_time));
  result = max(result, KS(index+1, current_time+vec[index].first)+vec[index].second);
  arr[index][current_time] = result;
  return result;

}


signed main() {
 cin >> n >> t;
  for(int i = 0; i < n;i++){
    int x, y;
    cin >> x >> y; vec.push_back(make_pair(x, y));
  }
  sort(vec.begin(), vec.end());
  int result = 0;
  for(int i = 0; i < 3005; i++) result = max(result, KS(i,0));

  cout << result;


}


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

int main(){

  int N, numB=0, numA=0, numC=0,ans=0;
  bool A=false;
  cin >> N;
  string s[N];
  for(int i=0; i<N; i++){
    cin >> s[i];
    if(s[i][0]=='B') numB++;
    if(s[i][s[i].size()-1]=='A') numA++;
    if(s[i][0]=='B' && s[i][s[i].size()-1]=='A') numC++;
  }

  ans = min(numA, numB);

  for(int i=0; i<N; i++){
    for(int j=1; j<s[i].size(); j++){
      if(s[i][j]=='B'&&s[i][j-1]=='A'){
         ans++;
      }
    }
  }

  if(numA==numB&&numA==numC&&numA!=0)ans--;

  cout << ans << endl;

  return 0;
}


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

const ll INF = LONG_LONG_MAX;
vector<P>edge[500010];

int main() {
    int v, e, r;
    cin >> v >> e >> r;
    rep(i, e) {
        int s, t, d;
        cin >> s >> t >> d;
        edge[s].push_back(P(t, d));
    }
    //dijkstra
    priority_queue<P, vector<P>, greater<P> > q;
    vector<ll>dist(v, INF);
    dist[r] = 0;
    q.push(P(0, r));
    while (!q.empty()) {
        ll d = q.top().first;
        ll prev = q.top().second;
        q.pop();
        if (dist[prev] < d)continue;
        for (auto next:edge[prev]) {
            ll to = next.first;
            ll cost = next.second;
            if (dist[prev] + cost<dist[to]) {
                dist[to] = dist[prev]+cost;
                q.push(P(dist[to], to));
            }
        }
    }
    //output
    rep(i, v) {
        if (dist[i] == INF)cout << "INF" << endl;
        else cout << dist[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 28824
#include <stdio.h>

#define STRING_DATA 20001
#define LAKE 10000

int stack_index[STRING_DATA];
int stack_area[STRING_DATA];
int stack_lake[LAKE];
int l = 0, pop_flag;

void push(int i) {
  stack_index[l] = i;
  l++;
}

int pop() {
  if(l != 0) {
    pop_flag = 0;
    l--;
    return stack_index[l];
  }
  else {
    pop_flag = 1;
    return 0;
  }
}

int main(void) {
  int k = 0, t, i, j = 0;
  long int max_lake = 0;
  char in;

  for(i = 0 ; i < STRING_DATA ; i++) {
    stack_index[i] = 0;
    stack_area[i] = 0;
  }
  
  while((in = getchar()) != EOF) {
    if(in == '\\') {
      push(k);
    }
    else if(in == '/') {
      t = pop();
      if(pop_flag != 1) {
	stack_area[t] = k - t;
	for(i = t + 1 ; i < k ; i++) {
	  stack_area[t] += stack_area[i];
	  stack_area[i] = 0;
	}
      }
    }
    k++;
  }

  for(i = 0 ; i < k ; i++) {
    if(stack_area[i] != 0) {
      max_lake += stack_area[i];
      stack_lake[j] = stack_area[i];
      j++;
    }
  }
  
  printf("%ld\n", max_lake);
  printf("%d", j);
  for(i = 0 ; i < j ; i++) {
    printf(" %d", stack_lake[i]);
  }
  printf("\n");
  return 0;
}


Measured memory_bytes: 2100
#include<iostream>
using namespace std;
const int MAX = 2000000;

int H,A[MAX+1];

void maxHeapify(int i){
int l,r,largest;
l = 2*i;
r= 2*i+1;
if(l<=H&&A[l]>A[i])largest = l;
else largest = i;
if(r<=H&&A[r]>A[largest])largest = r;
if(largest!=i){
    swap(A[i],A[largest]);
    maxHeapify(largest);
}
}

int main(){
cin>>H;
for(int i =1;i<=H;i++)cin>>A[i];
for(int i = H/2;i>=1;i--)maxHeapify(i);
for(int i = 1;i<=H;i++)cout<<" "<<A[i];
cout<<endl;
return 0;
}



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

using namespace std;

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

int main() {
  int N, K;
  cin >> N >> K;
  
  vector<vector<int>> snack(N);
  rep(i, K){
    int d;
    cin >> d;
    rep(i, d){
      int man;
      cin >> man;
      snack.at(man-1).push_back(i);
    }
  }
  
  int counter = 0;
  rep(i, N){
    if(snack.at(i).size() == 0)
     counter++;
  }
  
  cout << counter << endl;
  
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fi first
#define se second
#define pb push_back
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 int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

void solve() {
    ll n;
    cin >> n;
    string ans = "";
    for(int i = 1; i < 15; i++) {
        if(n > pow(26, i)){
            n -= pow(26, i);
            continue;
        }
        n--;
        rep(j, i){
            ans += 'a' + n % 26;
            n /= 26;
        }
        break;
    }
    reverse(all(ans));
    cout << ans << endl;
}

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

Measured memory_bytes: 4048