akhauriyash/Code-Regression huggingface dataset:
#include<cmath>
#include<algorithm>
#include<iostream>
#include<vector>
#include<climits>
#include<cfloat>
#define next(P, i) P[(i+1) % P.size()]
using namespace std;

double EPS = 1e-10;

double add(double a, double b){
  if(abs(a+b) < EPS * (abs(a)+abs(b)))return 0;
  return a+b;
}

struct point{
  double x, y;
  point(){}
  point(double x,double y) : x(x) , y(y){}

  point operator - (point p){
    return point(add(x,-p.x), add(y,-p.y));
  }
};

bool cmp_x(const point& p, const point& q){
  if(p.x != q.x)return p.x<q.x;
  return p.y < q.y;
}

double dot(point a, point b) {
  return (a.x * b.x + a.y * b.y);
}

double cross(point a, point b) {
  return (a.x * b.y - a.y * b.x);
}

int is_point_on_line(point a, point b, point c) {
  return cross(b-a, c-a)==0.0 &&
         (dot(b-a, c-a) > -EPS) &&
         (dot(a-b, c-b) > -EPS);
}

int is_intersected_ls(point a1, point a2, point b1, point b2) {

  if(cross(a1-a2,b1-b2)==0){
    return is_point_on_line(a1,a2,b1) || is_point_on_line(a1,a2,b2) 
        || is_point_on_line(b1,b2,a1) || is_point_on_line(b1,b2,a2);
  }
  else {
    return ( cross(a2-a1, b1-a1) * cross(a2-a1, b2-a1) < EPS ) &&
           ( cross(b2-b1, a1-b1) * cross(b2-b1, a2-b1) < EPS );
  }
}

int contain(point p, vector<point> ps){
  point a(p.x,p.y),b(1000000,p.y);

  double ymx=-DBL_MAX,ymn=DBL_MAX;
  for(int i=0;i<ps.size();i++){
    ymx=max(ymx,ps[i].y);
    ymn=min(ymn,ps[i].y);
  }
  if(a.y<=ymn||a.y>=ymx)return 0;

  int cnt1=0;
  for(int i=0;i<ps.size();i++)
    if(is_point_on_line(a,b,ps[i]))cnt1++;
  
  int cnt=0;
  for(int i=0;i<ps.size();i++)
    if(is_intersected_ls(ps[i],ps[(i+1)%ps.size()],a,b))cnt++;

  return (cnt-cnt1)%2;
}

int crossPol(vector<point> pol1, vector<point> pol2){

  for(int i=0;i<pol1.size();i++)
    if(contain(pol1[i],pol2))return 1;
  
  for(int i=0;i<pol2.size();i++)
    if(contain(pol2[i],pol1))return 1;

  for(int i=0;i<pol1.size();i++)
    for(int j=0;j<pol2.size();j++)
      if(is_intersected_ls(pol1[i],next(pol1,i),pol2[j],next(pol2,j)))return 1;
  
  return 0;
}

vector<point>convex_hull(point* ps, int n){
  sort(ps,ps+n,cmp_x);
  int k=0;
  vector<point>qs(n*2);
 
  for(int i=0;i<n;i++){
    while(k>1&&cross(qs[k-1]-qs[k-2],ps[i]-qs[k-1])<=0)k--;
    qs[k++]=ps[i];
  }
 
  for(int i=n-2,t=k;i>=0;i--){
    while(k>t&&cross(qs[k-1]-qs[k-2],ps[i]-qs[k-1])<=0)k--;
    qs[k++]=ps[i];
  }
  qs.resize(k-1);
  return qs;
}

int main(void){
  int n,m;
  point black[100],white[100];

  while(cin >> n >> m,n|m){

    for(int i=0;i<n;i++)
      cin >> black[i].x >> black[i].y;
    
    for(int i=0;i<m;i++)
      cin >> white[i].x >> white[i].y;

    if(n<2||m<2){
      if(n<2 && m<2)cout << "YES" << endl;
      else {
	bool fg=false;
	for(int i=0;i<n;i++){
	  for(int j=0;j<m;j++){
	    if(is_intersected_ls(black[i],black[(i+1)%n],white[j],white[(j+1)%n]))fg=true;
	  }
	}
	if(fg)cout <<"NO"<<endl;
	else cout << "YES" << endl;
      }
      continue;
    }

    vector<point>Black,White;

    Black=convex_hull(black,n);
    White=convex_hull(white,m);
    
    if(crossPol(Black,White))cout << "NO" << endl;
    else cout << "YES" << endl;
  }

  return 0;
}

Measured memory_bytes: 1248
object Main extends App {
	val a = Array.ofDim[Int](3, 3)
	for(i<-0 until 3){
		a(i) = scala.io.StdIn.readLine.split(" ").map(_.toInt)
	}
	val N = scala.io.StdIn.readInt
	for(i<-0 until N){
		val b = scala.io.StdIn.readInt

		if(a(0).contains(b)){
			a(0)(a(0).indexOf(b)) = 0
		}

		if(a(1).contains(b)){
			a(1)(a(1).indexOf(b)) = 0
		}

		if(a(2).contains(b)){
			a(2)(a(2).indexOf(b)) = 0
		}
	}

	var flag = false

	if(a(0).sum == 0 || a(1).sum == 0 || a(2).sum == 0) flag = true

	for(i<-0 until 3){
		if(a(0)(i) + a(1)(i) + a(2)(i) == 0) flag = true
	}

	if(a(0)(0) + a(1)(1) + a(2)(2) == 0) flag = true
	if(a(0)(2) + a(1)(1) + a(2)(0) == 0) flag = true

	if(flag) println("Yes")
	else println("No")

}


Measured memory_bytes: 25412
inf=10**10
def merge(a,left,cen,right):
    cnt=0
    n1=cen-left
    n2=right-cen
    L=[a[left+i] for i in range(n1)]+[inf]
    R=[a[cen+i] for i in range(n2)]+[inf]
    i,j=0,0
    for k in range(left,right):
        cnt+=1
        if L[i]<=R[j]:
            a[k]=L[i]
            i+=1
        else:
            a[k]=R[j]
            j+=1
    return cnt

def sorting(a,left,right):
    if left+1<right:
        m=(left+right)//2
        cntlr=sorting(a,left,m)+sorting(a,m,right)
        return merge(a,left,m,right)+cntlr
    return 0

n=int(input())
a=list(map(int,input().split()))
ans=sorting(a,0,n)
print(*a)
print(ans)


Measured memory_bytes: 63436
dice_1 = input().split()
dice_2 = input().split()

rolls = {' ':[0, 1, 2, 3, 4, 5], 
         'W':[2, 1, 5, 0, 4, 3], 
         'N':[1, 5, 2, 3, 0, 4], 
         'E':[3, 1, 0, 5, 4, 2], 
         'S':[4, 0, 2, 3, 5, 1]
        }
orders = [' ', 'N', 'W', 'E', 'S', 'NN']
tf = 0
for order in orders:
    copy_2 = dice_2
    for d in order:
        roll = rolls[d]
        copy_2 = [copy_2[i] for i in roll]
    
    l = [1, 2, 4, 3]
    a0 = copy_2[0] == dice_1[0]
    a1 = copy_2[5] == dice_1[5]
    a2 = ' '.join([copy_2[s]for s in l]) in ' '.join([dice_1[s]for s in l] * 2)
    if  a0 and a1 and a2:
        tf += 1

#    print(order)
#    print(' '.join([copy_2[s]for s in l]))
#    print(' '.join([dice_1[s]for s in l] * 2))
#    print(copy_2)

if tf>0:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 5572
#include <iostream>
#include <algorithm>
#include <set>
#include <math.h>
#include <stdio.h>
#include <string.h>
using namespace std;
typedef long long ll;
int main()
{
   int n,x,a[100001];
   ll sum=0;
   cin>>n>>x;
   for(int i=0;i<n;i++)scanf("%d",&a[i]);

   for(int i=1;i<=n-1;i++){
    if(a[i]+a[i-1]<=x) continue;
    else
    {
        if(a[i]+a[i-1]>x){
            ll p=abs((a[i]+a[i-1])-x);
            sum+=p;
            a[i]-=p;
            if(a[i]>=0)continue;
            else {a[i]=0;a[i-1]-=(p-a[i]);}
        }
    }
   }

   cout<<sum<<endl;
   return 0;
}


Measured memory_bytes: 640
//#include <stdio.h>
#include <math.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <queue>
#include <map>
#include <utility>
#include <iomanip>

using namespace std;

#define ll long long

void solve()
{
    ll N;
    cin >> N;

    vector<ll> A(N);

    for (ll i = 0; i < N; i++)
    {
        cin >> A.at(i);
        if ((A.at(i) % 2 == 0) &&
            (A.at(i) % 3 != 0) && (A.at(i) % 5 != 0))
        {
            cout << "DENIED" << endl;
            return;
        }
    }

    cout << "APPROVED" << endl;

    return;
}

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


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

using namespace std;

struct union_find {
    vector<int> par, sz;

    union_find(int n) {
        par.resize(n);
        sz.resize(n);
        for (int i =0; i < n; i++)
            par[i] = i, sz[i] = 0;
    }

    int find(int x) {
        if (par[x] == x)
            return x;
        else 
            return par[x] = find(par[x]);
    }

    void unite(int x, int y) {
        x = find(x), y = find(y);

        if (x == y) return ;

        else if (sz[x] < sz[y])
            par[x] = y;
        else {
            par[y] = x;
            if (sz[x] == sz[y])
                sz[x]++;
        }
    }

    bool same(int x, int y) {
        return find(x) == find(y);
    }
};

int main() {
    int n, m;  cin >> n >> m;
    union_find u(n);
    int *p = new int[n];
    for (int i = 0; i < n; i++)
        cin >> p[i];
    for (int i = 0; i < m; i++) {
        int x, y;   cin >> x >> y;
        x--, y--;
        u.unite(x, y);
    }

    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (u.same(p[i]-1, i))
            ans++;
    }

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

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

map< ll, int > prime_factor(ll n) {
  map< ll, int > ret;
  for(ll i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}

int main() {
  ll a, b;
  cin >> a >> b;
  ll ans=1;
  for(auto p: prime_factor(a)) {
    if(prime_factor(b).count(p.first)) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
#include <set>
#include <math.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll mod = 1000000007;
const ll INF = 1000000000000000;
ll bit[100010], num;
ll par[100010];
ll n, m, dp[100010];
map<ll, ll> mp;
vector<ll> road[100010];

struct edge { ll to, cost; };
ll V;
vector<edge> G[300010];
ll d[300010];

void dijkstra(ll s)
{
	priority_queue<P, vector<P>, greater<P>> que;
	for (int i = 0; i <= 300010; i++)
	{
		d[i] = INF;
	}
	d[s] = 0;
	que.push(P(0, s));

	while (!que.empty())
	{
		P p = que.top(); que.pop();
		ll v = p.second;
		if (d[v] < p.first) continue;
		for (ll i = 0; i < G[v].size(); i++)
		{
			edge e = G[v][i];
			if (d[e.to] > d[v] + e.cost)
			{
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to], e.to));
			}
		}
	}
}

ll sum(ll i)
{
	ll s = 0;
	while (i > 0)
	{
		s += bit[i];
		i -= i & -i;
	}
	return s;
}

void add(ll i, ll x)
{
	while (i <= num)
	{
		bit[i] += x;
		i += i & -i;
	}
}

ll po(ll x, ll y)
{
	if (y == 0) return 1;
	if (y % 2)
	{
		return po(x, y - 1) * x % mod;
	}
	else
	{
		ll yyy = po(x, y / 2);
		return yyy * yyy % mod;
	}
}

ll div(ll x)
{
	return po(x, mod - 2);
}

ll dfs(ll x)
{
	if (dp[x] != INF) return dp[x];
	ll res = 0;
	for (int i = 0; i < road[x].size(); i++)
	{
		res = max(res, 1 + dfs(road[x][i]));
	}
	return dp[x] = res;
}

int main(void)
{
	cin >> n >> m;
	for (int i = 0; i < m; i++)
	{
		ll x, y;
		cin >> x >> y;
		road[x].push_back(y);
	}
	for (int i = 1; i <= n; i++)
	{
		dp[i] = INF;
	}
	ll ans = 0;
	for (int i = 1; i <= n; i++)
	{
		ans = max(dfs(i), ans);
	}
	cout << ans << endl;
	int www;
	cin >> www;
}


Measured memory_bytes: 15872
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int x = Integer.parseInt(sc.next());
        int y = Integer.parseInt(sc.next());
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        int c = Integer.parseInt(sc.next());
        Integer[] rc = new Integer[a];
        Integer[] gc = new Integer[b];
        Integer[] nc = new Integer[c];
        PriorityQueue<Integer> rq = new PriorityQueue<>(Comparator.reverseOrder());
        PriorityQueue<Integer> gq = new PriorityQueue<>(Comparator.reverseOrder());
        PriorityQueue<Integer> nq = new PriorityQueue<>(Comparator.reverseOrder());
        for(int i=0; i<a; i++){
            rc[i] = Integer.parseInt(sc.next());
            rq.add(rc[i]);
        }
        for(int i=0; i<b; i++){
            gc[i] = Integer.parseInt(sc.next());
            gq.add(gc[i]);
        }
        for(int i=0; i<c; i++){
            nc[i] = Integer.parseInt(sc.next());
            nq.add(nc[i]);
        }
        nq.add(-1);
        Arrays.sort(rc, Collections.reverseOrder());
        Arrays.sort(gc, Collections.reverseOrder());
        PriorityQueue<Integer> red = new PriorityQueue<>();
        PriorityQueue<Integer> green = new PriorityQueue<>();
        
        long ans = 0;
        for(int i=0; i<x; i++){
            red.add(rc[i]);
            ans += rc[i];
        }
        for(int i=0; i<y; i++){
            green.add(gc[i]);
            ans += gc[i];
        }
        
        while(nq.size()!=0){
            int tmp = nq.poll();
            int s = red.peek();
            int t = green.peek();
            if(s < t){
                if(s < tmp){
                    ans -= red.poll();
                    ans += tmp;
                    red.add(tmp);
                }
            }else{
                if(t < tmp){
                    ans -= green.poll();
                    ans += tmp;
                    green.add(tmp);
                }
            }
        }
        
        System.out.println(ans);
        
    }
}


Measured memory_bytes: 70520
#pragma GCC optimize(3)
#include<bits/stdc++.h>
#define ll long long
#define db double
#define P pair<ll,ll>
#define mp make_pair
#define fi first
#define se second
#define INF 0x3f3f3f3f3f3f3f3f
#define N 1010
#define M 
using namespace std;

ll n,m,ans,num[N][N],dir[4][2]={1,0,-1,0,0,1,0,-1};
char mm[N][N];
queue<P>que;

int main()
{
    memset(num,-01,sizeof(num));
    ll i,j,p,q,x,y;
    cin>>m>>n;
    for(i=1;i<=m;i++)
    {
	scanf("%s",mm[i]+1);
	for(j=1;j<=n;j++)
	{
	    if(mm[i][j]!='#') continue;
	    num[i][j]=0;
	    que.push(mp(i,j));
	}
    }
    for(;!que.empty();)
    {
	p=que.front().fi;
	q=que.front().se;
	que.pop();
	for(i=0;i<4;i++)
	{
	    x=p+dir[i][0];
	    y=q+dir[i][1];
	    if(num[x][y]!=-1 || !x || x>m || !y || y>n) continue;
	    num[x][y]=num[p][q]+1;
	    ans=max(ans,num[x][y]);
	    que.push(mp(x,y));
	}
    }
    cout<<ans;
}



Measured memory_bytes: 25524
import java.util.*;
 
class Main {
    
	static int res=0,d,w,E[][]=new int[10][10];
	
    public static void main(String[] args) {
         
       Scanner cin=new Scanner(System.in);
       
       while(true) {
    	   int n=cin.nextInt();
    	   
    	   if(n==0)break;
    	   else if(n==1) {
    		   System.out.println(1);
    		   continue;
    	   }
    	   
    	   int res=0;
    	   List<Integer> A=new ArrayList<>();
    	   A.add(2);
    	   for(int i=3;i<=2*n;i++) {
    		   boolean jd=true;
    		   for(int j=0;j<A.size();j++) {
    			   if(i%A.get(j)==0) {
    				   jd=false;
    				   break;
    			   }
    		   }
    		   
    		   if(jd) {
    			   A.add(i);
    			   if(i>n)res++;
    		   }
    		   
    	   }
    	   
    	   System.out.println(res);
       }
    }
}


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

import operator

N,H,W = map(int,readline().split())
m = map(int,read().split())
RCA = sorted(zip(m,m,m),key=operator.itemgetter(2),reverse=True)

root = list(range(H+W))
size = [0] * (H+W)
no_cycle = [True] * (H+W)

def find_root(x):
    y = root[x]
    if x == y:
        return x
    path = [x]
    while y != root[y]:
        path.append(y)
        y = root[y]
    for p in path:
        root[p] = y
    return y

def merge(x,y):
    x,y = find_root(x),find_root(y)
    sx,sy = size[x],size[y]
    if sx < sy:
        sx,sy = sy,sx
        x,y = y,x
    root[y] = x
    no_cycle[x] = no_cycle[x] and no_cycle[y]

answer = 0
for R,C,A in RCA:
    x,y = R-1,H+C-1
    rx,ry = find_root(x),find_root(y)
    if rx == ry:
        if not no_cycle[rx]:
            continue
        no_cycle[rx] = False
    else:
        if (not no_cycle[rx]) and (not no_cycle[ry]):
            continue
        merge(rx,ry)
    answer += A

print(answer)

Measured memory_bytes: 34680
#pragma GCC optimze("Ofast")
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define mod 1000000007
#define md 998244353
#define trace(...)
#define ll long long int
#define ld long double
#define fi first
#define se second
#define fr(i,a,b) for(ll i=a;i<=b;i++)
#define frr(i,b,a) for(ll i=b;i>=a;i--)
#define mem(a) memset(a, 0, sizeof(a))
#define vpi std::vector<pair<int,int>>
#define pii pair<int,int>
#define pb push_back
#define sall(v) sort(v.begin(),v.end())
#define all(v) (v.begin(),v.end())
#define minf -10000000
const ll infl=0x3f3f3f3f3f3f3f3fLL;
const int infi=0x3f3f3f3f;
typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> oset;
auto clk=clock();
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) {
    uniform_int_distribution<int> uid(0,lim-1);
    return uid(rang);
}
ll power(ll x, ll y,ll p) { 
    ll res = 1;      // Initialize result 
    x = x % p;  // Update x if it is more than or equal to p 
    while (y > 0) {  
        if (y & 1) // If y is odd, multiply x with result
            res = (res*x) % p;  
        y = y>>1; // y = y/2 // y must be even now
        x = (x*x) % p;   
    } 
    return res; 
}
ll power(ll x, ll y) { 
    ll res = 1;      // Initialize result 
    while (y > 0) {    
        if (y & 1)// If y is odd, multiply x with result 
            res = (res*x) ;  
        y = y>>1; // y = y/2 // y must be even now 
        x = (x*x);   
    } 
    return res; 
}
 
ll max3(ll a,ll b,ll c){
    return max(a,max(b,c));
}
ll min3(ll a,ll b,ll c){
    return min(a,min(b,c));
}
bool isPrime(ll n) { // Corner cases 
    if (n <= 1) 
        return false; 
    if (n <= 3) 
        return true; 
    if (n % 2 == 0 || n % 3 == 0) 
        return false; 
    for (ll i = 5; i * i <= n; i = i + 6) 
        if (n % i == 0 || n % (i + 2) == 0) 
            return false; 
    return true; 
}

void solve() {
    int n;cin>>n;
    int arr0[n];
    int arr1[n];
    int arr2[n];
    fr(i,0,n-1)cin>>arr0[i]>>arr1[i]>>arr2[i];
    int dp[3][n];fr(i,0,n-1)dp[0][i]=dp[1][i]=dp[2][i]=1e9;
    dp[0][0]=arr0[0];dp[1][0]=arr1[0];dp[2][0]=arr2[0];
    fr(i,1,n-1){
        dp[0][i]=arr0[i]+max(dp[1][i-1],dp[2][i-1]);
        dp[1][i]=arr1[i]+max(dp[0][i-1],dp[2][i-1]);
        dp[2][i]=arr2[i]+max(dp[1][i-1],dp[0][i-1]);
    }
    cout<<max3(dp[0][n-1],dp[1][n-1],dp[2][n-1])<<endl;
    return ;
}

int main(){
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());
    cout<<fixed<<setprecision(8);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    #endif
    int t;
    // cin>>t;
    t=1;
    while(t--){
        solve();
    }
    #ifndef ONLINE_JUDGE
    cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
    #endif
    return 0;
}


Measured memory_bytes: 5928
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
#include <climits>

using namespace std;

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

  int x[N];

  for (int i = 0; i < N; i++) {
    cin >> x[i];
  }

  int ans = 0;
  for (int i = 0; i < N; i++) {
    ans += 2 * min(x[i], K - x[i]);
  }

  cout << ans << endl;

  return 0;
}

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

int main(){
  int N;
  cin>>N;
  unordered_map<int,int> x;
  for(int i=0;i<N;i++){
    int a;
    cin>>a;
    if(x.count(a-1))
      x[a-1]++;
    else
      x[a-1]=1;
    if(x.count(a))
      x[a]++;
    else
      x[a]=1;
    if(x.count(a+1))
      x[a+1]++;
    else
      x[a+1]=1;
  }
  int j=0;
  for(pair<int,int> i:x)
    j=max(j,i.second);
  cout<<j<<endl;
}

Measured memory_bytes: 4260
import sys

N=int(input())
NOSET=set([1<<i for i in range(50)])

if N in NOSET:
    print("No")
    sys.exit()

print("Yes")
print(1,2)
print(1,3)
print(2,3+N)
print(3,2+N)
print(1+N,2+N)

t=(N+1)//2*2
for i in range(4,t,2):
    print(1,i)
    print(1,i+1)
    print(i,i+1+N)
    print(i+1,i+N)
    
if N%2==0:
    N_head = 1<<(N.bit_length()-1)
    print(N,N_head)
    print(N*2,N^N_head^1)

Measured memory_bytes: 5436
#include <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
using ld = long double;
template <typename T> using lim = numeric_limits<T>;
template <typename T> istream& operator>>(istream& is, vector<T>& a) { for(T& x : a) { is >> x; } return is; }
template <typename X, typename Y> istream& operator>>(istream& is, pair<X, Y>& p) { return is >> p.first >> p.second; }
const int N = 60;
const ll INF = 1ll << 50;
ll mem[N+1][2][2];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<ll> a(n);
    cin >> a;
    ll target = accumulate(a.begin() + 2, a.end(), 0ll, bit_xor<ll>());
    bitset<N> a0(a[0]), a1(a[1]), t(target);
    memset(mem, -1, sizeof mem);
    function<ll(int, int, int)> opt = [&](int b, int borrow0, int carry1) {
        ll& ans = mem[b][borrow0][carry1];
        if(ans == -1) {
            if(b == N) {
                ans = borrow0 == 0 and carry1 == 0 ? 0 : INF;
            } else {
                ans = INF;
                int b0 = a0[b] ^ borrow0;
                int b1 = a1[b] ^ carry1;
                if((b0 ^ b1) == t[b]) {
                    ans = min(ans, opt(b + 1, not a0[b] and borrow0, a1[b] and carry1));
                    ans = min(ans, (1ll << b) + opt(b + 1, a0[b] - borrow0 - 1 < 0, a1[b] + carry1 + 1 >= 2));
                }
            }
        }
        return ans;
    };
    ll ans = opt(0, 0, 0);
    cout << (ans < a[0] ? ans : -1) << endl;
    return 0;
}


Measured memory_bytes: 3664
N,  M = map(int,input().split())
A = list(map(int, input().split()))
Asort = sorted(A,reverse = True)
ans = 'Yes'
c = 0
for a in Asort:
    if a < sum(Asort)*(1/(4*M)):
        ans = 'No'
    c += 1
    if c == M:
        break
print(ans)

Measured memory_bytes: 3064
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
#define mp make_pair
#define MAX 20000
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef vector<long long> vll;
typedef vector<ii> vii;
#define EPS 1e-9
#define LSOne(S) (S & (-S))
#define INF 1000*1000*1000+889
const int N = 1e5+10;
int n,ans=0;
void getlucky(ll x)
{
    if(x>n)
        return;
    ll temp = x;
    bool t=false,f=false,s=false;
    while(temp)
    {
        if(temp%10==3)
            t = true;
        if(temp%10==5)
            f = true;
        if(temp%10==7)
            s = true;
        temp/=10;
    }
    if(t&&s&&f)
        ans++;
    getlucky(x*10+3);
    getlucky(x*10+5);
    getlucky(x*10+7);
}
int main(void)
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n;
    getlucky(0);
    cout<<ans;
}


Measured memory_bytes: 256
import java.util.*;
import static java.lang.System.*;
import java.io.*;
import java.math.*;

public class Main {

	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		int n = sc.nextInt();
		HashSet<Integer> set = new HashSet<>();
		for(int i = 0; i < n; i++) {
			int num = sc.nextInt();
			if (set.contains(num)) {
				set.remove(num);
			} else {
				set.add(num);
			}
		}
		out.println(set.size());

		out.close();
	}

static class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}
}

Measured memory_bytes: 28708
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<math.h>
#include<map>

using namespace std;
#define mod 1000000007
#define ll long long 


ll n, arr[3009];
ll dp[3009][3009];


long long solve(int idx, int jdx) {
	
	if(idx > jdx)
		return 0;

	if(dp[idx][jdx] != -1)
		return dp[idx][jdx];

	ll ans = arr[idx] - solve(idx + 1, jdx);
	ans = max(ans, arr[jdx] - solve(idx, jdx - 1));

	return dp[idx][jdx] = ans;
}


int main() {

	// memset(dp, -1, sizeof(dp));
	for(int i = 0; i < 3009; i++) {
		for(int j = 0; j < 3009; j++)
			dp[i][j] = -1;
	}

	cin>>n;

	for(int i = 0; i < n; i++) {
		scanf("%lld", &arr[i]);
	}

	cout<<solve(0, n - 1)<<endl;

	return 0;
}

Measured memory_bytes: 71168
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include<cstdio>
#include<bits/stdc++.h>
using namespace std;
using ll =long long;

int main (void) {
  int H,W;
  cin >> H >> W;
  char A[H+2][W+2];
  char s,t;
  for (int i=0; i<=H+1; i++) {
      for (int j=0; j<=W+1; j++) {
        if (i==0 || j==0 || i==H+1|| j==W+1){
          printf("%c", 35);
          continue;
        }
        cin >> s;
        t=s;
        A[i][j]=t;
        cout << A[i][j];
      }
  cout << endl;
  }
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**7)
from collections import deque
n,x,y = map(int,input().split())
g = [[]for i in range(n)]
g[0].append(1)
g[n-1].append(n-2)
g[x-1].append(y-1)
g[y-1].append(x-1)
for i in range(1,n-1):
  g[i].append(i-1)
  g[i].append(i+1)
ans = [0]*(n-1)
def dfs(b,c):
  for i in g[b]:
    if a[i] > c+1:
      a[i] = c+1
      que.append([i,c+1])
    
for i in range(n):
  a = [999999999]*n
  a[i] = 0
  que = deque()
  que.append([i,0])
  while que:
    x,y = que.popleft()
    dfs(x,y)
  for j in a:
    if j == 0:
      continue
    ans[j-1] += 1
for i in ans:
  print(i//2)

Measured memory_bytes: 57692
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n - 1; i >= 0; i--)
#define ALL(x) x.begin(),x.end()
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

const ll INF = 1e18;
const int mod = 1e9+7;
const int MAX = 1e6;

bool is_prime(int x) { // 素数判定
    if (x < 2) return false;
    for (int i = 2; i * i <= x; i++) {
        if (x % i == 0) return false;
    }
    return true;
}

int seive[MAX+1]; // 整数の素因数で最小のもの

void erat() { // エラトステネスのふるい
    rep(i, MAX+1) seive[i] = i; // 初期化
    for (int i = 2; i <= MAX; i++) {
        if (seive[i] == i) { // seive[i]=iならばiは素数
            for (int j = i + i; j <= MAX; j += i) {
                seive[j] = i;
            }
        }
    }
}

void prime_fact(int x, set<int> &fact) { // 高速素因数分解
    while (x > 1 && x % seive[x] == 0) {
        fact.insert(seive[x]); // 素因数
        x /= seive[x];
    }
}


void prime_fact(int x, vector<int> &fact) { // 素因数分解
    for (int i = 2; i * i <= x; i++) {
        while (x % i == 0) {
            fact.push_back(i); // 素因数
            x /= i;
        }
    }
    if (x != 1) {
        fact.push_back(x);
    }
}

int main() {
    int n;
    cin >> n;
    map<int, int> p; // n!に含まれる素因数を格納
    // for (int i = 2; i <= n; i++) {
    //     int x = i;
    //     for (int j = 2; j * j <= x; j++) {
    //         while (x % j == 0) {
    //             p[j]++; // jはxの素因数
    //             x /= j;
    //         }
    //     }
    //     if (x != 1) p[x]++; // xは1か素数
    // }
    erat();
    for (int i = 2; i <= n; i++) {
        int x = i;
        while (x > 1 and x % seive[x] == 0) {
            p[seive[x]]++;
            x /= seive[x];
        }
    }
    ll ans = 1;
    for (int i = 2; i <= n; i++) {
        if (p.count(i)) ans *= p[i] + 1;
        ans %= mod;
    }
    cout << ans << "\n";
}

Measured memory_bytes: 7528
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

struct node{
  unsigned int key;
  struct node *next;
  struct node *prev;
};

typedef struct node * NodePointer;

NodePointer nil;

NodePointer listSearch(int key){
  NodePointer cur = nil->next;
  while( cur != nil && cur->key != key ){
    cur = cur->next;
  }
  return cur;
}

void init(){
  nil = malloc(sizeof(struct node));
  nil->next = nil;
  nil->prev = nil;
}

void printList(){
  NodePointer cur = nil->next;
  int isf = 1;
  while(1){
    if ( cur == nil ) break;
    if ( isf == 0)  printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
    isf = 0;
  }
  printf("\n");
}

void deleteNode(NodePointer t){
  t->prev->next = t->next;
  t->next->prev = t->prev;
  //  free(t);
}

void deleteFirst(){
  NodePointer t = nil->next;
  if ( t == nil ) return;
  deleteNode(t);
}

void deleteLast(){
  NodePointer t = nil->prev;
  if ( t == nil ) return;
  deleteNode(t);
}

void delete(int key){
  NodePointer t = listSearch(key);
  if ( t == nil ) return;
  deleteNode(t);
}


void insert(int key){
  NodePointer x;
  x = malloc(sizeof(struct node));
  x->key = key;
  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;
  x->prev = nil;
}

int main(){
  int key, n, i;
  int size = 0;
  char com[20];
  int np = 0, nd = 0;
  scanf("%d", &n);
  init();
  for ( i = 0; i < n; i++ ){
    scanf("%s%d", com, &key);
    if(!( 0 <= key && key <= 2000000000)){printf("error") ;}
    if ( com[0] == 'i' ) {insert(key); np++; size++;}
    else if ( com[0] == 'd' ) {
      if (strlen(com) > 6){
	if ( com[6] == 'F' ) deleteFirst();
	else if ( com[6] == 'L' ) deleteLast();
      } else {
	delete(key); nd++; 
      }
      size--;
    }
    if ( size > 1000000 ) { printf("error"); }
  }

  
  if(!( np+nd <= 2000000)){printf("error") ;}
  if(!( nd <= 20)){printf("error") ;}
  printList();


  return 0;
}



Measured memory_bytes: 36068
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
#define ll long long

int main(){
  string s;
  cin >> s;
  ll k;
  cin >> k;
  int cnt;
  cnt = s.size();
  char t;
  for(int i=0; i<s.size(); i++){
    if(s[i] != '1'){
      t = s[i];
      cnt = i;
      break;
    }
  }
  if(k<=cnt){
    cout << 1 << endl;
  }else{
    cout << t << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define ll long long int
#define oo 1000000000000000000
#define forr(i,n) for(ll i=0;i<n;i++)
#define fastio ios_base::sync_with_stdio(false); cin.tie(0) ; cout.tie(0);
#define all(x) x.begin(),x.end()
#define eb emplace_back
#define pb push_back
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
 
using namespace __gnu_pbds; 
using namespace std;

const ll MOD = 1e9 + 7;

ll valueOfIndex(ordered_set&s , ll i){ return *(s.find_by_order(i)); }
ll indexOfValue(ordered_set&s , ll x){ return s.order_of_key(x); }

ll add(ll a, ll b,ll p=MOD) { a%=p; b%=p; return (a+b + p)%p;}
ll mul(ll a, ll b,ll p=MOD) { a%=p; b%=p; return (a*b + p)%p;} // __int128

ll power(ll x,ll n,ll p=MOD){ if(x==0) return 0; if(n==0 || x==1) return 1LL;
    ll r = (power(x,n/2,p))%p; if(n&1) return mul(mul(r,r,p) , x,p); else return mul(r,r,p);
}



void __sol(){
    ll n; cin >> n;
    vector<pair<ll,ll>> v(n),p,q,r;
    forr(i,n) cin >> v[i].first;
    forr(i,n) cin >> v[n-i-1].second;
    int i = 0,j=0,k=0;
    while(i<n && v[i].first!=v[i].second) p.pb(v[i]),i++;
    while(i<n && v[i].first==v[i].second) q.pb(v[i]),i++;
    while(i<n && v[i].first!=v[i].second) r.pb(v[i]),i++;
    i=0;
    while( i<p.size() && j<q.size()){
        if( p[i].first!=q[j].second  && p[i].second!=q[j].first){
            swap(p[i].second,q[j].second);
            i++,j++;
        }
        else i++;
    }
    while( k<r.size() && j<q.size()){
        if( r[k].first!=q[j].second && r[k].second!=q[j].first){
            swap(r[k].second,q[j].second);
            k++,j++;
        }
        else k++;
    }
    for(auto &i: p){
        if(i.first==i.second){
            cout << "No\n";
            return;
        }
    }
    for(auto &i: q){
        if(i.first==i.second){
            cout << "No\n";
            return;
        }
    }
    for(auto &i: r){
        if(i.first==i.second){
            cout << "No\n";
            return;
        }
    }
    cout << "Yes\n";

    for(auto &i: p) cout << i.second << " ";
    for(auto &i: q) cout << i.second << " ";
    for(auto &i: r) cout << i.second << " ";
    
    return;
}


int main(){
    fastio
    ll tc=1;// cin >> tc;
    while(tc--) __sol();
    return 0;
}


Measured memory_bytes: 11604
#include<iostream>
#include<cstdio>
#include<algorithm>

using namespace std;

struct store {
	long A;
	int B;
};

bool cmp(const store &left, const store &right) {
	if (left.A >= right.A) {
		return false;
	}
	else {
		return true;
	}
}

int main(void)
{
	int N, M;
	int i, tmp;
	int need;
	long ans = 0;

	cin >> N >> M;
	store *input = new store[N + 3];

	for (i = 0; i < N; i++) {
		cin >> input[i].A >> input[i].B;
	}
	input[N].A = 1000000005;
	input[N].B = 1;

	sort(input, input+N, cmp);
	
	need = M;
	for (i = 0; i < N; i++) {
		tmp = input[i].B;
		if (tmp >= need) {
			ans = ans + (long)input[i].A * need;
			cout << ans << endl;
			return 0;
		}
		else {
			need = need - tmp;
			ans = ans + (long)input[i].A*tmp;
		}
	}


	delete[] input;

	return 0;
}


Measured memory_bytes: 1792
#include <cstdio>           // printf(), scanf()
#include <vector>
#include <list>

using namespace std;
static const int MAX_V = 10000;

vector<int> G[MAX_V];
list<int> out;
bool visited[MAX_V];

void
dfs(int u)
{
	visited[u] = true;
	for (unsigned int i = 0; i < G[u].size(); ++i)
	{
		int v = G[u][i];
		if (!visited[v])
			dfs(v);
	}

	out.push_front(u);
}

int
main(int argc, char** argv)
{
	int V, E;
	int s, t;

	scanf("%d %d", &V, &E);
	for (int i = 0; i < V; ++i)
		visited[i] = false;

	for (int i = 0; i < E; ++i)
	{
		scanf("%d %d", &s, &t);
		G[s].push_back(t);
	}

	for (int i = 0; i < V; ++i)
	{
		if (!visited[i])
			dfs(i);
	}

	for (list<int>::iterator it = out.begin(); it != out.end(); ++it)
		printf("%d\n", *it);

	return 0;
}

Measured memory_bytes: 2004
// https://atcoder.jp/contests/m-solutions2019/tasks/m_solutions2019_b

#include <bits/stdc++.h>
#define REP(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define REPR(i, n) for (int(i) = (n); (i) >= 0; (i)--)
#define FOR(i, m, n) for (int(i) = (m); (i) < (n); i++)
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;

int main()
{
  string S;
  int win = 0, remain = 15;
  cin >> S;

  for (auto &c : S)
  {
    remain--;
    if (c == 'o')
      win++;
  }

  if (7 < remain + win)
    cout << "YES" << '\n';
  else
    cout << "NO" << '\n';

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
	int n;
	int a,b,c,d;
	int count;
	while(scanf("%d",&n)!=EOF){
		count=0;
		for(a=0;a<=9;a++){
			for(b=0;b<=9;b++){
				for(c=0;c<=9;c++){
					for(d=0;d<=9;d++)if(n-a-b-c-d==0)count++;
				}
			}
		}
		printf("%d\n",count);
	}
	return 0;
}

Measured memory_bytes: 596
#include<stdio.h>
int main()
{
  int n;
  long long int ans;
  ans=1;
  scanf("%d",&n);
  long long int a[100005];
  for(int i=0;i<n;i++)
  {
      scanf("%lld",&a[i]);
      if(!a[i])
      {
          printf("0\n");
          return 0;
      }
  }
 for(int i=0;i<n;i++)
  {
    long long int temp;
    temp=ans*a[i];
    if(ans>temp||temp>1000000000000000000)
    {  printf("-1\n"); return 0;}
    ans=temp;
  }
  printf("%lld",ans);
  return 0;
}


Measured memory_bytes: 2492
#include <iostream>
using namespace std;
int main(){
  int W;
  int H;
  int x;
  int y;
  int r;
  cin>>W>>H>>x>>y>>r;
  if(x-r>=0&&y-r>=0&&x+r<=W&&y+r<=H){
    
      
    cout << "Yes" << endl;
    return 0;
  }
  cout << "No" << endl;
  return 0;

}
  


Measured memory_bytes: 3108
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <queue>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
const long long MOD = 1000000007LL;
const string alpha = "abcdefghijklmnopqrstuvwxyz";
long long gcd(long long a,long long b){
    if(b > a){
        swap(a,b);
    }
    bool flag = true;
    long long gcdl;
    while(flag){
        if(a%b == 0){
            flag = false;
            gcdl = b;
        }
        else{
            swap(a,b);
            b = b % a;
        }
    }
    return gcdl;
}
int main(){
    long long n,p;
    cin >> n >> p;
    long long a[n];
    long long gcda;
    rep(i,n){
        cin >> a[i];
        if(i==0){
            gcda = a[i];
        }
        else{
            gcda = gcd(gcda,a[i]);
        }
    }
    sort(a,a+n);
    if(p<=a[n-1]&&p%gcda==0){
        cout << "POSSIBLE" << endl;
    }
    else{
        cout << "IMPOSSIBLE" << endl;
    }
}

Measured memory_bytes: 1024
#include<stdio.h>
int main(){
  char a;

  while(1){
    scanf("%c",&a);
    if('a' <= a && a <= 'z'){
      printf("%c",a-32);
    }
    else if('A' <= a && a <= 'Z'){
      printf("%c",a+32);
    }
    else printf("%c",a);
    if(a == '\n')break;
  }
}



Measured memory_bytes: 2056
#include<stdio.h>
#include<stdlib.h>

int compare_int(const void *a,const void *b){
	return *(long*)a-*(long*)b;
}

int main(){
	int n,i,ans=0;
	long a[100000],c;
	scanf("%d",&n);
	for(i=0;i<n;i++)scanf("%ld",&a[i]);
	qsort(a,n,sizeof(long),compare_int);
	c=a[0];ans=n;
	for(i=1;i<n;i++){
		if(c==a[i]){
			c=-1;
			ans-=2;
		}else c=a[i];
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 1788
#include <iostream> 
#include <queue>
#include <algorithm>
#define MAX 10000
#define INF (1<<21)
#define WHITE 0
#define GRAY  1
#define BLACK 2
using namespace std;

int n;
vector<pair<int, int>> adj_list[MAX];

void Dijkstra() 
{
    priority_queue<pair<int,int>> PQ;
    int next, min_cost;
    int color[n], dist[n];

    for (int i = 0; i < n; ++i) 
    {
        color[i] = WHITE;
        dist[i] = INF;
    }

    dist[0] = 0;
    PQ.push(make_pair(0, 0));
    color[0] = GRAY;

    while(! PQ.empty())
    {
        pair<int, int> next = PQ.top(); PQ.pop();
        int u = next.second;

        color[u] = BLACK;

        if (dist[u] < next.first * (-1)) continue;

        for (int i = 0; i < adj_list[u].size(); ++i) 
        {
            int v = adj_list[u][i].first;
            if (color[v] == BLACK) continue;
            if (dist[v] > dist[u] + adj_list[u][i].second)
            {
                color[v] = GRAY;
                dist[v] = dist[u] + adj_list[u][i].second;
                PQ.push(make_pair(dist[v]*(-1), v));
            }
        }
    }
    
    int sum = 0;
    for (int i = 0; i < n; ++i) 
    {
        cout << i << ' ' << (dist[i] != INF ? dist[i] : -1) << endl; 
    }
}

int main() 
{
    int id, deg, v, w;

    cin >> n;
    for (int i = 0; i < n; ++i) 
    {
        cin >> id >> deg;
        for (int j = 0; j < deg; ++j) 
        {
            cin >> v >> w;
            adj_list[id].push_back(make_pair(v, w));
        }
    }

    Dijkstra();

    return 0;
}


Measured memory_bytes: 8000
#include <bits/stdc++.h>
using namespace std;
const unsigned int MOD = 1000000007;
#define ll long long
#define PI 3.1416
string day[]={"SUN","MON","TUE","WED","THU","FRI","SAT"};
int main() {
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int x,a,b;
    while(cin>>x>>a>>b){
        abs(x-a)<abs(x-b)?cout<<"A"<<endl:cout<<"B"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
var N : Int = (Int)(readLine()!)!
let data : [Int]  = [100,101,102,103,104,105]
let size = 1000000 + 1;
var dp = [Int](count: size, repeatedValue: -1)
dp[0] = 0;

for idx in 0..<size{
    if dp[idx] == -1{
        continue;
    }
    for value in data{
        if idx + value  < size {
            dp[idx + value] = 1;
        }
    }
}

if dp[N] == -1 {
    print(0)
} else {
    print(1)
}


Measured memory_bytes: 8448
#include <bits/stdc++.h>
#include <set>
#define rep(i,n) for (int i=0; i < (n); ++i)
#define all(a) a.begin(), a.end()
using ll = long long;
using namespace std;
 
// ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }


// const double PI = acos(-1);

void solve() {
  int r,g,b; cin >> r >> g >> b;
  // string ans = to_string(r+g+b);
  string r_str= to_string(r);
  string g_str= to_string(g);
  string b_str= to_string(b);
  string ans = r_str + g_str + b_str;
  int num = stoi(ans);
  if (num%4==0) {
    cout << "YES" << endl;
  }
  else {
    cout << "NO" << endl;
  }

}

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


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout<<(ans)<<endl
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define _LIBCPP_DEBUG 0
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);};};
const int MOD = 1000000007;
const int INF = INT_MAX;
const ll LLINF = 1LL<<62;
//g++ -std=c++1z main.cpp
//.\a.exe

int main(){
///////////////////////////////////////////////////////////
ll n,ans=0;
cin >> n;
ll a[n],b[n+1];
for(int i=0;i<n;i++){
    cin >> a[i];
}
for(int i=1;i<n+1;i++){
    b[i]=a[i-1]+b[i-1];
}
map<ll,ll> m;

for(int i=0;i<n+1;i++){
    m[b[i]]++;
}
for(auto it = m.begin(); it != m.end(); it++) {
    if(it->second>=2){
        ans=ans+it->second*(it->second-1)/2;
    }
}


cout << ans << endl;
//////////////////////////////////////////////////////////
}

Measured memory_bytes: 15872
#include <iostream>
#include <cmath>

using std::cin;

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

    int cnt = 0;
    while (data_num--) {
        int n;
        cin >> n;

        bool is_prime = true;
        if (n == 2) {
            is_prime = true;
        } else if (n % 2 == 0) {
            is_prime = false;
        } else {
            for (auto i = 3; i <= sqrt(n); i += 2) {
                if (n % i == 0) {
                    is_prime = false;
                    break;
                }
            }
        }

        if (is_prime == true) {
            cnt++;
        }
    }

    std::cout << cnt << std::endl;

    return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#define REP(i, n) for (int i = 0; i < (n); ++i)
using namespace std;

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

    int tmp = n;
    int digit = 0;
    while (tmp != 0) {
        tmp /= 10;
        digit++;
    }

    if (digit == 1) cout << n << '\n';
    if (digit == 2) cout << 9 << '\n';
    if (digit == 3) cout << 9 + n - 99 << '\n';
    if (digit == 4) cout << 9 + 900 << '\n';
    if (digit == 5) cout << 9 + 900 + n - 9999 << '\n';
    if (digit == 6) cout << 9 + 900 + 90000 << '\n';
    return 0;
}

Measured memory_bytes: 256
#include <math.h>

#include <algorithm>
#include <array>
#include <bitset>
#include <iomanip>
#include <iostream>
#include <queue>
#include <sstream>
#include <vector>

using namespace std;
using Graph = vector<vector<int>>;

typedef pair<int, int> P;
using ll = long long;
const int INF = 1e8;

int main() {
  string S_, T;
  cin >> S_;
  cin >> T;
  vector<int> T_start_idx;
  for (int i = 0; i < S_.size() - T.size() + 1; i++) {
    bool T_flag = true;
    if (S_[i] == T[0] || S_[i] == '?') {
      for (int j = 1; j < T.size(); j++) {
        if (S_[i + j] != '?' && S_[i + j] != T[j]) {
          T_flag = false;
          break;
        }
      }
    } else {
      continue;
    }
    if (T_flag) {
      T_start_idx.push_back(i);
    }
  }

  if (T_start_idx.size() == 0) {
    cout << "UNRESTORABLE" << endl;
    return 0;
  }
  string S_a = S_;
  for (int i = 0; i < S_.size(); i++) {
    if (S_a[i] == '?') {
      S_a[i] = 'a';
    }
  }
  vector<string> v_S;
  for (int i = 0; i < T_start_idx.size(); i++) {
    string S_i = S_a;
    for (int j = 0; j < T.size(); j++) {
      S_i[T_start_idx[i] + j] = T[j];
    }
    v_S.push_back(S_i);
  }
  sort(v_S.begin(), v_S.end());
  cout << v_S[0] << endl;

  return 0;
}


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

struct Node{
  int k;
  Node *r, *l, *p;
};

Node *T;
Node *NIL;

void insert(int key){

  Node *x = T;
  Node *y = NIL;
  Node *z;
  z = new Node;
  z->k = key;
  z->l = z->r = NIL;

  while(x != NIL){
    y = x;
    if(z->k > x->k){
      x = x->r;
    }else if(z->k < x->k){
      x = x->l;
    }

  }
    z->p = y;

    if(y == NIL){
      T = z;
    }else if(z->k < y->k){
      y->l = z;
    }else if(z->k > y->k){
      y->r = z;
    }
}

void in_print(Node *r){
  if(r == NIL) return;
  in_print(r->l);
  cout << " " << r->k;
  in_print(r->r);
}

void pre_print(Node *r){
  if(r == NIL) return;
  cout << " " << r->k;
  pre_print(r->l);
  pre_print(r->r);
}


int main(){

  int n;
  set<int> s;
  cin >> n;

  for(int i = 0; i < n; i++){
    string str;
    int k;
    cin >> str;

    if(str == "insert"){
      cin >> k;
      s.insert(k);
      insert(k);
    }else if(str == "print"){
      in_print(T);
      cout << endl;
      pre_print(T);
      cout << endl;
    }else if(str == "find"){
      cin >> k;
      set<int>::iterator iti = s.find(k);
      if(iti == s.end()) cout << "no" << endl;
      else cout << "yes" << endl;
    }
  }



}

Measured memory_bytes: 38716
#include<iostream>
#include<string>
using namespace std;
int main(){
	int a,b;
	cin>>a>>b;
	if(a<b){
		cout<<"a"<<" < "<<"b"<<endl;
	}
	if(a>b){
		cout<<"a"<<" > "<<"b"<<endl;
	}
	if(a==b){
		cout<<"a"<<" == "<<"b"<<endl;
	}
}


Measured memory_bytes: 3100
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a % b)

import math
import decimal

ctx = decimal.Context(prec=1, rounding=decimal.ROUND_CEILING)

for i in range(int(input())):
    a, b, c, d = map(int, input().split())

    if a < b:
        print('No')
        continue

    if b > d:
        print('No')
        continue

    if c >= b:
        print('Yes')
        continue

    g = gcd(b, d)
    r = a % g
    # FYI: https://stackoverflow.com/questions/2795946/getting-ceil-of-decimal-in-python
    _max = (int(((decimal.Decimal(b, context=ctx) - decimal.Decimal(r, context=ctx)) / decimal.Decimal(g, context=ctx)).to_integral_exact(context=ctx)) * g) + r - g

    # math.ceilは精度不足でエラーになる: https://cocoinit23.com/math-floor-ceil-error/
    #_max = ((math.ceil((b - r) / g)) * g) + r - g

    # OK: (a + b - 1) // b: https://nariagari-igakusei.com/cpp-division-round-up/
    #_max = ((b - r + g - 1)//g) * g + r - g
    if c < _max:
        print('No')
    else:
        print('Yes')


Measured memory_bytes: 79568