akhauriyash/Code-Regression huggingface dataset:
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#include <bits/stdc++.h>
 
using namespace std;
 
int main(void) {
    string s, t;
    cin >> s >> t;
    if(s.size() == t.size() - 1 && t.compare(0, s.size(), s) == 0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3624
package main

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

var K int64
var A int64
var B int64

func main() {
	K = nextInt64()
	A = nextInt64()
	B = nextInt64()
	var result int64
	if (B-A) > 2 && K > A {
		rst := (K - A + 1) % 2
		div := (K - A + 1) / 2
		result = A + div*(B-A) + rst
		fmt.Println(result)
	} else {
		result = K + 1
		fmt.Println(result)
	}
}

func nextInt64() int64 {
	v, _ := strconv.ParseInt(nextReader(), 10, 64)
	return v
}

func nextInt() int {
	v, _ := strconv.Atoi(nextReader())
	return v
}

func nextInts(n int) []int {
	r := make([]int, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt()
	}
	return r
}

var nextReader func() string

func init() {
	nextReader = NewScanner()
}

func NewScanner() func() string {
	r := bufio.NewScanner(os.Stdin)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)
	return func() string {
		r.Scan()
		return r.Text()
	}
}

func Min(a int, b int) int {
	if a > b {
		return b
	}
	return a
}

func MaxIn2Values(a int, b int) int {
	if a > b {
		return a
	}
	return b
}

func MinIn2Values(a int, b int) int {
	if a < b {
		return a
	}
	return b
}

func Abs(a int) int {
	if a < 0 {
		return a * -1
	}
	return a
}


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

int N, L;

int Sum() {
  return (L-1)*N + (N+1)*N/2;
}

int main() {
  cin >> N >> L;
  int i = max(1, min(1-L, N));
  cout << Sum() - (L + i - 1) << endl;
  return 0;
}




Measured memory_bytes: 256
#include <iostream>
#include <array>
#include <map>
#include <algorithm>
#include <cmath>
#include <vector>
#include <fstream>
#include <string>
#include <random>
#include <queue>
#include <iomanip>
#include <functional>
#include <climits>
#include <tuple>
#include <unordered_map>
#include <limits>
#include <functional>
#include <cassert>
#include <numeric>
#include <bitset>
#include <set>

#define FOR(x,n) for(int x = 0; x < n; x++)
#define INPUT(x) scanf("%d",&x)
#define PUT(x) printf("%d\n",x)
#define DPUT(x) printf("%.15lf\n",x)
#define GET(x,y) std::get<x>(y)
#define CHMAX(x,y) x = std::max(x,y)
#define CHMIN(x,y) x = std::min(x,y)
#define SP_END (i != n - 1 ? ' ' : '\n') ;

using namespace std;

using ll = long long int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vll = std::vector<ll>;
using vpll = std::vector<pll>;
using vpii = std::vector<pii>;
using vi = std::vector<int>;
using vvi = std::vector<vi>;
using vvpii = std::vector<vpii>;
using vch = std::vector<char>;
using vvch = std::vector<vch>;
using tiii = std::tuple<int, int, int>;

const ll mod197 = 1000000007LL;
const ll INF = 10000000000LL;

const double PI11 = 3.14159265359;

const int dis[5] = { 0,1,0,-1,0 };

const int disD[4] = { 0,1,1,0 };
const int disLD[3] = { 0,1,0 };

const char disC[4] = { 'U','D','R','L' };
const char disY[4] = { -1,1,0,0 };
const char disX[4] = { 0,0,1,-1 };

int main(void) {

	int n, result = 0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		ll a;
		cin >> a;
		while (a % 2 == 0) { a /= 2; result += 1; }
	}

	cout << result << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <list>
#include <cmath>

using namespace std;

int main() {
	int q;
	list<int> L;
	int query;
	int x;
	list<int>::iterator cursor = L.begin();

	cin >> q;
	for (int i = 0; i < q; i++) {
		cin >> query;
		if (query == 0) {
			cin >> x;
			cursor = L.insert(cursor, x);
		}
		else if (query == 1) {
			cin >> x;

			for (int j = 0; j < abs(x); j++) {
				if (x > 0)
					cursor++;
				else
					cursor--;
			}
		}
		else {
			cursor = L.erase(cursor);	
		}
	}

	for (cursor = L.begin(); cursor != L.end(); ++cursor)
		cout << *cursor << endl;
}




Measured memory_bytes: 18648
#include <bits/stdc++.h>
#include <numeric>
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); ++(i))
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<int, lint> pil;
typedef pair<lint, int> pli;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod*mod;
constexpr int MAX = 1000010;

int main(){
        int n;
        int dx[4]={-1, 0, 1, 0};
        int dy[4]={0, -1, 0, 1};
        while(scanf("%d", &n) && n){
                int L=0, R=0, U=0, D=0;
                vector<int> x(n, 0), y(n, 0);
                For(i, 1, n){
                        int k, d;
                        scanf("%d%d", &k, &d);
                        x[i]=x[k]+dx[d];
                        y[i]=y[k]+dy[d];
                        chmin(L, x[i]);
                        chmax(R, x[i]);
                        chmin(D, y[i]);
                        chmax(U, y[i]);
                }
                printf("%d %d\n", R-L+1, U-D+1);
        }
}


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

int main(void){
    int N, sum = 0, currentNumber;
    cin >> N;
    currentNumber = N;
    for(int i=0; i<8; i++){
        int rest = currentNumber % 10;
        sum += rest;
        currentNumber /= 10;
        if(currentNumber == 0) break;
    }
    if(N%sum == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#define M 100000
#define N 101
#define o 19260817
#define p 1000000007
#define q 998244353
int a[o],b[M],c[M],f[M],m;char r[N][N];
int dp(char*s,int t,int n)
{
    int u=n*n*n,v=n*n*n*n;
    for(int i=1;i<=n;i++)u=(u<<1|s[i])%o,v=(v<<1|s[i])%p;
    for(int i=a[u];i;i=b[i])if(c[i]==v)return f[i];
    b[++m]=a[u],c[a[u]=m]=v,f[u=m]=(s[1]+1ll)*dp(s+1,t+1,n-1)%q;
    for(int i=1,j;i<<1<=n;i++)for(memcpy(r[t]+1,s+1,i),j=1;(j+1)*i<=n;j++,f[u]=(f[u]+(long long)dp(r[t],t+1,i)*dp(s+i*j,t+1,n-i*j))%q)for(int k=1;k<=i;k++)r[t][k]&=s[i*j+k];
    return f[u];
}
int n;char s[N];
int main()
{
    scanf("%s",s+1),b[++m]=a[0],c[a[0]=m]=0,f[m]=1,n=strlen(s+1);
    for(int i=1;i<=n;i++)s[i]^=48;
    return 0&printf("%d\n",dp(s,0,n));
}

Measured memory_bytes: 75008
#include <iostream>
#include <string>
using namespace std;
int main() {
	int count = 0;
	string W, T;
	cin >> W;
	for (int i = 0; i < W.size(); i++)
		W[i] = tolower(W[i]);
	while (cin >> T, T != "END_OF_TEXT") {
		for (int i = 0; i < T.size(); i++)
			T[i] = tolower(T[i]);
		if (W == T)
			count++;
	}
	cout << count << endl;
}

Measured memory_bytes: 1192
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<map>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main(){
    int n;
    cin>>n;
    vector<int> x(n);
    rep(i,n) x.at(i)=i+1;
    vector<int> p(n);
    vector<int> q(n);
    rep(i,n) cin>>p.at(i);
    rep(i,n) cin>>q.at(i);
    int count=1,a,b;
    do{
        if(x==p){
            a=count;
        }
        if(x==q){
            b=count;
        }
        count++;
    }while(next_permutation(x.begin(),x.end()));

    cout<<abs(a-b)<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>  // min, max
#include <fstream>  // ifstream
#include <iomanip>  // setprecision
using namespace std;
typedef long long ll;

int main(void)
{
    ifstream inputFile("data/input.txt");
    if (getenv("SSH_CONNECTION") != nullptr) {
        cin.rdbuf(inputFile.rdbuf());
    }

    int N, M;
    cin >> N >> M;
    vector<int> k(M);
    vector<vector<int>> s(M, vector<int>(N, 0));
    vector<int> p(M);
    for (int i = 0; (i < M); ++i) {
        cin >> k[i];
        for (int j = 0; (j < k[i]); ++j) {
            cin >> s[i][j];
        }
    }
    for (int i = 0; (i < M); ++i) {
        cin >> p[i];
    }

    int res = 0;
    for (int i = 0; (i < pow(2, N)); ++i) {
        int numOn = 0;
        for (int j = 0; (j < M); ++j) {
            int sum = 0;
            for (int kk = 0; (kk < k[j]); ++kk) {
                sum += (i >> (s[j][kk]-1)) & 0x1;
            }
            if (p[j] == sum % 2)
                ++numOn;
        }
        if (numOn == M)
            ++res;
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 256
for i in range(int(input())):
	c,a,n = map(int,input().split())
	cnt = 0
	while True:
		if c<1 or a<1 or n<1:
			break
		c -= 1
		a -= 1
		n -= 1
		cnt += 1
	while True:
		if c<2 or a<1:
			break
		c -= 2
		a -= 1
		cnt += 1
	while True:
		if c<3:
			break
		c -= 3
		cnt += 1
	print(cnt)

Measured memory_bytes: 7632
def dist(a, b, c, d):
    return abs(a-c) + abs(b-d)

N, M = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(N)]
cd = [list(map(int, input().split())) for _ in range(M)]

for i in range(N):
    res = 10**10
    for j in range(M):
        if dist(ab[i][0], ab[i][1], cd[j][0], cd[j][1]) < res:
            res = dist(ab[i][0], ab[i][1], cd[j][0], cd[j][1])
            ans = j+1
    print(ans)


Measured memory_bytes: 40048
import sys
# input = sys.stdin.buffer.readline
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getlist():
    return list(map(int, input().split()))
import math
import heapq
from collections import defaultdict, Counter, deque
MOD = 10**9 + 7
INF = 10**15


def main():
    ans = 0
    s = input().strip()
    # print(s)
    pre = ""
    state = ""
    cnta = 0
    for c in s:
        if c == "A":
            if state == "A":
                cnta += 1
            else:
                state = "A"
                cnta = 1
        if c == "B":
            if state == "A":
                state = "AB"
            else:
                state = ""
                cnta = 0
        if c == "C":
            if state == "AB":
                ans += cnta
                state = "A"
            else:
                state = ""
                cnta = 0

    print(ans)

if __name__ == '__main__':
    main()

"""
9999
3

2916
"""

Measured memory_bytes: 40176
#include<bits/stdc++.h>
#define N 3005
using namespace std;
int F[N][N],ymax,xmax,ans;
int dy[4]={-1,0,1,0};
int dx[4]={0,1,0,-1};

void dfs(int y,int x,int cnt,int dir){
  if(F[y][x]>=0){
    int tmp=F[y][x];
    int ny=y+dy[tmp];
    int nx=x+dx[tmp];
    ans=max(ans,cnt+1);
    if(ny<0||nx<0||ymax<=ny||xmax<=nx)return;
    F[y][x]=-1;
    dfs(ny,nx,cnt+1,tmp);
    F[y][x]=tmp;
    return;
  }
  int ny=y+dy[dir];
  int nx=x+dx[dir];
  if(ny<0||nx<0||ymax<=ny||xmax<=nx)return;
  dfs(ny,nx,cnt,dir);
}

int main(){
  int n,x[N],y[N];
  char d[N];
  map<int,int> X,Y;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>x[i]>>y[i]>>d[i];
    X[x[i]]=0;
    Y[y[i]]=0;
  }
  int num=0;
  map<int,int>::iterator ite=X.begin();
  while(ite!=X.end()){
    (*ite).second=num;
    num++;
    ite++;
  }
  xmax=num;
  ite=Y.begin();
  num=0;
  while(ite!=Y.end()){
    (*ite).second=num;
    num++;
    ite++;
  }
  ymax=num;
  memset(F,-1,sizeof(F));
  for(int i=0;i<n;i++){
    if(d[i]=='^')F[Y[y[i]]][X[x[i]]]=0;
    if(d[i]=='>')F[Y[y[i]]][X[x[i]]]=1;
    if(d[i]=='v')F[Y[y[i]]][X[x[i]]]=2;
    if(d[i]=='<')F[Y[y[i]]][X[x[i]]]=3;
  }
  for(int i=0;i<n;i++)
    dfs(Y[y[i]],X[x[i]],0,0);
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 38632
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <stdio.h>
#include <bitset>
#include <complex>
#include <iomanip>
using namespace std;
using ll = long long;
#define MM 1000000000
#define MOD MM+7
#define pi pair<int32,int32>
#define pl pair<int64,int64>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
template<typename T>
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
int dp[100010];
int N,M;
vector<vector<int> > G;
int solve(int v){
    if (dp[v] != -1) return dp[v];
    int res = 0;
    for(int i = 0; i < G[v].size(); i++){
        res = max(res,solve(G[v][i])+1);
    }
    dp[v] = res;
    return dp[v];
}
int main(){
    cin >> N >> M;
    G.assign(N, vector<int>());
    for(int i = 0; i < M; i++){
        int x,y; cin >> x >> y;
        x--; y--;
        G[x].push_back(y);
    }
    fill(dp,dp+100001,-1);
    int ans = 0;
    for(int i = 0; i < N; i++){
        ans = max(ans,solve(i));
    }
    cout << ans << endl;
}
  



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

using namespace std;

int main()
{
	int n, m, h[1501], w[1501], s, t;
	
	while(cin>>n>>m && (n+m)){
		map<int,int> hmp1;
		map<int,bool> hmp2;
		
		for(int i = 0; i < n; i++){
			cin >> h[i];
		}
		for(int j = 0; j < m; j++){
			cin >> w[j];
		}
		
		for(int i = 0; i < n; i++){
			s = h[i];
			if(hmp2[s]){
				hmp1[s]++;
			} else {
				hmp2[s] = true;
				hmp1[s] = 1;
			}
			for(int j = i+1; j < n; j++){
				s += h[j];
				if(hmp2[s]){
					hmp1[s]++;
				} else {
					hmp2[s] = true;
					hmp1[s] = 1;
				}
			}
		}
		
		t = 0;
		for(int i = 0; i < m; i++){
			s = w[i];
			if(hmp2[s]){
				t += hmp1[s];
			}
			for(int j = i+1; j < m; j++){
				s += w[j];
				if(hmp2[s]){
					t += hmp1[s];
				}
			}
		}
		
		cout << t << endl;
	}
	
	return 0;
}

Measured memory_bytes: 21000
/**
 *     author: qodjf
 *     created: 04.17.2020 00:29:18
 */
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;
const int INF = 0x3f3f3f3f;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;
const ll MOD = 1e9 + 7;

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

string s;

int main() {
  cin >> s;
  int N = s.size();
  vector<int> ans(N, 0);

  int r = 0;
  for (int i = 0; i < N; i++) {
    if (s[i] == 'R') {
      r = i;
    } else {
      if ((i - r) % 2 == 0) {
        ans[r]++;
      } else {
        ans[r + 1]++;
      }
    }
  }

  int l = N;
  for (int i = N - 1; i >= 0; i--) {
    if (s[i] == 'L') {
      l = i;
    } else {
      if ((l - i) % 2 == 0) {
        ans[l]++;
      } else {
        ans[l - 1]++;
      }
    }
  }

  for (int i = 0; i < N; i++) {
    printf("%d%c", ans[i], i == N - 1 ? '\n' : ' ');
  }
}


Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<cstdio>
#include<cstdlib>
#include<queue>
#include<list>
#include<deque>
#include<cmath>
#include<unordered_map>
#include<numeric>
using namespace std;

using ll = int64_t;

/// <summary>
/// 単純なcoutの時に使う
/// </summary>
#define co(a) cout<<a<<endl


/// <summary>
/// [beg, end)の範囲を，添え字indexでループするfor文に置換します
/// </summary>
#define rep(i,a) for(ll i=0; i<a; ++i)

/// <summary>
/// 迷路等で使う方向のベクトル
/// </summary>
const vector<ll> dx = { 0, 1, 0, -1 }, dy = { 1, 0, -1, 0 };

/// <summary>
/// デバッグ時に使う
/// </summary>
#define DEBUG(x)     std::cout << #x << " : " << x << "\n"


///////////////////////////////////////////////////////////////////////////

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

	ll N;
	cin >> N;

	vector<ll> a(N);
	rep(i, N) {
		cin >> a[i];
	}
	ll ans = 0, alice = 0, bob = 0;

	sort(a.rbegin(), a.rend());

	rep(i, N) {
		if (i % 2 == 0) {
			alice += a[i];
		}
		else {
			bob += a[i];
		}
	}

	cout << alice - bob << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
 
int main(void)
 
{
    int a,b;
 
    scanf("%d %d",&a,&b);
 
    if( a < b )
        printf( "a < b\n" );
    if( a > b )
        printf( "a > b\n" );
    if( a == b )
        printf( "a == b\n");
 
    return 0;
}

Measured memory_bytes: 580
H, W = map(int, input().split())
DX = (-1, 0, 1, 0)
DY = (0, 1, 0, -1)

S = [[1] * (W + 2) for _ in range(H + 2)]
for i in range(1, H + 1):
    for j, x in enumerate(input(), start=1):
        if x == ".":
            S[i][j] = 0


for x in range(1, H + 1):
    for y in range(1, W + 1):
        if S[x][y] == 0:
            continue
        cnt = 0
        for dx, dy in zip(DX, DY):
            if S[x + dx][y + dy] == 0:
                cnt += 1
        if cnt == 4:
            print("No")
            exit()

print("Yes")


Measured memory_bytes: 3064
//#pragma warning disable
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System;
using System.Numerics;
using System.Threading.Tasks;
using static System.Math;
using static System.Console;
class Z { static void Main() => new K(); }
class K
{
	int F() => int.Parse(ReadLine());
	long FL() => long.Parse(ReadLine());
	int[] G() => ReadLine().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
	long[] GL() => ReadLine().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries).Select(long.Parse).ToArray();
	public const int MOD = 1000000007;
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	void Solve()
	{
		var s = Console.ReadLine();
		var n = int.Parse(s);
		Console.WriteLine(n % s.Sum(c => c - '0') == 0 ? "Yes" : "No");
	}
}


Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define forn for(int i=1;i<=n;i++)
#define form for(int j=0;j<m;j++)
#define pb push_back
#define mp make_pair
#define sc second
#define f first
#define kek cout<<"\n"
#define all(v)        ((v).begin()), ((v).end())
#define pob pop_back()
const ll MOD=1e9+7;
const ll INF=1e8;
const int maxn=1e5+5;
int main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
  int n,w;
  cin>>w>>n;
  pair<int,int> arr[n+1];
  forn cin>>arr[i].f>>arr[i].sc;
  int dp[w+1][n+1];
  for(int i=1;i<=n;i++) dp[1][i]=arr[i].sc;
  dp[1][0]=INF;
  for(int i=1;i<=n;i++) dp[1][0]=min(dp[1][0],dp[1][i]);
  
  for(int i=2;i<=w;i++)
  {
            dp[i][0]=INF;
            for(int j=1;j<=n;j++)
            {
                      if(i-arr[j].f<=0) dp[i][j]=arr[j].sc;
                      else dp[i][j]=dp[i-arr[j].f][0]+arr[j].sc;
            }
            for(int j=1;j<=n;j++) dp[i][0]=min(dp[i][0],dp[i][j]);
           // cout<<dp[i][0]<<endl;
  }
  cout<<dp[w][0];
  return 0;
}

Measured memory_bytes: 39424
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <cassert>
#include <string>
#include <memory.h>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <set>
#include <map>
#include <cctype>
#include <iomanip>
#include <sstream>
#include <cctype>
#include <fstream>
#include <cmath>
using namespace std;

#define REP2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define REP(i, n) REP2(i, 0, n)
#define ALL(c) (c).begin(), (c).end()
#define ITER(c) __typeof((c).begin())
#define PB(e) push_back(e)
#define FOREACH(i, c) for(ITER(c) i = (c).begin(); i != (c).end(); ++i)
#define MP(a, b) make_pair(a, b)
#define PARITY(n) ((n) & 1)

typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1000 * 1000 * 1000 + 7;
const double EPS = 1e-12;

int main(){
  int W, H;
  int dx[] = {0, -1, 0, 1};
  int dy[] = {1, 0, -1, 0};
  
  while(cin >> W >> H && W + H){
    int count = 0;
    vector<string> sblocks(H);
    vector<int> b_size;
    vector<int> total_y;
    
    REP(i, H) cin >> sblocks[i];
    vector<vector<int> > iblocks(H, vector<int>(W, -1));
    
    REP(i, H)REP(j, W)if(isdigit(sblocks[i][j])){
      queue<int> quex, quey;
      quex.push(i);
      quey.push(j);
      char	c    = sblocks[i][j];
      int	sz   = 1;
      int	toty = j;

      sblocks[i][j] = '.';
      iblocks[i][j] = count;
      while(!quex.empty()){
	int x = quex.front(); quex.pop();
	int y = quey.front(); quey.pop();
	
	REP(k, 4){
	  int nx = x + dx[k];
	  int ny = y + dy[k];
	  if(0 <= nx && nx < H &&
	     0 <= ny && ny < W &&
	     sblocks[nx][ny] == c){
	    
	    sblocks[nx][ny] = '.';
	    iblocks[nx][ny] = count;
	    sz++;
	    toty += ny;
	    quex.push(nx);
	    quey.push(ny);
	  }
	}
      }

      b_size.push_back(sz);
      total_y.push_back(toty);
      count++;
    }
    
    bool stable = true;
    REP(i, b_size.size()){
      double yl = INF;
      double yr = -INF;
      
      int &tot = total_y[i];
      int &cnt = b_size[i];

      set<int> used;
      
      REP(x, H)REP(y, W)if(iblocks[x][y] == i){
	if(x == H - 1 ||
	   (iblocks[x+1][y] != -1 && iblocks[x+1][y] != i)){
	  yl = min(yl, (double)y);
	  yr = max(yr, (double)y);
	}

	if(x > 0){
	  int id = iblocks[x-1][y];
	  if(id >= 0 && used.count(id) == 0 && id != i){
	    tot += total_y[id];
	    cnt += b_size[id];
	    used.insert(id);
	  }
	}
      }
      double g = (double)tot / cnt + 0.5;
      if(g < yl + EPS ||  g > yr + 1 - EPS) stable = false;
    }
    cout << (stable ? "STABLE" : "UNSTABLE") << endl;
  }  
  return 0;
}

Measured memory_bytes: 1244
n = int(input())
li = list(map(int,input().split()))
s = 0
for i in range(n):
    if li[i] % 2 == 0:
        if li[i] % 3 == 0 or li[i] % 5 == 0:
            continue
        else:
            s = 1
    else:
        continue
if s == 1:
    print("DENIED")
else:
    print("APPROVED")

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

typedef long double ld;
#define int long long   
#define PB push_back 
#define endl '\n'
#define all(x) (x).begin(),(x).end()
#define ii pair <int,int>
#define mii map <int,int>
#define vi vector<int> 
#define vii vector< ii >
#define F first
#define S second 
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define repd(i,a,b) for(int i=a; i>=b; --i)
#define sz(x) (int)((x).size())
const long double PI=3.141592653589793238462643383279502884197169399375105820974944;
inline void io(){
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);         
#endif
}

const int mod = 1e9+7;
const int maxn = 1e6+5;

void solve(){  
	int n; cin>>n;
	int mask = 0, a[n];
	rep(i, 0, n){
		cin>>a[i]; mask ^= a[i];
	}
	rep(i, 0, n){
		int ans = a[i]^mask;
		cout<<ans<<" ";
	}
}
signed main() 
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);// io();
    //cout<<setprecision(100);
    int tc=1; //cin>>tc;
    while(tc--){
        solve();cout<<'\n';
    }

    #ifndef ONLINE_JUDGE
        cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
    #endif

    return 0;
}


Measured memory_bytes: 5144
from collections import deque
def gridbfs(grid,sy,sx):
    INF = 10**18

    gridy = len(grid)
    gridx = len(grid[0])

    dist = [[INF]*gridx for _ in range(gridy)]
    dist[sy][sx] = 0
    q = deque([(sy,sx)])

    while q:
        y,x = q.popleft()
        for dy,dx in [(-1,0),(1,0),(0,-1),(0,1)]:
            ny,nx = y+dy, x+dx
            if not (0 <= ny < gridy and 0 <= nx < gridx):
                continue
            if grid[ny][nx] == '#':
                continue
            if dist[ny][nx] != INF:
                continue
            dist[ny][nx] = dist[y][x] + 1
            q.append((ny,nx))

    return dist

H,W = map(int,input().split())

Grid = [input() for _ in range(H)]

cnt = 0
for i in range(H):
    cnt += Grid[i].count('.')

d = gridbfs(Grid,0,0)

print(max(-1, cnt - d[H-1][W-1] -1))

Measured memory_bytes: 3316
h,w,k=map(int,input().split())
s=[list(input())for _ in range(h)]
g=1
for i in range(h):
    for j in range(w):
        if s[i][j]!='#':continue
        s[i][j]=g
        k=j-1
        while k>=0 and s[i][k]=='.':
            s[i][k]=g
            k-=1
        k=j+1
        while k<w and s[i][k]=='.':
            s[i][k]=g
            k+=1
        g+=1
for i in range(h-2,-1,-1):
    if s[i][0]=='.':
        for j in range(w):
            s[i][j]=s[i+1][j]
for i in range(h):
    if s[i][0]=='.':
        for j in range(w):
            s[i][j]=s[i-1][j]
for t in s:
    print(*t)

Measured memory_bytes: 7504
x=int(input())
if 400 <= x <=599:
    print(8)
elif 600 <= x <= 799:
    print(7)
elif 800 <= x <= 999:
    print(6)
elif 1000 <= x <= 1199:
    print(5)
elif 1200 <= x <= 1399:
    print(4)
elif 1400 <= x <= 1599:
    print(3)
elif 1600 <= x <= 1799:
    print(2)
else:
    print(1)

Measured memory_bytes: 9180
//  Mayank Agarwal
//  IIIT Hyderabad



#include<bits/stdc++.h>
using namespace std;
const long long int M = 1000000007; 
#define ll long long int
#define ld double
#define pb push_back
#define mp make_pair
ll power(ll x, ll y,  ll p) 
{ 
    ll res = 1;      
    x = x % p;   
    while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x) % p; 
        y = y>>1;x = (x*x) % p; 
    } return res%p; 
} 
ll modinver(ll a,ll b)
{
    return (power(a,1,M)*power(b,M-2,M))%M;
}
void SieveOfEratosthenes(int n) 
{   
    bool prime[10005]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        if (prime[p] == true) 
        { 
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
} 
ll dp[404][403];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    ll n;
    cin>>n;
    std::vector<ll> v(n);
    for (int i = 0; i <=403; ++i)
    {
    	for (int j = 0; j <=403; ++j)
    	{
    		dp[i][j]=1e17;
    	}
    }
    for(ll& x:v)
    {
    	cin>>x;
    }
    std::vector<ll> cum(n);
    cum[0]=v[0];
    for (int i = 1; i < n; ++i)
    {
    	cum[i]+=cum[i-1]+v[i];
    }
    for (int L = n-1; L >=0; --L)
    {
    	for (int R = L; R < n; ++R)
    	{
	    	if(L==R)
	    	{
	    		dp[L][R]=0;
	    		continue;
	    	}
    		for(int X=L;X<R;X++)
    		{
	    		
	    		if(L!=0)
	    			dp[L][R]=min({dp[L][R],cum[X]-cum[L-1]+dp[L][X]+cum[R]-cum[X]+dp[X+1][R]});
	    		else
	    			dp[L][R]=min({dp[L][R],cum[X]+dp[L][X]+cum[R]-cum[X]+dp[X+1][R]});
	    	}
    		// cout<<L<<" "<<R<<" "<<dp[L][R]<<'\n';
    	}
    }
    cout<<dp[0][n-1]<<'\n';
}


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

int main( void) 
{
 
  int a,b ;
  cin >> a >> b ;
  
  a-- ;
  
  for( int i = b-a ; i <= b ; i++ )  cout << i << " " ;
  
  for( int i = b+1 ; i <= b+a ; i++ )  cout << i << " " ;
  
  return 0 ;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LL long long
#define LD long double
#define pb push_back
#define mp make_pair
#define ss(x) (int) x.size()
#define fi first
#define se second
#define cat(x) cerr << #x << " = " << x << endl
#define rep(i, j, n) for (int i = j; i <= n; ++i)
#define per(i, j, n) for (int i = n; j <= i; --i)
#define all(x) x.begin(), x.end()
#define ull unsigned long long

using namespace std;

LL n;
vector <int> v;
deque <int> q;

int main() {
	scanf ("%lld", &n);
	n++;
	while (n > 1) {
		if (n % 2 == 0) {
			v.pb(0);
			n /= 2;
		}
		else {
			v.pb(1);
			n -= 1;
		}
	}
	printf ("%d\n", 2 * ss(v));
	reverse(all(v));
	rep(i, 1, ss(v))
		printf ("%d ", i);
	int cnt = 0;
	for (auto it : v) {
		if (it == 0) q.push_back(++cnt);
		else q.push_front(++cnt);
	}
	for (auto it : q) printf ("%d ", it);
	
	
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <functional>
#include <algorithm>
#include <climits>
#include <string>
#include <vector>
#include <map>
#include <cmath>

using namespace std;

namespace _{struct _{_(){ // initialize
  cin.tie(0); ios::sync_with_stdio(false);
}}_;}
template <typename T, size_t size>
inline size_t len(const T (&)[size]) { return size; }
#define println(s) cout << s << '\n';
#define str to_string
#define rep(i, n) for (int i=0; i<int(n); i++)
#define all(c) (c).begin(), (c).end()


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

  int count = 0;
  for (int i=1; i<=c; i++) {
    if (c % i == 0) {
      if (i >= a && i <= b) count++;
    }
  }
  cout << count << endl;
  return 0;
}

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

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int a = in.nextInt();
		int n = a, b = 0;
		while(0 < a) {
			b += a%10; a /= 10;
		}
		if(n % b == 0) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}


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

bool find( string a, string b )                         //文字列aの中に、bが含まれているかどうか判定する関数
{
    for( int i = 0; i <= a.size() - b.size(); i++ )
    {
        int j = i, k = 0;
        while( k < b.size() )
        {
            if( a[j] == b[k] )
            {
                j++;
                k++;
            }
            else
                break;
        }
        if( k == b.size() )
            return true;
    }
    return false;
}

int main()
{
    string cipher;
    string cand;

    int i = 0;                                               //cand[24]まで順にずらした文字列を順に格納
    while ( getline( cin, cipher ) )
    {
        for( int k = 1; k < 26; k++ )
        {
            cand = "";
            for( int j = 0; j < cipher.size(); j++, i++ )    //candに文字列を入れる操作
            {
                if( cipher[j] == ' ' )
                    cand += " ";
                else if( cipher[j] == '.' )
                    cand += ".";
                else
                    cand += 97 + ( cipher[j] + k ) % 26;     //cipherの文字列を順にずらして、candに格納
            }
            if( find( cand, "this" ) == true || find( cand, "that" ) == true || find( cand, "the" ) == true )
                cout << cand << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3124
#include<bits/stdc++.h>
  
using namespace std;
typedef long long ll;
  
ll N,Q;
  
  
//与えられた要素数より大きくすること 配列範囲
const ll INT_INF = 1LL << 31;
//INF定義
const ll MAX_N = 1LL << 20;
ll n; //要素数が与えられた時、それ以上の最小の２＾k数が欲しい
ll dat[2*MAX_N - 1]; //RMQのサイズは２*MAX_N（ビットと混同しないように）
  
void init(ll a){
  n = 1;  while( n < a){ n *= 2;}
  for(ll i = 0; i < 2*n - 1 ; i++){
    dat[i] = 0;} // infで初期化,範囲外参照でREしやすいので注意
}
void update(ll k, ll a){
  k += n - 1;
  dat[k] += a;
  while( k > 0){
    k = ( k - 1)/ 2;
    dat[k] =  dat[ 2* k + 1] + dat[2*k + 2] ;}
}
  
//[a,b)での最小値を求める
// l , r　は　k番目のノードが[l,r)に対応していることを意味
ll query(ll a, ll b, ll k , ll l, ll r){
  if( r <= a || b <= l){ return 0 ;}
  else if( a <= l && r <= b){ return dat[k];}
  else{
    ll vl = query(a,b,2*k + 1, l, ( l + r) / 2);
    ll vr = query(a, b, 2* k + 2, ( l + r) / 2, r);
    
  return vl + vr ;}
}
//initで初期化忘れないこと　0-index か 1-index問題によって注意(0-に合わせる）
  
  
int main(){
 cin >> N >> Q;
  init(N);
    
  for(ll i = 0; i < Q; i++){
    ll com,x,y; cin >> com >> x >> y;
    if( com == 0){ x--; update(x,y);}
    else{x--; y--; cout << query(x,y+1,0,0,n) << endl;}
      
  }
  return 0;}


Measured memory_bytes: 5140
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main() {
  ll l,r,c=0,k;
  cin >>l>>r;
  vector <ll> v,p;
  for(ll i=l;i<=r;i++){
    if(c==2019) break;
    v.push_back(i%2019);
    c++;
  }
  sort(v.begin(),v.end());
  ll vs=v.size(),b=0,ans=100000;
  for(ll i=0;i<vs-1;i++){
    for(ll j=i+1;j<vs;j++){
      if(i==j) continue;
      ans=min(ans,(v[i]*v[j])%2019);
    }
  }
  cout <<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
from collections import Counter
import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))
B = Counter(A)
C = [x[0] for x in B.items() if x[1] > 1]
C += [x[0] for x in B.items() if x[1] > 3]
C.sort(reverse = True)
if len(C) > 1:
    print(C[0] * C[1])
else:
    print(0)

Measured memory_bytes: 64920
#include <iostream>
using namespace std;
#define MAX_N 100
#define MAX_W 100000
int N, W;
long long dp[MAX_N + 1][MAX_W + 1];

int main() {
    cin >> N >> W;
    int w[N + 1], v[N + 1];
    for (int i = 0; i < N; i++) cin >> w[i] >> v[i];

    for (int i = 0; i < N; i++) {
        for (int j = 0; j <= W; j++) {
            if (j < w[i]) {
                dp[i + 1][j] = dp[i][j]; 
            } else {
                dp[i + 1][j] = max(dp[i][j], dp[i][j - w[i]] + v[i]);
            }
        }
    }
    cout << dp[N][W] << endl;
}

Measured memory_bytes: 78336
from collections import deque

H,W=map(int,input().split())
CH,CW=map(int,input().split())
DH,DW=map(int,input().split())

S=[list(input()) for _ in range(H)]
MAX_COST = 10 ** 9
Cost=[ [ MAX_COST for _ in range(W)] for _ in range(H)]

# print(S)

ans = -1

deq = deque()

deq.append((CH-1,CW-1,0))
Cost[CH-1][CW-1] = 0;

walk=[(1,0),(0,1),(-1,0),(0,-1)]

# used = set()

while 0 < len(deq):
	h,w,c=deq.popleft()
	# print(h,w,c)
	for i,j in walk:
		if 0 <= h+i and h+i < H and 0 <= w+j and w+j < W:
			if S[h+i][w+j] == '.' and c < Cost[h+i][w+j]:
				Cost[h+i][w+j] = c
				# print("updl ", i,j,h+i,w+j,c)
				deq.appendleft((h+i,w+j,Cost[h+i][w+j]))
	for i in range(-2,3,1):
		for j in range(-2,3,1):
			# print(i,j)
			if 0 <= h+i and h+i < H and 0 <= w+j and w+j < W:
				if S[h+i][w+j] == '.':
					if c + 1 < Cost[h+i][w+j]:
						Cost[h+i][w+j] = c + 1
						deq.append((h+i,w+j,Cost[h+i][w+j]))
						# print("updr ", h+i,w+j,Cost[h+i][w+j])

if Cost[DH-1][DW-1] == MAX_COST:
	print(-1)
else:
	print(Cost[DH-1][DW-1])

Measured memory_bytes: 142836
GI = lambda: int(raw_input()); GIS = lambda: map(int, raw_input().split())

def main():
  N = GI()
  a = [GIS(), GIS()]

  def recurse(r, c):
    if r > 1 or c == N:
      return 0
    return a[r][c] + max(recurse(r+1, c), recurse(r, c+1))

  print(recurse(0, 0))

main()

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

using namespace std;
using LL = long long;

constexpr int N = 1e5 + 5;

map< pair< int, int>, int> mp;

int msd(int x) {
    while (x >= 10) {
        x /= 10;
    }
    return x;
}


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

    int n;
    cin >> n;

    vector< int> freq(10);
    for (int i = 1; i <= n; i++) {
        mp[{msd(i), i % 10}]++;
    }

    LL result = 0;
    for (int i = 1; i <= n; i++) {
        result += mp[{i % 10, msd(i)}];
    }
    cout << result << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b){
  if(b==0) return a;
  return gcd(b, a%b);
}
int main() {
  int n;
  cin >> n;
  int a[100100];
  for(int i=0; i<n; i++) cin >> a[i];
  vector<int> L(n), R(n);
  for(int i=0; i<n-1; i++){
    L[i+1] = gcd(L[i],a[i]);
  }
  for(int i=n-1; i>0; i--){
    R[i-1] = gcd(R[i],a[i]);
  }
  int maxx = 1;
  for(int i=0; i<n; i++){
    maxx = max(maxx, gcd(L[i],R[i]));
  }
  cout << maxx << endl;
}

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

ll n, a[100009], b[100009];

int main()
{
    ll i, ans = 0, x;
    cin >> n;
    for(i = 0; i <= n; i++)
        cin >> a[i];
    for(i = 0; i < n; i++)
        cin >> b[i];

    for(i = 0; i < n; i++)
    {
        x = min(a[i], b[i]);
        ans += x;
        b[i] -= x;
        a[i] -= x;

        x = min(a[i+1], b[i]);
        ans += x;
        b[i] -= x;
        a[i+1] -= x;
    }

    cout << ans;
}


Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using p = pair<int, int>;
#define INF 1001001001
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repX(i, n ,x) for (int i = x; i < (int)(n); i++)
#define repBack(i, n) for (int i = n; i >= 0; i--)
#define dup(x,y) (((x)+(y)-1)/(y))

int main() {
    int X,Y,Z;
    cin >> X >> Y >> Z;
    swap(X,Y);
    swap(X,Z);
    printf("%d %d %d",X,Y,Z);

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    int iInputM, iInputF, iInputR;
    int iSum;
    int i;

    for (i = 0; i < 60; i++) {
        scanf("%d %d %d", &iInputM, &iInputF, &iInputR);
        if (iInputM == -1 && iInputF == -1 && iInputR == -1) break;
        iSum = iInputM + iInputF;
        if (iInputM == -1 || iInputF == -1) printf("F\n");
        else if (iSum >= 80) printf("A\n");
        else if (iSum >= 65) printf("B\n");
        else if (iSum >= 50) printf("C\n");
        else if (iSum >= 30) {
            if (iInputR >= 50) printf("C\n");
            else printf("D\n");
        }
        else printf("F\n");
    }

    return 0;
}


Measured memory_bytes: 2104
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    
    int a = sc.nextInt();
    int b = sc.nextInt();
	int h = sc.nextInt();
    
    int ab = a + b;
    
    System.out.println(ab * h / 2);
  }
}

Measured memory_bytes: 21972
//S.G.N.//
#include <bits/stdc++.h>
using namespace std;
typedef vector< long long > vi;
typedef long long ll;
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define endl "\n"
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define fr(n) for(ll i=0;i<n;i++)
#define tr(a) for(auto it=a.begin();it!=a.end();it++)
#define N 998244353445 
#define PI 3.1415926535897932384
#define F first
#define S second
#define mp make_pair
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mod 1000000007
vector<ll> v[100001];
ll vis[100001]={0};
pair<ll,ll> dfs(ll i)
{
  vis[i]=1;
  vector<pair<ll,ll>> vect;
  tr(v[i])
  {
    if(vis[*it]==0)
    {
      vect.pb(dfs(*it));
    }
  }
  if(vect.size()==0)
    return (make_pair(1,1));
  else if(vect.size()==1)
  {
    return (make_pair((vect[0].first+vect[0].second)%mod,vect[0].first));
  }
  ll pro1=1;
  ll pro2=1;
  tr(vect)
  {
    pro1=(pro1*((it->first+it->second)%mod))%mod;
    pro2=(pro2*(it->first))%mod;
  }
  return (make_pair(pro1,pro2));
}
void solve()
{
 ll n;
 cin>>n;
 fr(n-1)
 {
 ll x,y;
 cin>>x>>y;
 v[x].pb(y);
 v[y].pb(x);
 }
 pair<ll,ll> p=dfs(1);
 cout<<(p.first+p.second)%mod;
}
int main()
{
  
  #ifndef ONLINE_JUDGE
     * freopen("input.txt", "r", stdin);
      freopen("output.txt", "w", stdout);
  #endif
  FAST
  ll test;
test=1;
  //cin>>test;
  while(test--)
  {
    solve();
  }
  return 0;
}


Measured memory_bytes: 18180
//Author: A_S_M_M@sud_P@rvez
#include<bits/stdc++.h>
using namespace std;
#define    MP ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define    For(i,n) for(int i=0;i<n;i++)
#define    forn(i,n) for(int i=1;i<=n;i++)
#define    fors(i,s) for(int i=0;i<s.size();i++)
#define    all(v) v.begin(),v.end()
#define    gcd(a, b) __gcd(a , b)
#define    lcm(a,b) (a*(b/__gcd(a,b)))
#define    test   int t;cin>>t;for(int l=0;l<t;l++)
#define    min3(a,b,c)     min(a,min(b,c))
#define    max3(a,b,c)     max(a,max(b,c))
#define    min4(a,b,c,d)   min(min(a,b),min(c,d))
#define    max4(a,b,c,d)   max(max(a,b),max(c,d))
#define    nl     "\n"
#define    End    return 0 
#define    gt     greater<int>()
#define    ll     long long 
#define    mp     make_pair
#define    pb     push_back
#define    vi     vector<int>
#define    vl     vector<ll>
#define    mod    1000000007
#define    sp(n)  fixed<<setprecision(n)
#define    pi     acos(-1)

int main()
{
MP;
    //test
    {
        ll n,m,x,c=0;
        cin>>n>>m;
        while(n--)
        {
            ll a,b;
            cin>>a>>b;
            if(a*a+b*b<=m*m)c++;
        }
        cout<<c;
    }
    
End;
}


Measured memory_bytes: 3652
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
using namespace std;

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

using LL = long long;
using PII = pair<int, int>;
using VI = vector<int>;

const int N = 100000;
LL n, a[N], b[N], c[N];

int main() {
    cin >> n;
    REP(i, n) cin >> a[i] >> b[i], c[i] = i;
    sort(c, c + n, [&](int i, int j) {
        return a[i] + b[i] > a[j] + b[j];
    });
    LL ans = 0;
    REP(i, n) if (i % 2 == 0) ans += a[c[i]]; else ans -= b[c[i]];
    cout << ans << endl;
    return 0;
}

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

int main()
{
    int h, w;
    std::cin >> h >> w;
    h += 2;
    w += 2;
    std::vector<std::string> mt{std::vector<std::string>(h, std::string(w, '.'))};
    for (auto i = 1; i < h - 1; ++i)
    {
        std::string s;
        std::cin >> s;
        std::copy(s.begin(), s.end(), mt[i].begin() + 1);
    }
    for (auto i = 1; i < h - 1; ++i)
    {
        for (auto j = 1; j < w - 1; ++j)
        {
            if (mt[i][j] != '#')
            {
                int bomb_num{};
                for (auto ii = i - 1; ii < i + 2; ++ii)
                {
                    for (auto jj = j - 1; jj < j + 2; ++jj)
                    {
                        bomb_num += (mt[ii][jj] == '#') ? 1 : 0;
                    }
                }
                mt[i][j] = '0' + bomb_num;
            }
            std::cout << mt[i][j];
        }
        std::cout << "\n";
    }
    return 0;
}


Measured memory_bytes: 256
# input
n = int(input())
alist = list(map(int, input().split()))

# process/output
if not 1 in alist:
    print(-1)

else:
    i = 1
    for j in range(n):
        if alist[j] == i:
            i+=1
                    
    print(n-i+1)


Measured memory_bytes: 24768
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
using namespace std;

int main(){
    int N,L,aji[210],p,sum=0,min=400;
    cin>>N>>L;
    for(int i=0;i<N;++i){
        aji[i]=L+i;
        sum+=aji[i];
        if(abs(aji[i])<min){
            min=abs(aji[i]);
            p=i;
        }
    }

    cout<<sum-aji[p]<<endl;
    return 0;
}

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

int dfs(int v, int n, bool g[8][8], bool seen[8]){
   int ans =0;
   bool all = true;
   rep(i, n){ 
      if(seen[i] == false)
         all = false;
   }

   if(all){
      //全て辿れた
      return 1;
   }

   for(int i=0;i<n;++i){
      if(g[v][i]==false) continue;
      if(seen[i]) continue;

      seen[i]=true;
      ans +=dfs(i,n,g,seen);
      seen[i]=false;
   }
  
   return ans;
}

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

   bool g[8][8];
   rep(i,8)rep(j,8) g[i][j] = false;
   rep(i,m){
      int a , b;
      cin >> a >> b;
      --a;
      --b;

      g[a][b] = true;
      g[b][a] = true;
   }

   bool seen [8];
   rep(i,n) seen[i] = false;
   seen[0] = true;
   cout << dfs(0, n, g,seen)<< endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <queue>
#include <functional>

using namespace std;
static const long long int INF = 1e16;
typedef pair<int, int> P;


void solve()
{
	string s;
	cin >> s;
	for (int i = 0; i < s.size(); ++i)
	{
		if (s[i] == ',')
		{
			cout << ' ';
		}
		else
		{
			cout << s[i];
		}
	}
	cout << endl;
}

int main()
{
	solve();
	return(0);
}

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

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef vector<long long> vl;
typedef pair<long long, long long> pl;
typedef vector<vector<long long>> matrix;

#define F 						first
#define S 						second
#define PB 						push_back
#define MP 						make_pair
#define all(c) 					c.begin(), c.end()
#define f(i,a,b) 				for(ll i=a; i<b; i++)
#define rep(i,n) 				f(i,0,n)
#define tr(c,i) 				for(typeof(c).begin() i = c.begin(); i != c.end(); i++)
#define present(c,x) 			(c.find(x) != c.end())	//for set and map
#define cpresent(c,x) 			(find(all(c),x) != c.end())	//for vectors
#define w(t)					ll t; cin>>t; while(t--)
#define epsilon 				1e-9
#define MOD						(ll)1e9

void doublade() {
	ios::sync_with_stdio(false); cin.tie(0); cout.precision(10);
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif
}

int main() {
	doublade();
	// w(t) {
		string s;
		cin >> s;
		ll sum = 0;
		rep(i, s.length()) {
			ll temp = s[i]-'0';
			sum += (temp%9);
			sum %= 9;
		}
		if(sum==0) cout<<"Yes\n";
		else cout<<"No\n";
	// }
	return 0;
}

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

int main(void)
{
    int a,b;
    cin >> a >> b;
    if(a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0)
    {
        cout << "Possible" << endl;
    }
    else
    {
        cout << "Impossible" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){


    int W,H,x,y,r;


    scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);


    if(W<x+r || x-r<0 || H<y+r || y-r<0){
        printf("No\n");


    }else{


        printf("Yes\n");


     }


    return 0;


}

Measured memory_bytes: 584
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
 
const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;
ll gcd(ll x, ll y){
  if(y==0) return x;
  else return gcd(y, x%y);
}
ll lcm(ll x,ll y){
  ll g=gcd(x,y);
  return x/g*y;
}

using Graph=vector<vector<int>>;
Graph G;

int main(){
  int n;
  cin >> n;
  
  vector<string> vec(n);
  rep(i,n) cin >> vec[i];

  int a[26]={};
  rep(i,vec[0].size()){
    a[vec[0][i]-'a']++;
  }
  rep(i,vec.size()-1){
    int b[26]={};
    rep(j,vec[i+1].size()){
      b[vec[i+1][j]-'a']++;
    }
    rep(j,26){
      a[j]=min(a[j],b[j]);
    }
  }
  rep(i,26){
    if(a[i]){
      rep(j,a[i]) cout<<char('a'+i);
    }
  }
  
  cout<<endl;
  
  
}
    


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

using namespace std;
using ll=long long ;

void solve() {
    int n; cin >> n;
    vector<ll> sum(n+1);
    sum[0] = 0;
    for (int i = 1; i <= n; i++) {
        int x; cin >> x;
        sum[i] = sum[i-1] + x;
    }
    ll res = 1ll<<60;
    for (int i = 1; i < n; i++) {
        ll d = abs(2*sum[i] - sum[n]);
        res = min(res, d);
    }
    cout << res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


Measured memory_bytes: 1792
#include <stdio.h>

int main(void){
    int h,w;
    scanf("%d %d",&h,&w);
    char data[h][w+1];
    for(int i = 0;i<h;i++){
        scanf("%s",data[i]);
    }
    int count = 0;
    for(int i = 0;i<h;i++){
        for(int j = 0;j<w;j++){
            count = 0;
            if(data[i][j] == '#'){
                continue;
            }
            if(i != h-1){
                if(data[i+1][j] == '#'){
                    count++;
                }
                if(data[i+1][j+1] == '#'){
                    count++;
                }
                if(data[i+1][j-1] == '#'){
                    count++;
                }
            }
            if(i != 0){
                if(data[i-1][j] == '#'){
                    count++;
                }
                if(data[i-1][j+1] == '#'){
                    count++;
                }
                if(data[i-1][j-1] == '#'){
                    count++;
                }
            }
            if(data[i][j+1] == '#'){
                count++;
            }
            if(data[i][j-1] == '#'){
                count++;
            }
            if(count == 0){
                data[i][j] = '0';
            }else{
                data[i][j] = '0' + count;
            }
        }
    }
    
    for(int i = 0;i<h;i++){
        printf("%s\n",data[i]);
    }
}


Measured memory_bytes: 128