akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define irep(i,n) for(int i = 0; i < (int)(n); i++)
#define irep2(i,a,n) for(int i = (int)(a); i <= (int)(n); i++)
#define lrep(i,n) for(long long  i = 0; i < (long long)(n); i++)
#define lrep2(i,a,n) for(long long i = (long long)(a); i <= (long long)(n); i++)
#define irrep(i,n) for(int i = (int)(n-1); i > -1; i--)
#define irrep2(i,a,n) for(int i = (int)(n); i >= (int)(a); i--)

typedef long long ll;
typedef std::vector<int> v_int;
typedef std::vector<v_int > v2_int;
typedef std::vector<ll> v_ll;
typedef std::vector<v_ll > v2_ll;
typedef std::vector<std::string> v_string;
typedef std::vector<v_string > v2_string;
typedef std::vector<bool> v_bool;
typedef std::vector<v_bool > v2_bool;
typedef std::pair<ll, ll> pll;
typedef std::pair<int, int> pii;

const double PI = 3.1415926535897932;
const int INF = (int)1e9;
const ll LINF = 1e18;
const int IMOD = 1000000007;
const int dr[4] = {1, 0, -1, 0};
const int dc[4] = {0, 1, 0, -1};

using namespace std; 

int main(void)
{
    int n, m, k;
    cin >> n >> m >> k;
    
    if(k%n == 0 || k%m == 0) {
        cout << "Yes" << endl;
        return 0;
    }
    
    irep2(i, 1, n) {
        irep2(j, 1, m) {
            int K = i*m + (n-i)*j - i*j;
            if(K == k) { 
                cout << "Yes" << endl;
                return 0;
            }
        } 
    }
    cout << "No" << endl;
    return 0;
}
/** atcoder **/



Measured memory_bytes: 256
//
//  main.c
//  ITP1_4_B
//
//  Created by ??±??°?????? on 2015/09/27.
//  Copyright ?? 2015??´ HamadaShogo. All rights reserved.
//

#include <stdio.h>
#include <math.h>

int main(int argc, const char * argv[]) {
    double r;
    double S, L;
    
    scanf("%lf", &r);
    S = pow(r, 2)*M_PI;
    L = 2*r*M_PI;
    
    printf("%f %f\n", S, L);
    
    return 0;
}

Measured memory_bytes: 648
package main

import (
	"bufio"
	"fmt"
	"os"
)

var scanner = bufio.NewScanner(os.Stdin)

func scanText() string {
	scanner.Scan()
	return scanner.Text()
}

func main() {
	scanner.Split(bufio.ScanWords)
	s := scanText()
	b := s[0]
	for i := 1; i < 3; i++ {
		if s[i] != b {
			fmt.Println("Yes")
			return
		}
	}
	fmt.Println("No")
}

Measured memory_bytes: 640
#include <iostream>
#include <fstream>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <ctime>
#include <algorithm>
#include <sstream>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <cstdlib>
#include <cstdio>
#include <iterator>
#include <functional>
#include <bitset>

#ifdef LOCAL
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
clock_t __my_start_clock = clock();
#else
#define eprintf(...)
#endif

#define TIMESTAMP(x) eprintf("["#x"] Time : %.3lf s.\n", (clock() - __my_start_clock)*1.0/CLOCKS_PER_SEC)
#define TIMESTAMPf(x,...) eprintf("[" x "] Time : %.3lf s.\n", __VA_ARGS__, (clock() - __my_start_clock)*1.0/CLOCKS_PER_SEC)

using namespace std;

#ifdef LOCAL
static struct __timestamper {
  string what;
  __timestamper(const char* what) : what(what){};
  __timestamper(const string& what) : what(what){};
  ~__timestamper(){
    TIMESTAMPf("%s", what.data());
	}
} __TIMESTAMPER("end");
#else 
struct __timestamper {};
#endif

typedef long long ll;
typedef long double ld;

bool check(const vector<int>& a, int n) {
  vector<pair<int, int>> p;
  int sum = 0;
  for (int x : a) {
    if (sum >= x) {
      while (sum - p.back().second >= x) {
        sum -= p.back().second;
        p.pop_back();
      }
      assert(!p.empty());
      p.back().second = x - (sum - p.back().second);
      sum = x;
      while (!p.empty() && (p.back().first == n - 1 || p.back().second == 0)) {
        sum -= p.back().second;
        p.pop_back();
      }
      if (p.empty()) {
        return false;
      }
      if (p.back().second == 1) {
        p.back().first++;
      } else {
        p.back().second--;
        p.emplace_back(p.back().first + 1, 1);
      }
    }
    if (x > sum) {
      p.push_back({0, x - sum});
      sum = x;
    }
  }
  return true;
}

int main() {
#ifdef LOCAL
  freopen("c.in", "r", stdin);
  freopen("c.out", "w", stdout);
#endif

  int n;
  while (scanf("%d", &n) == 1) {
    vector<int> a(n);
    for (int& x : a) {
      scanf("%d", &x);
    }

    int l = 0;
    int r = n;
    while (r - l > 1) {
      int m = (l + r) / 2;
      if (check(a, m)) {
        r = m;
      } else {
        l = m;
      }
    }
    printf("%d\n", r);
  }

  return 0;
}


Measured memory_bytes: 4692
/*
 author : nit1n
 created : 08/09/2020 20:30:47
*/
#include<bits/stdc++.h>
#define int long long
using namespace std ;


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

	string s ; 
	cin >> s;
	if(s == "ABC")
		cout << "ARC" ; 
	else
		cout << "ABC" ;
}



Measured memory_bytes: 3656
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<iterator>
#include<cmath>
#include<string>
#include<algorithm>
#include<sstream>
#include<queue>
#include<list>
#include<deque>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<chrono>


/*  auto start = high_resolution_clock::now();
auto stop = high_resolution_clock::now();
auto duration = duration_cast<milliseconds>(stop - start);
pr(duration.count());    */


#define FastIO      ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define pb          push_back
#define siz         100009
#define mp          make_pair
#define ll          long long int
#define fileout     freopen("output.txt","w",stdout)
#define filein      freopen("input.txt","r",stdin)
#define pi          acos(-1.0)
#define all(x)      x.begin(),x.end()
#define ull		    unsigned long long int
#define m(a)	    memset(a,0,sizeof(a))
#define f(i,n)	    for(ll i=0;i<n;i++)
#define sc(a)	    scanf("%lld",&a)
#define pr(a)	    printf("%lld\n",a)
const ll inf = 1e15;
using namespace std;

int main()
{
	FastIO;
	ll a,b,c,d, co, t, i, j, k, n;
	cin >> n>>k;
	f(i, n)
	{
		cin >> b;
	}
	co = 1;
	k--;
	for (i = k+1; i < n; i += k)
	{
		co++;
	}
	cout << co << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

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

const ll MOD=1e9+7;
const ll INF=1e18;

int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};

int main(){
    string s; cin>>s;
    int k; cin>>k;
    int n=s.size();
    for(int i=0; i<n; i++){
        if(s[i]=='a') continue;

        if('z'-s[i]+1<=k){
            k-='z'-s[i]+1;
            s[i]='a';
        }
    }
    
    k%=26;
    char ch=s[n-1];
    while(k--) ch++;
    s[n-1]=ch;
    cout << s << endl;
}

Measured memory_bytes: 512
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest.ABC_175
{
    class A
    {
        static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false };
            SetOut(sw);

            Method(args);

            Out.Flush();
        }

        static void Method(string[] args)
        {
            string s = Read();
            int maxCnt = 0;
            int cnt = 0;
            for (int i = 0; i < 3; i++)
            {
                if (s[i] == 'R')
                {
                    cnt++;
                    maxCnt = Max(maxCnt, cnt);
                }
                else
                {
                    cnt = 0;
                }
            }
            WriteLine(maxCnt);
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 25968
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const long double PI = (acos(-1));
#define rep(i, x, n) for (int i = x; i < (int)(n); i++)
#define sc(x) scanf("%d",&x)
#define scll(x) scanf("%lld",&x)

static const int mod = 1e9+7;
ll fac(int n){
    if (n <= 1) return 1;
    return n * fac(n - 1) % mod;
}

ll facp(int n, int x){
    if (x == 0) return 1;
    return n * facp(n-1, x-1) % mod;
}

ll mpow(ll a, ll n){
    ll res = 1;
    while (n > 0){
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

ll com(int n, int a){
    ll x = facp(n, a);
    ll z = fac(a);
    return x * mpow(z, mod-2) % mod;
}

int main(){
    int n, a, b; sc(n), sc(a), sc(b);
    ll ans = 0;
    ans = mpow(2, n) - 1;
    ans = (ans - com(n, a) + mod) % mod;
    ans = (ans - com(n, b) + mod) % mod;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3328
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}
#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n: i32,
    }

    if n <= 999 {
        println!("ABC");
    } else {
        println!("ABD");
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define debug(x) cerr << #x << ": " << x << endl
#define debugArray(x, n)                           \
  for (long long hoge = 0; (hoge) < (n); ++(hoge)) \
  cerr << #x << "[" << hoge << "]: " << x[hoge] << endl
using namespace std;

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  tuple<long long, long long, char> XYU[N];
  tuple<long long, long long, char> YXU[N];
  tuple<long long, long long, char> XYU_45[N];
  tuple<long long, long long, char> YXU_45[N];
  for (int i = 0; i < N; i++) {
    int x, y;
    char u;
    cin >> x >> y >> u;
    XYU[i] = make_tuple(x, y, u);
    YXU[i] = make_tuple(y, x, u);
    XYU_45[i] = make_tuple(x - y, x + y, u);
    YXU_45[i] = make_tuple(x + y, x - y, u);
  }
  long long ans = INT_MAX;
  sort(XYU, XYU + N);
  sort(YXU, YXU + N);
  sort(XYU_45, XYU_45 + N);
  sort(YXU_45, YXU_45 + N);
  for (int i = 0; i < N; i++) {
    if (get<2>(XYU[i]) != 'U') continue;
    int j = i + 1;
    while (j < N && get<0>(XYU[i]) == get<0>(XYU[j])) {
      if (get<2>(XYU[j]) == 'U') i = j;
      if (get<2>(XYU[j]) == 'D') {
        ans = min(ans, 5 * (get<1>(XYU[j]) - get<1>(XYU[i])));
      }
      j++;
    }
    i = j - 1;
  }

  for (int i = 0; i < N; i++) {
    if (get<2>(YXU[i]) != 'R') continue;
    int j = i + 1;
    while (j < N && get<0>(YXU[i]) == get<0>(YXU[j])) {
      if (get<2>(YXU[j]) == 'R') i = j;
      if (get<2>(YXU[j]) == 'L') {
        ans = min(ans, 5 * (get<1>(YXU[j]) - get<1>(YXU[i])));
      }
      j++;
    }
    i = j - 1;
  }

  for (int i = 0; i < N; i++) {
    if (get<2>(XYU_45[i]) != 'R') continue;
    int j = i + 1;
    while (j < N && get<0>(XYU_45[i]) == get<0>(XYU_45[j])) {
      if (get<2>(XYU_45[j]) == 'R') i = j;
      if (get<2>(XYU_45[j]) == 'D') {
        ans = min(ans, 5 * (get<1>(XYU_45[j]) - get<1>(XYU_45[i])));
      }
      j++;
    }
    i = j - 1;
  }

  for (int i = 0; i < N; i++) {
    if (get<2>(XYU_45[i]) != 'U') continue;
    int j = i + 1;
    while (j < N && get<0>(XYU_45[i]) == get<0>(XYU_45[j])) {
      if (get<2>(XYU_45[j]) == 'U') i = j;
      if (get<2>(XYU_45[j]) == 'L') {
        ans = min(ans, 5 * (get<1>(XYU_45[j]) - get<1>(XYU_45[i])));
      }
      j++;
    }
    i = j - 1;
  }

  for (int i = 0; i < N; i++) {
    if (get<2>(YXU_45[i]) != 'R') continue;
    int j = i + 1;
    while (j < N && get<0>(YXU_45[i]) == get<0>(YXU_45[j])) {
      if (get<2>(YXU_45[j]) == 'R') i = j;
      if (get<2>(YXU_45[j]) == 'U') {
        ans = min(ans, 5 * (get<1>(YXU_45[j]) - get<1>(YXU_45[i])));
      }
      j++;
    }
    i = j - 1;
  }

  for (int i = 0; i < N; i++) {
    if (get<2>(YXU_45[i]) != 'D') continue;
    int j = i + 1;
    while (j < N && get<0>(YXU_45[i]) == get<0>(YXU_45[j])) {
      if (get<2>(YXU_45[j]) == 'D') i = j;
      if (get<2>(YXU_45[j]) == 'L') {
        ans = min(ans, 5 * (get<1>(YXU_45[j]) - get<1>(YXU_45[i])));
      }
      j++;
    }
    i = j - 1;
  }

  if (ans == INT_MAX) {
    cout << "SAFE" << endl;
  } else {
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 22304
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define MAX 5000001
int dx[] = {1,0,-1,0};
int dy[] = {0,-1,0,1};
const ll INF = 10010010010001;

int main(){
  int n;
  cin>>n;
  vector<long long int> c(5);
  for(int i=0;i<5;i++) c[i]=0;
  for(int i=0;i<n;i++){
    string s;
    cin>>s;
    if(s[0]=='M'){
      c[0]++;
    }else if(s[0]=='A'){
      c[1]++;
    }else if(s[0]=='R'){
      c[2]++;
    }else if(s[0]=='C'){
      c[3]++;
    }else if(s[0]=='H'){
      c[4]++;
    }
  }
  
    long long int ans=0;
    for(int i=4;i>=2;i--){
      for(int j=i-1;j>=1;j--){
        for(int k=j-1;k>=0;k--){
          ans+=c[i]*c[j]*c[k];
        }
      }
    }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
using namespace std;
long long a[1000000];
int main(){
	long long n,x=0,s=0;
	cin>>n;
	for(long long i=0;i<n;i++){
		cin>>a[i];
		if(a[i]<=0){
			x++;
		}
	}
	long long  min=1000000000;
	if(x%2==0){
		for(long long i=0;i<n;i++){
			s=s+abs(a[i]);
		}
		cout<<s;
		return 0;
	}
	else for(long long i=0;i<n;i++){
		if(abs(a[i])<min)min=abs(a[i]);
		s=s+abs(a[i]);
	}
	cout<<(s-min-min);
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>

int main() {
	double n, m, tot = 0, cont = 0;
	std::cin >> n >> m;
	std::vector<double> v(n);
	for (int i = 0; i < n; ++i) {
		std::cin >> v[i];
		tot += v[i];
	}

	tot = (tot / (4 * m));
	for (int i = 0; i < n; ++i) {
		if (v[i] < tot) continue;
		++cont;
	}

	if (cont >= m) std::cout << "Yes\n";
	else std::cout << "No\n";

return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector> 
//#include <climits>
using namespace std;


int main() {

    int N;
    cin >> N;

    vector<int> A(N);
    for (int i = 0; i < N; ++i)
    {
        cin >> A[i];
    }


    for (int i = 1; i <= N; ++i)
    {

        for (int i = 0; i < N; ++i)
        {
            cout << A[i];
            if(i != N-1) {
                cout << " ";
            }
        }
        cout << endl;

        int v = A[i];
        int j = i - 1;

        while(j>=0 && A[j] > v) {
            A[j+1] = A[j];
            j--;
        }
        A[j+1] = v;
    }

    return 0;
}


Measured memory_bytes: 3084
import java.util.*;
import java.io.*;

public class Main {
	static PrintWriter out;
	static StringBuilder sb;
	static int mod = 998244353;
	static int inf = (int) 1e15;
	static ArrayList<Integer>[] ad;
	static int n, s;
	static int[][][] memo;
	static int[] a;

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		out = new PrintWriter(System.out);
String s=sc.nextLine();
if(s.charAt(2)==s.charAt(3) && s.charAt(4)==s.charAt(5))
	System.out.println("Yes");
else
	System.out.println("No");
		out.close();
	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}

		public Scanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}

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

		public String nextLine() throws IOException {
			return br.readLine();
		}

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

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

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

		public Long nextLong() throws IOException {
			return Long.parseLong(next());
		}

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

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

		public boolean ready() throws IOException {
			return br.ready();
		}

		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
}


Measured memory_bytes: 22996
N, K = [int(i) for i in input().split()]
import numpy as np
ans = []
for i in range(N):
    score = i + 1
    counter = 0
    while score <= K - 1:
        score = score * 2
        counter += 1
    ans.append((1/N)*((1/2)**counter))
print(np.sum(ans))

Measured memory_bytes: 16336
#include<bits/stdc++.h>
#define int long long
#define INF 1000000009
#define INFL 1000000000000000018
#define mod 1234567
#define pb push_back
#define MAXN 100005
using namespace std;
typedef pair<int, int> PA;
typedef priority_queue<int> PQ;
typedef vector<int> VE;
typedef map<int, int> MAP;


int n, m, a[MAXN], b[MAXN], ans;
MAP mp;

signed main()
{
    cin >> n >> m;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        if(i == 0)b[i] = a[i];
        else{
            b[i] = b[i - 1] + a[i];
        }
    }
    for(int i = 0; i < n; i++){
        mp[b[i] % m]++;
    }
    MAP :: iterator ite;
    for(ite = mp.begin(); ite != mp.end(); ite++){
        ans += ite->second * (ite->second - 1) / 2;
        if(ite->first == 0){
            ans += ite->second;
        }
    }
    cout << ans << endl;


    return 0;
}




Measured memory_bytes: 5760
def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

import itertools

X, Y = two_int()

def comb(n,r,mod, N):
    def cmb(n, r, mod):
        if ( r<0 or r>n ):
            return 0
        r = min(r, n-r)
        return g1[n] * g2[r] * g2[n-r] % mod

    mod = 10**9+7 #出力の制限
    g1 = [1, 1] # 元テーブル
    g2 = [1, 1] #逆元テーブル
    inverse = [0, 1] #逆元テーブル計算用テーブル

    for i in range( 2, N + 1 ):
        g1.append( ( g1[-1] * i ) % mod )
        inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
        g2.append( (g2[-1] * inverse[-1]) % mod )

    return cmb(n,r,mod)

def calc(a, b, p):
    if b==0:
        return 1
    elif b%2==0:
        d=calc(a,b//2, p)
        return (d*d)%p
    else:
        return (a*calc(a,b-1,p))%p

dan = (X+Y)/3
if dan.is_integer():
    n = int(dan+1)
    k = Y-(n-1)+1
    print(int(comb(n-1,k-1,(10**9+7),X)))
else:
    print(0)

Measured memory_bytes: 127432
// The very basic /////////////////////////////////////////////////////////////
#include <bits/stdc++.h>
using namespace std;
#define ALL_H 1

// Debug it by D(x) ///////////////////////////////////////////////////////////
#define DEBUG 1
#if DEBUG
#define D(x) x
#else
#define D(x)
#endif

// Print elements of containers using << operator /////////////////////////////
// pair
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {
  return s << "(" << p.first << ", " << p.second << ")";}
// vector
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
  for (auto &elem : v) {
    s << elem;
    if (&elem != &v.back()) s << " ";
  }
  return s;
}
// 2 dimentional vector
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
  for (auto &elem : vv) {
    s << elem;
    if (&elem != &vv.back()) s << endl;
  }
  return s;
}
// map
template<typename T1, typename T2> ostream& operator<<(ostream& s, const map<T1, T2>& m) {
  s << "{" << endl;
  for (auto &elem: m) {
    s << " " << elem.first << " : " << elem.second << endl;
  }
  s << "}";
  return s;
}
//set
template<typename T> ostream& operator<<(ostream& s, const set<T>& m) {
  s << "{ ";
  for (auto &elem: m) {
    s << elem << " ";
  }
  s << "}";
  return s;
}

// Convenient macros //////////////////////////////////////////////////////////

// types
#define ll long long
#define ld long double
#define int ll
#define Pi pair<int, int>
#define Graph vector<vector<int>>
#define WeightGraph vector<vector<Pi>>

// other
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))

// update max or min //////////////////////////////////////////////////////////

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

// gcd
int gcd(int a,int b){return b?gcd(b,a%b):a;}

// for grids
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

///////////////////////////////////////////////////////////////////////////////
//                             Start Coding Here                             //
///////////////////////////////////////////////////////////////////////////////

signed main() {
  char a; cin >> a;
  cout << ++a << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
// memo  fixed  setprecision(20);
using vvll = vector<vector<ll>>;
ll mod =1e9+7;
/*"itob" int to "N"base */           template<typename TypeInt> string itob(const TypeInt v, int base){static const char table[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";string ret;static numeric_limits<TypeInt> t;TypeInt n = v;if (t.is_signed) {if (v < 0) n *= -1;}while (n >= base) {ret += table[n%base];n /= base;}ret += table[n];if (t.is_signed) {if (v < 0 && base == 10) ret += '-';}reverse(ret.begin(), ret.end());return ret;}
/*"chmin" a = MAX*/                  template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
/*"chmax" a = MIN*/                  template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
/*"ctoi"  char to int*/              int ctoi(char c) {return c-'0';}
/*"gcd"   MAX Euclidean */           ll gcd(ll a,ll b){if(b==0)return a; return gcd(b,a%b);}
    /*"lcm"   MIN*/                      ll lcm(ll a,ll b){ll g = gcd(a,b);return a/g*b;}
/*"primecheck"If prime,return true.*/bool primecheck(ll n){if(n < 2) return false;else{for(int i = 2; i * i <= n; i++){if(n % i == 0) return false;}return true;}}
string  reverserange(string s,ll a,ll b){reverse(s.begin()+a-1,s.begin()+b); return s;}
ll modpow(ll a,ll n, ll mod){ll res = 1;while(n>0){if (n%2==1){res = res * a % mod;}a = a * a % mod;n/=2;}return res;}
int main() {
    int n;
    cin >> n;
    vector<ll>a(4,0);
    for(int i=0;i<n;i++){
        string t;
        cin >>t;
        if(t=="AC")a.at(0)++;
        else if(t=="WA")a.at(1)++;
        else if(t=="TLE")a.at(2)++;
        else a.at(3)++;
    }
    cout<<"AC x "<<a.at(0)<<endl;
    cout<<"WA x "<<a.at(1)<<endl;
    cout<<"TLE x "<<a.at(2)<<endl;
    cout<<"RE x "<<a.at(3)<<endl;
}
    



Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
int main(){
  string a;
  cin>>a;
  int l=a.length();
  sort(a.begin(),a.end());
  a.erase(unique(a.begin(),a.end()),a.end());
  cout<<(a.length()==l?"yes":"no");
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int fun(int x){
    int r;
    if (x%2==0) {
        r=x/2;
    }else{
        r=3*x+1;
    }
    return r;
}

int main(){
    int s;
    cin >> s;
    vector<int> a;
    a.push_back(s);
    int flag=0;
    int k=0;
    while (flag==0) {
        int x=fun(a[k]);
        for (int i=0; i<a.size(); i++) {
            if (a[i]==x) {
                flag=1;
                break;
            }
        }
        a.push_back(x);
        k++;
    }
    cout<<a.size()<<endl;
    return 0;
}


Measured memory_bytes: 256
def main():
    
    import sys
    input = sys.stdin.readline
    
    N,A,B = map(int,input().split())
    H = []
    for i in range(N):
        h = int(input())
        H.append(h)
    H = sorted(H)[::-1]
    L = 0
    R = 10**9
    while 1:
        C = (L+R)//2
        tmp = 0
        for i in range(N):
            h = H[i]
            if h <= C*B:
                break
            else:
                tmp += int(-(-(h-C*B)//(A-B)))
        if tmp <= C:
            if C-1==L:
                ans = C
                break
            else:
                R = C
        else:
            if C+1==R:
                ans = R
                break
            else:
                L = C
    print(ans)
            
        
        
    
    
main()

Measured memory_bytes: 46300
# python3 (3.4.3)
import sys
input = sys.stdin.readline

# main
N,A,B = map(int,input().split())
X = list(map(int,input().split()))

ans = 0
for i in range(N-1):
    ans += min(B, A*(X[i+1]-X[i]))

print(ans)

Measured memory_bytes: 14172
#include <iomanip>
#include <iostream>
#include <algorithm>
using namespace std;
int n, x, t;
int main() {
	scanf("%d", &n);
	for(int i = 0; i < n; i++) {
		scanf("%x", &x);
		t = x >= 0 ? 1 : -1;
		x = x >= 0 ? x : x - 2147483648;
		cout << setprecision(20) << x / 128.0 * t << (x % 128 == 0 ? ".0" : "") << endl;
	}
}

Measured memory_bytes: 3320
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define INF 0x6fffffff
#define INFL 0x6fffffffffffffffLL

int main() {
	ll		a,b,c,i,j,k,n,m,x,y,ans = 0;
	string	s;

	cin >> n >> m;
	vector<int> l(m),r(m);

	for(i=0;i<m;i++) {
		cin >> l[i] >> r[i];
	}

	sort(l.begin(), l.end());
	sort(r.begin(), r.end());

	ans = max(0 , r[0]-l[m-1]+1);

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


Measured memory_bytes: 1024
def split(n): 
    return [char for char in n]
n=input()
n=split(n)
for i in range(len(n)):
        n[i] = int(n[i])
x=n[len(n)-1]
if x in range(4,6) or ((x==7 or  x==9) or x==2):
    print("hon")
elif x in range(2) or (x==6 or x==8):
    print("pon")
elif x==3:
    print("bon")

Measured memory_bytes: 61924
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
#include <queue>
using namespace std;
typedef long long int ll;
typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
typedef pair<ll,ll> pairs;
vector<pairs> p;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
bool pairCompareSecond(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.second < secondElof.second;
}
#define MAX_N 100100
#define MOD 1000000007
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
// 四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}
 
ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

int main(){
    ll h,w;
    cin >> h >> w;
    string s[h];
    for (ll i=0;i<h;i++){
        cin >> s[i];
    }
    bool flag=true;
    for (ll i=0;i<h;i++){
        for (ll j=0;j<w;j++){
            if (s[i][j]=='#'){
                bool f=false;
                for (ll k=0;k<4;k++){
                    ll x=i+dx[k];
                    ll y=j+dy[k];
                    if (x>=0 and x<h and y>=0 and y<w and s[x][y]=='#'){
                        f=true;
                    }
                }
                if (!f){
                    flag=false;
                }
            }
        }
    }
    if (flag){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define fr first
#define sc second
#define ii pair<int,int>
#define mp make_pair
#define All(v) v.begin(),v.end()
using namespace std;
int main()
{
    ll x,y;
    cin>>x>>y;
    ll t = x;
    if((x%y) == 0)
    {
        cout<<-1;
    }
    else
    {

        cout<<x;
    }
}


Measured memory_bytes: 256
# AOJ 0228: Seven Segments
# Python3 2018.6.25 bal4u
 
p = [[1,1,1,1,1,1,0], [0,1,1,0,0,0,0], [1,1,0,1,1,0,1], [1,1,1,1,0,0,1], [0,1,1,0,0,1,1], \
     [1,0,1,1,0,1,1], [1,0,1,1,1,1,1], [1,1,1,0,0,1,0], [1,1,1,1,1,1,1], [1,1,1,1,0,1,1]]
 
while True:
    n = int(input())
    if n < 0: break
    a = [0]*7
    for i in range(n):
        d = int(input())
        ans = ''
        for j in range(6,-1,-1):
            k = (a[j] ^ p[d][j]) & 1
            ans += '1' if k else '0'
            if k: a[j] = 1-a[j]
        print(ans)


Measured memory_bytes: 5600
#include <bits/stdc++.h>
    #define int long long
    #define gcd            __gcd
    #define setbits(x)     __builtin_popcountll(x)
    #define zrobits(x)     __builtin_ctzll(x)
    #define mod            1000000007
    #define mod2           998244353
    #define maxe           *max_element
    #define mine           *min_element
    #define inf            1e18
    #define deci(x,y)      fixed<<setprecision(y)<<x
    #define w(t)           int t; cin>>t; while(t--)
    #define nitin          ios_base::sync_with_stdio(false); cin.tie(NULL)
    #define PI             3.141592653589793238
    using namespace std;

    int power(int x, int y, int p)
    {
        int res = 1;
        x = x % p;
        while (y > 0)
        {
            if (y & 1)
                res = (res * x) % p;
            y = y >> 1;
            x = (x * x) % p;
        }
        return res;
    }
    int modi(int a, int m)
    {
        return power(a, m - 2, m);
    }
    int32_t main()
    {
        nitin;
        int n;
        cin>>n;
        vector<int>v(n);
        int sum=0;
        for(int i=0;i<n;i++){
            cin>>v[i];
            sum+=v[i];
        }
        int total=(n*(n+1))/2;
        if(sum%total!=0){
            cout<<"NO"<<endl;
        }
        else{
            int k=sum/total;
            bool flag=true;
            for(int i=1;i<n;i++) {
                if ((k - (v[i] - v[i - 1])) < 0 || (k - (v[i] - v[i - 1])) % n != 0)
                    flag = false;
            }
                if((k-(v[0]-v[n-1]))<0 || ((k-(v[0]-v[n-1])))%n!=0)
                    flag=false;
            if(flag)
            {
                cout<<"YES"<<endl;
            }
            else{
                cout<<"NO"<<endl;
            }
        }
        return 0;
    }

Measured memory_bytes: 3976
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true) {
			int w = sc.nextInt();
			int h = sc.nextInt();
			if(w==0 && h==0) break;
			int[][] s_wall = new int [h][w+1];
			int[][] u_wall = new int [h+1][w];
			for(int i=0;i<h;++i) {
				s_wall[i][0]=1;
				for(int j=1;j<w;++j){
					s_wall[i][j] = sc.nextInt();
				}
				s_wall[i][w] = 1;
				if(i==h-1) {
					for(int j=0;j<w;++j) {
						u_wall[0][j] = 1;
						u_wall[i+1][j] = 1;
					}
				} else {
					for(int j=0;j<w;++j) {
						u_wall[i+1][j] = sc.nextInt();
					}
				}
			}
			int[][] map = new int[h][w];
			Queue<Node> que = new LinkedList<Node>();
			map[0][0]=1;
			que.add(new Node(0,0));
			while(!que.isEmpty()) {
				Node cur = que.remove();
				if(cur.y!=0 && u_wall[cur.y][cur.x]==0) {
					if(map[cur.y-1][cur.x]==0) {
						que.add(new Node(cur.x,cur.y-1));
						map[cur.y-1][cur.x]=map[cur.y][cur.x]+1;
					}
				}
				if(cur.y!=h-1 && u_wall[cur.y+1][cur.x]==0) {
					if(map[cur.y+1][cur.x]==0) {
						que.add(new Node(cur.x,cur.y+1));
						map[cur.y+1][cur.x]=map[cur.y][cur.x]+1;
					}
				}
				if(cur.x!=0 && s_wall[cur.y][cur.x]==0) {
					if(map[cur.y][cur.x-1]==0) {
						que.add(new Node(cur.x-1,cur.y));
						map[cur.y][cur.x-1]=map[cur.y][cur.x]+1;
					}
				}
				if(cur.x!=w-1 && s_wall[cur.y][cur.x+1]==0) {
					if(map[cur.y][cur.x+1]==0) {
						que.add(new Node(cur.x+1,cur.y));
						map[cur.y][cur.x+1]=map[cur.y][cur.x]+1;
					}
				}
			}
			System.out.println(map[h-1][w-1]);
		}
	}
	public static class Node {
		int x;
		int y;
		Node(int x, int y){
			this.x = x;
			this.y = y;
		}
	}
}



Measured memory_bytes: 70140
import sys
 
RI = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
INF = 10 ** 18
MOD = 10 ** 9 + 7
 
# for i in range(int(ri())):
x,y,z = RI()
print(z,x,y)

Measured memory_bytes: 3064
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef pair<int,int> P;
typedef tuple<ll,int,int> T;
#define fi first
#define se second
#define all(v) (v).begin(),v.end()
set<string> c;
const ll mod=1000000007;
const ll mod2=998244353;
const ll inf=100000000000000000;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
vector<int> dy={-1,0,1,0},dx={0,-1,0,1};
int main(){
    int n;
    cin>>n;
    vector<int> a(n);
    for(int i=0;i<n;i++)cin>>a[i];
    vector<int>  q(n);
    for(int i=0;i<n;i++)q[a[i]-1]=i;
    int cnt=1;
    int ans=1;
    for(int i=0;i<n-1;i++){//
             if(q[i]<q[i+1])cnt++;
             else cnt=1;
             ans=max(cnt,ans);//移動しなくても良いものの最大値を求める
    }
    cout<<n-ans<<endl;
}


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

using namespace std;

struct Initializer {
  Initializer() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(15);
  }
} initializer;

template<typename T> bool chmin(T& a, T b) {return a > b ? a = b, true : false;}

template<typename T> bool chmax(T& a, T b) {return a < b ? a = b, true : false;}

int main() {
  int n;
  string s;
  cin >> n >> s;
  if (n < 3) {
    cout << 0 << endl;
    return 0;
  }
  vector<vector<int>> edges(n + 1);
  for (int i = 1; i < n - 1; ++i) {
    if (s[i] == '1') continue;
    if (s[i - 1] == '1') {
      for (int j = i + 1; j < n; ++j) {
        if (s[j] == '0') break;
        edges[j + 1].emplace_back(i - 1);
      }
    }
    if (s[i + 1] == '1') {
      for (int j = i - 1; j >= 0; --j) {
        if (s[j] == '0') break;
        edges[i + 2].emplace_back(j);
      }
    }
  }
  vector<int> dp(n + 1, numeric_limits<int>::max());
  dp[0] = 0;
  for (int i = 1; i <= n; ++i) {
    dp[i] = dp[i - 1] + (s[i - 1] == '1');
    for (int j : edges[i]) chmin(dp[i], dp[j] + 1);
  }
  cout << count(s.begin(), s.end(), '1') - dp.back() << endl;
}



Measured memory_bytes: 32668
// -_-
#include <bits/stdc++.h>
#define int long long
#define read(a) int a; cin >> a;
#define readarr(a, n) int a[(n) + 1] = {}; fori(i, 1, (n)) {cin >> a[i];}
#define readmat(a, n, m) int a[n + 1][m + 1] = {}; fori(i, 1, n) {fori(j, 1, m) cin >> a[i][j];}
#define pb push_back
#define fi first
#define se second
#define rz resize
#define fori(i, a, b) for(int i = a; i <= b; i++)
#define ford(i, a, b) for(int i = a; i >= b; i--)
#define mod 1000000007
#define  sort1(v) sort(v.begin(), v.end()) 
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pair <int, int>> vpi;

vector < vector <int> > adj;
int dp[100001][2] = {};
int w = 0, b = 1;

void dfs(int cur, int prev)
{
	dp[cur][w] = 1; dp[cur][b] = 1;
	for(int i : adj[cur])
	{
		if(i != prev)
		{
			dfs(i, cur);
			dp[cur][w] = ( dp[cur][w]*( (dp[i][w] + dp[i][b])%mod) )%mod;
			dp[cur][b] = ( dp[cur][b]*(dp[i][w]%mod) )%mod; 
		}
	}
}
 
signed main() 
{

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

	read(n);
	adj.rz(n+1);
	int x, y;

	fori(i, 1, n-1)
	{
		cin >> x >> y;
		adj[x].pb(y);
		adj[y].pb(x);
	}

	dfs(1, 0);
	if(n == 1) cout << 2;
	else
	cout << (dp[1][w]+ dp[1][b])%mod;;

	return 0;
}

Measured memory_bytes: 14208
n,k,s = map(int,input().split())
if k == 0:
	if s != 10**9:
		print(" ".join([str(10**9) for _ in range(n)]))
	else:
		print(" ".join([str(1) for _ in range(n)]))
elif s != 10**9:
	ans = [10**9 for _ in range(n)]
	for i in range(k):
		ans[i] = s
	print(" ".join([str(ans[i]) for i in range(n)]))
else:
	ans = [1 for _ in range(n)]
	for i in range(k):
		ans[i] = s
	print(" ".join([str(ans[i]) for i in range(n)]))

Measured memory_bytes: 12056
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;

const int INF = 1<<29;
using Edge = P;
using Graph = vector<vector<Edge>>;

Graph G;
set<P> use;

vector<ll> Dijkstra(int s){
    vector<ll> dist((int)G.size(), INF);
    vector<vector<int>> prev((int)G.size());
    dist[s] = 0;
    priority_queue<P, vector<P>, greater<P>> que;
    que.push({0,s});
    while(!que.empty()){
        auto cur = que.top(); que.pop();
        int cur_dist = cur.first;
        int v = cur.second;
        //if(cur_dist > dist[v]) continue;
        for(auto e : G[v]){
            if(dist[e.first] > dist[v] + e.second){
                dist[e.first] = dist[v] + e.second;
                que.push({dist[e.first], e.first});
                prev[e.first].clear();
                prev[e.first].push_back(v);
            }else if(dist[e.first] == dist[v] + e.second){
                prev[e.first].push_back(v);
            }
        }
    }
    for(int v = 0; v < (int)G.size(); ++v){
        for(auto u : prev[v]){
            use.insert(make_pair(min(u, v), max(u, v)));
        }
    }
    return dist;
}


int main(){
    int n, m; cin >> n >> m;
    G.resize(n);
    rep(i,m){
        int a, b, c; cin >> a >> b >> c;
        --a, --b;
        G[a].push_back(P(b,c));
        G[b].push_back(P(a,c));
    }
    for(int v = 0; v < n; v++) Dijkstra(v);
    cout << m - (int)use.size() << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <list>
#include <set>
#include <numeric>

#include <map>
#include <math.h>
#include <iomanip>
#include <stack>
#include <queue>
#include <bitset>
#include <math.h>

#define INF 100100100

typedef long long int llint;

using namespace std;

typedef pair<int, int>Pii;

#define pi 3.141592653589793

int main() {
	int n, k;
	cin >> n >> k;
	llint sum = k;
	for (int i = 1; i < n; i++) {
		sum *= k - 1;
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 256
//Abhinav ---IIIT_A
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define pb push_back
#define ff first
#define ss second
#define f(i,x,n) for(int i=x;i<(int)n;++i)
#define vpii vector<pair<int,int>>
#define vi vector<int>
#define mpii map<pair<int,int>,int>
#define mpivpii map<int,vector<pair<int,int>>>
#define pii pair<int,int>
#define all(x) x.begin(),x.end()
#define sz(x) x.size()
#define mpi map<int,int>
#define vvi vector<vector<int>>
#define vvvi vector<vvi>
ld pie=3.141592653589;
int mod=1e9+7;


void solve(){
	int n; cin>>n;
	int a[n],b[n],c[n];
	f(i,0,n) cin>>a[i]>>b[i]>>c[i];
	f(i,1,n) {
		a[i]+=max(b[i-1],c[i-1]);
		b[i]+=max(a[i-1],c[i-1]);
		c[i]+=max(b[i-1],a[i-1]);
	}
	int ans=max(a[n-1],b[n-1]);
	ans=max(ans,c[n-1]);
	cout<<ans;
}

signed main(){
  ios_base::sync_with_stdio(false);cin.tie(NULL);
  int t=1; //cin>>t;
  while(t--) solve();
  return 0;
}
// check for overflows dummy !!!


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

int main(){
	int a,b;
  cin>>a>>b;
  int ans=0;
  if(a>b){
  	ans=2*a-1;
  }else if(a==b){
  	ans=a*2;
  }else{
  	ans=2*b-1;
  }
  cout<<ans;
}

Measured memory_bytes: 256
/**
 *    authur: Bao Trung
**/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(), (x).end()
#define set_vect(a,n); vector<int>a(n); for(auto &z : a)cin>>z;


void solve(){
    string s;
    cin >> s;
    if(s == "ABC") cout << "ARC";
    else cout << "ABC";
}

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    
    int t = 1; //cin >> t;
    while(t--){solve();}
    return 0;
}

// Code By CodeWar :3

Measured memory_bytes: 3648
#include<iostream>
#include<cassert>
#include<stdexcept>
#include<utility>
#include<functional>
#include<numeric>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<array>
#include<stack>
#include<queue>
#include<deque>
#include<vector>
#include<complex>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<string>
#include<bitset>
#include<memory>
#include<vector>
#include<numeric>

namespace ProconLib{
    class UnionFind{
        int N;
        std::vector<int> par;
        std::vector<int> rank;
        public:
        UnionFind(int N):N(N),par(N),rank(N,0){std::iota(par.begin(),par.end(),0);}
        int find(int x);
        void unite(int x,int y);
        bool same(int x,int y){return find(x)==find(y);}
    };

    int UnionFind::find(int x){
        if(par[x]==x) return x;
        return par[x]=find(par[x]);
    }
    void UnionFind::unite(int x,int y){
        x=find(x),y=find(y);
        if(x==y) return;
        if(rank[x]>=rank[y]){
            if(rank[x]==rank[y]) rank[x]++;
            par[y]=x;
        }else{
            par[x]=y;
        }
    }
}using namespace std;
using namespace ProconLib;
using ll=long long;

struct Card{
    int r,c;
    ll a;
    int id;
};

struct Edge{
    int to;
    ll w;
};
using Graph=vector<vector<Edge>>;
Graph g;
vector<int> used;
void dfs(int v){
    if(used[v]) return;
    used[v]=true;
    for(auto to:g[v]){
        if(!used[to.to]) dfs(to.to);
    }
}
int main(){
    int n,h,w;
    cin>>n>>h>>w;
    vector<Card> cards(n);
    for(int i=0;i<n;i++){
        cin>>cards[i].r>>cards[i].c>>cards[i].a;
        cards[i].r--;
        cards[i].c--;
        cards[i].id=i;
    }
    sort(cards.begin(),cards.end(),[](Card lhs,Card rhs){return lhs.a>rhs.a;});
    vector<int> flag(n);

    g.resize(h+w);
    used.resize(h+w);
    UnionFind u(h+w);
    
    ll res=0;
    for(auto &card:cards){
        int x=card.r;
        int y=card.c+h;
        if(u.same(x,y)){
            if(used[x]+used[y]==0){
                res+=card.a;
                g[x].push_back(Edge{y,card.a});
                g[y].push_back(Edge{x,card.a});
                dfs(x);
                dfs(y);
            }
            else{
                assert(used[x]==used[y]);
                continue;
            }
        }
        if(used[x] && used[y]){
            continue;
        }
        else if(used[x]||used[y]){
            g[x].push_back(Edge{y,card.a});
            g[y].push_back(Edge{x,card.a});
            dfs(x);
            dfs(y);
            u.unite(x,y);
            res+=card.a;
        }
        else{
            u.unite(x,y);
            g[x].push_back(Edge{y,card.a});
            g[y].push_back(Edge{x,card.a});
            res+=card.a;
        }
    }
    cout<<res<<endl;
    
    return 0;
}


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



class Solution {
  int n;
public:
  void run() {
    cin >> n;
    vector<pair<int, int>> Es;
    for (int i = 1; i <= n; ++i) {
      for (int j = 1; j < i; ++j) {
        if (i + j != (n % 2 ? n : n + 1)) Es.emplace_back(i, j);
      }
    }
    cout << Es.size() << '\n';
    for (pair<int, int> e : Es) cout << e.first << ' ' << e.second << '\n';
  }
};


int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
  Solution().run();
}


Measured memory_bytes: 384
// organize and work - Abhinav IIITA
#include <bits/stdc++.h>
using namespace std;
#define int long long
void q1(){
	int n;	cin>>n;
	cout<<n*n*n;			
}
void q2(){
	int n;	cin>>n;	int ans=0;
	int idx[n],cost[n],Cost[n-1];
	for(int i=0;i<n;++i){
		cin>>idx[i];	idx[i]--;
	}for(int i=0;i<n;++i)
	{	cin>>cost[i];	ans+=cost[i]; }
	for(int i=0;i<n-1;++i)
	cin>>Cost[i];
	for(int i=1;i<n;++i){
		if(idx[i]-idx[i-1]==1)
		ans+=Cost[idx[i-1]];
	}
	cout<<ans;
}
int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t;//cin>>t;
	t=1;
	while(t--)//
	q2();
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
typedef long long ll;

int factorial(int n) {
    int f = 1;
    REP(i, 1, n + 1)
    f *= i;
    return f;
}

int order(vector<int> A) {
    vector<int> used(A.size(), 0);

    int ans = 1;
    REP(i, 0, A.size()) {
        int j = 0, idx = 0;
        while (A[i] - 1 != j) {
            if (used[j] != 1) idx++;
            j++;
        }

        if (idx > 0) {
            ans += factorial(A.size() - 1 - i) * idx;
        }

        used[A[i] - 1] = 1;
    }

    return ans;
}

int main() {
    int N; cin >> N;
    vector<int> P(N), Q(N);
    REP(i, 0, N) cin >> P[i];
    REP(i, 0, N) cin >> Q[i];

    cout << abs(order(P) - order(Q)) << endl;
    return 0;
}

Measured memory_bytes: 256
/**
 🍪 the_hyp0cr1t3
 🍪 29.08.2020 11:18:21
**/
#ifdef W
#include "k_II.h"
#else
#include <bits/stdc++.h>
using namespace std;
#define aylmao cin.tie(nullptr)->sync_with_stdio(false);
#endif
#define endl '\n'
#define pb emplace_back
// #define int long long
#define sz(x) (int)((x).size())
#define all(x) x.begin(), x.end()
#define Luv(...) [&](auto&& u, auto&& v) { return __VA_ARGS__; }
auto chmax = [](auto& A, auto&& B) { return B > A? A = B, true : false; };
auto chmin = [](auto& A, auto&& B) { return B < A? A = B, true : false; };

using ll = long long;
using pii = pair<int, int>;
const ll DESPACITO = 2e18;
const int INF = 2e9, MOD = 1e9+7;

const int N = 2e5+5;

int32_t main() {
    aylmao
    int i, n, m;
    cin >> n >> m;
    vector<vector<int>> g(n);
    vector<int> dp(n, 0), indeg(n);   
    for(i = 0; i < m; i++) {
        int u, v; cin >> u >> v;
        --u; indeg[--v]++;
        g[u].pb(v);
    }
    queue<int> q;
    for(i = 0; i < n; i++) 
        if(!indeg[i]) q.push(i);

    while(!q.empty()) {
        auto v = q.front(); q.pop();
        for(auto& x: g[v]) {
            chmax(dp[x], dp[v] + 1);
            if(!--indeg[x]) q.push(x);
        }
    }
    cout << *max_element(all(dp));
    return 0;
}

Measured memory_bytes: 9456