akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < n; i++)

using namespace std;

int main(void) {
  long N, K;
  cin >> N >> K;
  string S;
  cin >> S;
  char current = S[0];
  long count = 1;
  vector<long> foo;
  for (long i = 1; i < S.size(); i++) {
    if (S[i] == current) count++;
    else {
      foo.push_back(count * (current == '0' ? -1 : 1));
      count = 1;
      current = S[i];
    }
  }
  foo.push_back(count * (current == '0' ? -1 : 1));

  long max_result = 0;
  long result = 0;

  long i = 0;
  long j = 0;
  long can = K;
  for (; j < foo.size(); j++) {
    if (foo[j] < 0 and can <= 0) break;
    if (foo[j] > 0) result += foo[j];
    else {
      result -= foo[j];
      can--;
    }
  } 
  max_result = result;

  while (i < foo.size()) {
    if (foo[i] < 0) {
      can++;
      result += foo[i];
    } else {
      result -= foo[i];
    }
    i++;
    while (j < foo.size()) {
      if (foo[j] < 0 and can <= 0) break;
      if (foo[j] > 0) result += foo[j];
      else {
        result -= foo[j];
        can--;
      }
      j++;
    }
    if (result > max_result) max_result = result;
  }

  cout << max_result << endl;

  return 0;
}


Measured memory_bytes: 1528
###==================================================
### import
#import bisect
from collections import Counter, deque, defaultdict
from copy import deepcopy
#from functools import reduce, lru_cache
#from heapq import heappush, heappop
#import itertools
#import math
#import string
import sys
### stdin
def input(): return sys.stdin.readline()
def iIn(): return int(input())
def iInM(): return map(int, input().split())
def iInM1(): return map(int1, input().split())
def iInLH(): return list(map(int, input().split()))
def iInLH1(): return list(map(int1, input().split()))
def iInLV(n): return [iIn() for _ in range(n)]
def iInLV1(n): return [iIn()-1 for _ in range(n)]
def iInLD(n): return [iInLH() for _ in range(n)]
def iInLD1(n): return [iInLH1() for _ in range(n)]
def sInLH(): return list(input().split())
def sInLV(n): return [input().rstrip('\n') for _ in range(n)]
def sInLD(n): return [sInLH() for _ in range(n)]
### stdout
def OutH(lst, deli=' '): print(deli.join(map(str, lst)))
def OutV(lst): print('\n'.join(map(str, lst)))
### setting
sys.setrecursionlimit(10 ** 6)
### utils
int1 = lambda x: int(x) - 1
### constants
INF = int(1e9)
MOD = 1000000007
dx = (-1, 0, 1, 0)
dy = (0, -1, 0, 1)
###---------------------------------------------------

N, M = iInM()
AB = iInLD(M)

ans = 0
q= deque([[[1], []]]) # [[nodes], [edges]]

while len(q) > 0:
    n, e = q.pop()
    if len(n) == N:
        ans += 1
        continue
    for i in range(M):
        if i in e:
            continue
        if AB[i][0] == n[-1]:
            if AB[i][1] not in n:
                new_n = n[:]
                new_e = e[:]
                new_n.append(AB[i][1])
                new_e.append(i)
                q.append([new_n, new_e])
                continue
        if AB[i][1] == n[-1]:
            if AB[i][0] not in n:
                new_n = n[:]
                new_e = e[:]
                new_n.append(AB[i][0])
                new_e.append(i)
                q.append([new_n, new_e])
                continue

print(ans)
        

Measured memory_bytes: 69392
#include <iostream>
#include <string>
using namespace std;
int main(void){
    // Your code here!
    string S;
    cin >> S;
    int l = S.size();
    int flag1 = 0;
    int flag2 = 0;
    int flag3 = 0;
    
    for(int i=0;i<((l-1)/2);i++){
        if (S.at(i)!=S.at(l-i-1)){
            flag1 = 1;
        }
        if (S.at(i)!=S.at((l-1)/2-i-1)){
            flag2 = 1;
        }
        if (S.at((l+3)/2+i-1)!=S.at(l-i-1)){
            flag3 = 1;
        }
    }
    
    if ((flag1+flag2+flag3)==0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
from collections import Counter
def num_to_comb(val):
    return val*(val-1)//2

num_ = int(input())
ball_list = [int(i) for i in input().split()]

if len(set(ball_list)) == num_:
    for i in range(num_):
        print(0)

elif len(set(ball_list)) == 1:
    for i in range(num_):
        print((num_ - 1)*(num_ - 2) // 2)

else:
    temp = Counter(ball_list)
    ans_dict={}
    temp_ans_dict = {}
    
    for num in set(ball_list):
        if temp_ans_dict.get(temp[num], 0) == 0:
            temp_dict = temp.copy()
            temp_dict[num] = temp_dict[num]-1
            ans_dict[num] = sum(list(map(num_to_comb, temp_dict.values())))
            temp_ans_dict[temp[num]] = ans_dict[num]
        else:
            ans_dict[num] =temp_ans_dict[temp[num]]
            
    for i in ball_list:
        print(ans_dict[i])

Measured memory_bytes: 49652
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx,avx2,fma")

#include<bits/stdc++.h>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define ull unsigned long long
#define inf 2000000000
#define infLL 2000000000000000000
#define MAX 200005
#define sf(a) scanf("%d", &a)
#define sfl(a) scanf("%lld", &a)
#define pf(a) printf("%d\n", a)
#define pfl(a) printf("%lld\n", a)
#define Case(t) printf("Case %d: ", t)
#define pii pair<int, int>
#define MOD 1000000007
#define mod 998244353
#define PI acos(-1.0)
#define eps 1e-9
#define mem(a, b) memset(a, b, sizeof(a))
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

inline int Set(int N, int pos){return N=N | (1<<pos);}
inline int Reset(int N, int pos){return N=N & ~(1<<pos);}
inline bool Check(ll N, ll pos){return (bool)(N & (1LL<<pos));}

inline void normal(ll &a) { a %= mod; (a < 0) && (a += mod); }
inline ll modMul(ll a, ll b) { a %= mod, b %= mod; normal(a), normal(b); return (a * b) % mod; }
inline ll modAdd(ll a, ll b) { a %= mod, b %= mod; normal(a), normal(b); return (a + b) % mod; }
inline ll modSub(ll a, ll b) { a %= mod, b %= mod; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while (p) { if (p & 1LL) r = modMul(r, b); b = modMul(b, b); p >>= 1LL; } return r; }
inline ll modInverse(ll a) { return modPow(a, mod - 2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

ll fast_exp(ll x, ll n, ll m)
{
    ll res = 1;
    while(n>0)
    {
        if(n%2==1)
            res = (res * x) % m;
        x = (x * x) % m;
        n/=2;
    }
    return res%m;
}

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}

clock_t t_Start;
void Start()
{
    t_Start = clock();
}
void End()
{
    double Time = (double)(clock()-t_Start)/CLOCKS_PER_SEC;
    error(Time);
}

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>orderedSet;
typedef tree<int,null_type,greater<int>,rb_tree_tag,tree_order_statistics_node_update>orderedSet1;

int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    //Start();

    FASTIO;
    int a, b, c, d;
    cin>>a>>b>>c>>d;
    int x = (a+d-1)/d;
    int y = (c+b-1)/b;
    if(x>=y)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;

    //End();
    return 0;
}


Measured memory_bytes: 3652
# -*- coding: utf-8 -*-
import sys
# ----------------------------------------------------------------
# Use Solve Function

def solve(lines):
    N,X = map(int, lines.pop(0).split(' '))
    M = []
    for i in range(N):
        M.append(int(lines.pop(0)))
    X -= sum(M)
    min_m = min(M)
    res = N + int(X/min_m)
    print(res)

#
# main
#
lines = [x.strip() for x in sys.stdin.readlines()]

#
# solve !!
#
solve(lines)

Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<n; ++i)
#define all(x) begin(perm),end(perm)
#define showall(obj) for(auto x:obj)cout<<x<<endl;
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
typedef vector<int> vint;
typedef vector<ll> vll;
const int inf = 100100100;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
    int n,m; cin>>n>>m;
    vint num(n,0);
    if(n>1)num[0] = 1;
    map<int,int> p;
    rep(i,m){
        int tc,ts; cin>>ts>>tc;
        if(p.count(ts) == 1){
            if(p[ts] != tc){cout<<-1<<endl; return 0;}
        }else{
            p[ts] = tc;
        }
    }
    rep(i,n){
        if(p.count(i+1) == 1){
            num[i] = p[i+1];
        }
    }
    if(num[0] == 0 && n!= 1){cout<<-1;}
    else for(auto x:num)cout<<x;
}


Measured memory_bytes: 256
a = int(input())
b = int(input())
c = int(input())
x = int(input())

count = 0
for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            if (x - i * 500 - j * 100 - k * 50) == 0:
                count += 1
print(count)

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

class LazySegmentTree
{
    int n;
    using T1 = int;
    using T2 = int;
    T1 id1 = INT_MAX;
    T2 id2 = 0;
    std::vector<T1> node; // min
    std::vector<T2> lazy; // add

    // 遅延評価
    void eval(int k, int l, int r)
    {
        // 遅延配列が空なら終了
        if (lazy[k] == id2)
            return;
        // 遅延配列を適用
        node[k] = node[k] + lazy[k];
        if (r - l > 1)
        {
            lazy[2 * k + 1] = lazy[2 * k + 1] + lazy[k];
            lazy[2 * k + 2] = lazy[2 * k + 2] + lazy[k];
        }
        // 遅延配列初期化
        lazy[k] = id2;
    }

  public:
    LazySegmentTree(int _n)
    {
        int sz = _n;
        n = 1;
        while (n < sz)
            n *= 2;
        // 配列初期化
        node.resize(2 * n - 1, id2);
        lazy.resize(2 * n - 1, id2);
    }
    // 半開区間 [a, b) に対して値 val を反映させる
    void update(int a, int b, T2 val, int l = 0, int r = -1, int k = 0)
    {
        if (r < 0)
            r = n;
        // ノード k で遅延評価
        eval(k, l, r);
        if (b <= l || r <= a)
            return;
        // 区間が被覆されている場合
        if (a <= l && r <= b)
        {
            // 遅延配列更新, 評価
            lazy[k] = lazy[k] + val;
            eval(k, l, r);
        }
        else
        {
            // 子ノードの値を評価し, 更新
            int mid = (l + r) / 2;
            update(a, b, val, l, mid, 2 * k + 1);
            update(a, b, val, mid, r, 2 * k + 2);
            node[k] = std::min(node[2 * k + 1], node[2 * k + 2]);
        }
    }

    // 半開区間 [a, b) に対してクエリを投げる
    T1 query(int a, int b, int l = 0, int r = -1, int k = 0)
    {
        if (r < 0)
            r = n;
        eval(k, l, r);
        // 範囲外なら単位元返す
        if (b <= l || r <= a)
            return id1;
        if (a <= l && r <= b)
            return node[k];
        int mid = (l + r) / 2;
        T1 vl = query(a, b, l, mid, 2 * k + 1);
        T1 vr = query(a, b, mid, r, 2 * k + 2);
        return std::min(vl, vr);
    }
};

using namespace std;

void solve_dsl_2_h()
{
    int n, q;
    cin >> n >> q;
    LazySegmentTree lst(n);
    while (q--)
    {
        int type;
        cin >> type;
        if (type == 0)
        {
            int s, t, x;
            cin >> s >> t >> x;
            t++;
            lst.update(s, t, x);
        }
        else
        {
            int s, t;
            cin >> s >> t;
            t++;
            cout << lst.query(s, t) << endl;
        }
    }
}

int main()
{
    solve_dsl_2_h();
}



Measured memory_bytes: 4960
import heapq

n, m = map(int, input().split())
graph = [[] for i in range(n)]
memo = [[0 for i in range(n)] for j in range(n)]
for i in range(m):
    a, b, c = map(int, input().split())
    graph[a-1].append((b-1, c))
    graph[b-1].append((a-1, c))

INF = float('inf')

def dijkstra(s):
    dist = [INF for i in range(n)]
    dist[s] = 0
    q = [(0, s, -1)]
    while q:
        cost, node, parent = heapq.heappop(q)
        if dist[node] < cost:
            continue
        if parent != -1:
            memo[parent][node] = 1
        for no, co in graph[node]:
            if dist[node] + co < dist[no]:
                dist[no] = dist[node] + co
                heapq.heappush(q, (dist[node]+co, no, node))

for v in range(n):
    dijkstra(v)

ans = 0
for i in range(n):
    for j in range(i+1, n):
        if memo[i][j] == 1:
            ans += 1

print(m - ans)

Measured memory_bytes: 3316
using System;
using System.Linq;

namespace B.Cut_and_Count
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var S = Console.ReadLine();
            int cnt = 0;

            for (int i = 0; i < S.Length; i++)
            {
                var SA = S.Substring(0, S.Length - i).Distinct().ToArray();
                var SB = S.Substring(S.Length - i, i).Distinct().ToArray();

                cnt = Math.Max(cnt, SA.Count(x => SB.Contains(x)));
            }

            Console.WriteLine(cnt);
        }
    }
}


Measured memory_bytes: 13396
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <climits>
#include <stack>
#include <queue>
#include <set>
#include <cctype>
#include <bitset>
#include <type_traits>
#include <numeric>

#include <list>
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define YES(j) cout << (j ? "YES" : "NO") << endl;
#define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
#define yes(j) std::cout << (j ? "yes" : "no") << endl;



int main(void)
{
    string s;
    cin >> s;
    int ans1, ans2;
    ans1 = ans2 = 0;
    // ans1 01010101
    // ans2 10101010
    REP(i,s.length())
    {
        if(i%2==0)
        {
            if(s[i]=='0')
            {
                ans2++;
            }
            else
            {
                ans1++;
            }
            
        }
        else
        {
            if(s[i]=='0')
            {
                ans1++;
            }
            else
            {
                ans2++;
            }
        }
        
    }
    cout << min(ans1,ans2) << endl;
}


Measured memory_bytes: 512
n,h=map(int,input().split())
ab=[list(map(int,input().split())) for i in range(n)]
a_max=0
b=[]
ans=0
kaisuu=0
for i in range(n):
  if a_max<ab[i][0]:
    a_max=ab[i][0]
for i in range(n):
  b.append(ab[i][1])
b.sort(reverse=True)
i=0
while True:
  if len(b)>i and a_max<b[i]:
    h-=b[i]
    kaisuu+=1
  else:
    if h%a_max==0:
      kaisuu+=(h//a_max)
    else:
      kaisuu+=((h//a_max)+1)
    break
  if h<=0:
    break
  i+=1
print(kaisuu)  

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

using namespace std;

//#define int long long

using ll = long long;
using pii =  pair<int, int>;

const int IINF =  0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const int INF = sizeof(int) == sizeof(long long) ? LINF : IINF;
const ll MOD = 1e9+7;

#define for_(i, a, b) for(int i = (a);i < (b);++i)
#define rfor_(i, a, b) for(int i = (b)-1;i >= (a);--i)

#define rep(i, n) for_(i, 0, n)
#define rrep(i, n) rfor_(i, 0, n)

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ft first
#define sd second

#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define rev(a) reverse(all(a))

#define endl '\n'

const int limit = 100007;

int N, R, B;
char c;

signed main() {
  cin.tie(0);cout.tie(0);
  ios_base::sync_with_stdio(false);

  cin >> N;
  rep(i, N) {
    cin >> c;
    if(c=='R') ++R;
    else ++B;
  }

  if(R>B) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 256
// Problem : A - Wanna go back home
// Contest : AtCoder - AtCoder Grand Contest 003
// URL : https://atcoder.jp/contests/agc003/tasks/agc003_a
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
using namespace std; 
#define ll long long int
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define INF LLONG_MAX
#define PI acos(-1)
const ll MOD = 1e9 + 7;
#define fir first
#define sec second
#define all(x) x.begin(),x.end()
#define mem(a,b) memset(a,b,sizeof(a))
#define rep(c,a,b) for(ll c=a;c<b;c++)
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define min_heap priority_queue<pll,vector<pll>,greater<pll> >
ll dx4[]={-1,1,0,0};
ll dy4[]={0,0,-1,1};
ll dx8[]={-1,-1,-1,0,1,1,1,0};
ll dy8[]={-1,0,1,1,1,0,-1,-1};
bool isvalid(ll x,ll y,ll n,ll m)
{
    return (x>=0 and y>=0 and x<n and y<m);
}
ll isprime[1000];
vector<ll> prime;
void sievetoprime(ll n)
{
    mem(isprime,true);
    for(ll p=2;p*p<=n;p++)
    {
        if(isprime[p]==true)
        {
            for(ll i=p*p;i<=n;i+=p)
                isprime[i]=false;
        }
    }
}
ll lcm(ll a,ll b)
{
    return (a/__gcd(a,b))*b;
}
void solve()
{
    string s;
    cin>>s;
    map<char,ll> cnt;
    rep(i,0,s.size())
    {
    	cnt[s[i]]=1;
    }
    ll a=cnt['N'];
    ll b=cnt['S'];
    ll c=cnt['E'];
    ll d=cnt['W'];
    ll ok=0;
    if(a==0)
   	{
   		if(b==0)
   			ok=1;
   	}
   	else
   	{
   		if(b!=0)
   			ok=1;
   	}
   	if(c==0)
   	{
   		if(d==0)
   			ok+=1;
   	}
   	else
   	{
   		if(d!=0)
   			ok+=1;
   	}
   	if(ok==2)
   		cout<<"Yes";
   	else
   		cout<<"No";
}
int main()
{
    ll inpoup = 0;
    if(inpoup==1)
    {
        #ifndef ONLINE_JUDGE
            freopen("input.txt","r",stdin);
            freopen("output.txt","w",stdout);
        #endif
    }
    IOS
    ll t;
    t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
}

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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int N, Q;
string S;
set <int> st[26];

int Add(){
  int loc; char C; cin >> loc >> C;

  for (int i = 0; i < 26; i++){
    st[i].erase(loc);
  }
  st[C-'a'].insert(loc);
  return 0;
}

int Solve(){
  int L, R; cin >> L >> R;

  int ans = 0;
  for (int i = 0; i < 26; i++){
    auto iter = st[i].lower_bound(L);
    if (iter == st[i].end()) continue;
    if (*iter <= R) ans++;
  }
  cout << ans << endl;

  return 0;
}

int main(){
  cin >> N >> S >> Q;

  for (int i = 1; i <= N; i++){
    st[S[i-1] - 'a'].insert(i);
  }

  for (int i = 0; i < Q; i++){
    int num; cin >> num;
    if (num == 1) Add();
    else Solve();
  }

  return 0;
}


Measured memory_bytes: 27168
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;

int main(){
    int n;
    cin >> n;
    vector<ll> a(n);
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    ll tot_sum = 0;
    for(int i=0;i<n;i++){
        tot_sum += a[i];
    }
    ll ans = 0;
    for(int i=0;i<n-1;i++){
        tot_sum -= a[i];
        ll temp_sum = tot_sum%MOD;
        ll temp = temp_sum*a[i];
        temp %= MOD;
        ans += temp;
        ans %= MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 4832
if __name__ == "__main__":
    abc = [int(i) for i in input().split(" ")]
    abc.sort()
    if abc[0] == abc[1]:
        if abc[1] != abc[2]:
            print("Yes")
            exit(0)
    else:
        if abc[1] == abc[2]:
            print("Yes")
            exit(0)
    print("No")


Measured memory_bytes: 2940
#include <stdio.h>

int main(void) {
  int a,b,n,m,tmp;
  
  while (scanf("%d %d",&a,&b)==2) {
    n = a; m = b;
    while (n%m != 0) {
      tmp = m;
      m = n%m;
      n = tmp;
    }
    printf("%d %d\n",m,a/m*b);
  }
  
  return 0;
}

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

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcount

using namespace std;

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

template <typename T> T id(T b) {return b;};
template <class It> bool all(It f,It l){return std::all_of(f,l,id<bool>);}
template <class It> bool any(It f,It l){return std::any_of(f,l,id<bool>);}
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}

const int MAX_N = 400;
int n;
int a[MAX_N];
bool vis[MAX_N][MAX_N];
ll memo[MAX_N][MAX_N];

ll rec(int l, int r) {
  if (r <= l) return 0;

  if (vis[l][r]) return memo[l][r];

  vis[l][r] = true;

  ll res = LLONG_MAX;
  ll total = accumulate(a+l,a+r+1,0LL);
  for (int i = l; i < r; i++) {
    chmin(res, rec(l,i) + rec(i+1,r) + total);
  }

  return memo[l][r] = res;
}

int main()
{
#ifdef FASTIO
  ios_base::sync_with_stdio(false); cin.tie(nullptr);
#endif

  cin >> n;
  forn(i,n) cin >> a[i];

  cout << rec(0,n-1) << endl;


  return 0;
}


Measured memory_bytes: 1664
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();

int main() {
    int n, m, k, val;
    cin >> n >> m;
    int ans = 0;
    vector<vector<int>> mat(n, vector<int>());
    for(int i = 0; i < m; i++) {
        cin >> k;
        while(k--) {
            cin >> val;
            mat[--val].push_back(i);
        }
    }
    vector<int> bulb(m, 0);
    for(int& val: bulb) {
        cin >> val;
    }
    for(int state = 0; state < (1<<n); state++) {
        vector<int> bulb2 = bulb;
        for(int i = 0; i < n; i++) {
            if ((state >> i) & 1) {
                for(int idx: mat[i]) {
                    bulb2[idx] += 1;
                }
            }
        }
        int acc = 0;
        for(int val: bulb2) {
            acc += val % 2;
        }
        if (acc == 0) {
            ans += 1;
            // cout << "state " << state << endl;
        }
    }
    cout << ans << endl;
    return 0;
}




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

using namespace std;

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

    int n,a,b;
    cin>>n;
    if(n==1)
    {
        cout<<"Hello World\n";
    }
    else
    {
        cin>>a>>b;
        cout<<a+b<<endl;
    }
    return 0;
}


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

int main(){
  int a, b;
  string op;
  cin >> a >> op >> b;
  if(op=="+") cout << a + b << endl;
  else cout << a - b << endl;



}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9 + 7);

int main(void) {
	int a, b, c;
	cin >> a >> b >> c;
	
	bool yes = false;
	int i = 1;
	while( i * a <= a * b ) {
		if( (i * a) % b == c ) {
			yes = true;
			break;
		}
		
		i++;
	}
	
	if( yes ) cout << "YES" << endl;
	else cout << "NO" << endl;

	return 0;
}


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

constexpr int N = 100010;

int a[N][3];
int dp[N][3];

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

  memset(dp, 0, sizeof(dp));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> a[i][j];
    }
  }

  for (int i = 0; i < 3; i++) {
    dp[0][i] = a[0][i];
  }

  for (int i = 1; i < n; i++) {
    for (int j = 0; j < 3; j++) {
      for (int k = 0; k < 3; k++) {
        if(j == k) continue;

        dp[i][k] = max(dp[i][k], dp[i-1][j] + a[i][k]);
      }
    }
  }

  int ans = 0;
  for (int i = 0; i < 3; i++) {
    ans = max(ans, dp[n-1][i]);
  }
  cout << ans << '\n';
}

Measured memory_bytes: 2560
//		Knapsack
#include<bits/stdc++.h>
using namespace std;
vector<int> v,w;
long long int arr[105][100000];
long long max(long long a,long long b){
	if(a>b) return a;
	return b;
}
main(){
	//printf("WTF");
	int item,maxW,temp1,temp2;
	scanf("%d %d",&item,&maxW);
	for(int i=0;i<item;i++){
		scanf("%d %d",&temp1,&temp2);
		w.push_back(temp1);
		v.push_back(temp2);
	}
	/*for(int i=0;i<item;i++){
		scanf("%d",&temp1);
		v.push_back(temp1);
	}
	for(int i=0;i<item;i++){
		scanf("%d",&temp1);
		w.push_back(temp1);
	}*/
	for(int i=0;i<item;i++){
		for(int j=1;j<=maxW;j++){
			
			if(j>=w[i]){
				
				if(i==0) arr[i][j]=v[i];
				else arr[i][j]=max(arr[i-1][j],arr[i-1][j-w[i]]+v[i]);
				
			}
			else{
				if(i==0) arr[i][j]=0;
				else arr[i][j]=arr[i-1][j];
			}
		}
	}
	printf("%lld",arr[item-1][maxW]);
}
/*
10 165
92
   57
   49
   68
   60
   43
   67
   84
   87
   72
   23
   31
   29
   44
   53
   38
   63
   85
   89
   82
*/
/*
24 6404180
825594
1677009
1676628
1523970
943972
97426
69666
1296457
1679693
1902996
1844992
1049289
1252836
1319836
953277
2067538
675367
853655
1826027
65731
901489
577243
466257
369261
382745
799601
909247
729069
467902
44328
34610
698150
823460
903959
853665
551830
610856
670702
488960
951111
323046
446298
931161
31385
496951
264724
224916
169684
*/


Measured memory_bytes: 80128
//Optional FAST

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native")

//Required Libraries

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

//Required namespaces

using namespace std;
using namespace __gnu_pbds;

//Required defines

#define endl '\n'

#define READ(X) cin>>X;
#define READV(X) long long X; cin>>X;
#define READAR(A,N) long long A[N]; for(long long i=0;i<N;i++) {cin>>A[i];}
#define rz(A,N) A.resize(N);
#define sz(X) (long long)(X.size())
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define trav(x,A) for(auto &x:A)
#define FORI(a,b,c) for(long long a=b;a<c;a++)
#define FORD(a,b,c) for(long long a=b;a>c;a--)

//Required typedefs

typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
typedef vector<int> veci;
typedef vector<long long> vecl;

//Required Constants

const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);
const long long INIT=(long long)(1e6+1);

//Required Functions

ll power(ll x,ll y) 
{ 
	if (y == 0) 
		return 1; 
	ll p = power(x, y/2) % MOD; 
	p = (p * p) % MOD; 
  
	return (y%2 == 0)? p : (x * p) % MOD; 
}
ll modInverse(ll a) 
{ 
   return power(a,MOD-2); 
   
}

//Work

int main()
{
	#ifndef ONLINE_JUDGE
	if (fopen("INPUT.txt", "r"))
	{
		freopen ("INPUT.txt" , "r" , stdin);
		//freopen ("OUTPUT.txt" , "w" , stdout);
	}
	#endif
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	clock_t clk;
	clk = clock();
//-----------------------------------------------------------------------------------------------------------//

	READV(N);
	READV(A);
	READV(B);
	ll a1=1,a2=1;
	FORI(i,1,A+1)
	{
		a1=(a1*modInverse(i))%MOD;
		a1=(a1*(N-i+1))%MOD;
	}
	FORI(i,1,B+1)
	{
		a2=(a2*modInverse(i))%MOD;
		a2=(a2*(N-i+1))%MOD;
	}
	ll ans=(power(2,N)-1+MOD)%MOD;
	ans=(ans-a1+MOD)%MOD;
	ans=(ans-a2+MOD)%MOD;
	cout<<ans<<endl;

//-----------------------------------------------------------------------------------------------------------//


	clk = clock() - clk;
	cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << endl;

	return 0;
}

Measured memory_bytes: 384
# include <iostream>
# include <cmath>
# include <algorithm>
# include <stdio.h>
# include <cstdint>
# include <cstring>
# include <string>
# include <cstdlib>
# include <vector>
# include <bitset>
# include <map>
# include <queue>
# include <ctime>
# include <stack>
# include <set>
# include <list>
# include <random>
# include <deque>
# include <functional>
# include <iomanip>
# include <sstream>
# include <fstream>
# include <complex>
# include <numeric>
# include <immintrin.h>
# include <cassert>
# include <array>
# include <tuple>
# include <unordered_map>
# include <unordered_set>
# include <thread>

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using ui32 = unsigned int;
constexpr ll INFLL = 1e18;

#define CHECK_IMPL1(cond)              \
if (!(cond)) {                         \
    DEBUG("expected cond: " << #cond); \
    assert(cond);                      \
}

#define CHECK_IMPL2(cond, message)                                            \
if (!(cond)) {                                                                \
    DEBUG("expected cond: " << #cond << " failed with message: " << message); \
    assert(cond);                                                             \
}
#define CHECK_IMPL(_1, _2, NAME, ...) NAME
#define CHECK(...) CHECK_IMPL(__VA_ARGS__, CHECK_IMPL2, CHECK_IMPL1, CHECK_IMPL0)(__VA_ARGS__)

#ifdef __APPLE__
#define DEBUG(message) std::cerr << message << std::endl;
#else
#define DEBUG(message)
#endif

void solve() {
  string s;
  cin >> s;
  vector<char> st;
  for (auto ch : s) {
    while (st.size() >= 2) {
      size_t index = st.size() - 2;
      if (st[index] != ch) {
        st.pop_back();
      } else {
        break;
      }
    }
    st.push_back(ch);
  }
//  for (auto ch : st) {
//    cout << ch;
//  }
//  cout << endl;
  if ((s.size() - st.size()) % 2 == 0) {
    cout << "Second\n";
  } else {
    cout << "First\n";
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
#ifdef __APPLE__
  freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
#endif
  int t = 1;
//  cin >> t;
  for (int i = 1; i <= t; i++) {
    solve();
  }
  return 0;
}


Measured memory_bytes: 640
N = int(input())
L = list(map(int, input().split()))
count = 0
k = 0
for i in range(10000):
    for j in range(N):
        if L[j]%2 == 0:
            L[j] = int(L[j]/2)
        else:
            k = 1
            break
    if k == 1:
        break
    count += 1
    
print(count)

Measured memory_bytes: 3060
#!/usr/bin/env python3
#ABC137 C

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

def comb(n,r):
    return math.factorial(n)//math.factorial(n-r)//math.factorial(r)
n = I()
s = [input() for _ in range(n)]
x = [list(Counter(s[i]).items()) for i in range(n)]
for i in x:
    i.sort()

y = [tuple(i) for i in x]
f = defaultdict(lambda : 0)
for i in range(n):
    f[y[i]] += 1
ans = 0
for i in f.values():
    if i < 2:
        continue
    ans += comb(i,2)
print(ans)


Measured memory_bytes: 105084
import sys

def read_int():
    line = sys.stdin.readline().rstrip('\n')
    return int(line)

def read_int_list():
    line = sys.stdin.readline().rstrip('\n')
    return [int(e) for e in line.split(' ')]

def count(field, di, dj, H, W):
    ans = 0
    for i in range(H):
        if not (di & (1 << i)):
            continue
        for j in range(W):
            if not (dj & (1 << j)):
                continue
            if field[i][j] == '#':
                ans += 1
    return ans

H, W, K = read_int_list()
field = []
for _ in range(H):
    field.append(sys.stdin.readline().rstrip('\n'))

ans = 0
for di in range(2**H):
    for dj in range(2**W):
        count_k = count(field, di, dj, H, W)
        if count_k == K:
            ans += 1
print(ans)

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

int main(){
    int N,K;
    cin >> N >> K;
    string S;
    cin >> S;
    int flip = 0,ans = 0;
    for(int i=0;i<N-1;i++){
        if(S[i]!=S[i+1]) flip++;
        if(S[i]=='L') continue;
        if(S[i+1]=='R') ans++;
    }   
    for(int i=N-1;i>=1;i--){
        if(S[i]=='R') continue;
        if(S[i-1]=='L') ans++;
    }
    if((flip+1)/2<=K) cout << N-1 << endl;
    else cout << ans+2*K << endl;
}

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

    int main()
    {
       char string[1000000], ch;
       int c = 0, count[26] = {0},p=0;
       gets(string);
       while ( string[c] != '\0' )
       {

          if ( string[c] >= 'a' && string[c] <= 'z' )
             count[string[c]-'a']++;

          c++;
       }

       for ( c = 0 ; c < 26 ; c++ )
       {
          if( count[c] == 0 )
          {
              printf("%c\n",c+'a');
              p=1;
             break;
          }

       }
       if(p==0)printf("None\n");

       return 0;
    }


Measured memory_bytes: 256
#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 ordered_set tree<ll, null_type , less<ll> , rb_tree_tag , tree_order_statistics_node_update> 
#define ll long long
#define ull unsigned long long
#define pb push_back
#define inf 1e18
#define mk make_pair
#define ld long double
#define mod 1000000007
#define fi first
#define se second
#define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define test ll t; cin>>t; while(t--)
#define setbits __builtin_popcount
#define endl '\n'
#define LOCAL
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i));}
sim, class b dor(pair < b, c > d) {
    ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
    *this << "[";
    for (auto it = d.b; it != d.e; ++it)
        *this << ", " + 2 * (it == d.b) << *it;
    ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define maxn 500001
vector<ll>bit(maxn);
vector<ll>a(maxn);
pair<pair<ll,ll>,ll>p[maxn];
bool comp(const pair<pair<ll,ll>,ll>&p,const pair<pair<ll,ll>,ll>&p1)
{
    if(p.fi.se==p1.fi.se)
    {
        return p.fi.fi<p1.fi.fi;
    }
    return p.fi.se<p1.fi.se;
}
void update(ll index,ll val)
{
    while(index<maxn)
    {
        bit[index]+=val;
        index+=index&-index;
    }
}
ll get(ll index)
{
    ll ans=0;
    while(index>0)
    {
        ans+=bit[index];
        index-=index&-index;
    }
    return ans;
}
int main()
{
    fastIO;
    ll n,q;
    cin>>n>>q;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    for(int i=0;i<q;i++)
    {
        cin>>p[i].fi.fi>>p[i].fi.se;
        p[i].se=i;
    }
    sort(p,p+q,comp);
    map<ll,ll>m;
    ll x=0;
    vector<ll>ans(q);
    for(int i=0;i<n;i++)
    {
        if(m.find(a[i])!=m.end())
        {
            update(m[a[i]],-1);
        }
        m[a[i]]=i+1;
        update(m[a[i]],1);
        while(x<q && p[x].fi.se==i+1)
        {
            ll val=get(p[x].fi.se)-get(p[x].fi.fi-1);
            ans[p[x].se]=val;
            x++;
        }
    }
    for(auto itr:ans)
    {
        cout<<itr<<endl;
    }
}

Measured memory_bytes: 58484
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define EPS (1e-10)
#define equals(a, b) (fabs((a)-(b)) < EPS)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
  
int main() {
  int A,B;
  cin >> A >> B;
  cout << A*B << endl;
  return 0;
}

Measured memory_bytes: 3584
import math

def is_int(a, b):
  dist = 0
  for i in range(D):
    dist = dist + (a[i] - b[i])**2
  dist = math.sqrt(dist)
  flag = dist.is_integer()
  return flag


N, D = map(int, input().split())
X_list = []
for i in range(N):
  X = list(map(int, input().split()))
  X_list.append(X)

count = 0
for i in range(N):
  for j in range(i+1, N):
    if is_int(X_list[i], X_list[j]):
      count += 1
print(count)

Measured memory_bytes: 3064
#include<iostream>

using namespace std;

int main() {
	int a, b, c, n = 3;

	cin >> a >> b >> c;

	if (a == b) n--;
	if (b == c) n--;
	if (c == a) n--;
	if (n == 0) n = 1;

	cout << n << endl;

	return 0;

}



Measured memory_bytes: 256
$mod = 10**9+7
$fact = Array.new(10**5+2,0)
$exp = Hash.new(nil)
$fact[0] = 1
for i in 1..10**5+1
  $fact[i] = ($fact[i-1]*i)%$mod
end
def exp(a,b)
  if $exp[a]
    $exp[a]
  elsif b == 0
    1
  elsif b%2 == 0
    $exp[a] = (exp(a,b/2)**2)%$mod
  else
    $exp[a] = (a*exp(a,b-1))%$mod
  end
end
def combi(n,r)
  ($fact[n]*exp($fact[n-r],$mod-2)*exp($fact[r],$mod-2))%$mod
end
n = gets.to_i
a = gets.chomp.split(" ").map(&:to_i)
b = Array.new(n,-1)
for i in 0..n
  if b[a[i]-1] != -1
    c = i-b[a[i]-1]
    break
  else
    b[a[i]-1] = i
  end
end
for i in 1..n+1
  if n-c >= i-1
    puts (combi(n+1,i)-combi(n-c,i-1)+$mod)%$mod
  else
    puts combi(n+1,i)
  end
end

Measured memory_bytes: 20244
#include <iostream>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)
using ll = long long;

int main() {
    string S;cin>>S;
    ll cnt = 0, ans = 0;
    REP(i,S.size()){
        if(S[i]=='B') ++cnt;
        else if(cnt) ans += cnt;
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 640
#include <set>
#include <iostream>
#include <cstdio>
#include <vector>
#include <climits>
#include <queue>
using namespace std;
int main(){
	int n,k;
	scanf("%d%d",&n,&k);
	vector<int> c(n),r(n);
	for(int i=0; i<n; i++) scanf("%d%d",&c[i],&r[i]);
	vector<vector<int>> path(n,vector<int>());
	for(int x,y,i=0; i<k; i++){
		scanf("%d%d",&x,&y);
		path[x-1].push_back(y-1);
		path[y-1].push_back(x-1);
	}
	vector<vector<int>> route(n,vector<int>());
	queue<pair<int,int>> q;
	for(int i=0; i<n; i++){
		vector<bool> visit(n,false);
		visit[i] = true;
		q.push(make_pair(i,r[i]));
		for(;q.size();){
			int now = q.front().first;
			int rem = q.front().second;
			q.pop();
			for(int j=0; j<path[now].size(); j++){
				if(!visit[path[now][j]]){
					visit[path[now][j]] = true;
					route[i].push_back(path[now][j]);
					if(rem > 1){
						q.push(make_pair(path[now][j],rem-1));
					}
				}
			}
		}
	}
	priority_queue<pair<int,int>> pq;
	vector<int> dist(n,INT_MAX);
	pq.push(make_pair(dist[0]=0,0));
	for(;pq.size();){
		int cost = pq.top().first;
		int now = pq.top().second;
		pq.pop();
		for(int i=0; i<route[now].size(); i++){
			int to = route[now][i];
			if(dist[to] > c[now]+cost){
				pq.push(make_pair(dist[to] = c[now]+cost,to));
			}
		}
	}
	cout<<dist[n-1]<<endl;
}

Measured memory_bytes: 70444
#include <bits/stdc++.h>
using namespace std;
// #define dump(x) cerr << #x << " : " << (x) << " "
#define dump(x) cout << x << endl
#define rep(i, n) for(int i = 0; i < n; ++i)

int main() {
  int n;
  cin >> n;
  int ret = n;
  int cnt;
  rep(i, n+1) {
    int x = i;
    cnt = 0;
    while (x > 0) {
      cnt += x%6;
      x /= 6;
    }
    x = n-i;
    while (x > 0) {
      cnt += x%9;
      x /= 9;
    }
    if (ret > cnt) {
      ret = cnt;
    }
  }
  dump(ret);
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll int
#define fi first
#define deb(x) cout<<#x<<" "<<x<<endl;
#define debarr(a) cout<<#a<<endl;for(auto i: a) cout<<i<<" ";
#define se second
#define cnt(i) __builtin_popcountll(i)
#define pb emplace_back
#define append(j) pb(j)
#define print(p) cout<<p<<endl;
#define mp make_pair
#define len(w) w.size()
#define tuple(p,q) mp(p,q)
#define tc while(t--)
#define fo(n) for(int i=0;i<n;i++)
#define foj(m,n) for(int j=m;j<n;j++)
#define INF 9999999999
#define pra(a,n) fo(n)cout<<a[i]<<" ";cout<<endl;
#define vp vector<pair<int,int>>
#define vc vector<int>
#define all(v) (v.begin(),v.end())
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pp pair<ll,ll>
#define ispow2(x)  x && (!(x&(x-1)))
#define copy(a,b,n) copy_n(a,n,b) 
#define create(a,m,n) iota(a,a+n,m)
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define maximum(a,n)  ll* i1,maxi; i1 = std::max_element(a, a+n);maxi=*i1 
#define minimum(a,n)  ll* i1,mini; i1 = std::min_element(a, a+n);mini=*i1 
using namespace std;
ll n,m,k,s,dis[100005][101]={0},x,y,g,h;
#define MAXN (ll)1e6+5


				
signed main(){
    fio
    cin>>n;
    ll a[n][3],dp[n][3][3]={0};
    fo(n)
    cin>>a[i][0]>>a[i][1]>>a[i][2];
    fo(n)
    if(i==0)
    {for(ll j: {0,1,2})
        dp[i][0][j]=dp[i][1][j]=dp[i][2][j]=a[i][j];
    }
    else
    {
        for(ll j:{0,1,2})
        for(ll k: {0,1,2})
        if(j==k)
        continue;
        else
        for(ll l:{0,1,2})
        dp[i][j][k]=max(dp[i][j][k],dp[i-1][l][j]+a[i][k]);
    }
    ll maxi=0;
    
    for(ll j:{0,1,2})
        for(ll k: {0,1,2})
            maxi=max(maxi,dp[n-1][j][k]);
        
    cout<<maxi;
    return 0;
}

Measured memory_bytes: 8340
#include <bits/stdc++.h>
using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
//const int mod= int(1e9)+7;
const int mod=998244353;
using P = pair<int,int>;
using Pl= pair<ll,ll>;
using ld=long double;
using V=vector<int>;
using Vl=vector<ll>;
using VV=vector<vector<int>>;
using VVl=vector<vector<ll>>;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;cin >>n;
    vector<string>s(n);
    for (int i = 0; i < n; ++i) {
        cin >>s[i];
    }
    ll ans=0;
    int a=0;
    for (int b = 0; b < n; ++b) {
            bool flg=true;
            for (int i = 0; i <n; ++i) {
                for (int j =0; j <n; ++j) {
                    if(i<=j)break;
                    int i2,j2,iv,jv;
                    i2=(i+a)%n;j2=(j+b)%n;
                    iv=(j+a)%n;jv=(i+b)%n;
                    if(s[i2][j2]!=s[iv][jv]){
                        flg=false;
                        break;
                    }
                }
                if(!flg)break;
            }
            if(flg)ans++;
    }
    cout <<ans*n<<"\n";
}


Measured memory_bytes: 3748
package main

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

func getNextLine(scanner *bufio.Reader) string {
	var buffer string
	for {
		line, isPrefix, _ := scanner.ReadLine()
		buffer += string(line)
		if isPrefix == false {
			break
		}
	}
	return buffer
}

func getIntList(scanner *bufio.Reader) []int {
	list := strings.Split(getNextLine(scanner), " ")
	l := len(list)
	result := make([]int, l)
	for i := 0; i < l; i++ {
		result[i], _ = strconv.Atoi(list[i])
	}
	return result
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := bufio.NewReader(fp)

	s := getNextLine(scanner)
	fmt.Println(chokudai(s))
}

func chokudai(s string) string {
	part1, _ := strconv.Atoi(s[0:2])
	part2, _ := strconv.Atoi(s[2:4])
	if isM(part1) == true && isM(part2) == true {
		return "AMBIGUOUS"
	}
	if isM(part1) == true && isM(part2) == false {
		return "MMYY"
	}
	if isM(part1) == false && isM(part2) == true {
		return "YYMM"
	}
	return "NA"
}
func isM(m int) bool {
	if m == 0 || m > 12 {
		return false
	}
	return true
}


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

int a[11]; 
bool f(int n){
	while(n > 0){
		if(a[n%10] == 1){
			return false;
		}
		n /= 10;
	}
	return true;
}

int main(){
	int n, k, tmp;
	cin >> n >> k;
	for(int i = 1; i<= k; i++){
		cin >> tmp;
		a[tmp] = 1;
	}
	
	while(true){
		if(!f(n))
			n++;
		else{
			cout << n; 
			break;
		}
	}
	
	return 0;
}

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

using namespace std;

const int N = 8;

int x[N + 7];
int y[N + 7];

double dist (int i, int j) {
	return sqrt(abs(x[i] - x[j]) * abs(x[i] - x[j]) + abs(y[i] - y[j]) * abs(y[i] - y[j]));
}

double calculate (vector<int> &v) {
	double sum = 0;

	for (int i = 0; i + 1 < v.size(); i++) {
		sum += dist(v[i], v[i + 1]);
		// cerr << v[i] << " " << v[i + 1] << " " << dist(v[i], v[i + 1]) << "\n";
	}

	return sum;
}

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

	vector<int> is;

	for (int i = 1; i <= n; i++) {
		is.push_back(i);
	}

	for (int i = 1; i <= n; i++) {
		cin >> x[i] >> y[i];
	}

	double sum = 0;

	int cnt = 0;

	do {
		sum += calculate(is);
		cnt++;
	}
	while (next_permutation(is.begin(), is.end()));

	printf("%.6lf\n", sum / cnt * 1.0);

	return 0;
}

Measured memory_bytes: 256
// inputに入力データ全体が入る
function Main(input) {
	input = input.split("\n");
	var tmp = input[0].split(" ");
  	
  	tmp.sort((a,b) => a - b);
		
	//出力
	console.log(parseInt(tmp[0]) + parseInt(tmp[1]));
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7500