akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
// const ll MOD = 1000000007;
const int INF = 2000000000;

int H, W;
int g[1001][1001];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> H >> W;
  queue<pair<int, int>> q;
  fill(g[0], g[1001], INF);
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      char c;
      cin >> c;
      if (c == '#') {
        q.push(make_pair(i, j));
        g[i][j] = 0;
      }
    }
  }

  while (!q.empty()) {
    auto p = q.front();
    q.pop();
    int h = p.first, w = p.second;
    if (h - 1 >= 0 && g[h - 1][w] == INF) {
      g[h - 1][w] = g[h][w] + 1;
      q.push(make_pair(h - 1, w));
    }
    if (w - 1 >= 0 && g[h][w - 1] == INF) {
      g[h][w - 1] = g[h][w] + 1;
      q.push(make_pair(h, w - 1));
    }
    if (h + 1 < H && g[h + 1][w] == INF) {
      g[h + 1][w] = g[h][w] + 1;
      q.push(make_pair(h + 1, w));
    }
    if (w + 1 < W && g[h][w + 1] == INF) {
      g[h][w + 1] = g[h][w] + 1;
      q.push(make_pair(h, w + 1));
    }
  }

  int ans = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      ans = max(ans, g[i][j]);
    }
  }

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

Measured memory_bytes: 12432
H,W = map(int, input().split())

a = [list(input()) for _ in range(H)]

i = 0
while i < H:
    for j in range(W):
        if a[i][j] != '.':
            break
    else:
        a.pop(i)
        H -= 1
        continue
    i += 1

i = 0
while i < W:
    for j in range(H):
        if a[j][i] != '.':
            break
    else:
        for k in range(H):
            a[k].pop(i)
        W -= 1
        continue
    i += 1

for i in range(H):
    for j in range(W):
        print(a[i][j], end='')
    print()


Measured memory_bytes: 4596
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
using namespace std;
using ll = long long;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;

int main() {

    int a, b, c;
    cin >> a >> b >> c;
    
    if (a+b+c == 17) cout << "YES" << endl;
    else cout << "NO" << endl;
    
}

Measured memory_bytes: 256
import java.util.*;
import java.util.stream.Collectors;
import java.io.*;
import java.nio.charset.StandardCharsets;

public class Main {
	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		Main ins = new Main(in);
		ins.calc();
		ins.showResult();
	}

	int D;
	int[] c;
	int[][] s;
	int[] last;

	Main(BufferedReader in) throws IOException {
		D = Integer.parseInt(in.readLine());
		String[] tokens = in.readLine().split(" ");
		c = new int[tokens.length];
		for (int i = 0; i < tokens.length; ++i) {
			c[i] = Integer.parseInt(tokens[i]);
		}
		s = new int[D][c.length];
		for (int i = 0; i < D; ++i) {
			tokens = in.readLine().split(" ");
			for (int j = 0; j < tokens.length; ++j) {
				s[i][j] = Integer.parseInt(tokens[j]);
			}
		}
		last = new int[c.length];
		Arrays.fill(last, 0);
	}

	int sub(int day, int contest) {
		int result = s[day][contest];
		int minus = 0;
		for (int i = 0; i < c.length; ++i) {
			if (i != contest) {
				minus += (day - last[contest]) * c[contest];
			}
		}
		return result - minus;
	}

	int sub(int day) {
		// 最も得られる満足度が高いものを選ぶ
		int result = -1;
		int max = Integer.MIN_VALUE;
		for (int contest = 0; contest < c.length; ++contest) {
			int effort = sub(day, contest);
			if (max < effort) {
				result = contest;
				max = effort;
			}
		}

		return result;
	}

	void calc() {
		// まずは最大のSを選ぶことにする
		for (int i = 0; i < D; ++i) {
			int r = sub(i);
			if (r >= 0) {
				System.out.println((r + 1));
			} else {
				System.out.println("1");
			}
		}
	}

	void showResult() {
	}
}


Measured memory_bytes: 36208
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
//#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
//#include <unordered_map> // unordered_map
//#include <unordered_set> // unordered_set
#include <bitset> // bitset
//#include <cctype> // isupper, islower, isdigit, toupper, tolower
//It is so troublesome that I include bits/stdc++.h !
using namespace std;

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 int INF = 1001001000;
const int MOD = 1000000007;
bool E[2005][2005];
typedef pair<int,int> P;
//NのM乗を求める(繰り返し二乗法)
long long mod_pow(long long N, long long M) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % MOD, M / 2);
    //最下位ビット(*N)が1の時は単独でNをかける
    if (M & 1) res = (res * N) % MOD;

    return res %= MOD;
}
long long nCr(long long n, long long r) {
    long long A = 1, B = 1;
    //Aが分子Bが1/r!
    for (long long i = n - r + 1; i <= n; i++) {
        A = A * i % MOD;
    }
    for (long long i = 1; i <= r; i++) {
        B = B * i % MOD;
    }
    B = mod_pow(B, MOD - 2);
    B %= MOD;
    //Bは割るのではなく掛ける
    return (A * B) % MOD;
}

int main() {
  string S;cin >> S;
  long long K; cin >> K;
  int A;
  int B;
  for(int i = 0;i<S.size();i++){
      if(S.at(i) != '1') {
        A = i+1;
        B = (int)S.at(i)-'0';
        break;
      }
  }
  if(K >= A) cout << B << endl;
  else cout << 1 << endl;
  /*
  g++ abc.cpp
  ./a.out
  */
 return 0;
}

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

#define LL long long

#define lson l,mid,id<<1
#define rson mid+1,r,id<<1|1
#define ls id<<1
#define rs id<<1|1
#define MID(l,r) (((l)+(r))>>1)

const int MOD = (int) 1e9 + 7;
const double eps = (double) 1e-8;
const int maxn = (int) 2e5 + 20;

void work()
{
    LL n;
    cin >>n;

    LL ans = 0;
    for(LL i = 1; i * i <= n; i++)
    {
        if(n % i) continue;

        LL a, b;
        a = i; b = n / i;

        LL c = a - 1;
        if(c && n / c == n % c) ans += c;
        if(a != b)
        {
            c = b - 1;
            if(c && n / c == n % c) ans += c;
        }
    }

    cout <<ans <<endl;
}

int main()
{
#ifdef yukihana0416
freopen("in.txt", "r" ,stdin);
//freopen("out.txt", "w", stdout);
#endif // yukihana0416

    int tc = 1;
//    scanf("%d", &tc);
    for(int ca = 1; ca <= tc; ca++)
    {
//        printf("Case #%d: ", ca);
        work();
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
const int N=2e5+5;
const int MOD=1e9+7;
ll a[N];
int b[N];
int n,k,m;
int cmp(int a,int b)
{
    return a>b;
}

map <int,int> mp;
string s;
string t;

int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++) cin>>a[i];
    ll sum=a[1];
    ll ans=0;
    for(int i=2;i<=n;i++){
        ans=(ans+(sum*a[i])%MOD)%MOD;
        sum+=a[i];
        sum=sum%MOD;

    }
    cout<<ans<<endl;
}






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

using namespace std;

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

signed main () {
  cin.tie(0);
  cout << setprecision(10);

  int n, k; cin >> n >> k;
  vector<int> a(n);
  REP(i, n) cin >> a[i];

  int mi = INT_MAX;
  int now = 0;
  
  REP(i, n-k+1) {
    if(a[i] >= 0) {
      now = a[i+k-1];
    } else if (a[i+k-1] < 0) {
      now = abs(a[i]);
    } else {
      now = min(2*a[i+k-1] + abs(a[i]), a[i+k-1] + 2 * abs(a[i]));
    }
    mi = min(mi, now);
  }

  cout << mi << endl;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<ll,ll> P;
typedef pair<ll,pair<ll,ll>> p;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
#define bit(n,k) ((n>>k)&1) /*nのk bit目*/
static const int MAX_SIZE = 1 << 17; //segment tree のサイズ。この実装では2べきにする必要がある。 2^17 ≒ 1.3 * 10^5

int dp[110000][2];


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

  if(x%y==0) cout<<-1<<endl;
  else{
      ll i=2;
      while(true){
          if(x*i%y!=0){
              cout<<x*i<<endl;
              return 0;
          }
          i++;
      }
  }
}



Measured memory_bytes: 256
n,w=gets.split.map(&:to_i)
items=n.times.map{gets.split.map(&:to_i)}
diff=3


offset=diff*n+1
w1=items[0][0]
if w1>offset
    w=offset*(w/w1)+[w%w1,offset-1].min
    n.times{|i| items[i][0]=offset+items[i][0]%w1}
end

dp=Array.new(n+1){Array.new(w+1,0)}

items.each_with_index do |item,i|
    iw,iv=item
    (w+1).times do |j|
        dp[i+1][j]=dp[i][j] if dp[i][j]>dp[i+1][j]
        dp[i+1][j+iw]=dp[i][j]+iv if j+iw<=w && dp[i][j]+iv>dp[i+1][j+iw]
    end
end
puts dp[n].max

Measured memory_bytes: 25596
#include <iostream>
#include <string>
#include <cctype>
using namespace std;

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

int main(){
    string s;
    while(getline(cin,s)){
        rep(i,s.size()){
            s[i] = toupper(s[i]);
        }
        cout << s << endl;
    }
}

Measured memory_bytes: 1176
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<n;++i)
#define rep2(i,a,b) for (ll i=a;i<b;++i)
const ll MOD=1000000007;

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;
}

int main(){
    int N;
    cin >> N;
    vector<Pll> engine(N);
    rep(i,N){
        ll x,y;
        cin >> x >> y;
        engine[i]=Pll(x,y);
    }
    ll ans=0;
    rep(i,N){
        Pll p=engine[i];
        ll x1=p.first,y1=p.second;
        rep(j,4){
            ll x=y1,y=x1;
            x1=-x,y1=y;
            ll countx=0,county=0;
            ll cx1=0,cx2=0,cy1=0,cy2=0;
            rep(k,N){
                Pll q=engine[k];
                ll x2=q.first,y2=q.second;
                if (x1*x2+y1*y2>0){
                    countx+=x2,county+=y2;
                }
                else if (x1*x2+y1*y2==0){
                    if (x1*y2-x2*y1>0){
                        cx1+=x2,cy1+=y2;
                    }
                    else {
                        cx2+=x2,cy2+=y2;
                    }
                }
            }
            chmax(ans,countx*countx+county*county);
            countx+=cx1,county+=cy1;
            chmax(ans,countx*countx+county*county);
            countx+=cx2-cx1,county+=cy2-cy1;
            chmax(ans,countx*countx+county*county);
        }   
    }
    cout << fixed  << setprecision(10);
    cout << sqrt(ans) << endl;
}

Measured memory_bytes: 256
from bisect import bisect_left

N, M, *A = map(int, open(0).read().split())
A.sort()


def calc(t):
    cnt = 0
    for ai in A:
        cnt += N - bisect_left(A, t - ai)
    if M <= cnt:
        return True
    else:
        return False


def solve():
    left, right = 0, 2 * 10 ** 5 + 1
    while 1 < right - left:
        mid = (left + right) // 2
        if calc(mid):
            left = mid
        else:
            right = mid
    
    sum_A = [0] * N
    sum_A[-1] = A[-1]
    for i in range(N - 2, -1, -1):
        sum_A[i] = sum_A[i + 1] + A[i]
    
    ans = 0
    add_cnt = 0
    for ai in A:
        index = bisect_left(A, left - ai)
        if index == N:
            continue
        add_cnt += N - index
        ans += (N - index) * ai + sum_A[index]
    ans -= left * (add_cnt - M)
    print(ans)


if __name__ == '__main__':
    solve()


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

#define int long long

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int b0 = 0;
  int N;
  cin >> N;
  //   cout << 'a' << endl;
  vector<int> A(N);
  for ( int i = 0; i < N; i++ ) {
    cin >> A[i];
  }

  for ( int i = N-1; i >= 0; i-- ) {
    if ( (N-i)%2 ) b0 += A[i];
    else b0 -= A[i];
  }

  cout << b0 << " ";
  int now = b0 / 2;
  for ( int i = 0; i < N-1; i++ ) {
    cout << 2*(A[i]-now) << " ";
    now = A[i]-now;    
  }
  cout << endl;
  
  return 0;
}


Measured memory_bytes: 2176
using System;
using System.Linq;

class D
{
	static void Main()
	{
		Func<int[]> read = () => Console.ReadLine().Split().Select(int.Parse).ToArray();
		var h = read();
		var d = new int[h[0]].Select(_ => read()).GroupBy(a => a[0]).ToDictionary(g => g.Key, g => g.Select(a => a[1]).OrderByDescending(x => x).ToArray());
		int w = h[1], w0 = d.Keys.First();
		var v = Enumerable.Range(0, 4).Select(i => d.ContainsKey(w0 + i) ? d[w0 + i] : new int[0]).ToArray();

		var M = 0;
		for (int i0 = 0, s0 = 0, v0 = 0; s0 <= w; s0 += w0, v0 += v[0][i0++])
		{
			for (int i1 = 0, s1 = s0, v1 = v0; s1 <= w; s1 += w0 + 1, v1 += v[1][i1++])
			{
				for (int i2 = 0, s2 = s1, v2 = v1; s2 <= w; s2 += w0 + 2, v2 += v[2][i2++])
				{
					M = Math.Max(M, v2 + v[3].Take((w - s2) / (w0 + 3)).Sum());

					if (i2 == v[2].Length) break;
				}
				if (i1 == v[1].Length) break;
			}
			if (i0 == v[0].Length) break;
		}
		Console.WriteLine(M);
	}
}


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

typedef pair<int,int> pa;
bool used[100];
pa A[100],B[100];
int main(){
  int n,ans=0; cin>>n;
  for(int i=0;i<n;i++){
    cin>>A[i].first>>A[i].second;
  }
  for(int i=0;i<n;i++){
    cin>>B[i].first>>B[i].second;
  }
  sort(A,A+n);
  sort(B,B+n);
  for(int i=0;i<n;i++){
    int ymax=-999,index=-1;
    for(int j=0;j<n;j++){
      if(A[j].first<B[i].first&&A[j].second<B[i].second&&(!used[j])){
        if(ymax<A[j].second){
          ymax=A[j].second;
          index=j;
        }
      }
    }
    if(index!=-1){
      used[index]=true;
      ans++;
    }
  }
  cout<<ans<<"\n";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
const int MAXN=1e5+5;
const int MOD=1e9+7;
using namespace std;
ll a[MAXN];
ll b[MAXN];
ll father[MAXN];
ll num[MAXN];
ll tmp[MAXN];
ll n ,m;
ll Find(ll x){
    if(father[x]!=x)
        father[x]=Find(father[x]);
    return father[x];
}

int main(){
	ll sum=0;
	scanf("%d%d",&n,&m);
	for(ll i=0;i<m;++i)
		scanf("%d%d",&a[i],&b[i]);
	sum=n*(n-1)/2;
	for(ll i=1;i<=n;i++){
		father[i]=i;
		num[i]=1; 
	}
	for(ll i=m;i>=0;--i){
		tmp[i]=sum;
		ll x=Find(a[i]);
		ll y=Find(b[i]);
		if(x!=y){
			sum-=num[x]*num[y];
			if(num[x]<num[y]) 
				swap(x,y);
			num[x]+=num[y];
			father[y]=x;
		}
	}
	for(ll i=0;i<=m-1;i++)
		printf("%lld\n", tmp[i]);
	return 0;
}


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

int main() {
  int64_t n;
  cin>>n;
  vector<int64_t> h(n);
  for(int i=0;i<n;i++){
    cin>>h.at(i);
  }
  if(n==2){
    cout<<abs(h.at(1)-h.at(0))<<endl;
  }
  else{
    vector<int64_t> sa1(n-1);
    vector<int64_t> sa2(n-2);
    vector<int64_t> ans(n);
    for(int i=0;i<n-1;i++){
    sa1.at(i)=abs(h.at(i+1)-h.at(i));
  }
    for(int i=0;i<n-2;i++){
    sa2.at(i)=abs(h.at(i+2)-h.at(i));
  }
    ans.at(0)=0;
    ans.at(1)=sa1.at(0);
    for(int i=2;i<n;i++){
    ans.at(i)=min(ans.at(i-2)+sa2.at(i-2),ans.at(i-1)+sa1.at(i-1));
  }
    cout<<ans.at(n-1);
  }
}

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

using namespace std;

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

  int a, b, c, x, y;
  cin >> a >> b >> c >> x >> y;
  if (x > y) {
    swap(x, y);
    swap(a, b);
  }
  cout <<  x * min(a+b, 2*c) + (y-x) * min(b, 2*c) << endl;

  return 0;
}



Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <iostream>
#include <cstdio>
#include <memory>
#include <string>
#include <cstdlib>
#include <set>
#include <utility>
#include <vector>
#include <list>
#include <forward_list>
#include <algorithm>
#include <regex>
#include <cmath>
#include <map>
#include <iterator>
#include <climits>
#include <numeric>
#include <bitset>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <array>
#include <valarray>
#include <complex>
#include <random>
#include <functional>
#include <cassert>
#include <chrono>
#include <memory>

using namespace std;

#define int long long
//region TEMPLATE
////@formatter:off
#define double long double
typedef long long ll;
typedef unsigned long long ull;
template<typename T>void __read(T &a) { cin >> a; }
template<typename T, typename ... Args> void __read(T &a, Args &... args) { cin >> a;__read(args...);}
#define make(t, ...) t __VA_ARGS__; __read(__VA_ARGS__)
#define makev(a, n) VI a(n); FOR(n) cin >> a[i]
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define FORIT(p) for(auto it = p.begin(); it != p.end(); it++)
#define FOR(b) for(signed i = 0; i <(b); i++)
#define FORE(i, l, r) for(int i = (l); i < (r); i++)
#define NFOR(i, n) for(int i = (((int) n)-1); i >= 0; i--)
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef pair<pair<int, int>, int> PPII;
constexpr ll M7 = 1000000007ll;
constexpr ll M9 = 1000000009ll;
constexpr ll MFFT = 998244353ll;
template<class T> void outv(T &a) { for (auto &x : a) cout << x << ' '; }
static mt19937 rnd(static_cast<unsigned>(chrono::steady_clock::now().time_since_epoch().count())); // NOLINT(cert-err58-cpp)
auto __fast_io__ = (ios_base::sync_with_stdio(false), cin.tie(nullptr)); // NOLINT(cert-err58-cpp,cppcoreguidelines-interfaces-global-init)
////@formatter:on
//endregion



int32_t main() {
    make(char, c);
    if (c >= 'a' && c <= 'z'){
        cout << 'a';
    } else {
        cout << 'A';
    }

    return 0;
}

Measured memory_bytes: 3636
#include <iostream>

using namespace std;

string op = "+-";

int main() {
  string S;
  cin >> S;
  int A[4];
  for (int i = 0; i != 4; ++i) A[i] = S[i] - '0';
  for (int i = 0, n = 1 << 3; i != n; ++i) {
    if (A[0] + (1 - 2 * ((i >> 0) & 1)) * A[1] +
        (1 - 2 * ((i >> 1) & 1)) * A[2] + (1 - 2 * ((i >> 2) & 1)) * A[3] == 7) {
      cout << A[0] << op[(i >> 0) & 1] << A[1] << op[(i >> 1) & 1] << A[2]
           << op[(i >> 2) & 1] << A[3] << "=7" << endl;
      break;
    }
  }
}


Measured memory_bytes: 3608
n,m = map(int,input().split())
ls = []
for i in range(m):
    ls.append( list(map(int,input().split())) )
w = ["d"]*n
flag = False
for s,c in ls:
    if w[s-1] == "d":
        w[s-1] = str(c)
    elif w[s-1] != str(c) :
        flag = True
        break

for i in range(1,n):
    if w[i] == "d" :
        w[i] = "0"
if w[0] == "0":
    if n > 1:
        flag =True
elif w[0] == "d":
    if n > 1:
        w[0] = "1"
    else:
        w[0] = "0"


########
if flag:
    print(-1)
else :
    print("".join(w))


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

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;}

int dp[100];

//最大公約数
int gcd(int x, int y){
  if(x % y == 0) return y;
  return gcd(y, x % y);
}
//最小公倍数
int lcm(int x, int y){
  return x * y / gcd(x, y);
}
//フィボナッチ数列
//配列dpを-1で初期化する
int fib(int n){
  if(n == 0 || n == 1) return dp[n] = 1;
  if(dp[n] != -1) return dp[n];
  return dp[n] = fib(n - 1) + fib(n - 2);
}
//階乗計算(factorial)
int fact(int n){
  if(n = 1) return 1;
  return n * fact(n - 1);
}
//累乗計算(Exponentiation)
//x**y
ll expo(int x, int y){
  ll ans = 1;
  rep(i, y){
    ans *= x;
  }
  return ans;
}
//桁数
int keta(ll x){
  if(x == 0) return 1;
  int res = 0;
  while(x){
    x /= 10;
    res++;
  }
  return res;
}


int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  sort(a.begin(), a.end());
  ll sum = 0;
  int mx = a[n-1];
  int mn = a[0];
  rep(i, n){
    sum += a[i];
  }
  cout << mn << " " << mx << " " << sum << endl;
}






Measured memory_bytes: 3160
#include <iostream>
using namespace std;
int main(){
	string  a,b,c;
	cin >> a;
	string zz[7] = {"SUN","MON" ,"TUE","WED","THU","FRI","SAT"};
	for(int i =0;i <= 6;i++)
	{
		if(zz[i] == a)
		{
			cout << 7 - i << endl;
		}
	}
}

Measured memory_bytes: 256
# include <cstdio>

# define REP(i, n) for (int i = 1; i <= n; ++ i)
# define REP_D(i, n) for (int i = n; i >= 1; -- i)

# define NR 201000

const int M = 2002, M2 = 4010, M4 = 8050;
const int mod = 1000000007;

int n, x[NR], y[NR];
int a[M2 + 10][M2 + 10];
int fac[M4 + 10], fac_inv[M4 + 10];

int pr (int a, int z) { int s = 1; do { if (z & 1) s = 1ll * s * a % mod; a = 1ll * a * a % mod; } while (z >>= 1); return s; }
int binom (int n, int k) { return n < k ? 0 : 1ll * fac[n] * fac_inv[k] % mod * fac_inv[n - k] % mod; }

void inc (int &x, int y) { x = (x + y) % mod; }
void dec (int &x, int y) { x = (x + mod - y) % mod; }

int main () {
	scanf ("%d", &n);
	fac[0] = fac_inv[0] = 1;
	REP (i, M4) fac[i] = 1ll * fac[i - 1] * i % mod;
	fac_inv[M4] = pr (fac[M4], mod - 2);
	REP_D (i, M4 - 1) fac_inv[i] = 1ll * fac_inv[i + 1] * (i + 1) % mod;
	
	REP (i, n) scanf ("%d%d", &x[i], &y[i]), ++ a[M - x[i]][M - y[i]];
	REP (i, M2) REP (j, M2) inc (a[i][j], a[i][j - 1] + a[i - 1][j]);
	int ans = 0;
	REP (i, n) inc (ans, a[M + x[i]][M + y[i]]);
	//printf ("!%d\n", ans);
	REP (i, n) dec (ans, binom (2 * x[i] + 2 * y[i], 2 * x[i]));//, printf ("!%d %d\n", i, binom (2 * x[i] + 2 * y[i], 2 * x[i]));
	//printf ("!%d\n", ans);
	printf ("%lld\n", 1ll * ans * ((mod + 1) / 2) % mod);
	return 0;
}


Measured memory_bytes: 64896
#include<iostream>
#include<cmath>
#include<string>
#include<fstream>
#include<vector>
#include<algorithm>
using namespace std;

int main()
{
    int n;
    cin>>n;
    int a[n];
    int sum = 0;
    for(int i=0; i<n; i++)
    {
        cin>>a[i];
        sum += a[i];
    }
    cout<< sum - n<<endl;
	return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static int INF = 1 << 30;
	static long LINF = 1L << 55;
	static int MOD = 1000000007;
	static int[] mh4 = { 0, -1, 1, 0 };
	static int[] mw4 = { -1, 0, 0, 1 };
	static int[] mh8 = { -1, -1, -1, 0, 0, 1, 1, 1 };
	static int[] mw8 = { -1, 0, 1, -1, 1, -1, 0, 1 };

	static class TaskX {

		public void solve(int testNumber, InputReader in, PrintWriter out) {

			int x = in.nextInt();
			if (x == 3 || x == 5 || x == 7) {
				out.println("YES");
			} else {
				out.println("NO");
			}

		}
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

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

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

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

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

		public int[] nextIntArrayDec(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt() - 1;
			}
			return res;
		}

		public int[] nextIntArray1Index(int n) {
			int[] res = new int[n + 1];
			for (int i = 0; i < n; i++) {
				res[i + 1] = nextInt();
			}
			return res;
		}

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

		public long[] nextLongArrayDec(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong() - 1;
			}
			return res;
		}

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

		public double[] nextDoubleArray(int n) {
			double[] res = new double[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextDouble();
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}
	}

}


Measured memory_bytes: 20820
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
#include <deque>
#include <climits> 

int main()
{
    long N,K;
    std::cin >> N >> K;
    double result=0;
    if(K<=N){
        result=(double)(N-K+1)/(double)N;
        for(long i=1; i<K; i++){
            long necessary=std::ceil(std::log((double)K/(double)i)/std::log(2));
            result+=((double)1/(double)N)*std::pow(0.5,necessary);
        }
    }else{
        for(long i=1; i<=N; i++){
            long necessary=std::ceil(std::log((double)K/(double)i)/std::log(2));
            result+=((double)1/(double)N)*std::pow(0.5,necessary);
        }
    }
    std::cout << std::setprecision(15) << result << std::endl;
    return 0;
}

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

int main(void){
  	
	int n;
  	cin>>n;
  	long long int l[n];
  	for(int i=0;i<n;i++){
    	cin>>l[i];
    }
  	
  	long long int cnt=0;
  	
  	for(int i=0;i<n;i++){
    	for(int j=i;j<n;j++){
        	for(int k=j;k<n;k++){
            	if(i<j && j<k){
                  	if(l[i]!=l[j] && l[j]!=l[k] && l[k]!=l[i])
                	if(l[i]+l[j]>l[k]){
                    	if(l[j]+l[k]>l[i]){
                        	if(l[i]+l[k]>l[j]){
                            	cnt++;
                            }
                        }
                    }
                }
            }
        }
    }
  
  	cout<<cnt;
  	
  
}

Measured memory_bytes: 3636
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;

long long n, k;

int main(){
  ios_base::sync_with_stdio(false);

  cin >> n >> k;

  long long ans = n / k;
  long long aans = 0;

  if(k%2 == 0){
    aans = n / (k/2) - ans;
  }
  
  cout << ans*ans*ans + aans*aans*aans << endl;

  return 0;
}



Measured memory_bytes: 256
# C - Count Order

N = int(input())
P = list(int(p) for p in input().split())
Q = list(int(q) for q in input().split())

def dfs(X):
    global cnt
    global idxp
    global idxq
    if len(X)==N:
        if X==P:
            idxp = cnt
        if X==Q:
            idxq = cnt
        cnt += 1
        return
    for i in range(1, N+1):
        if i not in X:
            X.append(i)
            dfs(X)
            X.pop()

X = []
cnt = 0
idxp = 0
idxq = 0
dfs(X)

print(abs(idxp-idxq))

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

int main() {
double W,H,x,y;
  cin >> W>>H>>x>>y;
  double A=W*H/(double)2;
  if(W/2==x&&H/2==y){
    cout<<A<<" "<<1<<endl;
  }else{cout<<A<<" " <<0<<endl;}
  
  
  
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

		int i = 0;


		while(true){
			i++;
			int x =sc.nextInt();
			if ( x == 0) break;

			System.out.println("Case "+ i + ": "+  x);

		}


}
}




Measured memory_bytes: 44912
from sys import stdin


def main():
    c = [[int(x) for x in stdin.readline().rstrip().split()] for _ in range(3)]
    for x, y in [(0, 1), (1, 2), (2, 0)]:
        if not (c[0][x] - c[0][y] == c[1][x] - c[1][y] == c[2][x] - c[2][y]):
            print('No')
            break
        if not (c[x][0] - c[y][0] == c[x][1] - c[y][1] == c[x][2] - c[y][2]):
            print('No')
            break
    else:
        print('Yes')


if __name__ == '__main__':
    main()


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


int main (){
    int N;
    cin>>N;
    int Keta=0;
    int NN=N;
    while(N>0){
        Keta+=N%10;
        N-=N%10;
        N/=10;
    }
    if(NN%Keta==0){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
}

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

int main()
{
	stack <int> st;
	char cha; int ans = 0;
	while(cin >> cha) {
		ans ++;
		if(cha == 'S') {
			st.push(1);
		} else if(!st.empty()) {
			st.pop();
			ans -= 2;
		}
	} cout << ans << endl;
}

Measured memory_bytes: 640
import java.util.*;
class Main{
  public static void main(String[] args){
    Scanner scan=new Scanner(System.in);
    String S=scan.nextLine();
    switch(S){
      case "Sunny":
      	System.out.println("Cloudy");
      	break;

      case "Rainy":
      	System.out.println("Sunny");
        break;
      
      case "Cloudy":
        System.out.println("Rainy");
        break;

    }
  }
}

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

public class Main {

    private static FastReader in = new FastReader(System.in);
    private static PrintWriter out = new PrintWriter(System.out);

    private static final long MOD = (long) 1e9 + 7;

    public static void main(String[] args) {
        solve();
        out.flush();
    }

    private static void solve() {
        int n = in.nextInt();
        char[] s = in.next().toCharArray();
        char[] t = in.next().toCharArray();

        String ans = "";
        for (int i = 0; i < s.length; i++) {
            ans += String.valueOf(s[i]) + String.valueOf(t[i]);
        }
        out.println(ans);
    }

    // https://www.geeksforgeeks.org/fast-io-in-java-in-competitive-programming/
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader(InputStream inputStream) {
            br = new BufferedReader(new
                    InputStreamReader(inputStream));
        }

        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;
        }

        // https://qiita.com/masakinpo/items/5f77f2a879578a85a0bb
        public int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

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


Measured memory_bytes: 20820
import java.util.Scanner;

public class Main {
	static int n;
	static int s[][][];
	static int s2[][][];
	static int m1, m2;
	static int a[], b[];

	public static boolean isBorn(int x, int y, int z) {
		int sum = 0;
		for (int i = -1; i <= 1; i++) {
			for (int j = -1; j <= 1; j++) {
				for (int k = -1; k <= 1; k++) {
					if (0 <= z + i && z + i < 5 && 0 <= y + j && y + j < 5 && 0 <= x + k && x + k < 5) {
						sum += s[z + i][y + j][x + k];
					}
				}
			}
		}
		for (int i = 0; i < m1; i++) {
			if (sum == a[i]) {
				return true;
			}
		}
		return false;
	}

	public static boolean isDeath(int x, int y, int z) {
		int sum = -1;
		for (int i = -1; i <= 1; i++) {
			for (int j = -1; j <= 1; j++) {
				for (int k = -1; k <= 1; k++) {
					if (0 <= z + i && z + i < 5 && 0 <= y + j && y + j < 5 && 0 <= x + k && x + k < 5) {
						sum += s[z + i][y + j][x + k];
					}
				}
			}
		}
		for (int i = 0; i < m2; i++) {
			if (sum == b[i]) {
				return false;
			}
		}
		return true;
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int cases = 1;
		String sss = "";

		while (true) {
			n = sc.nextInt();
			if (n == 0) {
				break;
			}
			s = new int[5][5][5];
			s2 = new int[5][5][5];
			for (int i = 0; i < 5; i++) {
				for (int j = 0; j < 5; j++) {
					String str = sc.next();
					for (int k = 0; k < 5; k++) {
						s[i][j][k] = str.charAt(k) - '0';
					}
				}
			}
			m1 = sc.nextInt();
			a = new int[m1];
			for (int i = 0; i < m1; i++) {
				a[i] = sc.nextInt();
			}
			m2 = sc.nextInt();
			b = new int[m2];
			for (int i = 0; i < m2; i++) {
				b[i] = sc.nextInt();
			}

			while (n-- != 0) {
				for (int i = 0; i < 5; i++) {
					for (int j = 0; j < 5; j++) {
						for (int k = 0; k < 5; k++) {
							if (s[i][j][k] == 0) {
								if (isBorn(k, j, i)) {
									s2[i][j][k] = 1;
								} else {
									s2[i][j][k] = 0;
								}
							} else if (s[i][j][k] == 1) {
								if (isDeath(k, j, i)) {
									s2[i][j][k] = 0;
								} else {
									s2[i][j][k] = 1;
								}
							}
						}
					}
				}
				for (int i = 0; i < 5; i++) {
					for (int j = 0; j < 5; j++) {
						for (int k = 0; k < 5; k++) {
							s[i][j][k] = s2[i][j][k];
						}
					}
				}
			}

			System.out.print(sss);
			sss = "\n";
			System.out.println("Case " + cases + ":");
			for (int i = 0; i < 5; i++) {
				for (int j = 0; j < 5; j++) {
					for (int k = 0; k < 5; k++) {
						System.out.print(s[i][j][k]);
					}
					System.out.println();
				}
				if (i != 4) {
					System.out.println();
				}
			}
			cases++;
		}
	}
}

Measured memory_bytes: 28348
#include <bits/stdc++.h> 
using namespace std;
using ll = long long;
template<typename T> using v2 = vector<vector<T>>;
template<typename T> inline v2<T> fill(int r, int c, const T& t){ return v2<T>(r, vector<T>(c, t)); }
#define F first
#define S second

int n, m;
v2<int> adj;
vector<bool> v;

int dfs(int node){
    v[node] = true;
    int ans = 1;
    for(int next : adj[node]){
        if(!v[next]){
            ans += dfs(next);
        }
    }
    return ans;
}

void solve(){
    cin >> n>>m;
    adj = v2<int>(n);

    set<pair<int, int>> seen;
    for(int i = 0; i < m; ++i){
        int a, b;
        cin >>a>>b;
        --a, --b;

        if(!seen.count({a, b})){
            adj[a].push_back(b);
            adj[b].push_back(a);

            seen.insert({a, b});
            seen.insert({b, a});
        }
    }

    // for(int i = 0; i < n; ++i){
    //     cout << i+1 << ": ";
    //     for(int j : adj[i]) cout << j+1 << " ";
    //     cout << '\n';
    // }

    int ans = 0;
    v = vector<bool>(n, false);
    for(int i = 0; i < n; ++i){
        if(!v[i]){
            int sz = dfs(i);
            // cout<<i<<", "<<sz<<'\n';
            ans = max(ans, sz);
        }
    }

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

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;
}

Measured memory_bytes: 42208
<?php
fscanf(STDIN, '%s %s', $S, $T);
fscanf(STDIN, '%d %d', $A, $B);
fscanf(STDIN, '%s', $U);
if ($U == $S) {
    $A--;
} else {
    $B--;
}
echo $A . ' ' . $B . PHP_EOL;

Measured memory_bytes: 4728
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n int
	fmt.Scan(&n)

	a := make([]int, n)
	for i := range a {
		fmt.Scan(&a[i])
	}

	sort.Ints(a)

	paper := make([]int, 0)
	i := 0
	for i < len(a) {
		if i == len(a)-1 {
			paper = append(paper, a[i])
		} else {
			if a[i] == a[i+1] {
				i++
			} else {
				paper = append(paper, a[i])
			}
		}
		i++
	}

	fmt.Println(len(paper))
}


Measured memory_bytes: 7424
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = Integer.parseInt(sc.next());
        int B = Integer.parseInt(sc.next());
        int C = Integer.parseInt(sc.next());
        int X = Integer.parseInt(sc.next());

        int res = 0;
        for (int a=0; a<=A; a++) {
            for (int b=0; b<=B; b++) {
                int c = (X - a * 500 - b * 100) / 50;
                if (c >= 0 && c <= C)
                    res++;
            }
        }
        System.out.println(res);
    }
}

Measured memory_bytes: 21716
#include <iostream>
#include <vector>
#include <utility>
#include <list>
#include <algorithm>

typedef long long ll;

using namespace std;

struct B {
    int old;
    int num;
    int nw=0;
};

int main() {
    
    int N;
    cin>>N;
    vector<B> vb(N);
    list<B> ls;
    int numb=N;
    for(int i=0;i<N;++i){
        cin>>vb[i].num;
        vb[i].old=numb;
        --numb;
    }
    
    
    
    int count=1;
    
    
    
    for(int i=1;i<=N;++i){
        
        for(int j=N-1;j>=0;--j){
            if(vb[j].num>i)continue;
            //cout<<"judge1"<<endl;
            if(vb[j].nw!=0)continue;
            //cout<<"judge2"<<endl;
            bool flag=true;
            for(list<B>::iterator itr=ls.begin();itr!=next(ls.begin(),vb[j].num-1);++itr){
                if(itr->old<vb[j].old){
                    flag=false;
                    break;
                }
            }
            if(flag){
                vb[j].nw=count;
                ls.insert(next(ls.begin(),vb[j].num-1),vb[j]);
                
                ++count;
                
               // cout<<vb[j].num<<endl;
                break;
            }
            
            //cout<<"--------->>>"<<endl;
            /*
            for(list<B>::iterator itr=ls.begin();itr!=ls.end();++itr){
                cout<<itr->num<<" ";
                
            }
            cout<<endl;
            */
            
            
        }
    }
   // cout<<"============="<<endl;
    /*
    for(int i=0;i<N;++i){
        cout<<vb[i].old<<" ";
        cout<<vb[i].num<<" ";
        cout<<vb[i].nw<<" ";
        
    }
    cout<<endl;
    
    cout<<"============="<<endl;
    */
    sort(vb.begin(),vb.end(),[](B a,B b){return  a.nw<b.nw;});
    
    /*
    cout<<"============="<<endl;
    
    for(int i=0;i<N;++i){
        cout<<vb[i].old<<" ";
        cout<<vb[i].num<<" ";
        cout<<vb[i].nw<<" ";
        
    }
    cout<<endl;
    
    cout<<"============="<<endl;
     
     */
     
    if(vb[0].nw==0){
        cout<<-1<<endl;
    }else{
        for(int i=0;i<N;++i){
            cout<<vb[i].num<<endl;
        }
    }
    
    
}



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

using namespace std;

#define DEBUG(x) cout << '>' << #x << ':' << x << endl;

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


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

    int n, k;
    cin>>n>>k;

    vector<int> vec(n, 0);

    for(auto &x: vec){
        cin>>x;
    }

    vector<int> cost(n, 1000000010);
    cost[0] = 0;
    // DEBUG(cost[0]);
    rep(i, 1, n){
        int j = 1;
        while(i-j>=0 and j<=k)
        {
            cost[i] = min(cost[i-j]+ abs(vec[i] - vec[i-j]), cost[i]);
            j++;
        }
        // DEBUG(i);
        // DEBUG(cost[i]);
    }

    cout<<cost[n-1]<<endl;



    return 0 ;
}



Measured memory_bytes: 3952
import sys

sys.setrecursionlimit(2000)
import numpy as np

def solve(h):
  if len(h) < 1:
    return 0
  mizuyari = min(h)
  h -= mizuyari
  zero_index = np.array(np.where(h == 0)).flatten()
  starts = np.insert(zero_index+1,0, 0)
  ends = np.insert(zero_index,len(zero_index),len(h))
  for s, e in zip(starts,ends):
    mizuyari += solve(h[s:e])
  return mizuyari

N = int(raw_input())
H = np.array(map(int, raw_input().split()),dtype=np.int)
print solve(H)



Measured memory_bytes: 17288
#include <stdio.h>
#include <iostream>
#include <vector>
#define LIMIT 1000000

int main(){
	int num;
	while( scanf("%d",&num)!=EOF ){
		bool sosu[LIMIT]={0};
		int now=2,count=0;
		while(now<=num){
			if(!sosu[now]){
				count++;
				for(int i=now;i<LIMIT;i+=now){
					sosu[i] = true;
				}
			}
			now++;
		}
		std::cout << count << std::endl;
	}
	return 0;
}

Measured memory_bytes: 2188
/* A Naive recursive implementation of 0-1 Knapsack problem */
#include<stdio.h>
#include <bits/stdc++.h>

using namespace std;
map<pair<long long,long long>,long long> mymap;
// A utility function that returns maximum of two integers
int max(long long  a, long long b) { return (a > b)? a : b; }

// Returns the maximum value that can be put in a knapsack of capacity W
int knapSack(long long W, long long wt[], long long  val[], long long n)
{
// Base Case
if (n == 0 || W == 0)
	return 0;

// If weight of the nth item is more than Knapsack capacity W, then
// this item cannot be included in the optimal solution
if (wt[n-1] > W)
	return knapSack(W, wt, val, n-1);

// Return the maximum of two cases: 
// (1) nth item included 
// (2) not included

else{
    if(mymap.find(pair<long,long>(W,n-1))==mymap.end())
    {
        mymap[pair<long,long>(W,n-1)]=max( val[n-1] + knapSack(W-wt[n-1], wt, val, n-1),
					knapSack(W, wt, val, n-1)
				);
    }
    return  mymap[pair<long,long>(W,n-1)];
} 
}

// Driver program to test above function
int main()
{
/*	long long val[] = {60, 100, 120};
	long long wt[] = {10, 20, 30};
	long long W = 50;
	long long n = sizeof(val)/sizeof(val[0]);
//	printf("%d", knapSack(W, wt, val, n));*/

	int n,w;
	cin>>n>>w;
	long long val[n];
	long long wt[n];
	for(int i=0;i<n;i++)
	{
	    cin>>wt[i]>>val[i];
	}
	cout<<knapSack(w, wt, val, n);
	return 0;
}


Measured memory_bytes: 6016
#include<bits/stdc++.h>
using namespace std;
char n;
int a,b;
int main()
{
    cin>>a>>b;
    for(int s=0;s<a;s++)
    {
        cin>>n;
        if(n<'0'||n>'9')
        {
            cout<<"No"<<endl;
            return 0;
        }
    }
    cin>>n;
    if(n!='-')
    {
        cout<<"No"<<endl;
        return 0;

    }
    for(int s=0;s<b;s++)
    {
        cin>>n;
        if(n<'0'||n>'9')
        {
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl; 
    return 0;
}

Measured memory_bytes: 256
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}
double calcTime()
{
    struct::timespec getTime;
    clock_gettime(CLOCK_MONOTONIC, &getTime);
    return (getTime.tv_sec + getTime.tv_nsec*1e-9);
}

mt19937 mrand(random_device{}());

ll v[400];
ll days[30] = {};
ll c[30];
ll s[370][30];
ll ans[400] = {};
ll D;

ll get_score(){
    ll score = 0;
    rep(i,0,26) days[i] = 0;

    rep(i,0,D){
        score += s[i][ans[i]];
        days[ans[i]] = i+1;
        rep(j,0,26){
            score -= c[j] * (i+1 - days[j]); 
        }
    }
    return score;
}

void solve(){
    // print(365);
    // rep(i,0,26){
    //     cout << mrand() % 100 << " ";
    // }
    // cout << endl;
    // rep(i,0,365){
    //     rep(j,0,26){
    //         cout << mrand() % 20000 << " ";
    //     }
    //     cout << endl;
    // }
    // return;
    double start = calcTime();
    cin >> D;
    rep(i,0,26) cin >> c[i];

    rep(i,0,D){
        rep(j,0,26){
            cin >> s[i][j];
        }
    }

    rep(i,0,D){
        ll r = mrand() % 26;
        ans[i] = r;
        days[r] = i+1;
    }
    ll score = get_score();
    ll iter = 0;


    while(true){
        double x = calcTime() - start;
        if(x >= 1.9) break;
        ll temp = (ll)(10 * (x - 1.9) * (x - 1.9));
        iter++;
        ll d = mrand() % D;
        ll q = mrand() % 26;
        ll prev_val = ans[d];
        ans[d] = q;
        ll new_score = get_score();
        if(new_score > score){
            score = new_score;
            // print(x);
        }else{
            ll r = mrand() % 10000;
            if(r <= temp){
                score = new_score;
            }else{
                ans[d] = prev_val;
            }
        }
    }
    // print(score);
    rep(i,0,D) print(ans[i]+1);

}

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

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



int main() {
    int N,S;
    cin>>N>>S;
    vector<int> A(N);
    rep(i,N){cin>>A.at(i);}
    vector<vector<ll>> dp(N+1,vector<ll>(S+1));
    dp.at(0).at(0)=1;
    rep(i,N){
        dp.at(i+1).at(0)++;
        
        rep(j,S+1){
            dp.at(i+1).at(j)+=dp.at(i).at(j);
            dp.at(i+1).at(j)%=MOD2;
            if(j+A.at(i)<=S){
                dp.at(i+1).at(j+A.at(i))+=dp.at(i).at(j);
                dp.at(i+1).at(j+A.at(i))%=MOD2;
            }
        }
    }
    
    ll ans=0;
    rep(i,N+1){
        ans+=dp.at(i).at(S);
        ans%=MOD2;
    }
    cout<<ans<<endl;
}

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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<complex>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD =  (int)1e9 + 7;
const double EPS = 1e-9;

int N, M;
vector<int> G[100010];
int H[100010];
bool used[100010];

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

	cin >> N >> M;
	rep(i, 0, N)cin >> H[i];

	int a, b;
	rep(i, 0, M)
	{
		cin >> a >> b;
		a--, b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}

	int ans = 0;
	rep(i, 0, N)
	{
		vector<int> res;
		res.push_back(H[i]);
		for (auto e : G[i])
		{
			res.push_back(H[e]);
		}
		sort(all(res), greater<int>());
		if (SZ(res) == 1 || res[0] != res[1]&&res[0]==H[i])ans++;
	}

	cout << ans << endl;

	return 0;
}

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

#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define spa << " " <<
ll MOD = 1e9+7;
void chmin(long long &a, long long b) { if (a > b) a = b; }

int main(){
  ll i, j;
  ll n;
  cin >> n;
  vector<ll> a(n);
  ll result;
  for(i = 0; i < n; i++)
    cin >> a[i];
  sort(ALL(a));
  for(i = 0; i < n - 1; i++)
    result += a[i];
  result += a[i] / 2;
  cout << result << endl;

  return 0;
}

Measured memory_bytes: 256