akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
    #include <math.h>

    using namespace std;
    typedef long long ll;
    typedef unsigned long long ull;
    # define M_PI  3.14159265358979323846


    const int M=1e9+7;
    long long mod(long long x){
        return ((x%M + M)%M);
    }
    long long add(long long a, long long b){
        return mod(mod(a)+mod(b));
    }

    int maxN=2e5+5;
    int n,k;
    vector<int>a(maxN);

    bool isValid(int mid){
        int kk=k;
        if(mid==0)
            return false;
        for(int i=0;i<n;i++){
            if(a[i]<=mid)
                continue;
            int t=a[i]/mid;
            kk-=(int)t; 
        }
        return (kk>=0);
    }
    void solve(){
        cin>>n>>k;
        for(int i=0;i<n;i++)
            cin>>a[i];
        int i=0,j=1e9+10;
        while(i<j){
           int mid=i+(j-i)/2;
            if(isValid(mid)){
                j=mid;
            }
            else
                i=mid+1;
        }
        cout<<i;
    }
    int main(){
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        cout<<fixed;
        cout<<setprecision(10);
//        freopen("timber_input.txt", "r", stdin);
//        freopen("timber_output.txt", "w", stdout);
        int t=1;
//        cin>>t;
        for(int i=1;i<=t;i++){
//            cout<<"Case #"<<i<<": ";
            solve();
        }
        return 0;
    }


Measured memory_bytes: 3908
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define INF 100000000
#define rep(i,s,n) for (int i = (int)(s); i < (int)(n); i++)
ll mod = 1000000007;

int main(){
    ll a,b,c,d;
	cin>>a>>b>>c>>d;
	ll l = c*d/__gcd(c,d);
	a--;
	ll ans = b-a+1-((b/c-a/c)+(b/d-a/d)-(b/l-a/l));
	ans--;
	a++;
	if (a==b){
		int x = a%c!=0&&a%d!=0?1:0;
		cout<<x<<endl;
	}else{
		cout<<ans<<endl;
	}
}

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

using namespace std;

const int N = 2e5 + 5;

struct query {
    int type , side;
    char c;
} info[N];

string s;

void go (int i , bool rev) {
    if (i == -1) {
        if (rev)
            reverse(s.begin() , s.end());
        cout << s;
        return;
    }

    if (info[i].type == 1) {
        rev ^= 1;
        go(i - 1 , rev);
    } else {
        info[i].side ^= rev;
        if (info[i].side) {
            go(i - 1 , rev);
            cout << info[i].c;
        } else {
            cout << info[i].c;
            go(i - 1 , rev);
        }
    }
}

int main() {
    ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
#ifdef LOCAL
    freopen("input.in" , "r" , stdin);
#endif
    int q;
    cin >> s >> q;

    for (int i = 0 ;i < q ;i++) {
        cin >> info[i].type;
        if (info[i].type == 2) {
            cin >> info[i].side >> info[i].c;
            info[i].side--;
        }
    }

    go(q - 1 , 0);
}


Measured memory_bytes: 15492
#include <bits/stdc++.h>
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define nyan "(=^･ω･^=)"
#define mkp make_pair
#define lP pair<ll, ll>
#define iP pair<int,int>
typedef long long ll;
using namespace std;

int N, h[100], cnt;

int main() {
	cin >> N;
	for (int i = 0; i != N; ++i) {
		cin >> h[i];
	}
	for (int i = 0; i != N; ++i) {
		if(h[i]){
			++cnt;
			for (int j = i; j != N; ++j) {
				if (h[j]) {
					--h[j];
				}
				else break;
			}
			--i;
		}
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
S = input()

def do_eval(s) :
    res = 0
    am_flg = 1
    
    for i in list(s): 
        if i == '+' :
            am_flg = 1
        elif i == '-' :
            am_flg = -1
        else :
            res += int(i) * am_flg
            
    return res    

A, B, C, D = list(S)[0], list(S)[1], list(S)[2], list(S)[3]
evaled = False 

for i in list('+-') :
    for j in list('+-') :
        for k in list('+-') :
            toeval = A + i + B + j + C + k + D
            
            if do_eval(toeval) == 7 :
                print(toeval + "=7")
                evaled = True
                break
        if evaled == True :
            break
    if evaled == True :
        break
                
            
    

Measured memory_bytes: 3064
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
int main()
{
	int first,first_num, second, second_num;
	int i, n,a;
	int a1, a2;

	cin >> n;
	cin >> a1;
	cin >> a2;

	if (a1 > a2) {
		first = a1;
		second = a2;
		first_num = 0;
		second_num = 1;
	}
	else {
		first = a2;
		second = a1;
		first_num = 1;
		second_num = 0;
	}

	for (i = 2; i < n; i++) {
		cin >> a;
		if (first == a) {
			second = first;
			second_num = first_num;
			first_num = i;
		}
		else if (first < a) {
			second = first;
			second_num = first_num;
			first = a;
			first_num = i;
		}
		else if (second < a) {
			second = a;
			second_num = i;
		}
	}

	for (i = 0; i < n; i++) {
		if (i == first_num) {
			cout << second << endl;
		}
		else {
			cout << first << endl;
		}
	}

	return 0;
}


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

int main(){
  string n;
  cin >> n;
  
  if(n[0] == '1')cout << '9';
    else cout << 1;
  if(n[1] == '1')cout << '9';
    else cout << 1;
  if(n[2] == '1')cout << '9';
    else cout << 1;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;

class Main{
    public static void main(String args[]){
        try{
            BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));
            String s=reader.readLine();
            StringTokenizer st=new StringTokenizer(s," ");
            
            String a=st.nextToken();
            String b=st.nextToken();
            String c=st.nextToken();
            
            int an=Integer.parseInt(a);
            int bn=Integer.parseInt(b);
            int cn=Integer.parseInt(c);
            int min,mid,max;
            
            if(an>bn&&an>cn){
                max=an;
                if(bn>cn){
                    mid=bn; min=cn;
                }else{
                    mid=cn; min=bn;
                }
            }else if(bn>cn){
                max=bn;
                if(an>cn){
                    mid=an; min=cn;
                }else{
                    mid=cn; min=an;
                }
            }else{
                max=cn;
                if(an>bn){
                    mid=an; min=bn;
                }else{
                    mid=bn; min=an;
                }
            }
            
            System.out.println(min+" "+mid+" "+max);
        }catch(IOException e){
            System.out.println(e);
        }
    }
}

Measured memory_bytes: 24228
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;

int gcd(int a, int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int lcm(int a, int b){
    return a/gcd(a,b)*b;
}

vector<vi> g;

pii dfs(int now, int par){
    pii ret = pii(1,1);//黒、白
    // ret.first は sum(child.second)
    // ret.second は sum(child.first + child.second)
    rep(i,g[now].size())if(g[now][i] != par){
        pii child = dfs(g[now][i],now);
        (ret.first *= child.second) %= MOD;
        (ret.second *= child.first + child.second) %= MOD;
    }
    return ret;
}

signed main(void) {
    int n;
    cin >> n;
    g = vector<vi>(n);
    rep(i,n-1){
        int a,b;
        cin >> a >> b;
        a--,b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    pii ans = dfs(0, -1);
    cout << (ans.first + ans.second) % MOD << endl;
}


Measured memory_bytes: 12672
#include <bits/stdc++.h>
using namespace std;
//#define LOCAL
#define fastIO ios::sync_with_stdio(0), cin.tie(0)
#define endl '\n'
#define forn(i,a,b) for(int i=a;i<b;i++)
#define ft first
#define sd second
#define sz size()
#define pb push_back
#define pob pop_back()
#define pf push_front
#define pof pop_front()
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<char,char> pcc;
typedef pair<double,double> pdd;
typedef pair<long long,long long> pll;
//cout << fixed << setprecision(12) <<x<<endl;

int main(){
fastIO;
#ifdef LOCAL
     freopen("int.txt", "r", stdin);
#endif

int n,ans=1;
cin>>n;

for(int i=1;i<=3;i++){
    ans*=n;
}
cout<<ans<<endl;
}



Measured memory_bytes: 3644
# -*- coding: utf-8 -*-
import sys
from operator import itemgetter
from fractions import gcd
from math import ceil, floor, sqrt
from copy import deepcopy
from collections import Counter, deque
import heapq
from functools import reduce
# local only
# if not __debug__:
#     fin = open('in_1.txt', 'r')
#     sys.stdin = fin
# local only
sys.setrecursionlimit(200000)
input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def li(): return list(input().rstrip())
def debug(*args, sep=" ", end="\n"): print("debug:", *args, file=sys.stderr, sep=sep, end=end) if not __debug__ else None
def exit(*arg): print(*arg); sys.exit()
# template




def main():
    A, B, C = mi()
    if (A * B) % 2 == 0 and (B * C) % 2 == 0 and (C * A) % 2 == 0:
        print('Tem')
    else:
        print('Hom')

if __name__ == '__main__':
    main()



Measured memory_bytes: 6884
#ifdef __APPLE__
#include "bits:stdc++.h"
#else
#include <bits/stdc++.h>
#endif
#define REPP(i,j,n) for(LL i=j;i<n;++i)
#define REP(i,n) REPP(i,0,n)
#define F first
//#define S second

using namespace std;
typedef long long LL;
typedef pair<LL,LL> PLL;

auto scan = []{static LL a;scanf("%lld",&a);return a;};
#define MAXN 1000000
LL front[26]={0},back[26]={0};
char s[MAXN];
LL in(){
  LL ans = 0;
  REP(i, 26){
    ans += (back[i] + 1)* back[i] / 2;
  }return ans;
}
int main(){
  scanf("%s",s);
  LL l = strlen(s),ans = l * ( l + 1)/2 + 1;
  REP(i,l)++back[s[i]-'a'];
  printf("%lld\n",ans - in());
}

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

static const int INF = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

int main() {
    u32 n;
    cin >> n;
    vector<int> v(n);
    for (auto &&a : v) cin >> a;
    sort(v.begin(), v.end());
    cout << v[n-1] - v[0] << "\n";
    return 0;
}


Measured memory_bytes: 384
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx")

#include <cstdio>
#include <algorithm>

using namespace std;

using int64 = long long;

template<class T> inline void fastin(T &num) {
  T c;
  num = 0;
  c = getchar_unlocked();
  for (; (c > 47 && c < 58); c = getchar_unlocked()) num = (num << 3) + (num << 1) + c - 48;
}

constexpr int64 INF = 1e18;

int main() {
  int n; int64 x; fastin(n); fastin(x);
  int64 a[n];
  for (int i = 0; i < n; ++i) fastin(a[i]);

  int64 dp[n][n]; fill(dp[0], dp[n], INF);

  for (int i = 0; i < n; ++i) {
    for (int move = 0; move < n; ++move) {
      int pos = (i + move) % n;
      dp[i][move] = min(dp[i][(move + n - 1) % n], a[pos]);
    }
  }

  int64 ans = INF;

  for (int move = 0; move < n; ++move) {
    int64 sum = 0;
    for (int j = 0; j < n; ++j) {
      sum += dp[j][move];
    }
    sum += move * x;
    ans = min(ans, sum);
  }

  printf("%lld\n", ans);

  return 0;
}

Measured memory_bytes: 31488
#include <iostream>

int main()
{
  int N, M, X;
  std::cin >> N >> M >> X;
  int A[100];
  for (int i=0; i<M; i++) std::cin >> A[i];
  int left = 0;
  int right = 0;
  int i;
  for (i=0; i<M && A[i]<X; i++) left++;
  for (; i<M; i++) right++;
  std::cout << std::min(left, right) << std::endl;
  return 0;
}


Measured memory_bytes: 3588
N=int(input())
A=list(map(int,input().split()))
B=A
for i in range(N):
  B[i]-=i+1
C=sorted(B)
if N%2==0:
  b=(C[int(N/2-1)]+C[int(N/2)])//2
else:
  b=C[int((N-1)/2)]
ans=0
for i in range(N):
  ans+=abs(C[i]-b)
print(ans)

Measured memory_bytes: 26180
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <queue>

using namespace std;


int main(){
  int n,m;
  cin >> n>> m;
  int a[n];
  int i;
  for(i=0;i<n;i++){
    cin >> a[i];
  }
  std::priority_queue<int> que;
  for(i=0;i<n;i++){
    que.push(a[i]);
  }

  for(i=0;i<m;i++){
    int t = que.top();
    t /=2;
    que.pop();
    que.push(t);
  }

  long long int sum = 0;
  for(i=0;i<n;i++){
    sum += que.top();
    que.pop();
  }

  cout << sum << endl;
}


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

int main()
{
    int H, N;
    cin>>H>>N;
    vector< pair<int,int> > v(N);
    vector<ll> dp(H + 1, 1000000000);
    dp[0] = 0;
    for(int i = 0; i < N; i++)
    {
        cin>>v[i].first >> v[i].second;
    }
    for(int i = 1; i <= H; i++)
    {
        for(int j = 0; j < N; j++)
        {
            dp[i] = min(dp[i], dp[max(i-v[j].first, 0)] + v[j].second);
        }
    }
    cout << dp[H] << endl;
}


Measured memory_bytes: 384
const lines=readlines()
function find(u,p)
	if u==p[u]
		u
	else
		p[u]=find(p[u],p)
	end
end
function f(N,M)
	parent=collect(1:N)
	size=ones(Int,N)
	for _=1:M
		a,b=map(x->find(parse(Int,x),parent),split(shift!(lines)))
		if a!=b
			if size[a]>size[b]
				parent[b]=a
				size[a]+=size[b]
			else
				parent[a]=b
				size[b]+=size[a]
			end
		end
	end
	[find(i,parent) for i=1:N]
end
function main()
	N,K,L=map(x->parse(Int,x),split(shift!(lines)))
	E=Pair{Int,Int}[]
	for (a,b)=zip(f(N,K),f(N,L))
		push!(E,a=>b)
	end
	D=Dict{Pair{Int,Int},Int}()
	for v=E
		D[v]=get(D,v,0)+1
	end
	for v=E
		println(D[v])
	end
end
main()

Measured memory_bytes: 176324
#include <bits/stdc++.h>
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define IFOR(i, m, n) for(int i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
const ll INF = 1e18;
/* テンプレートここまで */

int main() {
  ll a,b,c; cin >> a >> b >> c;
  cout << a+b+c -max({a,b,c}) << endl;
}


Measured memory_bytes: 764
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var arr=input.trim().split("\n");
var nq=arr.shift().split(" ").map(Number);
var str = arr.shift();
var a=[0,0];
var cnt=0;
for(var i=1;i<str.length;i++){
   if(str[i]=="C" && str[i-1]=="A")cnt++;
   a.push(cnt);
}
var ans=[];
for(var i=0;i<nq[1];i++){
   var lr=arr[i].split(" ").map(Number);
   ans.push(a[lr[1]]-a[lr[0]]);
}
console.log(ans.join("\n"));

Measured memory_bytes: 34852
#pragma region _head

#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<numeric>
#include<utility>

#pragma region _define

#define f(i,a,b) for(LL i=a;i<b;i++)
#define f_vI(v,n) f(i,0,n)cin>>v[i]
#define f_v2I(v1,v2,n) f(i,0,n)cin>>v1[i]>>v2[i]
#define f_v3I(v1,v2,v3,n) f(i,0,n)cin>>v1[i]>>v2[i]>>v3[i]
#define f_vO(v,n,option) f(i,0,n)cout<<v[i]<<option;
#define all(a) a.begin(),a.end()
#define size(s) s.size()
#define check() cout<<"! ! !"
#define endl "\n"
#define _y() cout<<"Yes"<<endl
#define _Y() cout<<"YES"<<endl
#define _n() cout<<"No"<<endl
#define _N() cout<<"NO"<<endl
#define INF 1<<29

#pragma endregion

#pragma region _using

using namespace std;

using LL = long long;
using st = string;
using vi = vector<LL>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vc = vector<char>;
using vs = vector<st>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvvb = vector<vvb>;
using si = stack<LL>;
using ss = stack<st>;
using pi = pair<LL, LL>;
using v_pi = vector<pi>;

#pragma endregion

#pragma region _graph

#define node 50  //グラフの最大位数　適宜変更
//bool graph[node][node]; bool visited[node] = { false };
#define link(a,b,m) f(i,0,m){cin>>a[i]>>b[i]; a[i]--; b[i]--; graph[a[i]][b[i]]=graph[b[i]][a[i]]=true;}

#pragma endregion

LL gcd(LL a, LL b) {
	LL r;
	while ((r = a % b) != 0) {
		a = b;
		b = r;
	}
	return b;
}
LL lcm(LL a, LL b) {
	return (a / gcd(a, b)*b);
}

//階乗計算
LL factorial(LL n) {
	LL a = 1, ret = 1;
	while (a < n) {
		a++;
		ret *= a;
		//ret %= 1000000007;
	}
	return ret;
}

#pragma endregion

/************************************************************************/
int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);

	int n, m;
	cin >> n >> m;
	vi A(n), B(n);
	f_v2I(A, B, n);
	v_pi p(n);
	f(i, 0, n) {
		p[i] = { A[i],B[i] };
	}
	sort(all(p));
	LL sum = 0;
	LL i = 0;
	LL memo;
	while (true) {
		sum += (p[i].first*p[i].second);
		m -= p[i].second;
		if (m <= 0) {
			memo = p[i].first;
			break;
		}
		i++;
	}
	sum -= (memo * m *(-1));
	cout << sum;
	return 0;
}

Measured memory_bytes: 3456
import java.io.*;
import java.util.*;
public class Main{
    public static void main(String[] args) throws IOException{
        Reader r = new Reader();        
        int N = r.i();
        int[] a = r.ii();
        Arrays.sort(a); 
        
        int[] count = new int[100000];
        ArrayList<Integer> element = new ArrayList<>();
        for(int i = 0; i < N;){
            int temp = a[i];
            while(i < N && temp == a[i]){
                count[temp]++;
                i++;
            }       
            element.add(temp);
        }
        
        Iterator<Integer> iterator = element.iterator();
        int top = element.get(0);
        int ans = count[top];
        try{
            ans += count[top-1]+count[top+1];
        } catch(ArrayIndexOutOfBoundsException e){}
        
        while(iterator.hasNext()){
            int x = iterator.next();
            try{
                int temp = count[x-1]+count[x]+count[x+1];
                if(ans < temp)
                    ans = temp;
            } catch(ArrayIndexOutOfBoundsException e){}
        }
        println(ans);
    }
    static void print(Object o){
        System.out.print(o.toString());
    }
    static void println(Object o){
        System.out.println(o.toString());
    }
    static int Int(String s){
        return Integer.parseInt(s);
    }
    static long Long(String s){
        return Long.parseLong(s);
    }
    static class Reader extends BufferedReader{
        Reader(){
            super(new InputStreamReader(System.in));
        }
        String s() throws IOException{
            return readLine();
        }
        String[] ss() throws IOException{
            return s().split(" ");
        }
        int i() throws IOException{
            return Int(s());
        }
        int[] ii() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            int[] ii = new int[size];
            for(int j = 0; j < size; j++) ii[j] = Int(ss[j]);
            return ii;
        }
        long l() throws IOException{
            return Long(s());
        }
        long[] ll() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            long[] ll = new long[size];
            for(int j = 0; j < size; j++) ll[j] = Long(ss[j]);            
            return ll;
        }
    }
}

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

#define MOD 1000000007
#define MAX 100005
#define ll long long
#define slld(t) scanf("%lld",&t)
#define sd(t) scanf("%d",&t)
#define pd(t) printf("%d\n",t)
#define plld(t) printf("%lld\n",t)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tr(container,it) for(typeof(container.begin()) it=container.begin();it!=container.end();it++)
#define mp(a,b) make_pair(a,b)
#define FF first
#define SS second
#define pb(x) push_back(x)
#define vi vector<int>
#define vpii vector<pii >
#define vll vector<ll>
#define clr(x) memset(x,0,sizeof(x))

using namespace std;

int main(){
	int a,b;
	cin>>a>>b;
	
	if(a<=0&&0<=b){
		printf("Zero");
		return 0;
	}
	
	if(a>0){
		printf("Positive");
		return 0;
	}
	
	b=max(1,-b);a=-a;
	
	int cnt=a-b+1;
	
	if(cnt%2==0){
		printf("Positive");
		return 0;
	}else{
		printf("Negative");
		return 0;
	}
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;


class Program
{
    static void Main(string[] args)
    {
        // 入力
        //var s = Console.ReadLine();

        long[] av = Console.ReadLine().Split().Select(long.Parse).ToArray();
        long[] bw = Console.ReadLine().Split().Select(long.Parse).ToArray();
        var t = long.Parse(Console.ReadLine());
        var ans = "YES";

        if (bw[0] < 0)
        {
            if (av[0] - av[1] * t > bw[0] - bw[1] * t) ans = "NO";
        }
        if (av[0] + av[1] * t < bw[0] + bw[1] * t) ans = "NO";
        if (av[0] == bw[0]) ans = "YES";

        // 出力
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 28228
#include <algorithm>
#include <complex>
#include <cstdlib>
#include <ctime>
#include <time.h>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <numeric>
#include <limits>
#include <type_traits>
#include <locale>

using namespace std;
#define SAY_YES cout << "YES" << endl;
#define SAY_Yes cout << "Yes" << endl;
#define SAY_NO cout << "NO" << endl;
#define SAY_No cout << "No" << endl;
#define IFYES(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "YES" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "NO" << endl;  \
    }
#define IFYes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "Yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "No" << endl;  \
    }
#define IFyes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "no" << endl;  \
    }
#define DEBUG_OUTPUT_ARRAY(XXX, ONE)                            \
    for (int i = 0; i < (ONE); i++)                             \
    {                                                           \
        cout << "DEBUG: i = " << i << " -> " << XXX[i] << endl; \
    }
#define DEBUG_OUTPUT_ARRAY2(XXX, ONE, TWO)                             \
    for (int i = 0; i < (ONE); i++)                                    \
    {                                                                  \
        cout << "<<< i = " << i << " >>>" << endl;                     \
        for (int j = 0; j < (TWO); j++)                                \
        {                                                              \
            cout << "DEBUG: j = " << j << " -> " << XXX[i][j] << endl; \
        }                                                              \
    }
#define DEBUG_OUTPUT_ARRAY2_BOX(XXX, ONE, TWO) \
    for (int i = 0; i < (ONE); i++)            \
    {                                          \
        cout << i << "  ";                     \
        for (int j = 0; j < (TWO); j++)        \
        {                                      \
            cout << XXX[i][j] << " ";          \
        }                                      \
        cout << endl;                          \
    }

typedef pair<long long int, long long int> pll;
typedef pair<long long int, pll> lpll;


const long long int mod = 998244353;
const long long int INF = 1e18;
const long double PI=3.14159265358979323; 
const long long int pl=1000000;

long long int N,M,K;
string S;
int main(){
    cout << fixed << setprecision(18);
    cin>>N;
    for(long long int i=1;(i-1)*(i)<2*N;i++){
    	M=i;
    }
    K=M*(M+1)/2-N;
    for(int i=1;i<=M;i++)
    {
    	if(i!=K){cout<<i<<endl;}
    }
}



Measured memory_bytes: 3572
#include <iostream>
using namespace std;
int main()
{
    int A, B, C;
    cin >> A >> B >> C;
    if ((A == B && B != C) || (B == C && C != A) || (C == A && A != B))
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>

int h, A[600000];

void maxHeapify(int i) {
    int l, r, largest;
    l = i * 2;
    r = l + 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) {
        std::swap(A[i], A[largest]);
        maxHeapify(largest);
    }
}

int main(void) {
    int i;
    scanf("%d", &h);
    for (i = 1; i <= h; i++) scanf("%d", &A[i]);

    for (i = h / 2; i >= 1; i--) maxHeapify(i);

    for (i = 1; i <= h; i++) printf(" %d", A[i]);
    printf("\n");

    return 0;
}

Measured memory_bytes: 2984
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <queue>
#include <sstream>
#include <fstream>
#include <cmath>
#include <cstring>

using namespace std;
#define int long long
const int mod = 1000000007;

char flag[1000][1000] = {};
int ks[1000][1000] = {};
int z[1000][1000][3] = {};
char base[2][2];
signed main()
{
	int ans = 0;
	int H, W; cin >> H >> W;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			cin >> flag[i][j];
		}
	}
	for (int i = 0; i < 2; i++) {
		for (int j = 0; j < 2; j++) {
			cin >> base[i][j];
		}
	}
	for (int i = 0; i < H - 1; i++) {
		for (int j = 0; j < W - 1; j++) {
			int tmp = 0;
			int x, y;
			int m = 0;
			for (int k = 0; k < 2; k++) {
				for (int l = 0; l < 2; l++) {
					if (flag[i + k][j + l] == base[k][l]) {
						tmp++;
					}
					else {
						x = i + k; y = j + l;
						if (base[k][l] == 'J') m = 0;
						else if (base[k][l] == 'O') m = 1;
						else m = 2;
					}
				}
			}
			if (tmp == 4) {
				ans++;
				for (int k = 0; k < 2; k++) {
					for (int l = 0; l < 2; l++) {
						ks[i + k][j + l]++;
					}
				}
			}
			else if (tmp == 3) z[x][y][m]++;
		}
	}
	int tmp = 0;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			for (int k = 0; k < 3; k++) {
				if (z[i][j] != 0) {
					tmp = max(tmp, z[i][j][k]);
				//	cout << i << " " << j << endl;
				}
			}
		}
	}
	cout << ans+tmp << endl;
}

Measured memory_bytes: 35312
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)

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

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

    int N;
    cin>>N;
    vector<int> hs(N);
    rep(i, N) cin>>hs[i];

    vector<int> dp(N);
    dp[1] = dp[0] + abs(hs[1] - hs[0]);
    rep(i, N - 2) {
        dp[i + 2] = min(dp[i + 1] + abs(hs[i + 2] - hs[i + 1]), dp[i] + abs(hs[i + 2]  - hs[i]));
    }
    cout<<dp[N - 1]<<endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

string longlong_add (string str1, string str2 )
{
	string res = "";
	
	reverse (str1.begin(), str1.end() );
	reverse (str2.begin(), str2.end() );
	int len1 = str1.length();
	int len2 = str2.length();

	while (len1 != len2 ){
		if (len1 < len2 ){
			str1 += '0';
			len1 = str1.length();
		}else if (len1 > len2 ){
			str2 += '0';
			len2 = str2.length();
		} // end if
	} // end while

	bool carry = false;
	for (int i = 0; i < len1; i++ ){
		int num1 = str1[i] - '0';
		int num2 = str2[i] - '0';
		int sum = num1 + num2;

		sum += (carry ? 1 : 0 );

		if (sum < 10 ){
			res += sum + '0';
			if (carry){
				carry = false;
			} // end if
		}else{
			sum %= 10;
			res += sum + '0';
			carry = true;
		} // end if
	} // end for

	if (carry ){
		res += '1';
	} // end if

	reverse (res.begin(), res.end());

	return res;
}

int main()
{
//	cut here before submit 
//	freopen ("testcase.NB", "r", stdin );
	int n;
	scanf ("%d", &n );
	rep (i, n ){
		string a1, a2;
		cin >> a1 >> a2;
		bool ok = true;
		if (a1.length() > 80 && a2.length() > 80 ){
			ok = false;
		} // end if
		string add = longlong_add (a1, a2 );
		if (add.length() > 80 ){
			ok = false;
		} // end if
		if (ok ){
			cout << add << endl;		
		}else{
			printf ("overflow\n" );
		} // end if
	} // end rep

	return 0;
}

Measured memory_bytes: 1244
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
  int N;
  cin >> N;
  long long x[105], y[105], h[105];
  long long ans[105][105] = {0};
  for(int i = 0; i < N; i++){
    cin >> x[i] >> y[i] >> h[i];
  }

  int flag = 0;
  for(int k = 0; k < N; k++){
    if(h[k] == 0) continue;
    for(int i = 0; i <= 100; i++){
      for(int j = 0; j <= 100; j++){
        long long H;
        //H = max( abs(x[k] - i) + abs(y[k] - j) + h[k], 0LL);//中心座標 i, jで高さH k番目の情報
        H =abs(x[k] - i) + abs(y[k] - j) + h[k];
        if(flag == 0){
          ans[i][j] = H;
        }else{
          if(ans[i][j] == H){

          }else{
            ans[i][j] = -1;
          }
        }
      }
    }
    flag = 1;
  }
  for (int k = 0;k < N; ++k){
    for(int i = 0; i <= 100; i++){
      for(int j = 0; j <= 100; j++){
        if(h[k] == 0){
          if((abs(x[k] - i) + abs(y[k] - j)) < ans[i][j]){
            ans[i][j] = -1;
          }
        }
      }
    }
  }
  for(int i = 0; i <= 100; i++){
    for(int j = 0; j <= 100; j++){
      if(ans[i][j] != -1){
        cout << i << " " << j << " " << ans[i][j] << endl;
      }
    }
  }

  return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#include<iostream>
using namespace std;
#define int long long int
#define ld long double
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define removeDuplicates(a) a.resize(unique(all(a))-a.begin())
#define endl '\n'	
#define setbits(x) (__builtin_popcount(x))
int mod=1000000007;
int INF64=mod*mod+1;

struct item{
	int val;
	int op;
};

const int NOP=0;									// modify
const int NEU=0;									// modify

class segTree{
	int sz;
	vector<item> arr;

public:
	segTree(int n){
		sz=1;
		while(sz<n)	sz*=2;
		arr.resize(2*sz,{0,0});
	}

	item merge(item one, item two){
		item temp;
		temp.op=NOP;
		
		temp.val=max(one.val,two.val);											// modify
		return temp;
	}

	void updateIndex(int i, int v, int x, int lx, int rx){
		if(lx==rx){
			arr[x]={v,0};										// modify
			return;
		}

		int m=(lx+rx)/2;
		if(i<=m)
			updateIndex(i,v,2*x+1,lx,m);
		else
			updateIndex(i,v,2*x+2,m+1,rx);

		arr[x]=merge(arr[2*x+1],arr[2*x+2]);
	}

	void updateIndex(int i, int v){
		updateIndex(i,v,0,0,sz-1);
	}

	int queryRange(int l, int r, int x, int lx, int rx){
		// propagate(x,lx,rx);
		if(l>rx||lx>r)	return NEU;
		if(lx>=l&&rx<=r)	return arr[x].val;

		int m=(lx+rx)/2;
		return max(queryRange(l,r,2*x+1,lx,m),queryRange(l,r,2*x+2,m+1,rx));			//modify
	}

	int queryRange(int l, int r){
		return queryRange(l,r,0,0,sz-1);			//modify
	}
};

void solve(){
	int n,k;
	cin>>n>>k;

	segTree st(300001);
	int ans=1;

	while(n--){
		int a;
		cin>>a;
		int res=st.queryRange(max(0LL,a-k-1),min(300000LL,a+k-1));
		ans=max(ans,res+1);
		st.updateIndex(a-1,res+1);
	}

	cout<<ans;
}

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

	int T;
	// cin>>T;
	T=1;
	for(int i=1;i<=T;i++){
		// cout<<"Case #"<<i<<": ";
		solve();
	}
	cerr<<"Time : "<<1000*((double)clock())/(double)CLOCKS_PER_SEC<<"ms\n";
}

Measured memory_bytes: 19580
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>

using ll = long long;

using namespace std;

#define MAX 10000000

int main() {
    while (true) {
        int m, n;
        cin >> m >> n;
        vector<bool> check(MAX, false);
        if (m == 0 && n == 0) break;
        for (int i=m; i<MAX; i++) {
            if (check[i]) continue;
            if (n == 0) {
                cout << i << '\n';
                break;
            }
            n--;
            for (int k=1; k*i<MAX; k++) {
                check[k*i] = true;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 4232
from bisect import bisect_left, bisect_right

N=input()
A=map( int, raw_input().split() ) 

for i in range(N-1):
	A[i+1]+=A[i]


def nibutan(l,h):
	if l==0:
		t=(A[h]+1)/2
	else:
		t=(A[h]-A[l]+1)/2+A[l]

	for j in range(30):
		m=(h+l)/2
		if A[m]<t:
			l=m
		else:
			h=m
	if abs(A[h]-t)<abs(t-A[l]):
		return h
	else:
		return l

ans=float("inf")
for i in range(1,N-2): 
	m1=nibutan(0,i)
	x1=A[m1]
	x2=A[i]-A[m1]

	m2=nibutan(i,N-1)
	x3=A[m2]-A[i]
	x4=A[-1]-A[m2]

	x_min=min(x1,x2,x3,x4)
	x_max=max(x1,x2,x3,x4)

	ans=min(ans, x_max-x_min)


print ans

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

typedef long long ll;

const int INF = 100000000;

int main() {
    ll N;
    int num;
    cin >> N;

    for (int i = (int)sqrt(N); i >= 1; i--) {
        if (N % i == 0) {
            num = N/i;
            break;
        }
    }

    int ans = 0;
    while (num > 0) {
        ans++;
        num /= 10;
    }

    cout << ans << endl;
}


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

int main() {
  int A,B;
  cin >> A >> B;
  int count = 0;
  for(int i=A; i<=B; i++){
    int a1 = i/10000;
    int a2 = i%10000/1000;
    int a3 = i%1000/100;
    if(i == a1*10000 + a2*1000 + a3*100 + a2*10 + a1){
      count ++;
    }
  }
  cout << count << endl;
}

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

int main() {
  int K, X;
  cin >> K >> X;
  for (int i = X - K + 1; i <= X + K - 1; i++) {
    cout << i << " ";
  }
  cout << endl;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(auto i = (a); i < (b); i++)
#define iter(it,c) for(auto it = (c).begin(); it != (c).end(); ++it)
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
const int INF = ~(1<<31);
#define fs first
#define sc second
#define pb push_back

const double EPS = 1e-9;
const double pi = acos(-1);
typedef unsigned long long ull;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
template <class T> T smod(T a, T b) {
    return (a % b + b) % b;
}

int main() {
    cin.sync_with_stdio(false);
    double r;
    cin >> r;
    cout << setprecision(15) << fixed << 2*r*pi << endl;
    return 0;
}


Measured memory_bytes: 3808
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
    using namespace std;
 
int GCD(int a, int b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}
 
    int main(){
      int a[3];
      rep(i,3) cin >> a[i];
      sort(a,a+3);
      if(a[0]+a[1]==a[2]) cout << "Yes" << endl;
      else cout << "No" << endl;
      return 0;}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define lln long long int
#define llu unsigned lln
#define sc(n) scanf("%d",&n);
#define scl(n) scanf("%lld",&n);
#define scd(n) scanf("%lf",&n);
#define pf(res) printf("%d\n",res);
#define pfl(res) printf("%lld\n",res);
#define pfd(res) printf("%lf\n",res);
#define maxii 100005
using namespace std;
typedef pair<int,int> pii;
typedef pair<lln,lln> pll;
typedef vector<int> vi;
typedef vector<lln> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;


int arr[maxii];
int arr2[maxii];
int gcd(int a,int b)
{
    if(b==0){
      return a;
     }
    return gcd(b,a%b);
}
int lcm(int a,int b)
{
    int res=(a*b)/gcd(a,b);
    return res;
}
int po(int a,int b)
{
    int res=1;
    while(b)
    {
        if(b%2!=0)
        {
            res*=a;
            b--;
        }
        else
        {
            a*=a;
            b/=2;
        }
    }
    return res;
}

lln modMul(lln  a, lln b,lln mod){
    lln ans = 0;
    a = a % mod;
    while (b > 0){
        if ( b % 2 )ans = (ans%mod+ a%mod) % mod;
        a = (a%mod * 2%mod) % mod;
        b /= 2;
    }
    return ans % mod;
}
lln powerMod(lln a,lln b,lln mod){
	if(b==0)return 1LL%mod;
	lln x=powerMod( a,b/2,mod );
	x = ( x%mod * x%mod ) % mod;
	if( b%2==1 )x = ( x%mod * a%mod ) % mod;
	return x%mod;
}

int main()
{
   int n;
   sc(n)
   int tle=0,re=0,wa=0,ac=0;
   for(int i=0;i<n;i++)
   {
       string a;
       cin>>a;
       if(a=="AC")ac++;
       else if(a=="RE")re++;
       else if(a=="TLE")tle++;
       else wa++;
   }
   printf("AC x %d\n",ac);
   printf("WA x %d\n",wa);
   printf("TLE x %d\n",tle);
   printf("RE x %d\n",re);

}






Measured memory_bytes: 3788
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstdint>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <chrono>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#include <random>
#include <utility>
#include <limits>
#include <list>
#include <type_traits>

/* template start */
 
#define rep(i, a, b) for (long long i = (a); (i) < (b); (i)++)
#define all(i) i.begin(), i.end()

#ifdef LOCAL
#define debug(...) std::cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

void debug_out(){std::cerr<<std::endl;}

template<typename Head,typename... Tail>
void debug_out(Head h,Tail... t){
  std::cerr<<" "<<h;
  if(sizeof...(t)>0)std::cout<<" :";
  debug_out(t...);
}
 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}

template<typename Num>
constexpr Num mypow(Num a, long long b) {
  if(b==0)return 1;
  if (a==0)return 0;
  Num x = 1;
  while (b > 0) {
    if(b & 1)x*=a;
    a*=a;
    b >>= 1;
  }
  return x;
}

/* template end */

using ll = long long;

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

  ll n;
  std::cin>>n;

  std::vector<ll> cnt(n+1,0);

  ll ans=0;
  rep(i,1,n+1){
    for(ll j=i;j<=n;j+=i)cnt[j]++;
    ans+=i*cnt[i];
  }

  std::cout<<ans<<"\n";

  return 0;
}

Measured memory_bytes: 81340
import sys
input = sys.stdin.readline
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
# A = [ int(input()) for _ in range(N) ]
##############################

L, R = map(int, input().split())

MOD2019 = 2019

ans = INF

right = min(R+1, L+2019)
for l in range(L, right):
    for r in range(l+1, right):
        ans = min(ans, (l*r) % MOD2019)

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

const char NL = '\n';
const int MOD = 1e9 + 7;

void solve()
{
    int n, k; cin >> n >> k;
    vector<int> v;
    for (int i = 0; i < n; ++i) {
        int h; cin >> h;
        v.push_back(h);
    }
    vector<int> dp(n, 0);
    for (int i = 1; i < n; ++i) {
        int minCost = INT_MAX;
        for (int j = max(0, i - k); j < i; ++j) {
            int cost = dp[j] + abs(v[i] - v[j]);
            minCost = min(minCost, cost);
        }
        dp[i] = minCost;
    }
    cout << dp[n - 1] << NL;
}

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

Measured memory_bytes: 4240
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 1e9;
const LL LLINF = 1e16;

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    vector<int> b = a;
    sort(all(b));
    reverse(all(b));
    rep(i, n){
        cout << (a[i] == b[0] ? b[1] : b[0]) << endl;
    }
}

Measured memory_bytes: 3200
package main

import (
	"bufio"
	_ "container/heap"
	"fmt"
	"os"
	_ "sort"
	"strconv"
)

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func lcm(a, b int) int {
	return a / gcd(a, b) * b
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
const MOD = int(1e+9) + 7
const INF = 1 << 60

type Node struct {
	x, y int
}

type Queue struct {
	arr []Node
}

func (q *Queue) push(v Node) {
	q.arr = append(q.arr, v)
}

func (q *Queue) pop() Node {
	res := q.arr[0]
	q.arr = q.arr[1:]
	return res
}

func (q *Queue) isEmpty() bool {
	return len(q.arr) == 0
}

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	defer wtr.Flush()
	H, W := sc.nextInt(), sc.nextInt()
	G := make([][]rune, H)
	count := 0
	for i := 0; i < H; i++ {
		G[i] = sc.nextRuneSlice()
		for j := 0; j < W; j++ {
			if G[i][j] == '.' {
				count++
			}
		}
	}
	queue := Queue{}
	dx := []int{0, 0, 1, -1}
	dy := []int{1, -1, 0, 0}
	var visited [51][51]int
	for i := 0; i < 51; i++ {
		for j := 0; j < 51; j++ {
			visited[i][j] = -1
		}
	}
	bfs := func(node Node) {
		for i := 0; i < 4; i++ {
			nx, ny := node.x+dx[i], node.y+dy[i]
			if nx < 0 || W <= nx || ny < 0 || H <= ny || G[node.y][node.x] == '#' {
				continue
			}
			if visited[nx][ny] > 0 {
				continue
			}
			visited[nx][ny] = visited[node.x][node.y] + 1
			queue.push(Node{nx, ny})
		}
	}
	visited[0][0] = 1
	queue.push(Node{0, 0})
	for !queue.isEmpty() {
		bfs(queue.pop())
	}

	if visited[W-1][H-1] == -1 {
		fmt.Fprintln(wtr, -1)
	} else {
		fmt.Fprintln(wtr, count-visited[W-1][H-1])
	}
}


Measured memory_bytes: 896
from itertools import product
N, M = map(int, input().split())
S = []
for m in range(M):
    s = list(map(int, input().split()))
    S.append(s[1:])
    
p = list(map(int, input().split()))

ans = 0
for c in product([0, 1], repeat = N):
    ok = True
    for m in range(M):
        sm = 0
        for k in S[m]:
            sm += c[k - 1]
        if sm % 2 != p[m]:
            ok = False
            break
    if ok:
        ans += 1
print(ans)



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

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

int N,Q;
ll A[101010];
ll S[101010];
ll T[101010];
ll X;

int ok(int v) {
	if(v>N) return 0;
	
	int aa=(v+1)/2;
	int re=N-aa;
	int x=lower_bound(A,A+N,X-(A[re]-X))-A;
	return (x+v<=N);
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>Q;
	FOR(i,N) {
		cin>>A[i];
		S[i+1]=S[i]+A[i];
		T[i+1]=(i>=1?T[i-1]:0)+A[i];
	}
	
	while(Q--) {
		cin>>X;
		int turn=0;
		for(i=20;i>=0;i--) {
			if(ok(turn+(1<<i))) turn+=1<<i;
		}
		
		int a=(turn+1)/2;
		if(turn%2) turn++;
		
		ll ret=S[N]-S[N-turn/2];
		if(turn<N) ret+=T[N-turn];
		
		cout<<ret<<endl;
	}
}


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


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

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

typedef long long ll;

const int INF = 1 << 30;
const ll LLINF = 1LL << 62;

int mod = 1000000007;

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

    int A, B; cin >> A >> B;
    int inc = A-1;
    int ans = 1;
    while(A < B){
        A += inc;
        ans++;
    }
    if(B == 1) cout << 0 << endl;
    else cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
N, M, Q = map(int, input().split())

LR =[[0 for j in range(N+2)] for i in range(N+1)]
for i in range(M):
    L, R = map(int, input().split())
    LR[L][R] += 1
    LR[0][R] -= 1
    LR[L][N+1] -= 1
    LR[0][N+1] += 1

for i in range(1, N+1): #R方向への累積和
    for j in range(1, N+2):
        LR[i][j] += LR[i][j-1]
for i in range(N-1, -1, -1): #L方向への累積和
    for j in range(1, N+2):
        LR[i][j] += LR[i+1][j]

ans = []
for i in range(Q):
    p, q = map(int, input().split())
    ans.append(LR[p][q])

for i in range(Q):
    print(ans[i])

Measured memory_bytes: 10552