akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <functional>
#include <climits>
#include <cstring>
#include <unordered_map>

using namespace std;

#define int long long
#define rep(i, n) for (int i=0;i<(int)(n);++i)
#define rep1(i, n) for (int i=1;i<=(int)(n);++i)
#define range(i, l, r) for (int i=l;i<(int)(r);++i)
#define rrange(i, l, r) for (int i=r-1;i>=(int)(l);--i)
#define unless(a) if(!(a))
#define all(a) begin(a),end(a)
#define fst first
#define scd second
#define PB emplace_back
#define PPB pop_back

using vi=vector<int>;
using pii=pair<int, int>;
using ll=long long;

bool chmin(int&a,int b){return a>b?(a=b,true):false;}
bool chmax(int&a,int b){return a<b?(a=b,true):false;}
//int read(){int a;scanf("%lld",&a);return a;}

constexpr int TEN(int n){return n==0?1:10*TEN(n-1);}

const int inf = TEN(9) + 10;
const int mod = TEN(9) + 7;

int N, M, Q;
int a[55], b[55], c[55], d[55];
int arr[13];

int ans = 0;

void dfs(int cur, int mx)
{
	if (cur == N) {
		int s = 0;
		rep(i, Q) {
			if (arr[b[i]] - arr[a[i]] == c[i]) {
				s += d[i];
			}
		}

		chmax(ans, s);

		return;
	}

	range(i, mx, M + 1) {
		arr[cur] = i;
		dfs(cur + 1, i);
	}
}

signed main()
{
	cin >> N >> M >> Q;

	rep(i, Q) {
		cin >> a[i] >> b[i] >> c[i] >> d[i];
		--a[i], --b[i];
	}

	dfs(0, 1);

	cout << ans << endl;
}



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

int main(void){
    stack<int> s;
    string p;
    while(cin >> p){
        if(p == "+" ) {
            int b = s.top(); s.pop();
            int a = s.top(); s.pop();
            s.push(a + b);
        }else if(p == "-" ) {
            int b = s.top(); s.pop();
            int a = s.top(); s.pop();
            s.push(a - b);
        }else if(p == "*" ) {
            int b = s.top(); s.pop();
            int a = s.top(); s.pop();
            s.push(a * b);
        }else{
            s.push(stoi(p));
        }
    }
    cout << s.top() << endl;
    
    return 0;
}


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

int main()
{
    long long int n;
    cin >> n;
    vector<long long int> v;
    for(long long int i=0;i<n;i++)
    {
        long long int p;
        cin >> p;
        v.push_back(p);
    }
    long long int i;
    for(i=0;i<n;i++)
    {
        if(v[i]%2==0)
        {
            if(v[i]%3!=0 && v[i]%5!=0)
            {
                break;    
            }
        }
    }
    if(i!=n)
    {
        cout << "DENIED" << endl;
    }
    else
    {
        cout << "APPROVED" << endl;
    }
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    char S[4], T[4];
    int i, n = 0;

    scanf("%s",S);
    scanf("%s",T);

    for (i = 0; i < 3; i++){
        if (T[i] == S[i])
            n++;
    }
    printf("%d\n",n);

    return 0;
}

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

int n;
int t[10002];
int dp[5002][2], tmp[5002][2];

int minCost(const int &a, const int &b){
  if(a == -1) return b;
  if(b == -1) return a;
  return a > b ? b : a;
}

int solve(){
  memset(tmp, -1, sizeof(tmp));
  tmp[1][0] = tmp[0][1] = 0;

  for(int i = 1; i < n; i++){
    memset(dp, -1, sizeof(dp));

    for(int j = 0; j <= n / 2; j++){
      for(int pre = 0; pre < 2; pre++){
        if(tmp[j][pre] == -1) continue;

        for(int next = 0; next < 2; next++){
          if(pre == next){
            if(next == 0) dp[j + 1][next] = minCost(dp[j + 1][next], tmp[j][pre]);
            else          dp[j][next] = minCost(dp[j][next], tmp[j][pre]);
          }
          else{
            if(next == 0) dp[j + 1][next] = minCost(dp[j + 1][next], tmp[j][pre] + t[i - 1]);
            else          dp[j][next] = minCost(dp[j][next], tmp[j][pre] + t[i - 1]);
          }
        }
      }
    }

    for(int j = 0; j <= n / 2; j++){
      for(int k = 0; k < 2; k++){
        tmp[j][k] = dp[j][k];
      }
    }
  }

  return minCost(dp[n / 2][0], dp[n / 2][1]);
}

int main(){
  scanf("%d", &n);
  for(int i = 0; i < n - 1; i++){
    scanf("%d", &t[i]);
  }
  printf("%d\n", solve());
}

Measured memory_bytes: 952
#include <stdio.h>
int main(void){
    double weight;
    
    while(scanf("%lf",&weight)!=EOF){
        if(weight<=48.00)puts("light fly");
        else if(weight<=51.00)puts("fly");
        else if(weight<=54.00)puts("bantam");
        else if(weight<=57.00)puts("feather");
        else if(weight<=60.00)puts("light");
        else if(weight<=64.00)puts("light welter");
        else if(weight<=69.00)puts("welter");
        else if(weight<=75.00)puts("light middle");
        else if(weight<=81.00)puts("middle");
        else if(weight<=91.00)puts("light heavy");
        else puts("heavy");
    }
    return 0;
}

Measured memory_bytes: 608
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int a,b,c;
    cin>>a>>b>>c;
    long long int count=0;
    long long int now=0;
    long long int ans=0;
    while (1) {
        if (count==10000000) {
            cout<<-1<<endl;
            break;
        } else {
            if (now<c&&now+a>=c) {
                cout<<ans+c-now<<endl;
                break;
            } else {
                now+=a+b;
                ans+=a+b;
                if (now>=60) {
                    now-=60;
                }
                count++;
            }
        }
    }
}



Measured memory_bytes: 3108
# -*- coding: utf-8 -*-
"""
Created on Sun May 17 20:56:22 2020

@author: Kanaru Sato
"""

k = int(input())
s = list(input())
n = len(s)

if n <= k:
    print("".join(s))
else:
    print("".join(s[:k])+"...")

Measured memory_bytes: 9164
def canContinue(d, p):
    distance = abs(d[p][1] - d[p - 1][1]) + abs(d[p][2] - d[p - 1][2])
    if d[p][0] - d[p - 1][0] < distance:
        return False
    remaining_action = d[p][0] - d[p - 1][0] - distance
    if remaining_action % 2 == 0:
        return True
    else:
        return False

N = int(input())
d = []
d.append([0,0,0])
i = 0
while i < N:
    d.append(list(map(int, input().split())))
    i += 1
position = 1
answer = True
while position < N + 1:
    if canContinue(d, position):
        i += 1
    else:
        answer = False
        break
    position += 1
if answer:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 27300
#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(){
    ll n,a,b,c,d;
    cin >> n >> a >> b;
    c = a+b;
    d = n/c;
    //cout << "d" << d;
    n -=d*c;
    ll e;
    e = min(n,a);
    cout << d*a + e << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <list>
#include <queue>
#include <sstream>
#include <cmath>
#include <functional>
#include <climits>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define reps(s,i,n) for(int i=s;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define skip(i,n,p) for(int i=0;i<n;i+=p)
#define all(a)  (a).begin(),(a).end()
#define int64 long long
#define debug cerr << __FILE__ << ":" << __LINE__ << endl;
#define INF 2147483647

struct Init {
    Init() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout.precision(20);
        cout << fixed;
    }
} init;

template <typename _Ty>
ostream& operator << (ostream& ostr, const vector<_Ty>& v) {
    for(int i = 0; i < (int) v.size(); i++) {
        ostr << v[i] << (i + 1 != v.size() ? " " : "");
    }
    return ostr;
}

template <typename _K, typename _V>
ostream& operator << (ostream& ostr, const map<_K, _V>& v) {
    ostr << "{";
    for (auto iter = v.begin(); iter != v.end(); ++iter) {
        ostr << (*iter).first << ": " << (*iter).second << ", ";
    }
    ostr << "}";
    return ostr;
}

template <typename _K>
ostream& operator << (ostream& ostr, const set<_K>& v) {
    for (auto iter = v.begin(); iter != v.end(); ++iter) {
        ostr << *iter << (iter != v.end() ? " " : "");
    }
    return ostr;
}

template <typename _K, typename _V>
ostream& operator << (ostream& ostr, const pair<_K, _V>& v) {
    ostr << v.first << " " << v.second;
    return ostr;
}

int64 powmod(int64 n, int64 count, int64 mod) {
    if (count == 0) return 1;
    if (count % 2 == 0) {
        int64 t = powmod(n, count / 2, mod);
        return t * t % mod;
    }
    return n * powmod(n, count - 1, mod) % mod;
}

int64 ncr(int64 n, int64 r, int64 mod) {
    int64 a;
    if (n < r) a = min(n, r - n);
    else a = min(n - r, r);

    int64 res = 1;
    rep(i, a) {
        res = res * (n - i) % mod;
        res = res * powmod(i + 1, mod - 2, mod) % mod;
    }

    return res;
}

int main() {
    int a, b; cin >> a >> b;
    cout << a + (b / 2) << endl;
}


Measured memory_bytes: 256
while True:
    x, y, s = map(int , input().split())
    if x == 0 and y == 0 and s == 0:
        break

    ans = 0
    for a in range(1, s):
        for b in range(1, a + 1):
            pre = a * (100 + x) // 100 + b * (100 + x) // 100
            if pre == s:
                now = a * (100 + y) // 100 + b * (100 + y) // 100
                ans = max(ans, now)
    print(ans)


Measured memory_bytes: 5600
s = input()
q = int(input())
Q = []

for i in range(q):
    Q.append([x for x in input().split()])

bef = ""
aft = ""
flag = True

for i in Q:
    if i[0] == "1":
        flag = not(flag)
    else:
        if i[1] == "1":
            if flag == True:
                bef = i[2]+bef
            else:
                aft = aft+i[2]
        else:
            if flag == True:
                aft = aft+i[2]
            else:
                bef = i[2]+bef

if flag:
    print(bef+s+aft)
else:
    print(aft[::-1]+s[::-1]+bef[::-1])

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

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

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

int p[3], k;
vector<ul> p1, p23, all;

string addChar(string s, char c, int num = 1){
    rep(i,num){
        s += c;
    }

    return s;
}

int main(){
    int sx, sy;
    int tx, ty;

    cin >> sx >> sy >> tx >> ty;
    
    string move = "";
    int x = tx - sx;
    int y = ty - sy;
    move = addChar(move, 'U', y);
    move = addChar(move, 'R', x);
    move = addChar(move, 'D', y);
    move = addChar(move, 'L', x);

    move += 'L';
    move = addChar(move, 'U', y + 1);
    move = addChar(move, 'R', x + 1);
    move += "DR";
    move = addChar(move, 'D', y + 1);
    move = addChar(move, 'L', x + 1);
    move += 'U';

    cout << move  << endl;
} 

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

using namespace std;
using ll =long long;
typedef pair<int,int> P;
#define SORT(a) sort((a).begin(),(a).end())
#define REV(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

void coY() {cout <<"Yes"<<endl;}
void coN(){cout <<"No"<<endl;}
 
//Write From this Line

//const ll mod = 1e9+7;
//const ll mod = 998244353;
int main()
{
	ll n, d;
	cin >> n >> d;
	ll ans= 0;
	rep(i,n){
		ll x, y;
		cin >> x >> y;

		if(x*x+y*y <= d*d) ans++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 3616
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

// c++11
#include <array>
#include <tuple>
#include <unordered_map>
#include <unordered_set>

#define mp make_pair
#define mt make_tuple
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

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

const int INF = 1 << 29;
const double EPS = 1e-9;
const ll MOD = 1000000007;

const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
ll H,W,h,w;
const int MAX_HW = 510;
ll board[MAX_HW][MAX_HW];
int main() {
  cin >> H >> W >> h >> w;
  if (H % h == 0 and W % w == 0){
    cout << "No" << endl;
    return 0;
  }
  if (h == 1 and w == 1){
    cout << "No" << endl;
    return 0;
  }
  ll sum = 0;
  ll a = (1e9 - 1)/ (h * w - 1);
  for (int i = 0; i < H; i++){
    for (int j = 0; j < W; j++){
      board[i][j] = a;
      if (i % h == h - 1 and j % w == w - 1){
        board[i][j] = -((h * w - 1) * a + 1);
      }
      sum += board[i][j];
    }
  }
  if (sum > 0){
    cout << "Yes" << endl;
    for (int i = 0; i < H; i++){
      for (int j = 0; j < W; j++){
        cout << board[i][j] << " ";
      }
      cout << endl;
    }
  }else{
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 4864
inums = input()
# [int(i)for i in input().split()]
nums = []
for i in inums:
    nums.append(int(i))
o = []
for n in nums:
    if n == 1:
        o.append("9")
    elif n==9:
        o.append("1")
    else:
        o.append(str(n))
print("".join(o))


Measured memory_bytes: 2940
#include<stdio.h>
#define REP(i,n) for(i=1;i<n+1;i++)

int main(void)
{
  int n,k,i;
  scanf("%d%d",&n,&k);

  double ans = 0.0;
  double tmp;
  int now;


  REP(i,n)
  {
    tmp = 1.0/n;
    now = i;
    while(now<k)
   {
      now*=2;
      tmp/=2;
    }
    ans+=tmp;
  }
  printf("%.9lf\n",ans);
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b){
    if(b == 0)return a;
    return gcd(b,a%b);
}

int main(){
    int N,X;
    cin >> N >> X;
    vector<ll> d(N);
    for(int i = 0; i < N ;i++) {
        int x;cin >> x;
        d[i] = abs(x-X);
    }
    sort(d.begin(),d.end());
    int ans = 0;
    for(int i = 0; i < N; i++){
       ans = gcd(d[i],ans);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    ArrayList<Integer> a = new ArrayList<>();
    
    for(int i=0;i<n;i++){
      int b = sc.nextInt();
      a.add(b);
    }
    Collections.sort(a);
    
    int ans = a.get(n/2) - a.get((n/2)-1);
    System.out.println(ans);
  }
}

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

const int INF = 1LL << 60;

signed main(void){
  
  int n; cin >> n;
  vector<int> dp(101000,INF);
  
  for(int i = 0; i < n; i++){
    int a; cin >> a;
    
    int itr = lower_bound(dp.begin(),dp.end(),a)-dp.begin();
    
    dp[itr] = a;
  }

  for(int i = 101000-1; i >= 0; i--){
    if( dp[i] != INF ){ cout << i+1 << endl; return 0;}
    
  }

  return 0;
} 


Measured memory_bytes: 3636
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
using namespace std;

typedef long long ll;

#define INF 10e17 // 4倍しても(4回足しても)long longを溢れない
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<int>())

int main() {
  vector<int> a(5);
  rep(i,5) {
    cin >> a[i];
  }

  sorti(a);
  ll ans = 10000000;
  do {
    ll temp = 0;
    int cnt = 0;
    for (auto itr : a) {
      cnt += 1;
      if (itr % 10 != 0 and cnt != 5) {
        temp += itr + (10 - itr % 10);
      } else {
        temp += itr;
      }
    }
    ans = min<ll>(ans, temp);
  } while(next_permutation(a.begin(), a.end()));

  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <queue>
#include <vector>
#include <set>
using namespace std;
int main() {
	int N;
	bool ans = true;
	cin >> N;
	vector<string>S(N);
	for (int i = 0; i < N; i++)
	{
		cin >> S[i];
		if (i != 0)if (!(S[i - 1][S[i - 1].size() - 1] == S[i][0]))ans = false;
		if (!ans)break;
	}
	if (ans) {
		sort(S.begin(), S.end());
		for (int i = 0; i < N; i++)
		{
			if (i != 0)if (S[i - 1] == S[i])ans = false;
			if (!ans)break;
		}
	}
	cout << (ans ? "Yes" : "No");
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define N 500005
using namespace std;

typedef pair<int,int> P;

int n, C[N*2];
P AB[N];

signed main(){
  
  cin>>n;
  
  for(int i=0;i<n;i++) cin>>AB[i].first>>AB[i].second;
  
  sort( AB, AB+n );
  
  vector<P> v;
  
  for(int i=0;i<n;i++){
    
    v.push_back(P( 0, AB[i].second ));
        
    if( i != n-1 ) v.push_back(P(AB[i+1].first - AB[i].first, 0));
  }
  
  for(int i=0;i<(int)v.size();i++) C[i] = v[i].second - v[i].first;

  for(int i=1;i<(int)v.size();i++) C[i] += C[i-1];
  
  int ans = 0, minc = 0;
  
  for(int i=0;i<(int)v.size();i++){

    int cost = C[i];
    
    ans = max( ans, cost - minc );
    
    minc = min( minc, cost );
  }

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



Measured memory_bytes: 34156
import math
x = int(input())
'''
逐次探索だとTLE
def check():
    prime_li = [2]
    if x==2:
        return 2
    for i in range(3,x+1,2):
        if all(i%p!=0 for p in prime_li):
            prime_li.append(i)

    for i in range(x+1,10**6):
        if all(i%p!=0 for p in prime_li):
            return i
'''
#エラトステネスの篩でxまでの素数を求める
def get_primeli(x):
    prime_li=[]
    serch_li=list(range(2,x+1))
    while True:
        if serch_li[0]>math.sqrt(x):
            prime_li.extend(serch_li)
            break
        else:
            y = serch_li.pop(0)
            prime_li.append(y)
            serch_li = [n for n in serch_li if n%y!=0]
    return prime_li

prime_li = get_primeli(x)

#x以上の素数を探索
for n in range(x,10**6):
    if n in prime_li:
        print(n)
        break
    if all(n%p!=0 for p in prime_li):
        print(n)
        break

        




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

#define ll long long
#define mk make_pair
#define pb push_back
#define ff first
#define sc second



using namespace std;


int main(){
   
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);
   
   int N; cin >> N;
   vector<string> words;
   string ans = "Yes";
   string w; cin >> w;
   words.push_back(w);
   N--;
   while(N--){
      w; cin >> w;
      string last = words[words.size()-1];
      if(count(words.begin(), words.end(), w)){
         ans = "No";
      }
      if(w[0] != last[last.size()-1]){
         ans = "No";
      }
      words.push_back(w);
   } 

   cout << ans;
   return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string st;
int sumt,sums,sum,i;
int main()
{
    std::ios::sync_with_stdio(false);
    cin>>st;
    while(i<st.size())
    {
        if(st[i]=='S') sums++;
        else if(sums) sumt++;
        if(sums>=sumt)
        {
            sum+=min(sums,sumt)*2;
            sums-=min(sums,sumt);
            sumt=0;
        }
        i++;
    }
    cout<<st.size()-sum<<endl;
    return 0;
}

Measured memory_bytes: 720
import Control.Applicative
import Data.ByteString.Char8 (ByteString)
import qualified Data.ByteString.Char8 as B

main :: IO ()
main = solve <$> B.getLine >>= B.putStrLn

solve :: ByteString -> ByteString
solve = B.map f
  where
    f '?' = 'D'
    f x = x


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

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

int mod = 1000000007;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N; cin >> N;
    if(N == 1) cout << "Hello World" << endl;
    else{
        int a, b; cin >> a >> b;
        cout << a+b << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
string s; int n;
int main() {
	cin >> s >> n;
	for (int i = 0; i < s.size() - 1; i++) {
		int t = (26 - (s[i] - 'a')) % 26;
		if (n >= t) n -= t, s[i] = 'a';
	}
	s.back() = ((int)s.back() - 97 + n) % 26 + 'a';
	cout << s << endl;
	return 0;
}

Measured memory_bytes: 512
# -*- coding: utf-8 -*-


def main():
    n, k = map(int, input().split())
    h = sorted(list(map(int, input().split())), reverse=True)
    count = 0
    ans = 0

    for hi in h:
        if count >= k:
            ans += hi

        count += 1

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 26024
#include <stdio.h>
 
int main(void) {
    int n,m;
    scanf("%d%d", &n,&m);
    if(m&1) {
        long long t = n/m;
        printf("%lld", t*t*t);
    } else {
        long long t = n/m;
        long long t2 = (n+m/2)/m;
        printf("%lld", t*t*t+t2*t2*t2);
    }
}

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

ll int pos[100005],sum[100005];

int main(void)
{
    int n,k;
    cin >>n>>k;
    for(int i=1; i<=n; i++) {
        scanf("%lld", &pos[i]);
        sum[i]=sum[i-1]+pos[i];
    }

    ll int ans=1e17;
    for(int i=1; i<=n-k+1; i++) {
        ans =min(ans, pos[i+k-1]-pos[i]+min(abs(pos[i+k-1]), abs(pos[i])));
    }

    printf("%lld\n", ans);

    return 0;
}

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

#define MAX 10000001

bool p[MAX];

int main(){
  memset(p, 1, sizeof(p));
  p[0] = p[1] = 0;
  for(int i = 0 ; i < MAX ; i++){
    if(p[i]){
      for(int j = 2 * i ; j < MAX ; j += i){
	p[j] = 0;
      }
    }
  }

  int n;
  while(cin >> n, n){
    int next, prev;
    if(p[n] == 1) cout << 0 << endl;

    else{
      for(int i = n ; ; i++){
	if(p[i] == 1){
	  next = i;
	  break;
	}
      }
      for(int i = n ; ; i--){
	if(p[i] == 1){
	  prev = i;
	  break;
	}
      }
      cout << next - prev << endl;
    }
  }
  return 0;
}
   

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

int main(void)
{
    char op;
    int a, b,i=0, x[3000],y[3000];
       
    while(cin>>a>>op>>b){
        if(op == '?'){
            break;
        }
        x[i]=a;
        y[i]=b;
    
    if(op =='+'){
            cout << x[i]+y[i]<<"\n";
    }
    else if(op == '-'){
            cout << x[i]-y[i]<<"\n";
    }
    else if(op == '*'){
            cout << x[i]*y[i]<<"\n";
    }
    else if(op == '/'){
            cout << x[i]/y[i]<<"\n";
    }
    i++;
    }
    return 0;
}


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


N = int(input())
A = [0] + list(map(int, input().split())) + [0]


total = 0

for i in range(N + 1):
    total += abs(A[i + 1] - A[i])

for i in range(1, N + 1):
    print(total + abs(A[i + 1] - A[i - 1]) - abs(A[i + 1] - A[i]) - abs(A[i] - A[i - 1]))


Measured memory_bytes: 14048
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n = I()
    a = set(LI())
    if len(a) == n:
        print("YES")
    else:
        print("NO")
    return

#Solve
if __name__ == "__main__":
    solve()


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

typedef long long ll;
typedef long double ld;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vstr;

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

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define asd cout << "ok" << endl;

#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define trav(it, m) for(auto it = m.begin(); it it!= m.end(); it++)

const char nl = '\n';
const int MOD = 1e9 +7;
const ll INF = 1e19;
const ld PI = acos((ld)-1);
const int MX = 2e5 + 5;

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

  ll r, d, x;
  cin >> r >> d >> x;
  for(int i = 2001; i <= 2010; i++)
  {
    x = r*x-d;
    cout << x << nl;
  }


return 0;




}


Measured memory_bytes: 3552
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#include<iomanip>
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = n-1; i >= 0; i--)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define lamsort(v,p) sort(v.begin(),v.end(),[](p a, p b){return a.num < b.num;});
#define check(v) rep(i,v.size()) cout << v[i] << " ";\
cout << endl
const long long INF = 1LL<<60;
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; }
typedef long long ll;
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,k; cin >> n >> k;
    vector<int> v(n);
    rep(i,n) cin >> v[i];
    ll ans = 0;
    rep(i,min(k,n)+1) {
        for(int j = 0; i+j<=min(k,n);j++ ) {
            int d = k - i - j;
            ll score = 0;
            vector<int> s;
            rep(r,i) {
                s.push_back(v[r]);
                score += v[r];
            }
            rep(l,j) {
                s.push_back(v[n-1-l]);
                score += v[n-1-l];
            }
            sort(ALL(s));
            rep(m,d) {
                if(m>=s.size()) break;
                if(s[m]>0) break;
                score -= s[m];
            }
            ans = max(ans,score);

        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i, n) for(int i=0;i<(int)n;i++)
#define PI acos(-1)
#define fast_io ios_base::sync_with_stdio(false) ; cin.tie(0); cout.tie(0);
ll mod=1e9+7;

int main(){
    fast_io

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

    for(int i=0;i<=m;i++){
        for(int j=0;j<=n;j++){
            if(j*(m-i)+i*(n-j) == k){
                cout<<"Yes"<<endl;
                return 0;
            }
        }
    }
    cout<<"No"<<endl;
    return 0;

}


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

int main(){
  int n;
  string s;
  cin >> n >> s;

  int max=0,ans=0;
  rep(i,n){
    if(s[i]=='I')ans++;
    else ans--;
    if(max<ans)max=ans;
  }
  cout << max << endl;
}


Measured memory_bytes: 3644
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int N,M;
int A[1<<17],B[1<<17];
bool used[2<<17];
int cumsum[1<<17];
pair<int,int>AB[1<<17];
vector<pair<int,int> >E[1<<17];
vector<pair<int,int> >calc;
main()
{
	cin>>N>>M;
	{//入力をソート・圧縮する
		for(int i=0;i<N;i++)cin>>AB[i].first>>AB[i].second;
		sort(AB,AB+N);
		for(int i=0;i<N;i++)
		{
			A[i]=AB[i].first;
			B[i]=AB[i].second;
		}
		for(int i=0;i<M;i++)
		{
			int L,R;cin>>L>>R;
			L=lower_bound(A,A+N,L)-A;
			R=upper_bound(A,A+N,R)-A;
			if(L<R)E[L].push_back(make_pair(R,i));
		}
	}
	{//掃き出す
		for(int i=0;i<N;i++)
		{
			if(E[i].empty())continue;
			sort(E[i].begin(),E[i].end());
			for(int j=E[i].size()-1;j>=1;j--)//逆順に隣接要素を見る
			{
				int L=E[i][j-1].first,R=E[i][j].first;
				if(L<R)
				{
					E[L].push_back(make_pair(R,E[i][j].second));
					calc.push_back(make_pair(E[i][j-1].second,E[i][j].second));//第 first 行を第 second 行に足した
				}
			}
		}
	}
	{//x'を求める
		for(int i=0;i<N;i++)
		{
			if((B[i]+cumsum[i])%2==1)
			{
				if(E[i].empty())//その行に1の要素がない
				{
					cout<<-1<<endl;
					return 0;
				}
				pair<int,int>p=E[i][0];//最初の要素は掃き出されていないため、それを使う
				used[p.second]=true;
				cumsum[i]++;
				cumsum[p.first]--;//imos法
			}
			cumsum[i+1]+=cumsum[i];
		}
	}
	{//掃き出す操作を巻き戻す
		reverse(calc.begin(),calc.end());
		for(pair<int,int>p:calc)used[p.first]^=used[p.second];//第 second 列を第 first 列に足す
	}
	{//出力
		int cnt=0;
		for(int i=0;i<M;i++)cnt+=used[i];
		cout<<cnt<<endl;
		for(int i=0;i<M;i++)
		{
			if(used[i])cout<<i+1<<(--cnt?" ":"\n");
		}
	}
}

Measured memory_bytes: 37992
from itertools import accumulate

N = int(input())
A = list(map(int,input().split()))
A = sorted(A)
S = list(accumulate(A))
AS = []
flg = False
count = 0

for i in range(N-1):
  AS.append(S[i]*2 - A[i+1])
for j in range(N-2,-1,-1):
  if AS[j] < 0:
    count = j+1
    break
print(len(A)-count)

Measured memory_bytes: 16092
#include <iostream>
#include <vector>

std::vector<int> A;
int n;
int count = 0;

std::vector<int> insertionSort(std::vector<int> A, int n, int g)
{
	for(int i = g; i < n; i++) {
		int v = A[i], j = i - g;
		while(j >= 0 && A[j] > v) {
			A[j + g] = A[j];
			j -= g;
			count++;
		}
		A[j + g] = v;
	}
	return A;
}

std::vector<int> shellSort(std::vector<int> A, int n)
{
	int m = 0, G[100];
	count = 0;
	while(n >> m) m++;
	std::cout << m << std::endl;
	for(int i = 0; i < m; i++){
		G[i] = 1 << (m - i - 1);
		std::cout << G[i] << (i == m - 1 ? '\n' : ' ');
	}
	for(int i = 0; i < m; i++) {
		A = insertionSort(A, n, G[i]);
	}
	return A;
}

int main(void)
{
	std::cin >> n;
	for(int i = 0; i < n; i++) {
		int t;
		std::cin >> t;
		A.push_back(t);
	}
	A = shellSort(A, n);
	std::cout << count << std::endl;
	for(int i = 0; i < n; i++) {
		std::cout << A[i] << std::endl;
	}
	return 0;
}


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

int main(){
	string s;
	cin>>s;
	bool ok=true;
	bool s_ok=false;
	if(s[0]!='A')ok=false;
	if(s[1]=='C')ok=false;

	for(int i=0;i<s.size();++i){
		if(i==0)continue;
		char a=s[i];

		if(isupper(a) && a!='C')ok=false;
		if(2<=i && a=='C'){
			if(i==s.size()-1)continue;
			if(s_ok==true){
				s_ok=false;
				break;
			}
			
			s_ok=true;
		}
	}
	if(!s_ok)ok=false;

	if(ok)cout<<"AC"<<endl;
	else cout<<"WA"<<endl;
}

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

using namespace std;

int main()
{
	int a[5];
	
	for (int i=1;i<=3;++i)
	    cin>>a[i];
	    
	sort(a+1,a+3+1);
	
	cout<<a[1]*a[2]/2<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)  //  repマクロ
#define leng(n) (int)(log10(n)+1)  //  桁数leng
#define INF 9223372036854775807 //  巨大数INF
using namespace std;
int gcd(int a, int b) {
    if (b == 0)
        return a;

    return gcd(b, a % b);
}

int lcm(int a, int b) {
    return a * b / gcd(a, b);
}

int f(int n, int c, int d){
  return (n - n/c - n/d + n/lcm(c,d));
}

signed main() {
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  cout << f(B,C,D) - f(A-1,C,D) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <cstring>
#include <stdio.h>
#include <iomanip>

using namespace std;

typedef long long int lli;

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

	int A[5];
	std::memset(A, -1, sizeof(A));

	int s, c;
	int ans = 0;
	for (int i = 0; i < M; i++) {
		cin >> s >> c;
		if (A[s] != -1 && A[s] != c) {
			ans = -1;
		}
		else {
			A[s] = c;
		}
	}

	if (N != 1) {
		if (A[1] == 0) {
			ans = -1;
		}
		else if (A[1] == -1) {
			A[1] = 1;
		}
	}
	else {
		if (A[1] == -1) {
			A[1] = 0;
		}
	}

	if (ans != -1) {
		for (int i = 1; i <= N; i++) {
			if (A[i] == -1) {
				A[i] = 0;
			}
			cout << A[i];
		}
		cout << endl;
	}
	else {
		cout << -1 << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <string>

using namespace std;

void solve(int X, int Y) {
  int ans = X + Y / 2;
  printf("%d\n", ans);
}

int main() {
  int X, Y;
  cin >> X >> Y;
  solve(X, Y);
  return 0;
}

Measured memory_bytes: 888
using System;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var sum = 0L;
            for (int i = 1; i <= n; i++)
            {
                if (i % 3 == 0 || i % 5 == 0) continue;
                sum += i;
            }
            Console.WriteLine(sum);
        }
    }
}


Measured memory_bytes: 27532
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF (1LL<<50)
#define MOD 1000000007

int main(){
    double a,b,x;
    cin >> a >> b >> x;
    double ans;
    if(x>(a*a*b/2)){
        // x = a*a*(b-atanθ/2)
        ans = atan((2*a*a*b-2*x)/(a*a*a));
    }else if(x == (a*a*b/2)){
        ans = atan(b/a);
    }else{
        // x = (a*b*b)/(2*tanθ)
        ans = atan(a*b*b/(2*x));
    }
    cout << setprecision(9) << ans*(180/acos(-1)) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdlib>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cstring>

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;

#define SIZE(x) (int((x).size()))
#define rep(i,l,r) for (int i=(l); i<=(r); i++)
#define repd(i,r,l) for (int i=(r); i>=(l); i--)
#define rept(i,c) for (typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)

#ifndef ONLINE_JUDGE
#define debug(x) { cerr<<#x<<" = "<<(x)<<endl; }
#else
#define debug(x) {}
#endif

int a[100010];

void lemon()
{
	int n;
	scanf("%d",&n);
	rep(i,1,n) scanf("%d",&a[i]);
	int cnt=0;
	rep(i,1,n) if (a[a[i]]==i && a[a[a[i]]]==a[i]) cnt++;
	printf("%d\n",cnt/2);
}

int main()
{
	ios::sync_with_stdio(true);
	#ifndef ONLINE_JUDGE
		//freopen("b.in","r",stdin);
	#endif
	lemon();
	return 0;
}



Measured memory_bytes: 640
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        if (scanner.hasNextLine()) {
            String[] array = scanner.nextLine().split(" ");
            int a = Integer.parseInt(array[0]);
            int b = Integer.parseInt(array[1]);

            int p = a + b;
            int d = a - b;
            int m = a * b;
            
            if (p <= d && m <= d) {
                System.out.println(d);
            } else if (p <= m) {
                System.out.println(m);
            } else {
                System.out.println(p);
            }
        }
    }
}

Measured memory_bytes: 23764
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>
#include <cassert>
#include <functional>
#include <set>
#include <deque>
#include <list>
using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
const int INF = 1<<29;
#define LNF __LONG_LONG_MAX__
const ll MOD = 1000000007;
const int MAX = 200000;

long long 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;
    }
}

// 二項係数計算
long long 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;
}
// 法mでのaの逆元を計算
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//最大公約数
int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }
//最小公倍数
int lcm(int x, int y) { return x / gcd(x, y) * y; }
// nが大きく,kが10^7程度の時の二項係数
long long com[200005];
void combination(long long n,long long k){
    com[0] = 1;
    for(int i=1;i<=k;i++){
        com[i] = (com[i-1]*(n-i+1)%MOD)*modinv(i,MOD)%MOD;
    }
}

int main(){
    ll N,M,K; cin >> N >> M >> K;
    vector<ll> x(N+1,0);
    vector<ll> y(M+1,0);
    for(int i=0;i<N;i++){
        ll A; cin >> A;
        x[i+1] = A+x[i];
    }
    for(int i=0;i<M;i++){
        int B; cin >> B;
        y[i+1] = B+y[i];
    }
    ll out=0;
    for(int i=0;i<=N;i++){
        ll t = x[i];
        auto p=upper_bound(y.begin(),y.end(),K-t);
        int n = p - y.begin();
        n--;
        if(t+y[n]<=K){
            out = max(out,(ll)(i+n));
        }
        //cerr << i << "\t" << n << "\t" << t << "\t" << y[n] << "\t" << t+y[n] << endl;
    }
    cout << out << endl;
    return 0;
}


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

long modPow(long a, long x, long p) {
    //calculates a^x mod p in logarithmic time.
    long res = 1;
    while(x > 0) {
        if( x % 2 != 0) {
            res = (res * a) % p;
        }
        a = (a * a) % p;
        x /= 2;
    }
    return res;
}

long modInverse(long a, long p) {
    //calculates the modular multiplicative of a mod m.
    //(assuming p is prime).
    return modPow(a, p-2, p);
}

long modBinomial(long n, long k, long p) {
// calculates C(n,k) mod p (assuming p is prime).

    long numerator = 1; // n * (n-1) * ... * (n-k+1)
    for (int i=0; i<k; i++) {
        numerator = (numerator * (n-i) ) % p;
    }

    long denominator = 1; // k!
    for (int i=1; i<=k; i++) {
        denominator = (denominator * i) % p;
    }

    // numerator / denominator mod p.
    return ( numerator* modInverse(denominator,p) ) % p;
}

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

    int X, Y;
    cin >> X >> Y;
    long long cnt = 0;
    if (2 * X < Y || 2 * Y < X)
        cnt = 0;
    else if ((2 * X - Y) % 3 != 0 || (2 * Y - X) % 3 != 0)
        cnt = 0;
    else {
        int a = (2 * X - Y) / 3;
        int b = (2 * Y - X) / 3;
        int total = (X + Y) / 3;
        cnt = modBinomial(total, a, 1000000007);
    }
    cout << cnt << '\n';

    return 0;
}

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

void _149() {
    string s, t;
    cin >> s >> t;
    cout << t + s << endl;
}

void _148() {
    int a, b;
    cin >> a;
    cin >> b;

    int c = 0;
    if ((a != 1) && (b != 1))
        c = 1;
    else if ((a != 2) && (b != 2))
        c = 2;
    else if ((a != 3) && (b != 3))
        c = 3;
    cout << c << endl;
}

void _147() {
    int a, b, c;
    cin >> a >> b >> c;

    if (a + b + c >= 22)
        cout << "bust" << endl;
    else
        cout << "win" << endl;
}

void _146() {
    string s;
    cin >> s;

    vector<string> list = {"SAT", "FRI", "THU", "WED", "TUE", "MON", "SUN"};
    for (int i = 0; i < list.size(); ++i) {
        if (s == list[i])
            cout << i + 1 << endl;
    }
}

void _145() {
    int r;
    cin >> r;
    cout << pow(r, 2) << endl;
}

void _144() {
    int a, b;
    cin >> a >> b;

    if ((a >= 1 && a <= 9) && (b >= 1 && b <= 9))
        cout << a * b << endl;
    else
        cout << -1 << endl;
}

void _143() {
    int a, b;
    cin >> a >> b;

    if (b * 2 >= a)
        cout << 0 << endl;
    else
        cout << a - 2 * b << endl;
}

void _142() {
    int n;
    cin >> n;

    if (n % 2 == 0)
        cout << 1 / 2.0 << endl;
    else
        cout << (n / 2 + 1) / (float)n << endl;
}

void _141() {
    string s;
    cin >> s;

    string w;
    if (s == "Sunny")
        w = "Cloudy";
    else if (s == "Cloudy")
        w = "Rainy";
    else
        w = "Sunny";
    cout << w << endl;
}

int main()
{
    _141();
    return 0;
}



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

int main(void){
  int n, m, p;
  std::cin >> n >> m;
  std::vector<int> road(n);
  for(int i=0; i<m*2; i++){
    std::cin >> p;
    road.at(p-1)++;
  }
  for(int i=0; i<n; i++) std::cout << road.at(i) << std::endl;
  return 0;
}

Measured memory_bytes: 3592
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		int n = sc.nextInt();
		int[] a = new int[n];
		int cnt4 = 0;
		int cnt2 = 0;
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
			if (a[i] % 4 == 0) {
				cnt4++;
			} else if (a[i] % 4 != 0 && a[i] % 2 == 0) {
				cnt2++;
			}
		}
		if (n % 2 == 0) {
			n = n - cnt4 * 2 - cnt2;
		} else {
			n = n - cnt4 * 2;
			if (n == 1) {
				n = 0;
			} else {
				n = n - cnt2;
			}
		}
		if (n <= 0) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 49964
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define lli long long int   //used int to avoid mle
#define ulli unsigned long long int 
#define ld long double
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define loop(i,a,b) for(lli i=a;i<b;i++)
#define initialize(array,size,value) for(lli i=0;i<size;i++) array[i]=value
#define couta(array,size) for(lli i=0;i<size;i++) cout<<array[i]<<" "
#define vl vector<lli>
#define vp vector< pair <lli,lli> >
#define sl set<lli>
#define spl set<pll>
#define msl multiset <lli>
#define msp multiset <pll>
#define pll pair<lli, lli>
#define mll map<lli, lli>              //for( map<lli, lli>::iterator i=temp.begin();i!=temp.end();i++)cout<<i->fi<<" "<<i->se<<endl;
#define mvl map<lli, vl>
#define umll unordered_map<lli, lli>
#define vt vector<pair<lli, pll >  >
#define vf vector<pair<pll,pll > >
#define qu queue<lli>
#define pq priority_queue<lli>
#define dq deque <lli>
#define ptr vector<lli>::iterator
#define bs(array,x) binary_search(array.begin(),array.end(),x)
#define lb(array,x) lower_bound(array.begin(),array.end(),x)
#define ub(array,x) upper_bound(array.begin(),array.end(),x)
#define nobw(array,i,j) upper_bound(array.begin(), array.end(), j)-lower_bound(array.begin(), array.end(), i) //number of numbers between i & j
#define vc clear()
#define fbo find_by_order //returns iterator
#define fok order_of_key //return index
#define endl '\n'
#define sp system("pause");
#define INF 9223372036854775807
#define MINF -9223372036854775808
#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); cerr << endl << "Time elapsed: " << (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms"; return 0
lli mod=1000000007;
//string s=bitset<32>(n).to_string();
typedef tree<lli,null_type,less<lli>,rb_tree_tag, // change both to lli if set is req insted of multiset
tree_order_statistics_node_update> indexed_set;
lli power(lli x, lli y,lli p) 
{ 
    lli res = 1;      // Initialize result 
    x = x % p;  // Update x if it is more than or 
    while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x) % p; 
        y = y>>1; // y = y/2 
        x = (x*x) % p; 
    } 
    return res; 
}
lli modInverse(lli a, lli m) 
{ 
    //int g = gcd(a, m); 
    //if (g != 1) 
      //  cout << "Inverse doesn't exist"; 
    //else
    //{ 
        // If a and m are relatively prime, then modulo inverse 
        // is a^(m-2) mode m 
       // cout << "Modular multiplicative inverse is "
             return  power(a, m-2,m); 
    //} 
} 
lli ncr(lli n,lli r){
    lli res=1;
    for(lli i=n;i>=(n-r+1);i--)res=(res*i)%mod;
    lli res2=1;
    for(lli i=1;i<=r;i++)res2=(res2*i)%mod;
    return ((res*modInverse(res2,mod))%mod);

}  
int main()
{
     ios::sync_with_stdio(0);
    cin.tie(0);
    
        lli n;
        cin>>n;
        lli a,b;
        cin>>a>>b;
        lli ani=power(2,n,mod);
        ani=(ani+mod-1)%mod;
        ani=(ani+mod-ncr(n,a))%mod;
        ani=(ani+mod-ncr(n,b))%mod;
        cout<<ani;


}

Measured memory_bytes: 256
# D - RGB Triplets
from collections import defaultdict


def main():
    _ = int(input())
    S = input().rstrip()
    indices = defaultdict(set)
    for i, c in enumerate(S):
        indices[c].add(i)
    cnt = len(indices["R"]) * len(indices["G"]) * len(indices["B"])
    for c1, c2, c3 in ["RGB", "GBR", "BRG"]:
        cnt -= sum(
            (i + j) % 2 == 0 and (i + j) // 2 in indices[c3]
            for i in indices[c1]
            for j in indices[c2]
        )
    print(cnt)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9676
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const ll mo = 1000000007;
const ll INF = 1LL << 60; //MAX 9223372036854775807
ll ans = 0;

int main()
{
ll n,m;
cin >> n>>m;
vector<ll> G[n];
rep(i,m){
    ll a,b;
    cin >> a>>b;
    G[a-1].push_back(b-1);
    }
ll s,t;
cin >> s>>t;
s--;t--;

queue<pair<int, int>> q;
ll info[n][3]={};
q.push({s,0});

while(!q.empty()){
    pair<int, int> p = q.front();
    q.pop();
    rep(i,G[p.first].size()){
        if(info[G[p.first][i]][(p.second+1)%3]==0){
            info[G[p.first][i]][(p.second+1)%3]=p.second+1;
            q.push({G[p.first][i],p.second+1});
        }
    }
}
if(info[t][0]==0)cout << -1 << endl;
else cout << info[t][0]/3 << endl;
return 0;
}


Measured memory_bytes: 8064
#include <stdio.h>
int main(void){
	int g[12] = {0,3,0,2,0,2,0,0,2,0,2,0};
	int x,y;
	scanf("%d%d",&x,&y);
	if(g[x-1] == g[y-1])printf("Yes");
	else printf("No");	
	return 0;
}

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

string string_build(int a, int b, int c, int d) {
  return to_string(a) + " " + to_string(b) + " " +
         to_string(c) + " " + to_string(d) + "\n";
}

int main()
{
  int h, w;
  cin >> h >> w;

  int move_count = 0;
  string s;
  int a[h][w];
  for (auto i = 0; i < h; i++) {
    for (auto j = 0; j < w; j++) {
      cin >> a[i][j];
      if (j != 0 && a[i][j - 1] % 2 != 0) {
	s += string_build(i + 1, j, i + 1, j + 1);
	a[i][j]++;
	move_count++;
      }
      if (j == w - 1 && i != 0 && a[i - 1][j] % 2 != 0) {
	s += string_build(i, j + 1, i + 1, j + 1);
	a[i][j]++;
	move_count++;
      }
    }
  }
  cout << move_count << endl;
  cout << s;
}


Measured memory_bytes: 5124
import math

N,D=map(int,input().split())
X=[[] for x in range(N)]

for i in range(N):
  X[i]=[int(x) for x in input().split()]

c=0
for i in range(N):
  for j in range(i+1,N):
     d = 0
     for k in range(D):
       d += (X[i][k]-X[j][k])**2
     if int(round(math.sqrt(float(d)))**2) == d:
       c += 1
print(c)


Measured memory_bytes: 3188
main = getContents >>= putStr.unlines.cnt.lines

cnt :: [String] -> [String]
cnt xs = takeWhile (/="") $zipWith cntCase (take (length xs) $map show [1,2..] ) xs

cntCase :: String -> String -> String
cntCase _ "0" = ""
cntCase i x =  "Case "++i++": "++x 

Measured memory_bytes: 6804
#include<bits/stdc++.h>
using namespace std;
typedef long long int llint;
typedef long int lint;
typedef vector<char> vchar;
typedef vector<int> vint;
typedef vector<vector<int>> vvint;
typedef vector<vector<char>> vvchar;
#define vsort(v) sort((v).begin(), (v).end())
#define vrsort(v) sort((v).rbegin(), (v).rend())
#define vreverse(v) reverse((v).begin(), (v).end())
#define pb(a) push_back(a)
#define INF 1000000007
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  //input
  lint n,m,i;cin>>n>>m;vint a(m);
  vector<long long> dp(n+1,0);
  dp[0]=1;dp[1]=1;
  for(i=0;i<m;i++){
    cin>>a[i];dp[a[i]]=-1;
  }
  //caricurate
  for(i=2;i<n+1;i++){
    if(dp[i]!=-1){
      if(dp[i-2]!=-1){dp[i]+=dp[i-2];}
      if(dp[i-1]!=-1){dp[i]+=dp[i-1];}
      
      dp[i]=(dp[i]%1000000007);
    }
  }
  //output
  cout<<dp[n]<<endl;
}

Measured memory_bytes: 1408