akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define fi first
#define se second 
//#pragma GCC optimize "trapv"
char a[1000+10][1000+10];
int vi[1000+10][1000+10];
	int ch,cw,dh,dw;
	int h,w;
	int mrk[1004][1004];
void bfs(int x,int y)
{
	priority_queue<pair<ll, pair<ll, ll>>, vector<pair<ll, pair<ll, ll>>>, greater<pair<ll, pair<ll, ll>>>> q;
	q.push({0,{x,y}});
	vi[x][y]=0;
	while(!q.empty())
	{
		int x1 = q.top().se.fi;
		int y1 = q.top().se.se;

		q.pop();
		if(mrk[x1][y1]==1)
			continue;
		mrk[x1][y1];

		for(int i=-1;i<=1;i++)
		{
			for(int j=-1;j<=1;j++)
			{
				if(abs(i)==abs(j))
					continue;
				int x2 = x1 + i;
				int y2 = y1 + j;
				if(x2<0 || x2 >=h || y2 <0 ||y2 >=w )
					continue;

				if(a[x2][y2]=='#')
					continue;

				if((vi[x2][y2]>vi[x1][y1])|| vi[x2][y2]==-1)
				{
					vi[x2][y2] = vi[x1][y1];
					q.push({vi[x2][y2],{x2,y2}});
				}

			}
		}


		for(int i=-2;i<=2;i++)
		{
			for(int j=-2;j<=2;j++)
			{
				int x2 = x1+i;
				int y2 = y1 + j;
				if(x2<0 || x2 >=h || y2 <0 ||y2 >=w )
					continue;

				if(a[x2][y2]=='#')
					continue;

				if((vi[x2][y2]>vi[x1][y1]+1 )|| vi[x2][y2]==-1)
				{
					vi[x2][y2] = vi[x1][y1]+1;
					q.push({vi[x2][y2],{x2,y2}});

				}

			}
		}




	}

}




int main()
{
	// ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
	cin>>h>>w;
	cin>>ch>>cw;
	cin>>dh>>dw;
	ch--;
	cw--;
	dh--;
	dw--;
	// memset(vi,-1,sizeof(vi));
	for(int i=0;i<h;i++)
		for(int j=0;j<w;j++)
			vi[i][j] = -1;	
	for(int i=0;i<h;i++)
	for(int j=0;j<w;j++)
	{
		cin>>a[i][j];
	}

	bfs(ch,cw);
	if(vi[dh][dw]!=-1)
			cout<<vi[dh][dw]<<"\n";
	else
		cout<<"-1\n";

}


Measured memory_bytes: 8788
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <random>

using namespace std;

#define int long long

const int INF = 1e18 + 239;

int solve_one(vector<int> a, vector<int> cost) {
    int n = (int)a.size();
    vector<vector<int>> dp(n + 1, vector<int> (3, -INF));
    for (int i = 0; i < 3; i++) {
        dp[0][i] = 0;
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 3; j++) {
            for (int k = 0; k < 3; k++) {
                if (j == k) continue;
                if (dp[i][j] == -INF) continue;
                int win = 0;
                if ((k + 1) % 3 == a[i]) {
                    win = 1;
                }
                dp[i + 1][k] = max(dp[i + 1][k], dp[i][j] + win * cost[k]);
            }
        }
    }
    int ans = -INF;
    for (int i = 0; i < 3; i++) {
        ans = max(ans, dp[n][i]);
    }
    return ans;
}

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

    int n, k;
    cin >> n >> k;
    vector<int> cost(3);
    for (auto &t : cost) {
        cin >> t;
    }
    string t;
    cin >> t;
    vector<int> a;
    for (auto x : t) {
        if (x == 'r') a.push_back(0);
        if (x == 's') a.push_back(1);
        if (x == 'p') a.push_back(2); 
    }
    int ans = 0;
    for (int i = 0; i < k; i++) {
        vector<int> sub;
        for (int j = i; j < n; j += k) {
            sub.push_back(a[j]);
        }
        ans += solve_one(sub, cost);
    }
    cout << ans << endl;
}   


Measured memory_bytes: 8132
import Control.Applicative
import qualified Control.Monad as Monad
import qualified Control.Monad.Trans as Trans
import qualified Control.Monad.State as State
import qualified Data.List.Split as Split

type Room = (Int, Int, Int, Int)

main = do
    n <- getLine
    rs <- putRooms (read n)
    let rs' = Split.chunksOf limitRoom $ zipWith (++) (repeat " ") (show . getValue <$> rs)
    Monad.forM_ [1..(limitBuilding*limitFloor)] $ \bf -> do
        putStrLn $ concat $ rs' !! (bf-1)
        if ((bf `mod` limitFloor == 0) && bf /= (limitBuilding*limitFloor))
            then putStrLn "####################"
            else return ()

putRooms :: Int -> IO [Room]
putRooms n = (`State.execStateT` officialHouse) $ do
    Monad.forM_ [1..n] $ \_ -> do
        room <- Trans.lift $ toRoom . map (read :: String -> Int) . words <$> getLine
        State.modify (`updateRoom` room)

limitBuilding :: Int
limitBuilding = 4

limitFloor :: Int
limitFloor = 3

limitRoom :: Int
limitRoom = 10

officialHouse :: [Room]
officialHouse = [ (b,f,r,0) | b <- [1..limitBuilding],
                              f <- [1..limitFloor],
                              r <- [1..limitRoom] ]

toRoom :: [Int] -> Room
toRoom [b,f,r,v] = (b,f,r,v)

getValue :: Room -> Int
getValue (_, _, _, v) = v

updateRoom :: [Room] -> Room -> [Room]
updateRoom [] _ = []
updateRoom (room1@(b1,f1,r1,v1):rs) room2@(b2,f2,r2,v2)
    | (b1,f1,r1) == (b2,f2,r2) = (b1,f1,r1,(v1 + v2)) : rs
    | otherwise                = room1 : updateRoom rs room2

Measured memory_bytes: 4776
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b,c,d,e;
  
  cin >> a;
 
  b = a / 1000;
  c = a / 100 % 10;
  d = a / 10 % 10;
  e = a % 10;
  
  if (((b == c) && (c == d)) || ((c == d) && (d == e)))
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3632
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>

namespace adaptor = boost::adaptors;

void solve()
{
    int64_t N, M;
	std::cin >> N >> M;
	std::vector<int64_t> k(M);
	std::vector<std::vector<int64_t>> s(M);
	for (int64_t i = 0; i < M; i++) {
		std::cin >> k[i];
		s[i].resize(k[i]);
		for (int64_t j = 0; j < k[i]; j++) {
			std::cin >> s[i][j];
			s[i][j]--;
		}
	}
	std::vector<int64_t> p(M);
	for (int64_t i = 0; i < M; i++) {
		std::cin >> p[i];
	}

	int64_t ans = 0;
	for (int64_t bit = 0; bit < (1 << N); bit++) {
		bool ok = true;
		for (int64_t i = 0; i < M; i++) {
			int64_t count = 0;
			for (int64_t sw : s[i]) {
				if (bit & (1 << sw)) {
					count++;
				}
			}
			count %= 2;
			if (count != p[i]) {
				ok = false;
			}
		}
		if (ok) {
			ans++;
		}
	}

	std::cout << ans << std::endl;

}

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


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

ll dp[3001][3001][2];

ll solve(vector<int>& v, int i, int j, bool turn)
{
	if (i > j)//invalid subarray
		return 0;

	if (dp[i][j][turn] != -1)
		return dp[i][j][turn];

	if (turn == 1)
	{

		return dp[i][j][turn] = max(v[i] + solve(v, i + 1, j, 0), v[j] + solve(v, i, j - 1, 0));
	}
	else
		return dp[i][j][turn] = min(solve(v, i + 1, j, 1), solve(v, i, j - 1, 1));
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n;
	cin >> n;
	std::vector<int> v(n + 1);
	memset(dp, -1, sizeof dp);
	ll sum = 0;
	for (ll i = 1; i <= n; i++)
	{
		cin >> v[i];
		sum += v[i];
	}

	ll scoreX = solve(v, 1, n, 1);
	ll scoreY = (sum - (scoreX));//X+Y=sum
	cout << scoreX - scoreY;
}

Measured memory_bytes: 144584
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace AtCoder
{
    static class Program
    {
        static void Main()
        {
            //ここから

            var f = IO.ReadLineToIntList();
            var s = IO.ReadLineToIntList();

            int ans = f[0] < s[0] ? 1 : 0;

            //ここまで

            Console.WriteLine(ans);
            Console.ReadKey();
        }

    }

    static class Func
    {
        static public long mod = 1000000007;
        static public void Swap<T>(ref T a, ref T b) { T temp = a; a = b; b = temp; }
        static public long GCD(long a, long b) { return b != 0 ? GCD(b, a % b) : a; }
        static public long LCM(long a, long b) { return (long)a * b / GCD(a, b); }
        static public long Factorial(long a) { return a == 1 ? a : a * Factorial(a - 1); }


        public static double ToAngle(this double radian)
        {
            return (double)(radian * 180 / Math.PI);
        }

        public static double ToRadian(this double angle)
        {
            return (double)(angle * Math.PI / 180);
        }

        static public long Conbination(long n,long m)
        {
            if (m == 0) return 1;
            if (n == 0) return 0;
            return n * Conbination(n - 1, m - 1) / m;
        }

        static public void Factoring(long num, ref long[] vs)
        {
            if (num == 1)
            {
                vs[1]++;
            }
            for (long i = 2; i < Math.Sqrt(num); i++)
            {
                if (num % i == 0)
                {
                    vs[i]++;
                    Factoring(num / i, ref vs);
                }
            }
            vs[1]++;
        }
    }

    static class IO
    {
        static public string ReadLineToString() { return Console.ReadLine(); }

        static public int ReadLineToInt() { return int.Parse(Console.ReadLine()); }
        static public long ReadLineToLong() { return long.Parse(Console.ReadLine()); }
        static public List<string> ReadLineToStringList() { return Console.ReadLine().Split(' ').ToList(); }

        static public List<int> ReadLineToIntList() { return Console.ReadLine().Split(' ').Select(int.Parse).ToList(); }
        static public List<long> ReadLineToLongList() { return Console.ReadLine().Split(' ').Select(long.Parse).ToList(); }

        static public List<double> ReadLineToDoubleList() { return Console.ReadLine().Split(' ').Select(double.Parse).ToList(); }

        static public void WriteStrings(object[] strings) { foreach (var o in strings) { Console.Write(o + " "); } }
    }
}

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

int main(){
    string s,t; cin >> s >> t;
    bool found = true;
    for(int i=0; i<s.size(); i++){
        if(s[i] != t[i]) found = false;
    }

    if(found) cout << "Yes";
    else cout << "No";
    cout << endl;
}

Measured memory_bytes: 3596
#ifdef FAIRLY_LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <iostream>
#include <vector>
using namespace std;

const int MAX_SZ = 1e5 + 1;

typedef long long int ll;

int main() {
#ifdef FAIRLY_LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    int n;
    vector<int> cnt(MAX_SZ);
    ll sum = 0;

    cin >> n;
    for (int i = 0; i < n; ++i) {
        int a;
        cin >> a;

        cnt[a]++;
        sum += a;
    }

    int q;
    cin >> q;
    while (q --> 0) {
        ll b, c;

        cin >> b >> c;

        sum += cnt[b] * (c - b);
        cnt[c] += cnt[b];
        cnt[b] = 0;

        cout << sum << '\n';
    }
    return 0;
}

Measured memory_bytes: 3732
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
using namespace std;
typedef string::const_iterator State;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 1e18
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 998244353
#define REP(i,n) for(long long i = 0;i < n;++i)    
#define seg_size 524288
int main() {
	cout << fixed;
	cout << setprecision(20);
	while (true) {
		int n, m, p, a, b;
		cin >> n >> m >> p >> a >> b;
		if (n == 0) return 0;
		vector<double> tori;
		REP(i, n) {
			double a;
			cin >> a;
			tori.push_back(a);
		}
		vector<pair<int, double>> vertexs[40];
		REP(i, p) {
			int a, b;
			cin >> a >> b;
			double c;
			cin >> c;
			vertexs[a].push_back(make_pair(b, c));
			vertexs[b].push_back(make_pair(a, c));
		}
		long double dp[31][(1LL << 9LL)] = {};
		int visited[31][(1LL << 9LL)] = {};
		REP(i, 31) {
			REP(q, (1LL << 9LL)) {
				dp[i][q] = LONG_INF;
			}
		}
		dp[a][0] = 0;
		priority_queue < tuple<long double, int, int>, vector<tuple<long double, int, int>>, greater < tuple<long double,int,int >> > next;
		next.push(make_tuple(0, a, 0));
		while (next.empty() == false) {
			tuple<long double, int, int> now = next.top();
			next.pop();
			if (visited[get<1>(now)][get<2>(now)] == 0) {
				visited[get<1>(now)][get<2>(now)] = 1;
				int here = get<1>(now);
				for (int i = 0; i < n; ++i) {
					if ((get<2>(now) & (1LL << i)) == 0) {
						int next_cost = 1LL << i;
						next_cost += get<2>(now);
						for (int q = 0; q < vertexs[here].size(); ++q) {
							long double next_time = get<0>(now) + vertexs[here][q].second / tori[i];
							if (dp[vertexs[here][q].first][next_cost] > next_time) {
								dp[vertexs[here][q].first][next_cost] = next_time;
								next.push(make_tuple(next_time, vertexs[here][q].first, next_cost));
							}
						}
					}
				}
			}
		}
		long double ans = LONG_INF;
		REP(q, (1LL << 9LL)) {
			ans = min(ans, dp[b][q]);
		}
		if (ans == LONG_INF) {
			cout << "Impossible" << endl;
		}
		else {
			cout << ans << endl;
		}
	}
}


Measured memory_bytes: 6456
/** 
 * Dont raise your voice, improve your argument.
 * --Desmond Tutu
 */

#include <bits/stdc++.h>
using namespace std;

#define DEBUG
#ifndef DEBUG
#define endl "\n"
#endif

const double PI=3.1415926535897932384626433;
typedef long long ll;
#define fori(n) for(ll i=0; i<(n); i++)

#define cins(s) string s; cin>>s;
#define cini(i) int i; cin>>i;
#define cinll(l) ll l; cin>>l;
#define cind(d) double d; cin>>d;
#define cinai(a, n) vi a(n); fori(n) { cin>>a[i]; }
#define cinall(a, n) vll a(n); fori(n) { cin>>a[i]; }
#define cinas(s, n) vs s(n); fori(n) { cin>>s[i]; }

typedef pair<int, int> pii;
typedef pair<double,double> pdd;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<string> vs;
typedef vector<ll> vll;

void solve() {
    cini(m1);
    cini(d1);
    cini(m2);
    cini(d2);
    cout<<(m1!=m2)<<endl;
}

int main() {
cin.tie(nullptr);
std::ios::sync_with_stdio(false);
        solve();
}



Measured memory_bytes: 256
X = int(input())

dp = [-1] * (X + 1)
a = [100, 101, 102, 103, 104, 105]
m = [1000000] * 6
dp[0] = 0
for i in range(6):
    for j in range(X + 1):
        if dp[j] >= 0:
            dp[j] = m[i]
        elif j < a[i] or dp[j - a[i]] <= 0:
            dp[j] = -1
        else:
            dp[j] = dp[j - a[i]] - 1
            
print(int(dp[-1] >= 0))


Measured memory_bytes: 40304
n, m = map(int, input().split())
a = [input() for _ in range(n)]
b = [input() for _ in range(m)]
f = False
for i in range(n - m + 1):
    for j in range(n - m + 1):
        ok = True
        for k in range(m):
            for l in range(m):
                if a[i + k][j + l] != b[k][l]:
                    ok = False
                    break
            if not ok: break
        if ok:
            f = True
            break
    if f: break
if f: print('Yes')
else: print('No')


Measured memory_bytes: 3064
/*
貪欲
後ろから見る
DP
順位表をチェック
二分探索
不変なもの・偶奇に注目

*/
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include <cmath>
#include <limits>
#include <iostream>
#include <map>
#include<tuple>
#include<set>
using namespace std;
#define INF 1LL<<60
#define MAX 100000
#define MOD 1000000007
typedef long long ll;
//typedef pair<ll,int> P;
//typedef pair< pair<int,int>,pair<int,int> > p;
//#define int ll int main->signed main
#define bit(n,k) ((n>>k)&1) /*nのk bit目*/
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)
struct edge{ll to,cost,val;};
template<class T,class U>bool chmin(T&a,const U&b){if(a<=b)return false;a=b;return true;}
template<class T,class U>bool chmax(T&a,const U&b){if(a>=b)return false;a=b;return true;}
//__builtin_popcount(S);
//C.erase(unique(C.begin(),C.end()),C.end());

//http://kmjp.hatenablog.jp/entry/2018/11/26/0900

ll C[2100000],M[2100000],CM[2100000];

int main(){
    int N; string S; int Q;
    cin>>N>>S>>Q;
    for(int i=0;i<N;i++){
        M[i+1]+=M[i]+(S[i]=='M');
        C[i+1]+=C[i]+(S[i]=='C');
        CM[i+1]=CM[i];
        if(S[i]=='C'){
            CM[i+1]+=M[i];
        }
    }
    for(int i=N+1;i<=2000000;i++){
        C[i]=C[i-1];
        M[i]=M[i-1];
        CM[i]=CM[i-1];
    }
    while(Q--){
        int K;
        cin>>K;
        ll ret=0;
        for(int i=0;i<N;i++){
            if(S[i]=='D'){
                ll cm=CM[i+K]-CM[i];
                ll mi=M[i]*(C[i+K]-C[i]);
                //cout<<C[i+]<<endl;
                ret+=cm-mi;
                //cout<<ret<<endl;
            }
        }
        cout<<ret<<endl;
    }

}


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

    public class Main extends PrintWriter {
        Main() { super(System.out, true); }
        Scanner sc = new Scanner(System.in);
        public static void main(String[] $) {
            Main o = new Main(); o.main(); o.flush();
        }

        void main(){
            int A = Integer.parseInt(sc.next());
            int B = Integer.parseInt(sc.next());
            int C = Integer.parseInt(sc.next());
            int D = A + B + C;
            if(D >= 22){
                print("bust");
            }
            else{
                print("win");
            }
    }
}


Measured memory_bytes: 23892
using System;
using System.Collections.Generic;

namespace ITP1_8_C
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] memo = new int[26];
            while (true)
            {
                string text = Console.ReadLine();
                if (string.IsNullOrEmpty(text))
                    break;

                foreach (var t in text)
                {
                    char ch = char.ToLower(t);
                    if ('a' <= ch && ch <= 'z')
                        memo[ch - 'a']++;
                }
            }

            for(int i = 0; i < 26; i++)
            {
                Console.WriteLine("{0} : {1}", (char)('a' + i), memo[i]);
            }
        }
    }
}

Measured memory_bytes: 9112
import collections

n, k = map(int, input().split())
d = collections.Counter(x % k for x in range(1, n + 1))
ans = 0
for a in range(k):
    b = (k - a) % k
    c = (k - a) % k
    if (b + c) % k == 0:
        ans += d[a] * d[b] * d[c]
print(ans)

Measured memory_bytes: 50928
use std::io;
use std::str::FromStr;

fn input_tuple() -> (u64, u64, u64) {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    let vec: Vec<u64> = line.split_whitespace().map(|s| s.parse().unwrap()).collect();
    (vec[0], vec[1], vec[2])
}

fn input_vec() -> Vec<u64> {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    line.split_whitespace().map(|s| s.parse().unwrap()).collect()
}

fn main() {
    let (n, m, x) = input_tuple();
    let mut books: Vec<Vec<u64>> = Vec::new();
    for _ in 0..n {
        let book = input_vec();
        books.push(book);
    }
    let mut min = 1000000000;
    for bit in 0..1<<n {
        let mut achievement: Vec<u64> = vec![0; m as usize];
        let mut fee = 0;
        for i in 0..n as usize {
            if bit & (1<<i) != 0 {
                fee += books[i][0];
                for j in 1..books[i].len() {
                    achievement[j - 1] += books[i][j];
                }
            }
        }
        let mut is_achieved = true;
        for a in achievement {
            if a < x {
                is_achieved = false;
            }
        }
        if is_achieved {
            if fee < min {
                min = fee;
            }
        }
    }
    if min == 1000000000 {
        println!("-1");
        return;
    }
    println!("{}", min);
    
}


Measured memory_bytes: 2176
n = input()
ti = map(int, raw_input().split())

m = input()
xi = []
for i in range(m):
	xi.append(map(int, raw_input().split()))

for i in range(len(xi)):
	p = xi[i][0]
	x = xi[i][1]
	s = 0
	for j in range(n):
		if(j == p-1):
			s += x
		else:
			s += ti[j]
	print s

Measured memory_bytes: 2568
#include <iostream>

using namespace std;

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

	int A[n][m];
	int b[m];

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			cin >> A[i][j];
		}
	}
	for (int k = 0; k < m; k++) {
		cin >> b[k];
	}

	for (int l = 0; l < n; l++) {
		int answer = 0;
		for (int h = 0; h < m; h++) {
			answer += A[l][h] * b[h];		
		}
		cout << answer << endl;
	}
}


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

int a,b,c[110],d,e;
   cin >> a>>b;
   for(int i=0;i<a;i++)
     cin >> c[i];
  
  d =1;
  
  for(int i=0;i<=a;i++){
     e += c[i];
     if(e<=b){
      d++;   
  }
  }
    cout << d << endl;
}
    


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

using namespace std;

#define endl '\n'

int main()
{
#ifdef jcg
	assert(freopen("input.in", "r", stdin));
	// assert(freopen("output.out", "w", stdout));
#else
#endif

	ios_base::sync_with_stdio(0);
	cin.tie(0);

	int n;
	cin >> n;

	vector<int> l(2*n);
	for (int &x : l) cin >> x;
	sort(l.begin(), l.end());

	int ans = 0;
	for (int i = 0; i < 2*n; i += 2)
		ans += l[i];
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 0
//#ifdef LOCAL
//#define DEBUG(s) cout << (s) << endl
//#define dump(x)  cerr << #x << " = " << (x) << endl
//#define BR cout << endl;
//#else
//#define DEBUG(s) do{}while(0)
//#define dump(x) do{}while(0)
//#define BR
//#endif


//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 20)
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl

//ここから編集する


int main() {
    int n;
    cin >> n;
    vector<int> v(26,INF);
    rep(i,0,n){
        string s;
        cin >> s;
        vector<int> w(26,0);
        rep(j,0,s.size()){
            w[s[j] - 'a']++;
        }
        rep(j,0,26){
            v[j] = min(v[j],w[j]);
        }
    }
    rep(i,0,26){
        rep(j,0,v[i]){
            cout << (char)(i + 'a');
        }
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
def _main():
  N = int(input())
  lst = list(map(int, input().split()))
  K = int(input())
  key_lst = list(map(int, input().split()))

  ans = 0
  for k in range(K):
    if search(lst, key_lst[k]): ans += 1

  print(ans)

def search(lst, key):
  lst.append(key)
  i = 0
  while lst[i] != key:
    i += 1
  lst.pop()
  return len(lst) != i

if __name__ == '__main__':
  _main()


Measured memory_bytes: 6556
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy, copy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
A = LIST()

dic = defaultdict(int)
for x in A:
	dic[x] += 1

total = 0
for x in dic:
	total += dic[x]*(dic[x]-1)//2

for x in A:
	print(total-dic[x]+1)


Measured memory_bytes: 27304
// by Balloons
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define mpr make_pair
#define debug() puts("okkkkkkkk")
#define rep(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)

using namespace std;

typedef long long LL;

const int inf = 1e9, maxn=4005;

int n;
char s[maxn][3];
int dp[maxn][maxn], bit[2][maxn], a[maxn];
int cost[maxn][maxn][2];
void add(int bs,int x){for(int i=x;i<=n;i+=(i&(-i)))++bit[bs][i];}
int query(int bs,int x){int r=0;for(;x;x-=(x&(-x)))r+=bit[bs][x];return r;}

int main(){
	scanf("%d",&n);
	for(int i=1;i<=2*n;i++){
		scanf("%s%d",s[i] + 1,&a[i]);
	}
	for(int i=1;i<=2*n;i++){
		if(s[i][1] == 'W'){
			for(int j=0;j<=n;j++)
				cost[a[i]-1][j][0] = (i-1) - query(0,a[i]-1) - query(1,j); 
			add(0, a[i]);
		}else{
			for(int j=0;j<=n;j++)
				cost[j][a[i]-1][1] = (i-1) - query(0,j) - query(1,a[i]-1);
			add(1, a[i]);
		}
	}
	
	dp[0][0] = 0;
	for(int i=0;i<=n;i++)
		for(int j=0;j<=n;j++)if(i+j){
			dp[i][j] = inf;
			if(i)
				dp[i][j] = min(dp[i][j], dp[i-1][j]+cost[i-1][j][0]);
			if(j)
				dp[i][j] = min(dp[i][j], dp[i][j-1]+cost[i][j-1][1]);
		}
	printf("%d\n",dp[n][n]);

	return 0;
}


Measured memory_bytes: 95872
#include <iostream>
#include <string>

using namespace std;

int main() {
    while (true) {
        string S;
        cin >> S;
        if (S == "-") break;

        int N = S.size();

        int M;
        cin >> M;

        for (int i = 0; i < M; ++i) {
            S += S;
            int h;
            cin >> h;
            S = S.substr(h, N);
        }

        cout << S << endl;
    }
    return 0;
}



Measured memory_bytes: 3192
import fractions
A,B = list(map(int,input().split()))

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

x=fractions.gcd(A,B)
#print(x)

y = prime_factorize(x)
#print(y)

print(len(set(y))+1)


Measured memory_bytes: 5048
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    int sum=0,flag=1,flag2=1;
    string s;
    cin>>s;
    int l=s.length();
    sum+=((l-1)*9);
    int i=0;
    //cout<<sum<<endl;
    if(l==1)
    {
        cout<<s<<endl;
        return 0;
    }
    if(s[i]!='9')
    {
        sum+=s[i]-'0'-1;
        int j=1;
       while(j<l)
       {
           if(s[j]!='9')
           {
               //cout<<"dgsrh"<<endl;
               flag2=0;
               break;
           }
           j++;
       }
       if(flag2){
            //cout<<"falg"<<endl;
        sum+=1;
       }
    }
    else
    {
        //cout<<flag<<endl;
        i=1;
       while(i<l)
       {
           if(s[i]!='9')
           {
               //cout<<"dgsrh"<<endl;
               sum+=8;
               flag=0;
               break;
           }
           i++;
       }
       if(flag){
            //cout<<"falg"<<endl;
        sum+=9;
       }
    }
    cout<<sum<<endl;

    return 0;

}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
bool a[26];
int main()
{

	string s; cin >> s; int f = 0;
	for (int i = 0; i < s.size(); ++i)
	{
		a[s[i] - 'a']=true;
	}
	for (int i = 0; i < 26; ++i)
	{
		if (!a[i]) {
			cout << (char)(i + 'a');
			f = 1;
			break;
			
		}
	}
	if (!f)
		cout << "None";
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long n,x,ans=0;
  cin >> n >> x;
  long long a[n];
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  sort(a,a+n);
  for(int i=0;i<n;i++){
    if(x<a[i]){
      cout << ans << endl;
      return 0;
    }
    x-=a[i];
    ans++;
  }
  if(ans>0 and x>0){
    cout << ans-1 << endl;
  }else{
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define ii pair<int,int>
#define F first
#define S second
#define pb push_back
#define pf push_front
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fore(i,a,b) for(int i = a;i < b; i+= 1)
#define forr(i,a) for(int i = a; i >= 0; i--)
#define fori(i,m) for(auto i = m.begin(); i != m.end(); i++) 
#define sz(s) int(s.size())
#define cls(a,car) memset(a,car,sizeof (a))
using namespace std;
typedef long long ll;
const int N = 3 * 1e5 + 5;
const ll mod = 1e9 + 7;
const int INF = INT_MAX;
const ll INFCAD  = ll(INT_MAX) * 2 + 1;
vector<int> G[N];
int main(){/*
    freopen("in","r",stdin);
    freopen("out","w",stdout);*/
    char x,y;
    cin >> x >> y;
    cout << (x == y ? "H": "D") << endl;
    return 0;
}   

Measured memory_bytes: 7296
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<functional>
#include<math.h>

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

int main() {
	int n;
	cin >> n;
	double ans = 0;
	rep(i, n) {
		double x;
		string u;
		cin >> x >> u;
		if (u == "JPY") {
			ans += x;
		}
		else {
			ans += 380000.0*x;
		}
	}
	printf("%.10f\n", ans);

	return 0;
}

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

int main(){
    long long a,b,k;
    long long ans_a,ans_b;
    cin>>a >> b>> k;
    if (a-k<0)
    {
        ans_a = 0;
        if (b-(k-a)<0)
        {
            ans_b = 0;
        } else {
            ans_b = b-(k-a);
        }
    } else
    {
        ans_a = a-k;
        ans_b = b;
    }

    cout<<ans_a<<" "<<ans_b<<endl;
}

Measured memory_bytes: 256
/* Bismillahir Rahmanir Rahim */

#include <bits/stdc++.h>

#define rep(i, n)	for(int i=0;i<n;i++)
#define repn(i, n)	for(int i=1;i<=n;i++)
#define set(i, n)	memset(i, n, sizeof(i))

#define pb	push_back
#define f	first
#define s	second

using namespace std;

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

const int N = 100007;

ll n, A[N], B[N];

int main(){
	scanf("%lld", &n);
	repn(i, n) scanf("%lld %lld", &A[i], &B[i]);
	ll add = 0;
	for(int i=n;i>=1;i--){
		ll cur = A[i] + add;
		ll fuck = cur / B[i];
		if(cur % B[i]) fuck++;
		fuck *= B[i];
		fuck -= cur;
		add += fuck;
	}
	cout << add << endl;
	return 0;
}



Measured memory_bytes: 1920
#include<bits/stdc++.h>
using namespace std;
string Replace(string s,int a,int b,string t){
  for(int i=a; i<=b; i++){
        s[i]=t[i-a];
  }
  return s;
}

string Reverse(string s,int a,int b){
  int i=a,j=b;
  while(i<j){
        swap(s[i],s[j]);
        i++;
        j--;
  }
  return s;
}

void Print(string s,int a,int b){
  for(int i=a; i<=b; i++){
        cout << s[i];
  }
  cout << endl;
}

int main(){
  string str,command,t;
  cin >> str;
  int q,a,b;
  cin >> q;
  for(int i=0; i<q; i++){
        cin >> command;
        cin >> a >> b;
        if(command=="replace"){
          cin >> t;
          str=Replace(str,a,b,t);
        } else if(command=="reverse"){
          str = Reverse(str,a,b);
        } else if(command == "print"){
          Print(str,a,b);
        }
  }
  return 0;
}


Measured memory_bytes: 3208
#include <iostream>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <algorithm>
#include <functional>
#include <cstring>
#include <limits.h>
#include <bitset>
#include <complex>
#include <cassert>
#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)
#define SZ(i) ((int)i.size())
#define GI(i) (scanf("%d",&i))
#define GLL(i) (scanf("%lld",&i))
#define GD(i)  (scanf("%lf",&i))
#define PB          push_back
#define MP          make_pair
#define MT          make_tuple
#define GET0(x)     (get<0>(x))
#define GET1(x)     (get<1>(x))
#define GET2(x)     (get<2>(x))
#define ALL(X)      (X).begin(),(X).end()
#define LLMAX       (1LL<<60)
#define LLMIN       -(1LL<<60)
#define IMAX        (1<<30)
#define IMIN        -(1<<30)
typedef long long LL;
using namespace std;

const int VERTICAL = 0;
const int HORIZONTAL = 1;

int main(void){
    LL W,H;
    GLL(W);GLL(H);
    vector<pair<LL,int> > edge;
    REP(i,W){
        LL p;
        GLL(p);
        edge.PB(MP(p,VERTICAL));
    }
    REP(i,H){
        LL q;
        GLL(q);
        edge.PB(MP(q,HORIZONTAL));
    }
    sort(ALL(edge));
    LL numHorizontal = 0;
    LL numVertical = 0;
    LL ans=0;
    for(auto e:edge){
        // printf("e.first=%lld e.second=%d\n",e.first,e.second);
        if(e.second==VERTICAL){
            ans+=(H+1-numHorizontal)*e.first;
            numVertical++;
        }else{
            ans+=(W+1-numVertical)*e.first;
            numHorizontal++;
        }
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 6384
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
using namespace __gnu_pbds;
using namespace std;
 
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
typedef long long ll;
typedef long double ld;
 
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n;
	cin >> n;
	vector <ll> arr(n);
	ll c = 0;
	for (int z=0;z<n;z++){
		cin >> arr[z];
		c = c ^ arr[z];
	}
	if (c == 0) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG true
// sort(a.begin(), a.end(), std::greater<int>());

/*
std::vector<std::string> split(const std::string &input, char delimiter)
{
    std::istringstream stream(input);

    std::string field;
    std::vector<std::string> result;
    while (std::getline(stream, field, delimiter))
    {
        result.push_back(field);
    }
    return result;
}
*/

int main()
{
    char a, b;
    cin >> a >> b;
    if (a == 'H')
        cout << b << endl;
    else
    {
        if (b == 'D')
            cout << 'H' << endl;
        else
            cout << 'D' << endl;
    }
    return 0;
}

Measured memory_bytes: 256
open System

[<Literal>] 
let m = 2019

let S = Console.ReadLine()

let cusum = 
    let x = Array.zeroCreate (1 + S.Length) 
    let y = 
        let y = ref 1
        fun() -> 
            let r = !y
            y := !y * 10 % m 
            r
    for i in 1 .. S.Length do 
        let i' = S.Length - i;
        x.[i] <- ((int << string) S.[i'] * y() + x.[i - 1]) % m  
    x

cusum
|> Array.fold (fun (m, ans) x -> 
    if Map.containsKey x m then 
        let m' = Map.add x (m.[x] + 1) m
        (m', ans + m.[x])
    else
        let m' = Map.add x 1 m
        m', ans
    ) (Map.empty, 0)
|> snd
|> printfn "%i"

Measured memory_bytes: 49984
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) #x << "=" << x << "  " <<
using namespace std;
using ll = long long;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

const int MXN = 1e5 + 5;
const int MOD = 1e9 + 7;
int add(int x, int y) { return (x += y) < MOD ? x : x - MOD; }
int sub(int x, int y) { return (x -= y) >= 00 ? x : x + MOD; }
int mul(int x, int y) { return (ll) x * y % MOD; }
int pwr(int x, int p) {
  if (p == 0) return 1;
  if (p % 2) return mul(x, pwr(x, p - 1));
  return pwr(mul(x, x), p / 2);
}

int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  int n;
  cin >> n;
  vector<vector<int>> comps;
  vector<pair<int, int>> sol;
  if (n % 2) {
    comps.push_back({n--});
  }
  for (int i = 1; i <= n / 2; ++i) {
    for (int x : {i, n - i + 1}) {
      for (auto &comp : comps) {
        for (int y : comp) {
          sol.emplace_back(x, y);
        }
      }
    }
    comps.push_back({i, n - i + 1});
  }
  cout << sol.size() << '\n';
  for (auto &it : sol) {
    cout << it.first << ' ' << it.second << '\n';
  }
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <cmath>

using namespace std;
typedef long long i64;
typedef long double ld;
typedef pair<i64,i64> P;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);++(i))

int n;

vector<int> edges[1010];

int x[1010];


int main()
{
	cin >> n;
	for(int i = 2;i <= n;i++)
	{
		int a;
		cin >> a;
		edges[a].push_back(i);
	}
	for(int i = 1;i <=n;i++)
	{
		cin >> x[i];
	}

	vector<int> vec;
	{
		queue<int> que;
		que.push(1);
		while(!que.empty())
		{
			int v = que.front();
			que.pop();
			vec.push_back(v);
			for(int to : edges[v])
			{
				que.push(to);
			}
		}
	}

	reverse(vec.begin(),vec.end());

	vector<int> dp(n);

	for(int v : vec)
	{

		vector<int> cur(x[v] + 1,1e9);
		cur[0] = 0;

		for(int ch : edges[v])
		{
			vector<int> before = move(cur);
			cur.assign(x[v] + 1 , 1e9);
			for(int i = 0;i <= x[v];i++)
			{
				if(i + x[ch] <= x[v]) cur[i + x[ch]] = min(cur[i + x[ch]] , before[i] + dp[ch]);
				if(i + dp[ch] <= x[v]) cur[i + dp[ch]] = min(cur[i + dp[ch]] , before[i] + x[ch]);
			}
		}

		dp[v] = *min_element(cur.begin(),cur.end());
	}

	if(dp[1] < 1e9)
	{
		cout << "POSSIBLE" << endl;
	}
	else
	{
		cout << "IMPOSSIBLE" << endl;
	}


		


}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<pair<int,int>> vp;
typedef pair<int,int> pii;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
#define sz(a) a.size()
const ll MOD = 1e9+7;
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
//cout << 'H' << endl;
/*--------------------------------------------*/

int main(){
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);

    int a,b;cin >> a >> b;

    cout << (6 / a) / b << endl;

    

    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	int n;
	cin>> n;
	vector<int> h(n);
	vector<ll> dp(n);
	for(int i = 0;i< n;i++){
		cin >> h[i];
	}
	dp[0] = 0;//一段目
	dp[1] = abs(h[1] - h[0]);//二段目
	for (int i = 2; i < n; i++)
	{
		dp[i] = min(dp[i - 1] + abs(h[i] - h[i-1]),dp[i - 2]+abs(h[i] - h[i - 2]));
	}
	cout << dp[n - 1]<< endl;
	
	return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl

using namespace std;

typedef long long int ll;

template<typename T>
vector<T> make_v(size_t a, T b) {
    return vector<T>(a, b);
}

template<typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int D;
    cin >> D;
    cout << "Christmas";
    REP(i, D, 25) {
        cout << " Eve";
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>

using namespace std;

//I imitated Ant Book version 1: P.84.

int n,q,com,x,y;
int rank[10000],parent[10000];

int find(int x){
	if(x == parent[x])return x;
	else{
		return parent[x] = find(parent[x]);
	}
}

bool isSame(int x,int y){
	return find(x) == find(y);
}

void unite(int x,int y){
	x = find(x);
	y = find(y);

	if(x == y)return;

	if(rank[x] < rank[y]){
		parent[x] = y;
	}else{
		parent[y] = x;
		if(rank[x] == rank[y])rank[x]++;
	}
}

int main(){

	scanf("%d %d",&n,&q);

	for(int i = 0; i < n; i++){
		rank[i] = 0;
		parent[i] = i;
	}

	for(int i = 0; i < q; i++){
		scanf("%d %d %d",&com,&x,&y);

		if(com == 1){
			if(isSame(x,y))printf("1\n");
			else{
				printf("0\n");
			}
		}else{
			if(isSame(x,y))continue;

			unite(x,y);
		}
	}

	return 0;
}



Measured memory_bytes: 2732
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;
typedef string::const_iterator State;
#define Ma_PI 3.141592653589793
#define eps 1e-5
#define LONG_INF 2000000000000000000LL
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL
#define MOD 998244353LL
#define seg_size 262144
#define REP(a,b) for(long long a = 0;a < b;++a)
vector<long long> member;
vector<long long> food;
long long n, k;
long long solve(long long now) {
	long long now_cost = 0;
	if (now == 0) {
		REP(i, member.size()) {
			now_cost += member[i];
		}
	}
	else {
		for (int i = 0; i < food.size(); ++i) {
			long long hoge = now / food[i];
			now_cost += max(0LL, member[i] - hoge);
		}
	}
	if (now_cost > k) return 0;
	return 1;
}
int main(){
	cin >> n >> k;
	REP(i, n) {
		long long a;
		cin >> a;
		member.push_back(a);
	}
	REP(i, n) {
		long long a;
		cin >> a;
		food.push_back(a);
	}
	sort(member.begin(), member.end());
	sort(food.begin(), food.end());
	reverse(food.begin(), food.end());
	long long bot = 1e12;
	long long top = -1;
	while(bot - top > 1) {
		long long mid = (top + bot) / 2LL;
		if (solve(mid) == 1) {
			bot = mid;
		}
		else {
			top = mid;
		}
	}
	cout << bot << endl;
}

Measured memory_bytes: 4848
def cross(x, y):
    return (x.conjugate() * y).imag

def is_parallel(x, y):
    if abs(cross(x, y)) < 1e-10:
        return True
    return False

n = int(input())
for i in range(n):
    x1, y1, x2, y2, x3, y3, x4, y4 = map(float, input().split())
    a = complex(x2, y2) - complex(x1, y1)
    b = complex(x4, y4) - complex(x3, y3)    
    if is_parallel(a, b):
        print('YES')
    else:
        print('NO')

Measured memory_bytes: 7760
#include <cstdio>
#include <vector>
#define repeat(i, n) for (int i = 0; (i) < int(n); ++(i))
#define repeat_from(i, m, n) for (int i = (m); (i) < int(n); ++(i))
using ll = long long;
using namespace std;

constexpr int mod = 1e9+7;
vector<vector<int> > calc_choose(int n) { // O(n^2)
    vector<vector<int> > dp(n + 1);
    dp[0].assign(1, 1);
    repeat (i, n) {
        dp[i + 1].resize(i + 2);
        repeat (j, i + 2) {
            auto & it = dp[i + 1][j];
            if (j - 1 >= 0) {
                it += dp[i][j - 1];
                if (it >= mod) it -= mod;
            }
            if (j != i + 1) {
                dp[i + 1][j] += dp[i][j];
                if (it >= mod) it -= mod;
            }
        }
    }
    return dp;
}

int main() {
    // input
    int a, b; scanf("%d%d", &a, &b);
    // solve
    auto choose = calc_choose(a + b + 3);
    ll result = 0;
    result += a + 1;
    repeat_from (x, 1, b + 1) {
        ll acc = 0;
        repeat_from (y, b - x, a + 1) {
            acc += choose[b - 1][x - 1];
            if (acc >= mod) acc -= mod;
            int nb = b - x;
            repeat (z, nb) {
                int ny = y + (nb - 1 - z);
                if (ny <= a) result += acc * choose[nb - 1][z] % mod;
            }
        }
    }
    result %= mod;
    // output
    printf("%lld\n", result);
    return 0;
}


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

int main() {
    int n, q, time[100005], t = 0, times = 0;
    string name[100005];
    cin >> n >> q;
    for (int i = 0; i < n; ++i) {
        cin >> name[i] >> time[i];
        times += time[i];
    }

    while (times > 0) {
        times = 0;
        for (int i = 0; i < n; ++i) {
            if (time[i] == 0) continue;
            else if (time[i] > q) {
                time[i] -= q;
                t += q;
            }
            else {
                t += time[i];
                time[i] = 0;
                cout << name[i] << ' ' << t << endl;
            }
            times += time[i];
        }
    }
    
    return 0;
}


Measured memory_bytes: 6320
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <cctype>
#include <algorithm>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define pb push_back
#define rng(x) x.begin(),x.end()
using namespace std;
typedef long long ll;
typedef vector<int> vi;

int main() {
  string s;
  cin >> s;
  int n = 12;
  int x = 0;
  vi a(12);
  rep(i,7) a[i] = i+1;
  rep(i,5) a[7+i] = 7+i-5;
  // for (int xs : a) cout<<xs<<endl;
  reverse(rng(a));
  rep(i,11) {
    if (isdigit(s[i])) x += (s[i]-'0')*a[i];
  }
  x %= 11;
  // cout<<x<<endl;
  if (s.back() == '?') {
    int ans = 0;
    if (x <= 1) ans = 0;
    else ans = 11-x;
    cout<<ans<<endl;
  } else {
    if (s.back() == '0') {
      x = (0-x+11)%11;
      string t = s;
      int ans = -1;
      int cnt = 0;
      rep(i,n) {
        if (s[i] == '?') {
          rep(j,10) if (a[i]*j%11 == x) {
            s[i] = '0'+j;
            cnt++;
            ans = j;
          }
        }
      }
      swap(s,t);
      x = (x+1)%11;
      rep(i,n) {
        if (s[i] == '?') {
          rep(j,10) if (a[i]*j%11 == x) {
            s[i] = '0'+j;
            cnt++;
            ans = j;
          }
        }
      }
      if (cnt >= 2) puts("MULTIPLE");
      else cout<<ans<<endl;
    } else {
      int y = 11-(s.back()-'0');
      x = (y-x+11)%11;
      int ans = -1;
      rep(i,n) {
        if (s[i] == '?') {
          rep(j,10) if (a[i]*j%11 == x) {
            s[i] = '0'+j;
            ans = j;
          }
        }
      }
      cout<<ans<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 3196
#include <iostream>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
using namespace std;
int gcd(int x, int y)
{
	if (y == 0) return x;
	return gcd(y, x % y);
}
int main()
{
	int a, b;
	cin >> a >> b;
	cout << gcd(max(a, b), min(a, b)) << endl;
	return 0;
}



Measured memory_bytes: 3116