akhauriyash/Code-Regression huggingface dataset:
// https://beta.atcoder.jp/contests/abc109

#define SUBMIT

#include <bits/stdc++.h>
using namespace std;

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

    return x;
}

int main() {
#ifdef SUBMIT
    auto& stream = cin;
#else
    stringstream stream(R"(1 1
1000000000
)");
#endif
    int N, X;
    stream >> N >> X;
    int ans = INT_MAX;
    int min_dist = INT_MAX;
    for (int i = 0; i < N; ++i) {
        int x;
        stream >> x;
        min_dist = min(min_dist, abs(X - x));
        auto g = gcd(abs(X - x), min_dist);
        ans = min(ans, g);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define clr(a) memset(a, 0, sizeof(a))
#define sz(x) x.size()
#define printarray(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout<<*it<<" "; cout<<endl;
#define rep(n) for (ll i = 0; i < n; i++)
#define repc(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, x, y) for (int i = x; i < y; i++)
#define DEC(i, x, y) for (int i = x; i >= y; i--)
#define all(v) v.begin(), v.end()
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define alla(a, n) a, a + n
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) (a * b)/gcd(a, b)
#define int long long int
#define ull unsigned long long

using namespace std;
const int MOD = 1e9 + 7;
const int MAXN = 1e5 + 5;

int fastexpo(int b, int exp){
    if(exp == 0) return 1;
    if(exp == 1) return b;
    int ans = (fastexpo(b,exp/2) % MOD);
    ans *= ans;
    ans %= MOD;
    if(exp % 2 == 1){
        ans *= b;
    }
    ans %= MOD;
    return ans;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    vector<int> vec;
    int t2;
    cin>>t2;
    int len = 1;
    vec.pb(t2);
    for(int i= 1;i<n;i++){
    	int t1;
    	cin>>t1;
    	if(t1 != vec.back()){
    		vec.pb(t1);
    		len++;
    	}
    }    
    n = len;
    int ans = 1;
    int maxp = 0;
    map<int, int> cnt;
    cnt[vec[0]]++;
    for(int i = 1;i<n;i++){
    	ans += cnt[vec[i]];
    	ans = ans % MOD;
    	cnt[vec[i]] = ans;
    }
    cout<<ans<<endl;
    return 0;
}


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


int main(){
    int n,m,x,y;
    cin>>n>>m>>x>>y;
    vector<int> xn(n);
    for(int i=0;i<n;++i)cin>>xn[i];
    vector<int> ym(m);
    for(int i=0;i<m;++i)cin>>ym[i];
    int maxx=-1111111;
    for(int i=0;i<n;++i){
        maxx=max(maxx,xn[i]);
    }
    int miny=100000000;
    for(int i=0.;i<m;++i){
        miny=min(miny,ym[i]);
    }

    if(max(x, maxx) < min(y,miny)){
        cout<<"No War"<<endl;
    }else{
        cout<<"War"<<endl;
    }
    
    
}

Measured memory_bytes: 256
# For taking integer inputs.
import math


def inp():
    return(int(input()))


# For taking List inputs.
def inlist():
    return(list(map(int, input().split())))


# For taking string inputs. Actually it returns a List of Characters, instead of a string, which is easier to use in Python, because in Python, Strings are Immutable.
def instr():
    s = input()
    return(list(s[:len(s)]))


# For taking space seperated integer variable inputs.
def invr():
    return(map(int, input().split()))


def valid(x, y): return True if x >= 0 and x < row and y >= 0 and y < col else False


fx = [+0, +0, +1, -1, -1, +1, -1, +1]
fy = [-1, +1, +0, +0, +1, +1, -1, -1]
row, col = invr()
mat = []
for _ in range(row):
    mat.append(instr())

for i in range(row):
    for j in range(col):
        if mat[i][j] == ".":
            count = 0
            for k in range(len(fx)):
                nx = i + fx[k]
                ny = j + fy[k]
                if valid(nx, ny):
                    if mat[nx][ny] == "#":
                        count += 1
            mat[i][j] = str(count)

for r in mat:
    for i in r:
        print(i, end="")
    print()


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

#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define debug(x) cerr << #x << ": " << x << endl

using namespace std;

typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;

const ll MOD = 1000000007;
const long double EPS = 1e-10;
const int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

int main() {
    std::ios::sync_with_stdio(0); cin.tie(0);
    int n;
    cin >> n;
    vector<Pll> happiness(n); 
    for(int i=0;i<n;++i) {
        cin >> happiness[i].first >> happiness[i].second;
    }

    vector< pair<ll, int> > dishes;
    for(int i=0;i<n;++i) {
        dishes.emplace_back(happiness[i].second + happiness[i].first, i);
    }
    sort(rall(dishes));


    ll ans[2] = {0, 0};
    for(int i=0;i<n;i+=2) {
        ans[0] += happiness[dishes[i].second].first;
    }
    for(int i=1;i<n;i+=2) {
        ans[0] -= happiness[dishes[i].second].second;
    }
    for(int i=0;i<n;i+=2) {
        ans[1] += happiness[dishes[n-1-i].second].first;
    }
    for(int i=1;i<n;i+=2) {
        ans[1] -= happiness[dishes[n-1-i].second].second;
    }


    cout << max(ans[0], ans[1]) << endl;
}


Measured memory_bytes: 3956
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtcoderSubmit
{
    class Program
    {
        static void Main(string[] args)
        {
            var line = Console.ReadLine().Split(' ');
            var N = int.Parse(line[0]);
            var S = int.Parse(line[1]);
            var A = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            ulong mod = 998244353;

            var dp = Enumerable.Range(0, N + 1).Select(i => new ulong[S + 1]).ToArray();
            dp[0][0] = 1;
            for(int i = 0; i < N; i++) {
                for(int j = 0; j < S + 1; j++) {
                    dp[i + 1][j] += 2 * dp[i][j];
                    dp[i + 1][j] %= mod;
                    if(j + A[i] <= S) {
                        dp[i + 1][j + A[i]] += dp[i][j];
                        dp[i + 1][j + A[i]] %= mod;
                    }
                }
            }
            Console.WriteLine(dp[N][S]);
        }
    }
}


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

int main() {
	int N, M;
	cin >> N;
	map<int, int> Probs;
	for (int i = 0; i < N; i++) {
		int d;
		cin >> d;
		Probs[d]++;
	}
	cin >> M;
	bool ans = true;
	for (int i = 0; i < M; i++) {
		int t;
		cin >> t;
		if (Probs.find(t) == Probs.end()) ans = false;
		else {
			if (Probs[t] == 0) ans = false;
			else Probs[t]--;
		}
	}
	cout << (ans ? "YES" : "NO") << endl;
}

Measured memory_bytes: 9600
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
	int n; cin>>n;
	pair<int,int> p[100];
	for(int i=0;i<n;i++)
		p[i]=make_pair(0,i);
	
	for(int i=0;i<(n-1)*n/2;i++){
		int a,b,c,d; cin>>a>>b>>c>>d;
		if(c>d)
			p[a-1].first+=3;
		else if(c<d)
			p[b-1].first+=3;
		else{
			p[a-1].first++;
			p[b-1].first++;
		}
	}
	sort(p,p+n);
	reverse(p,p+n);
	
	int q[100];
	for(int i=0;i<n;i++)
		q[i]=!i||p[i].first<p[i-1].first?i+1:q[i-1];
	for(int i=0;i<n;i++)
		p[i]=make_pair(p[i].second,q[i]);
	sort(p,p+n);
	
	for(int i=0;i<n;i++)
		cout<<p[i].second<<endl;
	
	return 0;
}

Measured memory_bytes: 0
// Problem : D - Div Game
// Contest : AtCoder - AtCoder Beginner Contest 169
// URL : https://atcoder.jp/contests/abc169/tasks/abc169_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<long,long> pl;
typedef pair<ll,ll> pll;
typedef vector<long> vl;
typedef vector<bool> vb;
typedef vector<ll> vll;
typedef vector<vl> vvl;
typedef vector<vb> vvb;
typedef vector<vll> vvll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef unordered_map<ll,ll> umll;

#define FOR(i,a,b) for(long long i=a;i<b;++i)
#define REV(i,a,b) for(long long i=a;i>=b;i--)
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define tc ll tests;cin>>tests;while(tests--)
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define coutv(v) for(auto it: (v))cout<<it<<" ";newl;
#define cout2d(v) for(auto it: (v)) {for(auto j:it) cout<<j<<" ";newl;}
#define cinv(v,n) vll (v)(n);FOR(i,0,(n)){cin>>v[i];}
#define cinvg(v,n) (v).resize(n);FOR(i,0,(n)){cin>>v[i];}
#define cin2d(v,n,m) vvll (v)(n,vll(m,0));FOR(i,0,n){FOR(j,0,m){cin>>v[i][j];}}
#define cin2dg(v,n,m) (v).resize(n,vll(m));FOR(i,0,n){FOR(j,0,m){cin>>v[i][j];}}
#define newl cout<<"\n"
#define mod 1000000007
#define INF LLONG_MAX/2

vll nums;

umll pf;
void pfact(ll n)
{
	while(n%2==0)
	{
		n/=2;
		pf[2]++;
	}
	for(ll i=3;i*i<=n;i+=2)
	{
		while(n%i==0)
		{
			n/=i;
			pf[i]++;
		}
	}
	if(n!=1)//when prime
	{
		pf[n]++;
	}
}

int main()
{
    io;
    
    FOR(i,1,50)
    {
    	nums.pb((i*(i+1))/2);
    }
    ll n,cnt=0;
    cin>>n;
    if(n==1){cout<<0;return 0;}
    pfact(n);
    
    for(auto x: pf)
    {
    	//cout<<x.F<<" "<<x.S;newl;
    	ll ind=ub(all(nums),x.S)-nums.begin();
    	cnt+=ind;
    }
    cout<<cnt;
    return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    int A[100010];
    rep(i, N) cin >> A[i];
    ll ans = 0;
    rep(i, N) {
        if(i > 0 && A[i] > 0 && A[i - 1] > 0) {
            A[i]--; A[i - 1]--;
            ans++;
        }
        ans += A[i] / 2;
        A[i] -= (A[i] / 2) * 2;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 640
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};

const ll INF = 1LL << 50;

const ll mod = 1000000007;

int main() {
  ll n, m;
  cin >> n >> m;
  if (n <= m) puts("Yes");
  else
    puts("No");


  return 0;
}


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

using namespace std;
const int N = 2e5 + 11;
int ans[N],anss;
vector<int>v[N];

int dfs(int nod){
	
	int cur = 0;
	for(auto it:v[nod]){
		if(!ans[it])dfs(it);
		cur = max(cur , ans[it]);
	}
	
	return ans[nod] = cur+1;
}

int32_t main(){
ios_base::sync_with_stdio(0); cin.tie(0); cerr.tie(0); cout.tie(0);
	
	int n,m;
	cin>>n>>m;
	while(m--){
		int x,y;
		cin>>x>>y;
		v[x].pb(y);
	}
	
	for(int i=1;i<=n;i++){
		if(!ans[i])ans[i] = dfs(i);
		anss = max(anss , ans[i]);
		//cout<<ans[i]<<' ';
	}//cout<<'\n';
	
 	cout<<(anss-1)<<'\n';
return 0;
}

Measured memory_bytes: 10496
// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}

const int N = 110;
int K , T , a[N];

int main(){
  cin >> K >> T;
  rep(i,0,T) cin >> a[i];
  int mx = *max_element(a,a+T);
  cout << max(0 , mx - ((K - mx) + 1))<< endl;
  return 0;
}


Measured memory_bytes: 256
import sys
def input():
    return sys.stdin.readline()[:-1]

S = list(input())
S.append('R')

ans = []

R_count = 0
L_count = 0
before = 'R'

for R_L in S:
    if before == 'L' and R_L == 'R':
        ans.extend([0]*(R_count-1))
        total = R_count + L_count
        if total % 2 == 0:
            ans.extend([int(total/2), int(total/2)])
        elif total % 2 == 1:
            if R_count % 2 == 1:
                ans.extend([int(total/2) + 1, int(total/2)])
            else:
                ans.extend([int(total/2), int(total/2) + 1])
        ans.extend([0]*(L_count-1))
        R_count = 0
        L_count = 0
    if R_L == 'R':
        R_count += 1
        before = 'R'
    elif R_L == 'L':
        L_count += 1
        before = 'L'

print(*ans)

Measured memory_bytes: 7116
#include<stdio.h>
int main(void){
    double s,a,b;
    int c;
    scanf("%lf",&a);
    scanf("%lf",&b);
    c=(a+b)/2;
    s = (a+b)/2;
    if(s-c==0){
        printf("%3d",c);
    }else{
        c=c+1;
        printf("%3d",c);
    }
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <cmath>
#include <climits>
#include <string>
#include <queue>
#include <vector>
#include <set>
#include <unordered_map>
using namespace std;

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

  int count = 0;
  for (int i = A; i <= B; i++) {
    if (i / 10000 == i % 10) {
      int j = (i - 10000 * (i / 10000)) / 10;
      if (j / 100 == j % 10) {
        count++;
      }
    }
  }
  cout << count << endl;
}


Measured memory_bytes: 256
n = int(input())
a = [int(i) for i in input().split()]
ball = [0]*n
ans = []

for i in range(n,0,-1):
    cnt = 0
    x = i
    while x <= n:
        if ball[x-1] == 1:
            cnt += 1
        x += i
    if cnt%2 != a[i-1]:
        ball[i-1] = 1
        ans.append(i)

m = len(ans)
print(m)
if m != 0:
    for b in ans:
        print(b,end=" ")
    else:
        print("")


Measured memory_bytes: 12088
#include<stdio.h>
int main(void)
{
  int N,M,i,j,k,money_sum=0,count=0,sa,tmp;
  scanf("%d %d",&N,&M);
  int A[M],B[M],Money[M];
  for(i=0;i<M;i++)
  {
    scanf("%d %d",&A[i],&B[i]);
    sa=B[i]-A[i];
    if(sa>1) Money[i]=sa/2;
    else if(sa==1) Money[i]=1;
    else Money[i]=0;
  }
//  for(i=0;i<M;i++) printf("%d ",Money[i]);
//  printf("\n");

  for(i=0;i<M;i++)
  {
    for(j=M-1;j>i;j--)
    {
      if(Money[j]<Money[j-1])
      {
        tmp=Money[j];
        Money[j]=Money[j-1];
        Money[j-1]=tmp;
      }
    }
  }
//  for(i=0;i<M;i++) printf("%d ",Money[i]);
//  printf("\n");
  for(i=0;i<M-1;i++) money_sum+=Money[i];
  printf("%d\n",money_sum);
  return 0;
}



Measured memory_bytes: 2100
package main

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

var stdin = initStdin()

func initStdin() *bufio.Scanner {
	var stdin = bufio.NewScanner(os.Stdin)
	stdin.Split(bufio.ScanWords)
	return stdin
}

func nextString() string {
	stdin.Scan()
	return stdin.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(nextString())
	return i
}

func nextInt64() int64 {
	i, _ := strconv.ParseInt(nextString(), 10, 64)

	return i
}

type pair struct {
	k int
	s []int
	p int
}

func refbit(i int, b uint) int {
	return (i >> b) & 1
}

func main() {
	N := nextInt()
	M := nextInt()

	lights := []pair{}

	// 初期化
	for i := 0; i < M; i++ {
		k := nextInt()
		lights = append(lights, pair{k, []int{}, 0})

		for j := 0; j < k; j++ {
			lights[i].s = append(lights[i].s, nextInt())
		}
	}
	for i := 0; i < M; i++ {
		lights[i].p = nextInt()
	}

	var c int
	// fmt.Println(lights)

	states := int(math.Pow(float64(2), float64(N)))
next:
	for n := 0; n < states; n++ {
		// fmt.Printf("%08b\n", n)
		for i := 0; i < M; i++ {
			ons := 0
			for j := 0; j < lights[i].k; j++ {
				ons += refbit(n, uint(lights[i].s[j]-1))
			}
			// fmt.Printf("%d[%d] ons = %d\n", n, i, ons)
			if ons%2 != lights[i].p {
				// fmt.Printf("%dで違反\n", i)
				continue next
			}
		}
		c++
	}

	fmt.Println(c)
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define FOR(i,a,b) for (register int i=(a);i<=(b);i++)
#define For(i,a,b) for (register int i=(a);i>=(b);i--)
#define mem(i,j) memset(i,j,sizeof(i))
#define GO(u) for (register int j=f[u];j!=-1;j=nxt[j])
#define fi first
#define se second
#define pii pair<int,int>
#define MP make_pair
#define pb push_back
using namespace std;
typedef long long ll;
const int N=2020;
int n,a[N],vis[N],cnt=0,ans[N],du[N];
vector<int> vec[N],G[N];
priority_queue <pii> q;
inline int read()
{
	int x=0,f=1;
	char c=getchar();
	while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
	while (c>='0'&&c<='9') {x=(x<<1)+(x<<3)+c-'0';c=getchar();}
	return f*x;
}
inline void write(int x)
{
	if (x<0) putchar('-'),x=-x;
	if (x>9) write(x/10);
	putchar(x%10+'0');
	return;
}
inline int GCD(int x,int y)
{
	if (!y) return x;
	if (x<y) return GCD(y,x);
	return GCD(y,x%y);
}
inline void dfs(int u)
{
	vis[u]=1;
	FOR(i,0,(int)vec[u].size()-1)
	{
		int v=vec[u][i];
		if (vis[v]) continue;
		G[u].pb(v);
		du[v]++;
		dfs(v);
	}
	return;
}
bool cmp(const int x,const int y) {return a[x]<a[y];}
int main()
{
	n=read();
	FOR(i,1,n) a[i]=read();
	sort(a+1,a+n+1);
	FOR(i,1,n) FOR(j,1,n) if (i!=j) if (GCD(a[i],a[j])>1) vec[i].pb(j);
	FOR(i,1,n) sort(vec[i].begin(),vec[i].end());
	FOR(i,1,n) if (!vis[i])
	{
		dfs(i);
		q.push(MP(a[i],i));
	}
	while (q.size())
	{
		pii tmp=q.top();
		q.pop();
		ans[++ans[0]]=tmp.fi;
		FOR(i,0,(int)G[tmp.se].size()-1)
		{
			int v=G[tmp.se][i];
			du[v]--;
			if (!du[v]) q.push(MP(a[v],v));
		}
	}
	FOR(i,1,n) write(ans[i]),putchar(' ');
	return 0;
}

Measured memory_bytes: 16000
use std::io;
use std::cmp;

// read a line(without line feed)
fn read_line() -> String {
    let mut in_str = String::new();
    io::stdin().read_line(&mut in_str).unwrap();
    return in_str.trim().to_string();
}

// read wods on a line
pub fn read_words_in_line() -> Vec<String> {
    let s = read_line();
    return s.split_whitespace().map(|x| x.to_string()).collect::<Vec<String>>()
}

// read type t on a line
pub fn read_t_in_line<T : std::str::FromStr>() -> Vec<T> {
    let mut v : Vec<T> = Vec::new();
    for e in read_words_in_line().iter().map(|x| x.parse::<T>()) {
        if let Ok(r) = e {
            v.push(r);
        }
        else{
            return Vec::new();
        }
    }
    return v;
}

// sort slice
pub fn sort<T : std::cmp::Ord>(slice : &mut [T]) {
    slice.sort();
}
// sort slice by reverse order
pub fn sort_rev<T : std::cmp::Ord>(slice : &mut [T]) {
    slice.sort_by(|x, y| y.cmp(x));
}

pub fn min<T : std::cmp::Ord>(a : T, b : T) -> T{
    return cmp::min(a, b);
}

pub fn max<T : std::cmp::Ord>(a : T, b : T) -> T{
    return cmp::max(a, b);
}

fn main() {

    let a = read_t_in_line::<i32>()[0];
    let b = read_t_in_line::<i32>()[0];
    let c = read_t_in_line::<i32>()[0];
    let d = read_t_in_line::<i32>()[0];

    println!("{}", cmp::min(a, b) + cmp::min(c, d));
    
}


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

int N;
int h[1000];

bool isAllZero(){
  for (int i = 0; i < N; i++) {
    if ( h[i]!=0 ) return false;
  }
  return true;
}

int countGroups(){  
  int before = 0;
  int count = 0;
  for (int i = 0; i < N; i++) {
    if ( h[i]!=0 && before==0) count++;
    before = h[i];
  }
  return count;
}

void decrementH(){
  for (int i = 0; i < N; i++) {
    if(h[i]!=0) h[i]--;
  }
}

int main(){
  cin >> N;
  
  for (int i = 0; i < N; i++) {
    cin >> h[i];
  }
  
  int i = 0;
  while(!isAllZero()){
    int groups = countGroups();
    i += groups;
    
    decrementH();
  }
  cout << i << endl;
  
  return 0;
}

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

int main(){
  string s;
  cin >> s;
  int l=0;
  int r=s.size()-1;
  int ans=0;
  while(true){
    if(l>r){
      break;
    }
    if(s.at(l)==s.at(r)){
      l++;
      r--;
    }else if(s.at(l)=='x'){
      ans++;
      l++;
    }else if(s.at(r)=='x'){
      ans++;
      r--;
    }else{
      cout << -1 << endl;
      return 0;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 512
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include <numeric>
#include<queue>
#include <sstream>
#include<string.h>
#include<math.h>
using namespace std;
int prime[1000005];
bool is_prime[1000005];
int seve(int n)
{
    int p=0;
    for(int i=0;i<=n;i++)
        is_prime[i]=true;
    is_prime[0]=is_prime[1]=false;
    for(int i=2;i<=n;i++)
    {
        if(is_prime[i])
        {
            prime[p++]=i;
            for(int j=2*i;j<=n;j+=i)
                is_prime[j]=false;
        }
    }
    return p;
}
int main(void)
{
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        printf("%d\n",seve(n));
    }
    return 0;
}



Measured memory_bytes: 4480
import java.util.*;
import java.io.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
import static java.lang.Math.*;

public class Main {

	int INF = 1 << 28;
	//long INF = 1L << 62;
	double EPS = 1e-10;

	void run() {
		Scanner sc = new Scanner(System.in);
		int[][] dp = new int[4001][5];
		dp[0][0] = 1;
		for(int i=1;i<=4;i++) for(int j=0;j<=4000;j++) for(int k=0;k<=1000;k++) 
			if(j+k<=4000) dp[j+k][i] += dp[j][i-1];
		for(;sc.hasNext();) {
			System.out.println(dp[sc.nextInt()][4]);
		}
	}

	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}

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

Measured memory_bytes: 19408
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    h, w, a, b = map(int, readline().split())
    grid = [["0"] * w for _ in range(h)]

    for row in range(h):
        for col in range(w):
            c = 0
            if row < b:
                c ^= 1
            if col < a:
                c ^= 1
            grid[row][col] = str(c)

    for i in range(h):
        print("".join(grid[i]))


if __name__ == '__main__':
    main()


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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, K;
  cin >> N >> K;
  int maxn = (N - 1) * (N - 2) / 2;
  if (K > maxn)
    cout << -1 << '\n';
  else {
    vector<pair<int, int>> res;
    for (int i = 1; i <= N - 1; i++) {
      res.emplace_back(i, N);
    }
    int diff = maxn - K;
    int pl = 1, pr = 2;
    for (int i = 0; i < diff; i++) {
      res.emplace_back(pl, pr);

      pr++;
      if (pr == N) {
        pl++;
        pr = pl + 1;
      }
    }
    cout << res.size() << '\n';
    for (auto r : res) {
      cout << r.first << " " << r.second << '\n';
    }
  }
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define REP(i,n) for(int i=0;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<29
#define LINF LLONG_MAX/3
#define MP make_pair
#define PB push_back
#define pb push_back
#define EB emplace_back
#define ALL(v) (v).begin(),(v).end()
#define all(v) ALL(v)
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
constexpr double eps = 1e-14; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

int P,Q,R;

int add(int a,int b){
    if(a==0) return b;
    if(a==1) return (b==2? 2 : 1);
    if(a==2) return 2;
}

int mul(int a,int b){
    if(a==0) return 0;
    if(a==1) return (b==0?0:1);
    if(a==2) return b;
}

int formula(string& s){
    //cout << "formula : " << s << endl;
    string tmp = s;
    if('0'<=s[0] and s[0]<='2'){
        int ret = s[0]-'0';
        s = s.substr(1);
        //cout << tmp  << "  before return:" << s << endl;
        return ret;
    }else if(s[0]=='-'){
        s = s.substr(1);
        int v=formula(s);
        //cout << tmp  << "  before return:" << s << endl;
        return 2-v;
    }else if(s[0]=='('){
        s = s.substr(1);
        //cout << "2 operator(1)= " << s << endl;
        int v1 = formula(s);
        char com = s[0];
        s = s.substr(1);
        //cout << "2 operator(2)= " << s << endl;
        int v2 = formula(s);
        s = s.substr(1);
        //cout << tmp  << "  before return:" << s << endl;
        if(com=='+') return add(v1,v2);
        if(com=='*') return mul(v1,v2);
        assert(false);
    }else{
        //cout << "error:" << s << endl;
        assert(false);
    }
}

void solve(string s){
    //cout << "----- " << s << " -----" << endl;
    int ans=0;

    for(P=0;P<=2;P++) for(Q=0;Q<=2;Q++) for(R=0;R<=2;R++){
        string tmp = s;
        for(int i=0;i<sz(tmp);i++){
            if(tmp[i]=='P') tmp[i]=P+'0';
            if(tmp[i]=='Q') tmp[i]=Q+'0';
            if(tmp[i]=='R') tmp[i]=R+'0';
        }
//        cout << P << " " << Q << " " << R << endl;
        int val = formula(tmp);
        //cout << "val=" << val << endl;
        if(val==2) ans++;
    }
    cout << ans << endl;
}

int main(){
    string s;
    while(cin>>s){
        if(s==".") break;
        solve(s);
    }
}

Measured memory_bytes: 3084
#include "bits/stdc++.h"

using namespace std;

int main() {
    int n,m;
    while(cin>>n>>m,n){
        vector<vector<int>>g(n*m,vector<int>(n*m,0));
        for(int i=0;i<m;++i){
            for(int j=0;j<n-1;++j){
                int a;cin>>a;
                if(a)continue;
                g[i*n+j][i*n+j+1]=1;
                g[i*n+j+1][i*n+j]=1;
            }
            if(i==m-1)break;
            for(int j=0;j<n;++j){
                int a;cin>>a;
                if(a)continue;
                g[i*n+j][(i+1)*n+j]=1;
                g[(i+1)*n+j][i*n+j]=1;
            }
        }//ok
        queue<int>q;
        vector<int>memo(n*m,0);
        q.push(0);
        memo[0]=1;
        while(!q.empty()){
            int u=q.front();q.pop();
            if(u+1<n*m){
                if(g[u][u+1]){
                    if(memo[u+1]==0){
                        q.push(u+1);
                        memo[u+1]=memo[u]+1;
                    }
                }
            }
            if(u+n<n*m){
                if(g[u][u+n]){
                    if(memo[u+n]==0){
                        q.push(u+n);
                        memo[u+n]=memo[u]+1;
                    }
                }
            }
            if(u-1>=0){
                if(g[u][u-1]){
                    if(memo[u-1]==0){
                        q.push(u-1);
                        memo[u-1]=memo[u]+1;
                    }
                }
            }
            if(u-n>=0){
                if(g[u][u-n]){
                    if(memo[u-n]==0){
                        q.push(u-n);
                        memo[u-n]=memo[u]+1;
                    }
                }
            }
        }
        cout<<memo[n*m-1]<<endl;
    }
}

Measured memory_bytes: 5976
#include <stdio.h>
#include <bits/stdc++.h>
#define pb push_back
#define pp pop_back
#define mp make_pair
#define f first
#define s second
#define all(x) x.begin(), x.end()
typedef long long ll;

using namespace std;

const int N = 3e5 + 111, inf = 1e9, mod = 1e9 + 7;
const ll INF = 1e18;
const double pi = acos(-1.0), eps = 1e-9;

int n, x, cnt, a[N];

int main(){
	srand(time(NULL));
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(0);
	cout << setprecision(10) << fixed;

	cin >> n >> x;

	for(int i = 1; i <= n; ++i)
		cin >> a[i];

	sort(a + 1, a + n + 1);

	for(int i = 1; i <= n; ++i)
		if(a[i] <= x){
			x -= a[i];
			cnt++;
		}else{
			break;
		}
	
	if(cnt == n && x){
		cout << n - 1;
		return 0;
	}
	cout << cnt;

	//cout << (clock() + 0.0) / CLOCKS_PER_SEC;
}

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

template< typename T >
T extgcd(T a, T b, T &x, T &y) {
  T d = a;
  if (b != 0) {
    d = extgcd(b, a % b, y, x);
    y -= (a / b) * x;
  } else {
    x = 1; y = 0;
  }
  return d;
}

// mを法としたときのaのモジュラ逆元を求める
template< typename T >
T mod_inverse(T a, T m) {
  T x, y;
  extgcd(a, m, x, y);
  return (m+x%m) % m;
}

// return nCk % mod
template< typename T >
T mod_comb(T n, T k, T mod) {
  T mul = 1, div = 1;
  for (T i = 0; i < k; i++) {
    mul *= (n-i);
    mul %= mod;
    div *= (i+1);
    div %= mod;
  }
  return mul * mod_inverse(div, mod) % mod;
}
const long long MOD=1000000007;
int main(){
  long long x,y;
  cin>>x>>y;
  if((x+y)%3!=0){
    cout<<0<<endl;
    return(0);
  }
  long long times=(x+y)/3;
  long long a=0;
  while(!(a+2*(times-a)==x&&2*a+(times-a)==y)&&a<=times){
    a++;
  }
  if(a<0||times-a<0){
    cout<<0<<endl;
  }else{
    cout<<mod_comb(times,a,MOD)<<endl;
  }
  return(0);
}
  

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

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    long h, n;
    cin >> h >> n;
    while (n--) {
        long x;
        cin >> x;
        h -= x;
    }
    cout << (h <= 0 ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<cstdio>
#include<queue>
#include<cmath>
#include<algorithm>
using namespace std;
int main()
{
    int a,b;
    int n;
    scanf("%d%d",&a,&b);

   n=(a-1)/(b*2+1)+1;

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


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

int INF=1e9;

int n,m;
vector<pair<int,int>> v;

bool solve(int x){
    bool res=true;
    int d[60][60];
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            d[i][j]=INF;
            if(i==j)d[i][j]=1;
        }
    }
    for(int i=0;i<m;i++){
        if(i!=x){
            d[v[i].first][v[i].second]=1;
            d[v[i].second][v[i].first]=1;
        }
    }
    for(int k=0;k<n;k++){
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
            }
        }
    }
    for(int i=0;i<n;i++)if(d[0][i]==INF)res=false;
    
    return res;
    
}

int main(void){
    cin>>n>>m;
    v.resize(m);
    for(int i=0;i<m;i++){
        cin>>v[i].first>>v[i].second;
        v[i].first--;
        v[i].second--;
    }
    int ans=m;
    for(int i=0;i<m;i++){
        if(solve(i))ans--;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
class Main {
    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int[] a = new int[3];
	for(int i = 0; i<3; i++) {
	    a[i] = sc.nextInt();
	}
	Arrays.sort(a);
	long sum = 0;
	for(int i = 0; i<3; i++) {
	    if(i == 2) {
		int n = sc.nextInt();
		while(n>0) {
		    a[i] *= 2;
		    n--;
		}
	    }
	    sum += a[i];
	}
	System.out.println(sum);
    }
}

Measured memory_bytes: 21844
#include<iostream>
#include<fstream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<math.h>
#include<algorithm>
#include<iomanip>
#include<set>
#include<utility>

#define P 1000000007

using namespace std;

int main() {
  int w;
  cin >> w;
  string s1, s2;
  cin >> s1 >> s2;
  vector<int> a;
  map<char, bool> mp;
  for(int i = 0; i < w; i++) {
    if(mp[s1[i]]) continue;
    else {
      mp[s1[i]] = true;
      if(s2[i] == s1[i]) a.push_back(0);
      else a.push_back(1);
    }
  }
  int m = a.size();

  vector<long long> dp(m);
  if(a[0] == 0) dp[0] = 3;
  else dp[0] = 6;
  for(int i = 1; i < m; i++) {
    if(a[i] == 0) {
      if(a[i - 1] == 0) {
        dp[i] = (dp[i - 1] * 2) % P;
      } else {
        dp[i] = (dp[i - 1] * 1) % P;
      }
    } else {
      if(a[i - 1] == 0) {
        dp[i] = (dp[i - 1] * 2) % P;
      } else {
        dp[i] = (dp[i - 1] * 3) % P;
      }
    }
  }
  cout << dp[m - 1] << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define SORT(i) sort((i).begin(), (i).end())
#define INF 2000000000
constexpr ll mod = 1e9 + 7;
 
int main(){
    string s;
    cin >> s;
    int N = (int)s.size();
    int dp[N];
    dp[0] = 1;
    if(s[0] == s[1]){
        dp[1] = 1;
    }
    else {
        dp[1] = 2;
    }
    if(s[2] == s[1]){
        dp[2] = 2;
    }
    else {
        dp[2] = dp[1] + 1;
    }
    for (int i = 3; i < N;++i){
        if(s[i]==s[i-1]){
            dp[i] = dp[i - 3] + 2;
        }
        else {
            dp[i] = dp[i - 1] + 1;
        }
    }
    cout << dp[N - 1] << "\n";

    return 0;
}

Measured memory_bytes: 1284
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
struct edge{
  int u, v, d, c;
  edge(int u, int v, int d, int c) : 
    u(u), v(v), d(d), c(c) {}
  bool operator < (const edge& e) const {
    if(d != e.d) return d > e.d;
    else return c > e.c;
  }
};
typedef vector<edge> edges;

int main(){
  int N, M;
  while(cin>>N>>M && N){
    vector<edges> g(N);
    REP(i, M){
      int u, v, d, c;
      cin>>u>>v>>d>>c;
      u--, v--;
      g[u].push_back(edge(u, v, d, c));
      g[v].push_back(edge(v, u, d, c));
    }
    priority_queue<edge> que;
    int ans = 0;
    vector<bool> used(N);
    vector<int> mindist(N, INF);
    used[0] = true;
    FORIT(it, g[0]) que.push(*it);
    while(!que.empty()){
      edge e = que.top(); que.pop();
      if(used[e.v]) continue;
      //printf("edge(%d, %d, %d, %d)\n", e.u, e.v, e.d, e.c);
      ans += e.c;
      used[e.v] = true;
      FORIT(it, g[e.v])if(!used[it->v] && mindist[it->v] >= it->d + e.d) {
        que.push(edge(it->u, it->v, it->d + e.d, it->c));
        mindist[it->v] = it->d + e.d;
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}

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

using namespace std;

#define ll long long

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

	ll ans = 0;
	for (int i = 0; i < N + 1; i++) {
		ll sub = min(A[i], B[i]);
		B[i] -= sub;
		ans += sub;

		sub = min(B[i], A[i + 1]);
		A[i + 1] -= sub;
		ans += sub;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
/*
n以下でa,b,cがa+b,a+c,c+bがkの倍数->二倍はkの倍数になってるはず
二倍がkの倍数でもa+bがの倍数かは知らん
二倍がkの倍数になっている数字の集合を求める
2a = nk
kが奇数aはkの定数倍
k偶数
2a = nk
k/2の定数倍が候補
全部k/2はおっけい
*/
int main(void){
    long long n,k,val,ans;
    scanf("%lld %lld",&n,&k);
    if(k%2==1){
        val = n/k;
        if(val==1){
            printf("1\n");
        }else if(val == 2){ 
            printf("8\n");
        }else if(val == 0){
            printf("0\n");
        }else{
            ans = val*(val-1)*(val-2)+3*val*(val-1) + val;
            printf("%lld\n",ans);
        }
    }else{
        long long ans1,ans2;
        val = n/(k/2);
        long long val1,val2;
        if(val%2==1){
            val1 = val/2 + 1;
            val2 = val/2;
        }else{
            val1 = val/2;
            val2 = val/2;
        }
        if(val1==1){
            ans1 = 1;
        }else if(val1 == 2){ 
            ans1 = 8;
        }else if(val1 == 0){
            ans1 = 0;
        }
        else{
            ans1 = val1*(val1-1)*(val1-2)+3*val1*(val1-1) + val1;
        }
        if(val2==1){
            ans2 = 1;
        }else if(val2 == 2){ 
            ans2 = 8;
        }
        else if(val2 == 0){
            ans2 = 0;
        }
        else{
            ans2 = val2*(val2-1)*(val2-2)+3*val2*(val2-1) + val2;
        }
        printf("%lld\n",ans1+ans2);
    }

    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<numeric>
#include<math.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<climits>
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define ll long long
#define mkp make_pair
#define pll pair<ll,ll>
#define rep(i,from,to) for(int i=from;i<to;i++)
#define repd(i,from,till) for(int i=from;i>=till;i--)
#define waste ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define inf 1e9+1
#define mod 1e9+7
#define inf1 1e18+1
#define pie 3.14159265358979323846
#define N 100005
using namespace std;
/*
ll bin(ll i,ll j){
	ll mid=(i+j)/2;
	if(a[mid]==x)reutrn mid;
	else if(ans>x)return bin(i,mid-1);
	else return bin(mid+1,j);
}/*
ll power(ll base,ll power){
    ll res=1;
    base=base%mod;
    while(power>0){
    	if(power&1){
    		res=(res*base)%mod;
		}
		power=power>>1;
		base=(base*base)%mod;
	}
	return res;
}
*/
/*
int nCr(int x, int y){
	if(y>x)return 0;
	int num=fact[x];
	num*=invfact[y];
	num%=mod;
	num*=invfact[x-y];
	num%=mod;
	return num;
}
*/
/*bool prime[n+1];
void SieveOfEratosthenes(int n){
	rep(i,0,n+1)prime[i]=true
    for (int p=2;p*p<=n;p++)
        if (prime[p])
            for (int i=p*p;i<=n;i+=p)prime[i]=false;
}*/
/*
int gcd(int a,int b){
	if(b==0)return a;
	else return gcd(b,a%b);
}
*/
int solve(){
    int n;
    cin>>n;
	int a[n];
	rep(i,0,n)cin>>a[i];
	int b[n];
	rep(i,0,n)cin>>b[i];
	int c[n-1];
	rep(i,0,n-1)cin>>c[i];
	int sum=0;
	rep(i,0,n){
		sum+=b[a[i]-1];
		if(i!=0&&a[i-1]==a[i]-1)sum+=c[a[i-1]-1];
	}
	cout<<sum<<endl;
	return 0;
}
int main(){
    waste;
    int t;
    //cin>>t;
    t=1;
    while(t--){
       	solve();
    }
}


Measured memory_bytes: 256
N = int(input())
S = input()
n = S.count('.')
ans = min(n, N-n)
lsc = 0
rsc = N-n
for i, c in enumerate(S):
    if c == '#':
        lsc += 1
        rsc -= 1
    a = lsc + ((N-i-1) - rsc)
    ans = min(ans, a)

print(ans)


Measured memory_bytes: 9396
#include<cstdio>
const int mod=1000000007;
int N,X,Y,Z,f[41][1<<17|1],g[1<<17|1][11];
int main(){
	scanf("%d%d%d%d",&N,&X,&Y,&Z);
	Y+=X;Z+=Y;
	for(int s=1;s<=1<<Z;s++){
		for(int x=1;x<=10;x++){
			g[s][x]=1;
			for(int i=0;i<Z&&i+x<=Z;i++)if(s>>i&1){
				if(!(i<X&&i+x>X)&&!(i<Y&&i+x>Y))g[s][x]|=1<<i+x;
			}
			if(s==1<<Z||g[s][x]>=1<<Z)g[s][x]=1<<Z;
		}
	}
	f[0][1]=1;
	for(int i=0;i<N;i++)
		for(int j=1<<Z;j;j--)
			for(int x=1;x<=10;x++)(f[i+1][g[j][x]]+=f[i][j])%=mod;
	printf("%d\n",f[N][1<<Z]);
}

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

using namespace std;
using LL = long long;
using P = pair<int, int>;

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

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e19;
const int MOD = 1e9 + 7;

int f(char s)
{
    return (int)(s - '0');
}

signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string s;
    cin >> s;
    bool flag1 = false, flag2 = false;
    if(f(s[0]) == 0 && f(s[1]) > 0) flag1 = true;
    if(f(s[0]) == 1 && f(s[1]) <= 2) flag1 = true;
    if(f(s[2]) == 0 && f(s[3]) > 0) flag2 = true;
    if(f(s[2]) == 1 && f(s[3]) <= 2) flag2 = true;

    if(flag1 && flag2) cout << "AMBIGUOUS" << endl;
    else if(flag1) cout << "MMYY" << endl;
    else if(flag2) cout << "YYMM" << endl;
    else cout << "NA" << endl;
}

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

using namespace std;

bool pairCompare(const std::pair<double, string>& firstElem, const std::pair<double, string>& secondElem) {
    if(firstElem.first != secondElem.first) return firstElem.first > secondElem.first;
    else return firstElem.second < secondElem.second;
}

int main(){
    int n;
    while(cin >> n, n){
        vector<pair<double, string> > ret;
        for(int q=0; q < n; q++){
                string l;
                double p, a, b, c, d, e, f, s, m;
                cin >> l >> p >> a >> b >> c >> d >> e >> f >> s >> m;
                double time = a + b + c + d + e;
                double amount = f;
                for(int i=0; i< m-1; i++){time += d+e; amount += f;}
                double cost = s*amount-p;
                ret.push_back(make_pair(cost/time, l));
        }
        sort(ret.begin(), ret.end(), pairCompare);
        for(int i=0; i< ret.size(); i++) cout << ret[i].second << endl;
        cout << "#" << endl;
    }
}

Measured memory_bytes: 1252
#include<iostream>
using namespace std;
int main() {
    string s; cin >> s;
    int n = (int)s.size() - 1; //+を入れる間の箇所の数
    int a[n + 1];
    for (int i = 0; i < n + 1; ++i) {
        a[i] = s[i] - '0';
    }
    long long ans = 0;
    for (int i = 0; i < (1 << n); ++i) { //組み合わせ
        long long t = a[0]; //初期値 演算しない限りint入れて大丈夫
        for (int j = 0; j < n; ++j) { //iのjビット目が立っているか
            if (i & (1 << j)) { //立ってたら
                ans += t; //前のindex足す
                t = a[1 + j]; //次のに移動
                //ビット立ってないの来ない限り1桁の足し算
            } else {
                t = t * 10 + a[1 + j]; //1桁目にa[1 + j]
            }
        }
        ans += t;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll par[100001],n,m,a[100001],b[100001],siz[100001];
void init(ll n)
{
    for (ll i=0;i<n;++i)
	{
        par[i]=i;
        siz[i]=1;
    }
}
ll find(ll x)
{
    if (par[x]==x) return x;
    return par[x]=find(par[x]);
}
void unite(ll x, ll y)
{
    x=find(x);
    y=find(y);
    if (x==y) return;
    if (siz[x]<siz[y])
	{
        par[x]=y;
        siz[y]+=siz[x];
    }
	else
	{
        par[y]=x;
        siz[x]+=siz[y];
    }
}
bool same(ll x, ll y)
{
    return find(x)==find(y);
}
ll size(ll x)
{
    return siz[find(x)];
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
    cin>>n>>m;
    for (int i=0;i<m;++i) cin>>a[i]>>b[i],--a[i],--b[i];
    init(n);
    ll rets[100010];
    rets[m]=n*(n-1)/2;
    for (int i=m-1;i>=0;--i)
	{
        if (same(a[i],b[i])) rets[i]=rets[i+1];
        else rets[i]=rets[i+1]-size(a[i])*size(b[i]);
        unite(a[i],b[i]);
    }
    for (int i=1;i<=m;++i) cout<<rets[i]<<endl;
    return 0;
}

Measured memory_bytes: 5248
#include<stdio.h>
#include<string.h>
void haichi(void);
void Block(int,int);
int c,d,x,y,xg,yg,M,Flag;
int MAP[102][102],MF[102][102];
int main(void)
{
	int w,h,xs,ys,n;
	while(1){
		Flag=0;
		memset(MAP,0,sizeof(MAP));
		memset(MF,0,sizeof(MF));
		scanf("%d %d",&w,&h);
		if(w == 0 && h == 0) break;
		scanf("%d %d %d %d",&xs,&ys,&xg,&yg);
		scanf("%d",&n);
		for(int i=0;i<n;i++){
			scanf("%d %d %d %d",&c,&d,&x,&y);
			haichi();
		}
		/*for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				printf("%d",MAP[i][j]);
			}
			printf("\n");
		}*/
		M = MAP[ys][xs];//
		if(MAP[ys][xs] == MAP[yg][xg])
			Block(xs,ys);
		if(Flag==1)
			printf("OK\n");
		else
			printf("NG\n");
	}
	return 0;
}

void haichi(void)
{
	if(d==0){
		MAP[y][x]=c;MAP[y][x+1]=c;MAP[y][x+2]=c;MAP[y][x+3]=c;
		MAP[y+1][x]=c;MAP[y+1][x+1]=c;MAP[y+1][x+2]=c;MAP[y+1][x+3]=c;
	}
	else if(d==1){
		MAP[y][x]=c;MAP[y][x+1]=c;
		MAP[y+1][x]=c;MAP[y+1][x+1]=c;
		MAP[y+2][x]=c;MAP[y+2][x+1]=c;
		MAP[y+3][x]=c;MAP[y+3][x+1]=c;
	}
}

void Block(int X,int Y)
{
	MF[Y][X] = 1;
	//printf("%d",M);
	if(X == xg && Y == yg)
		Flag = 1;
	if(Y>0 && X>0){
		if(MAP[Y-1][X] == M && MF[Y-1][X] == 0){
			Block(X,Y-1); //???
			//MF[Y][X-1]=0;
		}
		if(MAP[Y+1][X] == M && MF[Y+1][X] == 0){
			Block(X,Y+1); //???
			//MF[Y+1][X]=0;
		}
		if(MAP[Y][X-1] == M && MF[Y][X-1] == 0){
			Block(X-1,Y); //???
			//MF[Y][X-1]=0;
		}
		if(MAP[Y][X+1] == M && MF[Y][X+1] == 0){
			Block(X+1,Y); //???
			//MF[Y][X-1]=0;
		}
	}
}

Measured memory_bytes: 2676
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};
int main(){
  int n,m;
  cin >> n >> m;
  UnionFind tree(n);
  rep(i,m){
    int a,b,c;
    cin >> a >> b >> c;
    tree.unite(a-1,b-1);
  }
  int cnt=0;
  rep(i,n){
    if(tree.root(i)==i)cnt++;
  }
  cout << cnt << endl;
}


Measured memory_bytes: 896
A, B = [int(i) for i in raw_input().split()]


def func(n, m):
	return int((n + 1) / (2 ** m)) * 2 ** (m - 1) + max(0, (n + 1) % (2 ** m) - 2 ** (m - 1))

print sum((func(B, i) - func(A-1, i)) % 2 * 2 ** (i - 1) for i in range(1, 64))


Measured memory_bytes: 2568
def gcd(a,b):
    if not b: return a
    return gcd(b,a%b)

def lcm(a, b):
    return (a*b)//gcd(a, b)

N = int(input())
A = list(map(int,input().split()))
l = 1
ans, mod = 0, 1000000007

for x in A:
    l = lcm(l, x)

for x in A:
    ans = ans + l//x
print(ans % mod)


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

int main () {
  string s, t = "CODEFESTIVAL2016";
  cin >> s;
  
  int count = 0;
  for (int i = 0; i < 16; i++) {
    if (s.at(i) != t.at(i)) {
      count ++;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> inline bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;

int main() {
    int x;
    cin >> x;
    int ans = 0;
    int now = 0;
    while(now < x) {
        ans++;
        now += ans;
    }
    cout << ans << endl;
}

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

int main() {
    string s;
    cin >> s;
    int n = s.size();
    sort(begin(s), end(s));
    auto itr = unique(begin(s), end(s));
    cout << (n == distance(begin(s), itr) ? "yes" : "no") << endl;
}


Measured memory_bytes: 256