akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false);cin.tie(NULL)
using namespace std;
#define int long long
#define MOD 1000000007
typedef vector<int> vi;
typedef pair<int,int> pi;
#define inf 1e18
#define For(i,a,b) for (int i = a; i < b; i++)
#define Rep(i,a,b) for (int i = a; i <= b; i++)
#define ps(x,y) fixed << setprecision(y) << x 
#define pb push_back 
#define mp make_pair 

int b[25];
 
int32_t main()
{
    fast;
    int n, m, c, res = 0, sum = 0, val; cin >> n >> m >> c;
    For(i, 0, m) cin >> b[i];
    For(i, 0, n) {
        sum = 0;
        For(j, 0, m) {
            cin >> val;
            sum += val * b[j];
        }
        if(sum + c > 0) res++;
    }

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

Measured memory_bytes: 3620
n,l = gets.split(" ").map(&:to_i)

ary = [] 

n.times do |i|
  ary.push(l+i)
end

d = 10000
idx = 0

ary.size.times do |j|
  if ary[j].abs < d
    d = ary[j].abs 
    idx = j
  end
end

ary.delete_at(idx)
p ary.inject(:+)


Measured memory_bytes: 1788
n = int(input())
l = list(map(int, input().split()))

flg = True

if n > 1:
    for i in range(len(l)-1):
        if l[i+1] > l[i]:
            l[i+1] -= 1;

        if l[i+1] < l[i]:
            flg = False
            break

if flg == True:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 14252
#include<cmath>
#include<cstdio>
#include<vector>
using namespace std;
struct node
{
	int u, v, w;
	node(int _u, int _v, int _w):u(_u), v(_v), w(_w) {}
};
vector<node>ans;
inline int lowbit(int x) {return x&-x;}
int main()
{
	int L;
	scanf("%d", &L);
	for(int i=19;i>1;i--)
	{
		ans.push_back(node(i,i+1,0));
		ans.push_back(node(i,i+1,(1<<(20-i-1))));
	}
	while(L)
	{
		int p=int(log2(lowbit(L)));
		if(p==19)
		{
			ans.push_back(node(1,2,0));
			ans.push_back(node(1,2,1<<18));
		}
		else ans.push_back(node(1,20-p,L^lowbit(L)));
		L^=lowbit(L);
	}
	printf("%d %d\n",20,ans.size());
	for(int i=0;i<ans.size();i++)
		printf("%d %d %d\n",ans[i].u,ans[i].v,ans[i].w);
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define INF 1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define arr array
#define _min(a) *min_element(a.begin(), a.end());
#define _max(a) *max_element(a.begin(), a.end());
#define _sort(x) sort(x.begin(), x.end())
#define _rsort(x) sort(x.rbegin(), x.rend())
#define _reverse(x) reverse(x.begin(), x.end())
#define _debug(x) cout << #x << " = " << x << endl;
#define debug(x, y) cout << #x " = " << x << " " << #y << " = " << y << endl;
#define _lower_bound(a, x) lower_bound(a.begin(), a.end(), x) - a.begin()
#define _upper_bound(a, x) upper_bound(a.begin(), a.end(), x) - a.begin()
typedef long long ll;
using namespace std;

void solve() {	
	int n, ans = 0; cin >> n;
	vector<int> a(n); for (auto &u : a) cin >> u;
	_sort(a);
	for (int i = 0; i < n - 2; ++ i) {
		for (int j = i + 1; j < n - 1; ++j) {
			for (int k = j + 1; k < n; ++k) {
				if (a[i] == a[j] || a[j] == a[k]) continue;
				if (a[i] + a[j] > a[k]) {
					++ans;
				}
			}
		}
	}
	cout << ans << endl;
}   

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

    // int t; cin >> t;
    // while(t--) 
        solve();
}

Measured memory_bytes: 3656
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;



int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;

    int a = 4, b = 7;

    bool res = false;
    for (auto x : {a, b}) {
        if (n % x == 0 && n / x >= 2) {
            res = true;
            break;
        }
    }
    {
        for (int i = 0; i <= n / a; ++i) {
            for (int j = 0; j <= n / b; ++j) {
                if (i * a + j * b == n) {
                    res = true;
                }
            }
        }
    }

    if (res) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
    return 0;
}

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

using namespace std;
const int N = 2500 + 3, M = 5000 + 3, OO = 1.2e9;
int head[N], nxt[M], to[M], cost[M], n, ne;
int dist[N];
void init() {
    ne = 0;
    memset(head, -1, n * sizeof head[0]);
}
void addEdge(int u, int v, int c) {
    to[ne] = v;
    cost[ne] = c;
    nxt[ne] = head[u];
    head[u] = ne++;
}
vector<int> inCycle;
bool inQ[N];
int bellman() {
    memset(dist, '?', sizeof dist);
    dist[0] = 0;
    queue<int> q;
    q.push(0);
    bool edit = true;
    for (int i = 0; i <= n && q.size(); ++i) {
        edit = false;
        int sz = q.size();
        while (sz--) {
            int u = q.front();
            q.pop();
            inQ[u] = false;
            for (int e = head[u]; ~e; e = nxt[e]) {
                int v = to[e];
                if (dist[v] > dist[u] + cost[e]) {
                    edit = true;
                    dist[v] = min(OO, dist[u] + cost[e]);
                    if (i == n)
                        inCycle.push_back(u);
                    if (!inQ[v]++)
                        q.push(v);
                }
            }
        }
    }
    if (edit)
        return OO;
    return dist[n - 1];
}
bool vis[N];
bool go(int u) {
    if (u == n - 1)
        return true;
    if (vis[u]++)
        return false;
    for (int e = head[u]; ~e; e = nxt[e]) {
        int v = to[e];
        if (go(v))
            return true;
    }
    return false;
}
int main() {
#ifndef ONLINE_JUDGE
//	freopen("input.in", "r", stdin);
//	freopen("output.out", "w", stdout);
#endif
    int a,b;
    scanf("%d %d", &a, &b);

    if(abs(a-b) %2 == 0) {
        printf("%d\n", (a + b) / 2);
    } else{
        puts("IMPOSSIBLE");
    }
    return 0;
}


Measured memory_bytes: 256
// IO library
#include <cstdio>
#include <iomanip>
#include <ios>
#include <iostream>

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

// container library
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

// namespace
using namespace std;

// typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<VB> VVB;

// conversion
#define INT(c) static_cast<int>(c)
#define CHAR(n) static_cast<char>(n)
#define LL(n) static_cast<ll>(n)

// container
#define EACH(i, c) for (auto i = (c).begin(); i != (c).end(); i++)
#define SORT(c) sort((c).begin(), (c).end())
#define GSORT(c) sort((c).begin(), (c).end(), greater<decltype((c).front())>())
#define SZ(x) (INT((x).size()))
#define MEMSET(c, v) memset((c), v, sizeof(c))

// repetition
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define NREP(i, n) FOR(i, 1, n + 1)
#define RFOR(i, a, b) for (int i = (a); i >= (b); i--)
#define RREP(i, n) RFOR(i, n, 0)
#define RNREP(i, n) RFOR(i, n, 1)

// constant
// const ll MOD = 1e9 + 7;
// const int INF = 1<<25;
// const ll INF = 1LL<<50;
// const int dx[4] = {0, -1, 1, 0};
// const int dy[4] = {-1, 0, 0, 1};
// const int dx[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
// const int dy[8] = {-1, -1, -1, 0, 0, 1, 1, 1};

// debug
#define test(x) cout << #x << " = " << x << endl

// answer output
#define Yes(c) cout << ((c) ? "Yes" : "No") << endl;
#define YES(c) cout << ((c) ? "YES" : "NO") << endl;
#define yes(c) cout << ((c) ? "yes" : "no") << endl;

#define possible(c) cout << ((c) ? "possible" : "impossible") << endl;
#define POSSIBLE(c) cout << ((c) ? "POSSIBLE" : "INPOSSIBLE") << endl;


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


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

  int x;
  cin >> x;
  cout << (x < 1200 ? "ABC" : "ARC") << endl;
  return 0;
}

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

#define int long long

using namespace std;

int row , colum;

const int MOD=1e9+7;

int dp[1005][1005];

char a[1005][1005];

void init()
{
	for(int i=0 ; i<=row ; ++i)
	{
		for(int j=0 ; j<=colum ; ++j)
		{
			dp[i][j]=0;
		}
	}
	for(int i=1 ; i<=colum ; ++i)
	{
		if(a[1][i]=='.')dp[1][i]=1;
		else break;
	}
	for(int i=2; i<=row ; ++i)
	{
		if(a[i][1]=='.')dp[i][1]=1;
		else break;
	}
}

void dynamic()
{
	for(int i=1 ; i <= row ; ++i )
	{
		for(int j=1 ; j <= colum ; ++j )
		{
			if(a[i][j]=='#')continue;
			if(a[i-1][j]=='.'&&a[i][j-1]=='.')dp[i][j]=dp[i-1][j]%MOD+dp[i][j-1]%MOD;
			else if(a[i-1][j]=='.'&&a[i][j-1]=='#')dp[i][j]=dp[i-1][j]%MOD;
			else if(a[i-1][j]=='#'&&a[i][j-1]=='.')dp[i][j]=dp[i][j-1]%MOD;
		}
	}
	cout << dp[row][colum]%MOD<<endl;
}

main()
{
	cin >> row >> colum ;
	for( int i=1 ; i <= row ; ++i)
	{
		for( int j = 1; j<= colum ; ++j )
		{
			cin >> a[i][j];
		}
	}
	init();
	dynamic();
	
}



Measured memory_bytes: 12440
#define NODE 0
#define WEIGHT 1
#define COST_IDX 0
#define TIME_IDX 1
#define P_IDX 0
#define Q_IDX 1
#define R_IDX 2
#include <iostream>
#include <cstring>
using namespace std;

int n, m, k;
int weights[101][101][2];
int requests[200][3];

bool read_input() {
  cin >> n >> m;
  if (n*m == 0) 
    return false;
  memset(weights, 0, sizeof(int)*101*101*2);
  for (int i = 0; i < n; i++) {
    int a, b, c, t;
    cin >> a >> b >> c >> t;
    weights[a][b][COST_IDX] = weights[b][a][COST_IDX] = c;
    weights[a][b][TIME_IDX] = weights[b][a][TIME_IDX] = t;
  }
  cin >> k;
  for (int i = 0; i < k; i++) {
    cin >> requests[i][P_IDX] >> requests[i][Q_IDX] >> requests[i][R_IDX];
  }
  return true;
}

int resolve_request(int i_th) {
  int p, q, r;
  p = requests[i_th][P_IDX];
  q = requests[i_th][Q_IDX];
  r = requests[i_th][R_IDX];
  
  int weight_sum_map[101];
  int in_queue[101] = {}; // set all to 0
  memset(weight_sum_map, -1, sizeof(int)*101);
  
  /* starting node has weight_sum of 0 */
  weight_sum_map[p] = 0;
  in_queue[p] = 1;
  int current_node = p; // first in queue is p

  while (current_node != q) {
    int weight_sum = weight_sum_map[current_node];
    in_queue[current_node] = 0;
    
    for (int i = 1; i < 101; i++) {
      if (!weights[current_node][i][r]) 
	continue;
      int adj_node = i;
      int w = weights[current_node][adj_node][r];
      int new_weight_sum =  weight_sum + w;
      if (weight_sum_map[adj_node] == -1 || new_weight_sum < weight_sum_map[adj_node]) {
	weight_sum_map[adj_node] = new_weight_sum;
	in_queue[adj_node] = 1;
      }
    }
    
    int min_sum = -1;
    for (int i = 1; i < 101; i++) {
      if (in_queue[i] && (min_sum == -1 || weight_sum_map[i] < min_sum)) {
	min_sum = weight_sum_map[i];
	current_node = i;
      }
    }
  }
  return weight_sum_map[q];
}

void solve() {
  for (int i = 0; i < k; i++)
    cout << resolve_request(i) << endl;
}

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

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

using namespace std;

#define  CLR(a)  memset(a,0,sizeof(a))
#define  SET(a)  memset(a,-1,sizeof(a))
#define  nl "\n";
#define FIO ios_base::sync_with_stdio(false);cout.setf(ios::fixed);cout.precision(10);cout.tie(nullptr);cin.tie(nullptr);

int dx[] = { 0,0,1,-1,-1,-1,1,1 };
int dy[] = { 1,-1,0,0,-1,1,1,-1 };

template < class T> inline T biton(T n, T pos) { return n | ((T)1 << pos); }
template < class T> inline T bitoff(T n, T pos) { return n & ~((T)1 << pos); }
template < class T> inline T ison(T n, T pos) { return (bool)(n & ((T)1 << pos)); }
template < class T> inline T gcd(T a, T b) { while (b) { a %= b; swap(a, b); }return a; }

template <class T> inline T bigmod(T p, T e, T m) {
	T ret = 1;
	for (; e > 0; e >>= 1) {
		if (e & 1) ret = (ret * p) % m; p = (p * p) % m;
	} return (T)ret;
}

#define DEBUG

#ifdef DEBUG
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template < typename Arg1 >
void __f(const char* name, Arg1&& arg1)
{
	cerr << name << " is " << arg1 << std::endl;
}
template < typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args)
{
	const char* comma = strchr(names + 1, ',');
	cerr.write(names, comma - names) << " is " << arg1 << " | ";
	__f(comma + 1, args...);
}
#else
#define debug(...)
#endif

void solve()
{
	int n,k;
	cin>>n>>k;

	vector<long long> items(n);

	for(int i=0;i<n;i++){
		cin>>items[i];
	}

	sort(items.begin(),items.end());

	long long sum=0;

	for(int i=0;i<k;i++){
		sum+=items[i];
	}
	cout<<sum<<nl;
}

int main()
{
	FIO;

	int t = 1;

	while (t--)
	{
		solve();
	}

	return 0;
}


Measured memory_bytes: 3624
import math

n, d = map(int, input().split())
l = [list(map(int, input().split())) for i in range(n)]
c = 0
for i in range(n):
    for j in range(n):
        x = 0
        for k in range(d):
            x += (l[i][k] - l[j][k])**2
        y = math.sqrt(x)
        if y != 0 and y.is_integer():
            c += 1
print(c//2)

Measured memory_bytes: 9136
#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>

#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define mod 1000000007
#define inf 1e18+42
#define endl "\n"
#define pi 3.1415926535897932384626433832795028841971693993751058
#define maxn 100005

#define out1(a) cout<<#a<<" "<<a<<endl
#define out2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define out3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl

#define rep(i,a,b) for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)
#define fori(it,A) for(auto it=A.begin();it!=A.end();it++)

#define ft first
#define sd second
#define pb push_back
#define mp make_pair
#define pq priority_queue
#define all(x) (x).begin(),(x).end()
#define zero(x) memset(x,0,sizeof(x));
#define ceil(a,b) (a+b-1)/b
 
using namespace std;

int binpow(int a, int b) {
    int res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}

//START OF CODE ->->->->->->->

void solve()
{
    int x,a;
    cin>>x>>a;

    if ( x < a ){
        cout<<"0"<<endl;
    }
    else{
        cout<<"10"<<endl;
    }
}

//END OF CODE ->->->->->->->->

signed main()
{
    fast;
    int t = 1;
    // cin>>t;

    while(t--)
    {
        solve();
    }
    return 0;
}



Measured memory_bytes: 384
import java.io.*;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        int n_sqrt = (int)(Math.sqrt(n));
        for (int i = n_sqrt; i > 0; i--){
            if (n % i == 0){
                System.out.println((int)(Math.log10(n / i) + 1));
                break;
            }
        }
        
    }
}


Measured memory_bytes: 21972
using System;
using System.Collections.Generic;
using System.IO;
class Program
{
	static void Main(string[] args)
	{
		int N = int.Parse(Console.ReadLine());
		var list = new List<int[]>();
		int[] n0 = new int[N];
		list.Add(n0);
		var aaa = "abcdefghij";
		for(var i=1;i<N;i++){
			var list2 = new List<int[]>(list);
			list.Clear();
			foreach(var j in list2){
				int max = 0;
				for(var k=0;k<i;k++){
					max = Math.Max(max,j[k]);
				}
				for(var k=0;k<=max+1;k++){
					int[] n1 = new int[N];
					for(var l=0;l<i;l++){
						n1[l] = j[l];
					}
					n1[i] = k;
					list.Add(n1);
				}
			}
		}
var sw = new StreamWriter(Console.OpenStandardOutput()){AutoFlush = false};
		Console.SetOut(sw);
		for(var i=0;i<list.Count;i++){
			for(var j=0;j<N;j++){
          		//Console.Write(list[i][j]);
				Console.Write(aaa.Substring(list[i][j],1));
			}
			Console.WriteLine();
		}
Console.Out.Flush();
	}
}

Measured memory_bytes: 27584
# coding: utf-8
# Your code here!

a = list([0] * 100)

while True :
    try :
        a[int(input())-1] += 1
    except EOFError :
        break
    
x = max(a)
for i in range(100) :
    if a[i] == x :
        print(i+1)


Measured memory_bytes: 5600
# S_i=BかつS_i+1=Wのときにi番目とi+1番目の石を入れ替える操作に等しい。
# つまり各白石について自身よりも左側に黒石がいくつあるかを数えれば良い。
S = list(input())
# 入れ替え総数を数える変数です。
count = 0
# 黒石の数を数えておく変数です。
count_b = 0
for s in S:
  if s == 'B':
    count_b += 1
  else:
    count += count_b
print(count)

Measured memory_bytes: 4840
#include<iostream>
using namespace std;
int main() {
	int ki, co=0;
	while (1) {
		co = 0;
		cin >> ki;
		if (ki == 0) { break; }
		ki = 1000 - ki;
		if (ki >= 500) {
			ki = ki - 500;
			co++;
		}
		if (ki >= 100) {
			while(2){
				ki = ki - 100;
				co++;
				if (ki < 100) { break; }
			}
		}
		if (ki >= 50) {
			ki = ki - 50;
			co++;
		}
		if (ki >= 10) {
			while(2){
				ki = ki - 10;
				co++;
				if (ki < 10) { break; }
			}
		}
		if (ki >= 5) {
			ki = ki - 5;
			co++;
		}
		if (ki >= 1) {
			while(2){
				ki = ki - 1;
				co++;
				if (ki == 0) { break; }
			}
		}
		cout << co << endl;
	}
	return 0;
}

Measured memory_bytes: 2980
//inlclude before define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<type_traits>
#include<numeric>
#include<deque>
#include<iomanip>
#include<set>
#include<unordered_set>
#include<tuple>
#include<map>
#include<memory>

using namespace std;

//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef vector<double> VD;
typedef pair<int, int> P1;
typedef long long int ll;

//number
#define INF 1e9
#define NUM 1000000007

//itr
#define all(x) begin(x),end(x)

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

//max,min
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))

//function

/*ll gcd(ll a, ll b) {
	if (b == 0) return a;
	else return gcd(b, a%b);
}*/

/*ll lcm(ll a,ll b) {
	ll g = gcd(a, b);
	retur5n a * (b / g);
}*/

int dig(int a) {
	int sum = 0;
	while (a) {
		sum += a % 10;
		a /= 10;
	}
	return sum;
}

//grid template
int x[] = { -1, 0, 1, 0 };
int y[] = { 0,-1,0,1 };
int xx[] = { -1,-1,1,1 };
int yy[] = { 1,-1,1,-1 };

int main() {
	double a, b, c, d, e, n;
	cin >> n >> a >> b >> c >> d >> e;
	double ans = min({ a, b, c, d, e });

	cout << (ll)(ceil(n / ans) + 4) << endl;
	//cout << floor(n / ans) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,x,q,k;
    vector<int>v;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>x;
        v.push_back(x);
    }
    cin>>q;
    for(int i=0;i<q;i++)
    {
        cin>>k;
        vector<int>::iterator s;
        s=lower_bound(v.begin(),v.end(),k);
        cout<<s-v.begin()<<endl;
    }
    return 0;
}



Measured memory_bytes: 3544
#include <stdio.h>

int main(){
    int i, j, counter;
    char w[101];
    
    scanf("%s", w);
    for (i=0; w[i]!='\0'; i++) {
        
        if (w[i]!='A'){
            counter=1;
            for (j=i+1; w[j]!='\0'; j++){
                if (w[i] == w[j]) {
                    counter++;
                    w[j] = 'A';
                }
            }
            w[i] = 'A';
            if (counter % 2 == 1){
                printf("No\n");
                return 0;
            }
        }
    }
    
    printf("Yes\n");
    
    return 0;
}

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

using namespace std;
typedef long long ll;
const int MAXN = 1005;
const int MAXH = 2 * 10005;
const ll INF = 2e18;

ll dp[MAXN][MAXH];

struct magic {
  int damage, cost;
  magic(): damage(0), cost(0) {};
  magic(int d, int c): damage(d), cost(c) {};
};

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

  vector<magic> magics(n);
  for (int i = 0; i < n; ++i) {
    int a, b;
    cin >> a >> b;
    magics[i] = magic(a, b);
  }

  fill(dp[0], dp[0] + MAXN * MAXH, INF);

  dp[0][0] = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < MAXH; ++j) {
      if (j < magics[i].damage) {
	dp[i + 1][j] = dp[i][j];
      } else {
	dp[i + 1][j] = min(dp[i][j], dp[i + 1][j - magics[i].damage] + magics[i].cost);
      }
    }
  }

  ll ans = INF;
  for (int i = h; i < MAXH; ++i) ans = min(ans, dp[n][i]);
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 157820
#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define pb push_back
#define pint pair<int,int>
using namespace std;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n,m,x,y;	cin>>n>>m>>x>>y;
	int i,j,a[n],b[m];
	for(i=0;i<n;i++){
		cin>>a[i];
	}
	for(i=0;i<m;i++){
		cin>>b[i];
	}

	int z;
	for(z=x+1;z<=y;z++){
		for(i=0;i<n;i++){
			if(a[i]>=z)	break;
		}
		if(i<n)	continue;

		for(i=0;i<m;i++){
			if(b[i]<z)	break;
		}
		if(i==m)	break;
	}

	if(z<=y)	cout<<"No War\n";
	else	cout<<"War\n";

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long 
#define ld long double
#define pb push_back
#define vl vector
#define ff first
#define ss second
using namespace std;
int main()
{
    ll a,b,i,j,n,t;
    string s;
    cin>>s;
    if(s[0]==s[1] || s[1]==s[2] || s[2]==s[3]) cout<<"Bad";
    else cout<<"Good";
}

Measured memory_bytes: 3628
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    
    #nの素因数分解，[[a1,b1],[a2,b2]...]   aがb個,
    def factorization(n):
        if n==1:
            return [0,1]
        arr = []
        temp = n
        for i in range(2, int(-(-n**0.5//1))+1):
            if temp%i==0:
                cnt=0
                while temp%i==0:
                    cnt+=1
                    temp //= i
                arr.append([i, cnt])

        if temp!=1:
            arr.append([temp, 1])

        if arr==[]:
            arr.append([n, 1])

        return arr
    
    N=I()
    ans=1
    L=[0]*(N+1)
    for i in range(2,N+1):
        arr=factorization(i)
        for j in range(len(arr)):
            L[arr[j][0]]+=arr[j][1]
    
    for i in range(len(L)):
        ans*=(L[i]+1)
        ans%=mod
    print(ans)
    

main()


Measured memory_bytes: 41708
#include <bits/stdc++.h>
#define sz(arr) (int)arr.size()
#define all(arr) arr.begin(), arr.end()

using namespace std;
typedef long long ll;

void _cin() {}
template <class Head, class... Tail>
void _cin(Head&& head, Tail&&... tail) {
  cin >> head;
  _cin(forward<Tail>(tail)...);
}

#define Cin(T, ...) \
  T __VA_ARGS__;    \
  _cin(__VA_ARGS__)

int main() {
  Cin(string, s);

  set<char> st;
  for (auto e : s) st.insert(e);

  char ans = 'a';
  while (st.count(ans)) ans++;

  if (ans > 'z')
    puts("None");
  else
    cout << ans << endl;

  return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(a) (long long)((a).size())

int main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
    
    string s,t;
    cin>>s>>t;
    ll ns = sz(s);
    ll nt = sz(t);
    if(nt == ns+1)
    {
        ll f = 0;
        for(ll i=0;i<ns;i++)
        {
            if(s[i]!=t[i]) {f=1;break;}
        }
        if(f) cout<<"No";
        else cout<<"Yes";
     }
     else cout<<"No";
}


Measured memory_bytes: 3612
import heapq

n, m = [int(i) for i in input().split()]
inf = 10**10
path = [[0] * n for _ in range(n)]
Q = [[inf] * n for _ in range(n)]
ans = 0
pathnum = []

for i in range(m):
    a, b, c = map(lambda x: int(x)-1 ,input().split())    
    path[a][b] = path[b][a] = c+1
    pathnum.append((a,b))

for i in range(n):
    decided = [False for _ in range(n)]
    H = []
    Q[i][i] = 0
    heapq.heappush(H,(0,i))
    for _ in range(n):
        while True:
            k = heapq.heappop(H)
            k = k[1]
            if not decided[k]:
                decided[k] = True
                break
        for j in range(n):
            if path[k][j] == 0:
                continue
            if decided[j]:
                continue
            Q[i][j] = min(Q[i][k] + path[k][j], Q[i][j])
            heapq.heappush(H,(Q[i][j],j))

for i in pathnum:
    if Q[i[0]][i[1]] == inf:
        continue
    elif Q[i[0]][i[1]] != path[i[0]][i[1]]:
        ans += 1
print(ans)

Measured memory_bytes: 3572
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll a7=1000000007;
ll inf=1000000000000000;
typedef pair<ll,ll> l_l;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back


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

int main(){
    ll n;cin>>n;
    ll a[n];
    ll sum=0;
    rep(i,0,n-1){
        cin>>a[i];
        sum+=a[i];
    }
    ll ans=inf;
    ll tot=0;
    
    rep(i,0,n-2){
        tot+=a[i];
        ans=min(ans,abs(tot-(sum-tot)));
    }
    cout<<ans<<endl;
    
    
    return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;

#define BIG_NUM 2000000000

using namespace std;

bool strCmp(char* base, char* comp){
	int length1 = 0,length2 = 0;
	for(int i=0;base[i] != '\0'; i++)length1++;
	for(int i=0;comp[i] != '\0'; i++)length2++;
	if(length1 != length2)return false;

	for(int i=0;base[i] != '\0'; i++){
		if(base[i] != comp[i])return false;
	}
	return true;
}

int main(){

	char left[7],right[7];
	int left_num,right_len,maximum,first_check,limit,work[6],tmp,tmp_sum;
	int maximum_count;
	queue<int> ANS,TMP_ANS;

	while(true){
		scanf("%s %s",left,right);
		if(left[0] == '0' && right[0] == '0')break;

		if(strCmp(left,right)){
			printf("%s %s\n",left,right);
			continue;
		}

		left_num = 0;
		for(int i = 0; left[i] != '\0'; i++){
			left_num = 10*left_num + left[i] - '0';
		}

		first_check = 0;
		for(right_len = 0;right[right_len] != '\0';right_len++){
			first_check += right[right_len] - '0';
		}
		if(first_check > left_num){
			printf("error\n");
			continue;
		}else{
			if(right_len == 1){
				printf("%d %d\n",first_check,first_check);
				continue;
			}
		}

		maximum = -1;
		maximum_count = 0;

		limit = pow(2,right_len-1);

		while(!ANS.empty())ANS.pop();
		while(!TMP_ANS.empty())TMP_ANS.pop();

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

			for(int k = 0; k < right_len-1; k++){
				if(i & (1 << k)){
					work[k] = 1;
				}else{
					work[k] = 0;
				}
			}

			tmp = right[0] - '0';
			tmp_sum = 0;

			while(!TMP_ANS.empty())TMP_ANS.pop();

			for(int k = 1; k <= right_len-1;k++){
				if(work[k-1] == 0){
					tmp = 10*tmp + right[k] - '0';
					if(k == right_len-1){
						tmp_sum += tmp;
						TMP_ANS.push(tmp);
						if(tmp_sum > maximum && tmp_sum <= left_num){
							while(!ANS.empty())ANS.pop();
							while(!TMP_ANS.empty()){
								ANS.push(TMP_ANS.front());
								TMP_ANS.pop();
							}
							maximum = tmp_sum;
							maximum_count = 1;
						}else if(tmp_sum == maximum && tmp_sum <= left_num){
							maximum_count++;
						}
					}
				}else{
					tmp_sum += tmp;
					TMP_ANS.push(tmp);
					tmp = right[k] - '0';
					if(k == right_len-1){
						tmp_sum += tmp;
						TMP_ANS.push(tmp);
						if(tmp_sum > maximum && tmp_sum <= left_num){
							while(!ANS.empty())ANS.pop();
							while(!TMP_ANS.empty()){
								ANS.push(TMP_ANS.front());
								TMP_ANS.pop();
							}
							maximum = tmp_sum;
							maximum_count = 1;
						}else if(tmp_sum == maximum && tmp_sum <= left_num){
							maximum_count++;
						}
					}
				}
			}
		}

		if(maximum_count == 0){
			printf("error\n");
		}else if(maximum_count > 1){
			printf("rejected\n");
		}else{
			printf("%d",maximum);
			while(!ANS.empty()){
				printf(" %d",ANS.front());
				ANS.pop();
			}
			printf("\n");
		}
	}

	return 0;
}

Measured memory_bytes: 2856
#include<iostream>
#include<stack>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<iomanip>
#include<set>
#include<bitset>
#include<cmath>
#include<numeric>
#include<limits>
#include<functional>

#define REP(i, m, n) for(int i = (m); i < (n); i++)
#define rep(i,n) REP(i,0,n)
#define NIL -1
using namespace std;
typedef long long ll;
typedef long long int lli;
static const int MOD = 10000007;
static const int MAX = 100005;

// typedef priority_queue<int, greater<int>> RevQ;
int N, M;
string s;
multiset<int, greater<int>> P;

int gcd(int a, int b) {
  if ( b > a ) swap(a, b);
  int r = 1;
  while (r > 0) {
    r = a % b;
    a = b;
    b = r;
  }
  return a;
}

int main(){
  cin >> N >> M;
  rep(i,N) {
    int a; cin >> a;
    P.insert(a);
  }

  rep(i, M) {
    int x;
    x = *P.begin(); P.erase(P.begin());
    // cout << x << endl;
    x = x/2;
    P.insert(x);
  }

  lli sum = 0;
  for (auto it = P.begin(); it != P.end(); it++) {
    // cout << *it << endl;
    sum += *it;
  }
  cout << sum << endl;
  // rep(i,M) {
  //   sum += P.top(); P.pop();
  // }
  // cout << sum << endl;
}


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

using ll = long long;

int main() {
    int n; cin >> n;
    map<ll, ll> p;
    p[0] = 0;
    ll now = 0, ans = 0;
    for(int i = 1; i <= n; ++i) {
        ll d; cin >> d;
        now += d;
        if(p.count(now) == 0) p[now] = i;
        ans = max(ans, i - p[now]);
    }
    cout << ans << endl;
}



Measured memory_bytes: 15584
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#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 all(v) v.begin(),v.end()
#define pb push_back
#define eb emplace_back
template<class T>void chmax(T &a,T b){if(a<b)a=b;}
template<class T>void chmin(T &a,T b){if(a>b)a=b;}
constexpr int INF=1000000000000000000;
constexpr int mod=1000000007;
constexpr double eps=1e-8;
const double pi=acos(-1);
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int Random(int mi,int ma){
    random_device rnd;
    mt19937 mt(rnd());//32bit
    //[mi,ma]
    uniform_int_distribution<int>engine(mi,ma);
    return engine(mt);
}
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;
}
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;
}
vector<int>kaijo,invkaijo;
void init_fact(int n){
    kaijo.resize(n+1);
    invkaijo.resize(n+1);
    kaijo[0]=1;
    for(int i=1;i<=n;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=mod;
    }
    rep(i,n+1)invkaijo[i]=modpow(kaijo[i],mod-2);
}
int comb(int a,int b){
    if(a<b)return 0;
    if(a<0||b<0)return 0;
    return kaijo[a]*invkaijo[a-b]%mod*invkaijo[b]%mod;
}
int inv(int x){
    x=modpow(x,mod-2);
    return x;
}

signed main(){
    cin.tie(0);ios::sync_with_stdio(false);
    int n;
    cin>>n;
    int ans=0;
    for(int i=1;i<=n;i++){
        ans+=(n-1)/i;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3676
import numpy as np

N = int(input())
A = list(map(int, input().split()))

A = np.array(A)
MOD = 10**9 + 7

ruisekiwa = np.zeros(N, dtype='int')
for i in range(1, N):
    ruisekiwa[i] = ruisekiwa[i-1] + A[i]

res = 0
for i in range(N-1):
    # res += np.sum(np.mod(A[i] * A[i+1:], MOD))
    res += (ruisekiwa[N-1] - ruisekiwa[i]) % MOD * A[i] % MOD
print(res % MOD)

# FIXME TLE

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

using namespace std;
using ll = long long;
#define int ll
using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define PB push_back

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')';
  return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'[';
  REP(i, a.size()) {out<<a[i];if(i!=a.size()-1)out<<',';}
  out<<']';
  return out;
}

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};

class UnionFind {
public:
  const static int MAX_N = 100010;
  int par[MAX_N];
  int s[MAX_N];
  UnionFind() { init(); }
  UnionFind(int n) { init(n); }
  void init() { for(int i=0; i<MAX_N; ++i) par[i] = i, s[i] = 1; }
  void init(int n) { for(int i=0; i<n; ++i) par[i] = i, s[i] = 1; }
  int find(int x) {
    if(par[x] == x) return x;
    return par[x] = find(par[x]);
  }
  void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if(x == y) return;
    if(s[x] < s[y]) par[x] = y, s[y] = s[x] + s[y];
    else par[y] = x, s[x] = s[x] + s[y];
  }
  bool same(int x, int y) { return find(x) == find(y);}
};
UnionFind uf;

vector<PII> g[100010];
int d[100010];
void dfs(int x, int p, int dist) {
  d[x] = dist;
  for(auto e: g[x]) {
    if(e.first != p) dfs(e.first, x, dist + e.second);
  }
}

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

  while(true) {
    int n, m;
    cin >> n >> m;
    if(!n) break;

    REP(i, n) g[i].clear();
    memset(d, 0, sizeof(d));
    uf.init(n);

    vector<PII> query;
    VI ans(m+5);
    int idx = 0;
    REP(i, m) {
      char c;
      int a, b;
      cin >> c >> a >> b; a--, b--;
      if(c == '!') {
        int w; cin >> w;
        if(!uf.same(a, b)) {
          uf.unite(a, b);
          g[a].PB({b, -w});
          g[b].PB({a, w});
        }
      } else {
        query.PB({a, b});
        if(!uf.same(a, b)) ans[idx] = LLINF;
        idx++;
      }
    }

    // cout << query << endl;
    REP(i, n) {
      if(d[i] == 0) dfs(i, -1, 0);
      // cout << "i:" << i << endl;
    }
    // REP(i, n) cout << d[i] << " ";
    // cout << endl;

    REP(i, query.size()){
      if(ans[i]==LLINF) cout << "UNKNOWN" << endl;
      else cout << d[query[i].first] - d[query[i].second] << endl;
    }
  }

  return 0;
}



Measured memory_bytes: 18792
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  bool result =true;
  vector<int> data(n);
  for(int i=0;i<n;i++)
    cin >> data.at(i);
  
  for(int i=0;i<n;i++){
    if(data.at(i)!=i+1){
      data.at(i)=i+1;
      break;
    }
  }
  for(int i=0;i<n;i++){
    if(data.at(i)!=i+1){
      data.at(i)=i+1;
      break;
    }
  }
  for(int i=0;i<n-1;i++){
    if(data.at(i)>data.at(i+1))
      result = false;
  }

  if(result)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}

Measured memory_bytes: 256
s = input()
n = len(s)
def judge(string):
    k = len(string)
    flag = True
    for i in range(k//2):
        if string[i] != string[-i-1]:
            flag = False
            break
    return flag
s1 = s[:(n-1)//2]
s2 = s[(n+3)//2-1:]
if judge(s) and judge(s1) and judge(s2):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
// @author: arch_

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

array<array<long, 100 + 1>, 100> a, b, c;

int main(void) {
    int n, m, l;
    cin >> n >> m >> l;
    REP(i, n) REP(j, m) cin >> a[i][j];
    REP(i, m) REP(j, l) cin >> b[i][j];
    REP(i, n) REP(j, m) REP(k, l) c[i][k] += a[i][j] * b[j][k];
    REP(i, n) REP(j, l) cout << c[i][j] << (j < l - 1 ? ' ' : '\n');
    return 0;
}

Measured memory_bytes: 3332
import sys
import heapq
range = xrange
input = raw_input

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

A = [(int(x),1) for x in input().split()]

Acount = n
Asum = sum(a[0]*a[1] for a in A)

heapq.heapify(A)

# This is an online (n + m) log n solution using heaps

for _ in range(m):
    new_count,new_val = [int(x) for x in input().split()]
    new_pair = (new_val,new_count)
    
    # Try to add this new pair to A
    heapq.heappush(A, new_pair)
    Acount += new_count
    Asum += new_count * new_val

    # While there is too many elements in A
    while Acount>n:
        # Remove the ones with the smallest values

        old_pair = heapq.heappop(A)
        
        old_count = old_pair[1]
        old_val = old_pair[0]
        Acount -= old_count
        Asum -= old_count * old_val

        if Acount<n:
            count = min(n - Acount, old_count)
            
            heapq.heappush(A, (old_val, count))
            Acount += count
            Asum += count * old_val
	
    # print Asum # <-- online
print Asum

Measured memory_bytes: 48224
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0503
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;

int n, m;

int solve(vector<int>& v, int x) {
	int ret = 0;
	for (int i = 0; i < n;i++) {
		if (v[i] == 1) {
			ret += pow(3, n - 1 - i);
			x ^= 2;
		}
		else if (v[i] != x) {
			ret += 2 * pow(3, n - 1 - i);
		}
	}
	return ret;
}

int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	while (cin >> n >> m, n|| m) {
		vector<int> v(n);
		for (int i = 0; i < 3;i++) {
			int c; cin >> c;
			for (int j = 0; j < c; j++) { int x; cin >> x; v[x - 1] = i; }
		}
		int ans = min(solve(v, 0), solve(v, 2));
		cout << ((ans > m) ? -1 : ans) << endl;
	}
}

Measured memory_bytes: 3216
package main

import "fmt"

func main() {
	var q, h, s, d, n int
	fmt.Scan(&q, &h, &s, &d, &n)
	c := q * 4
	if h*2 < c {
		c = h * 2
	}
	if s < c {
		c = s
	}
	ans := 0
	if d < c*2 {
		ans = n / 2 * d
		if n%2 == 1 {
			ans += c
		}
	} else {
		ans = n * c
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
using namespace std;
int main() {
	int N, M;
	long long ans = 0;
	cin >> N >> M;
	vector<int> A(N), B(N);
	for(int i = 0; i < N; i++) {
		cin >> A[i] >> B[i];
	}
	vector<pair<int, int>> AB(N);
	for(int i = 0; i < N; i++) {
		//前の値からソート (A[i])
		AB[i] = make_pair(A[i], B[i]);
	}
	sort(AB.begin(), AB.end());
	for(int i = 0; i < N; i++){
		int buy = min(M, AB[i].second);
		ans += (long long)buy * AB[i].first;
		M -= buy;
	}
	cout << ans << endl;	
}

Measured memory_bytes: 1792
import java.util.*;

public class Main {    
    public static void main(String[] args){
        
        Scanner sc = new Scanner(System.in);
         
         int N = sc.nextInt();
         int L = sc.nextInt();
         
         String[] arr = new String[N];
         
         for(int i = 0;i < N;i++){
             arr[i] = sc.next();
         }
        
         Arrays.sort(arr);
        
         for(String s:arr){
             System.out.print(s);
         }
        
    }            
}
        
        

Measured memory_bytes: 23124
#include <iostream>

using namespace std;


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

    int a, b;
    cin >> a >> b;
    if (a + b == 15) {
        cout << "+" << endl;
    } else if (a * b == 15) {
        cout << "*" << endl;
    } else {
        cout << "x" << endl;
    }
    return 0;
}

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

int main() {
  int A,B,M;
  cin >> A >> B >> M;
  int rmin=114514;
  int wmin=114514;
  vector<int> R(A);
  vector<int> W(B);
  for(int i=0;i<A;i++){
    cin >> R.at(i);
    rmin=min(rmin,R.at(i));
  }
  
  for(int j=0;j<B;j++){
    cin >> W.at(j);
    wmin=min(wmin,W.at(j));
  }
  int r,w,C;
  int cost=rmin+wmin;
  for(int h=0;h<M;h++){
    cin >> r >> w >> C;
    cost = min(cost,R.at(r-1)+W.at(w-1)-C);
  }

  cout << cost << endl;
  
}



Measured memory_bytes: 1024
#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<bitset>
#include<string>
#include<cstdio>
#include<cctype>
#include<cassert>
#include<cstdlib>
#include<cstring>
#include<sstream>
#include<iostream>
#include<algorithm>

#define For(i,x,y) for (int i=x;i<y;i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define lf else if

#define dprintf(...) fprintf(stderr,__VA_ARGS__)
using namespace std;

typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> Vi;

int IN(){
	int c,f,x;
	while (!isdigit(c=getchar())&&c!='-');c=='-'?(f=1,x=0):(f=0,x=c-'0');
	while (isdigit(c=getchar())) x=(x<<1)+(x<<3)+c-'0';return !f?x:-x;
}

const int N=100000+19;

struct Edge{
	int y,nxt;
} E[N*2];
int las[N],F[N];
int n,cnt;

void Link(int x,int y){
	E[cnt]=(Edge){y,las[x]};las[x]=cnt++;
	E[cnt]=(Edge){x,las[y]};las[y]=cnt++;
}
bool dfs(int x,int fa){
	F[x]=1;
	for (int i=las[x],y;~i;i=E[i].nxt)
		if ((y=E[i].y)!=fa){
			if (!dfs(y,x)) return 0;
			F[x]-=F[y];
		}
	return F[x]>=0;
}

int main(){
	memset(las,-1,sizeof(las));
	n=IN();
	For(i,1,n) Link(IN(),IN());
	puts(dfs(1,-1)&&!F[1]?"Second":"First");
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
const int N=100;
char s[N];bool fl=0;int n;
int main(){
    scanf("%s",s+1);n=strlen(s+1);
    for(int i=1;s[i];i++){
        if((i&1)&&s[i]!='h')fl=1;
        if(!(i&1)&&s[i]!='i')fl=1;
    }
    if((n&1)||fl)puts("No");
    else puts("Yes");
    return 0;
}

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

int main() {
    int n;
    cin >> n;
    int a[n];
    rep(i, n) {
        cin >> a[i]; 
    }
    sort(a, a+n);

    if(a[n-1] == 0) {
        cout << "Yes" << endl;
        return 0;
    }
    else if(a[n-1] != 0) {
        if(n%3 != 0) {
            cout << "No" << endl;
            return 0;
        }
        else if(n%3 == 0) {
            int m = n/3;

            if(a[0] == 0) {
                if(a[m-1] == 0 && a[m] == a[n-1]) {
                    cout << "Yes" << endl;
                    return 0;
                }
                else {
                    cout << "No" << endl;
                    return 0;
                }
            }
            else if(a[0] != 0) {
                int x = a[0];
                int y = a[m];
                int z = x^y;
                
                if(a[m-1] == x && a[2*m-1] == y && a[n-1] == z) {
                    cout << "Yes" << endl;
                    return 0;
                }
                else {
                    cout << "No" << endl;
                    return 0;
                }
            }
        }
    }
}

Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int MOD = 1e9+7, MAX = 1e9, larg = 1e5, INF = -1e9;
long long A,B,C,D,E,F,G,H,I,J,K,L,N,M,O,P,Q,R,S,T,U,V,W,X,Y,Z;
long long max_value = INF, max_index = -1;
long long min_value = MAX, min_index = -1;
long long sum = 0;

typedef pair<int, int> Pa;
typedef long long ll;

int main() {
    cin >> N >> M;
    vector<int> switchs[10];
    int supply[10] = {};
    rep(i, M){
        cin >> K;
        rep(j, K){
            cin >> S;
            switchs[S-1].push_back(i);
        }
    }
    rep(i, M){
        cin >> P;
        supply[i] = P;
    }

    int count = 0;
    rep(i, pow(2, N)){
        int curr = i;
        int index = 0;
        int res_supply[10] = {};
        while(curr > 0){
            if(curr%2 == 1){
                rep(j, switchs[index].size()){
                    res_supply[switchs[index][j]]++;
                }
            }
            index++;
            curr /= 2;
        }
        rep(j, 10){
            if(supply[j] != res_supply[j]%2) break;
            if(j == 9) count++;
        }
    }
    cout << count;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cctype>

using namespace std;

inline int read()
{
	int x=0,f=1;
	char ch=getchar();
	while (!isdigit(ch)) f=ch=='-'?-1:f,ch=getchar();
	while (isdigit(ch)) x=x*10+ch-'0',ch=getchar();
	return x*f;
}

const int MAXH=200;
const int V=(MAXH<<1)+5;

int fa[V],deg[V]/*in - out*/,size[V];
bool sat[V];
int n,H;

int getfather(int son){return fa[son]==son?son:fa[son]=getfather(fa[son]);}

inline void addedge(int x,int y)
{
	--deg[x],++deg[y];
	int fx=getfather(x),fy=getfather(y);
	if (!size[fx]) size[fx]=1;
	if (!size[fy]) size[fy]=1;
	if (fx!=fy) fa[fy]=fx,size[fx]+=size[fy];
}

int main()
{
	//freopen("jigsaw.in","r",stdin),freopen("jigsaw.out","w",stdout);
	n=read(),H=read();
	for (int i=0;i<=H<<1;++i) fa[i]=i;
	for (int i=1,a,b,c,d;i<=n;++i)
	{
		a=read(),b=read(),c=read(),d=read();
		int l=(c?-c:a)+H,r=(d?d:-b)+H;
		addedge(l,r);
	}
	bool judge=1;
	for (int x=0;judge&&x<=H<<1;++x)
		if (x-H)
		{
			if (x-H<0) judge&=deg[x]>=0;
			else judge&=deg[x]<=0;
			sat[getfather(x)]|=deg[x];
		}
	for (int x=0;judge&&x<=H<<1;++x) if (x==getfather(x)&&size[x]) judge&=sat[x];
	printf(judge?"YES\n":"NO\n");
	//fclose(stdin),fclose(stdout);
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	static int N = 0;
	public static void main(String[] args) {
		Scanner reader = new Scanner(System.in);
		N = reader.nextInt();;
		reader.close();
		if (execute(0)) {
			System.out.print("Yes");
		} else { 
			System.out.print("No");
		}
	}
	public static boolean execute(int num) {
		if (num < N) {
			return execute(num + 4) || execute(num + 7);
		} else {
			return  (num == N);
		}
	}
}


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

int main () {
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i=0;i<N;i++) {
    cin >> a.at(i);
  }
  int count=0;
  for (int i=0;i<(N-1);i++) {
    for (int j=i+1;j<N;j++) {
      count+=a.at(i)*a.at(j);
    }
  }
  cout << count << endl;
  return 0;
}

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

using namespace std;

typedef long long ll;
ll n, l;
ll f(ll n){
  return n & -n;
}
struct Trie{
  struct Node{
    Node* ch[2];
    bool end;
    Node(){
      ch[0] = ch[1] = 0;
      end = 0;
    }
  };
  Node* root;
  Trie(){
    root = new Node();
  }
  void add(string s){
    Node* cur = root;
    for(int i = 0;i < s.size();i++){
      if(cur -> ch[s[i] - '0'] == 0){
        cur -> ch[s[i] - '0'] = new Node();
      }
      cur = cur -> ch[s[i] - '0'];
    }
    cur -> end = 1;
  }
  ll solve(Node* nd, int d = 0){
    if(nd -> end)
      return 0;
    ll res = 0;
    if(nd -> ch[0])
      res ^= solve(nd -> ch[0], d + 1);
    else
      res ^= f(l - d);
    if(nd -> ch[1])
      res ^= solve(nd -> ch[1], d + 1);
    else
      res ^= f(l - d);
    return res;
  }
};
vector<string> arr;
int main()
{

//  freopen("in.txt", "r", stdin);
//  freopen("out.txt", "w", stdout);
//  int f[101];
//  f[0] = 1;
//  for(int i = 1;i < 101;i++){
//    vector<int> arr;
//    int x = 0;
//    for(int j = 1;j <= i;j++){
//      x ^= f[i - j];
//      arr.push_back(x);
//    }
//    sort(arr.begin(), arr.end());
//    for(int j = 1;j < 102;j++){
//      if(arr[j - 1] != j){
//        cout << j << ' ' << ((i + 1) & -(i + 1)) << endl;
//        f[i] = j;
//        break;
//      }
//    }
//  }
//
//
//  return 0;
  Trie tr;
  cin >> n >> l;
  arr.resize(n);
  for(int i = 0;i < n;i++){
    cin >> arr[i];
//    if(i == 1)return 0;
    tr.add(arr[i]);
  }
  cout << (tr.solve(tr.root) ? "Alice" : "Bob");
  return 0;
}


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

int main() {
    int a, b, h, m; cin >> a >> b >> h >> m;

    double ang1 = (h * 60.0 + m)/ 720.0 * 360.0;
    double ang2 = m/60.0 * 360;
    double angBetween = abs(ang2 - ang1);

    cout << setprecision(20) << sqrt((a*a) + (b*b) - (2*a*b*cos(angBetween * M_PI / 180)));

    return 0;
}


Measured memory_bytes: 4196
#include <stdio.h>
#define max(a, b) a>b?a:b
#define INF 1010001000

int data[5001];

int main(void)
{
    int i, j, n, ans, tmp;
    while (scanf("%d", &n), n) {
        ans = -INF;
        for (i = 0; i < n; i++) {
            scanf("%d", &data[i]);
        }
        for (i = 0; i < n; i++) {
            tmp = 0;
            for (j = i; j < n; j++) {
                tmp += data[j];
                ans = max(ans, tmp);
            }
        }
        printf("%d\n", ans);
    }
    return 0;
}

Measured memory_bytes: 612
n = int(input())
w1 = input()
words = set([w1])
for _ in range(n-1):
    w2 = input()
    if (w2 in words) or (w2[0]!=w1[-1]):
        print("No")
        break
    else:
        words.add(w2)
        w1 = w2
else:
    print("Yes")

Measured memory_bytes: 3060