akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define dump(x) cerr<<#x<<": "<<x<<endl;
#define bit(k) (1LL<<(k))
typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 >& p) {
  os << "{" <<p.first << ", " << p.second << "}";
  return os;
}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = (ll)1e9+7;
const double PI = acos(-1.0);
/*
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string dir = "DRUL";
*/

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

    string S;
    cin >> S;
    cout << S.substr(0,3) << endl;
}

Measured memory_bytes: 3652
import copy
S=input()
lst=[]
def Sum(l,S):
    if S=="A":
        return sum(l)
    a=l.pop()
    x=copy.copy(l)
    x.append(a*10+int(S[0]))
    y=copy.copy(l)
    y.extend([a,int(S[0])])
    return Sum(x,S[1:])+Sum(y,S[1:])
S+="A"
lst.append(int(S[0]))
print(Sum(lst,S[1:]))

Measured memory_bytes: 38640
#include<bits/stdc++.h>
#include<iomanip>
#define FOR(i,a,b) for(int i=(a);i<(int)(b);++i)
#define REP(i,n) FOR(i,0,n)

using namespace std;


int main(){
  int n;
  cin>>n;
  vector<int> a(n);
  long long x=0;
  REP(i,n){
    cin>>a[i];
    x=(i%2)?x-a[i]:x+a[i];
  }
  x/=2;
  vector<int> ans(n);
  ans[0]=x;
  REP(i,n-1){
    ans[i+1]=a[i]-ans[i];
  }
  REP(i,n)ans[i]*=2;
  cout<<fixed<<setprecision(6);
  REP(i,n){
    cout<<ans[i];
    if(i==n-1)cout<<endl;
    else cout<<endl;
  }
}


Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define _GLIBCXX_DEBUG
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
const ll INF = 9223372036854775807;

int main() {
  ll N, M;cin >> N >> M;
  vector<ll> H(N);
  rep(i, N) cin >> H[i];
  vector<vector<ll>>bri(M, vector<ll>(2));
  rep(i, M) rep(j, 2) cin >> bri.at(i).at(j);
  vector<vector<ll>>S(N, vector<ll>(0));
  rep(i, M) {
    S.at(bri.at(i).at(0) - 1).push_back(bri.at(i).at(1) - 1);
    S.at(bri.at(i).at(1) - 1).push_back(bri.at(i).at(0) - 1);
  }
  ll Ans = 0;
  rep(i, N) {
    ll count = 0;
    rep(j, S.at(i).size())  if (H[i] <= H[S.at(i).at(j)]) count++;
    if (count == 0) Ans++;
  }
  cout << Ans << endl;
}

Measured memory_bytes: 15404
# 2019-11-14 20:54:46(JST)
import sys
# import collections
# import math
# from string import ascii_lowercase, ascii_uppercase, digits
# from bisect import bisect_left as bi_l, bisect_right as bi_r
import itertools
# from functools import reduce
# import operator as op
# from scipy.misc import comb # float
# import numpy as np 

def main():
    n, k = [int(x) for x in sys.stdin.readline().split()]
    # ある１地点を経由してそれ以外の全てにいくのが最も多く
    # これは (n - 1) * (n - 2) // 2　通り
    # kがこれより大きいときには存在せず、それ以下の時は理論上存在する
    if k > (n - 1) * (n - 2) // 2:
        print(-1)
        sys.exit()
    all_combs = list(itertools.combinations(range(1, n+1), 2))
    # 1を中央として考えて、最低限1以外のn-1個の頂点は1とつながっている状態である必要がある
    m = n * (n - 1) // 2 - k
    print(m)
    for i in range(n*(n-1)//2-k): # kの制約から、iの最大値は最小で(n-1)-1まで
        print(all_combs[i][0], all_combs[i][1])


if __name__ == "__main__":
    main()


Measured memory_bytes: 3992
#include<iostream>
#include<set>

int main(void){
    std::string s;
    std::cin >> s;
    std::set<char> odd = {'R', 'U', 'D'};
    std::set<char> even = {'L', 'U', 'D'};
    int size = s.size();
    for(int i = 0; i < size; i++){
        int cur = i + 1;
        if(cur % 2 == 0 && even.find(s[i]) == even.end()){
            std::cout << "No" << std::endl;
            return 0;
        }else if(cur % 2 == 1 && odd.find(s[i]) == odd.end()){
            std::cout << "No" << std::endl;
            return 0;
        }
    }
    std::cout << "Yes" << std::endl;
    return 0;
}

Measured memory_bytes: 3612
N, M = map(int, input().split())
SC = [list(map(int, input().split())) for _ in range(M)]
for n in range(10**N):
    n = str(n)
    if len(n) != N:
        continue
    if all([n[SC[i][0]-1] == str(SC[i][1]) for i in range(M)]):
        print(n)
        exit()

print(-1)

Measured memory_bytes: 9120
using System;
class Program
{
    static void Main(string[] args)
    {
        int a = int.Parse(Console.ReadLine());
        int type = 1;
        while(a>999){
          type++;
          a=a-999;
        }
      
      switch(type){
        case 1:Console.WriteLine("ABC");break;
        case 2:Console.WriteLine("ABD");break;
        case 3:Console.WriteLine("ABE");break;
      }
    }
}

Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
#define MAX_V 100005


struct myque{
  int l,r;
  int t[MAX_V];
  void clear(){l=r=0;}
  void pop(){l++;}
  void push(int x){t[r++]=x;}
  int front(){return t[l];}
  bool empty(){return (l==r);}
};

myque que;
int pa[MAX_V],de[MAX_V],sz[MAX_V];
int cd[MAX_V],mv[MAX_V],hl[MAX_V];

int V;
vector<int> G[MAX_V];

void HLD(int root=0){
  que.clear();
  for(int i=0;i<V;i++){
    sz[i]=1;
    pa[i]=cd[i]=mv[i]=i;
    hl[i]=G[i].size();
    if(i==root)continue;
    if(hl[i]!=1)continue;
    que.push(i);
  }
  // calc sz[] cd[] pa[]
  while(!que.empty()){
    int pos=que.front();que.pop();
    if(pos==root)continue;
    for(int i=0;i<(int)G[pos].size();i++){
      int to=G[pos][i];
      if(pa[to]==pos)continue;
      pa[pos]=to;
      sz[to]+=sz[pos];           
      if(cd[to]==to)cd[to]=pos;
      if(sz[cd[to]]<sz[pos])cd[to]=pos;
      hl[to]--;
      if(hl[to]==1)que.push(to);
    }
  }

  // calc hl[] de[] mv[]
  que.clear();
  que.push(root);
  de[root]=hl[root]=0;
  while(!que.empty()){
    int pos=que.front();que.pop();
    if(cd[pos]==pos)continue;
    mv[cd[pos]]=mv[pos];
    hl[cd[pos]]=hl[pos]+1;
    int sum=hl[pos]+1+sz[cd[pos]];
    for(int i=0;i<(int)G[pos].size();i++){
      int to=G[pos][i];
      if(to==pa[pos])continue;
      que.push(to);
      de[to]=de[pos]+1;
      if(to==cd[pos])continue;
      hl[to]=sum;
      sum+=sz[to];
    }
  }
}

int lca(int a,int b){
  while(mv[a]!=mv[b]){
    if(mv[a]<mv[b])swap(a,b);
    a=pa[mv[a]];
  }
  return (de[a]<de[b]?a:b);
}

void add_edge(int a,int b){
  G[a].push_back(b);
  G[b].push_back(a);
}

int main(){
  scanf("%d",&V);

  for(int i=0;i<V;i++){
    int size,ch;
    scanf("%d",&size);
    while(size--){
      scanf("%d",&ch);
      add_edge(i,ch);
    }
  }
  HLD(0);
  /*
  for(int i=0;i<V;i++){
    cout<< (char)('A'+i) <<endl;
    cout<<" hl = "<< hl[i] <<" , ";
    cout<<" sz = "<< sz[i] <<" , ";
    cout<<" de = "<< de[i] <<" , ";
    cout<<" pa = "<< (char)('A'+pa[i]) <<" , ";
    cout<<" cd = "<< (char)('A'+cd[i]) <<" , ";
    cout<<" mv = "<< (char)('A'+mv[i]) <<" , ";
    cout<<endl;
  }
  */
  int a,b,Q;
  scanf("%d",&Q);
  while(Q--){
    scanf("%d %d",&a,&b);
    printf("%d\n",lca(a,b));
  }
  return 0;
}

Measured memory_bytes: 9656
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

long long solve(long long a, long long b) {
    if (b % a == 0) {
        return 2 * b - a;
    }
    return 2 * a * (b / a) + solve(b % a, a);
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);
    cout << fixed;

    long long n, x;
    cin >> n >> x;
    long long ans = n + solve(x, n - x);
    cout << ans << '\n';

    return 0;
}

Measured memory_bytes: 256
<?php
while(true){
    $line = fgets(STDIN);
    if($line == 0){
        break;
    }
    $score1=0;
    $score2=0;
    for ($i = 0; $i < $line; $i++) {
        $hoge = fgets(STDIN);
        $hoge = explode(' ', $hoge);
        $hoge[1] = str_replace(array("\r\n", "\r", "\n"), '', $hoge[1]);
        if($hoge[0]>$hoge[1]){
            $score1+=$hoge[0]+$hoge[1];
        }elseif($hoge[0]<$hoge[1]){
            $score2+=$hoge[0]+$hoge[1];
        }elseif($hoge[0]==$hoge[1]){
            $score1+=$hoge[0];
            $score2+=$hoge[0];
        }
    }
    echo $score1.' '.$score2.PHP_EOL;
}
?>


Measured memory_bytes: 9296
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#define LL long long
#define M 200020
#define mid ((l+r)>>1)
using namespace std;
LL read(){
	LL nm=0,fh=1; char cw=getchar();
	for(;!isdigit(cw);cw=getchar()) if(cw=='-') fh=-fh;
	for(;isdigit(cw);cw=getchar()) nm=nm*10+(cw-'0');
	return nm*fh;
}
LL n,m,K,D[M],B[M],ans,now,L[M],R[M],S[M],T[M<<2],p[M<<2],F[M];
void pushdown(LL x){if(p[x]) p[x<<1]=p[x],p[x<<1|1]=p[x],p[x]=0;}
LL query(LL x,LL l,LL r,LL pos){
	if(l==r) return p[x]; pushdown(x);
	if(pos<=mid) return query(x<<1,l,mid,pos);
	else return query(x<<1|1,mid+1,r,pos);
}
void mdf(LL x,LL l,LL r,LL opl,LL opr,LL kd){
	if(r<opl||opr<l||opr<opl) return;
	if(opl<=l&&r<=opr){p[x]=kd;return;}
	pushdown(x),mdf(x<<1,l,mid,opl,opr,kd);
	mdf(x<<1|1,mid+1,r,opl,opr,kd);
}
int main(){
	n=read(),K=read();
	for(LL i=1;i<=n;i++) D[i]=read(),B[i]=read(),S[i]=S[i-1]+D[i];
	for(LL i=1;i<=n;i++) if(B[i]==1&&K<(D[i]<<1)){puts("-1");return 0;}
	for(LL i=1;i<=n;i++){
		if(B[i]&1) L[i]=(-(S[i-1]<<1)%K+K)%K,R[i]=(-(S[i]<<1)%K+K)%K;
		else L[i]=0,R[i]=K-1; T[++m]=L[i],T[++m]=R[i];
	}
	sort(T+1,T+m+1),m=unique(T+1,T+m+1)-T-1;
	for(LL i=n;i>0;i--){
		L[i]=lower_bound(T+1,T+m+1,L[i])-T;
		R[i]=lower_bound(T+1,T+m+1,R[i])-T;
		LL tag=query(1,1,m,L[i]);
		if(tag) F[i]=F[tag]+((T[L[tag]]-T[L[i]])%K+K)%K;
		if(L[i]<=R[i]) mdf(1,1,m,1,L[i]-1,i),mdf(1,1,m,R[i]+1,m,i);
		else if(R[i]+1<L[i]) mdf(1,1,m,R[i]+1,L[i]-1,i);
	} ans=F[1];
	for(LL i=1;i<=m;i++){
		LL now=query(1,1,m,i); if(!now){ans=0;break;}
		ans=min(ans,F[now]+(((T[L[now]]-T[i])%K+K)%K));
	}
	printf("%lld\n",ans+(S[n]<<1));
}

Measured memory_bytes: 16512
#include <iostream>
#include <vector>
#include <algorithm>

int main() {
    long n, k;
    std::vector<int> dp(100010);
    std::cin >> n >> k; 
    std::vector<int> h_vec;
    int h;
    while (std::cin >> h) {
        h_vec.push_back(h);
    }
    for (int i = 1; i < n; i++) {
        int tmp_min = std::abs(h_vec[i - 1] - h_vec[i]) + dp[i - 1];
        for (int j = 1; j <= k && i - j >= 0; j++) {
            tmp_min = std::min(std::abs(h_vec[i - j] - h_vec[i]) + dp[i - j], tmp_min);
        }
        dp[i] = tmp_min;
    }
    std::cout << dp[n - 1] << std::endl;
}


Measured memory_bytes: 1276
#include<cstdio>
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<stack>
using namespace std;
int main(){
	stack<int> S1;
	stack<pair<int,int> > S2;
	char ch;
	int sum=0;
	for(int i=0;cin>>ch;i++){
		if(ch=='\\'){
		S1.push(i); 	
		}else if(ch=='/'&&S1.size()>0){
			int j=S1.top();
			S1.pop();
			sum+=i-j;
			int a=i-j;
			while(S2.size() >0&&S2.top().first>j){
				a+=S2.top().second;
				S2.pop();
			}
			S2.push(make_pair(j,a)); 
		}
	}
	vector<int> ans;
	while(S2.size() >0){
		ans.push_back(S2.top().second);
		S2.pop(); 
	}
	reverse(ans.begin(),ans.end());
	cout<<sum<<endl;
	cout<<ans.size();
	for(int i=0;i<ans.size();i++){
		cout<<" ";
		cout<<ans[i];
	} 
	cout<<endl;
	return 0;
}


Measured memory_bytes: 3196
#include <cstdio>
#include <algorithm>
#include <numeric>
#include <map>
#define fail return puts("-1"), 0

const int N = 1e5 + 5, M = 2e5 + 5;

int n, tot, lnk[N], ter[M], nxt[M], sz[N], fa[N];
long long dis[N], d[N];
std::map<long long, int> mp;

void add(int u, int v) {
	ter[++tot] = v, nxt[tot] = lnk[u], lnk[u] = tot;
}
void dfs(int u, int p) {
	for (int i = lnk[u]; i; i = nxt[i]) {
		int v = ter[i];
		if (v == p) continue;
		dis[v] = dis[u] + 1;
		dfs(v, u);
	}
}
int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		scanf("%lld", &d[i]);
		mp[d[i]] = i, sz[i] = 1;
	}
	int cnt = 0;
	for (auto it = mp.rbegin(); it != mp.rend(); it++) {
		int v = it->second, u = mp[it->first + 2 * sz[v] - n];
		if (!u || u == v) fail;
		add(u, v), add(v, u);
		fa[v] = u, sz[u] += sz[v];
		if (++cnt == n - 1) break;
	}
	int rt = mp.begin()->second;
	dfs(rt, 0);
	if (std::accumulate(dis + 1, dis + n + 1, 0LL) != d[rt]) fail;
	for (int i = 1; i <= n; i++) {
		if (fa[i]) printf("%d %d\n", fa[i], i);
	}
	return 0;
}

Measured memory_bytes: 14208
#include <bits/stdc++.h>
  using namespace std;
 
int main(){
 string s;
  cin>>s;
  if(s=="Sunny"){
    cout<<"Cloudy"<<endl;
  }else if(s=="Cloudy"){
    cout<<"Rainy"<<endl;
  }else{
    cout<<"Sunny"<<endl;
  }
}

Measured memory_bytes: 256
#!venv/bin/python
 
import math
import numpy as np
import random
import copy
import statistics 
import bisect
import heapq
from collections import defaultdict 

A, B = [ int(x) for x in input().split() ]

if A >= 13:
    print(B)
elif A >= 6:
    print(int(B/2))
else:
    print(0)


Measured memory_bytes: 25104
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

int A;

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

  cin >> A;
  int n = 1;
  while (true) {
    if ((ll)n * (n + 1) / 2 >= A) break;
    n++;
  }
  int pos = n - ((ll)n * (n + 1) / 2 - A);
  for (int i = 0; i < pos; i++) {
    cout << ")";
  }
  cout << "(";
  for (int i = 0; i < n - pos; i++) {
    cout << ")";
  }
  for (int i = 0; i < n - 1; i++) {
    cout << "(";
  }
  cout << endl;

  return 0;
}


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

int main() {
  // ここにプログラム
  int N, a, b, sum;
  cin >> N;
  sum = 0;
  for (int i = 0; i < N; i++) {
    cin >> a >> b;
    sum = sum + b - a + 1;
  }
  cout << sum << endl;
}


Measured memory_bytes: 256
isTruth::Int->Int->[Int]
isTruth n y = head ([[a,b,c] |a <- [0..n],b<- [0..n-a],let c =(n-a-b), c >= 0 && 10000*a + 5000*b + 1000*c == y] ++ [[-1,-1,-1]])
 
main = do
  [n,y] <- map read . words <$> getLine
  putStrLn $ unwords . map show $ isTruth n y

Measured memory_bytes: 508
#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() {
    string s;
    cin >> s;
    int ans=0;
    int r=0;
    rep(i,3){
        if (s[i]=='R') ++r;
    }
    if (r==2) {
        if (s[1]=='R') {
            cout << r << endl;
        } else {
            cout << 1 << endl;
        }
    } else {
        cout << r << endl;
    }
    return 0;
}

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

int main(){
    int n, x;
    cin >> n >> x;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    ll ans = 0;
    rep(i, n-1) {
        int tmp = a[i] + a[i+1];
        if (tmp>x) {
            tmp -= x;
            ans += tmp;
            a[i+1] -= tmp;
            if (a[i+1] < 0) a[i+1] = 0;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 640
// This template is based on Mr. tonymontaro's template (https://atcoder.jp/users/tonymontaro).
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
    static PrintWriter out;
    static CF_Reader in;

    public static void main(String[] args) throws IOException {
        out = new PrintWriter(new OutputStreamWriter(System.out));
        in = new CF_Reader();
        StringBuilder result = new StringBuilder();

        // Start: int型の整数n mを取得する
        // // N M 形式
        // int n = in.intNext();
        // int m = in.intNext();
        // End: int型の整数n mを取得する

        // Start: int型の整数Nと配列Aを取得する
        // // N
        // // A1 A2 A3... AN 形式
        // int n = in.intNext();
        // int[] A = in.nextIntArray(n);
        // End: int型の整数Nと配列Aを取得する

        // Start: Char型の文字をInt型に変換する
        // Integer.parseInt(String.valueOf(charText))
        // End: Char型の文字をInt型に変換する

        // Start: 文字列を1文字ずつ出力する
        String text = in.next();
        char[] work = new char[text.length()];
        int d = Integer.parseInt(String.valueOf(text.charAt(text.length() - 1)));
        if (d  == 2 || d ==4 ||d == 5 || d == 7 || d ==9) {
          result.append("hon");
        } else if (d == 3) {
          result.append("bon");
        } else {
          result.append("pon");
        }
        // for(int i = 0; i < text.length(); i++){
        //   work[i] = text.charAt(i); // Char型の文字
        //   out.println(work[i]);
        // }
        // End: 文字列を1文字ずつ出力する

        out.println(result);

        out.close();
    }

    static class CF_Reader {
        BufferedReader br;
        StringTokenizer st;

        public CF_Reader() throws IOException {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine().trim());
            return st.nextToken();
        }

        long longNext() throws IOException {
            return Long.parseLong(next());
        }

        int intNext() throws IOException {
            return Integer.parseInt(next());
        }

        double doubleNext() throws IOException {
            return Double.parseDouble(next());
        }

        char charNext() throws IOException {
            return next().charAt(0);
        }

        public int[] nextIntArray(final int n) throws IOException {
            final int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = intNext();
            return a;
        }

        public long[] nextLongArray(final int n) throws IOException {
            final long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = longNext();
            return a;
        }

        String line() throws IOException {
            return br.readLine().trim();
        }
    }
}

Measured memory_bytes: 32804
#include <cstdio>
#include <string>
#include <cmath>
#include <string>
#include <algorithm>
#include <iostream>
#include <map>
#include <vector>
#include <iomanip>
#include <tuple>
#include <queue>
using namespace std;
typedef long long ll;
#define rep(i, a, n) for (int i=a;i<n;++i)
#define repeq(i, a, n) for(int i=a;i<=n;++i)
#define per(i, a, n) for (int i=n-1; i>=a;--i)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()

// 
string S;
string T;
string ans = "No";

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

    string Stmp = S;
    rep(i, 0, S.size()){
        string tt = Stmp.substr(S.size()-1);
        Stmp.pop_back();
        Stmp = tt + Stmp;
        if(Stmp == T){
            ans = "Yes";
        }
    }

    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 256
# coding: utf-8
# Your code here!


import sys
#sys.setrecursionlimit(10**6)
readline = sys.stdin.readline 

n = int(input())
a = [int(i) for i in readline().split()]
a.sort()

ans = 0
for i in range(n):
    r = i+1
    for j in range(i+1,n):
        A = a[i] + a[j]
        while r < n and A > a[r]:
            r += 1
        ans += r-j-1

print(ans)    
    
















Measured memory_bytes: 3188
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <cmath>
# include <functional>
# include <utility>
# define MOD 1000000007
# define INF 2000000000
#define rep(i,rept)	for(ll i = 0; i<rept;i++)
typedef long long ll;
using namespace std;
int main() {
	ll sum = 0, ans = 0, pass = 0, counter = 0;
	ll  a = 0, b = 0, c = 0, k = 0, n = 0, m = 0;
	//newdefine
	cin >> a >> b;
	if (a < 10 && b < 10)cout << a * b << endl;
	else cout << -1 << endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int binarySearch(int data[], int n, int key){
  int left = 0;
  int right = n;
  while(left < right){
    int mid = (left + right) / 2;
    if(data[mid] == key){ return mid; }
    else if(key < data[mid]){ right = mid; }
    else { left = mid + 1; }
  }
  return -1;
}

int main(){
  int n, m, q, cnt=0;
  int s[100000] = {};
  
  cin >> n;
  for(int i = 0; i < n; i++){
    cin >> s[i];
  }
  cin >> m;
  for(int i = 0; i < m; i++){
    cin >> q;
    if(binarySearch(s, n, q) != -1){ cnt++; }
  }

  cout << cnt << endl;
  
  return 0;
}



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

#define int long long

using namespace std;
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
typedef pair<pint,int> P1;
typedef pair<int,pint> P2;
static const ll maxLL = (ll)1 << 62;
const ll MOD=1000000007,INF=1e18;
int dy[]={-1,0,1,0};
int dx[]={0,1,0,-1};

string s;
int cnt[111],mincnt[111];
 
signed main(){
	cin >>s;
	rep(i,0,26)mincnt[i]=0;
	rep(i,0,s.size()){
	    rep(j,0,26){
	        if(j!=s[i]-'a')cnt[j]++;
	        mincnt[j]=max(mincnt[j],cnt[j]);
	    }
	    cnt[s[i]-'a']=0;
	}
	int ans=111;
	rep(i,0,26)ans=min(ans,mincnt[i]);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#define _DEBUG
#include "bits/stdc++.h"
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,a4,x,...) x
#define debug_1(x1) cout<<#x1<<": "<<x1<<endl
#define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl
#define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl
#define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl
#define debug_5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl
#ifdef _DEBUG
#define debug(...) CHOOSE((__VA_ARGS__,debug_5,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__)
#else
#define debug(...)
#endif
#define rep(index,num) for(int index=0;index<(int)num;index++)
#define rep1(index,num) for(int index=1;index<=(int)num;index++)
#define brep(index,num) for(int index=(int)num-1;index>=0;index--)
#define brep1(index,num) for(int index=(int)num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=(ll)1e+18+1;
int INF=1e+9+1;
int popcount(int n){
	int cnt=0;
	while(n){
		cnt+=(n&1);
		n>>=1;
	}
	return cnt;
}
int nmodp[200001],nmodm[200001];
int f[200001];
int main(){
	int N;
	string X;
	scan(N>>X);
	f[0]=0;
	rep1(i,N){
		f[i]=f[i%popcount(i)]+1;
	}
	int inicnt=0;
	rep(i,N) if(X[i]=='1') inicnt++;
	int Xmodp=0,Xmodm=0;
	nmodp[0]=1%(inicnt+1);
	rep(i,N-1){
		nmodp[i+1]=nmodp[i]*2%(inicnt+1);
	}
	if(inicnt>1){
		nmodm[0]=1%(inicnt-1);
		rep(i,N-1){
			nmodm[i+1]=nmodm[i]*2%(inicnt-1);
		}
	}
	rep(i,N){
		if(X[N-i-1]=='1'){
			Xmodp+=nmodp[i];
			Xmodp%=inicnt+1;
			if(inicnt>1){
				Xmodm+=nmodm[i];
				Xmodm%=inicnt-1;
			}
		}
	}
	rep(i,N){
		if(X[i]=='0'){
			prin(f[(Xmodp+nmodp[N-i-1])%(inicnt+1)]+1);
		}
		else{
			if(inicnt==1){
				prin(0);
			}
			else{
				prin(f[(Xmodm-nmodm[N-i-1]+inicnt-1)%(inicnt-1)]+1);
			}
		}
	}
	return 0;
}


Measured memory_bytes: 5992
import random
import time
import copy
start = time.time()
D = int(input())
s = [[0 for j in range(26)] for i in range(D)]
c = list(map(int, input().split(" ")))
result = []
total = -10000000
for i in range(D):
    a = list(map(int, input().split(" ")))
    for j, k in enumerate(a):
        s[i][j] = int(k)
#while(1):
for t in range(26):
    result_tmp = []
    total_tmp = 0
    last = [0 for i in range(26)]
    for i in range(D):
        score = [0 for i in range(26)]
        score_tmp = [0 for i in range(26)]

        for j in range(26):
            score[j] = s[i][j]
            score_tmp[j] = s[i][j]
            for k in range(26):
                if j != k:
                    score_tmp[j] -= (i + 1 + t - last[k]) * c[k]
                    score[j] -= (i + 1 - last[k]) * c[k]

        score_sort = sorted(score_tmp, reverse=True)
        score_max = score_sort[0]

        tmp = []
        for j in range(26):
            if score_max == score_tmp[j]:
                score_max = j

        result_tmp.append(score_max)
        last[score_max] = i + 1
        total_tmp += score[score_max]
    if total < total_tmp:
        total = total_tmp
        result = result_tmp.copy()
    end = time.time()
    if end - start > 1.8:
        break
for i in range(D):
    print(result[i]+1)

Measured memory_bytes: 79744
parseInt(x) = parse(Int, x)
parseBigInt(x) = parse(BigInt, x)
parseFloat(x) = parse(Float64, x)
parseBigFloat(x) = parse(BigFloat, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    s=chomp(readline())
    flg1,flg2=false,false
    for i in s
        if i=='C'
            flg1=true
        elseif i=='F' && flg1
            flg2=true
            break
        end
    end
    if flg1 && flg2
        println("Yes")
    else
        println("No")
    end
end
main()

Measured memory_bytes: 109584
#include <stdio.h>
#include <string.h>
  
int main(void){
  char s[1001], order[8], ch[1001];
  int i, j, n, a, b;
  
  scanf("%s\n%d", s, &n);
  
  for(i=0;i<n;i++){
    scanf("%s %d %d", order, &a, &b);
      
    if(!strcmp(order, "reverse")){
      for(j=a;j<=b;j++)
        ch[b-j] = s[j];
      for(j=a;j<=b;j++)
        s[j] = ch[j-a];
    }
  
    if(!strcmp(order, "replace")){
      scanf("%s", ch);
      for(j=0;ch[j]!='\0';j++)
        s[a+j] = ch[j];
    }
  
    if(!strcmp(order, "print")){
      for(j=a;j<=b;j++)
        printf("%c", s[j]);
      printf("\n");
    }
  }
  
  return 0;
}


Measured memory_bytes: 1988
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1001001001;
const ll LINF = 1001001001001001001;
#define fori(i,a,b) for(ll i=(a);i<=(b);i++)
#define repi(i,n) fori(i,0,(n)-1)
#define forr(i,a,b) for(ll i=(b);i>=(a);i--)
#define repr(i,n) forr(i,0,(n)-1)
#define all(x) (x).begin(),(x).end()
#define vec vector<ll>
#define pb push_back
#define mp make_pair
#define pcnt __builtin_popcount
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}

bool f(ll x){
    for(int i=2;i*i<=x;i++){
        if(x%i==0)return false;
    }
    return true;
}

void solve(ll x){
    while(true){
        if(f(x)){
            cout<<x<<endl;
            return;
        }
        x++;
    }
}

int main(){
    ll x;
    scanf("%lld",&x);
    solve(x);
    return 0;
}


Measured memory_bytes: 256
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(ll i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) rep(i,v.size())cout<<" "<<v[i];cout<<endl<<endl;
#define show2d(v) rep(i,v.size()){rep(j,v[i].size())cout<<" "<<v[i][j];cout<<endl;}cout<<endl;
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
//#define mt make_tuple
//typedef tuple<int,int,int> tp;
//typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
ll keta(ll a){
	ll t=0;
	while(a){
		t+=a%10;
		a/=10;
	}
	return t;
}
ll sti(string s){
	ll t=0;
	rep(i,s.size()){
		t*=10;
		t+=s[i]-'0';
	}
	return t;
}
int main(){
	int n;
	cin>>n;
	string s="";
	set<ll>used;
	while(n){
		loop(i,1,10000){
			if(!n)break;
			string t=to_string(i)+s;
			string nt=to_string(i+1)+s;
			ll w=sti(t),nw=sti(nt);
			if((ll)keta(nw)*w>(ll)nw*keta(w))goto end;
			if(used.find(w)!=used.end())continue;
			used.insert(w);
			cout<<w<<endl;n--;
		}
		end:;
		s+="9";
	}
/*	int t=1;
	while(1){
		loop(i,1,100000){
			int w=t+i;
			if((ll)keta(w)*t>(ll)w*keta(t)){
				cout<<t<<" "<<w<<endl;
				goto end;
			}
		}
		cout<<t<<endl;
		end:;
		t++;
	}*/
}






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

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

    int i = 0;
    bool f = true;

    string s1 = "dream";
    string s2 = "dreamer";
    string s3 = "erase";
    string s4 = "eraser";
    int l1 = 5;
    int l2 = 7;
    int l3 = 5;
    int l4 = 6;

    for (; i < s.length();)
    {
        if (s.substr(i, l1+l4) == s1+s4)
        {
            i += l1 + l4;
        }
        else if (s.substr(i, l1 + l3) == s1 + s3)
        {
            i += l1 + l3;
        }
        else if(s.substr(i, l2) == s2)
        {
            i += l2;
        }
        else if (s.substr(i, l4) == s4)
        {
            i += l4;
        }
        else if (s.substr(i, l1) == s1 || s.substr(i, l3) == s3)
        {
            i += l1;
        }
        else
        {
            f = false;
            break;
        }
    }

    cout << (f ? "YES" : "NO") << endl;

    return 0;
}

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

int main() {
  string s;
  cin >> s;
  int count=0;
  int size;
  size = s.size();
  //cout << size/2;
  
    rep(i, size/2){
      if(s[i] != s[size-1-i]) count++;
    }
    
  
  cout << count;

}

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

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

#define MAX 100005
#define INF INT_MAX

typedef long long ll;
typedef pair<int, int> P;

int main(int, char**)
{
    int n;
    cin >> n;

    vector<P> w;
    int tmp;
    rep(i,n) {
        cin >> tmp;
        w.emplace_back(tmp, i);
    }
    sort(w.begin(), w.end());

    vector<bool> used(n, false);
    vector< vector<P> > loops; // 巡回群のリスト
    rep(i,n) {
        if (used[i]) continue;
        int now = i;
        vector<P> lp;
        while (!used[now]) {
            lp.push_back(w[now]);
            used[now] = true;
            now = w[now].second;
        }
        loops.push_back(lp);
    }
    int wmin = (*min_element(w.begin(), w.end())).first;
    int cost = 0;
    for (auto l : loops) {
        int lmin = (*min_element(l.begin(), l.end())).first;
        int sum = accumulate(l.begin(), l.end(), 0,[] (int a, P b) { return a + b.first; });
        int c1 = (sum-lmin) + lmin * (l.size()-1);    // 巡回群そのままのコスト
        int c2 = (sum-lmin) + wmin * (l.size()-1) + (lmin+wmin) * 2; // wminを使った場合のコスト
        cost += min(c1, c2);
    }

    cout << cost << endl;

    return 0;
}


Measured memory_bytes: 3160
# coding: utf-8

i = input().split()
a = i[0]
b = i[1]
c = i[2]

if b > c:
    n = b
    b = c
    c = n
if a > b:
    n = a
    a = b
    b = n
if b > c:
    n = b
    b = c
    c = n
print(a + " " + b + " " + c)


Measured memory_bytes: 5556
#include <bits/stdc++.h>
#define DEBUG if(0)
#define lli long long int
#define ldouble long double
using namespace std;

const int maxN = 2e5;
char s[maxN + 1];

int main()
{
  while (scanf(" %s", s) != EOF)
  {
    int sum = 0;
    for (int i = 0; s[i]; i++)
      sum = (sum + (s[i] - '0')) % 9;
    printf("%s\n", sum % 9 == 0 ? "Yes" : "No");
  }
  return 0;
}

Measured memory_bytes: 3844
from sys import stdin

class Node:
    def __init__(self, v, parent=None, left=None, right=None):
        self.value = v
        self.parent = parent
        self.left = left
        self.right = right

class BST:
    def __init__(self):
        self.root = None

    def insert(self, v):
        cur = self.root
        cur_p = None
        while cur != None:
            cur_p = cur
            if v < cur.value:
                cur = cur.left
            elif v > cur.value:
                cur = cur.right

        n = Node(v, cur_p)
        if cur_p == None:
            self.root = n
        elif v < cur_p.value:
            cur_p.left = n
        else:
            cur_p.right = n

    def preorder(self):

        def rec_preorder(t=self.root):
            if t != None:
                print(" ", t.value, sep="", end="")
                rec_preorder(t.left)
                rec_preorder(t.right)

        rec_preorder()
        print()

    def inorder(self):

        def rec_inorder(t=self.root):
            if t != None:
                rec_inorder(t.left)
                print(" ", t.value, sep="", end="")
                rec_inorder(t.right)

        rec_inorder()
        print()

m = int(stdin.readline().rstrip())
t = BST()
for _ in range(m):
    q = stdin.readline().rstrip().split()
    if q[0] == "insert":
        t.insert(int(q[1]))
    elif q[0] == "print":
        t.inorder()
        t.preorder()


Measured memory_bytes: 105484
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <math.h>
int compare(const void *a,const void *b){
    if(*(int*)a>*(int*)b)return 1;
    return -1;
}
int main()
{   int a[3],b[3],i,c[4]={0};
    for(i=0;i<3;i++){scanf("%d%d",&a[i],&b[i]);}
    for(i=0;i<3;i++){
        c[a[i]-1]++;
        c[b[i]-1]++;
    }
    qsort(c,4,sizeof(int),compare);
    
    if(c[0]==1&&c[1]==1&&c[2]==2&&c[3]==2){
    printf("YES");
    }else{
        printf("NO");
    }
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;


struct UnionFind {
  vector<int> data;
  int count;
  UnionFind(int size) : data(size, -1), count(size) { }
  bool unite(int x, int y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
      --count;
    }
    return x != y;
  }
  bool same(int x, int y) { return root(x) == root(y); }
  int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }
  int size(int x) { return -data[root(x)]; }
};
 
inline ll n_pairs(int s){
    return (ll)s * (s-1)/2;
}
 
void solve(int N,int M,vi& a,vi& b) {
    UnionFind uf(N);
    vll ans(M);
    ll curr = n_pairs(N);
    for (int i=M-1; i>=0; --i){
        ans[i] = curr;
        int ra=uf.root(a[i]), rb=uf.root(b[i]);
        if (ra != rb) {
            int sa=uf.size(a[i]), sb=uf.size(b[i]);
            curr += n_pairs(sa) + n_pairs(sb);
            uf.unite(a[i], b[i]);
            int s=uf.size(a[i]); 
            curr -= n_pairs(s);
        }
    }
    for (int i=0;i<M;++i){
        printf("%lld\n", ans[i]);
    }
}
 
int main() {
    int N, M; scanf("%d%d", &N, &M);
    vi a(M), b(M);
    for (int i=0;i<M;++i){
        scanf("%d%d", &a[i], &b[i]);
        --a[i]; --b[i];
    }
    solve(N,M,a,b);
    return 0;
}

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

using namespace std;

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

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<(x)<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

template<typename T> inline void CHMAX(T& a, const T b) {if(a<b) a=b;}
template<typename T> inline void CHMIN(T& a, const T b) {if(a>b) a=b;}

constexpr ll MOD=1000000007ll;
// constexpr ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-9;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  // cout<<setprecision(10)<<fixed;
  int A, B, m, a[125252], b[125252], x, y, c;
  cin>>A>>B>>m;
  int mia=1e9;
  REP(i, A){
    cin>>a[i];
    CHMIN(mia, a[i]);
  }
  int mib=1e9;
  REP(i, B){
    cin>>b[i];
    CHMIN(mib, b[i]);
  }
  int ans=mia+mib;
  REP(i, m){
    cin>>x>>y>>c;
    --x;--y;
    int tmpa=mia, tmpb=mib;
    CHMIN(ans, a[x]+b[y]-c);
  }
  cout<<ans<<'\n';
  return 0;
}


Measured memory_bytes: 1024
n=int(input())
dic={}
ans=0
for i in range(n):
    s=list(input())
    s.sort()
    s="".join(s)
    dic[s]=dic.get(s,0)
    if dic[s]==0:
        pass
    else:
        ans+=dic[s]
    dic[s]=dic[s]+1

print(ans)

Measured memory_bytes: 17808
#include <iostream>
#include <cstdio>
#include <algorithm>

#define MAX 86400

using namespace std;

int main(void){

  int n;
  while( cin >> n , n ){

    int train[MAX] = {0};
    int ma = 0;

    while(n--){

      int h1,m1,s1,h2,m2,s2;
      scanf("%d:%d:%d",&h1,&m1,&s1);
      int total_s1 = h1*3600 + m1*60 + s1;
      scanf("%d:%d:%d",&h2,&m2,&s2);
      int total_s2 = h2*3600 + m2*60 + s2;
      ma = max( ma , total_s1 );
      for( int i = total_s1 ; i < total_s2 ; i++ )
	train[i]++;

    }
    int ans = 0;
    for( int i = 0 ; i <= ma ; i++ ){
      ans = max( ans , train[i] );
    }
    cout << ans << endl;

  }
  return 0;
}

Measured memory_bytes: 1580
/// hi_im_manh :D
#include <bits/stdc++.h>
#define reset(a,n) memset(a,0,(n+1)*sizeof(int))
#define endl "\n"
#define llmin LLONG_MIN
#define llmax LLONG_MAX
#define intmax INT_MAX
#define intmin INT_MIN
#define ll long long
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)

#define duckman "TASK"

#define input freopen(duckman".inp", "r", stdin);
#define output freopen(duckman".out", "w", stdout);

#define nmax 22000
using namespace std;


int main()
{
    fast;
//    input;
//    output;

    int n;
    cin >> n;
    int a[n], b[n], c[n];
    int dp[n][3];
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> b[i] >> c[i];
    }
    dp[0][0] = a[0];
    dp[0][1] = b[0];
    dp[0][2] = c[0];
    for (int i = 1; i < n; i++) {
        dp[i][0] = a[i] + max(dp[i-1][1], dp[i-1][2]);
        dp[i][1] = b[i] + max(dp[i-1][0], dp[i-1][2]);
        dp[i][2] = c[i] + max(dp[i-1][0], dp[i-1][1]);
    }
    cout << max(dp[n-1][0], max(dp[n-1][1], dp[n-1][2]));
}
/*

*/


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

int main() {
            ll a;cin>>a;
            vector<ll>v;
            rep(i,a){
                     ll b;cin>>b;
                     if(b==0){
                              ll x;cin>>x;
                              v.push_back(x);
                              }
                     else if(b==1){
                                   ll p;cin>>p;                                  
                                   cout<<v[p]<<endl;
                                   }
                     else if(b==2){
                                   v.erase(v.end()-1);
                                   }
                     }
                           
}




Measured memory_bytes: 4884
#include <iostream>
#include <algorithm>
#include <limits>
#include <vector>
#define ll long long int
#define rep(i,n) for(int i = 0;i < n;i++)
#define pb push_back
#define mp make_pair

using namespace std;

int main(){

    ll n,a,b;
    cin >> n >> a >>b;
    vector<ll> x(n);
    rep(i,n){
        cin >> x[i];
    }

    ll ans = 0;

    rep(i,n - 1){
        ans += min((x[i + 1] - x[i]) * a,b);
    }

    cout << ans << endl;


    return 0;

    /*sort(x.begin(),x.end());

    int one;

    rep(i,n){
        if(x[i].second == 0){
            one = i;
        }
    }

    int sum1 = 0,sum2 = 0;

    for(int i = one;i > 0;i--){
        sum1 += min((x[i].first - x[i - 1].first) * a, b);
    }

    for(int i = one;i < n - 1;i++){

        if(i == one){
            if(i == 0){
                sum1 += min((x[i+1].first - x[i].first) * a, b);
                continue;
            }
            else{
                continue;
            }
        }
        
        sum1 += min((x[i+1].first - x[i].first) * a, b);
    }

    for(int i = one;i < n - 1;i++){
        sum2 += min((x[i+1].first - x[i].first) * a,b);
    }

    for(int i = one;i > 0;i--){
        if(i == one){
            if(i == n - 1){
                sum2 += min((x[i].first - x[i - 1].first) * a, b);
                continue;
            }
            else{
                continue;
            }
        }
        sum2 += min((x[i].first - x[i - 1].first) * a, b);
    }
    //cout << sum1 << " " << sum2 << endl;
    cout << min(sum1,sum2) << endl;

    return 0;*/
}

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

int main() {
    int h, w;
    cin >> h >> w;
    vector<string> v(h), ans;
    int karah[h] = {0}, karaw[w] = {0};
    for(int i = 0; i < h; ++i) cin >> v[i];
    for(int i = 0; i < h; ++i) {
        int dot = 0;
        for(int j = 0; j < w; ++j) {
            if(v[i][j] == '.') dot++;
            else break;
        }
        if(dot == w) karah[i] = 1;
    }
    for(int i = 0; i < w; ++i) {
        int dot = 0;
        for(int j = 0; j < h; ++j) {
            if(v[j][i] == '.') dot++;
        }
        if(dot == h) karaw[i] = 1;
    }
    
    for(int i = 0; i < h; ++i) {
        string a;
        for(int j = 0; j < w; ++j) {
            if(karah[i] == 0 && karaw[j] == 0) {
                a.push_back(v[i][j]);
            }
        }
        if(!a.empty()) ans.push_back(a);
    }
        
    for(int i = 0; i < ans.size(); ++i) {
        cout << ans[i] << '\n';
    }

    return 0;
}


Measured memory_bytes: 256
///BISMILLAH'IR  RO'HMANIR  ROH'IM
///RIFAT SHARIAR SAKIL
///SOFTWARE ENGINEERING(SUST)

#include<stdio.h>
int main()
{
  long long  int N,K,i,s=0,k,l,a[100000];
    scanf("%lld %lld",&N,&K);
    for(i=0;i<N;i++)
    {
      scanf("%lld",&a[i]);
    }
    for(i=0;i<N;i++)
    {
        if(a[i]>=K)
        {
            s=s+1;
        }
    }
    printf("%lld",s);
    return 0;
}


Measured memory_bytes: 896
package main

import "fmt"

func main() {
	var a, b int
	fmt.Scan(&a, &b)

	var s string
	if a > b {
		s = ">"
	} else if a < b {
		s = "<"
	} else {
		s = "=="
	}

	fmt.Printf("a %s b\n", s)
}



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

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)
#define reppp(i, m, n) for(int i=m;i<n;i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define debug(x) cerr << #x << ": " << x << endl;

using namespace std;

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

map<ll, ll> d;
priority_queue< Pll, vector<Pll>, greater<Pll> > que;
map<ll, vector<Pll> > edges;
ll n,m,p,r,c;

void dijkstra(ll start){
    d[start] = 0LL;
    que.push(Pll(0LL, start));

    while(!que.empty()){
        Pll v = que.top(); que.pop();
        if(d.find(v.second) != d.end() && d[v.second] < v.first) continue;
        for(Pll e: edges[v.second]){
            if(d.find(e.first) == d.end() || d[e.first] > d[v.second] + e.second){
                d[e.first] = d[v.second] + e.second;
                que.push(Pll(d[e.first], e.first));
            }
        }
    }
}

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

    cin >> n >> m;
    map<ll, ll> lines;
    ll next_line = 1;
    rep(m){
        cin >> p >> r >> c;
        p--; r--;
        if(lines[c] == 0) lines[c] = next_line++;
        c = lines[c];
        edges[p*(m+1LL)+c].emplace_back(r*(m+1LL)+c, 0LL);
        edges[r*(m+1LL)+c].emplace_back(p*(m+1LL)+c, 0LL);
        edges[p*(m+1LL)].emplace_back(p*(m+1LL)+c, 0LL);
        edges[p*(m+1LL)+c].emplace_back(p*(m+1LL), 1LL);
        edges[r*(m+1LL)].emplace_back(r*(m+1LL)+c, 0LL);
        edges[r*(m+1LL)+c].emplace_back(r*(m+1LL), 1LL);
    }

    dijkstra(0LL);
    if(d.find((n-1LL)*(m+1LL)) == d.end()){
        cout << -1 << endl;
    }else{
        cout << d[(n-1LL)*(m+1LL)] << endl;
    }
}


Measured memory_bytes: 111604
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
         final long mod = 1000000007;

        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long k = sc.nextLong();

        long sum_bottom, sum_upper;
        long ans ;

        sum_bottom = (k * (k-1) % mod  * modinv(2, mod)) % mod;
        sum_upper = (((2*n%mod) - ((k-1) % mod)) * k  % mod* modinv(2, mod)) % mod;
        ans = (mod(sum_upper - sum_bottom, mod) + 1 )% mod;

        for (long i = k+1; i <= n+1; i++) {
            sum_bottom = (sum_bottom + i-1) % mod;
            sum_upper = (sum_upper + n - (i-1)) % mod;
            ans =( ans + (mod(sum_upper - sum_bottom, mod) + 1) % mod) % mod;
        }

        System.out.println(ans);
    }
    static long modinv(long  a, long m) {
        long b = m, u = 1, v = 0;
        long tmp;
        while (b != 0) {
            long t = a / b;
            a -= t * b;
            tmp = b;
            b = a;
            a = tmp;
            
            u -= t * v;
            tmp = u;
            u = v;
            v = tmp;
        }
        u %= m;
        if (u < 0) u += m;
        return u;
    }

    static long mod(long val, long m) {
        long res = val % m;
        if (res < 0) res += m;
        return res;
    }
}


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

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

//ori
#define MOD 1000000007
 
int main() {
  LL x;
  cin >> x;
  LL s=x/11, t=x%11, ans=s*2;
  if(t>0) ans++,t-=6;
  
  if(t>0) ans++;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256