akhauriyash/Code-Regression huggingface dataset:
#include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<unordered_map>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y-1);(X) >=0;--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
//template<class T> using vv=vector<vector<T>>;
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"<<endl; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}

const ll MOD=1e9+7;

int main(){
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(0);
  int i,j,k;
  int n,l;
  cin>>n>>l;
  vector<ll> dp[2],x(n),a(n);
  rep(i,n)
    cin>>x[i];
  rep(i,n)
    cin>>a[i];
  rep(i,2)dp[i].resize(l+1);
  dp[0][0]=1;
  //cout<<dp[0];
  rep(i,n){
    ll sum=0,val=0;
    fill(all(dp[1-i%2]),0ll);
    rep(j,l){
      (sum+=dp[i%2][j])%=MOD;
      if(a[i]&&j>x[i]&&(j-x[i])%a[i]==0 || j==x[i]){
	dp[1-i%2][j+1]=sum;
      }
    }
    //cout<<dp[1-i%2];
  }
  ll re=0;
  rep(i,l+1)
    (re+=dp[n%2][i])%=MOD;
  cout<<re<<endl;
  return 0;
}

Measured memory_bytes: 1336
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <string>
#define LL long long

using namespace std;
double L;
int main()
{
    cin >>L;
    printf("%.8f\n",(L/3)*(L/3)*(L/3));


    return 0;
}


Measured memory_bytes: 256
from heapq import heappush, heappop

N, M, Start, Goal = map(int, input().split())
Start -= 1
Goal -= 1
adj_list = [[] for _ in range(N)]
for i in range(M):
  u, v, yen, sunuke = map(int, input().split())
  u -= 1
  v -= 1
  adj_list[u].append([u, v, yen, sunuke])
  adj_list[v].append([v, u, yen, sunuke])

def dijkstra(start, changed):
  res = [ -1 for _ in range(N) ]
  q = [[0, start]]
  visited = {}

  while len(q)>0:
    money, city = heappop(q)
    if res[city]>=0:
      continue
    res[city] = money

    for from_city, to_city, yen, sunuke  in adj_list[city]:
      if res[to_city]<0:
        cost = sunuke if changed else yen
        heappush(q, [money+[yen, sunuke][changed], to_city])
        

  return res


min_yen_path = dijkstra(Start, 0)
min_sunuke_path = dijkstra(Goal, 1)

res = []
max_sunuke = 0
for i in reversed(range(N)):
  s = 10**15-min_yen_path[i]-min_sunuke_path[i]
  max_sunuke = max([s, max_sunuke]) 
  res.append(max_sunuke)
  
for i in reversed(res):
  print(i)


Measured memory_bytes: 64856
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cassert>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <iostream>
#include <numeric>

/* debug macros */
#ifdef WAFDAYO
#define DBG_LINE() {std::cerr<<"\e[2m[L"<<__LINE__<<"]\e[m ";}
#define DBG_PRINT(s,t,u) {std::cerr<<(s)<<" \e[2m=\e[m \e[1m"<<(t)<<"\e[m"<<(u);}
#define SELECT_7TH(x1,x2,x3,x4,x5,x6,x7,...) x7
#define dbg1(x1) DBG_PRINT(#x1,x1,std::endl)
#define dbg2(x1,x2) DBG_PRINT(#x1,x1,", ")dbg1(x2)
#define dbg3(x1,x2,x3) DBG_PRINT(#x1,x1,", ")dbg2(x2,x3)
#define dbg4(x1,x2,x3,x4) DBG_PRINT(#x1,x1,", ")dbg3(x2,x3,x4)
#define dbg5(x1,x2,x3,x4,x5) DBG_PRINT(#x1,x1,", ")dbg4(x2,x3,x4,x5)
#define dbg6(x1,x2,x3,x4,x5,x6) DBG_PRINT(#x1,x1,", ")dbg5(x2,x3,x4,x5,x6)
#define dbg(...) DBG_LINE()\
SELECT_7TH(__VA_ARGS__,dbg6,dbg5,dbg4,dbg3,dbg2,dbg1)(__VA_ARGS__)
#else
#define dbg(...) {}
#endif

/* utility functions */
struct read_item{read_item(){};
template<class T>operator T(){T t;std::cin>>t;return t;}};
char splf(int i,int n){return(i+1<n)?' ':'\n';};
template<bool up>
struct _RI{int i;_RI(int a):i(a){}
int operator*(){return i;}void operator++(){i+=(up?1:-1);}
bool operator!=(const _RI& r){return up?i<r.i:i>=r.i;}};
template<bool up>
struct _RX{_RI<up> x,y;_RI<up> begin(){return x;}_RI<up> end(){return y;}
_RX(int a,int b):x(up?a:(a-1)),y(b){}_RX(int a):_RX(up?0:a,up?a:0){}};
typedef _RX<true> range;
typedef _RX<false> revrange;

/* types and constants */
typedef int64_t i64;
typedef uint64_t u64;
// const i64 inf = (i64)1.05e18;
// const int inf = (int)1.05e9;

using namespace std;

void search(string& cur, int kind, int n, vector<string>& ans) {

	int len = cur.size();
	if(len == n) {
		ans.push_back(cur);
		return;
	}

	cur.push_back('a');
	for(int i = 0; i <= kind; i++) {
		cur[len] = 'a' + i;
		search(cur, max(i + 1, kind), n, ans);
	}
	cur.pop_back();
	return;
}

int main() {

	const int N = read_item();
	string s;
	vector<string> ans;

	search(s, 0, N, ans);
	for(auto& a : ans) {
		printf("%s\n", a.c_str());
	}

	return 0;
}

/* wafdayo~~~ */


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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n,m,x; cin>>n>>m>>x;
	vector<bool>a(n+1,false);
	for(int i=0;i<m;++i){
		int A; cin>>A;
		a.at(A)=true;
	}
	int ans1=0;
	for(int i=x;i<=n;++i){
		if(a.at(i))++ans1;
	}
	int ans2=0;
	for(int i=x;i>=0;--i){
		if(a.at(i))++ans2;
	}
	cout<<min(ans1,ans2)<<"\n"s;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
	int yama[10];
	int i,j,dumy;

	for(i=0;i<10;i++){
	scanf("%d",&yama[i]);
	}

	for(i = 0; i < 9; i++){
		for(j = i + 1; j < 10; j++){
			if(yama[i] < yama[j]){
				dumy = yama[i];
				yama[i] = yama[j];
				yama[j] = dumy;
			}
		}
	}

	printf("%d\n",yama[0]);
	printf("%d\n",yama[1]);
	printf("%d\n",yama[2]);
	return 0;
}

Measured memory_bytes: 600
h, w, k  = map(int, input().split())

puyo_orig = [[0]*w for _ in range(h+1)]
for i in range(1,h+1):
    puyo_orig[i] = list(map(int, list(input())))

import copy
mx = 0
for i1 in range(2,h+1):
    for i2 in range(w):
        puyo = copy.deepcopy(puyo_orig)
        for l in range(i1,0,-1):
            puyo[l][i2] = puyo[l-1][i2]
        p = 0
        fin = 0
        turn = 0
        while fin==0:
            fin = 1
            for i in range(2,h+1):
                cnt = 1
                for j in range(w-1):
                    if puyo[i][j+1] == puyo[i][j] and puyo[i][j]>0:
                        cnt += 1
                    else:
                        if cnt>=k:
                            p += cnt * puyo[i][j] * 2**turn
                            for l in range(i,0,-1):
                                puyo[l][j-cnt+1:j+1] = puyo[l-1][j-cnt+1:j+1]
                            fin = 0
                        cnt = 1
                    if j==w-2:
                        if cnt>=k:
                            p += cnt * puyo[i][j] * 2**turn
                            for l in range(i,0,-1):
                                puyo[l][j-cnt+2:] = puyo[l-1][j-cnt+2:]
                            fin = 0
            turn += 1
        if p>mx:
            mx=p
            
print(mx)


Measured memory_bytes: 57180
import java.util.*;

public class Main {
	Scanner in = new Scanner(System.in);
	public static void main(String[] args) {
		new Main();
	}

	public Main(){
		new AOJ1135().doIt();
	}
	
	class AOJ1135{
		int nen,n,kin;
		Data[] data;
		
		int tanri(Data d){
			int result = 0;
			int a = kin;
			int b = 0;
			for(int i=0;i<nen;i++){
				b += (int)(a*d.ri);
				a -= d.mkin;
			}
			result = a+b;
			return result;
		}
		
		int fukuri(Data d){
			int result = 0;
			int a = kin;
			for(int i=0;i<nen;i++){
				a = (int)(a*(1+d.ri));
				a-=d.mkin;
			}
			result = a;
			return result;
		}
		
		void solve(){
			int result = -1;
			for(int i=0;i<n;i++){
				if(data[i].fukuri)result = Math.max(result, fukuri(data[i]));
				else result = Math.max(result, tanri(data[i]));
			}
			System.out.println(result);
		}
		
		void doIt(){
			int m = in.nextInt();
			for(int i=0;i<m;i++){
				kin = in.nextInt();
				nen = in.nextInt();
				n = in.nextInt();
				data = new Data[n];
				for(int s=0;s<n;s++)data[s] = new Data(in.nextInt(),in.nextDouble(), in.nextInt());
				solve();
			}
		}
		class Data{
			double ri,mkin;
			boolean fukuri;
			public Data(int which,double ri,int mkin){
				fukuri = which==1;
				this.ri = ri;
				this.mkin = mkin;
			}
		}
	}
	
}

Measured memory_bytes: 42000
#define _USE_MATH_DEFINES
     
#include <list>
#include <map>
#include <unordered_map>
#include <set>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <memory.h>
#include <ctime>
#include <bitset>
#include <vector>
#include <string>
#include <queue>

using namespace std;

void solution() {
    for (int i = 0; i < 5; i++) {
        int x;
        cin >> x;
        if (x == 0) {
            cout << i + 1 << endl;
        }
    }
}

/*-------------------*/

int main()
{
#ifdef Files
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    /*Test*/
    //freopen("input.txt", "w", stdout);
           
    double OcZ2X = clock();
#else
    //freopen("joke.in", "r", stdin);
    //freopen("joke.out", "w", stdout);
#endif

/*
　　     　 　          ∧_,,∧　　　
    　            ♪　  (・ω・)　♪
               ＿＿＿＿○＿＿つヾ＿＿＿＿＿
             /δ⊆・⊇ 。/†: :† /δ ⊆・⊇｡ /|
            |￣￣￣￣￣￣￣￣￣￣￣￣￣ | |
            |　　　*/solution();/* 　　| |
            |　　　　　　　　　　　　　 |
*/

#ifdef Time
double P2HxQ = clock();
printf("\n*** Total time = %.3f sec ***\n", (P2HxQ - OcZ2X) / CLOCKS_PER_SEC);
#endif
}

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

int main() {
    int n,m;
    cin>>n>>m;
    cout<<n*(n-1)/2+m*(m-1)/2<<endl;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String args[]) {

        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        String[] a = new String[n];
        for (int i = 0; i < n; i++) {
            int cost = Integer.parseInt(sc.next());
            int time = Integer.parseInt(sc.next());
            a[i] = String.format("%010d", time) + "/" + cost;
        }

        Arrays.sort(a);
        int task = 0;
        boolean result = true;
        for (String s : a) {
            String[] info = s.split("/");
            int time = Integer.parseInt(info[0]);
            task += Integer.parseInt(info[1]);
            if (time < task) {
                result = false;
                break;
            }
        }

        System.out.println(result ? "Yes" : "No");
    }
}

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

using namespace std;

using ll = long long;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    string tmp = "", prv = "";
    int cnt = 0;
    for (char c : s) {
        tmp += c;
        if (prv != tmp) {
            cnt++;
            prv = tmp;
            tmp = "";
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 720
import collections

N,K=map(int,input().split())
A=list(map(int,input().split()))

ans=0
A_=set(A)
if len(A_)<=K:
    pass
elif len(A_)>K:
    r=len(A_)-K
    A_Cnt=collections.Counter(A)
    A_Cnt_Sort=A_Cnt.most_common()[::-1]
    for a in A_Cnt_Sort[:r]:
        ans+=a[-1]

print(ans)

Measured memory_bytes: 50488
using System;
using System.Numerics;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = long.Parse(Console.ReadLine());
            Console.WriteLine(Resolve(n));
        }
        private static long Resolve(long n)
        {
            long A = 1;
            long B = 1;
            long C1 = 1;
            long C2 = 1;

            long mod = 1000000000 + 7;
            long res = 1;// 1000000000 + 7;

            for (long i = 0; i < n; ++i) {
                A = (10 * A) % mod;
                B = (8 * B) % mod;
                C1 = (9 * C1) % mod;
                C2 = (9 * C2) % mod;
            }
            return (A - C1 - C2 + B + mod+mod)%mod;
        }
    }
}


Measured memory_bytes: 27452
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64

signed main() {
  int n,m;cin>>n>>m;
  vector<string> a(n),b(n);
  for(int i=0;i<n;++i){
    cin>>a[i];
  }
  for(int i=0;i<n;++i){
    cin>>b[i];
  }

  int ans = 0;
  for(int hi=0;hi<n;++hi){
    for(int wi=0;wi<m;++wi){
      if(a[hi][wi]!=b[hi][wi]) ++ans;
    }
  }
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 11016
#include <stdio.h>
int main()
{
    long int a,b,W;
    scanf("%ld%ld%ld",&W,&a,&b);
    ((a<=b)&&(b<=a+W)) || ((b<=a)&&(a<=b+W))?puts("0"):printf("%ld\n",(b-a-W)>(a-b-W)?(b-a-W):(a-b-W));
    return 0;
}

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

int main() {
    int n; cin >> n;
    string s; cin >> s;
    s = "0" + s;
    vector<int> dp(n + 1);
    vector<int> v, w;
    int pv = 0;
    for (int i = 1; i <= n; ++i) {
        if (i > 0) dp[i] = dp[i - 1];
        if (s[i] == '1') {
            int g = i - pv;
            if (!v.empty()) {
                dp[i] = max(dp[i], w[min(g - 1, (int)w.size() - 1)] + i - pv);
                if (g < v.size()) dp[i] = max(dp[i], pv + v[g]);
            }
        }
        if (s[i] == '0') {
            v.clear();
            w.clear();
            for (int j = pv + 1; j < i; ++j) v.push_back(dp[j - 1] - j);
            for (int j = pv + 1; j < i; ++j) w.push_back(dp[j - 1]);
            reverse(v.begin(), v.end());
            reverse(w.begin(), w.end());
            for (int j = 1; j < w.size(); ++j) w[j] = max(w[j], w[j - 1]);
            for (int j = (int)v.size() - 2; j >= 0; --j) v[j] = max(v[j], v[j + 1]);
            pv = i;
        }
    }
    cout << dp[n] << "\n";
}


Measured memory_bytes: 7312
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(n, m, s, t, UVAB):
    g = defaultdict(list)
    for u, v, a, b in UVAB:
        g[u].append((v, (a, b)))
        g[v].append((u, (a, b)))

    def d(s, ck):
        dist = [0 if s == i else sys.maxsize for i in range(n+1)]
        # p = [None for i in range(n+1)]
        q =[]
        heapq.heappush(q, (dist[s], s))
        while q:
            c, u = heapq.heappop(q)
            if dist[u] > c:
                continue
            for v, cost in g[u]:
                alt = dist[u] + cost[ck]
                if dist[v] > alt:
                    dist[v] = alt
                    heapq.heappush(q, (alt, v))
        return dist

    dist0 = d(s, 0)
    dist1 = d(t, 1)

    ans = [sys.maxsize] * (n+1)
    
    for i in range(n-1, -1, -1):
        # print(i)
        ans[i] = min(ans[i+1], dist1[i+1] + dist0[i+1])
    c = 10**15
    return '\n'.join(map(lambda x: str(c-x), ans[:-1]))


def main():
    n, m, s, t = read_int_n()
    UVAB = [read_int_n() for _ in range(m)]

    
    print(slv(n, m, s, t, UVAB))


if __name__ == '__main__':
    main()


Measured memory_bytes: 131540
// Problem : C - Sqrt Inequality
// Contest : Panasonic Programming Contest 2020
// URL : https://atcoder.jp/contests/panasonic2020/tasks/panasonic2020_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cp-editor)

/*
 * author :Sadik Hassan
 * 
*/
#include "bits/stdc++.h"
using namespace std;
#define ll            long long
#define nl            "\n"
#define PB            push_back
#define fi            first
#define se            second
#define _SAD()        ios::sync_with_stdio(0),cin.tie(0), cout.tie(0);
#define rep(i,n)      for(int i=0;i<n;i++)
#define repn(i,n)     for(int i=1;i<=n;i++)
#define rrep(i,n)     for(int i=n-1;i>=0;i--)
#define SZ(s)         s.size()
#define SRT(x,y)      sort(x,x+y)
#define REV(a,b)      reverse(a,a+b)
#define VSRT(x)       sort(x.begin(),x.end())
#define VREV(x)       reverse(x.begin(),x.end())
#define TSFL(s)       transform(s.begin(),s.end(),s.begin(),::toupper);
#define TSFH(s)       transform(s.begin(),s.end(),s.begin(),::tolower);
/*---------------------------------------------------------------------*/
const int N = 2e5+10;
const int INF = (int)1e9+5;

int main()
{
    _SAD()
	ll a,b,c;
	cin>>a>>b>>c;
	ll ans=c-a-b;
	if(ans>0&&ans*ans>4*a*b)
	{
		cout<<"Yes"<<nl;
	}
	else
	{
		cout<<"No"<<nl;
	}
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n,i,ans,min;
	cin >> n;
	vector<int> v(n+1);
	for(i=1;i<=n;i++)
	{
		cin >> v[i];
	}
	ans=1,min=v[1];
	for(i=2;i<=n;i++)
	{
		if(v[i]<min)
		{
			ans++;
			min = v[i];
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  string s;
  cin >> s;
  if(s.at(0)==s.at(1)||s.at(1)==s.at(2)||s.at(2)==s.at(3))
    cout << "Bad" << endl;
  else
    cout << "Good" << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long n,INF=1e18,a[401],sum[401],dp[401][401];
int main()
{
    cin >> n;
    for(int i=1; i<=n; i++)
        cin >> a[i],sum[i] = sum[i-1] + a[i];
    for(int i=1; i<=n; i++) for(int j=1; j<=n; j++) dp[i][j] = INF;
    for(int i=1; i<=n; i++)
    {
        for(int j=1; j<=n; j++)
        {
            if(i + j - 1 > n) break;
            if(i == 1) dp[i][j] = 0;
            else
            {
                int l = j;
                int r = i + j - 1; 
                for(int k=l; k<r; k++)
                {
                    int size1 = k - l + 1; 
                    int size2 = r - k;
                    long long x1=INF,x2=INF;
                    x1 = sum[k] - sum[l-1];
                    x2 = sum[r] - sum[k]; 
                    dp[i][j] = min(dp[i][j],x1 + x2 + dp[size1][l] + dp[size2][k+1]);
                }
            } 
        }
    }
    cout << dp[n][1] << endl;
}

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

ll X;

int main(){
	cin>>X;
	ll sum=0,ans=0;
	while(sum<X){
		sum+=ans+1;
		ans++;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <cmath>
using namespace std;
using Int = long long;
int main()
{
    int q;
    cin >> q;
    for (int i = 0; i < q; i++) {
        Int a, b;
        cin >> a >> b;
        if (a > b) swap(a, b);
        if (a == b || a + 1 == b) {
            cout << 2*a - 2 << endl;
        } else {
            Int c = sqrt(a * b);
            if (c*c == a*b) c--;
            if (c * (c + 1) >= a * b) {
                cout << 2*c - 2 << endl;
            } else {
                cout << 2*c - 1 << endl;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    for(int i=0;i<s.length();i++)
    {
        if(s[i]=='1') s[i] = '9';
        else if(s[i]=='9') s[i] = '1';
    }
    cout<<s<<endl;
    return 0;
}


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

//#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

ll n,x;
vl t,p;
ll dfs(ll n,ll x){
  if(n == 0)return 1;
  else if(x == 1)return 0;
  else if(1 < x && x<= 1+t[n-1]) return dfs(n-1,x-1);
  else if(x==2+t[n-1]) return p[n-1]+1;
  else if(2+t[n-1] < x && x<3+2*t[n-1]) return p[n-1]+1+dfs(n-1,x-2-t[n-1]);
  else return 2*p[n-1]+1;
}
signed main()
{   
  gearup;
  cin >> n >> x;
  t.resize(n+1);
  p.resize(n+1);
  t[0] = 1,p[0] = 1;
  rep(i,n){
    t[i+1] = t[i]*2 + 3;
    p[i+1] = p[i]*2 + 1;
  }
  
  ll res = dfs(n,x);
  out(res);
}


Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N,*P = map(int,read().split())

INF = N+100
P = [INF,INF] + P + [INF,INF]

x_to_i = [0] * (INF+1)
for i,x in enumerate(P):
    x_to_i[x] = i

"""
・小さい方から埋めていく。
・埋めた位置に対して、「連結成分の左端」「連結成分の右端」を持つ
・区間の両端については、正しい値が入っている状態を保つ
"""

left = list(range(N+4))
right = list(range(N+4))
filled = [False] * (N+4)

answer = 0
for x,i in enumerate(x_to_i[1:N+1],1):
    filled[i] = True
    L = left[i-1] if filled[i-1] else i
    R = right[i+1] if filled[i+1] else i
    right[L] = R; left[R] = L
    # 自身より大きい場所。左右に2つずつ。
    c = i
    b = L-1; d = R+1
    a = left[L-2]-1 if filled[L-2] else L-2
    e = right[R+2]+1 if filled[R+2] else R+2
    coef = 0
    if b>=2: # 最大値をb,cとして選ぶ
        coef += (b-a)*(d-c)
    if d<=N+1:
        coef += (e-d)*(c-b)
    answer += x*coef

print(answer)

Measured memory_bytes: 20436
n=gets.to_i
s=gets.split.map &:to_i
h1=Hash.new();h2=Hash.new()
for i in 0...n
if i.odd?
  if h1[s[i]]==nil
    h1[s[i]]=1
  else
    h1[s[i]]+=1
  end
else
  if h2[s[i]]==nil
    h2[s[i]]=1
  else
    h2[s[i]]+=1
  end
end
end
ans1=h1.sort_by{|k,v|-v}.shift(2)
ans2=h2.sort_by{|k,v|-v}.shift(2)
kai1=ans1[0][1]-n/2==0? 0:ans1[1][1]
kai2=ans2[0][1]-n/2==0? 0:ans2[1][1]
if ans1[0][0]==ans2[0][0]
  puts n-([ans1[0][1]+kai1,ans2[0][1]+kai2].max)
else
  puts n-ans1[0][1]-ans2[0][1]
end


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

int main(){
  ll n,m,a,b;
  cin>>n>>m;
  dsu d(n);
  for(int i=0;i<m;i++){
    cin>>a>>b;
    a--;b--;
    d.merge(a,b);
  }
  vector<vector<int>> gr=d.groups();
  cout<<(ll)gr.size()-1<<endl;
}


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

int main () {
    string s;
    cin >> s;
    int sum = 700;

    for (int i =0; i < 3; i ++) {
        if (s[i] == 'o') {
            sum += 100;
        }
    }

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long a,b,c,d,i,e,f,g,n,m,k,l,in[200005],out[200005],C[200005],S[200005],B[22][200005],ver,u,u1,q;
vector <long long> v[200005];
string s,t;
int main()
{
           cin>>s>>t;
           for(long long i=0;i<3;i++)
           if(s[i]==t[i]) k++;
           cout<<k;
}

Measured memory_bytes: 6400
let id x = x
let n = Scanf.scanf "%d\n" id
let ar = Array.make (n+1) 0

let sum_init i =
  let rec sum i' tmp =
    if i' = (n + 1) then tmp + abs ar.(0) + abs ar.(n)
    else
      let v = Scanf.scanf "%d " id in
      let () = ar.(i') <- v in
      sum (i' + 1) (tmp + abs (v - ar.(i' - 1)))
  in
  sum 1 0

let cost = sum_init n

let skip i =
  if i = n then
    let off = abs (ar.(i) - ar.(i-1)) + abs ar.(n)
    and add = abs ar.(n-1) in
    cost - off + add
  else
    let off = abs (ar.(i) - ar.(i-1)) + abs (ar.(i + 1) - ar.(i))
    and add = abs (ar.(i + 1) - ar.(i - 1)) in
    cost - off + add


let () = for i = 1 to n do skip i |> Printf.printf "%d\n" done

Measured memory_bytes: 6400
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
class Vertex
{
    public:
    int a,b,c;
};
int main()
{
    int n;
    cin>>n;
    vector<Vertex> arr(n+1);
    for(int i=0;i<n;i++)
    {
        cin>>arr[i].a>>arr[i].b>>arr[i].c;
    }
    vector<Vertex> dp(n+1);
    dp[0].a=arr[0].a;
    dp[0].b=arr[0].b;
    dp[0].c=arr[0].c;
    for(int i=1;i<n;i++)
    {
        dp[i].a=(arr[i].a+max(dp[i-1].b,dp[i-1].c));
        dp[i].b=(arr[i].b+max(dp[i-1].a,dp[i-1].c));
        dp[i].c=(arr[i].c+max(dp[i-1].b,dp[i-1].a));
    }
   cout<<max(dp[n-1].a,max(dp[n-1].b,dp[n-1].c));
   return 0;
}

Measured memory_bytes: 2560
N = int(input())
As = []
for i in range(N):
  A = int(input())
  As.append(A)
As.sort()
if N%2 == 0:
  r = 2*sum(As[N//2+1:])-2*sum(As[:N//2-1])+As[N//2]-As[N//2-1]
if N%2 == 1:
  r1 = 2*sum(As[N//2+1:])-2*sum(As[:N//2-1])-As[N//2]-As[N//2-1]
  As.reverse()
  r2 = -2*sum(As[N//2+1:])+2*sum(As[:N//2-1])+As[N//2]+As[N//2-1]
  r = max(r1, r2)
print(r)


Measured memory_bytes: 7516
S = input()

lenmax = 0
lenACGT = 0
for s in S:
    if(s in "ACGT"):
        lenACGT += 1
    else:
        lenACGT = 0
    if(lenmax < lenACGT):
        lenmax = lenACGT
#    print("s = {}, lenACGT = {}, lenmax = {}".format(s, lenACGT, lenmax))

print(str(lenmax))


Measured memory_bytes: 2940
$n = gets.chomp.to_i
$li = gets.chomp.split.map(&:to_i)
ans = 0
(0..($n-1)).to_a.combination(3).each do |ary|
  tmp = [$li[ary[0]],$li[ary[1]],$li[ary[2]]].sort
  ans += 1 if tmp[0] + tmp[1] > tmp[2] && tmp.uniq.length == 3
end

puts ans

Measured memory_bytes: 14296
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20);} } fast;

long long mod = 1000000007;

long long modpow(long long m, long long n) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        long long t = modpow(m, n / 2);
        return t / 2;
    } else {
        return modpow(m, n - 1) * m % mod;
    }
}



int main() {
 	long long n;
    cin >> n;
    vector<long> as(n);
    map<long, long> cnt;
    for (int i = 0; i < n ; i++){
        cin >> as[i];
    }
    for (int i = 0; i < n ; i++){
        cnt[as[i]]++;
        if (cnt[as[i]] > 1){
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
}

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

using namespace std;

int main()
{
     long long int n;
     cin>>n;
     long long int a[n-1],i;
     for(i=0;i<n-1;i++)
     cin>>a[i];
     long long int b[n]={0};
    for(i=0;i<n-1;i++)
    {
        b[a[i]-1]++;
    }
    for(i=0;i<n;i++)
        cout<<b[i]<<"\n";
    return 0;
}


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

def gcd(a, b):
    while a > 0:
        if a < b:
            a, b = b, a
        a = a % b
    return b

def main():
    n, x = map(int, input().split())
    town = map(int, input().split())

    distance = (abs(x-y) for y in town)
    res = next(distance)
    for d in distance:
        if d % res != 0:
            res = gcd(res, d)

    print(res)

if __name__ == "__main__":
    main()

Measured memory_bytes: 11468
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
int a[100005];
int main(void)
{
	int n;
	scanf("%d", &n);
	for(int i = 0; i < n; i++){
		scanf("%d", &a[i]); 
	}
	long long totil = abs(a[0]);
	for(int i = 1; i < n; i++){
		totil += abs(a[i]-a[i-1]);
	}
	totil += abs(a[n-1]);
	long long l = totil;
	l -= abs(a[0])+abs(a[1]-a[0]);
	l += abs(a[1]);
	printf("%lld\n", l);
	for(int i = 1; i < n-1; i++){
		long long ans = totil;
		ans -= abs(a[i]-a[i-1])+abs(a[i+1]-a[i]);
		ans += abs(a[i+1]-a[i-1]);
		printf("%lld\n", ans);
	}
	long long r = totil;
	r -= abs(a[n-1]-a[n-2])+abs(a[n-1]);
	r += abs(a[n-2]);
	printf("%lld\n",r);
	return 0;
}

Measured memory_bytes: 1536
# 入力
N, M = map(int, input().split())
P = [0] * M
Y = [0] * M
city_list = []
for i in range(M):
    P[i], Y[i] = map(int, input().split())
    city_list.append([i, P[i], Y[i]])

# YでソートしてPでソートして識別番号つけて市番号出力
# Yでソート
city_list = sorted(city_list, key=lambda x: x[2])

# Pでソート
city_list = sorted(city_list, key=lambda x: x[1])

# 識別番号つける
# 県が同じうちは下6桁はインクリメント
city_number = [""] * M
city_count_in_prefecture = 1
for i in range(M):
    if i == 0:  # 一番最初ならば
        city_number[city_list[i][0]] = str(city_list[i][1]).zfill(6) + str(city_count_in_prefecture).zfill(6)
    elif city_list[i][1] == city_list[i - 1][1]:  # 前の市の県と同じならば
        city_count_in_prefecture += 1
        city_number[city_list[i][0]] = str(city_list[i][1]).zfill(6) + str(city_count_in_prefecture).zfill(6)
    else:  # 前の市の県と違うならば
        city_count_in_prefecture = 1
        city_number[city_list[i][0]] = str(city_list[i][1]).zfill(6) + str(city_count_in_prefecture).zfill(6)

# 市番号出力
for i in range(M):
    print(city_number[i])


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

int main(void) {
  int N, M, sum=0, cnt=0;
  cin >> N >> M;
  int A[N];
  
  for(int i=0; i<N; i++){
    cin >> A[i];
    sum += A[i];
  }
  
  for(int i=0; i<N; i++){
    if(A[i] >= (float)sum/(float)(4*M)){
      cnt++;
    }
  }
  
  if(cnt >= M) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <string>
#include <queue>
#include <numeric>
#include <ctype.h>
#include <limits>
#include <iomanip>

#define rep(i,n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(),(x).end()
using namespace std;

typedef long long ll;

int main() {
	/*int A, B;
	cin >> A >> B;
	if ((A + B) % 2 == 0)cout << (A + B) / 2;
	else cout << "IMPOSSIBLE";*/


	/*int N;
	cin >> N;
	int a, ans = 0;
	rep(i, N) {
		cin >> a;
		if (a != i + 1)ans++;

	}
	if (ans <= 2)cout << "YES";
	else cout << "NO";*/


	int N;
	cin >> N;
	vector<int>a(N + 1), b(N);
	rep(i, N + 1)cin >> a[i];
	rep(i, N)cin >> b[i];
	ll ans = 0;
	rep(i, N) {
		ans += min(a[i], b[i]);
		if (min(a[i], b[i]) == a[i]) {
			ans += min(a[i + 1], b[i] - a[i]);
			a[i + 1] -= min(a[i + 1], b[i] - a[i]);
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 1152
n = int(input())
a = list(map(int,input().split()))
q = int(input())
m = list(map(int,input().split()))

s = [list(map(int,bin(x)[2:].zfill(n))) for x in range(2**n)]

anset=set()
for j in s:
    ans=0
    for k in range(n):
        ans+=a[k]*j[k]
    anset.add(ans)

for i in range(q):
    if m[i] in anset:
        print('yes')
    else:
        print('no')



Measured memory_bytes: 248224
#define _USE_MATH_DEFINES
#include  <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include <stdlib.h>
#include<stdio.h>
#include <queue>
#include<map>
#include <sstream>
#include<set>
#include<stack>

//#include<bits/stdc++.h>


using namespace std;

int main() {
	int n, k, q;
	cin >> n >> k >> q;
	vector<int>p(n,k-q);
	for (int i = 0; i < q; i++) {
		int x;
		cin >> x; p[--x]++;
	}
	for (int i = 0; i < n; i++) {
		//cout << p[i];
		if (p[i] > 0)cout << "Yes" << endl;
		else cout << "No" << endl;
	}

	return 0;


}

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

using namespace std;

int main(){
    int n, sum = 0;
    cin >>n;
    vector<int> x(n);
    for(int i=0;i<n;i++){
        cin>>x[i];
        sum+=x[i];
    }
    int p = (int)round((double) sum / n);
    sum = 0;
    for(int i=0;i<n;i++){
        sum += (p-x[i]) *(p-x[i]);
    }
    cout <<sum;
}



Measured memory_bytes: 256
#include <iostream>
using namespace std;
void check(int now,int x,int y);
int ban[111][111];
int h,w;
int ans=11;
int main(){
  int sx,sy;
  while(1){
    ans=11;
    cin >> w >> h;
    if(w==0 && h==0)break;
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	cin >> ban[i][j];
	if(ban[i][j]==2){
	  sx=j;
	  sy=i;
	}
      }
    }
    check(1,sx,sy);
    if(ans==11){
      cout << -1 << endl;
    }else{
      cout << ans << endl;
    }
    ans=0;
  }
}

void check(int now,int x,int y){
  int dx[4]={0,1,0,-1};
  int dy[4]={1,0,-1,0};
  int nx,ny;
  if(now>=ans){//移動できなかったら
    return;
  }
  for(int i=0;i<4;i++){
    nx=x+dx[i];
    ny=y+dy[i];
    if(ban[ny][nx]==1)continue;//すぐ隣にブロックがあったら
    while(ban[ny][nx]!=1 && nx>=0 && nx<w && ny>=0 && ny<h){
      if(ban[ny][nx]==3){//ゴールだったら
	ans=now;
	return;
      }else{
	nx+=dx[i];
	ny+=dy[i];
      }
    }
    if(ban[ny][nx]==1 && nx>=0 && nx<w && ny>=0 && ny<h){//ブロック地点にきたら
      ban[ny][nx]=0;//ブロック地点を通過可能地点に
      check(now+1,nx-dx[i],ny-dy[i]);
      ban[ny][nx]=1;
    }
  }
}

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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

const int L = 500;
int k, n, c[L][L];

int main() {
	cin >> k;
	
	int n = min(k, L);
	inc(i, n) {
	inc(j, n) {
		c[i][(i + j) % n] = (i % 2 == 0 || j >= k - n ? j : j + n) + 1;
	}
	}
	
	cout << n << "\n";
	inc(i, n) {
	inc(j, n) {
		assert(c[i][j] > 0);
		cout << c[i][j] << (j == n - 1 ? "\n" : " ");
	}
	}
	
	return 0;
}


Measured memory_bytes: 2176
#include<iostream> 
#include<vector> 
#include<stack>
using namespace std;
static const int MAX = 100000;
static const int NIL = -1;

int n;
vector<int> G[MAX];
int color[MAX];

void dfs(int r, int c){

  stack<int> S;
  S.push(r);
  color[r] = c;
  while(!S.empty()){
    int u = S.top(); S.pop();
    for(int i = 0;i < G[u].size();i++){
      int v = G[u][i];
      if(color[v] == NIL){
        color[v] = c;
        S.push(v);
      }
    }
  }
}

void assignColor(){
  int id = 1;
  for(int i = 0;i < n;i++) color[i]=NIL;
  for(int u = 0;u < n;u++){
    if(color[u] == NIL) dfs(u, id++);
  }
}

int main(){
  int s, t, m, q;

  cin >> n >> m;

  for(int i = 0;i < m;i++){
    cin >> s >> t;
    G[s].push_back(t);
    G[t].push_back(s);
  }

  assignColor();

  cin >> q;

  for(int i = 0;i < q;i++){
    cin >> s >> t;
    if(color[s] == color[t]){
      cout << "yes" << endl;
    } else{
      cout << "no" << endl;
    }
  }

  return 0;
}

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}

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

    int64 N;
    cin >> N;
    using pdd = pair<double, double>;
    vector<pdd> p(N), p2;
    REP(i, N) {
        cin >> p[i].fs >> p[i].sc;
        if (p[i].fs == 0 && p[i].sc == 0) {
            continue;
        }
        p2.push_back(p[i]);
    }
    p = p2;
    sort(all(p), [](pdd a, pdd b) {
        return atan2(a.sc, a.fs) < atan2(b.sc, b.fs);
    });
    double res = 0;
    REP(i, p.size()) {
        REP(j, p.size()) {
            pdd now = p[i];
            int64 id = (i+1)%p.size();
            while (id != j) {
                now = pdd(now.fs + p[id].fs, now.sc + p[id].sc);
                id = (id + 1) % p.size();
            }
            chmax(res, now.fs * now.fs + now.sc * now.sc);
        }
    }
    cout << fixed << setprecision(10) << sqrt(res) << endl;
}


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

int main(){int N, Y; int cnt = 0;
cin >> N >> Y;
rep(i, N + 1){
    rep(j, N - i + 1){
        // if(10000 * i + 5000 * j > Y) break;
        // else{
            int z = (Y - (10000 * i + 5000 * j)) / 1000;
            if(z == N - i - j){
                cout << i << ' ' << j << ' ' << z;
                return 0;
            // }
        }
    }
}
cout << -1 << ' ' << -1 << ' ' << -1;

// cout << ans << endl;
  return 0;
 
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){

  int a,b,c,x;
  scanf("%d%d%d",&a,&b,&c);

  if(a>b) {
    x=a;
    a=b;
    b=x;
  }

  if(b>c){
    x=b;
    b=c;
    c=x;
  }

  if(a>b) {
    x=a;
    a=b;
    b=x;
  }
  
  printf("%d %d %d\n",a,b,c);
  return 0;
}

Measured memory_bytes: 596
#include <stdio.h>

#define N 100000

int main() {
	static char s[N + 1];
	int n, i, j, k;

	scanf("%d%s", &n, s);
	k = 0;
	for (i = 0; i < n; ) {
		j = i + 1;
		while (j < n && s[j] == s[i])
			j++;
		k++;
		i = j;
	}
	printf("%d\n", k);
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

template<typename T>
using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

const int infI=1e9+5;
const long long infL=1e16;
const int MOD=1e9+7;
const int MAX=2e5+5;

#define mp make_pair
#define pb push_back
#define ii pair<int,int>
#define iii pair<ii,int>
#define ll long long
#define pll pair<ll,ll>
#define vi vector<int>
#define vvi vector<vector<int> >
#define vl vector<ll>
#define forn(i,a,b) for(ll i=a;i<b;i++)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define endl '\n'
#define popb pop_back()
#define se second
#define fi first
#define test(t) int t;cin>>t;while(t--)
#define debug(x) cerr<<"=>"<<#x<<" = "<<x<<endl

ll power(ll a,ll b){
    if(b==0){
        return 1;
    }
    if(b==1){
        return a;
    }
    ll temp=power(a,b/2);
    temp=(temp*temp)%MOD;
    if(b%2){
        temp=(temp*a)%MOD;
    }
    return temp;
}

//only use if mod is prime
ll mod_inv(ll a,ll mod){
    a%=mod;
    return power(a,mod-2);
}

void extended_gcd(ll a,ll b,ll &x,ll &y){
    if(b==0){
        x=1;
        y=0;
        return;
    }
    ll x1,y1;
    extended_gcd(b,a%b,x1,y1);
    x=y1;
    y=x1-((a/b)*y1);
    return;
}

//TLE can also occur if vectors are not passed by reference, debug statements can also cause TLE.
//priority_queue implements max heap by default

int main(){
    fastio;
    // think about edge cases like n=1(especially graph questions).
    int n;
    cin>>n;
    vl a(n);
    for(auto &x:a){
        cin>>x;
    }
    sort(a.begin(),a.end());
    ll ans = a[n-1];
    ll ind = n-2,lst=0;
    for(int i = 2;i<n;i++){
        if(lst == 2){
            lst = 0;
            --ind;
        }
        ans+=a[ind];
        ++lst;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 4784
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

#define SIZE 100005
#define PI acosl(-1) //3.14159265358979323846264338327950L 
#define rep(i, N) for (i = 0; i < N; i++) //制御変数iを用いてN回転
#define array(N, t) (t*)calloc(N, sizeof(t)) //t型N要素の1次元配列を動的確保後0クリア(freeを忘れずに)
#define zero(a); {int iter; rep(iter, sizeof(a)/sizeof((a)[0])) (a)[iter]=0;} //1次元配列aのゼロ初期化?

typedef long long ll; typedef long double ld;
typedef struct node { int data; struct node *next; } Node;

Node *list[SIZE];
int queue[SIZE]; int q_head = 0, q_tail = 0;

void print_log(); //とりあえず文字を出力してどこまで実行できているか確認(for debug)
void printa_int(int *a, int size); //int型の1次元配列aを出力(for debug)
void printl_int(int size); //リンクリストを出力(for debug)
Node* add_node(int i, int data); void free_list(Node* head);
int queue_empty(); int queue_full();
void enqueue(int data); int dequeue();
ll* factorize(ll N); //Nを素因数分解、得られる配列は素因数,指数,素因数,…となっている(添字はintで指定する必要あり?)
void check_factorization(ll *fact); //素因数分解を表示(for debug)

int main() {
    int i, X, Y;
    scanf("%d %d", &X, &Y);
    if (Y % 2 == 0 && Y >= 2 * X && Y <= 4 * X) printf("Yes\n");
    else printf("No\n");
    return 0;
}

void print_log() {
    printf("=== print log ===\n");
}
void printa_int(int *a, int size) {
    int i;
    printf("[");
    for (i = 0; i < size; i++)
        printf("%d, ", a[i]);
    printf("]\n");
}
void printl_int(int size) {
    int i;
    Node *t;
    rep(i, size) {
        printf("[%d] ", i);
        for (t = list[i]; t; t = t->next) printf("%d, ", t->data);
        printf("\n");
    }
}
Node* add_node(int i, int data) {
    if (!list[i]) {
        list[i] = (Node*)malloc(sizeof(Node*));
        list[i]->data = data;
    } else {
        Node *t;
        t = list[i];
        list[i] = (Node*)malloc(sizeof(Node*));
        list[i]->data = data;
        list[i]->next = t;
    }
    return list[i];
}
void free_list(Node* head) {
    Node *prev = NULL, *t = head;
    while (t) {
        prev = t;
        t = t->next;
        free(prev);
    }
}
int queue_empty() {
    return q_head == q_tail;
}
int queue_full() {
    return (q_head - 1) % SIZE == q_tail % SIZE;
}
void enqueue(int data) {
    if (queue_full()) {
        printf("full!\n");
        return;
    }
    queue[q_tail++] = data;
    q_tail %= SIZE;
}
int dequeue() {
    if (queue_empty()) {
        printf("empty!\n");
        return -444444;
    }
    int data = queue[q_head++];
    q_head %= SIZE;
    return data;
}
ll* factorize(ll N) {
    ll *res = array(((sqrt(N) + 1) * 2), ll);
    ll i, x = N;
    int count = 0;
    for (i = 2; i * i <= N; i++) {
        ll e = 0;
        while (x % i == 0) {
            x /= i;
            e++;
        }
        if (e > 0) {
            res[count * 2] = i;
            res[count * 2 + 1] = e;
            count++;
        }
    }
    if (x > 1) {
        res[count * 2] = x;
        res[count * 2 + 1] = 1;
    }
    return res;
}
void check_factorization(ll *fact) {
    int i = 1;
    printf("%lld^%lld", fact[0], fact[1]);
    while (fact[i * 2] > 0) {
        printf(" * %lld^%lld", fact[i * 2], fact[i * 2 + 1]);
        i++;
    }
    printf("\n");
}

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

int w,h;
string s[100];
int ans;

void solve(int y,int x){
  int dx[] = {0,0,1,-1};
  int dy[] = {1,-1,0,0};

  if(x < 0 || y < 0 || x == w || y == h) return;

  if(s[y][x] == '#') return;

  s[y][x] = '#';

  ans++;

  for(int i=0;i<4;i++) solve(y+dy[i],x+dx[i]);

}

int main(){

  while(true){
    cin >> w >> h;
    if(!w && !h) break;
    ans = 0;

    for(int i=0;i<h;i++) cin >> s[i];

    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	if(s[i][j] == '@') solve(i,j);
      }
    }

    cout << ans << endl;

  }
}

Measured memory_bytes: 1220
from collections import defaultdict
from collections import Counter

H, W, N = map(int, input().split())

# 3*3マスの処理用リスト
dir = [[0, 0], [1, 0], [1, 1], [0, 1], [-1, 1],
       [-1, 0], [-1, -1], [0, -1], [1, -1]]

# そのマスを中心とする3*3グリッドに含まれる黒マスの数
dict = defaultdict(int)

for i in range(N):
    a, b = map(int, input().split())
    for dy, dx in dir:
        # 3*3グリッドは、H*Wの中に完全に含まれていなければならないことに注意
        if 2 <= a + dy <= H - 1 and 2 <= b + dx <= W - 1:
            dict[(a + dy, b + dx)] += 1

c = Counter(dict.values())
ans = [0 for _ in range(10)]

# ans[1], ans[2], ..., ans[9]を確定させる（ans[0]は後述）
for k, v in c.items():
    if v > 0:
        ans[k] = v

# 全体で作れる3*3グリッドは(H-2)*(W-2)個
# ans[1],...,ans[9]の総和を引くとans[0]になる
ans[0] = (H - 2) * (W - 2) - sum(ans[1:])

for i in range(10):
    print(ans[i])


Measured memory_bytes: 164448