akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.io.*;

class Main{
    public static void main(String[] args){
        FastScanner fsc=new FastScanner();
        int n=fsc.nextInt();
        int now=1;
        int ans=0;
        for(int i=0;i<n;i++){
            int a=fsc.nextInt();
            if(a!=now){
                ans++;
            }
            else{
                now++;
            }
        }
        fsc.close();
        if(ans<n) System.out.println(ans);
        else System.out.println(-1);
    }
    static class FastScanner {
        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() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
        private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
        public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; 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 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();
            }
        }
        public int nextInt() {
            long nl = nextLong();
            if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
            return (int) nl;
        }
        public double nextDouble() { return Double.parseDouble(next());}
        public void close(){
            try{in.close();}
            catch(IOException e){e.printStackTrace();}
        }
    }
}


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

#define lf double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

#define INF 10000

using namespace std;

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
    int n, m; cin>>n>>m;
    vector<vi> adj(n+1);
    rep(i, m){
        int a, b; cin>>a>>b;
        adj[a].pb(b);
    }

    vi ans(n+1);
    rep(i, n){
        queue<int> q;
        vi dist(n+1, INF), prev(n+1, -1);
        q.push(i+1);
        dist[i+1] = 0;
        while(q.size()){
            int v = q.front(); q.pop();
            for(auto u:adj[v]){
                if (dist[u] != INF) continue;
                prev[u] = v;
                dist[u] = dist[v]+1;
                q.push(u);
            }
        }
        pi best(INF, -1);
        rep(j, n){
            for(auto v:adj[j+1]){
                if (v == i+1){
                    best = min(best, mp(dist[j+1], j+1));
                }
            }
        }
        if (best.fi == INF) continue;
        int v = best.se;
        vi now;
        while(v != -1){
            now.pb(v);
            v = prev[v];
        }
        if (ans.size() > now.size()) ans = now;
    }
    if (ans.size()==n+1){
        cout << "-1\n";
    }else{
        cout << ans.size() << "\n";
        for(auto e:ans){
            cout << e << "\n";
        }
    }
	return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#define MAX(a,b) ((a)>(b)?(a):(b))

int main(void) {
   int N;
   scanf("%d", &N);
   int L[N][3];
   for (int i = 0; i < N; i++) {
      scanf("%d %d %d", &L[i][0], &L[i][1], &L[i][2]);
   }
   int dp[N+1][3];
   for (int i = 0; i < N+1; i++) {
      for (int j = 0; j < 3; j++) {
         dp[i][j] = 0;
      }
   }
   for (int day = 0; day < N; day++) {
      for (int i = 0; i < 3; i++) {
         for (int new = 0; new < 3; new++) {
            if (i != new) {
               dp[day+1][new] = MAX(dp[day][i]+L[day][new],dp[day+1][new]);
            }
         }
      }
   }
   int ans = 0;
   for (int i = 0; i < 3; i++) {
      ans = MAX(ans,dp[N][i]);
   }
   printf("%d\n",ans);
   return 0;

}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using ll=long long;
using namespace std;
#define rep_i(i, n) for (int i = 0; i < (n); ++i)
#define rep_ll(i, n) for (long long i = 0; i < (n); ++i)
#define r_rep_i(i, start, end) for (int i = (start); i < (end); ++i)
#define r_rep_ll(i, start, end) for (long long i = (start); i < (end); ++i)
#define debug_vi(v) copy((v).begin(), (v).end(), ostream_iterator<int>(cout, " "));
#define debug_vll(v) copy((v).begin(), (v).end(), ostream_iterator<long long>(cout, " "));
#define debug_vd(v) copy((v).begin(), (v).end(), ostream_iterator<double>(cout, " "));
#define sort_v(v) sort((v).begin(), (v).end()); //昇順
#define d_sort_vi(v) sort((v).begin(), (v).end(), greater<int>()); //降
#define d_sort_vd(v) sort((v).begin(), (v).end(), greater<double>()); //昇順
#define say(t) cout << (t) << endl;
#define sum_vi(v) accumulate((v).begin(), (v).end(), 0);
#define sum_vll(v)accumulate((v).begin(), (v).end(), 0LL);

int main(){
  ll a, b, r, x, tmp;
  cin >> a >> b;

  x = a * b;
  /* 自然数 a > b を確認・入替 */
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }
  /* ユークリッドの互除法 */
  r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }

  say(x/b);
}

Measured memory_bytes: 256
import java.util.*;
import java.util.stream.Collectors;

class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
      
        int n = sc.nextInt();
        int k = sc.nextInt();
        double result = k * Math.pow((k -1), n-1);
        System.out.println((long) (result));
    }
}

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

int main(void) {
  int N;
  vector<long long> L(2);
  L = {2, 1};
  cin >> N;
  for (int i = 2; i <= N; i++) {
    long long tmp = L[0] + L[1];
    L[0] = L[1];
    L[1] = tmp;
  }
  cout << L[1] << endl;
  return 0;
}

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

signed main() {
  ios::sync_with_stdio(false);

  int N;
  cin >> N;

  string S;
  cin >> S;

  vector<int> ps(N + 1);
  for (int i = 0; i < N; ++i) {
    ps[i + 1] = ps[i] + (S[i] == '#');
  }

  int ans = N;
  for (int i = 0; i < N + 1; ++i) {
    int a = ps[i];
    int b = (N - i) - (ps[N] - ps[i]);
    ans = min(ans, a + b);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1428
import sys
n, k = [int(i) for i in sys.stdin.readline().split()]
a_s = [int(i)-1 for i in sys.stdin.readline().split()]
cnt = 0
ind = 0
ls = [ind]
last_pos = {0:0}
_set = {ind}
while cnt < k:
    ind = a_s[ind]
    if ind in _set:
        break
    _set.add(ind)
    ls.append(ind)
    cnt += 1
if cnt == k:
    print(ind+1)
else:
    start = ls.index(ind)
    end = cnt+1
    print(ls[start:][(k - cnt) % (end - start)-1]+1)

Measured memory_bytes: 114936
#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> s;
    rep(i,n) {
        int a;
        cin >> a;
        s.insert(a);
    }
    if (s.size() == n) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 12988
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int INT_INF = 1 << 30;
const double PI = acos(-1.0);
#define MOD 1000000007LL
#define endl "\n"

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  string A;
  cin >> A;
  int N = sz(A);
  vvll ab(26, vll(N, 0));
  for(int i = 0; i < N; i++){
    ab.at(A.at(i) - 'a').at(i) = 1;
  }

  vvll sum(26, vll(N+1, 0));

  
  for(int i = 0; i < N; i++){
    for(int j = 0; j < 26; j++){
      sum.at(j).at(i+1) = sum.at(j).at(i) + ab.at(j).at(i);
    }
  }

  vll dp(N, 0);
  dp.at(0) = 1;
  for(int i = 1; i < N; i++){
    char c = A.at(i);
    dp.at(i) = dp.at(i-1) + (i - sum.at(c-'a').at(i));
  }
  cout << dp.at(N-1) << endl;

  /*実験
  map<string, int> mp;
  mp[A] = 1;
  for(int i = 0; i < N; i++){
    for(int j = i+1; j < N; j++){
      string pre = A.substr(0, i);
      string mid = A.substr(i, j-i+1);
      string post = A.substr(j+1, N-j);
      reverse(ALL(mid));
      mp[pre+mid+post]++;
      if(pre+mid+post == "abadacarbra") cout << i << ' ' << j << ' ' << pre + mid + post << endl;
    }
  }
  int counter = 0;
  for(auto i = mp.begin(); i != mp.end(); i++){
    cout << i->first << ' ' << i->second << endl;
    counter += i->second;
  }
  cout << counter << endl;
  cout<< mp.size() << endl;*/
}

Measured memory_bytes: 83320
N, M = list(map(int, input().split()))
result = ["x"] * N
no_break_check = 1
for i in range(M):
    s, c = list(input().split())
    s = int(s)
    if result[s-1] == "x":
        result[s-1] = c
    elif result[s-1] != c:
        print("-1")
        no_break_check = 0
        break

if no_break_check:
    if N > 1:
        for i, chr in enumerate(result):
            if result[i] == "x":
                if i == 0:
                    result[i] = "1"
                else:
                    result[i] = "0"
        if result[0] == "0":
            print("-1")
        else:
            print(int("".join(result)))
    else:
        if result[0] == "x":
            print(0)
        else:
            print(int(result[0]))

Measured memory_bytes: 3064
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <vector>

using namespace std;

typedef long long lint;

int main() {
  int n;
  scanf("%d", &n);
  vector<int> vals(n);
  lint s = 0;
  for (int i = 0; i < n; ++i) {
    scanf("%d", &vals[i]);
    s += vals[i];
  }
  int res = -1;
  lint dist = LLONG_MAX;
  for (int i = 0; i < n; ++i) {
    lint dist_i = abs((lint)vals[i] * n - s);
    if (dist_i < dist) {
      res = i;
      dist = dist_i;
    }
  }
  printf("%d\n", res);

  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include<math.h>
using namespace std;
#define INF 10000000
#define MOD 1000000007
typedef long long ll;
typedef pair<ll,int> P;

int st[3][40];

int main(){
    ll ans=2500000000;
    int N,C,D[40][40],c,a[3];
    cin>>N>>C;

    for(int i=1;i<=C;i++){
        for(int j=1;j<=C;j++) cin>>D[i][j];
    }

    for(int i=1;i<=N;i++){
        for(int j=1;j<=N;j++){
            cin>>c;
            st[(i+j)%3][c]++;
        }
    }

    for(a[0]=1;a[0]<=C;a[0]++){
        for(a[1]=1;a[1]<=C;a[1]++){
            for(a[2]=1;a[2]<=C;a[2]++){
                if(a[0]==a[1] || a[1]==a[2] || a[2]==a[0]) continue;
                ll temp=0;
                for(int i=0;i<3;i++){
                    for(int j=1;j<=C;j++){
                        temp+=st[i][j]*D[j][a[i]];
                    }
                }
                ans=min(ans,temp);
            }
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include<algorithm>
#include <cmath>
using namespace std;
int main(){
	while(1){
	double a,b,c;
	scanf("%lf %lf %lf",&a,&b,&c);
	if(a+b+c==0) break;
	int ans=0,u,w;
	for(int i=max((int)sqrt((double)ans),2);i<=(int)sqrt(a);i++){
		bool d=false;
			for(int k=2;k*k<=i;k++){
				if(i%k==0){
					d=true;
					break;
				}
			}
			if(d) continue;
		for(int j=max((int)(ans/i),2);j<=min(a/i,(int)i*c/b);j++){
			bool r=false;
			for(int k=2;k*k<=j;k++){
				if(j%k==0){
					r=true;
					break;
				}
			}
			if(r) continue;
			if(i*j<=a && ans<i*j){
				ans=i*j;
				u=i;
				w=j;
			}
		}
	}
	printf("%d %d\n",u,w);
	}
}

Measured memory_bytes: 1056
def insertion_sort(A,n):
    for i in range(n):
        v = A[i]
        j = i-1
        while(j>=0 and A[j]>v):
            A[j+1] = A[j]
            j = j-1
        A[j+1] = v
        for i in range(n-1):
            print(A[i],"",end="")
        print(A[n-1])

n = int(input())
A_idx = [int(i) for i in input().split()]

insertion_sort(A_idx,n)


Measured memory_bytes: 6312
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
template <class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b; }
template <class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b; }
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cout << H << " "; debug_out(T...); }
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  ll n;
  string s;
  cin >> n >> s;
  vector<ll> R(n+1,0),G(n+1,0),B(n+1,0);
  for (int i = n-1; i >= 0; --i) {
    if (s[i] == 'R') R[i]++;
    if (s[i] == 'G') G[i]++;
    if (s[i] == 'B') B[i]++;
    R[i] += R[i+1];
    G[i] += G[i+1];
    B[i] += B[i+1];
  }
  debug(R[0], G[0], B[0], R[n-1], G[n-1], B[n-1]);
  auto update = [&](int &bit, char x) {
    if (x == 'R') bit |= (1<<0);
    else if (x == 'G') bit |= (1<<1);
    else bit |= (1<<2);
  };
  auto check = [&](int bit, char x) {
    int i;
    if (x == 'R') i = 0;
    else if (x == 'G') i = 1;
    else i = 2;
    if (bit & (1<<i)) return false; //NG(フラグあり)
    else return true; //OK
  };
  ll ans = 0;
  for (int i = 0; i <= n-3; ++i) {
    for (int j = i+1; j <= n-2; ++j) {
      int bit = 0;
      update(bit, s[i]);
      if (check(bit, s[j])) update(bit, s[j]);
      else continue;
      int rgb = 0;
      rep(i,3) {
        if (!(bit & (1<<i))) rgb = i; //未フラグを探す
      }
      if (rgb == 0) ans += R[j+1];
      else if (rgb == 1) ans += G[j+1];
      else ans += B[j+1];
      if (j+j-i > n-1) continue;
      if (rgb == 0 && s[j+j-i] == 'R') ans--;
      else if (rgb == 1 && s[j+j-i] == 'G') ans--;
      else if (rgb == 2 && s[j+j-i] == 'B') ans--;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3648
H,W,h,w = gets.split.map &:to_i

if H % h == 0 && W % w == 0
  puts "No"; exit
end

puts "Yes"

aa,bb,a,b = W,H,w,h
transposed = aa % a == 0

if transposed
  aa,bb = bb,aa
  a,b = b,a
end

x = 1000
row = (0...aa).map{ |i| i % a == 0 ? x*(a-1)-1 : -x }
ans = (0...bb).map{ row.clone }

if transposed
  ans = ans.transpose
end

ans.each{ |row| puts row * " " }


Measured memory_bytes: 5628
#include <algorithm>
#include <iostream>
#include <iterator>
#include <numeric>
#include <vector>

constexpr uint_fast32_t law = 1'000'000'000 + 7;

int main()
{
    uint_fast16_t N;
    std::cin >> N;

    std::vector<uint_fast32_t> intervals(N - 1);
    {
        uint_fast32_t tmp;
        std::cin >> tmp;

        for (uint_fast32_t i = 0; i < N - 1; i++) {
            uint_fast32_t next;
            std::cin >> next;

            intervals[i] = next - tmp;
            tmp = next;
        }
    }

    std::vector<uint_fast32_t> coeffs(N - 1);
    {
        std::vector<uint_fast32_t> tmp(N - 1);


        std::iota(coeffs.begin(), coeffs.end() - 1, uint_fast32_t{2});
        coeffs.back() = 1;

        std::iota(tmp.begin() + 1, tmp.end(), uint_fast32_t{1});
        tmp.front() = 1;


        std::partial_sum(coeffs.crbegin(), coeffs.crend(), coeffs.rbegin(),
            [](uint_fast32_t left, uint_fast32_t right) {
                return uint_fast64_t{left} * uint_fast64_t{right} % law;
            });
        std::partial_sum(tmp.cbegin(), tmp.cend(), tmp.begin(),
            [](uint_fast32_t left, uint_fast32_t right) {
                return uint_fast64_t{left} * uint_fast64_t{right} % law;
            });


        std::transform(
            coeffs.cbegin(), coeffs.cend(),
            tmp.cbegin(),
            coeffs.begin(),
            [](uint_fast32_t left, uint_fast32_t right) {
                return uint_fast64_t{left} * uint_fast64_t{right} % law;
            });


        std::partial_sum(coeffs.cbegin(), coeffs.cend(), coeffs.begin(),
            [](uint_fast32_t left, uint_fast32_t right) {
                return (left + right) % law;
            });
    }

    std::cout << std::inner_product(
                     intervals.cbegin(), intervals.cend(),
                     coeffs.cbegin(), 0,
                     [](uint_fast32_t left, uint_fast32_t right) {
                         return (left + right) % law;
                     },
                     [](uint_fast32_t left, uint_fast32_t right) {
                         return uint_fast64_t{left} * uint_fast64_t{right} % law;
                     })
              << std::endl;

    return 0;
}


Measured memory_bytes: 2560
#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;
  int ans = n + n * n + n * n * n;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3616
#include<iostream>
using namespace std;
int main(void){
  long long n,a,b,s;
  cin >> n >> a >> b;
  if((a>b && (a-b)%2 == 0 )||(b>a && (b-a)%2 == 0 ) ){
  	if(a>b){
    	cout << (a-b)/2;
    }else{
    	cout << (b-a)/2;
    }
  }else{
  	if(a<b){
    	if(b-1>n-a){ 
           s = n-b+1+(-(a-b+1))/2;
          cout << s;
      }else{
          s = a+(b-a-1)/2;
        	cout << s;
        }
    }else{
    	if(a-1>n-b){
          s = n-a+1+(-(b-a+1))/2;
          cout << s;
      }else{
        	s = b+(a-b-1)/2;
        	cout << s;
        }
    }
  }
return 0;
}


Measured memory_bytes: 256
arr = input().split(' ')
(W, H, x, y, r) = tuple([int(x) for x in arr])

if ((x - r) < 0):
    print('No')
elif ((x + r) > W):
    print('No')
elif ((y - r) < 0):
    print('No')
elif ((y + r) > H):
    print('No')
else:
    print('Yes')

Measured memory_bytes: 7748
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1001001001;
const ll LINF = 1001001001001001001;
#define fori(i,a,b) for(ll i=(a);i<=(b);i++)
#define repi(i,n) fori(i,0,(n)-1)
#define forr(i,a,b) for(ll i=(b);i>=(a);i--)
#define repr(i,n) forr(i,0,(n)-1)
#define all(x) (x).begin(),(x).end()
#define vec vector<ll>
#define pb push_back
#define mp make_pair
#define pcnt __builtin_popcount
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
const string YES = "Yes";
const string NO = "No";

void solve(ll k, ll x){
    cout<<(k*500>=x?"Yes":"No")<<endl;
}

int main(){
    ll k;
    scanf("%lld",&k);
    ll x;
    scanf("%lld",&x);
    solve(k, x);
    return 0;
}


Measured memory_bytes: 256
def m(h,a,i)
  l,r,x=i*2,i*2+1,i
  l<=h&&a[x]<a[l]&&x=l
  r<=h&&a[x]<a[r]&&x=r
  x!=i&&(a[i],a[x]=a[x],a[i])&&m(h,a,x)
end
h=gets.to_i
a=[nil]+gets.split.map(&:to_i)
(h/2).downto(1){|i|m(h,a,i)}
puts a*' '


Measured memory_bytes: 51360
#include <iostream>
#include <string>
using namespace std;
int main(){
    int i;
    string s,u[7];
    u[0]="SUN";
    u[1]="MON";
    u[2]="TUE";
    u[3]="WED";
    u[4]="THU";
    u[5]="FRI";
    u[6]="SAT";
    cin >> s;
    for(i=0;i<7;i++){
        if(u[i]==s){
            cout << 7-i;
        }
    }




}


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

int main(){
  int n;
  long long ans = 1, f = 0;
  cin >> n;
  for(int i = 0; n > i; i++) {
    long long a;
    cin >> a;
    if(a == 0){
      cout << 0 << endl;
      return 0;
    }
    //cout << ans << endl;
    if(ans > 1000000000000000000LL / a) {
      f = 1;
    }
	ans = ans * a;
  }
  if(f) ans = -1;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3608
import sys
from collections import deque, Counter, defaultdict

input = sys.stdin.readline
MOD = (10**9+7)

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])
    if arr==[]:
        arr.append([n, 1])
    return arr


def pow_k1(x, n):
    if n == 0:
        return 1
    K = 1
    while n > 1:
        if n % 2 != 0:
            K *= x
        x *= x
        n //= 2
    return K * x


def pow_k(x, n):
    if n == 0:
        return 1
    K = 1
    while n > 1:
        if n % 2 != 0:
            K *= x
        x *= x
        n //= 2
        x%=MOD
    return K * x


def main():
    n = int(input())
    al = list(map(int, input().split())) 
    lcm_dic = defaultdict(int)
    # lcm_dic = {}
    # al_facs = []
    for a in al:
        fac = factorization(a)
        # a_fac_dic = {}
        for f in fac:
            # lcm_dic.setdefault(f[0],0)
            lcm_dic[f[0]] = max(f[1], lcm_dic[f[0]])
            # a_fac_dic[f[0]] = f[1]
        # al_facs.append(a_fac_dic)


    lcm = 1
    for prime, cnt in lcm_dic.items():
        lcm *= pow_k1(prime,cnt)

    
    ans = 0
    for a in al:
        ans += lcm//a
        # if ans >= MOD: ans%=MOD
    ans%=MOD


    # ans = 0
    # for al_f in al_facs:
    #     curr_val = 1
    #     for prime, cnt in lcm_dic.items():
    #         if prime in al_f:
    #             curr_val *= pow_k(prime,(cnt-al_f[prime]))
    #             curr_val%=MOD
    #         else:
    #             curr_val *= pow_k(prime,cnt)
    #             curr_val%=MOD
    #     ans += curr_val
    #     ans %= MOD
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 47452
import sys
from io import StringIO
import unittest
import math
from collections import deque


def resolve():
    hp, n = map(int, input().split())
    magics = [list(map(int, input().split())) for i in range(n)]

    max_magic_power = 0
    # min_magic_power = 99999

    for magic in magics:
        max_magic_power = max(max_magic_power, magic[0])
        # min_magic_power = min(min_magic_power, magic[0])

    # dp作成[与えることができる最大ダメージ]×2(配列再利用と呼ばれる DP 時のメモリ消費を抑えるテクニックを使うので、2つで十分)
    # dp = [[0 for i in range(hp + max_magic_power)] for j in range(2)]

    # 想定できる最大魔法実施回数(HP / 一番弱い魔法)
    # max_cnt = math.ceil(hp / min_magic_power)

    # for cnt, i in enumerate(range(max_cnt)):
    #     now = cnt % 2
    #     bef = (cnt + 1) % 2
    #
    #     for magic in magics:
    #         dp[now][]

    # ダメージ量ごとに処理を行うため、キューを作成
    que = deque()

    ans = [999999999 for i in range(hp + max_magic_power + 1)]
    ans[0] = 0

    # # 初期データを格納(ダメージ0,消費MP0)
    # que.append([0, 0])
    #
    # while len(que) is not 0:
    #     damage, use_mp = que.pop()
    #
    #     # HP以上のダメージを与え終えた場合、何もせず終了
    #     if damage >= hp:
    #         continue
    #
    #     for magic in magics:
    #         # 各魔法を使用した結果をシュミレーション
    #         work_damage = damage + magic[0]
    #         work_use_mp = use_mp + magic[1]
    #
    #         # 消費MPが少ないパターンを発見できた場合
    #         if ans[work_damage] > work_use_mp:
    #             # 結果を更新
    #             ans[work_damage] = work_use_mp
    #             # キューに追加(継続して検証する)
    #             que.append([work_damage, work_use_mp])
    #
    # print(min(ans[hp-1:hp + 10000]))

    # HPの数だけループすればOK(残りHP1で魔法の威力10・・とかも、これで検証できるので。
    for i in range(hp + 1):
        # 与えることができないパターンのダメージなら、何もしない。
        if ans[i] is 999999999:
            continue

        # 与えることができるパターンのダメージなら、さらに、全魔法を打ち込んだ場合を検証。
        for magic in magics:
            # ans[合計ダメージ量] = min(ans[合計ダメージ量] , ans[蓄積ダメージ量] + 今回の魔法の消費HP
            # ※ans[]は、各ダメージ量の場合の、最小消費MPを保持する。
            ans[i + magic[0]] = min(ans[i + magic[0]], ans[i] + magic[1])

    print(min(ans[hp:-1]))


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """9 3
8 3
4 2
2 1"""
        output = """4"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """100 6
1 1
2 3
3 9
4 27
5 81
6 243"""
        output = """100"""
        self.assertIO(input, output)
    def test_入力例_3(self):
        input = """9999 10
540 7550
691 9680
700 9790
510 7150
415 5818
551 7712
587 8227
619 8671
588 8228
176 2461"""
        output = """139815"""
        self.assertIO(input, output)
    def test_入力例_4(self):
        input = """10000 1
1 10000
"""
        output = """100000000"""
        self.assertIO(input, output)



if __name__ == "__main__":
    # unittest.main()
    resolve()

Measured memory_bytes: 52460
import java.util.*;
import java.math.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int X = sc.nextInt();
		int[] m = new int[N+1];
		int sum =0;
		for(int i =1;i<=N;i++) {
			m[i] = sc.nextInt();
			sum += m[i];
		}
		int amari = X-sum;
		int min =m[1];
		for(int i=2;i<=N;i++) {
			min = Math.min(min, m[i]);
		}
		int kosuu = amari/min;
		System.out.println(N+kosuu);
		sc.close();
	}

}


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

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

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

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

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        a: i64,
        b: i64,
        c: i64
    }
    println!("{}", if a<= c && c <= b {"Yes"} else {"No"});
}


Measured memory_bytes: 4352
import java.util.Scanner;

public class Main{

	private static int n;
	private static int m;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		m = sc.nextInt();
		int[] a = new int [n];

		for(int i = 0; i < n; i++) {
			a[i] =-1* sc.nextInt();
		}

		MyHeap heap = new MyHeap(a);

		for(int i = 0; i < m; i++) {
			int max = heap.pop()/2;
			heap.push(max);
		}

		long sum = 0;
		for(int i = 0; i < n; i++) {
			sum -= heap.heap[i];
		}
		System.out.println(sum);

		sc.close();
	}
	private static class MyHeap {

		int[] heap;
		int sz;//空の先頭

		MyHeap(int[] a){
			this.heap = new int[n+1];//最大容量
			this.sz = 0;
			for(int i = 0; i < a.length; i++) {
				this.push(a[i]);
			}
		}

		void push(int x) {
			int i = sz++;
			while(i > 0) {
				int p = (i-1)/2;
				if(heap[p] <= x) break;
				heap[i] = heap[p];
				i = p;
			}
			heap[i] = x;
		}

		 int pop() {
			int ret = heap[0];
			int x = heap[--sz];
			int i = 0;
			while(i*2+1<sz) {
				int a = i*2+1; int b = i*2+2;
				if(b < sz && heap[b] < heap[a]) a = b;
				if(heap[a] >= x) break;
				heap[i] = heap[a];
				i = a;
			}
			heap[i] = x;
			return ret;
		}
	}
}

Measured memory_bytes: 52604
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int N;cin >> N;
  int count = 0;
  rep(i,N){
    int x;cin >> x;
    count += x&1;
  }
  YESNO(count%2==0);
  return 0;
}


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

using namespace std;

#define int long long
#define endl "\n"

const long long INF = (long long)1e18;
const long long MOD = 1'000'000'007; 

string yn(bool f){return f?"Yes":"No";}
string YN(bool f){return f?"YES":"NO";}



signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int N;
	int ans = 0, sum = 0;
	vector<int> d;
	
	cin>>N;
	
	d.resize(N);
	
	for(int i = 0; i < N; i++){
		cin>>d[i];
		
		ans += sum * d[i];
		
		sum += d[i];
	}
	
	
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 256
N,M = map(int,input().split())
AB, C = [], []
for _ in range(M):
    AB.append(tuple(int(i) for i in input().split()))
    C.append(sum(1<<(int(i)-1) for i in input().split()))

INF = 10**18

# dp[i]: 状態がbin(i)のときの費用の最小値
# bin(i)のj桁が1: j番目の宝箱を開けられる
dp = [INF] * (1<<N)

# 初期条件(全ての宝箱を開けられない)
dp[0] = 0

for i in range(1<<N):
    for (a, _), c in zip(AB,C):
        # 状態iで状態cにする鍵を買ったときの状態
        state = i | c
        dp[state] = min(dp[state], dp[i] + a)

if dp[-1] == INF:
    ans = -1
else:
    ans = dp[-1]
print(ans)

Measured memory_bytes: 45416
#include <bits/stdc++.h>
#ifdef __LOCAL
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
#else
    #define DBG(X)
    #define SAY(X)
#endif

#ifdef __LOCAL
    #include <filesystem>
    namespace fs = std::filesystem;
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int dx[]={1, 0, -1, 0, 1,-1, 1,-1};
int dy[]={0, 1, 0, -1, 1, 1,-1,-1};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);
static mt19937 _g(time(nullptr));
 
inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) cout << "[" << el.first << ";" << el.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

int N,C;
struct TVshow{
    int s,flag,c;
    TVshow(int s, int f, int c):s(s),flag(f),c(c){};
};
vector<TVshow> tvshows;

void input(){
    fast_io();
    #ifdef __LOCAL
        fs::path p = __FILE__;
        fs::path input,output;
        input = output = p.parent_path();
        input += string("/input/") + string(p.stem()) + string(".txt");
        output += string("/output/") + string(p.stem()) + string(".txt");
        freopen(input.c_str(), "r", stdin);
        freopen(output.c_str(), "w", stdout);
    #endif
    cin >> N >> C;
    for (int i = 0; i < N; i++)
    {
        int s,t,c;
        cin >> s >> t >> c;
        tvshows.emplace_back(s,1,c);
        tvshows.emplace_back(t,-1,c);
    }

    auto cmp = [&](TVshow a, TVshow b){
        if(a.s!=b.s) return a.s < b.s;
        else return a.flag > b.flag;
    };

    sort(tvshows.begin(),tvshows.end(),cmp);    
}

int solve(){
    int ans=0;
    multiset<int> mse;
    set<int> se;
    for(auto tv:tvshows){
        if(tv.flag==1) {
            se.insert(tv.c);
            mse.insert(tv.c);
            ans = max(ans,(int)se.size());
            }
        if(tv.flag==-1) {
            mse.erase(mse.find(tv.c));
            if(mse.count(tv.c)==0) se.erase(tv.c);
            }
    }
    cout << ans << endl;
    return 0;
}   

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


Measured memory_bytes: 4980
#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(){
    string s, t;
    cin >> s >> t;

    int ans = 10000;
    for(int i=0; i<=s.size()-t.size(); i++){
        string sub = s.substr(i,t.size());
        int change = 0;
        for(int j=0;j<t.size();j++){
            if(t[j]!=sub[j])change++;
        }
        ans = min(ans, change);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
priority_queue<pii,vector<pii>,greater<pii> >q;
const int maxn=2e5+10;
int p[maxn],Mi[maxn][20][2],Log[maxn],deg[maxn],in[maxn];
int hea[maxn],to[maxn<<1],nxt[maxn<<1],tot,cnt;
pii v[maxn];
int get(int l,int r,int f) {
	int L=Log[r-l+1];
	return min(Mi[l][L][f],Mi[r-(1<<L)+1][L][f]);
}
void add(int a,int b) {
	if(!a||!b)return;
	deg[b]++;
	nxt[++tot]=hea[a];
	hea[a]=tot;
	to[tot]=b;
}
int dfs(int l,int r) {
	if(r<l)return 0;
	int a=get(l,r,l&1),b=get(p[a]+1,r,r&1),now=++cnt;
	in[a]=now;
	v[now].first=a;
	v[now].second=b;
	add(now,dfs(l,p[a]-1));
	add(now,dfs(p[a]+1,p[b]-1));
	add(now,dfs(p[b]+1,r));
	return now;
}
int main() {
	memset(Mi,0x3f,sizeof(Mi));
	int n,a;
	scanf("%d",&n);
	Log[1]=0;
	for(int i=2;i<=n;i++)
		Log[i]=Log[i>>1]+1;
	for(int i=1;i<=n;i++) {
		scanf("%d",&a);
		Mi[i][0][i&1]=a;
		p[a]=i;
	}
	for(int i=1;i<20;i++)
		for(int j=1;j+(1<<i)-1<=n;j++) {
			Mi[j][i][0]=min(Mi[j][i-1][0],Mi[j+(1<<(i-1))][i-1][0]);
			Mi[j][i][1]=min(Mi[j][i-1][1],Mi[j+(1<<(i-1))][i-1][1]);
		}
	dfs(1,n);
	q.push(v[1]);
	while(!q.empty()) {
		pii x=q.top();
		q.pop();
		printf("%d %d ",x.first,x.second);
		for(int i=hea[in[x.first]];i;i=nxt[i]) {
			deg[to[i]]--;
			if(!deg[to[i]])q.push(v[to[i]]);
		}
	}
	puts("");
	return 0;
}

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

using namespace std;
typedef long long ll;

const int N = 300;
const int INF = 1e9 + 7;

ll dist[N + 5][N + 5];
int cost[N + 5][N + 5];

int main(){
	for(int i=0; i<N+3; i++){
		for(int j=0; j<N+3; j++) dist[i][j] = cost[i][j] = INF;
	}
	int n,m,l;
	scanf("%d %d %d",&n,&m,&l);
	for(int i=0; i<m; i++){
		int u,v,w;
		scanf("%d %d %d",&u,&v,&w);
		dist[u][v] = dist[v][u] = w;
	}
	for(int k=1; k<=n; k++){
		for(int i=1; i<=n; i++){
			for(int j=1; j<=n; j++){
				dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
			}
		}
	}
	for(int i=1; i<=n; i++){
		for(int j=i; j<=n; j++){
			if(dist[i][j] <= l) cost[i][j] = cost[j][i] = 1;
		}
	}
	for(int k=1; k<=n; k++){
		for(int i=1; i<=n; i++){
			for(int j=1; j<=n; j++){
				cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
			}
		}
	}
	int q;
	scanf("%d",&q);
	while(q--){
		int u,v;
		scanf("%d %d",&u,&v);
		int ans = cost[u][v];
		if(ans == INF) ans = 0;
		printf("%d\n",ans-1);
	}
	return 0;
}

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

//naive solve 

int main() {
  long L,R;
  cin >> L >> R;
  
  long i,j,ans;
  ans = 2019;
  for(i=L;i<R;i++){
    for(j=L+1;j<=R;j++){
      ans = min(ans,(i*j)%2019);
      if(j-(L+1)>2019) break;
    }
    if(i-L>2019) break;
  }
  cout << ans << endl;
  //cout << std::setprecision(12) << M_PI << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){

int a,b,c;
cin>>a>>b>>c;
if(a==5 &&b==5 && c==7 || a==7 && b==5 &&c==5 || a==5 && b==7 &&c==5)
cout<<"YES";
else cout <<"NO";
    return 0;
}


Measured memory_bytes: 256
from itertools import product
from copy import deepcopy, copy
class QueenMAP():
    __slots__ = ["yoko", "tate", "naname1", "naname2", "MAP"]
    def __init__(self):
        self.yoko = set()
        self.tate = set()
        self.naname1 = set()
        self.naname2 = set()
        self.MAP = [["."] * 8 for _ in range(8)]
    def add(self, y, x):
        self.MAP[y][x] = "Q"
        self.yoko.add(y)
        self.tate.add(x)
        self.naname1.add(y - x)
        self.naname2.add(x + y)
    def check(self, y, x):
        if y in self.yoko or x in self.tate or (y - x) in self.naname1 or (x + y) in self.naname2:
            return False
        return True
    def allcheck(self):
        for i in range(8):
            if not "Q" in self.MAP[i]:
                return False
        return True
    def show(self):
        print("\n".join("".join(m) for m in self.MAP))
def MAIN():
    f = lambda M: "\n".join("".join(m) for m in M)
    QM = QueenMAP()
    n = int(input())
    for _ in range(n):
        a, b = map(int, input().split())
        QM.add(a, b)
    dp = [(deepcopy(QM), n)]
    while dp:
        Q, cnt = dp.pop()
        if cnt == 8:
            if Q.allcheck():
                Q.show()
                break
            continue
        cnt += 1
        for i, j in product(range(8), repeat=2):
            if Q.check(i, j):
                CQ = deepcopy(Q)
                CQ.add(i, j)
                dp.append((CQ, cnt))
MAIN()



Measured memory_bytes: 6352
//In the middle of Difficulty, lies Opportunity

#include <bits/stdc++.h>

#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define f first
#define s second

using namespace std;


void sol(){
	ll t, d, n=0;
    cin >> t >> d;

	ll x[200000], y[200000];
	for (ll i=0; i < t; i++)
		cin >> x[i] >> y[i];

	for (ll i=0; i < t; i++)
		if (sqrt((x[i] * x[i]) + (y[i] * y[i])) <= d)
			n++;

	cout << n;
}

int main(){
    std::ios::sync_with_stdio(false);
    sol();
    return 0;
}

Measured memory_bytes: 6804
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=1000000007;
const double PI=3.14159265358979;
const ll INF= pow(10,18);
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";

ll modpow(ll n,ll a){
  if(a==0){
    return 1;
  }
  else if(a%2==0){
    ll t=modpow(n,a/2);
    return t*t%MOD;
  }
  else
    return n*modpow(n,a-1)%MOD;
}
    
int main() {
  ll n;
  cin >> n;
  vl a(n);
  vl cnt(n);
  rep(i,n){
    cin >> a[i];
    cnt[a[i]]++;
  }
  bool B=false;
  ll i=n-1;
  while(i>=0){
    if(i!=0&&cnt[i]!=2){
      B=true;
    }
    if(i==0&&cnt[i]!=1){
      B=true;
    }
    i -=2;
  }
  if(B){
    cout << 0 << endl;
  }
  else{
    cout << modpow(2,n/2) << endl;
  }
}

Measured memory_bytes: 1792
def main():
    import sys
    read = sys.stdin.buffer.read
    readline = sys.stdin.buffer.readline
    readlines = sys.stdin.buffer.readlines
    sys.setrecursionlimit(10 ** 7)

    from collections import defaultdict
    from itertools import accumulate

    h, w, d = map(int, readline().split())
    dict = defaultdict(list)
    memo = [[0] for _ in range(d + 1)]
    for i in range(h):
        a = list(map(int, readline().split()))
        for j, aa in enumerate(a):
            dict[aa] = [i, j]
    for i in range(1, d + 1):
        bf = i
        for af in range(i + d, h * w + 1, d):
            memo[i].append(abs(dict[bf][0] - dict[af][0]) + abs(dict[bf][1] - dict[af][1]))
            bf = af
        memo[i] = list(accumulate(memo[i]))
    q = int(readline())
    for _ in range(q):
        l, r = map(int, readline().split())
        if r < l:
            r, l = l, r
        l, i = divmod(l, d)
        r //= d
        if i == 0:
            i = d
            l -= 1
            r -= 1
        print(memo[i][r] - memo[i][l])


if __name__ == '__main__':
    main()


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

struct PrimalDual{
  const int INF = 1<<28;
  typedef pair<int,int> P;
  struct edge{
    int to,cap,cost,rev;
    edge(){}
    edge(int to,int cap,int cost,int rev):to(to),cap(cap),cost(cost),rev(rev){}
  };

  int n;
  vector<vector<edge> > G;
  vector<int> h,dist,prevv,preve;

  PrimalDual(){}
  PrimalDual(int sz):n(sz),G(sz),h(sz),dist(sz),prevv(sz),preve(sz){}
  
  void add_edge(int from,int to,int cap,int cost){
    G[from].push_back(edge(to,cap,cost,G[to].size()));
    G[to].push_back(edge(from,0,-cost,G[from].size()-1));
  }

  int flow(int s,int t,int f){
    int res=0;
    fill(h.begin(),h.end(),0);
    while(f>0){
      priority_queue<P,vector<P>,greater<P> > que;
      fill(dist.begin(),dist.end(),INF);
      dist[s]=0;
      que.push(P(0,s));
      while(!que.empty()){
        P p=que.top();que.pop();
        int v=p.second;
        if(dist[v]<p.first) continue;
        for(int i=0;i<(int)G[v].size();i++){
          edge &e=G[v][i];
          if(e.cap>0&&dist[e.to]>dist[v]+e.cost+h[v]-h[e.to]){
            dist[e.to]=dist[v]+e.cost+h[v]-h[e.to];
            prevv[e.to]=v;
            preve[e.to]=i;
            que.push(P(dist[e.to],e.to));
          }
        }
      }
      if(dist[t]==INF) return -1;
      for(int v=0;v<n;v++) h[v]+=dist[v];
      int d=f;
      for(int v=t;v!=s;v=prevv[v]){
        d=min(d,G[prevv[v]][preve[v]].cap);
      }
      f-=d;
      res+=d*h[t];
      for(int v=t;v!=s;v=prevv[v]){
        edge &e=G[prevv[v]][preve[v]];
        e.cap-=d;
        G[v][e.rev].cap+=d;
      }
    }
    return res;
  }
};

int main(){
  int n;
  while(cin>>n,n){
    PrimalDual p(n*2+2);
    int sum=0,cube[n],a[3];
    vector<vector<int> >v(n);
    r(i,n){
      r(j,3)cin>>a[j];
      sort(a,a+3);
      sum+=a[0]*a[1]*a[2];
      cube[i]=a[0]*a[1]*a[2];
      r(j,3)v[i].push_back(a[j]);
    }
    r(i,n){
      r(j,n){
        int c=0;
        r(k,3)if(v[i][k]<v[j][k])c++;
        if(c==3){
          p.add_edge(i,n+j,1,0);
        }
      }
    }
    r(i,n)p.add_edge(n*2,i,1,0);
    r(i,n)p.add_edge(i+n,n*2+1,1,0);
    r(i,n)p.add_edge(i,n*2+1,1,cube[i]);
    cout<<p.flow(n*2,n*2+1,n)<<endl;
  }
}


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

int main()
{
    long numa, numb;
    int num;
    cin >> num;
    cin >> numa >> numb;
    long A,B;
    for(int i=1;i<num;i++){
        cin >> A >> B;
        if(A == B){
            if(numa<numb){
                numa = numb;
            }else{
                numb = numa;
            }
        }else{
            long currenta = max(numa/A,numb/B)*A;
            long currentb = max(numa/A,numb/B)*B;
            while((currenta<numa)||(currentb<numb)){
                currenta += A;
                currentb += B;
            }
            numa = currenta;
            numb = currentb;
        }
    }
    cout << numa + numb << endl;
    return 0;
}

Measured memory_bytes: 888
#include <iostream>
using namespace std;
int main(){
  int Width,Height,x,y,r;
  cin>>Width>>Height>>x>>y>>r;

  if(x-r>=0 && x+r<=Width && y-r>=0 && y+r<=Height)
  cout<<"Yes\n";
  else
  cout<<"No\n";
}


Measured memory_bytes: 3080
import java.util.Scanner;
import java.io.*;

public class Main{
	public static void main(String[] args) throws IOException{
		Scanner stdIn = null;
		
		try{
			stdIn = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
			int len = 0;
			int index = 0;
			int[] cars = new int[10000];
			int[] result = new int[10000];
			
			while( stdIn.hasNext() ){
				int x = 0;
				if( stdIn.hasNextInt() ){
					x = stdIn.nextInt();
				} else {
					stdIn.next();
				}
				if( x == 0 ){
					len--;
					result[index] = cars[len];
					cars[len] = 0;
					index++;
				} else {
					cars[len] = x;
					len++;
				}
			}
			
			for(int i = 0; i < result.length; i++){
				if( result[i] == 0 ){
					break;
				}
				System.out.println(result[i]);
			}
		} finally {
			if( stdIn != null ){
				stdIn.close();
			}
		}
	}
}

Measured memory_bytes: 12000
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define int long long
const int INF=1e15;
const int MAX=200001;
const int MOD=1e9+7;
int fac[MAX],finv[MAX],inv[MAX];

void COMinit(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<MAX;i++){
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}
 
int COM(int n,int k){
    if(n<k)return 0;
    if(n<0||k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}

signed main(){
    COMinit();
  	int N,K;cin>>N>>K;
    int ans=0;
    for(int i=0;i<=K;i++){
        ans+=COM(N,i)*COM(N-1,N-i-1)%MOD;
    }
    cout<<ans%MOD<<endl;
}

Measured memory_bytes: 4992