akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <cmath>

int main()
{
	std::string a, b;
	std::cin >> a >> b;

	int n = std::stoi( a + b );
	int sq = std::sqrt( n );

	std::cout << ( sq * sq == n ? "Yes" : "No" ) << std::endl;
	return 0;
}



Measured memory_bytes: 256
n = int(input())
data = []
for i in range(n):
    temp = list(input().split(" "))
    s = temp[0]
    p = int(temp[1])
    data.append([s,-p,i+1])
data.sort(key = lambda x:(x[0],x[1]))
for i in range(n):
    print(data[i][2])

Measured memory_bytes: 3060
s=list(input())
k=int(input())
#print(s,k)
for i in range(len(s)):
    if s[i]=='1' and i<=k-2:
        continue
    elif s[i]=='1' and i==k-1:
        print(1)
        break
    elif s[i]!='1' :
        print(s[i])
        break

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

int main(){
  int N,K;
  long long sum=0;
  cin >> N >> K;
  vector<int> H(N);
  for(int i=0;i<N;i++){
    cin >> H.at(i);
  }
  sort(H.begin(),H.end());
  reverse(H.begin(),H.end());
  for(int i=K;i<N;i++){
    sum+=H.at(i);
  }
  cout << sum << endl;
} 

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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

constexpr int atcoder_mod = 1e9+7;

using namespace std;
using ll = long long;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

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

	int N=in();
	auto R=vecin<ll>(N);
	vector<ll> MINR(N),MAXR(N),SUB(N,-(1LL<<50));
	REP(i,N){
		if(!i){
			MINR[i] = R[i];
			MAXR[N-1] = R[N-1];
			SUB[i] = 0;
		}
		else{
			MINR[i] = min(R[i],MINR[i-1]);
			MAXR[N-1-i] = max(R[N-i-1],MAXR[N-i]);
		}
	}
	REP(i,N-1){
		SUB[i] = MAXR[i+1]-MINR[i];
	}
	
	out(*max_element(ALL(SUB)));
	return 0;
}



Measured memory_bytes: 9128
#include <iostream>
#include <string>
using namespace std;
 
int main(){
  int N,K;
  cin >> N>>K;
  
  string S;
  cin >> S;
  
  if(S[K-1]=='A'){
    S[K-1] ='a';
  }else if(S[K-1]=='B'){
    S[K-1] ='b';
  }else if(S[K]=='C'){
    S[K-1] ='c';
  }
  
  cout << S << endl;
  
}

Measured memory_bytes: 256
#include<bits/stdc++.h> 
using namespace std;
typedef long long ll;
template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;}
template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;}
int dx[4]={0,1,-1,0};
int dy[4]={1,0,0,-1};
long double eps = 1e-9;
long double pi = acos(-1);

ll mod = 1e9+7;
template<typename T> void add(T &a,T b){a=(a+b)%mod;}
template<typename T> void sub(T &a,T b){a=(a+mod-b)%mod;}

template<typename T>
struct BIT{
    vector<T> bit;
    BIT(int n) : bit(n+1) {}
    void add(int a,T w){
        for(int x=++a; x < bit.size(); x+=(x&(-x)) ){
            bit[x] += w;
        }
    }
    // return v[0]+v[1]+...+v[a-1];
    T sum(int a){
        T ret=0;
        for(int x=a;x>0;x-=(x&(-x)) ){
            ret+=bit[x];
        }
        return ret;
    }
};

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);


    ll n;
    ll mod = 998244353;
    cin>>n;
    int x[n],y[n];
    array<int,2>  a[n];
    for(int i=0;i<n;i++){
        cin>>x[i]>>y[i];
        a[i] = {x[i],y[i]};
    }
    sort(a,a+n);
    sort(x,x+n);
    sort(y,y+n);
    ll beki[n+1]={};
    beki[0] = 1;
    for(int i=1;i<=n;i++){
        beki[i] = (beki[i-1]*2)%mod;
    }
    ll ans = 0;
    for(int i=0;i<n;i++){
        //cerr << a[i][0] << " " << a[i][1] << endl;
        ans += (beki[i]*4) % mod;
        // ans += ((beki[i]+mod-1)%mod*4)%mod;
        ans %= mod;
    }
    ans = mod - ans;
    ans %= mod;
    BIT<int> b(n+1);
    for(int i=0;i<n;i++){
        int now = lower_bound(y,y+n,a[i][1]) - y;
        int low = b.sum(now);
        int up = b.sum(n) - low;
        //ans += mod - beki[i] + mod - beki[n-1-i] + mod - beki[now] + mod - beki[n-now-1] + mod;
        ans %= mod;
        ans += beki[low] + beki[up] + beki[now-low] + beki[n-now-up-1] + mod;
        ans %= mod;
        b.add(now,1);
        //cerr << i << " " << now << " " << low << " " << up << " " << now-low << " " << n-now-up-1 << endl; 
    }
    ans += n*beki[n];
    ans %= mod;
    ans += mod - n;
    ans %= mod;
    cout << ans << endl;
    
}

Measured memory_bytes: 5760
#include<iostream>
#include <list>
#include<stack>
#include<queue>
#include <vector>
#include <set>
#include<algorithm>
#include<math.h>
#include<stdlib.h>
#include<string>
#include <functional>
#include<fstream>

#define FOR(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define LL long long
#define CLR(a) memset((a),0,sizeof(a))
#define SZ(x) (int((x).size()))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<<str<<endl
using namespace std;

const LL MOD = 1000000007;// 10^9+7
const int INF = (1 << 30);


//変数
LL goal;






//サブ関数
//入力
void input()
{
	cin >> goal;
	goal--;//0-indexedに変換
}

//貪欲に解けるときは解いてしまう
void greedy()
{
	LL cnt = 1;
	string res = "";
	while (res.size() < goal + 20) 
	{
		if (cnt % 15 == 0) res += "FizzBuzz";
		else if (cnt % 3 == 0)res += "Fizz";
		else if (cnt % 5 == 0)res += "Buzz";
		else res += to_string(cnt);
		cnt++;
	}
	
	cout << res.substr(goal, 20) << endl;
}

LL pow2(LL l, LL r)
{
	LL res = 1;
	REP(i, r)res *= l;
	return res;
}

//9*10^(exp-1)だけ、FizzBuzzを進めます
bool step(const LL& exp, LL& start, LL& len)
{
	LL n = to_string(start + 1).size();
	LL progress = (48 * n + 192)*pow2(10, exp - 1);

	if (len + progress < goal) {
		start += 9 * pow2(10, exp);
		len += progress;
		return true;
	}
	else {
		return false;
	}
}

void expUp(LL& exp, LL& start, LL& len)
{
	while (step(exp, start, len))exp++;
}
void expDown(LL& exp, LL& start, LL& len)
{
	while (exp > 0) {
		while (step(exp, start, len));
		exp--;
	}
}
void output(LL& exp, LL& start, LL& len)
{
	string res = "";
	//start++;

	while (res.size() < goal - len + 20) {
		if (start % 15 == 0)res += "FizzBuzz";
		else if (start % 3 == 0)res += "Fizz";
		else if (start % 5 == 0)res += "Buzz";
		else res += to_string(start);
		start++;
	}

	cout << res.substr(goal - len+1, 20) << endl;
}

//計算
void calc()
{
	if (goal < 1000) {
		greedy();
	}
	else {
		LL last = 9;//FizzBuzzの末端
		LL len = 18;//FizzBuzz[1,last]の文字列長
		LL exp = 1; //着目する進み度合い
		expUp(exp, last, len);
		expDown(exp, last, len);
		output(exp, last, len);
	}
}



//デバッグ
void debug()
{
	int N;
	cin>>N;
}


//メイン関数
int main()
{
	input();
	calc();
	debug();
	
	return 0;
}



Measured memory_bytes: 3288
import numpy as np
 
N, D = input().strip().split() #1行目のNを取得する
grid = []
for i in range(int(N)):
    array = list(map(int, input().strip().split()))
    grid.append(array)
grid = np.array(grid)
p = 0
for i in range(int(N)):
  if np.sqrt(grid[i,0]*grid[i,0] + grid[i,1]*grid[i,1]) <= int(D):
    p += 1
print(p)

Measured memory_bytes: 66600
# coding: utf-8
N = int(input())
anslist = []
ret = []
for i in range(N):
    A = int(input())
    tmp = []
    for j in range(A):
        X = list(input().split())
        tmp.append(X)
    anslist.append(tmp)

for i in range(2**N):
    ans = 0
    op = []
    for j in range(N):
        if ((i >> j) & 1) == 1:
            op.append("1")
        else:
            op.append("0")
    
    flag = 0
    for j in range(N):
        if op[j] == "1":
            for k in anslist[j]:
                if op[int(k[0])-1] != k[1]:
                    flag = 1
    if flag == 0:
        ret.append(op.count("1"))

print(max(ret))

Measured memory_bytes: 3444
#include <stdio.h>
#include <math.h>

int main(void){
 int n;
  int s[105];
  int ans=0;
  scanf("%d", &n);
  for(int i=0;i<n;i++){
    scanf("%d", &s[i]);
  }
  
  
  for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
      for(int l=j+1;l<n;l++){      
         if((s[i]+s[j]>s[l])&&(s[l]+s[j]>s[i])&&(s[i]+s[l]>s[j])&&s[i]!=s[j]&&s[i]!=s[l]&&s[j]!=s[l]){
           ans = ans+1;
         }
      }
    }           
  }
  
  printf("%d", ans);
 
  
  return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

bool eq(char a,char b){
  return (a=='?')|(b=='?')|(a==b);
}

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

  const int m=4010;

  string a,b,c;
  cin>>a>>b>>c;
  int la=a.size(),lb=b.size(),lc=c.size();
  vector<int> sb,sc,sbc;
  unordered_map<int,bool> aru;
  repl(s0,-m,m+1){
    bool ok=true;
    rep(i,la){
      if(i-s0>=0&&i-s0<lb&&!eq(a[i],b[i-s0]))ok=false;
    }
    if(ok){
      sb.push_back(s0);
    }
  }
  repl(s1,-m,m+1){
    bool ok=true;
    rep(i,la){
      if(i-s1>=0&&i-s1<lc&&!eq(a[i],c[i-s1]))ok=false;
    }
    if(ok){
      sc.push_back(s1);
      aru[s1]=true;
    }
  }
  repl(s2,-m,m+1){
    bool ok=true;
    rep(i,lb){
      if(i-s2>=0&&i-s2<lc&&!eq(b[i],c[i-s2]))ok=false;
    }
    if(ok){
      sbc.push_back(s2);
    }
  }

  int res=la+lb+lc;
  for(int s0 : sb){
    for(int s2 : sbc) {
      if(aru[s0+s2]){
        int mn=min({s0,0,s0+s2});
        int mx=max({s0+lb,la,s0+s2+lc});
        minch(res,mx-mn);
      }
    }
  }
  cout<<res<<endl;

  return 0;
}


Measured memory_bytes: 1152
#include <iostream>

using namespace std;

int main() {
  int n, m, x;
  int a[110];
  cin >> n >> m >> x;
  for (int i = 0; i < m; i++) {
    cin >> a[i];
  }
  int l = 0;
  int r = 0;
  for (int i = 0; i < m; i++) {
    if (a[i] < x) {
      l++;
    } else if (x < a[i]) {
      r++;
    }
  }
  cout << min(l, r) << endl;
  return 0;
}


Measured memory_bytes: 3140
#include<bits/stdc++.h>
using namespace std;
int main(){
	map<long long,long long> p{{2,0},{3,0},{5,0}};
	int n=1000;
	cin>>n;
	for(int i=7;i<=1000;++i){
		bool pr=true;
		for(int j=2;j!=i;++j){
			if(!(i%j)){
				pr=false;
				break;
			}
		}
		if(pr)
			p.insert({i,0});
	}
	for(int i=1;i<=n;++i){
		int k=i;
		auto it=p.begin();
		while(k!=1){
			while(k!=1 && !(k%it->first)){
				++it->second;
				k/=it->first;
			}
			++it;
		}
	}
	long long ans=1;
	for(auto i:p){
		if(i.second)
			ans*=(i.second+1);
		if(ans>1E9+7)
			ans%=int(1E9+7);
	}
	cout<<ans<<endl;

}

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

int main(){
	int N;
	int A[100];
	
	scanf("%d", &N);
	for(int i = 0; i < N; i++){
		scanf("%d", &A[i]);
	}
	
	bool flag = true;
	int tmp;
	int count = 0;
	while(flag){
		flag = false;
		for(int i = N -1; i >= 1; i--){
			if(A[i] < A[i-1]){
				tmp = A[i];
				A[i] = A[i-1];
				A[i-1] = tmp;
				flag = true;
				count++;
			}
		}
	}
	
	for(int i = 0; i < N; i++){
		printf("%d", A[i]);
		if(i != N-1) putchar(' ');
	}
	putchar('\n');
	printf("%d\n", count);
	
	return 0;
}

Measured memory_bytes: 1192
#include <iostream>
#include <string>
#include <vector>

struct st{
    int w, v;
};

using namespace std;

void knap(){
    vector<st> structs;
    int n,w;
    cin>>n>>w;
    long maxVal[n+1][w+1];
    structs.push_back({0,0});
    for (int i = 0; i < n; i++) {
        int wt, vl;
        cin>> wt >> vl;
        structs.push_back({wt,vl});
    }
    for (int i = 0; i <= w; i++) {
        maxVal[0][i]=0;
    }
    for (int i = 0; i <= n; i++) {
        maxVal[i][0]=0;
    }
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= w; j++) {
            if(j < structs[i].w){
                maxVal[i][j] = maxVal[i-1][j];
            }else{
                maxVal[i][j] = max(maxVal[i-1][j], maxVal[i-1][j-structs[i].w]+ structs[i].v);
            }
        }
    }
    cout<<maxVal[n][w];
}
int main()
{
    knap();
}


Measured memory_bytes: 79104
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <class T> using treap = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define int long long
#define REP(i, n) for (long long i = 0, max_i = (n); i < max_i; i++)
#define REPI(i, a, b) for (long long i = (a), max_i = (b); i < max_i; i++)
#define ALL(obj) begin(obj), end(obj)
#define RALL(obj) rbegin(obj), rend(obj)
#define fi first
#define se second
using ii = pair<int, int>;
vector<ii> dirs = {
  {1, 0}, {0, 1}, {-1, 0}, {0, -1},  // 4方向
  {1, 1}, {-1, 1}, {-1, -1}, {1, -1},  // 斜め
  {0, 0},  // 自身
};
template <class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }
template <class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
template <class T, class S> vector<T> make_vec(size_t n, S x) { return vector<T>(n, x); }
template <class T, class... Ts> auto make_vec(size_t n, Ts... ts) { return vector<decltype(make_vec<T>(ts...))>(n, make_vec<T>(ts...)); }

// debug
template <class T> ostream& operator<<(ostream& s, vector<T>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : " "); return s; }
template <class T> ostream& operator<<(ostream& s, vector<vector<T>>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : "\n"); return s; }
template <class T, class S> ostream& operator<<(ostream& s, pair<T, S>& p) { s << "{" << p.first << ", " << p.second << "}"; return s; }
template <class T, class S> ostream& operator<<(ostream& s, map<T, S> m) { for (auto it = m.begin(); it != m.end(); it++) { s << *it << (next(it) == m.end() ? "" : "\n"); } return s; }
template <class T, class S> ostream& operator<<(ostream& s, unordered_map<T, S> m) { for (auto it = m.begin(); it != m.end(); it++) { s << *it << (next(it) == m.end() ? "" : "\n"); } return s; }
#ifdef _MY_DEBUG
  #define dump(...) cerr << "/* " << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" << endl, dump_func(__VA_ARGS__), cerr << "*/\n\n";
#else
  #define dump(...)
  #define endl "\n"
#endif
void dump_func() { cerr << endl; }
template <class Head, class... Tail> void dump_func(Head&& h, Tail&&... t) { cerr << h << (sizeof...(Tail) == 0 ? "" : ", "), dump_func(forward<Tail>(t)...); }

struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); } } fast;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
constexpr int MOD = 1000000007;
// *************** TEMPLATE END *************** 

signed main() {
  int n; cin >> n;
  vector<int> a(n), b(n);
  REP (i, n) cin >> a[i] >> b[i];
  vector<int> ord(n);
  REP (i, n) ord[i] = i;
  sort(ALL(ord), [&](int i, int j) {
    return b[i] < b[j];
  });
  int acc = 0;
  REP (i, n) {
    int k = ord[i];
    acc += a[k];
    if (acc > b[k]) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}


Measured memory_bytes: 4992
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_A main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
// functions
ll gcd(ll a, ll b) {
    if (b == 0) return a;
    return gcd(b, a%b);
}

ll lcm(ll a, ll b) {
    ll g = gcd(a, b);
    return a / g * b;
}
#endif


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

    int N; cin >> N;
    vi a(N);  REP(i,N) cin >> a[i];
    a.push_back(-1);

    vi c;
    int len = 1;
    FOR(i,1,N+1) {
        if (a[i] == a[i-1]) {
            len++;
        } else {
            c.push_back(len);
            len = 1;
        }
    }

    int ans = 0;
    REP(i,c.size()) {
        ans += c[i] / 2;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
n = int(input())
as_ = map(int, input().strip().split())

data = [0] * 100002

for a in as_:
    data[a] += 1

max_count = 0
for i in range(1, 100001):
    count = data[i - 1] + data[i] + data[i + 1]
    max_count = max(count, max_count)

print(max_count)


Measured memory_bytes: 10124
// https://atcoder.jp/contests/abcXXX/tasks/abcXXX_x

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ull = unsigned long long;
using pll = pair<ll, ll>;

static const ll INF = 1001001001;
static const ll LLINF = 1001001001001001001;
static const ll MOD = (ll)1e9 + 7;
static const double EPS = 1e-9;

#define REP(i, n) for(ll i = 0; i < static_cast<ll>(n); ++i)
#define RANGE(i, m, n) for(ll i = (m); i <= static_cast<ll>(n); ++i)
#define RRANGE(i, m, n) for(ll i = static_cast<ll>(m); i >= static_cast<ll>(n); --i)
#define POSITIVE(x) (x)=((x) < 0) ? 0 : (x)

ll power(ll x, ll y) {
    ll ret = 1;
    while(y-- > 0) ret *= x;
    return ret;
}

ll gcd(ll a, ll b) {
    assert(a >= 0);
    assert(b >= 0);
    if (b == 0) return a;
    return gcd(b, a % b);
}

ll extgcd(ll a, ll b, ll& x, ll& y) {
    x = 1; y = 0;
    assert(a >= 0);
    assert(b >= 0);
    if (b == 0) return a;
    ll X, Y;
    auto d = extgcd(b, a % b, X, Y);
    x = Y;
    y = X - (a / b) * Y;
    return d;
}

vector<bool> visited{};

ll dfs(vector<vector<ll>>& g, ll next) {
    ll cnt = 1;
    visited[next] = true;
    for(auto x : g[next]) {
        if(! visited[x]) {
            cnt += dfs(g, x);
        }
    }
    return cnt;
}

int run(istream& in, ostream& out) {
    ll N, M;
    in >> N >> M;
    vector<vector<ll>> g{};
    visited.resize(N, false);
    g.resize(N);
    REP(i, M) {
        ll a, b;
        in >> a >> b;
        --a;
        --b;
        g[a].emplace_back(b);
        g[b].emplace_back(a);
    }
    ll max_count = 0;
    REP(i, N) {
        if(! visited[i]) {
            max_count = max(max_count, dfs(g, i));
        }
    }
    out << max_count << endl;
    return 0;
}

int main() {
    return run(cin, cout);
}


Measured memory_bytes: 23524
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		try (Scanner sc = new Scanner(System.in)) {
			String s = sc.next();
			String t = new String();
			int ans = Integer.MAX_VALUE;
			int tmp = 0;
			int dif = 0;
			int n = s.length();
			
			for (int i = 0; i < n - 2; i++) {
				t = s.substring(i, i + 3);
				tmp = Integer.parseInt(t);
				dif = Math.abs(753 - tmp);
				if (dif < ans) {
					ans = dif;
				}
			}
			System.out.println(ans);
		}
	}
}


Measured memory_bytes: 21716
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include <map> 


using namespace std;

struct three {
    string   first;
    int second;
    int third;

};

bool compare_by_b(three a, three b) {
    if(a.first != b.first){
        return a.first < b.first;
    }else{
        return a.second > b.second;
    }
}

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

    string S[N];
    int P[N];
    vector<three> map;
    
    for(int i = 0; i < N; i++){
        cin >> S[i] >> P[i];
        three tmp;
        tmp.first = S[i];
        tmp.second = P[i];
        tmp.third = i+1;
        map.push_back(tmp);
        }

    sort(map.begin(), map.end(), compare_by_b);
    
    //cout << "start\n";
    for(int i = 0; i < N; i++){
        //cout << map[i].first;
        cout << map[i].third << endl;
    }

}

Measured memory_bytes: 256
n, a, b = map(int, input().split())
s = input()
overseas = 0
student = 0
for i in range(n):
    if s[i] == "a":
        if a + b > student:
            print("Yes")
            student += 1
        else:
            print("No")
    if s[i] == "b":
        if a + b > student and overseas < b:
            print("Yes")
            overseas += 1
            student += 1
        else:
            print("No")
    if s[i] == "c":
        print("No")

Measured memory_bytes: 55000
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
/*------------------junk----------------------*/
typedef long long int lli;
typedef unsigned long long int ulli;
const int MOD = 1e9 + 7;
#define ff first
#define ss second
#define gc getchar_unlocked
#define fri(i, j , n) for (auto (i) = (j); (i) < (n); ++(i))
#define frie(i, j , n) for (auto (i) = (j); (i) <= (n); ++(i))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define f2a(x , n , v)  fill(&(x)[0][0], &(x)[0][0] + (0 + n) *(0 + n) , (v))
#define fa(x , n , v) fill( (x), (x)+(n), (v)) 
#define pb emplace_back
#define mp make_pair
#define getchar_unlocked getchar
# define TMP template<typename
#ifdef LOCAL 
template < class c > struct rge { c b, e; };
template < class c > rge<c> range(c i, c j) { return rge<c>{i, j}; }
template < class c > auto dud(c* x) -> decltype(cerr << *x, 0);
template < class c > char dud(...);
struct debug {
    
    ~debug() { cerr << endl; }
    template < class c > typename enable_if<sizeof dud<c>(0) != 1, debug&>::type operator<<(c i) { cerr << boolalpha << i; return * this; }
    template < class c > typename enable_if<sizeof dud<c>(0) == 1, debug&>::type operator<<(c i) { return * this << range(begin(i), end(i)); }
    template < class c, class b > debug & operator <<(pair < b, c > d) {
        return * this << "(" << d.first << ", " << d.second << ")";
    }
    template < class c > debug & operator <<(rge<c> d) {
        *this << "[";
        for (auto it = d.b; it != d.e; ++it)
            *this << ", " + 2 * (it == d.b) << *it;
        return * this << "]";
    }};
#define oo(...) __f(#__VA_ARGS__, __VA_ARGS__)
TMP Arg1>
void __f(const char *name, Arg1 &&arg1)
{cout << name << ": " << arg1 << "\n";}
TMP Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args)
{const char *comma = strchr(names + 1, ',');cout.write(names, comma - names) << ": " << arg1 << " |";__f(comma + 1, args...);
}
void in(int &x){
    cin  >> x;
}
#else
inline void in(int &x)
    {
    register int c = getchar_unlocked();
    x = 0;
    int neg = 0;
    for(;((c<48 || c>57) && c != '-');c = getchar_unlocked());
    if(c=='-') {neg=1;c=getchar_unlocked();}
    for(;c>47 && c<58;c = getchar_unlocked()) {x = (x<<1) + (x<<3) + c - 48;}
    if(neg) x=-x;
    }
inline void uin(ulli &n){
    register ulli c=gc();
    n=0;
    while(c<'0'||c>'9')
    c=gc();
    while(c<='9'&&c>='0'){
    n=n*10+c-'0';
    c=gc();}
}
#endif
/*----------check constraints again-------------*/

int32_t main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
    int n,k,tmp , c=0;
    in(n);
    in(k);
    fri(i,0,n) {
    in(tmp);
        if(tmp >= k) {
            c++;
        }
    }
    cout << c;
}























Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define next Next
#define gc getchar
#define int long long
const int N=1e6+5;
int n,m,top,b[N],vis[N],val[N],head[N],fa[N];
struct node{
	int x,y;
}a[N];
struct E{
	int too,next,zh;
}edge[N*2];
vector<int>g;
//char buf[1<<21],*p1=buf,*p2=buf;
//inline int gc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}
inline int read()
{
    int ret=0,f=0;char c=gc();
    while(!isdigit(c)){if(c=='-')f=1;c=gc();}
    while(isdigit(c)){ret=ret*10+c-48;c=gc();}
    if(f)return -ret;return ret;
}
int find(int x)
{
	if(fa[x]==x)return x;
	fa[x]=find(fa[x]);
	return fa[x];
}
bool cmp(node a,node b)
{
	return a.x<b.x;
}
void add(int a,int b,int c)
{
	edge[++top].too=b;edge[top].zh=c;
	edge[top].next=head[a];head[a]=top;
}
int dfs(int u)
{
	int res=val[u];
	vis[u]=1;
	for(int i=head[u];i;i=edge[i].next)
	{
		int v=edge[i].too,w=edge[i].zh;
		if(vis[v])continue;
		int x=dfs(v);
		if(x)
		{
			g.push_back(w);
			res^=1;
		}
	}
	return res;
}
signed main()
{
	n=read();m=read();
	for(int i=1;i<=n+1;i++)fa[i]=i;
	for(int i=1;i<=n;i++)
	{
		a[i].x=read();a[i].y=read();
	}
	sort(a+1,a+n+1,cmp);
	for(int i=1;i<=n;i++)b[i]=a[i].x;
	for(int i=1;i<=n;i++)val[i]=a[i].y^a[i-1].y;
	for(int i=1;i<=m;i++)
	{
		int l=read(),r=read();
		l=lower_bound(b+1,b+n+1,l)-b;
		r=upper_bound(b+1,b+n+1,r)-b;
		int x=find(l),y=find(r);
		if(x==y)continue;
		add(l,r,i);
		add(r,l,i);
		fa[x]=y;
	}
	dfs(n+1);
	for(int i=1;i<=n;i++)
	{
		if(vis[i])continue;
		if(dfs(i)==1)
		{
			puts("-1");
			return 0;
		}
	}
	sort(g.begin(),g.end());
	cout<<g.size()<<endl;
	for(int i=0;i<g.size();i++)printf("%lld ",g[i]);
	return 0;
}

Measured memory_bytes: 25592
#include<bits/stdc++.h>
#define LL long long
#define FOR(i,a,b) for(int i=a;i<=b;++i)
using namespace std;

const int mn=1e5+7;

int main()
{
	int a,b;
	scanf("%d%d",&a,&b);
	puts(b>=a?"unsafe":"safe");
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
typedef long long ll;
#define INF 1000000000
#define MOD 1000000007
int dx[4]={1,0,-1,0},dy[4]={0,-1,0,1};
using namespace std;
int main(void){
    int a,b,c,x,y;
    cin>>a>>b>>c>>x>>y;
    ll ans=0;
    if(2*c<=a+b and 2*c<=a and 2*c<=b){
        ans=2*c*max(x,y);
    }else if(2*c<=a+b){
        ans=2*c*min(x,y);
        if(x<=y){
            ans+=(y-x)*min(b,2*c);
        }else{
            ans+=(x-y)*min(a,2*c);
        }
    }else{
        ans=x*a+y*b;
    }
    cout<<ans<<endl;
 return 0;   
}

Measured memory_bytes: 256
# 見かけたのでやる
# やるだけ
# インプットの順番をidで保存しておいてyでソートしてpでソートしてidでソートして復元
n, m = map(int, input().split())
arr = []
for i in range(m):
    p, y = map(int, input().split())
    arr.append([i, p, y])

arr = list(sorted(arr, key=lambda x: x[2]))
arr = list(sorted(arr, key=lambda x: x[1]))
# print(arr)
flag = -1
count = 1
for a in arr:
    if a[1] != flag:
        flag = a[1]
        count = 1
    a[2] = "%06d" % count
    a[1] = "%06d" % a[1]
    count += 1
arr = list(sorted(arr, key=lambda x: x[0]))
for a in arr:
    print("{}{}".format(a[1], a[2]))



Measured memory_bytes: 37620
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <functional>
using namespace std;

typedef long long ll;

double d[1005][1005];
ll x[1003], y[1003], r[1003];
bool used[1005];

int main() {
	ll xs, ys, xt, yt; cin >> xs >> ys >> xt >> yt;
	int n; cin >> n;
	x[0] = xs; y[0] = ys; r[0] = 0;
	x[n + 1] = xt; y[n + 1] = yt; r[n + 1] = 0;
	for (int i = 1; i <= n; ++i) cin >> x[i] >> y[i] >> r[i];
	for (int i = 0; i <= n + 1; ++i) {
		for (int j = 0; j <= n + 1; ++j) {
			if (i == j) continue;
			d[i][j] = sqrt((x[i] - x[j])*(x[i] - x[j]) + (y[i] - y[j])*(y[i] - y[j])) - r[i] - r[j];
			if (d[i][j] < 0) d[i][j] = 0;
		}
	}

	priority_queue<pair<double, int>, vector<pair<double, int>>, greater<pair<double, int>>> que;
	for (int i = 1; i <= n + 1; ++i) {
		que.push({ d[0][i], i });
	}
	used[0] = true;
	while (!que.empty()) {
		double dis = que.top().first;
		int pos = que.top().second;
		que.pop();
		if (used[pos]) continue;
		used[pos] = true;
		d[pos][0] = d[0][pos] = dis;
		for (int i = 1; i <= n + 1; ++i) {
			if (used[i]) continue;
			que.push({ d[0][pos] + d[pos][i], i });
		}
	}
	printf("%.10f\n", d[0][n + 1]);
	return 0;
}

Measured memory_bytes: 18540
#include <bits/stdc++.h>
using namespace std;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) { cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl; }
#define mdebug(m) { cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;} }
#define Return(ans) { cout << (ans) << endl; return 0; }
#define pb push_back
#define fi first
#define se second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p){ cout << '(' << p.first << ',' << p.second << ')'; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using v_bool = vector<bool>;
using v_Pii = vector<Pii>;

//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};

const int mod = 1000000007;
//const int mod = 998244353;



signed main(){

    int N, K; cin >> N >> K;
    vec A(N); cin >> A;

    REP(t, K){
        vec a(N, 0);
        REP(i, N){
            int l = i - A[i], r = i + A[i];
            a[max(l, 0LL)]++;
            if(r + 1 < N) a[r + 1]--;
        }
        FOR(i, 1, N) a[i] += a[i - 1];

        A.swap(a);
        bool f = true;
        REP(i, N) if(A[i] < N) f = false;
        if(f) break;
    }
    REP(i, N) cout << A[i] << " ";
    cout << endl;

    return 0;
}


Measured memory_bytes: 6368
#include <iostream>
#include <stdio.h>
using namespace std;

int main(){

	int a, b, d, r;
	double f;
	cin >> a >> b;

	d = a / b;
	r = a % b;
	f = (double(a))/(double(b));

	cout << d << ' ' << r << ' ' << endl;
	printf("%lf", f);

	return 0;
}


Measured memory_bytes: 3228
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll inf=1e18;
int main()
{
    //freopen("take.in","r",stdin);
    ll n,W;
    cin>>n>>W;
    ll w[n+1],v[n+1];
    ll sum=0;
    for(ll i=1;i<=n;i++)
    {
        cin>>w[i]>>v[i];
        sum+=v[i];
    }
    vector<ll>dp(sum+1,inf);
    dp[0]=0;
    for(ll i=1;i<=n;i++)
    {
        for(ll now_value=sum-v[i];now_value>=0;now_value--)
        {
            dp[now_value+v[i]]=min(dp[now_value+v[i]],dp[now_value]+w[i]);
        }
    }
    ll ans=0;
    for(ll i=sum;i>=0;i--)
    {
        if(dp[i]<=W)
        {
            ans=max(ans,i);
        }
    }
    cout<<ans<<endl;
}

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

def main():
    N, M = map(int, input().split())
    PY = [tuple(map(int, input().split())) for _ in range(M)]

    sorted_PY  = sorted(PY)

    ans = [{} for _ in range(N+1)]
    i = 0
    pre = sorted_PY[0][0]
    for p, y in sorted_PY:
        if pre != p:
            i = 0
        i += 1
        ans[p][y] = i
        pre = p

    for p, y in PY:
        print(str(p).zfill(6) + str(ans[p][y]).zfill(6))

if __name__ == '__main__':
    main()


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

using namespace std;

int main() {
  int x, y;
  cin >> x >> y;
  string ans = "No";
  for (int c = 0; c <= x; c++) {
    int t = x - c;
    if (c * 2 + t * 4 == y) {
      ans = "Yes";
      break;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
struct nobe
{
    int v,a,b;
};
vector<nobe> gg[55];
int c[55],d[55];
long long f[55][3030];
int main()
{
    int n,m,s,i=1,j=0;
    scanf("%d%d%d",&n,&m,&s);
	s=min(s,2500);
    while(i<=m)
	{
		int u,v,a,b;
        scanf("%d%d%d%d",&u,&v,&a,&b);
        gg[u].push_back((nobe){v,a,b});
        gg[v].push_back((nobe){u,a,b});
        ++i;
    }
    i=1;
    while(i<=n)
    {
    	scanf("%d%d",&c[i],&d[i]);
    	++i;
    }
    memset(f,63,sizeof(f));
    f[1][s]=0;
    typedef tuple<long long,int,int> tt;
    priority_queue<tt,vector<tt>,greater<tt> > qu;
    qu.push(tt(0,1,s));
    while(!qu.empty())
	{
        long long t=get<0>(qu.top());
        int u=get<1>(qu.top()),w=get<2>(qu.top());
        qu.pop();
        if(f[u][w]>t) continue;
        i=0;
        while(i<gg[u].size())
		{
            int v=gg[u][i].v,a=gg[u][i].a,b=gg[u][i].b;
            if((w>=a)&&(f[v][w-a]>t+b))
			{
                f[v][w-a]=t+b;
                qu.push(tt(t+b,v,w-a));
            }
            ++i;
        }
        if(f[u][min(w+c[u],2500)]>t+d[u])
		{
            f[u][min(w+c[u],2500)]=t+d[u];
            qu.push(tt(t+d[u],u,min(w+c[u],2500)));
        }
    }
    i=2;
    while(i<=n)
	{
        long long ans=999999999999999999ll;
        j=0;
        while(j<=2500)
		{
            ans=min(ans,f[i][j]);
            ++j;
        }
        printf("%lld\n",ans);
		++i;
    }
    return 0;
}
/*
3 2 1
1 2 1 2
1 3 2 4
1 11
1 2
2 5
*/

Measured memory_bytes: 6524
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
typedef pair<ll, ll> P;
#define MOD 998244353
ll gcd(ll a, ll b) {
    return (b==0) ? a : gcd(b, a%b);
}

int main() {

    int n, m;cin >> n >> m;
    /// firstがto secondがcost
    const ll INF = 100100100100;
    struct Edge {ll to; ll cost;};
    vector<Edge> g[n];


    rep(i,m) {
        ll l, r; cin >> l >> r;
        ll c; cin >> c;
        Edge edge1 = {r-1, c};
        g[l-1].push_back(edge1);
    }
    rep(i, n-1) {
        Edge edge = {i, 0};
        g[i+1].push_back(edge);
    }
    priority_queue<P, vector<P>, greater<P>> pq;
    ll d[n];
    fill(d, d + n, 1e15);
    d[0] = 0;
    pq.push(P(0, 0));

    while(! pq.empty()){
        P p = pq.top(); pq.pop();
        int v = p.second;
        if (d[v] < p.first) continue;
        rep(i, g[v].size()) {
            auto e = g[v][i];
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                pq.push(P(d[e.to], e.to));
            }
        }
    }

    ll ans = d[n-1];
    if (ans >= 1e15) ans = -1;
    cout << ans << endl;
}

Measured memory_bytes: 9340
N, C = map(int, input().split())
INF = 10**20
rightSushi = [tuple(map(int, input().split())) for _ in range(N)]
leftSushi = [(C - x, v) for x, v in rightSushi[:: -1]]

def calc(sushi):
    ret = [-INF] * (N + 1)
    ret[0] = 0
    vSum = 0
    for i, (x, v) in enumerate(sushi, start=1):
        vSum += v
        ret[i] = max(vSum - x, ret[i - 1])
    return ret

leftV = calc(leftSushi)
rightV = calc(rightSushi)

def sol(sushi, maxV):
    ret = 0
    vSum = 0
    for i, (x, v) in enumerate(sushi, start=1):
        vSum += v
        ret = max(
            ret,
            vSum - x,
            vSum - x * 2 + maxV[N - i]
        )
    return ret

ans = max(sol(rightSushi, leftV), sol(leftSushi, rightV))

print(ans)

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

int main(){
    long long W, H, x, y; cin >> W >> H >> x >> y;
    cout << setprecision(22)  << (long double) (W*H)/2 << " ";
    if(W==2*x && H==2*y) cout << 1 << endl;
    else cout << 0 << endl;
}

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

int main(){//main_program
  int H1,M1,H2,M2,K,min;
  cin >> H1 >> M1 >> H2 >> M2 >> K;
  
  min = (H2 - H1) * 60 + (M2 - M1);
  
  if(min > K){
    cout << min - K << endl;
  }else{
    cout << 0 << endl;
  }
}

Measured memory_bytes: 3568
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define INF 1e16
typedef long long ll;
typedef pair<ll,ll> P;
 
ll Abs(ll x,ll y){
    if(x>=y)return x-y;
    else return y-x;
}



int main(void){
    int n,d;
    cin>>d>>n;
    if(d==0){
        int cnt = 0;
        int i=0;
        while(cnt<n){
            i++;
            if(i%100!=0)cnt++;
        }
        cout<<i<<endl;
    }
    if(d==1){
        int cnt =0;
        int i=0;
        while(cnt<n){
            i++;
            if(i%100==0){
                if(i%10000!=0)cnt++;
            }
        }
        cout<<i<<endl;
    }
    if(d==2){
        int cnt =0;
        int i=0;
        while(cnt<n){
            i++;
            if(i%10000==0){
                if(i%1000000!=0)cnt++;
            }
        }
        cout<<i<<endl;
    }
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <cstring>
#include <cassert>
#include <utility>
#include <iomanip>
#include <chrono>
#include <random>
#include <bitset>

using namespace std;

#define sz(x) (int) x.size()
#define unique(x) x.erase(unique(x.begin(), x.end()), x.end())
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x)) 
#define y1 aksjdaskdjksjfksdjf
#define left kdnvldvoiwejifejg
#define right lkdsjflksdjfdjfk
#define prev asdasfsadjkjsdfjs
#define tm aklsjdasjdasjdkdjjf
#define lcm hddalkwjeidjjhasda
#define random_shuffle asdasdd

string s;

int main() { 

  cin >> s;
  for (int i = 0; i < sz(s); i++) {
    s[i] = 'x';
  }

  cout << s << endl;

  return 0;
}


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

typedef long long ll;
typedef vector<ll> v1;
typedef vector<ll> vl;

typedef vector<vector<ll>> graph;

const ll INF = 1ll << 50;
const ll mod = 1000000007;

class union_find {
private:
  vl *par;
  vl *rnk;
  vl *siz;
public:
  union_find (ll n){
    par = new vl(n);
    iota(par->begin(),par->end(),0);
    rnk = new vl(n,0);
    siz = new vl(n,1);
  }
  ll find(ll x){
    if(par->at(x) == x) return x;
    else return par->at(x) = find(par->at(x));
  }
  ll size(ll x){
    return siz->at(find(x));
  }
  void unite(ll x,ll y){
    x = find(x);y = find(y);
    if(x == y)return;
    if(rnk->at(x) < rnk->at(y)){
      par->at(x) = y;
      siz->at(y) += siz->at(x);
    }
    else {
      par->at(y) = x;
      siz->at(x) += siz->at(y);
      if(rnk->at(x) == rnk->at(y)) rnk->at(x)++;
    }
  }
  bool same(ll x,ll y){
    return find(x) == find(y);
  }
};

ll h,w;
string s[402];
ll a[402][402];
ll dx[4] = {1, 0, -1, 0};
ll dy[4] = {0, 1, 0, -1};
ll ans;

union_find uf(402*402);

int main(){
    cin >> h >> w;
    for(ll i = 1;i <= h;i++) cin >> s[i];
    for(ll i = 1;i <= h;i++){
        for(ll j = 0;j < w;j++){
            if(s[i][j] == '.'){
                a[i][j+1] = -1;
            }else{
                a[i][j+1] = 1;
            }
        }
    }
    for(ll i = 1;i <= h;i++){
        for(ll j = 1;j <= w;j++){
            for(ll k = 0;k < 4;k++){
                if(a[i][j] * a[i+dx[k]][j+dy[k]] == -1){
                    uf.unite(i*401+j, (i+dx[k])*401+(j+dy[k]));
                }
            }
        }
    }
    unordered_map<ll,ll> m;


    for(ll i = 1;i <= h;i++){
        for(ll j = 1;j <= w;j++){
            if(a[i][j] < 0) m[uf.find(i*401+j)]++;
        }
    }
    for(ll i = 1;i <= h;i++){
        for(ll j = 1;j <= w;j++){
            if(a[i][j] > 0) ans += m[uf.find(i*401+j)];
        }
    }
    cout << ans << endl;


}


Measured memory_bytes: 12452
#include <stdio.h>

int main()
{
    int n,flag=1;
    scanf("%d", &n);
    int t[n+1], x[n+1], y[n+1];
    t[0]=0;
    x[0]=0;
    y[0]=0;
    for (int i = 1; i < n+1; i++) {
        scanf("%d %d %d", &t[i],&x[i],&y[i]);
    }
    int d;
    for(int i=0;i<n;i++){
        d=((t[i+1]-t[i])-(x[i+1]-x[i])-(y[i+1]-y[i]));
        if((d>=0)&&(d%2==0)){
        }else{
            flag=0;
            break;
        }
    }
    printf("%s\n", (flag==1)?"Yes":"No");
    return 0;
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a; cin >> a;
	string str; cin >> str;
	int dp[a + 50][2] = {0};
	dp[0][0] = (str[0] != '.');
	dp[0][1] = (str[0] != '#');
	for(int i=1; i<a; i++)
	{
		dp[i][0] = dp[i - 1][0] + (str[i] != '.');
		dp[i][1] = min(dp[i - 1][0], dp[i - 1][1]) + (str[i] != '#');
	}
	cout << min(dp[a - 1][0], dp[a - 1][1]) << '\n';
	return 0;
}

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


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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,a,b;
	cin>>n;
	a=n/10;
	b=n%10;
	if(a==9||b==9){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}
}

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

int main(void){
  string s;
  cin >> s;

  int min = 9999;
  for(int i = 0; i < s.size()-2; i ++){
    int n = stoi(s.substr(i, 3));
    if(min > abs(n-753)){
      min = abs(n-753);
    }
  }

  cout << min << endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
int main(){
  int x,y,z;
  cin >> x;
  y = x / 500 * 1000;
  z = x % 500 / 5 * 5;
  cout << y + z << '\n';
  return 0;   
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int n;
int a[252521];

int main(){
  scanf("%d",&n);
  REP(i,n)scanf("%d",a+i);
  if(a[0]>0){
    puts("-1");
    return 0;
  }
  REP(i,n-1){
    if(a[i+1]>a[i]+1){
      puts("-1");
      return 0;
    }
  }
  ll ans = 0;
  FORR(i,0,n){
    if(a[i]==0)continue;
    ans += a[i];
    while(i>0){
      if(a[i-1] == a[i]-1){
        i--;
      }else break;
    }
  }
  printf("%lld\n",ans);
  return 0;
}


Measured memory_bytes: 1024
/*
String[]の初期化、整数の型がlongになっているか
関数（splitとかcontainsとか）内では"+"とかは正規表現となされるので"\\+"とする
配列のコピーはarr1=arr.clone()
HashSet<>[]はおのおの初期化した？？？？？
負の数の割り算は絶対値が小さいほうに切り捨てられるex.-1/2=0ので、ある値>kみたいな式だとバグらせやすいので注意
ある値>=kとして、切り上げた値をとるべき
toLowerCase()はアルファベット以外に対して行ってもエラーにはならない
ArrayDequeではpopとpushはStackと同じ操作になる
*/
//入力終了→Ctrl+D
import java.util.*;
import java.awt.*;
import java.awt.geom.Point2D;
import static java.lang.System.*;
import static java.lang.Math.*;
public class Main {
    public static void main(String[] $) {
        int h = sc.nextInt();
        int w = sc.nextInt();
        int d = sc.nextInt();
        int[][] a = new int[h][w];
        int[] point = new int[90001];
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                a[i][j] = sc.nextInt();
                point[a[i][j]] = i * w + j;
            }
        }
        long[] ds = new long[h * w + 1];
        for (int i = 1; i <= h * w; i++) {
            if (i > d) ds[i] = ds[i - d] + abs(point[i] / w - point[i - d] / w) + abs(point[i] % w - point[i - d] % w);
        }
        int q = sc.nextInt();
        for (int i = 0; i < q; i++) {
            int l = sc.nextInt();
            int r = sc.nextInt();
            out.println(ds[r] - ds[l]);
        }
    }
    static class sc {
        static Scanner s = new Scanner(in);

        static String next() {
            return s.next();
        }

        static int nextInt() {
            return Integer.parseInt(s.next());
        }

        static long nextLong() {
            return Long.parseLong(s.next());
        }

        static double nextDouble() {
            return Double.parseDouble(s.next());
        }
    }
}

Measured memory_bytes: 65256
#include <stdio.h>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <iostream>
#include<math.h>
#include<bitset>
#include<iomanip>
#include<queue>
using namespace std;


int main() {
	int N,S2=0,S1=0; cin >> N;
	vector<int> W(N);
	for (int i = 0; i < N; i++) {
		cin >> W[i]; S2 +=W[i];
	}
	int ans=S2;
	for (int i = 0; i < N; i++) {
		if (abs(ans - 2 * W[i]) > ans)break;
		S2 -= W[i]; S1 += W[i];
		ans = min(ans,abs(S2 - S1));
	}
	cout << ans << endl;
}




Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<queue>
using namespace std;
template< typename FirstType, typename SecondType >
struct PairComparator {
  bool operator()( const pair<FirstType, SecondType>& p1, const pair<FirstType, SecondType>& p2 ) const 
    {  
		return p1.first > p2.first;
    }
};
bool inMST(vector< std::pair<int,int> > & MST,int j) {
	for (int k=0;k<(int)MST.size();++k){
		if(j == MST[k].second)
			return true;
	}
	return false;
}
int main(){
	int n;
	cin >> n;
	vector<int> E(n*n,-1);
	vector<int> DPG(n,-1);
	vector< std::pair<int,int> > MST;
	for(int j=0;j<n;++j) {
		int u,k; 
		cin >> u >> k;
		for(int i=0;i<k;++i){
			int v,c;
			cin >> v >> c;
			E[u*n+v] = c;
		}
	}
	priority_queue<pair<int,pair<int,int> >,vector< pair<int,pair<int,int> > >,
		PairComparator<int,pair<int,int> > > r;

	int cost = 0;
	int i=0;
	MST.push_back(pair<int,int>(i,i));
	DPG[i] = 0;
	while((int)MST.size() < n) {
		int ii=i*n;
		for (int j=0;j<n;++j) {
			if (E[ii+j] >= 0) {
				pair<int,int> add = std::make_pair(i,j);
				if (!inMST(MST,add.second)){
					r.push(std::pair<int,std::pair<int,int> >(E[ii+j]+DPG[i],add));
				}
			}
		}
		pair<int,pair<int,int> > top;
		while (!r.empty()) {
			top = r.top();
			r.pop();
			if (!inMST(MST,top.second.second)){
				break;
			}
		}
		cost += top.first;
		MST.push_back(top.second);
		i = top.second.second;
		DPG[i] = top.first;
		for(int j=0;j<n;++j){
			if (DPG[j] < 0)continue;
			if (E[i*n+j] >= 0) {
				DPG[j] = std::min(DPG[j],DPG[i] + E[i*n+j]);
			}
		}
	}
	for (int j=0;j<n;++j) {
		cout << j << " " <<  DPG[j] << endl;
	}
}

Measured memory_bytes: 1312