akhauriyash/Code-Regression huggingface dataset:
import os
import sys

import numpy as np


def solve(inp):
    r, c, k = inp[:3]
    items = np.zeros((r + 1, c + 1), dtype=np.int64)
    rrr = inp[3::3]
    ccc = inp[4::3]
    vvv = inp[5::3]
    for r_, c_, v in zip(rrr, ccc, vvv):
        items[r_][c_] = v

    dp = np.zeros((r + 1, c + 1, 4), dtype=np.int64)

    for i in range(1, r + 1):
        for j in range(1, c + 1):
            for w in range(4):
                dp[i][j][w] = max(dp[i][j - 1][w], dp[i - 1][j][3])
            if items[i][j] > 0:
                for w in range(2, -1, -1):
                    dp[i][j][w + 1] = max(dp[i][j][w + 1], dp[i][j][w] + items[i][j])

    return dp[r][c][3]


if sys.argv[-1] == 'ONLINE_JUDGE':
    from numba.pycc import CC

    cc = CC('my_module')
    cc.export('solve', '(i8[:],)')(solve)
    cc.compile()
    exit()

if os.name == 'posix':
    # noinspection PyUnresolvedReferences
    from my_module import solve
else:
    from numba import njit

    solve = njit('(i8[:],)', cache=True)(solve)
    print('compiled', file=sys.stderr)

inp = np.fromstring(sys.stdin.read(), dtype=np.int64, sep=' ')
ans = solve(inp)
print(ans)


Measured memory_bytes: 386748
x,n=map(int,input().split())

if n!=0:
  l=list(map(int,input().split()))
  d={}
  for i in l:
    if i not in d:
      d[i]=1
    else:
      d[i]+=1
  ct=0
  while 1:
    if x-ct not in d:
      print(x-ct)
      break
    elif x+ct not in d:
      print(x+ct)
      break
    ct+=1
    
else:
  print(x)


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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s, t;
    cin >> s >> t;
    if (t.size() != (s.size() + 1)) cout <<"No\n";
    else {
        bool yes = true;
        for (int i = 0; i < s.size() && yes; i++) {
            if (s[i] != t[i]) {
                yes = false;
            }
        }
        cout << (yes ? "Yes\n" : "No\n");
    }
}


Measured memory_bytes: 3656
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<ctime>
#include<cstdio>
#include<string>
//#include<string>
//#include<sstream>
using namespace std;
int main()
{
	int k,s;
	scanf("%d%d",&k,&s);
	int i,j,b,sum=0;
	for(i=0;i<=k;i++){
		for(j=0;j<=k&&j<=s-i;j++){
			if(s-i-j<=k) sum++;
		}
	}
	printf("%d\n",sum);
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <cstdio>
#include <cstdlib>
#include <string>
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
#include <bitset>
#include <cmath>
#include <limits>
#include <iostream>
#include <map>
#include <set>
#include <tuple>
using namespace std;
#define INF 1LL << 30
#define MAX 100000
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> P;
//typedef pair<pair<int,int>,int> p;
#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)
struct edge
{
    ll to, cost, val;
};
template <class T, class U>
bool chmin(T &a, const U &b)
{
    if (a <= b)
        return false;
    a = b;
    return true;
}
template <class T, class U>
bool chmax(T &a, const U &b)
{
    if (a >= b)
        return false;
    a = b;
    return true;
}
//__builtin_popcount(S);
//C.erase(unique(C.begin(),C.end()),C.end());
//#define int ll

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

    int N;
    cin>>N;
    int x;
    if(N%2==1) x=N;
    else x=N+1;
    vector<P> V;
    int count=0;
    for(int i=1;i<=N;i++){
        for(int j=i+1;j<=N;j++){
            if(i==j || i+j==x) continue;
            V.push_back(P(i,j));
        }
    }
    cout<<(int)V.size()<<endl;
    for(P v:V){
        cout<<v.first<<" "<<v.second<<endl;
    }
}


Measured memory_bytes: 384
/*
sonu_verma1
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb(a) push_back(a)
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL)
int main()
{
	string s;
	cin>>s;
	if(s[0]=='7'||s[1]=='7'||s[2]=='7')
		cout<<"Yes";
	else
		cout<<"No";


	return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int INF=1001001001;
#define PI 3.14159265359
 
long long int answ(long long int x){
  if(x==1) return 1;
  if(x>1) return 2*answ(x/2)+1;
}
int main() {
    int r;
    cin>>r;
    double ans=r*2*PI;
    
    cout<<ans<<endl;
 
 
}

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<long long, long long> pll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
typedef vector<pair<int,int> > vii;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<pair<long long,long long> > vpll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef pair<int,pair<int,int> > iii;
#define PI 3.141592653589793
#define mod 1000000009
# define N 100005
template<typename T> T gcd(T a,T b) { if(a==0) return b; return gcd(b%a,a); }
template<typename T> T pow(T a,T b, ll m){T ans=1; while(b>0){ if(b%2==1) ans=(ans*a)%m; b/=2; a=(a*a)%m; } return ans%m; }
# define INF (ll)1e18
# define LG 20	
typedef pair<int,pair<int,int> > pii;
# define INF_D 10000000000.00

map<ll,ll>m;

int main()
{
	int n;
	cin >> n;
	ll a[n+1];
	ll sum=0;
	m[0]++;
	for(int i=1;i<=n;i++)
	{
		cin >> a[i];
		sum+=a[i];
		m[sum]++;
	}
	ll ans=0;
	for( map<ll,ll>::iterator it=m.begin();it!=m.end();it++)
	{
		ans+=((it->second)-1)*(it->second)/2;
	}
	cout << ans;

}

Measured memory_bytes: 14336
def examA():
    S, T = LSI()
    ans = T+S
    print(ans)
    return

def examB():
    return

def examC():
    return

def examD():
    return

def examE():
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,inf
mod = 10**9 + 7
inf = float('inf')

if __name__ == '__main__':
    examA()


Measured memory_bytes: 3568
a, b, x = [int(i) for i in input().split()]

total = 0
if x > b:
    if a == 0:
        total += 1
else:
    q = a // x
    r = a % x
    if r == 0:
        total += 1
    next_ = x * (q + 1)

    if next_ <= b:
        total += 1
        total += ((b - next_) // x)

print(total)


Measured memory_bytes: 3060
def main():
 num = list(map(int,input().split()))
 bad = list(map(int,input().split()))

 while True :
  flg=0
  
  for i in range(0,len(str(num[0]))):
   stnum=str(num[0])
   if int(stnum[i]) in bad:
    flg=1
    break
   
  if flg==1:
   num[0]+=1
   continue
  else:
   break
  
 print(num[0])

main()

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <iomanip>

using namespace std;

int main(){
	string s;
	cin >> s;
	int len = s.length();
	if(s[len-1] == 's'){
		cout << s << "es\n";
	}
	else{
		cout << s << "s\n";
	}
	return 0;
}

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

#define ALL(v) v.begin(), v.end()
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)

using namespace std;
int main() {

	int N;
	cin >> N;

	vector<int> A(N), B(N), C(N);

	REP(i, N) 	cin >> A[i];
	REP(i, N) 	cin >> B[i];
	REP(i, N) 	cin >> C[i];

	sort(ALL(A));
	sort(ALL(B));
	sort(ALL(C));
	long long ans = 0;
	long long a = 0, c = 0;
	REP(i, N) {
		a = (lower_bound(ALL(A), B[i]) - A.begin());
		c = (C.end() - upper_bound(ALL(C), B[i]));
		ans += a * c;
	}



	cout << ans;


}

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

int main(){
	while(1){
		int n;
		cin >> n;
		if(n == 0) break;
		string s;
		cin >> s;
		string ans;
		for(int i = 0;i < n;i++){
			ans = "";
			for(int j = 0;j < s.length();j++){
				char c = s[j];
				size_t k = j;
				while(s[k] == c && k < s.length()) k++;
				stringstream ss;
				ss << (k - j);
				ans += ss.str();
				ans += c;
				j += (k - j) - 1;
			}
			s = ans;
		}
		cout << ans << endl;
	}
	
	return 0;
}

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

int main(){
  int a,b,c,f,e;
 cin>>a>>b>>c;
  f=min(a,b);
  vector<int>d(f+1);
  d[0]=0;
  e=0;
  for(int i=1;i<f+1;i++){
    d[i]=0;
  if(a%i==0&&b%i==0){
    d[i]=i;
  }
    
    }
  for(int i=0;i<f+1;i++){
    if(d[f-i]==0){
    continue;
    }
 else{
 e++;
 if(e==c){
 e=d[f-i];
   break;
 }
 }
    }
  cout<<e<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll inf=1000000000000000000;
double pi=2*acos(0);
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}

int main(){
    ios::sync_with_stdio(false);cin.tie(0);
    ll n;cin>>n;
    ll ans=0;
    if(n%2==1){
        cout<<0<<endl;
        return 0;
    }
    else{
        ll now=2;
        for(;;){
            now*=5;
            if(n<now)break;
            ans+=n/now;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
#include<set>
#include<map>

using namespace std;
typedef long long ll;
#define i_7 1000000007
#define i_5 1000000005

ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
#define inf 100000000/*10^8*/

/////////////////////////////////

int main(){
    ll x,y;cin>>x>>y;
    if(x%y==0)cout<<-1<<endl;
    else cout<<x<<endl;
    return 0;
}

Measured memory_bytes: 256
from itertools import accumulate
INF = float('inf')
N = int(input())
A = [int(x) for x in input().split()]

cumA = list(accumulate(A))
ans = INF
for i in range(N - 1):
    x = cumA[i]
    y = cumA[N - 1] - cumA[i]
    ans = min(ans, abs(x - y))

print(ans)

Measured memory_bytes: 30568
#include <bits/stdc++.h>
typedef long long int ll;
#define vaibhavv06               \
	ios::sync_with_stdio(false); \
	cin.tie(NULL);               \
	cout.tie(0);
#define int long long
#define MM(a,b) memset(a,b,sizeof(a))
const ll MOD = 1000000007;
using namespace std;



int32_t main() {
	vaibhavv06;
    int m,n; cin>>m>>n;
	if(m==n) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}

Measured memory_bytes: 256
import math

N,M = list(map(int,input().strip().split()))
ans = 1
i = 0

def is_prime(num):
    if num < 2:
        return False
    if num == 2 or num == 3 or num == 5:
        return True
    if num % 2 == 0 or num % 3 == 0 or num % 5 == 0:
        return False

    prime = 7
    step = 4
    num_sqrt = math.sqrt(num)
    while prime <= num_sqrt:
        if num % prime == 0:
            return False
        prime += step
        step = 6 - step

    return True

if is_prime(M) == False:
    while M//2 >= N+i:
        if M%(N+i) == 0:
            ans = M//(N+i)
            break
        else:
            i += 1

print(ans)

Measured memory_bytes: 3064
#include<cstdio>
#include<algorithm>
#include<string>
using namespace std;
int n;
int ans=0,a[15][15];
int get_f(int x)
{
    int b;
    while(x)
    {
        b=x%10;
        x/=10;
    }
    return b;
}
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        a[get_f(i)][i%10]++;
    }
    for(int i=0;i<10;i++)
    {
        for(int j=0;j<10;j++)
        {
            ans+=a[i][j]*a[j][i];
        }
    }
    printf("%d",ans);
}


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

int main (){
  int n;
  cin >> n;
  vector<int>v;
  for(int i=0;i<n;i++){
    int a;
    cin >> a;
    a--;
    v.push_back(a);
  }
  int now =0,c=0;
  for(;;){
    if(now == 1){
      cout << c <<endl;
      break;
    }
    if(c>=n){
      cout << -1 << endl;
      break;
    }
    c++;
    now = v[now];
  }
}

Measured memory_bytes: 892
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,s,e) for (int i=s;i<(e);i++)
#define All(v) (v).begin(),(v).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define int long long
using namespace std;
typedef long long llint;
typedef pair<int, int> P;
const int MOD = (int)1e9 + 7;
const int INF = (int)1e18 * 5;

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

    int N, K;
    cin >> N >> K;
    REP(i, N){
        int x;
        cin >> x;
    }
    cout << (N-2)/(K-1) + 1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll n,a,b,h[100001],cnt;
ll l=1,r=1e9,mid;
int main()
{
	cin>>n>>a>>b;
	a-=b;
	for (int i=0;i<n;++i) cin>>h[i];
	while (l!=r)
	{
		mid=(l+r)>>1;
		ll ans=0;
		for (int i=0;i<n;++i)
		{
			cnt=b*mid;
			if (cnt<h[i]) ans+=(h[i]-cnt-1)/a+1;
		}
		if (ans<=mid) r=mid;
		else l=mid+1;
	}
	cout<<l;
    return 0;
}

Measured memory_bytes: 1024
#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() {
    int n; cin >> n;
    vector<int> a1(n), a2(n), dp(n, 0);
    rep(i, n) {
        cin >> a1[i];
        if(i!=0) a1[i] += a1[i-1];
    }
    rep(i, n) cin >> a2[i];
    rep(i, n) {
        if(i!=0) dp[i] = max(a1[i]+a2[i],dp[i-1]+a2[i]);
        else dp[i] = a1[i] + a2[i];
    }
    cout << dp[n-1];
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm> 
#include <utility> 
#include <tuple> 
#include <cstdint> 
#include <cstdio> 
#include <map> 
#include <queue> 
#include <set> 
#include <stack> 
#include <deque> 
#include <unordered_map> 
#include <unordered_set> 
#include <bitset> 
#include <cctype> 
#include <cmath>
#include <iomanip>
#include <ctype.h>

using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi >;
using vl = vector<ll>;
using vvl = vector<vl >;
using pairi = pair<int, int>;
using pairl = pair<ll, ll>;

#define TR ","
#define TS " "
#define rep(i,N) for(int i=0;i<(int)N;++i)
#define rpt(i,a,b) for(int i=a;i<(int)b;++i)
#define all(v) v.begin(), v.end()
#define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)

ll gcd(ll a, ll b) {
    if (a < b) swap(a, b);
    if (b == 0) return a;
    return gcd(b, a % b);
}

ll lcm(ll x, ll y) {
    return x / gcd(x, y) * y;
}

void printVector(const vector<int>& vec) {
    for (int value : vec) {
        cout << value << " ";
    }
    cout << endl;
}

vector<int> IntegerToVector(int bit, int N) {
    vector<int> S;
    for (int i = 0; i < N; ++i) {
        if (bit & (1 << i)) {
            S.push_back(i);
        }
    }
    return S;
}

int main()
{
    IO;

    int N, j = 0, k = 0; cin >> N;
    vector<char> c(N);
    rep(i, N) {
        cin >> c[i];
        if (c[i] == 'W') ++j;
    }
    rpt(i, N - j, N) {
        if (c[i] == 'W') ++k;
    }
    cout << j - k << endl;

}

Measured memory_bytes: 3648
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner(System.in);
		int a = sc.nextInt(), b = sc.nextInt();
		int xmin = (int)Math.ceil(a/0.08);
		int xmax = (int)Math.floor((a+0.99)/0.08);
		int ymin = (int)Math.ceil(b/0.1);
		int ymax = (int)Math.floor((b+0.99)/0.1);
		int min = Math.max(xmin, ymin);
		int max = Math.min(xmax, ymax);
		if(min > max) {
			System.out.println(-1);
		}else{
			System.out.println(min);
		}
	}
	
	static class FastScanner {
		private BufferedReader reader = null;
	    private StringTokenizer tokenizer = null;
	    public FastScanner(InputStream in) {
	        reader = new BufferedReader(new InputStreamReader(in));
	        tokenizer = null;
	    }

	    public String next() {
	        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                tokenizer = new StringTokenizer(reader.readLine());
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }
	        return tokenizer.nextToken();
	    }

	    public String nextLine() {
	        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                return reader.readLine();
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }

	        return tokenizer.nextToken("\n");
	    }

	    public long nextLong() {
	        return Long.parseLong(next());
	    }

	    public int nextInt() {
	        return Integer.parseInt(next());
	    }

	    public double nextDouble() {
	         return Double.parseDouble(next());
	     }

	    public int[] nextIntArray(int n) {
	        int[] a = new int[n];
	        for (int i = 0; i < n; i++)
	            a[i] = nextInt();
	        return a;
	    }

	    public long[] nextLongArray(int n) {
	        long[] a = new long[n];
	        for (int i = 0; i < n; i++)
	            a[i] = nextLong();
	        return a;
	    }
	}
}


Measured memory_bytes: 32852
n,q=map(int,input().split())
edge=[[] for _ in range(n)] #木
cnt=[0]*n #出力用
for i in range(n-1): #辺の本数は頂点数-1
  a,b=map(int,input().split())
  a-=1
  b-=1
  edge[a].append(b)
  edge[b].append(a)
for _ in range(q):
  p,x=map(int,input().split())
  p-=1
  cnt[p]+=x
done=[False]*n #到達
par=0 #0からスタート
done[par]=True
stack=[par]
while stack:
  par=stack.pop()
  for chi in edge[par]:
    if done[chi]:
      None
    else:
      done[chi]=True
      cnt[chi]+=cnt[par]
      stack.append(chi)
    
print(*cnt)

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

n = int(input())
a = list(map(int, input().split()))
r_a = ["" for _ in range(n)]


sum = 0
for i in range(n):
    r_a[i] = 1/a[i]
    sum = sum + r_a[i]

print(1/sum)


Measured memory_bytes: 2940
S=input()

S=''.join(list(reversed(S)))

SS=['maerd','remaerd','esare','resare']

e=0
f=0

while e==0:
    s=1
    for i in range(len(SS)):
        if S[f:f+len(SS[i])]==SS[i]:
            f+=len(SS[i])
            s=0
    if f==len(S):
        print('YES')
        e=1
    if s==1:
        print('NO')
        e=1



Measured memory_bytes: 3956
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#pragma region Macros
#define FOR(i, m, n) for (ll i = (ll)(m); i < (ll)(n); i++)
#define rep(i, n) FOR(i, 0, n)

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

template <class T> string join(const T &v, const string delim = ",")
{
    if (v.empty())
        return "";

    ostringstream res;
    res << v[0];
    for (int i = 1; i < v.size(); i++)
    {
        res << delim << v[i];
    }
    return res.str();
}

#pragma endregion Macros

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

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

    vector<ll> t(N, -1);

    int c = 0;
    ll s = 0;

    ll l ; //ループするまでの移動回数
    ll m; //ループの大きさ

    rep(i,N){
        if(t[c] != -1){
            l = t[c];
            break;
        } 
        t[c] = s++;
        c = A[c];
    }

    m = s-l;

    cerr << join(t) << endl;

    ll ans;
    if(K < l){
        K %= s;
        rep(i,N){
            if(t[i] == K){
                ans = i+1;
                break;
            }
        }
    }else{
        K -= l;
        K %= m;
        rep(i,N){
            if(t[i] >= l && (t[i]-l == K)){
                ans = i+1;
                break;
            }
        }

    }

    cout << ans << endl;
}


Measured memory_bytes: 8124
#include <iostream>
#include <algorithm>
#include <ios>     // std::left, std::right
#include <iomanip> // std::setw(int), std::setfill(char)
using namespace std;

int main(){
    int A, B, C;
    int X;
    int cnt = 0;
    int num[3];
    cin >> A >> B >> C >> X;
    for (int a = 0; a <= A; a++){
        for (int b = 0; b <= B; b++){
            for (int c = 0; c <= C; c++){
                int sum = 500*a + 100*b + 50*c;
                if (sum == X){
                    cnt++;
                }
            }
        }
    }
    cout << cnt << endl;
}


Measured memory_bytes: 384
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**7)

N,M=map(int,input().split())

L=[[]for i in range(N+1)]
D=dict()
for i in range(M):
    l,r,d=map(int,input().split())
    L[l].append([r,d])
    L[r].append([l,-d])
    D[i]=(l,r,d)
    
C=["N" for i in range(N+1)]

def dfs(x):
    for i,j in L[x]:
        if C[i]=="N":
            C[i]=C[x]+j
            dfs(i)

for i in range(1,N+1):
    if C[i]=="N":
        C[i]=0
        dfs(i)
#print(C)
#print(D)
for i in range(M):
    l,r,d=D[i]
    if C[r]-C[l]!=d:
        print("No")
        exit()
print("Yes")

Measured memory_bytes: 162812
S = input()
T = input()

S_list = []
T_list = []
for _ in S:
  S_list.append(_)
for _ in T:
  T_list.append(_)

S_list.sort()
T_list.sort(reverse=True)

S=''
T=''
for _ in S_list:
  S+=_
for _ in T_list:
  T+=_


if S<T:
  ans='Yes'
else:
  ans='No'


print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1000000007;
constexpr lint INF = mod * mod;
constexpr int MAX = 200010;

int main(){
    int K;
    scanf("%d", &K);
    int tmp = 7;
    For(i, 1, K+10){
        if(tmp % K == 0){
            printf("%d\n", i);
            return 0;
        }
        tmp = (tmp * 10 + 7) % K;
    }
    puts("-1");
}

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

int sort(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}

int main()
{
  int n = 0;
  int ary[200005];
  int jud = 0;
  
  scanf("%d",&n);
  
  for(int i = 0;i < n;i++)
  {
    scanf("%d",&ary[i]);
  }
  
  qsort(ary, n, sizeof(int), sort);
  
  for(int i = 0;i < (n-1);i++)
  {
    if(ary[i] == ary[i+1])
    {
      jud++;
    }
  }
  if(jud == 0)
  {
    printf("YES");
  }
  else
  {
    printf("NO");
  }
    return 0;
}


Measured memory_bytes: 1788
const main = (input) => {
  input = input.trim().split('\n')

  let [, k] = input[0].split(' ').map(BigInt)
  const cities = input[1].split(' ').map(v => parseInt(v, 10) - 1)

  let size = null
  let loop_size
  let before_loop = null

  for (let arr=[0], his={ 0:1 }, i=0; true;) {
    if (~~his[cities[i]]) {
      before_loop = arr.indexOf(cities[i])
      size = arr.length
      loop_size = size - before_loop
      break
    }

    arr.push(cities[i])
    his[cities[i]] = 1
    i = cities[i]
  }


  let pre_move = 0
  let move = k

  if (size < k) {
    pre_move = before_loop
    k -= BigInt(before_loop)
    move = k % BigInt(loop_size)
  }

  // console.log('size', size)
  // console.log('loop_size', loop_size)
  // console.log('before', before_loop)
  // console.log('move', move)
  //
  // console.log('cities', cities)


  let ans = 0
  for (let i=0; i<pre_move; i++) ans = cities[ans]
  for (let i=0n; i<move; i++) ans = cities[ans]
  return console.log(ans + 1)
}

process.env.MYTEST
  ? (process.env.MYTEST === 'test' ? test() : main(require('fs').readFileSync('dev/stdin', 'utf8')))
  : main(require('fs').readFileSync('/dev/stdin', 'utf8'))

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

int main(){

	long long int n, x, a, b, ans = 0, i, z;
	cin >> n >> x;
	cin >> a;
	for (i = 1; i < n; i++) {
		cin >> b;
	    z = x;
		if (a + b > x){
			ans += b;
			b -= x < a ? b : (a + b) - x;
			ans -= b;
			ans += (!b && a > x? a - x: 0);
		}
		a = b; x = z; 
}
cout << ans;
return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[100009];
main(){
    //x+2y<=n
    int n;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    sort(a, a+n);
    if(a[n - 1] > a[0] + 1) {
        cout << "No"<<endl;
        return 0;
    }
    if(a[n - 1] == a[0]){
        if(a[0] == n - 1){
            cout << "Yes"<<endl;
            return 0;
        }
        if(2 * a[0] <= n){
            cout << "Yes"<<endl;
            return 0;
        }
        cout << "No"<<endl;
        return 0;
    }
    int x = 0;
    for(int i = 0; i < n; i++){
        if(a[i] == a[0]) x++;
    }
    int y = a[n - 1] - x;
    if(y <= 0){
        cout << "No"<<endl;
        return 0;
    }
    if(x + 2 * y > n){
        cout << "No"<<endl;
    }
    else cout <<"Yes"<<endl;

}


Measured memory_bytes: 640
# kaisetsu no marupakuri yan ke
n = gets.to_i

$facts = Array.new(n + 1, 0)
2.upto(n) do |k|
  2.upto(n) do |p|
    while k % p == 0
      k /= p
      $facts[p] += 1
    end
  end
end

def num(m)
  $facts.select {|i| i >= m}.size
end

p num(74) +
  num(24) * (num(2) - 1) +
  num(14) * (num(4) - 1) +
  num(4) * (num(4) - 1) * (num(2) - 2) / 2

Measured memory_bytes: 1916
a, b, c = map(int,input().split())
k = int(input())
cnt_b = 0
cnt_c = 0

while b <= a:
    b = b * 2
    cnt_b += 1
    if b > a:
        break
while c <= b:
    c = c * 2
    cnt_c += 1
    if c > b:
        break
if cnt_b + cnt_c <= k:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9120
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int pW[1000000];
int sE[1000000];
char s[1000000];
int main()
{
    ios_base::sync_with_stdio(0);
    int n;
    cin>>n;
    for (int i=1;i<=n;i++)
    {
        cin>>s[i];
        if (s[i]=='W')
            pW[i]=pW[i-1]+1;
        else
            pW[i]=pW[i-1];
    }
    for (int i=n;i>=1;i--)
    {
        if (s[i]=='E')
            sE[i]=sE[i+1]+1;
        else
            sE[i]=sE[i+1];
    }
    int ret=1e9;
    for (int i=1;i<=n;i++)
        ret=min(ret,pW[i-1]+sE[i+1]);
    cout<<ret<<endl;
}


Measured memory_bytes: 5760
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		
		System.out.println((int)Math.pow(k - 1,  n - 1) * k);

	}

}


Measured memory_bytes: 23892
#include <vector>
#include <list>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <cstdio>
#include <climits>
#include <complex>
#include <cstdint>
#include <tuple>

#define M_PI       3.14159265358979323846

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }
inline int readInt() { int x; scanf("%d", &x); return x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util

//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
int n, m;


int main() {
    //cout << fixed << setprecision(15);

    LL M, K; cin >> M >> K;

    if((M==1 && K==1) || pow(2, M)-1 < K) {
        cout << -1 << endl;
        return 0;
    }

    if(K==0){
        for(int i=0; i<pow(2, M); ++i){
            if(i==0) {
                cout << i;
                cout << " " << i;
            }else{
                cout << " " << i << " " << i;
            }
        }
        cout << endl;
    }else{
        cout << 0 << " " << K << " " << 0;
        for(int i=pow(2, M)-1; i>=1; --i){
            if(i==K) continue;
            cout << " " << i;
        }
        cout << " " << K;
        for(int i=1; i<pow(2, M); ++i){
            if(i==K) continue;
            cout << " " << i;
        }
    }
    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#include<bits/stdc++.h>
#include <vector>
#define ll long long int
#define ve vector<int>
#define pb push_back
#define mod 1000000007
#define INF 1e18
using namespace std;
ll dp[100001];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll n,w;cin>>n>>w;
ll val[n],wei[n];
ll sum=0;
for(int i=0;i<n;i++)
{
cin>>wei[i]>>val[i];
sum+=val[i];
}

for(int i=0;i<=100000;i++)
dp[i]=INF;

dp[0]=0;
for(int i=0;i<n;i++)
{
	for(int j=sum;j>=val[i];j--)
	{
		dp[j]=min(dp[j-val[i]]+wei[i],dp[j]);
	}
}

ll ans=0;
for(ll i=0;i<=100000;i++)
{
	if(dp[i]<=w)
	ans=max(ans,i);
}

cout<<ans;

}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
// Begin Header {{{
#define all(x) (x).begin(), (x).end()
#define lli long long int
#define rep(i,n) for(lli i=0; i<n; i++)
#define loop(i, j, n) for(lli i=j; i<n; i++)
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) < (b) ? (a) : (b))
constexpr int INF  = 0x3f3f3f3f;
const long long mod=1e9+7;
//Function
lli combi(lli n, lli r)
{
	if(r==0 || r==n) return 1;
	else return combi(n-1,r) + combi(n-1,r-1);
}
lli sigma1(lli n){return n*(n+1)/2;}
lli sigma2(lli s, lli n){return sigma1(n) - sigma1(s -1);}
using namespace std;
// }}} End Header

int main()
{
	ios::sync_with_stdio(false); cin.tie(nullptr);
	string s;
	cin >> s;
	lli j=0, k=0;
	rep(i,s.size()){
		if(s.at(i) == '0') j++;
		else k++;
	}
	cout << Min(j, k)*2 << endl;
	return 0;
}

Measured memory_bytes: 512
import collections
n=int(input())
a=list(map(int, input().split())) 
ans = 0
ru = []

for i in range(n):
    ru.append(int(i + 1 + a[i]))

c = collections.Counter(ru)
#print(c)

for i in range(n):
    tmp = i + 1 - a[i]
    ans += c[tmp]

print(ans)

Measured memory_bytes: 42760
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>

int main(){
    std::vector<int> v(3);
    for(int i = 0;i < 3;i++){
        std::cin>>v[i];
    }

    std::sort(v.begin(), v.end());
    std::cout<<v[0] + v[1]<<std::endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
typedef long long  ll;
#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)

ll n, a, b;
ll h[100001] = {};
ll k[100001] = {};
bool condition(ll T) {
	rep(i, 0, n) {
		k[i] = h[i];
	}

	ll H = b * T;

	rep(i, 0, n) {
		k[i] -= H;
	}

	ll cnt = 0;
	rep(i, 0, n) {
		if (k[i] > 0) {
			cnt += k[i] / (a - b) + ((k[i] % (a - b) == 0) ? 0 : 1);
		}
	}
	return cnt <= T;
}

int main() {
	cin >> n >> a >> b;
	ll maxH = 0;
	rep(i, 0, n) {
		cin >> h[i];
		maxH = max(maxH, h[i]);
	}

	ll T = 0;

	ll r = maxH / b + 1;
	ll l = 0;

	while (r - l != 1) {
		ll T = (r + l) / 2;
		if (condition(T)) {
			r = T;
		}
		else {
			l = T;
		}
	}
	cout << r << endl;

	return 0;
}

Measured memory_bytes: 1792
a, b, c, k = map(int, input().split())
if k <= a:
	print(k)
elif k <= (a+b):
	print(a)
elif k <= (a+b+c):
	e = a+b+c-k
	f = a-c+e
	print(f)
else:
	d = a - c
	print(d)

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

int main(){
    using namespace std;
    unsigned long N;
    cin >> N;
    puts([&]{for(unsigned long i{0}, A; i < N; ++i){
        cin >> A;
        if(A % 2 == 0 && A % 3 != 0 && A % 5 != 0)return false;
    }return true;}() ? "APPROVED" : "DENIED");
    return 0;
}

Measured memory_bytes: 764
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoderCs
{

    class Program
    {

        const int Mod = 1000000007;

        static void Main()
        {

            var arg = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            var list = new bool[arg[0]];
            for (int i = 0; i < arg[0]; i++) list[i] = true;
            var high = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();

            for (int i = 0; i < arg[1]; i++)
            {

                var select = Console.ReadLine().Split(' ').Select(x => int.Parse(x) - 1).ToArray();

                if (high[select[0]] < high[select[1]]) list[select[0]] = false;
                else if (high[select[0]] > high[select[1]]) list[select[1]] = false;
                else
                {

                    list[select[0]] = false;
                    list[select[1]] = false;
                }

            }

            Console.WriteLine(list.Count(x => x));

        }



    }
}


Measured memory_bytes: 49572
#include <iostream>
#include <algorithm>
#include <map>
#include <utility>
#include <vector>
#include <cstdio>
#include <iomanip>
#include <cmath>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < n; i++)

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

    int premax = 0;
    int maxi;
    for (int i = 1; i <= n; i++) {
        if (A[i] > premax) {
            premax = A[i];
            maxi = i;
        }
    }

    A[maxi] = 0;
    int secondmax = 0;
    for (int i = 1; i <= n; i++) {
        if (A[i] > secondmax) {
            secondmax = A[i];
        }
    }

    for (int i = 1; i <= n; i++) {
        if (i == maxi) {
            cout << secondmax << endl;
        } else {
            cout << premax << endl;
        }
    }

    return 0;

}


Measured memory_bytes: 2432
import fractions

n=int(input())
a=[]
for i in range(n):
    a.append(int(input()))

if n==1:
    print(a[0])
    exit()
elif n==2:
    g=fractions.gcd(a[0],a[1])
    print(a[0]*a[1]//g)
    exit()

else:
    g=fractions.gcd(a[0],a[1])
    lcm=a[0]*a[1]//g
    for i in range(2,n):
        g=fractions.gcd(lcm,a[i])
        lcm=a[i]*lcm//g

    print(lcm)


Measured memory_bytes: 5560
def judge(k, N, A):
    p = N - 1
    t = 0
    for i in A:
        while p >= 0 and A[p] + i < k:
            p -= 1
        t += (p + 1)
    return t
def main():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    A.sort(reverse=True)
    t = A[0] * 2
    b = 0
    X = None
    while t - b > 1:
        m = (t + b)//2
        i = judge(m, N, A)
        if i == M:
            X = m
            break
        if i > M:
            ip = judge(m + 1, N, A)
            if ip == M:
                X = m + 1
                break
            if ip < M:
                X = m
                break
            b = m + 1
        if i < M:
            im = judge(m - 1, N, A)
            if im >= M:
                X = m - 1
                break
            t = m - 1
    if X is None:
        X = b
    r = 0
    p = N - 1
    k = sum(A)
    for i in A:
        while p >= 0 and A[p] + i < X :
            k -= A[p]
            p -= 1
        r += i * (p + 1) + k
    return r - (judge(X, N, A) - M) * X
print(main())


Measured memory_bytes: 14020
N = gets.to_i
A = gets.split.map(&:to_i)
min = A.min
index = 1
loop do
    if A.count{|a| a%min!=0} == 0 then
        puts min
        break
    else
        n_min = min
        N.times do |i|
            next if A[i] == 0 || A[i] == min
            A[i] = A[i]%min
            n_min = A[i] if A[i] < n_min && A[i] > 0
        end
        min = n_min
    end
    index += 1
    break if index >= 100
end

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

int main() {
    string s;cin>>s;
    map<int,int>mp;
    mp[0]=1;
    int fac=1,curr=0,res=0;
    for(int i=s.length()-1;i>=0;i--)
    {
        curr=(curr+(s[i]-'0')*fac)%2019;
        res+=mp[curr];
        fac=(fac*10)%2019;
        mp[curr]++;
    }
    cout<<res;
    
	return 0;
}


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

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef unordered_set<int> si;
typedef pair<int, int> pp;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#define all(e) (e).begin(), (e).end()


template <typename T>
void printV(vector<T> A) {
    if (A.empty()) cerr << "EMTPY\n";
    else { 
        cerr << "[";
        for (int i = 0; i < A.size() -1 ; ++i) {
            cerr << A[i] << ", ";
        }
        if (A.size()) cerr << A.back() << "]\n";
    }
}


template <typename T>
void printVV(vector<vector<T>> A) {
    cerr << "[";
    for (auto v : A) {
        printV<T>(v);
    }
    cerr << "]";
}

template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
    cerr << name << ": " << arg1 << endl;
}

template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&& ...args) {
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << ": " << arg1 << " |";
    __f(comma + 1, args...);
}

const int N = 2001;
ll dp[N][N];

int main(int argc, char **argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n; cin >> n;
    vll arr(n+1);
    vi idx(n+1);
    for (int i = 1; i <= n; ++i) {
        cin >> arr[i];
        idx[i] = i;
    }

    sort(idx.begin() + 1, idx.end(), [&] (int a, int b) {
        return arr[a] > arr[b];
    });

    memset(dp,0,sizeof(dp));

    for (ll i = 1; i <= n; ++i) {
        ll pos = idx[i];
        ll val = arr[pos];
        for (int j = 0; j <= i-1; ++j) {
            dp[i][j+1] = max(dp[i][j+1], dp[i-1][j] + val * abs(pos - (j+1)));
            dp[i][j] = max(dp[i][j], dp[i-1][j] + val * abs(pos - (n - i + j + 1)));
        }
        cout << endl;
    }

    ll ans = 0;
    for (int i = 0; i <= n; ++i) {
        ans = max(ans, dp[n][i]);
    }

    cout << ans << '\n';
   
    return 0;
}



Measured memory_bytes: 34908
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef pair<ll, ll> P;



int main(){
    ll n;
        cin >> n;
    ll tmp = sqrt(n);
    for(ll i=tmp; 0<i; i--){
        ll k = n/i;
        if(n%i==0){
            tmp = max(i, k);
            break;
        }
    }
    int cnt=0;
    while(0<tmp){
        cnt += 1;
        tmp /= 10;
    }
    cout << cnt << endl;
}

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

public class Main{
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        
        int cycle = 0;
        String line;
        while(!((line = br.readLine()).equals("0"))) 
            System.out.println("Case " + ++cycle + ": " + line);
    }
}

Measured memory_bytes: 31220
#include<cstdio>
using namespace std;

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

    int nums[n];
    for(int i=0;i<n;i++){
        nums[i]=0;
    }

    int a;
    for(int i=0;i<n-1;i++){
        scanf("%d", &a);
        nums[a-1] += 1;
    }

    for(int i=0; i<n; i++){
        printf("%d\n", nums[i]);
    }

    return 0;
}

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

using namespace std;
int main(){
  unsigned int A, B;
  cin >> A >> B;
  string in;
  cin >> in;

  if(in.length() != A+B+1){
    cout << "No" << endl;
  }else{
    unsigned int i;
    for(i = 0; i < A; i++){
      if(in[i] == '-'){
        cout << "No" << endl;
        return 0;
      }
    }
    if(in[A] != '-'){
      cout << "No" << endl;
      return 0;
    }
    for(i = A+1; i < A+B+1; i++){
      if(in[i] == '-'){
        cout << "No" << endl;
        return 0;
      }
    }
    cout << "Yes" << endl;
  }

}


Measured memory_bytes: 256
N, K = map(int, input().split())
h_list = list(map(int, input().split()))
dp = [float('INF') for i in range(N)]
dp[0] = 0
 
def update_dp(now, next):
  global h_list
  global dp
  global N
  if next > N - 1: return
  if dp[next] > dp[now] + abs(h_list[next] - h_list[now]):
    dp[next] = dp[now] + abs(h_list[next] - h_list[now])
  return
 
for i in range(N):
  for j in range(1, K + 1):
    update_dp(i, i + j)
 
print(dp[N - 1])

Measured memory_bytes: 57184
line = gets.split(' ').map(&:to_i)
a=line[0]
b=line[1]
c=line[2]
if (c-a-b)>0 then
  if (c-a-b)**2 > 4*a*b then
    puts "Yes"
  else
    puts "No"
  end
else
  puts "No"
end

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

int main(){
    ll n,m;
    cin>>n>>m;
    ll a[m],sum=0;
    for(ll i=0;i<m;i++) cin>>a[i],sum+=a[i];
    if(sum>n)   cout<<"-1"<<endl;
    else    cout<<n-sum<<endl;
    return 0;
}


Measured memory_bytes: 3648
#include <iostream>
using namespace std;
int main(void){
    string s[]={"light fly","fly","bantam","feather","light","light welter","welter","light middle","middle","light heavy","heavy"};
    int w[]={48,51,54,57,60,64,69,75,81,91};
    double a;
    
    while(cin>>a){
        int i,j;
        for(i=j=0; j<10; j++){
            if(w[i]<a) i++;
            else break;
        }
        cout<<s[i]<<endl;
    }
}



Measured memory_bytes: 3244
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#define graph_from1 true
typedef long long ll;
using namespace std;

class Graph_func
{
public:
	int N;
	int N_edge;
	int xtmp, ytmp;
	vector<pair<int, int> > edgelist;
	vector<vector<int> > adjlistX;
	vector<vector<int> > adjlistY;
	vector<int> adjnumX;
	vector<int> adjnumY;

	vector<bool> xE;
	vector<bool> yE;

	void read_edge();
	void adjini();
	void graph_num_sbrtX(int x);
	void graph_num_sbrtY(int x);
	ll graph_num();
};

void Graph_func::read_edge()
{
	cin >> N_edge;
	N = 100000;
	edgelist.resize(N_edge);
	adjnumX.resize(N);
	adjnumY.resize(N);
	adjlistX.resize(N);
	adjlistY.resize(N);
	xE.resize(N);
	yE.resize(N);
	for (int i = 0; i < N; i++)
	{
		xE[i] = 0;
		yE[i] = 0;
	}
	for (int i = 0; i < N_edge; i++)
	{
		cin >> edgelist[i].first >> edgelist[i].second;
		if (graph_from1)
		{
			edgelist[i].first--;
			edgelist[i].second--;
		}
		xE[edgelist[i].first] = 1;
		yE[edgelist[i].second] = 1;
	}
	return;
}

void Graph_func::adjini()
{
	for (int i = 0; i < N; i++)
	{
		xE[i] = !xE[i];
		adjnumX[i] = 0;
	}
	for (int i = 0; i < N; i++)
	{
		yE[i] = !yE[i];
		adjnumY[i] = 0;
	}
	for (int i = 0; i < N_edge; i++)
	{
		int x = edgelist[i].first;
		int y = edgelist[i].second;
		adjlistX[x].push_back(y);
		adjlistY[y].push_back(x);
		adjnumX[x]++;
		adjnumY[y]++;
	}
	return;
}

void Graph_func::graph_num_sbrtX(int x) // ex. graph_num_sbrt(i, filled);
{
	for (int i = 0; i < adjnumX[x]; i++)
	{
		int y_new = adjlistX[x][i];
		if (!yE[y_new])
		{
			yE[y_new] = true;
			graph_num_sbrtY(y_new);
			ytmp++;
		}
	}
	return;
}

void Graph_func::graph_num_sbrtY(int y) // ex. graph_num_sbrt(i, filled);
{
	for (int i = 0; i < adjnumY[y]; i++)
	{
		int x_new = adjlistY[y][i];
		if (!xE[x_new])
		{
			xE[x_new] = true;
			graph_num_sbrtX(x_new);
			xtmp++;
		}
	}
	return;
}

ll Graph_func::graph_num()
{
	ll anstmp = 0;
	int i = 0;
	bool end = false;
	while (!end)
	{
		if (i >= N)
			break;
		while (1)
		{
			if (!xE[i])
				break;
			i++;
			if (i >= N)
			{
				end = true;
				break;
			}
		}
		if (end)
			break;
		xE[i] = true;
		xtmp = 1;
		ytmp = 0;
		graph_num_sbrtX(i);
		anstmp += (ll)xtmp * (ll)ytmp;
	}
	return anstmp;
}

int main() {
	Graph_func graph;
	ll ans = 0;
	graph.read_edge();
	graph.adjini();
	ans = graph.graph_num();
	ans -= graph.N_edge;
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 13568