akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;

int main() {
    int n,k;
    scanf("%d%d",&n,&k);
    vector<int> a(n);
    rep(i,n) {
        scanf("%d",&a[i]);
    }
    int limit = n - k + 1;
    ll counter = 0;
    ll ans = 1000000000;
    rep(i,limit) {
        counter += abs(a[i+k-1] - a[i]);
        counter += min(abs(0-a[i]),abs(0-a[i+k-1]));
        ans = min(ans,counter);
        counter = 0;
    }
    printf("%ld\n",ans);
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
#define vi               vector<int>
#define pb(x)            push_back(x)
#define all(x)           x.begin(), x.end()
#define sortall(x)       sort(all(x))
#define debug(x)         cout << '>' << #x << ':' << x << endl;
#define int              long long
// const int mod = 1000000007;
using namespace std;
// const int N = 1e5 + 5; 
// int n;
// int a[N];

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
 
string s;
cin >>s;
for(int i=0; i< s.size(); i++){
  if(s[i] == '?'){
    s[i] = 'D';
  }
  // else if(s[i] == '?' && s[i+1] == 'P'){
    // s[i] ='D';
  // }

}
  cout << s << endl;
return 0;
}

Measured memory_bytes: 3772
import java.util.Arrays;
import java.util.Scanner;

public class Main
{
	static int maxn=200000+100;
	static int n;
	static node[]ns=new node[maxn];
	static int[]bit=new int[maxn];
	static int[]arr=new int[maxn];
	static Scanner scan=new Scanner(System.in);
	
	public static void main(String[] args)
	{
//		new Thread(new analyze()).start();
		read();
		System.out.println(cal());
	}
	
	//二分计算答案
	static long cal() {
		long l=0,r=4000000000L;//左开右闭
		long tot=(long)(n+1)*n/2;
		while(r-l>1) {
			long mid=(l+r)>>1;
			if(2*f(mid)>tot)
				r=mid;
			else
				l=mid;
		}
		return r;	
	}
	
	//计算中位数小于等于x的区间个数
	static long f(long x) {
		ns[1]=new node(-1,1);
		for(int i=2;i<n+2;i++) {
			ns[i]=new node((arr[i-1]>x?1:-1)+ns[i-1].sum,i);
		}
		Arrays.sort(ns,1,n+2);
		//清空bit
		for(int i=1;i<maxn;i++)bit[i]=0;
		long ans=0;
		add(ns[n+1].pos);
		for(int i=n;i>=1;i--){
			ans+=que(ns[i].pos);
			add(ns[i].pos);
		}
		return ans;
	}
	
	//树状数组查询操作
	static int que(int x) {
		int ans=0;
		while(x>0) {
			ans+=bit[x];
			x-=x&-x;
		}
		return ans;
	}
	
	//树状数组更新操作
	static void add(int x) {
		while(x<maxn) {
			bit[x]++;
			x+=x&-x;
		}
	}
	
	//读入数据
	static void read() {
		n=scan.nextInt();
		for(int i=1;i<=n;i++) {
			arr[i]=scan.nextInt();
		}
	}
}
class node implements Comparable<node>{
	int sum;
	int pos;
	public node(int s,int p) {
		sum=s;pos=p;
	}
	@Override
	public int compareTo(node arg0)
	{
		return this.sum==arg0.sum?this.pos-arg0.pos:this.sum-arg0.sum;
	}
}

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

int comp(const void* c1,const void* c2);

int main(){
	int i;
	int data[10];

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

	qsort(data,10,sizeof(int),comp);
	for(i=0;i<3;i++){
		printf("%d\n",data[i]);
	}
	return 0;
}

int comp(const void *c1,const void *c2){
	int data1=*(int*)c1;
	int data2=*(int*)c2;

	return data2-data1;
}

Measured memory_bytes: 604
#include <iomanip>
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main(void) {
  ios::sync_with_stdio(false);
  int X, Y;
  cin >> X >> Y;
  for (int t = 0; t <= X; ++t) {
    int feet = t * 2 + (X - t) * 4;
    if (feet == Y) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 3652
package main

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

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	sc.Scan()
	num, e := strconv.Atoi(sc.Text())
	if e != nil {
		log.Fatal(e)
	}
	return num
}

func selectionSort(target []int) ([]int, int) {
	counter := 0
	for i := 0; i < len(target); i++ {
		min := target[i]
		minIndex := i
		isChage := false
		for j := i; j < len(target); j++ {
			if target[j] < min {
				min = target[j]
				minIndex = j
				isChage = true
			}
		}
		target[minIndex] = target[i]
		target[i] = min
		if isChage {
			counter++
		}
	}
	return target, counter
}

func printSlice(s []int) {
	for i := 0; i < len(s); i++ {
		fmt.Print(s[i])
		if i != len(s)-1 {
			fmt.Print(" ")
		}
	}
	fmt.Print("\n")
}

func main() {
	N := scanInt()
	var unSorted []int
	sc.Scan()
	line := strings.Split(sc.Text(), " ")
	for i := 0; i < N; i++ {
		number, e := strconv.Atoi(line[i])
		if e != nil {
			log.Fatal(e)
		}
		unSorted = append(unSorted, number)
	}
	sorted, counter := selectionSort(unSorted)
	printSlice(sorted)
	fmt.Println(counter)
}



Measured memory_bytes: 1192
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef priority_queue<int> PQ;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;



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

	int x1, y1, x2, y2, x3, y3;
	cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
	double a = (double)sqrt((double)(x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2));
	double b = (double)sqrt((double)(x1 - x3)*(x1 - x3) + (y1 - y3)*(y1 - y3));
	double c = (double)sqrt((double)(x3 - x2)*(x3 - x2) + (y3 - y2)*(y3 - y2));

	double s = (a + b + c) / 2;
	double S = sqrt(s*(s - a)*(s - b)*(s - c));
	double r = 2 * S / (a + b + c);
	
	double ma = a;
	if (a < b && c < b)ma = b;
	if (b < c && a < c)ma = c;





	//cout << S << " " << s << " " << r << endl;
	
	//cout << ma / (2 + (ma / r)) << endl;
	printf("%.12f", ma / (2 + (ma / r)));

	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
#define int long long
signed main() {
	int h, w, s, t; cin >> h >> w >> s >> t;
	if (!(h % 2) || !(w % 2))cout << "Yes\n";
	else {
		cout << ((s + t) % 2 ? "No\n" : "Yes\n");
	}
}


Measured memory_bytes: 3104
N = int(input())
x = int(N**0.5)+1
ans_1 = N

for i in range(x):
    if N % x == 0:
        ans_1 = x
        break
    else:
        x -= 1

ans_2 = N//ans_1
print(ans_1 + ans_2 - 2)


Measured memory_bytes: 9444
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
	n = readline() |> parseInt
	a = readline() |> split |> parseMap
	b = readline() |> split |> parseMap
	if sum(a) < sum(b)
		println(-1)
	else
		c = a-b
		c = sort(c,rev=true)
		total = 0
		mcount = 0
		for i in 1:n
			if c[i] < 0
				total -= c[i]
				mcount += 1
			end
		end
		now = 1
		while total > 0
			total -= c[now]
			mcount += 1
			now+=1
		end
		println(mcount)
	end
end

main()


Measured memory_bytes: 132084
#include <stdio.h>
int main(){

	int a1,a2,a3,a4;
	int b1,b2,b3,b4;
	int i;
	int hit,blow;

	while(scanf("%d %d %d %d ",&a1,&a2,&a3,&a4)!=EOF){
		scanf("%d %d %d %d ",&b1,&b2,&b3,&b4);
		
		hit=0;blow=0;
		if(a1==b1)hit++;
		if(a2==b2)hit++;
		if(a3==b3)hit++;
		if(a4==b4)hit++;
		if(a1==b2)blow++;
		if(a1==b3)blow++;
		if(a1==b4)blow++;
		if(a2==b1)blow++;
		if(a2==b3)blow++;
		if(a2==b4)blow++;
		if(a3==b1)blow++;
		if(a3==b2)blow++;
		if(a3==b4)blow++;
		if(a4==b1)blow++;
		if(a4==b2)blow++;
		if(a4==b3)blow++;
		
		
		
		
		printf("%d %d\n",hit,blow);
	}


	return 0;
}

Measured memory_bytes: 600
let n, a, b = stdin.ReadLine().Split() |> fun x -> int64 x.[0], int64 x.[1], int64 x.[2]
(if (b - a) % 2L = 0L then (b - a) / 2L else (min (a - 1L) (n - b)) + 1L + (b - a - 1L) / 2L) |> printfn "%d"

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

int main(){
  int N; cin >> N;
  vector<int> A(N + 1), num(N + 1, 0);
  for(int i = 1; i <= N; i++){
    cin >> A[i];
  }
  for(int i = 1; i <= N; i++){
    num[A[i]] += i;
  }
  for(int i = 1; i <= N; i++){
    cout << num[i] << " ";
  }
  cout << endl;
}

Measured memory_bytes: 1664
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <iomanip>
 
using namespace std;
 
typedef long long ll;
typedef pair <long long, long long> pll;
 
ll mod = 998244353;
 
int main(){
  ios_base::sync_with_stdio(false);
  string s, t;
  cin >> s >> t;
  ll n = s.length();
  ll b = 0;
  for (int i = 0; i < n; i++)
   if (s[i] != t[i])
    b++;
  cout << b;
}

Measured memory_bytes: 3860
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
class A
{
    public static void Main(string[] args)
    {
        int t = 1;
        while (t > 0)
        {
            int n = int.Parse(Console.ReadLine());
            string s = Console.ReadLine().Trim();
           
            char[] list = new char[] {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z' };
            var final = new char[s.Length];
            for(int i = 0; i < s.Length; i++)
            {
                var c = s[i];
                var pos = Array.IndexOf(list, c);
                var nextPos = (pos + n) % 26;
                final[i] = list[nextPos];
            }
            Console.WriteLine(new string(final));
            t--;
        }
    }
   
}

Measured memory_bytes: 13152
#include <iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
using namespace std;
typedef long long int ll;
string S;
int main()
{
    cin >> S;
    ll len = S.size(), mod = 1e9 + 7, ans = 1;
    for (ll i = len - 1, d = 1; i >= 0; i--, d = d * 3 % mod) {
        if (S.at(i) == '1') ans = (ans * 2 + d) % mod;
    }
    cout << ans << "\n";
}

Measured memory_bytes: 3752
#include <iostream>
using namespace std;
struct Node {
  Node *next;
  Node *prev;
  int value;
};
Node *head;

void insert(int x) {
  Node *newnode = (Node*)malloc(sizeof(Node));
  newnode->value = x;
  newnode->next = head->next;
  head->next->prev = newnode;
  head->next = newnode;
  newnode->prev = head;
}

void deleteNode(int x) {
  Node *targetNode = head;
  while (targetNode->next->value != x) {
    targetNode = targetNode->next;
    if (targetNode->next->value == -1) return;
  }
  Node *newnode = targetNode->next->next;
  newnode->prev = targetNode;
  free(targetNode->next);
  targetNode->next = newnode;
}

void deleteFirst() {
  Node *newnode = head->next->next;
  free(head->next);
  head->next = newnode;
  newnode->prev = head;
}

void deleteLast() {
  Node *targetNode = head->prev->prev;
  free(targetNode->next);
  targetNode->next = head;
  head->prev = targetNode;
}

void printList() {
  for (Node *node = head->next; node->value != -1; node=node->next) {
    cout << node->value;
    if (node->next->value != -1) {
      cout << " ";
    }
  } 
  cout << endl;
}

int main() {
  head = (Node*)malloc(sizeof(Node));
  head->value = -1;
  head->prev = head;
  head->next = head;
  
  int N; cin >> N;
  string s; int num;
  for (int i = 0; i < N; i++) {
    cin >> s;
    if (s == "insert") {
      cin >> num;
      insert(num);
    } else if (s == "delete") {
      cin >> num;
      deleteNode(num);
    } else if (s == "deleteLast") {
      deleteLast();
    } else if (s == "deleteFirst") {
      deleteFirst();
    }
  }
  printList(); 
}




Measured memory_bytes: 34436
import java.io.*;
import java.util.*;
public class Main {
    private static MyScanner scanner;
 
    public static void main (String[] args){
        Main instance = new Main();
        scanner = instance.new MyScanner();
        instance.solve();
    }
 
    private void solve() {
        try {
            int K = scanner.nextInt();
            int S = scanner.nextInt();
            int count = 0;
            for (int i = 0; i <= K; i++) {
                int X = i;
                for (int j = 0; j <= K; j++) {
                    int Y = j;
                    if (X + Y > S) {
                        break;
                    }
                    if (S - X - Y <= K) {
                        count++;
                    }
                }
            }
            System.out.println(count);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
 
    private class MyScanner {
        String[] s;
        int i;
        BufferedReader br;
        String reg = " ";
 
        MyScanner () {
            s = new String[0];
            i = 0;
            br = new BufferedReader(new InputStreamReader(System.in));
        }
 
        public String next() throws IOException {
            if (i < s.length) return s[i++];
            String line = br.readLine();
            while (line.equals("")) {
                line = br.readLine();
            }
            s = line.split(reg, 0);
            i = 0;
            return s[i++];
        }
 
        public int nextInt() throws NumberFormatException, IOException {
            return Integer.parseInt(next());
        }
 
        public double nextDouble() throws NumberFormatException, IOException {
            return Double.parseDouble(next());
        }
 
        public long nextLong() throws NumberFormatException, IOException {
            return Long.parseLong(next());
        }
    }
}

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

int main() {
    int a, b;
    cin >> a >> b;
    if (a == b)
        cout <<"Draw";
    else if (a == 1)
        cout << "Alice";
    else if (b == 1)
        cout << "Bob";
    else if (a > b)
        cout << "Alice";
    else if (a < b)
        cout << "Bob";

    return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

int main()
{
	int n, i, i2;
	int prime[10000];
	for(int i=2; i<= 10000; i++){
		prime[i]=1;
		for(i2 = 2; i2<=sqrt(i); i2++)
		{
			if(i % i2 == 0)
			{
				prime[i] = 0;
				break;
			}
		}
	}
	while(1)
	{
		scanf ("%d",&n);
		if(n==0)
		{
			return 0;
		}
		for(i=n; 1; i--)
		{
			if(prime[i] && prime[i-2])
			{
				printf("%d %d\n",i-2 ,i);
				break;
			}
		}
	}
}

Measured memory_bytes: 2728
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <time.h>
#include <list>
#include <bitset>

using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define reps(x,c) for(auto x:c)
#define all(x) begin(x), end(x)
#define pb(a) emplace_back(a) 
#define mp(a,b) make_pair((a),(b))
#define pl pair<ll,ll>
#define INF 2147483600
#define MOD 1000000007
#define fi first
#define se second
#define dbg(x) cout << #x"="<< (x) << endl
#define dbgv(x) cout<<#x<<endl;reps(y,x){cout<<y<<" ";}cout<<endl

int main(){
  ll n;cin>>n;
  map<ll,ll> m;
  ll a;
  rep(i,n){
    cin>>a;
    m[a+1]++;
    m[a-1]++;
    m[a]++;
  }
  ll ans=0;
  reps(x,m){
    ans=max(ans,x.se);
  }
  cout<<ans<<endl;
  return 0;
}

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

struct war {
  int a;
  int b;
};
bool operator < (const war &l, const war &r) { return l.b < r.b; }

int main() {
  int n, m;
  cin >> n >> m;
  war w[m];
  for ( int i = 0; i < m; i++ ) {
    int a, b;
    cin >> a >> b;
    w[i] = {a, b};
  }
  sort(w, w+m);

  int ans = 0;
  int before_bridge = -1;
  for ( int i = 0; i < m; i++ ) {
    if ( w[i].a > before_bridge ) {
      ans++;
      before_bridge = w[i].b-1;
    }
  }

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


Measured memory_bytes: 4356
#include <iostream>
#include <iomanip>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <algorithm>
#include <queue>
#include <cstdint>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

constexpr ll inf = INT64_MAX / 4;

int p[200000], n, k;

ll comb(ll n, ll k) {
    if (k == 0) return 1;
    return (comb(n - 1, k - 1) * n) / k;
}

int main() {
    string n;
    ll k, r = 0;
    cin >> n >> k;
    r += comb(n.size() - 1, k) * pow(9, k);
    string t;
    for (int i = 0; i < n.size(); i++)t.push_back('0');
    if (k == 1) {
        for (t[0] = '1'; t[0] <= '9'; t[0]++) {
            if (t <= n) r++;
        }
    }
    if (k == 2) {
        for (t[0] = '1'; t[0] <= '9'; t[0]++) {
            for (int i = 1; i < t.size(); i++) {
                for (t[i] = '1'; t[i] <= '9'; t[i]++) {
                    if (t <= n) r++;
                }
                t[i] = '0';
            }
        }
    }
    if (k == 3) {
        for (t[0] = '1'; t[0] <= '9'; t[0]++) {
            for (int i = 1; i + 1 < t.size(); i++) {
                for (t[i] = '1'; t[i] <= '9'; t[i]++) {
                    for (int j = i + 1; j < t.size(); j++) {
                        for (t[j] = '1'; t[j] <= '9'; t[j]++) {
                            if (t <= n) r++;
                        }
                        t[j] = '0';
                    }
                }
                t[i] = '0';
            }
        }
    }
    cout << r << endl;
}


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

class Main{
    public static void main(String args[])throws IOException{
      try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))){
        int[] input = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
        int N = Integer.parseInt(br.readLine());

        System.out.println(input[N-1]);
      }
    }
}

Measured memory_bytes: 22996
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=3e5+5,mod=1e9+7;
int n;
ll a[N],cnt[2];
ll ans=0;
int main() {
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
	for(int i=59;i>=0;i--) {
		cnt[0]=cnt[1]=0;
		for(int j=1;j<=n;j++) cnt[(a[j]>>i)&1]++;
		ans+=(1ll<<i)%mod*cnt[0]%mod*cnt[1]%mod;
		ans%=mod;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 2560
import java.util.*;
public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		
		int N = sc.nextInt();
		int K = sc.nextInt();
		if (1 + 2*(K-1) <= N) System.out.println("YES");
		
		else System.out.println("NO");
	}
}

Measured memory_bytes: 21716
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#define mod 1000000007
#define eps 1e-6
#define ll long long
#define INF 0x3f3f3f3f
#define MEM(x,y) memset(x,y,sizeof(x))
using namespace std;
int dt[][2]= {{1,0},{-1,0},{0,1},{0,-1},{0,0}};
//typedef pair<int, int> P;
//priority_queue<int, vector<int>, greater<int> > q;
int main()
{
   IOS;
   ll a,b;
   cin >>a >>b;
   ll mina,maxa,minb,maxb;
   //cout<<a/0.08<<endl;
   mina=ceil(a/0.08);
   maxa=floor((a+1)/0.08);
   if((a+1)/0.08==maxa)--maxa;
   minb=ceil(b/0.1);
   maxb=floor((b+1)/0.1);
   if((b+1)/0.1==maxb)--maxb;
   if(maxa<minb||mina>maxb){
       cout<<-1;
       return 0;
   }
   else
   {
       if(minb<=maxa&&maxb>=maxa){cout<<minb;return 0;}
       else if(minb<=mina&&maxb>=mina){cout<<mina;return 0;}
       else if(minb<mina&&maxb>maxa){cout<<mina;return 0;}
       else if(minb>mina&&maxb<maxa){cout<<minb;return 0;}
   }
   
}


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

long long inf = (1 << 30);
long long mod = 1e9;

int main(){

    int N;
    cin >> N;
    vector<int> a(N);
    for(int i = 0; i < N; i++) cin >> a[i];

    int div1 = 0, div2 = 0, div4 = 0;
    for(int i = 0; i < N; i++){
        if(a[i] % 4 == 0) div4++;
        else if(a[i] % 2 == 0) div2++;
        else div1++;
    }

    if(div2 == 0 && (div1 <= (div4 + 1))) cout << "Yes" << endl;
    else if(div1 <= div4) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 640
n = int(input())
num_list = sorted(list(map(int, input().split())))
def merge(num_list):
    if len(num_list) == 1: 
        return num_list
    if len(num_list) ==2: 
        return [(num_list[0] + num_list[1])/2]
    else:
        tmp = num_list[2:]
        tmp.append((num_list[0] + num_list[1])/2)
        return tmp

for i in range(n-1):
    num_list = sorted(merge(num_list))
print(num_list[0])
    



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

#define PI 3.14159265358979323846264338327950L
#define ll long long

using namespace std;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll answer = 0;
    ll x;
    cin >> x;
    ll amount = 100;
    while (amount < x) {
        amount += (ll)(amount / 100);
        answer++;
    }
    cout << answer << "\n";
    return 0;


}


Measured memory_bytes: 3568
#include<iostream>

using namespace std;
#define MAX 1000000
#define INF 1000000000

int dp1[MAX+1],dp2[MAX+2];

int main(){
    for(int i = 1;i <= MAX;i++){
        dp1[i] = INF;
        dp2[i] = INF;
    }

    for(int n = 1;n * (n + 1) * (n + 2) / 6 <= MAX;n++){
        int a = n * (n + 1) * (n + 2) / 6;
        for(int i = a;i <= MAX;i++){
            dp1[i] = min(dp1[i],dp1[i - a] + 1);
        }
        if(a % 2 == 0)continue;
        for(int i = a;i <= MAX;i++){
            dp2[i] = min(dp2[i],dp2[i - a] + 1);
        }
    }

    while(true){
        int n;
        cin >> n;
        if(n == 0)break;
        cout << dp1[n] << " " << dp2[n] << endl;
    }
    return 0;
}


Measured memory_bytes: 10892
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <cmath>
#include <ctime>
#include<bitset>
#include <utility>
using namespace std;
#define rank rankk
#define mp make_pair
#define pb push_back
#define xo(a,b) ((b)&1?(a):0)
//#define LL ll
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef long long ll;
typedef pair<ll,int> pli;
const int INF=0x3f3f3f3f;
const ll INFF=0x3f3f3f3f3f3f3f3fll;
const int MAX=1e6+5;
const int MAX_N=MAX;
const ll MOD=998244353;
const long double pi=acos(-1.0);
//const double eps=0.00000001;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
template<typename T>inline T abs(T a) {return a>0?a:-a;}
template<class T> inline
void read(T& num) {
    bool start=false,neg=false;
    char c;
    num=0;
    while((c=getchar())!=EOF) {
        if(c=='-') start=neg=true;
        else if(c>='0' && c<='9') {
            start=true;
            num=num*10+c-'0';
        } else if(start) break;
    }
    if(neg) num=-num;
}
inline ll powMM(ll a,ll b,ll M){
    ll ret=1;
    a%=M;
//    b%=M;
    while (b){
        if (b&1) ret=ret*a%M;
        b>>=1;
        a=a*a%M;
    }
    return ret;
}
void open()
{
    freopen("1009.in","r",stdin);
    freopen("out.txt","w",stdout);
}
ll inv[MAX],fac[MAX];
ll C(ll x,ll y)
{
    return fac[x]*inv[y]%MOD*inv[x-y]%MOD;
}
int n,m;ll da=1e6;
ll an;
int main()
{
    fac[0]=1;for(ll i=1;i<=da;i++)fac[i]=i*fac[i-1]%MOD;
    inv[da]=powMM(fac[da],MOD-2,MOD);for(ll i=da;i>=1;i--)inv[i-1]=inv[i]*i%MOD;
    scanf("%d%d",&n,&m);if(n<m)swap(n,m);
    for(ll i=1;i<=m;i++)
        an=(an+C(n+m-2*i,n-i)*C(2*i,i)%MOD)%MOD;
    an=an*inv[2]%MOD*fac[n]%MOD*fac[m]%MOD*inv[n+m]%MOD;
    printf("%lld\n",(an+n)%MOD);
}


Measured memory_bytes: 16000
import std.algorithm, std.stdio, std.range;

int N;
immutable W = 10, M = 12;
immutable dy = [-2,-2,-2,-1,-1,0,0,1,1,2,2,2], dx = [-1,0,1,-2,2,-2,2,-2,2,-1,0,1];
immutable ddy = [-1,-1,-1,0,0,0,1,1,1], ddx = [-1,0,1,-1,0,1,-1,0,1];
int[] ys, xs;

void main(){
	for(;init;){
		writeln(solve ? "OK" : "NA");
	}
}

bool init(){
	ys = []; xs = [];
	int y, x;
	scanf("%d%d", &y, &x);
	ys ~= y; xs ~= x;
	if(y == 0 && x == 0){
		return false;
	}
	scanf("%d", &N);
	foreach(_; 0..N){
		scanf("%d%d", &y, &x);
		ys ~= y; xs ~= x;
	}
	return true;
}

bool solve(){
	auto dp = new bool[][](N + 1, 9);
	dp[0][4] = true;

	foreach(i; 0..N){
		foreach(j; 0..9)if(dp[i][j]){
			foreach(k; 0..M){
				int ny = ys[i] + ddy[j] + dy[k], nx = xs[i] + ddx[j] + dx[k];
				if(0<=ny && ny<W && 0<=nx && nx<W)foreach(l; 0..9){
					if(ys[i+1] + ddy[l] == ny && xs[i+1] + ddx[l] == nx){
						dp[i+1][l] = true;
					}
				}
			}
		}
	}

	return count(dp[N], true) > 0;
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define deg_to_rad(deg) (((deg) / 360) * 2 * M_PI)
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)

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

typedef long long ll;

const string YES = "Yes";
const string NO = "No";

void solve(std::string S)
{
    set<char> s;
    rep(i, S.size()) { s.insert(S[i]); }
    if (s.size() == 2)
    {
        cout << YES << endl;
    }
    else
    {
        cout << NO << endl;
    }
}

int main()
{
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define REP2(i,x,n) for (int i = x; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);
static const int INF = 1e9+7;



int main(){
  ll a, b;
  cin >> a >> b;
  ll ans = a /__gcd(a,b) * b;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3608
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <stack>
#include <set>
#include <cmath>
#include <algorithm>
using namespace std;

int main(){
	int mx=0;
	int arr[101]={0};
	int j=0,n;
	while(cin>>n){
		arr[n]++;
	}
	for(int i=1 ; i<101 ; ++i){
		if(mx<arr[i])
			mx=arr[i];
	}
	for(int i=0 ; i<101 ; ++i){
		if(arr[i]==mx){
			cout << i << endl;
		}
	}
	return 0; 
}

Measured memory_bytes: 1160
S=input()
flag=True
words={'dream','dreamer','erase','eraser'}
while flag:
    if S=="" :
        break
    if S[-7:] in words:
        S=S[0:-7]
        continue
    elif S[-6:] in words:
        S=S[0:-6]
        continue
    elif S[-5:] in words:
        S=S[0:-5]
        continue
    else :
        flag=False
if flag:
    print("YES")
else :
    print("NO")


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

x = []
y = []
for i in range(N):
    in1, in2 = list(map(int,input().split()))
    x.append(in1)
    y.append(in2)

#f = [[0]*2 for i in range(N)]
X=[]
Y=[]
for i in range(N):
    #f[i][0] = x[i]-x[i]
    #f[i][1] = x[i]+y[i]
    X.append(x[i]-y[i])
    Y.append(x[i]+y[i])

dam1 = max(X) - min(X)
dam2 = max(Y) - min(Y)
print(max(dam1,dam2))

Measured memory_bytes: 123876
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	long long k;
	cin >> n >> k;
	vector<int> a(n+1);
	for(int i=1; i<=n; ++i) cin >> a[i];

	int t=1, vt=-1, r;
	vector<int> v(n+1,-1);
	v[1]=1;
	for(int i=1; i<=min((long long)n,k); ++i){
		t=a[t];
		if(v[t]!=-1){
			vt=v[t];
			r=i;
			break;
		}
		v[t]=i+1;
	}
	
	t=1;
	if(vt!=-1){
		k = (k-vt+1)%(r-vt+1);
		for(int i=1; i<vt; ++i) t=a[t];
	}
	for(int i=0; i<k; ++i){
		t=a[t];
	}

	cout << t << endl;
}

Measured memory_bytes: 4844
def linear_search(s,t):
    count = 0
    check_list = []
    for i in s:
        for j in t:
            if i == j and (j in check_list) == False:
                count = count + 1
                check_list.append(j)
    return count

sline = []
tline = []

n = int(input())

sline = list(map(int,input().split()))
if len(sline) != n:
    print("Error")
    exit()

q = int(input())

tline = list(map(int,input().split()))
if len(tline) != q:
    print("Error")
    print(len(tline),q)
    exit()

count = linear_search(sline,tline)

print(count)



Measured memory_bytes: 6328
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <math.h>
#include <stack>
#include <climits>
#include <bitset>
#include <utility>


using namespace std;
typedef long long ll;
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; }
// const ll INF = 1LL <<60;
const int INF = 10000;

//最小公倍数
ll gcd(ll x, ll y) {
  ll tmp = 0;
  if (x < y){
    tmp=x;
    x=y;
    y=tmp;
  }
  while (y > 0) {
    ll r = x % y;
    x = y;
    y = r;
  }
  return x;
}

//最大公倍数
ll lcm(ll x,ll y){
  return x/gcd(x,y)*y;
}

//階乗
ll kaijo(ll k){
    ll sum = 1;
    for (ll i = 1; i <= k; ++i)
    {
        sum *= i;
        sum%=1000000000+7;
    }
    return sum;
}

//for(int i = ; i < ; i++){}

ll lmax(ll s,ll t){
  if(s>t){
    return s;
  }
  else{
    return t;
  }
}

ll lmin(ll s,ll t){
  if(s<t){
    return s;
  }
  else{
    return t;
  }
}
// ここから開始

int main(){
  int n;
  cin>>n;
  int x[n],y[n];
  vector<pair<int,int> > d;
  for(int i = 0; i < n; i++) cin>>x[i]>>y[i];
  for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++){
      if(i==j) continue;
      else{
        d.push_back(make_pair(x[i]-x[j],y[i]-y[j]));
      }
    }
  }
  int ans = 0;
  for(auto a:d){
    int tmp = 0;
    for(int i = 0; i < n; i++){
      for(int j = 0; j < n; j++){
        if(make_pair(x[i]-x[j],y[i]-y[j])==a) tmp++;
      }
    }
    // cout<<tmp<<endl;
    ans=max(tmp,ans);
  }
  cout<<n-ans<<endl;
  return 0;
}


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


def solve(inp):
    H = int(inp.readline().strip())

    n = 1
    r = 1
    while True:
        n *= 2
        if n > H:
            break
        r = r * 2 + 1

    return r


def main():
    import sys
    result = solve(sys.stdin)
    if result is not None and result != '':
        print(result)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define mset(a, b) memset(a, b, sizeof(a))
#define mcpy(a, b) memcpy(a, b, sizeof(a))
using namespace std;
typedef long long LL;
const int MAXN = 535005;

template <typename T> inline void read(T &AKNOI) {
	T x = 0, flag = 1;
	char ch = getchar();
	while (!isdigit(ch)) {
		if (ch == '-') flag = -1;
		ch = getchar();
	}
	while (isdigit(ch)) {
		x = x * 10 + ch - '0';
		ch = getchar();
	}
	AKNOI = flag * x;
}

char s[MAXN];
int n, m, mx, ans[MAXN];
int root, tot, ch[MAXN * 13][3], ori[MAXN * 13], tag[MAXN * 13];

void pushdown(int rt) {
	if (tag[rt]) {
		swap(ch[rt][1], ch[rt][2]);
		for (int i = 0; i < 3; ++i) {
			tag[ch[rt][i]] ^= 1;
		}
		tag[rt] = 0;
	}
}

void Build(int &rt, int dep, int w, int num) {
	rt = ++tot;
	if (dep == n) {
		ori[rt] = num;
		return;
	}
	for (int i = 0; i < 3; ++i) {
		Build(ch[rt][i], dep + 1, w * 3, num + w * i);
	}
}

void Add1() {
	int rt = root;
	for (int i = 0; i < n; ++i) {
		pushdown(rt);
		swap(ch[rt][0], ch[rt][1]);
		swap(ch[rt][0], ch[rt][2]);
		rt = ch[rt][0];
	}
}

void GetAns(int rt, int dep, int w, int num) {
	if (dep == n) {
		ans[ori[rt]] = num;
		return;
	}
	pushdown(rt);
	for (int i = 0; i < 3; ++i) {
		GetAns(ch[rt][i], dep + 1, w * 3, num + w * i);
	}
}

void init() {
	read(n);
	scanf("%s", s + 1);
	m = strlen(s + 1);
	for (int i = mx = 1; i <= n; ++i, mx *= 3);
}

void solve() {
	Build(root, 0, 1, 0);
	for (int i = 1; i <= m; ++i) {
		if (s[i] == 'S') {
			tag[root] ^= 1;
		} else {
			Add1();	
		}/*
		GetAns(root, 0, 1, 0);
		for (int i = 0; i < mx; ++i) {
			printf("%d ", ans[i]);
		}
		printf("\n");*/
	}
	GetAns(root, 0, 1, 0);
	for (int i = 0; i < mx; ++i) {
		printf("%d ", ans[i]);
	}
}

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


Measured memory_bytes: 21912
using System;

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = Console.ReadLine();
            var sum = 0;
            for (int i = 0; i < N.Length; i++)
            {
                sum += int.Parse(N[i].ToString());
            }
            Console.WriteLine((sum % 9) == 0 ? "Yes" : "No");
        }
    }
}


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

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

const int lim = 1000000007;

int main(){
    ll a, b, c, d;
    cin >> a >> b >> c >> d;

    ll ans = max({a*c, a*d, b*c, b*d});
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3632
# D
import math
X = int(input())

B = -math.floor(math.pow(X, 0.2))
for b in range(B, 100000):
    tmp = math.pow(X + b ** 5, 0.2)
    if math.floor(int(tmp) - tmp + 1.0e-6) == 0:
        break
        
tmp = math.floor(tmp + 1.0e-6)
print(tmp, b)

Measured memory_bytes: 9444
K, N = map(int, input().split())
AA = list(map(int,input().split()))
 
KK = [False]*K
for a in AA:
  KK[a] = True
 
dist = 0
dist_max = 0
for i in range(2*K):
  if KK[int(i%K)] == 1:
    dist = 1
  else:
    dist += 1
  if dist > dist_max:
    dist_max = dist
print(K-dist_max)

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

bool isPrime(int N)
{
	int nsq = (int)sqrt((float)N);
	for (int i=2; i<=nsq; i++) {
		if (N%i==0) return false;
	}
	return true;
}

int main()
{
	int N;
	std::cin >> N;
	int count = 0;
	for (int i=0; i<N; i++) {
		int p;
		std::cin >> p;
		count += isPrime(p) ? 1 : 0;
	}
	std::cout << count << std::endl;
	
	return 0;
}




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

#define ll long long

ll MAX(ll a, ll b) {

	if (a>b)return a;
	else return b;

}
int main() {

	ll A, B, C, K, ans;
	cin >> A >> B >> C >> K;

	ans = MAX(A, MAX(B, C));
	for (int i = 0; i<K; i++)ans *= 2;
	cout << ans + A + B + C - MAX(A, MAX(B, C)) << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
const long double PI=(acos(-1));
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int main(){
  int n,m,X,Y;
  cin>>n>>m>>X>>Y;
  vector<int> x(n);
  vector<int> y(m);
  rep(i,n){
    cin>>x[i];
  }
  rep(i,m){
    cin>>y[i];
  }
  x.emplace_back(X);
  y.emplace_back(Y);
  int MAX_x=*max_element(x.begin(),x.end());
  int MIN_y=*min_element(y.begin(),y.end());
  if(MAX_x<MIN_y) cout<<"No War"<<endl;
  else cout<<"War"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
#define fi first
#define se second
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define repn(i,n) for(ll i=0;i<=(ll)(n);i++)
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
//cin.tie(0);
//ios::sync_with_stdio(false);

ll gcd(ll a,ll b){//最大公約数を求める
    if(a<b){
        swap(a,b);
    }

    if(a%b == 0){
        return b;
    }else{
    return gcd(b,a%b);
    }
}

signed main(){
    ll n,k,gcdofa=-1,maxofa=1;cin>>n>>k;

    for(int i=0;i < n;i++)
    {
        ll a;cin>>a;
        maxofa=max(a,maxofa);

        if(i==0)gcdofa=a;
        else gcdofa=gcd(a,gcdofa);
    }

    if(maxofa<k)cout<<"IMPOSSIBLE"<<endl;
    else{
        if(gcdofa==1)cout<<"POSSIBLE"<<endl;
        else{
            if(k%gcdofa==0)cout<<"POSSIBLE"<<endl;
            else cout<<"IMPOSSIBLE"<<endl;
        }
    }
}


    

Measured memory_bytes: 256
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    h, w = f()
    lines = []
    for i in range(h):
        lines.append(input())
    
    rl = set()
    rc = set()
    for i in range(h):
        for j in range(w):
            if lines[i][j]== '#':
                rl.add(i)
                rc.add(j)
    
    rl = sorted(rl)
    rc = sorted(rc)

    for i in rl:
        for j in rc:
            print(lines[i][j], end = '')
        print()



solve()


Measured memory_bytes: 4468
use std::io;

fn main() {
    let mut input_string = String::new();
    io::stdin().read_line(&mut input_string).expect("Error");
    let mut tmp_n_l = input_string.trim().split_whitespace();
    let n: i32 = tmp_n_l.next().unwrap().parse::<i32>().unwrap();
    let mut s_list: Vec<String> = Vec::new();
    for _ in 0..n {
        let mut input_s = String::new();
        io::stdin().read_line(&mut input_s).expect("Error");
        let input_s = input_s.trim().to_string();
        s_list.push(input_s);
    }
    s_list.sort();
    let mut result = String::new();
    for s in s_list {
        result += &s;
    }
    println!("{}", result);
}

Measured memory_bytes: 4352
a=[*?a..?z]
b=[10000]*26
n=gets.to_i
n.times do
  s=gets.chomp
  r=[0]*26
  s.length.times do |i|
    g=a.index(s[i])
    r[g]+=1
  end
  26.times do |i|
    b[i]=[b[i],r[i]].min
  end
end
s=""
26.times do |i|
  s+=a[i]*b[i]
end
puts s

Measured memory_bytes: 1788
#include <iostream> // cout, endl, cin
#include <cmath> //sqrt pow
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // dequef
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower

#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define all(a) (a).begin(), (a).end()
#define mod 1000000007
using ll = long long;
using namespace std;
const int len = 200010;
int modPow(ll a, ll n, ll p) { //繰り返し二乗法 a**n % p
  if (n == 1) return a % p;
  if (n % 2 == 1) return (a * modPow(a, n - 1, p)) % p;
  ll t = modPow(a, n / 2, p);
  return (t * t) % p;
}
vector<ll> fact(len), inv(len);
ll choose(ll n, ll k){
  if(n < k) return 0;
  if(!k) return 1;
  return fact[n] * (inv[k] * inv[n - k] % mod) % mod;
}
int main(){
  fact[0] = fact[1] = 1;
  for(int i = 2; i < len; i++) fact[i] = fact[i - 1] * i % mod;
  inv[len - 1] = modPow(fact[len - 1], mod - 2, mod);
  for(int i = len - 2; i >= 0; i--) inv[i] = inv[i + 1] * (i + 1) % mod;
  int n;
  cin >> n;
  int right = 0, left = 0;
  map<int, int> cnt;
  rep(i, n + 1){
    int a;
    cin >> a;
    if(cnt[a]){
      right = n - i;
      left = cnt[a] - 1;
    }
    cnt[a] = i + 1;
  }
  cout << n << endl;
  for(int i = 1; i <= n; i++){
    cout << (choose(n + 1, i + 1) + mod - choose(left + right, i)) % mod << endl;
  }
}

Measured memory_bytes: 9088
fun longList() = readLine()?.split(" ")?.map(String::toLong) ?: TODO()
fun main(args: Array<String>) {
    val n = readLine()?.toInt() ?: return
    var a = longList().sorted()
    var total = a.last()
    a = a.dropLast(1)
    var index = a.size - 1
    var d = false
    repeat(n - 2) {
        total += a[index]
        if (d) {
            d = false
            index--
        } else {
            d = true
        }
    }
    println(total.toString())
}

Measured memory_bytes: 71112
#include <iostream>
#include <set>
#include <vector>
#include <queue>
#include <stack>
#include <utility>
#include <algorithm>

using namespace std;

typedef long long signed int ll;

constexpr ll NIL = -20000000000;

int u[10010];

int main() {
    for(int i = 0;i < 10010;i++) u[i] = -1;
    int n,q,x,y,com;
    cin >> n >> q;
    for(int i = 0;i < q;i++) {
        cin >> com >> x >> y;
        if(com) {
            int c[2] = {x,y};
            while(u[c[0]] != -1) c[0] = u[c[0]];
            while(u[c[1]] != -1) c[1] = u[c[1]];
            if(c[0] == c[1]) cout << 1 << endl;
            else cout << 0 << endl;
        } else {
            int c[2] = {x,y};
            while(u[c[0]] != -1) c[0] = u[c[0]];
            while(u[c[1]] != -1) c[1] = u[c[1]];
            if(c[0] != c[1]) u[c[1]] = c[0];
        }
    }
}



Measured memory_bytes: 3124
/******************************************************************************

                            Online Java Compiler.
                Code, Compile, Run and Debug java program online.
Write your code in this editor and press "Run" button to execute it.

*******************************************************************************/
import java.util.*;
public class Main
{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int x = 0;
		while(true)
		{
		    if(n <= 1000)
		    {
		        x = 1000 - n;
		        break;
		    }
		    else
		    {
		        n = n - 1000;
		    }
		}
		System.out.println(x);
	}
}


Measured memory_bytes: 35776
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <random>
#include <cmath>
#include <iomanip>
#include <climits>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>
#include <new>
#include <typeinfo>
#include <iterator>
#include <cassert>

using ll = long long;
using ull = unsigned long long;
constexpr ll mop = 1000000007;
constexpr ll mop2 = 998244353;

using namespace std;

constexpr ll NOT_SPECIFIED_VALUE_MIN = INT64_MIN;
constexpr ll NOT_SPECIFIED_VALUE_MAX = INT64_MAX;

template <typename T>
T gcd(T a, T b) {
    if(a < b) gcd(b, a);
    T r;
    while ((r=a%b)) {
        a = b;
        b = r;
    }
    return b;
}

template <typename T>
T lcm(T a, T b) {
    return a * b / gcd(a,b);
}


template <typename T>
map<T,T> prime_factor(T n){
    map<T,T> res;
    for  (T i=2;i*i<=n;i++){
        while (n%i == 0){
            ++ res[i];
            n /= i;
        }
    }
    if(n!=1){
        res[n] += 1;
    }
    return res;
}

int main()
{
	ll n;
	cin >> n;
	unordered_map<ll, ll> primeFactorTable;
	ll nowGCD = 0;
    bool IsPairwiseCoprime = true;
	for( ll i = 0; i < n; i++ )
	{
		ll tmp;
		cin >> tmp;
        if( IsPairwiseCoprime )
        {
            auto tmpPrimeFactorTable = prime_factor( tmp );
            for( auto prime : tmpPrimeFactorTable )
            {
                if( primeFactorTable[prime.first] == 1 )
                {
                    IsPairwiseCoprime = false;
                    break;
                }
                primeFactorTable[prime.first] = 1;
            }
        }
		if( i == 0 )
		{
			nowGCD = tmp;
		}
		else
		{
			nowGCD = gcd( nowGCD, tmp );
		}
	}
    bool IsSetwiseCoprime = ( nowGCD == 1 ) ? true : false;
    if( IsPairwiseCoprime )
    {
        cout << "pairwise coprime" << endl;
    }
    else if( IsSetwiseCoprime )
    {
        cout << "setwise coprime" << endl;
    }
    else
    {
        cout << "not coprime" << endl;
    }
}


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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
	return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
	for(auto &e:u) fill_v<T>(e,v...);
}

int64 N;

PII decode(int64 x) {
  x--;
  return PII(x/N, x%N);
}

bool in(int y, int x) {
  return 0<=y && y<N && 0<=x && x < N;
}

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

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

	cin >> N;
	vector<int64> P(N*N);
	REP(i, N*N) cin >> P[i];

	auto d = make_v<int>(N, N);
	auto ok = make_v<int>(N, N);
	REP(i, N) {
	  REP(j, N) {
	    d[i][j] = min({i, j, N-i-1, N-j-1});
	    ok[i][j] = 1;
	  }
	}
	int64 res = 0;
	using T = tuple<int, int, int>;
	int64 cnt = 0;
	REP(i, N*N) {
	  int y, x;
	  tie(y, x) = decode(P[i]);
	  res += d[y][x];
	  ok[y][x] = 0;
	  deque<T> que;
	  que.emplace_back(d[y][x], y, x);
	  while (que.size()) {
//	    cnt++;
	    int cc, yy, xx;
	    tie(cc, yy, xx) = que.front(); que.pop_front();
	    int nc = cc + ok[yy][xx];
	    REP(k, 4) {
	      int ny = yy + dy[k], nx = xx + dx[k];
	      if (!in(ny, nx)) continue;
	      if (d[ny][nx] > nc) {
	        d[ny][nx] = nc;
	        if (ok[yy][xx])
	          que.emplace_back(nc, ny, nx);
          else
            que.emplace_front(nc, ny, nx);
	      }
	    }
	  }
	}
	cout << res << endl;
//	cout << cnt << endl;
}


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

#define ff first
#define ss second
#define PI acos(-1)
#define pb push_back
#define int long long
#define ld long double
#define sp fixed<<setprecision
#define bp __builtin_popcountll
#define all(x) x.begin(),x.end()
#define pii pair<long long,long long>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

const int M = (1e9)+7;
const int N = 1e6+5;

signed main()
{
    FAST
    int tc=1;
    //cin>>tc;
    for(int ti=1;ti<=tc;ti++)
    {
        int d,t,s;
        cin>>d>>t>>s;
        int ans = (s*t >= d);
        cout<<(ans?"Yes":"No")<<endl;
    }
    return 0;
}


Measured memory_bytes: 3636
#include<iostream>
using namespace std;
//flagを用いたバブルソート
int bubbleSort(int A[], int N){
    int sw = 0;
    bool flag = 1;
    for( int i = 0; flag; i++){
        flag = 0;
        for( int j = N - 1; j >= i + 1; j--){
            if( A[j] < A[j - 1] ){
                //隣接要素を交換する
                swap(A[j], A[j - 1]);
                flag = 1;
                sw++;
            }
        }
    }
    return sw;
}

int main() {
    int A[100], N, sw;
    cin >> N;
    for(  int i = 0; i < N; i++) cin >> A[i];

    sw = bubbleSort(A, N);

    for( int i = 0; i < N; i++){
        if(i) cout << " ";
        cout << A[i];
    }
    cout << endl;
    cout << sw << endl;

    return 0;
}


Measured memory_bytes: 3120
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb(in,tmp) in.push_back(tmp)
#define all(in) in.begin(),in.end()
#define PI acos(-1)
using namespace std;
int main(){
  int n;
  while(cin>>n,n){
    int sum=0;
    rep(i,n/4){
      int tmp;
      cin>>tmp;
      sum+=tmp;
    }
    cout<<sum<<endl;
  }

}

Measured memory_bytes: 1160
#include <string>
#include <iostream>
#include <set>

int main() {
  std::set<std::string> count;
  std::string s;
  int n;
  std::cin >> n;
  for (int i = 0; i < n; ++i) {
    std::cin >> s; 
    count.emplace(s);
  }
  std::cout << count.size() << std::endl;
  return 0;
}


Measured memory_bytes: 19232