akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
//#define cerr if (false) cerr
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define dbv(v) cerr << #v << "="; for (auto _x : v) cerr << _x << ", "; cerr << endl
#define dba(a, n) cerr << #a << "="; for (int _i = 0; _i < (n); ++_i) cerr << a[_i] << ", "; cerr << endl
template <typename A, typename B>
ostream& operator<<(ostream& os, const pair<A, B>& x) {
	return os << "(" << x.first << "," << x.second << ")";
}
typedef long long ll;
typedef long double ld;
char S[1000005], T[1000005];
int main() {
	int n;
	scanf("%d%s%s", &n, S, T);
	int las = n;
	vector<int> A = {n}, B = {n - 1};
	for (int i = n - 1; i >= 0; --i) {
		if (!i || T[i - 1] != T[i]) {
			if (i) B.push_back(i - 1);
			bool found = false;
			for (int j = min(las - 1, i); j >= 0; --j) {
				if (S[j] == T[i]) {
					las = j;
					for (; S[j] == S[j + 1]; ++j);
					A.push_back(j);
					found = true;
					break;
				}
			}
			if (!found) {
				printf("-1\n");
				return 0;
			}
		}
	}
	assert(A.size() == B.size() + 1);
	reverse(A.begin(), A.end());
	reverse(B.begin(), B.end());
	int ans = 0;
	int m = A.size();
	for (int i = 0; i + 1 < m; ++i) {
		int lo = 0, hi = m - 1 - i;
		while (lo < hi) {
			int j = (lo + hi) >> 1;
			if (A[i + j] - j >= B[i]) hi = j;
			else lo = j + 1;
		}
		assert(A[i + lo] - lo >= B[i]);
		ans = max(ans, lo);
	}
	printf("%d\n", ans);
}


Measured memory_bytes: 13300
#include <iostream>
using namespace std;
int main(void){
    int b1,b2,b3;
    cin>>b1>>b2>>b3;
    if(b1==1&&b2==0&&b3==0){
        cout<<"Close"<<endl;
    }
    if(b1==0&&b2==1&&b3==0){
        cout<<"Close"<<endl;
    }
    if(b1==1&&b2==1&&b3==0){
        cout<<"Open"<<endl;
    }
    if(b1==0&&b2==0&&b3==1){
        cout<<"Open"<<endl;
    }
    if(b1==0&&b2==0&&b3==0){
        cout<<"Close"<<endl;
    }
}


Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N,M;
  cin>>N>>M;
  int WA[N+1];
  int AC[N+1];
  for(int i=1;i<N+1;i++){
    WA[i]=0;
    AC[i]=0;
  }
  
  int NUM;
  string S;
  for(int i=1;i<M+1;i++){
    cin>>NUM>>S;
    
    if(S=="AC"){
      AC[NUM]=1;
    }
    if((S=="WA")&&(AC[NUM]==0)){
      WA[NUM]++;
    }
  }
  int count=0;
  int total=0;
  for(int i=1;i<N+1;i++){
    if(AC[i]==1){
      count++;
    }
  }
  for(int i=1;i<N+1;i++){
    if(AC[i]==1){
      total=total+WA[i];
    }
  }
  
  
  cout<<count<<" "<<total<<endl;
  
}

           

Measured memory_bytes: 1152
/*
ex5_3
TKC001
*/

#include<stdio.h>
#define SIDE 101
int main(void){
    char mat[SIDE][SIDE],row_mat[SIDE][SIDE], out_mat[SIDE][SIDE];
    /* mat:入力の行列
   row_mat:行を切った行列
   out_mat:さらに列を切った出力の行列
   */
    int row, column, delete=1, memo_row=0, memo_column=0;

    //H, Wの入力
    scanf("%d%d", &row, &column);

    for (int i = 0; i < row; i++)
    {   //色の入力
        scanf("%s", mat[i]);
    }

    for (int i = 0; i < row; i++)//行について黒があるかどうか調べる
    {
        for (int j = 0; j < column; j++)
        {
            if (mat[i][j]=='#')
            {
                delete = 0;//行のどこかに黒があったら消さない
            }
            
        }
        if (delete==0)//行を消さないとき
        {
            
            for (int j = 0; j < column; j++)
            {
                row_mat[memo_row][j] = mat[i][j];
            }
            memo_row +=1;
                                    
        }
        delete = 1;       
    }

    for (int j = 0; j < column; j++)//列について黒があるかどうか調べる
    {
        for (int i = 0; i < memo_row; i++)
        {
            if(row_mat[i][j]=='#'){
                delete = 0;
            }
        }
        if (delete==0)//列を消さないとき
        {
            for (int i = 0; i < memo_row; i++)
            {
                out_mat[i][memo_column] = row_mat[i][j];
            }
            memo_column +=1; 
        }
        delete = 1;
    }
    for(int i = 0; i < memo_row; i++)
    {
        for(int j = 0; j < memo_column; j++){
            //出力
            printf("%c", out_mat[i][j]);
        }
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b;
	cin>>a>>b;
	if(a>b)
	{
		for(int i=0;i<a;i++)
		{
			cout<<b;
		}
	}
	if(a<b)
	{
		for(int i=0;i<b;i++)
		{
			cout<<a;
		}
	}
	if(a==b)
		{	for(int i=0;i<b;i++)
		{
			cout<<a;
		}
	}
	return 0;
}


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

#define SZ(x) (((int)x.size()))
#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef long double ld;

using namespace std;

const int maxn = 200*1000+10;
int n, a[maxn], x;

int main()
{
	cin >> n;
	for (int i = 0; i < n - 1; i++)
	{
		cin >> x;
		x--;
		a[x]++;
	}
	for (int i = 0; i < n; i++)
		cout << a[i] << endl;
	return 0;
}


Measured memory_bytes: 4416
// Zhupengfei 2018
// This program / source file is in public domain.

// Solution for problem: arc101C

#include <bits/stdc++.h>

// Common definitions
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define repd(i, a, b) for (int i = (b); i >= (a); i--)
#if __cplusplus >= 201103L
#define foreach(it, container) for (it : (container))
#else
#define foreach(it, container)                                                                     \
    for (typeof((container).begin()) it = (container).begin(); it != (container).end(); ++it)
#endif
#define forever for (;;)

// Debug use
#ifdef LOCAL
#define dbg_out(x) cout << (x) << endl
#else
#define dbg_out(x)
#endif

// IO stream extensions
template <typename T>
std::ostream& operator<<(std::ostream& out, const std::vector<T>& v) {
    if (!v.empty()) {
        std::copy(v.begin(), v.end(), std::ostream_iterator<T>(out, " "));
    }
    return out;
}
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& out, const std::pair<T1, T2>& pa) {
    out << pa.first << " " << pa.second;
    return out;
}
template <typename T>
std::istream& operator>>(std::istream& is, std::vector<T>& v) {
    v.clear();
    size_t siz;
    is >> siz;
    v.reserve(siz);
    T value;
    for (size_t i = 0; i < siz; i++) {
        is >> value;
        v.push_back(value);
    }
    return is;
}
template <typename T1, typename T2>
std::istream& operator>>(std::istream& is, std::pair<T1, T2>& pa) {
    is >> pa.first >> pa.second;
    return is;
}

// Typedefs
#define Pair(typename) std::pair<typename, typename>
#define Vec(typename) std::vector<typename>
#define Arr(typename, count) std::array<typename, count>
#define Vec3(typename) Arr(typename, 3)
typedef long long int s64;
typedef unsigned long long int u64;
typedef signed char s8;
typedef unsigned char u8;
typedef long double ld;

// STL bullshit
// When really want to use, should add std::
#define next nextaerawer
#define prev prevawerawer
#define size sizewaeriwor
#define data dataaeraewra
#define hash hashdesrawer
#define move moveaerawer
#define x0 x0aerawerwe
#define x1 x1aesraewrew
#define y0 y0aeroiawera
#define y1 y1oiiajeroawe
#define left lefteaeraewr
#define right righteaerawer

using namespace std;

// Main segment

int x[100001] = {};

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

    int n, k;
    cin >> n >> k;
    for (int i = 1; i <= n; i++) {
        cin >> x[i];
    }
    int ans = 1e9;
    for (int i = 1; i <= n - k + 1; i++) {
        ans =
            min(ans, min(abs(x[i]) + x[i + k - 1] - x[i], abs(x[i + k - 1]) + x[i + k - 1] - x[i]));
    }
    cout << ans << endl;

#ifdef LOCAL
    system("pause");
#endif
    return 0;
}


Measured memory_bytes: 640
h,w = map(int,input().split())
a = [list(input()) for i in range(h)]
hl = [0] * h
wl = [0] * w
for i in range(h):
    if '#' in a[i]:
        hl[i] = 1
        for j in range(w):
            if a[i][j] == '#':
                wl[j] = 1

for i in range(h):
    t = []
    for j in range(w):
        if  hl[i] == 1 and wl[j] == 1:
            t.append(a[i][j])
    if len(t) != 0:
        print(''.join(t))  

Measured memory_bytes: 9240
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    string S;
    cin >> S;
    int leg = S.size();
    int win = 0;
    for (int i = 0; i < leg; i++) {
        if (S[i] == 'o') {
            win++;
        }
    }
    if (15 - leg >= 8 - win) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}


Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, char const *argv[]) {
  int a,b;
  char op;

  scanf("%d %c %d",&a, &op, &b );

  if(op == '+'){
    printf("%d\n",a + b );
  }else{
    printf("%d\n",a - b );
  }
  return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<math.h>
using namespace std;

int main()
{
	string s = "", arr[7] = {"SAT", "SUN", "MON", "TUE", "WED", "THU", "FRI" };
	int daysCount = 0, i = 0;
	cin >> s;
	bool startCounting = false, passedIter1 = false;
	while(true)
	{
		if (arr[i] == "SUN" && passedIter1)
		{
			break;
		}
		else if(s == arr[i])
		{
			startCounting = true;
		}
		if (startCounting)
		{
			daysCount++;
			passedIter1 = true;
		}	
		i++;
		if (i == 7)
		{
			i = 0;
		}
		
	}
	cout << daysCount << endl;
	//system("pause");
	return 0;
}

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

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

    cout << 6 - a - b << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String args[]){

        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();

        int array[][] = new int[n][2];

        for (int i=0; i<n; i++){
            array[i][0] = sc.nextInt();
            array[i][1] = sc.nextInt();
        }

        Arrays.sort(array, new Comparator<int[]>() {
            @Override
            public int compare(int[] o1, int[] o2) {
                return Integer.compare(o1[1], o2[1]);
            }
        });

//        System.out.println(array[0][0]);
//        System.out.println(array[0][1]);
//        System.out.println(array[1][0]);
//        System.out.println(array[2][0]);
//        System.out.println(array[3][0]);
//        System.out.println(array[4][0]);

        int sum=0;
        for (int i=0; i<n; i++){
            sum += array[i][0];
            if (array[i][1]<sum){
                System.out.println("No");
                return;
            }
        }
        System.out.println("Yes");
    }
}


Measured memory_bytes: 108528
// #include <bits/stdc++.h>
#include<climits>
#include<cmath>
#include<cstdio>
#include<deque>
#include<map>
#include<set>
#include<vector>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<numeric>
#include<string>
#include<tuple>
#include<queue>
using namespace std;
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
#define BEGIN ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define END return EXIT_SUCCESS
#define rep(I,N) for(auto I=0;I<(N);++I)
#define up(I,A,B) for(auto I=(A);I<=(B);++I)
#define dw(I,A,B) for(auto I=(A);I>=(B);--I)
#define all(C) (C).begin(),(C).end()
#define rall(C) (C).rbegin(),(C).rend()
#define ft first
#define sd second
#define mp make_pair
#define mt make_tuple
#define pf push_front
#define pb push_back
#define pt pop_front
#define pk pop_back
#define lb lower_bound
#define ub upper_bound
#define rs resize
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<class T>inline void                                      in(T &p){cin>>p;}
template<class T1,class T2>inline void                            in(T1 &p1,T2 &p2){cin>>p1>>p2;}
template<class T1,class T2,class T3>inline void                   in(T1 &p1,T2 &p2,T3 &p3){cin>>p1>>p2>>p3;}
template<class T1,class T2,class T3,class T4>inline void          in(T1 &p1,T2 &p2,T3 &p3,T4 &p4){cin>>p1>>p2>>p3>>p4;}
template<class T1,class T2,class T3,class T4,class T5>inline void in(T1 &p1,T2 &p2,T3 &p3,T4 &p4,T5 &p5){cin>>p1>>p2>>p3>>p4>>p5;}
template<class T>inline void                             out(T p){cout<<p<<endl;}
template<class T1,class T2>inline void                   out(T1 p1,T2 p2){cout<<p1<<" "<<p2<<endl;}
template<class T1,class T2,class T3>inline void          out(T1 p1,T2 p2,T3 p3){cout<<p1<<" "<<p2<<" "<<p3<<endl;}
template<class T1,class T2,class T3,class T4>inline void out(T1 p1,T2 p2,T3 p3,T4 p4){cout<<p1<<" "<<p2<<" "<<p3<<" "<<p4<<endl;}
long N,P;
string S;
vector<pair<pair<string,long>,long>>v;
inline void solve(void){
  in(N);
  rep(i,N){
    in(S,P);
    v.pb(mp(mp(S,-P),i+1));
  }
  sort(all(v));
  for(auto e:v)out(e.sd);
}
int main(int argc,char**argv){
  BEGIN;
  solve();
  END;
}


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

using namespace std;
#define ll long long

#define rep(i, a) for (int (i) = 0; (i) < (int) (a); (i)++)
#define reps(i, a, b) for (int (i) = (int) (a); (i) < (int) (b); (i)++)
#define rrep(i, a) for (int (i) = (int) a-1; (i) >= 0; (i)--)
#define rreps(i, a, b) for (int (i) = (int) (a)-1; (i) >= (int) (b); (i)--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define TRUE__ "Possible"
#define FALSE__ "Impossible"
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x

#ifdef LOCAL
	#define lcout(a) cout << a;
	#define lcoutln(a) cout << a << endl;
	#define lcerr(a) cerr << a;
	#define lcerrln(a) cerr << a << endl;
#else
	#define lcout(a) 
	#define lcoutln(a) 
	#define lcerr(a) 
	#define lcerrln(a) 
#endif

int main()
{
	CIN(int, a);
	CIN(int, b);
	PRINT(a%3==0 || b%3==0 || (a+b)%3==0);
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);
		long input1 = scanner.nextLong();
		long input2 = scanner.nextLong();

		long gcd = gcd(input1, input2);
		int count = 1;

		for (long i=2; i<=Math.sqrt(gcd); i++) {
			if (gcd % i == 0) {
				gcd /= i;
				count++;
			}
			while(gcd % i == 0) gcd /= i;
		}

		if (gcd > 1) count++;

		System.out.println(count);
	}

    static long gcd(long a, long b) {
        long max = Math.max(a, b);
        long min = Math.min(a, b);

        long re = max % min;
        if (re == 0)
            return min;
        return gcd(min, re);
    }
}

Measured memory_bytes: 21716
# Inputs
r, c = list(map(int, input().split()))
ori_t = []
for i in range(r):
    ori_t.append(list(map(int, input().split())))

# row sum
for a in range(r):
    ori_t[a].append(sum(ori_t[a]))

# column sum
ori_t.append([0 for x in range(c+1)])

for b in range(c):
    c_sum = 0
    for a in range(r):
        c_sum += ori_t[a][b]
    ori_t[r][b] = c_sum

# cross sum
ori_t[r][c] = sum(ori_t[r])

# output
for num in ori_t:
    print(*num)


Measured memory_bytes: 6232
import Data.IntMap ((!))
import qualified Data.IntMap.Strict as M
import qualified Data.ByteString.Char8 as B
import Data.List
import Data.Maybe
import Control.Applicative

untilFix f x = if f x == x then x else untilFix f (f x)

main = do
 [n,q] <- map read . words <$> getLine
 cxys <- map ((\[c,x,y]->(c,(x,y))) . map (fst . fromJust . B.readInt) . B.words) . B.lines <$> B.getContents
 mapM_ print (uft n q cxys)

uft :: Int -> Int -> [(Int,(Int,Int))] -> [Int]
uft n q = reverse . fst . foldl' process ([],(M.fromDistinctAscList (zip [0..n-1] [0..])))

process (lg,m) (c,(x,y))
 | c==0 = (lg, M.insert (max x y) v1 (M.insert v2 v1 m))
 | c==1 = ((if v1==v2 then 1 else 0) : lg, m)
 where
  v1 = untilFix (m!) (min x y)
  v2 = untilFix (m!) (max x y)

Measured memory_bytes: 67660
#include<iostream>
#include<cstdio>
#include<math.h>
using namespace std;
int main()
{
	int n;
	cin >> n;
	int a[200005];
	int b[200005];
	for(int i=1;i<=n;i++){
		cin >> a[i] ;
	}
	b[0]=0x3f3f3f3f;
	b[1]=a[1] ;
	for(int i=2;i<=n;i++){
		if(a[i]<b[i-1])  b[i]=a[i] ;
		else b[i]=b[i-1] ;
	}	
	int f=0;
	for(int i=1;i<=n;i++) {
		if(a[i]<b[i-1]) f++;
	}
	cout << f<<endl;
	return 0;
}


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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)
#define mp make_pair

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int32 n;
    cin >> n;
    vector<int32> x;
    REP(i,n){
        int32 a;
        cin >> a;
        auto itr = upper_bound(ALL(x), a, greater<int32>());
        if(itr == x.end()){
            x.pb(a);
        }else{
            *itr = a;
        }
    }
    cout << x.size() << endl;
    return 0;
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T &a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U &u,const V... v){for(auto &e:u)fill_v<T>(e,v...);}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, m;
    cin >> n >> m;
    vector<bool> ok(n, false);
    vector<int> penalty(n);
    int ac = 0,  wa = 0;
    rep(i, m) {
        int a;
        string s;
        cin >> a >> s;
        a--;
        if (s == "AC") {
            if (!ok[a]) {
                ok[a] = true;
                wa += penalty[a];
                ac++;
            }
        } else {
            if (!ok[a]) {
                penalty[a]++;
            }
        }
    }
    cout << ac << " " << wa << endl;
}


Measured memory_bytes: 3708
#include<iostream>
using namespace std;
int main(){
  int N,K,x[100];
  cin>>N>>K;
  for(int i=0;i<N;i++){cin>>x[i];}
  int ans=0;
  for(int i=0;i<N;i++){
    if(K-x[i]<x[i]){ans+=K-x[i];}
    else{ans+=x[i];}
  }
  cout<<ans*2;
  
  
  
  
  return 0;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
V = list(map(int, input().split()))


def dfs(left, right, k):
    if left > right:
        return 0
    if k == 0:
        return 0
    if (left, right, k) in memo:
        return memo[(left, right, k)]

    l1 = V[left] + dfs(left + 1, right, k - 1)
    l2 = dfs(left + 1, right, k - 2) if k >= 2 else 0
    r1 = V[right] + dfs(left, right - 1, k - 1)
    r2 = dfs(left, right - 1, k - 2) if k >= 2 else 0
    memo[(left, right, k)] = max([l1, l2, r1, r2, 0])
    return memo[(left, right, k)]


memo = {}
print(dfs(0, n-1, k))


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

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

	if (k % 2 == 0) cout << pow(k / 2, 2) << endl;
	else cout << (k / 2) * (k / 2 + 1) << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;
constexpr int mod = 1e9+7;

int main(){
  string s;
  cin >> s;
  int n = s.size();
  vector<vector<int>> dp(n+1, vector<int>(2, 0));
  dp[0][0] = 1;

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

    if (s[i] == '0') {
      dp[i + 1][0] = dp[i][0];
      dp[i + 1][1] = dp[i][1];
    } else {
      dp[i + 1][1] = (dp[i][0] + dp[i][1]) % mod;
    }
    if (s[i] == '0') {
      (dp[i + 1][1] += dp[i][1] * 2 % mod) %= mod;
    } else {
      (dp[i + 1][0] += dp[i][0] * 2 % mod) %= mod;
      (dp[i + 1][1] += dp[i][1] * 2 % mod) %= mod;
    }
  }
  cout << (dp[n][0] + dp[n][1]) % mod << endl;
  return 0;
}

Measured memory_bytes: 5760
N = gets.to_i
P = readlines.map {|s| s.split.map(&:to_i) }

def calc(x1,y1,x2,y2)
  Math.sqrt((x1-x2)**2+(y1-y2)**2)
end

n = 0
pt = [*0...N].permutation
pt.each do |a|
  a.each_cons(2) {|i,j| n += calc(*P[i],*P[j]) }
end
puts n / pt.size

Measured memory_bytes: 2300
#define _CRT_SECURE_NO_WARNINGS
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma comment(linker, "/stack:200000000")
#include <bits/stdc++.h>
#define rep(i, a, b) for (long long i = a; i <= b; ++i)
#define mp make_pair
#define ll long long
#define SIZE 1005
using namespace std;
void io() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); }
ll k;
set<string> st;
int main() {
	io(); cin >> k;
	queue<string> q;
	rep(i, 1, 9) q.push(to_string(i));
	vector<ll> vec;
	while (st.size() <= 2e5) {
		string top = q.front();
		q.pop();
		st.insert(top);
		if (top.back() != '9' && top.back() != '0') {
			char ch = top.back(); --ch;
			q.push(top + ch);
			q.push(top + top.back());
			ch += 2;
			q.push(top + ch);
		}
		else if (top.back() == '0') {
			char ch = top.back(); ++ch;
			q.push(top + top.back());
			q.push(top + ch);
		}
		else {
			char ch = top.back(); --ch;
			q.push(top + ch);
			q.push(top + top.back());
		}
	}
	for (auto i : st) {
		//cout << i << '\n';
		//ll num = stoi(i);
		vec.emplace_back((ll)stoll(i));
	}
	sort(vec.begin(), vec.end());
	//for (auto i : vec) cout << i << '\n';
	cout << vec[k - 1];
}

Measured memory_bytes: 51064
#include<iostream>
#include<string>
#include<regex>

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

using namespace std;

int main()
{
    int n;
    string s;
    cin >> n >> s;
    int a[n];
    rep(i,n){
        if(s[i] == 'R') a[i] = 0;
        if(s[i] == 'G') a[i] = 1;
        if(s[i] == 'B') a[i] = 2;
    }
    long long b[3] = {0};
    rep(i,n){
        b[a[i]]++;
    }
    long long ans = 1;
    rep(i,3) ans *= b[i];

    rep(j,n) rep(i,j){
        int k = j+(j-i);
        if(k < n){
            if(a[i] == a[j]) continue;
            if(a[i] == a[k]) continue;
            if(a[j] == a[k]) continue;
            ans--;
        }
    }
    cout << ans << endl;
    
    cout << endl;
    return 0;
}

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

const unsigned long long MOD = 1000000007;

int main(){
    unsigned long long N;
    cin >> N;
    unsigned long long ans = 1;
    for (unsigned long long i = 1; i <= N; i++) {
        ans *= i;
        if (MOD < ans) {
            ans %= MOD;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int T[5]={2,0,1,0,2};
int n,a[200005],c[3][200005];
LL dp[200005][5];
int main(){
	int i,j,k;
	scanf("%d",&n);
	for(i=0;i<n;++i){
		scanf("%d",a+i);
		if(!a[i]){
			c[1][i]=1;
			c[0][i]=2;
		}
		else if(a[i]&1){
			c[1][i]=0;
			c[0][i]=1;
		}
		else{
			c[1][i]=1;
			c[0][i]=0;
		}
		c[2][i]=a[i];
		for(j=0;j<5;++j){
			dp[i][j]=1000000000000000000ll;
		}
	}
	for(i=0;i<5;++i) dp[0][i]=(LL)c[T[i]][0];
	LL res=1000000000000000000ll;
	for(i=1;i<n;++i){
		for(j=0;j<5;++j){
			for(k=0;k<=j;++k){
				dp[i][j]=min(dp[i][j],dp[i-1][k]+(LL)c[T[j]][i]);
			}
		}
	}
	for(j=0;j<5;++j) res=min(res,dp[n-1][j]);
	printf("%lld\n",res);
	return 0;
}

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

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

    if ( r == "A" )
    {
        cout << "T" << endl;
    }
    else if ( r == "C" )
    {
        cout << "G" << endl;
    }
    else if ( r == "T" )
    {
        cout << "A" << endl;
    }
    else if ( r == "G" )
    {
        cout << "C" << endl;
    }
}


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

#define ft first
#define sd second
#define sz(x) ((int)x.size())

using namespace std;

typedef pair<int, int> ball;

const int MAXN = 200 * 1000 + 23, D = 1000 * 1000 * 1000 + 7;




struct tom {
    int a = -1, b = -1;
    ball q = {-1, INT_MAX}, w = {-1, INT_MAX};
    void add(int x, ball y) {
        if (y.sd < q.sd) {
            if (y.ft != q.ft)
                b = a, w = q;
            a = x, q = y;
        }
        else if (y.ft != q.ft && y.sd < w.sd)
            b = x, w = y;
    }
    int get(ball y) {
        if (q.ft != y.ft)
            return a;
        return b;
    }
} f;

int inv(int x) {
    int ret = 1, y = D - 2;
    for (; y; y >>= 1, x = 1ll * x * x % D)
        if (y & 1)
            ret = 1ll * ret * x % D;
    return ret;
}

int n, x, y, z[MAXN], zz, fact[MAXN], ans = 1, cnt[MAXN], ivf[MAXN];
ball b[MAXN];
vector<int> g[MAXN];
bitset<MAXN> mark;
vector<int> vec;

int dfs(int);

int main() {
    cin >> n >> x >> y;
    fact[0] = 1;
    for (int i = 1; i < MAXN; i++)
        fact[i] = 1ll * fact[i - 1] * i % D;
    ivf[MAXN - 1] = inv(fact[MAXN - 1]);
    for (int i = MAXN - 2; ~i; i--)
        ivf[i] = 1ll * ivf[i + 1] * (i + 1) % D;
    memset(z, -1, sizeof z);
    for (int i = 0; i < n; i++) {
        int c, w;
        cin >> c >> w;
        b[i] = {--c, w};
        f.add(i, {c, w});
        if (z[c] == -1 || w < b[z[c]].sd)
            z[c] = i;
    }
    for (int i = 0; i < n; i++)
        if (i != z[b[i].ft] && b[i].sd + b[z[b[i].ft]].sd <= x)
            g[i].push_back(z[b[i].ft]), g[z[b[i].ft]].push_back(i);
        else if (i == z[b[i].ft] && i != f.a && b[i].sd + b[f.a].sd <= y)
            g[i].push_back(f.a), g[f.a].push_back(i);
    for (int i = 0; i < n; i++)
        if (g[i].empty() && ~f.get(b[i]) && b[f.get(b[i])].sd + b[i].sd <= y)
            g[i].push_back(f.get(b[i])), g[f.get(b[i])].push_back(i);
    for (int i = 0; i < n; i++)
        if (!mark[i]) {
            vec.clear();
            ans = 1ll * ans * fact[dfs(i)] % D;
            for (auto i : vec)
                ans = 1ll * ans * ivf[cnt[i]] % D, cnt[i] = 0;
        }
    cout << ans;
    return 0;
}
int dfs(int v) {
    int ret = 1;
    cnt[b[v].ft]++;
    vec.push_back(b[v].ft);
    mark[v] = true;
    for (auto u : g[v])
        if (!mark[u])
            ret += dfs(u);
    return ret;
}

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

int main(void){
	int n;
	int a[5000];
	while(cin>>n,n){
		for(int i=0;i<n;i++)cin>>a[i];
		int sum=0;
		int m=a[0];
		for(int i=0;i<n;i++){
			sum+=a[i];
			m=max(m,sum);
			sum= sum>=0 ? sum : 0;
		}
		cout<<m<<endl;
	}
	return 0;
}

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

const int MOD = 1000000007;

int main() {
  long long a, b, c, d;
  cin >> a >> b >> c >> d;

  long long pair1_max = max(a, b);
  long long pair2_max = max(c, d);
  long long pair1_min = min(a, b);
  long long pair2_min = min(c, d);
  
  long long ans = -1000000000000000000;

  ans = max(ans, pair1_max * pair2_max);
  ans = max(ans, pair1_max * pair2_min);
  ans = max(ans, pair1_min * pair2_max);
  ans = max(ans, pair1_min * pair2_min);
  
  cout << ans << endl;
}

Measured memory_bytes: 3628
#include "bits/stdc++.h"
using namespace std;
const int MAX = 700000;
const int MOD = 1000000007;

long long  fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y){
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}
/*逆元計算*/
long long int  modinv(long long a, long long m) {
	long long int b = m, u = 1, v = 0;
	while (b) {
		long long int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
// index が条件を満たすかどうか
vector<long long int >meguru;
bool isOK(int index, int key) {
	if (meguru[index] >= key) return true;
	else return false;
}
// 汎用的な二分探索のテンプレ
int binary_search(int key) {
	int left = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
	int right = (int)meguru.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()
	/* どんな二分探索でもここの書き方を変えずにできる！ */
	while (right - left > 1) {
		int mid = left + (right - left) / 2;

		if (isOK(mid, key)) right = mid;
		else left = mid;
	}
	/* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている */
	return right;
}
int main() {
	map<long long int, long long int>s;
	long long int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		long long int a;
		cin >> a;
		s[a]++;
		if (s[a] == 2) {
			cout << "NO";
			return 0;
		}
	}
	cout << "YES";
}


Measured memory_bytes: 12800
#include<iostream>
#include <cmath>
#include <algorithm>
using namespace std;
int main(void){
    int x;
    while(cin>>x){
        int ma=1;
        for(int i=2;i<=x;i++){
            int sum=i;
            while(sum<=x){
                sum*=i;
                if(sum<=x)
                    ma=max(sum,ma);
            }
        }
        cout<<ma<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	ll n;
	cin>>n;
	vector<ll> a(5);
	ll mi=inf,ind;
	rep(i,5){
		cin>>a[i];
		if(chmin(mi,a[i])){
			ind=i;
		}
	}
	ll ans=ind+(4-ind)+(n+mi-1)/mi;
	cout<<ans<<endl;
}

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

typedef long long ll;
const int MAXN = 2010;

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

int n;
ll x, a[MAXN], Min[MAXN][MAXN];
ll ans;

inline ll query(int l, int r) {
	if(r > n) 
		return min(query(l, n), query(1, r-n));
	return Min[l][r];
}

int main() {
	n = read<int>();
	x = read<ll>();
	for(int i = 1; i <= n; i++) {
		a[i] = read<ll>();
		ans += a[i];
	}
	for(int i = 1; i <= n; i++) {
		Min[i][i] = a[i];
		for(int j = i+1; j <= n; j++) 
			Min[i][j] = min(Min[i][j-1], a[j]);
	}

	for(int j = 1; j < n; j++) {
		ll res = 0;
		for(int i = 1; i <= n; i++) {
			int l = i, r = l+j;
			res += query(l, r);
		}
		ans = min(ans, res+j*x);
	}
	printf("%lld\n", ans);
	return 0;
}


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

using namespace std;


int main(){
  
  long n;
  cin >>n;
  
  vector<long> a(n),b(n);
  for(int i=0;i<n;i++) cin >> a[i];
  for(int i=0;i<n;i++) cin >> b[i];
  
  long sum=0;
  priority_queue<long> que;
  long res=0;
  for(int i=0;i<n;i++){
   if(b[i]>a[i]) {
     sum+=b[i]-a[i];
    res++;
   }
     else {
       que.push(a[i]-b[i]);
     }
  }
  
  if(sum==0) {
    cout << 0 << endl;
    return 0;
  }
  
  while(!que.empty()&&sum>0){
    long c=que.top();
     que.pop();
    sum-=c;
    res++;
    }
  
  if(sum>0) {
    cout << -1 << endl;
    return 0;
  }
  
  cout << res << endl;
  
}

Measured memory_bytes: 2936
using static System.Console;
using System.Linq;
class Program
{
    static void Main(string[] args)
    {
        var n = int.Parse(ReadLine());
        var s = ReadLine();
        var x = 0;
        var max = 0;
        foreach(var c in s)
        {
            if (c == 'I') x++;
            else x--;
            if (max < x) max = x;
        }
        WriteLine(max);
    }
}

Measured memory_bytes: 2648
s=list(input())
t=list(input())
dp=[[0]*(3030) for j in range(3030)]

for i in range(len(s)):
    for j in range(len(t)):
        if s[i]==t[j]:
             dp[i+1][j+1] = dp[i][j]+1


        else:
            dp[i+1][j+1] =max(dp[i][j+1],dp[i+1][j])

#print(dp[len(s)][len(t)])
answer=[]
i,j=len(s),len(t)
d=dp[i-1][j-1]
while i>=0 and j>=0:

    if dp[i-1][j]==dp[i][j]:
        i-=1
    elif dp[i][j-1]==dp[i][j]:
        j-=1
    else:
        answer.append(s[i - 1])
        i -= 1
        j -= 1
print("".join(reversed(answer)))

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

#define FOR(i,l,r) for(int i = (int) (l);i < (int) (r);i++)
#define ALL(x) x.begin(),x.end()
template<typename T> bool chmax(T& a,const T& b){ return a < b ? (a = b,true) : false; }
template<typename T> bool chmin(T& a,const T& b){ return b < a ? (a = b,true) : false; }
typedef long long ll;

int N,M;
int bit [300002];

void add(int idx,int val)
{
	for(;idx <= M;idx += idx & -idx) bit [idx] += val;
}

int sum(int idx)
{
	int res = 0;
	for(;idx;idx -= idx & -idx) res += bit [idx];
	return res;
}

bool comp(const pair<int,int>& a,const pair<int,int>& b)
{
	return a.second - a.first < b.second - b.first;
}

int main()
{
	scanf("%d%d",&N,&M);
	vector< pair<int,int> > A(N);
	FOR(i,0,N){
		scanf("%d%d",&A [i].first,&A [i].second);
	}
	sort(ALL(A),comp);

	vector<int> ans(M + 1);
	int idx = 0;
	FOR(i,1,M + 1){
		while(idx < N && A [idx].second - A [idx].first + 1 < i){
			add(A [idx].first,1);
			add(A [idx].second + 1,-1);
			idx++;
		}
		ans [i] = N - idx;
		for(int j = i;j <= M;j += i){
			ans [i] += sum(j);
		}
		printf("%d\n",ans [i]);
	}

	return 0;
}


Measured memory_bytes: 4096
#include<bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
typedef long long ll;
#define pb push_back
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}
const double PI=acos(-1);

void solve(){
    int h, w; cin >> h >> w;
    vector<string> A;
    REP(i, h){
        string s;
        cin >> s;
        A.pb(s);
    }

    vector<vector<int>> B(h, vector<int>(w, 0));

    REP(i, h){
        REP(j, w){
            if(A[i][j] == '#'){
                if(i>0 && j>0) B[i-1][j-1]++;
                if(j-1>-1) B[i][j-1]++;
                if(i+1<h && j>0) B[i+1][j-1]++;
                if(i+1<h) B[i+1][j]++;
                if(i+1<h && j+1<w) B[i+1][j+1]++;
                if(j+1<w) B[i][j+1]++;
                if(i>0 && j+1<w) B[i-1][j+1]++;
                if(i>0) B[i-1][j]++;
            }
        }
    }

    REP(i, h){
        REP(j, w){
            if(A[i][j] != '#') cout << B[i][j];
            else cout << '#';
        }
        cout << endl;
    }
}

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

Measured memory_bytes: 256
from collections import deque

H, W = map(int, input().split())
X = [input() for _ in range(H)]


def solve_maze(s):
    bias = [(0, 1), (0, -1), (1, 0), (-1, 0)]
    inf = 10 ** 9

    d = [[inf] * W for _ in range(H)]
    d[s[0]][s[1]] = 0

    q = deque()
    q.append(s)
    while q:
        u, v = q.popleft()
        for i, j in bias:
            if (0 <= u + i < H and 0 <= v + j < W
                    and X[u + i][v + j] == "."
                    and d[u + i][v + j] > d[u][v] + 1):
                d[u + i][v + j] = d[u][v] + 1
                q.append((u + i, v + j))

    res = 0
    for i in range(H):
        for j in range(W):
            if d[i][j] < inf:
                res = max(res, d[i][j])
                
    return res


ans = 0
for i in range(H):
    for j in range(W):
        if X[i][j] == ".":
            ans = max(ans, solve_maze((i, j)))

print(ans)


Measured memory_bytes: 75120
#include <stdio.h>
#include <cmath>
#include <bits/stdc++.h>



using namespace std;

typedef vector<int> VI;
typedef vector<string> VS;


//container util
#define SORT(c) sort((c).begin(),(c).end())

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



int main(void){

	int N; cin >> N;
	if(N < 1000) cout << "ABC" << endl;
	else cout << "ABD" << endl;
	

	return 0;

}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		
		char[] s = scan.next().toCharArray();
		scan.close();
		 
		int[] digit = new int[s.length];
		int[] remainder = new int[s.length];//i桁までの数字を2019で割った余りは何かを保存する
		int[] num = new int[2019];//余りがiである数字の数
		int[] ppp = new int[s.length];
		num[0]++;
		for(int i = 0; i < digit.length; i++) {
			digit[i] = s[digit.length-1-i] - '0';//charをintに変換
			
			if(i == 0) {
				ppp[i] = 1;
				remainder[i] = digit[i] % 2019;
			}else {
				ppp[i] = 10*ppp[i-1] % 2019;
				remainder[i] = (ppp[i]*digit[i]+remainder[i-1]) % 2019;
			}
			
			num[remainder[i]]++;
		}
		
		int ans = 0;
		for(int i = 0; i < 2019; i++)
			ans += num[i]*(num[i]-1)/2;
		
		System.out.println(ans);
	}
}


Measured memory_bytes: 43048
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    int a[] = new int[M];
    int b[] = new int[M];
    for(int i=0;i<M;i++){
      a[i]=sc.nextInt();
      b[i]=sc.nextInt();
    }
    int ans[] = new int[N];
    for(int i=0;i<M;i++){
      ans[a[i]-1]++;
      ans[b[i]-1]++;
    }
    for(int i=0;i<N;i++){
      System.out.println(ans[i]);
    }
  }
  

  
}

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

int main() {
  int N;
  int B[110];
  cin >> N;
  for (int i = 0; i < N - 1; i++) cin >> B[i];

  int ans = 0;

  for (int i = N - 2; i > 0; i--) {
    ans += min(B[i], B[i - 1]);
  }
  ans += B[0];
  ans += B[N - 2];
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
A = int(input())
B = int(input())
C = int(input())
X = int(input())
count = 0
for i1 in range(A+1):
    for i2 in range(B+1):
        for i3 in range(C+1):
            if (i1*500 + i2*100 + i3 *50) == X:
                count += 1
print(count)

Measured memory_bytes: 3060
/*Author SHUBH AGRAWAL  */

#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define pu push  //  adds the value to the last of the queue 
#define lld long long int
#define ins insert /// used in set to insert the values 
#define adv advance  /// used to increment the iterator
#define mp make_pair
#define fi first
#define se second
#define all(c) c.begin(),c.end()
#define PI 3.1415926
#define INF (lld)1e18
#define vl  vector<long long int >
#define vpl vector< pair<lld ,lld> >
#define vvl vector<vector<lld> > 
#define pll pair <lld,lld>
long long int modp(lld a,lld p,lld n)
{
    int d[100];
    int i,j,k,l;
    if(n==0) return 1;
    for(i=0;n>=1;i++)
    {
        d[i]=n%2;
        n/=2;
    }
    l=i;
    long long int e=1;
    if(d[0]==1) e*=(a%p);
    for(i=1;i<l;i++)
    {
        a*=a;
        a=a%p;
        if(d[i]==1) 
        {
            e*=a;
            e=e%p;
        }
    }
    return e%p;
}
lld modInverse(lld n, lld p) 
{ 
    return modp(n, p, p-2); 
}

long long int nCrModPFermat(lld n, lld r,lld p) 
{ 
   // Base case 
   if (r==0) 
      return 1; 
    
    // Fill factorial array so that we 
    // can find all factorial of r, n 
    // and n-r 
    
    lld fac[n+1]; 
    fac[0] = 1; 
    for (lld i=1 ; i<=n; i++) 
    fac[i] = fac[i-1]*i%p; 
     
    return (fac[n]* modInverse(fac[r], p) % p * 
            modInverse(fac[n-r], p) % p) % p; 
}


long long int gcd(lld b,lld a)
{
    if(a<b) return gcd(a,b);
    if(a%b==0) return b;
    return gcd(a%b , b);
}

lld p1=1000000007,p2=998244353;
lld l,r,mid,ans;
lld n,m,i,j,k;
lld x,y,n1,a,b,n2,h,z,c;
queue<lld> q;
lld d,p=1000000000;
vector< vector <lld > > v(100001);

void bfs(lld x , vector<lld>& d)
{
    d[x]=0;
    q.pu(x);
    while(!q.empty())
    {
        x=q.front();
        q.pop();
        l=v[x].size();
        for(i=0;i<l;i++)
        {
            y=v[x][i];
            if(d[y]==INF) 
            {
                d[y] = d[x]+1;
                q.pu(y);
            }       
        }
    }

}
/*
lld DFS(lld a ,lld x)
{
    visited[a] =true;
    sub_size[a]=1;
 //   if(a==x) 
   //     cont[a] =true;
    lld l= v[a].size();
    for(lld i=0;i<l;i++)
    {
        if(visited[v[a][i]] == false)
        {
            sub_size[a]+= DFS(v[a][i],b);
//            if(cont[v[a][i]] ==true ) cont[a]=true;
        }
    }
    return sub_size[a];

}
*/

void solve()
{
     cin>>n;
     float p=3.14159;
     cout<<2*p*n;
     
}



int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    lld t=1;
//    cin>>t;
    for(int i=0;i<t;i++)
    {
    //    cout<<"Case #"<<i+1<<": ";
        solve();
        cout<<"\n";
    }

    return 0;
}


Measured memory_bytes: 5436
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;

int solve(const vector<int>& a)
{
    int w = a.size();
    int ret = 0;

    for(int i=0; i<w; ++i){
        vector<int> b = a;
        int tmp = 0;

        for(int x=0; x<i; ++x){
            if(b[x] == 1)
                ++ tmp;
            b[x+1] ^= 1;
        }
        for(int x=w-1; x>i; --x){
            if(b[x] == 1)
                ++ tmp;
            b[x-1] ^= 1;
        }
        if(b[i] == 1)
            ++ tmp;

        ret = max(ret, tmp);
    }

    return ret;
}

int main()
{
    int h, w;
    cin >> h >> w;

    vector<vector<int> > a(h, vector<int>(w));
    for(int y=0; y<h; ++y){
        for(int x=0; x<w; ++x){
            cin >> a[y][x];
            if(y > 0)
                a[y][x] ^= 1;
        }
    }

    int ret = 0;
    for(int y=0; y<h; ++y)
        ret += solve(a[y]);
    cout << ret << endl;

    return 0;
}

Measured memory_bytes: 1260
#include <bits/stdc++.h>
#define GET_REP(_1, _2, _3, NAME, ...) NAME
#define rep(...) GET_REP(__VA_ARGS__, irep, _rep)(__VA_ARGS__)
#define rep1(...) GET_REP(__VA_ARGS__, irep1, _rep1)(__VA_ARGS__)
#define _rep(i, n) irep (i, 0, n)
#define _rep1(i, n) irep1(i, 1, n)
#define irep(i, a, n) for (int i = a; i < (int)(n); ++i)
#define irep1(i, a, n) for (int i = a; i <= (int)(n); ++i)
#define rrep(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define rrep1(i, n) for (int i = (int)(n); i >= 1; --i)
#define allrep(X, x) for (auto &&X : x)
#define all(x) begin(x), end(x)
#define debug(x) cout << #x " => " << (x) << endl
#ifdef LOCAL
  #include "../../Lib/cout_container.hpp"
#endif
using lint = long long;
constexpr int MOD = (int)1e9 + 7;
constexpr double EPS = 1e-9;
using namespace std;
namespace { struct INIT { INIT() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } } INIT; }

int main(void) {
  int n, k, r, s, p;
  cin >> n >> k >> r >> s >> p;
  string t;
  cin >> t;
  vector<vector<vector<int>>> dp(n / k + 2, vector<vector<int>>(k, vector<int>(3)));
  vector<int> point{r, s, p};
  rep (i, k) {
    for (int j = 1, idx = i; idx < n; ++j, idx += k) {
      rep (now, 3) {
        rep (prev, 3) {
          if (now == prev) continue;
          int tmp = dp[j - 1][i][prev];
          if ((now == 0 && t[idx] == 's') || (now == 1 && t[idx] == 'p') || (now == 2 && t[idx] == 'r')) tmp += point[now];
          dp[j][i][now] = max(dp[j][i][now], tmp);
        }
      }
    }
  }
  int sum = 0;
  rep (i, k) {
    sum += *max_element(all(dp[ceil((n - i) / (double)k)][i]));
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 19664
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<functional>
#include<vector>
#include<stack>
#include<queue>
#include<iostream>
using namespace std;
int main(void)
{
	ios::sync_with_stdio(false);
    string str;
    getline(cin, str);
    for(int i=0;i<str.size();i++){
        if(str.substr(i, 5)=="apple")
            str.replace(i,5,"peach");
        else if(str.substr(i,5)=="peach")
            str.replace(i,5,"apple");
    }
    cout<<str<<endl;
    return 0;
}
 

Measured memory_bytes: 1188
open Batteries
module EnumL = Enum.Labels
module ListL = List.Labels
module ArrayL = Array.Labels

let dbg0 x = Printf.eprintf "[debug]%s\n" @@ dump x
let dbg1 x = dbg0 x; x

let id = identity

let (++) n m = List.range n `To m
let (++-) n m = if n >= m then List.range n `Downto m else []
let (++^) n m = if n < m then List.range n `To (pred m) else []

module ModOp = struct
  let prime = 1_000_000_007
  let (-) a b = (a + prime - b) mod prime
  let (+) a b = (a + b) mod prime
  let ( * ) a b = (a * b) mod prime

  let rec pow x n =
    if n = 0 then 1
    else if n mod 2 = 0 then pow (x*x) (n/2)
    else x * pow (x*x) (n/2)
end

let scan fmt = Scanf.sscanf (read_line ()) fmt

let scan_lines n fmt f =
  if n = 0 then []
  else List.map (fun _ -> scan fmt f) (1 ++ n)

let scan_list ?sep cnv =
  let line = read_line () in
  (match sep with
   | None -> List.map String.of_char @@ String.to_list line
   | Some sep -> String.split_on_char sep line)
  |> List.map cnv

let scan_array ?sep cnv = Array.of_list @@ scan_list ?sep cnv

let scan_matrix n m e ?sep conv =
  let arr = Array.make_matrix n m e in
  ListL.iter (0 ++^ n)
    ~f:(fun i -> arr.(i) <- Array.of_list @@ scan_list ?sep conv);
  arr

let atoi c = Char.code c - Char.code '0'

let rec powerset = function
  | [] -> [[]]
  | hd::tl ->
    let pws =  powerset tl in
    pws @ ListL.map pws ~f:(fun pw -> hd::pw)

let permutations l =
  let rec interleave x = function
    | [] -> [[x]]
    | (hd::tl) as l ->
      (x::l) :: (interleave x tl |> ListL.map ~f:(fun l -> hd::l)) in
  let rec aux = function
    | [] -> [[]]
    | a::rest ->
      aux rest |> ListL.map ~f:(interleave a) |> List.concat in
  aux l

let intersection l =
  EnumL.filter ~f:(fun x -> EnumL.exists ~f:((=) x) @@ Enum.clone l)

let zip l m =
  let n = min (List.length l) (List.length m) in
  List.combine (List.take n l) (List.take n m)

let lower_bound n f =
  let rec aux l u =
    if u - l > 1 then
      let m = (l + u) / 2 in
      if f m then aux l m
      else aux m u
    else u in aux (-1) n

let between n x m = n <= x && x < m

let (x,y)= scan "%d %d" Tuple2.make

let () =
  ListL.map (0++x) ~f:(fun i ->
      2*i + 4*(x-i) = y)
  |> List.exists ((=) true)
  |> (fun v -> Printf.printf "%s\n" (if v then "Yes" else "No"))


Measured memory_bytes: 5424