akhauriyash/Code-Regression huggingface dataset:
macro_rules! scan {
    () => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().to_string()
        }
    };
    (;;$n:expr) => {
        (0..$n).map(|_| scan!()).collect::<Vec<_>>()
    };
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty;;$n:expr) => {
        (0..$n).map(|_| scan!($t;;)).collect::<Vec<_>>()
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    scan!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    scan!($($t),*)
        ).collect::<Vec<_>>()
    };
}

fn dfs(graph: &[Vec<usize>], v: usize, d: i64) -> bool {
    if v == graph.len() - 1 {
        return true;
    }
    if d == 0 {
        return false;
    }

    for &n in graph[v].iter() {
        if dfs(graph, n, d - 1) {
            return true;
        }
    }
    false
}

fn main() {
    let (n, m) = scan!(usize, usize);
    let mut graph: Vec<Vec<usize>> = (0..(n + 1)).map(|_| vec![]).collect();
    for _ in 0..m {
        let (a, b) = scan!(usize, usize);
        graph[a].push(b);
        graph[b].push(a);
    }

    if dfs(&graph, 1, 2) {
        println!("POSSIBLE");
    } else {
        println!("IMPOSSIBLE");
    }
}


Measured memory_bytes: 18684
#include <iostream>
#include <string>
#include <algorithm>

std::string s, t;

int main()
{
  std::cin >> s;
  std::cin >> t;

  std::sort(s.begin(), s.end());
  std::sort(t.begin(), t.end());
  reverse(t.begin(), t.end());

  if(s<t) std::cout << "Yes" << '\n';
  else std::cout << "No" << '\n';
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <cmath>
#include <algorithm>
#define rep( i, n, m ) for(int i = ( n ); i < ( m ); i++)
int main( void ){
	int n;
	if (!scanf( "%d", &n ))
		return 0;
	int* input = new int[n];
	rep( i, 0, n ){
		if (!scanf( "%d", &( input[ i ] )))
			return 0;
	}
	std::sort( input, input+n);
	int count = 0;
	for(int i = n - 1; i > 1; i--){
		for(int j = i - 1; j > 0; j--){
			int d = input[ i ] - input[ j ];
			for(int k = j - 1; k > -1; k--){
				if (d < input[ k ])
					count++;
				else
					break;
			}
			if (d > input[ j - 1 ])
				break;
		}
	}
	printf( "%d\n", count );
	return 0;
}


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

int main() {
    int a = 0, b = 0, c = 0;
    for (int i = 0; i < 3; i++) {
        char s; cin >> s;
        if (s == 'a') {
            a++;
        } else if (s == 'b') {
            b++;
        } else if (s == 'c') {
            c++;
        }
    }
    if (a == 1 && b == 1 && c == 1) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1LL << 60
typedef long long int LL;
const int MOD = 1000000007;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }
//sort(all(x))とするとソートできるよ
// 10^x は pow(10,(x)) 
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main(){
    // 入力
    int N;cin >> N;
    vector<int> t(N),x(N),y(N);
    rep(i,N)cin >> t[i] >> x[i] >> y[i];

    bool ans = true;    // 条件1、2を満たすかのフラグ

    rep(i,N) if(t[i] % 2 != (x[i] + y[i]) % 2) ans = false;     // 条件1をチェック

    if(ans) rep(i,N){                                           // 条件2をチェック
        if(i == 0){ 
            if(t[0] < x[0]+y[0]) ans = false;
        }
        else if (t[i] - t[i-1] < abs(x[i] - x[i-1]) + abs(y[i] - y[i-1])) ans = false;
    }

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

Measured memory_bytes: 1408
import qualified Data.ByteString.Char8 as BS
import Data.Int (Int64)

main :: IO ()
main = do
  [x, y] <- map read . words <$> getLine :: IO [Int64]
  print $ solve x y


solve :: Int64 -> Int64 -> Int64
solve n k =
  let t = n `mod` k
  in
    min t (k - t)

iter :: Int64 -> Int64 -> Int64
iter n k = abs $ n - k


test :: IO ()
test = do
  print $ solve 7 4
  print $ solve 2 6
  print $ solve 1000000000000000000 1
  putStrLn "test finished"

Measured memory_bytes: 508
using System;
using System.Collections.Generic;
using System.Linq;
class Ho{
  static void Main(){
    var n = int.Parse(Console.ReadLine());
    var aho = Console.ReadLine().Split();
    var k = new List<int>();
    foreach(var a in aho) {k.Add(int.Parse(a));}
    var ko = 0;
    for(var i = 0;i<n;i++){
    	for(var j = 0;j<n;j++){
          if(i==j) {continue;}
          ko+=k[i]*k[j];
        }  
    }
    Console.WriteLine(ko/2);
  }
}

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

using namespace std;

int main() {
    int N, M;
    cin >> N >> M;

    vector<int> k;
    vector<vector<int>> s(M);
    for (int i = 0; i < M; i++) {
        int tmpK;
        cin >> tmpK;
        k.push_back(tmpK);
        for (int j = 0; j < tmpK; j++) {
            int tmpS;
            cin >> tmpS;
            s.at(i).push_back(tmpS - 1);
        }
    }

    vector<int> p;
    for (int i = 0; i < M; i++) {
        int tmpP;
        cin >> tmpP;
        p.push_back(tmpP);
    }

    // スイッチの全探索 -> on/offなので、O(2^N)のビット全探索を行う

    int bulbLihtPattern = 0;
    for (int bits = 0; bits < (1 << N); bits++) {  // ビットバターン
        int onBulbCount = 0;
        for (int i = 0; i < M; i++) {  // 電球に対するスイッチ列
            int onSwitchCount = 0;
            for (int id : s.at(i)) {
                if (bits & (1 << id)) {
                    onSwitchCount++;
                }
            }
            if (onSwitchCount % 2 == p.at(i)) {
                onBulbCount++;
            }
        }
        if (onBulbCount == M) {
            bulbLihtPattern++;
        }
    }

    cout << bulbLihtPattern << endl;

    return 0;
}

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

int main() {
  
  int N; cin >> N; int64_t A[N + 1];
  
  A[0] = 2; A[1] = 1;
  
  for (int i = 2; i <= N; i++) {
    A[i] = A[i - 2] + A[i - 1];
  }
  
  cout << A[N] << endl;
  
}

Measured memory_bytes: 256
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
using namespace std;
typedef long long int lnt;
typedef pair<lnt,lnt> P;
const lnt INF = 0xffffffffffffff;
lnt d[10][10];
lnt x,y,z;
lnt used[10];
int main()
{while(1){
	int n;
	cin>>n;
	if(!n) return 0;
	fill(d[0],d[10]+10,INF);
	fill(used,used+10,0);
	for(lnt i=0;i<n;i++){
		cin>>x>>y>>z;
		used[x]=1;
		used[y]=1;
		d[x][y]=z;
		d[y][x]=z;
	}
	for(lnt i=0;i<10;i++){
		if(used[i]) d[i][i]=0;
	}
	for(lnt k=0;k<10;k++){
		for(lnt i=0;i<10;i++){
			for(lnt j=0;j<10;j++){
				d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
			}
		}
	}
	P ans=P(-1,INF);
	lnt sum;
	for(lnt i=0;i<10;i++){
		if(!used[i]) continue;
		sum=0;
		for(lnt j=0;j<10;j++){
			if(!used[j]) continue;
			sum+=d[i][j];
		}
		if(ans.second>sum){
			ans.first=i;
			ans.second=sum;
		}
	}
	cout<<ans.first<<' '<<ans.second<<endl;
}}

Measured memory_bytes: 1164
#include<stdio.h>

int main(void)
{
	int  a, b;
	scanf("%d %d", &a, &b);
	if (a < b)
	{
		printf("a < b\n");
	}
	else if (a > b)
	{
		printf("a > b\n");
	}
	else
	{
		printf("a == b\n");
	}

	return 0;

}

Measured memory_bytes: 1008
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main() {
    ll n,m,ans=0,cnt; cin>>n>>m;
    vector<vector<ll>> a(8,vector<ll>(n,0));
    rep(i,n){
        vector<ll> x(3,0);
        rep(j,3) cin>>x[j];
        rep(j,8){
            cnt=0;
            rep(k,3){
                if(j&(1<<k)) cnt+=x[k];
                else cnt-=x[k];
            }
            a[j][i]=cnt;
        }
    }
    rep(i,8){
        sort(al(a[i]));
        reverse(al(a[i]));
        cnt=0;
        rep(j,m) cnt+=a[i][j];
        ans=max(ans,cnt);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
const MOD: usize = 1000000007;

fn main() {
	proconio::input!(s: usize);
	let mut dp = vec![0; s + 1];
	dp[0] = 1;
	for n in 3..=s {
		let mut s = dp[n-1] + dp[n-3];
		if s > MOD {
			s -= MOD;
		}
		dp[n] = s;
	}
	println!("{}", dp[s]);
}

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

int n, m, x;
int c[12], a[12][12];

int main() {
    int ans = 1e8;
    scanf("%d %d %d", &n, &m, &x);
    for (int i = 0; i < n; i++) {
        scanf("%d", &c[i]);
        for (int j = 0; j < m; j++) scanf("%d", &a[i][j]);
    }
    
    for (int i = 0; i < (1 << n); i++) {
        int und[m];
        fill(und, und + m, 0);
        int cost = 0;
        for (int j = 0; j < n; j++) {
            if (!((i >> j) & 1)) continue;
            cost += c[j];
            for (int k = 0; k < m; k++) und[k] += a[j][k];
        }
        for (int j = 0; j < m; j++) {
            if (und[j] < x) break;
            if (j == m - 1) ans = min(ans, cost);
        }
    }
    printf("%d\n", ans == 1e8 ? -1 : ans);
    return 0;
}


Measured memory_bytes: 1732
import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int K = Integer.parseInt(scan.next());
        int S = Integer.parseInt(scan.next());
        int cou = 0;

        for(int i = 0;i<=K;i++){
            for(int j = 0;j<=K;j++){
                if(0<=S-i-j&&S-i-j<=K){
                    if(i+j+(S-i-j) == S){
                        cou++;
                    }
                }
            }
        }
        System.out.println(cou);
    }
}

Measured memory_bytes: 21844
_,M,*A=`dd`.split.map &:to_i
*c=(*b=(a=[z=0]*(2*M+1)))
A.each_cons(2){|l,r|
	l>r&&r+=M
	z+=r-l
	a[l+1]+=l
	a[r+1]-=l
	b[l+1]+=1
	b[r+1]-=1
}
1.upto(2*M){|i|
	a[i]+=a[i-1]
	b[i]+=b[i-1]
	c[i]=a[i]-b[i]*(i-1)
}
p z+A.map{|i|c[i]+c[i+M]}.min

Measured memory_bytes: 14476
//AOJ 0621
#include<cstdio>
#include<algorithm>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)

const char WBR[] = "WBR";

int N, M;
char flag[50][51];

int main()
{
  scanf( "%d%d", &N, &M );
  rep( i, N )
    scanf( "%s", flag[i] );

  int ans = 2501;
  
  repi( k, 1, N ) repi( l, k+1, N )
  {
    int cnt = 0;
    
    rep( i, N )
      cnt += M-std::count(flag[i], flag[i]+M, WBR[i<k?0:i<l?1:2] );

    ans = std::min( ans, cnt );
  }
  
  printf( "%d\n", ans );
    
  return 0;
}

Measured memory_bytes: 2688
#include<bits/stdc++.h>
using namespace std;
const int MAX = 2e5 ;
const int INF = 1e9 + 1e5 + 2;
const int mod= 1e9+7;
#define eps 1e-15
typedef long long ll;
int main()
{
    double l;

    cin>>l;

    double x=l/3.0;

    cout<<fixed<<setprecision(9)<<x*x*x;

















}


Measured memory_bytes: 384
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;

namespace atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var ab = Console.ReadLine().Split(' ').Select(num => int.Parse(num)).ToArray();
            var a = ab[0];
            var b = ab[1];

            Console.WriteLine(Math.Max(a + b, Math.Max(a - b, a * b)));
        }
    }
}

Measured memory_bytes: 28292
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
typedef long long ll;
bool comp(ll &a,ll &b){
  return a>b;
}
int main()
{
  int n;
  cin >> n;
  ll m;
  cin >> m;
  vector<ll> a(n);
  ll mm = 0;
  for(int i=0;i<n;++i){
    cin >> a[i];
    mm = max(mm,a[i]);
  }
  mm *= 2;
  
  sort(a.begin(), a.end(),comp);

  ll lb=0,ub=mm+1;
  while(ub-lb>1){
    ll mid = (ub+lb)/2;
    ll cnt=0;
    for(int i=0;i<n;++i){
      ll thr = mid-a[i];
      ll lbb = -1,ubb = n;
      while(ubb-lbb>1){
	ll midd=(ubb+lbb)/2;
	if(a[midd]>=thr){
	  lbb = midd;
	}
	else{
	  ubb = midd;
	}
      }
      //      cout << i << ":" << lbb << "\n";
      cnt+=lbb+1;
    }
    //    cout << mid << ":" << cnt << "*************\n";
    if(cnt>=m){
      lb = mid;
    }
    else{
      ub = mid;
    }
  }
  
  ll x = lb;
  //  cout << x << "\n";
  vector<ll> sum(n+1);
  sum[0] = 0;
  for(int i=0;i<n;++i){
    sum[i+1] = sum[i]+a[i];
  }

  // for(int i=0;i<n+1;++i){
  //   cout << sum[i] << "\n";
  // }
  
  ll res = 0;
  ll ct = 0;
  for(int i=0;i<n;++i){
    ll thr = x - a[i];
    ll lbb = -1,ubb = n;
    while(ubb-lbb>1){
      ll midd = (ubb+lbb)/2;
      if(a[midd]>=thr){
	lbb = midd;
      }
      else{
	ubb = midd;
      }
    }
    //    cout << i << ":" << lbb << "\n";
    ct += lbb+1;
    res += a[i]*(lbb+1)+sum[lbb+1];
  }

  res -= (ct-m)*x;
  cout << res << "\n";
  
  return 0;
}


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

int main(){
  
  char c;
  
  for(int i = 0;i < 3;i++){
    for(int j = 0;j < 3;j++){
      cin >> c;
      if(i == j) cout << c;
    }
  }
  cout << endl;
  
  return 0;
}

Measured memory_bytes: 256
/// awoooooo

# include <bits/stdc++.h>
# define sz(x) (int)((x).size())

using namespace std;

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

const int N = (int)2e5 + 5;
const int inf = (int)1e9 + 7;

int n, q;
int a[3001];
int nd[3001][3001], d[3001][3001];

int main(){
  int inv2 = (inf + 1) / 2;
  scanf("%d %d", &n, &q);
  for(int i = 1; i <= n; ++i){
    scanf("%d", a + i);
  }
  for(int i = 1; i <= n; ++i){
    for(int j = 1; j <= n; ++j){
      d[i][j] = a[i] > a[j];
    }
  }
  for(int i = 1; i <= q; ++i){
    int x, y;
    scanf("%d %d", &x, &y);
    for(int z = 1; z <= n; ++z){
      if(z == x || z == y) continue;
      nd[z][x] = (d[z][x] + d[z][y]) * 1ll * inv2 % inf;
      nd[z][y] = (d[z][y] + d[z][x]) * 1ll * inv2 % inf;
      nd[x][z] = (d[y][z] + d[x][z]) * 1ll * inv2 % inf;
      nd[y][z] = (d[x][z] + d[y][z]) * 1ll * inv2 % inf;
    }
    nd[x][y] = (d[x][y] + d[y][x]) * 1ll * inv2 % inf;
    nd[y][x] = (d[x][y] + d[y][x]) * 1ll * inv2 % inf;
    for(int z = 1; z <= n; ++z){
      d[z][x] = nd[z][x];
      d[z][y] = nd[z][y];
      d[x][z] = nd[x][z];
      d[y][z] = nd[y][z];
    }
  }
  int ans = 0;
  for(int i = 1; i <= n; ++i){
    for(int j = i + 1; j <= n; ++j){
      ans += d[i][j];
      if(ans >= inf){
        ans -= inf;
      }
    }
  }
  for(int i = 1; i <= q; ++i){
    ans = ans * 2ll % inf;
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 70656
#include <stdio.h>

int main(){
  int a,b,c;
  scanf("%d %d %d", &a, &b, &c);
  if(a+b==c){
    printf("Yes");
  }else if(a==b+c){
    printf("Yes");
  }else if(b==c+a){
    printf("Yes");
  }else{
    printf("No");
  }
  return 0;
}


Measured memory_bytes: 128
#include <algorithm>
#include <bitset>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <chrono>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <typeindex>
#include <typeinfo>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define ALL(s) begin(s), end(s)
#define RALL(s) rbegin(s), rend(s)
#define DEBUG(x) cout << #x << ": " << x << endl
#define INFILE() freopen("input.txt", "r", stdin)
#define REP(i, a, b) for (int i = (a); i < (b); i++)
#define RREP(i, a, b) for (int i = (a); i >= (b); i--)
#define REPC(i, a) REP(i, 0, a)
#define RREPC(i, a) RREP(i, a, 0)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using i_i = pair<int, int>;
using ll_ll = pair<ll, ll>;
using d_i = pair<double, int>;
using i_d = pair<int, double>;
using d_d = pair<double, double>;

static constexpr ll LL_MOD = 1000000009;
static constexpr ll LL2_MOD = 1000000007;
static constexpr ll INF = 1LL << 60;
static constexpr double EPS = numeric_limits<double>::epsilon();
static constexpr double PI = 3.14159265358979323846264338327950288;

static map<type_index, const char *const> scanType = {
  { typeid(int), "%d" }, { typeid(ll), "%lld" }, { typeid(double), "%lf" }, { typeid(char), "%c" }};

template <class T> static void scan(vector<T>& v);
static void scan(vector<string>& v, bool isWord = true);
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; }

ll dp[100010][3];

int main(int argc, char *argv[]) {
  //INFILE();

  int n;
  cin >> n;
  vector<ll> a(n), b(n), c(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i] >> c[i];
  }
  
  dp[0][0] = a[0];
  dp[0][1] = b[0];
  dp[0][2] = c[0];

  for (int i = 0; i < n - 1; i++) {
    chmax(dp[i + 1][0], dp[i][1] + a[i + 1]);
    chmax(dp[i + 1][0], dp[i][2] + a[i + 1]);

    chmax(dp[i + 1][1], dp[i][0] + b[i + 1]);
    chmax(dp[i + 1][1], dp[i][2] + b[i + 1]);

    chmax(dp[i + 1][2], dp[i][0] + c[i + 1]);
    chmax(dp[i + 1][2], dp[i][1] + c[i + 1]);
  }


  cout << *max_element(ALL(dp[n - 1])) << endl;
  return 0;
}

template <class T> static void scan(vector<T>& v) {
  auto tFormat = scanType[typeid(T)];
  for (T& n : v) {
    scanf(tFormat, &n);
  }
}

static void scan(vector<string>& v, bool isWord) {
  if (isWord) {
    for (auto& n : v) {
      cin >> n;
    }
    return;
  }

  int i = 0, size = v.size();
  string s;
  getline(cin, s);

  if (s.size() != 0) {
    i++;
    v[0] = s;
  }

  for (; i < size; ++i) {
    getline(cin, v[i]);
  }
}


Measured memory_bytes: 4992
#include <cassert>
#include <cstddef>
#include <numeric>
#include <utility>
#include <vector>

class UnionFind {

public:
  using size_type = std::size_t;
  using container_type = std::vector<size_type>;

protected:
  container_type p, s;

public:
  UnionFind() : p(), s() {}
  explicit UnionFind(const size_type size)
      : p(size), s(size, static_cast<size_type>(1)) {
    std::iota(p.begin(), p.end(), static_cast<size_type>(0));
  }

  size_type size() const { return p.size(); }
  bool empty() const { return p.empty(); }

  size_type find(size_type x) {
    assert(x < size());
    while (p[x] != x)
      x = p[x] = p[p[x]];
    return x;
  }
  bool same(const size_type x, const size_type y) {
    assert(x < size());
    assert(y < size());
    return find(x) == find(y);
  }
  size_type size(const size_type x) {
    assert(x < size());
    return s[find(x)];
  }

  bool unite(size_type x, size_type y) {
    assert(x < size());
    assert(y < size());
    x = find(x);
    y = find(y);
    if (x == y)
      return false;
    if (s[x] < s[y])
      std::swap(x, y);
    s[x] += s[y];
    p[y] = x;
    return true;
  }
};

#include<iostream>
  
int main() {
    int n, q;
    std::cin >> n >> q;
    UnionFind T(n);
    while (q--) {
        int p, a, b;
        std::cin >> p >> a >> b;
        if (p)
            std::cout << (T.same(a, b) ? "1" : "0") << std::endl;
        else
            T.unite(a, b);
    }
    return 0;
}


Measured memory_bytes: 3228
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef long double D;
typedef complex<D> P;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;

template<typename T,typename U>istream & operator >> (istream &i,pair<T,U> &A){i>>A.F>>A.S; return i;}
template<typename T>istream & operator >> (istream &i,vector<T> &A){for(auto &I:A){i>>I;} return i;}
template<typename T,typename U>ostream & operator << (ostream &o,const pair<T,U> &A){o<<A.F<<" "<<A.S; return o;}
template<typename T>ostream & operator << (ostream &o,const vector<T> &A){ll i=A.size(); for(auto &I:A){o<<I<<(--i?" ":"");} return o;}
template<typename T>vector<T> & cset(vector<T> &A,T e=T()){for(auto &I:A){I=e;} return A;}

ll p;

ll order(ll a){
  ll ret=1,k=a;
  while(k!=1){
    ret++;
    (k*=a)%=p;
  }
  return ret;
}

ll mod_pow(ll a,ll x){
  ll ret=1;
  while(x>0){
    if(x&1){(ret*=a)%=p;}
    (a*=a)%=p;
    x>>=1;
  }
  return ret;
}


int main(){
  cin>>p;
  vector<ll> A(p);
  vector<ll> B(p-1);
  cin>>A;
  ll pr=1;
  while(order(pr)!=p-1){pr++;}
  ll k=1;
  for(int i=0;i<p-1;i++){
    B[i]=A[k];
    (k*=pr)%=p;
  }
  ll inv=mod_pow(pr,p-2);
  ll n=mod_pow(p-1,p-2);
  vector<ll> ans(p,0);
  k=1;
  for(int i=0;i<p-1;i++){
    ll l=1;
    for(int j=0;j<p-1;j++){
      ans[i]+=B[j]*l%p;
      ans[i]%=p;
      (l*=k)%=p;
    }
    (k*=inv)%=p;
  }
  for(auto &I:ans){(I*=n)%=p;}
  ans[p-1]=(ans[0]+p-A[0])%p;
  ans[0]=A[0];
  cout<<ans<<endl;
  

  return 0;
}


Measured memory_bytes: 384
import java.util.*;
import java.util.function.BiPredicate;
import java.util.stream.*;

public class Main {
    static Scanner scanner = new Scanner(System.in);

    public static void main(String[]$) {
        int a = scanner.nextInt(), b = scanner.nextInt(), q = scanner.nextInt();
        List<Long> s = IntStream.range(0, a).mapToObj(i -> scanner.nextLong()).collect(Collectors.toList());
        List<Long> t = IntStream.range(0, b).mapToObj(i -> scanner.nextLong()).collect(Collectors.toList());
        s.sort(Long::compareTo);
        t.sort(Long::compareTo);
        s.add(Long.MAX_VALUE);
        t.add(Long.MAX_VALUE);
        s.add(0, Long.MIN_VALUE);
        t.add(0, Long.MIN_VALUE);

        for (int i = 0; i < q; i++) {
            long x = scanner.nextLong();
            int s1 = binarySearch(s, (e, j) -> e < x);
            int t1 = binarySearch(t, (e, j) -> e < x);
            long sa = s.get(s1) == Long.MIN_VALUE ? s.get(s1 + 1) : s.get(s1);
            long sb = s.get(s1 + 1) == Long.MAX_VALUE ? s.get(s1) : s.get(s1 + 1);
            long ta = t.get(t1) == Long.MIN_VALUE ? t.get(t1 + 1) : t.get(t1);
            long tb = t.get(t1 + 1) == Long.MAX_VALUE ? t.get(t1) : t.get(t1 + 1);
            System.out.println(Math.min(Math.min(Math.min(Math.abs(x - sa) + Math.abs(sa - ta), Math.abs(x - sa) + Math.abs(sa - tb)), Math.min(Math.abs(x - sb) + Math.abs(sb - ta), Math.abs(x - sb) + Math.abs(sb - tb))), Math.min(Math.min(Math.abs(x - ta) + Math.abs(ta - sa), Math.abs(x - ta) + Math.abs(ta - sb)), Math.min(Math.abs(x - tb) + Math.abs(tb - sa), Math.abs(x - tb) + Math.abs(tb - sb)))));
        }
    }

    public static <T> int binarySearch(List<T> list, BiPredicate<T, Integer> predicate) {
        int ok = 0, ng = list.size();
        while (Math.abs(ok - ng) > 1) {
            int mid = (ok + ng) / 2;
            if (predicate.test(list.get(mid), mid)) {
                ok = mid;
            } else {
                ng = mid;
            }
        }
        return ok;
    }
}

Measured memory_bytes: 121544
#include <iostream>
#include <vector>
#include <string>
#include <list>
#include <queue>
#include <algorithm>
#define rep(i, n) for(i = 0; i < (n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define MOD 1000000007
#define PI 3.14159265358979323846
#define INF 1 << 30

using namespace std;
typedef long long ll;
typedef pair<int, int> pp;
typedef struct str{
	int a, b, c, d;
	bool operator<(str r) {
		return d < r.d;
	}
} tp;

vector<tp> A;
int Judge(vector<int>& d) {
	int i, ans = 0;
	rep(i, A.size()) {
		if (d[A[i].b] - d[A[i].a] == A[i].c)
			ans += A[i].d;
	}
	return ans;
}

int Search(int n, vector<int> d, int mi, int ma) {
	if (n == d.size()) {
		return Judge(d);
	}
	int ans = 0;
	for (int i = mi; i <= ma; i++) {
		d[n] = i;
		chmax(ans, Search(n + 1, d, i, ma));
	}
	return ans;
}

int main(void) {
	int num, i, ma, q, ans;
	cin >> num >> ma >> q;
	A.resize(q);
	rep(i, q) {
		cin >> A[i].a >> A[i].b >> A[i].c >> A[i].d;
		A[i].a--;
		A[i].b--;
	}
	vector<int> d(num);
	ans = Search(0, d, 1, ma);
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) ((a) <= (x) && (x) < (b))
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MODU 1000000007LL
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1LL << b))
#define bitunset(a,b)    (a &= ~(1LL << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int
#define PI 3.141592653589

#define izryt bool
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*)array, (T*)(array + N), val);
}

pll Dir[8] = { //移動
	{ 0 ,1 },{ -1 ,0 },{ 1 ,0 },{ 0 ,-1 },
	{ 1 ,1 },{ 1 ,-1 },{ -1 ,1 },{ -1 ,-1 }
};

//[a, b)
#define Getsum(ar, a,b) (ar[b] - ar[a])
#define INF 10000000000000000LL

struct Edge {
	ll from, to;
	ll w;
};

typedef vector<vector<Edge>> Graph;

signed main(void) {
	int q;
	cin >> q;

	int ar[8][8] = {};

	ar[0][1] = 1;
	ar[0][3] = 1;
	ar[0][5] = 1;
	ar[0][7] = 1;
	ar[2][1] = 1;
	ar[2][3] = 1;
	ar[2][5] = 1;
	ar[2][7] = 1;
	ar[4][1] = 1;
	ar[4][3] = 1;
	ar[4][5] = 1;
	ar[4][7] = 1; 
	ar[6][1] = 1;
	ar[6][3] = 1;
	ar[6][5] = 1;
	ar[6][7] = 1;

	REP(cc, q) {
		int a, b, c, d;

		cin >> a >> b >> c >> d;

		a--, b--;

		int cou = 0;
		rep(i, a, c) {
			rep(j, b, d) {
				cou += 1 - ar[i][j];
			}
		}

		cout << cou << endl;

	}
	return 0;
}


Measured memory_bytes: 3072
#include <stdio.h>
int main(void)
{
    long int n, m, ans[100001]={0}, a[100000], i, j=0;
    scanf("%ld%ld", &n, &m);
    for(i=0;i<m;i++){
        scanf("%ld", &a[i]);
    }

    ans[0]=0;
    ans[1]=1;
    ans[2]=2;
    if(n==1){
        printf("%ld\n", ans[1]);
        return 0;
    }
    for(i=0;i<=n;i++){
        if(a[j]==i){
            ans[i]=0;
            if(j!=m-1) j++;
        }
        else if(i==0) ans[i]=0;
        else if(i==1) ans[i]=1;
        else if(i==2 && ans[1]!=0) ans[i]=2;
        else if(i==2 && ans[1]==0) ans[i]=1;
        else ans[i]=ans[i-1]+ans[i-2];
        ans[i]=ans[i]%1000000007;
    }
    printf("%ld\n", ans[i-1]);
    
    return 0;
}

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

#define N (100000*2)
#define MOD 1000000007

long long f[N];
long long rf[N];
map<int, int> ma;

long long inv( long long x )
{
    long long res = 1;
    long long k = MOD - 2;
    long long y = x;
    while (k) {
        if (k & 1) res = (res * y) % MOD;
        y = (y * y) % MOD;
        k /= 2;
    }
    return res;
}

void init()
{
    f[0] = 1;
    for( int i = 1; i < N; i++ ) {
		f[i] = (f[i - 1] * i) % MOD;
	}
    rf[N - 1] = inv(f[N - 1]);
    for( int i = N - 2; i >= 0; i-- ) {
		rf[i] = (rf[i + 1] * (i + 1)) % MOD;
	}
}

void factorization( int n )
{
	int d = 2;
	while( n >= d * d ) {
		if( (n % d) == 0 ) {
			ma[d]++;
			n /= d;
		}
		else {
			d++;
		}
	}
	ma[n]++;
}

int main()
{
	int n, m;

	cin >> n >> m;

	factorization( m );
	init();
	long long ans = 1;
	for( auto a : ma ) {
		if( a.first == 1 ) {
			continue;
		}
		int nn = a.second;
		long long res = (f[nn + n - 1] * (rf[nn] * rf[n - 1] % MOD) ) % MOD;
		ans = ans * res % MOD;
	}

	cout << ans << endl;

	return 0;
}


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

int main(){
	int h[10]={0};
	for(int i=0;i<10;i++){
		cin>>h[i];
	}
	int m=0,k=0;
	for(int i=0;i<10;i++){
		if(m<h[i]){m=h[i];k=i;};
	}
	cout<<m<<endl;
	h[k]=0;k=0;m=0;
	for(int i=0;i<10;i++){
		if(m<h[i]){m=h[i];k=i;};
	}
	cout<<m<<endl;
	h[k]=0;k=0;m=0;
	for(int i=0;i<10;i++){
		if(m<h[i]){m=h[i];k=i;};
	}
	cout<<m<<endl;
	h[k]=0;k=0;m=0;
	return 0;
}

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

using namespace std;

const int N = 2e5 + 10;

long long ft[N];

void inc (int i, long long delta) {
	for (; i < N; i = (i | (i + 1)))
		ft[i] += delta;
}

long long sum (int r) {
	int result = 0;
	for (; r >= 0; r = (r & (r+1)) - 1)
		result += ft[r];
	return result;
}

long long sum (int l, int r) {
	return sum(r) - sum (l - 1);
}

void solve() {
    int n;
    long long d, a;
    cin >> n >> d >> a;
    vector<pair<long long, long long> > vt(n);
    for (int i = 0; i < n; i++) {
        cin >> vt[i].first >> vt[i].second;
    }
    sort(vt.begin(), vt.end());

    long long ans = 0;
    for (int i = 0; i < n; i++) {
        long long h = vt[i].second - sum(0, i);
        if (h <= 0) continue;
        long long cnt = (h + a - 1) / a;
        long long x = vt[i].first, nx = vt[i].first + 2 * d + 1;
        int id = lower_bound(vt.begin(), vt.end(), make_pair(nx, 0LL)) - vt.begin();
        inc(i, cnt * a);
        inc((id - 1) + 1, -cnt * a);
        ans += cnt;
    }
    cout << ans;
}

int main() {
    ios::sync_with_stdio(NULL), cin.tie(0), cout.tie(0);
    cout.setf(ios::fixed), cout.precision(20);
    solve();
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define ALL(vec) vec.begin(), vec.end()
#define rALL(vec) vec.rbegin(), vec.rend()
using namespace std;
using ll = long long;
// ------------------------------

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];
    ll ans = 0;
    rep(i, N - 1) {
        if (A[i] > A[i + 1]) {
            int tmp = A[i] - A[i + 1];
            ans += tmp;
            A[i + 1] = A[i];
        }
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;
#define fre freopen("in.txt","r",stdin)
#define IO ios::sync_with_stdio(false)
#define mem(a,n) memset(a,n,sizeof(a))
#define rep(i,a,n) for(int i=a;i<n;i++)
#define pb push_back
typedef long long ll;
const int INF=0x3f3f3f3f;
const double PI=3.1415926;
const int MOD=1e9+7;
const int N=9e4+5;
int ax[N],ay[N];
int sum[N];
int main()
{
    int h,w,d;
    scanf("%d%d%d",&h,&w,&d);
    rep(i,1,h+1)
    {
        rep(j,1,w+1)
        {
            int x;
            scanf("%d",&x);
            ax[x]=i,ay[x]=j;
        }
    }
    rep(i,d+1,h*w+1)
    sum[i]=sum[i-d]+abs(ax[i-d]-ax[i])+abs(ay[i-d]-ay[i]);
    int q;
    scanf("%d",&q);
    while(q--)
    {
        int l,r;
        scanf("%d%d",&l,&r);
        printf("%d\n",sum[r]-sum[l]);
    }
    return 0;
}


Measured memory_bytes: 2176
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;


class Program
{
    static void Main(string[] args)
    {
        // 入力
        //var s = Console.ReadLine();
        //var n = int.Parse(Console.ReadLine());
        int[] hw = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var h = hw[0];
        var w = hw[1];

        char[][] jag = new char[h][];
        for (int i = 0; i < h; i++)
        {
            jag[i] = Console.ReadLine().ToCharArray();
        }

        string[] ans = new string[h];
        for (int i = 0; i < h; i++)
        {
            var st = new StringBuilder();
            for (int k = 0; k < w; k++)
            {
                if (jag[i][k] == '#')
                {
                    st.Append("#");
                }
                else
                {
                    var count = 0;
                    if (i > 0 && jag[i - 1][k] == '#') count++;
                    if (i > 0 && k < w - 1 && jag[i - 1][k + 1] == '#') count++;
                    if (k < w - 1 && jag[i][k + 1] == '#') count++;
                    if (i < h - 1 && k < w - 1 && jag[i + 1][k + 1] == '#') count++;
                    if (i < h - 1 && jag[i + 1][k] == '#') count++;
                    if (i < h - 1 && k > 0 && jag[i + 1][k - 1] == '#') count++;
                    if (k > 0 && jag[i][k - 1] == '#') count++;
                    if (i > 0 && k > 0 && jag[i - 1][k - 1] == '#') count++;
                    st.Append(count.ToString());
                }
            }
            ans[i] = st.ToString();
        }

        // 出力
        for (int i = 0; i < h; i++)
        {
            Console.WriteLine(ans[i]);
        }

    }
}

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

class Main {

	void solve() {

		out.println((inint()+inint()+1)/2);

	}

	public static Scanner in = new Scanner(System.in);
	public static PrintWriter out = new PrintWriter(System.out);

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

	public int inint() {
		return in.nextInt();
	}

	public long inlong() {
		return in.nextLong();
	}
	
	public String instr() {
		return in.next();
	}

	public int[] inintar(int num) {
		int[] a = new int[num];
		for (int i=0; i<num; i++) {
			a[i] = in.nextInt();
		}
		return a;
	}

	public char[] incharar() {
		return in.next().toCharArray();
	}

}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

ll fac[200007],finv[200007],inv[200007];
void cominit(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<200007;i++){
        fac[i]=fac[i-1]*i%mod;
        inv[i]=mod-inv[mod%i]*(mod/i)%mod;
        finv[i]=finv[i-1]*inv[i]%mod;
    }
}
ll com(ll n,ll k){
    if(n<k)return 0;
    if(n<0 || k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%mod)%mod;
}
long long modpow(long long a, long long n) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    cominit();
    ll n,k;
    ll ans=0;
    cin>>n>>k;
    ll a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    k--;
    sort(a,a+n);
    for(int i=0;i<n;i++){
        ans-=(com(n-i-1,k)*(a[i]))%mod;
        ans%=mod;
    }
    for(int i=0;i<n;i++){
        ans+=(com(i,k)*(a[i]))%mod;
        ans%=mod;
    }
    cout <<(ans+mod)%mod<<endl;
    return 0;
}

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

#define REP(i, n) for (int i = 0; i < (int)(n); ++i)

using namespace std;

template<int Mod>
class ModInt {
 public:
  ModInt() : n_(0) {}
  ModInt(long long n) : n_(n % Mod) {}
  ModInt& operator+=(const ModInt& m) {
    n_ += m.n_;
    if (n_ > Mod) {
      n_ -= Mod;
    }
    return *this;
  }
  ModInt operator+(const ModInt& m) const {
    ModInt n(*this);
    n += m;
    return n;
  }
  ModInt& operator++() {
    (*this) += 1;
    return *this;
  }
  ModInt& operator-=(const ModInt& m) {
    n_ -= m.n_;
    if (n_ < 0) {
      n_ += Mod;
    }
    return *this;
  }
  ModInt operator-(const ModInt& m) const {
    ModInt n(*this);
    n -= m;
    return n;
  }
  ModInt& operator*=(const ModInt& m) {
    n_ *= m.n_;
    n_ %= Mod;
    return *this;
  }
  ModInt operator*(const ModInt& m) const {
    ModInt n(*this);
    n *= m;
    return n;
  }
  long long value() const { return n_; }
 private:
  long long n_;
};

template<int Mod>
std::ostream& operator<<(std::ostream& out, const ModInt<Mod>& m) {
  out << m.value();
  return out;
}

using mint = ModInt<1000000007>;

template <typename T>
T Gcd(T a, T b) {
  if (a > b) {
    return Gcd(b, a);
  }
  T m = b % a;
  if (m == 0) {
    return a;
  }
  return Gcd(m, a);
}

template <typename N>
class Rational {
 public:
  Rational(N numerator, N denominator) {
    assert(denominator != 0);
    if (numerator == 0) {
      numerator_ = 0;
      denominator_ = 1;
      return;
    }
    if (denominator < 0) {
      numerator = -numerator;
      denominator = -denominator;
    }
    N sign = 1;
    if (numerator < 0) {
      sign = -1;
      numerator = -numerator;
    }
    N gcd = Gcd(numerator, denominator);
    numerator_ = sign * (numerator / gcd);
    denominator_ = denominator / gcd;
  }
  N numerator() const { return numerator_; }
  N denominator() const { return denominator_; }
 private:
  N numerator_;
  N denominator_;
};

using ll = long long;

using Rat = Rational<ll>;

pair<ll, ll> ToPair(const Rat& r) {
  return make_pair(r.numerator(), r.denominator());
}

map<pair<ll, ll>, int> s1;
map<pair<ll, ll>, int> s2;

mint two[200001];

int main() {
  two[0] = 1;
  for (int i = 1; i <= 200000; ++i) {
    two[i] = two[i - 1] * 2;
  }

  int N;
  cin >> N;

  mint zeros = 0;

  ll A_zeros = 0;
  ll B_zeros = 0;

  REP(i, N) {
    ll A, B;
    cin >> A >> B;

    if (A == 0 && B == 0) {
      ++zeros;
      continue;
    }
    if (A == 0) {
      ++A_zeros;
      continue;
    }
    if (B == 0) {
      ++B_zeros;
      continue;
    }

    s1[ToPair(Rat(-B, A))]++;
    s2[ToPair(Rat(A, B))]++;
  }

  vector<pair<int, int>> groups;
  for (auto it : s2) {
    pair<int, int> p(it.second, s1[it.first]);
    if (p.second != 0 && it.first.first < 0) continue;

    groups.push_back(p);
  }
  groups.push_back(make_pair(A_zeros, B_zeros));

  mint mul = 1;
  for (auto p : groups) {
    // cout << p.first << " " << p.second << endl;
    mint m;
    if (p.second == 0) {
      m = two[p.first];
    } else {
      m = two[p.first] + two[p.second] - 1;
    }
    // cout << m << endl;
    mul *= m;
  }
  cout << (mul - 1 + zeros) << endl;
}


Measured memory_bytes: 43936
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		if(n % 2 ==1) {
			System.out.println("No");
		}else {
			char[] s = sc.next().toCharArray();
			boolean flag = true;
			for (int i = 0; i < n/2; i++) {
				if(s[i] != s[i+n/2]) {
					flag = false;
					break;
				}
			}
			System.out.println(flag ? "Yes":"No");
		}
		sc.close();
	}
}

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

#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define intll int long long
const intll INF = 1e9;
const int MOD = 1e9 + 7;

int main() {
  intll a , b , c , d , n ;
  cin >> a >> b >> c >> d >> n  ;
  
  intll D = min(min(8*a,4*b),min(2*c,d)) ;
  intll O = min(min(4*a,2*b),c);
  
  intll ans = 0 ; 
  ans += n/2 * D ;
  ans += n%2 * O ;
  
  cout << ans ;
      
  
  
  
}


Measured memory_bytes: 3628
sym = ["S", "H", "C", "D"]
rnk = range(1,14)
crds = []
for i in sym:
    for j in rnk:
        crds.append([i,j])
n = int(input())
for i in range(n):
    wrds = input().split()
    wrds[1] = int(wrds[1])
    crds.remove(wrds)
for i in crds:
    print (i[0], i[1])


Measured memory_bytes: 5596
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
int a, b;

int main() {
	cin >> a >> b;
	if(a > 8 || b > 8) puts(":(");
	else puts("Yay!");
}

Measured memory_bytes: 256
import java.io.*;
import java.util.StringTokenizer;

public class Main {

    void solve() {
        //price
        long cheap = Long.MAX_VALUE;
        long price = 0;

        long Q = in.nextLong()*8;
        if (Q < cheap) {
            cheap = Q;
            price = cheap/2;
        }
        long H = in.nextLong()*4;
        if (H < cheap) {
            cheap = H;
            price = cheap/2;
        }
        long S = in.nextLong()*2;
        if (S < cheap) {
            cheap = S;
            price = cheap/2;
        }
        long D = in.nextLong();
        //total
        long N = in.nextLong();
        if (N < 2 || cheap < D) {
            out.println(N*price);
        }else{
            long temp = N/2;
            long remain = N%2;
            out.println(temp * D + remain * price);
        }
    }



    FastScanner in;
    PrintWriter out;

    void run() {
        in = new FastScanner();
        out = new PrintWriter(System.out);
        solve();
        out.close();
    }

    public class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

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

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

        public int nextInt() {
            return Integer.parseInt(nextToken());
        }

        public long nextLong() {
            return Long.parseLong(nextToken());
        }

        public double nextDouble() {
            return Double.parseDouble(nextToken());
        }
    }

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

}

Measured memory_bytes: 23252
#include <iostream>
#include <vector>
#include <cstdio>
#include <string>
#include <algorithm>
#include <map>
using namespace std;

int main(void)
{
    long long n;
    cin >> n; 
    vector<long long > l;
    for (int i = 0; i < n; i++) {
        long long tmp;
        cin >> tmp;
        l.push_back(tmp);
    }

    sort(l.begin(), l.end(), greater<long long>());
    
    long long res = 0;
    for (int i = 0; i < n; i++) {
        //if (i != 0 && l[i] == l[i - 1]) continue;
        for (int j = i + 1; j < n; j++) {
            //if (j != i + 1 && l[j] == l[j - 1]) continue;
            for (int k = j + 1; k < n; k++) {
                //if (k != j + 1 && l[k] == l[k - 1]) continue;
                if (l[i] < l[j] + l[k]) {
                    //cout << i << " " << j << " " << k;
                    res++;
                }
            }
        }
    }
    cout << res << endl;
}



Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(int i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
#define pb push_back
using namespace std;
using ll=long long;
using ld=long double;
using ch=char;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
struct edge{ll to,cost;};
struct edge2{ll from,to,cost;};

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

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N;
    cin >> N;
    vl A(N);
    ll sum=0;
    rep(i,N){
        cin >> A[i];
        sum+=abs(A[i]);
    }
    sort(A.begin(),A.end());
    if(A[0]*A[N-1]<=0){
        cout << sum << endl;
    }
    else{
        if(A[0]>0){
            cout << sum-2*A[0] << endl;
        }
        else{
            cout << sum+2*A[N-1] << endl;
        }
    }
    FOR(i,1,N-1){
        if(A[i]>=0){
            cout << A[0] << ' ' << A[i];
            A[0]-=A[i];
        }
        else{
            cout << A[N-1] << ' ' << A[i];
            A[N-1]-=A[i];
        }
        cout << endl;
    }
    cout << A[N-1] << ' ' << A[0] << endl;
}
/*
overflow checked?
corner case checked?
boundary checked?
not TLE in worst case checked?
*/

Measured memory_bytes: 3908
#include <bits/stdc++.h>
#define int long
#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
int gcd(int a,int b){return b ? gcd(b,a%b) : a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}

main() {
    int N; cin >> N;
    cout << N*N*N << endl;

    return 0;
}

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

using namespace std;

int main() {
	int n;
	cin >> n;
	int d;
	vector<int> S;
	for (int i = 0; i < n; ++i) {
		cin >> d;
		S.push_back(d);
	}
	int q;
	cin >> q;
	vector<int> T;
	for (int i = 0; i < q; ++i) {
		cin >> d;
		T.push_back(d);
	}

	int count = 0;
	for (int j = 0; j < q; ++j) {
		for (int i = 0; i < n; ++i) {
			if (T[j] == S[i]) {
				++count;
				break;
			}
		}
	}
	cout << count << endl;
}

Measured memory_bytes: 1320
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 99999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=m;i>n;i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(),N.end()),N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(20) << S << endl
#define Vecpr(K,L1,L2,N) vector<pair<L1,L2>> K(N)
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M,R) vector<vector<L>> K(N, vector<L>(M,R))
#define Lower(v,X) lower_bound(v.begin(),v.end(),X)-v.begin();
#define mod 1000000007
#define MAX 5100000
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
int main(){
   lli A,B,C,L,R,N,M,K,X=0,Y=0,W,H=INF,sum=0,num=0,flag=0;string S,T,O;
   cin >> N >> X;
   Vec(P,lli,N+2,0);
   rep(i,0,N)cin >> P[i+1];
   rep(i,1,N+2){
      if(P[i]+P[i-1]>X){
         sum+=(P[i]+P[i-1]-X);
         P[i]-=(P[i]+P[i-1]-X);
      }
   }
   Out(sum);
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL << 40;
#define FOR(i,k,n) for(int i=(k);i<(n);++i)

int main(){
    int a,b,W;cin >> W >> a >> b;
    if(b>=a+W) cout << b-a-W << endl;
    else if(b+W<=a) cout << a-b-W << endl;
    else cout << 0 << endl;
    return 0;
}

Measured memory_bytes: 256
import sys

import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


def main():
    N = int(readline())
    H = list(map(int, readline().split()))
    H.append(10**10)

    dp = np.full(N+1, 10**10, np.int64)
    dp[0] = 0

    for i in range(N-1):
        dp[i+1] = min(dp[i+1], dp[i] + abs(H[i+1] - H[i]))
        dp[i+2] = min(dp[i+2], dp[i] + abs(H[i+2] - H[i]))

    print(dp[N-1])


main()


Measured memory_bytes: 21144