akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>

using namespace std;

int main()
{
    int N;
    string instr;

    int J[2]={0,0},O[2]={0,0},I[2]={0,0},JO[2]={0,0},JI[2]={0,0},OI[2]={0,0},JOI[2]={0,0};

    cin >> N >> instr;

    switch(instr[0]) {
    case 'J' :
        J[0]=1;
        JO[0]=1;
        JI[0]=1;
        break;
    case 'O' :
        JO[0]=1;
        break;
    case 'I' :
        JI[0]=1;
        break;
    }
    JOI[0]=1;


    for(int i=1; i<N; ++i) {
        switch(instr[i]) {
        case 'J' :
            J[i%2]=J[(i-1)%2]+JO[(i-1)%2]+JI[(i-1)%2]+JOI[(i-1)%2];
            O[i%2]=0;
            I[i%2]=0;
            JO[i%2]=J[(i-1)%2]+O[(i-1)%2]+JO[(i-1)%2]+JI[(i-1)%2]+OI[(i-1)%2]+JOI[(i-1)%2];
            JI[i%2]=J[(i-1)%2]+I[(i-1)%2]+JI[(i-1)%2]+JO[(i-1)%2]+OI[(i-1)%2]+JOI[(i-1)%2];
            OI[i%2]=0;
            JOI[i%2]=J[(i-1)%2]+O[(i-1)%2]+I[(i-1)%2]+JO[(i-1)%2]+JI[(i-1)%2]+OI[(i-1)%2]+JOI[(i-1)%2];
            break;
        case 'O' :
            J[i%2]=0;
            O[i%2]=O[(i-1)%2]+JO[(i-1)%2]+OI[(i-1)%2]+JOI[(i-1)%2];
            I[i%2]=0;
            JO[i%2]=J[(i-1)%2]+O[(i-1)%2]+JO[(i-1)%2]+JI[(i-1)%2]+OI[(i-1)%2]+JOI[(i-1)%2];
            JI[i%2]=0;
            OI[i%2]=O[(i-1)%2]+I[(i-1)%2]+JO[(i-1)%2]+JI[(i-1)%2]+OI[(i-1)%2]+JOI[(i-1)%2];
            JOI[i%2]=J[(i-1)%2]+O[(i-1)%2]+I[(i-1)%2]+JO[(i-1)%2]+JI[(i-1)%2]+OI[(i-1)%2]+JOI[(i-1)%2];
            break;
        case 'I' :
            J[i%2]=0;
            O[i%2]=0;
            I[i%2]=I[(i-1)%2]+JI[(i-1)%2]+OI[(i-1)%2]+JOI[(i-1)%2];
            JO[i%2]=0;
            JI[i%2]=J[(i-1)%2]+I[(i-1)%2]+JO[(i-1)%2]+JI[(i-1)%2]+OI[(i-1)%2]+JOI[(i-1)%2];
            OI[i%2]=O[(i-1)%2]+I[(i-1)%2]+JO[(i-1)%2]+JI[(i-1)%2]+OI[(i-1)%2]+JOI[(i-1)%2];
            JOI[i%2]=J[(i-1)%2]+O[(i-1)%2]+I[(i-1)%2]+JO[(i-1)%2]+JI[(i-1)%2]+OI[(i-1)%2]+JOI[(i-1)%2];
            break;
        }
            J[i%2]%=10007;
            O[i%2]%=10007;
            I[i%2]%=10007;
            JO[i%2]%=10007;
            JI[i%2]%=10007;
            OI[i%2]%=10007;
            JOI[i%2]%=10007;

    }

    int i=N-1;

    cout << (J[i%2]+O[i%2]+I[i%2]+JO[i%2]+JI[i%2]+OI[i%2]+JOI[i%2])%10007 << endl;

    return 0;
}

Measured memory_bytes: 3148
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
ll ans = 0;

int main()
{
ll m ;
cin >> m ;
vector<ll> d(m);
vector<ll> c(m);
rep(i, m){
  cin >> d[i] >> c[i];
}

ll sum=0,keta=0;
rep(i,m){
  sum+=d[i]*c[i];
  keta+=c[i];
}
ans+=keta-1;
ans+=(sum-1)/9;
cout << ans << endl;
return 0;
}

Measured memory_bytes: 3328
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

#define rep(i, n) for(int i=0;i<n;i++)

typedef int long long ll;
using namespace std;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;
static const int MAX = 100;
static const int INFint = (1 << 23);
static const ll INF = (ll)1e15;

int main() {
    ll n;
    cin>>n;
   vector<ll> a(n);
   rep(i,n){cin>>a[i];}
   vector<ll> rui;
   ll pre=0;
   rep(i,n){
       rui.push_back(pre+a[i]);
       pre+=a[i];
   }
  // rep(i,n)cout<<rui[i]<<endl;

   ll ans=MOD;
   ll l=0,r=2;
   for(ll k=1;k<n-2;k++) {
       while (l+1 < k && (abs((rui[k] - rui[l]) - (rui[l])) >abs((rui[k] - rui[l + 1]) - (rui[l + 1]))))l++;
       while (r+1 < n-1 && (abs((rui[n-1] - rui[r]) - (rui[r] - rui[k])) >abs((rui[n-1] - rui[r + 1])-(rui[r + 1] - rui[k]))))r++;

       ll mi = 1e18;ll ma = -1e18;
       ll tmp = rui[k] - rui[l];
       mi = min(mi, tmp);
       ma = max(ma, tmp);
       tmp = rui[l];
       mi = min(mi, tmp);
       ma = max(ma, tmp);
       tmp = rui[n-1] - rui[r];
       mi = min(mi, tmp);
       ma = max(ma, tmp);
       tmp = rui[r] - rui[k];
       mi = min(mi, tmp);
       ma = max(ma, tmp);
       ans = min(ans, ma - mi);
      


   }


   cout<<ans<<endl;




    return 0;
}


Measured memory_bytes: 3956
import java.util.Scanner;

public class Main 
{
	public static void main(String arg[])
	{
		Scanner scan = new Scanner(System.in);
		while(scan.hasNext())
		{
			int a=scan.nextInt();
			int b=scan.nextInt();
			int sum = a+b;

			String str = String.valueOf(sum);
			System.out.println(str.length());
		}
	}
}

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


int n, W;
int weight[110], value[110];

int dp[110][10010];

int main() {
	cin >> n >> W;
	rep(i, n) cin >> value[i] >> weight[i];

	// dp shokika
	for (int w = 0; w <= W; w++) dp[0][w] = 0;

	// dp loop
	rep(i, n) {
		for (int w = 0; w <= W; w++) {
			if (w >= weight[i]) dp[i+1][w] = max(dp[i][w-weight[i]]+value[i], dp[i][w]);
			else dp[i+1][w] = dp[i][w]; 
		}
	}
	cout << dp[n][W] << endl;
	return 0;
}


Measured memory_bytes: 7044
import java.util.*;
public class Main {
 public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	int K=sc.nextInt();
	int X=sc.nextInt();

	System.out.print(X-K+1);
	if(K>1){
	for(int i=X-K+2;i<X+K;i++){
	System.out.print(" "+i);
	}
	}
	System.out.println("");
 }
}

Measured memory_bytes: 22100
import numpy as np

def resolve():
    import sys
    input = sys.stdin.readline
    xn = [int(x) for x in input().rstrip().split()]
    x = xn[0]
    n = xn[1]
	
    if n == 0:
      print(x)
      exit()
    
    p = [int(x) for x in input().rstrip().split()]
    num_list = [i for i in range(0, 102) if not i in p]

    idx = np.abs(np.asarray(num_list) - x).argmin()
    print(num_list[idx])



# x = list(map(int, input().split()))

if __name__ == "__main__":
    resolve()


Measured memory_bytes: 27212
#include <stdio.h>
int main()
{
  int x,i,j,key,A[100],k;
  scanf("%d",&x);
  for(i=0;i<x;i++)
      scanf("%d",&A[i]);
  
  for(i=0;i<x;i++)
    {
      key = A[i];
      j = i-1;
      while(j>=0 && A[j]>key)
	    {   
	        A[j+1] = A[j];
	        j = j-1;
	    }
      A[j+1] = key;
      for(k = 0; k < x; k++)
        {
            printf("%d",A[k]);
            if(k < x-1)
            {
                printf(" ");
            }
        }
      printf("\n");
    }
  return 0;
}


Measured memory_bytes: 2124
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10

#solve
def solve():
    s = S()
    ans = 0
    w = 0
    for i, si in enumerate(s):
        if si == "W":
            ans += i-w
            w += 1
    print(ans)

    return


#main
if __name__ == '__main__':
    solve()


Measured memory_bytes: 62960
#define _GLIBCXX_DEBUG

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

constexpr ll INF = 1e16;

#define rep(i, N) for(ll i=0; i<N; ++i)

ll max(ll a, ll b) {return a < b ? b : a; }
ll min(ll a, ll b) {return a > b ? b : a; }
double maxf(double a, double b) { return a < b ? b : a; }

vector<int> H(200000);

int main() {
  long long n, k, ans = 0;
  cin>>n>>k;
  for(int i=0; i<n; i++){
    cin >> H[i];
  }
  sort(H.begin(), H.end(),  greater<int>());

  for(int i = k; i<n; i++){
    ans += H[i];
  }

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>

int binarySearch(int, int[], int);

int main(){
  int n,i,q,key,count=0;
  int S[100001];

  scanf("%d",&n);
  for(i = 0; i < n; i++) scanf("%d",&S[i]);
  scanf("%d",&q);
  for(i = 0; i < q; i++){
    scanf("%d",&key);
    if(binarySearch(n, S, key) != -1) count++;
  }
  printf("%d\n",count);
  
  return 0;
}

int binarySearch(int n, int A[], int key){
  int left = 0;
  int right = n;
  int mid;

  while(left < right){
    mid = (left + right) / 2;
    if(A[mid] == key) return mid;
    else if(key < A[mid]) right = mid;
    else left = mid + 1;
  }
  return -1;
}



Measured memory_bytes: 2104
/*********************************************************************************
*   Falling down is an accident, Staying down is a choice.                       *
**********************************************************************************/
#include <bits/stdc++.h>
using namespace std;
#define FastIO ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)
#define ll long long int
#define pb push_back
#define fi first
#define se second
const ll inf = 1e9+7; 
const ll modc = 998244353;
void solve();int main(){FastIO;solve();return 0;}
/*********************************************************************************/
void solve()
{
    int x,y;cin>>x>>y;
    if(y&1)
    {
        cout<<"No"<<endl;
        return;
    }
    for(int i=0;i<=x;i++)
    {
        //i is crane
        int c = i;
        int t = x-i;
        if(2*c+4*t==y)
        {
            cout<<"Yes"<<endl;
            return;
        }
    }
    cout<<"No"<<endl;
    return;
}

Measured memory_bytes: 3640
package main

import (
        "bufio"
        "fmt"
        "math"
        "os"
        "strconv"
        "strings"
)

////////////////////////////////////////
///        templates                 ///
////////////////////////////////////////

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
        sc.Scan()
        return sc.Text()
}

var rdr = bufio.NewReaderSize(os.Stdin, 1000000)

func readBigLine() string {
        buf := make([]byte, 0, 1000000)
        for {
                l, p, e := rdr.ReadLine()
                if e != nil {
                        panic(e)
                }
                buf = append(buf, l...)
                if !p {
                        break
                }
        }
        return string(buf)
}

func strSprit(str string) []string {
        cols := strings.Split(str, " ")
        return cols
}

func parseInt(str string) int {
        n, _ := strconv.Atoi(str)
        return n
}

func intSprit(str string) []int {
        strs := strSprit(str)
        cols := make([]int, len(strs))
        for i, v := range strs {
                cols[i] = parseInt(v)
        }
        return cols
}

func bitCount(n uint) int {

        x := uint64(n)

        const m = 1<<64 - 1
        const m0 = 0x5555555555555555
        const m1 = 0x3333333333333333
        const m2 = 0x0f0f0f0f0f0f0f0f

        x = x>>1&(m0&m) + x&(m0&m)
        x = x>>2&(m1&m) + x&(m1&m)
        x = (x>>4 + x) & (m2 & m)
        x += x >> 8
        x += x >> 16
        x += x >> 32

        return int(x) & (1<<7 - 1)
}

func bitExist(n, i int) bool {
        return ((n >> uint(i)) & 1) == 1
}

////////////////////////////////////////
///        end templates             ///
////////////////////////////////////////
func abs(a, b int) int {
        return int(math.Abs(float64(a - b)))
}

func chmin(dp []int, idx, n int) {
        if dp[idx] > n {
                dp[idx] = n
        }
}
func main() {
        line := readBigLine()
        N := parseInt(line)

        l := readBigLine()
        h := intSprit(l)

        INF := 1 << 30

        dp := make([]int, N+1000)
        for i := 0; i < N+1000; i++ {
                dp[i] = INF
        }
        dp[0] = 0

        for i := 0; i < N; i++ {
                if N > i+1 {
                        chmin(dp, i+1, dp[i]+abs(h[i], h[i+1]))
                }
                if N > i+2 {
                        chmin(dp, i+2, dp[i]+abs(h[i], h[i+2]))
                }
        }
        fmt.Println(dp[N-1])
}

Measured memory_bytes: 6016
import java.util.Scanner;

public class Main {
    
    static Node nil;

    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        init();
        int n = Integer.parseInt(sc.next());
        for(int i = 0; i < n; i++){
            String command = sc.next();
            switch (command) {
                case "insert":
                    insert(Integer.parseInt(sc.next()));
                    break;
                case "delete":
                    deleteKey(Integer.parseInt(sc.next()));
                    break;
                case "deleteFirst":
                    deleteFirst();
                    break;
                case "deleteLast":
                    deleteLast();
                    break;
            }
        }
        
        StringBuilder sb = new StringBuilder();
        Node cur = nil.next;
        while(cur != nil){
            sb.append(cur.key).append(" ");
            cur = cur.next;
        }
        if(sb.length() != 0) sb.deleteCharAt(sb.length()-1);
        
        System.out.println(sb);
    }
    
    static void init(){
        nil = new Node();
        nil.next = nil;
        nil.prev = nil;
    }
    
    static void insert(int key){
        Node x = new Node();
        x.key = key;
        x.next = nil.next;
        nil.next.prev = x;
        nil.next = x;
        x.prev = nil;
    }
    
    static Node listSearch(int key){
        Node cur = nil.next;
        while(cur != nil && cur.key != key){
            cur = cur.next;
        }
        return cur;
    }
    
    static void deleteNode(Node t){
        if(t == nil) return;
        t.prev.next = t.next;
        t.next.prev = t.prev;
    }
    
    static void deleteFirst(){
        deleteNode(nil.next);
    }
    
    static void deleteLast(){
        deleteNode(nil.prev);
    }
    
    static void deleteKey(int key){
        deleteNode(listSearch(key));
    }
    
    static class Node {
        int key;
        Node prev;
        Node next;
    }
}


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

using namespace std;

int main() {
  int n, x;
  cin >> n >> x;
  vector<int> l(n + 1);
  l[0] = 0;
  for (int i = 1; i <= n; ++i) {
    int tmp;
    cin >> tmp;
    l[i] = l[i - 1] + tmp;
  }

  int ans = 0;
  for (int i = 0; i <= n; ++i) {
    if (l[i] > x) break;
    else ans++;
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<queue>
#include<algorithm>
using namespace std;
int ans;
struct edges
{
	int to,next;
}edge[333];
int first1[55],first2[55],first3[55],now;
int d[55],d1[55];
void adde(int *first,int a,int b)
{
	now++;
	edge[now].to=b;
	edge[now].next=first[a];
	first[a]=now;
}
bool vis[55];
int fa1[55],fa2[55];
bool mk[55];
queue <int> q;
void work1(int p)
{
	vis[p]=true;
	for(int e=first1[p];e;e=edge[e].next)
		if(!vis[edge[e].to])
		{
			fa1[edge[e].to]=p;
			work1(edge[e].to);
		}
}
void work2(int p)
{
	vis[p]=true;
	for(int e=first2[p];e;e=edge[e].next)
		if(!vis[edge[e].to])
		{
			fa2[edge[e].to]=p;
			work2(edge[e].to);
		}
}
int main()
{
	int T,n,x,y,h,cnt,cnt1,p;
	bool jud;
	scanf("%d",&T);
	while(T--)
	{
		ans=214748;
		now=0;
		memset(first1,0,sizeof(first1));
		memset(first2,0,sizeof(first2));
		scanf("%d",&n);
		memset(d,0,sizeof(d));
		for(int i=1;i<n;i++)
		{
			scanf("%d%d",&x,&y);
			adde(first1,x,y);
			adde(first1,y,x);
			d[x]++;
			d[y]++;
		}
		for(int i=1;i<n;i++)
		{
			scanf("%d%d",&x,&y);
			adde(first2,x,y);
			adde(first2,y,x);
		}
		h=now;
		memset(vis,0,sizeof(vis));
		work1(1);
		memset(vis,0,sizeof(vis));
		work2(1);
		jud=true;
		for(int i=2;i<=n;i++)
			if(fa1[i]!=fa2[i])
				jud=false;
		if(jud)
		{
			printf("0\n");
			continue;
		}
		mk[0]=false;
		for(int i=1;i<=n;i++)
			if(d[i]==1)
			{
				memset(vis,0,sizeof(vis));
				work2(i);
				fa1[i]=fa2[i]=0;
				for(int j=1;j<=n;j++)
					if(i!=j)
					{
						memset(vis,0,sizeof(vis));
						vis[i]=true;
						work1(j);
						fa1[j]=i;
						cnt=0;
						for(int k=1;k<=n;k++)
							if(fa1[k]!=fa2[k])
							{
								mk[k]=true;
								cnt++;
							}
							else
								mk[k]=false;
						jud=false;
						for(int k=1;k<=n;k++)
							if((!mk[k])&&mk[fa1[k]])
								jud=true;
						if(jud)
							continue;
						memset(first3,0,sizeof(first3));
						now=h;
						memset(d1,0,sizeof(d1));
						for(int k=1;k<=n;k++)
							if(mk[k]&&mk[fa1[k]])
							{
								adde(first3,k,fa1[k]);
								d1[fa1[k]]++;
							}
						for(int k=1;k<=n;k++)
							if(mk[k]&&mk[fa2[k]])
							{
								adde(first3,fa2[k],k);
								d1[k]++;
							}
						cnt1=0;
						for(int k=1;k<=n;k++)
							if(mk[k]&&d1[k]==0)
								q.push(k);
						while(!q.empty())
						{
							p=q.front();
							cnt1++;
							q.pop();
							for(int e=first3[p];e;e=edge[e].next)
							{
								d1[edge[e].to]--;
								if(d1[edge[e].to]==0)
									q.push(edge[e].to);
							}
						}
						if(cnt1==cnt)
							ans=min(ans,cnt+1);
					}
			}
		if(ans==214748)
			ans=-1;
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int A[100000];

int main(){
  int n,i,j,p,q,r,x;

  scanf("%d",&n);
  for(i = 0;i < n;i++){
    scanf("%d",&A[i]);
  }

  r = n - 1;
  x = A[r];
  p = 0;
  i = p - 1;

  for(j = p;j < r;j++){
    if(A[j] <= x){
      i = i + 1;
      q = A[j];
      A[j] = A[i];
      A[i] = q;
    }
  }
  q = A[r];
  A[r] = A[i+1];
  A[i+1] = q;
  x = i + 1;

  for(i = 0;;){
    if(i == x){
      printf("[%d]",A[i]);
    }
    else{
      printf("%d",A[i]);
    }
    i++;
    if(i >= n)break;
    printf(" ");
  }
  printf("\n");

  return 0;
}

Measured memory_bytes: 992
#include<stdio.h>
int main(void)
{
	unsigned long int a, b, c;
	unsigned int i;
	unsigned long int A[200000];

	scanf("%ld", &a);

	for (i = 0; i < (a - 1); i++) {
		A[i] = 0;
		scanf("%ld", &b);
		A[b - 1]++;
	}
	A[i] = 0;

	for (i = 0; i < a; i++) {
		printf("%ld\n", A[i]);
	}


	return 0;
}

Measured memory_bytes: 3292
def main():
	N, K = map(int, input().split())
	h = list(map(int, input().split()))

	dp=[0]*N
 
	for i in range(1,N):
		dp[i] = min(
			dp[g] + abs(h[i] - h[g]) for g in range(max(i-K,0), i)
		)
	print(dp[N-1])
main()

Measured memory_bytes: 13980
from collections import defaultdict

n = int(input())
a = tuple(map(int, input().split()))

c = [0]
for a_ in a:
    c.append(c[-1] + a_)

d = defaultdict(int)
d[0] = 1

ans = 0
for i in range(n):
    v = c[i + 1]
    ans += d[v]
    d[v] += 1

print(ans)


Measured memory_bytes: 41472
#include <iostream>
#include <set>
#include <stdio.h>

using namespace std;

int main()
{
  
  int h,n;
  cin >> h;
  cin >> n;
  
  long h1[20010];
  int i;
  for(i=1;i<20010;i++){
    h1[i] = 100000000;
  }
  h1[0] = 0;
  
  for(i=0;i<n;i++){
    int a,b;
    cin >> a; cin >> b;
    int j;
    for(j=a;j<h+a;j++){
      if( h1[j] > h1[j-a] + b ){
        h1[j] = h1[j-a] + b;
      }
    }
  }
  
  int res = 100000000;
  for(i=h;i<h+10000;i++){
    if( h1[i] < res ){
      res = h1[i];
    }
  }
  
  cout << res << "\n";
  return 0;
  
}



Measured memory_bytes: 384
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<numeric>
#include<map>
using namespace std;

int main(){
    int N,Q,l[100010],r[100010];
    string S;
    vector<int> v;
    cin>>N>>Q>>S;
    for(int i=0;i<N-1;++i){
        if(S[i]=='A'&&S[i+1]=='C')
            v.push_back(i);
    }

    for(int q=0;q<Q;++q){
        cin>>l[q]>>r[q];
        auto itr1=lower_bound(v.begin(),v.end(),l[q]-1);
        auto itr2=lower_bound(v.begin(),v.end(),r[q]-1);
        cout<<itr2-itr1<<endl;
    }

    return 0;
}

Measured memory_bytes: 2044
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include<algorithm> 
#include <iomanip>
#include <math.h>

#define db double
#define vi vector<int>
#define pb push_back
#define fi first
#define se second
#define ll long long
#define ld long double
#define maxn 5005
#define mod 998244353
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vll vector<ll>
#define vpi vector<pii>
#define vpll vector<pll>
#define vv(z,a,b) vector<vector<int>>z(a,vector<int>(b))
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(c) begin(c),end(c)
using namespace std;

const int M=1000005;
int main(){
int n;cin>>n;
vi a(n);
rep(g,n)cin>>a.at(g);
vi cnt(M);
for(int x:a){
    if(cnt.at(x)!=0){
        cnt.at(x)=2;
        continue;
    }
    for(int i=x;i<M;i+=x)cnt.at(i)++;
}
int ans=0;
for(int x:a){
    if(cnt.at(x)==1)ans++;
}
cout<<ans<<endl;
}

Measured memory_bytes: 7956
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <cmath> 
using namespace std;


typedef long long LL;
int main(){
	LL a , b , c, d;
	cin >> a >> b >> c >> d;
	LL sum1 , sum2;
	sum1 = a * b;
	sum2 = c * d;
	LL ans = max(sum1 , sum2);
	cout << ans << endl;
	return 0;
	}

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

using namespace std;

using int64 = long long;

struct Edge {
  int from, to;
};

vector<vector<Edge>> ReadUndirectedGraph(
    int n, int m, bool is_one_indexed=false) {
  vector<vector<Edge>> graph(n);
  for (int i = 0; i < m; i++) {
    int v1, v2;
    cin >> v1 >> v2;
    if (is_one_indexed) {
      v1--;
      v2--;
    }
    graph[v1].push_back(Edge({v1, v2}));
    graph[v2].push_back(Edge({v2, v1}));
  }
  return graph;
}

// For modular arithmetic when a modular is specified per input case.
// Verified: ABC129F
struct ModInt {
 private:
  static int64 M;
  int64 x;
 public:
  static void SetMod(int64 mod) {
    M = mod;
  }
  ModInt(int64 input_x) : x(input_x % M) {}
  ModInt() : x(0) {}
  int64 Value() { return x; }
  inline ModInt operator+(ModInt o) {
    ModInt r(*this); r += o; return r;
  }
  inline ModInt operator-(ModInt o) {
    ModInt r(*this); r -= o; return r;
  }
  inline ModInt operator* (ModInt o) {
    ModInt r(*this); r *= o; return r;
  }
  inline void operator+= (ModInt o) { x = (x + o.x) % M; }
  inline void operator-= (ModInt o) { x = (x + M - o.x) % M; }
  inline void operator*= (ModInt o) { x = (x * o.x) % M; }
};
int64 ModInt::M = 1;  // Do not forget to add this line.

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

  int n;
  int64 mod;
  cin >> n >> mod;
  ModInt::SetMod(mod);

  vector<vector<Edge>> graph = ReadUndirectedGraph(n, n - 1, true);

  vector<ModInt> dp1(n);
  vector<vector<ModInt>> v_to_cpl(n);  // Cumulative product left
  vector<vector<ModInt>> v_to_cpr(n);  // Cumulative product right

  function<void(int, int)> dfs1 = [&](int v, int parent) {
    vector<ModInt> ps;
    for (auto e : graph[v]) {
      if (e.to == parent) continue;
      dfs1(e.to, v);
      ps.push_back(dp1[e.to] + 1);
    }

    if (ps.size() == 0) {
      dp1[v] = 1;
      return;
    }

    int d = ps.size();
    auto& cpl = v_to_cpl[v];
    auto& cpr = v_to_cpr[v];
    cpl.resize(d);
    cpr.resize(d);
    cpl[0] = ps[0];
    for (int i = 1; i < d; i++) {
      cpl[i] = cpl[i - 1] * ps[i];
    }
    cpr[d - 1] = ps[d - 1];
    for (int i = d - 2; i >= 0; i--) {
      cpr[i] = cpr[i + 1] * ps[i];
    }
    dp1[v] = cpl[d - 1];
  };
  dfs1(0, -1);

  vector<ModInt> dp2(n);
  function<void(int, int, ModInt)> dfs2 =
      [&](int v, int parent, ModInt factor) {
    // cout << "v: " << v << " factor: " << factor.Value() << endl;
    
    dp2[v] = dp1[v] * factor;

    auto& cpl = v_to_cpl[v];
    auto& cpr = v_to_cpr[v];
    
    int edge_id = 0;
    for (auto e : graph[v]) {
      if (e.to == parent) continue;
      ModInt new_factor = factor;
      if (edge_id - 1 >= 0) new_factor *= cpl[edge_id - 1];
      if (edge_id + 1 < cpr.size()) new_factor *= cpr[edge_id + 1];
      new_factor += 1;
      dfs2(e.to, v, new_factor);
      edge_id++;
    }
  };
  dfs2(0, -1, 1);

  for (int i = 0; i < n; i++) {
    cout << dp2[i].Value() << "\n";
  }
}


Measured memory_bytes: 27520
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;
import std.container;

enum MAX = 1_000_100;
ulong MOD = 1_000_000_007;
ulong INF = 1_000_000_000_000;
alias sread = () => readln.chomp();
alias Pair = Tuple!(long, "cost", long, "num");
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);

void main()
{
    long n, m;
    scan(n, m);
    auto a = aryread();
    PQueue!long pq;
    foreach (e; a)
        pq.insert(e);

    while (m > 0)
    {
        auto maxcost = pq.front();
        pq.removeFront();
        pq.insert(maxcost / 2);
        m--;
    }
    pq.sum.writeln();
}

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}


Measured memory_bytes: 5684
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;

public static class P
{
    public static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        var a = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var res = n - (a.GroupBy(x => x).Select(x => x.Count() - 1).Sum() + 1) / 2 * 2;
        Console.WriteLine(res);
    }
}


Measured memory_bytes: 30860
#include <bits/stdc++.h>
typedef long long       ll;
#define PI                acos(-1)
#define pb                push_back
#define mp                make_pair
#define mt                make_tuple
#define all(a)            (a).begin(), (a).end()
#define clr(a,h)          memset(a, (h), sizeof(a))
#define F first
#define S second
#define fore(i,b,e)		  for(int i=(int)b;i<(int)e;++i)
#define forr(i,b,e)		  for(int i=(int)b;i<(int)e;++i)
#define deb(x)			  cerr << "# " << (#x) << " = " << (x) << endl;
#define sz(x)             (int)x.size()
int faster_in(){int r=0,c;for(c=getchar();c<=32;c=getchar());if(c=='-') return -faster_in();for(;c>32;r=(r<<1)+(r<<3)+c-'0',c=getchar());return r;}

using namespace std;

typedef pair<int, int>  ii;
typedef vector<int>     vi;
typedef vector<ii>      vii;
typedef vector<ll>      vll;
const int INF = 1234567890;

int main()
{
    std::ios::sync_with_stdio(false); cin.tie(0);
    //freopen("","r",stdin);
    //freopen("","w",stdout);
    int k;
    cin >> k;
    while (k--) {
        cout << "ACL";
    }
    cout << '\n';
    return 0;
}
// Dinosaurs are cool!

Measured memory_bytes: 3596
import java.io.PrintWriter;
import java.util.Scanner;

public class Main{
	static final int MOD = 1000000007;
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		//入力
		String a = sc.next();
		String b = sc.next();
		sc.close();

		//処理
		String ans;
		if(a.equals("H")){
			if(b.equals("H")){
				ans = "H";
			}else{
				ans = "D";
			}
		}else{
			if(b.equals("H")){
				ans = "D";
			}else{
				ans = "H";
			}
		}

		//出力	
		out.println(ans);
		out.flush();
	}
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
#define rep(i, n) for (int i=0;i<(n);i++)
using namespace std;
#define vecout(V) for(int i=0;i<V.size();i++) {cout<<V[i]<<endl;}
typedef long long ll;


int main(void){
    int n;
    cin>>n;
    vector <int> a(n+1);
    rep(i, n){
        cin>>a[i+1];
    }
    vector <int> b(n+1);
    for (int i=n;i>=1;i--){
        int sum=0;
        for (int j=2*i;j<=n;j+=i){
            sum^=b[j];
        }
        b[i]=sum^a[i];
    }

    vector <int> ans;

    for(int i=1;i<=n;i++){
        if(b[i]){
            ans.push_back(i);
        }
    }
    cout<<ans.size()<<endl;
    rep(i, ans.size()){
        printf("%d%c", ans[i], i+1==ans.size()?'\n':' ');
    }

}

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;++i){
		string s,ss;
		cin>>s;
		int p=0;
		for(int j=0;j<s.size();++j){
			if(s[j]=='>')++p;
			else if(s[j]=='<')--p;
			else if('a'<=s[j]&&s[j]<='z'){
					if(p==-1){
						ss=s[j]+ss;
						p=0;
					}else if(p==ss.size())ss=ss+s[j];
			}
		}
		cout<<ss<<"\n";
	}
	return 0;
}

Measured memory_bytes: 0
#include <cstdio>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>


using namespace std;

int main()
{
	int n, a, b, Q, k, x, y;
	long long int c;
	map<int, long long int> vm[100001];

	scanf("%d", &n);
	for(int i=0; i<n-1; i++){
		scanf("%d %d %lld", &a, &b, &c);
		vm[a][b]=c;
		vm[b][a]=c;
	}
	scanf("%d %d", &Q, &k);
	
	long long int d[100001];
	for(int i=1; i<=n; i++){
		if(i==k){
			d[k]=0;
		}else{
			d[i]=-1;
		}
	}
	vector<int> v;
	v.push_back(k);
	while(!v.empty()){
		int v1=v.back();
		v.pop_back();
		for(auto itr=vm[v1].begin(); itr!=vm[v1].end(); itr++){
			int v2=itr->first;
			if(d[v2]==-1){
				d[v2]=d[v1]+itr->second;
				v.push_back(v2);
			}
		}
	}

	for(int i=0; i<Q; i++){
		scanf("%d %d", &x, &y);
		printf("%lld\n", d[x]+d[y]);
	}
	
	return 0;
}

Measured memory_bytes: 19832
#include <iostream>
#include <string>
#include <set>
#include <algorithm>

#define SCP(str) str.begin(),str.end()

using namespace std;

int main(void){
	int n;
	string str,sub1,sub2;

	cin >> n;

	for(int i=0;i<n;i++){
		set<string>	val;
		cin >> str;
		for(int j=1;j<str.length();j++){
			sub2=str.substr(j);
			sub1=str.substr(0,j);

			for(int k=0;k<4;k++){
				val.insert(sub1+sub2);
				val.insert(sub2+sub1);
				reverse(SCP(sub2));
				if(k==1)
					reverse(SCP(sub1));
			}
		}
		cout << val.size() << endl;
	}

	return 0;
}

Measured memory_bytes: 1288
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <functional>
#include <utility>
#include <queue>
#include <vector>
#include <string>
#include <stack>
#define rep(i,n) for(ll i=0;i<n;i++)
using namespace std;
typedef long long int ll;
const ll  MOD = 1000000007;
typedef pair<ll,ll> P;
const ll INF = 100100100100100100;

int N,K;
int a[10000];
bool dp1[5001][5010];
bool dp2[5001][5010];
int rui[5010][5010];
int ans;
int main(){
  cin >> N >> K;
  rep(i,N){
    cin >> a[i];
    if(a[i] > K){
      a[i] = K;
    }
  }
  dp1[0][0] = true;
  dp2[0][0] = true;
  rep(i,K){
    rui[0][i+1] = 1;
  }
  rep(i,N){
    rep(j,K){
      if(dp1[i][j]){
        dp1[i+1][j] = true;
        if(j+a[i] <= K){
          dp1[i+1][j+a[i]] = true;
        }
      }

      if(dp2[i][j]){
        dp2[i+1][j] = true;
        if(j+a[N-i-1] <= K){
          dp2[i+1][j+a[N-i-1]] = true;
        }
      }
      //rui1[i][j] = rui1[i][j-1] + dp1[i+1][j];
      rui[i+1][j+1] = rui[i+1][j] + dp2[i+1][j];
    }
  }
  /*
  rep(i,N+1){
    rep(j,K){
      cerr << dp1[i][j] << " ";
    }
    cerr << endl;
  }
  cerr << endl;
  rep(i,N+1){
    rep(j,K){
      cerr << dp2[i][j] << " ";
    }
    cerr << endl;
  }
  cerr << endl;
  rep(i,N+1){
    rep(j,K){
      cerr << rui[i][j] << " ";
    }
    cerr << endl;
  }
  cerr << endl;
  */
  rep(i,N){
    ll tmp = a[i];
    if(a[i] >= K){
      ans++;
      continue;
    }
    rep(j,K){
      if(dp1[i][j]){
        ll l = K - j - tmp;
        ll r = K - j;
        if(l < 0) l = 0;
        if(rui[N-i-1][r] - rui[N-i-1][l] > 0){
          ans++;
          //cerr << i << endl;
          break;
        }
      }
    }
  }
  cout << N-ans << endl;
}

Measured memory_bytes: 147200
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int N=2010,MOD=998244353;
int C[N*2][N*2],pw[N*2];
int n,K,ans;
int plu(int x,int y){return (1LL*x+y)%MOD;}
int mul(int x,int y){return 1LL*x*y%MOD;}
void prework(int n){
	C[0][0]=1;
	for (int i=1;i<=n;++i){
		C[i][0]=1; C[i][i]=1;
		for (int j=1;j<i;++j)
			C[i][j]=plu(C[i-1][j-1],C[i-1][j]);
	}
	pw[0]=1;
	for (int i=1;i<=n;++i) pw[i]=mul(pw[i-1],2);
}
int f(int x,int y,int z){
	if (y<0) return 0;
	int ret=0;
	for(int q=0;q<=z&&q<=x;++q)
		if (q+y-1<=z+y-1&&q+y-1>=0) 
			ret=plu(ret,mul(C[x][q],mul(pw[q],C[z+y-1][q+y-1])));
	return ret;
}

int main(){
#ifndef ONLINE_JUDGE
	freopen("a.in","r",stdin);
#endif
	int cnt;
	scanf("%d%d",&K,&n);
	prework(n+K);
	for (int i=2;i<=2*K;++i){
		cnt=0;
		for (int j=1;j<=K;++j)
			if (1<=i-j&&i-j<=K) ++cnt;
		if (i&1)
			ans=f(cnt/2,K-cnt,n);
		else{
			ans=f((cnt-1)/2,K-cnt,n);
			ans=plu(ans,f((cnt-1)/2,K-cnt,n-1));
		}
		printf("%d\n",ans);
	}
}

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


def solve(N: int, A: int, B: int):
    print(A * (N // (A+B)) + min(A, N % (A+B)))
    return


# Generated by 1.1.6 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()
    N = int(next(tokens))  # type: int
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(N, A, B)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <algorithm>  
#include <unordered_set>
#include <cmath>

#define ll long long

using namespace std;

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	ll t, n, m, x, y;


	cin >> t;

	if (t >= 30) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	


	return 0;
}

Measured memory_bytes: 3644
//Five Dishes

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end()
struct edge{int to;ll cost;};
const int inf = 2147483647;

int main (){
    int a[5],ans=0,c=inf;
    rep(i,0,5){
        cin>>a[i];
        if(a[i]%10!=0)c=min(c,a[i]%10);
    }
    rep(i,0,5){
        if(a[i]%10!=0)a[i]+=10-a[i]%10;
        ans+=a[i];
    }
    if(c==inf)c=10;
    cout << ans+c-10 << endl;
    return 0;
}

Measured memory_bytes: 256
N ,M = map(int,input().split())
L = []
import collections as col
for _ in range(N):
    l = list(map(int,input().split()))
    tmp = l.pop(0)
    for x in l:
        L.append(x)
c = list(col.Counter(L).items())
cnt = 0
for x in c:
    if x[1] == N:
        cnt += 1

print(cnt)


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

using namespace std;

typedef long long ll;

int t;
ll n;
ll a, b, c, d;

map<ll, ll> mp;
inline ll changeAns(ll x){
    if(mp[x]) return mp[x];
    if(x==0) return 0;
    mp[x] = 1e18;

    ll ret = 1e18;
    if(1e18 / d >= x) ret = d * x;

    if(x%2==0) ret = min(ret, changeAns(x/2) + a);
    else{
        ll tmp1 = (x-1)/2;
        ll tmp2 = tmp1+1;
        ret = min(ret, changeAns(tmp1) + d + (tmp1 ? a : 0));
        ret = min(ret, changeAns(tmp2) + d + a);
    }

    if(x%3==0) ret = min(ret, changeAns(x/3) + b);
    else{
        ll tmp1 = x/3;
        ll tmp2 = tmp1+1;
        ret = min(ret, changeAns(tmp1) + d * (x - 3*tmp1) + (tmp1 ? b : 0));
        ret = min(ret, changeAns(tmp2) + d * (3*tmp2 - x) + b);
    }

    if(x%5==0) ret = min(ret, changeAns(x/5) + c);
    else{
        ll tmp1 = x/5;
        ll tmp2 = tmp1+1;
        ret = min(ret, changeAns(tmp1) + d * (x - 5*tmp1) + (tmp1 ? c : 0));
        ret = min(ret, changeAns(tmp2) + d * (5*tmp2 - x) + c);
    }

    return mp[x] = ret;
}

int main(){
    scanf("%d", &t);
    while(t--){
        scanf("%lld %lld %lld %lld %lld", &n, &a, &b, &c, &d);
        mp.clear();
        printf("%lld\n", changeAns(n));
    }
}


Measured memory_bytes: 4584
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using Pair = pair<int64_t, int64_t>;

// std::cout << std::setprecision(20) << 1.1 << endl;

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

  int64_t N, K;
  cin >> N >> K;
  // const int64_t L = static_cast<int64_t>(T.length());
  vector<int64_t> hist(N + 1, 0);
  for (int64_t i = 0; i < N; ++i) {
    int64_t a;
    cin >> a;
    ++hist[a];
  }
  sort(hist.begin(), hist.end());
  reverse(hist.begin(), hist.end());
  int64_t count = 0;
  for (int64_t i = K; i <= N; ++i) {
    count += hist[i];
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

int n;
double d,x;

int main(){
	cin>>n>>x>>d;
	double t=0;
	while(n){
		double X=(d*5+x*(2*n+2))/(2*n),D=d*(n+2)/n;
		t+=x+d*(n-0.5);
		x=X;d=D;n--;
	}
	cout<<syosu(12)<<t<<endl;
}

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

int main() {
    ll N;
    cin >> N;
    ll ans = 110;
    for(ll i=1;i*i<=N;i++){
        if(N%i==0){
            ll m = max(i, N/i);
            ll d = 0;
            while(m>0){
                d++;
                m = m / 10;
            }
            ans = min(ans, d);
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3628
import fractions

a,b,c,d=[int(x) for x in input().split()]

def count(n):
  r=b//n
  l=a//n
  if a%n!=0:
     l+=1
  return r-l+1

ans=b-a+1-count(c)-count(d)+count(c*d//fractions.gcd(c,d))

print(ans)
#print(b-a+1,count(c),count(d),count(c*d//fractions.gcd(c,d)))


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

using namespace std ;

int main()
{
	ios_base::sync_with_stdio(0) ;
	cin.tie(0) ;
	int n ;
	cin>>n ;
	long long arr[n+1] , sum[n+1] , x[n+1];
	for(int i = 1 ; i <= n ; ++i)
		cin>>arr[i] ;
	sum[0] = x[0] = 0 ;
	for(int i = 1 ; i <= n ; ++i)
		sum[i] = sum[i-1] + arr[i] , x[i] = x[i-1] ^ arr[i] ;
	long long ans = 0ll ;
	for(int i = 1 ; i <= n ; ++i)
	{
		int l = i , r = n ;
		int now =i ;
		while(l <= r)
		{
			int mid = (l + r) >> 1 ;
			long long a = sum[mid] - sum[i-1] ;
			long long b = x[mid] ^ x[i-1] ;
			if(a == b)
				now = mid , l = mid+1 ;
			else
				r = mid-1 ;
		}
		ans = ans + (now-i+1ll) * 1ll ;
	} 
	return cout<<ans<<"\n" , 0 ;
}

Measured memory_bytes: 4992
a = input()
i = 0
for i in range(len(a)):
  if i % 2 == 0 and a[i] == 'L':
    print('No')
    exit(0)
  if i % 2 == 1 and a[i] == 'R':
    print('No')
    exit(0)
  i += 1
print('Yes')

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

using namespace std;

int main(){
    
    priority_queue<long int> pq;
    
    priority_queue<long int> cc;
    
    int X,Y,Z,K;
    cin >> X >> Y >> Z >> K;
    
    vector<long int> A(X);
    vector<long int> B(Y);
    vector<long int> C(Z);
    
    for (int i = 0; i < X; i++) {
        cin >> A[i];
    }
    for (int i = 0; i < Y; i++) {
        cin >> B[i];
    }
    for (int i = 0; i < Z; i++) {
        cin >> C[i];
    }
    
    for (int i = 0; i < X; i++) {
        for (int j = 0; j < Y; j++) {
            pq.push(A[i]+B[j]);
        }
    }
    
    sort(C.begin(), C.end());
    
    int kk = 0;
    
    long int aa = 0;
    long int bb = 0;
    
    while (kk != K) {
        
        if (pq.empty()) {
            aa = -1;
        }else{
            aa = pq.top() + C[Z-1];
        }
        
        if (cc.empty()) {
            bb = -1;
        }else{
            bb = cc.top();
        }
        
        if (aa > bb) {
            cout << aa << endl;
            kk += 1;
            
            pq.pop();
            
            for (int i = 0; i < Z-1; i++) {
                cc.push(aa-C[Z-1]+C[i]);
            }
        }else{
            cout << bb << endl;
            kk += 1;
            
            cc.pop();
            
        }
        
        
    }
    
    
    
}


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

using namespace std;


int calc( vector<int> src, int p, int q ){
	int i, j;

	do {
		for( i=0; src[p-i]==src[p] && p-i>0; i++ );
		for( j=0; src[q+j]==src[q] && q+j<src.size(); j++ );
		if( i+j < 4 ) return p+src.size()-q;
		p -= i; q += j;
	} while( src[p] == src[q] );

	return p+src.size()-q;
}

int main(void)
{
	int n, M, i, tmp, new_val;
	vector<int> chain;

	while( cin >> n, n!=0 ){
		chain.resize(n+1);

		chain[0] = chain[n] = 0;
		for( i=1; i<=n; i++ )
			cin >> chain[i];

		M = 10001;
		for( i=2; i<n; i++ ){
			if( chain[i]!=chain[i-1] ){
				tmp = chain[i];
				chain[i] = chain[i-1];
				new_val = calc( chain, i-1, i );
				if( M > new_val )
					M = new_val;
				chain[i] = tmp;
			}
			if( chain[i]!=chain[i+1] ){
				tmp = chain[i];
				chain[i] = chain[i+1];
				new_val = calc( chain, i, i+1 );
				if( M > new_val )
					M = new_val;
				chain[i] = tmp;
			}
		}

		cout << M << endl;
	}

	return 0;
}

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

using namespace std;

typedef long long ll;

signed main() {
    ll n, m;
    cin >> n >> m;
    map<ll, vector<string>> mp;
    string s;
    ll x;
    set<ll> ss;
    for (ll i = 0; i < m; ++i) {
        cin >> x >> s;
        mp[x].push_back(s);
        ss.insert(x);
    }
    vector<ll> penalty(n), ac(n);
    for (auto i:ss) {
        for (auto j:mp[i]) {
            if (j == "WA")penalty[i - 1]++;
            else {
                ac[i - 1]++;
                break;
            }
        }
    }
    ll pen = 0, ans = 0;
    for (ll i = 0; i < n; i++)if (ac[i])pen += penalty[i], ans++;
    cout << ans << " " << pen;
}

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

using namespace std;

const int N=100010;

int n,cnt,G[N],f[N],du[N];
struct edge{
	int t,nx;
}E[N<<1];

inline void addedge(int x,int y){
	E[++cnt].t=y; E[cnt].nx=G[x]; G[x]=cnt;
	E[++cnt].t=x; E[cnt].nx=G[y]; G[y]=cnt;
}

void dfs(int x,int p){
	int son=0,ct=0;
	for(int i=G[x];i;i=E[i].nx)
		if(E[i].t!=p){
			dfs(E[i].t,x);
			son++; ct+=!!f[E[i].t];
			f[x]+=f[E[i].t];
		}
	f[x]+=max(son-1-ct,0);
}

int main(){
	scanf("%d",&n);
	if(n==1) return puts("0"),0;
	for(int i=1,x,y;i<n;i++)
		scanf("%d%d",&x,&y),addedge(x,y),du[x]++,du[y]++;
	int rt=-1;
	for(int i=0;i<n;i++) if(du[i]>2) rt=i;
	if(rt==-1) return puts("1"),0;
	dfs(rt,-1);
	printf("%d\n",f[rt]);
	return 0;
}

Measured memory_bytes: 6528
s = input()
a = 0
mods = [0]*2019
mods[a] += 1
r = 1
for i in s[::-1]:
  a = (a+int(i)*r)%2019
  r = r*10%2019
  mods[a] += 1
ans = 0
for i in mods:
  ans += i*(i-1)//2
print(ans)

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

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

    vector<int> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A.at(i);
    }

    int max = 0;
    int tmp = 0;

    int i = 0;
    while (i < N) {
        int j = 0;
        while (j < N) {
            tmp = A.at(i) - A.at(j);
            if (max < tmp) {
                max = tmp;
            }
            j++;
        }
        i++;
    }

    cout << max << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    private static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {

        String s = sc.next();

        int x = 0;
        for (char ch : s.toCharArray()) {
            if (ch == 'x')
                x++;
        }

        System.out.println(x >= 8 ? "NO" : "YES");

    }


}


Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int X,A;
    cin >> X >> A;
    if(X<A){
        cout << 0;
    }else{
        cout << 10;
    };
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
#define dbg(a) cout << #a << " := " << (a) << endl
#define all(a) (a).begin(), (a).end()
 
using namespace std;
void solve();
signed main(){
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    solve();
 
    return 0;
}
 
 
const int INF = (int) 1e9 + 7;
void solve(){
    vector<int> nums(3); cin >> nums[0] >> nums[1] >> nums[2];
    int res = INF;
    for (int i = -2000; i <= 2000; ++i){
        int cur = 0;
        for (int j = 0; j < 3; ++j){
            int a = nums[j], b = i;
            if (a == b){
                cur += 0;
            } else if (b < a){
                cur += a - b;
            } else {
                if ((b - a) % 2 == 0)
                    cur += (b - a) / 2;
                else
                    cur += (b - (a - 1)) / 2 + 1;
            }
        }
        res = min(res, cur);
    }
    cout << res << endl;
}

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

typedef long long LL;

typedef vector<pair<LL,LL>>   vect_LL_LL;
typedef vector<pair<int,int>> vect_i_i;

bool compare(pair<LL,LL> p1, pair<LL,LL> p2)
{
    if (p1.first != p2.first)
        return p2.first > p1.first;
    else
        return p2.second > p1.second;

}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    LL H, W, N;
    cin >> H >> W >> N;
    LL x, y;
    vect_LL_LL obstacles;

    for (LL i=0; i<N; i++)
    {
        cin >> x >> y;
        if (x >= y)
            obstacles.push_back({x, y});
    }
    sort(obstacles.begin(), obstacles.end(), compare);

    int offset = 0;
    for (int i = 0; i < obstacles.size();i++)
    {

        if (obstacles[i].first > obstacles[i].second + offset)
        {
            cout << obstacles[i].first - 1;
            return 0;
        }
        else if (obstacles[i].first == obstacles[i].second + offset)
            offset++;
    }
    cout << H;
    return 0;
}


Measured memory_bytes: 6512