akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<bitset>
#include<cstdio>
#include<cmath>
#include<deque>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<string>
#include<tuple>
#include<utility>
#include<vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
typedef vector<vector<int>> vvi;

#define rep(i, a, n)  for(int i=a; i<n; i++)
#define REP(i, n)  for(int i=0; i<(int)(n); i++)
#define REPS(i, n)  for(int i=1; i<=(int)(n); i++)
#define PER(i, n) for(int i=(int)(n)-1; i>= 0; i--)
#define PERS(i, n)  for(int i=(int)(n); i>0; i--)
#define FOR(i, c) for(__typeof((c).begin()) i = (c).begin(); i!=(c).end(); i++)
#define RFOR(i, c)  for(__typeof((c).rbegin()) i=(c).rbegin(); i!=(c).end(); i++)
#define ALL(container)  (container).begin(), (container).end()
#define RALL(container) (container).rbegin(), (container).rend()
#define SZ(container) (container).size()
#define FILL0(n)  setfill('0') << right << setw(n)
#define mp(a, b)  make_pair(a, b)
#define toLower(c)  c+0x20
#define toUpper(c)  c-0x20
#define pb  push_back
#define eb  emplace_back

const int INF = 1e9;
const long long LLINF = 1e18;
const int MOD = 1000000007;

int main(){
  int s, w; cin >> s >> w;
  cout << (s<=w ? "unsafe" : "safe") << endl;
  return 0;
}


Measured memory_bytes: 3548
#include <iostream>
using namespace std;
int main(){
int n, t, a[3]={0};
cin >> n;
for(int i=0;i<n;i++){
cin >> t;
if(t%2==0)a[t%4==0?2:1]++;else a[0]++;
}
if((a[1] && a[0] <= a[2]) || (!a[1] && a[0] <= a[2] +1))
cout <<"Yes";
else
cout << "No";
cout << endl;
return 0;
}

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

int main(){
  
  int N,tmp,z=0;
  cin>>N;
  
  vector<int> A(N);
  for(int i=0;i<N;i++){
    cin>>A[i];
  }

  vector<int>::iterator max_1_itr = max_element(A.begin(), A.end());
  size_t index_1 = distance(A.begin(), max_1_itr);
  swap(A[index_1], z);
  vector<int>::iterator max_2_itr = max_element(A.begin(), A.end());
  size_t index_2 = distance(A.begin(), max_2_itr);
  swap(A[index_1], z);
  
  for(int j=0;j<N;j++){
    if(j == index_1)cout<<A[index_2]<<endl;
    else cout<<A[index_1]<<endl;
  }
    
  return 0;
}

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

int main() {
  int N;
  cin >> N;
  if ((N%1==0&&N<10)||(N%2==0&&N<19)||(N%3==0&&N<28)||(N%4==0&&N<37)||(N%5==0&&N<46)||(N%6==0&&N<55)||(N%7==0&&N<64)||(N%8==0&&N<73)||(N%9==0&&N<82)) {
    cout<< "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
  
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scn = new Scanner(System.in);
		String s = scn.next();
		String t = scn.next();
		int ans = 0;
		int n = s.length();
		for (int i = 0; i < n; i++) {
			char ch1 = s.charAt(i);
			char ch2 = t.charAt(i);
			if (ch1 != ch2) {
				ans++;
			}
		}
		System.out.println(ans);
	}

}


Measured memory_bytes: 32092
#include "bits/stdc++.h"
using namespace std;
#define dump(x) cout << (x) << endl;
typedef long long ll;

ll h(ll n) {
  ll ret = 1;
  while (n--) ret = 2 * ret + 1;
  return ret;
}

ll g(ll n) {
  ll ret = 1;
  while (n--) ret = 2 * ret + 3;
  return ret;
}

ll f(ll n, ll x) {
  ll a =  g(n);
  if (n == 0) return 1;
  if (x == 1) return 0;
  else if (x < (a-3)/2 + 2) return f(n-1, x-1);
  else if (x == (a-3)/2 + 2) return h(n-1) + 1;
  else if ((a-3)/2 + 2 < x && x < a) return h(n-1) + 1 + f(n-1, x - (a-3)/2 - 2);
  else if (x == a) return h(n);
}

int main() {
  ll n, x;
  cin >> n >> x;
  dump(f(n, x));
  return 0;
}


Measured memory_bytes: 256
import sys
from math import factorial
from collections import Counter
from fractions import Fraction
import heapq, bisect, fractions
import math
import itertools
sys.setrecursionlimit(10 ** 5 + 10)
INF = 10**15 +5
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
MOD = 10**9 + 7

n = INT()
a = [0]*(n+1)
b = [0]*(n+1)
for i in range(1,n+1):
    aa, bb = MAP()
    a[i] = aa
    b[i] = bb

a = sorted(a)
b = sorted(b)
if n%2 ==1:
    res = b[n//2 + 1]-a[n//2 + 1] +1
else:
    res = b[n//2] + b[n//2 + 1] - a[n//2] - a[n//2 + 1] + 1

print(res)

Measured memory_bytes: 84024
#include <stdio.h>
int main(void){
    int M1,D1,M2,D2;
    
    scanf("%d %d %d %d",&M1,&D1,&M2,&D2);
    
    if(D2==1){
        printf("1\n");
    }
    else{
        printf("0\n");
    }
    

    return 0;    
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using Int = int_fast64_t;

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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int h, w; cin >> h >> w;
	vector<string> v(h);
	for(auto &i:v) cin >> i;
	vector<vector<int>> a(h, vector<int>(w, 1e9));
	a[h-1][w-1] = (v[h-1][w-1] == '#');
	for(int i=h-1; i>=0; --i)
		for(int j=w-1; j>=0; --j)
			for(int k=0; k<2; ++k){
				int nx = i+dx[k];
				int ny = j+dy[k];
				if(nx >= h || ny >= w) continue;
				int t = (v[i][j] == '#' && v[nx][ny] == '.');
				a[i][j] = min(a[i][j], a[nx][ny]+t);
			}
	cout << a[0][0] << "\n";
}

Measured memory_bytes: 384
const main = inputs => {
  const n = +inputs[0]
  const s = inputs[1]
  const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ'

  if (n === 0) return console.log(s)
  
  var ans = ''
  for (var i = 0; i < s.length; i++) {
    ans += chars[chars.indexOf(s[i]) + n]
  }
  console.log(ans)
}

main(require("fs").readFileSync("/dev/stdin", "utf8").split('\n'))

Measured memory_bytes: 7372
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
using ll = long long;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

class UnionFind {
  vector<int> par, sz;
public:
  UnionFind(int n) {
    par.resize(n);
    for (int i = 0; i < n; i++)
      par[i] = i;
    sz.resize(n, 1);
  }
  int root(int x) {
    if (par[x] == x)
      return x;
    return par[x] = root(par[x]);
  }
  bool same(int x, int y) {
    return root(x) == root(y);
  }
  int size(int x) {
    return sz[root(x)];
  }
  bool unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y)
      return false;
    if (sz[x] >= sz[y]) {
      sz[x] += sz[y];
      par[y] = x;
    } else {
      sz[y] += sz[x];
      par[x] = y;
    }
    return true;
  }
};

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  UnionFind uf(n);
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    uf.unite(a, b);
  }
  int ans = 0;
  rep(i, n)
    chmax(ans, uf.size(i));
  cout << ans << endl;
  return 0;
}

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

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

	int n, c, k; cin >> n >> c >> k;
	vector<int> arrivals(n);
	for(int i = 0; i < n; i++) cin >> arrivals[i];
	sort(arrivals.begin(), arrivals.end());
	int bus = 0, j = 0;
	for(int i = 0 ; i < n ; i++) {
		int passengers = 0;
		while(j < n && passengers < c && arrivals[j] - arrivals[i] <= k){
			j++; passengers++;
		}
		if(passengers > 0) bus++;
		i = j - 1;
	}
	cout << bus << endl; 
	
	return 0;	
}
  

Measured memory_bytes: 640
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<int> &o) {
    int a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

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

    auto get_ll = [&]() {
        vector<ll> v(n);

        rep(i, n) {
            string s;
            cin >> s;

            if (find(s.begin(), s.end(), '.') == s.end()) s += ".0";

            while (distance(find(s.begin(), s.end(), '.'), s.end()) <= 9) {
                s += '0';
            }

            ll a = 0;
            for (char c : s) {
                if (c == '.') continue;
                ll k = c - '0';
                a *= 10;
                a += k;
            }

            v[i] = a;
        }
        return v;
    };

    vector<ll> v = get_ll();

    auto f = [&](int k) -> vector<int> {
        vector<int> res(n);
        rep(i, n) {
            ll t = v[i];
            int l = 0;
            while (t % k == 0) {
                l++;
                t /= k;
            }
            res[i] = l;
        }
        return res;
    };

    vector<int> tows = f(2);
    vector<int> fives = f(5);

    vector<P> pairs;
    rep(i, n) {
        pairs.push_back(P(tows[i], fives[i]));
    }
    map<P, ll> counts;
    for (P p : pairs) counts[p]++;
    ll ans = 0;

    auto check = [&](P a, P b) -> bool {
        return a.first + b.first >= 18 && a.second + b.second >= 18;
    };

    for (auto e1 : counts) {
        for (auto e2 : counts) {
            if (check(e1.first, e2.first))ans += e1.second * e2.second;
        }
    }

    auto check_one = [&](P a) -> bool {
        return a.first >= 9 && a.second >= 9;
    };
    for (P p : pairs) {
        if (check_one(p)) ans--;
    }
    ans /= 2;


    cout << ans << endl;

}


Measured memory_bytes: 10344
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();

    int count = 0;

    for (int i = 0; i < N; i++) {
      int h = sc.nextInt();
      if (K <= h) {
        count++;
      }
    }

    sc.close();
    
    System.out.println(count);
    
  }

}

Measured memory_bytes: 46936
using System;
using System.Collections.Generic;
using System.Linq;

static class RailwayLines
{
    static void Main()
    {
        var input = Console.In.ReadToEnd()
            .Split( 
                new[] { '\r', '\n' },
                StringSplitOptions.RemoveEmptyEntries )
            .Select( x => Array.ConvertAll( x.Split( ',' ), int.Parse ) );
        var q =
            from d in input
            let p = d[10] / (double)( d[10] + d[11] ) * d.Take( 10 ).Sum()
            select Enumerable.Range( 0, 10 )
                .Aggregate(
                    new int[2],
                    (x, y) => {
                        var sum = x[0] + d[y];
                        return new[] { sum, sum < p ? y : x[1] };
                    } )[1] + 2;
        q.ToList().ForEach( Console.WriteLine );
    }
}

Measured memory_bytes: 6040
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;
//const int mod = 998244353;

#define MAX_P 1000010
int fact[MAX_P]; //n! mid p

int extgcd(int a, int b, int &x, int &y)
{
    int d = a;
    if (b != 0)
    {
        d = extgcd(b, a % b, y, x);
        y -= (a / b) * x;
    }
    else
    {
        x = 1;
        y = 0;
    }
    return d;
}
int mod_inverse(int a, int m)
{
    int x, y;
    extgcd(a, m, x, y);
    return (m + x % m) % m;
}
//n! = a p^e -> a mod p
void make_fact()
{
    fact[1] = 1;
    for (int i = 2; i < MAX_P; i++)
    {
        fact[i] = (fact[i - 1] * i) % mod;
    }
    return;
}
int mod_fact(int n, int p, int &e)
{
    e = 0;
    if (n == 0)
        return 1;
    int res = mod_fact(n / p, p, e);
    e += n / p;
    if (n / p % 2 != 0)
        return res * (p - fact[n % p]) % p;
    return res * fact[n % p] % p;
}
//nCk mod p
int mod_comb(int n, int k, int p)
{
    if (n < 0 || k < 0 || n < k)
        return 0;
    int e1, e2, e3;
    int a1 = mod_fact(n, p, e1), a2 = mod_fact(k, p, e2), a3 = mod_fact(n - k, p, e3);
    if (e1 > e2 + e3)
        return 0;
    return a1 * mod_inverse(a2 * a3 % p, p) % p;
}

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

    int x, y;
    cin >> x >> y;
    if ((x + y) % 3 != 0)
    {
        cout << 0 << endl;
        return 0;
    }
    int n = (x + y) / 3;
    x -= n, y -= n;
    if (x < 0 || y < 0)
    {
        cout << 0 << endl;
        return 0;
    }
    make_fact();
    cout << mod_comb(x + y, x, mod) << endl;
}

Measured memory_bytes: 8064
#include <float.h>
#include <inttypes.h>
#include <limits.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <math.h>
#ifdef __cplusplus
#include <bits/stdc++.h>
#endif

#define getchar getchar
#define putchar putchar
int32_t nextint(void){ char c=getchar(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar(); bool s=false; if(c=='-'){s=true;c=getchar();} uint32_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar(); } return s?-x:x; }
int64_t nextlong(void){ char c=getchar(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar(); int s=0; if(c=='-'){s=1;c=getchar();} uint64_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar(); } return s?-x:x; }
uint32_t nextstr(char *s){ char c=getchar(); while(c==' '||c=='\n') c=getchar(); uint32_t len=0; while(c!=' '&&c!='\n'){ *s++=c; len++; c=getchar(); } *s='\0'; return len; }

int main(void){
	int I=nextint();
	int O=nextint();
	nextint();
	int J=nextint();
	int L=nextint();
	long ans= (long)O + (long)I/2*2 + (long)J/2*2 + (long) L/2*2 + (long) (I&J&L&1)*3;
	if(I>0&&J>0&&L>0){
		long ans2= (long)O + (long)(I-1)/2*2 + (long)(J-1)/2*2 + (long) (L-1)/2*2 + 3;
		if(ans2>ans) ans=ans2;
	}
	printf("%ld\n", ans);
}


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


int main() {
    int N;
    cin >> N;
    string s;
    map<string, int> m;
    for(int i=0;i<N;i++) {
        cin >> s;
        m[s]++;
    }
    int mx = 0;
    for(auto x: m) mx = max(mx, x.second);
    for(auto x:m) {
        if(x.second == mx) cout << x.first << endl;
    }
    
}

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

int main(){
  string S;
  cin >> S;
  vector<string> T={"dream","dreamer","erase","eraser"};
  reverse(S.begin(),S.end());
  for(int i=0;i<4;i++){
    reverse(T.at(i).begin(),T.at(i).end());
  }
  bool all_cut=true;
  for(int i=0;i<S.size();){
    bool cut=false;
    for(int j=0;j<4;j++){
      string U=S.substr(i,T.at(j).size());
      if(U==T.at(j)){
        i+=T.at(j).size();
        cut=true;
        break;
      }
    }
    if(!cut){
      all_cut=false;
      break;
    }
  }
  if(all_cut){
    cout << "YES" << endl;
  }
  else{
    cout << "NO" << endl;
  }
}

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

int main() {
  int n, m = 0;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    m += a[i];
  }
  cout << m - n << "\n";
  return 0;
}

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

main(){
    int W,H,x,y,r;
    cin>>W>>H>>x>>y>>r;
    
    if((x-r < 0) ||
       (y-r < 0) ||
       (x+r > W) ||
       (y+r > H)){
      cout << "No" << endl;
    }else{
      cout << "Yes" << endl; 
    }
}


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

int main()
{
  int n,k;
  cin >> n >> k;
  vector<int> d(k);
  for(int i=0;i<k;i++){
    cin >> d[i];
  }
  for(int i=n;i<100000;i++){
    if(
	(i/10000==0||find(d.begin(),d.end(),i/10000)==d.end()) &&
        (i/1000==0||find(d.begin(),d.end(),i/1000%10)==d.end()) &&
	(i/100==0||find(d.begin(),d.end(),i/100%10)==d.end()) &&
	(i/10==0||find(d.begin(),d.end(),i/10%10)==d.end()) &&
	find(d.begin(),d.end(),i%10)==d.end()
      ){
      cout<<i<<endl;
      break;
    }
  }
}


Measured memory_bytes: 256
#include"iostream"
#include"cstring"
using namespace std;

int c[1001][1001];
void lcs(char*a,char*b)
{
	int m = strlen(a);
	int n = strlen(b);
	int i, j;
	for(i=0;i<1001;++i)
	{
		c[0][i] = 0;
		c[i][0] = 0;
	}
	for (i = 1; i <= m; ++i)
		for (j = 1; j <= n; ++j)
			if (a[i-1] == b[j-1])c[i][j] = c[i - 1][j - 1] + 1;
			else c[i][j] = c[i][j - 1] > c[i - 1][j] ? c[i][j - 1] : c[i - 1][j];
	cout<<c[m][n]<<endl;
}
int main()
{
	int n,i;
	cin >> n;
	cin.get();
	char** a = new char* [2 * n];
	for (i = 0; i < 2 * n; ++i)
	{
		a[i] = new char[1001];
		cin.getline(a[i], 1001);
	}
	for (i = 0; i < 2 * n; i += 2)
		lcs(a[i], a[i + 1]);
	return 0;
}


Measured memory_bytes: 7184
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin >> n;
	deque<int>q;
	for (int i = 0; i < n; i++) {
		int x;
		cin >> x;
		if (i & 1)
			q.push_back(x);
		else
			q.push_front(x);
	}
	if (n & 1) {
		while (!q.empty()) {
			cout << q.front() << " ";
			q.pop_front();
		}
	}
	else {
		while (!q.empty()) {
			cout << q.back() << " ";
			q.pop_back();
		}
	}
}

Measured memory_bytes: 4464
#include <stdio.h>
int main(){
  int r,c,i,j;
  static int s[101][101];
  scanf("%d%d",&r,&c);
  for(i=0;i<=r;i++){
    for(j=0;j<c;j++){
      scanf("%d", &s[i][j]);
      printf("%d ", s[i][j]);
      s[i][c] += s[i][j];
      s[r][j] += s[i][j];
    }
    printf("%d\n",s[i][c]);
  }
  return 0;
}



Measured memory_bytes: 2104
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
#include <sstream>
#include <fstream>

#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)

using namespace std;
typedef long long unsigned int ll;

int main() {
  int N;
  cin >> N;
  vector<int> x(N), y(N), h(N);
  for (int i = 0; i < N; ++i) {
    cin >> x[i] >> y[i] >> h[i];
  }

  for (int yy = 0; yy <= 100; ++yy) {
    for (int xx = 0; xx <= 100; ++xx) {
      int H = -1;
      bool isValid = true;
      for (int i = 0; i < N; ++i) {
	if (h[i] > 0) {
	  int H_ = h[i] + abs(yy - y[i]) + abs(xx - x[i]);
	  if (H == -1) {
	    H = H_;
	  } else {
	    if (H != H_) {
	      isValid = false;
	      break;
	    }
	  }
	}
      }
      if (!isValid) continue;

      for (int i = 0; i < N; ++i) {
	if (h[i] == 0) {
	  int distance = abs(yy - y[i]) + abs(xx - x[i]);
	  if (H > distance) {
	    isValid = false;
	    break;
	  }
	}
      }
      if (!isValid) continue;
      cout << xx << " " << yy << " " << H << endl;
      return 0;
    }
  }

  return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(int argc, char const *argv[]) {
  string w;
  cin >> w;
  int cnt[26];
  for (int i = 0; i < 26; i++) {
    cnt[i] = 0;
  }
  for (int i = 0; i < w.length(); i++) {
    cnt[w[i] - 'a']++;
  }
  bool flag = true;
  for (int i = 0; i < 26; i++) {
    if (cnt[i] % 2 != 0) {
      flag = false;
      break;
    }
  }
  if (flag)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;
int n,m,q;
string s[2001];
int p[2001][2001];   //mang tinh so diem
int a[2001][2001];   //hang ngang
int b[2001][2001];   //hang doc
int x1,x2,y1,y2;
void debug()
{

    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
            cout<<p[i][j]<<" ";
        cout<<endl;
    }
    cout<<endl;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
            cout<<a[i][j]<<" ";
        cout<<endl;
    }
    cout<<endl;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
            cout<<b[i][j]<<" ";
        cout<<endl;
    }
    cout<<endl;

}
void solve()
{
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
        {
            //*****************
            p[i][j]=p[i-1][j]+p[i][j-1]-p[i-1][j-1];
            if(s[i-1][j-1]=='1')
                p[i][j]++;
            //*****************
            a[i][j]=a[i-1][j]+a[i][j-1]-a[i-1][j-1];
            if(i>=2&&s[i-1][j-1]=='1'&&s[i-2][j-1]=='1')
                a[i][j]++;
            //*****************
            b[i][j]=b[i-1][j]+b[i][j-1]-b[i-1][j-1];
            if(j>=2&&s[i-1][j-1]=='1'&&s[i-1][j-2]=='1')
                b[i][j]++;
        }
    //debug();
}
void Init()
{
    cin>>n>>m>>q;
    for(int i=0;i<n;i++)
        cin>>s[i];
    solve();
    for(int i=0;i<q;i++)
    {
        cin>>x1>>y1>>x2>>y2;
        long long res1= p[x2][y2]-p[x1-1][y2]-p[x2][y1-1]+p[x1-1][y1-1];
        long long res2= a[x2][y2]-a[x1][y2]-a[x2][y1-1]+a[x1][y1-1];
        long long res3= b[x2][y2]-b[x1-1][y2]-b[x2][y1]+b[x1-1][y1];
        cout<<res1-res2-res3<<endl;

    }


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


Measured memory_bytes: 52992
#include <bits/stdc++.h>
#define FOR(I,X,Y) for(long int I=X;I<Y;I++)
#define REP(I,X) for(long int I=X;I>=0;I--)
#define INF 1e9+7
using namespace std;

int main(){
  int a,b,c;
  vector<int> ans;
  while(1){
    cin >> a >> b >> c;
    if(!(a|| b || c))break;
    int N,i,j,k,l;
    cin >> N;
    set<int> unbroken;
    set<int> broken;
    int ii[N],jj[N],kk[N],ll[N];
    FOR(i,0,N)cin >> ii[i] >> jj[i] >> kk[i] >> ll[i];
    FOR(count1,0,N)FOR(count2,0,N){
      int i = ii[count2],j = jj[count2],k = kk[count2],l = ll[count2];
      if(l){
        unbroken.insert(i);
        unbroken.insert(j);
        unbroken.insert(k);
      }
      else{
        if(unbroken.count(i) && unbroken.count(j))broken.insert(k);
        if(unbroken.count(j) && unbroken.count(k))broken.insert(i);
        if(unbroken.count(k) && unbroken.count(i))broken.insert(j);
      }
    }
    FOR(i,1,a+b+c+1){
      if(unbroken.count(i))ans.push_back(1);
      else if(broken.count(i))ans.push_back(0);
      else ans.push_back(2);
    }
  }
  for(auto x:ans)cout << x << endl;
}



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

typedef long long ll;
#define MOD 1000000007
// vector<vector<double>> dp_arr;
// double prob(vector<double>& arr, int index, double p, double& tot_p, int tail_count)
// {
// 	if(index == arr.size())
// 	{
// 		tot_p += p;
// 		// cout << "tot_p: " << tot_p << endl;
// 		return;
// 	}
// 	if(dp_arr[index][tail_count] != -1)
// 	{
// 		tot_p += p*dp_arr[index][tail_count];
// 		return;
// 	}
// 	if(tail_count < arr.size()/2)
// 		prob(arr,index+1,p*(1-arr[index]),tot_p, tail_count+1);
// 	prob(arr,index+1,p*arr[index],tot_p, tail_count);
// 	if(dp_arr[index][tail_count] == -1)
// 		dp_arr[index][tail_count] = tot_p;
// }

int main()
{
	int n;
	cin >> n;
	vector<vector<double>> dp_arr(n+1,vector<double>(n+1,0));;
	vector<double> arr(n);
	for(int i = 0; i < n; i++)
	{
		cin >> arr[i];
	}
	double tot_p = 0;
	for(int index = 0; index <=n; index++)
	{
		for(int tail_count = 0; tail_count <= index; tail_count++)
		{
			if(index == 0 && tail_count == 0)
			{
				dp_arr[index][tail_count] = 1;	
			}
			else if(index < tail_count)
			{
				dp_arr[index][tail_count] = 0;
			}
			else
			{
				dp_arr[index][tail_count] = dp_arr[index-1][tail_count]*(arr[index-1]);
				if(tail_count > 0)
					dp_arr[index][tail_count] += dp_arr[index-1][tail_count-1]*(1-arr[index-1]);
				// cout << "index: " << index << " tails: " << tail_count << " dp: " << dp_arr[index][tail_count] << endl;	
			}
		}
	}
	for(int tail_count = 0; tail_count <= n/2; tail_count++)
		tot_p += dp_arr[n][tail_count];
	cout << std::setprecision(9) << tot_p << endl;
	// cout << std::setprecision(9) << dp_arr[n][0] << endl;
	return 0;
}


Measured memory_bytes: 70656
# include <iostream>
# include <stdio.h>
# include <cstring>
# include <string>
# include <cctype>
#include <algorithm> //transformの関数はaslgorithmライブラリに入っているみたい。
using namespace std;
int main(){
  string str,order,rep,temp;
  int q,a,b;
  cin >> str;
  cin >> q;
  for(int i =0;i<q;i++){
    cin >> order >> a >> b;
    if(order == "replace"){
      cin >> rep;
      str.replace(a,b-a+1,rep);
      // cout << str << ":test" << endl;
    }else if(order  == "reverse"){
      temp = str.substr(a,b-a+1);
      reverse(temp.begin(),temp.end());
      str.replace(a,b-a+1,temp);
      // cout << str << ":test" << endl;
    }else if(order == "print"){
      cout << str.substr(a,b-a+1) << endl;
    }
  }
  return 0;
}



Measured memory_bytes: 3172
#include <iostream>
#include <string>

using namespace std;

int main(){
    
int h,w;

cin>>h>>w;

char arr[h][w];

for(int i=0;i<h;i++){
    
    for(int j=0;j<w;j++){
        cin>>arr[i][j];
    }
    cout<<endl;
}

char arr1[h+2][w+2];

for(int i=0;i<h;i++){
    
    for(int j=0;j<w;j++){
      arr1[i+1][j+1] =    arr[i][j];
    }
    
}

for(int i=0;i<h+2;i++){
    arr1[i][0]='#';
    arr1[i][w+1]='#';

}
for(int i=0;i<w+2;i++){
    arr1[0][i]='#';
    arr1[h+1][i]='#';
}



for(int i=0;i<h+2;i++){
    
    for(int j=0;j<w+2;j++){
        
        cout<<arr1[i][j];
        
    }cout<<endl;
}








    
}

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

#define int long long int
const int N=1e3;

int32_t main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);

	int a,b,c,d,count=0;
	cin>>a>>b>>c>>d;
	while(true){
		count++;
		if(count%2 == 0){
			a -= d;
		}
		else
			c -= b;
		if(a <= 0)
			break;
		if(c <= 0)
			break;
	}
	if(count%2 == 1)
		cout<<"Yes\n";
	else
		cout<<"No\n";

	return 0;
}


Measured memory_bytes: 3644
using System;

namespace AtCoderBeginnerContest118_1
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');

            int A = int.Parse(s[0]);
            int B = int.Parse(s[1]);

            if (B % A == 0)
                Console.WriteLine((A + B).ToString());
            else
                Console.WriteLine((B-A).ToString());

        }
    }
}


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


int main() {
  int N,M,sum;
  sum =0;
  cin >> N >> M; 
  vector<int> a(N);
  
  for (int i=0;i < N;i++) {
    cin >> a.at(i);
    sum += a.at(i);
  }
    
    sort (a.begin(),a.end());
    reverse (a.begin(),a.end());
  if(sum%(4*M)==0) {
    if(a.at(M-1)>=sum/(4*M)) {
    cout << "Yes" << endl;
  }
    else {
    cout << "No" << endl;
  }
 }
  else { 
    if(a.at(M-1)>sum/(4*M)) {
    cout << "Yes" << endl;
  }
    else {
    cout << "No" << endl;
    }
  } 
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int asc(const void *a, const void *b) {
  return *(int *)a - *(int *)b;
}

int main()
{
    int n,k,h[100000],diff[100000];

    int i,j;
    scanf("%d %d",&n,&k);

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

    qsort(h,n,sizeof(int),asc);

    long long min = 10000000000;
    for (i = 0; i <= n - k; i++)
    {
        if(min > h[i + k - 1] - h[i])min = h[i + k - 1] - h[i];    }
    printf("%lld",min);
}

Measured memory_bytes: 892
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
ll arr[100001];
vector<ll> cache(100001,-1);
ll n;

ll frog(ll i)
{
	if(cache[i]!=-1)
		return cache[i];
	if(i==n-1)
		return 0;
	if(i>=n)
		return INT_MAX;
	return cache[i]=min(frog(i+1) + abs(arr[i]-arr[i+1]) , frog(i+2) + abs(arr[i]-arr[i+2]));
}

int main()
{
	cin>>n;
	for(ll i=0;i<n;i++)
	{
		cin>>arr[i];
	}
	cout<<frog(0)<<endl;
	return 0;
}

Measured memory_bytes: 4096
S = int(input())
K = int(input())
l = [int(x) for x in list(str(S))]
flag=0
flag2=0
i=0
j=0
ans = 0
if K<=len(l):
    while j<K and flag2 == 0:
        if l[j] == 1 or l[j]==0:
            ans = l[j]
            j = j + 1
        else:
            flag2 =1
            ans = l[j]
else:
    while flag ==0:
        if l[i] == 1 or l[i]==0:
            i = i + 1
        else:
            flag=1
            ans = l[i]
print(ans)


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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

int64 gcd(int64 a, int64 b){
	if(b == 0) return a;
	return gcd(b, a%b);
}

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int32 N, M;
	string s, t;
	cin >> N >> M >> s >> t;
	int64 g = gcd(N, M);
	int64 n = N/g, m = M/g, x = n*m;
	for(int32 i = 0;i < g+1;i++){
		if(s[i*n] != t[i*m]){
			cout << -1 << endl;
			return 0;
		}
	}
	cout << N*M/g << endl;
}


Measured memory_bytes: 640
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
B = Counter(A)

ans = 0
for i in B.values():
    ans += i*(i-1)//2

for a in A:
    k = B[a]
    print(ans - (k*(k-1)//2)+((k-1)*(k-2)//2))

Measured memory_bytes: 26772
#include <iostream>
#include <climits>
#include <vector>

using namespace std;

int main() {
    int H, N;
    cin >> H >> N;
    vector<int> A;
    vector<int> B;
    for (int i = 0; i < N; i++) {
        int a, b;
        cin >> a >> b;
        A.push_back(a);
        B.push_back(b);
    }
    vector<long long> dp = { 0 };

    for (int i = 1; i <= H; i++) {
        long long minimum = LLONG_MAX;
        for (int j = 0; j < N; j++) {
            int cost;
            if (A[j] >= i) {
                cost = B[j];
            } else {
                cost = B[j] + dp[i - A[j]];
            }
            if (minimum > cost) minimum = cost;
        }
        dp.push_back(minimum);
    }

    cout << dp[H] << endl;

    return 0;
}

Measured memory_bytes: 512
#include <stdio.h>
int main(void){
while(1){
    int h,w;
    scanf("%d%d",&h,&w);
    if(h==0&&w==0)
    break;
    
    int i,j;
    
 
    
    for(i=0;i<h;i++){
        for(j=0;j<w;j++){
            if(i!=0&&i!=h-1&&j!=0&&j!=w-1)
            printf(".");
            else
            printf("#");
        }
       printf("\n");
    }
   
    printf("\n");
}
return 0;
}

Measured memory_bytes: 2560
// う　し　た　ぷ　に　き　あ　く　ん　笑
#include <algorithm>
#include <array>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
#define int long long
constexpr int MOD = 1000000000 + 7;

// copied from https://github.com/atcoder-live/library/blob/master/mint.cpp
struct mint {
    using ll = long long;
    const int mod = 1e9 + 7;
    ll x;  // typedef long long ll;
    mint(ll x = 0) : x((x % mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint& operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }

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

    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];

    int inner_inversion = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            if (a[i] > a[j]) inner_inversion++;
        }
    }

    int outer_inversion = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (a[i] > a[j]) outer_inversion++;
        }
    }

    mint ans = 0;
    ans += inner_inversion * k;
    ans += outer_inversion * ((k * (k - 1) / 2) % MOD);
    cout << ans << endl;
}


Measured memory_bytes: 3500
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>
#include <bitset>
#include <iomanip>

#define repeat(i,n) for (long long i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i] << '\n'
#define debugArrayP(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i].first<< " " << x[i].second << '\n'

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ll INF = INT_MAX;
const ll MOD = 1e9+7;
int S(int n){
  string s = to_string(n);
  int ret=0;
  repeat(i,s.length()){
    ret += s[i]-'0';
  }
  return ret;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;cin>>N;
  cout << (N%S(N)==0? "Yes":"No")<<endl;
  return 0;
}


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

using namespace std;

int main(){

    //freopen ("input.txt", "r", stdin);

    int n;

    cin >> n;

    long long int sum = 0;


    for(int i=1; i<=n; i++){
        for(int j=1; j<=n; j++){
            for(int k=1; k<=n; k++){
                
                int temp = __gcd(i,j);
                sum += __gcd(temp,k);

            }
        }
    }

    cout << sum << endl;


    return 0;
}

Measured memory_bytes: 3604
n=int(input())
as_=list(map(int,input().split()))  # n+1
bs=list(map(int,input().split()))  # n
bf=sum(as_)
for i in range(n):
    if as_[i]-bs[i]<0:
        bs[i]-=as_[i]
        as_[i]=0
    else:
        as_[i]-=bs[i]
        bs[i]=0
    if as_[i+1]-bs[i]<0:
        as_[i+1]=0
    else:
        as_[i+1]-=bs[i]
print(bf-sum(as_))


Measured memory_bytes: 18624
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<string>
#include<random>
using namespace std;

int main(){

  int h, w;
  cin >> h >> w;

  for(int i=0; i<h; i++){
    string s;
    cin >> s;
    cout << s << endl;
    cout << s << endl;
  }

  return 0;
}














// EOF


Measured memory_bytes: 256
from sys import stdin                                                                                                                                                                                       
r = int(stdin.readline().rstrip())                                                                                                                                                                          
                                                                                                                                                                                                            
if r < 1200:                                                                                                                                                                                                
    print("ABC")                                                                                                                                                                                            
elif r <2800:                                                                                                                                                                                               
    print("ARC")                                                                                                                                                                                            
else:                                                                                                                                                                                                       
    print("AGC")                                                                                                                                                                                            

Measured memory_bytes: 2940
#include <iostream>

using namespace std;

int main() {
	int a, b, c;
	int num;
	cin >> a >> b >> c;
	if (a > b) {
		num = a;
		a = b;
		b = num;
	}
	if (b > c) {
		num = b;
		b = c;
		c = num;
	}
	if (a > b) {
		num = a;
		a = b;
		b = num;
	}
	cout << a << " " << b << " " << c << endl;

	return 0;
}



Measured memory_bytes: 3088
#include <iostream>
using namespace std;
int ans[105],tg[105],n,k,tmp;
int main(){
      cin>>n>>k;
      for(int i=0;i<k;i++)cin>>tg[i];
      for(int i=0;i<k;i++){
            int ctn=0;
            for(int j=0;j<n;j++){
                  cin>>tmp;
                  if(tmp==tg[i]){
                        ans[j]++;
                        ctn++;
                  }
            }
            ans[tg[i]-1]+=n-ctn;
      }
      for(int i=0;i<n;i++)cout<<ans[i]<<endl;
}

Measured memory_bytes: 1160
# -*- coding: utf-8 -*-
"""
Created on Wed Mar 25 10:07:17 2020

@author: Kanaru Sato
"""

N = int(input())
B = list(map(int, input().split()))
count = B[0]+B[-1]

if N > 2:
    for i in range(0, N-2):
        count += min(B[i], B[i+1])

print(count)

Measured memory_bytes: 3060
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#solve
def solve():
    n = II()
    print((n+1)//2)
    return


#main
if __name__ == '__main__':
    solve()


Measured memory_bytes: 39152
#include <iostream>


typedef long long int ll;

using namespace std;


ll min(ll a, ll b){
	return (a<b?a:b);
}

ll abs(ll a, ll b){
	return (a<b?b-a:a-b);
}


ll frog1(ll* ht, ll n){
	ll dp[n+1]={0};
	
	dp[2] = abs(ht[1]-ht[0]);
	
	dp[3] = min(abs(ht[2]-ht[0]), abs(ht[1]-ht[0])+ abs(ht[2]-ht[1]));
	
	for(int i=4;i<=n;i++){	
		
		dp[i] = min(dp[i-2]+abs(ht[i-1]-ht[i-3]), dp[i-1]+abs(ht[i-1]-ht[i-2]));
	}
	
	return dp[n]; 

}

int main(){
	
	ll n;
	cin>>n;
	ll arr[n];
	for(int i=0;i<n;i++)cin>>arr[i];
	
	cout<<frog1(arr, n)<<endl;
	
	

	return 0;
}

Measured memory_bytes: 1792
n = int(input())
x = list(map(int, input().split()))
def f(a):
  t = 0
  for i in range(n):
    t += (x[i]-a)**2
  return t
m=float('inf')
for i in range(1, 101):
  if m > f(i):
    m=f(i)
print(m)

Measured memory_bytes: 2940
#include <iostream>
#include <string>
#include <queue>
#include <map>

#define inRange(idx, hi, low) (low <= idx && idx < hi)

using namespace std;

typedef pair<string, int> Pair;

struct Puzzle {
	int count;
	int zero;
	string field;
};

void swap( string &str, int a, int b )
{
	char tmp = str[a];
	str[a] = str[b];
	str[b] = tmp;
}

map<string, int> field;

void search( void )
{
	int d[][4] = { { -1, 1, 4 }, { -1, 1, -4 } };
	string start = "01234567";
	Puzzle tmp;
	queue<Puzzle> q;
	int in = 0;
	field[start] = 0;
	tmp.count = tmp.zero = 0; tmp.field = start;
	q.push(tmp);
	while(!q.empty()) {
		tmp = q.front(); q.pop();
		for(int i=0; i < 3; ++i) {
			int idx = tmp.zero + d[tmp.zero/4][i];
			int hi = 8, low = 0;
			if		(tmp.zero < 4 && d[tmp.zero/4][i] == 1) hi = 4;
			else if	(tmp.zero > 3 && d[tmp.zero/4][i] ==-1) low= 4;
			if(inRange(idx, hi, low)) {
				Puzzle work = tmp;
				swap(work.field, tmp.zero, idx);
				if(!field.count(work.field)) {
					++work.count; work.zero = idx;
					q.push(work);
					field[work.field] = work.count;
				}
			}
		}
	}
}

int main( void )
{
	search();
	string input, str;
	while(cin >> input) {
		str += input;
		for(int i=0; i < 7; ++i) {
			cin >> input;
			str += input;
		}
		cout << field[str] << endl;
		str = "";
	}

	return 0;
}

Measured memory_bytes: 2192
#include <bits/stdc++.h>
#define ull unsigned long long int
#define ll long long
#define int long long
#define ld long double
#define endl '\n'
const int mod= 1e9+7;
#define F first
#define S second
//#define x first
//#define y second
#define pb push_back
#define mp make_pair
#define trace(x) cerr << #x << " is " << x << endl;
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<"\n";
#define all(x) x.begin(),x.end()
#define reset(x,val) memset(x,val,sizeof(x))
#define flush fflush(stdout)
#define sz(a) a.size()
#define pii pair<int,int>
void fail(){std::cout<<"NO\n";exit(0);}
using namespace std;
const int N=21;
int a[N][N];
int cache[N][1<<N],n;
int checker;

int dp(int man,int mask)
{
 //trace2(man,mask);
 if(man==n)
 {
  return (mask==checker);
 }
 int &ans=cache[man][mask];
 if(ans!=-1)return ans;
 
 ans=0;
 for(int women=0;women<n;women++)
 {
  if((mask>>women)&1)continue;
  if(a[man][women])
  ans+=dp(man+1,mask|(1<<women));
  ans%=mod;
 }
 return (ans+mod)%mod;
}
int32_t main() {
    ios_base::sync_with_stdio(false);cin.tie(NULL); 
    reset(cache,-1);
    //trace(cache[1][3]);
    cin>>n;
    checker=(1<<n)-1;
    //trace(checker);
    for(int i=1;i<=n;i++)
    for(int j=1;j<=n;j++)
    cin>>a[i-1][j-1];
    
    cout<<(dp(0,0)+mod)%mod<<endl;
    return 0; 
}


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

using namespace std;

int main(){
    char s[11];
    scanf("%s", s);
    int n = 0;
    while(s[n] != 0){
        n++;
    }
    if (s[0] != 'A'){
        puts("WA");
        return 0;
    }
    int flag = false;
    for (int i = 0; i < n; i++){
        if (s[i] == 'C'){
            if (!flag && i >= 2 && i <= n - 2){
                flag = true;
            }else{
                puts("WA");
                return 0;
            }
        }
    }
    if (!flag){
        puts("WA");
        return 0;
    }
    sort(s, s + n);
    if (s[2] <= 'Z'){
        puts("WA");
        return 0;
    }

    puts("AC");
}

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

int main() {
	ll a, b, n;
	while (cin >> a >> b >> n) {
		ll cnt = 0;
		rep(i, n) {
			a *= 10;
			cnt += (a / b) % 10;
			a %= b;
		}
		cout << cnt << endl;
	}
	return 0;
}

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

int main() {
  int N,  K;
  cin >> N >> K;
  vector <int> sunuke(N);
  for(int i=0; i<K; i++){
      int d;
      cin >> d; 
        for(int j=0; j<d; j++){
            int x;
            cin >>x;
            sunuke.at(x-1)++;
        }
  }
    int ans=0;
    for (int i=0; i<N; i++){
        if(sunuke.at(i)>0){
            
            ans++;
        }
    }
    cout << N-ans << endl;




  
}

Measured memory_bytes: 3608
s=input()
n=len(s)
i=1
for j in range(n//5):
    if s[-i:-i-5:-1]=="maerd":
        i+=5
 
    if s[-i:-i-5:-1]=="esare":
        i+=5

    if s[-i:-i-6:-1]=="resare":
        i+=6

    if s[-i:-i-7:-1]=="remaerd":
        i+=7

    if i==n+1:
        print("YES")
        break

if i != n+1:
    print("NO")

Measured memory_bytes: 42992
# review

n,m = map(int,input().split())
li_a = [list(input()) for _ in range(n)]
li_b = [list(input()) for _ in range(m)]
 
 
for i in range(n-m+1):
    for j in range(n-m+1):
        for k in range(m):
            if li_a[i+k][j:j+m] != li_b[k][:]:
                break
        else:
            print("Yes")
            exit()
            
print("No")          

Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <string.h>
#include <stdlib.h>

using namespace std;
// vector push_back push front top empty pop make_pair long long insert begin end  
typedef long long ll;
typedef vector<int> vi;
typedef vector<pair <int,int> > vpi;
typedef vector<long long> vll;
typedef pair<int,int> pi;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define B begin()
#define RB rbegin()
#define E end()
#define RE rend()
#define Z size()
#define REP(i,a,b) for (int i = a; i < b; i++)
#define L length()
#define show(a) cerr << " *** " << a << endl;
#define show1(a) cerr << " /// " << a << endl;
#define valid(a,b,c) (a >= b && a < c ? 1 : 0)
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
const int mod = (int)1e9 + 7;
ll gcd(ll a, ll b) {return (b==0? a:gcd(b,a%b));}
ll egcd(ll a, ll b, ll & x, ll & y) {if (a == 0){x = 0;y = 1;return b;}ll x1, y1;ll d = egcd(b % a, a, x1, y1);x = y1 - (b / a) * x1;y = x1;return d;}
ll mbinp(ll a, ll b){a %= mod;if (b == 0)return 1;ll ans = mbinp(a, b/2);ll tmp = (ans * ans) % mod;if (b % 2)return ((tmp * a) % mod);return ((tmp) % mod);}
ll binp(ll a, ll b){if (b == 0)return 1;ll ans = binp(a, b/2);ll tmp = (ans * ans);if (b % 2)return ((tmp * a));return ((tmp));}

const int maax = 1050;
ll dp[maax][maax];

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n,m;
	cin >> n >> m;
	dp[0][0] = 1;
	vector <string> all(n);
	REP(i,0,n)
		cin >> all[i];
	REP(i,0,n)
	{
		REP(j,0,m)
		{
			if (all[i][j] == '.')
			{
				REP(k,0,4)
				{
					if (valid(i+dx[k],0,n)&&valid(j+dy[k],0,m))
					{
						dp[i][j] += dp[i+dx[k]][j+dy[k]]; 
						dp[i][j] %= mod;
					}
				}
			}
		}
	}
	/*REP(i,0,n)
	{
		REP(j,0,m)
		{
			cout << dp[i][j] << " ";
		}
		cout << endl;
	}*/
	cout << dp[n-1][m-1]%mod;
}


Measured memory_bytes: 9472