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

using namespace std;

#define fstinpt     ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define ll          long long
#define sn          1010
#define bn          1000007
#define M           1000000007
#define iii(i)      cin>>i
#define ooo(i)      cout<<i
#define sss         cout<<" "
#define nnn         cout<<"\n"
//#define cin(i)      cin>>i
//#define cout(i)      cout<<i
//#define sss         cout<<" "
//#define nnn         cout<<"\n"


ll a[bn],b[bn];
map<ll,ll>m;

int main()
{
        ll a; iii(a);
        ooo(a+a*a+a*a*a);
        return 0;
}



/*






*/






















/**/


Measured memory_bytes: 3616
#include <iostream>
#include <cstdio>
#include <cstring>
#include <math.h>
using namespace std;


int main()
{
    int n;
    int64_t s=1;
    int64_t flag=1000000000000000000;
    cin>>n;
    while(n--)
    {
        int64_t a;
        cin>>a;
        if(!a) {printf("0");return 0;}
        if(flag)
        {s*=a;
        flag/=a;
        if(!flag) s=-1;
        }
    }
    printf("%lld",s);
    return 0;
}


Measured memory_bytes: 3776
n = int(input())
As = list(map(int, input().split()))

internal_max = [1]*(n+1)
internal_max[0] = 1-As[0]

for i in range(1,n+1):
    internal_max[i] = 2*internal_max[i-1]-As[i]

depth_sum = [0]*(n+1)
depth_sum[n] = As[n]
judge = False

for i in range(n-1, -1, -1):
    if depth_sum[i+1] > internal_max[i]*2:
        judge = True
        break
    else:
        depth_sum[i] = As[i] + min(internal_max[i], depth_sum[i+1])

if n == 0:
    if As[0] > 1:
        judge = True

if judge:
    print(-1)
else:
    print(sum(depth_sum))


Measured memory_bytes: 674208
#include<iostream>
#include<string>
#include<map>
#include<algorithm>

using namespace std;

int main()
{
	int a,b,c;
	cin >> a >> b >> c;
	int count = 0;

	for(int i=a; i<=b; i++){
		if(i % c == 0){
			count++;
			// cout << i<< endl;
		}
	}
	cout << count << endl;
}




Measured memory_bytes: 3164
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
#include <map>
#include <math.h>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <set>
#include <queue>
#include <sstream>
#include <stack>
#include <deque>
#include <memory.h>
#include <cassert>
#include <ctime>
#include <climits>
#include <list>
#include <time.h>
#include <unordered_map>
#include <bitset>
#include <exception>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned long long ull;
#define pb push_back
#define mp make_pair
#define FILE "file"
#define lc v << 1
#define rc (v << 1) + 1
#define inf 4 * 1e+9
#define linf ll(1e+18)
#define dinf 1e+14

typedef long long ll;
#define pb push_back
#define mp make_pair

const int maxn = 1e+5 + 5;

int v[26][maxn];

void solve()
{
    string s, t;
    cin >> s >> t;
    
    int n = (int) s.length();
    
    for(char c = 'a'; c <= 'z'; c++)
    {
        int first = -1;
        
        for(int i = 0; i < n; i++)
        {
            if(c == s[i])
            {
                first = i;
                break;
            }
        }
        
        for(int i = n - 1; i >= 0; i--)
        {
            v[c - 'a'][i] = first;
            
            if(i < n - 1)
            {
                v[c - 'a'][i] = v[c - 'a'][i + 1];
            }
            
            if(c == s[i])
            {
                v[c - 'a'][i] = i;
            }
        }
    }
    
    int cur = 0;
    long long ans = 0;
    
    int m = (int) t.length();
    for(int i = 0; i < m; i++)
    {
        int sym = t[i] - 'a';
        if(v[sym][cur] == -1)
        {
            ans = -1;
            break;
        }
        
        long long temp = 0;
        
        if(cur <= v[sym][cur])
        {
            temp = v[sym][cur] - cur + 1;
        }
        else
        {
            temp = n - (cur - v[sym][cur] - 1);
        }
        
        ans += temp;
        cur = (v[sym][cur] + 1) % n;
    }
    
    cout << ans;
}

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    //freopen("/Users/bekhzodsoliev/Desktop/C++/cp/cp/file.in", "r", stdin);freopen("/Users/bekhzodsoliev/Desktop/C++/cp/cp/file.out", "w", stdout);
    
    int t = 1;
    //cin >> t;
    
    while(t--)
    {
        solve();
    }
    
    return 0;
}


Measured memory_bytes: 10704
#include<cstdio>
#include<cstdlib>
int op1, op2, op3;

int binaryToOperand(int binary){
	return binary == 1 ? 1 : -1;
}

void setOperands(int n){
	int tmp;
	tmp = n / 4;
	n %= 4;
	op1 = binaryToOperand(tmp);
	tmp = n / 2;
	n %= 2;
	op2 = binaryToOperand(tmp);
	tmp = n;
	op3 = binaryToOperand(tmp);
}

void printOperand(int operand){
	operand == 1 ? printf("+") : printf("-");
}

int main(void){
	int ticketnumber, A, B, C, D, answer = 0, i = 0;
	scanf("%d",&ticketnumber);
	A = ticketnumber / 1000;
	ticketnumber %= 1000;
	B = ticketnumber / 100;
	ticketnumber %= 100;
	C = ticketnumber / 10;
	ticketnumber %= 10;
	D = ticketnumber;
	while (answer != 7) {
		setOperands(i);
		answer = A;
		answer += (B * op1);
		answer += (C * op2);
		answer += (D * op3);
		i++;
	}	
	printf("%d", A);
	printOperand(op1);
	printf("%d", B);
	printOperand(op2);
	printf("%d", C);
	printOperand(op3);
	printf("%d", D);
	printf("=7\n");
	return 0;
}

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

int n;
int q;
int parent[10000 + 5];

int root(int child) {
  if (parent[child] == child) {
    return child;
  }
  else {
    parent[child] = root(parent[child]);
    return parent[child];
  }
}

bool are_bro(int x, int y) {
  return root(x) == root(y);
}

int main() {
  int com, x, y;
  scanf("%d %d", &n, &q);
  for (int i = 0; i < n; i++) {
    parent[i] = i;
  }
  for (int i = 0; i < q; i++) {
    scanf("%d %d %d", &com, &x, &y);
    if (com == 0) {
      if (not are_bro(x, y)) {
	  parent[root(x)] = parent[root(y)];
      }
    }
    else {
      if (are_bro(x, y)) {
	printf("1\n");
      }
      else {
	printf("0\n");
      }
    }
  }
  return 0;
}


Measured memory_bytes: 3208
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
typedef pair<int,int>P;
#define Z(a,b)v.push_back(make_pair(a,b))

struct comp{bool operator()(const P a,const P b){return a.first*a.second<b.first*b.second;}};
int main(){
	int n,w,d;
	for(;scanf("%d%d%d",&n,&w,&d),w;puts("")){
		vector<P>v;
		Z(w,d);
		for(;n--;){
			int p,s,state=0;
			scanf("%d%d",&p,&s);p--;
			s%=v[p].first+v[p].second;
			unsigned x=v[p].first,y=v[p].second,_x=0,_y=0,x1,x2,y1,y2;
			for(;s--;)if(state==0){_x++;if(_x==x)state=1;}else _y++;
			if(state==0)x1=_x,x2=x-_x,y1=y2=y;
			else x1=x2=x,y1=_y,y2=y-_y;

			v.erase(v.begin()+p);
			if(x1*y1>x2*y2)
				Z(x2,y2),Z(x1,y1);
			else
				Z(x1,y1),Z(x2,y2);
		}

		for(sort(v.begin(),v.end(),comp());v.size();){
			printf("%d",v[0].first*v[0].second);
			v.erase(v.begin());
			if(v.size())printf(" ");
		}
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...) 0
#endif

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll as, bs, m;
    cin >> as >> bs >> m;
    vector<ll> a(as), b(bs);
    for (int i = 0; i < as; i++) cin >> a[i];
    for (int i = 0; i < bs; i++) cin >> b[i];
    ll ans = *min_element(a.begin(), a.end()) + *min_element(b.begin(), b.end());
    for (int i = 0; i < m; i++) {
        int x, y, c;
        cin >> x >> y >> c;
        x--, y--;
        ans = min(ans, a[x] + b[y] - c);
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
  vector<int> a(3);
  cin >> a.at(0) >> a.at(1) >> a.at(2);
  sort(a.begin(), a.end());
  cout << a.at(0) << " " << a.at(1) << " " << a.at(2) << endl;
}



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

using namespace std;
#define inf 1000000000
#define unvisited -1
#define visited 1
#define eps 1e-9
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define uint64 unsigned long long
#define FastSlowInput ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define debug if(true)
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;

int main(){
	ll n;
	scanf("%lld",&n);
	printf("%lld\n",n*n);	
	return 0;
};

Measured memory_bytes: 256
#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 n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a.at(i);
    sort(a.begin(), a.end());
    cout << a.at(a.size()-1) - a.at(0) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <set>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (long long i = m; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using PL = pair<long long, long long>;
const int INF = 1001001007;
const int MOD = 1000000007;
template <typename T>
void printvec(vector<T> &ar){
    rep(i,ar.size()-1) cout << ar[i] << " ";
    cout << ar[ar.size()-1] << endl;
}
template <typename Q>
void printvvec(vector<vector<Q>> &ar){
    rep(i,ar.size()){
        rep(j,ar[0].size()-1) cout << ar[i][j] << " ";
        cout << ar[i][ar[0].size()-1] << endl;
    }
}
template <typename S>
bool range(S a, S b, S x){
    return (a <= x && x < b);
}

int main(){
    int n; cin >> n;
    vector<PL> ar(n);
    rep(i,n){
        cin >> ar[i].first;
        ar[i].second = i+1;
    }
    sort(ar.begin(), ar.end(),greater<PL>());
    //rep(i,n) cout << ar[i].first << " " << ar[i].second << endl;
    vector<vector<ll>> dp(n+1, vector<ll>(n+1,0));
    repp(i,n+1,1){
        dp[0][i] = dp[0][i-1] + ar[i-1].first * (ar[i-1].second - i);
        dp[i][0] = dp[i-1][0] + ar[i-1].first * (n - i + 1 - ar[i-1].second);
    }
    repp(i,n+1,1){
        repp(j,n+1-i,1){
            ll a = ar[i+j-1].first * (ar[i+j-1].second - j);
            ll b = ar[i+j-1].first * (n - i + 1 - ar[i+j-1].second);
            dp[i][j] = max(dp[i][j-1] + a, dp[i-1][j] + b);
        }
    }
    ll ans = 0;
    rep(i,n+1){
        ans = max(ans, dp[i][n-i]);
    }
    //printvvec(dp);
    cout << ans << endl;
}

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

bool is_prime(int n) {
    if (n < 2) return 0;
    if (n == 2) return 1;
    if (n % 2 == 0) return 0;
    for (int i = 3; i * i <= n; i++) {
        if (n % i == 0) return 0;
    }
    return 1;
}

int main() {
    int cnt = 0;
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        if (is_prime(a)) {
            cnt++;
        }
    }
    cout << cnt << endl;
}


Measured memory_bytes: 3076
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        b: String,
    }
    match b.as_ref() {
        "A" => println!("T"),
        "T" => println!("A"),
        "G" => println!("C"),
        "C" => println!("G"),
        _ => panic!(),
    }
}


Measured memory_bytes: 4352
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <climits>
#include <ctime>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <deque>
#include <complex>
#include <string>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <numeric>
#include <iterator>
using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) container.begin(), container.end()
#define RALL(container) container.rbegin(), container.rend()
#define SZ(container) ((int)container.size())
#define mp(a,b) make_pair(a, b)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

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 (a>b) { a=b; return 1; } return 0; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}

const ll INF = 1ll<<60;
const double EPS = 1e-8;
const int MOD = 1000000007;


int n, m, l;

int main(){
	ios::sync_with_stdio(false);
	while(cin >> n >> m >> l){
		vector<ll> K(n), S(m), sum(m+1);
		REP(i, n) cin >> K[i], K[i]--;
		REP(i, m) cin >> S[i];
		sort(ALL(K));
		K.push_back(K.back()); ++n;
		partial_sum(ALL(S), sum.begin()+1);
		vector<vector<ll>> dp(n+1, vector<ll>(n+1, INF));
		dp[0][0] = 0;
		REP(i, n)REP(j, i){
			chmin(dp[i][j]  , dp[i-1][j] + (sum[K[i]+1] - sum[K[i-1]])/l);
			chmin(dp[i][i-1], dp[i-1][j] + (sum[K[i]+1] - sum[K[j]])/l);
		}
		cout << dp[n-1][n-2] << endl;
	}
	return 0;
}

Measured memory_bytes: 34000
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

// inf
constexpr ll infl = 10000000000000000LL;
constexpr int inf = 1000000000;

int main() {
    int N, A, B;
    cin >> N >> A >> B;
    cout << min(A * N, B) << endl;
    return 0;
}

Measured memory_bytes: 888
import java.util.*


fun main(args: Array<String>) {
  val sc = Scanner(System.`in`)
  val a = sc.nextInt()
  val b = sc.nextInt()
  val h = sc.nextInt()
  val m = sc.nextInt()

  println(abc168c(a, b, h, m))
}

private fun abc168c(a: Int, b: Int, h: Int, m: Int): Double {
  val ad = a.toDouble()
  val bd = b.toDouble()
  val hd = h.toDouble()
  val md = m.toDouble()


  val kakudo = 30.0 * hd - 6.0 * md + md / 2.0
  val rad = (2 * Math.PI * kakudo) / 360.0

  val ans = (ad * ad) + (bd * bd) - 2 * ad * bd * Math.cos(rad)

  return Math.sqrt(ans)
}



Measured memory_bytes: 36608
package main

import (
	"fmt"
	"sort"
	"strings"
)

func sortString(s string, reverse bool) string {
	sl := strings.Split(s, "")
	if reverse == true {
		sort.Strings(sl)
	} else {
		sort.Sort(sort.Reverse(sort.StringSlice(sl)))
	}
	return strings.Join(sl, "")
}

func main() {
	var s, t string
	fmt.Scan(&s)
	fmt.Scan(&t)

	//fmt.Println(sortString(s, true))
	//fmt.Println(sortString(t, false))
	if sortString(s, true) < sortString(t, false) {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


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


int main()
{
  int n;
  string s;
  cin >> n >> s;
  rep(i, s.length())
    if (s[i] + n <= 'Z')
      s[i] += n;
    else
      s[i] = 'A' - ('Z' - s[i]) + n - 1;
  cout << s << endl;
  return 0;
}

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

public class Main{
	static int n;
	static int[] A;
	static int q;
	static int m;
	static boolean ret = false;

	public static void main(String[] args) throws NumberFormatException, IOException {


		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		n = Integer.parseInt(br.readLine());

		String [] temp = br.readLine().split(" ");
		int max = temp.length;
		A = new int[max];
		for(int i = 0; i < max ; i++){
			A[i] = Integer.parseInt(temp[i]);
		}

		q = Integer.parseInt(br.readLine());

		temp = br.readLine().split(" ");
		max = temp.length;
		for(int i = 0; i < max ; i++){
			m = Integer.parseInt(temp[i]);
			if(solve(0,m)){
				System.out.println("yes");
			}
			else{
				System.out.println("no");
			}
		}

	}

	public static boolean solve(int i,int m){
		if(m == 0) return true;

		if(i >= n) return false;

		ret = solve(i+1,m) || solve(i+1,m-A[i]);
		return ret;
	}

}

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

int main(){
  int n;
  int num[3];

  cin>>n;
  for(int i=0;i<n;i++)cin>>num[i];
  sort(num,num+n);

  cout<<"1"<<endl;
  for(int i=2;i<=num[0];i++){
    if(n=2){
      if(num[1]%i==0&&num[0]%i==0)cout<<i<<endl;
    }else{
      if(num[1]%i==0&&num[2]%i==0&&num[0]%i==0) cout<<i<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1180
from collections import Counter
MOD = 998244353

N = int(input())

D = list(map(int, input().split()))

if D[0] > 0:
    print(0)
    exit()

c = Counter(D)
if c[0] > 1:
    print(0)
    exit()

ans = 1
for i in range(1, max(c)+1):
    if not c[i]:
        print(0)
        exit()
    
    ans *= pow(c[i-1], c[i], MOD) % MOD

print(ans%MOD)

Measured memory_bytes: 19936
/*
Character Drawing Adapted from FAKEUPDATE.NET
		   _    _____         _
		   \`,""   ,'7"r-..__/ \
		  ,'\ `, ,',','    _/   \
		 /   \, 7 / /     (   \ |
		J     \/ j  L______\  / |
		L   __JF"""/""\"\_,    /
		L,-"| O|  f O |  L_  _/
		F   \_ /  \__/   `-  j|
			.-'    `"""    ,' |          _..====.._
			\__/         r"_  A        ,' _..---.._`,
			 `-.______,,-L// / \  ___,' ,'_..:::.. `,`,
					  j   / / / 7"    `-<""=:'  '':. \ \
					 /   <,' /  F  . i , \   `,    :T W I
					 |    \,'  /    >X<  |     \   :| | L
					 |     `._/    ' ! ` |      I  :| |  G
					  \           \     /       |  :H T  |
					 __>-.__   __,-\   |        |  S P   |
					/     /|   | \  \  \_       | 'A R   |
				   /   __/ |   |  L  L   \      K./ /    L
				  /   |    |   4  I  I    |    E./ /   ,'
				 J    \    I    L F  I    |    // / _,'
		_________|     |   F    |J   F    |   //_/-'
		\   __   |    /   J     |/  J     |  /="
		\\  \_\  \__,' \  F     |   F     |
		\\\_____________\/      F__/      F
		 \\| 计算机编程 |_____/  (______/
		  \/从入门到入土/
*/
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <vector>
#include <sstream>
#include <set>
#include <queue>
#include <stack>
#include <cctype>
#include <map>
#include <climits>
#include <bitset>
#include <functional>
using namespace std;
#define MATH_PI 3.14159265358979323846
int main(){
	ios::sync_with_stdio(false);
	string sTemp;
	vector<string> arrString;
	int iLength, nCount, i;
	cin >> nCount >> iLength;
	for (i = 1; i <= nCount; ++i){
		cin >> sTemp;
		arrString.push_back(sTemp);
	}
	sort(arrString.begin(), arrString.end());
	for (i = 0; i < nCount; ++i){
		cout << arrString[i];
	}
	cout << '\n';
endapp:
	//system("pause > nul");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int 
int main()
{
    ll n;
    cin >> n;
    vector<ll> arr(n);
    for(ll i=0;i<n;i+=1)
    {
        cin >> arr[i];
    }
    for(ll i=1;i<=n-1;i++)
    {
        if(arr[i]>arr[i-1])
        {
            arr[i]--;
        }
        
    }
    ll flag=1;
    for(ll i=1;i<n;i++)
    {
        if(arr[i]<arr[i-1])
        {
            flag=-1;
        }
    }
    if(flag==-1)
    {
        cout << "No\n";
    }
    else
    {
        cout <<"Yes\n";
    }

}


Measured memory_bytes: 3992
H, W = gets.split.map(&:to_i)
B = *$<

C = H.times.map{ [nil]*W }
C[0][0] = B[0][0] == '#' ? 1 : 0
(1...W).each{|c|
	C[0][c] = C[0][c-1]
	C[0][c] += 1 if B[0][c] != B[0][c-1] && B[0][c] == '#'
}
(1...H).each{|r|
	C[r][0] = C[r-1][0]
	C[r][0] += 1 if B[r][0] != B[r-1][0] && B[r][0] == '#'
}
(1...H).each{|r|
	(1...W).each{|c|
		up = C[r-1][c]
		up += 1 if B[r][c] != B[r-1][c] && B[r][c] == '#'
		lf = C[r][c-1]
		lf += 1 if B[r][c] != B[r][c-1] && B[r][c] == '#'
		C[r][c] = [up, lf].min
	}
}
p C[-1][-1]


Measured memory_bytes: 3964
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        int n = sc.NextInt();
        int x = sc.NextInt();
        int[] a = sc.IntArray();

        a = a.OrderBy(_a => _a).ToArray();

        int answer = 0;
        for (int i = 0; i < n; i++)
        {
            if (x >= a[i])
            {
                answer++;
                x -= a[i];
            }
            else
            {
                break;
            }
        }

        if (answer == n && x > 0)
        {
            answer--;
        }

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

Measured memory_bytes: 11348
#include <iostream>
#include <cstring>
#include<vector>
#include <algorithm>
#include<cstdlib>
#include<set>
#include<math.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(i,n) for(ll i=0;i<n;i++)

int main()
{
	ll x,y;
	cin >> x;
	ll p, q;
	p = (x - x % 500) / 500;
	y = x - p * 500;
	q = (y - y % 5) / 5;
	ll ans;
	ans = 1000 * p + 5 * q;
	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 3532
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {
	static String Per(String s) {
		ArrayList<Character> list = new ArrayList<>();
		for (int i=0; i<s.length(); i++) list.add(s.charAt(i));

		int pivotPos = -1;
		char pivot = 0;
		for (int i=list.size()-2; i>=0; i--) {
			if (list.get(i) < list.get(i+1)) {
				pivotPos = i;
				pivot = list.get(i);
				break;
			}
		}

		if (pivotPos==-1 && pivot==0) return "Final";

		int L = pivotPos+1, R = list.size()-1;
		int minPos = -1;
		char min = Character.MAX_VALUE;
		for (int i=R; i>=L; i--) {
			if (pivot < list.get(i)) {
				if (list.get(i) < min) {
					min = list.get(i);
					minPos = i;
				}
			}
		}
		Collections.swap(list, pivotPos, minPos);
		Collections.sort(list.subList(L, R+1));

		StringBuilder sb = new StringBuilder();
		for (int i=0; i<list.size(); i++) sb.append(list.get(i));

		return sb.toString();
	}
	public static void main(String[] args) throws Exception {
        Scanner stdin = new Scanner(System.in);

        int N = stdin.nextInt();
        int x[] = new int[N];
        int y[] = new int[N];
        double avg=0;
        String s="";
        int cnt=0;

        for(int i=0;i<N;i++) {
        	s+=String.valueOf(i);
        	x[i] = stdin.nextInt();
        	y[i] = stdin.nextInt();
        }
        while(true) {
        	int j[] = new int[N];
        	for(int i=0;i<s.length();i++) {
        		j[i] = Integer.parseInt(s.substring(i,i+1));
        	}

	        for(int i=0;i<N-1;i++) {
	        	int l;
	        	int o;
	         	for(l=0;;l++){
	         		if(i == j[l]) break;
	         	}
	         	for(o=0;;o++) {
	         		if(i+1 == j[o]) break;
	         	}
	        	avg += Math.sqrt((x[l]-x[o])*(x[l]-x[o])+(y[l]-y[o])*(y[l]-y[o]));
	        }
	        cnt+=1;
	        s = Per(s);
	        if(s.equals("Final"))break;
        }
        System.out.println(avg/cnt);
	}
}


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

int main() {
    int H;
    int W;
    cin >> H;
    cin >> W;
	bool a[H][W];
	for (int i = 0; i < H; i++) {
	    string s;
	    cin >> s;
	    for (int j = 0; j < W; j++) {
	        if (s[j] == '.') {
	            a[i][j] = false;
	        } else {
	            a[i][j] = true;
	        }
	    }
	}

	int gyou = 0;
	bool b[H][W];
	for (int i = 0; i < H; i++) {
	    bool aho = false;
	    for (int j = 0; j < W; j++) {
	        //一個でもa[i][j]が#がある
	        if (a[i][j]) {
	            aho = true;
	        }
	    }
	    //#がある場合
	    if (aho) {
	        for (int j = 0; j < W; j++) {
	            b[gyou][j] = a[i][j];
	        }
	        gyou++;
	    }
	}

	int retsu = 0;
	bool c[gyou][W];
	for (int j = 0; j < W; j++) {
	     bool aho = false;
	     for (int i = 0; i < gyou; i++) {
        	 //一個でもb[i][j]が#がある
        	 if (b[i][j]) {
        	     aho = true;
        	 }
         }
         //#がある場合
         if (aho) {
        	  for (int i = 0; i < gyou; i++){
        	      c[i][retsu] = b[i][j];
        	  }
        	  retsu++;
         }
	}

	for (int i = 0; i < gyou; i++) {
	    char s[retsu+1];
	    for (int j = 0; j < retsu; j++) {
	        if (c[i][j]) {
	            s[j] = '#';
	        } else {
	            s[j] = '.';
	        }
	    }
	    s[retsu] = '\0';
	    cout << s << endl;
	}

	return 0;
}


Measured memory_bytes: 256
;; -*- coding: utf-8 -*-
(eval-when (:compile-toplevel :load-toplevel :execute)
  (defparameter OPT
    #+swank '(optimize (speed 3) (safety 2))
    #-swank '(optimize (speed 3) (safety 0) (debug 0)))
  #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))
                 (shadow :run)
                 (use-package :fiveam)))
#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)

;; BEGIN_INSERTED_CONTENTS
(declaim (ftype (function * (values fixnum &optional)) read-fixnum))
(defun read-fixnum (&optional (in *standard-input*))
  (declare #.OPT)
  (macrolet ((%read-byte ()
               `(the (unsigned-byte 8)
                     #+swank (char-code (read-char in nil #\Nul))
                     #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\Nul) nil))))
    (let* ((minus nil)
           (result (loop (let ((byte (%read-byte)))
                           (cond ((<= 48 byte 57)
                                  (return (- byte 48)))
                                 ((zerop byte) ; #\Nul
                                  ;; (return-from read-fixnum 0)
                                  (error "Read EOF or #\Nul."))
                                 ((= byte #.(char-code #\-))
                                  (setf minus t)))))))
      (declare ((integer 0 #.most-positive-fixnum) result))
      (loop
        (let* ((byte (%read-byte)))
          (if (<= 48 byte 57)
              (setq result (+ (- byte 48) (the fixnum (* result 10))))
              (return (if minus (- result) result))))))))

;; Body

(defun main ()
  (dotimes (_ (the fixnum (read)) (write-line "second"))
    (when (oddp (read-fixnum))
      (write-line "first")
      (return-from main))))

#-swank(main)


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

int main()
{
  int n, m;
  cin >> n;
  m = n + 1;
  int a[m], b[n];
  rep(i, m) cin >> a[i];
  rep(i, n) cin >> b[i];
  ll ans = 0;
  rep(i, n) {
    if(b[i] <= a[i]){
      ans += b[i];
    }
    else{
      ans += a[i];
      b[i] -= a[i];
      if(b[i] <= a[i + 1]){
        ans += b[i];
        a[i + 1] -= b[i];
      }
      else{
        ans += a[i + 1];
        a[i + 1] = 0;
      }
    }
    //cout << b[i] << " " << a[i] << endl;
  }
  cout << ans << endl;


    
  
  return 0;
}


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

struct node{
	unsigned int key;
	struct node *next;
	struct node *prev;
};

typedef struct node * NodePointer;

NodePointer nil;

NodePointer listSearch(int key){
	NodePointer  cur=nil->next;
	while(cur!=nil && cur->key!=key){
		cur=cur->next;
	}
	return cur;
}

void init(){
	nil = malloc(sizeof(struct node));
	nil->next = nil;
	nil->prev = nil;
}

void printList(){
	NodePointer cur = nil->next;
	int isf = 1;
	while(1){
		if ( cur == nil ){
			break;
		}
		if ( isf == 0){
			printf(" ");
		}
		printf("%d", cur->key);
		cur = cur->next;
		isf = 0;
	}
  	printf("\n");
}

void deleteNode(NodePointer t){
	if(t==nil){
		return;
	}
	t->prev->next=t->next;
	t->next->prev=t->prev;
	free(t);
}

void deleteFirst(){
	NodePointer t = nil->next;
	if ( t == nil ) {
		return;
	}
	deleteNode(t);
}

void deleteLast(){
	deleteNode(nil->prev);
}

void delete(int key){
	deleteNode(listSearch(key));
}


void insert(int key){
	NodePointer x;
	x = malloc(sizeof(struct node));
	x->key = key;
	x->next=nil->next;
	nil->next->prev=x;
	nil->next=x;
	x->prev=nil;
}

int main(){
	int key, n, i;
	int size = 0;
	char com[20];
	int np = 0, nd = 0;
	scanf("%d", &n);
	init();
	for ( i = 0; i < n; i++ ){
		scanf("%s%d", com, &key);
		if ( com[0] == 'i' ) {
			insert(key); np++; size++;
		}
		else if ( com[0] == 'd' ) {
			if (strlen(com) > 6){
				if ( com[6] == 'F' ){
					deleteFirst();
				}
				else if ( com[6] == 'L' ){
					deleteLast();
				}
			} 
			else {
				delete(key); nd++; 
			}
		size--;
		}
	}
	printList();
	return 0;
}



Measured memory_bytes: 32988
#include <algorithm>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f, MOD = 1000000007;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
/*-----------------------------------------*/
int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int n; long long k; cin >> n >> k;
  vector<long long> a(n); vector<int> b(n); REP(i, n) cin >> a[i] >> b[i];
  long long now = 0, ans = 0;
  for (int i = 30; i >= 0; --i) if ((k >> i) & 1) {
    now |= (1LL << i);
    long long tmp = now - 1, value = 0;
    REP(i, n) {
      if ((tmp | a[i]) <= tmp) value += b[i];
    }
    ans = max(ans, value);
  }
  long long value = 0;
  REP(i, n) {
    if ((k | a[i]) <= k) value += b[i];
  }
  ans = max(ans, value);
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll mod = 998244353;
const ll INF = mod * mod;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)

int main()
{
    int N; cin >> N;
    vector<int> D(N + 5); rep(i, N) cin >> D[i];

    vector<int> A(N + 5, 0);
    bool flag = true;
    rep(i, N) A[D[i]]++;

    ll ans;
    if (D[0] == 0 && A[0] == 1) ans = 1;
    else ans = 0;

    rep(i, N - 1)
    {
        int a = A[i], b = A[i + 1];
        rep(i, b)
        {
            ans *= a;
            ans %= mod;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
def main ():
    N = int(input())
    A = list(map(int,input(). split ()))
    if 0 in A:
        print(0)
        return
    
    prod = 1
    for a in A:
        prod *= a
        if prod > 1000000000000000000:
            print(-1)
            return
    print(prod)
    
main ()

Measured memory_bytes: 21656
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
using namespace std;
int main()
{ 
    int a[100],n,m,x,y,i;
	while(scanf("%d%d",&n,&m)!=EOF)
	{
		memset(a,0,sizeof(a));
		for(i=1;i<=m;i++)
		{
			scanf("%d%d",&x,&y);
			a[x]++;
			a[y]++;
		}
		for(i=1;i<=n;i++)
		printf("%d\n",a[i]);
	}
	return 0;
}

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

using namespace std;

int main() {
	int N, A, B;
	cin >> N >> A >> B;

	if (A + B <= N) {
		cout << min(A,B)  << " " << 0 << endl;
	}
	else {
		cout << min(A, B) <<" "<< A + B - N << endl;
	}

}




Measured memory_bytes: 256
using System;

namespace abc104A
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            int R = int.Parse(Console.ReadLine());
            if (R < 1200)
            {
                Console.WriteLine("ABC");
            }
            else if (R < 2800)
                Console.WriteLine("ARC");
            else
                Console.WriteLine("AGC");
        }
    }
}


Measured memory_bytes: 13140
a = int(input())
b = int(input())
c = int(input())
x = int(input())
cnt = 0
for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            if 500*i+100*j+50*k == x:
                cnt += 1
print(cnt)

Measured memory_bytes: 3060
#include <iostream>
using namespace std;
bool isPrime(int x) { for(int i=2; i*i<=x; i++) if(x%i==0) return false; return true; }
int main() {
  int n;
  while(cin >> n, n) {
    int ans = 0;
    for(int i=0; !isPrime(n+i); i++, ans++);
    for(int i=0; !isPrime(n-i); i++, ans++);
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
N,M=map(int,input().split())
AB=[[int(x) for x in input().split()] for i in range(N)]
AB.sort(key=lambda x: x[0])
out = 0
count = M
for i in range(N):
    if AB[i][1]<count+1:
        count-=AB[i][1]
        out+=AB[i][0]*AB[i][1]
    else:
        out+=count*AB[i][0]
        break
print(out)

Measured memory_bytes: 22756
//yukicoder@cpp14
//author:luckYrat(twitter:@luckYrat_)

#include <iostream>

#include <cmath>
#include <algorithm>
#include <iomanip>

#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <bitset>

#include <cctype>
#include <utility>
#include <climits>


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


const int mod = 1000000007;
const int inf = (1<<30)-1;
const ll linf = (1LL<<62LL)-1;
const double EPS = (1e-10);


#define anyfill(n,s) setw(n) << setfill(s)
#define loop(s) for(int i = 0; s > i; i++)
#define rep(i,q) for(int i = 0; (q) > i; i++)
#define repp(i,n,q) for(int i = n; (q) > i; i++)
#define dep(i,q) for(int i = (q); 0 < i; i--)


#define pb push_back
#define fir first
#define scn second
#define ednl endl


#define YesNo(a) (a?"Yes":"No")
#define YESNO(a) (a?"YES":"NO")
#define yesno(a) (a?"yes":"no")

P ar4[4] = {{0,1},{0,-1},{1,0},{-1,0}};
P ar8[8] = {{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};
struct dice{
  int me[6];
  dice(int m[]){
    for(int i = 0; 6 > i; i++){
      me[i] = m[i];
    }
  }
  void func(char c){
    if(c=='W'){
      int tmp = me[3];
      me[3]=me[0];
      me[0]=me[2];
      me[2]=me[5];
      me[5]=tmp;
    }else if(c=='E'){
      int tmp = me[3];
      me[3]=me[5];
      me[5]=me[2];
      me[2]=me[0];
      me[0]=tmp;
    }else if(c=='N'){
      int tmp = me[4];
      me[4]=me[0];
      me[0]=me[1];
      me[1]=me[5];
      me[5]=tmp;
    }else{
      int tmp = me[4];
      me[4]=me[5];
      me[5]=me[1];
      me[1]=me[0];
      me[0]=tmp;
    }
  }
  int up(){
    return me[0];
  }
  int three(int x,int y){
    for(int i = 0; 6 > i; i++){
      if(x==me[i]){
        x=i+1;
        break;
      }
    }
    for(int i = 0; 6 > i; i++){
      if(y==me[i]){
        y=i+1;
        break;
      }
    }
    bool sec = false;
    while(true){
      if((x==1&&y==2)||(x==2&&y==6)||(x==6&&y==5)||(x==5&&y==1)){
        if(sec){
          return me[3];
        }
        return me[2];
      }else if((x==4&&y==2)||(x==2&&y==3)||(x==3&&y==5)||(x==5&&y==4)){
        if(sec){
          return me[5];
        }
        return me[0];
      }else if((x==1&&y==4)||(x==4&&y==6)||(x==6&&y==3)||(x==3&&y==1)){
        if(sec){
          return me[4];
        }
        return me[1];
      }else{
        swap(x,y);
        sec = true;
      }
    }
  }

};

__attribute__((constructor))
void initial() {
 cin.tie(0);
 ios::sync_with_stdio(false);
}
int main(){
  int m[6];
  for(int i = 0; 6 > i; i++){
    cin>>m[i];
  }
  dice Dice(m);
  int q;cin>>q;
  while(q--){
    int x,y;cin>>x>>y;
    cout << Dice.three(x,y) << endl;
  }
}



Measured memory_bytes: 3152
import java.util.Arrays;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int k = in.nextInt();
		int[] h = new int[n];
		for ( int i = 0; i < h.length; i++ ) {
			h[i] = in.nextInt();
		}

		int[] cumlativeCost = new int[n];
		Arrays.fill(cumlativeCost, Integer.MAX_VALUE);
		cumlativeCost[0] = 0;

		// i番目に来るには、(i-k)~(i-1)番目のどこかコスト最小になる杭から飛び移る
		for ( int s1 = 0; s1 < cumlativeCost.length; s1++ ) {
			for ( int s2 = s1 + 1; s2 < cumlativeCost.length && s2 <= s1 + k; s2++ ) {
				// （ジャンプ元までの最適コスト + ジャンプ元からのコスト） or (従前の値) のうち小さい方で更新
				cumlativeCost[s2] = Math.min(cumlativeCost[s1] + Math.abs(h[s2] - h[s1]), cumlativeCost[s2]);
			}
		}

		System.out.println(cumlativeCost[n - 1]);
		in.close();
	}
}

Measured memory_bytes: 50624
#include <iostream>
#include <algorithm>
#include <queue>
#include <utility>
using namespace std;

const int MAX_V = 30;
const int INF = (1 << 28);

typedef pair<int, int> pii;
// ??????: 0 -> ???, 1 -> ???, 2 -> ???, 3 -> ???
typedef pair<pii, pii> P; // (??????????????????)?????§?¨?

int w, h;
int cost[4][MAX_V][MAX_V];
int s[MAX_V][MAX_V];
int c[4];
pii dir[4] = {pii(1, 0), pii(0, 1), pii(-1, 0), pii(0, -1)};

int main(void) {
    while (cin >> w >> h, w) {
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                cin >> s[i][j];
            }
        }
        for (int i = 0; i < 4; i++) {
            cin >> c[i];
        }

        priority_queue<P, vector<P>, greater<P>> que;
        que.push(P(pii(0, 0), pii(0, 0)));

        for (int i = 0; i < 4; i++)
            for (int j = 0; j < MAX_V; j++)
                for (int k = 0; k < MAX_V; k++)
                    cost[i][j][k] = INF;
        cost[0][0][0] = 0;

        while (!que.empty()) {
            P p = que.top(); que.pop();
            pii v = p.second;
            int d = p.first.second;

            if (cost[d][v.second][v.first] < p.first.first) continue;

            // cout << "#: " << v.first << " " << v.second << " d = " << d << endl;
            for (int i = 0; i < 4; i++) {
                int nd = (i+d)%4;
                int x = v.first + dir[nd].first;
                int y = v.second + dir[nd].second;

                if (0 <= x && x < w && 0 <= y && y < h) {
                    int nc = cost[d][v.second][v.first] + ((i == s[v.second][v.first]) ? 0 : c[i]);
                    if (cost[nd][y][x] > nc) {
                        cost[nd][y][x] = nc;
                        que.push(P(pii(nc, nd), pii(x, y)));
                    }
                }
            }
        }

        int ans = INF;
        for (int i = 0; i < 4; i++) {
            ans = min(ans, cost[i][h-1][w-1]);
        }

        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 1328
import java.util.HashMap;
import java.util.Map.Entry;
import java.util.Scanner;

class Main {
	public static void pr(Object o) {
		System.out.println(o);
	}

	static class Point {
		int x;
		int y;

		public Point() {

		}

		public Point(int x, int y) {
			this.x = Math.max(Math.min(x, 30), -30);
			this.y = Math.max(Math.min(y, 30), -30);
		}

		@Override
		public boolean equals(Object obj) {
			if (obj instanceof Point) {
				Point p = (Point) obj;
				return x == p.x && y == p.y;
			}
			return false;
		}

		public int hashCode() {
			return x + 37 * y;
		}

		public String toString() {
			return x + "," + y;
		}
	}

	HashMap<Point, Integer> pmap;

	static Point[] dir;
	static {
		dir = new Point[] { new Point(1, 0), new Point(1, 1), new Point(0, 1),
				new Point(-1, 0), new Point(-1, -1), new Point(0, -1) };
	}
	int x, y;
	int t, n;
	int count;

	void move(Point p, int turn) {
		if ((pmap.get(p) == null || pmap.get(p) > turn) && turn <= t) {
			for (int i = 0; i < 6; i++) {
				Point _p = new Point();
				_p.x = p.x + dir[i].x;
				_p.y = p.y + dir[i].y;
				move(_p, turn + 1);
			}
			pmap.put(p, turn);
		}
	}

	public void run() {
		Scanner sc = new Scanner(System.in);
		while (true) {
			n = 0;
			pmap = new HashMap<Point, Integer>();
			t = sc.nextInt();
			n = sc.nextInt();
			if (t == 0 && n == 0) {
				break;
			}
			for (int i = 0; i < n; i++) {
				Point p = new Point();
				p.x = sc.nextInt();
				p.y = sc.nextInt();
				pmap.put(p, -2);
			}
			Point zero = new Point();
			zero.x = sc.nextInt();
			zero.y = sc.nextInt();
			move(zero, 0);
			count = 0;
			if (pmap.size() > 0) {
				for (Entry<Point, Integer> p : pmap.entrySet()) {
					if (p.getValue() >= 0) {
						count++;
					}
				}
			}
			pr(count);
		}
	}

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

Measured memory_bytes: 16000
#include<bits/stdc++.h>
#define For(i,x,y) for (register int i=(x);i<=(y);i++)
#define FOR(i,x,y) for (register int i=(x);i<(y);i++)
#define Dow(i,x,y) for (register int i=(x);i>=(y);i--)
#define Debug(v) for (auto i:v) printf("%lld ",i);puts("")
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define ep emplace_back
#define siz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define fil(a,b) memset((a),(b),sizeof(a))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pa;
typedef pair<ll,ll> PA;
typedef vector<int> poly;
inline ll read(){
    ll x=0,f=1;char c=getchar();
    while ((c<'0'||c>'9')&&(c!='-')) c=getchar();
    if (c=='-') f=-1,c=getchar();
    while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
    return x*f;
}

const int N = 2e5+10;
int n,a[N],b[N];
ll c[N];
priority_queue<pair<ll,int>>q;

inline void GG(){
	puts("-1");exit(0);
}
inline int l(int u){
	return u==1?n:u-1;
}
inline int r(int u){
	return u==n?1:u+1;
}

int main(){
	n=read();
	For(i,1,n) a[i]=read();
	For(i,1,n) b[i]=c[i]=read();
	For(i,1,n) if (a[i]!=b[i]) q.push(mp(b[i],i));
	ll ans=0;
	while (!q.empty()){
		int u=q.top().se;q.pop();
		if (q.empty()){
			ll tmp=c[u==n?1:u+1]+c[u==1?n:u-1];
			if ((c[u]-a[u])%tmp) GG();
			ans+=(c[u]-a[u])/tmp;break;
		}
		int v=l(u);
		if (c[r(u)]>c[v]) v=r(u);
		ll tmp=c[r(u)]+c[l(u)],x=(c[u]-max(c[v],(ll)a[u]))/tmp;
		x=max(x,1ll);
		c[u]=c[u]-x*tmp,ans+=x;
		if (c[u]<a[u]) GG();
		if (c[u]>a[u]) q.push(mp(c[u],u));
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 10500
import scala.math

object Main extends App {
  def divisors(n: Int): List[Int] =
    for (i <- (1 to n).toList if n % i == 0) yield i
  val sc = new java.util.Scanner(System.in)
  var d = sc.nextInt()
  var s = List.fill(26)(sc.nextInt())
  var c = Array.ofDim[Int](d,26)
  for (i <- 0 until d){
    c(i) = Array.fill(26)(sc.nextInt())
  }
  for(i <- 0 until d){
    println( c(i).indexOf(c(i).max) + 1)
    for (j <- 0 until d){
      c(j)(c(i).indexOf(c(i).max)) *= s(c(i).indexOf(c(i).max)) / 100000
    }
  }
}


Measured memory_bytes: 58060
import sys
x, y = [int(i) for i in input().split()]
list = [1,3,5,7,8,10,12,4,6,9,11,2,0]
slice1 = list[0:7]
slice2 = list[7:11]
slice3 = list[11:12]

if x in slice1 and y in slice1:
    print('Yes')
elif x in slice2 and y in slice2:
    print ('Yes')
elif x in slice3 and y in slice3:
    print ('Yes')
else:
    print ('No')

Measured memory_bytes: 3064
while True:
    n,k=map(int,input().split())
    if n==0 and k==0:
        break
    a=[]
    max=0
    sum=0
    for i in range(n):
        a.append(int(input()))
        if i<k:
            sum+=a[i]
        else:
            sum+=a[i]-a[i-k]
        if i>=k-1 and max<sum:
            max=sum
    print(max)


Measured memory_bytes: 9608
import java.io.*;
import java.util.*;
public class Main {
    private static MyScanner scanner;

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

    private void solve() {
        try {
            int N = scanner.nextInt();
            int kisu = 0, gusu = 0;
            for (int i = 0; i < N; i++) {
                long ai = scanner.nextLong();
                if (ai % 2 == 0) {
                    gusu++;
                } else {
                    kisu++;
                }
            }
            gusu += kisu / 2;
            kisu = kisu - kisu / 2 * 2;
            if (kisu == 0) {
                System.out.println("YES");
            } else {
                System.out.println("NO");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private class MyScanner {
        String[] s;
        int i;
        BufferedReader br;
        String reg = " ";

        MyScanner () {
            s = new String[0];
            i = 0;
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public String next() throws IOException {
            if (i < s.length) return s[i++];
            String line = br.readLine();
            while (line.equals("")) {
                line = br.readLine();
            }
            s = line.split(reg, 0);
            i = 0;
            return s[i++];
        }

        public int nextInt() throws NumberFormatException, IOException {
            return Integer.parseInt(next());
        }

        public double nextDouble() throws NumberFormatException, IOException {
            return Double.parseDouble(next());
        }

        public long nextLong() throws NumberFormatException, IOException {
            return Long.parseLong(next());
        }
    }
}

Measured memory_bytes: 40348