akhauriyash/Code-Regression huggingface dataset:
gets.to_i
P = gets.chomp.split(" ").map(&:to_i)

tmp = P.map.with_index{|x, i| [x, i+1]}.select{|a, b| a == b}
ans = 0
while tmp.size > 1 do
  if (tmp[1][0] - tmp[0][0]) == 1 then
    tmp.shift
  end
  tmp.shift
  ans += 1
end
ans += 1 if tmp.size == 1

puts ans


Measured memory_bytes: 16524
#include<stdio.h>
int main(void){
  int s,h=0,m=0;
  scanf("%d",&s);
  if(60<=s){
    m=s/60;
    s=s-(m*60);
  
  }
  if(60<=m){
    h=m/60;
    m=m-(h*60);
  }
  printf("%d:%d:%d\n",h,m,s);
  return 0;
}

Measured memory_bytes: 592
import heapq

N, K = map(int, input().split())
H = list(map(int, input().split()))

H = list(map(lambda x:x*(-1), H))
heapq.heapify(H)

if N > K:
    for _ in range(K):
        heapq.heappop(H)

    ans = sum(H) * (-1)
else:
    ans = 0

print(ans)


Measured memory_bytes: 25896
#include <bits/stdc++.h>
using namespace std;
const int pos_x[] = {0, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 4};
const int pos_y[] = {2, 1, 2, 3, 0, 1, 2, 3, 4, 1, 2, 3, 2};
const int table[][5] = {
	{2, -1},
	{2, 5, -1},
	{0, 1, 3, 6, -1},
	{2, 7, -1},
	{5, -1},
	{1, 4, 6, 9, -1},
	{2, 5, 7, 10, -1},
	{3, 6, 8, 11, -1},
	{7, -1},
	{5, 10, -1},
	{6, 9, 11, 12, -1},
	{7, 10, -1},
	{10, -1},
};

struct Puzzle {
	vector<int> val;
	Puzzle(): val(13){}
	int score(){
		int res = 0;
		for (int i = 0; i < 13; i++){
			if (!val[i]) continue;
			int v = val[i];
			res += abs(pos_x[v] - pos_x[i]);
			res += abs(pos_y[v] - pos_y[i]);
		}
		return res;
	}
	void show(){
		for (int i = 0; i < 13; i++){
			printf("%d ", val[i]);
			if (i == 0 || i == 3 || i == 8 || i == 11 || i == 12){
				puts("");
			}
		}
	}
};

/*inline bool check(Puzzle &p)
{
	for (int i = 1; i <= 11; i++){
		if (p.val[i] != i) return false;
	}
	return true;
}*/

bool search(int d, Puzzle &p)
{
	if (p.score() == 0) return true;
	if (d == 0) return false;
	
	for (int i = 0; i < 13; i++){
		if (p.val[i]) continue;
		for (const int *to = &table[i][0]; ~(*to); to++){
			swap(p.val[i], p.val[*to]);
			//printf("%d %d\n", i, *to);
			//printf("%d\n", p.score());
			if (d - 1 - p.score() >= 0){
				if (search(d - 1, p)) return true;
			}
			swap(p.val[i], p.val[*to]);
		}
	}
	return false;
}

void solve(Puzzle &p)
{
	for (int d = 0; d <= 20; d++){
		if (search(d, p)){
			printf("%d\n", d);
			return;
		}
	}
	puts("NA");
}

int main()
{	
	Puzzle p;
	while (true){
		for (int i = 0; i < 13; i++){
			scanf("%d", &p.val[i]);
			if (p.val[i] == -1) return 0;
		}
		solve(p);
	}
}

Measured memory_bytes: 1196
// ITP1_10_D Distance2
import java.io.*;

public class Main {
   public static void main(String[] args) {
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

      try{
         int n = Integer.parseInt(br.readLine());
         int[] x = new int[n];
         int[] y = new int[n];
         String strx[] = br.readLine().split(" ");
         for (int i = 0; i < n ;i++)
            x[i] = Integer.parseInt(strx[i]);

         String stry[] = br.readLine().split(" ");
         for (int i = 0; i < n; i++)
            y[i] = Integer.parseInt(stry[i]);

         Minkowski(n, x, y);
      }

      catch (Exception e) {
         e.printStackTrace();
      }
   }

   private static void Minkowski(int n, int[] x, int[] y) {
      double D1 = 0;
      double D2 = 0;
      double D3 = 0;
      double Dmax = 0;

      for (int i = 0; i < n; i++) {
         D1 += Math.abs(x[i] - y[i]);
         D2 += Math.pow(Math.abs(x[i] - y[i]), 2);
         D3 += Math.pow(Math.abs(x[i] - y[i]), 3);
         if (Dmax < Math.abs(x[i] - y[i]))
            Dmax = Math.abs(x[i] - y[i]);
      }

      System.out.println(D1);
      System.out.println(Math.sqrt(D2));
      System.out.println(Math.cbrt(D3));
      System.out.println(Dmax);
   }
}

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

int x[100000];
int r[18][100000];
int main() {
	int n; scanf("%d", &n);
	rep(i, n)scanf("%d", &x[i]);
	int l, q; scanf("%d%d", &l, &q);
	rep(i, n)r[0][i] = upper_bound(x, x + n, x[i] + l) - x - 1;
	for (int i = 1; i < 18; i++) {
		rep(j, n)r[i][j] = r[i - 1][r[i - 1][j]];
	}
	rep(i, q) {
		int a, b; scanf("%d%d", &a, &b); a--; b--;
		if (a > b)swap(a, b);
		int lb = 0, rb = INF;
		while (lb != rb) {
			int t = (lb + rb) / 2;
			int e = a, f = b;
			for (int i = 17; i >= 0; i--) {
				if (t >> i & 1)e = r[i][e];
			}
			if (e >= f)rb = t;
			else lb = t + 1;
		}
		printf("%d\n", lb);
	}
}

Measured memory_bytes: 8192
#include <bits/stdc++.h>
#define MOD 1000000009
#define inf 1e9
#define endl '\n'
#define zeros(x) ((x)&(-x))

using namespace std;

typedef long long ll;
typedef long double ld;

int main()
{
    //freopen("input.txt", "r", stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    ll r;
    cin>>r;
    cout<<r*r;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
using namespace std;
typedef long long ll;

const int maxN = 1e5 + 5;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;

ll gcd(ll a, ll b){return !b ? a : gcd(b, a % b);}
ll modP(ll a, ll b) {return (!b ? 1 : (modP(a, b / 2) * modP(a, b / 2) * (b % 2 ? a : 1)) % MOD);}

int n, m, i, dp[maxN], X;
int in[maxN], out[maxN], u, v;
vector <int> G[maxN], sink;

int DP(int v){
	if (dp[v] == -1){
		int mx = 0;
		for (int u : G[v]){
			mx = max(mx, DP(u));
		}
		dp[v] = mx + 1;
	}
	return dp[v];
}

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> m;
	for (i = 0; i < m; i++){
		cin >> u >> v;
		out[u] += 1;
		in[v] += 1;
		G[v].push_back(u);
	}
	memset(dp, -1, sizeof dp);
	for (i = 1; i <= n; i++){
		if (in[i] == 0){
			dp[i] = 0;
		}
		if (out[i] == 1){
			sink.push_back(i);
		}
	}
	X = 0;
	for (int u : sink){
		X = max(X, DP(u));
	}
	cout << X + 1 << endl;
	return 0;
}



Measured memory_bytes: 11896
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define REP(i,a,b) for(int i=int(a);i<(int)b;++i)
#define Graph vector<vecctor<ll>>
#define pairs vector<pair<ll,ll>>
#define pb push_back



using namespace std;
using ll = long long;
const ll INF = 1e18;
const double PI = acos(-1);

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

const ll mod = 1e9 + 7;

ll modpow(ll a, ll b){
    if(b == 0)return 1;
    if(b%2 == 0){
        ll k = modpow(a,b/2);
        return k*k%mod;
    }else{
        return modpow(a,b-1)*a%mod;
    }
}

ll gcd(ll a,ll b){
    ll p = max(a,b);
    ll q = min(a,b);
    while(p%q != 0){
        ll s = p%q;
        p = max(s,q);
        q = min(s,q);
    }
    return q;
}



int main(void)
{
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    ll n,u,v;
    cin >> n >> u >> v;
    u--;v--;
    vector<vector<ll>>tre(n);
    rep(i,n-1){
        ll a,b;
        cin >> a >> b;
        a--;
        b--;
        tre[a].pb(b);
        tre[b].pb(a);
    }
    queue<ll> que1,que2;
    vector<ll>depth1(n),depth2(n),done1(n,false),done2(n,false);
    que1.push(u);que2.push(v);
    done1[u] = true;done2[v] = true;
    while(!que1.empty()){
        ll k = que1.front();que1.pop();
        for(auto t : tre[k]){
            if(!done1[t]){
                depth1[t] = depth1[k]+1;
                que1.push(t);
                done1[t] = true;
            }
        }
    }
    while(!que2.empty()){
        ll k = que2.front();que2.pop();
        for(auto t : tre[k]){
            if(!done2[t]){
                depth2[t] = depth2[k]+1;
                que2.push(t);
                done2[t] = true;
            }
        }
    }
    ll ans = 0;
    rep(i,n){
        cerr << depth2[i] << endl;
        if(depth1[i] > depth2[i])continue;
        ans = max(ans,depth2[i]);
    }

    cout << ans-1 << endl;



    return 0;


}


Measured memory_bytes: 12512
#include <bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define MOD (int)(1e9+7)
#define ceil(x, y) (x%y==0? (x/y) : (x/y+1))
#define FOR(i, N) for(int i = 0; i < N; ++i)
#define FOR1(i, N) for(int i = 1; i <= N; ++i)
#define vi vector <int>
#define pii pair <int, int>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mset(a, v) memset(a, v, sizeof(a))
#define all(v) (v).begin(), (v).end()
#define INF 2e9
#define EPS 1e-9
#define MAX 200009
#define int long long
/*#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef cc_hash_table<int, int, hash<int>> ht; // while using, comment #define int long long  */

void __print(int x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define dbg(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define dbg(x...)
#endif
using namespace std;
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
    	freopen("in2.txt", "r", stdin);
    	freopen("out.txt", "w", stdout);
    #endif

	int T=1;
	//cin >> T;
	FOR1(tp, T)
	{
		//cout << "Case #" << tp << ": ";
		int n; cin >> n;
		int d = n % 10;
		if(d == 2 or d == 4 or d == 5 or d == 7 or d == 9){
			cout << "hon";
		}
		else if (d == 0 or d == 1 or d == 6 or d == 8){
			cout << "pon";
		}
		else cout << "bon";
		cout << '\n';
	}
	return 0;
}


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

int main() {
    int n, x, t;
    cin >> n >> x >> t;
    int ans = (n+x-1)/x;
    ans *= t;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,t=0;
    cin>>a>>b;
    for(int i=1;i<=12;i++)
    {
        if(i<a)
            t++;
        else if(i==a&&i<=b)
                t++;
    }
    printf("%d",t);
    return 0;
}


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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
//#define int ll
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef vector< vvi > vvvi;
typedef vector<short> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<ld> vld;
typedef vector<vld> vvld;
typedef vector<vvld> vvvld;
typedef vector<string> vst;
typedef vector<vst> vvst;
typedef pair<ld, ld> pld;
typedef complex<double> base;

#define inmin(a, b) a = min(a, (b))
#define inmax(a, b) a = max(a, (b))
#define modsum(a, b) ((a) + (b) >= M ? (a) + (b) - M : (a) + (b))
#define modsubtract(a, b) ((a) - (b) < 0 ? (a) - (b) + M : (a) - (b))
#define modmultiply(a, b) (((a) * (b)) % M)
#define insum(a, b)  a = modsum(a, (b))
#define insubtract(a, b) a = modsubtract(a, (b))
#define inmultiply(a, b) a = modmultiply(a, (b))
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define sqr(x) ((x) * (x))
#define fori(i, n) for(int i = 0; i < (int)(n); ++i)
#define cint const int &
#define SZ(a) ((int)(a.size()))
#ifdef MAX_HOME
#define watch(x) cout << (#x) << " = " << x << endl;
#else
#define watch(x) cerr << (#x) << " = " << x << endl;
#endif

const double PI = 2 * acos(0.0);

const string DIGITS = "0123456789";
const string ALPH = "abcdefghijklmnopqrstuvwxyz";


template<class T>
ostream & operator << (ostream &out, vector<T> &a) {
    out << "{";
    for (auto x : a) out << x << " ";
    return out << "}";
}

template<class T>
ostream & operator << (ostream &out, pair<T, T> &a) {
    out << "{";
    cout << a.first << ", " << a.second;
    return out << "}";
}

void smain();

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

#ifdef MAX_HOME
    freopen("input.txt", "r", stdin);
#endif

    cout << setprecision(12) << fixed;

    smain();
}
/* END OF TEMPLATE ========================================================================================================================================== */;



void smain() {

    int q;
    cin >> q;
    while (q--) {
        ll a, b;
        cin >> a >> b;
        ll c = a * b;
        if (c == 1) {
            cout << "0\n";
            continue;
        }
        ll k = sqrt(c);
        while (k * k >= c) --k;
        ll mx = (c - 1) / k;
        ll lol = 0;
        if (mx == k) --lol;
        if (min(a, b) <= k) --lol;
        lol += k + k;
        cout << lol << "\n";

    }
}



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

int main(){
  int a, b;
  cin >> a >> b;
  
  int ans = 0;
  for(int x = 1; x < 1001; ++x){
  	if(x*8/100 == a && x/10 == b){
        ans = x;
  		break;
  	}
  }
  if(ans == 0) cout << -1 << endl;
  else cout << ans << endl;
  return 0;
}



Measured memory_bytes: 256
import sys

x, y = map(int, input().strip().split())

if x % y == 0:
    print(-1)
    sys.exit()

i = 1
while 1:
    z = x * i
    if z > 1.0e+18:
        print(-1)
        sys.exit()
    if z % y != 0:
        print(z)
        sys.exit()
    i += 1 


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

int main() {
	int a,b,c,k;
	cin>>a>>b>>c>>k;
	if(a>=k){
		cout<<k<<endl;
	}else if((a+b)>=k){
		cout<<a<<endl;
	}else{
		cout<<2*a+b-k<<endl;
	}
	return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
  //input
  int tmp;
  int n;cin>>n;
  vector<int> d;
  for(int i = 0; n > i; i++){
    cin >> tmp;
    d.push_back(tmp);
  }
  int m; cin>>m;
  vector<int> t;
  for(int i = 0; m > i; i++){
    cin >> tmp;
    t.push_back(tmp);
  }
  bool ok = true;

  //calc
  sort(d.begin(),d.end());
  sort(t.begin(),t.end());
  if(n < m)ok = false;
  else {  
    tmp = 0;
    for(int i = 0; m > i; i++){
      cerr << i << ":" << t[i] << "-> ";
      while(!(tmp > n)){
        cerr << d[tmp] << " ";
        if(d[tmp] == t[i]){
          tmp++;
          break;
        }
        tmp++;
      }
      cerr << endl;
      if(tmp > n){
        ok = false;
        break;
      }
    }
  }
  cout << (ok ? "YES" : "NO") << endl;
}

//N < M = no;

Measured memory_bytes: 2548
"""
・全探索してもよい
・ある値（例えばa1）を決めたら他の値は全部決まってしまう
→ a1に適当な値を入れて後は全部できているかチェックすればよい
"""
import sys

c = [[int(i) for i in input().split()] for j in range(3)]
a = [0] * 3
b = [0] * 3

max_val = 100

# a1を適当に決める
a[0] = 0

# 他の値は勝手に決まる
b[0] = c[0][0] - a[0]
b[1] = c[0][1] - a[0]
b[2] = c[0][2] - a[0]
a[1] = c[1][0] - b[0]
a[2] = c[2][0] - b[0]

#print(f"a;{a}\t b:{b}")

for i in range(3):
    for j in range(3):
        left = a[i] + b[j]
        right = c[i][j]
        #print(f"{a[i]}+{b[j]} -> {c[i][j]}")
        if(left != right):
            ans = False
            print("No")
            sys.exit()


print("Yes")

Measured memory_bytes: 3064
fn get_input() -> String {
    let mut word = String::new();
    std::io::stdin().read_line(&mut word).ok();
    return word.trim().to_string();
}

fn main() {
    let mut s:Vec<Vec<char>> = Vec::new();
    for _i in 0..3 {
        s.push(get_input().chars().collect());
    }

    let mut turn = 'a';

    loop {
        if s[(turn as i32 - 'a' as i32) as usize].len() == 0 {
            break;
        }
        turn = s[(turn as i32 - 'a' as i32) as usize].remove(0);
    }

    println!("{}", if turn == 'a' {"A"} else if turn == 'b' {"B"} else {"C"});
}


Measured memory_bytes: 4352
#include <iostream>

using namespace std;

int main() {
  int N;
  cin >> N;
  N %= 10;
  if(N == 3) cout << "bon" << endl;
  else if(N == 0 || N == 1 || N == 6 || N == 8) cout << "pon" << endl;
  else cout << "hon" << endl;
   return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define rep(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define repr(i, n, m) for (int i = (int)(n) - 1; i >= (int)(m); i--)
using namespace std;
using ll = int64_t;
const int MOD = 1000000007; // 10^9+7

int main() {
    double A, B;
    cin >> A >> B;
    int ans = -1;
    rep(i, 1, 2000)
    {
        double a = floor(0.08 * (double)i);
        double b = floor(0.1 * (double)i);
        if (a == A && b == B)
        {
            ans = i;
            break;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
//雪花飄飄北風嘯嘯
//天地一片蒼茫

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#define ll long long
#define ii pair<ll,ll>
#define iii pair<ii,ll>
#define fi first
#define se second
#define endl '\n'
#define debug(x) cout << #x << " is " << x << endl;

#define rep(x,start,end) for(auto x=(start)-((start)>(end));x!=(end)-((start)>(end));((start)<(end)?x++:x--))
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()

ll MAX(ll a){return a;}
ll MIN(ll a){return a;}
template<typename... Args>
ll MAX(ll a,Args... args){return max(a,MAX(args...));}
template<typename... Args>
ll MIN(ll a,Args... args){return min(a,MIN(args...));}

#define indexed_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>

mt19937 rng(chrono::system_clock::now().time_since_epoch().count());

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	string s,t;
	cin>>s>>t;
	
	int ans=0;
	rep(x,0,sz(s)){
		ans+=(s[x]!=t[x]);
	}
	
	cout<<ans<<endl;
}


Measured memory_bytes: 3808
#include<stdio.h>
#include<math.h>

int main(){

long N;
scanf("%ld",&N);
long I = sqrt(N);
long J;

while (N%I!=0){
  I--;
}

if(I!=0){
  J = N/I;
  printf("%ld",I+J-2);
}else{
  printf("%ld",N-1);
}

return 0;

}

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

#define task "A"
#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i <= (r); ++i)
#define Rep(i, r, l) for (int i = (r); i >= (l); --i)
#define pb push_back
#define F first
#define S second
#define by(x) [](const auto& a, const auto& b) { return a.x < b.x; } // sort(arr, arr + N, by(a));

using ll = long long;
using ld = long double;
using ull = unsigned long long;

using namespace std;

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

// Limit

// Struct

// Variables
int a,b;
// Function

int main()
{
	//freopen(task".in","r",stdin);
	//freopen(task".out","w",stdout);
	ios_base::sync_with_stdio(false);cin.tie(nullptr);
	cin >> a >> b;
	if (a>9||b>9) cout << -1;
	else cout << a*b;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>


using namespace std;


int main()
{
	int N,L;
	int v[201];
	int ans=0,min=1000000,mini;
	
	cin >> N >> L;
	
	for(int i=0;i<N;i++){
		v[i] = L + i;
	}
	
	for(int i=0;i<N;i++){
		ans += v[i];
		if(min > abs(v[i])) {
			min = abs(v[i]);
			mini = i;
		}
	}
	
	ans = ans - v[mini];
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using ll = long long;
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define ALL(x) x.begin(),x.end()

#define INF (ll)1e9 //10^9:∞
#define LLINF (ll)1e12
#define MOD (ll)(1e9+7) //10^9+7:合同式の法
#define PI 3.141592653589
#define PB push_back
#define F first
#define S second
#define __MAGIC__ ios::sync_with_stdio(false);cin.tie(nullptr);

#define YESNO(T) if(T){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define yesno(T) if(T){cout<<"yes"<<endl;}else{cout<<"no"<<endl;}
#define YesNo(T) if(T){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}

#define Graph vector<vector<int>>
#define PII pair<int,int>
#define VI vector<int>
#define VVI vector<vector<int>>
#define VPII vector<pair<int,int>>

#define DDD fixed<<setprecision(10)
#define endl "\n"

using namespace std;
/*..................DEFINE GLOBAL VARIABLES...................*/


/*.....................DEFINE FUNCTIONS ......................*/



/*.........................kemkemG0...........................*/
signed main() {
	__MAGIC__


	int N;
	cin >> N;

	vector<vector<pair<int, int>>> vp(N);  //vp[i]={(F1,S1),(F2,S2),(F3,S3)}:=人iの証言で

	REP(i, N) {
		int A;
		cin >> A;
		REP(j, A) {

			PII p;
			cin >> p.F >> p.S;

			--p.F;

			vp[i].push_back(p);
		}
	}


	int ans = 0;

	REP(bit, 1 << N) {
		vector<int> testify(N, -1); //未なら-1　正直なら1 不親切なら0

		bool ok = true;

		REP(i, N) {

			if ( (bit >> i) & 1) { //もしiの人が親切ならは
				for (auto pp : vp[i]) {

					// if (testify[pp.F] == -1)testify[pp.F] = pp.S;//まだ未証言なら証言を更新
					// else if (testify[pp.F] != -1 && testify[pp.F] != pp.S)ok = false; //すでに証言されてて食い違ってたらダメ

					if ( ((bit >> pp.F) & 1) != pp.S) ok = false; //今仮定してる設定と記録が食い違っててもダメ
				}
			}

		}

		if (!ok)continue;

		else ans = max(ans, __builtin_popcount(bit) );
	}

	cout << ans << endl;







	return 0;
}


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

constexpr int inf = 0x3f3f3f3f;
constexpr ll linf = 0x3f3f3f3f3f3f3f3fLL;

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

    int n; cin >> n;
    cout << n * (n + 1) / 2 << endl;
    return 0;
}


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

string s,t;

int main ( void ) {
	int ans=0;
	cin>>s>>t;
	for(int i=0;i<s.size();i++)
		if(s[i]==t[i])
			ans++;
	printf("%d\n",ans);
	
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cassert>
#include <algorithm>    
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <cstring>
#include <cmath>
#include <bitset>
#define mk make_pair
#define eb emplace_back
#define eps 1e-8
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
// #define int long long
using namespace std;

typedef long double ld;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef unsigned long long ull; 
typedef vector<int> vii;
typedef vector<long double> vd;
const int inf = 1e9;
const int M = 1e9 + 7;
//__int128


signed main()
{
  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  string s;
  int n;
  cin >> n >> s;
  int res = 1;
  for(int i = 1; i < n; ++i) {
  	if(s[i] == s[i - 1]) continue;
  	++res;
  }
  cout << res << endl;
	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
using LL=long long;
int main(){
  int N,Q;cin>>N>>Q;
  LL A[100002];
  for(int i=1;i<=N;i++)
    scanf("%lld",&A[i]);
  
  if(N%2!=0){
    for(int i=N;i>=1;i--)A[i+1]=A[i];
    A[1]=0;
    N+=1;
  }
  
  LL s[100002]={},k[100002]={};
  for(int i=1;i<=N;i++)s[i]=s[i-1]+A[i];
  for(int i=1;i<=N;i++)k[i]=k[i-1]+(i%2==0?A[i]:0);
  
  vector<LL>d(N/2+1);
  for(int i=1;i<=N/2;i++){
    d[i]=(A[N/2+i]+A[i*2])/2;
  }
  
  while(Q--){
    LL X;scanf("%lld",&X);
    vector<LL>::iterator it=lower_bound(d.begin(),d.end(),X);
    int t=N/2-(it-d.begin())+1;
    printf("%lld\n",s[N]-s[N-t]+k[N-t*2]);
  }
}


Measured memory_bytes: 4480
#include <iostream>
#include<stdio.h>
    using namespace std;
     
    int main() {
 int a,b,d,r;
  double f;
 
  scanf("%d %d",&a,&b);
 
  d=a/b;
  r=a%b;
  f=1.0*a/b;
 
  printf("%d %d %f\n",d,r,f);
    return 0;
    }

Measured memory_bytes: 1220
N = int(input())
a = list(map(int, input().split()))
a.insert(0, 0)
a.append(0)
# print(a)

li = [abs(a[i] - a[i+1]) for i in range(N + 1)]
sumli = sum(li)

# iは除く番号
for i in range(1, N + 1):
  print(sumli - (li[i-1] + li[i]) + abs(a[i-1]-a[i+1]))

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

/////////////////////////////////////////////////////////

void Main(){
  string S, T;
  cin >> S >> T;
  int res = 0;
  rep(i, 0, 3){
    if(S[i] == T[i]) res++;
  }
  cout << res << endl;
}

/////////////////////////////////////////////////////////

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  //cout << std::fixed << std::setprecision(15);

  Main();
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>

#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef vector<int> vec;
typedef vector<vector<int>> mat;
using P = pair<ll, ll>;

template<class T> inline bool chmin(T& a,T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a,T b) {if (a < b) {a = b; return true;} return false;}

const int INF = 1<<29;
const int MAX = 510000; //nCrのr
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX], facn[MAX];

// テーブルを作る前処理
void COMinit(ll n) {
    fac[0] = fac[1] = 1;
    facn[1] = n;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        facn[i] = facn[i-1] * (n-i+1) % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return facn[k] * finv[k] % MOD;
}

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


int main(){
  ll n, a, b; cin >> n >> a >> b;
  COMinit(n);
  ll res = (modpow(2, n, MOD) - 1 + MOD) % MOD;
  res = (res - COM(n, a) + MOD) % MOD;
  res = (res - COM(n, b) + MOD) % MOD;
  cout << res << endl;
}


Measured memory_bytes: 16128
n = int(input())
result = [0]*4
for i in range(n):
    r = input()
    if r == 'AC':
        result[0] += 1
    elif r == 'WA':
        result[1] += 1
    elif r == 'TLE':
        result[2] += 1
    elif r == 'RE':
        result[3] += 1

print(f'AC x {result[0]}')
print(f'WA x {result[1]}')
print(f'TLE x {result[2]}')
print(f'RE x {result[3]}')


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

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

  string s;
  cin >> s;

  vector<int> rle;
  int run = 1;
  rep(i, s.size() - 1) {
    if (s[i] != s[i+1]) {
      rle.push_back(run);
      run = 1;
    } else {
      run++;
    }
  }
  rle.push_back(run);

  rep(i, rle.size()) {
    if (i % 2 == 0) {
      rep(j, rle[i] - 1) cout << 0 << " ";
      cout << (rle[i]+1)/2 + rle[i + 1]/2 << " ";
    } else {
      cout << rle[i - 1]/2 + (rle[i] + 1)/2 << " ";
      rep(j, rle[i] - 1) cout << 0 << " ";
    }
  }
  cout << endl;
  return 0;
}


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


struct SegmentTree {
        private:
        int n;
        vector<int> node;
        
        public:
        SegmentTree(vector<int> v){
                int sz = v.size();
                n = 1;
                while(n < sz) n *= 2;
                node.resize(2*n-1,INF);
                for(int i=0;i<sz;i++) node.at(i+n-1) = v.at(i);
                for(int i=n-2;i>=0;i--) node.at(i) = min(node.at(2*i+1),node.at(2*i+2));
        }
        
        //x番目の要素をvalに変更する。
        void update(int x,int val){
                x += n-1;
                node.at(x) = val;
                while(x > 0){
                        x = (x-1)/2;
                        node.at(x) = min(node.at(2*x+1),node.at(2*x+2));
                }
        }
        
        //区間[a,b)の最小値を求める
        int getmin(int a,int b,int k=0,int l=0,int r=-1){
                if(r < 0) r = n;
                if(r <= a || b <= l) return INF;
                if(a <= l && r <= b) return node.at(k);
                int vl = getmin(a,b,2*k+1,l,(l+r)/2);
                int vr = getmin(a,b,2*k+2,(l+r)/2,r);
                return min(vl,vr);
        }
};
 
int main() {
  int n,m;
  cin >> n >> m;
  string S;
  cin >> S;
  vector<int> dp(n+1,INF);
  SegmentTree seg(vector<int>(n+1,INF));
  dp.at(0) = 0;
  seg.update(0,0);
  for(int i=1;i<=n;i++){
    if(S.at(i) == '1') continue;
    int l = max(0,i-m);
    dp.at(i) = seg.getmin(l,i) + 1;
    seg.update(i,dp.at(i));
  }
  
  if(dp.at(n) >= INF){
    cout << -1 << endl;
    return 0;
  }
  
  vector<int> dice;
  int s = 0;
  int i = n;
  int j = n;
  int before = n;
  int now = dp.at(n)-1;
  while(i >= 0){
    if(dp.at(i) == now-1 || before - i > m){
      dice.push_back(before-j);
      s += before-j;
      before = j;
      j = i;
      now --;
    }else if(dp.at(i) == now){
      j = i;
    }
    i --;
  }
    
  dice.push_back(n-s);
  reverse(dice.begin(),dice.end());
  
  for(int i=0;i<dice.size();i++) cout << dice.at(i) << endl;  
  
  
  return 0;
}



Measured memory_bytes: 2936
#pragma region
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define repc(i, m, n) for (int i = m; i < n; i++)
#define reprc(i, m, n) for (int i = m; i > n; i--)
#define all(v) v.begin(), v.end()
#define INF 1e9
#define EPS 1e-10
using namespace std;
typedef long long ll;
#pragma endregion

struct pos {
    int x;
    int y;
};

int main()
{
    int N,val1,val2,c = 0;
    cin >> N;
    vector<pos> p(N);

    rep(i, N){
        cin >> p[i].x >> p[i].y;
    }

    vector<int> order(N);

    rep(i, N){
        order[i] = i;
    }

    double alldist = 0;
    do{
        double dist = 0;
        repc(i, 1, N){
            val1 = (p[order[i - 1]].x - p[order[i]].x);
            val2 = (p[order[i - 1]].y - p[order[i]].y);
            dist += sqrt(val1 * val1 + val2 * val2);
        }
        alldist += dist;
        c++;
    }while(next_permutation(all(order)));

    cout << fixed << setprecision(10);
    cout << alldist / c << endl;
}

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

int main()
{
	int a,b;
	cin>>a>>b;
	if(a>8 || b>8 || a+b>16)
	{
		cout<<":("<<"\n";
	}
	else
	{
		cout<<"Yay!";
	}
}



Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(){
	char y[120][120];
	int a,b;
	scanf("%d %d",&a,&b);
	for(int i  = 0;i<a+2;i++){
		for(int j = 0;j<b+2;j++){
			y[i][j]='#';
		}
	}
	for(int i  = 0;i<a;i++){getchar();
		for(int j = 0;j<b;j++){
			scanf("%c",&y[i+1][j+1]);
		}
		
	}
	for(int i  = 0;i<a+2;i++){
		for(int j = 0;j<b+2;j++){
			printf("%c",y[i][j]);
		}
		printf("\n");
	}


}

Measured memory_bytes: 256
n = gets.chomp.to_i
x = []
y = []
length = 0
res = 1
result = 0

for i in 0..n-1
    x[i],y[i] = gets.split(' ').map(&:to_i)
end 

for i in 0..n-1
    for j in i+1..n-1
        length += Math.sqrt((x[i] - x[j]) ** 2 + (y[i] - y[j]) ** 2)
    end
end

for i in 1..n-1
    res *= i
end

puts (length * (res) * 2) / (res * n)

Measured memory_bytes: 1788
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
 
int main() {
int n;
cin>>n;
int a[n],i,c=0;
for(i=0;i<n;i++)
{
    cin>>a[i];
}
for(i=0;i<n;i++)
{
    if(a[i]!=i+1)
    c++;
}

if(c<=2)
cout<<"YES";
else
cout<<"NO";
}

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

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v) {
  int sz = v.size();
  for (int i = 0; i < sz; i++) {
    cout << v[i] << " \n"[i == sz - 1];
  }
}

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

  int k;
  cin >> k;
  k--;
  vector<int> v = {1, 1, 1, 2, 1, 2, 1, 5,  2, 2, 1, 5, 1, 2, 1, 14,
                   1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  cout << v[k] << endl;
  
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
  class Main {
     
static BufferedReader s1;
static BufferedWriter out;
static String read() throws IOException{String line="";while(line.length()==0){line=s1.readLine();continue;}return line;}
static int int_v (String s1){return Integer.parseInt(s1);}
static long long_v(String s1){return Long.parseLong(s1);}
static int[] int_arr() throws IOException{String[] a=read().split(" ");int[] b=new int[a.length];for(int i=0;i<a.length;i++){b[i]=int_v(a[i]);}return b;}
static long[] long_arr() throws IOException{String[] a=read().split(" ");long[] b=new long[a.length];for(int i=0;i<a.length;i++){b[i]=long_v(a[i]);}return b;}
static void assign(){s1=new BufferedReader(new InputStreamReader(System.in));out=new BufferedWriter(new OutputStreamWriter(System.out));}
 
  public static void main(String args[]) throws  IOException {
      assign();
    int[] a=int_arr();
    int y=a[0];
    a[0]=a[1];a[1]=y;
    y=a[0];
    a[0]=a[2];a[2]=y;
    out.write(a[0]+" "+a[1]+" "+a[2]+"");
    out.flush();
    
  }
}

Measured memory_bytes: 21460
#include <float.h>
#include <inttypes.h>
#include <limits.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <math.h>
#ifdef __cplusplus
#include <bits/stdc++.h>
#endif

bool arr[101];

uint32_t nextpint(void){ char c=getchar_unlocked(); while(c<'0'||'9'<c) c=getchar_unlocked(); uint32_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar_unlocked(); } return x; }
void printint(uint32_t x){ if(x<0){x=-x; putchar_unlocked('-');}else if(x==0){putchar_unlocked('0');} int d=0; char s[10]; while(x){ s[d]='0'+x%10; x/=10; d++; } for (int i=d-1; i>=0; i--) putchar_unlocked(s[i]); putchar_unlocked('\n'); }

uint32_t h[100000];
bool is[100000];

int main(void){
	uint32_t n=nextpint();
	uint32_t m=nextpint();
	for(uint32_t i=0; i<n; i++){
		h[i]=nextpint();
	}
	for(uint32_t i=0; i<m; i++){
		uint32_t a=nextpint()-1;
		uint32_t b=nextpint()-1;
		if(h[a]>h[b]){
			is[b]=true;
		}else if(h[a]<h[b]){
			is[a]=true;
		}else{
			is[a]=true;
			is[b]=true;
		}
	}
	uint32_t ans=0;
	for(uint32_t i=0; i<n; i++){
		if(!is[i]) ans++;
	}
	printint(ans);
}


Measured memory_bytes: 1992
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const ll nmax = 8;
const ll INF = 1e9;
bool graph[nmax][nmax];
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}

class UnionFind
{
  public:
    vector<ll> Parent;

    UnionFind(ll N)
    {
        Parent = vector<ll>(N, -1);
    }
    ll find(ll A)
    {
        if (Parent[A] < 0)
            return A;
        return Parent[A] = find(Parent[A]);
    }

    ll size(ll A)
    {
        return -Parent[find(A)];
    }

    bool Union(ll A, ll B)
    {
        A = find(A);
        B = find(B);
        if (A == B)
        {
            return false;
        }
        if (size(A) < size(B))
            swap(A, B);

        Parent[A] += Parent[B];
        Parent[B] = A;

        return true;
    }
};

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a / g * b;
}

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}

void solve(long long Q, long long H, long long S, long long D, long long N)
{
    int one = min(S, min(Q * 4, H * 2));

    if (one * 2 <= D)
    {
        cout << N * one << endl;
    }
    else
    {
        cout << (N / 2) * D + (N % 2) * one << endl;
    }
}

int main()
{
    long long Q;
    scanf("%lld", &Q);
    long long H;
    scanf("%lld", &H);
    long long S;
    scanf("%lld", &S);
    long long D;
    scanf("%lld", &D);
    long long N;
    scanf("%lld", &N);
    solve(Q, H, S, D, N);
    return 0;
}


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

using namespace std;

const int maxi = 1e6+10;
#define pb push_back
int n;
string s;
vector<int> v[maxi];

int d[1000][1000];

void solve(int l, int r, int x)
{
    if (l>=r) return;

    int mid = (l+r)/2;
    for (int i=l;i<=mid;i++)
        for (int j=mid+1;j<=r;j++)
           d[i][j] = x;

    solve(l,mid, x+1);
    solve(mid+1,r,x+1);
}
int main()
{
    cin>>n;

    solve(1,n,1);

    for (int i=1;i<=n;i++){
        for (int j=i+1;j<=n;j++)
        printf("%d ",d[i][j]);
    printf("\n");
    }

    return 0;
}
//pitaju me pitaju, mila gde si ?
//ja im kazem srecna jesi


Measured memory_bytes: 27776
#include<iostream>
#include<algorithm>
#include<cassert>
#include<vector>
#include<fstream>
#include<string>
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<queue>
#include<map>

using namespace std;
#define REP(i,m,n) for(int i=m;i<n;++i)
#define INF 10000000000000000
#define MOD 1000000007
#define ll long long
#define mp make_pair
#define all(v) v.begin(),v.end()

int main() {
	int n, a, b;
	cin >> n >> a >> b;
	if ((b - a) % 2 == 1) {
		printf("Borys");
	}
	else {
		printf("Alice");
	}
	return 0;
}

Measured memory_bytes: 256
S=input()
N=len(S)
A="01"*(N//2)
A+="0" if N%2==1 else ""
B="10"*(N//2)
B+="1" if N%2==1 else ""
ansA=0
ansB=0
for i in range(N):
  if S[i]!=A[i]:
    ansA+=1
  if S[i]!=B[i]:
    ansB+=1
print(min(ansA,ansB))

Measured memory_bytes: 3316
import std.stdio, std.conv, std.string, std.bigint;
import std.math, std.random, std.datetime;
import std.array, std.range, std.algorithm, std.container, std.format;
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }

/*
x: i日目にAをするときの最大
y: i日目にBをするときの最大
z: i日目にCをするときの最大

漸化式は
x = as[i] + max(y, z)
y = bs[i] + max(x, z)
z = cs[i] + max(x, y)

*/

void main(){
	long n = read.to!long;
	long[3][] xs;
	foreach(i; 0 .. n){
		xs ~= [read.to!long, read.to!long, read.to!long];
	}
	
	long[3] ans = [0, 0, 0];
	foreach(x; xs){
		ans = [
				x[0] + max(ans[1], ans[2]),
				x[1] + max(ans[0], ans[2]),
				x[2] + max(ans[0], ans[1])
				];
	}
	
	max(ans[0], ans[1], ans[2]).writeln;
}


Measured memory_bytes: 5372
#include<iostream>
#include<stdio.h>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
  //整数の時はint
  int n;
  //文字の時はstring
  int a;

  //外部入力
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>a;
    if(a%2==0){
      if(a%3!=0 && a%5!=0){
      cout<<"DENIED"<<endl;
      return 0;
      }
    }
  }
  cout<<"APPROVED"<<endl;
  return 0;
}


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

// 小数点以下桁数
// fixed << setprecision(i)

int64_t gcd(int64_t a,int64_t b){return (a%b==0?b:gcd(b, a%b));}
int64_t lcm(int a,int b){return (int64_t)a*b/gcd(a, b);}
int factorial(int a){int b=1;while(a){b*=a--;}return b;} //13以下対応
bool is_prime(int a){if(a<=1)return false;for(int i=2;(int64_t)i*i<=a;i++){if(a%i==0)return false;}return true;}
int get_adp(double x, int n){return (int)round((x-(int)x)*pow(10,n))%10;} // 小数点以下の指定桁の値を取得
int64_t sigma(int64_t s, int64_t n){return n*(2*s+n-1)/2;}

//順列の全列挙
// vector<int> v(N);
// iota(v.begin(), v.end(), 1);       // v に 1, 2, ... N を設定
// do {
//	for(auto x : v) cout << x << " "; cout << "\n";     // v の要素を表示
// } while( next_permutation(v.begin(), v.end()) ); 

//bit全探索
// for (int tmp = 0; tmp < (1 << ビット数); tmp++) {
//	bitset<ビット数> s(tmp);
//	// (ビット列sに対する処理)
// }

int ft_strchar(string s, char c, int n)
{
	for (int i = 0; i < n; i++)
	{
		if (c == s[i])
			return (i);
	}
	return (-1);
}

int main()
{
	vector<int64_t> achmr(5, 0);
	int64_t ans = 0;
	int n, index;
	string s;
	
	cin >> n;
	vector<string> sn(n);;
	for (int i = 0; i < n; i++)
		cin >> sn[i];
	for (int i = 0; i < n; i++)
	{
		if ((index = ft_strchar("ACHMR", sn[i][0], 5)) == -1)
			continue;
		achmr[index]++;
	}
	// for (int i = 0 ; i < 5; i++)
	// 	cout << achmr[i] << endl;
	for (int i = 0; i < 3; i++)
	{
		for (int j = i + 1; j < 4; j++)
		{
			for (int k = j + 1; k < 5; k++)
				ans += achmr[i] * achmr[j] * achmr[k];
		}
	}
	cout << ans << endl;
}


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

void print_rectangle(int h, int w)
{
  for (int i = 0; i < h; i++)
  {
    cout << string(w, '#') << endl;
  }
  cout << endl;
}

int main()
{
  int H, W;
  while (true)
  {
    cin >> H >> W;
    if (H == 0 && W == 0)
    {
      break;
    }
    print_rectangle(H, W);
  }
}



Measured memory_bytes: 3124
#include<bits/stdc++.h>
#define sq(a) ((a)*(a))
using namespace std;
typedef long long int ll;
typedef long double llf;
bool dist(ll x,ll y,ll d)
{
    if(sq(x)+sq(y)<=sq(d)) return true;
    else return false;
}
int main()
{
    ll n,d,c=0;cin>>n>>d;
    for(ll i=0;i<n;i++)
    {
        ll x1,y1;cin>>x1>>y1;
        if(dist(x1,y1,d)) c++;
    }
    cout<<c<<endl;
    return 0;
}

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

int main() {
  int n;
  cin >> n;
  string s,t;
  cin >> s >> t;
  string ans = "";
  rep(i,0,n) {
    ans += s.substr(i,1) + t.substr(i,1);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3600
#include <iostream>
#include <map>
#include <vector>

using namespace std;
typedef long long ll;
int main() {
  ll n, x, m;
  cin >> n >> x >> m;
  map<ll, int> mp;
  int idx = 0;
  vector<ll> path;
  do {
    mp[x] = idx++;
    path.emplace_back(x);
    x = x * x % m;
  } while (!mp.count(x));
  int start = mp[x];
  int len = idx - start;
  ll sum = 0;
  for (int i = start; i < idx; ++i)
    sum += path[i];
  ll ans = 0;
  if (n < start) {
    for (int i = 0; i < n; ++i)
      ans += path[i];
  } else {
    for (int i = 0; i < start; ++i)
      ans += path[i];
    ll loop = (n - start) / len;
    ans += loop * sum;
    ll rem = (n - start) % len;
    for (int i = 0; i < rem; ++i)
      ans += path[start + i];
  }
  cout << ans;
}

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

ll Pow(ll a, ll b, ll c){
    ll ans = 1;
    a %= c;
    while (b){
        if (b & 1) ans = (ans * a) % c;
        a = (a * a) % c;
        b >>= 1;
    }
    return (ans % c);
}

bool cmp(const int &a, const int &b){
    return a < b;
}

ll gcd(ll x, ll y){
    return x % y == 0 ? y : gcd(y, x % y);
}

ll lcm(ll x, ll y){
    return x / gcd(x, y) * y;
}

const int MAXN = 2000 + 5;
const int mod = 1e9 + 7;
ll comb[MAXN][MAXN];

void init(){
	for (int i = 0; i < MAXN; i++){
		comb[i][0] = comb[i][i] = 1;
		for (int j = 1; j < i; j++){
			comb[i][j] = comb[i - 1][j] + comb[i - 1][j - 1];
			comb[i][j] %= mod;
		}
	}
}

const int MAXM = 1e6;
int primes[MAXM], cnt;
bool st[MAXN];

void get_prime(int n){
	for (int i = 2; i <= n; i++){
		if (!st[i]) primes[cnt++] = i;
		for (int j = 0; j < cnt && i * primes[j] <= n; j++){
			st[i * primes[j]] = true;
			if (i % primes[j] == 0) break;
		}
	}
}

int main(){
    int n, a, b;
    scanf("%d%d%d", &n, &a, &b);
    printf("%d\n", min(n * a, b));
    return 0;
}


Measured memory_bytes: 256
def f(n, s, max)
  # s????????????max?????????
  max_min = ((2*s/n.to_f+n-1)/2)
  if n == 1
    # n=1?????¨??????s???????????´??°?????????????????????0???????????????
    if max >= s and s != 0
      return 1
    else
      return 0
    end
  elsif max < max_min
    return 0
  else
    result = 0
    for i in (max_min.ceil)..max
      if i <= s
        result += f(n-1, s-i, i-1)
      end
    end
    return result
  end
end
while (n, x = gets.split(" ").map(&:to_i)) != [0,0]
  puts f(3, x, n)
end

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

 
int main() {
    int r,d,x;
    cin>>r>>d>>x;

    rep(i,10){
        x=r*x-d;
        cout<<x<<endl;
    }
   
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
int main()
{
    float T,X;
    cin >>T>>X;

    

    cout << T/X << endl;

   return 0;
}

Measured memory_bytes: 256
a, b, c, x, y = map(int, input().split())

ans = 10**9
for i in range(10**5+1):
    tmp = 2*c*i + max((x-i), 0)*a + max((y-i), 0)*b
    if x < i and y < i:
            break
    ans = min(ans, tmp)
print(ans)

Measured memory_bytes: 3060
#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 ll INF = 1e18;
const ll MOD = 1e9 + 7;
const double EPS = 1e-8;

template<typename T> T chmax(T& a, const T& b){return a = (a > b ? a : b);}
template<typename T> T chmin(T& a, const T& b){return a = (a < b ? a : b);}

int main(){
    int n;
    cin >> n;
    vi a(n);
    rep(i, n) cin >> a[i];
    vi cnt(1e6+10, 0);
    rep(i, n) cnt[a[i]]++;
    REP(i, 1, cnt.size()) if(cnt[i]) {
        for(int j = i + i; j < (int)cnt.size(); j+=i) cnt[j] = 0;
        if(cnt[i] >= 2) cnt[i] = 0;
    }
    cout << accumulate(all(cnt), 0) << '\n';
    return 0;
}

Measured memory_bytes: 8008
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cassert>
#define InfL 2000000000
#define InfLL 4000000000000000000LL
#define mod 1000000007
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
using namespace std;
typedef long long ll;
typedef double db;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<db> vd;

int main() {
	ll L, R, d;
	cin >> L >> R >> d;
	ll ans = 0;
	for (ll i = L; i <= R; i++) {
		if (i % d == 0)
			ans++;
	}


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

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

ans = 0
for i in range(1, n+1):
    if i % 2 == 0:
        continue
    m = 0
    for j in range(1, i+1):
        if i % j == 0:
            m += 1

    if m == 8:
        ans += 1

print(ans)


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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

typedef long long ll;

const int INF = 1000000000;
const int MOD = 1000000007;

int main () {
    string s, t; cin >> s >> t;
    sort(all(s));
    sort(all(t), greater<char>());
    if (s < t) cout << "Yes" << endl;
    else cout << "No" << endl;
}



Measured memory_bytes: 256