akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define endl "\n"
#define rep(i, a, n) for (int i = a; i < n; ++i)
#define all(x) (x).begin(), (x).end()

const int INF = 1e9;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int h, w, ch, cw, dh, dw;
    cin >> h >> w >> ch >> cw >> dh >> dw;
    ch--;
    cw--;
    dh--;
    dw--;
    vector<string> s(h);
    rep(i, 0, h) cin >> s[i];

    vector<vector<int>> dist(h, vector<int>(w, INF));
    deque<pii> dq;
    dq.emplace_back(ch, cw);
    dist[ch][cw] = 0;

    while (!dq.empty())
    {
        int ph = dq.front().first;
        int pw = dq.front().second;
        dq.pop_front();
        rep(i, ph - 1, ph + 2)
        {
            rep(j, pw - 1, pw + 2)
            {
                if (i >= 0 && j >= 0 && i < h && j < w && abs(ph - i) + abs(pw - j) == 1)
                {
                    if (dist[i][j] > dist[ph][pw] && s[i][j] != '#')
                    {
                        dist[i][j] = dist[ph][pw];
                        dq.emplace_front(i, j);
                    }
                }
            }
        }
        rep(i, ph - 2, ph + 3)
        {
            rep(j, pw - 2, pw + 3)
            {
                if (i >= 0 && j >= 0 && i < h && j < w)
                {
                    if (dist[i][j] > dist[ph][pw] && s[i][j] != '#')
                    {
                        dist[i][j] = dist[ph][pw] + 1;
                        dq.emplace_back(i, j);
                    }
                }
            }
        }
    }

    int ans = dist[dh][dw] == INF ? -1 : dist[dh][dw];
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 9356
#include<cstdio>
#include<iostream>
using namespace std;
string a;
int ans;
int main()
{
	cin>>a;
	int l=a.size();
	for(int i=0;i<(l>>1);i++)
	if(a[i]!=a[l-i-1]) ans++;
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 256
h,w,k=map(int,input().split())
c=[input() for _ in range(h)]
count=0
for H in range(1<<h):
  for W in range(1<<w):
    b=0
    for i in range(h):
      for j in range(w):
        if (H >> i) & 1 == 0 and (W >> j) & 1 == 0 and c[i][j] == "#":
          b+=1
    if b==k:
      count+=1
print(count)

Measured memory_bytes: 73864
#include<iostream>
#include<iomanip>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<limits>
#include<numeric>
#include<bitset>
#include<unordered_map>
#include<functional>
using namespace std;

#define rep(i,s,n) for(int i=s;i<n;i++)
#define dow(i,n,s) for(int i=n-1;i>=s;i--)
#define all(a) a.begin(),a.end()
#define range(a,b,e) a.begin()+b,a.begin()+e
//#define DEBUG
typedef pair<int,int> II;
typedef unsigned long ul;
typedef long long ll;
typedef unsigned long long ull;

const int INF = 1e+9;
const int MAX_N = 1e+3;

int n;
vector<int> d,vtmp;

void solve();

int main() {

  cin>>n;
  d.resize(n);
  rep(i,0,n) cin>>d[i];
  solve();

  return 0;
}

void solve() {
  int res = 0;
  int itmp;
  bool flag;
  while(true) {
    flag = false;
    vtmp.clear();
    itmp = res;
    if(itmp == 0 || (itmp != 0 && log10(itmp) == 0)) vtmp.push_back(itmp);
    else{
      rep(i,0,(int)(log10(res)+1)) {
        vtmp.push_back(itmp%10);
        itmp/=10;
      }
    }
#ifdef DEBUG
    dow(i,vtmp.size(),0) cout<<vtmp[i]<<" , ";
    cout<<endl;
#endif
    rep(i,0,n) {
      if(!(flag) && (d[i] == vtmp[vtmp.size()-1])) {
        //cout<<"OK"<<i<<endl;
        flag = true;
        if(i <= n-vtmp.size()) {
          rep(j,1,vtmp.size()) {
            if(flag && d[i+j] != vtmp[vtmp.size()-1-j]) flag = false;
          }
        }else { flag = false; }
      }
    }
    if(!flag) { cout<<res<<endl; return ; }
    res++;
  }
}



Measured memory_bytes: 3424
MOD = 10**9 + 7
MAX = 10**6
X, Y = map(int, input().split())
m, n = 2*Y-X, 2*X-Y
if (X+Y) % 3 != 0 or m%3!=0 or n%3!=0 or m<0 or n<0:
    print(0)
    exit()

m //= 3
n //= 3

fac, inv = [0]*MAX, [0]*MAX
fac[0] = 1
for i in range(1, MAX):
    fac[i] = fac[i-1] * i % MOD
inv[-1] = pow(fac[-1], MOD-2, MOD)
for i in range(MAX-2, 0, -1):
    inv[i] = inv[i+1] * (i+1) % MOD

def com(n, k):
    if n<k:return 0
    if n<0 or k<0:return 0
    if n==k or k==0:return 1
    return int(fac[n] * (inv[k]*inv[n-k]%MOD) % MOD)

print(com(n=m+n,k=n))

Measured memory_bytes: 80060
n, m, x = map(int, input().split())
a = list(map(int, input().split()))

right = 0
for r in range(x, n+1):
    if r in a:
        right += 1

left = 0
for l in range(x):
    if l in a:
        left += 1

print(min(right, left))

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

int main() {
  ll a, b, c, k;
  cin >> a >> b >> c >> k;
  ll x = a + b + c * pow(2,k);
  ll y = a + b * pow(2,k) + c;
  ll z = a * pow(2,k) + b + c;
  cout << max(max(x,y),z) << endl;
}

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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

// grid
//--------------------------------------------
VL dx = {0, 1, 0, -1};
VL dy = {1, 0, -1, 0};
VL dx2 = {-1, 0, 1, -1, 1, -1, 0, 1};
VL dy2 = {-1, -1, -1, 0, 0, 1, 1, 1};

//debug
//--------------------------------------------
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//IO accelerate
//--------------------------------------------
struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

//template
//--------------------------------------------
template<typename T>
istream& operator >>(istream& is, vector<T>& vec) {
  for(T& x: vec) is >> x;
  return is;
}
template<typename T>
ostream& operator <<(ostream& os, const vector<T>& vec) {
  for(int i=0; i<vec.size(); i++){
    os << vec[i] << ( i+1 == vec.size() ? "" : "\t" );
  }
  return os;
}
template<typename T>
ostream& operator <<(ostream& s, const vector<vector<T>>& vv) {
	for (int i = 0; i < vv.size(); ++i) {
		s << vv[i] << endl;
	}
	return s;
}

//main code

int main(int argc, char const* argv[])
{
	int n;
	cin >> n;
	VL d(n);
	cin >> d;
	SORT(d);
	cout << d[n/2] - d[n/2-1] << endl;
	return 0;
}


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

const int mod = 1e9 + 7;

signed main() {
  int n;
  cin >> n;
  map < int, int > cnt;
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    ++cnt[x];
  }
  bool ok = 1;
  for (int i = n - 1; i >= 0; i -= 2) {
    if (i == 2)
      ok = ok && (cnt[i] == 2);
    else if (!i)
      ok = ok && (cnt[i] == 1);
    else
      ok = ok && (cnt[i] == 2);
  }
  if (!ok)
    cout << "0\n";
  else {
    int64_t ans = 1;
    for (int i = 0; i < n / 2; ++i)
      (ans *= 2) %= mod;
    cout << ans << '\n';
  }
}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using PQ = priority_queue<lint, vector<lint>, greater<lint>>;

struct UnionFind {
    vector<int> data;
    UnionFind(int n) { data.assign(n, -1); }

    bool unite(int x, int y) {
        x = root(x), y = root(y);
        if(x == y) return true;
        if(data[x] > data[y]) swap(x, y);
        data[x] += data[y];
        data[y] = x;
        return true;
    }

    int root(int x) {
        return (data[x]<0 ? x : data[x]=root(data[x]));
    }

    int size(int x) {
        return -data[root(x)];
    }
};

int main() {
  lint N, M;
  cin >> N >> M;

  vector<lint> a(N);
  for(auto& elem : a) cin >> elem;

  UnionFind uf(N);
  for(lint i=0; i<M; i++) {
    lint x, y;
    cin >> x >> y;
    uf.unite(x, y);
  }

  map<lint, PQ> mp;
  for(lint i=0; i<N; i++) {
    mp[uf.root(i)].push(a[i]);
  }
  vector<PQ> que;
  for(auto [key, value] : mp) que.push_back(value);
  sort(que.begin(), que.end(), [](PQ &q1, PQ &q2) {
    return q1.size() > q2.size();
  });

  lint ans = 0;
  lint k = que.size();
  PQ S = que[0];
  for(lint i=1; i<k; i++) {
    if(S.empty()) {
      cout << "Impossible" << endl;
      return 0;
    }
    lint ai = S.top(); S.pop();
    lint aj = que[i].top(); que[i].pop();
    ans += ai + aj;
    while(que[i].size()) {
      S.push(que[i].top());
      que[i].pop();
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 21732
import std.algorithm, std.conv, std.range, std.stdio, std.string;

void main()
{
  auto s = readln.chomp;
  auto p = readln.chomp;

  foreach (i; 0..s.length)
    if ((s[i..$] ~ s[0..i]).canFind(p)) {
      writeln("Yes");
      return;
    }

  writeln("No");
}

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

using namespace std;
typedef long long ll;
const int MAXN = 1000100;

int N;
int arr[MAXN];

int main()
{
    ios_base::sync_with_stdio(0);

    cin >> N;

    int cres = 0, ck = 0;
    for (int i = 0; i < N; i++)
    {
        char c; cin >> c;
        arr[i] = c - '1';

        if (arr[i] == 1) ck = -1e9;

        if (((N-1) & i) == i)
        {
            //cout << i << " " << arr[i] << "\n";
            cres = (cres + arr[i]) % 2;
            ck = (ck + arr[i] / 2);
        }
    }

    if (ck >= 0)
        cout << 2 * (ck % 2) << "\n";
    else
        cout << cres % 2 << "\n";
}

Measured memory_bytes: 4224
#include<iostream>
using namespace std;
int main()
{
	long int n,k;
	cin>>n>>k;
	long int t=0;
	if(k==10)
	{
		while(n!=0)
		{
			n=n/10;
			t++;
		}
	}
	else{
		t=1;
		while(n>=k)
		{
			n=n/k;
			t++;
		}
	}
	cout<<t<<endl;
	return 0;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;
 
template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}
 
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
 
class Mo {
	// segment: [left, right)
	class Query {
		public:
		int left;
		int right;
		int id;
		
		Query(const int left, const int right, const int id) 
			: left(left), right(right), id(id) {};
	};
	
	std::vector<Query> queries;
	const size_t N;
	
	size_t getSqrt(const size_t t) {
		size_t sqrt = 0;
		while(sqrt * sqrt <= t) sqrt++;
		return sqrt - 1;
	}
	void build(const size_t sqrtQ) {
		sort(begin(queries), end(queries), [&](Query a, Query b) {
			const int bucketA = a.left / sqrtQ, bucketB = b.left / sqrtQ;
			if(bucketA == bucketB) {
				if(bucketA & 1) {
					return a.right > b.right;
				} else {
					return a.right < b.right;
				}
			}
			return bucketA < bucketB;
		});
	}
	public:
	Mo(size_t n) : N(n) {}
	inline void addQuery(int left, int right) {
		queries.push_back(Query(left, right, (int)queries.size()));
	}
	inline int process() {
		static int left = 0, right = 0;
		static int index = 0;
		if(!index) build(getSqrt(queries.size()));

		Query q = queries[index++];
		while(left > q.left) add(--left);
		while(left < q.left) del(left++);
		while(right < q.right) add(right++);
		while(right > q.right) del(--right);
		return q.id;
	}
	inline void add(int i);
	inline void del(int i);
};
 
std::vector<int> a, count;
int val = 0;
 
// :::impl:::
inline void Mo::add(int i) {
	if(count[a[i]]++ == 0) val++;
};
inline void Mo::del(int i) {
	if(--count[a[i]] == 0) val--;
};
 
int main() {
	int n, q; scanf("%d%d", &n, &q); a.resize(n); count.resize(n);
	for(int i = 0; i < n; i++) scanf("%d", &a[i]);
	
	Mo mo(n);
	for(int i = 0; i < q; i++) {
		int a, b; scanf("%d%d", &a, &b);

		mo.addQuery(a - 1, b);
	}
	
	std::vector<int> ans(q);
	while(q--) {
		int id = mo.process();
		ans[id] = val;
	}
	for(auto v: ans) printf("%d\n", v);
	return 0;
}


Measured memory_bytes: 15476
#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
 
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define mod 1000000007
#define inf 1e18+42
#define endl "\n"

#define out1(a) cout<<#a<<" "<<a<<endl
#define out2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define out3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl

#define rep(i,a,b) for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)
#define fori(it,A) for(auto it=A.begin();it!=A.end();it++)

#define ft first
#define sd second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define zero(x) memset(x,0,sizeof(x));
 
using namespace std;

int binpow(int,int);
void dfs( vector< vector<int> >&, int , vector<int>& );
void bfs( vector< vector<int> >&, int , vector<int>& );

int binarySearchCount(vector<int> arr, int n, int key,int l,int r ) 
{ 
    int left = l; 
    int right = r; 
  
    int count = 0; 
  
    while (left <= right) { 
        int mid = (right + left) / 2; 
  
        // Check if middle element is 
        // less than or equal to key 
        if (arr[mid] < key) { 
  
            // At least (mid + 1) elements are there 
            // whose values are less than 
            // or equal to key 
            count = mid + 1; 
            left = mid + 1; 
        } 
  
        // If key is smaller, ignore right half 
        else
            right = mid - 1; 
    } 
  
    return count; 
} 
const int N = 2*1000 + 5;
void solve()
{
    int n;
    cin>>n;

    vector<int> a(n);
    int f[N] = {0};
    rep(i,0,a.size())
    {
        cin>>a[i];
        f[a[i]+1]++;
    }

    rep(i,1,N)
    {
        f[i] += f[i-1];
    }
    sort(all(a));
    int sum = 0;
    
    rep(i,0,a.size())
    {
        rep(j,i+1,a.size())
        {
            sum += f[a[i]+a[j]] - j - 1;
        }
    }


    cout<<sum<<endl;
}

signed main()
{
    fast;
    int t = 1;
    // cin>>t;

    while(t--)
    {
        solve();
    }
    return 0;
}

int binpow(int a, int b) {
    int res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}

void dfs ( vector< vector<int> > &v , int x , vector<int> &vis )
{
    vis[x] = 1;

    rep(i,0,v[x].size())
    {
        if( vis[v[x][i]] == 0 )
        {
            dfs(v,v[x][i],vis);
        }
    }
}

void bfs( vector< vector<int> > &v , int x , vector<int> &vis )
{
    queue<int> q;
    q.push(x);

    while( !q.empty() )
    {
        int p = q.front();
        q.pop();

        rep(i,0,v[p].size())
        {
            if ( vis[v[p][i]] == 0 )
            {
                vis[v[p][i]] = 1;
                q.push(v[p][i]);
            }
        }
    }
}

Measured memory_bytes: 256
n, m = map(int,input().split())
sc = []
for i in range(m):
    s,c = map(int,input().split())
    sc.append([s,c])
for i in range(1000):
    if len(str(i)) == n:
        flag = True
        for j in range(m):
            if int(str(i)[sc[j][0] - 1]) != sc[j][1]:
                flag = False
        if flag:
            print(i)
            exit()
        else:
            continue
print(-1)



Measured memory_bytes: 3064
def prime_factorize(n):
    cnt = {}
    f = 2
    while f * f <= n:
        if n%f != 0:
            f += 1
            continue
        cnt.setdefault(f, 0)
        cnt[f] += 1
        n //= f
    if n > 1:
        cnt.setdefault(n, 0)
        cnt[n] += 1
    return cnt
n, p = map(int, input().split())
cnt = prime_factorize(p)
ans = 1
for k, v in cnt.items():
    ans *= k ** (v//n)
print(ans)

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

int main() {
	int N, a[20010], b[20010], p[20010];
	cin >> N;
	for(int i=0; i<N; ++i){
	    int g; cin >> g;
	    p[g]=i;
	}
	a[1]=1, b[1]=p[1]-1;
	cout << 1;
	for(int i=2; i<=N; ++i){
	    if(p[i]-p[i-1]>0){
	        b[i]=b[i-1]-1;
	        a[i]=p[i]-b[i];
	    }
	    else{
	        a[i]=a[i-1]+1;
	        b[i]=p[i]-a[i];
	    }
	    cout << ' ' << a[i];
	}
	cout << endl;
	int ad=max(0, 1-b[N]);
	cout << b[1]+ad;
	for(int i=2; i<=N; ++i) cout << ' ' << b[i]+ad;
	cout << endl;
	return 0;
}


Measured memory_bytes: 768
#include <algorithm>
#include <array>
#include <cstddef>
#include <cstdint>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <vector>

using namespace std;

int main()
{
    int n;
    cin >> n;
    cout << (n * (n + 1) / 2) << endl;
}


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

#define GET_MACRO(_1,_2,_3,_4,NAME,...) NAME
#define REP2(i,n) for(int i=0;i<(int)(n);i++)
#define REP3(i,m,n) for(int i=m;i<(int)(n);i++)
#define REP4(i,m,n,s) for(int i=m;(s>0 and i<(int)(n)) or (s<0 and i>(int)(n));i+=s)
#define REP(...) GET_MACRO(__VA_ARGS__, REP4, REP3, REP2)(__VA_ARGS__)
#define REPIT(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define PIS(x) printf("%d ",x)
#define PRINTIA(a,n) REP(i,n){printf("%d ", *((a)+i));}putchar('\n');
#define PN() putchar('\n')
#define MP make_pair
#define PB push_back

typedef pair<int,int> PII;
typedef long long LL;
typedef unsigned long long ULL;

void RI() {}
template<typename... T>
void RI( int& head, T&... tail ) {
    scanf("%d",&head);
    RI(tail...);
}
void PI() {putchar('\n');}
template<typename... T>
void PI(const int head, T... tail ) {
    printf("%d ", head);
    PI(tail...);
}

#define MAX_N 300005
int a[MAX_N];
int b[MAX_N];
multiset<int> fh, sh, sh2;

int main()
{
    int N;
    RI(N);
    REP(i, 3*N) {
        RI(a[i]);
    }
    LL s1 = 0, s2 = 0;
    REP(i, N) {
        fh.insert(a[i]);
        s1 += a[i];
    }
    REP(i, 2*N) {
        b[i] = a[i+N];
    }
    sort(b, b+2*N);
    REP(i, N) {
        sh.insert(b[i]);
        s2 += b[i];
    }
    REP(i, N, 2*N) {
        sh2.insert(b[i]);
    }
    LL best = s1 - s2;
    //printf("%lld %lld %lld\n", s1, s2, best);
    REP(i, N, 2*N) {
        auto it = sh.find(a[i]);
        if(it != sh.end()) {
            s2 -= *it;
            sh.erase(it);
            auto it2 = sh2.begin();
            sh.insert(*it2);
            s2 += *it2;
            sh2.erase(it2);
        } else {
            sh2.erase(sh2.find(a[i]));
        }

        auto it3 = fh.begin();
        if(a[i] > *it3) {
            s1 -= *it3;
            fh.erase(it3);
            fh.insert(a[i]);
            s1 += a[i];
        }
        best = max(best, s1 - s2);
        //printf("%lld %lld %lld\n", s1, s2, best);
    }
    printf("%lld\n", best);
    return 0;
}


Measured memory_bytes: 16256
#include<stdio.h>
#define N 100000
#define M 50000


int main(void){
  int i, j, n, q, S[N], T[M], a, b, count=0;
  scanf("%d", &n);
  for(i=0; i<n ;i++) scanf("%d", &S[i]);
  scanf("%d", &q);
  for(i=0; i<q ;i++)  scanf("%d", &T[i]);
  
  for(i=0; i<n ;i++){
    for(j=0; j<q ;j++){
      
      a = S[i];
      b = T[j];
      if(a == b) { 
	count++;
	T[j] = -1; 
	break;
      }
    }
  }
  printf("%d\n", count);
  return 0;
}

Measured memory_bytes: 648
/* Note:
Check constants at the beginning of the code.
    N is set to 4e5 but be careful in problems with large constant factor.
    Setting N in every problem is more effective.
Check corner cases.
    N = 1
No def int long long for now.
Add something here.

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

int mod = 1000000007;
ll dp[100005];
const ll INF = 1e18;

ll gcd(long long a,long long b){

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


bool sortbyval(const pair<string, int> &a,
               const pair<string, int> &b)
{
    return (a.second < b.second);
}

 int main(){

 ll n,x,ans=1;
 bool over = false,zero = false;
  cin>>n;

  for(int i=0;i<n;i++)
  {
    cin>>x;
    if(x == 0){
        zero = true;
        break ; }

     if(x <= INF/ans)
        ans *= x;
     else
        over = true;

  }

   if(zero)
    cout<<"0"<<endl;
   else if(over)
    cout<<"-1"<<endl;
   else
    cout<<ans<<endl;

 return 0;
 }



Measured memory_bytes: 3624
from collections import deque
from pprint import pprint
N = int(input())
nextGame = [deque()] + [deque(map(int , input().split())) for _ in range(N)]
#print(nextGame)

canPlay = [[False] * (N + 1) for _ in range(N + 1)]
#pprint(canPlay)
days = [0] * (N + 1)
que = ([i for i in range(N + 1)])

while que:
    now = que.pop()
    #print("------------------------")
    if not nextGame[now]:
        continue
    enemy = nextGame[now].popleft()
    canPlay[now][enemy] = True
    #print("now : ",now)
    #print("enemy : ",enemy)
    #pprint(canPlay)

    if canPlay[now][enemy] and canPlay[enemy][now]:
        days[now] = days[enemy] = max(days[now], days[enemy]) + 1
        que.append(now)
        que.append(enemy)
    #print("days : ",days)

for test in nextGame:
    if test:
        print("-1")
        exit(0)
print(max(days))


Measured memory_bytes: 44272
#include <iostream>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <string.h>
#include <stack>
#define Endl endl
#define mp make_pair
#define rep(N) for(int i=0;i<N;i++)
#define repj(N) for(int j=0;j<N;j++)
#define ll long long 
#define pii pair<int,int>
#define pll pair<ll,ll>
#define For(I,N) for(int I=0;I<N;I++)
#define cinone(N) int N;cin>>N;
#define scanfone(N) int N;cin>>N;
#define cinng(N,M) int N[M];for(int yiuytvnm=0;yiuytvnm<M;yiuytvnm++) cin>>N[yiuytvnm];
#define scanfng(N,M) int N[M];for(int qrwuoiq=0;qrwuoiq<M;qrwuoiq++) scanf("%d",&N[qrwuoiq]);
#define over(A) {cout<<A<<endl;exit(0);}
typedef unsigned long long ull;
const int inf=103974182;
using namespace std;
int n;
int a[100005];

int main()
{
//	freopen("input.txt","r",stdin);
	cin>>n;
	ll maxn=0;
	int krk=-1;
	for(int i=0;i<n;i++)
	{
		scanf("%d",a+i);
		if(a[i]>maxn)
		{
			maxn=a[i];
			krk=i;
		}
	}
	ll ans=inf*10;
	ll res=-1;
	for(int i=0;i<n;i++)
	{
		if(i==krk) continue;
 		if(abs(1LL*a[i]*2-maxn)<ans)
		{
			res=a[i];
			ans=abs(1LL*a[i]*2-maxn);
		}
	}
	cout<<maxn<<' '<<res<<endl;
	return 0;
}

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

using ll = long long;
using P = pair<int, int>;

const int INF = 1e9;
const int MOD = 1e9 + 7;

// 4近傍、8近傍
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main() {
  ll N, D;
  cin >> N >> D;
  ll x[N], y[N];
  for (int i = 0; i < N; i++) cin >> x[i] >> y[i];

  int ans = 0;
  for (int i = 0; i < N; i++) {
    if (x[i] * x[i] + y[i] * y[i] <= D * D) ans++;
  }

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


Measured memory_bytes: 6744
class Trie:
    class Node:
        def __init__(self,c):
            self.c=c
            self.next_c_id={}
            #self.common=0
            self.end=-1

    def __init__(self):
        self.trie=[self.Node('')]
    
    def add(self,id,s):
        i=0
        now=0
        ary=[0]
        while i<len(s) and s[i] in self.trie[now].next_c_id:
            now=self.trie[now].next_c_id[s[i]]
            ary.append(now)
            #self.trie[now].common+=1
            i+=1
        while i<len(s):
            self.trie[now].next_c_id[s[i]]=len(self.trie)
            now=len(self.trie)
            ary.append(now)
            self.trie.append(self.Node(s[i]))
            #self.trie[now].common+=1
            i+=1
        self.trie[now].end=id
        return ary
    
    def search(self,s):
        i=0
        now=0
        ary=[0]
        while i<len(s) and s[i] in self.trie[now].next_c_id:
            now=self.trie[now].next_c_id[s[i]]
            ary.append(now)
            i+=1
        if i<len(s):return []
        return ary
def main(s):
    tr=Trie()
    s.sort(key=lambda x:len(x))
    ans=0
    for i,x in enumerate(s):
        ary=tr.add(i,x)
        seen=set(())
        while ary:
            id=ary.pop()
            for nv in seen&tr.trie[id].next_c_id.keys():
                if tr.trie[tr.trie[id].next_c_id[nv]].end>=0 and tr.trie[tr.trie[id].next_c_id[nv]].end!=i:
                    ans+=1
            seen.add(tr.trie[id].c)
    print(ans)

if __name__=='__main__':
    a2n=lambda x:ord(x)-ord('a')
    n=int(input())
    s=[list(map(a2n,list(input()))) for _ in range(n)]
    [x.reverse() for x in s]
    main(s)


Measured memory_bytes: 486200
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using Map = map<ll,ll>;
using T = tuple<ll,ll,ll>;
using vvl = vector<vector<ll>>;
#define all(v) v.begin(), v.end()
#define print(v) cout<<v<<endl;
#define fi(v) get<0>(v)
#define se(v) get<1>(v)
#define th(v) get<2>(v)
template <typename T> bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template <typename T> bool chmin(T &a, const T &b){if (a>b){a=b;return 1;}return 0;}
const ll INF=1LL<<60;
const ll MOD=1000000007;

ll K;

vector<vector<ll>> dpb(2000, vector<ll>(2000, 0));
vector<vector<ll>> dpw(2000, vector<ll>(2000, 0));

ll Fb(ll a,ll b,ll c,ll d){
    ll bc=0,ad=0,ac=0;
    if(a)ad=dpb[a-1][d];
    if(c)bc=dpb[b][c-1];
    if(a&&c)ac=dpb[a-1][c-1];
    return dpb[b][d]-bc-ad+ac;
}
ll Fw(ll a,ll b,ll c,ll d){
    ll bc=0,ad=0,ac=0;
    if(a)ad=dpw[a-1][d];
    if(c)bc=dpw[b][c-1];
    if(a&&c)ac=dpw[a-1][c-1];
    return dpw[b][d]-bc-ad+ac;
}


int main(){
    ll N;
    cin >> N;
    ll K;
    cin >> K;
    vector<ll> X(N,0);
    vector<ll> Y(N,0);
    vector<char> C(N);
    for(ll i=0;i<N;i++)cin>>X[i]>>Y[i]>>C[i];
    vector<vector<ll>> coub(2*K, vector<ll>(2*K, 0));
    vector<vector<ll>> couw(2*K, vector<ll>(2*K, 0));
    for(ll i=0;i<N;i++){
        X[i]%=2*K;
        Y[i]%=2*K;
        if(C[i]=='B')
        coub[X[i]][Y[i]]++;
        else
        couw[X[i]][Y[i]]++;
    }
    dpb[0][0]=coub[0][0];
    dpw[0][0]=couw[0][0];
    for(ll i=1;i<2*K;i++){
        dpb[0][i]=dpb[0][i-1]+coub[0][i];
        dpw[0][i]=dpw[0][i-1]+couw[0][i];
        dpb[i][0]=dpb[i-1][0]+coub[i][0];
        dpw[i][0]=dpw[i-1][0]+couw[i][0];
    }
    for(ll i=1;i<2*K;i++)
        for(ll j=1;j<2*K;j++){
                dpb[i][j]=dpb[i-1][j]+dpb[i][j-1]-dpb[i-1][j-1]+coub[i][j];
                dpw[i][j]=dpw[i-1][j]+dpw[i][j-1]-dpw[i-1][j-1]+couw[i][j];
        }
    ll ans=0;
    for(ll i=0;i<K;i++)
        for(ll j=0;j<K;j++){
            //左下が黒
            ll sumB,sumW;
            sumB=Fb(0,i,0,j)+Fb(i+K+1,2*K-1,0,j)+Fb(i+1,i+K,j+1,j+K)
                +Fb(0,i,j+K+1,2*K-1)+Fb(i+K+1,2*K-1,j+K+1,2*K-1);
            sumW=Fw(i+1,i+K,0,j)+Fw(0,i,j+1,j+K)+Fw(i+K+1,2*K-1,j+1,j+K)+Fw(i+1,i+K,j+K+1,2*K-1);
            chmax(ans,sumB+sumW);
            
            //左下が白
            sumB=Fb(i+1,i+K,0,j)+Fb(0,i,j+1,j+K)+Fb(i+K+1,2*K-1,j+1,j+K)+Fb(i+1,i+K,j+K+1,2*K-1);
            sumW=Fw(0,i,0,j)+Fw(i+K+1,2*K-1,0,j)+Fw(i+1,i+K,j+1,j+K)
                +Fw(0,i,j+K+1,2*K-1)+Fw(i+K+1,2*K-1,j+K+1,2*K-1);
            chmax(ans,sumB+sumW);
            
        }
    print(ans)
    return 0;
}


Measured memory_bytes: 127360
using System;

namespace _1_2b
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] hoge = Console.ReadLine().Split(' ');
            int a = int.Parse(hoge[0]);
            int b = int.Parse(hoge[1]);
            int c = int.Parse(hoge[2]);

            if (a < b && b < c)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}



Measured memory_bytes: 15968
#![allow(unused_imports)]
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(deprecated)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;
use std::usize;

const MOD_10_9_7: u64 = 1_000_000_007;
const INF: i64 = 1_000_000_000_000;
const MIN_INF: i64 = -1_000_000_000_000;

/// FYI: https://github.com/vain0x/scan-bench
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($t:ty) =>
        (rl().parse::<$t>().unwrap());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.trim_right().to_owned()
}

fn main() {
    let (r, d, x) = read!(i64, i64, i64);
    let mut tmp_x = x;
    for _i in 1..11 {
        tmp_x = r * tmp_x - d;
        println!("{}", &tmp_x);
    }
}


Measured memory_bytes: 4352
S=input()
c=[]
for i in range(1,len(S)//2+1):
    if S[0:i]==S[i:2*i]:
        c.append(S[0:i])


for i in range(1,len(c)+1):
    if c[-i]*2 in S[0:len(S)-1]:
        print(len(c[-i]*2))
        break
    

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <cstring>
#include <climits>
#include <algorithm>
#include <map>
using namespace std;

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

int X, Y;
int d[52][52];
int mintime[52][52][52][52];

void dfs(int tx, int ty, int kx, int ky, int t, int &mint) {
    if (tx == kx && ty == ky) {
        mint = min(t, mint);
        return ;
    }
    if (mint <= t) {
        return ;
    }
    mintime[tx][ty][kx][ky] = min(mintime[tx][ty][kx][ky], t);
    for (int i=0; i<4; ++i) {
        if (d[ty+dy[i]][tx+dx[i]] && d[ky-dy[i]][kx-dx[i]]) continue;
        int tx2 = tx, ty2 = ty;
        if ( ! d[ty+dy[i]][tx+dx[i]]) {
            tx2 += dx[i];
            ty2 += dy[i];
        }
        int kx2 = kx, ky2 = ky;
        if ( ! d[ky-dy[i]][kx-dx[i]]) {
            kx2 -= dx[i];
            ky2 -= dy[i];
        }
        if (t+1 < mintime[tx2][ty2][kx2][ky2]) {
            dfs(tx2, ty2, kx2, ky2, t+1, mint);
        }
    }
}

int main() {
    while (cin >> X >> Y, X) {
        int tx, ty, kx, ky;
        cin >> tx >> ty >> kx >> ky;
        for (int i=0; i<=Y+1; ++i) {
            for (int j=0; j<=X+1; ++j) {
                if (i==0 || i==Y+1 || j==0 || j==X+1) d[i][j] = 1;
                else cin >> d[i][j];
            }
        }
        for (int i=0; i<52; ++i) for (int j=0; j<52; ++j) {
            for (int k=0; k<52; ++k) for (int l=0; l<52; ++l) {
                mintime[i][j][k][l] = 101;
            }
        }
        int mint = 101;
        dfs(tx, ty, kx, ky, 0, mint);
        if (mint == 101) {
            cout << "NA" << endl;
        } else {
            cout << mint << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 29744
def SolveABC085C(N, Y):

    finFlag = 0
    for z in range(N + 1):
        for (x,y) in zip(range(N - z+1), range(N - z + 1)[::-1]):
            if x * 10 + y * 5 + z == Y/1000:
                print "{} {} {}".format(x,y,z)
                finFlag = 1
                break
        if finFlag == 1:
            break
        if z == N:
            print "-1 -1 -1"
            
N, Y = map(int, raw_input().split())
SolveABC085C(N, Y)

Measured memory_bytes: 2820
import java.util.Scanner;
public class Main {
	Scanner in = new Scanner(System.in);
	public static void main(String[] args) {
		new Main();
	}
	public Main() {
		new AOJ0041().doIt();
	}
	
	class AOJ0041{
		char[] op;
		char[] hyou;
		void doIt(){
			hyou = new char[3];
			hyou[0] = '+';
			hyou[1] = '-';
			hyou[2] = '*';
			op = new char[4];
			int num[] = new int[4];
			while(true){
				num[0] = in.nextInt();
				num[1] = in.nextInt();
				num[2] = in.nextInt();
				num[3] = in.nextInt();
				int sum = num[0]+num[1]+num[2]+num[3];
				if(sum == 0)return;				
				boolean sw = false;
				l1:
				for(int i=0;i<4;i++)for(int s=0;s<4;s++)for(int j=0;j<4;j++)for(int k=0;k<4;k++){
					if(i == s || i == j || i == k || s == j || s == k || j == k || sw)continue;
					int a = num[i];
					int b = num[s];
					int c = num[j];
					int d = num[k];
					if(patternA(a, b, c, d)){
//						System.out.println("A");
						System.out.println("((("+ a + " " + op[0] + " " + b + ") " + op[1] + " " + c + ")" + " " + op[2] + " " + d + ")");
						sw = true;
						break l1;
					}
					if(patternB(a, b, c, d)){
//						System.out.println("B");
						System.out.println("(("+ a + " " + op[0] + " (" + b + " " + op[1] + " " + c + "))" + " " + op[2] + " " + d + ")");
						sw = true;
						break l1;
					}
					if(patternC(a, b, c, d)){
//						System.out.println("C");
						System.out.println("("+ a + " " + op[0] + " " + b + ") " + op[1] + " (" + c  + " " + op[2] + " " + d + ")");
						sw = true;
						break l1;
					}
				}
				if(!sw)System.out.println("0");
//				System.out.println("END");
			}
		}
		
		boolean patternA(int a,int b,int c,int d){//(((a + b) + c) + d)
			for(int i=0;i<3;i++)for(int s=0;s<3;s++)for(int j=0;j<3;j++){
				int result = calc(calc(calc(a, b, i),c,s),d,j);
				if(result == 10){
					op = new char[3];
					op[0] = hyou[i];
					op[1] = hyou[s];
					op[2] = hyou[j];
					return true;
				}
			}
			return false;
		}
		
		boolean patternB(int a,int b,int c,int d){//((a + (b + c)) + d)
			for(int i=0;i<3;i++)for(int s=0;s<3;s++)for(int j=0;j<3;j++){
				int result = calc(calc(a,calc(b, c, s),i),d,j);
				if(result == 10){
					op[0] = hyou[i];
					op[1] = hyou[s];
					op[2] = hyou[j];
					return true;
				}
			}
			return false;
		}
		
		boolean patternC(int a,int b,int c,int d){//(a + b) + (c + d)
			for(int i=0;i<3;i++)for(int s=0;s<3;s++)for(int j=0;j<3;j++){
				int result = calc(calc(a, b, i),calc(c, d, j),s);
				if(result == 10){
					op[0] = hyou[i];
					op[1] = hyou[s];
					op[2] = hyou[j];
					return true;
				}
			}
			return false;
		}
		
		int calc(int a,int b,int op){
			if(op == 0)return a+b;
			else if(op == 1)return a-b;
			else return a*b;
		}
		
	}
	
}

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

int main()
{
	int n;
	cin >>n;
	for (int i = 1; ; i++){
		if (i * i == n){
			cout <<n <<endl;
			break;
		}
		if (i * i > n){
			cout <<(i - 1)*(i - 1) <<endl;
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 256
k,a,b = map(int,input().split())

bis = 0
if b-a <= 2 or k <= a-1:
    bis += k+1
else:
    bis += a + (b-a)*((k-a+1)//2)
    if (k-a+1) % 2 == 1:
        bis += 1

print(bis)

Measured memory_bytes: 3060
while True:
    h, w = map(int, input().split())
    if h == 0 and w == 0:
        break
    for j in range(h):
        for i in range(w):
            if (i + j) % 2 == 0:
                print("#", end="")
            else:
                print(".", end="")
        print()
    print()



Measured memory_bytes: 7000
#include<iostream>
using namespace std;
int main(){
  float N,b = 0.000000000,c = 0.000000000;
  cin >> N;
  for(int i = 1; i <= N; i++){
    if(i % 2 != 0){
      c += 1;
    }
  }
  b = c/(float)N;
  printf("%.10f",b);

}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline


class UnionFind():
    # 作りたい要素数nで初期化
    # 使用するインスタンス変数の初期化
    def __init__(self, n):
        self.n = n
        # root[x]<0ならそのノードが根かつその値が木の要素数
        # rootノードでその木の要素数を記録する
        self.root = [-1]*(n+1)
        # 木をくっつける時にアンバランスにならないように調整する
        self.rnk = [0]*(n+1)

    # ノードxのrootノードを見つける
    def Find_Root(self, x):
        if(self.root[x] < 0):
            return x
        else:
            # ここで代入しておくことで、後の繰り返しを避ける
            self.root[x] = self.Find_Root(self.root[x])
            return self.root[x]
    
    # 木の併合、入力は併合したい各ノード
    def Unite(self, x, y):
        # 入力ノードのrootノードを見つける
        x = self.Find_Root(x)
        y = self.Find_Root(y)
        # すでに同じ木に属していた場合
        if(x == y):
            return 
        # 違う木に属していた場合rnkを見てくっつける方を決める
        elif(self.rnk[x] > self.rnk[y]):
            self.root[x] += self.root[y]
            self.root[y] = x
        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            # rnkが同じ（深さに差がない場合）は1増やす
            if(self.rnk[x] == self.rnk[y]):
                self.rnk[y] += 1
    
    # xとyが同じグループに属するか判断
    def isSameGroup(self, x, y):
        return self.Find_Root(x) == self.Find_Root(y)

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


def main():
    N, M = map(int, input().split())
    A = []
    B = []
    for _ in range(M):
        a, b = map(int, input().split())
        A.append(a)
        B.append(b)
    
    T = UnionFind(N)
    ans = [0]*M
    ans[M-1] = N*(N-1)//2
    for i in reversed(range(M-1)):
        a = A[i+1]
        b = B[i+1]
        if T.isSameGroup(a, b):
            ans[i] = ans[i+1]
        else:
            ans[i] = ans[i+1] - T.Count(a) * T.Count(b)
        T.Unite(a, b)

    for i in range(M):
        print(ans[i])


if __name__ == '__main__':
    main()

Measured memory_bytes: 97372
def third_points(points)
  point_one = {x: (points[1][:x] + 2.0 * points[0][:x]) / 3.0, y: (points[1][:y] + 2.0 * points[0][:y]) / 3.0}
  point_two = {x: (points[0][:x] + 2.0 * points[1][:x]) / 3.0, y: (points[0][:y] + 2.0 * points[1][:y]) / 3.0}
  [point_one, point_two]
end

def triangle(points)
  x = points[0][:x] + (points[1][:x] - points[0][:x]) / 2.0 - (points[1][:y] - points[0][:y]) * Math.sqrt(3.0) / 2.0
  y = points[0][:y] + (points[1][:y] - points[0][:y]) / 2.0 + (points[1][:x] - points[0][:x]) * Math.sqrt(3.0) / 2.0
  {x: x, y: y}
end
def koch(points, n)
  return points if n == 0
  used_points = koch(points, n - 1)
  new_points = []
  used_points.each_cons(2){|two_points|
    thirds = third_points(two_points)
    try = triangle(thirds)
    new_points.push(two_points[0], thirds[0], try, thirds[1])
  }
  new_points.push(points[-1])
  new_points
end

n = gets.to_i
koch_points = koch([{x: 0.0, y: 0.0}, {x: 100.0, y: 0.0}], n)
koch_points.each do |point|
  puts("#{sprintf("%.8f", point[:x])} #{sprintf("%.8f", point[:y])}")
end

Measured memory_bytes: 9700
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
import java.lang.Math;

public class Main {
    public static void main(String[] args) {
        FS reader = new FS();
        // write reader
        int N = reader.nextInt();
        double[] P = new double[N];
        for (int i=0; i<N; i++) {
            P[i] = Double.parseDouble(reader.next());
        }
        double[][] dp = new double[N+1][N+1];
        dp[0][0] = 1.0;
        for (int i=0; i<N; i++) {
            for (int j=0; j<=i; j++) {
                dp[i+1][j+1] += dp[i][j]*P[i];
                dp[i+1][j]   += dp[i][j]*(1.0-P[i]);
            }
        }

        double ans = 0.0;
        for (int i=(N+1)/2; i<=N; i++) {
            ans += dp[N][i];
        }
        System.out.println(ans);
    }

    // Read Class
    static class FS {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;
        private boolean hasNextByte() {
            if (ptr < buflen) {
                return true;
            } else {
                ptr = 0;
                try {
                    buflen = in.read(buffer);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (buflen <= 0) {
                    return false;
                }
            }
            return true;
        }
    
        private int readByte() { return hasNextByte() ? buffer[ptr++] : -1;}
        private boolean isPrintableChar(int c) {return 33 <= c && c <= 126;}
        private void skipUnprintable() {while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
    
        public boolean hasNext() { skipUnprintable(); return hasNextByte();}
        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while(isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }
        public int nextInt() {
            return (int)nextLong();
        }
        public long nextLong() {
            if (!hasNext()) throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) {
                throw new NumberFormatException();
            }
            while(true) {
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                } else if(b == -1 || !isPrintableChar(b)) {
                    return minus ? -n : n;
                } else {
                    throw new NumberFormatException();
                }
                b = readByte();
            }
        }
    }
}



Measured memory_bytes: 132820
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int A[] = new int[N];
    for(int i=0;i<N;i++){
      A[i] = sc.nextInt();
    }
    trace(A,N);
    insertion(A,N);
  }
  public static void trace(int A[],int N){
    for(int i = 0;i<N;i++){
      if(i>0){
        System.out.print(" ");
      }
      System.out.print(A[i]);
    }
    System.out.print("\n");
  }
  public static void insertion(int A[],int N){
    int j, i, v;
    for(i=1;i<N;i++){
      v = A[i];
      j = i - 1;
      while(j >= 0 && A[j] > v){
        A[j+1] = A[j];
        j--;
      }
      A[j+1] = v;
      trace(A,N);
    }
  }
}



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

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

  vector<int> vec(N);

  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }

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

  int before = vec.at(0);
  int ans = 1;

  for (int i = 0; i < N; i++) {
    if (vec.at(i) < before) {
      before = vec.at(i);
      ans++;
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
N,K = map(int,input().split())
x = list(map(int,input().split()))

ans = 1e12
    
for i in range(N-K+1):
    a = abs(x[i])+abs(x[i]-x[i+K-1])
    b = abs(x[i+K-1]) + abs(x[i]-x[i+K-1])
    ans = min(ans,min(a,b))

print(ans)

Measured memory_bytes: 14564
#include <iostream>
#include <bitset>
#include <fstream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
//#include <boost/multiprecision/cpp_int.hpp>

const double EPS = (1e-10);


using namespace std;
using Int = long long;
//using namespace boost::multiprecision;

const Int MOD = 1000000007;

Int mod_pow(Int x, Int n) {
    Int res = 1;
    while(n > 0) {
        if(n & 1) res = (res * x) % MOD; //ビット演算(最下位ビットが1のとき)
        x = (x * x) % MOD;
        n >>= 1; //右シフト(n = n >> 1)
    }
    return res;
}

//最大公約数
template<typename T>
T gcd(T a, T b) {
    return b != 0 ? gcd(b, a % b) : a;
}

//最小公倍数
template<typename T>
T lcm(T a, T b) {
    return a * b / gcd(a, b);
}

long long ABC[3][1005];
vector<long long> ans(3000000);
vector<long long> AB_best(1000000);



int main(){

    int xyzk[4];
    for (int i = 0; i < 4; i++) {
        cin >> xyzk[i];
    }
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < xyzk[i]; j++) {
            cin >> ABC[i][j];
        }
    }
    int cnt = 0;
    for (int i = 0; i < xyzk[0]; i++) {
        for (int j = 0; j < xyzk[1]; j++) {
            AB_best[cnt++] = ABC[0][i] + ABC[1][j];
        }
    }
    sort(AB_best.begin(), AB_best.end(), greater<long long>());
    cnt = 0;
    for (int i = 0; (i < AB_best.size() && i < 3000); i++) {
        for (int j = 0; j < xyzk[2]; j++) {
            ans[cnt++] = AB_best[i] + ABC[2][j];
        }
    }
    sort(ans.begin(), ans.end(), greater<long long>());
    for (int i = 0; i < xyzk[3]; i++) {
        cout << ans[i] << endl;
    }
    return 0;
}



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

#define Bye return 0
#define ll long long

using namespace std;

void solve(){
    ll a, b, c, d; cin>>a>>b>>c>>d;

    ll maxi = max({a*c, a*d, b*c, b*d});

    cout<<maxi<<endl;
}

int main(){
    solve();
    Bye;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
 
int main() {

  int N;
  cin >> N;
  string S;
  cin >> S;
  
  int e=N/2;
  int x=0;
  for(int i=0; i<e; i++){
    if(S.at(i)==S.at(e+i)){
      x++;
    }
  }
  
  if(N%2==0 && x==e){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
h,w=map(int,input().split())
a=[list(map(int,list(input().split()))) for _ in range(h)]

ans=[]
for i in range(h):
    for j in range(w-1):
        if a[i][j]%2==1:
            a[i][j+1]+=1
            ans.append([i+1,j+1,i+1,j+2])

for i in range(h-1):
    if a[i][w-1]%2==1:
        a[i+1][w-1]+=1
        ans.append([i+1,w,i+2,w])
print(len(ans))
for i in ans:
    print(*i)

Measured memory_bytes: 30332
#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>
#define IP pair<int,P>
#define PI pair<P,int>
#define PP pair<P,P>
#define Yes(f){cout<<(f?"Yes":"No")<<endl;}
#define YES(f){cout<<(f?"YES":"NO")<<endl;}


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


    int n,k;
    cin>>n>>k;
    int ans=0;
    while(n){
        ans++;
        n/=k;
    }

    cout<<ans<<endl;

}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <limits.h>
#include <math.h>
int acs(const void *a, const void *b){return *(int*)a - *(int*)b;} /* 1,2,3,4.. */
int des(const void *a, const void *b){return *(int*)b - *(int*)a;} /* 8,7,6,5.. */
int cmp_char(const void *a, const void *b){return *(char*)a - *(char*)b;} /* a,b,c,d.. */
int cmp_str(const void *a, const void *b){return strcmp(*(const char **)a, *(const char **)b);} /* aaa,aab.. */
#define min(a,b) (a < b ? a: b)
#define max(a,b) (a > b ? a: b)
#define rep(i, l, r) for (int i = l; i < r; i++)
#define MAX 100001
#define MOD 1000000007

typedef long long int lli;

int main(void) {
  char s[101];
  lli k;
  scanf("%s %lld", s, &k);

  int n = strlen(s);
  lli one;
  rep(i, 0, n) {
    if ( s[i] != '1' ) break;
    one++;
  }
  if ( one >= k ) printf("1\n");
  else printf("%c\n", s[one]);
  return 0;
}


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

using namespace std;
 
int main() {
    string a;cin>>a;
    if(a == "Sunny") cout<<"Cloudy";
    else if(a == "Cloudy") cout<<"Rainy";
    else cout << "Sunny";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <numeric>
#include "math.h"
#include <string>
#include <vector>

using namespace std;






// 81
//*
int main() {

	int n,cnt=0;
	cin >> n;
	
	for (int i = 1; i < 10; i++) {
		for (int j = 1; j < 10; j++) {
			if (i * j != n) {
				continue;
			}
			cout << "Yes" << endl;
			return 0;

		}
	}

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


}
//*/

Measured memory_bytes: 256