akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

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

struct Radix {
	string s;
	int a[128];
	Radix(string s = "0123456789ABCDEF") :s(s) {
		for (int i = 0; i < s.size(); i++)
			a[s[i]] = i;
	}
	//10???(long long) -> n???(string)
	string format(long long x, int n, int len = 1) {
		if (!x)return string(len, s[0]);
		string ret;
		for (; x || len > 0; x /= n, len--)
			ret += s[x%n];
		reverse(ret.begin(), ret.end());
		return ret;
	}
	using It = string::iterator;
	//m???(string) -> n???(string)
	string format(It l, It r, int m, int n, int len = 1) {
		return format(format(l, r, m), n, len);
	}
	//m???(string) -> 10???(long long)
	long long format(It l, It r, int m) {
		long long x = a[*l];
		for (l++; l != r; l++)
			x = x * m + a[*l];
		return x;
	}
};

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N; cin >> N;
	vector<string> S(N); rep(i, 0, N) { cin >> S[i]; }
	Radix r(" abcdefghijklmnopqrstuvwxyz");
	unordered_set<long long> st;
	rep(i, 0, N) {
		int n = S[i].size();
		rep(h, 1, 5) {
			rep(j, 0, n - h + 1) {
				st.emplace(r.format(S[i].begin() + j, S[i].begin() + j + h, 27));
			}
		}
	}
	rep(i, 0, pow(27, 4)) {
		if (st.count(i))continue;
		string s = r.format(i, 27);
		if (s.find(' ') != string::npos)continue;
		cout << s << endl;
		return 0;
	}
	return 0;
}

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

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



int main()
{
    int k;cin >> k;
    vector <ll>a;
    for(int i=1;i<=9;i++)a.push_back(i);
    while(1){
        if(k<=a.size()){
            cout << a[k-1]<< endl;
            return 0;
        }
        k-=a.size();
        vector<ll>old;
        swap(a,old);
        for(ll x:old){
            for(int i=-1;i<=1;i++){
                int d=x%10+i;
                if(d<0||d>9)continue;
                a.push_back(x*10+d);
            }
        }
    }
    return 0;
}


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

int main(){
    int n;
    cin >> n;
    int A[55];
    for (int i=0;i<n;i++) cin >> A[i];
    
    int v[55];
    for (int i=0;i<n;i++) v[i] = A[i];
    sort(A, A+n);
    int count = 0;
    for (int i=0;i<n;i++){
        if (v[i] != A[i]) count++;
    }
    if (count == 2 || count == 0) cout << "YES" << endl;
    else cout << "NO" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long t;
int ans2, ans4;
int main()
{
	int N; scanf("%d", &N);
	for (int i = 0; i < N; i++) {
		scanf("%d", &t);
		if (t % 4 == 0)ans4++;
		else if (t % 2 == 0)ans2++;
	}
	if (ans4 * 2 >= N - 1) {
		printf("Yes\n");
	}
	else if (ans2 + ans4 * 2 >= N) {
		printf("Yes\n");
	}
	else printf("No\n");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef long double llf;
typedef pair<lint, lint> pi;
const int mod = 1e9 + 7;

int n, a[100005];
int p, q;

int main(){
	scanf("%d %d %d",&n,&p,&q);
	for(int i=0; i<n; i++){
		scanf("%d",&a[i]);
	}
	lint ret = 0;
	for(int i=1; i<n; i++){
		ret += min(1ll * (a[i] - a[i-1]) * p, 1ll * q);
	}
	cout << ret;
}



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

import sys

way = []
way.append([int(i) for i in input().split(' ')])
way.append([int(i) for i in input().split(' ')])
way.append([int(i) for i in input().split(' ')])

#print(way)

w_l = [0, 0, 0, 0]

for w in way:
    w_l[w[0]-1] += 1
    w_l[w[1]-1] += 1

for i in w_l:
    if i >= 3:
        print('NO')
        exit()

print('YES')

Measured memory_bytes: 3064
#include<cstdio>
#include<cstring>
using namespace std;
struct point
{
    int x,y;
} w[1000009];
int n,m,v[1009][1009],k=0,head,tail,cnt,ans=0;
char a[1009][1009];
int main()
{
    memset(v,0,sizeof(v));
    scanf("%d%d",&n,&m);
    for(int i=0; i<n; i++)
    {
        scanf("%s",a[i]);
        for(int j=0; j<m; j++)
        {
            if(a[i][j]=='#')
            {
                w[k].x=i;
                w[k++].y=j;
                v[i][j]=1;
            }
        }
    }
    head=0;
    tail=k;
    while(head<tail)
    {
        cnt=0;
        for(int i=head; i<tail; i++)
        {
            int q=w[i].x;
            int e=w[i].y;
            int run[4]= {0,1,0,-1},run1[4]= {1,0,-1,0};
            for(int j=0; j<4; j++)
            {
                if(q+run[j]>=0&&q+run[j]<n&&e+run1[j]>=0&&e+run1[j]<m&&!v[q+run[j]][e+run1[j]])
                {
                    v[q+run[j]][e+run1[j]]=1;
                    w[k].x=q+run[j];
                    w[k++].y=e+run1[j];
                    cnt++;
                }
            }
        }
        head=tail;
        tail+=cnt;
        ans++;
    }
    printf("%d",ans-1);
    return 0;
}


Measured memory_bytes: 12928
#include <stdio.h>
int main(void){
    int h,w;
    
    while(1){
        scanf("%d %d",&h ,&w);
        if(h==0 && w == 0){
            break;
        }
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++){
                if(i%2==0) {   //偶数行目
                    if(j%2==0){ //偶数列目
                        printf("#");
                    }else{
                        printf(".");
                    }
                }if(i%2==1){   //奇数列目
                    if(j%2==1){
                        printf("#");
                    }else{
                        printf(".");
                    }
                }
            }printf("\n");
        }printf("\n");
    }
    
    
    return 0;
}




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

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


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_map>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>
#include<iomanip>
#include<bitset>

using namespace std;

#define ll long long int

ll const MOD = 1000000007;
ll const INF = (long long int)1 << 61;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll n,m,c;
    cin >> n >> m >> c;

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

    vector<vector<ll>> b(n,vector<ll>(m));
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            cin >> b[i][j];
        }
    }
    
    ll ans = 0;

    for(int i = 0; i < n; i++){
        ll t = 0;
        for(int j = 0; j < m; j++){
            t += a[j]*b[i][j];
        }
        if(t+c > 0){
            ans++;
        }
    }

    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
// atcoder/abc157/D/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; for (auto& i: v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { for (auto& i: v) is >> i; return is; }
template<typename T> ostream& operator << (ostream& os, set<T> s) { os << "#{"; for (auto& i: s) os << i << ","; os << "}"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; for (auto& i: m) os << i << ","; os << "}"; return os; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

using lli = long long int;
using ull = unsigned long long;
using point = complex<double>;
using str = string;
template<typename T> using vec = vector<T>;

constexpr lli mod = 1e9 + 7;

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n, m, k;
  while (cin >> n >> m >> k) {
    vector<int> g[n];

    for (int i = 0; i < m; ++i) {
      int a, b;
      cin >> a >> b;
      --a;
      --b;
      g[a].push_back(b);
      g[b].push_back(a);
    }

    vector<int> h[n];
    for (int i = 0; i < k; ++i) {
      int a, b;
      cin >> a >> b;
      --a;
      --b;
      h[a].push_back(b);
      h[b].push_back(a);
    }

    int cnt = 0;
    int color[n];
    fill(color, color + n, -1);
    int x[n];
    fill(x, x + n, -1);
    auto bfs = [&] (int src) {
      set<int> vis;
      vis.insert(src);
      queue<int> q;
      for (q.push(src); q.size(); q.pop()) {
        int curr = q.front();
        each (next, g[curr]) {
          if (vis.count(next)) continue;
          vis.insert(next);
          q.push(next);
        }
      }
      each (i, vis) {
        x[i] = vis.size();
        color[i] = cnt;
      }
      ++cnt;
    };
    for (int i = 0; i < n; ++i) {
      if (x[i] == -1) bfs(i);
    }

    int y[n];
    for (int i = 0; i < n; ++i) {
      y[i] = x[i];
      y[i] -= g[i].size();
      each (j, h[i]) {
        if (color[i] == color[j]) {
          --y[i];
        }
      }
    }

    for (int i = 0; i < n; ++i) {
      if (i) cout << ' ';
      cout << y[i] - 1;
    }
    cout << endl;
  }

  return 0;
}


Measured memory_bytes: 18168
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
using namespace std;

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

int main() {
  int n;
  while(cin >> n,n ) {
    bool table[n][30];
    memset(table,0,sizeof(table));
    REP(i,n) {
      int m;
      cin >>m;
      REP(j,m) {
        int a;
        cin >> a;
        table[i][a-1] = 1;
      }
    }
    bool have[n][n];
    memset(have,0,sizeof(have));
    REP(i,n) have[i][i] = 1;
    bool f = 0;                 
    REP(i,30) {
      bool hoge[n];
      memset(hoge,0,sizeof(hoge));
      REP(j,n) {
        if (table[j][i]) {
          REP(k,n) {
            if (have[j][k]) {
              hoge[k] = 1;
            }
          }
        }
      }
      // cout << "hoge ";
      // REP(j,n)
      //   if (hoge[j])
      //     cout << j << " ";
      // cout<< endl;
      REP(j,n) {
        if (table[j][i]) {
          REP(k,n) {
            if (hoge[k]) {
              have[j][k] = 1;
//              printf("%d,%d\n",j,k);
            }
          }
        }
      }
      REP(j,n) {
        int cnt = 0;
        REP(k,n) {
          if (have[j][k]) {
            cnt++;
            //          printf("%d,%d\n", j,k);
          }
        }
        if (cnt==n) {
          cout<< i+1 << endl;
          f = 1;
          break;
        }
      }
      if (f)
        break;
    }
    if (!f)
      cout << -1 << endl;
  }
}

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

def pre_order(id, list):
    if id > -1:
        list.append(id)
        pre_order(node_dic[id].left, list)
        pre_order(node_dic[id].right, list)

def in_order(id, list):
    if id > -1:
        in_order(node_dic[id].left, list)
        list.append(id)
        in_order(node_dic[id].right, list)

def post_order(id, list):
    if id > -1:
        post_order(node_dic[id].left, list)
        post_order(node_dic[id].right, list)
        list.append(id)

class Node_Class():
    def __init__(self, left, right):
        self.left = left
        self.right = right

n = int(raw_input())
node_dic = {}
root = 0
for i in range(n):
    id, left, right = map(int, raw_input().split())
    node_dic[id] = Node_Class(left, right)
    root += i
for i in range(n):
    left = node_dic[i].left
    right = node_dic[i].right
    if left > -1:
        root -= left
    if right > -1:
        root -= right
A = []
B = []
C = []
pre_order(root, A)
in_order(root, B)
post_order(root, C)
print "Preorder"
print " "+" ".join(map(str, A))
print "Inorder"
print " "+" ".join(map(str, B))
print "Postorder"
print " "+" ".join(map(str, C))

Measured memory_bytes: 6408
#include <cstdio>
#include <cstring>
#include <set>

using namespace std;

char str[16];
char com[9];
set<long long> keys;

int getChar(char ch)
{
    if (ch == 'A') return 1;
    else if (ch == 'C') return 2;
    else if (ch == 'G') return 3;
    else if (ch == 'T') return 4;
    return 0;
}

long long getKey(char str[])
{
    long long sum = 0, p = 1;
    for (int i = 0; i < strlen(str); i++)
    {
        sum += p * (getChar(str[i]));
        p *= 5;
    }
    return sum;
}

bool find(char str[])
{
    return keys.find(getKey(str)) != keys.end();
}

void insert(char str[])
{
    keys.insert(getKey(str));
}

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

    for (int i = 0; i < n; i++)
    {
        scanf("%s %s", com, str);

        if (com[0] == 'i')
            insert(str);
        else if (find(str))
            printf("yes\n");
        else
            printf("no\n");
    }

    return 0;
}

Measured memory_bytes: 15672
#include <stdio.h>

int main(){
    int n=0,i=1;
    long long s=0;
    scanf("%d",&n);
    for(;i<=n;i++){
      if(i%3!=0&&i%5!=0){
        s+=i;
      }
    }
    printf("%lld\n",s);
    return 0;
}

Measured memory_bytes: 1704
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mk make_pair
#define pii pair<int,int>
#define fst first
#define scd second
using namespace std;
inline ll read() 
{
	ll f=1,x=0;
	char ch=getchar();
	while(!isdigit(ch))
	{
	   if(ch=='-')
	    	f=-1;
	   ch=getchar();
	}
	while(isdigit(ch))
	{
	   x=x*10+ch-'0';
	   ch=getchar();
	}
	return x*f;
}
const int MAXN=1e5+5;
int n,m,fa[MAXN];
struct EDGE 
{
	int u,v;
}e[MAXN];
ll ans[MAXN],sz[MAXN];
int get_fa(int x) 
{
	if(x==fa[x]) return x;
	return fa[x]=get_fa(fa[x]);
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	n=read();
	m=read();
	for(int i=1;i<=m;++i) 
	{
		e[i].u=read(); 
		e[i].v=read();
	}
	for(int i=1;i<=n;++i) 
	   fa[i]=i,sz[i]=1;
	ans[m]=(ll)n*(n-1)/2;   
	for(int i=m;i>=1;--i) 
	{
		int u=get_fa(e[i].u),v=get_fa(e[i].v);
		if(u==v) 
		    ans[i-1]=ans[i];
		else {
			ans[i-1]=ans[i]-sz[v]*sz[u];
			sz[v]+=sz[u]; fa[u]=v;
		}
	}
	for(int i=1;i<=m;++i) 
	   cout<<ans[i]<<endl;
	return 0;
}

Measured memory_bytes: 4096
import java.util.Scanner;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Map;
import java.util.HashMap;

public class Main
{
    int k, s;
    
    public static void main(String args[])
    {
	new Main().solve();
    }
    
    void solve()
    {
	in();

	int cnt = 0;
	
	for(int i = 0; i <= k; i++) {
	    for(int j = 0; j <= k; j++) {
		int n = s - i - j;
		if(n >= 0 && n <= k) cnt++;
	    }
	}
	
	out(cnt);
    }

    void in()
    {
	Scanner sc = new Scanner(System.in);
	k = sc.nextInt();
	s = sc.nextInt();
    }

    void out()
    {
	
    }
    
    void out(int n)
    {
	System.out.println(n);
    }

    void out(char c)
    {
	System.out.print(c);
    }
    
    void out(String s)
    {
	System.out.println(s);
    }
}


Measured memory_bytes: 22868
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int p[120005]={0};
int dp[120005]={0};
void prime()
{
	int l=1,flag=1;
	p[2]=1;
	for(int i=3;i<110005;i++)
	{
		flag=1;
		for(int j=2;j<=sqrt(i);j++)
		{
			if(i%j==0)
			{
				flag=0;
				break;
			}
		}
		if(flag)
			p[i]=1;
	}
}
void fun()
{
  for(int i=1;i<110005;i+=2)
  {
  	if(p[i]&&p[(i+1)/2])
  	{
  		dp[i]+=dp[i-1]+1;
  		dp[i+1]=dp[i];
  	}
  	else
  	{
  		dp[i]=dp[i-1];
  		dp[i+1]=dp[i];
  	}
  }
}
int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);
	prime();
	fun();
	int q,x,y;
	cin>>q;
    while(q--)
    {
    	cin>>x>>y;
    	cout<<(dp[y]-dp[x-1])<<endl;
    }
	return 0;
}

Measured memory_bytes: 1536
#include <iostream>
#include <map>

using namespace std;
typedef long long LL;

int main(){
    int n;
    cin >> n;
    map<LL,LL> cnt;
    for(int i = 0; i < n; ++i){
        LL v;
        cin >> v;
        cnt[v] = 1 - cnt[v];
    }
    LL total = 0;
    for(pair<LL,LL> p : cnt){
        total += p.second;
    }
    cout << total << endl;
    return 0;
}


Measured memory_bytes: 6528
import queue

k = int(input())

q = queue.Queue()
for i in range(1,10):
    q.put(i)

for i in range(k):
    x = q.get()

    p = 10 * x  
    m = x % 10
    if not m == 0:
        q.put(p + m - 1)

    q.put(p + m)

    if not m == 9:
        q.put(p + m + 1)
    
print(x)


Measured memory_bytes: 12512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=100010;
int n,k,h[N],ans=INT_MAX;
int main()
{
  cin>>n>>k;
  for(int i=1;i<=n;i++) cin>>h[i];
  sort(h+1,h+n+1);
  for(int i=1;(i+k-1)<=n;i++) ans=min(ans,h[i+k-1]-h[i]);
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <vector>
#include<cmath>
using namespace std;
#define ll (long long)
#define PI (acos(-1))

int main()
{
int N;
string S;
cin >> N;
cin >> S;
int num=0;
char c1,c2,c3;

for(int i=0; i<N; i++){
  c1 = S[i];
  c2 = S[i+1];
  c3 = S[i+2];

  if(c1 =='A' && c2 == 'B' && c3 == 'C'){
    num++;
    i+=2;
  }
}

cout << num;
}


Measured memory_bytes: 3508
import java.util.Scanner;
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        List<Integer> h = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            h.add(sc.nextInt());
        }
        Collections.sort(h);


        int ans = Integer.MAX_VALUE;
        for (int i = 0; i < n - k + 1; i++) {
            ans = Math.min(ans, h.get(i + k - 1) - h.get(i));
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 59016
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashMap;


public class Main {
	
	public static void main(String[] args) throws IOException {
		Main m = new Main();
		m.input();
		m.solve();
		m.output();
	}
	
	//	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	InputUtil in = new InputUtil();
	PrintWriter out = new PrintWriter(System.out);

	int N = 0;
	int M = 0;
	int[] D = null;
	int[] T = null;
	boolean ans = false;
	
	public void input() throws IOException {
		N = in.nextInt();
		D = in.nextInt(new int[N]);
		M = in.nextInt();
		T = in.nextInt(new int[M]);
				
	}

	public void solve() throws IOException {
		HashMap<Integer,Integer> DH = new HashMap<>();
		final Integer one = new Integer(1);
		for(Integer d : D){
			Integer value = null;
			if(DH.containsKey(d)){
				value = DH.get(d);
				value ++;
			}else{
				value = one;
			}
			DH.put(d, value);
		}
		HashMap<Integer,Integer> TH = new HashMap<>();
		for(Integer t : T){
			Integer value = null;
			if(TH.containsKey(t)){
				value = TH.get(t);
				value ++;
			}else{
				value = one;
			}
			TH.put(t, value);
		}
		
		for(Integer t : TH.keySet()){
			Integer tv = TH.get(t);
			Integer dv = DH.get(t);
			if(dv == null || tv > dv) {
				return;
			}
			
		}
		ans = true;
	}
	
	public void output() {
		out.println(ans ? "YES" : "NO");
		out.flush();
		
	}
}



class InputUtil {
	//Static Fields
	private static final int BUFSIZ = 100000;
	
	//Fields
	protected InputStream in;
	private byte[] buf = null;
	private int ptr = 0;
	private int max = -1;
	private DataInputStream dis = null;
	//Constructors
	public InputUtil() {this(System.in,BUFSIZ);}
	public InputUtil(InputStream in, int bufsiz) {
		initBuf(bufsiz);
		initIn(in);
	}
	
	//Methods
	//Initializer
	protected void initIn(InputStream in) {dis = new DataInputStream(this.in = in);}
	protected void initBuf(int bufsiz) {buf = new byte[bufsiz];}
	
	//buffer operation
	private void next() throws IOException {ptr++; readBuf();}
	private void readBuf() throws IOException {
		if(ptr >= max && dis.available()>0) {
			if(max>0) Arrays.fill(buf,0,max,(byte)0);
			max = dis.read(buf);
			ptr = 0;
		}
	}
	
	//Number Input Reader/Parser
	private boolean isNum(byte b) {return '0' <= b && b <= '9'; }
	private boolean isMinus(byte b) {return b=='-'; }

	private int _nextInt() throws IOException {
		int sign = 1;
		int res = 0;
		byte c;
		while (!isNum(c=buf[ptr]) && !isMinus(c)) 
			next();
		if (isMinus(buf[ptr])) {
			sign = -1;
			next();
		}
		while (isNum(c=buf[ptr])) {
			res *= 10;
			res += c - '0' ;
			next();
		}
		next();
		return sign * res;
	}
	
	public int nextInt() throws IOException {
		readBuf();
		return _nextInt();
	}

	public int[] nextInt(int[] result) throws IOException {
		readBuf();
		for(int i=0; i<result.length; i++) {
			result[i] = _nextInt();
		}
		return result;
	}
	
	//Close 
	public void close() throws IOException {
		if(!this.in.equals(System.in)) 
			this.in.close();
	}

}


Measured memory_bytes: 65252
module Main where

import Control.Applicative
import Control.Monad
import Data.List

main :: IO ()
main = do
    [a, b, c, x] <- replicateM 4 readLn :: IO [Int]
    let n = do
            i <- [0 .. a]
            j <- [0 .. b]
            k <- [0 .. c]
            let amt = i * 500 + j * 100 + k * 50
            guard (amt == x)
            return (i, j, k)
    print $ length n

Measured memory_bytes: 508
/* ****Ragnar7 -SHINIGAMI- _Lawliet_**** */
/* First, solve the problem.Then write the code. */
#include<bits/stdc++.h>
#define ll          long long
#define ld 			long double
#define hell        1000000007
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
std::mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());
using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	#ifndef ONLINE_JUDGE
	freopen ("input.txt","r",stdin);
	// freopen ("output.txt","w",stdout);
	#endif
	ll t = 1;
	// cin>>t;
	while(t--)
	{
		ll n,w;
		cin>>n>>w;
		vector<pair<ll,ll> > v;
		ll x,y;
		v.push_back({0,0});
		for(ll i=1;i<=n;i++)
		{
			cin>>x>>y;
			v.push_back({x,y});
		}
		ll dp[n+5][w+5];
		memset(dp,0,sizeof(dp));
		for(ll i=1;i<=w;i++)
		{
			for(ll j=1;j<=n;j++)
			{
				if(i-v[j].first>=0)
					dp[j][i] = max(dp[j][i],dp[j-1][i-v[j].first]+v[j].second);
				dp[j][i] = max(dp[j][i],dp[j-1][i]);
			}	
		}
		cout<<dp[n][w];

		
	}

	
	time
	return 0;
}

Measured memory_bytes: 85544
#include<cstdio>
#include<queue>
#include<stack>
#include<iostream>
#include<string>
#include<vector>
#include<map>
using namespace std;
typedef pair<int,int> P;

char s[20003];
stack<int> sta;
vector<P > ku;

int main(){

  scanf("%s",s);
  int res=0;
  for(int i=0;i<sizeof(s);i++){
    if(s[i]=='\\'){
      sta.push(i);
    }
    if(s[i]=='/' && !sta.empty()){
      int mama=sta.top();sta.pop();
      res+=i-mama;
      ku.push_back(P(mama,i));

    }
  }

  vector<int> ma;

  for(vector< P >::iterator it=ku.begin();it!=ku.end();it++){
    int ress=it->second-it->first;
    bool flg=true;
    for(vector< P >::iterator gt=ku.begin();gt!=ku.end();gt++){
      if(it->first<gt->first && it->second>gt->second){
        ress+=gt->second-gt->first;
      }
      if(it->first>gt->first && it->second<gt->second) flg=false;
    }
    if(flg) ma.push_back(ress);
  }


  printf("%d\n",res);
  printf("%d",ma.size());
  for(vector<int>::iterator it=ma.begin();it!=ma.end();it++)
    printf(" %d",*it);
  printf("\n");

  return 0;
}

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

using namespace std;

int main() {
    long long int n, k, d[1000]={}, a[200001]={}, i, j, snuk[1000]={}, left[200001]={}, right[200001]={}, dap=0;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>a[i];
       if(i>a[i])
       left[i-a[i]]++;
       if((i+a[i])<=n)
       right[i+a[i]]++;
    }
    
    for(i=1;i<=n;i++)
    {
        dap+=left[i]*right[i];
    }
    cout<<dap;
    return 0;
}

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

using namespace std;

using int64 = long long;
const int INF = 1 << 30;

int D, G;
int P[10], C[10];

int main() {
  cin >> D >> G;
  for(int i = 0; i < D; i++) {
    cin >> P[i] >> C[i];
  }

  int ret = INF;
  for(int i = 0; i < (1 << D); i++) {
    int pt = 0, add = 0;
    for(int j = 0; j < D; j++) {
      if((i >> j) & 1) {
        pt += C[j];
        pt += P[j] * (j + 1) * 100;
        add += P[j];
      }
    }
    vector< int > vs;
    for(int j = 0; j < D; j++) {
      if((i >> j) & 1) continue;
      for(int k = 0; k < P[j]; k++) vs.push_back((j + 1) * 100);
    }
    sort(begin(vs), end(vs));
    while(vs.size() && pt < G) {
      pt += vs.back();
      ++add;
      vs.pop_back();
    }
    if(pt >= G) {
      ret = min(ret, add);
    }
  }
  cout << ret << endl;
}

Measured memory_bytes: 256
#include<iostream>
#define ll long long
using namespace std;

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

	ll n;
	cin >> n;
	ll res = 0;
	for(ll i=1; i<=n; i++){
		if(!(i%3==0 or i%5==0)) res += i;
	}
	cout << res;
	return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
int m;
vector<int>p;
vector<int>s;
int maxn,minn;


int main(){
  int i,j,now=0,ni=0;
  while(1){
  cin >> m >> minn >> maxn;
  now = 0;
  if(m==0&&maxn==0&&minn==0)break;
  for(i=0;i<m;i++){
    cin >> j;
    p.push_back(j);
  }
  sort(p.begin(),p.end());
  for(i=0;i<m-1;i++)  s.push_back(p[i+1]-p[i]);
  for(i=m-minn-1;i>=m-maxn-1;i--){
    // cout << " bbb"<<s[i];
    if(s[i]>=now){
      now = s[i];
      ni = i;
      //cout <<"aaa"<< now << " "<< ni << endl;
    }
  }
  //cout <<endl<< ni << endl;
  cout << m-1-ni << endl;
  while(p.size())p.pop_back();
  while(s.size())s.pop_back();
  }
  return 0;
}


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

int main(){
  int n,x,array[100000],kyori[100000],ans=0;
  cin>>n>>x;
  for(int i=0;i<n;i++){
    cin>>array[i];
    kyori[i]=abs(array[i]-x);//Xからの距離を出す
  }
  for(int i=0;i<n;i++){
    ans=__gcd(ans,kyori[i]);//すべての最大公約数を求める(0とnの最大公約数はn)
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define _LIBCPP_DEBUG 0
using namespace std;
typedef long long int ll;
ll MOD = 1e9 + 7;
int INF = 1 << 30;

int main(void){

    ll A,B,N; cin>>A>>B>>N;
    if(N>=B){
        cout<<floor(A*(B-1)/B)-A*floor((B-1)/B)<<endl;
    }else{
        cout<<floor(A*N/B)-A*floor(N/B)<<endl;
    }

}


Measured memory_bytes: 3736
#include<stdio.h>
#include<math.h>

int main(void){

    double N,D;
    double X,Y;
    double total;
    double count = 0;

    scanf("%lf %lf",&N,&D);

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

        scanf("%lf %lf",&X,&Y);

        total = sqrt((X * X) + (Y * Y));

        if(total <= D){
            count++;
        }
    }

    printf("%.0lf\n",count);

    return 0;
}

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

#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false

int main()
{
   int r,g,b;
   cin>>r>>g>>b;
   (100*r+10*g+b)%4==0?cout<<"YES":cout<<"NO";
   cout<<endl;
   return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <utility>
#include <functional>
#include <deque>
#include <cctype>
#include <stack>
#include <bitset>
#include <set>

using namespace std;
using ll = long long;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, pair<ll, ll>> PP;

const ll MOD = 1e9 + 7;
const ll INF = 1 << 30;
const ll INF2 = 9e18;
const double INF3 = 9e14;
const int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
const int tx[8] = { -1,0,1,-1,1,-1,0,1 }, ty[8] = { -1,-1,-1,0,0,1,1,1 };
#define ALL(x) (x).begin(),(x).end()
#define pb push_back
#define fr first
#define sc second


int main() {
	ll n, ruie[300010] = { 0 }, ruiw[300010] = { 0 }, ans = INF;
	string s;
	cin >> n >> s;


	if (s[0] == 'W') {
		ruiw[0] = 1;
	}
	else {
		ruie[0] =  1;
	}

	for (int i = 1;i < n;i++) {
		if (s[i] == 'W') {
			ruiw[i] = ruiw[i - 1] + 1;
			ruie[i] = ruie[i - 1];
		}
		else {
			ruiw[i] = ruiw[i - 1];
			ruie[i] = ruie[i - 1] + 1;
		}
	}
	ans = ruie[n - 1] - ruie[0];
	for (int i = 1;i < n-1;i++) {
		ans = min(ans, ruiw[i - 1] + (ruie[n - 1] - ruie[i]));
	}
	ans = min(ans, ruiw[n - 2]);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 5508
#include <bits/stdc++.h>
const int N=1e5+5,Mod=1e9+7;
using namespace std;
int n,k,ans,num;
int pri[N],ok[N],g[N],f[N];
inline int A(long long a,long long b){return (a+b)%Mod;}
inline int M(long long a,long long b){return (a*b)%Mod;}
int Q(int b,int t){
	int ret=1;
	for(int i=1;i<=t;i<<=1,b=M(b,b))
		if(i&t) ret=M(ret,b);
	return ret;
}
int main(){
	
	scanf("%d%d",&n,&k);
	for(int i=1;i<=k;++i) f[i]=Q(i,n);
	for(int i=2;i<=k;++i){
		if(!ok[i]) pri[++num]=i;
		for(int j=1;j<=num&&i*pri[j]<=k;++j){
			ok[pri[j]*i]=1;
			if(i%pri[j]==0) break;
		}
	}
	for(int i=1;i<=k;++i)
		g[i]=i;
	for(int i=1;i<=k;++i)
	for(int j=2;i*j<=k;++j)
			g[i*j]-=g[i];
	for(int i=1;i<=k;++i)
		ans=A(ans,M(f[k/i],g[i]));
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 4928
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
template<typename T> inline void chkmin(T &a, const T &b) { a = a < b ? a : b; }
template<typename T> inline void chkmax(T &a, const T &b) { a = a > b ? a : b; }

int arr[205];
LL n;

int main() {
	scanf("%lld", &n); ++n;
	int he = 100, ta = 99, tn = 0, c = 0;
	for (LL i = n; i; i >>= 1) ++tn;
	for (int i = tn - 2; i >= 0; i--) {
		arr[++ta] = ++c;
		if (n >> i & 1) arr[--he] = ++c;
	}
	printf("%d\n", c << 1);
	for (int i = he; i <= ta; i++) printf("%d ", arr[i]);
	for (int i = 1; i <= c; i++) printf("%d ", i);
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#define _USE_MATH_DEFINES
#include<math.h>
#include<algorithm>
#include<memory>
#include<string>
typedef long long ll;
#define Rep(i,n) for(int i = 0;i < (n);i++)	

int gcd(int a, int b) { if (b == 0)  return a;  else  return gcd(b, a % b);  }
int lcm(int a, int b) { return a * b / gcd(a, b); }
void swap(int& a, int& b) { int temp = a; a = b; b = temp; return; }
int ncr(int n, int r) { int a = 1; Rep(i, r) a = (a * (n - i)) / (i + 1); return a; }
int npr(int n, int r) { int a = 1; Rep(i, r) a *= n - i; return a; }
int mod(int a, int b) { return a % b; }

int main() {
	double a;
	std::cin >> a;
	printf("%10.10f", 2 * a * M_PI);
	/*
	int n, m;
	std::vector<int> A;
	std::cin >> n >> m;
	int sum = 0;
	Rep(i, m) {
		int k;
		std::cin >> k;
		sum += k;
	}
	if (sum <= n) {
		std::cout << n - sum << std::endl;
	}
	else {
		std::cout << -1 << std::endl;
	}
	*/
	return 0;
}

Measured memory_bytes: 3752
#include <bits/stdc++.h>
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define SORTR(v,n) sort(v, v+n, greater<int>());
#define SORTPairSecond(v, n) sort(v, v+n, pairCompareSecond);
#define int long long    // %d=>%lld, 1<<n  => 1LL<<n
#define pb push_back

using namespace std;
typedef long long ll;

typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> piii;
typedef pair<ll, pll> plll;
bool pairCompareSecond(const pii& firstEl, const pii& secondEl) {
    return firstEl.second > secondEl.second;
}

const ll MOD = 1000000007;
const int INF = 1000000007;
// const int INF = 0x3f3f3f3f;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;
// const ll LLINF = 1LL << 50;
const double PI = acos(-1);
const double EPS = 0.000000001;

int h,w;
const int MAX_n = 10000;
int n,a[MAX_n];
int ans[50][200];

signed main(){

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

    int k = 0,l = 0;
    for(int i = 0;i < n;i++){
        for(int j = 0;j < a[i];j++){
            ans[k][l] = i+1;
            if(l == w*2-1){
                k++;
                l=0;
            }else{
                l++;
            }
        }
    }
    for(int i = 0;i < h;i++){
        if(i%2 == 0){
            for(int j = 0;j < w;j++){
                cout<< ans[i/2][j]<< " ";
            }
            cout<< endl;
        }else{
            for(int j = 0;j < w;j++){
                cout<< ans[i/2][2*w-1-j]<< " ";
            }
            cout<< endl;
        }
    }


    return 0;
}

Measured memory_bytes: 384
// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}

const int N = 202020 , inf = 1<<26;
int n , b[N] , Q;
pii seg[N];
int add[N << 2] , Mn[N << 2];
inline void Down(int c){
    if(add[c]) {
        add[c << 1] += add[c];
        Mn[c << 1] += add[c];
        add[c << 1 | 1] += add[c];
        Mn[c << 1 | 1] += add[c];
        add[c] = 0;
    }
}
inline void Up(int c){
    Mn[c] = min(Mn[c << 1] , Mn[c << 1 | 1]);
}
void Update(int c,int l,int r,int p,int x){
    if(l == r) Mn[c] = min(Mn[c] , x);
    else {
        int m = (l + r) >> 1;
        Down(c);
        if(p <= m) Update(c << 1 , l , m , p , x);
        else Update(c << 1 | 1 , m + 1 , r , p , x);
        Up(c);
    }
}
void Add(int c,int l,int r,int L,int R,int x){
    if(L <= l && r <= R) {
        add[c] += x;
        Mn[c] += x;
    } else {
        Down(c);
        int m = (l + r) >> 1;
        if(L <= m) Add(c << 1 , l , m , L , R , x);
        if(R > m) Add(c << 1 | 1 , m + 1 , r , L , R , x);
        Up(c);
    }
}
int query(int c,int l,int r,int L,int R){
    if(L <= l && r <= R) return Mn[c];
    else {
        int m = (l + r) >> 1;
        int res = inf;
        Down(c);
        if(L <= m) res = min(res , query(c << 1 , l , m , L , R));
        if(R > m) res = min(res , query(c << 1 | 1 , m + 1 , r , L , R));
        return res;
    }
}

int main(){
    scanf("%d",&n);
    rep(i,1,n+1) scanf("%d",b+i);
    scanf("%d",&Q);
    rep(i,0,Q) scanf("%d%d",&seg[i].fi,&seg[i].se);
    sort(seg,seg+Q);
    int c=0;
    rep(i,1,n+1) Add(1 , 0 , n , i , i , inf);
    rep(i,1,n+1) {
        while(c < Q && seg[c].fi == i) {
            int t = query(1 , 0 , n , 0 , seg[c].se);
            Update(1 , 0 , n , seg[c].se , t);
            ++c;
        }
        if(b[i] == 0) Add(1 , 0 , n , i , n , 1);
        else Add(1 , 0 , n , 0 , i - 1 , 1);
    }
    printf("%d\n",query(1 , 0 , n , 0 , n));
    return 0;
}


Measured memory_bytes: 8960
fn main() {
    let n: i32 = read();
    let chars: Vec<char> = read::<String>().chars().collect();

    let mut count = 0;

    // 000 ~ 999の暗証番号を作成できるかを探索
    for i in 0..1000 {
        let pass = format!("{:0width$}", i, width = 3)
            .chars()
            .collect::<Vec<_>>();

        if can_create(n, &chars, &pass) {
            count += 1;
        }
    }

    println!("{}", count);
}

fn can_create(n: i32, chars: &Vec<char>, pass: &Vec<char>) -> bool {
    // 1文字目があるか
    for j in 0..(n - 2) {
        if chars[j as usize] != pass[0] {
            continue;
        }

        // 1文字目があった場合のみ2文字目探索
        for k in (j + 1)..(n - 1) {
            if chars[k as usize] != pass[1] {
                continue;
            }

            // 2文字目があった場合のみ3文字目探索
            for l in (k + 1)..n {
                if chars[l as usize] != pass[2] {
                    continue;
                }
                return true;
            }

            // 3文字目が見つからない場合は即終了
            return false;
        }

        // 2文字目が見つからない場合は即終了
        return false;
    }

    return false;
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}


Measured memory_bytes: 2272
//author : Yogi79

#include<bits/stdc++.h>
using namespace std;

int main()
{
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   
   long n,cnt=0,k,x;
   cin>>n>>k;
   while(n--)
   {
    cin>>x;
    if(x>=k)
        cnt++;
   }   
   cout<<cnt;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) throws Exception{
		Scanner scn = new Scanner(System.in);
		int n = scn.nextInt();
		int[] a = new int[n+1];
		for(int i=0; i<n; i++){
			a[i] = scn.nextInt();
		}
      	int sum = 0;
      	int x = n;
      	for(int i=0; i<n; i++){
          sum += Math.abs(a[i]-a[x]);
          x = i;
        }
      	sum += Math.abs(a[n-1]-a[n]);
      	x = n;
      	for(int i=0; i<n; i++){
      	  int ans = sum;
      	  ans += Math.abs(a[x] - a[i+1]) - Math.abs(a[i] - a[x]) - Math.abs(a[i+1] - a[i]);
      	  System.out.println(ans);
      	  x = i;
    	}
	}
}


Measured memory_bytes: 60200
#include <iostream>
#include <cstdio>
#include <vector>

using namespace std;

int main()
{
  vector<int> a(10);
  while (scanf("%1d ", &a[0]) == 1) {
    for (int i = 1; i < 10; i++) {
      scanf("%1d ", &a[i]);
    }
    for (int i = 9; i >= 1; i--) {
      vector<int> b(i);
      for (int j = 0; j < i; j++) {
	b[j] = (a[j] + a[j + 1]) % 10;
      }
      a = b;
    }
    printf("%d\n", a[0]);
  }
  return 0; 
}

Measured memory_bytes: 0
def enqueue(t,x):
    list_t = list[t]
    list_t.append(x)
    return list

def front(t):
    list_t = list[t]
    if len(list_t)==0:
        return
    else:
        print(list_t[0])
        return list
def dequeue(t):
    list_t = list[t]
    if len(list_t) ==0:
        return
    else:
        del(list_t[0])
        return list
    
list1 = [int(i) for i in input().split()]
n = list1[0]
q = list1[1]

list=[]

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

for i in range(q):
    list2 = [int(j) for j in input().split()]
    a = list2[0]
    if a == 0:
        t = list2[1]
        x = list2[2]
        enqueue(t,x)
    elif a ==1:
        t = list2[1]
        front(t)
    else :
        t = list2[1]
        dequeue(t)


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

const int N = 100005;
int n, a[N];
bool flag = true;

int main () {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
	for (int i = 1; i <= n; i++) {
		if (a[i] % 2 == 0 && a[i] % 3 && a[i] % 5) flag = false;
	}
	if (flag) puts("APPROVED");
	else puts("DENIED");
	return 0;
}

Measured memory_bytes: 256
N = int(input())
l = list(map(int,input().split()))
sum = 0
flg = True

for i in range(N):
    sum = sum + l[i]
    
for j in range(N):
    if sum - l[j] <= l[j]:
        flg = False
        break
            
if flg == True:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9192
H, W = list(map(int, input().split()))
M = [[-1]*(W+2)]
ans = 0
for _ in range(H):
    s = input()
    ans += s.count('.')
    M.append([-1]+[0 if c=='.' else -1 for c in s]+[-1])
M += [[-1]*(W+2)]

queue = [(1,1)]
M[1][1] = 1
dr = [(+1,0),(-1,0),(0,+1),(0,-1)]
turn = 1
while len(queue)>0:
    turn += 1
    queue_new = []
    for qx, qy in queue:
        for dx, dy in dr:
            x, y = qx+dx, qy+dy
            if M[y][x]==0:
                M[y][x] = turn
                queue_new.append((x,y))
    queue = queue_new

print(ans-M[H][W] if M[H][W]>0 else -1)

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<functional>
#include<algorithm>
using namespace std;

int main(){
  string num;
  int tmp1[11111],tmp2[11111];
  int n;
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> num;
    int x=0,y=0;
    for(int j=0;j<8;j++){
      tmp1[j] = num[j] - '0';
      tmp2[j] = num[j] - '0';
    }
    sort(tmp1,tmp1+8);
    sort(tmp2,tmp2+8,greater<int>());
    for(int j=0;j<8;j++){
      x *= 10;
      y *= 10;
      x += tmp1[j];
      y += tmp2[j];
    }
    cout << y-x << endl;
  }
}

Measured memory_bytes: 1228
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
const ll INF = LONG_MAX;
// const ll MOD = 1000000007;

ll N;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N;
  ll m = INF;
  for (int i = 0; i < 5; i++) {
    ll tmp;
    cin >> tmp;
    if (tmp < m) {
      m = tmp;
    }
  }

  ll ans = 0;
  if (N % m == 0) {
    ans = N / m;
  } else {
    ans = (N / m) + 1;
  }

  cout << ans + 4 << endl;
  return 0;
}

Measured memory_bytes: 256
A = [int(a) for a in input().split()]
N = A[0]
M = A[1]

if(M==0):
    if(N==1):
        print("0")
    if(N==2):
        print("10")
    if(N==3):
        print("100")
    exit()

if(N==1):
    fdigi = 10
    for i in range(M):
        B = [int(b) for b in input().split()]
        s = B[0]
        c = B[1]
        if(fdigi<10 and fdigi!=c):
            print("-1")
            exit()
        else:
            fdigi = c
    if(fdigi==10):
        fdigi = 0
    print(fdigi)

if(N==2):
    fdigi = 10
    sdigi = 10
    for i in range(M):
        B = [int(b) for b in input().split()]
        s = B[0]
        c = B[1]
        if(s==1):
            if(c==0 or (fdigi<10 and fdigi!=c)):
                print("-1")
                exit()
            else:
                fdigi = c
        if(s==2):
            if(sdigi<10 and sdigi!=c):
                print("-1")
                exit()
            else:
                sdigi = c
    if(fdigi==10):
        fdigi=1
    if(sdigi==10):
        sdigi=0
    print(str(fdigi)+str(sdigi))

if(N==3):
    fdigi = 10
    sdigi = 10
    tdigi = 10
    for i in range(M):
        B = [int(b) for b in input().split()]
        s = B[0]
        c = B[1]
        if(s==1):
            if(c==0 or (fdigi<10 and fdigi!=c)):
                print("-1")
                exit()
            else:
                fdigi = c
        if(s==2):
            if(sdigi<10 and sdigi!=c):
                print("-1")
                exit()
            else:
                sdigi = c
        if(s==3):
            if(tdigi<10 and tdigi!=c):
                print("-1")
                exit()
            else:
                tdigi = c
    if(fdigi==10):
        fdigi=1
    if(sdigi==10):
        sdigi=0
    if(tdigi==10):
        tdigi=0
    print(str(fdigi)+str(sdigi)+str(tdigi))

Measured memory_bytes: 3192
def nibungi_search(arr, a)
  return false if arr.size <= 1 && arr.last != a
  mid = (arr.size/2).floor
  n = arr[mid]

  if a == n
    return true
  elsif a > n
    nibungi_search(arr[mid..-1], a)
  else
    nibungi_search(arr[0..mid-1], a)
  end
end

loop do
  n = gets.to_i
  break if n == 0

  arr = gets.split(' ').map(&:to_i).sort
  _q = gets.to_i
  q_arr = gets.split(' ').map(&:to_i)

  count = 0
  q_arr.each do |a|
    count += 1 if nibungi_search(arr, a)
  end
  puts count
end

Measured memory_bytes: 9128
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <set> 
#include <map>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstring>
#include <iomanip>
#define REP(i,n) for(int i=0; i<(n); ++i)
#define FOR(i,a,b) for(int i=(a); i<(b); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const ll INFLL = 1001001001001001001;  // > 10^18
const int MOD = (int)1e9 + 7;
const ll MODLL = (ll)1e9 + 7;
const double EPS = 1e-9;


int main () {
    
    int a,b,c; cin >>a>>b>>c;

    c -= (a-b);

    cout << max(c, 0) << endl;
    
    return 0;
}





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

int main() {
  int N,M;
  cin >> N >> M;
  int A[M];
  for(int i=0;i<M;i++){
    cin >> A[i];
  }
  
  int sum=0;
  for(int i=0;i<M;i++){
    sum += A[i];
  }
  if(N-sum<0){
    cout << -1 << endl;
  }
  else{
    cout << N-sum << endl;
  }
}


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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define INF         INT_MAX/3
#define LLINF       LLONG_MAX/3
#define MOD         (1000000007LL)
#define MODA(a, b)  a=((a)+(b))%MOD
#define MODP(a, b)  a=((a)*(b))%MOD
#define inc(i, l, r)   for(int i=(l);i<(r);i++)
#define dec(i, l, r)   for(int i=(r)-1;i>=(l);i--)
#define pb          push_back
#define se          second
#define fi          first
#define mset(a, b)  memset(a, b, sizeof(a))

using LL  = long long;

int di[] = {0, -1, 0, 1};
int dj[] = {1, 0, -1, 0};
// }}}

struct E {
    LL to, w;
};

using G = vector<vector<E>>;

template <typename T>
pair<vector<T>, vector<int>> dijkstra(G g, int s, T inf) {
    int n = g.size();
    vector<T> d(n, inf);
    vector<int> r(n, -1);
    d[s] = 0;
    using P = pair<T, int>;
    priority_queue<P, vector<P>, greater<P>> pq;
    pq.push({0, s});
    while(!pq.empty()){
        auto c = pq.top();pq.pop();
        if(d[c.second] < c.first) continue;
        for(auto e : g[c.second]){
            if(d[e.to] > d[c.second] + e.w){
                d[e.to] = d[c.second] + e.w;
                r[e.to] = c.second;
                pq.push({d[e.to], e.to});
            }
        }
    }
    return {d, r};
}


// Segment tree {{{
// O(N) 構築
// O(log(N)) update, query
// verified AOJ DSL_2_A
template <typename T>
struct SGT {
    vector<T> v;
    int n;
    T init;
    function<T(T, T)> f;
    SGT(vector<T> a, T init, function<T(T, T)> f){
        int m = a.size();
        n = 1;
        while(n < m) n <<= 1;
        this->init = init;
        this->f = f;
        v.resize(2*n-1, init);
        for(int i=0;i<m;i++) v[n-1+i] = a[i];
        for(int i=n-2;i>=0;i--) v[i] = f(v[i*2+1], v[i*2+2]);
    }
    void update(int i, T x) {
        i += n-1;
        v[i] = x;
        while(i>0){
            i = (i-1)/2;
            v[i] = f(v[i*2+1], v[i*2+2]);
        }
    }
    T query(int a, int b, int k, int l, int r) {
        if(r <= a || b <= l) return init;
        if(a <= l && r <= b) return v[k];
        T vl = query(a, b, k*2+1, l, (l+r)/2);
        T vr = query(a, b, k*2+2, (l+r)/2, r);
        return f(vl, vr);
    }
    T query(int a, int b) {
        return query(a, b, 0, 0, n);
    }
};
// }}}


int main() {
    cin.tie(0);ios::sync_with_stdio(false);
    int n, m, s, t;cin >> n >> m >> s >> t;
    s--;t--;
    G gs(n), gt(n);
    inc(i, 0, m){
        LL u, v, a, b;
        cin >> u >> v >> a >> b;
        u--;v--;
        gs[u].pb({v, a});
        gs[v].pb({u, a});
        gt[u].pb({v, b});
        gt[v].pb({u, b});
    }
    auto ds = dijkstra<LL>(gs, s, LLONG_MAX).fi;
    auto dt = dijkstra<LL>(gt, t, LLONG_MAX).fi;

    vector<LL> v(n);
    LL sunuke = 1e15;
    inc(i, 0, n){
        v[i] = sunuke-(ds[i]+dt[i]);
    }
    SGT<LL> sgt(v, 0, [](LL a, LL b){return max(a, b);});

    inc(i, 0, n){
        cout << sgt.query(i, n) << endl;
    }
    return 0;
}


Measured memory_bytes: 27452