akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
    #include <math.h>
    typedef long long ll;
    #define rep(i,n) for(ll i=0;i<n;++i)
    #define REP(i,k,n) for(ll i=k;i<=n;++i)
    const ll MOD=1e9+7;
     
    int main(){
        ll x;
        std::cin >> x;
        REP(a,-120,120){
            REP(b,-120,120){
                if(pow(a,5)-pow(b,5)==x){
                    std::cout << a << " " << b << std::endl;
                    return 0;
                }
            }
        }
        return 0;
    }

Measured memory_bytes: 3972
#include <iostream>
 
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <random>
#include <chrono>

#include <cstdio>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
 
#define itn int
#define fro for
#define lowbit(x) (x & (-x))
#define Fast freopen("in.txt", "r", stdin)
#define manx maxn
#define ceil(n, p) ((n + p - 1) / p)

#define DBG(x) (void)(cout << "L" << __LINE__ << ": " << #x << " = " << (x) << '\n')

using namespace std;
typedef long long ll;

/*------------------------------------------------------------------------------------*/
template <typename _t>
inline void read(_t &x){
    
    x = 0; _t fu = 1; char ch = getchar();
    while(ch < '0' || ch > '9'){if(ch == '-') fu = - 1; ch = getchar();}
    while(ch >= '0' && ch <= '9'){
        x = (x << 3) + (x << 1) + (ch & 15);
        ch = getchar();
    }
    x *= fu ;
}
/*------------------------------------------------------------------------------------*/
ll gcd(ll x, ll y){return !x? y: gcd(y % x, x);}
void exgcd(ll a, ll b, ll &x, ll &y){
    if(!b){x = 1; y = 0;return;}
    exgcd(b, a % b, y, x);
    y -= a / b * x;
}
/*------------------------------------------------------------------------------------*/
struct Mart{
    int a, b, c, d;
    Mart operator *(Mart &m){
        Mart temp;
        temp.a = a * m.a + b * m.c;
        temp.b = a * m.b + b * m.d;
        temp.c = c * m.a + d * m.c;
        temp.d = c * m.b + d * m.d;
        return temp;
    }
    Mart(){a = b = c = d = 0;}
    Mart(int x[4]){a = x[0]; b = x[1]; c = x[2]; d = x[3];}
    Mart(int u, int v, int w, int x){a = u; b = v; c = w; d = x;}
    int det(){return a * d - b * c;}
};
/*------------------------------------------------------------------------------------*/

ll n, a, b, c, d;

unordered_map<ll, ll> mp;

ll sove(ll n){
    if(n == 0) return 0;
    if(n == 1) return d;
    if(mp.count(n)) return mp[n];
    
    ll res = 1e18, temp;
    if(n < res / d) res = n * d;
    
    temp = n / 2 * 2; res = min(res, abs(n - temp) * d + a + sove(temp / 2));
    temp = (n + 1) / 2 * 2; res = min(res, abs(n - temp) * d + a + sove(temp / 2));
    temp = n / 3 * 3; res = min(res, abs(n - temp)* d + b + sove(temp / 3));
    temp = (n + 2) / 3 * 3; res = min(res, abs(n - temp) * d + b + sove(temp / 3));
    temp = n / 5 * 5; res = min(res, abs(n - temp) * d + c + sove(temp / 5));
    temp = (n + 4) / 5 * 5; res = min(res, abs(n -  temp) * d + c + sove(temp / 5));
    return mp[n] = res;
}

int main(){
//    Fast;
    int t; read(t); while(t--){
        read(n); read(a); read(b); read(c); read(d);
        printf("%lld\n", sove(n));
        mp.clear();
    }
    return 0;
}


Measured memory_bytes: 4116
#include<bits/stdc++.h>
using namespace std;
int n,x,lg,ans;
int main(){
	scanf("%d",&n);
	int now;
	for(int i=1;i<=n;i++){
		scanf("%d",&x);
		lg=log2(x);
		if(x&(x-1)) now>lg?now=lg:++lg;
		if(lg>now) ans+=lg-now,now=lg;
		if(lg<now) now=lg;
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 5020;
int d[N],len,D; ll Ans,f[N][2][2];
inline ll DynamicProgram(int n)
{
    int Lim = n/2; ll res = 0;
    for (int i=0;i<=Lim;i++)
        for (int j=0;j<=1;j++)
            for (int k=0;k<=1;k++)
                f[i][j][k] = 0;
    f[0][0][0] = 1;
    for (int i=0;i<Lim;i++)
        for (int j=0;j<=1;j++)
            for (int k=0;k<=1;k++)
                if ( f[i][j][k] != 0 )
                    for (int l=0;l<=9;l++)
                    {
                        int raw = l + d[i+1] + k , num = raw % 10;
                        int _k = raw / 10 , _j = j * 10 + l - num - d[n-i];
                        if ( _j < 0 || _j > 1 ) continue;
                        if ( i == 0 && ( l == 0 || num == 0 ) ) continue;
                        f[i+1][_j][_k] += f[i][j][k];
                    }
    if ( n % 2 == 1 )
        for (int j=0;j<=1;j++)
            for (int k=0;k<=1;k++)
                // if ( f[Lim][j][k] )
                    for (int i=0;i<=9;i++)
                    {
                        int num = i + d[(n+1)/2] + k;
                        if ( num % 10 == i && num / 10 == j )
                            res += f[Lim][j][k];
                    }
    else
    for (int j=0;j<=1;j++) res += f[Lim][j][j];
    return res;
}
int main(void)
{
    scanf("%d",&D);
    while ( D ) d[++len] = D%10 , D /= 10;
    for (int i=len;i<=2*len;i++)
        Ans += DynamicProgram(i);
    return printf("%lld\n",Ans) , 0;
}


Measured memory_bytes: 256
<?php
fscanf(STDIN, "%s", $S);
switch ($S) {
    case 'Sunny':
        echo('Cloudy').PHP_EOL;
        break;
    case 'Cloudy':
        echo('Rainy').PHP_EOL;
        break;
    case 'Rainy':
        echo('Sunny');
        break;
}

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

int main(){
  int n,x[302][302]={},y[302][302]={};
  cin>>n;
  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++)cin>>y[i][j],x[i][j]=y[i][j];
  
  int ans=max(y[0][n-1],y[n-1][0]);
  for(int i=0;i<n;i++)
    for(int j=n-2;j>=0;j--) {
      x[i][j]+=x[i][j+1];
      y[j][i]+=y[j+1][i];
    }

  
  int sum[302][302],K[2][302][302]={},t=0,f=1;
  while(f){
    t++,f=0;
    for(int i=0;i<n;i++) //yoko
      for(int j=i+1;j<n;j++) {//yoko
	int a=K[t%2][i][j],&b=K[(t+1)%2][i][j];
	b=a;
	sum[i][j]=-10000000;

	for(int k=a+1;k<n;k++) { //tate
	  int X=(x[a][i]-x[a][j+1])+(x[k][i]-x[k][j+1]);
	  int Y=(y[a+1][i]-y[k][i])+(y[a+1][j]-y[k][j]);
	  if(sum[i][j]<=X+Y)sum[i][j]=X+Y,b=k;
	}
	
	if(b!=n-1)f=1;
	ans=max(ans,sum[i][j]);
	for(int k=a+1;k<b;k++){//tate
	  sum[i][j]+=(x[k][i+1]-x[k][j])-(x[k-1][i]-x[k-1][j+1]);
	  ans=max(ans,sum[i][j]);
	}
      }
  }
  cout <<ans<<endl;
	  
  return 0; 
}

Measured memory_bytes: 2948
H, N  = map(int, input().split())
# hitpoint H
# waza N
As = [] # damage
Bs = [] # MP comsumptions
for i in range(N):
    a,b = map(int, input().split())
    As.append(a)
    Bs.append(b)

INF = 10**10
M = 21000
dp = [INF]*M
dp[0] = 0
for i,(a,b) in enumerate(zip(As,Bs)):
    # update
    for j in range(H):
        # 何回でも使っていい⇛dp[i+1][j]+b
        dp[j+a] = min(dp[j+a], dp[j]+b) 
print(min(dp[H:]))



Measured memory_bytes: 41452
n, m = map(int, input().split())
factors = [1, m]
sqrt = round(m ** 0.5 + 0.5)
for i in range(2, sqrt + 1):
    if not m % i:
        factors.append(i)
        factors.append(m // i)
factors = sorted(factors)
def search(l):
    for i in l:
        if i >= n:
            return m // i
print(search(factors))

Measured memory_bytes: 3060
import java.util.Scanner

object Main {
  def main(args: Array[String]) {
    val result = solve(new Scanner(System.in))
    if (result.length > 0) println(result)
  }

  def solve(in: String): String = solve(new Scanner(in))

  def solve(sc: Scanner): String = {
    val A = sc.nextInt
    val B = sc.nextInt
    val C = sc.nextInt

    Array(B / A, C).min.toString
  }
}


Measured memory_bytes: 25896
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  int n;
  string s;
  cin >> n >> s;
  vi w(n + 1, 0), e(n + 2, 0);
  rep(i, n) {
    w[i + 1] = w[i] + int(s[i] == 'W');
    e[n - i] = e[n + 1 - i] + int(s[n - 1 - i] == 'E');
  }
  int ans = 1e9;
  rep(i, n) ans = min(ans, w[i + 1] + e[i + 1] - 1);
  cout << ans << endl;
}

Measured memory_bytes: 3076
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

n=int(input())
print(10-n//200)

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

using namespace std;

int main()
{
  int N, M;
  cin >> N >> M;
  vector<int> edge[N], incnt(N);
  vector<bool> root(N, true);
  for (int i = 0; i < N + M - 1; i++)
  {
    int A, B;
    cin >> A >> B;
    edge[A - 1].push_back(B - 1);
    root[B - 1] = false;
    incnt[B - 1]++;
  }
  vector<long long> far(N, -1);
  vector<int> ans(N);
  priority_queue<pair<long long, int>, vector<pair<long long, int>>, greater<pair<long long, int>>> que;
  for (int i = 0; i < N; i++)
    if (root[i])
    {
      que.push({0, i});
      ans[i] = 0;
      far[i] = 0;
      break;
    }
  while (que.size())
  {
    pair<long long, int> p = que.top();
    que.pop();
    for (int t : edge[p.second])
    {
      incnt[t]--;
      if (incnt[t] == 0)
      {
        far[t] = far[p.second] + 1;
        que.push({far[t], t});
        ans[t] = p.second + 1;
      }
    }
  }
  for (int t : ans)
    cout << t << endl;

  return 0;
}


Measured memory_bytes: 7808
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pi M_PI
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

int d[7368792];
void Main() {
  int n,m;
  while(cin >> n >> m && n) {
    mem(d);
    REP(i,n,7368792) {
      if(!d[i]) {
        if(m) {
          m--;
          for(int j=i*2; j<=7368791; j+=i) d[j]=1;
        } else {
          pr(i);
          break;
        }
      }
    }
  }
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


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

struct Edge{int from,to,cost;};
using Graph=vector<vector<Edge>>;
int main(){
    int n,m;
    cin>>n>>m;
    Graph g(n);
    vector<bitset<100>> bit(n);
    for(int i=0;i<m;i++){
        int u,v,f;
        cin>>u>>v>>f;
        u--,v--;
        g[u].push_back({u,v,f});
        g[v].push_back({v,u,f});
        bit[u][v]=true;
        bit[v][u]=true;
    }
    bitset<100> s;
    function<int(int,bitset<100>)> dfs=[&](int idx,bitset<100> used){
        if(idx==n){
            int res=0;
            if(s.count()<=1) return 0;
            for(int i=0;i<n;i++){
                if(s[i]){
                    int sc=1000000;
                    for(auto &e:g[i]){
                        if(s[e.to]){
                            sc=min(sc,e.cost);
                        }
                    }
                    res+=sc;
                }
            }
            return res;
        }
        int res=dfs(idx+1,used);
        if(used[idx]) return res;
        s[idx]=true;
        res=max(res,dfs(idx+1,(used|(~bit[idx])).set(idx,true)));
        s[idx]=false;
        return res;
    };
    cout<<dfs(0,bitset<100>())<<endl;
    return 0;
}


Measured memory_bytes: 3176
package main

import (
	"fmt"
	"strings"
)

func main() {
	var s, t string
	fmt.Scanf("%s", &s)
	fmt.Scanf("%s", &t)
	if len(t) == len(s)+1 && strings.HasPrefix(t, s) {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


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

#define int             long long
#define FOR( i, m, n )  for( int (i) = (m); (i) < (n); (i)++ )
#define REP( i, n )     FOR( i, 0, n )
#define REPR( i, m )    for( int (i) = (m); (i) >= 0; (i)-- )
#define REPONE( i, n )  FOR( i, 1, n + 1 )
#define ALL( a )        (a).begin(), (a).end()
#define MP              make_pair

using namespace std;
using P = pair<int, int>;

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

const int INF = 1e18;
const int MOD = 1e9 + 7;

int dp[100101];

signed main(){
    int N, K; cin >> N >> K;
    vector<int> h( N );
    REP( i, N ) cin >> h[i];

    fill( dp, dp + 100001, INF );
    dp[0] = 0;

    REP( i, N ){
        REPONE( j, K ){
            chmin( dp[i + j], dp[i] + abs( h[i] - h[i + j] ) );
        }
    }

    cout << dp[N - 1] << endl;
}


Measured memory_bytes: 1792
// the biggest power of 2 that doesn't exceed X
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  long long n;
  cin >> n;
  // 0000000000001101 = 13
  // __builtin_ctzll(n);
  long long b = 1LL << (63 - __builtin_clzll(n));
  // while(2 * b <= n) b *= 2;
  cout << 2 * b - 1 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll N, A, B;
  cin >> N >> A >> B;
  ll ans = 0;
  if(A==0) {
    cout << 0;
    return 0;
  }
  ll a, b;
  a = N / (A+B);
  b = (N - a * (A+B));
  if(b < A) ans = a * A + (N - a * (A+B));
  if(b >= A) ans = (a+1) * A; 
  cout << ans;
}


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

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

    while (in.hasNext()) {
      int N = in.nextInt();
      int x = in.nextInt();
      int[] a = new int[N];

      long sum = 0;
      for(int i = 0; i < a.length; ++i) {
        a[i] = in.nextInt();
        sum += a[i];
      }

      if (sum < x) {
        System.out.println(N - 1);
      } else if (sum == x) {
        System.out.println(N);
      } else {
        Arrays.sort(a);
        
        int count = N;
        while ((sum -= a[--count]) > x){
        }
        
        System.out.println(count);
      }
    }
  }
}

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

int main() {
  int n;
  string s;
  cin >> n >> s;
  string abc="ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ";
  for (int i=0; i<s.size(); i++){
    for (int j=0; j<26; j++){
      if (s[i]==abc[j]){
        cout << abc[j+n];
      }
    }
  }
  cout << endl;
}

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

using namespace std;

bool solve(vector<string> &w) {
    //しりとりがつづくか
    for (int i = 0; i < w.size() - 1; ++i) {
        if (w[i].back() != w[i + 1].front()) {
            return false;
        }
    }

    //ダブリがないか
    set<string> st(w.begin(), w.end());
    sort(w.begin(), w.end());
    return st.size() == w.size();
}

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

    vector<string> vt(n);
    for (int i = 0; i < n; ++i) {
        cin >> vt[i];
    }

    if (solve(vt)) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


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

using namespace std;
using namespace __gnu_pbds; 
#define     mod             1e9+7
#define     MOD             998244353
#define     ll              long long
#define     mp              make_pair
#define     F               first
#define     S               second
#define     t()             int test;cin>>test;while(test--)
#define     ii              pair<int,int>
#define     que_max         priority_queue <int>
#define     IOS             ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define     endl            "\n"
typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
        //use cerr if u want to display at the bottom
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif






 
int main()
 
{  
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

    IOS;
    
   ll n;
   cin>>n;
   cout<<(ll)ceil((double)n/1000) * 1000 - n<<endl;
    
}

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

using namespace std;

int main() {
    int n, ans = 0;
    scanf("%d", &n);
    for(int i = 1; i <= n; i++) {
        int dig = 0, x = i;
        while(x) {
            dig++;
            x /= 10;
        }
        ans += (dig & 1);
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 256
from collections import Counter
n,m = map(int, input().split())
a = list(map(int, input().split()))
amax = max(a)
c = [0]*(amax+1)
b = [a[i]%m for i in range(n)]
rem = [0]*m
for i in range(n):
    rem[b[i]] += 1
    c[a[i]] += 1
ans = 0
for i in range(m//2+1):
    if i == 0 or i*2 == m:
        ans += rem[i]//2
        rem[i] -= rem[i]//2*2
        continue
    less = min(rem[i],rem[m-i])
    ans += less
    rem[i] -= less
    rem[m-i] -= less
for j in range(amax//m+1):
    for i in range(m):
        if m*j+i<=amax:
            if rem[i] >= c[m*j+i]:
                ans += c[m*j+i]//2
                rem[i] -= c[m*j+i]//2*2
            else:
                ans += rem[i]//2
                rem[i] -= rem[i]//2*2
print(ans)

Measured memory_bytes: 14220
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ll long long
#define watch(x) cout << (#x) << " is " << (x) << endl

typedef vector<int> vi;
typedef vector< vi > vvi;
typedef pair< int,int > ii;
typedef pair< double,double> dd;
#define pb push_back
#define eb emplace_back
#define sz(a) (int)a.size()
#define all(c) c.begin(),c.end()
#define FOR(i,a,b) for(i=a; i<b; i++)
#define FORR(i,a,b) for(i=a;i>=b;i--)
#define REP(i,n) FOR(i,0,n)
#define x first
#define y second
#define mp make_pair

const int INF = 1000000007;
const long long INFLL = (ll)INF * (ll)INF;

ll gcd_god(int n)
{
	ll sum=0;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			for(int k=1;k<=n;k++)
			{
				sum+=__gcd(i,__gcd(j,k));
			}
		}
	}
	return sum;
}
int32_t main()
{
	IOS;
	int k;
	cin>>k;
	cout<<gcd_god(k);
	return 0;
}


Measured memory_bytes: 3664
#include <bits/stdc++.h>
using namespace std;
#define pb                push_back
#define ppb               pop_back
#define pf                push_front
#define ppf               pop_front
#define all(x)            (x).begin(),(x).end()
#define sz(x)             (int)((x).size())
#define int               long long
#define M                 1000000007
#define MM                998244353
#define fr                first
#define sc                second
#define pii               pair<int,int>
#define rep(i,a,b)        for(int i=a;i<b;i++)
#define mem1(a)           memset(a,-1,sizeof(a))
#define mem0(a)           memset(a,0,sizeof(a))
#define ppc               __builtin_popcount

template<typename T1,typename T2>
std::istream& operator>>(std::istream& in,pair<T1,T2> &a)
{
	in>>a.fr>>a.sc;
	return in;
}
template<typename T1,typename T2>
std::ostream& operator<<(std::ostream& out,pair<T1,T2> &a)
{
	out<<a.fr<<" "<<a.sc;
	return out;
}

int a[100005][3];
int dp[100005][3];

void solve(){
	int n;
	cin>>n;
	rep(i,0,n){
		cin>>a[i][0]>>a[i][1]>>a[i][2];
	}
	dp[0][0]=a[0][0];
	dp[0][1]=a[0][1];
	dp[0][2]=a[0][2];
	rep(i,1,n){
		dp[i][0]=a[i][0]+max(dp[i-1][1],dp[i-1][2]);
		dp[i][1]=a[i][1]+max(dp[i-1][0],dp[i-1][2]);
		dp[i][2]=a[i][2]+max(dp[i-1][0],dp[i-1][1]);
	}
	int ans=max(dp[n-1][0],dp[n-1][1]);
	ans=max(ans,dp[n-1][2]);
	cout<<ans;
}
signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	#ifdef SEIVE
		seive();
	#endif
	#ifdef NCR
		init();
	#endif
	#ifdef DSU
		cleardsu(MAXDSUSIZE);
	#endif
	int t=1;
	//cin>>t;
	while(t--) solve();
	return 0;
}


Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std ;
#define int long long int
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<vi> vvi;
#define pb push_back
#define all(c) (c).begin(), (c).end()

void startup()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
}

int32_t main()
{
    startup();

    int n;
    cin>>n;
    vi v(n,0);
    for(int i=0 ; i<n ; ++i)
    	cin>>v[i];

    vi dp(n,0);
    dp[0]=0;
    dp[1]=abs(v[1]-v[0]);
    for(int i=2 ; i<n ; ++i)
    {
    	dp[i]=min(dp[i-1]+abs(v[i]-v[i-1]) , dp[i-2]+abs(v[i]-v[i-2]));
    }
    cout<<dp[n-1];
    
    
    return 0;
}

Measured memory_bytes: 4676
#include <stdio.h>



int main(){
  int W,H,j=0;
  int n = 0;
  int d[10000][2];
  while(j == 0){ 
    scanf("%d %d",&H,&W);
    if(W == 0 && H == 0){ 
      j = 1;
    }else{
      d[n][0] = H;
      d[n][1] = W;
      n++;
    }   
  }
  for(int i = 0;i < n;i++){ //???????????????????????°??????
    for(int q = 0;q < d[i][0];q++){
      for(j = 0;j < d[i][1];j++){
        printf("#");
      }   
      printf("\n");
    }   
    printf("\n");
  }
}

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

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

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

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

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

ll modpow(ll a, ll n) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % MOD;
    (a *= a) %= MOD;
    n >>= 1;
  }
  return res;
}

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  
  ll n; cin>>n;
  vll a(n);
  rep(i,n) cin>>a[i];
  
  vll invsum(n+1);
  rep(i,n){
    invsum[i+1]=(invsum[i]+modpow(i+1,MOD-2))%MOD;
  }
  
  ll ans=0;
  rep(i,n){
    (ans+=a[i]*(invsum[i+1]+invsum[n-i]-1)%MOD)%=MOD;
  }
  ll fact=1;
  reps(i,n){
    (fact*=i)%=MOD;
  }
  (ans*=fact)%=MOD;
  cout<<ans<<endl;
  
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define ENDL '\n'
#define deb(a) cout << #a << ": " << ENDL
#define all(a) begin(a), end(a)
#define sz(a) (int)(a.size())
#define fore(i, a, b) for(int i(a), ThkMk(b); i < ThkMk; ++i)
#define _ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;

typedef long long lli;
typedef long double ld;
typedef pair<lli, lli> ii;
typedef vector<lli> vi;

int main()
{   _
    string s; cin >> s;
    int a = s[0] == 'R';
    int b = s[1] == 'R';
    int c = s[2] == 'R';
    if(a + b + c == 3) {
        cout << 3 << ENDL;
        return 0;
    }
    if(a + b + c == 0) {
        cout << 0 << ENDL;
        return 0;
    }
    if(a + b + c == 1) {
        cout << 1 << ENDL;
        return 0;
    }
    cout << (b == 1 ? "2" : "1") << ENDL;
    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define __ ios_base::sync_with_stdio(0);cin.tie(0);
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(),x.end()
#define forn(i,a,n) for(int i=a; i < n; i++)
typedef long long int lli;
typedef long double Double;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
const int mod = 1e9+7;
const int maxn = 1000005;
const lli inf = 1e18;

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

	vi a(n),b(n);
	forn(i,0,n) cin >> a[i];
	forn(i,0,n) cin >> b[i];

	reverse(all(b));

	int l = 0,r=-1;
	int c = -1;
	forn(i,0,n){
		if(a[i] == b[i]){
			l = i;
			c = a[i];
			break;
		}
	}

	for(int i=n-1; i >=0; i--){
		if(a[i] == b[i]){
			r = i;
			break;
		}
	}

	forn(i,0,n){
		if(a[i] != c && b[i] != c && l <= r){
			swap(b[i],b[l]);
			l++;
		}
	}

	if(l <= r){
		cout << "No\n";
		return 0;
	}

	cout << "Yes\n";
	for(int x : b){
		cout << x << " ";
	}
	cout << endl;
	return 0;
}



Measured memory_bytes: 4784
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto& (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define sar(a,n) cout<<#a<<":";rep(pachico,n)cout<<" "<<a[pachico];cout<<endl
#define svec(v) cout<<#v<<":";rep(pachico,v.size())cout<<" "<<v[pachico];cout<<endl
#define svecp(v) cout<<#v<<":";each(pachico,v)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl
#define sset(s) cout<<#s<<":";each(pachico,s)cout<<" "<<pachico;cout<<endl
#define smap(m) cout<<#m<<":";each(pachico,m)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 100005;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vi a(n);
    rep(i,n){
        cin >> a[i];
    }
    int pr = 0;
    ll ans = 0;
    rrep(i,n){
        if(a[i] > i){
            cout << "-1\n";
            return 0;
        }
        if(a[i] >= pr){
            ans += a[i];
        }else if(a[i] < pr-1){
            cout << "-1\n";
            return 0;
        }
        pr = a[i];
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 1024
abc = list(map(int, input().split()))
abc.sort()
a, b, c = abc[0], abc[1], abc[2]
if a % 2 == b % 2:
    ans = (2 * c - a - b) // 2
else:
    ans = (2 * c + 1 - a - b) // 2 + 1
print(ans)


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

namespace abc127B
{
    class Program
    {
        static void Main(string[] args)
        {
            string r_D_x = Console.ReadLine();
            string[] c = r_D_x.Split(' ');
            int r = Convert.ToInt32(c[0]);
            int D = Convert.ToInt32(c[1]);
            int x = Convert.ToInt32(c[2]);
            int temp = x;

            for (int i =1; i<= 10;i++)
            {
                temp = r * temp - D;
                Console.WriteLine(Convert.ToString(temp));
            }
            Console.ReadKey();
        }
    }
}


Measured memory_bytes: 13268
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
import copy
import bisect

if __name__  == "__main__":
    n = int(input())
    nowX = 0
    nowY = 0
    nowT = 0
    for i in range(n):
        t,x,y = map(int,input().split())
        dt = t - nowT
        dx = abs(x - nowX)
        dy = abs(y - nowY)
        if dt%2 == 1:
            if (dx + dy)%2 == 1 and (dx + dy)<=dt:
                flag = 1
            else:
                print("No")
                sys.exit()
        else:
            if (dx + dy)%2 == 0 and (dx + dy)<=dt:
                flag = 1
            else:
                print("No")
                sys.exit()
        nowT = t
        nowX = x
        nowY = y
    print("Yes")


Measured memory_bytes: 3444
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
int main(){
    int n, m, c;
    int ans=0, cnt=0;
    cin >> n >> m >> c;
    vector<int> b(m);
    rep(i, m) cin >> b[i];
    vector<vector<int>> a(n, vector<int>(m));

    for(int i=0; i<n;i++){
        for(int j=0; j<m; j++){
            cin >> a[i][j];
        }
    }

    for(int i=0; i<n; i++){
        ans=0;
        for(int j=0; j<m; j++){
            ans += (a[i][j] * b[j]);
        }
        ans += c;
        if(ans > 0) cnt++;
    }

    cout << cnt << endl;

}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	int N;
	string s;
	
	int a = 0,b = 0;
	
	cin >> N;
	cin >> s;
	
	for (int i = 0; i < N; i++){
		if (s.at(i) == 'R'){
			a++;
		}else if (s.at(i) == 'B'){
			b++;
		}
	
	}
	if (a > b){
			cout << "Yes" <<endl;
		}else{
			cout << "No" << endl;
		}
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  for(int i = 0;i < N;i++) {
    cin >> vec.at(i);
  }
  int answer = 0;
  for(int i = 0;i < N;i++) {
    for(int j = 0;j < 1000;j++) {
      if(vec.at(i) % 2 == 0) {
        vec.at(i) = vec.at(i) / 2;
        answer++;
      }
      else {
        break;
      }
    }
  }
  cout << answer << endl;
}

Measured memory_bytes: 256
MOD = 10**9 + 7
class ModInt:
    def __init__(self, x):
        if isinstance(x, str):
            x = int(x)
        self.x = x % MOD

    def __str__(self):
        return str(self.x)

    __repr__ = __str__

    def __add__(self, other):
        return (
            ModInt(self.x + other.x) if isinstance(other, ModInt) else
            ModInt(self.x + other)
        )

    def __sub__(self, other):
        return (
            ModInt(self.x - other.x) if isinstance(other, ModInt) else
            ModInt(self.x - other)
        )

    def __mul__(self, other):
        return (
            ModInt(self.x * other.x) if isinstance(other, ModInt) else
            ModInt(self.x * other)
        )

    def __truediv__(self, other):
        return (
            ModInt(
                self.x * pow(other.x, MOD - 2, MOD)
            ) if isinstance(other, ModInt) else
            ModInt(self.x * pow(other, MOD - 2, MOD))
        )

    def __pow__(self, other):
        return (
            ModInt(pow(self.x, other.x, MOD)) if isinstance(other, ModInt) else
            ModInt(pow(self.x, other, MOD))
        )

    __radd__ = __add__

    def __rsub__(self, other):
        return (
            ModInt(other.x - self.x) if isinstance(other, ModInt) else
            ModInt(other - self.x)
        )

    __rmul__ = __mul__

    def __rtruediv__(self, other):
        return (
            ModInt(
                other.x * pow(self.x, MOD - 2, MOD)
            ) if isinstance(other, ModInt) else
            ModInt(other * pow(self.x, MOD - 2, MOD))
        )

    def __rpow__(self, other):
        return (
            ModInt(pow(other.x, self.x, MOD)) if isinstance(other, ModInt) else
            ModInt(pow(other, self.x, MOD))
        )

def calc(N, A, max_k):
    ret = ModInt(0)
    for k in range(max_k):
        count = 0
        for i in A:
            if i & (1 << k):
                count += 1
        ret += 2 ** k * count * (N - count)
    return ret

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

print(calc(N, A, max_k))

Measured memory_bytes: 125872
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define double long double
#define pii pair<int, int>
#define FOR(i, a, b) for(int i = a; i < (int)(b); ++i)
#define all(x) x.begin(), x.end()
#define deb(x) cout << (#x) << " is " << (x) << endl;
#define len(s) s.length()
const int mod = 1000 * 1000 * 1000 + 7;
using namespace std;

int32_t main() {
    int n;
    cin >> n;
    int a[n + 1], p[n + 1];
    p[0] = 0;
    FOR(i, 1, n + 1) {
        cin >> a[i];
        p[i] = p[i - 1] + a[i];
    }
    int d[n + 1][n + 1];
    memset(d, 0, (n + 1) * (n + 1) * sizeof(int));
    FOR(len, 2, n + 1) {
        FOR(i, 1, n - len + 2) {
            d[i][i + len - 1] = INT64_MAX;
            FOR(j, i, i + len - 1) {
                int k = d[i][j] + d[j + 1][i + len - 1];
                if (k < d[i][i + len - 1]) {
                    d[i][i + len - 1] = k;
                }
            }
            d[i][i + len - 1] += p[i + len - 1] - p[i - 1];
        }
    }
    cout << d[1][n];
    return 0;
}

Measured memory_bytes: 4856
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	#ifndef ONLINE_JUDGE
    	freopen("input.txt", "r", stdin);
    	freopen("output.txt", "w", stdout);
	#endif

    int n,x,t,a=1;
    cin>>n>>x>>t;
    while(n>x){
    	n=n-x;
    	a++;
    }
    cout<<a*t;

	return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#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)
using namespace std;
typedef long long ll;
typedef vector<int> VI;
int main() {
  int N;
  cin >> N;
  vector<string> vs;
  vs.push_back("a");
  rep(i, N - 1) {
    vector<string> vs2;
    for (auto s : vs) {
      char last = 'a';
      for (auto c : s) {
        last = max(c, last);
      }
      for (char si = 'a'; si < last + 2; si++) {
        vs2.push_back(s + si);
      }
    }
    swap(vs, vs2);
  }
  for (auto s : vs) {
    cout << s << endl;
  }
  return 0;
}


Measured memory_bytes: 10956
#include <bits/stdc++.h>
using namespace std;
#define li          long
#define ll          long long
#define ull         unsigned long long
#define ff          first
#define ss          second
#define pii         pair<int,int>
#define pli         pair<li,li>
#define pll         pair<ll,ll>
#define pb          push_back
#define fo(i,k,n)   for(int i = k;i<n; i++)
#define ro(i,k,n)   for(int i = k; i>=n; i--)
#define tc          int t;cin>>t;while(t--)
#define all(v)      v.begin(),v.end()
#define inf         INT_MAX
#define ninf        INT_MIN
#define v(x)        vector<x>
#define int         long long
#define ar(x,y)     array<x,y>
#define p(x,y)      pair<x,y>
const ll mod1 = 99844353;
const ll mod2 = 1e9+7;
/* template <class T>
using oset = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>; */

template<typename T>
T gcd(T a,T b){
    return b ? gcd(b, a%b) : a;
}

void fastio()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

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

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

class Template {
    int* readArray(int n){
        int *res = new int[n];
        for(int i = 0; i<n; i++){
            cin >> res[i];
        }
        return res;
    }
    void destroy(int *x){
        delete[] x;
    }
    v(int) readVector(int n){
        v(int) res(n);
        for(int i = 0; i<n; i++){
            cin >> res[i];
        }
        return res;
    }
    public:
    void solveOne(istream &in, ostream &out) {
        int n;
        in >> n;
        int mod = 1e9+7;
        int p1 = power(10,n,mod);
        int p2 = (p1 + power(8,n,mod))%mod;
        int p3 = ((p2 - (2*power(9,n,mod))%mod) + mod)%mod;
        out << p3 << "\n";
    }
    
    void solve(istream &in, ostream &out) {
        int nt = 1;
        //in >> nt;
        for (int it = 0; it < nt; ++it) {
            solveOne(in, out);
        }
    }
};
 
signed main() {
  fastio();
  Template solver;
  istream& in(cin);
  ostream& out(cout);
  solver.solve(in, out);
  return 0;
}

Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
const int maxn = 1e5+7,mod = 1e9+7;
char s[333][333];
int n,ans;
bool jude(int k){
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
            if(s[(i+k)%n][j] != s[(j+k)%n][i])
                return false;
    return true;
}
int main(){
    scanf("%d",&n);
    for(int i=0;i<n;i++)scanf("%s",s[i]);
    for(int k=0;k<n;k++){
        if(jude(k))
            ans += n;
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 384
import sys
from collections import Counter

N = int(sys.stdin.readline().strip())
A = list(map(int, sys.stdin.readline().strip().split()))

counter = Counter(A)
if N % 2 == 1:
    if 0 not in counter or counter[0] != 1:
        print(0)
        sys.exit()
       
if len(counter) != (N+1) // 2:
    print(0)
    sys.exit()

for (pos, count) in counter.items():
    if N % 2 == 1 and pos % 2 == 1:
        print(0)
        sys.exit()
    elif N % 2 == 0 and pos % 2 == 0:
        print(0)
        sys.exit()
        
    if pos != 0 and count != 2:
        print(0)
        sys.exit()

print((2**(N//2)) % (10**9 + 7))

Measured memory_bytes: 55404
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<queue>
#include<stack>
#include<cmath>	

using namespace std;

int main() {
	int A, B, T;
	cin >> A >> B >> T;
	int n = T / A;
	cout << n * B << endl;
	return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main() {
    int N, K, X, Y;
    cin >> N;
    cin >> K;
    cin >> X;
    cin >> Y;
    int ans = 0;
    if (N <= K){
        cout << X*N << endl;
        return 0;
    }
    ans += X*K;
    ans += Y*(N-K);
    cout << ans << endl;
}

Measured memory_bytes: 3564
#include<stdio.h>
int main(void)
{
	int e[4],i,j,box;
	for(i=0;i<4;i++){
	scanf("%d",&e[i]);
	}
	for(i=0;i<3;i++){
		for(j=i+1;j<4;j++){
			if(e[i]>e[j]){
				box=e[i];
				e[i]=e[j];
				e[j]=box;
			}
		}
	}
	if(e[0]==e[1]&&e[2]==e[3]){
		printf("yes\n");
	}
	else{
		printf("no\n");
	}
	return 0;
}



Measured memory_bytes: 2104
"""
ALDS1_9_B
最大ヒープを実装する
"""
import copy
import math

def get_parent(index):
    parent_index = math.floor((index-1)/2)
    return parent_index
    
def get_left(index):
    left_index = 2*index+1
    return left_index

def get_right(index):
    right_index = 2*index+2
    return right_index

def maxHeapify(A, i): #交換された時再帰関数で回す
    l = get_left(i)
    r = get_right(i)
    if A[l] and A[r]: #左も右も存在する時
        if l < n and A[l] > A[i]: #不等号は<（なぜなら，インデックスで与えてあるから
            largest = l
        else:
            largest = i
            
        if r < n and A[largest] < A[r]:
            largest = r
        
        if largest == i: #結局親が一番大きい時
            pass
        else:
            A[largest], A[i] = A[i], A[largest]
            maxHeapify(A, largest)
    
    elif not A[r]: #右の子がない時（左の子がない時は存在しない
        if l < n and A[l] > A[i]:
            A[l], A[i] = A[i], A[l]
            maxHeapify(A, l)
    
    else:
        pass



n = int(input())
heap_list = list(map(int, input().split()))+[None]*(n+1)

roop = math.floor(n/2)-1
for i in range(roop, -1, -1):
    maxHeapify(heap_list, i)


for i in range(n):
    k = heap_list[i]
    print(' '+str(k), end='')
print()



Measured memory_bytes: 64180
from itertools import permutations

def solve():
    N = int(input())
    A = []
    for _ in range(N):
        a, b = list(map(int, input().split()))
        A.append([a, b])
    l = list(permutations(A))
    s = 0
    for t in l:
        for i in range(N-1):
            a, b = t[i]
            c, d = t[i+1]
            s = s + ((a-c)**2 + (b-d)**2) ** 0.5
    return s / len(l)

print(solve())

Measured memory_bytes: 8052
#!/usr/bin/env python3

from collections import deque

def main():
    n = int(input())
    n_prev = [[2 for j in range(n)] for i in range(n)]
    post_matches = [[[] for j in range(n)] for i in range(n)]
    q = deque()
    for i in range(n):
        ai = list(map(int, input().split()))
        for j in range(n - 1):
            x = min(i, ai[j] - 1)
            y = max(i, ai[j] - 1)
            if j == 0:
                n_prev[x][y] -= 1
                if n_prev[x][y] == 0:
                    q.append((x, y))
            else:
                xp = min(i, ai[j - 1] - 1)
                yp = max(i, ai[j - 1] - 1)
                post_matches[xp][yp].append((x, y))

    time = 0
    while q:
        time += 1
        qn = deque()
        while q:
            i, j = q.pop()
            for i2, j2 in post_matches[i][j]:
                n_prev[i2][j2] -= 1
                if n_prev[i2][j2] == 0:
                    qn.append((i2, j2))
        q = qn

    for i in range(n):
        for j in range(i + 1, n):
            if n_prev[i][j] > 0:
                print(-1)
                return
    print(time)

if __name__ == "__main__":
    main()


Measured memory_bytes: 129288
#include"stdio.h"
 
int max(int a,int b)

{
	if(!b)
	{
		return a;
	}
	return max(b,a%b);
}
int main()
{
	int m,n,temp;
         while (scanf("%d%d", &m, &n) != EOF)
	{
		     
	    	
		 
			if(m>n)
			{
				int a=max(m,n) ;
			printf("%d %d\n",a,n/a*m);
			}
			else
			{
				temp=m;
				m=n;
				n=temp;
				int a=max(m,n);
			printf("%d %d\n",a,n/a*m);
				
			}
		 	
		}
	}

Measured memory_bytes: 1720
#include <iostream>
using namespace std;
 
void extgcd(int a,int b,int &x,int &y){
  x = 1; y = 0;
 
  if(b != 0) extgcd(b, a% b, y, x), y -= (a / b) * x; 
}
 
int main(){
  int a,b,x,y;
 
  cin >> a >> b;
  extgcd(a,b,x,y);
  cout << x << " " << y << endl;
 
  return 0;
}


Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll mod = 1000000007;
const ll INF = mod * mod;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)

int main() {
    int S, W; cin >> S >>W;
    if (S <= W) cout << "unsafe" << endl;
    else cout << "safe" << endl;
}

Measured memory_bytes: 3620
import scala.io.StdIn._

object Main extends App {
  val n = readInt()
  val a = Array.fill(n)(readInt() -1)

  def solve(): Int = {
    var cnt = 1
    var pushedButtons = Set.empty[Int]
    var btn = a.head
    while(!pushedButtons(btn)) {
      if(btn == 1) return cnt
      else {
        pushedButtons = pushedButtons + btn
        btn = a(btn)
        cnt += 1
      }
    }
    -1
  }

  println(solve())

}



Measured memory_bytes: 70600
# coding: utf-8
 
"""
20191116
"""
 
N, K = map(int, input().split())
h = list(map(int, input().split()))
 
 
def fun():
    if K >= N:
        return abs(h[N-1]-h[0])
 
    cost = [abs(h[k]-h[0]) for k in range(K+1)] + [None for i in range(K+1, N)]
 
    for i in range(K+1, N):
        cost[i] = min([cost[i-k] + abs(h[i]-h[i-k]) for k in range(1, K+1)])
 
    return(cost[N-1])
 
 
print(fun())

Measured memory_bytes: 57440
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define MOD 1000000007 
using namespace std;
void solve(){
  ll n,d;
  cin>>n>>d;
  ll x,y;
  ll res=0;
  for(ll i=0;i<n;i++){
    ld x,y;
    cin>>x>>y;
    ld ans=sqrt((x*x)+(y*y));
    if(ans<=d)res++;
  }
  cout<<res<<endl;
}
int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt","r", stdin);
    freopen("output.txt","w", stdout);
#endif
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    solve();
    return 0;
}

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

using namespace std;

char s[100005];
int main() {

    scanf("%s", s);
    int len = strlen(s);
    int res = 0;
    for (int i = 0; i < len; ++i) {
        if (i % 2 == 0) {
            if (s[i] == 'p') res--;
        } else {
            if (s[i] == 'g') res++;
        }
    }
    printf("%d\n", res);
        

    return 0;
}


Measured memory_bytes: 384
a, b, c = map(int, input().split())
# 5が2つ、7が1つあれば良い
# ５があるとき＋１して７があるとき＋２にする
# 合計が４なればYES、そうでないならNO
sum = 0
if a == 5:
    sum += 1
elif a == 7:
    sum += 2

if b == 5:
    sum += 1
elif b == 7:
    sum += 2

if c == 5:
    sum += 1
elif c == 7:
    sum += 2

if sum == 4:
    print('YES')
else:
    print(('NO'))


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

using namespace std;

long long N, M;
long long total = 0;

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

  if (N == 1 && M == 1)
  {
    total = 1;
  }
  else if (N == 1 || M == 1)
  {
    total = N * M - 2;
  }
  else
  {
    total = N * M - N - N - (M - 2) - (M - 2);
  }

  cout << total;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if(a < b){ a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if(a > b){ a = b; return 1; } return 0; }
typedef long long ll;
int main()
{
  int n;cin >> n;
  vector<ll> a(n);
  rep(i,n) cin >> a[i];

  sort(a.begin(), a.end());

  vector<ll> sum(n+1);
  sum[0] = 0;
  rep(i,n) sum[i+1] = sum[i] + a[i];
  
  int cnt = 1;
  for (int i = n - 1; i >= 0; --i) {
    if(sum[i] * 2 >= a[i]) cnt++;
    else break;
  }

  cout << cnt << "\n";
  
  return 0;
}


Measured memory_bytes: 1792
S = input()
T = input()
  
cnt = []
for i in range(len(S)-len(T)+1):
	mismatch = 0
	for j in range(len(T)):
		if S[i+j] != T[j]:
			mismatch += 1
	cnt.append(mismatch)
	
print(min(cnt))

			

Measured memory_bytes: 9036
#include <bits/stdc++.h>
using namespace std;
 
int main() 
{
    int n;
    int ali = 0,bob = 0;
    cin >> n;
    vector<int> a(n);

    for(int i = 0; i < n;i++)
    {
        cin >> a.at(i);
    }
    
    sort(a.begin(),a.end());
    reverse(a.begin(),a.end());

    for(int i = 0;i < n;i++)
    {
        if(i%2 == 0)
        {
            ali += a.at(i);
        }else{
            bob += a.at(i);
        }
    }

    cout << ali-bob << endl;

}

Measured memory_bytes: 256