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

void solve() {
  int N;
  scanf("%d", &N);
  int arr[N];
  for (size_t i = 0; i < N; i++) {
    scanf("%d", &arr[i]);
  }
  int arr_2[N];
  rep(i,N){
    arr_2[i] = arr[i];
  }
  int count=0;
  sort(arr_2, arr_2+N);
  rep(i, N) {
    if (arr[i]!=arr_2[i]) {
      count++;
    }
  }
  if (count==0||count==2) {
    std::cout << "YES" << '\n';
  } else {
    std::cout << "NO" << '\n';
  }
}

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


Measured memory_bytes: 256
import Control.Arrow
import Control.Monad
import Data.List
import qualified Data.ByteString.Char8 as B

main :: IO ()
main = readLine >>= print . solve

solve :: [Int] -> Int
solve [n, d] 
        | m > 0 = r + 1
        | otherwise = r
        where 
            (r, m) = n `divMod` (d * 2 + 1)

readLine :: IO [Int]
readLine = unfoldr (fmap (second (maybe B.empty snd . B.uncons)) . B.readInt) <$> B.getLine

readContents :: Int -> IO [[Int]]
readContents = flip replicateM readLine

Measured memory_bytes: 380
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
 
int main(void)
{
    int n, t[100001], x[100001], y[100001];
    int i, dt, dist;
    bool flag = false;
    scanf("%d", &n);
    t[0] = x[0] = y[0] = 0;
    for (i=1; i<n+1; i++)
    {
        scanf("%d %d %d", &t[i], &x[i], &y[i]);
    }
 
    for (i=0; i<=n-1; i++)
    {
        dt =  t[i+1] - t[i];
        dist = abs(x[i+1] - x[i]) + abs(y[i+1] - y[i]);
        if (dt < dist) {
            flag = true;
            break;
        }
        if (dt%2 != dist%2) {
            flag = true;
            break;
        }
    }
 
    if (flag == true) {
        printf("No\n");
    } else {
        printf("Yes\n");
    }
    return 0;
}

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

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

char s[MAXN];
int n;

void gg() {
	puts("-1");
	exit(0);
}

inline void Edge(int u, int v) {
	printf("%d %d\n", u, v);
}

void init() {
	scanf("%s", s + 1);
	n = strlen(s + 1);
}

void solve() {
	if (s[1] == '0') gg();
	if (s[n] == '1') gg();
	for (int i = 1; i < n; ++i) {
		if (s[i] != s[n - i]) gg();
	}
	int cur = 1;
	for (int i = 2; i <= (n + 1) / 2; ++i) {
		if (s[i] == '0') continue;
		Edge(cur, i);
		for (int j = cur + 1; j < i; ++j) {
			Edge(j, i);
		}
		cur = i;
	}
	Edge(cur, cur + 1);
	for (int i = cur + 2; i <= n; ++i) {
		Edge(cur + 1, i);
	}
}

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


Measured memory_bytes: 1536
#include <iostream>
#include <string>
#include <vector>

static bool Input(std::vector<std::string> &t, std::vector<std::string> &h, int &n)
{
	if (0x00 == &t || 0x00 == &h || 0x00 == &n) {
		return false;
	}

	n = 0;
	std::cin >> n;
	if (1000 < n) {
		return false;
	}

	t.resize(n);
	h.resize(n);

	for (int i = 0; i < n; i++) {
		std::cin >> t[i] >> h[i];
		if (100 < t[i].size() || 100 < h[i].size()) {
			return false;
		}
	}

	return true;

}

static bool calcScore(const std::vector<std::string> t, const std::vector<std::string> h, const int n, int &taro, int &hanako)
{
	if (0x00 == &taro || 0x00 == &hanako) {
		return false;
	}

	taro = 0;
	hanako = 0;

	for (int i = 0; i < n; i++) {
		if (0 == t[i].compare(h[i])) {
			taro += 1;
			hanako += 1;
		} else if (0 < t[i].compare(h[i])) {
			taro += 3;
		} else {
			hanako += 3;
		}
	}

	return true;
}
int main()
{
	int n = 0;
	int taro = 0, hanako = 0;
	std::vector<std::string> t, h;

	if (true == Input(t, h, n)) {
		(void) calcScore(t, h, n, taro, hanako);
		std::cout << taro << " " << hanako << std::endl;
	}

	return (0);
}

Measured memory_bytes: 3228
(N, M) = [int(n) for n in input().split()]
H = [int(n) for n in input().split()]
G = [1 for _ in range(N)]
for _ in range(M):
    (A, B) = [int(n)-1 for n in input().split()]
    if H[A] <= H[B]:
        G[A] = 0
    if H[B] <= H[A]:
        G[B] = 0

print(sum(G))
    


Measured memory_bytes: 19904
import sys

input = sys.stdin.readline

def main():
    ans = 0
    A, B, C = map(int, input().split())
    ma, mi = max(A,B,C), min(A,B,C)
    if ma*3%2 != (A+B+C)%2:
        ma += 1
    ans = (ma*3-(A+B+C))//2 + (ma*3-(A+B+C))%2
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 9068
import java.io.{InputStream, OutputStream, PrintStream}
import java.util.Scanner

object Main {

  def main(args: Array[String]): Unit = {
    val solver = new Solver(System.in, System.out)
    solver.solve()
  }

  class Solver(in: InputStream, out: OutputStream) {
    lazy val input = new Scanner(in)

    lazy val output = new PrintStream(out)

    def solve(): Unit = {
      val Array(n, t) = input.nextLine().split(" ").map(_.toInt)
      val nts = 0.until(n).map { i =>
        val Array(ni, ti) = input.nextLine().split(" ").map(_.toInt )
        (ni, ti)
      }


      val candidates = nts.filter { case (ni, ti) => ti <= t }
      if (candidates.isEmpty) println("TLE")
      else println(candidates.map(_._1).min)
    }

  }

}


Measured memory_bytes: 25548
N, K = map(int, input().split())
S = []
for j in range(K):
    S.append(list(map(int, input().split())))

m =  998244353

# print(S)

dp = [0] * N
dp[0] = 1
sum_of_region = [0] * K
for i in range(1, N):
    for j in range(K):
        if i - S[j][0] >= 0:
            sum_of_region[j] += dp[i - S[j][0]]
        if i - S[j][1] - 1 >= 0:
            sum_of_region[j] -= dp[i - S[j][1] - 1]
        dp[i] += sum_of_region[j] % m
        dp[i] %= m
    # print(i, dp, sum_of_region)

ans = dp[N - 1]
print(ans)


Measured memory_bytes: 16856
N=int(input())
S="a"
bottom=""
alpha="abcdefghijklmnopqrstuvwxyz"

for i in range(N):
    if i>25:
        bottom=bottom+"z"
    else:
        bottom=bottom+alpha[i]
    S=S+"a"

C=0
S=""
def F(S,loop,N,C):
    for i in range(0,loop):
        if N==C+1:
            print(S+bottom[i])
        else:
            if loop==i+1:
                loop+=1
            F(S+bottom[i],loop,N,C+1)
    return None
            
F(S,1,N,C)

Measured memory_bytes: 4340
#include <algorithm>
#include <functional>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <climits>
 
#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second
 
const int INF=100000000;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
using namespace std;
typedef pair<int ,int > P;
typedef pair<P,P> PP;
typedef long long ll;
 
 
int W,H;
string roomL[55],roomR[55];
 
bool range_check(int y,int x) {
    if(!(0<=y&&y<H)) return false;
    if(!(0<=x&&x<W)) return false;
 
    return true;
}
 
bool visited[55][55][55][55];
bool ok(P len,P rin) {
    memset(visited,0,sizeof(visited));
    visited[len.fr][len.sc][rin.fr][rin.sc]=true;
    queue<PP> que;
    que.push(PP(len,rin));
 
    while(que.size()) {
        PP pp=que.front(); que.pop();
        P next_len=pp.fr;
        P next_rin=pp.sc;
 
        //printf("[debug] %d %d %d %d\n",next_len.fr,next_len.sc,next_rin.fr,next_rin.sc);
 
        if(roomL[next_len.fr][next_len.sc]=='%' && roomR[next_rin.fr][next_rin.sc]=='%') {
            return true;
        }
        if(roomL[next_len.fr][next_len.sc]=='%' || roomR[next_rin.fr][next_rin.sc]=='%') {
            //visited[next_len.fr][next_len.sc][next_rin.fr][next_rin.sc]=false;
            continue;
        }
        rep(i,4) {
            next_len=pp.fr;
            next_rin=pp.sc;
 
            if(range_check(next_len.fr+dy[i],next_len.sc+dx[i]) && roomL[next_len.fr+dy[i]][next_len.sc+dx[i]]!='#') {
                next_len.fr+=dy[i];
                next_len.sc+=dx[i];
            }
            if(range_check(next_rin.fr+dy[i],next_rin.sc-dx[i]) && roomR[next_rin.fr+dy[i]][next_rin.sc-dx[i]]!='#') {
                next_rin.fr+=dy[i];
                next_rin.sc-=dx[i];
            }
 
            if(!visited[next_len.fr][next_len.sc][next_rin.fr][next_rin.sc]) {
                visited[next_len.fr][next_len.sc][next_rin.fr][next_rin.sc]=true;
                que.push(PP(next_len,next_rin));
            }
        }
    }
 
    return false;
}
 
void solve() {
    rep(y,55) roomL[y]=roomR[y]=string('#',55);
    rep(y,H) cin>>roomL[y]>>roomR[y];
    P len,rin;
    rep(y,H) rep(x,W) {
        if(roomL[y][x]=='L') len=P(y,x);
        if(roomR[y][x]=='R') rin=P(y,x);
    }
    if(ok(len,rin)) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}
 
int main() {
    while(cin>>W>>H) {
        if(!W) break;
        solve();
    }
    return 0;
}

Measured memory_bytes: 11104
#include <iostream>

template<class T> inline bool chmin(T& a, T b) {
  if ( a > b ) {
    a = b;
    return true;
  }
  return false;
}

const long long INF {1LL << 60};
const int MAX_N {110};
const int MAX_V {100100};
int N;
long long W;
long long weights [MAX_N];
long long values [MAX_N];
long long dp[MAX_N][MAX_V];

int main()
{
  std::cin >> N >> W;
  for ( int i = 0; i < N; i++ ) std::cin >> weights[i] >> values[i];
  
  // DP table
  for ( int i = 0; i < MAX_N; i++ ) {
    for ( int j = 0; j < MAX_V; j++ ) {
      dp[i][j] = INF;
    }
  }
  dp[0][0] = 0;

  for (int i = 0; i < N; i++) {
    for (int sum_v = 0; sum_v < MAX_V; sum_v++) {
      if ( sum_v - values[i] >= 0 ) {
        chmin(dp[i+1][sum_v], dp[i][sum_v - values[i]] + weights[i]);
      }
      chmin(dp[i+1][sum_v], dp[i][sum_v]);
    }
  }

  long long ans {0};
  for ( int sum_v = 0; sum_v < MAX_V; sum_v++ ) {
    if ( dp[N][sum_v] <= W ) {
      ans = sum_v;
    }
  }
  std::cout << ans << std::endl;
  return 0;
}


Measured memory_bytes: 86272
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll maxn=2e5+1;
#define MOD 1000000007
void solve()
{
	ll N;
	cin>>N;
	ll a[maxn],ans=1;
	for(ll i=1;i<=N;i++)
	{
		cin>>a[i];
	}
	ll R=-1,G=-1,B=-1;
	for(ll i=1;i<=N;i++)
	{
		ll c=0,doneincr=0;
		if(R==a[i]-1)
		{
			c++;
			R++;
			doneincr=1;
		}
		if(G==a[i]-1)
		{
			c++;
			if(doneincr==0)
			{
				G++;
				doneincr=1;
			}
		}
		if(B==a[i]-1)
		{
			c++;
			if(doneincr==0)
			{
				B++;
				doneincr=1;
			}
		}
		ans=(ans*c)%MOD;
	}
	cout<<ans<<"\n";
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll T=1,p=0;
	//cin>>T;
	do
	{
		solve();
		p++;
	}while(p<T);
	return 0;
}



Measured memory_bytes: 1024
package main

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

var (
	CH_UP   = '/'
	CH_DOWN = '\\'
	CH_FLAT = '_'
)

// Go には Generics ないので仕方なく interface{}
type Stack []interface{}

func (s *Stack) push(v interface{}) {
	*s = append(*s, v)
}

func (s *Stack) top() interface{} {
	return (*s)[len(*s)-1]
}

func (s *Stack) pop() interface{} {
	v := s.top()
	*s = (*s)[:len(*s)-1]
	return v
}

type Pair struct {
	start int
	area  int
}

func main() {
	var s string
	fmt.Scanln(&s)

	starts := Stack(make([]interface{}, 0))
	areas := Stack(make([]interface{}, 0))

	for i, c := range s {
		switch c {
		case CH_DOWN:
			starts.push(i)
		case CH_UP:
			if len(starts) == 0 {
				continue
			}

			start := starts.pop().(int)
			area := i - start

			// 自分の'\'~'/'の範囲に含まれる、自分より下のラインの面積を累計する。
			// これで水溜りごとの面積の合計を出せる。
			for len(areas) > 0 {
				p := areas.top().(Pair)
				if start > p.start {
					break
				}
				area += p.area
				areas.pop()
			}

			areas.push(Pair{start, area})
		}
	}

	total := 0
	for _, p := range areas {
		total += p.(Pair).area
	}

	w := bufio.NewWriter(os.Stdout)
	fmt.Fprintln(w, total)

	fmt.Fprint(w, len(areas))
	for _, p := range areas {
		fmt.Fprintf(w, " %d", p.(Pair).area)
	}
	fmt.Fprintln(w)

	w.Flush()
}



Measured memory_bytes: 3192
MOD = 10 ** 9 + 7
INF = 10 ** 11
import sys
sys.setrecursionlimit(100000000)

def main():
    a,b,c,d = map(int,input().split())
    dx = c - a
    dy = d - b
    print(c - dy,d + dx,a - dy,b + dx)
if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
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 ) *} } ;}
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 ) *} } ;}
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" ) } ;}

fn rec(i: usize, j: usize, k: usize, dp: &mut Vec<Vec<Vec<f64>>>) -> f64 {
   if dp[i][j][k] >= 0.0 {
      dp[i][j][k]
   } else if i == 0 && j == 0 && k == 0 {
      0.0
   } else {
      dp[i][j][k] *= -1.0;
      if i > 0 {
         dp[i][j][k] += rec(i - 1, j, k, dp) * i as f64;
      }
      if j > 0 {
         dp[i][j][k] += rec(i + 1, j - 1, k, dp) * j as f64;
      }
      if k > 0 {
         dp[i][j][k] += rec(i, j + 1, k - 1, dp) * k as f64;
      }
      dp[i][j][k] /= (i + j + k) as f64;
      dp[i][j][k]
   }
}

fn main() {
   input! {
      n: usize,
      a: [usize; n]
   }

   let mut nums = vec![0; 3];
   for &a in a.iter() {
      nums[a - 1] += 1;
   }
   let mut dp = vec![vec![vec![-(n as f64); 305]; 305]; 305];
   let ans = rec(nums[0], nums[1], nums[2], &mut dp);
   println!("{}", ans);
}


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

using namespace std;
using ll = long long;
using ld = long double;

#define ALL(x) begin(x), end(x)
#define REP(i, n) for (size_t i = 0, i##_len = (n); i < i##_len; ++i)

void solve(ll A, ll B, ll C, ll D) {
  cout <<   min(A,B) + min(C,D) << endl;
}

int main() {
  ll A;
  cin >> A;
  ll B;
  cin >> B;
  ll C;
  cin >> C;
  ll D;
  cin >> D;
  solve(A, B, C, D);
  return 0;
}


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

int main()
{
	int a,b,tasu,hiku,kake;
	cin >> a >> b;
	tasu = a + b;
	hiku = a - b;
	kake = a * b;
	if( tasu >= hiku && tasu >= kake )
	{
		cout << tasu << endl;
	}else if( hiku >= tasu && hiku >= kake )
	{
		cout << hiku << endl;
	}else{
		cout << kake << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include <iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<functional>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<numeric>

using namespace std;
typedef long long ll;
typedef pair<int, int>P;

int main(void)
{
	P D[6];
	for (int i = 0; i < 6; i++) {
		cin >> D[i].first >> D[i].second;
	    if (D[i].first > D[i].second)swap(D[i].first, D[i].second);
	}
	int flag = 0;
	sort(D,D+6);
	for (int i = 0; i < 6; i += 2) {
		if (D[i] == D[i + 1])D[i / 2] = D[i];
		else {
			flag = 1;
			cout << "no" << endl;
			break;
		}
	}
	if (!flag) {
		if (D[0].first == D[1].first && D[0].second == D[2].first && D[1].second == D[2].second)
			cout << "yes" << endl;
		else
			cout << "no" << endl;
	}
	return 0;
}

Measured memory_bytes: 3100
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;

typedef long long ll;
//typedef pair<int,int> Pint;
typedef pair<ll, ll> P;
//typedef pair<ll, pair<ll, ll>> P;
//typedef tuple<int,int,int> T;
typedef vector<ll> vec;
typedef vector<vec> mat;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define revrep(i, n) for(ll i = n-1; i >= 0; i--)
#define pb push_back
#define f first
#define s second
const ll INFL = 1LL << 60;//10^18 = 2^60
const int INF = 1 << 30;//10^9
const ll MOD = 1e9 + 7;
//ll MOD  = 998244353;
vector<ll> dy = {0, 0, 1, -1, 1, 1, -1, -1, 0};
vector<ll> dx = {1, -1, 0, 0, 1, -1, 1, -1, 0};

ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll pow_long(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x;
    k /= 2;
  }
  return res;
}

ll pow_mod(ll x, ll k){
  x %= MOD; x += MOD; x %= MOD;
  ll res = 1;
  while(k > 0){
    if(k % 2){
      res *= x; res %= MOD;
    }
    x *= x; x %= MOD;
    k /= 2;
  }
  return res;
}
ll inverse(ll x){return pow_mod(x, MOD - 2);};


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

ll lcm(ll x, ll y){return x / gcd(x, y) * y;};




int main(void){
  ll N;
  cin >> N;
  vector<ll> A(3 * N);
  rep(i, 3 * N) cin >> A[i];
  sort(A.begin(), A.end());
  reverse(A.begin(), A.end());
  ll ans = 0;
  rep(i, N) ans += A[2 * i + 1];
  cout << ans << endl;



}


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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

//MOD
//--------------------------------------------
#define MUL(a,b) (((a) % MOD) * ((b) % MOD)) % MOD

// grid
//--------------------------------------------
VL dx = {0, 1, 0, -1};
VL dy = {1, 0, -1, 0};
VL dx2 = {-1, 0, 1, -1, 1, -1, 0, 1};
VL dy2 = {-1, -1, -1, 0, 0, 1, 1, 1};

//debug
//--------------------------------------------
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//IO accelerate
//--------------------------------------------
struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

//main code

int main(int argc, char const* argv[])
{
	int n;
	cin >> n;
	VL w(n);
	LL s = 0, d = 0;
	for (int i = 0; i < n; i++) {
		cin >> w[i];
		d += w[i];
	}
	LL ans = d;
	for (int i = 0; i < n; i++) {
		s += w[i];
		d -= w[i];
		ans = min(ans, abs(d-s));
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int K,A,B;
  
  scanf("%d",&K);
  scanf("%d %d",&A,&B);

  if(B - B%K >= A){
    printf("OK\n");
  }
  else
    {
      printf("NG\n");
    }
  return 0;
}


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

int chkdigit(int a,int b)
{  
  if(a == 0) {
    if(b == 0) return 0; // yy
    else if(b > 0 && b <= 9) return 1; // yy or mm 
  } else if(a == 1) {
    if(b > 3) return 0; // yy
    else if(b > 0 && b <= 2) return 1; // yy or mm
  } else if(a > 1) {
    return 0; // yy
  }
  
}


int main(void)
{
  char s[4],buf;
  int in,a[4],i;
  scanf("%s",s);
  
  for(i = 0;i < 4;i++) {
    buf = s[i];
    a[i] = atoi(&buf);
  }
  
  int c0,c1;
  c0 = chkdigit(a[0],a[1]);
  c1 = chkdigit(a[2],a[3]);
  
  if(c0 == 0 && c1 == 0) {
    printf("NA\n");
  } else if(c0 == 0 && c1 == 1) {
    printf("YYMM\n");
  } else if(c0 == 1 && c1 == 0) {
    printf("MMYY\n");  
  } else if(c0 == 1 && c1 == 1) {
    printf("AMBIGUOUS\n");
  }

  return 0;
}








Measured memory_bytes: 128
#include <bits/stdc++.h>
 using namespace std;
#define FIO              ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0)
//#define int              long long
#define mod              1000000007
#define eps              1e-9
#define setbits          __builtin_popcount
#define gcd              __gcd
#define rep(i,a,b)       for(int i=a;i<=b;i++)
#define repr(i,b,a)      for(int i=b;i>=a;i--)
#define forn(i,n)        for(int i=0;i<n;i++)
#define all(a)           a.begin(), a.end()
#define pb               push_back
#define endl             "\n"
#define ff               first
#define ss               second
#define asort(c)         sort(all(c)) 
#define lbpos(x,v)       (int)(lower_bound(all(v),x)-v.begin())
#define ubpos(x,v)       (int)(upper_bound(all(v),x)-v.begin())
#define PI               3.14159265358979323846
 using vi = vector<int>;
 using ii = pair<int,int>;
 using vii = vector<ii>;
 using ld = long double;
#define trace(...) ZZ(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void ZZ(const char* name, Arg1&& arg1)
{std::cerr << name << " = " << arg1 << endl;}
template <typename Arg1,typename... Args>void ZZ(const char* names,Arg1&& arg1,
 Args&&... args)
{
  const char* comma = strchr(names + 1, ',');
  std::cerr.write(names, comma - names) << " = " << arg1;
  ZZ(comma, args...);
}
clock_t time_p=clock();
void timer()
{
  time_p=clock()-time_p;
  cerr<<"Execution Time: "<<(double)(time_p)/CLOCKS_PER_SEC<<"\n";
}


int32_t main()
{
  FIO;
  
 
  int n,a,b;
  cin>>n>>a>>b;

  int x=min(a,b);
  int y=max(a+b-n,0);

  cout<<x<<' '<<y;

  timer();
  return 0; 
}   


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define in(s) ll s; cin>>s
#define pr(r) cout<<r<<endl
#define prr(m,n) cout<<m<<" "<<n<<endl
#define prarr(a,i,n) fab(j,i,n) cout<<a[j]<<" "
#define wh(t) ll t; cin>>t; while(t--)
#define sz(u) u.size()
#define all(v) v.begin(),v.end()
#define arr(a,n) vl a(n + 1, 0); fab(i,0,n) cin>>a[i]
#define prs(u) cout<<u<<" "
#define fab(i,a,b) for(ll i=a;i<b;i++)
#define fba(i,b,a) for(ll i=b;i>=a;i--)
#define sup ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define endl "\n"
#define ll long long int
#define vl vector<ll>
#define vpl vector<pair<ll,ll>>
#define pl pair<ll,ll>
#define pll pair<ll,pl>
#define vvl vector<vl>
#define mxe(x,n) *max_element(x,x+n)
#define mne(x,n) *min_element(x,x+n)
#define mp make_pair
#define pb push_back
#define fs first
#define sd second
#define fr front()
#define bk back()
#define rr return
const ll N =(ll)3e5;
const ll inf =(ll)1e18 + 7;
const ll mod =(ll)1e9 + 7;
const ll MX = (ll)1e9 + 7;
const ll MAX = (ll)1e12 + 7;
 
bool rsort1(const pair<ll,ll> &a,const pair<ll,ll> &b) { return (a.first > b.first);}
bool rsort2(const pair<ll,ll> &a,const pair<ll,ll> &b) { return (a.second>b.second);}
bool sort2(const pair<ll,ll> &a,const pair<ll,ll> &b){ return (a.second < b.second);}

void add(ll &x, ll y){
    x = ((x % mod) + (y % mod)) % mod;
}

void mul(ll &x, ll y){
    x = ((x % mod) * (y % mod)) % mod;
}
 
bool isPrime(ll p)
{
    for(ll i = 2;i * i <= p; i++)
        if(p % i == 0)
            rr false;
    rr true;
}
 
void sieve(ll n,vl &v)
{
    v.pb(2);
    bool prime[n + 1];
    memset(prime, true, sizeof(prime));
    for(ll i = 3;i * i <= n; i += 2)
        if(prime[i])
            for(ll j = i; j * i <= n; j += 2)
                prime[j * i] = false;
        
    for(ll i = 3; i <= n; i += 2)
        if(prime[i])
            v.pb(i);
}

ll phi(ll n)
{
    ll result = n;
    for(ll p = 2; p * p <= n; p++)
    {
        if(n % p == 0)
        {
            while(n % p == 0)
                n /= p;
            result -= result/p;
        }
    }

    if(n > 1)
        result -= result/n;
    return result;
}

ll nCr(ll n, ll k) 
{ 
    vl C(k + 1, 0); 
    ll i, j; 
    C[0] = 1; 
    for (i = 1; i <= n; i++) { 
        for (j = min(i, k); j > 0; j--) { 
            add(C[j], C[j - 1]); 
        } 
    }
    return C[k] % mod; 
}


int main()
{
	sup;
    
    in(n);
    arr(a, n);
    map<ll, ll> m;
    fab(i, 0, n) {
        m[a[i]]++;
        if(m[a[i]] > 1) {
            pr("NO");
            rr 0;
        }
    }
    pr("YES");
    return 0;
}

Measured memory_bytes: 14336
/*
  Author - KISHAN TIWARI
  Dream bigger. Do bigger.
  Wake up with determination. Go to bed with satisfaction.
*/
//Sometimes later becomes never. Do it now.
#include<bits/stdc++.h>
using namespace std;
#define ll           long long
#define f(i,a,b)     for(ll i=a;i<b;i++)
#define mod          1000000007
#define fi           first
#define se           second
#define pa           pair <ll,ll>
#define mp           make_pair
#define pb           push_back
#define ve           vector<ll>
#define vep          vector< pa >
#define all(a)       a.begin(), a.end()
#define sz(x)        (ll)x.size()
#define c(t)         cout<<t<<"\n"
using namespace std;
void solve()
{  string s,t;
cin>>s>>t;
ll co=0;
f(i,0,3)
{
    if(s[i]==t[i])
        co++;
}
c(co);
}
int main()
{
    ios::sync_with_stdio(true);
   //freopen ("input.txt","r",stdin);
   //freopen ("output.txt","w",stdout);
    cin.tie(0);
    cout.tie(0);
    ll t=1;
    //cin>>t;
    while(t--)
    {

        solve();
    }
return 0;
}


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

using namespace std;
long long int arr[100000000];
int main()
{
    int n;
    scanf("%d",&n);
    int counter=0;
    for(int i=0; i<n; i++)
    {
        int p,q;
        scanf("%d",&p);
        if(p==0)
        {
            scanf("%lld",&arr[counter]);
            counter++;
        }
        else if(p==1)
        {
            long long int h;
            scanf("%lld", &h);
            printf("%lld\n", arr[h]);
        }
        else if(p==2)
        {
            counter--;
        }
    }
}



Measured memory_bytes: 4692
#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>;
#define chmax(x,y) x = max(x,y);
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};
const int INF = 1001001001;

int main() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    int l = 0, r = n-1;
    int cnt = 0;
    while (l < r) {
      if (s[l] == 'W') {
        if (s[r] == 'W') r--;
        else {
          cnt++;
          l++; r--;
        }
      } else {
        if (s[l] == 'W') {
          l++; r--;
        } else {
          l++;
        }
      }      
    }
    cout << cnt << endl;
    return 0;
}

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

int main() {
  int L,R,d;
  cin >> L >> R >> d;
  
  int LK,RK;
  LK=L/d;
  RK=R/d;
  if (L % d==0) {
    LK-=1;
  }
  cout << RK-LK << endl;
  
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007 

int main() {
	ll n;
	vector<tuple<string,ll,ll>>a;
	cin>>n;
	for(ll i=0;i<n;i++){
		string x;
		ll y,z;
		cin>>x>>y;
		z=i+1;
		y*=-1;
		a.push_back(make_tuple(x,y,z));
	}
	sort(a.begin(),a.end());
	for(ll i=0;i<n;i++){
		cout << get<2>(a[i])<<endl;
	}
	// your code goes here
	return 0;
}

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

int main() {
	int N;
	cin >> N;
	string S;
	string tmp;
	while(abs(N)>0){
		if(N%(-2)==0){
			tmp=S;
			S="0";
			S+=tmp;
			N/=(-2);
		}
		else{
			tmp=S;
			S="1";
			S+=tmp;
			N--;
			N/=(-2);
		}
	}
	if(S.size()==0)S="0";
	cout<<S<<endl;
}





Measured memory_bytes: 256
#include <stdio.h>
int n,k,line[1000000];
int binarySearch(int bw){
    int i,temp,t=1;
    for(i=0,temp=0;i<n;i++){
        if(line[i] > bw)
            return 0;
        if(temp+line[i] > bw){
            t++;
            temp=0;
        }
        temp+=line[i];
    }
    return t<=k;
}
int main(){
  int left=0,right=(1<<31),mid,i;
    scanf("%d %d",&n,&k);
    for(i=0;i<n;i++)
        scanf("%d",&line[i]);
    for(right=~right;left<right;){
        mid=(right+left)/2;
        if(binarySearch(mid))
            right=mid;
        else
            left=mid+1;
    }
    printf("%d\n",right);
    return 0;
}

Measured memory_bytes: 984
N,u,v=list(map(int,input().split()))
g=[[] for _ in range(N+1)]

def dist(x):
    dist=[-1]*(N+1)
    dist[x]=0
    stack=[x]
    while len(stack)>0:
        current=stack.pop()

        for s in g[current]:
            if dist[s]>-1:
                continue

            dist[s]=dist[current]+1
            stack.append(s)

    return dist

for _ in range(N-1):
    a,b=list(map(int,input().split()))

    g[a].append(b)
    g[b].append(a)

du=dist(u)
dv=dist(v)

ans=0

for i in range(1,N+1):
    if du[i]<=dv[i]:
        ans=max(ans,dv[i]-1)

print(ans)

Measured memory_bytes: 98600
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#define ll long long
#define INF 1000000007
using namespace std;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int size=s.size();
    for(int i=0;i<size;i++) {
        s.pop_back();
        int ss=s.size();
        if (s.substr(0, ss / 2) == s.substr(ss / 2, ss / 2)) {
            cout << ss - 1 << endl;
            return 0;
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
using namespace std;
void solve()
{
    int n;
    cin>>n;
    map<string,int>mp;
    while(n--)
    {
        string s;
        cin>>s;
        mp[s]++;
    }
    cout<<"AC x "<<mp["AC"]<<endl<<"WA x "<<mp["WA"]<<endl<<"TLE x "<<mp["TLE"]<<endl<<"RE x "<<mp["RE"];

}

int main()
{
    fast;
    int t;
    solve();
}


Measured memory_bytes: 3664
{$APPTYPE CONSOLE}

var
  a, b, h, m: Integer;
  rad_h, rad_m: Double;
  x_h, y_h, x_m, y_m: Double;
  answer: Double;

begin
  read(a);
  read(b);
  read(h);
  read(m);

  rad_h := 2 * Pi * (h / 12) + (2 * Pi * (m / 60) * 1/12);
  rad_m := 2 * Pi * (m / 60);

  x_h := Cos(rad_h) * a;
  y_h := Sin(rad_h) * a;

  x_m := Cos(rad_m) * b;
  y_m := Sin(rad_m) * b;

  answer := Sqrt(Sqr(x_h - x_m) + Sqr(y_h - y_m));

  writeln(answer);
end.

Measured memory_bytes: 1384
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
using namespace std;
int main(){
	int n;
	cin>>n;
	int ans=0;
	for(int i=0;i<n;i++){
		int x;
		cin>>x;
		ans+=x-1;
	}
	cout<<ans<<endl;
}

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

int main()
{
	int x, y;
	string str;
	cin >> str;
	x = stoi(str.substr(0, 2));
	y = stoi(str.substr(2, 2));
	
	if(x == 0 || x > 12){
		if(y == 0 || y > 12) cout << "NA" << endl;
		else cout << "YYMM" << endl;
	}

	else {
		if(y == 0 || y > 12) cout << "MMYY" << endl;
		else cout << "AMBIGUOUS" << endl;
	}
}

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

//UnionFind
int n = 200000;
vector<int> par(n);
vector<int> Size(n);

void init(int n){
  for(int i=0; i<n; i++){
    par.at(i) = i;
    Size.at(i) = 1;
  }
}

int root(int x){
  if(par.at(x) == x){
    return x;
  }
  else{
    return par.at(x) = root(par.at(x));
  }
}

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

void unite(int x, int y){
  x = root(x);
  y = root(y);
  if(x == y){
    return;
  }
  if (Size.at(x) < Size.at(y)){
    swap(x, y);
  }
  Size.at(x) += Size.at(y);
  par.at(y) = x;
}

int Size_x(int x){
  return Size.at(root(x));
}


int main(){
  int N, M;
  cin >> N >> M;
  
  init(N);
  
  for(int i=0; i<M; i++){
    int a, b;
    cin >> a >> b;
    a--; b--;
    unite(a,b);
  }
  
  int ans = 0;
  for(int i=0; i<N; i++){
    ans = max(ans,Size_x(i));
  }
  cout << ans << endl;
}

Measured memory_bytes: 4664
#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0
#define ll long long

ll a, b, v, w, t;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> a >> v >> b >> w >> t;
    if(a > b) swap(a, b);
    a += v * t;
    b += w * t;
    if(a >= b) cout << "YES\n";
    else cout << "NO\n";
}


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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(ll i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 30

signed main()
{
    string S;
    string correct = "CODEFESTIVAL2016";
    int ans = 0;
    cin >> S;
    REP(i, S.length()) {
        if(S[i] != correct[i]) { ans++; }
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 256
from collections import deque
n, m = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(m)]

q = deque([])
path = [-1] * n
ver = [[] for _ in range(n)]
for i in range(m):
    ab[i].sort()
    if ab[i][0] == 1:
        q.append([ab[i][0]-1,ab[i][1]-1])
        #path[ab[i][1]-1] = 1
    ver[ab[i][0]-1].append(ab[i][1]-1)
    ver[ab[i][1]-1].append(ab[i][0]-1)

#print(ver)
def bfs(q, visited_list):
    while len(q) > 0:
        now = q.popleft()
        go = now[1]
        #print(q)
        if path[go] == -1:
            path[go] = now[0]+1
            for i in range(len(ver[go])):
                q.append([go,ver[go][i]])
    return path
ans = bfs(q,path)
print('Yes')
for i in range(1,n):
    print(ans[i])

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


const int N=1e6,OO = 0x3f3f3f3f;
int d()
{
    int ret;
    scanf("%d", &ret);
    return ret;
}
long long lld()
{
    long long ret;
    scanf("%lld", &ret);
    return ret;
}
bool isplaind(int n){
    string s=to_string(n);
    string s1="";
    for(int i=s.length()-1;i>=0;i--)
        s1+=s[i];
    return (s==s1);
}
int main(){
    int a=d(),b=d();
    int ans=0;
    for(int i=a;i<=b;i++)
    if(isplaind(i))ans++;
    printf("%d\n",ans);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
int main(void){
	int n;
	cin >> n;
	P f[n];
	for(int i = 0; i < n; i++){
		int a;
		cin >> a;
		f[i] = P(a, i + 1);
	}
	sort(f, f + n);
	cout << f[0].second;
	for(int i = 1; i < n; i++) cout << ' ' << f[i].second;
	cout << endl;
	return 0;
}

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

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

    if(a<b){
        swap(a,b);
    }
    if(b<c){
        swap(b,c);
    }
    if(a<b){
        swap(a,b);
    }
    cout << 10*a+b+c << endl;
    return 0 ;
}



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

int main(){
	int a,b;
	cin >> a >> b;

		if( a == b )
		{
		cout << "a == b" << endl;
		}else{
			if(a > b)
			{
			cout << "a > b" << endl;
			}else{
			cout << "a < b" << endl;
			}
		}
}



Measured memory_bytes: 3080
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define sz(x) int(x.size())
#define pb push_back
#define eb emplace_back
using ll=long long;
using P = pair<ll,int>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
const ll MOD=1000000007,MOD2=998244353;



int main() {
    int P,Q,R;
    cin>>P>>Q>>R;
    int sum=P+Q+R;
    cout<<sum-max(max(P,Q),R)<<endl;
}

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

int main() {
  int n, m; std::cin >> n >> m;
  std::vector<int> a(n);
  for (int i = 0; i < n; ++i) std::cin >> a[i];
  int sum = std::accumulate(a.begin(), a.end(), 0);
  int cnt = 0;
  for (int i = 0; i < n; ++i)
    if (a[i] >= ((double)sum / (4*m))) ++cnt;
  
  if (cnt >= m) std::cout << "Yes" << std::endl;
  else std::cout << "No" << std::endl;
  
  return 0;
  
}

Measured memory_bytes: 3620
#include<stdio.h>
#include<stdlib.h>
void mergeSort(int *,int,int);
int count=0;
int main(){
  int i,A[500000],L,R;
  scanf("%d",&R);
  for(i=0;i<R;i++)scanf("%d",&A[i]);
  mergeSort(A,0,R);
  for(i=0;i<R;i++){
    if(i<R-1)printf("%d ",A[i]);
    else printf("%d\n",A[i]);
  }
  printf("%d\n",count);
  return 0;
}

void mergeSort(int *array,int L,int R){
  int i,l,r,Lnum,Rnum;
  int *array2;
  
  if(L+1 < R){
    mergeSort(array,L,(L+R)/2);
    mergeSort(array,(L+R)/2,R);
  
    array2=malloc(sizeof(int)*(R-L));
    l=L;
    r=(L+R)/2;
    for(i=0;i<R-L;i++){
      count++;
      if(l==((L+R)/2)){
	array2[i] = array[r];
	r++;
	
      }
      else if(r==R){
	array2[i] = array[l];
	l++;
	
      }
      else if(array[l]<=array[r]){
	array2[i] = array[l];
	l++;
	
      }
      else {
	array2[i] = array[r];
	r++;

      }
    }
    for(i=L;i<R;i++){
      array[i]=array2[i-L];
    }
    free(array2);
  }
}


Measured memory_bytes: 6344
#include<iostream>
#include<vector>
#include<string>
using namespace std;
int main(){
    int n,m;
    while(cin >> n >> m,n){
        vector<string> s(n);
        vector<int> num(n);
        for(int i = 0; i < n; i++)cin >> s[i] >> num[i];
        int ans = 0;
        while(m--){
            string t;
            cin >> t;
            for(int i = 0; i < n; i++){
                bool c = true;
                for(int j = 0; j < 8; j++){
                    if(s[i][j] != '*' && t[j] != s[i][j])c = false;
                }
                if(c)ans += num[i];
            }
        }
        cout << ans << endl;
    }
}



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

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int getRand(int l, int r)
{
    uniform_int_distribution<int> uid(l, r);
    return uid(rng);
}
  
#define int long long 
#define pb push_back
#define S second
#define F first
#define f(i,n) for(int i=0;i<n;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vi vector<int>
#define pii pair<int,int>
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define precise(x) fixed << setprecision(x) 

const int MOD = 998244353;

int mod_pow(int a,int b,int M = MOD)
{
    int res = 1;
    
    while(b)
    {
        if(b&1) res=(res*a)%M;
        a=(a*a)%M;
        b>>=1;
    }
    
    return res;
}

const int N = 2e5 + 10;

vector<int> fact(N),ifact(N);


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

void precalc()
{
    //Factorial and Inverse Factorial
    fact[0] = 1;
    for(int i=1;i<N;i++) fact[i] = mod_mul(fact[i-1],i);
        
    ifact[N-1] = mod_pow(fact[N-1],MOD-2);
    for(int i=N-2;i>=0;i--) ifact[i] = mod_mul(ifact[i+1],i+1);
}

int ncr(int n,int k)
{
    if(k>n) return 0;
    return mod_mul(fact[n],mod_mul(ifact[n-k],ifact[k]));
}

int get(int n,int m)
{
    int res = m;
    res = (res*mod_pow(m-1,n-1))%MOD;
    return res;
}

void solve()
{
    int n,m,k;
    cin >> n >> m >> k;
    
    int res = 0;
    
    for(int i=0;i<=k;i++)
    {
        res = (res + mod_mul(get(n-i,m),ncr(n-1,i)))%MOD;
    }
    
    cout << res;
}

signed main()
{
    fast;
    precalc();
    
    int t = 1;
    
//    cin >> t;
    
    while(t--)
        
    solve();
}

Measured memory_bytes: 6332
#include<bits/stdc++.h>
#define llong __int128
#define mkpr make_pair
#define x first
#define y second
#define iter iterator
#define riter reversed_iterator
#define y1 Lorem_ipsum_
#define tm dolor_sit_amet_
using namespace std;

inline int read()
{
	int x = 0,f = 1; char ch = getchar();
	for(;!isdigit(ch);ch=getchar()) {if(ch=='-') f = -1;}
	for(; isdigit(ch);ch=getchar()) {x = x*10+ch-48;}
	return x*f;
}

map<llong,llong> mp;
llong n,A,B,C,D;

void read128(__int128 &x) {long long y; scanf("%lld",&y); x = y;}

llong absl(llong x) {return x<0?-x:x;}

void updmin(llong &x,llong y) {x = min(x,y);}

void dfs(llong x)
{
	if(mp.count(x)) {return;}
	llong ret = x*D,t;
	t = x/2ll; dfs(t); updmin(ret,mp[t]+min((x-t)*D,A+(x-t*2ll)*D));
	t = (x+1)/2ll; dfs(t); updmin(ret,mp[t]+min((x-t)*D,A+(t*2ll-x)*D));
	t = x/3ll; dfs(t); updmin(ret,mp[t]+min((x-t)*D,B+(x-t*3ll)*D));
	t = (x+2)/3ll; dfs(t); updmin(ret,mp[t]+min((x-t)*D,B+(t*3ll-x)*D));
	t = x/5ll; dfs(t); updmin(ret,mp[t]+min((x-t)*D,C+(x-t*5ll)*D));
	t = (x+4)/5ll; dfs(t); updmin(ret,mp[t]+min((x-t)*D,C+(t*5ll-x)*D));
	mp[x] = ret;
	return;
}

int main()
{
	int T = read(); while(T--)
	{
		read128(n),read128(A),read128(B),read128(C),read128(D);
		mp.clear(); mp[0] = 0ll; mp[1] = D;
		dfs(n);
		printf("%lld\n",(long long)mp[n]);
	}
	return 0;
}

Measured memory_bytes: 4712
#include <stdio.h>

int gcd(int a,int b){
	return b ? gcd(b, a % b) : a;
}
int main()
{
  int k; scanf ("%d",&k); int a =0;
  for (int i=1;i<=k;i++) for (int j=1;j<=k;j++) for (int l=1;l<=k;l++) a += gcd(i,gcd(j,l));
  printf ("%d\n",a);
return 0;
}

Measured memory_bytes: 3156
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int dx[] = { 0, 1, -1, 0, 1, -1, 1, -1 };  // i<4:4way i<8:8way
int dy[] = { 1, 0, 0, -1, 1, -1, -1, 1 };

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    string s;
    cin >> s;
    rep(i,s.size()){
        if(s[i]=='h'&&s[i+1]=='i')i++;
        else{
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 256
//#pragma warning disable
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System;
using System.Numerics;
using System.Threading.Tasks;
using static System.Math;
using static System.Console;
class Z { static void Main() => new K(); }
class K
{
	int F() => int.Parse(ReadLine());
	long FL() => long.Parse(ReadLine());
	int[] G() => ReadLine().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
	long[] GL() => ReadLine().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries).Select(long.Parse).ToArray();
	public const int MOD = 1000000007;
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	void Solve()
	{
		var N = F();
		var a = G();
		long p = Abs(a[0]) + Abs(a[N - 1]);
		for (var i = 1; i < N; i++) p += Abs(a[i] - a[i - 1]);
		WriteLine(p - Abs(a[0]) - Abs(a[0] - a[1]) + Abs(a[1]));
		for (var i = 1; i + 1 < N; i++) WriteLine(p - Abs(a[i] - a[i - 1]) - Abs(a[i] - a[i + 1]) + Abs(a[i + 1] - a[i - 1]));
		WriteLine(p - Abs(a[N - 1]) - Abs(a[N - 1] - a[N - 2]) + Abs(a[N - 2]));
	}
}


Measured memory_bytes: 28124
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet};
#[allow(unused_imports)]
use std::io::*;
#[allow(unused_imports)]
use std::str::*;

#[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)*}
    };

    ($iter:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($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(dead_code)]
fn read<T: FromStr>() -> T {
    let cin = stdin();
    let cin = cin.lock();
    let s: String = cin
        .bytes() // Bytes
        .map(|c| c.expect("failed reading char") as char)
        .skip_while(|c| c.is_whitespace()) // c が whitespace である限り skip
        .take_while(|c| !c.is_whitespace()) // c が whitespace でない限り要素を返す
        .collect();
    s.parse().ok().expect("failed parsing")
}

#[allow(non_snake_case)]
fn main() {
    input! {
        N:usize,
        S:[String;N]
    }

    let mut h = HashSet::new();
    for i in 0..N {
        h.insert(&S[i]);
    }
    println!("{}", h.len());
}


Measured memory_bytes: 16468
#include<stdio.h>
#include<string.h>

int main(){
	
	int tamanhodea,tamanhodeb;
	
	char a[100];
	char b[100];
	char c[100];
	
	scanf("%s %s %s",&a,&b,&c);
	
	tamanhodea = strlen(a);
	tamanhodeb = strlen(b);
	
	if (a[tamanhodea-1] == b[0] && b[tamanhodeb-1] == c[0]){
		printf("YES\n");
	}else{
		printf("NO\n");
	}
	
	return 0;
}


Measured memory_bytes: 128
loop do
  n, m = gets.split.map &:to_i
  break if n+m == 0
  c = {0=>0}
  n.times{
    b = gets.to_i 2
    c.dup.each{|k, v| c[k ^ b] = v+1 if !c[k ^ b] || c[k ^ b] < v+1}
  }
  p c[0]
end

Measured memory_bytes: 185112