akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <math.h>
#define MAX 10000

int isPrime(int);

int main(){
  
  int n,array[MAX],i,count=0;

  //input
  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%d",&array[i]);
    if(isPrime(array[i])==1) count++;
  }
  
  printf("%d\n",count);
  
  return 0;
}

int isPrime(int x){
  int i;
  
  if(x==2) return 1;
  if(x<2||x%2==0) return 0;

  i=3;
  while(i<=sqrt(x)){
    if(x%i==0) return 0;
    i+=2;
  }
  
  return 1;
}

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

int main(void)
{
    int h, w;
    cin >> h >> w;

    vector<string> maze(h);
    rep(i, h) cin >> maze[i];

    int distv[h][w];
    rep(i, h)rep(j, w) distv[i][j] = -1;
    distv[0][0] = 0;
    queue<pair<int, int> > q;
    q.push(make_pair(0, 0));

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

    while(!q.empty())
    {
        pair<int, int> v = q.front(); q.pop();
        int vx = v.first;
        int vy = v.second;

        rep(i, 4){
            int nx = vx + dx[i];
            int ny = vy + dy[i];

            if(nx < 0 || nx >= h) continue;
            if(ny < 0 || ny >= w) continue;
            if(maze[nx][ny] == '#') continue;
            if(distv[nx][ny] != -1) continue;

            distv[nx][ny] = distv[vx][vy] + 1;
            q.push(make_pair(nx, ny));
        }
    }
    
    int numWall = 0;
    rep(i, h)rep(j, w) if(maze[i][j] == '#') ++numWall;

    int ans = h*w - numWall - (distv[h-1][w-1] + 1);
    if(distv[h-1][w-1] == -1) cout << -1 << endl;
    else cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>

using namespace std;

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

  if (N == M) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cstring>
#include <unordered_set>

#define NMAX 100010
#define MOD 1000000007
#define INF 2000000000
#define PI 3.1415926535
#define EPS 1.e10-6

#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define ABS(a) ((a) > 0 ? (a) : (-a))

typedef unsigned long long ull;

using namespace std;

int n;

int main()
{
	cin >> n;

	for (int i = 0; i <= n; i++)
		if ((int)(i * 1.08) == n)
		{
			cout << i << '\n';
			exit(0);
		}
	cout << ":(\n";
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env ruby
n, m = STDIN.readline.strip.split(' ').map(&:to_i)
py = STDIN.read.split("\n").each_with_index.map{|s, i| s.split(' ').map(&:to_i) + [i] }
def zero_p(i)
  i.to_s.rjust(6, '0')
end
py.sort_by!{|a| [a[0], a[1]]}
# puts "#{py}"
pre_pi = 0
p = []
yi = 0
py.each do |pi, y, i|
  yi = 1 if pre_pi != pi
#  puts "pi:#{pi}, y:#{y}, i:#{i}, yi:#{yi}"
  pre_pi = pi
  p[i] = zero_p(pi) + zero_p(yi)
  yi += 1
end
p.each do |l|
  puts l
end


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

//短縮
#define rep(i,n) for(int i=0;i<(n);++i)
//sort()用
#define all(v) v.begin(), v.end()

using namespace std;

int main(){
  int N,M;
  cin >> N >> M;
  vector<int> H(N);
  rep(i,N) cin >> H.at(i);
  vector<int> A(M);
  vector<int> B(M);
  vector<int> NN(N);

  rep(i,M){
    cin >> A.at(i) >> B.at(i);
  }
  rep(i,N){
    NN.at(i)=1;
  }

  rep(i,M){
    if(H.at(A.at(i)-1) > H.at(B.at(i)-1)){
      NN.at(B.at(i)-1)=0;
    }
    else if(H.at(A.at(i)-1) == H.at(B.at(i)-1)){
      NN.at(B.at(i)-1)=0;
      NN.at(A.at(i)-1)=0;
    }
    else{
      NN.at(A.at(i)-1)=0;
    }
  }

  int sum=0;
  rep(i,N){
    if(NN.at(i)==1){
      sum++;
    }
  }
  cout << sum;
  return 0;
}


Measured memory_bytes: 4844
N = int(input())
A = list(map(int,input().split()))
Ans = 1

if 0 in A:
  Ans = 0

else:
  for i in range(0,N):
    Ans *= A[i]
    if Ans > 1000000000000000000:
      Ans = -1
      break
    
print(Ans)


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

#define st first
#define nd second
#define ll long long
#define ld long double
#define pb push_back
#define emp emplace_back
#define pii pair<int, int>
#define usg unsigned
#define sg signed
#define mp make_pair

using namespace std;

void setIO(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
}

const ld PI = 4*atan((ld)1);
const int INF = 1e9+7;

int main(){
	setIO();
	string s, t;
	cin>>s>>t;
	if(s+t.back()==t) cout<<"Yes\n";
	else cout<<"No\n";
}

Measured memory_bytes: 3616
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v) {
  int sz = v.size();
  for (int i = 0; i < sz; i++) {
    cout << v[i] << " \n"[i == sz - 1];
  }
}

struct Point {
  ld x, y, rad;
};

bool operator<(const Point &lhs, const Point &rhs) { return lhs.rad < rhs.rad; }

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

  int n;
  cin >> n;
  vector<ld> x(n), y(n);
  vector<ld> rad(n);
  vector<Point> ps;
  for (int i = 0; i < n; i++) {
    cin >> x[i] >> y[i];
    complex<ld> c(x[i], y[i]);
    rad[i] = arg(c) / acos(-1.0) * 180;
    if (rad[i] < 0) rad[i] += 360;
    ps.push_back(Point{x[i], y[i], rad[i]});
  }
  sort(ps.begin(), ps.end());
  ld ret = 0;
  for (int i = 0; i < n; i++) {
    ld xsum = 0, ysum = 0;
    for (int j = 0; j < n; j++) {
      // ps[i] ~ ps[i+j]
      int index = (i + j) % n;
      xsum += ps[index].x;
      ysum += ps[index].y;
      ret = max(ret, sqrt(xsum * xsum + ysum * ysum));
    }
  }
  cout << fixed << setprecision(20) << ret << endl;
}


Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

	static Scanner scanner;

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

        String S=gs();
        int a=Integer.parseInt(S.substring(0, 1));
        int b=Integer.parseInt(S.substring(1, 2));
        int c=Integer.parseInt(S.substring(2, 3));
        int d=Integer.parseInt(S.substring(3, 4));
        
        for (int i=0; i< 8; i++) {
            int r = a;
            String sb="-";
            String sc="-";
            String sd="-";
            if((i>>0 & 1) == 0) {
            	r-=b;
            } else {
            	r+=b;
            	sb="+";
            }
            if((i>>1 & 1) == 0) {
            	r-=c;
            } else {
            	r+=c;
            	sc="+";
            }
            if((i>>2 & 1) == 0) {
            	r-=d;
            } else {
            	r+=d;
            	sd="+";
            }
            if(r==7) {
            	System.out.print(a+sb+b+sc+c+sd+d+"=7");
            	return;
            }
        }

//        if (s>L[n-2]) {
//        	System.out.println("Yes");
//        }else {
//        	System.out.println("No");
//        }
	}


	public static long uclid(long m, long n) {
    	if (m<n) {
			m^=n;
			n^=m;
			m^=n;
		}

		while(true) {
			long t=m%n;
			if (t==0) {
				return n;
			} else {
				m=n;
				n=t;
			}
		}
    }

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

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

int main(){
  int h,w,k;
  cin >> h >> w >> k;

  vector<string> s(h);
  for (int i = 0; i < h; i++)
  {
    cin >> s[i];
  }

  int ans = 0;
  for (int bith = 0; bith < (1<<h); bith++)
  {
    vector<bool> hflag(h,false);
    for (int i = 0; i < h; i++)
    {
      if((1<<i)&bith){
        hflag[i] = true;
      }
    }

    for (int bitw = 0; bitw < (1<<w); bitw++)
    {
      vector<bool> wflag(w,false);
      for (int i = 0; i < w; i++)
      {
        if((1<<i)&bitw){
          wflag[i] = true;
        }
      }
      
      int cnt = 0;
      for (int i = 0; i < h; i++)
      {
        if(hflag[i]) continue;
        for (int j = 0; j < w; j++)
        {
          if(wflag[j]) continue;
          if(s[i][j]=='#') cnt++;
        }
      }
      if(cnt==k){
        ans++;
        // cout << "bith=" << bith << endl;
        // cout << "bitw=" << bitw << endl;
      }
        // cout << "bith=" << bith << endl;
        // cout << "bitw=" << bitw << endl;
        // cout << endl;
    }    
  }
  cout << ans << endl;  
}

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

int main(){
  int N,K,tanka;
  int ans=0;
  priority_queue<int,vector<int>,greater<int>> val;
  cin >>N>>K;

  for(int i=0;i<N;i++){
    cin>>tanka;
    val.push(tanka);
  }
  
  for(int i=0;i<K;i++){
     ans+=val.top();
    val.pop();
  }    
   cout << ans;
return 0;
}

Measured memory_bytes: 3596
#include <cstdio>
#include <cctype>
#include <utility>
#include <vector>
#include <algorithm>
using namespace std;

#define gcu getchar_unlocked
#define pcu putchar_unlocked
#define _T template <typename T>
#define _HT template <typename H, typename... T>
#define _il inline
#define _in _il int in
#define _sc _il bool scan
_T T in(int c){T n=0;bool m=false;while(isspace(c)){c=gcu();}if(c=='-')m=true,c=gcu();
	do{n=10*n+(c-'0'),c=gcu();}while(c>='0'&&c<='9');return m?-n:n;}
_in() {return in<int>(gcu());}
_T T scan(T &n){int c=gcu();return c==EOF?false:(n=in<T>(c),true);}
_sc(char &c){c=gcu();gcu();return c!=EOF;}
#ifdef _GLIBCXX_STRING
_sc(string &s){int c;s="";
	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=c;}}
#endif
_HT _sc(H &h, T&&... t){return scan(h)&&scan(t...);}
#define _vo _il void out
#define _vl _il void outl
_vo(bool b) {pcu('0'+b);}
_vo(const char *s){while(*s)pcu(*s++);}
_vo(char c){pcu(c);}
#ifdef _GLIBCXX_STRING
_vo(string s){for(char c:s)pcu(c);}
#endif
_T _vo(T n){static char buf[20];char *p=buf;
	if(n<0)pcu('-'),n*=-1;if(!n)*p++='0';else while(n)*p++=n%10+'0',n/=10;
	while (p!=buf)pcu(*--p);}
_vl(){out('\n');}
#ifdef _GLIBCXX_VECTOR
_T _vo(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);outl();}
#endif
_HT _vo(H&& h, T&&... t){out(h);out(move(t)...);}
template <typename... T> _vl(T&&... t){out(move(t)...);outl();}

int main() {
	for (int t = in(); t; t--) {
		int n = in() - 1, k = in() - 1, p = in(), r = 0;
		vector<int> v;
		while (n--) {
			int c = in(), d = c - p;
			r += d;
			v.push_back(d);
			p = c;
		}
		auto m = v.begin() + min((int) v.size(), k);
		nth_element(v.begin(), m, v.end(), [](int a, int b) {return a > b;});
		for_each(v.begin(), m, [&r](int i){r -= i;});
		outl(r);
	}
}


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

int main()
{
	int r, c, x;
	cin >> r >> c;

	int table[r+1][c+1];

	for(int i=0; i<r+1; ++i)
		for(int j=0; j<c+1; ++j)
			table[i][j] = 0;

	for(int i=0; i<r; ++i) {
		for(int j=0; j<c; ++j) {
			cin >> x;
			table[i][j] = x;
			table[i][c] += x;
			table[r][j] += x;
		}
		table[r][c] += table[i][c];
	}

	++r; ++c;
	for(int i=0; i<r; ++i) {
		for(int j=0; j<c; ++j) 
			cout << table[i][j] << ( (j<c-1) ? " " : "" );
		cout << '\n';
	}

	return 0;
}




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

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

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

void BubbleSort(int n, pair<char, int> *a) {
  bool flag = true;
  rep(j, n) {
    rep(i, n - 1) {
      if (a[i + 1].second < a[i].second) {
        pair<char, int> tmp = a[i];
        a[i] = a[i + 1];
        a[i + 1] = tmp;
      }
    }
  }
}

void SelectStort(int n, pair<char, int> *a) {
  rep(i, n) {
    int minj = i;
    for (int j = i; j < n; j++) {
      if (a[j].second < a[minj].second) {
        minj = j;
      }
    }
    pair<char, int> tmp = a[i];
    a[i] = a[minj];
    a[minj] = tmp;
  }
}

void Print(int n, pair<char, int> *a, string ans) {
  rep(i, n) {
    cout << a[i].first << a[i].second;
    if (i != n - 1) cout << ' ';
    else cout << endl;
  }
  cout << ans << endl;
}

string IsStable(int n, pair<char, int> *a, pair<char, int> *sort_a) {
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      for (int k = 0; k < n; k++) {
        for (int l = k + 1; l < n; l++) {
          if ((a[i].second == a[j].second) && (a[i] == sort_a[l]) && (a[j] == sort_a[k])) {
            return "Not stable";
          }
        }
      }
    }
  }
  return "Stable";
}

int main() {
  int n;
  pair<char, int> a[36] = {};
  cin >> n;
  rep(i, n) {
    string s;
    cin >> s;
    a[i].first = s[0];
    s = s.substr(1, s.size());
    a[i].second = stoi(s);
  }
  pair<char, int> bubble_a[36] = {};
  pair<char, int> select_a[36] = {};
  rep(i, n) {
    bubble_a[i] = a[i];
    select_a[i] = a[i];
  }
  BubbleSort(n, bubble_a);
  string bubble_ans = IsStable(n, a, bubble_a);
  Print(n, bubble_a, bubble_ans);
  SelectStort(n, select_a);
  string select_ans = IsStable(n, a, select_a);
  Print(n, select_a, select_ans);
  return 0;
}



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

typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;

const int INF = 1e9;

class SegmentTree {
    private: vi st, A;
             int n;
             int left(int p){return p<<1;}
             int right(int p){return (p<<1)+1;}

             void build(int p, int L, int R){
                 if(L == R)
                     st[p] = L;
                 else{
                     build(left(p), L, (R+L)/2);
                     build(right(p), (R+L)/2+1, R);
                     int p1 = st[left(p)], p2 = st[right(p)];
                     st[p] = (A[p1] >= A[p2]) ? p1 : p2;
                }
             }
            
             int rmq(int p, int L, int R, int i, int j){
                 if(L > j || R < i) return -1;
                 if(L >= i && R <= j) return st[p];

                 int p1 = rmq(left(p), L, (L+R)/2, i, j);
                 int p2 = rmq(right(p), (L+R)/2+1, R, i, j);

                 if(p1 == -1) return p2;
                 if(p2 == -1) return p1;

                 return (A[p1] >= A[p2]) ? p1 : p2;
             }

             void update(int p, int L, int R, int i, int j, int x){
                //printf("%d %d %d %d %d %d\n", p, L, R, i, j, x);
                if(L > j || R < i) return;
                if(L >= i && R <= j){
                    st[p] = L;
                    return;
                }

                update(left(p), L, (L+R)/2, i, j, x);
                update(right(p), (L+R)/2+1, R, i, j, x);
                
                st[p] = ( (A[st[left(p)]] >= A[st[right(p)]]) ? st[left(p)] : st[right(p)] );
             }

    public:
             SegmentTree(const vi &_A){
                 A = _A; n = (int)A.size();
                 st.assign(4*n, 0);
                 build(1, 0, n-1);
             }

             int rmq(int i, int j){ return rmq(1, 0, n-1, i, j); }
             void update(int i, int j, int x){
                 for(int m = i; m <= j; m++) A[m] = x;
                 update(1, 0, n-1, i, j, x);
             }
};
                 
int main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);

//    int arr[] = {18, 17, 13, 19, 15, 11, 20};
//    vi A(arr, arr+7);
//    SegmentTree st(A);
//    cout << st.rmq(1, 3) << endl;
//    cout << "update" << endl;
//    st.update(5, 5, 100);
//    st.update(1, 1, 10);
//    st.update(3, 3, 12);
//    cout << st.rmq(1, 3) << endl;
//    cout << st.rmq(4, 6) << endl;
//
//    cout << endl;

    int N, K, NMAX = 300005; cin >> N >> K;
    vi A; A.resize(NMAX, 0);
    SegmentTree st(A);
    int sol = 0;

    for(int i = 0; i < N; i++){
        int x; cin >> x;
        int m = max(A[( (x-K>=0) ? st.rmq(x-K, x) : st.rmq(0, x))],  A[( (x+K<NMAX) ? st.rmq(x,  x+K) : st.rmq(x, NMAX-1) )]) + 1; 
        st.update(x, x, m);
        A[x] = m;
        sol = max(sol, m);
    }

    cout << sol << endl;
    
//    freopen("out.txt", "w", stdout);

    return 0;

}


Measured memory_bytes: 10356
N, M = map(int, input().split())
P = [0]*M
Y = [0]*M
for i in range(M):
    P[i],Y[i] = map(int, input().split())

# print(N, M, P, Y)

table = {}
for i in range(M):
    p = P[i]
    y = Y[i]
    data = (i, y)
    if p not in table:
        table[p] = [data]
    else:
        table[p].append(data)

# print(table)

for t in table:
    table[t].sort(key=lambda x: x[1])

# print(table)

ans = {}
for t in table:
    data = table[t]
    for i in range(len(data)):
        d = data[i]
        ans[d[0]] = (P[d[0]], i + 1)

# print(ans)

for i in ans:
    a = ans[i]
    print('{:06d}{:06d}'.format(a[0], a[1]))

Measured memory_bytes: 77396
"use strict";
var input=require("fs").readFileSync("/dev/stdin","utf8");
var cin=input.split(/ |\n/),cid=0;
function next(a){return a?cin[cid++]:+cin[cid++];}
function nexts(n,a){return a?cin.slice(cid,cid+=n):cin.slice(cid,cid+=n).map(a=>+a);}
function nextm(h,w,a){var r=[],i=0;if(a)for(;i<h;i++)r.push(cin.slice(cid,cid+=w));else for(;i<h;i++)r.push(cin.slice(cid,cid+=w).map(a=>+a));return r;}
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill().map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill().map(x=>"+r+")";return eval(r);}

var myOut = main();
if(myOut !== undefined)console.log(myOut);

function main(){
  var [n,k] = nexts(2);
  var b = xArray(0,n+1);
  var ans = n;
  for(var i = 0; i < k; i++){
    var d = next();
    for(var j = 0; j < d; j++){
      var a = next();
      if(b[a-1] === 0)ans--;
      b[a-1] = 1;
    }
  }
  return ans;
}

Measured memory_bytes: 32144
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		List<Integer> list = new ArrayList<>();
		for (int i = 0; i < n; i++) {
			list.add(sc.nextInt());
		}
		int q = sc.nextInt();
		for (int i = 0; i < q; i++) {
			int b  = sc.nextInt();
			int e = sc.nextInt();
			int k = sc.nextInt();
			int count = 0;
			for (int j = b; j < e; ++j) {
				if (list.get(j) == k) {
					++count;
				}
			}
			System.out.println(count);
		}
	}
}



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

#define FOR(i,l,r) for(int i = (l);i < (r);i++)
#define ALL(x) (x).begin(),(x).end()
template<typename T> void chmax(T& a,const T& b){if(a < b) a = b;}
template<typename T> void chmin(T& a,const T& b){if(b < a) a = b;}
typedef long long ll;

string S;

int main()
{
	cin >> S;
	S.insert(4," ");

	cout << S << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
#define rall(a) (a).rbegin(),(a).rend()
const int INF = 2e9;
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

int main(){
    int a, b, c; cin >> a >>b >> c;
    if(b-a == c-b) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{      int a;
        cin >> a;
        if (a <=104)
              {cout << 0;}
        else if (a <= 134)
              {cout << 1;}
        else if(a <= 164)
             {cout << 2;}
        else if(a <= 188)
             {cout << 3;}
        else if(a <= 194)
             {cout << 4;}
        else 
             {cout << 5;}
    return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
    #include <string.h>
     
    int main(void) {
    	char s[200];
    	scanf ("%s", s);
    	int n = strlen(s);
    	for(int i = n-2; i; i-=2) {
    		if(strncmp(s, s+i/2, i/2) == 0) {
    			printf("%d\n", i);
    			return 0;
    		}
    	}
    	return 0;
    }

Measured memory_bytes: 128
"""
~~ author : dokueki
~~ created : 10~05~2020
"""

import sys
INT_MAX = sys.maxsize
INT_MIN = -(sys.maxsize)-1
sys.setrecursionlimit(10**7)
mod = 1000000007


def IOE():
    sys.stdin = open("input.txt", "r")
    sys.stdout = open("output.txt", "w")


def main():
    n, k = map(int, sys.stdin.readline().split())
    v = set()
    for i in range(k):
        d = int(sys.stdin.readline())
        a = list(map(int, sys.stdin.readline().split()))
        for i in a:
            v.add(i)
    print(n - len(v))


if __name__ == "__main__":
    try:
        IOE()
    except:
        pass
    main()


Measured memory_bytes: 67672
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x) x
#define rep(...) MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c) c.begin(),c.end()
#define mp make_pair
#define write(x) cout<<(x)<<"\n"
using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vll;
template<class T>using vv = vector<vector<T>>; template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T>bool chmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
template<class T>bool chmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

using TP = pair<pair<int, int>, int>;
using Q = pair<pair<int, int>, TP>;

int N, M;
vv<int> graph;
vector<ll> dist;
vv<bool> visited;

void bfs_kkp(int s, int t) {
    dist.assign(graph.size(), LINF);
    dist[s] = 0;
    queue<Q> que;
    que.emplace(mp(s, 0), TP(mp(-1, -1), -1));

    while (!que.empty()) {
        auto& q = que.front();
        int& v = q.first.first;
        int& d = q.first.second;
        TP& h = q.second;

        if (d % 3 == 0) {
            dist[v] = d / 3;

            if (v == t) break;
        }

        for (int u : graph[v]) {
            if (visited[u][d % 3] == false) {
                visited[u][d % 3] = true;
                que.emplace(mp(u, d + 1), TP(mp(h.first.second, h.second), v));
            }
        }

        que.pop();
    }
}

int main() {
    cin >> N >> M;
    graph.resize(N);
    rep(i, M) {
        int u, v;
        cin >> u >> v;
        graph[u - 1].push_back(v - 1);
    }
    int S, T;
    cin >> S >> T;

    visited = vvec(N, 3, false);
    bfs_kkp(S - 1, T - 1);
    
    if (dist[T - 1] == LINF) {
        write(-1);
    }
    else {
        write(dist[T - 1]);
    }
}

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

int main () {

    int N, K;
    scanf("%d %d", &N, &K);

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

    sort(x, x + N, greater<int>());

    long long ans = INT_MAX;

    for (int i = 0; i < N-K+1; i++) {
        long long left = x[i], right = x[i+K-1];

        if (left * right >= 0) {
            ans = min(ans, max(abs(left), abs(right)));
        }
        else {
            ans = min(ans, min(2*abs(left)+abs(right), 2*abs(right)+abs(left)));
        }
    }
    printf("%lld\n", ans);

    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main() {

long long int x,a,b,ans;
cin>>x;
for(ll i=1;i<=1000;i++)
	for(ll j=-1000;j<=1000;j++)
    {
    	ans=pow(i,5);ans-=pow(j,5);
    	if(ans==x)
    	{
    		a=i;b=j;goto end;
    	}
    }
end: ;
cout<<a<<" "<<b;

}

Measured memory_bytes: 4100
#include <iostream>
using namespace std;
int main() {
    int N, T;
    cin >> N >> T;
    int minC = 1001;
    for (int i=0; i<N; i++) {
        int c, t;
        cin >> c >> t;
        if (t <= T) {
            minC = min(minC, c);
        }
    }
    if (minC > 1000) {
        cout << "TLE" << endl;
    } else {
        cout << minC << endl;
    }
}

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

int main() {
	int n, k, c;
	string s;
	cin >> n >> k >> c >> s;

	vector<int> r1(k), r2(k);
	int ci = 0;
	for(int i = 0; i < n; i++) {
		if (s[i] == 'o') {
			r1.at(ci) = i;
			if (ci == k - 1) break;
			ci++;
			i += c;
		}
	}
	ci = k - 1;
	for(int i = n - 1; i >= 0; i--) {
		if (s[i] == 'o') {
			r2.at(ci) = i;
			if (ci == 0) break;
			ci--;
			i -= c;
		}
	}
	for(int i = 0; i < k; i++) {
		if (r1.at(i) == r2.at(i)) {
			cout << r1.at(i) + 1 << endl;
		}
	}
}



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

bool isprime(int x){
  if(x==2)
   return true;

  if(x<2 || x%2==0)
   return false;

  for(int i=3; i*i<=x; i++){
    if(x%i==0)
     return false;
  }
  return true;
}

int main(){
  int n;
  cin >> n;

  int cnt;

  for(int i=0; i<n; i++){
    int x;
    cin >> x;

    if(isprime(x)){
      cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}



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

typedef long long LL;

const int N=1000000,mod=1000000007;

int add(int a,int b,int p=mod){return a+b>=p?a+b-p:a+b;}
int sub(int a,int b,int p=mod){return a-b<0?a-b+p:a-b;}
int mul(int a,int b,int p=mod){return (LL)a*b%p;}
void sadd(int &a,int b,int p=mod){a=add(a,b,p);}
void ssub(int &a,int b,int p=mod){a=sub(a,b,p);}
void smul(int &a,int b,int p=mod){a=mul(a,b,p);}
int Power(int a,int k,int p=mod){int res=1;for (;k;k>>=1,smul(a,a,p)) if (k&1) smul(res,a,p);return res;}
int Get_inv(int a,int p=mod){return Power(a,p-2,p);}

int n,h,d;

void into(){
  scanf("%d%d%d",&n,&h,&d);
}

int dp[N+9],sum[N+9];

void Get_dp(){
  int s=0;
  for (int i=1,fac=1;i<=n;++i) smul(fac,i),sadd(s,fac);
  sum[0]=dp[0]=Get_inv(s);
  for (int i=1;i<=h;++i) sum[i]=add(sum[i-1],dp[i]=mul(sub(sum[i-1],i>d?sum[i-d-1]:0),s));
  for (int i=1;i<=n;++i) smul(dp[h],i);
}

void work(){
  Get_dp();
}

void outo(){
  printf("%d\n",dp[h]);
}

int main(){
  into();
  work();
  outo();
  return 0;
}

Measured memory_bytes: 11636
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define SIZE 100100

bool is_prime[SIZE];

int main(){

	is_prime[0] = false;
	is_prime[1] = false;

	for(int i = 2; i < SIZE; i++){
		is_prime[i] = true;
	}

	vector<int> V;

	for(int i = 2; i < SIZE; i++){
		if(!is_prime[i])continue;

		V.push_back(i);

		for(int k = 2*i; k < SIZE; k += i){

			is_prime[k] = false;
		}
	}

	int X;
	scanf("%d",&X);

	int loc = lower_bound(V.begin(),V.end(),X)-V.begin();

	printf("%d\n",V[loc]);





	return 0;
}


Measured memory_bytes: 512
#include <stdio.h>

int main(void){
    int N,M,i,o,max,res,line[1000]={0},ans[1000]={0},b;
    scanf("%d %d",&N,&M);
    for(i=0;i<N;i++)
        scanf("%d",&line[i]);
    for(i=0;i<M;i++){
        scanf("%d",&b);
        for(o=0;o<N;o++){
            if(line[o] <= b){
                ans[o]++;
                break;
            }
        }
    }
    for(max=0,i=0;i<N;i++){
        if(max < ans[i]){
            max=ans[i];
            res=i+1;
        }
    }
    printf("%d\n",res);
    return 0;
}

Measured memory_bytes: 604
#include <iostream>
#include <cstring>
#define Max 1000000001
using namespace std;
char temp[Max];
int main(){
    int n,q;
    int S[10000];
    int T[500];
    int count=0;
    //memset(temp,'0',Max);
    
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>S[i];
    cin>>q;
    for(int i=0;i<q;i++)
        cin>>T[i];
    for(int i=0;i<n;i++)
        temp[S[i]]='1';
    for(int i=0;i<q;i++)
        if(temp[T[i]]=='1')
            count++;
    cout<<count<<endl;
    return 0;
}


Measured memory_bytes: 6244
#include<cstdio>
#define maxn 200005
int n,k,l,r;
bool rev;
char s[maxn];
int main()
{
	scanf("%d%d%s",&n,&k,s);
	for(int i=0;i<n;i++) s[i]-=65;
	if(k>n*2+1) k=k%2?(n*2+1):(n*2+2);
	r=n-1;
	for(int i=1;i<=k;i++) 
	{
		if(!(s[l]^rev)) s[l]^=1;
		else l=(l+1)%n,r=(r+1)%n,rev^=1;
	}
	for(;;l=(l+1)%n)
	{
		printf("%c",65+(s[l]^rev));
		if(l==r) break;
	}
}

Measured memory_bytes: 512
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
      int H=sc.nextInt();
      int N=sc.nextInt();
      int[] A=new int[N];
      for(int i=0;i<N;i++){
         A[i]=sc.nextInt();
         H-=A[i];
      }
      if(H<=0){
         System.out.print("Yes");
      }else{
         System.out.print("No");
      }
   }
}
         


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

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

    for(;;){
        int w, h;
        cin >> w >> h;
        if(w == 0)
            return 0;

        int y = 1;
        int x = 1;
        int d = 0;
        for(;;){
            string s;
            cin >> s;
            if(s == "FORWARD"){
                int k;
                cin >> k;
                y += dy[d] * k;
                x += dx[d] * k;
                y = max(1, min(h, y));
                x = max(1, min(w, x));
            }else if(s == "BACKWARD"){
                int k;
                cin >> k;
                y -= dy[d] * k;
                x -= dx[d] * k;
                y = max(1, min(h, y));
                x = max(1, min(w, x));
            }else if(s == "RIGHT")
                d = (d + 1) % 4;
            else if(s == "LEFT")
                d = (d + 3) % 4;
            else
                break;
        }
        cout << x << ' ' << y << endl;
    }
}

Measured memory_bytes: 0
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        int price;
        if(n*a < b){
            price = n*a;
        }else{
            price = b;
        }
		System.out.println(price);
	}
}

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

#define ll long long
#define MOD 1000000007

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

	int n;
	cin>>n;
	int r;
	while(n>0) {
		r=n%10;
		if(r==7) {
			break;
		}
      n/=10;
	}	
	if(n) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	
	return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <stack>

using namespace std;

int N;

int main(){
  while(cin >> N){
    vector<int> v(N);
    for(int i = 0 ; i < N ; i++) cin >> v[i];
    v.erase(unique(v.begin(), v.end()), v.end());
    
    int ans = 1;
    
    stack<int> st;
    st.push(v[0]);
    
    for(int i = 1 ; i < v.size() ; i++){
      if(v[i] > v[i-1]){
	ans++;
	st.push(v[i]);
      }
      else{
	while(!st.empty() && st.top() > v[i]) st.pop();
	
	if(st.empty() || st.top() < v[i]) ans++;
	st.push(v[i]);
      }
    }

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

Measured memory_bytes: 2588
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            out.println((int) Math.pow(in.nextInt(), 2) - in.nextInt());
        }

    }

    static class InputReader {
        private int lenbuf = 0;
        private int ptrbuf = 0;
        private InputStream in;
        private byte[] inbuf = new byte[1024];

        public InputReader(InputStream in) {
            this.in = in;
        }

        private int readByte() {
            if (lenbuf == -1) throw new InputMismatchException();
            if (ptrbuf >= lenbuf) {
                ptrbuf = 0;
                try {
                    lenbuf = in.read(inbuf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (lenbuf <= 0) return -1;
            }
            return inbuf[ptrbuf++];
        }

        public int nextInt() {
            int num = 0, b;
            boolean minus = false;
            while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
            if (b == '-') {
                minus = true;
                b = readByte();
            }

            while (true) {
                if (b >= '0' && b <= '9') {
                    num = num * 10 + (b - '0');
                } else {
                    return minus ? -num : num;
                }
                b = readByte();
            }
        }

    }
}



Measured memory_bytes: 21332
#include <sstream>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <string>
#include <queue>
#include <bitset>
#define int long long
#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)
#define FORD(i, a, b) for (int i = (a), _b = (b); i >= _b; --i)
#define REP(i, a) for (int i = 0, _a = (a); i < _a; ++i)

#define DEBUG(X) { cerr << #X << " = " << (X) << endl; }
#define PR(A, n) { cerr << #A << " = "; FOR(_, 1, n) cerr << A[_] << ' '; cerr << endl; }
#define PR0(A, n) { cerr << #A << " = "; REP(_, n) cerr << A[_] << ' '; cerr << endl; }

#define sqr(x) ((x) * (x))
#define ll long long
#define __builtin_popcount __builtin_popcountll
#define SZ(x) ((int)(x).size())
using namespace std;

double safe_sqrt(double x) { return sqrt(max((double)0.0, x)); }
int GI(int& x) { return scanf("%lld", &x); }

int n, a, b;
int x[100111];

#undef int
int main() {
#define int long long
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout << (fixed) << setprecision(9);
    while (GI(n) == 1) {
        GI(a); GI(b);
        FOR(i,1,n) GI(x[i]);
        sort(x+1, x+n+1);

        int res = 0;
        FOR(i,2,n) {
            int len = x[i] - x[i-1];
            res += min(len * a, b);
        }
        cout << res << endl;
    }
}


Measured memory_bytes: 1024
"use strict";
function I(t,i){this._s=t.split("\n"),this._c=0,this._l=0,this._f=i||Number}I.prototype.a=function(t){var i=this._s[this._l];if(i){var s=i.trim().split(" "),h=s[this._c];return this._c++,s.length===this._c&&(this._c=0,this._l++),t?t(h):this._f(h)}},I.prototype.l=function(t){var i=this._s[this._l];if(i)return this._c=0,this._l++,i.split(" ").map(t||this._f)},module.exports=I;

function main(input) {
  var o = new I(input);

  var m = o.a();
  var k = o.a();
  if (m === 0 && k === 0) {
    console.log("0 0");
  } else if (m === 0) {
    console.log("-1");
  } else if (m === 1 && k === 0) {
    console.log("1 0 0 1");
  } else if (m === 1 && k === 1) {
    console.log("-1");
  } else if (k < Math.pow(2, m)) {
    var arr = [];
    for (var i = 0; i < Math.pow(2, m); i++) {
      if (i !== k) arr.push(i);
    }
    arr.push(k);
    for (var i = Math.pow(2, m) - 1; i >= 0; i--) {
      if (i !== k) arr.push(i);
    }
    arr.push(k);
    console.log(arr.join(" "));
  } else {
    console.log("-1");
  }

}


main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 35788
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(x) (x).begin(),(x).end()
#define dup(x,y) (((x)+(y)-1)/(y))
#define sz(x) (int)(x).size()
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main(){
    int n;
    cin >> n;
    if(n%2 == 0) cout << n << endl;
    else cout << n*2 << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
	int S,h=0,m=0,s=0,a=0;
	scanf("%d",&S);
	h=S/3600;
	a=S%3600;
	m=a/60;
	a=a%60;
	s=a;
	printf("%d:%d:%d\n",h,m,s);
	return 0;
}

Measured memory_bytes: 592
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define FOR(i, a, b) for(i = a; i < b; ++i)
#define REP(i, n) FOR(i, 0, n)
#define comp(a, b) int comp(const void *a, const void *b)
#define MOD  1000000007

typedef unsigned int uint;
typedef unsigned long ul;
typedef long long ll;
typedef unsigned long long ull;

void TF_print(char boolean, char T[], char F[]){
    if(boolean){
        printf("%s\n", T);
    }else{
        printf("%s\n", F);
    }
}

comp(a, b){
    return *(uint*)b - *(uint*)a;
}

int main(){
    uint i, N, K;
    uint ANS = 0;
    scanf("%u %u", &N, &K);
    int num[N], temp;

    REP(i, N){
        num[i] = 0;
    }
    REP(i, N){
        scanf("%u", &temp);
        num[temp - 1]++;
    }
    qsort(num, N, sizeof(uint), comp);
    i = K;

    while(num[i] > 0 && i < N){
        ANS += num[i];
        i++;
    }
    printf("%u\n", ANS);
    return 0;
}

Measured memory_bytes: 1404
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll INF = 1e9+7;
ll MOD = 998244353;
typedef pair<ll,ll> ii;
#define iii pair<ii,ll>
#define f(i,a,b) for(ll i = a;i < b;i++)
#define rf(i,a,b) for(long long i=a;i>=b;i--)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define w(t) while(t--)
#define c(n); cin>>n;
#define p(n) cout<<n;
#define pl(n) cout<<n<<"\n";
#define ps(n); cout<<n<<" ";
#define F first
#define S second
#define pb(a) push_back(a)
#define all(x) (x).begin(), (x).end()
#define ull unsigned long long
#define vll vector<ll>
#define vii vector<ii>
#define mkp make_pair
#define ld long double
#define arrin(a,n) f(i,0,n){cin>>a[i];}
#define arrout(a,n) f(i,0,n){cout<<a[i]<<" ";}
#define printclock cerr<<"Time : "<<10000005*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
#define PI (2*acos(0))
#define EPS 1e-18
const long long N = 1e5+5;
vll visit,dist,taken;
vector<vll> adj;
vector<vii> adj2;
priority_queue<ii,vector<ii>, greater<ii> > pq;
ll bit[N];
ll an[N][35];
ll depth[N]={0};
ll siz;
ll res = 0;
ll lcm(ll a,ll b){return (a * b) / __gcd(a,b);}
ll gcd(ll a,ll b){return __gcd(a,b);}
ll power(ll a,ll b){if(b == 0)return 1;if(b == 1)return a;ll ans = power(a,b/2) % MOD;ans *= ans;ans %= MOD;if(b % 2 == 1)ans *= a;return ans%MOD;}
ll inverse(ll x){x%=MOD;return power(x,MOD-2);}
void BITup(ll k, ll x){while(k <= siz){bit[k]+=x;k += k & -k;}}
ll BITq(ll k){ll s=0;while(k>=1){s+=bit[k];k -= k &-k;}return s;}
struct point{ll x,y,idx;};
int main(void){
    fastio;
    ll n,s;
    cin>>n>>s;
    ll arr[n];
    arrin(arr,n);
    ll dp[n+1][s+1];
    ///dp[i][j] = ways to choose the sum j with the first i elements
    ///base case dp[0][0] = 2^n (all subsets) and all other dp[0][j] = 0
    f(i,1,s+1){
        dp[0][i] = 0;
    }
    ll inv = inverse(2);
    dp[0][0] = power(2,n);
    f(i,1,n+1){
        f(j,0,s+1){
            ///surely in the first i elements there are dp[i-1][j] solution
            dp[i][j] = dp[i-1][j];
            ///however we must add the solution which uses the new element (arr[i-1])
            if(j >= arr[i-1]){
                ///dp[i][j] += (dp[i-1][j-arr[i-1]] / 2) because there are dp[i-1][j-arr[i-1]] sums that gives the sum j-arr[i-1] and we divided with 2
                ///because the half of the solutions of dp[i-1][j-arr[i-1]] don't have a subset with sum j
                dp[i][j] = (dp[i][j] + (dp[i-1][j-arr[i-1]] * inv) % MOD) % MOD;
            }
        }
    }
    cout<<dp[n][s];
}


Measured memory_bytes: 74016
def recursive(num, n):
    if int(num) > n:
        return 0
    if all(num.count(val) for val in '357'):
        count = 1
    else:
        count = 0
    for val in '357':
        count += recursive(num+val, n)
    return count


def main():
    n = int(input())
    num = '0'
    count = recursive(num, n)
    print(count)


if __name__ == '__main__':
    main()


Measured memory_bytes: 53084
import java.math.BigDecimal;
import java.util.*;

public class Main {

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

    static class Period {
        int s;
        int e;

        public Period(int s, int e) {
            this.s = s;
            this.e = e;
        }
    }

    static class Node {
        int h;
        int w;
        int c;

        public Node(int h, int w, int c) {
            this.h = h;
            this.w = w;
            this.c = c;
        }
    }

    static void solve(Scanner scanner) {
        int H = scanner.nextInt(), W = scanner.nextInt();
        scanner.nextLine();
        char[][] grid = new char[H][W];
        for (int i = 0; i < H; i++) {
            grid[i] = scanner.nextLine().toCharArray();
        }

        Queue<Node> q = new ArrayDeque<>();
        q.add(new Node(0, 0, 0));
        Set<String> visited = new HashSet<>();
        int[][] dirs = {{1, 0}, {0, -1}, {-1, 0}, {0, 1}};

        int cost = 0;
        while (!q.isEmpty()) {
            Node n = q.poll();
            if (n.h == H - 1 && n.w == W - 1) {
                cost = n.c;
                break;
            }
            String s = String.format("%d:%d", n.h, n.w);
            if (visited.contains(s)) {
                continue;
            }
            visited.add(s);
            for (int[] d: dirs) {
                int nh = n.h + d[0];
                int nw = n.w + d[1];
                if (nh >= 0 && nh < H && nw >= 0 && nw < W && grid[nh][nw] == '.') {
                    q.add(new Node(nh, nw, n.c + 1));
                }
            }
        }

        int w = 0;
        for (char[] l: grid)
            for (char n: l)
                if (n == '.') {
                    w++;
                }

        System.out.println(cost == 0 ? -1 : w - cost - 1);
    }

}

Measured memory_bytes: 33684
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long W = sc.nextLong();
		long H = sc.nextLong();
		long x = sc.nextLong();
		long y = sc.nextLong();
		sc.close();

		double area = (double) W * H / 2;
		int flg = 0;
		if ((double) x == (double) W / 2 && (double) y == (double) H / 2) {
			flg = 1;
		}
		System.out.println(area + " " + flg);
	}
}


Measured memory_bytes: 25044
#include <iostream>
using namespace std;
int main(void){
 
	int N=0,M=0;
	int chk=0;
	int A=0;
	int rest=0;
 
	cin >> N >> M ;
 
	for(int i = 0; i < M ; i++){
		cin >> chk;
        A += chk;
    }
	rest = N - A;
	if( rest < 0 ){
		cout << -1 << endl;
	}else{
		cout << rest << endl;
	}
	return 0;
}

Measured memory_bytes: 3188
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <cstdlib>
#include <cmath>

using namespace std;

int main(){
  int N;
  cin >> N;
  vector<int> T(N);
  for(int i=0;i<N;i++){
    cin >> T.at(i);
  }
  int M;
  cin >> M;
  vector<int> P(M);
  vector<int> X(M);
  for(int i=0;i<M;i++){
    cin >> P.at(i) >> X.at(i);
  }

  int sum=0;
  for(int i=0;i<N;i++){
    sum+=T.at(i);
  }

  for(int i=0;i<M;i++){
    cout << sum - T.at(P.at(i)-1) + X.at(i) << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int n,i;
	long long cnt=0;
	if(scanf("%d",&n)!=1)return 1;
	for(i=0;i<n;i++) {
		char kakko[4];
		int num;
		if(scanf("%*d%s%d",kakko,&num)!=2)return 1;
		if(kakko[0]=='(')cnt+=num; else cnt-=num;
		puts(cnt==0?"Yes":"No");
	}
	return 0;
}

Measured memory_bytes: 588
import sys
import copy
import math
import bisect
import pprint
import bisect
from functools import reduce
from copy import deepcopy
from collections import deque

if __name__ == '__main__':
    a = [int(i) for i in input().split()]

    if a[2] >=a[0] and a[2] <=a[1]:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 3828
import sys
import bisect
from itertools import product
def input(): return sys.stdin.readline().strip()
A,B,Q = map(int,input().split())
s = [int(input()) for i in range(A)]
t = [int(input()) for i in range(B)]
stlist = [s,t]
ab = [A,B]
for i in range(Q):
    x = int(input())
    cand = []
    for i in range(2):
        st = stlist[i]
        cand1 = set()
        l1 = bisect.bisect_left(st,x)
        r1 = bisect.bisect_right(st,x)
        if 0 <= l1 <= ab[i]-1:
            cand1.add(st[l1])
        if 0 <= l1-1 <= ab[i]-1:
            cand1.add(st[l1-1])
        cand.append(cand1)
        
    ans = float('inf')
    for a,b in product(cand[0],cand[1]):
        c = min(abs(x-a)+abs(b-a),abs(x-b)+abs(b-a))
        ans = min(ans,c)
    print(ans)
        
        
    

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

using namespace std;
#define nn 200004

int n;
#define err {puts("Impossible");exit(0);}
int p[nn],rp[nn];
int b[nn],a[nn];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&p[i]),rp[p[i]]=i;
	
	for(int i=1;i<=n;i++)
	{
		b[i]=b[i-1];
		a[i]=b[i]+rp[i];
		if(a[i]<=a[i-1])
		{
			b[i]+=a[i-1]-a[i];
			a[i]+=a[i-1]-a[i];
		}
	}
	
	for(int i=1;i<=n;i++) printf("%d ",a[i]+i);
	int _m=0;puts("");
	for(int i=1;i<=n;i++) _m=max(_m,b[i]);
	for(int i=1;i<=n;i++)
	{
		b[i]-=_m;
		b[i]*=-1;
		printf("%d ",b[i]-i+n+1);
	} 
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
string reverse(string s){
	string t="";
	for(int i=s.size()-1;i>=0;i--) t+=s[i];
	return t;
}
int main(){
	string s;
	cin>>s;
	int cnt=0;
	string s1,s2;
	if(s.size()%2==0){
		s1=s.substr(0,s.size()/2);
		s2=s.substr(s.size()/2,s.size()-1);
	}
	else{
		s1=s.substr(0,s.size()/2);
		s2=s.substr((s.size()/2)+1,s.size()-1);
	}
	s2=reverse(s2);
	for(int i=0;i<=s1.size();i++) if(s1[i]!=s2[i]) cnt++;
	printf("%d\n",cnt);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define str to_string
#define endl "\n"
#define PI 3.141592653589
using namespace std;
using lint = long long;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

int main(){
    int n,k,a;cin>>n>>k;
    map<int,int> dic;
    for(int i=0;i<n;i++){
        cin>>a;dic[a]++;
    }
    vector<int> vec(0);
    for(auto p:dic){
        vec.pb(p.second);
    }
    sort(all(vec),greater<int>());
    int ans=0;
    for(int i=k;i<vec.size();i++){
        ans+=vec[i];
    }
    cout<<ans<<endl;
}


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

int main() {
  ll n,t;
  cin >> n >> t;
  vector<ll> a(n);
  ll sum=0;
  for(ll i=0;i<n;i++){
    cin >> a.at(i);
    if(i==0)
      sum=t;
    else{
      if(a.at(i)>a.at(i-1)+t)
        sum=sum+t;
      else
        sum=sum+a.at(i)-a.at(i-1);
    }
  }
  cout << sum << endl;
}



Measured memory_bytes: 1792
//In the name of Allah :)
#include <bits/stdc++.h>
using namespace std;

const int MAXN = 2e5 + 10;


int main(){
	ios_base::sync_with_stdio(NULL);cin.tie(nullptr);cout.tie(nullptr);
        string str1 , str2;
        cin >> str1 >> str2;
        if(str2.size() -1 != str1.size()) return cout << "No\n" , 0;
        str2.resize(str1.size());
        if(str1 != str2) cout << "No\n";
        else cout << "Yes\n";
        
}


Measured memory_bytes: 3656
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        int q = Integer.parseInt(sc.next());
        String s = sc.next();
        int[] l = new int[q];
        int[] r = new int[q];
        for(int i = 0; i < q; i++){
            l[i] = Integer.parseInt(sc.next());
            r[i] = Integer.parseInt(sc.next());
        }
        
        int[] ac = new int[n];
        int count = 0;
        for(int i = 0; i < n-1; i++){
            if(s.charAt(i) == 'A' && s.charAt(i+1) == 'C'){
                count++;
            }
            ac[i+1] = count;
        }
        
        StringBuilder sb = new StringBuilder();
        for(int i = 0; i < q; i++){
            sb.append(ac[r[i]-1] - ac[l[i]-1]).append(System.lineSeparator());
        }
        System.out.println(sb);
    }
}

Measured memory_bytes: 50380