akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define mod 1000000007
using namespace std;


int main(void){
   int a,b,x;
   cin>>a>>b>>x;
   double PI=acos(-1);
   double y=(double)x/(double)a;
   double g;
   if(2*y<=a*b){
      g=atan2(b,2*y/b);
   }else{
      g=atan2(2*(a*b-y)/a,a);
   }
   cout<<fixed;
   cout<<setprecision(7)<<g/PI*180<<endl;
   return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
    int i,j,k,l;
    cin>>i>>j>>k>>l;
    int a,b,c,d;
    a=(i+l-1)/l;
    b=(j+k-1)/j;
    if(a>=b){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}


Measured memory_bytes: 3632
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		//Input Initialize
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str;
		str = br.readLine();
		int Nver = Integer.parseInt(str);
		int[] Ver = new int[Nver];
		for (int i = 0; i < Nver; i++) {
			Ver[i] = i + 1;
		}

		str =br.readLine();
		int Nhor = Integer.parseInt(str);

		for (int i = 0; i < Nhor; i++) {
			//Input swap
			str = br.readLine();
			String[] tmp = str.split(",", 0);
			int[] SW = new int[2];
			SW[0] = Integer.parseInt(tmp[0]);
			SW[1] = Integer.parseInt(tmp[1]);

			//Swap
			swap(Ver, SW[0], SW[1]);

		}

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

	private  static void swap(int[] N, int a, int b) {
		int tmp;
		tmp = N[a-1]; N[a-1] = N[b-1]; N[b-1] = tmp;
		return;
	}

}

Measured memory_bytes: 24176
package main

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

func main() {
	sc.Split(bufio.ScanWords)
	N := nextInt()
	cx, cy, ct := 0, 0, 0
	for i := 0; i < N; i++ {
		t, x, y := nextInt(), nextInt(), nextInt()
		if (t - ct) % 2 == (abs(x - cx) + abs(y - cy)) % 2 && (t - ct) >= (abs(x - cx) + abs(y - cy)) {
			ct = t
			cx = x
			cy = y
		} else {
			fmt.Println("No")
			return
		}
	}
	fmt.Println("Yes")
}

// -------- Library --------
func abs(x int) int {
	if x > 0 {
		return x
	} else {
		return -x
	}
}

var sc = bufio.NewScanner(os.Stdin)

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

func nextInt() int {
	v, err := strconv.Atoi(next())
	if err != nil {
		fmt.Println("Failed to read int", err)
		os.Exit(1)
	}
	return v
}

func nextIntArray(size int) []int {
	res := make([]int, size)
	for i := 0; i < size; i++ {
		res[i] = nextInt()
	}
	return res
}


Measured memory_bytes: 1792
/*
Author: CNYALI_LK
LANG: C++
PROG: c.cpp
Mail: cnyalilk@vip.qq.com
*/
#include<bits/stdc++.h>
#define debug(...) fprintf(stderr,__VA_ARGS__)
#define DEBUG printf("Passing [%s] in LINE %lld\n",__FUNCTION__,__LINE__)
#define Debug debug("Passing [%s] in LINE %lld\n",__FUNCTION__,__LINE__)
#define all(x) x.begin(),x.end()
using namespace std;
const double eps=1e-8;
const double pi=acos(-1.0);
typedef long long ll;
typedef pair<ll,ll> pii;
template<class T>ll chkmin(T &a,T b){return a>b?a=b,1:0;}
template<class T>ll chkmax(T &a,T b){return a<b?a=b,1:0;}
template<class T>T sqr(T a){return a*a;}
template<class T>T mmin(T a,T b){return a<b?a:b;}
template<class T>T mmax(T a,T b){return a>b?a:b;}
template<class T>T aabs(T a){return a<0?-a:a;}
#define min mmin
#define max mmax
#define abs aabs
ll read(){
	ll s=0,base=1;
	char c;
	while(!isdigit(c=getchar()))if(c=='-')base=-base;
	while(isdigit(c)){s=s*10+(c^48);c=getchar();}
	return s*base;
}
char WritellBuffer[1024];
template<class T>void write(T a,char end){
	ll cnt=0,fu=1;
	if(a<0){putchar('-');fu=-1;}
	do{WritellBuffer[++cnt]=fu*(a%10)+'0';a/=10;}while(a);
	while(cnt){putchar(WritellBuffer[cnt]);--cnt;}
	putchar(end);
}
ll xu[402424];
int main(){
#ifdef cnyali_lk
	freopen("c.in","r",stdin);
	freopen("c.out","w",stdout);
#endif
	ll n,a,b;
	n=read();b=read();a=read();
	if((a+b-1)>n||(a*b<n))printf("-1\n");
	else{
		ll s=0,t=n;
		while(s<n){
//			debug("Now%lld\n",s);
			if((t-b)>=a-1){
				for(ll i=1;i<=b;++i){
					xu[++s]=(t-b+i);
				}
				t-=b;
				--a;
			}
			else{
				for(ll i=1;i<=t-a+1;++i)xu[++s]=t-(t-a+1)+i;
				t=a-1;
				while(t){
					xu[++s]=t;
					--t;
					
				}
			}
		}
		for(ll i=1;i<=n;++i)printf("%lld%c",xu[i],i==n?'\n':' ');
	}

	return 0;
}



Measured memory_bytes: 4608
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
#define sqr(x) ((x)*(x))
#define mp make_pair
#define uint unsigned
#define PI pair<int,int>
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline int read(){
	int x = 0; char ch = gc(); bool positive = 1;
	for (; !isdigit(ch); ch = gc())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = gc())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(int a){
    if(a<0){
    	a=-a; putchar('-');
	}
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(int a){
    if(a<0){
    	a=-a; putchar('-');
	}
	write(a); puts("");
}
inline int rnd(int x){
	return (rand()<<16|rand())%x;
}
const int N=100005,mod=1000007;
int n,father[N],vis[N];
queue<PI> q;
ll ycl[N];
vector<int> v[N];
struct has_table{
	bool has[mod]; int b[mod];
	ll a[mod],v[mod];
	inline int insert(int xx,int yy){
		ll x=ycl[xx]*n+ycl[yy];
		for(int i=x%mod;;i=i+1==mod?0:i+1){
			if(!has[i]||a[i]==x){
				has[i]=1; a[i]=x; b[i]++; return b[i];
			}
		}
	}
	inline void clear(int xx,int yy){
		ll x=ycl[xx]*n+ycl[yy];
		for(int i=x%mod;;i=i+1==mod?0:i+1){
			if(!has[i]||a[i]==x){
				has[i]=1; a[i]=x; b[i]=0; return;
			}
		}
	}
	inline int find(int xx,int yy){
		ll x=ycl[xx]*n+ycl[yy];
		for(int i=x%mod;;i=i+1==mod?0:i+1){
			if(!has[i]||a[i]==x){
				return b[i];
			}
		}
	}
}Ma;
inline int getfather(int x){
	return father[x]==x?x:father[x]=getfather(father[x]);
}
int main(){
	srand(time(0));
	n=read();
	for(int i=1;i<=n;i++)ycl[i]=(ll)rand()<<32|rand();
    for(int i=1;i<=n*2-2;i++){
        int x=read(),y=read(); 
        v[x].push_back(y); v[y].push_back(x);
        Ma.insert(y,x);
        if(Ma.insert(x,y)==2)q.push(mp(x,y));
    }
    for(int i=1;i<=n;i++)father[i]=i;
    while(!q.empty()){
    	int x=q.front().first,y=q.front().second; q.pop();
		x=getfather(x); y=getfather(y); if(x==y){continue; return 0;}
		if(v[x].size()<v[y].size()) swap(x,y); 
		//cout<<x<<" "<<y<<endl;
		vis[y]=1;
        for(unsigned i=0;i<v[y].size();i++){ 
            int to=v[y][i]; if(vis[to])continue;
            //if(y!=3||to!=3)cout<<x<<" "<<y<<" "<<to<<" "<<er.find(y,to)<<endl;
            v[to].push_back(x);
            Ma.insert(x,to);
            if(Ma.insert(to,x)==2)q.push(mp(to,x));
            v[x].push_back(to);
        }
        father[y]=x; v[y].clear();
    }
    int ans=0;
    for(int i=1;i<=n;i++)ans+=father[i]==i;
    if(ans==1) puts("YES"); else puts("NO");
    return 0;
}

Measured memory_bytes: 30064
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define FOR(i, a, b) for (int i = a; i <= b; i++)
#define ROF(i, a, b) for (int i = a; i >= b; i--)
using namespace std;

using pii = pair<int, int>; using vpii = vector<pii>;
using vi = vector<int>; using vvi = vector<vi>;
using ll = long long;
using pll = pair<ll, ll>; using vpll = vector<pll>;
using vll = vector<ll>; using vvll = vector<vll>;

pii dx[4] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};

struct state{
    int d, k, x, y, dir;
    friend bool operator< (const state x, const state y) {
        if (x.d == y.d) return x.k < y.k;
        else return x.d < y.d;
    }
    friend bool operator> (const state x, const state y) {
        if (x.d == y.d) return x.k > y.k;
        else return x.d > y.d;
    }
};

inline bool operator!= (const state& x, const state& y) {
    return (x.d != y.d || x.k != y.k || x.x != y.x || x.y != y.y || x.dir != y.dir);
}

class comp {
    public:
        bool operator() (state x, state y) {
            return x > y;
        }
};

using vs = vector<state>; using vvs = vector<vs>; using vvvs = vector<vvs>;
const state INF = {0x3f3f3f3f, 0, 0, 0, 0};

int main() {
    int h, w, k; cin >> h >> w >> k;
    int sx, sy, ex, ey; cin >> sx >> sy >> ex >> ey; sx--, sy--, ex--, ey--;
    vector <vector <char> > a(h, vector <char> (w));
    FOR(i, 0, h - 1) FOR(j, 0, w - 1) cin >> a[i][j];
    priority_queue <state, vs, comp> pq;
    vvvs ans(h, vvs(w, vs(4, {INF})));

    auto ing = [&] (state x) {
        return (x.x >= 0 && x.x < h && x.y >= 0 && x.y < w);
    };

    FOR(i, 0, 3) {
        state u = {0, 0, sx, sy, i};
        pq.push(u);
        ans[sx][sy][i] = u;
    }
    while (!pq.empty()) {
        state u = pq.top(); pq.pop();
        if (!ing(u) || ans[u.x][u.y][u.dir] != u) continue;
        state v = u;
        v.x += dx[v.dir].fi, v.y += dx[v.dir].se, v.k++;
        if (v.k > k) v.d++, v.k -= k;
        if (ing(v) && a[v.x][v.y] == '.' && v < ans[v.x][v.y][v.dir]) {
            ans[v.x][v.y][v.dir] = v;
            pq.push(v);
        }
        v = u;
        FOR(i, 0, 3) {
            if (u.dir == i) continue;
            if (v.k != 0) v.d++;
            v.k = 0, v.dir = i;
            if (v < ans[v.x][v.y][v.dir]) {
                ans[v.x][v.y][v.dir] = v;
                pq.push(v);
            }
        }
    }
    state rt = INF;
    FOR(i, 0, 3) {
        if (ans[ex][ey][i] < rt)
            rt = ans[ex][ey][i];
    }
    if (rt.d == INF.d) cout << -1 << endl;
    else cout << rt.d + (rt.k != 0) << endl;
}

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

#define sz(a) int((a).size())
#define all(c) c.begin(), c.end()
#define ll long long
#define pb push_back
#define zoom                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define pl pair<ll, ll>
#define MOD 1000000007
#define endl "\n"
#define ff first
#define ss second
#define trace1(x) cerr << #x << ": " << x << endl
#define trace2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl
#define trace3(x, y, z) cerr << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl
#define trace4(a, b, c, d) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl
#define trace5(a, b, c, d, e) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl
#define trace(v)                                   \
    for (auto it = v.begin(); it != v.end(); it++) \
        cerr << *it << " ";                        \
    cerr << endl;
#define tr(container, it) \
    for (typeof(container.begin()) it = container.begin(); it != container.end(); it++)

#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
typedef vector<vi> vvi;

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

    vi v(n);
    multiset<int> s;
    map<int,int> m;
    forn(i,n){
        cin>>v[i];
        m[v[i]]++;
        s.insert(v[i]);
    }
    if(m.count(1)==1){
        if(m[1]>1){
            cout<<"0"<<endl;
            return;
        }else{
            cout<<"1"<<endl;
            return;
        }
    }
    ll ans=0;
    for(auto i:m){
        if(i.ss>1){
            continue;
        }
        ll temp=i.ff;
        auto it=s.find(temp);
        s.erase(it);
        bool is=true;
        for(int j=1;j*j<=temp;j++){
            if(temp%j==0){
                int temp1=temp/j;
                if(s.count(j)>=1){
                    is=false;
                    break;
                }

                if(s.count(temp1)>=1){
                    is=false;
                    break;
                }
            }
        }
        if(is)ans++;
        s.insert(temp);
    }

    cout<<ans<<endl;
}

int main()
{
    zoom;
    ll t=1;
    //cin >> t;

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

Measured memory_bytes: 22736
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		List<Point> list = new ArrayList<Point>();
		while(sc.hasNext()) {
			String[] s = sc.next().split(",");
			list.add(new Point(Double.parseDouble(s[0]), Double.parseDouble(s[1])));
		}
		sc.close();
		double s = 0;
		for(int i = 1; i + 1 < list.size(); i++) {
			s += area(list.get(0), list.get(i), list.get(i + 1));
		}
		System.out.println(s);
	}
	static double area(Point p1, Point p2, Point p3) {
		return Math.abs((p1.x - p3.x) * (p2.y - p3.y) - (p2.x - p3.x) * (p1.y - p3.y)) / 2.0;
	}
	static class Point{
		double x, y;
		Point(double x, double y){
			this.x = x;
			this.y = y;
		}
	}
}


Measured memory_bytes: 26080
N, M = map(int, input().split())
listF = []
for i in range(N):
    listF.append(list(map(int, input().split())))

listC = listF[0][1:]
for i in range(N-1):
    listC = list(set(listF[i+1][1:]) & set(listC))


print(len(listC))


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

int main(){
    int n,flag=false;
    cin>>n;
    for(int i=1;i<10;i++){
        for(int j=1;j<10;j++){
            if(i*j==n){
                flag=true;
                break;
            }
        }
        if(flag) break;
    }
    if(flag){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 256
from collections import defaultdict

N, M = map(int, input().split())
Hs = list(map(int, input().split()))
ABs = []
for _ in range(M):
    ABs.append(tuple(map(int, input().split())))

ans = 0
edges = defaultdict(list)
for u, v in ABs:
    if u > v:
        u, v = v, u
    if v not in edges[u]:
        edges[u].append(v)
        edges[v].append(u)

for e, neighbors in edges.items():
    heights = [Hs[neighbor - 1] for neighbor in neighbors]
    is_good = all(list(map(lambda x: Hs[e - 1] > x, heights)))
    if is_good:
        ans += 1

print(ans + len(set(range(1, N + 1)) - set(edges.keys())))


Measured memory_bytes: 131788
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <cstdio>
#include <ctime>
#include <assert.h>
#include <chrono>
#include <random>
#include <numeric>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
	return (ull)rng() % B;
}

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n; cin >> n;
	vector<ll> a(n);
	for(int i=0;i<n;i++){
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	//a.erase(unique(a.begin(), a.end()),a.end());
	int res=0;
	n=a.size();
	for(int i=0;i<n;i++){
		for(int j=i+1;j<n;j++){
			for(int k=j+1;k<n;k++){
				if(a[i]+a[j]>a[k]&&a[i]!=a[j]&&a[j]!=a[k]){
					res++;
					//cout << a[i] << " " << a[j] << " " << a[k] << endl;
				}
			}
		}
	}
	cout << res << endl;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
typedef long long ll;

int main() {
    int n; cin >> n;
    string s; cin >> s;
    int sum = 0;
    rep1(i,n){
        if(s[i] == 'E') sum++;
    }
    int ans = sum;
    rep(i,n-1){
        if(s[i] == 'W') sum++;
        if(s[i+1] == 'E') sum--;
        ans = min(ans,sum);
    }
    cout << ans << endl;
}

Measured memory_bytes: 900
a,b,k = map(int, input().split())
for i in range(k):
    if i%2==0:
        if a%2==1:
            a -= 1
        b += a//2
        a = a//2
    else:
        if b%2 == 1:
            b -= 1
        a += b//2
        b = b//2
print(a,b)
        

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define int long long   // aaaaaaaaaaaaaaaaaa
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define allr(x) (x).rbegin(),(x).rend()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define SIZE(buff) (sizeof(buff)/sizeof(buff[0]))
typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<pair<int,int>> VPII;
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
void chmin(int64_t& a, int64_t b){
    a = min(a, b);
}
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
template<typename T, typename U>ostream& operator << (ostream& os, pair<T, U>& pair_var)
{os << "(" << pair_var.first << ", " << pair_var.second << ")";return os;}
// head
int q,m,n,k,res,tmp,tmp2,tmp3;
int a[100001] = {};
int b[100010] = {};
int ans[100010] = {};
deque<PII> que;
string s;


signed main() {
	cin.tie(0);
    ios::sync_with_stdio(false);
	std::cin >>n>>m;
  res = 0;
  res += min(n,m/2);
  n-=res;m-=2*res;
  res += m/4;
  cout<<res<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define fr(i,j,n)   for(int i=j;i<(n);++i)
#define bk(i,j,n)   for(int i=j;i>n;--i)
#define mset(x,y) memset(x,y,sizeof(x))
#define pb push_back
#define pop pop_back
#define mod 1000000007
#define all(x) x.begin(),x.end()
#define inf 1e18
#define iosbase ios_base::sync_with_stdio(false); cin.tie(NULL);
#define F first
#define S second
#define bye return

int main()
{
    ll X,Y,a,b,c,i,j,ans=0,a1,n,v,s;
    cin>>X>>Y>>a>>b>>c;
    //ll A[a],B[b],C[c];
    vector<ll>A,B,C,V;
    fr(i,0,a)
    {
        cin>>a1;
        A.pb(a1);
    }
    fr(i,0,b)
    {
        cin>>a1;
        B.pb(a1);
    }
    fr(i,0,c)
    {
        cin>>a1;
        C.pb(a1);
    }

    sort(A.begin(),A.end(),greater<ll>());
    sort(B.begin(),B.end(),greater<ll>());

    for(i=0;i<X;i++)
    {
        C.pb(A[i]);
    }
    for(i=0;i<Y;i++)
    {
        C.pb(B[i]);
    }

    sort(C.begin(),C.end(),greater<ll>());

    for(i=0;i<X+Y;i++)
    {
        ans+=C[i];
    }

    cout<<ans<<endl;
    bye 0;
    
}

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

int main() {
	long n,k=0,l=0;
	cin>>n;
	long a[n];
	for(int i=0;i<n;i++)cin>>a[i];
	for(int i=0;i<n;i++){
		k+=a[i];
	}
	for(int i=0;i<n;i++)a[i]=max(n*a[i]-k,-n*a[i]+k);
	for(int i=0;i<n;i++){
		if(a[l]>a[i])l=i;
	}
	cout<<l<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,m,p,a[5010],b[5010],c[5010],f;
long long d[5010],oo=1e18;
int main(){
	cin>>n>>m>>p;
	for(int i=1;i<n;i++) d[i]=-oo;
	for(int i=0;i<m;i++)
		scanf("%d%d%d",&a[i],&b[i],&c[i]),c[i]-=p,a[i]--,b[i]--;
	for(int i=0;i<2*n;i++)
		for(int j=0;j<m;j++){
			if(d[a[j]]==-oo) continue;
			if(d[a[j]]+c[j]>d[b[j]]) d[b[j]]=i<n-1?d[a[j]]+c[j]:1e18;
		}
	cout<<(d[n-1]==1e18?-1:d[n-1]<0?0:d[n-1]);
	return 0; 
}

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

int main() {
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	long long x,y,a,b,c;
	cin>>x>>y>>a>>b>>c;
	vector<long long> arr(a);
	vector<long long> brr(b);
	vector<long long> crr(c);
	for(long long i=0;i<a;i++)
		cin>>arr[i];
	for(long long i=0;i<b;i++)
		cin>>brr[i];
	for(long long i=0;i<c;i++)
		cin>>crr[i];
	sort(arr.rbegin(),arr.rend());
	sort(brr.rbegin(),brr.rend());
	for(long long i=0;i<x;i++)
		crr.push_back(arr[i]);
	for(long long i=0;i<y;i++)
		crr.push_back(brr[i]);
	long long ans=0;
	sort(crr.rbegin(),crr.rend());
	for(long long i=0;i<x+y;i++)
		ans+=crr[i];
	cout<<ans;

	return 0;
}

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

using namespace std;

typedef long long ll;

ll n, A[100005], dp[100005];

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

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

    ll ans=0;
    for (int i=2; i<=n; i++)
    {
        if (A[i]>A[i-1])
            dp[i]=0;
        else
            dp[i]=dp[i-1]+1;
        ans = max(ans, dp[i]);
    }

    cout<<ans;
    return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>

int quicksort( int x[], int left, int right ) {
	
	int i, j, pivot, temp;
	
	i = left;
	j = right;
	
	pivot = x[(left+right)/2];
	
	while (1) {
	
		while ( x[i] < pivot ) { i++; }
		
		while ( pivot < x[j] ) { j--; }
		
		if ( i >= j ) { break; }
		
		temp = x[i];
		x[i] = x[j];
		x[j] = temp;
		
		i++;
		j--;
		
	}
	
	if ( left < i - 1 ) { quicksort( x, left, i - 1 ); }
	if ( j + 1 < right ) { quicksort( x, j + 1, right ); }
	
	return 0;
		
}

int main( void ) {

	int t, n, k, x[1000000], y[999999], i, j, sum;
	
	scanf( "%d", &t );
	
	for ( i = 0; i < t; i++ ) {
	
		scanf( "%d %d", &n, &k );
		
		sum = 0;
	
		for ( j = 0; j < n; j++ ) { scanf( "%d", &x[j] ); }
		for ( j = 0; j < n - 1; j++ ) { y[j] = x[j+1] - x[j]; }
	
		quicksort( y, 0, n - 2 );
		
		for ( j = 0; j < n - k; j++ ) { sum += y[j]; }
		
		printf( "%d\n", sum );
		
	}
	
	return 0;

}

Measured memory_bytes: 6876
import math

A,B,H,M = map(int, input().split())

hour = (H % 12) * 30 + (M / 2)
minu = M * 6

sa = abs(hour - minu)

rad = math.radians(sa)

Z = A**2 + B**2 - 2*A*B*math.cos(rad)

print(math.sqrt(Z))

Measured memory_bytes: 62480
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author champon
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1e18
#define ceill(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
#define sp << " " <<
ll mod = 1e9+7;
void ans(bool b, ostream& out=cout){ out << (b ? "Yes" : "No") << endl; }
void ans2(bool b, ostream& out=cout){ out << (b ? "YES" : "NO") << endl; }
template<typename T> inline bool chmax(T &a, T b){ if(a<b) a=b; return a<b; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a) a=b; return b<a; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){fill((T*)array, (T*)(array+N), val);}
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};

#ifndef INCLUDE_DEBUG_HPP
#define INCLUDE_DEBUG_HPP

class debug
{
public:
    template<typename T> void vdeb(T vec);
    template<typename T1, typename T2> void adeb(T1 *arr, T2 n);
    template<typename T> void mdeb(T mp);
};

#endif //INCLUDE_DEBUG_HPP

template<typename T> void debug::vdeb(T vec)
{
    cout << "#vector set debug" << endl;
    for(auto vv : vec) cout << vv << " ";
    cout << endl;
}

template<typename T1, typename T2> void debug::adeb(T1 *arr, T2 n)
{
    cout << "#adebug" << endl;
    for(int i=0; i<=n; i++) cout << arr[i] << " ";
    cout << endl;
}

template<typename T> void debug::mdeb(T mp)
{
    cout << "#map pair debug" << endl;
    for(auto const& m : mp) cout << m.first sp m.second << endl;
}
debug dbg;

class B754 {
public:
	void solve(std::istream& in, std::ostream& out)
	{
	    string s;
	    in >> s;
	    vector<int> nums;
	    for(int i=0; i<s.length(); i++){
	        nums.push_back(s[i]-'0');
	    }

	    int res = 100000;
	    int size = nums.size();
        for(int i=0; i<size-2; i++){
            int num = 100*nums[i] + 10*nums[i+1] + nums[i+2];
            chmin(res, abs(num-753));
        }
	    out << res << endl;
	}
};


int main() {
	B754 solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

using namespace std;

string s,t;
int dp[4000][4000];
int main()
{
    cin>>s>>t;

    int ls = s.length();
    int lt = t.length();

    for(int i = 1; i<=ls; i++){
        for(int j = 1; j<=lt; j++){
            if(s[i-1] == t[j-1]){
                dp[i][j] = dp[i-1][j-1] + 1;
            }

            dp[i][j] = max(dp[i][j],dp[i-1][j]);
            dp[i][j] = max(dp[i][j],dp[i][j-1]);

        }
    }

    int i = ls;
    int j = lt;
    string out;
    while(i>0 && j>0){
        if(dp[i][j] == dp[i-1][j]){
            i--;
        } else if(dp[i][j] == dp[i][j-1]){
            j--;
        } else {
            out = out + s[i-1];
            i--;
            j--;
        }
    }

    int lo = out.length();

    for(int i = lo-1; i>=0; i--){
        cout<<out[i];
    }

    cout<<endl;
    return 0;
}


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

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

    for(i=n-1;i>=1;i--)
    {
        cout<<a[i]<<" ";
    }
    cout << a[0] << endl;
    return 0;
 }



Measured memory_bytes: 3032
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	private class Node {
		int key;
		Node left, right, parent;
		public Node(int key) {
			this.key = key;
			left = right = parent = null;
		}
	}
	
	private class BST {
		Node rootNode;
		public BST() {
			rootNode = null;
		}

		public void insert(int key) {
			Node newNode = new Node(key);
			Node parent = null;
			Node current = rootNode;
			while (current != null) {
				parent = current;
				if (key < current.key) {
					current = current.left;
				} else {
					current = current.right;
				}
			}
			newNode.parent = parent;
			if (parent == null) {
				rootNode = newNode;
			} else if (key < parent.key) {
				parent.left = newNode;
			} else {
				parent.right = newNode;
			}			
		}
		
		public Node find(int key) {
			Node current = rootNode;
			while (current != null) {
				if (key == current.key) {
					return current;
				}
				if (key < current.key) {
					current = current.left;
				} else {
					current = current.right;
				}
			}		
			return null;
		}
		
		public void delete(int key) {
			
		}
		
		public void print() {
			printInOrder(rootNode);
			System.out.println("");
			printPreOrder(rootNode);
			System.out.println("");
		}

		private void printPreOrder(Node node) {
			if (node != null) {
				System.out.print(" " + node.key);
				printPreOrder(node.left);
				printPreOrder(node.right);
			}
		}

		private void printInOrder(Node node) {
			if (node != null) {
				printInOrder(node.left);
				System.out.print(" " + node.key);
				printInOrder(node.right);
			}
		}
	}
	
	public static void main(String[] args) throws IOException {
		new Main().run();
	}
	
	private void run() throws IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(reader.readLine());
		BST bst = new BST();
		for (int i = 0; i < n; i++) {
			String cmd = reader.readLine();
			if (cmd.startsWith("print")) {
				bst.print();
			} else {
				StringTokenizer st = new StringTokenizer(cmd);
				cmd = st.nextToken();
				int key = Integer.parseInt(st.nextToken());
				if (cmd.equals("insert")) {
					bst.insert(key);
				} else if (cmd.equals("find")) {
					if (bst.find(key) != null) {
						System.out.println("yes");
					} else {
						System.out.println("no");
					}
				} else {
					bst.delete(key);
				}
			}
		}
		reader.close();
	}
}



Measured memory_bytes: 130868
#include <stdio.h>
int main(void) {
	int n,i;
	while(scanf("%d",&n)!=EOF){
		int p[100];
		for(i=0;i<n;i++){
			scanf("%d",&p[i]);
		}
		int j,tmp;
		for(j=n-1;j>0;j--){
			for(i=0;i<j;i++){
				if(p[i]>p[i+1]){
					tmp=p[i];
					p[i]=p[i+1];
					p[i+1]=tmp;
				}
			}
		}
		int q[100];
		q[0]=p[0];
		for(i=1;i<n;i++){
			q[i]=q[i-1]+p[i];
		}
		int sum=0;
		for(i=0;i<n;i++){
			sum=sum+q[i];
		}
		printf("%d\n",sum);
	}
	return 0;
}



Measured memory_bytes: 1920
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
using namespace std;
static_assert(sizeof(long) >= 8, "sizeof(long) >= 8");
struct P { int x, y; } p[200000];
constexpr double pi = acos(-1);
int main() {
    int x1, y1, x2, y2, n;
    scanf("%d %d %d %d %d", &x1, &y1, &x2, &y2, &n);
    if (x1 > x2) {
        swap(x1, x2);
        swap(y1, y2);
    }
    int m = 0;
    for (int i = 0; i < n; i++) {
        int x, y;
        scanf("%d %d", &x, &y);
        if (x < x1 || x > x2 || y < min(y1, y2) || y > max(y1, y2))
            continue;
        if (y1 > y2)
            y = 99999999 - y;
        p[m++] = P { x, y };
    }
    if (y1 > y2)
        y1 = 99999999 - y1, y2 = 99999999 - y2;
    sort(p, p + m, [](P lhs, P rhs) { return lhs.y < rhs.y; });
    std::vector<int> v;
    for (int i = 0; i < m; i++) {
        auto it = lower_bound(v.begin(), v.end(), p[i].x);
        if (it == v.end())
            v.push_back(p[i].x);
        else
            *it = p[i].x;
    }
    double ans = (x2 - x1 + y2 - y1) * 100.0 - v.size() * (20 - 5 * pi);
    if ((int) v.size() == min(x2 - x1, y2 - y1) + 1)
        ans += 5 * pi;
    printf("%.15f\n", ans);
}


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

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

    int n = s.size();
    bool ok = true;
    rep (i, n / 2)
        if (s[i] != s[n - 1 - i])
            ok = false;
    rep (i, (n - 1) / 2 / 2)
        if (s[i] != s[(n - 1) / 2 - 1 - i])
            ok = false;
    for (int i = (n + 3) / 2 - 1, cnt = 0; i < n; i++, cnt++)
        if (s[i] != s[n - 1 - cnt])
            ok = false;

    if (ok)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

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

#define F first
#define S second
#define all(x) x.begin(), x.end()

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;
 
const int Maxn = 52;
const ll Inf = LONG_LONG_MAX >> 2;
const int Log = 23;
const ll Mod = 10133;

ll mul(ll a, ll b){
	return (a * b) % Mod;
}
ll bin_pow(ll b, ll p){
	ll res = 1;
	for(ll pw = b, j = 1; j <= p; j <<= 1, pw = mul(pw, pw)) if(p & j) res = mul(res, pw);
	return res;
}
ll inv(ll x){
	return bin_pow(x, Mod - 2);
}

ll f(ll n, ll b){
	if(n) return f(n / b, b) + (n % b);
	return 0;
}
int Sqrt = 1000000;

int main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	ll n, s;
	cin >> n >> s;
	if(n == s) return cout << n + 1, 0;
	ll ans = Inf;
	//if(n % s == 0){
		//if(n / s > s) ans = min(ans, n / s);
	//}
	for(int i = 2; i <= Sqrt; i++) if(f(n, i) == s) ans = min(ans,(ll) i);
	ll fd, B;
	for(int sd = 1; sd <= Sqrt; sd ++){
		fd = s - sd;
		if(fd < 0) continue;
		if((n - fd) % sd == 0){
			B = (n - fd) / sd;
			if(B > max((ll) sd, fd)) ans = min(ans, B);
		}
	}
	if(ans == Inf) cout << -1;
	else cout << ans;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
#define LL long long int
using namespace std;
int main()
{
	string s,t;
	cin>>s;
	cin>>t;
	LL ans=0;
	for(LL i=0; i<s.length(); i++)
	{
		if(s[i]!=t[i])
		ans++;
	}
	cout<<ans<<'\n';

}


Measured memory_bytes: 3828
#include<stdio.h>
int ta[10010],to[60010],nt[60010],id[10010],cmp[100010],r=0,f[10010]={0};
int a[10010],b[10010],c[10010],q[10010];
  int Ta[110],To[1010],Co[1010],Nt[1010];
void sdfs(int e,int s,int k){
  int i;
  f[s]++;
  for(i=ta[s];i+1;i=nt[i]){
    if(i<e&&k<0&&f[to[i]]==0||i>=e&&k>=0&&f[to[i]]==1)sdfs(e,to[i],k);
  }
  k<0?(id[r++]=s):(cmp[s]=k);
}
void scc(int v,int e,int *a,int *b){
  int i,k;
  for(i=0;i<v;i++)ta[i]=-1;
  for(i=0;i<e;i++){
    nt[i  ]=ta[to[i+e]=a[i]];
    nt[i+e]=ta[to[i  ]=b[i]];
    ta[a[i]]=i;
    ta[b[i]]=i+e;
  }
  for(i=0;i<v;i++)f[i]=0;
  for(i=k=0;i<v;i++){
    if(f[i]==0)sdfs(e,i,-1);
  }
  for(i=r;i;i--){
    if(f[id[i-1]]==1)sdfs(e,id[i-1],id[i-1]);
  }
  }//*/
int mca(int v,int e,int k,int *a,int *b,int *c){
  int i,j,t,r,s,p=0;
  int bk[110]={0};
  int mi[110];
  for(i=0;i<v;i++)Ta[i]=mi[i]=-1;//??£??\??????????????????
  for(i=0;i<e;i++){
    Nt[i]=Ta[a[i]];
    To[i]=b[i];
    Co[Ta[a[i]]=i]=c[i];
    bk[a[i]]=bk[b[i]]=1;
  }
  for(i=0;i<v;i++)p+=bk[i];
  /*for(i=0;i<v;i++){
    printf("%d:",i);
    for(j=Ta[i];j+1;j=Nt[j])printf("%d ",To[j]);
    printf("\n");
    }printf("\n");//*/
  for(i=0;i<e;i++){//?????????MIN???????±???????
    if(mi[To[i]]==-1||Co[mi[To[i]]]>c[i])mi[To[i]]=i;
  }
  mi[k]=-1;
  /*for(i=0;i<v;i++)if(mi[i]+1)printf("%d %d %d\n",i,mi[i],Co[mi[i]]);
  printf("\n");
  for(i=0;i<v;i++){
    printf("%d:",i);
    for(j=Ta[i];j+1;j=Nt[j]){
      if(mi[To[j]]==j)printf("%d ",To[j]);
    }
    printf("\n");
    }printf("\n");//*/
  q[t=0]=k;
  for(r=1;r-t;t++){
    for(j=Ta[q[t]];j+1;j=Nt[j]){
      if(mi[To[j]]==j)q[r++]=To[j];
    }
  }
  //printf("n%d r%d\n",p,r);
  if(r==p){
    for(i=s=0;i<e;i++){
      if(mi[To[i]]==i)s+=Co[i];
    }
    return s;
  }//printf("d\n");
  for(i=r=0;i<v;i++){
    bk[i]=0;
    for(j=Ta[i];j+1;j=Nt[j]){
      if(mi[To[j]]-j)continue;
      a[r]=i;
      b[r++]=To[j];
    }
  }
  //for(i=0;i<r;i++)printf("%d %d\n",a[i],b[i]);printf("\n");
  scc(v,r,a,b);//?????£?????????????§£??§???????????????????????????
  //for(i=0;i<v;i++)printf("%d %d\n",i,cmp[i]);printf("\n");
  for(i=0;i<v;i++)bk[cmp[i]]++;
  // for(i=0;i<v;i++)printf("%d %d\n",i,bk[i]);printf("\n");
  for(i=r=s=0;i<v;i++){//printf("%d %d:",i,cmp[i]);
    for(j=Ta[i];j+1;j=Nt[j]){
      a[r]=cmp[i];
      b[r]=cmp[To[j]];//printf("%d %d %d %d ",To[j],b[r],bk[b[r]]-1,Co[j]);
      //if(bk[a[r]]-1){
      if(a[r]==b[r]){
	if(j==mi[To[j]])s+=Co[j];
      }
      //else c[r++]=co[j];
      //}
      else c[r++]=bk[cmp[To[j]]]-1?Co[j]-Co[mi[To[j]]]:Co[j];
    }//printf("\n");
  }
  //printf("s%d r%d\n",s,r);
  //printf("\n");
  //for(i=0;i<r;i++)printf("%d %d %d\n",a[i],b[i],c[i]);printf("\n");
  return mca(v,r,k,a,b,c)+s;
}
	 
int main(){
  int n,m,k,i;
  scanf("%d %d %d",&n,&m,&k);
  for(i=0;i<m;i++)scanf("%d %d %d",&a[i],&b[i],&c[i]);
  printf("%d\n",mca(n,m,k,a,b,c));
  return 0;
}

Measured memory_bytes: 680
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 200010
#define INF 1000000005
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define IN(a) cin>>(a)
#define OUT(a) cout<<(a)<<endl
typedef pair<int,int> P;
const int MAX = 1000005;
const int MOD = 1000000007;

int main(){
    string s;
    cin>>s;
    if(s=="ARC"){
        OUT("ABC");
    }else{
        OUT("ARC");
    }
    return 0;
}

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

const int mod = 1000000007;
int dp[100005][2];

int main() {
  string s;
  cin >> s;
  int n = s.size();
  dp[0][0] = 1;
  rep(i,n) {
    { // a+b = 0
      if (s[i] == '0') {
        dp[i+1][0] += dp[i][0];
        dp[i+1][1] += dp[i][1];
      } else {
        dp[i+1][1] += (dp[i][0] + dp[i][1]) % mod;
      }
    }
    { // a+b = 1
      if (s[i] == '0') {
        (dp[i+1][1] += dp[i][1]*2 % mod) %= mod;
      } else {
        (dp[i+1][0] += dp[i][0]*2 % mod) %= mod;
        (dp[i+1][1] += dp[i][1]*2 % mod) %= mod;
      }
    }
  }
  int ans = (dp[n][0]+dp[n][1]) % mod;
  cout << ans << endl;
  return 0;
}    


Measured memory_bytes: 1280
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <set> 
#include <map>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstring>
#include <iomanip>
#define REP(i,n) for(int i=0; i<(n); ++i)
#define FOR(i,a,b) for(int i=(a); i<(b); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const ll INFLL = 1001001001001001001;  // > 10^18
const int MOD = (int)1e9 + 7;
const ll MODLL = (ll)1e9 + 7;
const double EPS = 1e-9;

int main () {

    ll l,r; cin >>l>>r;

    ll res = 2019;
    for (ll i = l ; i < min(l+(3*2019), r); i++) {
        for (ll j = i + 1; j <= min(l+(3*2019), r); j++) {
            if (res > ((i*j) % 2019)) {
                res = (i*j) % 2019;
            } 
        }
    }

    cout << res << endl;
    return 0;
}



Measured memory_bytes: 384
/**
  * @brief atcoder
  * @author yao
  */
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <utility>
#include <algorithm>
#include <functional>
#include <climits>
#define ft first
#define sd second
#ifdef DBG
#   define dbg_pri(x...) fprintf(stderr,x)
#else
#   define dbg_pri(x...) 0
#   define NDEBUG
#endif //DBG
#include <cassert>

typedef unsigned int uint;
typedef long long int lli;
typedef unsigned long long int ulli;

#define N 262144
#define M 1048576
#define K 67108864
#define P 0xa53f309b5c65e11dull

char buf[N+M];
char *ss[N];
int nss[N];
class HashTable {
public:
    std::pair<uint,int> data[K];
    int& operator[](ulli k)
    {
        k *= P;
        int pos = k%K;
        while(data[pos].ft && data[pos].ft!=(uint)(k>>32)) pos = (pos+1) % K;
        data[pos].ft = k>>32;
        return data[pos].sd;
    }
}lu;
ulli hashs[N];
int cnt[128];

int main()
{
    int n;
    scanf("%d", &n);
    char *p = buf;
    for(int i=0;i<n;++i)
    {
        scanf("%s", p), nss[i] = strlen(p);
        ss[i] = p, p += nss[i] + 1;
    }
    for(int i=0;i<n;++i)
        dbg_pri("poi 3: %s\n", ss[i]);
    for(int i=0;i<n;++i)
    {
        for(int j=0;j<nss[i];++j)
            ++cnt[ss[i][j]];
        ulli x = 0;
        for(int j=nss[i]-1;j>=0;--j)
        {
            x = x * P;
            for(int k='a';k<='z';++k)if(cnt[k])
            {
                ++lu[x^k];
                dbg_pri("poi 1: %c %s %016llx\n", (char)k, ss[i]+j+1, x^k);
            }
            x^=ss[i][j];
            --cnt[ss[i][j]];
        }
        hashs[i] = x;
        dbg_pri("poi 2: %s %016llx\n", ss[i], x);
    }
    lli ans = 0;
    for(int i=0;i<n;++i) ans += lu[hashs[i]];
    ans -= n;
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 529800
#include <bit>
#include <bitset>
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <stdlib.h>
#include <queue>
#include <stack>


typedef long double ld;
typedef long long ll;

using namespace std;

vector<vector<pair<int, int> > > a;
int n;

int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		vector<pair<int, int> > cur;
		int t;
		cin >> t;
		for (int j = 0; j < t; j++) {
			int v, b;
			cin >> v >> b;
			v--;
			cur.push_back(make_pair(v, b));
		}
		a.push_back(cur);

	}

	int ret = 0;
	for (int mask = 0; mask < (1 << n); mask++) {
		bool ok = true;
		for (int i = 0; i < n; i++) {
			if (mask & (1 << i)) {
				for (int j = 0; j < a[i].size(); j++) {
					int val = 0;
					if (mask & (1 << a[i][j].first)) {
						val = 1;
					} 
					if (val != a[i][j].second) {
						ok = false;
					}
				}
			}
		}
		if (ok) {
			ret = max(ret, __builtin_popcount(mask));
		}
	}
	cout << ret << endl;
	return 0;
}


Measured memory_bytes: 3608
#include <stdio.h>
int main ()
{
    int a,b,c,d,e,f;
    scanf("%d%d%d%d",&a,&b,&c,&d);
    if(a>b)
    e=b;
    else
    e=a;
    if(c>d)
    f=d;
    else
    f=c;
    printf("%d\n",e+f);
    return 0;
}

Measured memory_bytes: 2152
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int n, w;

  	cin >> n >> w;
	vector<int> v(n+1), wei(n+1);
	
	for(int i=0;i<n;i++){
		cin>> v[i+1] >> wei[i+1];
	}
	int dp[n+1][w+1];
	
	for(int j=0;j<=w;j++){
		dp[0][j] = 0;
	}
	
	for(int i=0;i<n;i++){
		for(int j=0;j<=w;j++){
			if(wei[i+1]<=j){
				dp[i+1][j] = max(dp[i][j-wei[i+1]]+v[i+1], dp[i][j]);
			}else{
				dp[i+1][j] = dp[i][j];
			}
		}
	}
	cout<<dp[n][w] <<endl;
}


Measured memory_bytes: 7048
use std::io;

fn main() {
    let (n, m) = input_size();
    let m1 = input(n, m);
    let m2 = input(m, 1);

    for i in 0..n {
        let c: i32 = m1[i].iter().enumerate().map(|(k, &v)| v * m2[k][0]).sum();
        println!("{}", c);
    }
}

fn input_size() -> (usize, usize) {
    let mut s = String::new();
    io::stdin().read_line(&mut s).expect("");
    let mut iter = s.trim().split_whitespace();

    let n: usize = iter.next().unwrap().parse().unwrap();
    let m: usize = iter.next().unwrap().parse().unwrap();

    (n, m)
}

fn input(n: usize, m: usize) -> Vec<Vec<i32>> {
    let mut mat: Vec<Vec<i32>> = vec![];
    for i in 0..n {
        let mut s = String::new();
        io::stdin().read_line(&mut s).expect("");
        let mut iter = s.trim().split_whitespace();

        let mut v = vec![];
        for _ in 0..m {
            v.push(iter.next().unwrap().parse().unwrap());
        }
        mat.push(v);
    }

    mat
}



Measured memory_bytes: 5048
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long n,ans=0,cnt1=0,cnt2=0,cnt3=0;
  cin >> n;
  string s[n];
  for(int i=0;i<n;i++){
    cin >> s[i];
    int b=0,a=0;
    if(s[i][0]=='B'){
      b++;
    }
    if(s[i][s[i].size()-1]=='A'){
      a++;
    }
    if(a==1 and b==1){
      cnt1++;
    }
    if(a==0 and b==1){
      cnt2++;
    }
    if(a==1 and b==0){
      cnt3++;
    }
    for(int j=0;j<s[i].size()-1;j++){
      if(s[i][j]=='A' and s[i][j+1]=='B'){
        ans++;
        j++;
      }
    }
  }
  if(cnt1>0){
    ans+=cnt1-1;
    if(cnt2>0){
      ans++;
      cnt2--;
    }
    if(cnt3>0){
      ans++;
      cnt3--;
    }
  }
  ans+=min(cnt2,cnt3);
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,w;
  scanf("%d %d", &n, &w);
  vector<pair<int,int>>v(n);
  int weight[n];
  int profit[n];

  for(int i=0;i<n;i++)
    scanf("%d %d", &weight[i], &profit[i]);
  
  
  vector<vector<long long>>dp(n+1, vector<long long>(w+1,0));
  
  for(int i = 1;i<=n;i++){
    for(int j=1;j<=w;j++){
      if(j>=weight[i-1])
        dp[i][j] = max(dp[i-1][j], profit[i-1]+dp[i-1][j-weight[i-1]]);
      else
        dp[i][j] = max(dp[i][j], dp[i-1][j]);
    }
  }

  cout<<dp[n][w]<<"\n";
  return 0;
}

Measured memory_bytes: 80256
#include <stdio.h>
#define MAX 2000000

int n;

void CountingSort(int A[], int B[], int k) {
    int C[k];
    
    for (int i = 0; i <= k; i++) {
        C[i] = 0;
    }
    
    for (int i = 0; i < n; i++) {
        C[A[i]]++;
    }
    
    for (int i = 1; i <= k; i++) {
        C[i] += C[i-1];
    }
    
    for (int i = n-1; i >= 0; i--) {
        B[C[A[i]]] = A[i];
        C[A[i]]--;
    }
    
}

int main(void){
   int A[MAX], B[MAX], k = 0;
   
   scanf("%d", &n);
   
   for (int i = 0; i < n; i++) {
       scanf("%d", &A[i]);
       if (k < A[i]) k = A[i];
   }

   
   CountingSort(A, B, k);
   
   for (int i = 1; i <= n; i++) {
       if (i-1) printf(" ");
       printf("%d", B[i]);
   }
printf("\n");
   return 0;
    
}



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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;

const ll mod = 1e9+7;
const int maxn = 1e6 + 5;




int f[maxn];

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

    int n;
    cin>>n;
    
    for (int i=0; i<n; i++) {
	int x;
	cin>>x;
	f[x]++;
    }
    vector<ll> v; // frequencies of elems
    for (int i=0; i<maxn; i++) {
	if (f[i]) {
	    v.push_back(f[i]);
	}
    }

    sort(v.rbegin(), v.rend());
    int len = v.size();

    vector<ll> remaining(n+1, 0); // remaining[i]: remaining # of elems if we remove the top i most frequent elements.
    for (int i=len-1; i>=0; i--) {
	remaining[i] = v[i] + remaining[i+1];
    }


    auto get = [&](int m, int k) -> double {
	return 1.0 * remaining[m] / (k-m);
    };




    // for (int k=1; k<=n; k++) {
    // 	watch(k);
    // 	for (int m=1; m<k; m++) {
    // 	    cout<<get(m,k)<<" ";
    // 	}
    // 	cout<<endl;
    // }

    // return 0;

    for (int k=1; k<=n; k++) {
	ll res = n / k;
	int lo = 1;
	int hi = k;
	while (hi-lo>1) {
	    int mid = (lo+hi)/2;
	    assert(k>mid);
	    double resp = get(mid-1, k);
	    double resc = get(mid, k);
	    if (resp < resc) {
		hi = mid;
	    } else {
		lo = mid;
	    }
	}
	for (int m=hi-5; m<=hi+5; m++) {
	    if (k>m && m>=0) {
		res = min(res, (ll)get(m, k));
	    }
	}
	cout<<res<<"\n";
    }
    
    return 0;
}


Measured memory_bytes: 8840
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    int a,b,c,x,y;
    cin>>a>>b>>c>>x>>y;
    
    int sa=min(x,y), amari;
    int ha=c*(sa*2);
    int ha2=c*(max(x,y)*2);
    
    if(x<y){
        amari=b*abs(x-y);
    }else if(x>y){
        amari=a*abs(x-y);
    }
    
    int ans1=min(amari+ha, ha2);
        
    int ans2=a*x+b*y;
    
    cout<<min(ans1,ans2)<<endl;
    
  
}


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

s = sum(a)
ans = 10**18
t = 0
l = 0
for i in range(N-1):
    t += a[i]
    l = s-t
    b = abs(t-l)
    ans = min(ans,b)

print(ans)

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

int main(){

    int n;
    cin >> n;
    vector<pair<int,int>> ab(n);

    rep(i,n)cin >> ab[i].first >> ab[i].second;

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

    cout << ab.back().first+ab.back().second << endl;

    return 0;
}

Measured memory_bytes: 1024
#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##_len = (n); i < i##_len; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define INF 1145141919
int dy[] = {0, 0, 1, -1};
int dx[] = {1, -1, 0, 0};
int ny, nx;
typedef long long ll;
using namespace std;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

ll lcm(ll m, ll n)
{
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n);
}

ll llpow(ll x, ll y)
{
    ll ans = 1;
    REP(i, y)
    ans *= x;
    return ans;
}

int ctoi(char c)
{
    if (c >= '0' && c <= '9')
    {
        return c - '0';
    }
    return 0;
}

class UnionFind
{
public:
    vector<ll> par; // 各元の親を表す配列
    vector<ll> siz; // 素集合のサイズを表す配列(1 で初期化)

    // Constructor
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL)
    {
        for (ll i = 0; i < sz_; ++i)
            par[i] = i; // 初期では親は自分自身
    }
    void init(ll sz_)
    {
        siz.assign(sz_, 1LL); // assign: 再代入
        par.resize(sz_);      // resize: 再確保
        for (ll i = 0; i < sz_; ++i)
            par[i] = i; // 初期では親は自分自身
    }

    // Member Function
    // Find
    ll root(ll x)
    { // 根の検索
        while (par[x] != x)
        {
            x = par[x] = par[par[x]]; // x の親の親を x の親とする
        }
        return x;
    }

    // Union(Unite, Merge)
    bool merge(ll x, ll y)
    {
        x = root(x);
        y = root(y);
        if (x == y)
            return false;
        // merge technique（データ構造をマージするテク．小を大にくっつける）
        if (siz[x] < siz[y])
            swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y)
    { // 連結判定
        return root(x) == root(y);
    }

    ll size(ll x)
    { // 素集合のサイズ
        return siz[root(x)];
    }
};

template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}

template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}

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

int main()
{
    int N; cin >> N;
    vector<int> a(N);
    REP(i,N) cin >> a[i];

    // コピーコンストラクタ
    vector<int> res(a);
    int multiple2=0, multiple4=0;

    REP(i,N){
        if(res[i]%2==0){
            res[i]/=2;
            if(res[i]%2==0){
                multiple4++;
            }else{
                multiple2++;
            }
        }
    }

    int none=N-(multiple2+multiple4);

    // cout << "multiple2= " << multiple2 << " multiple4= " << multiple4 << endl;

    if(multiple2==0){
        if(none<=multiple4+1) cout << "Yes" << endl;
        else cout << "No" << endl;
    }else{
        if(none<=multiple4) cout << "Yes" << endl;
        else cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
int main(){
	int n,i = 1,s = 0,a;
	scanf("%d",&n);
	while(n--){
		scanf("%d",&a);
		if(i%2==1 && a%2==1)
			s = s + 1;
			i = i + 1;
	}
	printf("%d",s);
} 

Measured memory_bytes: 1724