akhauriyash/Code-Regression huggingface dataset:
import math
def comb(a,b):
    if a < b:
        return 0
    return math.factorial(a)//(math.factorial(a-b)*math.factorial(b))
N = int(input())
def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]
primelist = primes(N)
primes = {}
for i in primelist:
    a = sum(int(N/(i**j)) for j in range(1,8))
    primes[i] = a
cand = sorted(list(primes.values()))
ans1 = len([i for i in cand if i >= 74])
ans2 = len([i for i in cand if i >= 24])*(len([i for i in cand if i >= 2])-1)
ans3 = len([i for i in cand if i >= 14])*(len([i for i in cand if i >= 4])-1)
ans4 = comb(len([i for i in cand if i >= 4]),2)*(len([i for i in cand if i >= 2])-2)
print(ans1+ans2+ans3+ans4)
    


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(V) (V).begin(),(V).end()

bool solve(ll a, ll b, ll c, ll d) {
	if (a < b)return 0;
	if (b > d)return 0;
	if (c < b - 1)return 0;
	return 1;
}

ll gcd(ll x, ll y) {
	while (y) {
		x %= y;
		swap(x, y);
	}
	return x;
}

queue<string> Q;

int main(){
	ll A, B, C, D, E;
	int T;
	cin >> T;
	for (int i = 0;i < T;i++) {
		cin >> A >> B >> C >> D;
		E = gcd(B, D);
		C -= A % E;
		A /= E;
		B /= E;
		if (C < 0)C = -1;
		else C /= E;
		D /= E;
		if (solve(A, B, C, D))
			Q.push("Yes");
		else
			Q.push("No");
	}
	while (!Q.empty()) {
		cout << Q.front() << endl;
		Q.pop();
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
using namespace std;

int n;
int mini = 100000;
vector<int> money(1,1);

int search(int amount, int key, int count){
    if(count >= mini) return count;
    if(key == 0) return amount + count;
    int num = amount / money[key];
    if(num >= mini + count) num = mini;
    for (int i = num; i >= 0; i--)
    {
        mini = min(mini, search(amount - money[key] * i, key - 1, count + i));
    }
    return mini;
}

int main(){
    cin >> n;
    int i = 1;
    int nines = 9;
    while(nines <= n){
        money.push_back(nines);
        nines = pow(9, ++i);
    }
    int j = 1;
    int sixes = 6;
    while (sixes <= n){
        money.push_back(sixes);
        sixes = pow(6, ++j);
    }
    sort(money.begin(), money.end());
    //for(int k = 0; k < money.size(); k ++) cout << money[k] << endl;
    cout << search(n, money.size() - 1, 0) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<time.h>
#include<set>
#include<map>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i>b;i--)
#define vint vector<int> 
#define vvint vector<vint>
#define ct(a) cout<<a<<endl
#define tget(a,b) get<a>(b)
using namespace std;
typedef long long ll;
const ll INF = 1e17;
const int MOD = 1e9 + 7;

ll N,X,cur,ans;
ll x[100005];
ll gcd(ll A,ll B) {
	ll amari=INF;
	if (B > A)swap(A, B);
	while (amari != 0) {
		amari = A % B;
		A = B; B = amari;
	}
	return A;
}

int main(void) {
	cin >> N >> X;
	FOR(i, 0, N) {
		ll a;
		cin >> a;
		cur = abs(X - a);
		if (ans == 0)ans = cur;
		else ans = gcd(ans, cur);
	}
	ct(ans);

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
using namespace std;
int main(){
    int N;
    cin>>N;
    vector<double> x(N);
    vector<string> u(N);
    for(int i=0;i<N;++i){
        cin>>x[i]>>u[i];
    }
    double sum = 0;
    for(int i=0;i<N;++i){
        if(u[i]=="BTC"){
            sum += x[i]*380000.0;
        } else {
            sum += x[i];
        }
    }
    cout<<sum;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#ifdef ONLINE_JUDGE
#define LLD "%I64d"
#else
#define LLD "%lld"
#endif
#define fu(a,b,c) for(int a=b;a<=(int)c;++a)
#define fd(a,b,c) for(int a=b;a>=(int)c;--a)
#define cu(a,b,c) for(int a=b;a<(int)c;++a)
#define cd(a,b,c) for(int a=b-1;a>=(int)c;--a)
#define gcd(a,b) __gcd(a,b) 
#define pii pair<int,int>
#define pll pair<long long,long long>
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define pf push_front
#define MOD 1000000007
#define MAXN 52
#define MAXH 20
#define MAXM 52
#define INF 100000000
#define ll long long
#define ull unsigned long long
#define RNG rng mt19937(time(NULL))
#define udist(a,b) uniform_int_distribution<uint32_t> distribution(a,b)
#define max3(a,b,c) max(a, max(b, c))
#define min3(a,b,c) min(a, min(b, c))
#define gmax(a,b) a = max(a, b)
#define gmin(a,b) a = min(a, b)
#define whatis(x) cerr << #x << " is " << x << endl;
#define fast_io() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define PI 3.1415926535897932384626433
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int N = 120000;
int n,k;
bool hate[10];

bool valid(int x){
	while(x){
		if(hate[x % 10])return 0;
		x/=10;
	}
	return 1;
}

int main(){
	cin >> n >> k;
	cu(i,0,k){
		int x;
		cin >> x;
		hate[x] = 1;
	}
	while(!valid(n)){
		++n;
	}
	cout << n << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    int n,t;
    cin >> n >> t;
    int times[n];
    for (int i=0; i<n; i++){
        cin >> times[i];
    }
    int ans=0;
    for (int i=0; i<n-1; i++){
        if (times[i+1]-times[i]<=t){
            ans+=times[i+1]-times[i];
        }else {
            ans+=t;
        }
    }
    cout << ans+t << endl;
}

Measured memory_bytes: 1024
n,x,y = map(int,input().split())
arr = [0] * (n-1)

for i in range(1,n):
    for j in range(i+1,n+1):
        arr[min((j-i),abs(i-x)+1+abs(j-y),abs(i-y)+1+abs(j-x)) - 1] += 1
        
for i in arr:
    print(i)

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

int main(){
  int N;
  cin >> N;
  if(N<10){
    cout << N << endl;
  }else if(N<100){
    cout << 9 << endl;
  }else if(N<1000){
    cout << 9+N-99 << endl;
  }else if(N<10000){
    cout << 9+900 << endl;
  }else if(N<100000){
    cout << 9+900+N-9999 << endl;
  }else{
    cout << 9+900+90000 << endl;
  }
} 

Measured memory_bytes: 256
/* Everything happens for a reason.
Be patient, things will be at their rightful place.
It was meant to happen this way, accept it.
And now decide what you can do about it.
*/
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define ip pair<ll,ll>
#define vii vector<ll>
#define vpp vector<ip>
#define vdd vector<ld>
#define vb vector<bool>
#define pi  pair<ll,ip>
#define sc(x) scanf("%lli",&x)
#define c(x) cin >> x
#define fo(i,k,n) for( int i=k;i<n;i++)
#define hu 200010
#define pq priotity_queue<ll>
#define pqs priority_queue<ll,vii,greater<ll>>
#define ppq priority_queue<ip,vpp,greater<ip>>
#define INF INT_MAX
#define ff first
#define ss second
using namespace std;
const ll M = 1000000000+7;
//Grid Movement
ll dx[] = {-1, 0, 1, 0};
ll dy[] = {0, -1, 0, 1};

ld Pi= acos(-1);

ll lcm(ll a,ll b)
{
    return (a*b)/(__gcd(a,b));
}

ll mex(ll x, ll y) 
{ 
	ll res = 1;	  
	x = x % M; 
	if (x == 0) return 0; 
	while (y > 0) 
	{ 
		if (y & 1) 
		res = (res*x) % M; 
		y = y>>1; 
		x = (x*x) % M; 
	} 
	return res; 
} 

bool comp(ll comp1,ll comp2)
{
    return comp1>comp2;
}

void yes()
{
    printf("YES\n");
}

void no()
{
    printf("NO\n");
}

ll inv(ll a, ll m)
{
    ll m0 = m;
    ll y = 0, x = 1;
 
    if (m == 1)
      return 0;
 
    while (a > 1)
    {
        int q = a / m;
        int t = m;
        m = a % m, a = t;
        t = y;
        y = x - q * y;
        x = t;
    }
 
    if (x < 0)
       x += m0;
 
    return x;
}

void sieve(ll n)
{
    vii primes(n+1);
    vb is_prime(n+1);
	is_prime.resize(n+1);
	primes.resize(n+1);
 
	is_prime[0] = is_prime[1] = false;
	for(int i = 2; i<=n; i++)
	{
	    if(is_prime[i])
	    {
	    	primes.pb(i);
	        for (int j = i*i; j<=n; j+=i)
	            is_prime[j] = false;
	    }
	}
}

void solve()
{
    ll x;
    sc(x);
    ll adi = mex(10,x);
    
    ll meg = mex(9,x);
    ll tya = mex(8,x);
//    cout << adi << endl << tya << endl << meg <<endl;
    ll ans = ((adi + tya)%M -(2*meg)%M + M)%M;
    cout << ans;
    
}

int main()
{
//	base::sync_with_stdio(0); cin.tie(0);
    ll t=1;
  //  sc(t);
    while(t--) solve();
}





Measured memory_bytes: 3688
#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);

	string s;
	cin >> s;
	if (s.find("AC") != string::npos) cout << "Yes\n";
	else cout << "No\n";

	return 0;
}



Measured memory_bytes: 256
#include <string>
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
using namespace std;

typedef long long ll;

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

#define FOR(i, start, end) for(ll i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)

int main(void) {
    int N, M;
    cin >> N >> M;
    vector<vector<int>> next(N+1);
    REP(i, M) {
        int a, b;
        cin >> a >> b;
        next[a].push_back(b);
        next[b].push_back(a);
    }

    vector<int> prm(N);
    REP (i, N) {
        prm[i] = i + 1;
    }

    int ans = 0;
    do {
        if (*prm.begin() != 1) {
            break;
        }
        for (vector<int>::iterator p = prm.begin(); p != prm.end(); p++) {
            if (p + 1 == prm.end()) {
                ans++;
                break;
            }
            vector<int> n = next.at(*p);
            if (find(n.begin(), n.end(), *(p + 1)) == n.end()) {
                break;
            }
        }
    } while (next_permutation(prm.begin(), prm.end()));

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug" << x << endl;
using namespace std;
 
int main(){
    int h,w;
    while(cin >> h >> w, h||w){
        rep(i,h){
            rep(j,w){
                if(i == 0 || j == 0 || i == h - 1 || j == w - 1) cout << "#";
                else cout << '.';
            }
            cout << endl;
        }
        cout << endl;
    }
}


Measured memory_bytes: 3088
/**
 * File              : D-tutorial.cpp
 * Author            : JCHRYS <jchrys@me.com>
 * Date              : 27.01.2020
 * Last Modified Date: 27.01.2020
 * Last Modified By  : JCHRYS <jchrys@me.com>
 */

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int const SIZE = 10;
ll dp[SIZE][SIZE] {}; 
// dp[i][j] = number of numbers first digit is i and last digit is j

int main() {
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        string s = to_string(i);
        int n = s.size();
        int first = s[0] - '0';
        int last = s[n - 1] - '0';
        dp[first][last]++;
    }
    ll ans = 0;

    for (int i = 0; i < SIZE; i++)
        for (int j = 0; j < SIZE; j++)
            ans += dp[i][j] * dp[j][i];
        
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <algorithm>
#include <iostream>
#include <cassert>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <ctime>
#include <map>
#include <set>
#include <string>
#include <cassert>

#define INFLL 2000000000000000000
#define INF 2000000000
#define MOD 1000000007
#define PI acos(-1.0)

using namespace std;

typedef pair <int, int> pii;
typedef long long ll;
typedef vector <ll> vll;

long long dp[53][3];
string a, b;

int main() {
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n;
	cin >> n;
	cin >> a >> b;
	if (a[0] == b[0]) {
		dp[1][0] = 3;
	} else {
		dp[1][1] = 6;
	}	
	for (int i = 1; i < a.length(); i++) {
		if (a[i] == b[i]) {
			dp[i + 1][0] = dp[i][0] * 2;
			dp[i + 1][0] %= MOD;
			dp[i + 1][0] += dp[i][2] % MOD;
			dp[i + 1][0] %= MOD;
		} else {
			if (a[i - 1] == a[i]) {
				dp[i + 1][2] = dp[i][1];
			} else {
				dp[i + 1][1] = dp[i][0] * 2;
				dp[i + 1][1] %= MOD;
				dp[i + 1][1] += (dp[i][2] * 3) % MOD;
				dp[i + 1][1] %= MOD;
			}
		}
	}
	cout << max(dp[a.length()][0], max(dp[a.length()][1], dp[a.length()][2])) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;

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

	if (a * b % 2 == 0) cout << "Even" << endl;
	else cout << "Odd" << endl;
}


Measured memory_bytes: 384
# coding: utf-8

# In[20]:

import sys
#input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))


# In[21]:

import numpy as np
A.sort(key=lambda x:abs(x))
#print(N, A)


# In[25]:

A = np.array(A)
#print(sum(A<0))
if sum(A<0)%2 == 0:
    print(sum(abs(A)))
else:
    print(sum(abs(A[1:])) - abs(A[0]))


# In[ ]:





Measured memory_bytes: 21864
program test03_2
 implicit none
 integer N
 character(len=10),allocatable :: S(:)
 character(len=10),allocatable :: Smax(:)
 integer,allocatable :: Sk(:)
 integer :: kaisuu=1, maxkaisuu=0
 integer i, ii
 integer :: j=1
 integer :: yatta=0

 read *, N
 allocate(S(N))
 allocate(Sk(N))
 allocate(Smax(N))
 do i=1,N
  read *, S(i)
! S(i)=trim(S(i))
 end do

Smax='a'
Sk=1

 call quicksort1(S,1,N)

 do i=2,N
  if (S(i)==S(i-1)) then
   Sk(i)=Sk(i-1)+1
!print *,i, S(i) ,Sk(i), 'yes'
  else
   Sk(i)=1
!print *,i, S(i) ,Sk(i), 'no'
  end if
 !print *,i, S(i) ,Sk(i)
 end do

 yatta=MAXVAL(Sk) 
!print *, 'yatta=',yatta

 print *,''
 do i=1,N
  if ( Sk(i) == yatta ) then
   print '(A)', trim(S(i))
  end if
 end do

!print *,''
!print '(A)', S(1)


contains
recursive subroutine quicksort1(a, first, last)
  implicit none
   character(len=10),intent(inout)::a(*)
   integer,intent(in)::first,last

   character(len=10)::x,t
   integer::i,j

   x = a((first+last)/2)
   i = first
   j = last
   do 
     do while (a(i) < x)
       i=i+1
     end do
     do while (x < a(j))
       j=j-1
     end do
     if (i >= j) exit
      t = a(i)
      a(i) = a(j)
      a(j) = t
      i=i+1
      j=j-1
   end do
   if (first < i-1) call quicksort1(a, first, i-1)
   if (j+1 < last)  call quicksort1(a, j+1, last)
 return
end subroutine quicksort1

endprogram test03_2


Measured memory_bytes: 6656
import math
import bisect
import collections
import itertools
import heapq
import string
import sys
sys.setrecursionlimit(10**9)
def gcd(a,b):return math.gcd #最大公約数
def lcm(a,b):return (a*b) // math.gcd(a,b) #最小公倍数
def iin(): return int(input()) #整数読み込み
def isn(): return input().split() #文字列読み込み
def imn(): return map(int, input().split()) #整数map取得
def iln(): return list(map(int, input().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def join(l, s=''): return s.join(l) #リストを文字列に変換
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i: divisors.append(n//i)
    return divisors
def is_prime(n):
    if n == 1: return False
    for i in range(2, int(n**0.5) + 1):
        if n % i == 0: return False 
    return True
def primes(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n + 1, i): is_prime[j] = False
    return [i for i in range(n+1) if is_prime[i]]
def sieve_of_e(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n+1, i): is_prime[j] = False
    return is_prime

N,M = imn()
xy = [iln() for _ in range(M)]
b = [1] * (N+1)
r_exist = [False] * (N+1)
r_exist[1] = True

for i in range(M):
    s = xy[i][0]
    d = xy[i][1] 
    b[s] -= 1
    b[d] += 1
    if r_exist[s]: r_exist[d] = True
    if b[s] == 0: r_exist[s] = False
ans = 0
for i in range(1, N+1):
    if r_exist[i]: ans += 1
print(ans)
        
    




Measured memory_bytes: 29596
#define _CRT_SECURE_NO_WARNINGS // #pragma warning(disable:4996)
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <functional>
#include <sstream>
#include <cmath>
#include <set>
#include <map>
#include <stack>
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 pb push_back
#define mp(a,b) make_pair(a,b)
#define all(a) a.begin(),a.end()
#define len(x) ((int)(x).size())
#define tmax(a,b,c) max((a),max((b),(c)))
#define tmin(a,b,c) min((a),min((b),(c)))
#define debug(x) cerr << #x << " is " << x << endl;

typedef pair<int, int> Pii;
typedef map<int, int> Mii;
typedef vector<int> Vi;
typedef vector<vector<int> > VVi;
typedef long long ll;
const int inf = 2e9;
const ll ll_inf = 1e17;
const int mod = 1e9 + 7;
const long double eps = 1e-10;
typedef pair<ll, ll> Pll; 

int w, h;
int g[31][31]; // news = 1248
int d[31][31];
int r[4] = {1,2,4,8};
int rx[4] = {0,1,-1,0}; // news
int ry[4] = {-1,0,0,1};

void dijkstra()
{
	fill(d[0], d[31], 999);
	d[0][0] = 1;
	priority_queue<Pii> que;
	que.push(Pii(0,0));

	while (!que.empty()) {
		Pii p = que.top(); que.pop();
		int bh = p.first, bw = p.second;
		int cost = d[bh][bw];
		rep(i,0,4) {
			int nx = bw+rx[i], ny = bh+ry[i];
			if (nx < 0 || nx >= w || ny < 0 || ny >= h) continue;
			if (g[bh][bw] & r[i] && d[ny][nx] > cost+1) {
				d[ny][nx] = cost+1;
				que.push(Pii(ny, nx));
			}
		}
	}
	//rep(i,0,h) { rep(j,0,w) printf("%3d ", d[i][j]); cout << endl; }
}

int main()
{
	while (1) {
		cin >> w >> h;
		if (!w && !h) break;
		fill(g[0], g[31], 0);
		rep(i,0,h) {
			rep(j,0,w-1) {
				int t; cin >> t;
				if (!t) {
					g[i][j] += 2;
					g[i][j+1] += 4;
				}
			}

			if (i != h-1) rep(j,0,w) {
				int t; cin >> t;
				if (!t) {
					g[i][j] += 8;
					g[i+1][j] += 1;
				}
			}
		}
		dijkstra();
		d[h-1][w-1] == 999 ? cout << 0 << endl : cout << d[h-1][w-1] << endl;
	}

	return 0;
}

Measured memory_bytes: 3124
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Atcoder
{
    class Atcoderrrrrr
    {
        static void Main(string[] args)
        {
            int[] s = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            int k = int.Parse(Console.ReadLine());


            int sLarge = s.Max();
            Console.WriteLine(
                s.Max() * Math.Pow(2,k) + Math.Abs(s.Max() - s.Sum())
                );
        }
    }
}

Measured memory_bytes: 11348
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>

void print_state(int* A, int N) {
    for (int i=0; i<N-1; i++) {
        std::cout << A[i] << " ";
    }
    std::cout << A[N-1] << std::endl;
};

void swap(int* a, int* b) {
    int tmp = *b;
    *b = *a;
    *a = tmp;
};

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

    print_state(A,N);
    if (N > 1) {
        for (int i=1; i<N; i++) {
            // ideal: bisect
            for (int j=0; j<i; j++) {
                if (A[i] < A[j]) {
                    for (int k=j; k<i; k++) {
                        swap(&A[k],&A[i]);
                    }
                }
            }
            print_state(A,N);
        }
    }
    return 0;
}


Measured memory_bytes: 3128
#include <stdio.h>

int main (void)
{
    
    int a[5],i;
    for(i=0;i<5;i++)
    {
        scanf("%d",&a[i]);
    }
    for(i=0;i<5;i++)
    {
        if(a[i]==0)
        {
            printf("%d",i+1);
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 1680
n, q = gets.split().map(&:to_i)
queue = []

class Pro
  attr_accessor :name, :time

  def initialize(name, time)
    @name = name
    @time = time
  end
end

n.times do 
  name, time = gets.split()
  process = Pro.new(name, time.to_i)
  queue.push(process)
end

process_times = 0;

while queue.size > 0
  process = queue.shift
  if process.time <= q
    process_times += process.time
    puts "#{process.name} #{process_times}"
  else
    process_times += q
    process.time -= q
    queue.push(process)
  end
end




Measured memory_bytes: 13184
#!/usr/bin/env python3
import sys, math, itertools, heapq, collections, bisect, string, copy
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**8)
inf = float('inf')
mod = 10**9+7
ans = count = 0; pro = 1

n=int(input())
A=list(map(int,input().split()))
data=[0]*(10**5+1)
for i in range(n):
    if A[i]==0:
        pro*=3-data[0]
    else:
        # print(pro)
        # print(data[:10])
        # print(data[A[i]-1]-data[A[i]])
        pro*=data[A[i]-1]-data[A[i]]
    data[A[i]]+=1
    pro=pro%mod
# print(data[:10])
print(pro%mod)
    


Measured memory_bytes: 59504
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
    int h, w, m, tmph, tmpw, ans;
    cin >> h >> w >> m;
    vector<vector<int>> bh(h, vector<int>(2)), bw(w, vector<int>(2));
    vector<pair<int, int>> b;
    for (int i = 0; i < m; i++) {
        scanf("%d%d", &tmph, &tmpw);
        tmph--; tmpw--;
        bh[tmph][0]++; bw[tmpw][0]++;
        b.push_back(make_pair(tmph, tmpw));
    }
    for (int i = 0; i < h; i++) {
        bh[i][1] = i;
    }
    for (int j = 0; j < w; j++) {
        bw[j][1] = j;
    }
    sort(bh.begin(), bh.end());
    reverse(bh.begin(), bh.end());
    sort(bw.begin(), bw.end());
    reverse(bw.begin(), bw.end());
    sort(b.begin(), b.end());
    int i = 0, j;
    while (i < h && bh[i][0] == bh[0][0]) {
        j = 0;
        while (j < w && bw[j][0] == bw[0][0]) {
            auto itr = lower_bound(b.begin(), b.end(), make_pair(bh[i][1], bw[j][1]));
            if (*itr != make_pair(bh[i][1], bw[j][1])) {
                ans = bh[i][0] + bw[j][0];
                i = h;
                break;
            }
            else {
                ans = bh[i][0] + bw[j][0] - 1;
            }
            j++;
        }
        i++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 40324
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main()
{
    int n;
    cin>>n;
    int a[n+1];
    int b[n];
    for(int i=0;i<n+1;i++)
        cin>>a[i];
    for(int i=0;i<n;i++)
        cin>>b[i];
    int sum=0;
    for(int i=0;i<n;i++)
    {
        if(a[i]+a[i+1]<=b[i])
            {
                sum+=a[i]+a[i+1];
                a[i+1]=0;
            }
        else
        {
            sum=sum+b[i];
            if(b[i]<=a[i])
            {
                continue;
            }
            else if(b[i]>a[i])
            {
                a[i+1]=a[i+1]-(b[i]-a[i]);
            }
        }
    }
    cout<<sum;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define VIEW(x) do {cerr << #x << ": "; for(auto i : x) cerr << i << " "; cerr << endl;} while(0)
#define ALL(x) (x).begin(),(x).end()
template<class T>bool umax(T &a, const T &b) {if(a<b){a=b;return 1;}return 0;}
template<class T>bool umin(T &a, const T &b) {if(b<a){a=b;return 1;}return 0;}

template<typename A,size_t N,typename T> void FILL(A (&array)[N],const T &val){fill((T*)array,(T*)(array+N),val);}
template<typename T> void FILL(vector<T> &v, const T &x) {fill(v.begin(), v.end(), x);}
template<typename T> void FILL(vector<vector<T>> &v, const T &x) {for(auto &i:v)fill(i.begin(), i.end(), x);}

int main() {
  string s,t; cin >> s >> t;
  int n = s.size(), m=t.size();
  int ans = 1000;
  rep(i,n-m+1) {
    int c = 0; 
    rep(j,m) if(s[i+j] != t[j]) c++;
    umin(ans, c);
  }
  cout << ans << endl;

}


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

const int MAXN = 1e5+5;

ll n, dp[MAXN], x[MAXN], e, t, ct;
set<pii> dp1, dp2;

int main() {
	cin >> n >> e >> t;
	for (int i = 0; i < n; ++i)
		cin >> x[i];
	x[n] = e;

	dp[0] = x[0];
	dp1.insert(pii(dp[0]-x[0], 0));
	for (int j = 1; j <= n; ++j) {
		dp[j] = 1e18;
		while (2*(x[j-1]-x[ct]) > t) {
			dp1.erase(pii(dp[ct]-x[ct], ct));
			dp2.insert(pii(dp[ct]-3*x[ct], ct));
			++ct;
		}

		if (!dp1.empty())
			dp[j] = min(dp[j], (*dp1.begin()).first+t+x[j]);
		if (!dp2.empty())
			dp[j] = min(dp[j], (*dp2.begin()).first+x[j]+2*x[j-1]);
		dp1.insert(pii(dp[j]-x[j], j));
	}

	cout << dp[n] << endl;
}


Measured memory_bytes: 8064
def solve():
    N, M = map(int, input().split())
    c_doubled_cnt = M // 2
    ans = 0
    if N >= c_doubled_cnt:
        ans = c_doubled_cnt
    else:
        ans = N + (c_doubled_cnt-N) // 2
    
    print(ans)

if __name__ == '__main__':
    solve()

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

const int Maxn=1e5;

int N,A[Maxn+5];

int ans[Maxn+5];

int main() {
	#ifdef LOACL
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
	#endif
	scanf("%d",&N);
	for(int i=1;i<=N;i++)
		scanf("%d",&A[i]);
	int sum=0,tmp=0;
	for(int i=1;i<=N;i++) {
		if(i&1)tmp+=2*A[i];
		sum+=A[i];
	}
	ans[1]=tmp-sum;
	for(int i=2;i<=N;i++)
		ans[i]=2*A[i-1]-ans[i-1];
	for(int i=1;i<=N;i++)
		printf("%d ",ans[i]);
	return 0;
}

Measured memory_bytes: 2048
#include <iostream>
#include <algorithm>

using namespace std;
string str;

bool isPalindrome(int begin, int end) {
    string s, s_cpy;
    for (int i = begin; i <= end; i++) {
        s += str[i];
    }
    s_cpy = s;
    reverse(s.begin(), s.end());
    if (s == s_cpy) {
        return true;
    } else {
        return false;
    }
}

int main() {
    cin >> str;
    int len = str.length();
    if (isPalindrome(0, len - 1) && isPalindrome(0, (len - 1) / 2 - 1) && isPalindrome((len + 3) / 2 - 1, len - 1)) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		try {
			String input = scanner.nextLine();
			System.out.print(700 + input.replace("x", "").length() * 100);
		} catch(Exception e) {
			e.printStackTrace();
		}finally {
			scanner.close();
		}
	}
}

Measured memory_bytes: 21844
#include<iostream>
#include<string>
using namespace std;
int main(){
    string S;
    int sum=0,i;
    cin >> S;
    if(S=="SSS"){
        sum=0;
    }
    else{
        sum=1;
        for(i=1;i<3;++i){
            if(S.at(i-1)==S.at(i)&&S.at(i)=='R'){
                ++sum;

            }
        }
    }
    cout << sum << endl;
   
    
}

Measured memory_bytes: 3596
//itp1_topic2_b
#include <bits/stdc++.h>
using namespace std;
      int main(){
      int a,b,c;
      cin>>a>>b>>c;
  
  
      if (a < b && b < c) cout<<"Yes"<<endl;
      else cout<<"No"<<endl;


      return 0;
}


Measured memory_bytes: 3092
n = int(input())
a = list(map(int, input().split()))

evens = []
evens_count = 0
approved = "DENIED"
out_frag = 0

for i in range(n):
    if a[i] % 2 == 0:
        evens.append(a[i])
        evens_count += 1

if evens_count > 0:
    for j in range(evens_count):
        if (evens[j] % 3 == 0) or (evens[j] % 5 == 0):
            pass
        else:
            out_frag = 1
    if out_frag == 0:
        approved = "APPROVED"
elif evens_count == 0:
    approved = "APPROVED"

print(approved)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define REP(i,a,b) for(int i=(a),_ed=(b);i<=_ed;++i)
#define DREP(i,a,b) for(int i=(a),_ed=(b);i>=_ed;--i)
typedef long long ll;
inline int read(){
    register int x=0,f=1;register char ch=getchar();
    while(!isdigit(ch)){if(ch=='-')f=0;ch=getchar();}
    while(isdigit(ch)){x=x*10+(ch^'0');ch=getchar();}
    return f?x:-x;
}

const int N=4e2+5,mod=998244353;
int n,A,B,a[N],b[N],f[2][N][N],inv[N];
inline void inc(int &x,int y){x=x+y<mod?x+y:x+y-mod;}

int main(){
    //freopen("in.in","r",stdin);
    inv[1]=1;
    REP(i,2,N-1)inv[i]=1ll*(mod-mod/i)*inv[mod%i]%mod;
    n=read();
    REP(i,1,n)A+=a[i]=read(),B+=b[i]=read();
    f[0][0][0]=mod-1;//f[i][j][k]: j=\sum{a},k=\sum{d}
    REP(i,1,n){
	memcpy(f[1],f[0],sizeof f[0]);
	for(int t=0,p=1;t<b[i];++t,p=1ll*p*a[i]%mod*inv[t]%mod)
	    REP(j,a[i],A)REP(k,t,B)
		inc(f[0][j][k],mod-1ll*f[1][j-a[i]][k-t]*p%mod);
    }
    int ans=0;
    REP(j,1,A){
	int len=1ll*A*inv[j]%mod;
	for(int k=0,p=1;k<=B;++k,p=1ll*p*k%mod*inv[j]%mod)
	    inc(ans,1ll*f[0][j][k]*p%mod*len%mod);
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 1536
#include<stdio.h>
struct Card
	{
		char suit;
		int value;
	};
int main()
{
	int n,i,j,k;
	while(scanf("%d",&n)!=EOF)
	{
		struct Card a[100],b1[100],b2[100],c;
		for(i=0;i<n*2;i++)
		{
			a[i].suit=getchar();
			scanf("%d",&a[i].value);
		}
		for(i=0,j=1;i<n;i++,j+=2)
		{
			b1[i]=a[j];
			b2[i]=a[j];
		}
		for(i=0;i<n;i++)    //冒泡排序
		{
			for(j=n-1;j>i;j--)
			{
				if(b1[j].value<b1[j-1].value)
				{
					c=b1[j];
					b1[j]=b1[j-1];
					b1[j-1]=c;
				}
			}
		}
		for(i=0;i<n;i++)
		{
			if(i==n-1)
			{
				printf("%c%d",b1[i].suit,b1[i].value);
			}
			else
			{
				printf("%c%d ",b1[i].suit,b1[i].value);
			}
		}
		printf("\n");
		printf("Stable\n");

		for(i=0;i<n;i++)    //选择排序
		{
			k=i;
			for(j=i;j<n;j++)
			{
				if(b2[j].value<b2[k].value)
				{
					k=j;
				}
			}
				c=b2[k];
				b2[k]=b2[i];
				b2[i]=c;
		}
		for(i=0;i<n;i++)
		{
			if(i==n-1)
			{
				printf("%c%d",b2[i].suit,b2[i].value);
			}
			else
			{
				printf("%c%d ",b2[i].suit,b2[i].value);
			}
		}
		printf("\n");
		for(i=0,k=0;i<n;i++)
		{
			if(b1[i].suit!=b2[i].suit)
			{
				k++;
			}
		}
		if(k>0)
		{
			printf("Not stable\n");
		}
		else
		{
			printf("Stable\n");
		}
	}
	return 0;
}



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

using namespace std;

int main()
{
	int count;
	cin >> count;
	vector<int> rabbits;
	for (int i = 0; i < count; i++)
	{
		int like;
		cin >> like;
		rabbits.push_back(like);
	}

	int pair_count = 0;
	for (int i = 0; i < count + 1; i++)
	{
		int j = rabbits[i] - 1;
		if (i == rabbits[j] - 1)
			pair_count++;
	}
	cout << pair_count / 2 << endl;
	return 0;
}

Measured memory_bytes: 892
import std.stdio, std.conv, std.string, std.math, std.regex, std.range, std.ascii, std.algorithm;

void main(){
	auto N = readln.chomp.to!long;
	auto W = readln.split.to!(long[]);
	long count = W.sum;
	foreach(i; 0..N){
		long x = abs(W.sum - 2*((W[0..i]).sum));
		if(x < count) count=x;
	}
	writeln(count);
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main()
{
	ios::sync_with_stdio(false);
	ll n; cin >> n;
	if (n % 2LL != 0)
		n *= 2LL;
	cout << n << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long f(int n){
    long a = 1;
    for(int i=2;i<n+1;i++){
        a *= i;
    }
    return(a);
}
int main(){
    int n; cin >> n;
    double a = 0;
    vector<vector<int>> v(n,vector<int>(2));
    for(int i=0;i<n;i++)cin >> v[i][0] >> v[i][1];
    sort(v.begin(),v.end());
    do{
        for(int i=1;i<n;i++){
            a += (double)sqrt(pow(v[i][0]-v[i-1][0],2)+pow(v[i][1]-v[i-1][1],2));
        }
    }while(next_permutation(v.begin(),v.end()));
    double ans = a/f(n);
    cout << setprecision(20) << ans << endl;
}    

Measured memory_bytes: 3764
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
#include <map>
#include <iomanip>
#include <limits.h>

using namespace std;    
typedef long long ll;
typedef pair<ll, ll> pll;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const bool DEBAG = false;

int main(){

    ll N;
    cin >> N;
    vector<ll> v(N);
    for(int i = 0; i < N; i++) cin >> v[i];

    sort( all(v) );
    
    vector<ll> tmp;
    if(N % 2 == 0){
        tmp.push_back( v[ N / 2 - 1] );
        for(int i = 0; i < (N / 2 - 1); i++){
            tmp.push_back( v[N - 1 - i] );
            tmp.push_back( v[i] );
        }
        tmp.push_back( v[N / 2] );
        //cout << "size = " << N / 2 - 1 << endl;
        //cout << "size = " << tmp.size() << endl;

        ll ans = 0;
        for(int i = 0; i < N - 1; i++){
            ans += abs( tmp[i] - tmp[i+1] );
        }
        cout << ans << endl;
        return 0;
    }

    tmp.clear();
    tmp.push_back( v[ N / 2] );
    for(int i = 0; i < N / 2; i++){
        tmp.push_back( v[i] );
        tmp.push_back( v[N - 1 - i] );
    }

    ll ans1 = 0;
    for(int i = 0; i < N - 1; i++){
        ans1 += abs( tmp[i] - tmp[i+1] );
    }

    tmp.clear();
    tmp.push_back( v[ N / 2] );
    for(int i = 0; i < N / 2; i++){
        tmp.push_back( v[N - 1 - i] );
        tmp.push_back( v[i] );
    }

    ll ans2 = 0;
    for(int i = 0; i < N - 1; i++){
        ans2 += abs( tmp[i] - tmp[i+1] );
    }

    cout << max(ans1, ans2) << endl;





}

Measured memory_bytes: 2168
using System;
using static System.Console;
using System.Linq;

namespace Main
{
    class Program
    {
        static void Main(string[] args)
        {
            decimal[] tmp = ReadLine().Split(' ').Select(decimal.Parse).ToArray();
            decimal T = tmp[0];
            decimal X = tmp[1];
            WriteLine(T / X);
        }
    }
}

Measured memory_bytes: 13396
#include <iostream>
#define MAX 100001
using namespace std;

int binarySearch(int *S, int n, int key) {
    int l, r, mid;
    l = 0;
    r = n;
    while(l < r) {
        mid = (l + r) / 2;
        if(S[mid] == key) return 1;
        else if(key < S[mid]) r = mid;
        else l = mid + 1;
    }
    return 0;
}

int main() {
    int n, q, i, key, cnt=0;
    int S[MAX];
    cin >> n;
    for(i=0; i < n; i++) {
        cin >> S[i];
    }
    cin >> q;
    for(i=0; i < q; i++) {
        cin >> key;
        if(binarySearch(S, n, key)) cnt++;
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3496
#include <iostream>
#include <algorithm>

using namespace std;
int main() {
    int n;
    cin >> n; 
    int a[103];
    for (int i=0;i<n;i++){
        cin >>a[i];
    }
    for(int j=1;j<n;j++){
        int k=j-1;
        int v=a[j];
         for (int i=0;i<n-1;i++){
        cout << a[i]<<" ";
    }
    cout <<a[n-1]<<endl;
    while (1){
        if(k<0){
            break;
        }
        if(a[k]>v){
            a[k+1]=a[k];
            a[k]=v;
            }
        k--;
        v=a[k+1];
        } 
    }
         
    for (int i=0;i<n-1;i++){
        cout << a[i]<<" ";
    }
    cout <<a[n-1]<<endl;
    return 0;
}


Measured memory_bytes: 3116
#include <bits/stdc++.h>
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rer(i, a, b) for(ll i = ll(a) - 1; i >= ll(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
using namespace std;
typedef long long int ll;
typedef pair <int, int> P;

const ll MOD=1000000007;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin>>N;
    double x[N];
    string u[N];
    rep(i,0,N){
        cin>>x[i]>>u[i];
    }
    double ans=0;
    rep(i,0,N){
        if(u[i]=="JPY") ans+=x[i];
        else ans+=x[i]*380000;
    }
    cout <<setprecision(15)<<ans<<"\n";
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int main(){
	int n;
	scanf("%d",&n);
	int hi;
	scanf("%d",&hi);
	int a,cnt=0;
	for(int i = 1;i<=n;i++){
		scanf("%d",&a);
		if(a>=hi)cnt++;
	}
	printf("%d\n",cnt);
	return 0;
} 

Measured memory_bytes: 256
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x)          (x).begin(), (x).end()
#define rep(i, n)       for (i64 i = 0, i##_limit = (n); i < i##_limit; ++i)
#define reps(i, s, t)   for (i64 i = (s), i##_limit = (t); i <= i##_limit; ++i)
#define repr(i, s, t)   for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#ifndef DBG
#define trace(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U> inline bool chmax(T &a, const U &b) { return b > a && (a = b, true); }
template <class T, class U> inline bool chmin(T &a, const U &b) { return b < a && (a = b, true); }
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> make_v(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto make_v(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(make_v<T>(initValue, args...))>(sz, make_v<T>(initValue, args...));
}

inline void read() {}

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

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<< (ostream &out, const vector<T> &vec) {
    static constexpr const char *delim[] = { " ", "" };
    for (const auto &e : vec) out << e << delim[&e == &vec.back()];
    return out;
}
// }}} End Header

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr);

    int N;
    string s;

    read(N, s);

    s.erase(unique(all(s)), s.end());
    print(s.length());

    return 0;
}


Measured memory_bytes: 512
from math import factorial
from itertools import permutations

n = int(input())
x, y = [0] * n, [0] * n
for i in range(n):
    x[i], y[i] = map(int, input().split())

dist_sum = 0
for route in permutations(range(n), n):
    for j in range(1, n):
        dist = (x[route[j]] - x[route[j - 1]]) ** 2
        dist += (y[route[j]] - y[route[j - 1]]) ** 2
        dist = dist ** 0.5
        dist_sum += dist
ans = dist_sum / factorial(n)
print(ans)


Measured memory_bytes: 3064
N = int(input())
A = [0]*N
A = list(map(int, input().split()))
 
sum_step = 0
 
for n in range(1,N):
  if A[n] < A[n-1]:
    sum_step += A[n-1] - A[n]
    A[n] = A[n-1]

print(sum_step)

Measured memory_bytes: 33604
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
#define PAUSE \
	int t;    \
	cin >> t
#define int long long
#define vi vector<long long>
#define mapii map<long long, int>
#define mapci map<char, int>
#define append(x) push_back(x)
#define tcase          \
	long long t;       \
	scanf("%lld", &t); \
	while (t--)
#define prq priority_queue
#define fio                           \
	ios_base::sync_with_stdio(false); \
	cin.tie(NULL)
// #define debug(x, y) cout<<"case #"<<x<<" at itr #"<<y<<endl
#define debug(x) cout << "case #" << x << endl
#define ff first
#define ss second
#define range(ini, x) for (int itr = ini; itr < x; itr++)
#define takearr(x)    \
	for (auto &i : x) \
	cin >> i
#define print(x)     \
	for (auto i : x) \
		cout << i << " ";
#define FOR(x, y) for (int i = x; i < y; i++)
#define for0(i, n) for (int i = 0; i < n; i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define foreach(i, x) for (auto i : x)
#define setbitcount __builtin_popcount
//******************/
// #ifndef ONLINE_JUDGE
// 	freopen("input.txt", "r", stdin);
// 	freopen("output.txt", "w", stdout);
// #endif
//******************/
// #define range(ini, x, step) for( int itr = ini, i < x; itr += step )
using namespace std;
// using namespace __gnu_pbds;
// template < class type > using oset=tree<type, null_type,less<type>, rb_tree_tag,tree_order_statistics_node_update>;
const int mmx = 1e5 + 1;
const int mnx = 1e4 + 1;
const int mmod = 1e9 + 7;

int n, k;
int dp[mmx];
vi arr;

int jump( int index ){

	if( dp[index] != -1 ) return dp[index];

	if( index == n - 1 ){
		dp[index] = 0;
		return dp[index];
	}

	int mini = INT_MAX;

	for( int i = index + 1; i < min( n, index + k + 1 ); i++ ){
		mini = min( mini, abs( arr[index] - arr[i] ) + jump(i) );
	}

	dp[index] = mini;
	return dp[index];

}

signed main()
{

	memset(dp, -1, sizeof dp);

	cin>>n>>k;

	for0(i,n){
		int in;
		cin>>in;
		arr.push_back(in);
	}
	cout<<jump(0)<<endl;
	return 0;
}

Measured memory_bytes: 8180
S = input()

L_searching_flag = True
R_searching_flag = False
LR_idx = []
boundary_idx = []
for i, char in enumerate(S):
    if L_searching_flag:
        if char == "L":
            L_searching_flag = False
            R_searching_flag = True
            LR_idx.append(i)
        else:
            continue
    elif R_searching_flag:
        if char == "R":
            L_searching_flag = True
            R_searching_flag = False
            boundary_idx.append(i - 1)
        else:
            continue

# dummy right side idx
boundary_idx.append(len(S)-1)

last_right_L = -1

ans = []
for left_L_idx, right_L_idx in zip(LR_idx, boundary_idx):
    while(len(ans) < left_L_idx-1):
        ans.append(str(0))


    L_num = right_L_idx - left_L_idx + 1
    R_num = left_L_idx - last_right_L - 1
    last_right_L = right_L_idx
    if (L_num + R_num) % 2 == 0:
        ans.append(str(int((L_num+R_num)/2)))
        ans.append(str(int((L_num+R_num)/2)))
    else:
        if R_num < L_num:
            if L_num % 2 == 1:
                ans.append(str(int((L_num+R_num-1)/2)))
                ans.append(str(int((L_num+R_num+1)/2)))
            else:
                ans.append(str(int((L_num+R_num+1)/2)))
                ans.append(str(int((L_num+R_num-1)/2)))
        else:
            if R_num % 2 == 1:
                ans.append(str(int((L_num+R_num+1)/2)))
                ans.append(str(int((L_num+R_num-1)/2)))
            else:
                ans.append(str(int((L_num+R_num-1)/2)))
                ans.append(str(int((L_num+R_num+1)/2)))

while(len(ans) < len(S)):
    ans.append(str(0))

print(" ".join(ans))


Measured memory_bytes: 14108
package main

import (
        "fmt"
)

func solution(h, w int, a []string) []string {
        out := make([]string, h+2)
        for i := range out {
                buf := make([]byte, 0, w+2)
                for j := 0; j < w+2; j++ {
                        if i > 0 && i < h+1 && j > 0 && j < w+1 {
                                buf = append(buf, a[i-1][j-1])
                        } else {
                                buf = append(buf, '#')
                        }
                }
                out[i] = string(buf)
        }
        return out
}

func main() {
        var h, w int
        fmt.Scan(&h, &w)
        a := make([]string, h)
        for i := range a {
                fmt.Scan(&a[i])
        }
        for _, t := range solution(h, w, a) {
                fmt.Println(t)
        }
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pii;

#define abs(a) ((a) < (0)? -(a):(a))
#define rep(i, n) REP(i, 0, (n))
#define REP(i, a, n) for(int i=(a); i<(n); i++)
#define pb push_back

int main() {
	int n, m;
	cin >> n >> m;
	vector<vint> v;
	rep(i, m) {
	    int k;
	    cin >> k;
	    vint w;
	    rep(j, k) {
	        int x;
	        cin >> x;
	        w.pb(x);
	    }
	    v.pb(w);
	}
	vint p;
	rep(i, m) {
	    int x;
	    cin >> x;
	    p.pb(x);
	}
	int ans = 0;
	rep(i, 1<<n) {
	    int cnt = 0;
	    rep(j, m) {
	        int x = 0;
	        for(int s : v[j]) {
	            if(i & (1<<(s-1))) x++;
	        }
	        if(x % 2 == p[j]) cnt++;
	    }
	    if(cnt == m) ans++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <iostream>
using namespace std;

int main()
{
	int n,m,in,MAX;
	vector<int> P;
	vector<int>::iterator it;
	
	while(scanf("%d%d",&n,&m)&&(n!=0||m!=0)){
		P.clear();
		
		for(int i = 0; i < n; i++){
			scanf("%d",&in);
			P.push_back(in);
		}
		for(int i = 0; i < n; i++){
			for(int j = 0; j < n; j++){
				P.push_back(P[i]+P[j]);
			}
		}
	
		P.push_back(0);
		sort( P.begin(),P.end() );
		MAX = 0;
	
		for(int i = 0; i < P.size(); i++){
			if(P[i] >= m){
				break;
			}
			it = upper_bound(P.begin(),P.end(),m-P[i]);
			it--;
			MAX = max(MAX,P[i] + *it);
		}
	
		printf("%d\n",MAX);
	}
	
	return 0;
}

Measured memory_bytes: 7020
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
#define pq_pair_tB priority_queue <pair<ll,ll>, vector<pair<ll,ll> > , greater<pair<ll,ll> > >
#define pq_pair_ts priority_queue <pair<ll,ll> > //第二成分の大きさが関係ない
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}



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

    string str;
    ll K ;
    cin >> str;
    cin >> K;

    vector<string> ans;

    rep(aaaaa, 5){
        ll len = aaaaa + 1;
        if(str.size() < len) break;

        rep(i, str.size()){
            if((i + len) > str.size()) break;
            ans.pb(str.substr(i, len));
        }
    }
    rmsame(ans);
    //rep(i, ans.size()) cerr << ans[i] << endl;
    cout << ans[K-1] << endl;


	//cout << fixed << setprecision(16) << ans << endl;
	return 0;
}


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

const int INF = 1e9 + 9;

using namespace std;

bool exact(int idx, int K, vector<int>& A){
  int left = idx, right = idx;
  
  for(int i = idx; i > max(idx - K, -1); --i){
    if(A[i] >= A[idx]) left = i;
    else break;
  }
  
  for(int i = idx; i < min(idx + K, (int)A.size()); ++i){
    if(A[i] >= A[idx]) right = i;
    else break;
  }
  
  return right - left + 1 >= K;
}

int main(){
  int N, K, Q;
  cin >> N >> K >> Q;
  
  vector<int> A(N);
  for(int i = 0; i < N; ++i) cin >> A[i];
  
  int min_diff = INF;
  for(int i = 0; i < N; ++i){
    int erasable = 0;
    int len = 0;
    vector<int> max_candidate;
    priority_queue<int, vector<int>, greater<int>> pq;
    for(int j = 0; j < N; ++j){
      if(A[j] >= A[i]){
        ++len;
        pq.push(A[j]);
      }else{
        if(len - K + 1 >= 0){
          erasable += len - K + 1;
          for(int k = 0; k < len - K + 1; k++){
            max_candidate.push_back(pq.top());
            pq.pop();
          }
        }
        
        while(pq.size()) pq.pop();
        len = 0;
      }
    }
    
    if(len - K + 1 >= 0){
      erasable += len - K + 1;
      for(int k = 0; k < len - K + 1; k++){
        max_candidate.push_back(pq.top());
        pq.pop();
      }
    }
    
    if(erasable >= Q && exact(i, K, A)){
      sort(max_candidate.begin(), max_candidate.end());
      min_diff = min(max_candidate[Q - 1] - A[i], min_diff);
    }
  }
  
  cout << min_diff << endl;
  
  return 0;
}

Measured memory_bytes: 3664