akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <numeric>
#define rep(i, m, n) for(int i = m;i < n;i++)
#define repr(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define INF 999999999
using namespace std;

int main(){
    int n; cin >> n;
    int color[8] = {0}; //最初ブールでやったら失敗した
    int wild_card = 0;
    int rate;

    rep(i, 0, n){
        cin >> rate;
        if(rate <= 399) color[0] = 1;
        else if(rate <= 799) color[1] = 1;
        else if(rate <= 1199) color[2] = 1;
        else if(rate <= 1599) color[3] = 1;
        else if(rate <= 1999) color[4] = 1;
        else if(rate <= 2399) color[5] = 1;
        else if(rate <= 2799) color[6] = 1;
        else if(rate <= 3199) color[7] = 1;
        else wild_card += 1;
    }
    //色の種類数を求める
    int min = 0;
    rep(i, 0, 8) if(color[i] == 1) min += 1;

    int max;
    max = min + wild_card;
    //if(max > 8) max = 8;
    if(n == wild_card) min = 1;

    cout << min << " " << max << endl;

    //rep(i, 0, 8) cout << color[i] << " ";

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
const int maxV = 90010;
const int maxN = 1e5+10;
const int inf = 0x3f3f3f3f;
const ll MOD = 1e9+7;
const ll INF = 1000000000000000010LL;
#define X first
#define Y second


int T1,T2;
ll A1,A2,B1,B2;
int main() {
	scanf("%d %d",&T1,&T2);
	scanf("%lld%lld",&A1,&A2);
	scanf("%lld%lld",&B1,&B2);
	ll x = A1-B1;
	ll y = A2-B2;
	if(x < 0)
	{
		x = -x;
		y = -y;
	}
	if( y > 0)
	{
		puts("0");
		return 0;
	}
	else
	{
		ll s1 = x * T1;
		ll s2 = y * T2;
		if(s1+s2 == 0)
		{
			puts("infinity");
		}
		else if(s1 + s2 > 0)
		{
			puts("0");
		}
		else
		{
			ll s3 = -(s1+s2);
			ll cnt = s1/(s3) + (s1%s3 !=0);
			cnt *= 2;
			if(s1 % s3 == 0)
				cnt++; 
			printf("%lld\n",cnt-1); 
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int H, W;
int A[81][81];
int B[81][81];
bool DP[81][81][10000];

int main(int argc, char* argv[]) {
  // H, W
  cin >> H >> W;
  // A
  for(int y=0; y < H; ++y) {
    for(int x=0; x < W; ++x) {cin >> A[y][x];}
  }
  // B
  for(int y=0; y < H; ++y) {
    for(int x=0; x < W; ++x) {cin >> B[y][x];}
  }
  DP[0][0][abs(A[0][0]-B[0][0])]=true;
  for(int y = 0; y < H; ++y){
    for(int x = 0; x < W; ++x){
      for(int i = 0; i < 10000; ++i){
        if(DP[y][x][i]){
          if(x+1 < W) {
            DP[y][x+1][abs(i+(A[y][x+1]-B[y][x+1]))]=true;
            DP[y][x+1][abs(i-(A[y][x+1]-B[y][x+1]))]=true;
          }
          if(y+1 < H) {
            DP[y+1][x][abs(i+(A[y+1][x]-B[y+1][x]))]=true;
            DP[y+1][x][abs(i-(A[y+1][x]-B[y+1][x]))]=true;
          }
        }
      }
    }
  }
  int ans=10000;
  for(int i=0; i < 10000; ++i){
    if(DP[H-1][W-1][i]){ans=min(ans, i);}
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

class Mod{
  public:
    ll mod;
    // mod must be a prime number
    Mod(ll m){
        mod = m;
    }
    //a^p
    ll modpow(ll a, ll p){
        if(p == 0) return 1;
        if(p%2 == 0){
            ll half = modpow(a, p/2);
            return half * half % mod;
        }
        else return a * modpow(a,p-1) % mod;
    }

    //nCr
    ll comb(ll n, ll r){
        if(r > n) return 0;
        if(r > n-r) return comb(n,n-r);
        ll mul = 1;
        ll div = 1;
        for (int i = 0;i < r;i++){
            mul *= n-i;
            mul %= mod;
            div *= i+1;
            div %= mod;
        }
        return mul * modpow(div,mod-2) % mod;
    }
};

ll N,K;

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

    Mod mod(1e9+7);
    cin >> N >> K;

    ll m = 1e9+7;

    for (int i = 1;i <= K;i++){
        ll ans = (mod.comb(N-K+1,i)*mod.comb(K-1,i-1))%m;
        cout << ans << endl;
    }

    return 0;

}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<typename T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<typename T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef tuple<ll,ll,ll> tlll;
typedef tuple<int,int,int> tiii;
const ll mod=1e9+7;
const int inf=1<<30;

map<ll,ll> pfmp; //各素因数の冪指数の総和を格納
vector<ll> pfv(0); //異なる素因数を昇順に格納

void pf(ll N){
  ll n=N;
  if(n<=0) return;
  if(n%2==0){
    if(pfmp[2]==0) pfv.push_back(2);
    while(n%2==0){
      n/=2;
      pfmp[2]++;
    }
  }
  if(n==1) return;
  for(ll i=3;i<=sqrt(N);i+=2){
    if(n%i==0){
      if(pfmp[i]==0) pfv.push_back(i);
      while(n%i==0){
        n/=i;
        pfmp[i]++;
      }
    }
  }
  if(n!=1){
    if(pfmp[n]==0) pfv.push_back(n);
    pfmp[n]++;
  } 
  //sort(all(pfv));
}

int main(){
  ll n; cin >> n;
  pf(n);
  sort(all(pfv));
  ll ans=0;
  rep(i,pfv.size()){
    ll j=1;
    while(pfmp[pfv[i]]-j>=0){
      ans++;
      pfmp[pfv[i]]-=j;
      j++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3696
#include <stdio.h>
int minx(int v[],int n){
	int i,j,k,tmp;
	tmp=v[0];
	for(i=1;i<=n-1;i++){
		if(tmp>v[i])
		tmp=v[i];}
		return tmp;}
int maxx(int v[],int n){
	int i,j,k,tmp;
	tmp=v[0];
	for(i=1;i<=n-1;i++){
		if(tmp<v[i])
		tmp=v[i];}
		return tmp;}
int abs(int n){
		if(n<0){
		return -1*n;}else
		return n;}
int max(int n1,int n2,int n3){
	int tmp;
	tmp=n1;
	if(n2>tmp)
	tmp=n2;
	if(n3>tmp)
	tmp=n3;
	return tmp;}
int max2(int n1,int n2){
	int tmp;
	tmp=n1;
	if(n2>tmp)
	tmp=n2;
	return tmp;}
int min3(int n1,int n2,int n3){
	int tmp;
	tmp=n1;
	if(n2<tmp)
	tmp=n2;
	if(n3<tmp)
	tmp=n3;
	return tmp;}
int min2(int n1,int n2){
	int tmp;
	tmp=n1;
	if(n2<tmp)
	tmp=n2;
	return tmp;}
int main(void)
{int N,A,M,B,j,x,i,k,H,W,l,sum,m,mint,flag;
	scanf("%d",&N);
	int a[100];
	int t[100];
	int index[9]={0,1,2,3,4,5,6,7,8};
	flag=0;
	sum=0;
	mint=0;
	for(i=0;i<=N-1;i++){
		scanf("%d",&a[i]);}
	for(x=0;x<=7;x++){
		for(j=0;j<=N-1;j++){
			if(index[x]==a[j]/400){
				sum+=1;
				break;}}}
	for(k=0;k<=N-1;k++){
		if(a[k]/400>=8){
			mint+=1;}}
	if(sum>=8){
		printf("8 ");
		printf("%d",8+mint);}
		else if(sum!=0){
			printf("%d ",sum);
			printf("%d",sum+mint);}
				else{printf("1 ");
				printf("%d",mint);}
					
	
			
	



	return 0;
}


Measured memory_bytes: 128
N = int(input())
T,A = map(int, input().split())
H = list(map(int, input().split()))


ans_l = []

for i in range(N):
    mater = H[i]
    Temp = (T - (mater*0.006))
    ans = abs(A - Temp)
    ans_l.append(ans)


ans_mini = min(ans_l)

ans_posi =[]

for h in range(N):
    if ans_l[h] == ans_mini:
        ans2 = h+1
        ans_posi.append(ans2)


for j in ans_posi:
    print(j,end="")

Measured memory_bytes: 3064
import math

n, d = map(int, input().split())
x = [list(map(int, input().split())) for _ in range(n)]

c = 0
for i in range(n):
    for j in range(i + 1, n):
        dist = math.sqrt(sum((x[i][k] - x[j][k]) ** 2 for k in range(d)))
        if dist.is_integer():
            c += 1

print(c)


Measured memory_bytes: 38384
import math
import numpy as np
H, W = list(map(int, input().split()))
N = input()
colors = list(map(int, input().split()))

cumsum_colors = np.cumsum(colors)

color_ind = 0
arr = [0 for _ in range(H*W)]
for i in range(H*W):
    if i >= cumsum_colors[color_ind]:
        color_ind += 1
    arr[i] = color_ind + 1

for h in range(H):
    if h%2 == 0:
        print(" ".join(map(str, arr[h*W:(h+1)*W])))
    else:
        print(" ".join(map(str, reversed(arr[h*W:(h+1)*W]))))

Measured memory_bytes: 14452
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;


const int mod = 1000000007;
struct Mod {
public:
	int num;
	Mod() : Mod(0) { ; }
	Mod(long long int n) : num((n % mod + mod) % mod) {
		static_assert(mod<INT_MAX / 2, "mod is too big, please make num 'long long int' from 'int'");
	}
	Mod(int n) : Mod(static_cast<long long int>(n)) { ; }
	operator int() { return num; }
};

Mod operator+(const Mod a, const Mod b) { return Mod((a.num + b.num) % mod); }
Mod operator+(const long long int a, const Mod b) { return Mod(a) + b; }
Mod operator+(const Mod a, const long long int  b) { return b + a; }
Mod operator++(Mod &a) { return a + Mod(1); }
Mod operator-(const Mod a, const Mod b) { return Mod((mod + a.num - b.num) % mod); }
Mod operator-(const long long int a, const Mod b) { return Mod(a) - b; }
Mod operator--(Mod &a) { return a - Mod(1); }
Mod operator*(const Mod a, const Mod b) { return Mod(((long long)a.num * b.num) % mod); }
Mod operator*(const long long int a, const Mod b) { return Mod(a)*b; }
Mod operator*(const Mod a, const long long int b) { return Mod(b)*a; }
Mod operator*(const Mod a, const int b) { return Mod(b)*a; }
Mod operator+=(Mod &a, const Mod b) { return a = a + b; }
Mod operator+=(long long int &a, const Mod b) { return a = a + b; }
Mod operator-=(Mod &a, const Mod b) { return a = a - b; }
Mod operator-=(long long int &a, const Mod b) { return a = a - b; }
Mod operator*=(Mod &a, const Mod b) { return a = a * b; }
Mod operator*=(long long int &a, const Mod b) { return a = a * b; }
Mod operator*=(Mod& a, const long long int &b) { return a = a * b; }
Mod operator^(const Mod a, const int n) {
	if (n == 0) return Mod(1);
	Mod res = (a * a) ^ (n / 2);
	if (n % 2) res = res * a;
	return res;
}
Mod mod_pow(const Mod a, const long long  int n) {
	if (n == 0) return Mod(1);
	Mod res = mod_pow((a * a), (n / 2));
	if (n % 2) res = res * a;
	return res;
}
Mod inv(const Mod a) { return a ^ (mod - 2); }
Mod operator/(const Mod a, const Mod b) {
	assert(b.num != 0);
	return a * inv(b);
}
Mod operator/(const long long int a, const Mod b) {
	return Mod(a) / b;
}
Mod operator/=(Mod &a, const Mod b) {
	return a = a / b;
}

#define MAX_MOD_N 1024000

Mod fact[MAX_MOD_N], factinv[MAX_MOD_N];
void init(const int amax = MAX_MOD_N) {
	fact[0] = Mod(1); factinv[0] = 1;
	for (int i = 0; i < amax - 1; ++i) {
		fact[i + 1] = fact[i] * Mod(i + 1);
		factinv[i + 1] = factinv[i] / Mod(i + 1);
	}
}
Mod comb(const int a, const int b) {
	return fact[a] * factinv[b] * factinv[a - b];
}

int main() {
	int H, W, A, B; cin >> H >> W >> A >> B;
	int xply = B + H - A-1;
	init();
	vector<Mod>mods(max(H,W));
	Mod ans = 0;
	for (int x = 0; x < W; ++x) {
		int y = xply - x;
		if (y >= 0 && y < H) {
			if (y < H-A || x >= B) {

				Mod a = comb(x + y, x);
				Mod b = comb(H + W - x - y - 2, W - x - 1);
				mods[x] = a*b;
				ans += a*b;
			}
		}
	}
	cout << ans << endl;
	

	return 0;
}

Measured memory_bytes: 8576
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pb push_back
#define f first
#define s second
#define MOD 1000000007
 
using namespace std;

vector<int> v[100001];
void solve(){
	int n,k; cin>>n>>k;
	int r,s,p;
	cin>>r>>s>>p;
	string S; cin>>S;
	for(int i=0; i<n; i++){
		if(S[i] == 'r'){
			v[i%k].pb('p');
		}
		if(S[i] == 'p'){
			v[i%k].pb('s');
		}
		if(S[i] == 's'){
			v[i%k].pb('r');
		}
	}
	ll ans = 0;
	for(int i=0; i<k; i++){
		int c =1;
		for(int j=0; j<v[i].size(); j++){
			if(v[i][j] == v[i][j+1] && j != v[i].size()-1){
				c++;
			}
			else{
				int x;
				if(v[i][j] == 'r') x = r;
				if(v[i][j] == 's') x = s;
				if(v[i][j] == 'p') x = p;
				ans += ((c+1)/2)*x; 
				c=1;
			}
		}
	}

	cout<<ans;
}



int main()
{ 
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//cout<<fixed<<setprecision(12);
	
	int t =1; 
	//cin>>t;

	for(int i=1; i<=t; i++){
		solve();
		cout<<"\n";
	}
	return 0;

}




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

using namespace std;

int main(){
  int match[] = {-1,2,5,5,4,5,6,3,7,6};
  int n, m;
  cin >> n >> m;

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

  vector<int> dp(n+10, -1);
  dp[0] = 0;
  for (int i = 0; i < n; i++) {
    if (dp[i] == -1) { continue; }
    for (int j = 0; j < m; j++) {
      dp[i + match[a[j]]] = max(dp[i + match[a[j]]], dp[i] + 1);
    }
  }
  string ans = "";
  sort(a.begin(), a.end(), greater<int>());
  while (n > 0) {
    for (int i = 0; i < m; i++) {
      int rem = n - match[a[i]];
      if (rem < 0) { continue; }
      if (dp[rem] == -1) { continue; }
      if (dp[rem] == dp[n] - 1) {
        ans += (char)('0' + a[i]);
        n -= match[a[i]];
        break;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main() {
  int n, mina = INF, tot = 0;
  cin >> n;
  vector<int> s(n);

  rep(i, n) {
    cin >> s[i];
    if (s[i] % 10 != 0) mina = min(mina, s[i]);
    tot += s[i];
  }

  if (tot % 10 != 0)
    cout << tot << endl;
  else if (mina % 10 != 0)
    cout << tot - mina << endl;
  else
    cout << 0 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int n = 0;
int m = 0;

int main(){
    int N, P;
    cin >> N >> P;
    for(int i = 0; i < N; i++){
        int k;
        cin >> k;
        if(k % 2 == 0){
            m++;
        } else n++;
    }
    if(n == 0){
        if(P == 1){
            cout << 0 << endl;
        } else {
            cout << (1ll << m) << endl;
        }
    } else {
        cout << ( (1ll << m) * (1ll << (n-1))) << endl;
    }
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

	static final double EPS = 1e-8;

	class Point{
		double x, y;
		Point(double _x, double _y){
			this.x = _x;
			this.y = _y;
		}
		Point add(Point a){
			return new Point(this.x + a.x, this.y + a.y);
		}
		Point sub(Point a){
			return new Point(this.x - a.x, this.y - a.y);
		}
		double abs(){
			return Math.hypot(this.x, this.y);
		}
	}

	double iprod(Point p, Point q){
		return p.x*q.x + p.y*q.y;
	}

	double oprod(Point p, Point q){
		return p.x*q.y - p.y*q.x;
	}

	double distanceLinePoint(Point p1, Point p2, Point q){
		return Math.abs(oprod(p2.sub(p1), q.sub(p1))) / p2.sub(p1).abs();
	}

	double distanceSegmentPoint(Point p1, Point p2, Point q){
		if(iprod(p2.sub(p1), q.sub(p1)) < EPS) return q.sub(p1).abs();
		if(iprod(p1.sub(p2), q.sub(p2)) < EPS) return q.sub(p2).abs();
		return distanceLinePoint(p1,p2,q);
	}

	Point[] Cs;
	double[] Rs;

	void run(){
		Scanner in = new Scanner(System.in);
		for(int n=in.nextInt(); n>0; n = in.nextInt()){
			Cs = new Point[n];
			Rs = new double[n];
			for(int i=0; i<n; i++){
				double x = in.nextDouble(), y = in.nextDouble(), r = in.nextDouble();
				Cs[i] = new Point(x,y);
				Rs[i] = r;
			}
			int m = in.nextInt();
			for(int i=0; i<m; i++){
				double tx = in.nextDouble(), ty = in.nextDouble(),
						sx = in.nextDouble(), sy = in.nextDouble();
				System.out.println(solve(new Point(tx, ty), new Point(sx, sy))?"Danger":"Safe");
			}
		}
	}

	boolean check(Point p, Point q, Point center, double r){
		if((p.sub(center).abs() < r - EPS)^(q.sub(center).abs() < r - EPS)){
			return false;
		}
		if(p.sub(center).abs() < r - EPS){
			return true;
		}
		return distanceSegmentPoint(p,q,center) > r + EPS;
	}

	boolean solve(Point p, Point q){
		for(int i=0; i<Cs.length; i++){
			if(!check(p, q, Cs[i], Rs[i])) return false;
		}
		return true;
	}

	public static void main(String args[]){
		new Main().run();
	}
}

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

ll A, B , K;

int main(){
  cin >> A >> B >> K;
  if(A > K){
    cout << A - K << " "<< B << endl;
    return 0;
  }else{
    ll buf = K - A;
    if(B > buf){
      cout << 0 << " "<<  B -buf << endl;
    }else{
      cout << 0 << " "<< 0 << endl;
    }
    return 0;

  }

}


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

#define all(A) begin(A), end(A)
#define rall(A) rbegin(A), rend(A)
#define sz(A) int(A.size())
#define pb push_back

using namespace std;

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

int main () {
  ios::sync_with_stdio(false); cin.tie(0);
  int n;
  cin >> n;
  vector <int> arr(n);
  for (int i = 0; i < n; i++) cin >> arr[i];
  multiset <double> st(all(arr));
  while (sz(st) > 1) {
    double u = *begin(st);
    st.erase(begin(st));
    double v = *begin(st);
    st.erase(begin(st));
    st.insert((u + v) / 2.0);
  }
  cout << fixed << setprecision(15) << *begin(st) << '\n';
  return (0);
}


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

int main() {
  int a,b;
  cin>>a>>b;
  if(a>b) swap(a,b);
  for(int i=0;i<b;i++) cout<<a;
  cout<<endl;
}	


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        
        // 定数
        
        Scanner sc = new Scanner(System.in);
        //Scanner sc = new Scanner("abcdabcd");
        
        // 文字とその出現階数をもつMap
        Map<String, Integer> strMap = new HashMap<>();
        
        // 文字列を1文字ずつ配列に格納する
        String[] strArray = sc.next().split("");
        
        for(String str : strArray) {
            // Mapに文字が存在するかどうか確認する
            if(strMap.containsKey(str)) {
                // すでに存在する場合は出現回数を+1して再格納する
                int count = strMap.get(str);
                strMap.put(str, count + 1);
            } else {
                strMap.put(str, 1);
            }
        }
        
        // 美しい文字列フラグ（trueで初期化）
        String isBeautifulStr = "Yes";
        
        for(String key : strMap.keySet()) {
            int count = strMap.get(key);
            
            // 出現回数が偶数でない場合はフラグをfalseにする
            if(count % 2 != 0) {
                isBeautifulStr = "No";
            }
        }
        
        System.out.println(isBeautifulStr);
        
    }
    
}


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

int main(){
    int a,b;
    cin >> a >> b;
    int max = a+b;
    if(max<a-b)max =a-b;
    if(max<a*b)max = a*b;
    cout << max << endl;
    return 0;
}

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

int main() {
    int n, a[100];

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

    int maxi = 0;
    for(int i = 0; i < n; i++) {
        for(int j = i + 1; j < n; j++) {
            maxi = max(maxi, abs(a[i] - a[j]));
        }
    }
    cout << maxi << endl;
}


Measured memory_bytes: 256
from itertools import combinations_with_replacement
import sys

def LI(): return map(int, sys.stdin.readline().rstrip().split())

N, M, Q = LI()

Q_groups = []
for _ in range(Q):
    Q_groups.append([*LI()])

max_score = 0
for p in combinations_with_replacement(range(1, M + 1), r=N):
    temp_score = 0
    for q in Q_groups:
        if p[q[1] - 1] - p[q[0] - 1] == q[2]:
            temp_score += q[3]
    max_score = max(max_score, temp_score)

print(max_score)

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

void update_weights(int &w0, int &w1, int n0, int n1, int n2, int n3)
{	
	int o0, o1;
	o0 = min(w0 + abs(n2 - n0), w1 + abs(n2 - n1));
	o0 = min(o0, w0 + abs(n1 - n0) + abs(n2 - n1));

	o1 = min(w1 + abs(n3 - n1), w1 + abs(n2 - n1) + abs(n3 - n1));
	o1 = min(o1, w0 + abs(n1 - n0) + abs(n3 - n1));
	o1 = min(o1, w0 + abs(n2 - n0) + abs(n3 - n2));
	w0 = o0;
	w1 = o1;
}


int main()
{
	int N;
	cin >> N;
	vector<int> a(N);
	for (int i=0;i<N;i++)
		cin >> a[i];
		
	int w0, w1;
	w0 = abs(a[0] - a[1]);
	w1 = min(abs(a[2] - a[0]), w0 + abs(a[2] - a[1]));
	int output;
	if (N == 2)
	{
	    cout << abs(a[1] - a[0]);
	}
	else if (!(N % 2)) // N is even
	{
		for (int i = 1; i <= N - 5; i += 2)
		{
			update_weights(w0, w1, a[i], a[i+1], a[i+2], a[i+3]);
		}
		output = min(w0 + abs(a[N - 1] - a[N - 3]), w1 + abs(a[N - 1] - a[N - 2]));
		cout << output;
	}
	else
	{
		for (int i = 1; i <= N - 4; i += 2)
		{
			update_weights(w0, w1, a[i], a[i+1], a[i+2], a[i+3]);
		}
		cout << w1;
	}

	return 0;
}


Measured memory_bytes: 640
#include <stdio.h>

#define MAX 1000002

void initary( int * ary, int num ) 
{
	int i = 0;

	for ( i = 0 ; i < num ; i++ ) {
		*(ary+i) = -1; 
	}
}

int main()
{
	int  p = 0, q = 0, i = 0, j = 0;
	int extra[MAX];

	while ( scanf( "%d %d\n", &p, &q ) != EOF ) {
		initary( extra, MAX ); 
		// extraには余りの出現した位置を格納するため, 
		// 格納されうる値で初期化できないため, 初期化時には-1を代入する

		extra[p] = 0; // pはqで割り切れないため, 最初の余りの数はpとなる
		i = 1;  // 最初の余りはpであるため, 次の余りの位置は1からスタートとなる
		while ( 1 ) {
			p *= 10;
			// printf( "[%d]:[%d] = %d\n", p/q, p%q, extra[p%q] );
			printf( "%d", p/q );
			p %= q;
			if ( p == 0 ) {
				printf( "\n" );
				break;
			} 
			
			if ( extra[p] >= 0 ) {
				printf( "\n" );
				for ( j = 0 ; j < i ; j++ ) {
					if ( j < extra[p] ) {
						printf( " " );
					} else if ( j >= extra[p] ) {
						printf( "^" );
					}
				}
				printf( "\n" );
				break;
			}
			extra[p] = i; // 余りpが出現した位置iを記録する
			i++;
		}
	}
	return 0;
}



Measured memory_bytes: 5644
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		// TODO 自動生成されたメソッド・スタブ
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String input = br.readLine();
		int n = Integer.parseInt(input);

		String[] tmpArray = br.readLine().split(" ");

		long originalCost = 0;
		int position[] = new int[n + 2];

//		long dp[] = new long[n + 1];
//		int maxX = Integer.MIN_VALUE;
//		int minX = Integer.MAX_VALUE;

//		int[] sortArray = new int[n];
		for(int i = 0; i < n; i++){
			position[i + 1] = Integer.parseInt(tmpArray[i]);
			originalCost += Math.abs(position[i + 1] - position[i]);

//			if(i == 0){
//				dp[i] = Math.abs( position[i]);
//			}
//			else {
//				dp[i] = dp[i - 1] + Math.abs(position[i] - position[i - 1]);
//			}
//			sortArray[i] = position[i];

//			maxX = Math.max(maxX, position[i]);
//			minX = Math.min(minX, position[i]);
		}
		
		originalCost += Math.abs(position[n]);

//		dp[n] = dp[n - 1] + Math.abs(position[n - 1]);

//		Arrays.sort(sortArray);
//		if(sortArray[0] < 0){
//			originalCost += -2*sortArray[0];
//			System.out.println("origin "+originalCost);
//		}
//		if(sortArray[n - 1] > 0){
//			originalCost += 2*sortArray[n - 1];
//			System.out.println("origin "+originalCost);
//		}
//		originalCost = Math.abs(position[0]);
//		System.out.println("origin "+originalCost);
//		for(int i = 1; i < n; i++){
//			originalCost += Math.abs(position[i] - position[i - 1]);
//			System.out.println("origin "+originalCost);
//		}
//		originalCost += Math.abs(position[n - 1]);
//
//		System.out.println("origin "+originalCost);

		for(int i = 1; i <= n; i++){
			long result = originalCost;
			
			int dist1 = position[i] - position[i - 1];
			int dist2 = position[i + 1] - position[i];
//			System.out.println("dist1 "+dist1+" dist2 "+dist2);
			
			//i番目がピークになる場合
			if(dist1 * dist2 < 0){
//				System.out.println("update");
				result -= Math.abs(dist1) + Math.abs(dist2);
				result += Math.abs(position[i + 1] - position[i - 1]);
			}
			
			System.out.println(result);
		}


	}

}


Measured memory_bytes: 51284
// Ver19.03
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define INF (1 << 29) * 2
#define LLINF 4545454545454545454
#define MOD 1000000007
#define ll long long
#define ull unsigned long long
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
int upll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? -1 : *(ll *)a > *(ll *)b ? 1 : 0; }
int downll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? 1 : *(ll *)a > *(ll *)b ? -1 : 0; }
void sortup(ll *a, int n) { qsort(a, n, sizeof(ll), upll); }
void sortdown(ll *a, int n) { qsort(a, n, sizeof(ll), downll); }

int main()
{
  char a, b;
  scanf("%c%*c%c", &a, &b);
  puts(a == b ? "H" : "D");
  return 0;
}


Measured memory_bytes: 128
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (int64_t)(n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

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

  vector<bool> contains(26, false);
  for (char c : s) {
    contains[c - 'a'] = true;
  }

  if (s.size() < 26) {
    rep(i, 26) {
      if (!contains[i]) {
        cout << s << (char)(i + 'a') << endl;
        return 0;
      }
    }
  } else {
    set<char> t;
    rrep(i, s.size()) {
      char c = s[i];
      auto p = t.upper_bound(c);
      if (p != t.end()) {
        cout << s.substr(0, i) << *p << endl;
        return 0;
      }
      t.insert(c);
    }
  }
  cout << -1 << endl;
  return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
int main(){
int A,B,C,D;
  cin>>A>>B>>C>>D;
 while (true) {
        C -= B;
        if (C <= 0) {
            cout << "Yes" << endl;
            break;
        }
        A -= D;
        if (A <= 0) {
            cout << "No" << endl;
            break;
        }
    }
}

Measured memory_bytes: 3628
#include <iostream>

using namespace std;

int main()
{
  long x;
  cin >> x;
  int five_hund = 0;
  int five = 0;

  five_hund = x / 500;
  five = (x - five_hund * 500) / 5;

  cout << five_hund * 1000 + five * 5;

  return 0;
}

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

int main() {
    int N;
    cin >> N;
    string ans = "No";
    for(int i = 0; i <= 9; i++) {
        for(int j = 0; j <= 9; j++) {
            if(N == i*j) {
                ans = "Yes";
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3612
# import sys
# input = sys.stdin.readline

def mp(): return map(int, input().split())
def lmp(): return list(map(int, input().split()))

n = int(input())
point = []
p = []
m = []
for i in range(n):
    a,b = mp()
    point.append((a,b))
    p.append(a+b)
    m.append(a-b)
print(max(max(p)-min(p), max(m)-min(m)))





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

using namespace std;

using VI = vector<int>;
using VVI = vector<VI>;
using VB = vector<bool>;
using VVB = vector<VB>;
using VD = vector<double>;
using VVD = vector<VD>;
using VS = vector<string>;
using PII = pair<int, int>;
using VPII = vector<PII>;
using VL = vector<long long>;
using VVL = vector<VL>;

#define sz(var) (int)var.size()
#define REP(var, start, end) for(int var = start; var < (int)end; ++var)
#define CLEAR(var, with) memset(var, with, sizeof(var))
#define ALL(x) x.begin(), x.end()
#define LL long long
#define ULL unsigned long long
#define TIME cout << "Time elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms" << endl;

int sx, sy, tx, ty;
string shortestPath()
{
	string ret;
	const int dx = tx - sx, dy = ty - sy;
	ret += string(dy, 'U') + string(dx, 'R');
	ret += string(dy, 'D') + string(dx, 'L');
	
	ret += 'L';
	ret += string(dy + 1, 'U') + string(dx + 1, 'R');
	ret += 'D';

	ret += 'R';
	ret += string(dy + 1, 'D') + string(dx + 1, 'L');
	ret += 'U';

	return ret;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
#ifndef ONLINE_JUDGE
	//freopen("tmp.in", "r", stdin);
//	freopen("tmp.out", "w", stderr);
#endif
	cin >> sx >> sy >> tx >> ty;

	cout << shortestPath() << endl;

	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize(3)
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
bool Finish_read;
template<class T>
inline void read(T &x) {
	Finish_read=0;x=0;int f=1;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-1;if(ch==EOF)return;ch=getchar();}
	while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
	x*=f;Finish_read=1;
}
template<class T>
inline void print(T x) {
	if(x/10!=0)
		print(x/10);
	putchar(x%10+'0');
}
template<class T>
inline void writeln(T x) {
	if(x<0)
		putchar('-');
	x=abs(x);
	print(x);
	putchar('\n');
}
template<class T>
inline void write(T x) {
	if(x<0)
		putchar('-');
	x=abs(x);
	print(x);
}
/*================Header Template==============*/
double ans=0.0,f[40005];
int cnt,n,t[105],len,v[105];
int main() {
	read(n);
	for(int i=1;i<=n;i++) {
		read(t[i]);
		len+=t[i]*2;
	}
	f[0]=0;
	for(int i=1;i<=n;i++) {
		read(v[i]);
		for(int j=0;j<t[i]*2;j++) {
			cnt++;
			f[cnt]=min(1.0*f[cnt-1]+0.5,1.0*v[i]);
		}
	}
	cnt=len;
	f[len]=0;
	for(int i=n;i>0;i--)
		for(int j=0;j<t[i]*2;j++) {
			cnt--;
			f[cnt]=min(f[cnt],min(1.0*f[cnt+1]+0.5,1.0*v[i]));
		}
	for(int i=1;i<=len;i++)
		ans+=f[i-1]+f[i];
	printf("%.15lf\n",ans/4.0);
	return 0;
}

Measured memory_bytes: 512
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

namespace B_ABC164
{
    class MainClass
    {

        static int[] s;

        public static void Main(string[] args)
        {
            s = Array.ConvertAll(ReadLine().Split().ToArray(), int.Parse);
            int t = (s[0] + s[3] - 1) / s[3];
            int u = (s[2] + s[1] - 1) / s[1];
            // WriteLine("t : {0} u : {1} ",t,u);
            if (t < u)
            {
                WriteLine("No");
            }
            else if (t == u && s[0] % s[3] == 0 && s[2] % s[1] == 0)
            {
                WriteLine("Yes");
            }

            else if (t == u && s[0] % s[3] == 0)
            {
                WriteLine("No");
            }
            else if (t == u && s[0] % s[3] != 0 && s[2] % s[1] == 0)
            {
                WriteLine("Yes");
            }
            else
            {
                WriteLine("Yes");

            }

        }
    }
}


Measured memory_bytes: 27952
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = (int)1e9 + 7;
const int INF = (int)100100100;

void comb(vector<vector <long long int> > &v){
  for(int i = 0;i <v.size(); i++){
    v[i][0]=1;
    v[i][i]=1;
  }
  for(int k = 1;k <v.size();k++){
    for(int j = 1;j<k;j++){
      v[k][j]=(v[k-1][j-1]+v[k-1][j]);
    }
  }
}

int main() {
    //ll N; cin >> N;
    //ll N,M; cin >> N >> M;
    //string S; cin >> S;
    //ll H,W; cin >> H >> W;
    ll N,P;
    cin >> N >> P;
    ll odd=0,even=0;
    for(int i=0;i<N;i++){
        int a;
        cin >> a;
        if(a%2==0)even++;
        else odd++;
    }
    ll ans=pow(2,N-1);
    if (odd==0){
        if(P==0){
            ans=pow(2,N);
            cout << ans;
        }
        else cout << 0 << endl;
    }
    else cout << ans << endl;
    
}

/*



 */


Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <utility>
#define inf 10e9
using namespace std;

int ip(int a, int b) {
  return !b ? 1 : ip(a, b - 1) * a;
}

int main(void) {
  int n, i, j, ans = inf;
  scanf("%d", &n);
  pair<int, int> a[n];
  for(i = 0; i < n; ++i) scanf("%d%d", &a[i].first, &a[i].second);
  sort(a, a + n);
  for(i = 0; i < n; ++i) {
    for(j = i + 1; j < n; ++j) {
      if(ans < (a[i].first - a[j].first) * (a[i].first - a[j].first)) break;
      if(ans > (a[i].first - a[j].first) * (a[i].first - a[j].first) + (a[i].second - a[j].second) * (a[i].second - a[j].second)) ans = (a[i].first - a[j].first) * (a[i].first - a[j].first) + (a[i].second - a[j].second) * (a[i].second - a[j].second);
    }
  }
  printf("%d\n", ans);
  return 0;
}


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

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

	int ans = 0;

	for (int i = 0; i <= K; i++) {
		for (int j = 0; j <= K; j++) {
			int z = S - i - j;
			if (0 <= z && z <= K) ans++;
		}
	}
	cout << ans << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define fin(ans) cout<<(ans)<<endl
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p,q)
#define pb(n) push_back(n)
#define Sort(a) sort(a.begin(),a.end())
#define Rort(a) sort(a.rbegin(),a.rend())
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;}
const int P = 1000000007;
const int INF = INT_MAX;
const long long LLINF = 1LL<<60;
//g++ -std=c++1z main.cpp
//.\a.exe

int main(void){ios::sync_with_stdio(false);cin.tie(0);
////////////////////////////////////////////////////////
int n,a=0;
cin >> n;
int p[n];
for(int i=0;i<n;i++){
	cin >> p[i];
}

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

if(a>=n-2){
	cout << "YES" << endl;
}
else{
	cout << "NO" << endl;
}




////////////////////////////////////////////////////////
return 0;}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for(ut i=(a);i<(ut)(b);i++)
#define REP(i,b) FOR(i,0,b)
#define ALL(c) c.begin(),c.end()
#define PB push_back
#define debug cout << __LINE__ << endl
using namespace std;
typedef long long LL;
typedef double ld;
typedef LL ut;
typedef vector<ut> VI;
typedef pair<ut,ut> pr;
typedef vector<pr> Vpr;
typedef pair<ut,pr> ppr;
typedef vector<ppr> Vppr;
typedef pair<ut,ut> prs;
inline void IN(ut &x){cin >> x;}
inline void INA(ut n,ut x[]){REP(i,n) cin >> x[i];}
inline void INE(ut m,VI edges[]){
	ut a,b;
	REP(i,m){
		cin >> a >> b;
		edges[a].PB(b);
		edges[b].PB(a);
	}
}
inline void INEC(ut m,Vpr edges[]){
	ut a,b,c;
	REP(i,m){
		cin >> a >> b >> c;
		edges[a].PB(pr(c,b));
		edges[b].PB(pr(c,a));
	}
}
const LL p=7+1e9;
const int SIZE=300005;
LL nums[2][SIZE];
int main(){
	LL N,P,x;
	cin >> N >> P;
	nums[0][0]=1;
	REP(i,N){
		cin >> x;
		x%=2;
		nums[0][i+1]=nums[x][i]+nums[0][i];
		nums[1][i+1]=nums[1-x][i]+nums[1][i];
	
	}
	cout << nums[P][N] << endl;
	return 0;
}

Measured memory_bytes: 2304
using System;

class Program
{
    static void Main(string[] args)
    {
        var n = int.Parse(Console.ReadLine());
        var ans = 1L;
        for (int i = 0; i < n; i++)
        {
            ans = lcm(ans, long.Parse(Console.ReadLine()));
        }
        Console.WriteLine(ans);
    }

    static long lcm(long n, long m) => n / gcd(n, m) * m;
    static long gcd(long n, long m) => m == 0 ? n : gcd(m, n % m);
}


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

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

	int g[n][d];

	for (int k = 0; k < n; k++) {
		for (int l = 0; l < d; l++) {
			cin >> g[k][l];
		}
	}

	double ans = 0;
	int count = 0;
	for (int m = 0; m < n - 1; m++) {
		for (int p = m + 1; p < n; p++) {
			ans = 0;
			for (int o = 0; o < d; o++) {
				ans += (g[m][o] - g[p][o])*(g[m][o] - g[p][o]);
			}
			ans = sqrt(ans);
			if (ans - floor(ans) == 0) count++;
		}
	}
	cout << count << endl;
	return 0;
}


Measured memory_bytes: 764
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main(){
  int n,*a,i,k,p,kazu=0,s=0;
  scanf("%d",&n);
  a=(int *)malloc(n*sizeof(int));
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  for(i=0;i<n;i++){
    if(a[i]==2)kazu++;
    else if(a[i]%2 !=0&&a[i] !=1){
    for(k=2;k<=(sqrt(a[i]));k++){
      
      p=a[i]%k;
      if(p==0)s++;
     
      }
    if(s==0)kazu++;
    s=0;
  }
  }
  printf("%d\n",kazu);
  return 0;
}



Measured memory_bytes: 2104
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define ll long long
#define ld long double
#define MAX 1000000000
#define MOD 1000000007
#define MOD2 998244353
long long binpow(long long a, long long b, long long m) {
    a %= m;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
    //cin>>t;
    for(int cc=1;cc<=t;cc++){
        //cout<<"Case #"<<cc<<": ";
        int a,b,c,d;
        cin>>a>>b>>c>>d;
        int w = ceil((ld)a/d),s = ceil((ld)c/b);
        if(s<=w)
            cout<<"Yes\n";
        else
            cout<<"No\n";
    }
}


Measured memory_bytes: 3648
#include<bits/stdc++.h> 
using namespace std; 
typedef long long int ll;
int main() 
{  
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
     int n,k;
     cin>>n>>k;
     if(k==1)
     {
         cout<<0;
         return 0;
     }
     cout<<n-k;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cctype>
#include <string> 
#define mem(i,a) memset(i,a,sizeof(i))
#define PI acos(-1.0)
#define DMAX 100005
#define MOD 20190823
#define eps 1e-8
#define mp make_pair
#define INF 1000000000+9
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
template<class T> inline void read(T &f){
	f=0;
    T x=1;
    char ch=getchar();
    while(ch<48 || ch>57) {
        if(ch=='-') {
            x=-1;
        }
        ch=getchar();
    }
    while(ch<=57 && ch>=48) {
        f=f*10+ch-'0';
        ch=getchar();
    }
    f*=x;
}
ll n;
string s;
int main(){
	read(n);
	cin>>s;
	ll ans=1;
	char type=s[0];
	for(ll i=1;i<n;i++){
		if(s[i]==type){
			continue;
		}
		else{
			type=s[i];
			ans++;
		}
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 512
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
fn main(){
    let n = read::<i64>();
    let mut v = vec![];
    for _ in 0..n{
        v.push(read::<i64>());
    }
    v.sort();
    let sum:i64 = v.iter().sum();
    let sub = v.into_iter().filter(|x| x % 10 != 0).collect::<Vec<_>>();
    let ans = if sum % 10 == 0 {
        if sub.len() == 0 {
            0
        } else {
            sum - sub[0]
        }
    } else {
        sum
    };
    println!("{}",ans);
}

Measured memory_bytes: 4352
#include <stdio.h>

#define swap(a, b) {int tmp;tmp = a;a=b;b=tmp;}

int main(){
	int data[10];
	int i,t;
	for(i = 0;i < 10;i++)
		scanf("%d", data+i);
	for(i = 10-1;i >=0; i--){
		for(t = i;t < 10-1;t++){
			if(data[t]<data[t+1])swap(data

[t], data[t+1]);
		}
	}
	for(i = 0;i < 3;i++){
		printf("%d\n",data[i]);
	}
	return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define repp(i, m, n) for(int i = m, i##_len = (n); i < i##_len; ++i)
#define reprev(i, n) for(int i = (n-1LL); i >= 0; --i)
#define all(x) (x).begin(), (x).end()
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; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n);
    rep (i, n) cin >> a[i];
    ll ans = 0;
    rep (i, n - 1) {
        ans += a[i] / 2;
        a[i] %= 2;
        if (a[i] && a[i + 1]) {
            a[i + 1]--;
            ans++;
        }
    }
    ans += a[n - 1] / 2;
    cout << ans << "\n";
    return 0;
}

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

int gcd(int i, int j) {
    if (j == 0) return i;
    return gcd(j, i%j);
}

int main()
{
    int K; cin >> K;
    // vector<char> S; cin >> S;
    long long ans = 0;
    for (int i = 1; i <= K; i++) {
        for (int j = 1; j <= K; j++) {
            for (int k = 1; k <= K; k++) {
                ans += gcd(gcd(i, j), k);
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3192
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<limits>
#include<algorithm>
#include<numeric>
#include<utility>

struct restaurant{
    std::string S;
    int P;
    int i;

    restaurant(std::string _S, int _P, int _i){
        S = _S;
        P = _P;
        i = _i;
    }
};

int main(){
    int N;

    std::cin >> N;

    std::vector<restaurant> R;

    for(int i=0;i<N;i++){
        std::string _S;
        int _P;
        std::cin >> _S >> _P;
        restaurant _R(_S, _P, i+1);
        R.emplace_back(_R);
    }

    std::sort(R.begin(), R.end(), [](const restaurant &l, const restaurant &r){
        if(l.S != r.S) return l.S < r.S;
        return l.P > r.P;
    });

    for(int i=0;i<N;i++) std::cout << R[i].i << std::endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

int main(){
	int n, d[1003];
	bool appears[1003];
	
	REP(i,1000){
		appears[i] = false;
	}
	
	cin >> n;
	REP(i,n){
		cin >> d[i];
	}
	
	int d1, d2, d3;
	
	REP(i,n){
		d1 = d[i];
		appears[d1] = true;
		if (i+1<n){
			d2 = d[i+1];
			appears[d1*10+d2] = true;
		}
		if (i+2<n){
			d3 = d[i+2];
			appears[d1*100+d2*10+d3] = true;
		}
	}
	
	for (int i=0; i<1000; i++){
		if (!appears[i]){
			cout << i << endl; 
			break;
		}
	}
	
	return 0;
	
}


Measured memory_bytes: 3124
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
const double Pi=acos(-1);
struct Complex{
	double x,y;
	Complex(){x=y=0;}
	Complex(double _x,double _y){x=_x,y=_y;}
	Complex operator + (Complex b){
		return Complex(x+b.x,y+b.y);
	}
	Complex operator - (Complex b){
		return Complex(x-b.x,y-b.y);
	}
	Complex operator * (double b){
		return Complex(x*b,y*b);
	}
	Complex operator * (Complex b){
		return Complex(x*b.x-y*b.y,x*b.y+y*b.x);
	}
}ans;
int n,m;double a[3005];
Complex expi(double x){
	return Complex(cos(x),sin(x));
}
double mod(double x){
	if(x>=2*Pi)x-=2*Pi;
	if(x<0)x+=2*Pi;
	return x;
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1,x;i<=n;++i)
		scanf("%d",&x),a[i]=2*Pi*x/m;
	for(int i=1;i<=n;++i){
		Complex B=expi(a[i]),sum;
		for(int j=i%n+1,k=0;j!=i;j=j%n+1){
			Complex M=expi(a[j]+mod(a[i]-a[j])/2);
			ans=ans+M*k+(B-M)*sum;
			++k;sum=sum+expi(mod(a[j]-a[i])/2);
		}
	}
	ans=ans*(2.0/n/(n-1)/(n-2));
	printf("%.15lf %.15lf\n",ans.x,ans.y);
	return 0;
}


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

using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())

void Yes(){
	cout<<"Yay!"<<endl;
}
void No(){
	cout<<":("<<endl;
}

signed main(){

	lli n;
	cin>>n;
	string s;

	cin>>s;

	lli cnt=0;

	REP(i,0,10)REP(j,0,10)REP(k,0,10){
		lli a[3];
		a[0]=i;
		a[1]=j;
		a[2]=k;
		lli now=0;

		REP(l,0,s.size()){
			if((s.at(l)-'0') == a[now]){
				now++;
			}
			if(now==3){
				cnt++;
				break;
			}
		}
	}
	cout<<cnt<<endl;
	
	return 0;
}

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

int main(){
  int n,x; cin>>n>>x;
  vector<int>A(n);
  rep(i,n) cin>>A[i];
  sort(A.begin(), A.end());
  int ans = 0;
  rep(i,n){
    if (x>=A[i]){
      ans++;
      x -= A[i];
    }
  }
  if (x == 0||ans<n) cout << ans;
  else cout << ans-1;
}

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

int main(void){
    int n;
    cin >> n;
    int x = n / 111;
    if(n%111==0){
        cout << n << endl;
    }
    else if(n>111&&n<999){
        cout << (x + 1) * 111 << endl;
    }
    else{
        cout << 111 << endl;
    }
}


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

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

int main(){
    int n, m;
    string s, t;
    cin >> n >> m >> s >> t;
    int gc = gcd(n, m);
    long long lcm = (long long)n / gc * m;
    for(int i = 0; i < gc; i++){
        if(s[i * (n / gc)] != t[i * (m / gc)]){
            cout << -1 << endl;
            return 0;
        }
    }
    cout << lcm << endl;
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h> // Integer Product, by Errichto
using namespace std;
int main() {
    int n;
    scanf("%d", &n);
    map<pair<int,int>, int> cnt;
    for(int rep = 0; rep < n; ++rep) {
        double x;
        scanf("%lf", &x);
        long long i = llround(x * 1e9);
        int two = 0, five = 0;
        while(i % 2 == 0) {
            two++;
            i /= 2;
        }
        while(i % 5 == 0) {
            five++;
            i /= 5;
        }
        ++cnt[{two,five}];
    }
    long long answer = 0;
    for(auto p1 : cnt) {
        for(auto p2 : cnt) {
            if(p1.first.first+p2.first.first >= 18 && p1.first.second+p2.first.second >= 18) {
                if(p1 < p2) {
                    answer += (long long) p1.second * p2.second;
                }
                else if(p1 == p2) {
                    answer += (long long) p1.second * (p1.second - 1) / 2;
                }
            }
        }
    }
    printf("%lld\n", answer);
}

Measured memory_bytes: 3768
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float("INF")

#solve
def solve():
    x, n = LI()
    p = LI()
    ans = 0
    for i in range(102):
        if not i in p:
            if abs(ans - x) > abs(x - i):
                ans = i
    print(ans)
    return


#main
if __name__ == '__main__':
    solve()


Measured memory_bytes: 76808