akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <cmath>


#include <assert.h>    // LON
#include <math.h>    // sqrt()


using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
typedef long long ll;
//typedef pair<int, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = LONG_LONG_MAX;
const ll MINF = -10e10;
//const int INF = INT_MAX;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)


//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

//typedef priority_queue<P, vector<P>, greater<P>> PQ_ASK;
const int mod = 1000000007;


int main() {
    int n, a;

    cin >> n >> a;

    cout << (n * n) - a << endl;

}

Measured memory_bytes: 256
import itertools as it

S = input()
ans = 0
for config in it.product(["+", ""], repeat=len(S) - 1):
    num = []
    for i in range(len(S)):
        num.append(S[i])
        if i < len(S) - 1:
            num.append(config[i])
    ans += sum([int(i) for i in "".join(num).split("+")])
print(ans)


Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <numeric>
#include <algorithm>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <math.h>
#include <stdio.h>
#include <tuple>
#include <thread>///////////////////

#define rep(i,m,n) for(int i=(m);i<(n);++i)
#define rem(i,m,n) for(int i=(m);i>(n);--i)
#define MOD 1000000007

using namespace std;

using ll = long long int;
using std::swap;

vector<int> v;
vector<int> w;
vector<long long int> vll;
vector<long long int> wll;
//vector<vector<int>> vec(50, vector<int>(4, 0));
vector<vector<int>> vv;

//int N, Y;
int mode = 0;

//tuple<int, int, int> calc(int A, int B, int C) {}



int main() {
	string S, T;
	cin >> S >> T;
	if (S.length() + 1 == T.length()) {
		if (S == T.substr(0, S.length())) {
			cout << "Yes" << '\n';
			return 0;
		}

	}
	cout << "No" << '\n';
	return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
using namespace std;
using ll = long long;
typedef pair<int, int> pint;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1<<29);

int main() {

    ll N, M;
    cin >> N >> M;
    
    vector<ll> A(N);
    priority_queue<ll> PQ;
    REP(i, N) {
        cin >> A[i];
        PQ.push(A[i]);
    }

    for (ll i = 0; i < M; i++) {
        ll tmp = PQ.top();
        PQ.pop();
        PQ.push(tmp/2);
    }

    ll sum = 0;
    while (!PQ.empty()) {
        sum += PQ.top();
        PQ.pop();
    }
    
    cout << sum << endl;
    

    return 0;
}

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

int main(){
  int A,B,M;
  cin >> A >> B >> M;
  vector<int> r(A);
  vector<int> m(B);
  int a[M][3];
  for (int i = 0; i < A; i++)
  {
    cin >> r.at(i);
  }
  for (int i = 0; i < B; i++)
  {
    cin >> m.at(i);
  }
  for (int i = 0; i < M; i++)
  {
    cin >> a[i][0] >> a[i][1] >> a[i][2];
  }

  priority_queue<int, vector<int>, greater<int>> result;

  for (int i = 0; i < M; i++)
  {
    int x=a[i][0], y=a[i][1], z=a[i][2];
    result.push(r.at(x-1)+m.at(y-1)-z);
  }
  int minA = *min_element(r.begin(),r.end());
  int minB = *min_element(m.begin(),m.end());
  result.push(minA+minB);
  
  cout << result.top() << endl;
  return 0;   

}


Measured memory_bytes: 2940
def RT(num):
  if num%4 == 0:
    ans = num
  elif num%4 == 1:
    ans = 1
  elif num%4 == 2:
    ans = 1 ^ num
  elif num%4 == 3:
    ans = 0
  return ans
A,B=map(int,input().split())
print(RT(B)^RT(A-1))

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

// def
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
#define repeat(i, a, b) for (int i = (a); i < (b); i++)
#define revrepeat(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define revrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define CYES cout << "Yes" << endl
#define CNO cout << "No" << endl
#define SPC(x) cout << fixed << setprecision(x)
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;
typedef vector<vector<ll>> vll;
typedef pair<int, int> P;
typedef complex<ld> Point;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const int MAX_V = 1e5 + 5;
const int MAX_N = 1e5 + 5;
const double PI = acos(-1);

int main() {
    int n;
    cin >> n;
    if (n % 2 == 0) {
        out(n / 2);
    } else {
        out((n + 1) / 2);
    }
    return 0;
}


Measured memory_bytes: 256
import sys


def input():
    return sys.stdin.readline()[:-1]


def main():
    A, B = map(int, input().split())
    if A > B:
        print(-1)
        exit()
    for n in range(int(A / 0.08)-10, 10 * B + 10):
        if int(n * 0.08) == A and int(n * 0.1) == B:
            print(n)
            exit()
    print(-1)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn=1e5;
int n;
int a[maxn*2+8],b[maxn*2+8];

int read()
{
    int x=0,f=1;char ch=getchar();
    for (;ch<'0'||ch>'9';ch=getchar()) if (ch=='-') f=-1;
    for (;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
    return x*f;
}

bool check(int k)
{
    for (int i=1;i<2*n;i++) b[i]=a[i]>=k;
    for (int i=1;i<n;i++)
	{
	    if ((b[n-i]&&b[n-i+1])||(b[n+i]&&b[n+i-1])) return 1;
	    if ((!(b[n-i]||b[n-i+1]))||(!(b[n+i]||b[n+i-1]))) return 0;
	}
    return b[1];
}

int main()
{
    n=read();
    for (int i=1;i<2*n;i++) a[i]=read();
    int l=1,r=2*n-1,ans;
    while(l<=r)
	{
	    int mid=(l+r)>>1;
	    if (check(mid)) l=mid+1,ans=mid;
	    else r=mid-1;
	}
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 1792
A,B,M = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))

min_tmp = min(a)+min(b)

for i in range(M):
  x,y,c = list(map(int,input().split()))
  tmp = a[x-1]+ b[y-1]-c
  if min_tmp > tmp:
    min_tmp = tmp

print(min_tmp)

Measured memory_bytes: 18736
#include "bits/stdc++.h"
using namespace std;
const int maxN = 1e5 + 10;
int n, happy[3][maxN], dp[3][maxN];
int main()
{
	cin >> n;
	for(int i = 1; i <= n; i++) for(int j = 0; j < 3; j++) cin >> happy[j][i];
	for(int i = 1; i <= n; i++)
	{
		dp[0][i] = max(dp[1][i - 1], dp[2][i - 1]) + happy[0][i];
		dp[1][i] = max(dp[0][i - 1], dp[2][i - 1]) + happy[1][i];
		dp[2][i] = max(dp[0][i - 1], dp[1][i - 1]) + happy[2][i];
	}
	cout << max(dp[0][n], max(dp[1][n], dp[2][n])) << endl;
	return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b)for(int i=(a);i<=(b);i++)
#define repR(i,n) for(int i=n;i>=0;i--)
#define P pair<int, int>
#define sz(x) x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<int>
#define COUT(x) cout<<(x)<<endl
#define MA map<int,int>
#define SE set<int>
#define PQ priority_queue<int>
#define PQR priority_queue<int,VE,greater<int>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << 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;
}

using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
bool compare_by_b(pair<int, int> a, pair<int, int> b) {
	if (a.second != b.second) {
		return a.second < b.second;
	}
	else {
		return a.first < b.first;
	}
}

const long long MOD = 1000000007;
const long long INF = 1LL << 50;
// pair -> vector<pair<int,int>> 
//		   AandB.push_back(make_pair(a[i],b[i]))

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

char maze[110][110];
int n, m;
int k;
int sx=0, sy=0;
int gx=0, gy=0;

int d[110][110];

int bfs() {
	queue<P>que;
	rep(i, n)rep(j, m)d[i][j] = INF;
	que.push(P(sx, sy));
	d[sx][sy] = 0;
	while (!que.empty()) {
		P p = que.front(); que.pop();
		if (p.first == gx && p.second == gy)break;
		rep(i, 4) {
			int nx = p.first + dx[i]; int ny = p.second + dy[i];
			if (0 <= nx && nx < n && 0 <= ny && ny < m&&maze[nx][ny] != '#'&&d[nx][ny] == INF) {
				que.push(P(nx, ny));
				d[nx][ny] = d[p.first][p.second] + 1;
			}
		}
	}
	return d[gx][gy];
}

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> m;
	rep(i, n)rep(j, m)cin >> maze[i][j];
	gx = n - 1; gy = m - 1;
	int tmp = bfs();
	if (tmp == INF) {
		cout << -1 << endl; return 0;
	}
	int cnt = 0;
	rep(i, n)rep(j, m) {
		if (maze[i][j] == '#') {
			cnt++;
		}
	}
	int ans = n * m - cnt - tmp - 1;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 384
package main

import "fmt"

func main() {
  var n int
  fmt.Scan(&n)

  var num, sum, max int
  for i := 0; i < n; i++ {
    fmt.Scan(&num)
    sum += num
    if num > max {
      max = num
    }
  }
  if sum-max > max {
    fmt.Println("Yes")
    return
  }
  fmt.Println("No")
}

Measured memory_bytes: 512
#include <stdio.h>
typedef long long ll;

ll min(ll a,ll b){return a<b?a:b;}
int main(void){
    ll n,x,ans=0,count=1,countp=1;
    scanf("%lld%lld",&n,&x);
    for (int i=0; i<n; i++){
        count=count*2+3;
        countp=countp*2+1;
    }
    for (int i=n; i>0; i--){
        if (x>count){
            ans+=countp;
            x-=count;
            if (x>0){
                    ans++;
                    x--;
                } else {
                    break;
                }
            if (x>0){
                x--;
            } else {
                break;
            }
        } else {
            if (x>0){
                x--;
            } else {
                break;
            }
        }
        count=(count-3)/2;
        countp=(countp-1)/2;
    }
    printf("%lld\n",ans+min(x,3));
	return 0 ;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define fi first
#define se second
#define show(x) cerr<<#x<<"="<<x<<"\n"
typedef long long ll;
using namespace std;
//const ll MOD=(ll)1e9+7;
//const ll inf=(ll)1e14;
const int dy[]={1,0,-1};
const int dx[]={1,0,-1};
int n,m,h,w;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);
  cout<<fixed;
#ifdef LOCAL_DEFINE
  FILE *stream1;
  //FILE *stream2;
  stream1=freopen("in","r",stdin);
  //stream2=freopen("out","w",stdout);
  if(stream1==NULL)return 0;
  //if(stream2==NULL)return 0;
#endif
  while(cin>>n,n){
    vector<string> s(n);
    for(int i=0;i<n;i++){
      cin>>s[i];
      if(i==0)continue;
      int j;
      for(j=0;s[i][j+1]=='.';j++);
      s[i][j]='+';
      for(int k=i-1;s[k][j]=='.';k--)s[k][j]='|';
    }
    for(int i=0;i<n;i++){
      for(int j=0;j<(int)s[i].size();j++){
        if(s[i][j]=='.')s[i][j]=' ';
      }
      cout<<s[i]<<endl;
    }
  }
#ifdef LOCAL_DEFINE
  cerr<<"Time elapsed: "<<1.0*clock()/CLOCKS_PER_SEC<<"s.\n";
  fclose(stream1);
  //fclose(stream2);
#endif
  return 0;
}







Measured memory_bytes: 3444
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <array>
#include <tuple>
#include <random>

using namespace std;
typedef long long int ll;

#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); i++)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep,)(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()

#define inf 10000000000

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

    char a, b;
    cin >> a >> b;
    if(a > b){
        cout << '>' << endl;
    }else if(a < b){
        cout << '<' << endl;
    }else{
        cout << '=' << endl;
    }
}


Measured memory_bytes: 256
a = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
b = int(input())
print(a[b-1])


Measured memory_bytes: 2940
from bisect import bisect_left
n = int(input())
dp = []
a=[int(input()) for i in range(n)]
length=-1
for i in range(n):
    k = bisect_left(dp, a[i])
    if(length < k):
        dp.append(a[i])
        length += 1
    else:   
        dp[k] = a[i]
print(length+1)



Measured memory_bytes: 10352
#include <cstdio>
#include <cmath>
#include <complex>
#include <iostream>
using namespace std; 
#define X real()
#define Y imag()

const double EPS = 1e-10;

bool EQ(double a,double b){
  return fabs(a-b) < EPS;
}

typedef complex<double> Point;

namespace std {
  bool operator == (const Point &a, const Point &b) {
    return EQ(a.X, b.X) && EQ(a.Y, b.Y);
  }
  bool operator < (const Point &a, const Point &b) {
    return a.X != b.X ? a.X < b.X : a.Y < b.Y;
  }
}
struct Segment {
  Point p1, p2;
  Segment(){};
Segment(Point p1, Point p2) : p1(p1), p2(p2) {};
};

typedef Segment Line;
double dot(Point a, Point b){
  return a.X * b.X + a.Y * b.Y;
}
double cross(Point a, Point b){
  return a.real() * b.imag() - a.imag() * b.real();
}

Point project(Segment s, Point p) {
  double r = dot(p - s.p1, s.p2 - s.p1) / norm(s.p2 - s.p1);
  return s.p1 + (s.p2 - s.p1) * r;
}

Point reflect(Segment s, Point p) {
return p + (project(s, p) - p) * 2.0;
}

int main()
{
  Segment s;
  cin >> s.p1.real() >> s.p1.imag() >> s.p2.real() >> s.p2.imag();
  
  int q;
  
  cin >> q;
  Point p;
  for(int i=0;i<q;i++){
    cin >> p.X >> p.Y;
    Point p2 = project(s,p);
    //cout << p2.X << p2.Y << endl;
    
    printf("%.15f %.15f\n",p2.X,p2.Y);

  }

  return 0;
}

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

ll gcd(ll a,ll b){
    if(a<b)return gcd(b,a);
    if(a%b==0)return b;
    return gcd(b ,a%b);
}
int main(){
    int n;
    cin >> n;
    string s,t;
    cin >> s >> t;
    int ans = 2*n;
    for(int i=0;i<n;i++){
        bool end = true;
        for(int j=0;i+j < n;j++){
            if(s[i+j]!=t[j]){
                end = false;
            }
        }
        if(end){
            ans = i+n;
            break;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#define MOD 1000000007
typedef long long ll;
using namespace std;

int main(){
  ll n,k;
  cin>>n>>k;
  ll a[n+1]={};
  for(int i=0;i<n;i++){
    cin>>a[i];
  }

  ll p=n*(n+1)/2;
  ll sum[p+10]={};
  ll pos=0;
  for(int i=0;i<n;i++){
    ll tmp=0;
    for(int j=i;j<n;j++){
      tmp+=a[j];
      sum[pos]=tmp;
      pos++;
    }
  }

  ll np=0,ans=0;
  for(int i=40;i>=0;i--){
    ll now=(1ll<<i);
    np+=now;
    ll tmp=0;
    for(int j=0;j<p;j++){
      if((np&sum[j])==np){
        tmp++;
      }
    }
    //cout<<(1ll<<i)<<" "<<tmp<<endl;
    if(tmp>=k){
      ans+=now;
    }else{
      np-=now;
    }
  }

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 4224
n = int(input())

arr = list(map(int, input().split()))

diff = []
for i, x in enumerate(arr, 1):
    diff.append(x - i)

diff.sort()
b = (diff[(n-1)//2] + diff[n//2]) // 2

abs_diff = 0
for i, x in enumerate(arr, 1):
    abs_diff += abs(x - (i + b))
print(abs_diff)


Measured memory_bytes: 26836
#include<bits/stdc++.h> 
using namespace std;  
const int K = 3005;  
int x[K][K];  
int n,k;  
int getsize(int x1,int y1,int x2,int y2){  
    return x[x2][y2]-x[x2][y1]-x[x1][y2]+x[x1][y1];  
}  
int main(){  
    scanf("%d%d",&n,&k);  
    int a,b,i,j;  
    char c;  
    for(i = 1; i <= n; i++){  
        scanf("%d%d %c",&a,&b,&c);  
        a %= (2*k);  
        b %= (2*k);  
        if(c == 'W')  
            b += k;  
        x[a%(2*k)+1][b%(2*k)+1]++;  
    }  
    for(i = 1; i <= 2*k; i++){  
        for(j = 1; j <= 2*k; j++){  
            x[i][j] = x[i][j]+x[i-1][j]+x[i][j-1]-x[i-1][j-1];  
        }  
    }  
    int ans = 0,sum;  
    for(i = 1; i <= k; i++){  
        for(j = 1; j <= k; j++){  
            sum = getsize(0,0,i,j);  
            sum += getsize(i,j,k+i,k+j);  
            sum += getsize(k+i,k+j,2*k,2*k);  
            sum += getsize(k+i,0,2*k,j);  
            sum += getsize(0,k+j,i,2*k);  
            sum = max(n-sum,sum);  
            ans = max(ans,sum);  
        }  
    }  
    printf("%d\n",ans);  
    return 0;  
}  

Measured memory_bytes: 24832
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define all(n) n.begin(),n.end()
#define yn(x) cout << (x ? "Yes":"No") << endl;

int main() {
  double n;
  cin >> n;
  int a = (n+1)/2;
  cout << std::fixed << std::setprecision(7) << a/n << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define mo 1000000007
#define ll long long int
int n ;int a[22][22];ll dp[2200000][22];

ll func(int bm,int i)
{
	if(i>=n)
	return(1);
	
	if(dp[bm][i]!=-1)
	return(dp[bm][i]);
	
	ll ans = 0 ; 

	for(int j = 0 ;j<n ;j++)
	{ 
	int p = 1<<j;
	        p = bm&p ; 
	        
		if(a[i][j]&&(p))
		{   
		   int s = bm^p;
			ans = (ans+func(s,i+1))%mo;
		}
		}
		return(dp[bm][i]= ans);	
}

int main()
{
	ios_base:: sync_with_stdio(false);cin.tie(NULL);
	cin>>n;
	for(int i =0 ; i<n ; i++)
	{
		for(int j = 0 ; j<n ; j++)
		cin>>a[i][j]; 
	}
	
	int bm = 0 ; 
	for(int j = 0 ; j<n ;j++)
	{
	bm = bm<<1; 
	bm = bm|1;
	}
	memset(dp,-1,sizeof(dp));
	cout<<func(bm,0);
		return(0);
	}



Measured memory_bytes: 378496
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int n;
  cin >> n;
  int v1=0,v4=0;
  rep(i,n){
    int a;
    cin >> a;
    if(a%4==0) ++v4;
    else if(a%2==1) ++v1;
  }
  bool ans = v1<=v4 || (v1==v4+1&&v1+v4==n);
  cout << (ans?"Yes":"No") << endl;
}


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

using namespace std;

long long x, k, d;
int main()
{
	cin >> x >> k >> d;
	if(x == 0)
	{
		if(k % 2 == 0)
		{
			cout << 0 << endl;
		}
		else
		{
			cout << d << endl;
		}
		return 0;
	}
	if(x < 0)
	{
		x = -x;
	}
	if(x < d)
	{
		if(k % 2 == 0)
		{
			cout << x << endl;
		}
		else
		{
			cout << d - x << endl;
		}
		return 0;
	}
	long long y = x / d;
	if(y < k)
	{
		long long now = x % d;
		if((k - y) % 2 == 0)
		{
			cout << now << endl;
		}
		else
		{
			cout << d - now << endl;
		}
	}
	else
	{
		cout << x - k * d << endl;
	}
	return 0;
}



















Measured memory_bytes: 3628
N = int(input())
a = [int(c) for c in input().split()]
M = max(a)
Mi = a.index(M)
m = min(a)
mi = a.index(m)
ans = []
if 0<=m:
  for i in range(N-1):
    ans += [(i+1, i+2)]
elif M<=0:
  for i in range(N-1, 0, -1):
    ans += [(i+1, i)]
else:
  if abs(m)<abs(M):
    for i in range(N):
      if a[i]<0:
        ans += [(Mi+1, i+1)]
    for i in range(N-1):
      ans += [(i+1, i+2)]
  else:
    for i in range(N):
      if a[i]>0:
        ans += [(mi+1, i+1)]
    for i in range(N-1, 0, -1):
      ans += [(i+1, i)]

print(len(ans))
for c in ans:
  print(*c)

Measured memory_bytes: 38256
#include <stdio.h>

int main() {
    int a, b;
    scanf("%d %d", &a, &b);
    if(a>b){
        printf("a > b\n");
    }else if(a<b){
        printf("a < b\n");
    }else{
        printf("a == b\n");
    }
    return 0;
}

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

// 総数を1000000007で割った余り
const long long mod = 1e9 + 7;

using ll  = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
// #define SORT(v, n) stable_sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    // cout << fixed << setprecision(5);

    int k, x;
    cin >> k >> x;

    for (int i = x - k + 1; i < x + k; i++) {
        cout << i << " ";
    }

    return 0;
}


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

using namespace std;

static const int N = 100;
static const int INFTY = (1 << 21);

int n, M[N][N];
int 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 u, v, k;
    cin >> n;

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

    bfs(0);
}




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

int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  priority_queue<int> q;
  for(int i=0; i<n; i++) {
    int c; cin >> c;
    q.push(c);
  }
  for(int i=0; i<m; i++) {
    int s=q.top();
    s/=2;
    q.pop();
    q.push(s);
  }
  int64_t ans=0;
  while(!q.empty()) {
    ans+=q.top();
    q.pop();
  }
  cout << ans << endl;
}

Measured memory_bytes: 892
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010

struct P{
  int a, b, c, d;

  P(int a, int b, int c, int d):
    a(a), b(b), c(c), d(d) {}
};

int main(){
  int h, w;
  int a[501][501];

  cin >> h >> w;

  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin >> a[i][j];
    }
  }

  vector<P> vec;

  for(int i=0;i<h;i++){
    for(int j=0;j<w-1;j++){
      if (a[i][j] % 2) {
        vec.emplace_back(i+1, j+1, i+1, j+2);
        a[i][j+1] ++;
        a[i][j] --;
      }
    }
  }

  for(int i=0;i<h-1;i++){
    if (a[i][w-1] % 2) {
      vec.emplace_back(i+1, w, i+2, w);
      a[i+1][w-1] ++;
      a[i][w-1] --;
    }
  }

  cout << vec.size() << endl;

  for(P p : vec){
    cout << p.a << " " << p.b << " " << p.c << " " << p.d << endl;
  }

  return 0;
}


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

#define ll long long 
#define F first
#define S second
#define pb push_back
#define pp pop_back
#define in insert
#define pii pair<int, int>
#define pll pair<ll, ll>
#define N int(1e5) + 5
#define T int(1e4) + 5
#define H int(1e3) + 55

using namespace std;

ll n, m, a, sum, num, sam, nam, maxi, mini;

int main() {
	cin >> n >> m >> a;
	if(abs(m - a) % 2 == 0) {
	 	cout << "Alice";
	 	return 0;
	}
	else {
	 	cout << "Borys";
	 	return 0;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long N,M,X[1000],Y[1000],f[2],xdir,ydir,xsum,ysum;
vector<long>d;
int main(){
  cin>>N;
  for(long i=0;i<N;i++){
    cin>>X[i]>>Y[i];
    f[(X[i]+Y[i])%2]=1;
  }
  if(f[0]==f[1]){
    cout<<-1<<endl;
    return 0;
  }
  for(long i=30;i>=0;i--)d.push_back(1L<<i);
  if(f[0])d.push_back(1);
  M=d.size();
  cout<<M<<endl;
  for(long i=0;i<M-1;i++)cout<<d[i]<<" ";
  cout<<d[M-1]<<endl;
  for(long i=0;i<N;i++){
    xsum=ysum=0;
    for(long j=0;j<M;j++){
      if(xsum<=X[i]+Y[i])xdir=1,xsum+=d[j];
      else xdir=-1,xsum-=d[j];
      if(ysum<=X[i]-Y[i])ydir=1,ysum+=d[j];
      else ydir=-1,ysum-=d[j];
      if((xdir==1)&&(ydir==1))cout<<"R";
      else if((xdir==1)&&(ydir==-1))cout<<"U";
      else if((xdir==-1)&&(ydir==-1))cout<<"L";
      else cout<<"D";
    }
    cout<<endl;
  }
}


Measured memory_bytes: 256
/*
 _    _    _______   _    _
| |  / /  |  _____| | |  / /
| | / /   | |       | | / /
| |/ /    | |_____  | |/ /
| |\ \    |  _____| | |\ \
| | \ \   | |       | | \ \
| |  \ \  | |_____  | |  \ \
|_|   \_\ |_______| |_|   \_\

*/
/*#include <iostream>
#include <cstdio>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <cstring>
#include <string>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <assert.h>*/

#include <bits/stdc++.h>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef double ld;
typedef pair <int, int> PII;
typedef pair <ll, ll> PLL;

#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define right(x) x << 1 | 1
#define left(x) x << 1
#define forn(x, a, b) for (int x = a; x <= b; ++x)
#define for1(x, a, b) for (int x = a; x >= b; --x)
#define mkp make_pair
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define y1 kekekek

const ll ool = 1e18 + 9;
const int oo = 1e9 + 9, base = 1e9 + 7;
const ld eps = 1e-7;
const int N = 2e6 + 6;

int n, pos[N], l, r;
ll fact[N];

ll binpow(int deg, int x) {
    if (!deg) return 1;
    if (deg & 1) return binpow(deg - 1, x) * x % base;
    ll res = binpow(deg >> 1, x);
    return res * res % base;
}

ll cnk(int n, int k) {
    if (k > n) return 0;
    return fact[n] * binpow(base - 2, fact[n - k] * fact[k] % base) % base;
}

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

	cin >> n;
	forn(i, 1, n + 1) {
        int x;
        cin >> x;
        if (pos[x]) {
            l = pos[x];
            r = i;
        }
        pos[x] = i;
	}

	fact[0] = 1;
	forn(i, 1, n + 1) {
        fact[i] = fact[i - 1] * i % base;
	}

	forn(i, 1, n + 1) {
        ll res = cnk(n + 1, i);
        //cerr << res << "\n";
        res -= cnk(l - 1 + n - r + 1, i - 1);
        res += base;
        res %= base;
        cout << res << "\n";
	}

	return 0;
}


Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<ll,ll> P;
#define rep(i,a,b) for(ll i=a ; i<b ; i++)
const int max_n = 1e5;
const ll mod = 1e9+7;
void send(int a,int b,int c,int d){
  printf("%d %d %d %d\n",a,b,c,d);
}
struct edge{
  int to;
  ll cost;
};
vector<ll> v[200000];
vector<ll> ans;
void dfs(int u, int pre){//根uでカウントk
  for(int next : v[u]){
    if(next!=pre){
       ans[next] += ans[u];
       dfs(next, u);
    }
  }
}
int main(){
  int n,q;  cin >> n >> q;
  ans.assign(n,0);
  rep(i,0,n-1){
    int x,y;  cin >> x >> y;  --x;  --y;
    v[y].pb(x);
    v[x].pb(y);
  }
  ll sum = 0;
  rep(i,0,q){
    int x; ll y;  cin >> x >> y;
    --x;
    ans[x] += y;
  }
  dfs(0,-1);
  rep(i,0,n){
    cout << ans[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 24320
#include<stdio.h>

#define MAX 1000000

void insertSort(int *, int, int);
void shellSort(int *, int);

int cnt=0;

int main(){
  int len;
  int i;
  int array[MAX];
  
  scanf("%d", &len);
  for(i=0;i<len;i++) scanf("%d", &array[i]);
  shellSort(array,len);
  for(i=0;i<len;i++) printf("%d\n",array[i]);
  return 0;
}

void shellSort(int *A,int n){//warning
  int i=0,j;
  int G[MAX];
  
  G[0]=1;
  while(G[i]<=n){
    i++;
    G[i]=(3*G[i-1]+1);
  }  
  for(j=i-1;j>=0;j--) insertSort(A,n,G[j]);//大きい方から 
  printf("%d\n",i);//1 line 
  for(j=i-1;j>=0;j--){
    if(j==0) printf("%d\n",G[j]);    
    else printf("%d ",G[j]);
  }
  printf("%d\n",cnt);//3 line
}

void insertSort(int *A, int n, int g){
  int v;
  int i, j;

  for(i=g;i<n;i++){
    v=A[i];
    j=i-g;
    while(j>=0&&A[j]>v){
      A[j+g]=A[j];
      j-=g;
      cnt++;
    }
    A[j+g]=v;
  }
}



Measured memory_bytes: 5700
using System;

public class Hello
{
    public static void Main()
    {
        while (true)
        {
            string[] line = Console.ReadLine().Trim().Split(' ');
            if (line[0] == "0") break;
            var q1 = int.Parse(line[0]);
            var b = int.Parse(line[1]);
            var c1 = int.Parse(line[2]);
            var c2 = int.Parse(line[3]);
            var q2 = int.Parse(line[4]);
            var ac = 0; var ic = 0;
            if (q2 >= q1)
                if (b - c1 * q2 >= 0) { ac = q2; ic = (b - c1 * q2) / c2; }
                else if (b - c1 * q1 >= 0) { ac = b / c1; ic = (b - c1 * ac) / c2; }
                else
                {
                    var t = getAc(q1, b, c1, c2, q2);
                    if (t == -1) { Console.WriteLine("NA"); goto end; }
                    else { ac = t; ic = q1 - ac; }
                }
            else if (c1 * q2 + c2 * (q1 - q2) <= b)
            {
                ac = q2;
                ic = (b - c1 * q2) / c2;
            }
            else
            {
                var t = getAc(q1, b, c1, c2, q2);
                if (t == -1) { Console.WriteLine("NA"); goto end; }
                else { ac = t; ic = q1 - ac; }
            }
            if (ac < 0 | ic < 0) { Console.WriteLine("NA"); goto end; }
            Console.WriteLine("{0} {1}", ac, ic);
            end:;
        }
    }
    public static int getAc(int q1, int b, int c1, int c2, int q2)
    {
        for (int i = q2; i >= 1; i--)
            if (b - (c1 * i + c2 * (q1 - i)) >= 0) return i;
        return -1;
    }
}

Measured memory_bytes: 9120
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl "\n"
#define ll long long
#define int long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

vector<pair<long long, long long>> primeFactorize(long long N) {
    vector<pair<long long, long long>> res;
    for (long long i = 2; i * i <= N; ++i) {
        if (N % i != 0)
            continue;
        long long powInd = 0;
        while (N % i == 0) {
            powInd++;
            N /= i;
        }
        res.push_back({i, powInd});
    }
    if (N != 1)
        res.push_back({N, 1});
    return res;
}

signed main() {
    cin >> A >> B;
    N = gcd(A, B);
    auto v = primeFactorize(N);
    dump(v);
    cout << v.size() + 1 << endl;
}

Measured memory_bytes: 3648
n = gets.to_i
a = gets.chomp.split.map(&:to_i)
res = 0
1.step(n - 1) do |j|
  0.step(j - 1) do |i|
    res = (a[j] - a[i]).abs if (a[j] - a[i]).abs > res 
  end
end
puts res

Measured memory_bytes: 3836
#!/usr/bin/env python3
import sys

MOD = 1000000007  # type: int

def solve(S: str):
    N = len(S)
    r_d = [1] * (N+1)
    r_d[0] = 0
    for i in range(2, N+1):
        r_d[i] = (r_d[i-1] * 10) % 13
    
    dp = [[0 for j in range(N+1)] for i in range(13)] # dp[i][j]: 13でわってiになるSのj桁目まで数の総数
    dp[0][0] = 1

    for j in range(1, N+1):
        d = S[-j]
        if d != "?":
            d = (int(d) * r_d[j]) % 13
            for i in range(13):
                dp[i][j] += dp[(i - d) % 13][j-1]
            continue
        for k in range(10):
            d = (k * r_d[j]) % 13
            for i in range(13):
                dp[i][j] += dp[(i - d) % 13][j-1]
                dp[i][j] %= MOD
    print(dp[5][N])
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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: 109548
#include <iostream>
#include <algorithm>
#include <fstream>
#include <vector>
#include <deque>
#include <assert.h>
#include <stack>
#include <set>
#include <map>
#include <stdio.h>
#include <string.h>
#include <utility>
#include <math.h>
#include <bitset>
#include <iomanip>
#include <complex>
#include <queue>
using namespace std;
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define print(x) cout<<(x)<<'\n'
#define print_vec(v) rep(i,v.size()){if(i!=0)cout<<" ";cout<<v[i];}cout<<'\n'
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";rep(i,v.size())cout<<" "<<v[i];cout<<'\n'
#define pb push_back
#define mp make_pair
#define MOD 1000000007 //10^9+7
#define fi first
#define sc second
using ll=long long;
using pl=pair<ll,ll>;
using vi=vector<int>;
using vl=vector<ll>;
using vvi=vector<vi>;
using vvl=vector<vl>;
using vs=vector<string>;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }

void solve() {
    int N;
    cin >> N;
    vi A(N);
    rep(i, N) cin >> A[i];
    ll ans = 0;
    int wall = A[0];
    rng(i, 1, N){
        if(wall > A[i]) {
            ans += wall - A[i];
        } else {
            wall = A[i];
        }
    }
    print(ans);
}   

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
	cout<<fixed<<setprecision(20);
    //int q; cin >> q;
	//while (q--)
		solve();
    return 0;
}


Measured memory_bytes: 4000
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define ALL(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define reps(i, m, n) for (ll i = m; i < n; i++)
#define repr(i, m, n) for (ll i = m; i >= n; i--)
#define de(x) cout << #x << "=" << x << endl;
template <class T> bool maxi(T &a, const T &b) {
    if (a < b) { a = b; return 1;} return 0;}
template <class T> bool mini(T &a, const T &b) {
    if (b < a) { a = b; return 1;} return 0;}
#define dame {cout<< "-1" <<"\n"; return;}
#define INF2 1000000000000000037
#define INF  1000000007
#define MOD  1000000007
#define PI (acos(-1))
using namespace std;
using ll = long long;
using ld = long double;
using P  = pair<ll,ll>;
//--GLOBAL---------------------------------
const ll MAX = 202020;
ll fac[MAX], finv[MAX], inv[MAX];
void cinit() { // O(nlogn)
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    reps(i, 2, MAX){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
ll c(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;
}
//--MAIN-----------------------------------
void Main() {
    ll N,K; cin>>N>>K;
    vector<ll> A(N);
    rep(i,N) cin>>A[i];
    sort(ALL(A),greater<ll>());
    cinit();
    ll ans=0;
    rep(i,N){
        ll buf=0;
        buf+=c(N-i-1,K-1);
        buf-=c(i,K-1);
        buf*=A[i];
        buf+=1LL*MOD*MOD;
        buf%=MOD;
        ans+=buf;
        ans%=MOD;
    }
    cout<< ans <<"\n";
}

//--START----------------------------------
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}
//-----------------------------------------


Measured memory_bytes: 5760
#include<iostream>
    #include<cstdio>
    #include<cmath>
    #include<vector>
    #include<map>
    #include<set>
    using namespace std;
    int main()
    {
        unsigned long long h, w;
        cin>>h>>w;
        if(h==1 || w==1)
            cout<<1<<endl;
        else
            cout<<(h*w+1)/2<<endl;
        return 0;
    }

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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

vector<int> G[20];

vector<int> tlist;
vector<bool> vis;

void dfs(int v)
{
    if(vis[v]) return;
    vis[v]=true;
    rep(i,G[v].size()) dfs(G[v][i]);
    tlist.pb(v);
}

void tsort(int n)
{
    vis = vector<bool>(n,false);
    rep(i,n) dfs(i);
    reverse(all(tlist));
}

int main()
{
    int m,n;
    cin >>m >>n;

    rep(i,n)
    {
        int x,y;
        cin >>x >>y;
        --x;--y;
        if(x!=1) G[x].pb(y);
    }

    tsort(m);
    rep(i,m) cout << tlist[i]+1 << endl;
    return 0;
}

Measured memory_bytes: 3132
#include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>
#include<cassert>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T> using vv=vector<vector<T>>;
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"<<endl; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
const ll MOD=1e9+7;
const double INF=1e15;
template<class T,class G>
void dij(vv<pair<G,T>> &g,int s,vector<T> &d){
  typedef pair<T,G> Que;
  priority_queue<Que,vector<Que>,greater<Que> > que;
  int n=g.size();
  d.resize(n);
  fill(all(d),INF);
  d[s]=0;
  que.emplace(0,s);
  while(que.size()){
    Que p=que.top();que.pop();
    if(d[p.Y]<p.X)continue;
    for(auto e:g[p.Y]) if(MN(d[e.X],d[p.Y]+e.Y)) que.emplace(d[e.X],e.X);
  }
}

inline double dist(pll a,pll b){
  return hypot(abs(a.X-b.X),abs(a.Y-b.Y));
}

int main(){
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(10);
  ll sx,sy,tx,ty;
  cin>>sx>>sy>>tx>>ty;
  int n;
  cin>>n;
  vector<pll> cs(n+2);
  vector<ll> rs(n+2);
  rep(i,n) cin>>cs[i+1].X>>cs[i+1].Y>>rs[i+1];
  cs[0]=pll(sx,sy);
  cs[n+1]=pll(tx,ty);
  vv<pair<int,double>> g(n+2);
  rep(i,n+2)rep(j,n+2){
    g[i].eb(j,max(0.,dist(cs[i],cs[j])-rs[i]-rs[j]));
  }
  //cout<<g;
  vector<double> d;
  dij(g,0,d);
  //cout<<d;
  cout<<d[n+1]<<endl;
  return 0;
}


Measured memory_bytes: 20604
using System;

class Program
{
    static void Main(string[] args)
    {
        int n = int.Parse(Console.ReadLine());
        char[] strA = Console.ReadLine().ToCharArray();
        char[] strB = Console.ReadLine().ToCharArray();
        char[] strC = Console.ReadLine().ToCharArray();

        int ans = 0;
        for (int i = 0; i < n; i++)
        {
            int a = 1;
            if (strA[i] == strB[i] && strA[i] == strC[i]) { a = 0; }
            else if (strA[i] != strB[i] && strA[i] != strC[i]&&strB[i]!=strC[i]) { a = 2; }
            ans += a;
        }

        Console.WriteLine(ans.ToString());
    }
}

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

using namespace std;
using ll = long long;
int mod = 1000000007;

int main(void) {
  int n;
  cin >> n;
  vector<int> a(n);
  ll sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
    sum %= mod;
  }
  ll ans = 0;
  for (int i = 0; i < n - 1; i++) {
    sum -= a[i];
    if (sum < 0) {
      sum += mod;
    }
    ans += a[i] * sum;
    ans %= mod;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3996
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
const int INFTY =2147483647;
int main(){
    int n,a,A[200005]={};
    cin>>n;
    for(int i=1;i<n;i++){
        cin>>a;
        A[a-1]++;
    }
    REP(i,n)cout<<A[i]<<endl;
}

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

int main(){
  int n;
  cin >> n;
  int a[n+1];
  a[0] = 0;
  a[1] = 0;
  int ans[n+1] = {0};

  rep(i,2,n+1){
    cin >> a[i];
    ans[a[i]]++;
  }

  rep(i,1,n+1) cout << ans[i] << endl;

  return 0;
}

Measured memory_bytes: 5156
N = int(input())

s = input()

ans_first = ["SS", "SW", "WS", "WW"]

cand_oo = ["SSSS", "SWWS", "WWSW", "WSWW"]
cand_ox = ["SSSW", "SWWW", "WWSS", "SSWS"]
cand_xo = ["WSSS", "WWWS", "SWSW", "SSWW"]
cand_xx = ["WSSW", "WWWW", "SWSS", "WSWS"]

answered = False

for a in ans_first:
    if answered == True:
        break
        
        
    for i in range(1, N-1):
        if (s[i] == "o" and a[i] == "S") or (s[i] == "x" and a[i] == "W"):
            a = a + a[i-1]
            
        elif (s[i] == "o" and a[i] == "W") or (s[i] == "x" and a[i] == "S") :
            if a[i-1] == "S":
                a = a + "W"
            else:
                a = a + "S"
            
    if s[-1] + s[0] == "oo": 
        for can in cand_oo:
            if can == a[-2:] + a[:2]:
                print(a)
                answered = True
                break
                
    elif s[-1] + s[0] == "ox": 
        for can in cand_ox:
            if can == a[-2:] + a[:2]:
                print(a)
                answered = True
                break
    
    elif s[-1] + s[0] == "xo": 
        for can in cand_xo:
            if can == a[-2:] + a[:2]:
                print(a)
                answered = True
                break
    
    elif s[-1] + s[0] == "xx": 
        for can in cand_xx:
            if can == a[-2:] + a[:2]:
                print(a)
                answered = True
                break
                
if answered == False:
    print(-1)

Measured memory_bytes: 3572
import itertools
h, w, k = map(int, input().split())
table = [list(input()) for _ in range(h)]
ans = 0
for ptr_h in itertools.product([0, 1], repeat=h):
    for ptr_w in itertools.product([0, 1], repeat=w):
        cnt = 0
        for i in range(h):
            for j in range(w):
                if ptr_h[i] == 0 and ptr_w[j] == 0:
                    if table[i][j] == "#":
                        cnt += 1
        if cnt == k:
            ans += 1
print(ans)

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

int main() {
  int A, B;
  cin >> A >> B;
  int number = 0;
  int N = B-A+1;
  int a,b,c,d;
  
  for (int i=0; i<N; i++) {
    a = A%10;      //一の位
    b = A/10%10;   //十の位
    c = A/1000%10; //千の位
    d = A/10000;   //万の位
    
    if (a==d && b==c)
      number++;
    
    A++;
  }
  
  cout <<number <<endl;
}


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

#define loop(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < n; ++i)
#define dump(a) cerr << #a << " = " << (a) << "(L:" << __LINE__ << ")" << endl

void solve(long long N, long long K, std::vector<long long> p) {
    vector<double> E(N);
    rep (i, N) E[i] = (p[i] + 1.0) / 2.0;
    double tmp = 0;
    rep (i, K) tmp += E[i];
    double ans = tmp;
    loop (i, K, N) {
        tmp = tmp - E[i-K] + E[i];
        ans = max(ans, tmp);
    }
    printf("%.20lf\n", ans);
}

int main() {
    long long N;
    scanf("%lld", &N);
    long long K;
    scanf("%lld", &K);
    std::vector<long long> p(N);
    for (int i = 0; i < N; i++) {
        scanf("%lld", &p[i]);
    }
    solve(N, K, std::move(p));
    return 0;
}


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

typedef long long LL;
const int M=1e5+5;
int id[M];
struct Node
{
	int p;
	int l,r;
	void read(int i)
	{
		l=i-1;
		r=i+1;
		scanf("%d",&p);
		id[p]=i;
	}
}node[M];
void link(int l,int r)
{
	node[l].r=r;
	node[r].l=l;
}

int main()
{
	int n; scanf("%d",&n);
	for(int i=1;i<=n;i++)
		node[i].read(i);
	link(0,1); link(n,n+1);
	LL ans=0;
	for(int i=1;i<n;i++)
	{
		int u=id[i];
		int l=node[u].l,r=node[u].r;
		if(l)
			ans+=((LL)l-node[l].l)*((LL)r-u)*i;
		if(r!=n+1)
			ans+=((LL)node[r].r-r)*((LL)u-l)*i;
		link(l,r);
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 1792