akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
import java.util.*;

public class Main {

    private static final int PAYMENT = 1000;

    public static void main(String[] args) {
        try (CustomReader in = new CustomReader()) {
            new Main().execute(in);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public void execute(CustomReader in) throws IOException {
        while (true) {
            int price = Integer.parseInt(in.readLine());
            if (price == 0) {
                break;
            }
            int change = PAYMENT - price;
            System.out.println(countCoin(change));
        }
    }

    private int countCoin(int amount) {
        int coin = 0;
        while (amount > 0) {
            int n = amount % 10;
            coin += (n >= 5) ? n - 4 : n;
            amount /= 10;
        }
        return coin;
    }

    static class CustomReader extends BufferedReader {

        private static final int DEFAULT_BUF_SIZE = 2048;
        // private static final int DEFAULT_BUF_SIZE = 4096;
        // private static final int DEFAULT_BUF_SIZE = 8192;
        //private static final int DEFAULT_BUF_SIZE = 16384;
        // private static final int DEFAULT_BUF_SIZE = 1048576;

        public CustomReader() throws IOException {
            super(new InputStreamReader(System.in), DEFAULT_BUF_SIZE);
        }

        public int[] readLineAsIntArray() throws IOException {
            String[] strArray = this.readLine().split(" ");
            int[] intArray = new int[strArray.length];
            for (int i = 0, n = strArray.length; i < n; i++) {
                intArray[i] = Integer.parseInt(strArray[i]);
            }
            return intArray;
        }

        public int[][] readAsIntMatrix(int rows, int columns) throws IOException {
            int[][] matrix = new int[rows][columns];
            for (int i = 0; i < rows; i++) {
                String[] r = this.readLine().split(" ");
                for (int j = 0; j < columns; j++) {
                    matrix[i][j] = Integer.parseInt(r[j]);
                }
            }
            return matrix;
        }
    }
}


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


#define FOR(i, start, end) for(uint64_t i=start; i<end; i++)
#define REP(i, n) FOR(i, 0, n)

// 最大公約数gcd
// 最小公倍数lcm=m*n/gcd
uint64_t gcd(uint64_t m, uint64_t n) {
  uint64_t temp;
  while (m % n != 0){
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

uint64_t lcm(uint64_t m, uint64_t n) {
  return (m*n)/gcd(m,n);
}

// vector<vector<uint64_t> > v(n+1, vector<uint64_t>(n+1, 0))
// v[n][k]に組み合わせ数が入る。
void comb(vector<vector <uint64_t> > &v){
  for(uint64_t i = 0;i <v.size(); i++){
    v[i][0]=1;
    v[i][i]=1;
  }
  for(uint64_t k = 1;k <v.size();k++){
    for(uint64_t j = 1;j<k;j++){
      v[k][j]=(v[k-1][j-1]+v[k-1][j]);
    }
  }
}

// 掛け算オーバーフロー判定
bool is_product_overflow(uint64_t a, uint64_t b) {

	uint64_t prod = a * b;
	
	return (prod / b != a);
}

//素因数分解
void primeFactorization(uint64_t a, list<uint64_t> &factors){ //素因数分解を出力するプログラム
  long i,sq;
  if(a%2==0){ //偶数の場合
    factors.push_back(2);
    primeFactorization(a/2,factors); //2で割った値で再帰
    return;
  }
  sq = sqrt(a);
  for(i=3;i<=sq;i+=2){ //3以上√a以下の奇数の場合
	if(a%i==0){
	  factors.push_back(i);
      primeFactorization(a/i,factors); //割れた値で再帰
      return;
	}
  }
  //偶数でも3以上√a以下の奇数の場合でも割り切れない場合
  if(a!=1){ //aが1でないなら、a自身は素数
    factors.push_back(a);
  }
}

// フェルマーの小定理
// mod. m での a の逆元 a^{-1} を計算する
int64_t modinv(int64_t a, int64_t m) {
    int64_t b = m, u = 1, v = 0;
    while (b) {
        int64_t t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

// 円周率
// M_PI

// #include <iomanip> // setprecisionを使用するのに必要
// cout << std::fixed << std::setprecision(15) << y << endl;

// 昇順
// priority_queue<int, vector<int>, greater<int> > queue;

signed main() {
  string n;
  cin >> n;
  
  if(n.find("7")!=string::npos) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}



Measured memory_bytes: 3588
N, K = map(int, raw_input().split())
S = raw_input()

n = [0]
if S[0] == '0':
    n.append(0)

for i in xrange(1, N):
    if S[i - 1] != S[i]:
        n.append(i)

n.append(N)
if S[N - 1] == '0':
    n.append(N)

if len(n) <= K * 2 + 1:
    print N
else:
    m = 0
    for i in xrange(K * 2 + 1, len(n), 2):
        m = max(m, n[i] - n[i - K * 2 - 1])
    print m

Measured memory_bytes: 5892
#include <iostream>
#include <vector>
#include <algorithm>
 
using namespace std;
 
int ans = 0;
const int X = 2000;
vector <int> a;
vector <int> cnt;
 
void add (int i) {
  ans += (cnt[a[i]] == 0);
  cnt[a[i]]++;
}
 
void del (int i) {
  cnt[a[i]]--;
  ans -= (cnt[a[i]] == 0);
}
 
int que(int oldL, int oldR, int L, int R) {
  for (int i = oldL; i < L; i++)
    del(i);
  for (int i = L; i < oldL; i++)
    add(i);
  for (int i = oldR; i > R; i--)
    del(i);
  for (int i = R; i > oldR; i--)
    add(i);
  return ans;
}
 
bool cmp(pair <pair <int, int>, int> a, pair <pair <int, int>, int> b) {
  if (a.first.first / X != b.first.first / X) return a.first.first / X < b.first.first / X;
  return a.first.second < b.first.second;
}
 
int main () {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, q;
  cin >> n >> q;
  a.resize(n), cnt.resize(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    a[i]--;
  }
  vector <pair <pair <int, int>, int>> b(q);
  for (int i = 0; i < q; i++) {
    cin >> b[i].first.first >> b[i].first.second;
    b[i].first.first--, b[i].first.second--;
    b[i].second = i;
  }
  sort(b.begin(), b.end(), cmp);
  vector <int> answer(q);
  int oldL = 1, oldR = 0;
  for (int i = 0; i < q; i++) {
  	int id = b[i].second;
  	int L = b[i].first.first;
  	int R = b[i].first.second;
  	answer[id] = que(oldL, oldR, L, R);
  	oldL = L, oldR = R;
  }
  for (auto &now : answer)
    cout << now << '\n';
  return 0;
}

Measured memory_bytes: 15524
a,v = map(int,input().split())
b,w = map(int,input().split())
t = int(input())

if a < b:
    if a+v*t >= b + w*t:
        print('YES')
    else:
        print('NO')
else:
    if a-v*t <= b-w*t:
        print('YES')
    else:
        print('NO')

Measured memory_bytes: 9124
while 1:
    n, x = map(int,raw_input().split())
    if n == x == 0:
        break
    sum = 0
    for i in range(1,n+1):
        for j in range(i+1,n+1):
            k = x - i - j
            if k > j and k <= n:
                sum += 1
    print sum

Measured memory_bytes: 6392
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a[3],k;
	cin>>a[1]>>a[2]>>a[3];
	int minn=99999999;
	sort(a+1,a+3+1);
	int s=0;
	for(int i=2;i<=3;i++){
		s+=a[i]-a[i-1];
	}
	cout<<s<<endl;
	return 0;
}


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

int main()
{
    string s;
    int k,i,j;
    cin >> s >> k;
    set<string> se;
    for(i = 0;i < s.size();++i){
        for(j = 1;j <= k;++j){
            se.insert(s.substr(i,j));
        }
    }
    vector<string> array;
    for(string x: se){
        array.push_back(x);
    }
    sort(array.begin(),array.end());
    cout << array.at(k-1) << endl;
    return 0;
}

Measured memory_bytes: 1920
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <algorithm>
#include <functional>

#include <vector>

using namespace std;

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

	long long N, K;
	cin >> N >> K;

	vector<long long> pos(K, 0);

	for (int i = 0; i < K; i++)
	{
		cin >> pos[i];
	}

	vector<long long> dist;

	for (int i = 0; i < K; i++)
	{
		if (i == K - 1)
		{
			dist.push_back(N - pos[i] + pos[0]);
		}
		else
		{
			dist.push_back(pos[i + 1] - pos[i]);
		}
	}

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

	long long result = 0;
	for (int i = 0; i < K - 1; i++)
	{
		result += dist[i];
	}

	cout << result;

	return 0;
}


Measured memory_bytes: 3956
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <climits>
#include <cstring>
#include <string>
#include <map>
#include <set>
#include <vector>
#include <queue>


using namespace std;
#define INF 0x3f3f3f3f3f
#define ll long long
#define pr(x) (cerr << #x << ' ' << x << ' ')
#define prln(x) (cerr << #x << ' ' << x << endl)


int main()
{
	#ifdef LOCAL
		freopen("in.txt", "r", stdin);
	#endif // LOCAL
	int n;
	scanf("%d", &n);
	auto val = __gcd(2, n);
	cout << n * 2 / val << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int n,ice;
	int cnt[10001];
	int i,j;
	
	scanf("%d",&n);
	while(n!=0){
		for(i=0;i<10;i++){
			cnt[i]=0;
		}
		for(i=0;i<n;i++){
			scanf("%d",&ice);
			cnt[ice]++;
		}
		for(i=0;i<10;i++){
			for(j=0;j<cnt[i];j++){
				if (cnt[i]>0){
					printf("*");
				}
				else if(cnt[i]==0){
					printf("-");
				}
			}
			printf("\n");
		}
		scanf("%d",&n);
	}
	return 0;
}

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

int n,m;
vector<int> adj[100005];
int ind[100005];
int ans[100005];

int main(){
	
	cin>>n>>m;
	for(int i=0;i<m;i++){
		int x,y;
		cin>>x>>y;
		adj[x].push_back(y);
		ind[y]++;
	}
	
	queue<int> q;
	for(int i=1;i<=n;i++){
		if(ind[i] == 0) q.push(i);
	}
	
	int sol = 0;
	while(!q.empty()){
		int x = q.front();
		q.pop();
		for(int y:adj[x]){
			ind[y]--;
			ans[y] = max(ans[y],ans[x]+1);
			if(ind[y] == 0){
				q.push(y);
				sol = max(sol,ans[y]);
			}
		}
	}
	
	cout<<sol;
	
	return 0;
}


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

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
ld EPS = 1e-12;
int INF = numeric_limits<int>::max() / 2;
int MOD = 1e9 + 7;

template<typename T>
T gcd(T a, T b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

int vecgcd(vi a){
  int ans = a[0];
  for(int i = 0; i < a.size()-1; i++){
    ans = gcd(ans, a[i+1]);
  }
  return ans;
}

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

    int n;
    cin >> n;
    vi towns(n+1);
    for(int i = 0; i < n+1; i++)cin >> towns[i];
    sort(towns.begin(), towns.end());

    vi distance(n);
    for(int i = 0; i < n; i++){
      distance[i] = towns[i+1] - towns[i];
    }

    cout << vecgcd(distance) << '\n';
    return 0;
}


Measured memory_bytes: 1408
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	static final int MAX = 1000000;
	public static void main(String[] args) {
		doIt();
	}
	
	static void doIt(){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] ary = new int[200];
		int[] ary2 = new int[200];
		int[] dp = new int[MAX + 1];
		int[] dp2 = new int[MAX + 1];
		int p = 1;
		for(int i = 1; i < 200; i++){
			ary[i] = i * (i + 1) * (i + 2) / 6;
			if(ary[i] % 2 == 1){
				ary2[p] = ary[i];
				p++;
			}
		}
		solve(MAX, ary, dp);
		solve(MAX, ary2, dp2);
		while(0 < n){
			System.out.println(dp[n] + " " + dp2[n]);
			n = sc.nextInt();
		}
	}
	static int solve(int n, int[] ary, int[] dp){
		//int[] dp = new int[n + 1];
		Arrays.fill(dp, 1000000);
		dp[0] = 0;
		for(int i = 1; i <= n; i++){
			for(int j = 1; j < ary.length; j++)
				if(i < ary[j]) break;
				else if(dp[i - ary[j]] + 1 < dp[i]) dp[i] = dp[i - ary[j]] + 1;
		}
		return dp[n];
	}

}

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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);

	int n; cin >> n;
	multiset<int> d;
	rep(i, 0, n) {
		int t; cin >> t;
		d.insert(t);
	}

	int m; cin >> m;
	rep(i, 0, m) {
		int t; cin >> t;
		auto it = d.find(t);
		if (it == d.end()) {
			cout << "NO" << endl;
			return 0;
		}
		d.erase(it);
	}

	cout << "YES" << endl;
}


Measured memory_bytes: 9600
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		String S = sc.next();
		String T = sc.next();
		int maxMatch = 0;
		for (int i = 0; i < S.length() - T.length() + 1; i++) {
			int tmp = 0;
			for (int j = 0; j < T.length(); j++) {
				if (S.charAt(i + j) == T.charAt(j)) {
					tmp++;
				}
			}
			if (tmp > maxMatch) {
				maxMatch = tmp;
			}
		}
		System.out.println(T.length() - maxMatch);
	}

}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}

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

Measured memory_bytes: 32596
//{{{ #include <bits/stdc++.h>
#ifndef __clang__
#include <bits/stdc++.h>
#endif
using namespace std; //}}}
const long long MOD = static_cast<int>(1e9) + 7;
//{{{TEMPLATE_BEGIN
#include <unistd.h>
using namespace std::rel_ops;
typedef long long lint;
typedef unsigned long long ulint;
typedef long double ldouble;
typedef vector<int> vint;
#define rep(i, n)                                                              \
    for (int i = 0, i##_len = static_cast<int>(n); i < i##_len; i++)
#define all(c) begin(c), end(c)
#define perm(c)                                                                \
    sort(all(c));                                                              \
for (bool c##p = 1; c##p; c##p = next_permutation(all(c)))
#define uniquenize(v) (v).erase(unique(all(v)), end(v))
#define cauto const auto &
#define memset(x, y) memset(x, y, sizeof(x))
#define popcount __builtin_popcount
#define gcd __gcd
inline lint bit(int x) {
    return 1LL << x;
}
template <class T>
inline int size(const T &a) {
    return (int)a.size();
}
template <class T>
inline bool chmin(T &a, const T &b) {
    return a > b ? a = b, 1 : 0;
}
template <class T>
inline int clamp(T v, T lo, T hi) {
    return (v > hi) - (v < lo);
}
template <class T>
inline bool chmax(T &a, const T &b) {
    return a < b ? a = b, 1 : 0;
}
template <class T>
inline pair<vector<T>, char> operator*(const vector<T> &v, const char &c) {
    return make_pair(v, c);
}
template <class T>
inline istream &operator>>(istream &is, vector<T> &v) {
#ifdef ZEROKUGI
    if (v.empty()) {
        cerr << "Error L" << __LINE__ << ": vector size is zero." << endl;
        exit(EXIT_FAILURE);
    }
#endif
    for (auto &x : v)
        is >> x;
    return is;
}
template <class T>
inline ostream &operator<<(ostream &os, const pair<vector<T>, char> &v) {
    bool t = 0;
    for (const T &x : v.first) {
        if (t)
            os << v.second;
        os << x;
        t = 1;
    }
    return os;
}
template <class T>
inline ostream &operator<<(ostream &os, vector<T> &v) {
    return os << v * ' ';
}
struct before_main {
    before_main() {
        cin.tie(0);
        ios::sync_with_stdio(0);
        cout << fixed << setprecision(20);
    };
} __before_main;
//}}}TEMPLATE_END

int main() {
    int n, a, b;
    cin >> n >> a >> b;

    int x = min(a, b);
    int y = a + b - n;
    if(y < 0) y = 0;
    cout << x << " " << y << endl;
}



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

int main(){
  int N ; 
  cin >> N ; 
  vector<int> A(N) ; 
  for(int i = 0 ; i < N ; i++) cin >> A.at(i) ; 
  
  sort(A.begin() , A.end()) ; 
  
  cout << abs(A.at(0) - A.at(N-1)) <<endl ; 
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define LL long long
#define REP(i,n) for(int i=0;i<(n);++i)
#define lp(i,n) for(int i=0;i<(n);++i)
#define REPA(i,n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define PII pair<int,int>
#define PLI pair<long long, int>
#define PLL pair<long long, long long>
#define MOD ((int)1e9 + 7)
#define INF ((int)1e9)
#define INFLL ((LL)1e18)
#define ALL(x) (x).begin(),(x).end()
#define BIT(x) (1 << (x))
using namespace std;

int main(){
	int n;
	int m;
	string str;
	cin >> n >> str;
	n=0;
	m=0;
	foreach(i, str){
		if(i=='(')++m;
		else{
			if(m==0)++n;
			else --m;
		}
	}
	REP(i, n)cout << '(';
	foreach(i, str)cout << i;
	REP(i, m)cout << ')';
	cout << endl;
}


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

using namespace std;

int main()
{
  #define int long long int
    int n,flag=1;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    sort(a,a+n);
    for(int i=0;i<n;i++)
    {
        if(a[i]==a[i+1]){flag=0;break;}
    }
    if(flag==0)cout<<"NO"<<endl;
    else if(flag==1)cout<<"YES"<<endl;

    return 0;
}


Measured memory_bytes: 1792
n = gets.to_i
A = gets.chomp.split(' ').map(&:to_i).sort.reverse
i = 1
alice = 0
bob = 0

A.each do |a|
  if i % 2 == 1
    alice += a
  else
    bob += a
  end
  i += 1
end
puts alice-bob

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

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

    ll a, b;
    cin >> a >> b;

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

    ll ans = 0;
    for(int i = 1; i < n; i++){
        if((x[i] - x[i - 1]) * a < b){
            ans += (x[i] - x[i - 1]) * a;
        }else{
            ans += b;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 4320
import java.util.Scanner;

public class Main {

    public static int max_a (int[] array) {
        int val = array[0];
        for (int i = 1; i < array.length; i++) {
            val = Math.max(val, array[i]);
        }

        return val;
    }

    public static int min_a (int[] array) {
        int val = array[0];
        for (int i = 1; i < array.length; i++) {
            val = Math.min(val, array[i]);
        }

        return val;
    }

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

        int n = sc.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < a.length; i++) {
            a[i] = sc.nextInt();
        }

        int maxa = max_a(a);
        int mina = min_a(a);

        int min_cost = Integer.MAX_VALUE;
        for (int i = mina; i <= maxa; i++) {
            int cost = 0;
            for (int j = 0; j < n; j++) {
                 cost += (i - a[j]) * (i - a[j]);
            }
            min_cost = Math.min(min_cost, cost);
        }

        System.out.println(min_cost);
    }
}

Measured memory_bytes: 21844
#include <cstdio>
#include <cstdint>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <string>
#include <deque>

intmax_t f(std::deque<intmax_t> const& a) {
  size_t n = a.size();
  intmax_t res = 0;
  for (size_t i = 1; i < n; ++i)
    res += std::abs(a[i]-a[i-1]);

  // for (size_t i = 0; i < n; ++i)
  //   fprintf(stderr, "%jd%c", a[i], i+1<n? ' ': '\n');

  return res;
}

intmax_t g(std::deque<intmax_t> a) {
  size_t n = a.size();
  std::deque<intmax_t> res;
  for (size_t i = 0; i < n; ++i) {
    if (i % 2 == 0) {
      res.push_back(a.front());
      a.pop_front();
    } else {
      res.push_back(a.back());
      a.pop_back();
    }
  }

  intmax_t score = f(res);
  {
    intmax_t x = res.back();
    res.pop_back();
    res.push_front(x);
  }
  score = std::max(score, f(res));
  return score;
}

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

  std::deque<intmax_t> a(n);
  for (auto& ai: a) scanf("%jd", &ai);
  std::sort(a.begin(), a.end());

  intmax_t score = g(a);
  std::reverse(a.begin(), a.end());
  score = std::max(score, g(a));

  printf("%jd\n", score);
}


Measured memory_bytes: 1964
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#define dlog(str) cout << "====" << str << endl;
#else
#define dlog(str)
#endif
#define INF 999999999
#define MOD 1000000007
#define REP(i, n) for(int i = 0, i##_l = (n); i < i##_l; i++)
#define FOR(i, s, e) for(int i = s, i##_l = (e); i < i##_l; i++)
#define LLI long long int
#define _min(a,b) ((a<b)?a:b)
#define _max(a,b) ((a<b)?b:a)
#define chmax(a, b) a = _max(a, b)
#define chmin(a, b) a = _min(a, b)
#define bit(a, shift) ((a>>shift)&1))
#define pm(a) ((a)?1:-1)
#define SORT(v) sort(v.begin(),v.end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
// int 2.14E±9    lli 9.2E±18    double 1.7E±380


int main()
{
	cout << fixed << setprecision(10);

	int n;
	cin >> n;

	vector<LLI> a(n);
	REP(i, n)
	{
		cin >> a[i];
	}

	RSORT(a);


	LLI ans = a[0];
	int j = 1;
	REP(i, n - 2)
	{
		ans += a[j];
		if (i % 2 == 1)j++;
	}

	cout << ans;
	return 0;
}

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

int main() {
  int N,Q;
  cin >> N;
  vector<int> s(N);
  for(int i=0;i<N;i++) cin>>s[i];
  cin >> Q;
  vector<int> t(Q);
  for(int i=0;i<Q;i++) cin>>t[i];

  int count=0;
  for(int i=0;i<Q;i++){
    int start=0;
    int end=N;
    int idx = 0;
    while(end-start>0){
      if(idx == (start+end)/2) break;
      else{
      idx = (start+end)/2;
      if(t[i]==s[idx]){
        count++;
        break;
      }
      else if(t[i]<s[idx]){
        start = start;
        end= idx;
      }
      else if(t[i]>s[idx]){
        start= idx;
        end = end;
      }
    }
    }
  }


cout<<count<<endl;
  }



Measured memory_bytes: 3312
n,m=map(int, input().split())
c = 1 / (4*m)
ans = 0
l = [int(x) for x in input().split()]
l.sort(reverse=True)

for i in range(m):
    if l[i] < sum(l)*c:
        print("No")
        ans += 1
        break

if ans == 0:
    print("Yes")

Measured memory_bytes: 9020
from collections import Counter as c
from scipy.misc import comb
from functools import reduce

def f(n):
  d,i=c(),2
  while i*i<=n:
    while n%i==0:
      n//=i
      d[i]+=1
    i+=1
  if n>1:d[n]+=1
  return d.values()

n,m=map(int,input().split())
mod,v=10**9+7,1
for x in f(m):
  v*=comb(x+n-1,x,exact=True)%mod
print(v%mod)

Measured memory_bytes: 13176
#include <algorithm>
#include <iostream>
#include <queue>
#include <string>
#include <utility>
#include <vector>
using namespace std;

int main() {
	int H, W, a = 0;
	cin >> H >> W;
	vector<string> s(H);
	for (string& i : s) {
		cin >> i;
		a += count(i.begin(), i.end(), '#');
	}
	queue<pair<int, int>> b;
	b.emplace(0, 0);
	vector<vector<int>> c(H, vector<int>(W));
	c[0][0] = 1;
	while (!b.empty()) {
		if (H - 1 != b.front().first) {
			if (!c[1 + b.front().first][b.front().second] && '.' == s[1 + b.front().first][b.front().second]) {
				b.emplace(1 + b.front().first, b.front().second);
				c[1 + b.front().first][b.front().second] = 1 + c[b.front().first][b.front().second];
			}
		}
		if (W - 1 != b.front().second) {
			if (!c[b.front().first][1 + b.front().second] && '.' == s[b.front().first][1 + b.front().second]) {
				b.emplace(b.front().first, 1 + b.front().second);
				c[b.front().first][1 + b.front().second] = 1 + c[b.front().first][b.front().second];
			}
		}
		if (b.front().first) {
			if (!c[b.front().first - 1][b.front().second] && '.' == s[b.front().first - 1][b.front().second]) {
				b.emplace(b.front().first - 1, b.front().second);
				c[b.front().first - 1][b.front().second] = 1 + c[b.front().first][b.front().second];
			}
		}
		if (b.front().second) {
			if (!c[b.front().first][b.front().second - 1] && '.' == s[b.front().first][b.front().second - 1]) {
				b.emplace(b.front().first, b.front().second - 1);
				c[b.front().first][b.front().second - 1] = 1 + c[b.front().first][b.front().second];
			}
		}
		b.pop();
	}
	if (c.back().back()) cout << H * W - a - c.back().back();
	else cout << -1;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**7)

class UnionFind:
    def __init__(self,N):
        self.Parent = list(range(N))
    def get_Parent(self,n):
        if self.Parent[n] == n:return n
        p = self.get_Parent(self.Parent[n])
        self.Parent[n] = p
        return p
    def merge(self,x,y):
        x = self.get_Parent(x)
        y = self.get_Parent(y)
        if x!=y: self.Parent[y] = x
        return
    def is_united(self,x,y):
        return self.get_Parent(x)==self.get_Parent(y)

N,K,L = map(int,input().split())
PQ = [list(map(int,input().split())) for _ in [0]*K]
RS = [list(map(int,input().split())) for _ in [0]*L]

T1 = UnionFind(N)
T2 = UnionFind(N)
for p,q in PQ:
    p-=1;q-=1
    T1.merge(p,q)
for r,s in RS:
    r-=1;s-=1
    T2.merge(r,s)
P = {}
for i in range(N):
    p = (T1.get_Parent(i),T2.get_Parent(i))
    if not p in P:P[p] = []
    P[p].append(i)

ans = [0]*N
for v in P.values():
    s = len(v)
    for i in v:
        ans[i] = s
print(*ans)

Measured memory_bytes: 109788
# coding: utf-8
# Your code here!
s=input()

if s=="MON":
    print(6)
elif s=="TUE":
    print(5)
elif s=="WED":
    print(4)
elif s=="THU":
    print(3)
elif s=="FRI":
    print(2)
elif s=="SAT":
    print(1)
else:
    print(7)


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

using namespace std;
using ll = long long;
using ull = unsigned long long;

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

    ll sum = 0;
    for (ll i = 0; i < m; ++i) {
        ll x;
        cin >> x;
        sum += x;
    }

    ll ans = n - sum;
    if (ans < 0)
        cout << -1 << "\n";
    else
        cout << ans << "\n";
}

int main() {
    solve();

    return 0;
}

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

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

  vector<ll> A(10, 0);
  for (int i = 0; i < 10; i++) {
    cin >> A[i];
  }
  sort(A.begin(), A.end());
  reverse(A.begin(), A.end());

  for (int i = 0; i < 3; i++) {
    cout << A[i] << '\n';
  }
  return 0;
}


Measured memory_bytes: 3116
import math

x=0
y=0
deg=0
while(1):
    [a,b]=map(int,raw_input().split(','))
    if a==0 and b==0:
        print int(x)
        print int(y)
        break
    else:
        x+=a*math.sin(deg*math.pi/180)
        y+=a*math.cos(deg*math.pi/180)
        deg+=b

Measured memory_bytes: 6716
#include"bits/stdc++.h"
//#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define print(x) cout<<x<<endl;
typedef long long ll;

int n;
string s;
int int_s;
int ans[100005];
string ans_s[100005];
int flag = 0;

bool is(int s1, int s2) {
	ans[0] = s1;	//ans[i]=-1のとき羊、1の時狼
	ans[1] = s2;
	rep(i, 1, n) {
		if (ans[i] == -1 && s[i] == 'o') { ans[i + 1] = ans[i - 1]; }
		else if (ans[i] == -1 && s[i] == 'x') { ans[i + 1] = -ans[i-1]; }
		else if (ans[i] == 1 && s[i] == 'o') { ans[i + 1] = -ans[i - 1]; }
		else if (ans[i] == 1 && s[i] == 'x') { ans[i + 1] = ans[i - 1]; }
	}
	//rep(i, 0, n )cout << ans[i];
	//cout << endl;
	int flag = 0;
	if (ans[n - 1] == -1 && s[n - 1] == 'o'&&ans[n - 2] == ans[0] \
		|| ans[n - 1] == -1 && s[n - 1] == 'x'&&ans[n - 2] != ans[0] \
		|| ans[n - 1] == 1 && s[n - 1] == 'o'&&ans[n - 2] != ans[0]\
		|| ans[n - 1] == 1 && s[n - 1] == 'x'&&ans[n - 2] == ans[0]) flag += 1;
	if (ans[0] == -1 && s[0] == 'o'&&ans[n - 1] == ans[1] \
		|| ans[0] == -1 && s[0] == 'x'&&ans[n - 1] != ans[1] \
		|| ans[0] == 1 && s[0] == 'o'&&ans[n - 1] != ans[1] \
		|| ans[0] == 1 && s[0] == 'x'&&ans[n - 1] == ans[1]) flag += 1;
	if (flag == 2)return 1;
	return 0;
}

int main() {

	cin >> n;
	cin >> s;
	int sw[8] = { -1,-1,-1,1,1,-1,1,1};
	for(int i=0;i<8;i+=2) {
		//print(j);
		if (is(sw[i], sw[i+1])) {
			rep(j, 0, n) {
				if (ans[j] == -1) { ans_s[j] = 'S'; }
				else if (ans[j] == 1) { ans_s[j] = 'W'; }
			}
			rep(j, 0, n) { cout<<ans_s[j];}
			cout << endl;
			return 0;
		}
	}
	
	print(-1); return 0;
}

Measured memory_bytes: 6272
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <sstream>
#include <fstream>
#include <cmath>
#include <stack>
#include <queue>
#include <list>
#include <map>

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;

#define MAX(x,y) ( (x) > (y) ? (x) : (y) )
#define MIN(x, y) ( (x) < (y) ? (x) : (y) )
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)
#define IVFOR(p,a) for(vector<int>::iterator p = (a).begin(); p!=(a).end(); p++)
#define ILFOR(p,a) for(list<int>::iterator p = (a).begin(); p!=(a).end(); p++)
#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define CHECK(x)  cout << #x << " = " << (x) << endl
#define FINA(y) cout << (y) << endl

int main(){

  char c;
  cin >> c;
  
  if(c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o')
    FINA("vowel");
  else
    FINA("consonant");

 return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define nmax 101
#define WHITE 0
#define GRAY 1
#define BLACK 2

void dfs();
void dfvi(int);
 


int n,M[nmax][nmax];
int color[nmax],d[nmax],f[nmax];
int time;

void dfvi(int u){
  int v;
  color[u] = GRAY;
  d[u] = ++time;
  for(v = 0 ; v < n ; v++){
    if(M[u][v] == 0){
      continue;
    }
    if(color[v] == WHITE){
      dfvi(v);
    }
  }
  color[u] = BLACK;
  f[u] = ++time;
}

void dfs(){
  int u;
  for(u = 0 ; u < n ; u++){
    color[u] = WHITE;
  }
  
  time = 0;
  
  for(u = 0 ; u < n ; u++){
    if(color[u] == WHITE){
      dfvi(u);
    }
  }
  for(u = 0 ; u < n ; u++){
    printf("%d %d %d\n",u + 1,d[u],f[u]);
  }
}

int main(){
  int u,v,k;
  int i,j;

  scanf("%d",&n);
  for(i = 0 ; i < n ; i++){
    for(j = 0 ; j < n ; j++){
      M[i][j] = 0;
    }
  }

  for(i = 0 ; i < n ; i++){
    scanf("%d %d",&u,&k);
    u=u-1;
    for(j = 0 ; j < k ; j++){
      scanf("%d",&v);
      v=v-1;
      M[u][v] = 1;
    }
  }
  dfs();

  return 0;
}





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

public class Team
{
    public int sec { get; set; }
    public int tid { get; set; }
}

public class hello
{
    public static void Main()
    {
        while (true)
        {
            var n = int.Parse(Console.ReadLine().Trim());
            if (n == 0) break;
            var teams = new List<Team>();
            for (int i = 0; i < n; i++)
            {
                string[] line = Console.ReadLine().Trim().Split(' ');
                var a = Array.ConvertAll(line, int.Parse);
                var sec = 0;
                for (int j = 1; j < 9; j += 2)
                    sec += a[j] * 60 + a[j + 1];
                teams.Add(new Team { tid = a[0], sec = sec });
            }
            var teams2 = teams.OrderBy(x => x.sec).ToList();
            Console.WriteLine(teams2[0].tid);
            Console.WriteLine(teams2[1].tid);
            Console.WriteLine(teams2[n-2].tid);
        }
    }
}

Measured memory_bytes: 10740
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        double[] v = new double[n];
        for (int i = 0 ; i < n ; i++) {
            v[i] = sc.nextDouble();
        }

        Arrays.sort(v);
        double ans = (v[0] + v[1]) / 2;
        for (int i = 2 ; i < n ; i++) {
            ans = (ans + v[i]) / 2;
        }

        System.out.println(ans);
    }

}


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

public class Main {
    public static void main(String args[]) throws IOException {

	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	String[] array = br.readLine().split(" ");

	int X = Integer.parseInt(array[0]), A = Integer.parseInt(array[1]);

	System.out.println(A > X ? 0 : 10);
    }
}

Measured memory_bytes: 22356
#include<vector>
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<map>
#include<functional>
#include<queue>
#include<stack>
#include<string.h>
#include<list>
#include<limits>
#include<bitset>
#include<ctype.h>
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
const ll MOD=1000000007;
const ll INF=1000000000;
ll mod_pow(ll x,ll n,ll mod){
    ll ret=1;
    while(n>0){
        if(n&1){
            ret=ret*x%mod;
        }
        x=x*x%mod;
        n>>=1;
    }
    return ret;
}
ll f[100010],fr[100010];
ll ncr(ll n,ll r){
    if(n<r){
        return 0;
    }
    return f[n]*fr[r]%MOD*fr[n-r]%MOD;
}
int main() {   
    ll n;
    cin>>n;
    ll a[100001],b[100001];
    for(int i=1;i<=n+1;i++){
        cin>>a[i];
        b[i-1]=a[i];
    }
    sort(b,b+n+1);
    ll s;
    for(int i=0;i<n;i++){
        if(b[i]==b[i+1]){
            s=b[i+1];
            break;
        }
    }
    ll l=-1;
    ll r=0;
    for(int i=1;i<=n+1;i++){
        if(a[i]==s){
            if(l==-1){
                l=i;
            }else{
                r=i;
                break;
            }
        }
    }
    f[0]=1;
    for(ll i=1;i<=n+2;i++){
        f[i]=f[i-1]*i%MOD;
    }
    fr[n+2]=mod_pow(f[n+2],MOD-2,MOD);
    for(ll i=n+1;i>=0;i--){
        fr[i]=fr[i+1]*(i+1)%MOD;
    }
    for(ll k=1;k<=n+1;k++){
        ll ans=(ncr(n+1,k)-ncr(l+n-r,k-1)+MOD)%MOD;
        cout<<ans<<endl;
    }
    getchar();
    getchar();
}

                           


Measured memory_bytes: 4352
#include<stdio.h>
int main(void){
	int time,hour,minute,second;
	scanf("%d",&time);
	hour = (int)(time/3600);
	minute = (int)((time-hour*3600)/60);
	second = time-hour*3600-minute*60;
	printf("%d:%d:%d\n",hour,minute,second);
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
typedef long long ll;
ll d[4][4];
ll inf=1e18;
ll a[4];
int main(){
	ll x,y;
	cin>>x>>y;
	a[0]=x,a[1]=-x,a[2]=y,a[3]=-y;
	rep(i,4) rep(j,4) d[i][j]=inf;
	rep(i,4) d[i][i]=0;
	rep(i,4) rep(j,4) if(i!=j){
		if((i^1)==j) chmin(d[i][j],1LL);
		if(a[i]<=a[j]) chmin(d[i][j],a[j]-a[i]);
	}
	rep(i,4) rep(j,4) rep(k,4) chmin(d[j][k],d[j][i]+d[i][k]);
	cout<<d[0][2]<<endl;
}


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

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 (a>b) { a=b; return 1; } return 0; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()




int main() {
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    if (a + b < k) {
        int x = k - a - b;
        cout << a - x << endl;
    } else if (a < k) {
        cout << a << endl;
    } else {
        cout << k << endl;
    }
}


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

#define ff first
#define ss second
#define PI acos(-1)
#define pb push_back
#define int long long
#define ld long double
#define sp fixed<<setprecision
#define bp __builtin_popcountll
#define all(x) x.begin(),x.end()
#define pii pair<long long,long long>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

const int M = (1e9)+7;
const int N = 1e6+5;

signed main()
{
    FAST
    int tc=1;
    //cin>>tc;
    for(int ti=1;ti<=tc;ti++)
    {
        int n;
        cin>>n;
        int g = __gcd(360LL,n);
        int ans = (360/g);
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 3636
#include <stdio.h>
int main(){
	int n,a,b;
	long long int total=0;
	scanf("%d %d %d", &n, &a, &b);
	
	int i1=0,i2=0, i3=0, i4=0, i5=0;
	for(int i=1;i<=n;i++){
		
		i1=i/10000;	
		i2=(i%10000)/1000;
		i3=(i%1000)/100;
		i4=(i%100)/10;
		i5=i%10;
		
//		printf("%d %d %d %d %d\n", i1,i2,i3,i4,i5);
//		int temp=i;
//		int sum=0;
//		while(temp!=0){
//			sum+= temp%10;
//			temp/=10;

		int sum=i1+i2+i3+i4+i5;
		if(sum >=a && sum<=b){
			total+=i;
		
		}
	}

		printf("%lld\n", total);


	
	return 0;
}

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

int main(){
    double h, w, x, y;
    cin >> w >> h >> x >> y;
    cout << setprecision(11);
    cout << h * w / 2 << " " ;
    if (2 * x == w && 2 * y == h){
        cout << 1 << endl;
    }
    else{
        cout << 0 << endl;
    }
}

Measured memory_bytes: 384
#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> a(n), b(n), c(n-1);
    rep(i,n) cin >> a[i];
    rep(i,n) cin >> b[i];
    rep(i,n-1) cin >> c[i];
    int ans = 0;
    rep(i,n) {
        ans += b[i];
    }
    rep(i,n-1) {
        if (a[i]+1 == a[i+1]) {
            int x = a[i]-1;
            ans += c[x];
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
const int N=1000005;
bool vis[N];
vector<int>e[N],path,path2;
void dfs(int x)
{
	vis[x]=1;
	path.push_back(x);
	for(int i=0;i<e[x].size();i++)
	{
		if(!vis[e[x][i]])
		{
			dfs(e[x][i]);
			return;
		}
	}
}
int main()
{
	int n,m,a,b;
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)
	{
		scanf("%d%d",&a,&b);
		e[a].push_back(b);
		e[b].push_back(a);
	}
	dfs(1);
	swap(path,path2);
	dfs(1);
	printf("%d\n",path.size()+path2.size()-1);
	for(int i=(int)path2.size()-1;i>=0;i--)
		printf("%d ",path2[i]);
	for(int i=1;i<path.size();i++)
		printf("%d ",path[i]);
	printf("\n");
	return 0;
}


Measured memory_bytes: 30840
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())printf("%d ",v[_]);cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
// int dx[]={0,1,0,-1};
// int dy[]={1,0,-1,0};//RDLU
#define yes puts("YES")
#define no puts("NO")

int dp[410][410];
int n;
vi in;
int f(int l,int r){
	if(dp[l][r]-inf)return dp[l][r];
	if(r-l<2)return 0;
	int t=inf;
	loop(i,l,r-1)cmin(t,in[r]-in[l]+f(l,i+1)+f(i+1,r));
	return dp[l][r]=t;
}
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);

	rep(i,410)rep(j,410)dp[i][j]=inf;
	cin>>n;
	in=vi(n+1);
	rep(i,n)cin>>in[i+1];
	rep(i,n)in[i+1]+=in[i];
	cout<<f(0,n)<<endl;
}


Measured memory_bytes: 1664
// READ & UNDERSTAND
// ll, int overflow, array bounds, memset(0)
// special cases (n=1?), n+1 (1-index)
// do smth instead of nothing & stay organized
// WRITE STUFF DOWN

#include <bits/stdc++.h>

using namespace std;

#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end() 
#define MOD 1000000007

typedef long long ll;
typedef pair <int, int> ii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef long double ld;

ll INF=LLONG_MAX;

int const mxn=1e5+5;

vi adj[mxn];
ll h[mxn],cnt[mxn];


int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
	int n,m; cin >> n >> m;
	for(int i=1; i<=n; i++)cin >> h[i];
	memset(cnt,0,sizeof(cnt));
	for(int i=0; i<m; i++){
		int u,v;
		cin >> u >> v;
		if(h[v]>h[u]){
			cnt[v]++;
		}else if(h[u]>h[v]){
			cnt[u]++;
		}
		adj[u].pb(v); 
		adj[v].pb(u);
	}
	int ans=0;
	for(int i=1; i<=n; i++){
		if(adj[i].empty()||adj[i].size()==cnt[i]){
			ans++;
		}
	}
	cout << ans << endl;
}	


Measured memory_bytes: 10248
H, W = map(int, input().split())
S = [input() for i in range(H)]
C = [[0 for i in range(W)] for j in range(H)]
 
dx = [1, 1, 0, -1, -1, -1, 0, 1]
dy = [0, 1, 1, 1, 0, -1, -1, -1]
 
for i in range(H):
  for j in range(W):
    if S[i][j] == '.':
      for k in range(8):
        if 0 <= j + dx[k] < W and 0 <= i + dy[k] < H:
          if S[i + dy[k]][j + dx[k]] == '#':
            C[i][j] += 1
          else:
            pass
        else:
          pass
    else:
      C[i][j] = '#'
 
for i in range(H):
  for j in range(W):
    print(C[i][j], end = '')
  print('\n')

Measured memory_bytes: 3444
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <algorithm>
using namespace std;
#define ll long long
int main(){
    string s;
    cin>>s;
    if (s[0]==s[2]) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

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

        String AnsS = "keyence";
        String s = sc.nextLine();

        boolean isAns = true;

        int i = 0;
        int j = 0;
        int checkCnt = 0;
        while (checkCnt < AnsS.length()) {
            if (s.charAt(i) == AnsS.charAt(i)) {
                i++;
            }
            else if (s.charAt(s.length() - j - 1) == AnsS.charAt(AnsS.length() - j - 1)) {
                j++;
            }
            else {
                isAns = false;
            }
            checkCnt++;
        }

        System.out.println(isAns ? "YES" : "NO");
    }
}


Measured memory_bytes: 23636
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2e5+50;
int t,n,m;
int arr[maxn];
int main()
{
	ios::sync_with_stdio(false);
	cin>>n>>m;
	int sum=0;
	for(int i=1;i<=m;i++)
	{
		int a;cin>>a;
		sum+=a;
	}
	int fin=n-sum;
	if(fin<0) cout<<"-1"<<endl;
	else cout<<fin<<endl;
	return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long long INF = 10000000000000000;
int main(){
  int N, M;
  cin >> N >> M;
  int S, T;
  cin >> S >> T;
  S--;
  T--;
  vector<vector<pair<int, int>>> E(N);
  for (int i = 0; i < M; i++){
    int U, V, D;
    cin >> U >> V >> D;
    U--;
    V--;
    E[U].push_back(make_pair(D, V));
    E[V].push_back(make_pair(D, U));
  }
  vector<long long> d1(N, INF);
  priority_queue<pair<long long, int>, vector<pair<long long, int>>, greater<pair<long long, int>>> pq1;
  pq1.push(make_pair(0, S));
  vector<int> s1;
  while (!pq1.empty()){
    long long d = pq1.top().first;
    int v = pq1.top().second;
    pq1.pop();
    if (d1[v] == INF){
      d1[v] = d;
      s1.push_back(v);
      for (auto edge : E[v]){
        int w = edge.second;
        if (d1[w] == INF){
          pq1.push(make_pair(d + edge.first, w));
        }
      }
    }
  }
  vector<long long> dp1(N, 0);
  dp1[S] = 1;
  for (int i = 1; i < N; i++){
    int v = s1[i];
    for (auto edge : E[v]){
      int d = edge.first;
      int w = edge.second;
      if (d1[v] == d1[w] + d){
        dp1[v] += dp1[w];
        dp1[v] %= MOD;
      }
    }
  }
  vector<long long> d2(N, INF);
  priority_queue<pair<long long, int>, vector<pair<long long, int>>, greater<pair<long long, int>>> pq2;
  pq2.push(make_pair(0, T));
  vector<int> s2;
  while (!pq2.empty()){
    long long d = pq2.top().first;
    int v = pq2.top().second;
    pq2.pop();
    if (d2[v] == INF){
      d2[v] = d;
      s2.push_back(v);
      for (auto edge : E[v]){
        int w = edge.second;
        if (d2[w] == INF){
          pq2.push(make_pair(d + edge.first, w));
        }
      }
    }
  }
  vector<long long> dp2(N, 0);
  dp2[T] = 1;
  for (int i = 1; i < N; i++){
    int v = s2[i];
    for (auto edge : E[v]){
      int d = edge.first;
      int w = edge.second;
      if (d2[v] == d2[w] + d){
        dp2[v] += dp2[w];
        dp2[v] %= MOD;
      }
    }
  }
  long long ans = dp1[T] * dp2[S] % MOD;
  for (int i = 0; i < N; i++){
    if (d1[i] == d2[i]){
      long long tmp = dp1[i] * dp2[i] % MOD;
      long long sub = tmp * tmp % MOD;
      ans += MOD - sub;
      ans %= MOD;
    }
  }
  for (int i = 0; i < N; i++){
    for (auto edge : E[i]){
      int d = edge.first;
      int j = edge.second;
      if (d1[i] < d2[i] && d1[j] > d2[j] && d1[i] + d2[j] + d == d1[T]){
        long long tmp = dp1[i] * dp2[j] % MOD;
        long long sub = tmp * tmp % MOD;
        ans += MOD - sub;
        ans %= MOD;
      }
    }
  }
  cout << ans << endl;
}

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

using namespace std;
typedef long long ll;

#define INF (long long)(1e9+7)
#define REP(i,n) for(ll i = 0; i < n; i++)
#define REP1(i,n) for(ll i = 1; i <= n; i++)

int main(void)
{
  int n[6];
  cin >> n[0] >> n[1] >> n[2] >> n[3];
  sort(n, n+4);
  if(n[0] == 1 && n[1] == 4 && n[2] == 7 && n[3] == 9) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}


Measured memory_bytes: 256
import java.util.*;class Main{public static void main(String[]r){Scanner sc=new Scanner(System.in);int i,p,u,n=sc.nextInt(),m=sc.nextInt(),x=sc.nextInt(),w=Integer.MAX_VALUE,q=Integer.MAX_VALUE;int[]a=new int[n],b=new int[m];for(i=0;i<n;i++)w=(w<(a[i]=sc.nextInt()))?w:a[i];for(i=0;i<m;i++)q=(q<(b[i]=sc.nextInt()))?q:b[i];u=q+w;for(i=0;i<x;i++)u=(u<(p=a[sc.nextInt()-1]+b[sc.nextInt()-1]-sc.nextInt()))?u:p;System.out.println(u);}}

Measured memory_bytes: 149388
/*
 * a.cc:
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

/* typedef */

/* global variables */

/* subroutines */

/* main */



int main(){
  int a,b,c;
  cin>>a>>b;
  c=a*b;
  if(c%2==0) cout<<"Even"<<endl;
  else cout<<"Odd"<<endl;
}


Measured memory_bytes: 3000