akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long
#define lld long double
#define MOD 1000000007
#define CAP 10000000
#define inf 1000000000000000000LL
#define pii pair<ll,ll>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define endl '\n'
#define all(v)    v.begin(),v.end()
#define fast  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
ll power(ll x,ll y, ll md=MOD){ll res = 1;x%=md;while(y>0){if(y&1)res = (res*x)%md;x = (x*x)%md;y = y>>1;}return res%md;}
#define dbg(x) cout <<#x<<":"<<x<<endl;
ll max1(ll a, ll b, ll c=-inf, ll d=-inf) {ll mx1=(a>b)?a:b, mx2=(c>d)?c:d; return ((mx1>mx2)?mx1:mx2);}
#define int ll

struct node {
	vector<int> v,w;
};

signed main() {
	fast;

	int n,k;
	cin>>n>>k;
	vector<int> a(n),f(n);
	for(int i=0;i<n;i++) cin>>a[i];
	for(int i=0;i<n;i++) cin>>f[i];

	sort(all(a), greater<int>());
	sort(all(f));

	int l = 0, r = 1e+18, mid, ans = inf;
	while(l<=r) {
		mid = (l+r)/2;

		int cost = 0;
		
		for(int i=0;i<n;i++) {
			int val = mid/f[i];
			if(a[i]<=val) continue;
			cost += a[i]-val;
		}

		if(cost<=k) {
			r = mid - 1;
			ans = min(ans, mid);
		}
		else l = mid + 1;
	}

	cout<<ans<<endl;

}

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

//#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
//using namespace __gnu_pbds;

#define ss second
#define ff first
#define int long long
//#define double long double
#define pb push_back


const int N = 1e6 + 51 + 51, MOD = 1e9 + 7, mod = 998244353, INF = 3e18;

mt19937 Flash_new_51(51515);

using vi = vector <int>;
using vp = vector <pair <int, int>>;

//gp_hash_table<int, int> table;
int dp[400][400], a[N], pref[N];

int ask (int l, int r) {
    int mem;
    if (l == 0) mem = 0;
    else mem = pref[l - 1];
    return pref[r] - mem;
}

signed main() {
    #ifdef Flash
     freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
        if (i == 0) pref[i] = a[i];
        else pref[i] = pref[i - 1] + a[i];
    }
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) dp[i][j] = INF;
    }

    for (int i = 0; i < n - 1; i++) {
        dp[i][i + 1] = a[i] + a[i + 1];
    }
    for (int i = 2; i <= n; i++) {
        for (int j = 0; j < n; j++) {
            if (i + j >= n) break;
            int l = j, r = i + j;
            for (int i1 = l; i1 < r; i1++) {
                int l1 = i1;
                dp[l][r] = min(dp[l][r],
                               dp[l][l1] + dp[l1 + 1][r] + ask(l, l1) + ask(l1 + 1, r));
            }
        }
    }
    cout << dp[0][n - 1];
}


Measured memory_bytes: 4864
#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

int num[100010]={};

int main()
{
    int n;
    int i;
    int t;
    while (scanf("%d",&n)!=EOF)
    {
        memset(num,0,sizeof(num));
        for (i=1;i<=n;i++)
        {
            scanf("%d",&num[i]);
        }
        t=0;
        for (i=1;i<=n;i++)
        {
            if (num[i]==i)
            {
                t++;
                i++;
            }
        }
        printf("%d\n",t);
    }
    return 0;
}

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

int main(){
int n,a = 0,b = 0,m;

cin >> n;
vector<int> vec(n);

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

sort(vec.begin(),vec.end());

for(int i = 1;i <= n; i++){
  if(i%2 == 1){
    a += vec[n - i];
  }else{
    b += vec[n - i];
  }
}

cout << a -b << endl;
  return 0;
}

Measured memory_bytes: 3624
N = int(input())

def q(i):
    print(i)
    r = input()[0]
    if r=='V':
        exit()
    return r

z = q(0)
def is_ok(k):
    s = q(k)
    if k%2:
        return z!=s
    else:
        return z==s
ok = 0
ng = N
while ng-ok > 1:
    m = (ok+ng)//2
    if is_ok(m):
        ok = m
    else:
        ng = m

Measured memory_bytes: 3660
import bisect
import collections
import itertools


def getint(): return int(input())
def getints(): return list(map(int, input().split()))
def getint2d(rows): return [getints() for _ in range(rows)]
def getgrid(rows): return [input() for _ in range(rows)]
def array1d(n, value): return [value for _ in range(n)]
def array2d(n, m, value): return [array1d(m, value) for _ in range(n)]

n = getint()
values = list(sorted(getints()))

res = values[0]

for i in range(1, n):
    res = (res + values[i]) / 2.0

print(res)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include<string.h>
using namespace std;
using namespace __gnu_pbds;
using ll = long long int;
#define INF             1e14
#define dd              double
#define MOD             1000000007
#define my_sizeof(type) ((char *)(&type+1)-(char*)(&type)) 
#define nl              cout<<endl
#define fill(a,val)     memset(a,val,sizeof(a))
#define mp              make_pair
#define endl            "\n"
#define pb              push_back
#define ff              first    
#define ss              second
#define SIZE            200005
#define all(v)          v.begin(),v.end()
#define s(ar,n)         sort(ar,ar+n)
#define rs(ar,n)        sort(ar, ar+n, greater<ll>()) 
#define oa(a,n)         for(ll i=0;i<n;i++)cout<<a[i]<<" ";nl
#define cn(a,n)         for(ll i=0;i<n;i++)cin>>a[i];
#define maxa(ar,N)      *max_element(ar,ar+N)
#define mina(ar,N)      *min_element(ar,ar+N)
#define fastio()        ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define printclock      cerr<<"Time : "<<1000*(long double)clock()/(long double)CLOCKS_PER_SEC<<"ms\n";
typedef tree<pair<ll,ll>, null_type, less<pair<ll,ll>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
  
ll logtwo(ll n){
    if(n==1)
        return 0;
    return logtwo(n/2)+1;
}
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);} 
ll power(ll x,ll y,ll p = LLONG_MAX ){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
ll lcm(ll a , ll b){return (a*b)/gcd(a,b);}
signed main()
{
    fastio();   
   
    long long  n,m;
    cin>>n>>m;
    n = n*m;
    cout<<n<<endl;
    
}

Measured memory_bytes: 3636
#!/usr/bin/env python
# coding: utf-8
" 解説見てしまったのでしばらくねかせる "
from collections import namedtuple

Pos = namedtuple('Pos', ('x', 'y'))

def move(pf, pt):
    return (pf.y+1, pf.x+1, pt.y+1, pt.x+1)

def order(H, W):
    ret = []
    for y in range(H):
        if y % 2 == 0:
            for x in range(W):
                ret.append(Pos(x,y))
        else:
            for x in range(W-1, -1, -1):
                ret.append(Pos(x,y))
    return ret

def main():
    H, W = list(map(int, input().split()))
    field = []
    for _ in range(H):
        la = list(map(int, input().split()))
        field.append(la)
    commands = []
    lp = order(H, W)
    for i in range(len(lp)-1):
        pf = lp[i]
        coins = field[pf.y][pf.x]
        if coins % 2 == 0:
            continue
        pt = lp[i+1]
        field[pt.y][pt.x] += 1
        commands.append(move(pf, pt))
    print(len(commands))
    for c in commands:
        print(" ".join(map(str, c)))


if __name__ == '__main__':
    main()


Measured memory_bytes: 52176
S = input()
mS, m10, mSd = [0], 1, {}
for i in range(len(S)):
    mS.append((mS[-1] + int(S[-(i + 1)]) * m10) % 2019)
    m10 = (m10 * 10) % 2019
for s in mS[1:]:
    mSd[s] = mSd.get(s, 0) + 1
print(mSd.get(0, 0) + sum([v * (v - 1) // 2 for v in mSd.values()]))


Measured memory_bytes: 77336
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    int K, X;
    cin >> K >> X;

    if (K * 500 >= X) cout << "Yes" << endl;
    else cout << "No" << endl;
    
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <utility>
using namespace std;
typedef long long ll;
typedef pair<int, int> node;

int MAX_N = 100000;
vector<node> unionfind(MAX_N);
vector<int> size(MAX_N);
void init(int N){
	for(int i=0;i<N;i++){
		unionfind[i].first = i;
		unionfind[i].second = 0;
		size[i] = 1;
	}
}

int find(int n){
	if(unionfind[n].first == n){
		return n;
	}
	else{
		unionfind[n].first = find(unionfind[n].first);
		return unionfind[n].first;
	}
}

void unite(int x, int y){
	x = find(x);
	y = find(y);
	if(x == y) return;
	if(unionfind[x].second > unionfind[y].second){
		unionfind[x].first = y;
		size[y] += size[x];
		size[x] = 0;
	} 
	else{
		unionfind[y].first = x;
		size[x] += size[y];
		size[y] = 0;

	}
	if(unionfind[x].second == unionfind[y].second){
		unionfind[x].second++;
	}
}

bool same(int x, int y){
	return find(x) == find(y);
}

int main(){
	int N, M;
	cin >> N >> M;
	vector<int> A(M), B(M);
	for(int i=0;i<M;i++){
		cin >> A[i] >> B[i];
	}
	vector<ll> ans(M);
	init(N);
	ans[M-1] = (ll)N * (N-1) / 2;
	for(int i=M-2;i>=0;i--){
		if(same(A[i + 1]-1, B[i + 1]-1)) ans[i] = ans[i+1];
		else ans[i] = ans[i+1] - (ll)(size[find(A[i+1]-1)] * size[find(B[i+1]-1)]);
		//cout << "Ai:" << A[i+1]-1<< ":" <<size[find(A[i+1]-1)] 
		//	<< " Bi:" << B[i+1]-1<< ":" <<size[find(B[i+1]-1)] << endl;
		unite(A[i+1]-1,B[i+1]-1);
	}
	for(int i=0;i<M;i++){
		cout << ans[i] << endl;
	}
}

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

using ll = long long;
using p = pair<ll, ll>;
constexpr ll INF = 1LL << 61;

string gen_wall(ll len) {
  string s;
  for (ll i = 0; i < len; i++) {
    s += "#";
  }

  return s;
}

int main(void) {
  ll H, W;
  cin >> H >> W;

  ll hsize = H + 2;
  ll wsize = W + 2;
  ll size = hsize * wsize;

  vector<string> S(hsize);

  S[0] = gen_wall(wsize);
  for (ll i = 1; i <= H; i++) {
    string s;
    cin >> s;
    S[i] = "#" + s + "#";
  }
  S[H + 1] = gen_wall(wsize);

  for (auto s : S) {
    cerr << s << endl;
  }

  vector<vector<ll> > d(size, vector<ll>(size, INF));

  for (ll h = 1; h <= H; h++) {
    for (ll w = 1; w <= W; w++) {
      d[h * wsize + w][h * wsize + w] = 0;
      if (S[h][w] == '#') {
        continue;
      }

      auto dh = h + 1;
      auto dw = w + 1;

      if (S[dh][w] == '.') {
        d[h * wsize + w][dh * wsize + w] = 1;
        d[dh * wsize + w][h * wsize + w] = 1;
      }
      
      if (S[h][dw] == '.') {
        d[h * wsize + w][h * wsize + dw] = 1;
        d[h * wsize + dw][h * wsize + w] = 1;
      }
    }
  }

  for (ll k = 0; k < size; k++) {
    for (ll i = 0; i < size; i++) {
      for (ll j = 0; j < size; j++) {
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }

  ll ans = 0;

  for (ll i = 0; i < size; i++) {
    for (ll j = 0; j < size; j++) {
      if (d[i][j] != INF) {
        ans = max(ans, d[i][j]);
      }
    }
  }

  for (ll h = 1; h <= H; h++) {
    for (ll w = 1; w <= W; w++) {
      if (d[H * wsize + 1][h * wsize + w] == INF) {
        cerr << "# ";
      } else {
        cerr << d[H * wsize + 1][h * wsize + w] << " ";
      }
    }
    cerr << endl;
  }

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

Measured memory_bytes: 2048
import numpy
N, K = map(int,input().split())
h = numpy.array(input().split(),dtype=numpy.int64)
dp = numpy.array([0]*N,dtype = numpy.int64)
for i in range(1,N) :
    s = max(0,i-K)
    c = dp[s:i] + numpy.abs(h[i]-h[s:i])
    dp[i] = numpy.min(c)
print(dp[-1])

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

int main(){
  int N,t,change_point;
  t=0;
  change_point=1;
  cin>>N;
  vector<int> s(N);
  for (int i=0;i<N;i++){
    cin>>s.at(i);
  }
  for (int i=0;i<N-1;i++){
    if (s.at(i)>s.at(i+1)){
      if(t==1){
        change_point++;
        t=0;
      }
      else{
        t=-1;
      }
    }
    if (s.at(i)<s.at(i+1)){
      if (t==-1){
        change_point++;
        t=0;
      }
      else{
      	t=1;
      }
    }
  }
  cout<<change_point<<endl;
}
 

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n, m, nww;
string a, b;
map < ll, char > mapa;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> m;
    nww = n*m / __gcd(n, m);
    cin >> a >> b;
    for(int i=1; i<=n; i++){
        mapa[(i-1)*nww/n] = a[i-1];
    }
    for(int i=1; i<=m; i++){
        if(mapa[(i-1)*nww/m] != 0 && mapa[(i-1)*nww/m] != b[i-1]){
            cout << "-1";
            return 0;
        }
    }
    cout << nww;
}


Measured memory_bytes: 10880
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <bitset>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <queue>

#define mp make_pair
#define pb push_back


typedef long long ll;
typedef long double ld;

using namespace std;

const int MAXN = 510000;
const int LOG = 20;

char s[MAXN];
int go[MAXN][27];
int up[LOG][MAXN];
int n;

int main() {
	scanf("%s", s);
	n = strlen(s);
	for (int i = 0; i <= 26; ++i)
		go[n][i] = n + 1;
	for (int i = 0; i <= 26; ++i)
		go[n + 1][i] = n + 1;
	for (int i = n - 1; i >= 0; --i) {
		int c = s[i] - 'a';
		go[i][c] = i + 1;
		int now = i + 1;
		for (int j = c + 1; j <= 26; ++j) {
			now = go[now][j - 1];
			go[i][j] = now;
		}
		for (int j = 0; j < c; ++j)
			go[i][j] = go[now][j];
	}
	for (int i = 0; i <= n + 1; ++i)
		up[0][i] = go[i][26];
	for (int i = 1; i < LOG; ++i)
		for (int j = 0; j <= n + 1; ++j)
			up[i][j] = up[i - 1][up[i - 1][j]];
	int q;
	scanf("%d", &q);
	for (int i = 0; i < q; ++i) {
		int l, r;
		scanf("%d%d", &l, &r);
		--l;
		for (int j = LOG - 1; j >= 0; --j) {
			if (up[j][l] <= r)
				l = up[j][l];
		}
		if (l != r)
			printf("No\n");
		else
			printf("Yes\n");
	}
	return 0;
}




Measured memory_bytes: 93696
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef long long int lli;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

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

const int n = 26;

int main(){
    int days;
    cin >> days;

    vector<int> bad(n);
    rep(i, n) cin >> bad[i];
    vector<vector<int>> score(days, vector<int>(n));

    rep(i, days){
        rep(j, n) cin >> score[i][j];
    }

    vector<int> holdCons(days);
    rep(d,days) {
        cin >> holdCons[d];
        holdCons[d]--;
    }

    vector<int> last(n, 0);

    vector<ll> ans(days, 0);
    rep(d,days){
        int con = holdCons[d];
        ll sat = score[d][con];      
        rep(i, n){
            if (i == con){
                last[i] = 0;
                continue;
            }
            last[i]++;
            sat -= bad[i] * last[i];
        }
        if (d == 0) ans[d] = sat;
        else ans[d] = sat + ans[d-1];
    }
    rep(d, days) cout << ans[d] << endl;
}

Measured memory_bytes: 3652
/*--------------------------"SABUJ-JANA"------"JADAVPUR UNIVERSITY"--------*/
/*-------------------------------@greenindia-----------------------------------*/
//
//		  _____       _           _        _
//		 / ____|     | |         (_)      | |
//		| (___   __ _| |__  _   _ _       | | __ _ _ __   __ _
//		 \___ \ / _` | '_ \| | | | |  _   | |/ _` | '_ \ / _` |
//		 ____) | (_| | |_) | |_| | | | |__| | (_| | | | | (_| |
//		|_____/ \__,_|_.__/ \__,_| |  \____/ \__,_|_| |_|\__,_|
//		                        _/ |
//		                       |__/
/*---------------------- Magic. Do not touch.-----------------------------*/
/*------------------------------God is Great/\---------------------------------*/
#include <bits/stdc++.h>
using namespace std;
#define crap ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
//cout<<fixed<<showpoint<<setprecision(12)<<ans<<endl;
#define int long long int
#define double long double
#define PI acos(-1)
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
#define endl "\n"

void print1d(const vector<int>& vec) {for (auto val : vec) {cout << val << " ";} cout << endl;}

void print2d(const vector<vector<int>>& vec) {for (auto row : vec) {for (auto val : row) {cout << val << " ";} cout << endl;}}

void solve(vector<int>& arr, int r, int c) {

	int idx = 1;
	int dp[r][c];

	for (int i = 0; i < r; i++) {
		if (i % 2 == 0) {
			for (int j = 0; j < c; j++) {
				if (arr[idx - 1] == 0)
					idx++;
				dp[i][j] = idx;
				arr[idx - 1]--;

			}
		} else {
			for (int j = c - 1; j >= 0; j--) {
				if (arr[idx - 1] == 0)
					idx++;
				dp[i][j] = idx;
				arr[idx - 1]--;
			}
		}
	}


	for (int i = 0; i < r; ++i) {
		for (int j = 0; j < c; ++j) {
			cout << dp[i][j] << " ";
		}
		cout << endl;
	}

}

signed main() {
	crap;

	int r, c;
	cin >> r >> c;

	int n;
	cin >> n;

	vi arr(n);
	for (int i = 0; i < n; ++i) {
		cin >> arr[i];
	}

	solve(arr, r, c);

	return 0;
}

Measured memory_bytes: 3756
import java.util.*;

public class Main {

    long INF = Long.MAX_VALUE;

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

    void solve() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int ans=N/100;
        int A=ans*100+ans*10+ans;
        if(A>=N){
            ans=ans;
        }else{
            ans++;
        }
        for(int i=0;i<3;i++){
            System.out.print(ans);
        }
        System.out.println();
    }
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
#define f first
#define s second
#define mp make_pair

using namespace std;

typedef long long ll;
const int nax=1e6+6;
const int mod=1e9+7;
int nove[nax];
int dieci[nax];
int otto[nax];
int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin>>n;
  otto[0]=1;
  nove[0]=1;
  dieci[0]=1;
  for(int i=1;i<=n;i++){
    otto[i]=((ll)otto[i-1]*8LL)%mod;
    nove[i]=((ll)nove[i-1]*9LL)%mod;
    dieci[i]=((ll)dieci[i-1]*10LL)%mod;
  }
  cout<<((ll)dieci[n]-(ll)nove[n]-(ll)nove[n]+(ll)otto[n]+(ll)mod+(ll)mod)%mod<<endl;
}


Measured memory_bytes: 15320
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math

mod = 10**9+7


N = int(input())
s = round(math.sqrt(N))

ans = 0
for i in range(1,s+1):
    if N % i == 0:
        m = N//i-1
        # print(m)

        if m > 0 and i < m:
            ans += m

print(ans)


Measured memory_bytes: 6348
#include <stdio.h>
#include <string.h>

int main(void)
{
    int N=0;
    int ac=0,wa=0,tle=0,re=0;
    char array[100000][4]={};

    scanf("%d",&N);
    for(int i=0;i<N;i++){
        scanf("%s",array[i]);
        if(strcmp(array[i],"AC")==0){
            ac+=1;
        }
        else if(strcmp(array[i],"WA")==0){
            wa+=1;
        }
        else if(strcmp(array[i],"TLE")==0){
            tle+=1;
        }
        else {
            re+=1;
        }
    }

    printf("AC x %d\n",ac);
    printf("WA x %d\n",wa);
    printf("TLE x %d\n",tle);
    printf("RE x %d\n",re);

    return 0;
}

// strcmp(char* , char*) return true 0 false 1


Measured memory_bytes: 2124
import java.io.*;
import java.util.*;
import java.math.*;
class Main{
    public static void main(String[] args){
	BufferedReader sc=new BufferedReader(new InputStreamReader(System.in));
	try {
	    while(true){
		int z = Integer.valueOf(sc.readLine());
		if(z==0)
		    break;
		int mulz = z*z*z;
		int max = 0;
		for(int i=1; i<z; i++)
		    for(int j=1; j<z; j++){
			int tmp = i*i*i+j*j*j;
			if(tmp<mulz)
			    max = Math.max(max,tmp);
		    }
		System.out.println(mulz-max);
	    }
	}catch(Exception e){
	    System.out.println("Error");
	}
    }
}

Measured memory_bytes: 9484
#include <bits/stdc++.h>
using namespace std;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int l, r, d;
	cin>>l>>r>>d;
	int cnt=0;
	for(int i=l;i<=r;i++){
		if(i%d==0) cnt++;
	}
	cout<<cnt;
}

Measured memory_bytes: 3636
#include <stdio.h>
#include <string.h>
#include <algorithm>

int n, m, field[92][92];
int field_copy[92][92], ans = -1;

int dp(int finish_x, int finish_y) {
	int res = 0;
	if (field[finish_x][finish_y] == 0) { return 0; }
	field[finish_x][finish_y] = 0;
	if (field[finish_x][finish_y - 1] == 1) { res = std::max(res, dp(finish_x, finish_y - 1)); }
	if (field[finish_x][finish_y + 1] == 1) { res = std::max(res, dp(finish_x, finish_y + 1)); }
	if (field[finish_x - 1][finish_y] == 1) { res = std::max(res, dp(finish_x - 1, finish_y)); }
	if (field[finish_x + 1][finish_y] == 1) { res = std::max(res, dp(finish_x + 1, finish_y)); }
	field[finish_x][finish_y] = 1;
	return res + 1;
}

int main(void) {
	while (true) {
		scanf("%d%d", &n, &m);
		if (n == 0 && m == 0) { break; }
		for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) { scanf("%d", &field[i + 1][j + 1]); } }

		ans = 0;
		for (int x = 0; x < n; ++x) { for (int y = 0; y < m; ++y) { field_copy[x + 1][y + 1] = field[x + 1][y + 1]; } }
		for (int i = 0; i < n; ++i) {
			for (int j = 0; j < m; ++j) {
				ans = std::max(ans, dp(i + 1, j + 1));
				for (int x = 0; x < n; ++x) { for (int y = 0; y < m; ++y) { field[x + 1][y + 1] = field_copy[x + 1][y + 1]; } }
			}
		}

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

Measured memory_bytes: 2648
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime> 
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

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

	int x;
	cin >> x;
	cout << (!x) << endl;
}

Measured memory_bytes: 3156
N, K = map(int, input().split())
S = input() + '.'

count = []
pre = S[0]
c = 1
for t in S[1:] :
    if t == pre :
        c += 1
    else :
        count.append(c)
        pre = t
        c = 1
        
ret = sum(count)-len(count)
if K < len(count) // 2 :
    ret += 2 * K
else :
    ret = N - 1
print(ret)

Measured memory_bytes: 45680
#include "bits/stdc++.h"
#define int long long int
#define pb push_back
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define vvi vector<vector<int>>
#define vi vector<int>
#define f first
#define s second
using namespace std;
const int mod = 1e9 + 7;
int logi(int n) {int p = 0; while (n / 2) {n = n / 2; p++;} return p;}
int poww(int x, int y) {int pro = 1; while (y) {if (y & 1)pro = ((pro % mod) * (x % mod) % mod); y = y >> 1; x = ((x % mod) * (x % mod) % mod);} return pro;}
int poww2(int x, int y) {int pro = 1; while (y) {if (y & 1)pro = pro * x; y = y >> 1; x = x * x;} return pro;}
bool isprime(int n) { if (n == 1) return false; for (int i = 2; i <= sqrt(n); i++) if (n % i == 0) return false; return true;}
vector<vector<int>> adj(2e5);
vi visited(2e5, 0);
/*

*/

int solve() {
	int n;
	cin >> n;
	vector<int> v(n);
	int ans = 0;
	for (int i = 0; i < n; i++)
	{
		cin >> v[i];
	}
	for (int i = 1; i < n; i++)
	{
		if (v[i - 1] > v[i])
		{
			ans += v[i - 1] - v[i];
			v[i] = v[i - 1];
		}
	}
	cout << ans;
	return 0;
}
int32_t main() {
	/*#ifndef ONLINE_JUDGE
	    //for getting input from input.txt
	    freopen("input.txt","r",stdin);
	    //for writing output to output.txt
	    freopen("output.txt","w",stdout);
	#endif*/
	fast;
	int t = 1;
	//cin >> t;
	while (t--)
	{
		solve();
	}
	return 0;
}


Measured memory_bytes: 11084
#include <iostream>
#include <cstdlib>
#include <string>
#include <typeinfo>
#include <cstring>
#include <iostream>
#define MAX 500000
#define SENTINEL 2000000000
using namespace std;
int L[MAX/2+2],R[MAX/2+2],cut;

void merge(int A[],int n, int left, int mid, int right){
    int n1 = mid - left;
    int n2 = right - mid;
    for(int i = 0; i < n1; i++)L[i] = A[left + i];
    for(int i = 0; i < n2; i++)R[i] = A[mid + i];
    L[n1] = R[n2] = SENTINEL;
    int i = 0, j = 0;
    for(int k = left; k < right; k++){
        cut++;
        if(L[i] <= R[j])A[k] = L[i++];
        else A[k] = R[j++];
    }
}

void mergeSort(int A[],int n,int left, int right){
    if(left+1 < right){
        int mid =(left + right)/2;
        mergeSort(A,n,left,mid);
        mergeSort(A,n,mid,right);
        merge(A,n,left,mid,right);
    }
}

int main(){
    int A[MAX],n,i;
    cut = 0;
    
    cin >> n;
    for(i = 0; i < n; i++)cin >> A[i];
    mergeSort(A,n,0,n);
    for(i = 0; i < n; i++){
      if(i)cout << " ";
        cout << A[i];
    }
    cout << endl;
    cout << cut << endl;
    return 0;
}


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

vector<bool> seen;

void dfs(vector<vector<int>> &G, int a){
    if(seen[a])return;
    seen[a] = true;
    for(int i: G[a]){
        dfs(G, i);
    }
    return;

}

int main(){
    int n, m;
    cin >> n >> m;
    vector<vector<int>> G(n);
    rep(i, m){
        int a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    seen.resize(n, false);
    int ans = 0;
    rep(i, n){
        if(seen[i]) continue;
        dfs(G, i);
        ans++;
    }
    cout << ans << endl;
    return 0;
}

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

typedef long long ll;

ll gcd(ll a, ll b) {
    if(b == 0) return(a);
    return(gcd(b, a % b));
}
ll lcm(ll m, ll n) {
    if(m == 0 || n == 0) return(0);
    return(m * n / gcd(m, n));
}
int main(void) {
    int a, b;
    
    while(scanf("%d %d", &a, &b) != EOF) {
        cout << gcd(a, b) << " " << lcm(a, b) << endl;
    }
    
    return(0);
}

Measured memory_bytes: 1204
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pld pair<long double, int>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define ff first
#define ss second
#define SZ(x) ((int)(x).size())
#define ld long double
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int MAXN = 1e5+100;
int N, M;
bool vis[MAXN];
vector<int> adj[MAXN];

void read(){
    cin >> N >> M;
    for(int i = 0; i < M; i++){
        int u, v;
        cin >> u >> v;
        --u, --v;
        adj[u].pb(v);
        adj[v].pb(u);
    }
}

void dfs(int v){
    vis[v] = true;
    for(auto u : adj[v]){
        if(!vis[u]){
            dfs(u);
        }
    }
}

void solve(){
    read();
    int ans = -1;
    for(int i = 0; i < N; i++){
        if(!vis[i]){
            dfs(i);
            ans++;
        }
    }
    cout << ans;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
    return 0;
}


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

int main(){
	
	long long int n, m, i, ans = 0;
	
	scanf("%lld", &n);

	// iを「商と余りが等しい時の商の値」とする。
	// n == i * m + i (m > i) のため、i * (i + 1)←mの最小値 + i はn以下でなければならない。
	for(i = 1; i * (i + 1) + i <= n; i++){
		if((n - i) % i == 0)
			ans += (n - i) / i;
	}
	
	printf("%lld", ans);
	
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);
	static int[] g = new int[5];
	static int average = 0;

	public static void main(String[] args) {
		for (int i = 0; i < 5; i++) {
			g[i] = sc.nextInt();
				if (g[i] < 40) {
					g[i] = 40;
				}
				average += g[i];
		}
		System.out.println(average / 5);
	}

}


Measured memory_bytes: 26344
import sys
from collections import defaultdict
input = sys.stdin.readline

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.root = [-1]*(n+1)
        self.rank = [0]*(n+1)

    def Find_Root(self, x):
        if(self.root[x] < 0):
            return x
        else:
            self.root[x] = self.Find_Root(self.root[x])
            return self.root[x]

    def Unite(self, x, y):
        x_root = self.Find_Root(x)
        y_root = self.Find_Root(y)

        if(x_root == y_root):
            return
        # 違う木に属していた場合rankを見てくっつける方を決める
        if self.rank[x_root] >= self.rank[y_root]:
            self.root[x_root] += self.root[y_root]
            self.root[y_root] = x_root
        else:
            self.root[y_root] += self.root[x_root]
            self.root[x_root] = y_root

    # xとyが同じグループに属するか判断
    def isSameGroup(self, x, y):
        return self.Find_Root(x) == self.Find_Root(y)

    # ノードxが属する木のサイズを返す
    def Count(self, x):
        return self.root[self.Find_Root(x)]

n, k, l = map(int, input().split())
pq = [list(map(int, input().split())) for _ in range(k)]
rs = [list(map(int, input().split())) for _ in range(l)]

uf1 = UnionFind(n)
uf2 = UnionFind(n)

for i in range(k):
    uf1.Unite(pq[i][0], pq[i][1])

for i in range(l):
    uf2.Unite(rs[i][0], rs[i][1])

pairs = []
d = defaultdict(int)

for i in range(1, n+1):
    name = "{} {}".format(uf1.Find_Root(i), uf2.Find_Root(i))
    pairs.append(name)
    d[name] += 1

ans = []
for i in range(n):
    ans.append(d[pairs[i]])

print(*ans)




Measured memory_bytes: 155016
#include<bits/stdc++.h>
#define ll long long int
#define endl '\n'
#define mod 998244353
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define f first
#define s second
#define b begin
#define e end
#define pb push_back
#define mp make_pair
#define FOR(i,a,b) for(i=a;i<b;i++)
#define RFOR(i,a,b) for(i=a;i>=b;i--)
#define all(x) x.begin(),x.end()
#define itfr(it,x) for(it=x.begin();it!=x.end();it++)
#define flash ios_base::sync_with_stdio(false); cin.tie(NULL)
using namespace std;

int solve(int N, vector<int> v)
{
    int dp[N+1];
    dp[1] = 1; 
    for(int i = 2; i <= N; i++)
    {
        dp[i] = 0; 
        for(int j = 0; j < v.size(); j++)
            if(v[j] < i)
                dp[i] = (dp[i]%mod + dp[i-v[j]]%mod)%mod;
    }
    return dp[N];
}

int main()
{
   flash;
   //sieve();
   ll T=1,t,n,m,q,k,i,j;
   // cin>>T;
   while(T--)
   {
      string sr;
      cin>>sr;
      cout<<sr;
      if(sr[sr.length()-1]=='s')
         cout<<'e';
      cout<<'s';
      // cin>>n>>k;
      // vector<int> vec;
      // FOR(i,0,k)
      // {
      //    cin>>m>>t;
      //    FOR(j,m,t+1)
      //       vec.pb(j);
      // }
      // cout<<solve(n,vec);
   }
}

Measured memory_bytes: 3600
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

score = 0
order = -1

for i in range(n):
  score += b[i]
  _order = a[i]

  if order + 1 == _order:
    score += c[order - 1]
    
  order = _order

print(score)

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>

using namespace std;

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

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

	int ans = 0;
	for (int i = 2; i < n; i++) {
		int mini = min({p[i-2], p[i-1], p[i]});
		int maxi = max({p[i-2], p[i-1], p[i]});
		if (p[i-1] != mini && p[i-1] != maxi) {
			ans++;
		}
	}

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


Measured memory_bytes: 256
k=int(input())
ans=set([1,2,3,4,5,6,7,8,9])
for _ in range(11):
  c=set()
  for b in ans:
    x=int(str(b)[-1])
    if x==0:
      c.add(int(str(b)+'0'))
      c.add(int(str(b)+'1'))
    elif x==9:
      c.add(int(str(b)+'9'))
      c.add(int(str(b)+'8'))
    else:
      c.add(int(str(b)+str(x+1)))
      c.add(int(str(b)+str(x)))
      c.add(int(str(b)+str(x-1)))
  ans=ans|c
ans=list(ans)
ans.sort()
print(ans[k-1])

Measured memory_bytes: 296144
#include <cstdio>
#include <sstream>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

int n,u,k,p,d[105],f[105],tt=0;
bool adm[105][105],se[105];

void makemap()
{
    memset(adm,false,sizeof(adm));
    memset(se,true,sizeof(se));
    cin>>n;
    for(int i=0;i<n;i++)
    {
        scanf("%d%d",&u,&k);
        while(k--)
        {
            scanf("%d",&p);
            adm[u][p]=true;
        }
    }
}

void dfs(int p)
{
    d[p]=++tt;
    se[p]=false;
    for(int i=1;i<=n;i++)
        if(adm[p][i]&&se[i])dfs(i);
    f[p]=++tt;
}

int main()
{
    makemap();
    for(int i=1;i<=n;i++)if(se[i])dfs(i);
    for(int i=1;i<=n;i++)printf("%d %d %d\n",i,d[i],f[i]);
    return 0;
}


Measured memory_bytes: 3240
#include <iostream>
#include <algorithm>
#include <climits>
#include <numeric>
#include <iomanip>
#include <cmath>
#include <vector>
#include <set>
#include <unordered_set>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
#include <tuple>

using namespace std;

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define cina(s, n, a) for(int i = s; i < n; i++) cin >> a[i]
#define couta(n, a) for(int i = 0; i < n; i++) cout << a[i] << ' '
#define copy(s, n, a, b) for(int i = s; i < n; i++) b[i] = a[i]
#define yesno(ok) cout << (ok ? "YES" : "NO")
#define mod(a, b) (b + (a % b)) % b
#define MOD  (ll)1e9 + 7

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

void solve(){
    int n;
    cin >> n;
    int x = n / 100;
    int y = ((n / 10) % 10) * 10 + n % 10;
    if(x < 13 && x > 0){
        if(y < 13 && y > 0) cout << "AMBIGUOUS";
        else cout << "MMYY";
    }
    else if(y < 13 && y > 0) cout << "YYMM";
    else cout << "NA";
}

int main(){
    ios::sync_with_stdio(false);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int q = 1;
    //cin >> q;
    for(int i = 1; i <= q; i++){
        solve();
    }
}


Measured memory_bytes: 256
/*
AizuOnline A2155
Title
*/
#include <stdio.h>
// Select Below
//#include <stdlib.h>
#include <string.h>
//#include <float.h>
//#include <math.h>
//#include <limits.h>
//Global data section
int N,M;
struct msg_st
{
        int t;  //time
        int s;  //src
        int d;  //dst
} msg[20000];
char infected[20001];
int inf_machine;
//
int compare_msg(const void *a, const void *b)
{
        return(((struct msg_st *)a)->t - ((struct msg_st *)b)->t);
}


main()
{
        int i;

        while(scanf("%d %d",&N,&M) && (N||M))
        {
                for(i=0;i<M;i++)
                        scanf("%d %d %d",&msg[i].t,&msg[i].s,&msg[i].d);
                memset(infected,0,N+1);
                infected[1]=-1;
                inf_machine=1; 
                qsort(msg,M,sizeof(struct msg_st),compare_msg);
                for(i=0;i<M;i++)
                {
                        if(infected[msg[i].s] && (!infected[msg[i].d]))
                        {
                                infected[msg[i].d]=-1;
                                inf_machine++;
                        }
                }
                printf("%d\n",inf_machine);
        }
return(0);
}

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

int main(){
    int a,b;
    cin >> a >> b;
    cout << a * b <<" " << 2 * (a + b) <<endl;
}



Measured memory_bytes: 3084
S = input()[::-1]
T = input()[::-1]

ans = "UNRESTORABLE"

for i in range(len(S)-len(T)+1) :
    for j in range(len(T)) :
        if S[i+j] not in ["?", T[j]] : 
            break
    else :
        ans = (S[:i]+ T + S[i+len(T):])[::-1].replace("?", "a")
        break

print(ans)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const int maxn = 1e5 + 20;
multiset<int> st;
ll sum;
int main()
{
    int n;
    cin >> n;
    for(int i = 0; i < n; i++)
    {
        int a;
        cin >> a;
        if(a % 10)
            st.insert(a);
        sum += a;
    }
    if(sum % 10 == 0)
    {
        if(st.size() == 0)
        {
            cout << 0;
            return 0;
        }
        cout << sum - *st.begin() << endl;
        return 0;
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main() {
	int h, w, n;
	int sum = 0, count = 0;
	scanf ("%d %d %d", &h, &w, &n);
	
		if (h >= w) {
			for (sum; sum < n; sum += h) {
			count++;
			}
		}
		else {
			for (sum; sum < n; sum += w) {
			count++;
			}	
		}
	printf ("%d", count);
	
	return 0;
}

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

int main() {
	int a, b;
	cin >> a >> b;
	int ans;
	if ((a + b)%2 == 0) {
		ans = (a + b)/2;
	}
	else{
		ans = (a + b)/2 + 1;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3624
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstdlib>

using namespace std;

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

  long long B[N];
  for(int i=0; i<N-1; i++)
    cin >> B[i];

 
  long long dp[N];
  dp[0]=B[0];
  for(int i=1; i<N; i++)
    dp[i]=1000000;
  
  for(int i=0; i<N-1; i++)
    {
      if(B[i]<dp[i+1])
	dp[i+1]=B[i];
      if(B[i]<dp[i])
	dp[i]=B[i];
    }  

  int sum =0;
  for(int i=0; i<N; i++)
    {
      //  cout << dp[i] << " ";
      sum += dp[i];
    }
  //  cout << endl;
  cout << sum << endl;

  

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <utility>
#include <vector>
#include <cstdio>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < n; i++)


bool kaibun(string str) {
    bool hantei = true;
    int N = str.length();
    for (int i = 0; i < N/2; i++) {
        if (str[i] != str[N-1-i]) {
            hantei = false;
            return hantei;
        }
    }
    return hantei;

}

bool kaibun2(string str) {
    bool hantei = true;
    int N = str.length()/2;
    for (int i = 0; i < N/2; i++) {
        if (str[i] != str[N-1-i]) {
            hantei = false;
            return hantei;
        }
    }
    return hantei;

}

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

    if(kaibun(str)) {
       

        if (kaibun2(str)) {
            cout << "Yes" << endl;
            return 0;
        } else {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "No" << endl;
    return 0;
}

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

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

    int res = 0;
    string tmp = "";
    for (auto &&c : S)
    {
        if (c == 'A' || c == 'T' || c == 'C' || c == 'G')
        {
            tmp += c;
        }
        else
        {
            if (tmp.size() > res)
            {
                res = tmp.size();
            }
            tmp = "";
        }
    }
    if (tmp.size() > res)
    {
        res = tmp.size();
    }
    cout << res << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

class MainClass
{
    static void Main()
    {
        var r = Console.ReadLine().Split().Select(long.Parse).ToArray();
        var N = r[0];
        var A = r[1];
        var B = r[2];
        if (B < A)
        {
            Console.WriteLine(0);
            return;
        }
        if (N == 1)
        {
            if (A == B) Console.WriteLine(1);
            else Console.WriteLine(0);

            return;
        }
        

        Console.WriteLine(Math.Abs(A*(N-1)-B*(N-1))-(Math.Abs(A-B))+1);
    }
}

Measured memory_bytes: 28192
H,W=map(int,input().split())
s=[]
dst=[]
INF=1e8
for i in range(H):
    s.append(input())
    dst.append([INF for i in range(W)])

gx=W-1
gy=H-1
que=[]
que.append([0,0])
dst[0][0]=0
x=[-1,1,0,0]
y=[0,0,-1,1]

goalFlag=False
while len(que)>0:
    p=que.pop(0)
    if p[0]==gx and p[1]==gy: 
        goalFlag=True
        break
    for (dx,dy) in zip(x,y):
        nextx=p[0]+dx
        nexty=p[1]+dy
        if H>nexty>=0 and W>nextx>=0 and s[nexty][nextx]=='.' and dst[nexty][nextx]==INF:
            que.append([nextx,nexty])
            dst[nexty][nextx]=dst[p[1]][p[0]]+1
if goalFlag:
    count=0 
    for h in range(H):
        for w in range(W):
            if h==w==0 or (h==gy and w==gx):
                continue
            elif s[h][w]=='.':
                count+=1
    print(count-dst[gy][gx]+1)
else: print(-1)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n; cin >> n;
  string s; cin >> s;
  char moji = s.at(0);
  int cnt = 0;
  int ans = n;
  for(int i = 1; i < n; i++){
   // printf("i:%d s.at(i):%c\n",i,s.at(i));
    if(s.at(i) != moji){
      moji = s.at(i);
      ans -= cnt;
      cnt = 0;
      //cout << "ans "<< ans << endl;
    }
    else cnt++;
  }
  cout << ans - cnt;
}

Measured memory_bytes: 3692
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
#include <functional>
#include <cctype>

using namespace std;

int main()
{
	string W, IN;
	cin >> W;
	transform(W.begin(), W.end(), W.begin(), ::toupper);
	int c = 0;
	while(true) {
		cin >> IN;
		if(IN == "END_OF_TEXT")
			break;
		transform (IN.begin(), IN.end(), IN.begin(), ::toupper);
		if(IN == W)
			++c;
	}
	cout << c << endl;
	return 0;
}

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

int main(void) {
  int a, b, c, ct;

  while (scanf("%d %d", &a, &b) != EOF) {
    ct = 0;
    c = a + b;
    while (c != 0) {
      c /= 10;
      ct++;
    }
    printf("%d\n", ct);
  }
  return (0);
}

Measured memory_bytes: 596
import java.util.Scanner;

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

        int[][] A = new int[3][10];
        int[][] B = new int[3][10];
        int[][] C = new int[3][10];
        int[][] D = new int[3][10];

        for(int i = 0; i < 3; i++){
            for(int j = 0; j < 10; j++)
                A[i][j] = B[i][j] = C[i][j] = D[i][j] = 0;
        }

        int time = sc.nextInt();

        for(int i = 0; i < time; i++){
            int b = sc.nextInt();
            int f = sc.nextInt();
            int r = sc.nextInt();
            int v = sc.nextInt();

            if(b == 1)
                A[f - 1][r - 1] += v;
            if(b == 2)
                B[f - 1][r - 1] += v;
            if(b == 3)
                C[f - 1][r - 1] += v;
            if(b == 4)
                D[f - 1][r - 1] += v;
        }

        for(int i = 0; i < 3; i++){
            for(int j = 0; j < 10; j++)
                System.out.print(" " + A[i][j]);
            System.out.println("");
        }
        System.out.println("####################");
        for(int i = 0; i < 3; i++){
            for(int j = 0; j < 10; j++)
                System.out.print(" " + B[i][j]);
            System.out.println("");
        }
        System.out.println("####################");
        for(int i = 0; i < 3; i++){
            for(int j = 0; j < 10; j++)
                System.out.print(" " + C[i][j]);
            System.out.println("");
        }
        System.out.println("####################");
        for(int i = 0; i < 3; i++){
            for(int j = 0; j < 10; j++)
                System.out.print(" " + D[i][j]);
            System.out.println("");
        }
        
        sc.close();
    }
}



Measured memory_bytes: 30168
using System;

class ABC080A
{
	static public void Main(string[] args)
	{
		int N, A, B;
		string[] vals;
		vals = Console.ReadLine().Split();
		N = int.Parse(vals[0]);
		A = int.Parse(vals[1]);
		B = int.Parse(vals[2]);

		if(N * A > B)
		{
			Console.WriteLine(B);
		}
		else
		{
			Console.WriteLine(N * A);
		}
	}
}


Measured memory_bytes: 13140
#include <iostream>
using namespace std;
long long n, s=1, M=1e9+7, a[1005];
int main() {
	int i, j, k;
	cin>>n;
	for(j=2; j<=n; j++) {
		for(k=j, i=2; k>1; ) {
			if(k%i==0) k/=i, a[i]++;
			else i++;
		}
	}
	for(i=2; i<=n; i++) s = s*(a[i]+1)%M;
	cout<<s;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.lang.*;
import java.io.*;

public class Main {
    public static void main(String args[]) {
        Scanner scan = new Scanner(System.in);
        
        int n = scan.nextInt();
        int k = scan.nextInt();
        int rest = n%k;
        int val = n/k;
        
        int[] arr = new int[k];
        arr[0] = val;
        for(int i = 1; i < k; i++){
            arr[i] = val;
            if(i <= rest) arr[i]++;
        }
        
        long res = 0;
        
        if((k & 1) == 1){
            long temp = 1;
            temp *= arr[0];
            temp *= arr[0];
            temp *= arr[0];
            
            res += temp;
            System.out.println(res);
            return;
        }
        else{
            long temp1 = 1;
            long temp2 = 1;
            for(int i = 0; i < 3; i++){
                temp1 *= arr[0];
                temp2 *= arr[k >> 1];
            }
            res += temp1 + temp2;
            System.out.println(res);
            return;
        }

    }
}


Measured memory_bytes: 23124
from heapq import heappop, heappush
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def prime_factorization(n):
    d = {}
    i = 2
    while i * i <= n:
        if n % i == 0:
            d[i] = 1
            n //= i
            while n % i == 0:
                n //= i
                d[i] += 1
        i += 1
    if n > 1:
        d[n] = 1
    return d

def main():
    N = int(readline())

    d = prime_factorization(N)
    queue = []
    for k, v in d.items(): 
        for i in range(1, v+1):
            heappush(queue, (pow(k, i), k, i))
    
    cnt = dict()
    ans = 0
    while queue:
        z, p, e = heappop(queue)
        if p in cnt:
            if cnt[p] + e <= d[p]:
                cnt[p] += e
                ans += 1
            else:
                continue
        else:
            cnt[p] = e
            ans += 1

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9300
import java.io.IOException;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();

		int[] arr = new int[] { a, b, c };
		Arrays.sort(arr);

		int i;

		for (i = 0; i < arr.length; i++) {
			
			if (i == arr.length - 1) {
				System.out.println(arr[i]);
			}else {
				System.out.print(arr[i]+" ");
			}
		}
	}

}


Measured memory_bytes: 26236
#include<stdio.h>
int main(void){
    int W, H, x, y, r;
    scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);
    if(x - r < 0 || x + r > W || y - r < 0 || y + r > H){
        printf("No\n");
    }
    if(x - r >= 0 && x + r <= W && y - r >= 0 && y + r <= H){
        printf("Yes\n");
    }
    return 0;
}


Measured memory_bytes: 2112