akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>

bool is_royal(const std::vector<std::pair<int, char>> &cards) {
  std::set<int> s;
  for (const auto &p: cards) {
    s.insert(p.first);
  }
  return s.count(10) && s.count(11) && s.count(12) && s.count(13) && s.count(1);
}

bool is_flush(const std::vector<std::pair<int, char>> &cards) {
  std::set<char> s;
  for (const auto &p: cards) {
    s.insert(p.second);
  }
  return (s.size() == 1);
}

bool is_straight(const std::vector<std::pair<int, char>> &cards) {
  std::set<int> s;
  std::vector<int> t;
  for (const auto &p: cards) {
    s.insert(p.first);
    t.push_back(p.first);
  }
  if (s.size() != 5) return false;
  std::sort(t.begin(), t.end());
  return (t[4]-t[0] == 4);
}

std::vector<int> multi(const std::vector<std::pair<int, char>> &cards) {
  std::map<int, int> s;
  for (const auto &p: cards) {
    ++s[p.first];
  }
  std::vector<int> res;
  for (const auto &p: s) {
    if (p.second >= 2) {
      res.emplace_back(p.second);
    }
  }
  return res;
}

int testcase_ends(bool first) {
  int N;
  if (scanf("%d", &N) == EOF)
    return 1;

  if (!first)
    printf("\n");

  std::map<char, std::vector<int>> score;
  for (char ch: {'S', 'C', 'H', 'D'}) {
    score[ch].emplace_back(0);
    for (int i=1; i<=13; ++i) {
      int x;
      scanf("%d", &x);
      score[ch].emplace_back(x);
    }
  }

  std::vector<int> hands{0};
  for (int i=0; i<9; ++i) {
    int x;
    scanf("%d", &x);
    hands.emplace_back(x);
  }

  for (int i=0; i<N; ++i) {
    std::vector<std::pair<int, char>> cards;
    int base=0;
    for (int j=0; j<5; ++j) {
      char n, s;
      scanf(" %c%c", &n, &s);
      int num=0;
      switch (n) {
      case 'A':
        num = 1;
        break;
      case 'T':
        num = 10;
        break;
      case 'J':
        num = 11;
        break;
      case 'Q':
        num = 12;
        break;
      case 'K':
        num = 13;
        break;
      default:
        num = n-'0';
      }

      cards.emplace_back(num, s);
      base += score[s][num];
    }

    bool royal=is_royal(cards);
    bool straight=is_straight(cards);
    bool flush=is_flush(cards);
    std::vector<int> mul=multi(cards);
    std::sort(mul.begin(), mul.end());

    intmax_t res=base;
    if (royal && flush) {
      res *= hands[9];
    } else if (straight && flush) {
      res *= hands[8];
    } else if (mul.size() == 1 && mul[0] == 4) {
      res *= hands[7];
    } else if (mul.size() == 2 && mul[0] == 2 && mul[1] == 3) {
      res *= hands[6];
    } else if (flush) {
      res *= hands[5];
    } else if (straight || royal) {
      res *= hands[4];
    } else if (mul.size() == 1 && mul[0] == 3) {
      res *= hands[3];
    } else if (mul.size() == 2 && mul[0] == 2 && mul[1] == 2) {
      res *= hands[2];
    } else if (mul.size() == 1 && mul[0] == 2) {
      res *= hands[1];
    } else {
      res = 0;
    }
    printf("%jd\n", res);
  }
  return 0;
}

int main() {
  for (int i=0; true; ++i) {
    if (testcase_ends(i == 0)) return 0;
  }
}



Measured memory_bytes: 2672
#include <iostream>
using namespace std;
#define int long long
int n, a[223456];
signed main() {
	cin>>n;
	bool flag=1;
	for(int i=0;i<n;i++){
		cin>>a[i];
		if(a[i]>i)flag=0;
		if(i&&a[i]-a[i-1]>1)flag=0;
	}
	if(!flag){
		cout<<"-1\n";
		return 0;
	}
	int ans=0;
	for(int i=n-1;i>=0;i--){
		if(i==n-1)ans+=a[i];
		else if(a[i]+1!=a[i+1])ans+=a[i];
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1792
s = gets.chomp
words = ["dream", "dreamer", "erase", "eraser"]
cnt = 0
words.each do |a|
  words.each do |b|
    words.each do |c|
      words.each do |d|
        re = s.gsub(/#{a}/, "").gsub(/#{b}/, "").gsub(/#{c}/, "").gsub(/#{d}/, "")
        if re == ""
          puts "YES"
          cnt += 1
          exit
        end
      end
    end
  end
end
if cnt == 0
  puts "NO"
end

Measured memory_bytes: 19452
#include<bits/stdc++.h>
#define L long long
using namespace std;
const int q=924844033;
int n,m,t,x[2010],f[2010][2010][4],g[2010],p;
inline void add(int &a,int b)
{
	a=(a+b)%q;
}
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	int i,j,k;
	scanf("%d%d",&n,&m);
	t=n/m+1;
	f[1][0][0]=f[1][1][2]=1;
	for(i=1;i<t;i++)
	  for(j=0;j<=i;j++)
	    for(k=0;k<4;k++)
	      if(f[i][j][k])
	        {
	  	     add(f[i+1][j][k>>1],f[i][j][k]);
			 if(!(k&1))
			   add(f[i+1][j+1][k>>1],f[i][j][k]);
			 add(f[i+1][j+1][k>>1|2],f[i][j][k]);
			}
	g[0]=1;
	for(i=1;i<=n%m;i++)
	  for(j=n;j>0;j--)
	    for(k=1;k<=j && k<=t;k++)
	      g[j]=(g[j]+(L)g[j-k]*(f[t][k][0]+f[t][k][1]))%q;
	for(;i<=m;i++)
	  for(j=n;j>0;j--)
	    for(k=1;k<=j && k<t;k++)
	      g[j]=(g[j]+(L)g[j-k]*(f[t-1][k][0]+f[t-1][k][1]))%q;
	x[0]=1;
	for(i=1;i<=n;i++)
	  x[i]=(L)x[i-1]*i%q;
	for(i=0,j=1;i<=n;i++,j*=-1)
	  p=(p+(L)j*g[i]*x[n-i])%q;
	p=(p+q)%q;
	printf("%d\n",p);
	return 0;
}


Measured memory_bytes: 61440
#include<bits/stdc++.h>
#define ull unsigned long long
#define ll long long
#define pb push_back
#define endl '\n'
#define line cout<<"----------------------"<<endl
#define mp make_pair
#define mod 1000000007
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL)
#define filein freopen("input.txt","r",stdin)
#define fileout freopen("output.txt","w",stdout)
using namespace std;
const ll  mx=300009;
ll dp[100009];
int main()
{
    for(ll  i=1;i<100009;i++) dp[i]=1e10;
    ll  n,w;
    cin>>n>>w;
    for(ll  i=0;i<n;i++)
    {
        ll  a,b;
        cin>>a>>b;
        for(ll  j=100002;j>=b;j--)
        {
            dp[j]=min(dp[j],dp[j-b]+a);
        }
    }
    for(ll  i=100000;i>0;i--)
    {
        if(dp[i]<=w)
        {
            cout<<i<<endl;
            break;
        }
    }

}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
vector<int> vec(3);

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

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

cout <<vec.at(0)<<" "<<vec.at(1)<<" "<<vec.at(2)<<endl;

}


Measured memory_bytes: 3136
#include<iostream>
#include<iomanip>
#include<queue>
#include<string>
#include<stack>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<cassert>
#include<ctime>
#include<algorithm>
#include<utility>
#include<map>
#include<set>
#include<vector>
#include<functional>

using namespace std;

typedef  long long           ll;
typedef  unsigned            ui;
typedef  unsigned long long  ull;
typedef  pair<int,int>       i_i;
typedef  pair<ll,int>        ll_i;
typedef  pair<ll,ll>         ll_ll;
typedef  pair<double,int>    d_i;
typedef  pair<double,double> d_d;

#ifdef DEBUG
#define dprintf      printf
#define dputs        puts
#define dout(x)      cout<<#x" = "<<(x)<<endl
#define darray(x,n)  {int i;rep(i,n)cout<<#x"["<<i<<"] = "<<*((x)+i)<<endl;}
#define dloop(i,s,g) for(int (i)=(s);(i)<(g);(i)++)
#define drep(i,n)    for(int (i)=0;(i)<(n);(i)++)
#define dstop()      scanf("%*c")
#else
#define dprintf      (1)?0:printf
#define dputs        (1)?0:puts
#define dout(x)
#define darray(x,n)
#define dloop(i,s,g) if(int i=0){}else
#define drep(i,n)    if(int i=0){}else
#define dstop()
#endif

#define F    first
#define S    second
#define pb   push_back
#define mp   make_pair

#define loop(i,s,g) for((i)=(s);(i)<(g);(i)++)
#define rep(i,n)    for((i)=0;(i)<(n);(i)++)
#define all(x)      (x.begin(),x.end())
#define in(T,...) T __VA_ARGS__; impl(__VA_ARGS__)
#define array(T,id,n) T id[(n)]; for(int i=0;i<(n);i++)cin>>id[i]
#define putv(n)     cout<<(n)<<endl

//#define int long long
#ifndef int
#define INF __INT32_MAX__
#else
#define INF __INT64_MAX__
#endif

void impl(){};
template <typename T,typename... TS >
void impl(T &head,TS &... tail)
{
  cin>>head;
  impl(tail ...);
}

signed main(void)
{
  in(char,c);
  if(c=='a' || c=='i' || c=='u' || c=='e' || c=='o')
    puts("vowel");
  else
    puts("consonant");
  
  return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-

import sys
input = sys.stdin.readline

N, Q = map(int, input().split())
S = input()
LR = [list(map(int, input().split())) for i in range(Q)]

lst = [0] * N
count = 0
for i in range(N - 1):
    if S[i] == 'A' and S[i + 1] == 'C':
        count += 1
    lst[i + 1] = count

for l, r in LR:
    ans = lst[r-1] - lst[l-1]
    print(ans)


Measured memory_bytes: 64604
class Array
  # O(self.size)
  # required conditions:
  # only positive values and sorted in ascending order;[1, 2, 3, 4, 5]
  # or only negative values ans sorted in descending order;[-1, -2, -3, -4, -5]
  def is_sorted_and_number_of_pairs_that_prod_is_less_than_or_equal_to(x)
    res = 0
    l = 0
    r = self.size - 1
    while l < r
      r -= 1 while l < r && self[l] * self[r] > x
      res += r - l
      l += 1
    end
    res
  end
end

N, K = gets.chomp.split.map(&:to_i)
A = gets.chomp.split.map(&:to_i)

posi = []
nega = []
zeros = 0
A.each do |ai|
  if ai < 0
    nega << ai
  elsif ai > 0
    posi << ai
  else
    zeros += 1
  end
end

posi.sort!
nega.sort!.reverse!

posi_size = posi.size
nega_size = nega.size

zero_pairs = zeros * (zeros - 1) / 2 + zeros * (N - zeros)

ng = -(10**18 + 1)
ok = 10**18 + 1

nega_posi = [nega, posi]

ans = (ng..ok).bsearch do |mid|
  
  cnt = 0
  
  cnt += zero_pairs if mid >= 0

  if mid > 0
    cnt += nega_size * posi_size
    nega_posi.each do |ary|
      cnt += ary.is_sorted_and_number_of_pairs_that_prod_is_less_than_or_equal_to(mid)
    end
  else
    r = nega_size - 1
    posi.size.times do |l|
      r -= 1 while(r >= 0 && posi[l] * nega[r] <= mid)
      cnt += nega_size - r - 1
    end
  end

  cnt >= K
end

puts ans

Measured memory_bytes: 20476
#![allow(unused)]

fn solve<R: std::io::BufRead>(mut sc: Scanner<R>) {
    let k: i64 = sc.get();
    let a: i64 = sc.get();
    let b: i64 = sc.get();

    if a % k == 0 || b % k == 0 || b / k != a / k {
        println!("OK");
    } else {
        println!("NG");
    }
}

macro_rules! debug {
    ($($a:expr),*) => {
        eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

//
// Based on EbTech's Scanner https://stackoverflow.com/q/56449027
//
struct Scanner<'a, R: std::io::BufRead> {
    reader: R,
    buf: String,
    iter: std::str::SplitWhitespace<'a>,
}

impl<'a, R: std::io::BufRead> Scanner<'a, R> {
    fn new(reader: R) -> Self {
        Self { reader, buf: String::new(), iter: "".split_whitespace() }
    }

    fn get<T: std::str::FromStr>(&mut self) -> T {
        if let Some(t) = self.iter.next() {
            return t.parse().ok().expect("Parse error")
        }
        self.buf.clear();
        self.reader.read_line(&mut self.buf).expect("I/O error");
        self.iter = unsafe { std::mem::transmute(self.buf.split_whitespace()) };
        self.get()
    }

    fn gets<T: std::iter::FromIterator<char>>(&mut self) -> T {
        use std::io::Read;
        assert_eq!(self.iter.next(), None);
        self.reader
            .by_ref()
            .bytes()
            .map(|b| b.unwrap() as char)
            .skip_while(|&c| c.is_whitespace())
            .take_while(|&c| !c.is_whitespace())
            .collect()
    }
}

fn main() {
    let stdin = std::io::stdin();
    solve(Scanner::new(stdin.lock()));
}



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

using namespace std;

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

int main(void)
{
    int n;
    cin >> n;
    int max = 0;
    int second_max = 0;
    vector<int> v(n);

    rep(i, 0, n)
    {
        cin >> v[i];
        if (max < v[i])
        {
            second_max = max;
            max = v[i];
        }
        else if (second_max < v[i])
        {
            second_max = v[i];
        }
    }

    rep(i, 0, n)
    {
        if (v[i] < max)
        {
            cout << max << endl;
        }
        else
        {
            cout << second_max << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 2432
"""
import random
import functools
import copy
import bisect
import array
import re
import collections
import heapq
import fractions
import itertools
import string
import math
from operator import itemgetter as ig
from bisect import bisect_left, bisect_right, insort_left, insort_right
from itertools import permutations, combinations, product, accumulate, groupby
from heapq import heappush, heappop
from collections import deque, defaultdict, Counter
import sys
sys.setrecursionlimit(10 ** 7)
# import numpy as np

inf = 10 ** 20
INF = float("INF")
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)]
ddn9 = ddn + [(0, 0)]
'''for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:'''
"""
from collections import Counter
import sys
sys.setrecursionlimit(10 ** 7)


def wi(): return list(map(int, sys.stdin.readline().split()))
# WideIntPoint


def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]


def ws(): return sys.stdin.readline().split()


def si(): return int(sys.stdin.readline())  # SingleInt


def ss(): return input()


def hi(n): return [si() for _ in range(n)]


def hs(n): return [ss() for _ in range(n)]  # HeightString


def s_list(): return list(input())


def mi(n): return [wi() for _ in range(n)]  # MatrixInt


def mip(n): return [wip() for _ in range(n)]


def ms(n): return [ws() for _ in range(n)]


def num_grid(n): return [[int(i) for i in sys.stdin.readline().split()[
    0]] for _ in range(n)]  # NumberGrid


def grid(n): return [s_list() for _ in range(n)]


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


def main():
    N, K = wi()
    mod = 10 ** 9 + 7
    res = 0
    d = [0]*K

    for i in range(K, 0, -1):
        n = pow(K//i, N, mod)

        for j in range(2*i, K+1, i):
            n -= d[j-1]

        d[i-1] = n
        res += n*i
        res %= mod
    print(res)


if __name__ == '__main__':
    main()


Measured memory_bytes: 75136
#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using namespace atcoder;
using ll=long long;
template<class T,class U> inline bool chmin(T&x,U y){if(x>y){x=y;return true;}return false;}
template<class T,class U> inline bool chmax(T&x,U y){if(x<y){x=y;return true;}return false;}
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

int mx(int x,int y){return max(x,y);}
int e(){return -1;}
int b;
bool f(int x){
    return x<b;
}
void solve(){
    int n,q;
    cin>>n>>q;
    vector<int> a(n);
    for(auto&i:a) cin>>i;
    segtree<int,mx,e> sg(a);
    {
        int t,x,v;
        fr(_,q){
            cin>>t>>x>>v;
            switch(t){
                case 1:
                    sg.set(x-1,v);
                    break;
                case 2:
                    cout<<sg.prod(x-1,v)<<'\n';
                    break;
                default:
                    b=v;
                    cout<<sg.max_right<f>(x-1)+1<<'\n';
            }
        }
    }
}

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

Measured memory_bytes: 6148
import java.util.*;

public class Main {

    private static int MOD = 1_000_000_007;

    public static void main(String[] args) {
        final Scanner scanner = new Scanner(System.in);
        solve(scanner);
    }

    static long[] fac = new long[200_001];
    static long[] inv = new long[200_001];
    static long[] ifac = new long[200_001];

    static void makeTable() {
        fac[0] = fac[1] = 1;
        ifac[0] = ifac[1] = 1;
        inv[1] = 1;
        for (int i = 2; i < 200_001; i++) {
            fac[i] = (fac[i - 1] * i) % MOD;
            inv[i] = ((-inv[MOD % i] + MOD) * (MOD / i)) % MOD;
            ifac[i] = (ifac[i - 1] * inv[i]) % MOD;
        }
    }

    // int N = scanner.nextInt();
    // scanner.nextLine();
    // int[] n = Arrays.stream(scanner.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
    static void solve(Scanner scanner) {
        makeTable();
        int[] n = Arrays.stream(scanner.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
        int H = n[0], W = n[1], A = n[2], B = n[3];
        long ans = 0;
        for (int b = B + 1; b <= W; b++) {
            long up = fac[H - A + b - 2];
            up = (up * ifac[H - A - 1]) % MOD;
            up = (up * ifac[b - 1]) % MOD;
            long down = fac[A + W - b - 1];
            down = (down * ifac[A - 1]) % MOD;
            down = (down * ifac[W - b]) % MOD;
            ans = (ans + ((up * down) % MOD)) % MOD;
        }

        System.out.println(ans);
    }

}


Measured memory_bytes: 31180
#include<stdio.h>

int main(){
	char S[100000];
	scanf("%s",S);
	int i,frag = 0;
	for(i = 0; S[i] != '\0'; i++){
		if(S[i] == 'd' && S[i + 1] == 'r' && S[i + 2] == 'e' && S[i + 3] == 'a' && S[i + 4] == 'm'){
			if(S[i + 5] == 'e' && S[i + 6] == 'r'){
				if(S[i + 7] == 'a' && S[i + 8] == 's' && S[i + 9] == 'e'){
					i+=4;
				} else {
					i+=6;
				}
			} else {
				i += 4;
			}
		} else if(S[i] == 'e' && S[i + 1] == 'r' && S[i + 2] == 'a' && S[i + 3] == 's' && S[i + 4] == 'e'){
			if(S[i + 5] == 'r'){
				i += 5;
			} else {
				i += 4;
			}
		} else /*if(S[i] == '\0' || S[i + 1] == '\0' || S[i + 2] == '\0' || S[i + 3] == '\0' || S[i + 4] == '\0'){
			break;
		} else */{
			frag++;
			break;
		}
	}
	if(frag == 0){
		printf("YES");
	} else {
		printf("NO");
	}
	return 0;
}

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
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;

template <int mod>
struct ModInt {
    ll x;
    ModInt() : x(0) {}
    ModInt(ll y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
    ModInt &operator+=(const ModInt &p) { if((x += p.x) >= mod) x -= mod; return *this; }
    ModInt &operator-=(const ModInt &p) { if((x += mod - p.x) >= mod) x -= mod; return *this; }
    ModInt &operator*=(const ModInt &p) { x = 1LL * x * p.x % mod; return *this; }
    ModInt &operator/=(const ModInt &p) { *this *= p.inverse(); return *this; }
    ModInt operator-() const { return ModInt(-x); }
    ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
    ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
    ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
    ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
    bool operator==(const ModInt &p) const { return x == p.x; }
    bool operator!=(const ModInt &p) const { return x != p.x; }
    ModInt inverse() const {
        int a = x, b = mod, u = 1, v = 0, t;
        while(b > 0) {
            t = a / b;
            swap(a -= t * b, b);
            swap(u -= t * v, v);
        }
        return ModInt(u);
    }
    ModInt pow(ll n) const {
        ModInt ret(1), mul(x);
        while(n > 0) {
            if(n & 1) ret *= mul;
            mul *= mul;
            n >>= 1;
        }
        return ret;
    }
    friend ostream &operator<<(ostream &os, const ModInt &p) {
        return os << p.x;
    }
    friend istream &operator>>(istream &is, ModInt &a) {
        int64_t t;
        is >> t;
        a = ModInt<mod>(t);
        return (is);
    }
};
const int mod = 998244353;
using mint = ModInt<mod>;

mint dp[3010][6010][3];

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

    dp[0][0][0] = 1;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j <= s; ++j) {
            dp[i+1][j][0] += dp[i][j][0];
            dp[i+1][j+a[i]][1] += dp[i][j][0] * (i+1); // 左側　1,...,i+1
            dp[i+1][j+a[i]][2] += dp[i][j][0] * (i+1) * (n-i); // 右側　i+1,...,n

            dp[i+1][j][1] += dp[i][j][1];
            dp[i+1][j+a[i]][1] += dp[i][j][1];
            dp[i+1][j+a[i]][2] += dp[i][j][1] * (n-i);

            dp[i+1][j][2] += dp[i][j][2];
        }
    }
    cout << dp[n][s][2] << endl;
}

Measured memory_bytes: 427604
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>

#define pai 3.1415926535


int main(void) {
	int N;
	scanf("%d", &N);
	int a[200000];
	for (int i = 0; i < N; i++) {
		scanf("%d", &a[i]);
	}
	int count = 0;
	int flag = 1;
	for (int i =0; i < N; i++) {
		if (flag != a[i]) {
			count++;
		}
		else flag++;
		if (i == N - 1&&flag==1&&a[i]!=1) {
			count = -1;
			break;
		}
	}
	printf("%d", count);

	return 0;


}

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

int solution(const int& N, const int& K){
			
	if(K == 1) return 0;
	if(N == K) return 0;
	//K > N
	return (N - K);
		
}

int main() {
	int N, K;
	//N: ball
	//K: people
	cin >> N >> K;
	//N > K

	cout << solution(N, K) << endl;	
	return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

const ll inf = (ll)1e9;
const ll mod = (ll)1e9 + 7;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

#define print(s) cout << s;
#define println(s) cout << s << endl;
#define printd(s, f) cout << fixed << setprecision(f) << s << endl;


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

	vector<ll> dp(n + 1);

	dp[0] = 1;

	ll old = -1;
	for (int i = 0; i < m; i++)
	{
		int x;
		cin >> x;
		
		dp[x] = -1;
	}

	for (int i = 1; i <= n; i++)
	{
		if (dp[i] >= 0)
		{
			if (dp[i - 1] >= 0)
			{
				dp[i] = (dp[i] + dp[i - 1]) % mod;
			}

			if (i - 2 >= 0 && dp[i - 2] >= 0)
			{
				dp[i] = (dp[i] + dp[i - 2]) % mod;
			}
		}
	}

	println(dp[n]);
}


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

const int Maxn = 200005;

int n;
vector <int> neigh[Maxn];
int res[Maxn];

void Solve(int v, int p, int mx, int pres);

int Count(int v, int p, int mx)
{
    if (v > mx) return 0;
    int res = 1;
    for (int i = 0; i < neigh[v].size(); i++) {
        int u = neigh[v][i];
        if (u == p) continue;
        res += Count(u, v, mx);
    }
    return res;
}

void Expand(int v, int p, int mx, int pres)
{
    if (v > mx) { Solve(v, p, mx, pres); return; }
    res[v] = pres;
    for (int i = 0; i < neigh[v].size(); i++) {
        int u = neigh[v][i];
        if (u == p) continue;
        Expand(u, v, mx, pres);
    }
}

void Solve(int v, int p, int mx, int pres)
{
    pres++;
    vector <int> V;
    for (int i = 0; i < neigh[v].size(); i++) {
        int u = neigh[v][i];
        if (u == p) { V.push_back(0); continue; }
        V.push_back(Count(u, v, mx));
        pres += V.back();
    }
    res[v] = pres;
    for (int i = 0; i < neigh[v].size(); i++) {
        int u = neigh[v][i];
        if (u == p) continue;
        int got = pres - V[i] + Count(u, v, v);
        Expand(u, v, v, got);
    }
}

int main()
{
    scanf("%d", &n);
    for (int i = 0; i < n - 1; i++) {
        int a, b; scanf("%d %d", &a, &b);
        neigh[a].push_back(b);
        neigh[b].push_back(a);
    }
    for (int i = 0; i < neigh[1].size(); i++)
        Solve(neigh[1][i], 1, 1, 0);
    for (int i = 2; i <= n; i++)
        printf("%d%c", res[i], i + 1 <= n? ' ': '\n');
    return 0;
}


Measured memory_bytes: 28928
N = int(input())
S =input()

alpha = 'abcdefghijklmnopqrstuvwxyz'
ans = -1

for i in range(N-1):
    count = 0
    for j in range(26):
        if alpha[j] in S[0:i] and alpha[j] in S[i:N]:
            count += 1
    ans = max(ans,count)
    
print(ans)

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

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

    int n;
    cin >> n;
    vector<pair<int, int>> A(n);
    for(int i = 0; i < n; i++){
        int a, b;
        cin >> a >> b;
        A[i] = {b, a};
    }

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

    int now = 0;
    for(int i = 0; i < n; i++){
        if(now + A[i].second <= A[i].first){
            now += A[i].second;
        }else{
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define mk make_pair
using namespace std;
typedef long long ll;
const int N = 3e5 + 5;
const int mod = 1e9 + 7;
int n, k, a[101];
int dp[N];
int main() {
	cin >> n >> k;
	for (int i = 1; i <= n; ++i) cin >> a[i];
	for (int i = 1; i <= k; ++i) {
		for (int j = 1; j <= n; ++j) {
			if (a[j] <= i && !dp[i - a[j]]) {
				dp[i] = 1;
			}
		}
	}
	if (dp[k]) cout << "First";
	else cout << "Second";
}


Measured memory_bytes: 640
#include <iostream>
using namespace std;
int main(){
  int n,a,b,c,x,xn,y[100],i,endcnt,flag;
  while(1){
    flag=0;
    endcnt=0;
    cin >> n >> a >> b >> c >> x;
    if(n==0&&a==0&&b==0&&c==0&&x==0) break;
    for(i=0;i<n;i++){
      cin >> y[i];
    }
    i=0;
    xn=x;
    while(1){
      if(xn==y[i]){
        i++;
      }
      if(i==n){
    flag=1;
        break;
      }
      endcnt++;
      if(endcnt==10001){
    break;
      }
      xn=(a*x+b)%c;
      x=xn;
    }
    if(flag==0) cout << -1 << endl;
    else cout << endcnt << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
s=require("fs").readFileSync("/dev/stdin","utf8");
a = []
for (i = 0; i < s.split('\n')[0]; i++) {
	a.push(s.split('\n')[i + 1])
}
m = Math.max(...a)
a.forEach((n, i) => m == n && (a[i] = m / 2, m = 0))
b = 0;
a.forEach(n => b += n | 0);
console.log(b);


Measured memory_bytes: 7500
#include <iostream>
#include <queue>
using namespace std;
int main()
{
  int n,q;
  cin >> n >> q;
  queue< pair<string,int> > que;
  for(int i=0; i<n; i++){
    string name;
    int t;
    cin >> name >> t;
    que.push(make_pair<string,int>(name,t));
  }
  int count = 0;
  while(!que.empty()){
    pair<string,int> p = que.front(); que.pop();
    if(p.second <= q){
      count += p.second;
      cout << p.first << " " << count << endl;
    }else{
      p.second -= q;
      count += q;
      que.push(p);
    }
  }
  return 0;
}

Measured memory_bytes: 1300
#include <iostream>
#include <stdlib.h> 
using namespace std;
#define MAX 100000
typedef long long llong;

int n,k;
llong W[MAX];

int check(int p)
{
	int i;
	int v = 0;
	for(i = 0; i < k; i++)
	{
		llong sum = 0;
		while(sum + W[v] <= p)
		{
			sum += W[v];
			v++;
			if(v==n) return n;
		}		
	}
	return v;
}

int solve()
{
	llong left = 0;
	llong right = 100000 * 10000; 	//
	llong mid;
	while(right - left > 1)
	{
		mid = (left + right) / 2 ;
		int v = check(mid);
		if(v >= n) right = mid;
		else left = mid;
	}
	return right;
} 



int main() 
{
	cin >> n >> k;
	for( int i =0; i < n; i++) cin >> W[i];
	llong ans = solve();
	cout << ans << endl;
//	system("pause");
	return 0;
}


Measured memory_bytes: 3888
#include <bits/stdc++.h>
#define rep(a,n) for (ll a = 0; a < (n); ++a)
using namespace std;
typedef long long ll;
typedef pair<double,ll> P;
typedef vector<vector<ll> > Graph;
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 = 1e18;



int main(){
    int x,y;
    cin >> x >> y;
    cout << x + y/2 << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,a,b,c;
    cin >> n;
    while(n--){
        cin >> a >> b >> c;
        if(a<b) swap(a,b);
        if(a<c) swap(a,c);
        if((a*a)==(b*b+c*c))    cout << "YES\n";
        else cout << "NO\n";
    }
}  

Measured memory_bytes: 3072
#include <bits/stdc++.h>
#define PI 3.14159265359
typedef long long int ll;
typedef unsigned long long int ull;
using namespace std;
const ll INF=1e9+7;
void input(ll *a,ll n){
    for(ll i=0;i<n;i++)
        cin>>a[i];
}
ll lcm(ll a,ll b)
{
    return (a*b)/__gcd(a,b);
}
bool isprime(ll n){
    if(n==1){
        return false;
    }
    if(n==2 || n==3){
        return true;
    }
    for(ll i=2;i<=sqrt(n);i++){
        if(n%i==0)
            return false;
    }
    return true;
}

//ll x[100001]={0};
//ll p[100001]={0};
//ll a[100001]={0};
//vector<pair<ll,ll> > adj[100001];
//ll dist[100001]={0};


void sieve(ll n,bool *a)
{
    for (ll p=2; p*p<=n; p++){
        if (!a[p]){
            for (ll i=p*p;i<=n;i+=p)
                a[i]=true;
        }
    }
}

ll fact(ll n){
    ll res=1;
    for(ll i=1;i<=n;i++)
        res*=i;
    return res;
}

/*ll distance(ll x1,ll y1,ll x2,ll y2){
    return (ll)ceil(sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)));
}*/

/*void dfs(ll curr,ll prev,ll weight,bool found){

    if(weight>n)
        return;

    for(u:adj[curr]){
        if(u.first!=prev){
            if(u.second==d || found)
                dfs(u.first,curr,weight+u.second,true);
            else
                dfs(u.first,curr,weight+u.second,false);
        }
    }
    cout<<weight<<" "<<found<<endl;
    if(weight==n && found){
        ans+=1;
        ans=ans%INF;
    }
}*/

void solve(){
    string s,t;
    cin>>s>>t;
    bool flag=true;

    for(ll i=0;i<s.length();i++){
        if(s[i]!=t[i]){
            flag=false;
            break;
        }
    }
    if(flag){
        cout<<"Yes";
    }
    else{
        cout<<"No";
    }
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //sieve(100001,c);
    ll t=1;
    //cin>>t;
    for(ll i=0;i<t;i++){
        solve();
    }
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define dbug(x) cout<<#x<<"="<<x<<endl
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while ('0'>ch||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do {(t*=10)+=ch-'0';ch=getchar();} while ('0'<=ch&&ch<='9'); t*=f;
}
int n;
int main() {
	//freopen("1.txt","r",stdin);
	read(n);
	if (n&1) printf("%.10lf\n",((n+1)/2)*1.0/n);
	else printf("0.5\n");
	return 0;
}

Measured memory_bytes: 764
import sys

input=sys.stdin.readline
sys.setrecursionlimit(1000000)

N,M=map(int,input().split())
edge=[[] for i in range(0,N)]
dedge=[0 for i in range(0,N)]
data=[]
dic={}
for i in range(M):
    a,b=map(int,input().split())
    edge[a-1].append(b-1)
    edge[b-1].append(a-1)
    dedge[a-1]+=1
    dic[(a-1,b-1)]=0
    dic[(b-1,a-1)]=0
    dic[(a-1,b-1)]=i
    dic[(b-1,a-1)]=i
    data.append([a-1,b-1,0])

if M%2==1:
    print(-1)
    exit()

ans=[0 for i in range(N)]
treeedge=[[] for i in range(0,N)]
visit=set([0])
q=set([0])
sub=set([])
while q:
    while q:
        x=q.pop()
        for i in edge[x]:
            if i not in visit:
                treeedge[x].append(i)
                treeedge[i].append(x)
                visit.add(i)
                sub.add(i)

        if not q:
            q=sub
            sub=set([])
            break



def dfs(v,pv):
    if len(treeedge[v])==1 and v!=0:
        ans[v]=(dedge[v]%2,pv)
        return dedge[v]%2

    A=dedge[v]%2
    for i in treeedge[v]:
        if i!=pv:
            A+=dfs(i,v)
    ans[v]=(A%2,pv)
    return ans[v][0]

dfs(0,-1)

for i in range(1,N):
    val,parent=ans[i]
    if val==1:
        index=dic[(i,parent)]
        data[index][2]=1

for i in range(M):
    a,b,val=data[i]
    if val==0:
        print(a+1,b+1)
    else:
        print(b+1,a+1)


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

#define ll long long int
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define INF 0x3f3f3f3f
#define show(x) cerr<<#x<<" : "<<x<<'\n';
#define yogeshk972() cerr<<"\nTime Taken : "<<(float)(clock()-time_p)/CLOCKS_PER_SEC<<"\n";
clock_t time_p=clock();

using namespace std;
const int N=1e6, mod= 1e9+7;
ll p[N],w[N],v[N],vec[ (1<<21)+1 ];

int main(){
	ios_base::sync_with_stdio(0);	cin.tie(0);
	int n;
	cin>>n;
	if( (n&1)==0)cout<<"0.5";
	else cout<<setprecision(10)<<(double)(n-n/2)/n;
	
    yogeshk972();
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cassert>
#include <functional>
#include <numeric>
#include <limits>
#include <iomanip>
#include <queue>
#include <cmath>
#include <math.h>
#include <string>
#include <cmath>
#include <bitset>
#include <set>
using namespace std;
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; }
const long long INF = 1LL << 60;
using pll = pair<long long, long long>;
typedef long long ll;
#define min(a, b) ((a) < (b) ? (a) : (b))
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)

// 最大公約数
long long gcd(long long a, long long b)
{
	if (a % b == 0) {
		return(b);
	}
	else {
		return(gcd(b, a % b));
	}
}

int main() {
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	// cout << std::fixed << std::setprecision(15);

	string S;
	cin >> S;

	for (int i = 0; i < S.length(); i++) {
		cout << "x";
	}
	cout << endl;
	return 0;
}


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

using namespace std;

int main() {
    int x, ans = 0;
    cin >> x;

    int div = x/500;
    ans += div*1000;
    x -= div*500;

    div = x/5;
    ans += div*5;
    x -= div*5;

    cout << ans;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <stack>
#include <vector>
using namespace std;
typedef long long ll;
int main(){
  string s;
  cin >> s;
  if(s.size() != 26){
    map<char,bool> mp;
    string t = "abcdefghijklmnopqrstuvwxyz";
    for(char c:s)mp[c] = true;

    for(char c:t){
      if(mp[c]==false){
        s += c;
        break;
      }
    }
    cout << s << endl;
  }
  else{
    reverse(s.begin(),s.end());
    vector<char> dict;
    char c1 = '*';
    for(int i = 0;i < s.size()-1;i++){
      dict.push_back(s[i]);
      if(s[i] > s[i+1]){
        c1 = s[i+1];
        s[i+1] = '*';
        break;
      }
    }

    if(c1 == '*'){
      cout << -1 << endl;
      return 0;
    }

    sort(dict.begin(),dict.end());
    for(char c2:dict){
      if(c2 > c1){
        c1 = c2;
        break;
      }
    }

    reverse(s.begin(),s.end());
    string t = "";
    for(char c:s){
      if(c != '*')t += c;
      else{
        t += c1;
        break;
      }
    }

    cout << t << endl;
  }
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	@SuppressWarnings("resource")
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int m = scanner.nextInt();
		List<Coordinate> st = new ArrayList<>();
		List<Coordinate> ch = new ArrayList<>();

		for (int i = 0; i < n; i++) {
			st.add(new Coordinate(scanner.nextInt(), scanner.nextInt()));
		}
		for (int i = 0; i < m; i++) {
			ch.add(new Coordinate(scanner.nextInt(), scanner.nextInt()));
		}

		long min = 1000000000;
		int[] index = new int[n];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				if (min > Math.abs(st.get(i).x - ch.get(j).x) + Math.abs(st.get(i).y - ch.get(j).y)) {
					index[i] = j;
				}
				min = Math.min(min, Math.abs(st.get(i).x - ch.get(j).x) + Math.abs(st.get(i).y - ch.get(j).y));
			}
			min = 1000000000;
		}
		for (int i = 0; i < n; i++) {
			System.out.println(index[i] + 1);
		}
	}
}

class Coordinate {
	long x;
	long y;

	Coordinate(int x, int y) {
		this.x = x;
		this.y = y;
	}
}

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

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

i64 r, g;
int main() {
  cin >> r >> g;
  cout << 2 * g -r << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define N 1000000
int insertionSort(int *A, int n, int g){
int i;
 int j;
 int v;
 int cnt=0;
 for(i=g;i<n;i++){
   v = A[i];
   j = i - g;
   while( j >= 0 && A[j] > v){
     A[j+g] = A[j];
     j = j - g;
     cnt++;
   }
   A[j+g] = v;
 }
 return cnt;
}
 
void shellSort(int *A, int n){
  int  i;
  int  m=5;
  int  cnt=0;
  int  m_cnt=0;
  int  G[5]={1000,100,10,4,1};
  for(i=0;i<m;i++){
    if(G[i]<=n){
      cnt += insertionSort(A, n, G[i]);
      m_cnt++;
    }
  }
  printf("%d\n",m_cnt);
     
  for(i=0;i<m-1;i++){
    if(G[i]<=n){
      printf("%d ",G[i]);
    }
  }
  printf("%d\n",G[i]);
  printf("%d\n",cnt);
  for(i=0;i<n;i++){
    printf("%d\n",A[i]);
  }
}
 
int main(){
  int g=1;
  int i;
  int j;
  int n;
  int data[N];
 
  scanf("%d",&n);
 
  for(i=0;i<n;i++){
    scanf("%d",&data[i]);
  }
  shellSort(data,n);
   
  return 0;
}

Measured memory_bytes: 4504
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(v) v.begin(),v.end()

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


Measured memory_bytes: 3628
n = int(input())
A = list(map(int, input().split()))
acc = [0] * (n + 1)
for i in range(n):
    acc[i + 1] = acc[i] + A[i]

acc.sort()

from collections import Counter

cnt = 0
cacc = Counter(acc)
for k, v in cacc.items():
    if v > 1:
        cnt += v * (v - 1) // 2
print(cnt)

Measured memory_bytes: 119888
def main():
    menu = [ input() for a in range(5)]
    time = 0
    for i in range(len(menu)):
        if int(menu[i]) % 10 == 0:
            time += int(menu[i])
            menu[i] = "0"
    if len(menu) > 0:
        for i in range(menu.count("0")):
            menu.remove("0")
    if len(menu) > 0:
        menu.sort(key = (lambda x: 10 - int(x[-1])))

        for i in range(len(menu) - 1):
            time += int(menu[i]) + 10 - int(menu[i][-1])
        time += int(menu[-1])
    print(time)
main()

Measured memory_bytes: 3064
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
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;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
const ll mod=1e9+7;
const int inf=1<<30;

int main(){
  int n; cin >> n;
  if(n%2==0){
    int m=n*(n-1)/2-n/2;
    cout << m << endl;
    for(int i=1;i<=n;i++){
      for(int j=i+1;j<=n;j++){
        if(i+j==n+1) continue;
        cout << i << " " << j << endl;
      }
    }
  }
  else{
    int m=n*(n-1)/2-(n-1)/2;
    cout << m << endl;
    for(int i=1;i<=n;i++){
      for(int j=i+1;j<=n;j++){
        if(i+j==n) continue;
        cout << i << " " << j << endl;
      }
    }
  }
  
}

Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007


#A
def A():
    return

#B
def B():
    return

#C
def C():
    return

#D
def D():
    h,w = LI()
    s = SR(h)
    white = 0
    for i in range(h):
        white += s[i].count(".")
    bfs_map = [[-1 for i in range(w)] for j in range(h)]
    d = [[0,1],[0,-1],[1,0],[-1,0]]
    bfs_map[0][0] = 0
    q = deque()
    q.append([0,0])
    while q:
        y,x = q.popleft()
        for dy,dx in d:
            y_ = y+dy
            x_ = x+dx
            if 0 <= y_ < h and 0 <= x_ < w:
                if s[y_][x_] == "." and bfs_map[y_][x_] < 0:
                    bfs_map[y_][x_] = bfs_map[y][x]+1
                    q.append([y_,x_])
    if bfs_map[h-1][w-1] < 0:
        print(-1)
        quit()
    print(white-1-bfs_map[h-1][w-1])
#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == "__main__":
    D()


Measured memory_bytes: 40816
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <stack>
#include <cctype>
#include <complex>
#include <vector>
#include <algorithm>
#include <cassert>

using namespace std;


bool solve(){
	while(1){
		int n;
		cin>> n;
		if(!n) break;
		int ans=0;
		for(int i=0;i<n/4;i++){
			int in;
			cin>> in;
			ans += in;
		}
		cout<< ans<< endl;
	}

	return true;
}

int main(){
	cout.setf(ios::fixed);
	cout.precision(10);
	solve();

	return 0;
}

 

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

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  
  if(a>b){
    swap(a,b);
  }
  if(b>c){
    swap(b,c);
  }
  if(a>c){
    swap(a,c);
  }
  
  if(a+b==c){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

  

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ld long double
#define ll long long
#define st first
#define nd second
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define pb push_back
using namespace std;

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int n;
	cin>>n;
	int x = (n-1) / 1000 + 1;
	cout<< x * 1000 - n;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
int main(){
  string S,T;
  cin>>S>>T;
  int a=S.size()-T.size(), b=T.size(), counter=0;
  for(int i=0;i<=a;i++){
    int counter2=0;
    for(int j=0;j<b;j++){
      if(S[j+i]==T[j])counter2++;
    }
    if(counter2>counter)counter=counter2;
  }
  int c=T.size()-counter;
  cout<<c<<endl;
  return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
#define REP(i, init, n) for(int i = (int)(init); i < (int)(n); i++)

#define vi vector<int>
#define vl vector<long>
#define vvi vector<vector<int>>
#define vvl vector<vector<long>>
#define pint pair<int, int>
#define plong pair<long, long>

int main() {
    int N, M;
    cin>>N>>M;
    vvi G(N);
    REP(i, 0, M){
        int a, b;
        cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    int count = 0;
    queue<vvi> que;
    que.push({{0}, {0}});
    while(!que.empty()){
       auto cur = que.front(); que.pop();
       int v = cur[0][0];
       vi curArray = cur[1];
       if(curArray.size() == N){
           count++;
//           REP(i, 0, curArray.size()) cout << curArray[i] << " ";
//           cout << endl;
           continue;
       }
       for(int x: G[v]){
           auto itr = find(curArray.begin(), curArray.end(), x);
            if(distance(curArray.begin(), itr) == curArray.size()){
                vi newArray = curArray;
                newArray.push_back(x);
                que.push({{x}, newArray});
            }
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 1024
import math
a,b,h,m = map(int, input().split())
anga = 30 * h + m / 2
angb = 6 * m
she = abs(min(anga - angb, 360 - (anga - angb)))
if she == 90:
  print(math.sqrt(a ** 2 + b ** 2))
elif she == 180:
  print(a + b)
else:
  length = math.sqrt(a ** 2 + b ** 2 - 2 * a * b * math.cos(math.radians(she)))
  print(length)

Measured memory_bytes: 9488
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
const string ALPHABET = "abcdefghijklmnopqrstuvwxyz";
// 文字列 T の 先頭から, 順に, 文字列 S を 1グーゴル個連結した文字列(以下, S'と略記)中に, 出現する位置 を 保存.
LL dp[111111];
// 文字列 S の 各文字 の 出現位置 を 保管.
vector<vector<LL>> sPos(26);

int main(){
    
    // 1. 入力情報取得.
    char S[111111], T[111111];
    scanf("%s %s", S, T);
    int sl = strlen(S);
    int tl = strlen(T);
    
    // 2. 各文字の出現回数を保存.
    map<char, int> ms, mt;
    for(int i = 0; i < ALPHABET.size(); i++) ms[ALPHABET[i]] = 0, mt[ALPHABET[i]] = 0;
    for(int i = 0; i < sl; i++){
        ms[S[i]]++;
        int index = S[i] - 'a';
        sPos[index].push_back(i + 1);
    }
    for(int i = 0; i < tl; i++) mt[T[i]]++;
    // for(int i = 0; i < 26; i++){
    //     for(auto &p : sPos[i]) printf("%lld ", p);
    //     printf("\n");
    // }
    
    // 3. 存在しないケースを出力.
    // 文字列 S に 存在しない文字が, 文字列 T に 含まれている場合.
    for(auto &p : mt){
        char c = p.first;
        if(ms[c] == 0 && mt[c] > 0){
            printf("%d\n", -1);
            return 0;
        }
    }
    
    // 4. dp更新.
    // ex.
    // S = contest
    // T = sentence
    // -> 以下のように考える.
    // 文字列 T の 各文字 について, 文字列 S で, 何番目 を 使っているか見る.
    // s: 6
    // e: 5 -> 12
    // n: 3 -> 10 -> 17
    // t: 4 ->  7 -> 11 -> 14 -> 18
    // e: 5 -> 12 -> 19
    // n: 3 -> 10 -> 17 -> 24
    // c: 1 ->  8 -> 15 -> 22 -> 29
    // e: 5 -> 12 -> 19 -> 26 -> 33
    // -> 上記から, 33文字 と 判明.
    LL bef = 0; // 前回出現位置.
    for(int i = 0; i < tl; i++){
        // 今回チェックする文字列 T 中 の 文字 c.
        char c = T[i];
        int index = c - 'a';
        
        // 文字列 S 中 の 文字 c に関する出現位置情報 … sPos[index].
        // 今回出現位置 は 前回出現位置 から 逆算.
        LL tmp = lower_bound(sPos[index].begin(), sPos[index].end(), (bef % sl + 1)) - sPos[index].begin();
        LL cPos = 0;
        if(tmp == sPos[index].size()) cPos = (bef / sl + 1) * sl + sPos[index][0]; // 末尾なら, 次のサイクルの最初の要素を設定.
        else                          cPos = (bef / sl) * sl     + sPos[index][tmp];
        
        // 上記までで計算した位置を元に, dp を 更新.
        dp[i] = cPos;
        
        // 前回情報更新.
        bef = cPos;
    }
    
    // 5. 出力 ～ 後処理.
    // for(int i = 0; i < tl; i++) printf("%lld ", dp[i]);
    // printf("\n");
    printf("%lld\n", dp[tl - 1]);
    return 0;
    
}

Measured memory_bytes: 2336
#include<stdio.h>

int main(){
  int i,N,j,n=0,num,A[100];

  scanf("%d",&N);
  for(i = 0; i < N; i++) scanf("%d",&A[i]);

  for(i = 0; i < N; i++){
    for(j = N - 1; j > i ; j--){
      if(A[j] < A[j-1]){
	num = A[j-1];
	A[j-1] = A[j];
	A[j] = num;
	n++;
      }
    }
  }
  for(i = 0; i < N-1; i++)   printf("%d ",A[i]);
    printf("%d",A[N-1]);
  printf("\n%d\n",n);
  
}



Measured memory_bytes: 2084
/*
 * ALDS1_5_D.cpp
 *
 *  Created on: Apr 30, 2018
 *      Author: 13743
 */

#include<cstdio>


long mergeCount(int* A, int l, int r) {
	if(l+1 == r) {
		return 0;
	}
	int mid = (l + r) / 2;
	long c1 = mergeCount(A, l, mid);
	long c2 = mergeCount(A, mid, r);
	int n1 = mid - l;
	int n2 = r - mid;
	int A1[n1+1];
	int A2[n2+1];
	A1[n1] = 1000000001;
	A2[n2] = 1000000001;
	for(int i=0; i<n1; i++) {
		A1[i] = A[l+i];
	}
	for(int i=0; i<n2; i++) {
		A2[i] = A[mid+i];
	}
	int i1=0, i2=0;
	long cc = 0;
	for(int i=0; i<r-l; i++){
		if(A2[i2] < A1[i1]) {
			cc += n1 - i1;
			A[l+i] = A2[i2];
			i2++;
		}
		else {
			A[l+i] = A1[i1];
			i1++;
		}
	}
	return c1 + c2 + cc;
}

int main() {
	int n;
	int A[200000];

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

	long cnt = mergeCount(A, 0, n);

	printf("%ld\n", cnt);
}





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

int main() {
  
  int X,a,b,c;
  cin >> X;
  
  a = X / 500;  //500円玉の枚数
  b = X % 500;  //500円玉に換金した後の余り
  c = b / 5;  //5円玉の枚数
  
  cout << a * 1000 + c * 5 << endl;
  
}

Measured memory_bytes: 256