akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
using namespace std;

class Dice
{
  private:
    int top, front, right, left, back, bottom, temp;

  public:
    void set(int *nums)
    {
        this->top = nums[0];
        this->front = nums[1];
        this->right = nums[2];
        this->left = nums[3];
        this->back = nums[4];
        this->bottom = nums[5];
    }
    int getTop() { return this->top; }
    int getFront() { return this->front; }
    int getRight() { return this->right; }
    int getLeft() { return this->left; }
    int getBack() { return this->back; }
    int getBottom() { return this->bottom; }
    void east()
    {
        this->temp = this->top;
        this->top = this->left;
        this->left = this->bottom;
        this->bottom = this->right;
        this->right = this->temp;
    }
    void west()
    {
        this->temp = this->top;
        this->top = this->right;
        this->right = this->bottom;
        this->bottom = this->left;
        this->left = this->temp;
    }
    void north()
    {
        this->temp = this->top;
        this->top = this->front;
        this->front = this->bottom;
        this->bottom = this->back;
        this->back = this->temp;
    }
    void south()
    {
        this->temp = this->top;
        this->top = this->back;
        this->back = this->bottom;
        this->bottom = this->front;
        this->front = this->temp;
    }
};

void alignRollOfDice(Dice &dice, int top, int front)
{
    if (dice.getTop() == top && dice.getFront() == front)
    {
        return;
    }
    else
    {
        if (dice.getRight() != front && dice.getLeft() != front)
        {
            while (dice.getFront() != front)
            {
                dice.south();
            }
        }
        else
        {
            if (dice.getRight() == front)
            {
                dice.west();
                dice.south();
            }
            else
            {
                dice.east();
                dice.south();
            }
        }

        if (dice.getTop() != top)
        {
            while (dice.getTop() != top)
            {
                dice.east();
            }
        }

        return;
    }
}

int main(int argc, char *argv[])
{
    Dice firstDice, secondDice;
    int nums[6];
    for (int i = 0; i < 6; i++)
        cin >> nums[i];
    firstDice.set(nums);
    for (int i = 0; i < 6; i++)
        cin >> nums[i];
    secondDice.set(nums);

    alignRollOfDice(secondDice, firstDice.getTop(), firstDice.getFront());

    if (firstDice.getTop() != secondDice.getTop()) { cout << "No" << endl; return 0; }
    if (firstDice.getFront() != secondDice.getFront()) { cout << "No" << endl; return 0; }
    if (firstDice.getRight() != secondDice.getRight()) { cout << "No" << endl; return 0; }
    if (firstDice.getLeft() != secondDice.getLeft()) { cout << "No" << endl; return 0; }
    if (firstDice.getBack() != secondDice.getBack()) { cout << "No" << endl; return 0; }
    if (firstDice.getBottom() != secondDice.getBottom()) { cout << "No" << endl; return 0; }
    cout << "Yes" << endl;

    return 0;
}


Measured memory_bytes: 3136
{-# LANGUAGE OverloadedStrings #-}
module Main where

import           Data.List
import           Control.Monad
import           Debug.Trace
import qualified Data.ByteString.Char8         as BC
import           Data.Maybe                     ( fromJust )
import qualified Data.Set                      as S
import qualified Data.IntMap.Strict            as IM
import qualified Data.Map.Strict            as M
import           Data.Char


readTuple2 :: IO (Int, Int)
readTuple2 = do
    [a, b] <- map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine
    return (a, b)

readTuple3 :: IO (Int, Int, Int)
readTuple3 = do
    [a, b, c] <- map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine
    return (a, b, c)

readInt :: IO Int
readInt = fst . fromJust . BC.readInt <$> BC.getLine

readInts :: IO [Int]
readInts = map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine

split :: (a -> Bool) -> [a] -> [[a]]
split f [] = []
split f as =
    let (fo, la) = span f as
        las      = case la of
            [] -> []
            xs -> split f $ tail xs
    in  case fo of
            [] -> las
            xs -> xs : las

solve :: Int -> [Int] -> [Int] -> Int
solve n ps qs =
    let
        intListToStr xs = intercalate "" $ show <$> xs
        nList = sort $ intListToStr <$> permutations [1..n]
        listAndOrder = M.fromList $ zip nList [1..]
        pstr = intListToStr ps
        qstr = intListToStr qs
    in
    abs $ (listAndOrder M.! pstr ) - (listAndOrder M.! qstr)


main = do
    (n, m) <- readTuple2
    let ansn = max 0 $ (n * (n - 1)) `div` 2
    let ansm = max 0 $ (m * (m - 1)) `div` 2
    print $ ansn + ansm





Measured memory_bytes: 380
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std;
typedef long long ll;

int main(void){
    ll n, w[105], s1 = 0, s2 = 0;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> w[i];
        s2 += w[i];
    }
    
    ll ans = 1e9;
    for (int i = 0; i < n; i++) {
        s1 += w[i];
        s2 -= w[i];
        ans = min(ans, abs(s1 - s2));
    }
    
    cout << ans << endl;
    
    
}


Measured memory_bytes: 256
def modpow(a, n, mod):
    bi = format(n, 'b')
    res = 1
    for i in range(len(bi)):
        res = (res * res) % mod
        if bi[i] == '1':
            res = (res * a) % mod
    return res

N = int(input())
D = list(map(int, input().split()))
mod = 998244353

L = [0] * (max(D) + 1)
for d in D:
    L[d] += 1

if (L[0] != 1) | (D[0] != 0):
    ans = 0
else:
    ans = 1
    for i in range(len(L)-1):
        ans *= modpow(L[i], L[i+1], mod)
        ans %= mod

print(ans)

Measured memory_bytes: 14396
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,x;
    cin>>x>>a>>b;
    if(a>=b)
    {
        cout<<"delicious"<<endl;
        return 0;
    }
    else if(b>a+x)
    {
        cout<<"dangerous"<<endl;
        return 0;
    }
    else
    {
        cout<<"safe"<<endl;
        return 0;
    }
}

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

input = sys.stdin.readline


def S():
    return input().rstrip()


def I():
    return int(input())


def MI():
    return map(int, input().split())


n, k = MI()
p = list(MI())
c = list(MI())

p.insert(0, 0)
c.insert(0, 0)

ans = -float("INF")
for i in range(1, n + 1):
    next = p[i]
    score = 0
    MAX = -float("INF")

    for j in range(1, k + 1):
        score += c[next]
        MAX = max(MAX, score)
        if next == i:
            loop_score = score
            loop_size = j
            if loop_score > 0:
                q, r = divmod(k, loop_size)
                # 周れるだけ周る-1+余りの回数で最大となるマス動く
                score1 = loop_score * (q - 1) + MAX
                # 周れるだけ周る+余りの回数で最大となるマス動くとき
                score2 = loop_score * q
                MAX = score2
                next = p[i]
                for _ in range(1, r + 1):
                    score2 += c[next]
                    MAX = max(MAX, score2)
                    next = p[next]
                score = max(score1, MAX)
                break
            else:
                # 一周未満
                score = MAX
                break
        else:
            next = p[next]
    else:
        score = MAX

    ans = max(ans, score)


print(int(ans))


Measured memory_bytes: 74704
// Daniel Grzegorzewski
// while (clock()<=69*CLOCKS_PER_SEC)
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")

#define MP make_pair
#define PB push_back
#define ST first
#define ND second

using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

//X.find_by_order(k); - zwraca iterator na k-ty element (numeracja od zerowego)
//X.order_of_key(k); - zwraca liczbę elementów ostro mniejszych niż k

typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VII;
typedef long long LL;

void init_ios() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
}

int n, res;

int hm(int x) {
  int res = 0;
  while (x) {
    x /= 10;
    ++res;
  }
  return res;
}

int main() {
  init_ios();
  cin >> n;
  for (int i = 1; i <= n; ++i)
    if (hm(i)&1)
      ++res;
  cout<<res<<"\n";
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {

    public static void main(String[] args) {
       Scanner sc = new Scanner(System.in);
       int x = 0;
       int count = 1;
       while(sc.hasNext()){
           x = sc.nextInt();
           if(x ==0){
               return;
           }
           System.out.println("Case "+count+": "+ x);
           count++;
       }

       sc.close();
    }

}



Measured memory_bytes: 43112
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define BIG 1000000010
#define EPS 1e-9
#define fst first
#define scd second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long


signed main(){
  int n;
  cin>>n;
  cout<<(n-2)*180<<endl;
  
  return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

const (
	initialBufSize = 1e4
	maxBufSize     = 1e6 + 7
)

var buf []byte = make([]byte, maxBufSize)
var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf, maxBufSize)
}

func main() {
	N := nextInt()
	if N == 1 {
		fmt.Println("Yes")
		return
	}
	// prev := nextInt()
	lowerable := true
	// max := int(1e9) + 1
	Hn := make([]int, N)
	Hn[0] = nextInt()
	for i := 1; i < N; i++ {
		Hn[i] = nextInt()
		d := Hn[i] - Hn[i-1]
		if d >= 1 {
			Hn[i]--
			lowerable = false
		} else if d == 0 {
			lowerable = true
		} else if d == -1 && lowerable {
			lowerable = false
			Hn[i-1]--
		} else {
			fmt.Println("No")
			return
		}
	}
	// fmt.Println(Hn)
	for i := 1; i < N; i++ {
		if Hn[i-1] > Hn[i] {
			fmt.Println("No")
			return
		}
	}
	fmt.Println("Yes")
	// for i := 1; i < N; i++ {
	// 	cur := nextInt()
	// 	d := cur - prev
	// 	// if d >= 2 || d <= -2 {
	// 	// 	fmt.Println("No")
	// 	// 	return
	// 	// }
	// 	if d == 1 {
	// 		Hn[i-1], Hn[i] = prev, cur
	// 		prev = cur
	// 		lowerable = true
	// 	} else if d == -1 && lowerable {
	// 		Hn[i-1], Hn[i] = prev-1, cur
	// 		prev = cur
	// 		lowerable = false
	// 	} else if d == 0 || d >= 2 {
	// 		Hn[i-1], Hn[i] = prev, cur
	// 		prev = cur
	// 		lowerable = true
	// 	} else {
	// 		fmt.Println("No")
	// 		return
	// 	}
	// 	// fmt.Println(cur, prev, lowerable)
	// }
	// fmt.Println("Yes")
}

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

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func abs(a int) int {
	if a > 0 {
		return a
	} else {
		return -a
	}
}

func pow(p, q int) int {
	res := p
	if q == 0 {
		return 1
	}
	for i := 0; i < q-1; i++ {
		res *= p
	}
	return res
}

func MinOf(vars ...int) int {
	min := vars[0]
	for _, i := range vars {
		if min > i {
			min = i
		}
	}
	return min
}

func MaxOf(vars ...int) int {
	max := vars[0]
	for _, i := range vars {
		if max < i {
			max = i
		}
	}
	return max
}

func gcdof2numbers(a int, b int) int {
	if b == 0 {
		return a
	}
	return gcdof2numbers(b, a%b)
}

func lcmof2numbers(a int, b int) int {
	return a / gcdof2numbers(a, b) * b
}

// マイナスの場合は考慮していない
func fuctorial(a int) int {
	if a == 1 || a == 0 {
		return 1
	} else {
		return fuctorial(a-1) * a
	}
}

func NextPermutation(x sort.Interface) bool {
	n := x.Len() - 1
	if n < 1 {
		return false
	}
	j := n - 1
	for ; !x.Less(j, j+1); j-- {
		if j == 0 {
			return false
		}
	}
	l := n
	for !x.Less(j, l) {
		l--
	}
	x.Swap(j, l)
	for k, l := j+1, n; k < l; {
		x.Swap(k, l)
		k++
		l--
	}
	return true
}

// 素因数分解したmapを返す
func primeFuctorize(n int) map[int]int {
	pf := map[int]int{}
	for i := 2; i*i <= n; i++ {
		for n%i == 0 {
			pf[i]++
			n /= i
		}
	}
	if n != 1 {
		pf[n]++
	}
	return pf
}


Measured memory_bytes: 5236
import sys
N = int(input())
l = list(map(int, input().split()))

flg = 0
for i in range(N):
    if i+1 != l[i]:
        flg += 1
        l[l[i]-1] = l[i]
    if flg >= 2:
        print('NO')
        sys.exit()
print('YES')


Measured memory_bytes: 38384
#include<cstdio>
int main(){
	int n,a[100002],def=0,m;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
	}
	a[0]=0;
	a[n+1]=0;
	for(int i=0;i<=n;i++){
		if(a[i+1]-a[i]>=0){
			def += a[i+1]-a[i];
		}
		else{
			def += a[i]-a[i+1];
		}
	}
	for(int i=1;i<=n;i++){
		if((a[i]-a[i-1])*(a[i]-a[i+1])<=0){
			printf("%d\n",def);
		}
		else{
			int l,k;
			l=a[i]-a[i-1];
			k=a[i]-a[i+1];
			if(l>0){
				if(l<k){
					m=l;
				}
				else{
					m=k;
				}
			}
			else{
				if(0-l<0-k){
					m=0-l;
				}
				else{
					m=0-k;
				}
			}
			printf("%d\n",def-2*m);
		}
	}
}


Measured memory_bytes: 1536
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
//#define mt make_tuple
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef ll Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
//typedef tuple<int,int,int> tp;
//typedef vector<tp> vt;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-7;
const int inf=1e9;
const ll INF=2e18;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	int n;
	cin>>n;
	string s="";
	rep(i,n){
		string c;
		cin>>c;
		s+=c;
	}
	rep(i,10000){
		if(s.find(to_string(i))==string::npos){
			cout<<i<<endl;
			break;
		}
	}
}

Measured memory_bytes: 3264
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <string.h>

#define rep(i,n,m) for(int i=n; i<=m; i++)
#define per(i,n,m) for(int i=n; i>=m; i--)
#define print(x) printf("%d ", x);
#define println(x) printf("%d\n", x);
#define printarray(a,n) for(int i=0; i<n-1; i++){printf("%d ", a[i]);} printf("%d\n", a[n-1]);
#define scan(x) scanf("%d", &x);
#define scanarray(a,n) for(int i=0; i<n; i++){scanf("%d", &a[i]);}

int main () {

    std::vector<int> s;
    char str[7];
    int a,b;
    int length = 0;
    while(scanf("%s", str) != EOF) {
        if(str[0] == '+') {
            b = s[--length];
            a = s[--length];
            s[length] = a+b;

        }
        else if(str[0] == '-') {
            b = s[--length];
            a = s[--length];
            s[length] = a-b;
        }
        else if(str[0] == '*') {
            b = s[--length];
            a = s[--length];
            s[length] = a*b;
        } else {
            if(length >= s.size()) s.push_back(atoi(str));
            else s[length] = atoi(str);
        }
        length++;

    }


    std::cout << s[0] << std::endl;



    return 0;
}



Measured memory_bytes: 3252
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if(a < b){ a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if(a > b){ a = b; return 1; } return 0; }
typedef long long ll;
int main()
{
  int n; cin >> n;
  ll k; cin >> k;
  vector<int> a(n);
  rep(i,n) {
    cin >> a[i];
    a[i]--;
  }

  int s = 0;
  while(k > 0) {
    if(k & 1) s = a[s];
    vector<int> na(n);
    rep(i,n) {
      na[i] = a[a[i]];
    }
    a = na;
    k >>= 1;
  }
  
  cout << s+1 << "\n";
  
  return 0;
}


Measured memory_bytes: 4776
lst = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
K = int(input())

print(lst[K-1])

Measured memory_bytes: 3060
n, m = int(input()), int(input())
B, S = 0, m
d = [0]*m
for _ in range(n):
    cars = list(map(int, input().split()))
    for _ in range(cars[0]): d.append(0)
    try:
        for _ in range(cars[1]): d.pop()
    except IndexError:
        B = 1
    S = max(S, len(d))
print(0 if B else S)

Measured memory_bytes: 7560
#include<bits/stdc++.h>
#define F 1145141919810
using namespace std;

long long dp[110][110];
int n,m,s,f,g;

long long Min(long long a,long long b){
	if(a>b)return b;
	return a;
}

void FW(){
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			dp[i][j]=F;
			if(i==j)dp[i][j]=0;
		}
	}
	int a,b,c;
	for(int i=0;i<m;i++){
		cin>>a>>b>>c;
		dp[a-1][b-1]=c;
	}
	for(int k=0;k<n;k++){
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				dp[i][j]=Min(dp[i][j],dp[i][k]+dp[k][j]);
			}
		}
	}
}

int main(){
	while(cin>>n>>m>>s>>f>>g&&n){
	s--,f--,g--;
	FW();
	long long ans=F;
	for(int i=0;i<n;i++){
		ans=Min(ans,dp[s][i]+dp[i][f]+dp[i][g]);
	}
	cout<<ans<<endl;
	}
	return 0;
}

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

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

int main(void){
    string N;
    cin >> N;
    
    if(N == "ABC"){
        cout << "ARC" << endl;
    }
    else if(N == "ARC"){
        cout << "ABC" << endl;
    }
    
}


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

// https://atcoder.jp/contests/abc054/submissions/me

constexpr int MAX_N = 8;

int N, M;
bool graph[MAX_N+1][MAX_N+1];
int idx[]{1, 2, 3, 4, 5, 6, 7, 8};

int main() {
  scanf("%d%d", &N, &M);
  for (int i{}; i < M; ++i) {
    int a, b;
    cin >> a >> b;
    graph[a][b] = graph[b][a] = true;
  }
  int total{};

  do {
    bool reachedAll{true};
    for (int i{}; i < N-1; ++i) {
      if (!graph[idx[i]][idx[i+1]]) {
        reachedAll = false;
        break;
      }
    }
    if (reachedAll)
      ++total;
  } while (next_permutation(idx + 1, idx + N));

  printf("%d\n", total);
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }

#define Sq(x) (x)*(x)
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Unique(a) a.erase(unique(Range(a)), a.end())
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) { for(const auto &e : xs) cout << e << " "; cout << "\n"; }
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")
#define vc vector
#define Mini(a, x) a = min(a, x)
#define Maxi(a, x) a = max(a, x)

// constexpr int MOD = 1e9+7;

int main(void){
    Cin(int, n);
    Cins(int, n, a);
    Sort(a);
    if(a[0] == 0 && a[n-1] == 0){
        Cout("Yes");
        return 0;
    }
    if(n % 3 != 0){
        Cout("No");
        return 0;
    }
    if(a[0] == a[n/3-1] && a[n/3] == a[n/3*2-1] && a[n/3*2] == a[n-1]){
        int x = a[0], y = a[n/3], z = a[n/3*2];
        CoutYn((x ^ y) == z);
        return 0;
    }
    Cout("No");
}





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

int main(){
char s[201],t[101],p[101];
cin >>s >>p;
strcpy(t,s);
strcat(s,t);
if(strstr(s,p)==NULL)cout <<"No" <<endl;
else cout <<"Yes" <<endl;
return 0;
}

Measured memory_bytes: 3096
#include<bitset>
#include<vector>
#include<iostream>
#include<stdio.h>
using namespace std;
int main(){
  int sum[15],i,n,m,j,l,p[15],k,ans=0,x=0;
  vector<vector<int> > g(15);
  scanf("%d %d\n",&n,&m);
  for(i=0;i<m;i++){
    scanf("%d",&k);
    for(j=0;j<k;j++){
      scanf("%d",&l);
      l--;
      g[l].push_back(i);
    }
    scanf("\n");
  }
  for(i=0;i<m;i++){
    scanf("%d",&p[i]);
  }
  for(int tmp=0;tmp<(1<<n);tmp++){
    bitset<10> s(tmp);
    for(i=0;i<12;i++){
      sum[i]=0;
    }
    for(i=0;i<n;i++){
      if(s[i]==1){
        for(j=0;j<g[i].size();j++){
          sum[g[i][j]]++;
        }
      }
    }
    for(i=0;i<m;i++){
      if(sum[i]%2!=p[i]){
        x=1;
      }
    }
    if(x==0){
      ans++;
    }
    x=0;
  }
  printf("%d\n",ans);
  return 0;
}

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

using namespace std;

#define x first
#define y second
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;

const int MOD = 95542721;


string s;

int main(){
	cin >> s;
	int n = s.size()+1;
	vector< pair< char , int > > cmp;
	for (int i = 0; i+1 < n; ++i){
		if(cmp.size() && s[i] == s[i-1]){
			cmp.back().second++;
			continue;
		}
		cmp.push_back(make_pair(s[i],1));
	}
	vector< pair< char , pii > > nw;
	ll ans = 0;
	for(auto v : cmp){
		if(v.x == '>'){
			nw.pb(mp('>',mp(v.y,0)));
		}else{
			nw.pb(mp('<',mp(0,v.y)));
		}
		for(int i = 0 ; i <= v.y;++i)ans += i;
	}
	for (int i = 1; i < nw.size(); ++i){
		if(nw[i-1].first == '<' && nw[i].first == '>'){
			ans -= nw[i-1].y.y;
			ans -= nw[i].y.x;
			ans += max(nw[i-1].y.y,nw[i].y.x);
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 8568
#include <bits/stdc++.h>
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;
}
typedef long long int ll;

#define EPS (1e-7)
#define INF (1 << 30)
#define LLINF (1LL << 60)
#define PI (acos(-1))
#define MOD (1000000007)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

using edge = pair<int, int>;

void dfs(vector<vector<edge>> &g, vector<int> &color, int now, int c, int par)
{
    color[now] = c;
    for (auto v : g[now])
    {
        if (v.first == par)
        {
            continue;
        }
        if (v.second % 2)
        {
            dfs(g, color, v.first, 1 - c, now);
        }
        else
        {
            dfs(g, color, v.first, c, now);
        }
    }
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<vector<edge>> g(n);
    for (int i = 0; i < n - 1; i++)
    {
        int a, b, c;
        cin >> a >> b >> c;
        a--;
        b--;
        g[a].push_back(edge(b, c));
        g[b].push_back(edge(a, c));
    }
    vector<int> color(n, -1);
    dfs(g, color, 0, 0, -1);
    for (auto ans : color)
    {
        cout << ans << endl;
    }
}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n), id(n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
    id[i] = i;
  }

  sort(id.begin(), id.end(), [&](int i, int j) {
    return a[i] < a[j];
  });

  int answer = 0;
  for (int i = 0; i < n; ++i) {
    answer += (i & 1) && (~id[i] & 1);
  }
  cout << answer << endl;

  return 0;
}

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

using namespace std;

int main()
{
	int n;
	cin >> n;
	string s = "Christmas";
	for (int i = 25 - n; i > 0;i--) {
		s = s + " Eve";
	}
	cout << s << endl;
}

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

int main() {
  int h,w;
  vector<string> s(101);
  cin >> h >> w;
  int i;
  for(i=0;i<w+2;i++){
    cout << "#";
  }
  cout << endl;
  for(i=0;i<h;i++){
    cin >> s.at(i);
    cout << "#" << s.at(i) << "#" << endl;
  }
  for(i=0;i<w+2;i++){
    cout << "#";
  }
  cout << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize(3)
#include<bits/stdc++.h>
#define MAXN 200005
#define INF 1000000000000000000LL
#define MOD 1000000007
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int n,a[MAXN];
ll sum[MAXN];
ll find_max(ll a,ll b,ll c,ll d)
{
    return max(max(a,b),max(c,d));
}
ll find_min(ll a,ll b,ll c,ll d)
{
    return min(min(a,b),min(c,d));
}
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    for(int i=1;i<=n;i++) sum[i]=sum[i-1]+a[i];
    ll ans=INF;
    for(int i=2;i<=n-2;i++)
    {
        ll s=sum[i];
        int id=lower_bound(sum+1,sum+i,s/2)-sum;
        ll s2=sum[n]-sum[i];
        int id2=lower_bound(sum+i+2,sum+n,s+s2/2)-sum;
        for(int j=id-1;j<=id+1;j++)
        {
            if(j>=i||j<1) continue;
            for(int k=id2-1;k<=id2+1;k++)
            {
                if(k<=i||k>=n) continue;
                ll sum1=sum[j],sum2=s-sum1,sum3=sum[k]-s,sum4=s2-sum3;
                ans=min(ans,find_max(sum1,sum2,sum3,sum4)-find_min(sum1,sum2,sum3,sum4));
            }
        }
    }
    printf("%lld\n",ans);
    return 0;
}



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

int check(int a){
	int i;
	for(i = 2; i < a && a%i != 0; i++){}
	if(i == a)
		return 1;
	else
		return 0;
}

int main(void){
	int n,i,j=2;
	cin >> n;
	for(i = 0; i < n; i++){
		while(!(check(j)) || j%5 != 1)
			j++;
		cout << j << " " <<"\n";
        j++;
	}
	cout << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template<class T> ostream& operator<<(ostream &os, vector<T> V) {
os << "[ "; for(auto v : V) os << v << " "; return os << "]";}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {
    return os << "(" << P.first << "," << P.second << ")";}

// #define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...) 1
#endif
typedef long long ll;
typedef double ld;
#define pll pair<ll,ll>
#define pii pair<int, int>
#define pb push_back
#define mp(x, y) make_pair((x), (y))
#define F first
#define S second
#define I insert
#define vi vector<int>
#define vll vector<ll>
#define vpll vector<pll>
#define all(x) (x).begin(), (x).end()
#define sz(x) (ll)(x).size()
   
const ll Mod = 1e9 + 7;
int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); 
    ll n , x; cin >> n >> x;
    ll A[n] , s = 0 , cnt = 1;
    for(int i = 0 ;i < n; i++)
        cin >> A[i];
    for(int i = 0 ;i < n; i++){
        s += A[i];
        if(s <= x)
            cnt++;
    }
    cout << cnt << endl;
    return 0;
}

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

int main(){
    long long int h, w;
    cin >> h >> w;
    //vector<vector<int>> a(h, vector<int>(w));
    long long int sum = h*w;

    if(h == 1 || w == 1){
        cout << 1 << endl;
    }else{
        if(sum % 2 == 1){
            cout << sum / 2 + 1 << endl;
        }else{
            cout << sum / 2 << endl;
        }
    }   
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'
const char newl = '\n';
typedef long long int Int;
typedef pair<int,int> P;
using ll = long long;
using VI = vector<int>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const long long INF = 1LL<<60;

int main(){
    int n;cin >> n;
    vector<int> a(n);
    bool flag = true;
    for(int i=0;i<n;i++){
        cin >> a[i];
        if(a[i]==1&&flag){
            flag = false;
        }
    }
    if(flag){cout << -1 << endl;return 0;}
    int cur = 1;
    for(int i=0;i<n;i++){
        if(a[i]==cur) cur++;
    }
    cout << n-cur+1 << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
template<class T> inline bool chmax(T& a, T b) {if (a<b) {a=b; return true;} return false;}
template<class T> inline bool chmin(T& a, T b) {if (a>b) {a=b; return true;} return false;}
#define DEBUG_VLL(vec) REP(i, vec.size()) cerr<<vec[i]<<(i==vec.size()-1?'\n':' ');

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n; cin >> n;
    V<string> s(n);
    REP(i, n) {
        cin >> s[i];
        sort(s[i].begin(), s[i].end());
    }

    unordered_map<string, ll> smap;
    REP(i, n) {
        smap[s[i]]++;
    }
     
    ll ans = 0;
    for (auto sm: smap) ans += sm.second * (sm.second-1) / 2;
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 16036
#include<iostream>
 
using namespace std;
int main()
 
{
 
char s[4];
int x=0;
 
for( int i=0;i<4;i++){
    cin>>s[i];
}
for(int i=0;i<4;i++){
    if(s[i]=='-'){
    x--;
}
else if(s[i]=='+'){
    x++;
}
}
 
cout<<x<<endl;
 
return 0;
 
}

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

using namespace std;

int main()
{
  int n,m;
  for(;cin>>n>>m,n;)
    {
      vector<int> price;

      for(int i=0;i<n;i++)
	{
	  int tmp;
	  cin>>tmp;
	  price.push_back(tmp);
	}
      sort(price.begin(),price.end());
      int ans=0;
      int cnt=1;
      for(int i=n-1;i>=0;i--)
	{
	  if(cnt==m)
	    cnt=1;
	  else
	    {
	      ans+=price[i];
	      cnt++;
	    }
	}
      cout<<ans<<endl;
    }
}

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

int main(){
  //num,fk,lkは主処理で初めに書き込むべき配列番号、処理すべき初めの配列番号、処理すべき最後の配列番号をそれぞれ指定
  //数リストは予め一括ゼロ初期化
  long long K,i,j,num=9,memo[100001]={0},fk=0,lk=9,temp;
  cin>>K;
  K--;//0始まりの数に変換
  for(i=1;i<10;i++) memo[i-1]=i;//1~9まで生成(主処理の種)
  
  //主処理
  while(num<=K){//Kに達していなければ続行
    for(i=0;i<lk-fk;i++){
      for(j=-1;j<=1;j++){
        temp=memo[fk+i]%10+j;//次期1の位候補
        if(temp<0 || temp>9) continue;//1の位にありえない数なら破棄
        memo[num]=memo[fk+i]*10+temp;//最終的な数を生成
        num++;//次に書き込む配列番号を進める
        if(num>K) break;
      }
      if(num>K) break;
    }
    fk=lk;//次処理する最初の配列番号を指定
    lk=num-1;//次処理する最後の配列番号を指定
  }
  
  //答え
  cout<<memo[K]<<endl;
}

Measured memory_bytes: 1024
w[100000],n,k;
cntp(int p)
{
    int cnt=1,wgh=0;
    for(int i=0;i<n;)
    {
        if(wgh+w[i]<=p)
        {
            wgh+=w[i++];
        }
        else
        {
            if(wgh>0)cnt++;
            else return k+1; 
            wgh=0;
        }
    }
    return cnt;
}
main()
{
    scanf("%d%d",&n,&k);
    for(int i=0;i<n;scanf("%d",w+i++));
    int l=0,r=1e9,m;
    while(l<r)
    {
        m=(l+r)/2;
        if(cntp(m)>k)l=m+1;
        else r=m;
    }
    for(m--;;m++)
    {
        if(cntp(m)<=k)break;
    }
    printf("%d\n",m);
    return 0;
}

Measured memory_bytes: 2140
#include<bits/stdc++.h>
using namespace std;
long long const MAX=1e5+7;
bool dp[MAX]={0};
int main()
{long long i,j,n,r,k,p,w,y,sum,m,x;
cin>>n>>k;
long long a[n];
for(i=0;i<n;i++)
{cin>>a[i];}
for(i=0;i<=k;i++)
{for(auto j:a)
{if(i>=j)
{if(dp[i-j]==0)
dp[i]=1;}}}
if(dp[k]==0)
cout<<"Second";
else cout<<"First";
return 0;}


Measured memory_bytes: 384
#include <cstdio>
#include <iostream>
#include <set>
#include <algorithm>
#include <map>
#include <string>
#include <cstring>
#include <cmath>
using namespace std;
const int maxn = 2e5 + 100;
int f[maxn];
int d[maxn];
int ff(int x)
{
    if (x == f[x]) return x;
    int a = f[x];
    int b =ff(f[x]);
    d[x] += d[a];
    f[x] = b;
    return b;
}
int unit(int x,int y,int z)
{
    int fx = ff(x);
    int fy = ff(y);
    if (fx != fy){
        f[fy] = fx;
        d[fy] = d[x] - d[y] + z;
        return 1;
    }else 
    return (d[y] - d[x]) == z;
}
int main(){
    int n,m;
    scanf("%d%d",&n,&m);
    int flag = 0;
    for (int i = 0; i <= n; i++) f[i] = i;
    for (int i = 0; i < m; i++){
         int x,y,z;
         scanf("%d%d%d",&x,&y,&z);
         if (!unit(x,y,z)){
            flag = 1;
         }
    }
    if (!flag) printf("Yes\n");
    else printf("No\n");
}

Measured memory_bytes: 1152
n, y = map(int, input().split())

noguchi = 1000
higuchi = 5000
yukichi = 10000

ans = '-1 -1 -1'
for i in range(n+1):
    for j in range(n+1-i):
        k = n - (i+j)
        yen = noguchi * i + higuchi * j + yukichi * k
        if yen == y:
            ans = '{0} {1} {2}'.format(k,j,i)
            break

print(ans)


Measured memory_bytes: 3064
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define PF push_front
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double
#define pii pair<int,int>
#define pll pair<LL,LL>
#define vi vector<int>
#define vl vector<LL>
#define vii vector<vi>
#define vll vector<vl>

const double pi = 3.14159265358979323846264;
const int mod=1000000007;

int main(){
	int n,m;
    cin>>n>>m;
    vi p(m);
    vi ac(n,0);
    vi pe(n,0);
    vi ss(m);
    vector<string> s(m);
    FOR(i,0,m){
        cin>>p[i]>>s[i];
        p[i]--;
        if(ac[p[i]]){

        }else{
            if(s[i]=="WA"){
                pe[p[i]]++;
            }else{
                ac[p[i]]=1;
            }
        }
    }
    int na=0,np=0;
    FOR(i,0,n){
        if(ac[i])np+=pe[i];
        na+=ac[i];
    }
    cout<<na<<" "<<np<<endl;
}


Measured memory_bytes: 7296
#include<stdio.h>
int d[101],e[101],t=0,n;
bool went[101],graph[101][101];
void dfs(int x){
    if(went[x])return;
    went[x]=true;
    t++;
    d[x]=t;
    for(int i=1;i<=n;i++){if(graph[x][i])dfs(i);}
    t++;
    e[x]=t;
    return;
}

int main(){
    int m,temp,a;
    scanf("%d",&n);
    for(int i=0;i<101;i++){
        for(int j=0;j<101;j++)graph[i][j]=false;
        went[i]=false;
    }
    for(int i=0;i<n;i++){
        scanf("%d%d",&a,&m);
        for(int j=0;j<m;j++){
            scanf("%d",&temp);
            graph[a][temp]=true;
        }
    }
    for(int i=1;i<=n;i++)dfs(i);
    for(int i=1;i<=n;i++)printf("%d %d %d\n",i,d[i],e[i]);
}


Measured memory_bytes: 2768
#include <iostream>
#include <vector>
#include <algorithm>
#include <cassert>
#include <utility>
#include <string>
#include <cmath>
#include <set>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; ++i)
typedef long long ll;
typedef pair<int,int> pii;
int main(){
    int n,l;
    cin >> n >> l;
    vector<string>s(n);
    rep(i,n) cin >> s[i];
    sort(s.begin(),s.end());
    rep(i,n){
        cout << s[i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
# Problem: https://atcoder.jp/contests/agc025/tasks/agc025_a
# Python 3rd Try

import sys
# from collections import defaultdict
# import heapq,copy
# from collections import deque


def II(): return int(sys.stdin.readline())


def MI(): return map(int, sys.stdin.readline().split())


def LI(): return list(map(int, sys.stdin.readline().split()))


def LLI(rows_number): return [LI() for _ in range(rows_number)]


def solver(inputNum):
    result = 0
    # algorithm
    totalDigit = 0
    inputStr = str(inputNum)
    for j in range(0, len(inputStr)):
        totalDigit = totalDigit + int(inputStr[j])
    if totalDigit == 1:
        result = 10
    else:
        result = totalDigit
    return result


if __name__ == "__main__":
    print("{}".format(solver(II())))


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

const int mxN = 1e5 + 5, mxM = 105;
long long dp[mxM][mxN], w[mxM], v[mxM];
int main() {
	int n, m;
	cin >> n >> m;
	for(int i = 1; i <= n; ++i)
		cin >> w[i] >> v[i];
	for(int i = 1; i <= n; ++i) {
		for(int j = 1; j <= m; ++j) { 
			if(j >= w[i])
				dp[i][j] =max(v[i] + dp[i - 1][j - w[i]], dp[i - 1][j]);
			else
				dp[i][j] = dp[i - 1][j];
		}
	}
	cout << dp[n][m];
}


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

int main(){
  string s, t;
  int ans = 0;
  cin >> s >> t;
  rep(i,3,0){
    if(s[i] == t[i]) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

// https://atcoder.jp/contests/abc144/tasks/abc144_a
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		sc.close();

		int ans = -1;

		if(A<10&&B<10){
			ans = A * B;
		}
		System.out.println(ans);
//		int[] array = new int[N];
//		for(int i=0;i<N;i++) {
//			array[i]=sc.nextInt();
//		}
//		sc.close();
	}
}


Measured memory_bytes: 23892
#include <cstdio>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <list>
#include <tuple>
#include <bitset>

using namespace std;

inline bool cheak(int x, int y, int xMax, int yMax){ return x >= 0 && y >= 0 && xMax > x && yMax > y; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }
template<class T> inline T sqr(T x) { return x*x; }

typedef pair<int, int> P;
typedef tuple<int, int, int> T;
typedef long long ll;
typedef unsigned long long ull;
inline ll toInt(string s) { ll v; istringstream sin(s); sin >> v; return v; }

#define For(i,a,b)	for(int (i) = (a);i < (b);(i)++)
#define rep(i,n)	For(i,0,n)
#define clr(a)		memset((a), 0 ,sizeof(a))
#define mclr(a)		memset((a), -1 ,sizeof(a))
#define all(a)		(a).begin(),(a).end()
#define sz(a)		(sizeof(a))
#define Fill(a,v)	fill((int*)a,(int*)(a+(sz(a)/sz(*(a)))),v)

const int dx[8] = { 1, 0, -1, 0, 1, 1, -1, -1 }, dy[8] = { 0, -1, 0, 1, -1, 1, -1, 1 };
const int mod = 1000000007;
const int INF = 1e9;

const int M = 20;
int n;
int memo[65556];
int t[M][M];

int dfs(int bit){
	if (bit == 0)return 0;
	if (memo[bit] != -1)return memo[bit];
	int ret = INF;
	rep(i, n)if (bit >> i & 1){
		int tmp = dfs(~(~bit | 1 << i));
		int m = t[i][0];
		rep(j, n)if (bit >> j & 1 && i != j){
			m = min(t[i][j + 1],m);
		}
		ret = min(tmp + m, ret);
	}
	return memo[bit] = ret;
}

int main()
{
	while (cin >> n && n){
		   
		rep(i, n)rep(j, n + 1) cin >> t[i][j];
		mclr(memo);
		cout << dfs((1<<n) - 1) << endl;
	}
	return 0;
}

Measured memory_bytes: 1424
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int i,N,M;
    double A;
    long long sum;
    priority_queue<double> que;
    cin>>N>>M;
    for(i=1;i<=N;i++)
    {
        scanf("%lf",&A);
        que.push(A);
    }
    for(i=1;i<=M;i++)
    {
        A=que.top();
        que.pop();
        A/=2;
        que.push(A);
    }
    sum=0;
    for(i=1;i<=N;i++)
    {
        A=que.top();
        que.pop();
        /*if(floor(A*2)>floor(A)*2)
            sum+=ceil(A);
        else*/
        sum+=floor(A);
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 1400
#!/usr/bin/env python3
import sys
def input():
    return sys.stdin.readline()[:-1]

def main():
    N = int(input())
    H = list(map(int, input().split()))

    k = 0
    for i in range(N - 1):
        k += H[i + 1] - H[i]
        if k > 0:
            k = 0
        if k <= -2:
            print('No')
            exit()
    print('Yes')


if __name__ == '__main__':
    main()


Measured memory_bytes: 85456
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long int ll;
typedef vector<pair<ll,ll> > Q;
typedef pair<int,int> P;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
const ll inf=1e9+7;
ll gcd(ll a, ll b) { return (b ? gcd(b, a % b) : a); }
ll lcm(ll a, ll b) { return a / (gcd(a, b)) * b; }

int main(){
    int n,a,b;
    cin>>n>>a>>b;
    int x[100000];
    rep(i,0,n) cin>>x[i];

    ll ans=0;
    ll pos=0;
    rep(i,0,n-1){
      ll dis=x[i+1]-x[i];
      if(dis*a<b) ans+=dis*a;
      else ans+=b;
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 640
n,m=map(int,input().split())
a=[0]+list(map(int,input().split()))
a[0]%=2
for i in range(n):
	a[i+1]+=a[i]
	a[i+1]%=m
a.sort()
ans=0
cnt=1
for i in range(n):
	if a[i]==a[i+1]:
		cnt+=1
	else:
		ans+=cnt*(cnt-1)//2
		cnt=1
ans+=cnt*(cnt-1)//2
print(ans)

Measured memory_bytes: 14224
#include <iostream>
using namespace std;
const int maxn=5e3+2;
long long n, A, B, dp[maxn], a[maxn];

void Enter()
{
    cin>>n>>A>>B;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    a[n+1]=1e18;
    for(int i=1;i<=n+1;i++)
    {
        dp[i]=1e18;
        long long t=0;
        for(int j=i-1;j>=0;j--)
        {
            if(a[j]>a[i])t++;
            else
                dp[i]=min(dp[i],dp[j]+t*A+(i-j-1-t)*B);
        }
    }
    cout<<dp[n+1];
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    Enter();
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int n,q;
  cin >> n >> q;
  string s;
  cin >> s;
  vector<int>sum(n+1);
  for(int i=0;i<n-1;i++){
    if(s.at(i)=='A'&&s.at(i+1)=='C'){
      sum.at(i+2)+=sum.at(i+1)+1;
    }
    else{
      sum.at(i+2)+=sum.at(i+1);
    }
  }
  for(int i=0;i<q;i++){
    int l,r;
    cin >> l >> r;
    cout << (sum.at(r)-sum.at(l)) << endl;
  }
}

Measured memory_bytes: 3852
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<list>
#include<bitset>
#include<stack>
#include<memory>
#include<numeric>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
#define REP(i, n) for(int i = 0;i < (n);i++)
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
const llint mod=998244353;
const llint inf=2.19e18+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-10;
template <class T,class U>bool chmin(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool chmax(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(const vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(const vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}

int main(void){
	string S;cin>>S;
	for(auto&it:S){if(it=='?'){it='D';}}
	cout<<S<<endl;
	return 0;
}


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

const int mod =1000000007;
#define all(v) v.begin(),v.end()
#define mp make_pair
#define pb push_back

template<typename T, typename U>
inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U>
inline void amax(T &x, U y) { if(x < y) x = y; }

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<vb> vvb;

vvi dp(101,vi(100001,-1));
ll n,W;
ll w[101],v[101];

ll solve(int i,int wt){
	if(i==n)
	return (ll)0;
	
	ll & ans=dp[i][wt];
	if(ans==-1){
		ans=solve(i+1,wt);
		if(wt>=w[i]){
			amax(ans,v[i]+solve(i+1,wt-w[i]));
		}
	}
	return ans;
}

int main(){
	cin>>n >>W;
	
	for(ll i=0;i<n;++i)
	cin>>w[i] >>v[i];
	
	cout<<solve(0,W)<<endl;
    
	return 0;
}


Measured memory_bytes: 80256