akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#define int long long
using namespace std;

int h,w;
string s[400];
int f[411][411];
int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

int white,black,ans;

void dfs(int x,int y,char ch){
    f[x][y]=1;
    if(s[x][y]=='.')white++;
    else black++;
    
    for(int i=0;i<4;i++){
        int kx=x+dx[i],ky=y+dy[i];
        if(kx>=0 && ky>=0 && kx<h && ky<w && s[kx][ky]!=ch && f[kx][ky]!=1){
        	if(ch=='.')dfs(kx,ky,'#');
        	else dfs(kx,ky,'.');
        }
    }
    
    
    
    return ;
}

signed main(void){
    cin>>h>>w;
    for(int i=0;i<h;i++)cin>>s[i];
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(s[i][j]=='#'){
                dfs(i,j,'#');
                ans+=black*white;
                //cout<<ans<<endl;
            }
            black=0;white=0;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 11776
n=int(input())
lb=0
ra=0
ba=0
ans=0

import re

for _ in range(n):
    s=input()

    ans+=s.count('AB')

    if s[0]=='B' and s[-1]=='A':
        ba+=1
    elif s[0]=='B':
        lb+=1
    elif s[-1]=='A':
        ra+=1

if ba>0:
    ans+=ba-1
    ba=1

tmp=min(lb,ra,ba)
ans += 2*tmp

lb-=tmp
ra-=tmp
ba-=tmp

if lb<0:
    lb=0
if ra<0:
    ra=0
if ba<0:
    ba=0

if lb!=0 or ra!=0:
    ans+=min(lb,ra)
    ans+=min(lb,ba)
    ans+=min(ra,ba)


print(ans)

Measured memory_bytes: 9944
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
#define rep(i, n)for(int i=0; i<n; i++)

int main(){
  int D, T, S;  
  cin >> D >> T >> S;

  if(D <= S*T)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  
  return 0;
}


Measured memory_bytes: 3632
#include <iostream>
//#include <bits/stdc++.h>
// a&1 check odd or not and a>>=1 halfs a
// (n-1-i)%i previous in circle (i+n-1)%n next one
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define pb(x) push_back(x)
#define F first
#define S second
using namespace std;



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

    string s;
    cin>>s;
    stack<char> q;
    vector<char> v;
    loop(i,0,s.size()){
    	if(s[i]!='B'){
    		q.push(s[i]);
		}
		else{
			if(!q.empty())
				q.pop();
		}
	}
	while(!q.empty()){
		char x=q.top();
		v.pb(x);
		q.pop();
	}
	reverse(v.begin(),v.end());
	for(auto x:v){
		cout<<x;
	}
	
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdlib>

using namespace std;

#define ALL(c) c.begin(),c.end()
#define RALL(c) c.rbegin(),c.rend()
#define REP(type,i,n) for(type i=0;i<(n);++i)
#define MP(a,b) make_pair((a),(b))
#define F_ first
#define S_ second

typedef long long int lli;
typedef pair<int,int> Pi;

const int INF=100000000;
const long long int INF_=1000000000000000000;

int CharToInt(char ch){
	return 'a'-ch;
}

int convert(string s1,string s2){
	int a,b;
	a=60*10*CharToInt(s1[0])+60*CharToInt(s1[1])+CharToInt(s1[3])*10+CharToInt(s1[4]);
	b=60*10*CharToInt(s2[0])+60*CharToInt(s2[1])+CharToInt(s2[3])*10+CharToInt(s2[4]);
	return b-a;
}

int main(){
	int N,T;
	cin >> N >> T;
	int count=0;
	vector<pair<string,int> > ans;
	string time[4],name[4];
	REP(int,i,N){
		int idx1=i%2==0?0:2;
		cin >> time[idx1] >> name[idx1] >> time[idx1+1] >> name[idx1+1];
		if(i==0) continue;
		int idx2=i%2==0?3:1;
		if(convert(time[idx1],time[idx2])>=T){
			++count;
			ans.push_back(pair<string,int>(name[idx1],convert(time[idx1],time[idx2])));
		}
	}
	cout << count << endl;
	REP(int,i,ans.size()){
		cout << ans[i].F_ << ' ' << ans[i].S_ << endl;
	}
	return 0;
}

Measured memory_bytes: 1220
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 123;
#define int long long 
int n, k;

int s[maxn], a[maxn];
map <int, int> cnt;
main () { 
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    //(i - j + 1) == s[i]% k - s[j - 1] % k
//    s[i] % k - i == s[j - 1] % k - (j - 1)
  //  s[i] - s[j - 1] - (s[i] - s[j - 1]) / k * k == i - j + 1

  //	i - j + 1 == (s[i] - s[j - 1]) - (s[i] - s[j - 1]) / k * k
//  	s[i] - s[i] / k * k - i == s[j - 1] - s[j - 1] / k * k - (j - 1)

 // 	a -b                a 
  //	 k

    //ik - jk + k = s[i] - s[j - 1]

    //s[i] - ik = s[j - 1] - k(j - 1)

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


    for(int i = 1; i <= n; i++) s[i] = s[i - 1] + a[i];

    long long ans = 0;
    cnt[0] = 1;
    for(int i = 1; i <= n; i++) {
    int j = i;
    if(j >= k) cnt[(s[i - k] % k- (i - k) % k + k + k)% k]--;
    int x = (s[i] % k - j % k + k + k) % k;
    ans += cnt[x], cnt[x]++;
    }

    cout << ans;
}




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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define fst first
#define snd second
#define pb push_back
#define ALL(x) x.begin(),x.end()
#define EPS (1e-9)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

bool LT(double a,double b) { return !equals(a,b) && a < b; }
bool LTE(double a,double b) { return equals(a,b) || a < b; }

const string YES = "";
const string NO  = "";

typedef long long ll;

void solve() {

}

int main() {
  priority_queue<int> Q;
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) {
    cin >> a[i];
    Q.push(a[i]);
  }
  rep(i,n) {
    int v = Q.top(); Q.pop();
    if( v == a[i] ) {
      int w = Q.top(); Q.pop();
      cout << w << endl;
      Q.push(v);
      Q.push(w);
    } else {
      cout << v << endl;
    }
    Q.push(v);
  }
  return 0;
}


Measured memory_bytes: 4080
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 998244353;
const ll INF = mod * mod;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef pair<ll, ll> LP;
typedef vector<int> vec;
typedef vector<string> svec;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-8;

//閉路やばそう
//閉路の総和がPより大きいとヤバそう
//小さい場合は閉路を回る必要がないが

//閉路判定以外やるだけでは？

struct edge {
	int to; ll cost;
};
vector<edge> G[2500];
ll score[2500];
void solve() {
	int k, x; cin >> k >> x;
	for (int i = x - k + 1; i <= x + k - 1; i++) {
		if (i > x - k + 1)cout << " ";
		cout << i;
	}
	cout << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//init();
	solve();
	//cout << "finish" << endl;
	//stop
	return 0;
}


Measured memory_bytes: 384
#pragma warning (disable:4996)
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <cstdio>
#include <cmath>
#include <stack>
#include <queue>
#define inf 0X7f7f7f7f
#define MS_I(x) memset(x,-inf,sizeof(x))
#define MS(x) memset(x,0,sizeof(x))
#define MSI(x) memset(x,inf,sizeof(x))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = 1e5 + 5;

int order[maxn];
int place[maxn];

int main()
{
	int N;
	scanf("%d", &N);
	for (int i = 1; i <= N; i++)
	{
		scanf("%d", &order[i]);
		place[order[i]] = i;
	}
	for (int i = 1; i <= N; i++)
		printf("%d ", place[i]);
	printf("\n");
	return 0;
}

Measured memory_bytes: 1536
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<cctype>
#include<complex>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<functional>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<bitset>
using namespace std;
const int dx[] = {1,0,-1,0},dy[] = {0,1,0,-1};
#define INF 1e+8
#define EPS 1e-8
#define rep(i,j) for(int i = 0; i < (j); i++)
#define reps(i,j,k) for(int i = j; i < k; i++)
//typedef long long ll;
typedef pair<int,int> Pii;
int main(){
	int n;
	cin >> n;
	
	vector < string > change;
	change.push_back("");
	change.push_back(".,!? ");
	change.push_back("abc");
	change.push_back("def");
	change.push_back("ghi");
	change.push_back("jkl");
	change.push_back("mno");
	change.push_back("pqrs");
	change.push_back("tuv");
	change.push_back("wxyz");
	
	while(n--){
		string str;
		cin >> str;
		int len = str.size();
		string ans = "";
		rep(i,len){
			if(str[i] == '0')continue;
			int sub = i;
			while(str[i] == str[++sub]);
			if(str[sub-1]-48 == 1)ans += change[str[sub-1]-48][(sub-i-1)%5];
			else if(str[sub-1]-48 == 7 || str[sub-1]-48 == 9)ans += change[str[sub-1]-48][(sub-i-1)%4];
			else ans += change[str[sub-1]-48][(sub-i-1)%3];
			i = sub;
		}
		
		cout << ans << endl;
	}
	
	return 0;
}

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

int main(){
    int n;
    cin >> n;
    if (n % 7 == 0){
        cout  << "Yes" << endl;
        return 0;
        }
    while (n > 0){
        if (n % 4 == 0){
            cout << "Yes" << endl;
            return 0;
        }
        n -= 7;
    }
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
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; }

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) do{}while(0)
#endif





int main(){
	string s;
	ll n;
	cin >> n;
	cin >> s;
	s = "xR" + s + "Wx";
	ll l = 2;
	ll r = n+2;
	ll op = 0;
	while ( true ){
		while ( s[l] == 'R' ) l++;
		while ( s[r] == 'W' ) r--;
		if ( l >= r )
			break;
		
		if ( s[l] == 'W' || s[r] == 'R' ){
			op++;
			if ( s[l] == 'W' ) l++;
			if ( s[r] == 'R' ) r--;
		}
	}
	
	
	cout << op << endl;

	return 0;
}




Measured memory_bytes: 3924
// This code writed by chtholly_micromaker(MicroMaker)
#include <bits/stdc++.h>
#define reg register
using namespace std;
template <class t> inline void rd(t &s)
{
	s=0;
	reg char c=getchar();
	while(!isdigit(c))
		c=getchar();
	while(isdigit(c))
		s=(s<<3)+(s<<1)+(c^48),c=getchar();
	return;
}
signed main(void)
{
	ios::sync_with_stdio(false);cin.tie(0);
	long long n;
	cin>>n;--n;
	cout<<(1ll+n)*n/2ll<<endl;
	return 0;
}


Measured memory_bytes: 256
($x,$y)=glob<>;
@p=glob<>;
@q=glob<>;
@r=glob<>;
@apples=sort{$$b[1]<=>$$a[1]}(
  (map{[0,$_]}@p),
  (map{[1,$_]}@q),
  (map{[2,$_]}@r)
);
$all_eatable=$x+$y;
for(;0<$all_eatable;$i++){
  $e=$apples[$i][0];
  ($e==0)?$x&&($x--,$all_eatable--,$d+=$apples[$i][1]):
  ($e==1)?$y&&($y--,$all_eatable--,$d+=$apples[$i][1]):
  ($d+=$apples[$i][1],$all_eatable--)
}
print$d

Measured memory_bytes: 112516
from collections import deque
N, M = map(int, input().split())
Mlist = [[] for _ in range(N+1)]
for i in range(M):
    a, b = map(int, input().split())
    Mlist[a].append(b)
    Mlist[b].append(a)

ans = [0] * (N+1)

d = deque()
d.append(1)
count = 0
while count != N:
    Q = d.popleft()
    for i in Mlist[Q]:
        if ans[i] == 0:
            ans[i] = Q
            d.append(i)
            count = count+1
print('Yes')
for i in range(N-1):
    print(ans[i+2])


Measured memory_bytes: 34092
import java.util.Scanner;

public class Main {
  static Scanner sc = new Scanner(System.in);
  static boolean[][] bomb = new boolean[50][50];

  public static void main(String[] args) {
    int H = sc.nextInt();
    int W = sc.nextInt();
    int N = sc.nextInt();
    int K = sc.nextInt();

    rec(0, H, 0, W, N);
    long ans = 0;
    long mul = 1;
    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) {
        if (bomb[i][j]) ans += mul;
        mul *= 2;
        mul %= K;
      }
    }
    System.out.println("! " + (ans % K));
    System.out.flush();
  }

  static void rec(int t, int b, int l, int r, int c) {
    if (c == 0) return;
    if ((b - t) * (r - l) == c) {
      for (int i = t; i < b; i++) {
        for (int j = l; j < r; j++) {
          bomb[i][j] = true;
        }
      }
      return;
    }
    if (b - t > 1) {
      int upper = query(t, (t + b) / 2, l, r);
      rec(t, (t + b) / 2, l, r, upper);
      rec((t + b) / 2, b, l, r, c - upper);
    } else {
      int left = query(t, b, l, (l + r) / 2);
      rec(t, b, l, (l + r) / 2, left);
      rec(t, b, (l + r) / 2, r, c - left);
    }
  }

  static int query(int t, int b, int l, int r) {
    System.out.printf("? %d %d %d %d\n", t, l, b - 1, r - 1);
    System.out.flush();
    return sc.nextInt();
  }

}




Measured memory_bytes: 19216
use std::process::exit;
use proconio::input;

fn main() {
  input! {
    k: u32
  };
  input! {
    a: u32,
    b: u32,
  };
  for value in a..=b {
    if value % k == 0 {
      println!("OK");
      exit(0);
    }
  }
  println!("NG");
}

Measured memory_bytes: 2088
import java.util.*;
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        if(a-b>=0) {
            System.out.println("delicious");
        }else if(a-b>=-x) {
            System.out.println("safe");
        }else {
            System.out.println("dangerous");
        }
    }
}

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

int main() {
  int N;
  cin >> N;
 
  vector<int> cards(N+1);
  
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    cards.at(i) = a;
  }
  
   sort(cards.begin(), cards.end()); 
   reverse(cards.begin(), cards.end());
  
  int Alice = 0;
  int Bob = 0;
  
  for (int i = 0; i < N; i += 2) {
    Alice += cards.at(i);
  }
  
  for (int i = 0; i < N; i += 2) {
    Bob += cards.at(i+1);
  }
  
  cout << Alice - Bob << endl;
    
 }


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

using namespace std;

int main() {
  string S;
  cin >> S;


  int s1 = stoi(S.substr(0, 2));
  int s2 = stoi(S.substr(2, 2));

  if (s1 == 0 && s2 > 12) {
    cout << "NA" << endl;
    return 0;
  } else if (s2 == 0 && s1 > 12) {
    cout << "NA" << endl;
    return 0;
    
  } else if (s1 > 12 && s2 > 12) {
    cout << "NA" << endl;
    return 0;
  } else if (s1 == 0 && s2 == 0) {
    cout << "NA" << endl;
    return 0;
  }

  if (s1 == 0) {
    cout << "YYMM" << endl;
    return 0;
  } else if (s2 == 0) {
    cout << "MMYY" << endl;
    return 0;
  }
  
  if (s1 <= 12 && s2 <= 12) {
    cout << "AMBIGUOUS" << endl;
  } else if (s1 <= 12) {
    cout << "MMYY" << endl;
  } else {
    cout << "YYMM" << endl;
  }
  return 0;
}



Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define REP(i, b, n) for (Int i = b; i < Int(n); i++)
#define rep(i, n) REP(i, 0, n)
using namespace std;
using Int = long long;
Int inf = 1000000000000000001LL;
using vi = vector<Int>;
using vvi = vector<vi>;

Int GCD(Int a, Int b){
    if(b==0) return a;
    if(a < b) return GCD(b, a);
    unsigned r;
    while ((r=a%b)) {
        a = b;
        b = r;
    }
    return b;
}

int main() {
    int N,M;

    cin >> N >>M;
    vvi A = vvi(N);
    vi K;
    int ans =0;
    unordered_map<int, int> mp;
    rep(i,N){
        int k;
        cin >> k;
        rep(j,k){
            int a;
            cin >> a;
            mp[a]++;
        }
    }

    for(auto itr = mp.begin(); itr != mp.end(); ++itr) {
                  if(itr->second == N){
                    ans++;
                  }
    }


    cout << ans;
    return 0;
}

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

bool compare(int l, int r) {
  return l < r;
}

int main() {
  
  int N;
  cin >> N;
  vector<int> a(N);
  for(int i = 0; i < N; i++) cin >> a[i];
  sort(a.begin(), a.end(), compare);
  int sum = 0;
  for(int i = 0; i < N; i++) {
    if (i % 2 == 0) sum += a[N - 1 - i];
    if (i % 2 == 1) sum -= a[N - 1 - i];
  }
  cout << sum;
  
}

Measured memory_bytes: 256
l1 = input().split()
a = int(l1[0])
b = int(l1[1])
x = int(l1[2])
if x == a:
    print("YES")
for i in range(1,b+1):
    if x == a+i:
        print("YES")
        exit()
if x < a or (x > (a+b)):
    print("NO")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int n,a,b,k,cnt=0;
bool flag[1005]={};
vector<int>v[1005];
vector<int>ans[1005];
stack<int>S;
void DFS(int V)
{
	S.push(V);
	ans[V].push_back(cnt);
	flag[V]=true;
	while(!S.empty())
	{
		int p=S.top();
		bool flag1=true;
		for(int i=0;i<v[p].size();i++)
		{
			if(v[p][i]==p)continue;
			if(!flag[v[p][i]])
			{
				cnt++;
				S.push(v[p][i]);
				ans[v[p][i]].push_back(cnt);
				flag1=false;
			}
			flag[v[p][i]]=true;
			if(!flag1)break;
		}
		if(flag1)
		{
			cnt++;
			ans[p].push_back(cnt);
			S.pop();
		}
	}
}

int main()
{	
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a>>k;
		for(int j=0;j<k;j++)
		{
			cin>>b;
			v[a].push_back(b);
		}
	}
	for(int i=1;i<=n;i++)
	{
		if(flag[i])continue;
		cnt++;
		DFS(i);
	}
	for(int i=1;i<=n;i++)
	{
		cout<<i;
		for(int j=0;j<ans[i].size();j++)
		{
			cout<<" "<<ans[i][j];
		}
		cout<<endl;
	}
	return 0;
}



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

//repetition
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

//const value
//const ll MOD = 1e9 + 7;
//const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
//const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline ll toLL(string s) {ll v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll h, n;
  cin >> h >> n;
  ll sum = 0;
  rep(i, n) {
    ll a;
    cin >> a;
    sum += a;
  }
  if(sum >= h) cout << "Yes" << "\n";
  else cout << "No" << "\n";
  return 0;
}


Measured memory_bytes: 256
# https://atcoder.jp/contests/code-festival-2017-qualc/tasks/code_festival_2017_qualc_c
# xを抜いたときにその文章が回文になっていれば必ず回文にすることができる
# 回分にできる場合は両端から、文字をマッチングさせていけばxを挿入する最小回数が求められる

enu = enumerate
ra = range
s = input()
s_nx = []
for ss in s:
    if ss != 'x':
        s_nx.append(ss)

if s_nx != s_nx[::-1]:
    print(-1)
    exit()

n = (len(s_nx) + 1) // 2  # 真ん中の文字は何文字目か(1based)


# どうやったらバグらせにくい考えよう
# 各文字間に含まれるxの数をカウントして配列に入れる。あとはその配列を逆さにして差を取れば良い
s = s
x_cnt = [0]
for ss in s:
    if ss != 'x':
        x_cnt.append(0)
    else:
        x_cnt[-1] += 1
ans = 0
for a, b in zip(x_cnt, reversed(x_cnt)):
    ans += abs(a - b)


# print(x_cnt)
print(ans // 2)


Measured memory_bytes: 51188
fun main(args: Array<String>) {
	val (hei, wid) = readInts()
	val f = Array(hei) { readLn().map { if (it == '#') 1 else 0 } }
	val a = Array(hei) { IntArray(wid) }
	for (i in 0 until hei) {
		for (j in 0 until wid) {
			a[i][j] = i + j
			if (i > 0) a[i][j] = Math.min(a[i][j], a[i - 1][j] + if (f[i - 1][j] == f[i][j]) 0 else 1)
			if (j > 0) a[i][j] = Math.min(a[i][j], a[i][j - 1] + if (f[i][j - 1] == f[i][j]) 0 else 1)
		}
	}
	println((a.last().last() + f[0][0] + f.last().last()) / 2)
}

private fun readLn() = readLine()!!
private fun readStrings() = readLn().split(" ")
private fun readInts() = readStrings().map { it.toInt() }


Measured memory_bytes: 37724
function reversStr(s) {
    var rs = "";
    for (var i = 0, n = s.length; i < n; i++) {
        rs += s[n-i-1];
    }
    return rs;
}

function check(s) {
    return s === reversStr(s);
}

function main(input) {
    var s = input.trim();
    console.log(
        check(s) && check(s.slice(0, s.length / 2 | 0)) ? "Yes" : "No");
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 23368
## A - Cookie Exchanges
A, B, C = map(int, input().split())
if not (A%2 == B%2 == C%2 == 0):
    ans = 0
elif A == B == C:
    ans = -1
else:
    ans = 0
    while A%2 == B%2 == C%2 == 0:
        a = (B+C) // 2
        b = (C+A) // 2
        c = (A+B) // 2
        A = a
        B = b
        C = c
        ans += 1
print(ans)



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

#define IO  ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
#define endl '\n'
#define ll long long
#define f first
#define s second
#define mod 1000000007
#define INF 0x3f3f3f3f3f3f3f3f

using namespace std;
int main()
{
    IO
    int x,y,x1,y1,addx,addy;
    cin>>x>>y>>x1>>y1;
    addx=x1-x;
    addy=y1-y;
    cout<<x1-addy<<" "<<y1+addx<<" "<<x-addy<<" "<<y+addx;
    return 0;
}

Measured memory_bytes: 3596
#include <cstdio>
int main(){
	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	if(0<=a,b,c<=100){
		if(a<b && b<c && a<c && a!=b && c!=b && c!=a){
				printf("Yes");
				printf("\n");
			}
			else{
				printf("No");
				printf("\n");			
		}
	}
	return 0;
}


Measured memory_bytes: 2716
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    
    int max = 0;
    int maxCount = 0;
    int max2nd = 0;
    int[] A = new int[N];
    for (int i = 0; i < N; i++) {
      A[i] = sc.nextInt();
      if (A[i] > max) {
        // update max
        max2nd = max;
        max = A[i];
        maxCount = 1;
      } else if (A[i] == max) {
        maxCount++;
      } else if (A[i] > max2nd) {
        max2nd = A[i];
      }
    }
    
    for (int i = 0; i < N; i++) {
      if (A[i] == max) {
        if (maxCount >= 2) {
          System.out.println(max);
        } else {
          System.out.println(max2nd);
        }
      } else {
        System.out.println(max);
      }
    }
  }
}

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

int main(){
  int N, A, B;
  cin >> N >> A >> B;
  int sum = 0, ans = 0;
  int k;
  for(int i = 1; i <= N; i++){
    sum = 0;
    k = i;
    for(int j = 0; j < 5; j++){
      sum += k % 10;
      k /= 10;
    }
    if(A <= sum && sum <= B){
      ans += i;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3624
#include <iostream>

using namespace std;

int main() {
    int a, b, c, x;
    cin >> a;
    cin >> b;
    cin >> c;
    cin >> x;
    int count = 0;
    for (int i = 0; i <= a; i++) {
        for (int j = 0; j <= b; j++) {
            for (int k = 0; k <= c; k++) {
                int sum = 500*i + 100*j + 50*k;
                if (sum == x) {
                    count++;
                }
            }
        }
    }
    cout << count << endl;
}


Measured memory_bytes: 256
'use strict'

const main = input => {
	const args = input.split('\n')[0].split(' ')
	const p = parseInt(args[0], 10)
	const q = parseInt(args[1], 10)
	const r = parseInt(args[2], 10)
	let min = 200
	if ((p + q) < min) min = p + q
	if ((q + r) < min) min = q + r
	if ((r + p) < min) min = r + p
	console.log(min)
}

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


Measured memory_bytes: 9420
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
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(a > b){ a = b; return 1; } return 0; }
typedef long long ll;
struct UFT{
  vector<int> par;//親
  vector<int> rank;//木の深さ
  vector<int> size;//木の大きさ
  int n;
  
  UFT(int _n)
  {
    n = _n;
    par.resize(n);
    rank.assign(n,0);
    size.assign(n,0);
    rep(i,n){
      par[i] = i;
    }
  }
  
  //xの根を返す
  int find(int x)
  {
    if(par[x] == x) return x;
    else return par[x] = find(par[x]);
  }

  //x,yを併合
  void unite(int x,int y)
  {
    x = find(x);
    y = find(y);
    if(x == y) return;

    if(rank[x] < rank[y]){
      par[x] = y;
      size[y] += size[x];
    }
    else{
      par[y] = x;
      size[x] += size[y];
      if(rank[x] == rank[y]) rank[x]++;
    }
  }

  //x,yが同じグループにいるかどうかを返す
  bool same(int x,int y)
  {
    return find(x) == find(y);
  }

  //xの属する木のサイズを探す
  int usize(int x)
  {
    return size[find(x)];
  }
};
int main()
{
  int n;cin >> n;
  vector<int> x(n), y(n);
  rep(i,n) cin >> x[i] >> y[i];

  int M = 1e+5;
  rep(i,n) {
    y[i] += M;
  }

  UFT uf(2*M+1);
  rep(i,n) {
    uf.unite(x[i], y[i]);
  }

  vector<ll> sumx(2*M+1, 0), sumy(2*M+1, 0);
  rep(i,2*M+1) {
    if(i <= M) sumx[uf.find(i)]++;
    else sumy[uf.find(i)]++;
  }

  ll res = 0;
  rep(i,2*M+1) {
    res += sumx[i]*sumy[i];
  }

  res -= n;
  cout << res << "\n";
  
  return 0;
}


Measured memory_bytes: 6528
num = int(input())
Lucas_num = []
for i in range(87):
    if i == 0:
        Lucas_num.append(2)
    elif i == 1:
        Lucas_num.append(1)
    else:
        Lucas_num.append(Lucas_num[i - 2] + Lucas_num[i - 1])

print(Lucas_num[num])


Measured memory_bytes: 38256
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<ll,ll> ii;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define RST(i,n) memset(i,n,sizeof i)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define X first
#define Y second
#define mkp make_pair
#define pb push_back
#define eb emplace_back
#define pob pop_back
#ifdef cold66
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<", ";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // cold66
//}
template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;

const ll MAXn=1e5+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=0x3f3f3f3f;

ll a[MAXn],b[MAXn];
int main(){
  IOS();
  ll n,k;
  cin>>n>>k;
  REP(i,n) cin>>a[i]>>b[i];
  ll ans = 0;
  REP(i,n)if( (a[i]&k)==a[i] ) ans+=b[i];
  REP(i,31){
    ll tmp = (1<<i);
    if( k&tmp ){
      ll sum = 0;
      ll x = (k^tmp)|(tmp-1);
      REP(j,n)if( (a[j]&x)==a[j] ) sum+=b[j];
      chkmax(ans,sum);
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 1792
a,b,m = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

ans = min(A)+min(B)
for i in range(m):
    x,y,c = map(int,input().split())
    ans = min(ans, A[x-1] + B[y-1] - c)
print(ans)

Measured memory_bytes: 18608
main = do
    s <- getLine
    putStrLn $ mani s ""
    
mani :: String -> String -> String
mani str res
    | str == []				= res
    | head str == '0'		= mani ( tail str) (res ++ "0")
    | head str == '1'		= mani ( tail str) ( res ++ "1")
    | length res == 0		= mani ( tail str) res
    | otherwise				= mani ( tail str) ( init res)

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

int main(){
  int a[2],b[2];
  cin >> a[0] >> a[1] >> b[0] >> b[1];
  int ans = min(a[1],b[1])-max(a[0],b[0]);
  if(ans <0)cout << 0 << endl;
  else cout << ans << endl;
}


Measured memory_bytes: 256
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        return [[]]*num
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))

#################

from bisect import bisect_left

N = I()
A = III()
A.sort()

val = []
num = []
before = 0
for a in A:
    if a != before:
        val.append(a)
        num.append(1)
        before = a
    else:
        num[-1] += 1

ans = 0

for i in range(N)[::-1]:
    s = math.floor(math.log(2*A[i],2))
    p = bisect_left(val,2**s-A[i])
    if A[i]==2**s-A[i]:
        if num[p]>=2:
            ans += 1
            num[p] -= 2
    else:
        j = bisect_left(val,A[i])
        if p<=len(val)-1:
            if val[p]==2**s-A[i] and num[j] and num[p]:
                ans += 1
                num[j] -= 1
                num[p] -= 1

print(ans)

Measured memory_bytes: 104396
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  string s;
  cin >> s;
  s[3] = '8';
  cout << s << endl;
}

Measured memory_bytes: 3628
#include <array>
#include <iostream>
#include <string>

using namespace std;

static string BAD = "Bad";
static string GOOD = "Good";

int main() {
  int n;
  scanf("%d", &n);

  array<bool, 10> m = {false};
  
  string result = "";

  for (int i = 0; i < 4; i++) {
    int d = n % 10;
    n /= 10;
    if (m[d]) {
      result = BAD;
      break;
    } else {
      m.fill(false);
      m[d] = true;
      result = GOOD;
    }
  }

  cout << result << endl;
  
  return 0;
}


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

int main()
{
    int x, i;
    i = 1;
    x = 1;

    while(1){
        cin >> x;
        if(x == 0) break;
        cout << "Case" << ' ' << i << ':' << ' ' << x << endl;
        i++;
    }

    return 0;
}

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

int dp[1024][1000];
string S[11];

int main() {
	int H, W, K;
	cin >> H >> W >> K;
	for (int i = 0;i < H;i++) {
		cin >> S[i];
	}

	int ans = 0, c, n, fans = INT32_MAX;
	int B[11], R[11];
	for (int i = 0;i < 11;i++)B[i] = R[i] = 0;
	bool p, imp;

	for (int i = 0;i < (1 << (H - 1));i++) {
		c = 0;
		ans = 0;
		for (int k = 0;k < H;k++)B[k] = 0;
		for (int j = 0;j < W;j++) {
			c = 0, n = 0, p = 0, imp = 0;
			for (int k = 0;k < H;k++) {
				if (S[k][j] == '1')R[k] = 1;
				else R[k] = 0;
			}
			for (int k = 0;k < H - 1;k++) {
				c += B[k] + R[k];
				n += R[k];
				if (i & (1 << k)) {
					if (c > K) {
						if (n > K) {
							//不可能
							imp = 1;
						}
						else {
							//直前に仕切りを設けろ
							p = 1;
						}
					}
					c = 0;
					n = 0;
				}
			}
			c += B[H - 1] + R[H - 1];
			n += R[H - 1];
			if (c > K) {
				if (n > K) {
					//不可能
					imp = 1;
				}
				else {
					//直前に仕切りを設けろ
					p = 1;
				}
			}

			if (imp) {
				break;
			}

			if (p) {
				ans++;
				for (int k = 0;k < H;k++) {
					B[k] = R[k];
					R[k] = 0;
				}
			}
			else {
				for (int k = 0;k < H;k++) {
					B[k] += R[k];
					R[k] = 0;
				}
			}
		}

		if (!imp) {
			c = 0;
			for (int k = 0;k < H - 1;k++) {
				if (i & (1 << k))c++;
			}
			fans = min(ans + c, fans);
		}
	}
	cout << fans << endl;
}

Measured memory_bytes: 256
s = input()
answer = 0
sumList = []
numStr = ""
if len(s) == 1:
  print(s)
else:
  for i in range(2**(len(s)-1)):
    bit = "0" + str(len(s) - 1) + "b"
    iStr = format(i, bit)
    numStr += s[0]
    for j in range(len(iStr)):
      if iStr[j] == "1":
        sumList.append(int(numStr))
        numStr = s[j+1]
      else:
        numStr += s[j+1]
    sumList.append(int(numStr))
    numStr = ""
    answer += sum(sumList)
    sumList = []
  print(answer)

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

using namespace std;

using Int  = int_fast64_t;
using UInt = uint_fast64_t;

template <typename T>
using vec1 = vector<T>;

template <typename T>
T cin2var()
{
    T val;
    cin >> val;
    return val;
}

template <typename T>
vec1<T> cin2vec(size_t size)
{
    vec1<T> vec1(size);
    for (auto& v : vec1) {
        v = cin2var<T>();
    }
    return vec1;
}

void sub()
{
    const auto S(cin2var<string>());
    const vector<string> weeks{
        "SUN",
        "MON",
        "TUE",
        "WED",
        "THU",
        "FRI",
        "SAT",
    };
    const auto ite(find(weeks.begin(), weeks.end(), S));
    cout << 7 - (ite - weeks.begin()) << endl;
}

int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    sub();
    return 0;
}

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

bool vec_find(vector<int> vec, int n) {
    for (int i = 0; i < vec.size(); i++) {
        if (vec.at(i) == n) {
            return true;
        }
    }
    
    return false;
}

int main() {
  int x, y;
  cin >> x >> y;

  vector<int> vec_1;
  vec_1 = {1, 3, 5, 7, 8, 10, 12};
  vector<int> vec_2;
  vec_2 = {4, 6, 9, 11};
  
  if ((vec_find(vec_1, x) && vec_find(vec_1, y)) || (vec_find(vec_2, x) && vec_find(vec_2, y))) {
      cout << "Yes" << endl;
  } else {
      cout << "No" << endl;
  }
}

Measured memory_bytes: 256
import sys
import numpy as np
input = sys.stdin.readline

N,K = list(map(int,input().split()))
p = np.array(list(map(int,input().split())))

pn1 = p - 1

ans = sum(pn1[:K])
spb = ans
for i in range(N-K):
    sp = spb -pn1[i] + pn1[i+K]
    #print(sp,spb,pn1[i],pn1[i+K])
    ans = max(sp,ans)
    spb = sp
print(ans/2+K)



Measured memory_bytes: 50200
#include <algorithm>
#include <climits>
#include <iostream>

using namespace std;

int main() {
  int A, B;
  cin >> A >> B;
  int max = INT_MIN;
  max = std::max(max, A + B);
  max = std::max(max, A - B);
  max = std::max(max, A * B);
  cout << max << endl;
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.IO;
using System.Text;
using System.Collections;
using System.Collections.Generic;
 
class Program{
    static void Main(){
        string s = Console.ReadLine();
        Stack<int> startStk = new Stack<int>(s.Length);
        //Stack<Tuple<int, int>> areaStk = new Stack<Tuple<int, int>>(s.Length / 2);
        Stack<int[]> astk = new Stack<int[]>(s.Length / 2);
        int area = 0;
        int totalArea = 0;
        int currentPosition = 0;
        foreach (char ch in s)
        {
            if(ch == '\\') startStk.Push(currentPosition);
            else if(ch == '/' && startStk.Count() > 0){
                int startPosition = startStk.Pop();
                area = currentPosition - startPosition;
                totalArea += area;
                int areaStart = startPosition;
                //while(areaStk.Count() > 0 && startPosition < areaStk.Peek().Item1){
                while(astk.Count() > 0 && startPosition < astk.Peek()[0]){
                    //var tmp = areaStk.Pop();
                    var tmp = astk.Pop();
                    //areaStart = tmp.Item1;
                    areaStart = tmp[0];
                    //area += tmp.Item2;
                    area += tmp[1];
                }
                //areaStk.Push(Tuple.Create(areaStart, area));
                astk.Push(new int[]{areaStart, area});
            }
            currentPosition++;
        }
        Console.WriteLine(totalArea);
        //Console.Write(areaStk.Count());
        Console.Write(astk.Count());
        //if(areaStack.Count() > 0) Console.Write(" {0}", string.Join(" ", areaStk.Select(val => val.Item2).Reverse()));
        if(astk.Count() > 0) Console.Write(" {0}", string.Join(" ", astk.Select(val => val[1].ToString() ).Reverse().ToArray() ) );
        Console.WriteLine();
    }
}

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

using namespace std;
 
/// ----------------------------- (Debug) ------------------------------
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0); sim > char dud(...);
struct debug {
#ifndef ONLINE_JUDGE
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i));}
sim, class b dor(pair < b, c > d) {ris << "(" << d.first << ", " << d.second << ")";}
sim dor(rge<c> d) {*this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]";}
#else
sim dor(const c&) { ris; }
#endif
};
vector<char*> tokenizer(const char* args) {
	char *token = new char[111]; strcpy(token, args); token = strtok(token, ", ");
	vector<char*> v({token});
	while(token = strtok(NULL,", ")) v.push_back(token);
	return reverse(v.begin(), v.end()), v;
}
void debugg(vector<char*> args) { cerr << "\b\b "; }
template <typename Head, typename... Tail>
void debugg(vector<char*> args, Head H, Tail... T) {
	debug() << " [" << args.back() << ": " << H << "] ";
	args.pop_back(); debugg(args, T...);
}
#define harg(...) #__VA_ARGS__
#ifndef ONLINE_JUDGE
#define dbg(...) { debugg(tokenizer(harg(__VA_ARGS__, \b\t-->Line)), __VA_ARGS__, __LINE__); cerr << endl;}
#else
#define dbg(...) { }
#endif
/// -----------------------------------------------------------------------
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi; 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)    
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define print(x) cout << x << "\n";
#define REP(i,a,b) for(i=a;i<=b;i++)
#define RAP(i,a,b) for(i=a;i>=b;i--)
#define spa <<" "<<
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)x.size()
ll mod=1e9+7;
const int MX=0x3f3f3f3f;

int main(){
	ll n,d,x,y;
	int i;
	cin>>n>>d;
	d*=d;
	int ans=0;
	REP(i,0,n-1){
		cin>>x>>y;
		if(x*x+y*y<=d) ans++;
	}
	cout<<ans;
 	return 0;
}

Measured memory_bytes: 3588
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    a, b = map(int, input().split())
    if b == 1:
        print(0)
        return None

    total = 1
    for i in range(1, 20):
        total += a - 1
        if total >= b:
            print(i)
            return None

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
typedef long long i64;typedef vector<int> ivec;typedef vector<string> svec;

int main(){
	string S;
	cin >> S;
	i64 a = S.size();
	i64 ans = 753;
	i64 s = 0;
	for(i64 i=0;i<a-2;i++){
		s = (S[i]-'0')*100+(S[i+1]-'0')*10+(S[i+2]-'0');
		ans = min(ans,abs(753-s));
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#%%
import sys
def input():
    return sys.stdin.readline().rstrip()

def main():
    N=int(input())
    Hs=[int(x) for x in input().split()]

    h = Hs[N-1]
    for i in range(N-2,-1,-1):
        if Hs[i] > h+1:
            print('No')
            return
        else:
            if Hs[i] < h:
                h = Hs[i]
    else:
        print('Yes')


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

# %%
# from atcoder_test import doTest
# doTest("abc136","c",main)

Measured memory_bytes: 14396
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <cmath>
#include <numeric>

using namespace std;


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

    vector<bool> used(N);
    int now = 0;
    int res = 0;
    while (true) {
        if (used[now]) break;

        res++;
        used[now] = true;
        now = A[now] - 1;
        if (now + 1 == 2) {
            cout << res << endl;
            return 0;
        }
    }

    cout << -1 << endl;
    return 0;
}


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

using namespace std;

typedef long long ll;

int main()
{
    int n;
    scanf("%d",&n); 
    ll ans = 0;
    for(int i=0;i<n;i++)
    {
        int x;
        scanf("%d",&x);
        ans = ans + x - 1;
    }
    printf("%lld\n",ans);
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <set>
#include <stdio.h>
#include <vector>
typedef long long ll;

int main() {
  int n;
  int m;
  std::cin >> n;
  std::vector<int> a;
  for (int i = 0; i < n; i++) {
    int num;
    std::cin >> num;
    a.push_back(num - 1);
  }
  std::vector<ll> pos(n, 0);
  for (int i = 0; i < n; i++) {
    pos[a[i]] = i;
  }

  std::set<int> f_pos;
  std::set<int> r_pos;
  ll ans = 0;
  for (int i = 0; i < n; i++) {
    ll right;
    if (f_pos.lower_bound(pos[i]) != f_pos.end()) {
      right = *f_pos.lower_bound(pos[i]) - pos[i];
    } else {
      right = n - pos[i];
    }
    ll left;
    if (r_pos.lower_bound(n - 1 - pos[i]) != r_pos.end()) {
      left = *r_pos.lower_bound(n - 1 - pos[i]) - (n - 1 - pos[i]);
    } else {
      left = pos[i] + 1;
    }
    // std::cerr << left << ", " << right << ", " << pos[i] << std::endl;

    ans += left * right * (i + 1);
    f_pos.insert(pos[i]);
    r_pos.insert(n - 1 - pos[i]);
  }
  std::cout << ans << std::endl;
}


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

int main() {
  vector<int>uwara(3);
  for(int i = 0; i < 3; i++){
    cin>>uwara[i];
  }
  if (uwara[0]+uwara[1]+uwara[2] >= 22) {
    cout << "bust" << endl;
  }
  else {
    cout << "win" << endl;
  }
}


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

#define mp make_pair
#define pb push_back
#define REP(i,a,n) for(int i = a;i < (n);i++)
#define RREP(i,a) for(int i = a;i >= 0;i--)
#define rep(i,n) for(int i = 0;i < (n);i++)
#define rrep(i,n) for(int i = n - 1;i >= 0;i--)
#define all(s) s.begin(), s.end()
#define rall(s) s.rbegin(), s.rend()
#define range(x,min,max) ((min) <= (x) && (x) <= (max))
#define xyrange(x, minX, maxX, y, minY, maxY) (range(x, minX, maxX) && range(y, minY, maxY))

using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef pair<int,int> PII;
typedef vector<PII> VPII;

const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};
const int INF = 0x3f3f3f3f;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int W, a, b;
    cin >> W >> a >> b;
    if (a < b) {
        if (a + W >= b) {
            cout << 0 << endl;
        } else {
            cout << b - (a + W) << endl;
        }
    } else {
        if (b + W >= a) {
            cout << 0 << endl;
        } else {
            cout << a - (b + W) << endl;
        }
    }
    return 0;
}

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

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(a)-1;i>=b;i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(_v) for(auto _x:_v){cout<<_x<<" ";}cout<<endl
#define printVS(vs) for(auto x : vs){cout << x << endl;}
#define printVV(_vv) for(auto _v:_vv){for(auto _x:_v){cout<<_x<<" ";}cout<<endl;}
#define printP(p) cout << p.first << " " << p.second << endl
#define printVP(vp) for(auto p : vp) printP(p);
#define readV(_v) rep(j, _v.size()) cin >> _v[j];
#define readVV(_vv) rep(i, _vv.size()) readV(_vv[i]);
#define output(_x) cout << _x << endl;

typedef long long ll;
typedef pair<int, int> Pii;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<Pii> vp;
const int inf = 1e9;
const int mod = 1e9 + 7;

struct Rect {
    int r1, c1, r2, c2;
    Rect(){}
    Rect(int _r1, int _c1, int _r2, int _c2) : r1(_r1), c1(_c1), r2(_r2), c2(_c2) {}
    bool includes(double r0, double c0) {
        return r1 <= r0 && r0 <= r2 && c1 <= c0 && c0 <= c2;
    }
};

// N, E, S, W
const int dx[4] = {-1, 0,  1,  0};
const int dy[4] = { 0, 1,  0, -1};

bool inside(int x, int y, int H, int W) {
    return 0 <= x && x < H && 0 <= y && y < W;
}

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

    int n;
    while (cin >> n, n) {
        vector<Rect> rects;
        map<int, int> mp;
        rep(i, n) {
            int l, t, r, b;
            cin >> l >> t >> r >> b;
            rects.emplace_back(b, l, t, r);
            mp[b] = 0;
            mp[l] = 0;
            mp[t] = 0;
            mp[r] = 0;
        }
        mp[-inf] = 0;
        mp[inf] = 0;

        int sz = 0;
        for (auto& p : mp) {
            p.second = sz++;
        }

        rep(i, n) {
            rects[i].r1 = mp[rects[i].r1];
            rects[i].c1 = mp[rects[i].c1];
            rects[i].r2 = mp[rects[i].r2];
            rects[i].c2 = mp[rects[i].c2];
        }

        vvi a(sz, vi(sz, -1));

        auto valid = [&](int i, int j, int ni, int nj) {
            if (!inside(ni, nj, sz, sz)) return false;
            if (a[ni][nj] != -1) return false;
            rep(k, n) {
                if (rects[k].includes(i + 0.5, j + 0.5) ^ rects[k].includes(ni + 0.5, nj + 0.5)) {
                    return false;
                }
            }
            return true;
        };

        std::function<void(int, int, int)> dfs = [&](int i, int j, int color) {
            a[i][j] = color;
            rep(k, 4) {
                int ni = i + dx[k], nj = j + dy[k];
                if (valid(i, j, ni, nj)) {
                    dfs(ni, nj, color);
                }
            }
        };

        int ans = 0;
        rep(r0, sz) {
            rep(c0, sz) {
                if (a[r0][c0] == -1) {
                    dfs(r0, c0, ans++);
                }
            }
        }

        cout << ans << endl;
    }

}

Measured memory_bytes: 4548
# https://atcoder.jp/contests/abc087/tasks/abc087_b
# 2020/02/15
import sys
input = sys.stdin.readline

def main():
    a = int(input())
    b = int(input())
    c = int(input())
    x = int(input())
    ans = 0
    for i in range(a+1):
        if 500 * i > x:
            break
        for j in range(b+1):
            if 500 * i + 100 * j > x:
                break
            for k in range(c+1):
                if 500 * i + 100 * j + 50 * k > x:
                    break
                if 500 * i + 100 * j + 50 * k == x:
                    ans += 1
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <string> 
#include <vector>
#include <iomanip>
#include <math.h>
#include <map>
using namespace std;

int main()
{
	int X, A, B;
	cin >> X >> A >> B;
	cout << (X - A) % B << endl;
}

Measured memory_bytes: 256