akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s1, s2, s3;
	cin >> s1 >> s2 >> s3;
	char dif = 'A' - 'a';
	printf("%c%c%c\n", s1[0] + dif, s2[0] + dif, s3[0] + dif);

}


Measured memory_bytes: 256
// 4/29
// 過去問攻略

#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <cstring>
using namespace std;

const int MAX_N = 200010;

int main() {
    long long N;
    cin >> N;

    // 各番号の数字が何個入っているかをメモ。
    long long dp[MAX_N] = {0};

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

    // 全てを使ったときの組み合わせ。
    long long all_comb = 0;
    for (long long i = 0; i < MAX_N; i++) {
        all_comb += dp[i] * (dp[i] - 1) / 2;
    }

    // cout << all_comb << endl;

    // k = 1から順番に、組み合わせを計算していく。
    for (long long i = 0; i < N; i++) {
        long long comb = all_comb;

        if (dp[A[i]] == 0) cout << comb << endl;
        else cout << comb - dp[A[i]] + 1 << endl;
    }
}


Measured memory_bytes: 5760
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=55,M=22;
const ll inf=1e18;

int n,len[N];
ll f[N][M][2],c[N],ans=inf;
char s[N][M];

ll dp(int x,int y,int d) {//x????,y???,d???(??)
    if(y>len[x]) return 0;
    if(~f[x][y][d]) return f[x][y][d];
    ll &v=f[x][y][d];
     v=inf;
	bool flag=1;
	if(!d) {for(int j=y,k=len[x];j<k;j++,k--) if(s[x][j]!=s[x][k]) {flag=0; break;}}
	else {for(int j=y,k=1;j>k;j--,k++) if(s[x][j]!=s[x][k]) {flag=0; break;}}
	if(flag) return v=0;
    for(int i=1,j,k;i<=n;i++) {//???????????
        flag=1;
        if(!d) {
            for(j=y,k=len[i];j<=len[x]&&k>=1;j++,k--)
                if(s[x][j]!=s[i][k]) {flag=0; break;}
            if(flag) {
                if(k<1) v=min(v,c[i]+dp(x,j,0));
                else v=min(v,c[i]+dp(i,k,1));
            }
        }
        else {
            for(j=y,k=1;j>=1&&k<=len[i];j--,k++)
                if(s[x][j]!=s[i][k]) {flag=0; break;}
            if(flag) {
                if(j<1) v=min(v,c[i]+dp(i,k,0));
                else v=min(v,c[i]+dp(x,j,1));
            }
        }
    }
    return v;
}

int main() {
    scanf("%d",&n); memset(f,-1,sizeof(f));
    for(int i=1;i<=n;i++) scanf("%s",s[i]+1),scanf("%lld",&c[i]),len[i]=strlen(s[i]+1);
    for(int i=1;i<=n;i++) 
		ans=min(ans,c[i]+dp(i,1,0));
    printf("%lld\n",ans==inf?-1:ans);return 0;
}



Measured memory_bytes: 3744
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int a[100005];
int cnt[100005];

#define rep(i,s,t) for(int i=s;i<t;i++)
#define rrep(i,s,t) for(int i=s;i>=t;i--)

typedef long long ll;

ll mod=1000000007ll;

ll f[2010101], rf[2010101];

ll inv(ll x) {
    ll res = 1;
    ll k = mod - 2;
    ll y = x;
    while (k) {
        if (k & 1) res = (res * y) % mod;
        y = (y * y) % mod;
        k /= 2;
    }
    return res;
}
void init() {
    f[0] = 1;
    rep(i, 1, 2010101) f[i] = (f[i - 1] * i) % mod;
    rf[2010101 - 1] = inv(f[2010101 - 1]);
    rrep(i, 2010101 - 2, 0) rf[i] = (rf[i + 1] * (i + 1)) % mod;
}
//---------------------------------------------------------------------------------------------------
ll C(int n, int k) {
    if (k < 0 || n < k) return 0;

    ll a1 = f[n]; // = n!
    ll b = rf[n - k]; // = (n-k)!
    ll c = rf[k]; // = k!

    ll bc = (b * c) % mod;

    return (a1 * bc) % mod;
}


int main(){

	init();

	int n;

	scanf("%d",&n);

	int i;

	int k1;
	int k2;

	int value;

	for(i=1;i<=n+1;i++){
		scanf(" %d",&a[i]);
		cnt[a[i]]++;
		if(cnt[a[i]]==2){
			k1=i;
			value=a[i];
		}
	}

	for(i=1;i<=n+1;i++){
		if(a[i]==value){
			k2=i;
			break;
		}
	}


	int x=k2-1;
	int y=n+1-k1;

	for(i=1;i<=n+1;i++){
		cout << (C(n + 1, i) -  C(x+y, i - 1) + mod) % mod << endl;
	}

	return 0;
}

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

const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int n;
    cin >> n;
    vi a(n);
    rep(i, n) cin >> a[i];
    bool odd = false;
    rep(i, n) if (a[i]%2==1) odd = true;
    if (odd) cout << "first" << endl;
    else cout << "second" << endl;
    return 0;
}


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

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

LL gcd(LL x, LL y) {
  if(y == 0) return x;
  return gcd(y, x%y);
}

class Counter{
  public:
  map<LL, LL> data;
  Counter() {
  }

  void add_pair(LL x, LL y) {
    data[x]++;
    data[y+1]--;

  }

  LL dump() {
    LL ans = 0;
    LL cnt = 0;
    LL prev = 0;
    for(auto val: data) {
      LL cur = val.first;
      LL diff = val.second;
      if(cnt > 0) {
        ans += cur - prev;
      }
      cnt += diff;
      prev = cur;
    }
    return ans;

  }
};


int main() {
  LL X, D, N;
  cin >> N >> X >> D ;
  if(D==0) {
    int ans = ( X == 0 ? 1 : N + 1);
    cout << ans << endl;
    return 0;
  }
  LL g = gcd(abs(X), abs(D));

  LL M = abs(D) / g;

  vector<Counter> counters(min(M, N+10));
  LL upper = 0;
  LL lower = 0;
  for(int i=0; i<N+1; i++){
    LL diff = (X * M / D) * (i / M);
    counters[i % M].add_pair(lower + diff, upper + diff );
    // cout << lower + diff << " " << upper +  diff << endl;

    lower += i;
    upper += N-i-1;
  }

  LL ans = 0;
  for(auto counter: counters)
    ans += counter.dump();

  cout << ans << endl;



  return 0;
}




Measured memory_bytes: 50176
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
  
using namespace std;
  
typedef long long ll;
typedef pair <string,int> P;
typedef pair <int,P> PP;
  
static const double EPS = 1e-8;
  
const static int tx[] = {0,1,0,-1};
const static int ty[] = {-1,0,1,0};

int main(){
  int N;
  while(~scanf("%d",&N)){
    if(N == 0) break;
    vector<string> dict;
    int prior[256][256]; // prior[A][B] ::= A is prior to B or not
    memset(prior,-1,sizeof(prior));

    bool isok = true;
    bool res = true;
    for(int current_idx = 0;current_idx<N;current_idx++){
      string current;
      cin >> current;

      for(int prev_idx=0;prev_idx<dict.size();prev_idx++){
        for(int char_idx=0;
            char_idx < current.size() && char_idx < dict[prev_idx].size();
            char_idx++){
          if(current[char_idx] == dict[prev_idx][char_idx]) continue;

          if(prior[dict[prev_idx][char_idx]][current[char_idx]] == 1){
            break;
          }

          if(prior[dict[prev_idx][char_idx]][current[char_idx]] == -1){
            prior[dict[prev_idx][char_idx]][current[char_idx]] = 1;
            prior[current[char_idx]][dict[prev_idx][char_idx]] = 0;
            break;
          }
        }

        bool isok = true;
        bool is_first = true;
        for(int char_idx=0;
            char_idx < current.size() && char_idx < dict[prev_idx].size();
            char_idx++){
          if(current[char_idx] == dict[prev_idx][char_idx]) continue;
          if(is_first && prior[current[char_idx]][dict[prev_idx][char_idx]] == 1){
            isok = false;
            break;
          }
          is_first = false;
        }

        if(isok){
          if(current.size() < dict[prev_idx].size()
             && dict[prev_idx].substr(0,current.size()) == current){
            isok = false;
          }
        }

        res &= isok;
        if(!res){
          current_idx++;
          for(;current_idx < N;current_idx++){
            cin >> current;
          }
          goto found;
        }
      }

      dict.push_back(current);
    }
  found:;
    printf("%s\n",res ? "yes" : "no");
  }
}

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

vector<long long> testCase(){
    int n;
    cin>>n;
    for(long long i = -200; i <= 200; i++){
        for(long long j = -200; j <= 200; j++){
            if(pow(i, 5)-pow(j, 5) == n){
                return {i, j};
            }
        }
    }
    return {-1, -1};
}

int main(){
    int t;
    t = 1;
    // cin>>t;
    while(t--){
        vector<long long> v = testCase();
        cout<<v[0]<<" "<<v[1]<<endl;
    }
}



Measured memory_bytes: 3956
'use strict'
function Main(input) {
    input = input.split("\n");
    const n = parseInt(input[0], 10)
    const arr = input[1].split(' ').map(v => parseInt(v, 10))
    const sum = arr.reduce((pre, cur) => pre + cur)
    let min = -1
    let tmp = 0
    for (let i = 0; i < n - 1; i ++) {
        tmp += arr[i]
        const abs = Math.abs(sum - 2 * tmp)
        if (min < 0 || min > abs) {
            min = abs
        }
    }
    console.log(min)
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 34360
#include <iostream>
#include <math.h>
#include <vector>
#include <stack>
#include <cstdio>
#include <string>
#include <bitset>
#include <list>
#include <set>
#include <algorithm>
#include <numeric>
#include <tuple>
#include <unordered_map>
#include <array>
using namespace std;
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int a[100000] = { 0 };
int main() {
	int N;
	int sum = 0;
	int temp;
	unordered_map<int, int> count;

	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >>temp;
		temp <= N ? a[temp]++ : sum++;
	}
	for (int j = 1; j <= N; j++) sum+=a[j]>= j? a[j]-j:a[j];
	cout << sum;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<math.h>
using namespace std;
int main() {
	int K, S;	cin >> K >> S;
	int ans = 0;
	for (int i = 0; i <= K; ++i) {
		for (int j = 0; j <= K; ++j) {
			if (S - i - j >= 0 && S - i - j <= K) {
				++ans;
			}
		}
	}
	cout << ans << endl;
	cin >> K;
}

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

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define rsz resize
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define FOR(i, a, b) for(int i = a; i < b; i++)
#define odd(x) ((x) % (2))
#define fastio ios_base::sync_with_stdio(false), cin.tie(0);
#define fileio freopen("template.in", "r", stdin), freopen("template.out", "w", stdout);
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
const ll MOD = 1e9 + 7;

int main() {
    fastio;
    //fileio;
        
    string s;
    cin >> s;

    ll sumOfDigits = 0;
    FOR(i, 0, s.size()) {
        sumOfDigits += s[i] - '0';
    }
    if (sumOfDigits % 9) {
        cout << "No\n";
    } else {
        cout << "Yes\n";
    }
    return 0;
}


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

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m, q;    
    while(1){
        cin >> n >> m >> q;
        if(n + m + q == 0) break;
        vector<int> s(q + 1), d(m, (1LL << n) - 1);
        vector<string> b(q + 1), ss(q + 1);
        string tmp = "";
        s[0] = 0;
        rep(i, 0, m) tmp += "0";
        b[0] = tmp;
        rep(i, 1, q + 1){
            cin >> ss[i] >> b[i];
            s[i] = 0;
            rep(j, 0, ss[i].size()){
                s[i] *= 2;
                if(ss[i][j] == '1') s[i]++;
            }
        } 
        rep(i, 0, q){
            rep(j, 0, m){
                if(b[i][j] != b[i + 1][j]){
                    d[j] &= s[i + 1];
                    // cout << i << ' ' << j << ' ' << d[j] << endl;                    
                }else{
                    d[j] &= (1LL << n) - 1LL - s[i + 1];
                    int tmp = (1LL << n) - 1LL - s[i + 1];
                    // cout << " " << i << ' ' << j << ' ' << d[j] << " " << tmp << " " << s[i + 1] << endl;
                }
            }
        }
        string ans = "";
        rep(i, 0, m){
            int cnt = 0;
            char c;
            for(int j = n - 1; j >= 0; j--){
                if(d[i] & (1LL << j)){
                    cnt++;
                    int now = n - 1 - j;
                    // cout << i << ' ' << now << endl;                    
                    if(now < 10) c = '0' + now;
                    else c = 'A' + now - 10;
                }
            }
            if(cnt != 1) c = '?';
            ans += c;
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 4348
//! ----------------------------------------------
//! Framework <https://github.com/vain0x/procon>
//!
//! See the bottom of file for solution.
//! ----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

/// Print values to standard error if debug mode.
#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

/// Read from standard input and parse each word.
/// - `read!(T, U, ..)` parses a line as a tuple of words.
/// - `read![[T]]` parses a line as an array of words.
/// - `read![..; N]` parses `N` lines, using `read!(..)` repeatedly.
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

/// Read a line from standard input.
#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();

    #[allow(deprecated)]
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

fn main() {
    let N = read!(usize);
    let A1 = read![[usize]];
    let A2 = read![[usize]];

    let mut max_count = 0;

    for x in 0..N {
        let count = (0..x + 1)
            .map(|i| A1[i])
            .chain((x..N).map(|i| A2[i]))
            .sum::<usize>();
        max_count = max(max_count, count);
    }

    println!("{}", max_count)
}


Measured memory_bytes: 4352
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <numeric>
#include <limits>
#include <cmath>
#include <iomanip>
 
#define ALL(a)  (a).begin(),(a).end()
 
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;
 
int main() {
    ll n, ans = 0;
    vector<ll> p, q, v;

    cin >> n;

    for (int i = 0; i < n; i++) {
        int temp;
        cin >> temp;
        p.push_back (temp);
    }

    for (int i = 0; i < n; i++) {
        int temp;
        cin >> temp;
        q.push_back (temp);
    }

    for (int i = 0; i < n; i++) {
        v.push_back (i+1);
    }

    int a, b, i = 1;

    do {
        if (p == v) a = i;
        if (q == v) b = i;
        i++;
    } while (next_permutation(ALL(v)));

    cout << abs(b - a) << endl;


 
 
    return 0;
}

Measured memory_bytes: 256
n = gets.to_i
arr = gets.split.map(&:to_i)

plus = {}
minus = {}
arr.each_with_index do |num, ind|
  plus[num + ind] ||= 0
  plus[num + ind] += 1
  minus[ind - num] ||= 0
  minus[ind - num] += 1
end

count = 0
plus.each do |key, p_count|
  m_count = minus[key]
  count += p_count * m_count if !m_count.nil?
end

p count


Measured memory_bytes: 42368
#include<iostream>
#include<algorithm>
#include<bitset>
using namespace std;
int main()
{
    long long int a,b;
    cin>>a>>b;
    bitset<32> b1(a&b),b2(a|b),b3(a^b);
    cout<<b1<<endl;
    cout<<b2<<endl;
    cout<<b3<<endl;
}


Measured memory_bytes: 3172
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<int, P> E;
#define MOD (1000000007ll)
#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	b += MOD;
	a += b;
	a %= MOD;
}

int main(void){
	int n,i;
	double x,ans=0.0;
	string u;
	cin >> n;
	for(i=0; i<n; ++i){
		cin >> x >> u;
		if(u[0]=='B'){
			x *= 380000.0;
		}
		ans += x;
	}
	printf("%10lf\n",ans);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>

#define int long long
#define MOD7 1000000007
#define MOD9 1000000009

#define rep(i, n) for (int i = 0; i < (n); i++)
#define itrep(i, a) for (auto i = (a).begin(); i != (a).end(); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()
#define mp(a, b) make_pair((a), (b))

using namespace std;

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

template<class T> void inputVector(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}

int black[1010][1010];
int white[1010][1010];

int bmemo[1010][1010];
int wmemo[1010][1010];

signed main() {
	int N, K;
	cin >> N >> K;

	rep(i, N) {
		int x, y;
		char c;
		cin >> x >> y >> c;

		bool revX = (x / K) % 2;
		bool revY = (y / K) % 2;
		bool rev = revX ^ revY;

		if (rev) c = c == 'B' ? 'W' : 'B';
		x %= K;
		y %= K;

		if (c == 'B') {
			black[y][x]++;
		} else {
			white[y][x]++;
		}
	}

	rep(y, K) rep(x, K) {
		bmemo[y + 1][x + 1] = black[y][x];
		wmemo[y + 1][x + 1] = white[y][x];
	}
	
	rep(y, K + 1) {
		rep(x, K) {
			bmemo[y][x + 1] += bmemo[y][x];
			wmemo[y][x + 1] += wmemo[y][x];
		}
	}

	rep(x, K + 1) {
		rep(y, K) {
			bmemo[y + 1][x] += bmemo[y][x];
			wmemo[y + 1][x] += wmemo[y][x];
		}
	}

	//cerr << "black:" << endl;
	//for (int y = K; y >= 0; y--) {
	//	cerr << " ";
	//	rep(x, K + 1) cerr << bmemo[y][x] << " ";
	//	cerr << endl;
	//}
	//cerr << "white:" << endl;
	//for (int y = K; y >= 0; y--) {
	//	cerr << " ";
	//	rep(x, K + 1) cerr << wmemo[y][x] << " ";
	//	cerr << endl;
	//}

	int ret = 0;
	rep(y, K) rep(x, K) {
		int num1 = 0, num2 = 0, num3 = 0, num4 = 0;
		num1 = bmemo[K][K] - bmemo[y][K] - bmemo[K][x] + bmemo[y][x];
		if (x > 0 && y > 0)
			num2 = bmemo[y][x] - bmemo[0][x] - bmemo[y][0] + bmemo[0][0];

		if (x > 0)
			num3 = wmemo[K][x] - wmemo[K][0] - wmemo[y][x] + wmemo[y][0];
		if (y > 0)
			num4 = wmemo[y][K] - wmemo[0][K] - wmemo[y][x] + wmemo[0][x];

		int num = num1 + num2 + num3 + num4;

		ret = max(ret, num);
	}

	rep(y, K) rep(x, K) {
		int num = wmemo[K][K] - wmemo[y][K] - wmemo[K][x] + wmemo[y][x];
		if (x > 0 && y > 0)
			num += wmemo[y][x] - wmemo[0][x] - wmemo[y][0] + wmemo[0][0];

		if (x > 0)
			num += bmemo[K][x] - bmemo[K][0] - bmemo[y][x] + bmemo[y][0];
		if (y > 0)
			num += bmemo[y][K] - bmemo[0][K] - bmemo[y][x] + bmemo[0][x];

		ret = max(ret, num);
	}

	cout << ret << endl;

    return 0;
}


Measured memory_bytes: 32000
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.NoSuchElementException;
import java.util.PriorityQueue;

public class Main {
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        int x = sc.nextInt();

        long ans = 0;

        ans += x / 500 * 1000;
        x %= 500;

        ans += x / 5 * 5;

        System.out.println(ans);


    }

    private static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;

        private boolean hasNextByte() {
            if (ptr < buflen) {
                return true;
            } else {
                ptr = 0;
                try {
                    buflen = in.read(buffer);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (buflen <= 0) {
                    return false;
                }
            }
            return true;
        }

        private int readByte() {
            if (hasNextByte())
                return buffer[ptr++];
            else
                return -1;
        }

        private static boolean isPrintableChar(int c) {
            return 33 <= c && c <= 126;
        }

        public boolean hasNext() {
            while (hasNextByte() && !isPrintableChar(buffer[ptr]))
                ptr++;
            return hasNextByte();
        }

        public String next() {
            if (!hasNext())
                throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while (isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }

        public long nextLong() {
            if (!hasNext())
                throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) {
                throw new NumberFormatException();
            }
            while (true) {
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                } else if (b == -1 || !isPrintableChar(b)) {
                    return minus ? -n : n;
                } else {
                    throw new NumberFormatException();
                }
                b = readByte();
            }
        }

        public int nextInt() {
            long nl = nextLong();
            if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
                throw new NumberFormatException();
            return (int) nl;
        }

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

}


Measured memory_bytes: 21076
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>

using namespace std;

#define mod 1000000007

void printmove(string dir, int num)
{
	for(int i = 0; i < num; i++){
		cout << dir;
	}
	return;
}

void solve(int sx, int sy, int tx, int ty)
{
	if (sx < tx){
		printmove("R", tx - sx);
		printmove("U", ty - sy);
	} else {
		printmove("L", sx - tx);
		printmove("D", sy - ty);
	}
	return;
}

int main()
{
	int sx, sy, tx, ty;
	cin >> sx >> sy >> tx >> ty;
	solve(sx, sy, tx, ty);
	solve(tx, ty, sx, sy);
	cout << "D";
	solve(sx, sy - 1, tx + 1, ty);
	cout << "LU";
	solve(tx, ty + 1, sx - 1, sy);
	cout << "R" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

struct mint {
    const int mod = 1e9 + 7;
    long long x;
    
    mint (long long x = 0) : x((x % mod + mod) % mod) {
        
    }
    
    mint& operator=(const long long a) {
        x = a % mod;
        return *this;
    }
    
    mint& operator=(const mint a) {
        x = a.x % mod;
        return *this;
    }
    
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    
    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }
    
    mint& operator-=(const mint a) {
        if ((x += (mod - a.x)) >= mod) x -= mod;
        return *this;
    }
    
    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }
    
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    
    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }
    
    mint pow(long long t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }
    
    mint inv() const {
        return pow(mod - 2);
    }
    
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    
    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll n;
    cin >> n;
    vector<ll> c(n);
    rep(i, n) cin >> c[i];
    sort(all(c));
    vector<mint> e(n + 1);
    e[0] = 1;
    rep(i, n) e[i + 1] = e[i] * 2;
    mint ans = 0;
    rep(i, n) {
        ll r = n - 1 - i;
        mint tmp = e[r];
        if (r > 0) tmp += e[r - 1] * r;
        ans += e[i] * tmp * c[i];
    }
    ans *= e[n];
    cout << ans.x << endl;
    return 0;
}


Measured memory_bytes: 4992
#include<stdio.h>

int main(void)
{
    int a, b, i;
    char op;

    for(i = 0; ; i++)
    {
        scanf("%d %c %d", &a, &op, &b);
        
        if(op == '?')
        {
            break;
        }
        
        else if(op == '+')
        {
            printf("%d\n", a + b);
        }

        else if(op == '-')
        {
            printf("%d\n", a - b);
        }

        else if(op == '*')
        {
            printf("%d\n", a * b);
        }

        else if(op == '/')
        {
            printf("%d\n", a / b);
        }

    }

    return 0;
}


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

using namespace std;

int main()
{
	int h,w,n;
	cin >> h >> w >> n;
	vector<int> area;
	int input;
	for(int i=0;i < n;i ++)
	{
		cin >> input;
		for(int j=0;j < input;j ++)
		{
			area.push_back(i);
		}
	}

	int idx;
	for(int i=0;i < h;i ++)
	{
		if(i%2 == 0)
		{
			for(int j=0;j < w;j ++)
			{
				idx = i*w+j;
				cout << area[idx]+1 << " ";
			}
		}
		else
		{
			for(int j=w;j > 0;j --)
			{
				idx = i*w+j-1;
				cout << area[idx]+1 << " ";
			}
		}
		cout << endl;
	}

}


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


int main() {
    int H,W;
    const int dx[8] = {1,1,0,-1,-1,-1,0,1};
    const int dy[8] = {0,-1,-1,-1,0,1,1,1};
    cin >> H >> W;
    string S[H];
    for (int i = 0; i < H; ++i){
        cin >> S[i];
    }
    for (int i = 0; i < H; ++i){
        for (int j = 0; j < W; ++ j){
            if (S[i][j] == '#') continue;
            
            int count = 0;
            for (int d = 0; d < 8; ++d){
                if ( i + dx[d] < 0 or i + dx[d] >= H) continue;
                if ( j + dy[d] < 0 or j + dy[d] >= W) continue;
                
                if ( S[i + dx[d]][j + dy[d]] == '#') count += 1;
            }
            
            S[i][j] = char (count + '0');
        }
    }
    for (int i = 0; i < H; ++i){
        for (int j = 0; j < W; ++j){
            cout <<  S[i][j];
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main()
{
	char a[3];
	char b[3];
	char c[3];
	int flag = 0;
	for (int i = 0; i < 3; i++)
	{
		cin >>a[i];
	}
	for (int i = 0; i < 3; i++)
	{
		cin >> b[i];
		c[2 - i] = b[i];
	}
	
	for (int i = 0; i < 3; i++)
	{
		if (a[i] == c[i])
		{
			flag++;
		}
		else
		{
			flag--;
		}
	}

	if (flag == 3)
	{
		cout << "YES";
	}

	else
	{
		cout << "NO";
	}
	return 0;
}


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

flag = 'b'
b_num = 0

for i in range(len(b)):
    if b[i] == '.':
        continue
    else:
        b_num = b_num*10+int(b[i])

#print(b_num)
#exit()

print(int(a)*b_num//100)

Measured memory_bytes: 61764
#include <iostream>
#include <vector>
#include <valarray>
#include <cmath>
// #include "../cxx-prettyprint/prettyprint.hpp"

std::vector<std::valarray<int>> create_bitarrays(int length) {
    std::vector<std::valarray<int>> bitarrays;
    for (int i = 0; i < std::pow(2, length); i++) {
        std::valarray<int> bits(0, length + 1);
        for (int j = 0; j < length; j++) {
            bits[j + 1] = i >> j & 1;
        }
        bitarrays.push_back(bits);
    }
    return bitarrays;
}

int main() {
    int D, G;
    std::cin >> D >> G;

    std::valarray<int> level(0, D + 1);
    std::valarray<int> p(0, D + 1);
    std::valarray<int> c(0, D + 1);
    for (int i = 1; i <= D; i++) {
        level[i] = i;
        std::cin >> p[i] >> c[i];
    }
    std::valarray<int> complete_scores = level * 100 * p + c;

    int min_problems = p.sum();
    for (std::valarray<int> bits : create_bitarrays(D)) {
        int score_rest = G - (bits * complete_scores).sum();
        if (score_rest <= 0) {
            min_problems = std::min(min_problems, (bits * p).sum());
        } else if (score_rest > 0) {
            for (int i = D; i >= 1; i--) {
                int n_problems = (score_rest + (i * 100) - 1) / (i * 100);
                if (bits[i] == 0 & n_problems < p[i]) {
                    min_problems = std::min(min_problems, (bits * p).sum() + n_problems);
                    break;
                }
            }
        }
    }
    std::cout << min_problems << std::endl;
}


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

int main(){
  int n=0;
  int num=0,s1p=0,s2p = 0;
  cin >> n;
  for(int i = 0; i < n; i++){
    string s1, s2;

    cin >> s1 >> s2;
    if (s1.size() < s2.size()){
      num = s2.size();
    }else{
      num = s1.size();
    }
    if(s1 == s2){
      s1p += 1;
      s2p += 1;
    }else if (s1 < s2){
      s2p += 3;
    }else {
      s1p += 3;
    }
    //cout << s1 << " " << s2 << " " << num << endl;
  }
  cout << s1p << " " << s2p << endl;

}


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

using namespace std;

static const int INF = 1e9 + 7;

template<typename T>
using Vec = vector<T>;

template<typename T, typename T2>
using P = pair<T, T2>;

template<typename... Args>
using Tup = tuple<Args...>;

template<typename T>
using qp = priority_queue<T, Vec<T>, greater<T> >;

template<typename T>
using pq = priority_queue<T>;

using llong = long long;
using ullong = unsigned long long;
using uint = unsigned int;

void hawawa()
{
  llong x, y;
  cin >> x >> y;
  if (x == y || x % y == 0) {
    cout << "-1\n";
  } else {
    cout << x * (y + 1) << "\n";
  }
}

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


Measured memory_bytes: 256
/////////////////////////////////////////////////////////
//
//  c/temp.cpp file
//  Last Updated: 2018-10-23 ...Maybe
//
//    I hope you adding this code to the setting file
//    alias g++='g++ -std=c++1y -DDEBUG_LOCAL'
//
/////////////////////////////////////////////////////////

#include <bits/stdc++.h>

using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back

//#define int long long

#define _overload3(_1,_2,_3,name,...) name
#define _REP(i,n) REAP(i,0,n)
#define REAP(i,a,b) for(int i=int(a);i<int(b);++i)
#define REP(...) _overload3(__VA_ARGS__,REAP,_REP,)(__VA_ARGS__)

#define _REPR(i,n) REAPR(i,n,0)
#define REAPR(i,a,b) for(int i=int(a-1);i>=int(b);--i)
#define REPR(...) _overload3(__VA_ARGS__,REAPR,_REPR,)(__VA_ARGS__)

#define ALL(a) a.begin(),a.end()
#define rALL(a) a.rbegin(),a.rend()

#define coutALL(a) {int loop_coutALL=0;for(auto e:a) cout<<(loop_coutALL++?" ":"")<<e; cout<<endl;}

#define coutYN(a) cout<<((a)?"YES":"NO")<<endl;
#define coutYn(a) cout<<((a)?"Yes":"No")<<endl;
#define coutyn(a) cout<<((a)?"yes":"no")<<endl;

#define pcnt __builtin_popcount
#define buli(x) __builtin_popcountll(x)

const int INF=1145141919;
//const long long INF=114514191911451419;
const int MOD=(int)1e9+7;
const double EPS=1e-12;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};
//const int dx[]={-1,-1,-1,0,1,1,1,0},dy[]={-1,0,1,1,1,0,-1,-1};

using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;

typedef pair<int,int> pii;
typedef pair<int,string> pis;
typedef pair<string,int> psi;
typedef pair<string,string> pss;

typedef long long ll;

template<typename T> istream &operator >> (istream &is, vector<T> &v){for(T &x:v) is>>x;return is;}
template<typename T> ostream &operator << (ostream &os, vector<T> &v){int i=0;for(T &x:v) os<<(i++?" ":"")<<x;return os;}

ll rev(ll n){ll x=0;for(;n>0;){x=x*10+n%10;n/=10;}return x;}

template<class T> ll upper(T n,T m){return (n+m-1)/m;};
template<class T> ll rounding(T n){return (long double)n+0.5;};

template<class T> bool inG(T x,T n){return 0<=x && 0<n;}
template<class T> bool outG(T x,T n){return x<0 || n<=x;}

inline int qp(int a,ll b){if(!b)return 1;int ans=1;do{if(b&1)ans=1ll*ans*a;a=1ll*a*a;}while(b>>=1);return ans;}
inline int qp(int a,ll b,int mo){if(!b)return 1;int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}

inline ll fac(ll k,ll n){ll a=1;for(int i=0;i<n;i++)a*=k--;return a;}
inline ll fac(ll k,ll n,int mo){ll a=1;for(int i=0;i<n;i++)a*=k--,a%=mo;return a;}

inline int dsum(ll n){int a=0;for(;n;n/=10)a+=n%10;return a;}

struct Arithmetic{Arithmetic(){cin.tie(0);ios::sync_with_stdio(0);cout<<fixed<<setprecision(20);}};

//#define DEBUG_LOCAL

#ifdef DEBUG_LOCAL
template<typename T> void deb(T a){cerr<<"deb: "<<a<<"です"<<endl;}
#define debl {cerr<<"debug: "<<__LINE__<<"行目だ"<<endl;}
void what_cr(){cout<<__GCC_ATOMIC_CHAR16_T_LOCK_FREE<<" ←？"<<endl;}
//ori_func S

//ori_func E
#else
template<typename T>void deb(T a){}
#define debl
void what_cr(){}void t_t(){}
#endif

signed main(){

  Arithmetic Exception;

  int a,b;
  cin>>a>>b; a=b-a;

  cout<<(a+1)*a/2-b<<endl;

  return 0;

}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<set>
#include<algorithm>
using namespace std;

int main(){
  
  int n, ans = 0;
  string s, x, y;
  
  cin >> n >> s;
  
  for(int i = 0;i < s.size() - 1;i++){

    set<char> x, y;
    for(int j = 0;j < s.size();j++){
      if(j <= i) x.insert(s[j]);
      else y.insert(s[j]);
    }
    
    int cnt = 0;
    for(char ch = 'a';ch <= 'z';ch++){
      if(x.count(ch) && y.count(ch)) cnt++;
    }
    
    ans = max(ans, cnt);
  }
  
  cout << ans << endl;
  
  return 0;
}

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007;

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

int main(void){
    int N; cin >> N;
    VI a(N); REP(i,N) cin >> a[i];
    bool flag = false;
    REP(i,N){
        if(a[i]%2){
            flag = true;
            break;
        }
    }
    cout << (flag ? "first" : "second") << endl;
    return 0;
}

Measured memory_bytes: 640
using System;
using System.Collections.Generic;
using System.Text;
using System.Numerics;
using System.IO;


namespace SolutionCS
{
    class Program
    {

        static int A;
        static int B;
        static int Q;
        static long[] sh;
        static long[] te;

        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');

            A = int.Parse(s[0]);
            B = int.Parse(s[1]);
            Q = int.Parse(s[2]);

            sh = new long[A];
            for (int i = 0; i < A; i++)
            {
                sh[i] = long.Parse(Console.ReadLine());
            }

            te = new long[B];
            for (int i = 0; i < B; i++)
            {
                te[i] = long.Parse(Console.ReadLine());
            }


            for (int i = 0; i < Q; i++)
            {
                long pos = long.Parse(Console.ReadLine());

                long sh_l;
                long sh_r;
                SearchSide(pos, out sh_l, out sh_r, sh);

                long te_l;
                long te_r;
                SearchSide(pos, out te_l, out te_r, te);


                long a0 = Math.Min(Math.Abs(sh_r - pos) + Math.Abs(sh_r - te_l), Math.Abs(sh_l - pos) + Math.Abs(sh_l - te_l));
                long a1 = Math.Min(Math.Abs(sh_r - pos) + Math.Abs(sh_r - te_r), Math.Abs(sh_l - pos) + Math.Abs(sh_l - te_r));

                long b0 = Math.Min(Math.Abs(te_r - pos) + Math.Abs(te_r - sh_l), Math.Abs(te_l - pos) + Math.Abs(te_l - sh_l));
                long b1 = Math.Min(Math.Abs(te_r - pos) + Math.Abs(te_r - sh_r), Math.Abs(te_l - pos) + Math.Abs(te_l - sh_r));

                Console.WriteLine(Math.Min(Math.Min(a0, a1), Math.Min(b0, b1)));
            }
        }


        static void SearchSide(long pos, out long left, out long right, long[] a)
        {
            if(pos < a[0])
            {
                left = long.MinValue / 10;
                right = a[0];
                return;
            }

            int lb = 0;
            int rb = a.Length;

            if (pos > a[rb - 1])
            {
                right = long.MaxValue / 10;
                left = a[rb - 1];
                return;
            }

            int p = rb / 2;

            while(!(a[p] < pos && pos < a[p+1]))
            {
                if(a[p] < pos)
                {
                    lb = p;
                }
                else
                {
                    rb = p;
                }
                p = (rb + lb) / 2;
            }

            left = a[p];
            right = a[p + 1];
        }
    }
}




Measured memory_bytes: 17988
import * as fs from 'fs';

namespace AtCoder.abc087 {

    export class Program {

        constructor(private readonly args: string[][]) {
        }

        /**
         * in
         *
         * out
         *
         */
        main(this: Program): void {
            const [x]: number[] = this.args[0].map(Number);
//            const x: number = parseInt(this.args[0][0], 10);
            const a: number = parseInt(this.args[1][0], 10);
            const b: number = parseInt(this.args[2][0], 10);

            let wk: number = x - a;
            console.log(wk % b);

        }
    }
}

const args: string[][] = fs.readFileSync('/dev/stdin', 'utf8').trim().split('\n').map(r => r.split(' '));
const prg: AtCoder.abc087.Program = new AtCoder.abc087.Program(args);
prg.main();


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

#define ll                 long long
#define mod                1000000007
#define pb                 push_back
#define vecsort(v)         sort(v.begin(),v.end())
#define lcm(x,y)           (x/__gcd(x,y))*y
#define forn(i,n)          for(i = 0 ; i < n ; i++)
#define deb(x)             cout << #x << " " << x << endl;
#define T(t)               cout << "Case " << t <<": ";
#define scan(v)            for(int i = 0; i<n; i++){ll x;cin>>x;v.pb(x);}
#define fast_cin           ios_base::sync_with_stdio(false);cin.tie(NULL);



int main() {
     
       #ifndef ONLINE_JUDGE
       //freopen("read.txt","r",stdin);
      // freopen("write.txt","w",stdout);
       #endif

       set < string > S;

       ll n ;
       cin >> n ;
       for( int i = 0 ; i < n ; i++ ){
              string s;
              cin >> s;
              S.insert(s);
       }
       cout << S.size() << endl;





       return 0;

}

Measured memory_bytes: 19156
/****************************************************************************************************
                                        SUBMITTED BY-

                                                AISH_07

****************************************************************************************************/
#include<bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define ll long long
#define sl set<ll>
#define vs vector<string>
#define pb push_back
#define vl vector<ll>
#define vi vector<int>
#define PI  3.14159265
#define mod 998244353
int main()
{
    int s;
    cin>>s;

    int i,prev=s;
    set<int>se;
    se.insert(s);
    for( i=2;i<=1000000;i++)
    {
        if(prev%2==0)
        {

            if(!binary_search(se.begin(),se.end(),prev/2))
            {
                se.insert(prev/2);
                prev/=2;
            }
            else
              break;
        }
        else
        {

            if(!binary_search(se.begin(),se.end(),3*prev+1))
            {
                se.insert(3*prev+1);
                prev=3*prev+1;
            }
            else
              break;
        }
    }
    cout<<i<<"\n";
    return 0;
}


Measured memory_bytes: 3616
li = []
while True:
    li.append(list(map(int, input().split())))
    if li[-1] == [0,0]:
        li.pop()
        break
for l in li:
    print('#'*l[1])
    for i in range(l[0]-2):
        print('#' + '.'*(l[1]-2) + '#')
    print('#'*l[1])
    print('')


Measured memory_bytes: 5624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define PA pair<ll,ll>
#define FOR(I,A,B) for(ll I = int(A); I < int(B); ++I)
#define FORR(I,A,B) for(ll I = int((B)-1); I >= int(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e16+7;
const ll MOD=1e9+7;

int main(){
	ll H,W,h,w;
	cin >> H >> W >> h >> w;
	cout << H*W + h*w -h*W - w*H << endl;

}

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

typedef long long ll;
typedef long double ld;
typedef pair < int, int > pii;
typedef pair < ll, ll > pll;

const int INF = 1000000007;
const ll INFLL = 1000000000000000007;

#define st first
#define nd second
#define pb push_back
#define _boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

// ***************************** CODE ***************************** //

const int MAX = 3e3 + 7;

ll tab[MAX];
ll w[MAX][MAX];
ll dp[MAX][MAX];

ll calc(int l, int r)
{
    if(w[l][r])
        return dp[l][r];
    w[l][r] = true;

    if(l == r)
    {
        dp[l][r] = tab[l];
        return dp[l][r];
    }

    dp[l][r] = max(tab[l] - calc(l+1, r), tab[r] - calc(l, r-1));
    return dp[l][r];
}

int main() {
    _boost;

    int n; cin >> n;
    for(int i = 0; i < n; i++)
        cin >> tab[i];

    cout << calc(0, n-1);

    return 0;
}


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

//read_code(drken)
int main() {
    ll n;cin>>n;
    string a = "";
    while(n>0){
        --n;
        a += 'a' + (n%26);
        n/=26;
    }
    reverse(a.begin(),a.end());
    cout<<a<<endl;
	return 0;
}

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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << std::setprecision(10);

  int n; std::cin >> n;
  int prv;
  bool ok = true;
  vi h(n);
  rep(i, n) {
    std::cin >> h[i];
    h[i]--;
  }
  srep(i, 1, n) {
    if (h[i-1] > h[i]) h[i]++;
    if (h[i-1] > h[i]) ok = false;
  }
  std::cout << (ok ? "Yes" : "No") << "\n";
}


Measured memory_bytes: 640
#include<stdio.h>
int main(void){
   long A,B,K;
   scanf("%ld %ld %ld",&A,&B,&K);
   if(A>=K){
      A -=K;
   } else if(A+B<K) {
      A=0;
      B=0;
   } else {
      B -=K;
      B +=A;
      A=0;
   }
   printf("%ld %ld",A,B);
   return 0;
}


Measured memory_bytes: 1700