akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;

int gcd(int a, int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int lcm(int a, int b){
    return a/gcd(a,b)*b;
}


signed main(void) {
    int n;
    cin >> n;
    vi a(n);
    rep(i,n)cin >> a[i];
    vi b = a;
    rep(i,n-1)if(a[i]){
        b[i+1] += b[i];
    }
    int ma = 0;
    rep(i,n)ma = max(ma,b[i]);
    cout << ma+1 << endl;
}



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

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

    int n, input, count = 0;

    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> input;
        if (input != i)
            count++;
    }

    if (count <= 2)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <iostream>

#include <vector>

using namespace std;

int main()

{

  ios::sync_with_stdio(false);

  cin.tie(0);

  cout.tie(0);

  int n;

  cin >> n;

  long long sum = 0;

  vector<long long> a(n, 0), b(n, 0);

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

    cin >> a[i];

    

  b[0] = a[n-1];

  b[0] %= 1000000007;

  

  for (int i = 1; i < n; i++)

  {

      b[i] = b[i-1] + a[n-i-1];

      b[i] %= 1000000007;

  }

  long long res = 0;

  for (int i = 0; i < n-1; i++)

  {

    res += (b[n-i-2] * a[i]);

    res %= 1000000007;

  }

  cout << res << endl;

  return 0;

}

Measured memory_bytes: 5992
// Dividing a String

#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <ios>
#include <iomanip>
#include <string>
#include <numeric>

using namespace std;

int main() {
    string s;
    cin >> s;
    int len = s.size();

    int start = 0;
    string prev = s.substr(start, 1);
    int count = 1;


    start = 1;
    for (int i = 1; i <= len - start; i++) {
        string tmp = s.substr(start, i);
        if (prev != tmp) {

            // cout << "prev: " << prev << "  tmp: " << tmp << endl;
            prev = tmp;
            count++;
            start += i;
            i = 0;
        }
    }

    cout << count << endl;

    return 0;
}

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

#define INF (1.0/0.0)
#define EPS 1e-8
#define PI 3.1415926535
#define EQ(x, y) (abs((x)-(y))<EPS)
#define GE(x, y) ((x)>(y)||EQ(x, y))
#define LE(x, y) ((x)<(y)||EQ(x, y))
#define X real()
#define Y imag()

typedef complex<double> Point;
typedef Point Vec;
typedef array<Point, 2> Line;

int NA, NB;
vector<Point> ps[2];

enum Geometry {ABC=-2, CW, ACB, CCW, CAB, ON_LINE, OUTSIDE, INSIDE, ERROR};

namespace std {
  bool operator<(Point a, Point b) {
    if (!EQ(a.X, b.X)) return a.X < b.X;
    if (!EQ(a.Y, b.Y)) return a.Y < b.Y;
    return false;
  }

  bool operator>(Point a, Point b) {
    return b<a;
  }

  bool operator<=(Point a, Point b) {
    return !(a>b);
  }
}

double dot(Point a, Point b) {
  return (conj(a)*b).X;
}

double cross(Point a, Point b) {
  return (conj(a)*b).Y;
}

Geometry ccw(Point a, Point b, Point c) {
  a -= b;
  c -= b;
  if (cross(a, c) > EPS) return CCW; // ccw
  if (cross(a, c) < -EPS) return CW; // cw
  if (dot(a, c) < -EPS) return ABC; // a - b - c

  double al = abs(a);
  double cl = abs(c);
  if (EQ(al, cl)) return ERROR; // a and c are duplicate
  if (EQ(min(al, cl), 0)) return ERROR;
  if (al < cl) return CAB; // c - a - b
  else return ACB; // a - c - b
}

bool IsParallel(Line l, Line m) {
  Vec v1 = l[1]-l[0];
  Vec v2 = m[1]-m[0];
  return EQ(cross(v1, v2), 0.0);
}

bool IntersectSS(Line s, Line t) {
  // hard coding: CW := -1, CCW := 1 -> only CW*CW and CCW*CCW are equal to 1
  if (ccw(s[0], s[1], t[0])*ccw(s[0], s[1], t[1]) == 1) return false;
  swap(s, t);
  if (ccw(s[0], s[1], t[0])*ccw(s[0], s[1], t[1]) == 1) return false;
  if (!IsParallel(s, t)) return true;
  if (max(s[0], s[1]) < min(t[0], t[1])) return false;
  swap(s, t);
  if (max(s[0], s[1]) < min(t[0], t[1])) return false;
  return true;
}

double Calc(vector<Point> &ps, vector<Point> &qs) {
  vector<double> mind(ps.size(), INF);
  vector<bool> used(ps.size());
  double ret = abs(qs[0]-qs[1]);
  mind[0] = 0;
  while (1) {
    int u = -1;
    for (int i=0; i<ps.size(); i++) {
      if (used[i]) continue;
      if (mind[i] == INF) continue;
      if (u == -1 || mind[i] < mind[u]) u = i;
    }
    if (u == -1) break;
    used[u] = true;

    for (int v=0; v<ps.size(); v++) {
      if (IntersectSS(Line{ps[u], ps[v]}, Line{qs[0], qs[1]})) continue;

      double t = mind[u] + abs(ps[u]-ps[v]);
      if (mind[v] > t) mind[v] = t;
    }
  }

  return ret+mind[1];
}

int main() {
  scanf("%d%d", &NA, &NB);
  for (int i=0; i<NA; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    ps[0].emplace_back(Point(x, y));
  }

  for (int i=0; i<NB; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    ps[1].emplace_back(Point(x, y));
  }

  double ans = Calc(ps[0], ps[1]);
  ans = min(ans, Calc(ps[1], ps[0]));
  if (ans == INF) puts("-1");
  else printf("%.10f\n", ans);
}
    

Measured memory_bytes: 3252
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace AtCoder
{
	public class Program
	{
		static void Main(string[] args)
		{
			ulong MOD = 1000000007;

			string s = Console.ReadLine();
			int n = s.Length;

			ulong[,] dp = new ulong[100005, 13];
			dp[0, 0] = 1;

			for (int i = 0; i < n; i++) {
				for (int j = 0; j < 10; j++) {
					if (s[i] == '?' || s[i] == '0' + j) {
						for (int k = 0; k < 13; k++) {
							dp[i + 1, (k * 10 + j) % 13] += dp[i, k];
						}
					}
				}
				for (int k = 0; k < 13; k++) {
					dp[i + 1, k] %= MOD;
				}
			}
			Console.WriteLine(dp[n, 5]);
		}
	}
}

Measured memory_bytes: 21472
// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}

int main(){
  int a , b;
  cin >> a >> b;
  if(a <= 0 && b >= 0)
    cout << "Zero" << endl;
  else if(a > 0)
    cout << "Positive" << endl;
  else
    cout << ((b - a + 1) & 1 ? "Negative" : "Positive") << endl;
  return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<long long> L(N + 1);
  L[0] = 2, L[1] = 1;
  for (int i = 2; i <= N; ++i) {
    L[i] += L[i - 1] + L[i - 2];
  }
  cout << L[N] << endl;
}


Measured memory_bytes: 3584
const stdin = require('fs').readFileSync('/dev/stdin', 'utf8')

const _n = stdin.split('\n')[0]
const n = Number(_n)

let a = stdin.split('\n')[1].split(' ').map(Number)

const res = a.reduce((p,c)=>gcd(p,c))

console.log(res)

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


Measured memory_bytes: 17612
import java.lang.StringBuilder
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val sx = sc.nextInt()
    val sy = sc.nextInt()
    val tx = sc.nextInt()
    val ty = sc.nextInt()

    val answer = StringBuilder()
    val dy = Math.abs(ty - sy)
    val dx = Math.abs(tx - sx)

    // 1
    for (i in 1..dy) {
        answer.append("U")
    }
    for (i in 1..dx) {
        answer.append("R")
    }

    // 2
    for (i in 1..dy) {
        answer.append("D")
    }
    for (i in 1..dx) {
        answer.append("L")
    }

    // 3
    answer.append("L")
    for (i in 1..dy + 1) {
        answer.append("U")
    }
    for (i in 1..dx + 1) {
        answer.append("R")
    }
    answer.append("D")

    // 4
    answer.append("R")
    for (i in 1..dy + 1) {
        answer.append("D")
    }
    for (i in 1..dx + 1) {
        answer.append("L")
    }
    answer.append("U")

    println(answer)
}

Measured memory_bytes: 29356
#include<stdio.h>
int main()
{
char a[4];
  int c,i;
  c=0;
  scanf("%4s",a);
 for(i=0;i<3;++i)
 {
  if(a[i]==a[i+1])  {
    c++;
    }

 }
  
 if(c>0) printf("Bad");
  else printf("Good");
  
return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(ll i = n;i >= 0;--i)
#define FOR(i,m,n) for(ll i = m, i##_len=(n);i <i##_len; ++i)
#define all(x) (x).begin(),(x).end()
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; }
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const int INF = 1e9;
const ll LLINF = 1e16;
 
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

int main(void)
{
    int n,d;
    cin >> n >> d;
    vector<vector<int>> p(n,vector<int>(d));

    REP(i,n){
        REP(j,d){
            cin >> p[i][j];
        }
    }

    int ans = 0;

    for (int i = 0; i < n - 1;i++){
        for (int j = i + 1; j < n;j++){
            int sum = 0;
            REP(k,d){
                sum += pow(p[i][k] - p[j][k], 2);
            }
            if(pow(floor(sqrt(sum)),2) == sum){
                ans++;
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll ; 
typedef long double ld ;
typedef pair<ll , ll> pll ;

const ll N = 2e5 + 30 , Mod = 1e9 + 7 ;
const ll SQ = 330 ;
const ll INF = 1e17;

ll a[N] ;
int main () {
    ios::sync_with_stdio(0), cin.tie(0) ;
    string s, t;
    cin >> s >> t;
    cout << t << s << endl;
	    
    return (0) ;
}

Measured memory_bytes: 764
#include <iostream>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
const double eps = 1e-8;
const double pi = acos(-1.0);
const int inf = 0x3f3f3f3f;
typedef long long ll;
int sgn(double x){
    if(fabs(x)<eps){
        return 0;
    }
    if(x<0){
        return -1;
    }else{
        return 1;
    }
}
struct Point{
    double x,y;
    Point(){}
    Point(double _x,double _y){
        x = _x;
        y = _y;
    }
    void input(){
        scanf("%lf%lf",&x,&y);
    }
    double distance(Point p){
        return hypot(x-p.x,y-p.y);
    }
};
struct circle{
    Point p;
    double r;
    circle(){}
    circle(Point _p,double _r){
        p = _p;
        r = _r;
    }
    circle(double x,double y,double _r){
        p = Point(x,y);
        r = _r;
    }
    void input(){
        p.input();
        scanf("%lf",&r);
    }
    //两圆的关系
    //5 相离
    //4 外切
    //3 相交
    //2 内切
    //1 内含
    int relationcircle(circle v){
        double d = p.distance(v.p);
        if(sgn(d-r-v.r)>0){
            return 5;
        }
        if(sgn(d-r-v.r)==0){
            return 4;
        }
        double l = fabs(r-v.r);
        if(sgn(d-r-v.r)<0&&sgn(d-l)>0){
            return 3;
        }
        if(sgn(d-l)==0){
            return 2;
        }
        if(sgn(d-l)<0){
            return 1;
        }
    }
};
int main(){
    circle c1,c2;
    c1.input();
    c2.input();
    printf("%d\n",c1.relationcircle(c2)-1);
    return 0;
}



Measured memory_bytes: 3292
#include<bits/stdc++.h>
using namespace std;
inline int read()
{
    int x=0,f=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='1') f=-1;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    return x*f;
}
int n,m;
int main()
{   
    n=read();m=(n+3)/4*2;
    if(n==1) return 0*puts("1\n1");
    int dif=m*2-n;printf("%d\n",m);
    for(int i=1;i<=m;++i,puts(""))
        for(int j=1;j<=m;++j)
        {
            int x=(i+j-1)%m+1;
            x=x+(i%2)*m;
            if(x>m&&dif)
            {
                if(x-m<=dif) x-=m;
                else x-=dif;
            }
            printf("%d ",x);
        }
    return 0;
}

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

int factorial (int n) {
  if(n == 0) {
    return 1;
  } else if (n == 1) {
    return 1;
  } else {
    return n * factorial(n-1);
  }
}

int main() {
  int N;
  cin >> N;
  int copy = N;
  int digits = 0;
  while(copy != 0) {
    copy /= 10;
    digits++;
  }
  if(digits < 3) {
    cout << 0 << endl;
  } else {
    int ans = 0;
    for(int i=3;i<10;i++) {
      if(i == digits) {
        vector<string> vec(0);
        for(int j=0;j<=i-3;j++) {
          for(int k=0;k<=i-3-j;k++) {
            int l = (i-3)-j-k;
            string s1 (j+1, '3');
            string s2 (k+1, '5');
            string s3 (l+1, '7');
            string s = s1 + s2 + s3;
            do {
              vec.push_back(s);
            } while (next_permutation(s.begin(), s.end()));
          }
        }
        sort(vec.begin(), vec.end());
        for(int j=0;j<vec.size();j++) {
          if(stoi(vec[j]) > N) {
            ans += j;
            break;
          }
          if(j == vec.size()-1 && stoi(vec[j]) <= N) ans += vec.size();
        }
        break;
      } else {
        for(int j=0;j<=i-3;j++) {
          for(int k=0;k<=i-3-j;k++) {
            int l = (i-3)-j-k;
            int bunbo = factorial(j+1) * factorial(k+1) * factorial(l+1);
            ans += factorial(i) / bunbo;
          }
        }
      }
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 1280
#include <stdio.h>

    int lday[26] = {-1, -1, -1,-1, -1, -1,-1, -1, -1,-1, -1, -1,-1, -1, -1,-1, -1, -1,-1, -1, -1,-1, -1, -1,-1, -1}, dp[366], day[26][366] = {}, dayc[26] = {};   //  day     コンテストが実施された日    dayc    dayのインデックス
    int c[26], s[365][26], ave = 0;

int calc(int con, int dd)
{
    int i, ans;
    ans = s[dd][con];
    
    for (i = 0; i < con; i++)
        ans -= c[i] * (dd - lday[i]);
    for (i = con + 1; i < 26; i++)
        ans -= c[i] * (dd - lday[i]);
    return (ans);
}

int main(void){
    int d, D, ans[366], score = 0, tmpscore;
    int i, ii, iii, iv, tmp, tmp2;
    scanf("%d", &D);
    for (i = 0; i < 26; i++)
        scanf("%d", c + i);
    for (ii = 0; ii < D; ii++)
        for (i = 0; i < 26; i++)
            scanf("%d", &s[ii][i]);
    
    for (i = 0; i < 26; i++)
        ave += c[i];
    ave /= 26;
    tmpscore = 0;
    for (d = 0;  d < D; d++)
    {
        tmp = -1000000;
        for (i = 0; i < 26; i++)
        {
            tmp2 = calc(i, d);
            if (tmp2 > tmp)
            {
                tmp = tmp2;
                ans[d] = i;
            }
        }
        tmpscore += tmp;
        day[ans[d]][dayc[ans[d]]++] = d;
        lday[ans[d]] = d;
    }
    
    for (iv = 0; iv < 6; iv++)
    {
        for(i = 0; i < 26; i++)
        {
            if (c[i] > 1)
            {
                for (ii = 0; ii < dayc[i] - 1; ii++)
                {
                    if (day[i][ii + 1] - day[i][ii] > 80)
                    {
                        for (iii = dayc[i] + 1; iii > ii + 1; iii--)
                        {
                            day[i][iii] = day[i][iii - 1];
                        }
                        ans[day[i][ii] + 79] = i;
                        day[i][ii + 1] = day[i][ii] + 78;
                        dayc[i]++;
                    }
                }
            }
            else if (c[i] > 0)
            {
                for (ii = 0; ii < dayc[i] - 1; ii++)
                {
                    if (day[i][ii + 1] - day[i][ii] > 120)
                    {
                        for (iii = dayc[i] + 1; iii > ii + 1; iii--)
                        {
                            day[i][iii] = day[i][iii - 1];
                        }
                        ans[day[i][ii] + 79] = i;
                        day[i][ii + 1] = day[i][ii] + 118;
                    }
                }
            }
        }
    }
    
    for (i = 0; i < D; i++)
        printf("%d\n", ans[i] + 1);
}

Measured memory_bytes: 1764
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define dbg(x) cout<<#x"="<<x<<endl

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

#define INF 1000000000
#define MAX 1000000

// sieve of Eratosthenes (prime num)
bool p[MAX+3]; //prime number=false
void prime(int n){
  rep(i,n+1) p[i]=false;
  p[1]=true;
  for(int i=2;i<=n;i++){
    if(!p[i]){
      for(int j=i*2; j<=n; j+=i){
	p[j]=true;
      }
    }
  }
}

int main(){
  prime(MAX+2);

  while(true){
    int a,d,n;
    scanf("%d %d %d", &a, &d, &n);
    if(n==0)break;

    int cnt=0;
    while(true){
      if(!p[a]){
	cnt++;
	if(cnt>=n) break;
      }
      a+=d;
    }
    cout << a << endl;

  }
}

Measured memory_bytes: 2184
#include<bits/stdc++.h>
#include<vector>
#include<algorithm>
#define F first
#define S second
#define PB push_back
#define MP make_pair


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vii;
typedef set<int> si;
typedef map<string, int> msi;

#define INF 2000000000

const int max_n=1e9+1;
const ll mod=998244353;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin>>n;
    int ans=0;
    int digit=0,x=n;
    while(x){
        digit++;
        x/=10;
    }
    if(n>=9) ans+=9;
    if(n>=999) ans+=900;
    if(n>=99999) ans+=90000;
    if(n<9) {
        cout<<n;
        return 0;
    }
    if(n<999&&n>=100){
        ans+=(n-100+1);
        cout<<ans;
        return 0;
    }
    if(n<99999&&n>=10000){
        ans+=(n-10000+1);
        cout<<ans;
        return 0;
    }
    cout<<ans;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
using ll = long long;
using pll = pair<ll, ll>;
#define all(x) (x).begin(), (x).end()
#define call(x) (x).cbegin(), (x).cend()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define sz(x) ((x).size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
const double PI = acos(-1);
const int mod = 1e9+7;
const long long INF = (1LL << 60);
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
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;}
ll stringcount(string s, char c){return count(s.cbegin(), s.cend(), c);}
bool isInteger(double x){return floor(x) == x;}
ll ceil(ll a, ll b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmax(T &a, const T &b){ if(a < b){ a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b){ if(a > b){ a=b; return 1; } return 0; }



int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  
  ll n;
  cin >> n;
  vector<ll> a(n);
  bool second = true;
  for(ll i = 0; i < n; i++){
    cin >> a[i];
    if(a[i] % 2 == 1) second = false;
  }
  if(second) cout << "second" << endl;
  else cout << "first" << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int x,l,g,y,z,n;
  bool b=false;
  cin >> x >> n;
  if(n==0){
    cout << x << endl;
    return 0;
  }
  vector<int>a(n);
  for (int i=0;i<n;i++) {
    cin >> a.at(i); 
  }
  l=a.at(0);
  g=a.at(0);
  for (int i=0;i<n;i++) {
    if(a.at(i)<l){
      l=a.at(i);
    }
    if(a.at(i)>g){
      g=a.at(i);
    }
  }
  z=10000000;
  for (int i=0;i<10000;i++) {
    b=false;
    for (int j=0;j<n;j++) {
      if(x-i==a.at(j)){
        b=true;
        break;
      }
    }
    if(!b){
    cout << x-i << endl;
        return 0;
    }
    b=false;
    for (int j=0;j<n;j++) {
      if(x+i==a.at(j)){
        b=true;
        break;
      }
    }
    if(!b){
    cout << x+i << endl;
        return 0;
    }
  } 
}

Measured memory_bytes: 3624
#include <cstdio>
#include <cstring>

using namespace std;

char s[101];
char t[101];

int main() {
    int n, i, j;
    
    scanf("%d", &n);
    scanf("%s", s);
    scanf("%s", t);
    
    for (i = 0; i < n; i++) {
        for (j = 0; i + j < n; j++) {
            if (s[i + j] != t[j]) break;
        }
        
        if (i + j == n) {
            printf("%d\n", n + i);
            
            return 0;
        }
    }
    
    printf("%d\n", n * 2);
    
    return 0;
}


Measured memory_bytes: 128
import copy
n, m = map(int, input().split())
# 隣接行列
e = [[float('inf')]*n for i in range(n)]
for i in range(m):
    a, b,c = map(int, input().split())
    e[a-1][b-1]=c
    e[b-1][a-1]=c


ans=[[float('inf')]*n for i in range(n)]
d=copy.deepcopy(e)
# ワーシャルフロイド　全点最短経路、負の距離あっても可　o(n**3)
def warshall_floyd(d):
    #d[i][j]: iからjへの最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                if i==j or k==i or k==j:
                    continue
                if d[i][j]==float('inf') and (d[i][k]==float('inf') or d[k][j]==float('inf')):
                    continue
                else:
                    if d[i][j] > d[i][k] + d[k][j]:
                        d[i][j]=d[i][k]+d[k][j]

warshall_floyd(d)
x=0
for i in range(n):
    for j in range(n):
        if e[i][j]!=float('inf'):
            if e[i][j]>d[i][j]:
                x+=1
print(x//2)

Measured memory_bytes: 46812
import java.util.Scanner;

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

		int num_count = sc.nextInt();

		long[] array = new long[num_count];

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

		long ans1 = 0,sum = 0;

		for(int i = 0;i < num_count;i++){
			if(i % 2 == 0 && (sum + array[i]) <= 0){
				long cost = 1 - (sum + array[i]);
				ans1 += cost;
				sum = 1;
			}else if(i % 2 == 1 && (sum + array[i]) >= 0){
				long cost = 1 + (sum + array[i]);
				ans1 += cost;
				sum = -1;
			}else{
				sum += array[i];
			}
		}

		long ans2 = 0;
		sum = 0;


		for(int i = 0;i < num_count;i++){
			if(i % 2 == 1 && (sum + array[i]) <= 0){
				long cost = 1 - (sum + array[i]);
				ans2 += cost;
				sum = 1;
			}else if(i % 2 == 0 && (sum + array[i]) >= 0){
				long cost = 1 + (sum + array[i]);
				ans2 += cost;
				sum = -1;
			}else{
				sum += array[i];
			}
		}

		long min_ans = ans1 < ans2 ? ans1 : ans2;
		System.out.println(min_ans);
	}
}


Measured memory_bytes: 60532
#include <iostream>
using namespace std;
int main(){
   int n,ryouA=0,neA=0,ryouB=0,neB=0,i,j,hon1=0,hon2=0,ansa=0,ansb=0;
   cin>>n;
       cin>>ryouA>>neA>>ryouB>>neB;
       for(;;){
           hon1=hon1+ryouA;
           ansa+=neA;
           if(hon1>=n){
               break;
           }
           
       }
       for(;;){
           hon2=hon2+ryouB;
           ansb+=neB;
           if(hon2>=n){
               break;
           }
          
       }
   
   if(ansa<=ansb){
           cout<<ansa<<endl;
       }
       else if(ansb<ansa){
           cout<<ansb<<endl;
       }
return 0;
}



Measured memory_bytes: 3116
#include <iostream>
#include <map>
#include <string>
#include <queue>
#include<algorithm>

using namespace std;


map<string, int> dp;

int go[4] = {1, -1, 4, -4};

void pre_processing(){
    string init = "01234567";
    dp[init] = 0;
    queue<string> que;
    que.push(init);

    while (!que.empty()){
        auto now = que.front(); que.pop();

        int zero = 0;
        for (int i = 0; i < 8; ++ i) if (now[i] == '0') { zero = i; break; }
        for (int i = 0; i < 4; ++ i){
            int nxt_zero = zero + go[i];
            if (nxt_zero < 0 || nxt_zero > 7 || (zero == 3 && i == 0) || (zero == 4 && i == 1)) continue;
            string nxt = now;
            swap(nxt[nxt_zero], nxt[zero]);
            if (dp.find(nxt) == dp.end()){
                dp[nxt] = dp[now] + 1;
                que.push(nxt);
            }
        }
    }
}

int main(){
    dp.clear();

    string query;
    pre_processing();
    while (getline(cin, query)){
        query.erase(std::remove(query.begin(), query.end(), ' '), query.end());
        cout << dp[query] << endl;
    }
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int main(){
  string s;
  cin>>s;
  REP(c,26)if(count(ALL(s),'a'+c)==0){
    putchar('a'+c);puts("");return 0;
  }
  puts("None");
  return 0;
}


Measured memory_bytes: 512
a, b, m = map(int,input().split())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
ans = 10**19
for i in range(m):
  x, y, c = map(int,input().split())
  ans = min(A[x-1]+B[y-1]-c, ans)
print(min(ans,min(A)+min(B)))

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

using namespace std;

int main()
{
	double N, K;
	cin >> N >> K;

	double ans = 0;

	for (int i = 1; i <= N; i++) {
		int throwCount = max(ceil(log2(K / (double)i)), 0.0);
		ans += (1.0 / N) * pow(0.5, throwCount);
	}

	printf("%.12f\n", ans);

	return 0;
}


Measured memory_bytes: 512
use proconio::input;

fn main() {
    input! {
        n: usize,
        s: usize,
        v: [usize; n]
    }
    let mm = 998244353;

    let dp: Vec<Vec<usize>> = {
        let mut dp: Vec<Vec<usize>> = vec![vec![0; s+1]; n+1];
        dp[0][0] = 1;
        for i in 0..n {
            for x in 0..s+1 {
                dp[i+1][x] = {
                    if x >= v[i] {
                        (dp[i][x]*2+dp[i][x-v[i]])%mm
                    } else {
                        (dp[i][x]*2)%mm
                    }
                }
            }
        }
        dp
    };

    println!("{}",dp[n][s])
}

Measured memory_bytes: 72484
#include <iostream>
#include <math.h>
#include<iomanip>
using namespace std;

int main(){
  int N;
  int X[8];
  int Y[8];
  double sum = 0;
  int cnt = 0;
  
  cin >> N;
  for(int n=0; n<N; n++){
    cin >> X[n];
    cin >> Y[n];
  }

  for(int i=0; i<N;i++){
    for(int j=0; j<N;j++){
      if(i==j){
        continue;
      }
      sum += sqrt(  ((X[i] - X[j]) * (X[i] - X[j])) 
                  + ((Y[i] - Y[j]) * (Y[i] - Y[j])) );
      cnt++;
    }
  }
  //cout << sum;
  //cout << cnt;
  cout << setprecision(16)<< (double)sum/(double)N;
  
  return 0;
}




Measured memory_bytes: 256
def func1(i,N,S):
  indexS = 0 #Sの見ている場所
  indexI = 0 #3桁の暗証番号の見ている場所(0~2)
  i2 = str(i).zfill(3) # 0埋めしたi
  
  while indexS < N:
    if indexI > 2:
      break #探索終了
    if i2[indexI] == S[indexS]:
      indexI +=1
    indexS +=1
  return 1 if indexI >2 else 0

def main():
  N = int(input())
  S = input()
  print(sum([func1(i,N,S) for i in range(1000)]))

if __name__ == '__main__':
  main()

Measured memory_bytes: 39152
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<algorithm>
using namespace std;
int main()
{
	long long x,a,b;
	cin >> x;
	for(a=1;1;a++){
		if(a*a*a*a*a<=x){
			for(b=0;a*a*a*a*a-b*b*b*b*b<=x;b--){
				if(a*a*a*a*a-b*b*b*b*b==x){
					cout << a << " " << b << endl;
					return 0;
				}
			}
		}
		else{
			for(b=1;a*a*a*a*a-b*b*b*b*b>=x;b++){
				if(a*a*a*a*a-b*b*b*b*b==x){
					cout << a << " " << b << endl;
					return 0;
				}
			} 
		}
	}
	return 0;
}

Measured memory_bytes: 3620
n = int(input())
t = list(map(int, input().split()))
a = list(map(int, input().split()))
mod = 10 ** 9 + 7

tmax, amax = max(t), max(a)
if not any(ti == ai == tmax == amax for ti, ai in zip(t, a)):
    print(0)
    exit()

ans = 1
for i in range(1, n - 1):
    if t[i - 1] == t[i] and a[i] == a[i + 1]:
        ans = ans * min(t[i], a[i]) % mod
else:
    print(ans)


Measured memory_bytes: 97664
#include "bits/stdc++.h"
#define MOD 1000000007
#define INF 11234567890
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

LL N, A[112345];
LL res1, res2;

int main()
{
	in >> N;
	rep(i, N) { in >> A[i]; }

	std::sort(A, A + N, std::greater<LL>());
	rep(i, N - 1)
	{
		if (A[i] == A[i + 1] && res1 == 0)
		{
			res1 = A[i];
			++i;
		}
		else if (A[i] == A[i + 1] && res1 != 0 && res2 == 0)
		{
			res2 = A[i];
			break;
		}
	}

	out << res1*res2 << std::endl;
	return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    String weather = scan.nextLine();
    switch (weather) {
      case "SSS":
        System.out.println("0");
        break;
      case "SSR":
      case "SRS":
      case "RSS":
      case "RSR":
        System.out.println("1");
        break;
      case "SRR":
      case "RRS":
        System.out.println("2");
        break;
      case "RRR":
        System.out.println("3");
        break;
    }
  }
}

Measured memory_bytes: 35600
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 4005;

int N, psR[MAXN], psG[MAXN], psB[MAXN];
string str;

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

	cin >> N;
	cin >> str;

	for (int i = 1; i <= N; i++) {
		psR[i] = psR[i-1] + (str[i-1] == 'R');
		psG[i] = psG[i-1] + (str[i-1] == 'G');
		psB[i] = psB[i-1] + (str[i-1] == 'B');
	}

	long long ans = 0;
	for (int i = 0; i < N; i++) {
		for (int j = i-1; j > 0; j--) {
			if (str[i] == str[j]) continue;
			if (str[i] != 'R' && str[j] != 'R') {
				ans += psR[j];
				if (j - (i-j) >= 0 && str[j - (i-j)] == 'R') ans--;
			} else if (str[i] != 'G' && str[j] != 'G') {
				ans += psG[j];
				if (j - (i-j) >= 0 && str[j - (i-j)] == 'G') ans--;
			} else if (str[i] != 'B' && str[j] != 'B') {
				ans += psB[j];
				if (j - (i-j) >= 0 && str[j - (i-j)] == 'B') ans--;
			}
		}
	}
	cout << ans << "\n";
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const int MOD=1e9+7;

ll dp[110][4][4][4];

bool ng(int a,int b,int c){
  return a==1&&b==2&&c==3;
}

bool check(int a,int b,int c,int d){
  if(ng(a,b,c)||ng(b,c,d))return false;
  if(ng(b,a,c)||ng(a,c,d))return false;
  if(ng(a,c,b)||ng(c,b,d))return false;
  if(ng(a,b,d)||ng(b,d,c))return false;
  return true;
}

ll f(int idx,int a,int b,int c){
  if(~dp[idx][a][b][c])return dp[idx][a][b][c];
  if(!check(a,b,c,-1))return 0;
  if(!idx)return 1;
  ll res=0;
  for(int i=0;i<4;i++)if(check(i,a,b,c))res+=f(idx-1,i,a,b);
  return dp[idx][a][b][c]=res%MOD;
}

signed main(){
  memset(dp,-1,sizeof(dp));
  int n;cin>>n;
  cout<<f(n,5,5,5)<<endl;
}


Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using static System.Console;
using static System.Convert;
using static System.Math;
using static Extentions;

class IO
{
    int idx;
    string[] input = In.ReadToEnd().Split(new[] { " ", "\n", "\r" },
        StringSplitOptions.RemoveEmptyEntries);

    T Get<T>(Func<string, T> parser) => parser(input[idx++]);

    public string S => Get(s => s);
    public char C => Get(char.Parse);
    public int I => Get(int.Parse);
    public long L => Get(long.Parse);
    public double F => Get(double.Parse);
    public decimal D => Get(decimal.Parse);
    public BigInteger B => Get(BigInteger.Parse);

    T[] Gets<T>(int n, Func<string, T> parser)
        => input.Skip((idx += n) - n).Take(n).Select(parser).ToArray();

    public string[] Ss(int n) => Gets(n, s => s);
    public char[] Cs(int n) => Gets(n, char.Parse);
    public int[] Is(int n) => Gets(n, int.Parse);
    public long[] Ls(int n) => Gets(n, long.Parse);
    public double[] Fs(int n) => Gets(n, double.Parse);
    public decimal[] Ds(int n) => Gets(n, decimal.Parse);
    public BigInteger[] Bs(int n) => Gets(n, BigInteger.Parse);

    public void Write<T>(params T[] xs) => WriteLine(string.Join(" ", xs));
    public void Write(params object[] xs) => WriteLine(string.Join(" ", xs));
}

#region Library

static class Extentions
{
}

#endregion

static class Program
{
    public static void Main()
    {
        var sw = new StreamWriter(OpenStandardOutput()) { NewLine = "\n" };
#if DEBUG
        sw.AutoFlush = true;
#else
        sw.AutoFlush = false;
#endif
        SetOut(sw);
        Solve(new IO());
        Out.Flush();
    }

    static void Solve(IO io)
    {
        var x = io.I;
        var t = io.I;

        io.Write(Max(0, x - t));
    }
}

Measured memory_bytes: 11220
object Main extends App {
	val pw = new java.io.PrintWriter(System.out)

	val n = Scanner.next.map(_.toInt - 48)

	pw.println(if (n.sum % 9 == 0) "Yes" else "No")
	pw.flush()
}

object Scanner {
	private val buf = new Array[Byte](1024); private var ptr = 0; private var len = 0

	@inline private def isPrintableChar(c: Int): Boolean = 33 <= c && c <= 126
	@inline private def hasNextByte(): Boolean = if (ptr >= len) { ptr = 0; len = System.in.read(buf); len > 0 } else true
	@inline private def hasNext(): Boolean = {
		while (hasNextByte() && !isPrintableChar(buf(ptr))) ptr += 1
		hasNextByte()
	}
	@inline private def readByte(): Byte = if (hasNextByte()) { val res = buf(ptr); ptr += 1; res } else -1

	def next(): String = {
		if(!hasNext()) ???
		val sb = new StringBuilder; var b = readByte()
		while (isPrintableChar(b)) { sb.append(b.toChar); b = readByte() }
		sb.toString
	}

	def nextInt(): Int = {
		val n = nextLong()
		if (n < Int.MinValue || Int.MaxValue < n) ???
		n.toInt
	}

	def nextLong(): Long = {
		if(!hasNext()) ???
		var minus = false; var b = readByte()
		if (b == '-') { minus = true; b = readByte() }

		@scala.annotation.tailrec
		def go (b: Byte, n: Long = 0): Long = if ('0' <= b && b <= '9') go(readByte(), n * 10 + b - '0') else if (minus) -n else n

		go(b)
	}

	def nextDouble(): Double = next().toDouble
}

Measured memory_bytes: 57008
#include<bits/stdc++.h>
#define pii pair<int,int>
#define fi first
#define se second
#define int long long
#define pb push_back
#define mod 1000000007
#define pll pair<long long,long long>
using namespace std;
long long power(long long a,long long b){
    long long ans=1;
    while(b>0){
        if(b&1){ans=(ans*a)%mod;}
                a=(a*a)%mod;
                b>>=1;
        }
    return ans;
        
}
bool prime[100005];
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int k;
    cin>>k;
    int n=100005;
    for(int i=1;i<=n;i++){
	    prime[i]=true;
    } 
    prime[0]=false;
    prime[1]=false;
    for(int i=2;i<=n;i++){
    	if(prime[i]){
    		for(int j=2*i;j<=n;j+=i){
    			prime[j]=false;
    		}
    	}
    }
    while(1){
       if(prime[k]){
           cout<<k;
           return 0;
       } 
       else k++;
    }
    return 0;
}
    

Measured memory_bytes: 3696
#include <stdio.h>
#include <string.h>

int main(void)
{
    int n;
    scanf("%d", &n);

    char s[101];
    scanf("%s", s);

    int ans=0;

    for (int i=1; i<n; i++)
    {
        int cnt=0;
        
        for (char c='a'; c<='z'; c++)
        {
            int founda=0;
            int foundb=0;

            for (int j=0; j<i; j++)
            {
                if (s[j]==c) founda=1;
            }

            for(int j=i; j<n; j++)
            {
                if (s[j]==c) foundb=1;
            }

            if (founda && foundb) cnt++;
        }

        if (ans < cnt) ans = cnt;
    }

    printf("%d", ans);
    return 0;
}

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

// boost
#include <boost/multiprecision/cpp_int.hpp>
using boost::multiprecision::cpp_int;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;
using vld = vector<ld>;
using vvld = vector<vld>;

typedef pair<ll, ll> P;

#define bit(n) (1LL << (n))

//#define int long long

#define all(v) v.begin(), v.end()

#define rep(i, n) for (ll i = 0; i < n; i++)
#define REP(i, n) for (ll i = 1; i < n; i++)

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

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

#define mod (ll)(1e9 + 7)
// #define mod (998244353ll)

const long long INF = 1LL << 60;

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);

  ll a, b, c;
  cin >> a >> b >> c;

  ll k;
  cin >> k;

  ll cnt = 0;
  while (b <= a) {
    b *= 2;
    cnt++;
  }
  while (c <= b) {
    c *= 2;
    cnt++;
  }

  if (cnt <= k) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 3612
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#include <deque>
#include <iterator>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
template<class T> inline bool chmax(T& a, T b) {if (a<b) {a=b; return true;} return false;}
template<class T> inline bool chmin(T& a, T b) {if (a>b) {a=b; return true;} return false;}

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

int main() {
  ll n; cin >> n;
  map<ll, ll> card;
  REP(i, n) {
    ll a; cin >> a;
    card[a]++;
  }
  ll ans = 0;
  for (auto c: card) {
    ans += c.second-1;
  }
  cout << n-ans-ans%2 << endl;
  return 0;
}


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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<vector<ll>> VV;
typedef vector<vector<int>> VVi;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF=1e16+18;
const ll MAX=100005;
const ll MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n,m,arr) rep(i,n){rep(j,m){cerr<<arr[i][j]<<" ";}cerr<<endl;}
#define dbgdp(n,arr) rep(i,n){cerr<<arr[i]<<" ";}cerr<<endl;
#define sum(v) accumulate(ALL(v),0)
#define fi first
#define se second

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<std::setprecision(10);

    ll n;
    cin>>n;

    ll a1,a2,b1,b2,c1,c2;
    cin>>a1>>b1>>c1>>a2>>b2>>c2;
    Vec w;
    Vec v;

    w.pb(a1);
    w.pb(b1);
    w.pb(c1);
    v.pb(a2-a1);
    v.pb(b2-b1);
    v.pb(c2-c1);

    VV dp(4,Vec(n+1,0));
    // dp i j で i番目まで重さj以内の価値

    rep(i,3)rep(j,n+1){
        if(j<w[i]){
            dp[i+1][j]=dp[i][j];
        }else{
            dp[i+1][j] = max(dp[i][j],dp[i+1][j-w[i]]+v[i]);
        }
    }

    ll m = n + dp[3][n];
    w.resize(0);
    v.resize(0);
    w.pb(a2);
    w.pb(b2);
    w.pb(c2);
    v.pb(-a2+a1);
    v.pb(-b2+b1);
    v.pb(-c2+c1);

    VV dp2(4,Vec(m+1,0));
    rep(i,3)rep(j,m+1){
            if(j<w[i]){
                dp2[i+1][j]=dp2[i][j];
            }else{
                dp2[i+1][j] = max(dp2[i][j],dp2[i+1][j-w[i]]+v[i]);
            }
        }

    ll ans=dp2[3][m] + m;
    cout<<ans<<endl;
    return  0;
}


Measured memory_bytes: 977024
#include <cstdio>
#include <iostream>
#include <cmath>
using namespace std;

#define equals(a, b) (fabs((a)-(b)) < EPS)
const double EPS = (1e-10);

class Point {
public:
    double x, y;

    Point(double x = 0, double y = 0): x(x), y(y) {}

    Point operator + (Point p) {
        return Point(x+p.x, y+p.y);
    }
    Point operator - (Point p) {
        return Point(x-p.x, y-p.y);
    }
    Point operator * (double a) {
        return Point(x*a, y*a);
    }
    Point operator / (double a) {
        return Point(x/a, y/a);
    }

    double abs() {
        return sqrt(norm());
    }
    double norm() {
        return x*x + y*y;
    }

    bool operator < (const Point &p) const {
        return x != p.x ? x < p.x : y < p.y;
    }

    bool operator == (const Point &p) const {
        return fabs(x-p.x) < EPS && fabs(y-p.y) < EPS;
    }
};

typedef Point Vector;
// 内積
double dot(Vector a, Vector b) {
    return a.x*b.x + a.y*b.y;
}

class Segment {
public:
    Point p1, p2;

    Segment(Point p1, Point p2): p1(p1), p2(p2) {}
};

// 射影
Point project(Segment s, Point p) {
    Vector base = s.p2 - s.p1;
    Vector hypo = p - s.p1;
    double r = dot(hypo, base) / base.norm();
    return s.p1 + base*r;
}

int main(void) {
    double x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    Segment s(Point(x1, y1), Point(x2, y2));

    int q; cin >> q;
    double x, y;
    for (int i = 0; i < q; i++) {
        cin >> x >> y;
        Point ans = project(s, Point(x, y));

        printf("%.9f %.9f\n", ans.x, ans.y);
    }

    return 0;
}

Measured memory_bytes: 1236
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n)cin >> a[i];

    int ans = 1001001001;
    for(int i = -100; i <= 100; i++){
        int sum = 0;
        rep(j, n){
            sum += (i - a[j]) * (i - a[j]);
        }
        ans = min(ans, sum);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
typedef long long ll;
namespace mp = boost::multiprecision;
using Mint = mp::cpp_int;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = int(a); i < int(b); i++)
#define all(v) v.begin(), v.end()
#define uni(v) v.erase(unique(all(v)), v.end())
#define sort_g(v) sort(all(v), greater<int>())
#define dump(x) cerr << #x << ' ' << '=' << ' ' << x << endl

int main() {
    int N, D;
    cin >> N >> D;
    vector<vector<int>> p(N, vector<int>(D));
    rep(i, N) {
        rep(j, D) {
            cin >> p.at(i).at(j);
        }
    }

    int cnt = 0;
    rep(i, N - 1) {
        repi(j, i + 1, N) {
            double dist = 0;
            rep(k, D) {
                dist += pow(abs(p.at(i).at(k) - p.at(j).at(k)), 2);
            }
            dist = pow(dist, 0.5);
            double dist_f = floor(dist);
            if(dist == dist_f) cnt++; dump(dist);
        }
    }

    cout << cnt << endl;
}

Measured memory_bytes: 256
N,K = map(int,input().split())
ans = 0.0

for i in range(1,N+1):
  if i >= K:
    ans=ans+1.0/N
    continue;
    
  hi=100
  lo=0
  while hi-lo>1:
    mid=(hi+lo)//2
    if i*(2**mid)>=K:
      hi=mid
    else:
      lo=mid
    
  ans=ans+1.0/N*(0.5**hi)
  
print(ans)  


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

const ll INF = 1E+18;

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

    int A[N];
    rep(i, N) cin >> A[i];

    ll ans = INF;
    for (int bit=1; bit < (1<<N); bit++) {
        if (__builtin_popcount(bit) != K) continue;
        int front_highest = 0;
        ll cost = 0;
        rep(i, N) {
            if (bit & (1<<i)) {
                cost += max(front_highest - A[i] + 1, 0);
                front_highest++;
            }
            front_highest = max(front_highest, A[i]);
        }
        ans = min(ans, cost);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

ans = min(a) + min(b)
for i in range(M):
  x, y, c = map(int, input().split())
  ans = min(ans, a[x-1] + b[y-1] - c)

print(ans)

Measured memory_bytes: 18612
N, A = map(int, input().split())

b = list(map(int, input().split()))


b.sort()

ans = 0

for i in range(N):
	if A>=b[i]:
		ans = ans+1
		A = A - b[i]
else:
	if A>0 and N==ans:
		ans = ans-1

print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define ALL(vec) vec.begin(), vec.end()
#define rALL(vec) vec.rbegin(), vec.rend()
using namespace std;
using ll = long long;
// ------------------------------

int main() {
    int N;
    cin >> N;
    vector<int> vec(N);
    rep(i, N) cin >> vec[i];
    sort(rALL(vec));
    int cnt = 0;
    int before = vec[0];
    ll tmp1 = 0, tmp2 = 0;
    bool flag = false;
    rep(i, N) {
        int cnt = 0;
        if (vec[i] == before) {
            while (vec[i] == before) i += 1, cnt += 1, flag = true;
        }
        if (cnt >= 2) if (!tmp1) tmp1 = before, cnt -= 2;
        if (cnt >= 2) {tmp2 = before; break;}
        before = vec[i];
        if (flag) i -= 1, flag = false;
    }
    cout << tmp1*tmp2 << endl;
    return 0;
}


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

int main(){
    string s;
    cin >> s;
    int n = s.size();
    long long sum = 0;
    for(int i = 0; i<pow(2,n-1);i++){
        long long a = s[0]-'0';
        for(int j = 0;j<n-1; j++){
            if(i>>j & 1 == 1){
                sum += a;
                a = s[j+1] -'0';
            }else{
                a = 10*a;
                a += s[j+1] - '0';
            }
        }
        sum += a;
    }
    cout << sum << endl;
}

Measured memory_bytes: 640