akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define read()          freopen("in.txt","r",stdin)
#define write()         freopen("out.txt","w",stdout)
#define sf(n)           scanf("%d",&n)
#define sfd(n)          scanf("%lf",&n)
#define sl(x)           scanf("%I64d",&x)
#define sfl(n)          scanf("%lld", &n)
#define sfc(n)          scanf(" %c",&n)
#define sful(n)         scanf("%ull",&n)
#define ull             unsigned long long int
#define endll           pf("\n")
#define pf              printf
#define PI              acos(-1.0)
#define eps             1e-12
#define mem(a,b)        memset(a,b,sizeof(a))
#define pb              push_back
#define xx              first
#define yy              second
#define pii             pair<int, int>
#define pll             pair<ll, ll>
#define MP make_pair
#define ll              long long
#define uniq(a)      a.erase(unique(a.begin(), a.end()), a.end())
#define cnd tree[idx]
#define lnd tree[idx<<1]
#define rnd tree[(idx<<1)+1]
#define lndp (idx<<1),(b),((b+e)>>1)
#define rndp ((idx<<1)+1),(((b+e)>>1)+1),(e)
#define inf 1999999999
#define MX 100005
#define MOD 1000000007
#define var    int i,j,k,z=0,c=0,t,x,y,l,r,mid
//int dx[8]={0,0,1,1,-1,-1,1,-1};  //8 direction
//int dy[8]={1,-1,1,-1,1,-1,0,0};
//int dx[4]={1,-1,0,0};  //4 direction
//int dy[4]={0,0,1,-1};

ll n,m,a[200005];

int main()
{
    ll var;
    sfl(n);
    z=0;
    for(i=0;i<n;i++)
    {
        sfl(x);
        if(x%2==0)
        {
            if(x%3!=0 && x%5!=0)
            {
                z=1;
            }
        }
    }
    if(z==0)
    {
        pf("APPROVED\n");
    }
    else pf("DENIED\n");
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};
const int MAX = 510000;
const ll MOD = 10000000000007;

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

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

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

int main() {

    ll N,M;
    cin >>N>>M;
    
    cout << N*(N-1)/2+M*(M-1)/2 << endl;


    return 0;
    

}

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

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)

using ll = long long;
using P = std::tuple<int,int>;

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

int N;
std::vector<int> A[100010]; // A[i] = {k | a[k] = i}

int solve(int root){
    int loser_n = A[root].size();
    
    if(loser_n == 0){return 0;}
    
    std::priority_queue<int> q;
    for(const int v : A[root]){
        q.emplace(solve(v));
    }

    int res = 0, depthOffset = 1;
    while(!q.empty()){
        int n = q.top(); q.pop();
        res = max(res, n + depthOffset);

        ++depthOffset;
    }

    // printf("%d: %d\n", root, res);
    return res;
}

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

    std::cin >> N;

    for(int i=2;i<=N;++i){
        int a;
        std::cin >> a;

        A[a].emplace_back(i);
    }

    // for(int i=1;i<=N;++i){
    //     printf("%d: ", i);
    //     for(int j : A[i]){
    //         printf("%d, ", j);
    //     }
    //     puts("");
    // }

    std::cout << solve(1) << std::endl;
    
}


Measured memory_bytes: 13568
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <limits>
#include <algorithm>
#include <map>
#include <iterator>
#include <queue>

using namespace std;

#define repd(i,a,b) for (int i=(a);i<(b);++i)
#define rep(i,n) repd(i,0,n)
#define rrepd(i,a,b) for (int i=(a-1);i>=(b);--i)
#define rrep(i,n) rrepd(i,n,0)
typedef long long ll;
typedef pair<int, int> P;


int main(int argc, const char * argv[]) {

  int n;
  cin >> n;
  vector<int> l(n);
  rep(i, n){
    cin >> l[i];
  }
  long ans = 0;
  sort(l.begin(), l.end());
  rep(i,n-2){
    repd(j,i+1,n-1){
      repd(k,j+1,n){
        // cout << l[i] << "," << l[j] << "," << l[k] << endl;
        // cout << i << "," << j << "," << k << endl;
        if (l[k] < l[i] + l[j]) ans++;
      }
    }
  }
  cout << ans << endl;
  return 0; 
}


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

Measured memory_bytes: 1064
import java.util.*;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        
        System.out.println((a*b)+" "+((a+b)*2));
        
    }
}



Measured memory_bytes: 26308
N, W = map(int, input().split())
V = 10 ** 5
inf = 10 ** 18
dp = [inf] * (V + 1)
dp[0] = 0

for n in range(1, N+1):
    w, v = map(int, input().split())
    for i in range(v, V+1)[::-1]:
        if dp[i-v]+w <= W:
            dp[i] = min(dp[i], dp[i-v]+w)

for i in range(V+1)[::-1]:
    if dp[i] < inf:
        print(i)
        break


Measured memory_bytes: 41836
#include<iostream>
#include<algorithm>

using namespace std;

int main(int argc, char** argv) {
  int N;
  cin >> N;
  int Hmax = 0;
  int ans = 0;
  for (int i = 0; i < N; i++) {
  	int h;
    cin >> h;
    if (h >= Hmax) ans++;
    Hmax = max(Hmax, h);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;

ll f(ll a, ll b){
    if(b%a == 0)
        return (b / a * 2 - 1)*a;
    return b / a*a*2+ f(b%a, a);
}

int main(){
    ll N, X;
    cin >> N >> X;
    ll ans = N + f(min(N - X, X), max(N - X, X));
    cout << ans << endl;
}

Measured memory_bytes: 256
from functools import reduce
import math

def main():
    # 文字列の2進数を数値にする
    # '101' → '5'
    # 文字列の頭に'0b'をつけてint()にわたす
    # binary = int('0b'+'101',0)

    # 2進数で立っているbitを数える
    # 101(0x5) → 2
    # cnt_bit = bin(5).count('1')
    
    # N! を求める
    # f = math.factorial(N)

    # N の逆元
    # N_inv = pow(N,MOD-2,MOD)

    # nCr
    # Nの階乗 * rの階乗の逆元 * n-rの階乗の逆元
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    INF = float("inf")

    # 大きな素数
    MOD = 10**9+7
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    N = int(input().rstrip())
    a = list(int(_) for _ in input().split())
    cnt_4time = 0
    cnt_2time = 0
    for i in range(N):
        if a[i] % 4 == 0:
            cnt_4time +=1
        elif a[i] % 2 ==0:
            cnt_2time +=1
    N = N - (cnt_2time//2)*2
    if N <= 2*(cnt_4time)+1:
        print('Yes')
    else:
        print('No')
    
if __name__ == '__main__':
    main()


Measured memory_bytes: 14596
/*BISMILLAH
THE WHITE WOLF
NO DREAM IS TOO BIG AND NO DREAMER IS TOO SMALL*/

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<long long> vll;
typedef vector<int> vi;

#define io ios_base::sync_with_stdio(false)
#define pb push_back
#define eb emplace_back
#define mod    1000000007
#define PI 2*acos(0.0)

const int N = 100005;

int32_t main()
{
    io;
    int n;
    cin>>n;
    ll tx = 0;
    vi inp(n);
    for(int i = 0; i< n;i++)
    {
        cin>>inp[i];
        tx ^= inp[i];
    }
    for(int i = 0; i< n; i++)
        cout<<(tx^inp[i])<<" ";
    return 0;
}


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

typedef long long ll;
using namespace std;

int main() {
	ios::sync_with_stdio(false);
	//	srand(time(NULL));
	int x, y; cin >> x >> y;
	if(x % y == 0)
		cout << -1 << endl;
	else cout << x << endl;
	return 0;
}


Measured memory_bytes: 256
use std::io;
use std::str::FromStr;

fn input<T:FromStr>() -> T {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    line.trim().parse().ok().unwrap()
}

fn input_vec() -> Vec<u64> {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    line.split_whitespace().map(|s| s.parse().unwrap()).collect()
}

fn binary_search<F>(mut ok: i64, mut ng: i64, is_ok: F) -> i64
    where
        F: Fn(usize) -> bool
    {
        while (ok - ng).abs() > 1 {
            let mid = (ok + ng) / 2;
            if is_ok(mid as usize) {
                ok = mid;
            } else {
                ng = mid;
            }
        }
        ok
}

fn main() {
    let n: i64 = input();
    let mut a_vec = input_vec();
    let mut b_vec = input_vec();
    let mut c_vec = input_vec();
    a_vec.sort();
    b_vec.sort();
    c_vec.sort();

    // println!("{:?}", a_vec);
    // println!("{:?}", b_vec);
    // println!("{:?}", c_vec);
    let mut sum = 0;
    for b in &b_vec {
        let a_idx = binary_search(-1, n, |idx| {
            a_vec[idx] < *b
        });
        let c_idx = binary_search(n, -1, |idx| {
            c_vec[idx] > *b
        });
        // println!("{}, {}, {}", a_idx, *b, c_idx);
        sum += (a_idx + 1) * (n - c_idx);
    }

    println!("{}", sum);
}


Measured memory_bytes: 13560
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=1010010010010010000;
#define fi first
#define se second
#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)
template<class T> inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template<class T> inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
int main(){
    int n;cin >> n;
    vl a(n);
    rep(i,n){
        cin >> a[i];
    }
    ll ans=LINF;
    int flip=0;
    rep(si,2){
        int f=flip;
        ll cnt=0;
        ll sum=0;
        rep(i,n){
            if(f){
                if(sum+a[i]<=0){
                    cnt+=1-(sum+a[i]);
                    sum=1;
                }
                else{
                    sum=sum+a[i];
                }
            }
            else{
                if(sum+a[i]>=0){
                    cnt+=sum+a[i]+1;
                    sum=-1;
                }
                else{
                    sum=sum+a[i];
                }
            }
            f=f^1;
        }
        ans=min(ans,cnt);
        flip^=1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
let A: Int = Int(readLine()!)!
let B: Int = Int(readLine()!)!
let C: Int = Int(readLine()!)!
let X: Int = Int(readLine()!)!
var res: Int = 0
for a in 0...A {
    for b in 0...B {
        for c in 0...C {
            if 500*a + 100*b + 50*c == X { res += 1 }
        }
    }
}
print(res)

Measured memory_bytes: 3824
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define MOD 1000000007

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  int t = 1;
  int cnt = 0;
  for (int i = 0; i < n; ++i) {
    if (t == a[i]) {
      t++;
      cnt++;
    }
  }
  if (cnt == 0) {
    cout << -1 << endl;
  } else {
    cout << n - cnt << endl;
  }
  return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define SZ(v) ((int)(v).size())
#define zero(v) memset(v,0,sizeof(v))
#define rep(i,n) for(int i=0;i<(n);i++)
#define foreach(it,c) for(__typeof(c.begin()) it=c.begin();it!=c.end();it++)
#define all(v) (v).begin(),(v).end()
template<typename T>inline bool chkmin(T &a,const T &b){return a>b?a=b,1:0;}
template<typename T>inline bool chkmax(T &a,const T &b){return a<b?a=b,1:0;}
typedef long long ll;
typedef unsigned uint;
const int INF=0x3f3f3f3f;
const double EPS=1e-10;
typedef pair<int,int>P;
int inline in(){int x=0,c;for(;(uint)((c=getchar())-'0')>=10;)
{if(c=='-')return -in();if(!~c)throw ~0;}do{x=(x<<3)+(x<<1)+(c-'0');}
while((uint)((c=getchar())-'0')<10);return x;}
int n,m,k;
const int Maxn=10;
const int Maxm=1000;
string s[Maxn];
vector<int>v[Maxm];
int main(){
	cin>>n>>m>>k;
	rep(i,n)cin>>s[i];
	int ans=INF;
	rep(mask,1<<(n-1)){
		rep(j,Maxm)v[j].clear();
		int nv=__builtin_popcount(mask)+1;
		int cnt=__builtin_popcount(mask);
		bool ok=true;
		rep(j,m){
			int sum=0;
			rep(i,n){
				if(s[i][j]=='1')sum++;
				if(mask>>i&1){
					v[j].push_back(sum);sum=0;
				}
			}
			v[j].push_back(sum);sum=0;
			if(*max_element(all(v[j]))>k){
				ok=false;break;
			}
		}
		if(!ok)continue;
		vector<int>u(nv);
		rep(j,m){
			rep(p,nv)u[p]+=v[j][p];
			if(*max_element(all(u))>k){
				rep(p,nv)u[p]=v[j][p];
				cnt++;
			}
		}
		chkmin(ans,cnt);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 384
/* Atcoder abc123a
 * See tasks at: https://atcoder.jp/contests/abc123/tasks/abc123_a
 */
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
using ll = long long;
int main()
{
    int n = 5;
    
    vector<int> a(n);
    for (int i=0; i < n; i++)
    {
        int val;
        cin >> val;
        a[i] = val;
    }

    int k;
    cin >> k;

    for (int i=0; i < n-1; i++)
    {
        for (int j=i+1; j < n; j++)
        {
            if (a[j] - a[i] > k)
            {
                cout << ":(" << endl;
                return 0;
            }
        }
    }
    
    cout << "Yay!" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
#include <list>
#include <map>

using namespace std;    
typedef long long ll;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

ll minDiff(vector<ll> v, ll val){
    ll ans = 24;
    for(int i = 0; i < v.size(); i++){
        ans = min(ans, abs(v[i] - val));
    }
    return ans;
}

int main(){

    ll N;
    cin >> N;

    vector<ll> v(N);
    for(int i = 0; i < N; i++) cin >> v[i];

    sort(all(v));
    vector<ll> left;
    vector<ll> right;

    if(N == 1){
        cout << v[0] << endl;
        return 0;
    }

    for(int i = 0; i < N; i++){
        if(left.size() == 0) left.push_back(v[i]);
        else if(right.size() == 0) right.push_back(v[i]);
        else{
            ll l = minDiff(left, v[i]);
            ll r = minDiff(right, v[i]);
            if(l < r) right.push_back(v[i]);
            else left.push_back(v[i]);
        }
    } 

    sort(all(left));
    sort(all(right));
    ll lmin = left[0];
    ll rmin = right[0];
    for(int i = 0; i < left.size() - 1; i++){
        lmin = min(lmin, left[i+1] - left[i]);
    }; 
    for(int i = 0; i < right.size() - 1; i++){
        rmin = min(rmin, right[i+1] - right[i]);
    }; 

    cout << min( {
        lmin,
        rmin,
        min( right.back() + left.back() , 24 - abs( right.back() + left.back() )   )
    } )
    << endl;

}

Measured memory_bytes: 256
from collections import defaultdict
d = defaultdict(list)

N, M = map(int, input().split())
for _ in range(M):
    s, c = map(int, input().split())
    d[s].append(c)

val = [-1] * N

# とりあえず桁を確定させる
for k, v in d.items():
    if len(set(v)) > 1:
        print(-1)
        exit()
    val[k - 1] = v[0]

if N == 1:
    ans = max(0, val.pop())
    print(ans)
    exit()
if N >= 2:
    if val[0] == 0:
        print(-1)
        exit()

    if val[0] == -1:
        val[0] = 1
    for i in range(N):
        val[i] = max(0, val[i])

    print(*val, sep="")


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

// definition {{{ 1

// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)

#define Scll(x) scanf("%llu", &x)
#define Scll2(x,y) scanf("%llu%llu", &x, &y)
#define Scll3(x,y,z) scanf("%llu%llu%llu", &x, &y, &z)

#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2

// constants {{{ 2
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// }}} 2

// systems {{{ 2
#define Rep(x,y) for(int x = 0; x < y; x++)
#define Repe(x,y,z) for(int x = z; x < y; x++)
// }}} 2

// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n");
// }}} 2

// }}} 1

int main() {

    char s[100003];

    Scs(s);

    int slen = strlen(s);

    int hit = s[0];

    int cnt = 0;

    Repe(i,slen,1){
        if( s[i] != hit )cnt++;
        hit = s[i];
    }

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

    return 0;
}



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

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

  int n;
  cin >> n;

  vector<int> a(n + 2, 0);
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }

  int maxn = *max_element(a.begin(), a.end());
  int minn = *min_element(a.begin(), a.end());

  int total = 0;

  for (int i = 1; i < n + 2; i++) {
    total += abs(a[i] - a[i - 1]);
  }

  for (int i = 1; i <= n; i++) {
    int curr = abs(a[i] - a[i - 1]) + abs(a[i + 1] - a[i]);
    int next = abs(a[i + 1] - a[i - 1]);

    int diff = abs(next - curr);

    cout << total - diff << endl;
  }

  return 0;
}

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

#define MAX 1010
#define BLOCK '*'

int solve(int n, char G[MAX][MAX]){
  int W[MAX][MAX];
  
  for(int i = 0 ; i < n ; i++){
    W[0][i] = (G[0][i] == BLOCK) ? 0 : 1;
    W[i][0] = (G[i][0] == BLOCK) ? 0 : 1;
  }
  
  int maxWidth = 0;
  
  for(int i = 0 ; i < n ; i++){
    for(int j = 0 ; j < n ; j++){
      if(G[i][j] == BLOCK) W[i][j] = 0;
      else{
	W[i][j] = min(W[i-1][j-1], min(W[i-1][j], W[i][j-1])) + 1;
	maxWidth = max(maxWidth, W[i][j]);
      }
    }
  }
  return maxWidth;
}

int main(){
  int n;
  char G[MAX][MAX];
  
  while(cin >> n, n){
    for(int i = 0 ; i < n ; i++){
      for(int j = 0 ; j < n ; j++){
	cin >> G[i][j];
      }
    } 
    cout << solve(n, G) << endl;
  }
  return 0;
}

Measured memory_bytes: 6104
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
 
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define VSORT(v) sort(v.begin(), v.end())
#define DVSORT(v) sort(v.begin(), v.end(),greater<int>())
#define SORT(v, n) sort(v, v+n)
#define DSORT(v,n) sort(v, v+n,greater<int>())
#define vi vector<int>
#define pb push_back
#define P pair<int,int>
 
template <class T> void chmin(T&a,const T&b) { a = min(a,b); }
template <class T> void chmax(T&a,const T&b) { a = max(a,b); }
 
void print(){cout<<endl;}
template <class Head, class... Tail>
void print(Head&& h,Tail&&... t){ 
	if(sizeof...(t)==0)
		cout<<h;
	else
		cout<<h<<' ';
	print(move(t)...);
}
 
const double EPS =1e-9;
const long INF =2147483647;//32bit 2*1e+9
const long MOD =1e+9+7;
#define PI 3.14159265258979
 
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

int main(void){
	bool flug=false;
	int counter=0;
	int N,A[200]={};
	cin>>N;
	REP(i,N) cin>>A[i];
	while(1){
		REP(i,N){ 
			if(A[i]%2==1){
				flug=true; break;
			}else A[i]/=2;
		}
	if(flug) break;
	counter++;
	}
	print(counter);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define forn(i,n1, n2) for (ll i = n1; i < n2; i++)
#define w(t) ll t;cin>>t;while(t--)
#define en "\n"
#define f first
#define s second
const ll mod = 1000000007;
using namespace std;
ll i, n, m, x, y, z, j, k, l, mn = LLONG_MAX, mx = 0, c, a[2000005], r, cnt = 0, sum = 0,p;
string str;
char ch;
set<ll> s;
map<ll, ll> mp;
vector<vector<ll>> g;
vector<ll> v;
char grid[60][60];
ll d[60][60];
bool vis[60][60];
ll dx[] = {0, 1, 0, -1, 1, -1, -1, 1};
ll dy[] = {1, 0, -1, 0, 1, -1, 1, -1};
ll gcd(ll a , ll b)
{
    if(b==0)return a;
    return gcd(b,a%b);
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
  
    ll k1,k2,k3,k4,a,b,c,d;
    cin>>a>>b>>c>>d;
    k1=a*c;
    k2=a*d;
    k3=b*d;
    k4=b*c;
    cout<<max(max(k1,k2),max(k3,k4));
 
    return 0;
}

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

int main(){
    int N;
    cin>>N;
    double A[N],A2[N];
    for(int i=0;i<N;i++){
        cin>>A[i];
        A2[i]=A[i];
    }
    sort(A2, A2+N);
    for(int i=0;i<N;i++){
        auto lb=lower_bound(A2, A2+N,A[i]);
        auto ub=upper_bound(A2, A2+N,A[i]);
        int win = lb-A2;
        int even = ub-A2-win;
        int lose=N-win-even;
        cout<<win*3+even-1<<endl;
    }

    return 0;
}

Measured memory_bytes: 4632
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<stack>
#include<queue>
#include<map> 
#include<list>
#include<string>
#include<cstring>
#include<set>
#include<vector>
#define ll long long
#define memset(a,n) memset(a,n,sizeof(a))
#define mp make_pair 
#define pb push_back
using namespace std;
const int maxn = 1e6 + 100;


int n,a[maxn],b[maxn];
int main()
{
	scanf("%d",&n);
	for(int i = 1; i <= n;i++) scanf("%d",&a[i]);
	vector<int> q;
	for(int i = n ;i >= 1;i--){
		int sum = 0;
		for(int j = i + i ;j <= n;j += i) sum += b[j];
		if(sum % 2 != a[i]){
			b[i] = 1;q.push_back(i);
		}
	} 
	printf("%d\n",q.size());
	for(int i = 0 ; i < q.size();i++){
		printf("%d ",q[i]);
	}
	printf("\n");
 } 


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

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

int main(){
	string s;cin>>s;
	if(s=="AAA"||s=="BBB")puts("No");
	else puts("Yes");
}

Measured memory_bytes: 256
#include<iostream>


using namespace std;

int main() {
	int W;
	int a, b;

	//入力
	cin >> W >> a >> b;

	if (a <= b) {
		if (a + W < b) {
			//離れている
			cout << b - (a + W) << endl;
		}
		else if (a + W >= b) {
			//くっついている
			cout << 0 << endl;
		}
	}
	else {
		if (b + W < a) {
			//離れている
			cout << a - (b + W) << endl;
		}
		else if (b+W>=a) {
			//くっついている
			cout << 0 << endl;
		}
	}

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

ll val(ll a[],ll b[],ll w,ll i,vector<vector<ll> > &dp){
    if(w==0 || i<0)
    return 0;
    
    if(dp[i][w]!=-1)
    return dp[i][w];
    
    if(w-a[i]<0)
    return dp[i][w]=val(a,b,w,i-1,dp);
    
    return dp[i][w]=max(b[i]+val(a,b,w-a[i],i-1,dp),val(a,b,w,i-1,dp));
}

int main() {
    fastio
    
	ll n,i,j,x,t,k,m,w;
	cin>>n>>w;
	
	ll a[n],b[n];
	vector<vector<ll> > dp(n,vector<ll> (w+1,-1));
	
	for(j=0;j<n;j++)
	cin>>a[j]>>b[j];
	
	cout<<val(a,b,w,n-1,dp);
	
	return 0;
}



Measured memory_bytes: 82376
from functools import reduce

def match_word(w1, w2):
    return w1 == w2 or w1+'.' == w2

def count_if(f, lst):
    count = 0

    for l in lst:
        count += 1 if f(l) else 0

    return count

def main():
    count = 0

    word = input().lower()

    while True:
        line = input();

        if line == 'END_OF_TEXT':
            break

        count += count_if(lambda w: match_word(word, w.lower()), line.split())

    print(count)

if __name__ == '__main__':
    main()


Measured memory_bytes: 6236
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <stdio.h>
using namespace std;

long long MOD = 1000000007;

int main() {
    
    int N;
    cin >> N;
    set<int> A;
    for ( int i = 0; i < N; i++ ) {
        int a;
        cin >> a;
        A.insert(a);
    }
     
    cout << A.size() << endl;
    
    return 0;
}

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

void check_num(int *i, int *x, int *n, int *flag);
void include3(int *i, int *x, int *n, int *flag);
void end_check_num(int *i, int *x, int *n, int *flag);

void call(int n){
	int i = 1;
	int x = 0;
	int END_FLAG = 0;
	check_num(&i, &x, &n, &END_FLAG);
}

int main(void){
	int n;
	cin >> n;
	call(n);
	
	return 0;
}
void check_num(int *i, int *x, int *n, int *flag){
	*x = *i;
	if( *x % 3 == 0 ){
		cout << " " << *i;
		end_check_num(i, x, n, flag);	
	}
	else include3(i, x, n, flag);
}
void include3(int *i, int *x, int *n, int *flag){
	if( *flag == 0 ){
		if( *x % 10 == 3 ){
			cout << " " << *i;
			end_check_num(i, x, n, flag);
		}
		else{
			(*x) /= 10;
			if(*x) include3(i, x, n, flag);
			else end_check_num(i, x, n, flag);
		}
	}
}
void end_check_num(int *i, int *x, int *n, int *flag){
	if( ++(*i) <= *n ) check_num(i, x, n, flag);
	else{
		cout << endl;
		*flag = 1;
	}
}

Measured memory_bytes: 1160
// template.cpp

// Defines.
//#define DEBUG
#define NUMBER_OF_DIGITS 6

// Includes.
#include <bits/stdc++.h>

#ifdef DEBUG
#include <chrono>
#endif

// Usings.
using namespace std;

// Main function.
int main()
{
#ifdef DEBUG
	chrono::system_clock::time_point start, end;
	
	start = chrono::system_clock::now();
#endif
	
	// settings.
	ios::sync_with_stdio(false);
	
	//cout << fixed;
	//cout << setprecision(NUMBER_OF_DIGITS);
	
	// logic.
	int n;
	cin >> n;
	
	string s;
	cin >> s;
	
	map<char, bool> s0_cache, s1_cache;
	for (char i = '0'; i < ('0' + 10); i++)
	{
		s0_cache[i] = false;
		s1_cache[i] = false;
	}
	
	set<string> keys;
	for (int i = 0; i < (n - 2); i++)
	{
		if (s0_cache[s[i]] == true)
		{
			continue;
		}
		else
		{
			s0_cache[s[i]] = true;
		}
		
		for (int j = (i + 1); j < (n -1); j++)
		{
			if (s1_cache[s[j]] == true)
			{
				continue;
			}
			else
			{
				s1_cache[s[j]] = true;
			}
			
			for (int k = (j + 1); k < n; k++)
			{
				char key[3];
				key[0] = s[i];
				key[1] = s[j];
				key[2] = s[k];
				
				keys.insert(key);
			}
		}
				
		for (char j = '0'; j < ('0' + 10); j++)
		{
			s1_cache[j] = false;
		}
	}
	
	cout << keys.size() << endl;

#ifdef DEBUG
	end = chrono::system_clock::now();
	
	double elapsed = chrono::duration_cast<std::chrono::milliseconds>(end-start).count();
	cout << elapsed << "[ms]" << endl;
#endif
	
	return 0;
}


Measured memory_bytes: 3760
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<fstream>

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

int main(void) {
    int n,k;

    cin>>n>>k;

    if(k == 1) {
        cout<<0<<endl;
    } else {
        cout<<n-k<<endl;
    }
    return 0;
}




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

int main() {
    int a, b, c, d;
    cin >> a >> b >> c;
    d = a;
    a = b;
    b = d;
    d = a;
    a = c;
    c = d;
    cout << a << " " << b << " " << c << endl;
}

Measured memory_bytes: 256
import scala.io.StdIn._
object Main extends App {
  val n = readInt
  val as = 0 +: readLine.split(" ").map(_.toInt)
  val ans = new Array[Int](n + 1)

  (n to 1 by -1).foreach {i =>
    val cnt = (i * 2 to n by i).count(j => ans(j) == 1)
    ans(i) = (cnt & 1) ^ as(i)
  }
  val is = ans.zipWithIndex.collect{case (a, i) if a == 1 => i}
  println(is.size)
  println(is.mkString(" "))
}

Measured memory_bytes: 95824
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}

int main(){
  vector<int> v(3);
  int k;
  rep(i,3) cin >> v[i];
  cin >> k;
  
  sort(v.begin(),v.end());
  
  rep(i,k) v[2] *= 2;
  
  int ans = v[0] + v[1] + v[2];
  
  cout << ans;
  
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <functional>
#include <numeric>
#include <iomanip>
#define fi first
#define se second
#define fcout(n) cout<<fixed<<setprecision((n))
#define cinl(str) getline(cin,(str))
using namespace std;
bool value(int y,int x,int R,int C){return 0<=y&&y<R&&0<=x&&x<C;}
typedef pair<int,int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long > vll;
typedef vector< vi > vvi;
double pie=acos(-1);
int INF=1000000007;
int dx[4] = { 0,-1,0,1 };
int dy[4] = { -1,0,1,0 };


int main() {
	int a,b,c;
	cin>>a>>b>>c;
	if(b-a==c-b) cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define lli long long int
#define pb push_back
#define mod2 998244353
#pragma GCC optimize("-O2")
#define mod3 127
#define mod 1000000007
#define MAXN 1000000000
#define v32 vector<int>
#define v64 vector<lli>
#define v1024 vector<vector<int>>
#define v4096 vector<vector<lli>>
#define vt vector
#define f(x, y, z) for (lli x = y; x < z; x++)
#define fd(x, y, z) for (lli x = y; x > z; x--)
#define lb lower_bound
#define ld long double
#define m64 map<lli, lli>
#define m32 map<int, int>
#define m64it map<lli, lli>::iterator
#define m32it map<int, int>::iterator
#define fastio                    \
ios_base::sync_with_stdio(0); \
cin.tie(0);                   \
cout.tie(0)
#define ist insert
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define p_q priority_queue
#define min_p_q priority_queue<int, vt<int>, greater<int>>
using namespace std;
using namespace __gnu_pbds;
lli tmod(lli x, lli y)
{
    return (x % y + y) % y;
}
template <typename T>
void DEBUG_ARR(vt<T> a)
{
    f(i, 0, a.size()) cout << a[i] << " ";
    cout << "\n";
}
lli power(lli x, lli y) 
{
    lli res = 1;  
    while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x)%mod; 
        y = y>>1; 
        x = (x*x)%mod;
    }
    if(res<0)res+=mod;
    return res; 
}
lli dp[1000][10001];
int main()
{   
    fastio;
    f(i,0,1000)f(j,0,10001)dp[i][j]=MAXN*10000ll;
    lli h,n;
    cin>>h>>n;
    v64 a(n),b(n);
    f(i,0,n)cin>>a[i]>>b[i];
    f(i,0,n){
        f(j,0,h+1){
            if(i>0)
            dp[i][j]=dp[i-1][j];
            if(j==0){
                dp[i][j]=0;
                continue;
            }
            if(j>=a[i]){
                dp[i][j]=min(dp[i][j],dp[i][j-a[i]]+b[i]);
            }
            else dp[i][j]=min(dp[i][j],b[i]);
        }
    }
    cout<<dp[n-1][h]<<"\n";
    return 0;
}


Measured memory_bytes: 78464
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;

class Program
{
    static void Main()
    {
        var s = "1" + Console.ReadLine();
        s = s.Replace("-", "+-");
        s = s.Replace("x+", "x^1+");
        s = s.Replace("+x", "+1x");
        s = s.Replace("-x", "-1x");
        var ss = s.Split('+');
        int n = int.Parse(ss[0].Replace("x^", ""));
        var keisu = new int[n + 1];
        foreach (var item in ss)
        {
            if (item.Contains("x^"))
            {
                var sss = item.Replace("x^", "#").Split('#');
                keisu[int.Parse(sss[1])] = int.Parse(sss[0]);
            }
            else
            {
                keisu[0] = int.Parse(item);
            }
        }
        var ans = new List<long>();
        for (long i = 3000; i > -3000; i--)
        {
            long sum = 0;
            long xx = 1;
            for (int j = 0; j < keisu.Length; j++)
            {
                sum += xx * keisu[j];
                xx *= i;
            }
            if (sum == 0)
                ans.Add(-i);
        }
        var ret = new StringBuilder();
        foreach (var item in ans)
        {
            ret.Append("(x+");
            ret.Append(item);
            ret.Append(")");
        }
        Console.WriteLine(ret.ToString().Replace("+-", "-"));
    }
}

Measured memory_bytes: 9832
#include <stdio.h>

int main(void) {
    unsigned long long int X = 0;
    unsigned long long int dep = 100;
    int i = 0;
    scanf("%lu", &X);
    while (dep < X) {
        i++;
        dep += dep / 100;
    }
    printf("%d", i);
    return 0;
}

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

int main() {
 int N;
 cin >> N;
 vector<int> p(N);

 for(int i = 0; i < N; i++) {
   cin >> p[i];
 }

 int sum = 0;
 for(int i = 0; i < N; i++) {
   if(p[i] != i + 1) sum++;
 }

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


 return 0;
}



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

using namespace std;

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

    int k,n;
    cin>>k>>n;
    int a[n];
    vector<int>dis;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=1;i<n;i++){
        dis.push_back(a[i]-a[i-1]);
    }
    dis.push_back((a[0]-0)+(k-a[n-1]));
    sort(dis.begin(),dis.end());
    ll ans=0;
    for(int i=0;i<dis.size()-1;i++){
        ans+=dis[i];
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 2168
#include<stdio.h>
#define N 1000
 
int n,A[N],B[N],C[N],con,res,min;
 
void swap(int* A,int* B)
{
  int ch;
  ch=*A;
  *A=*B;
  *B=ch;
}
int small(int a,int b)
{
  if(a<b)return a;
  else return b;
}
 
int search(int a)
{
  int i;
  for(i=0; i<n; i++){
    if(A[i]==a)return i;
  }
}
 
int main()
{
  int i,j,sum=0,p;
 
  scanf("%d",&n);
 
  for(i=0; i<n; i++){
    scanf("%d",&A[i]);
    B[i]=A[i];
  }
 
  for(i=n-1; i>0; i--){
    for(j=0; j<i; j++){
      if(B[j]>B[j+1]) swap(&B[j],&B[j+1]);
    }
  }
 
  for(i=0; i<n; i++)C[i]=0;
 
  for(i=0; i<n; i++){
    p=i;
    con=res=0;
    min=(1<<24);
 
    while(C[p]==0){
      C[p]=1;
      con++;
      res+=A[p];
      min=small(min,A[p]);
      p=search(B[p]);
    }
 
    if(con<2)continue;
    sum+=small(res+B[0]*(con+1)+min,res+min*(con-2));
  }
 
  printf("%d\n",sum);
   
  return 0;
}



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

int x[16];

int main(){
    for(int i = 1; i < 6; i ++){
        scanf("%d", &x[i]);
    }

    for(int i = 1; i < 6; i ++){
        if(x[i] == 0){
            printf("%d", i);
            return 0;
        }
    }
}


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

int main() {
    int N;
    cin >> N;
    vector<int> p(N);
    rep(i, N) cin >> p[i];
    sort(p.begin(), p.end());
    int ans = p[N - 1]/2;
    rep(i, N - 1) ans += p[i];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
a, b = map(int, input().split())
ans = []
for i in range(50):
    ans.append(["." for i in range(100)])
for i in range(50):
    ans.append(["#" for i in range(100)])

for i in range((a - 1) // 50):
    for j in range(50):
        ans[51 + i * 2][2 * j] = "."
for i in range((a - 1) % 50):
    ans[99][2 * i] = "."
for i in range((b - 1) // 50):
    for j in range(50):
        ans[i * 2][2 * j] = "#"
for i in range((b - 1) % 50):
    ans[48][2 * i] = "#"

print(100, 100)
for i in range(100):
    print("".join(ans[i]))

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

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int a,b,c;
	cin >> a >> b >> c;
	set<int> st;
	st.emplace(a), st.emplace(b), st.emplace(c);
	if (st.size()==2) cout << "Yes";
	else cout << "No";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <ctype.h>
#include <ios> 
#include <iomanip>
using namespace std;

#define N_MAX   (100000)
#define LL_MAX_NUM (1LL<<60)
#define INF 1e7

typedef long long ll;
typedef long long int lli;

int main() {
	int a, b, h; cin >> a >> b >> h;
	cout << (a+b)*h/2 << endl;
	return 0;
}

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

const double eps = 1e-10;

int dcmp(double x) {
        if(fabs(x) < eps) return 0;
        return x < 0 ? -1 : 1;
}

bool same(double a, double b) {return dcmp(a - b) == 0;}
#define Vector P
struct P {
        double x, y;
        P(double x = 0, double y = 0): x(x), y(y) {}
        P operator + (P b) {return P(x + b.x, y + b.y);}
        P operator - (P b) {return P(x - b.x, y - b.y);}
        P operator * (double b) {return P(x * b, y * b);}
        P operator / (double b) {return P(x / b, y / b);}
        double operator * (P b) {return x * b.x + y * b.y;} // Dot
        double operator ^ (P b) {return x * b.y - y * b.x;} // Cross
        double abs() {return hypot(x, y);}
        P unit() {return *this / abs();}
        P spin(double o) {
                double c = cos(o), s = sin(o);
                return P(c * x - s * y, s * x + c * y);
        }
};

struct Line {
        //ax + by + c = 0
        double a, b, c, theta;
        P pa, pb;
        Line(): a(0), b(0), c(0), theta(0), pa(), pb() {}
        Line(P pa, P pb): a(pa.y - pb.y), b(pb.x - pa.x), c(pa ^ pb), theta(atan2(-a, b)), pa(pa), pb(pb) {}
                P projection(P p) {return pa + (pb - pa).unit() * ((pb - pa) * (p - pa) / (pb - pa).abs());}
                P reflection(P p) {return p + (projection(p) - p) * 2;}
        double get_ratio(P p) {return (p - pa) * (pb - pa) / ((pb - pa).abs() * (pb - pa).abs());}
        P dis(P p) {return ((pb - pa) ^ (p - pa)) / (pb - pa).abs();} // directed distance
};

struct Circle {
        P c;
        double r;
        Circle(P c, double r = 0): c(c), r(r) {}
};
double dis(P a, P b) {return (a - b).abs();}
vector<P> p;
double closest_pair(int l, int r) {
    // p should be sorted increasingly according to the x-coordinates.
    if (l == r) return 1e9;
    if (r - l == 1) return dis(p[l], p[r]);
    int m = (l + r) >> 1;
    double d = min(closest_pair(l, m), closest_pair(m + 1, r));
    vector<int> vec;
    for (int i = m; i >= l && fabs(p[m].x - p[i].x) < d; --i) vec.push_back(i);
    for (int i = m + 1; i <= r && fabs(p[m].x - p[i].x) < d; ++i) vec.push_back(i);
    sort(vec.begin(), vec.end(), [&](int a, int b) { return p[a].y < p[b].y; });
    for (int i = 0; i < vec.size(); ++i) {
        for (int j = i + 1; j < vec.size() && fabs(p[vec[j]].y - p[vec[i]].y) < d; ++j) {
            d = min(d, dis(p[vec[i]], p[vec[j]]));
        }
    }
    return d;
}
int main() {
        ios_base::sync_with_stdio(false); cin.tie(0);
        int n; cin >> n;
        for(int i = 0; i < n; i++) {
                P ps; cin >> ps.x >> ps.y;
                p.push_back(ps);
        }
                sort(p.begin(), p.end(), [&](P a, P b) {return same(a.x, b.x) ? a.y < b.y : a.x < b.x;});                   double ans = closest_pair(0, n - 1);
        cout << fixed << setprecision(12) << ans << '\n';
        return 0;
}


Measured memory_bytes: 5292
#include<iostream>
#include<cmath>

using namespace std;

class CVector{
public:
	CVector():x(0),y(0),z(0){}
	CVector(double x, double y, double z):x(x),y(y),z(z){}
	bool isLeft(const CVector &vt){
		double dz;
		dz = x * vt.y - vt.x * y; // cross
		if( dz >= 0 ) return true;
		else return false;
	}
	double x,y,z;
};

int main(void){
	while(1){
		int n;
		CVector vCrr(1.0,1.0,0.0);

		cin >> n;
		if( n == -1 ) break;

		for(int i = 2; i < n; i++){
			double x1, x2, y1, y2;
			double a = vCrr.x, a2 = pow(a,2.0);
			double b = vCrr.y, b2 = pow(b,2.0);
			CVector vT;

			x1 = sqrt(b2/(a2+b2));
			x2 = -x1;
			y1 = b!=0? -a/b*x1: 1;
			y2 = b!=0? -a/b*x2: -1;
			CVector vT1(x1,y1,0.0);
			CVector vT2(x2,y2,0.0);

			if( vCrr.isLeft(vT1) ) vT = vT1;
			else vT = vT2;

			vCrr = vT;
			vCrr.x += a;vCrr.y += b;
		}

		printf("%lf\n%lf\n", vCrr.x, vCrr.y);
	}
	return 0;
}

Measured memory_bytes: 0
n, m = gets.split.map(&:to_i)

ans = 0
if n == 1 && m == 1
  ans = 1
elsif n == 1 && m >= 3
  ans = m - 2
elsif n >= 3 && m == 1
  ans = n - 2
elsif n >= 3 && m >= 3
  ans += (n - 2) * (m - 2)
end

puts ans


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define MOD 1000000007
const int INF = 1LL<<30;

char fi[2010][2010];
int sh[2010][2010],sw[2010][2010];

int main(){
    int h,w;
    cin>>h>>w;
    rep(i,h) rep(j,w) cin>>fi[i][j];

    rep(i,h){
        int cnt=1;
        rep(j,w){
            if(fi[i][j]=='.'){
                sw[i][j]=cnt;
                cnt++;
            }
            else cnt=1;
        }
    }
    rep(j,w){
        int cnt=1;
        rep(i,h){
            if(fi[i][j]=='.'){
                sh[i][j]=cnt;
                cnt++;
            }
            else cnt=1;
        }
    }
    rep(i,h){
        for(int j=w-2;j>=0;j--){
            if(fi[i][j]=='.' && fi[i][j+1]=='.') sw[i][j]=sw[i][j+1];
        }
    }
    rep(j,w){
        for(int i=h-2;i>=0;i--){
            if(fi[i][j]=='.' && fi[i+1][j]=='.') sh[i][j]=sh[i+1][j];
        }
    }

    int ans=0;
    rep(i,h){
        rep(j,w){
            ans=max(ans,sh[i][j]+sw[i][j]-1);
        }
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 38916
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


h,w = list(map(int, input().split()))
a = []
for i in range(h):
    a.extend(list(input()))
    
from collections import Counter
c = Counter(a)
# print(c)
must = {1:0, 2:0, 4:0}
must[4] += (h//2) * (w//2)
if h%2==1:
    must[2] += (w//2)
if w%2==1:
    must[2] += (h//2)
if w%2==1 and h%2==1:
    must[1] += 1
    
for base in (4,2,1):
    val = 0
    for k,v in c.items():
        if val + v//base >= must[base]:
            c[k] -= (must[base] - val) * base
            val += (must[base] - val)
#             print(c, val, v, base)
            break
        val += v//base
        c[k] -= (v//base)*base
    if val<must[base]:
        ans = "No"
        break
else:
    ans = "Yes"
print(ans)

Measured memory_bytes: 68164
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define FOR(i,n,j) for(int i=(j);i<(n);++i)
#define ssort(n) sort((n).begin(),(n).end())
#define rsort(n) sort((n).begin(),(n).end(),greater<char>())
#define mp make_pair
using ll=long long;
using ld=long double;
typedef pair<int,int> P;
typedef pair<P,int> COST;
#define repl(i,n) for(ll i=0;i<(n);++i)
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl

using Graf_char=vector<vector<char>>;
using Graf_int=vector<vector<int>>;
#define MAX 10000000

int main()
{
    string s,t;
    cin >> s;
    cin >> t;
    vector<int> s_(s.size()),t_(t.size());
    rep(i,s.size()){
        s_[i]=s[i];
    }
    rep(i,t.size()){
        t_[i]=t[i];
    }
    ssort(s_);
    rsort(t_);
    int i=0;
    int count=0;
    while(i<s_.size()&&i<t_.size()){
        if(s_[i]<t_[i]){
            Yes;
            return 0;
        }else if(s_[i]>t_[i]){
            break;
        }
        ++i;
    }
    if(i<s_.size()&&i<t_.size()){
        No;
    }else{
        if(s_.size()>=t_.size()){
            No;
        }else{
            Yes;
        }
    }
}

Measured memory_bytes: 3596
#include<iostream>
#include<vector>
using namespace std;
typedef long long ll;

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++)  cin >> a[i];
    ll ret = 0, now = 0;
    for(int i = n-1; i >= 0; i--){
        if(now == a[i]){
            // there's nothing to do with a[i]
        }else if(now > a[i]){
            cout << -1 << endl;
            return 0;
        }else if(now < a[i]){
            now = a[i];
            if(now > i){
                cout << -1 << endl;
                return 0;
            }else{
                ret += now;
            }
        }
        now--;
        if(now < 0) now = 0;
    }
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 1152