akhauriyash/Code-Regression huggingface dataset:
h, w = map(int, input().split())
a_array = [[int(x) for x in input().split()] for x in range(h)]
visited_array = [[False for x in range(w)] for y in range(h)]
root_array = []
for i in range(h):
    if i % 2 == 0:
        for j in range(w):
            root_array.append([i, j])
    if i % 2 == 1:
        for j in reversed(range(w)):
            root_array.append([i, j])
res = []
for n in range(len(root_array)-1):
    i, j = root_array[n]
    next_i, next_j = root_array[n + 1]
    if visited_array[i][j]:
        continue
    visited_array[i][j] = True
    if a_array[i][j] % 2 == 1:
        res.append([i+1, j+1, next_i+1, next_j+1])
        a_array[next_i][next_j] += 1
        a_array[i][j] -= 1

print(len(res))
for root in res:
    print(" ".join([str(x) for x in root]))


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

const int N = 2e5 + 5;

int n, m;
int have[N];
bool can[N];

int main() {
	ios_base::sync_with_stdio(false);
	cin >> n >> m;
	for (int i = 1; i <= n; ++i) have[i] = 1;
	can[1] = 1;
	for (int i = 1; i <= m; ++i) {
		int x, y; cin >> x >> y;
		if (can[x]) can[y] = 1;
		have[x]--, have[y]++;
		if (!have[x]) can[x] = 0;
	}
	int cnt = 0;
	for (int i = 1; i <= n; ++i) cnt += can[i];
	cout << cnt << '\n';
}

Measured memory_bytes: 768
#include <stdio.h>

int main(void)
{
	int r;
	scanf("%d", &r);
	
	if(r < 1200) printf("ABC\n");
	else if (r < 2800) printf("ARC\n");
	else if (r <= 4208) printf("AGC\n");
	
	return (0);
}

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

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'

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

using namespace std;
using ll = long long;
using P = pair<ll, ll>;

//constexpr ll mod = 998244353;
constexpr ll mod = 1e9+7;
const double PI = acos(-1.0);
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());

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

  int n, k; cin >> n >> k;
  string s; cin >> s;
  if (s[k-1] == 'A') s[k-1] = 'a';
  if (s[k-1] == 'B') s[k-1] = 'b';
  if (s[k-1] == 'C') s[k-1] = 'c';

  cout << s << endl;
}

Measured memory_bytes: 256
DICT = { 'm' => 1000, 'c' => 100, 'x' => 10, 'i' => 1 }.freeze

def mcxi_to_digit(s)
  sum = 0
  DICT.each do |k, v|
    if s.include?(k)
      if s[s.index(k)-1] >= '2' and s[s.index(k)-1] <= '9'
        sum += s[s.index(k)-1].to_i * v
      else
        sum += v
      end
    end
  end
  return sum
end

def digit_to_mcxi(n)
  str = ''
  DICT.to_a.map do |k, v|
    val = n/v
    n = n%v
    if val >= 2
      str += "#{val}#{k}"
    elsif val == 1
      str += k
    end
  end
  return str
end

n = gets.to_i
n.times do
  a, b = gets.chomp.split(' ')
  sum = mcxi_to_digit(a) + mcxi_to_digit(b)
  puts digit_to_mcxi(sum)
end

Measured memory_bytes: 6116
#[allow(unused_imports)]
use itertools::Itertools;
#[allow(unused_imports)]
use num::*;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::collections::*;

fn solve() {
    input! {
        n: usize,
        vv: [(isize, isize); n]
    };

    let sum = (0..n)
        .permutations(n)
        .map(|p| {
            p.windows(2)
                .map(|v| {
                    let i = v[0];
                    let j = v[1];
                    let (xi, yi) = vv[i];
                    let (xj, yj) = vv[j];
                    let m = ((xi - xj).pow(2) + (yi - yj).pow(2)) as f64;
                    m.sqrt()
                })
                .sum::<f64>()
        })
        .sum::<f64>();
    let res = sum / (1..=n).into_iter().fold(1, |acc, x| acc * x) as f64;
    println!("{}", res);
}

fn main() {
    std::thread::Builder::new()
        .name("big stack size".into())
        .stack_size(256 * 1024 * 1024)
        .spawn(|| {
            solve();
        })
        .unwrap()
        .join()
        .unwrap();
}


Measured memory_bytes: 2248
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <regex>
#include <set>
#include <cmath>
#include <sstream>
#include <numeric>
#include <set>

using namespace std;

int main()
{
    int a, b;
    std::cin >> a >> b;
    std::cout << (a + b) % 24;

    return EXIT_SUCCESS;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cmath>
#include<algorithm>/*toupperとかが入っている*/
#include<vector>/*可変長配列vectorのインクルード*/
using namespace std;/*標準名前空間を利用する。cinやcoutはこれによって利用可能になる*/

int N;
int C[55];
int V[55];

int main(void) {
  cin >> N;
  for(int i=0; i<N; i++){
    cin >> V[i];
  }
  for(int i=0; i<N; i++){
    cin >> C[i];
  }
  
  int sum=0;
  for(int i=0; i<N; i++){
    if(V[i]>C[i]) sum = sum+V[i]-C[i];
  }

  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <iomanip> //setprecision()
#include <vector>
#include <map>
using ll = long long;
using namespace std;

void monmo(){
    
}

int main() {
    int n;
    for(int i=1;i<=5;i++){
        cin>>n;
        if(n==0){
            cout<<i;
        }
    }
}


Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <set>
#include <cstdint>
#include <numeric>
#define INF 1000000000
#define LLINF 2000000000000000
#define MOD 1000000007
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define LOOP(i,N) for(int i=0;i<N;i++)
#define LOOP1(i,N) for(int i=1;i<=N;i++)
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
#define int long long

signed main(){
  int n;
  string s;
  cin >> n >> s;
  int cs[3][n+1];
  cs[0][n] = cs[1][n] = cs[2][n] = 0;
  LOOP(i,n){
    int a;
    int k = n-i-1;
    if(s[k]=='R') a = 0;
    if(s[k]=='G') a = 1;
    if(s[k]=='B') a = 2;
    // cerr << k << endl;
    LOOP(l,3){
      cs[l][k] = cs[l][k+1];
    }
    // cerr << k << endl;

    cs[a][k]++;
  }

  // cerr << "a";
  int ans = 0;
  if(n<=2){
    cout << 0 << endl;
    return 0;
  }
  LOOP(a,n-1){
    FOR(b,a+1,n){
      if(s[a]==s[b])continue;
      char c = 'R'+'G'+'B' - s[a] - s[b];
      // cerr << c << endl;
      // cerr << b+b-a << " ";
      bool f = false;
      if(b+b-a < n){
        if(s[b+(b-a)] == c) f = true; //cerr << ":";
      }

      if(c=='R') c = 0;
      if(c=='G') c = 1;
      if(c=='B') c = 2;
      ans += cs[c][b];
      if(cs[c][b] && f)ans--;
      // cerr << a << "," << b << endl;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3692
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(){
  long long int a,b,c;
  scanf("%lld",&a);
  scanf("%lld",&b);
  scanf("%lld",&c);
  long long int ans;
  if (a+b+1 >= c) {//all cockies
    ans = c+b;
  } else {
    ans = a+b+1+b;
  }
  printf("%lld\n",ans);
  return 0;
}


Measured memory_bytes: 128
#include <stdio.h>

int main(void){
    int R;
    scanf("%d", &R);
    if(R < 1200){
        printf("%s\n", "ABC");
    }
    else if(R < 2800){
        printf("%s\n", "ARC");
    }
    else printf("%s\n", "AGC");
    return 0; 
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define for1(a,b,i) for(int i=a;i<=b;++i)
#define FOR2(a,b,i) for(int i=a;i>=b;--i)
using namespace std;
typedef long long ll;

#define M 2005
int n;
char a[M][M];
int f[M][M],l[M][M],r[M][M];

int main () {
	//freopen("a.in","r",stdin);
	scanf("%d",&n);
	for1(1,n,i) scanf("%s",a[i]+1);
	
	ll ans=0;
	FOR2(n,1,i) FOR2(n,1,j) 
		if(isdigit(a[i][j])) {
			bool t[2]={isdigit(a[i+1][j]),isdigit(a[i][j+1])};
			if(!t[0]&&!t[1]) {
				l[j][i]=r[j][i]=j;
				for1(i+1,n,k) l[j][k]=n+1,r[j][k]=0;
			}
			else if(!t[0]) {
				f[i][j]=f[i][j+1];
				l[j][i]=j,r[j][i]=r[j+1][i];
				for1(i+1,n,k) l[j][k]=l[j+1][k],r[j][k]=r[j+1][k];
			}
			else if(!t[1]) {
				f[i][j]=f[i+1][j];
				l[j][i]=r[j][i]=j;
			}
			else {
				int las=0;
				int tot=f[i+1][j]+f[i][j+1];
				l[j][i]=j,r[j][i]=r[j+1][i];
				
				for1(i+1,n,k) {
					if(l[j+1][k]<=r[j][k]&&l[j+1][k]>las) tot-=f[k][l[j+1][k]];
					las=max(las,r[j][k]);
					l[j][k]=min(l[j][k],l[j+1][k]);
					r[j][k]=max(r[j][k],r[j+1][k]); 
				}
				f[i][j]=tot;
			}
			ans+=f[i][j]*(a[i][j]-'0');
			f[i][j]+=a[i][j]-'0';
		}
		else l[j][i]=n+1,r[j][i]=0;
	cout<<ans<<endl;
}

Measured memory_bytes: 18176
#include "bits/stdc++.h"
using namespace std;

#define rep(i,a,b) for (int i = (a); i < (b); i++ )

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

	int ans = 0;
	rep(i, 0, 4) {
		if (a.at(i) == '2') {
			ans++;
		}
	}
	cout << ans << endl;
	}

Measured memory_bytes: 256
def main(N):
  
    CP = 4
    DP = 7
    
    if N <= 3:
        return "No"
    
    for i in range(100):
        for j in range(100):
            if (CP * i + DP * j) == N:
                return "Yes"
    return "No"
N = int(input())
print(main(N))

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s; cin>>s;
  int cnta=0, cntb=0;
  for (int i = 0; i < s.size(); i++) {
    if (s.at(i)=='0' && i%2==0) {
      cnta++;
    }
    else if (s.at(i)=='1' && i%2==1) {
      cnta++;
    }
  }
  for (int i = 0; i < s.size(); i++) {
    if (s.at(i)=='1' && i%2 == 0) {
      cntb++;
    }
    else if (s.at(i)=='0' && i%2==1) {
      cntb++;
    } 
  }
  cout<<min(cnta, cntb)<<endl;
}


Measured memory_bytes: 512
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <math.h>
#include <stack>
#include <climits>
#include <bitset>
#include <utility>


using namespace std;
typedef long long ll;

//最小公倍数
ll gcd(ll x, ll y) {
  ll tmp = 0;
  if (x < y){
    tmp=x;
    x=y;
    y=tmp;
  }
  while (y > 0) {
    ll r = x % y;
    x = y;
    y = r;
  }
  return x;
}

//最大公倍数
ll lcm(ll x,ll y){
  return x/gcd(x,y)*y;
}

//階乗
ll kaijo(ll k){
    ll sum = 1;
    for (ll i = 1; i <= k; ++i)
    {
        sum *= i;
        sum%=1000000000+7;
    }
    return sum;
}

//for(int i = ; i < ; i++){}

ll lmax(ll s,ll t){
  if(s>t){
    return s;
  }
  else{
    return t;
  }
}

ll lmin(ll s,ll t){
  if(s<t){
    return s;
  }
  else{
    return t;
  }
}

ll sum;
string s;
int a[4];
bool flag = false;

void func(int i, ll sum, string s){
  if(flag) ;
  else{
    if(i == 3){
      if(sum == 7){
        cout<<s+"=7"<<endl;
        flag = true;
      }
    }
    else{
      func(i+1,sum+a[i+1],s+'+'+to_string(a[i+1]));
      func(i+1,sum-a[i+1],s+'-'+to_string(a[i+1]));
    }
  }
}

int main(){
  string s1;
  cin>>s1;
   for(int i = 0; i < 4; i++){
     a[i]=s1[i]-'0';
   }
  sum=a[0];
  s=to_string(a[0]);
  func(0,sum,s);
  return 0;
}


Measured memory_bytes: 256
n, s = int(raw_input()), raw_input()
h = {'(':+1 , ')':-1}
m = 0
bal = 0
for i in range(len(s)):
	bal += h[s[i]]
	m = min(bal,m)

print '(' *abs(m) + s + ')' * max(0,bal + abs(m))

Measured memory_bytes: 64240
#include<bits/stdc++.h>
#define ll long long int

using namespace std;
int main()
{
    int n;
    cin>>n;
    int a[n];
    int num=0;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        if((i+1)%2==1&&a[i]%2==1)
            num++;
    }

    cout<<num<<endl;
}



Measured memory_bytes: 3584
#include <stdio.h>

int main(void)
{
    int n;
    int m = 100000;
    int i;

    scanf("%d", &n);

    for (i = 0; i < n; i++){
        m *= 1.05;
        m = (m % 1000 == 0 ? m : (m - m % 1000) + 1000);
    }

    printf("%d\n", m);

    return (0);
}

Measured memory_bytes: 592
<?php
list($s) = strs();
for ($i = 0; $i < 26; ++$i) $a2n[chr(97 + $i)] = $i;
if ($s === 'zyxwvutsrqponmlkjihgfedcba') exit('-1');
if (strlen($s) < 26) {
    for ($i = 0; $i < 26; ++$i) {
        if (strpos($s, chr(97 + $i)) === false) {
            echo $s . chr(97 + $i);
            exit;
        }
    }
}
// 26文字の場合
for ($i = 2; $i <= strlen($s); ++$i) {
    $a = str_split(substr($s, -$i));
    $b = $a;
    natsort($b);
    $b = array_values($b);
    if ($a[0] !== $b[count($b) - 1]) {
        foreach ($b as $bb) if ($a2n[$bb] > $a2n[$a[0]]) break;
        echo substr($s, 0, -$i) . $bb;
        exit;
    }
}
function strs()
{
    return explode(' ', trim(fgets(STDIN)));
}


Measured memory_bytes: 16296
#include<iostream>
#include<vector>
using namespace std;
int main(){
    cin.tie(0);
   	ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
    vector<int> d(n);
    for(int i=0; i<n; i++){
        cin >> d[i];
    }
    int t= -1,s=-1,u=-1;

    for(int i=0; i<n-1; i++){
        if(d[i]>d[i+1] && t==-1) t= i; 
        else if(d[i]>d[i+1] && t!=-1 && s==-1) s= i+1; 
        else if(d[i]>d[i+1] && t!=-1 && s!=-1 && u==-1) u= i; 
    }
    cerr << t << s << endl;
    if(u==-1){
        if(t==-1){
            cout << "YES" << endl;
            return 0;
        }
        int p= d[t-1];
        int q= d[s-1];
        int r= d[t+1];
        int ss= d[s+1];
        if(t-1==-1) p=0;
        if(s-1==-1) q=0;
        if(t+1==n) r=99999999;
        if(s+1==n) ss=99999999;
        cerr << p << r << q << s << endl;
        if((p <= d[s] && d[s] <= r) && (q < d[t] && d[t] < ss)) cout << "YES" << endl;
        else cout << "NO" << endl;
    } else {
        cout << "NO" << endl;
    } 


}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <string>

int main(int argc, char* argv[]) {
  std::map<char, char> m = {
      {'A', 'T'},
      {'C', 'G'},
      {'G', 'C'},
      {'T', 'A'},
  };
  char b;
  std::cin >> b;
  std::cout << m[b] << std::endl;
  return 0;
}


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

int main() {
  int N, L;
  cin >> N >> L;
  
  vector<string> S;
  for (int i = 0; i < N; i++) {
    string s;
    cin >> s;
    
    S.push_back(s);
  }
  
  sort(S.begin(), S.end());
  
  for (int i = 0; i < N; i++) {
    cout << S[i];
  }
  cout << endl;
}


Measured memory_bytes: 3612
/*#include <cstdio>

#define MOD 1000000007

#define MAXN 100000

int x[MAXN];

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

    for (int i = 0; i < n; i++)
        scanf("%d", &x[i]);

    int j = 0, ans = 1;
    for (int i = 0; i < n; i++) {
        while (j < n && x[j] >= 2 * (j - i))
            j++;
        ans = 1LL * ans * (j - i) % MOD;
    }

    printf("%d\n", ans);

    return 0;
}*/

#include <cstdio>
#include <algorithm>

#define MAXN 100000

int x[MAXN + 1], p[MAXN + 1];
long long v[MAXN + 1];

int main() {
    int n;
    scanf("%d%d", &n, &x[0]);

    for (int i = 1; i <= n; i++)
        scanf("%d%lld", &x[i], &v[i]);

    int q = n, st = 1, dr = n;
    while (x[st] < x[0] && x[0] < x[dr]) {
        if (v[st] >= v[dr]) {
            p[q] = dr;
            v[st] += v[dr];
            dr--;
        } else {
            p[q] = st;
            v[dr] += v[st];
            st++;
        }
        q--;
    }

    if (x[0] < x[st])
        for (int i = dr; i >= st; i--)
            p[q--] = i;
    else
        for (int i = st; i <= dr; i++)
            p[q--] = i;


    long long ans = 0;
    for (int i = 1; i <= n; i++)
        ans += std::abs(x[p[i]] - x[p[i - 1]]);

    printf("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 1664
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int maxn=5e5+10;
ll a[maxn];

int main()
{
	int n;cin>>n;
	for(int i=0;i<n;i++) cin>>a[i];
	int ans=0;sort(a,a+n);
	for(int i=0;i<n;i++){
		for(int j=i+1;j<n;j++){
			for(int k=j+1;k<n;k++){
				if(a[i]==a[j]||a[i]==a[k]||a[j]==a[k]) continue;
				if(a[i]+a[j]>a[k]) ans++;
			}
		}
	}
	cout<<ans;
	return 0;	
} 

Measured memory_bytes: 3192
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define ll long long
#define pi pair<int,int>
#define pl pair<ll,ll>
#define pd pair<double,double>
#define ld long double
#define pld pair<ld,ld>
#define lg length()
#define sz size()
#define pb push_back
#define INF 1000000005
#define LINF 1000000000000000005

int n,x,y,v[100005];

ll mod,dp[100005],s[100005],q[100005],ps[100005],ss[100005],f;

vector <int> g[100005];


void DFS1(int nod){
    v[nod]=1; dp[nod]=1;
    for(int i : g[nod]){
        if(!v[i]){
            DFS1(i);
            dp[nod]*=(1+dp[i]);
            dp[nod]%=mod;
        }
    }
}

void DFS2(int nod){
    v[nod]=1;
    f=1;
    for(int i : g[nod]){
        if(!v[i]){
            ps[i]=f;
            f*=(1+dp[i]);
            f%=mod;
        }
    }
    reverse(g[nod].begin(),g[nod].end());
    f=1;
    for(int i : g[nod]){
        if(!v[i]){
            ss[i]=f;
            f*=(1+dp[i]);
            f%=mod;
        }
    }
    reverse(g[nod].begin(),g[nod].end());
    for(int i : g[nod]){
        if(!v[i]){
            q[i]=(1+ps[i]*ss[i]%mod*q[nod])%mod;
            s[i]=dp[i]*q[i]%mod;
            DFS2(i);
        }
    }
}

int32_t main(){
    ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();
    cin >> n >> mod;
    for(int i=1;i<n;i++){
        cin >> x >> y;
        g[x].pb(y);
        g[y].pb(x);
    }
    DFS1(1);
    for(int i=1;i<=n;i++) v[i]=0;
    s[1]=dp[1]; q[1]=1;
    DFS2(1);
    for(int i=1;i<=n;i++) cout << s[i] << '\n';
}


Measured memory_bytes: 14336
#include<stdio.h>
using namespace std;
int main(){
    int a, b;
    char op;
 scanf("%d %c %d", &a, &op, &b);
 while(op!='?'){
     int c;
     if(op == '+') c = a + b;
     if(op == '-') c = a - b;
     if(op == '*') c = a * b;
     if(op == '/') c = a / b;
     printf("%d\n", c);
     scanf("%d %c %d", &a, &op, &b);
 }
 return 0;
}


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

using namespace std;

int main()
{
	int n, k;
	cin >> n >> k;
	set<int> d;
	for (int i = 0; i < k; i++)
	{
		int di;
		cin >> di;
		d.insert(di);
	}
	for (int i = n; i < 100*n; i++)
	{
		bool valid = true;
		for (int j = i; j > 0; j /= 10)
		{
			if (d.find(j%10) != d.end())
			{
				valid = false;
				break;
			}
		}
		if (valid)
		{
			cout << i << endl;
			break;
		}
	}

	return 0;
}


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

inline bool is(int a, int b, int c){
	return a+b>c && a!=b && b!=c;
}

int main(void){
	int n;
	cin>>n;
	int arr[n];
	for (int i = 0; i < n; ++i){
		cin>>arr[i];
	}
	sort(arr, arr+n);

	int ans = 0;
	for (int i = 0; i < n; ++i){
		for(int j=i+1; j<n; j++){
			for(int k=j+1; k<n; k++){
				ans += is(arr[i], arr[j], arr[k]);
				// if(is(arr[i], arr[j], arr[k])){
					// cout << i << " " << j << " " << k << endl;
				// }
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3624
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;

int main() {
    int n;
    int k;
    cin >> n >> k;
    int num;
    rep(i, n) {
        int a;
        cin >> a;
        if(a == 1) {
            num = i;
        }
    }

    int ans = n/(k-1);
    if(n%(k-1) > 1) {
        ans++;
    }
    if(k == 2)  {
        ans--;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
from collections import defaultdict

n = int(input())
a = list(map(int, input().split()))

cnt = defaultdict(int)
for num in a:
    for i in [-1, 0, 1]:
        cnt[num + i] += 1
ans = 0
for i in cnt:
    ans = max(cnt[i], ans)
print(ans)

Measured memory_bytes: 20948
#include <bits/stdc++.h>
#define RANGE(i,n) for(int i=0;i<n;i++)
typedef long long ll;

using namespace std;

signed main() {
    int N, K;
    cin >> N;
    vector<char> S(N);
    RANGE(i,N) cin >> S[i];
    cin >> K;

    char target = S[K-1];
    RANGE(i,N){
        if(S[i] == target){}
        else S[i] = '*';
    }

    RANGE(i,N) cout << S[i];
    cout <<  endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cstring>
#include <cstdlib>

using namespace std;

char field[51][51];

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

int w,h;
int bfs(int stx,int sty,int skx,int sky){

	queue<pair<pair<int,int>,pair<int,int> > > *prv=new queue<pair<pair<int,int>,pair<int,int> > >();
	queue<pair<pair<int,int>,pair<int,int> > > *nxt=new queue<pair<pair<int,int>,pair<int,int> > >();
	prv->push(make_pair(make_pair(sty,stx),make_pair(sky,skx)));
	int cnt=1;
	bool passed[51][51][51][51];
	memset(passed,0,sizeof(passed));
	while(prv->size()){
		if(cnt>100)
			return -1;
		while(prv->size()){
			pair<pair<int,int>,pair<int,int> > ppp = prv->front();
			prv->pop();
			pair<int,int> tp=ppp.first;
			pair<int,int> kp=ppp.second;
			if(passed[tp.first][tp.second][kp.first][kp.second]){
				continue;
			}
			passed[tp.first][tp.second][kp.first][kp.second]=true;
			for(int i = 0; i < 4; i++){
				int nky=kp.first+dy[i];
				int nkx=kp.second+dx[i];
				int nty=tp.first-dy[i];
				int ntx=tp.second-dx[i];
				// ©¸ä«ªÍÍOÉoÈ¢ê
				if(nky>=0&&nkx>=0&&nkx<w&&nky<h&&field[nky][nkx]=='0'){
					// ½©ä«ªÍÍOÉoéê
					if(!(nty>=0&&ntx>=0&&ntx<w&&nty<h&&field[nty][ntx]=='0')){
						nxt->push(make_pair(tp,make_pair(nky,nkx)));
						if(tp==make_pair(nky,nkx))
							return cnt;
					}
					else{
						nxt->push(make_pair(make_pair(nty,ntx),make_pair(nky,nkx)));
						if(make_pair(nty,ntx)==make_pair(nky,nkx))
							return cnt;
					}
				}
				// ½©ä«ªÍÍOÉoÈ¢ê
				else if(nty>=0&&ntx>=0&&ntx<w&&nty<h&&field[nty][ntx]=='0'){
					// ©¸ä«ªÍÍOÉoéê
					if(!(nky>=0&&nkx>=0&&nkx<w&&nky<h&&field[nky][nkx]=='0')){
						nxt->push(make_pair(make_pair(nty,ntx),kp));
						if(kp==make_pair(nty,ntx))
							return cnt;
					}
					else{
						nxt->push(make_pair(make_pair(nty,ntx),make_pair(nky,nkx)));
						if(make_pair(nty,ntx)==make_pair(nky,nkx))
							return cnt;
					}
				}
			}
		}
		cnt++;
		swap(prv,nxt);
	}
	return -1;
}

int main(){

	while(cin>>w>>h&&!(w==0&&h==0)){
		int ty,tx,kx,ky;
		cin>>tx>>ty>>kx>>ky;
		ty--;
		tx--;
		kx--;
		ky--;
		for(int i = 0; i < h; i++){
			for(int j= 0; j < w; j++){
				cin>>field[i][j];
			}
		}

		int ret=bfs(tx,ty,kx,ky);
		if(ret==-1)
			cout<<"NA"<<endl;
		else
			cout<<ret<<endl;
	}

	return 0;
}

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

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n),b(n);
  vector<ll> dif(n);
  ll asum=0,bsum=0;
  rep(i,n){
    cin >> a[i];
    asum += a[i];
  }
  rep(i,n){
    cin >> b[i];
    bsum += b[i];
  }
  
  if(asum < bsum){
    cout << "-1" << endl;
    return(0);
  }
  
  ll ans=0;
  ll need=0;
  vector<ll> c(n);
  rep(i,n){
    c[i] = a[i] - b[i];
    if(c[i] < 0){
      ans++;
      need += c[i];
    }
  }
  
  sort(c.begin(),c.end());
  reverse(c.begin(),c.end());
  
  ll i=0;
  while(need < 0){
    need += c[i];
    ans++;
    i++;
  }
  
  cout << ans << endl;
  
  return(0);
}

Measured memory_bytes: 6396
import java.util.*;
import java.awt.geom.*;
import java.io.*;
public class Main{
	int [][] dp;
	int MAX = 1120;
	int K= 14;
	boolean [] isprime;
	
	private void doit(){
		Scanner sc = new Scanner(System.in);
		
		isprime = new boolean[MAX + 1];
		eratos();
		
		dp = new int[K + 1][MAX + 1];
		dp();
		while(true){
			int n = sc.nextInt();
			int k = sc.nextInt();
			if((n|k) == 0) break;
			int ans = dp[k][n];
			//System.out.print("ANS = ");
			System.out.println(ans);
		}
		//debug
//		for(int i = 0; i < 30; i++){
//			System.out.println("i = " + i + "value= " + dp[1][i] + " "+ dp[2][i] + " dp3 = " + dp[3][i] + " dp4 = " + dp[4][i]);
//		}
	}

	private void dp() {
		//init
		for(int i = 1; i <= MAX; i++){
			dp[1][i] = isprime[i] ? 1 : 0;
		}
		
		for(int i = MAX; i >= 2; i--){
			if(! isprime[i]) continue;
			//for(int j = i; j <= MAX; j++){
			for(int j = MAX; j >= i; j--){
				for(int k = K - 1; k  >= 1; k--){
					if(k == 1 && j == i) continue;
					if(j + i > MAX) continue;
					dp[k+1][j + i] += dp[k][j];
//					if(j + i == 8 && k == 2){
//						System.out.println("debug=  " + i + " " + j  + " " + k + " " + dp[k][j]);
//					}
				}
			}
			
//			for(int j = i; j >= 2; j--){
//			for(int k = 1; k < K; k++){
//				if(k == 1 && j == i) continue;
//				if(j + i > MAX) continue;
//				dp[k + 1][j + i] += dp[k][j]; 
//				if(k == 2 && j == 5 && i == 5){
//					System.out.println("test");
//					System.out.println((j + i) + " " + dp[k][j]);
//				}
//			}
//		}
			// 2, 3 , 5
			//[0][5] => [1][5] = 1にする
			//[2][5] => [3][5 + 5] = 1にする
		}
	}

	private void eratos() {
		Arrays.fill(isprime, true);
		isprime[0] = false;
		isprime[1] = false;
		for(int i = 2; i * i <= MAX; i++){
			if(isprime[i]){
				for(int j = i * 2; j <= MAX; j+= i){
					isprime[j] = false;
				}
			}
		}
		
	}

	public static void main(String [] args){
		new Main().doit();
	}
}

Measured memory_bytes: 12000
import math
import re

n = int(raw_input())
a = raw_input().split()

cnt = 0
minus = 0
b = []
for i in a:
    a[cnt] = int(i)
    b.append(abs(int(i)))
    if a[cnt] < 0:
        minus += 1
    cnt += 1


if minus % 2 != 0:
    mini = min(b)
else:
    mini = 0

total = 0
for i in b:
    total += abs(i)

total -= 2 * abs(mini)
print total

Measured memory_bytes: 9784
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <numeric>
#include <string.h>
using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long  INFL = 1e18;
const int MOD = 1000000007;
int num, k;

void solve() {
	int max_num = -INF;
	int min_num = INF;
	for (int i = 0; i < 5; ++i) {
		cin >> num;
		max_num = max(max_num , num);
		min_num = min(min_num , num);
	}
	cin >> k;
	if (max_num - min_num <= k) {
		cout << "Yay!" << endl;
	} else {
		cout << ":(" << endl;
	}
	return;
}

int main(int args, char* argv[]) {
	solve();
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define fcout(d) cout << fixed << setprecision(d)
#define repU(i,s,t) for(int i = (int)(s); i <= (int)(t); ++i)
#define repD(i,t,s) for(int i = (int)(t); i >= (int)(s); --i)
#define rep(i,n) repU(i,0,n - 1)
#define rep1(i,n) repU(i,1,n)
#define all(v) begin(v),end(v)
#define vct vector
#define prique priority_queue
#define l_bnd lower_bound
#define u_bnd upper_bound
#define puf push_front
#define pub push_back
#define pof pop_front
#define pob pop_back
#define mkp make_pair
#define mkt make_tuple
#define fir first
#define sec second
#define qceil(n,d) ((n) > 0 ? ((n) - 1) / (d) + 1 : (n) / (d))
#define parity(a,b) (a & 1 == b & 1)

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair<int,int> pii;

const pii dir[] = { {1,0},{0,1},{-1,0},{0,-1},{1,1},{-1,1},{-1,-1},{1,-1} };
const int inf32 = (1 << 30) - 1;
const ll inf64 = (1LL << 62) - 1;
const int mod = 1e9 + 7;

void fail(){
	cout << -1 << endl;
}

int K,A[100100];
ll N[2][2];

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	cin >> K;
	A[0] = 1;
	rep1(i,K) cin >> A[i];
	if(A[K] != 2) fail(),exit(0);
	N[0][0] = N[0][1] = 2;
	int t = 0;
	repD(g,K - 1,0){
		ll l = N[t][0],r = N[t][1] + A[g + 1] - 1;
		t = 1 - t;
		N[t][0] = qceil(l,A[g]) * A[g];
		N[t][1] = r / A[g] * A[g];
		if(N[t][0] > N[t][1]) fail(),exit(0);
	}
	cout << N[t][0] << ' ' << N[t][1] << endl;
}



Measured memory_bytes: 640
N, Q = map(int, input().split())
S = input()
ac = [0] * (N + 1)
ans = []
for i in range(N):
    ac[i + 1] = ac[i] + (1 if S[i:i+2] == "AC" else 0)
for _ in range(Q):
    l, r = map(int, input().split())
    ans.append(ac[r - 1] - ac[l - 1])
for i in range(Q):
    print(ans[i])


Measured memory_bytes: 82068
#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
void debug() { cerr << "\n"; }
template <class T> void debug(const T &x) { cerr << x << "\n"; }
template <class T, class... Args> void debug(const T &x, const Args &... args) {
    cerr << x << " ";
    debug(args...);
}
template <class T> void debugVector(const vector<T> &v) {
    for(const T &x : v) {
        cerr << x << " ";
    }
    cerr << "\n";
}
using ll = long long;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
constexpr int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

template <int mod> struct ModInt {
    int x;

    ModInt() : x(0) {}

    ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}

    ModInt &operator+=(const ModInt &p) {
        if((x += p.x) >= mod)
            x -= mod;
        return *this;
    }

    ModInt &operator-=(const ModInt &p) {
        if((x += mod - p.x) >= mod)
            x -= mod;
        return *this;
    }

    ModInt &operator*=(const ModInt &p) {
        x = (int)(1LL * x * p.x % mod);
        return *this;
    }

    ModInt &operator/=(const ModInt &p) {
        *this *= p.inverse();
        return *this;
    }

    ModInt operator-() const { return ModInt(-x); }

    ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }

    ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }

    ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }

    ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }

    bool operator==(const ModInt &p) const { return x == p.x; }

    bool operator!=(const ModInt &p) const { return x != p.x; }

    ModInt inverse() const {
        int a = x, b = mod, u = 1, v = 0, t;
        while(b > 0) {
            t = a / b;
            swap(a -= t * b, b);
            swap(u -= t * v, v);
        }
        return ModInt(u);
    }

    ModInt pow(int64_t n) const {
        ModInt ret(1), mul(x);
        while(n > 0) {
            if(n & 1)
                ret *= mul;
            mul *= mul;
            n >>= 1;
        }
        return ret;
    }

    friend ostream &operator<<(ostream &os, const ModInt &p) {
        return os << p.x;
    }

    friend istream &operator>>(istream &is, ModInt &a) {
        int64_t t;
        is >> t;
        a = ModInt<mod>(t);
        return (is);
    }

    static int get_mod() { return mod; }
};

using mint = ModInt<MOD>;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    mint N, K;
    cin >> N >> K;
    auto f = [&](mint a) {
        return (mint(-2) * a * a * a + mint(3) * N * a * a +
                (mint(3) * N + 2) * a) /
               6;
    };
    cout << f(N + 1) - f(K - 1) + (N + 1 - K + 1) << endl;
}

Measured memory_bytes: 3620
#include<stdio.h>
#define MAX 2147483647

int dp[100][100],num[101];

int rensa(int);

int main(){
  int n,i,j;
  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d%d",num+i,num+i+1);
  printf("%d\n",rensa(n));  
  return 0;
}

int rensa(int n){
  int i,j,k,l,min;
  for(i=0;i<n;i++) dp[i][i]=0;
  
  for(l=1;l<n;l++){
    for(i=0;i<n-l;i++){
      j=i+l;
      dp[i][j]=MAX;
      for(k=i;k<j;k++){
        min=dp[i][k]+dp[k+1][j]+num[i]*num[k+1]*num[j+1];
        if(dp[i][j]>min) dp[i][j]=min;
      }
    }
  }
  return dp[0][n-1];
}


Measured memory_bytes: 2112
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	int snu[105]={1},n,k,tmp,l,count=0;
	cin>>n>>k;
	for(int i=0;i<k;i++){
		cin>>tmp;
		for(int j=0;j<tmp;j++){
			cin>>l;
			snu[l]++;
		}
	}
	for(int i=0;i<=n;i++){
		if(!snu[i])count++;
	}
	cout<<count;
	return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
#define degreeToRadian(deg) (((deg)/360)*2*M_PI)
#define radianTodegree(rad) (((rad)/2/M_PI)*360)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;
using P = pair<int,int>;
using ll = long long;
const ll INF = 1LL<<60;
const int MOD = 1e9 + 7;

//cin.tie(0);ios::sync_with_stdio(false);
//cout << fixed << setprecision(15) << y << endl;
int main() {
  string n;
  cin >> n;

  ll sum = 0;
  for (ll i = 0; i < n.size(); i++) {
    sum += n[i] - '0';
  }

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


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

public class Main{

    static ArrayList<ArrayList<Integer>> edges=new ArrayList<>();
    static boolean did[];
    
    static int ans=0;
    static int n;
    
    public static void main(String agrs[]) throws IOException{
	BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

	String str[]=br.readLine().split(" ");

	n=Integer.parseInt(str[0]);
	int m=Integer.parseInt(str[1]);

	did=new boolean[n];


	for(int i=0;i<n;i++){
	    edges.add(new ArrayList<>());
	}
	
	for(int i=0;i<m;i++){
	    str=br.readLine().split(" ");

	    int a=Integer.parseInt(str[0])-1;
	    int b=Integer.parseInt(str[1])-1;

	    edges.get(a).add(b);
	    edges.get(b).add(a);
	}

	did[0]=true;
	dfs(0,n);
	System.out.println(ans);
    }

    static void dfs(int s,int a){
	if(a==1){
	    ans++;
	    return;
	}

        for(Integer i:edges.get(s)){
	    if(!did[i]){
		did[i]=true;
		dfs(i,a-1);
		did[i]=false;
	    }
	}
    }
}


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

using namespace std;

#define int long long
int const maxn = 2e5 + 5;
vector < int > g[maxn];
int a[maxn], ans[maxn], sz[maxn], link[maxn], go[maxn];
unordered_map < int, int > cnt[maxn], add;

void dfs(int v, int p) {
    int to = -1;
    sz[v] = 1;
    for (auto u : g[v]) {
        if (u == p) continue;
        dfs(u, v);
        if (to == -1 || (int)cnt[link[u]].size() > (int)cnt[link[to]].size()) to = u;
        sz[v] += sz[u];
    }
    if (to == -1) {
        link[v] = v;
    }
    else {
        link[v] = link[to];
        int sum = sz[to] - cnt[link[to]][a[v]];
        for (auto u : g[v]) {
            if (u == p || u == to) continue;
            for (auto key : cnt[link[u]]) cnt[link[v]][key.first] += key.second;
            ans[a[v]] += sum * (sz[u] - cnt[link[u]][a[v]]);
            sum += (sz[u] - cnt[link[u]][a[v]]);
        }
    }
    ans[a[v]] += (sz[v] - cnt[link[v]][a[v]]) * (go[a[v]] - (sz[v] - cnt[link[v]][a[v]]) + 1);
    go[a[v]] -= (sz[v] - cnt[link[v]][a[v]]);
    cnt[link[v]][a[v]] = sz[v];
}

main() {
#ifdef HOME
    freopen("input.txt", "r", stdin);
#endif // HOME
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, u, v;
    cin >> n;
    for (int i = 1; i <= n; ++i) go[i] = n;
    for (int i = 1; i <= n; ++i) cin >> a[i];
    for (int i = 1; i < n; ++i) {
        cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    dfs(1, 0);
    for (int i = 1; i <= n; ++i) cout << ans[i] << '\n';
    return 0;
}



Measured memory_bytes: 74460
N,K=map(int,input().split())
X=list(map(int,input().split()))
if K==1 and 0 in X:
    print(0)
    exit()
if 0 in X:
    K-=1
left=sorted([i for i in X if i<0],reverse=True)
right=[i for i in X if i>0]

lst=set()
for l,L in enumerate(left):
    i=K-(l+1)-1
    if i>=0:
        if i<len(right):
            lst.add(right[i]-L*2)
    else:
        lst.add(-L)

for l,R in enumerate(right):
    i=K-(l+1)-1
    if i>=0:
        if i<len(left):
            lst.add(R*2-left[i])
    else:
        lst.add(R)

print(min(list(lst)))


Measured memory_bytes: 67804
#include <stdio.h>
#include <iostream>
#include <vector>
#include <list>
#include <cmath>
#include <fstream>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <iterator>
#include <cstdlib>
#include <cstring>
#include <sstream>

using namespace std;

#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) (EQ((a).real(),(b).real()) && EQ((a).imag(),(b).imag()))

typedef complex<double> P;
typedef long long ll;

struct edge{
    int to;
    char ch;
};

vector<edge> G[2][4000];
// dp[i][j]->m[gÌm[hði,m[gÌRs[Ìm[hðjÆµ½Æ«A»±ÜÅÉ¤ÊµÄ»êé¶ÍÌ
int dp[3600][3600];
int n[2],m[2];

const int INF=-1;
const int MOD=1000000007;

int dfs(int idx1,int idx2){
    if(dp[idx1][idx2]!=-1)
        return dp[idx1][idx2];
    if(idx1==0&&idx2==0)
        return 1;
    else if(idx1==0||idx2==0){
        return 0;
    }
    // »ÝÌn_É¢½é[gð·×Ä²×ã°é
    // ßèûÌgÝí¹ðXgAbvµA·×Ä²×é
    int res=0;
    for(int i = 0; i < G[0][idx1].size(); i++){
        edge back=G[0][idx1][i];
        for(int j = 0; j < G[1][idx2].size(); j++){
            edge back2=G[1][idx2][j];
            if(back.ch==back2.ch){
                res+=dfs(back.to,back2.to);
                res%=MOD;
            }
        }
    }
    return dp[idx1][idx2]=res%MOD;
}

int main(){

    int t;
    cin>>t;
    while(t--){
        //memset(dp,0,sizeof(dp));
        for(int i = 0; i < 3600; i++)
            fill(dp[i],dp[i]+3600,INF);
        for(int j = 0; j < 2; j++)
            for(int i = 0; i < 4000; i++)
                G[j][i].clear();
        for(int j = 0; j < 2; j++){
            cin>>n[j]>>m[j];
            int idx=n[j];
            for(int i = 0; i < m[j]; i++){
                int from,to;
                string str;
                cin>>from>>to>>str;
                // ¶ñðª£µÄ»ê¼êÉidðÂ¯ÄGÉi[·é
                int prv=from;
                for(int k = 0; k < str.size(); k++){
                    edge e;
                    e.to=prv;
                    e.ch=str[k];
                    int tmp=idx;
                    if(k==str.size()-1){
                        tmp=to;
                    }
                    G[j][tmp].push_back(e);
                    prv=tmp;
                    if(k==str.size()-1)
                        break;
                    idx++;
                }
            }
        }
        // »ÄAÅ¦ã°
        int res=dfs(n[0]-1,n[1]-1);
        cout<<res%MOD<<endl;
    }

    return 0;
}

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

#define _GLIBCXX_DEBUG

//vector<int> A(M), B(M);
//vector<vector<char>> answer(N, vector<char>(N, '-'));

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

Measured memory_bytes: 3612
function main(input) {
    const args = input.split(' ');
    const N = parseInt(args[0], 10),
          Y = parseInt(args[1], 10);

    var result = '-1 -1 -1';

    for (var a = 0; a <= N; a++) {
        for (var b = 0; b <= N; b++) {
            if ((a + b) > N) {
                continue;
            }

            var sum = (a * 10000) + (b * 5000) + ((N - a - b) * 1000);
            if (sum === Y) {
                result = `${a} ${b} ${N - a - b}`;
                break;
            }
        }        
    }

    console.log(result);

}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7628
#include<bits/stdc++.h>
#define LL long long
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
using namespace std;
inline int read(){
	int v=0,f=1;
	char c=getchar();
	while (c<'0' || c>'9'){
		if (c=='-') f=-1;
		c=getchar();
	}
	while (c>='0' && c<='9'){
		v=v*10+c-'0';
		c=getchar();
	}
	return v*f;
}
const int Maxn=300005;
const int mod=1e9+7;
char s[Maxn];
int dp[Maxn][2][2][2][2][2],n;
void Add(int &x,int y){
	x+=y;
	if (x>=mod) x-=mod;
}
bool Match(char c,int v){
	if (c=='?') return true;
	return (c-'0')==v;
}
int main(){
	scanf("%s",s);
	n=strlen(s);
	for (int i=0;i<2;i++){
		if (Match(s[0],i)){
			dp[0][i][i][i^1][0][i^1]=1;
		} 
	}
	for (int i=0;i<n-1;i++){
		for (int f1=0;f1<2;f1++){
			for (int f2=0;f2<2;f2++){
				for (int f3=0;f3<2;f3++){
					for (int f4=0;f4<2;f4++){
						for (int f5=0;f5<2;f5++){
							if (dp[i][f1][f2][f3][f4][f5]){
								for (int v=0;v<2;v++){
									if (Match(s[i+1],v)){
										int nf5;
										if (v==0)nf5=f5^1;
										else nf5=0;
										int nf3=(v==0)?f3:f3^f5^1;
										Add(dp[i+1][v][f2|(v==1 && f1==1 && f3)][nf3][f4|(f2&&v==1&&f1==1&&!f3)][nf5],dp[i][f1][f2][f3][f4][f5]);
									}
								}
							}
						}
						
					}
				}
			}
		}
	}
	int ans=0;
	for (int i=0;i<2;i++){
		for (int j=0;j<2;j++){
			for (int k=0;k<2;k++){
				for (int f=0;f<2;f++){
					for (int l=0;l<2;l++){
						if (f){
							Add(ans,dp[n-1][i][j][k][f][l]);
							continue;
						}
						if (i && j && !k){
							Add(ans,dp[n-1][i][j][k][f][l]);
							continue;
						}
					}
					
				}
			}
		}
	}
	printf("%d\n",ans);
	return 0;
}
/*
101
*/

Measured memory_bytes: 38016
//start of jonathanirvings' template v3.0.3 (BETA)

#include <bits/stdc++.h>
using namespace std;

typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
typedef pair<string,string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<LL> vl;
typedef vector<vl> vvl;

double EPS = 1e-9;
int INF = 1000000005;
long long INFF = 1000000000000000005LL;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};

#ifdef TESTING
  #define DEBUG fprintf(stderr,"====TESTING====\n")
  #define VALUE(x) cerr << "The value of " << #x << " is " << x << endl
  #define debug(...) fprintf(stderr, __VA_ARGS__)
#else
  #define DEBUG 
  #define VALUE(x)
  #define debug(...)
#endif

#define FOR(a,b,c) for (int (a)=(b);(a)<(c);++(a))
#define FORN(a,b,c) for (int (a)=(b);(a)<=(c);++(a))
#define FORD(a,b,c) for (int (a)=(b);(a)>=(c);--(a))
#define FORSQ(a,b,c) for (int (a)=(b);(a)*(a)<=(c);++(a))
#define FORC(a,b,c) for (char (a)=(b);(a)<=(c);++(a))
#define FOREACH(a,b) for (auto &(a) : (b))
#define REP(i,n) FOR(i,0,n)
#define REPN(i,n) FORN(i,1,n)
#define MAX(a,b) a = max(a,b)
#define MIN(a,b) a = min(a,b)
#define SQR(x) ((LL)(x) * (x))
#define RESET(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ALL(v) v.begin(),v.end()
#define ALLA(arr,sz) arr,arr+sz
#define SIZE(v) (int)v.size()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr,sz) sort(ALLA(arr,sz))
#define REVERSEA(arr,sz) reverse(ALLA(arr,sz))
#define PERMUTE next_permutation
#define TC(t) while(t--)

inline string IntToString(LL a){
  char x[100];
  sprintf(x,"%lld",a); string s = x;
  return s;
}

inline LL StringToInt(string a){
  char x[100]; LL res;
  strcpy(x,a.c_str()); sscanf(x,"%lld",&res);
  return res;
}

inline string GetString(void){
  char x[1000005];
  scanf("%s",x); string s = x;
  return s;
}

inline string uppercase(string s){
  int n = SIZE(s); 
  REP(i,n) if (s[i] >= 'a' && s[i] <= 'z') s[i] = s[i] - 'a' + 'A';
  return s;
}

inline string lowercase(string s){
  int n = SIZE(s); 
  REP(i,n) if (s[i] >= 'A' && s[i] <= 'Z') s[i] = s[i] - 'A' + 'a';
  return s;
}

inline void OPEN (string s) {
  #ifndef TESTING
  freopen ((s + ".in").c_str (), "r", stdin);
  freopen ((s + ".out").c_str (), "w", stdout);
  #endif
}

//end of jonathanirvings' template v3.0.3 (BETA)

int n,m;
vii adj[100005];
int l,r,d;
LL risan[100005];
bool sudah[100005];

void dfs(int now, LL x)
{
  if (sudah[now])
  {
    if (x != risan[now]) 
    {
      puts("No");
      exit(0);
    }
    return;
  }
  risan[now] = x;
  sudah[now] = 1;
  REP(i,SIZE(adj[now]))
  {
    dfs(adj[now][i].fi,x + adj[now][i].se);
  }
}

int main()
{
  scanf("%d %d",&n,&m);
  TC(m)
  {
    scanf("%d %d %d",&l,&r,&d);
    adj[l].pb(mp(r,d));
    adj[r].pb(mp(l,-d));
  }
  FORN(i,1,n) if (!sudah[i])
  {
    dfs(i,0);
  }
  pll ujung = mp(INFF,-INFF);
  REPN(i,n)
  {
    MIN(ujung.fi,risan[i]);
    MAX(ujung.se,risan[i]);
  }
  puts(ujung.se - ujung.fi <= 1000000000 ? "Yes" : "No");
  return 0;
}











Measured memory_bytes: 12416
#include<iostream>
#include<cstdio>

using namespace std;

int main(){
	int i,j;

	for(i=1;i<10;i++){
		for(j=1;j<10;j++){
			printf("%dx%d=%d\n", i, j, i*j);
		}
	}

    return 0;
}

Measured memory_bytes: 1096
import java.util.Scanner;

public class Main {
static Scanner s = new Scanner(System.in);
	public static void main(String[] args) {

		int n = s.nextInt();
		int m = s.nextInt();
		
		int sum =0;
		 if(n==1) {
			 sum+=0;
		 }
		 else
			 sum+=((n)*(n-1))/2;
		 
		 if(m==1)
			 sum+=0;
		 else
			 sum+=((m)*(m-1))/2;
		 
		 System.out.println(sum);

	}

}


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

using namespace std;
bool ishuiwen(string s)
{
    int n=s.length();
    for(int i=0;i<n/2;i++)
    {
        if(s[i]!=s[n-i-1])return false;
    }
    return true;
}
bool is(string s)
{
    if((int)s.length()%2==0)return false;
    int n=s.length();
    string t1="" ,t2="";
    for(int i=0;i<(n-1)/2;i++)
    {
        t1+=s[i];
    }
    for(int i=(n+1)/2;i<n;i++)
    {
        t2+=s[i];
    }
    if(ishuiwen(s)&&ishuiwen(t1)&&ishuiwen(t2))return true;
    else return false;
}
int main()
{
    string s;
    cin>>s;
    if(is(s))printf("Yes");
    else printf("No");
    return 0;
}

Measured memory_bytes: 256
n = int(input())
a = input().split()
b = input().split()

a = [int(i) for i in a]
b = [int(i) for i in b]

e = 0
for i in range(n):
        t = a[i] - b[i]
        if (t >= 0):
            e += b[i]
        else:
            e += a[i]
            t = abs(t)
            t2 = a[i+1] - t
            if (t2 >= 0):
                e += t
                a[i+1] -= t
            else:
                e += a[i+1]
                a[i+1] = 0

print(e)

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

public class Main{
  public static void main(String[] args)throws Exception{
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    try{
      String S = br.readLine();
      boolean f = S.charAt(0) == '7' || S.charAt(1) == '7' || S.charAt(2) == '7';
      System.out.println(f ? "Yes" : "No");
    }catch(Exception e){
    }
  }
}

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

int main(){
  int ans = 0, tmp = 10;
  vector<int> a(5);
  for(int i = 0; i < 5; i++){
    int b; cin >> b;
    a.at(i) = b;
    if(b % 10 == 0) ans += b;
    else{
      ans += (b / 10 + 1)*10;
      tmp = min(tmp, b % 10);
    }
  }
  if(tmp == 10) cout << ans << endl;
  else cout << ans - 10 + tmp << endl;
}
      

Measured memory_bytes: 256
//include,namespace
 #include<bits/stdc++.h>
#include<iostream> 
#include <queue>
#include <vector>
#include <string>
 using namespace std;
//REPmacro
 #define all(x) (x).begin(),(x).end()             //ソート
 #define FOR(i,x,n)for(int i=(x);i<(n);i++)
 #define FOR_R(i,x,n) for(int i=(n-1);i>=(x);i--)
 #define REP(i, n) FOR(i, 0, n)
 #define REP_R(i, n) FOR_R(i, 0, n)
//long long(define)
 using ll = long long;
 typedef long long ll;
 typedef long long int64;
 typedef long long lint;
 typedef long long lli;
////////////////いろいろあるよ//////////////////////////////////
 
int main(){
  int N;
  cin >> N;
  int data[N];
  REP(i,N){
    cin >> data[i];
  }
  sort(data,data+N);
  long long ans=100000000;
  REP(i,data[N-1]){
    int sum=0;
  	REP(j,N)sum	+= (data[j]-i-1)*(data[j]-i-1);
  	if(sum<ans)ans=sum;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256