akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <stack>
#include <deque>
#include <math.h>
#include <map>
#include <set>
#include <memory.h>
#include <stdio.h>
#include <cmath>
#include <time.h>

#define maxn 1000007
#define fi first
#define se second
#define sqr(a) a*a
#define de(X) cerr << X << ' ';
#define fuck cerr << "Fuck" << '\n';
using namespace std;
typedef long long ll;
typedef string st;
typedef double db;
typedef pair <int, int> ii;
typedef pair <ii, int> iii;
typedef pair <ii, ii> iiii;
typedef pair <db, db> dd;
typedef pair <st, st> ss;
typedef pair <st, int> si;
typedef pair <db, int> di;
template <class T> int getbit (T x, int pos) { return (x >> (pos - 1)) & 1; }
template <class T> void turn_on (T &x, int pos) { x = x | ((T)1 << (pos - 1)); }
template <class T> void turn_off (T &x, int pos) { x = x & ~((T)1 << (pos - 1)); }
int read_int() { char r; bool start = false , neg = false; int ret = 0; while(true) { r = getchar(); if((r-'0'<0 || r-'0'>9) && r!='-' && !start) continue; if((r-'0'<0 || r-'0'>9) && r!='-' && start) break; if (start) ret*=10; start = true; if (r=='-') neg=true; else ret+=r-'0'; } if(!neg) return ret; else return -ret; }
ll gcd(int a, int b) { if (b==0) return a; return gcd(b, a % b); }
const ll oo = 1e18 + 7;
const ll MOD = 1e9 + 7;


int minPrime[maxn + 1];
void solve(int n) {
    for (int i = 2; i * i <= n; ++i) {
        if (minPrime[i] == 0) {
            for (int j = i * i; j <= n; j += i) {
                if (minPrime[j] == 0) {
                    minPrime[j] = i;
                }
            }
        }
    }
    for (int i = 2; i <= n; ++i) {
        if (minPrime[i] == 0) {
            minPrime[i] = i;
        }
    }
}

ll F(int n) {
    ll res = 1;
    ll cnt = 0;
    int last = 0;
    while (n != 1) {
        if (minPrime[n] == last) {
            cnt += 1;
        } else {
            res = res * (cnt + 1);
            //cout << minPrime[n] <<' '<<last<<' '<< cnt << endl;
            cnt = 1;
        }
        last = minPrime[n];
        n /= minPrime[n];
    }
    res = res * (cnt + 1);
   // cout << cnt << endl;
    return res;
}

int main()
{
    srand(time(NULL));
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //freopen(".INP", "r", stdin);
    //freopen(".OUT", "w", stdout);
    int n;
    cin >> n;
    solve(n);
    ll res = 0;
    for (int i = 1; i<n; i++) {
        //cout << i <<' '<<F(i) << endl;
        res += F(i);
    }
    cout << res;
}


Measured memory_bytes: 7100
import java.util.Scanner;

/**
 * @author yoshizaki
 *
 */
public class Main {
    public static void main(String[] args) {
        Scanner scanner= new Scanner(System.in);
        int length = scanner.nextInt();
        String character = scanner.next();
        character = character + "!";
        String[] charas = character.split("ABC");
        System.out.println(charas.length -1);
    }
}


Measured memory_bytes: 23508
#include<stdio.h>

int main(){
	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	if(c > b && b > a){
		printf("%d %d %d\n",a,b,c);
	}
	else if(b > c && c > a){	
		printf("%d %d %d\n",a,c,b);
	}
	else if(c > a && a > b){
		printf("%d %d %d\n",b,a,c);
	}
	else if(a > c && c > b){
		printf("%d %d %d\n",b,c,a);
	}		
	else if(b > a && a > c){
		printf("%d %d %d\n",c,a,b);
	}
	else if(a > b && b > c){
		printf("%d %d %d\n",c,b,a);
	}
	else if(a == b && a,b > c){
		printf("%d %d %d\n",c,a,b);
	}
	else if(a == b && a,b < c){
		printf("%d %d %d\n",a,b,c);
	}
	else if(a == c && a,c > b){
		printf("%d %d %d\n",b,a,c);
	}
	else if(a == c && a,c < b){
		printf("%d %d %d\n",a,c,b);
	}
	else if(b == c && b,c > a){
		printf("%d %d %d\n",a,b,c);
	}
	else if(b == c && b,c < a){
		printf("%d %d %d\n",b,c,a);
	}
	else{
		printf("%d %d %d\n",a,b,c);
	}
	return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;


int main() {
  int n,m;
  cin >> n >> m;
  vector<int> a(n,-1);
  bool t=true;
  rep(i,m){
    int f,g;
    cin >> f >> g;
    if (a[f-1]!=g && a[f-1]!=-1) t=false;
    a[f-1]=g;
  }
  if (a[0]==0 && n!=1) t=false;
  if (!t) cout << -1 << endl;
  else {
    rep(i,n){
      if (a[i]==-1){
        if (i==0 && n!=1) cout << 1;
        else cout << 0;
      }
      else cout << a[i];
    }
    cout << endl;
  }
}


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

dp = [[-1]*102 for _ in range(sum(T) + 1)]
dp[0][0] = 0

nt = 0
pt = T[0]
# i 秒から i+1 秒へ配る
delta = [-1,0,1]
for i in range(sum(T)):
    if pt == i:
        nt += 1
        pt += T[nt]
    for j in range(101):
        if j > V[nt] or dp[i][j] == -1:break
        for d in delta:
            nj = j + d
            if 0 <= nj <= V[nt]:
                if d != 0 or j == V[nt]:
                    dp[i+1][nj] = max(dp[i+1][nj], dp[i][j] + (j+nj)/2)
                else :
                    dp[i+1][nj] = max(dp[i+1][nj], dp[i][j] + j + 0.25)

print(dp[-1][0])


Measured memory_bytes: 110940
#include<iostream>
void insertionsort(int A[],int n){
  int v,j;
  for(int i=0;i<n;i++){
    v=A[i];
    j=i-1;
    while(j>=0&&A[j]>v){
      A[j+1]=A[j];
      j--;
    }
      A[j+1]=v;
    for(int k=0;k<n;k++){
      std::cout<<A[k];
      if(k<n-1){
	std::cout<<" ";
      }
    }
    std::cout<<"\n";
  }
}

int main(){
  int N,a;
  int A[100]={0};
  std::cin>>N;
  for(int i=0;i<N;i++){
    std::cin>>a;
    A[i]=a;
  }
  insertionsort(A,N);
  return 0;
}



Measured memory_bytes: 3100
#include <stdio.h>
int main()
{
    int a,b,c,d,e,k;
    scanf("%d\n%d\n%d\n%d\n%d\n%d",&a,&b,&c,&d,&e,&k);
    if (b-a<=k&&c-a<=k&&d-a<=k&&e-a<=k&&c-b<=k&&d-b<=k&&e-b<=k&&d-c<=k&&e-c<=k&&e-d<=k)
        printf("Yay!");
    else
        printf(":(");
    return 0;
}

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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '?') {
      s[i] = 'D';
    }
  }
  cout << s << endl;
  return 0;
}


Measured memory_bytes: 3740
N, M = map(int,input().split())
H = list(map(int,input().split()))
a=[]
for i in range(M):
	a.append(list(map(int,input().split())))
ans={i for i in range(1,N+1)}
for i in range(M):
	if H[a[i][0]-1] == H[a[i][1]-1]:
		dif = {a[i][0],a[i][1]}
	elif H[a[i][0]-1] > H[a[i][1]-1]:
		dif = {a[i][1]}
	else:
		dif = {a[i][0]}
	ans -= dif
print(len(ans))

Measured memory_bytes: 40344
#include<stdio.h>
int main()
{
    int n,i;
    long long hi,s[100010],t[100010];
    
    scanf("%lld %d",&hi,&n);
    for(i=0;i<n;i++) scanf("%lld %lld",&s[i],&t[i]);
    
    int m=0;
    long long head=s[0],sum=0,ans=0;
    for(i=0;i<n;i++){
        sum += t[i]-s[i];
        while(t[i]-head > hi){
            if(s[m] <= t[i]-hi && t[i]-hi < t[m]){
                head = t[i]-hi;
                sum -= head-s[m];
            } else {
                sum -= t[m]-head;
                m++;
                head = s[m];
            }
        }
        if(ans < sum) ans = sum;
    }
    printf("%lld\n",ans);
    
    return(0);
}



Measured memory_bytes: 4260
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

int main(){
	int n;
	cin >> n;
	cout << "ABC" << n << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.lang.Math;
public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        String T = sc.next();
        char[] work = new char[S.length()];
        char[] work2 = new char[T.length()];
        int counter = 0;
        for(int i = 0; i < S.length(); i++){
                work[i] = S.charAt(i);
                work2[i] = T.charAt(i);
                if(work[i] != work2[i]){
                    counter++;
                }
            }
        System.out.println(counter);
    }
}


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

int main(){
	int x,y,z;
	cin>>x>>y>>z;

	x-=z;
	int count=0;
	while(x-y-z>=0){
		x-=(y+z);
		count++;
	}

	cout<<count<<endl;
} 

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

struct Init {
  Init() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
  }
} Init;

signed main() {
  int A, B, P, Q, R;
  cin >> A >> B >> P >> Q >> R;

  cout << double(P * B - Q * B + Q * A) / (Q + R) + B << endl;
  return 0;
}


Measured memory_bytes: 3304
# -*- coding: utf-8 -*-
import sys
import math
import collections
#sys.setrecursionlimit(100000)

#n=int(input())
tmp = input().split()
a,b = list(map(lambda a: int(a), tmp))

s=""
if(a>=b):
	max=a
	min=b
else:
	max=b
	min=a

for i in range(max):
	s+=str(min)
print(s)


Measured memory_bytes: 3436
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
  int n,m;
  while(cin>>n>>m,n){
    vector<pair<int,int> >v;
    int a[n][n],b[4][m][m];
    r(i,n)r(j,n)cin>>a[i][j];
    r(i,m)r(j,m)cin>>b[0][i][j];
    r(i,m)r(j,m)b[1][i][j]=b[0][j][m-i-1];
    r(i,m)r(j,m)b[2][i][j]=b[0][m-1-j][i];
    r(i,m)r(j,m)b[3][i][j]=b[0][m-1-i][m-1-j];
    r(i,n-m+1)r(j,n-m+1)r(k,4){
      int c=0;
      r(q,m)r(w,m)if(b[k][q][w]>=0)
       if(a[i+q][j+w]!=b[k][q][w])c++;
      if(!c)r(q,m)r(w,m)if(b[k][q][w]>=0)
        v.push_back(make_pair(q+i,w+j));
    }if(!v.size())cout<<"NA"<<endl;
    else{
      sort(v.begin(),v.end());
      cout<<v[0].second+1<<' '<<v[0].first+1<<endl;
    }
  }
}

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

int main() {
  int H, N;
  int a, A;
  cin >> H >> N;
  for (int i=0; i<N; i++){
    cin >> A;
    a += A;
  }
  if (a >= H)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}



Measured memory_bytes: 256
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Stack;

/*
 * @author Tanzim Ibn Patowary
 * Created  May 29, 2020 9:22:05 PM
 */
public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		for (int i = 0; i < 5; i++) {
			int x = in.nextInt();
			if (x==0) {
				System.out.println(i+1);
				break;
			}
		}
	}
}

Measured memory_bytes: 26948
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define rep1(i,n) for(int i=1;i<=(n);++i)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
const int MAX_V=500,inf=1e8;
//??????????????¨???????????¨????????????erase??§???????????????????????????
//map[s][t]???edge????????±(??????cap??????)?????????
map<int,int> G[MAX_V];
int level[MAX_V];
map<int,int>::iterator iter[MAX_V];
void add_edge(int from, int to, int cap=1){
	G[from][to]=G[to][from]=cap;
}
void erase_edge(int from, int to){
	G[from].erase(to);
	G[to].erase(from);
}
void bfs(int s){
	memset(level,-1,sizeof(level));
	queue<int> que;
	level[s]=0;
	que.push(s);
	while(!que.empty()){
		int v=que.front();
		que.pop();
		for(auto e:G[v]){
			if(e.sc>0 && level[e.fs]<0){
				level[e.fs]=level[v]+1;
				que.push(e.fs);
			}
		}
	}
}
int dfs(int v,int t,int f){
	if(v==t) return f;
	for(;iter[v]!=G[v].end();iter[v]++){
		int u=iter[v]->fs;
		if(G[v][u]>0 && level[v]<level[u]){
			int d=dfs(u,t,min(f,G[v][u]));
			if(d>0){
				G[v][u]-=d;
				G[u][v]+=d;
				return d;
			}
		}
	}
	return 0;
}
int max_flow(int s,int t){
	int flow=0;
	while(true){
		bfs(s);
		if(level[t]<0) return flow;
		rep(i,MAX_V) iter[i]=G[i].begin();
		int f;
		while( (f=dfs(s,t,inf))>0 ) flow+=f;
	}
}
int main(){
	int N,E,Q;
	cin>>N>>E>>Q;
	rep(i,E){
		int F,T;
		cin>>F>>T;
		add_edge(F-1,T-1);
	}
	int now=max_flow(0,N-1);
	rep(i,Q){
		int m,a,b;
		cin>>m>>a>>b;
		a--,b--;
		if(m==1){
			add_edge(a,b);
			now+=max_flow(0,N-1);
		}else{
			int ecap=G[a][b];
			erase_edge(a,b);
			if(ecap==2) swap(a,b);
			if(ecap!=1){
				rep(i,N) iter[i]=G[i].begin();
				bfs(a);
				int f=dfs(a,b,1);
				if(f==0){
					rep(i,N) iter[i]=G[i].begin();
					bfs(a);
					dfs(a,0,1);
					rep(i,N) iter[i]=G[i].begin();
					bfs(N-1);
					dfs(N-1,b,1);
					now--;
				}
			}
		}
		printf("%d\n",now);
	}
}

Measured memory_bytes: 3172
BIT = [0] * ((1 << 19) + 1)
def add(i, x):
    while i <= (1 << 19):
        BIT[i] += x
        i += i & -i
def query(i):
    res = 0
    while i > 0:
        res += BIT[i]
        i -= i & -i
    return res
n, q = map(int, input().split())
c = list(map(int, input().split()))
Q = [[] for i in range(n)]
for i in range(q):
    l, r = map(int, input().split())
    Q[r - 1].append([l - 1, i])
l = [-1] * n
a = [-1] * q
add(1, n)
for i in range(n):
    add(l[c[i] - 1] + 2, -1)
    add(i + 2, 1)
    l[c[i] - 1] = i
    for j in Q[i]:
        a[j[1]] = query(1 << 19) - query(j[0] + 1)
print(*a, sep="\n")

Measured memory_bytes: 229212
#include<stdio.h>
    #include <string.h>
     
    int main(void){
      int limit = 200001;
      char str1[limit];
      char str2[limit];
      scanf("%s", str1);
      scanf("%s", str2);
     
      int i;
      int count = 0;
      int length = strlen(str1);
      int lengthTrue = strlen(str2);
     
      if(length == lengthTrue){
      for(i = 0; i < length; i++){
        if(str1[i] != str2[i]){
          count++;
        }
      }
     
      printf("%d\n",count);
    }
    }

Measured memory_bytes: 2120
#include<bits/stdc++.h>
#define  mes(a, b)  memset(a, b, sizeof a)
#define pb push_back
typedef unsigned long long int ull;
typedef long long int ll;
const int    maxn = 2e5 + 20;
const int    maxm = 1e5 + 10;
const ll     mod  = 1e9 + 7;
const ll     INF  = 1e18 + 100;
const int    inf  = 0x3f3f3f3f;
const double pi   = acos(-1.0);
const double eps  = 1e-8;
using namespace std;
std::vector<int> mp[maxn];
int ans[maxn],dis[maxn],vis[maxn];
void spfa(int x){
    queue<int>q;
    q.push(x);dis[x] = 0;vis[x] = 1;
    while(!q.empty()){
        int u = q.front();q.pop();
        for(auto it : mp[u]){
            if(vis[it]) continue;
            dis[it] = dis[u] + 1;
            q.push(it);
            vis[it] = 1;
        }
    }
}
int main(){
    int n;cin >> n;
    for(int i = 1;i < n;i++){
        mp[i].push_back(i + 1);mp[i + 1].push_back(i);
    } 
    int x,y;cin >> x >> y;mp[x].push_back(y);mp[y].push_back(x);
    for(int i = 1;i <= n;i++){
        mes(vis,0);
        spfa(i);
        for(int j = i + 1;j <= n;j++) ans[dis[j]]++;
    }
    for(int i = 1;i < n;i++) printf("%d\n",ans[i]);
}

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


#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = (int)1e9 + 7; typedef vector<ll> VL;
void dbg(){ cerr << "\n"; }  template <class T, class ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T, class T2> void amax(T& a,T2 b){ if(a < b) a = b;}

int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	string s;
	cin >>s;
	int n=sz(s);
	rep(i, n-1){
		if(s[i]==s[i+1]){
			printf("%d %d\n", i+1, i+2); return 0;
		}else if(i+2<n && s[i]==s[i+2]){
			printf("%d %d\n", i+1, i+3); return 0;
		}
	}

	puts("-1 -1");
	return 0;
}


Measured memory_bytes: 512
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

n,m = map(int,readline().split())
mod = 10**9+7
a = [0]+[int(i) for i in readline().split()]
b = [0]+[int(i) for i in readline().split()]
dp = [[0]*(m+1) for i in range(n+1)]
su = [[0]*(m+1) for i in range(n+1)]

dp[0][0] = 1
su[0][0] = 1
for i in range(1,n+1):
  su[i][0] = 1
for j in range(1,m+1):
  su[0][j] = 1
  
for i in range(1,n+1):
  for j in range(1,m+1):
    if a[i] == b[j]:
      dp[i][j] = su[i-1][j-1]
    else:
      dp[i][j] = 0
    su[i][j] = su[i-1][j]+su[i][j-1]-su[i-1][j-1]+dp[i][j]
    su[i][j] %= mod
    
print(su[n][m])

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

int main() {
    ll n, q; cin >> n;
    vector<ll> seq_s(n);
    for(int i = 0; i < n; i++) { cin >> seq_s.at(i); }
    cin >> q; 
    vector<ll> seq_t(q);
    for(int i = 0; i < q; i++) { cin >> seq_t.at(i); }

    ll sum = 0;
    for(ll i = 0; i < q; i++) {
        for(ll j = 0; j < n; j++) {
            if(seq_s.at(j) == seq_t.at(i)) {
                sum++;
                break;
            }
        }
    }
    cout << sum << endl;

    return 0;
}




Measured memory_bytes: 3148
x, n = [int(s) for s in input().split(" ")]
if n == 0:
  print(x)
else:
  plist = [int(s) for s in input().split(" ")]

  dlist = {}
  for p in plist:
    d = abs(p - x)
    if d in dlist or d == 0:
      dlist[d] = (True, None)
    else:
      dlist[d] = (False, p - x)

  sorted_d = sorted(dlist.items(), key=lambda x:x[0])

  ans = 0
  prevk = 0
  flag = False
  for k, v in sorted_d:
    if not flag and prevk == 0 and k >= 1:
      ans = 0
      break
    elif k - prevk > 1:
      ans = -(prevk + 1)
      break
    elif not v[0]:
      ans = -v[1]
      break
    flag = True
    prevk = k
    ans = -(k + 1)
  print(x + ans)

Measured memory_bytes: 9192
l, r = gets.split(" ").map(&:to_i)
array = []
if r - l >= 2019
    puts 0
else
    (l..r).to_a.each do |i|
        (i+1..r).to_a.each do |j|
            array << i*j%2019
        end
    end
end

puts array.min

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

#define endl '\n'
using namespace std;
bool is_palindrome(string s, int start, int end) {
    int n = s.length();
    for(int i = 0; i <= (end - start) / 2; i++) {
        if(s[start + i] != s[end - i])
            return false;
    }
    return true;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    int N = s.length();
    if(is_palindrome(s, 0, s.length()-1)){
        int A = ((N - 1) / 2) - 1;
        int B = ((N + 3) / 2) - 1;
        if(is_palindrome(s, 0, A) && is_palindrome(s, B, s.length() - 1))
            cout << "Yes" << endl;
        else
            cout << "No" << endl;
    }
    else
        cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<utility>
#include<cmath>
#include<algorithm>
#include<climits>
#include<complex>

#define debug(x) cerr << #x << ": " << x << endl
#define EPS 1e-5
 
using namespace std;

int main(){
    int n;
    double r, theta;
    cin >> n;
    cin >> r >> theta;
    theta = theta/180.0*M_PI;
    complex<double> cities[n];
    for(int i=0;i<n;i++){
        double x,y;
        cin >> x >> y;
        cities[i] = complex<double>(x, y);
    }
 
    bool ok[n][n][n];
    fill_n(**ok, n*n*n, false);
    double dist[n][n];
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(i == j) continue;
            complex<double> v = cities[j] - cities[i];
            dist[i][j] = abs(v);
            for(int k=0;k<n;k++){
                if(i == k || j == k) continue;
                complex<double> u = cities[k] - cities[j];
                double theta_ = abs(arg(u/v)); // arg(u) - arg(v)だと角度が違う
                if(theta_ < theta+EPS){
                    ok[i][j][k] = true;
                }
            }
        }
    }

    double dp[2][n][n];
    fill(dp[0][0], dp[0][n], 200000.0);
    for(int j=1;j<n;j++){
        dp[0][0][j] = dist[0][j];
    }
    int i = 0, ans = 0;
    for(int i=0;i<=10000;i++){
        fill(dp[1-(i&1)][0], dp[1-(i&1)][n], 200000.0);
        for(int j=0;j<n;j++){
            for(int k=0;k<n;k++){
                if(j == k || dp[i&1][j][k] > r+EPS) continue;
                for(int l=0;l<n;l++){
                    if(j == l || k == l) continue;
                    if(ok[j][k][l]){
                        dp[1-(i&1)][k][l] = min(dp[1-(i&1)][k][l], dp[i&1][j][k] + dist[k][l]);
                    } 
                }
                ans = i+1;
            }
        }
    }
 
    cout << ans << endl;
}


Measured memory_bytes: 3472
#include<stdio.h>
#define N 100001
int depth(int);
struct Node{
  int p;
  int l;
  int r;
};
struct Node T[N];


int main()
{

  int i,j,n,par,child,sib,k,x;

  scanf("%d",&n);
  for(i = 0; i < n; i++){
    T[i].p = -1;
    T[i].l = -1;
    T[i].r = -1;
  }

  for(i = 0; i < n; i++){
    scanf("%d %d",&par,&k);
    for(j = 0; j < k; j++){
      scanf("%d",&child);
      if(j == 0){
	T[par].l = child;
      T[child].p = par;
      x = child;
      }
      else {
    T[x].r = child;
    T[child].p= par;
    x = child;
      }
    }
  }

  for(i = 0; i < n; i++){
    printf("node %d: parent = %d, depth = %d, ",i , T[i].p,depth(i));
    if(T[i].l  == -1 && T[i].p != -1)printf("leaf, ");
    else if(T[i].p == -1)printf("root, ");
    else if(T[i].l != -1)printf("internal node, ");
    printf("[");

    if(T[i].l != -1){
      printf("%d",T[i].l);

      sib = T[i].l;

      while(1){
	if(T[sib].r == -1)break;
	printf(", %d",T[sib].r);
      sib = T[sib].r;
    }
    }
  printf("]\n");
  }

  return 0;
}

int depth(int k){
  int dep =0;
  for(dep = 0; T[k].p != -1; dep++){
    k = T[k].p;
  }
    return dep;
  }

Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 

int main()
{
    ll n,w,i,j;
    cin>>n>>w;
    ll a[n],b[n];
    for(i=0;i<n;i++)
    {
        cin>>a[i]>>b[i];
    }
    ll t[n+1][w+1];
    for(i=0;i<n+1;i++)
    {
        for(j=0;j<w+1;j++)
        {
            if(i==0||j==0)
            t[i][j]=0;
            else if(a[i-1]<=j)
            {
                t[i][j]=max(t[i-1][j-a[i-1]]+b[i-1],t[i-1][j]);
            }
            else
            t[i][j]=t[i-1][j];
           // cout<<t[i][j]<<endl;
        }
    }
    cout<<t[n][w]<<endl;
}

Measured memory_bytes: 82344
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pl;
typedef vector<ll> vl;

int main (void) {
  ios::sync_with_stdio(false);cin.tie(0);
  cout << fixed << setprecision(15);
  int n,m,x;
  cin >> n >> m >> x;
  vector<int> cost (n);
  vector<vector<int>> a (n, vector<int> (m));
  for (int i = 0; i < n; i++) {
    cin >> cost[i];
    for (int j = 0; j < m; j++)
      cin >> a[i][j];
  }
  int lm = 1<<12;
  int ans = INT_MAX;
  for (int i = 1; i < lm; i++) {
    int p = i;
    int total_cost = 0;
    vector<int> level (m, 0);
    for (int j = 0; j < n; j++) {
      if (p&1) {
        total_cost += cost[j];
        for (int k = 0; k < m; k++)
          level[k] += a[j][k];
      }
      p >>= 1;
    }
    bool good = true;
    for (int j = 0; j < m; j++) {
      if (level[j] < x) {
        good = false;
        break;
      }
    }
    if (good) {
      ans = min(ans, total_cost);
    }
  }
  if (ans == INT_MAX) cout << -1 << '\n';
  else cout << ans << '\n';
  return 0;
}



Measured memory_bytes: 3660
n = gets.to_i
ret = [0, 0]
n.times do
    a,b = gets.chomp.split(" ")
    if a > b
        ret[0] += 3
    elsif a < b
        ret[1] += 3
    else
        ret[0] += 1
        ret[1] += 1
    end
end
puts ret.join(" ")


Measured memory_bytes: 8884
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
typedef long long ll;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define rrep(i,n,a) for(int i=n;i>=a;i--)
#define FOR(i,n) for(int i=0;i<n;i++)
#define all(s) s.begin(),s.end()
#define lla(s) s.rbegin(),s.rend()
#define pcnt(b) __builtin_popcount(b)
const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const ll INF = 1e18;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,m,d,t;
    cin>>n;
    map<int,int>q;
    rep(i,0,n){
        cin>>d;
        q[d]++;
    }
    cin>>m;
    rep(i,0,m){
        cin>>t;
        q[t]--;
    }
    for(auto i:q){
        if(i.second<0){cout<<"NO"<<endl;return 0;}
    }
    cout<<"YES"<<endl;return 0;
}


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

constexpr int MAXN = 1010;

ll N,A,B,C,D;

ll dp[MAXN][MAXN];

ll fact[MAXN],fact_inv[MAXN];

ll mod_pow(ll x,ll n,ll mod){
    ll ret=1;
    while(n){
        if(n&1) ret = (ret *x) % mod;
        x = (x*x) % mod;
        n >>= 1;
    }
    return ret;
}

void init(){
    fact[0] = 1;
    for(int i=1;i<MAXN;i++) fact[i] = (fact[i-1]*i) % mod;
    for(int i=0;i<MAXN;i++) fact_inv[i] = mod_pow(fact[i],mod-2,mod);
}

int main(){
    scanf("%lld%lld%lld%lld%lld",&N,&A,&B,&C,&D);

    init();

    dp[0][A] = 1;

    for(int i=0;i<=N;i++){
        for(int j=A;j<=B;j++){
            if(dp[i][j] <= 0) continue;

            dp[i][j+1] += dp[i][j]; // k=0
            dp[i][j+1] %= mod;

            for(int k=C;k<=D;k++){
                int nxt = i+j*k;
                if(nxt>N) break;
                ll t = dp[i][j];
                t = (t*fact[N-i]) % mod;
                t = (t*fact_inv[N-i-j*k]) % mod;
                t = (t * fact_inv[k]) % mod;
                t = (t * mod_pow(fact_inv[j],k,mod)) % mod;
                dp[nxt][j+1] += t;
                dp[nxt][j+1] %= mod;
            }
        }
    }

    //for(int i=0;i<N+1;i++){
    //    for(int j=0;j<B+2;j++){
    //        cout << dp[i][j] << " ";
    //    }
    //    cout << endl;
    //}

    printf("%lld\n",dp[N][B+1]);
}


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

int main(){
  ll n;
  cin >> n;
  ll m = n;
  int d = 0;
  vector<int> a;
  while(m > 0) {
    a.push_back(m % 10);
    m /= 10;
    d++;
  }
  reverse(a.begin(),a.end());
  vector<vector<int>> dp(d+1,vector<int>(2,-INF));
  dp[0][0] = 0;
  rep(i,d) {
    rep(j,10) {
      if(a[i] == j) dp[i+1][0] = max(dp[i+1][0],dp[i][0]+a[i]);
      else if(j < a[i]) dp[i+1][1] = max(dp[i+1][1],dp[i][0]+j);
      dp[i+1][1] = max(dp[i+1][1],dp[i][1]+j); 
    }
  }
  cout << max(dp[d][0],dp[d][1]) << endl;
  return 0;
}

Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;

int main(){
    int h,w;
    cin>>h>>w;
    int n=h*w;
    string s[h];
    for(int i=0;i<h;i++){
        cin>>s[i];
    }
    int d[n][n];
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            d[i][j]=INF;
        }
        d[i][i]=0;
    }
    const int dx[]={-1,0,0,1};
    const int dy[]={0,-1,1,0};
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(s[i][j]=='#')continue;
            for(int k=0;k<4;k++){
                int nx=i+dx[k];
                int ny=j+dy[k];
                if(nx<0||h<=nx||ny<0||w<=ny||s[nx][ny]=='#')continue;
                d[w*i+j][w*nx+ny]=1;
            }
        }
    }
    for(int k=0;k<n;k++){
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
            }
        }
    }
    int ans=-1;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(d[i][j]!=INF){
                ans=max(ans,d[i][j]);
            }
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 896
function main(lines) {
  const N = n();
  const S = s();

  let ans = i = 0;
  while (i < N-2) {
    if (S[i] == 'A' && S[i+1] == 'B' && S[i+2] == 'C') {
      ans++;
      i += 2;
    }
    i++;
  }
  
  return ans;
}



const lines = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");

let lineCount = 0;
const s = () => lines[lineCount++];
const n = () => Number(s());
const b = () => BigInt(s());
const sa = () => s().split(' ');
const na = () => sa().map(Number);
const ba = () => sa().map(BigInt);

const ans = main(lines);
console.log( ans );

Measured memory_bytes: 29660
import java.util.Scanner;

public class Main{
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int n;
		String str[] = new String[6];
		
		str[0] = "";
		str[1] = "";
		str[2] = "";
		str[3] = "";
		str[4] = "";
		str[5] = "";
		n = sc.nextInt();
		for (int i = 0; i < n; i++) {
			double a = sc.nextDouble();
			if (a < 165.0) {
				str[0] += "*";
			} else if (a < 170.0) {
				str[1] += "*";
			} else if (a < 175.0) {
				str[2] += "*";
			} else if (a < 180.0) {
				str[3] += "*";
			} else if (a < 185.0) {
				str[4] += "*";
			} else {
				str[5] += "*";
			}
		}
		
		for (int i = 0; i < 6; i++) {
			System.out.println((i + 1) + ":" + str[i]);
		}
	}
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
using namespace std;
int i,j,k,n,m,x,y,t;
bitset<4000100>f;
int main(){
	scanf("%d",&n);f|=1;
	for (i=1;i<=n;i++){ scanf("%d",&x); f|=f<<x; t+=x; }
	for (i=t+1>>1;i<=t;i++)if (f[i])return printf("%d ",i),0;
}

Measured memory_bytes: 1664
#include<stdio.h>

int main(){
    int N,X,ans,i;
    scanf("%d %d",&N,&X);
    int m[N];
    int min = 1000;
    for(i=0;i<N;i++){
        scanf("%d",&m[i]);
        X -= m[i];
        if(m[i]<min) min = m[i];
    }
    ans = N + X/min;
    printf("%d\n",ans);
        
    return 0;
}

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

typedef long long ll;
const int INF = 1e9;
const ll LINF = 1e18;
const int mod = 1e9+7;

#define pi pair<int,int>
#define pl pair<lld,lld>

#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl

#define mem0(x) memset(x,0,sizeof(x))
#define fillnum(x,n) fill(begin(x),end(x),n)
#define asort(x) sort(x.begin(),x.end())
#define dsort(x,t) sort(x.begin(),x.end(),greater<t>())
#define vuniq(x) x.erase(unique(x.begin(), x.end()), x.end())

#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)

int main() {
    ll N,X,T;
    cin >> N >> X >> T;
    cout << (N%X == 0 ? N/X*T : (N/X+1)*T) << endl;
}

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

bool check(int A, int B){
    
    if( A > 8 || B > 8 ){
        return false;
    }
    
    bool A_get = false;
    bool B_get = false;
    for( int i = 0; i < 16; ++i ){
        // 最初の一個はAを指定した人がとる
        if( A > 0 && !A_get ){
            --A;
            A_get = true;
            B_get = false;
            continue;
        }
        
        if( B > 0 && !B_get ){
            --B;
            B_get = true;
            A_get = false;
            continue;
        }
        
        A_get = false;
        B_get = false;
    }
    
    if( A == 0 && B == 0 && !A_get){
        return true;
    }else{
        return false;
    }
    
}

int main(){
    int A, B;
    cin >> A >> B;
    
    if( check(A,B) ){
        cout << "Yay!" << endl;
    }else{
        cout << ":(" << endl;
    }
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#define ll long long
using namespace std;
int main(){
    int m;
    scanf("%d",&m);
    for(int i=1;i<10;i++){
        for(int j=1;j<10;j++){
            if(i*j==m){printf("Yes\n");return 0;}
        }
    }
    printf("No\n");
    return 0;
}

Measured memory_bytes: 128
import Control.Monad
import Data.List

main :: IO ()
main = replicateM 2 getLine >>= putStrLn . solve 

solve :: [String] -> String
solve [ss, ts]
    | match "" ss = "Yes"
    | otherwise = "No"
    where
        match xs yys@(y : ys)
            | reverse xs `isSuffixOf` ts && yys `isPrefixOf` ts = True
            | otherwise = match (y : xs) ys
        match _ _ = False

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

#define eb emplace_back
#define INF 1LL<<62
#define FLT_INF pow(10.0, 16)

using ll = long long;
using vll = vector<ll>;
using ull = unsigned long long;
using int2 = pair<int, int>;

template <typename A> string to_string(const A& v);
string to_string(const string& s) { return '"'+ s + '"'; }
string to_string(const char *s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }

template <typename A, typename B> string to_string(const pair<A, B>& p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A> string to_string(const A& v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

template <typename T>
void sort(vector<T>& val) {
  sort(val.begin(), val.end());
}

template <typename T>
void sort_b(vector<T>& val) {
  sort(val.begin(), val.end(), greater<T>());
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...);
#endif

#define COMMON_MOD pow(10, 9) + 7
#define PI 3.14159265

// sort(a.begin(), a.end(), less<ll>()); greater<ll>()
// cout<<fixed<<setprecision(20)<<(s/kl)*2;

void color_edges(const vector<vector<pair<int, int>>>& edges, int current_vert, vll& used_vertices, vll& vert_colors) {
  for (auto& edge: edges[current_vert]) {
    if (used_vertices[edge.first] == 1) {
      continue;
    }
    used_vertices[edge.first] = 1;
    if (edge.second % 2 == 0) {
      vert_colors[edge.first] = vert_colors[current_vert];
    } else {
      vert_colors[edge.first] = (vert_colors[current_vert] + 1) % 2;
    }
    color_edges(edges, edge.first, used_vertices, vert_colors);

  }

}

int main() {

  ios::sync_with_stdio(false);
  cin.tie(0);

  // ll n, m;
  // cin >> n >> m;
  //
  // vector<vll> edges(n, vll());
  //
  // for (int i = 0; i < m; i++) {
  //   ll x, y, z;
  //   cin >> x >> y >> z;
  //   edges[x].eb(y);
  //   edges[y].eb(x);
  // }

  ll n;
  cin >> n;

  if (n == 1) {
    cout << 0 << endl;
    return 0;
  }

  vector<vector<pair<int, int>>> edges(n, vector<pair<int, int>>());
  for (int i = 0; i < n - 1; i++ ) {
    int u, v, w;
    cin >> u >> v >> w;
    u--;
    v--;
    edges[u].push_back({v, w});
    edges[v].push_back({u, w});
  }

  vll vert_colors(n, 0);
  vll used_vertices(n, 0);


  for (int i = 0; i < n; i++) {
    if (used_vertices[i] == 0) {
      used_vertices[i] = 1;
      vert_colors[i] = 0;
      color_edges(edges, i, used_vertices, vert_colors);
    }
  }



  for (int i = 0; i < n; i++) {
    cout << vert_colors[i] << endl;
  }



  //debug(edges);


  cout << endl;
  return 0;
}


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

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


Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
LL val[15][15];
int main() {
    int n, m;
    scanf("%d%d", &n, &m);
    for(int i = 0; i <= 9; ++i) {
        for(int j = 0; j <= 9; ++j) {
            scanf("%lld", &val[i][j]);
        }
    }
    for(int k = 0; k <= 9; ++k) {
        for(int i = 0; i <= 9; ++i) {
            for(int j = 0; j <= 9; ++j) {
                val[i][j] = min(val[i][j], val[i][k] + val[k][j]);
            }
        }
    }
    LL sum = 0;
    for(int i = 1; i <= n; ++i) {
        for(int j = 1; j <= m; ++j) {
            int res;
            scanf("%d", &res);
            if(res != -1) {
                sum += val[res][1];
            }
        }
    }
    printf("%lld\n", sum);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define erep(i, n) for (ll i = 0; i <= (ll)(n); ++i)
#define FOR(i,a,b) for (ll i = (a); i < (ll)(b); ++i)
#define EFOR(i,a,b) for (ll i = (a); i <= (ll)(b); ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } }

typedef pair<int, int> P;



struct Edge { int to, id; };
using Graph = vector<vector<Edge>>;

Graph g;
vector<int> ans;

// 確認する頂点番号, 親と確認する頂点を結ぶ辺の色, 親の頂点番号
void dfs(int v, int color, int parent) {
    int c = 1;
    // 今の頂点から辿れるやつ
    rep(i, g[v].size()) {
        int u = g[v][i].to, id = g[v][i].id;
        // 親の場合は何もしない
        if (u == parent) continue;
        // 親から来たときに使った色は使えない
        if (c == color) c++;
        // 解答用に, cinしたときのindexに色を入れておく
        ans[id] = c; c++;
        dfs(u, ans[id], v);
    }
}

int main() {
    int n; cin >> n;
    g.resize(n);
    ans.resize(n-1);
    for(int i=0; i<n-1; i++) {
        int a, b; cin >> a >> b;
        a--; b--;
        g[a].push_back((Edge){b,i});
        g[b].push_back((Edge){a,i});
    }
    dfs(0, -1, -1);

    // 使う色数の確認, 一番次数が多いとこの次数=使う色
    int color_num = 0;
    rep(i, n) chmax(color_num, (int)g[i].size());
    cout << color_num << endl;
    rep(i, n-1) cout << ans[i] << endl;

    return 0;
}

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

typedef   long long  int ll;
typedef  long double ld;
typedef std::vector<ll> vi;
typedef std::vector<std::vector<ll> > vv;

#define MOD 1000000007
#define IO ios_base::sync_with_stdio(false);cin.tie(NULL);
#define fo(i,a,b) for(i=a;i<b;i++)
#define mp make_pair
#define pb(x) push_back(x)
#define fi first
#define se second
#define print(vec,a,b) for(ll i=a;i<b;i++) cout<<vec[i]<<" ";cout<<endl;
#define all(a) a.begin(),a.end()
#define input(vec,a,b) for(ll i = a;i<b;i++) cin>>vec[i];
#define ms(a,val) memset(a,val,sizeof(a))
using namespace std;

const int N = 1e5 + 5;


void solve(){
            ll i,j,n,m,k;
            
            
            cin>>n;
            ll dp[n][3];
            ms(dp,0);
            ll a[n][3];
            fo(i,0,n)
            {fo(j,0,3)
				cin>>a[i][j];
			}
			fo(i,0,3)
			dp[0][i] = a[0][i];//,dp[1] = a[1],dp[2]  =a[2];
			fo(i,1,n)
			{
				fo(j,0,3)
				{
					//dp[i][j] = INT_MAX;
					fo(k,0,3)
					{
						if(j^k)
						 dp[i][j] = max(dp[i][j],dp[i-1][k] + a[i][j]);
					 }
				 }
			 }
			 ll minn =  INT_MIN;
			 fo(i,0,3)
			  minn = max(minn,dp[n-1][i]);
			  cout<<minn<<endl;
            
    
            
						            









}

int main()
{
    IO;
      ll t=1;
      //cin>>t;


      while(t--)
      {

          solve();
      }
    return 0;
}


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

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        long n = sc.NextLong();
        long a = sc.NextLong();
        long b = sc.NextLong();
        string s = sc.Next();

        long count = 0;
        long order = 1;
        for (int i = 0; i < n; i++)
        {
            if (s[i] == 'a')
            {
                if (count < a + b)
                {
                    Console.WriteLine("Yes");
                    count++;
                }
                else
                {
                    Console.WriteLine("No");
                }
            }
            else if (s[i] == 'b')
            {
                if (count < a + b && order <= b)
                {
                    Console.WriteLine("Yes");
                    count++;
                }
                else
                {
                    Console.WriteLine("No");
                }
                order++;
            }
            else
            {
                Console.WriteLine("No");
            }
        }

    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}


Measured memory_bytes: 27852
import java.util.Scanner;

public class Main {
    public static void main(String args[]){
        Scanner stdIn = new Scanner(System.in);
        int a = stdIn.nextInt();
        int b = stdIn.nextInt();
        int c = stdIn.nextInt();
        int x = stdIn.nextInt();
        int count = 0;
        
        for(int i = 0; i <= a; i++){
            if(i * 500 > x){
                break;
            }
            for(int j = 0; j <= b; j++){
                if(i * 500 + j * 100 > x){
                    break;
                }
                for(int k = 0; k <= c; k++){
                    if(i * 500 + j * 100 + k * 50 > x){
                        break;
                    }
                
                    if(i * 500 + j * 100 + k * 50 == x){
                        count++;
                        break;
                    }
                }
            }
        }
        
        System.out.println(count);
    }
}


Measured memory_bytes: 23892
#include <iostream>
#include <stdio.h>
#include <string.h>

using namespace std;


int main(){
    int n,m,k;
    int a,b,c;
    scanf("%d %d %d",&n,&m,&k);
    for(int i=0;i<=2000;i++){
        for(int j=0;j<=2000;j++){
            if(i*n+j*m-2*i*j==k && i<=m && j<=n){
                
                puts("Yes");
                return 0;
            }
        }
    }
    puts("No");
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl '\n'

using namespace std;
template<class T, class T2> inline void chkmax(T &x, const T2 &y) { if(x < y) x = y; }
template<class T, class T2> inline void chkmin(T &x, const T2 &y) { if(x > y) x = y; }
const int MAXN = (1 << 20);

int n, k;

void read()
{
	cin >> n >> k;
}

void solve()
{
	int64_t answer = 0;
	for(int b = 1; b <= n; b++)
	{
		int initial_h = b - 1;
		if(initial_h >= k) answer += initial_h - k + 1;
		if(k == 0) answer -= 1;

		for(int low = b; low <= n; low += b)
		{
			int high = low + b - 1;
			chkmin(high, n);
				
			int len = high - low;
			if(len >= k) answer += (len - k + 1);
		}
	}

	cout << answer << endl;
}

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

	read();
	solve();
	return 0;
}



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

using namespace std;
#define sqr(x) ((x)*(x))
#define cube(x) ((x)*(x)*(x))
#define GCD(a, b) __gcd(a, b)
#define LCM(a, b) ((a)*(b)/GCD(a,b))
#define PI (3.141592653589793238462643383279502884197169399375105820974944)
#define MP make_pair
#define n1 first
#define n2 second
#define ALL(x) (x).begin(), (x).end()
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define PDB pair<db,db>
#define SI set<int>
#define SL set<ll>
#define MS multiset
#define MSI multiset<int>
#define MSLL multiset<ll>
#define PB push_back
#define PF push_front
#define VI vector<int>
#define VPI vector<pair<int,int>>
#define VLL vector<ll>
#define VS vector<string>
#define SZ(x) ((int)x.size())

typedef long long ll;

typedef unsigned long long ull;
typedef long double ld;
typedef double db;
const db eps = 0.000001;
const int INF = 1000000007;
const ll LINF = 1000000000000000555;
const int N = 1850555;
const int M = 1155;
const int L = 20;

void solve() {
    int n;
    cin >> n;

    ll ans = 0;
    for (int i = 1; i <= n; i++){
        int k = n / i;
        ans += 1ll * i * k * (k + 1) / 2;
    }

    cout << ans;

}

int main() {
    ios_base::sync_with_stdio(false);
#ifdef dxz05
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else

#endif

    int T = 1;
    //cin >> T;

    while (T--) {
        solve();
    }

    return 0;
}

Measured memory_bytes: 3648
#include<iostream>
#include<algorithm>
#include<math.h>

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

/**
 * 各桁の和を計算します
 */
int sumOfdigit(int n) {
    int res = 0;
    while(true) {

        res+= n % 10; // 余りを追加
        if (n / 10 > 0) n /= 10;
        else break;
    }
    return res;
}

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

    int sum = sumOfdigit(N);

    if (N % sum == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
from collections import deque
import heapq
from collections import Counter
import math

# ------------------------------------------------------
class IN:
    @staticmethod
    def singleInt():
        return int(input())

    @staticmethod
    def singleStr():
        return input()

    @staticmethod
    def listInt():
        return list(map(int, input().split()))

    @staticmethod
    def listStr():
        return input().split()
# ------------------------------------------------------

print = lambda s: sys.stdout.write(str(s) + "\r\n")

def contain(c, x):
    return (x in c)

def str_reverse(s):
    return s[::-1]

def ctoi(c):
    return int.from_bytes(c.encode(), byteorder='big')
def itoc(x):
    return x.to_bytes((x.bit_length() + 7) // 8, byteorder='big').decode()

INF = 1001001001001001001
MOD = 1000000007
# ------------------------------------------------------

if __name__ == '__main__':
    N, M, S = IN.listInt()
    g = [[] for i in range(N)]
    for i in range(M):
        a, b, c = IN.listInt()
        g[a].append((b, c))
    
    hp = []
    dist = [INF for i in range(N)]
    heapq.heappush(hp, (0, S))
    dist[S] = 0
    while len(hp) > 0:
        _, v = heapq.heappop(hp)
        for (w, c) in g[v]:
            if dist[w] > dist[v] + c:
                dist[w] = dist[v] + c
                heapq.heappush(hp, (dist[w], w))

    for i in range(N):
        if dist[i] == INF:
            print("INF")
        else:
            print(dist[i])




Measured memory_bytes: 89676