akhauriyash/Code-Regression huggingface dataset:
n,m = map(int,input().split())

s = [0]*n
g = [0]*n

for i in range(m):
    a,b = map(int,input().split())
    if a == 1:
        s[b] = 1
    if b == n:
        g[a] = 1
for i in range(n):
    if s[i] and g[i]:
        print("POSSIBLE")
        exit()

print("IMPOSSIBLE")

Measured memory_bytes: 6132
def sum_digit(N):
    res = N%10
    while N//10 > 0:
        N = N//10
        res += N%10
    return res


if __name__ == '__main__':
    N, A, B = map(int, input().split())

    answer = 0
    for i in range(1,N+1):
        if A <= sum_digit(i) <= B:
            answer += i
    print(answer)

Measured memory_bytes: 3064
H,W = map(int,input().split())
mas = [input() for i in range(H)]
dx = [-1, 0, 1, -1, 0, 1, -1, 0, 1]
dy = [-1, -1, -1, 0, 0, 0, 1, 1, 1]

ans = []
for i in range(H) :
    ans.append(['#'] * W)

for h in range(H) :
    for w in range(W) :
        c = 0
        if mas[h][w] == '#':
            continue
        for i in range(9) :
            if w + dx[i] < 0 or h + dy[i] < 0 or w + dx[i] > W - 1 or h + dy[i] > H - 1:
                continue
            if mas[h+dy[i]][w+dx[i]] == '#' :
                c += 1
        ans[h][w] = c

for a in ans :
    b = map(str, a)
    print(''.join(b))

Measured memory_bytes: 3064
module Main where

import Data.List
import Control.Monad
import Debug.Trace
import qualified Data.ByteString.Char8 as BC
import Data.Maybe (fromJust, catMaybes)
import qualified Data.Vector as V


readTuple2 :: IO (Int, Int)
readTuple2 = do
    [a, b] <- map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine
    return (a, b)

readTuple3 :: IO (Int, Int, Int)
readTuple3 = do
    [a, b, c] <- map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine
    return (a, b, c)

readInt :: IO Int
readInt = fst . fromJust . BC.readInt <$> BC.getLine

readInts :: IO [Int]
readInts = do
    strs <- BC.words  <$> BC.getLine
    let bcList = catMaybes $ (BC.readInt <$> strs)
    pure $ fst <$> bcList

onOffLists :: Int -> Int -> [[Int]]
onOffLists i m = if i == m then [[0], [1]] else
    let
        prevLists = onOffLists (i + 1) m
    in
        [(1:), (0:)] <*> prevLists

checkVector :: [([Int], Int)] -> V.Vector Int -> Bool
checkVector ss v = all checker ss where
    checker (s,p) = ((foldr (\si acc -> (v V.! (si - 1) ) + acc ) 0 s) `mod` 2) == p

split :: (a -> Bool) -> [a] -> [[a]]
split f [] = []
split f as = let
    (fo, la) = span f as
    las = case la of
        [] -> []
        xs -> split f $ tail xs
    in
        case fo of
            [] -> las
            xs -> xs : las

solve :: [Int] -> Int
solve [] = 0
solve hs = let
    lowest = minimum hs
    waterGiven = fmap (\a -> a - lowest) hs
    newGroups = split (/=0) waterGiven
    in
        lowest + (sum $ solve <$> newGroups)


main = do
    _ <- getLine
    hs <- readInts
    print $ solve hs



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

int main() {
  string S;
  cin >> S;
  
  for(int i=0;i<S.size();i++){
    if(i%2==0 && S[i]=='L'){
      cout << "No" << endl;
      return 0;
    }
    if(i%2==1 && S[i]=='R'){
      cout << "No" << endl;
      return 0;
    }
  }
  
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 256
// https://atcoder.jp/contests/nomura2020/tasks/nomura2020_b

#include "algorithm"
#include "bitset"
#include "cmath"
#include "functional"
#include "iomanip"
#include "iostream"
#include "map"
#include "numeric"
#include "queue"
#include "set"
#include "string"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define rep1(i, to) for (ll i = 1; i <= (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define unless(cond) if (!(cond))
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
using VVL = V<VL>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;

template <typename T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

template <typename T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

template <typename T>
inline ll len(V<T> arr) {
  return arr.size();
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}

const ll INF = 1e18;

void solve();

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

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

void solve() {
  string T;
  cin >> T;

  string res = T;
  rep(i, T.size()) {
    if (T[i] == '?') res[i] = 'D';
  }

  cout << res << "\n";
}


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

#define ll long long
#define mod 1000000007
#define eb emplace_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fo(i,n) for(i=0;i<n;i++)
#define fok(i,k,n) for(i=k;i<n;i++)
#define dbg(x) cout<<#x<<" "<<x
#define sci(x) scanf("%d",&x)
#define scd(x) scanf("%lf",&x)
#define scl(x) scanf("%lld",&x)
#define pfi(x) printf("%d",x)
#define pfd(x) printf("%lf",x)
#define pfl(x) printf("%lld",x)


auto fatafat=[](){std::ios_base::sync_with_stdio(false); std::cin.tie(0); std::cout.tie(0); return 0;}();

// int maxGain(int n,int lastIndex,vector<vector<int>> v,int currentRow,vector<vector<int>> dp)
// {
//     if(currentRow>=n)
//         return 0;
//     if(dp[currentRow][lastIndex]!=-1)
//         return dp[currentRow][lastIndex];
    
//     int ans=0;
//     for(int i=0;i<3;i++)
//     {
//         if(i==lastIndex)
//             continue;
//         ans=max(ans,v[currentRow][i] + maxGain(n,i,v,currentRow+1,dp));
//         dp[currentRow][i]=max(dp[currentRow][i],ans);
//     }
    
//     return ans;
// }

int maxGain(int n,int lastCol,vector<vector<int>> &v,int currentRow,vector<vector<int>> &dp)
{
    for(int i=0;i<3;i++)
    {
        dp[0][i]=v[0][i];
        
    }
    
    int temp=0;
    for(int i=1;i<n;i++)
    {
        for(int j=0;j<3;j++)
        {
            temp=0;
            for(int k=0;k<3;k++)
            {
                if(k==j) continue;
                dp[i][j]=max(dp[i][j],v[i][j]+dp[i-1][k]);
            }
            
        }
    }
    
    
    return *max_element(dp[n-1].begin(),dp[n-1].end());
    
    
}



int main()
{
   
    int n;
    cin>>n;
    vector<vector<int>> v(n);
    for(int i=0;i<n;i++)
    {
        v[i].resize(3);
        for(int j=0;j<3;j++)
        {
            cin>>v[i][j];
        }
    }
    
    vector<vector<int>>dp(n);
    for(int i=0;i<n;i++)
    {
        dp[i].resize(3,-1);
    }
    
    
    cout<<maxGain(n,0,v,n-1,dp);
    
    
    
    
    
    
}

Measured memory_bytes: 11264
#include <iostream>
#include <cmath>

using namespace std;

int nc(int a)
{
    int x=0;
    while(a!=0)
    {
        a/=10;
        x++;
    }
    return x;
}

int main()
{
    int a,b,c=1;
    cin>>a>>b;
    for(int i=0;i<nc(b);i++)
        c*=10;
    int x=round(sqrt(a*c+b));
    if(x*x==a*c+b)
    {
        cout<<"Yes";
    }
    else
    {
        cout<<"No";
    }
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int i,j,w,h;
	while(1)
	{
		scanf("%d %d",&w,&h);
		if(w==0&&h==0)
		break;
		for(i=1;i<=w;i++)
		{
			for(j=1;j<=h;j++)
			{
				printf("#");
			}
			printf("\n");
		}
		printf("\n");	
	}
}


Measured memory_bytes: 2072
#include <bits/stdc++.h>
#define int int64_t
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++ (i))
#define REP_R(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define REP3R(i, m, n) for (int i = (int)(n) - 1; (i) >= (int)(m); -- (i))
#define REPP(i, n) for (int i = 1; (i) < (int)(n+1); ++ (i))
#define REPR(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i=(m)-1; i>=(n); i--)
#define ALL(v) v.begin(), v.end()
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())
#define SORTR(c) sort((c).begin(),(c).end(),greater<int>());
#define BIT(n) (1LL<<(n))
#define PCNT(x) __builtin_popcountll(x)
#define GCD(x,y) __gcd(x,y)
#define LCM(x,y) x/__gcd(x,y)*y
#define PB push_back
#define MP make_pair
#define endl "\n"
#define pa cout << ans << endl
#define p(x) cout << x << endl
#define pall(x) for(auto iter : x) p(iter)
#define yes cout << "Yes" << endl
#define no cout << "No" << endl
#define yn(x) cout << (x ? "Yes" : "No") << endl
using namespace std;
using Graph = vector<vector<int> >;
using WeightedGraph = vector<vector<pair<int, int> > >;
typedef long double LD;
typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
const int INF = 2000000000;
const long double PI = acosl(-1);
const int MOD = 1000000007;
void print() {cout << endl;}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head; if (sizeof...(tail) != 0) cout << " ";print(forward<Tail>(tail)...);}
template <class T> void print(vector<T> &vec) {for (auto& a : vec) {cout << a; if (&a != &vec.back()) cout << " ";} cout << endl;}
template <class T> void print(vector<vector<T>> &df) { for (auto& vec : df) { print(vec);}}


signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout << fixed << setprecision(10);
    int ans = 0;
    
    int X;
    cin >> X;

    ans = X/500 * 1000 + X%500 /5 *5;
    pa;
    
    
    
    return 0;
}

/*
cd ~/Desktop/Programming/AtCoder/contest/abc160/abc160_b && sh shellscripts/test_cpp.sh
cd ~/Desktop/Programming/AtCoder/contest/abc160/abc160_b && sh shellscripts/etest_cpp.sh
cd ~/Desktop/Programming/AtCoder/contest/abc160/abc160_b && sh shellscripts/submit_cpp.sh
*/


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

using namespace std;
const int mod = 1000000007;
int n;
long a[300000];
int main() {
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  
  long sum = 0;
  long base = 1;
  for (int k = 0; k < 62; ++k) {
    long c[2] = {};
    for (int i = 0; i < n; ++i) {
      int d = (a[i] >> k) & 1;
      ++c[d];
    }
    sum = (sum + c[0] * c[1] % mod * base) % mod;
    base = (base * 2) % mod;
  }
  cout << sum << endl;
}

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

int main() {
    int n, m;
    cin >> n;
    vector<int> arr(n);
    vector<int> brr(n);
    for(int i = 0; i < n; i++) {
        cin >> arr[i];
        brr[i] = arr[i];
    }
    sort(brr.begin(), brr.end());
    m = brr[n / 2 - 1];
    for(int i = 0; i < n; i++)  {
        if(arr[i] <= m) {
            cout << brr[n / 2] << endl;
        } else {
            cout << brr[n / 2 - 1] << endl; 
        }
    }
    
    return 0;
}


Measured memory_bytes: 3712
using System;
using System.Linq;

class B
{
	static void Main()
	{
        int  N = int.Parse(Console.ReadLine());
        int[] a  = Console.ReadLine()
                            .Split(' ')
                            .Select(a => int.Parse(a))
                            .ToArray();
		int Count=0;
        for(int i=0;i<N;i=i+2)
        {
            if(a[i]%2==1)
            {
                Count++;
            }
        }


        Console.WriteLine(Count.ToString());
        
	}
}

Measured memory_bytes: 28208
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 char a, b, c, d, e, f;
 cin >> a >> b >> c >> d >> e >> f;
 if ((c == d) && (e == f)){
    cout << "Yes" << endl;
 }
 else{
   cout << "No" << endl;
 }
   
}

Measured memory_bytes: 256
n = gets.to_i
s = gets.chomp.split("").map!{|i| i.to_s}
max = 0
s.length.times do |j|
  a = s[0..j]
  b = s[j+1..-1]
  c = (a&b).length
  if c > max 
    max = c
  end
end
puts max 


Measured memory_bytes: 1788
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// #include <ext/pb_ds/detail/standard_policies.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>;
 
typedef long long int ll;
const ll N = 1e5 +9;
const ll p = 31;
// const ll m = 1e9 + 7;
const ll inf= 1e14;
const ll mod = 1e9+7;
#define x first
#define y second
#define pb push_back
#define mp make_pair
using pii = pair<ll, ll>;
ll powm(ll a, ll b) { a = a%mod;ll res = 1; while (b) { if (b & 1) res = (res * a) % mod; a = (a * a) % mod; b >>= 1; } return res; }
    
int main()
{   
    ios::sync_with_stdio(false);
     cin.tie(0);
     cout.tie(0);
    ll T= 1;
    // cin >> T;
    while(T--){
        ll n;cin>>n;ll p[n];
        for(int i = 0;i<n;i++){
            cin>>p[i];
        }
        ll ct = 0;
        for(int i = 1;i<n-1;i++){
            if((p[i]<p[i+1])^(p[i]<p[i-1])){
                ct++;
            }
        }
        cout<<ct<<'\n';
    }
    return 0;
}   

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

#define NIL -1

void dfs(int r, int id, vector<vector<int>> &G, vector<int> &color) {
    stack<int> S;
    S.push(r);

    color[r] = id;
    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] = id;
                S.push(v);
            }
        }
    }
}

void assignColor(vector<vector<int>> &G, vector<int> &color) {
    int id = 1;

    for (int i = 0; i < G.size(); i++)
        color[i] = NIL;

    for (int u = 0; u < G.size(); u++) {
        if (color[u] == NIL) {
            dfs(u, id, G, color);
            id++;
        }
    }
}

int main() {
    int n, m;
    cin >> n >> m;

    vector<vector<int>> G(n);
    vector<int> color(n);

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

    // グループ分け
    assignColor(G, color);

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


Measured memory_bytes: 8616
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		int n, a, b;
		try (Scanner sc = new Scanner(System.in)) {
			n = Integer.parseInt(sc.next());
			a = Integer.parseInt(sc.next());
			b = Integer.parseInt(sc.next());
		}

		int total = 0;
		for (int i=1; i<=n; i++) {
			int sum = i/10000 + (i%10000)/1000 + (i%1000)/100 + (i%100)/10 + (i%10);
			if (a <= sum && sum <= b) {
				total += i;
			}
		}
		System.out.println(total);
	}
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
 
 
using namespace std;
 
typedef long long ll;
 
#define MOD 998244353
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define rrep(i,a,b) for(ll i=a;i>b;--i)
#define vi vector<int>
#define vl vector<ll>
#define ld long double
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
#define pii pair<int,int>
#define pll pair<long,long>
#define vpii vector<pii>
#define vpll vector<pll>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define PI 3.1415926535897932384626433832795
#define fix(f,n) fixed<<setprecision(n)<<f
#define all(x) x.begin(),x.end()
#define endl "\n"
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
ll newmod(ll a,ll b)
 {
  return ((a%b)+b)%b;
}
 
 
ll powM(ll a,ll b,ll m )
{ 
  a%=m;
  ll ans=1;
  while(b)
  {
    if(b&1)ans=ans*a%m;
    a=a*a%m;
    b>>=1;
  }
 
return ans;
}
 
ll pow(ll a,ll b)
{ 
  
  ll ans=1;
  while(b)
  {
    if(b&1)ans=ans*a;
    a=a*a;
    b>>=1;
  }
 
return ans;
}

ll arr[55];
int main()
{ 
  IOS;


ll x,y;
cin>>x>>y;

if(y%2){
  cout<<"No";
  return 0;
}

ll a=(y-2*x);

if(a<0||a%2){
  cout<<"No";
  return 0;
}

ll b=(2*x-y/2);

if(b<0){
  cout<<"No"<<endl;
  return 0;
}

cout<<"Yes";


 return 0;

 
 
}

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

int main(void){
    int n,count1=0;
    cin>>n;
    int i,j;
    vector<int> a(n);
    for(i=0;i<n;i++){
        cin>>a[i];
    }
    int flag=1;
    while(flag){
        flag=0;
        for(j=n-1;j>=1;j--){
            if(a[j]<a[j-1]){
                swap(a[j],a[j-1]);
                count1++;
                flag=1;
            }
        }
    }
    for(i=0;i<n-1;i++){
        cout<<a[i]<<" ";
    }
    cout<<a[n-1]<<endl;
    cout<<count1<<endl;
}


Measured memory_bytes: 3104
#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;
typedef unsigned long long ll;

const int mod=1e9+7;
const int inf=-1;
const int sz=2e5;

#define pi acos(-1)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define gap ' '
#define lb lower_bound
#define ub upper_bound
#define SIN(x) sin(x * pi / 180.0)
#define COS(x) cos(x * pi / 180.0)
#define clr(x) memset(x,0,sizeof(x))
#define all(x) sort(x.begin(),x.end())
#define rall(x) reverse(x.begin(),x.end())
#define dbg puts("finding wrong")
#define case(x,y) printf("Case %lld: %lld\n",++x,y)
#define fastio ios::sync_with_stdio(false);cin.tie(0)

ll bigmod(ll a, ll b, ll m)
{
  if(b==0) return 1;
 
  ll x=bigmod(a,b/2,m);
  x=(x*x)%m;
  if(b%2==1)x=(x*a)%m;
 
  return x;
}


int main()
{
  fastio;
  ll t, a, b, c, ans, i, n;
  cin>>n;
  ans=bigmod(10LL,n,mod);
  b=bigmod(9LL,n,mod);
  c=bigmod(8LL,n,mod);
  ll res=(ans+c+mod)%mod;
  b=(b*2)%mod;
  res=(res-b+mod)%mod;
  cout<<res<<endl;
}


Measured memory_bytes: 3632
import sys,queue,math,copy,itertools,bisect,collections
INF = 10**9
LI = lambda : [int(x) for x in sys.stdin.readline().split()]
_LI = lambda : [int(x)-1 for x in sys.stdin.readline().split()]
NI = lambda : int(sys.stdin.readline())
N,K = LI()
dq = LI()

ans = -INF
for r in range(N+1):
    if K < N - r: continue

    ret = 0
    for i in range(N-r+1):
        q = dq[:i] + dq[i+r:]
        ret = sum(q)
        q.sort()
        for j in range(K - (N-r)):
            if j >= len(q)-1 : break
            if q[j] < 0:
                ret -= q[j]
            else:
                break
        ans = max(ans,ret)
print(ans)


Measured memory_bytes: 43108
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define sz(x) int(x.size())
#define pb push_back
#define eb emplace_back
using ll=long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
const ll MOD=1000000007;



int main() {
    int N;
    cin>>N;
    vector<ll> A(N);
    rep(i,N)cin>>A.at(i);
    ll sum=0,ns=0;
    ll f1,f2;
    rep(i,N){
        sum+=A.at(i);
    }
    rep(i,N){
        ns+=A.at(i);
        if(ns>sum/2){
            f2=ns;
            f1=ns-A.at(i);
            break;
        }
    }
    f2=abs(sum-2*f2);
    f1=abs(sum-2*f1);
    cout<<min(f1,f2)<<endl;
}

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

using namespace std;

int fa[100010];
int find(int x){return x==fa[x]?x:fa[x]=find(fa[x]);} 
int N;
struct point
{
	int x,y,num;
}p[100010];

bool cmp1(point a,point b){return a.x<b.x;}
bool cmp2(point a,point b){return a.y<b.y;}

struct edge
{
	int l,r,len;
};
vector<edge>e;
bool cmp(edge a,edge b){return a.len<b.len;}

int main()
{
	scanf("%d",&N);
	for (int i=1;i<=N;i++)
	{
		fa[i] = i;
		scanf("%d%d",&p[i].x,&p[i].y);
		p[i].num = i;
	}	
	e.clear();
	sort(p+1,p+N+1,cmp1);
	for (int i=1;i<N;i++)
		e.push_back((edge){p[i].num,p[i+1].num,p[i+1].x-p[i].x});
	sort(p+1,p+N+1,cmp2);
	for (int i=1;i<N;i++)
		e.push_back((edge){p[i].num,p[i+1].num,p[i+1].y-p[i].y});
	sort(e.begin(),e.end(),cmp); 
	int ans = 0;
	for (int i=0;i<e.size();i++)
	{
		if (find(e[i].l) != find(e[i].r))
		{
			ans += e[i].len;
			fa[find(e[i].l)] = find(e[i].r);
		}
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 6516
#include<bits/stdc++.h>
 
#define ll long long 
#define in freopen("input.txt", "r", stdin)
#define out freopen("output.txt", "w", stdout)
#define skorost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) 

using namespace std ;
 
ll z , o , ans ;

ll N = 1e9 + 7 ;

int code(  ){

	char a ;

	cin >> a ;

	if( a >= 'a' && a <= 'z' ){

		cout << 'a'; 

	} 
	else{

		cout << 'A' ;

	}

	return 0 ;

}

int main(){ skorost ;

	int tjk = 1 ;

	// cin >> tjk ;

	while( tjk -- ){

		code( ) ;

	}

}

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

int main() {
    int K, A, B;
    cin >> K >> A >> B;
    
    string ans = "NG";
    for (int i = A; i <= B; ++i) {
        if (i % K == 0) ans = "OK";
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3596
#include <stdio.h>

int main(){
	double a,b,c,d,e,f;
	double kensa;
	double m,n;	/*mx=nÌ`Éµ½¢*/
	double x,y;
	
	while(scanf("%lf %lf %lf %lf %lf %lf",&a,&b,&c,&d,&e,&f)!=EOF){
		if(b==e){												/*yðÁ·âèû*/
			m=d-a;
			n=f-c;
		}else{
			m=d-(e/b)*a;
			n=f-(e/b)*c;
		}
		x=n/m;
		y=(c-a*x)/b;		/*d,e,fÆÇÁ¿Åà¢¢*/
		
		kensa=x*(10*10*10);			/*lÌÜü,x	*/
		kensa=kensa-(double)(int)kensa;
		if(kensa>=0.5){
			x+=0.001;
		}
		kensa=y*(10*10*10);			/*lÌÜü,y	*/
		kensa=kensa-(double)(int)kensa;
		if(kensa>=0.5){
			y+=0.001;
		}
		x+=0.;		/*	=-0.000ðh®½ß*/
		y+=0.;
		
		printf("%.3lf %.3lf\n",x,y);
	}
	
	return 0;
}

Measured memory_bytes: 0
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>

using namespace std;
const int MX=311;
int n,m;
int a[MX][MX];
int g[MX][MX];
typedef pair<int,int> pii;
#define mp make_pair
#define fr first
#define se second
pii ckfst(){
	static int c[MX];
	memset(c+1,0,sizeof(int)*m);
	pii ans=mp(0,0);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)if(a[i][j]){
			++c[a[i][j]];
			if(c[a[i][j]]>ans.fr)ans.fr=c[a[i][j]],ans.se=a[i][j];
			break;
		}
	return ans;
}
int wk(){
	int ans=n;
	for(int i=1;i<=m;i++){
		pii r=ckfst();
		ans=min(ans,r.fr);
		for(int i=1;i<=n;i++)
			for(int j=1;j<=m;j++)
				if(a[i][j]==r.se)a[i][j]=0;
	}
	return ans;
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			scanf("%d",&a[i][j]);
	printf("%d\n",wk());
	return 0;
}


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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 

#define ll long long

#define fr(i,a,b) for (ll i = (a), _b = (b); i <= _b; i++)
#define frr(i,a,b) for (ll i = (a), _b = (b); i >= _b; i--)
#define rep(i,n) for (ll i = 0, _n = (n); i < _n; i++)
#define repr(i,n) for (ll i = n - 1; i >= 0; i--)
#define fill(ar,val) memset(ar, val, sizeof(ar))
#define fill0(ar) fill((ar), 0)
#define debug(x) cout<<#x<<": "<<x<<endl

#define ld long double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second

typedef pair<ll, ll> ii;
typedef pair<ii, ll> iii;
typedef vector<ii> vii;
typedef vector<ll> vi;

#define INF 1000000000000000000
#define PI 3.14159265358979323846L

// Initialise the parents of nodes as the nodes itself, and the ranks as 0
struct dis_set
{
    ll parent;
    ll rank;
    ll si;
};

dis_set s[100001];

ll find(ll i)
{
    if(s[i].parent != i)
        s[i].parent = find(s[i].parent);

    return s[i].parent;
}

void Union(ll x, ll y)
{
    ll xroot = find(x);
    ll yroot = find(y);
    // cout << x << " " << y << " " << xroot << " " << yroot << endl;
    if(s[xroot].rank > s[yroot].rank)
    {
        s[yroot].parent = xroot;
        s[xroot].si += s[yroot].si;
    }
    else if(s[yroot].rank > s[xroot].rank)
    {
        s[xroot].parent = yroot;
        s[yroot].si += s[xroot].si;
    }
    else
    {
        s[xroot].parent = yroot;
        s[yroot].rank++;
    	s[yroot].si += s[xroot].si;
    }
}

vector<ll> row[100001];
vector<ll> col[100001];
map<ll, ll> pts[100001];

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

    ll n;
    cin >> n;

    pair<ll, ll> p[n];
    rep(i,n)
    {
    	ll x,y;
    	cin >> x >> y;
    	p[i] = mp(x,y);
    	col[x].pb(y);
    	row[y].pb(x);
    }

    fr(i,1,100000)
    {
    	s[i].parent = i;
    	s[i].rank = 0;
    	s[i].si = 1;
    }

    fr(i,1,100000)
    {
    	if(col[i].size()==0 || col[i].size()==1)
    		continue;
    	ll xx = col[i][0];

    	rep(j,col[i].size())
    	{
    		ll ro = col[i][j];
    		if(find(ro)!=find(xx))
    			Union(ro,xx);
    	}
    }

    fr(i,1,100000)
    {
    	ll par = find(i);
    	rep(j,row[i].size())
    	{
    		ll co = row[i][j];
    		pts[par][co]++;
    	}
    }

    ll ans = 0;

    fr(i,1,100000)
    {
    	if(pts[i].size()==0)
    		continue;
    	ll xx = pts[i].size();
    	ll siz = s[i].si;
    	xx = xx*siz;

    	ans = ans + xx;
    }

    cout << ans-n << endl;
}


Measured memory_bytes: 20352
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000000000000000000000001
#define LONG_INF 10000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)
int main() {
	map<pair<string, string>, int> wow;
	int n, k;
	cin >> n >> k;
	REP(i, n) {
		int s;
		cin >> s;
		vector<string> ge;
		REP(q, s) {
			string ges;
			cin >> ges;
			ge.push_back(ges);
		}
		REP(q, s) {
			for (int j = q + 1;j < s;++j) {
				if (ge[q] < ge[j]) {
					wow[make_pair(ge[q], ge[j])]++;
				}
				else wow[make_pair(ge[j], ge[q])]++;
			}
		}
	}
	vector<pair<string, string>> ans;
	for (auto i = wow.begin();i != wow.end();++i) {
		if (i->second >= k) {
			ans.push_back(i->first);
		}
	}	
	REP(i, ans.size()) {
		if (ans[i].first > ans[i].second) swap(ans[i].first, ans[i].second);
	}
	sort(ans.begin(), ans.end());
	cout << ans.size() << endl;
	REP(i, ans.size()) {
		cout << ans[i].first << " " << ans[i].second << endl;
	}
}


Measured memory_bytes: 3652
n, a, b = gets.split.map(&:to_i)

d = (a - b).abs

if d.even?
    puts d / 2
else
    mi, ma = [a, b].minmax
    ans_x = mi
    ans_x += (ma-mi-1)/2
    ans_y = n-ma+1
    ans_y += (ma-mi-1)/2
    puts [ans_x, ans_y].min
end


Measured memory_bytes: 1916
#include <iostream>
#include <algorithm>
#include <vector> //動的配列
#include <string>
#include <list> //双方向リスト
#include <map> //連想配列
#include <set> //集合
#include <stack>
#include <queue>
#include <deque>
#include <cmath>
#include <bitset>
#include <numeric>
#include <tuple>




typedef long long ll;


using namespace std;

typedef pair<int, int> P;
#define FOR(i,a,b) for(int i=(int)(a) ; i < (int) (b) ; ++i )
#define rep(i,n) FOR(i,0,n)
#define sz(x) int(x.size())


template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

//小さい順から取り出すヒープ
//priority_queue<ll, vector<ll>, greater<ll> > pque1;




int main(){
    string s;
    cin>>s;
    bool check=false;
    rep(i,3){
        if (s[i]==s[i+1]) check=true;
    }
    
    if (check) cout<<"Bad";
    else cout<<"Good";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#define rep(i,n) for(int i=0;i<(n);i++)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define psortfirst(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.first<b.first;});
#define All(x) (x).begin(),(x).end()
using namespace std;
using pii  = pair<int,int>;
long long gcd(long long a, long long b){return (b == 0 ? a : gcd(b, a%b));}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
typedef long long ll;
#define MOD 1000000007
#define EPS 10e-8

int U[2003][2003];

int main() {
    ll A[2];
    rep(i,2){
        cin >> A[i];
        if(A[i]==2){
            cout << "No"<<endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding: utf-8 -*-

N,M = map(int, input().split())
g = [[False]*(N+1) for _ in range(N+1)] # こうしないと同じ配列が参照される
a = [0]*(M+1)
b = [0]*(M+1)
for i in range(1, M+1):
  a[i],b[i] = map(int, input().split())
  g[a[i]][b[i]] = g[b[i]][a[i]] = True

def dfs(v):
  visited[v] = True

  for v2 in range(1, N+1):
    if not g[v][v2]: continue
    # 一度訪れてその先の経路も全て visit してるはずなので
    if visited[v2]: continue
    dfs(v2)

count = 0
for i in range(1, M+1):
  visited = [True] + [False]*N
  g[a[i]][b[i]] = g[b[i]][a[i]] = False
  dfs(1)
  if not all(visited): count += 1
  g[a[i]][b[i]] = g[b[i]][a[i]]= True

print(count)


Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;



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

	long long x, k, d, i, j, ans, xx, yy;

	cin >> x >> k >> d;
	xx = abs(x);
	if (xx / d >= k) ans = xx - d * k;
	else {
		yy = xx / d;
		k -= yy;
		xx %= d;

		if (k % 2 == 0) ans = min(xx, abs(xx - 2 * d));
		else ans = min(xx + d, abs(xx - d));
	}

	cout << ans << "\n";



	return 0;
}


Measured memory_bytes: 3164
all = int(input())
a = []
c = []
ans = []
f = False
for i in range(all):
    b = input().split()
    c.append(b[0])
    a.append(int(b[1]))
sleep = input()
for i in range(all):
    if not f:
        if c[i] == sleep:
            f = True
        continue
    else:
        ans.append(a[i])
ans = sum(ans)
print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<stack>
#include<set>
#include<map>
#include<stdio.h>

using ll = long long;

using namespace std;

ll mod = 1000000007;

ll n_pow(ll a, ll n) {
	if (n == 0)return 1;
	ll t = n_pow(a, n / 2);
	t *= t;
	t %= mod;
	if (n % 2 == 1)t *= a;
	return t % mod;
}

const int INF = 1001001001;


int main() {
	string s;
	cin >> s;
	ll n = s.size();
	int k;
	cin >> k;
	vector<vector<int>>dp0(n + 1, vector<int>(k + 1));
	vector<vector<int>>dp1(n + 1, vector<int>(k + 1));
	dp0[0][0] = 1;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < k + 1; j++) {
			int x = s[i] - '0';
			for (int d = 0; d < 10; d++) {
				int ni = i + 1, nj = j;
				if (d != 0)nj++;
				if (nj > k)continue;
				if (d == x) {
					dp0[ni][nj] += dp0[i][j];
					//dp1[ni][nj] += dp0[i][j];
				}
				if (d < x) {
					dp1[ni][nj] += dp0[i][j];
				}
				dp1[ni][nj] += dp1[i][j];

			}
		}
	}
	cout << dp0[n][k] + dp1[n][k] << endl;
	return 0;
}

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

void solve(string s){
    set<string> st;
    int N=s.size();
    for(int i=1;i<N;i++){
        string a=s.substr(0,i);
        string b=s.substr(i);
        string aa(a);
        string bb(b);
        reverse(aa.begin(),aa.end());
        reverse(bb.begin(),bb.end());
        st.insert(a+b);
        st.insert(aa+b);
        st.insert(a+bb);
        st.insert(aa+bb);
        st.insert(b+a);
        st.insert(bb+a);
        st.insert(b+aa);
        st.insert(bb+aa);
    }
    cout << st.size() << endl;
}

int main(){
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        string s;
        cin>>s;
        solve(s);
    }
}

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

#define rep(i,n) for(int i = 0; i < n; i++)
#define per(i,n) for(ll i = n-1; i >= 0; i--)
#define REP(i,n) for(ll i = 1; i < n; i++)
#define PER(i,n) for(ll i = n; i >= 1; i--)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
using vs = vector<string>;
using vb = vector<bool>;
using vc = vector<char>;
using vcc = vector<vc>;
using vP = vector<P>;
using vPP = vector<vP>;
using vPl = vector<Pl>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
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; }



int main(){
  int d;
  cin >> d;
  int k = 26;
  vi c(k);
  rep(i,k) cin >> c[i];
  vii s(d,vi(k));
  rep(i,d)rep(j,k) cin >> s[i][j];
  vi lastday(k);
  rep(i,d) {
    P mx = make_pair(0,0); // min-point, index
    rep(j,k) {
      int m_p = c[j] * ((i+1) - lastday[j]);
      chmax(mx, make_pair(m_p, j));
    }
    int today = mx.se;
    cout << today + 1 << endl;
    lastday[today] = i+1;
  }
}

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

int main(){
    int a, b, c, i, count = 0;
    scanf("%d %d %d", &a, &b, &c);
    for(i = a; i < b + 1;i++){
        if(c % i == 0) count++;
    }
    printf("%d\n", count);
}


Measured memory_bytes: 3216
//** aman**/
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define dl          double
#define hell        1000000007
#define endl        '\n'
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define lb lower_bound
#define ub upper_bound
#define bs          binary_search
#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
ll n,k,a[200005]={0};
ll chk(ll mid){
	ll cnt=0;
	for(ll i=0;i<n;i++){
		cnt+=a[i]/mid-1;
		if(a[i]%mid)cnt++;
	}
	if(cnt<=k)return 1;
	else return 0;
}
double chk1(double mid){
	ll cnt=0;
	double z;
	for(ll i=0;i<n;i++){
		z=(double)a[i];
		cnt+=ceil(z/mid)-1;
	}	
	if(cnt<=k)return 1;
	else return 0;
}
int main(){
	cin>>n>>k;
	for(ll i=0;i<n;i++)cin>>a[i];
	if(k==0)return cout<<*max_element(a,a+n),0;
	ll s=1,e=1e10,ans;
	while(s<=e){
		ll mid=(s+e)/2;
		if(chk(mid)){
			ans=mid;
			e=mid-1;
		}
		else{
			s=mid+1;
		}
	}

	cout<<ans<<endl;
}

Measured memory_bytes: 5112
//g++ -std=c++14 test.cpp -o test.out
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
using namespace std;

#define MAX 100001

int N,M;
int A[MAX];
int B[MAX];
int ans = 0;

void solve(){
	priority_queue<int> q;//優先度付きキュー
	vector<vector<int>> job(M+1);//i日後に報酬がもらえる仕事 の配列をjob[i]と定義
	for(int i=1;i<=N;i++){
		if(A[i]<=M) job[A[i]].push_back(B[i]);//配列job[A[i]]の末尾にB[i]を追加
	}
	for(int i=1;i<=M;i++){//条件の厳しいものから判定(最優先は1日後に報酬がもらえる仕事)
		for(int b:job[i]){//配列jobs[i]に入っている要素(i日後に報酬がもらえる仕事)をそれぞれbと置いてループ
			//優先度付きキュー(ヒープ木)に追加、削除はO(logN)ででき、参照はO(1)でできる
			q.push(b);//i日後に報酬がもらえる仕事　のそれぞれの要素を追加していく
		}
		if(!q.empty()){//キューが空でないならば（i日後に報酬がもらえる仕事が少なくとも1つあるならば）
			ans+=q.top();//一番優先度の高い（一番報酬の多い）仕事を見て、その報酬を足す
			q.pop();//さっき足したやつを捨てる
		}
	}
}

int main(){
	cin >> N >> M;
	for(int i=1;i<=N;i++) cin >> A[i] >> B[i];

	solve();

	cout << ans;
	return 0;
}


Measured memory_bytes: 6400
#include<bits/stdc++.h>
constexpr long long INFL = 1LL << 60;
constexpr int INF = 1e9;

using namespace std;

typedef long long ll;

struct second_order{
    bool operator()(const pair<int, int>& x,const pair<int, int>& y) const
    {
        return x.second > y.second;
    }
};

int main()
{
    int N,K;
    cin >> N >> K;
    vector<int> a(N);
    for(int i = 0; i < N; ++i) cin >> a[i];
    map<int, int> m;
    for(int i = 0; i < N; ++i){
        m[a[i]] += 1;
    }
    int cnt = 0;
    priority_queue<pair<int, int>, vector<pair<int, int>>, second_order> pq;
    for(auto p : m){
        pq.push(p);
    }
    while(pq.size() > K){
        cnt += pq.top().second;
        pq.pop();
    }
    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 12536
def get_data():
    data = input().split(',')
    l = []
    for i in range(10):
        l.append(int(data[i]))
        v1,v2 = int(data[10]),int(data[11])
    return v1,v2,l

def meet_point(v1,v2,l):
    l_total = 0
    for i in range(10):
        l_total += l[i]
    t = l_total/(v1+v2)
    p = v1*t
    res = 0
    for i in range(10):
        res += l[i]
        if p <= res:
            return i+1

while True:
    try:
        v1,v2,l = get_data()
        print(meet_point(v1,v2,l))
    except EOFError:
        break

Measured memory_bytes: 7600
#include <stdio.h>


 int main(){int i,a[1000],b;
 	scanf("%d",&i);
 	for(b=0;b<i;b++){
 	scanf("%d",&a[b]);
 	};
 	for(b=b-1;b>=1;b--){
 	printf("%d ",a[b]);
 	};
 	printf("%d\n",a[b]);
 	
 
 return 0;}



Measured memory_bytes: 2100
//#include<bits/stdc++.h>
#include<iostream>
#include<string>
#define ll long long int
using namespace std;
int main(){
    ll T,i,j,c,d,p,q,n,a,b,m;
    string s1,s2,s3,s4;
    cin>>T;
 a=b=c=d=0;
   while(T--)
    {

        cin >>s1;
        if(s1=="AC") a++;
        else if(s1=="WA") b++;
        else if(s1=="TLE") c++;
        else if(s1=="RE") d++;
    }
    cout<<"AC x "<<a<<endl;
    cout<<"WA x "<<b<<endl;
cout<<"TLE x "<<c<<endl;
cout<<"RE x "<<d<<endl;
}


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

int main() {
    while (true) {
        int n;
        cin >> n;
        if (n == 0) {
            break;
        }
        int b = 0;
        while (b * (b + 1) * (b + 2) / 6 <= n) {
            b++;
        }
        b--;
        int a = 0, max = 0;
        while (a <= n && 0 <= b) {
            int container1 = a * a * a, container2 = b * (b + 1) * (b + 2) / 6;
            if (container1 + container2 <= n) {
                if (max < container1 + container2) {
                    max = container1 + container2;
                }
                a++;
            } else {
                b--;
            }
        }
        cout << max << endl;
    }
}

Measured memory_bytes: 0
a = list(map(int,input().split()))
count = 0
while max(a)-min(a) >= 2:
    count += (max(a)-min(a))//2
    a =sorted(a)
    if (a[-1]-a[0])%2 == 0:
        a[0] = a[-1]
    else:
        a[0] = a[-1] - 1
while max(a)!=min(a):
    a =sorted(a)
    a[0] += 1
    a[1] += 1
    count += 1
print(count)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(v) v.begin(),v.end()

int main(){
    string s;cin>>s;
    int ans=753;
    rep(i,s.size()-2){
        string str="";
        str+=s.at(i);
        str+=s.at(i+1);
        str+=s.at(i+2);
        int x=stoi(str);
        if(abs(x-753)<ans){
            ans=abs(x-753);
        }
    }
    cout<<ans<<endl;
}

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

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

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

template <typename T>
std::tuple<T, T, T> extgcd(T a, T b){
    T s1 = 1, t1 = 0, s2 = 0, t2 = 1;
    while(b != 0){
        std::tie(s1, t1, s2, t2) = std::make_tuple(s2, t2, s1 - (a / b) * s2, t1 - (a / b) * t2);
        std::tie(a, b) = std::make_tuple(b, a % b);
    }
    return std::make_tuple(s1, t1, a);
}

// 注意: a と mod が互いに素である必要がある
template <typename T>
T mod_inverse(T a, T mod){
    T b;
    std::tie(b, std::ignore, std::ignore) = extgcd(a, mod);
    if(b < 0){b += mod;}
    return b;
}

template <typename T>
struct Combinatorics{
    T modulo;
    std::vector<T> fact, inv_fact;

    Combinatorics(T max, T modulo) : modulo(modulo), fact(max + 1), inv_fact(max + 1) {
        fact[0] = 1;
        for(T i=1;i<=max;++i){
            fact[i] = i * fact[i - 1] % modulo;
        }

        inv_fact[max] = mod_inverse(fact[max], modulo);
        for(T i=max;i>0;--i){
            inv_fact[i - 1] = i * inv_fact[i] % modulo;
        }
    }

    T nPk(T n, T k){
        if(n < k){return 0;}
        return fact[n] * inv_fact[n - k] % modulo;
    }

    T nCk(T n, T k){
        if(n < k){return 0;}
        return fact[n] * inv_fact[k] % modulo * inv_fact[n - k] % modulo;
    }

    T nHk(T n, T k){
        if(n == 0 && k == 0){return 1;}
        return nCk(n + k - 1, k);
    }
};

constexpr ll MOD = 1'000'000'007;
int N, X;
int S[210];
ll dp[210][100100];
Combinatorics<ll> comb(500, MOD);

ll rec(int i, int x, int n){
    if(i == N){
        return x;
    }

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

    ll c = 0;

    if(i < N - 1){ // 後で使う
        c = rec(i + 1, x, n - 1) * (n - 1) % MOD;
    }

    // 今使う
    c = (c + rec(i + 1, x % S[i], n - 1)) % MOD;

    return dp[i][x] = c;
}

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

    std::cin >> N >> X;

    for(int i=0;i<N;++i){
        std::cin >> S[i];
    }

    std::sort(S, S + N);
    std::reverse(S, S + N);

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

    int n = 0;

    for(int i=0;i<N;++i){
        if(S[i] > X){
            n += 1;
        }else{
            break;
        }
    }

    ll res = rec(n, X, N - n) * comb.nPk(N, n) % MOD;
    std::cout << res << std::endl;
}


Measured memory_bytes: 164480
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

using namespace std;

#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i <= b; i++)
#define all(a)  begin((a)),end((a))
#define uniq(c) (c).erase(unique(all((c))), end((c)))

int main()
{
    int N; cin >> N;
    vector<int> a(N);
    rep (i, 0, N) cin >> a[i];

    int ans = 0, counter = 1;
    bool flg = false;
    rep (i, 0, a.size()) {
        if (a[i] == counter) {
            ++counter;
            flg = true;
        }
        else {
            ++ans;
        }
    }

    if (flg)
        cout << ans << endl;
    else
        cout << -1 << endl;

}

Measured memory_bytes: 1024
a = gets.to_i
b = gets.to_i
c = gets.to_i
x = gets.to_i
count = 0
(0..a).each do |an|
  (0..b).each do |bn|
    (0..c).each do |cn|
      total = 500*an + 100*bn + 50*cn
      count += 1 if total == x
    end
  end
end
puts count

Measured memory_bytes: 1788
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define REP(i,n) for(ll i = 0;i < n; i++)
int main(){
    string s;
    int k;
    cin >> s;
    cin >> k;
    string ss=s+s;
    ll one=0,second=0,third=0;
    char x= s[0];
    ll t=0;
    REP(i,s.size()){
        if(x==s[i]) t++;
        else{
            one+=t/2;
            x= s[i];
            t=1;
        }
    }
    one+=t/2;
    t=0;
    x= ss[0];
    REP(i,ss.size()){
        if(x==ss[i]) t++;
        else{
            second+=t/2;
            x= ss[i];
            t=1;
        }
    }
    second+=t/2;
    t=0;
    ss+=s;
    x= ss[0];
    REP(i,ss.size()){
        if(x==ss[i]) t++;
        else{
            third+=t/2;
            x= ss[i];
            t=1;
        }
    }
    third+=t/2;
    ll A[2]= {second-one,third-second};
    ll c=one;
    // cout <<one<<second << third<< endl;
    c+= ((k-1)%2)?((A[0]+A[1])*((k-1)/2)+A[0]):(A[0]+A[1])*((k-1)/2);
    cout << c << endl;
    // isssi 1
    // isssiisssi 3
    // isssiisssiisssi 5
    // isssiisssiisssiisssi 7
    // sss 1
    // ssssss 3
    // sssssssss 4
    // ssssssssssss 6
    // issii 2
    // issiiissii 4
    // issiiissiiissii 6
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define SORT(i) sort((i).begin(), (i).end())
#define INF 2000000000
constexpr ll mod = 1e9 + 7;
 
int main(){
    int N;
    cin >> N;
    unordered_map<ll, int> mp;
    for (int i = 0; i < N;++i){
        ll a;
        cin >> a;
        ++mp[a];
    }
    ll ans = 0;
    for(auto p : mp){
        auto key = p.first;
        auto value = p.second;
        if(key<=value){
            ans += value - key;
        }
        else {
            ans += value;
        }
    }
    cout << ans << "\n";

    return 0;
}

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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const ll INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;



signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n,k; cin>>n>>k;
  vll a(n);
  rep(i,n) cin>>a[i];
  
  rep(_,k){
    // imos
    vll l(n+1);
    rep(i,n){
      l[i]++;
      ll r=min(n,i+a[i]+1);
      l[r]--;
    }
    rep(i,n) l[i+1]+=l[i];
    
    vll r(n+1);
    rrep(i,n){
      r[i+1]++;
      ll l=max(0LL,i+1-a[i]-1);
      r[l]--;
    }
    rrep(i,n) r[i]+=r[i+1];
    
    // rep(i,n+1) cout<<l[i]<<' ';
    // cout<<endl;
    // rep(i,n+1) cout<<r[i]<<" ";
    // cout<<endl;
    
    rep(i,n){
      a[i]=l[i]+r[i+1]-1;
    }
    
    bool flg=true;
    rep(i,n){
      if(a[i]!=n) flg=false;
    }
    if(flg){
      rep(i,n) cout<<a[i]<<endl;
      return 0;
    }
  }
  
  rep(i,n) cout<<a[i]<<endl;
  
}

Measured memory_bytes: 7952