akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define newl "\n"
using namespace std;
using lli = long long int;
using vvint = vector <vector <int>>;
const int mod = 1e9 + 7;

const int N = 2e5 + 1;

bool check(int num,int k,vector <int> &a){
	int out = 0;
	for(int i : a){
		if(i % num == 0) out += (i / num - 1);
		else out += i / num;
	}
	return out <= k;
}

void solve(){
	int n,k;
	cin >> n >> k;
	vector <int> a(n);
	int high = -1, low = 1;
	for(int i = 0;i < n;++i) cin >> a[i], high = max(high,a[i]);
	while(low < high){
		int mid = (low + high) / 2;
		if(check(mid,k,a)) high = mid;
		else low = mid + 1;
	}
	cout << low << newl;
	return;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout << fixed << setprecision(10);
	#ifdef EXECUTE_LOCALLY
		   freopen("in.txt","r",stdin);
	#endif
	int t = 1;
	//cin >> t;
	while(t--) solve();
	#ifdef EXECUTE_LOCALLY
    	cout << setprecision(3) << "program time: " << (double)clock() / CLOCKS_PER_SEC << newl;
	#endif
	return 0;
}


Measured memory_bytes: 3844
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr int INF = 2000000000;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
# define ALL(x)     (x).begin(),(x).end()
# define UNIQ(c)    (c).erase(unique(ALL((c))), end((c)))
# define mp         make_pair
# define eb         emplace_back
# define FOR(i,a,b) for(int i=(a);i<(b);++i)
# define REP(i,n)   FOR(i,0,n)
# define INIT       std::ios::sync_with_stdio(false);std::cin.tie(0);


int main() {
	int N;
	while (cin >> N&&N) {
		//1,0???n???
		stack<pair<int, int>> v;
		int ans = 0;
		int n;
		for (int i = 1; i <= N; i++) {
			cin >> n;
			if (i == 1) {
				if (n == 0) {
					ans++;
					v.push(make_pair(0, 1));
				}
				else {
					v.push(make_pair(1, 1));
				}
			}
			else if (i % 2 == 1) {
				if (n == 0)ans++;
				int t = v.top().first;
				if (n == t) {
					int k = v.top().second;
					v.pop();
					v.push(make_pair(t, k + 1));
				}
				else {
					v.push(make_pair(n, 1));
				}
			}
			else {
				int t = v.top().first;
				if (n == t) {
					if (n == 0)ans++;
					int k = v.top().second;
					v.pop();
					v.push(make_pair(t, k + 1));
				}
				else {
					int k = v.top().second;
					v.pop();
					int k2 = 0;
					if (v.size())k2 += v.top().second, v.pop();
					if (n == 0) {
						ans += k + 1;
					}
					else {
						ans -= k;
					}
					v.push(make_pair(n, k + k2 + 1));
				}
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 3012
#include <stdio.h>
#include <math.h>
 
int main(void){
  int n,score[1000],i,sum;
  double aver,hensa[1000],hsqsum,var,sdvi;
 
  while(1){
    scanf("%d",&n);
    if(n==0)  break;
     
    sum=0;
    for(i=0;i<n;i++){
      scanf("%d",&score[i]);  sum+=score[i];
    }
    aver=(double)sum/n;
    hsqsum=0;
    for(i=0;i<n;i++){
      hensa[i]=score[i]-aver;
      hsqsum+=(hensa[i]*hensa[i]);
    }
    var=hsqsum/n;
    sdvi=sqrt(var);
 
    printf("%f\n",sdvi);
  }
 
  return 0;
}

Measured memory_bytes: 636
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
using namespace std;
#define DEBUG(x) cout<<#x<<"="<<x<<endl
#define DEBUG2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl
typedef long long ll;
// #define LOCAL
void solve()
{
    ll A,B,N;
    cin>>A>>B>>N;
    cout<<A*min(B-1,N)/B;
}
int main()
{
#ifdef LOCAL
    freopen("in.txt","r",stdin);
#endif
    solve();
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define fr(i,j,p)   for(int i=j; i<p ;i++)
#define frr(i,j,p)  for(int i=j; i>=p ;i--)
#define PI          3.14159265358979323846
#define pb          push_back
#define mkp         make_pair
#define print(m)    std::cout << std::fixed << std::setprecision(11) << m <<endl;
#define ff          first
#define ss          second
#define mod         1000000007

int main() {
    int n,k;    cin>>n>>k;
    int h[n+1];
    h[0]=0;
    fr(i,1,n+1) cin>>h[i];
    int dp[n+1];
    dp[1]=0;
    dp[2]=abs(h[2]-h[1]);
    fr(i,3,n+1) {
        int mn=INT_MAX;
        for(int j=max(1,i-k); j<i; j++) {
            mn=min(mn,dp[j]+abs(h[i]-h[j]));
        }
        dp[i]=mn;
    }
    cout<<dp[n];
    
    return 0;
}




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

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

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

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

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

//main code

int main(int argc, char const* argv[])
{
    int N;
    cin >> N;
    VI a(N);
    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }
    SORT(a);
    LL min_sub = INT64_MAX;
    LL ans_right;
    for (int i = 0; i < N-1; i++) {
        if (min_sub > abs(a.back() - a[i]*2)) {
            ans_right = a[i];
            min_sub = abs(a.back() - a[i]*2);
        }
    }
    cout << a.back() << ' ' << ans_right << endl;
    return 0;
}


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

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

    int cnt = x / 100;
    int small = x % 100;
    if(small <= 5*cnt)
    {
        cout << 1 << endl;
    }
    else
    {
        cout << 0 << endl;
    }
    
}

Measured memory_bytes: 256
import java.util.*; 
import java.io.*;

public class Main {
    static StringTokenizer st;
    static BufferedReader br;  
    static PrintWriter out;
 
    public static void main(String[] args) throws IOException {
        br = new BufferedReader(new InputStreamReader(System.in));

        int N = nextInt();
        int M = nextInt();
        
        long sum = 0;
        for (int i=1; i<=M; i++) { 
            sum += nextInt();
        }

        if(N<sum){
            System.out.println(-1);
        }
        else{
            System.out.println(N-sum);    
        }
        
    }
    
      
    public static int nextInt() throws IOException {
        return Integer.parseInt(next());
    }
    public static long nextLong() throws IOException {
        return Long.parseLong(next());
    }

    public static double nextDouble() throws IOException {
        return Double.parseDouble(next());
    }

    static String next() throws IOException {
        while (st == null || !st.hasMoreTokens())
            st = new StringTokenizer(br.readLine().trim());
        return st.nextToken();
    }
}

Measured memory_bytes: 34304
N = int(input())
V = list(map(int,input().split()))
C = list(map(int,input().split()))
for i in range(N):
    V[i] = V[i]-C[i]
V.sort()
V.reverse()
ans = 0
for v in V:
    if v < 0:
        break
    ans += v
print(ans)

Measured memory_bytes: 3060
require 'pp'

# 空白区切の入力値を数値の配列で返却する
def gets_i_list()
  gets.chomp.split(" ").map(&:to_i)
end

N, M = gets_i_list
a_list = gets_i_list

hw_total = a_list.sum

if N >= hw_total
  puts N - hw_total
else
  puts -1
end


Measured memory_bytes: 14960
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ABC058_A solver = new ABC058_A();
        solver.solve(1, in, out);
        out.close();
    }

    static class ABC058_A {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int a = in.nextInt();
            int b = in.nextInt();
            int c = in.nextInt();
            out.println((b - a == c - b) ? "YES" : "NO");
        }

    }
}



Measured memory_bytes: 23764
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <stack>
#include <set>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()

const int N = (int)3e5;

ll mpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
  else return mpow(a,b-1) * a % MOD;
}
ll lpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = lpow(a,b/2); return memo*memo;}
  else return lpow(a,b-1) * a;
}
ll gcd(ll a, ll b){
  if(b==0) return a;
  else return gcd(b, a%b);
}
vector<ll> kaijo_memo;
ll kaijo(ll n){
  if(kaijo_memo.size() > n) return kaijo_memo[n];
  if(kaijo_memo.size() == 0) kaijo_memo.push_back(1);
  while(kaijo_memo.size() <= n) kaijo_memo.push_back(kaijo_memo[kaijo_memo.size()-1] * kaijo_memo.size() % MOD);
  return kaijo_memo[n];
}
vector<ll> gyaku_kaijo_memo;
ll gyaku_kaijo(ll n){
  if(gyaku_kaijo_memo.size() > n) return gyaku_kaijo_memo[n];
  if(gyaku_kaijo_memo.size() == 0) gyaku_kaijo_memo.push_back(1);
  while(gyaku_kaijo_memo.size() <= n) gyaku_kaijo_memo.push_back(gyaku_kaijo_memo[gyaku_kaijo_memo.size()-1] * mpow(gyaku_kaijo_memo.size(), MOD-2) % MOD);
  return gyaku_kaijo_memo[n];
}

ll nCr(ll n, ll r){
  if(n == r) return 1;//0個の丸と-1個の棒みたいな時に時に効く？不安.
  if(n < r || r < 0) return 0;
  ll ret = 1;
  ret *= kaijo(n); ret %= MOD;
  ret *= gyaku_kaijo(r); ret %= MOD;
  ret *= gyaku_kaijo(n-r); ret %= MOD;
  return ret;
}


int main(void){
  ll n,t;cin>>n>>t;
  ll dp[6002];
  rep(i,6002){
    dp[i] = 0;
  }
  vector<pair<ll,ll>> C;
  rep(i,n){
    ll a,b;cin>>a>>b;
    C.push_back({a,b});
  }
  sort(all(C));
  //reverse(all(C));
  rep(i,n){
    ll a = C[i].first;
    ll b = C[i].second;
    REP(j,6002-a){
      if(j >= t) continue;
      chmax(dp[j+a], dp[j] + b);
    }
  }
  ll ans = 0;
  rep(i,6002){
    chmax(ans, dp[i]);
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 384
n = gets.chomp.to_i
d = gets.chomp.split(' ').map(&:to_i)

counts = Array.new(d.max + 1, 0)
d.each do |di|
  counts[di] += 1
end

if !d[0].zero? || counts[0] != 1
  puts 0
  exit
end

sum = 1
counts.each_cons(2) do |ai, aj|
  if ai.zero? && !aj.zero?
    puts 0
    exit
  elsif !aj.zero?
    sum = (sum * ai ** aj) % 998244353
  end
end
puts sum


Measured memory_bytes: 9476
#include <bits/stdc++.h> 
 
using namespace std;
 
 template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
//constant
//--------------------------------------------
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

int main(){
    LL N,M;
    cin>>N>>M;
    LL res=min(N,M/2);
    M-=res*2;
    res+=M/4;
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector> //可変長配列
#include <queue> //キュー
#include <unordered_map> //ハッシュ連想配列
#include <numeric>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#define ll long long int
#define INFTY (1<<21)

using namespace std;

int main(void){
    cin.sync_with_stdio(false);
    string a,b,c;
    cin>>a>>b>>c;
    cout<<a[0]<<b[1]<<c[2]<<endl;
    return 0;
}

Measured memory_bytes: 764
#timeout
n=int(input())
a_max=int(n**0.5)+1

#a<=b

s_count=0
d_count=0
for a in range(1,a_max):
    b_max=(n//a)+1
    
    for b in range(a,b_max):
        c=n-a*b
        if c>=1:
            if a==b:
                s_count+=1
            else:
                d_count+=1
           
ans=s_count+d_count*2
print(ans)

Measured memory_bytes: 9440
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int D;
vector<int> c(26+1);
vector<vector<int>> s;

int compute_score(vector<int> t) {
    vector<vector<int>> last(D+1,vector<int>(26+1,0));
    int ans = 0;
    for(int d = 1; d <= D; d++) {
        last[d][t[d]] = d;
        ans += s[d][t[d]];
        for(int i = 1; i <= 26; i++) {
            if(i == t[d]) continue;
            last[d][i] = last[d-1][i];
            ans -= c[i]*(d-last[d][i]);
        }
    }
    return 0;
}

vector<int> greedy() {
    vector<int> t(D+1);
    vector<vector<int>> last(D+1,vector<int>(26+1,0));
    for(int d = 1; d <= D; d++) {
        int best_i = 0;
        int best_score_diff = -(INT32_MAX>>2);
        for(int i = 1; i <= 26; i++) {
            int score_diff = s[d][i];
            for(int j = 1; j <= 26; j++) {
                if(i==j) continue;
                score_diff -= c[j]*(d-last[d][j]);
            }
            if(score_diff >= best_score_diff) {
                best_i = i;
                best_score_diff = score_diff;
            }
        }
        for(int i = 1; i <= 26; i++) {
            if(i == best_i) {
                last[d][i] = d;
                t[d] = i;
            } else {
                last[d][i] = last[d-1][i];
            }
        }
    }
    return t;
}

int main(){
    ios::sync_with_stdio(false);
    cin >> D;
    s.assign(D+1,vector<int>(26+1,0));
    for(int i = 1; i <= 26; i++) cin >> c[i];
    for(int d = 1; d <= D; d++) for(int i = 1; i <= 26; i++) cin >> s[d][i];

    vector<int> t = greedy();
    for(int d = 1; d <= D; d++) cout << t[d] << endl;
}


Measured memory_bytes: 3780
#include <cstdio>
#include <cstring>
#define maxn 200010
using namespace std;
const long long inf = 0x3f3f3f3f3f3f3f3f;
inline long long min(long long a, long long b) {return a < b ? a : b;}
inline long long abs(long long a) {return a > 0 ? a : -a;}
int n, k, x, y;
int q, last;
long long V[maxn << 2][3], cov[maxn << 2];
void pushdown(int rt) {
    int lc = rt << 1, rc = rt << 1 | 1;
    long long &tmp = cov[rt];
    V[lc][0] += tmp;
    V[lc][1] += tmp;
    V[lc][2] += tmp;
    cov[lc] += tmp;
    V[rc][0] += tmp;
    V[rc][1] += tmp;
    V[rc][2] += tmp;
    cov[rc] += tmp;
    tmp = 0;
}
void update(int rt) {
    int lc = rt << 1, rc = rt << 1 | 1;
    V[rt][0] = min(V[lc][0], V[rc][0]);
    V[rt][1] = min(V[lc][1], V[rc][1]);
    V[rt][2] = min(V[lc][2], V[rc][2]);
}
void add(int rt, int l, int r, int p, long long num) {
    if (l == r) {
        V[rt][0] = num;
        V[rt][1] = num + l;
        V[rt][2] = num - l;
        return ;
    }
    if (cov[rt]) pushdown(rt);
    int mid = l + r >> 1;
    if (p <= mid) add(rt << 1, l, mid, p, num);
    else add(rt << 1 | 1, mid + 1, r, p, num);
    update(rt);
}
void add(long long num, int rt = 1) {
    V[rt][0] += num;
    V[rt][1] += num;
    V[rt][2] += num;
    cov[rt] += num;
}
long long ask(int rt, int l, int r, int L, int R, int op) {
    if (L <= l && R >= r) return V[rt][op];
    pushdown(rt);
    int mid = l + r >> 1;
    long long ans = inf;
    if (L <= mid) ans = ask(rt << 1, l, mid, L, R, op);
    if (R > mid) ans = min(ans, ask(rt << 1 | 1, mid + 1, r, L, R, op));
    return ans;
}
int main() {
    scanf("%d%d%d%d", &n, &k, &x, &y);
    scanf("%d", &q);
    memset(V, 0x3f, sizeof V);
    add(1, 1, n, x, abs(y - q));
    add(1, 1, n, y, abs(x - q));
    while (--k) {
        last = q; scanf("%d", &q);
        long long t0 = ask(1, 1, n, last, last, 0) + abs(q - last);
        long long t1 = ask(1, 1, n, q, n, 1) - q;
        long long t2 = ask(1, 1, n, 1, q, 2) + q;
        long long ans = min(t0, min(t1, t2));
        add(abs(q - last));
        add(1, 1, n, last, ans);
    }
    printf("%lld\n", V[1][0]);
    return 0;
}

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

int main(){
	int N;
  	int num;
  	int count;
  	int ans_num = 1;
  	int ans_count = 0;
  
  	cin >> N;
  	
  for(int i=1; i<=N; i++){
    num = i;
    count = 0;
    
    while( num % 2 == 0){
      num /= 2;
      count += 1;
    }
    
    if(count > ans_count){
      ans_count = count;
      ans_num = i;
    }
    
  }
  
  cout <<  ans_num << endl;
  
}


Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding: utf-8 -*-

_ = int(input())

d = dict()

sin = input()
for n in [int(s) for s in sin.strip().split()]:
    if n in d:
        d[n] += 1
    else:
        d[n] = 1
# print3d)
N = 0
for v in d.values():
    N += (v-1)
# print(N)

Nuniq = len(list(d.keys()))
ans = Nuniq - (0 if N%2==0 else 1)

print(ans)


Measured memory_bytes: 18976
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
struct Edge {
  ll to;
  ll cost;
};
int main() {
  int N;
  cin >> N;
  vector<ll> A(N);
  REP(i, N) cin >> A[i];
  int minuscnt = 0;
  REP(i, N) if (A[i] < 0) minuscnt++;
  ll ans = 0;
  REP(i, N) ans += abs(A[i]);
  if (minuscnt % 2 == 0) {
  } else {
    REP(i, A.size()) { A[i] = abs(A[i]); }
    sort(A.begin(), A.end());
    ans -= 2 * A[0];
  }
  cout << ans << endl;
}

Measured memory_bytes: 4048
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
#define vec(a,n) vector<int> (a)((n))
#define Vec(a,n) vector<string> (a)((n))
#define twovec(a,n,m) vector<vector<int>> a(n,vector<int>(m,0))
#define Twovec(a,n,m) vector<vector<double>> a(n,vector<double>(m,0))
#define P pair<int,int>
#define Sort(a) sort((a).begin(),(a).end())
#define Reverse(a) reverse((a).begin(),(a).end())
#define PQ(n) priority_queue<P,vector<P>,greater<P>> (n)
#define pq(n) priority_queue<int> (n)
using namespace std;
void Debug(auto a);

signed main(){
    vec(a,4);
    REP(i,6){
        int t;
        cin >> t;
        a[t-1]++;
    }
    Sort(a);
    bool ans=true;
    REP(i,4){
        if(i/2==0&&a[i]!=1){
            ans = false;
        }
        if(i/2==1&&a[i]!=2){
            ans = false;
        }
    }
    (ans)? cout << "YES": cout << "NO";
    return 0;
}



void Debug(auto a){
    cout << "{ ";
    for(auto b: a){
        cout << b << " ";
    }
    cout << "}" << endl;
}

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

using namespace std;

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

    int a, b, k;

    cin >> k >> a >> b;

    bool ok = false;

    for(int i = a; i <= b; i++){
        if(i % k == 0) ok = true;
    }

    if(ok) cout << "OK\n";
    else cout << "NG\n";
    
    return 0;
}

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

int main() {
    int K, N, i;
    int max_dst = 0;
    cin >> K >> N;
    vector<int> home(N);
    vector<int> dst(N);
    for (i = 0; i < N; i++) {
        cin >> home.at(i);
        if (i > 0) {
            dst.at(i - 1) = home.at(i) - home.at(i - 1);
            if (i == N - 1) {
                dst.at(i) = K - home.at(i) + home.at(0);
            }
        }
    }
    
    for (i = 0; i < N; i++) {
        if (max_dst < dst.at(i)) max_dst = dst.at(i);
    }
    cout << K - max_dst << endl;
}

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

int N;
const int MAX_N = 1e5;
ll a[3*MAX_N];
ll L[3*MAX_N];
ll R[3*MAX_N];

int main () {
  cin >> N;
  REP(i,3*N) cin >> a[i];

  priority_queue<int, vector<int>, greater<int> > ql;
  priority_queue<int> qr;

  REP(i,N) {
    L[N-1] += a[i];
    ql.push(a[i]);

    R[2*N-1] += a[i + 2*N];
    qr.push(a[i + 2*N]);
  }

  for(int i = N; i < 2*N; i++) {
    int diff = a[i] - ql.top();
    if(diff > 0) {
      L[i] = L[i-1] + diff;
      ql.pop();
      ql.push(a[i]);
    } else {
      L[i] = L[i-1];
    }
  }

  for(int i = 2*N-2; i >= N - 1; i--) {
    int diff = a[i+1] - qr.top();
    if(diff < 0) {
      R[i] = R[i+1] + diff;
      qr.pop();
      qr.push(a[i+1]);
    } else {
      R[i] = R[i+1];
    }
  }

  ll res = L[N-1] - R[N -1];
  for(int i = N - 1; i < 2*N; i++) res = max(res, L[i] - R[i]);

  cout << res << endl;
  return 0;
}


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

int a[5][5],vis[5][5];
int main()
{
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);

    for(int i=1; i<=3; i++)
    {
        for(int j=1; j<=3; j++)
        {
            cin >> a[i][j];
        }
    }
    int n; cin >> n;
    for(int k=1; k<=n; k++)
    {
        int p; cin >> p;
        for(int i=1; i<=3; i++)
        {
            for(int j=1; j<=3; j++)
            {
                if(a[i][j]==p)
                {
                    vis[i][j] = 1;
                }
            }
        }
    }

//    for(int i=1; i<=3; i++)
//    {
//        for(int j=1; j<=3; j++)
//        {
//            cout << vis[i][j] << " ";
//        }
//        cout << endl;
//    }



    int fg = 0;
    for(int i=1; i<=3; i++)
    {
        int c = 0;
        for(int j=1; j<=3; j++)
        {
            if(vis[i][j]==1)c++;
        }
        if(c==3)fg=1;
    }
    for(int j=1; j<=3; j++)
    {
        int c = 0;
        for(int i=1; i<=3; i++)
        {
            if(vis[i][j]==1)c++;
        }
        if(c==3)fg=1;
    }
    if(fg)cout << "Yes\n", exit(0);

    if(vis[2][2]==1)
    {
        if(vis[1][1]==1 && vis[3][3]==1)fg = 1;
        if(vis[1][3]==1 && vis[3][1]==1)fg = 1;
    }
    if(fg)cout << "Yes\n", exit(0);
    cout << "No\n";
    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3

import sys
sys.setrecursionlimit(300000)


def solve(S: str):
    if S == 'ARC':
        ret = 'ABC'
    else:
        ret = 'ARC'
    print(ret)
    return

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 61700
S = input()
reversed_S = ''.join(list(reversed(S)))  #Sを反転した文字列

divide = ['dream', 'dreamer', 'erase', 'eraser']

# divideの各要素も反転
for i in range(len(divide)):
    divide[i] = ''.join(list(reversed(divide[i])))

# 全体が分けきれるか
can = 1

i = 0

while i < len(S):
    can2 = 0
    for j in range(len(divide)):
        if reversed_S[i:i + len(divide[j])] == divide[j]:
            can2 = 1
            i += len(divide[j])

    if can2 == 0:
        can = 0
        break

if can == 1:
    print('YES')
else:
    print('NO')


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

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;


//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}


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


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

#define rep(i, N) for (int i = 0; i < N; i++)
#define rep1(i, N) for (ll i = 1; i <= N; i++)
#define repr(i, N) for (ll i = N-1; i >= 0; i--)
#define repr1(i, N) for (ll i = N; i > 0; i--)

#define MODNUM 1000000007

using ll = long long;
using namespace std;

int main(){
    int N,M,ans=0;
    cin >> N >> M;
    vector<int> k(M),p(M);
    vector<bool> swt(N),light(M);
    int s[12][12];
    for (int i = 0; i < M; i++){
        cin >> k[i];
        for (int j = 0; j < k[i]; j++){
            cin >> s[i][j];
        }
    }
    for (int i = 0; i < M; i++){
        cin >> p[i];
    }
    
    for (int i = 0; i < (1 << N); i++){
        for (int j = 0; j < N; j++){
            if(i & (1 << j)){
                swt[j] = true;
            }else{
                swt[j] = false;
            }
        }

        for (int j = 0; j < M; j++){
            int cnt = 0;
            light[j] = false;
            for (int l = 0; l < k[j]; l++){
                if(swt[s[j][l]-1]) cnt++;
            }
            if(cnt%2 != p[j]) break;
            else if(j == M-1) ans++;
        }
    } 
    
    cout << ans << endl;
    return 0;
}


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

#define ll long long

#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>=b;i--)
#define repA(i,A)   for(auto i:A)

#define err() cout<<"=================================="<<endl;
#define errA(A) for(auto i:A)   cout<<i<<" ";cout<<endl;
#define err1(a) cout<<#a<<" "<<a<<endl
#define err2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define err3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl
#define err4(a,b,c,d) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<" "<<#d<<" "<<d<<endl

#define mp make_pair
#define pb push_back
#define all(A)  A.begin(),A.end()
#define ft first
#define sd second

#define pll pair<ll,ll>
#define V vector<ll>
#define S set<ll>
#define VV vector<V>

#define endl "\n"

const ll logN = 20;
const ll N = 100005;
const ll M = 1000000007;
#define PI 3.14159265

int main(){
  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  int n, k;
  cin>>n>>k;
  ll h[n];
  rep(i, 0, n) cin>>h[i];
  ll cost[n] = {0};
  rep(i, 1, n){
    if(i==1){
      cost[i] = abs(h[i]-h[i-1]);
    }
    else{
      cost[i] = cost[i-1] + abs(h[i] - h[i-1]);
      for(int j=2; j<=k && i-j>=0; j++){
            cost[i] = min(cost[i], cost[i-j]+abs(h[i]-h[i-j]));
      }
    }
  }
  cout<<cost[n-1]<<endl;
  return 0;
}


Measured memory_bytes: 1792
/*
String[]の初期化、整数の型がlongになっているか
関数（splitとかcontainsとか）内では"+"とかは正規表現となされるので"\\+"とする
配列のコピーはarr1=arr.clone()
HashSet<>[]はおのおの初期化した？？？？？
 */
/*
サンプル1の流れ
バラバラ（4C2=6）→1,4のサイズ取得して計算（6-1*1=5）→つなぐ（1-4,2,3）→2,3のサイズ取得して計算（5-1*1=4）→2,3をつなぐ（1-4,2-3）→...
 */
import java.util.*;
import java.awt.*;
import java.awt.geom.*;
import static java.lang.System.*;
import static java.lang.Math.*;
public class Main {
    public static void main(String[] $) {
        Scanner sc = new Scanner(in);
        long n=sc.nextLong();
        int m=sc.nextInt();
        int[] A=new int[m];
        int[] B=new int[m];
        for (int i = 0; i < m; i++) {
            A[i]=sc.nextInt();
            B[i]=sc.nextInt();
        }
        long[] ans=new long[m];
        UF.init(100001);
        int a=0,b=0;
        ans[m - 1] = n * (n - 1) / 2;
        for (int i = 1; i < m; i++) {
            a = A[m - i];
            b = B[m - i];
            //out.print(m - i + " " + UF.us(a) + " size " + UF.us(b) + "→     ");
            //out.println(a + "と" + b + "をつなぐ");
            //out.print(" " + UF.same(a, b) + " ");
            if (UF.same(a, b)) {
                ans[m - i - 1] = ans[m - i];
            } else {
                ans[m - 1 - i] = ans[m - i] - (long) UF.us(a) * (long) UF.us(b);
            }
            UF.unite(a,b);
            //out.println(UF.us(a) + " size " + UF.us(b));
            //out.println(ans[m - 1 - i]);
        }
        for (long l:ans)out.println(l);
    }
    static class UF{
        static int size=100001;
        static int[] par=new int[size];
        static int[] count=new int[size];
        //初期化
        static void init(int n){
            for (int i = 0; i <n ; i++) {
                par[i]=i;
                count[i]=1;
            }
        }
        //根をたどる
        static int root(int x){
            if(par[x]==x){
                return x;
            }else{
                return par[x]=root(par[x]);
            }
        }
        //同じ根をもつか判定
        static boolean same(int x,int y){
            return root(x)==root(y);
        }
        //合体
        static void unite(int x,int y){
            x=root(x);
            y=root(y);
            if(x==y)return;
            count[y]+=count[x];
            par[x]=y;
        }
        //aを含む集合のサイズ
        static int us(int a){
            return count[root(a)];
        }
    }
}

Measured memory_bytes: 96168
import java.util.*;
class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int s=sc.nextInt();
    int a=s/1000;
    int b=s/100%10;
    int c=s/10%10;
    int d=s%10;
    if(a+b+c+d==7){
      System.out.print(a+"+"+b+"+"+c+"+"+d);
    }else if(a+b+c-d==7){
      System.out.print(a+"+"+b+"+"+c+"-"+d);
    }else if(a+b-c+d==7){
      System.out.print(a+"+"+b+"-"+c+"+"+d);
    }else if(a+b-c-d==7){
      System.out.print(a+"+"+b+"-"+c+"-"+d);
    }else if(a-b+c+d==7){
      System.out.print(a+"-"+b+"+"+c+"+"+d);
    }else if(a-b+c-d==7){
      System.out.print(a+"-"+b+"+"+c+"-"+d);
    }else if(a-b-c+d==7){
      System.out.print(a+"-"+b+"-"+c+"+"+d);
    }else{
      System.out.print(a+"-"+b+"-"+c+"-"+d);
    }
    System.out.println("=7");
  }
}

Measured memory_bytes: 23892
#include <stdio.h>;
#include <iostream>
using namespace std;

int main(){
    int a;
    int b;
    int d;
    int c;
    scanf("%d%d", &a, &b);
    c = a*b;
    d = 2*a + 2*b;
    cout << c << " " << d << endl;
    return 0;
}


Measured memory_bytes: 3172
#include<iostream>
#include<queue>
using namespace std;
static const int N = 100;
static const int INFTY = (1 << 21);

int n, M[N][N], d[N];

void bfs(int s) {
	queue<int> q;
	q.push(s);
	for(int i = 0; i < n; i++) {
		d[i] =INFTY;
	}
	d[s] = 0;
	int u;
	while(!q.empty()) {
		u = q.front();
		q.pop();
		for(int v = 0; v < n; v++) {
		    if(M[u][v] == 0) continue;
		    if(d[v] != INFTY) continue;
		    d[v] = d[u] + 1;
		    q.push(v);
	    }
    }
    for(int i = 0; i < n; i++) {
    	cout << i + 1 << " " << ( (d[i] == INFTY) ? -1 : d[i] ) << endl;
    }

}

int main() {
	int v, k ,u;
	cin >> n;
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < n; j++) {
		    M[i][j] = 0;	
		}
	}
	
	for(int i = 0; i < n; i++) {
		cin >> u >> k;
		for(int j = 0; j < k; j++) {
			cin >> v;
			M[u-1][v-1] = 1;
		}
	}
	
	bfs(0);
	
	return 0;
	
}

Measured memory_bytes: 3116
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define endl "\n"
#define ll long long
#define sz(s) (int)(s.size())
#define INF 0x3f3f3f3f3f3f3f3fLL
#define all(v) v.begin(),v.end()
#define watch(x) cout<<(#x)<<" = "<<x<<endl
const int dr[] { -1, -1, 0, 1, 1, 1, 0, -1 };
const int dc[] { 0, 1, 1, 1, 0, -1, -1, -1 };
#if __cplusplus >= 201402L
template<typename T>
vector<T> create(size_t n) {
	return vector<T>(n);
}
template<typename T, typename ... Args>
auto create(size_t n, Args ... args) {
	return vector<decltype(create<T>(args...))>(n, create<T>(args...));
}
#endif
void run() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
#ifdef EZZAT
	freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
#else
#endif
}
const int N = 2e5 + 1;
int f[N], pow2[3][N], res[3];
int cntBit(int n) {
	if (n == 0)
		return 0;
	return 1 + cntBit(n - (n & -n));
}
int main() {
	run();
	for (int i = 1; i < N; i++)
		f[i] = 1 + f[i % cntBit(i)];
	int n;
	string s;
	cin >> n >> s;
	int MOD = 0;
	for (int i = 0; i < n; i++)
		MOD += (s[i] == '1');
	for (int j = 0; j < 3; j++) {
		int mod = MOD + j - 1;
		if (mod <= 0)
			continue;
		pow2[j][0] = 1;
		for (int i = 1; i < n; i++)
			pow2[j][i] = (pow2[j][i - 1] << 1) % mod;
		for (int i = 0; i < n; i++)
			res[j] = (res[j] + (s[i] == '1') * pow2[j][n - 1 - i]) % mod;
	}
	for (int i = 0; i < n; i++) {
		if (s[i] == '1') {
			int mod = MOD - 1;
			if (mod == 0)
				cout << 0 << endl;
			else {
				int cur = (((res[0] - pow2[0][n - 1 - i]) % mod) + mod) % mod;
				cout << 1 + f[cur] << endl;
			}
		} else {
			int mod = MOD + 1;
			int cur = (res[2] + pow2[2][n - 1 - i]) % mod;
			cout << 1 + f[cur] << endl;
		}
	}
}


Measured memory_bytes: 6812
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        BigDecimal a = new BigDecimal(sc.next());
        BigDecimal b = new BigDecimal(sc.next());
        a = a.multiply(b);
        
        System.out.println(a.longValue());
    }
}


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

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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repp(i, s, e) for (int i = (s); i < (e); i++)
#define all(x) x.begin(), x.end()

#define endl "\n"

void use_cio() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
}

template <class L, class R>
ostream &operator<<(ostream &os, pair<L, R> P) {
  return os << "(" << P.first << "," << P.second << ")";
}
template <class T>
ostream &operator<<(ostream &os, vector<T> V) {
  os << "[";
  for (auto x : V) os << x << ", ";
  return os << "]";
}

//--------------------------------------------------//

int main() {
  use_cio();
  int n, d;
  cin >> n >> d;
  cout << n / (2 * d + 1) + (n % (2 * d + 1) > 0) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
LL Pow[40]={1};
LL calc(LL x1,LL y1,LL x2,LL y2,int d){
	if(d==-1)return abs(y2-y1);
	LL w=Pow[d];
	if(x1/w!=x2/w)return abs(x2-x1)+abs(y2-y1);
	if(x1/w==1&&abs(y1/w-y2/w)>=2){
		x1%=w,x2%=w;
		return abs(y2-y1)+min(x1+x2+2,w*2-x1-x2);
	}
	x1%=Pow[d],x2%=Pow[d];
	return calc(x1,y1,x2,y2,d-1);
}

LL cal(LL x1,LL y1,LL x2,LL y2,int level) {
    if(level==0) return abs(y1-y2);
    LL w=Pow[level-1];
    if(x1/w!=x2/w) return abs(x1-x2)+abs(y1-y2);//不同层
    if(x1/w==1&&abs(y1/w-y2/w)>=2) {//同层且在456这层
        return min(x1%w+x2%w+2,w*2-x1%w-x2%w)+abs(y1-y2);
    }
    return cal(x1%w,y1,x2%w,y2,level-1);
}
LL work(){
	LL a,b,c,d;scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
	a--,b--,c--,d--;if(abs(a-c)>abs(b-d))swap(a,b),swap(c,d);
	return calc(a,b,c,d,29);
}
int main(){
	for(int i=1;i<30;i++)Pow[i]=Pow[i-1]*3;
	int t;scanf("%d",&t);
	while(t--)printf("%lld\n",work());
	return 0;
}

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

int main(){
    string s;
    cin >> s;
    int n, l, tmp, i, wid, min;
    n = s.size();
    min = n;
    for(int j = 0; j< n; ++j){
        wid = s.find(s[j]);
        i = 0;
        if(wid >= 0){
            while(i < n){
                tmp = s.find(s[j],i);
                i = tmp + 1;
                if(i == 0) i = 1;
                l = (int)s.find(s[j],i);
                if(wid <(l - tmp - 1)) wid = l - tmp - 1;
                if(l< 0){
                    if(wid < (n - tmp - 1)) wid = n -tmp - 1;
                    break;
                }
            }
        }
        if(wid < min) min = wid;
    }
    cout << min  << endl;
}


Measured memory_bytes: 256
#134_C
n=int(input())
a=[int(input()) for _ in range(n)]
max1,max2=0,0
for i in range(n):
    if a[i]>max1:
        max2=max1
        max1=a[i]
    elif a[i]>max2:
        max2=a[i]
        
for i in range(n):
    print(max1 if a[i]!=max1 else max2)

Measured memory_bytes: 12628
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<vector>
#include<queue>
#include<bitset>
#include<string>
#include<stack>
#include<set>
#include<unordered_set>
#include<map>
#include<unordered_map>
#include<cstring>
#include<complex>
#include<cmath>
#include<iomanip>
#include<numeric>
#include<algorithm>
#include<list>
#include<functional>
#include<cassert>
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define y0 y12
#define y1 y22
#define INF 987654321
#define PI 3.141592653589793238462643383279502884
#define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
#define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
#define MEM0(a) memset((a),0,sizeof(a));
#define MEM_1(a) memset((a),-1,sizeof(a));
#define ALL(a) a.begin(),a.end()
#define SYNC ios_base::sync_with_stdio(false);cin.tie(0)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef double db;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<ld, ld> Pd;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<double> Vd;
typedef vector<Pi> VPi;
typedef vector<Pll> VPll;
typedef vector<Pd> VPd;
typedef tuple<int, int, int> iii;
typedef tuple<int,int,int,int> iiii;
typedef tuple<ll, ll, ll> LLL;
typedef vector<iii> Viii;
typedef vector<LLL> VLLL;
typedef complex<double> base;
const int MOD = 998244353;
ll POW(ll a, ll b, ll MMM = MOD) {ll ret=1; for(;b;b>>=1,a=(a*a)%MMM)if(b&1)ret=(ret*a)% MMM; return ret; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { if (a == 0 || b == 0)return a + b; return a*(b / gcd(a, b)); }
int dx[] = { 0,1,0,-1,1,1,-1,-1 }, dy[] = { 1,0,-1,0,1,-1,1,-1 };
int ddx[]={2,2,-2,-2,1,1,-1,-1},ddy[]={1,-1,1,-1,2,-2,2,-2};

int a[50],b[50];
int d[51][51];
int main(){
	int n;
	scanf("%d",&n);
	fup(i,0,n-1,1)scanf("%d",a+i);
	fup(i,0,n-1,1)scanf("%d",b+i);
	Vi v;
	fdn(t,50,0,1)
	{
		fup(i,0,50,1)fup(j,0,50,1)d[i][j]=i==j?0:INF;
		fup(i,1,t,1)fup(j,0,50,1)d[j][j%i]=1;
		for(int i:v)fup(j,0,50,1)d[j][j%i]=1;
		fup(k,0,50,1)fup(i,0,50,1)fup(j,0,50,1)d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
		fup(i,0,n-1,1)
			if(d[a[i]][b[i]]==INF)
			{
				if(t==50)return !printf("-1");
				v.pb(t+1);
				break;
			}
	}
	ll ans=0;
	for(int x:v)ans+=1LL<<x;
	printf("%lld",ans);
	
}

Measured memory_bytes: 256
use std::collections::BTreeMap;

const MOD: usize = 1e9 as usize + 7;

fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let n: usize = sc.read();
    let mut map = BTreeMap::new();
    println!("{}", solve(n, n, &mut map) % MOD);
}

fn solve(xor: usize, sum: usize, map: &mut BTreeMap<(usize, usize), usize>) -> usize {
    if sum == 0 {
        return 1;
    }
    if let Some(&ans) = map.get(&(xor, sum)) {
        return ans;
    }
    let mut ans = 0;
    if sum >= 2 {
        // odd+odd
        ans += solve(xor >> 1, (sum - 2) >> 1, map);
    }

    // even+even
    ans += solve(xor >> 1, sum >> 1, map);

    // even+odd
    ans += solve(xor >> 1, (sum - 1) >> 1, map);

    map.insert((xor, sum), ans % MOD);
    ans % MOD
}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 4352
import sys
import numpy as np

n = int(sys.stdin.readline().rstrip())
a = np.array(sys.stdin.read().split(), dtype=np.int64)

def main():
    mul_4 = n - np.count_nonzero(a % 4)
    mul_2 = n - np.count_nonzero(a % 2)

    if mul_4 >= n // 2:
        return 'Yes'
    if mul_4 * 2 + (mul_2 - mul_4) >= n:
        return 'Yes'
    else:
        return 'No'

if __name__ == '__main__':
    ans = main()
    print(ans)

Measured memory_bytes: 23836
#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(){
	vector<vector<int>> ns(3, vector<int>(3));
	vector<vector<int>> ok(3, vector<int>(3));
	rep(i, 3){
    	rep(j, 3){
        	cin >> ns.at(i).at(j);
        	ok.at(i).at(j) = 0;
        }
    }
	int n;
	cin >> n;
	rep(k, n){
    	int a = 0;
    	cin >> a;
        rep(i, 3){
            rep(j, 3){
                if(ns.at(i).at(j) == a) ok.at(i).at(j) = 1; 
            }
        }
    }
	int f = 0;
	int cou = 0;
	rep(i, 3){
    	cou = 0;
    	rep(j, 3){
          if(ok.at(i).at(j) == 1) cou++;
        }
    	if(cou == 3) f = 1;
    }
	rep(j, 3){
    	cou = 0;
    	rep(i, 3){
          if(ok.at(i).at(j) == 1) cou++;
        }
    	if(cou == 3) f = 1;
    }
	if(ok.at(0).at(0) == 1 && ok.at(1).at(1) == 1 && ok.at(2).at(2) == 1) f = 1;
	if(ok.at(0).at(2) == 1 && ok.at(1).at(1) == 1 && ok.at(2).at(0) == 1) f = 1;
	if(f == 0){
    	cout << "No" << endl;
    }else{
    	cout << "Yes" << endl;
    }
}

Measured memory_bytes: 256
n = int(input())
ms = []
say = []
for i in range(n):
    m = int(input())
    ms.append(m)
    say.append([])
    for j in range(m):
        p,q = list(map(int, input().split()))
        say[i].append([p,q])

# ms =  [2, 2, 2]
# say = [[[2, 1], [3, 0]], [[3, 1], [1, 0]], [[1, 1], [2, 0]]]

def bitlist(x,digit):
    res = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        res[i]=now%2
        now = now >> 1
    return res

ans = 0
for i in range(2**n):
    flag = 1
    nowbit = bitlist(i,n)
    for j in range(n):
        for k in range(ms[j]):
            if nowbit[j]==1:
                if say[j][k][1] != nowbit[say[j][k][0]-1]:
                    flag = 0
    if flag == 1:
        ans = max(ans, sum(nowbit))

print(ans)


Measured memory_bytes: 3064
#include<stdio.h>
#include<math.h>
int main()
{
	int a,b,c;
	while(scanf("%d%d%d",&a,&b,&c)!=EOF)
	{
		int yes=0;
		if(a==b&&b==c)
		{
			yes=1;
		}
//		if(b==c)
//		{
//			if(a+b>c&&a-b<c&&a+c>b&&a-c<b&&b+c>a&&b-c<a) yes=1;
//		}
//		if(c==a)
//		{
//			if(a+b>c&&a-b<c&&a+c>b&&a-c<b&&b+c>a&&b-c<a) yes=1;
//		}
		if(yes) printf("Yes");
		else    printf("No");
		printf("\n");
	}
	return 0;
 } 

Measured memory_bytes: 128
class Dice():
    def __init__(self, numbers):
        self.top = numbers[0]
        self.s = numbers[1]
        self.e = numbers[2]
        self.w = numbers[3]
        self.n = numbers[4]
        self.bot = numbers[5]
    def rot(self, dir):
        top, s, e, w, n, bot = (self.top, self.s, self.e, self.w, self.n, self.bot)
        if dir == 'N':
            self.top = s
            self.s = bot
            self.e = e
            self.w = w
            self.n = top
            self.bot = n
        elif dir == 'S':
            self.top = n
            self.s = top
            self.e = e
            self.w = w
            self.n = bot
            self.bot = s
        elif dir == 'E':
            self.top = w
            self.s = s
            self.e = top
            self.w = bot
            self.n = n
            self.bot = e
        elif dir == 'W':
            self.top = e
            self.s = s
            self.e = bot
            self.w = top
            self.n = n
            self.bot = w
    def getTop(self):
        return self.top
    def rotMany(self, command):
        for dir in command:
            self.rot(dir)

cmd_list = [
    "SEN", "SEN", "SEN", "SENN",
    "SEN", "SEN", "SEN", "SENN",
    "SEN", "SEN", "SEN", "SENN",
    "SEN", "SEN", "SEN", "SENE",
    "SEN", "SEN", "SEN", "SENEE",
    "SEN", "SEN", "SEN", ""
]

def same_dice(D1, D2):
    for cmd in cmd_list:
        if D1.top == D2.top and D1.s == D2.s and D1.w == D2.w and D1.e == D2.e and D1.n == D2.n and D1.bot == D2.bot:
            return True
        else:
            D1.rotMany(cmd)
    return False

n = int(input())
D = []
for _ in range(n):
    li = list(map(int, input().split()))
    D.append(Dice(li))

for i in range(0, n-1):
    for j in range(i+1, n):
        if same_dice(D[i], D[j]):
            print("No")
            exit(0)
print("Yes")


Measured memory_bytes: 5612
#include<cstdio>
#include<cmath>
using namespace std;
int n;
double x,y;
struct point{
    double x,y;
    point(double x=0,double y=0):x(x),y(y){}
    point operator +(point a){
        return point(x+a.x,y+a.y);
    }
    point operator -(point a){
        return point(x-a.x,y-a.y);
    }
    point operator *(double a){
        return point(x*a,y*a);
    }
    void print(){
        printf("%.10lf %.10lf\n",x,y);
    }
}p[5],ans;
typedef point vector;
struct segment{
    point p1,p2,base;
    segment(point a,point b){
        p1=a,p2=b,base=b-a;
    }
};
double cross(vector a,vector b){
    return a.x*b.y-a.y*b.x;
}
void cp(segment s1,segment s2){
    double d1=abs(cross(s2.base,s1.p1-s2.p1));
    double d2=abs(cross(s2.base,s1.p2-s2.p1));
    double t=d1/(d1+d2);
    ans=s1.p1+s1.base*t;
    ans.print();
}
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;++i){
        for(int j=1;j<=4;++j){
            scanf("%lf %lf",&x,&y);
            p[j]=point(x,y);
        }
        cp(segment(p[1],p[2]),segment(p[3],p[4]));
    }
    return 0;
}


Measured memory_bytes: 2736
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<stack>
#include<cstdio>
#include<cmath>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<int,P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
#define mp1(a,b,c) P1(a,P(b,c))

const int INF=1000000001;
const int dir_4[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
const int dir_8[8][2]={{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};

int main(){
	int n;
	int A[3002];
	int a[3002],b[3002];
	scanf("%d",&n);
	rep1(i,n)scanf("%d",&A[i]);
	rep(i,n-1)scanf("%d%d",&a[i],&b[i]);
	
	vector<int> vec;
	rep1(i,n)vec.pb(A[i]);
	sor(vec);
	uniq(vec);
	
	int used = 0;
	rep(x,vec.size()){
		int cnt[3002] = {};
		/*rep(i,n-1){
			if(A[a[i]] < A[b[i]])cnt[b[i]] ++;
			if(A[b[i]] < A[a[i]])cnt[a[i]] ++;
		}*/
		rep1(i,n){
			if(A[i] == vec[x]){
				A[i] = -1;
				used ++;
			}
		}
		rep(i,n-1){
			if(A[a[i]] == -1){
				if(A[b[i]] != -1 && A[b[i]] != INF){
					A[b[i]] = INF;
					used ++;
				}
			}
			if(A[b[i]] == -1){
				if(A[a[i]] != -1 && A[a[i]] != INF){
					A[a[i]] = INF;
					used ++;
				}
			}
		}
	}
	
	vector<int> ans;
	rep1(i,n){
		if(A[i] == INF)ans.pb(i);
	}
	rep(i,ans.size()){
		printf("%d%c",ans[i],(i+1==ans.size())?'\n':' ');
	}
}



Measured memory_bytes: 384