akhauriyash/Code-Regression huggingface dataset:
UNSEARCHED = 0
SEARCHED = -1
LAND = 1
SEA = 0
result = []

while(True):
    str = input().split(" ")
    w = int(str[0])
    h = int(str[1])
    if w == 0 and h == 0:
        break
    area = [[0 for i in range(w)] for i in range(h)]
    status = [[UNSEARCHED for i in range(w)] for i in range(h)]
    index = 0
    
    for i in range(h):
        str = input().split(" ")
        area[i] = [int(str[l]) for l in range(w)]
    
    for i in range(h):
        for l in range(w):
            if status[i][l] == UNSEARCHED and area[i][l] == LAND:
                index += 1
                status[i][l] = index
    
                # (y,x)
                stack = [(i+1, l), (i-1, l), (i, l+1), (i, l-1), (i+1, l+1), (i+1, l-1), (i-1, l-1), (i-1, l+1)]
                while(len(stack) > 0):
                    s = stack.pop(0)
                    
                    if not (0 <= s[0] < h and 0 <= s[1] < w):
                        continue
    
                    if status[s[0]][s[1]] == UNSEARCHED and area[s[0]][s[1]] == LAND :
                        status[s[0]][s[1]] = index
                        stack.append((s[0], s[1]))
                        stack.append((s[0], s[1]+1))
                        stack.append((s[0], s[1]-1))
                        stack.append((s[0]+1, s[1]))
                        stack.append((s[0]-1, s[1]))
                        stack.append((s[0]+1, s[1]+1))
                        stack.append((s[0]+1, s[1]-1))
                        stack.append((s[0]-1, s[1]+1))
                        stack.append((s[0]-1, s[1]-1))
                    elif area[s[0]][s[1]] == SEA:
                        status[s[0]][s[1]] = SEARCHED
    
            elif status[i][l] == UNSEARCHED:
                status[i][l] = SEARCHED
    
    result.append(index)

for i in result:
    print(i)
    





Measured memory_bytes: 5628
#include <bits/stdc++.h>
        using namespace std;
        #define ll long long int
        #define pb push_back
        #define mk make_pair
        #define ft first
        #define sc second
        #define ppb pop_back
        #define sz size
        #define forn(i,a,n) for(i=a;i<n;i++)
        #define M 998244353 
        #define inf 2e18
        
        int main() {
 
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
        
        ll n,m;
        cin>>n>>m;
        vector<ll> v(n);
        ll sum=0;
        for(ll i=0;i<n;i++){
            cin>>v[i];
            sum+=v[i];
        }
        sort(v.begin(),v.end());
        reverse(v.begin(),v.end());
        long double c = (4*m);
        c = (1/c)*sum;
        // cout<<c;
        ll fl=0;
        for(ll i=0;i<m;i++){
            if(v[i]<c){
                fl=1;
            }
        }
        if(fl)
            cout<<"No\n";
        else
            cout<<"Yes\n";

        return 0;
    }

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10 ** 6)

N, M = map(int, input().split())
graph = [[] for _ in range(N)]
for i in range(M):
    a, b = map(lambda x: int(x) - 1, input().split())
    graph[a].append(b)
    graph[b].append(a)
def dfs(cur, visited):
    if visited == (1 << N) - 1:
        return 1
    res = 0
    for to in graph[cur]:
        if not visited & (1 << to):
            res += dfs(to, visited | (1 << to))
    return res
print(dfs(0, 1))


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

template<typename T>
T factorial(int n) {
    T ans = 1;
    for (int i = n; i > 0; i--) {
        ans *= i;
    }
    return ans;
}


int main() {
    int N;
    cin >> N;
    vector<pair<int, int>> A;
    for (int i = 0; i < N; i++) {
        int x, y;
        cin >> x >> y;
        A.push_back(make_pair(x, y));
    }
    vector<int> p;
    for (int i = 0; i < N; i++) p.push_back(i);
    double d = 0;
    do {
        for (int i = 0; i < N - 1; i++) {
            d += sqrt((A[p[i]].first - A[p[i + 1]].first) *
                          (A[p[i]].first - A[p[i + 1]].first) +
                      (A[p[i]].second - A[p[i + 1]].second) *
                          (A[p[i]].second - A[p[i + 1]].second));
        }
    } while (next_permutation(p.begin(), p.end()));
    d /= factorial<int>(N);
    cout << fixed << setprecision(10) << d << endl;
}


Measured memory_bytes: 3768
import collections
N=int(input())
S=[]
P=[]
ids=[]
for i in range(N):
    s,p=input().split()
    p=int(p)
    S.append(s)
    P.append(p)
    ids.append(i+1)

s_ps = collections.defaultdict(list)
for s,p,i in zip(S,P,ids):
    s_ps[s].append((i,p))

for s, ps in sorted(s_ps.items(),key=lambda x:x[0]):
    for id, p in sorted(ps,key=lambda x:-x[1]):
        print(id)


Measured memory_bytes: 3316
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main{

	Scanner sc;

	static final int INF=1<<28;
	static final double EPS=1e-9;

	void run(){
		int[] p=new int[10001];
		int k=1;
		for(int i=1; i<p.length; i++){
			while(!isPrime(++k));
			p[i]=k+p[i-1];
			// println(k+"");
		}

		sc=new Scanner(System.in);
		for(;;){
			int n=sc.nextInt();
			if(n==0)
				break;
			println(p[n]+"");
		}
		sc.close();
	}

	boolean isPrime(int n){
		int m=(int)sqrt(n);
		for(int i=2; i<=m; i++)
			if(n%i==0)
				return false;
		return true;
	}

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

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

	public static void main(String[] args){
		new Main().run();
	}
}

Measured memory_bytes: 11000
#include <iostream>
#include <vector>
#include <math.h>
#include <string>
#include <string.h>
#include <stack>
#include <algorithm>
#include <stdio.h>
#include <functional>
using namespace std;

int main()
{
	int x, y;
	while (cin >> x >> y)
	{
		if (x == 0 && y == 0)
		{
			break;
		}
		if (x < y)
		{
			cout << x << " " << y << endl;
		}
		else
		{
			cout << y << " " << x << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1160
import java.util.*

fun main(args:Array<String>?): Unit {
    repeat(readLine()!!.trim().toInt()){
        println(Section.parse(readLine()!!.trim()).needToWin)
    }
}

sealed class Section {
    abstract val needToWin: Int
    class LowestSection(population: Int): Section(){
        override val needToWin: Int = population / 2 + 1
    }
    class HigherSection(lower: Collection<Section>): Section() {
        override val needToWin: Int by lazy{lower.map(Section::needToWin).sorted().take(lower.size / 2 + 1).sum()}
    }
    companion object {
        fun parse(expression: String): Section {
            tailrec fun sub(position: Int, stack: Stack<Stack<Section>>): Section {
                return if (position < expression.length) {
                    when(expression[position]) {
                        '[' -> {
                            stack.push(Stack())
                            sub(position + 1, stack)
                        }
                        ']' -> {
                            val top = stack.pop()
                            stack.peek().push(HigherSection(top))
                            sub(position + 1, stack)
                        }
                        else -> {
                            val end = (position until expression.length).find { expression[it] == ']' }!!
                            stack.peek().push(LowestSection((position until end).map { expression[it] - '0' }.reduce { acc, i -> acc * 10 + i }))
                            sub(end, stack)
                        }
                    }
                }else stack.peek().peek()
            }
            val stack = Stack<Stack<Section>>()
            stack.add(Stack())
            return sub(0, stack)
        }
    }
}


Measured memory_bytes: 82704
N = int(input())
S = [input() for _ in range(N)]
ans = 0
BA, BX, XA = 0, 0, 0
for s in S:
  ans += s.count('AB')
  if s[0] == 'B' and s[-1] == 'A':
    BA += 1
  elif s[0] == 'B':
    BX += 1
  elif s[-1] == 'A':
    XA += 1

x = max(0, BA - 1)
ans += x
BA -= x
x = min(BA, BX)
ans += x
BA -= x
x = min(BA, XA)
ans += x
BA -= x
ans += min(XA, BX)
print(ans)

Measured memory_bytes: 3700
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <functional>

using namespace std;

typedef pair<int, string> P;

int main() {
	int n;
	while (cin >> n) {
		if (n == 0) {
			break;
		}
		string s;
		getline(cin, s);
		priority_queue< string, vector<string>, greater<string> > pq;
		for (int i = 0; i < n; i++) {
			getline(cin, s);
			while (s.find(' ') != string::npos) {
				int k = s.find(' ');
				pq.push(s.substr(0, k));
				s = s.substr(k+1);
			}
			pq.push(s);
		}
		priority_queue<P> pqq;
		char c;
		cin >> c;
		while (!pq.empty()) {
			string p = pq.top();
			pq.pop();
			if (p[0] == c) {
				P pp;
				pp.first = 1;
				pp.second = p;
				while (!pq.empty()) {
					if (p == pq.top()) {
						pp.first++;
						pq.pop();
					} else {
						break;
					}
				}
				pqq.push(pp);
			} 
		}
		if (pqq.empty()) {
			cout << "NA" << endl;
		} else {
			int counter = 0;
			for (int i = 0; i < 5 && counter < 5; i++) {
				if (pqq.empty()) {
					break;
				}
				priority_queue< string, vector<string>, greater<string> > q;
				P ppp = pqq.top();
				pqq.pop();
				q.push(ppp.second);
				while (!pqq.empty()) {
					if ((pqq.top()).first == ppp.first) {
						q.push((pqq.top()).second);
						pqq.pop();
					} else {
						break;
					}
				}
				if (i == 0) {
					cout << q.top();
					q.pop();
					counter++;
				} else {
					cout << ' ' << q.top();
					q.pop();
					counter++;
				}
				while (!q.empty() && counter < 5) {
					cout << ' ' << q.top();
					q.pop();
					counter++;
				}
			}
			cout << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1264
#!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin, maxint


def main():
    num = int(stdin.readline())

    L = []
    for _ in xrange(num):
        L.append([int(s) for s in stdin.readline().split()])

    weight = [maxint] * num
    weight[0] = 0
    V = set(xrange(1, num))
    index = 0

    while V:
        Li = L[index]
        for i in xrange(Li[1]):
            v = Li[i*2+2]
            if v not in V:
                continue
            c = Li[i*2+3]
            weight[v] = min(weight[v], c + weight[index])

        index = min(V, key=lambda i: weight[i])
        V.remove(index)

    for i, d in enumerate(weight):
        print(i, d)


main()

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

using namespace std;

int main(){
  int k;
  int a;
  int b;
  bool flag=false;
  cin >> k >> a >> b;
  for(int i=a;i<=b;i++){
    if(i%k==0){
      flag=true;
      break;
    }
  }
  if(flag){
    cout << "OK" << endl;
  }
  else{
    cout << "NG" << endl;
  }
  return 0;
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,s=0,t=0;cin>>n;
  vector<int> w(n);
  for(int i=0;i<n;i++){
    cin>>w.at(i);
    s+=w.at(i);
  }
  s/=2;
  for(int i=1;i<n-1;i+=2)t+=w.at(i);
  int x=s-t;
  cout<<x*2;
  for(int j=0;j<n-1;j++){
    x=w.at(j)-x;
    cout<<" "<<x*2;
  }
  cout<<endl;
}


Measured memory_bytes: 1664
N = input()
N = int(N)
A = input().split()

minA = min(A)
minA = int(minA)
M = 10 ** 18

Y = 0
if minA != 0:
    Y = 1
    for i in range(N):
        X = A[i]
        X = int(X)
        Y = Y * X
        if Y > M:
            break


if Y > M:
    print(-1)
else:
    print(Y)

Measured memory_bytes: 19508
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;
const ll mod = 1e9+7;
const ll inf = 1e18;

//前から順番に和を求め，mod mが同じならペアにできる
//0は単独でペアにできる
//AC

int main(void){
	ll n,a[100010],ans=0,c=1;
	cin>>n;
	rep(i,n)cin>>a[i];
	rep(i,n){
		if(i==0){
			ans+=a[0]-1;
			c=2;
		}else{
			if(a[i]==c){
				c++;
				continue;
			}else if(a[i]<c){
				continue;
			}else{
				if(a[i]%c==0){
					a[i]-=c+1;
					ans++;
				}
				ans+=a[i]/c;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

int main(){
    int d;
    cin >> d;
    if(d==25){
        cout << "Christmas" << endl;
    }
    if(d==24){
        cout << "Christmas Eve" << endl;
    }
    if(d==23){
        cout << "Christmas Eve Eve" << endl;
    }
    if(d==22){
        cout << "Christmas Eve Eve Eve" << endl;
    }
    

    return 0;
}

Measured memory_bytes: 3556
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const int64_t LINF=8931145141919364364,LMOD=998244353;
// const int dy[]={0,-1,0,1,1,-1,-1,1};
// const int dx[]={1,0,-1,0,1,1,-1,-1};

int main() {
	int r; cin>>r;
	cout<<3*r*r<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
string a="YNEOS";
int main(){
    int A,B,C;cin>>A>>B>>C;
    int i=1-(C-B==B-A);
    while(i<5){
        cout<<a.at(i);
        i+=2;
    }
    cout<<endl;
}

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

ll gcd(ll x, ll y){
    if(y==0){
        return x;
    }else{
        return gcd(y,x%y);
    }
}

int main(){
    ll a,b,ans=1;
    cin >> a >> b;
    b = gcd(a,b);
    bool bl = true;
    for(ll i=2;i*i<b;i++){
        while(b%i==0){
            if(bl==true){
                ans++;
                bl=false;
            }
            b=b/i;
        }
        bl=true;
    }
    if(b!=1) ans ++;
    
    cout << ans << endl;
}





Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>

using namespace std;

const int NUMBER = 100000;

typedef struct resu
{
    int p;
    char kekka[2];
} RES;

RES inf[NUMBER];

bool s[NUMBER] = {0};

int main()
{
    int n,m;
    int a[NUMBER] = {0};
    int w[NUMBER] = {0};
    cin >> n >> m;
    int M = 0 ;
    for (int i = 0;i < m;i++){
        cin >> inf[i].p >> inf[i].kekka;
        if (s[inf[i].p] == false){
            if (inf[i].kekka[0] == 'A'){
                s[inf[i].p] = true;
                a[inf[i].p]++;
            }
            if (inf[i].kekka[0] == 'W'){
                w[inf[i].p]++;
            }
        }
        if (M < inf[i].p){
            M = inf[i].p;
        }
    }
    for (int i = 0;i < m;i++){
        if (s[inf[i].p] == false){
            w[inf[i].p] = 0;
        }
    }
    int ans[2] = {0};
    for (int i = 1;i <= M;i++){
        ans[0] += a[i];
        ans[1] += w[i];
    }
    
    
    cout << ans[0] << " " << ans[1] << endl;
}


Measured memory_bytes: 1920
#include <bits/stdc++.h>
#define REP(i,n) for(ll i=0;i<(n);++i);
#define FOR(i,m,n) for(int i=(m);i<(n);i++);
#define VSORT(v) sort(v.begin(),v.end());
#define YES cout<<"Yes"<<endl;
#define NO cout<<"No"<<endl;
using namespace std;
typedef long long ll;
const double PI=acos(-1);
typedef pair<int,int>P;
const int mod =1e9+7;
const int di[]={-1,0,1,0},dj[]={0,-1,0,1};
const int INF = 99999999;
const ll LINF = 9999999999999;
const int MAXN=510000;

struct mint {
  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;}


//k<=1e5
mint COM(long long N, long long K) {
    mint res = 1;
    for (long long n = 0; n < K; ++n) {
        res *= (N - n);
        res /= (n + 1);
    }
    return res;
}

ll fac[MAXN],finv[MAXN],inv[MAXN];

void COMint()
{
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<MAXN;i++)
    {
        fac[i]=fac[i-1]*i%mod;
        inv[i]=mod-inv[mod%i]*(mod/i)%mod;
        finv[i]=finv[i-1]*inv[i]%mod;
    }
}

ll COM(int n,int k)
{
    if(n<k)return 0;
    if(n<0 || k<0) return 0;
    return fac[n]*(finv[k]*finv[n-k]%mod)%mod;
}

int main()
{
    int n;
    cin>>n;
    if(n==1)
    {
        cout<<0;
        return 0;
    }
    mint all=1;
    for(int i=0;i<n;i++)
    {
        all*=10;
    }

    mint dust=1;
    for(int i=0;i<n;i++)
    {
        dust*=8;
    }

    mint onenashi=1;
    for(int i=0;i<n;i++)
    {
        onenashi*=9;
    }

    mint hiki=onenashi+onenashi-dust;
    
    all-=hiki;
    cout<<all.x;


}


Measured memory_bytes: 3632
#include<iostream>
#include<iomanip>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<map>
#include<cmath>
#include<string>

#define rep(i,p) for(int i=0;i<p;i++)
#define ll long long

using namespace std;

int main(){

ll int A ,B;
cin >> A >> B;

if(A<10 && B<10){
	cout << A*B;

}
else{
	cout << "-1";
}











	return 0;

}



Measured memory_bytes: 256
package main

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

const (
	initialBufSize = 10000
	maxBufSize     = 1000000
	mod            = 1e9 + 7
)

var (
	sc *bufio.Scanner = func() *bufio.Scanner {
		sc := bufio.NewScanner(os.Stdin)
		buf := make([]byte, initialBufSize)
		sc.Buffer(buf, maxBufSize)
		sc.Split(bufio.ScanWords)
		return sc
	}()
)

func main() {
	N := getInt()
	x := make([]int, N)
	y := make([]int, N)

	for i := 0; i < N; i++ {
		x[i] = getInt()
		y[i] = getInt()
	}

	totalDistance := 0.0
	for i := 0; i < N; i++ {
		for j := i+1; j < N; j++ {
			totalDistance += math.Sqrt(float64(pow(x[i] - x[j], 2) + pow(y[i] - y[j], 2)))
		}
	}

	fmt.Println(totalDistance * 2.0 / float64(N))
}

type Graph struct {
	n     int
	edges [][]int
}

func NewGraph(n int) *Graph {
	g := &Graph{
		n:     n,
		edges: make([][]int, n),
	}
	return g
}

func (g *Graph) AddEdge(u, v int) {
	g.edges[v] = append(g.edges[v], u)
	g.edges[u] = append(g.edges[u], v)
}

func dfs(c int, edges [][]int, visited map[int]struct{}) {
	visited[c] = struct{}{}

	for _, v := range edges[c] {
		_, flag := visited[v]
		if flag {
			continue
		}
		dfs(v, edges, visited)
	}
}

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

func abs(a int) int {
	return int(math.Abs(float64(a)))
}

func pow(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

func powMod(n, p int) int {
	if p == 0 {
		return 1
	} else if p%2 == 0 {
		t := powMod(n, p/2)
		return calcMod(t * t)
	} else {
		return calcMod(n * powMod(n, p-1))
	}
}

func min(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}

func max(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Max(float64(res), float64(nums[i])))
	}
	return res
}

func strSearch(a []string, b string) bool {
	for i := 0; i < len(a); i++ {
		if a[i] == b {
			return true
		}
	}
	return false
}

func printIntArray(array []int) {
	strArray := fmt.Sprint(array)
	fmt.Println(strArray[1 : len(strArray)-1])
}

func calcMod(x int) int {
	return x % mod
}

func reverse(s string) string {
	runes := []rune(s)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}

func isPrime(n int) bool {
	if n < 2 {
		return false
	} else if n == 2 {
		return true
	} else if n % 2 == 0 {
		return false
	}

	sqrtN := int(math.Sqrt(float64(n)))
	for i := 3; i <= sqrtN; i += 2 {
		if n % i == 0 {
			return false
		}
	}

	return true
}


Measured memory_bytes: 640
main = do
  str <- getLine
  let n = read str ::Int
  str <- getLine
  let a = take n $ map read (words str) ::[Int]
  let ret = and $ map ck $ filter even a
  if ret == True
    then putStrLn "APPROVED"
    else putStrLn "DENIED"


ck :: Int -> Bool
ck n
  | n `mod` 3 == 0 = True
  | n `mod` 5 == 0 = True
  | otherwise      = False

Measured memory_bytes: 1020
// In The Name Of God
#include <bits/stdc++.h>

#define sqr(A) ((A) * (A))
#define F first
#define S second
#define mp make_pair
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;
const int MOD2 = 1e9 + 9;
const int HP = 727;
const int INF = INT_MAX;
const ll LINF = LLONG_MAX;

const int N = 1e5 + 20;
vector<int> G[N];
int a[N], f[N], n, com[N], m, cnt, ans;
bool visited[N];

void dfs(int v, int c) {
	visited[v] = 1;
	com[v] = c;
	for (int u : G[v])
		if (!visited[u])
			dfs(u, cnt);
}

int main() {
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n >> m;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		f[a[i]] = i;
	}
	for (int i = 0, v, u; i < m; i++) {
		cin >> v >> u;
		G[v].push_back(u);
		G[u].push_back(v);
	}
	for (int i = 1; i <= n; i++)
		if (!visited[i])
			dfs(i, ++cnt);
	for (int i = 1; i <= n; i++)
		if (com[i] == com[f[i]])
			ans++;
	cout << ans << endl;
}

Measured memory_bytes: 9088
#include <iostream>
#include <map>
#include <vector>
#include <cstring>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <string>
#include <stack>
#include <set>
#include <deque>
#define mp make_pair
using namespace std;
int a,b,c,d,e,f,s[3005],w[3005];
int main(){
	cin>>a>>b>>c>>d>>e>>f;
	w[0]=1;
	for (int i=1;i<=f;i++){
		if (i-a*100>=0 && w[i-a*100]) w[i]=true;
		if (i-b*100>=0 && w[i-b*100]) w[i]=true;
	}
	s[0]=1;
	for (int i=1;i<=f;i++){
		if (i-c>=0 && s[i-c]) s[i]=true;
		if (i-d>=0 && s[i-d]) s[i]=true;
	}
	int maxv=0,maxs=0;
	double maxm=0;
	for (int i=1;i<=f;i++){
		if (w[i]){
			for (int j=0;j<=f;j++){
				if (s[j]){
					if (i+j<=f){
						if (double(double(j)/double((i+j)))>=maxm && double(double(j)/double((i+j)))<=double(double(e)/double(e+100))){
							maxs=j;
							maxm=double(double(j)/double((i+j)));
							maxv=i+j;
						}
					}
				}
			}
		}
	}
	cout<<maxv<<' '<<maxs;
	return 0;
}

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

using namespace std;
using Graph = vector<vector<int>>;
using Grid= vector<vector<char>>;
using vin= vector<int>;
using ll=long long;
using vll= vector<ll>;
using vbl=vector<bool>;
using vch=vector<char>;
using pnn=pair<int ,int>;

#define ft first
#define sd second
#define fn front
#define pb push_back
#define it insert
#define si(v) int((v).size())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rell(i,n) for (ll i=0; i< (ll)(n); i++)
#define sot(x) sort(x.begin(), x.end())
#define rese(x) reverse(x.begin(), x.end())
#define vnn(x,y,s,name) vector<vector<int>> name(x, vector<int>(y,s))
#define mse(x) memset(x, 0, sizeof(x))
#define mii(x,y,z) min(x,min(y,z))
#define maa(x,y,z) max(x,max(y,z))

string yes="Yes",no="No";

int main() {
   int n;
   cin>>n;
   bool ok1=false;
   bool ok2=false;
   bool ok3=false;
   bool ans=false;
   rep(i,n){
       int d1,d2;
       cin>>d1>>d2;
       if(d1!=d2){
          ok1=false;
        ok2=false;
     ok3=false;
           continue;
       }
       
       if(ok2) ok3=true;
       if(ok1) ok2=true;
       ok1=true;
       if(ok3) ans=true;
   }
   if(ans) cout<<yes<<endl;
   else cout<<no<<endl;

    
}   
   



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

using namespace std;

int main()
{
    int a[210]={0};
    for(int i=105;i<=200;i++){
        if(i%2==0){
            a[i]=a[i-1];
            continue;
        }
        int s=2;
        for(int j=2;j<i;j++){
            if(i%j==0) s++;
        }
        if(s==8){
            a[i]=a[i-1]+1;
        }
        else a[i]=a[i-1];
    }
    int n;
    while(scanf("%d",&n)!=EOF){
        if(n<105) {
            printf("0\n");
            continue;
        }
        printf("%d\n",a[n]);
    }
    return 0;
}


Measured memory_bytes: 256
import java.io.*;

import java.util.*;
import java.math.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
import static java.math.BigInteger.*;
import static java.lang.Character.*;

class AOJ1027 {
	public void run() {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()) {
			int K = sc.nextInt();
			if(K == 0)
				return;
			int sum = 0;
			int N = K * (K - 1) / 2;
			for(int i = 0; i < N; i++)
				sum += sc.nextInt();
			System.out.println(sum / (K - 1));
		}
	}
}

public class Main {
	public static void main(String... args) {
		new AOJ1027().run();
	}

	public static void debug(Object... os) {
		System.err.println(java.util.Arrays.deepToString(os));
	}
}

class Scanner {
	final java.util.Scanner sc;

	public double nextDouble() {
		return Double.parseDouble(sc.next());
	}

	public Scanner(java.io.InputStream is) {
		this.sc = new java.util.Scanner(is);
	}

	public boolean hasNext() {
		return sc.hasNext();
	}

	public String next() {
		return sc.next();
	}

	public int nextInt() {
		return Integer.parseInt(sc.next());
	}

	public String nextLine() {
		return sc.nextLine();
	}

	public long nextLong() {
		return Long.parseLong(sc.next());
	}
}

Measured memory_bytes: 12000
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

int pnt = 3;

vector<tuple<int, int, int, int>> out;

int op(int type, int i, int j) {
	out.push_back(make_tuple(type, i, j, pnt));
	pnt++;
	return pnt - 1;
}

int ONE = -1;
vector<int> PWS;

vector<int> make_bits(int POS) {
	int plus_one = op(0, POS, ONE);
	vector<int> bits(32);
	int cur = op(0, pnt, pnt);
	for (int i = 31; i >= 0; i--) {
		int cur_add = op(0, cur, PWS[i]);
		int cur_less = op(1, cur_add, plus_one);
		bits[i] = cur_less;
		for (int j = 0; j < i; j++) {
			cur_less = op(0, cur_less, cur_less);
		}
		cur = op(0, cur, cur_less);
	}
	return bits;
}

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

	int some_bigger = op(0, 0, 1);
	some_bigger = op(0, some_bigger, some_bigger);
	ONE = op(1, 0, some_bigger);
	PWS = {ONE};
	for (int i = 1; i < 32; i++) {
		PWS.push_back(op(0, PWS.back(), PWS.back()));
	}
	vector<int> bits_a = make_bits(0);
	vector<int> bits_b = make_bits(1);
	int C = op(0, pnt, pnt);
	for (int i = 0; i < 32; i++) {
		for (int j = 0; j < 32; j++) {
			int sm = op(0, bits_a[i], bits_b[j]);
			int ok = op(1, ONE, sm);
			for (int f = 0; f < i + j; f++) {
				ok = op(0, ok, ok);
			}
			C = op(0, C, ok);
		}
	}
	out.push_back(make_tuple(0, 2, C, 2));
	cout << out.size() << endl;
	for (auto x : out) {
		if (!get<0>(x)) {
			cout << "+ ";
		} else {
			cout << "< ";
		}
		cout << get<1>(x) << ' ' << get<2>(x) << ' ' << get<3>(x) << '\n';
	}
}

Measured memory_bytes: 3628
import java.util.Scanner;

public class Main{
	static final int[] p = {0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2};
	static final int[] q = {0, 0, 0, 1, 1, 1, 2, 2, 2, 0, 0, 0, 1, 1, 1, 2, 2, 2, 0, 0, 0, 1, 1, 1, 2, 2, 2};
	static final int[] r = {0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2};

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

		while(true){
			String str = sc.next();
			if(str.equals(".")) break;

			int cnt = 0;
			for(int i=0; i<27; i++){
				String tmp = str;
				tmp = tmp.replace('P', (char)('0'+p[i]));
				tmp = tmp.replace('Q', (char)('0'+q[i]));
				tmp = tmp.replace('R', (char)('0'+r[i]));
				int tf;
				if(tmp.charAt(0)=='('){
					tf = formula(tmp.substring(1, tmp.length()-1));
				}else{
					tf = formula(tmp);
				}
				if(tf==2) cnt++;
			}

			System.out.println(cnt);
		}
	}

	static public int formula(String str){
		if(str.length()==1) return str.charAt(0) - '0';
		int left, right;
		int i = 0, flag = 0;

		int j = 0;
		while(str.charAt(j)=='-') j++;

		while(true){
			if(str.charAt(i)=='('){
				flag++;
			}else if(str.charAt(i)==')'){
				flag--;
			}else if(flag==0 && (str.charAt(i)=='+' || str.charAt(i)=='*')){
				break;
			}
			if(++i==str.length()) break;
		}

		if(i==str.length()){
			if(j%2==0){
				if(str.charAt(j)=='('){
					return formula(str.substring(j+1, i-1));
				}else{
					return formula(str.substring(j, i));
				}
			}else{
				if(str.charAt(j)=='('){
					return 2 - formula(str.substring(j+1, i-1));
				}else{
					return 2 - formula(str.substring(j, i));
				}
			}
		}else{
			if(str.charAt(i-1)==')'){
				left = formula(str.substring(j+1, i-1));
			}else{
				left = formula(str.substring(j, i));
			}
			if(j%2==1) left = 2- left;

			if(str.charAt(i+1)=='('){
				right = formula(str.substring(i+2, str.length()-1));
			}else{
				right = formula(str.substring(i+1, str.length()));
			}

			if(str.charAt(i)=='+'){
				if(left==2||right==2){
					return 2;
				}else if(left==1||right==1){
					return 1;
				}else{
					return 0;
				}
			}else{
				if(left==0||right==0){
					return 0;
				}else if(left==1||right==1){
					return 1;
				}else{
					return 2;
				}
			}
		}
	}
}

Measured memory_bytes: 34688
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#include <random>
#include <cassert>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 2e2 + 10;
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	string str;
	int n;
	map<string, int> ms;
	cin >> n >> str;
	ms[str] = 1;
	char c = str.back();
	while (--n)
	{
		cin >> str;
		if (ms.count(str) || c != str.front()) puts("No"), exit(0);
		ms[str] = 1;
		c = str.back();
	}
	puts("Yes");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <tuple>
#include <map>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>
#include <limits>
using namespace std;
void init();
#ifdef DEBUG_BUILD
#define DBG(expr) cout << #expr << " = " << expr << endl;
#endif
#define ECHO(expr) cout << expr << endl;
#define REP(var, num) for(ll var = 0; var < num; var++)
#define REP_FROM(var, from, num) for(ll var = from; var < num; var++)
#define MAX_OF(type) numeric_limits<type>::max()
#define MIN_OF(type) numeric_limits<type>::min()
#define SORT(vec) sort(vec.begin(), vec.end())
#define REVERSE(vec) reverse(vec.begin(), vec.end())
#define ALL(vec) vec.begin(), vec.end()
typedef signed long long ll;
typedef unsigned long long ull;

void solve() {
    ll n;
    cin >> n;
    ll ans = 0;
    ll base = 1;
    do {
        int i = (n % 10 == 1) ? 9 : 1;
        ans += i * base;
        base *= 10;
        n /= 10;
    } while (n > 0);
    ECHO(ans)
}

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

#ifdef INPUT_FILE
    if (!freopen(INPUT_FILE, "r", stdin)) {
        perror("freopen");
        exit(1);
    }
#endif

    solve();
    return 0;
}

Measured memory_bytes: 256
#include <bit>
#include <bitset>
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <iomanip>

typedef long double ld;
typedef long long ll;

using namespace std;


/* TEMPLATE ENDS HERE */

#define MAXN (1 << 20)

vector<int> a[MAXN];
int n;

int edgeid(int i, int j) {
	if (i > j) {
		swap(i, j);
	}
	return (i - 1) * n + j - 1;
}

void addedge(int p1, int p21, int p22) {
	int ffrom = edgeid(p1, p21);
	int tto = edgeid(p1, p22);	
	a[ffrom].push_back(tto);
}

bool ok;
int v[MAXN];
vector<int> top;

void dfs(int cur) {
	if (v[cur]) {
		return;
	}
	v[cur] = 1;
	for (auto& e: a[cur]) {
		if (v[e] == 1) {
			ok = false;
			return;
		}
		dfs(e);
	}
	v[cur] = 2;
	top.push_back(cur);
}

int mem[MAXN];

int solve(int cur) {
	int & ret = mem[cur];
	if (ret >= 0) {
		return ret;
	}
	ret = 0;
	for (auto& e : a[cur]) {
		int nnext = solve(e);
		ret = max(nnext, ret);
	}
	ret++;
	return ret;
}

int m;

int main() {
	cout << fixed << setprecision(12);	
	cin >> n;
	for (int i = 0; i < n; i++) {
		int cur, prev;
		for (int j = 0; j < n - 1; j++) {
			cin >> cur;		
			if (j) {
				addedge(i + 1, prev, cur);
			}
			prev = cur;
		}
	}
	ok = true;
	m = n * n;
	for (int i = 0; i < m; i++) {
		dfs(i);
	}
	if (!ok) {
		cout << "-1" << endl;
		return 0;
	}
	memset(mem, -1, sizeof(mem));
	reverse(top.begin(), top.end());
	int ret = 0;
	for (auto& e: top) {
		int cur = solve(e);
		ret = max(ret, cur);
	}
	cout << ret << endl;
	return 0;
}


ll MOD = ((ll)1e9 + 7);

struct mod {
	ll x;

	mod(ll tx = 0) {
		x = tx;
		x %= MOD;
	}
	
	mod& operator=(const ll & tx) {
		x = tx % MOD;
		return *this;
	}
	
	mod& operator=(const mod & m2) {
		x = m2.x;
		return *this;
	}

	mod operator+(const mod& m2) const {
		return mod((x + m2.x) % MOD);
	}

	mod& operator+=(const mod& m2) {
		x += m2.x;
		x %= MOD;
		return *this;
	}

	mod operator-(const mod & m2) const {
		return mod((x - m2.x + MOD) % MOD);
	}

	mod& operator-=(const mod & m2) {
		x -= m2.x;
		x = (x + MOD) % MOD;
		return *this;
	}

	mod operator*(const mod & m2) const {
		return mod((x * m2.x) % MOD);
	}

	mod& operator*=(const mod & m2) {
		x *= m2.x;
		x %= MOD;
		return *this;
	}

	mod mypow(ll k) const {
		mod ret = 1;
		mod cur = x;
		while (k) {
			if (k & 1) {
				ret *= cur;
			}
			cur *= cur;
			k >>= 1;
		}
		return ret;
	}

	mod inv() const {
		return mypow(MOD - 2);
	}

	mod operator/(const mod & m2) const {
		return (*this) * m2.inv();
	}

	mod& operator/=(const mod & m2) {
		x *= m2.inv().x;
		x %= MOD;
		return *this;
	}

	bool operator<(const mod & m2) const {
		return x < m2.x;
	}
};

ostream &operator<<(ostream & os, const mod & m) {
	return os << m.x;
}



Measured memory_bytes: 55456
N,K=map(int,input().split())
H=list(map(int,input().split()))



if N>K:
    dp=[1000000000]*N
    dp[0]=0
    for i in range(1,K):
        dp[i]=abs(H[i]-H[0])

    for i in range(K,N):
        for j in range(1,K+1):
            dp[i]=min(dp[i], dp[i-j]+abs(H[i-j]-H[i]))

    print(dp[N-1])

else:
    print(abs(H[N-1]-H[0]))

Measured memory_bytes: 84576
#include <bits/stdc++.h>
typedef long long ll;

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

vector<P> prime_factorize(ll n) {
	vector<P> res;

	for (ll p = 2; p * p <= n; ++p) {
		if (n % p != 0) continue;

		int num = 0;
		while (n % p == 0) {
			++num;
			n /= p;
		}
		res.push_back(P(p, num));
	}
	if (n != 1) res.push_back(P(n, 1));

	return res;
}

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

	map<int, int> mp;
	for (int i = 2; i <= N; ++i) {
		vector<P> tmp = prime_factorize(i);
		for (int j = 0; j < tmp.size(); ++j) {
			mp[tmp[j].first] += tmp[j].second;
		}
	}

	vector<P> v;
	for (auto it = mp.begin(); it != mp.end(); ++it) {
		int f = it->first;
		int s = it->second;
		v.push_back(P(f, s));
	}

	int res = 0;
	// 2, 4, 4
	for (int i = 0; i < v.size(); ++i) {
		int a = v[i].second;
		for (int j = 0; j < v.size(); ++j) {
			if (j == i) { continue; }
			int b = v[j].second;
			for (int k = j + 1; k < v.size(); ++k) {
				if (k == i) { continue; }
				int c = v[k].second;

				if ((a >= 2) && (b >= 4) && (c >= 4)) {
					++res;
				}
			}
		}
	}
	// 4, 14
	for (int i = 0; i < v.size(); ++i) {
		int a = v[i].second;
		for (int j = 0; j < v.size(); ++j) {
			if (j == i) { continue; }
			int b = v[j].second;

			if ((a >= 4) && (b >= 14)) { ++res; }
		}
	}
	// 2, 24
	for (int i = 0; i < v.size(); ++i) {
		int a = v[i].second;
		for (int j = 0; j < v.size(); ++j) {
			if (j == i) { continue; }
			int b = v[j].second;

			if ((a >= 2) && (b >= 24)) { ++res; }
		}
	}
	// 74
	for (int i = 0; i < v.size(); ++i) {
		if (v[i].second >= 74) { ++res; }
	}

	cout << res << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <queue>
#include <vector>
#include <stack>
#include <cmath>
#include <memory.h>
#include <iomanip>
#include <cassert>
using namespace std;

#define maxn 200002
#define FOR(i, l, r) for (int i=l; i<=r; ++i)
#define FORD(i, r, l) for (int i=r; i>=l; --i)
#define REP(i, r) for (int i=0; i<(int)r; ++i)
#define REPD(i, r) for (int i=(int)r-1; i>=0; --i)
#define fi first
#define se second
#define mk make_pair
#define nil NULL
#define y0 y902
#define y1 y232
#define x0 x92
#define x1 x899
#define next asdfa
#define sz size
#define Debug(X) {cerr << #X << " = " << X << '\n';}
#define PR(A, n) {cerr << #A << " = "; FOR(i, 1, n) cerr << A[i] << ' '; cerr << '\n';}
#define PR0(A, n) {cerr << #A << " = "; REP(i, n) cerr << A[i] << ' '; cerr << '\n';}
typedef long long ll;
typedef double db;
typedef pair<db, db> dd;
typedef pair<int, int> ii;
typedef vector<int> vi;
const int inf = 1e9;
template<class T> int getbit(T x, int pos) {return (x>>(pos-1)) & 1;}
template<class T> void turn_on(T &x, int pos) {x = x | ((T)1<<(pos-1));}
template<class T> void turn_off(T &x, int pos) {x = x & ~((T)1<<(pos-1));}
template<class T> T sqr(T a) {return a*a;}

string s;
int ps[maxn][27];
ll f[maxn];

int main() {
    //freopen("revcomp.inp", "r", stdin);
    //freopen("", "w", stdout);
    ios::sync_with_stdio(0); cin.tie(0);
    cin >> s;
    int n = s.sz();
    s = '@' + s;
    f[1] = 1;
    FOR(i, 1, n) REP(j, 26) {
        ps[i][j] = ps[i-1][j] + (s[i]-'a'==j);
    }
    FOR(i, 2, n) {
        f[i] = f[i-1] + (i-ps[i][s[i]-'a']);
    }
    cout << f[n];
}



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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;
typedef tuple<ll, ll, ll, ll, ll> t5;

#define rep(a,n) for(ll a = 0;a < n;a++)
#define repi(a,b,n) for(ll a = b;a < n;a++)

using namespace std;

static const ll INF = 1e15;

template<typename T>
static inline void chmin(T & ref, const T  value) {
	if (ref > value) ref = value;
}

template<typename T>
static inline void chmax(T& ref, const T value) {
	if (ref < value) ref = value;
}

int main() {
	ll n, k;
	cin >> n >> k;
	vector<ll> vs(n);
	rep(i, n) cin >> vs[i];

	ll left = 0; 
	ll right = 2e9 + 1;

	while (right - left > 1) {
		ll middle = left + right;
		middle /= 2;
		ll vsum = 0;
		rep(j, n) {
			ll v = vs[j] / middle;
			if (vs[j] % middle != 0) {
				v++;
			}
			vsum += v - 1;
		}
		//cout <<		middle << "," << vsum << endl;
		if (vsum <= k) {
			right = middle;
		}
		else {
			left = middle;
		}
	}
	cout << right << endl;
	return 0;
}


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

using namespace std;

static const int INF = 1e9;
int d[11];
struct edge
{
	int from;
	int to;
	int cost;
};

void BellmanFord()
{
	int n;
	while (cin >> n, n)
	{
		vector<edge> E;
		for (int i = 0; i < n; ++i)
		{
			int from, to, cost;
			cin >> from >> to >> cost;
			edge e1, e2;
			e1.from = e2.to = from;
			e1.to = e2.from = to;
			e1.cost = e2.cost = cost;
			E.push_back(e1);
			E.push_back(e2);
		}
		int minPos = 0;
		int minSumCost = INF;
		for (int i = 0; i < 10; ++i)
		{			
			for (int j = 0; j < 10; ++j)
			{
				d[j] = INF;
			}
			d[i] = 0;
			bool update = true;
			while (update)
			{
				update = false;
				for (int j = 0; j < E.size(); ++j)
				{
					edge e = E[j];
					if (d[e.from] != INF && d[e.to] > d[e.from] + e.cost)
					{
						d[e.to] = d[e.from] + e.cost;
						update = true;
					}
				}
			}
			int sum = 0;
			for (int j = 0; j < 10; ++j)
			{
				if (d[j] != INF)
				{
					sum += d[j];
				}
			}
			if (sum == 0)
			{
				continue;
			}
			if (minSumCost > sum)
			{
				minSumCost = sum;
				minPos = i;
			}
		}
		cout << minPos << " " << minSumCost << endl;
	}
}

int dist[11][11];
void WarshallFloyd()
{
	int n;
	while (cin >> n, n)
	{
		for (int i = 0; i < 10; ++i)
		{
			for (int j = 0; j < 10; ++j)
			{
				dist[i][j] = INF;
			}
			dist[i][i] = 0;
		}
		for (int i = 0; i < n; ++i)
		{
			int from, to, cost;
			cin >> from >> to >> cost;
			dist[from][to] = cost;
			dist[to][from] = cost;
		}
		for (int k = 0; k < 10; ++k)
		{
			for (int i = 0; i < 10; ++i)
			{
				for (int j = 0; j < 10; ++j)
				{
					dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
				}
			}
		}
		int minSumCost = INF;
		int minPos = 0;
		for (int i = 0; i < 10; ++i)
		{
			int sum = 0;
			for (int j = 0; j < 10; ++j)
			{
				if (dist[i][j] != INF)
				{
					sum += dist[i][j];
				}
			}
			if (sum == 0)
			{
				continue;
			}
			if (minSumCost > sum)
			{
				minSumCost = sum;
				minPos = i;
			}
		}
		cout << minPos << " " << minSumCost << endl;
	}
}

int main()
{
	BellmanFord();
	//WarshallFloyd();
	return(0);
}

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

int main(){
  int N, D;
  cin >> N >> D;
  int count = 0;
  for( int i = 0; i < N; ++i ){
    int64_t x,y;
    cin >> x >> y;
    if( sqrt(x*x + y*y) <= D ){
      ++count;
    }
  }

  cout << count << endl;
}

Measured memory_bytes: 3680
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int d = sc.nextInt();
		
		int[] x = new int[n];
		int[] y = new int[n];
		for(int i=0; i < n;i++) {
			x[i] = sc.nextInt();
			y[i] = sc.nextInt();
		}
		
		int count=0;
		double dis = 0;
		
		for(int i=0; i < n; i++) {
			dis = Math.sqrt((long)x[i]*x[i] + (long)y[i]*y[i]);
			if(dis <= d) {
				count++;
			}
		}
		
		System.out.println(count);
		
	}

}


Measured memory_bytes: 61232
// #define _CRT_SECURE_NO_WARNINGS
// #define _USE_MATH_DEFINES	// M_PI=3.1415...
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <locale>
#include <cctype>
#include <sstream>
#include <iomanip>	// 20桁出力 cout << setprecision(20) << double;
#include <queue>
#include <bitset>	// bitset<8> bs1(131uL); // 10000011 bs1[0]は1 01stringからビット集合生成可
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<LL> VL;
typedef map<int, int> MAPII;
typedef multimap<int, char, greater<int> > MuMAPIC;
typedef vector<pair<int, int> > VPII;
typedef multimap<int, string, greater<int> > MuMIS;
typedef pair<int, int> P;
typedef pair<int, pair<P, P> > PP;

#define INF 999999999999999997;
#define MP make_pair
#define FAST_IO  cin.tie(0); ios::sync_with_stdio(false);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORL(i,a,b) for(LL i=(a);i<(b);i++)
#define FOR_REV(i,a,b) for(int i=(a);i>=(b);i--)
//for gcc (未test)
// #define FOREACH_IT(it,c) for(typeof(c)::iterator it=(c).begin(); it!=(c).end(); ++it)
//for Visual Studio
#define foreach_it(type,it,c) for(type::iterator it=c.begin(),c_end=c.end();it!=c_end;++it)
#define FOR_ITR(d) for(auto itr=d.begin(),d_end=d.end();itr!=d_end;++itr)	// C++11
// for Debug.
#define DUMP_VVI(b) FOR(i,0,b.size()){FOR(j,0,b[i].size())printf("%d ",b[i][j]);puts("");}
#define D_OUT(str,value) if(dbgF){cout<<str<<" : "<<value<<endl;}
// 入力をpush_back(d)やarray[d]に使う時に1行で書ける
// int INPUT_INT() {int d;cin>>d;return d;}
template<class T>T IN() { T d; cin >> d; return d; }
// 最大公約数（Greatest Common Divisor）
LL gcd(LL a, LL b) { return (b > 0) ? gcd(b, a%b) : a; }
// 最小公倍数（Least Common Multiple）
LL lcm(LL a, LL b) { return a / gcd(a, b) * b; }
// Y年はうるう年か否か
bool uruu(LL Y) { return (((Y % 4 == 0 && Y % 100 != 0) || Y % 400 == 0) ? true : false); }

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

// vector注意
// vec[i][j]の形に入力を入れるとき、vecは初期化してある必要がある.

// ------------------- include, typedef, define END. -------------------


int main() {
	FAST_IO;
	// for D_OUT(str, value)  ... cout<< str <<" : "<< value <<endl;
	bool dbgF = true;

	//コードはここから書く.
	LL N, A, B;
	cin >> N>>A >> B;
	cout << min(N*A, B) << endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
using namespace std;
struct S{int x1,x2,y1,y2,i;S(){}S(int x1,int x2,int y1,int y2):x1(x1),x2(x2),y1(y1),y2(y2),i(0){}}a[10];
int n;
void F(int s,int&c)
{
	int x=999,y=999,index=999,i;
	for(i=0;i<n;++i)
	{
		if(!(s&(1<<i)))continue;
		if(x>a[i].x1)
		{
			x=a[i].x1;
			y=a[i].y1;
			index=i;
		}
		else if(x==a[i].x1&&y>a[i].y1)
		{
			y=a[i].y1;
			index=i;
		}
	}
	a[index].i=++c;
	s^=(1<<index);
	y=a[index].y2;
	x=999;
	for(i=0;i<n;++i)
	{
		if(!(s&(1<<i)))continue;
		if(a[i].y1<y&&y<a[i].y2&&a[i].x1>=a[index].x2)
			x=min(x,a[i].x1);
	}
	int t=0;
	for(i=0;i<n;++i)
	{
		if( (s&(1<<i))&&x>=a[i].x2&&a[i].y2<=a[index].y2 )
			t|=(1<<i);
	}
	s^=t;
	if(t)F(t,c);
	if(s)F(s,c);
}
int main()
{
	int i,x1,x2,y1,y2,f=0;
	while(scanf("%d",&n),n)
	{
		for(i=0;i<n;++i)
		{
			scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
			if(x1>x2)swap(x1,x2);
			if(y1>y2)swap(y1,y2);
			a[i]=S(x1,x2,y1,y2);
		}
		int c=0;
		F((1<<n)-1,c);
		if(f++)puts("");
		for(i=0;i<n;++i)printf("%d\n",a[i].i);
	}
	return 0;
}

Measured memory_bytes: 0
n = int(input())
a = list(map(int, input().split()))

ruiseki = [0 for i in range(n+1)]
dic = {}
ans = 0
for i in range(n):
    ruiseki[i+1] = ruiseki[i] + a[i]
    moji = str(ruiseki[i+1])
    if moji == '0':
        if '0' in dic:
            dic['0'] += 1
            ans += dic['0']
        else:
            dic['0'] = 1
            ans += dic['0']
    else:
        if moji in dic:
            ans += dic[moji]
            dic[moji] += 1
        else:
            dic[moji] = 1

print(ans)

Measured memory_bytes: 51604
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
    string S;
    cin>>S;
    int a=S.size();
    rep(i,a){
        if(i%2==0){
            cout<<S[i];
        }
    }
    cout<<""<<endl;
}



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

using namespace std ;

int main()
{
    string c ;
    cin >> c ;
    if( c == "SUN" ) puts("7") ;
    if( c == "MON" ) puts("6") ;
    if( c == "TUE" ) puts("5") ;
    if( c == "WED" ) puts("4") ;
    if( c == "THU" ) puts("3") ;
    if( c == "FRI" ) puts("2") ;
    if( c == "SAT" ) puts("1") ;
    return 0 ;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <ctype.h>

int main(){
    char str[101];
    long i, j, len;
    long cnt = 0;
    while(1){
        if(scanf("%s",str) == EOF)break;
        len = strlen(str);
        i = 1;
        for(j = 0;j < len/2;j++){
            if(str[j] != str[len - 1 - j]){
                i = 0;
                break;
            }
        }
        cnt = cnt + i;
    }
    printf("%ld\n",cnt);
    return 0;
}

Measured memory_bytes: 540
def five_antennas(a: int, b: int, c: int, d: int, e: int, k: int)->bool:
    antennas = [a, b, c, d, e]
    for i in range(5):
        for j in range(i+1, 5):
            if k < antennas[j] - antennas[i]:
                return False
    return True


if __name__ == "__main__":
    inputs = [int(input()) for _ in range(6)]
    a, b, c, d, e, k = inputs
    yes = five_antennas(a, b, c, d, e, k)
    print('Yay!' if yes else ':(')


Measured memory_bytes: 3064