akhauriyash/Code-Regression huggingface dataset:
import sys
from collections import deque

sys.setrecursionlimit(10**5)

def solve():
    while 1:
        w, h = map(int, sys.stdin.readline().split())

        if w == h == 0:
            return

        room = [[int(j) for j in sys.stdin.readline().split()] for i in range(h)]

        cnt = 0

        for i in range(h):
            for j in range(w):
                if room[i][j]:
                    cnt += 1
                    bfs(w, h, room, i, j)

        print(cnt)

dx = (1, 0, -1, 0, 1, 1, -1, -1)
dy = (0, 1, 0, -1, 1, -1, 1, -1)

def bfs(w, h, room, i, j):
    room[i][j] = 0
    q = deque([(i, j)])

    while q:
        ci, cj = q.popleft()

        for k in range(len(dx)):
            ni = ci + dy[k]
            nj = cj + dx[k]

            if 0 <= ni < h and 0 <= nj < w and room[ni][nj]:
                room[ni][nj] = 0
                q.append((ni, nj))

    return

def dfs(w, h, room, i, j):
    if i < 0 or i >= h or j < 0 or j >= w or (not room[i][j]):
        return

    room[i][j] = 0

    dfs(w, h, room, i + 1, j)
    dfs(w, h, room, i - 1, j)
    dfs(w, h, room, i, j + 1)
    dfs(w, h, room, i, j - 1)
    dfs(w, h, room, i + 1, j + 1)
    dfs(w, h, room, i + 1, j - 1)
    dfs(w, h, room, i - 1, j + 1)
    dfs(w, h, room, i - 1, j - 1)

if __name__ == '__main__':
    solve()

Measured memory_bytes: 7924
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;
constexpr ll INF = (1LL << 55);

int main(){
  string s, t;
  cin >> s >> t;
  int n = sz(t);
  s += s;
  for (int i = 0; i < n; i++) {
    if (s.substr(i,n) == t) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
} 

Measured memory_bytes: 256
//author: zekigurbuz (Zeki Gurbuz) 2020
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;

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

#define mp make_pair
#define pb push_back
#define lb lower_bound
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second

const int N = 1e5 + 10;
const int M = 1e9 + 7;

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

template<class T>void ckmin(T&a,T b){a=min(a,b);}
template<class T>void ckmax(T&a,T b){a=max(a,b);}




void solve() {
	ll n, k;
	cin >> n >> k;
	unordered_set<ll> s;
	ll ans = 1e18;
	ll sub = n / k;
	ans = min({n - sub * k, abs(n - (sub + 1) * k), ans});
	cout << ans << endl;
}

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

	int t = 1;
    //cin >> t;
	for (int i = 1; i <= t; ++i) {
		solve();
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<algorithm>
using namespace std;
#define ll long long
//int l[n+1];
int main() {
  int x,y;
  cin >> x>>y;
  int a;
  
  if((4*x-y)/2 >=0 && (4*x-y)%2 ==0 && (y-2*x) >=0) {
    cout << "Yes";
  }else{cout << "No";}
    
}

Measured memory_bytes: 3632
package main 

import (
  "fmt"
)

func main() {
  var n int
  fmt.Scan(&n)
  
  a := make([]int ,n)
  for i := 0; i < n; i++ {
    fmt.Scan(&a[i])
  }

  ans := make([]int, n)
  for i := 0; i < n; i++ {
    if a[i] != 0{
    ans[a[i]-1]++
    }
  }

  for i := 0; i < n; i++ {
    fmt.Println(ans[i])
  }
}

Measured memory_bytes: 7960
#include<bits/stdc++.h>
using namespace std;
int n;
long long dp[100007][3];
int read()
{
	int num = 0, f = 1;
	char c = getchar();
	while ((c < '0' || c>'9') && c != '-')c = getchar();
	if (c == '-')f = -1, c = getchar();
	while (c < '0' || c>'9')c = getchar();
	while (c >= '0' && c <= '9')num = num * 10 + c - '0', c = getchar();
	return num * f;
}
int main()
{
	n = read();
	dp[0][0] = 0, dp[0][1] = dp[0][2] = -1e18;
	for (int i = 1; i <= n; i++)
	{
		int v = read();
		dp[i][0] = max(dp[i - 1][0], dp[i - 1][1]) + v;
		dp[i][1] = max(dp[i - 1][1], dp[i - 1][2]) - v;
		dp[i][2] = dp[i - 1][2] + v;
		if (v < 0)
		{
			dp[i][2] = max(dp[i][2], dp[i][1]);
			dp[i][1] = max(dp[i][1], dp[i][0]);
		}
	}
	cout << max(dp[n][0], max(dp[n][1], dp[n][2])) << endl;
	return 0;
}

Measured memory_bytes: 2560
// {{{
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
// }}}

using ll = long long;

int N;
string S;

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

    int ans = 0;
    for (int i = 0; i < 1000; ++i) {
        int d[3] = {i/100, i/10%10, i%10};
        int s = 0;
        for (int j = 0; j < N; ++j) {
            if (s < 3 && d[s] == (S[j] - '0')) {
                ++s;
            }
        }
        if (s == 3) ++ans;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 384
a, b, c = map(int, input().split())
if a<=b and a<=c:
    if b<=c:
        print(a, b, c)
    else:
        print(a, c, b)
elif b<=c and b<=a:
    if c<=a:
        print(b, c, a)
    else:
        print(b, a, c)
else:
    if b<=a:
        print(c, b, a)
    else:
        print(c, a, b)



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

#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
// #define int long long
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using ul = unsigned long;

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

int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { return a * b / GCD(a, b); }

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

inline bool inside(int y, int x, int H, int W) {
    return (y >= 0 && x >= 0 && y < H && x < W);
}

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int dp[3005][3005];

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  int n,t; cin>>n>>t;
  vector<pii> ab(n);
  rep(i,n) cin>>ab[i].first>>ab[i].second;
  vsort(ab);
  int ans=0;
  rep(i,n){
    rep(j,t){
      if(j+ab[i].first<t) chmax(dp[i+1][j+ab[i].first],dp[i][j]+ab[i].second);
      chmax(dp[i+1][j],dp[i][j]);
      chmax(ans,dp[i][j]+ab[i].second);
    }
  }
  cout<<ans<<endl;
  return 0;
}


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

using namespace std;

int main() {
    int h, w, l, r;
    cin >> h >> w;
    multiset<int> ms; // end - start
    map<int, int> s; // ending, starting
    for(int i = 1; i <= w; i++) { s.insert({i, i}); ms.insert(0); }
    for(int i = 1; i <= h; i++) {
        cin >> l >> r;
        vector<int> to_remove;
		auto it = s.lower_bound(l);
        for(; it != s.end() && (it->first) <= r; it++) {
            to_remove.push_back(it->first);
        }
        int last = -1;
        for(auto x : to_remove) {
            ms.erase(ms.find(x - s[x]));
            last = s[x];
            s.erase(x);
        }
        if(r < w && s.find(r+1) == s.end() && last != -1) {
            s.insert({r+1,last});
            ms.insert(r+1-last);
        }
        /*cout << "set" << endl;
        for(auto x : s) cout << x.first << ' ' << x.second;
        cout << endl;
        cout << "multiset" << endl;
        for(auto x : ms) cout << x << ' ';
        cout << endl;*/
        if(ms.empty()) cout << "-1" << endl;
        else cout << i + *ms.begin() << endl;
    }
    
    return 0;
}

Measured memory_bytes: 22340
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <utility>
#include <functional>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <iomanip>
#include <numeric>
#include <complex>
#include <cassert>
#include <climits>

using namespace std;
using i64 = int64_t;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const int INF = (1<<30);
const i64 INFL = (1LL<<62);
const i64 MOD = 1000000007;
template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<class T> i64 mod_pow(i64 a, i64 n, T mod) { mod=(i64)mod; i64 res=1, p=a%mod; while(n){ if(n&1) res=res*p%mod; p=p*p%mod; n>>=1; } return res; }
void print() { std::cout << std::endl; }
template <typename T, typename... A> void print(const T& first, const A&... rest) { cout << sizeof...(rest) << endl; std::cout << first; if (sizeof...(rest)) std::cout << " "; print(rest...); }
template <typename... A> void print(const A&... rest) { print(rest...); }
template <typename A> void print(const std::vector<A>& v) { std::for_each(v.begin(), v.end(), [](A x) { std::cout << x << " "; }); std::cout << std::endl; }

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int m;
    cin >> m;
    // vector<int> d(m);
    // vector<int> c(m);
    vector<pair<i64, i64>> dc;
    i64 digitsum = 0;
    i64 ketasu = 0;
    rep(i, m){
        i64 b, c;
        cin >> b >> c;
        dc.push_back({b, c});
        digitsum += (b * c);
        ketasu += c;
    }
    cout << (digitsum - 1) / 9 + ketasu - 1 << endl;    

    return 0;
}

Measured memory_bytes: 6000
#include <stdio.h>

#define N 100

void trace(int A[], int n){
  int i;
  for ( i = 1; i <= n; i++ ){
    if ( i > 1 ) printf(" ");
    printf("%d", A[i]);
  }
  printf("\n");
}

int main(void)
{
  int A[N+1],i,j,key,n,count=0,mini,cou;
  scanf("%d",&n);
  for(i=1 ; i<n+1 ; i++)
    {
      scanf("%d",&A[i]); 
    }
  for(i=0 ; i<=n ; i++)
    {
      mini = i;
      cou=0;
      for(j=i ; j<=n ; j++)
	{
	  if(A[j] < A[mini])
	    {
	      mini = j;
	      cou=1;
	    }
	}
      if(cou==1)
	{
	  key = A[i];
	  A[i] = A[mini];
	  A[mini] = key;
	  count++;
	}
    }
  trace(A, n);
  printf("%d\n",count);
  return 0;
}

Measured memory_bytes: 604
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#define maxn 30
#define ll long long int
#define rep(i, l, r) for (register int i = l; i <= r; i++)
#define per(i, r, l) for (register int i = r; i >= l; i--)
using namespace std;

int num[maxn];
int ct = 0;

int dp[maxn][2];
bool vis[maxn][2];
int DP(int pos, bool op){
    if (pos == ct + 1) return 0;
    if (vis[pos][op]) return dp[pos][op];
    vis[pos][op] = 1;
    int& ans = dp[pos][op];
    if (op){
        rep(i, 0, num[pos] - 1) ans = max(ans, DP(pos + 1, 0) + i);
        ans = max(ans, DP(pos + 1, 1) + num[pos]);
        return ans;
    }
    else return ans = (ct + 1 - pos) * 9;
}

int main(){
    ll x;
    scanf("%lld", &x);
    while (x){
        num[++ct] = x % 10;
        x /= 10;
    }
    reverse(num + 1, num + 1 + ct);
    printf("%d", DP(1, 1));
    return 0;
}

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

int main()
{
	int n, max = -1000000000, min;
	cin >> n;
	cin >> min;
	int x;

	for (int i = 1; i < n; i++) {
		cin >> x;
		max = (x - min) > max ? x - min : max;
		min = min > x ? x : min;
	}
	cout << max << "\n";
	return 0;
}

Measured memory_bytes: 1168
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
 
#define FOR(idx, begin, end) for(int idx = (begin); idx < (end); ++idx)
#define DMP(x) cerr << #x << ": " << x << "\n"
 
using namespace std;
typedef long long lint;
const int MOD = 1000000007;
 
int main() {
 
	cin.tie(0);
 
	int N, M;
	cin >> N >> M;
 
	vector<int> visited(N, 0);
 
	vector<int> a(M), b(M);
	FOR(i, 0, M) cin >> a[i] >> b[i];
 
	vector<vector<int>> path(N, vector<int>(N, 0));
	FOR(i, 0, M) {
		path[a[i] - 1][b[i] - 1] = 1;
		path[b[i] - 1][a[i] - 1] = 1;
	}
 
	int ans = 0;
 
	stack<pair<int, vector<int>>> node;
	node.push({0, visited});
 
	while (!node.empty()) {
		
		auto now = node.top();
		now.second[now.first] = 1;
		node.pop();
 
		FOR(i, 0, N) {
			if (now.second[i] == 0 && path[now.first][i] == 1) {
 
				node.push({i, now.second});
			}
		}
 
		FOR(i, 0, N) {
 
			if (now.second[i] == 0) break;
			if (i == N - 1) ans++;
		}
	
	}
 
	cout << ans;
 
	return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007

int main() {

  int N;
  cin >> N;

  vector<vector<int>> G(N,vector<int>(0));
  vector<int> c(N);
  long long sum = 0;
  for(int i = 0;i < N-1;i++) {
    int a,b;
    cin >> a >> b;
    a--; b--;
    G[a].push_back(b);
    G[b].push_back(a);
  } 

  for(int i = 0;i < N;i++) cin >> c.at(i);
  sort(c.rbegin(),c.rend());

  queue<int> Q;
  vector<bool> seen(N,false);
  vector<int> ans(N);
  ans[0] = c[0];
  Q.push(0);
  seen[0] = true;
  int now = 1;
  
  while(!Q.empty()) {
    int q = Q.front();
    Q.pop();
    for(int v:G[q]) {
      if(seen[v]) continue;
      sum += c[now];
      ans[v] = c[now];
      now++;
      Q.push(v);
      seen[v] = true;
    }
  }

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


Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>
int compare_int(const void *a, const void *b){
    return *(int*)b - *(int*)a;
}
int main(void){
    int n, k, num[200000+5]={0};
    scanf("%d %d", &n, &k);
    for(int i=0; i<n; i++){
        int a;
        scanf("%d", &a);
        num[a-1]++;
    }
    
    int cnt=0;
    for(int i=0; i<200000; i++){
        if(num[i]>0)cnt++;
    }
    
    int ans=0;
    if(k<cnt){
        qsort(num, 200000, sizeof(int), compare_int);
        // for(int i=0; i<5; i++)printf("%d ", num[i]);
        for(int i=cnt-1; i>k-1; i--)ans+=num[i];
    }
    printf("%d\n", ans);
    return 0;
}


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

    int Sx,Sy,Tx,Ty,V,H;
    string S;

    cin >> Sx>>Sy>>Tx>>Ty;

    H=Tx-Sx;
    V=Ty-Sy;

    for(int i=1;i<=V;i++){
        S+="U";
    }
    for(int i=1;i<=H;i++){
        S+="R";
    }

    for(int i=1;i<=V;i++){
        S+="D";
    }
    for(int i=1;i<=H;i++){
        S+="L";
    }

    S+="LU";

    for(int i=1;i<=V;i++){
        S+="U";
    }
    for(int i=1;i<=H;i++){
        S+="R";
    }

    S+="RDRD";

    for(int i=1;i<=V;i++){
        S+="D";
    }
    for(int i=1;i<=H;i++){
        S+="L";
    }

    S+="LU";

    cout << S<<endl;

    return 0;
}

Measured memory_bytes: 256
ans = []
while 1:
    N = int(input())
    if N == 0:
        break
    *A, = map(int, input().split())
    s = sum(A)
    cnt = 0
    for a in A:
        if a*N <= s:
            cnt += 1
    ans.append(cnt)
print(*ans, sep='\n')



Measured memory_bytes: 6608
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <utility>

using namespace std;
typedef long long ll;

inline int getint(){
  char c; int res = 0, sig = 1;
  for(c = getchar();c < '0' || c > '9';c = getchar()) if(c == '-') sig = -1;
  for(;c >= '0' && c <= '9';c = getchar()) res = res * 10 + (c - '0');
  return res * sig;
}

int main(){
  int n = getint(), x = getint(), pos = 0;
  int res = 1;
  for(int i = 1;i <= n;i++){
    pos += getint();
    res += (pos <= x);
  }
  printf("%d\n",res);
  return 0;
}


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

int main(){
    int K,N;
    cin >> K >> N;
    int A[N+1] = {};
    int m = 0;
    rep(i,N){
        cin >> A[i+1];
        m = max(m,A[i+1] - A[i]);
    }
    m = max(m,K-A[N]+A[1]);
    cout << K - m << endl;


    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include<stdio.h>
#include<string.h>
#include <iostream>
#include<bits/stdc++.h>
#include<stdio.h>
#include<string.h>
#include <algorithm>
#include <vector>
#include<iterator>
using namespace std;
int main()
{
    int l,k,c=0,i=0;
    string s,t;
    cin>>s;
    cin>>t;
    l=s.size();
    k=t.size();
    while(l>0)
    {
        if(s[i]==t[i])
        {
            c++;
        }
        l--;
        i++;
    }
    cout<<c<<endl;
    return 0;
}









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

using namespace std;

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

    int W, H, x, y;
    cin >> W >> H >> x >> y;

    double area = (double)W * H;
    cout.precision(17);
    cout << fixed << area / 2. << " " << (x == W / 2. && y == H / 2.) << "\n";

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <bitset>
#include <functional>

#define FOR_LT(i, beg, end) for (int i = beg; i < end; i++)
#define FOR_LE(i, beg, end) for (int i = beg; i <= end; i++)
#define FOR_DW(i, beg, end) for (int i = beg; end <= i; i--)

using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int n, x; cin >> n >> x;
	vector<int> ls(n);
	for (auto& l : ls) {
		cin >> l;
	}

	int ans = 1;
	int y = 0;
	FOR_LT(i, 0, n) {
		y += ls[i];
		if (y <= x) ans++;
		else break;
	}

	cout << ans << endl;

	return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long

const long long MOD = 1000000007;

int main(){
  int n,a;
  int ans = 0;
  cin >> n;
  int m = n+1;
  
  rep(i,n){
    cin >> a;
    if(a<m){
      m=a;
      ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(p,a,b)    for(int p=a;p<b;p++)
#define INF 0x3f3f3f3f
#define N 100007


int main() {
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("o2.txt", "w", stdout);
    #endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    int n,a,b;
    cin>>n>>a>>b;
    for(int i=a ; i<=b ; i++)if(i%n==0){cout<<"OK";return 0;}
    cout<<"NG";
    return 0;
}

Measured memory_bytes: 3616
#include<stdio.h>
#include<math.h>
int arr[1000000];
int main()
{
    int k,n,c;

    while(scanf("%d",&n)!=EOF)
    {
       c=0;
    for(k=1;k<=n;k++)
    arr[k]=k;

    for(k=2;k<=sqrt(n);k++)
    Crossout(arr,k,n);
    for(k=2;k<=n;k++)
    if(arr[k]!=1)
    c++;
    printf("%d\n",c);

    }


    return 0;
}
int Crossout(int a[],int k,int n)
{
    int l;
    if(a[k]==1)
        return;
    for(l=2*k;l<=n;l+=k)
        a[l]=1;
    return ;
}

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

// ABC-084-D

// 累積和
struct cumulative_sum {
    using lint = long long int;
    int sz;
    // data[i]:元の数列
    vector<lint> data;
    // cum[i]:[0,i)の和
    vector<lint> sum;
    // 要素数を指定して初期化
    cumulative_sum(const int _sz) : sz(_sz) {
        data.assign(sz, 0);
        sum.assign(sz + 1, 0);
    }
    lint& operator[](const int k) {
        return data[k];
    }
    // dataに基づいてsumを構築
    void build() {
        for (int i = 0; i < sz; i++) sum[i + 1] = sum[i] + data[i];
    }
    // [a,b)の和を求める
    lint query(const int a, const int b) {
        return sum[b] - sum[a];
    }
};

int q;

//エラトステネスの篩
vector<bool> eratosthenes_sieve(int n) {
    vector<bool> res(n + 1, true);
    res[0] = res[1] = false;
    for (int i = 2; i * i <= n; i++) {
        if (res[i]) {
            for (int j = i; i * j <= n; j++) res[i * j] = false;
        }
    }
    return res;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    vector<bool> p = eratosthenes_sieve(1e+5);
    cumulative_sum cum(1e+5 + 1);
    for (int i = 0; i <= 1e+5; i++) {
        if (i % 2 == 1 && p[i] && p[(i + 1) / 2]) {
            cum[i] = 1;
        } else {
            cum[i] = 0;
        }
    }
    cum.build();
    cin >> q;
    for (int i = 0; i < q; i++) {
        int l, r;
        cin >> l >> r;
        r++;
        cout << cum.query(l, r) << endl;
    }
}

Measured memory_bytes: 2176
S1 = input()
S2 = input()
arr1 = [i for i in range(len(S1) + 1)]
arr2 = [1 for _ in range(len(S1) + 1)]

for i, s2 in enumerate(S2):
  arr2[0] = arr1[0] + 1
  for j in range(1, len(S1) + 1):
    if s2 == S1[j - 1]:
      cost = 0
    else:
      cost = 1
      
    arr2[j] = min(arr2[j - 1] + 1,
                  arr1[j] + 1,
                  arr1[j - 1] + cost)
  arr1, arr2 = arr2, arr1
  
print(arr1[-1])


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

int main(){
    int n, m; cin >> n >> m;
    vector<vector<int>> vec(m);
    
    for(int i=0; i < m; i++){
        int k; cin >> k;
        vec[i].resize(k);
        for(int j=0; j<k; j++){
            cin >> vec[i][j];
            --vec[i][j];
        }
    }

    vector<int> p(m);
    for(int i=0; i<m; i++) cin >> p[i];

    int ans = 0;
    for(int i=0; i < (1 << n); i++){
        bool ok =true;
        for(int j=0; j<m; j++){
            int c=0;
            for(int id : vec[j]){
                if((i >> id) & 1){
                    c++;
                }
            }
            c=c%2;
            if(c!= p[j]) ok = false;
        }
        if(ok) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3616
import java.util.Scanner;

public class Main{ 
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)) {
			
			while(sc.hasNext()) {
				int h = sc.nextInt();
				int w = sc.nextInt();
				if(h+w==0)break;
				
				int taikaku = h*h+w*w;
				int min = 6000000;
				int ansh = 151;
				int answ = 151;
				
				for(int i=1;i<150;i++) {
					for(int j=i+1;j<=150;j++) {
						int tai = i*i+j*j;
						if(tai>=taikaku) {
							if(tai==taikaku && h>=i)
								continue;
							if(min > tai) {
								min = tai;
								ansh = i;
								answ = j;
							}

						}
					}
				}
				
				System.out.println(ansh +" "+answ);
			}
		}
	}
}



Measured memory_bytes: 27320
/**
 * Created by karayuu on 2018/04/14
 */

fun main(args: Array<String>) {
    val (a, b, c) = readLine()!!.split(" ").map { it.toInt() }

    val list = readLine()!!.split(" ").map { it.toInt() }

    val right = list.filter { it in c..a }.size
    val left = list.filter { it in 0..c }.size

    println(
            if (right <= left) right else left
    )
}

Measured memory_bytes: 37868
import std.stdio, std.string, std.conv, std.range, std.algorithm;
void main() {
	long n, m, l;
	"%d %d %d\n".readf(&n, &m, &l);
	long[][] a, b;
	foreach (_n; 0..n) a ~= readln.split.to!(long[]);
	foreach (_m; 0..m) b ~= readln.split.to!(long[]);
	foreach (_a; a) {
		long[] c = [];
		foreach (_l; 0..l)
			c ~= iota(m).map!(_m => _a[_m] * b[_m][_l]).sum;
		c.to!(string[]).join(" ").writeln;
	}
}

Measured memory_bytes: 3700
#include <stdio.h>
#include <string.h>
#include <math.h>
#define lop(i, n) for(i=0; i<=n; i++)

int ketasu(int num)
{
        int digit = 0;
        while(num!=0){
                num = num / 10;
                digit++;
        }
        return digit;
}

int main()
{
	int N, cnt=0;
	
	scanf("%d", &N);
	
	while(N>0){
		if((ketasu(N)) % 2 != 0){ cnt++; }
		N--;
	}
	
	printf("%d", cnt);
	
	return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;

int main(){
    static double dp[3000][3000];
    int N;
    cin >> N;
    double p[3000];
    for(int i=1;i<=N;i++) cin >> p[i];

    dp[0][0] = 1.0;
    for(int i=1;i<=N;i++) dp[0][i] = 0.0;
    
    for(int i=1;i<=N;i++){
        dp[i][0] = dp[i-1][0] * (1-p[i]);
        for(int j=1;j<=N;j++) dp[i][j] = dp[i-1][j] * (1-p[i]) + dp[i-1][j-1] * p[i];
    }

    double ans = 0.0;
    for(int i=(N+1)/2;i<=N;i++) ans += dp[N][i];

    printf("%.12f\n", ans);

    return 0;
}

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

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

    long long n;
    cin >> n;

    long long ans = 1e18;
    for(long long i = 1; i <= (int)(sqrt(n)); i++){
        if(n % i != 0) continue;
        ans = min(ans, (i + n / i) - 2);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
#include <cstdarg>
#include <sys/time.h>
#include <fstream>
//#include "cout.h"

using namespace std;

#define SZ(x) ((int)x.size())
#define MSET(x,a) memset(x, a, (int)sizeof(x))
#define PB push_back
#define VI vector < int >
#define PII pair < int, int >
#define LL long long
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(), (v).end()
#define FIT(it,v) for (__typeof((v).begin()) it = (v).begin(); it != (v).end(); it++)
#define OUT(A) cout << #A << " = "<< (A) << endl
#define OUT2(A, B) cout << "(" << #A << ", " << #B << ") = (" << (A) << ", "<< (B) << ")" << endl
template<class T> void chmin(T &t, T f) { if (t > f) t = f; } 
template<class T> void chmax(T &t, T f) { if (t < f) t = f; } 

#define present(c, e) ((c).find((e)) != (c).end())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())

int n;
LL a[100010];
char op[100010];
LL dp[100010][3];

void init() {
}

void input() {
	cin >> n;
	REP(i, n) {
		cin >> a[i];
		if (i < n-1) cin >> op[i+1];
	}
}

void solve() {
	REP(i, 100010) REP(j, 3) dp[i][j] = -1e15;
	dp[0][0] = a[0];
	FOR(i, 1, n){
		if(op[i] == '+'){
			dp[i][0] = max({
				dp[i-1][0]+a[i], 
				dp[i-1][1]+a[i], 
				dp[i-1][2]+a[i]
				});
			dp[i][1] = max({
				dp[i-1][1]-a[i], 
				dp[i-1][2]-a[i]
				});
			dp[i][2] = max({
				dp[i-1][2]+a[i]
				});
		}
		else{
			// dp[i][0] = max({
			// 	dp[i-1][0]-a[i], 
			// 	dp[i-1][1]-a[i], 
			// 	dp[i-1][2]-a[i]
			// 	});
			dp[i][1] = max({
				dp[i-1][0]-a[i], 
				// dp[i-1][1]+a[i], 
				// dp[i-1][2]+a[i]
				});
			dp[i][2] = max({
				dp[i-1][1]+a[i], 
				// dp[i-1][2]-a[i]
				dp[i-1][2]+a[i]
				});
		}
	}
	cout << max({dp[n-1][0], dp[n-1][1], dp[n-1][2]}) << endl;
}

int main() {
	init();
    input();
    solve();
	return 0;
}








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

int main() {
    int n;
    cin >> n;
    set<int> a;
    rep(i,n) {
        int ai;
        cin >> ai;
        if (a.count(ai)) a.erase(ai);
        else a.insert(ai);
    }
    cout << a.size() << endl;
    return 0;
}

Measured memory_bytes: 8192
N =list(map(int,input().split()))
if N[0]==7 and N[1]==5 and N[2]==5:
    print("YES")
elif  N[0]==5 and N[1]==7 and N[2]==5:
    print("YES")
elif  N[0]==5 and N[1]==5 and N[2]==7:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3060
import sys
input = sys.stdin.buffer.readline

n, m = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]
cnt = [0] * (m + 1)
cur = [[0, 0] for _ in range(n)]
done = set()
for i in range(n):
	cnt[a[i][0]] += 1
	cur[i][1] = a[i][0]
ans = max(cnt)
for _ in range(m - 1):
	col = cnt.index(max(cnt))
	done.add(col)
	for i in range(n):
		if cur[i][1] == col:
			j = cur[i][0]
			while a[i][j] in done:
				j += 1
			t = a[i][j]
			cur[i] = [j, t]
			cnt[t] += 1
	cnt[col] = 0
	ans = min(ans, max(cnt))
print(ans)

Measured memory_bytes: 4212
/*

Coded and Decoded by : Yash Kapoor

*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

// s.find_by_order(index);
// s.order_of_key(value);

#define ll long long
#define ld long double
#define pb push_back
#define pf push_front
#define mp make_pair
#define pll pair<ll, ll>
#define vl vector<ll>
#define sl set<ll>
#define vll vector<pll>
#define ml map<ll, ll>
#define mll map<pll, ll>
#define all(a) a.begin(), a.end()
#define x first
#define y second
#define sz(x) (ll) x.size()
#define dl '\n'
#define why (ll)1000000007
//#define why         (ll)998244353
#define lp(i, a, b) for (ll i = a; i < b; ++i)
#define lpr(i, a, b) for (ll i = a; i >= b; i--)
#define lpd(i, x) for (auto i : x)
#define ios                                                                                                            \
  ios_base::sync_with_stdio(false);                                                                                    \
  cin.tie(0);                                                                                                          \
  cout.tie(0);

typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

ll inf = 1e18;
ld pi = 3.141592653589;
ll mod = why;
ll fast_power(ll base, ll power, ll mod)
{
  ll result = 1;
  while (power) {
    if (power % 2)
      result = (result * base) % mod;
    base = (base * base) % mod;
    power /= 2;
  }
  return result;
}

ll inverse(ll base, ll mod) { return fast_power(base, mod - 2, mod); }
int test = 1;
void solve() 
{
  ll n, k; cin >> n >> k;
  vl a(n); lp(i,0,n) cin >> a[i];
  ll dp[n];
  dp[0] = 0;
  dp[1] = abs(a[1] - a[0]);
  lp(i,2,n){
    dp[i] = dp[i-1] + abs(a[i-1] - a[i]);
    lp(j,2,k+1){
      if(i - j >= 0)
      dp[i] = min(dp[i],dp[i - j] + abs(a[i - j] - a[i]));
    }
  }
  cout << dp[n - 1] << dl;
}

int main()
{
  // #ifndef ONLINE_JUDGE 
  //   freopen("input.txt", "r", stdin);
  //   freopen("output.txt", "w", stdout);
  // #endif
  ios 
  ll t = 1;
  //cin >> t;
  while (t--) 
  {
    //cout << "Case #" << test++ << ": ";
    solve();
  }
}

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

int n, a, ans;
int main() {
	cin >> n;
	for(int i=1; i<=n; i++) {
		cin >> a;
		if(i%2 && a%2) ans++;
	}
	cout << ans;
	return 0;
}


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

int main()
{
  int d;
  cin >> d;
  vector<vector<int>> c;
  int weight[26];
  for (int k = 0; k < 26; k++)
  {
    weight[k] = 1;
  }
  for (int i = 0; i < d + 1; i++)
  {
    c.push_back(vector<int>());

    for (int j = 0; j < 26; j++)
    {
      int v;
      cin >> v;
      c[i].push_back(v);
    }
  }

  int sum(0);
  for (int i = 0; i < d; i++)
  {
    int max_j = 0;
    int max_score = INT_MIN;

    for (int j = 0; j < 26; j++)
    {
      int score = c[i + 1][j];
      for (int k = 0; k < 26; k++)
      {
        if (j != k)
        {
          score -= c[0][k] * weight[k];
        }
      }
      if (max_score < score)
      {
        max_score = score;
        max_j = j;
      }
    }
    sum += max_score;
    for (int j = 0; j < 26; j++)
    {
      if (j != max_j)
      {
        weight[j]++;
      }
      else
      {
        weight[j] = 1;
      }
    }
    std::cout << max_j + 1 << std::endl;
  }
  return 0;
}

Measured memory_bytes: 3704
cards = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 1]
A, B = map(int, input().split())
Alice, Bob = cards.index(A), cards.index(B)
if Alice > Bob:
    print("Alice")
elif Alice < Bob:
    print("Bob")
else:
    print("Draw")


Measured memory_bytes: 3060
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int s = sc.nextInt();
    if(s==111){
      System.out.println(3);
    }else if(s==101||s==11||s==110){
      System.out.println(2);
    }else if(s==0){
      System.out.println(0);
    }else{
      System.out.println(1);
    }
  }
  

  
}

Measured memory_bytes: 23124
#include "bits/stdc++.h"
using namespace std;

int main() {
	int N;
	cin >>N;
	set<int>S;
	for (int n = 1;n<=9;++n) {
		for (int m = 1;m<=9;++m) {
			S.insert(n*m);
		}
	}
	set<int>::iterator it = S.find(N);
	if (it != S.end()) {
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 3588
main=do
 [n,x]<-map read.words<$>getLine :: IO [Int]
 ss<-map read.words<$>getLine :: IO [Int]
 let p=fst$foldl(\a b->if snd a<=x then (fst a+1,snd a+b) else a)(0,0)ss
 print$if sum ss<=x then p+1 else p

Measured memory_bytes: 892
#include "bits/stdc++.h"
using namespace std;

const int N=1e5+20;

int n,m,k,u,v,color,col[N],dp[N];
vector <int> adj[N],blocked[N],nodes;
bool vis[N];

void dfs(int node)
{
	vis[node]=true;
	nodes.push_back(node);
	for(auto child:adj[node])
		if(not vis[child]) dfs(child);
}

int main()
{
	scanf("%d%d%d",&n,&m,&k);
	while(m--)
	{
		scanf("%d%d",&u,&v);
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	while(k--)
	{
		scanf("%d%d",&u,&v);
		blocked[u].push_back(v);
		blocked[v].push_back(u);
	}

	for(int i=1;i<=n;i++)
	{
		if(vis[i]) continue;
		color++;
		dfs(i);

		for(auto node:nodes)
			col[node]=color;

		int cc_size=nodes.size();
		while(not nodes.empty())
		{
			int node=nodes.back();
			nodes.pop_back();

			int blocked_in_cc=0;
			for(auto child:blocked[node])
				if(col[child]==color) blocked_in_cc++;
			dp[node]=cc_size-adj[node].size()-blocked_in_cc-1;
		}
	}

	for(int i=1;i<=n;i++)
		printf("%d ",dp[i]);
}

Measured memory_bytes: 13564
n,m = map(int,input().split())
query = [list(map(lambda x:int(x)-1,input().split())) for i in range(m)]
query.sort(key=lambda x:x[1])

l_end = -1
ans = 0
for i in range(m):
    a,b = query[i]
    if a+1>l_end:
        l_end = b
        ans+=1
print(ans)


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

#define lli long long int
#define REP(i,s,l) for(lli i=s;i<l;i++)
#define DEBUG 0
#define INF (1LL<<50)
#define MOD 1000000007

int main()
{
    string s, result = "";
    cin >> s;
    for(int i=1; i<=s.length(); i++){
        if(i%2==1) result += s[i-1];
    }
    cout << result << endl;
    return 0;
}

Measured memory_bytes: 512
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a[] = new int[3];
		for (int i = 0; i < a.length; i++) {
			a[i] = sc.nextInt();
		}
		Arrays.sort(a);

		int sum;
		sum = (a[2] - a[0]) + (a[2] - a[1]);
		if(sum % 2 == 0) System.out.println(sum / 2);
		else System.out.print(((sum + 1) / 2) + 1);
	}
}

Measured memory_bytes: 21844
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define showall(obj) for(auto x:obj)cout<<x<<endl;
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
typedef vector<int> vint;
typedef vector<ll> vll;
const int inf = 100100100;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

ll div_cnt(ll a, ll b, ll div){
	ll ans;
	ans = b/div;
	ll t = (a-1)/div;
	return ans-t;
}

int main(){
	ll a,b,c,d;
	cin>>a>>b>>c>>d;
	ll e_by_c = div_cnt(a, b, c);
	ll e_by_d = div_cnt(a, b, d);
	ll e_by_cd = div_cnt(a,b, (c*d)/__gcd(c,d));
	cout<<b-a+1-e_by_c-e_by_d+e_by_cd<<endl;
	return 0;
}

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

int main() {
    int N,l,r;
    cin >> N ;
    int count = 0;
    rep(i, N) {
        cin >> l >> r;
        count += r - l + 1;
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define PB push_back
#define PF push_front
#define MP make_pair
typedef long long int ll;
const ll mod = 1e9+7;
const ll INF = 2e9;
const double epsilon = 1e-7;
const double PI = 3.1415926535;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}

int main(){
  ll k,x;
  cin>>k>>x;
  
  for(ll i = max((ll)-1000000,x-k+1);i<=min((ll)1000000,x+k-1);i++){
    cout<<i<<' ';
  }

}

Measured memory_bytes: 256
#include<iostream>

using namespace std;
#define int long long

signed main(){

   int N, M;
   cin>> N>> M;

   int r=0;
   if(N*2<=M){
      r+=N;
      M-=2*N;
      r+=(M/4);
   }else{
      r+=M/2;
   }

   cout<< r<< endl;

   return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<string>
#include<algorithm>
#include<utility>
#include<math.h>
#include<cstdlib>
#define rep(i, n) for(int i=0;i<n;i++)
#define repb(i, a, b) for(int i=a;i<b;i++)

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

const int INF = 1<<30;

int main(){
  int n, m;cin>>n>>m;
  int ans=-1;
  for(int i=1;i<=min(m/n, int(sqrt(m)));i++){
  	if(m%i!=0)continue;
    int t=m/i;if(t>m/n)t=-1;
    ans=max(ans, max(i, t));
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
import Control.Monad

main = do
  [n, k] <- map read . words <$> getLine
  members <- forM [1..(k::Int)] $ \x -> do
    getLine
    member <- map read . words <$> getLine
    return (member::[Int])
  
  putStrLn $ show $ n - (length $ ans n [] members)

push notExists exists = 
  notExists ++ ( filter (\x -> (x `elem` notExists) == False) exists)

ans :: Int -> [Int] -> [[Int]] -> [Int]
ans n buffer members
  | xs == [] = push buffer x
  | length buffer == n = buffer
  | otherwise = ans n (push buffer x) xs
  where (x:xs) = members


Measured memory_bytes: 5428
#include <bits/stdc++.h>
using namespace std;
 
template <typename T> void print(T t) { cout<<t<<endl; }
template<typename T, typename... Args> void print(T t, Args... args) { cout<<t<<" "; print(args...); }
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define int long long
#define double long double

int arr[200005];
int cache[200005][3];
int vis[200005][3];
int n;
int dp(int pos,int skip)
{
    if(skip>n%2+1)
        return -1e18;
    if(pos>=n)
    {
        if(!skip && n%2)
            return -1e18;
        return 0;
    }
    if(vis[pos][skip])
        return cache[pos][skip];
    vis[pos][skip]=1;
    int ans=max(dp(pos+1,skip+1),arr[pos]+dp(pos+2,skip));
    cache[pos][skip]=ans;
    return ans;
}
int32_t main() 
{
    IOS;
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>arr[i];
    print(dp(0,0));
}   


Measured memory_bytes: 19272
#include<stdio.h>

int main(void){
    int n;
    long long int b=1; 
    int tmp;
    tmp=scanf("%d",&n);
    for(int i=0;i<n;i++){
        long long int a;
        tmp=scanf("%lld",&a);
        if(a==0){
            printf("0\n");
            return 0;
        }
        else if(a>1000000000000000000){
            b=0;
        }
        else if(b*a>1000000000000000000||b*a<0){
           	b=0;
        }
        b=b*a;
    }
    if(b==0){
      printf("-1\n");
      return 0;
    }
    printf("%lld\n",b);
    return 0;
}

Measured memory_bytes: 1732
from itertools import compress

n, m = map(int, input().split())
ac = [0] * (n + 1)
wa = [0] * (n + 1)

for i in range(m):
    p, s = input().split()
    p = int(p)
    if ac[p]:
      continue
    if s == "AC":
        ac[p] = 1
    else:
        wa[p] += 1

print(sum(ac), sum(c for c in compress(wa, ac)))


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

ll mod = 1e9+7;

ll mod_pow(ll n, ll p){
    n %= mod;
    if(p==0) return 1;
    ll res = mod_pow(n*n%mod, p/2);
    if(p%2==1) res = res * n % mod;
    return res;
}


int main(){
    int N;  cin >> N;
    vector<int> A(N), copyA(N);
    for(int i=0; i<N; i++){
        cin >> A[i];
        copyA[i] = A[i];
    }

    map<int, int> mp;
    for(int i=0; i<N; i++){
        for(int n=2; n*n<=A[i]; n++){
            int cnt = 0;
            while(A[i]%n==0){
                cnt++;
                A[i]/=n;
            }
            if(mp.find(n) == mp.end()) mp[n] = cnt;
            else mp[n] = max(mp[n], cnt);
        }
        if(A[i] > 1){
            if(mp.find(A[i]) == mp.end()) mp[A[i]] = 1;
            else mp[A[i]] = max(mp[A[i]], 1);
        }
    }
    ll L = 1;
    for(auto p: mp){
        ll cnt = p.second;
        while(cnt--){
            L = (L * p.first)%mod;
        }
    }

    ll ans = 0;
    for(int i=0; i<N; i++){
        ll invA = mod_pow(copyA[i], mod-2);
        ll b = (L * invA)%mod;
        ans = (ans + b)%mod;
    }
    cout << ans << endl;
}


Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef vector<pair<ll, ll>> pll;
 
#define mod 1000000007
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define popcount(x) __builtin_popcountll(x)
 
const long double PI = acos(-1);
 
ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a / gcd(a,b) * b;}
ll stringcount(string s, char c){return count(s.cbegin(), s.cend(), c);}
bool isInteger(double x){return floor(x) == x;}


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

  ll n, m;
  cin >> n >> m;
  ll ans = 0;
  ll sum = 0;
  vector<ll> a(n);
  for(ll i = 0; i < n; i++){
    cin >> a[i];
    sum += a[i];
  }

  for(ll i = 0; i < n; i++){
    if(a[i] >= (double)(sum/(4.0*m))) ans++;
  }
  if(ans >= m) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)

using namespace std;

int main() {
    string a, b;
    cin >> a;
    cin >> b;
    int j = 0;
    int cnt = 0;
    if(a.length() > b.length()) {
        puts("GREATER");
        return 0;
    } else if(a.length() < b.length()) {
        puts("LESS");
        return 0;
    } else {
        REP(i, a.length()) {
            int num_a = a[i] - '0';
            int num_b = b[i] - '0';
            if(num_a > num_b) {
                puts("GREATER");
                return 0;
            }else if(num_a < num_b) {
                puts("LESS");
                return 0;
            }
        }
        puts("EQUAL");
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <deque>
#include <iomanip>


using namespace std;


typedef long long ll;


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

  string str;
  cin >> str;

  int N = (int)str.size();
  vector<int> memoZero(N, 0);
  vector<int> memoOne(N, 0);
  if (str[0] == '0') {
    memoOne[0] = 1;
  }
  else {
    memoZero[0] = 1;
  }
  for (int i = 1 ; i < N ; i++) {
    if (str[i] == '0') {
      memoZero[i] = memoOne[i-1];
      memoOne[i] = memoZero[i-1] + 1;
    }
    else {
      memoOne[i] = memoZero[i-1];
      memoZero[i] = memoOne[i-1] + 1;
    }
  }

  cout << min(memoZero[N-1], memoOne[N-1]);


  return 0;
}




Measured memory_bytes: 1232
<?php


class Scanner
{
    private $arr = [];
    private $count = 0;
    private $pointer = 0;

    public function next()
    {
        if ($this->pointer >= $this->count) {
            $str = trim(fgets(STDIN));
            $this->arr = explode(" ", $str);
            $this->count = count($this->arr);
            $this->pointer = 0;
        }
        $result = $this->arr[$this->pointer];
        $this->pointer++;
        return $result;
    }

    public function hasNext()
    {
        return $this->pointer < $this->count;
    }

    public function nextInt()
    {
        return (int)$this->next();
    }

    public function nextDouble()
    {
        return (double)$this->next();
    }
}

class out
{
    public static function printIn($str = "")
    {
        echo $str . PHP_EOL;
    }
}

$sc = new Scanner;


$a = $sc->next();
$b = $sc->next();
$c = $sc->next();

$num = $a . $b . $c;

if ((int)$num % 4 === 0) {
    echo 'YES';
}else{
    echo 'NO';
}


Measured memory_bytes: 4728
#include<iostream>
#include<string>
#include<sstream>
using namespace std;
string s, w[1000];
stringstream ss;
int i;

int main() {
	getline(cin, s);
	ss << s;
	for (i = 0; ss >> w[i]; i++) {
		int p = w[i].find("apple"), q = w[i].find("peach");
		if (p != string::npos) {
			w[i].replace(p, 5, "peach");
		}
		if (q != string::npos) {
			w[i].replace(q, 5, "apple");
		}
	}
	for (int j = 0; j < i; j++) {
		if (j)cout << " ";
		cout << w[j];
	}
	cout << endl;
}


Measured memory_bytes: 3132
#include <bits/stdc++.h>
using namespace std;
#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >

//std::ios::sync_with_stdio(false); 

int main(){
	ll n,i;
	cin>>n;
	ll ans=0;
	//ll i;
	ll temp=0;
for(i=0;i<n;i++){
	cin>>temp;
	ans+=temp;
}
if(ans%2==0) cout<<"YES";
else cout<<"NO";

	return 0;
} 


Measured memory_bytes: 256
//wawando's template

#include <iostream>
#include <string>
#include <fstream>
#include <functional>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <list>
#include <set>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>  //clock_t , clock() , CLOCKS_PER_SEC
#include <cstring>
#include <cctype>
#include <climits> // LLONG_MAX , LLONG_MIN , INT_MAX , INT_MIN

//MACROS
#define pb              push_back
#define mp              make_pair
#define INF             1000000000     //1 billion safer for floyd warshall, avoid overflow

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

int main() {
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	//ios::sync_with_stdio(false);

  int N,K;
  string S;

  cin >>N >>K;
  cin >>S;
  S[K-1] += 32;
  cout <<S <<endl;
  return 0;
}


Measured memory_bytes: 256