akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
using namespace std;

int main() {
    int x, y, z;
    cin >> x >> y >> z;

    int ans = x / (y + z);
    if (x % (y + z) < z) ans--;

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


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cstring>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <stack>
#include <cmath>
#include <time.h>
#include <unordered_set>
#include <unordered_map>
#define ll long long
#define LINF 0x3f3f3f3f3f3f3f3f
#define INF 0x3f3f3f3f
#define PI 3.14159265
#define RAND (rand()*rand())
#define MAX(x, y) ((x) > (y) ? (x):(y)) 
#define MIN(x, y) ((x) > (y) ? (y):(x))
#define ABS(x) ((x) > 0 ? ((x) : -(x)))
#define CEIL(x, y) (((x) + (y) - 1)/(y))
using namespace std;
const int MAXN = 1e5 + 5;
const ll MOD = 1e9 + 7;
int N, M, K, Q, T;
char grid[205][205];
int depth[205];

int main()
{
	int i, j;
	scanf("%d", &N);
	for (i = 1; i <= N; ++i) {
		scanf("%s", grid[i]);
	}

	int ans = 0;
	for (i = 1; i <= N; ++i) {
		for (j = 1; j <= N; ++j) depth[j] = 0;
		queue<int> q;
		int d = 1;
		depth[i] = d;
		q.push(i);
		while (!q.empty()) {
			int sz = q.size();
			++d;
			while (sz--) {
				int u = q.front();
				q.pop();
				for (int v = 1; v <= N; ++v) {
					if (grid[u][v - 1] == '0') continue;
					if (depth[v] == 0) {
						depth[v] = d;
						q.push(v);
					}
					else if (depth[v] == depth[u]) {
						printf("-1");
						return 0;
					}
				}
			}
		}
		ans = MAX(ans, d - 1);
	}
	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  unsigned long long int i,n,input;
  unsigned long long int ave=0;
  double average;
  scanf("%llu",&n);
  for(i=0;i<n;i++){
    scanf("%llu",&input);
    ave+=input;
  }
  ave/=n;
  printf("%llu\n",ave);
  return 0;
}

Measured memory_bytes: 0
//from https://coderecipe.org/atcoder/abc104_d.html#%E5%8F%82%E8%80%83%E3%81%AB%E3%81%AA%E3%81%A3%E3%81%9F%E3%82%B3%E3%83%BC%E3%83%89
#include<bits/stdc++.h>

#define rep(i,n) for(ll i = 0; i < (n); i++)
#define ll long long
#define MOD 1000000007

using namespace std;

ll dp[100011][4];

int main(){
  string s;cin>>s;
  dp[0][0]=1;

  rep(i, s.size()){

    if(s[i]=='A'){
      rep(j,4){
        dp[i+1][j]=dp[i][j];
      }
      dp[i+1][1]=(dp[i][1] + dp[i][0])%MOD;
    }

    if(s[i]=='B'){
      rep(j,4){
        dp[i+1][j]=dp[i][j];
      }
      dp[i+1][2]=(dp[i][2] + dp[i][1])%MOD;
    }

    if(s[i]=='C'){
      rep(j,4){
        dp[i+1][j]=dp[i][j];
      }
      dp[i+1][3]=(dp[i][3] + dp[i][2])%MOD;      
    }

    if(s[i]=='?'){
      dp[i+1][0]=3*dp[i][0]%MOD;
      rep(j,3){
        dp[i+1][j+1]=(dp[i][j] + 3*dp[i][j+1])%MOD;
      }
    }

  }

  cout<<dp[s.size()][3]%MOD<<endl;

  return 0;
}


Measured memory_bytes: 3584
n = int(input())
a = list(map(int, input().split()))
a = [0] + a + [0]
ans = []
i = 1
s = [abs(a[1])] + [None for _ in range(n)]
d = [0 for _ in range(n + 1)]
for i in range(1, n + 1):
    s[i] = abs(a[i + 1] - a[i])
    if (a[i - 1] - a[i]) * (a[i] - a[i + 1]) >= 0:
        d[i] = 0
    else:
        d[i] = s[i] + s[i - 1] - abs(a[i + 1] - a[i - 1])
ss = sum(s)
for i in range(1, n + 1):
    print(ss - d[i])

Measured memory_bytes: 14956
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define pb push_back
#define mp make_pair

using namespace std;

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

const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1000000000000000000L;

int main() {
    int n, m;
    cin >> n >> m;

    priority_queue<P, vector<P>, greater<P> > pq;
    int p[100000];
    rep(i, m) {
        int y;
        cin >> p[i] >> y;
        pq.push(P(y, i));
    }

    ll ans[100000];
    int x[100000];
    fill(x, x + n, 0);
    while(!pq.empty()) {
        P tmp = pq.top(); pq.pop();
        int pre = p[tmp.second];
        x[pre - 1]++;
        ans[tmp.second] = (ll)pre * 1000000 + x[pre - 1];
    }

    rep(i, m) {
        printf("%012ld\n", ans[i]);
    }

    return 0;
}


Measured memory_bytes: 3956
#include<bits/stdc++.h>
using namespace std;
#define ld long double
#define lli long long int
#define vi vector<int>
#define vlli vector<lli>
#define vvi vector<vi >
#define str string
#define vs vector<str>
#define vb vector<bool>
#define slli set<lli>
#define mii map<int, int>
#define mlli map<int, lli>
#define msi map<str, int>
#define mp make_pair
#define pii pair<int, int>
#define pll pair<lli, lli>
#define vpii vector<pii >
#define vpll vector<pll >
#define pb push_back
#define loop(i, s, l, j) for(int i = s; i < l; i += j)
#define rloop(i, s, l, j) for(int i = s; i >= l; i -= j)
#define rep(i, n) loop(i,0,n,1)
#define rrep(i, n) rloop(i,n-1,0,1) 
#define fastio() ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define ft first
#define sd second   
#define mit mii::iterator
#define vit vi::iterator
#define all(a) a.begin(),a.end()
#define min3(a, b, c) min(a, min(b, c))
#define mod 1000000007
#define inf 100000000000000000
#define limit 200005
#define minval -100000000000000000
/**********************************************************************************************************************************************/
int dx4[4] = {0, -1, 0, 1};
int dy4[4] = {1, 0, -1, 0};
int dx8[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
int dy8[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
int Power(int base,int exp){int ans=1;  while(exp > 0){if(exp&1)ans=(1LL*ans*base)%mod; exp=exp>>1; base=(1LL*base*base)%mod;}  return ans;}
/**********************************************************************************************************************************************/ 

void input()
{
	int s;
	cin >> s;

	lli dp[s+1] = {};
	dp[0] = dp[1] = dp[2] = 0;
	dp[0] = 1;
	loop(i,3,s+1,1)
	{
		loop(j,3,i+1,1)
		{
			if(i-j < 0)
				break;
			dp[i] = (dp[i] + dp[i-j])%mod;
		}
	}
	cout << dp[s] << '\n';
}

int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
 
    fastio();
    int q = 1;
    //cin >> q;
    while(q--)
        input();
}

Measured memory_bytes: 3684
import sys, bisect, math, itertools, string, queue, copy
import numpy as np
import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
# input = sys.stdin.readline.rstrip()
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplt(n): return [tuple(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

n = inp()
XY = [(0,0)] + inplt(n)

P = permutations(range(1,n+1))
ans = 0
s = 0
for l in P:
    for i in range(1,n):
        s += math.sqrt((XY[l[i]][0]-XY[l[i-1]][0])**2 + (XY[l[i]][1]-XY[l[i-1]][1])**2)
        
ans = s/math.factorial(n)
print(ans)

Measured memory_bytes: 31144
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<set>
using namespace std;
int x,y,z;
multiset<string> s;
int main(){
	scanf("%d %d %d",&x,&y,&z);
	for(int i=1;i<=x;i++) s.insert("a");
	for(int i=1;i<=y;i++) s.insert("b");
	for(int i=1;i<=z;i++) s.insert("c");
	multiset<string>::iterator it;
	while(s.size()>1){
		it=s.begin(); string s1=*it;
		s.erase(it);
		it=s.end(); it--; string s2=*it;
		s.erase(it);
		s.insert(s1+s2);
	}
	it=s.begin();
	cout<<*it<<endl;
	return 0;
}

Measured memory_bytes: 256
/**
 * File    : A.cpp
 * Author  : Kazune Takahashi
 * Created : 11/22/2018, 7:40:56 PM
 * Powered by Visual Studio Code
 */

#include <iostream>
#include <iomanip>   // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple>
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set>
#include <functional>
#include <random> // auto rd = bind(uniform_int_distribution<int>(0, 9), mt19937(19920725));
#include <chrono> // std::chrono::system_clock::time_point start_time, end_time;
// start = std::chrono::system_clock::now();
// double elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end_time-start_time).count();
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.

typedef long long ll;

// const int dx[4] = {1, 0, -1, 0};
// const int dy[4] = {0, 1, 0, -1};

// const int C = 1e6+10;
// const ll M = 1000000007;

int main()
{
  int x;
  cin >> x;
  if (x < 1200)
  {
    cout << "ABC" << endl;
  }
  else
  {
    cout << "ARC" << endl;
  }
}

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

#define MAX 100000

int partition(int A[], int p, int r) {
  int x = A[r];
  int i = p - 1;
  int tmp;
  for (int j = p; j < r; j++) {
    if (A[j] <= x) {
      i++;
      tmp = A[i];
      A[i] = A[j];
      A[j] = tmp;
    }
  }
  tmp = A[i+1];
  A[i+1] = A[r];
  A[r] = tmp;
  return i + 1;
}

int main() {
  int A[MAX], n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> A[i];
  }

  int q = partition(A, 0, n-1);

  for (int i = 0; i < n; i++) {
    if (i) cout << " ";
    if (i == q) {
      cout << "[" << A[i] << "]";
    } else {
      cout << A[i];
    }
  }
  cout << endl;

  return 0;
}



Measured memory_bytes: 3376
//In The Name Of Allah
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define sz(x) (int)(x.size())
#define double long double 
#define fi first
#define se second
#define pii pair<int, int>

signed main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);
  int n;
  cin >> n;
  string s;
  cin >> s;
  for (int b = 0; b < 4; b++) {
    char a[n];
    for (int i = 0; i < 2; i++) {
      if (b & (1 << i)) {
        a[i] = 'S';
      } else {
        a[i] = 'W';
      }
    }
    for (int i = 1; i < n - 1; i++) {
      if (s[i] == 'o' ^ a[i] == 'W') {
        a[i + 1] = a[i - 1];
      } else {
        if (a[i - 1] == 'W') a[i + 1] = 'S';
        else a[i + 1] = 'W';
      }
    }
    int ch, ch2;
    if (s[n - 1] == 'o' ^ a[n - 1] == 'W') {
      ch = a[n - 2];
    } else {
      if (a[n - 2] == 'W') ch = 'S';
      else ch = 'W';
    }

    if (s[0] == 'o' ^ a[0] == 'W') {
      ch2 = a[n - 1];
    } else {
      if (a[n - 1] == 'W') ch2 = 'S';
      else ch2 = 'W';
    }
    if (ch == a[0] && ch2 == a[1]) {
      for (int i = 0; i < n; i++) {
        cout << a[i];
      }
      cout << "\n";
      return 0;
    }
  }
  cout << "-1\n";
}



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

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

    int x;
    int c = 1;
    while(cin >> x){
        if(x == 0)
            return 0;

        cout << "Case " << c << ": " << x << endl;
        ++c;
    }

    return 0;
}

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

#define int long long

#define Vanya Unstoppable

#define double long double

using namespace std;

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

    int n, x, y;
    cin >> n >> x >> y;

    set < pair < int, int > > s[n];
    for(int i = 1; i <= n; ++i){
        for(int j = i + 1; j <= n; ++j){
            if(abs(x - i) + abs(y - j) + 1 < j - i){
                s[abs(x - i) + abs(y - j) + 1].insert({i, j});
            }
            else{
                s[j - i].insert({i, j});
            }
        }
    }

    for(int i = 1; i <= n - 1; ++i){
        cout << s[i].size() << endl;
    }
}


Measured memory_bytes: 125312
use std::io;
use std::cmp;


/// https://beta.atcoder.jp/contests/abc099/tasks/abc099_c
/// Strange Bank
/// 6^p * 6 == 6^(p + 1)
fn main() {
    let n = read_one::<usize>();
    let mut ans = ::std::usize::MAX;
    for i in 0..n + 1 {
        let mut cnt = 0;
        let mut t = i;
        while t > 0 { cnt += t % 6; t /= 6; }
        t = n - i;
        while t > 0 { cnt += t % 9; t /= 9; }
        ans = cmp::min(ans, cnt);
    }
    println!("{}", ans);
}


#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<vector<int>> adj(200001);
vector<int> vis(200001);
vector<int> towns;
void dfs(int root , int cnt){
    ++vis[root];
    for(int child : adj[root]){
        if(!vis[child]){
            ++cnt;
            towns.emplace_back(child);
            dfs(child,cnt);
        }
        else{
            towns.emplace_back(child);
            break;
        }
    }
}
int main(){
    int n;
    cin>>n;
    ll k;
    cin>>k;
    int arr[n];
    for(int i = 0 ; i<n ; i++){
        cin>>arr[i];
        adj[i+1].push_back(arr[i]);
    }
    towns.emplace_back(1);
    int cnt = 0;
    dfs(1 , cnt);
    //for(int i = 0 ; i<towns.size() ; i++){
      //  cout<<towns[i]<<" ";
    //}
    //cout<<"\n";
    if(k<towns.size()-1){
        cout<<towns[k];
    }
    else{
        k-=(towns.size()-2);
        int index = 0;
        for(int i = 0 ; i<towns.size()-1 ; i++){
            if(towns[i] == towns[towns.size()-1]){
                index = i;
                break;
            }
        }
        ll townIndex = k%(towns.size()-2-index+1);
        if(townIndex==0){
            townIndex = towns.size()-2-index+1;
        }
        cout<<towns[index+townIndex-1];
    }
    return 0;
}

Measured memory_bytes: 28764
#include<iostream>
#include<string>
#include<stdio.h>
using namespace std;
int main() {
    int N, K, l[50], M,S=0;
    cin >> N >> K;
    for (int i = 0; i < N; ++i) {
        cin >> l[i];
        for (int j = 0; j < i; ++j) {
            if (l[i] > l[j]) {
                M = l[i];
                l[i] = l[j];
                l[j] = M;
            }
        }
    }
    for (int k = 0; k < K; ++k) {
        S = S+l[k];
    }
    cout << S << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
    int a,c;
    char b;
    cin >> a >> b >> c;
    if (b-'+'==0){
    cout << ( a + c ) << endl;
    }
    else if(b-'-'==0){
    cout << ( a - c ) << endl;
    }
    else{
    cout << "error" << endl;
    }
}


Measured memory_bytes: 256
ans = 0

while True:
    a, op, b =  input().split()
    a = int(a)
    b = int(b)
    
    if op == "?":
        break
    elif op == "+":
        ans = a + b
    elif op == "-":
        ans = a - b
    elif op == "*":
        ans = a * b
    else:
        ans = a // b
    print(ans)


Measured memory_bytes: 5592
import math
n=int(input())

alpha=[chr(ord('a') + i) for i in range(26)]
ans=[]

while True:
    ans.append(alpha[n%26-1])
    if n//26==0:
        break
    elif n==26:
        break
    else:
        n/=26
        n=math.ceil(n-1)

print("".join(reversed(ans)))

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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()
#define endl "\n"

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

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


Measured memory_bytes: 3636
a,b,k = map(int, input().split())

li = []
s = 1
e = 0
a = float(a)
b = float(b)

while True:
    if a % s == 0 and b % s == 0:
        li.append(s)
        e += 1
    if s == a or s == b:
        break
    s += 1

print(li[-k])


Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <cstdio>

using namespace std;

struct colors {
  int R;
  int G;
  int B;
};

int N;
char S[4001];
struct colors c[4001];

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

  for (int i=0; i<N; i++) {
    if (i==0) c[0].R = c[0].G = c[0].B = 0;
    else c[i] = c[i-1];
    switch(S[i]) {
    case 'R':
      c[i].R++;
      break;
    case 'G':
      c[i].G++;
      break;
    case 'B':
      c[i].B++;
      break;
    }
  }

  // for (int i=0; i<N; i++) {
  //   printf("%d %d %d\n", c[i].R, c[i].G, c[i].B);
  // }

  long long int ans = 0;
  for (int i=0; i<N-2; i++) {
    for (int j=N-1; j>i+1; j--) {
      long long int tmp;
      if ((S[i]=='R' && S[j]=='G') || (S[i]=='G' && S[j] == 'R')) {
        tmp = c[j].B - c[i].B - (((j-i)%2==0 && S[(j+i)/2] == 'B')?1:0);
        ans += tmp;
        // printf("B %d %d: %lld\n", i, j, tmp);
      }
      if ((S[i]=='R' && S[j]=='B') || (S[i]=='B' && S[j] == 'R')) {
        tmp = c[j].G - c[i].G - (((j-i)%2==0 && S[(j+i)/2] == 'G')?1:0);
        ans += tmp;
        // printf("G %d %d: %lld\n", i, j, tmp);
      }
      if ((S[i]=='B' && S[j]=='G') || (S[i]=='G' && S[j] == 'B')) {
        tmp = c[j].R - c[i].R -(((j-i)%2==0 && S[(j+i)/2] == 'R')?1:0);
        ans += tmp;
        // printf("R %d %d: %lld\n", i, j, tmp);
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3676
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <cstdio>

using namespace std;
#define prev prev55

long long n, t[50000], v[50000];
long long scale[50000];

int main()
{
    fill(scale, scale + 50000, 1000000000000);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    for (int i = 0; i < n; i++) cin >> t[i];
    for (int i = 0; i < n; i++) cin >> v[i];
    for (int i = 0; i < n; i++) t[i] += t[i], v[i] += v[i];
    int l = 0;
    for (int i = 0; i <= 40000; i++) scale[i] = min(scale[i], (long long)i);
    for (int j = 0; j < n; j++)
    {
        int r = l + t[j];
        for (int i = l; i >= 0; i--)
        {
            scale[i] = min(scale[i], l - i + v[j]);
        }
        for (int i = l; i <= r; i++) scale[i] = min(scale[i], v[j]);
        for (int i = r; i <= 40000; i++)
        {
            scale[i] = min(scale[i], i - r + v[j]);
        }
        l = r;
    }
    for (int i = l; i >= 0; i--) scale[i] = min(scale[i], (long long)l - i);
    for (int i = l; i <= 40000; i++) scale[i] = 0;
    long long summ = 0;
    for (int i = 0; i <= 40000; i++)
    {
        summ += scale[i];
    }
    printf("%.9f", summ / 4.0);
}


Measured memory_bytes: 640
n = int(input()) - 1

j = 0

ans = 0

for i in range(1, n):
    
    j = i
    
    while True:
        j += 1
        if i * j > n:
            break
        ans += 1


k = 1

er = 0

while True:
    er += 1
    if k ** 2 > n:
        break
    k += 1


print((ans * 2) + er - 1)


Measured memory_bytes: 9172
from collections import deque
N, X, Y = map(int, input().split())
G = [[] for _ in range(N)]
for i in range(N - 1):
    G[i].append(i + 1)
    G[N-i-1].append(N - i - 2)
G[X-1].append(Y-1)
G[Y-1].append(X-1)

mind = [[N] * N for _ in range(N)]
todo = deque()
for s in range(N):
    todo.append((0, s))
    done = set()
    while todo:
        d, p = todo.popleft()
        mind[s][p] = min(mind[s][p], d)
        done.add(p)
        for np in G[p]:
            if not np in done:
                todo.append((d + 1, np))

counts = [0] * (N - 1)
for i in range(N - 1):
    for j in range(i + 1, N):
        counts[mind[i][j]-1] += 1
for c in counts:
    print(c)

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

namespace ConsoleApplication6
{
    class Program
    {
        static void Main(string[] args)
        {
            bool ret = false;
            string retstr = string.Empty;
            var sin = Console.ReadLine();
            var strlst=sin.Split(' ');
            var lst = strlst.Select(x => c2i(x)).ToList();
            if (lst[0] > lst[1])
            {
                for (int i = 0; i < lst[0]; i++) retstr += strlst[1];
            }
            else
            {
                for (int i = 0; i < lst[1]; i++) retstr += strlst[0];
            }
            Console.WriteLine(retstr);
            Console.ReadLine();
        }

        static int c2i(string c) { return int.Parse(c); }
    }
}


Measured memory_bytes: 13268
'use strict';

function Main(input) {
    // N K
    // P1 P2 ... PN
    let tmp = input.trim().split('\n');
    const NK = tmp[0].split(' ').map((v) => Number(v));
    const N = NK[0];
    const K = NK[1];
    const P = tmp[1]
        .split(' ')
        .map((v) => Number(v))
        .sort((a, b) => a - b);
    // console.log(N, K, P);

    let result = 0;
    for (let i = 0; i < K; i++) {
        result += P[i];
    }

    console.log(result);

    return;
}
Main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 29752
N, M = gets.split.map(&:to_i)
lr_list = M.times.map { gets.split.map(&:to_i) }
table = Array.new(N + 1) { 0 }
lr_list.each do |(l, r)|
  table[l - 1] += 1
  table[r] -= 1
end
(0...N).each { |i| table[i + 1] += table[i] }
ans = table.count { |n| n == M }
puts ans


Measured memory_bytes: 10364
#include <iostream>
#include <string>

using namespace std;

int main(){
        string s;
        cin >> s;

        if( s[0] == s[1] || s[2] == s[3] || s[1] == s[2])

                cout << "Bad" << endl;
        else
                cout << "Good" << endl;

        return 0;
}

Measured memory_bytes: 3588
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations
import sys
import string
from bisect import bisect_left


INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LIM(): return list(map(lambda x:int(x) - 1, sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def LIRM(n): return [LIM() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
mod = 1000000007


n = I()


def sieve(n):
    n -= 1
    prime = [1] * n
    prime[0] = 0
    prime[1] = 0
    for i in range(2, int(n**0.5)+1):
        if prime[i]:
            for j in range(i*2, n, i):
                prime[j] = 0
    return [i for i in range(n) if prime[i]]


    return prime



print(*[i for i in sieve(55555) if i % 5 == 1][:n])

Measured memory_bytes: 41072
#12
import sys
N,K = map(int,input().split())
num = float("inf")
n = 0

for i in reversed(range(1,18)):
    n = (10**i)*K
    for j in range(9):
        N -= n
        if N < 0:
            N+=n
            break

if N == 0:
    print(0)
    sys.exit()
    

while num > K:
    num = abs(N-K)
    N = num
    

if abs(N-K) > num:
    print(num)
else:
    print(abs(N-K))
    

Measured memory_bytes: 8908
import java.util.ArrayList;
	import java.util.Arrays;
	import java.util.Collections;
	import java.util.Comparator;
	import java.util.HashMap;
	import java.util.HashSet;
	import java.util.List;
	import java.util.Map;
	import java.util.Map.Entry;
	import java.util.PriorityQueue;
	import java.util.Queue;
	import java.util.Scanner;
	import java.util.Set;

	public class Main{

		public static void main(String[] args) {

			Scanner scanner = new Scanner(System.in);

			int n = Integer.parseInt(scanner.nextLine());
			Queue<Job> q = new PriorityQueue<>();
			for(int i = 0; i < n; i++) {
				q.add(new Job(scanner.nextInt(), scanner.nextInt()));
			}

			int sum = 0;
			for(int i = 0; i < n; i ++) {

				Job x = q.poll();
				sum += x.cost;
				if(sum > x.limit) {

					System.out.println("No");
					return;
				}

			}

			System.out.println("Yes");
		}
		public static class Job implements Comparable<Job>{

			int limit, cost;

			public Job(int cost, int limit) {

				this.limit = limit;
				this.cost = cost;
			}

			@Override
			public int compareTo(Job another) {

				return this.limit - another.limit;
			}

		}

	}

Measured memory_bytes: 67208
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();

// find consecutive LIS
int main() {
    int n, val;
    cin >> n;

    vector<int> pos(n+1, INT_MAX);
    for(int i = 0; i < n; i++) {
        cin >> val;
        pos[val] = i;
    }
    int cnt = 0, ans = 1;
    for(int i = 1; i <= n; i++) {
        if (pos[i] > pos[i-1]) {
            cnt += 1;
            ans = max(ans, cnt);
        } else {
            cnt = 1;
        }
    }
    cout << n - ans << endl;
    return 0;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
 
using namespace std;
 
#define f0r(a, b) for (long long a = 0; a < (b); a++)
#define f1r(a, b, c) for (long long a = (b); a < (c); a++)
#define f0rd(a, b) for (long long a = (b); a >= 0; a--)
#define f1rd(a, b, c) for (long long a = (b); a >= (c); a--)
#define ms(arr, v) memset(arr, v, sizeof(arr))
#define pb push_back
#define mp make_pair
#define f first
#define s second
using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vpl = vector<pll>;
 
void fio() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); 
  cout.tie(0);
}
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const long double pi = 3.14159265358979323846;



void solve() {
  ll n; cin >> n;
  n %= 1000;
  cout << (1000 - n) % 1000 << '\n';
}
 
int main() {
  fio();
  
  int T = 1;
  // cin >> T;
  while (T--) solve();
} 

Measured memory_bytes: 3652
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <tuple>
using namespace std;
int dx[4]={0, 0, -1, 1};
int dy[4]={-1 ,1, 0, 0};
int main(){

	int H, W;
	cin>>H>>W;
	vector<string> S;
	for(int i=0;i<H;i++){
		string s;
		cin>>s;
		S.push_back(s);
	}

	int ans=0;

	for(int sx=0;sx<H;sx++){
		for(int sy=0;sy<W;sy++){

			if(S[sx][sy]=='#')
				continue;

			int dist[21][21]={};
			for(int i=0;i<H;i++)
				for(int j=0;j<W;j++)
					dist[i][j]=-1;

			queue<tuple<int, int, int>> que;
			que.emplace(sx, sy, 0);

			while(que.size()){
				int x_now, y_now, d_now;
				tie(x_now, y_now, d_now)=que.front();
				que.pop();

				if(dist[x_now][y_now]!=-1)
					continue;

				dist[x_now][y_now]=d_now;

				for(int k=0;k<4;k++){
					int x_next=x_now+dx[k], y_next=y_now+dy[k], d_next=d_now+1;
					if(dist[x_next][y_next]!=-1 || S[x_next][y_next]=='#')
						continue;
					que.emplace(x_next, y_next, d_next);
				}
			}

			for(int gx=0;gx<H;gx++)
				for(int gy=0;gy<W;gy++)
					ans=max(ans, dist[gx][gy]);

		}
	}

	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 256
N, Q = map(int, input().split())
S = input()
# print(S)
t = [0] * (N + 1)
for i in range(N):
    t[i + 1] = t[i] + (1 if S[i : i + 2] == 'AC' else 0)
#     print(i, t[i+1], t[i], S[i:i+2])
# print(t)

for i in range(Q):
    l, r = map(int, input().split())
#     print(r,l,t[r-1],t[l-1])
    print(t[r-1] - t[l-1])

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

#define REP(i,s,n) for(int i=s; i<n; ++i)
#define rep(i,n) REP(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false

typedef long long ll;
typedef pair<int, int> ii;

int main(){

	ll n, k;
	cin >> n >> k;

	ll h;

	ll ans = 0;

	rep(i, n){
		cin >> h;
		if(k <= h) ans++;
	}

	cout << ans << endl;


	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    // 整数の入力
    int X = sc.nextInt();

    int count = 0;
    count += (X / 500) * 1000;
    X = X % 500;
    count += (X / 5) * 5;

    // 出力
    System.out.println(count);
  }
}


Measured memory_bytes: 23892
#include <bits/stdc++.h>
using namespace std;
const int INF=1000010000;
typedef long long ll;
int dp[101100];
int h[101100];
int main() {
  int n,k;cin >> n >> k;
  for(int i=0; i<n; i++) cin >> h[i];
  for(int i=0; i<n; i++) dp[i]=INF;
  dp[0]=0;
  for(int i=0; i<n-1; i++){
    for(int j=1; j<=k; j++){
      dp[i+j]=min(dp[i+j],dp[i]+abs(h[i+j]-h[i]));
    }
  }
  cout << dp[n-1] << endl;
}

Measured memory_bytes: 1024
class UnionFind:
    def __init__(self, n):
        self.v = [-1 for _ in range(n)]  # 根(負): 連結頂点数 * (-1) / 子(正): 根の頂点番号(0-indexed)

    def find(self, x):  # xを含む木における根の頂点番号を返す
        if self.v[x] < 0:  # (負)は根
            return x
        else:  # 根の頂点番号
            self.v[x] = self.find(self.v[x])  # uniteでは, 旧根に属する頂点の根が旧根のままなので更新
            return self.v[x]

    def unite(self, x, y):  # 違う根に属していたらrankが低くなるように連結
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if -self.v[x] < -self.v[y]:  # size比較, 　(-1) * (連結頂点数 * (-1)), (正)同士の大小比較
            x, y = y, x  # 連結頂点数が少ない方をyにすると, findでの更新回数が減る？
        self.v[x] += self.v[y]  # 連結頂点数の和を取る, 連結頂点数 * (-1)
        self.v[y] = x  # 連結頂点数が少ないy(引数yの根の頂点番号)の根をx(引数xの根の頂点番号)にする

    def root(self, x):
        return self.v[x] < 0  # (負)は根

    def same(self, x, y):
        return self.find(x) == self.find(y)  # 同じ根に属するか

    def size(self, x):
        return -self.v[self.find(x)]  # 連結頂点数を返す


N, M = map(int, input().split())
e = []
for _ in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    e.append((a, b))

init = N * (N - 1) // 2
uf = UnionFind(N)

ans = [-1 for _ in range(M)]
cc = 0
for i in sorted(range(M), reverse=True):
    ans[i] = init - cc
    a, b = e[i]
    sa, sb = uf.size(a), uf.size(b)
    if sa == 1:
        if sb == 1:
            cc += 1
        else: #sb > 1
            cc -= sb * (sb - 1) // 2
            cc += sb * (sb + 1) // 2
    else:
        if sb == 1:
            cc -= sa * (sa - 1) // 2
            cc += sa * (sa + 1) // 2
        else:
            # sa > 1 and sb > 1
            if uf.same(a, b):
                pass
            else:
                cc -= sa * (sa - 1) // 2
                cc -= sb * (sb - 1) // 2
                cc += (sa + sb) * (sa + sb - 1) // 2
    uf.unite(a, b)

for i in range(M):
    print(ans[i])


Measured memory_bytes: 25304
#include <iostream>
using namespace std;
int main(void){

    string p,s;
    cin >> p >> s;
    string out = "No";
    for(int i=0;i<p.size();i++){
        if(p[i] == s[0]) for(int j=0;j<s.size();j++){
            int tmp;
            if(i+j>p.size()-1){
                tmp = i+j - p.size();
            }else{
                tmp = i+j;
            }
            //cout << tmp <<" "<< i << " " << j << " " << p[i+j] << " " << s[j] << endl;;
            if(p[tmp] != s[j]) break;
            if(j==s.size()-1) out="Yes";
        }
    }
        cout << out << endl;
}



Measured memory_bytes: 3220
#include <iostream>

using namespace std;

int main() {
    int n, m, i, j;
    
    cin >> n >> m;
    
    //2?¬??????????a?????£?¨?
    int **a = new int* [n];
    for(i = 0; i < n; i++) a[i] = new int [m];
    
    //??????b, c
    int *b = new int [m];
    int *c = new int [n];
    
    //c????????????
    for(i = 0; i < n; i++) c[i] = 0;
    
    //a?????????
    for(i = 0; i < n; i++) {
        for(j = 0; j < m; j++) {
            cin >> a[i][j];
        }
    }
    
    //b?????????
    for(i = 0; i < m; i++) cin >> b[i];
    
    //c?????????
    for(i = 0; i < n; i++) {
        //cout << endl;
        for(j = 0; j < m; j++) {
            //cout << a[i][j] << " ";
            c[i] += a[i][j] * b[j];
        }
    }
    
    //Output
    for(i = 0; i < n; i++) cout << c[i] << endl;
}

Measured memory_bytes: 1228
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

s = ns()

a = inf
z = -inf
for i in range(len(s)):
    if s[i] == 'A':
        a = min(a, i)
    if s[i] == 'Z':
        z = max(z, i)

print(z - a + 1)

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

signed main() {
    int s;
    cin >> s;

    map<int, int> m;
    m[s]++;
    int p = s;
    for (int i = 2;; i++) {
        int a = (p % 2 ? 3 * p + 1 : p / 2);
        if (m[a]) {
            cout << i << endl;
            return 0;
        }
        m[a]++;
        p = a;
    }

    return 0;
}


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

int main(){
	int n;
	cin>>n;
	int count = 0;
	f(i,n){
		int a;
		cin>>a;

		if(a%2==1 && (i+1)%2==1) count++;
	}
	cout<<count;
}

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

int main() {
	string s;
	cin >> s;

	string r = s;
	reverse(r.begin(), r.end());

	if (r != s)
	{
		cout << "No" << endl;
		return 0;
	}

	string r1 = "";
	for (int i = 0; i < (s.size() - 1) / 2; i++)
	{
		r1.push_back(s[i]);
	}
	
	string r2 = r1;
	reverse(r2.begin(), r2.end());

	if (r1 != r2)
	{
		cout << "No" << endl;
		return 0;
	}

	string s1 = "";
	for (int i = (s.size() + 1) / 2; i < s.size(); i++)
	{
		s1.push_back(s[i]);
	}

	string s2 = s1;
	reverse(s2.begin(), s2.end());

	if (s1 != s2)
	{
		cout << "No" << endl;
		return 0;
	}

	cout << "Yes" << endl;

	return 0;
}

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


def main():
    import sys
    input = sys.stdin.readline

    d = int(input())
    c = list(map(int, input().split()))
    s = [list(map(int, input().split())) for _ in range(d)]

    for i in range(1, d + 1):
        p, q = divmod(i, 26)

        if q == 0:
            q += 1

        print(q)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9520
#include <cstdio>
#include <functional>
#include <algorithm>
#include <vector>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iostream>
#include <queue>
#include <bits/stdc++.h>
#define INF (1ll<<60)
#define MOD 1000000007
#define BOUND 27182818284

typedef long long ll;
typedef long long int lli;

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

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

using namespace std;

// gcd
int gcd(int a, int b){
    if(a==0)
        return b;
    return gcd(b%a,a);
}
// gcd array
int findGCD(int arr[], int n){
    int result = arr[0];
    for (int i=1; i < n; i++)
        result = gcd(arr[i], result);

    return result;
}

// sort big to small
// sort(A,A+N, greater<int>());

// v.front() = -BOUND;
// v.back() = BOUND;

// Iterator
// v.begin
// v.end

int main() {
    unsigned int N,K;
    int minimum;

    cin >> N >>K;

    vector<int> h(N,0);
    rep(i,N){
        cin >> h[i];
    }
    sort(h.begin(), h.end());

    minimum = h.back() - h.front();
    for(int i=0; i<=N-K; i++){
        minimum = min(minimum, h[i+K-1]-h[i]);
    }

    cout << minimum << endl;
    return 0;
}



Measured memory_bytes: 640
// tested by Hightail: https://github.com/dj3500/hightail
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define INF 1001001001
#define FOR(i,n) for(int (i)=0;(i)<(n);++(i))
#define FORI(i,n) for(int (i)=1;(i)<=(n);++(i))
#define mp make_pair
#define pii pair<int,int>
#define ll long long
#define vi vector<int>
#define SZ(x) ((int)((x).size()))
#define fi first
#define se second
#define wez(n) int (n); scanf("%d",&(n));
#define wez2(n,m) int (n),(m); scanf("%d %d",&(n),&(m));
#define wez3(n,m,k) int (n),(m),(k); scanf("%d %d %d",&(n),&(m),&(k));
inline void pisz(int n) { printf("%d\n",n); }
template<typename T,typename TT> ostream& operator<<(ostream &s,pair<T,TT> t) {return s<<"("<<t.first<<","<<t.second<<")";}
template<typename T> ostream& operator<<(ostream &s,vector<T> t){FOR(i,SZ(t))s<<t[i]<<" ";return s; }
#define DBG(vari) cout<<"["<<__LINE__<<"] "<<#vari<<" = "<<(vari)<<endl;
#define ALL(t) t.begin(),t.end()
#define FOREACH(i,t) for (__typeof(t.begin()) i=t.begin(); i!=t.end(); i++)
#define TESTS wez(testow)while(testow--)
#define REP(i,a,b) for(int (i)=(a);(i)<=(b);++i)
#define REPD(i,a,b) for(int (i)=(a); (i)>=(b);--i)
#define REMAX(a,b) (a)=max((a),(b));
#define REMIN(a,b) (a)=min((a),(b));
#define IOS ios_base::sync_with_stdio(0);

int main () {
   wez(a)
   pisz(3*a*a);
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <complex>
#include <map>
#include <climits>
#include <sstream>
using namespace std;

#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second
#define mkp make_pair

static const double PI=6*asin(0.5);
typedef long long ll;
typedef complex<double> CP;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vint;
static const int INF=1<<24;

template <class T>
void initvv(vector<vector<T> > &v,int a,int b, const T  &t = T()){
	v.assign(a,vector<T>(b,t));
}

//v.erase(unique(v.begin(),v.end()),v.end());


int main(){
	rep(i,3){
		int a[3],aa,b[3],bb;
		rep(j,3){
			cin>>a[j];
		}
		aa=a[0]*3600+a[1]*60+a[2];
		rep(j,3){
			cin>>b[j];
		}
		bb=b[0]*3600+b[1]*60+b[2];
		aa=bb-aa;
		int c[3]={0};
		int d[3]={3600,60,1};
		rep(j,3){
			while(aa>=d[j]){
				aa-=d[j];
				c[j]++;
			}
		}
		rep(j,3){
			if(j) cout<<" ";
			cout<<c[j];
		}
		cout<<endl;
	}
}

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

int main() {
	string S;
	string mae;
	int Q;
	int mode = 1;

	cin >> S;
	cin >> Q;

	for (int i = 0; i < Q; i++) {
		int a, b;
		char c;
		cin >> a;
		if (a == 1) {
			mode = !mode;
			continue;
		} else {
			cin >> b >> c;
			if (mode + b == 2) mae += c;
			else S += c;
		}
	}

	reverse(mae.begin(), mae.end());

	S = mae + S;

	if (!mode) reverse(S.begin(), S.end());

	cout << S << endl;

	return 0;
}


Measured memory_bytes: 1116
#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define iter(c) __typeof((c).begin())
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
#define pb(a) push_back(a)
#define pr(a) cout<<(a)<<endl
#define PR(a,b) cout<<(a)<<" "<<(b)<<endl
#define R cin>>
#define F first
#define S second
#define ll long long
bool check(int n,int m,int x,int y){return (x<0||x>=n||y<0||y>=m)?false:true;}
const ll MAX=1000000007,MAXL=1LL<<60,dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};
//typedef pair<int,int> P;

struct P {
  double x,y,z;
};

double D(P a, P b) {
  return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)+(a.z-b.z)*(a.z-b.z);
}

int main() {
  int n,m;
  R n >> m;
  P a[n];
  rep(i,n) {
    double xx,yy,zz;
    R xx >> yy >> zz;
    a[i]=(P){xx,yy,zz};
  }
  double d[n][n];
  rep(i,n) {
    rep(j,n) {
      if(i!=j) d[i][j]=D(a[i],a[j]);
    }
  }
  double ans=0;
  for(int t=0; t<(1<<n); t++) {
    vector<int> v;
    for(int i=0; (1<<i)<=t; i++) {
      if(t&(1<<i)) v.pb(i);
    }
    if(v.size()!=m) continue;
    double c=0;
    rep(i,m) {
      REP(j,i+1,m) c+=d[v[i]][v[j]];
    }
    ans=max(ans,c);
  }
  printf("%.10f\n",ans);
  return 0;
}


Measured memory_bytes: 1272
n = int(input())
r = [0] * n
c = [0] * n
for i in range(n):
    r[i], c[i] = map(int, input().split())

dp = [[0 for i in range(n+1)] for j in range(n+1)]

for i in range(2, n+1): #幅
    for j in range(0, n+1-i): #左端
        dp[j][j+i] = min([dp[j][k]+(r[j]*c[k-1]*c[j+i-1])+dp[k][j+i] for k in range(j+1,j+i)])

print(dp[0][n])


Measured memory_bytes: 5664
#include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>
#include<cassert>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define Endl endl

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T> using vv=vector<vector<T>>;
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"<<endl; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
#define out(args...){vector<string> a_r_g_s=s_p_l_i_t(#args, ','); e_r_r(a_r_g_s.begin(), args); }
vector<string> s_p_l_i_t(const string &s, char c){vector<string> v;int d=0,f=0;string t;for(char c:s){if(!d&&c==',')v.pb(t),t="";else t+=c;if(c=='\"'||c=='\'')f^=1;if(!f&&c=='(')++d;if(!f&&c==')')--d;}v.pb(t);return move(v);}
void e_r_r(vector<string>::iterator it) {}
template<typename T, typename... Args> void e_r_r(vector<string>::iterator it, T a, Args... args){ if(*it==" 1"||*it=="1") cerr<<endl; else cerr << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << ", "; e_r_r(++it, args...);}
const ll MOD=1e9+7;

struct UF{
  vector<int> data;
  UF(int size):data(size,-1){}
  bool unite(int x,int y){
    x=root(x); y=root(y);
    if(x!=y){
      if(data[y]<data[x]) swap(x,y);
      data[x]+=data[y]; data[y]=x;
    }
    return x!=y;
  }
  bool findSet(int x,int y){return root(x)==root(y);}
  int root(int x){return data[x]<0?x:data[x]=root(data[x]);}
  int size(int x) {return -data[root(x)];}
};


int main(){
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(0);
  int n;
  cin>>n;
  vector<pii> xs(n),ys(n);
  rep(i,n){
    int x,y;
    cin>>x>>y;
    xs[i]=pii(x,i);
    ys[i]=pii(y,i);
  }
  sort(all(xs)); sort(all(ys));
  typedef pair<int,pii> piii;
  vector<piii> es;
  reps(i,1,n) es.eb(xs[i].X-xs[i-1].X,pii(xs[i].Y,xs[i-1].Y));
  reps(i,1,n) es.eb(ys[i].X-ys[i-1].X,pii(ys[i].Y,ys[i-1].Y));
  sort(all(es));
  UF uf(n);
  ll re=0;
  for(piii e:es) if(uf.unite(e.Y.X,e.Y.Y)){
      re+=e.X;
      //out(e,1);
    }
  cout<<re<<endl;
  return 0;
}


Measured memory_bytes: 6388
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <random>
#include <chrono>
#include <string>
#include <bitset>
#include <cassert>
#include <queue>
#include <memory>

//#pragma comment(linker, "/STACK:16777216")
//#pragma GCC optimize("O3")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("unswitch-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,abm,mmx,avx,avx2,popcnt,tune=native")

using namespace std;

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

#define ll long long
#define ull unsigned long long
//#define double long double
#define int ll
//#define int ull
//#define int short
//#define int unsigned short
//#define int unsigned int
#define mp make_pair
#define F first
#define S second
#define pii pair<int, int>
#define hash hash228
const int SZ = 2e5 + 4;
const double EPS = 1e-7;
const int mod = 1e9;
const int hashpow = 2;
const int inf = 2e9;

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

int n;
int c[SZ];
vector<int> g[SZ];

void read() {
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> c[i];
        --c[i];
    }
    for (int i = 1; i < n; ++i) {
        int a, b;
        cin >> a >> b;
        --a, --b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
}

int ans[SZ];
int sz[SZ];
bool used[SZ];

int f(int x) {
    return (x * x + x) / 2;
}

void dfs(int u) {
    used[u] = true;
    sz[u] = 1;
    for (int v : g[u]) {
        if (!used[v]) {
            dfs(v);
            sz[u] += sz[v];
        }
    }
}

vector<pii> tmp[SZ];
int y[SZ];
int z[SZ];
void dfs2(int u) {
    used[u] = true;

    if (!tmp[c[u]].empty()) y[tmp[c[u]].back().S] -= sz[u];
    else z[c[u]] -= sz[u];

    for (int v : g[u]) {
        if (!used[v]) {
            tmp[c[u]].emplace_back(u, v);
            dfs2(v);
            tmp[c[u]].pop_back();
            ans[c[u]] -= f(y[v]);
        }
    }
}

void solve() {
    dfs(0);
    fill(used, used + n, false);
    for (int i = 0; i < n; ++i) {
        ans[i] = f(n);
        y[i] = sz[i];
        z[i] = n;
    }
    dfs2(0);
    for (int i = 0; i < n; ++i) {
        ans[i] -= f(z[i]);
        cout << ans[i] << "\n";
    }
}

signed main() {

#ifdef __LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif

//    int t;
//    cin >> t;
//    for (int i = 0; i < t; ++i) {
        read();
        solve();
//    }

    return 0;
}

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

int main(void){
    int N, x;
    cin >> N >> x;
    vector<int> a(N);

    for(int i=0 ;i <N;i++){
      cin>>a[i];
    }
    sort(a.begin(), a.end());//昇順ソート

    // for(int i=0 ;i <N;i++){
    //   cout<<a[i]<<endl;
    // }

    vector<int> sum(N);
    sum[0] = a[0];
    if (sum[0] > x){
      cout<<0<<endl;
      return 0;
    }
    for(int i=1 ;i <N;i++){
      sum[i] += sum[i-1]+a[i];
      //cout<<sum[i]<<endl;
      if (sum[i] > x){
        cout<<i<<endl;
        return 0;
      }
    }

    if(sum[N-1]==x){
      cout<<N<<endl;
    }
    else{
      cout<<N-1<<endl;
    }

    // cout<<<<endl;
    // printf("%d");



    return 0;
}


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

int main(){
  int k,x;
  cin >> k >> x;
  int ka,jou;
  ka = max(x-(k-1),-1000000);
  jou = min(x+(k-1),1000000);
  for(int i=ka; i<=jou; i++){
    cout << i << ' ';
  }
  cout << endl;
}

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

using namespace std;

int main(int argc, char** argv){
    vector<tuple<string, int, int>> v(0);
    int N;
    cin >> N;
    for (int i=0; i<N; i++){
        string S;
        int P;
        cin >> S >> P;
        v.push_back(make_tuple(S, -P, i+1));
    }
    sort(begin(v), end(v));

    for (int i=0; i<N; i++) cout << get<2>(v[i]) << "\n";

    return 0;
}


Measured memory_bytes: 256