akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>

using namespace std;

int main(){

   int h, w;
   vector<int> v_h, v_w;

   cin >> h >> w;

   while(h != 0 && w != 0){
      v_h.push_back(h);
      v_w.push_back(w);

      cin >> h >> w;
   }

   for(int i = 0; i < v_h.size(); i++){
      for(int j = 0; j < v_h[i]; j++){
         for(int k = 0; k < v_w[i]; k++){
            if(j == 0 || j == v_h[i] - 1){
               cout << "#";
            }
            else{
               if(k == 0 || k == v_w[i] - 1){
                  cout << "#";
               }
               else{
                  cout << ".";
               }
            }
         }
         cout << endl;
      }
      cout << endl;
   }

   return 0;
}


Measured memory_bytes: 3108
import sys
stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)

i_i = lambda: int(i_s())
i_l = lambda: list(map(int, stdin.readline().split()))
i_s = lambda: stdin.readline().rstrip()

s = i_s()

ans = 0
for i in range(1<<(len(s)-1)):
    tmp = s[0]
    for j in range(len(s)-1):
        if i & 1 << j:
            tmp += '+'
        tmp += s[j+1]
    ans += eval(tmp)

print(ans)

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


int main()
{

	int n;
	cin >> n;
	int d[110];
	for (int i = 0; i < n; i++)
	{
		cin >> d[i];
	}
	set<int> v;
	for (int i = 0; i < n; i++)
	{
		v.insert(d[i]);
	}
	cout << v.size() << endl;
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func Scanner() string {
	sc.Scan()
	return sc.Text()
}

func intScanner() int {
	n, _ := strconv.Atoi(Scanner())
	return n
}

func floatScanner() float64 {
	n, _ := strconv.ParseFloat(Scanner(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func stringSliceScanner(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scanner()
	}
	return a
}
func intSliceScanner(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = intScanner()
	}
	return a
}

var mod int

func main() {
	mod = 1000000007
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	n := intScanner()
	as := make([]int, n)
	as[0] = intScanner()
	for i := 1; i < n; i++ {
		as[i] = intScanner() + as[i-1]
	}
	d := make(map[int]int)
	d[0]++
	for _, v := range as {
		d[v]++
	}
	ans := 0
	for _, v := range d {
		ans += v * (v - 1) / 2
	}
	fmt.Println(ans)
}


Measured memory_bytes: 14080
n, k = map(int, input().split())
scores = list(map(int, input().split()))
t = [0 if i=="r" else (1 if i=="s" else 2) for i in input()]

score = 0
no = [-1 for i in t]

for i, x in enumerate(t):
	if no[i] != x:
		score += scores[x-1]
		try:	
			no[i+k] = x
		except:
			pass
	
print(score)


Measured memory_bytes: 4796
#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
#include <numeric>
#include <string>
#include <cstring>
#include <list>
#include <unordered_set>
#include <tuple>
#include <cmath>
#include <limits>
#include <type_traits>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <set>
#include <bitset>
#include <regex>
#include <random>
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
#define rep(i,n)for(ll i=0;i<n;++i)
#define exout(x) printf("%.12f\n", x)
const double pi = acos(-1.0);
const ll MOD = 1000000007;
const ll INF = 1e18;
const ll MAX_N = 1010101;

//組み合わせの余りを求める
ll fac[MAX_N], finv[MAX_N], inv[MAX_N];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX_N; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

ll dx[8] = { 1,-1,0,0,1,1,-1,-1 };
ll dy[8] = { 0,0,1,-1,1,-1,1,-1 };
char c[2010][2010];
ll sum[2010][2010];
ll sum2[2010][2010];

//long longしか使わない
//素数は1より大きい
//lower_boundは指定したkey以上の要素の一番左のイテレータをかえす
//upper_boundは指定したkeyより大きい要素の一番左のイテレータをかえす
int main() {
	ll a, b;
	cin >> a >> b;
	string ans;
	if (a < b) {
		char res = '0' + a;
		rep(i, b)ans += res;
		cout << ans << endl;
	}
	else {
		char res = '0' + b;
		rep(i, a)ans += res;
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 3588
using System;
using System.Collections.Generic;

namespace ConsoleApp1
{
    class ABC178F
    {
        // https://atcoder.jp/contests/abc178/tasks/abc178_f

        const long m = 1000000007;
        static int[] A = new int[200001];
        static int[] B = new int[200001];

        static int[] CA = new int[200001];
        static int[] CB = new int[200001];

        static void Main(string[] args)
        {
            int N = Int32.Parse(Console.ReadLine());
            var itemsA = Console.ReadLine().Split();
            var itemsB = Console.ReadLine().Split();

            for (int i = 0; i < N; i++)
            {
                A[i] = Int32.Parse(itemsA[i]);
                B[i] = Int32.Parse(itemsB[i]);

                CA[A[i]] += 1;
                CB[B[i]] += 1;
            }

            for (int i = 1; i <= N; i++)
            {
                if (CA[i] + CB[i] > N)
                {
                    Console.WriteLine("No");
                    return;
                }
            }

            int max = 0;

            for (int i = 1; i <= N; i++)
            {
                CA[i] += CA[i - 1];
                CB[i] += CB[i - 1];

                max = Math.Max(max, CA[i] - CB[i - 1]);
            }

            Console.WriteLine("Yes");

            for (int i = 0; i < N - 1; i++)
            {
                int index = (i + N - max) % N;
                Console.Write(B[index] + " ");
            }

            int index2 = (N - 1 + N - max) % N;
            Console.WriteLine(B[index2]);
        }
    }
}


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

int main() {
    ll n;
    cin >> n;
    if (n % 2) {
        cout << 0 << endl;
        return 0;
    }
    ll res = 0;
    n /= 2;
    while (n) {
        res += n / 5;
        n /= 5;
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
// #pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define ll long long
#define S second
#define F first

using namespace std;

const ll N = 2e5 + 5, mod = 1e9 + 7;

int n;
char s[N];

int main()
{
    scanf("%s", s);
    n = strlen(s);
    int c = 0;
    for(int i = 0 ; i < n ; i++)
    {
        if(i and s[i] == s[i - 1]) s[i + 1] = '.';
        else c++;
    }
    printf("%d\n", c);
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2333;
const int MOD = 1000000007;
int a[MAXN], b[MAXN];
int dp[MAXN][MAXN];
int main()
{
	int n, m;
	cin >> n >> m;
	for (int i = 1; i <= n; i++)cin >> a[i];
	for (int i = 1; i <= m; i++)cin >> b[i];
	for (int i = 1; i <= n; i++)
		for  (int j = 1; j <= m; j++)
		{
            dp[i][j] = (dp[i-1][j] + dp[i][j-1]) - dp[i-1][j-1];
            if(a[i] == b[j]) dp[i][j] += dp[i-1][j-1] + 1;
            if (dp[i][j] < 0)dp[i][j] += MOD;
            if (dp[i][j] >= MOD)dp[i][j] %= MOD;
        }
	cout << (dp[n][m] + 1) % MOD << endl;
	return 0;
}


Measured memory_bytes: 18688
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
const ll INF = 1LL<<60;
const ll M = pow(10,9)+7;
/*template*/


int main()
{
  ll r;cin>>r;
  printf("%.20f",M_PI*2*r);
  return 0;
}


Measured memory_bytes: 3748
use std::io::{stdin, stdout, Read, Write};
fn main() {
    let mut buffer = Vec::new();
    let stdin = stdin();
    let mut handle = stdin.lock();
    handle.read_to_end(&mut buffer).unwrap();
    let mut outbuf = Vec::new();
    for &c in buffer.iter().step_by(2) {
        outbuf.push(c);
    }
    outbuf.push(b'\n');
    stdout().write(&outbuf).unwrap();
}


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

int main() {
	char c;
	cin>>c;
	if(c=='a' || c=='e' || c=='i' || c=='o'|| c=='u'){
		cout<<"vowel"<<endl;
	}else{cout<<"consonant"<<endl;}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define db long double
#define fi first
#define se second
#define  pb push_back
#define  pob pop_back
#define W while
#define fn(i,x) for(int i=0;i<x;i++)
#define fs(i,s,x) for(int i=s;i<x;i++)
#define fr(i,x) for(int i=x;i>=0;i--)
#define fit(it,s) for(auto it=s.begin();it!=s.end();it++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define mod 1000000007
#define MAX 1005
using namespace std;
int main()
{
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);

    // freopen("in.txt","r",stdin);
    // freopen("out.txt","w",stdout);
    
    string g;
    cin >> g;
    int a = (g[0]-'0')*10 + (g[1]-'0');

    int b = (g[2]-'0')*10 + (g[3]-'0');
    if((b ==0 or b>12) and (a==0 or a>12)){
        cout <<"NA";
    }
    else if(b ==0 or b>12){
      cout << "MMYY";
    }
    else if(a==0 or a>12) {
      cout << "YYMM";
    }
    else cout <<"AMBIGUOUS";
    return 0;

}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long LL;
const LL INF = 0x3f3f3f3f3f3f3f3f;

struct node{
	LL h,p;
}s[5005];
bool cmp(node x,node y){
	return x.h + x.p < y.h + y.p;
}

LL n;
LL dp[5005];

int main(){
	cin >> n;
	for(LL i = 1;i <= n;i ++) cin >> s[i].h >> s[i].p;
	sort(s + 1,s + 1 + n,cmp);
	
	memset(dp,INF,sizeof(dp)); dp[0] = 0;
	for(LL i = 1;i <= n;i ++){
		for(LL j = i;j >= 1;j --){
			if(dp[j - 1] <= s[i].h) dp[j] = min(dp[j],dp[j - 1] + s[i].p);
		}
	}
	for(LL i = n;i >= 0;i --){
		if(dp[i] < INF){
			cout << i << endl;
			break;
		}
	}
	return 0;
}
//

Measured memory_bytes: 384
#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;

int main()
{
	double a, b, c;
	double s, l, h;
	
	cin >> a >> b >> c;
	
	s=0.5*a*b*sin((M_PI/180)*c);
	l=a+b+sqrt(a*a+b*b-(2*a*b*cos((M_PI/180)*c)));
	h=2*s/a;
	
	cout << fixed << setprecision(4) << s << endl;
	cout << fixed << setprecision(4) << l << endl;
	cout << fixed << setprecision(4) << h << endl;
	
	return 0;
}

Measured memory_bytes: 1284
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main(){
    ll n, in, min;
    cin >> n;
    min = 100000;
    rep(i, n){
        int k = 0;
        cin >> in;
        while(in%2 == 0){
            in /= 2;
            k++;
        }
        if(min > k) min = k;
    }
    cout << min << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int d,e,i;
	scanf("%d%d",&d,&e);
	int a=d+e;
	int b=d-e;
	int c=d*e;
	if(a<b){i=a; a=b; b=i;}
	if(b<c){i=b; b=c; c=i;}
	if(a<b){i=a; a=b; b=i;}
	printf("%d\n",a);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef tuple<int, int, int> tp;
typedef long long LL;
typedef long double LD;
typedef pair<int, int> pii;
typedef pair<int, LL> pil;
typedef pair<LL, int> pli;
typedef pair<LL, LL> pll;
typedef pair<pii, int> piipi;
typedef pair<int, pii> pipii;
typedef pair<pii, pii> piipii;
typedef pair<LL, pii> plpii;
typedef pair<LD, LD> pdd;
typedef pair<LD, int> pdi;
typedef pair<LD, LL> pdl;
typedef pair<int, LD> pid;
typedef pair<LL, LD> pld;
const int mod = 1e9 + 7;
const int hf = 999983;
const int N = 1e6;
int dp[1<<21][21], n;
int a[25][25];
int dfs(int i, int x){
    if(x == n) return 1;
    if(dp[i][x] != -1) return dp[i][x];
    int ans = 0;
    for(int y=0;y<n;y++){
        if(!a[x][y] || ((i>>y)&1)) continue;
        ans = (ans + dfs(i|(1<<y), x+1))%mod;
    }
    return dp[i][x] = ans;
}
int main(){
    memset(dp, -1, sizeof(dp));
    scanf("%d", &n);
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            scanf("%d", &a[i][j]);
        }
    }
    printf("%d\n", dfs(0, 0));
}


Measured memory_bytes: 172288
/** "Ever tried.
         Ever failed.
               No matter.
                   Try Again.
                        Fail again.
                             Fail better.**/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define ll long long
#define bp  __builtin_popcount
#define endl "\n"
#define oo 0x3f3f3f3f3f3f3f3fLL
#define pb push_back
#define loop(i,n) for(int i = 0;i < int(n);i++)
#define range(i,a,b) for(int i = int(a);i <= int(b);i++)
#define sz(s) (int)(s.size())
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define debug(x) cout<<" LOOK "<<(#x)<<" = "<<x <<'\n'
#define NumofDigits(n)   ((long long)log10(n)+1)

using namespace std;
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;
const int maxn=1e5+5;
const  double EPS = 1e-9;
const int MOD = 1e9+7;
/*
ll gcd(ll a, ll b) { return !b ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
ll fastpow(ll b, ll p)
{if(!p)return 1;ll ret = fastpow(b, p >> 1);ret *= ret;if(p&1)ret*= b;return ret;}
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};*/
inline void File()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
#endif
}


int main()
{
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    File();
    ll x, k, d;
    cin >> x >> k >> d;
    if (x < 0)
        x = -x;
    if (x / d >= k)
        cout << x - k * d;
    else if ((k - x / d) % 2 == 0)
        cout << x % d;
    else
        cout << d - x % d;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;

int main() {
	ll a;
	cin >> a;
	vector <ll> arr;
	arr.resize(a);
	for (int x=0;x<a;x++){
		cin >> arr[x];
	}
	sort(arr.begin(),arr.end());
	
	if (arr[(a/2)-1]==arr[(a/2)]) {
		cout << 0;
		return 0;
	} 
	ll temp1=arr[(a/2)-1];
	ll temp2=arr[(a/2)];
	cout << temp2-temp1;


}	


Measured memory_bytes: 1152
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>//sort,reverse
#include<utility>//pair
#include<queue>//queue,priority_queue
#include<deque>//double_ended queue
using namespace std;
typedef pair<int,int> P;//Pでpair<-,->を表す。
typedef long long LL; 
LL MOD=1000000007;
#include<cmath>//三角関数,逆三角関数,絶対値,ルート、累乗など(これ以外を使うこともないだろう)
#include<iomanip>//不動小数点表示精度の調整
int main()
{ 
  	cout<<setprecision(15);
    int n;
    int k;
    cin>>n>>k;
    LL a[n];
    LL b[n-k+1];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=0;i<n-k+1;i++){
        b[i]=0;
        if(i==0){
            for(int j=0;j<k;j++){
                b[0]=b[0]+a[j];
            }
        }
        else{b[i]=b[i-1]-a[i-1]+a[k+i-1];}
    }
    sort(b,b+n-k+1);
    double x;
    x=(b[n-k]+k)/2.0;
    cout<<x<<endl;
    return 0;
}


Measured memory_bytes: 3328
/*
	submission # - User: herp_sy
	https://atcoder.jp/contests/
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <stdbool.h>

#define _CRT_SECURE_NO_WARNINGS
#define TLong long long
#define TBMod 1000000007

TLong v[5003][5003];
TLong nCr(TLong n, TLong r){
	for(TLong i = 0; i <= n; ++i){
		for(TLong j = 0; j <= i; ++j){
			if(j == 0)  v[i][j] = 1;
			else  v[i][j] = v[i - 1][j - 1] + v[i - 1][j];
		}
	}
	return v[n][r];
}

int main(int argc, char const *argv[])
{
	TLong n,p,a[50];
	TLong ans = 0;
	TLong odd = 0,even = 0;
	scanf("%lld%lld",&n,&p);
	for (TLong i = 0; i < n; ++i){
		scanf("%lld",&a[i]);
		if(a[i] % 2)	++odd;
		else ++even;
	}
	if(p){	// p = 1
		for (TLong i = 1; i <= odd; i += 2)
		{
			for (TLong j = 0; j <= even; ++j)	ans += nCr(odd, i) * nCr(even, j);
		}
	}
	else{	// p = 0
		for (TLong i = 0; i <= odd; i += 2)
		{
			for (TLong j = 0; j <= even; ++j)	ans += nCr(odd, i) * nCr(even, j);
		}
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 384
N,K = map(int,input().split())
R,S,P = map(int,input().split())
T = input()
points = {'r':R, 's':S, 'p':P}
win = {'r':'p', 's':'r', 'p':'s'}

batch = [T[i::K] for i in range(K)]

ans = 0
for b in batch:
    tmp = 0
    for p in 'rsp':
        t = 0
        before = p
        if p == win[b[0]]: t += points[win[b[0]]]
        for i in range(1,len(b)):
            if win[b[i]] != before:
                t += points[win[b[i]]]
                before = win[b[i]]
            else:
                if i+1 < len(b):
                    before = b[i+1]
        if t > tmp: tmp = t
    ans += tmp
print(ans)

Measured memory_bytes: 8820
#include <iostream>
#include <sstream>
#include <cstdio>
#include <stdlib.h>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int bubblesort(vector<int> &A,int n){
  bool flag=1;
  int cnt = 0;
  while(flag){
    flag=0;
    for(int j=n-1;j>0;j--){
      if(A[j]<A[j-1]){
	swap(A[j],A[j-1]);
	flag=1;
	cnt++;
      }
    }
  }
  return cnt;
}

int main(){
  vector<int>a;
  int n,cnt,i;
  cin>>n;
  for (i=0;i<n;i++){
    cin>>cnt;
    a.push_back(cnt);
  }
  cnt=bubblesort(a,n);
  for(i=0;i<n-1;i++)
    cout<<a[i]<<" ";
  cout<<a[i]<<endl<<cnt<<endl;
  return 0;
}



Measured memory_bytes: 3164
#include <bits/stdc++.h>
#define INF 2e9
using namespace std;
typedef long long llong;
typedef long double ldouble;
int main()
{
  int N;
  cin >> N;
  vector<int> P(N);
  for(int i=0; i<N; ++i) cin >> P.at(i);
  int MIN=N+1;
  int ans=0;
  for(int i=0; i<N; ++i){
    if(MIN >= P.at(i)){
      MIN = P.at(i);
      ++ans;
    }
  }
  cout << ans << endl;
}

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

int main(){
  long long int n,k=10,kotae=0;
  cin>>n;
  if(n%2==1){
    cout<<0;
    return 0;
  }
  for(;k<=n;k*=5){
    kotae+=n/k;
  }
  cout<<kotae;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
import copy

class trump:
    def __init__(self, s):
        self.name = s
        s = list(s)
        self.value = int(s[1])

N=int(input())
C = list(map(trump, input().split()))
C_copy = C.copy()

def BubbleSort(A,N):
    for i in range(N):
        for j in reversed(range(i+1,N)):
            if A[j].value < A[j-1].value:
                A[j],A[j-1]=A[j-1],A[j]
    for i in range(N):
        if i==N-1:
            print(A[i].name)
        else:
            print(A[i].name,end=" ")
    print("Stable")

def SelectionSort(A,N):
    for i in range(N):
        minj=i
        for j in range(i,N):
            if A[j].value<A[minj].value:
                minj=j
        A[i],A[minj]=A[minj],A[i]
    for i in range(N):
        if i==N-1:
            print(A[i].name)
        else:
            print(A[i].name,end=" ")
    if C==C_copy:
        print("Stable")
    else:
        print("Not stable")
        
BubbleSort(C,N)
SelectionSort(C_copy,N)



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

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define REP(i, n)  FOR(i, 0, n)
#define ASC(c) sort((c).begin(), (c).end())
#define DESC(c) sort((c).begin(), (c).end(), greater<int>())

#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define DEBUG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

typedef long long ll;
typedef unsigned long long ull;
struct edge { int u, v; ll w; };
 
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
    int n; cin >> n;
    vector<int> d(n);
    REP(i, n) cin >> d[i];
    ll ans = 0;
    for (int i = 0; i < n - 1; i++) {
        for (int k = i + 1; k < n; k++) {
            ans += d[i] * d[k];
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs= sys.stdin.buffer.readlines
#rstrip().decode('utf-8')

#import math
import numpy as np
#import operator
#from heapq import heapify,heappop,heappush
#from math import gcd
#from fractions import gcd
#from collections import deque
#from collections import defaultdict
#from collections import Counter
#from itertools import accumulate
#from itertools import groupby
#from itertools import permutations
#from itertools import combinations
#from scipy.sparse import csr_matrix
#from scipy.sparse.csgraph import floyd_warshall
#from scipy.sparse.csgraph import csgraph_from_dense
#from scipy.sparse.csgraph import dijkstra
#sys.setrecursionlimit(10**7)

#map(int,input().split())

def main():
	N,K=map(int,input().split())
	AF=np.array(read().split(),np.int64)
	A,F=np.split(AF,2)
	A.sort()
	F.sort()
	F=F[::-1]
	
	lt=0
	rt=10**12+1
	
	Asum=A.sum()
	
	while rt-lt>1:
		mid=(rt+lt)//2
		if Asum-np.minimum(A,mid//F).sum()<=K:
			rt=mid
		else:
			lt=mid
	print(rt if Asum-K>0 else 0)
	
if __name__ == '__main__':
	main()

Measured memory_bytes: 35620
def partition(a, left, right)
  x = a[right]
  i = left-1
  left.upto(right-1) do |j|
    if a[j] <= x
      i += 1
      a[i], a[j] = a[j], a[i]
    end
  end
  a[i+1], a[right] = a[right], a[i+1]
  i+1
end

N = gets.to_i
A = gets.split.map(&:to_i)
q = partition(A, 0, N-1)
A[q] = "[#{A[q]}]"

puts A.join(" ")



Measured memory_bytes: 13956
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>
#include <map>
#include <list>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>

// #define cerr if(false)cerr
#define watch(x) cerr << "> " << #x << ": " << x << "\n";

using namespace std;

template <typename T>
std::ostream &operator <<(std::ostream &out, vector<T> &v) {
	for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
		out << v[i] << " ";
	out << "\n";
    return out;
}
template <typename T, typename N>
std::ostream &operator <<(std::ostream &out, vector<pair<T, N> > &v) {
	for (size_t i = 0; i < v.size(); ++i)
		out << "(" << v[i].first << ", " << v[i].second << ") ";
	out << "\n";
    return out;
}
template <typename T>
std::ostream &operator <<(std::ostream &out, vector<vector<T> > &v) {
	for (size_t i = 0; i < v.size(); ++i) {
		for (size_t j = 0; j < v[i].size(); ++j) {
			out << v[i][j] << " ";
		}
		out << "\n";
	}
   	return out;
}

int main() {

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

	int n;
	cin >> n;

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

	string x;
	cin >> x;

	int i = 0;
	while (i < n && songs[i] != x) {
		++i;
	}

	int total_time = 0;
	for (int j = i + 1; j < n; ++j) {
		total_time += time[j];
	}

	cout << total_time << "\n";

	return 0;

}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main(void)
{
    long long int a,b;
    cin >> a >> b;
    long long int i;
    for(i=min(a,b);i>=1;i--)
        if(a%i==0 && b%i==0)
            break;
    cout << a*b/i;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define SORT(v) sort(v.begin(), v.end());
#define RSORT(v) sort(v.rbegin(), v.rend());
#define REVERSE(v) reverse(v.begin(), v.end());

template <typename T>
void printlnVector(T v)
{
    rep(i, v.size())
    {
        cout << v[i] << endl;
    }
}

template <typename T>
void printVector(T v)
{
    rep(i, v.size())
    {
        cout << v[i] << " ";
    }
    cout << endl;
}

struct WeightedUnionFind
{
    vector<pair<int, int>> d;
    WeightedUnionFind(int n = 0) : d(n, make_pair(-1, 0)) {}
    int find(int x)
    {
        if (d[x].first < 0)
            return x;

        int r = find(d[x].first);
        d[x].second += d[d[x].first].second;
        return d[x].first = r;
    }
    bool unite(int x, int y, int l)
    {
        l = dist(x) + l - dist(y);
        x = find(x);
        y = find(y);
        if (x == y)
            return false;
        if (d[x].first > d[y].first)
        {
            swap(x, y);
            l *= -1;
        }
        d[x].first += d[y].first;
        d[y].first = x;
        d[y].second = l;
        return true;
    }
    bool same(int x, int y) { return find(x) == find(y); }
    int size(int x) { return -(d[find(x)].first); }
    int dist(int x)
    {
        find(x);
        return d[x].second;
    }
    int diff(int x, int y) { return dist(y) - dist(x); }
};

int main()
{
    int N, M;
    cin >> N >> M;
    WeightedUnionFind uf(N);
    bool is_ok = true;
    rep(i, M)
    {
        int L, R, D;
        cin >> L >> R >> D;
        --L;
        --R;
        if (uf.same(L, R))
        {
            if (uf.diff(L, R) != D)
                is_ok = false;
        }
        else
        {
            uf.unite(L, R, D);
        }
    }

    printYesNo(is_ok);
    return 0;
}


Measured memory_bytes: 1024
import java.util.*;

public class Main {
    static Scanner sc = new Scanner(System.in);
    public static void main(String[] args) {
        int n = sc.nextInt();
        UnionFind uf = new UnionFind(n);
        int m = sc.nextInt();
        int[] a = new int[m];
        int[] b = new int[m];
        for(int i = 0; i < m; ++i) {
            a[i] = sc.nextInt() - 1;
            b[i] = sc.nextInt() - 1;
        }
        
        long[] ans = new long[m];
        for(int i = m - 1; i >= 0; --i) {
            if(i == m - 1) {
                ans[i] = 1L * n * (n - 1) / 2;
                continue;
            }
            
            if(uf.isSameSet(a[i + 1], b[i + 1])) ans[i] = ans[i + 1];
            else ans[i] = ans[i + 1] - 1L * uf.getSameSetNum(a[i + 1]) * uf.getSameSetNum(b[i + 1]);
            
            uf.unite(a[i + 1], b[i + 1]);
        }
        
        for(int i = 0; i < m; ++i) System.out.println(ans[i]);
    }
}

class UnionFind {
    int[] roots;
    int[] sameSetCnt;
	
	public UnionFind(int N) {
		roots = new int[N];
		sameSetCnt = new int[N];
		for(int i = 0; i < N; ++i) {
		    roots[i] = i;
		    sameSetCnt[i] = 1;
		}
	}
	
	int getRoot(int x) {
		if(roots[x] == x) return x;
		else return roots[x] = getRoot(roots[x]);
	}
	
	boolean isSameSet(int x, int y) {
		return getRoot(x) == getRoot(y);
	}
	
	void unite(int x, int y) {
	    int rx = getRoot(x);
	    int ry = getRoot(y);
	    if(rx == ry) return;
	    
	    if(sameSetCnt[rx] < sameSetCnt[ry]) {
	        int tmp = rx;
	        rx = ry;
	        ry = tmp;
	    }
	    
	    sameSetCnt[rx] += sameSetCnt[ry];
	    roots[ry] = rx;
	}
	
	int getSameSetNum(int i) {
	    return sameSetCnt[getRoot(i)];
	}
}

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


int main() {
  int a, b, c, d, x, y;
  cin >> a >> b >> c >> d;
  x = 0;
  y = 0;
  while (a > 0){
    a -= d;
    ++x;
  }
  while (c > 0){
    c -= b;
    ++y;
  }
  if(x >= y) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3636
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<vector>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#define ll long long
#define F(i,a,b) for(int i=(a);i<=(b);i++)
#define mst(a,b) memset((a),(b),sizeof(a))
#define PII pair<int,int>
#define rep(i,x,y) for(auto i=(x);i<=(y);++i)
#define dep(i,x,y) for(auto i=(x);i>=(y);--i)
using namespace std;
template<class T>inline void rd(T &x) {
    x=0; int ch=getchar(),f=0;
    while(ch<'0'||ch>'9'){if (ch=='-') f=1;ch=getchar();}
    while (ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
    if(f)x=-x;
}
const int inf=0x3f3f3f3f;
ll n,k;
int main()
{
    cin>>n>>k;
    ll temp=n%k;
    cout<<min(temp,abs(temp-k))<<endl;
    return 0;
}

Measured memory_bytes: 256
<?php
  fscanf(STDIN, "%d", $N);
for ($i = 1;$i <= 9 ; $i++) {
   if ($N %$i == 0 && $N/$i < 10) {
        $ans ='Yes';
        break;
    }else{
        $ans ='No'; 
   }
}
echo $ans;
  ?>

Measured memory_bytes: 3828
import re
class c(int):
 def __add__(self,n):return c(int(self)+int(n))
 def __sub__(self,n):return c(int(self)-int(n))
 def __mul__(self,n):return c(int(self)*int(n))
 def __truediv__(self,n):return c(int(int(self)/int(n)))
for _ in[0]*int(input()):print(eval(re.sub(r'(\d+)',r'c(\1)',input()[:-1])))


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

using namespace std;

int main() {
    long long int a, b, c, d;
    vector<long long int> res;
    ios::sync_with_stdio(false);
    
    cin >> a >> b >> c >> d;

    res.push_back(a * c);
    res.push_back(b * d);
    res.push_back(b * c);
    res.push_back(a * d);

    auto max = max_element(res.begin(), res.end());
    auto dist = distance(res.begin(), max);

    cout << res[dist];
    return 0;
}

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

char **s;
int m,n,o,set[10] = {63,6,91,79,102,109,125,39,127,111};

void IntToBinary(int a, char *s){
	int b = a;
	for(int i=6; i>=0; i--){
		if(b >= pow(2.0,i)){
			b -= pow(2.0,i);
			s[6-i] = '1';
		}else
			s[6-i] = '0';
	}
	s[7] = '\0';
}

int main(){
	while(true){
		std::cin >> n;
		if(n == -1)
			return 0;
		s = new char*[n];
		for(int i=0; i<n; i++)
			s[i] = new char[8];
		std::cin >> m;
		IntToBinary(set[m], s[0]);
		for(int i=1; i<n; i++){
			std::cin >> o;
			IntToBinary(set[m]^set[o], s[i]);
			m = o;
		}
		for(int i=0; i<n; i++){
			std::cout << s[i] << std::endl;
			delete[] s[i];
		}
		delete[] s;
	}
}

Measured memory_bytes: 0
package main

import (
    "fmt"
    "strings"
)

func main() {
    var n int 
    fmt.Scan(&n)
    s := make([]string, n)
    for i := 0; i < n; i++ {
        fmt.Scan(&s[i])
    }   

    var res []byte
    for _, ch := range []byte("abcdefghijklmnopqrstuvwxyz") {
        min := int(^uint(0) >> 1)
        for i := range s { 
            cnt := strings.Count(s[i], string(ch))
            if cnt < min {
                min = cnt 
            }   
        }   
        for i := 0; i < min; i++ {
            res = append(res, ch) 
        }   
    }   

    fmt.Println(string(res))
}  


Measured memory_bytes: 640
#include<stdio.h>
#include<string.h>
#include<iostream>
#include <fstream>
using namespace std;

#define N	50001
#define M	20
#define	INIT	(N+1)
int	m = M;
int	 d[M];
int	counts[N];
void compute(int k);

inline int getC(int k)
{
	if (counts[k] == INIT)
		compute(k);
	return	counts[k];
}

void compute(int k)
{
	counts[k] = k;
	for (int i = 0; i < m; ++i)
	{
		if (k < d[i]){
			continue;
		}
		int count = 1 /*d[i]の分*/ + getC(k - d[i]);
		if (count < counts[k]){
			counts[k] = count;
		}
	}
}

int main(){
	std::istream & c_in = cin;
	memset(d, 0, sizeof(d));
	for (int i = 0; i < N; ++i)counts[i] = INIT;

	int n;
	c_in >> n >> m;
	for (int i = 0; i < m; i++){
		c_in >> d[i];
	}
	printf("%d\n",getC(n));
    return 0;
}

Measured memory_bytes: 3680
#include <bits/stdc++.h>
 
#define endl '\n'
#define fi first
#define se second
#define MOD(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,n) for (int i = 0; i < n; i++)
#define forr(i,a,b) for (int i = a; i <= b; i++)
#define all(v) v.begin(), v.end()
#define pb push_back
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<ii> vii;

int n, m, a, b;

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

	cin >> n >> m >> a >> b;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++)
			if ((i < b) == (j < a))
				cout << 1;
			else 
				cout << 0;
		cout << endl;
	}

	return 0;
}


Measured memory_bytes: 1280
import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = println(solve(new Scanner(System.in)))

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

  def solve(sc: Scanner): String = {
    val N = sc.nextInt
    val K = sc.nextInt
    val A = Array.fill(N)(sc.nextInt)

    var ans = 0
    var n = N
    while (n > K) {
      ans += (n / K)
      n = (n / K) + (n % K)
    }
    if (n > 1) ans += 1
    ans.toString
  }
}


Measured memory_bytes: 51820
#include<iostream>
#include<iomanip>
#include<queue>
#include<string>
#include<stack>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<cassert>
#include<ctime>
#include<algorithm>
#include<utility>
#include<map>
#include<set>
#include<vector>
#include<functional>

using namespace std;

#ifdef DEBUG
#define dprintf      printf
#define dout(x)      cout<<#x" = "<<(x)<<endl
#define darray(x,n)  {int i;rep(i,n)cout<<#x"["<<i<<"] = "<<*((x)+i)<<endl;}
#define dloop(i,s,g) for(int (i)=(s);(i)<(g);(i)++)
#define drep(i,n)    for(int (i)=0;(i)<(n);(i)++)
#define dstop()      scanf("%*c")
#else
#define dprintf      (1)?0:printf
#define dout(x)
#define darray(x,n)
#define dloop(i,s,g) if(int i=0){}else
#define drep(i,n)    if(int i=0){}else
#define dstop()      scanf("")
#endif

#define F    first
#define S    second
#define pb   push_back
#define mp   make_pair

#define loop(i,s,g) for(int (i)=(s);(i)<(g);(i)++)
#define rep(i,n)    for(int (i)=0;(i)<(n);(i)++)
#define all(x)      (x.begin(),x.end())
#define in(T,...) T __VA_ARGS__; impl(__VA_ARGS__);
#define array(T,id,n) T id[n]; rep(i,n)cin>>id[i];

//#define int long long;
#ifndef int
#define INF (0x7fffffff)
#else
#define INF (0x7fffffffffffffff)
#endif

typedef  long long           ll;
typedef  unsigned            ui;
typedef  unsigned long long  ull;
typedef  pair<int,int>       i_i;
typedef  pair<ll,int>        ll_i;
typedef  pair<ll,ll>         ll_ll;
typedef  pair<double,int>    d_i;
typedef  pair<double,double> d_d;

void impl(){};
template <typename T,typename... TS >
void impl(T &head,TS &... tail)
{
  cin>>head;
  impl(tail ...);
}

signed main(void)
{
  char s[112345]={};
  scanf("%s",s);
  int i;
  int n=strlen(s);
  for(i=0;i<n;i+=2)
    putchar(s[i]);
  puts("");


  return 0;
}


Measured memory_bytes: 384
N = int(input())
A = []
D, X = map(int, input().split())
for i in range(N):
    A.append(int(input()))

cnt = 0
for i in range(N):
    day = 1
    while True:
        if day > D:
            break
        cnt += 1
        #print(day)
        day += A[i]

print(cnt + X)


Measured memory_bytes: 3060
class UnionFind():
    def __init__(self,n):
        self.n = n
        
        # parents が負の時は要素数
        # parents が正の時は親の番号
        self.parents = [-1] * n
 
    # xの根を求める
    def find(self,x):
        if self.parents[x] < 0:
            return x
        else:
            # 根を再帰的に求める
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
 
    # xとyを併合する
    def union(self,x,y):
        x = self.find(x)
        y = self.find(y)
 
        # 根が同じ場合はreturn
        if x == y:
            return
 
        # ランクを考慮（要素数の少ない木を要素数の多い木に併合）
        if self.parents[x] > self.parents[y]:
            x,y = y,x
 
        self.parents[x] += self.parents[y]
        self.parents[y] = x
 
    # xの木の要素数を求める
    def size(self,x):
        return - self.parents[self.find(x)]
 
    # xとyが同じ木なのか確かめる
    def same(self,x,y):
        return self.find(x) == self.find(y)
 
 
n, m, k = (int(x) for x in input().split())

uf = UnionFind(n)
n_find = [0] * n

for i in range(m):
    a, b = (int(x) for x in input().split())

    a -= 1
    b -= 1

    n_find[a] += 1
    n_find[b] += 1
    uf.union(a, b)

ans = [uf.size(i) -1 - n_find[i] for i in range(n)] 

for i in range(k):
    c, d = (int(x) for x in input().split())

    c -= 1
    d -= 1

    if uf.same(c, d):
        ans[c] -= 1
        ans[d] -= 1

print(*ans)


Measured memory_bytes: 14108
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using f80 = __float80;
constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
#define _overload3(_1,_2,_3,name,...) name
#define repi(i,start,end) for(i64 i=(start);i<(end);++i)
#define _rep(i,n) repi(i,0,n)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,start,end) for(i64 i=(start);i>end;--i)
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define v(T) vector<T>
#define vv(T) v(v(T))
typedef v(i64) vi;
typedef v(vi) vvi;
template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
static const int dy[4] = {0,1,0,-1}, dx[4] = {1,0,-1,0};

void Main()
{
  i64 X, Y, A, B, C;
  cin >> X >> Y >> A >> B >> C;

  vi P(A), Q(B), R(C);
  cin >> P >> Q >> R;

  sort(P.rbegin(),P.rend());
  sort(Q.rbegin(),Q.rend());

  while(P.size() > X) P.pop_back();
  while(Q.size() > Y) Q.pop_back();

  vi con{P};
  for(auto &p: Q) con.emplace_back(p);
  for(auto &p: R) con.emplace_back(p);

  sort(con.rbegin(),con.rend());
  while(con.size() > X+Y) con.pop_back();
  cout << accumulate(con.begin(),con.end(),0LL) << endl;
}

int main()
{
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}



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

int main() {
  int A, B;
  string S;
  cin >> A >> B >> S;
  bool ans = true;
  for (int i = 0; i < S.size(); ++i) {
    if (i < A && isdigit(S.at(i))) {
      continue;
    }
    if (i == A && S.at(i) == '-') {
      continue;
    }
    if (i > A && i <= A + B && isdigit(S.at(i))) {
      continue;
    }
    ans = false;
    break;
  }
  if (ans) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
fn main() {
    let mut n = read::<u64>();
    let count = (n / 11) * 2;
    n %= 11;
    let ans = match n {
        0 => count,
        1...6 => count + 1,
        _ => count + 2,
    };
    println!("{}", ans);
}

#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 4352
S = [int(x) for x in list(input())]
K = int(input())
flag = True; i = 0
while flag:
    if S[i] == 1:
        if K == 1:
            print(1)
            flag = False
        else:
            i += 1
            K -= 1
    else:
        print(S[i])
        flag = False

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

using namespace std;
using ll = long long;

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

  int k;
  cin >> k;

  vector<ll> runrun;
  for (ll i = 1; i <= 9; i++)
    runrun.push_back(i);

  int max_k = 1e5;
  int cnt = 9;
  function<void(ll, int)> dfs = [&](ll n, int depth) -> void {
    if (cnt >= max_k)
      return;
    if (depth == 0) {
      runrun.push_back(n);
      cnt++;
      return;
    }
    int cur = n % 10;
    for (int i = -1; i <= 1; i++) {
      if (cur + i < 0 || cur + i > 9)
        continue;
      dfs(n * 10 + (cur + i), depth - 1);
    }
  };
  for (int i = 1; cnt < max_k; i++) {
    for (int j = 1; j <= 9; j++)
      dfs(j, i);
  }
  cout << runrun[k - 1] << endl;

  return 0;
}


Measured memory_bytes: 4240
'''
Rjの最小値を保持することで最大利益の更新判定をn回で終わらせる
'''

r = []

n = int(input())
for i in range(n):
    i = int(input())
    r.append(i)

minv = r[0]
maxv = r[1] - r[0]

for j in range(1,n):
    maxv = max(maxv, r[j]-minv)
    minv = min(minv, r[j])

print(maxv)



Measured memory_bytes: 13592
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
static const double EPS = 1e-8;
typedef long long ll;

int main()
{
	int r, c, q;
	static int a[50000], b[50000], order[50000];
	int used_rows, used_columns;
	static bool used_row[50000], used_column[50000];

	while (scanf("%d%d%d", &r, &c, &q), r || c || q)
	{
		for (int i = 0; i < q; ++i)
			scanf("%d%d%d", a+i, b+i, order+i);

		used_rows = used_columns = 0;
		fill(used_row, used_row + r, false);
		fill(used_column, used_column + c, false);
		ll res = 0;
		for (int i = q-1; i >= 0; --i)
		{
			if (a[i] == 0)
			{
				if (order[i] && !used_row[b[i]])
					res += c - used_columns;
				if (!used_row[b[i]])
					++used_rows;
				used_row[b[i]] = true;
			}
			else
			{
				if (order[i] && !used_column[b[i]])
					res += r - used_rows;
				if (!used_column[b[i]])
					++used_columns;
				used_column[b[i]] = true;
			}
		}
		printf("%lld\n", res);
	}
	
	return 0;
}

Measured memory_bytes: 1560
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")


def main():
    X = int(input())
    
    B = 0
    while B**5 < X:
        B += 1
    B *= -1
    for A in range(10**6):
        while A**5 - B**5 > X:
            B += 1
        if A**5 - B**5 == X:
            print(str(A) + " " + str(B))
            return
    


if __name__ == '__main__':
    main()

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

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

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

int N, A[200100], C[200100];

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

  std::cin >> N;

  for(int i=2;i<=N;++i){
      std::cin >> A[i];
      C[A[i]] += 1;
  }

  for(int i=1;i<=N;++i){
      std::cout << C[i] << std::endl;
  }
}


Measured memory_bytes: 5144
#include <stdio.h>

/** Application main entry point. */
int
main (
  int     argc,
  char  * argv[ ]
  )
{
  for ( ; ; )
  {
    char r = 'A';
    int  s;
    int  s1, s2;

    scanf ( "%d%d", &s1, &s2 );
    if ( !( s1 | s2 ) ) break ;
    s = s1 + s2;

    scanf ( "%d%d", &s1, &s2 );
    if ( s1 + s2 > s ) { r = 'B'; s = s1 + s2; }
    scanf ( "%d%d", &s1, &s2 );
    if ( s1 + s2 > s ) { r = 'C'; s = s1 + s2; }
    scanf ( "%d%d", &s1, &s2 );
    if ( s1 + s2 > s ) { r = 'D'; s = s1 + s2; }
    scanf ( "%d%d", &s1, &s2 );
    if ( s1 + s2 > s ) { r = 'E'; s = s1 + s2; }

    printf ( "%c %d\n", r, s );
  }

  return ( 0 );
}

Measured memory_bytes: 0
#include <iostream>

using namespace std;
int main(int argc, char *argv[]) {
	int n, k;
	scanf("%d", &n);
	for (int i = 0; i <= n / 7; i++) {
		int sum = i * 7;
		if ((n-sum) % 4 == 0) {
			printf("Yes");
			return 0;
		}
	}
	printf("No");
	return 0;
	
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>
#include <functional>
#include <cfloat>
#include <math.h>
#include <numeric>
#include <string.h>
#include <sys/time.h>
#include <random>


#define fs first
#define sc second

using namespace std;

typedef long long ll;
typedef unsigned int uint;
typedef pair<ll, ll> P;


// a と b の最大公約数を返す
ll gcd(ll a, ll b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}


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



// 素数判定
bool is_prime(ll N) {
    if (N == 1) return false;
    for (ll i = 2; i * i <= N; ++i) {
        if (N % i == 0) return false;
    }
    return true;
}


// 約数列挙
vector<ll> enum_divisors(ll N) {
    vector<ll> res;
    for (ll i = 1; i * i <= N; ++i) {
        if (N % i == 0) {
            res.push_back(i);
            if (N/i != i) res.push_back(N/i);
        }
    }
    sort(res.begin(), res.end());
    return res;
}


// 素因数分解
vector<pair<ll, ll>> prime_factorize(ll N){
    vector<pair<ll, ll>> res;
    for(ll i = 2; i * i <= N; i++){
        if(N % i != 0)  continue;
        ll ex = 0;

        while(N % i == 0){
            ex++;
            N /= i;
        }

        res.push_back({i, ex});
    }

    if(N != 1)  res.push_back({N, 1});
    return res;
};


int main(){
    ll n, m;    cin >> n >> m;
    vector<ll> a(n, 0);
    for(int i = 0; i < n; i++){
        cin >> a[i];
        if(a[i] % 2 == 1){
            cout << 0 << endl;
            return 0;
        }
        a[i] /= 2;
    }

    int factor2 = -1;
    for(int i = 0; i < n; i++){
        int tmpFactor2 = 0;
        while(a[i] % 2 == 0){
            a[i] /= 2;
            tmpFactor2++;
        }
        if(factor2 == -1){
            factor2 = tmpFactor2;
        }
        else if(factor2 != tmpFactor2){
            cout << 0 << endl;
            return 0;
        }
    }

    ll x = 1;
    while(factor2 > 0){
        x *= 2;
        factor2--;
    }
    for(int i = 0; i < n; i++){
        x = lcm(x, a[i]);
    }

    if(x > m){
        cout << 0 << endl;
    }
    else{
        cout << (m / x + 1) / 2 << endl;
    }



    return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args)
	{
		Scanner s=new Scanner(System.in);
		
		int n=s.nextInt();
		
		String str=s.next();
		
		int r=0;
		int w=0;
		
		for(int i=0;i<n;i++)
		{
			if(str.charAt(i)=='R')
			{
				r++;
			}
			else
			{
				w++;
			}
		}
		
		int count=0;
		
		for(int i=0;i<n;i++)
		{
			if(str.charAt(i)=='W'&&i<=r-1)
			{
				count++;
			}
		}
		
		System.out.println(count);
		
	}
	
}

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

using namespace std;

const unsigned int MAX = 200002;
char str[MAX];


int main(){
    int i=0;
    int top=-1;
    int bottom=-1;

    fgets(str, MAX, stdin);

    while(str[i] != '\0'){
        if(top == -1 && str[i] == 'A')
            top = i;
        if(str[i] == 'Z')
            bottom = i;
        i++;
    }

    printf("%d\n", bottom - top + 1);
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for(int i = 0; i < N; i++){
  cin >> A.at(i);
  }
  int ans = 0;
  for(int i = 1; i < N; i++){
  for(int j = 0; j< i; j++){
  ans += A.at(i) * A.at(j);
  }
  }
  cout <<ans;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define repk(i,k,n) for (ll i = k; i < (ll)(n); ++i)
#define MAX 500000001000000000
#define MOD 1000000007
typedef long long  ll;

using namespace std;

int ans, cnt;

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

	vector<vector<int>> A(3,vector<int>(3));
	rep(i, 3) {
		rep(j, 3) {
			cin >> A[i][j];
		}
	}

	int N;
	cin >> N;

	int b;
	rep(i, N) {
		cin >> b;
		rep(i, 3) {
			rep(j, 3) {
				if (A[i][j] == b) {
					A[i][j] = -1;
				}
			}
		}
	}

	rep(i, 3) {
		if (A[i][0] == -1 && A[i][1] == -1 && A[i][2] == -1) {
			cout << "Yes" << endl;
			return 0;
		}
		if (A[0][i] == -1 && A[1][i] == -1 && A[2][i] == -1) {
			cout << "Yes" << endl;
			return 0;
		}
	}

	if (A[0][0] == -1 && A[1][1] == -1 && A[2][2] == -1) {
		cout << "Yes" << endl;
		return 0;
	}
	if (A[0][2] == -1 && A[1][1] == -1 && A[2][0] == -1) {
		cout << "Yes" << endl;
		return 0;
	}

	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256