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

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

        int n = sc.nextInt();
        int[] arr = new int[n];

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

        int max = Integer.MIN_VALUE;
        int min = Integer.MAX_VALUE;

        int max_index = 0;
        int min_index = 0;

        StringBuilder str = new StringBuilder();

        for(int i = 0; i < n; i++) {
            if (max < arr[i]) {
                max = arr[i];
                max_index = i;

            }
            if (min > arr[i]) {
                min = arr[i];
                min_index = i;
            }
        }
        if (max_index == min_index) {
            min_index = 0;
            max_index = n-1;
        }

        for(int i = 0; i < n; i++) {
            if( i != min_index && i != max_index) {
                if(arr[i] < 0) {
                    str.append(max + " " + arr[i]);
                    max = max - arr[i];

                    str.append("\n");
                }
                else{
                    str.append(min + " " + arr[i]);
                    min = min - arr[i];

                    str.append("\n");
                }
            }
        }
        System.out.println(max - min);
        str.append(max + " " + min);
        System.out.println(str.toString());
    }
}


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

if a + b + c == 17:
    if (a == 5 and b == 5) or (b == 5 and c == 5) or (c == 5 and a == 5):
        ans = "YES"
    else:
        ans = "NO"
else:
    ans = "NO"

print(ans)


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,c=0;
	int a[3010],v[3010]={},x,y;
	vector<int> g[3010];
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	for(int i=1;i<n;i++){
		scanf("%d%d",&x,&y);
		g[x].push_back(y);
		g[y].push_back(x);
	}
	while(c<n){
		for(int i=1;i<=n;i++){
			if(v[i]) continue;
			bool flag=true;
			for(int j=0;j<g[i].size();j++){
				int to=g[i][j];
				if(v[to]!=1&&a[to]<a[i]){
					flag=false;
					break;
				}
			}
			if(flag) v[i]=-1,c++;
		}
		for(int i=1;i<=n;i++){
			if(v[i]) continue;
			for(int j=0;j<g[i].size();j++){
				int to=g[i][j];
				if(v[to]==-1&&a[to]<a[i]){
					v[i]=1;
					c++;
					break;
				}
			}
		}
	}
	bool fst=true;
	for(int i=1;i<=n;i++){
		if(v[i]>0){
			if(fst) fst=false;
			else putchar(' ');
			printf("%d",i);
		}
	}
	puts("");
	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
char s[100005];
stack<int> stk;
int main(){
	scanf("%s",s);
	
	int len = strlen(s), res = 0;
	for(int i = 0 ; i < len ; i++){
		if(!stk.empty() && stk.top() + s[i] == '1'){
			stk.pop();
			res++;
		}
		else
			stk.push(s[i] - '0');			
	}
	printf("%d\n", res * 2);
	
	return 0;
}

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

int main(){

    char s[3]; cin>>s;

    int a=0,b=0,c=0;

    for(int i=0; i<3; i++){
        if(s[i] == 'a') a++;

        else if(s[i] == 'b')b++;

        else c++;
    }

    if(a==b && b==c) cout<<"Yes"<<endl;

    else cout<<"No"<<endl;

    return 0;
}

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

// See:
//   https://kira924age.github.io/Algorithm/data_structure/union_find.html
class UnionFindTree
{
  vector<int> par, sizes;

public:
  UnionFindTree(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); }
  int size(int x){ return sizes[find(x)]; }
};


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

  // store bridges in reverse-order..
  vector<pair<int, int>> v;
  for (int i = 0; i < m; i++){
    int a, b;
    cin >> a >> b;
    v.push_back(make_pair(a-1, b-1)); // caution!! : not (a, b)
  }


  vector<long long> ans;
  long long curr_index = (long long) n * (n - 1) / 2;
  ans.push_back(curr_index);

  UnionFindTree t(n);

  for (int i = m - 1; i > 0; i--){
    int a = v[i].first;
    int b = v[i].second;
    if (!t.same(a, b)){
      curr_index -= (long long) t.size(a) * t.size(b);
      t.unite(a, b);
    }
    ans.push_back(curr_index);
  }

  for (int i = m - 1; i >= 0; i--){
    cout << ans[i] << endl;
  }
}


Measured memory_bytes: 3828
from collections import Counter, deque, OrderedDict
# from copy import copy, deepcopy
# from functools import reduce
# from heapq import heapify, heappop, heappush
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np  # Pythonのみ！
# from operator import xor
# import re
# from scipy.sparse.csgraph import connected_components  # Pythonのみ！
# ↑cf.  https://note.nkmk.me/python-scipy-connected-components/
# from scipy.sparse import csr_matrix
# import statistics # Pythonのみ
# import string
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()


def resolve():
    N = int(input())
    A = list(map(int, input().split()))
    A = Counter(A)

    ans=[0,0]
    for k,v in A.items():
        if v>=2:
            ans.append(k)
        if v>=4:
            ans.append(k)
    ans.sort()
    print(ans[-1]*ans[-2])


resolve()

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

using namespace std;

#define INF 1000000007
#define LINF (1LL << 60)
#define PI 3.14159265358979

typedef long long i64;
typedef pair<i64,i64> P;

inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; }

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



int n, k, a[101010];
void solve(){
	cin >> n >> k;
	int cnt = 0;
	for(int i = 0; i < n; i++){
		cin >> a[i];
		if(a[i] == 0) k--;
		if(a[i] < 0) cnt++;
	}
	
	int ans = INF;
	if(cnt >= k) chmin(ans, abs(a[cnt-k]));
	if(n-cnt >= k) chmin(ans, a[cnt+k-1]);
	for(int i = 1; i < k; i++){
		if(cnt < k-i) continue;
      	if(cnt+i-1 >= n) continue;
		chmin(ans, max(a[cnt+i-1],abs(a[cnt-k+i]))+2*min(a[cnt+i-1],abs(a[cnt-k+i])));
		//cout << ans << " " << a[cnt+i-1] << " " << a[cnt-k+i] <<  endl;
		//cout << a[cnt+i-1]+abs(a[cnt-k+i])+2*min(a[cnt+i-1],abs(a[cnt-k+i])) << endl;
	}
	cout << ans << endl;
}

int main(){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
	
	return 0;
}


Measured memory_bytes: 640
#include <stdio.h>

int search(int a[], int key, int n) {
  int start, fin, current;
  fin = n;
  start = 0;

  while (fin > start) {
    current = (fin + start) / 2;
    if (a[current] == key) {
      return 1;
    } else if (a[current] < key) {
      start = current + 1;
    } else {
      fin = current;
    }
  }

  return 0;
}


int main() {
  int key;
  int n, q;
  int sum = 0;
  int i;
  scanf("%d", &n);
  int s[n];
  for (i = 0; i < n; i++)
    scanf("%d", &s[i]);
  scanf("%d", &q);
  for (i = 0; i < q; i++) {
    scanf("%d", &key);
    if (search(s, key, n))  ++sum;
  }

  printf("%d\n", sum);

  return 0;
}



Measured memory_bytes: 2088
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
const ll MOD = 1e9+7;
const ll inf = (LLONG_MAX>>2);
int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  //cout << fixed;
  //cout.precision(40);
  ll n;
  cin >> n;
  vector<ll> a(n);
  for(ll i = 0; i < n; ++i) cin >> a[i];
  ll tot = 0,crt = 0,ans = INT_MAX;
  for(ll i = 0; i < n; ++i) tot += a[i];
  for(ll i = 0; i < n; ++i){
    crt += a[i];
    if(2*crt < tot){
      ans = min(ans,tot-2*crt);
    }
    else{
      ans = min(ans,2*crt-tot);
    }
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 1792
n, k = map(int, input().strip().split())
total = 0
for i in range(1, min(n+1, k)):
	j = i
	x = 0
	while True:
		j *= 2
		x += 1
		if j >= k:
			break
	total += (1/n)*((1/2)**x)

for i in range(k, n+1):
	total += (1/n)

# print("{0:.11f}".format(total))
print(total)

Measured memory_bytes: 3060
//teja349
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip> 
//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val

using namespace std;
#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >

//std::ios::sync_with_stdio(false);   
ll s;

ll power(ll a){
	ll ans=1,val=10;
	while(a>0){
		if(a%2)
			ans*=val;
		ans%=mod;
		val*=val;
		val%=mod;
		a/=2;
	}
	return ans;
}
int dig[31234567];
int main(){
    std::ios::sync_with_stdio(false);
    ll i;
    ll val=0;
    ll haha=1;
    cin>>s;
    ll ans=0;
    f(i,1,3100*10000){
    	if(haha==i){
    		haha*=10;
    		val++;
    	}
    	dig[i]=val;
    }
    //return 0;
    ll j=1,lol=0;
    f(i,1,10000000){
    	//cout<<i<<endl;
    	while(ans<s){
    		ans+=dig[j];
    		j++;
    	}
    	if(ans==s){
    		lol++;
    	}
    	ans-=dig[i];
    }
    //cout<<j<<endl;
    //cout<<lol<<endl;
    //return 0;
    ans=lol;
    ans%=mod;
    for(i=1;i*i<=s;i++){
    	if(s%i==0){
    		//cout<<i<<endl;
    		
    		if(i>=8){
    			//cout<<"dassd"<<endl;
	    		val=s/i;
	    		ans+=power(i)-power(i-1)-val+1;
	    		ans%=mod;
	    		if(i>=8)
	    			ans--;
	    	}
    		i=s/i;
	    	if(i>=8 && i*i!=s){
	    		//cout<<i<<endl;
	    		val=s/i;
	    		ans+=power(i)-power(i-1)-val+1;
	    		//cout<<power(i+1)
	    		ans%=mod;
	    		if(i>=8)
	    			ans--;
	    	}
	    	i=s/i;
    	}
    	//cout<<i<<endl;
    	
    }
    //cout<<ans<<endl;
    //return 0;
    //cout<<ans<<endl;
    ll a,b,val1,val2,c;
  //   f(i,9,s+1){
  //   	val=i;
  //   	//cout<<"dasds";
  //   	a=val;
		// b=val-1;
		// c=s;
		// val1=c/a;
		// val2=c/b;
		// if(c%b==0)
		// 	val2--;
		// val1++;
		// cout<<val1<<" "<<val2<<endl;
		// ans+=max(val2-val1+1,0LL);
  //   	ans%=mod;
  //   }
    ans++;
    
     ans+=s/8-1;

    ans+=mod;
    ans%=mod;
    cout<<ans<<endl;
    return 0;  
    
}



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

const int day = 100;
int64_t dp[day];

int main(){
  int64_t N;
  cin >> N;
  vector<int64_t> vec(N);
  for(int i=0; i<N; i++){
    cin >> vec[i];
  }
  
  dp[0] = 1000;
  
  for(int i=0; i<N; i++){
    dp[i+1] = dp[i];
    for(int j=0; j<i; j++){
      int64_t stock = dp[j] / vec[j];
      int64_t amari = dp[j] % vec[j];
      dp[i+1] = max(dp[i+1], stock*vec[i] + amari);
    }
  }
  cout << dp[N] << endl;
}

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

#define REP(i, n ,N) for(ll i = (n); i < (N); i++)
#define p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl
using namespace std;
typedef long long ll;
ll mod = 1e9+7;
ll inf = 1e18;


ll N, W;
ll w[110], v[110];
ll dp[110][100010];
int main(){
	cin >> N >> W;
	REP(i,0,N){
		cin >> w[i] >> v[i];
	}
	dp[0][0]=0;
	REP(i,0,N){
		REP(nw,0,W){
			dp[i+1][nw] = max(dp[i+1][nw], dp[i][nw]);
			if(nw + w[i] > W) continue;
			dp[i+1][nw + w[i]] = max(dp[i+1][nw + w[i]], dp[i][nw] + v[i]);

		}
	}
	ll ans = 0;
	REP(i,0,W+1){
		ans = max(ans, dp[N][i]);
	}
	p(ans);
	return 0;
}

Measured memory_bytes: 79360
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t_hp = Integer.parseInt(sc.next());
        int t_atk = Integer.parseInt(sc.next());
        int a_hp = Integer.parseInt(sc.next());
        int a_atk = Integer.parseInt(sc.next());
        boolean t_victory = false;
        while ((t_hp > 0) || (a_hp > 0)) {
            a_hp -= t_atk;
            if (a_hp <= 0) {
                t_victory = true;
                break;
            }
            t_hp -= a_atk;
            if (t_hp <= 0) {
                break;
            }
        }
        if (t_victory) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }

        sc.close();
    }

}


Measured memory_bytes: 35580
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
#define inf 1000000000000000000
#define bpc(x) __builtin_popcountll(x)
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define rep(n) for(ll i = 0; i < n; i++)
#define repi(i,n) for(ll i = 0; i < n; i++)

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 

using namespace std;

#define Pi 3.14159265                   

int main()
{
   FAST/**/
   
   ll r;
   cin>>r;
   ld ans = ((ld)2)*Pi*r;
   cout<<fixed<<setprecision(12)<<ans;
   
   return 0;        
}  
  
   

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

typedef long long LL;

const int N = 3005;
const int MOD = 998244353;

int A, B, C, D, f[N][N][2];

int main()
{
	scanf("%d%d%d%d", &A, &B, &C, &D);
	f[A][B][1] = 1;
	for (int i = A; i <= C; i++)
		for (int j = B; j <= D; j++) if (i > A || j > B)
		{
			f[i][j][0] = (LL)(f[i - 1][j][0] + f[i - 1][j][1]) * j % MOD;
			f[i][j][1] = (f[i][j - 1][0] + (LL)f[i][j - 1][1] * i % MOD) % MOD;
		}
	printf("%d\n", (f[C][D][0] + f[C][D][1]) % MOD);
	return 0;
}

Measured memory_bytes: 74196
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
#define rep(i,m,n) for(int i=m;i<n;i++)
#define co(n) cout<<n<<endl
#define all(n) (n).begin(),(n).end()
#define pb(n,m) n.push_back(m)
#define fix(n) cout<<fixed<<setprecision(n);
using namespace std;
//using bint=boost::multiprecision::cpp_int;
typedef long long ll;
typedef unsigned long long ull;

int main(){
  ll n; cin>>n;
  vector<ll> v(n);
  rep(i,0,n) cin>>v[i];
  sort(all(v)); reverse(all(v));
  ll ans=v[0],c=2;
  rep(i,1,n){
    if(c<n){
      ans+=v[i];
      c++;
    }
    else break;
    
    if(c<n){
      ans+=v[i];
      c++;
    }
    else break;
  }
  co(ans);
  
  return 0;
}

Measured memory_bytes: 4828
# coding: utf-8
# Your code here!
# coding: utf-8
import sys
sys.setrecursionlimit(10000000)

#const
# my functions here!
def pin(type=int):
    return map(type,input().rstrip().split())

def resolve():
    A=sorted(list(pin()))
    a,b,c=A
    if a*b*c%2==0:
        print(0)
    else:    
        ans=A[0]*A[1]
        print(ans)
"""         
#printデバッグ消した？
#前の問題の結果見てないのに次の問題に行くの？
"""
"""
お前カッコ閉じるの忘れてるだろ
"""
import sys
from io import StringIO
import unittest

class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """3 3 3"""
        output = """9"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """2 2 4"""
        output = """0"""
        self.assertIO(input, output)
    def test_入力例_3(self):
        input = """5 3 5"""
        output = """15"""
        self.assertIO(input, output)

if __name__=="__main__":resolve()

Measured memory_bytes: 51184
import java.util.Scanner;

public class Main {
	static final long M = 1000000007;
	public static void main(String[] args) {
		long N, K, res = 0;
		Scanner sc = new Scanner(System.in);
		N = sc.nextLong();
		K = sc.nextLong();
		for(long i=K; i<=N+1; i++) {
			res = (res + (N*i%M -i*i%M + i +1)%M)%M;
		}
		System.out.println(res);
	}
}


Measured memory_bytes: 35808
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <numeric>
#include <fstream>
#include <iomanip>

typedef long double ld;
typedef long long ll;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1e9 + 7;

// Split
namespace util {

std::vector< std::string > split(std::string s, char delimiter)
{
  std::vector< std::string > vs;
  std::string sub;
  for (auto c : s) {
    if (c == delimiter) vs.push_back(sub), sub.clear();
    else sub += c;
  }
  vs.push_back(sub);
  return vs;
}

} // namespace util

// Minimum, Maximum
template<class T> T minimum(T head, T tail) { return std::min(head, tail); }
template<class H, class... T> H minimum(H head, T... tail) { return std::min(head, minimum(tail...)); }
template<class T> T maximum(T head, T tail) { return std::max(head, tail); }
template<class H, class... T> H maximum(H head, T... tail) { return std::max(head, maximum(tail...)); }

// Output
template<class T, class S> std::ostream& operator << (std::ostream& os, std::pair<T, S> p)
{
  return os << p.first << " " << p.second;
}

template<class T> std::ostream& operator << (std::ostream& os, std::vector< T > v)
{
  for (ll i = 0; i < (ll)v.size(); i++){ os << " [" << i << "]" << v[i]; if (i % 10 == 9) os << std::endl; }
  return os;
}

template<class T, class S> std::ostream& operator << (std::ostream& os, std::vector< std::pair<T, S> > vp)
{
  ll i = 0;
  for (auto p : vp){os << " [" << i++ << "]" << p.first << " " << p.second; if (i % 10 == 0) os << std::endl;}
  return os;
}

void print(){ std::cout << std::endl; }
template<typename H> void print(H head) { std::cout << head << std::endl; }
template<typename H, typename... T> void print(H head, T... tail){ std::cout << head << " ", print(tail...); }

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

  ll H, W, K;
  std::cin >> H >> W >> K;

  std::string judge = "No";
  for (ll y = 0; y <= H; y++) {
    for (ll x = 0; x <= W; x++) {
      if (x * (H - y) + y * (W - x) == K) {
	judge = "Yes";
      }
    }
  }

  print(judge);
  return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
x = sum(a)
for i in range(n):
    if a[i]<=b[i]:
        a[i], b[i] = 0, b[i]-a[i]
        a[i+1] = max(a[i+1]-b[i], 0)
    else:
        a[i] -= b[i]
print(x-sum(a))

Measured memory_bytes: 18624
#include <iostream>
#include <string>
#include <algorithm>
#include <unordered_map>
#include <vector>
#include <map>
using namespace std;

int main()
{
  string s;
  cin >> s;
  int k;
  cin >> k;
  map<char, vector<string>> mp;

  int sLength = s.size();
  for (int i = 0; i < sLength; ++i)
  {
    vector<string> tmp;
    for (int j = 0; j < 5; ++j)
    {
      mp[s[i]].push_back(s.substr(i, j + 1));
    }
  }
  int count = 0;
  k--;

  for (auto pair : mp)
  {
    std::sort(mp[pair.first].begin(), mp[pair.first].end());
    std::vector<string>::iterator new_end = std::unique(mp[pair.first].begin(), mp[pair.first].end());
    mp[pair.first].erase(new_end, mp[pair.first].end());

    if (count <= k && k < count + mp[pair.first].size())
    {
      cout << mp[pair.first][k - count] << endl;
      return 0;
    }
    else
    {
      count += mp[pair.first].size();
    }
  }

  return 0;
}

Measured memory_bytes: 1532
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int A,B,C,X;
    int ans=0;
    cin>> A>>B>>C>>X;
    for(int i=0;i<=A;i++){
        for(int j=0;j<=B;j++){
            for(int k=0;k<=C;k++){
               if(500*i+100*j+50*k==X){
                   ans++;
               } 
            }
        }
    }
    cout <<ans;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
int a,b,c;
scanf("%d", &a);
scanf("%d", &b);
scanf("%d", &c);
if(a>b){
if(a>c){
printf("%d\n",10*a+b+c);
}else{
printf("%d\n",a+b+10*c);
}
}else{
if(b>c){
printf("%d\n",a+10*b+c);
}else{
printf("%d\n",a+b+10*c);
}
}
return 0;
}

Measured memory_bytes: 128
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(10);
}
ll f(ll v){
  if(v==1) return 1;
  else return 1+f(v/2)*2;
}
signed main(){
  init_io();
  ll h;
  cin >> h;
  cout << f(h)<<endl;
}


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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define ALL(x) x.begin(),x.end()
#define EPS (1e-8)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

typedef long long ll;
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;

inline bool LT(double a,double b) { return !equals(a,b) && a < b; }
inline bool LTE(double a,double b) { return equals(a,b) || a < b; }

void compute() {

}

int main() {
  string s;
  cin >> s;
  int n = s.size();
  int g = 0, p = 0;
  rep(i,n) ++( s[i] == 'g' ? g : p );
  int win = 0;
  for(int i=n-1;i>=0;--i) {
    if( s[i] == 'g' && g-1 >= p+1 ) {
      --g, ++p, ++win;
    }
  }
  cout << win << endl;
  compute();
  return 0;
}


Measured memory_bytes: 512
#include <iostream>

using namespace std;

int calc_combination(int x, int y, int z){
    if(x == y && y == z){
        return 1;
    }
    else if(x == y || y == z){
        return 3;
    }
    else{
        return 6;
    }
    cout << "error" << endl;
    return 0;
}

int main(){
    int K,S;
    cin >> K >> S;

    int ans = 0;
    for(int x=0; x<=K; x++){
        for(int y=x; y<=K; y++){
            for(int z=y; z<=K;z++){
                if(x+y+z==S){
                    ans += calc_combination(x,y,z);
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <cstdlib>
#include <string>
#include <algorithm>
using namespace std;

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

int main() {
	int n, k, x, y, ans = 0;
	cin >> n >> k >> x >> y;
	if(n <= k){
		for(int i = 0; i < n; i++){
			ans += x;
		}
	}else{
		for(int i = 0; i < k; i++){
			ans += x;
		}
		for(int i = 0; i < n-k; i++){
			ans += y;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_A main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
// functions

#endif

int main_A() {
    cin.tie(0);
    ios::sync_with_stdio(false);
     
    int N; cin >> N;

    string ans = N>999 ? "ABD" : "ABC";

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std ;
int main(){
	const long long int INF=1e9+7;
	int n;
	cin>>n;
	long long int h[n];
	for(int i=0;i<n;i++){
		cin>>h[i];
	}
	long long int dp[n];
	std::fill_n(dp,n,INF);
	dp[0]=0;
	for(int i=0;i<n;i++){
		if(i+1<n){
			dp[i+1]=min(dp[i+1],abs(h[i]-h[i+1])+dp[i]);
		}
			if(i+2<n){
			dp[i+2]=min(dp[i+2],abs(h[i]-h[i+2])+dp[i]);
		}
	}
	cout<<dp[n-1]<<endl;
	return 0;
}

Measured memory_bytes: 1792
import sys
input = sys.stdin.readline

n, m = map(int, input().split())
mod = 1000000007
a = set(int(input()) for _ in range(m))

dp = [0]*(n+1)
dp[0] = 1
if 1 not in a:
    dp[1] = 1

for i in range(2, n+1):
    if i not in a: dp[i] = dp[i-1] + dp[i-2]

print(dp[n]%mod)

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

int main(){
  int N;cin>>N;
  int H[N];
  for(int i=0;i<N;i++){
    cin>>H[i];
  }
  int check = 0;
  int count = 0;
  int ans = 0;
  
  for(int i=0;i<N-1;i++){
    if(H[i]<H[i+1]){
      ans = max(ans,count);
      count = 0;
    }
    else count++;
  }
  cout<<max(ans,count)<<endl;
}
    
    

Measured memory_bytes: 3968
#include <cstdio>
#include <cstring>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define INF (1<<21)
#define max(a,b) (a<b?b:a)
int v[10][10];
int N;

int dx[] = {0,1,0,-1,-1,1};
int dy[] = {1,1,-1,-1,0,0};

bool done[10][10] = {0};
bool chk(int x,int y,int num,int &c){
	if(y < 0 || x >= y+1 || x < 0 || y >= N) return false;	
	if(!v[y][x])return true;
	if(num != v[y][x])return false;
	if(done[y][x])return false;
	else done[y][x] = true;
	c++;
	bool ans = false;
	rep(i,6) ans |= chk(x+dx[i],y+dy[i],num,c);
	return ans;
}

int solve(int c){
	int ans = -INF;
	
	rep(i,N){
		rep(j,i+1){
			int sum = 0;
			memset(done,0,10*10);
			if(v[i][j]) continue;
			v[i][j] = c;
			int a=0;
			if( !chk(j,i,v[i][j],a) ) sum -= 2*a;
			memset(done,0,10*10);
			
			rep(y,N)rep(x,y+1){
				if( done[y][x] || !v[y][x])continue;
				int b = 0;
				if( !chk(x,y,v[y][x],b) )sum += b;
			}
			v[i][j] = 0;
			ans = max(ans,sum);
		}
	}
	return ans;
}

int main(){
	int c;
	while(scanf("%d %d",&N,&c) && N || c){
		rep(i,N)rep(j,i+1) scanf("%d",&v[i][j]);
		printf("%d\n",solve(c));
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define REP(i, n) for(long long i=0; i<n; i++)
#define REPR(i, n) for(long long i=n-1; i>=0; i--)
#define FOR(i, m, n) for(long long i=m; i<=n; i++)
#define FORR(i, m, n) for(long long i=m; i>=n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;
const ll mod = 1e9+7;
const ll inf = 1e15;



int main(){FIN

    ll n,k;cin>>n>>k;
    vll h(n); REP(i,n) cin>>h[i];
    VSORT(h);
    ll mn=inf;
    ll i=0;
    while(i+k-1<n){
        ll ans = h[i+k-1] - h[i];
        mn=min(mn,ans);
        i++;
    }
    cout<<mn<<endl;
    return 0;
}

Measured memory_bytes: 1024
N = int(input())
X = []
L = []
for i in range(N):
    x, l = map(int, input().split())
    X.append(x)
    L.append(l)

# できるだけ少ないロボットを取り除いて条件を満たすようにしたい
ranges = [[x - l, x + l] for x, l in zip(X, L)]
ranges = sorted(ranges, key=lambda x:x[1])

ans = N
for i in range(1, N):
    if ranges[i][0] < ranges[i - 1][1]:
        ranges[i][1] = ranges[i - 1][1]
        ans -= 1
print(ans)


Measured memory_bytes: 29976
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(void){
    int slen, tlen;
    string s, t;
    cin >> s >> t;
    slen = s.length();
    tlen = t.length();
    for(int i=slen-tlen;i>=0;i--){
        bool flg = true;
        for(int j=0;j<tlen;j++){
            if(s[i+j] != t[j] && s[i+j] != '?'){
                flg = false;
                break;
            }
        }
        if(flg){
            for(int j=0;j<slen;j++){
                if(j == i){
                    while(j < i + tlen){
                        s[j] = t[j-i];
                        j++;
                    }
                }
                if(s[j] == '?') s[j] = 'a';
            }
            cout << s << endl;
            return 0;
        }
    }
    puts("UNRESTORABLE");
}


Measured memory_bytes: 256
A, B, C, D = map(int, input().split())
 
ans = 0
 
for i in range(max(A, B, C, D)+1):
  if (A <= i and i <= B) and (C <= i and i <= D):
    ans += 1
 
if ans <= 1:
  print(0)
elif A == C and B == D:
  print(ans - 1)
else:
  print(ans-1)

Measured memory_bytes: 3064
#include <stdio.h>
#define MAX 250

int parent(int);
int left(int);
int right(int);

int main(){
  int H,i,A[MAX+1];
    
  scanf("%d",&H);
  for(i=1;i<=H;i++){
    scanf("%d",&A[i]);
  }

  for(i=1;i<=H;i++){
    printf("node %d: key = %d, ",i,A[i]);
    if(parent(i)>=1) printf("parent key = %d, ",A[parent(i)]);
    if(left(i)<=H) printf("left key = %d, ",A[left(i)]);
    if(right(i)<=H) printf("right key = %d, ",A[right(i)]);
    printf("\n");
  }
  return 0;
}

int parent(int i){
  return i/2;
}

int left(int i){
  return 2*i;
}

int right(int i){
  return 2*i+1;
}


Measured memory_bytes: 2104
#include <stdio.h>
#include <string.h>
int main(void){
    int q, i, side[6], front, top, right;
    
    scanf("%d %d %d %d %d %d\n", &side[0], &side[1], &side[2], &side[3], &side[4], &side[5]);
    scanf("%d", &q);
    
    for(i=0; i<q; i++){
        scanf("%d %d", &top, &front);
        
        if(top==side[0]){
            if(front==side[1]){
                right = side[2];
            }else if(front==side[2]){
                right = side[4];
            }else if(front==side[3]){
                right = side[1];
            }else if(front==side[4]){
                right = side[3];
            }else{
                break;
            }
            
        }else if(top==side[1]){
            if(front==side[0]){
                right = side[3];
            }else if(front==side[2]){
                right = side[0];
            }else if(front==side[3]){
                right = side[5];
            }else if(front==side[5]){
                right = side[2];
            }else{
                break;
            }
            
        }else if(top==side[2]){
            if(front==side[0]){
                right = side[1];
            }else if(front==side[1]){
                right = side[5];
            }else if(front==side[4]){
                right = side[0];
            }else if(front==side[5]){
                right = side[4];
            }else{
                break;
            }
            
        }else if(top==side[3]){
            if(front==side[0]){
                right = side[4];
            }else if(front==side[1]){
                right = side[0];
            }else if(front==side[4]){
                right = side[5];
            }else if(front==side[5]){
                right = side[1];
            }else{
                break;
            }
            
        }else if(top==side[4]){
            if(front==side[0]){
                right = side[2];
            }else if(front==side[2]){
                right = side[5];
            }else if(front==side[3]){
                right = side[0];
            }else if(front==side[5]){
                right = side[3];
            }else{
                break;
            }
            
        }else if(top==side[5]){
            if(front==side[1]){
                right = side[3];
            }else if(front==side[2]){
                right = side[1];
            }else if(front==side[3]){
                right = side[4];
            }else if(front==side[4]){
                right = side[2];
            }else{
                break;
            }
            
        }else{
            break;
        }
        printf("%d\n", right);
    }
    return 0;
}



Measured memory_bytes: 2040
#include<iostream>
#include<algorithm>
#include<set>
using namespace std;
set<int>s;
long ans,n,a[1<<18],p[1<<18];
main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		p[a[i]-1]=i;
	}
	s.insert(-1);s.insert(n);
	for(int i=0;i<n;i++)
	{
		set<int>::iterator it=s.lower_bound(p[i]);
		long r=(*it)-p[i];
		it--;
		long l=p[i]-(*it);
		ans+=(i+1)*r*l;
		s.insert(p[i]);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 13184
#include <bits/stdc++.h>
#define len(x) (int) (x.size())
using namespace std;
typedef long long ll;

int main(){
    int n, val;
    cin >> n;
    vector<bool> elem(1000001, false);
    map<int, bool> visited;
    
    for(int i = 0; i < n; i++) {
        cin >> val;
        if(visited[val] == true) {
            elem[val] = false;
            continue;
        }
        for(int j = val; j < 1000001; j += val) {
            visited[j] = true;
            if(j == val) elem[j] = true;
            else elem[j] = false;
        }
    }
    ll ans = 0;
    for(int i = 0; i < 1000001; i++) {
        if(elem[i] == true) ans++;
    }
    cout << ans << '\n';
    
    return 0;
}

Measured memory_bytes: 50632
#include <bits/stdc++.h>
 
using namespace std;
 
#define lli long long int
#define MOD 1000000007
#define DEBUG 1
#define REP(i,n) for(int i=0;i<n;i++)
#define REP2(i,n) for(lli i=1;i<=n;i++)


int main(){

	lli n,m;
	cin>>n>>m;

	lli ans=0;
	for(lli b=m+1;b<=n;b++){
		lli p = n/b;
		lli r = n%b;
		ans += p * max((lli)0,b-m) + max((lli)0,r-m+1) - (m==0?1:0);
	}
	cout<<ans<<endl;
 
	return 0;
}
 

Measured memory_bytes: 256
n=int(input())
s=[input() for i in range(n)]
s.sort()
m=int(input())
t=[input() for i in range(m)]
t.sort()

#print(n)
#print(s)
#print(m)
#print(t)

ans=0

s1=list(set(s))
#print(s1)
t1=list(set(t))
#print(t1)
st1=s1+t1

for i in range(len(st1)):
    cnt=s.count(st1[i])-t.count(st1[i])
    if ans<cnt:
      ans=cnt
      
#print(cnt)
#print(st1)

print(ans)



Measured memory_bytes: 3064
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <string>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <map>
#include <bitset>
using namespace std;
#define len(n) (int)n.length()
#define dump cout
#define pb push_back
#define ll long long

int main()
{
	ios::sync_with_stdio(false);
	
	int n;
	cin >> n;
	
	vector<int> vec;
	for (int i = 0; i < n; i++) {
	    int tmp;
		cin >> tmp; vec.pb(tmp);
	}
	
	int ans = 0;
	for (int i = 0; i < n; i++) {
		int min_i = i;
	    for (int k = i; k < n; k++) {
	        if (vec[min_i] > vec[k])
			{
				min_i = k;
			}
	    }
	    int tmp = vec[min_i];
		vec[min_i] = vec[i];
		vec[i] = tmp;
		if (min_i != i)
			ans++;
	}
	
	for (int i = 0; i < n-1; i++) {
	    cout << vec[i] << " ";
	}
	cout << vec[n-1] << endl;
	cout << ans << endl;
	
	
	return 0;
}

Measured memory_bytes: 3184
#include<iostream>
#include<cmath>
#include<vector>
#include<climits>
#include<algorithm>
#include<map>
using namespace std;
#define ll long long
const ll Mod = (int)1e9;
ll CaseN=1;
ll fast_power(ll a,ll b,ll mod){
	ll ans=1;
	while(b>0){
	if(b&1){
	ans=(a*ans)%mod;
	}
	b=b>>1;
	a=(a*a)%mod;
	}
	return ans;
	}


ll nCr(ll n ,ll r)
{
ll p= n;
r = min(r,n-r);
ll a =1;
ll b=1;	
while(r)
{
	a = a*p;
	b = b*r;
	
	int g = __gcd(a,b);
	
	a = a/g;
	b = b/g;
	
	p--;
	r--;	
}	
return a;
	
}



void solve()
{
	ll a,b;
	cin>>a>>b;
	cout<<a*b<<endl;

   //cout<<"Case #"<<CaseN<<": ";
   CaseN++;
	// print your ans below;

return ;
}


signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t=1;
	//cin>>t;
	while(t--)
	{
	solve();	
	}
}


Measured memory_bytes: 3608
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define DEBUG true
#ifdef ONLINE_JUDGE
#undef DEBUG
#define DEBUG false
#endif 

using namespace std;

#define MAXN ((int)2e5+5)
#define MOD ((int)1e9 + 7)
#define INF ((int)1e9 + 9)
#define ll long long
#define _ << " " <<
#define CLEAR(a, b) memset(a, b, sizeof(a))
#define TRACE(x) if(DEBUG) cerr << #x << " = " << x << endl;
#define TRACE2(x,y) if(DEBUG) cerr << #x << " = " << x << " | " << #y << " = " << y << endl;
#define pb push_back
#define all(x) x.begin(), x.end()
#define endl "\n"
#define pii pair<int,int>
#define mid ((l+r)/2)

int n;

int main()
{
	ios_base::sync_with_stdio(false);cin.tie(0);
	cin >> n;
	cout << fixed << ( n * 1LL * (n-1) ) / 2 << endl;
}

Measured memory_bytes: 256
a,b,m=map(int,input().split())
al=list(map(int,input().split()))
bl=list(map(int,input().split()))
l=[]

for i in range(m):
  q=list(map(int,input().split()))
  l.append(al[q[0]-1]+bl[q[1]-1]-q[2])
l.append(min(al)+min(bl))
print(min(l))



Measured memory_bytes: 70588
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  string s;
  cin>>n>>s;
  
  if(n%2==1){
    cout<<"No"<<endl;
  }
  
  else{
    int middle=n/2;
    int c=0;
    
    for(int i=0;i<middle;i++){
      if(s[i]==s[middle+i]){
        c++;}
      else{
        c=middle+1;
      }
    }
      if(c==middle){
        cout<<"Yes"<<endl;
      }
      else{
        cout<<"No"<<endl;
      }
    }
  
  
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<int,ll> pil;
#define Mp make_pair
const int MAXN = 2e5 + 5;
const ll linf = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;

inline void chk_max(ll &a,ll b){ if(a<b) a=b;}

struct Segment_Tree
{
	ll mx[MAXN<<2];
	#define ls(u) ((u)<<1)
	#define rs(u) ((u)<<1|1)
	inline void push_up(int u){ mx[u] = max(mx[ls(u)], mx[rs(u)]);}
	void update(int u,int l,int r,int q,ll k)
	{
		if(l==r){ mx[u]=k; return;}
		int mid = (l+r)>>1;
		if(q<=mid) update(ls(u),l,mid,q,k);
		else update(rs(u),mid+1,r,q,k);
		push_up(u);
	}
	ll query(int u,int l,int r,int ql,int qr)
	{
		if(ql<=l && r<=qr) return mx[u];
		int mid = (l+r)>>1;
		ll res=-linf;
		if(ql<=mid) chk_max(res, query(ls(u),l,mid, ql,qr));
		if(mid<qr) chk_max(res, query(rs(u),mid+1,r, ql,qr));
		return res;
	}
}tree;

ll a[MAXN];
ll pre[MAXN][2], suf[MAXN][2];

int main(void)
{
	int n;
	scanf("%d",&n);
	for(int i=1; i<=n; ++i) scanf("%lld",&a[i]);
	if(!(n&1)) a[++n]=-1e16;
	
	for(int i=1; i<=n; ++i)
	{
		pre[i][0] = pre[i-1][0];
		pre[i][1] = pre[i-1][1];
		pre[i][i&1] += a[i];
	}
	for(int i=n; i>=1; --i)
	{
		suf[i][0] = suf[i+1][0];
		suf[i][1] = suf[i+1][1];
		suf[i][i&1] += a[i];
	}
	
	ll ans=-linf, dif=0;
	for(int i=1; i<=n; ++i)
	{
		if(i>1) chk_max(ans, suf[i+1][1] + tree.query(1,1,n, 1,i-1) + dif);
		if(!(i&1)) dif += a[i];
		tree.update(1,1,n, i,pre[i-1][1]-dif);
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 15748
/*#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <array>
#include <vector>
#include <deque>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <unordered_map>
#include <unordered_set>
*/

#include <bits/stdc++.h>
using namespace std;

#define int long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define FOR(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define ve vector
#define vi vector<int>
#define vp vector<pair<int,int>>
#define vvi vector<vector<int>>

typedef long long ll;
const ll INF = LLONG_MAX / 4 - 100;
const ll mod = 1e9 + 7;
const int MAX_N = 5e5 + 5;
int dx[] = { -1LL,0,1LL,0 }, dy[] = { 0,1LL,0,-1LL };
vector<ll> prime;

ll inv[MAX_N], fac[MAX_N];

void DEBUG(vector<int> a) {for(int i=0;i<a.size();i++){cout<<a[i]<<" ";}cout<<endl;}
inline ll GCD(ll a, ll b) { ll c; while (b != 0) { c = a % b; a = b; b = c; }return a; }
inline ll LCM(ll a, ll b) { return a * b / GCD(a, b); }
inline ll POW(ll a, ll b) { ll c = 1LL; while (b > 0) { if (b & 1LL) { c = a * c%mod; }a = a * a%mod; b >>= 1LL; }return c; }
inline void _nCr() { fac[0] = 1LL; for (int i = 1LL; i < MAX_N; i++) { fac[i] = fac[i - 1LL] * i%mod; }for (int i = 0; i < MAX_N; i++) { inv[i] = POW(fac[i], mod - 2); } }
inline ll nCr(ll n, ll r) { return (fac[n] * inv[r] % mod)*inv[n - r] % mod; }
inline void PRI(ll n) { bool a[n + 1LL]; for (int i = 0; i < n + 1LL; i++) { a[i] = 1LL; }for (int i = 2; i < n + 1LL; i++) { if (a[i]) { prime.pb(i); ll b = i; while (b <= n) { a[b] = 0; b += i; } } } }
template <typename T> T chmin(T& a, T b) {if(a>b)a=b;return a;}
template <typename T> T chmax(T& a, T b) {if(a<b)a=b;return b;}

signed main() {
	int n, K; cin >> n >> K;
	int v[n]; REP (i,n) cin >> v[i];
	int ans = -INF;
	REP (i,n+1) {
		REP (j,n+1) {
			//左からiこ 右からj娘
			if (i + j > n) continue;
			if (i + j > K) continue;
			vi cand;
			int tmp = 0;
			REP (k,i) {
				cand.pb(v[k]);
				tmp += v[k];
			}
			REP (k,j) {
				cand.pb(v[n-k-1]);
				tmp += v[n-k-1];
			}
			sort(ALL(cand));
			REP (k,min((int)cand.size(),K-i-j)) {
				// DEBUG({i,j,k,K,tmp});
				if (cand[k] >= 0) break;
				tmp -= cand[k];
			}
			chmax(ans,tmp);
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
int N,H,W;	
int main(){
	cin>>N>>H>>W;
	cout<<(N-H+1)*(N-W+1)<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <limits>
#include <map>
#include <cassert>
#pragma GCC optimize("O3,Ofast,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#pragma GCC target("arch=ivybridge")
using namespace std;
using VI = vector<long>;

int main() {
    string s;
    cin >> s;
    int a = s.front() == 'A';
    int cnt = 0;
    for (int i = 2; i < s.size() - 1; i++) {
        if (s[i] == 'C') cnt++;
    }
    int c = 0;
    for (int i = 0; i < s.size(); i++) {
        if ('a' <= s[i] && s[i] <= 'z') c++;
    }
    if (a && cnt == 1 && c + 2 == s.size()) {
        cout << "AC" << endl;
    } else {
        cout << "WA" << endl;
    }
}


Measured memory_bytes: 256
from collections import defaultdict
D=defaultdict(int)
E=defaultdict(int)
n=int(input())
l=map(int,input().split())
for i in l:
    D[i]+=1
m=int(input())
e=map(int,input().split())
for j in e:
    E[j]+=1
for i in E.keys():
    if E[i]>D[i]:print("NO");exit()
print("YES")

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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;



int main(){
    cin.tie(0);
    cin.sync_with_stdio(0);

    int A, B;
    string S;
    cin >> A >> B >> S;
    int idx = S.find('-');
    for(int a = idx + 1; a < (int)S.size(); a++){
        if(S[a] == '-'){
            cout << "No";
            return 0;
        }
    }

    if(idx == string::npos){
        cout << "No";
    } else {
        cout << (idx == A && (int)S.size() - idx == B + 1 ? "Yes" : "No");
    }
}

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

int main(){
    int n;
    cin >> n;
    int ret = 0;
    int a[n];
    for(int i = 0; i < n; i++)  cin >> a[i];
    int bef = 1<<30;
    for(int i = 0; i < n; i++){
        if(bef < a[i]){
            bef = a[i];
            continue;
        }else{
            ret++;
            bef = a[i];
        }
    }
    cout << ret << endl << n << endl;
    return 0;
}


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

int main(void){
    int i,keyn,key[101];
    char code[101];
    char station[53]="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
    int kingpos;
    while(scanf("%d",&keyn)!=EOF && keyn!=0){
        for(i=0;i<=keyn;i++){
            scanf("%d ",&key[i]);
        }
        scanf("%s",code);
        for(i=0;i<=strlen(code)-1;i++){
            if(islower(code[i]))kingpos=code[i]-'a'-key[i%keyn];
            else kingpos=code[i]-'A'+26-key[i%keyn];
            if(kingpos<0)kingpos+=52;
            printf("%c",station[kingpos]);
        }
        printf("\n");
    }
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  int X=N%10;
  if(X==2||X==4||X==5||X==7||X==9)
    cout << "hon" << endl;
  else if(X==0||X==1||X==6||X==8)
    cout << "pon" <<endl;
  else cout << "bon" << endl;
}


Measured memory_bytes: 3636
#include<iostream>
using namespace std;
int main(){
int a,b,c,t;
cin>>a>>b>>c;

if(a>b){t=a; a=b; b=t;}
if(b>c){t=b; b=c; c=t;}
if(a>b){t=a; a=b; b=t;}

cout<< a <<" "<< b <<" "<< c <<endl;

return 0;
}

Measured memory_bytes: 1168
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) FOR(i,0,b)
#define INF mugen
#define dump(x) cerr<<#x<<"="<<x<<endl
#define all(a) (a).begin(),(a).end()
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<vii> viii;
typedef pair<int,int> P;
template <class T> void chmin(T & a, T const & b) { if (b < a) a = b; }

using ll = long long;
const ll mod = LLONG_MAX;


int main(){
  string s;
  cin>>s;
  int n=s.size();
  int ans = n;
   for (int i = 0; i < n - 1; ++i){
      if (s[i] != s[i + 1]) {
       ans = min(ans, max(i + 1, n - (i + 1)));
     }
   }
  cout << ans << endl;
}


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

int main(){
  int num[5];
  for(int i = 0;i < 5;i++){
    scanf("%d", num + i);
  }
  sort(num, num + 5);
  for(int i = 4;i >= 0;i--){
    if(i != 4)putchar(' ');
    printf("%d", num[i]);
  }
  puts("");
  return 0;
}

Measured memory_bytes: 1056
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define f first
#define s second
ll dist[100001];
vector<pair<ll,ll> >adj[100001];
void dfs(ll src,ll p,ll d)
{
	dist[src]=d;
	for(int i=0;i<adj[src].size();i++)
	{
		ll u=adj[src][i].first;
		ll w=adj[src][i].second;
		if(u==p) continue;
		
		dfs(u,src,dist[src]+w);
	}
}
int main()
{
	int t=1;// cin>>t;
	while(t--)
	{
		int n; cin>>n;
		for(int i=0;i<n-1;i++)
		{
			int x,y,w; cin>>x>>y>>w;
			adj[x].pb(mp(y,w));
			adj[y].pb(mp(x,w));
		}
		
		ll q,k; cin>>q>>k;
		dfs(k,-1,0);
		while(q--)
		{
			ll x,y; cin>>x>>y;
			cout<<dist[x]+dist[y]<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 14336
#include <stdio.h>

int main(void)
{
  int k, n;
  int a[200001] = {0};
  int max = 0;

  scanf("%d %d", &k, &n);
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);

  for (int i = 1; i < n; i++){
    if (max < a[i] - a[i-1]) max = a[i] - a[i-1];
  }

  if (max < k - a[n-1] + a[0]) max = k - a[n-1] + a[0];
  

  printf("%d", k - max);

  return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		String s = sc.next();

		char[] c = s.toCharArray();

		boolean can = true;
		for (int i = 0; i < s.length(); i++) {
			if (i == a && c[i] != '-') {
				can = false;
			}
			if (i != a && c[i] == '-') {
				can = false;
			}
		}

		if (can) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}

		sc.close();
	}

}


Measured memory_bytes: 23124
#include<bits/stdc++.h>
using namespace std;
typedef long double ld;
const int N=1000005,M=1000000007;
int n,i,j,ans,l,r,al,ar,sp;
char c[N];
void rt(int m,int l,int r)
{
	for(i=strlen(c+1);i>=1;--i)
	{
		if(c[i]=='0')
		{
			--l;
			--r;
			if(l<0)
				l+=2;
		}
		if(c[i]=='1')
		{
			++l,++r;
			if(r>m)
				r-=2;
		}
		if(c[i]=='?')
		{
			--l;
			if(l<0)
				l+=2;
			++r;
			if(r>m)
				r-=2;
		}
		if(l>r||l>m||r<0)
		{
			al=1;
			ar=0;
			return;
		}
	}
	al=l,ar=r;
}
bool check(int m)
{
	int i;
	int a[2][2],b[2][2];
	rt(m,0,m/2*2);
	a[0][0]=al,a[0][1]=ar;
	rt(m,1,(m&1?m:m-1));
	a[1][0]=al,a[1][1]=ar;
	for(i=1;c[i];++i)
		if(c[i]=='0')
			c[i]='1';
		else
			if(c[i]=='1')
				c[i]='0';
	rt(m,0,m/2*2);
	b[0][0]=m-ar,b[0][1]=m-al;
	rt(m,1,(m&1?m:m-1));
	b[1][0]=m-ar,b[1][1]=m-al;
	if(m&1)
	{
		swap(b[0][0],b[1][0]);
		swap(b[0][1],b[1][1]);
	}
	for(i=1;c[i];++i)
		if(c[i]=='0')
			c[i]='1';
		else
			if(c[i]=='1')
				c[i]='0';
	if(min(a[0][1],b[0][1])>=max(a[0][0],b[0][0])||min(a[1][1],b[1][1])>=max(a[1][0],b[1][0]))
		return true;
	else
		return false;
}
int main()
{
	scanf("%s",c+1);
	int l=1,r=strlen(c+1);
	while(l<r)
	{
		int mid=l+r>>1;
		if(check(mid))
			r=mid;
		else
			l=mid+1;
	}
	cout<<l;
}


Measured memory_bytes: 4748