akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
const ll INF = 1e16;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)

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

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cout << a[i] << " "; cout << "\n"; }
template<class T> void verr(const vector<T>& v){ for(auto& a : v) cout << a << " "; cout << "\n"; }
ll dbgt = 1; void err() { cout << "passed " << dbgt++ << "\n"; }
template<class H, class... T> void err(H&& h,T&&... t){ cout<< h << (sizeof...(t)?" ":"\n"); if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}
//--------------------------------------------------------------------------------//
ll dp[3005][3005];
int main() {
    init();
    ll N, T;
    cin >> N >> T;
    vc<pair<ll, ll>> A(N);
    rep(i, N) cin >> A[i].first >> A[i].second;
    sort(all(A));
    
    rep(i,N){
        ll a, b;
        tie(a, b) = A[i];
        rep(j,T){
            if(j>=a)
                dp[i + 1][j] = max(dp[i][j], dp[i][j - a] + b);
            else
                dp[i + 1][j] = dp[i][j];
        }
    }

    ll ans = 0;
    rep(i,N){
        chmax(ans, dp[i][T - 1] + A[i].second);
    }
    cout << ans << endl;

}

Measured memory_bytes: 70784
import java.util.*;

class Main {
	Scanner sc = new Scanner(System.in);


	public boolean isPrime(int n){
		if(n<2)return false;

		for(int i=2;i*i<=n;i++){
			if(n%i==0)return false;
		}
		return true;
	}

	public void run() {
		while (sc.hasNext()) {
			int val=sc.nextInt();
			int lessP=0;int greatP=0;
			for(int i=val-1;;i--){
				if(isPrime(i)){
					lessP=i;break;
				}
			}
			for(int i=val+1;;i++){
				if(isPrime(i)){
					greatP=i;break;
				}
			}
			ln(lessP+" "+greatP);
		}
	}


	public static void main(String[] args) {
		new Main().run();
	}

	public static void pr(Object o) {
		System.out.print(o);
	}

	public static void ln(Object o) {
		System.out.println(o);
	}

	public static void ln() {
		System.out.println();
	}
}

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

int main(){
  int N,K;
  cin >> N >> K;
  vector<long long> h(N);
  for(int i=0; i<N; i++)  cin >> h.at(i);
  
  vector<long long> dp(N,-1);
  dp.at(0) = 0;
  
  for(int i=1; i<N; i++){
    for(int j=1; j<=K&&j<=i; j++){
      if(dp.at(i) == -1) dp.at(i) = dp.at(i-j) + abs(h.at(i) - h.at(i-j));
      dp.at(i) = min(dp.at(i), dp.at(i-j) + abs(h.at(i) - h.at(i-j)));
    }
  }
    
  cout << dp.at(N-1) << endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc  __builtin_popcountl
#define m_p make_pair
#define inf 1000000000000000000ll
#define MAXN 1000001
#define eps 0.0000000001
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>//usage rand<long long>()
T rand() {
    return uniform_int_distribution<T>()(rng);
}

// string to integer stuuu()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();

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

#define S second
#define F first
#define int long long  
///////

long long powerm(long long x, unsigned long long y, long long p) 
{ 
    long long res = 1;
    x = x % p;
    while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x) % p; 
        y = y>>1;
        x = (x*x) % p;   
    } 
    return res; 
} 

signed main()
{
	fastio;
	#ifdef ANIKET_GOYAL
		freopen("inputf.in","r",stdin);
		freopen("outputf.in","w",stdout);
	#endif
	string s;
	cin>>s;
	int mo=1000000007;
	int n=s.length();
	int ans=0;
	int c=0;
	for(int i=0;i<n;++i)
	{
		if(s[i]=='1')
		{
			ans+=(powerm(3,n-i-1,mo)*powerm(2,c,mo))%mo;
			++c;
			ans%=mo;
		}
	}
	ans+=powerm(2,c,mo);
	ans%=mo;
	cout<<ans;
}

Measured memory_bytes: 512
let id x = x

let t = Array.init (Scanf.scanf "%d " id) (fun _ -> Scanf.scanf "%d " id)

let px =
  Array.init (Scanf.scanf "%d " id) (fun _ ->
      Scanf.scanf "%d %d " (fun p x -> (p, x)) )


let sum = Array.fold_left ( + ) 0 t

let () =
  Array.iter (fun (p, x) -> sum - (t.(p - 1) - x) |> Printf.printf "%d\n") px


Measured memory_bytes: 512
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.par = [-1] * n
    def find(self, x):
        if self.par[x] < 0:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.find(x) > self.find(y):
            x, y = y, x
        self.par[x] += self.par[y]
        self.par[y] = x
    def size(self, x):
        return -self.par[(self.find(x))]
    def same(self, x, y):
        return self.find(x) == self.find(y)
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]
    def roots(self):
        return [i for i, x in enumerate(self.par) if x < 0]
    def group_count(self):
        return len(self.roots())
    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}
    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

n, m, k = map(int, input().split())
a, b = [0] * m, [0] * m
c, d = [0] * k, [0] * k

direct =[[] for _ in range(n)]
uf = UnionFind(n)

for i in range(m):
    a[i], b[i] = map(int, input().split())
    a[i] -= 1
    b[i] -= 1
    direct[a[i]].append(b[i])
    direct[b[i]].append(a[i])
    uf.union(a[i], b[i])

for i in range(k):
    c[i], d[i] = map(int, input().split())
    c[i] -= 1
    d[i] -= 1
    if uf.same(c[i], d[i]):
        direct[c[i]].append(d[i])
        direct[d[i]].append(c[i])

ans = [0] * n
for i in range(n):
    ans[i] = uf.size(i) - len(direct[i]) - 1

print(*ans)

Measured memory_bytes: 39908
def bubble(N,C):
  for i in range(N):
    for j in range(i+1,N)[::-1]:
      if C[j][1] < C[j-1][1]:
        _=C[j]
        C[j]=C[j-1]
        C[j-1]=_
  print(*C)

def selection(N,C):
  for i in range(N):
    minj=i
    for j in range(i,N):
      if C[minj][1] > C[j][1]:
        minj=j
    _=C[minj]
    C[minj]=C[i]
    C[i]=_
  print(*C)

def stable(A,C):
  result='Stable'
  for i in range(1,10):
    a=[j for j in A if j[1]==str(i)]
    c=[k for k in C if k[1]==str(i)]
    if a!=c:
      result='Not stable'
  print(result)

N=int(input())
C=list(input().split())
A=C[:]
bubble(N,C)
stable(A,C)
C=A[:]
selection(N,C)
stable(A,C)


Measured memory_bytes: 5620
#include <cstdio>

using namespace std;
using ll = long long;

const int M = 2e5 + 5;
int n, k;
ll arr[M];

int main() {
    scanf("%d%d", &n, &k);
    for (int i = 0; i < n; i++) {
        scanf("%lld", arr + i);
    }
    for (int i = k, j = 0; i < n; i++, j++) {
        if (arr[j] < arr[i]) {
            puts("Yes");
        } else {
            puts("No");
        }
    }
    return 0;
}

Measured memory_bytes: 3204
#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
#define idfc ios_base::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
//:/
#define pb push_back
#define mp make_pair
#define nt _ll128
#define ld double
long double PI =3.14159265;
using ll = long long;

const ll modo=1e9+7;
const ll ms=1e5+5;
const ll inf=1e9+9;


int main()
{
    idfc;

    ll n;
    cin>>n;
    ll e;
    ll p=0;
    ll ans=0;
    while(n--)
    {
        cin>>e;
        if(p>e)
        {
            ans+=(p-e);
        }
        p=max(e,p);
    }
    cout<<ans;

    return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#include <set>
#include <queue>
using namespace std;
int n, m, a,b;
set<int> adj[(int)1e5+5];
 
void SPFA(){
    queue<int> pq;
    pq.push(1);
    vector<int> dist((int)1e5+5, 1e9);
    dist[1] = 0;
    vector<int> signpost((int)1e5+5, 1e9);
 
    while(!pq.empty()){
        int here = pq.front(); pq.pop();
        for(auto there : adj[here]){
            if(dist[there] > dist[here] + 1){
                dist[there] = dist[here] + 1;
                signpost[there] = here;
                pq.push(there);
            }
        }
    }
    for(int i = 2; i <= n ; ++i){
        if(dist[i] >= 1e9){
            cout << "No";
            return;
        }
    }
    cout << "Yes\n";
    for(int i = 2; i <= n ; ++i){
        cout << signpost[i] << "\n";
    }
}
 
int main(){
    cin >> n >> m;
    while(m--){
       cin >> a >> b;
       adj[a].emplace(b);
       adj[b].emplace(a);
    }
    SPFA();
    return 0;
}

Measured memory_bytes: 27652
unittest
{
	assert( [ "7", "100 130 130 130 115 115 150" ].solve == 1685 );
	assert( [ "6", "200 180 160 140 120 100" ].solve == 1000 );
	assert( [ "2", "157 193" ].solve == 1216 );
}



import std.conv;
import std.range;
import std.stdio;

void main()
{
	stdin.byLineCopy.solve.writeln;
}

auto solve( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = input.front.to!( long );
	input.popFront;
	auto as = input.front.split.to!( long[] );
	
	auto ans = 1000L;
	auto k = 0L;
	foreach( i; 0L .. as.length.signed - 1 )
	{
		if( as[ i ] < as[ i + 1 ] )
		{
			k += ans / as[ i ];
			ans %= as[ i ];
		}
		else
		{
			ans += k * as[ i ];
			k = 0;
		}
	}
	ans += k * as[ $ - 1 ];
	return ans;
}


Measured memory_bytes: 2756
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
	string s;
  	string t;
  	cin>>s;
  	cin>>t;
  	if(s == t.substr(0,t.size()-1))
    {
		cout<<"Yes"<<"\n";
    }
  	else
		cout<<"No"<<"\n";
}

Measured memory_bytes: 3628
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
typedef pair<LL, LL> pii;
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)


int main() {
	LL x, y;
	cin >> x >> y;
	cout << gcd(x, y) << endl;
}


Measured memory_bytes: 3088
import java.util.Scanner;

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

        for (int i = x - k + 1; i <= x + k - 1; i++) {
            System.out.print(i);

            if (i == x + k - 1) {
                System.out.println();
            } else {
                System.out.print(' ');
            }
        }
    }
}


Measured memory_bytes: 22868
#include <iostream>
#include <algorithm>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>

using namespace std;

/////////////         qsortのラッピング

class juice {
public:
	long price;
	long n;
};
int qsort_int_compare_ascend(const void *a, const void *b) {
	long x = ((juice*)a)->price - ((juice*)b)->price;
	if (x > 0) { return 1; }
	else if (x == 0) { return 0; }
	return -1;
}
void ascendOrder(int size, juice *array) {//sho-jun
	qsort(array, size, sizeof(juice), qsort_int_compare_ascend);
}

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

	juice *a = new juice[N];
	for (int i = 0; i < N; i++) {
		cin >> a[i].price >> a[i].n;
	}

	ascendOrder(N, a);
	long xsum = 0;
	for (int i = 0; i < N; i++) {
		if (a[i].n >= M) {
			xsum += a[i].price * M;
			break;
		}
		else {
			M -= a[i].n;
			xsum += a[i].price * a[i].n;
		}
	}

	cout << xsum;

	return 0;
}

Measured memory_bytes: 3324
#include <iostream>

int main()
{
    int a = 0;
    int b = 0;
    int c = 0;
    int count = 0;
    
    // input
    std::cin >> a;
    std::cin >> b;
    std::cin >> c;
    
    if( a < 1 || a > 10000 || b < 1 || b > 10000 || c < 1 || c > 10000 )
    {
        std::cout << "Error : out of range!" << std::endl;
        return -1;
    }
    
    if( a > b )
    {
        std::cout << "Error : a > b" << std::endl;
        return -2;        
    }
    
    for( int i = a; i <= b; ++i )
    {
        if( 0 == c % i )
        {
            ++count;
        }
    }
    
    std::cout << count <<std::endl;
    
    return 0;
}


Measured memory_bytes: 3100
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = Integer.parseInt(scanner.nextLine());
        long[] aArr = new long[n];
        long[] bArr = new long[n];

        String[] aLine = scanner.nextLine().split(" ", n);
        long aSum = 0;
        for (int i = 0; i < n; i++) {
            aArr[i] = Long.parseLong(aLine[i]);
            aSum += aArr[i];
        }

        long loseCount = 0;
        long loseTotal = 0;
        long[] diffArr = new long[n];

        String[] bLine = scanner.nextLine().split(" ", n);
        long bSum = 0;
        for (int i = 0; i < n; i++) {
            bArr[i] = Long.parseLong(bLine[i]);
            bSum += bArr[i];

            if (aArr[i] < bArr[i]) {
                loseCount++;
                loseTotal += bArr[i]- aArr[i];
            } else {
                diffArr[i] = aArr[i] - bArr[i];
            }
        }

        if (aSum < bSum) {
            System.out.println(-1);
            return;
        }

        long magicCount = 0;
        long magicTotal = 0;
        Arrays.sort(diffArr);
        for (int i = n - 1; i >= 0; i--) {
            if (loseTotal <= magicTotal) {
                System.out.println(loseCount + magicCount);
                return;
            }

            magicTotal += diffArr[i];
            magicCount++;
        }

        // should be unreachable, but don't wanna fail
        System.out.println(-1);
    }
}


Measured memory_bytes: 54440
#include<bits/stdc++.h>
#define REP(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
const ll MOD = 1000000007;

int main() {
  int n, ma = 0;
  cin >> n;
  int a[n];
  REP(i, n) cin >> a[i];

  REP(i, n) for (int j = i + 1; j < n; ++j) {
    ma = max(abs(a[i] - a[j]), ma);
  }
  cout << ma << endl;
  return 0;
}

Measured memory_bytes: 256
///Astalavista Code........~CodeSlayer007
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long
#define double long double
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define PT(x) cout << (#x) << " is " << (x) << endl;
#define SPD_emergency ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
const int M = 1e9 + 7;
int IM = 1e17;
void PV(vi v) { for (int i = 0 ; i < v.size() ; i++) cout << v[i] << " "; cout << endl;}
void PA(int v[], int n) {for (int i = 0 ; i < n ; i++)cout << v[i] << " " ; cout << endl;}
void IN(int a[], int n) {for (int i = 0; i < n; i++)cin >> a[i];}
inline void PTN(int n = 1, int a = 0, int b = 0, int c = 0) { if (n--)cout << a << " "; if (n--)cout << b << " "; if (n--)cout << c << " "; cout << endl; }
inline void open() {
#ifndef ONLINE_JUDGE
   freopen("input.txt", "r", stdin);
   freopen("output.txt", "w", stdout);
#endif
}
// <-------------------------------------------------------------------------------------------------------------------------------------------------------------------------> Ignore This-->  tuple first second push_back  continue make_pair break deque stack queue sort reverse accumulate  count lower_bound upper_bound next_permutation copy_n __builtin_popcount make_tuple
// <========================================================================================================================================================================

signed  main() {
   SPD_emergency

   //int t; cin >> t; int tt = 1; while (t--)
   {
      int k, a, b;
      cin >> k;
      cin >> a >> b;
      int n = b/k;
      n = n*k;     
      if( n>=a && n<=b)
         cout<<"OK";
      else
         cout<<"NG";
    
   }
   return 0;
}

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

def factorize(n):
  
  arr = []
  temp = n
  
  for i in range(2, int(n**(1/2))+1):
    if temp % i == 0:
      while temp % i == 0:
        temp //= i
        arr.append(i)

  if temp != 1:
    arr.append(temp)

  return arr

set_a = set(factorize(a))
set_b = set(factorize(b))

set_ab = set(set_a) & set(set_b)
ans = len(set_ab) + 1
print(ans)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long x;
  cin >> x;
  for(int i = 0; i < 150; i++){
    for(int j = -100; j < 200; j++){
      if(i*i*i*i*i-j*j*j*j*j==x){
        cout << i << " " << j;
        return 0;
      }
    }
  }
}

Measured memory_bytes: 3644
#include<iostream>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) loop(i,0,b)
using namespace std;
int main(){
  int in[10];
  int p;
  while(cin>>p){
    in[0]=p*100;
    int a,b;
    int suma=0,sumb;
    char d;
    cin>>d;
    int sum=in[0];
    loop(i,1,10){
      int tmp;
      cin>>tmp;
      in[i]=tmp*100;
      sum+=in[i];
      cin>>d;
    }
    cin>>a>>d>>b;
    sumb=sum;
    int i;
    //cout<<suma<<" "<<sumb<<endl;
    for(i=0;sumb>suma;i++){
      suma+=in[i];
      sumb-=(((double)in[i]/a)*b);
      //cout<<suma<<" "<<sumb<<endl;
    }
    cout<<i<<endl;
  }
}

Measured memory_bytes: 1160
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 100000000
#define INF 300000000000000000
#define MOD 1000000007
#define mod 1000000007
#define REP(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define REPE(i, a, n) for (ll i = a; i <= (ll)(n); i++)
#define rep(i,n)for (ll i = 0; i < (ll)(n); i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<int,int>Pin;
typedef pair<ll,ll>Pll;
template<class T> using V=vector<T>;
long long GCD(long long a, long long b) {return b?GCD(b,a%b):a;}
long long LCM(long long a, long long b) {return a/GCD(a,b)*b;}
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int ddx[8]={-1,0,1,0,1,1,-1,-1};
int ddy[8]={0,-1,0,1,1,-1,1,-1};
ll cmp1(pair<ll,ll>a,pair<ll,ll> b){
        if(a.se!=b.se)
        return a.se<b.se;
        else
        return a.fi<b.fi;
}
//----------------------------------------------------------------------
ll dp[2020][2020];
//----------------------------------------------------------------------
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------  
    //ll begin_time=clock();
    //-------------------------------
    ll n;cin>>n;
    V<ll>a(n);
    V<Pll>P(n);
    for(ll i=0;i<n;i++){
        cin>>a[i];
        P[i].fi=a[i];
        P[i].se=i;
    }

    sort(all(P));
    reverse(all(P));

    
    for(ll i=0;i<=n;i++){
        for(ll j=0;j<=n;j++){
            dp[i][j]=-INF;
        }
    }
    dp[0][0]=0;
    for(ll i=0;i<n;i++){
        ll v=P[i].fi;
        ll ipos=P[i].se;
        for(ll x=0;x<=i;x++){
            ll y=i-x;
            chmax(dp[x+1][y],dp[x][y]+abs(ipos-x)*v);
            chmax(dp[x][y+1],dp[x][y]+abs(ipos-(n-1-y))*v);
        }
    }
    ll ans=-INF;
    for(ll x=0;x<=n;x++){
        chmax(ans,dp[x][n-x]);
    }
    cout<<ans<<endl;
    //-------------------------------  
    //ll end_time=clock();cout<<"time="<<end_time-begin_time<<"ms"<<endl;
    //-------------------------------
    return 0;
}
//----------------------------------------------------------------------

















































Measured memory_bytes: 35288
#include<bits/stdc++.h>
using namespace std;
int main()
{
	char a[101];
	int ans=0;
	cin>>a;
	int l=strlen(a);
	for(int i=1;i<l-1;i++)
	ans++;
	cout<<a[0]<<ans<<a[l-1];
	return 0;
}

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

using namespace std;
using ll =long long;

#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cout << #x << " = " << (x) << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
bool coY() {cout <<"Yes"<<endl;}
bool coN(){cout <<"No"<<endl;}

const ll INF = 1LL << 60;

ll n,m;
string s;
//Write From this Line

const int mod = 1e9+7;
int main()
{
	cin >> n >> m ;
	priority_queue<pair<int,int>> q;
	rep(i,n){
		int a ;cin >> a;
		q.push(make_pair(a,1));
	}
	rep(i,m){
		int b , c ;
		cin >> b >> c;
		q.push(make_pair(c,b));
	}
	ll ans = 0 ;
	rep(i,n){
		auto p = q.top();
		q.pop();
		ans += p.first;
		p.second -- ;
		if(p.second > 0){
			q.push(p);
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 2420
#include<iostream>
#include<cmath>
using namespace std;
int main(){
	double a,b,c,d,x,y;
	cin>>a>>b>>c>>d;
	x=a-c;
	x*=x;
	y=b-d;
	y*=y;
	double z = sqrt(x+y);
	cout<<fixed<<z<<endl;
	return 0;
}

Measured memory_bytes: 1284
#include<iostream>
#include<numeric>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;

int main(){ 
	int x,a,b,A,B;
	cin>>x>>a>>b;
	A=abs(x-a);
	B=abs(x-b);
	if(A>B){
		cout<<'B'<<endl;
	}
	else{
		cout<<'A'<<endl;
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<functional>
#include <string>
#include<cstdio>
#include<math.h>
#include<stack>
#include<queue>
#include<cstring>
#include<vector>
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define EREP(i,n) for(int i=(n-1);i>=0;--i)
#define D(n,retu) REP(i,n){cin>>retu[i];}
#define mod 1000000007
#define MIN -931931114514181
#define INF 931931114518101
using namespace std;
typedef long long int ll;
template<typename T>
void fill_all(T& arr, const T& v) {
	arr = v;
}
template<typename T, typename ARR>
void fill_all(ARR& arr, const T& v) {
	for (auto& i : arr) { fill_all(i, v); }
}

//------------------変数-----------------------//
ll n, m;
typedef pair<ll, ll> P;

ll dp[20][100000] = {};//vコメの頂点のとき、どの頂点に行ったか
ll maxa = 0, moto = 0;
queue <ll>q;
ll bitmax = 0;
//-------------------関数----------------------//

struct G {
	ll from;
	ll to;
	ll cost;
};
G g[10001];
ll weight[10001];
int main() {
	fill_all(weight, (ll)MIN);
	weight[0] = 0;
	cin >> n >> m;
	REP(i, m) {
		ll a, b, c; cin >> a >> b >> c; a--; b--;
		g[i].from = a; g[i].to = b; g[i].cost = c;
	}
	ll j = 0;
	while (true) {
		j++;
		bool g_update = false;
		bool flag = true;
		REP(i, m) {
			G a = g[i];
			if (weight[a.from] != MIN&&weight[a.to]<weight[a.from] + a.cost) {
				flag = false;
				if (a.to == n - 1) { g_update = true; }
				weight[a.to] = weight[a.from] + a.cost;
			}
		}
		if (flag) { break; }
		if ((j > 30000) && (g_update)) { cout << "inf" << endl; return 0; }
		if ((j > 60000)) { break; }
	}
	cout << weight[n - 1] << endl;
	return 0;
}



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

typedef long long ll;
typedef pair<int,int> P;
typedef map<int,int> M;
typedef vector<int> V;
typedef queue<int> Q;
typedef pair<long,long> PLL;
typedef map<long,long> MLL;
typedef vector<long long> VLL;
typedef vector<pair<int,int>> VP;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define MOD (1e9+7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n-1);i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
/*--------------------------------------------*/
int main(){
    int n;cin>>n;
    V c(n),s(n),f(n);
    n--;
    rep(i,n){
        cin>>c[i]>>s[i]>>f[i];
    }
    rep(i,n){
        int ans=s[i];
        for(int j=i;j<n;j++){
            ans+=c[j]; 
            if(j!=n-1){
                if(ans<s[j+1])ans=s[j+1];
                while(ans%f[j+1]!=0){
                    ans++;
                }
            }
        }
        cout<<ans<<endl;
    }
    cout<<0<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
using namespace std;
typedef long long int ll;

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int q; cin >> q;
	for(int z=0;z<q;z++){
		int n; cin >> n;
		int ma=0,ma1=0;
		vector<int> a(n);
		for(int i=0;i<n;i++){
			cin >> a[i];
			if(i){
				ma=max(ma,a[i]-a[i-1]);
				ma1=max(ma1,a[i-1]-a[i]);
			}
		}
		cout << ma << " " << ma1 << endl;
	}
}


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

int main(){
    int N, K, d;
    scanf("%d %d", &N, &K);
    vector<vector<int> > A(K);
    vector<int> D(K);
    for (int i=0; i<K; i++){
        scanf("%d", &D[i]);
        for (int j=0; j<D[i]; j++){
            scanf("%d", &d);
            A[i].push_back(d);
        }
    }
    int res(0);
    for (int i=1; i<=N; i++){
        bool pair = false;
        for (int j=0; j<A.size(); j++){
            for (int k=0; k<A[j].size(); k++){
                if (A[j][k] == i) pair = true;
            }
        }
        if (!pair) res++;
    }
    printf("%d\n", res);
    return 0;
}


Measured memory_bytes: 3800
#include <bits/stdc++.h>
using namespace std;
 
#define froop1(a,n) for(int i = a;i < n;i++)
#define froop2(a,n) for(int i = a;i > n;i--)
int main(){
	long long N;
  long long sum = 0;
  cin >> N;
  sum += (N / 500)*1000;
  N -= 500*(N / 500);
  sum += (N / 5)*5;
  cout << sum << endl;
}

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

# define rep(i, n) for(int(i)=0;(i)<(n);(i)++)
# define reps(i, n) for(int(i)=1;(i)<=(n);(i)++)
# define rrep(i, n) for(int i=((int)(n)); i>0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>=0; --i)
# define ALL(v) v.begin(), v.end()
template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<typename T> void dump(T e){std::cout << e << std::endl;}
template<typename T> void dump(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void dump(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ dump(v); } }
template <typename T>
void dump_stack(std::stack<T>& stack) {
  std::stack<T> temp;
  while (!stack.empty()) {
    T top = stack.top(); stack.pop();
    std::cout << top << " ";
    temp.push(top);
  }
  std::cout << endl;
  while (!temp.empty()) {
    T top = temp.top(); temp.pop();
    stack.push(top);
  }
}
template <typename T>
void dump_queue(std::queue<T>& queue) {
  std::queue<T> temp;
  while (!queue.empty()) {
    T top = queue.front(); queue.pop();
    std::cout << top << " ";
    temp.push(top);
  }
  std::cout << endl;
  while (!temp.empty()) {
    T top = temp.front(); temp.pop();
    queue.push(top);
  }
}

typedef long long ll;




int main(){
  stack <int> sk;
  stack< pair<int , int> > sk2;
  //int imos1[200001],imos2[200001],ans,sum,SUM;
  //dump(imos1[1]);
  string s; cin >> s;
  int sum=0;
  rep(i,s.length()){
    if(s[i]=='\\')sk.push(i);
    if(s[i]=='/'){
      if(sk.empty())continue;
      int x=sk.top();sk.pop();// \の位置
      //dump(i);
      //dump(x);
      //exit(0);
      sum += i-x;
      int a = i-x; // 今入力された/から対応する\までの距離＝面積
      //dump(x);
      // 今新しくできた水たまりが過去の水たまりを包含している場合、以下のwhileループで再計算する
      while(sk2.size() > 0 && sk2.top().first > x) {
        a += sk2.top().second; 
        sk2.pop(); // 包含された水たまりの面積を今の水たまりに加え、スタックS2から削除
      }
      //dump(a);
      //dump("===");
      sk2.push(make_pair(x,a));
    }
  }
  vector<int> ans;
  while(sk2.size() > 0){
    ans.push_back(sk2.top().second);
    sk2.pop();
  }
  reverse(ans.begin(),ans.end());
  cout << sum << endl;
  cout << ans.size();
  rep(i,ans.size()) {
    cout << " " << ans[i];
  }
  cout << endl;
}



Measured memory_bytes: 3252
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

int f[50][50];
int main()
{
    int W,H,T,p;
    cin >>W >>H >>T >>p;

    vector<int> x(p),y(p),t(p);
    rep(i,p) cin >>x[i] >>y[i] >>t[i];

    rep(i,H)rep(j,W)
    {
        cin >>f[i][j];
        --f[i][j];
    }

    rep(i,p)if(f[y[i]][x[i]]!=-1) ++f[y[i]][x[i]];

    int ans = 0;
    rep(i,H)rep(j,W)if(f[i][j]!=-1) ans += f[i][j];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3104
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <math.h>
#include <sstream>
#include <numeric>
#include <string>
#include <cassert>
#include <bitset>

using namespace std;
typedef long long ll;

int main() {
  ll A, B, C, K;
  cin >> A >> B >> C >> K;
  if (K <= A) {
    cout << K << endl;
    return 0;
  } else if (K <= A + B) {
    cout << A << endl;
    return 0;
  } else {
    cout << A - (K - (A + B)) << endl;
    return 0;
  }
  return 0;
}


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

#define rp(i, k, n) for (int i = k; i < n; i++)
typedef long long ll;
typedef double ld;

template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF = 1ll << 60;
const ll MOD = 1e9 + 7ll;
const double PI=3.14159265358979323846;


int main() {
    int n, a;
    cin >> n >> a;
    vector<vector<vector<ll>>> dp(n+10, vector<vector<ll>>(n+10, vector<ll>(2700)));
    rp(i, 0, n+1) {
        dp[i][0][0] = 1ll;
    }
   
    rp(i, 0, n){
        int x; cin >> x;
        rp(j, 1, n+1){
            rp(k, 0, 2700) {
                dp[i+1][j][k] = dp[i][j][k];
                if(k-x >= 0) dp[i+1][j][k] += dp[i][j-1][k-x];
            }
        }
    }
    
    ll res = 0;
    rp(i, 1, n+1) {
        res += dp[n][i][a*i];
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 80592
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstring>
using namespace std;
class dice
{
public:
    dice()
    {

    }
    int n[6];
    void set(int n0,int n1,int n2,int n3,int n4,int n5)
    {
        n[0] = n0;
        n[1] = n1;
        n[2] = n2;
        n[3] = n3;
        n[4] = n4;
        n[5] = n5;
    }
    int get(int i)
    {
        return n[i];
    }
    int rot(char c)
    {
        int t[6];
        for(int i = 0;i < 6;i++)
        {
            t[i] = n[i];
        }
        switch(c)
        {
        case 'N':
            n[0] = t[1];
            n[1] = t[5];
            n[5] = t[4];
            n[4] = t[0];
            break;
        case 'S':
            n[0] = t[4];
            n[1] = t[0];
            n[5] = t[1];
            n[4] = t[5];
            break;
        case 'E':
            n[0] = t[3];
            n[3] = t[5];
            n[5] = t[2];
            n[2] = t[0];
            break;
        case 'W':
            n[0] = t[2];
            n[3] = t[0];
            n[5] = t[3];
            n[2] = t[5];
            break;
        default:
            break;
        }
    }
};

int main()
{
    int n[6];
    for(int i= 0;i < 6;i++)
    {
        cin >> n[i];
    }
    dice d;
    d.set(n[0],n[1],n[2],n[3],n[4],n[5]);
    string s;
    cin >> s;
    for(int i = 0;i < s.size();i++)
    {
        d.rot((char)s.at(i));
    }
    cout << d.get(0) << endl;
    return 0;
}

Measured memory_bytes: 1204
//
//
//  algoC.cpp - created by us162022
//
#include <iostream>
#include <queue>
using namespace std;
struct Node{
  int u,k,v[99];
  int distance;
};

int main(int argc, char *argv[])
{
  int n;
  Node node[100];
  queue<Node> que;

  cin >> n;

  for(int i=0; i<n; i++){
    cin >> node[i].u >> node[i].k;

    for(int j=0; j<node[i].k; j++)
      cin >> node[i].v[j];

    node[i].distance=-1;
  }

  node[0].distance = 0;
  que.push(node[0]);

  while(!que.empty()){
    Node fro = que.front();

    for(int i=0; i<fro.k; i++){
      int x = fro.v[i]-1;
  
      if(node[x].distance==-1){
	    node[x].distance = fro.distance+1;

        que.push(node[x]);
        }
    }

    que.pop();
  }

  for(int i=0; i<n; i++)
    cout << node[i].u << " " << node[i].distance << endl;

}

Measured memory_bytes: 3176
#include<bits/stdc++.h>
#define ll long long
const ll mod=1e9+7;
const int maxn=10000;
using namespace std;

int main()
//int found; found=chaine.find(cara); if (found!=std::string::npos) how to verify if a caracter exists in a chaine
// toupper(caractere) ==> return the majuscule of a caractere
//floor(x) Returns the largest integer smaller than x
//ceil(x) returns  Returns the smallest integer greater
/* #ifndef ONLINE_JUDGE
      freopen("input.txt","r",stdin);
    #endif */
{
     int n;
     cin>>n;
     string s;
     cin>>s;
     int red=0;
     int wh=0;
	 for(int i=0;i<n;i++)
     {
     	if(s[i]=='W')
     	{
     		wh++;
		 }
		 else
		 {
		 	red++;
		 }
	 }
	 int cnt=0;
	 for(int i=0;i<red;i++)
	 {
	 	if(s[i]=='W')
	 	{
	 		cnt++;
		 }
	 }
	 cout<<cnt<<endl;
}




Measured memory_bytes: 3716
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdio>
#include<math.h>
#include<map>
#include<set>
#include<queue>
#include<vector>

using namespace std;

map<int, int> mp;

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

	for (int i = 0; i < N; i++) {
		cin >> num;
		mp[num] += 1;
	}

	cin >> M;

	for (int i = 0; i < M; i++) {
		cin >> num;
		if (mp.find(num) == mp.end()) {
			cout << "NO" << endl;
			return 0;
		}
		else {
			mp[num] -= 1;
			if (mp[num] == 0) {
				mp.erase(num);
			}
		}
	}
	cout << "YES" << endl;
	return 0;
}

Measured memory_bytes: 9600
#include <stdio.h>
#include<math.h>
#include <string.h>
#include <ctype.h>

int main(){
int n,i,j,a,suu1,suu2,ba,t;
int tarou[100];
int hanako[100];
while(1){
scanf("%d",&n);
if(n==0)break;

for(i=0;i<n;i++)tarou[i]=0,hanako[i]=0;
for(i=0;i<n;i++)scanf("%d",&tarou[i]);
for(i=0;i<n;i++){
for(j=0;j<n-1;j++){
if(tarou[j]>tarou[j+1]){
a=tarou[j];
tarou[j]=tarou[j+1];
tarou[j+1]=a;
}
}
}
j=0;
a=0;
for(i=1;i<=n*2;i++){
if(tarou[j]!=i){
hanako[a]=i;
a++;
}
else if(tarou[j]==i)j++;
}
suu1=n;
suu2=n;
t=0;
ba=0;
while(suu2!=0&&suu1!=0){
if(t==0){
for(i=0;i<n;i++){
if(ba<tarou[i]&&tarou[i]!=0){
ba=tarou[i];
tarou[i]=0;
t=1;
suu2--;
break;
}
if(i==n-1){
t=1;
ba=0;
}
}
}
else if(t==1){
for(i=0;i<n;i++){
if(ba<hanako[i]&&hanako[i]!=0){
ba=hanako[i];
hanako[i]=0;
t=0;
suu1--;
break;
}
if(i==n-1){
t=0;
ba=0;
}
}
}
}
printf("%d\n%d\n",suu1,suu2);
}
return 0;
}

Measured memory_bytes: 1028
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#define INF (int)(1e9)
#define MAXN 1000001
using namespace std;

int sankaku[500];
int simen[500];
int simen2[500];
int maxi,maxj;
int dp[MAXN];
int dp2[MAXN];

void solve(){
  int i,j,t;
  int n=1111111;
  for(i=0;i<MAXN;i++){
    dp[i]=dp2[i]=INF;
  }
  dp[0]=dp2[0]=0;
  for(i=0;i<=maxj;i++){
    t=simen[i];
    for(j=t;j<MAXN;j++){
      dp[j]=min(dp[j],dp[j-t]+1);
    }
  }

  for(i=0;i<=maxi;i++){
    t=simen2[i];
    //if(t%2==0) continue;
    for(j=t;j<MAXN;j++){
      dp2[j]=min(dp2[j],dp2[j-t]+1);
    }
  }
}


int main(void){
  int n,i,j,t;
  t=i=j=1;
  sankaku[0]=1;
  simen[0]=1;
  simen2[0]=1;
  while(simen[j-1]<MAXN){
    sankaku[j]=sankaku[j-1]+j+1;
    simen[j]=simen[j-1]+sankaku[j];
    t=simen[j++];
    if(t%2==1) simen2[i++]=t;
  }
  maxi=i;
  maxj=j;
  
  solve();
  /*
  for(i=0;i<10;i++){
    printf("%d : %d   %d\n",i,simen[i],simen2[i]);
  }
  */
  while(scanf("%d",&n),n){
    cout<<dp[n]<<" "<<dp2[n]<<endl;
  }
  
  return 0;
}

Measured memory_bytes: 10932
#include<bits/stdc++.h>
using namespace std;
int main()
{
	//code
	int k,a,b;
	cin>>k;
	cin>>a>>b;
	
	for(int i=a;i<=b;i++)
	{
		if(i%k==0)
		{
			cout<<"OK";
			return 0;
		}
	}
	cout<<"NG";
 	return 0;
}



Measured memory_bytes: 3636
import java.util.*;

public class Main{
    void solve(){
        Scanner scan = new Scanner(System.in);
        int a = scan.nextInt();
        int b = scan.nextInt();
        int x = scan.nextInt();
        System.out.println(a <= x && x <= a + b ? "YES" : "NO");
    }
    
    public static void main(String[] args){
        new Main().solve();
    }
}

Measured memory_bytes: 35580
using System;
using System.Collections.Generic;
using System.Globalization;

namespace cswork
{
    class Program
    {
        public Program() { }

        Scanner cin;
        const int MAXIN = 1024;
        bool[] used = new bool[MAXIN];
        int[] perm = new int[MAXIN];

        List<int[]> permList = new List<int[]>();

        void Omame()
        {
            cin = new Scanner();
            string a = cin.next();
            string b = cin.next();
            string c = cin.next();
            string s = a + b + c;

            if (int.Parse(s) % 4 == 0)
            {
                Console.WriteLine("YES");
            }
            else
            {
                Console.WriteLine("NO");
            }
        }

        static void Main(string[] args)
        {
            new Program().Omame();
        }

        public void Permutation(int pos, int n, int length)
        {
            if (pos == n)
            {
                permList.Add((int[])perm.Clone());
            }

            for (int i = 0; i < n; i++)
            {
                if (!used[i])
                {
                    perm[pos] = i;
                    used[i] = true;
                    Permutation(pos + 1, n, length);
                    used[i] = false;
                }
            }
        }
    }

    class Scanner
    {
        string[] s;
        int i;

        char[] cs = new char[] { ' ' };

        public Scanner()
        {
            s = new string[0];
            i = 0;
        }

        public string next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();

            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next();
        }

        public int nextInt()
        {
            return int.Parse(next());
        }

        public long nextLong()
        {
            return long.Parse(next());
        }

        public double nextDouble()
        {
            return double.Parse(next());
        }
    }
}

Measured memory_bytes: 11092
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main() {
    int l;
    string s, t;
    cin >> l >> s >> t;
    int n = s.length(), m = t.length();
    string ans = string(l, '{');

    int p1 = -1, q1 = -1, p2, q2;
    REP(x,l/n+1){
        int y = (l - x*n) / m;
        if (x*n + y*m != l) continue;
        if (p1 == -1){
            p1 = x;
            q1 = y;
        }
        p2 = x;
        q2 = y;
    }

    string s1, s2, t1, t2;
    REP(i,p1) s1 += s;
    REP(i,p2) s2 += s;
    REP(i,q1) t1 += t;
    REP(i,q2) t2 += t;

    if (s1 + t1 < ans) ans = s1 + t1;
    if (t1 + s1 < ans) ans = t1 + s1;
    if (s2 + t2 < ans) ans = s2 + t2;
    if (t2 + s2 < ans) ans = t2 + s2;
    cout << ans << endl;

    return 0;
}




Measured memory_bytes: 1664
#include <iostream>
using namespace std;
int main(){
	int n,m;
	int vegetable[10001];
	while(cin>>n>>m){
		if(n+m==0)break;
		for(int i=0 ; i<n ; i++ )
			cin>>vegetable[i];
		//sort__
		for(int i=0 ; i<n ; i++ ){
			for(int j=i+1 ; j<n ; j++ ){
				if( vegetable[i] < vegetable[j] ){
					int tmp=vegetable[i];
					vegetable[i]=vegetable[j];
					vegetable[j]=tmp;
				}
			}
		}
		//_sort.
		int x=n/m;
		int y=n%m;
		int sum=0;
		int tmp;
		for(int i=n-y ; i<n ; i++ )
			sum+=vegetable[i];
		for(int i=0 ; i<n-y ; i++ ){
			if((i+1)%m){
				sum+=vegetable[i];
			}
		}
		cout<< sum << endl;
	}
}

Measured memory_bytes: 2988
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
int main()
{
  int h;
  cin >> h;
  int n;
  cin >> n;
  int sum = 0;
  rep(i,n){
    int a;
    cin >> a;
    sum += a;
  }
  if(sum>=h){
    cout << "Yes" << "\n";
  }
  else{
    cout << "No" << "\n";
  }
  
  return 0;
}


Measured memory_bytes: 256
import math

a, b, h, m = map(int,input().split())

htheta = h*30 + m*0.5 
mtheta = m*6

#xh = a * math.cos(math.radians(htheta))
#yh = a * math.sin(math.radians(htheta))

#xm = b * math.cos(math.radians(mtheta))
#ym = b * math.sin(math.radians(mtheta))

#print(((xh-xm)**2 + (yh-ym)**2)**(0.5))

l2 = a**2 + b**2 - 2*a*b*math.cos(math.radians(htheta-mtheta))
print(l2**0.5)


Measured memory_bytes: 9484
#include<iostream>
using namespace std;
int main(){
    int n,i,max,min;
    long long sum=0;
    int a[10001];
    cin>>n;
    for(i=1;i<=n;i++){
        cin>>a[i];
        sum=sum+a[i];
        if(i==1){
            max=a[i];
            min=a[i];
        }
        else{
            if(max<a[i]){
                max=a[i];
            }
            if(min>a[i]){
                min=a[i];
            }
        }
    }
    cout<<min<<" "<<max<<" "<<sum<<endl;
}


Measured memory_bytes: 3152
import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
from collections import deque, Counter
def getN():
    return int(input())
def getList():
    return list(map(int, input().split()))
import math
INF = 10**10
def bfs(graph, visited, position, root):
    visited[root] = 1
    position[root] = 0
    deq = deque([root])
    while(deq):
        cur = deq.pop()
        # print(cur)
        for nxt, dist in graph[cur]:
            if position[cur] + dist != position[nxt]:
                if position[nxt] != INF:
                    return False
                else:
                    position[nxt] = position[cur] + dist
            if not visited[nxt]:
                deq.append(nxt)
                visited[nxt] = 1

    return True

def main():
    n,x = getList()

    ans = n
    mx, mn = x, n - x
    if mx < mn:
        mx,mn = mn, mx

    # print(mx, mn)

    while(True):
        if mx % mn == 0:
            ans += 2 * mn * (mx // mn) - mn
            break
        else:
            ans += mn * 2 * (mx // mn)
            mx, mn = mn, mx % mn

    print(ans)


if __name__ == "__main__":

    main()

Measured memory_bytes: 38256
using System;
using System.Collections.Generic;
class _0005
{
    public static void Main()
    {
        char[] splitChar = { ' ' };
        List<long> GCD = new List<long>();
        List<long> LCM = new List<long>();
        long[] data = new long[2];
        string str;
        while ((str = Console.ReadLine()) != null)
        {
            string[] nums = str.Split(splitChar);
            int l = 0;
            foreach (string num in nums)
            {
                data[l] = long.Parse(num);
                l++;
            }
            long a, b, c;
            a = data[0];
            b = data[1];
            c = 1;
            while (c != 0)
            {
                c = a % b;
                a = b;
                b = c;
            }
            GCD.Add(a);
            LCM.Add(data[0] * data[1] / a);
        }
        for (int i = 0; i < GCD.Count; i++) Console.WriteLine(GCD[i] + " " + LCM[i]);
    }
}

Measured memory_bytes: 20000