akhauriyash/Code-Regression huggingface dataset:
n,m,x = map(int, input().split())
dat = []
for i in range(n):
    l = list(map(int, input().split()))
    dat.append(l)
#print(dat)
res = 999999999999999999999999999
for i in range(2**n):
    pat = "{:020b}".format(i)
    pat = pat[::-1]
    #print(pat)
    cost = 0
    kekka = [0] * m
    for j in range(n):
        if pat[j] == "1":
            cost += dat[j][0]
            item = dat[j][1:]
            for k in range(m):
                kekka[k] += item[k]
    can = True
    #print(kekka)
    #print(">cost", cost)
    for k in range(m):
        if kekka[k] < x:
            can= False
    if can:
        #print("ok", cost)
        res = min(res, cost)

if res == 999999999999999999999999999:
    print(-1)
else:
    print(res)

Measured memory_bytes: 68636
# -*- coding: utf-8 -*-
import heapq
import sys
sys.setrecursionlimit(10**9)

# 全頂点からのゴールへの到達可能性を確認
# 頂点1からDFSしてNまできたら、それまでのパス全てについて到達可能に更新
# その後、到達可能な部分のみを新たな辺にして、ベルマンフォード
# 辺の重みは（C - P）
# 負閉路を検出したなら-1
# そうでなければNまでの距離


N, M , P = map(int,input().split())
ABC = [list(map(int,input().split())) for _ in range (M)]

Edge = [[] for _ in range(N)]
for a,b,c in ABC:
    Edge[b-1].append(a-1)


reachable = [False]*N
reachable[N-1] = True

def dfs(v):
    for nv in Edge[v]:
        if reachable[nv]:
            continue
        else:
            reachable[nv] = True
            dfs(nv)
    return 

def BellmanFord(s, N, Edge):
    INF = 10**20
    dist = [INF] * N
    dist[s] = 0
    for i in range(N):
        isUpdated = False
        for t in range(N):
            if dist[t] == INF:
                continue
            for v,c in Edge[t]:
                if dist[t]+c < dist[v]:
                    dist[v] = dist[t]+c
                    isUpdated = True
        if not isUpdated:
            break
        elif i==N-1:
            return -1
    return dist

                
dfs(N-1)
newEdge = [[] for _ in range(N)]
for a,b,c in ABC:
    if reachable[a-1]:
        newEdge[a-1].append([b-1, P-c])

dist = BellmanFord(0, N, newEdge)
if dist==-1:
    print(-1)
else:
    print(max(0, -dist[N-1]))






Measured memory_bytes: 56408
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
using namespace std;
using ll = long long int;

int n;
ll k;
vector<ll> A;
vector<ll> S;

int main(){
    cin >> n >> k;
    A.resize(n+3);
    for(int i = 1; i <= n; i++){
        cin >> A[i];
        A[i] %= k;
    }

    S.resize(n+3);
    S[0] = 0;
    ll tot = 0;
    ll ans = 0;
    map<ll, ll> M;
    M[0] = 1;
    for(int i = 1; i <= n; i++){
        if (i >= k){
            M[S[i-k]]--;
        }
        tot += A[i];
        int ik = i % k;
        ll now = (tot + k - ik) % k;
        if (M.find(now) != M.end()){
            ans += M[now];
            M[now]++;
        }
        else M[now] = 1;

        S[i] = now;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 18356
import sys
input = sys.stdin.readline
N, Q = map(int, input().split())
G = [set() for _ in range(N+1)]
for i in range(N-1):
    a, b = map(int, input().split())
    G[a].add(b)
    G[b].add(a)

g2 = [set() for _ in range(N+1)]
p = [0]*(N+1)
vs = set()
stack = [1]
dfs_vs = []
vs.add(1)
while stack:
    v = stack.pop()
    dfs_vs.append(v)
    for u in G[v]:
        if u in vs:
            continue
        g2[v].add(u)
        p[u] = v
        stack.append(u)
        vs.add(u)

d = [0]*(N+1)
for i in range(Q):
    z, x = map(int, input().split())
    d[z] += x

#print(d)
#print(p)

for v in dfs_vs:
    d[v] += d[p[v]]

print(*d[1:])


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

int count_digit(long long int n) {
	int i;

	i = 0;
	while(n > 0) {
		n /= 10;
		i += 1;
	}
	return i;
}

int main(void) {
	long long int N;
	long long int a, b;
	int a_digit, b_digit;
	double sqrtN;
	char buf[128], *ch;

	fgets(buf, sizeof(buf), stdin);
	ch = strtok(buf, " ");
	N = atoll(ch);

	sqrtN = sqrt((double)N) + 1;

	b = 1;
	a = 1;
	while(b < sqrtN) {
		if(N % b == 0) {
			a = b;
		}
		b += 1;
	}

	b = N / a;
	a_digit = count_digit(a);
	b_digit = count_digit(b);
	if(a_digit >= b_digit) {
		printf("%d\n", a_digit);
	} else {
		printf("%d\n", b_digit);
	}

	return 0;
}


Measured memory_bytes: 2076
#include <iostream>
#include <vector>
#include <cstring>
using namespace std;

const int maxn = 200000;

vector<int> graph[maxn];
int color[maxn];
bool visited[maxn][20];

void dfs(int v, int d, int c) {
    if (color[v] == 0) {
        color[v] = c;
    }
    if (visited[v][d] or d == 0) return;
    visited[v][d] = true;

    dfs(v, d - 1, c);

    for (int to : graph[v]) {
        dfs(to, d - 1, c);
    }
}

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

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

        graph[a].emplace_back(b);
        graph[b].emplace_back(a);
    }

    int Q;
    cin >> Q;

    vector<int> v(Q), d(Q), c(Q);
    for (int i = 0; i < Q; i++) {
        cin >> v[i] >> d[i] >> c[i];
        v[i]--;
    }

    for (int i = Q - 1; i >= 0; i--) {
        dfs(v[i], d[i], c[i]);
    }

    for (int i = 0; i < N; i++) {
        cout << color[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 14584
#pragma GCC optimize("Ofast")
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // setprecision
#include <complex> // complex
#include <math.h> 
#include <functional>
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
// constexpr ll mod = 998244353;
const int dx[8] = {1, 0, -1, 0,1,1,-1,-1};
const int dy[8] = {0, 1, 0, -1,1,-1,1,-1};
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; }
// --------------------------------------------------------------------------

#include "atcoder/dsu.hpp"

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N,Q;
  cin >> N >> Q;
  atcoder::dsu uf(N);
  while(Q--){
	int id;
    cin >> id;
    int u,v;
    cin >> u >> v;
    if(id == 0){
      uf.merge(u,v);
    }else{
      cout << (uf.same(u,v)) << "\n";
    }
  }
  return 0;
}

Measured memory_bytes: 3832
#include<iostream>
#include<math.h>
using namespace std;
#define lns 1e13;

int main()
{
    long long n, ans;
    long long a = 1, b;
    cin >> n;
    for(int i = 1; i < sqrt(n)+1; i++){
        if(n%i == 0){
            a = i;
            b = n/i;
        }
    }

    ans = (a + b) - 2;

    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int arr[n],dp[n];
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    dp[0]=0;
    //dp[1]=0;
    for(int i=1;i<n;i++)
    {
        dp[i]=INT_MAX;
        for(int j:{i-1,i-2})
        {
            if(j>=0)
            {
                dp[i]=min(dp[j]+abs(arr[j]-arr[i]),dp[i]);
            }
        }
    }
    cout<<dp[n-1]<<endl;

}

Measured memory_bytes: 1024
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	var n int
	var dp [100001][3]int

	fmt.Scanf("%d", &n)

	abc := make([][]int, n+1)
	for i := 0; i < n; i++ {
		abci := nextInts(3)
		abc[i] = abci
	}

	abc[n] = []int{0, 0, 0}
	for i := 0; i < 3; i++ {
		dp[0][i] = abc[0][i]
	}

	for i := 0; i < n; i++ {
		for j := 0; j < 3; j++ {
			if j == 0 {
				dp[i+1][0] = Max(dp[i][1], dp[i][2]) + abc[i+1][0]
			} else if j == 1 {
				dp[i+1][1] = Max(dp[i][0], dp[i][2]) + abc[i+1][1]
			} else {
				dp[i+1][2] = Max(dp[i][0], dp[i][1]) + abc[i+1][2]
			}
		}
	}
	ans := 0
	for i := 0; i < 3; i++ {
		ans = Max(ans, dp[n-1][i])
	}

	fmt.Println(ans)
}

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

func NextLineInt() []int {
	lineString := strings.Split(NextInt(), " ")
	var lineInt = make([]int, len(lineString))
	for i := range lineString {
		lineInt[i], _ = strconv.Atoi(lineString[i])
	}
	return lineInt
}

func Bool2Int(b bool) int {
	if b {
		return 1
	} else {
		return 0
	}
}

func Abs(v int) int {
	if v < 0 {
		return -v
	}
	return v
}

func Min(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}

func Max(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func Distance(a, b int) int {
	return Abs(a - b)
}

func nextInts(n int) []int {
	r := make([]int, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt()
	}
	return r
}

func nextInt() int {
	v, _ := strconv.Atoi(nextReader())
	return v
}

var nextReader func() string

func init() {
	nextReader = NewScanner()
}

func NewScanner() func() string {
	r := bufio.NewScanner(os.Stdin)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)
	return func() string {
		r.Scan()
		return r.Text()
	}
}


Measured memory_bytes: 9856
#include <iostream>

using namespace std;
int main() {
  int a, b, c;
  cin >> a >> b >> c;
  if (a + b == c || b + c == a || c + a == b){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;    
  }
  return 0;
}


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

using namespace std;
typedef long long ll;

int main() {
  string S; cin >> S;
  set<char> m;
  for (char c : S) {
    m.insert(c);
  }
  cout << (m.size() == 2 ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 256
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;


void main() {
    int n;
    scan(n);
    auto a = readln.split.to!(int[]);

    auto b = new int[](n);
    foreach (i ; 0 .. n) {
        b[i] = a[i] - (i + 1);
    }

    b.sort();

    auto med = b[n / 2];

    long ans;

    foreach (i ; 0 .. n) {
        ans += abs(b[i] - med);
    }

    writeln(ans);
}






































void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}


Measured memory_bytes: 11608
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define chmin(a,b) a = min(a,b)
#define chmax(a,b) a = max(a,b)
using namespace std;
using ll = long long;
using vi = vector<int>;
using vv = vector<vi>;
using P  = pair<int,int>;//(cost,to)
using vP = vector<P>;
using vvP= vector<vP>;

const int INF = 1001001001;


int main(){
    int n;cin>>n;
    
    vector<ll> a(n);
    
    rep(i,n)cin>>a[i];
    
    sort(a.rbegin(), a.rend());
    
    ll ans = 0;
    rep(i,n-1){
        ans += a[(i+1)/2];
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4840
#include <bits/stdc++.h>
typedef long long ll; 
const ll mod = 1e9+7;
#define fo(i, n) for (int i = 0; i < n; i++)
#define sc(n) scanf("%d", &n) 
using namespace std;

void solve() {
    int n; sc(n);
    char s[n]; scanf("%s", s);
    char c = s[0];
    int ans = 1;
    for(int i = 1; i < n; i++) {
        if (s[i] != c) {
            c = s[i];
            ans++;
        }
    }
    printf("%d", ans);
}

int main() {
    int t = 1;
    //scanf("%d", &t);
    while (t--) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 384
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
typedef long long ll;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    ll H, W, N;
    cin >> H >> W >> N;
    using pii = pair<int, int>;
    map<pii, int> mp;
    rep(k, N) {
        int a, b;
        cin >> b >> a;
        for(int i = -1; i <= 1; i++) {
            for(int j = -1; j <= 1; j++) {
                if(a + i - 1 >= 1 && a + i + 1 <= W && b + j - 1 >= 1 &&
                   b + j + 1 <= H) {
                    mp[MP(a + i, b + j)]++;
                }
            }
        }
    }
    vector<ll> res(10, 0);
    ll sum = 0;
    for(pair<pii, ll> x : mp) {
        // cout << x.first.first << " " << x.first.second << " " << x.second
        //  << endl;
        res[x.second]++;
        sum++;
    }
    res[0] = (H - 2LL) * (W - 2LL) - sum;
    rep(i, 10) { cout << res[i] << endl; }
    return 0;
}

Measured memory_bytes: 56448
#if __has_include("../library/Basic/Debug.hpp")

#include "../library/Basic/Debug.hpp"

#else

/* ----- Header Files ----- */
// IO
#include <cstdio>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm
#include <algorithm>
#include <cmath>
#include <numeric>

// container
#include <vector>
#include <string>
#include <tuple>
#include <complex>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>

// others
#include <random>
#include <limits>
#include <functional>
#include <ctime>
#include <cassert>
#include <cstdint>

/* ----- Type Alias ----- */
using Int = long long int;
using Real = long double;
using std::pair;
using std::string;
using std::tuple;
using std::vector;
template <class T>
using MaxHeap = std::priority_queue<T>;
template <class T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template <class T>
T genv(T v) { return v; }

template <class T, class... Ts>
auto genv(size_t l, Ts... ts) {
    return vector<decltype(genv<T>(ts...))>(l, genv<T>(ts...));
}

template <class Cost = Int>
struct Edge {
    Int src, dst;
    Cost cost;
    Edge(Int src = -1, Int dst = -1, Cost cost = 1)
        : src(src), dst(dst), cost(cost){};

    bool operator<(const Edge<Cost>& e) const { return this->cost < e.cost; }
    bool operator>(const Edge<Cost>& e) const { return this->cost > e.cost; }
};

template <class Cost = Int>
using Edges = vector<Edge<Cost>>;
template <class Cost = Int>
using Graph = vector<vector<Edge<Cost>>>;

#endif

/* ----- Misc ----- */
void fastio() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
}

struct Fout {
    Int precision;
    Fout(Int precision) : precision(precision) {}
};
std::ostream& operator<<(std::ostream& os, const Fout& fio) {
    os << std::fixed << std::setprecision(fio.precision);
    return os;
}


/* ----- Constants ----- */
// constexpr Int INF = std::numeric_limits<Int>::max() / 3;
// constexpr Int MOD = 1000000007;
const Real PI = acos(-1);
// constexpr Real EPS = 1e-10;
// std::mt19937 mt(int(std::time(nullptr)));

using std::complex;
using Complex = complex<Real>;

int fact(int n) {
    return n == 0 ? 1 : n * fact(n - 1);
}

int main() {
    int n;
    std::cin >> n;

    vector<Complex> xs(n);
    for (auto& x : xs) {
        Real a, b;
        std::cin >> a >> b;
        x = Complex(a, b);
    }
    xs.emplace(xs.begin(), 0);
    xs.emplace_back(0);

    Real ans = 1e100;
    for (int q = 0; q < fact(n); ++q) {
        Real theta = 0, sum = 0;
        for (int i = 0; i <= n; ++i) {
            Real phi = std::arg(xs[i + 1] - xs[i]);
            Real delta = std::abs(theta - phi);
            sum += std::min(delta, 2 * PI - delta) * 180 / PI;
            theta = phi;
        }
        ans = std::min(ans, sum);
        std::next_permutation(xs.begin() + 1, xs.end() - 1,
                              [](Complex a, Complex b) { return a.real() < b.real(); });
    }

    std::cout << Fout(10) << ans << std::endl;
    return 0;
}



Measured memory_bytes: 3360
S,T = 2.times.map{gets.chomp}
ST,TS = {}, {}

def s2t_ok?(i)
  if ST[S[i]] 
    ST[S[i]] == T[i] 
  else
    ST[S[i]] = T[i]
  end
end

def t2s_ok?(i)
  if TS[T[i]] 
    TS[T[i]] == S[i]
  else
    TS[T[i]] = S[i]
  end
end
  
ans = S.size.times.all? do |i|
  s2t_ok?(i) && t2s_ok?(i)
end
puts ans ? 'Yes' : 'No'

Measured memory_bytes: 2624
import java.util.*;
public class Main{
    static Scanner kbd = new Scanner(System.in);
    public static void main(String[] args){
	while(kbd.hasNext()){
	    long n = kbd.nextLong();
	    if(n!=0) solve(n);
	}
    }

    static void solve(long n){
	String s = Long.toOctalString(n);
	long[] k = new long[s.length()];
	int i;
	for(i=0; i<s.length(); i++)
	    k[i] = Long.parseLong(s.substring(i, i+1));
	s = "";
	for(i=0; i<k.length; i++){
	    if(k[i]>=4) k[i]++;
	    if(k[i]>=6) k[i]++;
	    s += Long.toString(k[i]);
	}
	n = Long.parseLong(s);
       
	System.out.println(s);
    }
}

Measured memory_bytes: 62924
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dy[] = {1, 0, -1, 0};
const int dx[] = {0, 1, 0, -1};
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    cout << (n - 1) * (m - 1) << endl;
    return 0;
}



Measured memory_bytes: 256
x, y = input().split()
price = 0
try:
    if 1 <= int(x) <= 205 and 1 <= int(y) <= 205:
        if int(x) == 1 and int(y) == 1:
            price += 400000
        if int(x) == 1:
            price += 300000
        elif int(x) == 2:
            price += 200000
        elif int(x) == 3:
            price += 100000
        if int(y) == 1:
            price += 300000
        elif int(y) == 2:
            price += 200000
        elif int(y) == 3:
            price += 100000

    print(price)
except:
    print(price)

Measured memory_bytes: 3064
n=int(input())
a=list(map(int,input().split()))
ct=0
b=[0]*n
for i in range(n):
    if  a[i]<0:
        ct+=1
        b[i]=-a[i]
    else:
        b[i]=a[i]
b.sort()
if ct%2==0:
    print(sum(b))
else:
    print(sum(b)-min(b)*2)

Measured memory_bytes: 14412
#include <stdio.h>

int main()
{
  int n, x;
  int i, j, k, count;

  while(1){
    scanf("%d %d", &n, &x);
    
    if(n == 0 && x == 0)
      break;

    count = 0;

    for(i = 1; i < n-1; i++){
      for(j = i+1; j < n; j++){
        for(k = j+1; k < n+1; k++){
          if(i+j+k == x)
            count++;
        }
      }
    }

    printf("%d\n", count);

  }

  return 0;
}

Measured memory_bytes: 1772
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)

int main(){
    ll N, K;
    cin >> N >> K;
    cout << (ll)(K * pow(K-1, N-1)) << endl;
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <iomanip>
// std::cout << std::setprecision(2) << 3.141; // "3.1"
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <map>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;

static const int giga = pow(10,9);
// double pi = 3.141592653589793238463;

int main(void){
  int n;
  cin >> n;

  for(int i = n/7; i >= 0; i--){
    if((n - i*7)%4 == 0){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

int main()
{
	int i, a, v[26];
	for (i = 0; i < 26; i++)
		v[i] = 0;
	char s[100000];
	scanf("%s", s);
	for (i = 0; s[i] != '\0'; i++)
	{
		a = (int)(s[i] - 'a');
		v[a]++;
	}
	for (i = 0; i < 26; i++)
	{
		if (v[i] == 0)
		{
			printf("%c", 'a' + i);
			return 0;
		}
	}
	printf("None");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>


void print_array(int a[], int n)
{
    for (int i = 0; i < n; ++i)
    {
        if (0 < i)
        {
            std::cout << " ";
        }

        std::cout << a[i];
    }

    std::cout << std::endl;
}

void insertion_sort(int a[], int n)
{
    for (int i = 1; i < n; ++i)
    {
        auto key = a[i];
        auto j = i - 1;
        while (j >= 0 && a[j] > key)
        {
            a[j + 1] = a[j];
            j--;
        }

        a[j + 1] = key;

        print_array(a, n);
    }
}


int main()
{
    int n;
    std::cin >> n;
    int a[n];
    for (int i = 0; i < n; ++i)
    {
        std::cin >> a[i];
    }

    print_array(a, n);
    insertion_sort(a, n);

    return 0;
}


Measured memory_bytes: 3108
#include <cstdio>

using namespace std;

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

int main()
{
	repi(i,1,10)
		repi(j,1,10)
			printf("%dx%d=%d\n",i,j,i*j);
	
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <math.h>
using namespace std;

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

  for(int i=-119; i<=120; i++){
    for(int j=-120; j<=119; j++){
      if(pow(i,5)-pow(j,5)==x){
        cout << i << ' ' << j <<endl;
        return 0;
      }
    }
  }
}

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

int main()
{
	string input_str;
	int k;

	cin >> input_str >> k;
	int len = input_str.length();

	string min_str = "zzzzzz";	// 咬ませ犬
	for( char c = 'a'; c <= 'z'; ++c )
	{
		for( int i = 0; i <= len; ++i )		//文字列の最後まで
		{
			if( input_str[i] == c )
			{
				if( len-i < k )			// [c]からの文字列長が[k]に満たない場合
				{
					k -= (len-i);
					break;
				}
				else
				{
					string tmp_str = input_str.substr(i,k);
					if( min_str > tmp_str )
						min_str = tmp_str;
				}
			}
		}

		if( min_str != "zzzzzz") break;
	}

	cout << min_str << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 
  double a,b,ave1,ave2;
  int num;
  
  cin >> a >> b;
  
  ave1 = ave2 = (a + b) / 2;
  
  num = ave1;
  
  if(ave2 - num >= 0.5){
    num++;
  }
  
  cout << num << endl;
}

Measured memory_bytes: 256
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const X = parseInt(arg[0]);
    
    let sum = 0;
    
    for(let i=1; i<=X+1; i++) {
        if(sum >= X) {
            console.log(i - 1);
            return;
        }
        
        sum += i;
    }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
#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 memo[SIZE] = {};

  scanf("%d", &N);

  memo[0] = 3;

  ll ans = 1;

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

    ans = (ll)ans * max(0, memo[A]) % mod;
    memo[A]--;
    memo[A+1]++;
  }

  cout << ans << endl;


  return 0;
}


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

// nに含まれる2の素因数の数を返す
int f(int n)
{
  int res = 0;
  while (n % 2 == 0)
  {
    n /= 2;
    res++;
  }
  return res;
}

// 最大公約数
int gcd(int a, int b)
{
  return b ? gcd(b, a % b) : a;
}

// 最小公倍数
int lcm(int a, int b)
{
  return a / gcd(a, b) * b;
}

int main()
{
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  rep(i, n) cin >> a.at(i);

  // 小数を除去するために式変形し、全てのaについて2で割る
  rep(i, n) a.at(i) /= 2;

  // 2の素因数の数(t)が全てのaで同じことを確認
  int t = f(a.front());
  rep(i, n)
  {
    if (f(a.at(i)) != t)
    {
      cout << 0 << endl;
      return 0;
    }
    a.at(i) = a.at(i) / pow(2, t);
  }

  // aの最小公倍数を求める
  m = m / pow(2, t);
  int l = 1;
  rep(i, n)
  {
    l = lcm(l, a.at(i));
    if (l > m)
    {
      cout << 0 << endl;
      return 0;
    }
  }

  // m以下の最小公倍数×奇数の数を求める
  m /= l;
  int ans = (m + 1) / 2;
  cout << ans << endl;
}


Measured memory_bytes: 640
import java.util.*;

public class Main {
	static class Node {
		Node parent;
		int value;
		Node right, left;

		Node(int value) {
			this.value = value;
			this.parent = null;
			this.right = null;
			this.left = null;
		}

		/**
		 * 値を追加して，rootのnodeを返す
		 * 
		 * @param value
		 * @return
		 */
		Node add(int value) {
			if (this.value >= value) {
				// 自分の親にする
				Node insert = new Node(value);
				Node parent = this.parent;
				if (parent != null) {
					parent.right = insert;
					insert.parent = parent;
				}
				insert.left = this;
				this.parent = insert;
				return parent;
			} else {
				// 右に挿入
				if (this.right == null) {
					this.right = new Node(value);
					this.right.parent = this;
					return this;
				} else {
					// 右の子として挿入
					this.right.add(value);
					return this;
				}
			}
		}

		Node getRoot() {
			if (this.parent == null) {
				return this;
			} else {
				return this.parent.getRoot();
			}
		}

		long getCost(long base) {
			if (this.left == null && this.right == null) {
				return this.value - base;
			} else if (this.left != null && this.right != null) {
				long result = 0;
				result += this.left.getCost(this.value);
				result += this.right.getCost(this.value);
				result += this.value - base;
				return result;
			} else if (this.left != null) {
				// leftのみ
				long result = 0;
				result += this.left.getCost((this.value));
				result += this.value - base;
				return result;
			} else {
				// rightのみ
				long result = 0;
				result += this.right.getCost(this.value);
				result += this.value - base;
				return result;
			}
		}
	}

	int N;
	int[] h;
	List<Deque<Integer>> sections;

	Main() {
		Scanner in = new Scanner(System.in);
		N = Integer.parseInt(in.nextLine());
		String[] tokens = in.nextLine().split(" ");
		h = new int[N];
		for (int i = 0; i < N; ++i) {
			h[i] = Integer.parseInt(tokens[i]);
		}
		in.close();
	}

	Node genTree(int[] h) {
		// 最初のnodeを作る
		Node root = new Node(h[0]);
		for (int i = 1; i < h.length; ++i) {
			root.add(h[i]);
			root = root.getRoot();
		}
		return root;
	}

	public static void main(String[] args) {
		Main ins = new Main();
		Node root = ins.genTree(ins.h);
		System.out.println(root.getCost(0));
	}

}

Measured memory_bytes: 23764
def min(a,b); a < b ? a : b; end

L, R = gets.split.map(&:to_i).map{|v| v.divmod(2019) }
if L[0] < R[0]
  puts 0
else
  puts (L[1] .. R[1]).to_a.combination(2).inject(2019){|s,(i,j)| min(s, (i * j) % 2019) }
end


Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define range(c) c.begin() , c.end()
#define forn(i,n) for(ll i=0; i<n; ++i)
#define endl '\n'
#define MOD 1000000007
#define test ll t;cin >> (t);while(t--)
using namespace std;
//////////////////////////////////////////////////////////////

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    string s,t;
    cin >> s >> t;
    int n=s.size();
    int m=t.size();
    ll dp[n+1][m+1];
    for(ll i=0;i<=n;i++)
    {
        dp[i][0]=0;
    }
    for(ll i=0;i<=m;i++)
    {
        dp[0][i]=0;
    }
    vector<char> v;
    for(ll i=1;i<=n;i++)
    {
        for(ll j=1;j<=m;j++)
        {
            if(s[i-1]==t[j-1])
            {
                dp[i][j]=1+dp[i-1][j-1];
            }
            else
            {
                dp[i][j]=max(dp[i-1][j], dp[i][j-1]);
               
            }
            
        }
    }
   
    ll i=n,j=m;
    while(i>0 && j>0)
    {
        if(s[i-1]== t[j-1])
        {
            v.pb(s[i-1]);
            i--;j--;
        }
        else if(dp[i-1][j] > dp[i][j-1])
            i--;
        else
        {
             j--;
        }
        
    }
    for(ll i=v.size()-1;i>=0;i--)
        cout << v[i] ;
}


Measured memory_bytes: 70656
/*
"Won't stop untill I'm Phenomenal"
- Phenomenal, EMINEM
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define ff first
#define Shazam ios_base::sync_with_stdio(false);   cin.tie(NULL); cout.tie(NULL);
#define ss second
#define all(c) c.begin(),c.end()
#define endl "\n"
#define test() int t; cin>>t; while(t--)
#define fl(i,a,b) for(int i = a ; i <b ;i++)
#define get(a) fl(i,0,a.size())  cin>>a[i];
#define pra(a) fl(i,0,a.size()) cout<<a[i]<<" ";	cout<<endl;
#define pr(a,n) fl(i,0,n) cout<<a[i]<<" ";	cout<<endl;
const ll INF = 2e18;
const int inf = 2e9;
const int mod1 = 1e9 + 7;



int main(){
    Shazam;
    int k; cin>>k;
    deque<ll> lunlun;
    for(ll i = 1; i < 10; i++)
        lunlun.push_back(i);
    ll ans;
    for(int i = 1; i <= k; i++){
        ans = lunlun.front();
        lunlun.pop_front();
        if(ans%10) lunlun.push_back(ans*10LL + (ans%10) - 1);
        lunlun.push_back(ans*10LL + ans%10);
        if(ans%10<9) lunlun.push_back(ans*10LL + (ans%10) + 1);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 4796
n, x, m = map(int, input().split())

dp = [-1 for _i in range(10**5+2)]
nums = [-1 for _i in range(10**5+2)]
nums[x] = 1

dp[x] = x
bef = x
nex = (x**2)%m
r = [0, x]
while dp[nex] < 0:
    nums[nex] = nums[bef]+1
    dp[nex] = dp[bef]+nex
    r.append(dp[nex])
    nex, bef = (nex**2)%m, nex

if nex == 0:
    print(r[min(len(r)-1, n)])
elif n <= nums[bef]:
    print(r[n])
else:
    roop = nums[bef] - nums[nex] + 1
    roop_value = r[nums[bef]] - r[nums[nex] - 1]
    plus = r[nums[nex]-1]*(n>=nums[nex]+1)
    n = max(0, n-nums[nex]+1)
    print(
        roop_value*(n//roop)+plus+
        r[n%roop + nums[nex] -1]
        -r[nums[nex] - 1]
    )

Measured memory_bytes: 14620
//============================================================================
// Name        : m
// Date        : Thu Feb 21 10:19:17 CST 2019
// Author      : landcold7
// Description : Actions speak louder more than words
//============================================================================
#include "bits/stdc++.h"
using namespace std;

#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define mst(x, y) memset(x, y, sizeof(x))
#define pvar(x) cout << #x << ": "
#define fora(e, c) for (auto &e : c)
#define fori(i, a, b) for (int i = a; i < b; ++i)
#define ford(i, a, b) for (int i = a; i > b; --i)
#define output(v) cout << (v) << '\n'
#define prt(x, a, n) { cout << x[a]; if (a < n - 1) cout << " "; }
#define pvi(x, v) if(v) pvar(x); fora(a, x) cout << a << " "; cout << "\n"
#define par(x, s, n, v) if(v) pvar(x); fori(y, s, n) prt(x, y, n) cout << "\n"

#ifndef __has_trace
#define trace(...)
#endif
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

const int mod = (int) 1e9 + 7;

void add(ll &a, ll b) {
    a += b;
    if (a >= mod) {
        a -= mod;
    }
}

void solve() {
    int n, k; cin >> n >> k;
    vi aa(n + 1);
    fori (i, 1, n + 1) {
        cin >> aa[i];
    }

    vector<vl> dp(n + 1, vl(k + 1, 0));
    // dp[i][j]: the number of ways such that there are j candies for i childs.
    dp[0][0] = 1;
    fori (i, 1, n + 1) {
        // Compute prefix sum
        vl sum(k + 2, 0);
        fori (j, 1, k + 2) {
            sum[j] = (sum[j - 1] % mod + dp[i - 1][j - 1] % mod) % mod;
        }
        // trace(sum);
        fori (j, 0, k + 1) {
            // dp[i][j] <- dp[i - 1][j - aa[i] + aa[i]]
            // dp[i][j] <- dp[i - 1][j - aa[i] - 1 + (aa[i] - 1)]

            add(dp[i][j], (sum[j + 1] - sum[max(0, j - aa[i])] + mod) % mod);

            // Navie way of computing
            // fori (h, 0, aa[i] + 1) {
            //     if (j - h >= 0) {
            //         add(dp[i][j], dp[i - 1][j - h]);
            //     }
            // }
        }
    }
    // trace(dp);
    output(dp[n][k]);
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    solve();
    return 0;
}



Measured memory_bytes: 80256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
    int n;
    cin >> n;
    int x[n];
    for(int&i:x){
        cin>>i;
    }
    int ans = INT_MAX;
    for(int i=1;i<=100;i++){
        int c = 0;
        for(int j:x){
            c += pow(abs(j-i),2);
        }
        ans = min(ans,c);
    }
    cout<<ans;
}

Measured memory_bytes: 3576
n, m, q = gets.split.map(&:to_i)
abcd = Array.new(q)
q.times do |i|
  abcd[i] = gets.split.map(&:to_i)
end

result = 0
arlist = []
1.upto(n) do |j|
  (1..m).to_a.combination(j) do |bar|
    if j > 1
      (1..(n-1)).to_a.combination(j-1) do |car|
        ar = []
        i = 0
        k = 0
        bx = 0
        car.each_with_index do |x, index|
          ar += [bar[index]]*(x-bx)
          bx = x
        end
        ar += [bar.last] * (n - ar.size)
        arlist.push ar
      end
    else
      arlist.push [bar[0]]*n
    end
  end
end

arlist.each do |ar|
  point = 0
  abcd.each do |rule|
    if (ar[rule[1]-1] - ar[rule[0]-1]) == rule[2]
      point += rule[3]
    end
  end
  if point > result
    result = point
  end
end

puts result

Measured memory_bytes: 31512
#include <cstdio>

using namespace std;

typedef long long ll;

int main() {
    ll w, h, x, y;
    scanf("%lld%lld%lld%lld", &w, &h, &x, &y);
    printf("%.15lf %d\n", w * h / 2.0, w == x * 2 && h == y * 2);
    return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		try (Scanner sc = new Scanner(System.in)) {
			int n, x;
			n = sc.nextInt();
			x = sc.nextInt();
			
			int count = 1;
			int p = 0;
			
			for (int i = 0; i < n; i++) {
				p += sc.nextInt();
				
				if (p <= x) count++;
			}
			
			System.out.println(count);
			
		} catch (Exception e) {
			// TODO: handle exception
		}
	}
	
}


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

int main(){
  int N;
  cin >> N;
  vector<int> d(N);
  for (int i = 0; i < N; i++){
    cin >> d.at(i);
  }
  int count = 1;
  for (int i = 1; i < N; i++){
    for (int j = 0; j < i; j++){
      if (d.at(i) == d.at(j)) break;
      else if (j == i - 1) count++;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define RI register int
#define g getchar()
using namespace std;
typedef long long ll;
const int mod=1e9+7,N=1e5+10;
void qr(int &x) {
	char c=g;x=0;
	while(!isdigit(c))c=g;
	while(isdigit(c))x=x*10+c-'0',c=g;
}
int n; ll ans;
int a[N],deg[N],vis[N],footL[N],sum[N],f[N];
bool cir[N];
int qm(int x) {return x>=mod?x-mod:x;}
void workcir(int x) {
	int now=0,fr=0,frL=0,ed=0;
	//now是当前环的长度，fr是第一个有脚点的位置,frL是位置对应的脚长,ed为上一个有脚点的位置。 
	while(cir[x]) {
		++now; cir[x]=0;
		if(footL[x]) {
			if(!fr) ed=fr=now,frL=footL[x];
			else {
				ans=ans*((footL[x]<now-ed)+(footL[x]<=now-ed))%mod;//脚的放法 
				ed=now;
			}
		}
		x=a[x];
	}
	if(!ed) ++sum[now];
	else ans=ans*((frL<now-ed+fr)+(frL<=now-ed+fr))%mod;
}
void work() {
	for(RI i=1;i<=n;i++) {//脚对环上交接点贡献 
		if(deg[i]) continue;
		int x=i,len=0; while(!cir[x])x=a[x],++len;
		footL[x]=len;//脚长 
	}
	ans=f[0]=1;
	for(RI i=1;i<=n;i++) if(cir[i]) workcir(i);//以环为基准计算基环内向树的情况 
	for(RI i=1;i<=n;i++) {//计算简单环 
		for(RI j=1;j<=sum[i];j++) {
			if(i>1&&(i&1)) f[j]=qm(f[j-1]<<1);
			else f[j]=f[j-1];
			if(j>1) f[j]=qm(f[j]+(ll)f[j-2]*(j-1)%mod*i%mod);
		}
		ans=ans*f[sum[i]]%mod;
	}
}
int main() {
	qr(n);
	for(RI i=1;i<=n;i++) qr(a[i]),++deg[a[i]];
	for(RI i=1;i<=n;i++) if(!vis[i]) {
		int x=i;while(!vis[x]) vis[x]=i,x=a[x];
		if(vis[x]!=i) continue;//脚 
		while(!cir[x]) cir[x]=1,x=a[x];//标记环上点 
	}
	for(RI i=1;i<=n;i++)
		if((cir[i]&&deg[i]>2)||(!cir[i]&&deg[i]>1)) return puts("0"),0;//开叉就不行 
	work(); printf("%lld\n",ans); return 0;
}

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


int main(void) {
    int n, q;
    cin >> n >> q;
    string str;
    cin >> str;
    str += 'E';
    
    int t[n] = { 0 };
    for (int i = 0; i < str.size() - 1; ++i) {
        t[i + 1] = t[i] + (str[i] == 'A' && str[i + 1] == 'C');
    }

    for (int i = 0; i < q; ++i) {
        int s, e;
        cin >> s >> e;
        
        cout << t[e - 1] - t[s - 1] << endl;
    }

    return 0;
}

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

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

typedef int64_t ll;
typedef long double ld;

const int INF = 1e9;
const ld EPS = 1e-8;
const ll MOD = 1e9 + 7;

struct Edge {
  int src, dst;
  Edge() {}
  Edge(int src, int dst) : src(src), dst(dst) {}
};

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

ll perm(int n, int k) {
  ll ret = 1;
  REP(i, k) ret = ret * (n - i) % MOD;
  return ret;
}

int main(){
  int N, K;
  cin >> N >> K;
  Graph g(N);
  REP(i, N - 1) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    g[a].push_back(Edge(a, b));
    g[b].push_back(Edge(b, a));
  }

  ll ret = K;
  vector<bool> flag(N, false);
  queue<int> que;
  que.push(0);
  while(!que.empty()) {
    int p = que.front(); que.pop();
    if(flag[p]) continue;
    flag[p] = true;

    int deg = 0;
    for(Edge v : g[p]) if(!flag[v.dst]) ++deg;
    if(p == 0) {
      ret = ret * perm(K - 1, deg) % MOD;
    }else{
      ret = ret * perm(K - 2, deg) % MOD;
    }

    for(Edge v : g[p]) {
      if(flag[v.dst]) continue;
      que.push(v.dst);
    }
  }

  cout << ret << endl;
  return 0;
}



Measured memory_bytes: 6900
n = int(input())
a = input()
b = input()
c = input()
cnt=0
for i in range(n):
        if a[i]==b[i] and b[i]==c[i]:
            pass
        elif a[i]==b[i] or a[i]==c[i] or b[i]==c[i]:
            cnt+=1
        else:
            cnt+=2
print(cnt)

Measured memory_bytes: 9016
#pragma warning(disable:4996)
#include <bits/stdc++.h>
using namespace std;

#define ALL(a) begin(a), end(a)
#define TPL template
#define TNM typename

using ll = long long;
using ull = unsigned long long;
TPL<TNM T> using vec = vector<T>;
TPL<TNM T> using vec2 = vec<vec<T>>;
TPL<TNM T> using vec3 = vec<vec2<T>>;

TPL<TNM T> inline bool chmin(T&a, T&b) { if (a > b) { a = b; return true; } return false; }
TPL<TNM T> inline bool chmax(T&a, T&b) { if (a < b) { a = b; return true; } return false; }
TPL<TNM V, TNM H> void resize(vector<V>& _v, const H _h) { _v.resize(_h); }
TPL<TNM V, TNM H, TNM ... T> void resize(vector<V>& _v, const H& _h, const T& ... _t) { _v.resize(_h); for (auto& __v : _v) resize(__v, _t ...); }
TPL<TNM V, TNM T> TNM enable_if<!is_class<V>::value, void>::type fill(vector<V>& _v, const T &_t) { std::fill(ALL(_v), _t); }
TPL<TNM V, TNM T> TNM enable_if<is_class<V>::value, void>::type fill(vector<V>& _v, const T &_t) { for (auto &_e : _v) fill(_e, _t); }
TPL<TNM T> inline void UNIQUE(vector<T>& _v) { sort(ALL(_v)); _v.erase(unique(ALL(_v)), _v.end()); }
struct pre_ { pre_() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(6); } } pre__;

vector<string> split(const string &s, char delim) {
	vector<string> elems;
	stringstream ss(s);
	string item;
	while (getline(ss, item, delim)) {
		if (!item.empty()) {
			elems.push_back(item);
		}
	}
	return elems;
}

set<char> alphabets(string s) {
	set<char> st;
	for (char c : s) {
		if (isalpha(c)) {
			st.insert(c);
		}
	}
	return st;
}

bool solve(string s, set<char> st) {
	map<string, int> cnt;
	bool n = false;
	char v;
	for (char c : s) {
		if (c == '~') {
			n = true;
		}
		else if (c == '&' || c == ')') {
			//not?
			if (n) {
				cnt["~" + string{ v }]++;
			}
			else {
				cnt[string{ v }]++;
			}
			n = false;
		}
		else {
			v = c;
		}
	}
	for (char c : st) {
		if (cnt[string{ c }] && cnt["~" + string{ c }]) {
			return false;
		}
	}
	return true;
}

void solve2(vector<string>& vs) {
	for (int i = 0; i < vs.size(); ++i) {
		set<char> st = alphabets(vs[i]);
		if (solve(vs[i], st)) {
			cout << "yes" << endl;
			return;
		}
	}
	cout << "no" << endl;
	return;
}
int main(void) {
	while (1) {
		string S;
		cin >> S;
		if (S == "#")break;
		vector<string> vs = split(S, '|');
		solve2(vs);
	}
	
	return 0;
}


Measured memory_bytes: 3236
#include <iostream>

using ll = long long;
int main(int argc, char ** argv)
{
  //
  ll a, b, k;
  std::cin >> a >> b >> k;

  if ((k - a) > 0) {
    k -= a;
    a = 0;

    if ((k - b) > 0) {
      b = 0;
    } else {
      b -= k;
    }

  } else {
    a -= k;
  }

  std::printf("%lld %lld\n", a, b);
  return 0;
}


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

#ifdef LOCAL
#include "dump.hpp"
#else
#define dump(...)
#define dumpv(...)
#endif

#define rep(i, n) for (int i = 0; i < (n); i++)
#define mins(x, y) (x = min(x, y))
#define maxs(x, y) (x = max(x, y))
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
const int MOD = 1e9 + 7;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;

void solve() {
  int n;
  cin >> n;
  vvi to(n);
  rep(i, n) {
    string s;
    cin >> s;
    rep(j, n) {
      if (s[j] == '1') to[i].push_back(j);
    }
  }
  dump(to);
  vector<int> used(n, -1);
  function<int(int, int)> dfs = [&](int u, int d) {
    if (0 <= used[u]) {
      if ((used[u] % 2) == (d % 2)) return false;
      return true;
    }
    used[u] = d;
    for (auto& v : to[u]) {
      if (dfs(v, d + 1)) return true;
    }
    return false;
  };
  if (dfs(0, 0)) {
    cout << -1 << endl;
    return;
  }
  vvi dist(n, vi(n, INF));
  rep(i, n) dist[i][i] = 0;
  rep(i, n) {
    for (auto& v : to[i]) dist[i][v] = 1;
  }
  rep(k, n) rep(i, n) rep(j, n) { dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]); }
  int mx_len = 0;
  rep(i, n) {
    rep(j, n) {
      if (i != j) maxs(mx_len, dist[i][j]);
    }
  }
  dump(mx_len);
  cout << mx_len + 1 << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  // freopen("temp.1", "r", stdin);
  solve();
  return 0;
}

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


int main(void){
	int n,m;
	int **p;
	int max,max2;

	while(1){
		scanf("%d %d",&n,&m);
		if(n==0 && m==0){break;}
		p=(int**)malloc(m*sizeof(int*));
		for(int i=0;i<m;i++){
			p[i]=(int*)malloc(n*sizeof(int));
			for(int j=0;j<n;j++){
				scanf("%d",&p[i][j]);
			}
		}

		max=0;
		for(int i=0;i<m;i++){
			max+=(p[i][0]);
		}

		for(int i=1;i<n;i++){
			max2=0;
			for(int j=0;j<m;j++){
				max2+=(p[j][i]);
			}
			if(max < max2){
				max=max2;
			}
		}
		printf("%d\n",max);
	}

    return 0;
}


Measured memory_bytes: 2216
#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 (1e9)
#define LLINF (1e18)
#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};

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

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    string t = s;
    reverse(ALL(t));
    if (s == t)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
#include<iomanip>
#include<math.h>
#include<vector>
#include<cctype>
#include<string>
#include<set>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
std::string line;
typedef long long ll;

int main(){

   int n;
   double a[110];
   cin >> n;
   rep(i,n) cin >> a[i];


   double denom = 0;
   rep(i,n) denom += 1/a[i];

   double ans = 1/denom;

   cout <<  setprecision(6)  << ans << endl;


   return 0;
}

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


using namespace std;

int main() {
	int W, H, N;
	cin >> W >> H >> N;

	vector<int>x(W);
	vector<int>y(H);
	vector<int>a(N);
	int ans = 0;
	int xMAX = 0;
	int yMAX = 0;

	for (int i = 0; i < N; i++) {
		cin >> x[i] >> y[i] >> a[i];
	}

	for (int i = 0; i < N; i++) {
		if (a[i] == 1) {
			xMAX = max(xMAX, x[i]);
		}
		else if (a[i] == 2) {
			W = min(W, x[i]);
		}
		else if (a[i] == 3) {
			yMAX = max(yMAX, y[i]);
		}
		else if (a[i] == 4) {
			H = min(H, y[i]);
		}
	}

	if (xMAX > W || yMAX> H) {
		cout << 0 << endl;
	}
	else {
		cout << (W - xMAX)*(H - yMAX) << endl;
	}

	return 0;
}

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

int main() {
    int N=3;
    string S;
    cin >> S;
    //AAB Y
    //BBA Y
    //BBB
    string result;
    for(int i=0;i<N-1;i++){
		if(S[i+1]!=S[i]){
			cout<<"Yes"<<endl;
			return 0;
		}
    }
	result="No";
    cout << result << endl;

    return 0;
}


Measured memory_bytes: 256
from functools import reduce

N = int(input())
A = [int(_) for _ in input().split()]

def gcd_base(a, b):
	while b:
		a, b = b, a % b
	return a

def gcd(*num):
    return reduce(gcd_base, num)

def gcd_list(num):
    return reduce(gcd, num)

print(gcd_list(A))

Measured memory_bytes: 14748
//==========================================
// ABC139d
//
// 2019/09/01
//==========================================

#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <map>
#include <algorithm>
#include <functional>

using namespace std;

int main(int argc, char* argv[])
{
  unsigned long long n;
  cin >> n;
  unsigned long long cnt=0;
  for(unsigned long long i=1; i<n; ++i)
  {
    cnt += i;
  }
  cout << cnt << endl;

  return 0;
}

Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
MIN = 10**18
for i in range(1, N):
    val = 0
    a, b = i, N-i
    while a or b:
        x = a%10
        y = b%10
        val += (x+y)
        a //=10
        b //= 10
    MIN = min(MIN, val)

print(MIN)

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

int main(){
    string s; cin >> s;
    sort(s.begin(),s.end());

    if(s[0]==s[1] && s[1]!=s[2] && s[2]==s[3])cout << "Yes" << endl;
    else cout << "No" << endl;
    
}

Measured memory_bytes: 256
<?php
    fscanf(STDIN, "%s", $s);
    $result = '';
    if($s === 'Sunny'){
        $result = 'Cloudy';
    }elseif($s === 'Cloudy'){
        $result =  'Rainy';
    }elseif($s === 'Rainy'){
        $result = 'Sunny';
    }
    echo $result;
  ?>

Measured memory_bytes: 3576
word = input()
textArray = []

while True:
    T = input()
    if T == 'END_OF_TEXT':
        break
    T = T.lower().split()
    textArray += T
    
answer = 0
word = word.lower()
for v in textArray:
    if v == word:
        answer += 1
print(f"{answer}")


Measured memory_bytes: 5568