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

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

using namespace std;

long long dp[4001][5];

int main(){
	rep(k, 1001){
		rep(i, 4001){
			for(int j = 1; j <= 4; ++j){
				if(i == 0){
					dp[i][j] = 1;
				}
				else if(j == 1){
					dp[i][j] = i <= k;
				}
				else if(k == 0){
					dp[i][j] = 0;
				}
				else if(i > k){
					dp[i][j] = dp[i - 1][j] - dp[i - k - 1][j - 1] + dp[i][j - 1];
				}
				else{
					dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
				}
			}
		}
	}

	int n;
	while(scanf("%d", &n) != EOF){
		printf("%lld\n", dp[n][4]);
	}
	return 0;
}

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

int main(){
    using namespace std;
    unsigned long N, P, Q;
    cin >> N >> P >> Q;
    vector<long> C(N);
    for(auto& i : C)cin >> i;
    
    vector<long> D(N);
    for(size_t i = 0; i < N; ++i)D[i] = (Q - i) * P - C[i];
    sort(D.rbegin(), D.rend());
    
    long ans{accumulate(C.begin(), C.end(), 0L)}, ad{ans};
    for(unsigned long k = 0; k < N; ++k)ans = max(ad += 2 * k * P + D[k], ans);
    
    cout << ans << endl;
}


Measured memory_bytes: 10748
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <set>
#define INF 1e9+100
typedef long long ll;
using namespace std;
ll ans=INF;
int main()
{
	ll l,r;
	cin >> l >> r;
	
	if(r-l < 2019) {
		for(ll i=l; i<=r; i++) {
			for(ll j=i+1; j<=r; j++) {
				ll t = (i*j) % 2019;
				ans = min(t,ans);
			}
		}
	}else{
		ans = 0;
	}
	cout << ans <<endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_7_A
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
struct Node{
	int p,l,r;//親、最も左の子、右の兄弟
};
Node T[100001];
int N,depth[100001];
void print(int u){
	printf("node %d: parent = %d, depth = %d, ",u,T[u].p,depth[u]);
	if(T[u].p==-1) printf("root, ");
	else if(T[u].l==-1) printf("leaf, ");
	else printf("internal node, ");
	printf("[");
	for(int i=0,child=T[u].l;child!=-1;i++,child=T[child].r){
		if(i) printf(", ");
		printf("%d",child);
	}
	printf("]");
	kaigyo;
}
void rec(int u,int p){
	depth[u]=p;
	if(T[u].r!=-1) rec(T[u].r,p);
	if(T[u].l!=-1) rec(T[u].l,p+1);
}
int main(){
	scan(N);
	rep(i,N) T[i].p=T[i].l=T[i].r=-1;
	rep(i,N){
		int v,k;
		scan(v>>k);
		int prevchild=-1;
		rep(j,k){
			int child;
			scan(child);
			if(j==0) T[v].l=child;
			else T[prevchild].r=child;
			prevchild=child;
			T[child].p=v;
		}
	}
	int root;
	rep(i,N) if(T[i].p==-1) root=i;
	rec(root,0);//再帰的に深さを求める
	rep(i,N) print(i);
	return 0;
}



Measured memory_bytes: 7808
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        
        String S = sc.next();
        
        int count = 0;
        for(int i = 0; i < S.length(); i++){
            if( S.charAt(i) - '0' == i % 2 ) count++;
        }
        
        System.out.println( Math.min(count, S.length()-count) );
    }
}


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


int main() {
int N, K;
int sum = 0;
cin >> N >> K;

vector <int> vec(N);

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

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

for(int k=0; k<K; k++){
    sum += vec.at(k);
}

cout << sum << endl;





}


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

using namespace std;
typedef long long ll;
const int MAXN=1e5+10;
struct edge{int nxt,to;}e[MAXN*8];
struct data{int x,y,id;}dat[MAXN];
int n,d,a,b,x,y,head[MAXN],vis[MAXN],cnt[MAXN],tot=0;
ll res=0;

void add_edge(int from,int to)
{
	e[++tot].nxt=head[from];e[tot].to=to;head[from]=tot;
	e[++tot].nxt=head[to];e[tot].to=from;head[to]=tot;
}

bool operator < (data a,data b)
{
	if(a.x!=b.x) return a.x<b.x;
	return a.y<b.y;
}

void solve(int k)
{
	sort(dat+1,dat+n+1);
	int cur,lst,l,r;
	for(cur=lst=l=r=1;cur<=n;cur++)
	{
		while(dat[l].x<dat[cur].x-d||dat[l].x==dat[cur].x-d&&dat[l].y<dat[cur].y-k) l++;
		while(dat[r].x<dat[cur].x-d||dat[r].x==dat[cur].x-d&&dat[r].y<=dat[cur].y+k) r++;
		cnt[dat[cur].id]+=r-l;lst=max(lst,l);
		if(lst>=r) continue;
		
		add_edge(dat[cur].id,dat[lst].id);
		for(;lst<r-1;lst++) add_edge(dat[lst].id,dat[lst+1].id);
	}
}

void dfs(int x)
{
	vis[x]=true;res+=cnt[x];
	for(int i=head[x];i;i=e[i].nxt)
		if(!vis[e[i].to]) dfs(e[i].to);
}

int main()
{
	scanf("%d%d%d",&n,&a,&b);
	for(int i=1;i<=n;i++)
		scanf("%d%d",&x,&y),dat[i]={x+y,x-y,i};
	
	d=max(abs(dat[a].x-dat[b].x),abs(dat[a].y-dat[b].y));
	solve(d);
	for(int i=1;i<=n;i++) swap(dat[i].x,dat[i].y);
	solve(d-1);
	
	dfs(a);printf("%lld",res);
	return 0;
}

Measured memory_bytes: 10240
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#include"debug_deque.hpp"
#define vector DebugDeque
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printe) FUNC(printw) FUNC(printew) FUNC(printb) FUNC(printd) FUNC(printde);
#endif
template <class S, class T>
istream& operator >> (istream& in, pair<S, T>& p){ in >> p.first >> p.second; return in; }
template <class T>
istream& operator >> (istream& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<int> as(n); cin >> as;
    int ans = 0;
    for(int i = 1; i < n; i++){
        if(as[i] == as[i - 1]){
            ans++;
            i++;
        }
    }
    cout << ans << '\n';
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<string>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<iostream>
using namespace std;
typedef long long ll;
ll n;
struct cc
{
	int l,r,num[210];
};
int num;
cc ksm(ll x)
{
	cc t;
	if(x==1)
	{
		memset(t.num,0,sizeof(t.num));
		t.l=101;
		t.r=100;
		return t;
	}
	t=ksm(x/2);
	t.num[++t.r]=++num;
	if(x&1) t.num[--t.l]=++num;
	return t;
}
int ans;
int main()
{
//	freopen("C.in","r",stdin);
//	freopen("C.out","w",stdout);
	cin>>n;
	++n;
	cc t=ksm(n);
	printf("%d\n",(t.r-t.l+1)*2);
	for(int i=t.l;i<=t.r;++i)
	printf("%d ",t.num[i]);
	for(int i=t.l;i<=t.r;++i)
	printf("%d ",i-t.l+1);
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <cctype>
#include <queue>
#include <stdlib.h>
#include <cstdlib>
#include <math.h>
#include <set>
#include"queue"
#include <vector>
#define inf 107374182
#define M 10010001
#define ll long long
#define PII pair<int,int>
using namespace std;
const int N=200110;

int main()
{
	ll a,b,c,d;
	scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
	ll sum1=a*d;
	ll sum2=a*c;
	ll sum3=b*c;
	ll sum4=b*d;
	ll ans=max(max(sum1,sum2),max(sum3,sum4));
	printf("%lld\n",ans);
    
}

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

using namespace std;

int l[206], ans, n;

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++)
        scanf("%d", &l[i]);
    for (int i = 1; i <= n; i++)
        for (int j = i + 1; j <= n; j++)
            for (int k = j + 1; k <= n; k++)
                if (l[i] + l[j] > l[k] && l[i] + l[k] > l[j] && l[j] + l[k] > l[i] && l[i] != l[j] && l[i] != l[k] &&
                    l[j] != l[k])
                    ans++;
    printf("%d", ans);
    return 0;
}


Measured memory_bytes: 3816
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>

#define REP(i,a,b) for(int i=int(a);i<int(b);i++)

using namespace std;

typedef long long int lli;

int main () {
    int N, M;
    cin >> N >> M;
    vector<set<int>> v(N);
    REP (i, 0, M) {
        int ai, bi;
        cin >> ai >> bi;
        if (ai > bi) swap(ai, bi);
        ai--;
        bi--;
        v[ai].insert(bi);
        v[bi].insert(ai);
    }
    for (auto &i : v[0]) {
        if (v[i].count(N - 1)) {
            cout << "POSSIBLE" << endl;
            return 0;
        }
    }
    cout << "IMPOSSIBLE" << endl;
    return 0;
}


Measured memory_bytes: 28416
package main

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

func main() {
	var n int
	_, _ = fmt.Scan(&n)
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	d := strings.Split(scanner.Text(), " ")
	foods := make([]int, 4096)
	
	for index, str := range d {
		foods[index], _ = strconv.Atoi(str)
	}
	
	sum := 0
	
	for index, num := range foods {
		for index2, num2 := range foods {
			if index != index2 {
				sum += num * num2
			}
		}
	}
	
	fmt.Println(sum / 2)
}


Measured memory_bytes: 640
using System;
using System.Linq;
namespace AtCoder_Core
{
    class Program
    {
        static void Main(string[] args)
        {
            var line = Console.ReadLine().Trim().Split(' ').Select(n => int.Parse(n)).ToArray();
            int K = line[0];
            int X = line[1];
            if (500 * K >= X)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}


Measured memory_bytes: 13268
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define all(in) in.begin(), in.end()
#define INF (sizeof(int) == 4 ? (int)1e9:(int)1e18)
#define EPS 0.0000000001
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
signed main(){
    int N; cin >> N;
    vector<int>v(N);
    for(auto& e : v) cin >> e;
    map<int,int>cnt,toid;
    vector<int>compress;
    for(auto e : v){
        if(cnt[e] == 0){
            compress.push_back(e);
            toid[e] = compress.size() - 1;
        }
        cnt[e]++;
    }
    vector<int>l(compress.size(),0LL),r(compress.size(),0LL);
    rep(i,l.size()){
        if(i == 0) continue;
        l[i] =  l[i-1] + cnt[compress[i-1]] * (cnt[compress[i-1]] - 1) /2;
    }
    for(int ri  = r.size() - 1; ri >= 0;--ri){
        if(ri + 1 == r.size()) continue;
        r[ri] =  r[ri+1]  + cnt[compress[ri+1]] * (cnt[compress[ri+1]] - 1) /2;
    }
    for(auto e : v){
        int id = toid[e];
        cout << r[id] + l[id] + ((cnt[e]-1) * (cnt[e] - 2)) / 2 << endl;
    }
}


Measured memory_bytes: 21876
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,int> pli;
typedef pair<int,int> pii;
typedef long double ld;
#define rep(i,a,b) for(ll i=a ; i<b ; i++)
#define qrep(que, ite) for(auto ite=begin(que) ; ite!=end(que) ; ite++)
const int max_n = 1e5;
const ll mod = 1e9+7;
const ll INF = 1LL<<60;
const int inf = 1e5;
//typedef long double ld;
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; }
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
struct UnionFind {
    vector<int> par;

    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    int size(int x) {
        return -par[root(x)];
    }
};
ll gcd(ll a, ll b) { return a ? gcd(b%a, a) : b; }
int main(){
  int K; cin>>K;
  ll sum =0 ;
  rep(i,1,K+1){
    rep(j,1,K+1){
      ll gc = gcd(i,j);
      rep(k,1,K+1){
        sum += gcd(gc, k);
      }
    }
  }
  cout << sum << endl;
  return 0;
}


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

int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<char>> A(H, vector<char>(W));
  
  for (int i=0; i<H; i++) {
    for (int j=0; j<W; j++) {
      cin >> A.at(i).at(j);
    }
  }
  
  for (int j=0; j<W+2; j++) {
    cout << "#";
  }  
  cout << endl;
  
  for (int i=0; i<H; i++) {
    cout << "#";
    for (int j=0; j<W; j++) {
      cout << A.at(i).at(j);
    }
    cout << "#" << endl;
  }
  for (int j=0; j<W+2; j++) {
    cout << "#";
  }  
  cout << endl;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using Vbo = vector<bool>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using VVbo = vector<Vbo>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
#define rep2(i, m, n) for(ll i=int(m); i<int(n); ++i)
#define drep2(i, m, n) for(ll i=int(m)-1; i>=int(n); --i)
#define rep(i, n) rep2(i, 0, n)
#define drep(i, n) drep2(i, n, 0)


template<typename T>
struct LinearSystemIncidence {
  struct Edge {
    int id, to;
    bool fwd;
    Edge(int i, int t, bool f) : id(i), to(t), fwd(f) {}
  };

  int n, m;
  vector<T> x;
  vector<bool> seen;
  vector<vector<Edge>> G;
  
  LinearSystemIncidence(int n, vector<P> &E) : n(n), m(E.size()), G(n) {
    rep(i, m) {
      G[E[i].first].emplace_back(i, E[i].second, true);
      G[E[i].second].emplace_back(i, E[i].first, false);
    }
  }

  T dfs(vector<T> &b, int u) {
    seen[u] = true;
    T res = b[u];
    for (Edge e : G[u]) {
      if (seen[e.to]) continue;
      T tmp = dfs(b, e.to);
      x[e.id] = tmp * (e.fwd ? 1 : -1);
      res += tmp;

      // mod2
      x[e.id] %= 2;
      if (x[e.id] < 0) x[e.id] += 2;
      ////
    }
    res %= 2; // mod 2
    return res;
  }

  pair<bool, vector<T>> solve(vector<T> &b) {
    x.assign(m, 0);
    seen.assign(n, false);
    for (int s = 0; s < n; ++s) {
      if (seen[s]) continue;
      if (dfs(b, s)) return {false, vector<T>()};
    }
    return {true, move(x)};
  }
};


int main() {
  ll n, m; cin >> n >> m;
  vector<P> E;
  Vll c(n);
  rep(i, m) {
    int u, v; cin >> u >> v;
    --u, --v;
    E.emplace_back(u, v);
    ++c[v];
  }

  LinearSystemIncidence<ll> LSI(n, E);
  auto sol = LSI.solve(c);

  if (!sol.first) {
    cout << -1 << "\n";
    return 0;
  }
  rep(i, m) {
    if (sol.second[i] == 0) swap(E[i].first, E[i].second);
    ++E[i].first;
    ++E[i].second;
    cout << E[i].first << " " << E[i].second << "\n";
  }
  return 0;
}


Measured memory_bytes: 12660
N,x=map(int,input().split())
a=list(map(int,input().split()))

a.sort()

ans=0

if x==sum(a):
  print(N)
  exit()
  
for i in range(N):
  x-=a[i]
  if x<0:
    print(i)
    exit()
else:
  print(N-1)


Measured memory_bytes: 38256
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;
using static System.Console;


namespace atcorder2
{
    class Program
    {
        public static long Read()
        {

            return long.Parse(Console.ReadLine());
        }

        public static long[] Reads()
        {

            return Console.ReadLine().Split().Select(long.Parse).ToArray();
        }

       




        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            var s = ReadLine();
            var n = s.Length;
      
            long count = 0;
            long ans = 0;
            var right =new long[n+1];
            var left = new long[n+1];

            right[0] = 0;
            left[n] = 0;
            for (int i = 0; i <n; i++)
            {
                if (s[i] == '<') count++;
                else count = 0;
                right[i+1] = count;
            }
            count = 0;
            for (int i = n-1; i>=0; i--)
            {
                if (s[i] == '>') count++;
                else count = 0;
                left[i] = count;
            }
            for (int i = 0; i <= n; i++)
            {
                ans += Math.Max(right[i],left[i]);
            }
            
            
            WriteLine(ans);
            


            Console.Out.Flush();
        }
    }
}




Measured memory_bytes: 20704
//~ while (clock()<=69*CLOCKS_PER_SEC)
//~ #pragma comment(linker, "/stack:200000000")
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
//~ #pragma GCC optimize("Ofast")
//~ #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//~ #pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define st first
#define nd second

using namespace __gnu_pbds;
using namespace std;
 
template <typename T>
using ordered_set =
	tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
 
#define shandom_ruffle random_shuffle
 
using ll=long long;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using vi=vector<int>;
using vll=vector<ll>;

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout << fixed << setprecision(11);
	cerr << fixed << setprecision(6);
	
	int n, k;
	cin >> n >> k;
	vi nums(n);
	for (int &x : nums) { cin >> x; }
	
	int ans = n - k + 1;
	set<int> S;
	for (int i = 1; i < k; ++i) { S.insert(nums[i]); }
	
	int nincr = 0;
	for (int i = 1; i < k; ++i) { nincr += nums[i] > nums[i-1]; }
	
	bool had_incr = false;
	
	for (int a = 0; a + k < n; ++a) {
		bool last_incr = (nincr == k-1);
		nincr -= nums[a+1] > nums[a];
		nincr += nums[a+k] > nums[a+k-1];
		bool next_incr = (nincr == k-1);
		
		if (a == 0 && last_incr) { had_incr = true; --ans; }
		
		if (next_incr) {
			had_incr = true;
			--ans;
		} else if (nums[a] < *S.begin() && nums[a+k] > *S.rbegin()) {
			--ans;
		}
		S.erase(nums[a+1]);
		S.insert(nums[a+k]);
	}
	ans += had_incr;
	cout << ans << "\n";
}


Measured memory_bytes: 10368
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <vector>
#include <cstring>
#include <queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using uld = unsigned long long;
using P = pair<int,int>;
ll MAX(ll a,ll b,ll c){return max(a,max(b,c));}
ll MIN(ll a,ll b,ll c){return min(a,min(b,c));}
const ll mod = 1e9+7;
const ll INF = 1e10;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};
template<class T> inline bool chmax(T &a,T& b){if(a < b){a = b; return true;} else return false;}
template<class T> inline bool chmin(T &a,T& b){if(a > b){a = b; return true;} else return false;}
int main(){
    int n;
    cin >> n;
    cout << (10000-n)%1000 << endl;
}

Measured memory_bytes: 3576
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define SZ(x) ((int)(x).size())
#define rep(i,n) for(int i=0;i<(n);++i)
#define fore(i,a) for(auto &i:a)
#define min(...) min({__VA_ARGS__})
#define max(...) max({__VA_ARGS__})
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
#define ALL(x) (x).begin(),(x).end()
signed _main(); signed main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> using v = vector<T>;
template<class T> using vv = vector<v<T>>;
const int MOD=1e9+7;
const long long INF = 1LL << 60;
using P=pair<int,int>;

signed _main(){
  int N,K; cin >> N >> K;
  int ans=0;
  string S; cin >> S;
  string s="";
  rep(i,SZ(S)){
    while(1){
      if(i+1<SZ(S) && S[i]==S[i+1]){
        ans++;
        i++;
      }
      else{
        s+=S[i];
        break;
      }
    }
  }
  //cout << s << endl;
  //cout << ans << endl;
  if(SZ(s)==1){
    cout << ans << endl;
    return 0;
  }
  if(SZ(s)==2){
    cout << ans+1 << endl;
    return 0;
  }
  int X=(SZ(s)-1)/2;
  int Y=0;
  if(SZ(s)%2==0) Y=1;

  if(K<=X){
    ans+=K*2;
    cout << ans << endl;
    return 0;
  }
  ans+=X*2;
  ans+=Y;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 592
#include <iostream>
#include <cmath>
using namespace std;
int num[200010],q[200010];
int main(){
    int n;
    cin>>n;
    for(int i=0;i<n-1;i++){
        int x;
        cin>>x;
        num[x]++;
    }
    for(int i=1;i<=n;i++)
        cout<<num[i]<<endl;
    return 0;
}


Measured memory_bytes: 3944
#!/usr/bin/env python3
import sys


def solve(N: int, M: int, A: "List[int]", B: "List[int]"):
    par = [[] for _ in range(N)]
    chi = [[] for _ in range(N)]
    root = None
    for i in range(N + M - 1):
        chi[A[i] - 1].append(B[i] - 1)
        par[B[i] - 1].append(A[i] - 1)

    #print(chi)
    #print(par)
    for i in range(N):
        if len(par[i]) < 1:
            root = i
            par[i].append(-1)
            break

    cur = {root}
    while len(cur) > 0:
        #print(cur)
        nex = set()
        for idx in cur:
            for c in chi[idx]:
                if len(par[c]) < 2:
                    nex.add(c)
                else:
                    par[c].remove(idx)
        cur = nex

    for i in range(N):
        ret = par[i][0]
        print(ret + 1)

    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    A = [int()] * (N-1+M)  # type: "List[int]" 
    B = [int()] * (N-1+M)  # type: "List[int]" 
    for i in range(N-1+M):
        A[i] = int(next(tokens))
        B[i] = int(next(tokens))
    solve(N, M, A, B)

if __name__ == '__main__':
    main()


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

strings = {}

ans = 0

for _ in range(N):
    s = sorted(list(input()))
    join_s = ''.join(s)
    if join_s in strings:
        strings[join_s] += 1
        ans += strings[join_s]
    else:
        strings[join_s] = 0

print(ans)

Measured memory_bytes: 17808
import java.util.Scanner;




public class Main {

    public static void main(String[] args) {

    	Main main=new Main();

    	main.run();

    }

    void run() {
    	Scanner sc=new Scanner(System.in);
    	int N=sc.nextInt();
    	int P=sc.nextInt();

    	int cntEven=0;
    	int cntOdd=0;
    	for(int i=0;i<N;i++) {

    		int buf=sc.nextInt();

    		if(buf%2==0) {
    			cntOdd++;
    		}else {
    			cntEven++;
    		}


    	}

    	if(cntEven==0) {
    		if(P==0) {
    			System.out.printf("%.0f",Math.pow(2,N));
    		}else {
    			System.out.println("0");
    		}
    	}else {
    		System.out.printf("%.0f",Math.pow(2,N-1));
    	}

    }

}



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

#define pb push_back
#define all(v) v.begin(), v.end()
#define sz(v) int(v.size())
#define pii pair<int, int>
#define mp make_pair
#define f first
#define ll long long
#define ld long double
#define s second
#define vec vector<int>

using namespace std;

const int N = (int) 2e5 + 100;
const int M = (int) 2e6 + 100;
const int K = (int) 200;
const int INF = (int) 1e9 + 7;
const int mod = (int) 998244353;
const ld EPS = (ld) 1e-9;
const ll LINF = (ll) 1e15;

int n;
int a[N], b[N];
ll dp[N];

bool ok(int lim) {
    ll cnt = 0;
    for (int i = 1; i <= n; i++) {
        b[i] = (a[i] <= lim ? 1 : -1);
    }
    for (int i = 1; i <= n; i++) {
        b[i] += b[i - 1];
    }
    map<int, int> last;
    for (int i = 1; i <= n; i++) {
        dp[i] = last.count(b[i]) ? dp[last[b[i]]] : 0;
        if (b[i] - b[i - 1] > 0) {
            dp[i] += (last.count(b[i]) ? i - last[b[i]] - 1 : i);
        }
        last[b[i]] = i;
        cnt += dp[i];
    }
    ll pos = (n * 1ll * (n + 1)) / 2;
    pos = pos / 2 + 1;
    return cnt < pos;
}

int median(vec v) {
    sort(all(v));
    return v[sz(v) / 2];
}

int main() {
	srand(time(0));
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    int l = 0, r = INF, ans;
    while (l <= r) {
        ll m = (l + r) / 2;
        if (ok(m)) {
            ans = m;
            l = m + 1;
        } else {
            r = m - 1;
        }
    }
    cout << ans + 1;
	return 0;
}


Measured memory_bytes: 8576
b,s,o,i;main(a){for(scanf("%d",&i);i<13&&~scanf("%s",&a);b=a%3?a&1?o?b:(s=!printf("%d\n",b>3?s+b-3:s)):b+1:!(s+=++b))  o=a&1?-~o%3:o;return 0;}

Measured memory_bytes: 0
from sys import stdin

n = stdin.readline().rstrip()

list = []
for i in range(3):
    list.append(n[i])

if list[0] == '1':
    list[0] = '9'
else:
    list[0] = '1'
if list[1] == '1':
    list[1] = '9'
else:
    list[1] = '1'
if list[2] == '1':
    list[2] = '9'
else:
    list[2] = '1'

ans = ''.join(list)

print(ans)


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

int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> a(m);
  for (int i = 0; i < m; ++i) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    a[i] = {y, x};
  }
  int ans = 0;
  int pos = -1;
  sort(a.begin(), a.end());
  for (int i = 0; i < m; ++i) {
    if (a[i].second > pos) {
      ++ans;
      pos = a[i].first - 1;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4032
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using Map = map<ll,vl>;
using T = tuple<ll,ll,ll>;
using vvl = vector<vector<ll>>;
#define all(v) v.begin(), v.end()
#define print(v) cout<<v<<endl
#define first(v) get<0>(v)
#define second(v) get<1>(v)
#define third(v) get<2>(v)
template <typename T> bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template <typename T> bool chmin(T &a, const T &b){if (a>b){a=b;return 1;}return 0;}
const ll INF=1LL<<60;
const ll MOD=1000000007;

vector<ll> H={INF,2,5,5,4,5,6,3,7,6};
ll M;
vector<string> A(10);
vector<ll> a(10);

//ans[i]: the maximum number that can be shaped by i matches
vector<string> ans(10001,"");


string F(ll x){
    if(x==0)return "";
    if(ans[x]!="")return ans[x];
    string rec="NG";
    for(ll i=0;i<M;i++){
        if(x-H[a[i]]<0||F(x-H[a[i]])=="NG")continue;
        if(rec=="NG"||F(x-H[a[i]]).size()+1>rec.size()){
            rec=F(x-H[a[i]])+A[i];
        }
        if(F(x-H[a[i]]).size()+1==rec.size()){
            chmax(rec,F(x-H[a[i]])+A[i]);
        }
    ;}
    return ans[x]=rec;
}




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

    for(ll i=0;i<M;i++){
        cin>>A[i];
        a[i]=stoi(A[i]);
    ;}
    A[M]="0";
    a[M]=0;

    for(ll i=1;i<8;i++){
        ans[i]=="NG";
    ;}
    for(ll i=0;i<8;i++){
        for(ll j=0;j<M;j++){
            if(i-a[j]>=0&&ans[i-a[j]]==""){
                ans[i]="";
            }
        ;}
    ;}
    

    print(F(N));
    
    

    
    return 0;
}


Measured memory_bytes: 41984
#include<cstdio>
#include<iostream>
#include<vector>
#include<tuple>
#include<queue>
#include<set>
#include<algorithm>
#include<string>
#include<math.h>

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

using namespace std;

int main(int argc, char* argv[]){
  long long int N, M;
  long long int work = 0;
  long long int ans;
  long long int A[10001];
  cin >> N >> M;
  rep(i, M){
    cin >> A[i];
    work += A[i];
  }
  ans = N - work;
  if(ans < 0) ans = -1;
  
  cout << ans << endl;
  return 0;
}



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



//素因数分解
void factorization(long long n,map<long long ,long long>& mp){
    for(long long i=2;i*i<=n;i++){
        while(n%i==0){
            mp[i]++;
            n /= i;
        }
      }
      if(!(n == 1)) mp[n]++;
}
int main() {
  ll n,ans;
  cin>>n;
  map<ll,ll> mp;
  while(true){
    factorization(n,mp);
    if(mp[n]==1){
      ans=n;
      break;
    }
    n++;
  }
  cout<<ans<<endl;
}

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

vector<int> primeList = {2, 3}; 

int isPrime(int a) {
    for (vector<int>::iterator it = primeList.begin(); it != primeList.end(); it++) {
        if (a % *it == 0) { 
            return 0;
        }
    }
    return 1;
}

int main() {
    int n;
    scanf("%d", &n);

    printf("%d ", 2);
    int count = 1;

    for (int i = 1; count < n ; i++) {
        if (isPrime(6 * i - 1)) {
            primeList.push_back(6 * i - 1);
            if (i % 5 == 0) { 
                printf("%d ", 6 * i - 1);
                count++;
            }
        }
        if (isPrime(6 * i - 1)) {
            primeList.push_back(6 * i + 1);
        }
    }
    printf("\n");
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#include<bits/stdc++.h>
#pragma GCC optimize(2)
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#define Mod 1000000007
#define eps 1e-6
#define ll long long
#define INF 0x3f3f3f3f
#define MEM(x,y) memset(x,y,sizeof(x))
#define maxn 100000 * 2 + 10
using namespace std;
int main()
{
    string a;
    a = "";
    cin>>a;
    if(a == "SUN")
        cout<<7<<endl;
    else if(a == "MON")
        cout<<"6"<<endl;
    else if(a == "TUE")
        cout<<"5"<<endl;
    else if(a == "WED")
        cout<<4<<endl;
    else if(a == "THU")
        cout<<3<<endl;
    else if(a == "FRI")
        cout<<2<<endl;
    else
        cout<<1<<endl;
}


Measured memory_bytes: 256
use io::*;

fn main() {
    let input = read_string();
    let mut sc = Scanner::new(&input);
    let n: usize = sc.next();
    let d = sc.next_mat::<usize>(n, n);
    let mut total: usize = d.iter().map(|x| x.iter().sum::<usize>()).sum::<usize>() / 2;
    for i in 0..n {
        for j in i+1..n {
            for k in 0..n {
                if k == i || k == j {
                    continue;
                }
                if d[i][j] > d[i][k] + d[k][j] {
                    println!("-1");
                    return;
                } else if d[i][j] == d[i][k] + d[k][j] {
                    total -= d[i][j];
                    break;
                }
            }
        }
    }
    println!("{}",total);
}

pub mod io {
    use std;
    use std::str::FromStr;

    pub struct Scanner<'a> {
        iter: std::str::SplitWhitespace<'a>,
    }

    impl<'a> Scanner<'a> {
        pub fn new(s: &'a str) -> Scanner<'a> {
            Scanner {
                iter: s.split_whitespace(),
            }
        }

        pub fn next<T: FromStr>(&mut self) -> T {
            let s = self.iter.next().unwrap();
            if let Ok(v) = s.parse::<T>() {
                v
            } else {
                panic!("Parse error")
            }
        }

        pub fn next_vec_len<T: FromStr>(&mut self) -> Vec<T> {
            let n: usize = self.next();
            self.next_vec(n)
        }

        pub fn next_vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
            (0..n).map(|_| self.next()).collect()
        }

        pub fn next_mat<T: FromStr>(&mut self, w: usize, h: usize) -> Vec<Vec<T>> {
            (0..h).map(|_| self.next_vec(w)).collect()
        }

        pub fn next_vec_char(&mut self) -> Vec<char> {
            self.next::<String>().chars().collect()
        }

        pub fn next_mat_char(&mut self, n: usize) -> Vec<Vec<char>> {
            (0..n).map(|_| self.next_vec_char()).collect()
        }
    }

    pub fn read_string() -> String {
        use std::io::Read;

        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }

    pub fn read_line() -> String {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        s.trim_right().to_owned()
    }
}


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

using namespace std;


int main()
{
	string S;
	cin >> S;

	int ans = 700;

	for(int i = 0; i < S.size(); i++){
		if (S[i] == 'o') {
			
			ans += 100;
		}
	
	}
	cout << ans << endl;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll INF = 1'010'000'000'000'000'017LL;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

int main() {
    // AtCoder
    // template
    ll n, k;
    cin >> n >> k;
    ll ans = k;
    rep(i, n - 1) ans *= k - 1;
    cout << ans << endl;
}


Measured memory_bytes: 256
s=input()[::-1]
words = {"dream", "dreamer", "erase", "eraser"}

while len(s)!=0:
    for i in words:
        l = len(i)
        if s[0:l] == i[::-1]:
            s = s[l::]
            break
    else:
        break

print("NO"if len(s)!=0else "YES")

Measured memory_bytes: 3188
#include<algorithm>
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<cmath>
#include<string>
#include<cstring>
#include<queue>
using namespace std;
#define REP(i, a,b) for(i=a;i<b;i++) 
#define output(x) cout<<x<<endl;

int par[100001];

void init(int n) {
	for (int i = 0; i < n; i++) {
		par[i] = i;
	}
}
//木の根を求める
int root(int x) {
	if (par[x] == x)
		return x;
	else {
		return par[x] = root(par[x]);
	}
}
//find
bool same(int x, int y) {
	return root(x) == root(y);

}
//union
void unite(int x, int y) {
	x = root(x);
	y = root(y);
	if (x == y) return;
	par[x] = y;
}

int main()
{
	long long int i, j, k, l, m, n, sum,flag,ans1,N,M,K,X,Y;
	sum = 0;
	flag = 0;
	ans1 = 0;
	int A[3];
	cin >> N >> M >> X >> Y;
	vector<int>x(N);
	for (i = 0; i<N; i++) {
		cin >> x[i];
	}
	vector<int>y(M);
	for (i = 0; i < M; i++) {
		cin >> y[i];
	}
	sort(x.begin(), x.end());
	sort(y.begin(), y.end());
	REP(i, X + 1, Y + 1) {
		if (i > x[N - 1] && i <= y[0]) {
			flag = 1;
			break;
		}
	}
	if (flag) {
		output("No War");
	}
	else
		output("War")
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
int main () {
  int n; cin >> n;
  
  if(n%2==0) {cout << fixed << setprecision(6); cout << 0.500000 << endl;}
  else {cout << fixed << setprecision(6); cout << double (n+1)/(2*n) << endl;}
}

Measured memory_bytes: 256
a,v=map(int, input().split())
b,w=map(int, input().split())
t=int(input())

dis=abs(b-a)
speed=v-w
if speed==0:
    if dis==0:
        print("YES")
        exit(0)
    else:
        print("NO")
        exit(0)


time =dis/speed
#print(time)
if time <0:
    print("NO")

elif time <=t:
    print("YES")
else:
    print("NO")

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

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

    string s, t;
    cin >> s >> t;

    map<char, set<int>> chars;
    for (int i = 0; i < s.size(); i++) {
        chars[s[i]].insert(i);
        chars[s[i]].insert(i + s.size());
    }
    int64_t ret = 0;
    for (int i = 0; i < t.size(); i++) {
        if (chars[t[i]].empty()) {
            ret = -1;
            break;
        }
        int p = ret % s.size();
        auto it = chars[t[i]].lower_bound(p);
        ret += *it - p + 1;
    }

    cout << ret << endl;

    return 0;
}


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


int main(){
    int N;
    long long K;
    std::cin >> N >> K;
    std::vector< long long > P, M, Z;
    long long tmp;
    for(int i=0; i<N;i++){
        std::cin >> tmp;
        if(tmp > 0){ P.push_back(tmp); }
        else if(tmp < 0){ M.push_back(tmp); }
        else{ Z.push_back(tmp); }
    }
    
    long long P_n, M_n, Z_n;
    M_n = P.size() * M.size();
    P_n = ( P.size() * (P.size() - 1) + M.size() * (M.size() - 1) ) / 2;
    Z_n = ( (P.size() + M.size() + Z.size()) * (P.size() + M.size() + Z.size() - 1) ) / 2 - M_n - P_n;
    
    int pmz;
    if(K <= M_n){ pmz = -1; }
    else if(K <= M_n + Z_n){ pmz = 0; }
    else{ pmz = 1; }
    
    if(pmz == -1){
        std::sort(P.begin(), P.end());
        std::sort(M.begin(), M.end());
        long long min = -1e+18 - 1;
        long long max = -1;
        while(max - min > 1){
            long long ave = (max + min) / 2;
            long long sum = 0;
            for(int i=0; i<P.size(); i++){
                long long d = (ave - P[i] + 1) / P[i];
                sum += upper_bound(M.begin(), M.end(), d) - M.begin();
            }
            if(sum < K){
                min = ave;
            }else{
                max = ave;
            }
        }
        std::cout << max << std::endl;
    }else if(pmz == 0){
        std::cout << 0 << std::endl;
    }else{
        for(int i=0;i<M.size();i++){
            M[i] = abs(M[i]);
        }
        std::sort(P.begin(), P.end());
        std::sort(M.begin(), M.end());
        K = K - M_n - Z_n;
        long long min = 0;
        long long max = 1e+18;
        while(max - min > 1){
            long long ave = (max + min) / 2;
            long long sum = 0;
            for(int i=0; i<P.size(); i++){
                long long d = ave / P[i];
                long long tmp = upper_bound(P.begin(), P.end(), d) - P.begin();
                if(i < tmp) tmp--;
                sum += tmp;
            }
            for(int i=0; i<M.size(); i++){
                long long d = ave / M[i];
                long long tmp = upper_bound(M.begin(), M.end(), d) - M.begin();
                if(i < tmp) tmp--;
                sum += tmp;
            }
            sum /= 2;
            if(sum < K){
                min = ave;
            }else{
                max = ave;
            }
        }
        std::cout << max << std::endl;
    }
    return 0;
}


Measured memory_bytes: 2548
#define _USE_MAT_DEFINES
#include<iostream>
#include <iomanip>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include <queue>
#include <utility>
#include <map>
#include <set>
#include <stack>
#include <deque>
#include <numeric>
#include <functional>
using namespace std;

static const int MOD = 1e9 + 7;

bool f(int x, int a, int b) {
    return x < (a + b);
}

int main() {

    int N;
    cin >> N;
    cout << ((N+1)/2) / (double)N;

}

Measured memory_bytes: 256
H,W = map(int, input().split())
S = [["#"] * (W + 2)]
S += [["#"] + list(input()) + ["#"] for _ in range(H)]
S.append(["#"] * (W + 2))

INF = 10 ** 5

visited = [[False] * (W + 2) for _ in range(H + 2)]
dist = [[INF] * (W + 2) for _ in range(H + 2)]

DY = [-1,1,0,0]
DX = [0,0,-1,1]

from collections import deque
def bfs():
    visited[1][1] = True
    dist[1][1] = 0
    que = deque([(1,1)])
    while que:
        y,x = que.popleft()
        for dy,dx in zip(DY,DX):
            ny = y + dy
            nx = x + dx
            if visited[ny][nx]: continue
            if S[ny][nx] == "#": continue

            if dist[ny][nx] > dist[y][x] + 1:
                dist[ny][nx] = dist[y][x] + 1
                visited[ny][nx] = True
                que.append((ny,nx))
    return True if visited[H][W] else False

if not bfs():
    print(-1)
    exit()

ans = 0
for i in range(1, H + 1):
    for j in range(1, W + 1):
        if S[i][j] == ".": ans += 1

print(ans - (dist[H][W] + 1))

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

int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	string str;
	cin >> str;
	for (int i = 0; i < str.length(); i++)
	{
		if (str[i] == '7')
		{
			cout << "Yes" << "\n";
			return 0;
		}
	}
	cout << "No" << "\n";
	return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define LL long long
#define PII pair<int, int>
using namespace std;

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	LL n, x, d, mi = 0, mx = 0;
	map<LL, vector<pair<LL, LL>>> intv;
	
	cin >> n >> x >> d;
	
	if (d == 0) {
		cout << (x == 0 ? 1 : n + 1) << '\n';
		return 0;
	}
	
	for (LL i = 0; i <= n; i++) {
		LL a = i * x + mi * d, b = i * x + mx * d;
		intv[i * x % abs(d)].push_back({min(a, b), max(a, b)});
		mi += i;
		mx += n - i - 1;
	}
	
	LL ans = 0;
	for (auto &p : intv) {
		auto &vec = p.second;
		pair<LL, LL> pre = {(LL) -5e18, -5e18};
		sort(vec.begin(), vec.end());
		for (auto now : vec) {
			if (now.second <= pre.second) continue;
			ans += (now.second - max(now.first, pre.second)) / abs(d);
			if (pre.second < now.first) {
				ans++;
			}
			pre = now;
		}
	}
	
	cout << ans << '\n';
	
	return 0;
}

Measured memory_bytes: 22144
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<math.h>
#include<unordered_map>
using namespace std;
typedef long long ll;
const long double pi = 3.14159265358979323846264338327950288;
int main() {
	string a;
	cin >> a;
	int sum = -1;
	for (int i = 0; i < a.size();) {
		int j = i;
		while (j<a.size()&&a[i] == a[j])
			j++;
		i = j;
		sum++;
	}
	cout << sum << endl;
	cin >> a;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> pii;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define vv(type, c, m, n, i) vector<vector<type>> c(m, vector<type>(n, i))
#define mat(type, c, m, n) vector<vector<type>> c(m, vector<type>(n));for(auto& r:c)for(auto& i:r)cin>>i;
#define rep(i,a,n) for(int i=(a), i##_len=(n); i<i##_len; ++i)
#define rrep(i,a,n) for(int i=(a), i##_len=(n); i>i##_len; --i)
#define each(x,y) for(auto &(x):(y))
#define var(type, ...)type __VA_ARGS__;Scan(__VA_ARGS__);
template<typename T> void Scan(T& t) { cin >> t; }
template<typename First, typename...Rest>void Scan(First& first, Rest&...rest) { cin >> first; Scan(rest...); }
#define vec(type, c, n) vector<type> c(n);for(auto& i:c) cin>>i;
#define len(x) ((int)(x).size())
#define mp make_pair
#define eb emplace_back
#define em emplace
#define pb pop_back
#define fi first
#define se second
#define get(a, i) get<i>(a)
#define mt make_tuple
inline string zero(int a,string s,char c='0'){return string(a-len(s),c)+s;}
inline string zero(int a,int t,char c='0'){return zero(a, to_string(t), c);}
inline string zero(int a,ll t,char c='0'){return zero(a, to_string(t), c);}
#define mini min_element
#define maxi max_element
#define sum accumulate
#define chmax(a,b) if(a<b)a=b
#define chmin(a,b) if(a>b)a=b
template <class T> inline void print(T t){cout << t << endl;}
template <class H, class... T> inline void print(H h, T... t){cout << h << " ";print(t...);}
int main() {
	var(int, n, a);
	print((n % 500 <= a) ? "Yes" : "No");
	return 0;
}


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

signed main() {
    int N, T; cin >> N >> T;
    int A[N], B[N];
    rep(i, N) cin >> A[i] >> B[i];
    int dp[N+1][T][2];
    rep(i, N+1) rep(j, T) rep(k, 2) dp[i][j][k] = 0;
    
    rep(i, N) {
        rep(j, T) {
            dp[i+1][j][0] = max(dp[i+1][j][0], dp[i][j][0]);
            dp[i+1][j][1] = max(dp[i+1][j][1], dp[i][j][1]);
            dp[i+1][j][1] = max(dp[i+1][j][1], dp[i][j][0]+B[i]);
            
            if (j+A[i]<T) {
                dp[i+1][j+A[i]][0] = max(dp[i+1][j+A[i]][0], dp[i][j][0]+B[i]);
                dp[i+1][j+A[i]][1] = max(dp[i+1][j+A[i]][1], dp[i][j][1]+B[i]);
            }
        }
    }
    
    cout << dp[N][T-1][1] << endl;
}

Measured memory_bytes: 140928
// parameter "input" gets all data
function Main(input) {
	// the first line is assigned to input[0], the second line is assigned to input[1] similarly.
	var splitInput = input.split(" ");
	var n = parseInt(splitInput[0])
	var a = parseInt(splitInput[1])
	var b = parseInt(splitInput[2])
	
	var maximum = Math.min(a,b)
	var minimum = Math.max(a+b-n,0)
	//output
	console.log('%d %d',maximum,minimum);
}
// Don't edit this line!
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

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

using ll = long long;
using pii = pair<int, int>;
using Vi = vector<int>;


int main(){
  int N,K;
  cin >> N;
  vector<vector<int>> V(N, vector<int>(3));
  
  rep(i, N){
    rep(j, 3){
      cin >> V[i][j];
    }
  }
  
  
  Vi dp1(N, 0);
  Vi dp2(N, 0);
  Vi dp3(N, 0);
  dp1[0] = V[0][0];
  dp2[0] = V[0][1];
  dp3[0] = V[0][2];
  
  rep2(i, 1, N){
    dp1[i] += (max(dp2[i-1], dp3[i-1]) + V[i][0]);
    dp2[i] += (max(dp1[i-1], dp3[i-1]) + V[i][1]);
    dp3[i] += (max(dp1[i-1], dp2[i-1]) + V[i][2]);
  }
  
  cout << max(dp1[N-1], max(dp2[N-1], dp3[N-1])) << endl;
  
   
  
}

      
      
       




Measured memory_bytes: 9860