akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

const int N = 1e5 + 10;

char in[N];

int main() {
    scanf("%s", in+1);
    int n = (int)strlen(in+1), ans = 0;
    for (int i = 2; i <= n; i++) {
        if (in[i] == in[i-1]) {
            ans++;
            in[i] = 1 - (in[i-1] - '0') + '0';
        }
    }
    printf("%d\n",ans);
    return 0;
}

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

using namespace std;

int num(int n){
    int c = 0;
    while(n){
        n /=10;
        c++;
    }
    return c;
}

string extend(int x, int y){
    int xs = num(x);
    int ys = num(y);
    string ans = "";

    for(int i = 0; i < 6 - xs ; i++){
        ans+="0";
    }
    ans+=to_string(x);

    for(int i = 0; i < 6 - ys ; i++){
        ans+="0";
    }
    ans+=to_string(y);

    return ans;

}

int main()
{
    int n,m;
    cin >> n >> m;
    vector<pair<int,int>> arr[n];

    for(int i = 0 ; i < m ; i++){
        int p,y;
        cin >> p >> y;
        p--;
        arr[p].push_back(make_pair(y,i));
    }

    for(int i = 0 ; i < n ; i++)
        sort(arr[i].begin(), arr[i].end());


    string ans[m];


    for(int i = 0 ; i < n ; i++){
        for(int j = 0 ; j < arr[i].size() ; j++){
            ans[arr[i][j].second] = extend(i+1,j+1);

        }
    }

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



}


Measured memory_bytes: 12416
#include<stdio.h>
#include<stdlib.h>

int compare(const void *a,const void *b){
	return *(int*)b-*(int*)a;
}

int main(){
	
	int N,K,l[60],i,max=0;
	
	scanf("%d%d",&N,&K);
	for(i=0;i<N;i++){
		scanf("%d",&l[i]);
	}
	
	qsort(l,N,sizeof(int),compare);
	
	
	for(i=0;i<K;i++){
		max+=l[i];
		
	}
	
	printf("\n%d\n\n",max);
	
	
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FORR(i,a,b) for (int i=(a);i>=(b);i--)
#define pb push_back
#define pcnt __builtin_popcount
#define show(x) cout<<#x<<" = "<<x<<endl;
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define fi first
#define se second
#define rng(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define sz(x) (int)(x).size()
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef set<int> si;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll;
typedef set<ll> sl;
typedef __int128_t lll;
typedef pair<lll,lll> plll;
typedef vector<lll> vlll;
template<typename T>string join(vector<T>&v)
{stringstream s;FOR(i,0,sz(v))s<<' '<<v[i];return s.str().substr(1);}
ll gcd(ll a,ll b){if(a>b)swap(a,b);for(;a>0;b%=a,swap(a,b));return b;}
int modpow(ll a,ll n,int m){if(a==0)return a;ll p=1;for(;n>0;n/=2,a=a*a%m)if(n&1)p=p*a%m;return(int)p;}
void dout(double d){printf("%.12f\n",d);}

const int iinf = 1e9;
const ll linf = 1e18;
const int mod = 1e9+7;
const double pi = acos(-1);
const double eps = 1e-10;
ll x;

main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> x;
  ll ans = x/11*2;
  x %= 11;
  if(x == 0){
  }else if(x > 6){
    ans += 2;
  }else{
    ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
result = None
N, M = [int(i) for i in input().split()]

a = [None for i in range(N)]

for i in range(M):
    s, c = [int(i) for i in input().split()]
    s = s - 1

    if a[s] is not None and c != a[s]:
        result = False
    a[s] = c

if a[0] == 0 and N >=2:
    result = False

if a[0] is None and N >= 2:
    a[0] = 1

a.reverse()

if result is None:
    result = 0
    for i, num in enumerate(a):
        if num is None:
            num = 0
        result += num * 10**i

if result is False:
    result = -1


print(result)

Measured memory_bytes: 3064
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        
        int r = sc.nextInt();
        int s = sc.nextInt();
        int p = sc.nextInt();
        
        String str = sc.next();
        char[] c = str.toCharArray();
        
        int[][] dp = new int[n+1][3];
        
        for (int i = 0; i < k; i++) {
            if (c[i] == 'r') {
                dp[i+1][2] = p;
            } else if (c[i] == 's') {
                dp[i+1][0] = r;
            } else {
                dp[i+1][1] = s;
            }
        }
        
        for (int i = k; i < n; i++) {
            dp[i+1][0] = Math.max(dp[i-k+1][1], dp[i-k+1][2]);
            dp[i+1][1] = Math.max(dp[i-k+1][2], dp[i-k+1][0]);
            dp[i+1][2] = Math.max(dp[i-k+1][0], dp[i-k+1][1]);
            
            if (c[i] == 'r') {
                dp[i+1][2] += p;
            } else if (c[i] == 's') {
                dp[i+1][0] += r;
            } else {
                dp[i+1][1] += s;
            }
        }
        
        int ans = 0;
        for (int i = n; i >= n - k + 1; i--) {
            int max = Math.max(dp[i][0], Math.max(dp[i][1], dp[i][2]));
            ans += max;
        }
        System.out.println(ans);
        // for (int[] d : dp) {
            // System.out.println(Arrays.toString(d));
        // }
    }
}


Measured memory_bytes: 43388
n,k=map(int,input().split())
mod=10**9+7
k=min(k,n-1)
ans=1
g=1
h=1
for i in range(k):
    g*=(n-i)*pow(i+1,mod-2,mod)
    g%=mod
    h*=(n-1-i)*pow(i+1,mod-2,mod)
    h%=mod
    ans+=g*h%mod
    ans%=mod
print(ans)


Measured memory_bytes: 40428
#include<iostream>
#include<vector>
#include<algorithm>
#include<tuple>
using namespace std;
class UnionFind {
private:
	unsigned size_; std::vector<unsigned> par, rank;
public:
	UnionFind() : size_(0), par(std::vector<unsigned>()), rank(std::vector<unsigned>()) {};
	UnionFind(unsigned size__) : size_(size__) {
		par.resize(size_); rank.resize(size_);
		for (unsigned i = 0; i < size_; i++) par[i] = i, rank[i] = 0;
	}
	unsigned size() { return size_; }
	unsigned root(unsigned x) { return par[x] == x ? x : par[x] = root(par[x]); }
	bool same(unsigned x, unsigned y) { return root(x) == root(y); }
	void unite(unsigned x, unsigned y) {
		x = root(x), y = root(y);
		if (x == y) return;
		if (rank[x] < rank[y]) par[x] = y;
		else if (rank[x] == rank[y]) par[y] = x, rank[x]++;
		else par[y] = x;
	}
	bool operator==(const UnionFind &u) { return par == u.par; }
	bool operator!=(const UnionFind &u) { return par != u.par; }
};
int n; long double x[200000], y[200000], R, r1 = 0.1145141919, r2 = 0.9868864999;
bool used[200000]; tuple<long double, long double, int>p[200000];
long double dst(long double px, long double py, long double qx, long double qy) {
	return sqrtl((px - qx)*(px - qx) + (py - qy)*(py - qy));
}
int main() {
	cin >> n >> R; int ans = 0;
	for (int i = 0; i < n; i++) {
		cin >> x[i] >> y[i];
		x[i] *= r2; y[i] *= r2;
		long double J1 = x[i], J2 = y[i]; J1 *= r1 / r2; J2 *= r1 / r2;
		x[i] -= J2; y[i] += J1; p[i] = make_tuple(x[i], y[i], i);
	}
	sort(p, p + n); UnionFind UF(n);
	for (int i = 0; i < n; i++) {
		if (used[i] == true)continue; ans++; used[i] = true;
		int pos1 = lower_bound(p, p + n, make_tuple(x[i] - R, y[i], i)) - p;
		int pos2 = lower_bound(p, p + n, make_tuple(x[i] + R, y[i], i)) - p;
		for (int j = pos1; j < pos2; j++) {
			if (dst(x[i], y[i], get<0>(p[j]), get<1>(p[j])) <= R*1.001l) {
				if (UF.same(i, get<2>(p[j])) == false) {
					UF.unite(i, get<2>(p[j])); used[get<2>(p[j])] = true;
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 20316
'use strict'

const main = (input) => {
    input = input.split('\n')
    const As = input[1].split(' ').map(i => parseInt(i)).sort((a, b) => b - a)
    let A = []
    let B = []
    As.forEach((v, i) => {
        if(i % 2 === 0){
            A.push(v)
        }else{
            B.push(v)
        }
    })
    console.log(A.reduce((p, c) => p + c) - B.reduce((p, c) => p + c))
}

main(require('fs').readFileSync('/dev/stdin', 'utf-8'))

Measured memory_bytes: 11596
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SORT(x) sort(all(x));
#define RSORT(x) sort(rall(x));
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vd = vector<double>;
using vb = vector<bool>;
using pii = pair<int, int>;
using vc = vector<char>;
using vvc = vector<vc>;
using vs = vector<string>;
using tiii = tuple<int, int, int>;
const int inf = 1<<29;
const ll mod = 1000000007;
const double eps = 1e-9;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//cout << fixed << setprecision(10);

bool f(int x) {
  int keta = 0;
  while (x) {
    keta++;
    x /= 10;
  }
  return keta%2 == 1;
}

int main () {
  int N; cin >> N;
  int ans = 0;
  for (int i = 1; i <= N; i++) {
    if (f(i)) ans++;
  }
  cout << ans << 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 all(v) v.begin(), v.end()
#define int long long
#define _GLIBCXX_DEBUG

signed main() {
  int N; cin >> N;
  unordered_map<string,int> S;
  rep(i, N) {
    string s; cin >> s;
    sort(all(s));
    S[s]++;
  }
  

  int ans = 0;
  for(auto p : S) {
    ans += p.second*(p.second-1)/2;
  }
  cout << ans << endl;

}

Measured memory_bytes: 10660
#include <bits/stdc++.h>
using namespace std;
#define vaibhav ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mp make_pair
#define pb push_back
#define ll long long int
#define ld long double
#define M  998244353
// freopen("user1.dat", "r", stdin);
// freopen("user1.dat", "w", stdout);



// C++ program to count number of factors 
// of an array of integers 

const int MAX = 1000001; 

// array to store prime factors 
int factor[MAX] = { 0 }; 

// function to generate all prime factors 
// of numbers from 1 to 10^6 
void generatePrimeFactors() 
{ 
	factor[1] = 1; 

	// Initializes all the positions with their value. 
	for (int i = 2; i < MAX; i++) 
		factor[i] = i; 

	// Initializes all multiples of 2 with 2 
	for (int i = 4; i < MAX; i += 2) 
		factor[i] = 2; 

	// A modified version of Sieve of Eratosthenes to 
	// store the smallest prime factor that divides 
	// every number. 
	for (int i = 3; i * i < MAX; i++) { 
		// check if it has no prime factor. 
		if (factor[i] == i) { 
			// Initializes of j starting from i*i 
			for (int j = i * i; j < MAX; j += i) { 
				// if it has no prime factor before, then 
				// stores the smallest prime divisor 
				if (factor[j] == j) 
					factor[j] = i; 
			} 
		} 
	} 
} 

// function to calculate number of factors 
int calculateNoOFactors(int n) 
{ 
	if (n == 1) 
		return 1; 

	int ans = 1; 

	// stores the smallest prime number 
	// that divides n 
	int dup = factor[n]; 

	// stores the count of number of times 
	// a prime number divides n. 
	int c = 1; 

	// reduces to the next number after prime 
	// factorization of n 
	int j = n / factor[n]; 

	// false when prime factorization is done 
	while (j != 1) { 
		// if the same prime number is dividing n, 
		// then we increase the count 
		if (factor[j] == dup) 
			c += 1; 

		/* if its a new prime factor that is factorizing n, 
		then we again set c=1 and change dup to the new 
		prime factor, and apply the formula explained 
		above. */
		else { 
			dup = factor[j]; 
			ans = ans * (c + 1); 
			c = 1; 
		} 

		// prime factorizes a number 
		j = j / factor[j]; 
	} 

	// for the last prime factor 
	ans = ans * (c + 1); 

	return ans; 
} 

// Driver program to test above function 
int main() 
{ 
	// generate prime factors of number 
	// upto 10^6 
	generatePrimeFactors(); 

	int n;
	cin>>n;
	ll ans=0;

	for(int i=1;i<n;i++)
	{
		int x=n-i;
		ans=ans+calculateNoOFactors(x);
		//cout<<ans<<endl;
	}

		cout <<ans<<"\n";

	return 0; 
} 


Measured memory_bytes: 7540
#include <stdio.h>

int main(void) {
	int id_map[100];
	int used_map[100];
	int width;
	int query_num,now_query;
	char query_type[2];
	int q_id,q_width;
	int i,j;
	while(1) {
		scanf("%d%d",&width,&query_num);
		if(width==0 && query_num==0)break;
		for(i=0;i<width;i++)used_map[i]=0;
		for(now_query=0;now_query<query_num;now_query++) {
			scanf("%s%d",query_type,&q_id);
			if(query_type[0]=='s') {
				scanf("%d",&q_width);
				for(i=0;i<=width-q_width;i++) {
					for(j=0;j<q_width;j++) {
						if(used_map[i+j])break;
					}
					if(j>=q_width) {
						printf("%d\n",i);
						for(j=0;j<q_width;j++) {
							id_map[i+j]=q_id;
							used_map[i+j]=1;
						}
						break;
					}
				}
				if(i>width-q_width)puts("impossible");
			} else if(query_type[0]=='w') {
				for(i=0;i<width;i++) {
					if(used_map[i] && id_map[i]==q_id)used_map[i]=0;
				}
			}
		}
		puts("END");
	}
	return 0;
}

Measured memory_bytes: 0
q,h,s,d = gets.split.map(&:to_i)
n = gets.to_i

q1 = q*4
h1 = h*2
s1 = s
d1 = d/2
w = [q1, h1, s1, d1]

ans = 0
if w.min == d1
  ans += n/2 * d
  n = n%2
  w.pop
end

ans += w.min * n
puts ans

Measured memory_bytes: 1788
n,x,m = map(int, input().split())
be = x % m
ans = be
memo = [[0,0] for i in range(m)]
am = [be]
memo[be-1] = [1,0]  #len-1
for i in range(n-1):
    be = be**2 % m
    if be == 0:
        break
    elif memo[be-1][0] == 1:
        kazu = memo[be-1][1]
        l = len(am) -  kazu
        syou = (n-i-1) // l
        amari = (n-i-1)%l
        sum = 0
        for k in range(kazu, len(am)):
            sum += am[k]
        ans = ans + syou*sum
        if amari > 0:
            for j in range(kazu,kazu + amari):
                ans += am[j]
        break
    else:
        ans += be
        am.append(be)
        memo[be-1][0] = 1
        memo[be-1][1] = len(am) -1
print(ans)


Measured memory_bytes: 21120
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a[256];
  for(int i=0;i<3;i++){
    cin>>a[i];
  }
  sort(a,a+3);
  cout<<a[0]<<' '<<a[1]<<' '<<a[2]<<'\n';
  
  return 0;
}



Measured memory_bytes: 3108
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <iterator>
#include <cmath>
#include <set>
#include <deque> 
#include <string>


using namespace std;

int n;

char s[30010];
int a[3];

bool doSearch()
{
	int p = 0;
	int pA = 0;
	while (p < n)
	{
		if (a[pA] == s[p])
		{
			pA++;
			if (pA >= 3)
				return true;
		}
		
		p++;
	}
	
	if (pA < 3)
	{
		return false;
	}
}

int main()
{
	scanf("%d\n", &n);
	
	scanf("%s\n", s);
		
	int count = 0;
	for (int num = 0 ; num < 1000 ; num++)
	{
//		printf("%d\n", num);
		
		int newNum = num;
		a[2] = newNum % 10 + '0';
		newNum = newNum / 10;
		a[1] = newNum % 10 + '0';
		newNum = newNum / 10;
		a[0] = newNum + '0';
		
		if (doSearch()){
			count++;
		}
	}
	
	printf("%d\n", count);
		
	return 0;
}


Measured memory_bytes: 128
import java.util.*;
 
public class Main {
	public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int n = sc.nextInt();
        int c[] = new int[n - 1];
        int s[] = new int[n - 1];
        int f[] = new int[n - 1];
        for(int i = 0; i < n - 1; i++){
        	c[i] = sc.nextInt();
            s[i] = sc.nextInt();
            f[i] = sc.nextInt();
        }
        for(int i = 0; i < n - 1; i++){
            int time = 0;
        	for(int j = i; j < n - 1; j++){
            	if(time < s[j]){
                	time = s[j];
                }else if(time % f[j] != 0){
                	time += f[j] - (time % f[j]);
                }
                time += c[j];
            }
            System.out.println(time);
        }
        System.out.println(0);
    }
}

Measured memory_bytes: 39404
#include <algorithm>
#include <array>
#include <cmath>
#include <functional>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>
#include <bitset>

#define pv(val) cerr << #val << '=' << (val) << endl
#define pvn(name, val) cerr << name << '=' << (val) << endl
#define pl cerr << '@' << __LINE__ << endl

using namespace std;

using ll = int64_t;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define all(a) a.begin(), a.end()

template <class T>
ostream &operator<<(ostream &os, vector<T> const &vec) {
    if (vec.empty()) {
        os << "{}";
    } else {
        os << '{';
        for (size_t i = 0; i < vec.size() - 1; i++) os << vec[i] << ", ";
        os << vec.back() << '}';
    }
    return os;
}

template <class T, size_t S>
ostream &operator<<(ostream &os, array<T, S> const &arr) {
    if (arr.empty()) {
        os << "{}";
    } else {
        os << '{';
        for (size_t i = 0; i < arr.size() - 1; i++) os << arr[i] << ", ";
        os << arr.back() << '}';
    }
    return os;
}

template <class T, class U>
ostream &operator<<(ostream &os, pair<T, U> const &p) {
    os << '(' << p.first << ", " << p.second << ')';
    return os;
}

namespace math {
ll gcd(ll u, ll v) {
    while (v != 0) {
        ll r = u % v;
        u = v;
        v = r;
    }
    return u;
}
ll lcm(ll m, ll n) {
    if ((0 == m) || (0 == n)) return 0;

    return ((m / math::gcd(m, n)) * n);
}
}  // namespace math

struct UnionFind {
    vector<ll> data;
    UnionFind(ll size) : data(size, -1) {}
    bool unionSet(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x != y) {
            if (data[y] < data[x]) swap(x, y);
            data[x] += data[y];
            data[y] = x;
        }
        return x != y;
    }
    bool findSet(ll x, ll y) { return root(x) == root(y); }
    ll root(ll x) { return data[x] < 0 ? x : data[x] = root(data[x]); }
    ll size(ll x) { return -data[root(x)]; }
};

template <class T, class U>
pair<T, U> operator+(pair<T, U> const &a, pair<T, U> const &b) {
    return pair<T, U>(a.first + b.first, a.second + b.second);
}

template <class T, class U>
pair<T, U> operator-(pair<T, U> const &a, pair<T, U> const &b) {
    return pair<T, U>(a.first - b.first, a.second - b.second);
}

ll bound(function<bool(ll)> f, ll ng, ll ok) {
    while (abs(ng - ok) > 1) {
        ll mid = (ng + ok) / 2;
        if (f(mid))
            ok = mid;
        else
            ng = mid;
    }

    return ok;
}

int main(void) {
    ll N;
    array<ll, 5> in;
    cin >> N;
    rep(i, 5)
        cin >> in[i];

    cout << 4ll + (ll)(ceil((double)N / *min_element(in.begin(), in.end())) + 0.1) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1000000005;

int main()
{
	ll n,l;
	cin >> n >> l;
	vector<ll> a(n);
	rep(i,n)cin >> a[i];
	ll ma = 0;

	rep(i,n-1)
	{
		if(a[i]+a[i+1]>a[ma]+a[ma+1])ma=i;
	}
	if(a[ma]+a[ma+1]<l)
	{
		cout<<"Impossible"<<endl;
		return 0;
	}
	cout<<"Possible"<<endl;
	rep(i,ma)
	{
		cout<<i+1<<endl;
	}
	for(ll i=n-2;i>ma;--i)
	{
		cout<<i+1<<endl;
	}
	cout<<ma+1<<endl;
	return 0;
}

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

int pow2(int l){
    if(l>0){
        return 2*pow2(l-1);
    }
    return 1;
}

vector<bool> inttobool(int n,int l){
    vector<bool> rep;
    for(int i=0;i<l;i++){
        rep.push_back(n%2);
        n/=2;
    }
    return rep;
}

void hantei(int i,int j,vector<string> s,int H,int W,int *c){
    if(0<=i && i<H && 0<=j && j<W){
        if((s.at(i)).at(j)=='#'){
            (*c)++;
        }
    }
}

int main(){
    int H,W;
    cin>>H>>W;
    vector<string> s(H);
    for(int i=0;i<H;i++){
        cin>>s.at(i);
    }
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            if((s.at(i)).at(j)=='#'){
                int count=0;
                int *c=&count;
                hantei(i+1,j,s,H,W,c);
                hantei(i-1,j,s,H,W,c);
                hantei(i,j+1,s,H,W,c);
                hantei(i,j-1,s,H,W,c);
                if(count==0){
                    cout<<"No"<<endl;
                    return 0;
                }
            }
        }
    }
    cout<<"Yes"<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int main()
{
    int n;
    scanf("%d", &n);
    int a[100000];
    int i;
    a[0] = 0;
    for (i = 1; i <= n; i++)
        scanf("%d", &a[i]);
    a[n + 1] = 0;
    int x;
    int ans;
    int k = 0;
    for (i = 0; i <= n; i++)
        k += abs(a[i + 1] - a[i]);
    for (i = 1; i <= n; i++)
    {
        ans = k;
        ans -= abs(a[i - 1] - a[i]);
        ans -= abs(a[i] - a[i + 1]);
        ans += abs(a[i + 1] - a[i - 1]);
        printf("%d\n", ans);
    }
    return 0;
}

Measured memory_bytes: 1536
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws FileNotFoundException {

		Scanner scan = new Scanner(System.in);
		// Scanner scan = new Scanner(new File("c:\\0509-input.txt"));

		while (true) {
			int n = scan.nextInt();
			int m = scan.nextInt();
			if (n == 0)
				break;

			int[] bx = new int[m];

			for (int i = 0; i < n; i++)
				for (int j = 0; j < m; j++) {
					int x = scan.nextInt();
					if (x == 1)
						bx[j]++;
				}

			for (int i = 0; i < m; i++) {
				int result = 0, max = -1;
				for (int j = 0; j < m; j++)
					if (bx[j] > max) {
						max = bx[j];
						result = j;
					}
				bx[result] = -1;
				if (i > 0)
					System.out.print(" ");
				System.out.print(result + 1);
			}
			System.out.println();
		}

		scan.close();
		System.exit(0);
	}

	private static void run(int n, String s) {
		if (n == 0) {
			System.out.println(s);
			return;
		}

		StringBuilder ss = new StringBuilder("");

		for (int i = 0; i < s.length(); i++) {
			int repeat = 1;
			for (int j = i + 1; j < s.length(); j++)
				if (s.charAt(i) == s.charAt(j)) {
					repeat++;
					i++;
				} else
					break;
			ss.append(String.valueOf(repeat));
			ss.append(String.valueOf(s.charAt(i)));
		}

		run(n - 1, ss.toString());
	}

}

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

S = str(input())
q = int(input())

p = ''
s = ''
cur = 0
for i in range(q):
    query = input().split()
    #print(query)
    if len(query) == 1:
        if cur == 0:
            cur = 1
        else:
            cur = 0
    else:
        t, f, c = query
        if f == '1':
            if cur == 0:
                p = c + p
            else:
                s = s + c
        else:
            if cur == 0:
                s  = s + c
            else:
                p = c + p
ans = p+S+s
if cur == 1:
    ans = ''.join(list(reversed(ans)))
print(ans)


Measured memory_bytes: 6244
#include <bits/stdc++.h>
using namespace std;
set<int> s;
int main() {
	ios::sync_with_stdio(false);
	// freopen("in.txt", "r", stdin);
	int x, n;
	while (cin >> x >> n) {
      	int ans = 100;
		int d = 0x3f3f3f3f;
		for (int i = 0; i < n; i++) {
			int t;
			cin >> t;
			s.insert(t);
		}
		for (int i = -1; i <= 101; i++) {
			if (!s.count(i)) {
				if (d > abs(x - i)) {
					ans = i;
					d = abs(x - i);
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3648
# -*- coding: utf-8 -*-

import sys
from collections import Counter

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N, K, Q = MAP()
scores = [K] * N
A = LIST(Q)

C = Counter(A)
for i in range(N):
    scores[i-1] -= Q - C[i]

for score in scores:
    if score > 0:
        Yes()
    else:
        No()


Measured memory_bytes: 15108
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;

int main(void) {
    int n;
    cin >> n;
    ll a[n],b[n];
    rep(i,n+1){cin>>a[i];}
    rep(i,n){cin>>b[i];}
    ll res=0;
    rep(i,n){
        ll tmp = min(a[i],b[i]);
        res += tmp;
        b[i] -= tmp;
        if(b[i]>0){
            tmp = min(a[i+1], b[i]);
            res += tmp;
            a[i+1] -= tmp;
        }
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 1920
N, M = list(map(int, input().split()))
arr = []

for _ in range(N):
    arr.append(list(map(int, input().split())))

arr = sorted(arr, key=lambda x:x[0])

cost = 0
for a, c in arr:
    b = min(M, c)
    cost += a*b
    if M-c<=0:
        break
    else:
        M -= c
print(cost)

Measured memory_bytes: 29788
// https://atcoder.jp/contests/abc140/tasks/abc140_e

#include "algorithm"
#include "iostream"
#include "set"
#include "vector"
#define rep(i, from, to) for (ll i = from; i < (to); ++i)
using namespace std;
typedef long long ll;

template <class T>
inline bool chmax(T& a, T b);
template <class T>
inline bool chmin(T& a, T b);

void solve() {
  ll N;
  cin >> N;

  vector<ll> ps(N), num_to_index(N + 1);
  rep(i, 0, N) cin >> ps[i];

  rep(i, 0, N) num_to_index[ps[i]] = i;

  multiset<ll> large_indices;

  large_indices.insert(-1);
  large_indices.insert(-1);
  large_indices.insert(N);
  large_indices.insert(N);

  ll res = 0;

  for (ll num = N; num >= 1; num--) {
    ll i = num_to_index[num];

    auto it = large_indices.lower_bound(i);
    ll bi = *it++;
    ll bi2 = *it--;
    it--;
    ll si = *it--;
    ll si2 = *it;

    // s を取る場合
    res += (si - si2) * (bi - i) * num;
    // b を取る場合
    res += (bi2 - bi) * (i - si) * num;

    large_indices.insert(i);
  }

  cout << res << endl;
}

#ifndef TEST
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
  return 0;
}
#endif

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;
}


Measured memory_bytes: 6528
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
 
//krishrawat
 
 
//----------------------------MACROS-------------------------------------------------
#define pb insert//                                                                 |
#define eb emplace_back//                                                           |
#define ff first//                                                                  |
#define ss second//                                                                 |
typedef long long int ll;//                                                         |
typedef long double ld;//                                                           |
#define all(a) a.begin(), a.end()//                                                 |
#define show(x) cerr << #x << " is " << x << "\n"//                                 |
#define show2(x, y) cerr << #x << " " << #y << " " << x << " " << y << "\n"//       |
typedef vector<ll> vl;//                                                            |
typedef vector<vl> vvl;//                                                           |
typedef pair<ll, ll> pp;//                                                          |
typedef vector<pp> vp;//                                                            |
typedef map<pp, ll> ipi;//                                                          |
typedef map<pp, char> ipc;//                                                        |
typedef map<ll, ll> ii;//                                                           |
typedef set<ll> sl;//                                                               |
typedef multiset<ll> msl;//                                                         |
typedef map<char, ll> ci;//                                                         |
typedef set<pair<ll, ll>> sp;//                                                     |
const ll mod = 1e9 + 7;//                                                           |
const ll N = 1e3 + 1;//                                                             |
//----------------------------------------------------------------------------------

ll n,m;

bool check(ll x){
    ll k=x-n;
    ll w=m;
    if(k>0){
        w-=k*2;
    }
    if(w/2>=x) return true;
    return false;
}

//solution
void solve()
{   
    
    cin>>n>>m;
    ll l=0;
    ll r=1e18;
    while(r-l>3){
        ll mid=(l+r)/2;
        if(check(mid)) l=mid;
        else r=mid-1;
    }
    //cout<<l<<"\n";
    while(r>=l){
        if(check(r)) break;
        r--;
    }
    cout<<r<<"\n";
}
 
 
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
    
    ll t; t=1;
    //cin>>t;
    while(t--) solve(); return 0;
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<ll> ql;
typedef deque<ll> dql;
typedef priority_queue<ll/*, vl, greater<ll>*/> pql; //降順(/*昇順*/)
typedef set<ll> sl;
typedef pair<ll, ll> pl;
typedef pair<pl, ll> ppl;
typedef vector<vl> vvl;
typedef vector<pl> vpl;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rep2(i, k, n) for(ll i = ll(k); i <= ll(n); i++)
#define rep3(i, n, k) for(ll i = ll(n); i >= ll(k); i--)
#define all(v) (v).begin(), (v).end()
ll mod(ll a, ll b) {if(b == 0) return 0; return (a % b + b) % b;}
bool chmin(ll &a, ll b) {if(b < a) {a = b; return 1;} return 0;}
bool chmax(ll &a, ll b) {if(b > a) {a = b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const ll MAX = 1e9;
const char newl = '\n';

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

  vl a(2), c(2);
  cin >> a[0] >> a[1] >> c[0] >> c[1];
  
  ll ans = -INF;
  rep(i, 2) rep(j, 2) chmax(ans, a[i]*c[j]);
  cout << ans << newl;
  return 0;
}

Measured memory_bytes: 3652
use strict;
use warnings;

my ($N, $M) = glob(<>);
my @SC = ();

for (my $i = 0; $i < $M; $i++) {
    my ($s, $c) = glob(<>);
    $SC[$i] = [ $s, $c ];
}

for (my $i = 0; $i < 1000; $i++) {
    if (length($i) == $N) {
        my $all = 1;
        foreach (@SC) {
            if (substr($i, $_->[0] - 1, 1) != $_->[1]) {
                $all &= 0;
            }
        }
        if ($all == 1) {
            print $i;
            exit;
        }
    }
}

print -1;

Measured memory_bytes: 768
#include<stdio.h>
#define rep2(i,n) rep3(i,0,n)
#define rep3(i,j,n) for((i)=(j) ; (i)<(n) ; (i)++)
#define pl(format,var) p(format "\n",var)
#define p(format,var) printf(format,var)
#define asizeof(array) (sizeof(array)/sizeof(array[0]))

//入力したdouble値を小数点第n位で四捨五入する
//細かいエラーチェックは書いてない
double rounddouble(double a, int n){
  double dup = a; //計算で使う一時変数
  double adjuster = 5; //四捨五入で使う一時変数
  int i; //カウンタ変数
  
  //弟n位に5を入れた小数点をつくる
  for(i=0 ; i<n ; i++)
    adjuster /= 10;
  
  //つくった値を足して
  if(dup<0){
    dup -= adjuster;
  }else{
    dup += adjuster;
  }
  
  //10^n倍して
  dup *= pow(10, n-1);
  
  //小数点以下を切り捨てて, 10^nで割る
  dup = (int)dup / (double)pow(10, n-1);
  
  return dup;
}

int main(){
	char line[80];
	int i=0; //入力されたデータの個数
	int curprice, curnum; //入力された販売単価、販売数量
	int sumprice=0, sumnum=0; //合計の単価、数量
	double avgnum = 0.0;

	while(fgets(line, sizeof(line), stdin) != NULL){
		sscanf(line, "%d,%d", &curprice, &curnum);
		sumprice += curprice * curnum;
		sumnum += curnum;
		i++;
	}
	//平均を計算する
	avgnum = sumnum / (double)i;
	
	//出力する
	//ただし平均は小数点第一位で四捨五入
	pl("%d", sumprice);
	pl("%d", (int)rounddouble(avgnum,1));

  return 0;
}

Measured memory_bytes: 620
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <math.h>
#include <list>
#include <stack>
#include <queue>
#include <utility>

using namespace std;

#define ll long long
#define MOD 1000000007
#define rep(i, n) for(int i = 0;i < n;i++)

bool compare_by_seond(pair<ll, ll> a, pair<ll, ll> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}


int main()
{
    int n;
    cin >> n;
    vector<pair<ll,ll> > pairs;
    ll a,b;

    rep(i,n)
    {
        pair<ll,ll> mypair;
        cin >> a >> b;
        mypair = make_pair(a,b);
        pairs.push_back(mypair);
    }
    /*rep(i,n)
    {
        cout << pairs[i].first <<pairs[i].second <<  endl;
    }*/
    sort(pairs.begin(),pairs.end(),compare_by_seond);

    
    int index = 0;
    int work = 0;
    int time = 0;
    int dl;
    int flag = 0;

    queue<ll> q;

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

        if (time+pairs[i].first <= pairs[i].second)
        {
            time+= pairs[i].first;
        }else
        {
            flag = 1;
            break;
        }
        
    }
    
    if (flag == 1)
    {
        cout << "No" << endl;
    }else
    {
        cout << "Yes" << endl;
    }
    
    
}

Measured memory_bytes: 6256
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

ll Pow(ll n,ll p){
	ll r=1;
	for(;p>0;p>>=1){
		if(p&1) r=(r*n)%mod;
		n=(n*n)%mod;
	}
	return r;
}

const int M=10005;
ll F[M];

void Init(){
	F[0]=1;
	for(int i=1;i<M;i++) F[i]=F[i-1]*i%mod;
}

ll Div(ll n,ll m){
	return n*Pow(m,mod-2)%mod;
}

ll nCk(ll n,ll k){
	return Div(F[n],F[n-k]*F[k]%mod);
}

int n,k;

int main(){
	Init();
	cin>>n>>k;
	for(int i=1;i<=k;i++){
		if(n-k<i-1) cout<<0<<endl;
		else cout<<nCk(n-k+1,i)*nCk(k-1,k-i)%mod<<endl;
	}
}

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

using namespace std;

#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define dump(x) cerr << #x " = " << (x) << '\n'
#define sz(x) ((int)(x).size())
#define endl '\n'

#ifdef _DEBUG27_
    //#define STRESS 1
#endif

typedef long long llong;

const int INF = 2e9 + 999;
const llong LINF = 2e18 + 999;

void inv(bool e);
template<typename T> T sign(T a);
template<typename T> void die(T &a);
template<typename T> void umax(T &a, T b);
template<typename T> void umin(T &a, T b);

bool brute, alter;
int cnt_tests = 1;

// Get + in div1

// Code below

double a, b;

void inp() {
    cin >> a >> b;
}

void solve() {
    cout << (2.0 * b - a);
}

void stress() {

}

void naive() {

}

void run();
int main() {
    #ifdef _DEBUG27_
        if (1)
            freopen("input.txt", "r", stdin);
    #else
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        if (0) {
            freopen("palindrome.in", "r", stdin);
            freopen("palindrome.out", "w", stdout);
        }
    #endif
    srand(time(0));
    #ifdef STRESS
        brute = true;
    #else
        brute = false;
    #endif

    for (int i = 0; (i < cnt_tests); i++) {
        run();
    }

    #ifdef _DEBUG27_
        cout << endl << "Time: " << clock() / 1000.0 << " ms";
    #endif
    return 0;
}

void run() {
    if (!brute) {
        inp();
    }
    else {
        stress();
    }
    solve();
    cout << endl;
}

template<typename T>
void die(T &a) {
    cout << a;
    exit(0);
}

template<typename T>
T sign(T a) {
    if (a == 0)
        return 0;
    if (a < 0)
        return -1;
    return 1;
}

template<typename T>
void umax(T &a, T b) {
    if (b > a)
        a = b;
}

template<typename T>
void umin(T &a, T b) {
    if (b < a)
        a = b;
}

void inv(bool e) {
    if (!e) {
        vector<int> a;
        a[-1] += 1;
    }
}

/** CLEARING BUFFER

    cout << VAL << flush;

    OR

    printf(VAL);
    fflush(stdout);
*/


Measured memory_bytes: 256
A,B,K=map(int,input().split())
max=0
min=0
l=[]
if A<B:
    max=B
    min=A
else:
    max=A
    min=B

for i in range(min):
    if (A%(i+1)==0)and(B%(i+1)==0):
        l.append(i+1)
l.sort(reverse=True)
print(l[K-1])

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


int main(){
  ll n,m;
  while(cin>>n>>m && n){
  vector<pll> dp(n);
  vector<pll> mi(n);
  for(int i=0;i<n;i++){
    dp[i]=mi[i]={0,i};
  }
  for(int i=0;i<m;i++){
    ll s,k;
    cin>>s>>k;
    for(int t=0;t<k;t++){
      ll p;
      cin>>p;
      p--;
      if(k==1){mi[p].first+=s;}
      dp[p].first+=s;
    }
  }
  sort(dp.begin(),dp.end(),greater<pll>());
  sort(mi.begin(),mi.end());
  if(n==1){cout<<0<<endl;}
  else{
    ll mx=0;
    if(dp[0].second!=mi[0].second){mx=dp[0].first-mi[0].first;}
    else{
      mx=max(dp[0].first-mi[1].first,dp[1].first-mi[0].first);
    }
    cout<<mx+1<<endl;
  }

  }


  return 0;
}



Measured memory_bytes: 3324
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <functional>
#include <sstream>
#include <complex>
#include <climits>
using namespace std;

#define REP(i,a,n) for(int i=(a);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define EPS 1e-8

int dp[2][1010];

int main(){
	int w,n;
	pair<int,int> kati[1000];
	for(int T=1; scanf("%d",&w),w; T++){
		printf("Case %d:\n",T);
		memset(dp,0,sizeof(dp));
		scanf("%d",&n);
		rep(i,n){
			int a,b; scanf("%d,%d",&a,&b);
			kati[i].first = a;
			kati[i].second = b;
		}
		rep(i,n){
			int cur = i%2;
			int next = (i+1)%2;
			for(int j=0; j<=w; j++){
				if( kati[i].second>j ){
					dp[next][j] = dp[cur][j];
				}else{
					dp[next][j] = max(dp[next][j],
												max(dp[cur][j-kati[i].second]+kati[i].first,dp[cur][j]));
				}
			}
			rep(i,w+1)dp[cur][i]=0;
		}
		int sum=0,omosa=0;
		rep(i,w+1)if( sum<dp[n%2][i] ){
			sum = dp[n%2][i];
			omosa = i;
		}
		printf("%d\n%d\n",sum,omosa);
	}
	return 0;
}

Measured memory_bytes: 0
N, M = gets.split.map(&:to_i)
ABS = M.times.map { gets.split.map(&:to_i) }

routes = {} # room: [rooms...]

ABS.each do |ab|
  a, b = ab
  routes[a] = (routes[a] || []).push(b)
  routes[b] = (routes[b] || []).push(a)
end

results = { 1 => [nil, 0] } # room: [label, cost]
results.default = nil

if routes[1].length == 0
  puts "No"
  exit
end

queue = [] + routes[1]
i = 0
loop do
  room = queue[i]
  break unless room
  if results.has_key?(room)
    i += 1
    next
  end
  # puts "room #{room}"

  label = nil
  cost = N + 1
  routes[room].each do |r|
    # puts "#{r}, #{results[r]}"
    if !results.has_key?(r)
      queue.push(r)
    elsif results[r][1] < cost
      label = r
      cost = results[r][1] + 1
    end
  end
  results[room] = [label, cost]
  i += 1
end

puts "Yes"
results.delete(1)
results.keys.sort.each do |k|
  puts results[k][0]
end


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

#define REP(i, x) REPI(i, 0, x)
#define REPI(i, a, b) for (int i = int(a); i < int(b); ++i)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
using namespace std;

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

  ll N, X;
  cin >> N >> X;
  vector<ll> x(N + 1);
  REP(i, N) { cin >> x.at(i); }
  x.at(N) = X;
  sort(x.begin(), x.end());
  vector<ll> y(N);
  REP(i, N) { y.at(i) = x.at(i + 1) - x.at(i); }
  ll min_diff = *min_element(y.begin(), y.end());
  ll ans = min_diff;
  REP(i, N) {
    if (y.at(i) % min_diff != 0) {
      ans = __gcd(ans, y.at(i));
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1920
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<set>
#include<tuple>
#include<ctime>
#include<functional>
#include<cmath>
#include<cassert>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> p; 
#define rep(i,n) for(ll i=0;i<(n);i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")
#define pb push_back
#define mp make_pair
#define fi first
#define se second
int main(){
   ll N,a[200010];
   cin>>N;
   rep(i,N) cin>>a[i];
    ll max1=a[0];
    ll cnt=0;
    rep(i,N){

        if(a[i]<max1){
            cnt+=max1-a[i];
        }
        if(max1<a[i]) max1=a[i];
    }
    cout<<cnt<<endl;
}

Measured memory_bytes: 5184
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int N;
    cin >> N;
    vector<int> B(N-1);
    for(int i=0; i<N-1; i++)
    cin >> B.at(i);
    vector<int> A(N);
    A.at(0)=B.at(0);
    A.at(N-1)=B.at(N-2);
    for(int i=1; i<N-1; i++){
        A.at(i)=min(B.at(i),B.at(i-1));
    }
    int sum=0;
    for(int i=0; i<N; i++){
        sum+=A.at(i);
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
x,y = map(int,input().split())
g1 = [1,3,5,7,8,10,12]
g2 = [4,6,9,11]
g3 = [2]
if x in g1 and y in g1:
    print('Yes')
elif x in g2 and y in g2:
    print('Yes')
else:
    print('No')

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


void solve(std::string S){
    if(S=="Sunny")cout<<"Cloudy"<<endl;
    else if(S=="Cloudy")cout<<"Rainy"<<endl;
    else cout<<"Sunny"<<endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayDeque;

public class Main {
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter pw = new PrintWriter(System.out);
		
		int n = Integer.parseInt(br.readLine());
		ArrayDeque<Integer> list = new ArrayDeque<Integer>();
		for (int i = 0; i < n; i++) {
			String com = br.readLine();
			if (com.charAt(0) == 'i')
				insertKey(list, Integer.parseInt(com.substring(7)));
			else {
				if (com.charAt(6) == ' ')
					deleteKey(list, Integer.parseInt(com.substring(7)));
				else if (com.charAt(6) == 'F')
					deleteFirstMember(list);
				else
					deleteLastMember(list);
			}
		}
		
		pw.print(list.poll());
		for (Integer element : list)
			pw.print(" "+element);
		pw.println();
		pw.close();
	}
	
	public static void insertKey(ArrayDeque<Integer> l, int x) {
		l.addFirst(x);
	}
	
	public static void deleteKey(ArrayDeque<Integer> l, int x) {
		l.removeFirstOccurrence(x);
	}
	
	public static void deleteFirstMember(ArrayDeque<Integer> l) {
		l.removeFirst();
	}
	
	public static void deleteLastMember(ArrayDeque<Integer> l) {
		l.removeLast();
	}
}

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

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

  ll sum = 0;

  int bitsize = S.size() - 1;
  rep(i, pow(2, bitsize)) {
    ll buf = S[0] - '0';
    rep(j, bitsize) {
      if (i & (1 << j)) {
        sum += buf;
        buf = S[j + 1] - '0';
      } else {
        buf *= 10;
        buf += S[j + 1] - '0';
      }
    }
    sum += buf;
  }

  cout << sum << endl;
}

Measured memory_bytes: 256
##N人の子供がいます。 子供たちには 1,2, .. ,N と番号が振られています。
##x個のお菓子を子供たちに配ることにしました。
##このとき、 x個のお菓子をすべて配り切らなければなりません。
##お菓子を貰わない子供がいても構いません。
##各i (1 ≤ i ≤ N) について、子供 i はちょうど ai個のお菓子を貰うと喜びます。 
##お菓子を配る方法を工夫し、喜ぶ子供の人数を最大化しようとしています。
##喜ぶ子供の人数の最大値を求めてください。

##入力は以下の形式で標準入力から与えられる。
##N x
##a1 a2 .. aN
n, x = gets.chomp.split(" ").map(&:to_i)
last = n - 1
a_n = gets.chomp.split(" ").map(&:to_i).sort

##喜ぶ子供の人数の最大値を出力せよ。
a_m = []
a_n.each_index do |idx|
  check = x - a_n[idx]
  if check >= 0
    if idx == last
      a_m << x
    else
      x -= a_n[idx]
      a_m << a_n[idx]
    end
  else
    a_m << 0
  end
end
# p a_n
# p a_m

num = 0
a_m.each_index do |idx|
  num += 1 if a_m[idx] == a_n[idx]
end
p num

Measured memory_bytes: 1788
N=int(input())
S=input()
whi=0
bla=0
c1=0
dp=[[0,0] for i in range(N+1)]
for i in range(N):
    s=S[i]
    if s=="#":
        dp[i+1][0]=dp[i][0]+1
    else:
        dp[i+1][0]=dp[i][0]
for i in range(N):
    s=S[N-1-i]
    if s==".":
        dp[N-i-1][1]=dp[N-i][1]+1
    else:
        dp[N-i-1][1]=dp[N-i][1]


ans=float("inf")
for i in range(N+1):
    ans=min(ans,dp[i][0]+dp[i][1])
print(ans)


Measured memory_bytes: 63820
import java.util.*
import kotlin.comparisons.reverseOrder

fun main(args: Array<String>) {
    val (n, m) = readLine()!!.split(' ').map(String::toInt)
    val array = readLine()!!.split(' ').map(String::toLong)
    val pq = PriorityQueue<Long>(n, reverseOrder())
    pq.addAll(array)
    repeat(m) {
        val num = pq.poll() / 2
        pq.add(num)
    }
    println(pq.sum())
}


Measured memory_bytes: 73916
#include <iostream>
#include <vector>

using namespace std;

int main()
{
	int N;
	int swapcount = 0;

	cin >> N;

	vector<int> A(N);

	for (int i = 0;i < N;i++)
		cin >> A[i];

	for (int i = 0;i < N;i++)
	{
		int minj = i;

		for (int j = i;j < N;j++)
		{
			if (A[j] < A[minj])
				minj = j;
		}

		swap(A[i], A[minj]);
		if (i != minj)
			swapcount++;
	}

	for (int i = 0;i < N;i++)
	{
		if (i > 0)
			cout << " ";

		cout << A[i];
	}
	cout << endl;

	cout << swapcount << endl;
	
	return 0;
}

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

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

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

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF   = 1e9;
const ll  INFLL = 1e18;
typedef pair<int, int> PII;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

int main()
{
    ios::sync_with_stdio(false);
    set<int> colors;
    int free_color = 0;

    int N; cin >> N;
    rep(j, N) {
        int A; cin >> A;
        if (A >= 3200) {
            free_color++;
        } else {
            for (int i=1;; i++) {
                if (A < 400 * i) {
                    colors.insert(i);
                    break;
                }
            }
        }
    }

    int max_num = colors.size() + free_color;
    int min_num = max(1, (int)colors.size());
    cout << min_num << " " << max_num << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cassert>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> PLL;

constexpr int LIM = 100010;

int N, M;
int x[LIM], y[LIM];

int main() {
    cin >> N >> M;
    for (int j = 0; j < M; ++j) {
        cin >> x[j] >> y[j];
        --x[j]; --y[j];
    }

    int count[LIM];
    char possible[LIM];

    fill(count, count + N, 1);
    fill(possible, possible + N, 0);
    possible[0] = 1;

    for (int j = 0; j < M; ++j) {
        if (possible[x[j]]) {
            if (count[x[j]] == 1) {
                possible[x[j]] = 0;
            }

            possible[y[j]] = 1;


        }
        --count[x[j]];
        ++count[y[j]];
    }

    int sum = 0;
    for (int j = 0; j < N; ++j) {
        sum += possible[j];
    }

    cout << sum << endl;


    return 0;
}


Measured memory_bytes: 1536