akhauriyash/Code-Regression huggingface dataset:
def solve():
    H,W = list(map(int, input().split()))
    S = ['.'*(W+2)]+['.'+input()+'.' for _ in range(H)]+['.'*(W+2)]
    result = 'Yes'
    
    # print(S)
    
    for i in range(1,H+1):
        for j in range(1,W+1):
            if S[i][j] == '#':
                if not(S[i+1][j] == '#' or S[i-1][j] == '#' or S[i][j+1] == '#' or S[i][j-1] == '#'):
                    result = 'No'
                    break
    
    print( result )
    
solve()

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;

int main() {
	string s, t;
	cin >> s >> t;
	sort(all(s)); sort(t.rbegin(),t.rend());
	if (s < t) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}


Measured memory_bytes: 3608
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
	n,m = readline() |> split |> parseMap
	a = Tuple{Int,Int}[(0,0) for i in 1:n]
	ac = zeros(Int,n)
	wa = zeros(Int,n)
	for i in 1:m
		p,x = readline() |> chomp |> split
		p = parseInt(p)
		if x=="AC"
			ac[p]=1
		elseif ac[p]==0
			wa[p] += 1
		end
	end
	b = 0
	for i in 1:n
		if ac[i]==1
			b += wa[i]
		end
	end
	println(sum(ac)," ",b)
end

main()

Measured memory_bytes: 170516
#include <bits/stdc++.h>
  using namespace std;
#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long ab;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsl(s) vector<pair<ll,ll>> (s);
#define pairss(s) vector<pair<string,string>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairspl(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsps(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsREV(s) (s).push_back(make_pair(bb,aa));
#define pairslREV(s) (s).push_back(make_pair(bb,aa));
#define pairssREV(s) (s).push_back(make_pair(bb,aa));
#define MOD 1000000007

int main() {
	
	int K,S;
	cin>>K>>S;
	ll ans=0;
	fx(K+1){
		fy(K+1){
			if(S-x-y<=K&&S-x-y>=0){
				ans++;
			}
		}
	}
	ce(ans)
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <limits>
using namespace std;
int main()
{
    int n;
    cin >> n;
    vector<int> vec(n);
    for(int i=0;i<n;i++)
    {
        cin >> vec[i];
    }
    int min = numeric_limits<int>::max();
    int max = numeric_limits<int>::min();
    for(int i=0; i<n;i++)
    {
        int tmp = vec[i];
        if(tmp < min)
        {
            min = tmp;
        }
        if(tmp > max)
        {
            max = tmp;
        }
    }
    cout << max - min << endl;
    return 0;
}



Measured memory_bytes: 256
import collections

n=int(input())
a=list(map(int,input().split()))
ans=[]
deqans=collections.deque(ans)
for i in range(1,n+1):
    if i%2==0:
        deqans.appendleft(a[i-1])
    else:
        deqans.append(a[i-1])
if n%2!=0:
    deqans.reverse()
ans=list(deqans)
ans=[str(a) for a in ans]
print(" ".join(ans))

Measured memory_bytes: 121684
/*
  AtCoder Beginner Contest 084
  D - 2017-like Number
*/

#include<iostream>
using namespace std;

int Q;
bool p[100001]; // true: 合成数, false: 素数
int c[100002]; // 2017-like numbers

int main() {
  for (int i = 2; i <= 100000; ++i) {
    if (!p[i]) {
      for (int j = i + i; j <= 100000; j += i) p[j] = true;
    }
  }

  for (int i = 3; i <= 100000; i += 2) {
    if (!p[i] && !p[(i + 1) / 2]) c[i] += 1;
  }

  for (int i = 3; i <= 100000; ++i) {
    c[i] += c[i-1];
  }

  scanf("%d", &Q);
  for (int q = 0; q < Q; ++q) {
    int l, r;
    scanf("%d %d", &l, &r);
    printf("%d\n", c[r] - c[l - 1]);
  }

  return 0;
}

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

int main() {
    ll n;
    cin >> n;
    vector<int> a(n), b(n), c(n);
    rep(i, n) cin >> a[i];
    rep(i, n) cin >> b[i];
    rep(i, n) cin >> c[i];
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    sort(c.begin(), c.end());
    ll ans = 0;
    for (int j = 0; j < n; j++) {
        ll i = lower_bound(a.begin(), a.end(), b[j]) - a.begin();
        ll k = upper_bound(c.begin(), c.end(), b[j]) - c.begin();
        ans += i * (n - k);
    }
    cout << ans << endl;
}

Measured memory_bytes: 1408
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int[] list = new int[N];
        for(int i = 0; i < N; i++) System.out.print((list[i] = scanner.nextInt()) + (i== N-1?"\n":" "));
 
        for(int i = 1; i < N; i++) {
            int v = list[i];
            int j = i - 1;
            while(j >= 0 && list[j] > v) {
                list[j + 1] = list[j];
                j--;
            }
            list[j + 1] = v;
            for(int n : list) System.out.print(n + (n == list[N - 1] ? "\n" : " "));
        }
 
        scanner.close();
    }
}


Measured memory_bytes: 33836
#include <iostream>
#include <queue>
#include <cmath>

using namespace std;
using ll = long long;
using ld = long double;

#define st first
#define nd second

const int MAXN = 2e5 + 5;

int n;
ll dp[MAXN], h[MAXN];

ll f(int j,  int i) {
    return dp[j] + (h[i] - h[j]) * (h[i] - h[j]);
}

ld intersection(int i, int j) {
    return (ld) (f(j, 0) - f(i,  0)) / (ld) (2 * (h[j] - h[i]));
    //return (ld) ((h[j] * h[j] + dp[j]) - h[i] * h[i] - dp[i]) / (2 * (h[j] - h[i]));
}

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

    ll C;
    cin >> n >> C;
    for (int i = 1; i<= n; i++) {
        cin >> h[i];
    }

    deque<int> Q = {1};
    int m = 1;
    for (int i = 2; i <= n; i++) {
        while (Q.size() > 1 and f(Q[1], i) < f(Q[0], i)) {
            m--;
            Q.pop_front();
        }

        dp[i] = f(Q[0], i) + C;

        while (Q.size() > 1 and intersection(Q[Q.size() - 2], i) <= intersection(Q[Q.size() - 2], Q.back())) {
            m--;
            Q.pop_back();
        }
        Q.push_back(i);
    }

    cout << dp[n] << "\n";
}


Measured memory_bytes: 3968
#include "bits/stdc++.h"
 
typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
using namespace std;
int MOD = 1000000007;
vector<int> G[2010];
int used[2010][2010] = {0};
int cnt[2010] = {0};
int n,k;
void dfs1(int p,int d,int i){
    if(used[i][p] == 1)return;
    used[i][p] = 1;    
    if(d > k/2)cnt[i]++;
    for(auto x:G[p])dfs1(x,d+1,i);
    return;
}
void dfs2(int p,int d,int i){
    used[i][p] = 1;    
    if(d > k/2)cnt[i]++;
    for(auto x:G[p]) if(used[i][x] == 0)dfs2(x,d+1,i);
    return;
}
signed main(){
    cin >> n >> k;
    pair<int,int> edge[2010];
    rep(i,n-1){
        int a,b;
        cin >> a >> b;
        G[b-1].push_back(a-1);
        G[a-1].push_back(b-1);
        edge[i] = MP(a-1,b-1);
    }
    if(k%2 == 0){
        rep(i,n){
             dfs1(i,0,i);
        }
        int mini = INF;
        rep(i,n)mini = min(mini,cnt[i]);
        cout << mini << endl;
    }else{
        rep(i,n-1){
            used[i][edge[i].fi] = 1;
            used[i][edge[i].se] = 1;
            dfs2(edge[i].fi,0,i);
            dfs2(edge[i].se,0,i);
        }
        int mini = INF;
        rep(i,n-1)mini = min(mini,cnt[i]);
        cout << mini << endl;
    }
    
    return 0; 
}

// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl https://agc026.contest.atcoder.jp/tasks/agc026_c
// rm -r -f test;oj dl http://abc107.contest.atcoder.jp/tasks/abc107_b

Measured memory_bytes: 31872
<?php
  $N = trim(fgets(STDIN));
  $current_x = 0;
  $current_y = 0;
  $success = true;
  $pre_time = 0;
  
  for($i = 0; $i < $N; $i++){
    $temp = trim(fgets(STDIN));
    $temp = str_replace(array("\r\n", "\r", "\n"), "", $temp);
    $array = explode(" ", $temp);
    $time = $array[0] - $pre_time;
    $trip_x = $array[1];
    $trip_y = $array[2];

    $move = abs($trip_x - $current_x) + abs($trip_y - $current_y);
    if(($time - $move) % 2 == 0 && $move <= $time){
      $current_x = $trip_x;
      $current_y = $trip_y;
      $pre_time += $time;
    } else {
      $success = false;
      break;
    }
  }
  
  if($success){
    echo "Yes\n";
  } else {
    echo "No\n";
  }
?>

Measured memory_bytes: 3576
#include <iostream>

using namespace std;
typedef long long ll;
int main(){
    ll A,B,C,D;

    cin >>A >>B >> C >>D;


    while(1){


        C = C-B;

        if(C<=0){


            cout << "Yes" << endl;


            break;
        }

        A = A-D;

        if(A<=0){

            cout << "No" <<endl;
            break;
        }



    }


 
 

  

    return 0;

}

Measured memory_bytes: 3624
// Last Change: 05/11/2019 21:21:15.
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

namespace NS {
void LoopUntilZeroInpput() {
  int hogegegege = 0;
  while (cin >> hogegegege && hogegegege != 0) {
  }
}
} // namespace NS

int main() {
  int R, G, B, N, ans;
  cin >> R >> G >> B >> N;

  ans = 0;

  for (int i = 0; i * R <= N; ++i) {
    for (int j = 0; j * G <= N; ++j) {
      ll tmp = N - i * R - j * G;
      if (tmp % B == 0 and tmp >= 0) {
        ++ans;
      }
    }
  }

  cout << ans << endl;

  //NS::LoopUntilZeroInpput();
}


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

int n;

int main(){
    cin>>n;
    if (n==(n&-n)) return puts("No"), 0;
    puts("Yes\n1 2\n2 3");
    printf("3 %d\n%d %d\n%d %d\n",n+1,n+1,n+2,n+2,n+3);
    for (int i=4;i<n;i+=2){
        printf("%d %d\n%d 1\n1 %d\n%d %d\n",i+1,i,i,i+1+n,i+1+n,i+n);
    }
    if (n%2==0){
        for (int i=20;i>=0;--i)
            if (n>>i&1){
                printf("%d %d\n%d %d\n",n,n-(1<<i),(1<<i)+1+n,n*2);
                break;
            }
    }
}

Measured memory_bytes: 2304
/*  TAHMID RAHMAN
    DAMIAN FOREVER
     MATH LOVER
    NEVER GIVE UP
*/
#include<bits/stdc++.h>
using namespace std;
#define pi acos(-1.0)
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define pb push_back
#define fi first
#define se second
#define in insert
#define mp make_pair
#define GCD(a,b) __gcd(a,b);
#define endl "\n"
#define FRU freopen("out.txt","w",stdout)
#define FRO freopen("in.txt","r",stdin)
#define INFLL 9223372036854775807
#define debug 0
#define MAXN   100001
#define ar array
const int mxN=2e5;
const int MOD=1e9+7;
bool sortbysec(const pair<int,int> &a,const pair<int,int> &b){return (a.second < b.second);}
//Don't hesitate to ask me if you don't understand my code.......Happy coding,Tahmid...;
int main()
{
    fastio;
    ll n;
    cin>>n;
    cout<<(1000-n%1000)%1000<<endl;


}


Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
#define arep(i,x,n) for(int i=int(x);i<(int)(n);i++)
#define rep(i,n) for(long long i = 0;i < n;++i)
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9+7  
using ll = long long; 
using P=pair<int,int>;
using lP=pair<ll,ll>;
using fP=pair<double,double>;

bool f(pair<string,int> a,pair<string,int>b){
    if(a.first!=b.first){
        return a.first<b.first;
    }
    return a.second>b.second;
}

int main(){
    int n;
    cin>>n;
    vector<pair<string,int>>r(n);
    vector<int>c(n);
    map<int,int>mp;
    rep(i,n){
        string s;
        int p;
        cin>>s>>p;
        r[i].first=s;
        r[i].second=p;
        mp[p]=i+1;
    }
    sort(r.begin(),r.end(),f);
    rep(i,n){
        cout<<mp[r[i].second]<<endl;
    }
  
    return 0;
}

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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

constexpr int MOD = 1'000'000'007;
int dp[100100][13];
std::string S;
int N;

int rec(int i, int rem){
    if(i == N){
        return rem == 5;
    }

    if(dp[i][rem] != -1){
        return dp[i][rem];
    }

    int res = 0;

    if(S[i] == '?'){
        for(int j=0;j<=9;++j){
            res = (res + rec(i + 1, (rem * 10 + j) % 13)) % MOD;
        }        
    }else{
        res = rec(i + 1, (rem * 10 + (S[i] - '0')) % 13);
    }



    return dp[i][rem] = res;
}

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

    std::cin >> S;

    N = S.size();

    memset(dp, -1, sizeof(dp));

    int res = rec(0, 0);
    std::cout << res << std::endl;
}


Measured memory_bytes: 13392
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e9
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;

int a[100010];
signed main(){
    int n,m;
    cin>>n>>m;
    multiset<int>st;

    REP(i,n) {
        cin>>a[i];
        st.insert(a[i]);
    }
    //cerr<<st.size()<<endl;
    ll sum=0;
    for (int i = 0; i < m; i++)
    {
      auto itr=st.end();
      itr--;
     // cerr<<*itr<<endl;
      st.erase(itr);
      st.insert(*itr/2);
    //  cerr<<"a"<<st.size()<<endl;
    }
    //cerr<<st.size()<<endl;
    for(auto itr = st.begin(); itr != st.end(); ++itr) {
      //  std::cout << *itr << "\n";      // イテレータの指す先のデータを表示
          sum+=*itr;
    }
   cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,M;
int A[404],B[404];
ll G[404][404];
ll mo=1000000007;
ll F[404][404];
ll H[404][404][144];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	M=N/3;
	FOR(i,N) cin>>A[i], A[i]--;
	FOR(i,N) cin>>B[i], B[i]--;
	
	G[0][0]=1;
	FOR(i,M) {
		FOR(j,N) G[i+1][j+2]=G[i][j];
		for(j=N;j>0;j--) if(G[i+1][j]) (G[i+1][j-1]+=G[i+1][j]*j)%=mo;
	}
	
	FOR(x,N+1) FOR(y,N+1) F[x][y]=101010;
	for(x=1;x<=N;x++) {
		int cnt[404]={};
		int num=x;
		FOR(i,x) cnt[A[i]]=1;
		for(y=1;y<=N;y++) {
			if(B[y-1]==A[x-1]) break;
			if(cnt[B[y-1]]==1) continue;
			num++;
			cnt[B[y-1]]=1;
			F[x][y]=num;
		}
	}
	
	FOR(x,N+1) FOR(y,N+1) H[x][y][0]=1;
	for(int t=1;t<=M;t++) {
		for(x=1;x<=N;x++) for(y=1;y<=N;y++) {
			ll cur=max(0LL,3*t-F[x][y]);
			H[x][y][t]=(cur*H[x-1][y-1][t-1] + H[x-1][y][t] + H[x][y-1][t] - H[x-1][y-1][t] + mo)%mo;
		}
	}
	
	cout<<H[N][N][M]*G[M][0]%mo<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 185728
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <climits>
#include <ctime>
#include <cmath>
#include <set>
#include <map>
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define abs(x) ((x)>0?(x):(-(x)))
#define FOR(i,a,b) for(int i = (a);i<=(b);i++)
#define FORD(i,a,b) for(int i = (a);i>=(b);i--)
#define REP(i,n) for(int i = 0;i<(n);i++)
#define rst(x,k) memset(x,k,sizeof(x))
#define lowbit(x) ((x)&(-(x)))
#define h(x) (1<<(x))
#define lson (ind<<1)
#define rson (ind<<1|1)
#define maxn 210000
#define INF 2100001000
#define mod 1000000007LL
#define link fsafsdfas
using namespace std;
typedef long long LL;
const int maxtime = 10081;
map<string,int> bst;
string name[maxn];
int c[10082];
int ans[maxn];
int fuck[maxn];
int n,f;
void update(int pos,int v){
    while(pos <= maxtime){
        c[pos] += v;
        pos += lowbit(pos);
    }
}
int req(int pos){
    int res = 0;
    while(pos > 0){
        res += c[pos];
        pos -= lowbit(pos);
    }return res;
}
int cal(int a,int b){
    return req(b) - req(a-1);
}
void INIT(void){
    FOR(i,1,n) name[i].clear();
    bst.clear();
    rst(c,0);
    FOR(i,1,n){
        cin >> name[i];
        int w,t; cin >> w >> t;
        t -= 600;
        ans[i] = w*1440+(t/100*60+t%100)+1;
        bst[name[i]] = i;
    }
    bool ok = true;
    cin >> f;
    FOR(i,1,f){
        string tt; cin >> tt;
        int kk = bst[tt];
        int a = ans[kk];
        ans[kk] = -100;
        if(cal(a,a+29) >0)ok = false;
        update(a,1); update(a+29,1);
    }
    if(!ok){printf("-1\n");return;}
    int cnt = 0;
    int res = f;
    FOR(i,1,n){
        if(ans[i] >= 0)
            fuck[cnt++] = ans[i];
    }
    sort(fuck,fuck+cnt);
    REP(i,cnt){
        if(cal(fuck[i],fuck[i]+29) == 0){
            res++;
            update(fuck[i],1); update(fuck[i]+29,1);
        }
    }
    printf("%d\n",res);
}

int main(void){
    while(cin >> n && n){
        INIT();
    }return 0;
}

Measured memory_bytes: 3036
#include <iostream>
#include <cmath>
#include <stdio.h>

using namespace std;

int main(){
   long double x1,y1,x2,y2;
   long double d;

   cin >> x1>> y1>> x2 >>y2;
   d=sqrt(((x2-x1)*(x2-x1))+((y2-y1)*(y2-y1)));
   printf("%.8Lf\n", d);
  
  return 0;
}



Measured memory_bytes: 3208
#include <bits/stdc++.h>
#define LL long long
#define PII pair<int,int>
using namespace std;
const int MAXN = 100000;
const int INF = 1e9 + 5;

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	int A, B, C, m;
	cin >> A >> B >> C;
	m = max({A, B, C});
	
	int cnt = (m % 2 == A % 2) + (m % 2 == B % 2) + (m % 2 == C % 2);
	if (cnt != 2) {
		cout << (3 * m - A - B - C) / 2 << "\n";
		return 0;
	}
	
	cout << (3 * (m + 1) - A - B - C) / 2 << '\n';
	return 0;
	
	/**** Note MAXN ****/
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		sc.next();
		char[] s = sc.next().toCharArray();
		int count = 0;
		for (int i = 2; i < s.length; i++) {
			if(s[i-2] == 'A' && s[i-1] == 'B'&& s[i] == 'C') count++;
		}
		System.out.println(count);
		sc.close();
	}
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(obj)   (obj).begin(),(obj).end()

#define debug(var)  do{std::cout << __LINE__ << "> " << #var << ": ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

struct SieveOfEstosthenes {
    int n;
    vector<bool> is_prime;
    vector<int> prime;
    SieveOfEstosthenes(int n) : n(n), is_prime(n, true) {
        is_prime[0] = is_prime[1] = false;
        for (int i = 2; i <= n; ++i) {
            if (is_prime[i]) {
                prime.push_back(i);
                for (int j = 2 * i; j <= n; j += i) is_prime[j] = false;
            }
        }
    }
};

void Main() {
	int N; cin >> N;
	SieveOfEstosthenes era(55555);
	vi res;
	for (auto n : era.prime) {
		if (n % 5 == 1) res.push_back(n);
	}
	REP(i,N) {
		cout << (i == 0 ? "" : " ") << res[i];
	}
	cout << endl;
}

int main() {
    cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
}


Measured memory_bytes: 384
#include<iostream>
#include<cmath>
#include<vector>
#include<set>
#include<algorithm>
#include<tuple>
#include<utility>
#include<cctype>
#include<climits>
#include<map>
#include<queue>
#include<functional>
#include<stack>


using namespace std;

#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPL(i,a,n) for(ll i=a;i<n;++i)
#define RUP(a,b) ((a+b-1)/(b))
#define ENT "\n"
#define SRTVG(v) sort(v.begin(),v.end(),greater<>())
#define SRTV(v) sort(v.begin(),v.end())
#define SRTAG(a,n) sort(a,a+n,greater<>())
#define MOD 1000000007

typedef long long ll;
typedef tuple<int,int,bool> Tb;
typedef pair<int,int> Pii;
typedef map<string,int> si;

template<class T> void chmax(T& a, T b) {if(a < b){a=b;}}
template<class T> void chmin(T& a, T b) {if(a > b){a=b;}}
template<class T> void YesNo(T& a) {if(a){cout << "Yes" << ENT;}else{cout << "No" << ENT;}}
template<class T> void YESNO(T& a) {if(a){cout << "YES" << ENT;}else{cout << "NO" << ENT;}}


vector<int> used;
vector<vector<int>> connect;
int n,m;
vector<int> a,b;

bool dfs(int now, int bridge) {
    bool ret=true;

    stack<int> st;
    st.emplace(now);
    while(st.size()>0){
        int e = st.top();
        st.pop();
        used[e]=1;

        REP(i,0,n){
            if(connect[e][i]==1 && used[i]!=1) if(a[bridge]!=min(e,i) || b[bridge]!=max(e,i)) st.push(i);
        }
    }
    REP(i,0,n) if(used[i]!=1) {ret = false;}
    used = vector<int>(n,0);

    return ret;
}

int atcoder() {
    cin >> n >> m;
    REP(i,0,m){
        int tmpa,tmpb;
        cin >> tmpa >> tmpb;
        a.push_back(tmpa);
        b.push_back(tmpb);
        a[i]--; b[i]--;
    }
    int ans=0;

    
    used = vector<int>(n,0);
    connect = vector<vector<int>> (n,vector<int>(n,0));
    REP(i,0,m) connect[a[i]][b[i]] = connect[b[i]][a[i]] = 1;
    
    REP(i,0,m) if(!dfs(0,i)) ans++;
    cout << ans << ENT;

    return 0;
}

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


Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;

int main(int argc, const char *argv[]) {
  int N;
  cin >> N;
  vector<int> A(N - 1);
  vector<int> count(N, 0);

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

  for (int i = 0; i < N - 1; i++) {
    count[A[i] - 1]++;
  }
  for (int i = 0; i < N; i++) {
    cout << count[i] << endl;
  }

  return 0;
}


Measured memory_bytes: 4852
a, b, x = map(int, input().split())
import math
if x == (a**2)*b:
    print(0)
elif x >= (a**2)*b/2:
    z = math.atan((a**3)/(2*(b*(a**2)-x)))
    print(90-math.degrees(z))
else:
    z = math.atan(2*x/(a*(b**2)))
    print(90-math.degrees(z))

Measured memory_bytes: 3064
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <algorithm>
#define MP make_pair
using ll = long long;
using namespace std;

int main()
{
  string s;
  cin >> s;
  int ans = 0;
  for(int i=0; i < s.length(); i++){
    if(s[i] == '+')
      ans++;
    else
      ans--;
  }
  cout << ans << endl;
  return 0;
}


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

int n,c,k,dp1[200005],dp2[200005];
char s[200005];

int main()
{
    scanf("%d%d%d%s",&n,&k,&c,s+1);
    dp1[0]=-0x3f3f3f3f,dp2[k+1]=0x3f3f3f3f;
    for(int i=1,cnt=1;i<=n;i++)
        if(s[i]=='o'&&i>dp1[cnt-1]+c) dp1[cnt++]=i;
    for(int i=n,cnt=k;i>=1;i--)
        if(s[i]=='o'&&i<dp2[cnt+1]-c) dp2[cnt--]=i;
    for(int i=1;i<=k;i++)
        if(dp1[i]==dp2[i]) printf("%d\n",dp1[i]);
    return 0;
}

Measured memory_bytes: 3200
#include "bits/stdc++.h"
#define ll long long
#define mp(a, b) make_pair(a, b)
using namespace std;
typedef pair<ll, ll> pairs;
typedef pair<ll, pairs> tpl;
ll dp[101][100001], a[1001], sum, mod = (ll)1e9 + 7;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll n, k;
    cin >> n >> k;
    for (ll i = 0; i < n; i++)
        cin >> a[i];
    for (ll i = 0; i <= a[0]; i++)
        dp[0][i] = 1;
    for (ll i = 1; i < n; i++)
    {
        ll pre[k + 1];
        pre[0] = 0;
        for (ll j = 0; j <= k; j++)
            pre[j + 1] = (pre[j] + dp[i - 1][j]) % mod;
        for (ll j = 0; j <= k; j++)
            dp[i][j] = (pre[j + 1] - pre[max(0LL, j - a[i])] + mod) % mod;
    }
    cout << dp[n - 1][k];
}

Measured memory_bytes: 82544
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;

#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

using Pi = pair<int, int>;
using ll = long long;
const int INF = 1 << 28;

string to_string(string s) {
  return s;
}

template <class T>
string to_string(vector<T> v) {
  string ret = "{";
  for (int i = 0; i < v.size() - 1; ++i) {
    ret += to_string(v[i]) + ",";
  }
  if (v.size() > 0) {
    ret += to_string(v.back());
  }
  ret += "}";
  return ret;
}

void debug() {
  cerr << endl;
}

template <class Head, class... Tail>
void debug(Head head, Tail... tail) {
  cerr << to_string(head) << " ";
  debug(tail...);
}

void print() {
  cout << endl;
}

template <class Head, class... Tail>
void print(Head head, Tail... tail) {
  cout << to_string(head);
  print(tail...);
}

void get() {}

template <class Head, class... Tail>
void get(Head& head, Tail&... tail) {
  cin >> head;
  get(tail...);
}

template <class T>
void getv(vector<T>& vec) {
  for (int i = 0; i < vec.size(); ++i)
    cin >> vec[i];
}

int main() {
  int H, W;
  get(H, W);
  map<char, int> cnt;
  FOR(i, H) {
    string s;
    get(s);
    FOR(j, W) { cnt[s[j]]++; }
  }
  bool f = 1;
  if (H % 2 == 1 && W % 2 == 1) {
    bool f2 = 0;
    for (pair<char, int> p : cnt) {
      if (p.second % 2 == 1) {
        if (f2)
          f = 0;
        cnt[p.first]--;
        f2 = 1;
      }
    }
    if (!f2)
      f = 0;
  }
  int yz = (H % 2 ? W / 2 : 0) + (W % 2 ? H / 2 : 0);
  for (pair<char, int> p : cnt) {
    if (p.second % 4 == 2)
      yz--;
  }
  if (yz < 0 || yz % 2 == 1)
    f = 0;
  for (pair<char, int> p : cnt) {
    if (p.second % 2 != 0) {
      f = 0;
    }
  }
  print(f ? "Yes" : "No");
  return 0;
}


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

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

    char c;
    cin >> c;
    if (c <= 'Z' && c >= 'A') cout << "A\n";
    else cout << "a\n";
}

Measured memory_bytes: 3632
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int k; cin >> k;
    cout << a[k - 1] << "\n";
    return 0;
}

Measured memory_bytes: 892
#include <iostream>
#include <sstream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <assert.h>
#include <deque>
using namespace std;

typedef unsigned long long UL;
typedef long long LL;
#define LP(i, a, b) for (int i = int(a); i < int(b); i++)
#define LPE(i, a, b) for (int i = int(a); i <= int(b); i++)
typedef pair<int, int> PII;
//typedef vector<vector<PII> > WAL;
typedef vector<vector<int> > SAL;
#define Ep 1e-7

#define INF 1e9

/*
 if can add to the current bus, add
 other wise, add a new bus

 can add to current bus if cap < C and headTime - curTime

 */

int const MaxSize = 100000;

int n, c, k, t[MaxSize];

int main() {

	ios_base::sync_with_stdio(false);
	//freopen("/Users/george/A_1.in", "r", stdin);
	cin >> n >> c >> k;
	LP(i, 0, n)
		cin >> t[i];

	sort(t, t+ n);

	int ans = 1;
	int curN = 1;
	int headT = t[0];

	LP(i, 1, n){

		int curT = t[i];
		if((headT + k) >= curT && curN < c){
			curN++;
		}else{
			ans++;
			curN = 1;
			headT = curT;
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <algorithm>
#include <cstring>
#include <memory.h>
#include <math.h>
#include <vector>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <stdio.h>
#include <queue>
#include <stack>
#include <cstdio>
#include <bitset>
 
using namespace std;
 
#define nfs ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define f first
#define s second
#define m_p make_pair
#define pb push_back
#define ii pair<int,int>
#define iii pair<int,pair<int,int> >
#define ll long long
#define ull unsigned long long
#define ld long double
#define ef else if
#define loc(x) (x).begin(),(x).end() 
#define locR(x) (x).rbegin(),(x).rend()
#define no puts("NO")
#define yes puts("YES")
#define ex puts("-1")
#define en puts("")
#define _ cout  
#define __ <<
#define outV(v) for(int i = 0 ; i < v.size() ; i++)cout << v[i] << ' ';
#define outA(x,l,r) for(int i = l ; i < r ; i++)cout << x[i] << ' ';
 
 
 
const ld EPS = 1e-18;
const double DEPS = 1e-9;
const ld PI = 3.141592653589793238;
const ull MOD = 1e9 + 7;
const int N = (int)(5e5) + 1;
 
 
ll gcd(ll fx, ll fy)
{
	if (!fy) return fx;
	return gcd(fy, fx % fy);
}
 
inline void fill(int* ar, int sz, int val)
{
	for (int i = 0; i < sz; i++)
	{
		ar[i] = val;
	}
}
 
int n, m;
ll dp[1001][1001];
char g[1001][1001];
 
int main()
{
	cin >> n >> m;
 
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			scanf(" %c", g[i] + j);
		}
	}
 
	dp[n - 1][m - 1] = 1;
 
	for (int i = n - 1; i >= 0; i--)
	{
		for (int j = m - 1; j >= 0; j--)
		{
			if (g[i][j] == '#')continue;
 
			if (j + 1 < m)
			{
				dp[i][j] += dp[i][j + 1];
			}
 
			dp[i][j] %= MOD;
 
			if (i + 1 < n)
			{
				dp[i][j] += dp[i + 1][j];
			}
 
			dp[i][j] %= MOD;
		}
	}
 
	printf("%lld", dp[0][0]);
}

Measured memory_bytes: 9088
import sys
input = sys.stdin.readline

# A - Addition
n = int(input())
a = list(map(int, input().split()))
odd_count = 0
even_count = 0

for i in range(n):
	if a[i] % 2 == 1:
		odd_count += 1
	else:
		even_count += 1

if odd_count % 2 == 1:
	print('NO')
else:
	print('YES')

Measured memory_bytes: 14052
import statistics

N = int(input())
A = []
B = []
for i in range(N):
    a, b = list(map(int, input().split()))
    A.append(a)
    B.append(b)
Am = statistics.median(A)
Bm = statistics.median(B)

if N % 2 == 0:
    print(round(2 * (Bm - Am) + 1))
else:
    print(Bm - Am + 1)

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

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

	std::vector<int> B(N - 1, 0);
	for(auto &b : B) {
		std::cin >> b;
	}

	int result = 0;
	for(int i = 0; i < N; i++) {
		if(i == 0) {
			result += B[i];
		} else if(i == N - 1) {
			result += B[i - 1];
		} else {
			result += std::min(B[i - 1], B[i]);
		}
	}

	std::cout << result << std::endl;

	return 0;
}


Measured memory_bytes: 256
X,Y,Z,K = list(map(int,input().split()))
A = sorted(list(map(int,input().split())),reverse=True)
B = sorted(list(map(int,input().split())),reverse=True)
C = sorted(list(map(int,input().split())),reverse=True)

ma,mb,mc = A[0],B[0],C[0]
sA = [a-ma for a in A] + [-10**15]
sB = [b-mb for b in B] + [-10**15]
sC = [c-mc for c in C] + [-10**15]

ia,ib,ic = 0,0,0
while min(10**5,(X)*(Y)*(Z)) > (ia+1)*(ib+1)*(ic+1):
    m = max(sA[ia+1],sB[ib+1],sC[ic+1])
    if ia < (X-1) and sA[ia+1] == m:
        ia = min(ia+1,X-1)
    if ib < (Y-1) and sB[ib+1] == m:
        ib = min(ib+1,Y-1)
    if ic < (Z-1) and sC[ic+1] == m:
        ic = min(ic+1,Z-1)
ans = []
for a in A[:ia+1]:
    for b in B[:ib+1]:
        for c in C[:ic+1]:
            ans.append(a+b+c)
ans.sort(reverse=True)
for out in ans[:K]:
    print(out)

Measured memory_bytes: 9000
#include <bits/stdc++.h>
using namespace std;
 
/*** Template Begins ***/
#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
 
// Debug //
 
#define trace(x)                 cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;

/*** Template Ends ***/

void solve(){
    string s,t;
    cin>>s>>t;
    int n=s.size(),m=t.size();
    int ans=m;
    for(int i=0;i+m-1<n;i++){
        int cnt=0;
        for(int j=0;j<m;j++){
            if(s[i+j]!=t[j])cnt++;
        }
        ans=min(ans,cnt);
    }
    cout<<ans<<endl;
}
 
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 3660
/*input
9
*/
#include <bits/stdc++.h>
#define ll long long int
#define ull unsigned long long
#define mod 1000000007
#define inf 1000000000000000001
#define all(c) c.begin(),c.end()
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define sz(a) int((a).size())
#define pb push_back
#define tr(c,i) for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())     
#define rep(i,j,n) for(ll i=j;i<n;i++)
#define mp make_pair
#define N 998244353
#define PI acos(-1.0)
//if (s.find('R') != std::string::npos)
//s.replace(s.find("10"), sizeof("10") - 1, "");
using namespace std;
bool comp(pair<string,ll>a,pair<string,ll>b){
  if(a.first==b.first) return a.second>b.second;
  return a.first<b.first;
}
int main()
{
  // added the two lines below 
  ios_base::sync_with_stdio (false); 
  cin.tie(NULL);
  cout.tie(0);

  ll r,d,x;
  cin>>r>>d>>x;
  for(int i=0;i<10;i++){
    x=r*x-d;
    cout<<x<<endl;
  }
  }

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

public class Main {
	static BufferedReader br;
	static PrintWriter pw;
	static int inf = (int) 1e9;
	static long mod = (long) 1e9 + 7;

	public static void main(String[] args) throws NumberFormatException, IOException, InterruptedException {
		br = new BufferedReader(new InputStreamReader(System.in));
		pw = new PrintWriter(System.out);
		StringTokenizer st = new StringTokenizer(br.readLine());
		int h1 = Integer.parseInt(st.nextToken());
		int s1 = Integer.parseInt(st.nextToken());
		int h2 = Integer.parseInt(st.nextToken());
		int s2 = Integer.parseInt(st.nextToken());
		while (h1 > 0 || h2 > 0) {
			h2 -= s1;
			if (h2 <= 0)
				break;
			h1 -= s2;
			if (h1 <= 0)
				break;
		}
		if(h1<=0)
			pw.println("No");
		else
			pw.println("Yes");
		pw.flush();

	}

	static int n;
	static boolean[] visited;
	static ArrayList<Integer>[] g;

	static void bfs(int s, int[] arr) {
		Queue<Integer> q = new LinkedList<Integer>();
		q.add(s);
		visited = new boolean[n];
		visited[s] = true;
		arr[s] = 0;
		while (!q.isEmpty()) {
			int u = q.remove();

			for (int v : g[u])
				if (!visited[v]) {
					visited[v] = true;
					q.add(v);
					arr[v] = arr[u] + 1;
				}
		}
	}

	static class Edge implements Comparable<Edge> {
		int node, cost, con;

		Edge(int a, int b, int c) {
			node = a;
			cost = b;
			con = c;
		}

		public int compareTo(Edge e) {
			return cost - e.cost;
		}
	}

	static class pair implements Comparable<pair> {
		int x;
		int y;

		public pair(int d, int u) {
			x = d;
			y = u;
		}

		public int compareTo(pair o) {
			return y - o.y;
		}

	}

	static class triple implements Comparable<triple> {
		int x;
		int y;
		int z;

		public triple(int a, int b, int c) {
			x = a;
			y = b;
			z = c;
		}

		public int compareTo(triple o) {
			return x - o.x;
		}
	}

	static int[] nxtarr() throws IOException {
		StringTokenizer st = new StringTokenizer(br.readLine());
		int[] a = new int[st.countTokens()];
		for (int i = 0; i < a.length; i++) {
			a[i] = Integer.parseInt(st.nextToken());
		}
		return a;
	}

	static long pow(long a, long e) // O(log e)
	{
		long res = 1;
		while (e > 0) {
			if ((e & 1) == 1)
				res *= a;
			a *= a;
			e >>= 1;
		}
		return res;
	}

	static int gcd(int a, int b) {
		if (a == 0)
			return b;
		return gcd(b % a, a);
	}
}


Measured memory_bytes: 32716
x, y = gets.chomp.split.map(&:to_i)
group = [[1, 3, 5, 7, 8, 10, 12], [4, 6, 9, 11], [2]]
judge = group.inject(false){|flag, i| flag = true if i.include?(x) && i.include?(y); flag}
puts judge ? "Yes" : "No"

Measured memory_bytes: 1788
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<math.h>
#include<numeric>
#include<cassert>
#include<random>
#include<deque>
#include<chrono>
#include<unordered_map>
#include<list>
#include<fstream>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
const ll E=1e18+7;
#define F first
#define S second
#define MK make_pair
const ll MOD=1000000007;



int main(){
    ll n;
    cin>>n;
    vector<ll> a;
    for(int i=0;i<3*n;i++){
        ll b;
        cin>>b;
        a.push_back(b);
    }
    sort(a.begin(),a.end());
    ll ans=0;
    for(int i=n;i<3*n;i+=2){
        ans+=a[i];
    }
    cout<<ans<<endl;
    return 0;
}


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

using namespace std;
using ll = long long int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define rep(i, N) for (ll i = 0; i < (N); i++)
#define FOR(i, a, b) for (ll i = (a), i < (N): i++)
// #define all(A) A.begin(),A.end()

int main(){
    int N, M;
    cin >> N >> M;
    vector<pll> AB(N);
    rep(i, N) {
        cin >> AB[i].first >> AB[i].second; 
    }
    sort(AB.begin(), AB.end());
    ll ans = 0;
    int i = 0;
    while (true) {
        if (AB[i].second >= M) {
            ans += M * AB[i].first;
            cout << ans << endl;
            return 0;
        }
        else {
            M -= AB[i].second;
            ans += AB[i].first * AB[i].second;
            i++;
        }

    }

    return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<math.h>
#include<string>
#include<vector>
#include<queue>
#include<deque>
using namespace std;
typedef pair<int, int>P;
typedef pair<int, pair < int, int > > PP;
typedef long long ll;
ll inf = -1;
ll mod = pow(10, 9) + 7;
 
int main() {
	string s;cin>>s;
	for(int i=1;i<4;i++){
		if(s[i-1]==s[i]){
			cout<<"Bad"<<endl;
			return 0;
		}
	}
	cout<<"Good"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdlib.h>
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
using ll=long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}

int main() {
  long long a,b;
  cin>>a>>b;
  cout<<(a-1)*(b-1)<<endl;
}


Measured memory_bytes: 256
class DSUWeighted():
    def __init__(self, n):
        self.n = n
        self.par_size = [-1] * n
        self.wt = [0] * n

    def leader(self, a):
        #assert 0 <= a < self.n
        x = a
        order = [x]
        while self.par_size[x] >= 0:
            x = self.par_size[x]
            order.append(x)
        for s in order[:-1][::-1]:
            self.wt[s] += self.wt[self.par_size[s]]
            self.par_size[s] = x
        return x

    def same(self, a, b):
        #assert 0 <= a < self.n
        #assert 0 <= b < self.n
        return self.leader(a) == self.leader(b)

    def merge(self, a, b, w):
        #assert 0 <= a < self.n
        #assert 0 <= b < self.n
        x = self.leader(a)
        y = self.leader(b)
        w += self.wt[a] - self.wt[b]
        if x == y: return x
        if -self.par_size[x] < -self.par_size[y]:
            x, y = y, x
            w = -w
        self.par_size[x] += self.par_size[y]
        self.par_size[y] = x
        self.wt[y] = w
        return x

    def diff(self, x, y):
        return self.wt[y] - self.wt[x]

import sys
input = sys.stdin.buffer.readline

N, M = map(int, input().split())

uf = DSUWeighted(N)

for _ in range(M):
    l, r, d = map(int, input().split())
    if uf.same(l - 1, r - 1):
        if uf.diff(l - 1, r - 1) != d:
            print('No')
            break
    else:
        uf.merge(l - 1, r - 1, d)
else:
    print('Yes')

Measured memory_bytes: 71828
n,q=map(int,input().split())
import sys
sys.setrecursionlimit(10**9) #再帰の上限をあげる

root=[i for i in range(n+1)] #自分が親なら自身の番号を、そうでないなら（元）親の番号を示す
def r(x):   #親は誰？
    if root[x]==x:
        return x
    else:
        root[x]=r(root[x])
        return root[x]
def unite(x,y):
    x=r(x)
    y=r(y)
    if x==y:
        return
    if x>y:
        x,y=y,x
    root[y]=x
for i in range(q):
    t,x,y=map(int,input().split())
    if t==0:
        unite(x,y)
    else:
        if r(x)==r(y):
            print(1)
        else:
            print(0)


Measured memory_bytes: 86072
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    for (ll i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    ll res = 0;
    for (ll i = 0; i <= min(k, n); i++)
    {
        for (ll j = 0; i + j <= min(k, n); j++)
        {
            vector<ll> b;
            ll cur = 0;
            for (ll s = 0; s < i; s++)
                b.push_back(a[s]), cur += a[s];
            for (ll t = 0; t < j; t++)
                b.push_back(a[n - 1 - t]), cur += a[n - 1 - t];
            sort(b.begin(), b.end());
            for(ll s = 0; s < min(k - i - j, (ll)b.size()); s++)
                if(b[s] < 0)
                cur -= b[s];
                res = max(res,cur);
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int a = sc.nextInt();
		int count = 0;
		boolean flag = true;
		while(flag){
			 h -= a;
			count++;
			if(h<=0){
				flag = false;
			}
		}
System.out.println(count);
	}
}

Measured memory_bytes: 21716
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>

using namespace std;
static const int INF = 1000000010;

int main(){
	ios_base::sync_with_stdio(false);
	while(true){
		int n;
		cin >> n;
		if(n == 0){ break; }
		vector<int> a(n), b(n);
		for(int i = 0; i < n; ++i){
			string s;
			cin >> s;
			if(s == "x"){
				b[i] = 1;
			}else{
				a[i] = atoi(s.c_str());
			}
		}
		int lower = -INF, upper = INF;
		for(int i = 0; i < n; ++i){
			if(b[i] == 0){
				if(i + 1 >= n || b[i + 1]){ continue; }
				if(i % 2 == 0){
					if(a[i] >= a[i + 1]){
						lower = INF; upper = -INF;
					}
				}else{
					if(a[i] <= a[i + 1]){
						lower = INF; upper = -INF;
					}
				}
				continue;
			}
			if(i + 1 < n && b[i + 1]){
				lower = INF; upper = -INF;
			}
			if(i % 2 == 0){
				for(int j = -1; j <= 1; j += 2){
					const int k = i + j;
					if(k < 0 || n <= k || b[k]){ continue; }
					upper = min(upper, a[k] - 1);
				}
			}else{
				for(int j = -1; j <= 1; j += 2){
					const int k = i + j;
					if(k < 0 || n <= k || b[k]){ continue; }
					lower = max(lower, a[k] + 1);
				}
			}
		}
		if(lower > upper){
			cout << "none" << endl;
		}else if(lower == upper){
			cout << lower << endl;
		}else{
			cout << "ambiguous" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1236
#include<cstdio>
using namespace std;
int main(){
	int N, T, S, M[3001]={}, maxM=0;
	scanf("%d%d%d", &N, &T, &S);
	if(S==0){
		for(int n=0; n<N; n++){
			int mise_fun, mise_time;
			scanf("%d%d", &mise_fun, &mise_time);
			for(int t=T; t>=mise_time; t--){
				int newM = M[t-mise_time] + mise_fun;
				
				if(M[t] < newM){
					M[t] = newM;
					if(maxM<newM)maxM = newM;
				}
			}
		}
	}
	else{
		for(int n=0; n<N; n++){
			int mise_fun, mise_time;
			scanf("%d%d", &mise_fun, &mise_time);
			for(int t=T; t>=mise_time; t--){
				if(t<=S || t >= S  + mise_time){
					int newM = M[t-mise_time] + mise_fun;
					if(M[t] < newM){
						M[t] = newM;
						if(maxM<newM)maxM = newM;
					}
				}
			}
		}
	}
	printf("%d\n", maxM);
	return 0;
}

Measured memory_bytes: 1048