akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

    /** 借金額 */
    private static final int LOAN = 100000;

    /** 1週間ごとの利子（％） */
    private static final int INTEREST = 5;

    /** 切り上げの単位 */
    private static final int ROUND_UP_SCALE = 1000;

    /**
     * <p>
     * 引数で与えられたn週間後の借金額の残高を出力する。<br/>
     * 借金額は10万円、利子は1週間につき5％、利子の計算後に1,000円未満を切り上げることとする。<br/>
     * <br/>
     * 標準入力から以下を入力値として受け取る。<br/>
     * ・何週間後か（0?100）<br/>
     * </p>
     *
     * @param args
     *            利用しない。
     * @throws IOException
     */
    public static void main(String[] args) throws IOException {

        // 入力値を受け取る
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = br.readLine();
        int weeks = Integer.parseInt(line);

        // n週間後の借金の残高を計算する
        int loanBalance = calcLoanBalance(weeks);

        // 結果を出力する
        System.out.println(loanBalance);

    }

    /**
     * <p>
     * 引数で与えられた週数が経過したときの借金の残高を計算する。<br/>
     * 1週間経過するごとに利子と残高を再計算し、金額の1,000円未満を切り上げる。<br/>
     * </p>
     *
     * @param weeks
     *            経過週数
     * @return 残高
     */
    private static int calcLoanBalance(int weeks) {

        int loanBalance = LOAN;
        for (int i = 0; i < weeks; i++) {
            loanBalance = roundUp(loanBalance + loanBalance * INTEREST / 100,
                    ROUND_UP_SCALE);
        }

        return loanBalance;

    }

    /**
     * <p>
     * 引数で与えられた数値を、引数で指定された単位で切り上げる。<br/>
     * </p>
     *
     * @param amount
     *            数値
     * @param scale
     *            切り上げの単位
     * @return 結果
     */
    private static int roundUp(int amount, int scale) {

        int quotient = amount / scale;
        int remainder = amount % scale;

        if (remainder == 0) {
            return amount;
        } else {
            return (quotient + 1) * scale;
        }

    }
}

Measured memory_bytes: 16864
#include<bits/stdc++.h>
 
#define ar array 
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i,a,b) for(int i = a; i < b; i++)
#define deb(x) cout << #x << "=" << x << endl
#define PI 3.1415926535897932384626
#define endl '\n'
 
using namespace std;
 
typedef long double ld; 
typedef vector<int> vi;
typedef pair<int,int> pii;
 
 
const  int mxN = 1e5+5;
const  long long INF= 1e18;
const long long mod= 1e9+7;


void solve() {
  int n, k;
  cin >> n >> k;

  vector<int> v(n);

  rep(i, 0, n) cin >> v[i];
  
  int ans = 1e9 + 100;
  int  l = 1, r = 1e9 + 100;

  while(l <= r) {
    int mid = (l + r)/2;

    int count = 0;
    rep(i, 0, n) {
      if(v[i] <= mid) continue;
      count += (v[i] + mid - 1)/mid - 1;
    }
    if(count <= k) {
      ans = min(ans, mid);
      r = mid - 1;
    }
    else l = mid + 1;
  }

  cout << ans << endl;
}

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

int t = 1;
//cin >> t;
while(t--) {
solve();
}
}



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

int main() {
	string s;
	cin >> s;
	int c = 0;
	for (int i = 2; i < (int) s.size(); i++) {
		if (s[i] == 'C')
			c++;
		else if (isupper(s[i])) {
			cout << "WA";
			return 0;
		}
	}
	if (c == 1 and s[s.size() - 1] != 'C') {
		if (s[1] != 'A' and s[1] != 'C') {
			if (isupper(s[1])) {
				cout << "WA";
				return 0;
			}
			if (s[0] == 'A')
				cout << "AC";
			else
				cout << "WA";
		} else {
			cout << "WA";
		}
	} else
		cout << "WA";
}


Measured memory_bytes: 256
#include <iostream>

bool f(std::string s) {
    int count = 0;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == 'o') {
            count++;
        }
    }
    return (8 - count) <= (15 - s.size()) ;
}

int main() {

    std::string s;
    std::cin >> s;

    if (f(s)) {
        std::cout << "YES" << std::endl;
    } else {
        std::cout << "NO" << std::endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,M,X,Y;
  cin >> N >> M >> X >> Y;
  vector<int> x(N+1);
  vector<int> y(M+1);
  x[N]=X;
  y[M]=Y;
  for(int i=0;i<N;i++) cin >> x[i];
  for(int i=0;i<M;i++) cin >> y[i];
  sort(x.begin(),x.end());
  sort(y.begin(),y.end());
  if(x[N]<y[0])cout << "No War";
  else cout << "War";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define nyan "(=^･ω･^=)"
#define mkp make_pair
#define lP pair<ll, ll>
#define iP pair<int,int>
typedef long long ll;
using namespace std;

int N, M, x, y, t, g[100000], G[100000], c[100000], DP[100000], MAX;
bool b[100000];
vector<int>v[100000];

void dfs(int x) {
	--c[x];
	g[t] = x;
	G[x] = t;
	++t;
	for (int i = 0; i != v[x].size(); ++i) {
		--c[v[x][i]];
		if (!c[v[x][i]])
			dfs(v[x][i]);
	}
}
int main() {
	cin >> N >> M;
	for (int i = 0; i != M; ++i) {
		cin >> x >> y;
		--x;
		--y;
		v[x].push_back(y);
		++c[y];
	}
	for (int i = 0; i != N; ++i) {
		if (!c[i])
			dfs(i);
	}
	for (int i = 0; i != N; ++i) {
//		cout << g[i] << endl;
		MAX = max(MAX, DP[i]);
		for (int j = 0; j != v[g[i]].size(); ++j) {
			DP[G[v[g[i]][j]]] = max(DP[G[v[g[i]][j]]], DP[i] + 1);
		}
	}
	cout << MAX << endl;
	return 0;
}

Measured memory_bytes: 10368
#include <bits/stdc++.h>
#define int long long
using namespace std;
//BEGIN CUT HERE
struct Dinic{
  const int INF=1<<28;
  
  struct edge {
    int to,cap,rev;
    edge(){}
    edge(int to,int cap,int rev):to(to),cap(cap),rev(rev){}
  };

  int n;
  vector<vector<edge> > G;
  vector<map<int,int> > M;
  vector<int> level,iter;

  Dinic(){}
  Dinic(int sz):n(sz),G(n),M(n),level(n),iter(n){}
  
  void add_edge(int from,int to,int cap){
    M[from][to]=G[from].size();
    M[to][from]=G[to].size();
    G[from].push_back(edge(to,cap,G[to].size()));
    // undirected
    //G[to].push_back(edge(from,cap,G[from].size()-1));
    // directed
    G[to].push_back(edge(from,0,G[from].size()-1));
  }
  
  void bfs(int s){
    fill(level.begin(),level.end(),-1);
    queue<int> que;
    level[s]=0;
    que.push(s);
    while(!que.empty()){
      int v=que.front();que.pop();
      for(int i=0;i<(int)G[v].size();i++){
        edge &e = G[v][i];
        if(e.cap>0&&level[e.to]<0){
          level[e.to]=level[v]+1;
          que.push(e.to);
        }
      }
    }
  }
  
  int dfs(int v,int t,int f){
    if(v==t) return f;
    for(int &i=iter[v];i<(int)G[v].size();i++){
      edge &e=G[v][i];
      if(e.cap>0&&level[v]<level[e.to]){
        int d = dfs(e.to,t,min(f,e.cap));
	     if(d>0){
	       e.cap-=d;
	       G[e.to][e.rev].cap+=d;
	       return d;
	     }
      }
    }
    return 0;
  }
  
  int flow(int s,int t,int lim){
    int fl=0;
    for(;;){
      bfs(s);
      if(level[t]<0||lim==0) return fl;
      fill(iter.begin(),iter.end(),0);
      int f;
      while((f=dfs(s,t,lim))>0){
	     fl+=f;
	     lim-=f;
      }
    }
  }

  int flow(int s,int t){
    return flow(s,t,INF);
  }

  //cap==1 only
  bool back_edge(int s,int t,int from, int to){
    for(int i=0;i<(int)G[from].size();i++) {
      edge& e=G[from][i];
      if(e.to==to) {
        if(e.cap==0&&flow(from,to,1)==0) {
          flow(from,s,1);
          flow(t,to,1);
          return 1;
        }
      }
    }
    return 0;
  }
};
//END CUT HERE

signed main(){
  int n,sum=0,X=0;
  cin>>n;
  int a[n];
  for(int i=0;i<n;i++) cin>>a[i],X+=max(a[i],0LL);
  Dinic D(n+2);
  
  for(int i=0;i<n;i++){
    int x=a[i];
    if(x<0)sum+=x,x=0;
    D.add_edge(n,i,x);
  }
  for(int i=0;i<n;i++){
    int x=-a[i];
    if(x<0)x=0;
    D.add_edge(i,n+1,x);
  }
  for(int i=0;i<n;i++){
    int x=i+1;
    for(int j=i+1;j<n;j++){
      int y=j+1;
      if(y%x==0){
        D.add_edge(j,i,1e13);
      }
    }
  }
  cout<<X-D.flow(n,n+1,1e18)<<endl;
}

Measured memory_bytes: 384
import java.io.*;
import java.util.*;




public class Main
{

	static int n,m;


	static int[][] a;


	static long[][] dp;

	static int mod=1000000007;



	static long find(int i,int j)
	{
		if(i>=n || j>=m) return 0L;
		if((i==n-1) && (j==m-1)) return 1L;
		if(dp[i][j] != -1) return (dp[i][j])%mod;
		dp[i][j]=0;
		if(j<(m-1) && a[i][j+1]!=0) dp[i][j]=(find(i,j+1))%mod;
		if(i<(n-1) && a[i+1][j]!=0) dp[i][j]+=(find(i+1,j))%mod;
		return dp[i][j]=dp[i][j]%mod;
	}

	


	public static void main(String[] Rohan)throws IOException
	{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));





		String[] s=br.readLine().split(" ");

		n=Integer.parseInt(s[0]);m=Integer.parseInt(s[1]);

		a=new int[n][m];

		dp=new long[n][m];


		for(int i=0;i<n;i++)
		{
			String s1=br.readLine();

			for(int j=0;j<m;j++)
			{
				if(s1.charAt(j)=='.') a[i][j]=1;
				else a[i][j]=0;
				dp[i][j]=-1;
			}
		}

		
		System.out.println(find(0,0));
		

	}
}

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

using ll = long long;

constexpr ll MOD = 1e9+7;
constexpr ll INF = 1ll<<60;

#define FOR(i,a,b) for (ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

int main(int argc, char **argv)
{
	ll N; cin >> N;
	vector<ll> P(N); REP(i, N) cin >> P[i];
	vector<ll> Q(N);

	REP(i, N)
	{
		Q[P[i]-1] = i;
	}

	ll res{1}, tmp{1};
	REP(i, N-1)
	{
		if (Q[i] < Q[i+1])
		{
			++tmp;
		}
		else
		{
			tmp = 1;
		}
		res = max(res, tmp);
	}

	std::cout << N - res << std::endl;
}

Measured memory_bytes: 3456
import math
N,D,A=map(int,input().split())
l=[]
for i in range(N):
  k=list(map(int,input().split()))
  l.append(k)
l.sort()
S=[0]*N
ma=[0]*N
tmp=N-1
for i in reversed(range(N)):
  x=l[i][0]
  for j in reversed(range(0,tmp)):
    if abs(l[j][0]-(x-D))>D:
      ma[i]=j+1
      tmp=j+1
      break
  else:
    ma[i]=0
    tmp=0
ans=0
S[0]=math.ceil(l[0][1]/A)
for i in range(1,N):
  h=l[i][1]
  left=S[ma[i]-1] if ma[i]>0 else 0
  right=S[i-1]
  sum_=(right-left)*A
  if h<=sum_:
    S[i]=S[i-1]
    continue
  time=math.ceil((h-sum_)/A)
  S[i]=time+S[i-1]
print(S[N-1])

Measured memory_bytes: 100824
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <algorithm>

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

using namespace std;

bool large(pair<int, int> p1, pair<int, int> p2) {
	if (p1.first == p2.first)
		return p1.second < p2.second;
	else
		return p1.first > p2.first;
}

int main(void) {	
	int n, m;
	while (cin >> n >> m && n > 0) {
		vector<pair<int,int> > v(m);
		REP(i, m) {
			v[i].first = 0;
			v[i].second = i+1;
		}
		REP(i, n) {
			REP(j, m) {
				int a;
				cin >> a;
				v[j].first += a;
			}
		}
		sort(v.begin(), v.end(), large);
		cout << v[0].second;
		FOR(i, 1, m - 1)
			cout << " " << v[i].second;
		cout << endl;
		
	}
				  
	return 0;
}

Measured memory_bytes: 1200
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();
		int A = sc.nextInt();
		int B = sc.nextInt();
		sc.close();
		if(B <= A) {
			System.out.println("delicious");
		}else if(A + X >= B) {
			System.out.println("safe");
		}else {
			System.out.println("dangerous");
		}
	}
}

Measured memory_bytes: 21332
S = input()
  
judge = 'Yes'
count = 1
for item in S:
  if count % 2 == 1:
    if item == 'L':
      judge = 'No'
      break;
  if count % 2 == 0:
    if item == 'R':
      judge = 'No'
      break;

  count += 1

print(judge)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define X first
#define Y second
using namespace std;
typedef pair<int,int> pii;

int h, w, d[1005][1005], ans;
char tmp[1005];

queue<pii> q;

bool valid (int X, int Y) {
	return (1 <= X && X <= h && 1 <= Y && Y <= w);
}

int main()
{
	scanf("%d%d",&h,&w);
	for(int i=1;i<=h;i++) {
		scanf("%s",tmp+1);
		for(int j=1;j<=w;j++) {
			if(tmp[j] == '#') {
				d[i][j] = 1;
				q.push({i, j});
			}
		}
	}
	while(!q.empty()) {
		int A, B;
		tie(A, B) = q.front();
		ans = max(ans, d[A][B]-1);
		q.pop();
		for(int i=0;i<4;i++) {
			int dx = "1210"[i] - '1', dy = "2101"[i] - '1';
			if(!valid(A+dx, B+dy) || d[A+dx][B+dy]) continue;
			d[A+dx][B+dy] = d[A][B] + 1;
			q.push({A+dx, B+dy});
		}
	}
	printf("%d\n",ans);
}


Measured memory_bytes: 12304
/*
 * Remember a 7.0 student can know more than a 10.0 student.
 * Grades don't determine intelligence, they test obedience. 
 * I Never Give Up.
 */
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0);
#define pb emplace_back
#define endl "\n"
#define f first
#define mp make_pair
#define s1 second
#define delrep  v.erase(unique(v.begin(),v.end()),v.end());
#define all(a)  (a).begin(),(a).end()
#define sz(x)   (int)x.size()
#define lll __int64
const int N=1e6+10;
const int M=1e3+7;
const int MOD =1e9+7;
using namespace std;
typedef long long ll;
vector<vector<ll>> adj(N);
vector<pair<ll,ll>>adj2[N];
vector<ll> vis(N),out(N); 
vector<ll> vx;
vector<ll>a(N);
set<ll>s;
ll n,m,k,ans,cnt,dis=0,ind;
bool visx[M][M];
int used[M][M];
char ch[M][M];
vector<int>ax(N),bx(N),b(N);
int idx[]={0,-1,0,1};
int idy[]={1,0,-1,0};
inline bool in (int x , int y) { return 1 <= x && x <n+1 && 1<= y && y <m+1; }
ll power(ll a, ll n, ll m = MOD) {
    if(n==0) return 1; ll p = power(a, n>>1, m); p=(p*p)%m;
    if(n&1) p=(p * a) % m;
    return p;
}
void dfs2(ll x, ll y=0)
{
   vis[x]=1; //cout<<x<<" "<<y<<endl;
   y+=ax[x]; bx[x]=y;
   for(auto i : adj[x]) {  if(!vis[i]) dfs2(i,y); } 

}
void dfs3(int i,int p=-1) 
{
    for(auto j : adj[i]) if(j!=p) {  ax[j]+=ax[i];  dfs3(j,i); }
}
void dfs(ll x, ll y) 
{
   if(!in(x,y) || ch[x][y]=='*' || visx[x][y]) return;
   visx[x][y]=1;
   cnt++;
   used[x][y]=ind;
   for(int i=0;i<4;i++) dfs(x+idx[i],y+idy[i]);   
}
void dfsz(ll x,ll y, ll z)
{
  vis[x]=1;                                                                  
  if(a[x]^y!=b[x]) { vx.pb(x); y=!y; }
  for(auto i:adj[x]) if(!vis[i]) dfsz(i,z,y);                              
}
                                                    
int main() 
{  
   cin>>n>>k; for(int i=1;i<n;i++) { int x,y; cin>>x>>y; adj[x].pb(y); adj[y].pb(x); }
   while(k--) { int x1,y1; cin>>x1>>y1; ax[x1]+=y1;  }
   dfs3(1);
   for(int i=1;i<=n;i++) cout<<ax[i]<< " ";
}                                                                                                  




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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
using ull = unsigned long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int gcd(int x, int y){
  if(y==0)return x;
  return gcd(y,x%y);
}

int cnter(int n){
  int cnt = 0;
  while(n&&n%2==0){
    cnt++;
    n/=2;
  }
  return cnt;
}

int main(){
  int n,k; cin >> n >> k;
  int ans = 1;
  for(int i = 0; i < n; ++i){
    if(ans < k)ans *= 2;
    else ans += k;
  }
  cout << ans << endl;
} 


Measured memory_bytes: 3600
import java.util.Scanner;

class Main{
    public static void main(String args[]){
        Scanner scanner = new Scanner(System.in);
        while(true){
            int x = scanner.nextInt();
            int y = scanner.nextInt();
            if(x == 0 && y == 0) break;
            if(x < y){
                System.out.println(Integer.toString(x) + " " +Integer.toString(y));
            }else{
                System.out.println(Integer.toString(y) + " " +Integer.toString(x));  
            }
        }
    }
}


Measured memory_bytes: 34372
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        while(scan.hasNext()){
            int n = scan.nextInt();
            if(n == 0){
                break;
            }
            int[] a = new int[n];
            for(int i = 0;i < n;i++){
                a[i] = scan.nextInt();
            }
            int max = a[0];
            int res = a[0];
            for(int i = 1;i < n;i++){
            	max = maximum(a[i],a[i]+max);
            	res = maximum(res,max);
            }
            System.out.println(res);
        }
    }
    public static int maximum(int a,int b){
        return (a > b)?a:b;
    }
}

Measured memory_bytes: 26340
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MM = 1000000000;
const int MOD = MM + 7;
const int MAX = 510000;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
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;}
const ll INF = 1LL << 60;
const double pi = acos(-1.0);

int main() {
    int n, m; cin >> n >> m;
    vector<pair<int, int>> v(m);
    rep(i, m) {
        int a, b; cin >> a >> b;
        v[i] = make_pair(a, b);
    }
    sort(all(v), [](pair<int, int> x, pair<int, int> y){
        if(x.second != y.second) return x.second < y.second;
        else return x.first < y.first;
    });
    int ans = 1;
    int now = v[0].second;
    Rep(i, 1, m) {
        if(now <= v[i].first) {
            ans++;
            now = v[i].second;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 4052
import os
import sys

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

N = int(input())
A = np.array(list(map(int, input().split())), dtype=int) - 1
print((A[A] == np.arange(N)).sum() // 2)


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

int counter(int x) {
    if(x == 0) return 0;
    return counter(x >> 1) + (x & 1);
}

int main() {

int N;
int A[20];
int x[20][20], y[20][20];

  //get data OK
 cin >> N;
for(int i = 1; i < N + 1; i++){
 cin >> A[i];
for(int j = 1; j < A[i]+1; j++){
 cin >> x[i][j] >> y[i][j];
}
}

  int ans = 0;
  for (int bits = 0; bits < (1 << N); bits++){
      bool judge = true;
    for (int i = 1; i < N+1; i++) {
      if (!(bits & (1 << (i - 1)))) continue;
  for (int j = 1; j < A[i] + 1; j++) {
    if (((bits >> (x[i][j]-1)) & 1) ^ y[i][j]) judge = false;
  }
  }
  if(judge == true) ans = max(ans, counter(bits));    
  }  
       cout << ans << endl;
}

Measured memory_bytes: 256
//# define FLAG
///delet....................................
# include <bits/stdc++.h>
using namespace std;
# define eps 1e-8
# define VI vector<int>
# define pb push_back
# define mp make_pair
# define pi acos(-1.0)
# define bug puts("H")
# define mem(a,b) memset(a,b,sizeof(a))
# define IOS ios::sync_with_stdio(false)
# define FO(i,n,a) for(int i=n; i>=a; --i)
# define FOR(i,a,n) for(int i=a; i<=n; ++i)
# define MAX 0x7fffffffffffff
# define INF 0x3f3f3f3f
# define MOD 1e9+7
# define Template int   ///          <-------------变量类型
# define hr putchar('\n')
# define pc putchar
# pragma comment(linker, "/STACK:1024000000,1024000000")
typedef unsigned long long ULL;
typedef long long LL;
inline char gtc() {
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
inline Template Scan() {
    int flag=1;
    char ch=gtc();
    if(ch==EOF)return EOF;   ///EOF的值是-1
    Template sum=0;
    while(!((ch>='0'&&ch<='9')||ch=='-'))ch=gtc();
    if(ch=='-')flag=-1,ch=gtc();
    while(ch>='0'&&ch<='9')sum=sum*10+ch-'0',ch=gtc();
    return sum*flag;
}
inline int Scan(Template &sum) {
    int flag=1;
    char ch=gtc();
    if(ch==EOF)return EOF;   ///EOF的值是-1
    sum=0;
    while(!((ch>='0'&&ch<='9')||ch=='-'))ch=gtc();
    if(ch=='-')flag=-1,ch=gtc();
    while(ch>='0'&&ch<='9')sum=sum*10+ch-'0',ch=gtc();
    sum*=flag;
    return 1;
}
inline void Out(Template x) {
    if(x<0)putchar('-'),x=-x;
    if(x>9)Out(x/10);
    putchar(x%10+'0');
}
///coding...................................

struct node {
    LL a;
    double b;
    LL c;
}a[5];

bool cmp(node i,node j) {
    return i.b<j.b;
}

int main() {
    IOS;
#ifdef FLAG
    freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
#endif
    LL n,ans=0;
    FOR(i,1,4)cin>>a[i].a;
    a[1].b=a[1].a*4,a[1].c=4;
    a[2].b=a[2].a*2,a[2].c=2;
    a[3].b=a[3].a,a[3].c=1;
    a[4].b=a[4].a/2.0,a[4].c=0;
    cin>>n;
    sort(a+1,a+5,cmp);
    //FOR(i,1,4)cout<<a[i].c<<endl;
    if(a[1].c==0) {
        ans+=n/2*a[1].a,n%=2;
        if(n)ans+=n*a[2].c*a[2].a;
    }
    else {
        ans+=n*a[1].c*a[1].a;
    }
    cout<<ans<<endl;
    return 0;
}











///delete FLAG..............................






Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#ifndef LOCAL
#define endl '\n'
#endif

const int mod = 1e9 + 7;

int pwr(int a,int b) {
	int ans = 1;
	while(b) {
		if(b & 1) ans = (ans * 1LL * a) % mod;
		a = (a * 1LL * a) % mod;
		b >>= 1;
	}
	return ans;
}

void yes() {
	cout << "Yes" << endl;
	exit(0);
}

void no() {
	cout << "No" << endl;
	exit(0);
}

const int N = 1e5 + 5;
int a[N];

void solve() {
	int n;
	cin >> n;
	set<int> s;
	for(int i = 1; i <= n; i++) {
		cin >> a[i];
		s.insert(a[i]);
	}
	if(s.size() > 2) {
		no();
		return;
	}
	if(s.size() == 1) {
		int v = *s.begin();
		if(v == n - 1) {
			yes();
		}
		if(2 * v <= n) {
			yes();
		}
		no();
	}
	int v1 = *s.begin();
	s.erase(s.begin());
	int v2 = *s.begin();
	if(v2 != v1 + 1) {
		no();
	}
	int c1 = 0, c2 = 0;
	for(int i = 1; i <= n; i++) {
		if(a[i] == v1) c1++;
		else c2++;
	}
	if(v2 > c1 && 2 * (v2 - c1) + c1 <= n) {
		yes();
	}
	no();
}

signed main() {
	ios :: sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t;
	// cin >> t;
	t = 1;
	for(int tt = 1; tt <= t; tt++) {
		// cout << "Case #" << tt << ": ";
		solve();
	}
	return 0;
}

Measured memory_bytes: 5376
// abc164_b
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

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

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    int A, B, C, D;
    cin >> A >> B >> C >> D;

    int x = (C + B - 1) / B;
    int y = (A + D - 1) / D;

    if (x <= y){
        print("Yes");
    } else {
        print("No");
    }

    return 0;
}


Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
int n;
char s[100005];
int main() {
	scanf(" %s",s);
	n = strlen(s);
	for(int i=0;i<n-1;i++) {
		if(s[i]=='A' && s[i+1]=='C'){
			printf("Yes");
			return 0;
		}
	}
	printf("No");
}


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

int main(){
  int n;
  cin >> n;
  
  int l = 0,r = 0;
  int ans = 0;
  
  for(int i = 0;i < n;i++){
    cin >> l >> r;
    ans += (r - (l - 1));
  }

  cout << ans << endl;

}


Measured memory_bytes: 256
#include <stdio.h>
#include <vector>

using namespace std;

#define REP(a, i, n) for (int i = a; i < n; ++i)

int max(int X, int Y) {
    return X > Y ? X : Y;
}

int abs(int a, int b) {
    return max(b - a, a - b);
}

struct data_t {
    int i;
    int before_cost;
    int after_cost;
    int new_cost;
    int total;
};

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

    int A[N + 2];
    A[0] = 0;
    REP(1, i, N + 1) {
        scanf("%d", &A[i]);
    }
    A[N + 1] = 0;

    int total = 0;
    REP(0, i, N + 1) {
        total += abs(A[i], A[i + 1]);
    }

    vector<data_t> v;
    int before_cost = 0;
    int after_cost = 0;
    int new_cost = 0;
    REP(1, i, N + 1) {
        before_cost = abs(A[i], A[i - 1]);
        after_cost = abs(A[i + 1], A[i]);
        new_cost = abs(A[i + 1], A[i - 1]);
        v.push_back((data_t){i, before_cost, after_cost, new_cost, total - before_cost - after_cost + new_cost});
    }

    REP(0, i, N) {
        // printf("i: %d, before_cost: %d, after_cost: %d, new_cost: %d, total: %d\n", v[i].i, v[i].before_cost, v[i].after_cost, v[i].new_cost, v[i].total);
        printf("%d\n", v[i].total);
    }

    return 0;
}


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

int main() {
	int mai;
	int alice(0), bob(0);
	vector<int>vec;

	cin >> mai;
	for (int i = 0; i < mai; i++) {
		int k;
		cin >> k;
		vec.push_back(k);
	}

	/*for (int i = 0; i < mai; i++) {
		cout << vec.at(i);
	}*/

	sort(vec.begin(), vec.end());
	reverse(vec.begin(), vec.end());


	for (int i = 0; i < mai; i++) {
		if (i % 2 == 0) {
			alice += vec.at(i);
		}
		if (i % 2 == 1) {
			bob += vec.at(i);
		}
	}

	cout << alice-bob;

}


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


public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));
		
		int n = Integer.parseInt(buf.readLine());
		String[] str = buf.readLine().split(" ");
	
		long sum = 0;
		int max = Integer.MIN_VALUE, min = Integer.MAX_VALUE, tmp = 0; 
		for (int i = 0; i < n; i++) {
			tmp = Integer.parseInt(str[i]);
			if(tmp < min)min = tmp;
			if(tmp > max)max = tmp;
			sum = sum + tmp;
		}
		System.out.println(min+" "+max+" "+sum);
	}

}

Measured memory_bytes: 25608
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <stack>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <complex>
#include <string>
#include <sstream>

#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cstring>

using namespace std;

#define all(c) c.begin(),c.end()
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

typedef long long ll;
typedef vector<int> vi;


template<typename T>
ostream& operator<<(ostream& os,const vector<T>& val){
    os << "[ ";
    for(typename vector<T>::const_iterator it=val.begin();
        it != val.end();++it){
        os << *it << " ";
    }
    os << "]";
    return os;
}

int main(){
    int D,N;
    cin >> D >> N;
    vector<int> T(D);
    vector<int> A(N),B(N),C(N);
    for(int i=0;i<D;i++) cin >> T[i];
    for(int i=0;i<N;i++) cin >> A[i] >> B[i] >> C[i];

    const int dame = -1;
    vector<int> maxi(N,dame);
    // first day.
    for(int i=0;i<N;i++){
        if(A[i] <= T[0] and T[0] <= B[i]){
            maxi[i] = 0;
        }
    }

    for(int i=1;i<D;i++){
        vector<int> next(N,dame);
        for(int mae=0;mae<N;mae++){
            if(maxi[mae] == dame) continue;
            for(int now=0;now<N;now++){
                if(A[now] <= T[i] and T[i] <= B[now]){
                    next[now] = max(next[now],maxi[mae]+abs(C[mae]-C[now]));
                }
            }
        }
        maxi = next;
    }
    cout << *max_element(all(maxi)) << endl;
    return 0;
}

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

#define W 50
#define H 50

using namespace std;
void dfs(int w, int h);
int map[H][W];
int dy[8] = {1,1,0,-1,-1,-1,0,1}, dx[8] = {0,-1,-1,-1,0,1,1,1};
int w,h;

int main(){
  int i = 0,j = 0,is=0;
  cin >> w >> h;

  while(w != 0 && h != 0){
    for(i = 0;i < h;i++){
      for(j = 0;j<w;j++){
	cin>>map[i][j];
      }
    }
    i = j = 0;
    is = 0;
    while(i <= h-1  && j <= w-1){
      if(map[i][j] == 1){
	dfs(i,j);
	is++;
      }
      i++;
      if(i == h){
	i = 0;
	j++;
      }
    }
    cout << is << endl;
    cin >> w >> h;
  }
  return 0;
}

void dfs(int x,int y){
  int i = 0;
  map[x][y] = 0;
  for(i = 0;i < 8; i++){
    if(x + dx[i] > -1 && y + dy[i] > -1 && x + dx[i] < h && y + dy[i] < w){
      if(map[x + dx[i]][y + dy[i]] == 1){
	dfs(x + dx[i],y + dy[i]);
      }
    }
  }
}

Measured memory_bytes: 1236
#include <algorithm>
#include <cmath>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>
#define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef double db;
typedef __int128_t int128;
const int maxn = 1e2 + 10;
int n, m;
int x1[maxn], y11[maxn], x2[maxn], y2[maxn];
db width(int *x, int *y, int n, db x0)
{
    double lb = 1e8, ub = -1e8;
    for (int i = 0; i < n; i++)
    {
        double x1 = x[i], y1 = y[i], x2 = x[(i + 1) % n], y2 = y[(i + 1) % n];
        if ((x1 - x0) * (x2 - x0) <= 0 && x1 != x2)
        {
            double y0 = y1 + (y2 - y1) * (x0 - x1) / (x2 - x1);
            lb = min(lb, y0);
            ub = max(ub, y0);
        }
    }
    return max(0.0, ub - lb);
}
int main()
{
    IOS;
    while (cin >> m >> n)
    {
        if (m == 0 && n == 0)
            break;
        for (int i = 0; i < m; i++)
            cin >> x1[i] >> y11[i];
        for (int i = 0; i < n; i++)
            cin >> x2[i] >> y2[i];
        int min1 = *min_element(x1, x1 + m), max1 = *max_element(x1, x1 + m);
        int min2 = *min_element(x2, x2 + n), max2 = *max_element(x2, x2 + n);
        vector<int> v;
        for (int i = 0; i < m; i++)
            v.push_back(x1[i]);
        for (int i = 0; i < n; i++)
            v.push_back(x2[i]);
        sort(v.begin(), v.end());
        double ans = 0;
        for (int i = 0; i + 1 < v.size(); i++)
        {
            db a = v[i], b = v[i + 1], c = (a + b) / 2;
            if (min1 <= c && c <= max1 && min2 <= c && c <= max2)
            {
                double fa = width(x1, y11, m, a) * width(x2, y2, n, a);
                double fb = width(x1, y11, m, b) * width(x2, y2, n, b);
                double fc = width(x1, y11, m, c) * width(x2, y2, n, c);
                ans += (b - a) / 6 * (fa + 4 * fc + fb);
            }
        }
        cout << fixed << setprecision(12) << ans << endl;
    }

    return 0;
}



Measured memory_bytes: 3240
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n: usize,
        v: [usize; n]
    }
    let segt = SegT::from_vec(v);
    let mut ans = 0;
    for i in 0..n {
        ans = std::cmp::max(ans, segt.get(i));
    }
    println!("{}", ans);
}

fn gcd(n: usize, m: usize) -> usize {
    let mut l = std::cmp::min(n, m);
    let mut r = std::cmp::max(n, m);
    while l > 0 {
        let t = l;
        l = r % l;
        r = t;
    }
    r
}

#[derive(Debug)]
struct SegT {
    v: Vec<usize>,
    n: usize
}

impl SegT {
    fn from_vec(xs: Vec<usize>) -> SegT {
        let l = xs.len();
        let mut s = 1;
        while s < l {
            s *= 2;
        }
        let mut v = vec![0; 2 * s - 1];
        for i in 0..l {
            v[i + s - 1] = xs[i];
        }
        for i in 2..s + 1 {
            let p = s - i;
            v[p] = gcd(v[2 * p + 1], v[2 * p + 2]);
        }
        SegT{v: v, n: s}
    }

    fn get(&self, idx: usize) -> usize {
        let n = self.n;
        self.get_rec(idx, 0, 0, n - 1)
    }

    fn get_rec(&self, idx: usize, p: usize, pl: usize, pr: usize) -> usize {
        if pl > idx || pr < idx {
            self.v[p]
        } else if pl == idx && pr == idx {
            0
        } else {
            let a = self.get_rec(idx, 2 * p + 1, pl, (pl + pr - 1) / 2);
            let b = self.get_rec(idx, 2 * p + 2, (pl + pr + 1) / 2, pr);
            gcd(a, b)
        }
    }
}


Measured memory_bytes: 6396
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};


int main(){
    int n, k;
    cin >> n >> k;
    vector<int> x(n);
    rep(i, n) cin >> x[i];
    int ans = 0;
    rep(i, n) {
        int now = min(x[i], k-x[i]);
        ans += 2*now;
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define soja(i,a,n) for(ll i=a;i<=n;i++)
#define ulta(i,n,a) for(ll i=n;i>=a;i--)
#define pb push_back
int main()
{
    bool fg=0;
    ll n,m,k,i,j,sum=0;
    double p,c;
    cin>>n>>m;
    soja(i,0,n-1)
    {
        cin>>p>>c;
        if(sqrt((p*p)+(c*c))<=m)
            sum++;
    }
    cout<<sum<<endl;
return 0;
}


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

using namespace std;

void getResult(int a, int b, long long* vals, long long** result) {

	if (result[a][b] != -1) {
		return;
	}

	if (a == b) {
		result[a][b] = vals[a];
		return;
	}

	getResult(a + 1, b, vals, result);
	getResult(a, b - 1, vals, result);

	if (result[a + 1][b] < result[a][b - 1]) {
		result[a][b] = result[a + 1][b] + vals[a];
	}

	else {

	}

	result[a][b] = max(vals[a] - result[a + 1][b], vals[b] - result[a][b - 1]);
	return;

}

int main() {

	int n;
	cin >> n;

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

	// Resulting value of x-y for a game only including values from indices a to b
	long long** result = new long long*[n];
	for (int i = 0; i < n; i++) {
		result[i] = new long long[n];
	}

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			result[i][j] = -1l;
		}
	}

	getResult(0, n-1, vals, result);
	cout << result[0][n-1] << endl;

}

Measured memory_bytes: 70912
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
int main(){
    int n,t;
    cin >> n >> t;
    long long a[n],b[n];
    rep(i,n) cin >> a[i] >> b[i];
    //long long dp[n+1][t+3010][2];
    vector<vector<vector<long long>> > dp;
    vector<vector<long long>> tmp;
    vector<long long> tmpp = {0,0};
    rep(i,t+3010) tmp.push_back(tmpp);
    rep(i,n+1){
        dp.push_back(tmp);
    }
    //rep(i,t+3010) dp[0][i][0]=0;
    //rep(i,t+3010) dp[0][i][1]=0;
    rep(i,n+1){
        rep(j,t+3010){
            dp[i][j][0]=0;
            dp[i][j][1]=0;
        }
    }
    //dp[0][0][0] = 0;
    //dp[0][0][1] = 1;
    long long ans = 0;
    rep(i,n){
        rep(j,t+2){
                dp[i+1][j+a[i]][0] = max(dp[i+1][j+a[i]][0],dp[i][j][0]+b[i]);
                dp[i+1][j][0] = max(dp[i+1][j][0],dp[i][j][0]);
                dp[i+1][j][1] = max(dp[i+1][j][1],dp[i][j][0] + b[i]);
        }
        rep(j,t+2){
                dp[i+1][j+a[i]][1] = max(dp[i+1][j+a[i]][1],dp[i][j][1]+b[i]);
                dp[i+1][j][1] = max(dp[i+1][j][1],dp[i][j][1]);
        }
    }
    //rep(i,t+1) ans = max(ans,dp[n][i][0]);
    //rep(i,t) ans = max(ans,dp[n][i][1]);
    ans = max(dp[n][t-1][1],dp[n][t][0]);
    cout << ans << endl;
}

Measured memory_bytes: 996480
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000007
int main()
{
    int n,k;
    cin>>n>>k;
    int a[n];
    for(int i=0;i<n;i++)
    cin>>a[i];
    int dp[n];
    dp[0]=0;
    dp[1]=abs(a[1]-a[0]);
    for(int i=2;i<n;i++)
    {dp[i]=INT_MAX;
        for(int j=i-k;j<i;j++)
        {
            if(j>=0)
            {
                dp[i]=min(dp[i],abs(a[i]-a[j])+dp[j]);
            }
        }
    }
    cout<<dp[n-1]<<endl;
    
}

Measured memory_bytes: 1024
import java.util.*;
import java.lang.*;
import java.io.*;

public class Main{
    public static void main(String[] args) throws IOException{
        FastReader in = new FastReader();
        FastWriter out = new FastWriter();
        String s = in.next();
        switch (s){
            case "SUN":
                out.pl(7);
                break;
            case "MON":
                out.pl(6);
                break;
            case "TUE":
                out.pl(5);
                break;
            case "WED":
                out.pl(4);
                break;
            case "THU":
                out.pl(3);
                break;
            case "FRI":
                out.pl(2);
                break;
            case "SAT":
                out.pl(1);
                break;
        }
        out.close();
    }
}
class FastReader{ 
    BufferedReader br; 
    StringTokenizer st; 
    public FastReader() { 
        br = new BufferedReader(new InputStreamReader(System.in)); 
    } 
    String next(){ 
        while (st == null || !st.hasMoreElements()) { 
            try{ 
                st = new StringTokenizer(br.readLine()); 
            }catch (IOException  e){ 
                e.printStackTrace(); 
            } 
        } 
        return st.nextToken(); 
    } 
    int nextInt(){ 
        return Integer.parseInt(next()); 
    } 
    long nextLong(){ 
        return Long.parseLong(next()); 
    } 
    double nextDouble(){ 
      return Double.parseDouble(next()); 
    } 
    String nextLine(){ 
        String str = ""; 
        try{ 
            str = br.readLine(); 
        } 
        catch (IOException e){ 
            e.printStackTrace(); 
        } 
        return str; 
    } 
}
class FastWriter{
    PrintWriter out;
    FastWriter(){
        out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
	out.flush();
    }
    void pl(Object o){
        out.write(o.toString());
	    out.write("\n");
        out.flush();
    }
    void pl(){
        out.write("\n");
    }
    void p(Object o){
        out.write(o.toString());
    }
    void close(){
        out.flush();
        out.close();
    }  
}


Measured memory_bytes: 32852
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<queue>

using namespace std;

struct UnionFind{
  vector<int> par;
  vector<int> sizes;
  UnionFind(int n) : par(n), sizes(n, 1) {
    for(int i=0;i<n;i++) par[i] = i;
  }

  int find(int x) {
    if (x == par[x]) return x;
    return par[x] = find(par[x]);  // 根を張り替えながら再帰的に根ノードを探す
  }

  void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    if (sizes[x] < sizes[y]) swap(x, y);
    par[y] = x;
    sizes[x] += sizes[y];
  }

  bool same(int x, int y) {
    return find(x) == find(y);
  }

  long long int size(int x) {
    return sizes[find(x)];
  }
};

int main(){

  int v,e;
  cin >> v >> e;

  vector<vector<long long>> G(e);
  for(int i=0;i<e;i++){
    int a,b,c;
    cin >> a >> b >> c;
    G[i].push_back(c);
    G[i].push_back(a);
    G[i].push_back(b);
  }

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

  UnionFind tree(v);
  long long int s=0;

  for(int i=0;i<e;i++){
    if(tree.same(G[i][1],G[i][2]));
    else{
      tree.unite(G[i][1],G[i][2]);
      s+=G[i][0];
    }
  }

  cout << s << endl;

}


Measured memory_bytes: 10080
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(long long x){
  char f[20];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
template<class S, class T> inline S chmin(S &a, T b){
  if(a>b){
    a=b;
  }
  return a;
}
int N;
int A[18];
long long doit(int a, int b, long long m1, long long m2){
  int i;
  long long res;
  if(b-a==1){
    return 0;
  }
  res = 4611686016279904256LL;
  for(i=a+1;i<b;i++){
    chmin(res, doit(a,i,m1,m1+m2) + doit(i,b,m1+m2,m2) + A[i] * (m1 + m2));
  }
  return res;
}
int main(){
  long long res;
  rd(N);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=0;Lj4PdHRW<N;Lj4PdHRW++){
      rd(A[Lj4PdHRW]);
    }
  }
  res = doit(0, N-1, 1, 1) + A[0] + A[N-1];
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190714-1

// --- original code ---
// int N, A[18];
// 
// ll doit(int a, int b, ll m1, ll m2){
//   int i;
//   ll res;
// 
//   if(b-a==1) return 0;
//   
//   res = ll_inf;
//   rep(i,a+1,b) res <?= doit(a,i,m1,m1+m2) + doit(i,b,m1+m2,m2) + A[i] * (m1 + m2);
//   return res;
// }
// 
// {
//   ll res;
//   rd(N,A(N));
//   res = doit(0, N-1, 1, 1) + A[0] + A[N-1];
//   wt(res);
// }


Measured memory_bytes: 256
#include <iostream>
int main() {
    int n, m, l, a[100][100], b[100][100];
    std::cin >> n >> m >> l;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            std::cin >> a[i][j];
        }
    }
    for (int i = 0; i < m; ++i) {
        for (int j = 0; j < l; ++j) {
            std::cin >> b[i][j];
        }
    }
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < l; ++j) {
            long s = 0L;
            for (int k = 0; k < m; ++k) {
                s += a[i][k] * b[k][j];
            }
            if (j > 0) {
                std::cout << ' ';
            }
            std::cout << s;
        }
        std::cout << std::endl;
    }
}



Measured memory_bytes: 3164
def resolve():
    x = []
    y = []
    c = []
    ans = []
    A, B, M = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    for _ in range(M):
        X, Y, C = map(int, input().split())
        x.append(X)
        y.append(Y)
        c.append(C)
    ans.append(min(a)+min(b))
    for i in range(M):
        ans.append(a[x[i]-1]+b[y[i]-1]-c[i])
    print(min(ans))
resolve()

Measured memory_bytes: 34640
#include <iostream>
#include <math.h>
#include <algorithm>
using namespace std;
#define rep(i,q) for(int i = 0; (q) > i; i++)
#define all(c) (c).begin(),(c).end()
int main(){
  int N,H;cin>>N>>H;
  int a[N],b[N];
  int amax = 0;
  int sm = 0;
  int nage = 0;
  rep(i,N){
    cin >> a[i] >> b[i];
    if(amax < a[i]){
      amax=a[i];
    }
  }
  int kekka = 0;
  sort(b,b+N,greater<int>());
  rep(i,N){
    if(b[i] > amax)H-=b[i],nage++;
    if(H <= 0){
      kekka = i+1;
      break;
    }
  }
  
  if(kekka == 0){
    kekka = H/amax+(H%amax==0?0:1)+nage;
  }
  cout << kekka << endl;
}

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2018/02/23  Problem: 003_agc_b / Link: https://agc003.contest.atcoder.jp/tasks/agc003_b?lang=en ----- */
/* ------問題------

高橋君は 1 から N までの整数のうちのどれかが書かれたカードをたくさん持っています。 高橋君は整数 i が書かれたカードを Ai 枚持っています。

2 枚のカードについて、それらに書かれた整数の差の絶対値が 1 以下のとき、これらをペアにすることができます。

高橋君は、同じカードが複数のペアに使われないように、できるだけ多くのペアを作りたいです。高橋君が作れるペアの個数の最大値を求めてください。

-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */

LL N;

LL ans = 0LL;

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

	cin >> N;
	VL a(N);

	FOR(i, 0, N) {
		cin >> a[i];
	}

	FOR(i, 0, N) {
		ans += a[i] / 2;
		a[i] = a[i] % 2;
		if (i != N - 1) {
			LL cnt = min(a[i], a[i + 1]);
			a[i] -= cnt;
			a[i + 1] -= cnt;
			ans += cnt;
		}
	}


	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 1024
package main

import (
	"fmt"
)

func sqrtInequality(a, b, c int) string {
	x := 4 * a * b
	y := c - a - b
	z := y * y

	if y < 0 {
		return "No"
	}

	if x < z {
		return "Yes"
	}
	return "No"
}

func main() {
	var a, b, c int
	fmt.Scanf("%d %d %d", &a, &b, &c)
	r := sqrtInequality(a, b, c)
	fmt.Print(r)
}


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

int main() {
    long long n, k;
    cin >> n >> k;
    long long sum = 0;
    vector<long long> a(n);
    for (int i = 0; i < n; i++)
        cin >> a[i];
    vector<long long> dp(n, INT64_MAX);
    dp[0] = 0;
    for (int i = 1; i < n; i++)
        for (int j = 1; j <= min(i, (int)k); j++)
            dp[i] = min(dp[i - j] + abs(a[i] - a[i - j]), dp[i]);
    cout << dp[n - 1] << endl;
}

Measured memory_bytes: 1792
#include <iostream>
using namespace std;
int main()
{
  int N;
  cin >> N;
  int div = 0;
  int n = N;
  while (n > 0) {
    div += (n%10);
    n /= 10;
  }
  if ((N%div)==0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256