akhauriyash/Code-Regression huggingface dataset:
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

typedef long double ld;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const long long infll = (long long) 1.01e18;
const ld eps = 1e-9;
const ld pi = acos((ld) -1);

mt19937 mrand(random_device{} ()); 

int rnd(int x) {
  return mrand() % x;
}

void precalc() {
}

const int maxn = (int) 2e5 + 5;
int n;
int a[maxn];

int read() {
  if (scanf("%d", &n) < 1) {
    return false;
  }
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  return true;
}

void solve() {
  if (a[0]) {
    printf("-1\n");
    return;
  }
  for (int i = 0; i + 1 < n; i++) {
    if (a[i] + 1 < a[i + 1]) {
      printf("-1\n");
      return;
    }
  }
  long long res = 0;
  int cur = 0;
  for (int i = n - 1; i >= 0; i--) {
    cur = max(0, cur - 1);
    if (a[i] != cur) {
      assert(a[i] > cur);
      res += a[i];
      cur = a[i];
    }
  }
  printf("%lld\n", res);
}

int main() {
  precalc();
#ifdef DEBUG
  assert(freopen(TASK ".in", "r", stdin));
  assert(freopen(TASK ".out", "w", stdout));
#endif
  while (read()) {
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}


Measured memory_bytes: 1152
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

now = sum(b)
j = len(b)
while j > 0 and now > k:
    j -= 1
    now -= b[j]
ans = j
for i, ai in enumerate(a, 1):
    now += ai
    while j > 0 and now > k:
        j -= 1
        now -= b[j]
    if now > k:
        break
    ans = max(ans, i + j)
print(ans)


Measured memory_bytes: 118528
#include <stdio.h>
int main(){
    int N, i;
    scanf("%d", &N);
    double x;
    double sum=0;
    char u[3];
    for(i=0;i<N;i++){
        scanf("%lf %s", &x, u);
        if(u[0] == 'J'){
            sum += x;
        }
        else{
            sum += x*380000;
        }
    }
    printf("%lf\n", sum);
    return 0;
}

Measured memory_bytes: 128
H,W,K = gets.split.map &:to_i
x1,y1,x2,y2 = gets.split.map{|s| s.to_i - 1}
Map = H.times.map{ gets.chars.map{|s| s=='.'}}

INF = 10**10
Cost = Array.new(H){[INF]*W}

q = [[x1,y1,0]]
Cost[x1][y1] = 0

while xyc = q.shift
    #p xyc
    x,y,c = xyc
    if x==x2 && y==y2 then
        puts c
        exit
    end

    nc = c+1

    1.upto(K) do |i|
        nx = x - i
        break if nx<0 || !Map[nx][y] || Cost[nx][y]<=c
        if nc < Cost[nx][y] then
            Cost[nx][y] = nc
            q << [nx,y,nc]
        end
    end

    1.upto(K) do |i|
        nx = x + i
        break if H<=nx || !Map[nx][y] || Cost[nx][y]<=c
        if nc < Cost[nx][y] then
            Cost[nx][y] = nc
            q << [nx,y,nc]
        end
    end

    1.upto(K) do |i|
        ny = y - i
        break if ny<0 || !Map[x][ny] || Cost[x][ny]<=c
        if nc < Cost[x][ny] then
            Cost[x][ny] = nc
            q << [x,ny,nc]
        end
    end

    1.upto(K) do |i|
        ny = y + i
        break if W<=ny || !Map[x][ny] || Cost[x][ny]<=c
        if nc < Cost[x][ny] then
            Cost[x][ny] = nc
            q << [x,ny,nc]
        end
    end
end

puts -1

Measured memory_bytes: 111992
#include <bits/stdc++.h>
 
using namespace std;
 
int main()
{
    long N;
    cin >> N;
    vector<char> base{'z','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y'};
    vector<char> answer;
    while (N > 0)
    {
        char po = base.at(N%26);
        answer.push_back(po);
        N = (N-1)/26;
    }
    for (long i = answer.size()-1; i >= 0; i--)
    {
        cout << answer.at(i);
    }
}

Measured memory_bytes: 3628
#include<stdio.h>
int main()
{  int n,a[100],i,j,s,min,t;
   scanf("%d",&n);
   for(i=0;i<n;i++)
   scanf("%d",&a[i]);
   for(i=0;i<n-1;i++)
   for(j=0;j<n-1-i;j++)
   if(a[j]>a[j+1])
   {  t=a[j];
      a[j]=a[j+1];
      a[j+1]=t;
   }
   for(i=a[0];i<=a[n-1];i++)
   {  s=0;
      for(j=0;j<n;j++)
      s=s+(a[j]-i)*(a[j]-i);
      if(i==a[0]) min=s;
      if(s<min) min=s;
   }
   printf("%d",min);
} 

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
	char c;
	cin >> c;
	if (c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o') {
		cout << "vowel" << endl;
	}
	else {
		cout << "consonant" << endl;
	}
}

Measured memory_bytes: 3600
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<climits>
#include<numeric>
#include<cmath>
#include<cstring>
#include<deque>
#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define VSORT(v) sort(v.begin(), v.end());
#define VE vector<int>
#define VEP vector<pair<int,int>>
#define llong long long
#define pb(a) push_back(a)
using namespace std;
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}
int main() {
	int k, x;
	cin >> k >> x;
	for (int i = x - k + 1; i < k + x; ++i) {
		cout << i << " ";
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

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

        while (!(line = br.readLine()).equals("0 0")) {
            int n, m, l, taro_sum, hana_sum;
            n = Integer.parseInt(line.substring(0, line.indexOf(' ')));
            m = Integer.parseInt(line.substring(line.indexOf(' ') + 1));
            taro_sum = hana_sum = 0;
            boolean[] taro = new boolean[101];
            boolean[] hana = new boolean[101];

            for (int i = 0; i < n; i++) {
                l = Integer.parseInt(br.readLine());
                taro[l] = true;
                taro_sum += l;
            }
            for (int i = 0; i < m; i++) {
                l = Integer.parseInt(br.readLine());
                hana[l] = true;
                hana_sum += l;
            }

            boolean hit = false;
            if (Math.abs(taro_sum - hana_sum) % 2 == 0) {
                if (taro_sum < hana_sum) {
                    for (int i = 0, j = (hana_sum - taro_sum) / 2; j < 101; i++, j++) {
                        if (taro[i] && hana[j]) {
                            System.out.println(i + " " + j);
                            hit = true;
                            break;
                        }
                    }
                } else if (taro_sum > hana_sum) {
                    for (int i = (taro_sum - hana_sum) / 2, j = 0; i < 101; i++, j++) {
                        if (taro[i] && hana[j]) {
                            System.out.println(i + " " + j);
                            hit = true;
                            break;
                        }
                    }
                } else {
                    for (int i = 0; i < 101; i++) {
                        if (taro[i] && hana[i]) {
                            System.out.println(i + " " + i);
                            hit = true;
                            break;
                        }
                    }
                }
            }
            if (!hit) {
                System.out.println(-1);
            }
        }
    }
}

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

using namespace std;

int main() {
    int n, h, w, a, b, ans = 0;

    cin >> n >> h >> w;

    for (int i=0; i<n; i++) {
        scanf("%d %d", &a, &b);
        if (a >= h && b >= w) {
            ans++;
        }
    }

    cout << ans;

}

Measured memory_bytes: 256
n, m = map(int, input().split())

n -= 2
m -= 2

ans = 0

if n == 0 or m == 0:
    ans = 0

elif n == -1 and m == -1:
    ans = 1

elif n == -1 or m == -1:
    ans = max(n, m)

else:
    ans = n * m

print(ans)


Measured memory_bytes: 9172
#include <iostream>
using namespace std;
int main ()
{
	int n, najmanji=0, broj=0; cin>>n;
	int P[n+1];
	for (int i=1; i<n+1; i++) cin>>P[i];
	najmanji=P[1];
	for (int i=1; i<n+1; i++) if (najmanji>=P[i])
	{
		broj++;
		najmanji=P[i]; 
	}
	cout<<broj<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>

using namespace std;
 
int main(){
  string h;
  int a;
 
  while(cin >> a,a){
    int sum = 1,top = 1,dice[4] = {2,3,4,5};
    for(int i = 0 ; i < a ; i++){
      cin >> h;
      int tmp = top;
      if( i == 0 ) top = 1;
      if(h == "North"){
	top = dice[0];
	dice[0] = 7 - tmp;
	dice[3] = tmp;
      }
      else if(h == "East"){
	top = dice[2];
	dice[2] = 7 - tmp;
	dice[1] = tmp;
      }
      else if(h == "West"){
	top = dice[1];
	dice[1] = 7 - tmp;
	dice[2] = tmp; 
      }
      else if(h == "South"){
	top = dice[3];
	dice[3] = 7 - tmp;
	dice[0] = tmp;
      }
      else if(h == "Right"){
	tmp = dice[3];
	dice[3] = dice[2];
	dice[2] = dice[0];
	dice[0] = dice[1];
	dice[1] = tmp;
      }
      else{
	tmp = dice[3];
	dice[3] = dice[1];
	dice[1] = dice[0];
	dice[0] = dice[2];
	dice[2] = tmp; 
      }
      sum += top;
    }
    cout << sum << endl;
  }
 
  return 0;
}

Measured memory_bytes: 1208
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;

int main(){
    string s;
    ll k;
    cin >> s >> k;
    ll ans = 0;
    vector<ll> c;
    char now ;
    rep(i,s.size()){
        if(now == s[i]) c.back() ++;
        else{
            c.push_back(1);
            now = s[i];
        }
    }
    if(c.size() == 1){
        cout << (c[0] * k) /2 << endl;
        return 0;
    }
    rep(i,c.size()){
        ans += c[i] / 2;
        //cout << c[i] << " " ;
    }
    //cout << ans << endl;
    if(s.front() == s.back()){
        if(c.back() == 1 && c.front() == 1){
            cout << ans * k + k - 1 << endl;
        }else if(c.back() == 1){
            if(c.front()%2 == 0) cout << ans * k << endl;
            else cout << ans * k + k - 1 << endl;
        }else if(c.front() == 1){
            if(c.back()%2 == 0) cout << ans * k << endl;
            else cout << ans * k + k - 1 << endl;
        }else{
            if(c.back()%2 == 1 && c.front()%2 == 1) cout << ans * k + k-1 << endl;
            else cout << ans * k << endl;
        }
    }else{
        cout << ans * k << endl;
    }
    return 0;
}

Measured memory_bytes: 3640
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;
#define FAST  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define ll long long int 
#define ar array
#define pb push_back
#define fi(a,b) for(int i=a;i<(b);i++)
#define fj(a,b) for(int j=a;j<(b);j++)
#define fk(a,b) for(int k=a;k<(b);k++)
#define lb lower_bound
#define ub upper_bound
//hash base 177013


int main()
{
    FAST;
    //#ifndef ONLINE_JUDGE
    //    freopen("input.txt","r",stdin);
    //    freopen("output.txt","w",stdout);
    //#endif
    //ll testcase;
    //cin>>testcase;
    //while(testcase--)
    {
		ll n,m,q;
		cin>>n>>m>>q;
		map<int,int> r,c;
		set<pair<int,int>> s;
		int max_row=0,max_col=0;
		fi(0,q)
		{
			int x,y;
			cin>>x>>y;
			--x,--y;
			s.insert({x,y});
			r[x]++;
			c[y]++;
			max_row=max(max_row,r[x]);
			max_col=max(max_col,c[y]);
		}
		vector<int> rows,cols;
		for(int i=0;i<n;i++)
		{
			if(r[i]==max_row)
			{
				rows.pb(i);
			}
		}
		int ans=max_row+max_col;
		for(int j=0;j<m;j++)
		{
			if(c[j]==max_col)
			{
				cols.pb(j);
			}
		}
		if(rows.size()*cols.size()>300000)
		{
			cout<<ans;
			return 0;
		}
		//cout<<"here\n";
		bool common=false;
		for(auto i:rows)
		{
			for(auto j:cols)
			{
				if(s.find({i,j})==s.end())
				{
					common=true;
				}
			}
		}
		if(!common) ans--;
		cout<<ans;
		
		
    }
}


Measured memory_bytes: 49584
import java.util.*;
 
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		double ans = 0.0;
		for(int i=0;i<N;++i){
			double x = sc.nextDouble();
			String u = sc.next();
			if(u.equals("JPY")) ans += x;
			else ans += x*380000.0;
		}
		System.out.println(ans);
		return;
	}
}

Measured memory_bytes: 22612
#include<stdio.h>

int main(void){
  int N;
  scanf("%d",&N);
  N=N%10;
  if(N==2||N==4||N==5||N==7||N==9){
    printf("hon\n");
  }else if(N==0||N==1||N==6||N==8){
    printf("pon\n");
  }else{
    printf("bon\n");
  }
  
  return(0);
}

Measured memory_bytes: 1596
import java.io.PrintWriter
import java.util.NoSuchElementException

fun main(args: Array<String>) = IO().exec {
    val n = int()
    val k = int()
    val x = LongArray(n)
    val y = LongArray(n)
    for (i in 0 until n) {
        x[i] = long()
        y[i] = long()
    }
    val sortedX = x.copyOf()
    val sortedY = y.copyOf()
    sortedX.sort()
    sortedY.sort()
    var ret = Long.MAX_VALUE
    for (p in 0 until n)
        for (q in 0 until n)
            for (r in p until n)
                for (s in q until n) {
                    val w = sortedX[p]..sortedX[r]
                    val h = sortedY[q]..sortedY[s]
                    var cnt = 0
                    for (i in 0 until n) if (x[i] in w && y[i] in h) cnt++
                    if (cnt >= k) ret = Math.min(ret, (w.size()-1)*(h.size()-1) )
                }
    println(ret)
}

fun LongRange.size(): Long = this.last + 1 - this.first

class IO {
    val printable = 33..126
    val buffer = ByteArray(1024)
    var ptr = 0
    var buflen = 0
    val out = PrintWriter(System.out)
    fun hasNextByte(): Boolean {
        if (ptr < buflen) {
            return true
        } else {
            ptr = 0
            buflen = System.`in`.read(buffer)
            if (buflen <= 0) {
                return false
            }
        }
        return true
    }
    fun readByte(): Byte {
        return if (hasNextByte()) buffer[ptr++] else return -1
    }
    fun hasNext(): Boolean {
        while (hasNextByte() && buffer[ptr] !in printable) ptr++
        return hasNextByte()
    }
    fun string(): String {
        if (!hasNext()) throw NoSuchElementException()
        val sb = StringBuilder()
        var b = readByte()
        while (b in printable) {
            sb.appendCodePoint(b.toInt())
            b = readByte()
        }
        return sb.toString()
    }
    fun long(): Long {
        if (!hasNext()) throw NoSuchElementException()
        var n = 0L
        var minus = false
        var b = readByte()
        if (b == '-'.toByte()) {
            minus = true
            b = readByte()
        }
        if (b !in '0'.toByte()..'9'.toByte()) {
            throw NumberFormatException()
        }
        while (true) {
            if (b in '0'.toByte()..'9'.toByte()) {
                n *= 10
                n += b - '0'.toByte()
            } else if (b == (-1).toByte() || b !in printable) {
                return if (minus) -n else n
            } else {
                throw NumberFormatException()
            }
            b = readByte()
        }
    }
    fun int(): Int {
        val nl = long()
        if (nl !in Integer.MIN_VALUE..Integer.MAX_VALUE) throw NumberFormatException()
        return nl.toInt()
    }
    fun double(): Double {
        return string().toDouble()
    }
    fun print(obj: Any) = out.print(obj)
    fun print(i: Int) = out.print(i)
    fun print(l: Long) = out.print(l)
    fun println(obj: Any) = out.println(obj)
    fun println(i: Int) = out.println(i)
    fun println(l: Long) = out.println(l)
    inline fun exec(block: IO.() -> Unit) {
        block()
        out.flush()
    }
}




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

int main(){
	string s;
	cin >> s;
	int l, r;
	int n = s.size();
	for(int i = 0; i < n; i++) if(s[i] == 'A') {
		l = i;
		break;
	}
	for(int i = n-1; i >= 0; i--) if(s[i] == 'Z') {
		r = i;
		break;
	}
	if(l > r) cout<<0<<endl;
	else cout<<r - l  +1<<endl;
}


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

int main() {
	ll N;
	cin >> N;
	vector<ll> a(N);
	vector<ll> b(N);
	vector<ll> c(N);
	for (int i = 0; i < N; i++) cin >> a[i];
	for (int i = 0; i < N; i++) cin >> b[i];
	for (int i = 0; i < N; i++) cin >> c[i];
	sort(a.begin(), a.end());
	sort(b.begin(), b.end());
	sort(c.begin(), c.end());

	ll res = 0;
	for (int i = 0; i < N; i++) {
		if ((a[0] >= b[i]) || (c[N - 1] <= b[i])) continue;

		int ita = lower_bound(a.begin(), a.end(), b[i]) - a.begin();
		int itc = upper_bound(c.begin(), c.end(), b[i]) - c.begin();

		res += ita * (N - itc);
	}

	cout << res << endl;
	return 0;
}


Measured memory_bytes: 2560
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) {
		try {
			BufferedReader br = new BufferedReader(new InputStreamReader(
					System.in));
			StringBuilder s=new StringBuilder(); 
			int val = Integer.parseInt(br.readLine());
			int x = 0;

			for (int i = 1; i <= val; i++) {
				if (i % 3 == 0) {
					s.append(" " + i);
				} else if (i % 10 == 3) {
					s.append(" " + i);
				} else {
					x = i / 10;
					while (x != 0) {
						if (x % 10 == 3) {
							s.append(" " + i);
							break;
						}
						x /= 10;
					}
				}
			}
			System.out.println(s);
			br.close();
		} catch (Exception e) {
			System.err.println(e);
		}
	}
}

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

typedef long long ll;

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

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define ANS(n) cout << (n) << endl

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(a);i>=(b);i--)

#define ALL(obj) (obj).begin(),(obj).end()

#define pii pair<int,int>

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

int main()
{
	int n;
	cin >> n;
	string s;
	cin >> s;
	int redCnt = 0, blueCnt = 0;
	FOR(i,0,n){
		if(s[i] == 'R'){
			redCnt++;
		}else{
			blueCnt++;
		}
	}
	Yes(redCnt > blueCnt);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define INIT(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define INIT2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"

#define umap unordered_map
//cout << setfill('0') << right << setw(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}

ll solve(){
  ll X,Y,Z,K; cin >>X>>Y>>Z>>K;
  ll a[X]; CINA(a,X); sort(a,a+X,greater<ll>());
  ll b[Y]; CINA(b,Y); sort(b,b+Y,greater<ll>());
  ll c[Z]; CINA(c,Z); sort(c,c+Z,greater<ll>());
  vector<ll> v;
  REP(i,X){
    REP(j,Y){
      REP(k,Z){
        if( (i+1)*(j+1)*(k+1)<= K ){ v.push_back( a[i]+b[j]+c[k] ); } 
        else{ break;}
      }
    }
  }
  sort(ALL(v),greater<ll>());
  for(int i=0;i<K;++i){
    cout << v.at(i) <<"\n";
  }
  
}

int main(){
  solve();
}




Measured memory_bytes: 1400
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

int main() {
    int n; cin >> n;
    for (int i = 0; i < n - 1; i++) {
        for (int j = i + 1; j < n; j++) {
            int k = 0;
            while (true) {
                if (((1 << k) & i) ^ ((1 << k) & j)) {
                    break;
                }
                k++;
            }
            cout << k + 1 << " ";
        }
        cout << endl;
    }
    return 0;
}


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


s = readline().decode().rstrip()
q = int(readline())

cnt1 = 0
t2 = []
for _ in range(q):
    t = list(readline().decode().rstrip().split())
    t2.append(t)
    if t[0] == '1':
        cnt1 += 1

if cnt1 % 2 != 0:
    s = s[::-1]
s1 = []
s2 = []

for t in t2:
    if t[0] == '1':
        cnt1 -= 1
    else:
        if cnt1 % 2 == 0 and t[1] == '1':
            s1.append(t[2])
        elif cnt1 % 2 != 0 and t[1] == '2':
            s1.append(t[2])
        elif cnt1 % 2 == 0 and t[1] == '2':
            s2.append(t[2])
        else:
            s2.append(t[2])

print(''.join(s1[::-1])+s+''.join(s2))

Measured memory_bytes: 32780
#16:07
n = int(input())
raw = []
for _ in range(n):
  raw.append(list(map(lambda x: int(x)-1, input().split())))
cnt = [0 for _ in range(n)]
tmp = [0 for _ in range(n)]
now = [i for i in range(n)]
ans = 0
while now:
  ans += 1
  last = now
  now = []
  for x in last:
    tmp[x] = 0
  for x in last:
    try:
      y = raw[x][cnt[x]]
      if tmp[x] == tmp[y] == 0 and x == raw[y][cnt[y]]:
        cnt[x] += 1
        cnt[y] += 1
        tmp[x] = 1
        tmp[y] = 1
        now.append(x)
        now.append(y)
    except:
      pass
  #print(now)
if cnt == [n-1 for _ in range(n)]:
  print(ans-1)
else:
  print(-1)

Measured memory_bytes: 54620
N = int(input())
lists = [int(x) for x in input().split()]
step_sum = 0

for y in range(1, N):
    if lists[y - 1] <=  lists[y]:
        continue
    else:
        s = abs(lists[y] - lists[y -1])
        lists[y] += s
        step_sum += s
        continue
        
print(step_sum)

Measured memory_bytes: 105400
import java.util.HashSet;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scn =new Scanner(System.in);
		
			int n=scn.nextInt();
			 int val1=n;
			 long ans=7;
			 long cnt=0;
			 while(val1>10){
				 ans*=10;
				 ans+=7;
				 cnt++;
				 val1/=10;
			 }
			 HashSet<Long> hs =new HashSet<>();
			 
			 boolean f=false;
			
			 while(true){
				 long mod = ans%n;
				 if(mod==0){
					 break;
				 }
				 if(hs.contains(mod)){
					 f=true;
					 break;
				 }
				 hs.add(mod);
				 ans=mod*10+7;
				 cnt++;
			 }
			 if(f){
				 System.out.println(-1);
			 }else{
				 System.out.println(cnt+1);
			 }
		}

	

}

Measured memory_bytes: 131732
#include <stdio.h>
#define INF 1000000000
#define N 500000
void merge(int , int , int);
void mergeSort(int ,int);

int A[N];
int L[N/2+1],R[N/2+1];
int count=0;
int main(){
  int n,i;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  mergeSort(0, n);
  for(i=0;i<n-1;i++){
    printf("%d ",A[i]);
  }
  printf("%d\n",A[i]);
  printf("%d\n",count);

  return 0;

}

void merge(int left, int mid, int right){
  int i,j,k,n1,n2;
  n1=mid-left;
  n2=right-mid;
  for(i=0;i<n1;i++)
    L[i]=A[left+i];
  for(i=0;i<n2;i++)
    R[i]=A[mid+i];
  L[n1]=INF+100;
  R[n2]=INF+100;
  i=0;
  j=0;
  for(k=left;k<right;k++){
    if(L[i]<=R[j]){
      A[k]=L[i];
      i=i+1;
    }
    else{
      A[k]=R[j];
      j=j+1;
    }
    count++;
  }
}
  
void mergeSort(int left,int right){
  int mid;
  if(left+1 < right){
    mid=(left+right)/2;
    mergeSort(left, mid);
    mergeSort(mid, right);
    merge(left, mid, right);
  }
}

Measured memory_bytes: 4504
#include<bits/stdc++.h>
using namespace std;
int main() {
  long int N, i ,j;
  long int count = 0;
  cin >> N;

  vector<vector<int>> A(N, vector<int>(2));
  for (i = 0; i < N; i++) {
    for (j = 0; j < 2; j++) {
      cin >> A[i][j];
    }
    //cout << A[i][0] << A[i][1] << endl;
    if(A[i][0] == A[i][1]){
      count++;
      //cout << A[i][0] << A[i][1] << endl;
      if(count == 3){
        cout << "Yes" << endl;
        return 0;
      }
    }else{
      count = 0;
    }
  }
  cout << "No" << endl;
  return 0;

}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N;
    cin >> N;
    for(int i=N;i<1000;i++){
        if(i/100==i%100/10&&i%100/10==i%100%10){
            cout << i << endl;
            break;
        }
    }

}

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

int main() {
  int M;
  cin >> M;
  int D;
  cin >> D;
  
  int t=D/10;
  int o=0;
  if(t>=1) o=9;
  int q=D-(t*10);
  int ans=0;
  
  if(M<4 || t<=1) cout << 0 << endl;
  else if(o==0 && q<=1) cout <<0 << endl;
    
  else if(q!=9 && M>=4 && t>1 && o>1){
    for(int i=2; i<t; i++){
      for(int j=2; j<=o; j++){
        if(M>=i*j) ans++;
      }
    }
    if(q>1){
      for(int i=2; i<=q; i++){
        if(M>=i*t) ans++;
      }
    }
    cout << ans << endl;
  }
  
  else if(q==9 && M>=4 && t>1){
    for(int i=2; i<=t; i++){
      for(int j=2; j<=q; j++){
        if(M>=i*j) ans++;
      }
    }
    cout << ans << endl;
  } 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  auto a = [&]() -> V<lint> {
    const string t = "FESTIVA";
    string s;
    for (int i = 0; i < 8; ++i) {
      for (char c : t) {
        s += string(1 << i, c);
      }
    }
    V<lint> dp(8);
    dp[0] = 1;
    V<lint> res;
    for (int i = 0; i < (int)s.size(); ++i) {
      auto ndp = dp;
      int j = t.find(s[i]);
      ndp[j + 1] += dp[j];
      swap(dp, ndp);
      if (s[i] == 'A' and s[i + 1] != 'A') {
        res.push_back(dp.back());
      }
    }
    return res;
  }();

  lint k; cin >> k;
  string res;
  for (int i = 7; i >= 0; --i) {
    res += string(k / a[i], 'F');
    for (char c : "ESTIVAL"s) {
      res += string(1 << i, c);
    }
    k %= a[i];
  }
  cout << res << '\n';
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
import decimal
def input():
    return sys.stdin.readline()[:-1]

def main():
    A, B = map(int, input().split())

    for i in range(1, 10 ** 4):
        a = int(decimal.Decimal(i * 0.08))
        b = int(decimal.Decimal(i * 0.1))
        if a == A and b == B:
            print(i)
            exit()
    print(-1)

if __name__ == '__main__':
    main()


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

main(){
  int h,w,d;
  cin>>h>>w>>d;
  vector<P> p(h*w); 
  rep(i,h)rep(j,w){
    int a;
    cin>>a;
    a--;
    p[a]=make_pair(i,j);
  }
  vector<int> r[d];
  rep(s,d){
    r[s].push_back(0);
    for(int i=1; i*d+s<h*w; i++){
      int pi,pj,ni,nj;
      tie(pi,pj)=p[(i-1)*d+s];
      tie(ni,nj)=p[i*d+s];
      r[s].push_back(r[s][r[s].size()-1]+abs(ni-pi)+abs(nj-pj));
    }
  }
  int q;
  cin>>q;
  rep(i,q){
    int L,R;
    cin>>L>>R;
    L--; R--;
    cout<<r[R%d][R/d]-r[L%d][L/d]<<endl;;
  }
}

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

const ll INF = LLONG_MAX;
const ll MOD = 1e9 + 7;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll N, K;
    cin >> N >> K;
    vector<pair<ll, ll>> ab(N);
    ll cnt = 0;
    rep(i, N)
    {
        cin >> ab[i].first >> ab[i].second;
    }
    sort(ab.begin(), ab.end());
    rep(i, N) {
        cnt += ab[i].second;
        if (cnt >= K) {
            cout << ab[i].first << endl;
            return 0;
        }
    }

    return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>

	int main(void){

	int x,y;

while(1){
	scanf("%d %d", &x, &y);
	
	if(x == 0 && y == 0){
		break;
	}
	
	if(x > y){
		printf("%d %d\n", y, x);
	}
	else{
		printf("%d %d\n", x, y);
	}

	
}
	return 0;
	}

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


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

    int N, K;
    cin >> N >> K;
    string S;
    cin >> S;

    int max_len = 0;
    char prev_char = '2';
    int left = 0;
    int right = -1;
    int prev_len = 0;
    int limit = K;
    for (int i = 0; i < S.length(); ++i) {
        char cur_char = S[i];
        prev_len++;

        if (prev_char != '0' && cur_char == '0') {
            if (limit == 0) {
                prev_len -= right - left + 1;
                left = right + 1;
                for (int j = left + 1; j <= i; ++j) {
                    if (S[j - 1] == '0' && S[j] == '1') {
                        right = j - 1;
                        break;
                    }
                }
            } else {
                limit--;
            }
        }
        if (prev_char == '0' && cur_char == '1' && right == -1) {
            right = i - 1;
        }
        max_len = max(max_len, prev_len);
        prev_char = cur_char;
    }

    cout << max_len << '\n';

    return 0;
}


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

using namespace std;

int n, k;
bool edge[105][105];

int main(void)
{
    scanf("%d%d", &n, &k);
    int num = (n - 1) * (n - 2) / 2;
    for (int i = 2; i <= n; ++i)
        edge[i][1] = edge[1][i] = true;
    if (num < k) {
        printf("-1\n");
        return 0;
    }
    while (num > k) {
        int x = rand() % n + 1, y = rand() % n + 1;
        if (x == y || edge[x][y]) continue;
        --num, edge[x][y] = edge[y][x] = true;
    }
    int cnt = 0;
    for (int i = 1; i <= n; ++i)
        for (int j = 1; j < i; ++j)
            if (edge[i][j]) ++cnt;
    printf("%d\n", cnt);
    for (int i = 1; i <= n; ++i)
        for (int j = 1; j < i; ++j)
            if (edge[i][j]) printf("%d %d\n", i, j);
    return 0;
}

Measured memory_bytes: 256
from collections import deque

n,c,k = map(int, input().split())
t = [int(input()) for _ in range(n)]

tk = [(ti, ti+k) for ti in t]
tk.sort(key=lambda x:x[1])
tk = deque(tk)
#print(tk)


ans = 0
# tkが尽きるまで
while tk:
    _, bus = tk[0]
    
    # バスの時刻より早く来ている客をカウント
    cnt = 0
    while (tk[cnt][0] <= bus) and (cnt < c):
        cnt += 1
        
        if cnt == len(tk):
            break
        
        
    # バスの定員もしくはいる人数を乗せていく
    for _ in range(min(cnt,c)):
        tk.popleft()
    
    ans += 1
        
print(ans)

Measured memory_bytes: 19384
import java.util.List;
import java.util.Scanner;

public class Main {

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

	void run() {
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int x = sc.nextInt();

		int[] a=new int[N];
		int[] init=new int[N];

		//初期の値を記録しておく。
		for (int i = 0; i < N; i++) {
			a[i]=sc.nextInt();
			init[i]=a[i];
		}

		//左端をx以下を保証。
		a[0]=Math.min(a[0],x);

		//a[i]+a[i-1]がx以下になるには
		//a[i]をx-a[i-1]まで減らしてあげるといい

		for (int i = 1; i < N; i++) {
			a[i]=Math.min(a[i],x-a[i-1]);
		}

		long ans=0;
		//初期の値との差を足し上げていく。
		for (int i = 0; i < N; i++) {
			ans+=init[i]-a[i];
		}

		System.out.println(ans);
	}

	//以下テンプレート

	public static int[] extgcd(int a, int b) {

		int x0 = 1;
		int x1 = 0;

		int y0 = 0;
		int y1 = 1;

		while (b != 0) {
			int q = a / b;
			int r = a % b;

			int x2 = x0 - q * x1;
			int y2 = y0 - q * y1;

			a = b;
			b = r;

			x0 = x1;
			x1 = x2;

			y0 = y1;
			y1 = y2;
		}

		return new int[] { a, x0, y0 };

	}

	static int gcd(int a, int b) {

		if (b == 0)
			return a;

		if (a < b) {
			int t = a;
			a = b;
			b = t;
		}

		return gcd(b, a % b);

	}

	static int lcm(int a, int b) {
		return a * b / gcd(a, b);
	}

	static void swap(int[] a) {
		int t;

		t = a[0];
		a[0] = a[1];
		a[1] = t;

		return;
	}

	static <T> void output(List<T> list) {

		for (int i = 0; i < list.size(); i++) {
			System.out.print(list.get(i));

			if (i != list.size() - 1) {
				System.out.print(" ");
			} else {
				nl();
			}
		}

	}

	static void output(String[][] str) {

		for (int i = 0; i < str.length; i++) {
			for (int j = 0; j < str[i].length; j++) {
				print(str[i][j]);
			}

			nl();
		}

	}

	static void output(boolean flg, String Yes, String No) {

		if (flg) {
			pln(Yes);
		} else {
			pln(No);
		}

	}

	static void output(String[][] str, int digit) {

		String dig = "%" + String.valueOf(digit) + "s";

		for (int i = 0; i < str.length; i++) {
			for (int j = 0; j < str[i].length; j++) {
				System.out.printf(dig, str[i][j]);
			}
			nl();
		}

	}

	static void pln(String str) {
		System.out.println(str);
	}

	static void pln(int x) {
		System.out.println(x);
	}

	static void print(String str) {
		System.out.print(str);
	}

	static void print(int x) {
		System.out.print(x);
	}

	static void print(String str, int times) {
		for (int i = 0; i < times; i++) {
			print(str);
		}
	}

	static void print(int x, int times) {
		for (int i = 0; i < times; i++) {
			print(x);
		}
	}

	static void nl() {
		System.out.println();
	}

}


Measured memory_bytes: 60184
H,W,N = map(int, input().split())
AB = [ [int(j)-1 for j in input().split()] for _ in range(N)]

s = []
for i in range(N):
    a,b = AB[i]

    y = [a-1, a, a+1]
    x = [b-1, b, b+1]

    for ey in y:
        if 1 <= ey < H-1:
            for ex in x:
                if 1 <= ex < W-1:
                    s.append( (ey, ex) )
    
# print(s)
from collections import Counter,defaultdict
c = Counter(s)
d = defaultdict(int)

allp = (H-2)*(W-2)

for k in c.keys():
    d[c[k]] += 1


ans = []
for i in range(1, 9+1):
    ans.append (  d[i] )

print(allp - sum(ans)) 

for i in range(1,9+1):
    print(ans[i-1])



Measured memory_bytes: 177600
from scipy.sparse.csgraph import minimum_spanning_tree
from scipy.sparse import csr_matrix
from operator import itemgetter

n = int(input())
xy = [list(map(int, input().split())) + [i] for i in range(n)]

edge = set()
for key in (itemgetter(0), itemgetter(1)):
    xy.sort(key=key)
    for (x1, y1, i1), (x2, y2, i2) in zip(xy, xy[1:]):
        d = min(abs(x1 - x2), abs(y1 - y2))
        edge.add((i1, i2, d))

u, v, c = zip(*edge)

graph = csr_matrix((c, (u, v)), shape=(n, n), dtype=int)
mst = minimum_spanning_tree(graph, overwrite=True).astype(int)
ans = mst.sum()
print(ans)


Measured memory_bytes: 92032
import sys
sys.setrecursionlimit(4100000)

def os(): return input()
def oi(): return int(input())
def oli(): return map(int, input().split())
def olai(): return list(map(int, input().split()))
def olas(): return list(input().split())
def mlai(L): return [int(input()) for _ in range(L)]
def mlas(L): return [input() for _ in range(L)]
def ar(a, b, c=-1, d=-1, INIT=0):
    if(c==-1): return [[INIT]*b for _ in range(a)]
    if(d==-1): return [[[INIT]*c for _ in range(b)] for __ in range(a)]
    return [[[[INIT]*d for _ in range(c)] for __ in range(b)] for ___ in range(a)]

n, m = oli()

#全方位木dp
#-------------------------------------------------------------------
#扱うクラス


#零元
zero = 1

#一個上に遷移した時の変化
def step(x):
    return x+1
#マージ
def merge(x, y):
    return (x*y)%m

G = [[] for _ in range(100001)]
down_data = [zero for _ in range(100001)]
dat = [zero for _ in range(100001)]

def dfs(now, parent):
    cnt = 0
    for to in G[now]:
        if(to==parent): continue
        cnt += 1
        dfs(to, now)
        down_data[now] = merge(down_data[now], step(down_data[to]))

def dfs_rev(now, parent, rev):
    #累積
    left = []
    right = []
    cnt = 0
    for to in G[now]:
        if(to==parent): continue
        if(len(left)==0): left.append(step(down_data[to]))
        else: left.append(merge(left[cnt-1], step(down_data[to])))
        cnt += 1
    cnt = 0
    for to in reversed(G[now]):
        if(to==parent): continue
        if(len(right)==0): right.append(step(down_data[to]))
        else: right.append(merge(right[cnt-1], step(down_data[to])))
        cnt += 1
    cnt = 0
    dat[now] = merge(rev, down_data[now])

    for to in G[now]:
        if(to==parent): continue
        x = zero if cnt==0 else left[cnt-1]
        y = zero if cnt==len(right)-1 else right[len(right)-2-cnt]
        dfs_rev(to, now, step(merge(rev, merge(x, y))))
        cnt += 1

def calc(N):
    root = -1
    for i in range(1, N+1):
        if(len(G[i]) == 1 or len(G[i]) == 0):
            root = i
            break
    dfs(root, -1)
    dfs_rev(root, -1, zero)
#-------------------------------------------------------------------

for i in range(n-1):
    a, b = oli()
    G[a].append(b)
    G[b].append(a)
calc(n)
for i in range(1, n+1):
    print(dat[i])


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

int n, k, x, y, sum;

int main() {
    cin >> n >> k >> x >> y;
    if (n <= k) {
        sum = n * x;
    } else {
        sum = k * x + (n-k) * y;
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
line1 = input().rstrip().split(' ')
hit_point = int(line1[0])
N = int(line1[1])

line2 = input().rstrip().split(' ')
special_skills = map(int, line2)

total_attack_point = sum(special_skills)

print('Yes' if hit_point <= total_attack_point else 'No')

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

using namespace std;

typedef long long LL;

int A,B,C;
LL a[100005],b[100005],c[100005],ans;
priority_queue<pair<LL,int> > q1,q2,q3;
bool vis[100005];
int n;
struct Node
{
	LL a,b,id;
}f[100005];
bool cmp(Node a,Node b)
{
	return a.a>b.a;
}
int main()
{
	scanf("%d%d%d",&A,&B,&C);
	for (int i=1;i<=A+B+C;++i) scanf("%lld%lld%lld",&a[i],&b[i],&c[i]);
	for (int i=1;i<=A+B+C;++i) ans+=b[i],a[i]-=b[i],c[i]-=b[i];
	n=A+B+C;
	for (int i=1;i<=n;++i) 
	{
		f[i].a=a[i];f[i].b=c[i];
		f[i].id=i;
	}
	sort(f+1,f+n+1,cmp);
	for (int i=1;i<=n;++i) vis[i]=false;
	for (int i=1;i<=A;++i) ans+=f[i].a;
	for (int i=A+1;i<=n;++i) q1.push(make_pair(f[i].a,f[i].id));
	for (int i=A+1;i<=n;++i) q2.push(make_pair(f[i].b,f[i].id));
	for (int i=1;i<=A;++i) q3.push(make_pair(f[i].b-f[i].a,f[i].id));
	for (int i=1;i<=C;++i)
	{
		pair<LL,int> id1,id2;
		while (!q1.empty())
		{
			id1=q1.top();q1.pop();if (vis[id1.second]==false) break;
		}
		while (!q2.empty())
		{
			id2=q2.top();q2.pop();if (vis[id2.second]==false) break;
		}
		if (id2.first>id1.first+q3.top().first)
		{
			ans+=id2.first;vis[id2.second]=true;
			q1.push(id1);
		}
		else
		{
			ans+=id1.first+q3.top().first;
			vis[id1.second]=true;
			q2.push(id2);
			q3.pop();
			q3.push(make_pair(c[id1.second]-a[id1.second],id1.second));
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 9712
while True:
	h, w = map(int, input().split())
	if h == 0 and w == 0:
		exit(0)
	for i in range(0, h):
		for j in range(0, w):
			if i == 0 or i == h - 1 or j == 0 or j == w - 1:
				print('#', end='')
			else:
				print('.', end='')
		print()
	print()



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

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define endl '\n'

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;

const ll mod = 1000000007;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// head

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

    int x;
    cin >> x;
    if(x >= 30) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;

    }
    return 0;
}


Measured memory_bytes: 3656
/*by freesteed*/
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define pb push_back
#define fill(x,c) memset(x,c,sizeof(x))
#define fi first
#define se second
#define sz(A) (int)(A.size())
#define all(x) (x).begin(),(x).end()
#define caset int ___T; cin>>___T; for(int cs=1;cs<=___T;cs++)
#define get_be(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
//get_be biger & equal
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
const ll mod=1e9+7;
const ll oo=1e9+10;
const int Max = 1e6+10;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}

void solve(){
	 ll m,n;
	 cin>>m>>n;
	 cout<<max({m+n,m-n,m*n}); 
}
int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//caset{
		solve();
	//}
  	return 0;
}





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

int main(){
  int amida[1005][105];
  int n, m, a;
  while(cin >> n >> m >> a, n|m|a){
    int h, p, q, maxh = -1;
    memset(amida, 0, sizeof(amida));
    for(int i = 0; i < m; i++){
      cin >> h >> p >> q;
      amida[h][p] = q;
      amida[h][q] = p;
      maxh = max(maxh, h);
    }
    for(int i = maxh; i > 0; i--){
      if(amida[i][a]) a = amida[i][a];
    }
    cout << a << endl;
  }
  return 0;
}



Measured memory_bytes: 3436
#include <stdio.h>
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <string>
#include <utility>
#include <queue>
#include <unordered_set>
#include <set>
#include <unordered_map>
#include <cmath>
#include <iomanip>
using namespace std;
#define sL(i) i << 1
#define sR(i) i << 1 | 1
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pair<int,int>, int> ppi;
const int MOD = 1e9 + 7;
const int INF = 2e9 + 5;

int N, K, Q, a[2005];
unordered_set<int> distinct;
vector<int> b;

bool possible(int large, int small){
    int streak = 0;
    int inRange = 0;
    int taken = 0;
    for(int i = 0; i < N; i++){
        if(a[i] < small){
            inRange = 0;
            streak = 0;
            continue;
        }
        streak++;
        if(a[i] >= small && a[i] <= large) inRange++;
        if(streak >= K && inRange > 0){
            inRange--;
            taken++;
        }
    }
    return taken >= Q;
}

int main(){
    cin.sync_with_stdio(0);
    cin.tie(0);
    cin >> N >> K >> Q;
    for(int i = 0; i < N; i++){
        cin >> a[i];
        if(!distinct.count(a[i])){
            distinct.insert(a[i]);
            b.pb(a[i]);
        }
    }
    sort(b.begin(), b.end());
    int M = b.size();
    int ans = INF;
    for(int i = 0; i < M; i++){
        int Y = b[i];
        int lo = i;
        int hi = M - 1;
        int best = INF;
        while(lo <= hi){
            int m = (lo + hi) / 2;
            int X = b[m];
            if(possible(X, Y)){
                best = min(best, m);
                hi = m - 1;
            }else{
                lo = m + 1;
            }
        }
        if(best == INF) continue;
        ans = min(ans, b[best] - Y);
        //cout << i << " " << Y << " " << best << " " << b[best] << "\n";
    }
    cout << ans;
}

Measured memory_bytes: 384
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();
	  String[][] w = new String[H][W];

	  for(int i=0; i<H; i++) {
		  w[i] = sc.next().split("");
	  }
	  sc.close();

	  boolean flg = true;
	  // 行ループ
	  for(int k=0; k<H; k++){
		  // 列ループ
		  for(int l=0; l<W; l++){
			  if (w[k][l].equals("#")) {

				  // 下
				  if (k < (H - 1)) {
					  if(w[k+1][l].equals("#")) {
						  continue;
					  }
				  }
				  // 上
				  if (k > 0) {
					  if(w[k-1][l].equals("#")) {
						  continue;
					  }
				  }
				  // 右
				  if (l < (W - 1)) {
					  if(w[k][l+1].equals("#")) {
						  continue;
					  }
				  }
				  // 左
				  if (l > 0) {
					  if(w[k][l-1].equals("#")) {
						  continue;
					  }
				  }
				  
				  // continueされなかったらNG
				  System.out.println("No");
				  flg = false;
				  break;
			  }
		  }
		  if (!flg) {
			  break;
		  }
	  }
	  if (flg) {
		  System.out.println("Yes");
	  }
	}
}

Measured memory_bytes: 21972
N, T = map(int, input().split())
K = []
for i in range(N):
    a, b = map(int, input().split())
    K.append([a, b])
K.sort()

dp = [[0]*(N+1) for _ in range(T+3001)]

for i in range(1, T+3001):
    for j in range(N):
        if 0 <= i - K[j][0] <= T-1:
            dp[i][j+1] = max(dp[i - K[j][0]][j]+K[j][1], dp[i][j])
        else:
            dp[i][j+1] = dp[i][j]

ans = 0
for i in range(1,T+3001):
    ans = max(dp[i][N],ans)
print(ans)

Measured memory_bytes: 180824
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int[][] a = new int[2][N];
        for(int i = 0; i < 2; i++) {
            for(int j = 0; j < N; j++) {
                a[i][j] = Integer.parseInt(sc.next());
            }
        }
        
        int max = 0;
        int sum = 0;
        for(int k = 0; k < N; k++) {
            sum = 0;
            int i = 0;
            for(int j = 0; j < N; j++) {
                if(k == j) {
                    sum += a[i][j];
                    i = 1;
                }
                sum += a[i][j];
            }
            if(sum > max) {
                max = sum;
            }
        }
        System.out.println(max);
        
    }
}

Measured memory_bytes: 21844
#include<iostream>
using namespace std;
int main()
{
  int x[5],i;
  cin>>x[0]>>x[1]>>x[2]>>x[3]>>x[4];
  for(i=0;i<5;i++){
    if(x[i]==0){
      cout<<i+1;
      break;
    }
  }
}

Measured memory_bytes: 3620
N = int(input())
A = list(map(int, input().split()))

ave = sum(A) // N 
if sum(A) % N >= N / 2:
  ave += 1

ans = 0
for i in range(N):
  ans += (A[i] - ave) * (A[i] - ave) 

print(int(ans))

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

//使用flag的冒泡排序法 
int bubbleSort(int A[],int N){
	int sw=0;
	bool flag=1;
	for(int i=0;flag;++i){
		flag=0;
		for(int j=N-1;j>=i+1;j--){
			if(A[j]<A[j-1]){
				//交换相邻元素 
				swap(A[j],A[j-1]);
				flag=1;
				sw++;
			}
		}
	}
	return sw;
}
int main(){
	int A[100],N,sw;
	cin>>N;
	for(int i=0;i<N;i++) cin>>A[i];
	
	sw=bubbleSort(A,N);
	
	for(int i=0;i<N;++i){
		if(i) cout<<" ";
		cout<<A[i];
	} 
	cout<<endl;
	cout<<sw<<endl;
	
	return 0;
} 


Measured memory_bytes: 3092
#include <iostream>
#include <vector>
#include <array>
#include <deque>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <complex>
#include <bitset>
#include <functional>

using namespace std;
using ll=long long int;

int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    for (auto &e: a) cin >> e;

    set<ll> s;
    ll sum = accumulate(a.begin(), a.end(), 0LL);
    ll acc = 0;
    s.insert(acc);
    for (int i = 0; i < n; ++i) {
        acc += a[i];
        s.insert(acc);
    }

    auto it = s.upper_bound(sum/2);
    ll c1 = *it;
    ll c2 = *prev(it);

    ll d = min(abs(c1*2 - sum), abs(c2*2 - sum));

    cout << d << endl;

    return 0;
}


Measured memory_bytes: 11136
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int INF = 1LL << 30;
int MOD = 1e9+7;
main(){
    int N;
    ll cnt[5] = {};
    cin >> N;
    for(int i = 0;i < N;i++){
        string s,str = "MARCH"; 
        cin >> s;
        for(int j = 0;j < 5;j++)if(s[0] == str[j])cnt[j]++;
    }
    ll sum = 0;
    for(int i = 0;i < 5;i++)for(int j = i+1;j < 5;j++)for(int k = j+1;k < 5;k++){
        sum += cnt[i] * cnt[j] * cnt[k];
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
n,m=gets.chomp.split(" ").map(&:to_i)
arr = Array.new(n){0}
m.times do
  b,c=gets.chomp.split(" ").map(&:to_i)
  arr[b-1] = arr[b-1] + 1 #配列の最初は0番目であることに注意
  arr[c-1] = arr[c-1] + 1
end
n.times do |k| #0-(m-1)の値を取るから注意
  puts(arr[k])
end

Measured memory_bytes: 14232