akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cmath>
#define LEN 6378.1
#define PI 3.141592653589793238
using namespace std;
double a, b, c, d, BC, CA, C;
int main() {
    while (true) {
        cin >> a >> b >> c >> d;
        if (a == -1) { break; }
        BC = PI / 180 * (90.0 - a);
        CA = PI / 180 * (90.0 - c);
        C = PI*(d - b) / 180;
        cout << (int)(0.5 + LEN*acos(cos(BC)*cos(CA) + sin(BC)*sin(CA)*cos(C)))<< endl;
    }
}

Measured memory_bytes: 3440
#!/usr/bin/env python
# -*- coding: utf-8 -*-
let = [chr(i) for i in xrange(ord('A'), ord('Z') + 1)]

def reverse(s, pos):
    res, rev = "", ""
    p = 0
    while p < len(s):
        if s[p] == '[':
            hoge, p = reverse(s[p + 1:], p + 1)
            rev += hoge
        elif s[p] == ']':
            return rev[::-1], p + pos
        else:
            rev += s[p]
        p += 1

def letter(s):
    stack = 0
    tmp = ""
    for i in s:
        if i == '+':stack += 1
        if i == '-':stack -= 1
        if ord('A') <= ord(i) and ord(i) <= ord('Z'):
            tmp += let[(ord(i) - ord('A') + stack + 26*30)%26]
            stack = 0
        if i == '?':
            tmp += 'A'
            stack = 0
        if i == '[' or i == ']':
            tmp += i
    res = ""
    p = 0
    while p < len(tmp):
        if tmp[p] == '[':
            hoge, p = reverse(tmp[p + 1:], p + 1)
            res += hoge
        elif tmp[p] != ']':
            res += tmp[p]
        p += 1;
    return res

def __main__():
    while 1:
        s = raw_input()
        if s == ".":break
        print letter(s)


__main__()

Measured memory_bytes: 6472
#include <stdio.h>		// standard input output
#include <iostream>		// input output stream, cin cout( console in console out)
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>		// input output manipulation

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define ll long long 

int main() {
  int X, Y, flg=0;
  cin >> X >> Y;
  
  int j;
  for(int i=0; i<=X; i++){
    j = X - i;
    if((i*2 + j*4) == Y){
      cout << "Yes" << endl;
      flg = 1;
      break;
    }
  }
  
  if(flg == 0){
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18)
#define all(v) v.begin(),v.end()
#define prique(T) priority_queue<T,vector<T>,greater<T>>
using namespace std;

template<class T> inline void chmax(T &a, T b) {
	a = std::max(a, b);
}
template<class T> inline void chmin(T &a, T b) {
	a = std::min(a, b);
}

int mod_pow(int x, int y, int m = mod) {
	int res = 1;
	while (y) {
		if (y % 2) {
			res *= x;
			res %= m;
		}
		x = x * x % mod;
		y /= 2;
	}
	return res;
}

int H, W;
char a[105][105];

struct edge {
	int to, cap, rev;
};
vector<edge> G[250];
bool used[250];
void add_edge(int from, int to, int cap) {
	G[from].push_back((edge ) { to, cap, G[to].size() });
	G[to].push_back((edge ) { from, 0, G[from].size() - 1 });
}
int dfs(int v, int t, int f) {
	if (v == t)
		return f;
	used[v] = true;
	for (edge &e : G[v]) {
		if (!used[e.to] && e.cap > 0) {
			int d = dfs(e.to, t, min(f, e.cap));
			if (d > 0) {
				e.cap -= d;
				G[e.to][e.rev].cap += d;
				return d;
			}
		}
	}
	return 0;
}
int max_flow(int s, int t) {
	int flow = 0;
	while (1) {
		memset(used, 0, sizeof(used));
		int f = dfs(s, t, inf);
		if (f == 0)
			return flow;
		flow += f;
		if (flow >= inf)
			return inf ;
	}
}

signed main() {
	cin >> H >> W;
	rep(i,H)
	{
		rep(j,W)
		{
			cin >> a[i][j];
			if (a[i][j] == 'S') {
				add_edge(200, i, inf);
				add_edge(200, 100 + j, inf);
			} else if (a[i][j] == 'T') {
				add_edge(i, 201, inf);
				add_edge(100 + j, 201, inf);
			} else if (a[i][j] == 'o') {
				add_edge(i, 100 + j, 1);
				add_edge(100 + j, i, 1);
			}
		}
	}
	int ans = max_flow(200, 201);
	if (ans == inf)
		cout << -1 << endl;
	else
		cout << ans << endl;
}


Measured memory_bytes: 1536
fn main() {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    let mut h: u64= iter.next().unwrap().parse().unwrap();

    let mut ans = 0u64;
    let mut nr_enemy = 1u64;

    while h > 0 {
        ans += nr_enemy;
        nr_enemy *= 2;
        h /= 2;
    }

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


Measured memory_bytes: 4352
H, W = list(map(int, input().split()))
S = [input() for _ in range(H)]

def update(y, x, direction, d, q, end_pos):
    next_y, next_x = (y + direction[0], x + direction[1])
    if (next_y < 0 or next_y >= H or next_x < 0 or next_x >= W): # 端なら
        return end_pos 
    if (S[next_y][next_x] == '#') or (d[next_y][next_x] != -1): # 壁か既に訪問状態なら
        return end_pos
    d[next_y][next_x] = d[y][x] + 1
    q[end_pos] = (next_y, next_x)
    return end_pos + 1
    
def bfs(i, j):
    DIJ = ((-1, 0), (0, -1), (1, 0), (0, 1)) # (y, x):下, 左, 上, 右
    dist = [[-1] * W for _ in range(H)]
    dist[i][j] = 0 #始点は０

    wall_num = sum(ss.count('#') for ss in S)
    queue = [(-1, -1) for _ in range(H * W - wall_num)]
    queue[0] = (i, j)
    queue_end_pos = 1 # 一番後ろの値の+1
    while queue:
        cur_y, cur_x = queue.pop(0)
        queue_end_pos -= 1
        for i in range(4):
            queue_end_pos = \
            update(cur_y, cur_x, DIJ[i], dist, queue, queue_end_pos)
    return max(max(dd) for dd in dist)
    
max_results = 0
for i in range(H):
    for j in range(W):
        if S[i][j] != '#':
            max_results = max(bfs(i, j), max_results) 
print(max_results)

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


using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007



int main(){
  
  srand((unsigned)time(NULL));
  int d;
  int res = 0;
  cin >> d;
  vector<int> c(26);
  rep(i,26)cin >> c[i];
  vector<vector<int>> v(d,vector<int>(26));
  vector<int> contest(d,0);
  vector<int> last(26,0);
  vector<int> satisfy(26,0);
  rep(i,d)rep(j,26){
    int x;cin >> x;
    v[i][j] = x;
  }/*
  for(int i = 1;i <= d;i++){
    rep(j,26)if(v[i-1][contest[i-1]] < v[i-1][j])contest[i-1] = j;
    last[contest[i-1]] = i;
    res += v[i-1][contest[i-1]];
    rep(j,26)res -= c[j]*(i-last[j]),satisfy[j] += c[j]*(i-last[j]);
  }
  while(1.0*clock()/CLOCKS_PER_SEC <= 1.7){
    //int now_time = clock();
    //if(1.0*now_time/CLOCKS_PER_SEC > 1.7)break;
    int day = rand()%d,pos = rand()%26;
    vector<int> new_contest = contest;
    int res_ = res;
    int pre = new_contest[day];
    res_ += satisfy[pos];
    res_ += satisfy[pre];
    res_ -= v[day][pre];
    res_ += v[day][pos];
    int pos_satisfy = 0,pre_satisfy = 0;
    last[pos] = last[pre] = 0;
    new_contest[day] = pos;
    for(int i = 1;i <= d;i++)last[pos] = (new_contest[i-1] == pos ? last[pos] = i : last[pos]),pos_satisfy += c[pos]*(i-last[pos]);
    for(int i = 1;i <= d;i++)last[pre] = (new_contest[i-1] == pre ? last[pre] = i : last[pre]),pre_satisfy += c[pre]*(i-last[pre]);
    res_ -= (satisfy[pos]+satisfy[pre]);
    if(res < res_){
      res = res_;
      contest = new_contest;
      satisfy[pre] = pre_satisfy;
      satisfy[pos] = pos_satisfy;
    }
  }
  rep(i,d)cout << contest[i]+1 << endl;*/
  int j = 365;
  for(int i = 0;j;i++){
    cout << (i%26) + 1 << endl;
    j--;
  }
  


  return 0;
}


Measured memory_bytes: 3680
x1, y1, x2, y2 = [int(x) for x in input().split()]

x4 = x1 - (y2 - y1)
y4 = y1 + (x2 - x1)
x3 = x2 + x4 - x1
y3 = y2 + y4 - y1

print("{} {} {} {}".format(x3, y3, x4, y4))

Measured memory_bytes: 2940
from math import factorial

n = int(input())
xy = [[int(i) for i in input().split()] for i in range(n)]

length = []

for i in range(n-1):
    for j in range(i+1, n):
        length.append(pow(((xy[i][0]-xy[j][0])**2 + (xy[i][1]-xy[j][1])**2), 1/2))

m = (n-1) / (n*(n-1)/2)
mount = 0
for i in range(len(length)):
    mount += length[i] * m

print(mount)


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

using namespace std;

void Main() {
    long long A, B, V, W, T;
    cin >> A >> V;
    cin >> B >> W;
    cin >> T;

    if (V <= W) {
        cout << "NO" << endl;
        return;
    }

    long long oniX = 0LL;
    long long koX = abs(A - B);
    cout << ((koX <= (V - W) * T) ? "YES" : "NO") << endl;
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int x;
    cin >> x;
    int a[] = {599, 799, 999, 1199, 1399, 1599, 1799, 1999};
    for (int i = 0; i < 8; ++i)
        if (x <= a[i]) {
            cout << 8 - i << endl;
            break;
        }
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int N,W,i,x,y;
	cin >> N >> W;
	vector <long long> dp(W+1,0);	
	for(i=0;i<N;i++)
	{
		cin >> x >> y;//x is weight and y is value
		for(int weight = W;weight >= x;weight--)
		{
			dp[weight] = max(dp[weight],dp[weight-x]+y);
		}
	}
	cout << dp[W];
}

Measured memory_bytes: 1024
#pragma region

#include <bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(), (x).end()
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for (int i = (begin); i < (end); i++)
#define IFOR(i, begin, end) for (int i = (end)-1; i >= (begin); i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define MOD 1000000007
#define debug(x) cerr << #x << " = " << (x) << " (line: " << __LINE__ << ") " << endl;
typedef long long ll;
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (auto &v : vec) is >> v;
  return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "vec[ ";
  REP(i, vec.size())
  i == 0
      ? os << vec[i]
      : os << ", " << vec[i];
  os << " ]";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const deque<T> &deq) {
  os << "deq[ ";
  REP(i, deq.size())
  i == 0
      ? os << deq[i]
      : os << ", " << deq[i];
  os << " ]";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const set<T> &set) {
  os << "{ ";
  for (auto &&s : set) &s == &(*set.begin()) ? os << s : os << ", " << s;
  os << " }";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const unordered_set<T> &set) {
  os << "{ ";
  for (auto &&s : set) &s == &(*set.begin()) ? os << s : os << ", " << s;
  os << " }";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const multiset<T> &set) {
  os << "{ ";
  for (auto &&s : set) &s == &(*set.begin()) ? os << s : os << ", " << s;
  os << " }";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const unordered_multiset<T> &set) {
  os << "{ ";
  for (auto &&s : set) &s == &(*set.begin()) ? os << s : os << ", " << s;
  os << " }";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
  os << "(" << p.first << ", " << p.second << ")";
  return os;
}
template <typename TK, typename TV>
ostream &operator<<(ostream &os, const map<TK, TV> &m) {
  os << "{ ";
  for (auto &&k : m) &k == &(*m.begin()) ? os << k.first << " => " << k.second : os << ", " << k.first << " => " << k.second;
  os << " }";
  return os;
}
template <typename TK, typename TV>
ostream &operator<<(ostream &os, const unordered_map<TK, TV> &m) {
  os << "{ ";
  for (auto &&k : m) &k == &(*m.begin()) ? os << k.first << " => " << k.second : os << ", " << k.first << " => " << k.second;
  os << " }";
  return os;
}

#pragma endregion

typedef struct tuple<int, bool, int> ibituple;

typedef struct Node {
  vector<Node *> parents;
  double time;
} node;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  string S;
  cin >> S;
  if (S == "SUN")
    cout << 7 << "\n";
  else if (S == "MON")
    cout << 6 << "\n";
  else if (S == "TUE")
    cout << 5 << "\n";
  else if (S == "WED")
    cout << 4 << "\n";
  else if (S == "THU")
    cout << 3 << "\n";
  else if (S == "FRI")
    cout << 2 << "\n";
  else if (S == "SAT")
    cout << 1 << "\n";
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1

def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(a, b, x):
    c = x / (a**2)
    if b > 2*c:
        y = (2*a*c)/b
        h = math.sqrt(y**2 + b**2)
        return math.degrees(math.acos(y/h))
    
    d = 2*b - (2*x)/(a**2)
    h = math.sqrt(a**2 + d**2)
    return math.degrees(math.acos(a/h))


def main():
    A, B, X = read_int_n()
    print(slv(A, B, X))


if __name__ == '__main__':
    main()


Measured memory_bytes: 61844
# AtCoder Beginner Contest 175
# A - Rainy Season

S=input()
if S=="RRR":
    print(3)
    exit()
if S=="SRR" or S=="RRS":
    print(2)
    exit()
if S=="SSS":
    print(0)
    exit()
else:
    print(1)

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

using namespace std;

int main() {

	string s;
	cin >> s;
	int count = 700;
	if(s[0] == 'o') {
		count += 100;
	}

	if(s[1] == 'o') {
		count += 100;
	}

	if(s[2] == 'o') {
		count += 100;
	}
 
 	printf("%d\n", count);
	return 0;
}

Measured memory_bytes: 892
#include <iostream>
#include <vector>

using namespace std;

#define MAXN 100005

vector<int> adj[MAXN];

int depth[MAXN];

bool visited[MAXN];



int dfs(int s){

    visited[s]=true;
    
    int ret=0;

    for(int a : adj[s]){
    
        if(visited[a]) ret=max(ret,depth[a]+1);
        else ret = max(ret,dfs(a)+1);

    } 
    return depth[s] = ret;

}

int main(){

    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);cerr.tie(NULL);

    int n,m;cin>>n>>m;
    int tmp1,tmp2;
    for(int i=0;i<m;i++){
        cin>>tmp1>>tmp2;
        adj[tmp1].push_back(tmp2);
    }
    int ans=0;
    for(int i=1;i<=n;i++){

        if(!visited[i]) ans = max(ans,dfs(i));
    
    }

    cout<<ans<<endl;

    return 0;

}


Measured memory_bytes: 8320
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 200000 + 10;
const ll mod = 1000000007;
ll n;
int main(){
    cin >> n;
    ll sum[N] = {0};
    ll ans = 0;
    vector<ll> a(n + 10);

    for(int i = 1;i<=n;i++){
        cin >> a[i];
        sum[i] = (sum[i-1] + a[i]);
    }

    for(int i = 1;i<=n-1;i++){
        ans += (a[i] * ((sum[n] - sum[i]) % mod));
        ans %= mod;
    }
    cout << ans % mod << endl;

    return 0;
}

Measured memory_bytes: 6432
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
 
long long N, M, a[100009][3], maxn = -(1LL << 60);
 
int main() {
	cin >> N >> M;
	for (int i = 1; i <= N; i++) {
		for (int j = 0; j < 3; j++) cin >> a[i][j];
	}
	for (int i = 0; i < 8; i++) {
		vector<long long>vec;
		for (int j = 1; j <= N; j++) {
			long long S = 0;
			for (int k = 0; k < 3; k++) { if ((i / (1 << k)) % 2 == 0) S += a[j][k]; else S -= a[j][k]; }
			vec.push_back(S);
		}
		sort(vec.begin(), vec.end()); reverse(vec.begin(), vec.end());
		long long ans = 0;
		for (int j = 0; j < M; j++) ans += vec[j];
		maxn = max(maxn, ans);
	}
	cout << maxn << endl;
	return 0;
}

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

ans = {}
if M > 0:
  for _ in range(M):
    key, value = input().split()
    if key not in ans:
      ans[key] = []
    ans[key].append(value)
else:
  print(0," ",0)
  exit()

ac = 0
wa = 0

for v in ans.values():
  if 'AC' in v: # ACを出している場合
    for a in v:
      if a == 'WA':
        wa += 1
      else:
        ac += 1
        break
  else: # ACを出していない場合
    continue

print(ac, " ", wa)

Measured memory_bytes: 31580
#line 2 "../../library/template.hpp"
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using pl = pair<ll, ll>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0; i < (ll)n; i++)
#define rep3(i, l, r) for(ll i = l; i < (ll)r; i++)
#define per(i, n) for(ll i = (ll)n-1; i >= 0; i--)
#define per3(i, l, r) for(ll i = (ll)r-1; i >= (ll)l; i--)
#define all(v) begin(v), end(v)
template<class T, class U>
inline void cmax(T& a, U b) { if (a < b) a = b; }
template<class T, class U>
inline void cmin(T& a, U b) { if (a > b) a = b; }

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    cerr << fixed << setprecision(15);
  }
} io_setup;

constexpr char el = '\n';

template<class T, class U>
ostream &operator<<(ostream &os, const pair<T, U>& p) {
  os << p.first << " " << p.second;
  return os;
}
template<class T, class U>
istream &operator>>(istream &is, pair<T, U> &p) {
  is >> p.first >> p.second;
  return is;
}
template<class T>
ostream &operator<<(ostream &os, const vector< T > &v) {
  rep(i, v.size())
    os << v[i] << (i + 1 != v.size() ? " " : "");
  return os;
}
template<class T>
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}
#line 2 "a.cpp"

int main() {
  double n;
  cin >> n;
  cout << 2 * n * 3.14159265 << el;
}


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



int main()
{
	int A, B;
	scanf("%d%d", &A, &B);
	if((A % 3 == 0) || (B % 3 == 0) || ((A + B) % 3 == 0))
		puts("Possible");
	else
		puts("Impossible");
}


Measured memory_bytes: 256
import Control.Applicative
import Control.Monad

rInt s = read s :: Int

main  = do
	ss <- (map (map rInt) . map words . lines) <$> getContents
	mapM (mapM putStrLn . board) $ takeWhile (\(h:(w:_)) -> h/=0 && w/=0) ss 
		where 
			board (h:(w:_)) = (map (f w) [1..h]) ++ [""]
			f w i = map c $ map (+i) [1..w]
			c i = if even i then '#' else '.'

Measured memory_bytes: 5048
#include <iostream>
using namespace std;
int main(void)
{
    int n;
    cin >> n;
    long long int min = 10000000 ;
    long long int max = -10000000 ;
    long long int  x, sum = 0;
    for(int i = 0; i < n; i++){
        cin >> x;
        if (min > x){
            min = x;
        }
        if (max < x){
            max = x;
        }
        sum = sum + x;
    }
    cout << min << " ";
    cout << max << " ";
    cout << sum << endl;
    // Your code here!
    
}



Measured memory_bytes: 3088
#include <functional>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;
typedef pair <ll, ll> P;

int main() {
    cin.sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int n;
    cin >> n;

    vector <P> p(n);
    for (int i = 0; i < n; i++) {
        cin >> p[i].first;
        p[i].second = i;
    }

    sort(p.begin(), p.end(), greater<P>());

    multiset <ll> st;
    st.insert(-1);
    st.insert(-1);
    st.insert(n);
    st.insert(n);
    st.insert(p[0].second);

    ll ans = 0;
    for (int i = 1; i < n; i++) {
        ll val = p[i].second;

        auto itr = st.lower_bound(val);
        itr--;
        ll l1 = *itr;
        itr--;
        ll l2 = *itr;

        itr = st.lower_bound(val);
        ll r1 = *itr;
        itr++;
        ll r2 = *itr;

        ans += p[i].first * ((l1 - l2) * (r1 - val) + (val - l1) * (r2 - r1));

        st.insert(val);
    }

    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 6528
#include<iostream>
#include<complex>
#define rep(i,n) for(int i=0;i<n;i++)
#define op(a,b) (conj(a)*(b)).imag()
#define ip(a,b) (conj(a)*(b)).real()
using namespace std;
typedef complex<int> P;
int sign(P p,P d,P *a,int n,int s){
	int r=0,o;
	rep(i,n){
		o=-op(d,a[i]-p);
		if(o!=0){
			if(r*o<0){
				return 2;
			}
			r=o>0?1:-1;
		}else if(ip(d,a[i]-p)*s<0)return 2;
	}
	return r!=0?r>0?1:-1:0;
}
int main(){
	int n,m; while(cin>>n>>m,n){
		P b[n],w[m];
		rep(i,n)cin>>b[i].real()>>b[i].imag();
		rep(i,m)cin>>w[i].real()>>w[i].imag();
		rep(i,n)rep(j,m){
			P p=b[i],d=w[j]-b[i];
			int sb=sign(p,d,b,n,-1),sw=sign(p,d,w,m,1);
			if(sb!=2&&sw!=2&&sb*sw<=0){
				cout<<"YES"<<endl; goto END;
			}
		}
		cout<<"NO"<<endl; END:;
	}
	return 0;
}

Measured memory_bytes: 852
import collections
from functools import lru_cache
import bisect

INF = float("inf")
ZERO = 0
ONE = 1


def read():
    return input().strip()


def readInt():
    return int(input().strip())


def readList():
    return list(map(int, input().strip().split()))


def solve(N, M, arr):
    graph = collections.defaultdict(list)

    for u, v in arr:
        u -= 1
        v -= 1
        graph[u].append(v)
        graph[v].append(u)

    seen = [False] * N
    ans = 0

    for i in range(N):
        if not seen[i]:
            seen[i] = True
            q = collections.deque([i])
            componentSize = 0

            while q:
                curr = q.popleft()
                componentSize += 1

                for nei in graph[curr]:
                    if not seen[nei]:
                        seen[nei] = True
                        q.append(nei)

            ans = max(ans, componentSize)

    return ans


N, M = readList()
arr = set()

for _ in range(M):
    arr.add(tuple(sorted(readList())))

print(solve(N, M, arr))


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

int main(){
  int N, W;
  int v[1000], w[1000];
  int dp[10001];
  memset(dp, 0, sizeof(dp));
  cin>>N>>W;
  for(int i=0; i<N; i++)
    cin>>v[i]>>w[i];
  for(int i=0; i<N; i++)
    for(int j=0; j<=W; j++)
      if(w[i]<=j)dp[j]=max(dp[j], dp[j-w[i]]+v[i]);
  cout<<dp[W]<<endl;
  return 0;
}

Measured memory_bytes: 1216
using System;
using System.Linq;
using static System.Console;

namespace c {

static class Extensions {
   public static long ToInt(this string str) {
      return Int64.Parse(str);
   }
}

class Program {
   public static void Main(string[] args) {
      var tarr = ReadLine().Split(' ').Select(x => x.ToInt()).ToArray();
      var n = tarr[0];
      var m = tarr[1];
      
      var arr = new long[n][];
      for (int i = 0; i < n; i++) {
         arr[i] = ReadLine().Split(' ').Select(x => x.ToInt()).ToArray();
      }

      arr = arr.OrderBy(x => x[0]).ToArray();
      
      long count = 0;
      long okane = 0;
      for (int i = 0; i < n; i++) {
         if (arr[i][1] + count < m) {
            count += arr[i][1];
            okane += arr[i][0] * arr[i][1];
         } else {
            for (int j = 0; j < arr[i][1]; j++) {
               if (count != m) {
                  count++;
                  okane += arr[i][0];
               } else {
                  goto label;
               }
            }
         }
      }
      label:

      WriteLine(okane);
   }
}

}

Measured memory_bytes: 25524
#include<bits/stdc++.h>
using namespace std;
int main()
{

     long long int n,i,j=1,c=0,f=10000000000,l,k,x,y,z,m,b,a=10000000;
     string s,w="",s1;
    cin>>s>>w;
       n=w.length();

       for(i=0;i<s.length()-n+1;i++)
       {
           c=0;
            s1=s.substr(i,n);
               for(j=0;j<w.length();j++)
               {
                   if(s1[j]!=w[j])
                    c++;
                        //cout<<s[j]<<" "<<w[j]<<endl;
           }
          a=min(a,c);
          //break;
       }
       cout<<a<<endl;
}


Measured memory_bytes: 3640
// Created by sz
#include <bits/stdc++.h>
using namespace std;

const int N = 1e5 + 5;
int n, d;

int main(){
#ifdef LOCAL
    freopen("./input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    cin >> n >> d;
    
    vector<vector<int> > x(n, vector<int>(d, 0));
    
    for (int i = 0; i < n; i++){
        for (int j = 0; j < d; j++){
            cin >> x[i][j];
        }
    }
    
    int ans = 0;
    for (int i = 0; i < n; i++){
        for (int j = i+1; j < n; j++){
            int dis_square = 0;
            for (int k = 0; k < d; k++){
                dis_square += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
            }
            
            int sq = sqrt(dis_square + 0.5);
            if(dis_square == sq * sq)ans++;
        }
    }
    
    
    cout << ans << "\n";
    
    return 0;
}


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

using namespace std;

#define fi first
#define se second
#define pb push_back
#define sz(x) ((int) x.size())
#define all(x) (x).begin(), (x).end()
#define re return
#define mp make_pair
#define makeunique(x) sort(all(x)), x.resize(unique(all(x)) - x.begin())
#define endl '\n'

typedef pair<int, int> ii;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vll;
typedef vector<string> vs;

template <class T> T abs (T x) { re x > 0 ? x : -x; }
template <class T> T sqr (T x) { re x * x; }

const double pi = acos(-1.);
const ll inf = 1e18 + 7;
const int N = 3e5 + 17;

int n, m;
double g[1010][1010];
double x[1010], y[1010], r[1010];
double dist[1010];

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int x1, x2, y1, y2;
	cin >> x1 >> y1 >> x2 >> y2;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> x[i] >> y[i] >> r[i];
	}
	x[n] = x1, y[n] = y1;
	x[n + 1] = x2, y[n + 1] = y2;
	n += 2;
	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++) {
			double d = sqrt(sqr(x[i] - x[j]) + sqr(y[i] - y[j]));
			d = max(double(0), d - r[i] - r[j]);
			g[i][j] = d;
		}
	for (int i = 0; i < n; i++) dist[i] = inf;
	dist[n - 2] = 0;
	vi was(n);
	for (int z = 0; z < n; z++) {
		int best = -1;
		double cur = inf;
		for (int i = 0; i < n; i++)
			if (cur > dist[i] && !was[i]) {
				cur = dist[i];
				best = i;
			}
		was[best] = 1;
		for (int i = 0; i < n; i++)
			if (!was[i] && dist[i] > cur + g[best][i]) {
				dist[i] = cur + g[best][i];
			}
	}
	cout << setprecision(30) << dist[n - 1];
}

Measured memory_bytes: 11736
#include <bits/stdc++.h>
using namespace std;
 
#define FASTIO  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ll long long int
#define ld long double
#define vll vector<ll>
#define pll pair<ll,ll>
#define vl(p) vector<p>
#define W while
#define For(i,s,x) for(i=s;i<x;i++)
#define Fore(i,s,x) for(i=s;i<=x;i++)
#define FOR(i,x) for(i=0;i<x;i++)
#define Rof(i,s,x) for(i=s;i>=x;i--)
#define all(v) v.begin(),v.end()
#define it(r,v) for(auto r=v.begin();r!=v.end();r++)
#define pb push_back
#define in insert
#define sz size()
#define F first
#define S second
#define nl cout<<"\n"
#define pr(a) cout<<a<<" "
#define pr2(a,b) cout<<a<<" "<<b<<"\n"
#define pr3(a,b,c) cout<<a<<" "<<b<<" "<<c<<"\n"
#define mod 1000000007
#define mp make_pair

  int main()
  {
        string s,t;
        cin>>s;
        cin>>t;
        ll count=0,n=s.size();
        for(int i=0;i<n;i++)
        {
            if(s[i]!=t[i])
            count++;
        }
        cout<<count;
        
  }

Measured memory_bytes: 3908
// clang-format off
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979;
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
bool odd(const int &n) { return n & 1; }
bool even(const int &n) { return ~n & 1; }
template<typename T = int> T in() { T x; cin >> x; return x; }
template<typename T = int> T in(T &&x) { T z(forward<T>(x)); cin >> z; return z; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &x : v) is >> x; return is; }
template<typename A, typename B> istream &operator>>(istream &is, pair<A, B> &p) { return is >> p.first >> p.second; }
template<typename T> ostream &operator<<(ostream &os, const vector<vector<T>> &v) { int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "" : "\n"); return os; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "" : " "); return os; }
template<typename A, typename B> ostream &operator<<(ostream &os, const pair<A, B> &p) { return os << p.first << ' ' << p.second; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
// clang-format on

main {
  int n;
  cin >> n;
  while (n--) {
    string s;
    cin >> s;
    function<int(int)> dfs = [&](int i) -> int {
      if (isdigit(s[i])) return stoll(s.substr(i)) / 2 + 1;
      vector<int> v;
      for (int j = i, c = 0;; j++) {
        if (s[j] == '[') {
          if (c == 0) v.emplace_back(dfs(j + 1));
          c++;
        }
        if (s[j] == ']') {
          if (c == 0) break;
          c--;
        }
      }
      int s = 0;
      sort(all(v));
      rep(j, v.size() / 2 + 1) s += v[j];
      return s;
    };
    cout << dfs(1) << endl;
  }
}



Measured memory_bytes: 3228
#include<iostream>
#include<cstring>
#include<cstdio>
#include<set>
#include<map>
#include<algorithm>
using namespace std;
int n;
#define Maxn 200010
int a[Maxn];
int sum[31];
bool vis[Maxn];
int cnt=0;
set<int> s[Maxn];
map<int,int> mp;
int at[Maxn];
int to[Maxn][31];
int main(){
    int Ans=0;
    sum[0]=1;
    for(register int i=1;i<=30;++i)sum[i]=sum[i-1]*2;
    scanf("%d",&n); 
    for(register int i=1;i<=n;++i)scanf("%d",&a[i]);
    sort(a+1,a+n+1);
    for(register int i=1;i<=n;++i){
        if(!mp[a[i]])mp[a[i]]=++cnt;
        s[mp[a[i]]].insert(i);
        at[i]=mp[a[i]];
    }
    for(register int j=1;j<=30;++j){
        int zz=n;
        for(register int i=1;i<=n;++i){
            while(zz>=1&&a[i]+a[zz]>sum[j])zz--;
            if(zz>=1&&a[i]+a[zz]==sum[j])to[i][j]=at[zz];
        }
    }
    for(register int i=n;i>=1;--i)
        if(!vis[i]){
            vis[i]=true;
            s[mp[a[i]]].erase(i);
            for(register int j=1;j<=30;++j){
                int num=to[i][j];
                if(num&&s[num].size()){
                    int hehe=*(s[num].begin());
                    s[num].erase(hehe);
                    vis[hehe]=true;
                    Ans++;
                    break;
                }
            }
        }
    printf("%d\n",Ans);
    return 0;
}

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

#define int long long
#define pb push_back
#define f first
#define s second
#define all(container) container.begin(),container.end()

#define fast ios::sync_with_stdio(0); cin.tie(0)

int32_t main(){
  
    int n,k; cin >> n >> k;
    bool dislike[10] = {false};
    
    for(int i=1;i<=k;i++){
      int d; cin >> d;
      dislike[d] = true;
    }

    string s = to_string(n);
    int maxx_digit;

    for(int i=0;i<10;i++){
      if(!dislike[i]) maxx_digit = i;
    }

    for(int i=0;i<s.size();i++) s[i] = maxx_digit + 48;

    for(int i=s.size()-1;i>=0;i--){
      for(int j=0;j<10;j++){
        if(!dislike[j]){
          char temp = s[i];
          // cout << "j " << j << '\n';
          s[i] = j + 48;
          if(stoi(s)<n){
            s[i] = temp;
          }
          else break;
          // cout << "s = " <<./a s << '\n';
        }
      }
    }

    if(stoi(s)<n){
      vector<char> min_digit;
      for(int i=0;i<10;i++){
        if(!dislike[i]&&min_digit.size()!=2){
          min_digit.pb(i+48);
        }
      }

      s = string(s.size()+1,min_digit[0]);
      // cout << s;
      if(min_digit[0]=='0') s[0] = min_digit[1];

    }

    cout << s;

    return 0;
} 

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

using namespace std;

int dp[3001][3001];

int main(){
    string s, t;
    cin >> s >> t;
    for(int i=1;i<=s.size();i++){
        for(int j=1;j<=t.size();j++){
            if(s[i-1]==t[j-1]) dp[i][j] = 1 + dp[i-1][j-1];
            else{
                dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
            }
        }
    }
    string ans = "";
    int i = s.size(), j =t.size();
    while(i>0 && j>0){
        if(s[i-1]==t[j-1]) {ans = ans+s[i-1]; i--; j--;}
        else if(dp[i-1][j]>=dp[i][j-1]) i--;
        else j--;
    }
    reverse(ans.begin(), ans.end());
    cout << ans << endl; 
    return 0;
}

Measured memory_bytes: 38364
a = int(input())
ans = 1
flag = 0
d = list(map(int,input().split()))
if 0 in d:
    print(0)
else:    
    for i in d:
        ans *= i 
        if ans > 10**18:
            flag = 1
            break
        else:
            continue
    if flag == 0:
        print(ans)
    else:
        print(-1)

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

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

//#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define sz(x) ll(x.size())
//typedef pair<ll, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = LONG_LONG_MAX / 100;
//const ll INF = 1e15;
const ll MINF = LONG_LONG_MIN;
//const int INF = INT_MAX / 10;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)

bool contain(set<char> &s, int a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);


typedef priority_queue<long long, vector<long long>, greater<long long> > PQ_ASK;
const int mod = 1000000007;


int main() {

    while (true) {
        int m, f, r;
        cin >> m >> f >> r;

        int ma = max(m, 0);
        int fa = max(f, 0);

        if (m == -1 && f == -1 && r == -1) return 0;

        if (m == -1 || f == -1) cout << 'F' << endl;
        else if (m + f >= 80) cout << 'A' << endl;
        else if (m + f >= 65) cout << 'B' << endl;
        else if (m + f >= 50) cout << 'C' << endl;
        else if (m + f >= 30 && r >= 50) cout << 'C' << endl;
        else if (m + f >= 30) cout << 'D' << endl;
        else cout << 'F' << endl;
    }
}


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

class Main {
    static boolean binary(int key, int[] s) {
        int left = 0;
        int right = s.length;
        int mid = 0;
        int count = 0;
        while( left < right) {
            mid = (left + right)/2;
            if(s[mid] == key) {
            return true;
            }
             if (s[mid] > key) {
                 right = mid;
            } else {
                 left = ++mid;
            }
        }
        return false;
    }
    public static void main(String...args)throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int count = 0;
        int sSize = Integer.parseInt(br.readLine());
        String[] sStr = br.readLine().split(" ");
        int[] s = new int[sSize];
        for(int i = 0; i < sSize; i++) {
            s[i] = Integer.parseInt(sStr[i]);
        }

        int tSize = Integer.parseInt(br.readLine());
        String[] tStr = br.readLine().split(" ");

        for(int n = 0; n < tSize; n++) {
            int key = Integer.parseInt(tStr[n]);
            if(binary(key, s)) {
            count++;
            }             
            }
        System.out.println(count);
    }
}


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

long long gcd(long long t1,long long t2){
  if(t2==0) return t1;

  return gcd(t2,t1%t2);
}

//最小公倍数
long long lcm(long a,long b){
  long long lcm=gcd(a,b);

  return a/lcm*b;

}

int main(){
  int n;

  cin>>n;

  long long t[101];

  //1で初期化
  long long ans=1LL;
  
  for(int i=0;i<n;i++){
    cin>>t[i];

    ans=lcm(ans,t[i]);

  }

  cout<<ans<<endl;
  
  return 0;

}


Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
a.sort()
f=1
if n%2==0:
  for i in range(n):
    if i%2==0 and i+1!=a[i] or i%2==1 and i!=a[i]:
      f=0
      break
else:
  for i in range(n):
    if i%2==1 and i+1!=a[i] or i%2==0 and i!=a[i]:
      f=0
      break
if f==0:print(0)
else:
  ans=1
  for j in range(n//2):
    ans*=2
  print(ans%(10**9+7))

Measured memory_bytes: 14008
#include <stdio.h>

int main(void){
	int n[100];
	int a = 0;
	int m = 0;
	for(int i=0;i<100;++i){
		n[i] = 0;
	}
	while(scanf("%d", &a) != EOF){
		n[a-1]++;
	}
	for(int i=0; i<100; ++i){
		if(m < n[i]){
			m = n[i];
		}
	}
	for(int i=0; i<100; ++i){
		if(n[i] == m){
			printf("%d\n", i+1);
		}
	}
	return 0;
}

Measured memory_bytes: 0
#include <stdio.h>

int main(void){
    int A;
    long long B, N;
    double x;

    scanf("%d%lld%lld", &A, &B, &N);
    if(B <= N)
        x =  (double)(B - 1)/B;
    else
        x = (double)N/B;
    printf("%d\n", (int)(x*A));
    
    return 0;
}


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

int main()
{
	int k;
	cin >> k;
	string s;
	cin >> s;
	if(s.size() <= k)
		cout << s;
	else
	{
		rep(i,k)
			cout<<s[i];
		cout << "...";
	}
	//////////////////////////////////
	//--------end--------
	//
	return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stdio.h>
#include <stack>
#include <queue>
#include <deque>
#include <numeric>
#include<bits/stdc++.h>
#include <utility>

#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,a,b) for(int i = (a); (b) <= i; i--)
#define REP(i,n) for(int i = 0; i < (n); i++)
#define RREP(i,n) for(int i = n; n <= i; i--)
#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))
#define elif else if
#define MOD 1000000007
#define INF (1<<29)

using namespace std;
using ll = long long;
map <int ,int> mpa,mpb;
typedef pair<ll, ll> P;
priority_queue<P, vector<P>, greater<P>> pque;

const int MAX = 100010;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

// NのP乗をMで割った余りを返す
ll pow_mod(ll n,ll k,ll m){
  if(k==0){
    return 1;
  }else if(k%2==1){
    return pow_mod(n,k-1,m)*n%m;
  }else{
    ll t=pow_mod(n,k/2,m);
    return (t*t)%m;
  }
}

//(10*9*8)/(3*2*1);
//10*9*8 -> ansMul
//3*2*1 -> ansDiv
long calcComb(int a, int b) {
	if (b > a - b) return calcComb(a, a - b);


	long ansMul = 1;
	long ansDiv = 1;
	for (int i = 0; i < b; i++)
	{
		ansMul *= (a - i);
		ansDiv *= (i + 1);
		ansMul %= MOD;
		ansDiv %= MOD;
	}
	//ansMul / ansDivをやりたい
	//ansDivの逆元を使って求めよう！

	long ans = ansMul * pow_mod(ansDiv,MOD - 2,MOD);
	return ans;
}


int main(){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  vector<double> a;
  cin >> n;
  double t;
  for(int i=0;i<n;i++){
    cin >> t;
    a.push_back(t);
  }
  sort(a.rbegin(),a.rend());
  COMinit();
  int ans1=a[0],ans2=a[n];
  double cnt=a[0]/2.0;
  for(int i=0;i<n;i++){
    if(abs(a[i]-a[0]/2.0)<cnt){
      ans2=a[i];
      cnt=abs(a[i]-a[0]/2);
    }
  }
  printf("%d %d\n",ans1,ans2);
  return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
typedef pair<int, ll> il;
typedef vector<ii> vii;
typedef vector<il> vil;
typedef vector<li> vli;

#define F first
#define S second
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define sz size()
#define all(A)    A.begin(), A.end()
#define mem(a, b) memset(a, b, sizeof(a))
#define f0(i,b)   for(int i=0;i<(b);i++)
#define f1(i,b)   for(int i=1;i<=(b);i++)
#define f2(i,a,b) for(int i=(a);i<=(b);i++)
#define fr(i,b,a) for(int i=(b);i>=(a);i--)
#define rep(i,a,b,c) for(int i=(a);i!=(b);i+=(c))
#define mod 1000000007

#define forr(i,n)    for(i=0; i<n; i++)
#define whilee(i,t)  while(i!=t)
#define  sl(a)  scanf("%lld",&a)
#define  pl(a)  printf("%lld\n",a)

#define scan(x) do{while((x=getchar())<'0'); for(x-='0'; '0'<=(_=getchar()); x=(x<<3)+(x<<1)+_-'0');}while(0)
char _;

//for(auto it =A.begin(); it!=A.end(); it++)
//sort(A.begin(),A.end());
//binary_search(A.begin(),A.end(),x);
//reverse(A.begin(), A.end());
//cout << *max_element(A.begin(), A.end());
//cout << *min_element(A.begin(), A.end());
//count(A.begin(), A.end(), X); //counts the occurrences of X
//distance(A.begin(),A.end());  //distance between first to last element
//accumulate(A.begin(), A.end(), 0); //add
//next_permutation(A.begin(), A.end());
//prev_permutation(A.begin(), A.end());
//swap(S[0], T[0]);

//scanf("%d",&x);
//printf("%d\n",x);
//while (scanf("%d %d", &a, &b) == 2)
//printf("Case %d: %d\n", t++, a);

//vector <int> A;
//deque <int> A;
//queue <int> A;
//stack <int> A;
//set <int> A;
//map <int,int> A;
//pair <int,int> A ;
//vector <pair <int,int>> A ;
//bitset<32> bset1;
//char ch;
//string S, T, U;
ll i, j, k, a, b, c, d, f, g, h, l, m, n, p, q, r, s, t=1, u, v, w, x, y, z, maxx=INT_MIN, minn=INT_MAX, ans=0, sum=0, cnt=0;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);//NULL
    cout.tie(nullptr);//NULL

    //scan(n);
    cin>>n;
    ll A[n],B[n];
    forr(i,n)
    {
        cin>>A[i];
    }
    forr(i,n)
    {
        cin>>B[i];
        if(B[i]<A[i])
        {
            cnt+=A[i]-B[i];
        }
    }
    cout<<cnt<<endl;

    return 0;
}






Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string a,b;
  cin>>a;
  b="CODEFESTIVAL2016";
  int i,l,c=0;
    l=a.size();
    for(i=0;i<l;i++)
    {
        if(a[i]!=b[i])
            c++;
    }

    cout<<c<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#define REP(i,n) for(int i = 0; i < (int)n; i++)
using namespace std;

int main(){
  int n;
  cin >> n;
  int a[n+2];
  long long total = 0;
  a[0]=0;
  a[n+1]=0;
  REP(i,n){
    cin >> a[i+1];
    total += abs(a[i+1]-a[i]);
  }
  total += abs(a[n+1]-a[n]);
  REP(i,n){
    cout << total-abs(a[i+1]-a[i])-abs(a[i+1]-a[i+2])+abs(a[i+2]-a[i]) << endl;
  }
  return 0;
}


Measured memory_bytes: 1664
#include <iostream>
#include <string>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <ctime>
#include <cstdlib>


using namespace std;

int main() {
   
    int h,w;
    while (true) {
        cin >> h >> w;
        if(h == 0 and w == 0){
            break;
        }
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                if(i == 0 or i == h-1) {
                    cout << "#";
                }else if (j == 0 or j == w-1){
                    cout << "#";
                }else{
                    cout << ".";
                }
            }
            cout << endl;
        }
        cout << endl;
    }
}


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

int main(){
  int x;
  cin >> x;
  int ans;
  while (true){
    bool flag = false;
    for (int i = 2; i*i <= (int)(x); i++) {
      if (x % i == 0) flag = true;
    }
  if (flag == false) break;
  x++;
  }
  cout << x << endl;
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

using namespace std;

int main(){
  int N;
  cin >> N;
  map<int,int> aCnt;
  rep(i,N){
    int input;
    cin >> input;
    aCnt[input]++;
  }
  //iterator map_ite;
  int ans = 0;
  for( auto map_ite = aCnt.begin(); map_ite != aCnt.end(); map_ite++){
    //cout << map_ite-> first << ' ' << map_ite->second << endl;
    if(map_ite->first < map_ite->second) ans += map_ite->second - map_ite->first;
    else if(map_ite->first > map_ite->second) ans += map_ite->second;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4736
use std::io::Read;

fn main() {
    let mut buf = String::new();

    // 標準入力から全部bufに読み込む
    std::io::stdin().read_to_string(&mut buf).unwrap();

    //println!("{}", buf);

    let input = buf.trim();
    let x = match input {
        "SUN" => 7,
        "MON" => 6,
        "TUE" => 5,
        "WED" => 4,
        "THU" => 3,
        "FRI" => 2,
        "SAT" => 1,
        _ => 5,
    };
    println!("{}", x);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
int depth[510];
vector<int> edge[510];
int main(){
	int n,m;
	while(true){
		cin>>n>>m;
		if(n==0)	return 0;
		for(int i=0;i<510;i++)	edge[i].clear();
		for(int i=0;i<m;i++){
			int a,b;	cin>>a>>b;	a--;	b--;
			edge[a].push_back(b);
			edge[b].push_back(a);
		}
		for(int i=0;i<510;i++)	depth[i]=-1;
		depth[0]=0;
		queue<int> q;	q.push(0);
		set<int> ans;
		while(!q.empty()){
			int now=q.front();	q.pop();
			if(depth[now]>=2)	continue;
			for(int i=0;i<(int)edge[now].size();i++){
				int next=edge[now][i];
				if(depth[next]==-1){
					depth[next]=depth[now]+1;
					q.push(next);
					ans.insert(next);
				}
			}
		}
		cout<<ans.size()<<endl;
	}	
}

Measured memory_bytes: 1380
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll sq(ll num) { return num*num; }
ll mod_pow(ll x, ll n) {
	if (n == 0)return 1;
	if (n == 1)return x%MOD;
	ll res = sq(mod_pow(x, n / 2));
	res %= MOD;
	if (n % 2 == 1) {
		res *= x;
		res %= MOD;
	}
	return res;
}
ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

ll n,MA,MB;
ll a[41],b[41],c[41];

ll dp[41][501][501];

int main(){
	cin >> n >> MA >> MB;
	rep(i,n)cin >> a[i] >> b[i] >> c[i];
	rep(i,41)rep(j,501)rep(k,501)dp[i][j][k] = INF;
	dp[0][0][0] = 0;
	rep(i,n){
		rep(j,401){
			rep(k,401){
				dp[i+1][j+a[i]][k+b[i]] = min(dp[i][j][k]+c[i],dp[i+1][j+a[i]][k+b[i]]);
				dp[i+1][j][k] = min(dp[i][j][k],dp[i+1][j][k]);
			}
		}
	}
	ll ans = INF;
	for(int i = 1;;i++){
		if(i*max(MA,MB) >= 400)break;
		ans = min(ans,dp[n][i*MA][i*MB]);
	}
	if(ans == INF)cout << -1 << endl;
	else cout << ans << endl;
}

Measured memory_bytes: 80768