akhauriyash/Code-Regression huggingface dataset:
N, x = map(int, input().split())
a = [0]+list(map(int, input().split()))

cnt = 0
for i in range(1, N+1):
    if i == 1:
        if a[i]>x:
            cnt += a[i]-x
            a[i] -= a[i]-x
        continue
    if a[i-1]+a[i]>x:
        cnt += a[i]+a[i-1]-x
        a[i] -= a[i]+a[i-1]-x
print(cnt)

Measured memory_bytes: 14252
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE NumDecimals #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}

import Control.Applicative
import Control.Arrow
import Control.Monad
import Control.Monad.ST

import Data.Char
import Data.List
import Data.Maybe

import qualified Data.ByteString.Char8 as B

import Data.Array.ST.Safe
import Data.STRef

import Debug.Trace
import Text.Printf

readInt = readLn :: IO Int
readInteger = readLn :: IO Integer
readInts = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine
readIntegers = map ( fst . fromJust . B.readInteger ) . B.words <$> B.getLine

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

modifyArray a i f = writeArray a i =<< f <$> readArray a i

main = do
	n <- readInt
	as <- sort <$> readIntegers
	print $ fromMaybe (-1) $ foldl f ( Just 1 ) as

f ( Just a ) b
	| a * b <= 10 ^ 18 = Just $ a * b
	| a == 0 || b == 0 = Just 0
	| otherwise = Nothing
f _ _ = Nothing

Measured memory_bytes: 19132
fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());
    let n: usize = sc.read();
    let s = sc.chars();
    let r = s.iter().filter(|&&c| c == 'R').count();

    let mut ans = 0;
    for i in 0..r {
        if s[i] == 'W' {
            ans += 1;
        }
    }

    println!("{}", ans);
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> Self {
        Self(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: ToString>(&mut self, s: S) {
        use std::io::Write;
        self.1.write_all(s.to_string().as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 3164
from collections import defaultdict
from itertools import permutations

n, m = map(int, input().split())

graph = defaultdict(list)

for _ in range(m):
    a, b = map(int, input().split())
    graph[a].append(b)
    graph[b].append(a)

pattern = [x for x in permutations(range(1, n + 1)) if x[0] == 1]

ans = []
for p in pattern:
    tmp = []
    for i in range(n - 1):
        if p[i + 1] in graph[p[i]]:
            tmp.append(True)
        else:
            tmp.append(False)
    ans.append(all(tmp))

print(sum(ans))

Measured memory_bytes: 9516
import sys
sys.setrecursionlimit(10000)


class Node:
    
    def __init__(self):
        self.root = self
        self.child = None
        self.length = 1
    
    def set_root(self, root):
        if self.child:
            self.child.set_root(root)
        self.root = root
            
    def set_child(self, child):
        if self.child:
            self.child.set_child(child)
        else:
            self.child = child
        
        
n,q = [int(i) for i in input().split()]
A = []
for i in range(n):
    A.append(Node())

for i in range(q):
    c, x, y = [int(i) for i in input().split()]
    if c == 0:
        if A[x].root == A[y].root:
            continue
        if A[x].root.length < A[y].root.length:
            A[y].set_child(A[x].root)
            A[y].root.length += A[x].root.length
            A[x].root.set_root(A[y].root)
        else:
            A[x].set_child(A[y].root)
            A[x].root.length += A[y].root.length
            A[y].root.set_root(A[x].root)
    else:
        if A[x].root == A[y].root:
            print(1)
        else:
            print(0)


Measured memory_bytes: 16452
#include<bits/stdc++.h>
using namespace std;
#define lp(i,n) for(int i=0;i<n;i++)
#define lpin(a,i,n) for(int i=0;i<n;i++){cin>>a[i];}

int main(){
  int n;
  int a[101],b[101];
  lp(i,101){
    a[i]=0;
    b[i]=0;
  }
  cin>>n;
  int x;
  cin>>x;
  lp(i,x){
    int c;
    cin>>c;
    a[c]++;
    b[c]--;
  }
  cin>>x;
  lp(i,x){
    int c;
    cin>>c;
    a[c]++;
  }
  cin>>x;
  lp(i,x){
    int c;
    cin>>c;
    a[c]++;
    b[c]++;
  }
  int ans=0;
  lp(i,n+1){
    if(i==0) continue;
    if(a[i]==3 || b[i]==1) ans++;
  }
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 3096
from collections import deque
import sys
readline = sys.stdin.readline
write = sys.stdout.write

def rotate(nd, d):
    c = nd[d]
    if d:
        nd[1] = c[0]
        c[0] = nd
    else:
        nd[0] = c[1]
        c[1] = nd
    return c


root = None
def insert(val, pri):
    global root
    st = []
    dr = []
    x = root
    while x:
        st.append(x)
        if x[2] == val:
            return
        d = (x[2] < val)
        dr.append(d)
        x = x[d]
    nd = [None, None, val, pri]
    while st:
        x = st.pop(); d = dr.pop()
        c = x[d] = nd
        if x[3] >= c[3]:
            break
        rotate(x, d)
    else:
        root = nd

def __delete(nd):
    st = []; dr = []
    while nd[0] or nd[1]:
        l = nd[0]; r = nd[1]
        d = (l[3] <= r[3]) if l and r else (l is None)
        st.append(rotate(nd, d))
        dr.append(d ^ 1)
    nd = x = None
    while st:
        nd = x; x = st.pop(); d = dr.pop()
        x[d] = nd
    return x

def delete(val):
    global root
    x = root

    y = None
    while x:
        if val == x[2]:
            break
        y = x; d = (x[2] < val)
        x = x[d]
    else:
        return

    if y:
        y[d] = __delete(x)
    else:
        root = __delete(x)

def find(val):
    x = root
    while x:
        if val == x[2]:
            return 1
        x = x[x[2] < val]
    return 0

def debug():
    s0 = [""]
    s1 = [""]

    def dfs(nd):
        v = str(nd[2])
        s0.append(v)
        if nd[0]:
            dfs(nd[0])
        s1.append(v)
        if nd[1]:
            dfs(nd[1])
    dfs(root)
    return " ".join(s1), " ".join(s0)


M = int(readline())
ans = []
for m in range(M):
    cmd, *V, = readline().split()
    if cmd == "print":
        ans.extend(debug())
    elif cmd == "find":
        ans.append("yes" if find(int(V[0])) else "no")
    elif cmd == "delete":
        delete(int(V[0]))
    else:
        val, pri = map(int, V)
        insert(val, pri)
write("\n".join(ans))
write("\n")




Measured memory_bytes: 65684
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <functional>
#include <iomanip>
#include <bitset>
#include <numeric>
#include <queue>
#include <map>
#include <cstdint>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
const long long mod = 1000000007;
typedef long long int ll;
typedef pair<ll, ll> P;
const vector<int> di = { -1, 0, 1, 0 };
const vector<int> dj = { 0, 1, 0, -1 };



int main() {

	int a, b;
	cin >> a >> b;
	int ans = a + b;

	if (ans >= 10) {
		cout << "error" << endl;
	}
	else {
		cout << ans << endl;
	}

	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define EPS 0.0000000001
#define INF 1000000000
#define MOD 1000000007
typedef long long ll;

int main()
{
    int a,b;
    cin>>a>>b;
    cout<<a-b+1;
}


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

using namespace std;

int main(int argc, char* argv[])
{
	int N;
	int K;
	vector<bool> Ds(10);
	cin >> N >> K;
	for (int i = 0; i < K; i++) {
		int D;
		cin >> D;
		Ds[D] = true;
	}
	for (int v = N; v < 10000 * 10; v++) {
		bool flag = true;
		int tmp   = v;
		do {
			if (Ds[tmp % 10]) {
				flag = false;
				break;
			}
			tmp /= 10;
		} while (tmp > 0);
		if (flag) {
			cout << v << endl;
			break;
		}
	}
	return 0;
}


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

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i=0; i<N; i++) cin >> A[i];
    // 割れた回数を持っておく
    int ans = 0;
    bool div_by_2 = true;
    while(div_by_2){
        for(int i=0; i<N; i++){
            if(A[i] % 2 == 1){
                div_by_2 = false;
                break;
            }else{
                A[i] /= 2;
           }
        }
        // すべて2で割り切れる
        if(div_by_2){
            ans++;
        }
    }
    cout << ans << endl;

}

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

int main()
{
    int H, W; cin >> H >> W;
    vector<string> s(H);
    for (int i = 0; i < H; i++) cin >> s[i];

    bool flag = true;
    for (int h = 0; h < H; h++) {
        for (int w = 0; w < W; w++) {
            if (s[h][w] == '#') {
                if ((w >= 1 && s[h][w-1] == '.') 
                 && (w < W - 1 && s[h][w+1] == '.') 
                 && (h >= 1 && s[h-1][w] == '.') 
                 && (h < H - 1 && s[h+1][w] == '.'))
                    flag = false;
            }
        }
    }
    cout << ((flag) ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 256
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout

	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
		if len(os.Args) > 2 {
			wfp, _ = os.Create(os.Args[2])
		}
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)

	m := getNextInt64(scanner)
	n := getNextInt64(scanner)

	powers := make([]int64, 32)

	powers[0] = m
	for i := 1; i < 32; i++ {
		powers[i] = (powers[i-1] * powers[i-1]) % int64(1e9+7)
	}

	var ans int64
	ans = 1
	for i := 0; i < 32; i++ {
		if n>>uint(i)&1 == 1 {
			ans = (ans * powers[i]) % int64(1e9+7)
		}
	}

	fmt.Fprintln(writer, ans)
	writer.Flush()
}



Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
const int siz = 16;
long long n,sum[(1<<siz)],dp[(1<<siz)],vals[siz][siz];
 
void getsum(int mask){
    vector<int> g;
    for(int i = 0 ; i < n ; i += 1){
        if(mask & (1<<i)){
            g.push_back(i);
        }
    }
    for(int i = 0 ; i+1 < g.size() ; i += 1){
        for(int j = i+1 ; j < g.size() ; j += 1){
            sum[mask] += vals[g[i]][g[j]];
        }
    }
}

long long tryall(int curr , int mask , int val);
 
long long ans(int curr){
    if(curr == 0){
        return 0;
    }
    if(dp[curr] != -1){
        return dp[curr];
    }
    return dp[curr] = tryall(0,0,curr);
}

long long tryall(int curr , int mask , int val){
	if(curr == siz){
		if(mask){
			return sum[mask]+ans(val^mask);
		}
		return 0;
	}
	long long ret;
	if(val & (1<<curr)){
		ret = max(tryall(curr+1,mask,val),tryall(curr+1,mask^(1<<curr),val));
	}else{
		ret = tryall(curr+1,mask,val);
	}
	return ret;
}

int main(){
	memset(dp,-1,sizeof dp);
    cin >> n;
    for(int i = 0 ; i < n ; i += 1){
        for(int j = 0 ; j < n ; j += 1){
            cin >> vals[i][j];
        }
    }
    for(int i = 0 ; i < (1<<n) ; i += 1){
        getsum(i);
    }
    cout << ans((1<<n)-1);
}

Measured memory_bytes: 1280
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010


int main(){
  int N;
  int in[SIZE];

  scanf("%d", &N);

  for(int i=0; i<N; i++) {
    int a;
    scanf("%d", &a);

    in[a-1] = i;
  }

  for(int i=0; i<N; i++) {
    printf("%d%c", in[i] + 1, " \n"[i+1 == N]);
  }

  return 0;
}


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

int main() {
  int n, x;
  cin >> n >> x;
  int sum = 0;
  int minl = 1000;
  for(int i=0; i<n; i++) {
    int m;
    cin >> m;
    sum+=m;
    minl = min(minl,m);
  }
  cout << n+(x-sum)/minl << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

string judge(int A,int B){
    if (A<=8&&B<=8) return "Yay!";
    else if (A>8||B>8) return ":(";
}

int main(){
    int A,B;
    cin >> A >> B;
    cout << judge(A,B) << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
  int a[101],c,d,i;
  scanf("%d",&c);
  for(i=0;i<c;i++){
    scanf("%d",&a[i]);}
  d=c-1;
  for(i=d;i>=0;i--){
    if(i==d){
    printf("%d",a[i]);}
    else{
    printf(" %d",a[i]);}
  }
  printf("\n");
  return 0;
}


Measured memory_bytes: 2104
//config = { input: 'tmp', newline: '\r\n' }; // win
config = { input: '/dev/stdin', newline: '\n' }; // linux

line = require('fs').readFileSync(config.input, 'ascii')
  .split(config.newline);

T = line[0];
P = line[1];

for (i = T.indexOf(P, 0); i !== -1; i = T.indexOf(P, ++i))
  console.log(i);

Measured memory_bytes: 16584
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define str string
#define fi first
#define se second
#define pb push_back
#define SET(a, b) memset(a, b, sizeof(a))
#define eps 1e-6
#define pi atan(1) * 4
#define mod 998244353
#define inf 1000000000
#define llinf 1000000000000000000
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
#define FORl(i, a, b) for (ll i = (a); i <= (b); i++)
#define FORDl(i, a, b) for (ll i = (a); i >= (b); i--)
using namespace std;
ll power[200005];
ll fac[200005], inv[200005];
ll ncr (int n, int r) {
  return fac[n] * inv[r] % mod * inv[n - r] % mod;
}
ll bigmod (ll b, int i) {
  if (i == 1) return b;
  else if (i == 0) return 1;
  ll m = bigmod(b, i >> 1);
  if (i & 1) return m * m % mod * b % mod;
  else return m * m % mod;
}
int main () {
  int n, m, k;
  scanf("%d %d %d", &n, &m, &k);
  power[0] = 1; fac[0] = inv[0] = 1;
  FOR(i, 1, n) {
    power[i] = power[i - 1] * (m - 1) % mod;
    fac[i] = fac[i - 1] * i % mod;
    inv[i] = bigmod(fac[i], mod - 2);
  }
  ll ans = 0;
  FOR(i, 0, k) {
    ans = (ans + m * power[n - i - 1] % mod * ncr(n - 1, i) % mod) % mod;
  }
  printf("%lld\n", ans);
  return 0;
}

Measured memory_bytes: 8408
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <ctime>
#include <cassert>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define fs first
#define sc second
#define INF 1000000000
#define MOD 1000000007
#define EPS 0.00000001


int main() {
    ll N, K; cin >> N >> K;
    vector<ll> A(N);
    for(ll &a:A)
        cin >> a;
    
    ll ans = 0;
    for(int i=0; i<N; i++){
        for(int j=i+1; j<N; j++){
            if(A[i]>A[j]) ans++;
        }
    }
    
    ans = (ans * K) % MOD;
    ans %= MOD;
    
    
    vector<ll> D(N);
    for(int i=0; i<N; i++){
        for(int j=0; j<N; j++){
            if(A[i]<A[j]) D[i]++;
        }
    }
    
    for(int i=0; i<N; i++){
        ans = (ans + (D[i] * K %MOD * (K-1) % MOD * 500000004 %MOD)) % MOD;
        ans %= MOD;
    }
    
    
    cout << ans % MOD << endl;
    
    return 0;
    
}





Measured memory_bytes: 256
import sys
input = lambda: sys.stdin.readline().rstrip()

n = int(input())
a = [int(x) for x in input().split()]

from itertools import accumulate

a_csum = list(accumulate(a))

ans = 10**10

for i in range(n - 1):
    ans = min(ans, abs(a_csum[i] - (a_csum[-1] - a_csum[i])))

print(ans)

Measured memory_bytes: 92324
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

#define N               100005
#define ff              first
#define ss              second
#define ll              long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<ll,ll>
#define vi              vector<ll>
#define mii             map<ll,ll>
#define pq_max          priority_queue<ll>
#define pq_min          priority_queue<ll,vi,greater<ll> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            ll x; cin>>x; while(x--)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;


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

int main(){
    fio();

    ll k;
    cin>>k;

    ll val = 7 % k;
    bool p = false;
    for(ll z=1;z<1e7;z++){
        if(val == 0) {
            cout<<z;
            p = true;
            break;
        }

        val = (val*10 + 7) % k;
    }

    if(! p) cout<<-1;

    return 0;
}

Measured memory_bytes: 3628
from collections import deque, defaultdict
from heapq import heappush, heappop
import sys
input = sys.stdin.readline

N, Q = map(int, input().split())
events = [None] * (2*N)
for i in range(N):
    S, T, X = map(int, input().split())
    events[2*i] = (S-X, X)
    events[2*i+1] = (T-X, -X)
events.sort(key=lambda x: x[0])
events = deque(events)
ans = [0] * Q
cur = []
remove = defaultdict(int)
for i in range(Q):
    D = int(input())
    while events and events[0][0] <= D:
        t, x = events.popleft()
        if x > 0:
            heappush(cur, x)
        else:
            remove[-x] += 1
    while cur and remove[cur[0]]:
        remove[cur[0]] -= 1
        heappop(cur)
    ans[i] = cur[0] if cur else -1
print(*ans, sep='\n')


Measured memory_bytes: 121264
-- https://github.com/minoki/my-atcoder-solutions
import Data.Char
import Data.List
import qualified Data.ByteString.Char8 as BS

main = do
  [p,q,r] <- unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
  print $ p + q + r - maximum [p, q, r]


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

int main(){
  long int H , W;
  cin >> H >> W ;
  if(H != 1 && W != 1){
    cout << (H / 2) * ( W / 2) + (H - H / 2) * (W - W / 2) << endl;
  }
  else cout << 1 << endl;
}


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


int main () {
  int r,D;
  int x[11];

  cin >> r >> D;
  cin >> x[0];
  for(int i=0;i<11;i++){
    x[i+1] = x[i]*r - D;
  }

  for(int i=1;i<11;i++){
    cout << x[i] << endl;
  }


}


Measured memory_bytes: 256
N, K = map(int, input().split())

P = list(map(lambda x: int(x) - 1, input().split()))
ans = 0 if P[0] == 0 else 1
P[0] = 0
Edge = [[] for _ in range(N)]
for i in range(1, N):
    p = P[i]
    Edge[i].append(p)
    Edge[p].append(i)

used = set([0])
stack = [0]
dist = [0]*N
while stack:
    vn = stack.pop()
    for vf in Edge[vn]:
        if vf not in used:
            used.add(vf)
            stack.append(vf)
            dist[vf] = 1 + dist[vn]

L = sorted(list(range(N)), key = lambda x: dist[x])

seen = set()
for l in L[::-1]:
    if l in seen:
        continue
    if dist[l] > K:
        vs = l
        for _ in range(K-1):
            vs = P[vs]
        seen.add(vs)
        stack = [vs]
        while stack:
            vn = stack.pop()
            for vf in Edge[vn]:
                if vf not in seen and vf != P[vs]:
                    seen.add(vf)
                    stack.append(vf)
        
        ans += 1

print(ans)


Measured memory_bytes: 87404
/*
解法が分からなかった（アイデアが分からなかった）

*/
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;


int main() {
    // 入力
    int n, m; cin >> n >> m;
    vector<int> P(m), Y(m);
    for (int i = 0; i < m; ++i) cin >> P[i] >> Y[i], --P[i];
    
    // vals[v] := P[i] = v であるような i についての Y[i] の値を集めたもの
    vector<vector<int> > vals(n);
    for (int i = 0; i < m; ++i) vals[P[i]].push_back(Y[i]);
    
    // 各 p の値に対して
    for (int v = 0; v < n; ++v) {
        sort(vals[v].begin(), vals[v].end());
        
        // 今回は不要だが、通常は数のダブりをなくす
        vals[v].erase(unique(vals[v].begin(), vals[v].end()), vals[v].end());
    }

    // 答え
    for (int i = 0; i < m; ++i) {
        int v = P[i];
        printf("%06d", v + 1);
        
        // 座標圧縮して導いた答え
        int id = lower_bound(vals[v].begin(), vals[v].end(), Y[i]) - vals[v].begin();
        printf("%06d\n", id + 1);
    }
}

Measured memory_bytes: 7808
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a),i##formax=(b);i<i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formax=(b);i>=i##formax;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)
#define show(x) cout<<#x<<" = "<<x<<endl;
#define all(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))
#define bitComb(a,n,k) for(int a##x,a##y,a=(1<<k)-1;a<(1<<n);a##x=a&-a,a##y=a+a##x,a=(((a&~a##y)/a##x)>>1)|a##y)
#define uniq(v) sort(all(v));v.erase(unique(all(v)), v.end())
#define bit(n) (1LL<<(n))
#define randInt(l,r) (uniform_int_distribution<ll>(l,r)(rnd))
#define randDouble(l,r) (uniform_real_distribution<double>(l,r)(rnd))
#define dout(d) printf("%.12f\n",d)

typedef long long ll;
typedef __int128_t lll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>ostream& operator<<(ostream& o,const pair<T,Y>& p){return o<<"("<<p.fi<<", "<<p.se<<")";}
template<typename A,size_t N,typename T>void Fill(A (&array)[N],const T&v){fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0;return gcd(a,b,x,y);}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return (x%m+m)%m;}
ll modPow(lll a,lll n,ll m){if(!a)return a;lll p=1;for(;n>0;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
bool isPrime(ll n){if(n<2||n%2==0)return n==2;lll t=n-1,d=t/(t&-t);for(lll a:{2,325,9375,28178,450775,9780504,1795265022})if(a%n){for(t=d,a=modPow(a,t,n);t!=n-1&&a!=1&&a!=n-1;a=a*a%n,t=t*2%n);if(a!=n-1&&t%2==0)return 0;}return 1;}
const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7;
const double PI = acos(-1);
const double EPS = 1e-10;
static random_device rd;
static mt19937 rnd(rd());

const int N = 1e5;
int n;
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  if(n%1000%111 && n/10%111){
    cout << "No" << endl;
  }else{
    cout << "Yes" << endl;
  }
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	scanInit()

	n := nextInt()

	v := float64(n) / 1.08

	if isInteger(v) {
		fmt.Println(v)
		return
	}

	if int(float64(int(v))*1.08) == n {
		fmt.Println(int(v))
		return
	}
	if int(float64(int(v+1))*1.08) == n {
		fmt.Println(int(v + 1))
		return
	}
	fmt.Println(":(")

}
func isInteger(x float64) bool {
	return math.Floor(x) == x
}

// ---- readfunc
func scanInit() {
	const cap = 64 * 1024
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


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

int main(){
  int n,a[101];
  cin>>n;
  for(int i=0;i<n;i++) cin>>a[i];
  for(int j=0;j<n;j++){
    if(j) cout<<" ";
    cout<<a[n-j-1];
  }
  cout<<endl;
}


Measured memory_bytes: 3076
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
	long long a;
	while(scanf("%lld",&a),a){
		long long ret=0;
		vector<long long>v;
		for(int i=1;(long long)i*i<=a;i++){
			if(a%i==0){
				v.push_back(a/i);
				if((long long)i*i!=a)v.push_back(i);
			}
		}
		vector<long long>p;
		long long b=a;
		for(int i=2;(long long)i*i<=b;i++){
			if(b%i==0){
				p.push_back(i);
				while(b%i==0)b/=i;
			}
		}
		if(b>1)p.push_back(b);
		for(int i=0;i<v.size();i++){
			long long d=a/v[i];
			int tmp=0;
			for(int j=0;j<p.size();j++)if(d%p[j]==0)tmp++;
			ret+=(1LL<<tmp);
		}
		printf("%lld\n",ret/2+1);
	}
}

Measured memory_bytes: 1080
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

int main(int argc, char const *argv[]) {
    int a,b;
    while (true) {
        cin>>a>>b; if (!a&&!b) break;
        if (b<a) swap(a,b);
        printf("%d %d\n",a,b);
    }
    return 0;
}


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

using ll=long long;

int in(){
  int a;
  cin >> a;
  return a;
}//int型関数の受け取り

void forin(int* x,int y){
  for (int i=0;i<y;i++){
    cin >> x[i];
  }
}//(x,y) int型配列x[y]の受け取り

int fact(int x){
  if (x == 1) return 1;
  return x*fact(x-1);
}//(x) x!

int div1(ll x){
  return x%1000000007;
}

main(){
    int n=in(),we=in(),w[n],v[n];
    for (int i=0;i<n;i++) cin >> w[i] >> v[i];
    ll dp[n+1][we+1] = {};
    for (int i=1;i<n+1;i++){
        for (int i2=1;i2<we+1;i2++){
            if (i2<w[i-1]){
                dp[i][i2]=dp[i-1][i2];
            }
            else{
                dp[i][i2]=max(dp[i-1][i2],dp[i-1][i2-w[i-1]]+v[i-1]);
            }
        }
    }
    cout << dp[n][we] << endl;
}

Measured memory_bytes: 79104
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define endl "\n"
#define fast ios::sync_with_stdio(0);cin.tie(NULL);std::cout.tie(NULL);
#define endl "\n"
#define vst vector<char>
#define vll vector<ll>
#define fo(i, x, y)   for (__typeof(x) i = x; i < y; ++i)
#define fr(i, x, y)   for (__typeof(x) i = x; i > y; i--)
#define sort(a) stable_sort(a.begin(),a.end())
#define sortd(a) stable_sort(a.begin(),a.end(),greater<int>())
#define vpr vector<pair<ll,ll>>
#define gcd(a,b) __gcd(a,b)
#define TC ll t; cin>>t; while(t--)
#define F first
#define S second
const ll N=1e9+7;
ll lcm(ll x,ll y){return (x*y*1LL)/gcd(x,y);}
 
ll power(ll x, ll y){ 
    ll res = 1; 
    while (y > 0){
        if (y & 1) 
            res = ((res) * (x));
        res %= N; 
        y = y >> 1; 
        x = ((x) * (x)); 
    }
    return res; 
}
 
ll powmod(ll a,ll b,ll n)
{
    ll x=1, y=a; 
    while (b > 0) 
    {
        if (b%2 == 1) 
        {
            x = (x*y) % n;
        }
        y = (y*y) % n; 
        b /= 2;
    }
    return x % n;
}
ll prime(ll n)
{
    for(ll i=2;i<=sqrt(n);i++)
    {
        if(n%i==0)
        {
            return 0;
        }
    }
    return 1;
}

  

int main()
{
   fast;
   ll n,k;
   cin>>n>>k;
   ll a[n];
   fo(i,0,n)
   cin>>a[i];
   ll dp[n]={0};
   dp[1]=abs(a[1]-a[0]);
   
   fo(i,2,n)
   {
       ll mini=100000000000001;
       for(ll j=1;j<=k;j++)
       {
           if(i-j>=0)
           {
               
           ll v1=dp[i-j]+abs(a[i]-a[i-j]);
           mini=min(mini,v1);
           }
           else
           break;
       }
       dp[i]=mini;
   }
   cout<<dp[n-1]<<endl;

   
    
}  


Measured memory_bytes: 5256
#include<bits/stdc++.h>
using namespace std;
#define fo(i,a,n) for(int i=a;i<n;i++)
#define rfo(i,n,a) for(int i=n;i>=a;i++)
#define ll long long int
#define p(a,b) pair<a,b>
#define mp(a,b) make_pair(a,b)
#define hpq(a) priority_queue<a>
#define lpq(a) priority_queue<a, vector<a>, greater<a>>
#define nl endl
#define pb(x) push_back(x);
#define ft(x,a) for(auto &it : a)
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
/*

   *                          (                            (
 (  `          )   )          )\ )            )            )\ )        (      )    *   )              )                                                  (
 )\))(      ( /(( /(   (  (  (()/(  (      ( /(   (  (    (()/(        )\  ( /(  ` )  /((   (      ( /(                   (         )    (               )\ )  (
((_)()\  (  )\())\()) ))\ )(  /(_))))\  (  )\()) ))\ )(    /(_))  (   ((_) )\())  ( )(_))(  )\ )   )\())(     (  (  `  )  )\ )     (     )\ )    (  (   (()/( ))\
(_()((_) )\(_))((_)\ /((_|()\(_))_/((_) )\((_)\ /((_|()\  (_))_   )\  )\ )(_))/  (_(_()|()\(()/(  (_))/ )\    )\ )\ /(/( (()/(     )\  '(()/(    )\ )\   ((_))((_)
|  \/  |((_) |_| |(_|_))  ((_) |_(_))( ((_) |(_|_))  ((_)  |   \ ((_)_(_/(| |_   |_   _|((_))(_)) | |_ ((_)  ((_|(_|(_)_\ )(_))  _((_))  )(_))  ((_|(_)  _| (_))
| |\/| / _ \  _| ' \/ -_)| '_| __| || / _|| / // -_)| '_|  | |) / _ \ ' \))  _|    | | | '_| || | |  _/ _ \ / _/ _ \ '_ \) || | | '  \()| || | / _/ _ \/ _` / -_)
|_|  |_\___/\__|_||_\___||_| |_|  \_,_\__||_\_\\___||_|    |___/\___/_||_| \__|    |_| |_|  \_, |  \__\___/ \__\___/ .__/ \_, | |_|_|_|  \_, | \__\___/\__,_\___|
                                                                                            |__/                   |_|    |__/           |__/

*/
int main()
{
    int n;
    cin>>n;
    int a[n];
    map<int,int> m;
    string s="YES";
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        m[a[i]]++;
        if(m[a[i]]>1)
            s="NO";
    }
    cout<<s;
}


Measured memory_bytes: 10368
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
 
class Simple {
    long N, M;
    void Solve() {
        //input
        N = io.Long;
        M = io.Long;
        //cal
        var ans=(long)(100*(N-M)+1900*M)*Math.Pow(2,M);
        //ret
        Console.WriteLine(ans);
    }
 
 
    SimpleIO io = new SimpleIO();
    public static void Main(string[] args) { new Simple().Stream(); }
    void Stream() { Solve(); io.writeFlush(); }
}
 
class SimpleIO {
    string[] nextBuffer;
    int BufferCnt;
    char[] cs = new char[] { ' ' };
    StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
    public SimpleIO() {
        nextBuffer = new string[0];
        BufferCnt = 0;
        Console.SetOut(sw);
    }
    public string Next() {
        if (BufferCnt < nextBuffer.Length)
            return nextBuffer[BufferCnt++];
        string st = Console.ReadLine();
        while (st == "")
            st = Console.ReadLine();
        nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        BufferCnt = 0;
        return nextBuffer[BufferCnt++];
    }
    public string String => Next();
    public char Char => char.Parse(String);
    public int Int => int.Parse(String);
    public long Long => long.Parse(String);
    public double Double => double.Parse(String);
    public void writeFlush() { Console.Out.Flush(); }
}

Measured memory_bytes: 11092
N,X = map(int,input().split())
a = list(map(int,input().split()))
a.sort()

b = []
for _ in range(N):
    b.append(0)
    
c = 0

for i in range(N):
    for j in range(i+1):
        b[i] += a[j]

for k in range(N-1):
    if b[k] <= X:
        c += 1
if b[N-1] == X:
    c += 1
print(c)

Measured memory_bytes: 3064
fn main() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let nums: Vec<i32> = s.trim()
        .split_whitespace()
        .map(|e| e.parse().unwrap()).collect();
    let (w, h, x, y, r): (i32, i32, i32, i32, i32)
                          = (nums[0], nums[1], nums[2], nums[3], nums[4]);
    if x + r <= w && x - r >= 0 && y + r <= h && y - r >= 0 {
        println!("Yes");
    } else {
        println!("No");
    }
}



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

using namespace std;

char field[110][110];
int ans[110][110];

int main() {
    int h, w;
    cin >> h >> w;
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            ans[i][j] = -1;
            cin >> field[i][j];
            if (field[i][j] == 'c') {
                ans[i][j] = 0;
            }
        }
    }
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            if (field[i][j] == 'c') {
                int nx = i, ny = j + 1;
                while (field[nx][ny] == '.') {
                    ans[nx][ny] = ans[nx][ny - 1] + 1;
                    ++ny;
                }
            }
        }
    }
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            cout << ans[i][j] ;
            if (j != w - 1) {
                cout << " ";
            }
        }
        cout << '\n';
    }
}


Measured memory_bytes: 3144
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    int L[100];
    L[0] = 2;
    L[1] = 1;
    REP(i, 2, N) {
        L[i] = L[i - 1] + L[i - 2];
    }
    cout << L[N] << endl;

    return 0;
}


Measured memory_bytes: 256
wa = 0
count = 0
s = input()
if s[0] != "A":
    wa = 1
for i in range(1, len(s)):
    if s[i] == "C" and i not in  {len(s)-1,1} :
        count += 1
        if count >= 2:
            wa = 1
    else:
        if s[i].isupper():
            wa = 1
print("AC" if not wa and count else "WA")


Measured memory_bytes: 3064
#include <stdio.h>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <math.h>
using namespace std;

//vector <pair <long long int,int>> p[8];
int n,m;
int main(void)
{
    cin >> n;    
    for(int i=0; i<100; i++){
        for(int j=0; j<100; j++){
            if(4*i + 7*j == n){
                cout << "Yes";
                return 0;
            }
        }
    }
    cout << "No";
 return 0;
}


Measured memory_bytes: 256
// -----------------------------------
// Author     : MatsuTaku
// Affiliation: Tokushima University
// Country    : Japan
// Date       : 03/26/2020
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

  string N; cin>>N;
  int K; cin>>K;
  vector<array<int, 4>> dpe(N.size()), dpl(N.size());
  dpe[0][1] = 1;
  dpl[0][1] = N[0]-'1';
  dpl[0][0] = 1;
  for (int i = 1; i < N.size(); i++) {
    auto n = N[i]-'0';
    if (n == 0) {
      dpe[i] = dpe[i-1];
    } else {
      for (int j = 1; j < 4; j++) {
        dpe[i][j] = dpe[i-1][j-1];
        dpl[i][j] += dpe[i-1][j-1]*(n-1) + dpe[i-1][j];
      }
    }
    for (int j = 0; j < 4; j++) {
      dpl[i][j] += dpl[i-1][j];
    }
    for (int j = 1; j < 4; j++) {
      dpl[i][j] += dpl[i-1][j-1]*9;
    }
  }
  auto ans = dpe.back()[K] + dpl.back()[K];
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int a[][]=new int[3][3];
		 for(int i=0;i<3;i++)  
		    {  
		        for(int j=0;j<3;j++)  
		            a[i][j]=sc.nextInt();
		    } 
		 int sum1,sum2,sum3,sum4;  
		    sum1=a[0][0]+a[1][1]+a[2][2];  
		    sum2=a[0][1]+a[1][2]+a[2][0];  
		    sum3=a[1][0]+a[2][1]+a[0][2];  
		    if(sum1==sum2&&sum2==sum3)  
		       System.out.println("Yes"); 
		    else
               System.out.println("No");
	}

}


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

int linearSearch(int S[], int n, int key){
    int i = 0;
    S[n] = key;
    while ( S[i] != key ){
        i++;
    }
    if ( i == n ) return -1;
    return i;
}   

int main(){
    int n, q;
    int S[100001], key;
    int sum = 0;
    cin >> n;
    for ( int i = 0; i < n; i++ ) cin >> S[i];
    cin >> q;
    for ( int i = 0; i < q; i++ ){
        cin >> key;
        if ( linearSearch(S, n, key) == -1 ) continue;
        else sum++;
    }
    cout << sum << endl;
    
    return 0;
}


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


public class Main {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
		int h = sc.nextInt();
		@SuppressWarnings("unused")
		int w = sc.nextInt();

		char[][] c = new char[h][];
		for (int i = 0; i < h; i++) {
			c[i] = sc.next().toCharArray();

			pr.println(c[i]);
			pr.println(c[i]);
		}

	}

	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		pr = new Printer(System.out);

		solve();

		pr.close();
		sc.close();
	}

	private static class Printer extends PrintWriter {
		Printer(PrintStream out) {
			super(out);
		}
	}
}


Measured memory_bytes: 10320
#include <bits/stdc++.h>
using namespace std;
						
#define fast_cin() ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define endl '\n'
#define int long long
#define ld long double

const int N = 301;

int n, a[N];
ld dp[N][N][N];

ld solve(int cnt1, int cnt2, int cnt3) {
	if (cnt1 == 0 && cnt2 == 0 && cnt3 == 0) {
		return 0.0;
	}
	ld &ans = dp[cnt1][cnt2][cnt3];
	if (ans == ans) return ans;
	ans = 0.0;
	if (cnt1 > 0) ans += ((ld)cnt1 / n) * (solve(cnt1 - 1, cnt2, cnt3) + 1);
	if (cnt2 > 0) ans += ((ld)cnt2 / n) * (solve(cnt1 + 1, cnt2 - 1, cnt3) + 1);
	if (cnt3 > 0) ans += ((ld)cnt3 / n) * (solve(cnt1, cnt2 + 1, cnt3 - 1) + 1); 
	int sum = cnt1 + cnt2 + cnt3;
	ans += (ld)(n - sum) / n;
	ans *= (ld)n / sum;
	return ans;
}
				
int32_t main() {
	fast_cin();  
	cin >> n;
	int cnt1 = 0, cnt2 = 0, cnt3 = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		cnt1 += (a[i] == 1);
		cnt2 += (a[i] == 2);
		cnt3 += (a[i] == 3);
	}
	memset(dp, -1, sizeof dp);
	ld ans = solve(cnt1, cnt2, cnt3);
	cout << fixed << setprecision(13) << ans << endl;
	return 0;
}

Measured memory_bytes: 426368
#include<bits/stdc++.h>
#define rep(i,k) for(int i=0;i<k;i++)
using namespace std;
int main(){
    int count=0;
    int a,b,c,x;
    cin>>a>>b>>c>>x;
    rep(i,a+1)rep(j,b+1)rep(k,c+1){
        if(500*i+100*j+50*k==x) count++;
    }
    cout<<count<<endl;
    return 0;
}

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

void solve(){
	int n;
	cin>>n;
	vector<int> v(n);
	for(int i=0;i<n;i++)
	{
		cin>>v[i];
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			swap(v[i],v[j]);
			if(is_sorted(v.begin(),v.end())){
				cout<<"YES";
			return ;
			}
			swap(v[i],v[j]);
		}
		
	}
cout<<"NO";

}


int main() {
solve();


}



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

using namespace std;
typedef long long ll;
ll a[maxn],n,ans;

int main(){
    cin >> n;
    for (int i=0;i<n;i++) cin >> a[i],a[i]-=i;
    sort(a,a+n);
    for (int i=0;i<n;i++) ans+=abs(a[i]-a[n/2]);
    cout << ans << endl;
}


Measured memory_bytes: 1792
/*************************************************************************
    > File Name: aoj2249.cpp
    > Author:    WArobot 
    > Blog:      http://www.cnblogs.com/WArobot/ 
    > Created Time: 2017??´06???20??\ ????????? 15??¶23???28?§?
 ************************************************************************/

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

const int MAX_N = 12345;
const int MAX_M = 20010;
const int INF = 0x3f3f3f3f;

struct edge{
	int to , cost , money;
	edge(int tt , int tc , int tm) : to(tt) , cost(tc) , money(tm) {} ;
};
typedef pair<int,int> P;

vector< edge > G[MAX_N];
int dis[MAX_N];
int n , m;
int ans[MAX_N];

void Dijkstra(){
	fill(dis,dis+n+1,INF);
	dis[1] = 0;
	priority_queue< P , vector<P> , greater<P> >	que;
	que.push( P(0,1) );
	while(!que.empty()){
		P p = que.top();	que.pop();
		int v = p.second;
		if( dis[v] < p.first )	continue;
		for(int i = 0 ; i < G[v].size() ; i++){
			edge e = G[v][i];
			if( dis[e.to] > dis[v] + e.cost ){
				dis[e.to] = dis[v] + e.cost;
				que.push( P(dis[e.to] , e.to) );
			}
		}
	}
}
int main(){
	int u , v , cost , money;
	while(~scanf("%d%d",&n,&m) && (n+m)){
		for(int i = 0 ; i <= n ; i++)	G[i].clear();
		for(int i = 0 ; i < m ; i++){
			scanf("%d%d%d%d",&u,&v,&cost,&money);
			G[u].push_back( edge(v,cost,money) );
			G[v].push_back( edge(u,cost,money) );
		}
		Dijkstra();
		fill(ans,ans+n+1,INF);
		for(int i = 1 ; i <= n ; i++){
			// ????????????????¶???????????????¶????´???¨???????????£??????????´???¨
			for(int j = 0 ; j < G[i].size() ; j++){
				edge e = G[i][j];
				if( dis[i] + e.cost == dis[e.to] ){
					ans[e.to] = min( ans[e.to] , e.money );
				}
			}
		}
		int sum = 0;
		for(int i = 2 ; i <= n ; i++)	sum += ans[i];
		printf("%d\n",sum);
	}
	return 0;
}

Measured memory_bytes: 5204
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <random>
#include <cstdio>
#include <cstring>
#include <cmath>

// for i in f..<t {... : as Swift
#define forin(i, f, t) for(auto i = f; i < t; i++)

using namespace std;
using ll = long long;

const char Black = 'B';
const char White = 'W';

int n, k;

struct stus {
    ll x, y;
    char c;
    void cast() {
        x %= 2 * k;
        if (c == White) y += k;
        c = Black;
        y %= 2 * k;
    }
};

int bb[4000][4000];
int acc[4001][4001];

int sumb(int dx, int dy, int dtx, int dty) {
    return acc[dx][dy] + acc[dtx][dty] - acc[dx][dty] - acc[dtx][dy];
}

int main() {
    cin >> n >> k;
    stus s[n];
    forin(i, 0, n) {
        auto &st = s[i];
        cin >> st.x >> st.y >> st.c;
        st.cast();
    }
    auto k2 = 2 * k;
    for (auto &st : s) {
        bb[st.x][st.y]++;
        bb[st.x + k2][st.y]++;
        bb[st.x][st.y + k2]++;
        bb[st.x + k2][st.y + k2]++;
    }
    forin(i, 0, 4 * k) {
        forin(j, 0, 4 * k) {
            acc[i + 1][j + 1] = acc[i][j + 1] + acc[i + 1][j] - acc[i][j] + bb[i][j];
        }
    }
    
    auto maxDreams = 0;
    forin(dx, 0, k2) {
        forin(dy, 0, k2) {
            auto dtx = dx + k, dty = dy + k;
            auto numb = sumb(dx, dy, dtx, dty);
            numb += sumb(dtx, dty, dtx + k, dty + k);
            maxDreams = max(numb, maxDreams);
        }
    }
    cout << maxDreams << endl;
}



Measured memory_bytes: 127616
n, m = map(int, input().split())
P = tuple(map(lambda x: int(x)-1, input().split()))
par = list(range(n))
size = [1] * n
def find(x):
    """ 根のノードの値を見つけて返す """
    if x != par[x]:
        par[x] = find(par[x])
    return par[x]

def unite(x, y):
    """xとyを結合する"""
    rootx = find(x)
    rooty = find(y)
    if rootx == rooty:
        return False
    else:
        if size[rootx] < size[rooty]:
            par[rootx] = rooty
            size[rooty] += size[rootx]
        else:
            par[rooty] = rootx
            size[rootx] += size[rooty]
        return True

def same(x, y):
    """ xとyが同じ集合に属しているか """
    return find(x) == find(y)

for _ in range(m):
    x, y = map(lambda x: int(x)-1, input().split())
    unite(x, y)
groups = {}
for idx, p in enumerate(par):
    p = find(p)
    groups.setdefault(p, set())
    groups[p].add(idx)

cnt = 0
for k, g in groups.items():
    for gi in g:
        pi = P[gi]
        if pi in g:
            cnt += 1
print(cnt)


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

using namespace std;

int n;
map<int, int> dp;

int dfs(int now) {
	int res = now;
	if (now == 0) return 0;
	if (dp.count(now)) return dp[now];
	int k = 6;
	while (k <= now) k *= 6;
	k /= 6;
	for (int i = k; i >= 6; i /= 6) {
		res = min(res, 1 + dfs(now - i));
	}
	k = 9;
	while (k <= now) k *= 9;
	k /= 9;
	for (int i = k; i >= 9; i /= 9) {
		res = min(res, 1 + dfs(now - i));
	}
	return dp[now] = res;
}

void hawawa()
{
	cin >> n;
	cout << dfs(n) << "\n";
}

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


Measured memory_bytes: 1792
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int n = Integer.valueOf(scan.next());
        int[] ns_b = new int[n];
        String[] strs_b = new String[n];
        int[] ns_s = new int[n];
        String[] strs_s = new String[n];
        for(int i=0;i<n;i++) {
        	String str = scan.next();
        	strs_s[i] = str.substring(0, 1);
        	ns_s[i] = Integer.valueOf(str.substring(1));
        	strs_b[i] = str.substring(0, 1);
        	ns_b[i] = Integer.valueOf(str.substring(1));
        }
        bubbleSort(ns_b,strs_b,n);
        selectionSort(ns_s,strs_s,n);
        for(int i=0;i<n-1;i++) {
        	System.out.print(strs_b[i]+ns_b[i]+" ");
        }
        System.out.println(strs_b[n-1]+ns_b[n-1]);
        System.out.println("Stable");
        for(int i=0;i<n-1;i++) {
        	System.out.print(strs_s[i]+ns_s[i]+" ");
        }
        System.out.println(strs_s[n-1]+ns_s[n-1]);
        boolean check = true;
        for(int i=0;i<n-1;i++) {
        	if(!strs_s[i].equals(strs_b[i])) {
        		check=false;
        		break;
        	}
        }
        if(check) {
        	System.out.println("Stable");
        }
        else {
        	System.out.println("Not stable");
        }
        scan.close();
    }
    
    public static void bubbleSort(int[] ns,String[]strs,int n) {
    	boolean fg = true;
        int change = 0;
        String changeS;
        while(fg) {
        	fg = false;
        	for(int i=n-1;i>0;i--) {
        		if(ns[i] < ns[i-1]) {
        			change =  ns[i];
        			ns[i] = ns[i-1];
        			ns[i-1] = change;
        			changeS =  strs[i];
        			strs[i] = strs[i-1];
        			strs[i-1] = changeS;
        			fg=true;
        		}
        	}
        }
    }
    
    public static void selectionSort(int[] ns,String[]strs,int n) {
    	int change = 0;
        int minj=0;
        String changeS;
        for(int i=0;i<n;i++) {
        	minj = i; 
        	for(int j=i;j<n;j++) {
        		if(ns[j]<ns[minj]) {
        			minj = j;
        		}
        	}
        	if(minj!=i) {
	        	change = ns[minj];
	        	ns[minj] = ns[i];
	        	ns[i] = change;
	        	changeS = strs[minj];
	        	strs[minj] = strs[i];
	        	strs[i] = changeS;
        	}
        }
    }
}


Measured memory_bytes: 26396
#include "bits/stdc++.h"
using namespace std;
typedef long long LL;
int main() {
	int N, T;
	cin >> N >> T;
	int l = 0, r = 0;
	LL X = 0;
	for (int i = 0; i < N; i++) {
		int t;
		cin >> t;
		if (r < t) X += (r - l), l = t, r = t + T;
		else r = t + T;
	}
	X += r - l;
	cout << X << endl;
}

Measured memory_bytes: 256