akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
using namespace std;
int main(void){
    int n;
    cin>>n;
    int f[110][10];
    for(int i=0;i<n;i++){
        for(int j=0;j<10;j++){
                cin>>f[i][j];
        }
    }
    int p[110][15];
    for(int i=0;i<n;i++){
        for(int j=0;j<=10;j++){
            cin>>p[i][j];
        }
    }
    int a[15]={};
    long long ans=-100000000000;
    for(int i=0;i<1023;i++){
        a[0]++;
        int q=0;
        for(int j=0;j<=10;j++){
            if(a[j]==2){
                a[j]=0;
                a[j+1]++;
            }
        }
        for(int k=0;k<n;k++){
            int t=0;
            for(int l=0;l<10;l++){
                if(f[k][l]==1&&a[l]==1)t++;
            }
            q+=p[k][t];
        }
        if(ans<q)ans=q;
    }
    cout<<ans<<endl;
    return 0;
}


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

int main()
{
  string s;
  cin >> s;
  int n = s.size()-1;
  ll ans = 0;

  for (int bit = 0; bit < (1 << n); bit++) {
    ll a = s[0]-'0';
    for (int i = 0; i < n; i++) {
      if (bit & (1 << i)) {
        ans += a;
        a = s[i+1]-'0';
      }
      else {
        a *= 10;
        a += s[i+1]-'0';
      }
    }
    ans += a;
  }
  cout << ans << endl;
  return 0;
}

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

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

const int  MOD=1000000007;
const int  INF= int(1e9);


int main() {
    ios_base::sync_with_stdio(false);
    int n,k;
    cin>>n>>k;
    vi a(n);
    for(int i=0;i<n;i++) {
        cin>>a[i];
    }
    n--;
    k--;
    int res = (n+k-1)/k;
    cout<<res<<"\n";




    return 0;
}


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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define abs(a) max((a),-(a))
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repe(i,n) rep(i,(n)+1)
#define per(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define pere(i,n) rep(i,(n)+1)
#define all(x) (x).begin(),(x).end()
#define SP <<" "<<
#define RET return 0
#define MOD 1000000007
#define INF 1000000000000000000

typedef long long LL;
typedef long double LD;

int main(){
  string s;
  cin >> s;
  if((s[0]==s[1]&&s[0]==s[2])||(s[1]==s[2]&&s[1]==s[3])) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


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[] dam = new int[n + 1];
        int[] rain = new int[n + 1];

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

        for (int i = 0; i < n; ++i) {
            if (i % 2 == 0) {
                rain[0] += dam[i];
            } else {
                rain[0] -= dam[i];
            }
        }

        for (int i = 1; i < n; ++i) {
            rain[i] = dam[i - 1] * 2 - rain[i - 1];
        }

        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < n; ++i) {
            sb.append(rain[i]);
            if (i != n - 1) {
                sb.append(" ");
            }
        }
        System.out.println(sb.toString());
    }
}


Measured memory_bytes: 55132
//  ©   ___MRX___

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

#define ll long long int

int main()
{
    int n, i, flag = 1;
    cin >> n;
    vector<int> vec(n);
    for(i = 0; i < n; i++) {
        cin >> vec[i];
    }
    int max_height = vec[0];
    for(i = 1; i < n; i++) {
        if(max_height < vec[i])
            max_height = vec[i];
        if(vec[i] >= vec[0] && vec[i] >= max_height)
            flag++;
    }

    cout << flag << '\n';

    return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>

using namespace std;

int main()
{
    int a, b, c, x;

    cin >> a >> b >> c >> x;

    int res = 0;

    for (int i = 0; i <= a; i++)
        for (int j = 0; j <= b; j++)
            for (int k = 0; k <= c; k++)
            {
                if (i * 500 + j * 100 + k * 50 == x)
                    res++;
            }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
// #include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <tuple>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repd(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define repdm(i, a, b) for (ll i = (ll)(a); i > (ll)(b); i--)
const ll INF = 1LL << 60;

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

int N;
ll W, weight[110], value[110];

// dpテーブル。配列の２次元目は、その時のナップサックのweightそのものを表し、そこにvalueを入れるようになっている
ll dp[110][100010] = {0};

int main()
{
  cin >> N >> W;
  rep(i, N) cin >> weight[i + 1] >> value[i + 1];

  rep(i, N)
  {
    rep(sum_w, W + 1)
    {
      // i番目の品物を選ぶ場合
      if (sum_w - weight[i + 1] >= 0)
      {
        // sum_w - weight[i+1]は新しいナップサックの状態（weight）を
        chmax(dp[i + 1][sum_w], dp[i][sum_w - weight[i + 1]] + value[i + 1]);
      }

      chmax(dp[i + 1][sum_w], dp[i][sum_w]);
    }
  }

  cout << dp[N][W];
}

Measured memory_bytes: 79360
X, K, D = map(int, input().split())
X = abs(X)
cnt = X // D
if cnt >= K:
  print(X - D * K)
  exit()
if (cnt % 2) ^ (K % 2) == 0:
  print(X - D * cnt)
else:
  print(abs(X - D * cnt - D))

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

int main() {
  int n;
  int count=0;
  string value;
  cin >> n >> value;
  map<char,int> list_i;
  for (int i=0; i<n-2; i++) {
    if (list_i.size()==10) {
      break;
    }
    else if (list_i.count(value.at(i))) {
      continue;
    }
    else {
      list_i[value.at(i)]=1;
      map<char,int> list_j;
      for (int j=i+1; j<n-1;j++) {
        if (list_j.size()==10) {
          break;
        }
        else if (list_j.count(value.at(j))) {
          continue;
        }
        else {
          list_j[value.at(j)]=1;
          map<char,int> list_k;
          for (int k=j+1; k<n; k++) {
            if (list_k.size()==10) {
              break;
            }
            else if (list_k.count(value.at(k))) {
              continue;
            }
            else {
              list_k[value.at(k)]=1;
              count++;
            }
          }
        }
      }
    }
  }
  cout << count;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<bool> m(n);
  for(int i=0;i<n;i++){
    int p;
    cin>>p;
    m.at(i)=(p-1==i);
  }
  int c=0;
  for(int i=0;i<n;i++){
    if(m.at(i)){
      c++;
      m.at(i)=0;
      if(i+1<n)
        m.at(i+1)=0;
    }
  }
  cout<<c<<endl;
}

Measured memory_bytes: 256
from collections import Counter
s=input()
ch=set([c for c in s])
ans=101

for c in ch:
    cur=s
    cnt=0
    while len(set([x for x in cur]))>1:
        cnt+=1
        tmp=''
        for i in range(len(cur)-1):
            if cur[i]==c or cur[i+1]==c:
                tmp+=c
            else:
                tmp+=cur[i]
        cur=tmp
    ans=min(ans,cnt)

print(ans)

Measured memory_bytes: 74156
/**
 * Areas on the Cross-Section Diagram
 * http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_3_D&lang=ja
 * 
 * 参考： Areas on the Cross-Section Diagram 解き方メモを読めば理屈がわかる
 * https://mtdtx9.hatenablog.com/entry/2017/04/24/230941
 */

#include<iostream>
#include<vector>
#include<stack>
using namespace std;

struct WaterArea {
  // 水たまりの左端の場所
  int leftIndex;
  // 水たまりの大きさ
  int areaSize;
};

WaterArea mkWaterArea(int leftIndex, int areaSize) {
  WaterArea area = WaterArea();
  area.leftIndex = leftIndex;
  area.areaSize = areaSize;
  return area;
}

/**
 * それぞれの水たまりの大きさを出力する
 */
void trace(stack <WaterArea>A) {
  vector <int>areaSizes(A.size());
  while (A.size() > 0) {
    // stackはLIFOなので、一度取り出して整頓する
    WaterArea area = A.top();
    A.pop();
    areaSizes.at(A.size()) = area.areaSize;
  }

  // 水たまりのサイズを出力
  for (int i = 0; i < areaSizes.size(); i++) {
    cout << ' ' << areaSizes.at(i);
  }
}

int areaTotalSize(stack <WaterArea>A) {
  int total = 0;
  while (A.size() > 0) {
    WaterArea area = A.top();
    A.pop();
    total += area.areaSize;
  }

  return total;
}

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

  stack <WaterArea>areaStack;
  stack <int>slopeIndexStack;

  char slope;
  int currentIndex = -1;
  while (++currentIndex <= 20000) {
    cin >> slope;
    if (cin.eof()) {
      break;
    } else if (slope == '\\') {
      slopeIndexStack.push(currentIndex);
    } else if (slope == '/') {
      if (slopeIndexStack.empty()) {
        continue;
      }

      int slopeIndex = slopeIndexStack.top();
      slopeIndexStack.pop();
      WaterArea area = mkWaterArea(slopeIndex, currentIndex - slopeIndex);
      while (areaStack.size() > 0) {
        WaterArea areaTop = areaStack.top();
        // cout << "area top index " << areaTop.size << " " << areaTop.index <<  endl;
        if (areaTop.leftIndex > area.leftIndex) {
          areaStack.pop();
          area.areaSize += areaTop.areaSize;
        } else {
          break;
        }
      }
      areaStack.push(area);
    }
  }

  // 水たまりの総サイズ
  cout << areaTotalSize(areaStack) << endl;
  // 水たまりの数
  cout << areaStack.size();
  // それぞれの水たまりのサイズ
  trace(areaStack);
  cout << endl;

  return 0;
}



Measured memory_bytes: 3192
# -*- coding: utf-8 -*-
import math

N = int(input())

left_side = 1
right_side = N

# 平方根から下げていく
square = int(math.sqrt(N))
for i in reversed(range(1, square+1)):
    if N % i == 0:
        left_side = i
        right_side = N // i
        break

distance = (left_side - 1) + (right_side - 1)
print(distance)



Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
int main () {
  int N, K;
  cin >> N >> K;
  vector <int> cost(N);
  for (int i = 0; i < N; i++) cin >> cost.at(i);
  sort (cost.begin(), cost.end());
  int ans = 0;
  for (int i = 0; i < K; i++)  ans += cost.at(i);
  cout << ans << endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <time.h>
#define int long long
#define endl '\n'
#define INF 1000000000000000000
#define EPS 1e-10
#define all(a) a.begin(),a.end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define fi first
#define se second
#define pb push_back
#define double long double
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
template<class T, class S> bool chmax(T &a, const S &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T, class S> bool chmin(T &a, const S &b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll n, ll m) { return (m ? gcd(m, n%m) : n); }
ll lcm(ll n, ll m) { return n / gcd(n, m)*m; }

ll mod = 1000000007;
int n, k;

vector<vector<int>> mat_mul(vector<vector<int>> a, vector<vector<int>> b) {
	vector<vector<int>> ans(n, vector<int>(n));
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			for (int k = 0; k < n; k++) {
				ans[i][j] += a[i][k] * b[k][j];
				ans[i][j] %= mod;
			}
		}
	}
	return ans;
}

vector<vector<int>> mat_pow(vector<vector<int>> a, int b) {
	vector<vector<int>> ans(n, vector<int>(n));
	for (int i = 0; i < n; i++) ans[i][i] = 1;
	while (b) {
		if (b & 1) ans = mat_mul(ans, a);
		a = mat_mul(a, a);
		b >>= 1;
	}
	return ans;
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);
	//modcalc();

	cin >> n >> k;
	vector<vector<int>> a(n, vector<int>(n));
	rep(i, n) rep(j, n) cin >> a[i][j];
	vector<vector<int>> s = mat_pow(a, k);
	int ans = 0;
	rep(i, n) {
		rep(j, n) {
			ans += s[i][j];
			if (ans > mod) ans -= mod;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define ull unsigned long long
#define ll long long
#define pb push_back
#define endl '\n'
#define line cout<<"----------------------"<<endl
#define mp make_pair
#define mod 1000000007
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL)
#define filein freopen("input.txt","r",stdin)
#define fileout freopen("output.txt","w",stdout)
using namespace std;
const ll  mx=2000009;
ll ara[mx];
ll dp[409][409];
ll sum[409];
int main()
{
    ll n;
    cin>>n;
    for(ll i=1;i<=n;i++)
    {
        cin>>ara[i];
        sum[i]=sum[i-1]+ara[i];
    }
    for(ll i=n;i>0;i--)
    {
        for(ll j=i+1;j<=n;j++)
        {
            dp[i][j]=LLONG_MAX;
            for(ll k=i;k<j;k++)
            {
                dp[i][j]=min(dp[i][j],dp[i][k]+dp[k+1][j]+sum[j]-sum[i-1]);
            }
        }
    }
    cout<<dp[1][n]<<endl;

}


Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
int main()
{
    /*vector <int> v(3);
    for(int i=0;i<3;i++)
    {
        cin>>v[i];
    }
    sort(v.begin(),v.end());
    double a=(v[0]*v[1])/2;
    cout<<(int)a<<endl;
    double a,b;
    cin>>a>>b;
    if(b%a==0)
    {
        cout<<a+b<<endl;
        return 0;
    }
    else*/
    int y,m,d;
    char c;
    cin>>y>>c>>m>>c>>d;
    if(m>=5) cout<<"TBD"<<endl;
    else cout<<"Heisei"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const long long int INF = 1e18;

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

    vector<int> a(n), b(n);
    for(int i=0; i<n; i++) cin >> a[i];
    for(int i=0; i<n; i++) cin >> b[i];

    int V = 51;// 0 ~ 50
    vector<int> choose;
    vector<vector<long long int>> d(V, vector<long long int>(V, INF));

    for(int x=50; x>=0; x--){
        d.assign(V, vector<long long int>(V, INF));
        for(int i=0; i<V; i++){
            d[i][i] = 0;
            for(int j=1; j<=min(i,x); j++) d[i][i%j] = min(d[i][i%j], 1LL<<j);
            for(int j : choose)            d[i][i%j] = min(d[i][i%j], 1LL<<j);
        }

        // Warshall-Floyd
        for(int k=0; k<V; k++){// potential relay points
            for(int i=0; i<V; i++){
                for(int j=0; j<V; j++){
                    d[i][j] = min(
                        d[i][j],// without going through k
                        d[i][k] + d[k][j]// with going through k
                    );
                }
            }
        }

        for(int i=0; i<n; i++){
            if(d[a[i]][b[i]] == INF){
                if(x == 50){ cout << -1 << endl; return 0; }
                else{ choose.push_back(x+1); break; }
            }
        }
    }

    long long int ans = 0;
    for(int c : choose){
        //cout << c << " ";
        ans += 1LL<<c;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3592
using System;
class P
{
    static void Main(string[] args)
    {
        var kari = Console.ReadLine().Split(' ');

        int ninzu = int.Parse(kari[0]);
        int oyu = int.Parse(kari[1]);
        var timeS = Console.ReadLine().Split(' ');
        int[] time = new int[ninzu];
        for (int i = 0; i < ninzu; i++)
        {
            time[i] = int.Parse(timeS[i]);
        }
        int sum_time = 0;

        for (int i = 1; i < time.Length; i++)
        {
            if ((time[i] - time[i - 1]) < oyu) { sum_time += (time[i]-time[i-1]); }
            else { sum_time += oyu; }
        }
		sum_time += oyu;
        Console.WriteLine(sum_time);
    }
}


Measured memory_bytes: 28256
# https://atcoder.jp/contests/abc143/tasks/abc143_b
# -*- coding: utf-8 -*-

tako_cnt = int(input())
tako_deli = list(map(int, input().strip().split()))

eat_hp = 0
for i in range(0,tako_cnt):
    for j in range(i + 1,tako_cnt):
        eat_hp += tako_deli[i] * tako_deli[j]

print(eat_hp)


Measured memory_bytes: 2940
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _0014
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                string n = Console.ReadLine();
                if (n == null) break;

                int width = int.Parse(n);
                int blocks = 600 / width;
                int erea = 0;
                for (int i = 0; i < blocks; i++)
                {
                    erea += width * (int)Math.Pow(width * i, 2);
                }

                Console.WriteLine(erea);
            }
        }
        
    }
}



Measured memory_bytes: 15952
n = int(input())

a = [0] * n
for i in range(n):
    a[i] = int(input())

loop = [0] * n


if (2 not in a):
    print(-1)
    exit()

tar_index = 0
loop[0] = 1
# 何回目で２に到達するか
count = 0

while True:
    tar_index = a[tar_index] - 1
    #print(count, tar_index)
    count += 1

    if (tar_index == 1):
        print(count)
        exit()

    # 一回行った場所に戻ると、循環してるのでOUT
    if (loop[tar_index] == 1):
        print(-1)
        exit()

    loop[tar_index] = 1


Measured memory_bytes: 13508
#include "bits/stdc++.h"
using namespace std;

#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
const int inf = 1000000001;
const ll INF = 1e18 * 4;
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<<fixed<<p<<endl;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };

class Land { 
public:
	int J, O, I;
	Land(int j = 0, int o = 0, int i = 0) {
		J = j;
		O = o;
		I = i;
	}
	Land operator + (Land other) {
		Land res(0, 0, 0);
		res.J = J + other.J;
		res.O = O + other.O;
		res.I = I + other.I;
		return res;
	}
};

int main() {
	int w, h, k, i, j;
	cin >> h >> w >> k;
	vs a(h);
	for (i = 0; i < h; i++) {
		cin >> a[i];
	}
	Land z(0, 0, 0);
	vector< vector<Land> > sum(h + 1, vector<Land>(w + 1, z));
	for (i = 0; i < h; i++) {
		for (j = 0; j < w; j++) {
			sum[i + 1][j + 1] = sum[i + 1][j];
			switch (a[i][j]) {
			case 'J':
				sum[i + 1][j + 1].J++;
				break;
			case'O':
				sum[i + 1][j + 1].O++;
				break;
			default:
				sum[i + 1][j + 1].I++;
			}
		}
		for (j = 0; j < w; j++) {
			sum[i + 1][j + 1] = sum[i + 1][j + 1] + sum[i][j + 1];
		}
	}
	/*
	for (i = 0; i <= h; i++) {
		for (j = 0; j <= w; j++) {
			cout << sum[i][j].J << sum[i][j].O << sum[i][j].I << " ";
		}
		cout << endl;
	}
	*/
	for (i = 0; i < k; i++) {
		int a, b, c, d;
		cin >> a >> b >> c >> d;
		int J = 0, O = 0, I = 0;
		J = sum[c][d].J - sum[c][b - 1].J - sum[a - 1][d].J + sum[a - 1][b - 1].J;
		O = sum[c][d].O - sum[c][b - 1].O - sum[a - 1][d].O + sum[a - 1][b - 1].O;
		I = sum[c][d].I - sum[c][b - 1].I - sum[a - 1][d].I + sum[a - 1][b - 1].I;
		cout << J << " " << O << " " << I << endl;
	}
}

Measured memory_bytes: 15528
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<ll>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

int n;
vi a, sum;
vvi s;
ll dfs(int l, int r) {
    if(s[l][r] != -1) return s[l][r];
    if(r-l == 1) return 0LL;
    ll &res = s[l][r] = LINF;
    for(int i = l+1; i != r; i++) {
        chmin(res, dfs(l, i) + dfs(i, r));
    }
    return res += sum[r]-sum[l];
}


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    a.resize(n);
    sum.resize(n+1);
    s.assign(n, vi(n+1, -1));
    rep(i, n) cin >> a[i];
    rep(i, n) sum[i+1] = sum[i] + a[i];

    cout << dfs(0, n) << endl;
}

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

int main (){
  int a,b,c;
  cin>>a>>b>>c;
  if(a==b && b==c || a!=b && b!=c && c!=a){
    cout<<"No"<<endl;
  }
  else{
    cout<<"Yes"<<endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int a,b,dis = 999999,total = 0,eat = 0;
  cin >> a >> b;
  vector<int> vec(a);
  for(int i = 0;i < a;i++){
    vec.at(i) = i + b;
    total += vec.at(i);
  }
  for(int i = 0;i < a;i++){
    if(abs(total - (total - vec.at(i))) < dis){
      dis = abs( total - (total - vec.at(i)));
      eat = vec.at(i);
    }
  }
  cout << total - eat << endl;
  
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
string S;
int K;
string x;
string res;
void rec(char a) {
	x.push_back(a);
	int cur = 0;
	bool ok = false;
	for (int i = 0; i  + ((int)x.size() - 1) < S.size(); i++) {
		bool f = true;
		for (int j = 0; j < x.size(); j++) {
			if (x[j] != S[i + j])f = false;
		}
		if (f)ok = true;
	}
	if (ok) {
		K--;
		//cerr << x << endl;
		if (K == 0)res = x;
		if (res.size() > 0) {
			return;
		}
		rec('a');
		x.pop_back();
	}
	else {
		x.pop_back();
		if (a == 'z') {

		}
		else {
			rec(a + 1);
		}
	}

}
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> S;
	cin >> K;
	for (char i = 'a'; i <= 'z'; i++) {
		rec(i);
		if (res.size() > 0)break;
	}
	cout << res << endl;
}

Measured memory_bytes: 256
S = input()
sequence = 0
max_sequence = 0
for i in range(len(S)):
    if S[i] == 'A' or S[i] == 'C' or S[i] == 'G' or S[i] == 'T':
        sequence += 1
    else:
        max_sequence = max(sequence,max_sequence)
        sequence = 0
max_sequence = max(sequence,max_sequence)
print(max_sequence)

Measured memory_bytes: 3060
while True:
    s=input()
    if s=='-':
        break
    m=int(input())
    s=list(s)
    for i in range(m):
        h=int(input())
        for j in range(h):
            pop=s.pop(0)
            s.append(pop)
    a=''.join(s)
    print(a)


Measured memory_bytes: 5584
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n)for(int i=0;i<(int)(n);i++)
#define PI 3.141592653589793
//vector < vector<int>>a(0, vector<int>(0));二次元配列宣言


int main()
{
	int n;
	cin >> n;
	vector<int>a(n);
	int i;
	double ans=0;
	for (i = 0; i < n; i++)
	{
		cin >> a.at(i);
		ans += (double)(1.0 / a.at(i));
		//cout << ans << endl;
	}
	ans = 1 / ans;
	printf("%.10f\n", ans);
}

Measured memory_bytes: 3744
def main(argv)
  a, b = gets.split(' ').map(&:to_i)
  if a + b == 15 then
    puts '+'
  elsif a * b == 15 then
    puts '*'
  else
    puts 'x'
  end
end

if self.to_s == 'main' then
  main(ARGV)
end

Measured memory_bytes: 1788
import std;

long calc(int n) {
    long sum = 0;
    for (int i = 1; i <= n; i++) {
        if (i % 3 == 0 || i % 5 == 0) continue;
        sum += i;
    }
    return sum;
}

void main() {
    int n; scan(n);
    writeln(calc(n));
}

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;


Measured memory_bytes: 3624
//by Himanshu Shukla
#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define ll long long
#define v32 vector<int>
#define v64 vector<ll>
#define s32 set<int>
#define s64 set<ll>
#define p32 pair<int,int>
#define p64 pair<ll,ll>
#define fi first
#define se second
#define ln '\n'
#define debug(x) cout << (#x) << ": " << (x) << ln
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline ll add(ll a, ll b, ll m) { return (((a % m + b % m) % m + m) % m); }
inline ll mul(ll a, ll b, ll m) { return (((a % m * b % m) % m + m) % m); }
const double EPS = 1e-6;
const ll MOD = 1e9 + 7;
template <typename T, typename U>
ostream& operator<<(ostream& out, const pair<T,U>& p){
	out << '[' << p.fi << ", " << p.se << ']';
	return out;
}
template <template <typename, typename...> class ContainerType, typename ValueType, typename ...Args>
void print_container(const ContainerType<ValueType, Args...>& c){
	cout << "{ ";
	for(const auto& v : c)
		cout << v << ' ';
	cout << '}' << ln;
}

int main()
{
	FASTIO;
	int n;
	cin >> n;
	v64 arr(n + 1,0);
	for(int i = 1;i < n + 1;i++)
		cin >> arr[i],arr[i] = 2 * arr[i];
	v64 ans(n + 1,0);
	ll tmp = 0;
	for(int i = 1;i < n - 1;i += 2)
		tmp += (arr[i] - arr[i + 1]);
	tmp += arr[n];
	ans[1] = tmp / 2;
	ans[n] = arr[n] - ans[1];
	for(int i = 2;i < n;i++)
		ans[i] = arr[i - 1] - ans[i - 1];
	for(int i = 1;i < n + 1;i++)
		cout << ans[i] << " ";
	cout << ln;
	return 0;
}


Measured memory_bytes: 2944
s = input()
a = [0] * (len(s) +1)
for i in range(len(s)):
    if s[i] == '<':
        a[i+1] = a[i]+1
for i in range(len(s)-1, -1, -1):
    if s[i] == '>':
        a[i] = max(a[i], a[i+1]+1)
print(sum(a))


Measured memory_bytes: 23340
///*****************************************************///
///*.......................Faiyaj Bin Amin............................*///
///*...................................................................*///
///*.........................KUET CSE 2K17......................*///
///*...................................................*///
///*****************************************************///

#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

#define fastio      ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define ret return
#define rep(q, i, n) for(int q=i; q<n; q++)
#define forn(i, n) for(int i=0; i<n; i++)
#define mems(a,x) memset(a,x,sizeof(a))
#define ll long long
#define pb push_back
#define em emplace_back
#define mp make_pair
#define all(v) (v).begin(), (v).end()
#define ff first
#define ss second
#define pii pair<int,int>
#define pdd pair<double, double>

#define see(x)        cerr<< __LINE__ << ": " << (#x) << " is "<< (x) <<'\n';
#define seecontent(v) for(auto x : v) { cout << x << " ";} cout << "\n\n";

#define PI 2*acos(0.0)
#define lcm(a, b)  ((a / __gcd(a, b) ) * b)

#define filein freopen ("input.txt", "r", stdin)
#define fileout freopen ("output.txt", "w", stdout)

#define mx 100005
#define INF 1e18
#define MOD 1000000007
#define MIN 0

//template <typename T>  using orderedSet =
//    tree<T, null_type, less_equal<T>,
//    rb_tree_tag, tree_order_statistics_node_update>; //find_by_order, order_of_key


/*------------------------------Graph Moves----------------------------*/
//const int fx[]={+1,-1,+0,+0}; // Directional
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*---------------------------------------------------------------------*/

/**------------------------------------BITMASK------------------------------------------**/
//int Change(int N, int pos){return N= N^(1<<pos);}
//bool Check(int N, int pos){return (bool)(N &(1<<pos));}  /// check bit 0 or 1
/**-----------------------------------------------------------------------------------------------**/

//using namespace __gnu_pbds;
using namespace std;

int main()
{
////    fastio;
    int n;
    cin>>n;

    string s;
    cin >>s;

    int cnt=1;
    for(int i=1; i<n; i++)
    {
        if(s[i]!=s[i-1])
            cnt++;
    }
    cout << cnt << "\n";

    return 0;
}





Measured memory_bytes: 3728
import java.util.Scanner;

class Main{
      public static void main(String args[]){
	Scanner sc = new Scanner(System.in);
	int k = sc.nextInt();
	String s = sc.next();
	if(s.length()<=k)
	    System.out.println(s);
	else
	    System.out.println(s.substring(0,k)+"...");
      }
}


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

import bisect

N, M = map(int, input().split())

y = [1, M]
for i in range(2, int(M ** 0.5) + 1):
    if M % i == 0:
        y.append(i)
        y.append(M // i)

y.sort()
print(M // y[bisect.bisect_left(y, N)])



Measured memory_bytes: 3060
#include<stdio.h>
#define N 500000
   
int H;
int A[N+1];
   
void maxHeap(int i){
  int max;
  int r=i*2+1,l=i*2;
  int temp=0;
  
  if(l <= H && A[l] > A[i]){
    max=l;
  }
  else {
    max=i;
  }
  if(r <= H && A[r] > A[max]){
    max=r;
  }  
  if(max != i){
    temp = A[i];
    A[i] = A[max];
    A[max] = temp;
    maxHeap(max);
  }
}
 
void buildMaxHeap(){
  int i=0;
  for(i = H/2; i >= 1; i--){
    maxHeap(i);
  }
}
   
int main(){
  int i,j;
  scanf("%d", &H);
  for(i = 1; i <= H; i++){
    scanf("%d", &A[i]);
  }
  buildMaxHeap();
  for(i = 1; i <= H; i++){
    printf(" ");
    printf("%d", A[i]);
  }
  printf("\n");
   
  return 0;
}

Measured memory_bytes: 2552
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
int sg(int x, int y) {
	if (x % y == 0) return x / y;
	int div = x / y, mns = div + 1;
	int delta = x - y * div, cnt = delta / mns + (delta % mns != 0);
	return sg(x - mns * cnt, y);
}
int main() {
	int n, ans = 0; read(n);
	for (int i = 1; i <= n; i++) {
		int x, y; read(x), read(y);
		ans ^= sg(x, y);
	}
	if (ans) puts("Takahashi");
	else puts("Aoki");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include<math.h>
using namespace std;
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; }

int64_t cx(int64_t i) {
    int64_t res = 1;
    while (i > 1) {
        res = res * i;
        i--;
    }

    return res;
}

int main()
{
    int64_t N;
    cin >> N;
    map<string, int64_t>d;
    for (int64_t i=0; i<N; i++) {
        string s;
        cin >> s;
        sort(s.begin(), s.end());
        if (d.count(s) > 0) {
            d[s] = d[s] + 1;
        } else {
            d[s] = 1;
        }
    }

    int64_t sum_count = 0;
    for (auto c : d) {
        if (c.second > 2) {
            int64_t i = c.second;
            while (i > 1) {
                sum_count += i - 1;
                i--;
            }
        } else if (c.second == 2) {
            sum_count += 1;
        }
    }

    cout << sum_count << endl;
    return 0;
}

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

int main() {
	int a,b;
    cin >> a >> b;
  	if(a % 2 == 0 || b % 2 == 0){
    cout << "Even" << endl;
    }
  	else{
    cout << "Odd"  << endl;
    }
}


Measured memory_bytes: 256
from collections import deque


def main():
    n = int(input())
    ans = [0 for _ in range(n)]
    graph = [[] for _ in range(n)]
    for _ in range(n - 1):
        a, b = map(lambda x: int(x) - 1, input().split())
        graph[a].append(b)
        graph[b].append(a)
    c = list(map(int, input().split()))
    c.sort(reverse=True)
    root = 0
    max_deg = 0
    for i in range(n):
        if max_deg < len(graph[i]):
            root = i
            max_deg = len(graph[i])
    q = deque([root])
    ans[root] = c[0]
    idx = 1
    while q:
        now_v = q.pop()
        for next_v in graph[now_v]:
            if ans[next_v] == 0:
                ans[next_v] = c[idx]
                idx += 1
                q.append(next_v)
    print(sum(c[1:]))
    print(" ".join(map(str, ans)))


if __name__ == '__main__':
    main()


Measured memory_bytes: 11888
#include<bits/stdc++.h>
#define ll long long
#define int long long
#define M 1000000007
#define sz(c) c.size()
#define fr first
#define sc second
#define pb push_back
#define sz(c) c.size()
#define ppb  pop_back
#define mp make_pair
#define all(a)      (a).begin(),(a).end()
#define rep(i,a,n)   for( int i=a ; i<n ; i++)
#define what_is(x)  cout << #x << " is " << x << endl;
#define U 1000000007
#define N 100005
using namespace std;
signed main()
{
  ios_base::sync_with_stdio(false);
  
  int n;
  cin>>n;
  int a[n];
  int b[n];
  int c[n-1];
  rep(i,0,n) cin>>a[i];
  rep(i,0,n) cin>>b[i];
  rep(i,0,n-1) cin>>c[i];
  int ans=0;
  rep(i,0,n)ans+=b[a[i]-1];
  rep(i,0,n-1) if(a[i]+1==a[i+1])ans+=c[a[i]-1];
  cout<<ans;



}

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

int main() {
    ll n , k;
    cin >> n >> k;
    cout << min(n - k*(ll)(n/k), k*(ll)(n/k) + k - n) << endl;
    return 0;
}


Measured memory_bytes: 3596
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<queue>
#include<cmath>
#define R(i, n) for(int i = 0;i < n;i++)
#define S(a) scanf("%d", &a)
#define S2(a, b) scanf("%d%d", &a, &b)
#define S3(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define P(a) printf("%d", a)
#define INF 1000000000
using namespace std;
using ll = long long;
using IR = pair<int, int>;

int L;

int main() {
	S(L);
	double three = (double)L / 3;
	printf("%lf", three * three * three);
}

Measured memory_bytes: 256
n,m=map(int,input().split())

A=[];B=[]
for i in range(n):
    A.append(input())
    
for i in range(m):
    B.append(int(input()))

for i in range(len(A)):
    Arc=[int(k) for k in A[i].split()]
    x=0
    for k in range(len(Arc)):
       x += Arc[k]*B[k]
    print(x)
    


Measured memory_bytes: 5660
import itertools as it
class mybool:
    def __init__(self, value):
        self.value = value
    def __neg__(self):
        return mybool(2-self.value)
    def __mul__(self, other):
        return mybool(min(self.value,other.value))
    def __add__(self, other):
        return mybool(max(self.value,other.value))

while 1:
    s = raw_input()
    if s == ".": break
    
    while "--" in s: s = s.replace("--","")
    s = s.replace("2","mybool(2)").replace("1","mybool(1)").replace("0","mybool(0)")
    
    ans = 0
    for p,q,r in it.product([0,1,2],repeat=3):
        P,Q,R = mybool(p),mybool(q),mybool(r)
        if eval(s).value == 2:
            ans += 1
    
    print ans
    

Measured memory_bytes: 4396
import sys
readline = sys.stdin.readline

N,M = map(int,readline().split())
G = [[] for i in range(N)]
for i in range(M):
  a,b = map(int,readline().split())
  G[a - 1].append(b - 1)
  G[b - 1].append(a - 1)

# 1の部屋からBFSして、初めて来た部屋だったら直前の部屋番号(+1)を入れる
ans = [None] * N

from collections import deque
q = deque([])

q.append((0, -1))
while q:
  v, parent = q.popleft()
  if ans[v] is not None:
    continue
  ans[v] = parent + 1
  for child in G[v]:
    if child == parent:
      continue
    q.append((child, v))

print("Yes")
for i in range(1, len(ans)):
  print(ans[i])
  

Measured memory_bytes: 48916
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
#define double long double
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod * mod;
constexpr int MAX = 200010;

using grid = vector<vector<char>>;

bool check(grid &c, int L, int R, int U, int D, vector<bool> &used){
    For(i, U, D+1)For(j, L, R+1){
        if(c[i][j] == '.' || !used[c[i][j]-'A']) return false;
    }
    return true;
}

void solve(){
    int h, w;
    scanf("%d%d", &h, &w);
    grid c(h, vector<char>(w));
    int L[26], R[26], U[26], D[26];
    rep(i, 26){
        L[i] = w; U[i] = h;
        R[i] = D[i] = -1;
    }
    vector<char> v;
    rep(i, h)rep(j, w){
        scanf(" %c", &c[i][j]);
        if(c[i][j] != '.'){
            v.push_back(c[i][j]);
            int t = c[i][j] - 'A';
            chmin(U[t], i); chmin(L[t], j);
            chmax(D[t], i); chmax(R[t], j);
        }
    }
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());

    bool flag = false;
    do{
        bool tmp = true;
        vector<bool> used(26, false);
        for(auto x: v){
            int t = x - 'A';
            used[t] = true;
            if(!check(c, L[t], R[t], U[t], D[t], used)){
                tmp = false;
                break;
            }
        }
        if(tmp){
            flag = true;
            break;
        }
    }while(next_permutation(v.begin(), v.end()));

    puts(flag ? "SAFE" : "SUSPICIOUS");
}

int main(){
    int t;
    scanf("%d", &t);
    rep(tt, t){
        solve();
    }
}


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

int main(){
  int n,k;
  cin >> n >> k;
  vector<int> h(n);
  rep(i,n) cin >> h[i];
  sort(h.begin(), h.end());
  k = min(n,k);
  ll ans = 0;
  rep(i,k){
    h.pop_back(); 
  }
  rep(i,h.size()) ans += h[i];
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<ll>::iterator sit;
typedef map<ll,ll>::iterator mit;

const int MOD = 1e9 + 7;

void add(int &a, int b)
{
	a+=b;
	while(a>=MOD) a-=MOD;
}

int mult(int a, int b)
{
	return (a*1LL*b)%MOD;
}

const int N = 500100;
int pregood[N+1];
int sufgood[N+1];
int pre00[N+1];
int suf00[N+1];
int dp[N+1][2][4];

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	string s; cin>>s;
	int n = s.length();
	int total = 1;
	for(int i=0;i<n;i++)
	{
		if(s[i]=='?') total = mult(total, 2);
	}
	//compute # of ways for prefix and suffix to be 00-win
	for(int i=2;i<n;i+=2) //make [1,i] good
	{
		int tot = (s[i-1]=='?'?2:1)*(s[i]=='?'?2:1);
		if(s[i-1]!='0'&&s[i]!='0') tot--;
		pregood[i] = tot;
		if(i>2) pregood[i]=mult(pregood[i],pregood[i-2]);
	}
	for(int i=n-3;i>=0;i-=2) //make [i,n-2] good
	{
		int tot = (s[i+1]=='?'?2:1)*(s[i]=='?'?2:1);
		if(s[i+1]!='0'&&s[i]!='0') tot--;
		sufgood[i] = tot;
		if(i<n-3) sufgood[i]=mult(sufgood[i],sufgood[i+2]);
	}
	for(int i=1;i<n;i+=2) //make [0,i] a 00-win
	{
		if(s[0]=='1'||s[i]=='1') continue;
		if(i==1) pre00[i]=1;
		else pre00[i] = pregood[i-1];
	}
	for(int i=n-2;i>=0;i-=2) //make [i,n-1] a 00-win
	{
		if(s[i]=='1'||s[n-1]=='1') continue;
		if(i==n-2) suf00[i] = 1;
		else suf00[i] = sufgood[i+1];
	}
	//fix the length 3 1-run 
	int ans = 0;
	for(int i=2;i+3<n;i++) //[i,i+2] is the length 3 run
	{
		if(s[i]=='0'||s[i+1]=='0'||s[i+2]=='0') continue;
		add(ans, mult(pre00[i-1], suf00[i+3]));
	}
	//# of prefixes with all 1-runs <= 2 and NO occurence of ....11<even> (or equivalently 11 such that the first 1 is at odd position if 0-indexed)
	for(int i=0;i<2;i++)
	{
		if(s[0]=='0'+(i^1)) continue;
		dp[0][i][i+2] = 1; //avoid leading 11
	}
	for(int i=0;i<n-1;i++)
	{
		for(int j=0;j<2;j++)
		{
			for(int k=0;k<4;k++)
			{
				if(dp[i][j][k]!=0)
				{
					int v = dp[i][j][k];
					//append 0
					if(s[i+1]!='1') add(dp[i+1][j][((k&1)<<1)], v);
					if(k%2==0) //previous bit is 0
					{
						if(s[i+1]!='0') add(dp[i+1][j][((k&1)<<1) + 1], v);
					}
					else if(k==1)//previous bit is 1
					{
						if(!j&&(i%2==0))
						{
							if(s[i+1]!='0') add(dp[i+1][j][((k&1)<<1) + 1], v);
						}
					}
				}
			}
		}
	}
	//no occurence of ....11<even>
	for(int i=0;i<2;i++)
	{
		for(int j=0;j<4;j++)
		{
			if(i&&(j&1)) continue;
			add(ans, dp[n-1][i][j]);
		}
	}
	//loop through FIRST occurence of ...11<even>
	for(int i=1;i<n;i+=2) //[i, i+1] is the first occurence of even
	{
		if(s[i]=='0'||s[i+1]=='0') continue;
		int lhs = 0;
		for(int j=0;j<2;j++)
		{
			for(int k=0;k<4;k+=2)
			{
				add(lhs, dp[i-1][j][k]);
			}
		}
		int rhs = suf00[i+2];
		add(ans, mult(lhs,rhs));
	}
	add(total, MOD - ans);
	cout<<total<<'\n';
}


Measured memory_bytes: 19220
#include <bits/stdc++.h>
    using namespace std;
           
    int main(){
      int n,l,i;        
      cin >> n >> l;
      vector<string> s(n);
      
      for(i=0;i<n;i++) cin >> s.at(i);
            
      sort(s.begin(),s.end());
      for(i=0;i<n;i++) cout << s.at(i);
    }

Measured memory_bytes: 3596
#include <iostream>
#include <sstream>
#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>
using namespace std;

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

    while(--n >= 0){
        int ret = 0;
        int out = 0;
        bool first = false;
        bool second = false;
        bool third = false;

        for(;;){
            string s;
            cin >> s;
            if(s == "HIT"){
                if(third)
                    ++ ret;
                third = second;
                second = first;
                first = true;
            }else if(s == "HOMERUN"){
                if(first)
                    ++ ret;
                if(second)
                    ++ ret;
                if(third)
                    ++ ret;
                ++ ret;
                first = second = third = false;
            }else{
                ++ out;
                if(out == 3)
                    break;
            }
        }
        cout << ret << endl;
    }
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define LL long long int
#define DL double
#define MLL map<LL,LL>::iterator
#define MSL map<string,L>::iterator
#define MLS map<LL,string>::iterator
#define MSS map<string,string>::iterator
#define MCL map<char,LL>::iterator
#define SL set<LL>::iterator
#define SS set<string>::iterator
#define VL vector<LL>::iterator
#define G getline
#define SZ size()
#define IN insert
#define C clear()
#define B begin()
#define F front()
#define T top()
#define E end()
#define EM empty()
#define V vector
#define Q queue
#define DQ deque
#define PQ priority_queue
#define ST stack
#define FI first
#define SE second
#define PI acos(-1)
#define PS push
#define PP pop()
#define PSF push_front
#define PSB push_back
#define PPF pop_front()
#define PPB pop_back()
#define endl "\n"
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
void Y()
{
    cout<<"Yes"<<endl;
}
void N()
{
    cout<<"No"<<endl;
}
V<LL>v;
int main()
{
    FAST;
    LL n,m,i,j,k,p,q,o,l,s,t,z;
    string a;
    cin>>n;
    for(i=0,k=0,l=0; i<n; i++)
    {
        cin>>o;
        k+=o;
        l=max(l,o);
    }
    if(k-l>l)
    {
        Y();
    }
    else
    {
        N();
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <queue>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
#include <string>
#include <unordered_map>
using namespace std;
#define MAXSIZE 10005
typedef long long LL;


int main() {
	//freopen("in.txt", "r", stdin);
	string s1, s2;
	cin >> s1 >> s2;
	int flag = 0;
	int l = s1.length();
	for (int i = 0; i < s1.length(); i++) {
		flag = 0;
		for (int j = 0; j < s2.length(); j++) {
			if (s1[(i+j)%l] != s2[j]) {
				flag = 1;
				break;
			}
		}
		if (flag == 0) break;
	}
	if (flag == 0) printf("Yes\n");
	else printf("No\n");
	//printf("\n");
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<queue>
#include<vector>
#include<string.h>
#include<algorithm>
#include <cmath>

using namespace std;

long long N,K,i,j,k,X,Y,jmax,ans,Z,a;

deque<long long> Q;

int main()
{
  cin>>K;
  
  if(K<10)
  {
    cout << K;
    return 0;
  }
  
  for(i=1;i<10;i++)
  {
    Q.push_back(i);
  }
  
  for(i=0;i<K;i++)
  {
    j=Q.front();
    a=j%10;
    
    if(a>0)
    {
      Q.push_back(10*j+a-1);
    }
    
    Q.push_back(10*j+a);
    
    if(a<9)
    {
      Q.push_back(10*j+a+1);
    }
    
    Q.pop_front();
    
  }
  
  
  cout <<j;

  
}

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

int main(int argc, char const *argv[])
{
	int n;
	cin>>n;
	int a[n],b[n];
	for (int i = 0; i < n; ++i)
	{
		cin>>a[i];
		b[i]=a[i];
	}
	sort(b,b+n);
	for (int i = 0; i < n; ++i)
	{
		if (a[i]<=b[n/2-1])
		{
			cout<<b[n/2]<<endl;
		}
		else
		{
			cout<<b[n/2-1]<<endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3712
#include <assert.h>
#include <limits.h>
#include <cmath>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <complex>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using ll = long long;
using P = std::pair<ll, ll>;

#define rep(i, a, b) for (ll(i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(i) std::cout << i << "\n"

//const ll MOD = 998244353;
const ll MOD = 1e9+7;
 
int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  //問題文中の添え字が0-indexか1-indexか確認!

  ll n,t;
  std::cin>>n>>t;
  ll min;
  std::vector<ll> b(n-1);
  std::cin>>min;
  rep(i,1,n){
    ll a;
    std::cin>>a;
    b[i-1]=a-min;
    min=std::min(min,a);
  }
  std::sort(all(b));
  ll max=b[n-2];
  std::cout<<(ll)(b.end()-std::lower_bound(all(b),max));
  return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
void mergesort(int* A,int left,int right);
void merge(int* A,int left,int mid,int right);

int c=0;

int main(){
  int n,a[500000],i,mid;
  scanf("%d",&n);
  for(i=0;i<n;i++){scanf("%d",&a[i]);}

  mid=n/2;
  mergesort(a,0,n);

  for(i=0;i<n-1;i++){printf("%d ",a[i]);}
  printf("%d\n%d\n",a[n-1],c);
  return 0;
}

void mergesort(int A[], int left,int right){
  int mid;
  if (left+1 < right){
    mid = (left + right)/2;
    mergesort(A, left, mid);
    mergesort(A, mid, right);
    merge(A, left, mid, right);
  }
}

void merge(int A[],int left,int mid,int right){
  int i,j,k,n1,n2,LeftArr[500000],RightArr[500000];

  n1 = mid - left;
  n2 = right - mid;

  for (i = 0; i<n1;i++){LeftArr[i] = A[left + i];}
  for (i = 0; i<n2;i++){RightArr[i] = A[mid + i];}
  LeftArr[n1] = 1000000001;
  RightArr[n2] = 1000000001;

  i = 0;
  j = 0;

  for (k = left; k<right; k++){
    if (LeftArr[i] <= RightArr[j]){
      A[k] = LeftArr[i];
      i+=1;
      c++;
    }
    else {
	A[k] = RightArr[j];
	j+=1;
	c++;
    }
  }
}


Measured memory_bytes: 5624
//Radhe Radhe
#include<bits/stdc++.h>
#define ll long long
#define fixed cout.setf(ios::fixed);
#define Precise cout.precision(7);
using namespace std;
int main()
{
    ll n,b;
    double x;
    cin>>n;
    x=n/1.08;
    b=ceil(x);
    if(floor(b*1.08)==n)
    cout<<b<<endl;
    else cout<<":("<<endl;

    return 0;
}





Measured memory_bytes: 3656