akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

bool cmp(pair<int,int> a ,pair<int,int> b ){
	if( a.first * a.first + a.second * a.second !=  b.first * b.first + b.second * b.second )
		return a.first * a.first + a.second * a.second < b.first * b.first + b.second * b.second;
	return a.first < b.first;
}
int main(){

	int h,w;
	while(cin >> h >> w && h ){
		pair<int,int> x;
		for(int i = 1 ; i <= 200 ; i++){
			for(int j =  i+1; j <= 200 ; j++){
				if( cmp({h,w},{i,j}) && ( x.first == 0 || cmp({i,j},x)) ){
					x = {i,j};
				}
			}
		}
		cout << x.first << " " << x.second << endl;
	}
}

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

//#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

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;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//以降 cin の入力元が 'input.txt' になる
//std::ifstream in("input.txt");
//std::cin.rdbuf(in.rdbuf());
 
signed main()
{   
    //後ろから考える
    gearup;
    ll n,m,k; cin >> n >> m >> k;
    vl a(n),b(m);
    vl sa(n+1),sb(m+1);
    rep(i,n)cin>>a[i],sa[i+1]=sa[i]+a[i];
    rep(i,m)cin>>b[i],sb[i+1]=sb[i]+b[i];
    ll res = 0;
    rep(i,n+1){
        ll now = sa[i];
        ll dif = k - now;
        ll idx = upper_bound(all(sb), dif) - sb.begin();
        if(idx == 0)continue;
        res = max(res,(i)+idx-1);
    }
    out(res);
}

Measured memory_bytes: 9456
#include <iostream>
#include <bits/stdc++.h>
#include <math.h>

using namespace std;

int main(){
    int n,k;
    cin>>n>>k;
    vector<int> hoge(n);
    
    for(int i=0;i<n;i++) cin>>hoge.at(i);
    
    sort(hoge.begin(),hoge.end());
    reverse(hoge.begin(),hoge.end());
    if(k>n) k=n;
    
    for(int i=0;i<k;i++) hoge.at(i)=0;
    
    long long ans=0;
    for(int i=0;i<n;i++) ans+=hoge.at(i);
    
    cout<<ans<<endl;
    
    return 0;
}

Measured memory_bytes: 1024
N= int(input())
l=[0]*10000
for i in range(1,101):
   for j in range(1,101):
      for k in range(1,101):
         x=i**2+j**2+k**2+i*j+j*k+i*k
         if x>10000:
            pass
         else:
            l[x-1]+=1
for i in range(N):
   print(l[i])

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

LL dp[5000][5000];
LL value[5000];

LL cal(LL i, LL j)
{
    if (j < i)
    {
        return 0;
    }

    if (dp[i][j] == -1)
    {

        if (dp[i + 2][j] == -1)
        {
            dp[i + 2][j] = cal(i + 2, j);
        }

        if (dp[i + 1][j - 1] == -1)
        {
            dp[i + 1][j - 1] = cal(i + 1, j - 1);
        }

        if (dp[i][j - 2] == -1)
        {
            dp[i][j - 2] = cal(i, j - 2);
        }

        dp[i][j]=max(value[i]+min(dp[i+2][j],dp[i+1][j-1]),value[j]+min(dp[i+1][j-1],dp[i][j-2]));
    }

    return dp[i][j];
}

int main()
{
    LL i, j, k, n,sum=0;
    for (i = 0; i < 5000; i++)
    {
        for (j = 0; j < 5000; j++)
        {
            dp[i][j] = -1;
        }
    }

    cin >> n;
    for (i = 1; i <= n; i++)
    {
        cin >> value[i];
        sum+=value[i];
    }

    LL answer = cal(1, n);

    cout<<2*answer-sum<<endl;
}

Measured memory_bytes: 195712
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<string>
#include<sstream>
#include<iomanip>
#include<utility>
#include<cmath>
#include<set>
#include<list>
#include<queue>
#include<stack>
#include<deque>
#include<map>
#include<set>
#include<cstring>
#include<iterator>
#include<bitset>
#include<assert.h>
using namespace std;
 
struct edge {int /*from,*/to,cost;};
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
typedef vector<int> VI;
typedef vector<long long int> VL;
typedef vector<edge> VE;
static const int MOD = 1000000007;
//static const int INF = 2147483647;
//static const long long INF = 9223372000000000000;
//static const long long INF = 9223372000000000000/2;
//static const int INF = 1000010000;
//int dx4[4] = {0,1,0,-1}, dy4[4] = {-1,0,1,0};
//int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
//int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
//int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define NP next_permutation
#define PQ priority_queue
#define UB upper_bound
#define LB lower_bound
#define ALL(x) (x).begin(),(x).end()
#define SZ(a) int((a).size())
#define LEN(a) int((a).length())
#define MAX(a,b,c) max((a),max((b),(c)))
#define MIN(a,b,c) min((a),min((b),(c)))
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REP1(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREP1(i,x) for(int i=((int)(x));i>0;i--)
#define int ll

signed main(){
    int x;
    scanf("%lld",&x);
    int cnt = x/11;
    x -= cnt*11;
    if(x>6) printf("%lld\n",2*cnt+2);
    else if(x>0) printf("%lld\n",2*cnt+1);
    else printf("%lld\n",2*cnt);
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#define _USE_MATH_DEFINES
#include<cmath>
#include<numeric>
#include<iomanip>
#include<deque>
#include<tuple>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<cstdint>
#include<unordered_map>
#include<sstream>
#include<boost/multiprecision/cpp_int.hpp>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define vi vector<int>
#define vll vector<ll>
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
#define pb push_back

namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

ll M = 1000000007;

typedef pair<int, int> P;

bool ps1(const P& element1, const P& element2)
{//first昇順
	return element1.first < element2.first;
}
bool ps2(const P& element1, const P& element2)
{//first降順
	return element1.first > element2.first;
}
bool ps3(const P& element1, const P& element2)
{//second昇順
	return element1.second < element2.second;
}
bool ps4(const P& element1, const P& element2)
{//second降順
	return element1.second > element2.second;
}

ll combination(ll n, ll r) {
	if (r * 2 > n) r = n - r;
	ll dividend = 1;
	ll divisor = 1;
	for (ll i = 1; i <= r; ++i) {
		dividend *= (n - i + 1);
		divisor *= i;
	}
	return dividend / divisor;
}
int main() {
	int r;
	cin >> r;
	cout << 3 * pow(r, 2) << endl;
}

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

int main() {
	int N, a[100001], out = -1;
	map<int, int> mp;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> a[i+1];
	}
	int next = 1, min = 0;
	while (true) {
		if (mp[next] == 1) break;
		if (next == 2) {
			out = min;
			break;
		}
		mp[next] = 1;
		next = a[next];
		min++;
	}
	cout << out << endl;
}

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

int main() {
  int n, S = 0, r = 0;
  cin >> n;
  vector<char> v(n);
  for(int i = 0;i < n;i++) {
    cin >> v[i];
    if(v[i] == 'R') r++;
  }
  for(int i = 0;i < r;i++) {
    if(v[i] == 'R') S++;
  }
  cout << r - S << endl;
}



Measured memory_bytes: 3612
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <algorithm> // sort
#include <map>
#include <cmath>

#define REP(i, n) for (long long i = 0; i < (n); i++) 
typedef long long ll;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)
using namespace std;

//0°から90°
//体積の何％が余っているかでは???
//半分 -> 45.000000 
int main(){
    double a,b,x;
    cin >> a >> b >> x;

    double tai = a * a * b;
    double z,res;
    //残りのほうが小さい
    if(tai - x < x)
    {
        z = b - (tai - x) / (a*a);
        //printf("%.12f\n",b-z);
        //printf("%.12f\n",a);

        res = atan2((b-z), a/2.0);
    }
    else
    {
        z = a - x /(b*a);
        //printf("%.12f\n",a-z);
        //printf("%.12f\n",b);
        res = atan2(b/2.0, (a-z));
    }

    //printf("%.12f\n",res);
    res = (double)rad_to_deg(res);
    //cout << tai << "," << x << endl;
    printf("%.12f\n",res);

    return 0;    
}



Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<vector>
#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define fo(i,a,b) for(i=a;i<=b;i++)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pi;
const int mx=90+10,mo=1000000007;
const ll inf=1000000000000000000;
ll fib[mx];
vector<pi> a[mx];
vector<pi>::iterator it;
ll x,y,n,m,num;
int i,j,k,l,t,tot,ca,ans;
int main(){
    fib[0]=fib[1]=1;
    tot=1;
    while (1){
        fib[tot+1]=fib[tot]+fib[tot-1];
        if (fib[tot+1]>inf) break;
        tot++;
    }
    a[1].pb(mp(1,2));a[1].pb(mp(1,3));
    fo(i,1,tot-3){
        it=a[i].begin();
        while (it!=a[i].end()){
            x=(*it).xx;y=(*it).yy;
            x+=y;
            while (x<=fib[i+3]+fib[i]){
                a[i+1].pb(mp(y,x));
                x+=y;
            }
            it++;
        }
    }
    scanf("%d",&ca);
    while (ca--){
        scanf("%lld%lld",&n,&m);
        if (n>m) swap(n,m);
        ans=1;
        while (fib[ans+1]<=n&&fib[ans+2]<=m) ans++;
        printf("%d ",ans);
        if (ans==1){
            printf("%lld\n",n*m%mo);
            continue;
        }
        else{
            num=0;
            it=a[ans-1].begin();
            while (it!=a[ans-1].end()){
                x=(*it).xx;y=(*it).yy;
                if (y<=n) (num+=(m-x)/y)%=mo;
                if (y<=m) (num+=(n-x)/y)%=mo;
                it++;
            }
            printf("%d\n",num);
        }
    }
}

Measured memory_bytes: 4096
/*** 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)...);}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    string S;
    cin >> S;
    ll ans = 0;
    ll cnt[1001] = {};
    vector<ll> pos[11];
    rep(i,0,N){
        pos[S[i] - '0'].push_back(i);
    }

    rep(i,1,N-1){
        ll c = S[i] - '0';
        rep(j,0,10){
            rep(k,0,10){
                ll p1 = lower_bound(pos[j].begin(), pos[j].end(), i) - pos[j].begin();
                ll p2 = upper_bound(pos[k].begin(), pos[k].end(), i) - pos[k].begin();
                if(p1 != 0 && p2 != pos[k].size()){
                    ll num = j * 100 + c * 10 + k;
                    cnt[num]++;
                    // print(num,i);
                }
            }
        }
    }
    rep(i,0,1000){
        if(cnt[i] > 0) ans++;
    }
    print(ans);


}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<bool> vb;

int main() {
  int h, w;
  cin >> h >> w;
  vector<vi> map(h + 2, vi(w + 2, -2));
  int whites = 0;
  rep(i, h) rep(j, w) {
    char c;
    cin >> c;
    if(c == '.') {
      whites++;
      map[i + 1][j + 1] = -1;
    }
  }
  vi di = {-1, 0, 0, 1};
  vi dj = {0, -1, 1, 0};
  map[1][1] = 0;
  queue<pair<int, int>> q;
  q.push(make_pair(1, 1));
  while(!q.empty()) {
    auto p = q.front();
    q.pop();
    rep(k, 4) {
      int ni = p.first + di[k];
      int nj = p.second + dj[k];
      if(map[ni][nj] == -1) {
        q.push(make_pair(ni, nj));
        map[ni][nj] = map[p.first][p.second] + 1;
      }
    }
  }
  cout << (map[h][w] > 0 ? whites - map[h][w] - 1 : -1) << endl;
}

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

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

Measured memory_bytes: 256
#define rep(i,x) for (int i = 0; i < x; i++)
#define mod 1000000007
#define MOD 998244353
#define inf 1e18
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <math.h>
#include <complex>
#include <cassert>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> p;
typedef complex<double> com;


int main(){
	int d, g;
	cin >> d >> g;
	vector<p> a(d);
	rep(i, d) {
		cin >> a[i].first >> a[i].second;
	}
	ll ans = inf;
	rep(i, 1 << d) {
		ll sub = 0,score=0,maxx=-1;
		rep(j, d) {
			if ((i >> j) & 1) {
				score += 100 * (j + 1)*a[j].first + a[j].second;
				sub += a[j].first;
			}
			else {
				maxx = j;
			}
		}
		if (score < g) {
			int j = 0;
			while (j < a[maxx].first && score<g) {
				score += 100 * (maxx + 1);
				sub++;
				j++;
			}
		}
		if (score >= g) {
			ans = min(ans, sub);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Text;

namespace AtTest.ABC_103
{
    class D
    {
        static void Main(string[] args)
        {
            Method(args);
            Console.ReadLine();
        }

        static void Method(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int n = int.Parse(input[0]);
            int m = int.Parse(input[1]);
            var request = new int[m][];
            for (int i = 0; i < m; i++)
            {
                string[] inText = Console.ReadLine().Split(' ');
                request[i] = new int[2];
                request[i][0] = int.Parse(inText[0]) - 1;
                request[i][1] = int.Parse(inText[1]) - 1;
            }

            List<int[]> check = new List<int[]>();
            Array.Sort(request, (a, b) => a[0] - b[0]);
            check.Add(request[0]);
            int nowIndex = 0;
            for (int i = 1; i < m; i++)
            {
                if (request[i][1] <= check[nowIndex][1])//内包
                {
                    check[nowIndex][0] = request[i][0];
                    check[nowIndex][1] = request[i][1];
                }
                else
                {
                    if (request[i][0] < check[nowIndex][1])//被り
                    {
                        check[nowIndex][0] = request[i][0];
                    }
                    else//独立
                    {
                        check.Add(request[i]);
                        nowIndex++;
                    }
                }
            }

            Console.WriteLine(check.Count);
        }
    }
}


Measured memory_bytes: 21572
N,A,B,C=[int(i) for i in input().split()]
l=[]
for i in range(N):
  l.append(int(input()))

def magic(cur,a,b,c):
  if cur==N:
    if a*b*c!=0:
      return abs(a-A)+abs(b-B)+abs(c-C)-30
    else:
      return 10**9
  r0=magic(cur+1,a,b,c)
  r1=magic(cur+1,a+l[cur],b,c)+10
  r2=magic(cur+1,a,b+l[cur],c)+10
  r3=magic(cur+1,a,b,c+l[cur])+10
  return min(r0,r1,r2,r3)

print(magic(0,0,0,0))

Measured memory_bytes: 3064
import sys
n,t = map(int, input().split())
a = []
b = []
m = []
for i in range(n):
    ai,bi = map(int, input().split())
    m.append((ai,bi))
m.sort()
###ソート
for i in range(n):
    a.append(m[i][0])
    b.append(m[i][1])
a_mx = max(a)
dp = [0]*(t+a_mx+1)
#dp2 = [i for i in range(t+a_mx)]##注文時間

for i in range(n):
    for s in range(t+a[i]-1,a[i]-1,-1):##時間制限
        if dp[s]<=dp[s-a[i]]+b[i]:
            dp[s] = dp[s-a[i]]+b[i]
#            dp2[s] = s-a[i]


        
print(max(dp))


Measured memory_bytes: 44976
#include <stdio.h>
#include <cstdlib>
#include <cassert>
#include <iostream>
#include <set>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <complex>
#include <map>
#include <queue>
#include <array>
#include <bitset>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef long double ld;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef vector<pii> vii;
typedef vector<string> vs;

void upd(vi & v, int x) {
  assert(x < v.size());
  vi nv(v.size(), 0);
  for (int i = 0; i < v.size(); ++i) {
    if (v[i]) {
      if (i >= x) nv[i-x] = 1;
      if (i + x < v.size()) nv[i+x] = 1;
    }
  }
  v.swap(nv);
}

int main() {
  std::ios::sync_with_stdio(false); std::cin.tie(0);
  string s;
  int x, y;
  cin >> s >> x >> y;
  assert(abs(x) <= (int)s.size() && abs(y) <= (int)s.size());
  vi v(1, 0);
  for (int i = 0; i < s.size(); ++i) {
    if (s[i] == 'F') ++v.back();
    else v.push_back(0);
  }
  x -= v[0];
  int N = s.size();
  vi a(2 * N + 1), b(2 * N + 1);
  a[N] = b[N] = 1;
  for (int i = 1; i < v.size(); ++i) {
    if (i % 2) upd(b, v[i]);
    else upd(a, v[i]);
  }
  x += N;
  y += N;
  if (x >= 0 && y >= 0 && x < (int)a.size() && y < (int)b.size() && a[x] && b[y]) {
    cout << "Yes\n";
  } else {
    cout << "No\n";
  }
  return 0;
}

Measured memory_bytes: 512
k = int(input())
ans = 0

import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)


for i in range(1, k+1):
    for j in range(1, k+1):
        for n in range(1, k+1):
            ans += gcd(i, j, n)
            
print(ans)

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

using namespace std;

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

// container util
#define all(x) (x).begin(), (x).end()

// typedef
typedef long long llint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

// constant
const int MOD = (int)1e9 + 7;
const int INF = (int)1e9;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double pi = 3.14159265358979323846;

// conversion
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

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

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

  int h, n;
  cin >> h >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }

  for (int i = 0; i < n; i++) {
    h -= a[i];
  }

  if (h <= 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}

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

int main(){
	int n;
	cin >> n;
	vector<int> d(n);
	rep(i, n)cin >> d[i];
	int sum = 0;

	for (int i = 0; i < n; i++) {
		for (int j = i; j < n; j++) {
			if (i == j) { continue; 
			}else {
				sum += d[i] * d[j];
			}
		}
	}

	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
    int n,y,sum;
    cin>>n>>y;
    for(int i = 0; i <= n; i++){
        for(int j = i; j <= n; j++){
            sum = 10000*(n - j) + 5000*(j - i) + 1000*i;
            if(sum == y){
                cout<<n-j<<" "<<j-i<<" "<<i<<endl;
                return 0;
            }
        }
    }
    cout<<-1<<" "<<-1<<" "<<-1<<endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		Map<List<Integer>, Integer> map = new HashMap<>();
		for(int i=1; i<=n; i++){
			String str= Integer.toString(i);
			char head = str.charAt(0);
			char tail = str.charAt(str.length()-1);
			List<Integer> list = new ArrayList<>();
			list.add(Integer.parseInt(String.valueOf(tail)));
			list.add(Integer.parseInt(String.valueOf(head)));
			if(!map.containsKey(list) && tail != '0'){		
				map.put(list, 0);
			}
		}
		for (List<Integer> key : map.keySet()) {
			int f = key.get(0);
			int l = key.get(1);
			for(int i=1; i<=n; i++) {
				String str= Integer.toString(i);
				char head = str.charAt(0);
				char tail = str.charAt(str.length()-1);
				if(f == Integer.parseInt(String.valueOf(head))
				   && l == Integer.parseInt(String.valueOf(tail))){
					map.put(key, map.get(key)+1);
				}
			}
		}
		int result = 0;
		for(int i=1; i<=n; i++) {
			String str= Integer.toString(i);
			char head = str.charAt(0);
			char tail = str.charAt(str.length()-1);
			List<Integer> list = new ArrayList<>();
			list.add(Integer.parseInt(String.valueOf(tail)));
			list.add(Integer.parseInt(String.valueOf(head)));
			if(tail != '0'){
				result += map.get(list);
			}
		}
		System.out.println(result);
	}
}


Measured memory_bytes: 314072
"use strict";

function Main(input) {
    let lines = input.split('\n')
    let N = lines[0].split(' ')[0] * 1
    let D = lines[0].split(' ')[1] * 1
    lines.shift()
    let ans = 0
  	// それぞれの行をバラす処理
    let line = lines.map((l) => {
        return l.split(' ')
    })
  	// 組み合わせのループ処理の常套句
  	for(let i = 0; i < N - 1; i++ ){
    	for(let j = i + 1; j < N; j++ ){
        	// 判定用の値
          	let t = 0;
          	// 次元に合わせた計算用のループ
			for(let k = 0; k < D; k++){
            	t += Math.pow((line[i][k] - line[j][k]),2);
            }
          	//平方根とって1で割ってあまりが出ないならそれは条件を満たしている
          	if(Math.sqrt(t) % 1 == 0){
            	ans++;
            }
        }
    }
 
  	console.log(ans)
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
#include<stdio.h>
#define MAX 10000
#define NIL -1
struct Node_struct{int p, l, r;}; /*p: 親(parent), l: 一番左の子(left child), r:右の兄弟(right sibling)*/
typedef struct Node_struct Node;
Node T[MAX];
 int D[MAX],H[MAX];

int max(int a,int b){
  if(a>b) return a;
  else return b;
}

int getSibling(int u){
  if(T[u].p==NIL) return NIL;
  if(T[T[u].p].l!=u && T[T[u].p].l!=NIL) return T[T[u].p].l;
  if(T[T[u].p].r!=u && T[T[u].p].r!=NIL) return T[T[u].p].r;
  return NIL;
}

void print(int u){
  int deg=0;
  if(T[u].l!=NIL) deg++;
  if(T[u].r!=NIL) deg++;
  printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, ", u, T[u].p,getSibling(u),deg,D[u],H[u]);
  if(T[u].p==NIL) printf("root\n");
  else if(T[u].l==NIL && T[u].r==NIL) printf("leaf\n");
  else printf("internal node\n");
}

void calcDepth(int u, int p){
  if(u==NIL) return ;
  D[u] = p;
  if(T[u].r!=NIL) calcDepth(T[u].r,p+1);
  if(T[u].l!=NIL) calcDepth(T[u].l,p+1);
}

int calcHeight(int u){
  int h1=0,h2=0;
  if(T[u].l!=NIL) h1=calcHeight(T[u].l)+1;
  if(T[u].r!=NIL) h2=calcHeight(T[u].r)+1;
  return H[u]=max(h1,h2);
}




int main(){
  int i, j, k;
  int n;
  int id,l,r;
  int root = 0;
  scanf("%d", &n);
  for(i=0; i<n; i++) T[i].p=NIL;
  
  for(i=0; i<n; i++){
    scanf("%d%d%d", &id,&l,&r);
      T[id].l = l;
      T[id].r=r;
      if(l!=NIL) T[l].p = id;
      if(r!=NIL) T[r].p = id;
  }

  //根を求める (find the root)
  for(i=0; i<n; i++){
    if(T[i].p == -1) root = i;
  }
  
  //それぞれのノードの高さ深さを求める (find depth of each node)
  calcHeight(root);
  calcDepth(root, 0);

  //出力 (output)
  for(i=0; i<n; i++) print(i);
  
  return 0;
}  



Measured memory_bytes: 2108
#include <bits/stdc++.h>
#define LL long long
#define PII pair<int,int>
#define PIII pair<int,PII>
#define PLL pair<LL,LL>
#define PLII pair<LL,PII>
#define VI vector<int>
#define FF first
#define SS second
#define MP make_pair
#define PB push_back
#define P1 31
#define EPS 0.00000000001
#define MOD int(10e9 + 9)
#define PI acos(-1)
#define INF 100000000
#define loop(i,b,n) for(int i=b;i<n;++i)
#define rev_loop(i,b,n) for(int i=b;i>=n;--i)
using namespace std;

int main()
{
    string s,s1="",s2="";
    cin>>s;
    int n = s.length(), f = 1;
    loop(i,0,n/2)
    {
        s1 += s[i]; s2+=s[n-i-1];
        if(s[i] != s[n-i-1]) {f = 0; break;}
    }

    if(f)
    {
        int n1 = n/2;
    loop(i,0,n1/2)
    {
        if(s1[i] != s1[n1-i-1]) {f = 0; break;}
        if(s2[i] != s2[n1-i-1]) {f = 0; break;}
    }
    }

    if(f) cout<<"Yes\n";
    else cout<<"No\n";

    return 0;
}


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

int main() {
    ll n, a, b;
    cin >> n >> a >> b;
    if (abs(b-a) % 2 == 0) {
        cout << (ll) abs(b-a)/2 << endl;
        return 0;
    }

    ll ans = min(a-1, n-b) + 1 + (b-a-1)/2;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3600
#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use itertools::Itertools;
use num::clamp;
use proconio::{input, marker::*, fastout};
use superslice::*;
use num_bigint::*;
use num_traits::{Zero, One};

#[fastout()]
fn main() {
    input! {
        n: usize,
        a: [u64; n]
    }
    let m = 1_000_000_007u64.to_biguint().unwrap();

    let mut l = a[0].to_biguint().unwrap();
    for &v in &a {
        l = lcm(l, v.to_biguint().unwrap());
    }

    let mut ans: BigUint = Zero::zero();
    for &v in &a {
        let v = v.to_biguint().unwrap();
        ans += l.clone() / v;
        ans %= m.clone();
    }
    println!("{}", ans);
}
#[allow(dead_code)]
pub fn gcd(a: BigUint, b: BigUint) -> BigUint {
    if b == Zero::zero() {
        a
    } else {
        gcd(b.clone(), a % b)
    }
}
#[allow(dead_code)]
pub fn lcm(a: BigUint, b: BigUint) -> BigUint {
    a.clone() / gcd(a, b.clone()) * b
}

Measured memory_bytes: 3132
use std::io::stdin;
use std::str::FromStr;
use std::collections::HashMap;
use std::cmp::max;

fn main(){
    let (r, c, k): (usize, usize, usize) = get_triple();
    let rcv = {
        let mut rcv = HashMap::new();
        for _ in 0..k {
            let (r, c, v): (usize, usize, usize) = get_triple();
            rcv.entry(r).or_insert(HashMap::new()).insert(c, v);
        }
        rcv
    };
    let mut field = {
        let mut field = Vec::new();
        for _ in 0..r+2 {
            let mut row = Vec::new();
            for _ in 0..c+2 {
                row.push(vec![0; 4]);
            }
            field.push(row);
        }
        field
    };

    for i in 1..r+1 {
        for j in 1..c+1 {
            for p in 0..4 {
                field[i][j+1][p] = max(field[i][j+1][p], field[i][j][p]);
                field[i+1][j][0] = max(field[i+1][j][0], field[i][j][p]);

                if p == 3 { continue; }
                if let Some(v) = rcv.get(&i).and_then(|cv| cv.get(&j)) {
                    field[i][j+1][p+1] = max(field[i][j+1][p+1], field[i][j][p] + v);
                    field[i+1][j][0] = max(field[i+1][j][0], field[i][j][p] + v);
                }
            }
        }
    }

    let v = rcv.get(&r).and_then(|cv| cv.get(&c)).unwrap_or(&0);

    println!("{}", max(field[r][c][0] + v, max(field[r][c][1] + v, max(field[r][c][2] + v, field[r][c][3]))));
}


#[allow(dead_code)]
fn get_line() -> String {
    let mut s = String::new();
    match stdin().read_line(&mut s){
        Ok(_) => {s.trim().to_string()}
        Err(_) => String::new()
    }
}

#[allow(dead_code)]
fn get_vec<T: std::str::FromStr>() -> Vec<T> {
    let line = get_line();
    line.split_whitespace().filter_map(|x| x.parse().ok()).collect()
}

#[allow(dead_code)]
fn get_one<T: FromStr + Copy>() -> T {
    let v = get_vec();
    v[0]
}

#[allow(dead_code)]
fn get_pair<T: FromStr + Copy>() -> (T, T) {
    let v = get_vec();
    (v[0], v[1])
}

#[allow(dead_code)]
fn get_triple<T: FromStr + Copy>() -> (T, T, T) {
    let v = get_vec();
    (v[0], v[1], v[2])
}

#[allow(dead_code)]
fn get_chars() -> Vec<char> {
    get_line().chars().collect()
}

#[allow(dead_code)]
fn vec_min(xs: &Vec<i64>) -> i64 {
    xs.iter().map(|&x|x).fold(std::i64::MAX, std::cmp::min)
}

#[allow(dead_code)]
fn vec_max(xs: &Vec<i64>) -> i64 {
    xs.iter().map(|&x|x).fold(std::i64::MIN, std::cmp::max)
}

#[allow(dead_code)]
fn vec_sum(xs: &Vec<i64>) -> i64 {
    xs.iter().fold(0, |acc, &x| acc+x)
}


Measured memory_bytes: 654500
#include <bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
#define eps 1e-9

typedef long long ll;

using namespace std;

const ll inf = 1e18;
const ll mod = 1e9+7;
const int N = 1e5+5;
//int a[N];

int main()

{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

    int n, tmp, x = 0, y = 0;

    cin >> n;

    for (int i = 0; i < n; i++) {

        cin >> tmp;

        if (tmp%4 == 0) x++;
        else if (tmp%4 == 2) y++;
    }

    if (n <= 2*x+(y==0)+y) cout << "Yes";
    else cout << "No";

    return 0;
}


Measured memory_bytes: 256
n=int(input())
p=list(map(int,input().split()))
ans=0
cnt=0
for i in range(n):
    if p[i]==i+1:
        cnt+=1
        if cnt==2:
            ans+=1
            cnt=0
    elif cnt==1:
        ans+=1
        cnt=0
if cnt==1:
    ans+=1
print(ans)

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

using namespace std;
using ll = long long;
using ii = pair<ll, ll>;

const int MAX { 200010 };
const ll MOD { 1000000007 }, oo { 1LL << 62 };

ll solve(int N, const vector<ll>& xs)
{
    return 0;
}

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

    int a;
    cin >> a;

    cout << (a + a*a + a*a*a) << '\n';

    return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<(n);i++)
#define MOD 1000000007
#define all(n) (n).begin(),(n).end()
typedef long long ll;
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}else{return 0;}}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}else{return 0;}}
template <class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <class T> inline T LCM(T a,T b){return a*b/GCD(a,b);}

int main(){
	int n;
	bool ans=1;
	string s;
	cin >> n;
	
	cin >> s;
	if(n%2==1){
		ans=0;
	}

	FOR(i,n/2){
		if(s[i]!=s[n/2+i]){ans=0;}
	}

	if(ans){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//define
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define SUB(a, b) a = (a+mod-b)%mod
#define MUL(a, b) a = (a * b) % mod
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define fi first
#define se second
// 許容する誤差ε
#define EPS (1e-10)
// 2つのスカラーが等しいかどうか
#define EQ(a,b) (abs((a)-(b)) < EPS)
// 2つのベクトルが等しいかどうか
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
//template
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p){
  os << "(" << p.first << "," << p.second << ")";return os;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v){
  for (auto it = v.begin();it != v.end();++it){
    if(it != v.begin())os << " ";os << *it;
      }return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &mp){
  for(auto x: mp)os << "(" << x.first << "," << x.second << ")" << endl;
  return os;
}
template<typename T, int SIZE>
int array_length(const T (&)[SIZE]){return SIZE;}
template<typename T, int N>
void PRINTF(const T (&a)[N], int s = N, int t = -1, bool f = true){
	if(t == -1){rep(i,s){if(i)cout << " ";cout << a[i];}}
	else repi(i,s,t){if(i!=s)cout << " ";cout << a[i];}
	if(f)cout << "\n";
}
template<typename T, int N1, int N2>
void PRINTF(const T (&a)[N1][N2], int h = N1, int w = N2){
	rep(i,h){rep(j,w){cout << a[i][j] << " \n"[j==w-1];}}
}
//typedef
typedef complex<double> Point;
typedef pair<int,int> P;
typedef pair<int, P> PP;
typedef pair<P, int> Pi;
typedef vector<int> vi;
typedef deque<int> dq;
const int inf = 1e9+7;
const int INF = 1e18+7;



const int MAX = 300000;
int dp[MAX+1];
signed main(){
  int n, q;
  scanf("%lld%lld", &n, &q);
  rep(i,n){
    int x;
    scanf("%lld", &x);
    dp[x] = x;
  }
  rrep(i,MAX)chmax(dp[i], dp[i-1]);
  rep(_,q){
    int x;
    scanf("%lld", &x);
    int ans = 0;
    for(int i = x-1;i <= MAX;i += x)chmax(ans, dp[i]%x);
    chmax(ans, dp[MAX]%x);
    printf("%lld\n", ans);
  }
	return 0;
}











Measured memory_bytes: 5536
n, m, c = gets.split.map(&:to_i)
b_m = gets.split.map(&:to_i)
a_m = n.times.map{ gets.split.map(&:to_i) }
ans = 0
a_m.each do |a|
    ans += 1 if a.zip(b_m).map{ |aa, bb| aa * bb }.reduce(:+) + c > 0
end
puts ans

Measured memory_bytes: 3836
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int> 
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
int n,ok;
int g[210][210];
bool vis[210];
int c[210];
void dfs(int v,int co){
    if(!ok) return;
    for(int i=0;i<n;i++){
        if(!g[i][v]) continue;
        if(vis[i] && c[i]!=co){
            ok=0;
            return;
        }
        if(!vis[i]){
            c[i]=co;
            vis[i]=1;
            dfs(i,1-co);
        }
    }
}
int dep[210][210];
void dfs2(int v,int now){
    for(int i=0;i<n;i++)
        if(g[v][i]){
            if((dep[now][i] || i==now) && dep[now][i]<=dep[now][v]+1) continue;
            dep[now][i]=dep[now][v]+1;
            dfs2(i,now);
        }
}
int dist[210][210];
int main(){
    cin>>n;
    for(int i=0;i<n;i++){
        char s[210];
        scanf("%s",s);
        for(int j=0;j<n;j++){
            g[i][j]=s[j]-'0';
            if(i!=j) dist[i][j]=(g[i][j])?1:1000000000;
        }
    }
    vis[0]=1;
    c[0]=0;
    ok=1;
    dfs(0,1);
    if(ok){
        for(int k=0;k<n;k++)
            for(int i=0;i<n;i++)
                for(int j=0;j<n;j++)
                    if(dist[i][k]+dist[k][j]<dist[i][j])
                        dist[i][j]=dist[i][k]+dist[k][j];
        int ans=0;
        for(int i=0;i<n;i++)
            for(int j=0;j<n;j++)
                ans=max(ans,dist[i][j]+1);
        cout<<ans<<endl;
    }
    else
        puts("-1");
    return 0;
}

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

using ll = int64_t;
#define int ll

#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(i, 0, b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(), x.end()

using pi = pair<int, int>;
using vi = vector<int>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  REP(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

ll read() {
  ll i;
  scanf("%" SCNd64, &i);
  return i;
}

void printSpace() { printf(" "); }

void printEoln() { printf("\n"); }

void print(ll x, int suc = 1) {
  printf("%" PRId64, x);
  if (suc == 1)
    printEoln();
  if (suc == 2)
    printSpace();
}

string readString() {
  static char buf[3341000];
  scanf("%s", buf);
  return string(buf);
}

char *readCharArray() {
  static char buf[3341000];
  static int bufUsed = 0;
  char *ret = buf + bufUsed;
  scanf("%s", ret);
  bufUsed += strlen(ret) + 1;
  return ret;
}

template <class T, class U> void chmax(T &a, U b) {
  if (a < b)
    a = b;
}

template <class T, class U> void chmin(T &a, U b) {
  if (b < a)
    a = b;
}

template <class T> T Sq(const T &t) { return t * t; }

const int mod = 1e9 + 7;

signed main() {
  int n = read();
  std::cout << "ABC" << n << std::endl;
}


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

#define F first
#define S second

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

const int N = 510, M = 35, INF = 0x3f3f3f3f;

int n, m;
int c[M][M];
int cnt[3][M];

int main()
{
	cin >> n >> m;
	for (int i = 1; i <= m; i ++ )
		for (int j = 1; j <= m; j ++ )
			cin >> c[i][j];
	for (int i = 1; i <= n; i ++ )
		for (int j = 1; j <= n; j ++ )
		{
			int x;
			cin >> x;
			cnt[(i + j) % 3][x] ++ ;
		}
	
	LL res = 1e18;
	for (int i = 1; i <= m; i ++ )
		for (int j = 1; j <= m; j ++ )
			for(int k = 1; k <= m; k ++ )
				if (i != j && j != k && k != i)
				{
					LL t = 0;
					for (int u = 1; u <= m; u ++ )
					{
						t += (LL)cnt[0][u] * c[u][i];
						t += (LL)cnt[1][u] * c[u][j];
						t += (LL)cnt[2][u] * c[u][k];
					}
					res = min(res, t);
				}
	
	cout << res << endl;
	return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n), b(n), c(n-1);
  for(int i=0; i<n; i++) 
    cin >> a.at(i);
  for(int i=0; i<n; i++)
    cin >> b.at(i);
  for(int i=0; i<n-1; i++)
    cin >> c.at(i);
    
  int answer = b.at(a.at(0)-1);
  
  for(int i=1; i<n; i++) {
    answer += b.at(a.at(i)-1);
    if(a.at(i) - a.at(i-1) == 1)
      answer += c.at(a.at(i-1)-1);
  }
  
  cout << answer << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
long long n,a[200100];
long long f(long long x)
{
	long long k=50,ans=0;
	while(x>=k)
	{
		ans+=x/k;
		k*=5;
	}
	return ans; 
}
int main()
{
	cin>>n;
	if(n%2==1)
	{
		cout<<0<<endl;
		return 0;
	}
	cout<<n/10+f(n)<<endl;
}

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

int main() {
  int64_t A, B, C, K;
  cin >> A >> B >> C >> K;

  if (A >= K) {
    cout << K << endl;
  }
  else if ((A + B) >= K) {
    cout << A << endl;
  }
  else {
    cout << A - (K - A - B) << endl;
  }
}

Measured memory_bytes: 3632
using System;
using System.Collections;
using System.Linq;

public class MainApp
{
    static public void Main(string[] args)
    {
        int N = int.Parse(Console.ReadLine());
        string S = Console.ReadLine();
        string temp = S;
        for (;;)
        {
            int delete = temp.IndexOf("()");
            if (delete != -1)
            {
                temp = temp.Substring(0, delete) + temp.Substring(delete + 2);

            }
            else break;

        }
        int hidarikakko = 0;
        int migikakko = 0;
        for (int c = 0; c < temp.Length; c++)
        {
            if (temp[c] == ')') hidarikakko++;
            else
            {
                migikakko = temp.Length - c;
                break;
            }
        }

        string hidari = "";
        string migi = "";
        for (int c = 0; c < hidarikakko; c++) hidari += "(";
        for (int c = 0; c < migikakko; c++) migi += ")";
        Console.WriteLine(hidari + S + migi);


    }
    

}

Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
int main(){
  double N,K,i,j=0,num,mnum=0;
  cin >> N >> K;
  vector<double> p(N);

  for(i=0;i<N;i++){
    int n;
    cin >> n;
    num = (1 + n) * n / 2;
    num = num/n;
    p.at(i)= num;
  }
  for(i=0;i<K;i++)
    mnum += p.at(i);
  num = mnum;

  for(i=K;i<N;i++){
    num = num+p.at(i)-p.at(j);
    mnum = max(mnum,num);
    ++j;
  }
  cout << setprecision(10) << mnum;
}


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

class Program
{
  public static void Main(string[] args)
  {
    int n = int.Parse(Console.ReadLine());
    int[] s = Console.ReadLine().Split().Select(int.Parse).ToArray();
    Array.Sort(s);
    Array.Reverse(s);
    Console.WriteLine(s.Where((value, index) => index % 2 == 0).Sum() - s.Where((value, index) => index % 2 == 1).Sum());
  }
}


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

using namespace std;

typedef long double ld;

ld pi = 3.14159265359;
ld po = 180.000;
int main()
{
    ld a,b,x;
    cin >> a >> b >> x;

    //x *= 2;
    //x /= a;


    if(a*a*b >= x*2){
        ld ans = (long double)atan(( (b*b*a)/(x*2) ));
        ans *= (po/pi);
        cout << fixed << setprecision(10) << ans << endl;
    }
    else{
        ld tr = (a*b - (x/a));
        tr *=2;
        tr/=a;
        ld ans = (long double)atan( tr/a );
        ans *= (po/pi);
        cout << fixed << setprecision(10) << ans << endl;
    }

}


Measured memory_bytes: 256
package main

import (
  "bufio"
  "os"
  "strconv"
  "fmt"
)

func Get() (int, []byte) {
  r := bufio.NewReaderSize(os.Stdin, 1000000)
  l, _, _ := r.ReadLine()
  n, _ := strconv.Atoi(string(l))

  bs, _, _ := r.ReadLine()

  return n, bs
}

func Search(n int, oxs []byte) {
  as := []byte { 'S', 'W' }
  for _, a := range as {
    for _, b := range as {
      ps := make([]byte, n)
      ps[0] = a
      ps[1] = b

      for i := 2; i < n; i++ {
        ox := oxs[i-1]
        l := ps[i-1]
        ll := ps[i-2]

        if ox == 'o' {
          if l == 'S' {
            if ll == 'S' {
              ps[i] = 'S'
            } else {
              ps[i] = 'W'
            }
          } else {
            if ll == 'S' {
              ps[i] = 'W'
            } else {
              ps[i] = 'S'
            }
          }
        } else {
          if l == 'S' {
            if ll == 'S' {
              ps[i] = 'W'
            } else {
              ps[i] = 'S'
            }
          } else {
            if ll == 'S' {
              ps[i] = 'S'
            } else {
              ps[i] = 'W'
            }
          }
        }
      }


      // check
      ok := false
      for i := 0; i < n; i++ {
        var m,l,r byte
        m = ps[i]
        if i == 0 {
          l = ps[n - 1]
          r = ps[i + 1]
        } else if i == n - 1 {
          l = ps[i - 1]
          r = ps[0]
        } else {
          l = ps[i - 1]
          r = ps[i + 1]
        }
        ox := oxs[i]

        if ox == 'o' {
          if m == 'S' {
            if r == l {
              ok = true
            } else {
              ok = false
            }
          } else {
            if r == l {
              ok = false
            } else {
              ok = true
            }
          }
        } else {
          if m == 'S' {
            if r == l {
              ok = false
            } else {
              ok = true
            }
          } else {
            if r == l {
              ok = true
            } else {
              ok = false
            }
          }
        }

        if !ok {
          break
        }
      }

      if ok {
        fmt.Println(string(ps))
        return
      }
    }
  }

  fmt.Println(-1)
}

func main() {
  Search(Get())
}


Measured memory_bytes: 1408
#include<cstdio>
#include<algorithm>

using namespace std;

class Graph{
    int n;
    int **G;
    int *seen;
    int *todo;
    int *next;
    int *dist;
    const int MAX = 101;
    public: Graph(int _n){
        n = _n;
        G = new int*[n+1];
        seen = new int[n+1];
        todo = new int[n+1];
        next = new int[n+1];
        dist= new int[n+1];
        for(int i = 0;i <=n;++i){
            G[i] = new int[n+1];
            seen[i] = 0;
            todo[i] = 0;
            next[i] = 0;
            dist[i] = MAX;
        }
        for(int i = 0;i <= n;++i){
            for(int j = 0;j <= n;++j){
                G[i][j] = 0;
            }
        }
    }
    
    public: void BuildMatrix(){
        int u,k,v;
        for(int i = 0;i < n;++i){
            scanf("%d %d",&u,&k);
            for(int j = 0;j < k;++j){
                scanf("%d",&v);
                G[u][v] = 1;
            }
        }
    }
    
    public: void PrintMatrix(){
        for(int i = 1;i <= n;++i){
            for(int j = 1;j <n;++j){
                printf("%d ",G[i][j]);
            }
            printf("%d\n",G[i][n]);
        }
    }
    
    
   public: void DoBFS(){
        dist[1] = 0;
        todo[1] = 1;
        while(!isEmpty(todo)){
            for(int i = 1;i <= n;++i){
                if(todo[i] == 1) BFS(i,dist[i]);
            }
            for(int i = 1;i <= n;++i) swap(todo[i],next[i]);
        }
        for(int i = 1;i <= n;++i) printf("%d %d\n",i,(dist[i] != MAX) ? dist[i]:-1);
    }
    void BFS(int s,int cnt){
        cnt++;
        todo[s] = 0;
        seen[s] = 1;
        for(int i = 1;i <= n;++i){
            if(G[s][i]  == 1){
                dist[i] = std::min(dist[i],cnt);
                if(seen[i] != 1) next[i] = 1;
            }
        }
    }
    
    bool isEmpty(int* l){
        for(int i = 1;i <= n;++i){
            if(l[i] != 0) return false;
        }
        return true;
    }
    
};

int main(){
    int n;
    scanf("%d",&n);
    Graph G(n);
    G.BuildMatrix();
    G.DoBFS();
}





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

#define int long long

#define inf 1000000007LL
#define mod 1000000007LL

#define rep(i, n) for(int i = 0; i < (n); i++)
#define trep(i, n) for(int i = 0; i <= (n); i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define mfor(i, s, t) for(int i = (s); i < (t); i++)
#define tfor(i, s, t) for(int i = (s); i <= (t); i++)
#define rfor(i, s, t) for(int i = (t) - 1; i >= (s); i--)

int k[514];
bool ok[514];
vector<int> v[514];

bool okok[114514];
pair<int, int> f[114514];

void dfs(int p) {
  if(!ok[p]) {
    ok[p] = true;
    for(auto i : v[p]) {
      okok[i] = true;
      dfs(f[i].first);
      dfs(f[i].second);
    }
  }
}

signed main() {
  int n, h;
  cin >> n >> h;
  rep(i, (h + 10) * 2) {
    k[i] = 0;
    ok[i] = false;
  }
  rep(i, n) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if(c == 0) {
      v[a].push_back(i);
      k[a]++;
      f[i].first = a;
    }
    else {
      v[c + h + 10].push_back(i);
      k[c + h + 10]--;
      f[i].first = c + h + 10;
    }
    if(d == 0) {
      v[b + h + 10].push_back(i);
      k[b + h + 10]++;
      f[i].second = b + h + 10;
    }
    else {
      v[d].push_back(i);
      k[d]--;
      f[i].second = d;
    }
  }
  rep(i, (h + 10) * 2) {
    if(k[i] < 0) {
      cout << "NO" << endl;
      return 0;
    }
  }
  rep(i, n) {
    okok[i] = false;
  }
  rep(i, (h + 10) * 2) {
    if(k[i] > 0) {
      dfs(i);
    }
  }
  rep(i, n) {
    if(!okok[i]) {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
}


Measured memory_bytes: 4864