akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES 
#include <cmath>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<string>
#include<vector>
#define rep(i,start,n) for(int i=start;i<n;i++)
#define And &&
#define Or ||
#define Lb cout<<endl
using namespace std;

int main(void) {
	string str;
	getline(cin, str);
	rep(i, 0, str.length()) {
		if (islower(str[i])) str[i]=toupper(str[i]);
		else str[i]=tolower(str[i]);

	}
	cout << str << endl;
}

Measured memory_bytes: 1176
k,n = map(int,input().split())

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

d = [0]*n
for i in range(n):
    if i!=(n-1):
        d[i] = a[i+1]-a[i]
    else:
        d[i] = a[0] + k - a[i]

ans = sum(d) - max(d)

print(ans)

Measured memory_bytes: 77388
// Package main provides
//
// File:  main.go
// Author: ymiyamoto
//
// Created on Wed Feb  6 11:23:19 2019
//
package main

import (
	"fmt"
	"sort"
)

func main() {
	var N, H int
	fmt.Scan(&N, &H)

	as := make([]int, N)
	bs := make([]int, N)
	for i := range as {
		fmt.Scan(&as[i], &bs[i])
	}
	sort.Ints(as)
	sort.Ints(bs)
	maxA := as[len(as)-1]

	ans := 0
	for i := len(bs) - 1; i >= 0; i-- {
		if bs[i] > maxA {
			H -= bs[i]
			ans++
			if H <= 0 {
				fmt.Println(ans)
				return
			}
		}
	}

	ans += (H + maxA - 1) / maxA
	fmt.Println(ans)
}


Measured memory_bytes: 5504
#include <bits/stdc++.h>
#define ll long long
#define V vector<long long>
#define VV vector<vector<long long>>
#define rep(i,n) for(ll (i)=0;(i)<(n);++(i))
using namespace std;

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

int main(){
    ll k;
    cin>>k;
    ll sum1=0;
    for(ll i=1;i<=k;i++){
        sum1+=i;
    }
    ll sum2=0;
    for(ll i=1;i<=k;i++){
        for(ll j=1;j<=k;j++){
            if(i==j)continue;
            sum2+=gcd(i,j);
        }
    }
    sum2*=3;
    ll sum3=0;
    for(ll i=1;i<=k;i++){
        for(ll j=1;j<=k;j++){
            if(i==j)continue;
            for(ll l=1;l<=k;l++){
                if(i==l || j==l)continue;
                sum3+=gcd(i,gcd(j,l));
            }
        }
    }
    cout<<sum1+sum2+sum3<<endl;
}


Measured memory_bytes: 3636
//abc043_b.cpp
//Sun Oct 21 10:27:30 2018

#include <iostream>
#include <string>
#include <queue>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <stack>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

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

	stack<char> ss;
	for (int i=0;i<s.size();i++){
		if (s[i] == '0' || s[i] == '1'){
			ss.push(s[i]);
		}else if (ss.size() != 0) {
			ss.pop();
		}
	}

	char ans[ss.size()];
	for (int i=ss.size()-1;i>=0;i--){
		ans[i] = ss.top();
		ss.pop();
	}

	for (int i=0;i<sizeof(ans);i++){
		cout << ans[i];
	}
	printf("\n");
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (in i = 0; i < (in)(n); i++)
#define REP(i,a,b) for(in i=(in)(a);i<(in)(b);i++)
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1e18+7;
const in inf=1e9+7;
using P=pair<in,in>;
vector<in> dx={0,1,-1,0};
vector<in> dy={1,0,0,-1};



int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cout << fixed << setprecision(10);
    in n,m;
    cin>>n>>m;
    priority_queue<in> que;
    in x;
    rep(i,n){
        cin>>x;
        que.emplace(x);
    }
    rep(i,m){
        x=que.top();
        que.pop();
        x /=2;
        que.emplace(x);
    }
    in ans=0;
    rep(I,n){
        ans +=que.top();
        que.pop();
    }
    cout<<ans<<endl;
}/*
./problem.exe
*/

Measured memory_bytes: 1400
#include<bits/stdc++.h>
using namespace std;
#define v_int vector<int> 

const int NO_OF_TYPES = 3;
//marking choices here so that its easy to understand
// 0 means swim today
// 1 means catch today
// 2 means doHW today

signed main()
{
    int n;
    cin>>n; // no of days

    v_int swimH(n+1);
    v_int catchH(n+1);
    v_int dohwH(n+1);

    for(int i=1; i<=n; i++)
    {
        scanf("%d%d%d", &swimH[i], &catchH[i], &dohwH[i]);
    }

    //we want to calculate maxm happiness 
    vector<v_int> maxm_happiness( n+1, v_int(NO_OF_TYPES, 0) ); //n+1 * 3 size initialized with 0

    for(int i=1; i<=n; i++)
    {
        //if on ith day I chose swimming
        maxm_happiness[i][0] = swimH[i] + max( maxm_happiness[i-1][1] , maxm_happiness[i-1][2] );

        //if on the ith day I chose catching
        maxm_happiness[i][1] = catchH[i] + max( maxm_happiness[i-1][0] , maxm_happiness[i-1][2] );

        //if on the ith day I chose to do HW
        maxm_happiness[i][2] = dohwH[i] + max( maxm_happiness[i-1][0] , maxm_happiness[i-1][1] );

    }

    //ans will max value of maxm_happiness[n][k] where k =0, 1, 2 i.e. last day of any of three choices
    int ans = max({ maxm_happiness[n][0], maxm_happiness[n][1], maxm_happiness[n][2] });

    cout<<ans;



    return 0;
}

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

int main()
{
    ll n, a, b; cin >> n >> a >> b;

    ll quo = n / (a + b);
    ll mod = n % (a + b);

    ll ans = 0;

    ans += quo * a;

    if (a < mod) ans += a;
    else ans += mod;
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
  int i, n = 0, c = 0;
  char number[1001];
  while(1){
    scanf("%s", number);
    if(number[0]-'0' == 0)break;

    while(1){
      if(number[c] == '\0')break;
      c++;
    }
    for(i = 0; number[i] != '\0'; i++){
      n += (number[i] - '0');
    }
    printf("%d\n",n);
    n = 0;
    c = 0;
  }
  return 0;
}

Measured memory_bytes: 536
#include<bits/stdc++.h>
#define maxn 10000
using namespace std;
int n,cnt=0;
string s[maxn];
vector<string> v;
int a=0,b=0,c=0;
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>s[i];
		for(int j=0;j<=s[i].size()-2;j++)
			if(s[i].substr(j,2)=="AB")
				++cnt;
		string t="";
		if(s[i][0]=='B'&&s[i][s[i].size()-1]=='A')
			c++;
		else if(s[i][0]=='B')
			a++;
		else if(s[i][s[i].size()-1]=='A')
			b++;
	}
	cnt+=min(a,b);
	cnt+=c;
	if(a==0&&b==0&&c!=0)
		--cnt;
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 768
K,T = map(int ,raw_input().split(" "))
A = map(int,raw_input().split(" "))

a = max(A)
b = K
if K%2 == 1:
    b+=1

if (b/2 >= a):
    print 0
else:
    c = K-a
    
    z = a - c - 1
    print z



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

using namespace std;
using ll = long long;

int main() {
    int N = 0;
    cin >> N;
    int ans = 0;
    map<pair<int, int>, bool> r;
    for(int i = 0; i < N; i++) {
        //cout << i << endl;
        int a, b;
        cin >> a;
        b = i + 1;
        pair<int, int> p = make_pair(min(a, b), max(a, b));
        //cout << "##" << endl;
        if(r.count(p)) {
            ans++;
            r.erase(p);
        } else {
            r[p] = 1;
        }
    }
    cout << ans << endl;

    return 0;
}

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

int main(void)
{
    int a;
    int b ;
    int c ;
    scanf("%d" "%d" "%d", &a, &b, &c);

    if(a == b){
        printf("%d\n",c);
    }else if (a == c){
        printf("%d\n",b);
    }else if(b == c){
        printf("%d\n",a);
    }

   return 0;
}

Measured memory_bytes: 128
n,a,b = map(int,input().split())
lim = 10**9+7
def combination(n, r, mod=10**9+7):
    r = min(r, n-r)
    res = 1
    for i in range(r):
        res = res * (n - i) * pow(i+1, mod-2, mod) % mod
    return res

print((pow(2,n,lim)-combination(n,a)-combination(n,b)-1) % lim)


Measured memory_bytes: 40556
/**
*   @Author : MeGaCrazy
*   @InitTime : Thu Jul 18 03:14:33 2019
*   @Idea :
*
*
*
*
*
*  Happy Solving :)
**/
#include <bits/stdc++.h>
using namespace std;
int main(){
#ifndef ONLINE_JUDGE
   //freopen("in","r",stdin);
   //freopen("out","w",stdout);
#endif
    int n;

    cin>>n;


    vector<long long>a(n);
    for(int i=0;i<n;i++){
    	cin>>a[i];
    	  //  cerr<<"we"<<endl;
	a[i]=(a[i]-(i+1));
	  //  	    cerr<<"wo"<<endl;
    }
    sort(a.begin(),a.end());
    long long sum=0;
    for(int i=0;i<n;i++){
       sum+=abs(a[i]-a[n/2]);
    }
    long long rsum=0;
    for(int i=0;i<n;i++){
      rsum+=abs(a[i]-a[n/2 -1]);
    }
    cout<<min(sum,rsum)<<endl;
   	







}

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

bool match(string s,string t){
  int n=s.size();
  bool f=1;
  rep(i,n){
    if(s[i]!='?'&&s[i]!=t[i]) f=0;
  }
  return f;
}

string conv(string t){
  int n=t.size();
  rep(i,n){
    if(t[i]=='?') t[i]='a';
  }
  return t;
}

int main(){
  vector<string> ans(0);
  string s,t; cin >> s >> t;
  int sn=s.size();
  int tn=t.size();
  rep(i,sn-tn+1){
    string u;
    rep(j,i) u+=s[j];
    u+=t;
    for(int j=i+tn;j<sn;j++){
      u+=s[j];
    }
    if(match(s,u)){
      ans.push_back(conv(u));
    }
  }
  sort(all(ans));
  if(ans.size()==0) ans.push_back("UNRESTORABLE");
  cout << ans[0] << endl;
  
}

Measured memory_bytes: 256
#include <iostream>

int main()
{
    std::string s;
    std::string t;

    std::cin >> s;
    std::cin >> t;

int count = 0;
    for(int i = 0; i < int(s.size());++i)
    if(s[i] != t[i])
    ++count;

    std::cout << count << std::endl;

    return 0;
}

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

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

from collections import Counter
count_dict = Counter(A)

check = 0

for i, v in count_dict.items():
    if v >= 3 and v % 2 == 0:
        count_dict[i] = 2
    elif v >= 3 and v % 2 == 1:
        count_dict[i] = 1
    
    if count_dict[i] == 2:
        check += 1
        
if check % 2 == 0:
    print(len(count_dict))
else:
    print(len(count_dict) - 1)

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

int main() {
  int n;
  cin >> n;
  
  vector<int> height(n);
  for(int i=n-1; i>=0; i--) {
    cin >> height[i];
  }
  
  bool judge = true;
  for (int i=0; i<n; i++) {
    if (i == 0) {
      continue;
    }
    if (height[i] > height[i-1] + 1) {
      judge = false;
      break;
    }
    else if (height[i] == height[i-1] + 1) {
      height[i]--;
    }
  }
  
  cout << (judge ? "Yes" : "No") << endl;
}

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

typedef long long i64;

const int N = 1 << 18;

int n, L, v[N], w[N], lim;
vector<int> vec;
vector<pair<int, i64>> _opt[N];
vector<pair<int, i64>> all;
vector<pair<int, i64>> opt;
i64 ans;

void dfs(int i, int noww, i64 nowv) {
  if (i == lim) {
    all.emplace_back(noww, nowv);
    return;
  }
  dfs(i + 1, noww, nowv);
  dfs(i + 1, noww + w[vec[i]], nowv + v[vec[i]]);
}
void dfs2(int i, int noww, i64 nowv) {
  if (noww > L) return;
  if (i == vec.size()) {
    auto it = upper_bound(opt.begin(), opt.end(),
      make_pair(L - noww, (i64)1e18));
    if (it != opt.begin()) {
      --it;
      ans = max(ans, it->second + nowv);
    }
    return;
  }
  dfs2(i + 1, noww, nowv);
  dfs2(i + 1, noww + w[vec[i]], nowv + v[vec[i]]);
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n;
  for (int i = 1; i <= n; ++i)
    cin >> v[i] >> w[i];
  int q;
  cin >> q;
  for (int v; q--;) {
    cin >> v >> L;
    vec.clear();
    for (int i = v; i; i >>= 1)
      vec.push_back(i);
    reverse(vec.begin(), vec.end());
    lim = min<int>(11, vec.size());
    if (!_opt[vec[lim - 1]].empty())
      opt = _opt[vec[lim - 1]];
    else {
      all.clear();
      dfs(0, 0, 0);
      sort(all.begin(), all.end());
      opt.clear();
      for (int i = all.size() - 1; i >= 0; --i) {
        while (!opt.empty() && opt.back().second <= all[i].second)
          opt.pop_back();
        opt.push_back(all[i]);
      }
      reverse(opt.begin(), opt.end());
      _opt[vec[lim - 1]] = opt;
    }
    ans = 0;
    dfs2(lim, 0, 0);
    cout << ans << '\n';
  }
}


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

long long ans;
int n;

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin>>n;
    for(int i=1;i<=n;i++){
        for(int j=i;j<=n;j+=i){
            ans+=j;
        }
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 3636
object Main {

  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)

    val N = sc.nextInt()
    val result = for {
      a <- (1 to 9)
      b <- (1 to 9)
      if a * b == N
    } yield ()
    
    if (result.nonEmpty) println("Yes")
    else println("No")
  }

}

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

int main() {
	int H, W;
	cin >> H >> W;
	char S[H + 2][W + 2];

	for (int i = 0; i < H + 2; i++) {
		for (int j = 0; j < W + 2; j++) {
			S[i][j] = char('#');
		}
	}

	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			cin >> S[i + 1][j + 1];
		}
	}

	for (int i = 0; i < H + 2; i++) {
		for (int j = 0; j < W + 2; j++) {
			cout << S[i][j];
		}
		cout << endl;
	}
}

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

int main() {
  string s;
  cin >> s;
  if(s[5] == '0') {
    if(s[6] == '1' || s[6] == '2' || s[6] == '3' || s[6] == '4')
      cout << "Heisei" << endl;
    else
      cout << "TBD" << endl;
  }
  else
    cout << "TBD" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define ll long long
#define ull unsigned long long
#define sii set <ll>
#define vi vector <ll>
#define popcount(x) __builtin_popcountll(x)
#define mii map <ll,ll>
#define vpi vector <pair <ll,ll> >
#define sz(c) (int)c.size()
#define fr first
#define ll long long
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define sc second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define mem0(a) memset(a,0,sizeof(a))
#define rep(i,a,n) for(ll i=a ; i<n ; i++)
#define ld long double
#define rall(a) (a).rbegin(),(a).rend()
#define INF 1000000000
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
 
 
 
ll power(ll b,ll e,ll m)
{
  if(b==0) return 0;
  if(e==0) return 1;
  if(e&1) return b*power(b*b%m,e/2,m)%m;
  return power(b*b%m,e/2,m);
}
ll power( ll b, ll e)
{
  if(b==0) return 0;
  if(e==0) return 1;
  if(e&1) return b*power(b*b,e/2);
  return power(b*b,e/2);
}  
bool isPowerOfTwo(ll x)
{
    // x will check if x == 0 and !(x & (x - 1)) will check if x is a power of 2 or not
    return (x && !(x & (x - 1)));
}


void solve()
{
	string s;
	string ans;
	cin>>s;
	rep(i,0,s.size())
	{
		if(s[i]=='0')
			ans+='0';
		else if(s[i]=='1')
			ans+='1';
		else
		{
			if(ans.size()) ans.erase(ans.begin()+ans.size()-1);
		}
	}
	cout<<ans;
}


int main()
{
	// freopen("input.txt","r",stdin);
	// freopen("output.txt","w",stdout);
  fastio
  int tt=1;
  // cin>>tt;
  while(tt--)
  {
    solve();
    cout<<"\n";
  }
  return 0;
}

Measured memory_bytes: 3588
use proconio::input;

fn main() {
    input! {
        n: usize,
        a: [usize; n]
    }

    solve(n, &a);
}

fn solve(n: usize, a: &[usize]) {
    for i in 0..n {
        if a[i] % 2 == 1 {
            continue;
        }
        if a[i] % 3 == 0 {
            continue;
        }
        if a[i] % 5 == 0 {
            continue;
        }

        println!("DENIED");
        return;
    }

    println!("APPROVED");
}


Measured memory_bytes: 2116
# include <bits/stdc++.h>
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define range_for(i, b, e) for(int i=(b), i##_len=(e); i<=i##_len; ++i)
# define ALL(x) (x).begin(), (x).end()
# define RALL(x) (x).rbegin(), (x).rend()
# define pb push_back
# define len(x) ((int)(x).size())
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
# define debug(x) std::cerr<<#x<<": "<<(x)<<endl;
# define cauto const auto
using namespace std;
using lint = long long;
template <class Type> inline constexpr bool InRange(const Type& x, const Type& i, const Type& a) { return (i <= x) && (x <= a); }
template<class Integer>bool chmax(Integer &a, const Integer &b) { if (a<b) { a=b; return 1; } return 0; }
template<class Integer>bool chmin(Integer &a, const Integer &b) { if (b<a) { a=b; return 1; } return 0; }
template<class Integer>bool IsOdd(Integer &n) { return n & 1; }
template<class Integer>bool IsEven(Integer &n) { return !(n & 1); }
int ctoi(const char c) { return ('0' <= c && c <= '9') ? (c - '0') : -1; }
string YesNo(bool b) { return b ? "Yes" : "No"; }
string YESNO(bool b) { return b ? "YES" : "NO"; }
string yesno(bool b) { return b ? "yes" : "no"; }
static const lint MOD9 = (lint)1e9+7;
int dy[4] = {0, 1, 0, -1};
int dx[4] = {1, 0, -1, 0};

// 整数の桁数を返す ( log(N) )
template <class Integer> Integer GetDigit(Integer n) {
    Integer d = 0;
    while (n) {
        n /= 10;
        d++;
    }
    return d;
}

// 素数かどうかを返す ( O(sqrt(N)) )
template <class Integer>
constexpr bool IsPrime(const Integer n) noexcept {
    if (n < 4) return n == 2 || n == 3;
    if (n % 2 == 0 || n % 3 == 0 || (n % 6 != 1 && n % 6 != 5)) return false;
    for (Integer i = 5; i * i <= n; i += 6) if (n % i == 0 || n % (i + 2) == 0) return false;
    return true;
}


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

    int cnt = 0;
    while (N != 0)
    {
        N /= K;
        cnt++;
    }

    cout << cnt << "\n";

    return 0;
}



Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<iostream>
#include<cstring>
#include<memory.h>
#include<map>
#include<set>
#include<queue>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
string S;
int main()
{
	int N,r=0,b=0;
	cin>>N;
	cin>>S;
	rep(i,0,N-1)
	{
		if(S[i]=='R')r++;else b++;
	}
	puts(r>b?"Yes":"No");
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#define ll long long
#define INF 0x3f3f3f3f
#define SIS std::ios::sync_with_stdio(false)
using namespace std;

int main()
{
    ll h,w;
    while(cin>>h>>w)
    {
        ll first,second,ans;
        if(w%2==0)
            first=w/2,second=first;
        else
            first=w/2+1,second=first-1;
        if(h%2==0)
            ans=(h/2)*(first+second);
        else
            ans=(h/2)*(first+second)+first;
        if(h==1||w==1)
            ans=1;
        cout<<ans<<endl;
    }
    return 0;
}


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

#define showoff     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb          push_back
#define pii         pair<long long,long long>
#define FOR(i,a,b)  for(long long i=a;i<b;++i)
#define RFOR(i,a,b) for(long long i=a;i>b;--i)
#define f           first
// #define se          second
#define maxn        400005
#define all(v)      v.begin(),v.end()
#define sz(x)       (long long)x.size()
//#define mod         1000000007
#define pqueue      priority_queue<long long>
#define pdqueue     priority_queue< long long,vector<long long> ,greater< long long >>
 
typedef long long ll;
 
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//const long long md = 998244353;
 
/*const long long mod = 998244353;
long long power(long long a,long long n)
{
	if(n == 1)return a%mod;
	if(n == 0)return 1;
	if(n&1)return ((a%mod)*(power((a*a)%mod,n/2))%mod)%mod;
	return power((a*a)%mod,n/2)%mod;
}
*/

int t[8];

int main()
{
	int n, a, b, c, ans = INT_MAX;
	cin >> n >> a >> b >> c;

	FOR (i,0,n)
		cin >> t[i];

	// construct dp
	int l = pow(4, n);
	FOR (i,0,l) {
		int xx = 0;
		int m = i;
		int xa = 0, xb = 0, xc = 0;
		FOR(j,0,n) {
			switch (m & 3) {
				case 1:
					if (xa > 0)
						xx += 10;
					xa += t[j];
					break;
				case 2:
					if (xb > 0)
						xx += 10;
					xb += t[j];
					break;
				case 3:
					if (xc > 0)
						xx += 10;
					xc += t[j];
					break;
			}
			m >>= 2;
		}

		if ((xa==0)||(xb==0)||(xc==0))
			continue;

		xx += abs(a - xa)+abs(b-xb)+abs(c-xc);
		ans = min(ans, xx);
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef unsigned long long ull;
typedef long double ld;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define PI 3.14159265
const int MOD=1e9+7;
 
 
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a)  (a).begin(),(a).end()

const int N=305;
double dp[N][N][N];
double p[N];
int n;
int sum=0;
double go(int cnt1,int cnt2,int cnt3)
{
    if(cnt1 <0 || cnt2<0 || cnt3<0)
    {
        return 0;
    }
    if(cnt1 ==0 && cnt2==0 && cnt3==0)
        return 0;
    double &ans=dp[cnt1][cnt2][cnt3];
    if(ans!=-1)
        return ans;
    ans=n+cnt1*go(cnt1-1,cnt2,cnt3)+cnt2*go(cnt1+1,cnt2-1,cnt3)+cnt3*go(cnt1,cnt2+1,cnt3-1);
    ans/=(cnt1+cnt2+cnt3);
    return ans;


}

int32_t main()
{
    IOS;
    cin>>n;
    map<int,int>m;
    for(int i=1;i<=n;i++)
    {
        cin>>p[i];
        m[p[i]]++;
    }
    for(int i=0;i<=n;i++)
    {
        for(int j=0;j<=n;j++)
        {
            for(int k=0;k<=n;k++)
                dp[i][j][k]=-1.0;
        }
    }
    cout<<fixed<<setprecision(12)<<go(m[1],m[2],m[3])<<endl;
    
}

Measured memory_bytes: 219392
#include <bits/stdc++.h>
//#define int long long

using namespace std;
//const int MN = 1e5+7;
const int MN = 3e3+7;
const int INF = 1e15+7;

//int n, m, x[MN], y[MN], dp[MN];
int dp[MN][MN], par[MN][MN];
string s, t;

signed main()
{
    string s, t;
    cin >> s >> t;
    dp[0][0] = s[0] == t[0];
    if(dp[0][0])par[0][0] = 1;
    for(int i = 1; i < s.size(); i++){
        dp[i][0] = (dp[i-1][0] || s[i] == t[0]);
        if(s[i] == t[0]){
            par[i][0] = 1;
        }
        if(dp[i-1][0]){
            par[i][0] = 2;
        }
    }
    for(int i = 1; i < t.size(); i++){
        dp[0][i] = (dp[0][i-1] || s[0] == t[i]);
        if(s[0] == t[i]){
            par[0][i] = 1;
        }
        if(dp[0][i-1]){
            par[0][i] = 3;
        }
    }
    for(int i = 1; i < s.size(); i++){
        for(int j = 1; j < t.size(); j++){
            if(s[i] == t[j]){
                dp[i][j] = dp[i-1][j-1]+1;
                par[i][j] = 1;
                continue;
            }
            if(dp[i-1][j] > dp[i][j-1]){
                dp[i][j] = dp[i-1][j];
                par[i][j] = 2;
            }
            else{
                dp[i][j] = dp[i][j-1];
                par[i][j] = 3;
            }
        }
    }
    int po = s.size()-1, qo = t.size()-1;
    string ans;
    while(po != -1 && qo != -1){
        if(par[po][qo] == 1){
            ans.push_back(s[po]);
            po--;qo--;
            continue;
        }
        if(par[po][qo] == 2){
            po--;
        }
        else{
            qo--;
        }
    }
    string rs;
    for(int i = ans.size()-1; i >= 0; i--){
        rs.push_back(ans[i]);
    }
    cout << rs;
    /*
    cin >> n >> m;
    for(int i = 0; i < m; i++){
        cin >> x[i] >> y[i];
        x[i]--;
        y[i]--;
    }
    for(int i = 0; i < m; i++){
        dp[y[i]] = max(dp[y[i]], dp[x[i]] + 1);
        //cout << y[i] << ":";
        //cout << dp[y[i]] << ' ';
    }
    int ans = 0;
    for(int i = 0; i < n; i++){
        ans = max(ans, dp[i]);
    }
    cout << ans;
    */
}


Measured memory_bytes: 70784
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>
 
using namespace std;
int main(){
int a,b,c,d;
cin>>a>>b>>c>>d;
if(abs(a-c)<=d||(abs(a-b)<=d&&abs(b-c)<=d))cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#define print(n) std::cout << n << std::endl
#define FOR(i,n) for(int i = 0; i < n; i++)
using namespace std;

int main() {
    string a,b,c;
    cin >> a >> b >> c;
 
    if((a.substr(a.size() - 1,1) == b.substr(0,1)) && (b.substr(b.size() - 1,1) == c.substr(0,1)))print("YES");
    else print("NO");


}

Measured memory_bytes: 256
#「探索候補スタック」「探索済みリスト」「現在地点」の３点セットでとらえる
n,q=map(int,input().split())
mat=[set() for _ in range(n)]
for _ in range(n-1):
    a,b=map(int,input().split())
    mat[a-1].add(b-1)
    mat[b-1].add(a-1) # プラスした要素
count=[0]*n
for _ in range(q):
    p,score=map(int,input().split())
    count[p-1]+=score

stack=[[0,0,-1]]
while stack:
    # print(stack)
    num,cnt,pr=stack.pop()
    count[num]+=cnt
    for k in mat[num]:
        if k==pr:
            continue
        stack.append([k,count[num],num])
print(*count)

Measured memory_bytes: 191700
#include <iostream>
    #include <iomanip>
    #include <string>
    #include <vector>
    #include <deque>
    #include <queue>
    #include <map>
    #include <set>
    #include <algorithm>
    #include <climits>
    #include <cmath>
     
    using namespace std;
    using Pos = std::pair<int, int>;
    //cout<<fixed<<std:cout<<fixed<<setprecision(2)<<Max<<endl;
    constexpr int mod = 1e9 + 7;
     
    int N;
    string str;
    vector<bool> a;//sheep->0, wolf->1
     
    bool check(){
        //fill
        if(str[0]=='x'){
            a[1]=a[0]?a[N-1]:!a[N-1];
        }else{
            a[1]=a[0]?!a[N-1]:a[N-1];
        }
        for(int i=2;i<N-1;++i){
            if(str[i-1]=='x'){
                a[i]=a[i-1]?a[i-2]:!a[i-2];
            }else{
                a[i]=a[i-1]?!a[i-2]:a[i-2];
            }
        }
     
        //check
        if(a[N-2]){
            if(str[N-2]=='x'){
                if(a[N-1]!=a[N-3])return false;
            }else{
                if(a[N-1]==a[N-3])return false;
            }
        }else{
            if(str[N-2]=='x'){
                if(a[N-1]==a[N-3])return false;
            }else{
                if(a[N-1]!=a[N-3])return false;
            }
        }
     
        if(a[N-1]){
            if(str[N-1]=='x'){
                if(a[0]!=a[N-2])return false;
            }else{
                if(a[0]==a[N-2])return false;
            }
        }else{
            if(str[N-1]=='x'){
                if(a[0]==a[N-2])return false;
            }else{
                if(a[0]!=a[N-2])return false;
            }
        }
        return true;
    }
     
    int main() {
        cin>>N>>str;
        a.resize(N);
     
        a[0]=0;
        a[N-1]=0;
        if(check()){
            for(const auto& val:a){
                if(val)cout<<'W';
                else cout<<'S';
            }
            cout<<endl;
            return 0;
        }
        a[0]=0;
        a[N-1]=1;
        if(check()){
            for(const auto& val:a){
                if(val)cout<<'W';
                else cout<<'S';
            }
            cout<<endl;
            return 0;
        }
        a[0]=1;
        a[N-1]=0;
        if(check()){
            for(const auto& val:a){
                if(val)cout<<'W';
                else cout<<'S';
            }
            cout<<endl;
            return 0;
        }
        a[0]=1;
        a[N-1]=1;
        if(check()){
            for(const auto& val:a){
                if(val)cout<<'W';
                else cout<<'S';
            }
            cout<<endl;
            return 0;
        }
        cout<<-1<<endl;
     
        return 0;
    }

Measured memory_bytes: 512
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Numerics;
using System.Text;
using static System.Math;

class Node
{
    public List<int> children;
    public int Value;

    public Node()
    {
        children = new List<int>();
    }
}

class Graph
{
    public int n;
    public Node[] node;
    public bool[] isVisited;
    public int[] c;
    public int index = 0;

    public Graph(int n)
    {
        this.n = n;
        node = new Node[n];
        isVisited = new bool[n];
        for (int i = 0;i < n; i++)
            node[i] = new Node();
        c = new int[n];
    }

    public void SetEdge(int a,int b)
    {
        node[a - 1].children.Add(b - 1);
        node[b - 1].children.Add(a - 1);
    }

    public void DFS(int v)
    {
        isVisited[v] = true;
        foreach (var i in node[v].children)
        {
            if (!isVisited[i]) DFS(i);
        }
        node[v].Value = c[index];
        index++;
    }

    public void Solve()
    {
        Array.Sort(c);
        DFS(0);
        Console.WriteLine(c.Sum() - c[n - 1]);
        for (int i = 0;i < n - 1; i++)
            Console.Write("{0} ",node[i].Value);
        Console.WriteLine(node[n - 1].Value);
    }
}

class Program
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        Graph g = new Graph(n);
        for (int i = 0;i < n - 1; i++)
        {
            int[] ab = Console.ReadLine().Split().Select(int.Parse).ToArray();
            g.SetEdge(ab[0],ab[1]);
        }
        g.c = Console.ReadLine().Split().Select(int.Parse).ToArray();
        g.Solve();
    }
}

Measured memory_bytes: 21564
#include <stdio.h>

int main()
{
	int array[3] = { 0 }, a = 0,i,j;
	for (int l = 0; l < 3; l++)
	{
		scanf("%d",&array[l]);
	}
	for (i = 0; i < 2; i++)
	{
		for (j = 2; j > i; j--)
		{
			if (array[i] > array[j])
			{
				a=array[j];
				array[j] = array[i];
				array[i] = a;
			}
		}
	}
	for (int l = 1,i=0; l < 6,i<3; l++)
	{
		if (l % 2 == 0)
			printf(" ");
		else
		{
			printf("%d", array[i]);
			i++;
		}
	}
	printf("\n");
}


Measured memory_bytes: 2072
#define  _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
#pragma comment (linker, "/STACK:526000000")

using namespace std;
typedef string::const_iterator State;
#define eps 1e-11L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL

#define MOD 998244353LL
#define seg_size 262144*2LL
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()

unsigned long xor128() {
	static unsigned long x = 123456789, y = 362436069, z = 521288629, w = time(NULL);
	unsigned long t = (x ^ (x << 11));
	x = y; y = z; z = w;
	return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}

void init() {
	iostream::sync_with_stdio(false);
	cout << fixed << setprecision(10);
}

#define int ll
void solve() {
	while (true) {
		int d;
		long double e;
		cin >> d >> e;
		if (d == 0) return;
		long double ans = 1e9;
		for (int x = 0; x <= d; ++x) {
			long double now = pow(x, 2) + pow(d - x, 2);
			now = sqrt(now);
			ans = min(ans, abs(now - e));
		}
		cout << ans << endl;
	}
}
#undef int

int main() {
	init();
	solve();
}


Measured memory_bytes: 3260
slist=list(input())
tlist=list(input())
s=len(slist)
t=len(tlist)
kazu=s-t+1
ans=10000000000

for i in range(kazu):
    kari=[]
    an=0
    for j in range(i,i+t):
        kari.append(slist[j])
    for k in range(t):
        if tlist[k]!=kari[k]:
            an+=1
    if ans>an:
        ans=an

print(ans)

Measured memory_bytes: 9076
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>

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

int n,m,q;
vector<int> a,b,c,d;
int ans;

void dfs(vector<int> A){
    if(A.size() == n+1){
        int now = 0;
        
        rep(i,q){
            if(A[b[i]] - A[a[i]] == c[i]) now += d[i];
        }
        ans = max(ans,now);
        return ;
    }

    A.push_back(A.back());
    while(A.back() <= m){
        dfs(A);
        A.back()++;
    }
}

int main(){
    cin >> n >> m >> q;
    a = b = c = d = vector<int>(q);
    rep(i,q){
        cin >> a[i] >> b[i] >> c[i] >> d[i];
    }    
    dfs(vector<int>(1,1) );
    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 3552
//C Attack Survival
#include "bits/stdc++.h"
using namespace std;

int main()
{
  int n,k,q,a;
  cin>>n>>k>>q;
  a=k-q;
  vector<int> point(n,a);
  vector<int> correct(q);
  for(int i=0;i<q;i++)
  {
    cin>>correct.at(i);
    point.at(correct.at(i)-1)++;
  }
  for(int i=0;i<n;i++)
  {
    if(point.at(i)>0)
    {
      cout<<"Yes"<<endl;
    }
    else
    {
      cout<<"No"<<endl;
    }
  }
}


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

int main() {
  ll n, a;
  cin >> n;
  multiset<ll, greater<ll>> st;
  rep(i, n) {
    cin >> a;
    st.insert(a);
  }
  ll ans = 0;
  while(!st.empty()) {
    auto it = st.begin();
    st.erase(it);
    ll p = 2;
    while(p <= *it) {
      p *= 2;
    }
    auto jt = st.find(p - *it);
    if(jt == st.end()) continue;
    st.erase(jt);
    ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 9600
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;


int main(void){
  int a,b,c;
  
  cin >> a >> b >> c;
  
  if ((c-a)*(c-b)<0) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}

Measured memory_bytes: 256
<?php

fscanf(STDIN, "%d %d", $n, $k);
$hs = explode(' ', trim(fgets(STDIN)));

arsort($hs);
if (count($hs) <= $k) {
  echo 0;
} else {
  array_splice($hs, 0, $k);
  echo array_sum($hs);
}


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

int l[6];

struct dice {

    void in() {
        for(int i = 0; i < 6; i++) cin >> l[i];
    }
    
    void roll(char c) {
        if(c == 'N') {
            char tmp;
            tmp = l[0];
            l[0] = l[1];
            l[1] = l[5];
            l[5] = l[4];
            l[4] = tmp;
        }
        else if(c == 'E') {
            char tmp;
            tmp = l[0];
            l[0] = l[3];
            l[3] = l[5];
            l[5] = l[2];
            l[2] = tmp;
        }
        else if(c == 'W') {
            char tmp;
            tmp = l[0];
            l[0] = l[2];
            l[2] = l[5];
            l[5] = l[3];
            l[3] = tmp;
        }
        else if(c == 'S') {
            char tmp;
            tmp = l[0];
            l[0] = l[4];
            l[4] = l[5];
            l[5] = l[1];
            l[1] = tmp;
        }
        else if(c == 'R') {
            char tmp;
            tmp = l[1];
            l[1] = l[3];
            l[3] = l[4];
            l[4] = l[2];
            l[2] = tmp;
        }
        else if(c == 'L') {
            char tmp;
            tmp = l[1];
            l[1] = l[2];
            l[2] = l[4];
            l[4] = l[3];
            l[3] = tmp;
        }
    }

    void rot(int a, int b) {
      	int i;
      
        for(i = 0; i < 6; i++) if(l[i] == a) break;
        if(i==1) roll('N');
        else if(i==2) roll('W');
        else if(i==3) roll('E');
        else if(i==4) roll('S');
        else if(i==5) roll('N'),roll('N');

        for(i = 1; i < 5; i++) if(l[i] == b) break;
        if(i==2) roll('L');
        else if(i==3) roll('R');
        else if(i==4) roll('R'), roll('R');
    }
};

int main() {
    //サイコロ作成
    dice d;  d.in();

    //回数
    int q;  cin >> q;

    for(int i  = 0; i < q; i++) {

        int up, front;  cin >> up >> front;

        d.rot(up, front);
        
        cout << l[2] << endl;
    }
}



Measured memory_bytes: 3096
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <queue>

using namespace std;

struct p {
	char name[11];
	int time;
	int num;
};

int n;
int q;
queue<p> P;
p que[100000];

void solve()
{
	int now = 0;
	while (P.size()) {
		p tmp = P.front(); P.pop();
		if (tmp.time <= q) {
			now += tmp.time;
			cout << tmp.name << " " << now << endl;
		} else {
			now += q;
			que[tmp.num].time -= q;
			P.push(que[tmp.num]);
		}
	}
}

int main()
{
	cin >> n >> q;
	for (int i = 0; i < n; i++) {
		cin >> que[i].name >> que[i].time;
		que[i].num = i;
		P.push(que[i]);
	}
	solve();
	return 0;
}


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

using namespace std;

using ll=long long ;
// when range [l, r), has property notP~P, want first P.
// when return r, means not found.
template <typename T>
T bs_first(T l, T r, function<bool (T)> f) {
    assert(l < r);
    T mid;
    while (l != r) {
        mid = l + (r-l)/2;
        if (f(mid)) {
            r = mid;
        }else {
            l = mid + 1;
        }
    }
    return r;
}
void solve() {
    auto q = [](ll x)->bool{
        cout << "? " << x << endl;
        char y; cin >> y;
        return y == 'Y';
    };
    auto p = [](ll x){
        cout << "! " << x << endl;
    };
    const int N = 1000'000'000; 
    if (q(N)) {
        int k = bs_first<int>(0, 10, [&](int k){
                return q(2*pow(10,k));
                });
        p(pow(10, k));
    } else {
        int k = bs_first<int>(1, 10, [&](int k){
                return !q(pow(10,k));
                });
        int n = bs_first<int>(pow(10,k-1)+1, pow(10,k), [&](int n){
                return q(10ll*n);
                });
        p(n);
    }

}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


Measured memory_bytes: 596
from collections import defaultdict

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


dd = defaultdict(int)

for _ in range(n):
    a, b = map(int, input().split())
    dd[a] += b

cnt = 0
for key, v in sorted(dd.items()):
    cnt += v
    if k <= cnt:
        print(key)
        break


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

int main() {
  int N = 0, K = 0, sum = 0, x = 0;
  cin >> N >> K;
  
  for(int i = 0; i < N; i++){
    cin >> x;
    if( (K - x) > x){
      sum += x * 2;
    }else{
      sum += (K - x) * 2;
    }
  }
  
  cout << sum << endl;
  
}

Measured memory_bytes: 3624
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<list>

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



int main(){
  list<int> il;
  char command[20];
  int n;
  int key;
  scanf("%d",&n);
  REP(i,n){
    scanf("%s",command);
    if(command[0] == 'i'){  //insert
      scanf("%d",&key);
      il.push_front(key);
    }
    else if((command[0]=='d') && (command[6]=='F')){
      il.pop_front();
    }
    else if((command[0]=='d') && (command[6]=='L')){
      il.pop_back();
    }
    else if(command[0] == 'd'){
      scanf("%d",&key);
      for(list<int>::iterator it=il.begin();it != il.end();it++){
        if(*it == key){
          il.erase(it);
          break;
        }
      }
    }
  }
  int i = 0;
  for(list<int>::iterator it=il.begin();it != il.end();it++){
    if(i++)printf(" ");
    printf("%d",*it);
  }
  printf("\n");
  return 0;
  }

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

int main(){
  int h, w;
  cin >> h >> w;
  vector<string> a(h);
  rep(i, h){
    string str;
    cin >> str;
    a[i] = str;
  }
  
  vector<bool> row(h, false);
  vector<bool> col(w, false);
  rep(i, h){
    rep(j, w){
      if (a[i][j] == '#') row[i] = true, col[j] = true;
    }
  }
  
  rep(i, h){
    rep(j, w){
      if (row[i] && col[j]) cout << a[i][j];
    }
    if (row[i]) cout << endl;
  }
      
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int a = sc.nextInt();
		int b = sc.nextInt();
		
		if (a*b%2==1) {
			System.out.println("Odd");
		} else {
			System.out.println("Even");
		}
		
	}
}

Measured memory_bytes: 21844
import java.util.Scanner;

class Main {
    public static void main(final String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        
        if (s.equals("ABC")) {
            System.out.println("ARC");
        } else {
            System.out.println("ABC");
        }
    }
}


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

using namespace std;
typedef long long int ll;

#define PI (acos(-1))
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

int main(void){
    int n; cin>>n;
    vector <int> v;
    int w;
    ll sum_w = 0;
    REP(i, n){
        cin >> w;
        sum_w += w;
        v.push_back(w);
    }
    ll ans = 1e7;
    ll tmp_sum_w = 0;
    REP(i, n){
        tmp_sum_w += v[i];
        ans = min(ans, llabs(2*tmp_sum_w-sum_w));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <ext/pb_ds/assoc_container.hpp> 	// Common file
#include <ext/pb_ds/tree_policy.hpp> 		// Including tree_order_statistics_node_update
#include<bits/stdc++.h>
#define int            		long long
#define x              		first
#define y              		second
#define all(aaa)       		(aaa).begin(),(aaa).end()
#define REP(i,sss,eee) 		for(int i=sss;i<=eee;++i)
#define pb             		push_back
#define pii            		pair<int,int>
#define vi             		vector<int>
#define speed          		ios_base::sync_with_stdio(0);cin.tie(0);
#define N              		1000000007
using namespace __gnu_pbds;
using namespace std;
template <class T>
T MAX(T a, T b){return ((a>b)?a:b);}
template <class T>
T MIN(T a, T b){return ((a<b)?a:b);}
template <class T>
T MOD(T a){return ((a>=0)?a:(-1*a));}
template <class T>
void SWAP(T &a,T &b){T temp=a;a=b;b=temp;}

typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;

long long ex(long long a, long long b){
	if(b==0||a==1){return 1;}
	if(a==0||b==1){return a;}
	long long tmp=ex(a,(b/2));
	if(b%2){return ((((tmp*tmp)%N)*a)%N);}
	else{return ((tmp*tmp)%N);}
}
long long inv(long long k){
	if(k==1){return 1;}
	else{return ex(k,N-2);}
}
/*****************default********************/
int solve()
{
	int A,B,Q;cin>>A>>B>>Q;
	vi s,t;
	s.pb(-1*100000000000000);t.pb(-1*100000000000000);
	REP(i,0,A-1){int tmp;cin>>tmp;s.pb(tmp);}
	REP(i,0,B-1){int tmp;cin>>tmp;t.pb(tmp);}
	s.pb(100000000000000);t.pb(100000000000000);
	REP(i,0,Q-1){
		int inp;cin>>inp;
		auto sit=lower_bound(s.begin(),s.end(),inp);
		auto tit=lower_bound(t.begin(),t.end(),inp);
		int shi=((*(sit))-inp);
		int thi=((*(tit))-inp);
		--sit;--tit;
		int slo=(inp-(*(sit)));
		int tlo=(inp-(*(tit)));
		int ans=MIN((shi+(tlo*2)),((shi*2)+tlo));
		ans=MIN(ans,MIN((thi+(slo*2)),((thi*2)+slo)));
		ans=MIN(ans,MAX(thi,shi));
		ans=MIN(ans,MAX(tlo,slo));
		cout<<ans<<"\n";
	}

}
signed main(){
	speed
	int tt=1;
	//cin>>tt;
	while(tt--)
	{
		solve();
	}
	return 0;
}

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
typedef pair<int,int> P;
int MAX=1000000007;
 
int main() {
  int n;
  while(cin >> n && n) {
    P a[n];
    for(int i=0; i<n; i++) cin >> a[i].first >> a[i].second; 
    int dp[n+1][4];
    fill(dp[0],dp[n+1],MAX);
    if(a[0].first<=a[0].second) dp[1][1]=a[0].first;
 
    int px=a[0].first,pt=a[0].second;
    for(int i=1; i<n; i++) {
      int x=a[i].first,t=a[i].second;
      int T=t-pt;
      for(int j=1; j<4; j++) {
    if(dp[i][j]==MAX) continue;
    if(px*(j+1)+x<=T) dp[i+1][1]=min(dp[i+1][1],dp[i][j]+px+x);
    if(j<3 && abs(px-x)*(j+1)<=T) dp[i+1][j+1]=min(dp[i+1][j+1],dp[i][j]+abs(px-x));
      }
      px=x;
      pt=t;
    }
 
    int ans=MAX;
    bool ck=true;
    for(int i=1; i<=n; i++) {
      bool ck2=false;
      for(int j=1; j<4; j++) {
    if(dp[i][j]!=MAX) ck2=true;
    if(i==n) ans=min(ans,dp[i][j]+px);
      }
      if(!ck2) {
    ck=false;
    ans=i;
    break;
      }
    }
    if(!ck) cout << "NG " << ans << endl;
    else cout << "OK " << ans << endl;
  }
  return 0;
}


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

int main(){
  int n,cnt=0;
  cin >> n;
  map<int,int> mp;
  for(int i=0;i<n;i++){
    int a;
    cin >> a;
    mp[a]++;
  }
  for(auto i:mp){
    if(i.second<i.first) cnt += i.second;
    else cnt += i.second-i.first;
  }
  cout << cnt << endl;
}

Measured memory_bytes: 4736
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)

	n := nextInt()
	m, s := 0, 0
	mind := -1
	for i := 0; i < n; i++ {
		a := nextInt()
		if m < a {
			s = m
			m = a
			mind = i
		} else if s < a {
			s = a
		}
	}

	for i := 0; i < n; i++ {
		if i == mind {
			fmt.Println(s)
		} else {
			fmt.Println(m)
		}
	}
}

Measured memory_bytes: 5248
(defn get_H_W []
  (->> (clojure.string/split (read-line) #"\s")
    (map #(Integer/parseInt %))))

(defn set_Array [^"[[C" Array H W]
  (dotimes [h H]
    (->> (read-line)
      (char-array W)
      (aset Array h))))

(defn Minesweeper [^"[[C" Array H W]
  (doseq [x (range W)
          y (range H)
          :let [v ^char (aget ^"[C" (aget Array y) x)]
          :when (not= \# v)]
    (->>
      (with-local-vars [counts 0]
        (doseq [d-y-x [[-1 -1] [-1 0] [-1 1] [0 -1] [0 1] [1 -1] [1 0] [1 1]]
                :let [[dy dx] (map + (list y x) d-y-x)]
                :when (and
                        (<= 0 dx)
                        (< dx W)
                        (<= 0 dy)
                        (< dy H)
                        (= \# (aget ^"[C" (aget Array dy) dx)))]
          (var-set counts (unchecked-inc-int  @counts)))
        @counts)
      (unchecked-add-int (unchecked-int \0))
      unchecked-char
      (aset ^"[C" (aget Array y) x))))

(defn output [^"[[C" Array]
  (-> (areduce Array idx ret ""
        (str ret
          (apply str (aget Array idx))
          "\n"))
    print))

(let [[H W] (get_H_W)]
  (doto (make-array Character/TYPE H W)
    (set_Array H W)
    (Minesweeper H W)
    (output)))

Measured memory_bytes: 74916
#include <bits/stdc++.h>
using namespace std;
 int main(){
     string s;cin>>s;
     int ans=0;
     for(int i=0;i<s.size()/2;i++){
         if(s[i]!=s[s.size()-i-1])ans++;
     }
     cout<<ans<<endl;
    }
        






Measured memory_bytes: 256
#include <inttypes.h>
#include <math.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void)
{
    intmax_t N, K, S;
    intmax_t A[(int)1e5] = {};

    scanf("%jd%jd%jd", &N, &K, &S);

    for (size_t i = 0; i < K; i++) {
        A[i] = S;
    }
    intmax_t padding;
    if (S == (int)1e9) {
        padding = 1;
    } else {
        padding = (int)1e9;
    }
    for (size_t i = K; i < N; i++) {
        A[i] = padding;
    }

    for (size_t i = 0; i < N; i++) {
        printf("%jd ", A[i]);
    }
    printf("\n");

    return 0;
}


Measured memory_bytes: 2048
gets
a = gets.split.map(&:to_i).sort
p = Hash.new(0)
a.each do |x|
  p[x] += 1
end
q = a[-1].next
f = [true] * q
p.each do |k, v|
  f[k] = false if v > 1
  (k + k).step(q, k) do |i|
    f[i] = false
  end
end
puts a.select{|x| f[x]}.size

Measured memory_bytes: 46124