akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <queue>
#include <cstring>

using namespace std;

typedef struct a
{
	int x; 
	int y;
}coordin;

int h,w,c;
int res = 0;
int maze [8][8];
int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};

void changeColor(int tmp[8][8],int color)
{
	int originColor = tmp[0][0];
	queue <coordin> q;
	coordin cc;
	cc.x = 0; cc.y = 0;

	q.push(cc);
	tmp[0][0] = color;
	
	while (!q.empty())
	{
		cc = q.front();
		q.pop();

		for (int i=0;i<4;++i)
		{
			int tmp_x = cc.x + dx[i];
			int tmp_y = cc.y + dy[i];
			
			if (0<= tmp_x && tmp_x < w && 0<= tmp_y && tmp_y < h)
			{
				if (tmp[tmp_x][tmp_y] == originColor)
				{	
					coordin tmp_cc;
					tmp_cc.x = tmp_x;
					tmp_cc.y = tmp_y;
					if (color != originColor) q.push(tmp_cc);
					tmp[tmp_x][tmp_y] = color;
				}
				
			}
		}
	}
	
	return;
	
}

int cnt(int m[8][8], int x, int y)
{
    int count=1;
    int oc = m[x][y];
    m[x][y] = 0;
    for(int i=0; i<4; i++)
    {
        int tmp_x = x+dx[i];
        int tmp_y = y+dy[i];
        if(0<=tmp_x && tmp_x<w && 0<=tmp_y && tmp_y<h)
        {
            if(m[tmp_x][tmp_y]==oc) count+=cnt(m, tmp_x, tmp_y);
        }
    }
    return count;
}

int dfs(int m[8][8],int depth)
{
	if (depth == 4)
	{
		if(m[0][0]!=c) changeColor(m,c);
		return cnt(m,0,0);
	}
	
	for (int i=1;i<=6;++i)
	{
		int tmp_m[8][8];
		memcpy(tmp_m,m,sizeof(tmp_m));
		
		if (tmp_m[0][0] != i) changeColor(tmp_m,i);
		res = max(res,dfs(tmp_m,depth+1));
	}
	
	return res;
}

int main()
{
	cin>>h>>w>>c;
	
	while (h!=0)
	{
		for (int i=0;i<h;++i)
			for (int j=0;j<w;++j)
				cin>>maze[j][i];
		
		cout<<dfs(maze,0)<<endl;
		res = 0;
		cin>>h>>w>>c;
	}
	
	return 0;
}

Measured memory_bytes: 912
#define _USE_MATH_DEFINES

#include <iostream>
#include <math.h>
#include <iomanip>

using namespace std;

int main() {
	long double A, B, H, M;
	cin >> A >> B >> H >> M;

	long double theta = (6.0 * M) - (30.0 * H + 0.5 * M);
	long double rad = theta * M_PI / 180.0;
	long double dist = A * (A - 2.0 * B * cosl(rad)) + B * B;

	cout << fixed << setprecision(21) << sqrt(dist);
	
	return 0;
}

Measured memory_bytes: 3552
let () = Scanf.scanf "%d %d\n" @@ fun h w ->
  let ass = Array.init h @@ fun _ ->
    Scanf.scanf "%s\n" @@ fun as_ -> as_ in
  let row = Array.make h true in
  let col = Array.make w true in
  for i = 0 to h - 1 do
    for j = 0 to w - 1 do
      if ass.(i).[j] = '#' then begin
        row.(i) <- false;
        col.(j) <- false
      end
    done
  done;
  for i = 0 to h - 1 do
    if not row.(i) then begin
      for j = 0 to w - 1 do
        if not col.(j) then
          print_char ass.(i).[j]
      done;
      print_newline ()
    end
  done


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

using namespace std;
template <typename T> void print(T vec) { for (auto d : vec) cout << d << ' '; cout << '\n'; }
template<typename T> void print2D(T mat) { for (auto vec : mat) print(vec); }

typedef long long int ll;
const int MOD = (int)1e9 + 7;
int n;

void bfs(vector<vector<int>>& Graph, vector<bool>& visited, int node, vector<vector<ll>> &dp) {
    visited[node] = 1;
    dp[node][0] = 1;
    dp[node][1] = 1;
    for (auto d : Graph[node]) {
        if (!visited[d]) {
            bfs(Graph, visited, d, dp);
            dp[node][0] *= (dp[d][0] + dp[d][1]);
            dp[node][0] %= MOD;
            dp[node][1] *= dp[d][0];
            dp[node][1] %= MOD;
        }
    }
    dp[node][0] %= MOD;
    dp[node][1] %= MOD;
}

void solve(vector<vector<int>> &Graph) {
    vector<vector<ll>> dp(100007, vector<ll>(2));
    vector<bool> visited(100007, 0);
    //dp[1][0] = 1;
    //dp[1][1] = 1;
    bfs(Graph, visited, 1, dp);
    cout << (dp[1][0] + dp[1][1]) % MOD << '\n';
    //print2D(Graph);
}



int32_t main() {
    
    cin >> n;
    vector<vector<int>> A(n + 1);
    int a, b;
    for (int i = 1; i < n; i++) {
        cin >> a >> b;
        A[a].push_back(b);
        A[b].push_back(a);
    }
    solve(A);
    return 0;
}

Measured memory_bytes: 18176
//Created Time:2019年10月27日 星期日 20时09分40秒
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#define db double
#define N 602

using namespace std;

int n, m;
db mat[N][N], deg[N], ans[N], tmp[N];
bool mp[N][N];

int main(){
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= m; ++i){
		int u, v; scanf("%d%d", &u, &v);
		mp[u][v] = true; deg[u] += 1.0;
	}
	for(int i = 1; i <= n; ++i){
		for(int j = 1; j <= n; ++j)
			if(mp[i][j])
				mat[i][j] = -1.0 / deg[i];
		mat[i][i] = 1.0; mat[i][n + 1] = 1.0;
	}
	mat[n][n + 1] = 0;
	for(int i = 1; i <= n; ++i){
		int mx = i;
		for(int j = i + 1; j <= n; ++j)
			if(fabs(mat[j][i]) > fabs(mat[mx][i])) mx = i;
		if(i != mx) swap(mat[i], mat[mx]);
		db div = mat[i][i];
		for(int j = i; j <= n + 1; ++j) mat[i][j] /= div;
		for(int j = i + 1; j <= n; ++j){
			div = mat[j][i];
			for(int k = i; k <= n + 1; ++k) mat[j][k] -= mat[i][k] * div;
		}
	}
	for(int i = n; i; --i){
		ans[i] = mat[i][n + 1];
		for(int j = n; j > i; --j) ans[i] -= ans[j] * mat[i][j];
	}

	memcpy(tmp, ans, sizeof tmp);
	db res = ans[1];
	for(int i = 1; i <= n; ++i)
		if(deg[i] > 1.0){
			double mx = 0.0, sum = 0.0;
			for(int j = i + 1; j <= n; ++j)
				if(mp[i][j]) sum += ans[j], mx = max(mx, ans[j]);
			ans[i] = (sum - mx) / (deg[i] - 1) + 1;
			for(int j = i - 1; j; --j){
				ans[j] = 0.0;
				for(int k = j + 1; k <= n; ++k)
					if(mp[j][k]) ans[j] += ans[k];
				ans[j] /= deg[j]; ans[j] += 1.0;
			}
			res = min(res, ans[1]); memcpy(ans, tmp, sizeof ans);
		}
	printf("%.10lf", res);
	return 0;
}


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

namespace {

inline char read() {
    static const int IN_LEN = 1000000;
    static char buf[IN_LEN], *s, *t;
    s == t ? t = (s = buf) + fread(buf, 1, IN_LEN, stdin) : 0;
    return s == t ? -1 : *s++;
}

template <typename T>
inline bool read(T &x) {
    static char c;
    static bool iosig;
    for (c = read(), iosig = false; !isdigit(c); c = read()) {
        if (c == -1) return false;
        c == '-' ? iosig = true : 0;
    }
    for (x = 0; isdigit(c); c = read()) x = x * 10 + (c ^ '0');
    iosig ? x = -x : 0;
    return true;
}

inline void read(char &c) {
    while (c = read(), isspace(c) && c != -1)
        ;
}

inline int read(char *buf) {
    register int s = 0;
    register char c;
    while (c = read(), isspace(c) && c != -1)
        ;
    if (c == -1) {
        *buf = 0;
        return -1;
    }
    do
        buf[s++] = c;
    while (c = read(), !isspace(c) && c != -1);
    buf[s] = 0;
    return s;
}

const int OUT_LEN = 1000000;

char obuf[OUT_LEN], *oh = obuf;

inline void print(char c) {
    oh == obuf + OUT_LEN ? (fwrite(obuf, 1, OUT_LEN, stdout), oh = obuf) : 0;
    *oh++ = c;
}

template <typename T>
inline void print(T x) {
    static int buf[30], cnt;
    if (x == 0) {
        print('0');
    } else {
        x < 0 ? (print('-'), x = -x) : 0;
        for (cnt = 0; x; x /= 10) buf[++cnt] = x % 10 | 48;
        while (cnt) print((char)buf[cnt--]);
    }
}

inline void print(const char *s) {
    for (; *s; s++) print(*s);
}

inline void flush() { fwrite(obuf, 1, oh - obuf, stdout); }

struct InputOutputStream {
    template <typename T>
    inline InputOutputStream &operator>>(T &x) {
        read(x);
        return *this;
    }

    template <typename T>
    inline InputOutputStream &operator<<(const T &x) {
        print(x);
        return *this;
    }

    ~InputOutputStream() { flush(); }
} io;

const int MAXN = 200000 + 9;

int cnt[MAXN];

struct Comparator {
    inline bool operator()(const int a, const int b) const {
        return cnt[a] < cnt[b] || (cnt[a] == cnt[b] && a < b);
    }
};

std::set<int, Comparator> set;

int n, k;

inline void solve() {
    io >> n >> k;
    for (register int i = 1, a; i <= n; i++) io >> a, cnt[a]++;
    for (register int i = 1; i <= n; i++)
        if (cnt[i]) set.insert(i);
    register int ans = 0;
    while (set.size() > k) {
        register int min = *set.begin(), max = *set.rbegin();
        cnt[max] += cnt[min];
        ans += cnt[min];
        set.erase(set.begin());
    }
    io << ans;
}
}  // namespace

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

Measured memory_bytes: 11392
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

int main()
{
    int n , x;
    cin >> n >> x;
    vector<int> v(n);
    int ans = n;

    int min = 1000;
    int sum = 0;
    for (int i = 0; i < n; i++) {
        cin >> v[i];
        sum += v[i];
        if (v[i] < min) {
            min = v[i];
        }
    }

    x = x-sum;
    while(1)
    {
        if (x-min>=0) {
            ans++;
            x = x-min;
        }
        else {
            break;
        }
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
// Template from https://techracho.bpsinc.jp/jhonda/2019_08_05/78537

// input macro for competive-programming from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        input_inner!{$s, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };

    ($iter:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, bytes) => {
        read_value!($iter, String).into_bytes()
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    use std::io::Read;
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();

    println!("{}", solve(&s));
}

macro_rules! test {
    ($($exp_input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                let start = std::time::Instant::now();
                let input = solve($exp_input);
                let end = start.elapsed();
                assert_eq!(input, $output, "{}.{:03}", end.as_secs(), end.subsec_millis());
                assert!(end.as_secs() <= 2, "expected_sec: {}sec, actual_sec: {}sec", 2, end.as_secs());
                assert!(end.as_secs() <= 1, "expected_sec: {}sec, actual_sec: {}sec", 1, end.as_secs());
                assert!(end.subsec_millis() <= 10, "expected_ms: {}ms, actual_ms: {}ms", 10, end.subsec_millis());
                assert!(end.subsec_millis() <= 2, "expected_ms: {}ms, actual_ms: {}ms", 2, end.subsec_millis());
            )*
        }
    };
}

test! {
r#"10 4"# => r#"3"#,

r#"1 10000"# => r#"1"#,

r#"10000 1"# => r#"10000"#,
}

fn solve(src: &str) -> String {
    let mut src_iter = src.split_whitespace();
    input! {
        source = src_iter,
        mut h: isize,
        a: isize
    }

    let mut ans = 0;

    while 0 < h {
        h -= a;
        ans += 1;
    }

    ans.to_string()
}

Measured memory_bytes: 4352
n = int(input())
li = list(map(int, input().split()))
a = 0
br = False
while True:
    for i in li:
        if i % 2 != 0:
            br = True
            break
    if br:
        break
    a += 1
    li = list(map(lambda x: x / 2, li))
print(a)

Measured memory_bytes: 2940
def middle(lst):
    _lst = lst
    _lst.sort()
    return _lst[-2]

def min_times(lst):
    data = lst
    times = 0
    idx_even = []
    idx_odd = []
    for i, v in enumerate(data):
        if v % 2 == 0:
            idx_even.append(i)
        else:
            idx_odd.append(i)
    odd_len = len(idx_odd)
    if odd_len in (0, 3):
        times += (max(data) - middle(data)) / 2
        times += (max(data) - min(data)) / 2
    if odd_len == 2:
        for i in idx_odd:
            data[i] += 1
        return min_times(data) + 1
    if odd_len == 1:
        for i in idx_even:
            data[i] += 1
        return min_times(data) + 1
    return times

use_data = [int(i) for i in raw_input().strip().split()]

print(min_times(use_data))

Measured memory_bytes: 2696
from collections import deque
N = int(input())
X = [list(map(int, input().split())) for _ in range(N - 1)]

graph = [[] for _ in range(N)]
tree = [[] for _ in range(N)]
for n, (i, j) in enumerate(X):
    graph[i - 1].append(j - 1)
    graph[j - 1].append(i - 1)
    
    tree[i - 1].append((n, j - 1))
    
K = max(len(x) for x in graph)
q = deque()
q.append((0, 0))
ans = [0] * (N - 1)

while len(q) > 0:
    # u: node number, c: color
    u, c = q.popleft()
    
    cnt = 1
    for i, (n, v) in enumerate(tree[u]):
        if cnt == c:
            cnt += 1

        ans[n] = cnt
        q.append((v, cnt))
        cnt += 1
        
print(K)
print(*ans, sep="\n")


Measured memory_bytes: 95704
#include <stdio.h>

int n, m, x, y, ans;
bool vis[410][410], dead[410];
int main() {
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= m; i++) {
		scanf("%d%d", &x, &y);
		if (vis[x][y]) dead[x] = dead[y] = 1;
		if (dead[x]) dead[y] = 1;
		if (dead[y]) dead[x] = 1;
		vis[y][x] = vis[x][y] = 1;
		for (int i = 1; i <= n; i++) {
			if (i == x || i == y) continue;
			if (vis[i][x]) vis[i][y] = vis[y][i] = 1;
			if (vis[i][y]) vis[i][x] = vis[x][i] = 1;
		}
	}
	for (int i = 1; i < n; i++)
		for (int j = i + 1; j <= n; j++)
			if (!dead[i] && !dead[j] && !vis[i][j]) ans++;
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 384
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Deque;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		List<Deque<Integer>> list = new ArrayList<>();
		int n = sc.nextInt();
		int q = sc.nextInt();
		for (int i = 0; i < n; i++) {
			list.add(new ArrayDeque<>());
		}
		for (int i = 0; i < q; i++) {
			switch (sc.nextInt()) {
				case 0:
					list.get(sc.nextInt()).addLast(sc.nextInt());
					break;
				case 1:
					int t = sc.nextInt();
					if (!list.get(t).isEmpty()) {
						System.out.println(list.get(t).peekFirst());
					}
					break;
				case 2:
					t = sc.nextInt();
					if (!list.get(t).isEmpty()) {
						list.get(t).removeFirst();
					}
					break;
			}
		}
	}
}


Measured memory_bytes: 170296
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const ll INF=1e18;
const ll MOD=1e9+7;
const double pi=acos(-1);

int n,m;
vector<vector<int>>G;
int dp[100010];
int rec(int v){
  if(dp[v]!=-1)return dp[v];
  int ans=0;
  for(auto nv:G[v]){
    chmax(ans,rec(nv)+1);
  }
  return dp[v]=ans;
}
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  cin >> n >> m;
  G.assign(n,vector<int>());
  rep(i,m){
    int x,y;
    cin >> x >> y;
    x--;
    y--;
    G[x].push_back(y);
  }
  rep(i,n) dp[i]=-1;
  
  int ans=0;
  rep(i,n)chmax(ans,rec(i));
  cout << ans << endl;
    
}

Measured memory_bytes: 7808
/*
*	User: Isanchez_Aguilar
*	Problem: AtCoder ABC134B - Golden Apple
*/
#include <bits/stdc++.h>

using namespace std;
using Long = long long;

const int MAX_N = 3001;

Long vals[MAX_N];
vector< vector<Long> > memo(MAX_N, vector<Long>(MAX_N, LONG_MIN));

Long dp(int i, int j)
{
	if (i == j)
		return vals[i];

	if (memo[i][j] == LONG_MIN)
	{
		memo[i][j] = max(vals[i] - dp(i + 1, j), vals[j] - dp(i, j - 1));
	}

	return memo[i][j];
}

int main(void)
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	int n;
	cin >> n;

	for (int i = 0;i < n; ++i)
		cin >> vals[i];


	cout << dp(0, n - 1);

	return 0;
}

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

int main() {
  int n,n1,n2,n3,n4;
  cin >> n;
  n1 = n % 10;
  n2 = n / 10 % 10;
  n3 = n / 10 / 10 % 10;
  n4 = n / 10 / 10 / 10 % 10;
  if (n2 == n3 && (n1 == n2 || n3 == n4)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

}


Measured memory_bytes: 3624
from math import sqrt, factorial
from itertools import permutations

n = int(input())
towns = []
for i in range(n):
  towns.append(list(map(int,input().split())))

def sd(p1, p2):
  return sqrt((p1[0]-p2[0])**2 + (p1[1]-p2[1])**2)

def path(p):
  distance = 0
  for i in range(len(p)-1):
    distance += sd(p[i],p[i+1])
  return distance

ans = sum(map(path,permutations(towns)))/factorial(n)
print(ans)

Measured memory_bytes: 3064
//4

#include <stdio.h>
#include <string.h>

int main ()
{
	int a, i =0;
	
	scanf ("%d", &a);
	
	char status[3];
	int ac = 0, wa = 0, tle = 0, re = 0;

	while (i<a)
	{
	i++;
	 scanf ("%s", status);
	 getchar ();
		if (!strcmp ("AC", status))
		{
			ac++;
		}
		else if (!strcmp ("WA", status))
		{
			wa++;
		}
		else if (!strcmp ("TLE", status))
		{
			tle++;
		}
		else if (!strcmp ("RE", status))
		{
			re++;
		}
	}
	
	printf ("AC x %d\n",ac);
	printf ("WA x %d\n",wa);
	printf ("TLE x %d\n",tle);
	printf ("RE x %d\n",re);


return 0;
}

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

#define ONLINE_JUDGE
#define pb(a) push_back(a)
#define ALL(a) a.begin(), a.end()
#define FOR(x,to) for(x=0;x<(to);x++)

using ll = long long;

const int E5 = 1e5;

//////////// Solution /////////////////////////////////

void solve() {	
	map<string,int> mp;
	int N,M;
	cin >> N;
	int mx = 0;
	for (int i = 0; i < N; ++i) {
		string s;
		cin >> s;
		mp[s]++;
	}

	cin >> M;
	for (int i = 0; i < M; ++i) {
		string s;
		cin >> s;
		mp[s]--;
	}

	for (auto x : mp) {
		mx = max(mx,x.second);
	}
	cout << mx << '\n';

}	

/////////// End Solution ///////////////////////////////////////

//////// Initialization ////////////////////////////////////

int main() {

	#ifndef ONLINE_JUDGE
	FILE *FIN = freopen("/home/danil/prog/input.txt", "r", stdin);
	clock_t time_start = clock();
	#endif

	ios::sync_with_stdio(false);
	cin.tie(NULL);

	solve();

	#ifndef ONLINE_JUDGE
	fclose(FIN);
	cerr << "\x1b[031m\n-----------------\nTime=" << (ll)((double)(clock()-time_start) / CLOCKS_PER_SEC * 1000) << "ms\n\x1b[0m";
	#endif

	return 0;
}

//////// End Initialization ///////////////////////////////////////

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int n,k;
	cin >> n >> k;
  	long int h[n];
  for (int i = 0; i < n; i++)
    cin >> h[i];
  // logic
  sort(h, h+n);
  long int ans = h[k-1]-h[0];
  for (int i = 1; i < n-k+1; i++ ){
  	long int temp = h[i+k-1] - h[i];
    (temp < ans)? ans = temp : ans = ans;
  }
  // printing the result
  cout << ans <<'\n';
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define debug(x) cerr << #x << ": " << x << '\n';
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = (int)1e9;
const int MOD = (int)1e9 + 7;

int main(void){
	int P, Q, R;
	cin >> P >> Q >> R;

	int res = min(P+Q, min(Q+R, R+P));
	cout << res << '\n';

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int a[4][4];
int x[4],y[4];

int main()
{
    for(int i = 1; i <= 3; i++)
    {
        for(int j = 1; j <= 3;j++)
        {
            cin >> a[i][j];
        }
    }
    int ax = min(min(a[1][1],a[1][2]),a[1][3]);
    int flag = 0;
    for(int i = 0; i <= ax; i++)
    {
        int ok = 0;
        x[1] = i;
        y[1] = a[1][1] - x[1];
        y[2] = a[1][2] - x[2];
        y[3] = a[1][3] - x[3];
        x[2] = a[2][1] - y[1];
        x[3] = a[3][1] - y[1];
        for(int j = 1; j <= 3; j++)
        {
            for(int k = 1; k <= 3; k++)
            {
                if(x[j] + y[k] != a[j][k])
                {
                    ok = 1;
                    break;
                }
            }
        }
        if(ok == 0)
            flag = 1;
    }
    if(flag)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    
    return 0;
}


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

const int MOD = 1000000007;
int n;
long long int power = 1;

int main() {
    cin >> n;
    for (int i = 1; i <= n; i++) {
        power = ((power % MOD) * i) % MOD;
    }

    cout << power << endl;

    return 0;
}

Measured memory_bytes: 3616
#include <stdio.h>
#include <stdbool.h>

int main(){
    bool on = true;
    int x[3000] = {0};
    int y[3000] = {0};
    int temp = 0;
    while(on == true){
        scanf("%d %d",&x[temp],&y[temp]);
        if(x[temp] == 0 && y[temp] == 0){
            break;
        }
        if(x[temp] > y[temp]){
            printf("%d %d\n",y[temp],x[temp]);
        }else{
            printf("%d %d\n",x[temp],y[temp]);
        }
        temp++;
    }
    return 0;
}

Measured memory_bytes: 628
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi =vector<vi>;

int main(){
  string s;
  cin >> s;
  if(s[0]=='7'||s[1]=='7'||s[2]=='7') cout <<  "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define va first
#define vb second
#define lb lower_bound
#define pb push_back
#define all(v) v.begin(),v.end()
#define fio ios_base::sync_with_stdio(0);cin.tie(0);
#define showcon(v) {for(auto u : (v)) cerr << u << ' '; cout << '\n';}
using namespace std;
using ll = long long;
using lf = long double;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

const int mx = 1e5 + 5;

int vis1[mx], vis2[mx];
int dp1[mx], dp2[mx];
int sz[mx];
int n;
int mod;
int ans[mx];
vector<int> G[mx];
vector<int> pm[mx], rm[mx];

inline void mlt(int& a, int b){
    a = ll(a) * b % mod;
}

inline int vmlt(int a, int b){
    return ll(a) * b % mod;
}

void dfs1(int x){
    vis1[x] = 1;
    dp1[x] = 1;
    int deg = G[x].size();
    pm[x].resize(deg + 2, 1);
    rm[x].resize(deg + 2, 1);
    for(int i = 1; i <= deg; i++){
        int u = G[x][i-1];
        if(vis1[u]) continue;
        dfs1(u);
        pm[x][i] = rm[x][i] = (1 + dp1[u]) % mod;
        mlt(dp1[x], 1 + dp1[u]);
    }
}

void dfs2(int x){
    vis2[x] = 1;
    int deg = G[x].size();
    for(int i = 1; i <= deg; i++){
        int u = G[x][i-1];
        if(vis2[u]){
            pm[x][i] = rm[x][i] = (1 + dp2[u]) % mod;
        }
    }
    for(int i = 1; i <= deg; i++){
        mlt(pm[x][i], pm[x][i-1]);
        mlt(rm[x][deg+1-i],rm[x][deg+2-i]);
    }
    ans[x] = pm[x][deg];
    for(int i = 1; i <= deg; i++){
        int u = G[x][i-1];
        if(vis2[u]) continue;
        dp2[x] = vmlt(pm[x][i-1], rm[x][i+1]);
        dfs2(u);
    }
}

int main(){
    fio;
    cin >> n >> mod;
    for(int i = 1, a, b; i < n; i++){
        cin >> a >> b;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    dfs1(1);
    dfs2(1);
    for(int i = 1; i <= n; i++){
        cout << ans[i] << '\n';
    }
}

Measured memory_bytes: 26624
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;


int main(){
  ll a,b; cin >> a >> b; cout << a*b/2 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORALL(i, m) for( auto i = m.begin(); i != m.end() ; ++i )
#define INF 2e9
#define ALL(v) v.begin(), v.end()
#define TM_T template <class T>
using namespace std;
typedef long long ll;
TM_T T inp(){T it;cin >> it;return it;}

ll N;
vector<ll> li;
vector<ll> sm;
vector<vector<ll>> dp;

int input(){
  cin >> N;
  REP(i,N) li.push_back( inp<ll>() );
}

ll rep(ll l, ll r){
  if ( dp[l][r]>-1 ){
    return dp[l][r];
  }
  if (l==r){
    dp[l][l] = 0;
    return dp[l][r];
  }
  
  ll mi = 1e15l;
  FOR(i,l,r){
    mi = min(mi, rep(l,i) + rep(i+1,r));
  }
  mi += sm[r+1] - sm[l];
  dp[l][r] = mi;
  //cout << l << "," << r << "," << dp[l][r] << endl;
  return dp[l][r];  
}

int main()
{
  input();
  
  sm.push_back(0l);
  REP(i,N) sm.push_back( sm[i]+li[i] );
  //REP(i,N+1) cout << sm[i] << endl;
  REP(i,N) {
    dp.push_back( vector<ll>() );
    REP(j,N) dp[i].push_back(-1);
  }
  
  cout << rep(0,N-1) << endl;
  
}

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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int N;
ll A[int(2e5+5)], DP[19][19], ans;

int Solve(int I, int J){
  for (int i = 0; i < 19; i++){
    for (int j = 0; j < 19; j++){
      if (I + i >= 18 && J + j >= 18){
        if (i == I && j == J) ans += DP[i][j] * (DP[i][j] - 1);
        else ans += DP[i][j] * DP[I][J];
      }
    }
  }
  return 0;
}

int Input(int num){
  string S; cin >> S;

  ll ans = 0, cnt = 0;
  bool flag = false;

  for (int i = 0; i < S.length(); i++){
    if (S[i] == '.') flag = true;
    else{
      ans *= 10; ans += S[i] - '0';
      if (flag) cnt++;
    }
  }

  for (int i = cnt; i < 9; i++) ans *= 10;
  A[num] = ans;

  return 0;
}

int main(){
  cin >> N;
  for (int i = 0; i < N; i++) Input(i);

  for (int i = 0; i < N; i++){
    int cnt2 = 0;
    while (A[i] % 2 == 0){
      cnt2++; A[i] /= 2;
    }
    cnt2 = min(cnt2, 18);
    int cnt5 = 0;
    while (A[i] % 5 == 0){
      cnt5++; A[i] /= 5;
    }
    cnt5 = min(cnt5, 18);
    DP[cnt2][cnt5]++;
  }

  for (int i = 0; i <= 18; i++){
    for (int j = 0; j <= 18; j++){
      Solve(i, j);
    }
  }
  cout << ans / 2 << endl;

  return 0;
}


Measured memory_bytes: 5116
#include <bits/stdc++.h>
typedef long long ll;

using namespace std;


const int VMAX = 10;
const int INF = 10000;

int dist[VMAX][VMAX];


void wf_run(int V) {
  for (int k = 0; k < V; ++k) {
    for (int i = 0; i < V; ++i) {
      if (dist[i][k] == INF) {
        continue;
      }
      for (int j = 0; j < V; ++j) {
        if (dist[k][j] == INF) {
          continue;
        }
        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
      }
    }
  }
}


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

  for (size_t i = 0; i < 10; i++) {
    for (size_t j = 0; j < 10; j++) {
      cin >> dist[i][j];
    }
  }

  wf_run(10);
  // for (size_t i = 0; i < 10; i++) {
  //   for (size_t j = 0; j < 10; j++) {
  //     cout << dist[i][j] << " ";
  //   }
  //   cout << endl;
  // }

  int nc[10] = {};
  for (size_t i = 0; i < H; i++) {
    for (size_t j = 0; j < W; j++) {
      int t;
      cin >> t;
      if (t >= 0) {
        nc[t]++;
      }
    }
  }

  int sum = 0;
  for (size_t i = 0; i < 10; i++) {
    sum += dist[i][1] * nc[i];
  }
  cout << sum << endl;
}


Measured memory_bytes: 256
function Main(input){
    input = input.split("\n");
    var [p,k] = input[0].split(" ");
    var arr = input[1].split(" ");
    var n = arr.length;
    console.log(Math.ceil((n-1)/(k-1)));
}Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());


Measured memory_bytes: 34752
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
//l={1,2,3,4}
//greater<int>()
//sort(l,l+n)

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

	if ((a + b) % 2 == 0)
		cout << (a + b) / 2 << endl;
	else
		cout << (a + b) / 2 + 1 << endl;
}


Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.text.DecimalFormat;

public class Main {
    public static void main(String[] args) throws IOException {
        FastReader in = new FastReader(System.in);
        StringBuilder sb = new StringBuilder();
        int i,j;
        int n=in.nextInt();
        int ans[]=new int[n+1];
        for(i=1;i<n;i++){
            int x=in.nextInt();
            ans[x]++;
        }

        for(i=1;i<=n;i++)
            sb.append(ans[i]+"\n");
        System.out.print(sb);
    }
}

class FastReader {

    byte[] buf = new byte[2048];
    int index, total;
    InputStream in;

    FastReader(InputStream is) {
        in = is;
    }

    int scan() throws IOException {
        if (index >= total) {
            index = 0;
            total = in.read(buf);
            if (total <= 0) {
                return -1;
            }
        }
        return buf[index++];
    }

    String next() throws IOException {
        int c;
        for (c = scan(); c <= 32; c = scan());
        StringBuilder sb = new StringBuilder();
        for (; c > 32; c = scan()) {
            sb.append((char) c);
        }
        return sb.toString();
    }
    String nextLine() throws IOException {
        int c;
        for (c = scan(); c <= 32; c = scan());
        StringBuilder sb = new StringBuilder();
        for (; c !=10 && c!=13; c = scan()) {
            sb.append((char) c);
        }
        return sb.toString();
    }
    char nextChar() throws IOException{
        int c;
        for (c = scan(); c <= 32; c = scan());
        return (char)c;
    }

    int nextInt() throws IOException {
        int c, val = 0;
        for (c = scan(); c <= 32; c = scan());
        boolean neg = c == '-';
        if (c == '-' || c == '+') {
            c = scan();
        }
        for (; c >= '0' && c <= '9'; c = scan()) {
            val = (val << 3) + (val << 1) + (c & 15);
        }
        return neg ? -val : val;
    }

    long nextLong() throws IOException {
        int c;
        long val = 0;
        for (c = scan(); c <= 32; c = scan());
        boolean neg = c == '-';
        if (c == '-' || c == '+') {
            c = scan();
        }
        for (; c >= '0' && c <= '9'; c = scan()) {
            val = (val << 3) + (val << 1) + (c & 15);
        }
        return neg ? -val : val;
    }
}


Measured memory_bytes: 46816
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <set>

#define pb push_back
#define mp make_pair

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef unsigned long long ull;
typedef long long ll;

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

  int L = 1;
  int R = 100005;
  for (int i = 0; i < m; ++i) {
    int l, r;
    cin >> l >> r;

    L = max(l, L);
    R = min(r, R);
  }
  
  cout << max(0, R-L+1) << endl;

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <map>
#include <queue>
#define rep(i,n) for (int i=0;i<(n);i++)

using namespace std;

int main() {
	string s;
	cin >> s;

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

	return 0;
}

Measured memory_bytes: 3588
#include <iostream>
#include <numeric>
#include <math.h>
#include <algorithm>
#include <float.h>
#include <limits>
#include <vector> 
#include <string.h>
#include <iomanip>

#define rep(i,a,n) for(ll int (i) = (a);(i) < (n);(i)++)
#define urep(i,a,n) for(ll int (i) = (a);(i) > (n);(i)--)
#define MOD 1000000007
#define INF 2147483647
#define ll long long
#define asort(a) sort(a.begin(),a.end());//昇順ソート
#define usort(a) sort(a.rbegin(),a.rend());//降順ソート

using namespace::std;

int jo(ll int a, ll int b){//累乗
    ll int num=1;
    rep(i,0,b) num=num*a;
    return num;
}
char tobig(char s){//char大文字化
  return (s-0x20);
}
char tolow(char s){//char小文字化
  return (s+0x20);
}
int ctoi(char a){//char->int
  if('0'<=a&&a<='9') return (a-'0');
  return -1;
}

int gcd(ll int a,ll int b) {//最大公約数
  if(a<b) return gcd(b,a);
  int c;
  while ((c=a%b)) {
    a=b;
    b=c;
  }
  return b;
}
int lcm(ll int a,ll int b){//最小公倍数
 return (a*b)/gcd(a,b);
}


int main(){
  string A,B;cin>>A;B="YAKI";
  A=A+"BBBB";
  int check=0;
  rep(i,0,4){
    if(A[i]!=B[i]) check++;
  }
  cout<<(!check?"Yes":"No");
}




// vector<vector<int>> 変数名(左の個数, vector<int>(右の個数));

//cout<<fixed<<setprecision(n);  //小数点n桁まで表示

//  vector<pair<int,int>> data(N);  //2つのデータを格納、.first/.secondで参照
// pairのソートはfirst優先の昇順


Measured memory_bytes: 256
/*
T(i, S) 截止到第 i 行，状态为 S 的方案数，如果截止到 i 行 S 中没有 i 个 1，则没意义

T(i, S' | (1<< j) ) = Sum{ T(i-1, S') }
*/

package main

import "fmt"

const MOD = 1e9+7
const N = 21
var a [N][N]int

func main() {
  var n int
  fmt.Scanf("%d", &n)
  for i := 0; i < n; i++ {
    for j := 0; j < n; j++ {
      fmt.Scanf("%d", &a[i][j])
    }
  }
  current := make([]int, 1<<n)
  current[0] = 1
  for i := 0; i < n; i++ {
    next := make([]int, 1<<n)
    for s := 0; s < (1<<n); s++ {
      if current[s] == 0 { continue }
      for j := 0; j < n; j++ {
        if a[i][j] == 0 { continue }
        next[s | (1<<j)] = (next[s | (1<<j)] + current[s]) % MOD
      }
    }
    current = next
  }
  fmt.Println(current[(1<<n) - 1])
}

Measured memory_bytes: 69848
a = list(map(int, input().split()))
k = int(input())
count = 0

while a[1] <= a[0]:
    a[1] = a[1]*2
    count += 1
while a[2] <= a[1]:
    a[2] = a[2]*2
    count += 1

if count > k:
    print('No')
else:
    print('Yes')


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

using lint = long long;
template <typename T> using V = vector<T>;
template <typename T> using VV = vector<vector<T>>;
#define rep(i, n) for(int i = 0; i < int(n); i++)
#define repu(i, a, b, s) for(int i = int(a); i < int(b); i += int(s))
#define repd(i, a, b, s) for(int i = int(a); i > int(b); i += int(s))
#define endl "\n"
constexpr lint INF = 2e18;
constexpr lint MOD = 1e9 + 7;

void solve() {

    lint R, C, K;
    cin >> R >> C >> K;

    auto grid = new lint[3001][3001]();
    auto dp = new lint[3001][3001][4]();

    rep(i, R) {
        rep(j, C) { grid[i][j] = -1; }
    }

    rep(i, K) {
        lint r, c, v;
        cin >> r >> c >> v;
        r--;
        c--;
        grid[r][c] = v;
    }

    rep(y, R) {
        rep(x, C) {
            rep(i, 4) { dp[y][x][i] = 0; }
        }
    }

    if(grid[0][0] != -1)
        dp[0][0][1] = grid[0][0];

    rep(y, R) {
        rep(x, C) {

            // 選ばない
            if(0 <= y - 1) {
                rep(i, 4) { dp[y][x][0] = max(dp[y][x][0], dp[y - 1][x][i]); }
            }
            if(0 <= x - 1) {
                rep(i, 4) { dp[y][x][i] = max(dp[y][x][i], dp[y][x - 1][i]); }
            }

            // 選ぶ
            if(grid[y][x] != -1) {
                if(0 <= y - 1) {
                    rep(i, 4) {
                        dp[y][x][1] =
                            max(dp[y][x][1], dp[y - 1][x][i] + grid[y][x]);
                    }
                }
            }
            if(0 <= x - 1) {
                repu(i, 1, 4, 1) {
                    dp[y][x][i] =
                        max(dp[y][x][i], dp[y][x - 1][i - 1] + grid[y][x]);
                }
            }
        }
    }

    lint ans = -INF;
    rep(i, 4) { ans = max(ans, dp[R - 1][C - 1][i]); }
    cout << ans << endl;

    delete[] dp;
    delete[] grid;
}

int main() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    solve();
    return 0;
}


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

 int main()
 {
 string S, T;
 cin >> S >> T;
 int N = S.size(), ans = 0;
 for(int i = 0; i < N; ++i){
 if(S[i] != T[i]) ++ans;
 }
 cout << ans << endl;
 }

Measured memory_bytes: 3880
/*
for (int i = 0; i < N; ++i){}

// 各桁の和を計算する関数
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

sort(a, a + N, greater<int>());  // a[0:N] を大きい順にソート

int num[110] = {0};  // バケット
for (int i = 0; i < N; ++i) {
    num[d[i]]++;  // d[i] が 1 個増える
}

map<string, int> mp; // 連想配列 map<キー型, 値型> オブジェクト名
for (int i = 0; i < N; ++i) {
    auto itr = mp.find(s[i]);        // s[i] が設定されているか？
    if(itr != mp.end() ) {
         mp[s[i]] += 1;
    }
    else {
         mp[s[i]] += 1 ;
    }
}
stack<int> s;	//intをデータとするスタックを用意
s.push(1);		//{} -> {1}
printf("%d\n", s.top());	// 3
s.pop();

queue<int> que;	//intをデータとするキューを用意
que.push(1);		//{} -> {1}
printf("%d\n", que.front());	// 1
que.pop();
*/
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>

using namespace std;

// #define for(i,a,b) for (int i=(a);i<(b);++i)
typedef long long ll;
typedef pair<int,int> point;
#define rep(i,n) for(i,0,n)
 
int main() {
	// 入力
	ll N, x;
	cin >> N >> x;
	ll a[N];
	for (int i = 0; i < N; ++i) cin >> a[i];
	
	
	// 解法
	sort(a, a + N);
	ll sum = 0;
	ll ans = 0;
	for (int i = 0; i < N; ++i){
		sum+=a[i];
		if (sum>x) break;
		ans++;
		if (sum==x) break;
		if (i==N-1) ans--;
	}
	printf("%lld\n", ans);
}
 


Measured memory_bytes: 256
import math


def to_angle(x):
    return x * 180 / math.pi


def main():
    a, b, x = map(float, raw_input().split())
    v = a * a * b
    if v <= x * 2:
        print(to_angle(math.atan(2 * (v - x) / a ** 3)))
    else:
        print(to_angle(math.atan(a * b * b / x * 0.5)))


main()


Measured memory_bytes: 28012
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
using namespace std;
typedef pair<int, int> P;

int n;
int INF = 1e12;

signed main(){
    while(cin >> n, n){
        int d[20][20] = {};
        rep(i, 0, n){
            rep(j, 0, n + 1){
                cin >> d[i][j];
            }
        }
        int dp[(1 << n)];
        rep(i, 0, (1 << n)) dp[i] = INF;
        dp[0] = 0;
        for(int mask = 0; mask < (1 << n); mask++){
            for(int i = 0; i < n; i++){
                if((mask & (1 << i)) == 0){
                    int tmp = d[i][0];
                    rep(j, 0, n){
                        if(mask & (1 << j)){
                            tmp = min(tmp, d[i][j + 1]);
                        }
                    }
                    dp[mask | (1 << i)] = min(dp[mask | (1 << i)], dp[mask] + tmp);
                }
            }
        }
        // rep(i, 0, 16) cout << i << " " << dp[i] << endl;
        cout << dp[(1 << n) - 1] << endl;
    }
}

Measured memory_bytes: 3592
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
typedef pair<int, int> P;
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;
}
const vector<int> di = {-1, 0, 1, 0};
const vector<int> dj = {0, -1, 0, 1};
const int INF = 1001001001;
const int MOD = 1000000007;

int n, m;
vector<tuple<int, int, int>> phrases;
vector<int> melodies;

int main() {
  cin >> n;
  phrases.resize(n);

  rep(i, n) {
    int s, l, p;
    cin >> s >> l >> p;
    phrases[i] = make_tuple(s, l, p);
  }

  cin >> m;
  melodies.resize(m);
  rep(i, m) cin >> melodies[i];

  vector<int> ans(m);
  bool ok = true;

  rep(i, m) {
    int melody_length = melodies[i];
    vector<vector<int>> dp(n + 1, vector<int>(melody_length + 1, 0));

    rep(j, n) {
      int shortest, longest, score;
      tie(shortest, longest, score) = phrases[j];

      rep(k, melody_length + 1) {
        dp[j + 1][k] = dp[j][k];

        if (k - shortest >= 0) {
          chmax(dp[j + 1][k], dp[j + 1][k - shortest] + score);
        }

        if (k - longest >= 0) {
          chmax(dp[j + 1][k], dp[j + 1][k - longest] + score);
        }
      }
    }

    // for (auto&& x : dp) {
    //   for (auto&& y : x) {
    //     cout << y << ' ';
    //   }
    //   cout << endl;
    // }

    if (dp[n][melody_length]) {
      ans[i] = dp[n][melody_length];
    } else {
      ok = false;
      break;
    }
  }

  if (ok) {
    for (auto&& i : ans) {
      printf("%d\n", i);
    }
  } else {
    printf("-1\n");
  }
}



Measured memory_bytes: 3420
#9:41〜9:52
N,M=map(int,input().split())
likelist=[]
for n in range(N):
	like=list(map(int,input().split()))
	likelist.extend(like[1:])
everyonelikes=0
for m in range(1,M+1):
	if likelist.count(m) == N:
		everyonelikes += 1
print(everyonelikes)

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

class mint {
    long long x;
public:
    mint(long long x = 0) : x((x% MOD + MOD) % MOD) {}
    mint operator-() const {
        return mint(-x);
    }
    mint& operator+=(const mint& a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint& a) {
        if ((x += MOD - a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const  mint& a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint operator+(const mint& a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint& a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint& a) const {
        mint res(*this);
        return res *= a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }
    // for prime MOD
    mint inv() const {
        return pow(MOD - 2);
    }
    mint& operator/=(const mint& a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint& a) const {
        mint res(*this);
        return res /= a;
    }

    friend ostream& operator<<(ostream& os, const mint& m) {
        os << m.x;
        return os;
    }
};

///////////////////////////

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

    vector<ll> A(N + 1), B(N + 1);

    repn(i, N) cin >> A[i] >> B[i];

    vector<pair<ll, ll>> v(2 * N + 1);
    repn(i, N) v[i] = { A[i],i };
    repn(i, N) v[N + i] = { B[i],i };

    sort(++v.begin(), v.end());

    ll ans = 0;
    vector<ll> c(N + 1,0);
    ll check = 0;
    repn(i, N) {
        ans += v[i].first;
        c[v[i].second]++;
        if (c[v[i].second] == 2) { check = 1; }
    }

    if (check == 0) { 
        if (v[N].second != v[N + 1].second) { ans = ans - v[N].first + v[N + 1].first; }
        else {
            ans = min(ans - v[N - 1].first + v[N + 1].first, ans - v[N].first + v[N + 2].first);
        }
    }

    ll sa = 0;
    ll sb = 0;
    repn(i, N) {
        sa += A[i];
        sb += B[i];
    }

    ans = min(ans, min(sa, sb));

    cout << ans;

		

	
	system("PAUSE");
}


Measured memory_bytes: 6008
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000000000000
#define MOD 1000000007
#define all(v) v.begin(),v.end()
#define pb push_back
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int kaijo[2000010];
struct edge{int to,cost;};
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
void init_fact(){
    kaijo[0]=1;
    for(int i=1;i<=2000000;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=MOD;
    }
}
int modpow(int a,int b){
    if(b==0)return 1;
    if(b%2)return modpow(a,b-1)*a%MOD;
    int memo=modpow(a,b/2);
    return memo*memo%MOD;
}
int comb(int a,int b){
    if(!kaijo[0])init_fact();
    return kaijo[a]*modpow(kaijo[a-b],MOD-2)%MOD*modpow(kaijo[b],MOD-2)%MOD;
}
int inv(int x){
    x=modpow(x,MOD-2);
    return x;
}
bool kosa(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy){
    double ta=(cx-dx)*(ay-cy)+(cy-dy)*(cx-ax);
    double tb=(cx-dx)*(by-cy)+(cy-dy)*(cx-bx);
    double tc=(ax-bx)*(cy-ay)+(ay-by)*(ax-cx);
    double td=(ax-bx)*(dy-ay)+(ay-by)*(ax-dx);
    return tc*td<0&&ta*tb<0;
}
double dist(double ax,double ay,double bx,double by){
    return sqrt((bx-ax)*(bx-ax)+(ay-by)*(ay-by));
}
int h,n,a[100010],sum;
signed main(){
    cin>>h>>n;
    rep(i,n){
        cin>>a[i];
        sum+=a[i];
    }
    if(sum>=h)puts("Yes");
    else puts("No");
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;

int main(){
    int N, D[51] = {}, pos[51] = {};
    cin >> N;
    for(int i = 1; i <= N; i++){
        cin >> D[i];
    }
    sort(D, D+(N+1));
    bool right = true;
    for(int i = 0; i <= N; i++){
        if(right){
            pos[i] = D[i];
        }else{
            pos[i] = (24-D[i])%24;
        }
        right = !right;
    }
    sort(pos, pos+(N+1));
    for(int i = 0; i <= N; i++){
        //printf("%d: %d\n", i, pos[i]);
    }
    int ans = 10000;
    for(int i = 0; i < N; i++){
        ans = min(ans, pos[i+1] - pos[i]);
    }
    ans = min(ans, 24 - pos[N]);
    cout << ans << endl;
}


        
    

Measured memory_bytes: 256
N = int(input())
Li_2 = 2
Li_1 = 1
Li = 0
if N > 1:
    for i in range(2, N+1):
        Li = Li_1 + Li_2
        Li_2 = Li_1
        Li_1 = Li
print(Li) if N !=1 else print(Li_1) 

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

using namespace std;

#define llong long long int
#define rep(i, n) for (int i = 0; i < n; ++i)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define stl_repr(itr, x) for (auto itr = x.rbegin(); itr != x.rend(); ++itr)
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()

const static int MOD = 1000000000 + 7;
const static int inf = INT_MAX / 2;
const static llong INF = 1LL << 31;
const static int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

vector<vector<int> > dp, G;
int main (int argc, char *argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n, m, s, t;
  cin >> n >> m;
  G.resize(n);
  rep(i, m) {
    int u, v;
    cin >> u >> v;
    --u;
    --v;
    G[u].emplace_back(v);
  }
  cin >> s >> t;
  --s;
  --t;

  dp.resize(n, vector<int>(3, inf));
  dp[s][0] = 0;
  queue<pair<int, int> > Q;
  Q.push(make_pair(s, 0));

  while(! Q.empty()) {
    int cur = Q.front().first, cost = Q.front().second;
    Q.pop();
    rep(i, (int)G[cur].size()) {
      if (dp[G[cur][i]][(cost + 1) % 3] == inf) dp[G[cur][i]][(cost + 1) % 3] = dp[cur][cost] + 1, Q.push(make_pair(G[cur][i], (cost + 1) % 3));
    }
  }

  if (dp[t][0] == inf) cout << -1 << endl;
  else cout << dp[t][0] / 3 << endl;


  return 0;
}

Measured memory_bytes: 11264