akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

const int MOD = 1e9 + 7;
const int INF32 = 1<<30;
const ll INF64 = 1LL<<60;

int main()
{
	// #ifndef ONLINE_JUDGE
	// freopen(".in.txt", "r", stdin);
	// freopen(".out.txt", "w", stdout);
	// #endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll a, b; cin >> a >> b;
	ll g = __gcd(a, b);
	int ans = 0;
	for(ll i = 1; i <= sqrtl(g); i++) if(!(g % i))
	{
		bool p = 1;
		for(ll j = 2; j <= sqrtl(i); j++) if(!(i % j))
		{
			p = 0;
			break;
		}
		if(p) ans++;
		if(g/i == i) break;
		p = 1;
		for(ll j = 2; j <= sqrtl(g/i); j++) if(!(g/i % j))
		{
			p = 0;
			break;
		}
		if(p) ans++;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int i,a[5],j,temp;
	int time = 0;
	
	for(i = 0; i < 5; i++){
		scanf("%d",&a[i]);
	}
	
	int hosuu[5];
	
	
	//補数の計算
	
	for(i = 0; i < 5; i++){
		hosuu[i] = 10 - a[i]%10;
		if(hosuu[i] == 10){
			hosuu[i] = 0;
		}
	}
	
	//ソート
	for(i = 0; i < 5; i++){
		for(j = i + 1; j < 5; j++){
			if(hosuu[i] > hosuu[j]){
				temp = hosuu[i];
				hosuu[i] = hosuu[j];
				hosuu[j] = temp;
				temp = a[i];
				a[i] = a[j];
				a[j] = temp;								
			}
		}
	}
	
	//時間の計算
	
	for(i = 0; i < 5 ; i++){
		if(i != 4){
			time = time + a[i] + hosuu[i];
		}else{
			time = time + a[i]; 
		}
	}
	
	printf("%d",time);
	
	return 0;
}
	
	

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

#A
def A():
    a = LI()
    a.sort()
    a, b, c = a
    print(int(str(c)+str(b))+a)
    return

#B
def B():
    _, _, X, Y = LI()
    x = LI()
    y = LI()
    x.append(X)
    y.append(Y)
    x.sort()
    y.sort()
    print("No " * (x[-1] < y[0]) + "War")
    return

#C
def C():
    s = S()
    t = S()
    ds = defaultdict(int)
    dt = defaultdict(int)
    for i in range(len(s)):
        if ds[s[i]]:
            if ds[s[i]] == ord(t[i]):
                continue
            print("No")
            return
        if dt[t[i]]:
            if dt[t[i]] == ord(s[i]):
                continue
            print("No")
            return
        ds[s[i]] = ord(t[i])
        dt[t[i]] = ord(s[i])
    print("Yes")
    return

#D
def D():
    return

#Solve
if __name__ == '__main__':
    C()


Measured memory_bytes: 70732
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <stack>
#include <cmath>
#include <queue>
#include <numeric>

std::vector<std::vector<int> > path(8, std::vector<int>(8, 0));


int dfs(std::vector<long long> visited, int pos) {
	int ret = 0;

	if (std::accumulate(visited.begin(), visited.end(), 0) == visited.size()) {
		return 1;
	}

	for (size_t i = 0; i < visited.size(); i++)
	{
		if (path[pos][i] == 1 && visited[i] != 1) {
			visited[i] = 1;
			ret += dfs(visited, i);
			visited[i] = 0;
		}
	}
	return ret;
}

int main()
{
	long long n, m;

	std::cin >> n >> m;

	std::vector<long long> visited(n, 0);

	visited[0] = 1;

	for (size_t i = 0; i < m; i++)
	{
		int a, b;

		std::cin >> a >> b;

		path[a - 1][b - 1] = 1;
		path[b - 1][a - 1] = 1;
	}

	visited[0] = 1;

	std::cout << dfs(visited, 0) << std::endl;

	return 0;
}


Measured memory_bytes: 384
import Control.Applicative
import Control.Monad
import Control.Monad.ST
import qualified Data.ByteString as BS
import Data.Functor
import Data.Function
import Data.Monoid
import Data.Maybe
import Data.List
import qualified Data.Foldable as Foldable
import qualified Data.Set as Set
--import qualified Data.Sequence as Sequence
import Data.List.Split
import Data.Bits
import Data.Char
import Data.Ix
import Data.Ratio
import Data.Ord
import Data.Tuple
import Data.Array
--import Data.Array.Unboxed
--import Data.Array.IArray
import Data.Array.MArray
import Data.Array.IO
import Data.Array.ST
import Data.IORef
import Data.STRef
import GHC.ST
-- import System.IO.Unsafe

-- templete
readInt = read :: String -> Int
readInteger = read :: String -> Integer
readDouble = read :: String -> Double
getInt = readLn :: IO Int
getInts = map readInt . words <$> getLine
getInteger = readLn :: IO Integer
getIntegers = map readInteger . words <$> getLine
getDouble = readLn :: IO Double
getDoubles = map readDouble . words <$> getLine
sjoin :: (Show a) => [a] -> String
sjoin = unwords . map show
tjoin :: (Show a, Show b) => (a, b) -> String
tjoin (x, y) = show x ++ (' ' : show y)
cond :: a -> a -> Bool -> a
cond t f c = if c then t else f
apply2 :: (a -> a -> b) -> [a] -> b
apply2 f [x,y] = f x y
apply3 :: (a -> a -> a -> b) -> [a] -> b
apply3 f [x,y,z] = f x y z
apply4 :: (a -> a -> a -> a -> b) -> [a] -> b
apply4 f [x,y,z,w] = f x y z w
fnTuple :: (a -> b, a -> c) -> a -> (b, c)
fnTuple (f,g) a = (f a, g a)
replace :: (Eq a) => a -> a -> [a] -> [a]
replace x y = map (\z -> if z==x then y else z)
binMap :: (a -> a -> b) -> [a] -> [b]
binMap f (x:xs@(y:_)) = f x y : binMap f xs
binMap _ _ = []
splitRec :: Int -> [a] -> [[a]]
splitRec _ [] = []
splitRec n xs = let (y,ys) = splitAt n xs in y : splitRec n ys
infixl 7 `divCeil`
divCeil :: Integral a => a -> a -> a
x `divCeil` y = (x+y-1) `div` y
coverC :: Ord a => (a, a) -> a -> Bool
coverC (l,r) x = l<=x && x<=r
coverH :: Ord a => (a, a) -> a -> Bool
coverH (l,r) x = l<=x && x<r
ibsearch :: (Int -> Bool) -> (Int,Int) -> Int
ibsearch f (ok,ng) = if abs (ok-ng) <= 1 then ok else let mid = (ok + ng) `div` 2 in ibsearch f (if f mid then (mid,ng) else (ok,mid))
-- templete




main = getInts >>= putStrLn . cond "Open" "Close" . (\s -> s==[1,1,0] || s==[0,0,1])


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

int main () {
  int x, n, a, b, c, idx, ans = 0;
  int min = 100000;
  bool bb, bc = false;
  cin >> x >> n;
  if(n == 0) {
    ans = x;
  } else {
  vector<int> vec(n);
  for (int i = 0; i < n; i++) {
  	cin >> vec.at(i);
  }
  for (int j = 0; j < n; j++) {
  	a = abs(x - vec.at(j));
    if(a < min) {
      min = a;
      idx = j;
    }
  }
  for (int k = 0; k < n; k++){
    bb = false;
    bc = false;
    b = vec.at(idx) - k;
    c = vec.at(idx) + k;
    for (int h = 0; h < n; h++){
      if (b == vec.at(h)){
        bb = true;
      }
      if(c == vec.at(h)){
        bc = true;
      }
    }
   if(bb == 0){
    ans =  b;
     break;
   }
    if(bc == 0){
     ans = c;
     break;
   }
  }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 3636
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0144

"""
import sys
from sys import stdin
input = stdin.readline
from enum import Enum


class Graph(object):
    """ single source shortest path """
    class Status(Enum):
        """ ?????????????¨??????¶??? """
        white = 1  # ????¨????
        gray = 2  # ?¨???????
        black = 3  #?¨???????

    def __init__(self, n, data):
        self.num_of_nodes = n+1
        self.color = [Graph.Status.white] * self.num_of_nodes  # ????????????????¨??????¶???
        self.M = [[float('inf')] * self.num_of_nodes for _ in range(self.num_of_nodes)]
        for i in range(self.num_of_nodes):
            self.M[i][i] = 0
        self._make_matrix(data)  # data????????????????????£??\??????(?????\?¶???¨???????????????????????§????????????)
        self.d = [float('inf')] * self.num_of_nodes  # ?§???????????????????(?????????)
        self.p = [-1] * self.num_of_nodes  # ????????????????????????????¨?????????????????????????

    def _make_matrix(self, data):
        for d in data:
            r = d[0]
            for t in d[2:]:
                self.M[r][t] = 1

    def dijkstra(self, start):
        self.d[start] = 0
        self.p[start] = -1
        while True:
            mincost = float('inf')
            # ??\??????????????§??????????????¨?????????????????????u???????????????
            for i in range(len(self.d)):
                if self.color[i] != Graph.Status.black and self.d[i] < mincost:  # S????±???????????????????S??¨??\?¶?????????????????????????????????????????°???????????????????
                    mincost = self.d[i]
                    u = i  # u??????????????????ID
            if mincost == float('inf'):
                break
            self.color[u] = Graph.Status.black  # ?????????u???S????±???????????????´???
            for v in range(len(self.d)):
                if self.color[v] != Graph.Status.black and self.M[u][v] != float('inf'):
                    # v????????????????????????????????°??????S???????????£???u????????????????????????????????????????????°??????????????±??§??´??°??????
                    if self.d[u] + self.M[u][v] < self.d[v]:
                        self.d[v] = self.d[u] + self.M[u][v]
                        self.p[v] = u
                        self.color[v] = Graph.Status.gray

    def warshallFloyd(self):
        for k in range(self.num_of_nodes):
            for i in range(self.num_of_nodes):
                for j in range(self.num_of_nodes):
                    if self.M[i][k] + self.M[k][j] < self.M[i][j]: 
                        self.M[i][j] = self.M[i][k] + self.M[k][j]


def main(args):
    n = int(input())
    network = []
    for _ in range(n):
        network.append([int(x) for x in input().split()])

    packets = []
    p = int(input())
    for _ in range(p):
        packets.append([int(x) for x in input().split()])

    g = Graph(n, network)
    g.warshallFloyd()

    for s, d, v in packets:
        if g.M[s][d] < v:
            print(g.M[s][d]+1)
        else:
            print('NA')



if __name__ == '__main__':
    main(sys.argv[1:])

Measured memory_bytes: 8432
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.StringTokenizer;

public class Main  implements Runnable {
    public static void main(String[] args) {

        new Thread(null, new Main(), "", 16 * 1024 * 1024).start();

    }

    public void run() {
    	FastScanner sc = new FastScanner(System.in);
/*		FastScanner sc = new FastScanner("6 6 \r\n" +
				"..#..#\r\n" +
				"......\r\n" +
				"#..#..\r\n" +
				"......\r\n" +
				".#....\r\n" +
				"....#.");*/
    	//FastScanner sc = new FastScanner("1000000000000");
    	int n = Integer.parseInt(sc.next()); 
    	int k = Integer.parseInt(sc.next());
    	char a[]= sc.next().toCharArray();
		//ArrayList<Long> ttest = new ArrayList<Long>();
		//ttest.add(n);
		//int b = Integer.parseInt(sc.next());
		//int t = Integer.parseInt(sc.next());
		//int k = 0;
		//int k = Integer.parseInt(sc.next());
		//String str = sc.next();
		//char c[] = str.toCharArray();
		//char a[][] = new char[n];
		//int atmp[] = new int[h];
		//int max= 0;
		//int blackar[][] = new int[h*w][2];
		//int p=0;
		PrintWriter out = new PrintWriter(System.out);
		//for(long i = 1; i < n; i++)
		//{
		//	if(n/i==n%i)
		//	{
		//		out.println(n + ":" + i + ":" + n/i + ":" + n%i+":"+ (n/(n%i)-1));
		//	}
		//}


//N=(N%M)*M
//a=N%M
//a+Ma=N =1+M=N/a
    	a[k-1] = Character.toLowerCase(a[k-1]);
		out.println(String.valueOf(a));
		out.flush();
	}

    static class FastScanner {
        private BufferedReader reader = null;
        private StringTokenizer tokenizer = null;
        public FastScanner(String in) {
        	StringReader sr = new StringReader(in);
            reader = new BufferedReader(new BufferedReader(sr));
            tokenizer = null;
        }
        public FastScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
            tokenizer = null;
        }

        public String next() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public String nextLine() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    return reader.readLine();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }

            return tokenizer.nextToken("\n");
        }

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

        public long nextInt() {
            return Integer.parseInt(next());
        }

    }

}

Measured memory_bytes: 23252
#include <stdio.h>

#define MOD	((long long) 1e9 + 7)
#define N	200000

int ii[N + 1];

int mult(int a, int b) {
	return (int) ((long long) a * b % MOD);
}

int power(int a, int b) {
	int p;

	if (b == 0)
		return 1;
	p = power(a, b / 2);
	p = mult(p, p);
	if (b % 2 == 1)
		p = mult(p, a);
	return p;
}

int choose(int n, int k) {
	return k == 0 ? 1 : mult(mult(choose(n - 1, k - 1), n), ii[k]); 
}

int inv(int a) {
	return power(a, MOD - 2);
}

void init() {
	int a;

	for (a = 1; a <= N; a++)
		ii[a] = inv(a);
}

int main() {
	int h, w, a, b, i;
	int ch1, ch2, cnt;

	init();
	scanf("%d%d%d%d", &h, &w, &a, &b);
	h--, w--;
	ch1 = choose(b - 1, b - 1);
	ch2 = choose(w - b + h, w - b);
	for (i = 0; i <= h - a; i++) {
		cnt = (cnt + mult(ch1, ch2)) % MOD;
		ch1 = mult(mult(ch1, b - 1 + i + 1), ii[i + 1]);
		ch2 = mult(mult(ch2, ii[w - b + h - i]), h - i);
	}
	printf("%d\n", cnt);
	return 0;
}

Measured memory_bytes: 4096
import java.util.*;
import java.io.*;
 
public class Main{
    public static void main(String[] args){
        new Main().solve();
    }
 
    void solve(){
 
        Scanner cin = new Scanner(System.in);
        int MAXA = 1200;
        int MAXB = 20;
        int[][] dp = new int[MAXA][MAXB];
        dp[0][0] = 1;
        for(int i=2;i<=MAXA;i++){
            if(isPrime(i)){
                for(int j=MAXA- i - 1;j>= 0;j--){
                	for(int k=MAXB-2;k>=0;k--){
                		dp[j+i][k+1] += dp[j][k];
                	}
                }
            }
        }
        while(true)
        {
            int n = cin.nextInt();
            int k = cin.nextInt();
            if(n==0) return;
            System.out.println(dp[n][k]);
        }
    }
 
    boolean isPrime(int a){
        if(a<2) return false;
        for(int i=2;i*i<=a;i++){
            if(a%i==0) return false;
        }
        return true;
    }
}

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

using namespace std;

int fac(int n) {
  if (n == 0) return 0;
  if (n == 1) return 1;
  return n * fac(n-1);
}

int get_order(int N, vector<int>& P) {
  set<int> s;
  for (int i = 1; i <= N; i++) {
    s.insert(i);
  }

  int ret = 0;
  for (int i = 0; i < N; i++) {
    int c = 0;
    for (auto it = s.begin(); it != s.end(); it++) {
      if (*it == P[i]) {
        s.erase(it);
        break;
      }
      c++;
    }
    ret += c * fac(N - i - 1);
  }
  return ret;
}

int main() {
  int N;
  cin >> N;
  vector<int> P(N);
  vector<int> Q(N);

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

  cout << abs(get_order(N, P) - get_order(N, Q)) << endl;

  return 0;
}


Measured memory_bytes: 256
# A - Can't Wait for Holiday
s = input()

day = 0

if s == 'SUN':
    day = 7
elif s == 'MON':
    day = 6
elif s == 'TUE':
    day = 5
elif s == 'WED':
    day = 4
elif s == 'THU':
    day = 3
elif s == 'FRI':
    day = 2
else:
    day = 1

print(day)

Measured memory_bytes: 2940
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n = sc.nextInt()
  val (c, s, f) = Array.fill(n-1)((sc.nextInt(), sc.nextInt(), sc.nextInt())).unzip3
  for (i <- 0 until n) {
    var ans = 0L
    var t = 0
    for (j <- i until n-1) {
      if (t <= s(j)) {
        ans += s(j) - t
        t = s(j)
      } else {
        val r = t % f(j)
        val w = if (r == 0) 0 else f(j) - r
        ans += w
        t += w
      }
      ans += c(j)
      t += c(j)
    }
    println(ans)
  }
}


Measured memory_bytes: 55996
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res

def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    n = I()

    return

#B
def B():
    n = I()

    return

#C
def C():
    n = I()
    a = LI()
    b = LI()
    q = []
    for i in range(n):
        if b[i] > a[i]:
            heappush(q,(-b[i],i))
    ans = 0
    while q:
        bi,i = heappop(q)
        r = (i+1)%n
        l = i-1
        s = b[l]+b[r]
        if a[i] < s:
            m = b[i]//s
            if m:
                ans += m
                b[i] %= s
                if b[i] != a[i]:
                    heappush(q,(-b[i],i))
        else:
            k = -bi-a[i]
            m = k//s
            b[i] -= m*s
            ans += m
            if b[i] != a[i]:
                break
    if a == b:
        print(ans)
    else:
        print(-1)
    return

#D
def D():

    return

#E
def E():
    n = I()

    return

#F
def F():
    n = I()

    return

#Solve
if __name__ == "__main__":
    C()


Measured memory_bytes: 122196
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.Arrays;
import java.util.Scanner;

class Main {
    static Node root = null;
    static StringBuilder sb = new StringBuilder("");

    public static void main (String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int m = Integer.parseInt(br.readLine());
        String input;

        for (int i = 0; i < m; i++) {
            input = br.readLine();
            if (input.charAt(0) == 'i') {
                insert(new Node(Integer.parseInt(input.substring(7))));
            } else {
                print();
            }
        }
        System.out.print(sb);
    }

    public static void insert(Node node) {
        Node parent = null;
        Node child = root;
        while (child != null) {
            parent = child;
            if (node.key < child.key) {
                child = child.left;
            } else {
                child = child.right;
            }
        }

        if (parent == null) {
            root = node;
        } else if (node.key < parent.key) {
            parent.left = node;
        } else {
            parent.right = node;
        }
    }

    public static void print() {
        printInorder(root);
        sb.append("\n");
        printPreorder(root);
        sb.append("\n");
    }

    public static void printPreorder(Node node) {
        if (node == null) return;
        sb.append(" ").append(node.key);
        printPreorder(node.left);
        printPreorder(node.right);
    }

    public static void printInorder(Node node) {
        if (node == null) return;
        printInorder(node.left);
        sb.append(" ").append(node.key);
        printInorder(node.right);
    }
}

class Node {
    public int key;
    public Node left;
    public Node right;

    public Node(int key) {
        this.key = key;
        left = right = null;
    }
}

Measured memory_bytes: 96252
package main

import(
	"bufio"
	"fmt"
	"os"
)

func main() {
	var n int
	var k int
	var num int
	sc := bufio.NewScanner(os.Stdin)
	sc.Scan()
	fmt.Sscanf(sc.Text(), "%d %d", &n, &k)

	if n%2 == 0{
		num = n/2
	} else {
		num = ((n-1)/2) + 1
	}


	if k <= num{
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9;
const int MOD = 1e9 + 7;

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

  vector<ll> a(n);
  for (auto &e : a)
    cin >> e;

  ll cnt = 0;
  for (int i = 1; i < n; ++i)
  {
    if (a[i - 1] > x)
    {
      cnt += a[i - 1] - x;
      a[i - 1] = x;
    }
    ll diff = a[i] + a[i - 1] - x;
    if (diff > 0)
    {
      cnt += diff;
      a[i] -= diff;
    }
  }

  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long n, a, b, c, d, e;
  cin >> n >> a >> b >> c >> d >> e;
  long long neck = min(a, min(b, min(c, min(d, e))));
  cout << (n + neck - 1) / neck + 4 << endl; 
}

Measured memory_bytes: 256
//自称高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

int main() {
    int ans = 0;
	int a, b;
	cin >> a >> b;
	if(b%a == 0) cout << a+b << endl;
	else cout << b-a << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <limits>
#include <queue>
#include <iomanip>
#include <set>
//#include <bits/stdc++.h>
template<typename T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<typename T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}
using namespace std;
#define ALL(X) X.begin(),X.end()
using ll = long long int;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
const int MOD=1000000007;
//const int MOD=998244353;
const int INTMAX=2147483647;
const ll LLMAX=9223372036854775807;


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    /*ll N;
     cin>>N;
     
     vll A(N+1);
     for(ll i=0;i<=N;i++)cin>>A[i];
     if(N==0){
     if(A[0]==1){
     cout<<1<<endl;
     return 0;
     }else {
     cout<<-1<<endl;
     return 0;
     }
     }
     if(A[0]!=0){
     cout<<-1<<endl;
     return 0;
     }
     
     
     vll B(N+1);
     for(ll i=0;i<=N;i++){
     if(i==0){
     B[0]=1;
     }else{
     B[i]=(B[i-1]-A[i-1])*2;
     if(B[i]<A[i]){
     cout<<-1<<endl;
     return 0;
     }
     }
     }
     
     vll C(N+1);
     for(ll i=N;i>=0;i--){
     if(i==N){
     C[i]=A[i];
     }else{
     C[i]=C[i+1]+A[i];
     }
     }
     
     ll ans=0;
     for(ll i=0;i<=N;i++){ans+=min(B[i],C[i]);
     }
     cout<<ans<<endl;
     
     return 0;
     }
     
     int main() {*/
    //ll n,a[100005]={0},b[100005],c[100005],pv,ans=0;
    ll n,pv;
    //vll a(n+2),b(n+2),c(n+2);
    vll a(100005),b(100005),c(100005);
    bool ok=false;
    cin >> n;
    for(ll i=0;i<=n;i++){
        cin >> a[i];
    }
    for(ll i=0;i<=n;i++){
        if(i==0){
            if(a[i]>1){
                cout << -1 << endl;
                return 0;
            }
            b[0]=1;
        } else {
            if(ok) b[i]=2*1e17;
            else b[i]=(b[i-1]-a[i-1])*2;
            if(b[i]>=1e17) ok=true;
            if(a[i]>b[i]){
                cout << -1 << endl;
                return 0;
            }
        }
    }
    b[n+1]=1;
    for(ll i=n;i>=0;i--){
        if(i==n){
            c[i]=a[i];
        } else {
            c[i]=c[i+1]+a[i];
        }
    }
    c[n+1]=0;
    for(ll i=0;i<=n+1;i++){
        if(b[i]>c[i]){
            pv=i;
            break;
        }
    }
    ll ans=0;
    for(ll i=0;i<=n;i++){
        if(i<pv){
            ans+=b[i];
        } else {
            ans+=c[i];
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 5500
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <iterator>
#include <vector>
using namespace std;

template<class T> inline void chmax(T& a, const T& b) { if(b > a) a = b; }

vector<vector<int> > sum;
vector<vector<int> > memo;

int dfs(int genre, int rest) {
	if(genre == sum.size())
		return 0;

	if(memo[genre][rest] != -1)
		return memo[genre][rest];

	int res = 0;
	for(int i = 0; i < sum[genre].size() && rest - i >= 0; ++i)
		chmax(res, sum[genre][i] + dfs(genre + 1, rest - i));

	return memo[genre][rest] = res;
}

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

	int n, k;
	cin >> n >> k;

	vector<vector<int> > price(10);
	for(int i = 0; i < n; ++i) {
		int c, g;
		cin >> c >> g;
		price[g - 1].push_back(c);
	}

	vector<vector<int> >::iterator it = price.begin();
	while(it != price.end()) {
		if((*it).size()) {
			sort((*it).begin(), (*it).end(), greater<int>());
			++it;
		}
		else {
			it = price.erase(it);
		}
	}

	sum.resize(price.size());
	for(int i = 0; i < price.size(); ++i) {
		sum[i].push_back(0);
		int tmp = 0;
		for(int j = 0; j < price[i].size(); ++j) {
			tmp += price[i][j];
			sum[i].push_back(tmp + j * (j + 1));
		}
	}

	memo.resize(price.size(), vector<int>(k + 1, -1));
	cout << dfs(0, k) << endl;

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1328
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int H,W;
    while(true){
        cin>>H>>W;
        if(H==0&&W==0){
            break;
        }
        for(int j=0;j<W;j++){
            cout<<'#';
        }
        cout<<endl;
        for(int i=1;i<H-1;i++){
            cout<<'#';
            for(int j=1;j<W-1;j++){
                cout<<'.';
            }
            cout<<'#'<<endl;
        }
        for(int j=0;j<W;j++){
            cout<<'#';
        }
            cout<<endl<<endl;
        }
         
    }


Measured memory_bytes: 3080
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#include <utility>
#include <cstdio>
using namespace std;
typedef long long LL;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n, m) for (int i = n; i >= m; i--)

template <class T>
bool contain(const std::string &s, const T &v)
{
    return s.find(v) != std::string::npos;
}

int a,b,cnt[5]={};
int main()
{
    rep(i,3){
        cin>>a>>b;
        cnt[a]++;
        cnt[b]++;
    }
    if(cnt[1]==1&&cnt[2]==2&&cnt[3]==2&&cnt[4]==1){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }
}

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

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

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

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

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

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

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

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

int main(){
    int n, m;
    cin >> n >> m;
    vi ac(n), pena(n);
    rep(i, m) {
        int p;
        string s;
        cin >> p >> s;
        p--;
        if (ac[p]) continue;
        if (s == "AC") {
            ac[p]++;
        }
        else {
            pena[p]++;
        }
    }
    int AC = 0, PENA = 0;
    rep(i, n) {
        AC += ac[i];
        if (ac[i]) PENA += pena[i];
    }
    cout << AC << ' ' << PENA << endl;
    return 0;
}



Measured memory_bytes: 1024
N = int(input())
list = input().split()
on = 0
for i in range(N):
  k = int(list[i])
  if k % 2 == 0:
    if k % 3 == 0 or k % 5 == 0:
      on = 1 
    else:
      print("DENIED")
      break
  if i == N-1:
  	print("APPROVED")

Measured memory_bytes: 3060
n = int(input())
a = [int(i) for i in input().split()]
a_abs = [abs(i) for i in a]
if len([i for i in a if i < 0]) % 2 == 0:
  ans = sum(a_abs)
else:
  ans = sum(a_abs) - min(a_abs) * 2
print(ans)

Measured memory_bytes: 14412
#include <iostream>
#include <sstream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <utility>
#include <functional>
#include <cmath>

#define REP(i,x,y) for(int i=(int)(x);i<(int)(y);i++)
#define RREP(i,x,y) for(int i=(int)(x);i>(int)(y);i--)
#define all(x) (x).begin(),(x).end()

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#endif

typedef long long ll;

using namespace std;

const int MAX_N = 100000;
int N;
int A[MAX_N + 1];

int solve() {
    int ans = -1;
    int count = 1;
    int cur = 1;
    REP(i, 0, N){
        if(A[cur] == 2){
            ans = count;
            break;
        }
        count++;
        cur = A[cur];
    }
    return ans;
}

int main() {
    // to shorten execution time for iostream
    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> N;
    REP(i, 1, N+1) cin >> A[i];
    cout << solve() << "\n";
    return 0;
}


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

int n, m;

int main()
{
	cin >> n;
	
	while (n!=0)
	{
		m=n%10;
		if (m==7)
		{
			cout << "Yes";
			return 0;
		}
		n/=10;
	}
	
	cout << "No";
	return 0;
}

Measured memory_bytes: 3568
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define pb push_back
#define X first
#define Y second
#define sz(v) (int)v.size()

void solve();

main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
#ifdef ONPC
	freopen("in.txt", "r", stdin);
#endif
	int t = 1;
	//cin >> t;
	while (t--) solve();
	return 0;
}

const int N = 1e5 + 5;
pair<int, int> a[N];
int n, ans;

void solve() {
	cin >> n;
	for (int i = 1; i <= n; ++i) {
		cin >> a[i].X;
		a[i].Y = i;
	}
	sort(a + 1, a + n + 1);
	for (int i = 1; i <= n; ++i) {
		if (a[i].Y % 2 != i % 2) ++ans;
	}
	cout << ans / 2;
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<stack>
#include<cstdio>
#include<cmath>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<int,P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
#define mp1(a,b,c) P1(a,P(b,c))

const int INF=1000000000;
const int dir_4[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
const int dir_8[8][2]={{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};

int main(){
	string s;
	cin >> s;
	cout << s.substr(0,s.size()-8) << endl;
}



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

int main(){
  int n;
  cin >> n;
  ll ans =0;
  for(int i=1;i<=n; i++){
   if(i%3 == 0) continue;
   if(i%5 == 0) continue;
    ans += i;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
#include <string>
#include <cmath>
#include <sstream>
//#include <unordered_map>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define FORD(i, a, b) for(int i = (a-1); i >= (b); i--)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
typedef long long int ll;
using namespace std;
ll mod=1000000007;
//ll mod=67280421310721;
//ll mod=998244353;
ll INF=1e18;
ll po(ll a,ll b)
{
	ll re=1;
	while(b)
	{
		if(b%2==1)
		{
			re=(re*a);
			re%=mod;
		}
		a=(a*a);
		a%=mod;
		b>>=1;
	}
	return re;
}
ll dp[1000001];
int main()
{
//	ios_base::sync_with_stdio(false);
//	cin.tie(NULL);
//	cout.tie(NULL);
	int test=1;
//	cin>>test;
	while(test--)
	{
		ll n;
		cin>>n;
		if(n==1)
		{
			cout<<1;
			return 0;
		}
		if(n==2)
		{
			cout<<4;
			return 0;
		}
		dp[0]=n;
		dp[1]=(n*n)%mod;
//		cout<<'k';
		ll s=(dp[0]+dp[1])%mod;
		FOR(i,2,n)
		{
			dp[i]=(s-dp[i-2]+(n-1)*(n-1)+(n-i+1)+mod)%mod;
			s=(s+dp[i])%mod;
//			cout<<dp[i]<<'\n';
		}
		cout<<dp[n-1];
	}
	return 0;
}


Measured memory_bytes: 8064
#include <bits/stdc++.h>
#define inf 10000
using namespace std;

int a, b, c, q, x, y;
string s, t;

int main() {
  cin >> q;
  while(q--) {
    a = inf;
    cin >> s >> t;
    for(int i = 0; i < s.size(); ++i) {
      if(s[i] != t[i]) a = min(a, i);
      if(s[i] == '1') b = i;
      if(t[i] == '1') c = i;
    }
    if(a == inf)
      cout << 0 << endl;
    else {
      x = max(b - a, 0);
      y = c - min(a, b);
      if(y < 0) y *= -1;
      cout << x + y << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 3208
#include <iostream>
#include <string>
#define FOR(i,k,n) for(int(i)=(k);(i)<(n);(i)++)
using namespace std;

int main()
{
  long X;
  cin >> X;

  long i;
  for (i = 0;; ++i) {
    if (i * (i + 1) / 2 >= X) break;
  }

  cout << i << endl;
  return 0;
}


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

int main() {
  int N;
  std::cin >> N;
  std::vector<int> h(N);
  for (int i = 0; i < N; i++) std::cin >> h[i];
  int ans = 0;
  int c = 0;
  for (int i = 0; i < N - 1; i++) {
    ans = std::max(ans, c);
    if (h[i] >= h[i + 1]) {
      c++;
    } else {
      c = 0;
    }
  }
  ans = std::max(ans, c);
  std::cout << ans << std::endl;
  return 0;
}



Measured memory_bytes: 640
#include<stdio.h>
int main(void)
{
  int r,d,x[15];
  scanf("%d%d%d",&r,&d,&x[0]);
  for(int i=1;i<11;i++){
    x[i]=r*x[i-1]-d;
    printf("%d\n",x[i]);
  }
  return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;

#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define INF ((long long)1e18)
#define MOD ((int)1e9+7)
#define endl "\n"

#define yn(f) ((f)?"Yes":"No")
#define YN(f) ((f)?"YES":"NO")

#define MAX 10
#define MAX_V 1100

int l[MAX];
int N, A, B, C;
int ans = INF;

int check(int a, int b, int c){
	int d = b-a, res = INF;
	// cout<<c<<" a = "<<a<<" b = "<<b<<endl;
	
	for(int i = 0; i < d; i++){
		res = min(abs(l[i+a]-c),res);
		// cout<<" res = "<<abs(l[i+a]-c)<<" "<<l[i+a]<<endl;
	}
	// cout<<" ans -> "<<res<<endl;
	if(res <= 10) return res;
	
	for(int i = 1; i < (1<<d); i++){
		int temp = 0, con = 0;
		for(int j = 0; j < d; j++){
			if(i&(1<<j)){
				con++;
				temp += l[j+a];
			}
		}
		// cout<<i<<" temp->"<<temp<<" con = "<<con<<endl;
		res = min(res,abs(temp-c)+max(0ll,(con-1)*10));
	}
	// cout<<" ans -> "<<res<<endl;
	return res;
}

void hoge(vector<int>& num){
	
	int t = check(num[0],num[1],A)+check(num[1],num[2],B)+check(num[2],N,C);
	// cout<<" <><><><><><><><> "<<endl;
	ans = min(ans,t);
}

void solve(int depth, vector<int>& num){//cout<<depth<<endl;
	if(depth == 2){
		hoge(num);
		// cout<<num[1]<<" num "<<num[2]<<" num size"<<num.size()<<endl;
		return;
	}
	for(int i = num[depth]+1; i < N; i++){//cout<<" i -- "<<i<<endl;
		num.push_back(i);
		solve(depth+1,num);
		num.pop_back();
	}
}

void solve2(){
	vector<int> test(1,0);
	sort(l,l+N);
	for(;;){//cout<<" +++++ "<<endl;
	// string hogehoge;cin>>hogehoge;
		solve(0,test);
		bool flag = next_permutation(l,l+N);
		if(flag == false) return;
		
	}
}

signed main(){
	// cin.tie(0);
	// ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	
	
	cin>>N>>A>>B>>C;
	
	rep(i,N){
		cin>>l[i];
	}
	
	solve2();
	
	cout<<ans<<endl;
	
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=(b);++i)
#define mem(a,x) memset(a,x,sizeof(a))
#define pb push_back
#define pi pair<int, int>
#define mk make_pair
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
const int N=1e5+10;
ll x,y,a,b,c;
ll p[N],q[N],r[N];
ll t[4*N];

bool cmp(int x,int y)
{
    return x>y;
}
int main()
{
	cin>>x>>y>>a>>b>>c;
	rep(i,1,a) scanf("%lld",&p[i]);
	rep(i,1,b) scanf("%lld",&q[i]);
	rep(i,1,c) scanf("%lld",&r[i]);

	sort(p+1,p+1+a,cmp);
	sort(q+1,q+1+b,cmp);
	sort(r+1,r+1+c,cmp);
	int len=0;
	for(int i=1;i<=x;++i) t[++len]=p[i];
	for(int i=1;i<=y;++i) t[++len]=q[i];

	sort(t+1,t+1+len);
	ll ans=0;
	rep(i,1,len) ans+=t[i];

	int i,pos=1;
	for(i=1;i<=len&&pos<=c;++i){
        if(r[pos]>=t[i]){
            ans+=r[pos]-t[i];
            pos++;
        }
	}
	cout<<ans<<endl;
}


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

const long long MOD = 1000000007;
const long long INF = 1LL << 60;

int main()
{
  int P, Q, R;
  cin >> P >> Q >> R;
  int ans = 0;
  ans = min(P + R, min(P + Q, Q + R));
  cout << ans << endl;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args){

		String str = null;
		BufferedReader br = null;
		br = new BufferedReader(new InputStreamReader(System.in));
		
		
		String[] str1;
		int a,b,c;

		try {
			str = br.readLine();
		} catch (IOException e) {
			// TODO ????????????????????? catch ????????????
			e.printStackTrace();
		}
		
		boolean d = true;
		str1 = str.split(" ");
		a = Integer.parseInt(str1[0]);
		b = Integer.parseInt(str1[1]);
		c = Integer.parseInt(str1[2]);
		int e = 0;
		for(int i=a;i<=b;i++){
			
			if(c%i==0){
				e++;
				
			}
			
			
		}
		System.out.println(e);
	}
}

Measured memory_bytes: 24416
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v)
{
    int sz = v.size();
    for (int i = 0; i < sz; i++)
    {
        cout << v[i] << " \n"[i == sz - 1];
    }
}

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

    ll r, d, x;
    cin >> r >> d >> x;
    for (int i = 0; i < 10; i++)
    {
        x = r * x - d;
        cout << x << endl;
    }
}


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

int main(){
    int n;
    cin >> n;
    int ans = 0, count = 0;

    for (int i = 1; i <= n;) {
        count = 0;
        for (int j = 1; j <= i; j++) {
            if (i%j == 0) count++;
        }
        if (count == 8) ans++;
        i += 2;
    }
    cout << ans << endl;
}

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


int main ( void ) {
  
  int num[1000], art, target, count;
  
  scanf("%d", &target);
  scanf("%d", &art);
  
  for(int i = 0; i < art; i++){
	scanf("%d", &num[i]);
  }
  
  for(int i = 0; i <= target; i++){
    count = 0;
    for(int j = 0; j < art; j++){
      if(num[j] != target - i ){
        count++;
      }
    }
    if(count == art){
      printf("%d\n", target - i);
      break;
    }

    count = 0;
    for(int j = 0; j < art; j++){
      if(num[j] != target + i ){
        count++;
      }
    }
    if(count == art){
      printf("%d\n", target + i);
      break;
    }
    
  }
    
  return 0;
}

Measured memory_bytes: 1740
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
const int mod=1000000007;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;cin >> n;
	vector<int> a(n);
	vector<int> b(n);
	rep(i,n) cin >> a.at(i);
	int i=n/2,j=1,k=0;
	bool flg=true;
	if(n%2==0){
		b.at(i)=a.at(k);
		k++;
		flg=false;
		while(k<n){
			if(flg){
				b.at(i+j)=a.at(k);
				k++;
				j++;
				flg=false;
			}
			else{
				b.at(i-j)=a.at(k);
				k++;
				flg=true;
			}
		}
	}
	else{
		b.at(i)=a.at(k);
		k++;
		while(k<n){
			if(flg){
				b.at(i+j)=a.at(k);
				k++;
				flg=false;
			}
			else{
				b.at(i-j)=a.at(k);
				k++;
				j++;
				flg=true;
			}
		}
	}
	rep(i,n-1) cout << b.at(i) << " ";
	cout << b.at(n-1) << endl;
}

Measured memory_bytes: 3712
#include "bits/stdc++.h"

using namespace std;

#define int long long int
#define all(x) x.begin(), x.end()
#define pb push_back
#define mp make_pair
#define se second
#define fi first

typedef pair<int, int> pii;
typedef vector<int> vi;

const int inf = 1e18;
const int mod = 1e9 + 7;

inline int add(int x, int y) { x += y; if (x >= mod) x -= mod; return x;}
inline int sub(int x, int y) { x -= y; if (x < 0) x += mod; return x;}
inline int mul(int x, int y) { return ((x % mod) * (y % mod)) % mod;}
inline int power(int a, int b) {
    int x = 1;
    while (b) {
        if (b & 1) x = mul(x, a);
        a = mul(a, a);
        b >>= 1;
    }
    return x;
}
inline int inv(int a) { return power(a, mod - 2);}

const int N = 3005;
int a[N],dp[N][N][2];

int f(int i,int j,int k){
    if(i>j) return 0;
    int &ret = dp[i][j][k];
    if(ret != -1) return ret;
    if(k==0){ // player 1 trying to maximize
        ret = max(a[i]+f(i+1,j,1-k),a[j]+f(i,j-1,1-k));
    } else { // player 2 trying to minimize
        ret = min(-a[i]+f(i+1,j,1-k),-a[j]+f(i,j-1,1-k));
    }
    return ret;
}

int32_t main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

    int n; cin >> n;
    for(int i=1;i<=n;i++) cin >> a[i];
    for(int i=0;i<N;i++) for(int j=0;j<N;j++) dp[i][j][0] = dp[i][j][1] = -1;
    cout << f(1,n,0) << endl;

    return 0;
}

Measured memory_bytes: 141568
#include <bits/stdc++.h>
using i64 = long long;

int main() {
    constexpr i64 mod = 1000000007;
    int n;
    std::cin >> n;
    std::vector<int> a(n);
    for (int i = 0; i < n; i++) {
        int in;
        std::cin >> in;
        a[in]++;
    }
    i64 ret = 1;
    for (int i = n - 1; i > 0; i -= 2) {
        if (a[i] != 2) ret = 0;
        else ret = ret * 2 % mod;
    }
    if (a[!(n & 1)] != 2 - n % 2) ret = 0;
    std::cout << ret << std::endl;

    return 0;
}


Measured memory_bytes: 640
#include <cstdio>
#include <algorithm>
const int maxn = 1e5 + 5;
using namespace std;
struct E{
	int to, nxt;
}e[maxn];
int head[maxn], tot = 0;
void addedge(int u, int v){
	e[++tot].to = v, e[tot].nxt = head[u];
	head[u] = tot;
}
int a[maxn], dep[maxn], n, k, ans = 0;
void dfs(int cur, int fa){
	for (int i = head[cur]; i; i = e[i].nxt){
		int v = e[i].to;
		dfs(v, cur);
		dep[cur] = max(dep[cur], dep[v] + 1);
	}
	if (fa != 1 && dep[cur] == k - 1 && cur != 1) dep[cur] = -1, ++ans;
}
int main(){
	scanf("%d%d%d", &n, &k, a + 1);
	if (a[1] != 1) a[1] = 1, ++ans;
	for (int i = 2; i <= n; i++){
		scanf("%d", a + i);
		addedge(a[i], i);
	}
	dfs(1, 0);
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 6784
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

template <typename T> // T : type of cost
struct BellmanFord {
    T inf = numeric_limits<T>::max(); // initial value, reused when clear() is called
    int n;                            // number of nodes
    vector<T> dist;                   // distance from start node
    bool negativeLoop;
    struct edge {
        int from, to;
        T cost;
        edge(int from, int to, T cost) : from(from), to(to), cost(cost) {}
    };
    vector<edge> edges;

    BellmanFord(int n) : n(n), negativeLoop(false), dist(n, inf){};
    // 0-indexed!
    void addEdge(int from, int to, T cost) { edges.emplace_back(from, to, cost); }
    // calculate dist[i] as a shortest distance from start (to end)
    // end is used to check if there is "relevant" negative circuit
    // even if there is negative curcuit, it might not affect the path of interest
    void build(int start, int end = -1) {
        dist[start] = 0;
        for (int i = 0; i <= 2 * n; ++i) {
            for (auto &e : edges) {
                if (dist[e.from] != inf && dist[e.to] > dist[e.from] + e.cost) {
                    dist[e.to] = dist[e.from] + e.cost;
                    if (i >= n && (end == -1 || end == e.to)) {
                        negativeLoop = true;
                        break;
                    }
                }
            }
        }
    }
};

int main() {
    ll n, m, p;
    cin >> n >> m >> p;
    BellmanFord<ll> graph(n);
    vl a(m), b(m), c(m);
    for (int i = 0; i < m; ++i) {
        cin >> a[i] >> b[i] >> c[i];
        a[i]--;
        b[i]--;
        graph.addEdge(a[i], b[i], p - c[i]);
    }
    graph.build(0, n - 1);
    if (graph.negativeLoop) {
        cout << -1 << "\n";
        return 0;
    }
    BellmanFord<ll> graph2(n);
    for (int i = 0; i < m; ++i) {
        graph2.addEdge(a[i], b[i], p - c[i]);
    }
    graph2.build(n - 1, n - 1);
    if (graph2.negativeLoop) {
        cout << -1 << "\n";
    } else {
        cout << max(0LL, -graph.dist[n - 1] - graph2.dist[n - 1]) << "\n";
    }
    return 0;
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
#define ll long long
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int main()
{
	fast;
   // #ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    //#endif
    ll int s,w;
    cin>>s>>w;
    if(w>=s)
    	cout<<"unsafe";
    else
    	cout<<"safe";
}

Measured memory_bytes: 3660