akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <math.h>
using namespace std;

const int MAXN = 1e5 + 10;
int N, M;
int A[MAXN];

int main() {
	register int i, j = 0, k = 0;
	scanf("%d%d", &N, &M);
	for(i = 1; i <= M; ++i)
		scanf("%d", A + i);
	if(M == 1) {
		if(A[1] == 1) return printf("1\n1\n1\n"), 0;
		printf("%d\n", A[1]);
		printf("%d\n", 2);
		printf("%d %d\n", A[1] - 1, 1);
		return 0;
	}
	for(i = 1; i <= M; ++i)
		if(A[i] & 1) {
			if(!j) j = i;
			else if(!k) k = i;
			else return puts("Impossible"), 0;
		}
	if(j) swap(A[j], A[1]);
	if(k) swap(A[k], A[M]);
	if(j && k && A[1] < A[M]) swap(A[1], A[M]);
	for(i = 1; i <= M; ++i)
		printf("%d%c", A[i], " \n"[i == M]);
	++A[1], --A[M];
	if(!A[M]) --M;
	printf("%d\n", M);
	for(i = 1; i <= M; ++i)
		printf("%d%c", A[i], " \n"[i == M]);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const ll MOD = 1000000007;

int ans[102][102];

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

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

    int idx = 0;
    for(int i=0;i<H;i++){
        if(i % 2 == 0){
            for(int j=0;j<W;j++){
                ans[i][j] = idx + 1;
                a[idx]--;
                if(a[idx] == 0) idx++;
            }
        }else{
            for(int j=W-1;j>=0;j--){
                ans[i][j] = idx + 1;
                a[idx]--;
                if(a[idx] == 0) idx++;
            }
        }
    }

    for(int i=0;i<H;i++){
        cout << ans[i][0];
        for(int j=1;j<W;j++){
            cout << " " << ans[i][j];
        }
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<cmath>
#include<algorithm>
#include<iomanip>
#include<string>
using namespace std;
int n, k, a[100009], dp[100009];
int main() {
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	for (int i = 1; i < n; i++) {
		dp[i] = 1e9;
		for (int j = i - 1; j >= (i - k)*(i > k); j--) {
			dp[i] = min(dp[i], dp[j] + abs(a[i] - a[j]));
		}
	}
	cout << dp[n - 1];
	//system("pause");
}

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

int main() {
	char S[20];
	string T;
	string p;
	string Q;
	double m;
	int a = 0;
	int A = 0;
	int b = 0;
	int B = 0;
	int c = 0;
	int C = 0;
	int q, w, z;
	int n = 0;
	int x = 0;
	int y = 0;
	int ans = 0;
	int X[100] = { 0 };
	cin >> n;
	if (n == 1) {
		cout << "Hello World";
	}
	else {
		cin >> a >> b;
		cout << a + b;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#define maxn 1003
#define mod 1000000007
using namespace std;
int pos[maxn], g[maxn], s[maxn], f[maxn][maxn];
void upd(int &x, int y){
	x += y;
	if (x >= mod)
		x -= mod;
}
int main(){
	int n, k;
	cin >> n >> k;
	for (int i = 1; i <= k; ++ i){
		int u, v;
		cin >> u >> v;
		pos[u] = v;
		pos[v] = u;
	}
	n <<= 1;
	for (int i = 1; i <= n; ++ i)
		s[i] = s[i - 1] + (pos[i] == 0);
	g[0] = 1;
	for (int i = 2; i <= n; ++ i)
		g[i] = 1LL * g[i - 2] * (i - 1) % mod;
	int ans = 0;
	for (int i = n; i; -- i)
		for (int j = i; j <= n; ++ j){
			bool flag = false;
			for (int k = i; k <= j; ++ k)
				if (pos[k] && (pos[k] < i || pos[k] > j)){
					flag = true;
					break;
				}
			if (flag)
				continue;
			f[i][j] = g[s[j] - s[i - 1]];
			for (int k = i; k < j; ++ k)
				upd(f[i][j], mod - 1LL * f[i][k] * g[s[j] - s[k]] % mod);
			upd(ans, 1LL * f[i][j] * g[s[i - 1] + (s[n] - s[j])] % mod);
		}
	cout << ans << endl;
}


Measured memory_bytes: 2560
n = gets.to_i
a = gets.split.map(&:to_i)
cnt=[0,0]

2.times do |i|
  f = -1 + 2*i
  sum = 0
  for j in 0..n-1
    sum += a[j]
    if f == 1 && sum <= 0
      cnt[i] += -(sum - 1)
      sum = 1
    elsif f == -1 && sum >= 0
      cnt[i] += sum + 1
      sum = -1
    end
    f *= -1
  end
end
puts cnt.min

Measured memory_bytes: 8588
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""

input:
6
1 2 2 3
2 2 3 4
3 1 5
4 1 6
5 1 6
6 0

output:
1 1 12
2 2 11
3 3 8
4 9 10
5 4 7
6 5 6

"""
import sys

UNVISITED, VISITED_IN_STACK, POPPED_OUT = 0, 1, 2


def dfs(v_init):
    global timer

    # init the first node of overall graph iterations(times >= 1)
    stack = list()
    stack.append(v_init)
    d_time[v_init] += timer
    # init end

    while stack:
        current = stack[-1]
        v_table = adj_table[current]
        visited[current] = VISITED_IN_STACK
        # if adj is None, current's adj(s) have been all visited
        adj = v_table.pop() if v_table else None

        if adj:
            if visited[adj] is UNVISITED:
                visited[adj] = VISITED_IN_STACK
                timer += 1
                d_time[adj] += timer
                stack.append(adj)
        else:
            stack.pop()
            visited[current] = POPPED_OUT
            timer += 1
            f_time[current] += timer

    return None


def dfs_init():
    global timer
    for v in range(v_num):
        if visited[v + 1] == UNVISITED:
            timer += 1
            dfs(v + 1)


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    v_num = int(_input[0])
    vertices = map(lambda x: x.split(), _input[1:])

    # config length = (v_num + 1)
    # stack = []
    visited = [UNVISITED] * (v_num + 1)
    d_time, f_time = ([0] * (v_num + 1) for _ in range(2))
    adj_table = tuple([] for _ in range(v_num + 1))
    for v_info in vertices:
        v_index, adj_num, *adj_list = map(int, v_info)
        # assert len(adj_list) == adj_num
        adj_table[v_index].extend(sorted(adj_list, reverse=True))

    # timing start from 1
    timer = 0
    dfs_init()

    for index, time_info in enumerate(zip(d_time[1:], f_time[1:]), 1):
        print(index, *time_info)

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

int main(){
  int a,b;
  string s;
  cin>>a>>b>>s;
  if(s[a]!='-'){
  	cout << "No" << endl;
  	return 0;
  }
  s.erase(s.begin()+a);
  for(int i=0;i<s.size();++i){
  	if(s[i]-'0'<0||s[i]-'0'>9){
  		cout << "No" << endl;
		return 0;
  	}
  }
  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 256
def main():
    from builtins import int, map, list, print
    import sys
    sys.setrecursionlimit(10 ** 6)

    input = sys.stdin.readline
    input_list = (lambda: input().rstrip().split())
    input_number = (lambda: int(input()))
    input_number_list = (lambda: list(map(int, input_list())))

    N = input_number()
    cnt = [0]

    def check(s=""):
        if int(s) > N:
            return 0
        rt = 1 if all(s.count(c) > 0 for c in '753') else 0
        for c in '753':
            rt += check(s + c)
        return rt

    print(check("0"))


if __name__ == '__main__':
    main()


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

int main() {
    int64_t N, K;
    cin >> N >> K;
    vector<int64_t> P(N), C(N);
    for (int64_t i = 0; i < N; i++) {
        cin >> P[i];
        P[i]--;
    }
    for (int64_t i = 0; i < N; i++) {
        cin >> C[i];
    }

    //iからN回遷移したときのスコア
    vector<int64_t> loop_score(N, 0);
    vector<int64_t> loop_num(N, 0);
    for (int64_t i = 0; i < N; i++) {
        int64_t pos = i;
        for (int64_t j = 0; j < N; j++) {
            pos = P[pos];
            loop_score[i] += C[pos];
            if (pos == i) {
                loop_num[i] = j + 1;
                break;
            }
        }
    }

    int64_t ans = LLONG_MIN;
    for (int64_t i = 0; i < N; i++) {
        //ループをふんだんに使う
        //といっても限界一個前まで
        if (K >= 2 * N) {
            int64_t curr_loop_num = K / loop_num[i] - 1;
            int64_t score = curr_loop_num * loop_score[i];
            int64_t rem = K - curr_loop_num * loop_num[i];
            ans = max(ans, score);
            int64_t pos = i;
            for (int64_t j = 0; j < rem; j++) {
                pos = P[pos];
                score += C[pos];
                ans = max(ans, score);
            }
        }

        //2 * Nまで普通に回す
        {
            int64_t score = 0;
            int64_t pos = i;
            for (int64_t j = 0; j < min(2 * N, K); j++) {
                pos = P[pos];
                score += C[pos];
                ans = max(ans, score);
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3796
#include <array>
#include <iostream>

using namespace std;

template <size_t N>
struct Ans
{
    bool is_prime[N];
    int count[N + 1];
    constexpr Ans() : is_prime(), count()
    {
        for (size_t i = 0; i < N; i++)
        {
            is_prime[i] = true;
        }
        is_prime[0] = false;
        is_prime[1] = false;
        for (size_t i = 2; i * i < N; i++)
        {
            if (is_prime[i])
            {
                size_t cur = i * 2;
                while (cur < N)
                {
                    is_prime[cur] = false;
                    cur += i;
                }
            }
        }

        count[0] = 0;
        for (size_t i = 0; i < N; i++)
        {
            count[i + 1] = count[i];
            if (i % 2 == 1 && is_prime[i] && is_prime[(i + 1) / 2])
            {
                count[i + 1] += 1;
            }
        }
    }
};

int main()
{
    constexpr auto is_prime = Ans<100010>();
    int q;
    cin >> q;
    for (size_t i = 0; i < q; i++)
    {
        int a, b;
        cin >> a >> b;
        cout << (is_prime.count[b + 1] - is_prime.count[a]) << endl;
    }
}

Measured memory_bytes: 1152
#include <iostream>
using namespace std;
int main()
{
    int A,B;
    cin>>A>>B;
    if (A==1) A=14;
    if (B==1) B=14;
    if (A>B)
      cout<<"Alice";
    if (A<B)
      cout<<"Bob";
    if (A==B)
      cout<<"Draw";
    system("pause");
    return 0; 
}

Measured memory_bytes: 504
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] array = new int[10];
		for (int i = 0; i < 10; i++) {
			array[i] = Integer.parseInt(sc.nextLine());
		}

		int n = array.length;
		for (int i = 0; i < n; i++) {
			for (int j = 1; j < n; j++) {
				if (array[j - 1] < array[j]) {
					int box = array[j - 1];
					array[j - 1] = array[j];
					array[j] = box;
				}
			}
		}

		for (int i = 0; i < 3; i++) {
			System.out.println(array[i]);
		}
	}
}

Measured memory_bytes: 26024
import sys

def main():
  input = sys.stdin.readline
  n = int(input())
  l = [int(a) for a in input().split()]
  m = max(l)
  s = sum(l) - m
  if s > m:
    print('Yes')
  else:
    print('No')


if __name__ == '__main__':
  main()


Measured memory_bytes: 2940
#include <iostream>


#include <string>


#include <algorithm>


#include <utility>


#include <iomanip>


#include <functional>


#include <queue>


#include <stack>


#include <map>


#include <vector>


#include <cmath>


#include <cctype>


#include <cstdio>


#define ll long long


#define INF 1e+9


#define MOD 1000000007


using namespace std;



int main(){


    string S;


    cin >> S;


    int N = S.length();


    


    int ans = 0;


    int temp=0;


    for(int i=0; i<N; i++){


        if(S[i]=='0'){


            if(temp>0){


                ans+=2;


            }


            temp--;


        }else if(S[i]=='1'){


            if(temp<0){


                ans+=2;


            }


            temp++;


        }


    }


    cout<<ans<<endl;


    return 0;


}

Measured memory_bytes: 512
//

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

ll A[200000];
ll order[200000];

int main() {
	ll N, K;
	cin >> N >> K;

	for (ll i=0; i<N; i++) {
		cin >> A[i];
		A[i]--;
		order[i] = -1;
	}

	ll town = 0;
	order[0] = 0;
	ll loop_start = 0;
	ll loop_length = INF;
	for (ll i=0; i<K; i++) {
		town = A[town];
		//cout << "town=" << town << endl; // **** debug ****

		if (order[town] != -1) {
			loop_start = i + 1;
			loop_length = i - order[town] + 1;
			break;
		}

		order[town] = i+1;
	}

	//cout << "loop_start=" << loop_start << endl; // **** debug ****
	//cout << "loop_length=" << loop_length << endl; // **** debug ****

	ll dist = (K - loop_start) % loop_length + loop_start;

	town = 0;
	for (ll i=0; i<dist; i++) {
		town = A[town];
	}

	ll ans = town + 1;

	cout << ans << endl;

	return 0;
}

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

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> X(N);
  for (int i = 0; i < N; i++) {
    int A;
    cin >> A;
    X.at(A - 1) += 1;
  }
  
  sort(X.begin(), X.end());
  reverse(X.begin(), X.end());
  
  int ans = N;
  for (int i = 0; i < K; i++) {
    ans -= X.at(i);
  }
  
  cout << ans << endl;
}


Measured memory_bytes: 1024
# coding: utf-8
def main():
    s = set(input())
    l = len(s)
    if l % 2 != 0:
        print('No')
    else:
        if 'N' in s and 'S' in s:
            print('Yes')
        elif 'W' in s and 'E' in s:
            print('Yes')
        else:
            print('No')


if __name__ == '__main__':
    main()

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

int main(){
	vector<int>value(3);
	for (int i = 0; i < 3; ++i)
	{
		cin >> value.at(i);
	}
	sort(value.begin(),value.end());
	int sum = value.at(0) + value.at(1);
	cout << sum << endl;
}

Measured memory_bytes: 256
import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations,accumulate,combinations,product
from fractions import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7

s=input()
ans=0
lst=["A","C","G","T"]
for i in range(len(s)):
    tmp=0
    for j in range(i,len(s)):
        if not s[j] in lst:
            break
        else:
            tmp+=1
    ans=max(ans,tmp)
print(ans)

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

template<class E, class T> struct Rerooting {
    using F = function<T(T, T)>;
    using H = function<T(T, E)>;
private : 
    struct Edge {
        int to;
        E dat;
        T dp, sum;
        Edge (int to, const E &dat, const T &dp, const T &sum) : 
            to(to), dat(dat), dp(dp), sum(sum) { }
    };
    vector<vector<Edge>> g;
    vector<T> subdp, dp;
    const T id;
    const F f;
    const H h;
    int edges;

public : 
    Rerooting (int n, const F &f, const H &h, const T &id) : 
        g(n), f(f), h(h), id(id), subdp(n, id), dp(n, id) { edges = 0; }

    void add_edge (int v, int u, const E &val) {
        assert(++edges < (int)g.size());
        g[v].emplace_back(u, val, id, id);
        g[u].emplace_back(v, val, id, id);
    }

    void add_edge2 (int v, int u, const E &val1, const E &val2) {
        assert(++edges < (int)g.size());
        g[v].emplace_back(u, val1, id, id);
        g[u].emplace_back(v, val2, id, id);
    }

    void dfs1 (int v, int p) {
        for (const auto &e : g[v]) {
            if (e.to == p) continue;
            dfs1(e.to, v);
            subdp[v] = f(subdp[v], h(subdp[e.to], e.dat));
        }
    }

    void dfs2 (int v, int p, const T &top) {
        T buff = id;
        for (int i = 0; i < (int)g[v].size(); i++) {
            Edge &e = g[v][i];
            e.sum = buff;
            e.dp = h(e.to == p ? top : subdp[e.to], e.dat);
            buff = f(buff, e.dp);
        }
        dp[v] = buff;
        buff = id;
        for (int i = (int)g[v].size() - 1; i >= 0; i--) {
            Edge &e = g[v][i];
            if (e.to != p) dfs2(e.to, v, f(buff, e.sum));
            e.sum = f(e.sum, buff);
            buff = f(buff, e.dp);
        }
    }

    vector<T> build(int s = 0) {
        dfs1(s, -1);
        dfs2(s, -1, id);
        return dp;
    }

};

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

    auto f = [](int a, int b) { return max(a, b); };
    auto h = [](int a, int b) { return (a + b); };
    Rerooting<int, int> g(n, f, h, 0);
    for (int i = 0; i < n - 1; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        g.add_edge(a, b, c);
    }

    for (int ans : g.build()) {
        cout << ans << '\n';
    }

    return 0;
}


Measured memory_bytes: 4740
import java.io.IOException;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String args[]) throws IOException {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int A[] = new int[n];
		for (int i = 0; i < n; i++) {
			A[i] = scanner.nextInt();
		}

		System.out.println(Arrays.toString(A).replaceAll("[,\\[\\]]", ""));
		for (int j = 1; j < A.length; j++) {
			int key = A[j];
			int i = j - 1;
			while (i >= 0 && A[i] > key) {
				A[i + 1] = A[i];
				i--;
			}
			A[i + 1] = key;
			System.out.println(Arrays.toString(A).replaceAll("[,\\[\\]]", ""));
		}
	}
}

Measured memory_bytes: 24484
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <complex>

#define pb push_back
#define mp make_pair
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define tr(c, i) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define rtr(c, i) for (typeof((c).rbegin()) i = (c).rbegin(); i != (c).rend(); --i)
#define contains(c, x) ((c).find(x) != (c).end())
#define Contains(c, x) (find(all(c), x) != (c).end())
#define REP(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) REP(i, 0, (n))
#define To_String to_string< char,std::char_traits<char>,std::allocator<char> >

typedef long long ll;
typedef unsigned long long ull;
using namespace std;

int a[100][100];
int n, m;
int dx[] = { -1, 0, 1, 0 };
int dy[] = { 0, -1, 0, 1 };
int dfs(int i, int j)
{
	int res = 0;
	a[i][j] = 0;
	rep(k, 4) {
		int y = i + dy[k];
		int x = j + dx[k];
		if (x<0 || x>=m || y<0 || y>=n || !a[y][x]) continue;
		res = max(res, dfs(y, x));
	}
	a[i][j] = 1;
	return res + 1;
}

int main()
{
	ios_base::sync_with_stdio(0);
	while (cin >> m >> n, (m|n)) {
		rep(i, n) rep(j, m) cin >> a[i][j];
		int res = 0;
		rep(i, n) rep(j, m) if (a[i][j]) res = max(res, dfs(i, j));
		cout << res << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

using R = long double;
constexpr R pi = acos((R)-1), eps = 1e-10;

int sgn(R a) { return (a > eps) - (a < -eps); }
int sgn(R a, R b) { return sgn(a - b); }
using P = complex<R>;
istream& operator>>(istream& i, P& p) { R x, y; i >> x >> y; p = P(x, y); return i; }
ostream& operator<<(ostream& o, P p) { return o << fixed << setprecision(15) << real(p) << ' ' << imag(p); }
bool cmp(P p, P q) { return 2 * sgn(real(p), real(q)) + sgn(imag(p), imag(q)) < 0; }
bool eql(P p, P q) { return !cmp(p, q) and !cmp(q, p); }
R dot(P p, P q) { return real(conj(p) * q); }
R crs(P p, P q) { return imag(conj(p) * q); }
int ccw(P p, P q) {
  int s = sgn(crs(p, q));
  if (s) return s;
  if (dot(p, q) < 0) return -2;
  if (dot(p, q - p) > 0) return 2;
  return 0;
}
int ccw(P o, P p, P q) { return ccw(p - o, q - o); }
struct L {
  P s, t;
  P vec() const { return t - s; }
  R abs() const { return std::abs(vec()); }
  R arg() const { return std::arg(vec()); }
};

// BEGIN CUt HERE
using G = V<P>;
R area(const G& g) {
  if ((int)g.size() < 3) return 0;
  R res = 0;
  P p = g.back();
  for (P q : g) {
    res += crs(p, q) / 2;
    p = q;
  }
  return res;
}
// END CUT HERE

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int n; cin >> n;
  G g(n); for (auto&& e : g) cin >> e;
  cout << fixed << setprecision(1) << area(g) << '\n';
}


Measured memory_bytes: 3308
#include <cstdio>

using namespace std;

int main() {
    int n, x, d = 0, t = 1, l;
    scanf("%d%d", &n, &x);
    for (int i = 0; i < n; ++i) {
        scanf("%d", &l);
        d += l;
        if (d <= x) ++t;
        else break;
    }
    printf("%d\n", t);
    return 0;
}


Measured memory_bytes: 128
#include<iostream>
using namespace std;
int main(){
  string s;
  cin >> s;
  int judge=-1,j;
  for(int i=0;i<s.size();i++){
    if(s[i]=='C'){
      judge++;
      j=i+1;
      break;
    }
  }
  for(j;j<s.size();j++){
    if(s[j]=='F'){
      judge++;
      break;
    }
  }
  if(judge==1)
    cout << "Yes" << endl;
  else 
    cout << "No" << endl;
}

Measured memory_bytes: 256
N = input()
H = map(int, input().split())
last_h = float('inf')
ans, cnt = 0, -1
for h in H:
  if last_h >= h:
    cnt += 1
  else:
    ans = max(ans, cnt)
    cnt = 0
  last_h = h
print(max(ans, cnt))

Measured memory_bytes: 11132
#include "bits/stdc++.h"
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<vi> vvi;

 #define rep(i, a, b) for (int i=a; i<(b); i++)
    
 #define sz(x) (int)(x).size()
 #define mp make_pair
 #define pb push_back
 #define f first
 #define s second
 #define lb lower_bound
 #define ub upper_bound
 #define all(x) x.begin(), x.end()
 

 #define trav(container, it) for(typeof(container.begin()) it=container.begin(); it!=container.end(); it++)
 
 #define PI 3.14159265358979323846264338327950L
const int MOD = 1000000007;
const char nl = '\n';
 
vvi adj;
vi vis;
vi v;

void bfs()
{
    queue<int> q;
    q.push(1);
    vis[1] = 1;
    
    while(q.size()){
        int cur = q.front(); q.pop();
        for(auto i : adj[cur]){
            if(!vis[i])
            {
                v[i] = cur;
                q.push(i);
                vis[i] = 1;
            }
        }
    }
}

int main() 
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n,m;cin>>n>>m;

    adj.resize(n+1);
    vis.resize(n+1);
    v.resize(n+1);

    int x,y;
    rep(i,0,m)
    {
        cin>>x>>y;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }

    bfs();

    cout<<"Yes"<<nl;
    rep(i,2,n+1)
    {
        cout<<v[i]<<nl;
    }
}


Measured memory_bytes: 10700
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define ep emplace_back
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,1,0,-1},dy={-1,0,1,0};
bool inside(int y,int x,int h,int w){ if(y<h && y>=0 && x<w && x>=0) return true; return false; }
template<class T> inline bool chmin(T& a, T b){ if(a > b){ a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b){ if(a < b){ a = b; return true; } return false; }





int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string a,b,c;cin >> a >> b >> c;
	string ans = "";
	ans += (a.at(0) - 'a' + 'A');
	ans += (b.at(0) - 'a' + 'A');
	ans += (c.at(0) - 'a' + 'A');
	cout << ans  << endl;
}


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

using namespace std;
int main(){
	int i,j,n,cnt = 0,x = 0,y = 0,z = 0;
	cin >> n;
	for(i=0;i<n;i++){
		string s;
		cin >> s;
		int k = s.size();
		for(j=0;j<k - 1;j++){
			if(s[j]=='A' && s[j+1]=='B'){
				cnt++;
			}
		}
		if(s[0]=='B'&& s[k-1]=='A') x++;
		else if(s[0]=='B') y++;
		else if(s[k-1]=='A') z++;
	}
	if(x>0){
		if(y>0 || z>0){
			cnt += x;
		}else{
			cnt += x - 1;
			cout << cnt << endl;
			return 0;
		}
	}
	cout << cnt + min(y,z) << endl;
}

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


int main(){
    int n , m ;
    cin >> n >> m;
    vector <bool> vis (n+1,false);
    bool ans = false;
    int a, b;
    for(int i = 1 ; i <= m ; i++){
       cin >> a >> b;
    if(a == 1) {
       if(vis [b]) {
          ans = true;
}
    vis[b] = true;
}   else if (b == n) {
    if(vis[a]) {
    ans=true;
}
    vis[a]=true ;
               }
    }
    if(!ans) cout << "IM";
    cout <<"POSSIBLE"<<endl;
    return 0;
}

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

const ll dx[4] = { 0, 1, 0, -1 };
const ll dy[4] = { -1, 0, 1, 0 };

ll bfs(P start, vector<string>& S, ll H, ll W)
{
    queue<P> que;
    que.push(move(start));

    ll black = 0;
    ll white = 0;
    while (!que.empty()) {
        auto q = que.front();
        que.pop();
        auto x = q.first;
        auto y = q.second;
        if (S[y][x] == '#') {
            black++;
        } else if (S[y][x] == '.') {
            white++;
        } else {
            continue;
        }

        for (ll i = 0; i < 4; i++) {
            auto nx = x + dx[i];
            auto ny = y + dy[i];
            if (nx >= 0 && nx < W && ny >= 0 && ny < H) {
                if (S[ny][nx] != '*' && S[y][x] != S[ny][nx]) {
                    que.emplace(nx, ny);
                }
            }
        }
        S[y][x] = '*';
    }

    return black * white;
}

void solve(long long H, long long W, std::vector<std::string> S)
{
    ll ans = 0;
    for (ll i = 0; i < H; i++) {
        for (ll j = 0; j < W; j++) {
            if (S[i][j] == '#') {
                ans += bfs({ j, i }, S, H, W);
            }
        }
    }
    cout << ans << endl;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
// clang-format off
#pragma GCC diagnostic ignored "-Wunused-result"
int main(){
    long long H;
    scanf("%lld",&H);
    long long W;
    scanf("%lld",&W);
    std::vector<std::string> S(H);
    for(int i = 0 ; i < H ; i++){
        std::cin >> S[i];
    }
    solve(H, W, std::move(S));
    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define MAXN 150
using namespace std;

int a[MAXN*1000],arr[MAXN][MAXN],r=1,c=1,dir=1;

int main(){
	int h,w;
	cin>>h>>w;
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	for(int i=0;i<n;i++){
		while(a[i]){
			arr[r][c]=i+1;
			a[i]--;
			if(dir==1){
				if(c==w){
					r++;
					dir=-1;
				}
				else{
					c++;
				}
			}
			else{
				if(c==1){
					r++;
					dir=1;
				}
				else{
					c--;
				}
			}
		}
	}
	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++){
			cout<<arr[i][j]<<" ";
		}cout<<endl;
	}
}


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


int main()
{
  string s, t;

  cin >> s >> t;
  
  for(int i = 0; i < s.size(); i++) {
    cout << s[i];
    if(i < t.size()) cout << t[i];
  }

  cout << endl;
  
  return 0;
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
#define LLI long long int
#define FOR(v, a, b) for(LLI v = (a); v < (b); ++v)
#define FORE(v, a, b) for(LLI v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(LLI v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define fst first
#define snd second
#define popcount __builtin_popcount
#define UNIQ(v) (v).erase(unique(ALL(v)), (v).end())
#define bit(i) (1LL<<(i))

#ifdef DEBUG
#include <misc/C++/Debug.cpp>
#else
#define dump(...) ((void)0)
#endif

#define gcd __gcd

using namespace std;
template <class T> constexpr T lcm(T m, T n){return m/gcd(m,n)*n;}

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}
template <typename T, typename U> bool chmin(T &a, const U &b){return (a>b ? a=b, true : false);}
template <typename T, typename U> bool chmax(T &a, const U &b){return (a<b ? a=b, true : false);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}

struct Init{
  Init(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);
    cerr << fixed << setprecision(12);
  }
}init;



int main(){
  string s;
  while(cin >> s){
    int ans = 0;

    REP(i,s.size()/2){
      if(s[i] != s[s.size()-i-1]){
        ++ans;
      }

      
    }
    


    cout << ans << endl;
  }


  return 0;
}


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

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

#define ll long long
#define str string
#define pii pair<int, int>
#define pll pair<ll, ll>
#define fi first
#define se second

#define vc vector<char>
#define vvc vector<vc>
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vi>
#define vvll vector<vll>
#define vvvll vector<vvll>
#define vs vector<str>
#define vvs vector<vs>
#define vpii vector<pii>
#define vvpii vector<vpii>
#define vpll vector<pll>
#define vvpll vector<vpll>
#define vb vector<bool>
#define vvb vector<vb>
#define rep(i, a, b) for (int i = (a); i < int(b); i++)
#define repi(i, a, b) for (int i = (a); i <= int(b); i++)


using namespace std;
ll INF = LONG_LONG_MAX;
ll mod = 1000000000 + 7;

template <typename T, typename L>
void read(vector<T> & _data, L & _size, bool _shift) {
    _data.resize(_size + (ll)_shift);
    for (ll i = (ll)_shift; i < _size + (ll)_shift; i++)
        cin >> _data[i];
}

template <typename T, typename L>
void read(vector<vector<T>> & _data, L & _rows, L & _cols, bool _shiftRows, bool _shiftCols) {
    _data.resize(_rows + (ll)_shiftRows);
    for (ll i = 0; i < _rows + (ll)_shiftRows; i++)
        _data[i].resize(_cols + (ll)_shiftCols);
    for (ll i = (ll)_shiftRows; i < _rows + (ll)_shiftRows; i++)
        for (ll j = (ll)_shiftCols; j < _cols + (ll)_shiftCols; j++)
            cin >> _data[i][j];
}

template <typename T>
void write(vector<T> & _data, bool _shift) {
    for (ll i = (ll)_shift; i < _data.size(); i++)
        cout << _data[i] << " ";
    cout << endl;
}


//TODO: SOLUTION


void solve() {
    str s; cin >> s;
    ll ans = 0;
    ll bcsuf = 0;
    for (int i = s.size() - 2; i >= 0; i--) {
        str sub; sub.resize(2);
        sub[0] = s[i]; sub[1] = s[i + 1];
        if (sub == "BC")
            bcsuf++;
        else if (sub == "BA" || sub == "BB" || sub == "CC" || sub == "AC")
            bcsuf = 0;
        else if (sub == "AB" || sub == "AA")
            ans += bcsuf;
    }
    cout << ans << endl;
}


int main() {

    // TODO: Set value of this variable manually
    bool _multipleTestCases = false;

    if (_multipleTestCases) {
        ll t; cin >> t;
        while (t--)
            solve();
    }
    else {
        solve();
    }

    return 0;
}

Measured memory_bytes: 3752
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>

using namespace std;

const int N = 1e5+100;
typedef long long LL;

int n,m;
int h[N],e[N],ne[N],idx;
int din[N];
int q[N];
int dp[N];

void add(int a,int b){
    e[idx] = b, ne[idx] = h[a], h[a] = idx++;
}

void topsort(){
    int hh = 0, tt = -1;
    for(int i = 1; i<=n; i++) {
        if(din[i] == 0) 
            q[++tt] = i;
    }
    
    while(hh<=tt){
        int t = q[hh++];
        
        for(int i = h[t]; ~i; i = ne[i]){
            int j = e[i];
            if(--din[j] == 0) q[++tt] = j;
        }
    }
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    cin>>n>>m;
    
    memset(h,-1,sizeof h);
    for(int i = 1; i<=m; i++){
        int a,b;
        cin>>a>>b;
        add(a,b);
        din[b] ++;
    }
    
    topsort();
    for(int i = 0; i<n; i++){
        int u = q[i];
        for(int k = h[u]; ~k; k = ne[k]){
            int j = e[k];
            dp[j] = max(dp[j] , dp[u]+1);
        }
    }
    cout<<dp[q[n-1]];
    return 0;
}

Measured memory_bytes: 5456
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store") // to restrict undesirable precision
#pragma GCC optimize ("-fno-defer-pop")// to pop argument of function as soon as it returns
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define takeline cin.ignore();
#define sc second
#define N 3000005
#define endl "\n"
#define mod 1000000007
//((1.0l)*BIG MULTIPLY MAGIC?)
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//-----------------------------------------------
int main(){

	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	ll i,j,k,l;
	ll c[3][3],s=0;
	for(i=0;i<3;i++){
		for(j=0;j<3;j++){
			cin>>c[i][j];
			s+=c[i][j];
		}
	}
	ll res=0;
	if (c[0][1] - c[0][0] == c[1][1] - c[1][0])res++;
	if (c[0][1] - c[0][0] == c[2][1] - c[2][0])res++;
	if (c[0][2] - c[0][1] == c[1][2] - c[1][1])res++;
	if (c[0][2] - c[0][1] == c[2][2] - c[2][1])res++;
	if (c[1][0] - c[0][0] == c[1][1] - c[0][1])res++;
	if (c[1][0] - c[0][0] == c[1][2] - c[0][2])res++;
	if (c[2][0] - c[1][0] == c[2][1] - c[1][1])res++;
	if (c[2][0] - c[1][0] == c[2][2] - c[1][2])res++;
	if(res==8){
		cout<<"Yes";
	}
	else{
		cout<<"No";
	}
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static Input;

public class Prog
{
    private const int INF = 1000000007;
    public struct Pair { public int x, y; public Pair(int x, int y) { this.x = x; this.y = y; } }
    public static void Solve()
    {
        string L = NextString();
        string S = new string(L.Reverse().ToArray());
        int N = L.Length;
        long ans = 1;
        long a = 1;
        //1が立つまで経たなかった場合の下位bitは全て01 10 00 の3通りに出来る
        //逆に立てた場合は10 01 なので既存から2通り増える
        for (int i = 0; i < N; i++)
        {
            if (S[i] == '1')
                ans = (ans * 2 + a) % INF;
            a = (a * 3) % INF;
        }
        Console.WriteLine(ans % INF);
    }
    public static void Main()
    {
        var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(sw);
        Solve();
        Console.Out.Flush();
    }
}

public class Input
{
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static char NextChar() { Confirm(); return char.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}


Measured memory_bytes: 15456
n,m = map(int,input().split())
xyz = [list(map(int,input().split())) for i in range(n)];ans = 0
for i in range(1 << 3):
    ls = [];sumls = []
    for j in range(3):
        if (i >> j) & 1 == 1:ls.append('+')
        else:ls.append('-')
    for j in range(n):
        sumls.append(xyz[j][0]*int(ls[0]+'1') + xyz[j][1]*int(ls[1]+'1') + xyz[j][2]*int(ls[2]+'1'))
    sumls.sort(reverse = True)
    ans = max(ans,sum(sumls[:m]))
print(ans)

Measured memory_bytes: 3444
#define _USE_MATH_DEFINES // for C++  
#include "bits/stdc++.h"
#define NUM ((long long)1000000007)
#define int long long

using namespace std;

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

    string s;
    int k;
    cin >> s >> k;
    vector<string> substrs;
    for (size_t i = 0; i < k; i++)
    {
        for (size_t j = 0; j < s.size() - i; j++)
        {
            string substr = s.substr(j, i + 1);
            substrs.emplace_back(substr);
        }
    }
    sort(substrs.begin(), substrs.end());
    unique(substrs.begin(), substrs.end());

    cout << substrs[k - 1] << endl;
}

Measured memory_bytes: 1660
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i,n) for(int (i)=0;(i)<(n);++(i))
#define all(x) (x).begin(),(x).end()
using namespace std;

int main() {
    int k, n; cin >> k >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];

    vector<int> dis(n, 0);

    dis[0] = k + a[0] - a[n - 1];
    for (int i = 0; i < n-1; ++i) {
        dis[i + 1] = a[i + 1] - a[i];
    }
    sort(all(dis), greater<int>());
    cout << (k - dis[0]) << endl;
}


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

#define N 100

int main() {
	static char s[N + 1];
	int n, i, yes;

	scanf("%s", s);
	n = strlen(s);
	yes = 1;
	for (i = 0; i < n; i += 2)
		if (s[i] == 'L' || (i < n - 1 && s[i + 1] == 'R')) {
			yes = 0;
			break;
		}
	printf(yes ? "Yes\n" : "No\n");
	return 0;
}


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

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

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
#define dump(x) cout << #x << " = " << (x) << endl

int main() {
	int N;
	cin >> N;
	bool even = true;
	rep(i, N) {
		int x;
		cin >> x;
		if (x % 2 == 1) {
			even = false;
		}
	}
	if (even) {
		puts("second");
	} else {
		puts("first");
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll inf=1LL<<60;
long double pi=3.14159265358979323846L;
double eps=1e-12;
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
#define srep(itr,st) for(auto itr=st.begin();itr!=st.end();itr++)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
ll beki(ll n,ll k,ll md){
  ll ret=1;
  ll now=n;
  while(k>0){
    if(k%2==1){
      ret*=now;
      ret%=md;
    }
    now*=now;
    now%=md;
    k/=2;
  }
  return ret;
}
ll gyaku(ll n,ll md){
  return beki(n,md-2,md);
}

int main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n;cin>>n;
    ll a[n];
    ll sum[n];
    cin>>a[0];
    sum[0]=a[0];
    rep(i,1,n){
        cin>>a[i];
        sum[i]=sum[i-1]+a[i];
    }
    ll ans=inf;
    rep(i,0,n-1){
        ll x=sum[i];
        ll y=sum[n-1]-x;
        ans=min(ans,abs(x-y));
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 3328
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <map>
#include <set>
#include <vector>
#include <list>
#include <queue>
#include <sstream>
#include <cmath>
#include <functional>
#include <climits>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define reps(s,i,n) for(int i=s;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define skip(i,n,p) for(int i=0;i<n;i+=p)
#define all(a)  (a).begin(),(a).end()
#define int64 long long
#define debug cerr << __FILE__ << ":" << __LINE__ << endl;
#define INF 2147483647

struct Init {
    Init() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout.precision(20);
        cout << fixed;
        // setw(6) << setfill('0')
    }
} init;

template <typename _Ty>
ostream& operator << (ostream& ostr, const vector<_Ty>& v) {
    for(int i = 0; i < (int) v.size(); i++) {
        ostr << v[i] << (i + 1 != v.size() ? " " : "");
    }
    return ostr;
}

template <typename _K, typename _V>
ostream& operator << (ostream& ostr, const map<_K, _V>& v) {
    ostr << "{";
    for (auto iter = v.begin(); iter != v.end(); ++iter) {
        ostr << (*iter).first << ": " << (*iter).second << ", ";
    }
    ostr << "}";
    return ostr;
}

template <typename _K>
ostream& operator << (ostream& ostr, const set<_K>& v) {
    for (auto iter = v.begin(); iter != v.end(); ++iter) {
        ostr << *iter << (iter != v.end() ? " " : "");
    }
    return ostr;
}

template <typename _K, typename _V>
ostream& operator << (ostream& ostr, const pair<_K, _V>& v) {
    ostr << "(" << v.first << ", " << v.second << ")";
    return ostr;
}

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

int64 powmod(int64 n, int64 count, int64 mod) {
    if (count == 0) return 1;
    if (count % 2 == 0) {
        int64 t = powmod(n, count / 2, mod);
        return t * t % mod;
    }
    return n * powmod(n, count - 1, mod) % mod;
}

int64 ncr(int64 n, int64 r, int64 mod) {
    int64 a;
    if (n < r) a = min(n, r - n);
    else a = min(n - r, r);

    int64 res = 1;
    rep(i, a) {
        res = res * (n - i) % mod;
        res = res * powmod(i + 1, mod - 2, mod) % mod;
    }

    return res;
}

int main() {
    int h, m, h2, m2, k; cin >> h >> m >> h2 >> m2 >> k;

    cout << (h2 - h) * 60 + (m2 - m) - k << endl;
}


Measured memory_bytes: 3652
#include <iostream>
#include <cmath>
#include <iomanip>

using namespace std;

int main(){
  double pi=3.1415926535897932846;
  double a,b,h,m;
  cin>>a>>b>>h>>m;
  h += m / 60;
  double xa,ya, xb,yb;
  xa = a*cos(h*pi/6);
  ya = a*sin(h*pi/6);
  xb = b*cos(m*pi/30);
  yb = b*sin(m*pi/30);
  double dx, dy;
  dx = xa - xb;
  dy = ya - yb;
//  cerr<<"a("<<xa<<","<<ya<<"), b("<<xb<<","<<yb<<")"<<endl;
//  cerr<<"dx,dy = "<<dx<<","<<dy<<endl;
  cout<<std::fixed<<std::setprecision(20)<<sqrt(dx*dx + dy*dy)<<endl;
  return 0;
}

Measured memory_bytes: 4152
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
  
#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define all(v) (v).begin(), (v).end()
#define rev(s) (s).rbegin(), (s).rend()
#define MP make_pair
#define X first
#define Y second
  
using namespace std;
  
typedef long long ll;
typedef pair<int, int> P;

const int INF = 1<<29;

struct edge{
	int to;
	string word;
	edge(int t = 0, string s = ""):to(t), word(s){}
};

int main(){
	int n, a, s, g;
	while(cin >> n >> a >> s >> g, n|a|s|g){
		vector<vector<edge> > G(n);
		rep(i, a){
			int x, y;
			string str;
			cin >> x >> y >> str;
			G[y].push_back(edge(x, str));
		}

		string INF = "NO";
		vector<string> dist(n, INF);
		dist[g] = "";
		for(int k = 0; k < 600; k++){
			for(int i = 0; i < n; i++){
				for(int j = 0; j < G[i].size(); j++){
					if(dist[i] == INF) continue;
					if(dist[G[i][j].to] == INF || dist[G[i][j].to] > G[i][j].word + dist[i]){
						dist[G[i][j].to] = G[i][j].word + dist[i];
						if(k > 500 && G[i][j].to == s){
							goto NG;
						}
					}
				}
			}
		}
OK:
		cout << dist[s] << endl;
		continue;
NG:
		cout << "NO" << endl;
		continue;
	}

    return 0;
}

Measured memory_bytes: 2680
let dict = Array.init 26 (fun n -> ((Char.chr (97+n)),0));;

let increment c =
  let code = (Char.code c) in
  if code >= 97 && code <= 122 then
    let i = (-) (Char.code c) 97 in
    let ( _, n) = dict.(i) in dict.(i) <- (c, (n+1))
  else ();;

let rec read u =
  try let line = read_line () in
      String.iter (fun ch -> Char.lowercase ch |> increment) line;
      read u
  with
    End_of_file ->
    Array.iter (fun (a,b) -> Printf.printf "%c : %d\n" a b) dict;;

let () = read ();;

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

int main(void)
{
    int **matrix;
    int *vector;
    int col, row, c, r, sum;

    scanf("%d%d", &col, &row);

    vector = (int *)malloc(sizeof(int) * row);
    matrix = (int **)malloc(sizeof(int *) * col);
    for (c=0; c<col; c++) {
        matrix[c] = (int *)malloc(sizeof(int) * row);
    }

    for (c=0; c<col; c++) {
        for (r=0; r<row; r++) {
            scanf("%d", &matrix[c][r]);
        }
    }
    for (r=0; r<row; r++) {
        scanf("%d", &vector[r]);
    }

    for (c=0; c<col; c++) {
        sum = 0;
        for (r=0; r<row; r++) {
            sum += matrix[c][r] * vector[r];
        }
        printf("%d\n", sum);
    }

    return 0;
}


Measured memory_bytes: 2108
/*   _/                _/                 _/_/_/   _/
  _/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
   _/     _/    _/   _/     _/    _/  _/_/_/     _/
  _/     _/    _/   _/     _/    _/  _/    _/   _/
   _/_/   _/_/       _/_/   _/_/      _/_/     _/ */
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
using ll=long long;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=2e9;
const ll INF=1e18;
using P=pair<int,int>;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  map<char,int> m;
  for(int i=0; i<s.size(); i++) {
    m[s[i]]++;
  }
  for(auto p:m) {
    if(p.second%2) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}

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

int main()
{
    int n,x,y,i,j,k, tem1, tem2;
    cin>>n>>x>>y;
    int a[n-1];
    for(i=0;i<n-1;i++)
        a[i]=0;

    for(i=0;i<n;i++)
    {
        for(j=i+1;j<n;j++)
        {
            tem1=j-i;
            tem2=abs(x-i-1)+abs(y-j-1)+1;
            k=min(tem1, tem2);
            a[k-1]++;
        }
    }
    for(i=0;i<n-1;i++)
        cout<<a[i]<<endl;
}


Measured memory_bytes: 256