akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define elif else if
typedef long long ll;
typedef unsigned long long ull;
#define DEBUG(x) cout << (x) << endl

int ans[2005][2005] = {0};
vector<int> nei[2005];
bool check[2005] = {false};
int out[2005] = {0};

int main()
{
    int n, x, y;
    scanf("%d %d %d", &n, &x, &y);
    nei[x].push_back(y);
    nei[y].push_back(x);
    for (int i = 0; i <= n; i++)
    {
        for (int j = 0; j <= n; j++)
        {
            ans[i][j] = INT_MAX;
        }
    }
    for (int i = 1; i < n; i++)
    {
        nei[i].push_back(i + 1);
        nei[i + 1].push_back(i);
    }
    queue<pair<int, int> > pend;
    for (int i = 1; i <= n; i++)
    {
        memset(check, false, sizeof(check));
        check[i] = 1;
        pend.push(make_pair(i, 0));
        while (pend.size())
        {
            ans[i][pend.front().first] = min(pend.front().second,ans[i][pend.front().first]);
            ans[pend.front().first][i] = min(pend.front().second,ans[pend.front().first][i]);
            for (int j = 0; j < nei[pend.front().first].size(); j++)
            {
                if (check[nei[pend.front().first][j]] == false)
                {
                    pend.push(make_pair(nei[pend.front().first][j], pend.front().second + 1));
                    check[nei[pend.front().first][j]] = true;
                }
            }
            pend.pop();
        }
    }
    for (int i = 1; i <= n;i++)
    {
        for (int j = 1; j <= n;j++)
        {
            out[ans[i][j]] += 1;
        }
    }
    for (int i = 1; i < n;i++)
    {
        printf("%d\n", out[i] / 2);
    }

        return 0;
}

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

int main()
{
    ll n, a[300000], ans = 0;
    cin >> n;
    rep(i, n) cin >> a[i];
    for (int i = 1; i < n; i++)
    {
        if (a[i - 1] > a[i])
        {
            ans += a[i - 1] - a[i];
            a[i]=a[i-1];
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 5204
package main

import (
	"fmt"
	"sort"
)

type str []byte

func (arg str) Len() int {
	return len(arg)
}

func (arg str) Less(i, j int) bool {
	return arg[i] < arg[j]
}

func (arg str) Swap(i, j int) {
	arg[i], arg[j] = arg[j], arg[i]
}

func combination(n, r uint) uint {
	if r == 0 || r == n {
		return 1
	} else if r == 1 {
		return n
	} else {
		return (combination(n-1, r-1) + combination(n-1, r))
	}
}

func main() {
	var n int

	fmt.Scan(&n)

	m := make(map[string]uint, n)

	for i := 0; i < n; i++ {
		s := make(str, 10)
		fmt.Scan(&s)
		sort.Sort(s)

		if _, ok := m[string(s)]; ok {
			m[string(s)]++
		} else {
			m[string(s)] = 1
		}
	}

	var ans uint

	for _, val := range m {
		if val != 1 {
			ans += combination(val, 2)
		}
	}

	fmt.Println(ans)

}


Measured memory_bytes: 12160
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,0,n+1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
const int MOD=1e9+7;
const int INF=1e18;
 
signed main(){
    int N;cin>>N;
    map<int,int>Amemo;
    map<int,int>Bmemo;
    REP(i,N){
        int a;cin>>a;
        Amemo[a+i]++;
        Bmemo[a-i]++;
    }
    int ans=0;
    for(auto v:Amemo){
        int pls=Amemo[v.first]*Bmemo[-v.first];
        ans+=pls;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 37736
#include <iostream>
#include <climits>
#include <set>
#include <string>
#include <algorithm>
#include <vector>
#define MAX 1000000007


using namespace std;
#define ll long long
#define dbg if(0)
#define ISRANGE(val,lo,hi) ((lo<=val)&&(val<hi))



int main(){
    ll ans;
    char a;
    cin >>a;
    bool f=true;
    for(int i=0;i<3;i++){
        char b;
        cin>>b;
        if(a==b)f=false;
        a=b;
    }

    {
        if(f)cout <<"Good"<<endl;
        else cout <<"Bad"<<endl;
    }

    dbg cout <<ans<<endl;

    return 0;

}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
int n;
while(scanf("%d",&n)!=EOF){
int count=0;
for(int a=9;a>=0;a--){
for(int b=9;b>=0;b--){
for(int c=9;c>=0;c--){
for(int d=9;d>=0;d--){
if(a+b+c+d==n){
count++;
}
}
}
}
}
printf("%d\n",count);
}
return 0;
}

Measured memory_bytes: 1024
import sys
from collections import defaultdict
readline = sys.stdin.buffer.readline
#sys.setrecursionlimit(10**8)


def geta(fn=lambda s: s.decode()):
    return map(fn, readline().split())


def gete(fn=lambda s: s.decode()):
    return fn(readline().rstrip())


def main():
    s = gete()
    t = gete()
    ans = 0
    for i in range(len(s)):
        if s[i] == t[i]:
            ans += 1

    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 38384
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cassert>

using namespace std;
typedef long long LL;
template <typename F, typename S> std::ostream& operator<<(ostream& os, const pair<F,S>& p) {
    os << "(" << p.first << "," << p.second << ")"; return os; }
template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "["; for(const T& a: v){ os << a << ", "; } os << "]"; return os; }
template <typename K, typename V> ostream& operator<<(ostream& os, const map<K,V>& m) {
    os << "{"; for(const auto& p: m){ os << p.first <<":"<< p.second << ", "; } os << "}"; return os; }


LL get_depth(LL cur, LL parent, vector<vector<LL>>& edge, LL depth, vector<LL>& node_depth){
    LL m = depth;
    for(LL next: edge[cur]){
        if(next == parent) continue;
        m = max(m, get_depth(next, cur, edge, depth+1, node_depth));
    }
    node_depth[cur] = m;
    return m;
}


bool get_route(LL cur, LL parent, vector<vector<LL>>& edge, LL target, vector<LL>& route){
    if(cur == target){
        route.push_back(target);
        return true;
    }
    for(LL next: edge[cur]){
        if(next == parent) continue;
        if(get_route(next, cur, edge, target, route)){
            route.push_back(cur);
            return true;
        }
    }
    return false;
}


int main(){
    LL n, u, v;
    cin >> n >> u >> v;
    --u; --v;
    vector<vector<LL>> edge(n);
    for(LL i = 0; i < n-1; ++i){
        LL a, b;
        cin >> a >> b;
        --a; --b;
        edge[a].push_back(b);
        edge[b].push_back(a);
    }
    vector<LL> node_depth(n);
    get_depth(v, -1, edge, 0, node_depth);
    vector<LL> route;
    get_route(v, -1, edge, u, route);
    reverse(route.begin(), route.end());
    LL best = 0;
    for(LL i = (route.size()+1)/2; i < route.size(); ++i){
        best = max(best, node_depth[route[i]] - 1);
    }
    cout << best << endl;
    //cerr << route << endl;
    //cerr << node_depth << endl;
    return 0;
}



Measured memory_bytes: 13440
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <stack>
#include <string>
#include <ctime>
#include <iomanip>
#include <set>
#include <iterator>
#include <map>
using namespace std;

#define pb push_back

#define forn(i, n) for(int i = 0; i < (int)(n); i++)
#define for1(i, n) for(int i = 1; i <= (int)(n); i++)

using ll = long long;

typedef vector<int> vi;

const int INF = 1e9 + 5;

void max_self(ll& a, ll b)
{
	a = max(a, b);
}

void min_self(ll&a, ll b)
{
	a = min(a, b);
}

int main()
{
	int n, W;
	cin >> n >> W;
	vector<int> weight(n), value(n);
	for (int i = 0; i < n; i++)
		cin >> weight[i] >> value[i];
	int sum_value = 0;
	forn(i, n) sum_value += value[i];
	vector<ll> dp(sum_value + 1, INF);
	dp[0] = 0;
	for (int item = 0; item < n; item++)
	{
		for (int v_al = sum_value - value[item]; v_al >= 0; v_al--)
		{
			min_self(dp[v_al + value[item]], dp[v_al] + weight[item]);
		}
	}

	ll ans = 0;
	for (int i = 0; i <= sum_value; i++)
		if (dp[i] <= W)
			ans = max(ans, (ll) i);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
/*
				C++
				encoding:UTF-8
				Modified: <26/May/2019 07:25:51 PM>

				✪ H4WK3yE乡
				Mohd. Farhan Tahir
				Indian Institute Of Information Technology (IIIT), Gwalior
*/

#include <bits/stdc++.h>

using namespace std;

// clang-format off

#define		 ll                     long long
#define		 mod                    1000000007
#define		 ve                     vector
#define		 pb                     push_back
#define		 umap                   unordered_map
#define		 pq                     priority_queue
#define		 endl                   "\n";
#define		 ff                     first
#define		 ss                     second
#define		 pii                    pair<ll, ll>
#define		 len(v)                 ll(v.size())
#define		 all(v)                 v.begin(), v.end()
#define		 reset(a, b)            memset(a, b, sizeof(a));
#define		 sum(v)                 accumulate(v.begin(), v.end(), (ll)0);
#define		 pr1(x)                 cout<<x<<"\n"
#define		 pr2(x, y)              cout<<x<<" "<<y<<"\n"
#define		 pr3(x, y, z)           cout<<x<<" "<<y<<" "<<z<<"\n"
#define		 prv(v, s, n)           fr(i, s, n) cout<<v[i]<<" "; cout<<"\n"
#define		 fr(i, s, n)            for (ll i = s ; i < n ; ++i)
#define		 dfr(i, s, n)           for (ll i = s ; i > n ; --i)

// clang-format on
const ll N = 51;
ll v[N];
ll n, k;
ll mx;


signed main () {
	ios_base::sync_with_stdio (false), cin.tie (0);
	cin >> n >> k;
	fr (i, 0, n) cin >> v[i];
	ll ans = 0;
	fr (i, 0, min (n, k) + 1) {
		fr (j, 0, min (k - i, n - i) + 1) {
			multiset< ll > s;
			ll a = 0;
			fr (p, 0, i) {
				a += v[p];
				if (v[p] < 0) s.insert (v[p]);
			}
			fr (p, 0, j) {
				a += v[n - 1 - p];
				if (v[n - 1 - p] < 0) s.insert (v[n - 1 - p]);
			}
			ll out = k - i - j;
			while (out and !s.empty ()) {
				auto it = s.begin ();
				a -= (*it);
				s.erase (it);
				out--;
			}
			ans = max (ans, a);
		}
	}
	pr1 (ans);
	return 0;
}


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

using namespace std;
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        int sum=0,s[100005];
        for(int i=0;i<n;i++)
        {
            scanf("%d",&s[i]);
            while(s[i]%2==0)
            {
                sum++;
                s[i]=s[i]/2;
            }
        }
        printf("%d\n",sum);
    }
    return 0;
}


Measured memory_bytes: 256
//Tuvshee
 
#include<iomanip>
#include<iostream>
#define _USE_MATH_DEFINES
#include<math.h>
#include<cmath>
#include<stdio.h>
#include<algorithm>
#include<string>
#include<cctype>
#include<vector>
#include<queue>
using namespace std;
#define I int
#define V void
#define D double
#define F float
#define C char
#define S string
#define B bool
#define L long long
#define rep(n) for(int i=0;i<n;i++)
#define reps(m,n,c) for(int c=m;c<n;c++)
#define repd(m,n,j) for(int j=n;j>m;j--)
#define whL while
#define eL endl
#define oR ||
#define anD &&
#define rtn return
#define pause system("PAUSE")
#define Max 300
#define max(m,n) ((n<m)?m:n)
#define min(m,n) ((n>m)?m:n)
 
int main(void)
{
    int h,w;
    while(1){
        scanf("%d%d", &h, &w);
 
        if(h == 0 && w == 0){
            break;
        }
        for(int i = 0; i < h; i++){
            for(int j = 0; j < w; j++){
                if(i == 0 || i == h-1 || j == 0 || j == w-1){
                    printf("#");
                } else {
                    printf(".");
                }
            }
            printf("\n");
        }
        printf("\n");
 
    }
    return 0;
}

Measured memory_bytes: 1160
# coding: utf-8
# Your code here!
N = int(input())
W = list(map(int,input().split()))

ans = 100
for T in range(N):
    S1 = sum(W[0:T + 1])
    S2 = sum(W[T + 1:N])
    ans = min([ans,abs(S1 - S2)])
print(ans)

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

#define rep(i, n) REP(i, 0, n)
#define REP(i, k, n) for(auto i = k; i != n; i++)
#define rrep(i, n) RREP(i, n, 0)
#define RREP(i, n, k) for(auto i = n; i != k; i--)
#define all(x, r) (x), (x)+(r)
#define ALL(x) (x).begin(), (x).end()
#define debug(x) cerr << #x << " " << x << endl
#define exst(x, data) (data).find(x) != (data).end()
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define np next_permutation
#define b32 bitset<32>

using ll = long long;
using Pii = pair<int,int>;
using Tiii = tuple<int, int, int>;
template<class T>using V = vector<T>;

vector<int> makePrimes(int size) {
    vector<int> primes;
    bool *flag = new bool[size];

    rep(i, size) {
        flag[i] = true;
    }

    long long limit = sqrt(size);
    REP(i, 2, limit) {
        if(flag[i]) {
            primes.push_back(i);
            for(long long j=i; j<size; j+=i) {
                flag[j] = false;
            }
        }
    }
    REP(i, limit, size) {
        if(flag[i]) {
            primes.push_back(i);
        }
    }

    delete[] flag;
    return primes;
}

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

    V<int> P = makePrimes(100000 +1); V<int> like2017;
    REP(itr,P.begin(),P.end()) {
        int N2 = (*itr)*2-1;
        if(N2 > 100000) break;
        if(find(ALL(P),N2) != P.end()) like2017.pb(N2);
    }

    // REP(itr,like2017.begin(),like2017.end()) cout << *itr << " ";
    // cout << endl;

    int Q; cin >> Q;
    rep(i,Q) {
        int l, r; cin >> l >> r;
        auto l_itr = lower_bound(ALL(like2017),l);
        auto r_itr = upper_bound(ALL(like2017),r);
        cout << r_itr - l_itr << endl;
    }

    return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
#define repr(i, s, e) for(int i=s; i>=e; i--)
#define reps(i, s, e) for(int i=s; i<=e; i++)
#define inf 1e18
#define all(v) v.begin(),v.end()
#define vsort(v) sort(v.begin(), v.end())
#define vsortr(v) sort(v.begin(), v.end(), greater<ll>())
#define sz(x) x.size()
#define ceil(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
#define sp << " " <<
#define enl << endl
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T &a, T b){ if(a<b){ a=b; return true; } return false; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a){ a=b; return true; } return false; }
template<typename T> T gcd(T a, T b){ if(b==0) return a; return gcd(b, a%b); }
template<typename T> T lcm(T a, T b){ return a*(b/gcd(a, b)); }
template<typename T> void vdebug(vector<T> v){ for(auto vv : v){ cout << vv << " "; } cout << endl; }
template<typename T> void adebug(T arr[], int n){ rep(i, n){ cout << arr[i] << " "; } cout << endl; }
void ans(bool b){ if(b) cout << "Yes" << endl; else cout << "No" << endl; }
void ans2(bool b){ if(b) cout << "YES" << endl; else cout << "NO" << endl; }
int keta(ll num){ int k=0; while(num>0){ num/=10; k++; } return k; }
int dx[] = {1, -1, 0, 0, 1, -1, 1, -1};
int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};


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

    int n, tmpa, tmpf;
    ll k;
    vector<ll> a, f;

    cin >> n >> k;
    rep(i, n){
        cin >> tmpa;
        a.push_back(tmpa);
    }
    rep(i, n){
        cin >> tmpf;
        f.push_back(tmpf);
    }

    vsort(a);
    vsortr(f);

    ll l = -1;
    ll r = 1e12;

    while(l+1  < r){
        ll c = (l+r)/2;
        bool good = [&]{
            ll sum = 0;
            rep(i, n){
                sum += max(0ll, a[i]-c/f[i]);
            }
            return sum <= k;
        }();
        if(good) r=c;
        else l=c;
    }

    cout << r << endl;

    return 0;
}


Measured memory_bytes: 4848
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<int, lint> pil;
typedef pair<lint, lint> pll;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(const T a, const T b){return a>=0 ? a/b : (a+1)/b-1;}
template<class T> T div_ceil(const T a, const T b){return a>=0 ? (a-1)/b+1 : a/b;}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod*mod;
constexpr int MAX = 100010;

int main(){
    int n, m;
    while(scanf("%d%d", &n, &m) && n){
        int c[m];
        lint x[n+1];
        rep(i, m) scanf("%d", &c[i]);
        rep(i, n) scanf("%lld", &x[i+1]);
        lint dp[n+1][256];
        rep(i, n+1)rep(j, 256) dp[i][j] = INF;
        dp[0][128] = 0;
        rep(i, n)rep(j, 256)if(dp[i][j] < INF){
            rep(k, m){
                int y = min(255, max(0, j + c[k]));
                chmin(dp[i+1][y], dp[i][j] + (y-x[i+1])*(y-x[i+1]));
            }
        }
        lint ans = INF;
        rep(j, 256) chmin(ans, dp[n][j]);
        printf("%lld\n", ans);
    }
}


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

int main() {
	long long x;
	cin >> x;
	long long x2 = pow(x,0.5);
// a^5 - b^5 = x  a > b
// (a-b)(a^4 + ab^3 + a^2b^2 + a^3b + b^4)
	long long a=-1,b=0;
	for(long long i=1;i<=x2;i++)
	{
		if(x % i == 0)
		{
			for(long long j=-400;j<400;j++)
			{
				long long
				 y1 = pow(j,4) * i * 5,
				 y2 = pow(j,3) * pow(i,2) * 10,
				 y3 = pow(j,2) * pow(i,3) * 10,
				 y4 = j * pow(i,4) * 5,
				 y5 = pow(i,5);
				if(y1 + y2 + y3 + y4 + y5 == x)
				{
					b = j;
					a = j + i;
					break;
				}
			}
		}
		if(a >= 0)
		{
			break;
		}
	}
	cout << a << ' ' << b << endl;
	return 0;
}


Measured memory_bytes: 4012
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<set>
#include<map>
#include<iostream>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x.begin(), _x.end(), std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
#define INF 1 << 30
const ll mod = 1000000007;
int main() {
	ll N, K, t = 0, x = 0;
	ll ans = 0;
	cin >> N >> K;
	vector<int> A(N);
	rep(i, 0, N)cin >> A[i];
	rep(i, 0, N) {
		rep(i2, i + 1, N) {
			if (A[i] > A[i2])t++;
		}
		t %= mod;
	}
	ans += t * K;
	ans %= mod;
	t = 0;
	rep(i, 0, N) {
		rep(i2, 0, N) {
			if (A[i] < A[i2])t++;
		}
		t %= mod;
	}
	ans += t * ((K * (K - 1) / 2) % mod) % mod;
	ans %= mod;
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 256
/*
ABHIJEET BISWAS
CSE 4th SEM 
MNNIT ALLAHBAD
https://atcoder.jp/contests/dp/tasks/dp_h
*/

#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1e18
#define ll long long
#define ld long double
#define pii pair<int,int>
#define pli pair<long long,int>
#define pll pair<long long,long long>
#define MAX 1000009
#define pb push_back
#define mp map<int,int>
#define f first
#define s second
#define fastIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
ld pi=2.0*acos(0.0);
ll dp[1001][1001];
ll grid[1001][1001];
ll h,w;
ll solve(int i,int j)
{
	if(i<=0||j<=0||i>h||j>w||grid[i][j]==-1)
	return 0;
	if(i==h and j==w)
	return 1;
	if(dp[i][j]!=-1)
	return dp[i][j];
	return dp[i][j]=(solve(i,j+1)+solve(i+1,j))%MOD;
	
	
}
int main() {
	fastIO
	cin>>h>>w;
	for(int i=1;i<=h;i++)
	{
		string str;
		cin>>str;
		for(int j=0;j<w;j++)
		if(str[j]=='.')
		grid[i][j+1]=0;
		else
		grid[i][j+1]=-1;
	}
	for(int i=0;i<=h;i++)
	for(int j=0;j<=w;j++)
	dp[i][j]=-1;
	cout<<solve(1,1)<<endl;
	return 0;
}

Measured memory_bytes: 16000
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <cmath>
#include <stack>
#include <string>
#include <cstring>
#include <numeric>
#include <iomanip>
using namespace std;
//
const int inf=1e9+7;//0x3f
//
int main(){
	int N;
	cin>>N;
	vector<int> V(N);
	for(int i=0;i<N;i++){
		cin>>V[i];
	}
	int ans=0;
	for(int i=0;i+1<N;i++){
		if(i+1==V[i]&&i+2==V[i+1]){
			swap(V[i],V[i+1]);
			ans++;
		}
	}
	for(int i=0;i<N;i++){
		if(i+1==V[i]){
			ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

#define M 1046527
#define NIL (-1)
#define L 14

char H[M][L];

int getChar(char ch)
{
	if(ch == 'A') return 1;
	else if(ch == 'C') return 2;
	else if(ch == 'G') return 3;
	else if(ch == 'T') return 4;
	else return 0;
}

long long getKey(char str[])
{
	long long sum = 0, p = 1, i;
	for(i = 0; i < strlen(str); i++)
	{
		sum += p*(getChar(str[i]));
		p *= 5;
	}
	return sum;
}

int h1(int key){return key % M;}
int h2(int key){return 1 + (key % (M - 1));}

int find(char str[])
{
	long long key, i, h;
	key = getKey(str);
	for(i = 0;;i++)
	{
		h = (h1(key) + i * h2(key)) % M;
		if(strcmp(H[h],str) == 0) return 1;
		else if(strlen(H[h]) == 0) return 0;
	}
	return 0;
}
	
int insert(char str[])
{
	long long key, i, h;
	key = getKey(str);
	for(i = 0;;i++)
	{
		h = (h1(key) + i * h2(key)) % M;
		if(strcmp(H[h],str) == 0) return 1;
		else if(strlen(H[h]) == 0)
		{
			strcpy(H[h], str);
			return 0;
		}
	}
	return 0;
}

int main(void)
{
	int i, n, h;
	char str[L], com[9];
	for(i = 0; i< M; i++) H[i][0] = '\0';
	scanf("%d", &n);
	for(i = 0; i< n;i++)
	{
		scanf("%s %s", com, str);
		
		if(com[0] == 'i')
		{
			insert(str);
		}
		else
		{
			if(find(str))
			{
				printf("yes\n");
			}
			else
			{
				printf("no\n");
			}
		}
	}
	return 0;
}


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

using namespace std;

const auto INF = 1e9;
const auto NMAX = 100000 + 5;
int aa[NMAX], bb[NMAX], cc[NMAX];

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

    aa[0] = 0, bb[0] = 0, cc[0] = 0;
    for (int i = 1; i <= N; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        aa[i] = max(bb[i - 1], cc[i - 1]) + a;
        bb[i] = max(cc[i - 1], aa[i - 1]) + b;
        cc[i] = max(aa[i - 1], bb[i - 1]) + c;
    }

    cout << max({aa[N], bb[N], cc[N]}) << endl;
    return 0;
}

Measured memory_bytes: 1408
// B - Bingo
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

#define YES puts("Yes")
#define NO puts("No")

int main(){
	int A[3][3]; rp(i,0,3)rp(j,0,3) cin>>A[i][j];
	int N; cin>>N;

	rp(i,0,N){
		int b; cin>>b;
		rp(r,0,3)rp(c,0,3) if(A[r][c] == b) A[r][c] = 0;
	}

	rp(r,0,3) if(!A[r][0] && !A[r][1] && !A[r][2]){YES;return 0;}
	rp(c,0,3) if(!A[0][c] && !A[1][c] && !A[2][c]){YES;return 0;}
	if(!A[0][0] && !A[1][1] && !A[2][2]){YES;return 0;}
	if(!A[2][0] && !A[1][1] && !A[0][2]){YES;return 0;}
	NO;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
rr = range


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_col(H, n_cols):
    '''
    H is number of rows
    n_cols is number of cols
    A列、B列が与えられるようなとき
    '''
    ret = [[] for _ in range(n_cols)]
    for _ in range(H):
        tmp = list(map(int, read().split()))
        for col in range(n_cols):
            ret[col].append(tmp[col])
    return ret


def read_matrix(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


def read_map(H):
    '''
    H is number of rows
    文字列で与えられた盤面を読み取る用
    '''
    return [read()[:-1] for _ in range(H)]


def read_map_as_int(H):
    '''
    #→1,.→0として読み込む
    '''
    ret = []
    for _ in range(H):
        ret.append([1 if s == '#' else 0 for s in read()[:-1]])
        # 内包表記はpypyでは若干遅いことに注意
        # #numpy使うだろうからこれを残しておくけど
    return ret


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right
from fractions import gcd


def lcm(a, b):
    # 最小公倍数
    g = gcd(a, b)
    return a * b // g


N, M = read_ints()
A = read_ints()

thre = sum(A) / (4 * M)
cnt = 0
for a in A:
    if a >= thre:
        cnt += 1
print('Yes' if cnt >= M else 'No')


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

const int mod = 1000000007;

int h, w, k;
int dp[200][10];

int main()
{
    cin >> h >> w >> k;

    dp[0][0] = 1;

    for (int i = 1; i <= h; ++i) {
        for(int k = 0; k < (1 << (w - 1)); ++k) {
            
            bool flag = true;
            for (int j = 0; j < (w - 2); ++j) if ((k & (1 << j)) && (k & (1 << (j + 1)))) flag = false;
            if (!flag) continue;

            for (int j = 0; j < w; ++j) {
                if (j >= 1 && (k & (1 << (j - 1)))) {
                    dp[i][j] += dp[i - 1][j - 1];
                    dp[i][j] %= mod;
                }
                else if (j + 1 < w && (k & (1 << j))) {
                    dp[i][j] += dp[i - 1][j + 1];
                    dp[i][j] %= mod;
                }
                else {
                    dp[i][j] += dp[i - 1][j];
                    dp[i][j] %= mod;
                }
            } 

        }
    }

    printf("%d\n", dp[h][k - 1]);

    return 0;
}

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

int main() {
	cin >> S;
	if (S == "Sunny") cout << "Cloudy";
	else if (S == "Cloudy") cout << "Rainy";
	else if (S == "Rainy") cout << "Sunny";
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
/*input
2
cccbca 5
acb 1
*/
// https://atcoder.jp/contests/abc175/tasks/abc175_f
// Clean code.
#include <bits/stdc++.h>
#define ps pair<string,int>
#define ll long long
using namespace std;
const int N = 55;

string a[N];
ll c[N];
int n;
map< ps, ll > d;
struct query {
	ps state;
	ll val;
	query(){state = {"", -1}; val = 0; }
	query(ps _state, ll _val) {state = _state; val = _val;}
};
bool operator>(query a, query b){
	return a.val > b.val;
}
pair<string,int> compose(string left, string right){
	int pos_l = left.size() - 1, pos_r = 0;
	while (pos_l >=0 && pos_r < (int)right.size()){
		if (left[pos_l] != right[pos_r]) return {"", -1}; // cannot compose.  
		pos_l--;
		pos_r++;
	}
	string res = "";
	if (pos_l < 0){
		for(int i=pos_r;i<right.size();++i) res += right[i];
		return {res, 1};
	}
	if (pos_r == right.size()){
		for(int i=0;i<=pos_l;++i) res += left[i];
		return {res, 0};
	}
}
bool is_palindrome(string s){
	if (s.size() <= 1) return true;
	int n = s.size();
	for(int i=0;i<n;++i){
		if (s[i] != s[n-1-i]) return false;
	}
	return true;
}
long long solve(){
	priority_queue< query, vector<query>, greater<query> > pq;
	for(int i=1;i<=n;++i){
		ps curNode = {a[i],1};
		if (d[curNode]) d[curNode] = min(d[curNode], c[i]);
		else d[curNode] = c[i];
		pq.push(query(curNode, 1LL * c[i]));
	}
	while (pq.size()){
		ps u = pq.top().state;
		ll curVal = pq.top().val;	pq.pop();
		if (curVal != d[u]) continue;
		if (is_palindrome(u.first)) return curVal;
		for(int i=1;i<=n;++i){
			string left = a[i], right = u.first;
			if (!u.second) swap(left, right);
			ps v = compose(left, right);
			if (v.second == -1) continue;
			if (!d[v] || d[v] > curVal + c[i]){
				pq.push(query(v, curVal + c[i]));
				d[v] = curVal + c[i];
			}
		}
	}
	return -1;
}
int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> n;
	for(int i=1;i<=n;++i){
		cin >> a[i] >> c[i];
	}
	cout << solve();
	return 0;
}

Measured memory_bytes: 3676
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
bool check_three(int);

int main()
{
  int n, b, f, r, v; cin >> n;
  int ans[4][3][10] = {0};

  for (int i=0; i < n; i ++) {
    cin >> b >> f >> r >> v;
    ans[b-1][f-1][r-1] += v;
  }

  // 棟数分ループ
  for (int i = 0; i < 4; i ++) {
    // 階数分ループ
    for (int j = 0; j < 3; j ++) {
      // 部屋数分ループ
      for (int k = 0; k < 10; k ++) {
        cout << " " << ans[i][j][k];
      }
      cout << endl;
    }
  if (i != 3) cout << "####################" << endl;
  }
  return 0;
}


Measured memory_bytes: 3092
from itertools import *
N = int(input())
D = {"M":0,"A":0,"R":0,"C":0,"H":0}

for n in range(N):
  s = input()
  if s[0] in "MARCH":
    D[s[0]]+=1

print(sum(a*b*c for a,b,c in combinations(D.values(),3)))

Measured memory_bytes: 9100
import sys
import itertools
n, m, x=map(int, input().split())
text = [list(map(int, i.strip('\n').split())) for i in sys.stdin]
num_tex = [i for i in range(1, len(text) + 1)]
all_c = []
for comb in num_tex:
    for v in itertools.combinations(text, comb):
        sum_a = []
        for j in range(1, len(v[0])):
            sum_a.append(sum([v_[j] for v_ in v]))
        if all([x <= sum_a_ for sum_a_ in sum_a]):
            all_c.append(sum([v_[0] for v_ in v]))
if len(all_c)!=0:
    print(sorted(all_c)[0])
else:
    print(-1)

Measured memory_bytes: 9384
N = int(input())
S = input()
T = ""
char = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
char2 = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ"
for i in range(len(S)):
    for j in range(26):
        if S[i] == char[j]:
            T += char2[j + N]
            break
print(T)


Measured memory_bytes: 73432
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int maxn=1e5+10;
int a[maxn];
int cmp(const int a,const int b){return a>b;}
int n,m,v,p,b[maxn];
bool check(int mid)
{
    if(mid<=p)return 1;
    if(a[mid]+m<a[p])return 0;
    if(v<=p-1&&a[mid]+m>=a[p])return 1;
    for(int i=1;i<=n;i++)b[i]=a[i];
    int temp=0;
    for(int i=1;i<=p-1;i++)b[i]+=m,temp+=m;
    int inx=n,cnt=v-p+1;
    while(inx>mid&&cnt>1)temp+=m,inx--,cnt--,b[inx]+=m;
    temp+=m;
    int now=a[mid]+m;
    int res=m*v-temp;
    for(int i=p;i<mid;i++)
	{
        int add=min(m,max(now-a[i],0ll));
        if(add>res)add=res;
        res-=add,b[i]+=add;
    }
    return now>=b[p]&&res<=0;
}
signed main()
{
    cin>>n>>m>>v>>p;
    for(int i=1;i<=n;i++)cin>>a[i];
    sort(a+1,a+n+1,cmp);
    int l=1,r=n;
    int ans=0;
    while(l<=r)
	{
        int mid=(l+r)>>1;
        if(check(mid))l=mid+1,ans=mid;
        else r=mid-1;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 5160
import numpy as np

N,D  = list(map(lambda x: int(x),input().split()))
Xs=[]
for i in range(N):
    X = list(map(lambda x: int(x),input().split()))
    Xs.append(X)
count=0
for i in range(N):
    for j in range(i+1,N):
        s = np.sum((np.array(Xs[i])-np.array(Xs[j]))**2)**0.5
        #print(s)
        if s==int(s):
            count += 1

print(count)



Measured memory_bytes: 21600
#include <bits/stdc++.h>
using namespace std;
const int base[9]={1,10,100,1000,10000,100000,1000000,10000000,100000000};
const int mod=1000000007;
int s,nl,nr,now;
inline int ksm(int x,int n) {
    int ret=1;
    while (n) {
        if (n&1) ret=1ll*ret*x%mod;
        n>>=1;
        x=1ll*x*x%mod;
    }
    return ret;
}
int main()
{
    scanf("%d",&s);
    int res=0;
    for (int l=1,r=1;l<10000000;++l) {
        while (now<s&&r<=22499999) {
            if (r>=base[nr]) ++nr;
            now+=nr;
            ++r;
        }
        if (now==s) ++res;
        if (l>=base[nl]) ++nl;
        now-=nl;
    }
    res+=s/8;
    for (int i=1;i<=s/8;++i)
        if (s%i==0)
            res=((res+(ksm(10,s/i)-ksm(10,s/i-1)-i)%mod)%mod+mod)%mod;
    printf("%d\n",res);
    return 0;
}


Measured memory_bytes: 3776
import java.util.*;

class Main {
public static void main(String[] args){

Scanner sc = new Scanner(System.in);
String N = sc.next();
String a = N.substring(0,1);
String b = N.substring(2,3);
if(a.equals(b)){
    System.out.println("Yes");
}else{
    System.out.println("No");
}

}
}

Measured memory_bytes: 21844
N = int(input())
S = [int(input()) for _ in range(N)]
#print(S)

s = ()
nex = 1

for i in range(N):
    #print(S[nex-1])
    nex = S[nex-1]
    if nex == 2:
        print(i+1)
        break
    if i == N-1:
        print(-1)

Measured memory_bytes: 76040
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int main(){
	int n; cin >> n;
	vector<int>v(n);
	vector<int>c(n);
	for(int i = 0; i < n; i++){
		cin >> v[i];
		c[i] = v[i];
	}
	int cnt = 0;
	sort(v.begin(), v.end());
	for(int i = 0; i < n; i++){
		if(v[i] != c[i])
			cnt++;
	}
	if(cnt > 2)
		cout << "NO";
	else
		cout << "YES";
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int H,W,h,w;
	int x,y;
	scanf("%d %d %d %d",&H,&W,&h,&w);
	x=H-h;
	y=W-w;
	printf("%d\n",x*y);
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <numeric>
#include <vector>

int main() {
  unsigned int K;
  std::cin >> K;

  std::vector<std::vector<unsigned int>> gcd_array(K + 1, std::vector<unsigned int>(K + 1, 0));
  for (size_t i = 1; i <= K; ++i) {
    for (size_t j = i; j >= 1; --j) {
      gcd_array.at(i).at(j) = std::gcd(i, j);
    }
  }

  unsigned long sum = 0;
  for (unsigned int a = 1; a <= K; ++a) {
    for (unsigned int b = 1; b <= K; ++b) {
      const unsigned int ab_gcd = gcd_array.at(std::max(a, b)).at(std::min(a, b));
      for (unsigned int c = 1; c <= K; ++c) {
        const unsigned int gcd = gcd_array.at(std::max(ab_gcd, c)).at(std::min(ab_gcd, c));
        sum += gcd;
      }
    }
  }

  std::cout << sum << std::endl;
  return 0;
}


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

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

	char oa = (a[0] - 'a') + 'A';
	char ob = (b[0] - 'a') + 'A';
	char oc = (c[0] - 'a') + 'A';
	cout << oa << ob << oc << endl;
}

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

#include <boost/algorithm/string/classification.hpp> // is_any_of
#include <boost/algorithm/string/split.hpp>
#include <boost/algorithm/string/join.hpp>
#include <boost/algorithm/string/replace.hpp>
#include <boost/range/algorithm.hpp> // boost::sort(arr)
using boost::algorithm::split; // split(result, s, boost::is_any_of(","));
using boost::algorithm::join; // string s = join(arr, "");
using boost::algorithm::replace_all; // replace_all(s, "AtCoder", "A");

int main() {
  int n, l;
  cin >> n >> l;
  vector<string> arr;
  rep(i, n) {
    string s;
    cin >> s;
    arr.emplace_back(s);
  }
  sort(arr.begin(), arr.end());
  string s = join(arr, "");
  cout << s << endl;
}

Measured memory_bytes: 256
n=int(input())
p=list(map(int,input().split()))
l=[[p[i],p[i+1],p[i+2]] for i in range(n-2)]
c=0
for item in l:
  if (item[1]>item[0] and item[1]<item[2]) or (item[1]<item[0] and item[1]>item[2]):
    c+=1
print(c)

Measured memory_bytes: 3060
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc=new Scanner(System.in);
        int a=sc.nextInt();
        int b=sc.nextInt();
        if(a>=13)
            System.out.println(b);
        else if(a>=6)
            System.out.println(b/2);
        else
            System.out.println(0);
    }
}


Measured memory_bytes: 21716
import sys
input = sys.stdin.buffer.readline

import heapq
INF = 10**18
def dijkstra_heap(s, edge, n):
    d = [INF] * n
    used = [True] * n #True: not used
    d[s] = 0
    used[s] = False
    edgelist = []
    for e in edge[s]:
        heapq.heappush(edgelist,e)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        if not used[minedge[1]]:
            continue
        v = minedge[1]
        d[v] = minedge[0]
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v],e[1]))
    return d

def main():
    n, m, s, t = map(int, input().split())
    s -= 1
    t -= 1
    edge1 = [[] for _ in range(n)]
    edge2 = [[] for _ in range(n)]
    for i in range(m):
        u, v, a, b = map(int, input().split())
        u, v = u-1, v-1
        edge1[u].append((a, v))
        edge1[v].append((a, u))
        edge2[u].append((b, v))
        edge2[v].append((b, u))

    d1 = dijkstra_heap(s, edge1, n)
    d2 = dijkstra_heap(t, edge2, n)
    #print(d1)
    #print(d2)
    C = [0]*n
    for i in range(n):
        C[i] = (d1[i]+d2[i], i)
    heapq.heapify(C)
    cur = -1
    for i in range(n):
        if cur < i:
            while C:
                x, t = heapq.heappop(C)
                if t >= i:
                    cur = t
                    break
        #print(cur)
        print(10**15-x)

if __name__ == '__main__':
    main()

Measured memory_bytes: 122908
#include <iostream>
#include <cstring>
#include <vector>
#include <set>
#include <list>
#include <map>
#include <deque>
#include <algorithm>
#include <utility>
#include <stdio.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
#define for1(i,n) for (ll i=0;i<(n);i++)
#define for2(i,m,n) for (ll i=(m);i<(n);i++)
#define for3(i,m,n,d) for (ll i=(m);i<(n);i+=(d))
#define DEBUG 0

void solve()
{
    ll W,H,x,y;
    char as[1000];
    cin >> W >> H >> x >> y;
    long double ans1 = (long double)W*H/2;
    ll ans2 = 0;
    if (x*2==W && y*2==H) {
        ans2 = 1;
    }
    sprintf(as, "%.11Lf %d", ans1, ans2);
    cout << string(as) << endl;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    do {
        solve();
    } while (DEBUG);
}


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

using i32 = int_fast32_t;
using i64 = int_fast64_t;

string n;
i32 k, l;

i64 com(i64 m, i64 r) {
    if (r < 0 || r > m) return 0;
    if (r == 0) return 1;
    return m * com(m-1, r-1) / r;
}

i64 solve(i32 i, i32 j, bool less) {
    if (j == 0) return 1;
    if (i == l) return 0;

    if (less) return com(l-i, j) * pow(9, j);
    if (n[i] == '0') return solve(i+1, j, false);
    return solve(i+1, j, true) + solve(i+1, j-1, true) * (n[i] - '1') + solve(i+1, j-1, false);
}

int main() {
    cin >> n;
    cin >> k;
    l = n.size();

    cout << solve(0, k, false) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
const Int MAX = 5050;
Int solve(Int ga,Int sa,Int ba,Int gb,Int sb,Int bb,Int n){
  using P = pair<Int, Int>;
  vector<P> vt;
  vt.emplace_back(ga,gb);
  vt.emplace_back(sa,sb);
  vt.emplace_back(ba,bb);
  sort(vt.begin(),vt.end());

  Int res=n;
  for(Int uku=0;uku<3;uku++){
    if(uku==1) swap(vt[0],vt[2]);
    if(uku==2) swap(vt[1],vt[2]);

    tie(ga,gb)=vt[0];
    tie(sa,sb)=vt[1];
    tie(ba,bb)=vt[2];

    for(Int i=0;i<MAX;i++){
      if(i*ga>n) break;
      for(Int j=0;j<MAX;j++){
        Int sum=i*ga+j*sa;
        if(sum>n) break;
        Int k=(n-sum)/ba;
        assert(n-(i*ga+j*sa+k*ba)>=0);
        chmax(res,n-(i*ga+j*sa+k*ba)+(i*gb+j*sb+k*bb));
      }
    }

    if(uku==1) swap(vt[0],vt[2]);
    if(uku==2) swap(vt[1],vt[2]);
  }
  return res;
}

signed main(){
  Int n;
  cin>>n;

  Int ga,sa,ba;
  Int gb,sb,bb;
  cin>>ga>>sa>>ba;
  cin>>gb>>sb>>bb;

  Int p=solve(ga,sa,ba,gb,sb,bb,n);
  Int q=solve(gb,sb,bb,ga,sa,ba,p);
  cout<<q<<endl;
  return 0;
}


Measured memory_bytes: 256
n,h=map(int,input().split())
A,B=[],[]
for i in range(n):
  a,b=map(int,input().split())
  A.append(a)
  B.append(b)
ma=max(A)
BB=[]
for i in range(n):
  if B[i]>ma:
    BB.append(B[i])
BB.sort(reverse=True)
count=0
dmg=0
while dmg<h:
  if count<len(BB):
    dmg+=BB[count]
    count+=1
  else:
    r=(h-dmg-1)//ma+1
    dmg=h
    count+=r
print(count)

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

int N;
string S;

bool check(int x,int y){
	int a[100010]={};
	a[0]=x; a[1]=y;
	reg(i,1,N){
		int c=0;
		if(S[i-1]=='o')c++;
		if(a[i-1]==1)c++;//S
		if(a[i]==1)c++;//S
		if(c%2==0)a[i+1]=2;//W
		if(c%2==1)a[i+1]=1;//S
	}
	if(a[N]==a[0] && a[N+1]==a[1]){
		reg(i,1,N){
			if(a[i]==1){
				printf("S");
			}else{
				printf("W");
			}
		}
		printf("\n");
		return true;
	}
	return false;
}

int main(void){
	scanf("%d",&N);
	cin>>S;
	if(check(1,1))return 0;
	if(check(1,2))return 0;
	if(check(2,1))return 0;
	if(check(2,2))return 0;
	printf("-1\n");
	return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
#define mins(x,y) (x=min(x,y))
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P  = pair<int,int>;
using v  = vector<int>;
using vv = vector<v>;

int main(){
    int n;
    cin >> n;
    
    vv cost(n,v (n));
    vv seat(n,v (n,1));
    
    rep(i,n)rep(j,n){
        cost[i][j] = i;
        mins(cost[i][j],j);
        mins(cost[i][j],n-1-i);
        mins(cost[i][j],n-1-j);
    }
    
    int ans = 0;
    
    v di={-1,0,1,0};
    v dj={0,-1,0,1};//四方
    
    for(int i=0; i<n*n; i++){
        int p;
        cin >> p;
        p--;
        int pi = p/n;
        int pj = p%n;
        
        ans += cost[pi][pj];
        seat[pi][pj] = 0;
        
        //幅優先で距離リストを更新
        queue<P> more;
        more.emplace(pi,pj);
        
        while(!more.empty()){
            
            int ni = more.front().first;
            int nj = more.front().second;
            int nc = cost[ni][nj]+seat[ni][nj];
            
            for(int l=0; l<4; l++){
                int mi = ni+di[l], mj = nj+dj[l];
                if(mi>=n || mi<0 || mj>=n || mj<0)continue;
                if(cost[mi][mj]<=nc)continue;
                
                cost[mi][mj] = nc;
                more.emplace(mi,mj);
                
            }
            more.pop();
        }
    }
    
    cout << ans << endl;
    return 0;
}

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

// DP テーブル
long long dp[3100][3100];

int main() {
    // 入力受け取り
    int N; cin >> N;
    vector<int> a(N);
    for (int i = 0; i < N; ++i) cin >> a[i];
    
    // 初期条件
    for (int i = 0; i < N; ++i) dp[i][i] = 0;
    
    // DP
    for (int len = 1; len <= N; ++len) {
        for (int left = 0; left + len <= N; ++left) {
            int right = left + len;

            // 先手番
            if ((N - len) % 2 == 0)
                dp[left][right] = max(dp[left + 1][right] + a[left], dp[left][right - 1] + a[right - 1]);
            
            // 後手番
            else
                dp[left][right] = min(dp[left + 1][right] - a[left], dp[left][right - 1] - a[right - 1]);
        }
    }
    
    // 答え
    cout << dp[0][N] << endl;
}

Measured memory_bytes: 73984
import sys
import copy
import math
import bisect
import pprint
import bisect
from functools import reduce
from copy import deepcopy
from collections import deque

if __name__ == '__main__':
    a=input()
    b=input()
    count =0

    for i in range(3):
        if a[i] ==b[i]:
            count +=1

    print(count)

Measured memory_bytes: 3956
#include <stdio.h>

using namespace std;

int main() {
char a,b;

scanf("%c %c",&a,&b);



  if(a=='H' && b=='H')
  {

      printf("H\n");
  }

else if(a=='D' && b=='H')
{
    printf("D\n");
}
else if(a=='D' && b=='D')
{
    printf("H\n");
}
else if(a=='H' && b=='D')
{
    printf("D\n");
}
  return 0;
}





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

using namespace std;

struct Coord {
    int x;
    int y;
    
    Coord (int x, int y) {
        this->x = x;
        this->y = y;
    }
    
    bool in_range(int H, int W) {
        return 0 <= x && x < W && 0 <= y && y < H;
    }
    
    Coord operator + (const Coord& another) const {
        return Coord(x + another.x, y + another.y);
    }
};

Coord dp[4] = {
    Coord(1, 0),
    Coord(0, 1),
    Coord(-1, 0),
    Coord(0, -1),
};

int main(void){
    int H, W;
    cin >> H >> W; cin.ignore();
    int N;
    cin >> N; cin.ignore();
    vector<int> num_color(N+1);
    for (int i = 0; i < N; i++) {
        cin >> num_color[i+1];
    }
    cin.ignore();
    
    int ans[101][101];
    Coord current_pos = Coord(0, 0);
    int current_color = 1;
    bool closed[101][101] = {};
    while (1) {
        closed[current_pos.y][current_pos.x] = true;
        ans[current_pos.y][current_pos.x] = current_color;
        num_color[current_color]--;
        if (num_color[current_color] <= 0) {
            current_color++;
        }
        
        if (current_color > N) {
            break;
        }
        
        for (Coord move: dp) {
            Coord p = current_pos + move;
            if (!p.in_range(H, W) || closed[p.y][p.x]) continue;
            current_pos = p;
            break;
        }
    }
    
    for (int y = 0; y < H; y++) {
        for (int x = 0; x < W; x++) {
            cout << ans[y][x] << " ";
        }
        cout << endl;
    }
}


Measured memory_bytes: 384
#include <stdio.h>
int isprime(int n){
  for(int i = 2 ; i*i<=n ;i++){
    if(n%i==0)return 0;
}
 return 1;
}
int main(){
  int number[10000+2]={0};
  int n ,i , fir ,sec;
  for(i=2 ; i<10000 ;i++){
    number[i] = isprime(i);
  }
  while(scanf("%d" ,&n)){
    if(n==0)break;
    fir = 0 ,sec = 0;
    for(i=n ;i>3 ;i--){
      if(number[i] && number[i-2]){
        fir = i-2;
        sec = i;
        break;
      }
    }
    printf("%d %d\n" ,fir ,sec);
  }
  return 0;
}

Measured memory_bytes: 2720
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <limits.h>    
#define inf 100000000
#define INF 9223372036854775807
#define EPS 1e-10
#define sq(n) ((n)*(n))
#define rep(i,n) for(i=0;i<n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
#define sort(a,n) qsort(a,n,sizeof(TYPE),cmp)
#define sort_r(a,n) qsort(a,n,sizeof(TYPE),cmp_r);
#define chsort(s,n) qsort(s,n,sizeof(char),cmp)
#define chsort_r(s,n) qsort(s,n,sizeof(char),char_cmp_r);
#define TYPE long long
#define MEMSET(a) memset(a,0,sizeof(a))
long long mod=(long long)1e09+7;

int in(void){
    int i;scanf("%d",&i);
    return i;
}
long long llin(void){
    long long i;scanf("%lld",&i);
    return i;
}
double din(void){
    double i;scanf("%lf",&i);
    return i;
}
void chin(char s[]){
    scanf("%s",s);
}
void print(int a){
    printf("%d\n",a);
}
void llprint(long long a){
    printf("%lld\n",a);
}
void dprint(double a){
    printf("%.10f\n",a);
}
void print2(int a,int b){
    printf("%d %d\n",a,b);
}
long long max(long long a,long long b){
    return a>b?a:b;
}
long long min(long long a,long long b){
    return a<b?a:b;
}
int cmp(const void *a,const void *b){
    return *(TYPE *)a-*(TYPE *)b;
}
int cmp_r(const void *a,const void *b){
    return *(TYPE *)b-*(TYPE *)a;
}
int char_cmp(const void *a,const void *b){
    return strcmp((char *)a,(char *)b);
}
int char_cmp_r(const void *a,const void *b){
    return strcmp((char *)b,(char *)a);
}
void swap(int *a,int *b){
    int t=*a;
    *a=*b;
    *b=t;
}
long long gcd(long long x,long long y){
    return x%y?gcd(y,x%y):y;
}
long long lcm(long long x,long long y){
    return x/gcd(x,y)*y;
}

// write codes below this
// when you use 'sort',
// make sure TYPE macro is correct

int main(void){
    double d=din();
    dprint(fmax(d*sqrt(2),(int)d+1));
    return 0;
}


Measured memory_bytes: 2144
/*
Sharif Hasan - CSE, PUST
Apr 24, 2020 02: 14 PM
*/
#include<bits/stdc++.h>
#include "string.h"
#define br cout<<"\n"
#define what(x) cout<<"in here var= "<<x<<"\n";

/*STL definations*/
#define pb push_back

#define FOR(i,n) for(int i=0;i<n;i++)
#define FROM(a,i,n) for(int i=a;i<n;i++)
using namespace std;
double clockAngle(double a,double b){
    double f=fabs(b*6-(a*30+b/2));
    if(f>180) f=360-f;
    return  f*acos(-1)/180.0;
}
int main(){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    printf("%.14f\n",sqrt(a*a+b*b-2*a*b*cos(clockAngle(c,d))));
    return 0;
}

Measured memory_bytes: 4104