akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  vector<int> yen(5);
  for (int i = 0; i < 5; i++) {
    cin >> yen.at(i);
  }
  int ans = 0;
  int m = 10;
  for (int i = 0; i < 5; i++) {
    if (yen.at(i) % 10 == 0) {
      ans += yen.at(i);
    } else {
      ans += (yen.at(i) / 10 + 1) * 10;
      if (yen.at(i) % 10 < m) {
        m = yen.at(i) % 10;
      }
    }
  }
  cout << ans - (10 - m) << endl;
}

Measured memory_bytes: 256
r, c = map(int, input().split())
output = []
for _ in range(r):
  l = list(map(int, input().split()))
  s = sum(l)
  l.append(s)
  output.append(l)
final = []
for i in range(c):
  t = 0
  for j in range(r):
    t += output[j][i]
  final.append(t)
s = sum(final)
final.append(s)
output.append(final)
for i in output:
  print(*i)


Measured memory_bytes: 6224
import sys
input = sys.stdin.readline
from heapq import heappop, heappush

N, M = map(int,input().split())
work_list = [[] for j in range(M+1)]
for i in range(N):
    temp = list(map(int,input().split()))
    if temp[0] > M:
        continue
    work_list[temp[0]].append(temp[1])

sum = 0
works = []

for i in work_list:
    for j in i:
        heappush(works, -1*j)
    if len(works) == 0:
        continue
    sum -= (heappop(works))

print(sum)


Measured memory_bytes: 23748
import sys

n = int(input())
prev_t = 0
prev_x = 0
prev_y = 0

for _ in range(n):
    t, x, y = map(int, input().split())
    d_t = abs(prev_t - t)
    d_x = abs(prev_x - x)
    d_y = abs(prev_y - y)
    if d_t % 2 != ((d_x + d_y) % 2) or d_t < d_x + d_y:
        print('No')
        sys.exit()
    prev_t = t
    prev_x = x
    prev_y = y
print('Yes')


Measured memory_bytes: 3064
import java.util.Scanner;
public class Main{ 
  public static void main(String[] args) { 
    Scanner sc = new Scanner(System.in);
    for(int i=1;;i++){
      int x = sc.nextInt(); 
      if(x==0) break;
      System.out.printf("Case %d: %d\n",i,x);
    }
  }
}
  

Measured memory_bytes: 65572
def merge(S, left, mid, right):
	global cnt
	L = S[left:mid] + [float('inf')]
	R = S[mid:right] + [float('inf')]
	i,j = 0,0
	for k in range(left,right):
		if L[i] <= R[j]:
			S[k] = L[i]
			i += 1
		else:
			S[k] = R[j]
			j += 1
			cnt += mid - left - i


def merge_sort(S, left = 0, right = 200000):
	right = min(len(S),right)
	if left+1 < right:
		mid = (left+right) // 2
		cnt1 = merge_sort(S, left, mid)
		cnt2 = merge_sort(S, mid, right)
		cnt3 = merge(S, left, mid, right)


if __name__ == '__main__':
	n = int(input())
	A = [int(s) for s in input().split()]
	cnt = 0
	inv = merge_sort(A)
	print(cnt)

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

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

	int cnt = 0, N = s.size();

	for (int i = 0; i < N; ++i) {
		if (s[i] - '0' == i % 2) cnt++;
	}

	cout << min(cnt, N - cnt) << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <iomanip>
#include <math.h>
//#include <unistd.h>
//#include <stdio.h>
#define rep(i,x) for(ll i = 0;i<x;i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;
using dou = double;
const ll inf = 2147483647;
const ll INF = 1LL << 60;
const ld pi = 3.14159265358;
const ll mod = 1000000007;
typedef pair<ll,ll> P;
using graph = vector<vector<ll>>;
template<class T> inline bool chmax(T& a, T b){if(a < b){a = b; return true;}return false;}
template<class T> inline bool chmin(T& a, T b){if(a > b){a = b; return true;}return false;}
ll gcd(ll a,ll b){
    if(a < b)swap(a,b);
    if(a % b == 0)return b;
    else return gcd(b,a%b);
}
//素数判定O(sqrt(N))
bool isp(ll n){
    bool res = true;
    if(n == 1)return false;
    else{
        for(ll i = 2;i * i <= n;i++){
            if(n % i == 0){
                res = false;
                break;
            }
        }
        return res;
    }
}

ll fac[510000], finv[510000], inv[510000];

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

// 二項係数計算
ll nCk(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
//nのm乗をMODで割ったあまりO(logN)
ll modpow(ll n,ll m,ll MOD){
    ll res = 1;
    while(m){
        if(m & 1)res = (res * n) % MOD;
        m >>= 1;
        n *= n;
        n %= MOD;
    }
    return res;
}

//printf("%.10f\n", N);
/*  vector<ll> vec = {1,2,5,6,8,9,10};
    cout << binary_search(all(vec),5) << endl; -> true*/
/*
    vector<ll> vec = {1,2,5,6,8,9,10};
    auto n = upper_bound(all(vec),4);
    cout << *n << endl; -> 5*/

//    cout << fixed << setprecision(15);

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll S;
    cin >> S;
    if(S % 111 == 0)
    cout << S / 111 * 111 << endl;
    else cout << (S / 111 + 1) * 111 << endl;
}

Measured memory_bytes: 3644
n=int(input())
a=list(map(int,input().split()))

#if n==1:
#    if a[0]==0:
#        print(1)
#    else:
#        print(0)
#    quit()

l=[0]
r=[0]
s_l=0
s_r=0
for i in range(n):
    s_l+=a[i]
    s_r+=a[n-i-1]
    l.append(s_l)
    r.append(s_r)

d={}
for i in r:
    if i in d:
        d[i]+=1
    else:
        d[i]=1

ans=0

for i in range(0,n):
    d[r[n-i]]-=1
    if s_l-l[i] in d:
        ans+=d[s_l-l[i]]


print(ans)


Measured memory_bytes: 50132
process.stdin.resume();
process.stdin.setEncoding('utf-8');
 
let inputString = '';
let currentLine = 0;
 
process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});
 
process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });
    
    main();    
});
 
function readLine() {
    return inputString[currentLine++];
}

function main() {
  const [n, k] = readLine().split(/\s/).map(Number)
  const as = readLine().split(/\s/).map(Number)
  const sum = as.reduce((a, b) => a + b)
  const avg = Math.ceil(sum / (k + 1))
  console.log(binarySearch(
    v => {
      const count = as.reduce((acc, a) => acc + Math.ceil(a / v) - 1, 0)
      return count > k
    },
    avg
  ))
}

function binarySearch(compare, r, l = 1) {
  while (l < r) {
    const m = Math.floor((l + r) / 2)
    if (compare(m - 1)) {
      if (!compare(m)) {
        return m
      }
      l = m + 1
      continue
    }
    r = m
  }
  return compare(l) ? l - 1 : l
}

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

using namespace std;

#define ALL(x) x.begin(), x.end()
#define RALL(x) x.rbegin(), x.rend()
#define MP make_pair
#define PB push_back
#define X first
#define Y second

typedef long long int lld;
typedef pair<int, int> pii;
typedef pair<lld, lld> pll;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n = 0;
    cin >> n;
    vector<lld> v(n);

    for (lld &x : v) {
        cin >> x;
    }

    lld sum = accumulate(v.begin(), v.end(), 0LL);
    lld ans = 0;
    lld mod = (lld) 1e9 + 7;

    for (int i = 0; i < n ; i++) {
        sum -= v[i];
        lld t = v[i] * (sum % mod) % mod;
        ans = (ans + t) % mod;
    }

    cout << ans % mod << '\n';

    return 0;
}

// g++ sol.cpp -o sol.out -Wall -Wextra -Wshadow -fsanitize=undefined -std=c++17

Measured memory_bytes: 4716
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define call(var) cout<<#var<<"="<<var<<endl;
#define dup(x,y) (((x)+(y)-1)/(y))
using ll=long long;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;
const int INTMAX = 2147483647;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

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

    int n = s.size(), m = t.size();

    vector<vi> dp(3030, vi(3030,0));
    rep(i,n){
        rep(j,m){
            if(s[i] == t[j]){
                dp[i+1][j+1] = dp[i][j] + 1;
            }
            else dp[i+1][j+1] = max(dp[i+1][j], dp[i][j+1]);
        }
    }

    int x = n, y = m;
    string ans = "";
    while(x>0 && y>0){
        if(dp[x-1][y] == dp[x][y]){
            --x;
        }else if(dp[x][y-1] == dp[x][y]){
            --y;
        }
        else {
            ans += s[x-1];
            --x;--y;
        }
        //cerr << "x = " << x << " y = " << y << endl;
    }
    reverse(ans.begin(), ans.end());
    cout << ans << endl;
}

Measured memory_bytes: 36224
n, m = list(map(int, input().split()))
d = {}
for i in range(m):
    a, b = list(map(int, input().split()))
    a -= 1
    b -= 1
    if a not in d:
        d[a] = [b]
    else:
        d[a].append(b)
    if b not in d:
        d[b] = [a]
    else:
        d[b].append(a)

ans = 0

def DFS(now, visited):
    global ans
    if len(visited) == n:
        ans += 1
        return
    for i in d[now]:
        if i not in visited:
            DFS(i, visited + [i])

DFS(0, [0])
print(ans)

Measured memory_bytes: 3064
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=10005;
long long a[N];
long long b[N];
int n;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%lld",&a[i]);
	long long sum1=0,sum2=0;
	for(int i=1;i<=n;i++){
		scanf("%lld",&b[i]);
		b[i]=a[i]-b[i];
		if(b[i]>0)
			sum1+=b[i];
		else{
			long long c=-b[i];
			sum2+=c/2;
		}
	}
    if(sum1>sum2)
		printf("No\n");
	else
		printf("Yes\n");
}


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

using ll = long long;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	ll h;
	cin >> h;
	ll lg = log2(h);
	ll ans = (1ll<<(lg+1))-1;
	cout << ans;
	return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <set>
#include <algorithm>

std::set<std::string> set;

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

    while(N--){
        std::string S;
        std::cin >> S;

        set.clear();
        
        int L = S.size();
        for(int i=1;i<L;i++){
            std::string s(S, 0, i), t(S, i);

            for(int j=0;j<2;j++){
                for(int k=0;k<2;k++){
                    set.insert(s + t);
                    set.insert(t + s);
                    std::reverse(s.begin(), s.end());
                }
                std::reverse(t.begin(), t.end());
            }
        }

        std::cout << set.size() << std::endl;
    }
}

Measured memory_bytes: 1292
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>

using namespace std;

int main(){
	int N;
	long long a[100000];
	int num[100000];
	scanf("%d",&N);

	for(int i=0;i<N;i++){
		a[i] = -1;
		num[i] = 0;
	}
	for(int i=0;i<N;i++){
		scanf("%lld",&a[i]);
	}

	sort(a,a+N);
	bool one = false;
	bool two = false;
		long long l1,l2;

	for(int i=N-1;i>0;i--){

		if(a[i]==a[i-1]){
			if(one == false){
				l1 = a[i];
				i--;
				one = true;
			}else if(two == false){
				l2 = a[i];
				two = true;
			}
		}

	}
	if(one&&two){
		printf("%lld\n",l1*l2);
		return 0;
	}else{
		printf("0\n");
	}

	return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int x, i = 1;

    while(true){
        cin >> x;
        if(x == 0){
            break;
        }
        cout << "Case " << i << ": " << x << endl;
        i++;
    }
    return 0;
}

Measured memory_bytes: 2948
#include<iostream>
#include<vector>
#include<algorithm>
#define ll long long
using namespace std;

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

    sort(A.begin(),A.end(),greater<ll>());
    ll ans = A[0];
    for(int i=1;i<=(N-2)/2;i++) ans += 2*A[i];
    if(N%2==1) ans+=A[N/2];


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

Measured memory_bytes: 4848
fn poor() -> Result<&'static str, &'static str> {
    let mut input = String::new();
    std::io::stdin().read_line(&mut input)
        .map_err(|_| "input error")?;
    let abc: Vec<&str> = input.trim_right().split_whitespace().collect();

    let f1 = (abc[0] == abc[1]) ^ (abc[0] == abc[2]);
    let f2 = (abc[1] == abc[2]) ^ (abc[1] == abc[0]);
    let f3 = (abc[2] == abc[0]) ^ (abc[2] == abc[1]);

    if f1 || f2 || f3 {
        Ok("Yes")
    }
    else {
        Ok("No")
    }
}


fn main() {
    println!("{}", poor().unwrap());
}

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

#define speed 			            ios_base::sync_with_stdio(0); cin.tie(0);
#define FL(i,a,n)		            for(ll i=a;i<n;i++)
#define even(x) 	                (((x)%(2)) == (0))
#define odd(x) 			            (((x)%(2)) == (1))
#define meme(x) 		            memset(x, 0, sizeof(x))
#define mod       		            1000000007

#define pb              	        push_back
#define mp                          make_pair
#define ff 			                first
#define ss 			                second
#define all(x)                      (x).begin(),(x).end()

typedef long double                 ld;
typedef pair<int,int>               pii;
typedef pair<ll,ll>                 pll;
typedef pair<double,double>         pdd;
typedef pair<ld,ld>                 pld;
typedef pair<string , string>       pss;


int main()
{
    speed
    string s;
    cin>>s;
    int n=s.length();

    if(s[n-1]=='s')
    s+="es";
    else
    {
        s+='s';
    }
    
    cout<<s<<endl;
 
}



Measured memory_bytes: 3624
/*
[agc006] E - Rotate 3x3
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
#define ALL(c) (c).begin(), (c).end()

const int MAX_N = 1e5;
const int MAX_BIT_IDX = MAX_N;

template <typename T>
class BIT {
public:
    vector<T> b;
    BIT(int n) : b(n + 1) {}
    T sum(int i) {  // i : [0, n], returns sum of [0, i)
        T s = 0;
        for (; i > 0; i -= i & -i) {
            s += b[i];
        }
        return s;
    }
    void add(int i, T x) {  // i : [0, n)
        for (i += 1; i < (int)b.size(); i += i & -i) {
            b[i] += x;
        }
        return;
    }
};

int N;
ll a[3][MAX_N];
map<ll, int> at[2];
vector<int> v[2];
int fl[2];

bool solve() {
    for (int i = 0; i < N; i++) {
        ll p = 1 + i * 3, q = p + 1, r = q + 1;
        if (i % 4 >= 2) {
            swap(p, r);
        }
        at[i % 2][(p << 40) | (q << 20) | r] = i / 2;
    }
    for (int i = 0; i < N; i++) {
        if (i % 4 >= 2) {
            swap(a[0][i], a[2][i]);
        }
        ll k1 = (a[0][i] << 40) | (a[1][i] << 20) | a[2][i];
        ll k2 = (a[2][i] << 40) | (a[1][i] << 20) | a[0][i];
        if (at[i % 2].count(k1)) {
            v[i % 2].push_back(at[i % 2][k1]);
        } else if (at[i % 2].count(k2)) {
            v[i % 2].push_back(at[i % 2][k2]);
            fl[i % 2] ^= 1;
        } else {
            return false;
        }
    }

    for (int b = 0; b < 2; b++) {
        BIT<int> bit((N + 1) / 2);
        ll inv = 0;
        for (int i = v[b].size() - 1; i >= 0; i--) {
            inv += bit.sum(v[b][i]);
            bit.add(v[b][i], 1);
        }

        if (inv % 2 != fl[b ^ 1]) {
            return false;
        }
    }

    return true;
}

int main() {
    cin >> N;
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < N; j++) {
            cin >> a[i][j];
        }
    }

    cout << (solve() ? "Yes" : "No") << endl;

    return 0;
}


Measured memory_bytes: 9516
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}

const int MAX_E = 2200;
const int MAX_V = 1100;
const ll INF = 100100100100100;

struct edge{
    int from,to;
    ll cost;
};

edge es[MAX_E];
ll d[MAX_V];
int V,E;

// s番目の頂点から各頂点への最短距離を求める
void shortest_path(int s){
    rep(i,V)d[i] = INF;
    d[s] = 0;
    while(true){
        bool update = false;
        rep(i,E){ //有向辺の場合はE
            edge e = es[i];
            if(d[e.from]!=INF && d[e.to]>d[e.from]+e.cost){
                d[e.to] = d[e.from]+e.cost;
                update = true;
            }
        }
        if(!update)break;
    }
}

bool shortest_path2(int s){
    rep(i,V)d[i] = INF;
    d[s] = 0;
    ll x,y;
    int i = 0;
    while(true){
        i++;
        bool update = false;
        rep(i,E){ //有向辺の場合はE
            edge e = es[i];
            if(d[e.from]!=INF && d[e.to]>d[e.from]+e.cost){
                d[e.to] = d[e.from]+e.cost;
                update = true;
            }
        }
        if(!update)break;
        if(i==1500)x = d[V-1];
        if(i==3000){
            y = d[V-1];
            return x==y;
        }
    }
}

ll shortest_path3(int s){
    rep(i,V)d[i] = INF;
    d[s] = 0;
    ll x,y;
    int i = 0;
    while(true){
        i++;
        bool update = false;
        rep(i,E){ //有向辺の場合はE
            edge e = es[i];
            if(d[e.from]!=INF && d[e.to]>d[e.from]+e.cost){
                d[e.to] = d[e.from]+e.cost;
                update = true;
            }
        }
        if(!update)break;
        if(i==1500)x = d[V-1];
        if(i==3000){
            y = d[V-1];
            return y;
        }
    }
}

bool find_negative_loop(){
    rep(i,V){
        d[i] = 0;
    }
    rep(i,V){
        rep(j,E){ //有向辺の場合はE
            edge e = es[j];
            if(d[e.to]>d[e.from]+e.cost){
                d[e.to] = d[e.from] + e.cost;
                if(i==V-1)return true;
            }
        }
    }
    return false;
}

int main() {
    cin >> V >> E;
    rep(i,E){
        cin >> es[i].from >> es[i].to >> es[i].cost;
        es[i].from--;
        es[i].to--;
        es[i].cost = -es[i].cost;
        /*
        // 無向辺
        es[E+i].from = es[i].to;
        es[E+i].to = es[i].from;
        es[E+i].cost = es[i].cost;
        */
    }
    if(find_negative_loop()){
        if(!shortest_path2(0)){
            cout << "inf" << endl;
            return 0;
        }else{
            cout << -shortest_path3(0) << endl;
            return 0;
        }
    }


    shortest_path(0);
    ll ans = d[V-1];
    cout << -ans << endl;
    return 0;
}
 


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

int main(){
	int n;
	cin >> n;
	
	
	vector<vector<int>> to(n);
	rep(i,n-1){
		int a,b;
		cin >> a >> b;
		--a; --b;
		to[a].push_back(b);
		to[b].push_back(a);
	}
	
	priority_queue<int> c;
	rep(i,n){
		int tmp;
		cin >> tmp;
		c.push(tmp);
	}
	
	vector<int> d(n,-1);

	queue<int> q;
	q.push(0);
	while(!q.empty()){
		int now = q.front();
		q.pop();
		d[now] = c.top();
		c.pop();
		for(auto v : to[now]){
			if(d[v] == -1) q.push(v);
		}
	}
	
	ll m = -d[0];
	rep(i,n) m += d[i];
	cout << m << endl;
	
	rep(i,n){
		cout << d[i] << " ";
	}
	
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<cctype>
using namespace std;

int main(){
    char ch;
    int word[26] = {};

    while(cin >> ch){
        ch = tolower(ch);
        if(isalpha(ch)){
            word[ch - 'a']++;
        }
    }

    for(int i = 0; i < 26; i++){
        printf("%c : %d\n", i + 'a', word[i]);
    }
    return 0;
}


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

#define rep(i,n) for(i=0;i<n;i++)

int n,A[30];
bool res = false;

bool solve(int i,int m){
    if(m==0) return true;
    if(i>=n) return false;
    res = solve(i+1,m) || solve(i+1,m-A[i]);
    return res;
}

int main(){
    int i;
    scanf("%d",&n);
    rep(i,n) scanf("%d",&A[i]);
    int q,tmp;
    scanf("%d",&q);
    rep(i,q){
        scanf("%d",&tmp);
        if(solve(0,tmp)) printf("yes\n");
        else printf("no\n");
    }
}

Measured memory_bytes: 3088
#include<bits/stdc++.h>
using namespace std ;
#define Fors(n) for(int i=1;i<=n;i++)
#define For(n) for(i=0;i<n;i++)
#define ll long long
#define vint(s) vector<int> s
#define pb(x)  push_back(x)
#define mpair(x,y) make_pair(x,y)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

ll x=0,y=0,s=0,n=0,i=0;

int main(){
    IOS;
    cin >> n;
    
    ll jj=3;
    vector<vector<ll>> v(n+2, vector<ll>(jj,0));
    //memset(v,0,sizeof(v));
    for (i= 0;i< n; i++){
    	ll a,b,c;
    	cin >> a >> b >> c;
    	if (i == 0){
    		v[i][0] = a;
    		v[i][1] = b;
    		v[i][2] = c;
    		s = max(v[i][0], max(v[i][1], v[i][2]));
    	}
    	else{
    			v[i][0] = max(v[i-1][1],v[i-1][2])+a;
				v[i][1] = max(v[i-1][0],v[i-1][2])+b;
				v[i][2] = max(v[i-1][1],v[i-1][0])+c;
				s = max(v[i][0], max(v[i][1], v[i][2]));
    	}
    }
    cout << s << endl;
    return 0;
} 


Measured memory_bytes: 5760
#include<string>
using namespace std;
#include <stdio.h>
#include <limits.h>
#include "bits/stdc++.h"
int a, b, c, x, y, z, n, m, ans1;
int main() 
{
	cin >> a >> b >> c >> x >> y;
	if (c * 2 >= a + b) {
		ans1 = a*x + b*y;
}
	if (x >= y) {
		z = x;
		n = a;
		m = y;
	}
	if (x < y) {
		z = y;
		n = b;
		m = x;
	}
	if (c * 2 < a + b) {
		if (c < n / 2) {
			ans1 = z*c * 2;
		}
		else {
			ans1 = m*c * 2 + n*(z - m);
		}
	}
	cout << ans1;
	return 0;

}

Measured memory_bytes: 256
using System;

namespace abc099_c
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] dp = new int[n + 10];
            int[] a = new int[] { 1, 6, 36, 216, 1296, 7776, 46656, 9, 81, 729, 6561, 59049 };
            for (int i = 1; i <= n; i++)
            {
                int min = int.MaxValue;
                for (int j = 0; j < a.Length; j++)
                {
                    if (i >= a[j]) min = Math.Min(min, dp[i - a[j]]);
                }
                dp[i] = min + 1;
            }
            Console.WriteLine(dp[n]);
        }
    }
}

Measured memory_bytes: 13148
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a),i##formax=(b);i<i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formax=(b);i>=i##formax;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)
#define show(x) cout<<#x<<" = "<<x<<endl;
#define all(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))
#define bitComb(a,n,k) for(int a##x,a##y,a=(1<<k)-1;a<(1<<n);a##x=a&-a,a##y=a+a##x,a=(((a&~a##y)/a##x)>>1)|a##y)
#define uniq(v) sort(all(v));v.erase(unique(all(v)), v.end())
#define bit(n) (1LL<<(n))
#define randInt(l,r) (uniform_int_distribution<ll>(l,r)(rnd))
#define randDouble(l,r) (uniform_real_distribution<double>(l,r)(rnd))
#define dout(d) printf("%.12f\n",d)

typedef long long ll;
typedef __int128_t lll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>ostream& operator<<(ostream& o,const pair<T,Y>& p){return o<<"("<<p.fi<<", "<<p.se<<")";}
template<typename A,size_t N,typename T>void Fill(A (&array)[N],const T&v){fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0;return gcd(a,b,x,y);}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return (x%m+m)%m;}
ll modPow(lll a,lll n,ll m){if(!a)return a;lll p=1;for(;n>0;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
bool isPrime(ll n){if(n<2||n%2==0)return n==2;lll t=n-1,d=t/(t&-t);for(lll a:{2,325,9375,28178,450775,9780504,1795265022})if(a%n){for(t=d,a=modPow(a,t,n);t!=n-1&&a!=1&&a!=n-1;a=a*a%n,t=t*2%n);if(a!=n-1&&t%2==0)return 0;}return 1;}
const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 998244353;
const double PI = acos(-1);
const double EPS = 1e-10;
static random_device rd;
static mt19937 rnd(rd());

const int N = 300;
const int NN = 90001;
int n, a[N], s, t;
ll DP[NN], DP2[NN];
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  DP[0] = 1;
  FOR(i, 0, n){
    cin >> a[i];
    s += a[i];
    FOR(j, 0, NN) DP2[j] = (DP[j]*2+(j>=a[i] ? DP[j-a[i]] : 0))%MOD;
    swap(DP, DP2);
  }
  ll ans = modPow(3, n, MOD);
  FOR(i, (s+1)/2, s+1) ans -= DP[i]*3;
  if(s%2==0){
    fill(DP, DP+NN, 0);
    DP[0] = 1;
    FOR(i, 0, n){
      FOR(j, 0, NN) DP2[j] = (DP[j]+(j>=a[i] ? DP[j-a[i]] : 0))%MOD;
      swap(DP, DP2);
    }
    ans += DP[s/2]*3;
  }
  cout << (ans%MOD+MOD)%MOD << endl;
}

Measured memory_bytes: 1664
#include <cstdio>

#include <cmath>

#include <cstring>

#include <iostream>

#include <algorithm>

#include <queue>

#include <vector>

#include <map>



using namespace std;



typedef long long LL;


LL a,b,c;

int main()

{
	cin>>a>>b;
	if (a>0)
	{
		cout<<"Positive"<<endl;
		return 0;
	}
	if (a==0)
	{
		cout<<"Zero"<<endl;
		return 0;
	}
	if (b<0)
	{
		c=b-a+1;
		if (c%2==0) cout<<"Positive"<<endl;
		else cout<<"Negative"<<endl;
		return 0;
	}
		cout<<"Zero"<<endl;
		return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
    using namespace std;
    #define ll long long 
    #define ull unsigned long long 
    #define ld long double
    #define fi first
    #define se second
    #define pb push_back
    #define mp make_pair
    ll mod=1e9+7;
 
     ll a[200005];
       ll b[200005];
 
     ll idx[100005][2];
    // ll cnt[200005];
     ll pre[200005];
    // ll end[200005];
     map<ll,ll> m;
 
    bool comp(const pair<ll,ll>& a, const pair<ll,ll>& b){
      return (a.fi-a.se)>(b.fi-b.se);
    }
 
    bool revcomp(const pair<ll,ll>& a, const pair<ll,ll>& b){
      return (a.fi)>(b.fi);
    }
 
 
    ll ceil11(ll a, ll b){
      if(a%b!=0)return a/b+1;
      else return a/b;
    }
    ll power(ll a,ll b,ll n){ll ans=1;while(b>0){if(b%2==1)ans=(ans*a)%n;a=(a*a)%n;b/=2;}return ans;}
 
    ll count1=0;
 
 
    ll gcd(ll a, ll b){
      //if(a<b)swap(a,b);
      if(b==0)return a;
      return gcd(b,a%b);
    }
 
  ll primepos(ll fact, ll p) 
  { 
      ll res = 0; 
      while (fact > 0) {         
          res += fact / p; 
          fact /= p;  
      } 
    
      return res; 
  } 
 
  // void dfs(ll n, ll p){
  //   if(vis[n]!=0){
  //     return;
  //   }
  //   else{
  //     vis[n]=1;
  //     b[n]=p;
  //     for(int i=0;i<v[n].size();i++){
  //       dfs(v[n][i],p);
  //     }
  //   }
  ll ceil1(ll a,ll b){
    return a/b;
  }

   
   int main(){

      ios::sync_with_stdio(0);
      int n;
      cin>>n;
      for(int i=1;i<=n;i++){
        cin>>a[i];
      }
      ll dp[n+1][n+1][2];
      memset(dp,0,sizeof dp);
      for(int i=0;i<=n;i++){
        for(int j=0;j<=n;j++){
          if(i==j){
            dp[i][j][0]=a[i];
            dp[i][j][1]=-1*a[i];
          }
         
          //cout<<dp[i][j][0]<<" "<<dp[i][j][1]<<endl;
        }
      }
      for(int j=1;j<=n;j++){
        for(int i=j-1;i>=0;i--){
          if(i==0||j==0){
            dp[i][j][0]=0;
            dp[i][j][1]=0;
          }
          else{
            dp[i][j][0]=max(a[i]+dp[i+1][j][1],a[j]+dp[i][j-1][1]);
            dp[i][j][1]=min(-1*a[i]+dp[i+1][j][0],-1*a[j]+dp[i][j-1][0]);
          }
        }
      }
      cout<<dp[1][n][0]<<endl;

      return 0;
} 

Measured memory_bytes: 142976
#define _GLIBCXX_DEBUG//TLEの原因になるので注意！！！！！！！！！！！
#include<cmath>
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
vector<int> arr;
stack<int> st;
queue<int> qu;
queue<pair<int,int> > qu2;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)
#define mins(x,y) x=min(x,y)
#define maxs(x,y) x=max(x,y)
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;
static const int INF = 1000000007;
#define mp make_pair
#define sz(x) int(x.xise())
#define mod 1000000007
#define reps(i,s,n) for(int i = s; i < n; i++)
deque<int> deq;
//#define int long long

//cerrはコメントアウトしなくても通る//ただしTLEを引き起こすことがある

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;//thisポインター　thisで自分自身のアドレス
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

vector<ll> t(2),a(2),b(2);
//vector<mint> t(2),a(2),b(2);

int main(){
    rep(i,2){
        cin >> t[i];
        //t[i]=tt[i];
    }
    rep(i,2){
        cin >> a[i];
        //a[i]=aa[i];
    }rep(i,2){
        cin >> b[i];
        //b[i]=bb[i];
    }
    ll A,B;
    A=a[0]-b[0];
    B=a[1]-b[1];
    if((A*t[0])==0||(A*t[0]+B*t[1])==0){
        cout<<"infinity"<<endl;
        return 0;
    }else if(((A*t[0]>0)&&(B*t[1]+A*t[0]>0))||((A*t[0]<0)&&(B*t[1]+A*t[0]<0))){
        cout<<0<<endl;
        return 0;
    }
    ll ans;
    if((A*t[0])<0){
        ll c=(A*t[0]*2+B*t[1])-(A*t[0]);
        ll d=(-1*A*t[0])/c;
        ans=(d)*2+1;
        if((-1*A*t[0])%c==0)ans--;
        //ans%=mod;
    }else{
        ll c=(A*t[0])-(A*t[0]*2+B*t[1]);
        ll d=A*t[0]/c;
        ans=(d)*2+1;
        if((A*t[0])%c==0)ans--;
        //ans%=mod;
    }
    cout<<ans<<endl;
    //cerr<<'G'<<endl;
    return 0;
}




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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int main(){
  ll t1,t2; cin >> t1 >> t2;
  ll a1,a2,b1,b2; cin >> a1 >> a2 >> b1 >> b2;
  if(a1*t1+a2*t2 == b1*t1+b2*t2){
    cout << "infinity" << endl;
    return 0;
  }
  ll x1,x2,y1,y2;
  x1 = a1*t1;
  x2 = a2*t2;
  y1 = b1*t1;
  y2 = b2*t2;
  if(x1+x2<y1+y2){
    swap(x1,y1);
    swap(x2,y2);
  }
  ll ans = 0;
  ll dif1 = y1-x1;
  ll dif2 = x1-y1 + x2-y2;
  if(dif1 < 0){
    cout << 0 << endl;
    return 0;
  }

  if(dif1==0){
    cout << 1 << endl;
    return 0;
  }
    
  ans++;
  ans += (dif1/dif2)*2;
  if(dif1%dif2==0)ans--;
  cout << ans << endl;
  return 0;
}


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

bool is_prime(int n){
    if(n == 1) return false;
    
    for(int i = 2; i * i <= n; i++){
        if(n % i == 0) return false;
    }
    
    return true;
}

int main(void){
    // Your code here!
    
    const int MAX = 101010;
    vector<int> a(MAX,0);
    for(int i = 0; i < MAX; i++){
        if(is_prime(i) && is_prime((i+1) / 2)) a[i] = 1; //i is a 2017-like number
    }
    
    //the cumulative sum
    vector<int> s(MAX, 0);
    for(int i = 0; i < MAX; i++) s[i+1] = s[i] + a[i];
    
    int q;
    cin >> q;
    for(int i = 0; i < q; i++){
        int l, r;
        cin >> l >> r;
        
        r++;
        cout << s[r] - s[l] << endl;
    }
    
    
}


Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <queue>
#include <fstream>
#include <algorithm>
using namespace std;

using ll = long long;

const int N = 2e5 + 10;

int x, n, p, best;
bool mk[N];

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

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

    int l = x, r = x;
    while (mk[l])
        l--;
    while (mk[r])
        r++;

    if (abs(r - x) < abs(l - x)) cout << r;
        else cout << l;
}


Measured memory_bytes: 3652
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Linq.Enumerable;
using static System.Math;

class Program
{
    static void Main()
    {
        var S = int.Parse(ReadLine());

        var mod = 1_000_000_007L;

        var dp = new long[S + 1];
        dp[0] = 1;

        for (int i = 0; i <= S; i++)
            for (int j = 0; j <= i - 3; j++)
                dp[i] = (dp[i] + dp[j]) % mod;

        WriteLine(dp[S]);
    }
}

static class ArrayDeconstructExtensions
{
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2) => (i1, i2) = (a[0], a[1]);
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2, out T i3) => (i1, i2, i3) = (a[0], a[1], a[2]);
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2, out T i3, out T i4) => (i1, i2, i3, i4) = (a[0], a[1], a[2], a[3]);
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2, out T i3, out T i4, out T i5) => (i1, i2, i3, i4, i5) = (a[0], a[1], a[2], a[3], a[4]);
}


Measured memory_bytes: 26968
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>


using namespace std;
int main(){

    while (1) {
        int a, b;
        string op;
        cin >> a >> op >> b ;
        if (op == "?"){
            break;
        }else{
            if (op == "+"){
                cout << a + b << endl;
            } else if (op == "-"){
                cout << a - b << endl;
            } else if (op == "*"){
                cout << a * b << endl;
            } else {
                cout << a/b  << endl;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 3112
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << endl;}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << endl;
}
const int mod = 1e9 + 7;

int main(){
	ll n; cin >> n;
	vl a(n),b(n);
	rep(i,n) cin >> a[i];
	rep(i,n) cin >> b[i];
	rep(i,n) if(i&1) swap(a[i],b[i]);
	ll ans = inf;
	rep(bit,1<<n){
		ll cnt = 0;
		rep(i,n) if(bit>>i & 1) cnt++;
		if((n+1)/2!=cnt) continue;
		vpl ev,od;
		rep(i,n){
			if(bit>>i & 1) od.emplace_back(a[i],i);
			else ev.emplace_back(b[i],i);
		}
		sort(all(od)), sort(all(ev));
		vl v;
		bool flag = true;
		rep(i,n/2){
			if(ev[i].first < od[i].first){
				flag = false;
				break;
			}
			if(n&1 || i<n/2-1){
				if(ev[i].first > od[i+1].first){
					flag = false;
					break;
				}
			}
			v.push_back(od[i].second); v.push_back(ev[i].second);
		}
		if(n&1) v.push_back(od.back().second);
		if(!flag) continue;
		cnt = 0;
		rep(i,n-1){
			REP(j,i+1,n){
				if(v[i]>v[j]) cnt++;
			}
		}
		chmin(ans,cnt);
	}
	if(ans==inf) puts("-1");
	else cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
bool prime[10000001];
int main() {
    for(int i=3;i<3162;i++)if(!prime[i])for(int j=i+i;j<10000001;j+=i)prime[j]=1;
    int n;
    while(cin>>n,n){
        if(n%2==0)n--;
        for(;;n-=2){
            if(!prime[n]&&!prime[n-2]&&!prime[n-6]&&!prime[n-8]){
                cout<<n<<endl;
                break;
            }
        }
    }
}

Measured memory_bytes: 10924
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int inputValue(){
    int a;
    cin >> a;
    return a;
};

void inputArray(int * p, int a){
    REP(i, a){
        cin >> p[i];
    }
};

void inputVector(vector<int> * p, int a){
    REP(i, a){
        int input;
        cin >> input;
        p -> push_back(input);
    }
}

int main()
{
    string S;
    cin >> S;
    REP(i, S.length()){
        S[i] = 'x';
    }
    cout << S << endl;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

MOD = 10**9 + 7

N = int(input())
S = input().rstrip()

is_left = [(i%2 == 0) ^ (x == 'W') for i,x in enumerate(S)]

answer = 1
left = 0
for bl in is_left:
    if bl:
        left += 1
    else:
        answer *= left
        left -= 1
        answer %= MOD
if left != 0:
    answer = 0

for i in range(1,N+1):
    answer *= i
    answer %= MOD

print(answer)

Measured memory_bytes: 5104
object Main extends App {
	val S = scala.io.StdIn.readLine
	var ans = List[Int]()
	for(i<-0 until S.size-2){
		val a = S(i).toInt - 48
		val b = S(i+1).toInt - 48
		val c = S(i+2).toInt - 48
		ans ::= a*100 + b*10 + c 
	}
//	println(ans.mkString(" "))
	println(ans.map{z => (z - 753).abs}.min)

}


Measured memory_bytes: 25408
#include<stdio.h>
#include<math.h>
#include<string>
#include<cstring>
#include<iostream>
#include<iomanip>
#include<queue>
#include<stack>
#include<map>
#include<cmath>
#include<fstream>  // 文件读取  ifstream ofstream
#include<algorithm>  
#include<vector>
using namespace std;


int main()  
{  


	string ss;
	cin>>ss;
	
	bool sta = false;

	if(ss.size()%2==0)
		sta = true; //偶数

	int len = ss.size()/2;
	while(len>=1){
		bool find = true;
		for(int i = 0;i<len;i++){
			if(ss[i]!=ss[i+len]){
				find = false;
				break;
			}
		}
		if(find&&!sta){
			cout<<2*len;
			break;
		}
		else{
			len--;
			sta = false;
		}
	}



	return 0;


} 




Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; ++i)
#define RREP(i, n) for (int i = n; 0 <= i; --i)
#define FOR(i, start, end) for (int i = start; i < end; ++i)
#define RFOR(i, start, end) for (int i = start; end <= i; --i)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1'000'000'007
#define INF32 1'050'000'000
#define INF64 4'000'000'000'000'000'000
using ll = long long;
using namespace std;
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; }


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

    ll A, B; cin >> A >> B;
    cout << max(max(A+B, A-B), A*B) << '\n';
    return 0;
}



Measured memory_bytes: 256
# from math import factorial,sqrt
# from itertools import permutations as permus
# from fractions import gcd
from collections import deque,Counter
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np
# import scipy as scp

# 入力の受け取り
n = int(input())
# 列ベクトルとかの受け取り
lists = ["".join(sorted(list(input()))) for _ in range(n)]

strcount = Counter(lists)

ans = 0
for i,n in strcount.items():
    if n == 1:
        continue
    else:
        ans += n*(n-1)/2

ans = int(ans)
print(ans)
# print("{:.10f}".format(ans))
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する



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

#define For(i, j, k) for(int i = j; i <= k; i++)
#define Forr(i, j, k) for(int i = j; i >= k; i--)

using namespace std;

const int N = 410, M = 1e5 + 10;

int n, m;
bool G[N][N], bad[N];
int X[M], Y[M];

int main(){
	scanf("%d%d", &n, &m);
	For(i, 1, m) scanf("%d%d", &X[i], &Y[i]);
	int ans = 0;

	For(i, 1, n){
		G[i][i] = true;
		Forr(j, m, 1){
			if(G[i][X[j]]){
				if(G[i][Y[j]]){
					bad[i] = true;
					break;
				}
				G[i][Y[j]] = true;
			}
			else if(G[i][Y[j]]) G[i][X[j]] = true;
		}

		if(!bad[i]) For(j, 1, i - 1) if(!bad[j]){
			bool flag = true;
			For(k, 1, n) if(G[i][k] && G[j][k]){
				flag = false;
				break;
			}
			ans += flag;
		}
	}

	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 1152
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int w = sc.nextInt();
        int ans[][] = new int[1000][1000]; 
        int time;
        for(int i = 0; i < h; i++){
            char[] hw = sc.next().toCharArray();
            time = -1;
            for(int j = 0; j < w; j++){
                if(hw[j] == 'c'){
                    time = 0;
                }
                ans[i][j] = time;
                if(time != -1){ 
                    time++;
                }
            }
        }
         
        for(int i = 0; i < h; i++){
            for(int j = 0; j < w; j++){
                if(j == w - 1){
                    System.out.println(ans[i][j]);
                }else{
                    System.out.print(ans[i][j]);
                    System.out.print(" ");
                }
            }
        }
    }
}

Measured memory_bytes: 39664
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
#from itertools import accumulate #list(accumulate(A))

N, M = mi()

if N==M:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
using namespace std;
void output(vector<int> a);
int main(void){
	int n;
	int q;
	int count=0;
	cin >> n;
	
	vector<int> S(n);
	
	for(int i=0 ; i< n; i++){
		cin >> S[i];
	}
	cin >> q;
	vector<int> T(q);
	
	for(int i=0 ; i< q; i++){
		cin >> T[i];
	}
	
	for(int i=0 ; i< q; i++){
		
		for(int j=0 ; j< n; j++){
			if(T[i]==S[j]){
				count++;
				break;
			}
		}
	}
	
	cout << count<< endl;
}

Measured memory_bytes: 1232
#include <bits/stdc++.h>
#define db(x) cout<<x<<" "
#define db1(x) cout<<x<<'\n'
#define db2(x,y) cout<<x<<" "<<y<<'\n'
#define db3(x,y,z) cout<<x<<" "<<y<<" "<<z<<'\n'
#define rep(i,n) for(int i=0;i<(n);++i)
#define repA(i,a,n) for(int i=a;i<=(n);++i)
#define repD(i,a,n) for(int i=a;i>=(n);--i)
#define pair(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define ll  long long int
#define vi vector<ll>
#define pi pair<ll,ll>
#define vpi vector<pair<ll,ll>>
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define mod 1000000007
#define MAX_N 100000
using namespace std;
// int dx[4] = {1,-1,0,0};
// int dy[4] = {0,0,1,-1};

ll get(vector<ll>&arr, int i, int k,vector<vector<ll>>&dp){
    if(i==arr.size() && k==0)
        return 1;
    if(i==arr.size())
        return 0;

    if(dp[i][k]!=-1)
        return dp[i][k];

    ll ans = 0;
    repA(c,0,arr[i]){
        if(k>=c){
            ans+=get(arr,i+1,k-c,dp);
            ans%=mod;
        }
        else
            break;
    }
    return dp[i][k] = ans;
}

void solve(){

    ll n,W;
    cin>>n>>W;

    ll value[n],weight[n];
    rep(i,n)
    cin>>weight[i]>>value[i];

    ll maxVal = n*1000;
    ll dp[n+1][maxVal+1];

    repA(i,0,maxVal){
       dp[1][i]=INT_MAX;
    }

    dp[1][value[0]]=weight[0];
    dp[1][0]=0;

    repA(i,2,n){
        repA(j,0,maxVal){
            dp[i][j] = dp[i-1][j];
            if(value[i-1]<=j){
                dp[i][j]=min(dp[i][j],dp[i-1][j-value[i-1]]+weight[i-1]);
            }
        }
    }

    ll ans = 0;

    repA(i,0,maxVal){
        if(dp[n][i]<=W)
            ans=max(ans,(ll)i);
    }
    db1(ans);
}
int main(){ 

int t=1;
//cin>>t;
while(t--){
 solve();
}
  return 0; 
}





Measured memory_bytes: 78336
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    x = int(readline())
    cnt = x // 11 * 2
    x %= 11
    if x == 0:
        print(cnt)
    elif 1 <= x <= 6:
        print(cnt + 1)
    elif 7 <= x <= 10:
        print(cnt + 2)


if __name__ == '__main__':
    solve()


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

int main(){
  int N;
  cin >> N;
  std::vector<int> a(N);

  for (int i = 0; i < N; i++) {
    cin >> a.at(i);
  }

  if(a.at(0)==1){
    cout << -1 << endl;
    return 0;
  }
  int on=1;
  int cnt=0;

  for(int i = 0 ; i < N ; i++){
    on=a.at(on-1);
    cnt++;
    if(on==2){
      cout << cnt << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}


Measured memory_bytes: 768
N = int(input())
a = list(map(int, input().split()))

a = sorted(a)
i = len(a) - 1
b = []

while (i - 1 >= 0):
	if (a[i] == a[i - 1]):
		b.append(a[i - 1])
		i -= 2

	else:
		i -= 1

	if(len(b) == 2):
		break


if(len(b) == 2):
	print(b[0]*b[1])

else:
	print(0)

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

int main(){
  int a, b;
  cin >> a >> b;
  int ans = 0;
  for (int i = 0; i < 2; i++){
    if (a > b){ ans += a; a--;}
    else { ans += b; b--;}
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
function main(input) {

  let list = input.split("\n")[1].split(' ').map(x => parseInt(x));

  let cnt = 0; // AOJ 提出用

  let flag = true;
  let i = 0;
  while (flag) {
    flag = false;
    for (let j = list.length - 1; j >= i + 1; j--) {
      if (list[j - 1] > list[j]) {
        let a = list[j - 1];
        let b = list[j];
        list[j - 1] = b;
        list[j] = a;
        flag = true;
        cnt++;  // AOJ 提出用
      }
    }
    i++;
  }
  console.log(list.join(" "));
  console.log(cnt);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


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

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

  vector<int> degwer(n);
  for (int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    a--, b--;

    degwer[a]++;
    degwer[b]++;
  }

  bool f = true;
  for (int i = 0; i < n; ++i) {
    if (degwer[i] & 1) f = false;
  }

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


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

int main() {
  long long N; cin >> N;
  string S; cin >> S;
  long long R = 0, G = 0, B = 0;
  long long T = S.size();
  for (long long i = 0; i < T; i++){
    if (S[i] == 'R') R++;
    if (S[i] == 'G') G++;
    if (S[i] == 'B') B++;
  }
  long long count = R * G * B;
  for (long long i = 0; i < N; i++){
    for (long long j = i; j < N; j++){
      if (2 * j - i > N - 1) continue;
      if (S[i] != S[j] && S[i] != S[2 * j - i] && S[j] != S[2 * j - i]) count--;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 3604