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

#define show(x) cerr << #x << " = " << x << endl

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v)
{
    os << "sz:" << v.size() << "\n[";
    for (const auto& p : v) {
        os << p << ",";
    }
    os << "]\n";
    return os;
}

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


constexpr ll MOD = (ll)1e9 + 7LL;

template <typename T>
constexpr T INF = numeric_limits<T>::max() / 100;

using P = pair<ll, ll>;


int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    ll Z, W;
    cin >> Z >> W;
    vector<ll> a(N + 2);
    a[0] = Z;
    a[1] = W;
    for (int i = 0; i < N; i++) {
        cin >> a[i + 2];
    }
    vector<vector<P>> dp(N + 2, vector<P>(N + 2, make_pair(INF<ll>, -INF<ll>)));  // 手持ちが(a[i],a[j])から初めたときのスコア(Max,Min)
    vector<vector<ll>> first_mini(N + 2, vector<ll>(N + 2, INF<ll>));
    vector<vector<ll>> second_maxi(N + 2, vector<ll>(N + 2, -INF<ll>));
    for (int i = 0; i < N + 1; i++) {
        dp[i][N + 1] = make_pair(abs(a[i] - a[N + 1]), abs(a[i] - a[N + 1]));
        first_mini[i][N + 1] = abs(a[i] - a[N + 1]);
        second_maxi[i][N + 1] = abs(a[i] - a[N + 1]);
    }
    for (int i = N; i >= 0; i--) {
        for (int j = N; j > i; j--) {
            ll maxi = second_maxi[j][j + 1];
            ll mini = first_mini[j][j + 1];
            second_maxi[i][j] = max(second_maxi[i][j + 1], mini);
            first_mini[i][j] = min(first_mini[i][j + 1], maxi);
            dp[i][j] = make_pair(maxi, mini);
        }
    }
    cout << dp[0][1].first << endl;


    return 0;
}


Measured memory_bytes: 125824
#include <iostream>

using namespace std;
#define MAX 100000
typedef long long llong;

int n, k;
llong T[MAX];

int check(llong P) {
    int i = 0;
    for (int j = 0; j < k; ++j) {
        llong s = 0;
        while (s + T[i] <= P) {
            s += T[i];
            i++;
            if (i == n) return n;
        }
    }
    return i;
}

int solve() {
    llong left = 0;
    llong right = 100000 * 10000;
    llong mid;
    while (right - left > 1) {
        mid = (left + right) / 2;
        int v = check(mid);
        if (v >= n) right = mid;
        else left = mid;
    }
    return right;
}

int main(){
    cin >> n >> k;
    for (int i = 0; i < n; ++i) {
        cin >> T[i];
    }
    llong ans = solve();
    cout << ans << endl;
}


Measured memory_bytes: 3876
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define MAX 2000000
#define MOD 1000000007

int main(){
  int H,W;
  cin>>H>>W;
  vector<vector<char>> a(H+1,vector<char>(W+1,'#'));
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cin>>a.at(i+1).at(j+1);
    }
  }

  vector<vector<int>> dp(H+1,vector<int>(W+1,0));
  dp.at(1).at(1)=1;
  for(int i=1;i<=H;i++){
    for(int j=1;j<=W;j++){
      if(a.at(i).at(j)=='#'){
        continue;
      }
      if(a.at(i-1).at(j)=='.'){
        dp.at(i).at(j)+=dp.at(i-1).at(j);
      }
      if(a.at(i).at(j-1)=='.'){
        dp.at(i).at(j)+=dp.at(i).at(j-1);
      }
      dp.at(i).at(j)%=MOD;
    }
  }

  cout<<dp.at(H).at(W)<<endl;
}


Measured memory_bytes: 5248
#include <iostream>
#include<string>
#include<cmath>
#include<ciso646>
#include<cstring>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<utility>
#include<map>
#include<math.h>

using ll = long long;


using namespace std;
int main()
{
	int n;
		cin >> n;
		vector<int> zy(n);
		vector<int> x(n);
		vector<int> y(n);
		int cnt = 1;
		for (int i = 0;i < n;i++) {
			cin >> x[i];
			cin >> y[i];
			zy[i] = i;
			cnt *= i + 1;
		}
		long double sum = 0;
		do {
			long double len;
			for (int i = 1;i < n;i++) {
				int ky_x = x[zy[i - 1]] - x[zy[i]];
				int ky_y = y[zy[i - 1]] - y[zy[i]];
				int dd = (ky_x * ky_x) + (ky_y * ky_y);
				len = pow(dd, 0.5);
				sum += len;
			}
		} while (next_permutation(zy.begin(), zy.end()));
		cout << setprecision(12)<<sum / cnt;
}



Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
	long long int a, b, c,k,sum=0;
	
	scanf("%lld %lld %lld %lld", &a, &b, &c, &k);

	if (k >= a) {
		sum += a;
		k -= a;
	}
	else {
		sum += k;
		printf("%lld", sum);
		return 0;
	}
	if (k >= b) {
		k -= b;
	}
	else {
		printf("%lld", sum);
		return 0;
	}
	if (k >= c) {
		sum -= k;
		k -= c;
		printf("%lld", sum);
	}
	else {
		sum -= k;
		printf("%lld", sum);
	}

	return 0;
}

Measured memory_bytes: 1732
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FFOR(i,a,b) for(int i=(a);i<=(b);i++)
#define REP(i,b) FOR(i,0,b)
#define RREP(i,b) FFOR(i,1,b)
#define PB push_back
#define F first
#define S second
#define BE(c) c.begin(),c.end()
using namespace std;
typedef long long LL;
typedef LL ut;
typedef long double ld;
typedef pair<ut,ut> pr;
typedef vector<pr> Vpr;
typedef vector<ut> VI;
typedef pair<ut,pr> ppr;
typedef priority_queue<pr,Vpr, greater<pr> > PQ;
const int SIZE=5+3*1e+4;
const ut INF=1<<30;
const ld eps=1e-6;
const LL mod=7+1e+9;

int memo[30][2 << 17];
int A[32], B[32], N, C;

int rec(int n, int p){
	if(n >= N)
		return 0;

	if(memo[n][p] != -1)
		return memo[n][p];
	
	int res = 0;
	int t = p | A[n];
	REP(i,C){
		res = max(res, rec(n + 1, t & ~B[i]) + __builtin_popcount(t & B[i]));
	}
	return memo[n][p] = res;
}

int main(){
	int a, b;
	while(cin >> N >> C && (N || C)){
		memset(memo, -1, sizeof(memo));
		memset(A, 0, sizeof(A));
		memset(B, 0, sizeof(B));
		REP(i,N){
			REP(j,16){
				cin >> a;
				A[i] |= (a << j);
			}
		}
		REP(i,C){
			REP(j,16){
				cin >> b;
				B[i] |= (b << j);
			}
		}
		B[C] = 0;
		C++;
		cout << rec(0, 0) << endl;
	}
}

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

int main()
{
  string s, cmd; cin >> s;
  int n, begin_i, end_i; cin >> n;

  rep(i, n){
    cin >> cmd;
    if(cmd == "print") {
      cin >> begin_i >> end_i;
      // cout << s.substr(begin_i, end_i) << endl;
      for (int j = begin_i; j < end_i+1; j++) {
        cout << s[j];
      }
      cout << endl;
      // cout << "debug print " << s << endl;
    } else if(cmd == "reverse") {
      cin >> begin_i >> end_i;
      string tmp;
      for (int j = begin_i; j < end_i+1; j++) {
        tmp += s[j];
      }
      // cout << "debug reverse tmp " << tmp << endl;
      reverse(tmp.begin(), tmp.end());
      for (int j = begin_i, k=0; j < end_i+1; j++, k++) {
        s[j] = tmp[k];
      }
      // cout << "debug reverse " << s << endl;
    } else {
      string rep_s; cin >> begin_i >> end_i >> rep_s;
      // s.replace(begin_i, end_i, rep_s);
      for (int j = begin_i, k=0; j < end_i+1; j++, k++) {
        s[j] = rep_s[k];
      }
      // cout << "debug replace " << s << endl;
    }
  }
  return 0;
}


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

#define SIZE 50000

int main(void) {
    int prime[SIZE + 1] = {};
    int p[SIZE] = {};
    int len = 0;
    int n;
    
    for(int i = 2; i <= SIZE; ++i) {
        if(prime[i] != 0)   continue;
        
        int j = i * 2;
        while(j <= SIZE) {
            ++prime[j];
            j += i;
        }
        
        p[len] = i;
        ++len;
    }
    
    while(cin >> n) {
        if(n == 0)   break;
        
        int ans = 0;
        
        int i = 0;
        while(p[i] <= n / 2) {
            if(prime[n - p[i]] == 0) {
                ++ans;
            }
            ++i;
        }
        
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3484
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
#define rep(i, a, b) for (int i = a; i < b; ++i)

int main(){
int r,g,b;
cin>>r>>g>>b;

int sum=0;
sum= 100*r+10*g+b;
if(sum%4==0) cout<<"YES"<<endl;
else cout<<"NO"<< endl;
return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define VSORT(v) sort(v.begin(), v.end())
#define DVSORT(v) sort(v.begin(), v.end(),greater<int>())
#define SORT(v, n) sort(v, v+n)
#define DSORT(v,n) sort(v, v+n,greater<int>())
#define vi vector<int>
#define pb push_back
#define P pair<int,int>


template <class T> void chmin(T&a, const T&b) { a = min(a,b); }
template <class T> void chmax(T&a, const T&b) { a = max(a,b); }

const double EPS =1e-9;
const long INF =999999999;
const long MOD =1000000007; //10^9+7
#define PI 3.14159265258979

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

int main(){
	string A,B;
	int flug=0;
	cin>>A>>B;

	if(A.length()>B.length()) flug=1;
	else if(A.length()<B.length()) flug=2;
	else{
		if(A>B) flug=1;
		else if(A<B) flug=2;
		else flug=3;
	}

	switch(flug){
		case 1:
			puts("GREATER");
			break;
		case 2:
			puts("LESS");
			break;
		case 3:
			puts("EQUAL");
			break;
	}
	return 0;
}



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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string  N;
  cin>>N;
  if(N.at(0)=='7'||N.at(1)=='7'||N.at(2)=='7'){
  cout<<"Yes"<<endl;
  
  }
  else{
  cout<<"No"<<endl;
  }
}


Measured memory_bytes: 3624
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<numeric>
#include<vector>
#include<cmath>
#include<set>
using namespace std;
int main() {
	int n;
	cin >> n;
	vector<int> a(n), b(n);
	for(int i = 0; i < n; ++i) {
		cin >> a[i];
		b[i] = a[i];
	}
	sort(a.begin(), a.end());
	int ma = a[n - 1], nma = a[n - 2];
	for(int i = 0; i < n; ++i) {
		if(b[i] == ma) {
			cout << nma << endl;
		}
		else {
			cout << ma << endl;
		}
	}
}

Measured memory_bytes: 4848
#include<stdio.h>

int main(){
	int ans=0,n,m,c,b[20],a[20][20],i,j;
	scanf("%d%d%d",&n,&m,&c);
	for(i=0;i<m;i++)scanf("%d",&b[i]);
	for(i=0;i<n;i++){
		for(j=0;j<m;j++){
			scanf("%d",&a[i][j]);
		}
	}
	for(i=0;i<n;i++){
		int tmp=c;
		for(j=0;j<m;j++)tmp+=a[i][j]*b[j];
		if(tmp>0)ans++;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

int main()
{
  int flag=1, n, temp;
  int A[100];   //Array
  int i, count=0;   //loop counter variable

  scanf("%d", &n);

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

  while( flag ){
    flag = 0;
    for( i = n-1 ; i >= 1 ; i-- ){
      if( A[i] < A[i-1] ){
	temp = A[i-1];
	A[i-1] = A[i];
	A[i] = temp;
	flag = 1;
	count++;
      }
    }
  }
  
  for( i = 0 ; i < n ; i++ ){
    printf("%d", A[i]);
    if( i != (n-1) ) printf(" ");
  }

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

  return 0;
}

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

int n, maxn = 0, minn = 1000000001;

int main() {
  int x;
  cin >> n;
  for(int i = 0; i < n; ++i) {
    cin >> x;
    if(maxn < x) maxn = x;
    if(minn > x) minn = x;
  }

  cout << maxn - minn << endl;
  return 0;
}

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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define MP make_pair
#define PB push_back
const int INF = (1LL<<30);
const ll LLINF = (1LL<<60);
const double PI = 3.14159265359;
const double EPS = 1e-12;
const int MOD = 1000000007;
#define int ll

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }

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

signed main(void)
{
  int n;
  cin >> n;
  FOR(i, 1, 3501) FOR(j, 1, 3501) {
    if(4*i*j-n*i-n*j == 0) continue;
    int k = n*i*j/(4*i*j-n*i-n*j);
    // cout << i << " " << j << " " << k << " " << 4*i*j*k << " " << n*(i+j+k) << endl;
    if(1 <= k && 4LL*i*j*k == n*(i*j+j*k+k*i)) {
      cout << i << " " << j << " " << k << endl;
      return 0;
    }
  }
  assert(false);

  return 0;
}


Measured memory_bytes: 764
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>
#include <set>

using namespace std;
typedef long long ll;
#define rep(i, s, e) for (int(i) = (s); (i) <= (e); ++(i))
#define all(x) x.begin(),x.end()


int main()
{
	ll n, k; cin >> n >> k;
	vector<vector<ll>> pk(4005, vector<ll>(4005, 0));
	pk[0][0] = 1;
	ll M = 1000000007;
	rep(i, 0, 4000)rep(j, 0, 4000)
	{
		pk[i + 1][j] = (pk[i][j] + pk[i + 1][j]) % M;
		pk[i][j + 1] = (pk[i][j] + pk[i][j + 1]) % M;
	}
	rep(i, 1, k)
	{
		if (n - k + 1 < i)cout << 0 << endl;
		else cout << pk[n - k + 1 - i][i] * pk[k - i][i - 1] % M << endl;
	}
}

Measured memory_bytes: 125696
cards = {"a" : [input(), 0], "b" : [input(), 0], "c" : [input(), 0]}

turn = "a"
while True:
    cur = cards[turn]
    if cur[1] == len(cur[0]):
        print(turn.upper())
        break
    cards[turn][1] += 1
    turn = cur[0][cur[1] - 1]


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
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; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b 

signed main(){
	string s; cin>>s;
	string t; cin>>t;
	int n=s.size();
	if(s==t){
		cout<<"Yes"<<endl;
		return 0;
	}
	else{
		rep(i,0,n){
			string c;
			c.push_back(s[n-1]);
			s.insert(0,c);
			s.pop_back();
			if(s==t){
				cout<<"Yes"<<endl;
				return 0;
			}
		}
		cout<<"No"<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rrepi(i,a,b) for(int i=((int)(b)-1);i>=(a);--i)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) rrepi(i,0,n)
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define ZERO(x) memset(x,0,sizeof(x))
#define MINUS(x) memset(x,-1,sizeof(x))
#define UNIQUE(x) (x).erase(unique(ALL(x)), (x).end())
#define debug(var)  do{std::cout << #var << " : "; view(var);}while(0)
#define fi first
#define se second
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){for(const auto& v : vv){ view(v); } }
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void viewarr(T arr[], int n) { for(int i = 0; i < n; ++i) std::cout << arr[i] << " "; std::cout << std::endl; }
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; }
ll qp(ll a,ll b){ll ans=1;do{if(b&1)ans=1ll*ans*a;a=1ll*a*a;}while(b>>=1);return ans;}
ll qp(ll a,ll b,ll mo){ll ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const int INF = 1e9;
const ll INFL = 1e18;
const int MOD = 1e9 + 7;
const int MAX_N = 1e5;

int main() {
    int N, P;
    string S;
    cin >> N >> P >> S;
    if(P == 2 || P == 5) {
        ll ans = 0;
        rep(i,N) {
            if((S[i]-'0')%P == 0) ans += i+1;
        }
        cout << ans << endl;
        return 0;
    }
    vector<int> U(N+1, 0);
    for(int i = N-1, p = 1; i >= 0; --i, (p *= 10) %= P) {
        U[i] = ((S[i]-'0')*p + U[i+1]) % P;
    }
    vector<int> cnt(P, 0);
    ll ans = 0;
    rep(i,N) {
        ++cnt[U[i]];
        ans += cnt[U[i]] + (U[i] == 0 ? 0 : -1);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1412
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <string>
using namespace std;
long long gcd(long long a,long long b){
	if(a<b){
		swap(a,b);
	}
	if(a%b==0){
		return b;
	}else{
		return gcd(b,a%b);
	}
}
int main(){
	int n;
	cin>>n;
	long long ans=0;
	for(int i=1;i<=n;i++){
		if(i%3==0||i%5==0){
			continue;
		}else{
			ans+=i;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3596
N, M, X = map(int, input().split())
C = []
L = []
for i in range(N):
    B = list(map(int, input().split()))
    C.append(B[0])
    L.append(B[1:])

res = 10 ** 9
for i in range(2 ** N):
    c = 0
    s = [0 for _ in range(M)]
    for j in range(N):
        if i & (2 ** j):
            c += C[j]
            for k in range(M):
                s[k] += L[j][k]
    f = 1
    for j in range(M):
        if s[j] < X:
            f = 0
            break
    if f:
        res = min(res, c)

if res == 10 ** 9:
    print(-1)
else:
    print(res)


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

using namespace std;

const int md = 998244353;
const int N = 200005;

int f[N];

int add(int x, int y) {
  x += y;
  if (x >= md) {
    x -= md;
  }
  return x;
}

int sub(int x, int y) {
  x -= y;
  if (x < 0) {
    x += md;
  }
  return x;
}

int mul(int x, int y) {
  return (int)((long long)x * y % md);
}

int power(int x, int y) {
  int ans = 1;
  while (y) {
    if (y & 1) {
      ans = mul(ans, x);
    }
    x = mul(x, x);
    y >>= 1;
  }
  return ans;
}

int inv(int x) {
  return power(x, md - 2);
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  f[0] = f[1] = 1;
  for (int i = 2; i < N; i++) {
    f[i] = mul(i, f[i - 1]);
  }
  int n, m, k;
  cin >> n >> m >> k;
  int ans = 0;
  int num = f[n - 1];
  for (int i = 0; i <= k; i++) {
    int deno = mul(f[i], f[n - 1 - i]);
    int c = mul(num, inv(deno));
    c = mul(c, m);
    c = mul(c, power(m - 1, n - i - 1));
    ans = add(ans, c);
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 4424
using System;

namespace AtCoderBegin
{
    class Program
    {
        static void Main(string[] args)
        {
            int output = 0;
            string[] temp = Console.ReadLine().Split(" ");
            for (int i = 0; i < int.Parse(temp[0]); i++)
            {
             
                string[] line = Console.ReadLine().Split(" ");
                if (Math.Sqrt(Math.Pow(double.Parse(line[0]), 2) + Math.Pow(double.Parse(line[1]), 2)) <= double.Parse(temp[1]))
                {
                   output++;
                }


            }
            Console.WriteLine(output);
        }
    }
}   

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

#define ll long long

using namespace std;

string s;
int check(int i){
    if(s.substr(i,3)=="ABC")return 1;
    else return 0;
}
int main(){
    int n; cin>>n>>s;
    ll ans=0;
    for(int i=0; i<n-2; i++){
        if(s[i]=='A')ans+= check(i);
    }
    cout<<ans<<"\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rep1(i,n) for(int i=1;i<=int(n);i++)
#define per(i,n) for(int i=int(n)-1;i>=0;i--)
#define per1(i,n) for(int i=int(n);i>0;i--)
#define foreach(i,n) for(auto &&i:n)
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort(all(x))
#define GSORT(x) sort(all(x), greater<int>())
#define REV(x) reverse(all(x))
#define MAX(x) *max_element(all(x))
#define MIN(x) *min_element(all(x))
#define LOWitr(x, n) lower_bound(all(x), n)
#define UPRitr(x, n) upper_bound(all(x), n)
#define cii(x) int x;cin >> x
#define cill(x) LL x;cin >> x
#define cis(x) string x;cin >> x
#define co(x) cout << x << endl
#define dump(x)  cout << #x << " = " << (x) << endl
#define truecheck assert
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef long long int64;
template<class T,class U>bool chmax(T &a, const U &b) { if (a<b) { a=b; return true; } return false; }
template<class T,class U>bool chmin(T &a, const U &b) { if (b<a) { a=b; return true; } return false; }
const int INF = 1e9, MOD = 1e9 + 7;
const LL LLINF = 1e16;

int main() {
    fastcin();
    cout << fixed << setprecision(10);
    cii(n);
    auto ans = (n % 2 == 0)
            ?n
            :n * 2;
    co(ans);
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>

using namespace std;
int n;
int **tp, **ts;
int *a;

bool check(int S) {
	bool *h = new bool[n];
	for (int i = 0; i < n; ++i) {
		h[i] = S & 1;
		S = S >> 1;
	}
	for (int i = 0; i < n; ++i) {
		if (!h[i]) {
			continue;
		}
		for (int j = 0; j < a[i]; ++j) {
			if (h[tp[i][j] - 1] != ts[i][j]) {
				//cout << "error at " << tp[i][j] << ' ' << i << endl;
				delete []h;
				return false;
			}
		}
	}
	delete []h;
	return true;
}
int counts(int S) {
	//cout << S << endl;
	int res = 0;
	for (int i = 0; i < n; ++i) {
		res += (S & 1);
		S = S / 2;
	}
	//cout << "n = " << n << endl;
	//cout << "res = " << res << endl;
	return res;
}

int main() {
	cin >> n;
	tp = new int*[n];
	ts = new int*[n];
	a = new int[n];
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
		tp[i] = new int[a[i]];
		ts[i] = new int[a[i]];
		for (int j = 0; j < a[i]; ++j) {
			cin >> tp[i][j] >> ts[i][j];
		}
	}
	int res = 0;
	for (int S = 0; S < (1 << n); ++S) {
		if (check(S)) {
			//cout << S << ' ' << counts(S) << endl;
			res = max(res, counts(S));
		}
	}
	cout << res << endl;

	return 0;
}

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

int solve(int n,int m){
  
  if(m==1){
    return 1;
  }
  
  int res=0;
  for(int i=0;i<=n;i+=m*m){
    res+=solve(n-i,m-1);  
  }
  
  return res;
}

int main(){
  int n;
  while(1){
    cin>>n;
    if(n==0)break;
    cout<<solve(n,17)<<endl;
  }
  return 0;
}

Measured memory_bytes: 2972
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        final Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int n = in.nextInt();
        int k = in.nextInt();
        int[] cost = new int[n];
        int[] h = new int[n];
        for (int i = 0; i < n; i++) {
            h[i] = in.nextInt();
        }

        for (int i = 1; i < n; i++) {
            int min = Integer.MAX_VALUE;
            for (int j = 1; j <= k; j++) {
                if (i - j >= 0) {
                    min = Math.min(min, cost[i - j] + Math.abs(h[i] - h[i - j]));
                } else {
                    break;
                }
            }
            cost[i] = min;
        }
        System.out.println(cost[n - 1]);
    }
}

Measured memory_bytes: 61428
#include <iostream>
#include <string>
#include <algorithm>
#include <utility> 
#include <unordered_set>
#include <vector>
#include <list> 
#include <string>
#include <iterator> 
#include <deque>
#include <array>
#include <forward_list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <climits>
#include <bitset>
using namespace std;

#define N 12
#define EPS 1e-9
#define PI 3.14159265358979323846264338327950

int g[N][N];
int price[N];
int level[N];
int n, m, x;

int solve() {
	int ans = INT_MAX;
	int cost, ok;
	for (int i = 1; i <= (1 << n) - 1; ++i) {
		cost = 0;
		memset(level, 0, sizeof level);
		for (int k = 0; k < n; ++k) {
			if ((i>>k) & 1) {
				cost += price[k];
				for (int l = 0; l < m; ++l) {
					level[l] += g[k][l];
				}
			}
		}
		
		ok = true;
		for (int k = 0; k < m; ++k)
			ok = ok && level[k] >= x;
		if (ok) {
			ans = min(ans, cost);
		}
	}

	return ans == INT_MAX ? -1 : ans;
}

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

	cin >> n >> m >> x;
	for (int i = 0; i < n; ++i) {
		cin >> price[i];
		for (int j = 0; j < m; ++j)
			cin >> g[i][j];
	}
	cout << solve() << '\n';
}


Measured memory_bytes: 3080
# include <bits/stdc++.h>
#define flash ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define endl '\n'
#define ll long long int
#include <tr1/unordered_map>
#define ld long double
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define f(i,a,b)  for(long long i=a;i<b;i++)
#define all(c) (c).begin(),(c).end()
#include <map>
using namespace std;





int main()
{



     flash;
     ///////////////////////////////////////////////////////////////////////////////////////

ll n;
cin>>n;
vector <ll> vect1;
vector <ll> vect2;

	bool flag=false;
for(ll i=1;i*i<=n;i++)
{
	if(n%i==0)
	{
		vect1.push_back(i);
		vect2.push_back(n/i);
	}
}
for(ll i=0;i<vect1.size();i++)
{
	if(vect1[i]<=9&&vect2[i]<=9)
	{
		flag=true;
		break;
	}
}
if(flag==true)
{
	cout<<"Yes"<<endl;
}
else
{
	cout<<"No"<<endl;
}






    ///////////////////////////////////////////////////////////////////////////////////////

     return 0;

}


Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
    ll a,b,c,d,i,t,e=0,o=0;
    cin>>a;
    int s[a];
    for(i=0;i<a;i++)
    {
        cin>>s[i];
        if(s[i]%2==0)e++;
        else if(s[i]%2==1)o++;

    }if(o==0)cout<<"YES";
    else if(o%2==0)cout<<"YES";
    else cout<<"NO";
}



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

#define INF 1e9
#define LLINF 1e18
#define pi 3.14159265358979323
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;

int gcd(int a, int b) {
    if(a % b == 0) {
        return b;
    }
    else {
        return(gcd(b, a % b));
    }
}


int main() {
    int n, ans = 0;
    cin >> n;
    vector<int> l(n);
    rep(i, n) cin >> l.at(i);
    sort(l.begin(), l.end());
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            for (int k = j + 1; k < n; k++) {
                if (l.at(i) != l.at(j) && l.at(j) != l.at(k)) {
                    if (l.at(k) != l.at(i) && l.at(k) < l.at(i) + l.at(j)) {
                        ans++;
                    }
                }
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3632
import java.util.Scanner;
import java.util.Arrays;
public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] a = new int[n];
		for(int i=0; i<n; i++){
			a[i] = scan.nextInt();
		}
		Arrays.sort(a);
		System.out.println(a[n-1] - a[0]);
	}
}


Measured memory_bytes: 36040
#include <string>
#include <stack>
#include <iostream>
using namespace std;

int main() {
	string word;
	stack<int> S;
	while (cin >> word) {
		if (word == "+") {
			int a,b,c;
			a = S.top();
			S.pop();
			b = S.top();
			S.pop();
			c = a+b;
			S.push(c);
		}
		else if (word == "-") {
			int a,b,c;
			a = S.top();
			S.pop();
			b = S.top();
			S.pop();
			c = b-a;
			S.push(c);
		}
		else if (word == "*") {
		int a,b,c;
			a = S.top();
			S.pop();
			b = S.top();
			S.pop();
			c = a*b;
			S.push(c);
		}
		else {
			int toi = stoi(word);
			S.push(toi);
		}
	}

	cout << S.top() << endl;
}

Measured memory_bytes: 3192
#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>;

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

ll lcm(ll x, ll y) {
    return x*y / gcd(x, y);
}

int main() {
    ll a, b;
    cin >> a >> b;
    cout << lcm(a,b) << endl;
    return 0;
}

Measured memory_bytes: 256
main = do 
  n <- getLine
  xs <- map read . words <$> getLine
  ys <- map read . words <$> getLine
  putStrLn . show $ solve xs ys

solve :: [Int] -> [Int] -> Int
solve xs ys = inSolve (sum ys) xs ys

inSolve xysum [] [] = xysum
inSolve xysum (x:xs) (y:ys) = max (x + xysum) $ inSolve (xysum - y + x) xs ys
  


Measured memory_bytes: 1020
/* author   : mpily :-()
title : Competing.cpp
time :Sat Nov 23 10:47:49 2019

*/
#include<bits/stdc++.h>
using namespace std;
long double getdist(pair<int,int>A,pair<int,int>B){
	long double sqdist = (A.first-B.first)*(A.first-B.first) + (A.second-B.second)*(A.second-B.second);
	return sqrt(sqdist);
}
vector<long double> visitPath(long double totdist,int town, vector<pair<int,int>>&coords, vector<int>visited){
	vector<long double>sol;
	bool visiting = 1;
	for(int i = 0; i < coords.size(); i++){
		if(!visited[i]){
			visiting = 0;
			visited[i] = 1;
			long double ndist = totdist+getdist(coords[town],coords[i]);
			vector<long double>fori = visitPath(ndist,i,coords,visited);
			visited[i] = 0;
			sol.insert(sol.end(),fori.begin(),fori.end());
		}
	}
	if(visiting){
		vector<long double> toret = {totdist};
		return toret;
	}
	return sol;
}
int main(){
	int N;
	cin>>N;
	vector<pair<int,int>>townCoords(N);
	for(int i = 0; i < N; i++){
		cin>>townCoords[i].first>>townCoords[i].second;
	}
	long double sum = 0.0;
	for(int i = 0; i < N; i++){
		vector<int>visited(N);
		visited[i] = 1;
		vector<long double> fori = visitPath(0,i,townCoords,visited);
		for(auto a : fori){
			sum+=a;
		}
	}
	for(int i = 2; i <= N; i++){
		sum/=i;
	}
	cout<<setprecision(14);
	cout<<fixed;
	cout<<sum;
	return 0;
}


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

int main() {
    string s;
    cin >> s;
    string ans = "";
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == '0')
            ans += '0';
        else if (s[i] == '1')
            ans += '1';
        else {
            if (!ans.empty())
                ans.pop_back();
        }
    }
    cout << ans << endl;
    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(){
  int n;
  cin >> n;
  string x;
  vector<string> s(n);
  vector<int> t(n);
  int ans = 0;
  rep(i, n){
    cin >> s[i] >> t[i];
    ans += t[i];
  }
  cin >> x;
  rep(i, n){
    ans -= t[i];
    if(s[i] == x) break;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3580
#include<stdio.h>
int main(void)
{
	int x,y,r;
	do{
	scanf("%d %d",&x,&y);
	if(x>y)
	{
		r=x;
		x=y;
		y=r;
	}
	if(x!=0 || y!=0)printf("%d %d\n",x,y);
	}while(x!=0 || y!=0);
return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
int main(){
long long n,k;
cin >> n >> k;
long long h[n+1];
for (int i = 0;i < n;i++) cin >> h[i];
long long sum=0;
sort(h,h+n,greater<long long>());
 for (int i = k;i < n;i++){
     sum += h[i];
     //cout << h[i] << endl;
 }
 cout << sum << endl;

}

Measured memory_bytes: 1792
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program{
	const int mod=(int)1e9+7;
	const double eps=1e-11;
	static void Main(){
		Sc sc=new Sc();
		var n=sc.I;
		var a=sc.Ia;
		Array.Sort(a,(u,v)=>v-u);
		long ans=a[0];
		for(int i = 1,j=2;i<n&&j<n;i++) {
			ans+=a[i];
			j++;
			if(j==n){break;}
			ans+=a[i];
			j++;
		}
		Console.WriteLine("{0}",ans);
	}
}
public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),int.Parse);}
	public int[] Ia3(int a){return Array.ConvertAll((Console.ReadLine()+" "+a.ToString()).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),long.Parse);}
	public long[] La3(int a){return Array.ConvertAll((Console.ReadLine()+" "+a.ToString()).Split(),long.Parse);}
	public double[] Da2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),double.Parse);}}
	public double[] Da3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),double.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}

Measured memory_bytes: 46316
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0;i< (n);i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
//long long ccw(const Point& A, const Point& B, const Point& C) {
//	return 1LL * (B.x - A.x)*(C.y - A.y) - 1LL * (B.y - A.y)*(C.x - A.x);
//}

ll a[501];

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	int n; ll k; cin >> n >> k;
	ll l = 1000000000;
	ll r = 0;
	ll sum = 0;
	rep(i, n) {
		cin >> a[i];
		sum += a[i];
	}
	set<ll> s;
	for (ll i = 1; i* i <= sum; i++) {
		if (sum % i == 0) {
			s.insert(i);
			s.insert(sum / i);
		}
	}
	ll ans = 1;
	for (auto x : s) {
		vector<ll> v;
		ll R = 0;
		rep(i, n) {
			ll tmp = a[i] % x;
			R += (x - tmp);
			v.push_back(tmp);
		}
		ll L = 0;
		sort(v.begin(), v.end());
		rep(i, n) {
			R -= (x - v[i]);
			L += v[i];
			if (R == L && R <= k) {
				ans = max(ans, x);
				break;
			}
		}
	}
	cout << ans << '\n';
	




}

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

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)
#define reppp(i, m, n) for(int i=m;i<n;i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define debug(x) cerr << #x << ": " << x << endl

using namespace std;

typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;

const ll MOD = 1000000007;
const long double EPS = 10e-10;

int main(){
    std::ios::sync_with_stdio(0); cin.tie(0);
    int n;
    cin >> n;
    int a[n];
    rep(n) cin >> a[i];

    int MAX_A = 100001;
    int v[2][MAX_A];
    fill(v[0], v[2], 0);
    rep(n) v[i%2][a[i]]++;

    int u[2][2];
    rep(2){
        u[i][0] = int(max_element(v[i], v[i]+MAX_A) - v[i]);
        v[i][u[i][0]] = -1;
        u[i][1] = int(max_element(v[i], v[i]+MAX_A) - v[i]);
    }
    int ans = 0;
    if(u[1][0] == u[0][0]){
        int tmpans[2] = {0, 0};
        rep(n){
            if(a[i] != u[i%2][i%2]) tmpans[0]++;
        }
        rep(n){
            if(a[i] != u[i%2][1-i%2]) tmpans[1]++;
        }
        ans = min(tmpans[0], tmpans[1]);
    }else{
        rep(n){
            if(a[i] != u[i%2][0]) ans++;
        }
    }
    
    
    cout << ans << endl;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	
	int n, m; cin >> n >> m;
	vi a(n); rep(i, n) cin >> a[i];
	set<int> s;
	ll g = 1;
	rep(i, n){
		s.insert(__builtin_ctz(a[i]));
		a[i] /= 2;
		g = g * a[i] / __gcd(g, (ll)a[i]);
		if(g > m || s.size() > 1){
			cout << 0 << endl;
			return 0;
		}
	}
	cout << (1 + m / g) / 2 << endl;
	
	return 0;
}

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

int main() {
  ios::sync_with_stdio(0); cin.tie(0);
  int m, d;
  cin >> m >> d;
  int ans = 0;
  for (int d1 = 2; d1 < 10; d1++) {
    for (int d2 = 2; d2 < 10; d2++) {
      if (d1+d2*10 <= d && d1*d2 <= m) {
	ans++;
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;int N,C,D[2][5001],i,j,*A,*B;
main(){A=*D;B=D[1];cin>>N;fill_n(*D,1e4+2,1e9);A[1]=*B=0;for(;++i<N&&cin>>C;)for(j=N/2;~j;)A[j+1]=min(A[j],B[j]+C),B[j--]=min(A[j]+C,B[j]);cout<<min(A[N/2],B[N/2])<<endl;}

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

const int INF = (1 << 30) - 1;
int main()
{
    int N, M;

    while ( cin >> N, N ) {

        bool path[105][105] = {};
        int value[105];
        int memo[105];

        string purpose;
        unordered_map < string , int > hash;

        for ( int i = 0; i < N; i++ ) {
            string name;
            cin >> name >> value[i];
            hash[name] = i;
        }

        cin >> M;
        for ( int p = 0; p < M; p++ ) {
            string node;
            int k;
            cin >> node >> k;
            for ( int i = 0; i < k; i++ ) {
                string to;
                cin >> to;
                path[ hash[node] ][ hash[to] ] = true;
            }
        }

        cin >> purpose;
        memset(memo, -1, sizeof(memo));
        function < int(int) > calc = [&]( int v )
        {
            if ( memo[v] == -1 ) {
                memo[v] = INF;
                for ( int i = 0; i < N; i++ ) {
                    if ( path[v][i] ) {
                        if ( memo[v] == INF ) {
                            memo[v] = 0;
                        }
                        memo[v] += calc(i);
                    }
                }
                memo[v] = min(memo[v], value[v]);
            }
            return ( memo[v] );
        };

        cout << calc(hash[purpose]) << endl;
    }

    return (0);
}



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

const double PI = 3.14159265358979323846;
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
//typedef pair<ll, ll> P;
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

std::istream &operator>>(std::istream &in, set<int> &o) {
    ll a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
const int mod = 1000000007;
//const ll mod = 1e10;
typedef priority_queue<string, vector<string>, greater<string> > PQ_ASK;

#include <iostream>
#include <vector>

using namespace std;

struct Food {
    ll time, good;
};

vector<vector<ll>> knapsack(int n, ll t, vector<Food> &foods) {
    vector<vector<ll>> dp(n + 1, vector<ll>(t + 1, -1));
    dp[0][0] = 0;

    auto set = [&](int i, ll j, ll value) {
        if (i > n) return;
        if (j > t) return;
        if (dp[i][j] == -1) dp[i][j] = value;
        else
            cmax(dp[i][j], value);
    };

    rep(i, n) {
        rep(j, t + 1) {
            if (dp[i][j] == -1) continue;
            set(i + 1, j, dp[i][j]);
            set(i + 1, j + foods[i].time, dp[i][j] + foods[i].good);
        }
    }


    rep(i, n + 1) {
        rep(j, t + 1) {
            if (j == 0) continue;
            cmax(dp[i][j], dp[i][j - 1]);
        }
    }
    return dp;
}

vector<vector<ll>> knapsack2(int n, ll t, vector<Food> foods) {
    reverse(foods.begin(), foods.end());
    vector<vector<ll>> ans = knapsack(n, t, foods);
    reverse(ans.begin(), ans.end());
    return ans;
}

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

    vector<Food> foods(n);
    rep(i, n)cin >> foods[i].time >> foods[i].good;

    vector<vector<ll>> k1 = knapsack(n, t - 1, foods);
    vector<vector<ll>> k2 = knapsack2(n, t - 1, foods);

    ll ans = 0;
    rep(i, n) {
        rep(t1, t) {
            ll t2 = t - t1 - 1;
            assert(t1 + t2 + 1 == t);

            ll left = k1[i][t1];
            ll right = k2[i + 1][t2];
            ll g = foods[i].good;
            ll now = left + right + g;
            cmax(ans, now);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 141312
#include <bits/stdc++.h>
#include <algorithm>
#include <functional>
#include <map>
#include <queue>
#include <set>
#include <stack>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(i, m, n) for (ll(i) = (ll)(m); i < (ll)(n); ++i)
#define rep2(i, m, n) for (ll(i) = (ll)(n)-1; i >= (ll)(m); --i)
#define REP(i, n) rep(i, 0, n)
#define REP2(i, n) rep2(i, 0, n)
#define all(hoge) (hoge).begin(), (hoge).end()
#define en '\n'
using Edge = pair<int, long long>;
using Graph = vector<vector<Edge>>;
typedef vector<ll> vec;
typedef vector<vector<ll>> mat;
typedef vector<vector<vector<ll>>> mat3;
typedef vector<string> svec;
typedef vector<vector<string>> smat;
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll)1e9 + 7;
// constexpr long long MOD = 998244353LL;
using ld = long double;
static const ld pi = 3.141592653589793L;
template <class T> inline void print(T x){ cout << x << '\n';}
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;
}

long long gcd(long long x, long long y) { return y ? gcd(y, x % y) : x; }

vector<pair<long long, long long>> prime_factorize(long long N) {
    vector<pair<long long, long long>> res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0;
        while (N % a == 0) {
            ++ex;
            N /= a;
        }
        res.push_back({a, ex});
    }
    if (N != 1) res.push_back({N, 1});
    return res;
}
// ~~~~~~~~~~~~~~memo~~~~~~~~~~~~~~
// for (int i = 0; i < n; ++i)
// v ector<long long> v(n), c(n);
// cout << res << endl;
// cout << res << '\n';
// int型の2次元配列(h×w要素の)の宣言
// vector<vector<int>> data(h, vector<int>(w));
// rotate(s.begin(), s.begin() + 1, s.end());
// sort(all(a),greater<int>());
// s.substr(0,2) 先頭から2文字切り出す
// for (auto it = mp.rbegin();it != mp.rend(); ++it)
// vector<vector<vector<int>>> dp(n + 1, vector<vector<int>>(w + 1, vector<int>(k+1, 0)));

// ll dp[1005][3] = {99999999};

int main() {
    // ios::sync_with_stdio(false);
    // cin.tie(0);
    ll a, b;
    cin >> a >> b;
    if (a >= 13) {
        print(b);
    } else if (6<=a && a <= 12) {
        print(b/2);
    } else {
        print(0);
    }

    return 0;
}


Measured memory_bytes: 3576
#include <cstdio>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <cctype>
#include <cfloat>

#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <list>

#include <iostream>
#include <sstream>
#include <fstream>

#include <algorithm>
using namespace std;
#ifdef ONLINE_JUDGE
    #define debug
    #define log(message)
#else
    #define debug printf("passing [%s] in line %d\n", __FUNCTION__, __LINE__)
    #define log(message) puts(message)
#endif
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
void closeSync() {ios :: sync_with_stdio(0), cin.tie(0), cout.tie(0);}
template<class T> inline void read(T &x) {
    x = 0; int f = 1; char ch = getchar();
    while(ch < '0' || ch > '9') f &= (ch ^ '-'), ch = getchar();
    while('0' <= ch && ch <= '9') x = (x << 1) + (x << 3) + (ch ^ '0'), ch = getchar();
    x = f ? x : -x;
}

typedef long long ll;
typedef long double ld;

int num[10];

char op[10];

void dfs(int p, int sum) {
	if(p == 4) {
		if(sum == 7) {
			printf("%d%c%d%c%d%c%d=7\n", num[1], op[1], num[2], op[2], num[3], op[3], num[4]);
			exit(0);
		}
		return;
	}
	op[p] = '+';
	dfs(p + 1, sum + num[p + 1]);
	op[p] = '-';
	dfs(p + 1, sum - num[p + 1]);
}

int main() {
	scanf("%s", op);
	for(int i = 0 ; op[i] ; ++ i) num[i + 1] = op[i] - '0';
	dfs(1, num[1]);
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
int main(){
    int N,i,j,k;
    int x,y;
    double sum=0,ans=0;
    int X[10],Y[10];
    scanf("%d",&N);
    for (i=0;i<N;i++){
        scanf("%d %d",&x,&y);
        X[i]=x;
        Y[i]=y;
    }
    for (j=0;j<N-1;j++){
        if(N>3){
            for (k=1;k<N-j;k++){
                sum = sum + sqrt((X[j]-X[j+k])*(X[j]-X[j+k])+(Y[j]-Y[j+k])*(Y[j]-Y[j+k]));
            }
        }else{
            sum = sum + sqrt((X[j]-X[j+1])*(X[j]-X[j+1])+(Y[j]-Y[j+1])*(Y[j]-Y[j+1]));
        }
    }
    if(N==3){
        ans = (sum+sqrt((X[0]-X[N-1])*(X[0]-X[N-1])+(Y[0]-Y[N-1])*(Y[0]-Y[N-1])))*2/N;
    }else if(N==2){
        ans = sum;
    }else{
        ans = sum*2/N;
    }
    printf("%lf\n",ans);
}

Measured memory_bytes: 128