akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
using namespace std;
#define MAX 120
typedef long long ll;

int data,a[4],k=3,ans[4];
bool flag=true;

void solve(int count,int num){
  if(count==4){
    if(num==0 && flag){
      flag=false;

      for(int i=0;i<3;i++){
        cout<<a[i];
        if(ans[i]==1) cout<<"+";
        else cout<<"-";
      }
      cout<<a[3]<<"=7"<<endl;
      return;
    }else return;
  }
  ans[count-1]=1;
  solve(count+1,num-a[count]);
  ans[count-1]=0;
  solve(count+1,num+a[count]);
}

int main(){
  cin>>data;
  while(data!=0){
    a[k--]=data%10;
    data/=10;
  }
  solve(1,7-a[0]);
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    int N, W;   cin >> N >> W;
    int *v = new int[N], *w = new int[N];

    for (int i = 0; i < N; i++)
        cin >> v[i] >> i[w];

    int *dp = new int[W+1];
    for (int i = 0; i <= W; i++)
        dp[i] = 0;

    for (int i = 0; i < N; i++) {
        for (int j = 0; j <= W; j++) {
            if (j >= w[i])
                dp[j] = max(dp[j-w[i]]+v[i], dp[j]);
        }
    }

    cout << dp[W] << endl;

    return 0;
}



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

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		ArrayList<ArrayDeque<Integer>> que = new ArrayList<ArrayDeque<Integer>>();

		int n = in.nextInt(), loop = in.nextInt();
		for(int i = 0; i < n ; i++) {
			ArrayDeque<Integer> q = new ArrayDeque<>();
			que.add(q);
		}

		for(int i = 0; i < loop; i++) {
			int odr = Integer.parseInt(in.next()), index = Integer.parseInt(in.next());

			switch(odr) {
				case 0:
					que.get(index).add(Integer.parseInt(in.next()));
					break;

				case 1:
					if(!que.get(index).isEmpty()) {
						out.println(que.get(index).peek());
					}
					break;

				case 2:
					if(!que.get(index).isEmpty()) {
						que.get(index).remove();
					}
					break;
			}
		}
		out.flush();
		in.close();

	}

}





Measured memory_bytes: 108324
n = int(input())
l = list(map(int, input().split()))
l.sort()

from bisect import bisect_left
ans = 0
for i in range(n):
  for j in range(i+1, n):
    t = l[i]+l[j]
    idx = bisect_left(l, t)
    ans += max(0, idx-j-1)
print(ans)

Measured memory_bytes: 3188
n,m=map(int,input().split())
x=[int(i) for i in input().split()]
if m==1 or n>m:
    print(0)
else:
    x=sorted(x)

    if n==1:
        print(x[-1]-x[0])
    else:

        xsa=[]
        for i in range(len(x)-1):
            xsa.append(x[i+1]-x[i])

        xsa=sorted(xsa)



        print(sum(xsa[0:(m-n)]))


Measured memory_bytes: 13840
import java.util.*;
public class Main {

	public static void main (String[] args){
	
		Scanner sc = new Scanner(System.in);
		
		String b = sc.next();
		
		switch (b) {
			case "A":
				System.out.println("T");
				break;
			case "T":
				System.out.println("A");
				break;
			case "C":
				System.out.println("G");
				break;
			case "G":
				System.out.println("C");
				break;
		}

	}
	
}

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

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()

#####Shorten#####
def DD(arg): return defaultdict(arg)


#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i])*n**i for i in range(len(str(X))))

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############

S = S()

d = DD(int)
for s in S:
  d[s] += 1
print(min(d["0"],d["1"])*2)

Measured memory_bytes: 39408
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <climits>
#include <stack>
#include <queue>
#include <set>
#include <cctype>
#include <bitset>
#include <type_traits>

#include <list>
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define YES(j) cout << (j ? "YES" : "NO") << endl;
#define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
#define yes(j) std::cout << (j ? "yes" : "no") << endl;

typedef long long ll;
int main(void)
{
    int d;
    ll g;
    cin >> d >> g;

    ll p[d + 1], c[d + 1];
    REP(i, d)
    {
        cin >> p[i + 1] >> c[i + 1];
    }

    ll ans = 1001001001;

    for (int x = 0; x < (1 << d); x++)
    {
        vector<ll> prob;
        ll cnt;
        ll score;

        REP(i, d)
        {
            if (((x >> i) & 1) == 1)
            {
                prob.push_back(i + 1);
            }
        }

        // 全部解く場合
        cnt = 0;
        score = 0;
        for (int i = 0; i < prob.size(); i++)
        {
            int num = prob[i];
            score += p[num] * (num)*100 + c[num];
            cnt += p[num];
        }
        if (score >= g)
            ans = min(ans, cnt);

        // 一つだけ全部解かない問題がある場合 i 全部は解かない問題
        for (int i = 0; i < prob.size(); i++)
        {
            score = 0;
            cnt = 0;

            // j すべて解く問題
            for (int j = 0; j < prob.size(); j++)
            {
                int num = prob[j];
                if (i == j)
                    continue;
                score += p[num] * (num)*100 + c[num];
                cnt += p[num];
            }

            ll diff = g - score;
            if (diff <= 0)
            {
                ans = min(ans, cnt);
            }
            else
            {
                int num = prob[i];
                ll singlescore = num * 100;
                ll amari = (diff + singlescore - 1) / singlescore;
                if (amari < p[num])
                    ans = min(ans, cnt + amari);
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
while 1:
    n=int(input())
    if n==0:break
    a=[int(input()),1]
    for i in range(n-1):
        b=int(input())
        if a[-2]==b:a[-1]+=1
        if i&1 and a[-2]!=b:a+=[b]+[1]
        elif a[-2]!=b:
            if len(a)>2:
                a[-3]+=a[-1]+1
                a=a[:-2]
            else:
                a[-2]=b
                a[-1]+=1
    print(sum(a[2*i+1] for i,x in enumerate(a[::2])if x==0))

Measured memory_bytes: 7716
import collections
import copy

H,W=map(int,input().split())
c=[]
for i in range(10):
    c.append(list(map(int,input().split())))
A=[]
for i in range(H):
    A += list(map(int,input().split()))
A=[a for a in A if a!=-1 and a!=1]
cnt=collections.Counter(A)

inf=1<<60
best_cost=inf
def walk(place, cost, history):
    global best_cost
    if cost==0:
        best_cost=inf
    if place==1:
        best_cost=min(best_cost,cost)
        return cost
    ret=inf
    for i in range(10):
        if i in history:
            continue
        if i == place:
            continue
        if cost+c[place][i]>=best_cost:
            continue
        history2 = copy.copy(history)
        history2 += [i]
        #print(place,i,history)
        ret=min(ret,walk(i,cost+c[place][i],history+[i]))
    return ret

ans=0
for k,v in cnt.items():
    ans+=v*walk(k,0,[])
print(ans)


Measured memory_bytes: 43736
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define override_rep(i, l, r, mes, ...) mes
#define rep1(i, n) for (int i = 0; i < n; i++)
#define rep2(i, l, r) for (int i = l; i < r; i++)
#define rep(...) override_rep(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)
using P = pair<int, int>;
template<typename T, typename U>
istream& operator>>(istream& in, pair<T, U>& p) {
    in >> p.first >> p.second;
    return in;
}

signed main(signed argc, char* argv[]) {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    const int MOD = 1e9+7;
    int n,c,k;
    cin>>n>>c>>k;
    vector<int> t(n);
    rep(i,n){
        cin>>t[i];
    }
    sort(t.begin(),t.end(),greater<>());
    int cnt=0,before=5*1e9,ans=0;
    rep(i,n){
        if(t[i]+k<before||cnt+1>c){
            cnt=1;
            before=t[i];
            ans++;
        }
        else cnt++;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
const bool debug=false;
#define DEBUG if(debug==true)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
ll n,m;
ll mod = 1000000007;
int main(void) {
    cin >> n >> m; 
    ll dp[100005]={};
    rep(i,m){
        int tmp;
        cin >> tmp;
        dp[tmp]=-1;
    }
    dp[0]=1;
    rep(i,n){
        if(dp[i]!=-1){
            if(dp[i+2]!=-1){
                dp[i+2]+=dp[i];
                dp[i+2]%=mod;
            }
            if(dp[i+1]!=-1){
                dp[i+1]+=dp[i];
                dp[i+1]%=mod;
            }
        }
    }
    cout << dp[n] << endl;
    return 0;
}


Measured memory_bytes: 1024
import java.io.OutputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.PrintWriter;
    import java.util.StringTokenizer;
    import java.io.IOException;
    import java.io.BufferedReader;
    import java.io.InputStreamReader;
    import java.io.InputStream;
     

    public class Main {
        public static void main(String[] args) {
            InputStream inputStream = System.in;
            OutputStream outputStream = System.out;
            InputReader in = new InputReader(inputStream);
            PrintWriter out = new PrintWriter(outputStream);
            TaskA solver = new TaskA();
            solver.solve(1, in, out);
            out.close();
        }
     
        static class TaskA {
            public void solve(int testNumber, InputReader in, PrintWriter out) {
                int a = in.nextInt();
                int b = in.nextInt();
                if (a <= 0 && b >= 0) {
                    out.println("Zero");
                } else if (a > 0 || (b - a + 1) % 2 == 0) {
                    out.println("Positive");
                } else {
                    out.println("Negative");
                }
            }
     
        }
     
        static class InputReader {
            public BufferedReader reader;
            public StringTokenizer tokenizer;
     
            public InputReader(InputStream stream) {
                reader = new BufferedReader(new InputStreamReader(stream), 32768);
                tokenizer = null;
            }
     
            public String next() {
                while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                    try {
                        tokenizer = new StringTokenizer(reader.readLine());
                    } catch (IOException e) {
                        throw new RuntimeException(e);
                    }
                }
                return tokenizer.nextToken();
            }
     
            public int nextInt() {
                return Integer.parseInt(next());
            }
     
        }
    }
     

Measured memory_bytes: 8276
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2048;
struct Node {int v, nxt;} G[maxn << 1];
int head[maxn], cnt = 1;
void ins(int u, int v) {G[cnt] = (Node) {v, head[u]}; head[u] = cnt++;}
int dep[maxn];
void dfs(int x, int fa) {
	for (int i = head[x]; i; i = G[i].nxt) {
		int v = G[i].v;
		if(v == fa) continue;
		dep[v] = dep[x] + 1;
		dfs(v, x);
	}
}
struct data {int u, v;} e[maxn << 1];
int main() {
	int n, k;
	scanf("%d%d", &n, &k);
	for (int i = 1; i < n; ++i) {
		int u, v; scanf("%d%d", &u, &v);
		e[i].u = u; e[i].v = v;
		ins(u, v); ins(v, u);
	}
	int ans = 0x3f3f3f3f;
	if((k & 1) == 0) {
		int res = 0;
		for (int i = 1; i <= n; ++i) {
			res = dep[i] = 0; dfs(i, i);
			for (int j = 1; j <= n; ++j) if(dep[j] > (k >> 1)) ++res;
			ans = min(ans, res);
		}
	} 
	else {
		int res = 0;
		for (int i = 1; i < n; ++i) {
			dep[e[i].u] = dep[e[i].v] = res = 0;
			dfs(e[i].v, e[i].u); dfs(e[i].u, e[i].v);
			for (int j = 1; j <= n; ++j) if(dep[j] > (k >> 1)) ++res;
			ans = min(ans, res);
		}
	}
	printf("%d\n", ans);
	return 0;
}

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

signed main(){
  
  int n;
  cin>>n;
  
  if( n % 2 ) cout<<0<<endl;
  else{
    int ans = 0, num = 10;
    while(1){
      ans += n / num;
      if( num > n / 5.0 ) break;
      num *= 5;
    }
    cout<<ans<<endl;
  }
  
  return 0;
}


Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};

#[allow(unused_imports)]
use std::io::Write;

fn main() {
    input!{
      r: i64,
      d: i64,
      mut x: i64,
    }
    for i in 0..10 {
        x = r * x - d;
        println!("{}", x);
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#include <iostream>
#include<map>
#include <algorithm>
#include <vector>
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int n, k;
  cin >> n >> k;
    int count = 0;
  while (n /= k) {
    count++;
  } 
   cout << count + 1 << endl;
}




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

using namespace std;

int maxHappines(vector<vector<int> >& activites){
  int n = activites.size();
  
  vector<vector<int> > dp(n, vector<int>(3, 0));

  dp[0][0] = activites[0][0];
  dp[0][1] = activites[0][1];
  dp[0][2] = activites[0][2];

  for(int i = 1; i < n; i++){
    dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + activites[i][0];
    dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + activites[i][1];
    dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + activites[i][2];
  }
 
  return max({dp[n - 1][0], dp[n - 1][1], dp[n - 1][2]});
}

int main(){

  int n;
  cin >> n;
  vector<vector<int> > activites(n, vector<int>(3));
  for(int i = 0; i < n; i++){
  	for(int j = 0; j < 3; j++){
      cin >> activites[i][j];
    }
  }

  cout << maxHappines(activites) << endl;
  return 0;
}


Measured memory_bytes: 11136
#include<iostream>

using namespace std;

int K, A,B;
int main(){
    cin >> K >> A >> B;
    for(int i=A;i<B+1;i++){
        if(i%K==0){
            cout << "OK";
            return 0;
        }
    }
    cout << "NG";
    return 0;

}

Measured memory_bytes: 3132
#include <bits/stdc++.h>
#include <iostream>
typedef long long ll;
#define rep(i,a,b) for(ll i =a ;i <= b;i++)
#define per(i,a,b) for(ll i =a ;i >= b;i--)
using namespace std;
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;
 


int main()
{
	//ifstream cin("input.txt");
	int n,m,c;
	cin>>n>>m>>c;
	ll sum, count = 0,x;

	vi b(m);
	rep(i,0,m-1)
		cin>>b[i];

	rep(i,0,n-1){
		sum = 0;	
		rep(j,0, m -1)
			{
				cin>>x;
				sum += x*b[j];
			}
			sum +=c;

		if(sum > 0)
			count++;	
	}
	cout<<count;
		
	
}


Measured memory_bytes: 3528
#include<iostream>
#include<string.h>
using namespace std;
int main(){
	int W,H;
	int b[100][100];
	char cloud[100][100];
	int cunt,j,n,s,i;
	cin>>H>>W;
	for(i=0;i<H;i++){
		for(s=0;s<W;s++){
			cin>>cloud[i][s];
		}
	}
	for(i=0;i<H;i++){
		for(s=0;s<W;s++){
			if(cloud[i][s]=='c'){
				b[i][s]=0;
			}
			else{
				b[i][s]=-1;
			}
		}
	}
	for(i=0;i<H;i++){
		for(s=1;s<W;s++){
			if(cloud[i][s]=='.'&&b[i][s-1]==0){
					b[i][s]=1;
			}
		}
	}
	for(i=0;i<H;i++){
		for(s=1;s<W;s++){
				if(cloud[i][s]=='.'&&b[i][s-1]>=1){
					b[i][s]=b[i][s-1]+1;
			}
		}
	}
	for(i=0;i<H;i++){
		for(s=0;s<W;s++){
			cout<<b[i][s];
			if(s<W-1){
				cout<<" ";
			}
		}
		cout<<endl;
	}
	return 0;
}

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

using namespace std;

int main() {
    int r, g, b;
    cin >> r >> g >> b;

    if ((10 * g + b) % 4 == 0) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    return 0;
}


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

typedef tuple<int,int,int> P;

const int INF = 1e9;

int N, M, d[100005][3];
vector<int> G[100005];

int bfs(int s, int t){
  
  for(int i=0;i<N;i++)
    for(int j=0;j<3;j++) d[i][j] = INF;
  
  queue<P> Q;
  Q.push(P(s,0,0));
  d[s][0] = 0;
  
  while(!Q.empty()){
    
    int node, idx, cost;
    
    tie(node,idx,cost) = Q.front(), Q.pop();

    if( node == t && idx == 0 ) return cost;
    
    for(int nnode : G[node]){
      
      int nidx = ( idx + 1 ) % 3;
      int ncost = cost;

      if( idx == 2 ) ncost++;
      
      if( d[nnode][nidx] > ncost ){
	
	d[nnode][nidx] = ncost;

	Q.push(P(nnode,nidx,ncost));
	
      }
      
    }
    
  }
  
  return -1;
}

signed main(){
  
  cin>>N>>M;
  
  for(int i=0;i<M;i++){
    int u, v;
    cin>>u>>v;
    G[u-1].push_back(v-1);
  }
  
  int s, t;
  cin>>s>>t;
  
  s--, t--;
  
  cout<<bfs(s,t)<<endl;
  
  return 0;
}


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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

using ll = long long;
using ld = long double;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;

bool check(vector<int> a, vector<int> b) {
  bool ok = true;
  rep (i, a.size()) {
	if (a[i] != b[i]) ok = false;
  }

  return ok;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
	int n;
	cin >> n;
	vector<int> p(n), q(n), a(n);
	rep (i, n) cin >> p[i], a[i] = i + 1;
	rep (i, n) cin >> q[i];
	int np = -1, nq = -1, cnt = 0;
	do {
	  if (np == -1 && check(a, p)) np = cnt;
	  if (nq == -1 && check(a, q)) nq = cnt;
	  cnt++;
	} while (next_permutation(a.begin(), a.end()));
	cout << abs(np - nq) << endl;
	
    return 0;
}



Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;

#include <vector>

struct UnionFind
{
    vector<int> data;

    UnionFind(int sz)
    {
        data.assign(sz, -1);
    }

    bool unite(int x, int y)
    {
        x = root(x), y = root(y);
        if (x == y)
            return false;
        if (data[x] > data[y])
            swap(x, y);
        data[x] += data[y];
        data[y] = x;
        return true;
    }

    int root(int k)
    {
        if (data[k] < 0)
            return k;
        data[k] = root(data[k]);
        return data[k];
    }

    int size(int k)
    {
        return (-data[root(k)]);
    }

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

struct BipartiteGraph : UnionFind
{
    vector<int> color;

    BipartiteGraph(int N) : color(2 * N, -1), UnionFind(2 * N) {}

    /*
    color u, v by same color ->  unite(u, v) && unite(u + N, v + N)
    color u, v by different color -> unite(u + N, v) && unite(u, v + N)
    */

    bool BG_unite(int u, int v, bool same)
    {
        int N = ((int)color.size()) / 2;
        if (same == true)
        {
            unite(u, v);
            unite(u + N, v + N);
        }
        else
        {
            unite(u + N, v);
            unite(u, v + N);
        }
    }

    // 0, 1, ..., v - 1 -> left; v, v + 1, ..., 2 * v - 1 -> right;
    bool BG_coloring()
    {
        int N = ((int)color.size()) / 2;
        for (int i = 0; i < N; i++)
        {
            int s = root(i), t = root(i + N);
            if (s == t)
                return false;
            if (color[s] < 0)
                color[s] = 0, color[t] = 1;
        }
        return true;
    }

    //return k's color
    bool operator[](int v)
    {
        return (bool)(color[root(v)]);
    }
};

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

    for (int i = 0; i < M; i++)
    {
        int a, b;
        cin >> a >> b;
        a--, b--;
        bg.BG_unite(a, b, 0);
    }

    if (bg.BG_coloring() == false)
    {
        ll a = N, b = M;
        cout << a * (a - 1) / 2 - b << endl;
    }
    else
    {
        map<bool, int> mp;
        for (int i = 0; i < N; i++)
        {
            mp[bg[i]]++;
        }
        cout << (ll)mp[false] * (ll)mp[true] - (ll)M << endl;
    }
}


Measured memory_bytes: 1920
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cassert>
#include <iterator>

#define ios ios_base::sync_with_stdio(0), cout.tie(0), cin.tie(0);
#define S second
#define F first
#define pb push_back
#define nl '\n'
#define mp make_pair
#define NL cout << '\n';
#define EX exit(0)
#define all(s) s.begin(), s.end()
#define FOR(i, start, finish, k) for(int i = start; i <= finish; i += k)

const long long MXN = 1e5 + 100;
const long long MNN = 3e2 + 10;
const long long MOD = 998244353;
const long long INF = 1e18;
const long long OO = 1e9 + 500;

typedef long long llong;
typedef unsigned long long ullong;

using namespace std;

long long n, m, a[302][302], viz[302], cnt[302], ans = 1e18;
queue<long long> q[302];

void func(int k){
	memset(cnt, 0, sizeof(cnt));
	long long maxx = 0, x = 0;
	for(int i = 1; i <= n; i++) {
		if(q[i].size() == 0)
      continue;
		while(viz[q[i].front()]){
			q[i].pop();
		}
		cnt[q[i].front()]++;
		if(maxx < cnt[q[i].front()]){
			maxx = max(maxx, cnt[q[i].front()]);
			x = q[i].front();
		}
	}
	if(maxx == 1){
		cout << 1;
		exit(0);
	}
	viz[x] = 1;
	ans = min(ans, maxx);
	if(k == 1)
    return;
	return func(k - 1);
}

int main()
{
  cin >> n >> m;
	set<int> v;
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= m; j++){
			cin >> a[i][j];
			q[i].push(a[i][j]);
		}
	}
	func(m);
	cout << ans;
	return 0;
}


Measured memory_bytes: 1792
s = str(input())
ans = 0
if(s[0]=="R"):
  if(s[1]=="R"):
    if(s[2]=="R"):
      ans = 3
    else:
      ans = 2
  else:
    ans = 1
else:
  if(s[1]=="R"):
    if(s[2]=="R"):
      ans = 2
    else:
      ans = 1
  else:
    if(s[2]=="R"):
      ans = 1
    else:
      ans = 0
print(ans)


Measured memory_bytes: 9064
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
const int maxn = 1<<17, rt = 1<<10;
int n, a[maxn][3];
int id(int x) {
	if(a[x][0] + 1 == a[x][1] && a[x][1] + 1 == a[x][2]) return a[x][2]/3;
	if(a[x][0] - 1 == a[x][1] && a[x][1] - 1 == a[x][2]) return -a[x][0]/3;
	return -(1<<30);
}
struct fenwick {
	int a[maxn], n;
	void init(int n) {
		this->n = n;
		memset(a, 0, sizeof a);
	}
	void add(int i) {
		for(; i <= n; i += i&-i) a[i] ^= 1;
	}
	int get(int i) {
		int r = 0;
		for(; i; i -= i&-i) r ^= a[i];
		return r;
	}
};

int count(vi a) {
	fenwick f;
	f.init(2*a.size() + 2);
	int ans = 0, t = 0;
	for(auto i : a) {
		ans ^= f.get(i)^t;
		f.add(i);
		t ^= 1;
	}
	return ans;
}

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin >> n;
	for(int i = 0; i < 3; i++)
		for(int j = 1; j <= n; j++)
			cin >> a[j][i];
	map<int, int> cnt[2];
	vi p[2];
	int sgn[2] = {0, 0};
	for(int i = 1; i <= n; i++) {
		sgn[i&1] ^= id(i) < 0;
		p[i&1].push_back(abs(id(i)));
		cnt[i&1][abs(id(i))]++;
		if(id(i) == -(1<<30)) return cout << "No\n", 0;
	}
	sgn[0] ^= count(p[1]);
	sgn[1] ^= count(p[0]);
	for(int i = 1; i <= n; i++) if(cnt[i&1][i] != 1 || sgn[0] || sgn[1]) return cout << "No\n", 0;
	cout << "Yes\n";
}


Measured memory_bytes: 7288
//おまじない
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#define INF 1e9+7
#define rep(i,m,n) for(int i=m;i<n;i++)
#define mrep(i,m,n) for(int i=m;i>n;i--)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;


//(int)'a'は97 (int)'A'は65 (int)'1'は49
//おまじない

int main() {

	int n;
	ll num[100000] = { 0 };
	ll ans1 = 0, ans2 = 0;
	ll pm = 1;
	ll sum = 0;

	cin >> n;

	rep(i, 0, n) {
		cin >> num[i];
	}

	pm = 1;
	
	rep(i, 0, n) {
		sum += num[i];
		pm = pm * (-1);//pmと符号を同じにする
		if (sum*pm < 0) {
			ans1 += abs(pm - sum);
			sum = pm;
		}
		else if (sum == 0) {
			ans1 += 1;
			sum = pm;
		}
	}


	pm = -1;
	sum = 0;

	rep(i, 0, n) {
		sum += num[i];
		pm = pm * (-1);//pmと符号を同じにする
		if (sum*pm < 0) {
			ans2 += abs(pm -sum);
			sum = pm;
		}
		else if(sum==0){
			ans2 += 1;
			sum = pm;
		}
	}

	cout << min(ans1, ans2) << endl;

	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll int64_t
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};
int dp[2][111111][111];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    dp[0][0][0] = 1;
    string s;cin>>s;
    int n,d;
    cin>>d;
    n = s.size();
    REP(i,n){
        REP(j,10){
            REP(k,d){
                add(dp[1][i+1][(k+j)%d],dp[1][i][k]);
                if(j>s[i]-'0') continue;
                else if(j < s[i] - '0') add(dp[1][i+1][(k+j)%d],dp[0][i][k]);
                else add(dp[0][i+1][(k+j)%d],dp[0][i][k]);
            }
        }
    }
    cout<<(dp[0][n][0]+dp[1][n][0]-1+MOD)%MOD<<endl;
}

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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {

    string s, t; cin >> s >> t;

    for (int i = 0; i < s.length(); ++i) {
        if (s[i] != t[i]) {
            puts("No");
            return 0;
        }
    }

    puts("Yes");
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long int
#define fo(i,n) for(i=0;i<n;i++)
#define pb push_back
#define mp make_pair
#define endl "\n"
#define MAXN 1000002
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
const ll mod=1e9+7;

void solve()
{
  int n,k,d,x;
  cin>>n>>k;
  //unordered_map<int,int> um;
  set<int> S;
  for(int i=0;i<k;i++)
  {
    cin>>d;
    for(int j=0;j<d;j++)
    {
      cin>>x;
      S.insert(x);
    }
  }
  int ans=n-S.size();
  cout<<ans<<endl;
}

int main()
{
  fastio
  solve();
}


Measured memory_bytes: 3656
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    public static void main(String args[]) {
        FastReader sc = new FastReader();
        int n = sc.nextInt();
        List<Integer> as = new ArrayList<>();
        for (int i = 0; i < n; i++) as.add(sc.nextInt());
        int max = Collections.max(as);
        List<Double> bs = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            bs.add(Math.abs(1.0 * max / 2 - as.get(i)));
        }
        double min = Double.MAX_VALUE;
        int minIndex = 0;
        for (int i = 0; i < n; i++) {
            if (bs.get(i) < min && as.get(i) != max) {
                min = bs.get(i);
                minIndex = i;
            }
        }
        System.out.printf("%d %d\n", max, as.get(minIndex));
    }

    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}


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

#define INF 1e9
#define llINF 1e18
#define MOD 1e9+7
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long

using namespace std;
int main(){
  int n,w;
  cin>>n>>w;
  vector<vector<ll> >value(5);
  ll a,b;cin>>a>>b;
  value[0].pb(b);
  for(int i=1;i<n;i++){
    ll c,d;cin>>c>>d;
    value[c-a].pb(d);
  }
  for(int i=0;i<4;i++){
    sort(value[i].begin(),value[i].end(),greater<ll>());
  }
  ll a1[4][110]={};
  for(int i=0;i<4;i++)
    for(int j=1;j<=value[i].size();j++)
      a1[i][j]=a1[i][j-1]+value[i][j-1];
  ll ans=0;
  for(int i=0;i<=value[0].size();i++){
    for(int j=0;j<=value[1].size();j++){
      for(int k=0;k<=value[2].size();k++){
	for(int l=0;l<=value[3].size();l++){
	  if((i+j+k+l)*a+j+k*2+l*3<=w){
	    ans=max(ans,a1[0][i]+a1[1][j]+a1[2][k]+a1[3][l]);
	  }
	}
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}


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

int main(void) {
    int N, M, X, Y;
    int x[100], y[100];
    std::cin >> N >> M >> X >> Y;
    for (int i=0; i<N; i++) std::cin >> x[i];
    for (int i=0; i<M; i++) std::cin >> y[i];

    std::sort(x, x+N);
    std::sort(y, y+M);
    if (x[N-1] >= Y || y[0] <= X) {
        std::cout << "War" << std::endl;
    } else if (x[N-1] < y[0]) {
        std::cout << "No War" << std::endl;
    } else {
        std::cout << "War" << std::endl;
    }

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();
		long M = sc.nextLong();
		sc.close();
		if(N >= M / 2) {
			System.out.println(M / 2);
		}else {
			long res = M - 2 * N;
			long ans = N + res / 4;
			System.out.println(ans);
		}
	}
}

Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include <tuple>
using namespace std;

int main() {

  int n;
  cin>>n;

  vector<pair<int,int>> d(n);

  for(int i=0;i<n;i++)
    cin>>d[i].first>>d[i].second;


  int cnt=0;
  for(int i=0;i<d.size();i++){
    if(d[i].first == d[i].second)
      cnt+=1;
    else
      cnt=0;
    if(3 <= cnt){
      cout<<"Yes\n";
      return 0;
    }
  }
  cout<<"No\n";

  return 0;
}


Measured memory_bytes: 3112
//#include <bits/stdc++.h>
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }


int
main(void){  
  int n;
  cin >> n;
  ll ans = 0LL;
  REP(i, n+1) ans += i;

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


Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<string.h>
#include<vector>
#include<algorithm>
#include<iomanip>
using namespace std;

int main(){
	string s;
	cin >> s;
	for(int i=0;i<s.size();i=i+2){
		cout << s[i];
	}
	cout << endl;
	return 0;
}

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

using namespace std;

#define MODULE 1000000007
#define MP make_pair

template<class T,class U>inline void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>inline void chmax(T &t,U f){if(t<f)t=f;}

typedef pair<int, int> P;
typedef long long LL;
const int INF = INT_MAX / 2;    //int_max->2*e+9
const int MAXN = 100001;
/*struct edge {
    edge(int to, int cost) : to(to), cost(cost) {}
    int to, cost;
};
vector<int> graph[MAXN];*/

//-----Template---------
unordered_map<char,int> counter;
typedef pair<int,char> pic;
set<pic,std::greater<pic> > st;//mapは<A,B>のpairでソートされる
vector<set<pic>::iterator> vec;
string s;   int N,K;
int main(){
    ios::sync_with_stdio(false);
    cin>>N>>K;
    for (int i = 0; i < N; ++i) {
        cin>>s;
        counter[s[0]]+=1;
    }
    for(auto it=counter.begin();it!=counter.end();it++){
        st.insert(make_pair(it->second,it->first));
    }

    int res=0;
    while (!st.empty()){
        for(set<pic>::iterator it=st.begin();it!=st.end();it++){
            vec.push_back(it);
            if(vec.size()==K) {
                res++;
                break;
            }
        }
        for(auto it : vec){//取り出した値を上書き
            if(((it->first)-1)!=0){//減らす
                pic p=make_pair(it->first,it->second);
                st.erase(p);
                st.insert(make_pair(p.first-1,p.second));
            }else{                  //消す
                st.erase(make_pair(it->first,it->second));
            }
        }
        vec.clear();
    }

    cout<<res<<endl;
}

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

using namespace std;

double toRad(double x) {
    return x * (acos(-1) / 180.);
}

double toDeg(double x) {
    return x * (180. / acos(-1));
}

int main() {
//    ios::sync_with_stdio(false);
//    cin.tie(nullptr);
    int a, b, x;
    cin >> a >> b >> x;
    double angle = toDeg(atan2(b, a));
    double low = 0., high = 90.;
    for (int i = 0; i < 200; i++) {
        double mid = (low + high) / 2.;
        if (mid < angle) {
            double opp = tan(toRad(mid)) * a;
            double trArea = opp * a / 2.;
            if ((a * b - trArea) * a >= x) {
                low = mid;
            } else {
                high = mid;
            }
        } else {
            double opp = tan(toRad(90. - mid)) * b;
            double trArea = opp * b / 2.;
            if (trArea * a >= x) {
                low = mid;
            } else {
                high = mid;
            }
        }
    }
    cout << fixed << setprecision(10) << low;
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
 
using namespace std;
#define sz(x) (int)(x).size()
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define ll long long
const int N=3e5+5;
 
 

int main()
{	
	//#ifndef ONLINE_JUDGE
		//freopen("tst.txt","r",stdin);
	//#endif
 	
 	int x;
 	scanf("%d",&x);
 	for(int i=1;;i++){
 		if(((i-1)*i/2)>=x-i || ((i-1)*i/2)>=x+i){
 			return !printf("%d\n",i );
 		}
 	}
 	
}
 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001;

ll N,A, ans = INF;

ll getProd(vl cur) {
    ll z = 1;
    for (ll i: cur) z *= i;
    return z;
}

void test(int num) {
    if (num == 0) {
        ans = min(ans,N);
        return;
    }
    ll ret = A*num;
    vl cur(num+1);
    for (int i = 0; ; i++) {
        if (getProd(cur) >= N) {
            ans = min(ans,ret);
            return;
        }
        cur[i%(num+1)] ++;
        ret ++;
    }
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> N >> A;
    F0R(i,60) test(i);
    cout << ans;
}

// read the question correctly (is y a vowel? what are the exact constraints?)
// look out for SPECIAL CASES (n=1?) and overflow (ll vs int?) ARRAY OUT OF BOUNDSS

Measured memory_bytes: 256
#include <utility>
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
#include <map>
#include <set>
#include <list>
#include <string>
#define REP(i, n) for (int i = 0; i < n; i++)
using namespace std;

typedef long long ll;
typedef pair<ll, ll> Pll;

ll ookii = 1000000007;

int main()
{
    int N, M;
    cin >> N >> M;
    int a[N];
    REP(i, N)
    {
        a[i] = 0;
    }
    REP(i, M)
    {
        int t;
        cin >> t;
        a[t] = 1;
    }
    ll ret = 0;
    ll ret1 = 1;
    ll ret2 = 0;
    for (int i = 1; i < N; i++)
    {

        ret = ret2 + ret1;

        if (a[i] == 1)
            ret = 0;

        ret %= ookii;
        ret2 = ret1;
        ret1 = ret;
    }

    cout << (ret1 + ret2) % ookii << endl;
}

void cheatsheet()
{
    // loop
    // vector<int> vec(10);
    vector<int> vecloop;
    REP(i, 10)
    {
        vecloop.push_back(i);
    }

    // swap
    int a = 1;
    int b = 5;
    swap(a, b); // -> a = 5, b = 1

    // sort
    int arr[] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
    sort(arr, arr + 9, greater<int>()); // 9 8 7 6 5 4 3 2 1

    // lower
    vector<int> vec(arr, end(arr));
    sort(vec.begin(), vec.end());
    cout << lower_bound(vec.begin(), vec.end(), 2)[0]; // 2

    // map
    map<Pll, ll> m;
    m[Pll(10, 100)] = 100;
}

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

long long rec(int n, long long x) {
    if (n == 0) return 1;
    long long len = (1LL<<(n+1)) - 3;
    long long num = (1LL<<n) - 1;
    if (x == 1) return 0;
    else if (x <= len + 1) return rec(n-1, x-1);
    else if (x == len + 2) return num + 1;
    else if (x <= (len + 1) * 2) return num + 1 + rec(n-1, x-len-2);
    else return num * 2 + 1;
}

int main() {
    int N; long long X;
    cin >> N >> X;
    cout << rec(N, X) << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#define MAX 2000001
#define I (1<<30)

long long A[MAX];
int n;

void maxHeapify(int);
void insert(int);
void increasekey(int,int);
int extract();


int main(){
  int i,key;
  char com[10];

  while(1){
    scanf("%s",com);
    if(strcmp(com,"end")==0) break;
    if(strcmp(com,"insert")==0){
      scanf("%d",&key);
      insert(key);
    }
    else{
      printf("%d\n",extract());
    }
  }
  return 0;
}

void maxHeapify(int i){
  int large;
  int temp;

  if(2*i<=n && A[2*i]>A[i]) large=2*i;
  else large=i;
  if(2*i+1<=n && A[2*i+1]>A[large]) large=2*i+1;

  if(large!=i){
    temp=A[i];
    A[i]=A[large];
    A[large]=temp;
    maxHeapify(large);
  }
}

void insert(int key){
  n++;
  A[n]=-I;
  increasekey(n,key);
}

void increasekey(int i,int key){
  int temp;
  if(key<A[i]) return;
  A[i]=key;
  while(i>1 && A[i/2]<A[i]){
    temp=A[i/2];
    A[i/2]=A[i];
    A[i]=temp;
    i=i/2;
  }
}

int extract(){
  int large;
  if(n<1) return -I;
  large=A[1];
  A[1]=A[n--];
  maxHeapify(1);
  return large;
}

Measured memory_bytes: 8784
import java.util.Arrays;
import java.util.Scanner;
import static java.lang.Math.*;
public class Main {
	static boolean check(String a,String b) {
		if(a.length() != b.length())return false;
		for(int i = 0;i < a.length();i ++) {
			if(a.charAt(i) == b.charAt(0) && (a.substring(i, a.length()) + a.substring(0, i)).equals(b)) {
				return true;
			}
		}
		return false;
	}
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int d;
		int ans = 0;
		for(int i = 0;i < n;i ++) {
			d = in.nextInt();
			ans += d - 1;
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 25808
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<queue>
#include<cmath>
#include<algorithm>
#include<iomanip>
#include<functional>
#include<set>
#include<map>
#include<utility>
#define ul unsigned long long int
#define ll long long int
#define MAX 1000000+1
using namespace std;
#define F first
#define S second
#define pi 2*acos(0.0)
#define PB push_back
#define Pp push
#define LSTAGE 1
int arr[200010];
ll bfs(vector<int> a[])
{
    queue<int>v;
    v.push(1);
    int t;
    arr[1] = 0;
    int x;
    while(v.size())
    {
        t = v.front();
        v.pop();
        if(arr[t]==2)
            return 1;
        for(int i= 0; i < a[t].size(); i++)
        {
            x = a[t][i];
            if(arr[x]==-1)
            {
                v.push(x);
                arr[x] = arr[t]+1;

            }
        }

    }
    return 0;

}


int main()
{
    ll n, r, t, f, s;
    t = f = s = 0;
    cin >> n;
    for(ll i =0; i< n; i++)
    {
        cin >> r;
        if(r%4==0)
            f++;
        else if(r%2==0)
            t++;
        else
            s++;
    }
    if(t)
        s++;
    if((f+s)/2 <= f)
        cout <<"Yes";
    else
        cout << "No";


    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define MOD 1000000007
#define INF (1<<29)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;

string str;
bool ng[216000];

int main(){
    cin >> str;
    int n = str.size();
    int ans = n;
    for(int i = 0;i < n - 1;i++){
        ng[i] = str[i] == str[i+1];
    }
    for(int i = 0;i < n-1;i++){
        if(ng[i]){
            ans--;
            if(i+1 < n-1)ng[i+1] = false;
            if(i+2 < n-1)ng[i+2] = false;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 772
#include <bits/stdc++.h>
using namespace std;
typedef   long long ll;
typedef   unsigned long long ull ;
typedef   double dll ;
#define   mp make_pair
#define   pb push_back
#define   ff first 
#define   ss second
#define   IOS ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define   endl "\n" 
#define   pll pair<ll, ll>
#define   all(x) x.begin(), x.end()
#define   vll vector<ll> 

int main()
{
    IOS
    ll n;
    cin>>n;
    map<string,int> mp;
    mp["AC"]=0;
    mp["WA"]=0;
    mp["TLE"]=0;
    mp["RE"]=0;
    for(int i=0;i<n;i++)
    {
        string s;
        cin>>s;
        mp[s]++;
    }
    cout<<"AC x "<<mp["AC"]<<endl;
    cout<<"WA x "<<mp["WA"]<<endl;
    cout<<"TLE x "<<mp["TLE"]<<endl;
    cout<<"RE x "<<mp["RE"]<<endl;
    return 0;
}

Measured memory_bytes: 3664