akhauriyash/Code-Regression huggingface dataset:
// Package main provides
//
// File:  a.go
// Author: ymiyamoto
//
// Created on Sat Jan  5 15:32:20 2019
//
package main

import "fmt"

func main() {
	var s string
	fmt.Scan(&s)

	var ans int
	for i := range s {
		if s[i] == '1' {
			ans++
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define int long long
int n,a[100000],b[100000],ac=0,bc=0,ans=0;
vector<int> vec;
signed main(){
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>a[i];
    ac+=a[i];
  }
  for(int i=0;i<n;i++){
    cin>>b[i];
    bc+=b[i];
  }
  if(ac<bc){
    cout<<-1<<endl;
    return 0;
  }
  int cnt=ac-bc;
  for(int i=0;i<n;i++){
    if(a[i]>=b[i])vec.push_back(a[i]-b[i]);
  }
  sort(vec.begin(),vec.end());
  for(int i=0;i<vec.size();i++){
    cnt-=vec[i];
    if(cnt<0)break;
    ans++;
  }
  cout<<n-ans<<endl;
}

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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vll = vector<ll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;

template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

template<typename T>
ostream& operator <<(ostream &os, vector<T> &v) {
	for (auto &u : v) os << u << el;
	return (os);
}

template<typename T>
istream& operator >>(istream &is, vector<T> &v) {
	for (auto &u : v) is >> u;
	return (is);
}

template<typename T1, typename T2>
istream& operator >>(istream &is, pair<T1, T2> &p) {
	return (is >> p.first >> p.second);
}

int main() {
	int N; cin >> N;
	vector<vll> dp(N, vll(3, -LLINF));

	cin >> dp[0][0];
	for (int i = 1; i < N; i++) {
		char op; ll val;
		cin >> op >> val;
		if (op == '-') val = -val;
		chmax(dp[i][0], dp[i-1][0] + val);
		chmax(dp[i][1], dp[i-1][1] - val);
		chmax(dp[i][2], dp[i-1][2] + val);
		if (op == '-') {
			chmax(dp[i][1], dp[i-1][0] + val);
			chmax(dp[i][2], max(dp[i-1][1], dp[i-1][2]) - val);
		}
		chmax(dp[i][1], dp[i-1][2] - val);
		chmax(dp[i][0], dp[i-1][1] + val);
	}
	cout << max({dp[N-1][0], dp[N-1][1], dp[N-1][2]}) << endl;
	return (0);
}


Measured memory_bytes: 5760
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	ll n;
	cin >> n;
	ll m=1e13,flag=1;
	for(int i=1;i<=sqrt(n);i++){
		if(n%i==0)m=min(m,i+n/i-2),flag=0;
	}
	if(flag)cout << n-2 <<endl;
	else cout << m << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <iostream>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <math.h>
#include <sstream>
#include <numeric>
#include <cctype>
#include <bitset>
#include <cassert>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define SIZE 100005
#define INF 1000000000000000LL
using pint = pair<int,int>;
using vec = vector<int>;
using ll=long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n;cin>>n;
    string ans;
    while(n){
        n--;
        ans +=('a'+n%26);
        n/=26;
    }
    reverse(ans.begin(),ans.end());
    cout<<ans<<endl;
}

Measured memory_bytes: 3628
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <math.h>
#include <sstream>
#include <numeric>
#include <string>
#include <cassert>

using namespace std;
typedef long long ll;

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  vector<int> B(N - 1);
  for (int i = 0; i < N -1; ++i) {
    cin >> B[i];
  }
  
  A[0] = B[0];
  for (int i = 1; i < N - 1; ++i) {
    A[i] = min(B[i - 1], B[i]);
  }
  A[N - 1] = B[N - 2];

  int ans = 0;
  for (int i = 0; i < N; ++i) {
    ans += A[i];
  }
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 256
open System

let xs = Console.ReadLine().Split(' ')
        |> Array.map int

let mutable result = 0

for s in [1..xs.[0]] do
    let v = string s
            |> List.ofSeq 
            |> List.map (fun c -> int c - int '0')
            |> List.sum

    if xs.[1] <= v && v <= xs.[2] then
        result <- result + s

Console.WriteLine(
    result
)

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

int main(){
	int a,b,c,d,e;
	cin >> a >> b >> c >> d >> e;
	vector<int> v{a,b,c,d,e};
	int mini = 0, minix = a%10;
	for (int i=1;i<5;i++){
		if(v[i]%10 < minix && v[i]%10 !=0) {
			mini = i;
			minix = v[i]%10;
			}
		}
	int sum=0;
	for (int i=0; i<5; i++){
		if (mini!=i) sum+=(v[i]-1)/10*10 + 10;
	}
	sum+=v[mini];
	cout << sum;
		
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<string>
#include<cstring>
#include<cstdlib>
using namespace std;
string s; 
int main()
{
  cin>>s;
  cout<<s.substr(0,5)<<' '<<s.substr(6,7)<<' '<<s.substr(14,5)<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
using namespace std;
#define loop(i,N) for(ll (i)=0; (i)<(N);++(i))
struct _OMAZINAI_ { _OMAZINAI_() { std::ios::sync_with_stdio(false); std::cin.tie(0); } } __omazinai_instance__;
#define INF ((1LL<<61) + (1<<29))
#define YesNo(x) {std::cout << ((x)?"Yes":"No") << std::endl;}
#define YESNO(x) {std::cout << ((x)?"YES":"NO") << std::endl;}
#define OddEven(x) {std::cout << ((x)%2?"Odd":"Even") << std::endl;}
#define ODDEVEN(x) {std::cout << ((x)%2?"ODD":"EVEN") << std::endl;}
typedef long long int ll;
ll my_gcd(ll a, ll b) { return b ? my_gcd(b, a%b) : a; };
void _INPUT_IMPL_() {};
template <class T, class... Args> void _INPUT_IMPL_(T& dest, Args&... args) { cin >> dest; _INPUT_IMPL_(args...); }
void _OUTPUT_IMPL_() {};
template <class T, class... Args> void _OUTPUT_IMPL_(T dest, Args... args) { cout << dest << (sizeof...(Args) ? " " : ""); _OUTPUT_IMPL_(args...); }
#define in(type, ...) type __VA_ARGS__; _INPUT_IMPL_(__VA_ARGS__)
#define in_v(type, name, cnt) vector<type> name(cnt); loop(i, cnt) cin >> name[i];
#define sort_v(v) std::sort(v.begin(), v.end())
#define out(...) (_OUTPUT_IMPL_(__VA_ARGS__), std::cout<<std::endl)
#define set_fix(x) ((std::cerr<<std::fixed<<std::setprecision(x)),(std::cout<<std::fixed<<std::setprecision(x)))
//小さい方に寄る
#define space_op(x, y, a, b, c) ([](auto x_, auto y_, auto a_, auto b_, auto c_){if(x_<y_)return a_;if(x_>y_)return c_;return b_;}(x,y,a,b,c))
#define space_out(x, y, a, b, c) out(space_op(x, y, a, b, c))

int main() {
	in(ll, N);
	string s;
	ll tmp = 1;
	while (N) {
		if (N % (abs(tmp)<<1) == 0)
			s += "0";
		else
			s += "1", N -= tmp;
		tmp *= -2;
	}
	if (s.empty()) s = "0";
	string r(s.rbegin(), s.rend());
	out(r);
}


Measured memory_bytes: 256
import std.stdio, std.string, std.conv;
import std.algorithm, std.array;
auto solve(string s_) {
    immutable N = s_.to!int();
    auto ab = new long[2][N];
    foreach(ref v;ab) v = readln.split.map!(to!long).array();
    long c=0;
    foreach_reverse(ref v;ab) {
        immutable a=v[0], b=v[1];
        c+=(b-(a+c)%b)%b;
    }
    return c;
}
void main(){ for(string s; (s=readln.chomp()).length;) writeln(solve(s)); }

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

int main() {
    int A, B, Q;
    cin >> A >> B >> Q;

    vector<ll> s(A), t(B), y(Q);
    rep(i, A) cin >> s[i];
    rep(i, B) cin >> t[i];
    rep(i, Q) cin >> y[i];

    rep(i, Q) {
        ll x = y[i];
        // cin >> x;

        int right1 = lower_bound(s.begin(), s.end(), x) - s.begin();  // xより大きいxのindex。i = Aなら右端、i = 0なら左端
        int left1 = right1 - 1;  // xより小さいxのindex。i = --1なら左側には何もない

        int right2 = lower_bound(t.begin(), t.end(), x) - t.begin();
        int left2 = right2 - 1;

        ll ret = LLONG_MAX;
        ll now;

        // 左側にしか行かない。
        if (left1 != -1 && left2 != -1) {
            now = max(x - s[left1], x - t[left2]);
            ret = min(ret, now);
        }

        // 右側にしか行かない。
        if (right1 != A && right2 != B) {
            now = max(s[right1] - x, t[right2] - x);
            ret = min(ret, now);
        }

        // 神社は左、寺は右
        if (left1 != -1 && right2 != B) {
            now = (x - s[left1]) * 2 + (t[right2] - x);
            ret = min(ret, now);

            now = (x - s[left1]) + (t[right2] - x) * 2;
            ret = min(ret, now);
        }

        // 寺は左、神社は右
        if (left2 != -1 && right1 != A) {
            now = (x - t[left2]) * 2 + (s[right1] - x);
            ret = min(ret, now);

            now = (x - t[left2]) + (s[right1] - x) * 2;
            ret= min(ret, now);
        }

        cout << ret << endl;
    }

    return 0;
}

Measured memory_bytes: 5608
#include <bits/stdc++.h>
using namespace std;
#define ll long long;
 
int main(){
  string s;cin>>s;
  int a=(s[0]-'0')*10+(s[1] - '0');
  int b=(s[2] - '0')*10+(s[3] - '0');
  bool flg1=0<a && a<=12;
  bool flg2=0<b && b<=12;
  if(flg1 && flg2) 
		cout<<"AMBIGUOUS"<< endl;
  else if(a == 0 && flg2) 
		cout<<"YYMM"<<endl;
  else if(b == 0 && flg1) 
		cout<<"MMYY"<<endl;
  else if(flg1 && !flg2) 
		cout<<"MMYY"<< endl;
  else if(!flg1 && flg2) 
		cout<<"YYMM"<<endl;
  else cout<<"NA"<<endl;
  return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <numeric>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, start, end) for(int i = start; i < end; i++)
#define all(x) (x).begin(), (x).end()
typedef long long ll;

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

    vector<int> nums(n);
    rep(i, n) cin >> nums[i];

    int sum = 0;
    rep(i, n){
        while(nums[i] % 2 == 0){
            nums[i] /= 2;
            sum ++;
        }
    }

    cout << sum << endl;
}

Measured memory_bytes: 256
// C/C++ program to find minimum number of 
// flip to make binary string alternate 
#include <bits/stdc++.h> 
using namespace std; 

// Utility method to flip a character 
char flip(char ch) 
{ 
	return (ch == '0') ? '1' : '0'; 
} 

// Utility method to get minimum flips when 
// alternate string starts with expected char 
int getFlipWithStartingCharcter(string str, 
								char expected) 
{ 
	int flipCount = 0; 
	for (int i = 0; i < str.length(); i++) 
	{ 
		// if current character is not expected, 
		// increase flip count 
		if (str[i] != expected) 
			flipCount++; 

		// flip expected character each time 
		expected = flip(expected); 
	} 
	return flipCount; 
} 

// method return minimum flip to make binary 
// string alternate 
int minFlipToMakeStringAlternate(string str) 
{ 
	// return minimum of following two 
	// 1) flips when alternate strign starts with 0 
	// 2) flips when alternate strign starts with 1 
	return min(getFlipWithStartingCharcter(str, '0'), 
			getFlipWithStartingCharcter(str, '1')); 
} 

// Driver code to test above method 
int main() 
{ 
	string str;
  cin >> str;
	cout << minFlipToMakeStringAlternate(str); 
	return 0; 
} 


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

int main(){
    long long N;
    cin >> N;
    long long A;
    long long ans=0;
    for(A=1; A<N; A++){
        if(N%A==0){
            ans+=(N/A-1);
        }else{
            ans+=(N/A);
        }
    }
    cout << ans << endl;
    system("pause");
    return 0;
}

Measured memory_bytes: 3676
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <random>
#include <queue>
using namespace std;
typedef long long int ll;

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int a,b,c; cin >> a >> b >> c;
	cout << a+b+c << endl;
}


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

int main(void)
{
    int i,n;
        double x,mean,poi[1010]={0};
    
    while(scanf("%d",&n) && n!=0){
        x=0;
        for(i=0;i<n;i++){
            scanf("%lf",&poi[i]);
            x+=poi[i];
        }
        mean=x/n;
        x=0;
        
        for(i=0;i<n;i++){
            x+=pow(poi[i]-mean,2);
        }
        
        mean=sqrt(x/n);
        printf("%f\n",mean);
    }
    return 0;
}


Measured memory_bytes: 2064
N = int(input())

A = list(map(int,input().split()))
A.sort()
hantei = 0
for i in range(len(A)-1):
    if A[i] == A[i+1]:
        hantei = 1
        break
    
if hantei == 0:
    print("YES")
elif hantei == 1:
    print("NO")



Measured memory_bytes: 26808
K,N=map(int,input().split())
A=list(map(int,input().split()))
L=0
m=K-A[-1]+A[0]
for i in range(1,N):
    l = A[i]-A[i-1]
    if l < m:
        L += l
    else:
        L += m
        m = l
print(L)

Measured memory_bytes: 26444
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vector<int> h(n);
	for (int i = 0; i < n; i++) {
		cin >> h[i];
	}
	vector<long long> dp(n);
	dp[0] = 0;
	dp[1] = abs(h[1] - h[0]);
	for (int i = 2; i < n; i++) {
		dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]));
	}
	cout << dp[n - 1] << endl;
	return 0;
}

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

int main()
{
    ll n,k,x,y;
    cin>>n;
    ll ar[n+1][4],dp[n+1][4];
    for(ll i=1; i<=n; i++ )
        for(ll j=1;j<=3;j++)
        {
            cin>>ar[i][j];
        }
    for(ll i=1; i<=3; i++ )
        dp[n][i]=ar[n][i];
    for(ll i=n-1; i>=1; i-- )
    {
        dp[i][1]=ar[i][1]+max(dp[i+1][2],dp[i+1][3]);
        dp[i][2]=ar[i][2]+max(dp[i+1][1],dp[i+1][3]);
        dp[i][3]=ar[i][3]+max(dp[i+1][2],dp[i+1][1]);
        //cout<<dp[i][1]<<dp[i][2]<<dp[i][3]<<endl;
    }
    ll maxi=dp[1][1];
    for(ll i=2; i<=3; i++ )
    {
        //cout<<dp[i][1];
        if(maxi<dp[1][i])
            maxi=dp[1][i];

    }
    cout<<maxi<<endl;
}


Measured memory_bytes: 6528
#include <stdio.h>
int main(void)
{
	int a, max = 1, min = 1000000000,i;
	int c;
	scanf("%d", &a);
	for (i = 0; i < a; i++) {
		scanf("%d", &c);
		if (c > max)max = c;
		if (c < min) {
			min = c;
		}
	}
	//printf("%d %d\n", max, min);
	printf("%d\n", max - min);
	return 0;
}



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

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

using namespace std;

using ll = long long;
using P = pair<int , int>;
  
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  ll x; cin >> x;
  ll i, j;
  for(i = 0, j = 100; j < x; ++i) {
    j += (j/100);
  }
  cout << i;
}
  


Measured memory_bytes: 3648
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

vector<string> v;
int N; 
void dfs(string& S, int p, int depth) {
    //cout << S << " " << depth << endl;
    if (depth >= N) {
        v.push_back(S);
        return;
    }
    rep(i, p + 1) {
        S += 'a' + i;
        dfs(S, max(i + 1, p), depth + 1);
        S.pop_back();
    }
}


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    string S = "";
    dfs(S, 0, 0);
    sort(v.begin(), v.end());
    rep(i, v.size()) {
        cout << v[i] << endl;
    }


    return 0;
}


Measured memory_bytes: 9716
#include<stdio.h>
 
#define MAX 100
 
int n,M[MAX+1][MAX+1];
int d[MAX+1];
int Q[MAX+1];
int head = 1, tail;
 
void enqueue(int x){
    
  Q[tail] = x;
  if((tail +1) == MAX+1)
    tail = 0;
  else
    tail++; 
}
  
int dequeue(){
  
  int x;
  x = Q[head];
  if((head + 1) == MAX+1)
    head = 0;
  else
    head++;
  return x; 
  
}
  
int Q_empty(){
  int i;
  for(i=0;i<MAX+1;i++)
    if(Q[i]!=-777) return 777;
  return 0;
}
 
void BFS(int s){
  int i,u,v,count=0,flag=1;     
  enqueue(s);
  for(i=0;i<n;i++) d[i] = (1<<21);
  d[s]=0;
   
  
  while(1){
    if(Q_empty()==0)break;
    for(i=count;i<MAX+1;i++){
      u=dequeue();
      if(u!=-777) break;
    }
     if(u==-777) break;
    count=i;
    for(v=0;v<n;v++){
      if(M[u][v]==0) continue;
      if(d[v]!= (1<<21))continue;
      d[v]=d[u]+1;
      enqueue(v);
    }
  }
  for(i=0;i<n;i++){
    printf("%d",i+1);
    if(d[i]==(1<<21)) printf(" %d\n",-1);
    else printf(" %d\n",d[i]);
  }
}
 
int main(){
  int u,k,v,i,j;
  for(i=0;i<MAX+1;i++){
    Q[i]=-777;
  }
  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      M[i][j]=0;
    }
  }
 for(i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    u--;
    for(j=0;j<k;j++){
      scanf("%d",&v);
      v--;
      M[u][v]=1;
    }
  }
  BFS(0);
  return 0;
}

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

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

  int rest_gram = X;
  int donuts_count = 0;
  int minimum_donuts_gram = 1000;
  for (int i = 0; i < N; i++) {
    int donuts_gram;
    cin >> donuts_gram;

    // ドーナツを1つ作る
    rest_gram -= donuts_gram;
    donuts_count++;
    // 最小コストで作れるドーナツを判定する
    minimum_donuts_gram = min(minimum_donuts_gram, donuts_gram);
  }

  // 余った材料で作成できるドーナツの数
  int c = rest_gram / minimum_donuts_gram;

  cout << (donuts_count + c) << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
 using namespace std;
#define INF 1000000000
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
typedef long long LL;
int N;
int main(){
    string S,T;
    cin>>S>>T;
    string ans="";
    REP(i,S.size()+1){
        ans=ans+"z";
    }
    
    REP(i,S.size()-T.size()+1){
        string SS=S;
        bool check=false;
        REP(j,T.size()){
            if(SS[i+j]=='?'){
               SS[i+j]=T[j];
            }
            if(SS[i+j]!=T[j]){
               check=true;
            }
        }
        //cout<<ans<<" "<<SS<<endl;
        if(check)continue;
        REP(j,SS.size()){
            if(SS[j]=='?'){
               SS[j]='a';
            }
        }
        //cout<<ans<<" "<<SS<<endl;
        ans=min(ans,SS);
    }
    
    
    if(ans.size()==S.size()+1){
       cout<<"UNRESTORABLE"<<endl;
    }else{
       cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
N = int(input())
S = input()
if N%2 == 0:
    f = True
    for i in range(N//2):
        if S[i] == S[i + N // 2]:
            continue
        else:
            f = False
else:
    f = False
if f:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 2940
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    x, N = map(int, readline().split())

    if N == 0:
        print(x)
        exit()

    P = set([int(i) for i in readline().split()])

    for i in range(60):
        if x - i not in P:
            print(x - i)
            break
        if x + i not in P:
            print(x + i)
            break



if __name__ == "__main__":
    main()


Measured memory_bytes: 9192
// Implementation practice (Have seen the editorial)
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef map<int,int> mii;
typedef map<string,int> msi;
typedef set<int> si;
typedef priority_queue<int> pqi;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(a) a.begin(), a.end()
#define loop(i, a) for (int i = 0; i < (a); i++)
#define loop1(i, a) for (int i = 1; i <= (a); i++)
#define loopr(i, a, b) for (int i = (a); i <= (b); i++)
#define dloop(i, a) for (int i = (a) - 1; i >= 0; i--)
#define dloopr(i, b, a) for (int i = (b); i >= (a); i--)
#define tr(it, container) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define present(container, element) (container.find(element) != container.end())
#define vpresent(container, element) (find(container.being(), container.end() ,element) != container.end())
#define show(a) cout << a << "\n"
#define showloop(a, len) for (int i = 0; i < len; i++) cout << a[i] << "\n"
#define debug(a) cout << #a << ": " << (a) << "\n"
#define mem(x, val) memset((x), (val), sizeof(x));
#define sz(x) ((int)x.size())
#define ran(a, b) ((((rand() << 15) ^ rand()) % ((b) - (a) + 1)) + (a))
const int MOD = 1000000007;
const double PI = acos(-1);

int main() {
	//freopen("in", "r", stdin);
	//freopen("out", "w", stdout);
	//ios::sync_with_stdio(false);cin.tie(NULL);

	int n, k; cin >> n >> k;
	int x[n]; loop(i, n) cin >> x[i];
	int ans = 0;
	loop(i, n) ans += 2 * min(x[i], k - x[i]);
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    string n;
    int s=0;
    cin>>n;
    for (int i=0;i<n.length();i++)
        s=s+n[i]-48;
    if (s%9==0) {cout<<"Yes";}
    else {cout<<"No";}
    return 0;
}


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

using namespace std;

#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)((x).size()))

typedef pair<int, int> PII;
typedef vector<int> VI;
typedef long long int64;
typedef unsigned int uint;
typedef unsigned long long uint64;

#define gi(x) ((x) = F())
#define gii(x, y) (gi(x), gi(y))
#define giii(x, y, z) (gii(x, y), gi(z))

int F()
{
	char ch;
	int x, a;
	while (ch = getchar(), (ch < '0' || ch > '9') && ch != '-');
	if (ch == '-') ch = getchar(), a = -1;
	else a = 1;
	x = ch - '0';
	while (ch = getchar(), ch >= '0' && ch <= '9')
		x = (x << 1) + (x << 3) + ch - '0';
	return a * x;
}

int n, a[100010];

long long ans;

int main()
{
	gi(n);
	for (int i = 1; i <= n; ++i) gi(a[i]);
	for (int i = 1; i <= n; ++i)
	{
		if (a[i] & 1)
		{
			if (a[i + 1]) ++ans, --a[i], --a[i + 1];
		}
	}
	for (int i = 1; i <= n; ++i)
	{
		ans += a[i] >> 1;
	}
	printf("%lld\n", ans);
	return 0;
}



Measured memory_bytes: 640
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <queue>
#include <set>
#include <map>
#include <stack>
 
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
 
ll N,K,ans,X;
string S,T;
ll C[200005];
ll A[200005];
set<ll> B;
ll money;
ll INF = 100000009;

bool found = true;
int main(){
    cin >> N >> K;
    for(int i=0;i<N;i++){
        cin >> A[i];
    }
    ll i = 0;
    ll j = 1;
    ll k;
    set<ll>::iterator ite;
    while(i<=N){
        ite = B.find(j);
        if(ite != B.end()){
            break;
        }
        B.insert(j);
        C[i] = j;
        j = A[j-1];
        i++;
    }
    for(int l=0;l<N;l++){
        if(C[l]==j){
            k = l;
        }
    }
    if(K>k){
        K = (K-k)%(i-k) + k;
    }
    
    cout << C[K] << endl;
    
}




Measured memory_bytes: 15804
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <map>
#include <functional>
#include <cmath>

using namespace std;

int main()
{
	unsigned int n, k  , h;
	int i,sum=0;
	cin >> n >> k;
	for (i = 0; i < n; i++)
	{
		cin >> h;
		if (h >= k)
			sum++;
	}
	cout << sum << endl;
	return 0;
} 


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using namespace std;
int mod = 1000000007;
int inf = INT_MAX;
int m_inf = INT_MIN;
int dp[100001][2];


int32_t main() 
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	std::cout.unsetf ( std::ios::floatfield );
	std::cout.precision(6);
	string str;
  cin>>str;
  int a = 0,b = 0;
  for(int i = 0;i<str.size();i++)
  {
	if(str[i] == 'A')
      a++;
    else
      b++;
  }
  if(a && b)
    cout<<"Yes\n";
  else
    cout<<"No\n";
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
  int i,j;
  int a,b,k,c1[100],c2[100];
  char g[100][100];
  
  for(a=0;a<100;a++){
    c1[a]=0;
    c2[a]=0;
  }
  
  cin>>i>>j;
  for(a=0;a<i;a++){
    for(b=0;b<j;b++){
      cin>>g[a][b];
    }
  }
  
  
  for(a=0;a<i;a++){
    for(b=0;b<j;b++){
      if(g[a][b]=='.'){
        c1[a]++;
        c2[b]++;
      }
    }
  }
  
 for(a=0;a<i;a++){
    if(c1[a]==j) {
      continue;}
    else{
    for(b=0;b<j;b++){
      if(c2[b]==i)
        continue;
      else
        cout<<g[a][b];
    }
    cout<<endl;}
  }
  
  return 0;
}

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

using std::pair;
using std::vector;
using std::string;

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

#define fst first
#define snd second
#define pb(a) push_back(a)
#define mp(a, b) std::make_pair(a, b)
#define debug(...) fprintf(stderr, __VA_ARGS__)

template <typename T> bool chkmax(T& a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> bool chkmin(T& a, T b) { return a > b ? a = b, 1 : 0; }

const int oo = 0x3f3f3f3f;

string procStatus() {
    std::ifstream t("/proc/self/status");
    return string(std::istreambuf_iterator<char>(t), std::istreambuf_iterator<char>());
}

template <typename T> T read(T& x) {
    int f = 1; x = 0;
    char ch = getchar();
    for(;!isdigit(ch); ch = getchar()) if(ch == '-') f = -1;
    for(; isdigit(ch); ch = getchar()) x = x * 10 + ch - 48;
    return x *= f;
}

int x, y;
int main() {
#ifdef Wearry
    freopen("in", "r", stdin);
    freopen("out", "w", stdout);
#endif

    read(x), read(y);
    if(x % y == 0) puts("-1"); else printf("%d\n", x);

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>

#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long LL;
using namespace std;

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

	vector<int> a(n), p(n);
	rep(i, m) {
		int sub;
		string s;
		cin >> sub >> s;
		sub--;
		if (a[sub]) continue;

		if (s == "AC") {
			a[sub] = 1;
		}
		else {
			p[sub]++;
		}
	}
	int ans = 0;
	int pe = 0;
	rep(i, n) {
		ans += a[i];
		if (a[i]) {
			pe += p[i];
		}
	}

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

Measured memory_bytes: 1024
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#define DEBUG(x) std::cout << '>' << #x << ':' << x << '\n';
#define PRINTVEC(x) for (int i = 0; i < (int)x.size(); i++) std::cout << x[i] << ' '; std::cout << '\n';
#define PRINTP(x) for (int i = 0; i < (int)x.size(); i++) std::cout << x[i].first << ' ' << x[i].second << '\n'; std::cout << '\n';
#define io std::ios_base::sync_with_stdio(false);std::cin.tie(NULL);   
const int INF = 1<<29;
typedef long long ll;



int main()
{
	io;
    #ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin); 
    //freopen("output.txt", "w", stdout);  
    #endif

    int n,k;
    std::cin >> n >> k;
    std::cout << (n * n - n) / 2 + (k * k - k) / 2;

    #ifndef ONLINE_JUDGE   
    //std::cout << '\n' << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
    #endif
    return 0;
}


Measured memory_bytes: 256
N = int(input())
A1 = [int(i) for i in input().split()]
A2 = [int(i) for i in input().split()]
ans = 0
for b in range(N):
    ame = 0
    ame += sum(A1[:b+1])
    ame += sum(A2[b:])
    if ans <= ame:
        ans = ame
print(ans)

Measured memory_bytes: 3060
#include"bits/stdc++.h"
using namespace std;
using ll = int64_t;

int main() {
    string S, T;
    cin >> S >> T;

    const ll N = S.size();
    for (ll i = 0; i < N; i++) {
        bool same = true;
        for (ll j = 0; j < N; j++) {
            if (S[(i + j) % N] != T[j]) {
                same = false;
                break;
            }
        }

        if (same) {
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>

int main(void) {
    using std::cin;
    using std::cout;
    using std::vector;

    int N, C;
    cin >> N >> C;
    vector<vector<int>> D(C);
    for (int i = 0; i < C; ++i) {
        D.at(i).resize(C);
        for (int j = 0; j < C; ++j) {
            cin >> D.at(i).at(j);
        }
    }
    vector<int> c_mod_0(C);
    vector<int> c_mod_1(C);
    vector<int> c_mod_2(C);
    std::fill(c_mod_0.begin(), c_mod_0.end(), 0);
    std::fill(c_mod_1.begin(), c_mod_1.end(), 0);
    std::fill(c_mod_2.begin(), c_mod_2.end(), 0);
    for (int i = 1; i <= N; ++i) {
        for (int j = 1; j <= N; ++j) {
            int c;
            cin >> c;
            if ((i + j) % 3 == 0) c_mod_0.at(c - 1) += 1;
            if ((i + j) % 3 == 1) c_mod_1.at(c - 1) += 1;
            if ((i + j) % 3 == 2) c_mod_2.at(c - 1) += 1;
        }
    }

    // c_mod_0 -> color i
    // c_mod_1 -> color j
    // c_mod_2 -> color k
    int min_wrongness = 1'000'000'000;  //'
    for (int i = 0; i < C; ++i) {
        for (int j = 0; j < C; ++j) {
            if (j == i) continue;
            for (int k = 0; k < C; ++k) {
                if (k == i || k == j) continue;
                int d_sum = 0;
                for (int c = 0; c < C; ++c) {
                    d_sum += c_mod_0.at(c) * D.at(c).at(i);
                    d_sum += c_mod_1.at(c) * D.at(c).at(j);
                    d_sum += c_mod_2.at(c) * D.at(c).at(k);
                }
                min_wrongness = std::min(min_wrongness, d_sum);
            }
        }
    }

    std::cout << min_wrongness << '\n';
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int h, w;
  cin >> h >> w;
  vector<vector<int>> c(10, vector<int>(10));
  rep(i, 10){
    rep(j, 10) cin >> c.at(i).at(j);
  }
  vector<int> a(10, 0);
  rep(i, h){
    rep(j, w){
      int in;
      cin >> in;
      if(in != -1) a.at(in)++;
    }
  }
  rep(k, 10){
    rep(i, 10){
      rep(j, 10){
        c.at(i).at(j) = min(c.at(i).at(j), c.at(i).at(k)+c.at(k).at(j));
      }
    }
  }
  ll ans = 0;
  rep(i, 10){
    ans += a.at(i) * c.at(i).at(1);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3612
#include<iostream>
#include<string>
#include<vector>
using namespace std;
 
int main() {
    int h, w; scanf("%d%d", &h, &w);
    vector <string> lines(h);
    vector <int> cols(h, 0), rows(w, 0);
    for(int i=0;i<h;i++)cin >> lines[i];
    for(int col=0;col<h;col++){
        for(int row=0;row<w;row++){
            if(lines[col][row]=='#'){cols[col]=1;rows[row]=1;}        
            }
    }
    for(int col=0;col<h;col++){
        if(cols[col]==1){
            for(int row=0;row<w;row++){
                if(rows[row]==1)printf("%c", lines[col][row]);
            }printf("\n");
        }
    }return 0;
}

Measured memory_bytes: 3736
#include<bits/stdc++.h>
using namespace std;
int n,sum1,sum2;
char s[100010];
int main()
{
	scanf("%s",s);
	n=strlen(s);
	for(register int i=0;i<n;i++)
		if(s[i]=='0')
			sum1++;
		else
			sum2++;
	printf("%d",2*min(sum1,sum2));
	return 0;
}

Measured memory_bytes: 384
def judge(x):
    for i in range(1000):
        if x==i**2:
            return True
    return False

def f(x,y):
    res = 0
    for i in range(len(x)):
        res += (x[i]-y[i])**2
    return res

n,d = map(int,input().split())

a = [list(map(int,input().split())) for i in range(n)]

ans = 0
for i in range(n):
    for j in range(i+1,n):
        if judge(f(a[i],a[j])):
            ans += 1
print(ans)

Measured memory_bytes: 38512
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
using ll=long long;
constexpr ll mod=1000000007;
constexpr int inf=1000000000;
constexpr ll linf=1000000000000000000;

struct UnionFind{
private:
    vector<int> data;
public:
    vector<int> sz;
    UnionFind(int n){
        data.assign(n,-1);
        sz.assign(n,1);
    }
    int root(int x){
        if(data[x]<0)return x;
        else return data[x]=root(data[x]);
    }
    bool issame(int x,int y){
        return root(x)==root(y);
    }
    bool merge(int x,int y){
        x=root(x),y=root(y);
        if(x==y)return false;
        if(data[x]>data[y])swap(x,y);
        data[x]+=data[y];
        data[y]=x;
        sz[x]+=sz[y];
        return true;
    }
    int size(int x){
        return -data[root(x)];
    }
};

int main(){
    int n,m;
    cin>>n>>m;
    UnionFind uf(n);
    rep(i,m){
        int a,b;
        cin>>a>>b;
        --a,--b;
        uf.merge(a,b);
    }
    int ans=0;
    rep(i,n){
        ans=max(ans,uf.sz[i]);
    }
    cout<<ans<<"\n";
}


Measured memory_bytes: 4820
n = int(input())
ws = [str(input()) for i in range(n)]
t = ws[0][0]
for w in ws:
  if ws.count(w) > 1:
    print('No')
    break
  if t[-1] != w[0]:
    print('No')
    break
  else:
    t = w
    n-=1
if n == 0:
  print('Yes')

Measured memory_bytes: 3060
def hantei(s):
    rev_s = s[::-1]

    for x in range(len(s)):
        if s[x] != rev_s[x]:
            return False
    
    return True

s = input()

if hantei(s) and hantei(s[:int((len(s)-1)/2)]) and hantei(s[int((len(s)+3)/2)-1:]):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 2940
<?php
    $n = fgets(STDIN);
    $d = fgets(STDIN);
    $d_array = explode(' ', $d);

    $ans  = 0;
    for($i=0; $i<$n; $i++){
        for($j=$i+1;$j<$n; $j++){
            $temp = $d_array[$i] * $d_array[$j];
            $ans += $temp;
        }
    }
    echo $ans;
?>

Measured memory_bytes: 4856
n = gets.to_i
ss = n.times.map { gets.chomp }

all_chars = ss.map { |s| s.chars }.flatten.sort.uniq
available_chars = Array.new(all_chars)
counters = []

ss.each do |s|
  all_chars.each do |c|
    available_chars.delete(c) unless s.include?(c)
  end

  if available_chars.empty?
    puts
    exit
  end

  counters.push(
    s.chars.each_with_object(Hash.new(0)) { |c, counter| counter[c] += 1 }
  )
end

puts available_chars.map { |c|
  c * counters.map { |counter| counter[c] }.min
}.join


Measured memory_bytes: 2040
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
using namespace std;

int gcd(int x, int y)
{
    if(x < y)
        swap(x, y);
    int r = x % y;
    while(r != 0)
    {
        x = y;
        y = r;
        r = x % y;
    }

    return y;
}

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

    int gcd_forward[n];
    int gcd_backward[n];

    gcd_forward[0] = a[0];
    gcd_backward[0] = a[n-1];

    for(int i=0;i<n-1;++i)
        gcd_forward[i+1] = gcd(gcd_forward[i], a[i+1]);

    for(int i=0;i<n-1;++i)
    {
        int j = n-1-i;
        gcd_backward[i+1] = gcd(gcd_backward[i], a[j-1]);
    }

    int max_gcd = std::max(gcd_forward[n-2], gcd_backward[n-2]);

    for(int i=0;i<n-2;++i)
    {
        int tmp_gcd = gcd(gcd_forward[i], gcd_backward[n-3-i]);
        if(tmp_gcd > max_gcd)
            max_gcd = tmp_gcd;
    }
        

    cout << max_gcd << endl;
    return 0;
}

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

int main(){
    int a,b,k;
    cin >> a >> b >> k;
    map<int,int> m;
    for(int i=a;i<a+k;i++){
        m[min(i,b)]++;
    }
    for(int i=b;i>b-k;i--){
        m[max(i,a)]++;
    }
    for(auto x:m){
        cout << x.first << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main(){
    int N, M;
    cin >> N >> M;
    //long long x_p, y_p, z_p;
    //long long x_n, y_n, z_n;
    long long x,y,z;
    vector< vector<long long> > xyz(8, vector<long long>(N));
    for(int i = 0; i < N; i++){
        cin >> x >> y >> z;
        xyz[0][i] = x + y + z;
        xyz[1][i] = -x + y + z;
        xyz[2][i] = x - y + z;
        xyz[3][i] = x + y - z;
        xyz[4][i] = -x - y + z;
        xyz[5][i] = x - y - z;
        xyz[6][i] = -x + y - z;
        xyz[7][i] = -x - y - z;
    }

    long long max = 0;
    for(int i = 0; i < 8; i++){
        sort(xyz[i].begin(), xyz[i].end());
        long long sum = 0;
        for(int k = 0; k < M; k++)
            sum += xyz[i][N-1-k];
        //cout << sum << endl;
        if(sum > max)
            max = sum;
    }
    cout << max << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,i;
int a[200001],b[200001],c[200001];
int dp[200001][3];
int main(){
    cin>>n;
    for(i=1;i<=n;i++)cin>>a[i]>>b[i]>>c[i];
    for(i=1;i<=n;i++){
        dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a[i];
        dp[i][1]=max(dp[i-1][0],dp[i-1][2])+b[i];
        dp[i][2]=max(dp[i-1][0],dp[i-1][1])+c[i];
    }
    cout<<max(dp[n][0],max(dp[n][1],dp[n][2]))<<endl;
}

Measured memory_bytes: 3712
#include<cstdio>
#include<iostream>
#include<cstring>
#define RG register
using namespace std;
int n;
inline int read(){
	char ch=getchar(); int x=0, f=1;
	while(ch<'0' || ch>'9'){if(ch=='-') f=-1;ch=getchar();}
	while(ch>='0' && ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;}
int main()
{
//	freopen("Programming Education.in","r",stdin);
//	freopen(".out","w",stdout);
	n=read();
	if(n==1)
	{
		printf("Hello World\n");
	}
	else 
	{
		int a=read(), b=read();
		printf("%d\n",a+b);
	}
//	fclose(stdin); fclose(stdout);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>
#include <boost/range/adaptors.hpp>

using namespace std;
using namespace boost::adaptors;

using ll = long long;

//問題は正しく読みましょう
//K「以上」のカーネルを使ってフリップして良い

//試して見ればわかるが，端の方はひっくり返しやすく，真ん中の方にいくにつれてひっくり返しにくい
//つまり，ひっくり返しの必要の真ん中度を求めればOK

int main() {
    string s;
    cin >> s;
    ll n = s.size();
    ll start = (n-1)/2;
    ll end = n-1;
    ll minimum = s.size();
    for (auto &&i: boost::irange(start, end)){
        if (s.at(i)!=s.at(i+1)){
            minimum = min(minimum, i+1);
            break;
        }
    }
    reverse(s.begin(), s.end());
    for (auto &&i: boost::irange(start, end)){
        if (s.at(i)!=s.at(i+1)){
            minimum = min(minimum, i+1);
            break;
        }
    }
    cout << minimum << endl;
}

Measured memory_bytes: 512
#include <stdio.h>
#include <string>
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int myfunction(vector<long> a, vector<long>b) {
    return a[0] < b[0];
}

int book_num, algo_num, goal_num;
vector<vector<long> > lib;
int DP(int k, vector<long> work) {
    bool Have_Pos = false;
    for (int i = 1; i < work.size(); i++) {
        if (work[i] > 0) {
            Have_Pos = true;
        }
    }
    if (!Have_Pos) {
        return work[0];
    }
    if (k > book_num) {
        return INT_MAX;  
    }
    else {
        vector<long>get_this = work;
        get_this[0] += lib[k][0];
        for (int i = 1; i <= algo_num; i++) {
            get_this[i] -= lib[k][i];
        }
        return min(DP(k + 1, work), DP(k + 1, get_this));
    }
}

int main()
{

    
    cin >> book_num >> algo_num >> goal_num;
    lib.resize(book_num + 1);
    for (int i = 0; i <= book_num; i++) {
        lib[i].resize(algo_num + 1);
    }
    for (int i = 1; i <= algo_num; i++) {
        lib[0][i] = goal_num;
    }
    for (int i = 1; i <= book_num; i++) {
        for (int j = 0; j <= algo_num; j++) {
            cin >> lib[i][j];
        }
    }
    sort(lib.begin()+1, lib.end(), myfunction);
    vector<long> work= lib[0];
    int output = DP(1, work);
    if (output == INT_MAX) {
        cout << -1;
    }
    else {
        cout << output;
    }

    return 0;
}


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

    

int main(){
  ll N,ans=0;
  cin >> N;
  vector<vector<ll>> dp(10, vector<ll>(10,0));
  rep(i,N){
    ll x,y;
    y=(i+1)%10;
    if((i+1)/100000>0){
      x=(i+1)/100000;
    }else if((i+1)/10000>0){
      x=(i+1)/10000;
    }else if((i+1)/1000>0){
      x=(i+1)/1000;
    }else if((i+1)/100>0){
      x=(i+1)/100;
    }else if((i+1)/10>0){
      x=(i+1)/10;
    }else{
      x=i+1;
    }
    dp.at(x).at(y)++;
  }
  for(ll i=1;i<10;i++){
    for(ll j=1;j<10;j++){
      ans+=dp.at(i).at(j)*dp.at(j).at(i);
    }
  }
  cout << ans << endl;
    
  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fo(i,w,n) for(int i=(int) w;i<(int) n;i++)
#define qi queue<int>
#define vi vector<int>
#define ll long long
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define fi first
#define se second
#define prq priority_queue
#define foreach(it,c) for(__typeof((c).begin()) it=c.begin();it!=c.end();it++)
using namespace std;
inline ll read(){
	ll x=0;
	int f=1;
	char c=getchar();
	for(;!isdigit(c);c=getchar()) if(c=='-')f=-f;
	for(;isdigit(c);c=getchar())x=x*10+(c-'0');
	return x*f;
}
int main(){
	//freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
	int a,b;
	cin>>a>>b;
	cout<<(a*3+b)/2;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, const char * argv[]) {
    int i,j,H,W;
    while(1){
        scanf("%d %d",&H,&W);
        if(H==0&&W==0)break;
        for(i=0;i<H;i++){
            for(j=0;j<W;j++){
                if((i+j)%2==0){
                    printf("#");
                }else{
                    printf(".");
                }
            }
        printf("\n");
    }
    printf("\n");
}
    return 0;
}

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

int n;
string s;
vector<vector<int>> DP;
const int inf = (int)1e9 + 7;

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

	// the idea is to case work the last element 
	// 4 <><
	// 1 < 3 > 2		4
	// 2 < 3 > 1		4
	// 1 < 4 > 2		3
	// 2 < 4 > 1		3
	// 3 < 4 > 1		2

	// if doing this way the only thing that matters is number of prefixes (satisfy requirements)
	// and the last element on the prefix (interface to the last element) the prefix of length len is using 1 ... len
	// 2D DP[len][j] array, len is the lengh of the prefix, and j is the last element in the prefix
	// len 1 ... n, j 1 ... n
	DP.resize(n + 1);
	for (int i = 2; i < n + 1; i++)
		DP[i].resize(n + 1, 0);
	DP[1].resize(n + 1, 1);
	// brute force approach
#if 0
	for (int len = 2; len < n + 1; len++)
	{
		for (int j = 1; j < len + 1; j++)
		{
			for (int k = 1; k < len + 1; k++)
			{
				// j is the last element that I am working on, k is the last element of the len-1 prefix
				// k can be anything from 0 to n-1, but k can't be same as j
				// if k and j not satisfy relation dont do anything
				if (k == j)
					continue;
				if ((s[len - 2] == '>' && k < j) || (s[len - 2] == '<' && k > j))
					continue;
				int k_sub = k;
				if (k > j)
					k_sub--;
				DP[len][j] = (DP[len][j] + DP[len - 1][k_sub]) % inf;
			}
		}
	}
#endif
	vector<int> psum;
	psum.resize(n+1, 0);
	for (int len = 2; len < n + 1; len++)
	{
		fill(psum.begin(), psum.end(), 0);
		for (int j = 1; j < len + 1; j++)
		{
			psum[j] = (psum[j - 1] + DP[len - 1][j])%inf;
		}
		for (int j = 1; j < len + 1; j++)
		{
			// either sum from 1 to j -1 or j+1 to len depend on the comparator from the string
			// so we can do prefix sum
			if(s[len-2]=='<')
				DP[len][j] = psum[j - 1];
			else if (s[len - 2] == '>')
				DP[len][j] = (psum[len-1] - psum[j-1]+inf)%inf;
		}
	}

	int total = 0;
	for (int j = 1; j < n+1; j++)
	{
		total = (total+DP[n][j])%inf;
	}
	cout << total << endl;
}

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

int main() {
  int n;
  double m;
  cin >> n >> m;
  int vote[n];
  double sum = 0;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    vote[i] = x;
    sum += x;
  }
  double sumsum = sum/(4*m);
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (vote[i] >= sumsum) ans++;
  }
  cout << ((ans >= m) ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
N = int(input())
xy = []
for i in range(N):
    a, b = (int(x) for x in input().split())
    xy.append([a, b])
    
def distance(d, xy, i, j):
    return (
              (xy[i][0] - xy[j][0]) ** 2
            + (xy[i][1] - xy[j][1]) ** 2
        ) ** 0.5
 
import itertools
d = []
l1 = [x for x in range(N)]
for v in itertools.permutations(l1, N):
    l2 = list(v)
    d0 = []
    for c in range(N-1):
        i = l2[c]
        j = l2[c+1]
        d0.append(distance(d, xy, i, j))
    d.append(sum(d0))
 
print(sum(d) / len(d))

Measured memory_bytes: 4528
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=100001,INF=1<<30;
vector<int> S[MAX],point(MAX),C(MAX);

int BFS(){
    int ans=0,cnt=1;
    queue<int> Q;
    point[0]=C[0];
    Q.push(0);
    while(!Q.empty()){
        int a=Q.front();
        Q.pop();
        for(int i=0;i<S[a].size();i++){
            int b=S[a][i];
            if(point[b]) continue;
            point[b]=C[cnt];
            cnt++;
            ans+=point[b];
            Q.push(b);
        }
    }
    return ans;
}

int main(){
    
    int N;cin>>N;
    for(int i=0;i<N-1;i++){
        int a,b;cin>>a>>b;
        a--;b--;
        S[a].push_back(b);
        S[b].push_back(a);
    }
    
    for(int i=0;i<N;i++){
        cin>>C[i];
    }
    
    sort(C.rbegin(),C.rend());
    
    cout<<BFS()<<endl;
    
    for(int i=0;i<N;i++){
        if(i) cout<<" ";
        cout<<point[i];
    }
    
    cout<<endl;
}


Measured memory_bytes: 3840
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long int ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
#define REP(i,n) for(int i=0;i<(n);i++)
const int INF=100000000;

ll N,A[100010],B[100010],ans1,ans2,mode,sum;

int main(){
	cin>>N;
	REP(i,N){
		cin>>A[i];
		B[i]=A[i];
	}
	REP(i,N){
		sum+=A[i];
		if(mode==0){
			if(sum<=0){
				ans1+=abs(1-sum);
				sum=1;
			}
			mode=1;
		}
		else{
			if(sum>=0){
				ans1+=abs(-1-sum);
				sum=-1;
			}
			mode=0;
		}
		DEB(sum)END
	}
	sum=0,mode=0;
	REP(i,N){
		sum+=A[i];
		if(mode==1){
			if(sum<=0){
				ans2+=abs(1-sum);
				sum=1;
			}
			mode=0;
		}
		else{
			if(sum>=0){
				ans2+=abs(-1-sum);
				sum=-1;
			}
			mode=1;
		}
	}
	cout<<std::min(ans1,ans2)<<endl;
	return 0;
}

Measured memory_bytes: 1792