akhauriyash/Code-Regression huggingface dataset:
// 見せてやるぜ、奇跡ってやつをよぉ……
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
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 DEBUG_VLL(vec) REP(sz, vec.size()) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll h, w; cin >> h >> w;
    V<string> s(h);
    REP(i, h) cin >> s[i];
    
    vvll d(h, vll(w, HIGHINF));
    ll ans = 0;
    REP(i, h) REP(j, w) {
        if (s[i][j] == '.') {
            REP(tmpi, h) REP(tmpj, w) d[tmpi][tmpj] = HIGHINF;
            d[i][j] = 0;
            queue<P<ll, ll> > que; que.push(make_pair(i, j));
            while (!que.empty()) {
                P<ll, ll> q = que.front(); que.pop();
                if (q.first - 1 >= 0 && s[q.first - 1][q.second] == '.') {
                    if (d[q.first - 1][q.second] > d[q.first][q.second] + 1) {
                        d[q.first - 1][q.second] = d[q.first][q.second] + 1;
                        que.push(make_pair(q.first - 1, q.second));
                    }
                }
                if (q.first + 1 < h && s[q.first + 1][q.second] == '.') {
                    if (d[q.first + 1][q.second] > d[q.first][q.second] + 1) {
                        d[q.first + 1][q.second] = d[q.first][q.second] + 1;
                        que.push(make_pair(q.first + 1, q.second));
                    }
                }
                if (q.second - 1 >= 0 && s[q.first][q.second - 1] == '.') {
                    if (d[q.first][q.second - 1] > d[q.first][q.second] + 1) {
                        d[q.first][q.second - 1] = d[q.first][q.second] + 1;
                        que.push(make_pair(q.first, q.second - 1));
                    }
                }
                if (q.second + 1 < w && s[q.first][q.second + 1] == '.') {
                    if (d[q.first][q.second + 1] > d[q.first][q.second] + 1) {
                        d[q.first][q.second + 1] = d[q.first][q.second] + 1;
                        que.push(make_pair(q.first, q.second + 1));
                    }
                }
            }
            REP(tmpi, h) REP(tmpj, w) {
                if (s[tmpi][tmpj] == '.') chmax(ans, d[tmpi][tmpj]);
            }
        }
    }
    cout << ans << '\n';
    return 0;
}


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

using namespace std;
int main() {
	int min_=124,max_=0;
	int tmp;
	for(int i=0; i<5; ++i) {
		cin>>tmp;
		min_=min(tmp, min_);
		max_=max(tmp, max_);
	}
	int k; cin>>k;
	if(max_-min_>k)cout<<":(";
	else cout<<"Yay!";
	cout<<endl;

	return 0;
}

Measured memory_bytes: 256
#include <utility>
#include <stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<cmath>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define YES(b) std::cout<< (b ? "Yes" : "No")
using namespace std;
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin >> s;
	s[5] = ' ';
	s[13] = ' ';
	cout << s;
}


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

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

int dp[10010];

int main(){
    int N,W;
    cin >> N>>W;
    int v[N+1],w[N+1];
    v[0]=0;w[0]=0;
    for(int i=1;i<N+1;i++){
        cin >> v[i]>>w[i];
    }
    for(int i=0;i<W+2;i++){
        dp[i]=0;
    }
    for(int j=0;j<W+1;j++){//重さ
        for(int n=0;n<N+1;n++){//種類全探索
            if(j-w[n]>=0){
                chmax(dp[j],dp[j-w[n]]+v[n]);
            }
        }
    }
    std::cout << dp[W] << endl;
    return 0;
}


Measured memory_bytes: 3132
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <set> 
#include <map>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstring>
#include <iomanip>
#define rep(i,n) for(int i=0; i<(n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1001001001; // > 10^9
const int MOD = (int)1e9 + 7;
const ll INFLL = 1001001001001001001;  // > 10^18
const ll MODLL = (ll)1e9 + 7;
const double EPS = 1e-9;

int main () {
    
    ll n,ma,mb; cin >>n>>ma>>mb;
    vector<ll> a(n); vector<ll> b(n); vector<ll> c(n);
    rep(i,n) cin >> a[i] >> b[i] >> c[i];

    ll n1 = n/2;
    vector<P> pairs1((1<<n1));

    ll ans1 = INFLL;
    for (ll s = 0; s < (1<<n1); s++) {
        ll suma = 0;
        ll sumb = 0;
        ll sumc = 0;
        for (ll i = 0; i < n1; i++) {
            if (s & (1<<i)) {
                suma += a[i];
                sumb += b[i];
                sumc += c[i];
            }
        }
        pairs1[s] = P(suma*mb - sumb*ma, sumc);
        if (suma * mb == sumb * ma && sumc > 0 && ans1 > sumc) {
            ans1 = sumc;
        } 
    }

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

    ll ans = INFLL;
    for (ll s = 0; s < (1<<(n-n1)); s++) {
        ll suma = 0;
        ll sumb = 0;
        ll sumc = 0;
        for (ll i = 0; i < (n-n1); i++) {
            if (s & (1<<i)) {
                suma += a[n1 + i];
                sumb += b[n1 + i];
                sumc += c[n1 + i];
            }
        }
        ll m = sumb*ma - suma*mb;
        ll ok = (1<<n1);
        ll ng = -1;
        while (abs(ng-ok)>1) {
            ll mid = (ok+ng)/2;
            if (m <= pairs1[mid].first) {
                ok = mid;
            } else {
                ng = mid;
            } 
        }
        if (!(sumc == 0 && pairs1[ok].second == 0) && m == pairs1[ok].first) {
            if (ans > sumc + pairs1[ok].second) {
                ans = sumc + pairs1[ok].second;
            } 
        } 
    }

    if (ans == INFLL && ans1 == INFLL) {
        cout << -1 << endl;
    } else {
        cout << min(ans, ans1) << endl;
    } 

    return 0;
}



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

#define ll long long
#define pb push_back
#define eb emplace_back
//#define st first
#define sc second

using namespace std;

const ll mod = 1e9 + 7;
const int e = 1e5 + 69;
const int base = 311;

// dung inverse module de tinh nCk
// beginer 74
// mbeginer
// cach tao hoan vi tu n so : n*(n+1)/2;

//vector<pair<ll,ll>>adj[e];

ll Pow(ll n, ll dem)
{
    if(dem == 0) return 1;
    if(dem == 1) return n ;
    ll t = Pow(n, dem/2);
    if(dem % 2 == 0) return (t*t);
    else return ((t * t) * n);
}

/*ll C(ll k, ll n)
{
    if(k == 0) return 1;
    if(n < k) return 0;
    return (gt[n]%mod * (igt[k]%mod * igt[n-k]%mod)%mod)%mod;
}*/

int  m, k;

ll a[e];

int main()
{
    ll N;
    cin >> N;
    for(ll h=1; h<=3500; h++)
    {
        for(ll n=1; n<=3500; n++)
        {
            ll cur = 4*h*n - N*(n+h);
            ll curr = n*h*N;
            ll d = __gcd(cur, curr);
            cur /= d;
            curr /= d;
            if(cur == 1 && curr > 0)
            {
                cout << h << " "<<n<<" "<<curr;
                return 0;
            }
        }
    }
}
/*

*/


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <map>
const int MOD = 1e9+7;
typedef long long ll;
using namespace std;

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


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

int main() {
    string s;
    cin >> s;
    bool flag = true;
    rep(i,3) {
        if(s[i] == s[i+1]) {
            flag = false;
            break;
        }
    }
    if(flag) cout << "Good" << endl;
    else cout << "Bad" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
class UnionFind {
  vector<ll> par, rank; // par > 0: number, par < 0: -par
public:
  void init(ll n) {
    par.resize(n); rank.resize(n);
    fill(par.begin(), par.end(), 1); fill(rank.begin(), rank.end(), 0);
  }
  ll getSize(ll x) {
    return par[find(x)];
  }
  ll find(ll x) {
    if (par[x] > 0) return x;
    return -(par[x] = -find(-par[x]));
  }
  void merge(ll x, ll y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    if (rank[x] < rank[y]) {
      par[y] += par[x];
      par[x] = -y;
    } else {
      par[x] += par[y];
      par[y] = -x;
      if (rank[x] == rank[y]) rank[x]++;
    }
  }
  bool isSame(ll x, ll y) {
    return find(x) == find(y);
  }
};
int main(void){
    ll n,m;
    cin>>n>>m;
    UnionFind uf;
    uf.init(n);
    for(int i=0;i<m;i++){
        ll a,b,c;
        cin>>a>>b>>c;
        a--,b--;
        uf.merge(a,b);
    }
    set<ll> s;
    for(int i=0;i<n;i++){
        s.insert(uf.find(i));
    }
    cout<<s.size()<<endl;
}

Measured memory_bytes: 7936
import sys

def main():
    N, K, Q = map(int, input().split())

    A = []
    for _ in range(Q):
        A.append(int(input()))


    pt = []
    for i in range(N):
        pt.append(K-Q)

    for x in A:
        pt[x-1] += 1

    for y in pt:
        if y >= 1:
            print('Yes')
        else:
            print('No')



main()

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

string s, t;
int be = -1;

int main() {
	cin >> s >> t;

	for (int i = 0; i < s.length() - t.length() + 1; i++) {
		bool flag = true;
		for (int j = 0; j < t.length(); j++) {
			if (s[i+j] != '?' && s[i + j] != t[j])flag = false;
		}
		if (flag)be = i;
	}

	if (be != -1) {
		for (int i = 0; i < s.length(); i++) {
			if (be <= i && i < be + t.length())s[i] = t[i - be];
			else if (s[i] == '?')s[i] = 'a';
		}

		cout << s << endl;
	}
	else {
		cout << "UNRESTORABLE" << endl;
	}
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <map>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#define speed ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define eps 1e-7
#define inf 0x3f3f3f3f
#define mod 1000000007
using namespace std;

ll gcd(ll a, ll b) {
	if (a == 0)
		return b;
	return gcd(b % a, a);
}

int main() {
	speed;
	ll a, b, c, d;
	cin >> a >> b >> c >> d;
	
	ll nl = a + ((c - (a % c)) % c), nr = b - (b % c);
	ll cd = (nr - nl) / c;
	
	nl = a + ((d - (a % d)) % d), nr = b - (b % d);
	ll dd = (nr - nl) / d;
	
	ll e = c / gcd(c, d) * d;
	nl = a + ((e - (a % e)) % e), nr = b - (b % e);
	ll ed = (nr - nl) / e;

	cout << (b - a) - (cd + dd - ed);
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdlib>
using namespace std;
int main(){
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  if(abs(a-b)<=d&&abs(b-c)<=d) cout << "Yes\n";
  else{
    if(abs(a-c)<=d) cout << "Yes\n";
    else cout << "No\n";
  }
  return 0;
}


Measured memory_bytes: 256
import std.algorithm;
import std.array;
import std.container;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

void main() {
    // auto q = new BinaryHeap!(Array!int); // TLE(3 sec)
    auto q = new BinaryHeap!(int[])(new int[2_000_001], 0); // AC(1.53 sec)

    string s;
    while ((s = readln.chomp).length > 0) {
        if (s == "end") break;

        if (s[0] == 'e') { // extract
            writeln(q.front);
            q.popFront;
        }
        else {
            auto ss = s.split;
            int x = ss[1].to!int;
            q.insert(x);
        }
    }
}



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

using ll = long long;

int main() {
	string s, t;
	cin >> s >> t;
	int n = s.size();
	int cnt = 0;
	for(int i=0;i<n;i++) {
		if(s[i] != t[i]) cnt++;
	}
	printf("%d\n", cnt);
}

Measured memory_bytes: 3920
#include<stdio.h>
int main(void){
	int n,x,y,b,p,i,r;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d%d%d%d",&x,&y,&b,&p);
		r=x*b+y*p;
		if(b>=5&&p>=2){
			r=r*0.8;
		}
		else if(b>=5&&p<2&&r>(x*b+y*2)*0.8){
			r=(x*b+y*2)*0.8;
		}
		else if(b<5&&p>=2&&r>(x*5+y*p)*0.8){
			r=(x*5+y*p)*0.8;
		}
		else if(b<5&&p<2&&r>(x*5+y*2)*0.8){
			r=(x*5+y*2)*0.8;
		}
		printf("%d\n",r);
	}
	return 0;
}

Measured memory_bytes: 600
from collections import defaultdict
A=input()
N=len(A)
dp=[0]*26
x=ord('a')
ans=0
for i in range(N):
    dp[ord(A[i]) - x]+=1
    ans += (i + 1 - dp[ord(A[i]) - x])
    #print(dp,ans)
print(ans+1)


Measured memory_bytes: 40560
n = int(input())

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

flag = 1
count = 0

while flag == 1:
    for i in range(n):
        if a[i] % 2 != 0:
            flag = 0
        
    if flag == 1:
        for i in range(n):
            a[i] = a[i] / 2
        count += 1
        
print(count)

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

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

  int N, K;
  string S;
  cin >> N >> K >> S;
  int left = 0, right = 0;
  int count = 0;
  int max = 0;
  int zeroCount = 0;
  while (right < N) {
    if (zeroCount == K) {
      while (S[left] == '1') {
        count--;
        left++;
      }
      if (S[left] == '0') {
        while (S[left] == '0') {
          count--;
          left++;
        }
      }
      zeroCount--;
    }
    if (S[right] == '0') {
      while (S[right] == '0') {
        count++;
        right++;
      }
      zeroCount++;
    }
    while (S[right] == '1') {
      count++;
      right++;
    }    if (count > max) {
      max = count;
    }
  }
  cout << max << endl;
}

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

long long N;
vector<long long> A;

int main(){
	cin >> N;
	for(long long i = 0; i < N; i++) {
		long long tmp;
		cin >> tmp;
		A.push_back(tmp);
	}

	long long ans = 0;
	set<long long> numset;
	sort(A.begin(), A.end());

	for(long long i = 0; i < A.size(); i++) {

		long long num = A[i];

		bool ok = true;

		if(i > 0 && num == A[i-1]) {
			ok = false;
		}

		if(i < A.size() - 1 && num == A[i+1]) {
			ok = false;
		}





		for(long long j = 1; j * j <= num; j++) {
			if(num%j == 0){
				if(numset.count(j)>0) {
					ok = false;
					break;
				}
				if(numset.count(num/j)>0) {
					ok = false;
					break;
				}
			}
		}

		if(ok) {
			ans++;
		}

		numset.insert(num);
	}
	cout << ans << endl;
}


Measured memory_bytes: 14240
// i hope i get better                                                           
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int sz=2e5+9;
ll n;
pll p[sz];
int nxt[sz];
ll dp[sz];
ll mod=998244353;
ll add(ll a,ll b){return ((a%mod+b%mod)%mod+mod)%mod;}
ll x[sz];
int segtree[4*sz];

ll solve(int i){
	ll &ret=dp[i];
	if(~ret) return ret;
	if(i>=n) return ret=1;
	ret=solve(i+1);
	ret=add(ret,solve(nxt[i]));
	return ret;
}

void update(int node,int left,int right,int pos,int v){
    if(left==right){
    	segtree[node]=v;
        return;
    }
    int mid=(left+right)>>1;
    // check if the update position is in my left or right child
    if(pos>=left&&pos<=mid) update(2*node,left,mid,pos,v);
    else update(2*node+1,mid+1,right,pos,v);
    // update my node because one of my children is updated
    segtree[node]=max(segtree[2*node],segtree[2*node+1]);
}

int query(int node,int left,int right,int ql,int qr){
    // left, right are the node range
    // ql, qr are the query range
    //case 1: node range is all outside the query range
    if(left>qr||right<ql) return -20;
    // case 2: node range is all included in the query range
    if(left>=ql&&right<=qr) return segtree[node];
    // case 3: node range is partially included in the query range
    int mid=(left+right)>>1;
    int child1=query(2*node,left,mid,ql,qr);
    int child2=query(2*node+1,mid+1,right,ql,qr);
    return max(child1,child2);
}

int main(){
	cin>>n;
	for(int i=0;i<n;++i){
		cin>>p[i].f>>p[i].s;
		x[i]=p[i].f;
	}
	sort(p,p+n);
	sort(x,x+n);
	nxt[n-1]=n;
	update(1,0,n-1,n-1,nxt[n-1]);
	for(int i=n-2;i>=0;i--){
		ll myr=p[i].f+p[i].s;
		int r=lower_bound(x,x+n,myr)-x;
		if(r==i+1){
			nxt[i]=i+1;
			update(1,0,n-1,i,nxt[i]);
			continue;
		}
		if(r>=n){
			nxt[i]=n;
			update(1,0,n-1,i,nxt[i]);
			continue;	
		}
		r--;
		int l=i+1;
		nxt[i]=max(r+1,query(1,0,n-1,l,r));
		update(1,0,n-1,i,nxt[i]);
	}
	memset(dp,-1,sizeof(dp));
	cout<<solve(0);
    return 0;
}

Measured memory_bytes: 13568
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 999999999999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=m-1;i>=n;i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(),N.end()),N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(25) << S << endl
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define TV(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define mod 1000000007
#define MAX 5100000
#define ALL(a)  a.begin(),a.end()
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int main(){
  lli A,B,C,D,E,F,N,M,K,L,R,X,Y,Z,H,W,sum=0,num=0,flag=0;string S,T;
  cin >> N;
  Vec(P,pint,N,pint(0,0));
  Vec(Q,pint,N,pint(0,0));
  rep(i,0,N)cin >> P[i].first >> P[i].second;
  rep(i,0,N){
    Q[i].second=P[i].first-P[i].second;
    Q[i].first=P[i].first+P[i].second;
  }
  Sort(Q);
  sum=Q[0].first;
  rep(i,1,N){
    if(sum>Q[i].second){
      num++;
      continue;
    }
    sum=Q[i].first;
  }
  Out(N-num);
}

Measured memory_bytes: 3328
#include<iostream>
#include<vector>
#include<math.h>

using namespace std;

bool era(int num){
    if(num < 2) {
        return false;
    }else if(num==2) {
        return true;
    }else{
        if(num%2==0){
            return false;
        }else{
            int end =  sqrt(num);
            for(int i = 3; i <= end; i+=2){
                if(num%i==0) return false;
            }
        }
    }
    return true;
    
}

int main(){
    int n;
    int answer = 0;
    cin >> n;
    vector<int>numbers(n);
//入力部分
    for(int i = 0; i < n; i++){
        cin >> numbers[i];
    }

    for(int i = 0; i < n; i++){
        if(era(numbers[i])) answer++;
            
    }
    cout << answer << endl;
}


Measured memory_bytes: 3124
#include <stdio.h>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <iostream>
#include<math.h>
#include<bitset>
#include<iomanip>
#include<queue>
using namespace std;

int main() {
	int A, B, T; cin >> A >> B >> T;
	cout << (T / A)*B << endl;

}




Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long 
#define ld long double
#define pb push_back
#define vl vector
#define ff first
#define ss second
using namespace std;
int main()
{
    ll a,b,i,j,n,t,c,d,m,k;
    cin>>a>>b>>c>>d;
    ll ans=LLONG_MIN;
    ans=max(a*c,a*d);
    ans=max(ans,b*c);
    ans=max(ans,b*d);
    cout<<ans;
}

Measured memory_bytes: 3632
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
#define For(i,a,b) for(i=a;i<(ll)b;i++)
#define bFor(i,a,b) for(i=a;i>=(ll)b;i--)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N-1,0)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define endl "\n"
#define pb push_back
#define output(v) do{bool f=0;for(auto outi:v){cout<<(f?" ":"")<<outi;f=1;}cout<<endl;}while(0)
const ll mod=1000000007;
const ll inf=1LL<<60;
const double PI = acos(-1);
const double eps = 1e-9;
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;} 
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;} 

void startupcpp(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(15);
}

double distance(ddatas& x,ddatas& y){
  double a=x.first-y.first,b=x.second-y.second;
  return sqrt(a*a+b*b);
}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

vec modncrlistp,modncrlistm;

ll modncr(ll n,ll r){
  ll i,size=modncrlistp.size();
  if(size<=n){
    modncrlistp.resize(n+1);
    modncrlistm.resize(n+1);
    if(!size){
      modncrlistp[0]=modncrlistm[0]=1;
      size++;
    }
    For(i,size,n+1){
      modncrlistp[i]=modncrlistp[i-1]*i%mod;
      modncrlistm[i]=modinv(modncrlistp[i]);
    }
  }
  return modncrlistp[n]*modncrlistm[r]%mod*modncrlistm[n-r]%mod;
}

ll modpow(ll a,ll n){
  ll res=1;
  while(n){
    if(n&1)res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll gcd(ll a,ll b){if(!b)return a;return (a%b==0)?b:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

ll countdigits(ll n){
  ll ans=1;
  while(n){n/=2;ans*=2;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}
void judgement(int a){
  if(a){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  if(a){
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;
  }
}

int main(){
  ll i,j,N,K,bf,cnt=0,res=0;
  cin>>N>>K;
  vec v(N),ans(N*(N+1)/2);
  rep(i,N){
    cin>>v[i];
  }
  rep(i,N){
    bf=0;
    For(j,i,N){
      bf+=v[j];
      ans[cnt++]=bf;
    }
  }
  N=(N+1)*N/2;
  brep(i,40){
    cnt=0;
    rep(j,N){
      if(ans[j]&(1LL<<i))cnt++;
    }
    if(!res&&cnt<K)continue;
    if(cnt>=K){
      res+=1LL<<i;
      rep(j,N){
        if(ans[j]&(1LL<<i)){
          ans[j]%=1LL<<i;
        }else{
          ans[j]=0;
        }
      }
    }
  }
  cout<<res<<endl;
  return 0;
}

Measured memory_bytes: 4224
import collections
import math

mod = int(1e9 + 7)
n = int(input())
a = list(map(int,input().split()))

c = collections.Counter(a)
if n%2 == 0:
    check = True
    for i in range(n//2):
        if c[1+2*i] != 2:
            check = False
    if check:
        print(pow(2,n//2,mod))
    else:
        print(0)
else:
    if c[0] == 1:
        check = True
    else:
        check = False
    for i in range(1,n//2+1):
        if c[2*i] != 2:
            check = False
    if check:
        print(pow(2,n//2,mod))
    else:
        print(0)

Measured memory_bytes: 14812
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>

using namespace std;

#define mp make_pair
#define FOR(i, a, b) for (int(i) = a; (i) <= (b); ++(i))
#define rep(i, n) FOR(i, 0, n-1 )
#define FFOR(i, a, b) for (int(i) = a; (i) > (b); --(i))
#define rrep(i, n) FFOR(i, 0, n)
#define vsort(v) sort((v).begin(), (v).end());           //小さい順
#define rvsort(v) sort(v.begin(), v.end(), greater<>()); //大きい順
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl
#define no cout << "no" << endl
#define all(c) (c).begin(), (c).end()
#define ll long long
#define lb long double
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define Print(p) cout << (p) << endl
#define F first
#define S second
#define pb push_back
#define mod 1000000007LL
#define INF 123456789012345
#define int ll
typedef pair<int, int> P;
typedef pair<int, P> PP;

const int maxn = 1e5 + 10;

signed main() {

  int n,k;cin >>n>>k;

  cout <<(n%k==0?0:1) << endl;


    

  
 
}


Measured memory_bytes: 768
import sys

a,b,c=list(map(int,input().split()))

n=[]
def yaku(c):
  j=1
  moto=c
  while j<=moto:
    if c%j==0:
      n.append(j)    
    j+=1
  return n

s=[k for k in range(a,b+1)]
print(len(set(s)&set(yaku(c))))
      


Measured memory_bytes: 6612
#include <stdio.h>

int main(void){
  
  int a, b;
  int ans1, ans2;
  int temp;
  int i;
  int j;
  
  while( scanf("%d", &a) != EOF ){
    scanf("%d", &b);
    if( a > b ){
       temp = a;
       a = b;
       b = temp;
    }
    
    j = 0;
    if( !(a%2) && !(b%2) ) j = 1;
    if( a%2 && a%2 ) j = 1;
    
    i = a;
    while( i > 0 ){
      if( !(a % i) ){
        if( !(b % i) ){
           ans1 = i;
           i = 1;
        }
      }
      
      i = i - 1 - j;
    }
    
    ans2 = (b/ans1) * a;
    
    printf("%d %d\n", ans1, ans2);
    
  }
  
    
  return 0;
}

Measured memory_bytes: 596
#coding:utf-8
import sys
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = lambda *something : print(*something) if DEBUG else 0
DEBUG = True
def main(given = sys.stdin.readline):
    input = lambda : given().rstrip()
    LMIIS = lambda : list(map(int,input().split()))
    II = lambda : int(input())
    XLMIIS = lambda x : [LMIIS() for _ in range(x)]

    n = II()
    d = LMIIS()

    if d[0] != 0:
        print(0)
        exit()

    d.sort()

    a = 1

    c = 0
    old_c = 1
    ans = 1
    for i in range(1, n):
        if d[i] == a:
            c += 1
        elif d[i] == a+1 and c > 0:
            for j in range(c):
                ans = ans * old_c % 998244353
            a += 1
            old_c = c
            c = 1
        else:
            print(0)
            exit()

    if c > 0:
        for j in range(c):
            ans = ans * old_c % 998244353
    print(ans)









if __name__ == '__main__':
    main()


Measured memory_bytes: 14396
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
	    	Scanner sc = new Scanner(System.in);
	    	int n = sc.nextInt();
	    	int[] a = new int[n];
	    	int[] b = new int[n];
	    	long aSum = 0;
	    	long bSum = 0;
	    	long downCount = 0;
	    	long upSum = 0;
	    	long downSum = 0;
	    	long ansCount = 0;
	    	List<Integer> upList = new ArrayList<>();
	    	for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
			aSum += a[i];
		}
	    	for (int i = 0; i < n; i++) {
			b[i] = sc.nextInt();
			bSum += b[i];
			if (a[i] - b[i] >= 0) {
				upList.add(a[i]- b[i]);
				upSum += a[i] - b[i];
			} else {
				downCount++;
				downSum += (b[i] - a[i]);
			}
		}
	    	Collections.sort(upList, Comparator.reverseOrder());
	    	if (downCount == 0) {
	    		System.out.println(0);
	    		return;
	    	}
	    	if (upSum < downSum) {
	    		System.out.println(-1);
	    		return;
	    	}
	    	for (Integer integer : upList) {
			downSum -= integer;
			ansCount++;
			if (downSum <= 0) {
				System.out.println(ansCount+downCount);
				return;
			}
		}
	}
}


Measured memory_bytes: 85612
import java.io.*;
class Main{
  public static void main(String[] args)throws java.io.IOException{
             BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
 
             String hoge = input.readLine();
             int x = Integer.parseInt(hoge);
 
             System.out.println(x*x*x);
       }
}
       

Measured memory_bytes: 16856
#include<bits/stdc++.h>
#define ll long long 
#define pb push_back
#define ff first
#define ss second
#define setbits(x)          __builtin_popcountll(x)
#define lp(a,n) for(ll i=a; i<n; i++)
#define lpi(a,n) for(int i=a; i<n; i++)
#define w(t) int t; cin>>t; while(t--)
#define vi vector<int> 
#define vll vector<ll>
#define pll pair<ll, ll>
#define pii pair<int, int>
#define inf 1e9
#define LB lower_bound
#define UB upper_bound
const int mod = 1000000007;
using namespace std;
ll gcd(ll a,ll b){
    if(a==0)return b;
    return gcd(b%a,a);
}
ll lcm(ll a, ll b){
    return (a*b)/gcd(a,b);
}

int prime[100007];
void SieveOfEratosthenes(int n) 
{ 
    memset(prime, -1, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
         
        if (prime[p] == -1) 
        { 
            for (int i=p*p; i<=n; i += p) 
                prime[i] = p; 
        } 
    } 
    
} 
int lps(string s){
    int len = 0;
    int n = s.length();
    int dp[n];
    dp[0] = 0;
    for(int i=1; i<n; i++){
        if(s[i] == s[len]){
            len++;
            dp[i] = len;
            continue;
        }
        if(len!=0){
            len = dp[len-1];
            i--;
            continue;
        }
        dp[i]=0;
    }
    return dp[n-1];
}
 
ll power(unsigned ll x,unsigned  ll y) 
{ 
    ll res = 1;     
    while (y > 0) 
    { 
        if (y & 1) 
            res = res*x; 
   
        y = y>>1;
        x = x*x;  
    } 
    return res; 
}

//to calculate p1^x  *  p2^x2  *p3^x3 ----------
//i.e. prime factorization and store pi and xi in vector 
vector<pair<ll, ll>> pFactor;

void factorize(long long n) 
{ 
    int count = 0; 
  
    // count the number of times 2 divides  
    while (!(n % 2)) { 
        n >>= 1; // equivalent to n=n/2; 
        count++; 
    } 
  
    // if 2 divides it 
    if (count) 
        pFactor.pb({2,count}); 
  
    // check for all the possible numbers that can  
    // divide it 
    for (long long i = 3; i <= sqrt(n); i += 2) { 
        count = 0; 
        while (n % i == 0) { 
            count++; 
            n = n / i; 
        } 
        if (count) 
            pFactor.pb({i,count});
    } 
  
    // if n at the end is a prime number. 
    if (n > 2) 
        pFactor.pb({n,1}); 
} 



int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
   ll n, k;
   cin>>n>>k;
   map<ll, ll> mp;
   lp(1 , n+1){
       ll x;
       cin>>x;
       mp[i] = x;
   }
   set<ll> s;
   //s.insert(1);
   ll lpbegin=1;
   ll x=0;
   while(s.find(lpbegin)==s.end()){
       s.insert(lpbegin);
       lpbegin = mp[lpbegin];
       x++;
   }
   ll c=0, i=1;
   while(i!=lpbegin){
       i = mp[i];
       c++;
   }
   x -= c;
   ll ans;
   if(k > c){
       k-=c;
       k = k%x;
       
       while(k>0){
           lpbegin = mp[lpbegin];
           k--;
       }
       cout<<lpbegin;
   }
   else {
       lpbegin=1;
       while(k>0){
           lpbegin = mp[lpbegin];
           k--;
       }
       cout<<lpbegin;
   }
}

Measured memory_bytes: 25416
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cassert>
#include <functional>
#include <string>
using namespace std;


int main(){
  int x, t; cin >> x >> t;
  cout << max(0, x - t) << endl;
}


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

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

	sort(a.begin(), a.end());
	cout << a[n - 1] - a[0] << endl;
	
	return 0;
}

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

using ll = long long;
#define ld long double
#define ull unsigned long long int

#define rep(i, n) for (int i = 0; i < (int)(n); i++)  // (i, 10) i=0～i=9まで
#define repr(i, n) for (int i = n; i >= 0; i--)   // (i, 10) i=10～i=0まで
#define FOR(i, m, n) for (int i = m; i < n; i++)  // (i, 3, 10) i=3～i=9まで
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define ret return

typedef pair<int, int>    pii;
typedef vector<int>       vi;
typedef vector<vi>        vii;
typedef vector<long long> vl;

// 総数を1000000007で割った余り
const long long mod = 1e9 + 7;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    // cout << fixed << setprecision(5);

    // 入力
    string s1, s2, s3;
    cin >> s1 >> s2;

    // 処理
    s3 = s1 + s1;
    regex  re(s2);
    smatch m;

    // 出力
    cout << (regex_search(s3, m, re) ? "Yes" : "No") << endl;

    return 0;
}


Measured memory_bytes: 256
/*
このコード、と～おれ!
Be accepted!
  ∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
　　　　　　　　　　(¸.·´ (¸.·'* ☆
*/

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define printyn(a) printf(a ? "Yes\n" : "No\n");
#define printYN(a) printf(a ? "YES\n" : "NO\n");
#define all(x) (x).begin(), (x).end()

using ll = long long;

//マクロとかここまで

#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
//#include <vector>

using namespace std;

int main() {

	int n, k, ans;
	scanf("%d%d", &n, &k);
	ans = k;
	rep(i, n - 1)ans *= k - 1;
	printf("%d", ans);

	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
#include<string>
#include <numeric>
#include <queue>
#include <sstream>

using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;

template<typename T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }

template<typename T>
map<T, T> primeFactor(T n) {
	map<T, T> res;
	for (T i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			res[i] ++;
			n /= i;
		}
	}
	if (n != 1) res[n] = 1;
	return res;
}

template<typename T>
bool IsPrimeNumber(T num)
{
	if (num <= 2) return true;
	else if (num % 2 == 0) return false;

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			return false;
		}
	}

	return true;
}


#define in(x) cin >> x
#define out(x) cout << x
#define outn(x) cout << x << '\n'
#define outs(x) cout << x << ' '
#define rep(i,s,e) for(long i=s;i<e;i++)
#define repeq(i,s,e) for(long i=s;i<=e;i++)



int main() {
	static const double pi = 3.141592653589793;
	double a,b,x,s,t;
	in(a);
	in(b);
	in(x);
	
	s=(double)a*b;
	t=(double)x/a;

	if(2*t>=s){
		cout << fixed << setprecision(10) << 180*atan((s-t)*2/(a*a))/pi << endl; // C++
	}
	else{
		cout << fixed << setprecision(10) << 90.000000-(180*atan(t*2/(b*b))/pi) << endl; // C++
	}

	return 0;

}


Measured memory_bytes: 256
import sys
N,M = [int(n) for n in input().split()]

a = [0]*M
b = [0]*M
bucket = [0]*N
for i in range(M):
    a[i], b[i] = [int(n)-1 for n in input().split()]
    bucket[a[i]]+=1
    bucket[b[i]]+=1
for i in range(N):
    print(bucket[i])


Measured memory_bytes: 3060
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {

	sc := bufio.NewScanner(os.Stdin)
	sc.Scan()
	in := sc.Text()

	vars := strings.Split(in, " ")
	a, _ := strconv.Atoi(vars[0])
	b, _ := strconv.Atoi(vars[1])
	c, _ := strconv.Atoi(vars[2])

	if a <= b && b <= c {
		fmt.Printf("%v %v %v", a, b, c)
	} else if a <= c && c <= b {
		fmt.Printf("%v %v %v", a, c, b)
	} else if b <= a && a <= c {
		fmt.Printf("%v %v %v", b, a, c)
	} else if b <= c && c <= a {
		fmt.Printf("%v %v %v", b, c, a)
	} else if c <= a && a <= b {
		fmt.Printf("%v %v %v", c, a, b)
	} else if c <= b && b <= a {
		fmt.Printf("%v %v %v", c, b, a)
	}

	fmt.Println()
}



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

using namespace std;

#define pb push_back
#define mk make_pair
#define mod 1000000007
#define ff first
#define ss second

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

ll modpow(ll a, ll b){

    ll ans=1;
    while(b){
        if(b&1){
            ans=(ans*a)%mod;
        }
        a=(a*a)%mod;
        b=b/2;
    }
    return ans;
}

int main(){

	string n;
    cin>>n;

    if(n[0]==n[2]) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;


}


Measured memory_bytes: 256
def main():
    x, y, a, b, c = map(int, input().split())
    P = list(map(int, input().split()))
    Q = list(map(int, input().split()))
    R = list(map(int, input().split()))
    t = [1]
    t.sort()
    P.sort(reverse=True)
    Q.sort(reverse=True)
    R.sort(reverse=True)

    s = P[:x] + Q[:y]
    s.sort()
    for i in range(x + y):
        if i < c:
            if s[i] < R[i]:
                s[i] = R[i]
            else:
                break
        else:
            break
    print(sum(s))


if __name__ == "__main__":
    main()


Measured memory_bytes: 23328
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
input = sys.stdin.readline
 
# bisect_left(lists, 3)
# bisect_right(lists, 3)
 
def main():
	r, D, x2000 = map(int, input().split(" "))
	#N = int(input())
	#S = input()

	ans = []
	for i in range(10):
		if i == 0:
			tmp = r * x2000 - D
			ans.append(tmp)
		else:
			tmp = r * ans[i-1] - D
			ans.append(tmp)
	
	for i in ans:
		print(i)


if __name__ == "__main__":
	main()

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

int main() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    int w = 0, e = 0;
    vector<int> W(n+1, 0);
    vector<int> E(n+1, 0);
    rep(i,n) {
        if(s[i]=='W'){
            w++;
            W[i+1]=w;
        }else {
            W[i+1] = w;
        }
    }

    for(int i = n-1; i >= 1; --i) {
        if(s[i]=='E') {
            e++;
            E[i-1]=e;
        } else {
            E[i-1] = e;
        }
    }
    int ans = 999999999;
    rep(i,n) {
        int cnt = E[i] + W[i];
        ans = min(ans, cnt);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6132
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define ll long long
#define lst(x) x.size()-1
#define ld long double
#define pr pair<ll,ll>
#define loop(i,n) for(int i=0 ; i<n ; ++i)
#define rep(i,x,n) for(int i=x ; i<=n ; ++i)
#define iteloop(type,data,name,it) for(type<data>::iterator it=name.begin() ;it!=name.end() ; ++it)

using namespace __gnu_pbds;
using namespace std;

template<typename T>
using os = tree<T, null_type, less<T>, rb_tree_tag,
        tree_order_statistics_node_update>;
const int D=5,D2=5e2+5;
const ll N=D2,M=1e1+5,MOD=1e9+7,OO=1e9;
int arr[N*N],n;
int vec[D],vecSz;
void conn(int x){
    vecSz=0;
    if(x%n != 0)
        vec[vecSz++]=x+1;
    if((x-1)%n != 0)
        vec[vecSz++]=x-1;
    if(x+n<=n*n)
        vec[vecSz++]=x+n;
    if(x-n >= 1)
        vec[vecSz++]=x-n;
}
pair<int,int> getInd(int x){
    int row=(x-1)/n;
    int col=x-row*n-1;
    return {row,col};
}
int ans[N][N];
bool taken[N][N];
int main(){
    cin.sync_with_stdio(false), cin.tie(0) , cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("std/in.txt", "rt" , stdin);
    // freopen("in.txt", "wt" , stdout);
#endif // ONLINE_JUDGE
    scanf("%d",&n);
    loop(i,n*n){
        scanf("%d",&arr[i]);
    }
    loop(i,n){
        loop(j,n){
            ans[i][j] = min({i,j,n-i-1,n-j-1});
        }
    }
    int res=0;
    queue<int> q;
    loop(i,n*n){
        int x=arr[i];
        auto p=getInd(x);
        taken[p.first][p.second]=true;
        int cost = ans[p.first][p.second];
        res+=cost;
        conn(x);
        loop(k,vecSz){
            int g=vec[k];
            auto pg=getInd(g);
            int &r=ans[pg.first][pg.second];
            if(r>cost){
                r=cost;
                q.push(g);
            }
        }
        while(!q.empty()){
            int cur=q.front();
            q.pop();
            p=getInd(cur);
            conn(cur);
            cost = ans[p.first][p.second]+!taken[p.first][p.second];
            loop(k,vecSz){
                int g=vec[k];
                auto pg=getInd(g);
                int &r=ans[pg.first][pg.second];
                if(r>cost){
                    r=cost;
                    q.push(g);
                }
            }
        }
    }
    printf("%d\n",res);
}

Measured memory_bytes: 6020
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n;
    cin>>n;
    long long arr[n],arrf[n];
    for(long long i=0;i<n;i++){
        cin>>arr[i];
        arrf[i]=arr[i];
    }
    sort(arr,arr+n);
    long long x=arr[n-1];
    long long y=arr[n-2];
    for(long long i=0;i<n;i++){
        if(arrf[i]==x)
            cout<<y<<endl;
        else
            cout<<x<<endl;
    }
    return 0;
}


Measured memory_bytes: 4736
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9 + 7);

int main(void) {
	int n, x, t;
	cin >> n >> x >> t;
	
	cout << ((n + x - 1) / x) * t << endl; 
	
	return 0;
}


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

#define REPI(i, n) for(int i = 0; i < n; i++)
#define REPJ(j, n) for(int j = 0; j < n; j++)

using ll = long long;
using namespace std;

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

    int a, b; cin >> a >> b;
    if(a == 1)a+=13; if(b == 1)b+=13;
    cout << (a == b ? "Draw" : a > b ? "Alice" : "Bob");
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#pragma warning(disable:4996)
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
#define MOD 1000000007
using namespace std;

int main(int argc, char* argv[])
{
    long n, k;
    scanf("%ld%ld", &n, &k);

    ll ans=1;
    long i;
    for(i=0; i<n; i++) {
        if(i==0) ans = k;
        else     ans *= (k-1);
    }
    printf("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 128
#include<stdio.h>

int main(){
    int num1;

    char buf[256];
    fgets(buf,256,stdin);
    sscanf(buf,"%d",&num1);

    while(num1 < 1000){
        if(num1 == 111||num1 == 222||num1 == 333||num1 == 444||num1 == 555||num1 == 666||num1 == 777||num1 == 888||num1 == 999){
            printf("%d\n",num1);
            break;
        }
        num1++;
    }


}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef pair<double, double> pdd;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef vector<pii> vii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
const int mod = 998244353;
/*
ll mpow(ll x, ll n) {
  ll res = 1;
  while (n) {
    if (n & 1) res = res * x % mod;
    x = x * x % mod;
    n /= 2;
  }
  return res;
}

int dw(int x) {
  if (x >= mod) return x - mod;
  return x;
}*/

const int B = 22;
vvi precf(B);
vvi precg(B);

ll conv(const string & s) {
  ll x = 0;
  for (int i = 0; i < s.size(); ++i) if (s[i]) x += 1LL << i;
  return x;
}

string out(string s) {
  for (int i = 0; i < s.size(); ++i) s[i] += '0';
  return s;
}

ll f(const string & s);

ll g(const string & s) {
  int n = s.size();
  if (n == 1) return 1 + s[0]; 
  ll mask = conv(s);
  if (n < B && precg[n][mask] >= 0) return precg[n][mask];
  ll res = 0;
  for (int l = 1; l <= n / 2; ++l) if (n % l == 0) {
    string tmp(l, 1);
    for (int i = 0; i < l; ++i) for (int j = i; j < n; j += l) if (!s[j]) {
      tmp[i] = 0; break;
    }
/*    ll nmask = mask % (1LL << l);
    for (int i = l; i < n; i += l) nmask &= (mask >> i) % (1LL << l);
    for (int i = 0; i < l; ++i) tmp[i] = (nmask & (1LL << i)) ? 1 : 0;*/
    res = (res + f(tmp)) % mod;
  }
  if (n < B) precg[n][mask] = res;
//  cerr << "g " << out(s) << ' ' << res << endl;
  return res;
}

ll f(const string & s) {
  int n = s.size();
  if (n == 1) return 1 + s[0]; 
  ll mask = conv(s);
  if (n < B && precf[n][mask] >= 0) return precf[n][mask];
  vi d(n + 1);
  d[0] = 1;
  for (int i = 0; i < n; ++i) {
    for (int j = i; j < n; ++j) {
      d[j + 1] = (d[j + 1] + d[i] * g(s.substr(i, j - i + 1))) % mod;
    }
  }
  if (n < B) precf[n][mask] = d[n];
//  cerr << "f " << out(s) << ' ' << d[n] << endl;
  return d[n];
}

int main() {
  std::ios::sync_with_stdio(false); std::cin.tie(0);
  for (int i = 0; i < B; ++i) {
    precf[i].assign(1 << i, -1);
    precg[i].assign(1 << i, -1);
  }
  string s;
  cin >> s;
  for (int i = 0; i < s.size(); ++i) s[i] -= '0';
  cout << f(s) << endl;
  return 0;
}

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

int main(){
   // 制約見て！！！デカかったらlong longにすること！

    string s;
    int w;

    cin >> s >> w;

    string ans;
    int i = 0,slen=s.size();
    while(true){
        if(i>=slen){
            break;
        }
        ans += s[i];
        i+=w;
    }

    cout<<ans<<endl;
}


Measured memory_bytes: 3588
#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>;
const ll INF = 1LL << 60;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }

ll a[100010][3];

ll dp[100010][3];

int main(void){
    int n; cin >> n;
    rep(i,n) for(int j=0; j<3; j++) cin >> a[i][j];

    for(int i=0; i<n; i++){
        for(int j=0; j<3; j++){
            for(int k=0; k<3; k++){
                if(j == k) continue;
                chmax(dp[i+1][k], dp[i][j] + a[i][k]);
            }
        }
    }

    ll res = 0;
    for(int j=0; j<3; j++) chmax(res, dp[n][j]);
    cout << res << endl;

    return 0;
}


Measured memory_bytes: 4992
#include <cstdio>
#include <vector>
#include <tuple>
#include <algorithm>

using namespace std;

int main() {
  vector<pair<int, int> > vec;
  int N;
  scanf("%d", &N);
  for(int n=0; n<N; ++n) {
    int a, b;
    scanf("%d%d", &a, &b);
    vec.emplace_back(b, a);
  }
  sort(vec.begin(), vec.end());
  
  long long sum = 0;
  for(auto & v : vec) {
    sum += v.second;
    if(v.first<sum) {
      printf("No\n");
      return 0;
    }
  }
  printf("Yes\n");
  return 0;
}


Measured memory_bytes: 2420
import java.io.*;

public class Main{
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = br.readLine();
        String ans = "";

        for(int i = 0; i < line.length(); i++){
            String str = line.substring(i, i+1);
            if(str.equals(str.toUpperCase())){
                ans += str.toLowerCase();
            }else{
                ans += str.toUpperCase();
            }
        }
        System.out.println(ans);
    }
}

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

int main() {
  double w, h, x, y;
  cin >> w >> h >> x >> y;
  double ans;
  ans = (w*h)/2.0;
  cout << ans << " ";
  if(x*2==w && y*2==h){
    cout << 1 << endl;
  }
  else{
    cout << 0 << endl;
  }
}


Measured memory_bytes: 256