akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <chrono>

using namespace std;
using namespace chrono;
 
typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

//#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define loop(x,n) for(int x = 0; x < n; ++x)
#define FORd(i,a,b) for (int i = (b)-1; i >= (a); i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a, x) for (auto& a : x)

#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound

#define sz(x) (int)x.size()
#define beg(x) x.begin()
#define en(x) x.end()
#define all(x) beg(x), en(x)
#define resz resize

const int MOD = 1000000007; // 998244353
const ll INF = 1e18;
const int MX = 100001;

string get_str() {
    string temp;
    cin >> temp;
    return temp;
}
int get_int() {
    int temp;
    cin >> temp;
    return temp;
}


int n, k, a[1000];


int main() {
    
    cin >> n >> k;

    loop(i, n) cin >> a[i];
    
    sort(a, a+n);

    ll ans = 0;

    loop(i, k) ans += a[i];

    cout << ans << endl;

}

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

int main(){
  int A,B,C;
  int p,q,r;
  cin >>A>>B>>C;
  p=abs(A-B);
  q=abs(B-C);
  r=abs(A-C);
  cout<<p+q+r-max(max(p,q),r)<<endl;
  return 0;
}


Measured memory_bytes: 256
/********************************
*** ******** ********** *********
*** * ****** ********* * ********
*** ** ***** ******** *** *******
*** *** **** ******* ***** ******
*** **** *** ****** ******* *****
*** ***** ** ***** +++++++++ ****
*** ****** * **** *********** ***
*** *******  *** ************* **
*** ******** ** *************** *
**********_**********************
* |   /  / \  \     /    /\     *
* |  /  |   |  \   /    /  \    *
* | /   |   |   \ /    /    \   *
* |+\   |   |    |    /______\  *
* |  \  |   |    |   |        | *
* |   \  \_/     |   |        | *
********************************/
#include<bits/stdc++.h>
#define lli long long int
#define ld long double
#define MOD 1000000007
#define KING 1000000002
#define queen 1000002
#define fi first
#define se second
#define se second
#define lsb(i) (i & -i)
#define Pi 3.141592653589793238
#define nl cout<<'\n'
#define TEST cout<<"TEST",nl
#define all(a) a.begin(), a.end()
#define remax(a, b) (a = ((a<b) ? b : a))
#define remin(a, b) (a = ((a<b) ? a : b))
#define pr pair<lli,lli>
#define pb push_back
#define eb emplace_back
#define precise(a) cout<<fixed<<setprecision(a)
#define mp make_pair
#define vi vector<lli>
#define vpi vector<pr> 
#define P pair<lli,pr>
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL)
#define NA(i,s,n) for(lli i=s;i<n;i++)
using namespace std;

lli power(lli x,lli y,lli p) { 
	lli res = 1;	 
	x = x % p; 
	while (y > 0) 
	{ 
		if (y & 1) 
			res = (res*x) % p; 
		y = y>>1; 
		x = (x*x) % p; 
	} 
	return res; 
} 

const lli N = 3e3 + 1;
lli n; 
ld p, dp[N];

void solve(){
    cin >> n;
    // dp[i] is prob of having exactly i heads sofar.
    dp[0] = 1;
    NA(i,0,n){
        cin >> p;
        for(lli j = i+1; j>-1; --j){
            dp[j] = (j==0 ? 0 : dp[j-1]) * p + dp[j] * (1 - p); 
            // dp[j] -> prob of (j-1) heads * present head + prob j heads * present tail
        }
    }
    ld ans = 0;
    NA(i,(n/2)+1, n+1){
        ans += dp[i];
    }
    precise(10);
    cout << ans << '\n';
    return;
}
int main(){
    fastIO;
    lli t = 1;
    // cin>>t;
    NA(i,0,t){
        solve();
    }
    return 0;

}


Measured memory_bytes: 384
n, m, k = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)
b = gets.split.map(&:to_i)
c = Array.new(n + 1, 0)
n.times do |i|
  c[i + 1] = c[i] + a[i]
end
d = Array.new(m + 1, 0)
m.times do |i|
  d[i + 1] = d[i] + b[i]
end
cnt = 0
0.upto(n) do |i|
  break if c[i] > k
  ok = 0
  ng = m + 1
  while (ng - ok).abs > 1
    mid = (ok + ng) / 2
    if d[mid] <= k - c[i]
      ok = mid
    else
      ng = mid
    end
  end
  cnt = i + ok if cnt < i + ok
end
puts cnt

Measured memory_bytes: 44928
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#include<map> 
#define sqr(x) (x)*(x)
using namespace std;
int n,x,ans;
map<int,int> mp;
int main()
{
	cin>>n;
	for (int i=1;i<=n;i++) {cin>>x;mp[x]++;}
	for (map<int,int>::iterator it=mp.begin();it!=mp.end();it++)
	{
		if (it->first>it->second) ans+=it->second; else ans+=it->second-it->first;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 4736
#include <cstdio>
#include <algorithm>

using namespace std;

int x[200000];
long long left[200001];
long long right[200001];

int main() {
    int l, n, i;
    long long ans = 0;
    
    scanf("%d %d", &l, &n);
    
    for (i = 0; i < n; i++) scanf("%d", &x[i]);
    
    for (i = 0; i < n; i++) left[i + 1] = left[i] + x[i] * 2;
    for (i = 0; i < n; i++) right[i + 1] = right[i] + (l - x[i]) * 2;
    
    for (i = 0; i < n; i++) {
        long long sum = 0;
        
        sum += left[(n + i + 1) / 2] - left[i];
        sum += right[n] - right[(n + i + 1) / 2];
        
        if ((n - i) % 2 == 0) {
            sum -= l - x[(n + i) / 2];
        } else {
            sum -= x[(n + i) / 2];
        }
        
        ans = max(ans, sum);
    }
    
    for (i = n - 1; i >= 0; i--) {
        long long sum = 0;
        
        sum += right[i + 1] - right[(i + 1) / 2];
        sum += left[(i + 1) / 2];
        
        if ((i + 1) % 2 == 0) {
            sum -= x[i / 2];
        } else {
            sum -= l - x[i / 2];
        }
        
        ans = max(ans, sum);
    }
    
    printf("%lld\n", ans);
    
    return 0;
}


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

using namespace std;

void insertion_Sort(int A[], int N){
    for(int j = 1; j < N; j++){
        int v = A[j];
        int i = j - 1;
        while(i >= 0 && A[i] > v){
            A[i + 1] = A[i];
            i--;
        }            
        A[i + 1] = v;
        for(int k = 0; k < N-1; ++k) {
            cout << A[k] << " "; 
        }
        cout << A[N-1] << endl;
    }
}

int main(){
    int N;
    cin >> N;
    int A[110];
    for(int i = 0; i < N; ++i) cin >> A[i];
    for(int i = 0; i < N-1; ++i) cout << A[i] << " ";
    cout << A[N-1] << endl;
    insertion_Sort(A, N);
    return 0;

}


Measured memory_bytes: 3100
def main2():
    dic = {1:0, 2:0, 3:0, 4:0, 5:0, 6:0, 7:0, 8:0, 9:0, 10:1, 11:1, 12:1, 13:1, 14:2, 15:2, 16:3, 17:3, 18:3, 19:3, 20:8, 21:8, 22:11, 23:11, 24:11, 25:11, 26:14, 27:14, 28:32, 29:32, 30:35, 31:35, 32:35, 33:35, 34:42, 35:42, 36:42, 37:42, 38:49, 39:49, 40:49, 41:49, 42:49, 43:49, 44:75, 45:75, 46:86, 47:86, 48:86, 49:86, 50:86, 51:86, 52:123, 53:123, 54:131, 55:131, 56:131, 57:131, 58:148, 59:148, 60:153, 61:153, 62:170, 63:170, 64:170, 65:170, 66:170, 67:170, 68:227, 69:227, 70:227, 71:227, 72:227, 73:227, 74:250, 75:250, 76:323, 77:323, 78:324, 79:324, 80:324, 81:324, 82:354, 83:354, 84:354, 85:354, 86:384, 87:384, 88:384, 89:384, 90:384, 91:391, 92:491, 93:491, 94:529, 95:529, 96:529, 97:529, 98:529, 99:529, 100:543}
    print(dic[int(input())])


if __name__ == '__main__':
    main2()

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

using namespace std;

int main(){
    ll N,K;    
    cin >> N >> K;
    
    vector<int> A(N);
    pair<int,int> T;
    rep(i,N) cin >> A[i];
    
    ll tk = 0, tkAll = 0;
    for(ll i = 0; i < N; i++) {
        ll t = A[i];
        for(ll j = 0; j < N; j++) {
            if(t > A[j]) {
                if(j >= i) tk++;
                tkAll++;
            }
        }
    }
    
    ll ans;
    ans=K*(K-1)/2;
    ans%=1000000007;
    ans*=tkAll;
    ans%=1000000007;
    ans+=tk*K;
    ans%=1000000007;
    
    cout << ans  << endl;
}


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

int main(){
	int H , W;
	while(1){
		cin >> H >> W;
		if(H==0 && W==0) break;
		for(int i=1 ; i<=H ; i++){
			for(int j=1 ; j<=W ; j++){
				cout << '#';
			}
			cout << endl;
		}
		cout << endl;
	}
}

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

int main() {
  int a,b,x,y;
  cin>>a>>b>>x>>y;
  for(int i=0;i<x-a;i++){
    cout<<"R";
  }
  for(int i=0;i<y-b;i++){
    cout<<"U";
  }
  for(int i=0;i<x-a;i++){
    cout<<"L";
  }
  for(int i=0;i<y-b+1;i++){
    cout<<"D";
  }
  for(int i=0;i<x-a+1;i++){
    cout<<"R";
  }
  for(int i=0;i<y-b+1;i++){
    cout<<"U";
  }
  cout<<"L"<<"U";
  for(int i=0;i<x-a+1;i++){
    cout<<"L";
  }
  for(int i=0;i<y-b+1;i++){
    cout<<"D";
  }
  cout<<"R";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(v) ((v).begin()), ((v).end())
#define s(n) scanf("%d", &n)
#define sc(n) scanf("%c", &n)
#define sl(n) scanf("%lld", &n)
#define sf(n) scanf("%lf", &n)
#define ss(n) scanf("%s", n)
#define INF (int)1e9
#define EPS 1e-9
#define bitcount __builtin_popcount
#define gcd __gcd
#define mod(a, k) (a % k)
#define sz(v) ((int)((v).size()))
#define clr(v, d) memset(v, d, sizeof(v))
#define rep(i, v) for (int i = 0; i < sz(v); ++i)
#define lp(i, n) for (int i = 0; i < (int)(n); ++i)
#define lpi(i, j, n) for (int i = (j); i < (int)(n); ++i)
#define lpd(i, j, n) for (int i = (j); i >= (int)(n); --i)
#define LSOne(S) (S & (-S))
#define repa(v) lpi(i, 0, sz(v)) lpi(j, 0, sz(v[i]))
#define P(x) cout << #x << " = { " << x << " }\n"
#define pb push_back
#define MP make_pair
#define M_PI 3.14159265358979323846
#define fast_IO                       \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define file_IO                       \
    freopen("input.txt", "r", stdin); \
    freopen("output.txt", "w", stdout)
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<vd> vvd;
typedef pair<int, int> pii;
typedef vector<pii> vii;
typedef vector<string> vs;
int dcmp(double x, double y) { return fabs(x - y) <= EPS ? 0 : x < y ? -1 : 1; };
int main()
{

    fast_IO;
    int n;
    cin >> n;
    double ans = 0.0, tmp = 0.0;
    vector<double> in(n);
    for (double &x : in)
    {
        cin >> x;
    }
    sort(in.begin(), in.end());
   // reverse(in.begin(), in.end());
    ans = in[0];
    for (int i = 1; i < n; i++)
    {
        ans = (ans + in[i]) / 2.0;
    }
    cout << ans << '\n';
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using namespace atcoder;
int main() {
  int n, m;
  cin >> n >> m;
  dsu uf(n);
  for (int i = 0; i < m; i++) {
    int t;
    cin >> t;
    int a, b;
    cin >> a >> b;
    if (t) {
      cout << uf.same(a,b) << endl;
    } else {
      uf.merge(a,b);
    }
  }
}


Measured memory_bytes: 3908
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
typedef long long ll;
int dx[] = {1, 0, 0, -1};
int dy[] = {0, 1, -1, 0};
vector<string> s = {};
int H, W;

bool chk(int x, int y){
    if(
        s[std::max(0, x-1)][y] == '#' ||
        s[std::min(H-1, x+1)][y] == '#' ||
        s[x][std::max(0, y-1)] == '#' ||
        s[x][std::min(W-1, y+1)] == '#'
    ) return true;
    return false;
}

int main(int argc, char* argv[]){
    string temp;
    cin >> H >> W;
    rep(i, H){
        cin >> temp;
        s.push_back(temp);
    }
    rep(i, H){
        rep(j, W){
            if(s[i][j] == '#'){
                if(!chk(i, j)){
                    cout << "No" << endl;
                    return 0;
                }
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
//#include <iomanip>
//#include <string>
#include <vector>
#include <algorithm>
//#include <utility>
//#include <set>
#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;
//#define all(v) v.begin(),v.end()
//ll mod = 1000000007 ;
//long double pie = acos(-1) ;
//ll INF = 1000000000000 ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void fix_cout(){cout << fixed << setprecision(20) ;}

int main(){
	ll n ; cin >> n ;
	ll t ; cin >> t ;
	vll a(n) ;
	for(auto &i:a) cin >> i ;
	ll mx = a.at(n-1) ;
	ll sub = -10000000000 ;
	map<ll,ll> m ;
	for(int i=n-2;i>=0;i--){
		m[mx-a.at(i)]++ ;
		sub = max(sub,mx-a.at(i)) ;
		mx = max(mx,a.at(i)) ;
//		cout << sub << " " << mx << endl ;
	}
	cout << m[sub] << endl ;
}


Measured memory_bytes: 7296
def main():
    inp = input()
    data = inp.split(" ")
    data = [int(i) for i in data]
    a = data[0]
    b = data[1]
    c = data[2]
    k = data[3]

    if a > k:
        print(k)
        return

    r = k - a
    score = a

    if b > r:
        print(score)
        return

    r = r - b

    if c > r:
        score -= r
    else:
        score -= c

    print(score)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9200
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <bitset>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <utility>
#include <set>
#include <map>
#include <tuple> 
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <list>
using namespace  std;
typedef pair<long long , long long> P;
typedef long long ll;
typedef long long lint;
#define REP(i, n) for(long long (i)=0; (i)<(n); ++i)
#define FOR(i, a, b) for(long long (i)=(a); (i)<(b); ++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
const long long MOD = static_cast<long long>(1e9) + 7LL;
const long long INF = 1234567891234567890LL;
signed main(){
    ll x, a;
    cin>>x>>a;
    if(x<a) cout <<0 <<endl;
    else cout << 10 <<endl; 
    return 0;
}

Measured memory_bytes: 256
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
//#pragma GCC target("avx,avx2")
//#pragma GCC target("avx2")
//#pragma GCC optimize("O3")

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

# include <ext/pb_ds/assoc_container.hpp>
# include <ext/pb_ds/tree_policy.hpp>

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

#define _USE_MATH_DEFINES_
#define ll long long
#define ld long double
#define Accepted 0
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x.size())
#define every(x) x.begin(),x.end()
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define For(i,x,y)  for (ll i = x; i <= y; i ++) 
#define FOr(i,x,y)  for (ll i = x; i >= y; i --)
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
// ROAD to...                                                                                                                                                                                                                Red

void setIn(string s) { freopen(s.c_str(),"r",stdin); }
void setOut(string s) { freopen(s.c_str(),"w",stdout); }
void setIO(string s = "") {
	// cin.exceptions(cin.failbit); 
	// throws exception when do smth illegal
	// ex. try to read letter into int
	if (sz(s)) { setIn(s+".in"), setOut(s+".out"); } // for USACO
}

const double eps = 0.000001;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9;
const int N = 6e5 + 123;                                          
const int M = 22;
const int pri = 997;
const int Magic = 2101;

const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
mt19937 gen(chrono::steady_clock::now().time_since_epoch().count());
 
int rnd (int l, int r) {
	return uniform_int_distribution<int> (l, r)(gen);
}
 
int n, m, k;
int cnt[N];
string s;
int a[N];
vector < int > g[N];
int u[N];
int ans, res;
int cur;



int main () {
	SpeedForce;
	setIO();
	cin >> n >> k;
	for (int i = 1; i <= n; ++i) cin >> a[i];
	sort (a + 1,  a + n + 1);
	cout << accumulate(a + 1, a + k + 1, 0ll);

	return Accepted;
}

// B...a

Measured memory_bytes: 17736
#include <bits/stdc++.h>
#include <cmath>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define been(ix) (ix).begin(),(ix).end()
using namespace std;
typedef long long ll; 
typedef vector<int> vi;
typedef vector<long long> vl;
const ll INF = 1e18;
#define foreach(ix,i) for(auto& (ix) : (i))
typedef long double ld;
int main(){
  ll n;
  cin>>n;
  ll a[n];
  rep(i,n)cin>>a[i];
  ll sum[n]; sum[0]=a[0];
  rep(i,n){
    sum[i+1]=sum[i]+a[i+1];
    //cout<<sum[i]<<endl;
  }
  ll ans =INF;
  rep(i,n-1){
    ans =min(ans,abs(sum[n-1]-sum[i]-sum[i]));
  }
  cout<<ans<<endl;
  
}

Measured memory_bytes: 3328
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

  public static void main(String[] args) throws IOException {
    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    String readValue;
    while ((readValue = reader.readLine()) != null) {
      int h = Integer.parseInt(readValue.split(" ")[0]);
      int w = Integer.parseInt(readValue.split(" ")[1]);
      if (h == 0 && w == 0)
        break;
      for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
          System.out.print((i == 0 || i == h-1) || (j == 0 || j == w-1) ? "#": ".");
        }
        System.out.println();
      }
      System.out.println();
    }
  }

}

Measured memory_bytes: 24796
import java.util.Scanner;

class Main{
	public static void main(String[] ag) {
		Scanner sc=new Scanner(System.in);
		int H=sc.nextInt();
		int W=sc.nextInt();

		String a="";

		for(int i=0; i<W+2; i++) {
			a=a+"#";
		}
		System.out.println(a);

		for(int i=0; i<H; i++) {
			a="";
			a="#"+sc.next()+"#";
			System.out.println(a);
		}

		a="";

		for(int i=0; i<W+2; i++) {
			a=a+"#";
		}
		System.out.println(a);
	}
}

Measured memory_bytes: 21844
from fractions import gcd
from functools import reduce

def lcm(a,b):
    return a*b//gcd(a,b)

n,m = map(int,input().split())
l = list(map(int,input().split()))

lh = list(map(lambda x:x//2, l))
lcm = reduce(lcm,lh)
res = 0
times = [(lcm//x)%2==1 for x in lh]

if all(times):
    res = ((m // lcm) +1) // 2

print(res)

Measured memory_bytes: 16236
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <tuple>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repd(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define repdm(i, a, b) for (ll i = (ll)(a); i > (ll)(b); i--)

int main()
{

  int N;
  cin >> N;
  int h[N];
  int height = 0;
  int ans = 0;
  rep(i, N)
  {
    cin >> h[i];

    if (height < h[i])
    {
      ans += h[i] - height;
    }
    height = h[i];
  }

  cout << ans;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<queue>
#include<map>

using namespace std;

int dx[4] = { 1,-1,4,-4 };
map<string, int>res;

void solve(void) {
    queue<string>que;
    que.push("01234567");
    while (!que.empty()) {
        string v = que.front();
        que.pop();
        int pos = 0;
        for (int i = 0; i < 8; i++)
            if (v[i] == '0')pos = i;

        for (int i = 0; i < 4; i++) {
            if (0 <= pos + dx[i] && pos + dx[i] < 8 &&
                !(pos == 3 && i == 0) && !(pos == 4 && i == 1)) {
                string u = v;
                swap(u[pos], u[pos + dx[i]]);

                if (res[u] == 0) {
                    que.push(u);
                    res[u] = res[v] + 1;
                }
            }
        }
    }
}

int main(void) {
    int in;
    res["01234567"] = 1;
    solve();
    while (true) {
        string s;
        for (int i = 0; i < 8; i++) {
            if (!(cin >> in))return 0;
            s += in + '0';
        }
        cout << res[s] - 1 << endl;
    }
    return 0;
}


Measured memory_bytes: 5432
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n+1; i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end());

typedef long long ll;

int main(){
  int a,b;
  vector<int> check8(1501);
  vector<int> check10(1501);
  rep1(i,1500){
    check8[i] = i*0.08;
    check10[i] = i*0.10;
  }
  cin >> a >> b;
  int a_min;
  bool mincheck = 0;
  int a_max;
  bool maxcheck = 0;
  rep1(i,1500){
    if(check8[i] == a){
      if(!mincheck)a_min = i;
      mincheck = 1;
    }
    if(check8[i] == a+1){
      if(!maxcheck)a_max = i-1;
      maxcheck = 1;
    }
  }
  int b_min;
  mincheck = 0;
  int b_max;
  maxcheck = 0;
  rep1(i,1500){
    if(check10[i] == b){
      if(!mincheck)b_min = i;
      mincheck = 1;
    }
    if(check10[i] == b+1){
      if(!maxcheck)b_max = i-1;
      maxcheck = 1;
    }
  }
  if(a_max < b_min || b_max < a_min) cout << -1 << endl;
  else cout << max(a_min,b_min) << endl;
}

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

int main() {
  int x,y;
  cin >> x >> y;
  
  if((x == 1 || x == 3 || x == 5 || x == 7 || x == 8 || x == 10 || x == 12) && (y == 1 || y == 3 || y == 5 || y == 7 || y == 8 || y == 10 || y == 12)){
    cout << "Yes" << endl;
  }
  
  else if((x == 4 || x == 6 || x == 9 || x == 11) && (y == 4 || y == 6 || y == 9 || y == 11)){
    cout << "Yes" << endl;
  }
  
  else{
    cout << "No" << endl;
  }
     
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 char c;
 cin >> c;
  
  if(c == 'A') cout << 'T' << endl;
  if(c == 'T') cout << 'A' << endl;
  if(c == 'C') cout << 'G' << endl;
  if(c == 'G') cout << 'C' << endl;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using i64 = long long;

int main() {
    int n;
    std::cin >> n;
    std::vector<std::pair<i64, i64>> v;
    for (int i = 0; i < n; i++) {
        int x, y;
        std::cin >> x >> y;
        v.emplace_back(x, y);
    }

    std::sort(v.begin(), v.end(), [](const auto &lhs, const auto &rhs) {
        return std::atan2(lhs.first, lhs.second) < std::atan2(rhs.first, rhs.second);
    });
    for (int i = 0; i < n; i++) v.push_back(v[i]);

    i64 ret = 0;
    for (int i = 0; i < n; i++) {
        i64 x = 0, y = 0;
        for (int j = 0; j < n; j++) {
            x += v[i + j].first;
            y += v[i + j].second;
            ret = std::max(ret, x * x + y * y);
        }
    }

    std::cout << std::fixed << std::setprecision(12) << std::sqrt(ret) << std::endl;

    return 0;
}


Measured memory_bytes: 256
////ABC 079
#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 FORR(i, m, n) for(int i = (m);i >= (n);i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define ALL(obj) (obj).begin(),(obj).end()

using namespace std;

const int INF = 99999999;
const ll LINF = 9999999999999;

typedef pair<int, int> P;
typedef pair<ll, ll> LP;
int vx[4] = { 0,1,0,-1 };
int vy[4] = { 1,0,-1,0 };

string num;
int n1, n2, n3, n4;
signed main() {

	std::ios::sync_with_stdio(false);
	std::cin.tie(0);

	cin >> num;

	n1 = num[0]-'0';
	n2 = num[1] - '0';
	n3 = num[2] - '0';
	n4 = num[3] - '0';
	
	if (n1 + n2 + n3 + n4 == 7) {
		cout << n1 << "+" << n2 << "+" << n3 << "+" << n4<<"=7";
		return 0;

	}

	if (n1 - n2 + n3 + n4 == 7) {
		cout << n1 << "-" << n2 << "+" << n3 << "+" << n4 << "=7";
		return 0;

	}

	if (n1 + n2 - n3 + n4 == 7) {
		cout << n1 << "+" << n2 << "-" << n3 << "+" << n4 << "=7";
		return 0;

	}

	if (n1 - n2 - n3 + n4 == 7) {
		cout << n1 << "-" << n2 << "-" << n3 << "+" << n4 << "=7";
		return 0;
	}

	if (n1 + n2 + n3 - n4 == 7) {
		cout << n1 << "+" << n2 << "+" << n3 << "-" << n4 << "=7";
		return 0;

	}

	if (n1 - n2 + n3 - n4 == 7) {
		cout << n1 << "-" << n2 << "+" << n3 << "-" << n4 << "=7";
		return 0;

	}

	if (n1 + n2 - n3 - n4 == 7) {
		cout << n1 << "+" << n2 << "-" << n3 << "-" << n4 << "=7";
		return 0;

	}

	if (n1 - n2 - n3 - n4 == 7) {
		cout << n1 << "-" << n2 << "-" << n3 << "-" << n4 << "=7";
		return 0;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
#define MAX 1000000000000000000
int main(){
	int n;
  	cin>>n;
  	long long int a[n];
  	long long int d=1;
  	for(int i=0;i<n;i++){
    	cin>>a[i];
    }
  	sort(a, a+n);
  	for(int i=0;i<n;i++){
    	if(a[i]==0){
          	d=0;
          	break;
        }if(MAX/a[i]<d && a[i]!=0){
        	d=-1;
          	break;
        }
      	d*=a[i];
    }
  	cout<<d<<endl;
  	return 0;
}

Measured memory_bytes: 4424
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        int[] c = new int[n];
        for (int i = 0; i < n; i++)
            c[i] = i;
        
        for (int i = 0; i < q; i++) {
            int com = sc.nextInt(), x = sc.nextInt(), y = sc.nextInt();
            if (com == 0) {
                for (int j = 0; j < n; j++) 
                    if (c[j] == c[x] && j != x) c[j] = c[y];
                c[x] = c[y];
            } else {
                System.out.println(c[x] == c[y] ? 1 : 0);
            }
        }
    }
}



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

using namespace std;
int a[1000000];
int main(){
    a[0]=1;
    int n,k;
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++)
    a[i]=min(a[i-1]+k,a[i-1]*2);
    cout<<a[n];
    return 0;
}

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

using namespace std;

string s;
int a[100005];
int b[100005];
int mx, mn = 2e9;

int main()
{
    cin>>s;
    for(int i = 0; i < s.size(); i++)
    {
        if(s[i] == 'R') mx = i;
        else a[i] = mx;
    }
    for(int i = s.size() - 1; i >= 0; i--)
    {
        if(s[i] == 'L') mn = i;
        else a[i] = mn;
    }
    for(int i = 0; i < s.size(); i++)
    {
        if(s[i] == 'L')
        {
            if(abs(a[i] - i) % 2 == 0) b[a[i]]++;
            else b[a[i] + 1]++;
        }
        else
        {
            if(abs(a[i] - i) % 2 == 0) b[a[i]]++;
            else b[a[i] - 1]++;
        }
    }
    for(int i = 0; i < s.size(); i++)
    {
        printf("%d ", b[i]);
    }
    return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
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;}

int main(){
  ll n;
  cin >> n;
  ll total = 0;
  for (ll i = 1; i < n+1; i++) {
    if (i % 3 == 0 || i % 5 == 0) continue;
    total += i;
  }
  cout << total << endl;
}


Measured memory_bytes: 3612
import copy

n, m = map(int,input().split())
edge = []
graph = [[] for i in range(n+1)]
for i in range(m):
    edge.append(list(map(int,input().split())))
    graph[edge[-1][0]].append(edge[-1][1])
s, g = map(int,input().split())

INF = 10**11
ans = [[INF, INF, INF] for i in range(n+1)]
q = [s]
d = 0
while q:
    nq = []
    d += 1
    p = d % 3
    for cf in q:
        for ct in graph[cf]:
            if ans[ct][p] == INF:
                ans[ct][p] = d
                nq.append(ct)
    q = copy.deepcopy(nq)
if ans[g][0] == INF:
    print(-1)
else:
    print(ans[g][0]//3)

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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << std::setprecision(10);

  int k, a, b; std::cin >> k >> a >> b;
  bool ok = false;
  srep(i, a, b+1) {
    if (i % k == 0) ok = true;
  }
  std::cout << (ok ? "OK" : "NG") << "\n";
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define IFOR(i, m, n) for(int i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
/* テンプレートここまで */

int main() {
  int x, a; cin >> x >> a;
  if(x < a) cout << 0 << endl;
  else cout << 10 << endl;
  
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(void){
    int n,x[110000],y[110000],t[110000];
    cin >> n;
    x[0] = y[0] = t[0] = 0;
    for(int i = 1;i <= n;i++){
        cin >> t[i] >> x[i] >> y[i];
    }
    bool can = true;
    for(int i = 0;i < n;i++){
        int dist = abs(x[i+1]-x[i]) + abs(y[i+1]-y[i]);
        int dt = t[i+1] - t[i];
        if(dist > dt){
            can = false;
            break;
        }
        if(dist %2 != dt %2){
            can = false;
            break;
        }
    }
        if(can){
            cout << "Yes" << endl;
            return 0;
        }else{
            cout << "No" <<endl;
            return 0;
        }
}

Measured memory_bytes: 1408
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
#include<iterator>
#include<list>

using namespace std;

typedef  long long int lint;

#define rep(i, n) for (lint i = 0; i < n; i++)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define mp make_pair
#define enld endl

lint f(string A, string B) {
	lint cnt = 0;
	rep(i, A.size()) {
		if (A[i] != B[i]) {
			cnt++;
		}
	}
	return cnt;
}

int main() {
	string S, T;
	cin >> S >> T;
	lint ans = 100000;
	rep(i, S.size() - T.size() + 1) {
		ans = min(ans, f(T, S.substr(i, T.size())));
	}
	cout << ans << endl;
}

Measured memory_bytes: 3632
def is_solved(nums):
  keys = set(nums)
  for key in keys:
    if nums.count(key) >= 2:
      tmp = nums[:]
      tmp.remove(key)
      tmp.remove(key)
      for key in keys:
        key_count = tmp.count(key)
        if key_count == 4:
          if key + 1 in tmp and key + 2 in tmp:
            for _ in range(4): tmp.remove(key)
            tmp.remove(key + 1)
            tmp.remove(key + 2)
        elif key_count == 3:
          for _ in range(3): tmp.remove(key)

        elif tmp.count(key + 1) >= key_count and tmp.count(key + 2) >= key_count:
          for _ in range(key_count):
            tmp.remove(key)
            tmp.remove(key + 1)
            tmp.remove(key + 2)
      if tmp == []:
        return True
  return False

while True:
  try:
    puzzle = list(map(int, list(input())))
    ans = []
    for i in range(1, 10):
      if puzzle.count(i) <= 3 and is_solved(puzzle + [i]):
        ans.append(i)
    if ans:
      print(*ans)
    else:
      print(0)
  except EOFError:
    break



Measured memory_bytes: 5608
from itertools import combinations

N, A, B, C = map(int, input().split())
S = [input() for _ in range(N)]

def sol():
    now = {'A': A, 'B': B, 'C': C}
    ret = []
    for i, s in enumerate(S):
        u, v = s[0], s[1]
        if now[u] == now[v] == 0:
            return []
        if now[u] > now[v]:
            ret.append(v)
            now[u] -= 1
            now[v] += 1
            continue
        if now[u] < now[v]:
            ret.append(u)
            now[u] += 1
            now[v] -= 1
            continue
        if i == N - 1:
            ret.append(u)
            continue

        nx = S[i + 1]
        if u in nx:
            ret.append(u)
            now[u] += 1
            now[v] -= 1
            continue
        if v in nx:
            ret.append(v)
            now[v] += 1
            now[u] -= 1
            continue

    return ret

ans = sol()
if len(ans) == 0:
    print('No')
    exit()

print('Yes')
print(*ans, sep='\n')


Measured memory_bytes: 18424
def sieve(n):
    p = 0
    prime = [0] * n
    is_prime = [True] * (n + 1)
    is_prime[0], is_prime[1] = False, False
    for i in range(2, n + 1):
        if is_prime[i]:
            prime[p] = i
            p += 1
            for j in range(2 * i, n + 1, i):
                is_prime[j] = False
            
    return prime[:p]

N = int(input())
A = []
for i in sieve(55555):
    if i % 5 == 1:
        A.append(i)
        
print(' '.join(map(str, A[:N])))

Measured memory_bytes: 4084
import sys
import math
from fractions import gcd
# import queue
# from collections import Counter
# from itertools import accumulate
# from functools import reduce

def lcm(a, b):
    return a * b // gcd(a, b)

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

big_prime = 1000000007

"""
# 標準入力取得
## 文字列
 =  sys.stdin.readline().rstrip()
 =  list(sys.stdin.readline().rstrip())

## 数値
 =  int(sys.stdin.readline())
 =  map(int, sys.stdin.readline().split())
 =  list(map(int, sys.stdin.readline().split()))
 =  [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
"""


A, B, C, D, E, F =  map(int, sys.stdin.readline().split())

def bluteforce(limit):
    suger = 0
    for c in range(limit // C + 1):
        for d in range(limit // D + 1):
            tmpsum = c * C + d * D
            if tmpsum > limit:
                break
            suger = max(suger,tmpsum)
    return suger

def greedy(limit):
    suger = 0

    while True:
        if limit >= D:
            limit -= D
            suger += D
            continue
        elif limit >= C:
            limit -= C
            suger += C
            continue
        else:
            return suger

a_m = 0
a_s = 0
dense = 0
for a in range(1, 31):
    for b in range(0, 31):
        water = (100 * a * A) + (100 * b * B)
        if water >= F:
            break
        wei_lim = F - water
        # suger = greedy(min((a * A + b * B) * E, wei_lim))
        suger = bluteforce(min((a * A + b * B) * E, wei_lim))
        mass = water + suger
        d = (suger / mass) * 100
        if d >= dense:
            # print(suger, water, a, b, d)
            dense = d
            a_m = mass
            a_s = suger

print(a_m, a_s)



Measured memory_bytes: 66796
#include<stdio.h>

#define N 100

int main() {
  int n,i,j,u,k,v,G[N][N];

  scanf("%d",&n);

  for(i = 0 ; i < n ; i++) {
    for(j = 0 ; j < n ; j++) {
      G[i][j] = 0;
    }
  }

  for(i = 0 ; i < n ; i++) {
    scanf("%d%d",&u,&k);
    u--;
    for(j = 0 ; j < k ; j++) {
      scanf("%d",&v);
      v--;
      G[u][v] = 1;
    }
  }

  for(i = 0 ; i < n ; i++) {
    for(j = 0 ; j < n ; j++) {
      if(j)
	printf(" ");
      printf("%d",G[i][j]);
    }
    printf("\n");
  }
  return 0;
}



Measured memory_bytes: 2112
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b,m;
	cin>>a>>b>>m;
	int aa[100005] = {0}, bb[100005] = {0}; 
	for(int i = 1; i <= a; i++){
		cin>>aa[i];
	}
	for(int i = 1; i <= b; i++){
		cin>>bb[i];
	}
	int a1,b1,dis;
	int sum = 0x3f3f3f3f;
	for(int i = 1; i <= m; i++){
		cin>>a1>>b1>>dis;
		sum = min(aa[a1] + bb[b1] - dis ,sum);
	}
	sort(aa + 1,aa + 1 + a);
	sort(bb + 1,bb + 1 + b);
	sum = min(aa[1] + bb[1],sum);
	cout<<sum;
	
	return 0;
}

Measured memory_bytes: 1024
//file_name:ABC109_B.cpp
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts()
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
const int MX = 200005;

    // 整数スキャン（複数）
    /*
    int x;
    scanf("%d",&x);
    int y;
    scanf("%d",&y);
    int z;
    scanf("%d",&y);

    // n個の整数のスキャン
    /*
    ll a[n] = {};
    rep(i,n){
        scanf("%lld",&a[i]);
    }
    */

    // 文字列スキャン
    /*
    string s;
    cin >> s;
    */

    // n個の文字列スキャン
    /*
    vector<string> slist;
    rep(i,n){
        string s;
        cin >> s;
        slist.push_back(s);
    }
    */


int main() {
    int n;
    scanf("%d",&n);

    vector<string> slist;
    rep(i,n){
        string s;
        cin >> s;
        slist.push_back(s);
    }

    int flag = 0;

    rep(i,n-1){
        string si = slist[i];
        string sii = slist[i+1];
        if(si[si.size()-1]!=sii[0]){
            flag=1;
        }
        srep(j,i+1,n){
            if(slist[i]==slist[j]){
                flag=1;
            }
        }
    }


    if(flag==0)yn;

    return 0;
}



Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) FOR(i,0,b)
#define INF mugen
#define dump(x) cerr<<#x<<"="<<x<<endl
#define all(a) (a).begin(),(a).end()
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<vii> viii;
typedef pair<int,int> P;
template <class T> void chmin(T & a, T const & b) { if (b < a) a = b; }
template <class T> void chmax(T & a, T const & b) { if (b > a) a = b; }
template <typename T>
string to_string(const T &n){ostringstream stm;stm << n;return stm.str();}
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
using ll = long long;
const ll mod = LLONG_MAX;
#define int long long
int N,M;
int a[112345],ans;
int imos[112345];
int ar[112345];
P query[112345];
signed main(){
    cin>>N>>M;
    rep(i,N)cin>>a[i];


    sort(a,a+N);

    rep(i,M){
        int b,c;
        cin>>b>>c;
        query[i].first=c;
        query[i].second=b;
    }
    sort(query,query+M);
    reverse(query,query+M);
    int idx=0;
    rep(i,N){
        for(int j=i;j<i+query[idx].second;j++){
            ar[j]=query[idx].first;
        }
        i=i+query[idx].second-1;
        // dump(i);
        // dump(idx);
        // dump(query[idx].first);
        idx++;
        if(idx>=M)break;
    }

    // rep(i,N){
    //     dump(ar[i]);
    // }
    


    rep(i,N){
        //dump(a[i]);
        ans+=max(a[i],ar[i]);
    }
    cout<<ans<<endl;
 
}

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

int main(){
  int n,a,b;
  cin >> n >> a >> b;
  int distance;
  distance = b-a;
  if(distance%2 == 1){
    cout << "Borys" << endl;
  }else{
    cout << "Alice" << endl;
  }
}

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

const long long INF = (1LL << 60);

int main(){

  while(true){
    int N, M;
    cin >> N >> M;

    if(N == 0){
      break;
    }

    vector<int> C(M);
    for(int i = 0; i < M; i++){
      cin >> C[i];
    }

    vector<int> x(N);
    for(int i = 0; i < N; i++){
      cin >> x[i];
    }

    vector<vector<long long>> minCost(N + 1, vector<long long>(256, INF));
    minCost[0][128] = 0;
    for(int i = 0; i < N; i++){
      for(int j = 0; j < 256; j++){
	long long cost = minCost[i][j];
	if(cost == INF){
	  continue;
	}
	for(int k = 0; k < M; k++){
	  int nextState = j + C[k];
	  nextState = min(nextState, 255);
	  nextState = max(nextState, 0);
	  int diff = nextState - x[i];
	  long long nextCost = cost + diff * diff;
	  	  
	  minCost[i + 1][nextState] = min(minCost[i + 1][nextState], nextCost);
	}
      }
    }

    long long ans = INF;
    for(int i = 0; i < 256; i++){
      ans = min(ans, minCost[N][i]);
    }

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



Measured memory_bytes: 43848
class Dice:
	
	def __init__(self, faces):
		self.faces = faces
		self.t = faces[0]
		self.s = faces[1]
		self.e = faces[2]
		self.w = faces[3]
		self.n = faces[4]
		self.b = faces[5]

	def roll(self, drct):
		t_ = self.t
		s_ = self.s
		e_ = self.e
		w_ = self.w
		n_ = self.n
		b_ = self.b
		if drct == 'S':
			self.t = n_
			self.s = t_
			self.n = b_
			self.b = s_
		elif drct == 'N':
			self.t = s_
			self.s = b_
			self.n = t_
			self.b = n_
		elif drct == 'E':
			self.t = w_
			self.e = t_
			self.w = b_
			self.b = e_
		elif drct == 'W':
			self.t = e_
			self.e = b_
			self.w = t_
			self.b = w_
		else:
			return
	
	def rotate_right(self):
		s_ = self.s
		w_ = self.w
		n_ = self.n
		e_ = self.e
		self.s = e_
		self.w = s_
		self.n = w_
		self.e = n_
	
	def is_identical(self, other):		
		directions = 'NWWWNN'
		for direction in directions:
			for i in range(4):
				if self.is_matchall(other): return True
				self.rotate_right()
			self.roll(direction)
		return False

	def is_matchall(self, other):
		if self.t != other.t: return False
		if self.s != other.s: return False
		if self.e != other.e: return False
		if self.w != other.w: return False
		if self.n != other.n: return False
		if self.b != other.b: return False
		return True
		
faces1 = list(map(int, input().split()))
faces2 = list(map(int, input().split()))
dice1 = Dice(faces1)
dice2 = Dice(faces2)

if dice1.is_identical(dice2):
	print('Yes')
else:
	print('No')



Measured memory_bytes: 5612
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <climits>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string.h>
#include <iomanip>
#include <ctype.h>

#define ll          long long int
#define ull         unsigned long long int
#define pb          push_back
#define pii         pair<int,int>
#define F         first
#define S          second
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define M_PI        3.14159265358979323846
#define mp          make_pair
#define sz(x)       (int)x.size()
#define hell        1000000007
#define forn(i,a,b)  for(int i=a;i<b;i++)
#define eps 1e9
#define all(a)      (a).begin(),(a).end()
const long long INF = (long long) 10000;


using namespace std;
void solve();

void fastIO() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}

int main(){
   fastIO();
    solve();
}
//void sieve();
ll pw(ll k,ll x);
ll gcd(ll x,ll y);

bool comp(pair<ll,ll> a,pair<ll,ll> b);
bool comp(pair<ll,ll> a,pair<ll,ll> b){
  if(a.F!=b.F)
  return a.F<b.F;
  else
  return a.S<b.S;
}

void solve(){

  int n;
  cin>>n;
  int pos[n+1];
  forn(i,0,n){
    int x;
    cin>>x;
    pos[x]=i+1;
  }
  forn(i,1,n+1)
  cout<<pos[i]<<" ";
}



///Before submit=>
///    *check for integer overflow,array bounds
///    *check for n=1

ll gcd(ll x,ll y){
  if(x==0)
  return y;
  else
  return gcd(y%x,x);
}


ll pw(ll k,ll x){
  if(x==0)
  return 1;
  if(x&1)
  return ((pw(k,x-1)%hell)*k%hell)%hell;
  else
  return ((pw(k,x/2)%hell)*(pw(k,x/2)%hell))%hell;
}

/*void sieve(){

  for(int i=2;i<=1000000;i++){
    if(prime[i]==true){
      for(int j=i*i;j<=1000000;j+=i)
      prime[j]=false;
    }
  }

}*/


Measured memory_bytes: 1280
n = int(input())

anss = set(range(1, 10))

def f(x):
    return x / sum(map(int, str(x)))

for i in range(1, 16):
    x = 10**i - 1
    for j in range(1, 1000):
        k = list(str(j))
        k[1:] = ['9' for _ in range(len(k)-1)]
        k = int(''.join(k))
        #print(k, j)
        if f(j*10**i + x) <= f(k*10**i + x):
            anss.add(j*10**i + x)

ans = sorted(anss)

s = 10**100


ans2 = []
for a in reversed(ans):
    if f(a) <= s:
        ans2.append(a)
        s = f(a)


print("\n".join(map(str, reversed(ans2[-n:]))))

Measured memory_bytes: 3920
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

vector<int> x, y;
vector<pair<int, int>> u;
int n;
int dfs(vector<int> &v, int depth = 1){
    if(n-(depth-1)*2 < 1) {
        int ret = 0;
        for (int i = 0; i < u.size(); ++i) {
            for (int j = i+1; j < u.size(); ++j) {
                if(u[i].first*u[j].second == u[j].first*u[i].second) ret++;
            }
        }
        return ret;
    }

    int ans = 0;
    for (int i = 0; i < n; ++i) {
        if(v[i]) continue;
        for (int j = i+1; j < n; ++j) {
            if(v[j]) continue;
            int tmp1 = v[i], tmp2 = v[j];
            v[i] = v[j] = depth;
            u.emplace_back(x[i]-x[j], y[i]-y[j]);
            ans = max(ans, dfs(v, depth+1));
            u.pop_back();
            v[i] = tmp1; v[j] = tmp2;
        }
        break;
    }
    return ans;
}

int main() {
    cin >> n;
    x.resize(n); y.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> x[i] >> y[i];
    }
    vector<int> v(n);
    cout << dfs(v) << "\n";
    return 0;
}


Measured memory_bytes: 3104