akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <array>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <string>
#include <utility>
#include <vector>
#define FOR(i,a,b) for (int i=(a),for_##i##_max=(b);i<=(for_##i##_max);++i)
#define RFOR(i,a,b) for (int i=(a),rfor_##i##_min=(b);i>=(rfor_##i##_min);--i)
#define REP(i,n) for (int i=0,rep_##i##_len=(n);i<(rep_##i##_len);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)
constexpr int INF = 100100100;

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

template<typename T>
void chmin(T &x, T y) {
  x = std::min(x, y);
}

template<typename T>
void chmax(T &x, T y) {
  x = std::max(x, y);
}

using namespace std;

void solve(int height, int width, vector<string> const &field) {
  vector<vector<int>> dist(height, vector<int>(width, INF));
  queue<tuple<int, int, int>> que;
  REP(i, height) REP(j, width) {
    if (field[i][j] == '#') {
      que.emplace(i, j, 0);
    }
  }
  while (!que.empty()) {
    int i, j, d;
    tie(i, j, d) = que.front();
    que.pop();
    if (d >= dist[i][j]) {
      continue;
    }
    dist[i][j] = d;
    REP(p, 4) {
      int ni = i + dx[p], nj = j + dy[p];
      if (ni < 0 || height <= ni || nj < 0 || width <= nj) {
        continue;
      }
      que.emplace(ni, nj, d + 1);
    }
  }
  int ans = -1;
  REP(i, height) REP(j, width) {
    chmax(ans, dist[i][j]);
  }
  cout << ans << endl;
}

int main() {
  // cout << fixed << setprecision(10);
  int H, W;
  cin >> H >> W;
  vector<string> field;
  REP(i, H) {
    string row;
    cin >> row;
    field.push_back(row);
  }
  solve(H, W, field);
  return 0;
}


Measured memory_bytes: 53576
#include <stdio.h>
#include <stdlib.h>

int main(void){
    int x, n, i, s[102]={0}, min=99999, ans;
    scanf("%d%d",&x,&n);
    int p[n];
    for(i=0;i<n;i++){
        scanf("%d",&p[i]);
        s[p[i]] = 1;
    }

    for(i=0;i<102;i++){
        if(s[i] != 1){
            if(min > abs(x-i)){
                min = abs(x-i);
                ans = i;
            }else{
                continue;
            }
        }
    }

    printf("%d",ans);

    return 0;
}

Measured memory_bytes: 1692
#include<stdio.h>
long long int dp[30];
int main(){
	dp[0]=1;
	dp[1]=2;
	dp[2]=4;
	for(int i=3;i<30;i++)dp[i]=dp[i-1]+dp[i-2]+dp[i-3];
	int a;
	while(scanf("%d",&a),a)printf("%d\n",((dp[a-1]+9)/10+364)/365);
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int main(){
  int H,N;
  cin>>H>>N;
  vector<int>ougi(N);
  int yu=0;
  for(int i=0;i<N;i++){
    cin>>ougi.at(i);
    yu+=ougi.at(i);
    
  }
  if(yu>=H){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}

  
    

Measured memory_bytes: 640
#include <stdio.h>

int main(int argc, char const *argv[]) {
  int i, n, flag = 1, tmp, count = 0;
  int A[100];

  scanf("%d", &n);
  for(i = 0; i < n; i++) {
    scanf("%d", &A[i]);
  }

  while(flag) {
    flag = 0;
    for(i = n - 1; i > 0; i--) {
      if(A[i] < A[i - 1]){
        tmp = A[i];
        A[i] = A[i - 1];
        A[i - 1] = tmp;
        flag = 1;
        count++;
      }
    }
  }

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

  return 0;
}


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

using namespace std;

int main() {
    string s, result = "";
    cin >> s;
    for (int i = 0; s[i]; i++) {
        if (s[i] == '1')
            result += "1";
        else if (s[i] == '0')
            result = result + "0";
        else if (result.size() >= 1)
            result.pop_back();
    }
    cout << result;
}


Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <functional>
using namespace std;
#define int long long
#define All(v) (v).begin(),(v).end()
const int mod = 1000000007;
const int inf = mod*mod;
const int d5 = 100100;
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a,b,c;
    cin>>a>>b>>c;
    cout<<c<<' '<<a<<' '<<b<<endl;
}

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

const int MAXN = 1e5 + 5;
ll n, x, hmod, pref[MAXN];

struct test {
    ll b, l, u;
    bool operator< (const test &o) const { return (b*l + (x - b)*u) > (o.b*o.l + (x - o.b)*o.u); }
};
vector<test> tests;

bool can(ll hrs) {
    ll hm = hrs % x, take = hrs / x;
    ll score = 0;
    for(int i = 0; i < n; i++)
        score -= tests[i].b * tests[i].l;
    ll bestGain = 0;
    for(int i = 0; i < n; i++) {
        test t = tests[i];
        ll gain = 0;
        if(i >= take)
            gain = pref[take - 1];
        else {
            gain = pref[take];
            gain -= (t.b*t.l + (x - t.b)*t.u);
        }
        gain += (hm >= t.b ? (t.l*t.b + (hm - t.b)*t.u) : hm*t.l);
        bestGain = max(gain, bestGain);
    }
    score += bestGain;
    return score >= 0ll;
}

int main() {
    cin >> n >> x;
    for(int i = 0; i < n; i++) {
        ll b, l, u;
        cin >> b >> l >> u;
        tests.push_back({b, l, u});
    }
    sort(tests.begin(), tests.end());
    for(int i = 0; i < n; i++) {
        test t = tests[i];
        pref[i] = t.b*t.l + (x - t.b)*t.u;
        if(i > 0)
            pref[i] += pref[i - 1];
    }
    ll lo = 0;
    ll hi = n*x;
    while(lo < hi) {
        ll mi = (lo + hi)/2ll;
        if(can(mi))
            hi = mi;
        else
            lo = mi + 1ll;
    }
    cout << lo << endl;
}

Measured memory_bytes: 4980
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pi M_PI
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  int n;
  cin >> n;
  string s;
  R s;
  int x=0,z=0;
  rep(i,n) {
    if(s[i]=='(') z++;
    else z--;
    if(z<0) {
      x++;
      z=0;
    }
  }
  rep(i,x) s='('+s;
  rep(i,z) s+=')';
  pr(s);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


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

int main() {
  int N, A;
  string op;
  cin >> N >> A;

  if (A <= 1000) {
    if (N % 500 == 0 && A == 0) {
      cout << "Yes" <<endl;
        }
    else if (N % 500 <= A ) {
      cout << "Yes" <<endl;
        }
    else {
      cout << "No" <<endl;
        }
    }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
//INCLUDE
//------------------------------------------
#include <bits/stdc++.h>
//DEFINE
//------------------------------------------
#define ll long long
#define ld long double
#define ALLv(a)  (a).begin(),(a).end()
#define ALL(a,n)  (a),(a)+n
#define vi vector<long long>
#define vd vector<long double>
#define vs vector<string>
//CONST
//------------------------------------------
#define INF 1010000000000000017LL
#define MOD 1000000007LL
#define EPS 1e-12
#define PI 3.14159265358979323846
//REPEAT
//------------------------------------------
#define   FOR(i,m,n) for(ll (i)=(m);   (i)<(n);  (i)++)
#define   REP(i,n)   for(ll (i)=0;     (i)<(n);  (i)++)
#define  REPS(i,x)   for(ll (i)=1;     (i)<=(x); (i)++)
#define  RREP(i,x)   for(ll (i)=(x)-1; (i)>=0;   (i)--)
#define RREPS(i,x)   for(ll (i)=(x);   (i)> 0;   (i)--)
#define  WREP(i,in,j,jn) REP(i,in)REP(j,jn)
//-----------------------------------------
#define dcml(n) fixed<<setprecision(n)
using namespace std;
int main(void){
    ll N,Y;cin>>N>>Y;
    if(Y/N==10000){cout<<N<<" "<<"0 0\n";exit(0);}
    if(Y/N==5000){cout<<"0 "<<N<<" 0\n";exit(0);}
    if(Y/N==1000){cout<<"0 0 "<<N<<"\n";exit(0);}
    REP(i,N+1){//10000
        if(i>N)break;
        ll l1=i*10000;
        if(l1>Y)break;
        REP(j,N+1){//5000
            if(i+j>N)break;
            ll l2=l1+j*5000;
            if(l2>Y)break;
            REP(k,N+1){//1000
                if(i+j+k>N)break;
                if(i+j+k!=N)continue;
                ll l3=l2+k*1000;
                if(l3>Y)break;
                if(l3==Y){
                    cout<<i<<" "<<j<<" "<<k<<"\n";
                    exit(0);
                }
            }
        }
    }
    cout<<-1<<" "<<-1<<" "<<-1<<"\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
typedef long long ll ;
const int oo=1e9;

int main() {_
 int n;cin >> n;
 int t[101];
 for(int i=0;i<n;i++){
    cin >> t[i];
 }
 int occ=1,ans=0;
 for(int i=0;i<n-1;i++){
    if(t[i]==t[i+1])
        occ++;
    else{
        ans+=occ/2;
        occ=1;
    }
 }
 ans+=occ/2;
 cout << ans;
}


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

int main(){
	ll A, B;
	int K;
	cin >> A >> B >> K;
	set<ll> st;
	for (ll i = A; i <min(A+K,B+1); i++) {
		st.insert(i);
	}
	for (ll i = B; i>max(B-K,A-1); i--){
		st.insert(i);
	}
	for (ll s : st) {
		cout << s << endl;	
	}
	return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <iomanip>

using namespace std;

int main()
{
    int size;

    cin >> size;
    long long a[size];
    int i;

    for(i=0; i<size; i++){
       cin >> a[i];
    }

    long long max=0;

    for(i=0; i<size; i++){
        if(max < a[i] || i==0){
            max = a[i];
        }
        else{
        }
    }

    long long min=0;

    for(i=0; i<size; i++){
        if(min > a[i] || i==0){
            min = a[i];
        }
        else{
        }
    }

    long long sum=0;

    for(i=0; i<size; i++){
        sum+= a[i];
    }

    cout << min << " " << max << " " << sum << endl;
    return 0;
}



Measured memory_bytes: 3184
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define repr(i,n) for(ll i=(n-1);i>=0;i--)
#define all(x) x.begin(),x.end()
#define br cout << "\n";
using namespace std;
const long long INF = 1e10;
const long long MOD = 1e9+7;
using Graph = vector<vector<ll>>;
using pll = pair<ll, ll>;
template<class T> inline bool chmin(T &a, T b) { if(a > b){ a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b) { if(a < b){ a = b; return true;} return false;}

// 0 false, 1 true 
// string to int : -48
// a to A : -32
// ceil(a)  1.2->2.0
// c++17	g++ -std=c++17 a.cpp

ll d;
vector<ll> c(26);
vector<vector<ll>> vec(d, vector<ll>(26));

ll calc(vector<ll> t){
    ll res = 0;
    vector<ll> last(26);
    rep(i, d){
        rep(j, 26){
            if(t[i] == j){
                res += vec[i][j];
                last[j] = 0;
            }else{
                last[j]++;
            }
        }
        rep(j, 26){
            res -= c[j]*last[j];
        }
    }
    return res;
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    
    cin >> d;
    clock_t start = clock();
    rep(i, 26){
        cin >> c[i];
    }
    vec.resize(d, vector<ll>(26));
    rep(i, d){
        rep(j, 26){
            cin >> vec[i][j];
        }
    }

    ll ans = 0;
    vector<ll> last(26);
    vector<ll> t;
    rep(i, d){

        ll max_value = -1;
        ll contest_type = -1;

        //それぞれの日を選んだ場合
        ll max_val = -INF;
        ll tmp_day = -1;
        rep(j, 26){
            ll tmp = 0;

            rep(k, 26){
                if(j == k){
                    tmp += vec[i][j];
                }
                else{
                    tmp -= c[k] * (last[k] + 1);
                }
            }
            if(max_val < tmp){
                max_val = tmp;
                tmp_day = j;
            }
        }

        //cout << tmp_day + 1 << endl;
        t.push_back(tmp_day);
        ans += max_val;

        //後処理
        rep(j, 26){
            if(j == tmp_day){
                last[j] = 0;
            }else{
                last[j]++;
            }
        }
    }

    

    //cout << ans << endl;

    while(true){

        srand(time(NULL));
        ll before = rand() % 26 + 1;
        ll after = rand() % 26 + 1;
        if(t[before] != after){
            ll old = t[before];
            t[before] = after;

            ll res = 0;
            res = calc(t);

            if(ans < res){
                ans = res;
            }else{
                t[before] = old;
            }
        }

        clock_t end = clock();
        const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC * 1000.0;
        //printf("time %lf[ms]\n", time);
        if(time > 1800){
            break;
        }
    }

    rep(i, t.size()){
        cout << t[i] + 1 << endl;
    }
    
    
    
    
    /*
    clock_t end = clock();
    const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC * 1000.0;
    printf("time %lf[ms]\n", time);
    */


}

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

#define INF 1LL<<60

int main() {
    int h, n;
    cin >> h >> n;
    int a[1010], b[1010];
    vector<long long> dp(h + 1, INF);

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

    dp[0] = 0;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < n; j++) {
            int next = min(h, i + a[j]);
            dp[next] = min(dp[next], dp[i] + b[j]);
        }
    }
    cout << dp[h] << endl;
    return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<climits>
#include<bitset>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define int long long
#define mod 1000000007
using namespace std;
inline int read(){
    int f=1,ans=0;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9'){ans=ans*10+c-'0';c=getchar();}
    return f*ans;
}
const int MAXN=17;
int f[MAXN][1<<MAXN],fac[1<<MAXN],N,M,A[MAXN],Lim,ifac[1<<MAXN],inv[1<<MAXN],Ans;
bool cmp(int a,int b){return a>b;}
int C(int a,int b){return a<b?0:fac[a]*ifac[a-b]%mod*ifac[b]%mod;}
int lowbit(int x){return x&-x;}
int cont(int x){int c=0;while(x){x-=lowbit(x);c++;}return c;}
signed main(){
    //freopen("1.in","r",stdin);
    N=read(),M=read();for(int i=1;i<=M;i++) A[i]=read();sort(A+1,A+M+1,cmp);Lim=(1<<N);
    fac[0]=fac[1]=inv[1]=ifac[0]=ifac[1]=1;for(int i=2;i<=Lim;i++) fac[i]=fac[i-1]*i%mod,inv[i]=(mod-mod/i)*inv[mod%i]%mod,ifac[i]=ifac[i-1]*inv[i]%mod;f[0][0]=1;
    for(int i=1;i<=M;i++){
        for(int j=0;j<Lim;j++){
            f[i][j]+=f[i-1][j];
            for(int k=0;k<N;k++){
                if((j&(1<<k))) continue;
                f[i][j|(1<<k)]+=f[i-1][j]*C((1<<N)-A[i]-j,(1<<k)-1)%mod*fac[(1<<k)]%mod,f[i][j]%=mod;
            }
        }
    }
    for(int i=0;i<Lim;i++){
        int pw=(cont(i)&1)?-1:1;
        Ans=(Ans+pw*f[M][i]*fac[Lim-1-i]+mod)%mod;
    }printf("%lld\n",Ans*(1<<N)%mod);return 0;
}


Measured memory_bytes: 13032
#include <algorithm>
#include <climits>
#include <cmath>
#include <deque>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <set>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define all(collection) (collection).begin(), (collection).end()
#define loop(i, times) for(int i = 0; i < times; i++)
#define seloop(i, start_index, end_index) for(int i = start_index; i < end_index; i++)
#define eqseloop(i, start_index, end_index) for(int i = start_index; i <= end_index; i++)

int main()
{
	int a; cin >> a;
	int b; cin >> b;
	int c; cin >> c;

	if (a*c <= b)
		cout << c;
	else
		cout << (int)(b / a);
	return 0;
}

Measured memory_bytes: 256
use proconio::input;

fn main() {
    input! {
        n: usize,
        a: [i32; n],
    }

    let count = a.iter().map(|&ai| get_div2(ai)).min().unwrap();
    println!("{}", count);
}

fn get_div2(n: i32) -> i32 {
    let mut n = n;
    let mut count = 0;
    while n % 2 == 0 {
        n /= 2;
        count += 1;
    };
    count
}

Measured memory_bytes: 2096
#include<iostream>
#include<sstream>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<complex>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cassert>

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-9;

ll calc(ll n){
	ll res = 0;
	res += (n / 3 + n / 5) * 4;
	for(ll lo = 1, hi = 10, len = 1; ; lo *= 10, hi *= 10, len++){
		ll r = min(hi - 1, n);
		if(lo * 10.0 > n * 1.1) r = n;
		
		if(r < lo) break;
		ll tmp = r - r / 3 - r / 5 + r / 15;
		tmp -= lo - 1 - (lo - 1) / 3 - (lo - 1) / 5 + (lo - 1) / 15;
		res += tmp * len;
	}
	return res;
}

int main(){
	ll s, lo = 0, hi = (ll)1e18, mid;
	cin >> s;
	
	while(lo + 1 < hi){
		mid = (lo + hi) / 2;
		if(calc(mid) >= s) hi = mid;
		else lo = mid;
	}
	s -= calc(lo) + 1;
	stringstream ss;
	rep(i, 20){
		if(hi % 3 == 0 || hi % 5 == 0){
			if(hi % 3 == 0) ss << "Fizz";
			if(hi % 5 == 0) ss << "Buzz";
		}
		else ss << hi;
		hi++;
	}
	cout << ss.str().substr(s, 20) <<endl;
	return 0;
}

Measured memory_bytes: 1216
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <algorithm>
#include <set>

using namespace std;

using ll = long long;

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int N, A, B;
	cin >> N >> A >> B;
	cout << min(N * A, B);
	//system("pause");
	return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <string>
#include <iostream>
#include <queue>
#include <algorithm>
#include <functional>
#include <map>
#include <array>
#include <cmath>

using namespace std;

long long PRIME = 1000000007;


int main(int argc, char* argv[]){
    string S;
    cin >> S;

    int count_A = 0;
    long long ret = 0;

    int cursor = 0;

    while(cursor < S.size() - 1){
        if(S[cursor] == 'A'){
            ++count_A;
            ++cursor;
        }
        else if(S[cursor] == 'B' && S[cursor+1] == 'C'){
            ret += count_A;
            cursor += 2;
        }
        else{
            count_A = 0;
            ++cursor;
        }
    }

    cout << ret;

}


Measured memory_bytes: 640
package main

import (
	"bufio"
	"errors"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
)

func main() {
	sc := NewScanner(os.Stdin)
	h, _ := sc.NextInt()
	w, _ := sc.NextInt()
	k, _ := sc.NextInt()
	x1, _ := sc.NextInt()
	y1, _ := sc.NextInt()
	x2, _ := sc.NextInt()
	y2, _ := sc.NextInt()
	stage := make([]string, h)
	for i := 0; i < h; i++ {
		sc.Scan()
		stage[i] = sc.Text()
	}
	ans := solve(h, w, k, x1-1, y1-1, x2-1, y2-1, stage)
	fmt.Println(ans)
}

type state struct {
	x, y, dist int
}

var inf = math.MaxInt64
var dxs, dys = []int{0, 0, -1, 1}, []int{-1, 1, 0, 0}

func solve(h, w, k, x1, y1, x2, y2 int, stage []string) int {
	dists := make([][]int, h)
	for x := range dists {
		dists[x] = make([]int, w)
		for y := range dists[x] {
			dists[x][y] = inf
		}
	}

	dists[x1][y1] = 0
	// q := priorityQueue{}
	q := []*state{}
	s := &state{x1, y1, 0}
	// heap.Push(&q, s)
	q = append(q, s)
	//for len(q) > 0 {
	for idx := 0; idx < len(q); idx++ {
		//fmt.Println(q.String())
		// p := heap.Pop(&q).(*state)
		p := q[idx]
		//if p.x == x2 && p.y == y2 {
		//	return p.dist
		//}
		for d := range dxs {
			for i := 1; i <= k; i++ {
				x, y := p.x+i*dxs[d], p.y+i*dys[d]
				if x < 0 || h <= x || y < 0 || w <= y {
					break
				}
				if stage[x][y] == '@' {
					break
				}
				dist := p.dist + 1
				if dist > dists[x][y] {
					break
				}
				if dist == dists[x][y] {
					continue
				}
				dists[x][y] = dist
				s := &state{x, y, dist}
				q = append(q, s)
			}

		}
	}
	if dists[x2][y2] == inf {
		return -1
	}
	return dists[x2][y2]
}

// Scanner is a wrapper of bufio.Scanner which is customized for competitive programing.
type Scanner struct {
	bufio.Scanner
}

// NewScanner is a constructor for Scanner.
func NewScanner(r io.Reader) *Scanner {
	sc := Scanner{*bufio.NewScanner(r)}
	sc.Buffer([]byte{}, math.MaxInt64)
	sc.Split(bufio.ScanWords)
	return &sc
}

// NextInt reads a integer from io stream.
func (sc *Scanner) NextInt() (int, error) {
	if !sc.Scan() {
		return -1, errors.New("failed to scan")
	}
	return strconv.Atoi(sc.Text())
}


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

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

#define sf scanf
#define pf printf
#define pb push_back
#define mp make_pair
#define PI ( acos(-1.0) )
#define mod 1000000007LL
#define IN freopen("test.txt","r",stdin)
#define OUT freopen("pieaters.out","w",stdout)
#define FOR(i,a,b) for(i=a ; i<=b ; i++)
#define DBG pf("Hi\n")
#define i64 long long int
#define eps (1e-8)
#define xx first
#define yy second
#define ln 17
#define off 2

using namespace __gnu_pbds;
using namespace std ;

typedef tree< i64, null_type, less<i64>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef pair<i64, i64> pii;

#define INF 2000000000
#define alpha 26
const int N = 200 ;
#define LOG 18

#define maxn 100005

vector <int> g[maxn] ;

int dfs(int u ,int par)
{
    int ans = 1 ;
    for(int i=0 ; i<g[u].size() ; i++)
    {
        int v = g[u][i] ;
        if(v==par) continue ;
        ans += dfs(v,u) ;
    }
    if( ans > 2 ) return ans ;
    return (ans&1) ;
}

int main()
{
    int n ;

    scanf("%d",&n) ;

    for(int i=1 ; i<n ; i++)
    {
        int u , v ;
        scanf("%d %d",&u,&v) ;
        g[u].pb(v) ; g[v].pb(u) ;
    }

    int res = dfs(1,0) ;

    if(res==0) printf("Second\n") ;
    else printf("First\n") ;

    return 0 ;
}


Measured memory_bytes: 5888
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<bitset>
#include<cstdio>
#include<cmath>
#include<deque>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<string>
#include<tuple>
#include<utility>
#include<vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
typedef vector<vector<int>> vvi;

#define rep(i, a, n)  for(int i=a; i<n; i++)
#define REP(i, n)  for(int i=0; i<(int)(n); i++)
#define REPS(i, n)  for(int i=1; i<=(int)(n); i++)
#define PER(i, n) for(int i=(int)(n)-1; i>= 0; i--)
#define PERS(i, n)  for(int i=(int)(n); i>0; i--)
#define FOR(i, c) for(__typeof((c).begin()) i = (c).begin(); i!=(c).end(); i++)
#define RFOR(i, c)  for(__typeof((c).rbegin()) i=(c).rbegin(); i!=(c).end(); i++)
#define ALL(container)  (container).begin(), (container).end()
#define RALL(container) (container).rbegin(), (container).rend()
#define SZ(container) (container).size()
#define FILL0(n)  setfill('0') << right << setw(n)
#define mp(a, b)  make_pair(a, b)
#define toLower(c)  c+0x20
#define toUpper(c)  c-0x20
#define pb  push_back
#define eb  emplace_back

const int INF = 1e9;
const long long LLINF = 1e18;
const int MOD = 1000000007;

int main(){
  int N;  cin >> N;
  vector<int> H(N);
  REP(i, N) cin >> H[i];
  int ans = 0, cnt = 0;
  REPS(i, N-1){
    if(H[i-1]<H[i]){
      ans = max(ans, cnt);
      cnt = 0;
      continue;
    }
    cnt++;
  }

  ans = max(ans, cnt);
  cout << ans << endl;
}


Measured memory_bytes: 640
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <tuple>
#include <vector>

using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;

#define INF (1e9)

int N, D;

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

    vvi X(N, vi(D));
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < D; j++) {
            cin >> X[i][j];
        }
    }

    int ans = 0;
    for (int i = 0; i < N; i++) {
        for (int j = i + 1; j < N; j++) {
            float dist2 = 0;
            for (int k = 0; k < D; k++) {
                dist2 += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
            }
            float dist = sqrt(dist2);
            int distInt = int(dist);
            if (float(distInt * distInt) == dist2) ans++;
        }
    }

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


Measured memory_bytes: 256
ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
tma = lambda :tuple(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
import collections
import math
import itertools
import heapq as hq
ceil = math.ceil

n = ni()
A = lma()
co = collections.Counter(A)
ans = 0
for num,cnt in co.items():
    if num<cnt:
        ans+=(cnt-num)
    if num>cnt:
        ans+=cnt
print(ans)


Measured memory_bytes: 22308
import sys
  
def get_shifted_char(shift_count, ch):
    if ord(ch) >= ord('a') and ord(ch) <= ord('z'):
        return chr(((ord(ch)-71-shift_count) %26 + 97))
    else:
        return ch


for enc_text in sys.stdin:
    text_list = list(filter(lambda s:len(s)==3 or len(s)==4,enc_text.strip().split()))

    shift_count = 1

    while(shift_count < 27):
        flg = False
        for text in text_list:
            decoded = ''.join(list(map(lambda c:get_shifted_char(shift_count,c),text)))
            if decoded == "the" or decoded == "this" or decoded == "that":
                flg = True
        if flg:
            break
        shift_count += 1

    print(''.join(list(map(lambda c:get_shifted_char(shift_count,c),enc_text.strip()))))




Measured memory_bytes: 5560
#include<iostream>
using namespace std;
int main(){
  int a,b,c,temp;
  cin>>a>>b>>c;
  if(b<a){temp=a; a=b; b=temp;}
  if(c<b){temp=b; b=c; c=temp;}
  if(b<a){temp=a; a=b; b=temp;}
  cout<<a<<" "<<b<<" "<<c<<endl;
  return 0;
}

Measured memory_bytes: 3080
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b,r;
  cin >> a >> b >> r;
  string c;
  cin >> c;
  vector<int> g(1,-1000000);
  for(int i = 0;i < a;i++){
    int m = g.size();
    if(c.at(i) == 'o' && g.at(m-1)+r<i){
      g.push_back (i);}
  }
  int mw = g.size();
    vector<int> n;
  
  if(mw == b+1){
    vector<int> h(1,1000000);
     for(int i = a-1;i > -1;i--){
    int m = h.size();
    if(c.at(i) == 'o' && h.at(m-1)-r > i){
      h.push_back (i);
    if(i == g.at(b-m+1)){
    n.push_back(i);}
    }
     }
     
    reverse(n.begin(), n.end());
    for(int i = 0;i < n.size();i++){
      cout << n.at(i)+1 << endl;}
     }
  
}

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

using namespace std ;

int main()
{
	string s1,s2 ;
	cin>>s1>>s2;
	int ans = 0 ;
	for(int i=0 ; i<s1.length() ; i++)
	{
		string c = s1.substr(i,s2.length());
		int count = 0 ;
		if(c.length()==s2.length())
		{
			for(int j=0 ; j<c.length() ; j++)
			{
				if(s2[j]==c[j])
					count++ ;
			}
			ans = max(ans,count);
		}
		
	}
	cout<<s2.length()-ans;

}


Measured memory_bytes: 3632
import math,sys,bisect,heapq
from collections import defaultdict,Counter,deque
from itertools import groupby,accumulate
#sys.setrecursionlimit(200000000)
int1 = lambda x: int(x) - 1
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
ilele = lambda: map(int,input().split())
alele = lambda: list(map(int, input().split()))
ilelec = lambda: map(int1,input().split())
alelec = lambda: list(map(int1, input().split()))
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
#MOD = 1000000000 + 7
def Y(c):  print(["NO","YES"][c])
def y(c):  print(["no","yes"][c])
def Yy(c):  print(["No","Yes"][c])

D,T,s = ilele()
dis =s*T
Yy(dis>= D)

Measured memory_bytes: 65452
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		int T = Integer.parseInt(sc.next());
		int A = Integer.parseInt(sc.next());

		double diff = Double.MAX_VALUE;
		int num = -1;

		for (int i=0; i<N; i++){
			int h = Integer.parseInt(sc.next());
			double h_diff = Math.abs((T - h * 0.006) - A);

			if (h_diff < diff){
				diff = h_diff;
				num = i;
			}
		}
		System.out.println(num+1);
	}
}

Measured memory_bytes: 23892
#include <iostream>
#include <stdio.h>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <set>
#include <math.h>
#include <utility>
using namespace std;
typedef pair<int,int> P;
const int INF = (int)((unsigned int)-1>>1);
const int MAX_N = 100;

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

int H, W, N;
P s;
P c[9];
bool map_mat[1000][1000];

struct state{
    int d,to,y,x;
};

int main(){
    scanf("%d %d %d", &H, &W, &N);
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            char ch;
            cin >> ch;
            if (ch == 'S'){
                s = P(i,j);
            }else if ('1' <= ch && ch <= '9'){
                c[(int)(ch-'1')] = P(i,j);
            }
            if (ch == 'X'){
                map_mat[i][j] = false;
            }else{
                map_mat[i][j] = true;
            }
        }
    }

    queue<state> que;
    que.push((state){0, 0, s.first, s.second});
    bool itta[1000][1000];
    for(int i=0;i<H;i++)for(int j=0;j<W;j++) itta[i][j] = false;

    while(que.size()){
        state q = que.front(); que.pop();
        //printf("%d %d %d %d\n",q.d,q.to,q.y,q.x);
        if (c[q.to].second == q.x && c[q.to].first == q.y){
            q.to += 1;
            while(que.size()) que.pop();
            if (q.to == N){
                printf("%d\n", q.d);
                break;
            }else{
                for(int i=0;i<H;i++)for(int j=0;j<W;j++) itta[i][j] = false;
                itta[q.y][q.x] = true;
            }
        }
        for(int i=0;i<4;i++){
            int nextx = q.x+dx[i], nexty = q.y+dy[i];
            if(0<=nextx && nextx<W && 0<=nexty && nexty<H && map_mat[nexty][nextx] && !itta[nexty][nextx]){
                itta[nexty][nextx] = true;
                que.push((state){q.d+1, q.to, nexty, nextx});
            }
        }
    }

    return 0;
}

Measured memory_bytes: 3180
//
// Created by Hideaki Imamura on 2020-03-16.
//
# include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair <ll, ll> l_l;
typedef pair<int, int> i_i;

template<class T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

# define EPS (1e-7)
# define INF (1e9)
# define PI (acos(-1))
//const ll mod = 1000000007;

int n;
int n_1 = 0, n_2 = 0, n_3 = 0;

int main() {
    cin >> n;
    for (int i = 0; i < n; ++i) {
        int a;
        cin >> a;
        if (a == 1) n_1++;
        else if (a == 2) n_2++;
        else n_3++;
    }

    static double dp[310][310][310];
    dp[0][0][0] = 0;
    for (int k = 0; k <= n; ++k) {
        for (int j = 0; j <= n; ++j) {
            for (int i = 0; i <= n; ++i) {
                if (i + j + k == 0) continue;
                if (i + j + k > n) continue;
                if (i - 1 >= 0) dp[i][j][k] += 1.0 * i * dp[i - 1][j][k] / (i + j + k);
                if (j - 1 >= 0) dp[i][j][k] += 1.0 * j * dp[i + 1][j - 1][k] / (i + j + k);
                if (k - 1 >= 0) dp[i][j][k] += 1.0 * k * dp[i][j + 1][k - 1] / (i + j + k);
                dp[i][j][k] += 1.0 * n / (i + j + k);
            }
        }
    }

    printf("%.10f\n", dp[n_1][n_2][n_3]);
    return 0;
}

Measured memory_bytes: 225536
#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    a, b, t = LI()
    print(b * (t // a))
    return

#B
def B():
    n = II()
    v = LI()
    c = LI()
    ans = 0
    for i in range(n):
        if v[i] > c[i]:
            ans += v[i] - c[i]
    print(ans)
    return

#C
def C():
    def gcd(a, b):
        if b > a: a, b = b, a
        while b:
            a, b = b, a % b
        return a
    n = II()
    a = LI()
    dp1 = [None] * (n - 1)
    dp1[0] = a[0]
    dp2 = [None] * (n - 1)
    dp2[-1] = a[-1]
    for i in range(1, n - 1):
        dp1[i] = gcd(dp1[i - 1], a[i])
        dp2[-i - 1] = gcd(dp2[-i], a[-i - 1])
    ans = 0
    dp1.insert(0, dp2[0])
    dp2.append(dp1[-1])
    for i in range(n):
        ans = max(ans, gcd(dp1[i], dp2[i]))
    print(ans)
    return

#D
def D():
    n = II()
    a = LI()
    positive = []
    negative = []
    for ai in a:
        if ai >= 0:
            positive.append(ai)
        else:
            negative.append(ai)
    positive.sort()
    negative.sort()
    ans = sum(positive) + sum(map(lambda x: abs(x), negative))
    if len(negative) & 1:
        ans -= 2 * min(positive[0] if positive else inf, abs(negative[-1]))
    print(ans)
    return

#Solve
if __name__ == '__main__':
    D()


Measured memory_bytes: 65440
#include <bits/stdc++.h>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,Q,K,A,B;
string S;
const ll MOD = 998244353;
//const ll MOD = (1e+9) + 7;
typedef pair<ll, ll> P;
const ll INF = (1LL<<58);

template<class T> bool chmin(T &a, const T &b){
    if(a > b) {a = b; return true;}
    else return false;
}
template<class T> bool chmax(T &a, const T &b){
    if(a < b) {a = b; return true;}
    else return false;
}

ll calc(mat &s, vec &c, vec &ans){
    ll res = 0;
    vec last(26, 0);
    rep(day, N){
        last[ans[day]] = day + 1;
        rep(i, 26){
            if(i == ans[day]){
                res += s[day][i];
            }else{
                res -= c[i] * (day + 1 - last[i]);
            }
        }
    }
    return res;
}

int main() {
    cin>>N;
    vec c(26), last(26, 0), ans(N);
    mat s(N, vec(26)), ans_another(26, vec(1, 0));
    rep(i,26) cin>>c[i];
    rep(i,N) rep(j, 26) cin>>s[i][j];
    ll score = 0;
    rep(day, N){
        vec temp(26, 0);
        rep(i, 26) temp[i] += s[day][i];
        rep(i, 26) temp[i] += c[i] * (day + 1 - last[i]);
        auto ite = max_element(ALL(temp));
        ans[day] = ite - temp.begin();
        ans_another[ans[day]].push_back(day + 1);
        last[ite - temp.begin()] = day + 1;
        rep(i, 26){
            if(i == ans[day]){
                score += s[day][i];
            }else{
                score -= c[i] * (day + 1 - last[i]);
            }
        }
    }
    rep(i,26) ans_another[i].push_back(N + 1);

    ll total_num = 150000;
    while(total_num) {
        mat minus(N + 1, vec(26, 0));
        priority_queue<P> pque;
        rep(i, 26) {
            vec &table = ans_another[i];
            int id = 0;
            reps(day, 1, N) {
                if (table[id + 1] == day) {
                    ++id;
                } else {
                    ll weight = s[day - 1][i], len = table[id + 1] - table[id] - 1;
                    ll wh = day - table[id];
                    weight += c[i] * ((len * (len + 1) / 2) - (wh * (wh - 1) / 2 + (len - wh) * (len - wh + 1) / 2));
                    pque.emplace(weight, day * 26 + i);
                }
            }
        }
        if((total_num -= 20) < 0) break;
        ll non_update = 0;
        rep(check, 10000) {
            P p = pque.top();
            pque.pop();
            ll day = p.se / 26, i = p.se % 26;
            --day;
            ll old = ans[day];
            ans[day] = i;
            if (!chmax(score, calc(s, c, ans))) {
                ans[day] = old;
                check += non_update * 3;
            }else{
                ++non_update;
            }
            if((--total_num) < 0) break;
        }
    }

    rep(i,N) cout<<ans[i] + 1<<'\n';
}


Measured memory_bytes: 3984
//package AtCoder.Indeed10;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        int n = in.NI();
        List<Long> q = new ArrayList<>(n);
        for (int i=0;i<n;i++) q.add(in.NL());

        long fans = Long.MAX_VALUE;

        long sign = 1; long presum = 0;
        long ans = func(n, q, sign, presum);

        fans = Long.min(fans, ans);

        sign = -1; presum = 0;
        ans = func(n, q, sign, presum);

        fans = Long.min(fans, ans);

        out.println(fans);
        out.close();
    }

    private static long func(final int n, final List<Long> q, long sign, long presum) {
        long ans  =0;
        for (int i=0;i<n;i++) {
            presum+=q.get(i);
            if (presum*sign > 0) { sign = sign*-1L;  continue; }
            if (presum==0) {
                if (sign==1) {ans++; presum++;}
                else {ans++; presum--;}
            } else if (presum>0) {
                ans += (1+presum);
                presum = -1;
            } else {
                ans += (1-presum);
                presum = 1;
            }
            sign = sign * -1L;
        }
        return ans;
    }

    static InputStream inputStream = System.in;
    static OutputStream outputStream = System.out;
    static InputReader in = new InputReader(inputStream);
    static PrintWriter out = new PrintWriter(outputStream);

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int NI() {
            return Integer.parseInt(next());
        }

        public long NL() {
            return Long.parseLong(next());
        }

    }
}

Measured memory_bytes: 45228
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define ll long long
#define ld long double
#define mk make_pair
#define f first
#define se second
#define vll vector<ll>
#define pii pair<ll,ll>
#define vvll vector< vector<ll> >
#define pb push_back
#define sz(v) (v).size()
#define inf 1e18
#define md 1000000007
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define tel(a){cout<<a<<"\n";}
#define tell(a,b){cout<<a<<" | "<<b<<"\n";}
#define telll(a,b,c){cout<<a<<" | "<<b<<" | "<<c<<"\n";}
#define teln(v,n){cout<<"v- ";rep(i,0,n)cout<<v[i]<<" ";cout<<"\n";}
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); 

using namespace std;
using namespace __gnu_pbds;

template<typename T>
using o_set=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define M 410
vll g[410];
char a[22][22];
ll b[22][22],h,w;
bool ok(ll i,ll j){
	if(i<0 or i>=h or j<0 or j>=w)return 0;
	if(a[i][j]=='#')return 0;
	return 1;
}
int main(){
	IOS;
	cin>>h>>w;
	ll ct=1;
	rep(i,0,h)rep(j,0,w)cin>>a[i][j],b[i][j]=ct,ct++;
	rep(i,0,h)rep(j,0,w){
		if(a[i][j]=='.'){
			ll x=b[i][j];
			if(ok(i+1,j))g[x].pb(b[i+1][j]);
			if(ok(i-1,j))g[x].pb(b[i-1][j]);
			if(ok(i,j+1))g[x].pb(b[i][j+1]);
			if(ok(i,j-1))g[x].pb(b[i][j-1]);
		}
	}
	ll mx=0;
	rep(i,0,h)rep(j,0,w)rep(i1,0,h)rep(j1,0,w){
		ll d[M];rep(i,0,M)d[i]=-1;
		ll sor=b[i][j];
		ll tar=b[i1][j1];
		queue<ll>q;
		q.push(sor),d[sor]=0;
		while(!q.empty()){
			ll u=q.front();q.pop();
			for(auto v:g[u]){
				if(d[v]!=-1)continue;
				d[v]=d[u]+1;
				if(v==tar)break;
				q.push(v);
			}
		}
		mx=max(mx,d[tar]);
	}
	cout<<mx;
	return 0;
}



Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int n, i;  
  int a[45] = {1,1};
  
  scanf("%d", &n);
  
  for(i=2; i<=n; i++)
    a[i] = a[i-1] + a[i-2];
  
  printf("%d\n", a[n]);
  
  return 0;
}

Measured memory_bytes: 2728
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define puf push_front
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
//#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
const int64 INF = 1LL << 58;
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<typename T> void remove(T & vector, unsigned int index){vector.erase(vector.begin() + index);}

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

    vei N(4); rep(i,4) cin>>N[i];
  
  	sort(all(N));

    if(N[0] == 1 and N[1] == 4 and N[2] == 7 and N[3] == 9) cout << "YES"<<endl;
  	else cout << "NO"<<endl;
  	return 0;
}



Measured memory_bytes: 256
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;

alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

void minAssign(T, U = T)(ref T dst, U src)
{
    dst = cast(T) min(dst, src);
}

void maxAssign(T, U = T)(ref T dst, U src)
{
    dst = cast(T) max(dst, src);
}

void main()
{
    long N = lread();
    long K = lread();

    long m = long.max;

    foreach (i; 0 .. N + 1)
    {
        long a = (2 ^^ i) + (K * (N - i));
        // long b = (1 + K * (N - i)) + (2 ^^ i);
        // writeln(a);
        m.minAssign(a);
    }
    writeln(m);
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <vector>
#include <stdio.h>
#include <math.h>
#include <algorithm>
#include <queue>
#include <cmath>
#include <cstdio>
using namespace std;
int main(){
int a,b,c;
cin>>a>>b>>c;
int d=a*b;
if(d>c)
cout<<c;
else
cout<<d;
system("pause");
return 0;
}

Measured memory_bytes: 504
h, w = map(int, input().split())
field = [[c for c in input().strip()] for _ in range(h)]
sx, sy = 0, 0
gx, gy = w - 1, h - 1
dirx = [1, 0]
diry = [0, 1]
inf = 1001001001
dp = [[(inf, False) for _ in range(w)] for _ in range(h)]
flip = False
step = 0
for i in range(w):
    if field[0][i] == '.':
        if flip:
            step += 1
            flip = False
    elif field[0][i] == '#':
        if flip == False:
            flip = True
    dp[0][i] = (step, flip)

flip = False
step = 0
for i in range(h):
    if field[i][0] == '.':
        if flip:
            step += 1
            flip = False
    elif field[i][0] == '#':
        if flip == False:
            flip = True
    dp[i][0] = (step, flip)

for i in range(1, h):
    for j in range(1, w):
        tmp1, f1 = dp[i - 1][j]
        tmp2, f2 = dp[i][j - 1]
        if field[i][j] == '.':
            if f1:
                tmp1 += 1
                #f1 = False
            if f2:
                tmp2 += 1
                #f2 = False
            dp[i][j] = (min(tmp1, tmp2), False)
        else:
            if i == gy and j == gx:
                dp[i][j] = (min(tmp1 + 1, tmp2 + 1), True)
            else:
                dp[i][j] = (min(tmp1, tmp2), True)

print(dp[h - 1][w - 1][0])


Measured memory_bytes: 3828
import fractions
from functools import reduce


def factorize(n):
    fct = []  # prime factor
    b, e = 2, 0  # base, exponent
    while b * b <= n:
        while n % b == 0:
            n = n // b
            e = e + 1
        if e > 0:
            fct.append((b, e))
        b, e = b + 1, 0
    if n > 1:
        fct.append((n, 1))
    return fct


def reduce_gcd(numbers):
    return reduce(fractions.gcd, numbers)


def main():
    N = int(input())
    A_N = list(map(int, input().rstrip().split()))
    gcd = reduce_gcd(A_N)
    factorized = factorize(gcd)
    if factorized:
        print(factorized[0][1])
    else:
        print('0')


if __name__ == '__main__':
    main()


Measured memory_bytes: 5624
from sys import stdin, stdout
a=int(input())
l=[]
for i in range(34):
    l.append(i*i)
    l.append(i**3)
    l.append(i**4)
    l.append(i**5)
    l.append(i**6)
    l.append(i**7)
    l.append(i**8)
    l.append(i**9)
    l.append(i**10)
l.sort()
for i in range(100):
    if l[i]>a:
        print(l[i-1])
        break


Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
int main(void){
  int n;
  cin>>n;
  int a[n];
  int ans=0;
  for(int i=0;i<n;i++){
    cin>>a[i];
    if(i%2==0 && a[i]%2==1){
      ++ans;
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3596
#include<stdio.h>
int p[8192],wz[8192];
long long dp[5005][5005];
int main()
{
	int n,a,b;
	scanf("%d%d%d",&n,&a,&b);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&p[i]);
		wz[p[i]]=i;
	}
	for(int i=0;i<=n;i++)
	{
		for(int j=0;j<=n;j++)
		{
			if(i==0&&j==0)
			{
				dp[i][j]=0;
				continue;
			}
			dp[i][j]=1000000000000000000LL;
			if(i)
			{
				if(dp[i-1][j]<dp[i][j])
				{
					dp[i][j]=dp[i-1][j];
				}
			}
			if(j)
			{
				int inc=a;
				if(wz[j]>i)
				{
					inc=b;
				}
				if(dp[i][j-1]+inc<dp[i][j])
				{
					dp[i][j]=dp[i][j-1]+inc;
				}
			}
			if(i&&j)
			{
				if(wz[j]==i)
				{
					if(dp[i-1][j-1]<dp[i][j])
					{
						dp[i][j]=dp[i-1][j-1];
					}
				}
			}
		}
	}
	printf("%lld\n",dp[n][n]);
	return 0;
}

Measured memory_bytes: 195712