akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <bitset>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;

const ll MOD = 1000000007;
const long double EPS = 1e-10;
const int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

class UnionFind {
    public:
    int n;
    vector<int> par, rank, size;  //親, 深さ, その木の要素数

    UnionFind(int n): n(n) {
        for(int i=0;i<n;++i){
            par.push_back(i);
            rank.push_back(0);
            size.push_back(1);
        }
    }

    //根を求める
    int find(int x){
        if(par[x] == x){
            return x;
        }else{
            int p = find(par[x]);
            size[x] = size[p];
            return par[x] = p;
        }
    }

    //xとyの属する集合の併合
    void unite(int x, int y){
        x = find(x);
        y = find(y);
        if(x == y) return;
        
        size[x] += size[y];
        size[y] = size[x];
        if(rank[x] < rank[y]){
            par[x] = y;
        }else{
            par[y] = x;
            if(rank[x] == rank[y]) rank[x]++;
        }
    }

    //同じ集合に属するか否か
    bool is_same(int x, int y){
        return find(x) == find(y);
    }
};


int main() {
    std::ios::sync_with_stdio(0); cin.tie(0);
    int n, m, x, y;
    cin >> n >> m;
    vector<int> p(n+1);
    for(int i=1;i<=n;++i){
        cin >> p[i];
    }

    UnionFind uf = UnionFind(n+1);
    for(int i=0;i<m;++i){
        cin >> x >> y;
        uf.unite(x, y);
    }

    int ans = 0;
    for(int i=1;i<=n;++i){
        if(uf.is_same(i, p[i])) ++ans;
    }

    cout << ans << endl;

}


Measured memory_bytes: 2028
n = int(input())
A = list(map(int, input().split()))
freq = [0] * (max(A)+1)
for a in A:
    freq[a] += 1
total = 0
for f in freq:
    total += f*(f-1)//2
for a in A:
    print (total - max(freq[a]-1, 0))

Measured memory_bytes: 32220
#include<bits/stdc++.h>
using namespace std;
int main(){
string A,B,C;
  cin>>A>>B>>C;

   int a=A.size();
  int b=B.size();
  if(A.at(a-1)==B.at(0)&&B.at(b-1)==C.at(0)){
  cout<<"YES"<<endl;
  }
  else{
  cout<<"NO"<<endl;
  }

}


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

typedef long long ll;

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define ANS(n) cout << (n) << endl

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(a);i>=(b);i--)

#define ALL(obj) (obj).begin(),(obj).end()

#define pii pair<int,int>

#define pb(a) push_back(a)
#define mp make_pair

int main()
{
	int n;
	cin >> n;
	string ns = to_string(n);
	int digitSum = 0;
	FOR(i,0,(int)ns.size())digitSum += ns[i] - '0';
	Yes(n % digitSum == 0);
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

#define max 200000
int maxProfit(int[]);

int main(){
    int n,maxv,minv;
    int r[max];

    scanf("%d",&n);

    for(int i=0;i<n;i++){
        scanf("%d",&r[i]);
    }

    maxv = r[1] - r[0];
    minv = r[0];
    for(int j=1;j<n;j++){
        if(maxv <= r[j]-minv)maxv = r[j] - minv;
        if(minv >= r[j])minv = r[j];
    }

    printf("%d\n",maxv);

    return 0;
}



Measured memory_bytes: 2564
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
bool judge(string s){
	string t = s.substr(1, (s.find(')') - 1));
	REP(i,t.size())if(t[i]=='&')t[i] = ' ';
	stringstream ss(t);
	vector<string> v;
	for(string u; ss>>u;){ v.push_back(u); }
	assert(v.size() == 3);
	//REP(i,v.size())cout<<v[i]<<endl;
	bool ok = true;
	REP(i,3)FOR(j,i+1,3)if("~"+v[i] == v[j] || "~"+v[j] == v[i])ok = false;
	if(ok) return true;
	if(s.find('|') != -1){
		return judge(s.substr(s.find('|')+1));
	}else{
		return false;
	}
}

int main(){
	string s;
	while(cin>>s,s!="#"){
		if(judge(s))cout<<"yes"<<endl;
		else cout<<"no"<<endl;
	}
	return 0;
}

Measured memory_bytes: 924
#include <stdio.h>
#include <string.h>
#define  N 26

int main()
{
	char input[N + 1];
	size_t i, j;
	scanf("%s", input);

	for (i = 0; i < strlen(input); i++) {
		for (j = i + 1; j < strlen(input); j++) {
			if (input[i] == input[j]) {
				printf("no\n");
				return 0;
			}
		}
	}
	printf("yes\n");
	return 0;
}


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

using namespace std;

int main() {
	long long a, b, c, x, y;
	cin >> a >> b >> c >> x >> y;

	int flag_a = 0, flag_b = 0, flag_ab = 0;
	if (a + b > c * 2) 	flag_ab = 1;
	if (a > c * 2) 	flag_a = 1;
	if (b > c * 2) 	flag_b = 1;
	
	long long ans = 0;
	if (flag_ab == 1) {
		if (x > y) {
			ans += c * 2 * y;
			x -= y;
			if (flag_a == 1) {
				ans += c * 2 * x;
			}
			else {
				ans += a * x;
			}
		}
		else {
			ans += c * 2 * x;
			y -= x;
			if (flag_b == 1) {
				ans += c * 2 * y;
			}
			else {
				ans += b * y;
			}
		}
	}
	else {
		if (flag_a == 1) {
			ans = c * 2 * x + (b - c * 2) * y;
		}
		else if (flag_b == 1) {
			ans = (a - c * 2) * x + c * 2 * y;
		}
		else {
			ans = a * x + b * y;
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3584
M = 10**9+7

S = int(input())

num_list = [0]*(S+1)
num_list[-1] = 1

for idx in reversed(range(3,S+1)):
    for i in reversed(range(idx-2)):
        num_list[i] += num_list[idx]


ans = num_list[0]%M
print(ans)

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

list.sort(reverse = True)

while(len(list) > 1):
    vj = list.pop()
    vi = list.pop()
    vk = (vi + vj)/2
    list.append(vk)
    list.sort(reverse = True)

print(list[0])



Measured memory_bytes: 2940
import java.io.*;
public class Main {

    private static int[] arr = new int[100001];
    private static int N, Q;
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));

        N = Integer.parseInt(br.readLine());

        String[] temp = br.readLine().split(" ");
        for(int i=0;i<temp.length;i++){
            arr[Integer.parseInt(temp[i])]++;
        }

        long sum = 0;
        for(int i=1;i<=100000;i++){
            sum += i*arr[i];
        }

        Q = Integer.parseInt(br.readLine());
        while(Q-- > 0){
            temp = br.readLine().split(" ");
            int from = Integer.parseInt(temp[0]);
            int to = Integer.parseInt(temp[1]);

            arr[to] += arr[from];
            sum += (long)to*(long)arr[from];
            sum -= (long)from*(long)arr[from];
            arr[from] = 0;
            bw.write(sum + "\n");
        }
        bw.flush();



    }
}


Measured memory_bytes: 62160
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
#define PI 3.14159265359 //πの値
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

 
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
  ll a;
  cin >> a;
    if(400<=a&&a<=599) cout << 8;
    else if(600<=a&&a<=799) cout << 7;
    else if(800<=a&&a<=999) cout << 6;
    else if(1000<=a&&a<=1199) cout << 5;
    else if(1200<=a&&a<=1399) cout << 4;
    else if(1400<=a&&a<=1599) cout << 3;
    else if(1600<=a&&a<=1799) cout << 2;
    else if(1800<=a&&a<=1999) cout << 1;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#define ll  long long
#define ull unsigned long long
#define IO ios::sync_with_stdio(false), cin.tie(0)
#define endl '\n'
#define main() int main()
#define ff1(i,n) for(int i=1;i<=n;++i)
#define ff0(i,n) for(int i=0;i<n;++i)
#define pi acos(-1.0)
#define ms(a, x) memset(a, x, sizeof(a))
#define lowbit(x) ((x)&(-(x)))
#define pb push_back
#define binarycount __builtin_popcount(x)
#define tr t[root]
#define lson t[root << 1]
#define rson t[root << 1 | 1]
#define fir first
#define sec second
#define debug(x) cout<<x<<'\n'
#define sa(a) scanf("%d", &a)
#define sab(a, b) scanf("%d%d", &a, &b)
#define pa(a) printf("%d",a)
#define pab(a,b) printf("%d%d",a,b)
#define pii pair<int,int>
using namespace std;

#define maxn 100
const int inf = 0x3f3f3f3f;
const int mod = 1e9+7;
const double eps = 1e-8;
ll gcd(ll a, ll b) {return b==0?a:gcd(b, a%b);}
ll lcm(ll a, ll b) {return a/gcd(a, b)*b;}
ll powmod(ll a,ll b){
    ll ans = 1, pow = a%mod;
    while(b) { if(b&1) ans = (ans*pow)%mod; pow = (pow*pow)%mod; b >>= 1; }
    return ans%mod;
}
ll n,m,q,aa[maxn],b[maxn],c[maxn],d[maxn],a[maxn];
ll ans;
void sousuo(ll x,ll y) {
    if(x-1==n){
    	ll tmp=0;
    	for(int i=1;i<=q;i++){
    		if(a[b[i]]-a[aa[i]]==c[i])tmp+=d[i];
		}
		ans=max(ans,tmp);
        return;
    }
    for(int i=y;i<=m;i++){
    	a[x]=i;
    	sousuo(x+1,i);
	}
}
main(){
	ll n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	ll sum=0;
	map<ll,ll> mp;
	for(int i=0;i<n;i++){
		if(mp.count(i-a[i])!=0){
			sum+=mp[i-a[i]];
		}
		mp[i+a[i]]++;
	}
	cout<<sum<<endl;
} 

Measured memory_bytes: 16840
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
using namespace std;
vector<ll> Graph[200005];
ll cnt;
bool vis[200005];
void dfs(ll cur)
{
	cnt++;
	vis[cur]=1;
	for(auto h:Graph[cur])
	{
		if(!vis[h])
		{
			dfs(h);
		}
	}
}
int main()
{
	ll n;
	cin>>n;
	ll m;
	cin>>m;
	while(m--)
	{
		ll x,y;
		cin>>x>>y;
		Graph[x].push_back(y);
		Graph[y].push_back(x);
	}
	ll ans=0;
	for(ll p=1;p<=n;p++)
	{
		if(!vis[p])
		{
			cnt=0;
			dfs(p);
			ans=max(ans,cnt);
		}
	}
	cout<<ans;
}


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

#define rep(i,a,b) for(int i=int(a),nn=int(b);i<=nn;++i) 
#define vep(i,a,b) for(int i=int(a),nn=int(b);i>=nn;--i) 
#define xep(i,b) for(int i=0,nn=int(b);i<nn;++i) 

typedef long long ll; 

inline void print(ll x) { 
	int as=0; while (x) ++as, x/=10; 
	cout<<as<<endl; 
	exit(0); 
}
int main() { 
	ll n; cin>>n; ll x=sqrt(n); 
	for (;x;--x) if (n%x==0) print(n/x); 
	return 0; 
}

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

int n, a[55];

int main () {
	cin >> n;
	int id = -1;
	int mx = -10000000;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		int b = abs(a[i]);
		if (mx < b) {
			mx = b;
			id = i;
		}
	}
	cout << 2 * (n - 1) << endl;
	for (int i = 0; i < n; i++) {
		if (i == id) continue;
		cout << id + 1 << " " << i + 1 << endl;
	}
	for (int i = 0; i < n - 1; i++) {
		if (a[id] > 0) {
			cout << i + 1 << " " << i + 2 << endl;
		}
	}
	for (int i = n - 1; i > 0; i--) {
		if (a[id] <= 0) {
			cout << i + 1 << " " << i << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef vector<ll> vel;
typedef vector<str> ves;
#define REP(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define rep(i, b) REP(i, 0, b)
const ll mod = 1000000007;
const double pi = 3.14159265358979;

ll expo(ll a, ll b){
    ll ex = 1;
    rep(i, b){
        ex *= a;
    }
    return ex;
}

ll fact(ll a){
    ll fc = 1;
    REP(i, 1, a+1){
        fc *= i;
    }
    return fc;
}

int main() {
    ll n, i;
    cin >> n >> i;
    cout << n - i + 1 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <numeric>
#include <map>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <algorithm>
#include <memory>
#include <memory.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> PP;
typedef pair<P,P> P2;
const int INF = 1 << 30;
const double EPS = 1E-9;

int dy[] = {
	0, 1, 0, -1
};
int dx[] = {
	1, 0, -1, 0
};
int n;
int w, h;
vector<P> ps;
char field[30][30];
int G[11][11];
int dis[30][30];
int dp[11][1 << 11];

int main(){
	while(cin >> w >> h && (w || h)){
		fill(&field[0][0], &field[29][29], 'x');
		ps.clear();
		int s;
		for(int i = 1; i <= h; i++){
			for(int j = 1; j <= w; j++){
				cin >> field[i][j];
				if(field[i][j] == 'o'){
					s = ps.size();
					ps.push_back(P(i,j));
				}else if(field[i][j] == '*'){
					ps.push_back(P(i, j));
				}
			}
		}
		n = ps.size();
		bool ng = false;
		for(int i = 0; i < n; i++){
			fill(&dis[0][0], &dis[29][29], INF);
			int y = ps[i].first;
			int x = ps[i].second;
			dis[y][x] = 0;
			queue<P> que;
			que.push(ps[i]);
			while(!que.empty()){
				P p = que.front(); que.pop();
				y = p.first;
				x = p.second;
				for(int j = 0; j < 4; j++){
					int y2 = y + dy[j];
					int x2 = x + dx[j];
					if(field[y2][x2] == 'x') continue;
					if(dis[y2][x2] > dis[y][x] + 1){
						dis[y2][x2] = dis[y][x] + 1;
						que.push(P(y2, x2));
					}
				}
			}
			for(int j = 0; j < n; j++){
				G[i][j] = dis[ps[j].first][ps[j].second];
				if(G[i][j] == INF) ng = true;
			}
		}
		if(ng){
			cout << -1 << endl;
			continue;
		}
		fill(&dp[0][0], &dp[10][(1 << 11) - 1], INF);
		dp[s][1 << s] = 0;
		queue<P> que;
		que.push(P(s, 1 << s));
		while(!que.empty()){
			P p = que.front(); que.pop();
			int pl = p.first;
			int st = p.second;
			for(int i = 0; i < n; i++){
				if(st & ( 1 << i)) continue;
				if(dp[i][st | (1 << i)] > dp[pl][st] + G[pl][i]){
					dp[i][st | (1 << i)] = dp[pl][st] + G[pl][i];
					que.push(P(i, (st | (1 << i))));
				}
			}
		}
		int m = INF;
		for(int i = 0; i < n; i++){
			m = min(m, dp[i][(1 << n) - 1]);
		}
		cout << m << endl;
	}
	return 0;
}

Measured memory_bytes: 1020
// Original: https://github.com/tanakh/competitive-rs
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

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

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

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

#[allow(dead_code)]
fn chmin<T>(x: &mut T, y: T) -> bool
where
    T: PartialOrd + Copy,
{
    *x > y && {
        *x = y;
        true
    }
}

#[allow(dead_code)]
fn chmax<T>(x: &mut T, y: T) -> bool
where
    T: PartialOrd + Copy,
{
    *x < y && {
        *x = y;
        true
    }
}

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, VecDeque};

fn main() {
    input!(l: i64, r: i64);
    let m = 2019 as i64;

    let mut ans = 1 << 30;
    for i in l..min(r + 1, l + 2019) {
        for j in i + 1..min(r + 1, l + 2019) {
            ans = min(ans, (i * j) % m);
        }
    }
    println!("{}", ans % m);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    vector<int> a(5);
    for(int i = 0; i < 5; i++){
        cin >> a.at(i);
        if(a.at(i) == 0){
            cout << i+1 << endl;
        }
    }
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)

#define INF 2e9
#define ALL(v) v.begin(), v.end()

int main(){
    int x,y,z;
    cin>>x>>y>>z;
    cout<<z<<" "<<x<<" "<<y;
    return 0;
}

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

#define TC int t; cin>>t; while(t--)
#define MOD 1000000007
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define MEM(a, b) memset(a, (b), sizeof(a))
#define FOR(i, st, en, in) for (int i=st ; i<en ; i+=in)
#define RFOR(i, st, en, in) for (int i=st ; i>=en ; i-=in)
#define REP(i, n) FOR(i, 0, n, 1)
#define RREP(i, n) RFOR(i, n-1, 0, 1)
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define sz(a) int(a.size())
#define SORT(c) sort(all(c))
#define RSORT(c) sort(rall(c))

using namespace std;
using ull = unsigned long long int;
using ll = long long;
using pii = pair<int,int>;

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

ll bs(ll s,ll e,ll a[],ll v){
    ll m =(s+e)/2;
    if(v>a[m]) return bs(m+1,e,a,v);
    else if(v<a[m]) return bs(s,m-1,a,v);
    return m;
}

void fastio() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
}

void testingio(){
	freopen("input.txt","r",stdin); //redirects standard input
    freopen("output.txt","w",stdout); //redirects standard output	
}

int main(){
	//testingio();
	fastio();
    int a[3];
    REP(i,3){
        cin>>a[i];  
    }
    sort(a,a+3,greater<int>());
    int prev = a[0],sum=0;
    FOR(i,1,3,1){
        sum+=prev-a[i];
        prev = a[i];
        //cout<<sum<<" "<<prev<<endl;
    }
    cout<<sum<<endl;
	return 0;
}

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

from functools import lru_cache
# メモ化
@lru_cache(maxsize=2**12)

def solve(i, m):
    if (m == 0):
        return True
    elif (i == N):
        return False
    return solve(i+1, m) or solve(i+1, m-A[i])

for m in M:
    if (solve(0, m)):
        print('yes')
    else:
        print('no')


Measured memory_bytes: 7664
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define M 1000000007

const int mod=M;
struct mint{
    long long x;
    mint(long long x=0):x((x%mod+mod)%mod){}
    mint operator-()const{
        return mint(-x);
    }
    mint &operator+=(const mint &a){
        if((x+=a.x)>=mod) x-=mod;
        return *this;        
    }
    mint &operator-=(const mint &a){
        if((x+=mod-a.x)>=mod) x-=mod;
        return *this;        
    }
    mint &operator*=(const mint &a){
        (x*=a.x)%=mod;
        return *this;        
    }
    mint operator+(const mint &a)const{
        return mint(*this)+=a;        
    }
    mint operator-(const mint &a)const{
        return mint(*this)-=a;        
    }
    mint operator*(const mint &a)const{
        return mint(*this)*=a;        
    }
    mint pow(long long t)const{
        if(!t){
            return 1;
        }
        mint a=pow(t>>1);
        a*=a;
        if(t&1){
            a*=*this;
        }
		return a;
	}
	mint inv()const{
		return pow(mod-2);
	}
	mint &operator/=(const mint &a){
		return (*this)*=a.inv();
	}
	mint operator/(const mint &a)const{
		return mint(*this)/=a;
	}
};
istream &operator>>(istream &is,const mint &a){
    return is>>a.x;
}
ostream &operator<<(ostream &os,const mint &a){
    return os<<a.x;
}
struct combination{
	vector<mint> fact,ifact;
	combination(int n):fact(n+1),ifact(n+1){
		assert(n<mod);
		fact[0]=1;
		for(int i=1;i<=n;i++){
			fact[i]=fact[i-1]*i;
		}
		ifact[n]=fact[n].inv();
		for(int i=n;i>=1;i--){
			ifact[i-1]=ifact[i]*i;
		}
	}
	mint operator()(int n,int k){
		if(k<0||n<k){
			return 0;
		}
		return fact[n]*ifact[k]*ifact[n-k];
	}
}c(2000005);
int main(){
	ll k;
	cin>>k;
	string s;
	cin>>s;
	ll le=s.size();
	mint ans=0;
	for(ll i=0;i<=k;i++){
		ans+=c((int)(le+i-1),(int)i)*mint(25).pow(i)*mint(26).pow(k-i);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 36508
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;

ll dp[3002][3002][4];

int main(){
    int r,c,k;
    cin >> r >> c >>k;
    vector<vector<int>> maze(r,vector<int>(c,0));
    rep(i,k){
        int a,b,v;
        cin >> a >> b >> v;
        --a;--b;
        maze[a][b] = v;
    }
    dp[0][0][0] = 0;
    dp[0][0][1] = maze[0][0];
    for(int i=0;i<r;i++){
        for(int j=0;j<c;j++){
            for(int k=0;k<=3;++k){
                if(k==3){
                    if(j+1<c) dp[i][j+1][k] = max(dp[i][j+1][k],dp[i][j][k]);
                    if(i+1<r){
                        dp[i+1][j][0] = max(dp[i+1][j][0],dp[i][j][k]);
                        if(maze[i+1][j]>0) dp[i+1][j][1] = max(dp[i+1][j][1],dp[i][j][k]+maze[i+1][j]);
                    }
                }
                else{
                    if(j+1<c){
                        dp[i][j+1][k] = max(dp[i][j+1][k],dp[i][j][k]);
                        if(maze[i][j+1]>0) dp[i][j+1][k+1] = max(dp[i][j+1][k+1],dp[i][j][k]+maze[i][j+1]);
                    }
                    if(i+1<r){
                        dp[i+1][j][0] = max(dp[i+1][j][0],dp[i][j][k]);
                        if(maze[i+1][j]>0) dp[i+1][j][1] = max(dp[i+1][j][1],dp[i][j][k]+maze[i+1][j]);
                    }
                }
            }
        }
    }
    ll ans = 0;
    rep(i,4) ans = max(ans,dp[r-1][c-1][i]);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 319640
n, m = map(int,input().split())

par = [i for i in range(n+1)]
rank = [0] * (n+1)

def find(x):
  if par[x] == x:
    return x
  return find(par[x])

def unite(x,y):
  root_x = find(x)
  root_y = find(y)
  if rank[root_x] != rank[root_y]:
    par[min(root_x,root_y)] = max(root_x,root_y)
  else:
    par[root_y] = root_x
    rank[root_x] += 1


for i in range(m):
  x, y, z = map(int,input().split())
  unite(x,y)
  
roo = [-1]

for i in range(n):
  roo.append(find(i+1))

print(len(set(roo))-1)

Measured memory_bytes: 17964
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
char s[100005];
int len,l,r,s1[36],l1;
int main()
{
	scanf("%s",s+1);
	len=strlen(s+1);
	l=1,r=2;
	if(s[1]==s[2])
	{
		printf("1 2");
		return 0;
	}
	s1[s[1]-'a']++,s1[s[2]-'a']++;
	while(r<len)
	{
		r++;
		s1[s[r]-'a']++;
		if(s[r]!=s[l])
		{
			s1[s[l]-'a']--;
			l++;
		}
		if(s1[s[r]-'a']*2>r-l+1)
		{
			printf("%d %d",l,r);
			return 0;
		}
	}
	printf("-1 -1");
}

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

using namespace std;

typedef long long ll;

ll leftrule(string s)
{
	ll ret=0;
	int i=0;
	if(s.size()==1)
		return s[0]-'0';
	
	ret=s[0]-'0';
	i++;
	while(i<s.size())
	{
		if(s[i]=='+')
		{
			ret+=(s[i+1]-'0');
			i+=2;
		}else{
			ret*=(s[i+1]-'0');
			i+=2;
		}
	}
	return ret;
}

ll multirule(string s)
{
	vector<ll> num;
	vector<bool> op;
	ll ret=0;
	if(s.size()==1)
		return s[0]-'0';
	
	for(int i=0;i<s.size();i++)
	{
		if(s[i]=='+')
			op.push_back(false);
		else if(s[i]=='*')
			op.push_back(true);
		else
			num.push_back(s[i]-'0');
	}
	int j=0;
	ret=num[0];
	for(int i=1;i<num.size();i++)
	{
		if(op[j])
		{
			ret*=num[i];
			j++;
		}else{
			j++;
			ll tmp=num[i];
			while(op[j])
			{
				if(j==op.size())
					break;
				i++;
				tmp*=num[i];
				j++;
			}
			ret+=tmp;
		}
	}
	return ret;
}

int main()
{
	string s;
	string ss="ILMU";
	ll a;
	int ans=0;
	cin>>s;
	cin>>a;
	ll l=leftrule(s);
	//cerr<<l<<endl;
	ll m=multirule(s);
	//cerr<<m<<endl;
	if(a==l)
		ans+=1;
	if(a==m)
		ans+=2;
	cout<<ss[ans]<<endl;
	return 0;
}


Measured memory_bytes: 3212
import math

def getRightTryangleAngle(base, area):
    height = 2.0 * area / base
    radian = math.atan(height / base)
    return math.degrees(radian)

a, b, x = map(float, input().split())
area = x / a
if area < (a * b) / 2:
    degree = 90.0 - getRightTryangleAngle(b, area)
else:
    degree = getRightTryangleAngle(a, a * b - area)

print('{:.6f}'.format(degree))


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

int main() {
    int N;
    std::cin >> N;

    std::string s;
    std::unordered_map<std::string, int> blue;
    for (int i = 0; i < N; ++i) {
        std::cin >> s;
        if (blue.count(s) == 0) {
            blue[s] = 1;
        } else {
            blue[s] += 1;
        }
    }

    int M;
    std::cin >> M;

    std::unordered_map<std::string, int> red;
    for (int i = 0; i < M; ++i) {
        std::cin >> s;
        if (red.count(s) == 0) {
            red[s] = 1;
        } else {
            red[s] += 1;
        }
    }

    int max = 0;
    for (const auto& p : blue) {
        int score = p.second;
        if (red.count(p.first) != 0) {
            score -= red[p.first];
        }

        max = std::max(max, score);
    }

    std::cout << max << std::endl;

    return 0;
}


Measured memory_bytes: 256
import sys
stdin = sys.stdin

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n = ni()
ans = 0
for _ in range(n):
    l,r = li()
    ans += (r-l+1)
    
print(ans)

Measured memory_bytes: 3064
#include <stdio.h>

int const M = 998244353;
int i, n, x, c[7 << 14];

int pow(int a, int b) {
  int r = 1;
  for(; b; b >>= 1) {
    if(b & 1)
      r = (long long) r * a % M;
    a = (long long) a * a % M;
  }
  return r;
}  

int main() {
  scanf("%d%d", &n, &x);
  int r = 0;
  if(x == 0) {
    for(i = 1; i < n; c[x]++, i++) scanf("%d", &x);
    if(c[0] == 0) {
      c[0] = r = 1;
      for(i = 1; c[i]; i++) {
        n -= c[i];
        r = (long long) r * pow(c[i - 1], c[i]) % M;
      }
    }
  }
  printf("%d\n", n > 1 ? 0 : r);
  return 0;
}


Measured memory_bytes: 512
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

const int mod = 1000000007;
//const int mod = 998244353;

struct mint {
  int64_t x;
  mint(int64_t x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(int64_t t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  //for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) {return mint(*this) /= a;}
};

istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

struct combination {
  vector<mint> frac, ifrac;
  combination(int n):frac(n+1), ifrac(n+1) {
    assert(n < mod);
    frac[0] = 1;
    for (int i = 1; i <= n; ++i) frac[i] = frac[i-1]*i;
    ifrac[n] = frac[n].inv();
    for (int i = n; i >= 1; --i) ifrac[i-1] = ifrac[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return frac[n]*ifrac[k]*ifrac[n-k];
  }
} C(1000000);

//head

int n, a, b, c;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> a >> b >> c;

  mint mom(a+b);
  mom = mom.pow(2*n-1);
  mom *= 100-c;

  mint chl;
  rep(i, n) {
    mint now = mint(a).pow(n)*mint(b).pow(i)*mint(a+b).pow(n-1-i) + mint(a).pow(i)*mint(b).pow(n)*mint(a+b).pow(n-1-i);
    now *= C(n+i-1, i);
    now *= n+i;
    chl += now*100;
  }

  //cout << mom << ' ' << chl << endl;

  cout << chl/mom << endl;
}

Measured memory_bytes: 18660
#include <stdio.h>
#include <string.h>
int N, M, Q, i, D[100], t;
int main(void)
{
    for(;scanf("%d%d",&N,&Q),N;)
    {
        memset(D,0,sizeof(D));
        for(i=0;i<N;i++)
            for(scanf("%d",&M);M--;)
            {
                scanf("%d",&t);
                D[t]++;
            }
        for(i=0,t=-1;i<100;i++)
            if ((t==-1&&D[i]>=Q)||(t!=-1&&D[i]>D[t]))
                t=i;
                printf ("%d\n", t == -1 ? 0 : t);
    }
}

Measured memory_bytes: 1728
#include <stdio.h>
int main(void)
{
	char s[11];
	scanf("%s",s);
	if(s[0]=='1')printf("9");
	else printf("1");
	if(s[1]=='1')printf("9");
	else printf("1");
	if(s[2]=='1')printf("9\n");
	else printf("1\n");
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#include<math.h>
#include <stdio.h>
#include<vector>
#include<deque>
#include<stdlib.h>
#include <algorithm>
#include<set>
#include<map>
#include <limits>
#include<iomanip>
#include<string>
#define rep(i,n) for(int i = 0; i < n; i++)
typedef long long ll;
using namespace std;
#define llMAX numeric_limits<long long>::max()
#define intMAX numeric_limits<int>::max()
#define ll long long
#define d_2 100000
#define d9_7 1000000007
int main(void){
  ll n;
  cin >> n;
  vector<ll> t(n);
  vector<ll> a(n);
  rep(i,n){
    cin>>t[i];
  }
  rep(i,n){
    cin>>a[i];
  }
  ll ans=0;
  if(n==1&&a[0]!=t[n-1]){
    cout<<0<<endl;
    return 0;
  }
  if(n==2){
    if(a[0]==a[1]  ||  t[0]==t[1]){
      cout<<1<<endl;
    }else{
      cout<<0<<endl;
    }
    return 0;
  }
  if(a[0]!=t[n-1]){
    cout<<0<<endl;
    return 0;
  }
  rep(i,n){
    if(i==0){
      ans=1;
      continue;
    }else if(i==n-1){
      continue;
    }
    ll aa=(ll)min(a[i],t[i]);
    if(t[i-1]<t[i]||a[i+1]<a[i]){
      aa=1;
    }
    if(i>n/2+1){
      if(t[i-1]<t[i]){
        if(a[n-1-i]<t[i]){
          cout<<"0"<<endl;
          return 0;
        }
      }
    }else if(i<n/2){
      if(a[i+1]<a[i]){
        if(t[n-1-i]<a[i]){
          cout<<"0"<<endl;
          return 0;
        }
      }
    }
    if(t[i-1]<t[i]){
      if(t[i]>a[i]){
        cout<<"0"<<endl;
        return 0;
      }
    }
    if(a[i+1]<a[i]){
      if(t[i]<a[i]){
        cout<<"0"<<endl;
        return 0;
      }
    }
    ans=(aa*ans)%d9_7;
  }
  cout<<ans%d9_7<<endl;
  return 0;
}

Measured memory_bytes: 1792
/*
 * 17-05-13_ABC061_C.cpp
 *
 *  Created on: 2017/05/13
 *      Author: ryoma
 */

#include<iostream>
#include<algorithm>

using namespace std;

int N;
long long K;
pair<int,int> vec[100010];
int ans;
int main(){
	cin >> N >>K;
	for(int i=0;i<N;i++){
		int a,b;
		cin >> a >>b;
		vec[i] = make_pair(a,b);
	}
	sort(vec,vec+N);
	long long idx = 0;
	for(int i=0;i<N;i++){
		idx += vec[i].second;
		if(idx >= K){
			ans  = vec[i].first;
			break;
		}
	}
	cout << ans << endl;
	return 0;
}




Measured memory_bytes: 1024
#include <algorithm>
#include <cmath>
#include <climits>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
constexpr int kMod = 1000000007;

bool is_753(int digits) {
  std::string str = std::to_string(digits);
  if ((str.find("3") != std::string::npos) &&
      (str.find("5") != std::string::npos) &&
      (str.find("7") != std::string::npos)) return true;
  else return false;
}

int main() {
  std::vector<int> sub_patterns = {
    333, 335, 337, 353, 355, 357, 373, 375, 377,
    533, 535, 537, 553, 555, 557, 573, 575, 577,
    733, 735, 737, 753, 755, 757, 773, 775, 777,
  };

  int N; std::cin >> N;

  int counter = 0;
  if (N < 3000) {
    for (int digits : sub_patterns) {
      if (N < digits) break;
      if (is_753(digits)) ++counter;
    }
  } else {
    counter = 6;
    int keta = 1000;
    while(true) {
      std::vector<int> patterns;
      for (int digits : sub_patterns) {
        int new_digits = 3 * keta +  digits;
        if (N < new_digits) break;
        patterns.push_back(new_digits);
        if (is_753(new_digits)) {
          ++counter;
        }
      }
      if (N < 5 * keta) break;

      for (int digits : sub_patterns) {
        int new_digits = 5 * keta +  digits;
        if (N < new_digits) break;
        patterns.push_back(new_digits);
        if (is_753(new_digits)) {
          ++counter;
        }
      }
      if (N < 7 * keta) break;

      for (int digits : sub_patterns) {
        int new_digits = 7 * keta +  digits;
        if (N < new_digits) break;
        patterns.push_back(new_digits);
        if (is_753(new_digits)) {
          ++counter;
        }
      }
      if (N < 10 * keta) break;

      sub_patterns = patterns;
      keta *= 10;
    }
  }

  std::cout << counter << std::endl;
}


Measured memory_bytes: 512
import java.io.*;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
    FastScanner in;
    PrintWriter out;

    void solve() {
        final int MAX = (int) 2e5;
        int[] cnt = new int[MAX];
        int n = in.nextInt();
        for (int i = 0; i < n; i++) {
            cnt[in.nextInt()]++;
        }
        long curSum = 0;
        for (int i = 0; i < MAX; i++) {
            curSum += i *1L * cnt[i];
        }
        int q = in.nextInt();
        for (int i = 0; i < q; i++) {
            int bef = in.nextInt();
            int now = in.nextInt();
            curSum += (now - bef) * 1L * cnt[bef];
            cnt[now] += cnt[bef];
            cnt[bef] = 0;
            out.println(curSum);
        }
    }

    final int mod = 998244353;

    int mul(int x, int y) {
        return (int) ((x * 1L * y) % mod);
    }

    int add(int x, int y) {
        x += y;
        return x >= mod ? (x - mod) : x;
    }

    void run() {
        try {
            in = new FastScanner(new File("Main.in"));
            out = new PrintWriter(new File("Main.out"));

            solve();

            out.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }

    void runIO() {

        in = new FastScanner(System.in);
        out = new PrintWriter(System.out);

        solve();
        out.close();
    }

    class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner(File f) {
            try {
                br = new BufferedReader(new FileReader(f));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

        public FastScanner(InputStream f) {
            br = new BufferedReader(new InputStreamReader(f));
        }

        String next() {
            while (st == null || !st.hasMoreTokens()) {
                String s = null;
                try {
                    s = br.readLine();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (s == null)
                    return null;
                st = new StringTokenizer(s);
            }
            return st.nextToken();
        }

        boolean hasMoreTokens() {
            while (st == null || !st.hasMoreTokens()) {
                String s = null;
                try {
                    s = br.readLine();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (s == null)
                    return false;
                st = new StringTokenizer(s);
            }
            return true;
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }
    }

    public static void main(String[] args) {
        new Main().runIO();
    }
}

Measured memory_bytes: 64132
package main

import (
	"fmt"
)

func main() {
	var s, r int
	fmt.Scan(&s)
	var arr []int
	arr = append(arr, s)
	i := 1
	for {
		w := arr[i-1]
		if w%2 == 0 {
			arr = append(arr, w/2)
		} else {
			arr = append(arr, 3*w+1)
		}
		var b bool
		for j := i - 1; j >= 0; j-- {
			if arr[i] == arr[j] {
				r = i + 1
				b = true
				break
			}
		}
		if b {
			break
		}
		i++
	}
	fmt.Println(r)
}

Measured memory_bytes: 512
#include <iostream>
using namespace std;
#define N 16
pair<int, int> v[N][N];
int l[N];

bool bit_find(int number, int pos) {
    return number & (1 << pos);
}

int bit_count(int number, int n) {
    int sol = 0;
    for (int i = 0; i < n; i ++) {
        sol += bit_find(number, i);
    }
    return sol;
}

bool check(int number, int n) {
    for (int i = 0; i < n; i ++) {
        int pp = bit_find(number, i), p = 1;
        for (int j = 0; j < l[i]; j ++) {
            if (v[i][j].second != bit_find(number, v[i][j].first)) {
                if (pp) return false;
                p = 0;
            }
        }
        if (pp != p)    return false;
    }
    return true;
}

int main() {
    int n;
    cin >> n;
    for (int i = 0; i < n; i ++) {
        cin >> l[i];
        for (int j = 0; j < l[i]; j ++) {
            cin >> v[i][j].first >> v[i][j].second;
            v[i][j].first --;
        }
    }
    int fin = (1 << n), sol = 0;
    for (int i = 0; i < fin; i ++) {
        if (check(i, n)) {
            sol = max(sol, bit_count(i, n));
        }
    }
    cout << sol;
    return 0;
}


Measured memory_bytes: 256
n, m = gets.split(" ").map(&:to_i)
matrix = Array.new(n).map{ Array.new(m) }
vector = Array.new(m)
c = Array.new(n, 0)

for i in 0..(n - 1)
  matrix[i] = gets.split(" ").map(&:to_i)
end

for j in 0..(m - 1)
  vector[j] = gets.to_i
end

for i in 0..(n - 1)
  for j in 0..(m - 1)
    c[i] += matrix[i][j] * vector[j]
  end
end

for i in 0..(n - 1)
  puts c[i]
end

Measured memory_bytes: 6216
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;

double ab,ac,ad,bc,bd,cd;
bool heron();

int main(){
	double xa,ya,xb,yb,xc,yc,xd,yd;
	while(scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf",&xa,&ya,&xb,&yb,&xc,&yc,&xd,&yd) != EOF){
		
		ab = sqrt((xa-xb)*(xa-xb) + (ya-yb)*(ya-yb));
		ac = sqrt((xa-xc)*(xa-xc) + (ya-yc)*(ya-yc));
		ad = sqrt((xa-xd)*(xa-xd) + (ya-yd)*(ya-yd));
		bc = sqrt((xb-xc)*(xb-xc) + (yb-yc)*(yb-yc));
		bd = sqrt((xb-xd)*(xb-xd) + (yb-yd)*(yb-yd));
		cd = sqrt((xc-xd)*(xc-xd) + (yc-yd)*(yc-yd));
		
		bool f = heron();
		(f) ? puts("YES") : puts("NO");
	}
	return 0;
}

bool heron(){
	double sq1=0.0,sq2=0.0;
	double S,s;
	
	/*sq1*/
	s = (ab+ac+bc)*0.5;
	S = sqrt(s * (s-ab) * (s-ac) * (s-bc));
	sq1 += S;
	s = (ac+ad+cd)*0.5;
	S = sqrt(s * (s-ac) * (s-ad) * (s-cd));
	sq1 += S;
	
	/*sq2*/
	s = (ab+ad+bd)*0.5;
	S = sqrt(s * (s-ab) * (s-ad) * (s-bd));
	sq2 += S;
	s = (bc+bd+cd)*0.5;
	S = sqrt(s * (s-bc) * (s-bd) * (s-cd));
	sq2 += S;
	bool j;
	(fabs(sq1-sq2) <= 0.01) ? j = true : j = false;
	
	return j;
}

Measured memory_bytes: 1036
# C
N, A, B, C = map(int, input().split())
l = [int(input()) for i in range(N)]

INF = 10**9

def dfs(cur, a, b, c):
    if cur == N:
        return abs(a-A) + abs(b-B) + abs(c-C) -30 if min(a,b,c) > 0 else INF
    ret0 = dfs(cur + 1, a, b, c)
    ret1 = dfs(cur + 1, a + l[cur], b, c) + 10
    ret2 = dfs(cur + 1, a, b + l[cur], c) + 10
    ret3 = dfs(cur + 1, a, b, c + l[cur]) + 10
    return min(ret0, ret1, ret2, ret3)
print(dfs(0,0,0,0))

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

using namespace std;

using int64 = long long;

constexpr int64 P = 1000000007;

// Verified: ABC133E, ABC132D, ABC130E
struct FiniteField {
 private:
  int64 x;
 public:
  FiniteField(int64 input_x) : x(input_x) {}
  FiniteField() : x(0) {}
  int64 Value() { return x; }
  inline FiniteField operator+(FiniteField o) {
    FiniteField r(*this); r += o; return r;
  }
  inline FiniteField operator-(FiniteField o) {
    FiniteField r(*this); r -= o; return r;
  }
  inline FiniteField operator* (FiniteField o) {
    FiniteField r(*this); r *= o; return r;
  }
  inline FiniteField operator/ (FiniteField o) {
    FiniteField r(*this); r /= o; return r;
  }
  inline void operator+= (FiniteField o) { x = (x + o.x) % P; }
  inline void operator-= (FiniteField o) { x = (x + P - o.x) % P; }
  inline void operator*= (FiniteField o) { x = (x * o.x) % P; }
  void operator/=(FiniteField o) {
    int64 p = P - 2; while (p) { if (p % 2) { *this *= o; } o *= o; p /= 2; }
  }
};

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

  int n;
  string s;
  cin >> n >> s;

  vector<vector<FiniteField>> dp1(n);
  vector<vector<FiniteField>> dp2(n);
  dp1[0] = vector<FiniteField>(n);
  for (int j = 0; j < n; j++) {
    dp1[0][j] = 1;
  }
  dp2[0] = vector<FiniteField>(n);
  dp2[0][0] = dp1[0][0];
  for (int j = 1; j < n; j++) {
    dp2[0][j] = dp2[0][j - 1] + dp1[0][j];
  }

  for (int i = 0; i < n - 1; i++) {
    dp1[i + 1] = vector<FiniteField>(n - (i + 1));
    dp2[i + 1] = vector<FiniteField>(n - (i + 1));

    for (int j = 0; j < n - (i + 1); j++) {
      if (s[i] == '<') {
        dp1[i + 1][j] = dp2[i][j];
      } else {
        // s[i] == '>'
        dp1[i + 1][j] = dp2[i][n - i - 1] - dp2[i][j];
      }
    }

    dp2[i + 1][0] = dp1[i + 1][0];
    for (int j = 1; j < n - (i + 1); j++) {
      dp2[i + 1][j] = dp2[i + 1][j - 1] + dp1[i + 1][j];
    }
  }

  cout << dp1[n - 1][0].Value() << endl;
}


Measured memory_bytes: 70784
#include<iostream>
#include <fstream>
#include <stdio.h>
#include <stdlib.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include<string>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<sstream>
#include<algorithm>
#include<map>
#include<complex>
using namespace std;


#define li			long long int
#define rep(i,to)	for(int i=0;i<((int)(to));i++)
#define repp(i,start,to)	for(int i=(int)(start);i<((int)(to));i++)
#define pb			push_back
#define sz(v)		((li)(v).size())
#define bgn(v)		((v).begin())
#define eend(v)		((v).end())
#define allof(v)	(v).begin(), (v).end()
#define dodp(v,n)		memset(v,(li)n,sizeof(v))
#define bit(n)		(1ll<<(li)(n))
#define mp(a,b)		make_pair(a,b)
#define rin	rep(i,n)
#define EPS 1e-10
#define ETOL 1e-8
#define MOD 1000000007
#define F first
#define S second
#define p2(a,b)		cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)		cout<<a<<"\t"<<b<<"\t"<<c<<endl

string yobi[7]={
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday",
"Sunday"
};

int main(){
	li m,d;
	li acum=3;
	li day[12]={31,29,31,30,31,30,31,31,30,31,30,31};
	
	while(1){
		acum=3;
		cin>>m>>d;
		if(min(m,d)==0)break;
		
		rep(i,m-1)acum+=day[i];
		acum+=d-1;
		cout<<yobi[acum%7]<<endl;
	}
	
	return 0;
}

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

int main(void)
{
  	int a[5]={0};
    int index = 0;
  
   for(int i=0;i<5;i++){
     cin >> a[i];
     
     if(a[i]==0){
       index = i;
     }
   }
     
     cout << index + 1;
}


Measured memory_bytes: 3564
/**
 *    author:  otera    
**/
#include<iostream>
#include<string> 
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm> 
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

void solve() {
	int n; cin >> n;
    vector<int> a(n);
    map<int, int> mp;
    int sum = 0;
    rep(i, n) {
        cin >> a[i];
        sum += a[i];
        mp[a[i]] ++;
    }
    int q; cin >> q;
    rep(i, q) {
        int b, c; cin >> b >> c;
        sum += + (c - b) * mp[b];
        cout << sum << endl;
        mp[c] += mp[b];
        mp[b] = 0;
    }
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}

Measured memory_bytes: 10052
//AnkitCode99 here....
#include<bits/stdc++.h>
#define endl "\n"
typedef long long int ll;
#define MOD 1000000007
#define mp make_pair
#define pll pair<ll,ll>
#define pb push_back
//max xor btw range of two numbers..
#define max_XOR(a,b) (1 << int(log2(a ^ b) + 1)) - 1
#define vl vector<ll>
#define inf ll(1e18)
#define all(v) v.begin(),v.end()
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define rep(i,a,b) for(long long int i=a;i<b;i++)
#define nrep(i,a,b) for(long long int i=a;i>=b;i--)
#define ceil(a,b) a/b+((a%b ==0 )?0:1)
using namespace std;

const ll sz=100005;
const ll szz=1000006;

int main()
{
    fast;
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("op.txt","w",stdout);
    #endif

    ll n,m;
    cin>>n>>m;
    // ll ar[m];
    ll sum=0;
    rep(i,0,m)
    {
        ll ele;
        cin>>ele;
        sum+=ele;
    }
    if(sum>n)
    {
        cout<<"-1";
    }
    else
    {
        cout<<n-sum;
    }
    
}//Goodbye...

Measured memory_bytes: 3652