akhauriyash/Code-Regression huggingface dataset:
import os
import sys
from collections import defaultdict, Counter
from itertools import product, permutations,combinations, accumulate
from operator import itemgetter
from bisect import bisect_left,bisect
from heapq import heappop,heappush,heapify
from math import ceil, floor, sqrt, gcd
from copy import deepcopy
from functools import reduce



def main():
    n = int(input())
    x_list = list(map(int, input().split()))
    x_list.sort(reverse=True)
    a,b = 0,0
    for i in range(n):
        if i%2 == 0:
            a += x_list[i]
        else:
            b += x_list[i]

    print(a-b)

if __name__ == "__main__":
    main()


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


main()
{
	int a;
	cin >> a;
	
	set<int>sp;
	
	for(int i=0;i<a;i++)
	{
		int x;
		cin >> x;
		sp.insert(x);
	}
	cout << *--sp.end() - *sp.begin();
	
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>//printf("%.9f\n",*********);
#include<vector>//文字列.erase(n),vector
#include<algorithm>//next_permutation
#include<set>
#include<string>//char(小文字-32=大文字) to_string,string,char
#include<sstream>
#include<complex>
#include<time.h>
#include<random>
#include<cmath>//min,max
#include<math.h>
#include<queue>
#include<time.h>
#include<iomanip>
#include<locale>
#include<utility>//swap
#define rt "\n"
#define rep(i,n) for(int i=0;i<n;i++)
#define rop(i,n) for(int i=1;i<=n;i++)//start==1
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define drop(i,n) for(int i=n;0<i;i--)//end==1
#define yes(ans) if(ans)cout<<"yes"<<rt;else cout<<"no"<<rt;
#define Yes(ans) if(ans)cout<<"Yes"<<rt;else cout<<"No"<<rt;
#define YES(ans) if(ans)cout<<"YES"<<rt;else cout<<"NO"<<rt;
#define Yay(ans) if(ans)cout<<"Yay!"<<rt;else cout<<":("<<rt;
#define sec(a,b,ans) if(ans)cout<<a<<rt;else cout<<b<<rt;
#define vcin(s,n) rep(i,n)cin>>s[i];//vcin(配列名),(繰り返し回数)
#define sort(s) sort(s.begin(),s.end())//標準=昇順
#define reve(s) reverse(s.begin(),s.end())//反転
#define str string
#define please return
#define AC 0
#define rapid_pleaseAC_fast cin.tie(0);ios::sync_with_stdio(false)
#define pi 3.1415926535897932384626//pi
#define nine 1000000000//10^9

using namespace std;
typedef vector<int> vint;
typedef long double ldouble;
typedef vector<string> vstr;
typedef vector<char> vchar;
typedef vector<double> vdou;
typedef vector<double> vdouble;
typedef long long int llint;
typedef pair<int, int> pint;
typedef pair<llint, llint> pllint;
typedef vector<llint> vllint;
typedef vector<pint> vpint;
typedef vector<pair<llint, llint>> vpllint;
typedef vector<vector<int>> vvint;
typedef vector<vector<char>> vvchar;
typedef vector<vector<double>> vvdouble;
typedef vector<vector<llint>> vvllint;
typedef vector<vector<string>> vvstr;
typedef vector<vector<bool>> vvbool;
typedef vector<vector<pint>> vvpint;
typedef vector<bool> vbool;

long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

long long LCM(long long a, long long b) {
	return a * b / GCD(a, b);
}

unsigned GetDigit(unsigned num) {
	return std::to_string(num).length();
}

int tow(int n) {//2のn乗
	if (n == 0)return 1;
	int x = tow(n / 2);
	x *= x;
	if (n % 2 == 1)x *= 2;
	return x;//@domino
}

int SED(int n) { //Sum of Each Digit
	int sum = 0;
	while (n > 0) {
		sum += n % 10; n /= 10;
	}
	return sum;
}

unsigned ND(unsigned num) {//Number of Digits
	return std::to_string(num).length();//outmax=10
}//stringのほうが効率よくないか？

/*

 (char)toupper(a[n])=文字列のn文字目を大文字で出力

  pow(a,b)=aのb乗

  */


int main(void) {
	rapid_pleaseAC_fast;

	string a, b;
	cin >> a >> b;

	rep(i, b.size()) {
		cout << a[i] << b[i];
	}
	if (a.size() != b.size()) {
		cout << a[a.size() - 1];
	}
	cout << rt;

	please AC;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
vector<int> b, r, x, y;
b.resize(n);
r.resize(n);
x.resize(m);
y.resize(m);
for(int i = 0; i < m; i++) {
cin >> x[i] >> y[i];
}
for(int i = 0; i < n; i++) {
b[i] = 1;
}
r[0] = 1;
for(int i = 0; i < m; i++ ) {
b[x[i] - 1]--;
b[y[i] - 1]++;
if(r[y[i] - 1] ==0)
r[y[i] - 1] = r[x[i] - 1];
if(b[x[i] - 1] == 0)
r[x[i] - 1] = 0;
}
int c = 0;
for(int i = 0; i < n; i++)
if(r[i] == 1) c++;
cout << c << endl;
return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/tag_and_trait.hpp>
#define BEGIN ios_base::sync_with_stdio(0);cin.tie(0)
#define END return EXIT_SUCCESS
#define FOR(I,A,B) for((I)=(A);(I)<(B);(I)++)
#define REP(I,N) FOR(I,0,N)
#define UP(I,A,B) for((I)=(A);(I)<=(B);(I)++)
#define DW(I,A,B) for((I)=(A);(I)>=(B);(I)--)
#define IN(P) std::cin>>(P)
#define IN2(P1,P2) std::cin>>(P1)>>(P2)
#define IN3(P1,P2,P3) std::cin>>(P1)>>(P2)>>(P3)
#define INS(I,N,V) REP(I,N) std::cin>>V[I]
#define OUT(P) std::cout<<P<<std::endl
#define OUT2(P1,P2) std::cout<<P1<<" "<<P2<<std::endl
#define OUT3(P1,P2,P3) std::cout<<P1<<" "<<P2<<" "<<P3<<std::endl
#define OUTS(I,N,V) REP(I,N) std::cout<<V[i]<<std::endl
#define ALL(C) (C).begin(),(C).end()
using namespace std;
using namespace __gnu_pbds;
typedef unsigned long ul;
const ul MOD=1000000007;
ul H,W,dp[1001][1001],i,j;
vector<string> a;
void add(ul&a,ul&b){
  a+=b;
  if(a>=MOD)a-=MOD;
}
inline void solve(){
  IN2(H,W);
  a.resize(H);
  INS(i,H,a);
  dp[0][0]=1;
  REP(i,H){
    REP(j,W){
      if(i+1<H&&a[i+1][j]=='.')add(dp[i+1][j],dp[i][j]);
      if(j+1<W&&a[i][j+1]=='.')add(dp[i][j+1],dp[i][j]);
    }
  }
  OUT(dp[H-1][W-1]);
}

int main(int argc,char**argv){
  BEGIN;
  solve();
  END;
}


Measured memory_bytes: 9088
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define F first
#define S second
int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll n, mn = INT_MAX;
    cin >> n;
    while(n--)
    {
        ll x, y = 0;
        cin >> x;
        while(x % 2 == 0)
        {
            ++y;
            x /= 2;
        }
        mn = min(mn, y);
    }
    cout << mn;
    return 0;
}


Measured memory_bytes: 256
H,W = map(int,input().split())
L = []
A = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']
for i in range(H):
  L.append(input().split())
for i in range(H):
  for j in range(W):
    if L[i][j] == 'snuke':
      k = i+1
      l = A[j]
      break
print(l+str(k))


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

int main() {
    int n;
    cin >> n;
    vector<int> a(1e5);
    for (int i = 0; i < n; i++) {
        int aa;
        cin >> aa;
        a[aa]++;
    }
    int ans = 0;
    for (int i = 1; i < 1e5 - 1; i++) ans = max(ans, a[i-1] + a[i] + a[i+1]);
    cout << ans << endl;
}


Measured memory_bytes: 640
#include<stdio.h>
#include<string.h>

int main(){
  typedef struct {
    char s[31];
    int a;
  } book;
  
  book b[100];
  int i=0;
  while(scanf("%s %d", b[i].s, &b[i].a) != EOF){
    i++;
  }
  
  int j,k;
  for(j=0;j<i-1;j++){
    for(k=0;k<i-1;k++){
      if(strcmp(b[k].s, b[k+1].s)>0)
	{int p;char q[31];
	  p=b[k].a;b[k].a=b[k+1].a;b[k+1].a=p;
	  strcpy(q,b[k].s);strcpy(b[k].s,b[k+1].s);strcpy(b[k+1].s,q);
	}
    }
  }


  for(j=0;j<i-1;j++){
    for(k=0;k<i-1;k++){
      if(strcmp(b[k].s, b[k+1].s)==0){
	if(b[k].a > b[k+1].a){
	  int p;
	  p=b[k].a;b[k].a=b[k+1].a;b[k+1].a=p;
	}
      }
    }
  }

  printf("%s\n%d", b[0].s, b[0].a);
  for(j=1;j<i;j++){
    if(strcmp(b[j].s, b[j-1].s) != 0){
      printf("\n");
      printf("%s\n%d", b[j].s, b[j].a);
    }
    else{
      printf(" %d", b[j].a);
    }
  }
  printf("\n");

  return 0;
}

Measured memory_bytes: 2628
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
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 (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


int main() {
    ll N,K;
    cin >>N>>K;
    vector<Pi>ab(N);
    rep(i,N){
        ll a,b;
        cin>>a>>b;
        ab[i]=mp(a,b);
    }

    sort(all(ab));
    ll cnt=0;
    rep(i,N){
        cnt+=ab[i].second;
        if(cnt>=K){
            cout<<ab[i].first<<endl;
            return 0;
        }
    }


    return 0;
    

}

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

using namespace std;

typedef pair<int,int>P;

const int MAX_N = 100005;

int a[MAX_N];
int n;

int main()
{
	scanf("%d",&n);
	rep(i,n){
		scanf("%d",&a[i]);
	}
	sort(a,a+n);
	ll asum=0;
	int cnt=1;
	for(int i=0;i<n-1;i++){
		if(2*(asum+a[i]) >= a[i+1]){
			cnt++;
		}else{
			cnt=1;
		}
		asum += a[i];
	}
	printf("%d\n",cnt);
	return 0;
}

Measured memory_bytes: 640
#include<iostream>
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
N = int(input())
s = [int(input()) for _ in range(N)]

s.sort()
mod = [i%10 for i in s]
ans = sum(s)

if ans%10 == 0:
    if mod.count(0)==N:
        ans=0
    else:
        for i in range(N):
            if mod[i]!=0:
                ans -=s[i]
                break
            
print(ans)

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

a_min = min(a)
a_pos = a.index(min(a))

if ((len(a) - 1) % (k - 1)) == 0:
    print((len(a) - 1) // (k - 1))
else:
    print((len(a) - 1) // (k - 1) + 1)


Measured memory_bytes: 52652
// author: Saman Mahdanian
#include <iostream>
#include <algorithm>
#include <map>

using namespace std;
const int N = 20;

int n;
string s;
map <pair <string, string>, long long> mp;
string get (string &, int, int);

int32_t main() {
	cin >> n >> s;
	string s1 = s.substr(0, n);
	string s2 = s.substr(n, n);
	reverse (s2.begin(), s2.end());

	for (int mask = 0; mask < (1 << n); mask++)
		mp[{get(s2, mask, 0), get(s2, mask, 1)}]++;

	long long int ans = 0;
	for (int mask = 0; mask < (1 << n); mask++)
		ans += mp[{get(s1, mask, 0), get(s1, mask, 1)}];

	cout << ans << endl;
}

string get (string &t, int mask, int v) {
	string res = "";
	for (int i = 0; i < n; i++)
		if (((mask >> i) & 1) == v)
			res += t[i];
	return res;
}

// SamMHD :: 21/11/2018 12:27:10 :: Another MAP...


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

int main(){
    int n;
    cin >> n;
    int b[n];
    for(int i = 0; i < n-1; i++){
        cin >> b[i];
    }
    int ans = b[0];
    ans += b[n-2];
    b[n-1] = 100000;
    for(int i = 0; i < n-2; i++){
        ans += min(b[i],b[i+1]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
long n,c,a,s;
int main(){
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>a;
    if(a)s+=a;
    else c+=s/2,s=0;
  }
  c+=s/2;
  cout<<c<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <cstdlib>
#include <map>
#include <queue>
#include <algorithm>
#include <stack>
#include <functional>
#define rep(i,j,n) for(i=j;i<(n);i++)
#define rrep(i,j,n) for(i=j;i>(n);i--)
typedef long long int lli;
//#define N 1000000007

using namespace std;

int main(){
    lli n,a,ans=0;
    map<lli,lli> m;
    vector<lli> v;
    lli i;
    cin>>n;
    rep(i,0,n){
        cin>>a;
        if(m[a]==1){
            v.push_back(a);
            m[a]=0;
        }
        else{
            m[a]=1;
        }
    }
    if(v.size()!=0){
        sort(v.begin(),v.end());
        ans=v[v.size()-1]*v[v.size()-2];
    }
    cout<<ans<<endl;
}


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

#define  pf                  printf
#define  sc                  scanf
#define  PI                  2*acos(0.0)
#define  fast                ios_base::sync_with_stdio(false);cin.tie(0); cout.tie(0)
#define  mem(a,b)            memset(a, b, sizeof(a) )
#define  gcd(a,b)            __gcd(a,b)
#define  lcm(a,b)            (a*(b/gcd(a,b)))
#define  MAX                 1234567899
#define  mod                 1000000007
#define  all(v)              (v).begin(),(v).end()
#define  vSort(v)            sort(all(v))
#define  maxSort(v)          sort(all(v),greater<int>())
#define  Unique(v)           v.erase(unique(all(v)),v.end())
#define  sqr(x)              ((x)*(x))
#define  qube(x)             ((x)*(x)*(x))
#define  deci(n)             cout<<fixed<<setprecision(n)
#define  sci(n)              sc("%d",&(n))
#define  scii(x,y)           sc("%d %d",&(x),&(y))
#define  scl(x)              sc("%lld",&(x))
#define  scll(x,y)           sc("%lld %lld",&(x),&(y))
#define  vi                  vector<int>
#define  hi                  pf(" HI \n")
#define  pp                  pair<int,int>
#define  pb(x)               push_back(x)
#define  mp(x,y)             make_pair(x,y)
#define  F                   first
#define  S                   second
#define  check(n,pos)        (n & (1<<(pos)))
#define  biton(n,pos)        (n  (1<<(pos)))
#define  bitoff(n,pos)       (n & ~(1<<(pos)))
typedef  long long int       lli;
typedef  unsigned long long int ulli;
int dx4[] = { 0 , 0 , -1 , 1 } ;
int dy4[] = { -1 , 1 , 0 , 0 } ;
bool valid( int r , int c , int x , int y ){
    if( x >= 1 && x <= r && y >= 1 && y <= c ) return 1 ; return 0 ;}

using namespace std;

int main ()
{
    lli n;
    cin >> n;
    n--;
    lli p =((n)*(n+1))/2;
    cout << p <<endl;
    return 0;
}



Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <bitset>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define index(xs, x) (int)(lower_bound(all(xs), x) - xs.begin())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007

int N;
int L[100000], R[100000];
bool dead[100000];

long long solve() {
  priority_queue<P> lmax;
  priority_queue<P, vector<P>, greater<P> > rmin;
  rep(i, N) {
    lmax.push(P(L[i], i));
    rmin.push(P(R[i], i));
  }

  long long s = 0;
  int pos = 0;
  rep(i, N) dead[i] = false;
  rep(_, N) {
    if (_%2) {
      // <-
      while (dead[rmin.top()._2]) rmin.pop();
      int id = rmin.top()._2;
      dead[id] = true;
      if (R[id] < pos) s += pos-R[id], pos = R[id];
    }
    else {
      // ->
      while (dead[lmax.top()._2]) lmax.pop();
      int id = lmax.top()._2;
      dead[id] = true;
      if (pos < L[id]) s += L[id]-pos, pos = L[id];
    }
  }
  s += abs(pos);
  return s;
}

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> N;
  rep(i, N) cin >> L[i] >> R[i];
  long long m = solve();
  rep(i, N) L[i] = -L[i], R[i] = -R[i], swap(L[i], R[i]);
  m = max(m, solve());
  cout << m << "\n";
  return 0;
}


Measured memory_bytes: 4076
// AtCoder template
// sabaより胡蝶しのぶさんの方が可愛いのではないか？
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0; i < n; ++i)



int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string s; cin >> s;
    if(s.size()%2 == 1){
        cout << "No" << endl;
        return 0;
    }

    for(int i = 0; i < s.size(); i += 2){
        if(s[i] != 'h' || s[i+1] != 'i'){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long
#define lf long double
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef pair <ll,ll> ii;
typedef vector <ll> vi;
typedef vector <ii> vii;
typedef vector <bool> vb;
typedef vector <vector <ll> > vv;
typedef vector <vector <vector<ll> > > vvv;
typedef vector <string> vs;
typedef vector <lf> vf;
#define tr1(x) cerr << #x << ": " << x << endl
#define tr2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl
#define tr3(x,y,z) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trv(a) cerr<<#a<<":\n";for(ll zz=0;zz<a.size();zz++) cerr<<a[zz]<<" ";cerr<<endl
#define mod 1000000007
#define inf 9999999999999999ll

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n,k;
    cin>>n>>k;
    ll ans=0;
    while(n)
    {
        n/=k;
        ans++;
    }
    cout<<ans<<endl;
}


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

typedef vector< long long > vi;
#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define ll long long
#define MAX 100005

ll dp[MAX][3];

ll vac(ll happy[][3], ll n, ll s1, ll s2, ll c)
{
    if (n == 1)
        dp[n][c] = max(happy[0][s1], happy[0][s2]);
    
    if (dp[n][c] == -1)
        dp[n][c] = max(happy[n - 1][c] + vac(happy, n - 1, c, s2, s1), happy[n - 1][c] + vac(happy, n - 1, s1, c, s2));
    return dp[n][c];
}

int main(void)
{
    for (int j = 0; j < 3; j++)
        for (int i = 0; i < MAX; i++)
            dp[i][j] = -1;
    ll n;
    cin >> n;
    ll happy[n][3];
    for (int i = 0; i < n; i++)
        cin >> happy[i][0] >> happy[i][1] >> happy[i][2];
    vac(happy, n, 0, 1 ,2), vac(happy, n, 2, 1 ,0), vac(happy, n, 2, 0 ,1);
    cout << max(dp[n][2], max(dp[n][0], dp[n][1])) << "\n";
}


Measured memory_bytes: 12800
#include<bits/stdc++.h>
using namespace std;
int main(){
	long long int a,b,c,d,i=0,n=0;
  	cin >> n;
  	string s;
  	unordered_set <string> str;
  	for(i=0;i<n;i++){
    	cin >> s;
      	str.insert(s);
    }
  	//if(c<=0){cout<<"Yes"<<endl;}
  	//else cout << "No"<<endl;
  	cout << str.size()<<endl;
}

Measured memory_bytes: 17788
h, w = map(int, input().split())
T = [input() for _ in range(h)]
flagRow = [0] * h
flagColumn = [0] * w

for i in range(h):
    for j in range(w):
        if T[i][j] == "#":
            flagRow[i] = 1
            flagColumn[j] = 1

for i in range(h):
    if flagRow[i] == 1:
        for j in range(w):
            if flagColumn[j] == 1:
                print(T[i][j], end = "")
        print("")

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

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

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

    int mprofit = -1111111111;
    int minv = prices[0];
    for (int i = 1; i < n; i++) {
        mprofit = max(mprofit, prices[i] - minv);
        minv = min(minv, prices[i]);
    }

    cout << mprofit << endl;
    return 0;
}

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
#define ll long long

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);
	char c;
	cin>>c;
	cout<<(c=='e'||c=='u'||c=='o'||c=='a'||c=='i'?"vowel\n":"consonant\n");
}




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

void print(vector<int> x){
  for (int n = 0; n < x.size(); n++){
    cout << x.at(n) << " ";
  }
  cout << endl;
}

int main(){
  int N, K;
  cin >> N >> K;

  vector<int> P(N);
  for (int n = 0; n < N; n++){
    cin >> P.at(n);
  }

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

  int cost = 0;
  for (int n = 0; n < K; n++){
    cost += P.at(n);
  }
  cout << cost << endl;
}


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

int main() {
  int N, i, answer;
  int Ap = 0, Bp = 0;
  cin >> N;
  vector<int> card(N);
  for (i = 0; i < N; i++) {
    cin >> card.at(i);
  }
  
  sort(card.begin(), card.end());
  reverse(card.begin(), card.end());
  for (i = 0; i < N; i++) {
    //Alice's turn
    if  ((i % 2) == 0) {
      Ap += card.at(i);
    } else {  //Bob's turn
      Bp += card.at(i);
    }
  }
  
  answer = Ap - Bp;
  cout << answer << endl;
   
}

Measured memory_bytes: 256
def solve():
  n,m = (int(i) for i in input().split())
  a = [0]*n
  for i in range(m):
    a1,b1 = (int(i) for i in input().split())
    a[a1-1]+=1
    a[b1-1]+=1
  ans = 'YES'
  for i in range(n):
   if a[i]%2 == 1:
    ans ='NO'
  return ans
                   
  
if __name__ == '__main__':
  print(solve())

Measured memory_bytes: 3828
#include <iostream>

using namespace std;

int main()
{
    long long n;
    cin>>n;
    if(n>=1&&n<=9)
        cout<<n<<endl;
    else if(n>=10&&n<=99)
        cout<<9<<endl;
    else if(n>=100&&n<=999)
        cout<<n-90<<endl;
    else if(n>=1000&&n<=9999)
        cout<<909<<endl;
    else if(n>=10000&&n<=99999)
        cout<<n-10000+1+909<<endl;
    else if(n==100000)
        cout<<90909<<endl;
}


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

vector<int> R[100000];

int main() {
	int N, M, tmp, ans;
	ans = 0;
	vector<int> H;

	cin >> N >> M;

	for (int i = 0; i < N; i++) 
	{
		cin >> tmp;
		H.push_back(tmp);
	}

	for (int i = 0; i < M; i++) 
	{
		int a, b;
		cin >> a >> b;

		R[a - 1].push_back(b - 1);
		R[b - 1].push_back(a - 1);
	}
	for (int i = 0; i < N; i++) 
	{
		if (R[i].size() == 0)
		{
			ans++;
		}
		else 
		{
			int flag = 1;
			for (int j = 0; j < R[i].size(); j++) 
			{
				if (H[i] <= H[R[i][j]])
					flag = 0;
			}
			if (flag == 1)
				ans++;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 8776
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <vector>

using namespace std;

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

matrix mult(matrix a, matrix b, int m) {
  matrix c;
  for(int i = 0; i < a.size(); i++) {
    c.push_back({});
    for(int j = 0; j < b[0].size(); j++) {
      c[i].push_back(0);
      for(int k = 0; k < b.size(); k++) {
        c[i][j] += a[i][k] * b[k][j];
        c[i][j] %= m;
      }
    }
  }
  return c;
}

matrix pow(matrix b, ll e, int m) {
  matrix r;
  for(int i = 0; i < b.size(); i++) {
    r.push_back({});
    for(int j = 0; j < b.size(); j++) {
      r[i].push_back(i == j);
    }
  }
  while(e) {
    if(e%2) {
      r = mult(r, b, m);
    }
    e /= 2;
    if(e) {
      b = mult(b, b, m);
    }
  }
  return r;
}

void solve(ll start, ll diff, ll numTerms, ll m) {
  ll len = 1;
  ll currCap = 9;
  matrix curr;
  curr.push_back({0});
  curr.push_back({start%m});
  curr.push_back({1});
  while(numTerms > 0) {
    /*
    (x, start, 1) -> (10**len*x + start, start + diff, 1)
    */
    len *= 10;
    len %= m;
    for(int d = 60; d >= 0; d--) {
      if((1LL << d) > numTerms) continue;
      ll lastTerm = start + (-1 + (1LL << d)) * diff;
      if(lastTerm <= currCap) {
        numTerms -= 1LL << d;
        matrix b = {
          {len, 1, 0},
          {0, 1, diff%m},
          {0, 0, 1}
        };
        curr = mult(pow(b, 1LL << d, m), curr, m);
        start += (1LL << d) * diff;
      }
    }
    currCap = 10 * currCap + 9;
  }
  cout << curr[0][0] << "\n";
}

void solve() {
  ll a, b, n, m;
  cin >> n >> a >> b >> m;
  solve(a, b, n, m);
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  solve();
  /*
  int t;
  cin >> t;
  for(int i = 1; i <= t; i++) {
    cout << "Case #" << i << ": ";
    solve();
  }
  */
}


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

int i,j,k,park[15][2],time[200],head,last,eee,lot,tim,ttt;
int n,m;

int main(){
	while(scanf("%d %d",&m,&n)*m*n){
		head=1;last=0;eee=0;
		while(eee<n){
			if(ttt%10==0 && last<n){
				last++;
				scanf("%d",&time[last]);
			}

			ttt++;
			time[0]=999;

			for(i=0;i<m;i++){
				time[park[i][0]]--;
				time[park[i][1]]--;
			}

			for(i=0;i<m;i++){
				if(time[park[i][0]]<1){
					printf("%d",park[i][0]);
					eee++;
					if(eee<n)printf(" "); else printf("\n"); 
					park[i][0]=park[i][1];
					park[i][1]=0;
					i--;
				}
			}

			while(head<=last){
				lot=-1;tim=999999999;
				for(i=0;i<m;i++){
					if(park[i][1]>0)continue;
					if(park[i][0]==0){lot=i;break;}
					else if(time[head]<=time[park[i][0]]){
						if(tim>(time[park[i][0]]-time[head])){
							tim=(time[park[i][0]]-time[head]);
							lot=i;
						}
					}
					else if(tim>(time[head]-time[park[i][0]])*1000){
						tim=(time[head]-time[park[i][0]])*1000;
						lot=i;
					}
				}
				if(lot>-1){
					if(park[lot][0]>0)park[lot][1]=park[lot][0];
					park[lot][0]=head;
					head++;
				}
				else break;
			}
			/*
			printf("time:%d head:%d last:%d\n",ttt,head,last);
			for(i=0;i<2;i++){
				for(j=0;j<m;j++){
					printf("%3d-%3d",park[j][i],time[park[j][i]]);
				}printf("\n");
			}
			printf("\n\n");
			*/
		}
	}
	return 0;
}

Measured memory_bytes: 604
#include<bits/stdc++.h>
    using namespace std;
    int main() {
      int n;
      cin>>n;
      vector<int>vec(n+1);
      vector<int>dp(n+1, 0);
      
      for(int i=1;i<=n;i++)
        cin>>vec[i];
      
      dp[0]=0;
      dp[1]=0;
      dp[2]=abs(vec[2]-vec[1]);  
     
      for(int i=3;i<=n;i++) 
        dp[i]=min((dp[i-1]+abs(vec[i-1]-vec[i])), (dp[i-2]+abs(vec[i-2]-vec[i])));
        
      
      
      cout<<dp[n]<<endl;
      
    }  

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

#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define cases int t;cin>>t;while(t--)
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define per(i,a,b)	for(ll i=a;i>b;i--)

#define test4(x,y,z,a) cout<<"x is "<<x<<"		y is "<<y<<"		z is "<<z<<"		a is "<<a<<endl;
#define test3(x,y,z) cout<<"x is "<<x<<"		y is "<<y<<"		z is "<<z<<endl;
#define test2(x,y) cout<<"x is "<<x<<"		y is "<<y<<endl;
#define test1(x) cout<<"x is "<<x<<endl;

ll mod = 1000000007;

using namespace std;
int main()
{
	#ifndef ONLINE_JUDGE
	freopen("inputf.in", "r", stdin);
	freopen("outputf.in", "w", stdout);
	#endif
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	
	ll n,m;
	cin>>n>>m;
	ll h[n];
	rep(i,0,n){
		cin>>h[i];
	}
	ll u,v;
	vector<ll>G[n];
	set<pair<ll,ll> >s;
	rep(i,0,m){
		cin>>u>>v;
		u--;v--;
		s.insert({u,v});
	}
	// for(auto i:s){
	// 	test2(i.ff,i.ss)
	// }
	for(auto i:s){
		G[i.ff].pb(i.ss);
		G[i.ss].pb(i.ff);
	}
	ll count=0;
	rep(i,0,n){
		ll p=h[i],flag=0;
		for(auto j:G[i]){
			// test2(p,h[j])
			if(p<=h[j]){
				flag=1;
				break;
			}
		}

		if(flag==0){
			// test1(i)
			count++;
		}
	}
	cout<<count;



	return 0;
}

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

typedef long long ll;

const ll inf = 10000000;

int main() {
    int N, M;
    int ans = 0;
    cin >> N >> M;
    vector<pair<int, int>>ab(M);
    for (int i = 0; i < M; i++) {
        cin >> ab[i].first >> ab[i].second;
    }
    sort(ab.begin(), ab.end());
    int l, r;
    l = 0;
    r = inf;
    for (int i = 0; i < M; i++) {
        if (r <= ab[i].first) {
            ans++;
            r = inf;
        }
        l = max(l, ab[i].first);
        r = min(r, ab[i].second);
    }
    if (r != inf) {
        ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
n,k=map(int, input().split())
r,s,p=map(int, input().split())
t=input()

line=[ t[i::k] for i in range(k)]

rr=0
ss=0
pp=0
for x in line:
    #print(x)

    combo=1
    al=x[0]
    for i in x[1:]:
        if al == i:
            combo+=1
            next
        else:
            if al == 'r':
                pp+=(combo+1)//2
            elif al == 's':
                rr+=(combo+1)//2
            else:
                ss+=(combo+1)//2
            combo=1
            al=i

    if al == 'r':
        pp+=(combo+1)//2
    elif al == 's':
        rr+=(combo+1)//2
    else:
        ss+=(combo+1)//2

#print(rr,ss,pp)

print(pp*p+rr*r+ss*s)

Measured memory_bytes: 47472
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(10)

using namespace std;

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int N, M;
    cin >> N >> M;
    vector<vector<int>> G(N, vector<int>(N, 0));
    REP(i, M) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        G[a][b] = 1;
        G[b][a] = 1;
    }

    int ans = 0;
    vector<int> v;
    REP(i, N-1) {
        v.push_back(i+1);
    }
    do {
        if (G[0][v[0]] == 0) continue;

        bool ok = true;
        REP(i, v.size() - 1) {
            if (G[v[i]][v[i+1]] != 1) {
                ok = false;
                break;
            }

        }
        if (!ok) continue;
        ans++;
    } while (next_permutation(v.begin(), v.end()));

    cout << ans << endl;

    return 0;
}


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

int main() {
	char S[3];
	cin >> S;
	if (S[0] != S[1] && S[1] != S[2] && S[2] != S[0]) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
n = input()
len_n = len(n)
if len_n == 1:
  print(int(n))
elif len_n == 2:
  print(9)
elif len_n == 3:
  n = int(n)
  print(n - 99 + 9)
elif len_n == 4:
  print(909)
elif len_n == 5:
  n = int(n)
  print(n - 9999 + 909)  
else:
  print(90909)
  

Measured memory_bytes: 3060
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	sc := bufio.NewScanner(os.Stdin)
	bf := make([]byte, 1024*1024)
	sc.Buffer(bf, 10*1024*1024)
	sc.Split(bufio.ScanWords)

	in := func() uint64 {
		sc.Scan()
		i, _ := strconv.ParseUint(sc.Text(), 10, 64)
		return i
	}

	n := in()

	vc := make(map[uint64]uint64)

	var i uint64
	for i = 0; i < n; i++ {
		vc[in()]++
	}

	var val uint64

	for v, c := range vc {
		for v1, c1 := range vc {
			if v1 > v {
				for v2, c2 := range vc {
					if v2 < (v1+v) && v2 > v1 {
						val += c * c1 * c2
					}
				}
			}
		}
	}

	fmt.Println(val)
}


Measured memory_bytes: 1848
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;

int main() {
  int64_t n,a,b;
  cin >> n >> a >> b;
  if ((b-a)%2 == 0) {
    cout << (b-a) / 2 << endl;
  }
  else {
    int64_t x = (a+b-1) / 2;
    int64_t y = (n*2-a-b+1) / 2;
    cout << min(x,y) << endl;
  }
}  

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

int main(){
	LL x, k;
	cin >> x >> k;
	LL r[k];
	for(int i = 0; i < k; i++) cin >> r[i];
	LL q;
	cin >> q;
	vector<LL> t;
	vector<LL> a;
	for(int i = 0; i < q; i++){
		LL p, r;
		cin >> p >> r;
		t.push_back(p);
		a.push_back(r);
	}

	LL minv = 0;
	LL maxv = x;
	LL dx = 0;
	LL sgn = -1;

	LL s1 = 0;
	LL s2 = 0;
	LL lastt = 0;
	while(s2 < t.size()){
		if(s1 == k || t[s2] < r[s1]){
			// answer
			LL f = max(minv, min(maxv, a[s2] + dx));
			f += sgn*(t[s2] - lastt);
			f = max(0LL, min(x, f));
			cout << f << endl;
			s2++;
		} else {
			LL diff = r[s1] - lastt;
			diff *= sgn;
			minv += diff;
			maxv += diff;
			dx += diff;
			minv = max(0LL, min(x, minv));
			maxv = max(0LL, min(x, maxv));
			sgn *= -1;
			lastt = r[s1];
			s1++;
			//cout << minv << " " << maxv << " " << dx << " " << sgn << endl;
		}
	}
}


Measured memory_bytes: 3820
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

#define rep(i, n) for(int i=0;i<n;i++)

typedef int long long ll;
using namespace std;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;

int main() {
    int n;
    cin>>n;
    vector<int> y(n);
    rep(i,n){
        cin>>y[i];
    }
    int p=y[0];
    int ans=1;
    for(int i=1;i<n;i++){
        if(y[i]>=p){
            ans++;
            p=y[i];
        }
    }
    cout<<ans<<endl;




    return 0;
}


Measured memory_bytes: 256
/**
 *    author:  tourist
 *    created: 03.11.2019 19:31:34       
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  struct State {
    int onlyI;
    int onlyD;
    int both;
    int val;
    int val_worse;
  };
  auto UpdateBoth = [&](State& s, int dp, int dpval) {
    if (dp < s.both) {
      if (dp == s.both - 1) {
        s.val_worse = min(s.val, dpval);
      } else {
        s.val_worse = dpval;
      }
      s.val = dpval;
      s.both = dp;
    } else {
      if (dp == s.both) {
        s.val = min(s.val, dpval);
      }
      if (dp == s.both + 1) {
        s.val_worse = min(s.val_worse, dpval);
      }
    }
  };
  State x;
  x.onlyI = 1;
  x.onlyD = 1;
  x.both = 2;
  x.val = 0;
  x.val_worse = 0;
  for (int i = 1; i < n; i++) {
    State y;
    y.onlyI = y.onlyD = min(min(x.onlyI, x.onlyD), x.both) + 1;
    y.both = y.onlyI + 1;
    y.val = y.val_worse = 0;
    { // onlyI -> onlyI
      if (a[i] >= a[i - 1]) {
        y.onlyI = min(y.onlyI, x.onlyI);
      }
    }
    { // onlyI -> both
      if (a[i] >= a[i - 1]) {
        UpdateBoth(y, x.onlyI + 1, a[i - 1]);
      }
    }
    { // onlyD -> onlyD
      if (a[i] <= a[i - 1]) {
        y.onlyD = min(y.onlyD, x.onlyD);
      }
    }
    { // onlyD -> both
      UpdateBoth(y, x.onlyD + 1, max(0, a[i] - a[i - 1]));
    }
    { // both -> onlyI
      if (a[i] >= x.val) {
        y.onlyI = min(y.onlyI, x.both);
      }
    }
    { // both -> onlyD
      if (a[i] <= a[i - 1] - x.val) {
        y.onlyD = min(y.onlyD, x.both);
      }
    }
    for (int rot = 0; rot < 2; rot++) {
      { // both -> both, keep
        int curI = x.val;
        int curD = a[i - 1] - x.val;
        if (a[i] < curI + curD) {
          curD -= (curI + curD) - a[i];
        } else {
          curI += a[i] - (curI + curD);
        }
        if (curD >= 0 && curI >= 0) {
          UpdateBoth(y, x.both, curI);
        }
      }
      { // both -> both, break I
        int curI = 0;
        int curD = a[i - 1] - x.val;
        if (a[i] < curI + curD) {
          curD -= (curI + curD) - a[i];
        } else {
          curI += a[i] - (curI + curD);
        }
        if (curD >= 0 && curI >= 0) {
          UpdateBoth(y, x.both + 1, curI);
        }
      }
      { // both -> both, break D
        int curI = x.val;
        int curD = (int) 1.01e9;
        if (a[i] < curI + curD) {
          curD -= (curI + curD) - a[i];
        } else {
          curI += a[i] - (curI + curD);
        }
        if (curD >= 0 && curI >= 0) {
          UpdateBoth(y, x.both + 1, curI);
        }
      }
      x.both += 1;
      x.val = x.val_worse;
    }
    x = y;
  }
  cout << min(min(x.onlyI, x.onlyD), x.both) << '\n';
  return 0;
}


Measured memory_bytes: 1024
// union-findぽい
// これunion-findじゃないな
#include <bits/stdc++.h>
typedef long long lint;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

int h,w;
string s[400];
bool visited[400][400];

// <black, white>
pair<lint,lint> dfs(int y, int x) {
    pair<lint,lint> res;
    if (visited[y][x]) return res;
    visited[y][x] = true;
    if (s[y][x] == '#') res.first ++;
    else res.second ++;
    int yc[] = {0,0,-1,1};
    int xc[] = {-1,1,0,0};
    rep(i,4) {
        int ny = y + yc[i];
        int nx = x + xc[i];
        if (0 <= ny and ny < h and 0 <= nx and nx < w) {
            if (s[y][x] != s[ny][nx]) {
                auto t = dfs(ny,nx);
                res.first += t.first;
                res.second += t.second;
            }
        }
    }
    return res;
}

int main() {
    cin >> h >> w;
    rep(i,h) cin >> s[i];
    lint ans = 0;
    rep(y,h) {
        rep(x,w) {
            if (not visited[y][x]) {
                auto p = dfs(y,x);
                ans += p.first * p.second;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 23856
#include <bits/stdc++.h>
#define FOR(i, k, n) for(int i = (k); i < (n); i++)
#define FORr(i, k, n) for(int i = (k); i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORr(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;
using ll = long long;

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

  vector<int> a(n);
  REP(i, n) cin >> a[i];

  ll sum = 0;
  REP(i, n) sum += a[i];

  set<ll> candidates;
  for(int i = 1; i*i <= sum; i++){
    if(sum % i == 0){
      candidates.insert(i);
      candidates.insert(sum/i);
    }
  }
  ll ans = 1;
  for(ll x : candidates){
    ll need;
    vector<ll> r(n);
    REP(i, n) r[i] = a[i] % x;
    sort(ALL(r));
    ll rSum = 0;
    REP(i, n) rSum += x - r[i];
    ll lSum = 0;
    need = 1e18;
    REP(i, n){
      lSum += r[i];
      rSum -= x - r[i];
      chmin(need, max(lSum, rSum));
    }
    if(need <= k) chmax(ans, x);
  }
  cout << ans << endl;
  return 0;
}

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

void solve()
{
	int b;
	while(cin >> b, b != 1)
	{
		bool flag[300001] = {false};
		int i = 1;
		cout << b << ":";
		while(true)
		{
			int x = 7 * i - 1;
			if(x > b)
			{
				break;
			}
			if(!flag[x] && b % x == 0)
			{
				cout << " " << x;
				for(int j = x; j <= b; j += x)
				{
					flag[j] = true;
				}
			}
			int y = 7 * i + 1;
			if(y > b)
			{
				break;
			}
			if(!flag[y] && b % y == 0)
			{
				cout << " " << y;
				for(int j = y; j <= b; j += y)
				{
					flag[j] = true;
				}
			}
			++i;
		}
		cout << endl;
	}
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 1460
# -*- coding:utf-8 -*-

"""解説
https://www.youtube.com/watch?v=5O4k1n5Ejzw

区間を考える問題

-30 -10 0 10 20 50

・K = 3のとき、

0座標を必ず含める、ある連続するK個のロウソクについて考える

・-30 -10 0 10
・-10 0 10 20
・0 10 20 50

左端と右端に到達する最小値を求めていけばよくて、間のロウソクは無視してよい（必ず移動中に火をつけるので）

すべての場合について求めて、その中の最小値が答え
"""
def solve():
    N, K = list(map(int, input().split()))
    X = list(map(int, input().split()))
    if 0 in X:
        # 0座標にロウソクがあるなら、火をつけるロウソクをひとつ減らしてよい
        K -= 1
    else:
        X.append(0)
    X.sort()

    origin_i = X.index(0)
    left_i = max(origin_i-K, 0)

    INF = 10**12
    ans = INF
    while left_i <= origin_i:
        if left_i+K < len(X):
            tmp1 = abs(X[left_i]-0)*2 + abs(X[left_i+K]-0)
            tmp2 = abs(X[left_i]-0) + abs(X[left_i+K]-0)*2
        else:
            break
        ans = min(ans, tmp1, tmp2)
        left_i += 1
    print(ans)

if __name__ == "__main__":
    solve()



Measured memory_bytes: 14252
#include <bits/stdc++.h>
using namespace std;
#define M 30005
#define N 105
int a[N];
int main()
{
    int ma=0,mi=0,sum=0,i,j,n,num=0,n1=0;
    string s;
    char t;
    cin>>n;
    cin>>s;
    for(i=0;i<n;i++)
    {
        if(s[i]=='(')
            a[i]=1;
        else a[i]=-1;
        sum+=a[i];
        mi=min(sum,mi);
        ma=max(sum,ma);
    }
        for(i=mi;i<0;i++)
        cout<<'(';
    cout<<s;
    for(i=0;i<sum-mi;i++)
    cout<<')';


    return 0;

}


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

int main()
{
    char a,b;
    cin>>a>>b;
    if(a=='H'&&b=='H')
        cout<<"H";
    else if(a=='H'&&b=='D')
        cout<<"D";
    else if(a=='D'&&b=='D')
        cout<<"H";
    else if(a=='D'&&b=='H')
        cout<<"D";
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <tuple>

using namespace std;

typedef tuple<int,int,int,int> edge;//<to,fee,hour,corp>
typedef tuple<int,int,int> T;//<cost,time,st>?´????????????????????????????????????????????????????

#define INF 1e8

struct vert{
    vector<edge> E;
};
vert St[100];
priority_queue<T, vector<T>, greater<T>> que;
int main(){
    int N,M,H,K;
    while(cin>>N>>M>>H>>K,N){
        for(auto& s:St)s.E.clear();
        for(int i=0;i<M;i++){
            int a,b,c,h,r;
            cin>>a>>b>>c>>h>>r;
            a--;b--;r--;
            St[a].E.emplace_back(b,c,h,r);
            St[b].E.emplace_back(a,c,h,r);
        }
        int S,T;
        cin>>S>>T;
        S--;T--;

        int P;
        cin>>P;
        int dp[256];
        fill(dp,dp+256,INF);
        dp[0]=0;
        for(int i=0;i<P;i++){
            int l,d;
            cin>>l>>d;
            int corp=0;
            for(int j=0;j<l;j++){
                int k;
                cin>>k;
                corp|=(1<<--k);//??????????????£?????????
            }
            for(int j=0;j<(1<<K);j++){
                dp[j|corp]=min(dp[j|corp],dp[j]+d);
            }
        }
        int minimum_cost[N][H+1];
        int ans=INF;
        for(int i=0;i<(1<<K);i++){
            if(dp[i]==INF)continue;
            fill(minimum_cost[0],minimum_cost[N],INF);
            que.emplace(0,0,S);
            while(!que.empty()){
                auto t=que.top();que.pop();
                int cost=get<0>(t), time=get<1>(t), st=get<2>(t);
                if(st==T){
                    while(!que.empty())que.pop();
                    ans=min(ans,cost+dp[i]);
                }
                if(minimum_cost[st][time]<cost) continue;
                for(auto& e:St[st].E){
                    int to=get<0>(e), fee=get<1>(e), hour=get<2>(e),corp=get<3>(e);
                    if(i&(1<<corp)){
                        fee=0;
                    }
                    if(time+hour>H)continue;
                    if(minimum_cost[to][time+hour]>cost+fee){
                        minimum_cost[to][time+hour]=cost+fee;
                        que.emplace(cost+fee,time+hour,to);
                    }
                }
            }
        }
        if(ans==INF){
            cout<<-1<<endl;
        }else{
            cout<<ans<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3212
n, p = map(int, input().split())
s = input()

ans = 0

d = {i:0 for i in range(p)}
d[0] = 1

ap = 1
if p not in [2, 5]:
    pre = 0
    for si in s[::-1]:
        si = int(si)
        a = (si * ap + pre) % p
        ans += d[a]
        d[a] += 1
        pre = a
        ap = (ap * 10) % p
else:
    for i, si in enumerate(s):
        if int(si) % p == 0:
            ans += i+1
print(ans)


Measured memory_bytes: 4072
#include<stdio.h>
#include<string.h>
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    scanf("%d",&n);
    int d[n];
    for(int i=0;i<n;i++)
        scanf("%d",d+i);
    sort(d,d+n);
    for(int i=n-1;i>0;i--)
    {
        if(d[i]==d[i-1])
        {
            for(int j=i-2;j>0;j--)
                if(d[j]==d[j-1])
            {
                long long a=(long long )d[i];
                long long b=(long long )d[j];
                printf("%lld\n",a*b);
                return 0;
            }
        }
    }
    printf("0\n");
    return 0;
}


Measured memory_bytes: 640
use io::*;

fn main() {
    let con =read_string();
    let mut sc =Scanner::new(&con);

    let a:i32 = sc.next();
    let b:i32 = sc.next();
    let c:i32 = sc.next();
    let d:i32 = sc.next();
    if a*b>c*d{
    println!("{}",a*b);
    }else{
    println!("{}",c*d);
    }
}

pub mod io {
    use std;
    use std::str::FromStr;
 
    pub struct Scanner<'a> {
        iter: std::str::SplitWhitespace<'a>,
    }
 
    impl<'a> Scanner<'a> {
        pub fn new(s: &'a str) -> Scanner<'a> {
            Scanner {
                iter: s.split_whitespace(),
            }
        }
 
        pub fn next<T: FromStr>(&mut self) -> T {
            let s = self.iter.next().unwrap();
            if let Ok(v) = s.parse::<T>() {
                v
            } else {
                panic!("Parse error")
            }
        }
 
        pub fn next_vec_len<T: FromStr>(&mut self) -> Vec<T> {
            let n: usize = self.next();
            self.next_vec(n)
        }
 
        pub fn next_vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
            (0..n).map(|_| self.next()).collect()
        }
    }
 
    pub fn read_string() -> String {
        use std::io::Read;
 
        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }
 
    pub fn read_line() -> String {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        s.trim_right().to_owned()
    }
}


Measured memory_bytes: 4352
import java.util.Scanner;

public class Main {

     static Scanner scanner;

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

         int N=gi();

         StringBuilder sb=new StringBuilder();
         for (int i=0;i<N;i++) {
             sb.append('a');
         }

         while(true) {
        	 if(sb.charAt(0)!='a')break;
        	 System.out.println(sb);
        	 for (int j=0; j<N;j++) {
        		 char c1= sb.charAt(N-j-1);
        		 char max='a';
        		 for (int k=0;k<N-j-1; k++) {
        			 char tc=sb.charAt(k);
        			 if(max<tc)max=tc;
        		 }
        		 if(c1<=max) {
        			 c1++;
        			 sb.setCharAt(N-j-1, c1);
        			 for (int k=N-j; k<N; k++) {
        				 sb.setCharAt(k, 'a');
        			 }
        			 break;
        		 }
        	 }
         }

         //System.out.println(sb);
     }

     // 文字列として入力を取得
     public static String gs() {
          return scanner.next();
     }

     // intとして入力を取得
     public static int gi() {
          return Integer.parseInt(scanner.next());
     }

     // longとして入力を取得
     public static long gl() {
          return Long.parseLong(scanner.next());
     }

     // doubleとして入力を取得
     public static double gd() {
          return Double.parseDouble(scanner.next());
     }
}

Measured memory_bytes: 56140
#include<bits/stdc++.h>
#define FAST_IO   ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define Relocate freopen("./in.txt","r",stdin);freopen("./out.txt","w",stdout)
#define up(mi,a,b) for(mi=a;mi<=b;++mi)
#define down(mi,b,a) for(mi=b;mi>=a;--mi)
#define mfill(a,v) memset(a,v,sizeof(a))
#define INF 0x3f3f3f3f
#define MAX 1005
#define v_n 5005
#define LL long long
#define e_n 5000005
#define MOD 1000000007
#define eps 0.000000001
#define Blen 32
using namespace std;
struct P {
	string name;
	int jc, id;
	bool operator<(P one)
	{
		if (name == one.name)
			return jc < one.jc;
		return name < one.name;
	}
};
vector<P > hh;
int main(void)
{
	int i, j, k;
	FAST_IO;
	//Relocate;
	int n;
	cin >> n;
	string name;
	up(i, 1, n)
	{
		cin >> name >> j;
		hh.push_back(P{ name, -j, i });
	}
	sort(hh.begin(), hh.end());
	up(i, 0, n-1)
	{
		cout << hh[i].id << endl;
	}
	return 0;
}

Measured memory_bytes: 256
<?php
  declare(strict_types=1);

  fscanf(STDIN, "%i", $n);
  $xs = explode(" ", trim(fgets(STDIN)));

  $solve = function () use ($n, $xs)
  {
      $s = array_sum($xs);
      $t = (int)(($n * $n + $n) / 2);
      if (($s % $t) !== 0)
      {
          return "NO";
      }
      
      $k = (int)($s / $t);
      $xs[-1] = $xs[$n - 1];
      for ($i = 0; $i < $n; $i++)
      {
          $d = $xs[$i] - $xs[$i - 1] - $k;
          if ($d > 0 || ($d % $n) !== 0)
              return "NO";
      }

      return "YES";
  };

  echo $solve().PHP_EOL;


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

int main()
{
	string s,t;
	cin>>s>>t;
	int cnt=0;
	for(int i=0;i<3;i++)
	{
		if(s[i]==t[i])
			cnt++;
	}
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 256