akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
public class Main{
    public static void main(String[] args){
	new Main().run();
    }

    Scanner kbd = new Scanner(System.in);

    void run(){
	int data = 0;
	while(kbd.hasNext()){	   
	    int n = kbd.nextInt(); // 支払い金額
	    if(n!=0) { 
		if(data>0)
		    System.out.println();
		solve(n);
		data++;
	    }
	}
    }

    void solve(int n){
	int[] first = new int[4]; // 最初の持ちコイン
	int[] last = new int[4];  // 支払い後の持ちコイン
	int sum = 0; // 最初の手持ち
	for(int i=0; i<4; i++){
	    first[i] = kbd.nextInt();
	    if(i==0)
		sum += first[i]*10;
	    else if(i==1)
		sum += first[i]*50;
	    else if(i==2)
		sum += first[i]*100;
	    else if(i==3)
		sum += first[i]*500;
	}
	int change = sum-n; // おつり
	//System.out.println(sum+" "+n+" "+change);

	while(change >= 500){
	    last[3]++;
	    change -= 500;
	}
	while(change >= 100){
	    last[2]++;
	    change -= 100;
	}
	while(change >= 50){
	    last[1]++;
	    change -= 50;
	}
	while(change >= 10){
	    last[0]++;
	    change -= 10;
	}
	
	int[] ans = new int[4]; // 実際に支払うコイン
	for(int i=0; i<4; i++){
	    //System.out.println(last[i]);
	    ans[i] = first[i]-last[i];
	}

	// 出力
	for(int i=0; i<4; i++){
	    if(ans[i]>0){
		if(i==0)
		    System.out.print("10 ");
		else if(i==1)
		    System.out.print("50 ");
		else if(i==2)
		    System.out.print("100 ");
		else if(i==3)
		    System.out.print("500 ");
		System.out.println(ans[i]);
	    }
	}
    }
}

Measured memory_bytes: 33992
W,H,N = list(map(int, input().split()))
p = [0] * 3
s = [0] * 2
e = [W, H]
for i in range(N):
    p = list(map(int, input().split()))
    if p[2] == 1 and p[0] > s[0]:
        s[0] = p[0]
    elif p[2] == 2 and p[0] < e[0]:
        e[0] = p[0]
    elif p[2] == 3 and p[1] > s[1]:
        s[1] = p[1]
    elif p[2] == 4 and p[1] < e[1]:
        e[1] = p[1]

if e[0] >= s[0] and e[1] >= s[1]:
    print((e[0] - s[0]) * (e[1] - s[1]))
else:
    print(0)

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

typedef long long ll;

int main(){
	int n;
	cin>>n;
	string s;
	cin>>s;
	int ans=0;
	for(int i=0;i<n-2;i++){
		if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C'){
			ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

int A, B;
#define S 100
bool R[S][S];

int main() {
  cin >> A >> B; --A; --B;
  for(int i = 0; i < S / 2; ++i) for(int j = 0; j < S; ++j) R[i][j] = true;
  int x = 0, y = 0;
  for(int i = 0; i < A; ++i) {
    R[x][y] = false;
    y += 2; if(y == S) { y = 0; x += 2; }
  }
  x = S / 2 + 1; y = 0;
  for(int i = 0; i < B; ++i) {
    R[x][y] = true;
    y += 2; if(y == S) { y = 0; x += 2; }
  }
  cout << S << " " << S << endl;
  for(int i = 0; i < S; ++i) {
    for(int j = 0; j < S; ++j) {
      cout << (R[i][j] ? '#' : '.');
    }
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
//for(int i = 0; i<n; i++)
 
 
int main()
{
    ll n,a,b;cin>>n>>a>>b;
    if (b < a){
        cout << 0 << endl;
    }else {
        ll ans = (n- 2)*(b-a)+1;
        cout<<(ans < 0 ? 0: ans) << endl;
          
    }
    return 0;
    
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
#include<cstdio>
#include<cstring>

using namespace std;

typedef long long ll;
typedef double db;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef string S;
typedef queue<int> qi;
typedef pair<ll,ll> P;
typedef vector<P> vp;
//#define sort(a) sort(a.begin(),a.end())
#define reverse(a) reverse(a.begin(),a.end())
#define pb push_back
#define elif else if
#define unique(a) a.erase(unique(a.begin(),a.end()),a.end())
#define mp make_pair
#define fr(i,n)for(ll i=0;i<(n);i++)
#define ifr(i,n)for(ll i=(n)-1;i>=0;i--)
#define ALL(a) (a).begin(),(a).end()
const int MOD = 1e9+7;
const ll INF =1e18;

int main(){
  ll n, x;cin>>n>>x;
  ll a[n];
  fr(i,n) cin>>a[i];
  ll ans = INF;
  ll b[n][n];
  fr(i,n)b[0][i] = a[i];
  fr(j,n){
    fr(i,n-1){
      b[i+1][j] = min(b[i][j],a[(j-i-1+n)%n]);
    }
  }
  fr(k,n){
    ll p = k*x;
    fr(i,n)p += b[k][i];
    ans = min(ans,p);
  }
  cout << ans << endl;
}

Measured memory_bytes: 31488
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using iii = pair<ii, int>;
#define vt vector
#define pq priority_queue
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define __lcm(a, b) a * b / __gcd(a, b)
// #define multicase
const int MOD = 1e9 + 7;
const int INF = 2e9;
// const int N = ;

int n;

void solve() {
    int T = 1;
  #ifdef multicase
    cin >> T;
  #endif
    while(T--) {
        cin >> n;
        for(int i = 1; i <= 9; i++) {
            if(n % i == 0) {
                if(n / i < 10) {
                    cout << "Yes\n";
                    return;
                }
            }
        }
        cout << "No\n";
    }
}

int main() {

    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    solve();
    
}

Measured memory_bytes: 3620
#include <stdio.h>

#define N 10000
#define Q 500

int main(){
  int S[N],T[Q];
  int n,m,i,j,count=0,flag=0;
  scanf("%d",&n);
  for(i=0; i<n ; i++){
    scanf("%d",&S[i]);
  }

  scanf("%d",&m);
  for(i=0; i<m ; i++){
    scanf("%d",&T[i]);
  }
  for(i=0; i<m ; i++){
    flag=0;
    for(j=0; j<n ; j++){
      if(flag!=0 && flag!=1)
	continue;
      if(S[j]==T[i]){
	count++;
	break;
      }
    }
  }
  if(count==0) printf("0\n");
  else printf("%d\n",count);
  return 0;
}

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

long long euclidean_gcd(long long a,long long b){
  long long temp;

  if (a<b) {
    temp = a;
    a = b;
    b = temp;
  }

  if (a % b == 0) return b;
  euclidean_gcd(b, a % b);
}

int main(){
  long long A,B,cnt;
  cnt = 0;
  cin >> A;
  cin >> B;

  long long gcd = euclidean_gcd(A,B);

  for (long long i = 2;i*i <= gcd;i++){
    if (gcd % i == 0) {
      cnt++;
    }
    while (gcd % i == 0) gcd /= i;
  }
  if (gcd > 1) cnt++;
  cout << cnt+1 << endl;
  return 0;
}


Measured memory_bytes: 256
from sys import stdin
from collections import deque
n = int(stdin.readline())
a = map(int, stdin.readline().split())
a.sort()
f = 1
q = deque(a)
t = 1
while 1:
    if len(q) == 1:
        f = (q[0] - t + 1) & 1 ^ 1
        break
    if t == q[0] == q[-1]:
        f = len(q) & 1 ^ 1
        break
    x = q.pop()
    if len(q) == 1 and (q[0] - t + 1) & 1:
        f = 1
        break
    if t == q[0] == q[-1] and len(q) & 1:
        f = 1
        break
    q.append(x)
    while q and q[0] == t:
        q.popleft()
    t += 1
    if len(q) == 1 and (q[0] - t + 1) & 1:
        f = 1
        break
    if t == q[0] == q[-1] and len(q) & 1:
        f = 1
        break
    q.pop()
    if not q:
        f = 0
        break
print "First" if f else "Second"


Measured memory_bytes: 11524
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cmath>
#include <numeric>
#include <iomanip>
#include <stack>
#include <complex>
#include <functional>
#include <tuple>

using namespace std;

#define Rep(i,a,b) for(ll i = a; i < b; ++i)
#define rep(i,b) Rep(i,0,b)
#define allof(a) (a).begin(), (a).end()

#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE")

using ll = long long;

constexpr int inf = 1e9 + 7;
constexpr ll infll = 1ll << 60ll;
constexpr ll mod = 1e9 + 7;
// 0~3までは右下左上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, 1, 0, -1, -1, 1, 1, -1 };

namespace {
    template<typename T> bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
    template<typename T> bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

    void Cout(long long x, const char* end = "\n") { std::cout << x << end; }
    template <typename T> void Cout(const T& x, const char* end = "\n") { std::cout << x << end; }
    template <typename T> void Cout(const std::vector<T>& x, const char* sep = " ", const char* end = "\n") { for (std::size_t i = 0, sz = x.size(); i < sz; ++i) { std::cout << x[i] << (i == sz - 1 ? end : sep); } }

    // 標準入出力
    struct inp {
        std::size_t szi, szj;
        inp(std::size_t _szi = 1, std::size_t _szj = 1) : szi(_szi), szj(_szj) {}
        template <typename T> operator T () const { T a; std::cin >> a; return a; }
        template <typename T> operator std::vector<T>() const { std::vector<T> a(szi); for (std::size_t i = 0; i < szi; ++i) std::cin >> a[i]; return a; }
        template <typename T> operator std::vector<std::vector<T>>() const {
            std::vector<std::vector<T>> a(szi, std::vector<T>(szj));
            for (std::size_t i = 0; i < szi; ++i) for (std::size_t j = 0; j < szj; ++j) cin >> a[i][j]; return a;
        }
    };
    inp inp1;
}

int main() {

    int A, B, m;
    cin >> A >> B >> m;
    vector<int> a = inp(A);
    vector<int> b = inp(B);
    vector<int> x(m), y(m), c(m);
    rep(i, m) cin >> x[i] >> y[i] >> c[i];

    int ans = inf;

    rep(i, m) {
        chmin(ans, a[x[i] - 1] + b[y[i] - 1] - c[i]);
    }

    chmin(ans, *min_element(allof(a)) + *min_element(allof(b)));

    Cout(ans);

    return 0;
}


Measured memory_bytes: 2176
#include<stdio.h>
int main(void){
    int W,H,x,y,r;
    scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
    if(x+r<=W&&y+r<=H&&x-r>=0&&y-r>=0){
        printf("Yes\n");
    }
    else printf("No\n");

    return 0;
}

Measured memory_bytes: 584
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
 
int main() {
	
	vector<int> a(3);
	
	cin >> a[0] >> a[1] >> a[2];

	sort(a.begin(),a.end());
	
	string ans="NO";
		
	
	if(a[0]==5 && a[1]==5 && a[2]==7){
		ans="YES";
	}
  
    cout << ans << endl;
    
    return 0;

}

Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        String s = input.next();
        int w = input.nextInt();
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < s.length(); i++){
            if (i%w == 0){
                sb.append(s.charAt(i));
            }
        }
        String ans = sb.toString();
        System.out.println(ans);
    }
}

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

using namespace std;
template<typename T> void in(T &x) { x = 0; bool neg = false; register T c = getchar(); if (c == '-')neg = true, c = getchar(); while ((c < 48) || (c > 57))c = getchar(); for (; c < 48 || c > 57; c = getchar()); for (; c > 47 && c < 58; c = getchar())x = (x << 3) + (x << 1) + (c & 15); if (neg) x *= -1; }
template<typename T> void out(T n) { bool neg = 0; if (n < 0)n *= -1, neg = 1; char snum[65]; int i = 0; do { snum[i++] = n % 10 + '0'; n /= 10; } while (n); --i; if (neg)putchar('-'); while (i >= 0)putchar(snum[i--]); }
template<typename T> void outln(T n) { bool neg = 0; if (n < 0)n *= -1, neg = 1; char snum[65]; int i = 0; do { snum[i++] = n % 10 + '0'; n /= 10; } while (n); --i; if (neg)putchar('-'); while (i >= 0)putchar(snum[i--]); putchar('\n'); }
#define len(_x) (sizeof((_x)) / sizeof(_x)[0])
#define ll long long
#define itr(_c) for(auto i=_c.begin();i!=_c.end();i++)
#define itrr(_c)for(auto i=_c.begin();i!=_c.end();i++)
#define f1(_x)for (int i = 0; i < _x; ++i)
#define fr(_x)for (int i = _x; i >0; i--)
#define f2(_x,_y)for (int i = _x; i < _y; ++i)
#define fileIO 	freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
typedef pair<int, int>pii; typedef pair<long, long>pll; typedef pair<string, int>psi;
typedef vector<int> vi; typedef vector<string> vs; typedef vector<bool> vb; typedef vector<long long>vll; typedef vector<pair<int,int> > vii;
typedef set<int> si; typedef set<string> ss; typedef set<bool> sb; typedef set<long long>sll; typedef set<pair<int, int> > sii;
typedef list<int> li; typedef list<string> ls; typedef list<bool> lb; typedef list<long long>lll; typedef list<pair<int, int> > lii;
typedef map<string, int> msi;
void fastIO(){ ios_base::sync_with_stdio(false); cin.tie(0); }

int main() {
	fastIO();
	vector<pii>v;
	ll a1, a2, a3, a4, s;
	ll sum;
	std::cin >> a1 >> a2 >> a3 >> a4 >> s;
	v.push_back(make_pair(a1 ,1));
	v.push_back(make_pair(a2 ,2));
	v.push_back(make_pair(a3 ,4));
	v.push_back(make_pair(a4,8));
	sort(v.begin(), v.end(), [](pii x1, pii x2) {return (float)x1.first/x1.second < (float)x2.first/ x2.second; });


	s *= 4;
	sum = s / v[0].second *v[0].first;
	ll rst = s - s/ v[0].second *v[0].second;
	
	if(rst>0)
	{	
		sum+= rst / v[1].second *v[1].first;
	    rst = s - s / v[1].second *v[1].second;
		if (rst > 0)
		{
			sum += rst / v[2].second *v[2].first;
			rst = s - s / v[2].second *v[2].second;
			if (rst>0)
			{
				sum += rst / v[3].second *v[3].first;
				std::cout << sum;
			}
			else std::cout << sum;
		}
		else std::cout << sum;
	}
	else std::cout <<sum;



	




}


Measured memory_bytes: 256
#Bitter Alchemy

#入力
N, X = map(int, input().split())
m = []
for i in range(N):
	m.append(int(input()))

#計算
remain = X - sum(m)
x = 0
count = 0
while(1):
	if x > remain:
		break
	count += 1
	x = count*min(m)

#出力
print(N + count-1)


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

#define i64 int64_t
#define ff(ii,nn,mm) for(int ii=nn;ii<mm;ii++)
#define ffrvs(ii,nn,mm) for(int ii=nn;ii>=mm;ii--)
#define srt(vvv) sort(vvv.begin(),vvv.end())
#define srtrvs(vvv) reverse(vvv.begin(),vvv.end())
#define Graph vector<vector<int>>
i64 inf = 1000000007;
i64 giant = 4000000000000000037;

using namespace std;

//メモリ置き場
int n, k, s;

//inputします
void input() {
    cin >> n >> k >> s;
}

//ライブラリ置き場



//main
int main() {
    input();
    if (k == 0) {
        if (s == 1000000000)s -= 2;
        cout << s + 1;
        ff(i, 1, n) {
            cout << " " << s + 1;
        }
        cout << endl;
        return 0;
    }
    cout << s;
    ff(i, 1, k) {
        cout << " " << s;
    }
    if (s == 1000000000)s -= 2;
    ff(i, k, n) {
        cout << " " << s + 1;
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 1280
n=int(input())
s=[int(input()) for _ in range(n)]

goukei=sum(s)
if goukei%10!=0: print(goukei)
else:
    lis=[s[i] for i in range(len(s)) if s[i]%10!=0]
    lis.sort()
    print(goukei-lis[0] if len(lis)>0 else 0)

Measured memory_bytes: 38384
#include <cstdio>
void calc(int x1, int y1, int a, int x2, int y2, int b)
{
	double d1 = x2;
	double d2 = x1;
	double xx1 = d1 * x1;
	double xy1 = d1 * y1;
	double a1 = d1 * a;
	double xx2 = d2 * x2;
	double xy2 = d2 * y2;
	double b1 = d2 * b;
	double y = xy1 - xy2;
	double c = a1 - b1;
	y = c / y;


	d1 = y2;
	d2 = y1;
	xx1 = d1 * x1;
	xy1 = d1 * y1;
	a1 = d1 * a;
	xx2 = d2 * x2;
	xy2 = d2 * y2;
	b1 = d2 * b;
	double x = xx1 - xx2;
	c = a1 - b1;
	x = c / x;
	if (x == 0)
	{
		x = 0;
	}
	if (y == 0)
	{
		y = 0;
	}
	printf("%.3lf %.3lf\n", x, y);
}
int main(int argc, char const *argv[])
{
	int x1, y1, a, x2, y2, b;

	while(scanf("%d %d %d %d %d %d", &x1, &y1, &a, &x2, &y2, &b) != EOF)
	{
		calc(x1, y1, a, x2, y2, b);
	}

		
	return 0;
}


Measured memory_bytes: 2576
#include <stdio.h>

using namespace std;

int main(){
	int n,m,l;
	scanf("%d %d %d",&n,&m,&l);
	int A[n][m],B[m][l];
	long long int C[n][l];
	for(int i = 0; i < n; i++){
		for(int j = 0; j < l; j++){
			C[i][j] = 0;
		}
	}

	for(int i = 0; i < n; i++){
		for(int j = 0; j < m; j++){
			scanf("%d",&A[i][j]);
		}
	}
	for(int i = 0; i < m; i++){
		for(int j = 0; j < l; j++){
			scanf("%d",&B[i][j]);
		}
	}

	for(int i = 0; i < n; i++){
		for(int k = 0; k < l; k++){
			for(int j = 0; j < m; j++){
				C[i][k] += A[i][j]*B[j][k];
			}
		}
	}

	for(int i = 0; i < n; i++){
		for(int j = 0; j < l-1; j++){
			printf("%lld ",C[i][j]);
		}
		printf("%lld\n",C[i][l-1]);
	}
}



Measured memory_bytes: 2908
n,m=map(int,input().split())
a=[[]for j in range(n)]
for i in range(n):
 a[i]=list(map(int,input().split()))

b=[[]for i in range(m)]

for i in range(m):
 b[i]=int(input())

for i in range(n):
 c = 0
 for j in range(m):
  c += a[i][j]*b[j]
 print(c)


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

signed main() {
	int n, k;
	string s;
	cin >> n >> k >> s;
	vector<pair<char, int>> v;
	rep(i, s.size()) {
		if(v.empty() || v.back().first != s[i]) {
			v.push_back(make_pair(s[i], 1));
		}
		else {
			v.back().second++;
		}
	}
	int ans = 0;
	int now = 0;
	int nk = 0;
	int ta = 0;
	rep(i, v.size()) {
		now += v[i].second;
		if(v[i].first == '0') {
			nk++;
			if(nk > k) {
				while(1) {
					now -= v[ta].second;
					ta++;
					if(v[ta - 1].first == '0') {
						break;
					}
				}
			}
		}
		ans = max(ans, now);
	}
	cout << ans << endl;
}

Measured memory_bytes: 2548
#include<iostream>
#include<string>
using namespace std;
int main(void){
   int N,X,i,a,count,sum;
   cin>>N>>X;
   count=0;
   sum=0;

   for(i=0;i<N;i++){
     
     cin>>a;
     sum+=a;
     if(sum>X){
         
     }else{
         count++;
     }
     
   }
 cout<<count+1<<endl;

return 0;
}   

Measured memory_bytes: 256
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <map>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

enum Men{
	Syoumen,
	Migi,
	Haimen,
	Hidari,
	Ue,
	Shita,
};

Men men_array[6] = {Syoumen,Migi,Haimen,Hidari,Ue,Shita};

enum Loc{
	Top,
	Right,
	Left,
	Bottom,
};

char buf[4];

void func(){

	bool table[6][4];
	for(int i = 0; i < 6; i++){
		for(int k = 0; k < 4; k++){
			table[i][k] = false;
		}
	}

	for(int col = 0; col < 3; col++){
		if(buf[col] == '*'){
			table[Syoumen][Top] = true;
			if(col == 0){
				table[Syoumen][Left] = true;
			}
			if(col == 2){
				table[Syoumen][Right] = true;
			}
		}
	}

	scanf("%s",buf);
	for(int col = 0; col < 3; col++){
		if(buf[col] == '*'){
			if(col == 0){
				table[Syoumen][Left] = true;
			}
			if(col == 2){
				table[Syoumen][Right] = true;
			}
		}
	}

	scanf("%s",buf);
	for(int col = 0; col < 3; col++){
		if(buf[col] == '*'){
			table[Syoumen][Bottom] = true;
			if(col == 0){
				table[Syoumen][Left] = true;
			}
			if(col == 2){
				table[Syoumen][Right] = true;
			}
		}
	}

	for(int i = 1; i <= 5; i++){

		scanf("%s",buf);
		for(int col = 0; col < 3; col++){
			if(buf[col] == '*'){
				table[men_array[i]][Top] = true;
				if(col == 0){
					table[men_array[i]][Left] = true;
				}
				if(col == 2){
					table[men_array[i]][Right] = true;
				}
			}
		}

		scanf("%s",buf);
		for(int col = 0; col < 3; col++){
			if(buf[col] == '*'){
				if(col == 0){
					table[men_array[i]][Left] = true;
				}
				if(col == 2){
					table[men_array[i]][Right] = true;
				}
			}
		}

		scanf("%s",buf);
		for(int col = 0; col < 3; col++){
			if(buf[col] == '*'){
				table[men_array[i]][Bottom] = true;
				if(col == 0){
					table[men_array[i]][Left] = true;
				}
				if(col == 2){
					table[men_array[i]][Right] = true;
				}
			}
		}
	}

	int ans = BIG_NUM;

	//{Syoumen,Migi,Haimen,Hidari,Ue,Shita};

	if(table[Syoumen][Bottom] == true && table[Haimen][Bottom] == true){
		ans = 0;
	}

	if((table[Syoumen][Right] == true && table[Haimen][Left] == true) || (table[Syoumen][Left] == true && table[Haimen][Right] == true)){
		ans = min(ans,1);
	}

	if(table[Syoumen][Top] == true && table[Haimen][Top] == true){
		ans = min(ans,2);
	}

	if((table[Ue][Bottom] == true && table[Shita][Top] == true) || (table[Ue][Top] == true && table[Shita][Bottom] == true)){
		ans = min(ans,1);
	}

	if((table[Ue][Right] == true && table[Shita][Right] == true) || (table[Ue][Left] == true && table[Shita][Left] == true)){
		ans = min(ans,2);
	}

	if((table[Migi][Left] == true && table[Hidari][Right] == true) || (table[Migi][Right] == true && table[Hidari][Left] == true)){
		ans = min(ans,2);
	}

	if((table[Migi][Top] == true && table[Hidari][Top] == true) || (table[Migi][Bottom] == true && table[Hidari][Bottom] == true)){
		ans = min(ans,3);
	}

	printf("%d\n",ans);

}

int main(){

	while(true){
		scanf("%s",buf);
		if(buf[0] == '#')break;

		func();
	}


}

Measured memory_bytes: 3076
#include<bits/stdc++.h>
#define x first
#define y second
typedef std::pair<int,int>P;int k,x,y,t;P a[1<<20];P C(int x,int y){if(x>y){P t=C(y,x);return{t.y,t.x};}if(x<0){P t=C(-x,y);return{-t.x,t.y};}if(x+y>=2*k)return{x,y-k};if(x+y==k)return{0,0};int t=k-(x+y)/2;return{-t,y-k+x+t};}
main(){for(scanf("%d%d%d",&k,&x,&y),!(k&1)&&(x+y&1)&&(exit(puts("-1")&0),0),a[0]={x,y};a[t].x||a[t].y;t++)a[t+1]=C(a[t].x,a[t].y);for(printf("%d\n",t);t--;)printf("%d %d\n",a[t].x,a[t].y);}

Measured memory_bytes: 4096
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    n = I()
    s = S()
    r = 0
    t = '-'
    for c in s:
        if c != t:
            r += 1
            t = c

    return r


print(main())



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

#ifdef _DEBUG
#define debug(x) cerr << "line: " << __LINE__ << ", func: " << __func__ << " ->  " << #x << " = " << x << endl
#else
#define debug(x)
#endif

#define all(s) begin(s), end(s)
#define rall(s) rbegin(s), rend(s)
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = ((a)-1); i >= (b); i--)
#define pb push_back
#define sz(a) int((a).size())
#define put(a) ((cout) << (a) << (endl))
#define putf(a, n) ((cout) << (fixed) << (setprecision(n)) << (a) << (endl))
#define deg2rad(x) (((x)*PI) / (180.0))
#define rad2deg(x) (((x) * (180.0)) / PI)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using i_i = pair<int, int>;
using ll_ll = pair<ll, ll>;
using d_ll = pair<double, ll>;
using ll_d = pair<ll, double>;
using d_d = pair<double, double>;

static constexpr ll LL_INF = 1LL << 60;
static constexpr int I_INF = 1 << 28;
static constexpr double PI = static_cast<double>(3.14159265358979323846264338327950288);
static constexpr double EPS = numeric_limits<double>::epsilon();

static map<type_index, const char* const> scanType = {
    {typeid(int), "%d"}, {typeid(ll), "%lld"}, {typeid(double), "%lf"}, {typeid(char), "%c"}};

template <class T> static void scan(vector<T>& v);
[[maybe_unused]] static void scan(vector<string>& v, bool isWord = true);
template <class T> static inline bool chmax(T& a, T b);
template <class T> static inline bool chmin(T& a, T b);
template <class T> static inline T gcd(T a, T b);
template <class T> static inline T lcm(T a, T b);
template <class A, size_t N, class T> static void Fill(A (&arr)[N], const T& val);
template <class T> T mod(T a, T m);

int main(int argc, char* argv[]) {
  ll n, k;
  cin >> n >> k;

  ll ans = 0;
  rep(i, 1, n + 1) {
    ll m = k - (i % k);
    if (m > n) continue;
    if (k - m != m && m != k) continue;
    ll count = 1 + (n - m) / k;
    ans += count * count;
  }

  put(ans);
  return 0;
}

template <class T> static void scan(vector<T>& v) {
  auto tFormat = scanType[typeid(T)];
  for (T& n : v) {
    scanf(tFormat, &n);
  }
}

static void scan(vector<string>& v, bool isWord) {
  if (isWord) {
    for (auto& n : v) {
      cin >> n;
    }
    return;
  }

  int i = 0, size = v.size();
  string s;
  getline(cin, s);

  if (s.size() != 0) {
    i++;
    v[0] = s;
  }

  for (; i < size; ++i) {
    getline(cin, v[i]);
  }
}

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;
}

template <class T> inline T gcd(T a, T b) { return __gcd(a, b); }

template <class T> inline T lcm(T a, T b) { return (a * b) / gcd(a, b); }

template <class A, size_t N, class T> void Fill(A (&arr)[N], const T& val) {
  std::fill((T*)arr, (T*)(arr + N), val);
}

template <class T> T mod(T a, T m) { return (a % m + m) % m; }


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

int main(){
  typedef pair<string,int>P;
  while(1){
    string str;
    map<string,int>maps;
    queue<P>que;
    int kaku=0;
    cin>>str;
    if(str[0]=='0')break;
     que.push(P(str,0));
     while(!que.empty()){
       P p=que.front();que.pop();
       string  now,turn;
       int cnt=1;
       int ans;
       now=p.first;
       turn=p.first;
       ans=p.second;
       //   cout<<now<<" "<<ans<<endl;
       if(maps[now]==1)continue;
       maps[now]=1;
       
       for(int i=0;i<str.size()-1;i++){
	 if(now[i]==now[i+1])cnt++;
       }
       if(cnt==str.size()){
	 cout<<ans<<endl;
	 kaku=1;
	 break;
       }
       for(int i=0;i<str.size()-1;i++){
	 if(now[i]=='b' && now[i+1]=='r' || now[i]=='r' && now[i+1]=='b'){
	   now[i]='g';now[i+1]='g';
	   que.push(P(now,ans+1));
	   now=turn;
	 }
	 if(now[i]=='r' && now[i+1]=='g' || now[i]=='g' && now[i+1]=='r'){
	   now[i]='b';now[i+1]='b';
	   que.push(P(now,ans+1));
	   now=turn;
	 }
	 if(now[i]=='b' && now[i+1]=='g' || now[i]=='g' && now[i+1]=='b'){
	   now[i]='r';now[i+1]='r';
	   que.push(P(now,ans+1));
	   now=turn;
	 }
       }
     }
     if(!kaku)cout<<"NA"<<endl;
  }   
}

Measured memory_bytes: 3384
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define per(i,n) for(int i = n-1; i >= 0; i--)
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
const long long mod = 1000000007LL;

const long long MAX = 10000LL;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; 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;
    }
}

// 二項係数計算
long long 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() {
  ll s;
  cin >> s;
  ll ans = 0LL;
  COMinit();
  for(int i = 1; i<=s; i++) {
    if(i*3>s) break;
    ll n = i;
    ll m = s;
    m -= 3*n;
    ans += COM(m+n-1,n-1);
    ans %= mod;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3860
#[allow(dead_code)]
fn main() {
    let (a, b) = i::u2();
    println!("{}", a * b / gcd(a, b));
}

#[allow(unused_imports)]
use greatest_common_divisor::*;

#[allow(dead_code)]
mod greatest_common_divisor {
    use std::mem::swap;

    pub fn gcd(mut a: usize, mut b: usize) -> usize {
        if a < b {
            swap(&mut b, &mut a);
        }
        while b != 0 {
            a = a % b;
            swap(&mut a, &mut b);
        }
        a
    }
}

#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::io::*;
#[allow(unused_imports)]
use std::num::*;
#[allow(unused_imports)]
use std::str::*;

#[allow(dead_code)]
mod i {
    use super::*;

    pub fn read<T: FromStr>() -> T {
        stdin()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>()
            .parse::<T>()
            .ok()
            .unwrap()
    }

    pub fn str() -> String {
        read()
    }

    pub fn s() -> Vec<char> {
        str().chars().collect()
    }

    pub fn i() -> i64 {
        read()
    }

    pub fn u() -> usize {
        read()
    }

    pub fn u2() -> (usize, usize) {
        (read(), read())
    }

    pub fn u3() -> (usize, usize, usize) {
        (read(), read(), read())
    }

    pub fn f() -> f64 {
        read()
    }

    pub fn c() -> char {
        read::<String>().pop().unwrap()
    }

    pub fn iv(n: usize) -> Vec<i64> {
        (0..n).map(|_| i()).collect()
    }

    pub fn iv2(n: usize) -> Vec<(i64, i64)> {
        (0..n).map(|_| iv(2)).map(|a| (a[0], a[1])).collect()
    }

    pub fn uv(n: usize) -> Vec<usize> {
        (0..n).map(|_| u()).collect()
    }

    pub fn uv2(n: usize) -> Vec<(usize, usize)> {
        (0..n).map(|_| uv(2)).map(|a| (a[0], a[1])).collect()
    }

    pub fn uv3(n: usize) -> Vec<(usize, usize, usize)> {
        (0..n).map(|_| uv(3)).map(|a| (a[0], a[1], a[2])).collect()
    }

    pub fn fv(n: usize) -> Vec<f64> {
        (0..n).map(|_| f()).collect()
    }

    pub fn cmap(h: usize) -> Vec<Vec<char>> {
        (0..h).map(|_| s()).collect()
    }
}


Measured memory_bytes: 4476
k = int(input())

even_list = []
odd_list = []

is_odd = True
for i in range(1, k + 1):
    if is_odd:
        odd_list.append(i)
    else:
        even_list.append(i)
    is_odd = not is_odd

print(int(len(even_list) * len(odd_list)))


Measured memory_bytes: 2940
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <map>
using namespace std;
map<int, int> mp;
int main() {
	int N; scanf("%d", &N);
	for(int i = 1; i <= N; ++i) {
		int val; scanf("%d", &val); 
		if(mp.find(val) == mp.end()) mp[val] = 1;
		else mp[val]++;
	}
	long long ans = 0;
	for(map<int, int> ::iterator it = mp.begin(); it != mp.end(); it++) {
		int tmp = it -> second; int val = it -> first;
		//cout << val << ' ' << tmp << endl;
		if(tmp >= val) ans += tmp - val;
		else ans += tmp;
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 4736
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef int ll;
typedef long double ld;
const ll N = 1000005;
char en = '\n';
ll inf = 1e16;
ll mod = 1e9 + 7;
ll power(ll x, ll n, ll mod) {
  ll res = 1;
  x %= mod;
  while (n) {
    if (n & 1)
      res = (res * x) % mod;
    x = (x * x) % mod;
    n >>= 1;
  }
  return res;
}

ll fact[N];
ll ifact[N];

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

  fact[0] = ifact[0] = 1;
  for (ll i = 1; i < N; i++) {
    fact[i] = (i * fact[i - 1]) % mod;
    ifact[i] = power(fact[i], mod - 2, mod);
  }

  ll x, y;
  cin >> x >> y;

  ll res = 0;
  for (ll i = 0; i <= min(x, y); i++) {
    ll reqx = x - i;
    ll reqy = y - i;

    if ((reqx + reqy) != i)
      continue;

    res += fact[i] * ifact[reqx] % mod * ifact[i - reqx] % mod;
  }

  cout << res << en;
  return 0;
}

/*
5
1 2 3 1 2
1
1 5
 */

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

using namespace std;
using ll =long long;

#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cout << #x << " = " << (x) << endl;
bool coY() {cout <<"Yes"<<endl;}
bool coN(){cout <<"No"<<endl;}

const ll INF = 1LL << 60;

ll N,M,H,W,K,A,B;
string S;
//Write From this Line

int main()
{
	cout << setprecision(10);
	cin >> A >> B >> N;
	ll hairu = min(A-B , N);
	cout << N - hairu << endl;

}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    int N, i;
    scanf("%d", &N);
    for(i = 0; i < N; i++){
        int x, y, dx, dy;
        int max_d, max_x, max_y;
        x = y = max_d = max_x = max_y = 0;
        while(1){
            scanf("%d %d", &dx, &dy);
            if(dx == 0 && dy == 0)
                break;
            x += dx;
            y += dy;
            if(max_d < (x * x) + (y * y)){
                max_d = (x * x) + (y * y);
                max_x = x;
                max_y = y;
            }else if(max_d == (x * x) + (y * y) && max_x < x){
                max_d = (x * x) + (y * y);
                max_x = x;
                max_y = y;
            }
        }
        printf("%d %d\n", max_x, max_y);

    }
    return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <cstdio>
#include <cctype>
#include <cstring>
using namespace std;

int main(){  
  int a,b;
  cin >> a >> b;
  if (a*b%2 == 0)
  {
    cout << "Even" << endl;
  } else {
    cout << "Odd" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
using namespace std;
typedef long long ll;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//V,P(大文字)使用不可
//乗算の際にオーバーフローに注意せよ！！（適切にmodをとれ）
//制約をよく読め！

const ll INF=1e18;

signed main(){
    ll A,B,m;
    cin>>A>>B>>m;
    V<ll> a(A),b(B);
    cinf(A,a);
    cinf(B,b);
    V<ll> x(m),y(m),c(m);
    rep(i,m) cin>>x[i]>>y[i]>>c[i];
    ll ans=INF;
    priority_queue<ll,V<ll>,greater<ll>> que;
    rep(i,m){
        que.push(a[x[i]-1]+b[y[i]-1]-c[i]);
    }
    sort(all(a));
    sort(all(b));
    que.push(a[0]+b[0]);
    cout<<que.top()<<endl;
}

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

int main(){
  int W,H,N;
  scanf("%d%d%d",&W,&H,&N);
  vector<int> X(N),Y(N),a(N);
  for(int i=0;i<N;i++) scanf("%d%d%d",&X[i],&Y[i],&a[i]);
  //vector<bool> Ver(H,true),Hor(W,true);
  int l=0,r=W,d=0,u=H;
  for(int i=0;i<N;i++){
    switch(a[i]){
      case 1:
        l=max(l,X[i]);
        break;
      case 2:
        r=min(r,X[i]);
        break;
      case 3:
        d=max(d,Y[i]);
        break;
      case 4:
        u=min(u,Y[i]);
        break;
    }
  }
  int ans=max(0,r-l)*max(0,u-d);
  printf("%d\n",ans);
}

Measured memory_bytes: 3804
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.Channels;
import java.nio.channels.ReadableByteChannel;

public class Main {
    static final ByteBuffer buf = ByteBuffer.allocate(1000000);
    static final ReadableByteChannel in = Channels.newChannel(System.in);
    static final int NAME = 0;
    static final int T = 1;// top;
    static final int B = 2;// Bottom;
    static final int L = 3;// left;
    static final int R = 4;// right;
    static final int UNDERS = 5;

    public static void main(String[] args) throws IOException {
	init();
	int n = getInt();
	for (int i = 0; i < n; i++) {
	    int h = getInt();
	    int w = getInt();
	    byte[][] box = new byte[h][w];
	    int[][] item = new int[7][6];
	    int count = 0;
	    for (int y = 0; y < h; y++) {
		getLine(box[y]);
		for (int x = 0; x < w; x++) {
		    final byte c = box[y][x];
		    if (c != '.') {
			for (int k = 0; k < 7; k++) {
			    if (item[k][NAME] == 0) {
				item[k][NAME] = c;
				item[k][T] = item[k][B] = y;
				item[k][L] = item[k][R] = x;
				count++;
				break;
			    } else if (item[k][NAME] == c) {
				if (item[k][B] != y) {
				    item[k][B] = y;
				}
				if (x < item[k][L]) {
				    item[k][L] = x;
				} else if (item[k][R] < x) {
				    item[k][R] = x;
				}
				break;
			    }
			}
		    }
		}
	    }
	    boolean isSUSPICIOUS = false;
	    for (int num = 0; !isSUSPICIOUS && num < count; num++) {
		for (int y = item[num][T]; !isSUSPICIOUS && y <= item[num][B]; y++) {
		    for (int x = item[num][L]; !isSUSPICIOUS
			    && x <= item[num][R]; x++) {
			final byte parts = box[y][x];
			if (parts != item[num][NAME]) {
			    if (parts == '.') {
				isSUSPICIOUS = true;
			    } else {
				int partsNum;
				for (int j = 0; j < count; j++) {
				    if (item[j][0] == parts) {
					partsNum = j;
					isSUSPICIOUS = !setUnders(item, partsNum,
						num);
					break;
				    }
				}
			    }

			}
		    }
		}
	    }
	    System.out.println(isSUSPICIOUS?"SUSPICIOUS":"SAFE");

	}

    }

    private static boolean setUnders(int[][] item, int upperNum, int underNum) {
	if (underNum == upperNum) {
	    return false;
	}
	for (int i = 0; i < 7; i++) {
	    if ((item[underNum][UNDERS] & getLayer(i)) != 0) {
		if (!setUnders(item, upperNum, i)) {
		    return false;
		}
	    }
	}
	item[upperNum][UNDERS] |= getLayer(underNum);
	return true;
    }

    static int getLayer(int i) {
	return 1 << i;
    }

    static void init() throws IOException {
	buf.clear();
	in.read(buf);
	buf.flip();
    }

    static int getInt() {
	byte b = buf.get();
	while (b < '0' || '9' < b) {
	    b = buf.get();
	}
	int result = 0;
	while ('0' <= b && b <= '9') {
	    result = result * 10 + (b - '0');
	    b = buf.get();
	}
	return result;
    }

    static void getLine(byte[] array) {
	byte b = buf.get();
	while (b != '.' && (b < 'A' || 'Z' < b)) {
	    b = buf.get();
	}
	buf.position(buf.position() - 1);
	buf.get(array);
    }
}

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

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int x, y, z; cin >> x >> y >> z;
    int n = x + y + z;
    vector<long long> a(n), b(n), c(n);
    vector<int> v;
    long long sum = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> b[i] >> c[i];
        sum += a[i]; b[i] -= a[i], c[i] -= a[i];
        v.emplace_back(i);
    }
    auto cmp = [&b, &c](int i, int j) {
        return b[i] - c[i] > b[j] - c[j];
    };
    sort(v.begin(), v.end(), cmp);
    vector<long long> pre_b(n, 0), suf_c(n, 0);
    auto calc = [&v](int st, int en, int inc, int sz, auto &val, auto &w) {
        multiset<long long> ms; long long sum = 0;
        for (int i = st; i != en; i += inc) {
            sum += val[v[i]];
            ms.insert(val[v[i]]);
            if (ms.size() > sz) {
                sum -= *ms.begin();
                ms.erase(ms.begin());
            }
            w[i] = sum;
        }
    };
    calc(0, n, 1, y, b, pre_b);
    calc(n-1, -1, -1, z, c, suf_c);
    long long ans = 0;
    for (int i = y-1; i < n-z; i++) {
        ans = max(ans, sum + pre_b[i] + suf_c[i+1]);
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 8952
#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

#[allow(dead_code)]
fn yesno(b: bool){
    if b {
        println!("Yes");
    }
    else{
        println!("No");
    }
}

fn main(){
    let v = read_vec::<u32>();
    let n = v[0];
    let d:f64 = v[1].into();
    let xys = read_vec2::<f64>(n);
    let d2 = d.powf(2f64);
    let mut cnt = 0;
    for xy in xys {
        if xy[0].powf(2f64)+xy[1].powf(2f64) <= d2{
            cnt = cnt+1;
        }
    }

    println!("{}", cnt);

}

Measured memory_bytes: 12832
/// Bismillahir Rahmanir Rahim
/* Author: Mohammad Morsalin (aka white_space)
    Dept of ICE, NSTU
*/
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define endl "\n"
#define f0(n) for(int i=0;i<n;i++)
#define ms(x) memset(x,0,sizeof(x))
#define ins insert
#define ALL(v) v.begin(),v.end()
#define highest(x) numeric_limits<x>::max()
#define lowest(x) numeric_limits<x>::min()
#define Inf INFINITY
#define minv(v) *min_element(v.begin(),v.end())
#define maxv(v) *max_element(v.begin(),v.end())
#define PI acos(-1)
#define IOS ios::sync_with_stdio(false);
using namespace std;
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};
const long long MOD = 1000000007;
template<typename T>inline T Bigmod(T base, T power, T MOD){
    T ret=1;
    while(power)
    {
        if(power & 1)ret=(ret*base)%MOD;
        base=(base*base)%MOD;
        power>>=1;
    }
    return ret;
}

bool sortinrev(const pair<int,int> &a,
               const pair<int,int> &b)
{
       return (a.first > b.first);
}
int main()
{
    IOS
    ll a,b,c,k;
    while(cin>>a>>b>>c>>k){
        ll ans=0;
        ans+=min(a,k);
        k-=a;
        if(k<=0){
            cout << ans << endl;
            continue;
        }
        k-=b;
        if(k<=0){
            cout << ans << endl;
            continue;
        }
        ans-=min(k,c);
        k-=c;
        if(k<=0){
            cout << ans << endl;
            continue;
        }
    }
    return 0;
}
///Alhamdulillah


Measured memory_bytes: 3608
#include <iostream>
#include <vector>
#define llint long long

using namespace std;

llint n;

llint calc(llint x, llint y)
{
	llint ret = 0;
	vector<int> vec;
	for(int i = 1; i <= n; i++){
		vec.clear();
		for(int t = i; t; t/=10) vec.push_back(t%10);
		if(vec.front() == y && vec.back() == x) ret++;
	}
	return ret;
}

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	llint ans = 0;
	for(int i = 1; i <= 9; i++){
		for(int j = 1; j <= 9; j++){
			ans += calc(i, j) * calc(j, i);
		}
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const ll MOD = 1000000007;

int A[2][102];

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

    for(int i=0;i<2;i++){
        for(int j=0;j<N;j++){
            cin >> A[i][j];
        }
    }

    int ans = 0;
    int c = 0;
    for(int j=0;j<N;j++){
        c += A[0][j];
        int s = c;
        for(int k=j;k<N;k++){
            s += A[1][k];
        }
        ans = max(ans, s);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
from collections import defaultdict

def main()->str:
    H,W,M=map(int,input().split())
    ch=[0]*H
    cw=[0]*W
    bm=defaultdict(lambda:False)
    for _ in range(M):
        h,w=map(int,input().split())
        h-=1
        w-=1
        bm[(h,w)]=True
        ch[h]+=1
        cw[w]+=1
    hb=max(ch)
#    max_h=[i for i, x in enumerate(ch) if x == hb]
    max_h=[]
    for i in range(len(ch)):
        if ch[i]==hb: max_h.append(i)
    wb=max(cw)
#    max_w=[i for i, x in enumerate(cw) if x == wb]
    max_w=[]
    for i in range(len(cw)):
        if cw[i]==wb: max_w.append(i)
    
    z=hb+wb
    for mh in max_h:
        for mw in max_w:
            if bm[(mh,mw)]==False:
                return(z)
    return(z-1)

if __name__ == "__main__":
    print(main())

Measured memory_bytes: 178836
#include <stdio.h>
#include <string.h>

int main() {
	int ining;
	int ten[50];
	int base[3];
	char act[8];
	int outCnt = 0;
	
	for(int i=0;i<50;i++){
		ten[i] = 0;
	}
	
	for(int i=0;i<3;i++){
		base[i] = 0;
	}
	
	scanf("%d",&ining);
	
	for(int i=0;i<ining;i++){
		while(outCnt < 3){
			scanf("%s",act);
			if(strcmp(act,"HIT") == 0) {
				ten[i] = ten[i] + base[2];
				base[2] = base[1];
				base[1] = base[0];
				base[0] = 1;
			} else if(strcmp(act,"HOMERUN") == 0) {
				for(int l=0;l<3;l++){
					ten[i] = ten[i] + base[l];
					base[l] = 0;
				}
				ten[i] = ten[i] + 1;
			} else if(strcmp(act,"OUT") == 0) {
				outCnt++;
			}
		}
		outCnt = 0;
		for(int i=0;i<3;i++){
			base[i] = 0;
		}
	}
	
	for(int i=0;i<ining;i++)
		printf("%d\n",ten[i]);
	
	return 0;
}


Measured memory_bytes: 2556
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>



#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = (int)(n-1); i >= 0; i--)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll a;cin>>a;
  string s;cin>>s;
  if(a>=3200){
    cout<<s<<endl;
  }
  else {
    cout<<"red"<<endl;  
  }
  return 0;

}


Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        a: usize,
        b: usize
    }
    if a <= b {
        for i in 0..b {
            print!("{}", a);
        }
        println!("");
    } else {
        for i in 0..a {
            print!("{}", b);
        }
        println!("");
    }
}


Measured memory_bytes: 4352
#include<cstdio>
#include<iostream>
#include<algorithm>

using namespace std;

int main(void) {

	int n, x, sum = 0, minn = 100000;

	cin >> n >> x;

	int m[n], num = n;

	for (int i = 0; i < n; i++)
	{
		cin >> m[i];
		sum += m[i];
		minn = min(minn, m[i]);
	}

	x -= sum;
	num += x / minn;

	cout << num << "\n";



	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <cstring>

using namespace std;

const int N=100005;
const int P=998244353;

int n;
long long x,y,z;

void init(){
	cin>>x>>y;
	if(x>y) swap(x,y);
	z=x*y;
	long long w=sqrt(z);
	if(w*w==z){
		if(x==w){
			cout<<2*w-2<<endl;
		}
		else{
			cout<<2*w-3<<endl;
		}
	}
	else if(w*(w+1)>=z){
	//	if(x==w) cout<<2*w-3<<endl;
	//	else{
			cout<<2*w-2<<endl;
	//	}
	}
	else cout<<2*w-1<<endl;
}

int main(){
	cin>>n;
	for(int i=1;i<=n;i++) init();
	return 0;
}

Measured memory_bytes: 256