akhauriyash/Code-Regression huggingface dataset:
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	mp := make(map[int]int)
	for i := 0; i < n; i++ {
		var tmp int
		fmt.Scan(&tmp)
		mp[tmp] = mp[tmp] + 1
	}
	count := 0
	for k, v := range mp {
		if v >= k {
			count += v - k
		} else {
			count += v
		}
	}
	fmt.Println(count)
}

Measured memory_bytes: 8960
#pragma GCC optimize "-O3"
#pragma GCC target ("avx")
#define _USE_MATH_DEFINES
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define inf (1ll<<60)
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v),greater<int>())
signed gcd(int a, int b){return b?gcd(b,a%b):a;}
signed lcm(int a,int b){return a*b/gcd(a,b);}

using namespace std;

const int mod=1e9+7;

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

signed f(int num){
    if(num%2==0)return num/2;
    else return num*3+1;
}

void run(){
    int n,k;
    cin >> n >> k;
    vi h(n);
    rep(i,n)cin >> h[i];
    RSORT(h);
    vi sa(n-k+1);
    rep(i,n-k+1)
    {
        sa[i]=h[i]-h[i+k-1];
    }
    SORT(sa);
    cout << sa[0] << endl;
}

Measured memory_bytes: 1792
#include <algorithm>
#include <cmath>
#include <complex>
#include <iomanip>
#include <iostream>
#include <string>
#include <utility>
#include <vector>

using namespace std;

using ll = long long int;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 373;

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

template <typename T>
using vector2 = vector<vector<T>>;
template <typename T>
vector2<T> init_vector2(size_t n0, size_t n1, T e = T()) {
    return vector2<T>(n0, vector<T>(n1, e));
}

template <typename T>
using vector3 = vector<vector<vector<T>>>;
template <typename T>
vector3<T> init_vector3(size_t n0, size_t n1, size_t n2, T e = T()) {
    return vector3<T>(n0, vector2<T>(n1, vector<T>(n2, e)));
}

int main() {
    int x, a, b;
    cin >> x >> a >> b;
    cout << (x - a) % b << endl;
    return 0;
}


Measured memory_bytes: 504
#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 DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define INF (1LL<<50)

signed main(){

	lli n;
	cin>>n;

	vector<lli> a(n);
	lli cnt=0;

	REP(i,0,n){
		cin>>a[i];
		if(i!=0){
			if(a[i]==a[i-1]){
				a[i] = INF-cnt;
				cnt++;
			}
		}
	}

	cout<<cnt<<endl;




	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    int n,m,k,a,i,j,cnt[30] = {0},ans = 0;

    scanf("%d %d",&n,&m);
    for (i = 0; i < n; i++)
    {
        scanf("%d",&k);
        for(j = 0;j < k;j++)
        {
            scanf("%d",&a);
            cnt[a - 1]++;
        }
    }

    for (i = 0; i < m; i++)
    {
        if(cnt[i] == n)ans++;
    }
    printf("%d",ans);
}

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

using namespace std;

int main(){
	int n , k ; 
	cin >> n >> k ; 
	int arr[n] ; 
	for(int& i : arr) cin >> i ;

	vector<bool>dp(k+1,false);
	for(int i=0;i<=k;i++){
		for(int stones : arr){
			if( i-stones >= 0 and dp[i-stones] == false){
				dp[i] = true;
			}
		}
	}

	cout << ( dp[k]?"First":"Second" ) << endl ;
	return 0;
}


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

#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define all(x) begin(x), end(x)
#define uniq(x) (x).erase(unique(all(x)), end(x))
#define bit(n) (1LL << (n))
#define dump(x) cerr << #x " = " << (x) << endl
using vint = vector<int>;
using vvint = vector<vint>;
using pint = pair<int, int>;
using vpint = vector<pint>;
template<typename T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
constexpr long double PI = 3.1415926535897932384626433832795028L;
constexpr int DY[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int DX[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T> void fin(T mes) {
    cout << mes << endl;
    exit(0);
}
template<typename T, typename U> bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct setup {
    static constexpr int PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

int H;
signed main() {
    cin >> H;
    int ans = 0, n = 1;
    while (H > 0) {
        ans += n;
        n *= 2;
        H /= 2;
    }
    cout << ans << endl;
}

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

using namespace std;

int main() {
    int n;
    cin >> n;
    int a[n];
    for (auto &ai:a)
        cin >> ai;
    double sum = 0;
    for (auto &ai:a) {
        sum += 1 / (double) ai;
    }
    cout << setprecision(10) << 1 / sum << '\n';
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<map>
#include<algorithm>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
int main(void){
    int n,a,b;
    cin>>n;
    vector<int> v(n,0);
    rep(i,n){
        cin>>v[i];
    }
    int count=0;
    bool f=1;
    while(f){
        count++;
        bool f=1;
        rep(i,n){
            if(v[i]%2==0) v[i]/=2;
            else{
                count--;
                f=0;
                break;
            }    
        }
        if(f!=1) break;       
    }
    cout<<count<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,1,0,-1},dy={-1,0,1,0};
bool inside(int y,int x,int h,int w){
	if(y<h && y>=0 && x<w && x>=0) return true;
	return false;
}





int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int s;cin >> s;
	vector<int> a(1000000, -1);
	a.at(s) = 1;
	int k = 2;
	while(true){
		if(s % 2 == 0) s /= 2;
		else s = s * 3 + 1;
		if(a.at(s) != -1){
			a.at(s) = k;
			break;
		}
		a.at(s) = k;
		k++;
	}
	cout << a.at(s) << endl;
}


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

typedef complex<long double> P;
typedef pair<P, P> L;

const long double INF = 1e+9;
const long double EPS = 1e-5;

bool equal(long double a, long double b){ return fabs(a-b) < EPS;}
long double dot(P a, P b){ return real(conj(a)*b); }
long double cross(P a, P b){ return imag(conj(a)*b); }
int ccw(P a, P b, P c){
  b -= a;
  c -= a;
  if(cross(b,c) > EPS) return 1;
  if(cross(b,c) < -EPS) return -1;
  if(dot(b,c) < -EPS) return 2;
  if(norm(b) < norm(c)) return -2;
  return 0;
}
P crossPoint(L l, L m){
  long double A = cross(l.second - l.first, m.second - m.first);
  long double B = cross(l.second - l.first, l.second - m.first);
  if(fabs(A) < EPS && fabs(B) < EPS) return m.first;
  else if(fabs(A) >= EPS) return m.first + B / A * (m.second - m.first);
}
vector<P> convex_cut(vector<P> G, L l){
  vector<P> ans;
  for(int i=0;i<G.size();i++){
    P A = G[i];
    P B = G[(i+1)%G.size()];
    if(ccw(l.first, l.second, A) != -1) ans.push_back(A);
    if(ccw(l.first, l.second, A) * ccw(l.first, l.second, B) < 0)
      ans.push_back(crossPoint(L(A,B), l));
  }
  return ans;
}
long double area(vector<P> v){
  long double sum = 0.0;
  int n = v.size();
  for(int i=0;i<n;i++) sum += (real(v[i]) - real(v[(i+1)%n])) * (imag(v[i]) + imag(v[(i+1)%n]));
  return fabs(sum) / 2;
};
bool equal(P a, P b){
  return equal(a.real(), b.real()) && equal(a.imag(), b.imag());
}


int n;
vector<P> v;

long double binary_search(bool is_h){
  L l;
  long double le = -INF, ri = INF, mid;
  vector<P> cut_v;

  while(ri - le > EPS/1000.0){
    mid = (ri + le) / 2.0;
    if(is_h) l = L(P(-INF, mid), P(INF, mid));
    else l = L(P(mid, INF), P(mid, -INF));
    cut_v = convex_cut(v, l);
    if(area(v) > area(cut_v) * 2.0) ri = mid;
    else le = mid;
  }

  return (ri + le) / 2.0;
}

P solve(){
  P res = P(binary_search(false), binary_search(true));
  bool f = true;

  if(n % 2 == 1) f = false;
  else {
    for(int i=0;i<n/2;i++){
      if(!equal(v[i] - res, res - v[i+n/2])){
        f = false;
        break;
      }
    }
  }

  if(f) return res;
  else return P(INF, INF);
}

int main(){
  long double x, y;
  while(cin >> n){
    v.clear();
    for(int i=0;i<n;i++){
      cin >> x >> y;
      v.push_back(P(x, y));
    }
    P res = solve();
    if(equal(res, P(INF, INF))) cout << "NA" << endl;
    else printf("%.6Lf %.6Lf\n",res.real(),res.imag());
  }
}

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

public class Main {
    public static void main(String[] args) {
        try {
            // 標準入力
            InputStreamReader isr = new InputStreamReader(System.in);
            BufferedReader br = new BufferedReader(isr);
            String strArr[] = br.readLine().split("");
            int ans = 700;
            for (int i = 0; i < strArr.length; i++) {
                if ("o".equals(strArr[i])) {
                    ans += 100;
                }
            }
            System.out.println(ans);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}


Measured memory_bytes: 21332
#include <iostream>
#include <algorithm>
#include <limits.h>
using namespace std;

// 2で割れる回数を返す
int MyLog2(int n) {
	int kaisuu = 0;
	for (; n % 2 == 0; n /= 2) {
		kaisuu++;
	}
	return kaisuu;
}

int main() {
	int N = 0;
	cin >> N;
	int ans = INT_MAX;
	for (int i = 0; i < N && ans!=0; i++) {
		int Ai = 0;
		cin >> Ai;
		ans = min(ans, MyLog2(Ai));
	}
	cout << ans << endl;
}

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

int main(){
  int N,K;
  string S;
  cin >> N >> S >> K;
  char p = S[K - 1];
  for (int i = 0; i < N; i++){
    if (p != S[i]) S[i] = '*';
  }
  cout << S << endl;
}
  

Measured memory_bytes: 256
N, M = map(int, input().split())
mod = 1000000007
dp = [0] * (N+2)
A = set([int(input()) for _ in range(M)]) 
dp[-2] = 1

for i in range(N-1, -1, -1):
    if (i in A) == False:
        dp[i] = (dp[i + 1] + dp[i + 2]) % mod 

print(dp[0])

Measured memory_bytes: 13984
/*
💭             💭
    💭        💭
     💭     💭
  💭💭💭☁
💭🌘💭🌘☁
💭💭🌸💭☁
  ☁☁☁☁
      🎀🎀🎀☁
      💭💭💭💭☁
      🍴 💭🍴💭☁ 💭
      📨  ☁📨☁☁





😡😡😡😡😡😡😡
😁I'm so angry!😁
💀💀💀💀💀💀💀
😑😤😤😤😤😤😑
  🔥✂✂✂✂✂🔥
😡😡😡😡😡😡😡
*/#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define print(a) for(auto f:a)cout<<f<<" ";
#define sor(v) sort(v.begin(),v.end());
#define rsor(v) sort(v.rbegin(),v.rend());
#define rev(v) reverse(v.begin(),v.end())
#define all(v) (v.begin(),v.end())
#define fi first
#define se second
#define lp(x,q) for(ll i=x ;i<q;i++)
#define pb(x) push_back(x)
#define pob pop_back()
#define res(v,a) v.resize(a)
#define md(q,w)  (q+w)/2;
#define lp(q,w) for(ll x=q;x<w;x++)
#define MY_TORNADO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define minn(v) *min_element(v.begin(),v.end())
#define maxx(v) *max_element(v.begin(),v.end())
vector<vector<int>>adj;
vector<bool>vis(1e5,false);
vector<int>level(1e4);
//global variable:
ll cou=0,mx=INT_MIN,mn=INT_MAX,sum=0,av=0,hi=0,lo=0,ans=0,w,flag;



int main()
{int a,s;
cin>>a>>s;
sum=0;
while (s--){
    int t;
    cin>>t;
    sum+=t;
}
if(sum<a)cout<<"No";
else cout<<"Yes";
}

















/*😢😖😩😫😩😖😢
😢💔💔😫💔💔😢
💔👤👥💔👤👥💔😢
💔👤👤👤👤👥💔😢
💔👤👤👤👤👥💔😢
😢💔👤👤👥💔😢
😢😖💔👥💔😖😢
😢😖😩💔😩😖😢
😢😖😩😫😩😖😢


*/


Measured memory_bytes: 256
n,x = map(int, input().split())
al = list(map(int, input().split()))

ans = 0
if al[0] > x:
    ans += (al[0]-x)
    al[0] = x

for i in range(1,n):
    rem = al[i-1]+al[i] - x
    if rem > 0:
        al[i] -= rem
        ans += rem

print(ans)

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



int main()
{
    string a,b;
    cin >> a >> b;
    reverse(b.begin(),b.end());
    if(a==b) cout << "YES" << endl;
    else cout << "NO" << endl;

    return 0;

}

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

using namespace std;

int main()
{
	// 入力
	int N;
	cin >> N;
	vector<int> v(N);
	for (int i = 0; i < N; i++)
	{
		cin >> v[i];
	}
	// 具材の価値を昇順にソート
	sort(v.begin(), v.end());
	
	double answer = v[0];
	for (int i = 0; i < N; i++)
	{
		// 具材の価値の計算の更新
		answer = (answer + v[i]) / 2;
	}
	
	// 出力
	cout << answer << endl;
	
	return 0;
}

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

int main()
{
    int n,m,ans=0;
    cin>>n>>m;
    int freq[n+2]={0};
    for(int i=0; i<m; i++)
    {
        int a,b;
        cin>>a>>b;
        freq[a]++; freq[b+1]--;
    }
    for(int i=1; i<=n; i++)
    {
        freq[i]+=freq[i-1];
        if(freq[i]==m) ans++;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 640
local s=io.read()
local sable={a=0,b=0,c=0}
for i=1,#s do
    s_i=s:sub(i,i)
    sable[s_i]=sable[s_i]+1
end

if math.max(sable.a,sable.b,sable.c)-math.min(sable.a,sable.b,sable.c)<=1 then
    print("YES")
else
    print("NO")
end

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string S; cin >> S;
    int K; cin >> K;
    set<string> st;
    for(char c = 'a'; c <= 'z'; ++c){
        for(int i = 0; i < S.size(); ++i){
            if(S[i] != c) continue;
            for(int j = 1; j <= K && i+j <= S.size(); ++j) {
               st.insert(S.substr(i, j));
            }
        }
        if(st.size() >= K) {
            int counter = 1;
            for(string s : st){
                if(counter == K) {
                    cout << s << '\n';
                    return 0;
                }
                counter++;
            }
        }
    }
    return 0;
}

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

typedef long long ll;

int n;

int win[10][10];

int dfs(int s,int t){ // s:チーム目のt:試合目を見ている
	if(s==t)return dfs(s,t+1);
	if(s==n-1&&t==n)return 1;
	if(t==n)return dfs(s+1,0);
	if(win[s][t]!=0)return dfs(s,t+1);
	int res=0;
	int num=0,cnt=0;
	for(int i=0;i<n;i++){
		if(s==i)continue;
		if(win[s][i]==0)cnt++;
		else num+=win[s][i];
	}
	if(abs(num)>cnt)return 0;
	if(abs(num)==cnt){
		queue<int> q;
		if(num==cnt){
			for(int i=0;i<n;i++){
				if(s==i)continue;
				if(win[s][i]==0){
					win[s][i]=-1;
					win[i][s]=1;
					q.push(i);
				}
			}
		}
		else{
			for(int i=0;i<n;i++){
				if(s==i)continue;
				if(win[s][i]==0){
					win[s][i]=1;
					win[i][s]=-1;
					q.push(i);
				}
			}
		}
		bool ok=1;
		for(int i=s+1;i<n;i++){
			int p=0,pp=0;
			for(int j=0;j<n;j++){
				if(i==j)continue;
				if(win[i][j]==0)p++;
				else pp+=win[i][j];
			}
			if(abs(pp)>p)ok=0;
			if(!ok)break;
		}
		if(ok)res=dfs(s+1,0);
		else{
			while(q.size()){
				int qq=q.front(); q.pop();
				win[s][qq]=win[qq][s]=0;
			}
			return 0;
		}
		while(q.size()){
			int qq=q.front(); q.pop();
			win[s][qq]=win[qq][s]=0;
		}
	}
	else{
		win[s][t]=1;
		win[t][s]=-1;
		res+=dfs(s,t+1);
		win[s][t]=win[t][s]=0;
		win[s][t]=-1;
		win[t][s]=1;
		res+=dfs(s,t+1);
		win[s][t]=win[t][s]=0;
	}
	return res;
}

int main(){
	while(cin >> n,n){
		int m; cin >> m;
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				win[i][j]=0;
			}
		}
		for(int i=0;i<m;i++){
			int x,y; cin >> x >> y;
			x--; y--;
			win[x][y]=1;
			win[y][x]=-1;
		}
		cout << dfs(0,0) << endl;
	}
}



Measured memory_bytes: 3112
#include <bits/stdc++.h>
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rer(i, a, b) for(ll i = ll(a) - 1; i >= ll(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
using namespace std;
typedef long long int ll;
typedef pair <int, int> P;

const ll MOD=1000000007;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll K,A,B;
    cin>>K>>A>>B;
    if(B-A<=2||K<=A){
        cout <<K+1<<"\n";
        return 0;
    }
    if((K-A)%2){
        cout <<A+(B-A)*(K-A+1)/2<<"\n";
        return 0;
    }
    else{
        cout <<A+(B-A)*(K-A)/2+1<<"\n";
        return 0;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> C(N - 1), S(N - 1), F(N - 1);
  for (int i = 0; i < N - 1; i++){
    cin >> C[i] >> S[i] >> F[i];
  }
  for (int i = 0; i < N; i++){
    int t = 0;
    for (int j = i; j < N - 1; j++){
      t = max(t, S[j]);
      t = (t + F[j] - 1) / F[j] * F[j];
      t += C[j];
    }
    cout << t << endl;
  }
}

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

int main()
{
    ll x,y,i,c=0,t=0,s=1,p,q,j,k;
    cin>>x>>y;
    c=x*2;
    t=x*4;
    if(y<c||y>t)
    {
        s=1;
    }
    else if(y<=t&&y>=c)
    {
//        if(y%2==1)
//        {
//            s=1;
//        }
//        else
//        {
//            cc=y/2;
//            tt=y/4;
//
//        }
        for(j=0; j<x; j++)
        {
            for(k=j; k<=x; k++)
            {
                if(((j*2+k*4)==y)&&(j+k)==x)
                {
                    s=0;
                    //cout<<j<<" "<<k<<endl;
                }
            }
        }
        if(s==1)
        {
            for(j=0; j<x; j++)
            {
                for(k=j; k<=x; k++)
                {
                    if(((k*2+j*4)==y)&&(j+k)==x)
                    {
                        s=0;
                        //cout<<j<<"* "<<k<<endl;
                    }
                }
            }
        }
    }
    if(s==1)
    {
        cout<<"No"<<endl;
    }
    else
    {
        cout<<"Yes"<<endl;
    }
    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll; //int:2*10**9
typedef long double ld;
typedef pair<ll,ll> P;
#define REP(i,n) for(ll i = 0; i<(ll)(n); i++)
#define REPS(i,n) for (ll i = 1; i<=(ll)(n); i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define vec2(name,i,j) vector<vector<ll>> name(i,vector<ll>(j))
#define vec2f(name,i,j,k) vector<vector<ll>> name(i,vector<ll>(j,k))
#define vec3(name,i,j,k) vector<vector<vector<ll>>> name(i,vector<vector<ll>>(j,vector<ll>(k)))
#define vec3f(name,i,j,k,l) vector<vector<vector<ll>>> name(i,vector<vector<ll>>(j,vector<ll>(k,l)))
#define vec4(name,i,j,k,l) vector<vector<vector<vector<ll>>>> name(i,vector<vector<vector<ll>>>(j,vector<vector<ll>>(k,vector<ll>(l))))
#define vec4f(name,i,j,k,l,m) vector<vector<vector<vector<ll>>>> name(i,vector<vector<vector<ll>>>(j,vector<vector<ll>>(k,vector<ll>(l,m))))
#define pb push_back
#define MOD 1000000007
#define MOD2 998244353
#define PI 3.141592653
#define INF 100000000000000 //14
//cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
#define N 110000
vector<ll> minht(N);
vector<ll> maxht(N);
vector<ll> minha(N);
vector<ll> maxha(N);
vector<ll> t(N);
vector<ll> a(N);
vector<ll> minh(N);
vector<ll> maxh(N);

int main(){
    ll n; cin >> n;
    REP(i,n){
        cin >> t[i];
        if (i==0) minht[i]=maxht[i]=t[i];
        else if (i==n-1) {maxht[i]=t[i]; minht[i]=0;}
        else if (t[i]>t[i-1]) minht[i]=maxht[i]=t[i];
        else {maxht[i]=t[i]; minht[i]=0;}
    }
    REP(i,n){
        cin >> a[i];
    }
    FORD(i,n-1,0){
        if (i==n-1) minha[i]=maxha[i]=a[i];
        else if (i==0) {maxha[i]=a[i]; minha[i]=0;}
        else if (a[i]>a[i+1]) minha[i]=maxha[i]=a[i];
        else {maxha[i]=a[i]; minha[i]=0;}
    }
    REP(i,n){
        maxh[i]=min(maxha[i],maxht[i]);
        minh[i]=max(minha[i],minht[i]);
    }
    /*REP(i,n){
        cout << maxht[i] << " " << minht[i] << endl;
    }
    REP(i,n){
        cout << maxha[i] << " " << minha[i] << endl;
    }
    REP(i,n){
        cout << maxh[i] << " " << minh[i] << endl;
    }*/
    ll ans = 1;
    REP(i,n){
        if (maxh[i]<minh[i]) ans = 0;
        else if (minh[i]==0) ans = (ans*maxh[i])%MOD;
        else ans = (ans*(maxh[i]-minh[i]+1))%MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 9964
import java.util.*;

public class Main {
	public static void main(String args[]) {
    	Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int i = sc.nextInt();
        boolean check = false;
        while(check) {
        	if(1 <= n && n <= 100 && 1 <= i && i <= n) {
                check = true;
            }
            n = sc.nextInt();
            i = sc.nextInt();
        }
        
        
        System.out.println(n + 1 - i);
    }
}


Measured memory_bytes: 21844
N = int(input())
XYH_list = [list(map(int, input().split())) for i in range(N)]
XYH_list = sorted(XYH_list, key=lambda x: x[2], reverse=True)

for xi in range(0, 101):
    for yi in range(0, 101):
        tmpH = 0
        for k in range(N):
            x,y,h = XYH_list[k]
            if k == 0:
                tmpH =h + abs(x - xi) + abs(y - yi)
            if h == max((tmpH - abs(x - xi) - abs(y - yi)), 0):
                if k == N - 1:
                    ans = [str(xi), str(yi), str(tmpH)]
                continue
            else:
                break
print(' '.join(ans))

Measured memory_bytes: 9160
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define All(A) A.begin(),A.end()
#define RAll(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1e9+7;
const LL LINF=1LL<<62;
const LL INF=1<<30;


int main(){
    int N,M;
    while(cin >> N >> M){
        if(N==0&&M==0) break;
        vector<LL> s(N),d(M),ac(1<<N);
        for(int i=0;i<N;i++) cin >> s[i];
        for(int i=0;i<M;i++) cin >> d[i];
        for(int i=0;i<(1<<N);i++){
            for(int j=0;j<N;j++){
                if(i&(1<<j)) ac[i]+=s[j];
            }
        }
        sort(All(d));
        LL dp[M+1][1<<N];
        memset(dp,0,sizeof(dp));
        for(int i=1;i<M+1;i++){
            for(int j=0;j<(1<<N);j++){
                dp[i][j]=LINF;
            }
        }
        for(int m=0;m<M;m++){
            for(int k=0;k<(1<<N);k++){
                for(int s=0;s<N;s++){
                    if(k&(1<<s)) continue;
                    int p=k|(1<<s);
                    dp[m][p]=min(dp[m][p],dp[m][k]);
                }
                dp[m+1][k]=min(dp[m+1][k],dp[m][k]+abs(ac[k]-d[m]));
            }
        }
        LL ans=LINF;
        for(int k=0;k<(1<<N);k++){
            ans=min(ans,dp[M][k]);
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 29272
#include <stdio.h>

int main(){
    int a,b;
    scanf("%d %d",&a,&b);
    
    if(a < b){
        printf("a < b\n");
    }else if(a > b){
        printf("a > b\n");
    }else{
        printf("a == b\n");
    }
    
    return 0;
}

Measured memory_bytes: 580
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k; cin >> n >> k;
    vector<int> x(n);
    int ans = 0;
    for(int i = 0; i < n; i++)
    {
        cin >> x[i];
        ans += 2*min(k-x[i],x[i]);
    }
    cout << ans << endl;
}

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

using namespace std;

#define ll long long
#define ld long double
#define pll pair <ll , ll>

#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define mp make_pair

#define X first
#define Y second

#define LB(x) ((x) & -(x))
#define BIT(a , b) (((a)>>(b)) & 1)

const ll MAXN=1e5+10;
const ll MAXT=20;
const ll INF=1e9+10;

vector <pll> vertex[MAXN];

vector <pll> w;

ll a[MAXN];

ll dp[1<<MAXT];

ll e[MAXT];

bool check[MAXN];

void dfs(ll v)
{
    check[v]=true;

    for(ll i=0;i<vertex[v].size();i++)
    {
        if (!check[vertex[v][i].X])
        {
            dfs(vertex[v][i].X);
            a[v]^=vertex[v][i].Y;
            a[vertex[v][i].X]^=vertex[v][i].Y;
        }
    }
}

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

	ll n , x=0 , res=0;
	cin>>n;

	for(ll i=0;i<(n-1);i++)
    {
        ll v , u , w;
        cin>>v>>u>>w;

        v++;
        u++;

        vertex[v].pb(mp(u , w));
        vertex[u].pb(mp(v , w));
    }

    dfs(1);

    for(ll i=1;i<=n;i++)
    {
        e[a[i]]++;
    }

    for(ll i=1;i<=15;i++)
    {
        res+=(e[i]/2);

        if (e[i]&1)
        {
            x+=(1<<(i-1));
        }
    }

    for(ll mask=1;mask<(1<<15);mask++)
    {
        w.pb(mp(__builtin_popcount(mask) , mask));
    }

    sort(w.begin() , w.end());

    for(ll z=0;z<w.size();z++)
    {
        ll mask=w[z].Y;
        dp[mask]=INF;

        for(ll i=0;i<15;i++)
        {
            for(ll j=i+1;j<15;j++)
            {
                if (BIT(mask , i) && BIT(mask , j))
                {
                    ll w=((i+1)^(j+1))-1;
                    dp[mask]=min(dp[mask] , dp[mask^(1<<i)^(1<<j)^(1<<w)]+BIT(mask , w)+1);
                }
            }
        }
    }

    cout<<res+dp[x];
}

/*
4
0 1 1
1 2 2
2 3 4
*/


Measured memory_bytes: 14204
f = lambda:map(int,input().split())
n,m = f()
ll = [list(f()) for _ in range(m)]
l = [0]*n
d = {}
for p,y in sorted(ll,key=lambda k:k[1]):
  l[p-1] += 1
  d[y] = str(p).zfill(6)+str(l[p-1]).zfill(6)
for l in ll:
  print(d[l[1]])

Measured memory_bytes: 43940
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define f first
#define s second

void solve(){
    int n; cin>>n;
    // vector<int> v(n);
    ll sum=0;
    ll a;
    map<ll,ll> mp;
    for(int i=0;i<n;++i){
        cin>>a;
        // cin>>v[i];
        mp[a]++;
        sum += a;
    }
    ll q; cin>>q;
    ll x,y;
    while(q--){
        cin>>x>>y;
        ll k=mp[x];
        sum -= k*x;
        sum += k*y;
        mp[x] = 0;
        mp[y] += k;
        cout<<sum<<endl;
    }
}
int main() {
    // int t; cin>>t;
    // while(t--){
        solve();
        // cout<<endl;
    // }
}

Measured memory_bytes: 9408
def main
  n = gets.split.map(&:to_i)
  xs = gets.split.map(&:to_i)
  puts solve(xs)
end

def solve(xs)
  min = Float::INFINITY
  total = xs.reduce(:+)
  xs.pop
  x = 0
  for i in xs
    x += i
    cand = (2*x - total).abs
    min = cand if cand < min
  end
  min
end

main


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

int main() {
    int N;
    cin >> N;
    
    vector<int> vec(N);
    for(int i = 0; i < N;i++) {
        cin >> vec.at(i);
    }

    vector<int> cpy(vec);


    sort(vec.begin(),vec.end());

    int bef = N / 2 - 1;
    int aft = N / 2;

    for(int i = 0; i < N; i++) {
        if(cpy.at(i) <= vec.at(bef) ) {
            cout << vec.at(aft) << endl;
        }else if(cpy.at(i) >= vec.at(aft)) {
            cout << vec.at(bef) << endl;
        }
    }
    // for(int i = 0; i < N;i++) {
    //     cout << cpy.at(i) << " ";
    // }
    // cout << vec.at(aft) << " " << vec.at(bef) << endl;
    
 }


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

using ll=long long;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  bitset<32> ANS;
  ANS.set();
  rep(i,n){
    int k;
    cin >> k;
    bitset<32> res;
    rep(j,k){
      int num;
      cin >> num;
      res.set(num,1);
    }
    ANS = ANS & res;
  }
  cout << ANS.count() << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <limits>
#include <queue>
#include <iomanip>
#include <set>
//#include <bits/stdc++.h>
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;}
using namespace std;
#define ALL(X) X.begin(),X.end()
using ll = long long int;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
const int MOD=1000000007;
//const int MOD=998244353;
const int INTMAX=2147483647;
const ll LLMAX=9223372036854775807;


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    ll N,K;
    cin>>N>>K;
    vll A(N);
    for(ll i=0;i<N;i++){
        cin>>A[i];
        A[i]--;
    }
    
    vll count(N,-1);
    count[0]=0;
    ll now=0;
    ll i=1;
    while(true){
        now=A[now];
        if(count[now]==-1){
            if(i==K){
                cout<<now+1<<endl;
                return 0;
            }
            count[now]=i;
            i++;
        }else{
            break;
        }
    }
    
    ll target=(K-count[now])%(i-count[now])+count[now];
    //printf("%d,%d,%d,%d\n",i,count[now],target,now);
    for(ll i=0;i<N;i++){
        if(count[i]==target){
            cout<<i+1<<endl;
            return 0;
        }
    }
    
    return 0;
}


Measured memory_bytes: 6368
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=4e5+10;
int a[N],b[N];
int ta[N],tb[N];
int dp[N],fa[N];
int n,m,ans;
int find(int x){
	return fa[x]==x?x:fa[x]=find(fa[x]);
}
signed main(){
	scanf("%lld",&n);
	for(int i=1;i<=n;++i){
		scanf("%lld",&a[i]);
		a[n+1]^=a[i];
		ta[i]=a[i];
	}
	for(int i=1;i<=n;++i){
		scanf("%lld",&b[i]);
		b[n+1]^=b[i];
		tb[i]=b[i];
	}
	++n;
	ta[n]=a[n];tb[n]=b[n];
	sort(ta+1,ta+n+1);sort(tb+1,tb+n+1);
	for(int i=1;i<n;++i)
		if(ta[i]!=tb[i]){
			printf("-1");
			return 0;
		}
	for(int i=1;i<=n;++i) 
		if(a[i]!=b[i]||i==n){
			dp[++m]=a[i];
			dp[++m]=b[i];
			if(i<n)++ans;
		}
	if(!ans){
		printf("0");
		return 0;
	}
	sort(dp+1,dp+m+1);
	m=unique(dp+1,dp+m+1)-dp-1;
	for(int i=1;i<=m;++i)
		fa[i]=i;
	for(int i=1;i<=n;++i)
		if(a[i]!=b[i]){
			a[i]=lower_bound(dp+1,dp+m+1,a[i])-dp,
			b[i]=lower_bound(dp+1,dp+m+1,b[i])-dp;
			fa[find(a[i])]=find(b[i]);
		}
	for(int i=1;i<=m;++i)
		if(fa[i]==i)
			++ans;
	printf("%lld",ans-1);
	return 0;
}

Measured memory_bytes: 16896
use std::io::prelude::*;

fn input<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn main() {
    let n: usize = input();
    let a: Vec<i64> = (0..n).map(|_| input()).collect();

    let max = *a.iter().max().unwrap();
    let (_, r) = a.iter().fold((0, 0), |(m, r), &a| {
        let t = std::cmp::min(a, max - a);
        if m < t {
            (t, a)
        } else {
            (m, r)
        }
    });

    println!("{} {}", max, r);
}


Measured memory_bytes: 4476
#include <stdio.h>

int main()
{
    int n,i,start=0,goal,judge=0,p,search;
    char ans[10],b4ans,turn='l';
    scanf("%d", &n);
    goal = n;
    printf("0\n");
    fflush(stdout);
    scanf("%s", ans);
    if (ans[0] == 'V')
        return 0;
    for (i = 0; i < 19; i++)
    {
        if (judge == 1);
        {
            if (turn == 'l')
                turn = 'r';
            else
                turn = 'l';
        }
        if ((goal - start) % 2 == 0)
            p = (goal - start) / 2;
        else
        {
            if (turn == 'l')
                p = (goal - start + 1) / 2;
            else
                p = (goal - start - 1) / 2;
        }
        search = start + p;
        b4ans = ans[0];
        printf("%d\n", (search));
        fflush(stdout);
        scanf("%s", ans);
        if (ans[0] == 'V')
            return 0;
        if ((search - start) % 2 == 0)
        {
            if (ans[0] == b4ans)
            {
                start = search;
                judge = 0;
            }
            else
            {
                goal = start;
                start = search;
                judge = 1;
            }
        }
        else
        {
            if (ans[0] == b4ans)
            {
                goal = start;
                start = search;
                judge = 1;
            }
            else
            {
                start = search;
                judge = 0;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 760
#include <iostream>


using namespace std;

int sum_rank(int n){
  int n5 = n / 10000;
  n -= n5*10000;
  int n4 = n / 1000;
  n -= n4*1000;
  int n3 = n / 100;
  n -= n3*100;
  int n2 = n / 10;
  int n1 = n - n2*10;
  return n5+n4+n3+n2+n1;
}

int main(){
  int N;
  cin >> N;
  
  int sum_min = 10000;
  for (int a = 1; a <= (N+1)/2; a++){
    int b = N - a;
    sum_min = min(sum_min,sum_rank(a)+sum_rank(b));
  }
  
  cout << sum_min << endl;
  return 0;
}


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

int main() {
  ll N;
  cin >> N;
  if (N==0) {
    cout << 0 << endl;
    return 0;
  }
  vector<int> A(0);
  while (N != 0) {
    int n = A.size();
    if (N % (ll)(pow(2,n+1)) == (ll)(pow(2,n)) || N % (ll)(pow(2,n+1)) == (ll)(pow(2,n) - pow(2,n+1))) {
      A.push_back(1);
      N -= pow(-2,n);
    } else {
      A.push_back(0);
    }
  }
  reverse(A.begin(),A.end());
  for (int i = 0; i < A.size(); i++) {
    cout << A[i];
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int i = (int)(n); i >= 0; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;

int main(){
    int N;
    cin >> N;
    vector<int> vec(N);
    rep(i,N){
        cin >> vec[i];
    }
    int count = 0;
    rep(i,N){
        if (i % 2 == 0 && vec[i] % 2 == 1) count++;
    }
    cout << count << endl;
}

Measured memory_bytes: 3592
#include <iostream>
#include <cmath>
using namespace std;
typedef long long ll;

int main()
{
    ll x, k, d;
    cin >> x >> k >> d;
    ll ans = 0;
    if(x < 0) x = -x;

    if(k < x/d) {ans = x - k * d; } 
    else{
        if(!((k - x / d) % 2)) {ans = x % d;} 
        else { ans = d - x % d; } 
    }

    cout << ans << endl;

    return 0;
}

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

int main()
{
	int n;
	int hen[3];
	
	cin >> n;
	
	for (int i = 0; i < n; i++){
		for (int j = 0; j < 3; j++){
			cin >> hen[j];
			hen[j] *= hen[j];
		}
		
		sort(hen, hen + 3);
		
		if ((hen[0] + hen[1]) == hen[2]){
			cout << "YES";
		}
		else {
			cout << "NO";
		}
		cout << endl;
	}
	
	return (0);
}

Measured memory_bytes: 1164
#include<stdio.h>
int g[9][9]={};
int visit[9]={},n;
int dfs(int p){
  visit[p]=1;
  int flag=1,cnt=0;
  for(int i=1;i<=n;i++)
    flag*=visit[i];
  if(flag){
    visit[p]=0;
    return 1;
  }
  for(int i=2;i<=n;i++)
    if(g[p][i]==1&&visit[i]==0)
      cnt+=dfs(i);
  visit[p]=0;
  return cnt;
}

int main(){
  int m,a,b;
  scanf("%d %d",&n,&m);
  for(int i=0;i<m;i++){
    scanf("%d %d",&a,&b);
    g[a][b]=g[b][a]=1;
  }
  printf("%d\n",dfs(1));
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
 
using namespace std;
 
#define repr(i,a,b) for (int i=a; i<b; i++)
#define rep(i,n) for (int i=0; i<  n; i++)
 
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; }
 
const long long INF = 1LL << 60;
#define PI 3.14159265359 
 
template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}
 
int gcd(int a, int b){
    if(b == 0) return a;
    else return gcd(b, a%b);
}
 
long long lcm (int a, int b){
    return  (long long) a*b /gcd(a,b);
}

long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }



int collatz(int n){
    int a=n;
    if(a%2 == 0)a/=2;
    else a = a*3+1;
    return a;
}

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

    for(int i = 0; i<3 ; i++){
        if(s[i] == '1')s[i] = '9';
        else if(s[i] ='9')s[i]= '1';
    }
    cout << s << endl;

}



Measured memory_bytes: 3576
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define FORSTEP(i, start, end, step) for (int i = start; i < end; i += step)
#define RFOR(i, start, end) for (int i = start; end <= i; i--)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1000000007
typedef long long ll;
const int INF32 = 2147483647;
const ll INF64  = 9223372036854775807;
using namespace std;

template <class T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}

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

    int N;
    cin >> N;
    vector<int> a(N);
    REP(i, N) cin >> a[i];

    SORT(a);
    int ans = 0;
    FOR(i, a[0], a[N - 1] + 1) {
        auto x  = equal_range(ALL(a), i - 1);
        auto y  = equal_range(ALL(a), i);
        auto z  = equal_range(ALL(a), i + 1);
        int sum = x.second - x.first + y.second - y.first + z.second - z.first;
        chmax(ans, sum);
    }

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

Measured memory_bytes: 640
S = input()
maxlen = 0
top = 0
while top < len(S):
    c = top
    while c < len(S):
        if S[c] == 'A' or S[c] =='C' or S[c] == 'G' or S[c] == 'T':
            c += 1
        else:
            break
    if maxlen < c - top:
        maxlen = c - top
    top = c + 1

print(maxlen)

Measured memory_bytes: 3060
#include <iostream>
#include<string>
using namespace std;
int main(void){
    string S;
    cin>>S;
    int T;
    T=S.size();
    for (int i=0; i<T; i=i+2) {
        cout << S[i] ;
    }
    cout<<endl;
    
    
    return 0;
    
}

Measured memory_bytes: 512
N = int(input())
n = N - 1
A = list(str(n))
A = list(int(n) for n in A)
ans1 = sum(A) + 1

n = N // 2
A = list(str(n))
A = list(int(n) for n in A)
ans2 = 2 * sum(A)

if N % 2 == 0:
    ans = min(ans1, ans2)
else:
    ans = min(ans1, ans2 + 1)

print(ans)

Measured memory_bytes: 9144
#include <iostream>
#include <string>
#include <queue>
#include <utility>
#include <algorithm>
#include <numeric>
#include <set>
#include <climits>
#include <map>
#include <cmath>
#include <deque>
#include <numeric>

using namespace std;

long long x[100000];
long long v[100000];

long long cum_sum_v[100000];
long long max_profit[100000];
long long reverse_cum_sum_v[100000];
long long reverse_max_profit[100000];
int main(){
  int N;
  long long C;
  cin >> N >> C;
  for(int i = 0; i < N; i++){
    cin >> x[i] >> v[i];
  }

  cum_sum_v[0] = v[0];
  max_profit[N - 1] = cum_sum_v[0] - x[0];
  for(int i = 1; i < N; i++){
    cum_sum_v[i] = cum_sum_v[i - 1] + v[i];
    max_profit[i] = max(cum_sum_v[i] - x[i], max_profit[i - 1]);
  }

  reverse_cum_sum_v[N - 1] = v[N - 1];
  reverse_max_profit[N - 1] = reverse_cum_sum_v[N - 1] - (C - x[N - 1]);
  for(int i = N - 2; i >= 0; i--){
    reverse_cum_sum_v[i] = reverse_cum_sum_v[i + 1] + v[i];
    reverse_max_profit[i] = max(reverse_cum_sum_v[i] - (C - x[i]), reverse_max_profit[i + 1]);
  }

  long long ans = 0;


  //go right first
  //turn aroiund from start
  ans = max(ans, reverse_max_profit[0]);

  for(int i = 0; i < N - 1; i++){
    long long tmp_ans = cum_sum_v[i] - x[i];
    long long turn_around_profit = max((long long) 0, reverse_max_profit[i + 1] - x[i]);
    tmp_ans += turn_around_profit;
    ans = max(ans, tmp_ans);
  }
  //no turn around
  ans = max(ans, cum_sum_v[N - 1] - x[N - 1]);

  //go left first
  for(int i = N - 1; i > 0; i--){
    long long tmp_ans = reverse_cum_sum_v[i] - (C - x[i]);
    long long turn_around_profit = max((long long) 0, max_profit[i - 1] - (C  - x[i]));
    tmp_ans += turn_around_profit;
    ans = max(ans, tmp_ans);
  }

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


Measured memory_bytes: 4992
class UnionFind():
    def __init__(self,n):
        self.n=n
        self.parents=[-1]*n

    def find(self,x): #要素xが属するグループの根を返す
        #根ならその番号を返す
        if self.parents[x]<0: 
            return x 
        # 根でないなら、親の要素で再検索
        else:
            # 走査していく過程で親を書き換える
            self.parents[x]=self.find(self.parents[x])
            return self.parents[x]
    
    def union(self,x,y): #要素xが属するグループと要素yが属するグループとを併合する
        #根を探す
        x=self.find(x)
        y=self.find(y)

        if x==y:
            return
        if self.parents[x]>self.parents[y]: #グループの大きい方に合わせる
            x,y=y,x

        self.parents[x]+=self.parents[y] #x(根)の要素にｙ(根)のグループの要素数をプラスする(要素の値は負の数で表される)
        self.parents[y]=x

    def size(self,x): #要素xが属するグループのサイズ（要素数）を返す
        return -self.parents[self.find(x)]
    
    def same(self,x,y): #要素x, yが同じグループに属するかどうかを返す
        return self.find(x)==self.find(y)

    def members(self,x): #要素xが属するグループに属する要素をリストで返す
        root=self.find(x)
        return [i for i in range(self.n) if self.find(i)==root]
    
    def roots(self): #すべての根の要素をリストで返す
        return [i for i ,x in enumerate(self.parents) if x<0]

    def group_count(self): #グループの数を返す
        return len(self.roots())

    def all_group_members(self): #{ルート要素: [そのグループに含まれる要素のリスト], ...}の辞書を返す
        return {r:self.members(r) for r in relf.roots()}

    def __str__(self): #ルート要素: [そのグループに含まれる要素のリスト]を文字列で返す (print()での表示用)
        return '\n'.join('{}:{}'.format(r,self.members(r)) for r in self.roots())

N,M,K=map(int,input().split())
uf=UnionFind(N)
friend=[0]*N
block=[0]*N

#友達関係
for i in range(M):
    a,b=map(int,input().split())
    uf.union(a-1,b-1) #a,bが所属するグループを併合
    friend[a-1]+=1
    friend[b-1]+=1

#ブロック関係
for i in range(K):
    c,d=map(int,input().split())
    if uf.same(c-1,d-1): #同じグループだった場合
        block[c-1]+=1
        block[d-1]+=1

#(iを含むグラフの連結成分のサイズ)-(iと同一の連結成分に含まれている人のうち、iと友達関係にある人の数)-(iと同一の連結成分に含まれている人のうち、iとブロック関係にある人の数)-1
print(' '.join([str(uf.size(i)-friend[i]-block[i]-1) for i in range(N)]))

Measured memory_bytes: 15560
import java.util.*;

public class Main {

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();

        UF uf = new UF(n);
        for(int i=0 ;i< m; i++) {
            uf.join(sc.nextInt() - 1, sc.nextInt() - 1);
        }

        int[] c = new int[n];
        int max = 0;
        for(int i=0; i<n; i++) {
            c[uf.root(i)]++;
            max = Math.max(max, c[uf.root(i)]);
        }
        System.out.println(max);

    }

    static class UF {
        int[] p;
        int n;

        UF(int n) {
            this.n = n;
            p = new int[n];
            for(int i=0; i<n; i++){
                p[i] = i;
            }
        }
        int root(int a) {
            if(p[a] == a) {
                return a;
            }

            int res =  root(p[a]);
            p[a] = res;
            return res;

        }

        void join(int a ,int b) {
            p[root(a)] = p[root(b)];
        }
    }




}

Measured memory_bytes: 69064
n,m = map(int,input().split())
lis = input().split()
lis = [int(i) for i in lis]
s = sum(lis)
ans = 0


for i in range(n):
    if lis[i] >= s*(1/(4*m)):
        ans += 1


if ans >= m:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 38384
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<cmath>
#include<string>
#include<bitset>
#include <sstream>
#include<queue>
#include<set>
#include<iomanip>
#define rep(i,n) for(ll i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef pair<double,double>P;

int main()
{
    string s,t,u;
    int a,b;
    cin>>s>>t;
    cin>>a>>b;
    cin>>u;
    if(u==s && a>0)a--;
    if(u==t && b>0)b--;
    cout<<a<<" "<<b;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	set<int> color; color.clear();
	int a, b, c; cin >> a >> b >> c;

	color.insert(a);
	color.insert(b);
	color.insert(c);

	cout << (int)color.size() << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i, x, n) for(int i = x; i < (int)(n); ++i)
 
int x[3001];
vector<int> tr[3001];
bool bad[3001];
 
bool go(int v, int p = 0){
	if (bad[v])return false;
	bool w = false;
	f(i, 0, tr[v].size())if (tr[v][i] != p && x[tr[v][i]] < x[v])w |= !go(tr[v][i], v);
	return w;
}
 
int main(){
	int n;
	scanf("%d", &n);
	f(i, 1, n + 1)scanf("%d", x + i);
	f(i, 1, n){
		int a, b;
		scanf("%d%d", &a, &b);
		tr[a].push_back(b);
		tr[b].push_back(a);
	}
	f(i, 1, n + 1){
		bool b = true;
		f(j, 0, tr[i].size())if (x[tr[i][j]] < x[i])b = false;
		if (b)bad[i] = true;
	}
	bool s = false;
	f(i, 1, n + 1)if (!bad[i] && go(i)){
		if (s)printf(" ");
		s = true;
		printf("%d", i);
	}
	printf("\n");
}


Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<iomanip>
using namespace std;
typedef long long ll;
const int INF=100000000;
const int MOD=1000000007;

int main()
{
  string s,ans;
  int sign[3];
  string ssign[3];
  cin >> s;
  for(int i=0;i<(1<<3);i++){
    for(int j=0;j<3;j++){
      if((i&(1<<j))==0) sign[j]=1;
      else sign[j]=-1;  
    }
//     cout << sign[0] <<  sign[1] <<  sign[2]<<  endl;
  	if((s[0]-'0')+sign[0]*(s[1]-'0')+sign[1]*(s[2]-'0')+sign[2]*(s[3]-'0')==7){
      for(int k=0;k<3;k++){
      if(sign[k]==1) ssign[k]="+";
      else ssign[k]="-";  
    }
      cout << s[0] << ssign[0] << s[1] << ssign[1] << s[2] << ssign[2]<< s[3] <<"=7"<< endl;
      break;
    }
  }
  return 0;
}

Measured memory_bytes: 256
def main(a,b,c,x):
    count = 0
    #各硬化を何枚選ぶか全探索
    for i in range(a+1):
        for j in range(b+1):
            for k in range(c+1):
                p = (500*i) + (100*j) + (50*k)
                if p == x:
                    count += 1
    return count

a = int(input())
b = int(input())
c = int(input())
x = int(input())
print(main(a,b,c,x))

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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define FOR(i, a, b) for (ll i=a; i<(b); i++)
#define range(a) a.begin(), a.end()
#define endl "\n"
#define Yes() cout << "Yes" << endl
#define No() cout << "No" << endl
using Graph = vector<vector<int>>;
const unsigned long long mod = 1e9 + 7;
const long long INF = 1LL<<60;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
void chmin(long long &a, long long b) { if (a > b) a = b; }
void chmax(long long &a, long long b) { if (a < b) a = b; }

int main(void){

    ll N,sum,ans=INF;   cin>>N;
  	ll A=sqrt(N);
    FOR(i,1,A+1){
        if(N%i==0){
            sum=i+N/i;
            ans=min(sum,ans);
        } 
    }

    cout<<ans-2<<endl;

    return 0;
}




Measured memory_bytes: 3620