akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<math.h>

using namespace std;

int n;
int t, a;
long long h[1000000];
double te[1000000];

int main(){
  cin >> n;
  cin >> t >> a;
  double s = 1000001;
  long long answer;
  for(int i = 0; i < n; ++i){
    cin >> h[i];
  }
  for(int i = 0; i < n; ++i){
    te[i] = t - 0.006 * h[i];
    //cout << te[i] << endl;
  }
  for(int i = 0; i < n; ++i){
    if(abs(te[i] - a) < abs(s)){
      s = te[i] - a;
      answer = (i + 1);
    }
  }
  cout << answer << endl;
}

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

int main()
{
	int n;scanf("%d",&n);
	int l1=0,l2=0,l3=0;
	while(n--)
	{
		int x,y,z;
		scanf("%d%d%d",&x,&y,&z);
		int t1,t2,t3;
		t1=x-l1;t2=abs(y-l2);t3=abs(z-l3);
		t2+=t3;
		if(t1<t2||t1==0)
		{
			puts("No");
			return 0;
		}
		if((t2-t1)&1)
		{
			puts("No");
			return 0;
		}
		else
		{
			l1=x;l2=y;l3=z;
			continue;
		}
	}
	puts("Yes");
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
    //cout.precision(10);
    string S;
    string T;
    cin >> S >> T;
    int sa[100100];
    int ta[100100];
    sa[0] = 0;
    ta[0] = 0;
    for(int i = 1; i <= S.size(); i++){
        sa[i] = sa[i - 1];
        if(S[i - 1] == 'A'){
            sa[i]++;
        }
    }
    for(int i = 1; i <= T.size(); i++){
        ta[i] = ta[i - 1];
        if(T[i - 1] == 'A'){
            ta[i]++;
        }
    }
    int q;
    cin >> q;
    for(int i = 1; i <= q; i++){
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        int AinSover = b - a + 1 - 2 * (sa[b] - sa[a - 1]);
        int AinTover = d - c + 1 - 2 * (ta[d] - ta[c - 1]);
        if(AinSover < 0){
            AinSover = AinSover * (-2);
        }
        if(AinTover < 0){
            AinTover = AinTover * (-2);
        }
        //cout << i << " " << AinSover << " " << AinTover << endl;
        if((AinSover - AinTover) % 3 == 0){
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1664
#include<stdio.h>
#include<math.h>

int main(){
  int x1,y1,x2,y2;
  scanf("%d", &x1);
  scanf("%d", &y1);
  scanf("%d", &x2);
  scanf("%d", &y2);

  if(x1==x2){
    int hen = y1-y2;
    if(hen<0)hen=-hen;
    if(y1>y2){ //migi
      printf("%d %d %d %d\n", x1+hen,y2,x1+hen,y1);
      return 0;
    }
    else{ //hidari
      printf("%d %d %d %d\n", x1-hen,y2,x1-hen,y1);
      return 0;
    }
  }
  else if(y1==y2){
    int hen = x1-x2;
    if(hen<0)hen=-hen;
    if(y1>y2){ //ue
      printf("%d %d %d %d\n", x2,y2+hen,x1,y1+hen);
      return 0;
    }
    else{ //sita
      printf("%d %d %d %d\n", x2,y2-hen,x1,y1-hen);
      return 0;
    }
  }

  int side2 = (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2);
  int diag2 = 2*side2;
  int x3[2],y3[2];
  int num3=0;
  int x4[2],y4[2];
  int num4=0;
  int exit=0;
  for(int x=-1000; x<=1000 && !exit; x++){
    for(int y=-1000; y<=1000 && !exit; y++){
      int side = (x2-x)*(x2-x) + (y2-y)*(y2-y);
      int diag = (x1-x)*(x1-x) + (y1-y)*(y1-y);
      if(side==side2 && diag==diag2){
	x3[num3] = x;
	y3[num3] = y;
	num3++;
	if(num3==2 && num4==2) exit = 1;
      }
      int sidee = (x1-x)*(x1-x) + (y1-y)*(y1-y);
      int diagg = (x2-x)*(x2-x) + (y2-y)*(y2-y);
      if(sidee==side2 && diagg==diag2){
	x4[num4] = x;
	y4[num4] = y;
	num4++;
	if(num3==2 && num4==2) exit = 1;
      }
    }
  }

  //  printf("x3:(%d, %d) or (%d, %d)\n", x3[0],y3[0],x3[1],y3[1]);
  //  printf("x4:(%d, %d) or (%d, %d)\n", x4[0],y4[0],x4[1],y4[1]);

  for(int i=0; i<2; i++){
    if(x1<x2){
      if(y1<y2 && x3[i]<x2)      printf("%d %d ", x3[i],y3[i]);
      else if(y1>y2 && x3[i]>x2) printf("%d %d ", x3[i],y3[i]);
    }
    else if(x1>x2){
      if(y1<y2 && x3[i]<x2)      printf("%d %d ", x3[i],y3[i]);
      else if(y1>y2 && x3[i]>x2) printf("%d %d ", x3[i],y3[i]);
    }
  }
  int i3=-1;
  for(int i=0; i<2; i++){
    if(x1<x2){
      if(y1<y2 && x3[i]<x2)      i3=i;
      else if(y1>y2 && x3[i]>x2) i3=i;
    }
    else if(x1>x2){
      if(y1<y2 && x3[i]<x2)      i3=i;
      else if(y1>y2 && x3[i]>x2) i3=i;
    }
    //    printf("i3=%d\n",i3);
  }

  for(int i=0; i<2; i++){
    int side = (x3[i3]-x4[i])*(x3[i3]-x4[i]) + (y3[i3]-y4[i])*(y3[i3]-y4[i]);
    int diag = (x2-x4[i])*(x2-x4[i]) + (y2-y4[i])*(y2-y4[i]);
    if(side==side2 && diag==diag2){
      printf("%d %d\n", x4[i],y4[i]);
    }  
  }


  return 0;
}


Measured memory_bytes: 128
'use strict'

function main(input) {
  const inputList = input.split('\n');
  const dimenstion = inputList[0].split(' ')
  const h = Number(dimenstion[0])
  const w = Number(dimenstion[1])
  const columns = inputList.slice(1)
  const s = columns.map(column => column.split(''))

  const result = checkAdjacentSquares(s, h, w)
  if (result) {
    console.log('Yes')
  } else {
    console.log('No')
  }

}

function checkAdjacentSquares(array, h, w) {
  for (let i=0; i<h; i++) {
    for (let j=0; j<w; j++) {
      if (array[i][j] === '#') {
        if (!canPaint(array, i, j)) {
          return false
        }
      } 
    }
  }

  return true
}

function canPaint(array, i, j) {
  if (i-1>=0 && array[i-1][j] === '#')             return true 
  if (i+1<array.length && array[i+1][j] === '#')   return true
  if (j-1>=0 && array[i][j-1] === '#')             return true 
  if (j+1<array[i].length && array[i][j+1] === '#')return true
  return false
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7484
#include<string>
#include<iostream>
#include <algorithm>
#include<vector>
#include<functional>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#define ll long long
#define rep(i,n) for(ll i=0;i<(ll)n;i++)
using namespace std;

int main() {
	ll a=0, b=0, k=0;
	cin >>a>>b>>k; //入力
	if (k <= a) {
		a = a - k;
		cout << a << " " << b << endl;
		return 0;
	}
	else if (k > a && k <= a+b) {
		b = b - k+a;
		a = 0;
		cout << a << " " << b << endl;
		return 0;
	}
	else if (k > a + b) {
		a = 0;
		b = 0;
		cout << a << " " << b << endl;
		return 0;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,a[105]={0,2};
int main(void) {
    cin>>n;
    if(n==1) {
        cout<<1<<"\n";
        exit(0);
    }
    for(int i=2; i<=100; i++)  a[i]=a[i-1]*2;
    for(int i=1; i<=100; i++) {
        if(n>=a[i]&&n<a[i+1]) {
            cout<<a[i]<<endl;
            exit(0);
        }
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define N 300005
#define mod 1000000007
using namespace std;
typedef long long ll;
ll dp[N][5];
int n;
int flag[N];
vector <int> e[N];
ll ans;

void dfs(int k,int fat)
{
    if(e[k].size()==1&&e[k][0] == fat)
    {
        dp[k][0] = dp[k][1] = 1;
        return ;
    }
    ll x=1,y=1;
    for(int i=0;i<e[k].size();i++)
    {
        int to = e[k][i];if(to==fat) continue;
        dfs(to,k);
        x = (x*(dp[to][0]+dp[to][1])%mod)%mod;
        y = y*dp[to][0]%mod;
    }
    dp[k][0] = x;
    dp[k][1] = y;
}

int main()
{
    cin>>n;
    for(int i=1,x,y;i<n;i++)
    {
        cin>>x>>y;
        e[x].pb(y);
        e[y].pb(x);
        flag[y] = 1;
    }
    int root = 0;
    for(int i=1;i<=n;i++)
    {
        if(!flag[i])
        {
            root = i;
            break;
        }
    }
    dfs(root,-1);
    ans = (dp[root][0]+dp[root][1])%mod;
    printf("%lld\n",ans);
}


Measured memory_bytes: 20992
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

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


using namespace std;

int denom = 1000000007;

long long solve(int n) {
	long long res = 1;
	for (int i = 1; i <= n; i++) {
		res *= i;
		res %= denom;
	}
	return res;
}

int main() {
	int n, m;
	cin >> n >> m;
	if(n == m){
		long long res = 2 * solve(n) * solve(m) % denom;
		cout << res << endl;
	}
	else if (abs(n - m) == 1) {
		long long res = solve(n) * solve(m) % denom;
		cout << res << endl;
	}
	else {
		cout << 0 << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef pair<int, int> P;

int main(){
    int n; cin >> n;
    int p[11];
    for(int i=0;i<n;i++) cin >> p[i];

    sort(p, p+n); reverse(p, p+n);
    p[0] /= 2;

    int ans = 0;
    for(int i=0;i<n;i++) ans += p[i];

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

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

void dijkstra(vector<int> &S, int K) {
    using P = pair<int, int>;

    priority_queue<P, vector<P>, greater<P>> que;
    que.emplace(S[1], 1);

    while(!que.empty()) {
        P p = que.top();
        que.pop();
        int v = p.second;
        if(S[v] < p.first) continue;

        for(int y=0; y<10; ++y) {
            int nv = (10 * v + y) % K;
            if(S[nv] > S[v] + y) {
                S[nv] = S[v] + y;
                que.emplace(S[nv], nv);
            }
        }
    }
}

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

    vector<int> S(K, 100100101);
    for(int i=1; i<min(10, K); ++i) S[i] = i;

    dijkstra(S, K);
    cout << S[0] << endl;
}

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

#ifdef DEBUG
#define PRINT(x)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#x<<" = "<<(x)<<endl;
#define PRINTA(a,first,last)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#a<<"["<<(first)<<", "<<(last)<<")"<<endl;\
    for (int _i=(first);_i<(last);++_i){cout<<#a<<"["<<_i<<"] = "<<(a)[_i]<<endl;}
#define PRINTI(a,i)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#a<<"["<<#i<<"] = "<<#a<<"["<<(i)<<"] = "<<(a)[i]<<endl;
#else
#define PRINT(x)
#define PRINTA(a,first,last)
#define PRINTI(a,i)
#endif

#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 pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define MOD 1000000007
//#define MOD 998244353

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

template <class T, class U> void amax(T& x, U y) {if (x < y) x = y;}
template <class T, class U> void amin(T& x, U y) {if (x > y) x = y;}

template <class T, class U>
std::ostream& operator<<(std::ostream &os, const std::pair<T, U> &p) {
	os << "(" << p.first << ", " << p.second << ")";
	return os;
}
 
template <class T>
std::ostream& operator<<(std::ostream &os, const std::vector<T> &v) {
    os << "[";
	for (int i = 0; i < v.size(); ++i) {
        if (i) {
            if (i % 5 == 0) {
                os << ",\n ";
            } else {
                os << ", ";
            }
        }
		os << v[i];
	}
	os << "]";
	return os;
}

template <class T>
using vec2 = vector<vector<T>>;

template <class T>
using vec3 = vector<vector<vector<T>>>;

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

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

    int R, C, K;
    cin >> R >> C >> K;
    vector<vector<int>> a(R, vector<int>(C));
    REP(i, K) {
        int r, c, v;
        cin >> r >> c >> v;
        --r;
        --c;
        a[r][c] = v;
    }

    vector<vector<vector<ll>>> dp(R, vector<vector<ll>>(C, vector<ll>(4, -1)));

    REP(i, R) REP(j, C) REP(k, 4) {
        if (i == 0 && j == 0) {
            if (k == 0) {
                dp[i][j][0] = 0;
            } else {
                dp[i][j][k] = a[i][j];
            }
        } else if (i == 0) {
            if (k > 0) {
                dp[i][j][k] = max(dp[i][j - 1][k - 1] + a[i][j], dp[i][j - 1][k]);
            } else {
                dp[i][j][k] = dp[i][j - 1][k];
            }
        } else if (j == 0) {
            if (k == 0) {
                dp[i][j][k] = dp[i - 1][j][3];
            } else {
                dp[i][j][k] = max(dp[i - 1][j][3], dp[i - 1][j][3] + a[i][j]);
            }
        } else {
            dp[i][j][k] = max(dp[i - 1][j][3], dp[i][j - 1][k]);
            if (k > 0) {
                amax(dp[i][j][k], max(dp[i][j - 1][k - 1] + a[i][j], dp[i - 1][j][3] + a[i][j]));
            }
        }
    }

    cout << dp[R - 1][C - 1][3] << endl;

    return 0;
}


Measured memory_bytes: 670888
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		long n = sc.nextLong();
		long a = sc.nextLong();
		long b = sc.nextLong();
		long s=n/(a+b);
		long t=n%(a+b);
		if(t<=a){
			System.out.println(s*a+t);
		}else{
			System.out.println(s*a+a);
		}
	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define lli long long int
#define inf 2147483647
#define infll LLONG_MAX
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define Yes() cout << "Yes" << endl
#define No() cout << "No" << endl
#define YES() cout << "YES" << endl
#define NO() cout << "NO" << endl
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    lli n, k;
    cin >> n >> k;
    n %= k;

    cout << min(n, abs(n-k)) << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <vector>
#include <stdio.h>
#include <functional>
using namespace std;

int N, M, i;
long long int r;

template<typename ...> static inline int gc(void) { return getchar(); }
static inline void read(int &x){int k=gc();x=0;for(;;k=gc()){if(isdigit(k)){x=k-48;break;}}for(;;){k=gc();if(!isdigit(k))break;x=x*10+k-48;}}

int main(){
    read(N);
    M = N;
    N <<= 1;
    M += N;
    ++N;
    vector<int> a(M);
    for(; i ^ M; ++i){
        read(a[i]);
    }
    sort(a.begin(), a.end(), greater<int>());
    for(i = 1; i ^ N; i += 2){
        r += a[i];
    }
    printf("%lld", r);
    return 0;
}


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

int N;
long long h[100005];
long long dp[100005];


int main() {
    cin >> N;
    for (int i = 1; i <= N; ++i) {
        int tmp;
        cin >> tmp;
        h[i] = tmp;
    }

    dp[1] = 0LL;
    for (int x = 2; x <= N; ++x) {
        if (x == 2)
            dp[x] = dp[x - 1] + abs(h[x] - h[x - 1]);
        else
            dp[x] = min(dp[x - 1] + abs(h[x] - h[x - 1]), dp[x - 2] + abs(h[x] - h[x - 2]));
    }

    cout << dp[N] << endl;

}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <map>
#define llint long long
#define mod 1000000007

using namespace std;

llint n;
llint a[10005], b[10005];
llint prime[1000005];
map<llint, llint> mp;

const int FACT_MAX = 200005;
llint fact[FACT_MAX], fact_inv[FACT_MAX];

llint modpow(llint a, llint n)
{
	if(n == 0) return 1;
	if(n % 2){
		return ((a%mod) * (modpow(a, n-1)%mod)) % mod;
	}
	else{
		return modpow((a*a)%mod, n/2) % mod;
	}
}

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

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	for(int i = 2; i < 1005; i++){
		if(prime[i]) continue;
		for(int j = 2*i; j < 1000005; j+=i) prime[j] = i;
	}
	
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> a[i];
	
	llint ans = 0;
	for(int i = 1; i <= n; i++){
		ans += a[n] * modpow(a[i], mod-2) % mod;
		b[i] = a[i] / gcd(a[i], a[n]);
		ans %= mod;
	}
	
	for(int i = 1; i <= n; i++){
		map<llint, llint> mp2;
		llint t = b[i];
		while(1){
			if(prime[t] == 0){
				mp2[t]++;
				break;
			}
			mp2[prime[t]]++;
			t /= prime[t];
		}
		for(auto it = mp2.begin(); it != mp2.end(); it++){
			mp[it->first] = max(mp[it->first], it->second);
		}
	}
	
	llint lcm = 1;
	for(auto it = mp.begin(); it != mp.end(); it++){
		lcm *= modpow(it->first, it->second), lcm %= mod;
	}
	ans *= lcm, ans %= mod;
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 9984
i=61,f[],c,m,y;main(s){for(;~s?++f["=2>?J13IK<@V&"[1+--s]+y*12+*f]:~scanf("%d,%d,%d",f,&y,&s)?s*=4:i++<179?i%12>1?(y=f[i])?y>m?m=y:1:++c:1:!printf("%d\n%d\n",c,m););}

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

int main() {
    string word, sentence;
    int count = 0;

    cin >> word;
    while(cin >> sentence && sentence != "END_OF_TEXT") {
        for(int i = 0; i < sentence.size(); i++) {
            sentence[i] = tolower(sentence[i]);
        }
        if(sentence == word) count++;
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 3164
#include <iostream>

using namespace std;

int main(){
    long long N, A, B, C, D, E;
    cin >> N >> A >> B >> C >> D >> E;

    long long m = min(min(min(min(A, B), C), D), E);

    long long ans = N / m + 5uLL;

    if(N % m == 0)
        ans--;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
n, m, q = map(int, input().split())
l = [list(map(int, input().split())) for _ in range(q)]

def score(A):
    s = 0
    for i in range(q):
        a = l[i][0]
        b = l[i][1]
        c = l[i][2]
        d = l[i][3]
        if A[b-1] - A[a-1] == c:
            s += d
    return s
        
ans = 0

def dfs(A):  #Aはリスト
    global ans
    if len(A) == n:
        t = score(A)
        ans = max(ans, t)
        return
    
    
    if len(A)>0:
        lastn = A[-1]
    else:
        lastn =1
        
    for i in range(lastn, m+1):
        A.append(i)
        dfs(A)
        A.pop()
    

dfs([])
print(ans)

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

int main() {
    string s;
    int k;
    cin >> s >> k;
    int n = s.size();
    k--;
    char c = '1';
    int m = n;
    rep(i,n){
        if(s[i] != '1'){
            c = s[i];
            m = i;
            break;
        }
    }

    char ans;
    if(c == '1' || m > k) ans = '1';
    else ans = c;

    cout << ans << endl;
}

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

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

using namespace std;

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

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

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

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

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

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

	int X;
	cin >> X;
	int ans = 0;
	int p = 0;
	rep(i, 1, 100010)
	{
		p += i;
		ans++;
		if (p >= X)break;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <algorithm>
#include <sstream>
#include <string>
#include <map>
#include <set>
#include <stack>
using namespace std;

#define rep(i, n) for (int i=0; i<int(n); i++)
using ll = long long;

const ll mod = 1000000007ll;
ll dp[125252];


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

	vector<bool> vec(n+1, true);
	rep(i, m) {
		int a;
		cin >> a;
		vec.at(a) = false;
	}

	dp[0] = 1;
	for (int i=0; i<n; i++) {
		if (i+1<=n and vec.at(i+1)) {
			dp[i+1] += dp[i];
			dp[i+1] %= mod;
		}
		if (i+2<=n and vec.at(i+2)) {
			dp[i+2] += dp[i];
			dp[i+2] %= mod;
		}
	}
	cout << dp[n] << endl;
	return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
struct edge { int u, v; ll w; };
 
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
  int N;
  int a[100];

  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }

  sort(a, a + N);
  cout << a[N - 1] - a[0] << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define rep(i, n) for(ll i = 0; i < n; i++)
using namespace std;
int dy[4] = { 1, 0, -1, 0 }, dx[4] = { 0, 1, 0, -1 };
const ll MOD = 1e9 + 7;
const ll INF = 1e9;

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int p, q, r;
  cin >> p >> q >> r;
  int ans = p + q + r - max({p, q, r});
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(unused_macros)]
#![allow(unused_variables)]

use std::cmp::{max, min};
use std::io::{stdout, Write, BufWriter};

macro_rules! input {
  (source = $s:expr, $($r:tt)*) => {
    let mut iter = $s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
  ($($r:tt)*) => {
    let s = {
      use std::io::Read;
      let mut s = String::new();
      std::io::stdin().read_to_string(&mut s).unwrap();
      s
    };
    let mut iter = s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
}

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

macro_rules! read_value {
  ($iter:expr, ( $($t:tt),* )) => {
    ( $(read_value!($iter, $t)),* )
  };
  ($iter:expr, [ $t:tt ; $len:expr ]) => {
    (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
  };
  ($iter:expr, chars) => {
    read_value!($iter, String).chars().collect::<Vec<char>>()
  };
  ($iter:expr, usize1) => {
    read_value!($iter, usize) - 1
  };
  ($iter:expr, $t:ty) => {
    $iter.next().unwrap().parse::<$t>().expect("Parse error")
  };
}

fn main() {
  let out = std::io::stdout();
  let mut out = BufWriter::new(out.lock());
  input! {
    n: i32,
    a: i32,
    b: i32,
    s: String,
  }
  let mut x = 0;
  let mut y = 0;
  for c in s.chars() {
    if c == 'a' {
      if x < a + b {
        out.write(b"Yes\n").ok();
        x += 1;
      } else {
        out.write(b"No\n").ok();
      }
    } else if c == 'b' {
      if x < a + b && y < b {
        out.write(b"Yes\n").ok();
        x += 1;
        y += 1;
      } else {
        out.write(b"No\n").ok();
      }
    } else {
      out.write(b"No\n").ok();
    }
  }
}


Measured memory_bytes: 2308
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <tuple>
#include <utility>
#include <vector>
#define ll long long
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl
#define COYE cout<<"YES"<<endl
#define COYe cout<<"Yes"<<endl
#define COye cout<<"yes"<<endl
#define CONO cout<<"NO"<<endl
#define CONo cout<<"No"<<endl
#define COno cout<<"no"<<endl
#define FORE(i,a) for(auto &i:a)
#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,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define PB push_back
#define MP make_pair
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define EACH(V,i) for(typeof((V).begin()) i=(V).begin();i!=(V).end();++i)
#define equals(a,b) (fabs((a)-(b))<EPS)
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MAX 5100000
using namespace std;
using Edge=pair<int,int>;
using Graph=vector<vector<int>>;
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>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;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
  int N;
  cin>>N;
  int A[N];
  REP(i,N) cin>>A[N-1-i];
  
  vector<int> L(N+2,MOD);
  L[0]=-1;
  
  REP(i,N){
    if(A[i]<L[0]) L[0]=A[i];
    else *(upper_bound(ALL(L),A[i])--)=A[i];
  }
  
  RREP(i,N+1){
    if(L[i]==MOD){
      co(i-1);
      return 0;
    }
  }
}

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

public class Main {

	private static final int mod =(int)1e9+7;
	public static void main(String[] args) throws Exception  {
	      Scanner  sc=new Scanner(System.in);
	      PrintWriter out=new PrintWriter(System.out);
	   int a=sc.nextInt();
	   int b=sc.nextInt();
	   System.out.println((a+b)>=10?"error":(a+b));
	        
	        
	}

static long nCr(int n, int r, 
    int p) 
{ 


if (r == 0) 
return 1; 


int[] fac = new int[n + 1]; 
fac[0] = 1; 

for (int i = 1; i <= n; i++) 
fac[i] = fac[i - 1] * i % p; 

return (fac[n] * modInverse(fac[r], p) 
% p * modInverse(fac[n - r], p) 
% p) 
% p; 
} 
static long modInverse(int n, int p) 
{ 
    return pow(n, p - 2)%mod; 
} 
static long pow(long x,long y) {
  long res=1l;
  while(y!=0) {
    if(y%2==1) {
      res=x*res%mod;
    }
    y/=2;
    x=x*x%mod;
  }
  return res;
} 
}




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

int int_len(int n) {
  int s=0;
  while(n!=0) s++, n/=10;
  return s;
}

int int_sum(int n) {
  int m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(int i=s-1;i>=0;i--) m+=n/((int)pow(10,i))-(n/((int)pow(10,i+1)))*10;
  return m;
}






int ggcd(int a,int b)
{
 
  int r, tmp;
 
  
 
  /* 自然数 a > b を確認・入替 */
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }
 
  /* ユークリッドの互除法 */
  r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
 
 
 
  return b;
}







int fac(int n){
  int m=1;
  while(n>=1) m*=n,n--;
  return m;
}

int vec_sum(vector<int> v){
  int n=0;
  for(int i=0;i<v.size();i++) n+=v[i];
  return n;
}
///////////////////////////
int main() {
  int n,a;
  cin>>n;
  vector<int> v(n);
  rep(i,n) cin>>v[i];
  sort(v.begin(),v.end());
  a=vec_sum(v)-v[n-1];
  if(v[n-1]<a){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
}
///////////////////////////





Measured memory_bytes: 256
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=sys.stdin.readline
def resolve():
    n=int(input())
    A=[0]*n
    ans=0
    for i in range(n):
        A[i]=list(map(int,input().split()))
        ans+=sum(A[i])
    from copy import deepcopy
    B=deepcopy(A)
    # Warshall-Floyd
    from itertools import product
    for k,i,j in product(range(n),repeat=3):
        B[i][j]=min(B[i][j],B[i][k]+B[k][j])
    # calculate
    if A!=B:
        print(-1)
        return
    for i,j in product(range(n),repeat=2):
        if i==j: continue
        flag=False
        for r in range(n):
            if i==r or j==r: continue
            flag=(flag or B[i][j]==B[i][r]+B[r][j])
        if flag: ans-=B[i][j]
    print(ans//2)

resolve()

Measured memory_bytes: 55772
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
#include<complex>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 4000001;
const double eps = 1E-18;

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

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

ll gcd(ll a, ll b) {
	if (b == 0) { return a; }
	if (a < b) { return gcd(b, a); }
	return gcd(b, a % b);
}

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% MOD + MOD) % MOD) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint& a) {
		if ((x += a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator-=(const mint& a) {
		if ((x += MOD - a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator*=(const  mint& a) {
		(x *= a.x) %= MOD;
		return *this;
	}
	mint operator+(const mint& a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint& a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint& a) const {
		mint res(*this);
		return res *= a;
	}

	mint operator^(const ll& t)const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}
	// for prime MOD
	mint inv() const {
		return pow(MOD - 2);
	}
	mint& operator/=(const mint& a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint& a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream& os, const mint& m) {
		os << m.x;
		return os;
	}
};

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

int main() {
	ll A, B, K;
	cin >> K >> A >> B;
	if ((A - 1) / K < B / K) { cout << "OK" << endl; }
	else { cout << "NG" << endl; }
	
	system("PAUSE");
}


Measured memory_bytes: 3700
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

const int MOD = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%MOD+MOD)%MOD){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += MOD-a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= MOD; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime MOD
  mint inv() const { return pow(MOD-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
// combination MOD prime
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < MOD);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
  mint p(int n, int k) {
    return fact[n]*ifact[n-k];
  }
} c(10000007);
// c(5, 2) → 10, c.p(5, 2) → 20, c.fac[4] → 24

int main() {
  // 非負と負でカテゴリー分け、積が0以上になるかどうか
  // 積が正になる時負の数は2つずつとる
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  rep(i, N) cin >> A[i];
  sort(A.rbegin(), A.rend());
  vector<ll> pos; // 0を含む
  vector<ll> neg;
  rep(i, N) {
    if (A[i] < 0) neg.push_back(A[i]);
    else pos.push_back(A[i]);
  }
  int lenP = sz(pos);
  int lenN = sz(neg);
  bool bl = false; // 積を正に出来るならtrue
  if (lenP > 0) {
    if (N==K) bl = (lenN%2 == 0);
    else bl = true;
  } else {
    // 負の数のみ
    bl = (K%2 == 0);
  }
  mint ans = 1;
  //cout << "bl " << bl << '\n';
  if (bl) {
    vector<ll> cand;
    int cur = 0;
    if (K&1) {
      ans = pos[0];
      cur = 1;
      K--;
    }
    for (int i = cur; i < min(K+1
                              , lenP); i++) {
      if ((i-cur)&1 || i+1 == lenP) continue;
      cand.push_back(pos[i] * pos[i+1]);
    }
    sort(neg.begin(), neg.end());
    for (int i = 0; i < min(K, lenN); i++) {
      if (i&1 || i+1 == lenN) continue;
      cand.push_back(neg[i] * neg[i+1]);
    }
    sort(cand.rbegin(), cand.rend());
    K /= 2;
    rep(i, K) ans *= cand[i];
  } else {
    rep(i, K) ans *= A[i];
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 163604
#include <iostream>
#include <cstring>
#include <vector>

class dice{

    public:
        dice():pip{}{};
        void SetPips();
        int GetUpperPip(){return pip[0];};
        void Rolldice(char order);
        friend std::ostream &operator<<(std::ostream &out, const dice &d);//?????
    private:
    int pip[6];

};

//dice::dice():pip{}{}

void dice::SetPips(){
    for(int i=0;i<6;i++){
        std::cin>>pip[i];
    }
}

void dice::Rolldice(char order){
    int tem;
    switch(order){
        case 'N':{
            tem=pip[0];
            pip[0]=pip[1];
            pip[1]=pip[5];
            pip[5]=pip[4];
            pip[4]=tem;
            break;
        }
        case 'E':{
            tem=pip[0];
            pip[0]=pip[3];
            pip[3]=pip[5];
            pip[5]=pip[2];
            pip[2]=tem; 
            break;           
        }
        case 'S':{
            tem=pip[0];
            pip[0]=pip[4];
            pip[4]=pip[5];
            pip[5]=pip[1];
            pip[1]=tem;  
            break;    
        }
        case 'W':{
            tem=pip[0];
            pip[0]=pip[2];
            pip[2]=pip[5];
            pip[5]=pip[3];
            pip[3]=tem;  
            break;    
        }
    }
}

std::ostream &operator<<(std::ostream &out, const dice &d)
{
    for (auto &x : d.pip)
    {
        out << x << " ";
    }
} //??????

int main(){
    using namespace std;
    string order;
    dice d;
    d.SetPips();
    std::cin>>order;
    for (int i=0;i<order.length();i++){
        d.Rolldice(order[i]);
    }
    std::cout<<d.GetUpperPip()<<std::endl;
    return 0;
}




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

int main() {
    string S;
    cin >> S;
    int val = 700;
    for (auto itr = S.begin(); itr != S.end(); itr++){
        if(*itr == 'o') val += 100;
    }
    cout << val << endl;
    return 0;
}

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

typedef long long ll;
#define PB push_back

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	int n; cin >> n;
	ll sum = 0;
	for (int i = 1; i <= n; ++i) {
		if (i % 3 != 0 && i % 5 != 0) sum += i;
	}
	cout << sum;
}


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

int main() {
	int N, K;
	cin >> N >> K;
	vector<int> H(N);
	for (int h = 0; h < N; h++) {
		cin >> H[h];
	}

	long long INF = 10000000000;
	vector<long long> TotalMinCost(N, INF);
	TotalMinCost[0] = 0;
	for (int h = 0; h < N; h++) {
		for (int k = 1; k <= K; k++) {
			if (h + k < N) {
				TotalMinCost[h + k] = min(TotalMinCost[h + k], TotalMinCost[h] + abs(H[h + k] - H[h]));
			}
		}
	}

	cout << TotalMinCost[N - 1] << endl;
}

Measured memory_bytes: 1408
#include<iostream>
#include<fstream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<math.h>
#include<algorithm>
#include<iomanip>
#include<set>
#include<utility>

using namespace std;

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for(int i = 0; i < n; i++) cin >> a[i];
  vector<int> ia(n);
  for(int i = 0; i < n; i++) ia[a[i] - 1]++;
  map<int, int> mp;
  int rest = 0;
  for(int i = 0; i < n; i++) {
    if(ia[i] > 0) {
      mp[ia[i]]++;
      rest++;
    }
  }
  int ans = 0;
  if(rest <= k) {
    cout << 0 << endl;
    return 0;
  }
  for(auto it = mp.begin(); it != mp.end(); it++) {
    if(rest - it->second < k) {
      ans += it->first * (rest - k);
      break;
    }
    rest -= it->second;
    ans += it->first * it->second;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
#include<stdio.h>
#include<math.h>
int main(){
	float x0,y0,x1,y1,x2,y2,S=0,a,b,c,z;
	scanf("%f,%f%f,%f",&x0,&y0,&x1,&y1);
	while(~scanf("%f,%f",&x2,&y2)){
		a=hypot(x0-x1,y0-y1);
		b=hypot(x1-x2,y1-y2);
		c=hypot(x2-x0,y2-y0);
		z=(a+b+c)/2;
		S+=sqrt(z*(z-a)*(z-b)*(z-c));
		x1=x2;
		y1=y2;
	}
	printf("%f\n",S);
	return 0;
}

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

const int maxn = 2000000;
const int mod = 1e9 + 7;

int step[maxn], inv_step[maxn];

int power(int x, int times) {
	int rt = 1, base = x;
	while (times) {
		if (times & 1) rt = (long long)rt * base % mod;
		base = (long long)base * base % mod;
		times >>= 1;
	}
	return rt;
}

int C(int a, int b) {
	if (b < 0 || b > a) return 0;
	return (long long)step[a] * inv_step[b] % mod * inv_step[a - b] % mod;
}

int f[maxn];

int main() {
	step[0] = 1;
	for (int i = 1; i < maxn; i++) step[i] = (long long)step[i - 1] * i % mod;
	for (int i = 0; i < maxn; i++) inv_step[i] = power(step[i], mod - 2);

	int n;
	scanf("%d", &n);
	n--;
	for (int i = 1; i <= n; i++) f[i] = C(i - 1, n - i);


	//for (int i = n; i >= 1; i--) f[i] = (f[i] - (long long)f[i - 1] * (n - (i - 1))) % mod;
//	for (int i = 1; i <= n; i++) cout << f[i] << endl;

	long long ans = 0;
	for (int i = 1; i <= n; i++) {
		ans = (ans + (long long)f[i] % mod * step[i] % mod * step[n - i]) % mod;
//		cout << ans << endl;
	}

	ans = ((long long)step[n] * (n + 1) - ans) % mod;
	cout << (ans + mod) % mod << endl;
	return 0;
}

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

long long dp[200003][3];
long long ara[200003],n;

long long solve(long long idx,long long sta,long long lim)
{

    long long rr=lim-sta;

    if(idx+rr==n)return ara[idx];
    else if(dp[idx][sta]!=-1)return dp[idx][sta];
    else
    {

        long long p;

        p=ara[idx]+solve(idx+2,sta,lim);

        if(sta+1<=lim)
        {
            p=max(p,ara[idx]+solve(idx+3,sta+1,lim));
        }

        dp[idx][sta]=p; return dp[idx][sta];

    }


}

int main()
{

    long long a,i,j,st=1,ans=LLONG_MIN;

    scanf("%lld",&n);

    for(i=1;i<=n;i++)
    {
        scanf("%lld",&a);  ara[i]=a; dp[i][0]=-1; dp[i][1]=-1; dp[i][2]=-1;
    }


    if(n%2==1)
    {
        ans=max(ans,solve(1,0,2));

        st=2;
    }

    if(st==2){memset(dp,-1,sizeof dp);}
    ans=max(ans,solve(st,0,1));

    memset(dp,-1,sizeof dp);
    ans=max(ans,solve(st+1,0,0));

    printf("%lld\n",ans);


    return 0;
}


Measured memory_bytes: 14764
from collections import deque
n = int(input())

Q = deque()
for i in range(n):
    command = input().split()
    if command[0] == "insert":
        Q.appendleft(command[1])
    elif command[0] == "deleteFirst":
        Q.popleft()
    elif command[0] == "deleteLast":
        Q.pop()
    elif command[0] == "delete":
        try:
            Q.remove(command[1])
        except:
            pass
print(" ".join(Q))

Measured memory_bytes: 71796
n,k=map(int,input().split())
S=list(input())
if S[k-1]=="A":
  S[k-1]="a"
elif S[k-1]=="B":
  S[k-1]="b"
elif S[k-1]=="C":
  S[k-1]="c"
print("".join(S))

Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>
#include<vector>
 
using namespace std;
 
 int gcd(int a,int b){
   if(b>a) swap(a,b);
   int tem;
  while(b!=0){
    tem=a%b;
    a=b;
    b=tem;
  }
  return a;
 }

int main() {
  long long N;
  cin >> N;
  long long A[N+10];
  int ans;
  cin >> ans;
  for(int i=1; i<N; i++){
    cin >> A[i];
    ans=gcd(ans,A[i]);
  }
  cout << ans << endl;
}

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

int main(){
  ll n,sum=0;
  cin >> n;
  vector<ll> v(n+2);
  v[0]=0;	v[n+1]=0;
  r(i,n)cin >> v[i+1];
  r(i,n+1)sum+=abs(v[i+1]-v[i]);
  r(i,n){
    cout<<sum-abs(v[i+1]-v[i])-abs(v[i+2]-v[i+1])+abs(v[i+2]-v[i])<<endl;
  }
}

Measured memory_bytes: 2048
#include<iostream>
#include<cstdio>
using namespace std;
int main() {
	int a,b,c,d;
	scanf("%d %d %d %d",&a,&b,&c,&d);
	if(c>b||a>d) {
		printf("0");//abcd\\cdab
	} else {
		if(a>=c){//cabd\\cadb
			if(b<=d){
				printf("%d",b-a);//cabd
			}else{
				printf("%d",d-a);//cadb
			}
		}else{//acdb\\acbd
			if(b<=d){
				printf("%d",b-c);//acbd
			}else{
				printf("%d",d-c);//acdb
			}
		}
	}
	return 0;
}

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

int main() {
    int A,B,C,X;
    int count = 0;
    int i = 0;
    cin >> A >> B >> C >> X;
    for(int a=0;a<=A;a++){
        for(int b=0;b<=B;b++){
            for(int c=0;c<=C;c++){
                i = 500*a + 100*b + 50*c;
                if(i==X) count++;
            }
        }
    }
    
    cout << count << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define inf (1<<28)
#define EPS 1e-10
#define equals(a,b) (fabs((a)-(b)) < EPS)
using namespace std;
int h,w;

int main()
{
  while(cin >> h >> w,h|w)
    {
      int ah,aw;
      ah = aw = inf;
      double d = sqrt(w*w+h*h);
      double mdist = inf;
      REP(i,1,h+100)
	REP(j,1,w+100)
	{
	  if(i == h && j == w)continue;
	  if(j <= i)continue;
	  double dist = sqrt((double)(i*i+j*j));
	  if(!equals(dist,d))
	    {
	      if(dist < d)continue;
	    }
	  else
	    {
	      if(i < h)continue;
	    }

	  if(!equals(dist,mdist))
	    {
	      if(dist < mdist)
		{
		  mdist = dist;
		  ah = i,aw = j;
		}
	    }
	  else
	    {
	      if(i < ah)
		{
		  ah = i;
		}
	    }
	}
      cout << ah << " " << aw << endl;
    } 
  return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); ++(i))
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef pair<int, int> pii;
typedef complex<double> xy_t;

const lint mod = 1e9 + 7;

int main(){
    string s;
    cin >> s;
    int n = s.size();
    
    int f[n+1];
    f[0] = 0;
    rep(i, n){
        if(i == 0) f[i+1] = 1;
        else if(i == 1 && s[i] == s[i-1]) f[i+1] = 1;
        else if(i > 1 && s[i] == s[i-1]) f[i+1] = f[i-2] + 2;
        else f[i+1] = f[i] + 1;
    }
    
    printf("%d\n", f[n]);
}

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

int main() {
  int n; cin >> n;
  vector<int> a(n);
  int mi = 100, ma = -100, ans = 1000000005;
  rep(i,n) {
    cin >> a[i];
    mi = min(mi,a[i]);
    ma = max(ma,a[i]);
  }
  for (int i = mi; i<=ma; i++) {
    int sum = 0;
    rep(j,n) {
      sum += (a[j]-i)*(a[j]-i);
    }
    ans = min(ans,sum);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3584
import math

def resolve():
    N, M, X = map(int, input().split())
    C_list = []
    A_list = []

    for i in range(N):
        tmp_list = list(map(int, input().split()))
        C_list.append(tmp_list.pop(0))
        A_list.append(tmp_list)
    
    ans = math.inf
    for b in range(1 << N):
        cost = 0
        d_list = [0 for i in range(M)]
        for i in range(N):
            if b >> i & 1:
                cost += C_list[i]
                for j in range(M):
                    d_list[j] += A_list[i][j]

        flag = True
        for d in d_list:
            if d < X:
                flag = False
        if flag:
            ans = min(ans, cost)
    
    if ans == math.inf:
        print(-1)
    else:
        print(ans)

    return
        

if __name__ == "__main__":
    resolve()

Measured memory_bytes: 9100
#include <iostream>
using namespace std;
int main(){
    int R, G, B, N, ans=0, r=0, g=0, b=0;
    cin >> R >> G >> B >> N;
    int rmax = N/R;
    int gmax = N/G;
    int bmax = N/B;
    for(int i=0; i<=rmax; i++){
        r = i;        
        for(int j=0; j<=gmax; j++){
            g = j;
            b = (N - r*R - g*G)/B;
            if(b<0||b>bmax||r*R+g*G+b*B!=N);
            else ans++;
        }
    }
    cout<< ans <<endl;
}

Measured memory_bytes: 256
main = interact $ unlines . map (unwords . map show . prime2 . read) . lines

prime2 n = [last under, if o==n then (head over) else o]
 where (under,(o:over)) = break (>=n) primes

primes = 2:3:[x | i<-[1..], j<-[-1,1], let x = 6*i+j, isPrime x]
 where isPrime n = null [i | i<-takeWhile (\x -> x*x <= n) primes, rem n i == 0]

Measured memory_bytes: 5084
#include <stdio.h>
int main()
{
	int n,i,j,sum=1,x=0,min;
	scanf("%d",&n);
	int a[n];
	for(i=0;i<n;i++)
		scanf("%d",&a[i]);
	min=a[0];
	for(i=1;i<n;i++)
	{
		if(a[i]<=min)
		{
			sum++;
			min=a[i];
		}
	}
	printf("%d",sum);
}

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

#define rep(i,n) for(ll i=0;i<n;i++)
#define repm(i,m,n) for(ll i=m;i<n;i++)
#define max(a,b) (((a)>(b))?(a):(b))
#define min(a,b) (((a)<(b))?(a):(b))
#define YesNo(a) (a)?cout<<"Yes"<<endl:cout<<"No"<<endl
#define YESNO(a) (a)?cout<<"YES"<<endl:cout<<"NO"<<endl
#define INF (2e9)
#define PI (acos(-1))
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007

typedef long long ll;

int main(){
  int n; cin >> n;
  string s; cin >> s;

  reverse(all(s));

  int disastar_count = 0;
  int disastar_point = 0;
  bool disastar = false;
  rep(i,n){
    if(!disastar && s[i] == 'R'){
      disastar = true;
      disastar_point = i;
    }
    if(disastar && s[i] == 'W'){
      disastar_count++;
    }
  }

  int d = disastar_point+disastar_count;
  repm(i,disastar_point,d){
    if(s[i] == 'W') disastar_count--;
  }

  cout << disastar_count << endl;
}

Measured memory_bytes: 3760
function main(input){
    let lines = input.split("\n");
    let n = lines[0];
    let c = 0;
    for(let i = 1; i <= n; i++) c+= isPrime(Number(lines[i]));
    console.log(c);
}
function isPrime(x){
    if (x == 2) return 1;
    if (x < 2 || x %2 == 0) return 0;
    i = 3
    while (i <= Math.sqrt(x)){
        if(x%i == 0) return 0;
        i = i + 2
    }
 return 1;
}
main(require('fs').readFileSync('/dev/stdin', 'UTF-8'));


Measured memory_bytes: 17784
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define All(V) V.begin(), V.end()
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD = 1e9+7, INF = 1e9;

int main()
{
    int n, k; cin >> n >> k;
    set<int> s;
    rep(i, k){
        int d; cin >> d;
        rep(j, d){
            int a; cin >> a;
            s.insert(a);
        }
    }
    int ans = 0;
    for(int i = 1; i <= n; i++){
        if(!s.count(i)){
            ans++;
        }
    }
    cout << ans << endl;
    system("pause");
}

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

int main()
{
	string number;
	while (cin >> number, number != "0") {
		int sum = 0;
		for (int i = 0; i < number.size(); i++) {
			sum += number[i] - '0';
		}
		cout << sum << endl;
	}
    return 0;
}

Measured memory_bytes: 1188
#include <bits/stdc++.h>
#define pi 3.14159
using namespace std;

int main()
 {
 	int n,i,j,d,c=0,k,s;
 	cin>>n>>d;
 	int a[n][d];
 	for(i=0;i<n;i++)
 		for(j=0;j<d;j++)
 			cin>>a[i][j];
 	for(i=0;i<n-1;i++)
 		{
 			
 			for(j=i+1;j<n;j++)
 			{
 				 s=0;
 				for(k=0;k<d;k++)
 					s=s+pow(a[i][k]-a[j][k],2);
			 
				int x=sqrt(s);
				if(x*x==s)
			 		c++;
			
			
		}
		 }
 		
 	
 	cout<<c<<endl;
 }

Measured memory_bytes: 3672