akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> ii;
typedef long long ll;
ll a[200005];
int tw[200005], fi[200005];
int ct[20][20];
ll ans = 0;
int main(){
    int n;
    scanf("%d",&n);
    for (int i = 0; i <n; i++){
        long double x;
        scanf("%Lf",&x);
        a[i] = (x*1000000000 + 0.5);
        //printf("%lld ",a[i]);
        while (a[i] % 2 == 0){
            tw[i]++;
            a[i] /= 2;
        }
        while (a[i] % 5 == 0){
            fi[i]++;
            a[i] /= 5;
        }
        tw[i] = min(tw[i],18);
        fi[i] = min(fi[i],18);
        for (int k = 18-tw[i]; k <= 18; k++){
            for (int l = 18-fi[i]; l <= 18; l++){
                ans += ct[k][l];
            }
        }
        ct[tw[i]][fi[i]]++;
    }
    printf("%lld\n",ans);
}


Measured memory_bytes: 6944
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
typedef long long LL;
int N;
LL a[8];
int main(){
	REP(i,7){
		cin>>a[i];
	}
	LL ans=0;
	ans+=a[1]*2;
	ans+=(a[3]/2)*4;
	ans+=(a[4]/2)*4;
	ans+=(a[0]/2)*4;
	LL ans2=0;
	ans2+=a[1]*2;
	if(a[3]>0&&a[4]>0&&a[0]>0){
		a[3]--;
		a[4]--;
		a[0]--;
		ans2+=6;
	}
	ans2+=(a[3]/2)*4;
	ans2+=(a[4]/2)*4;
	ans2+=(a[0]/2)*4;
	cout<<max(ans,ans2)/2<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n, k;
    cin >> n >> k;
    int h[n],  dp[n];
    for(int i = 0; i < n; i++) {
        cin >> h[i];
    }
    dp[0] = 0;
    for(int i = 1; i < n; i++) {
        dp[i] = 1e9+7;
        for(int j = i-1; j >= 0 && j >= i-k; j--){
            dp[i] = min(dp[i], dp[j]+abs(h[i]-h[j]));
        }
    }
    cout << dp[n-1] << endl;
}


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

int main(){
  int A, B;
  char op;
  int ans = 0;
  
  cin >> A >> op >> B;
  
  if(op == '+') ans = A + B;
  if(op == '-') ans = A - B;
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

char S[500500];
int C[500500][27],V[500500][19];

int main()
{
	scanf ("%s",S+1);
	int L = 0;
	while (S[L+1]) L++;
	for (int i=L;i>=1;i--){
		int p = S[i]-'a';
		C[i][p] = i+1;
		for (int j=p+1;j<=26;j++) C[i][j] = C[C[i][j-1]][j-1];
		V[i][0] = C[i][26];
		if (V[i][0]) for (int j=0;j<p;j++) C[i][j] = C[V[i][0]][j];
		for (int j=1;j<19;j++) V[i][j] = V[V[i][j-1]][j-1];
	}

	int Q; scanf ("%d",&Q); while (Q--){
		int l,r; scanf ("%d %d",&l,&r); r++;

		for (int i=18;i>=0;i--){
			if (V[l][i] && V[l][i] <= r) l = V[l][i];
		}

		puts(l == r? "Yes":"No");
	}
	return 0;
}

Measured memory_bytes: 91008
import math
import functools
import itertools
import sys
MAX_INT = int(10e10)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

X,Y,Z,K = IL()
A = IL()
B = IL()
C = IL() 

A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

ab = []
for i in list(itertools.product(A,B)):
    ab.append(sum(i))

ab.sort(reverse=True)

ans = []
for i in list(itertools.product(ab[:3000],C)):
    ans.append(sum(i))

ans.sort(reverse=True)

for i in range(K):
    print(ans[i])


Measured memory_bytes: 283192
import sys
from itertools import combinations


def main():
    ll = read_ll()
    result = c(ll)
    print(result)

def c(ll):
    count = 0
    for i, j, k in combinations(ll, 3):
        if i != j and j != k and i != k:
            if i + j > k:
                count += 1
    return count

def read_ll():
    n = int(input())

    ll = input().split()
    ll = list(map(int, ll))
    ll.sort()
    return ll

if __name__ == '__main__':
    main()


Measured memory_bytes: 9092
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define forn(i,a,b) for(int i=a;i<=b;i++)
#define INF 2147483647
#define LLINF 9223372036854775807
using namespace std;
int main(){
	long long cnt=0;
	int n;
	cin>>n;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			for(int k=1;k<=n;k++){
				cnt+=__gcd(i,__gcd(j,k));
			}
		}
	}
	cout<<cnt<<endl;
	return 0;
} 

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define cvector vector<char>
#define svector vector<string>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll,lvector,greater<ll>>
#define P pair<ll,ll>
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define rep(i,n) for(ll i=0; i<n; ++i)
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,s=0,mod=1e9+7,ans=0;cin>>n;
  lvector A(n);rep(i,n) {cin>>A[i];s=(s+A[i])%mod;}
  rep(i,n) {
    s-=A[i];
    if(s<0) s+=mod;
    ans+=(A[i]*s)%mod;
    ans%=mod;
  }
  print(ans);
  return 0;
}

Measured memory_bytes: 4728
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <iomanip>
#include <string>

using namespace std;

int main() {
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;++i){
      cin>>a[i];
    }
    long long ans=0;
    for(int i=0;i<n;i++){
      for(int j=i+1;j<n;j++){
        ans+=a[i]*a[j];
      }
    }
    cout<<ans<<endl;

   return 0;
 }


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

int main() {
  long int N,tibi,deka,zikan;
  int count=0;
  deka=0;
  vector<long int> data(5);
  cin >> N;
  for(int i=0 ;i<5 ;i++){
    cin >> data.at(i);
    deka=max(deka,data.at(i));
  }
  tibi=deka;
  for(int i=0;i<5;i++){
    tibi=min(tibi,data.at(i));
  }
  for(int i=0;i<5 ;i++){
    if(data.at(i)==tibi){
      count=i;
      break;
    }
  }
  if( N % data.at(count)==0){
    zikan = count + N/data.at(count) + 4- count;
  }
  else{
    zikan= count + N/data.at(count) + 1 + 4 - count;
  }
  cout << zikan << endl;
}

       
  
    


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

#define int long long
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int x[200010];
int y[200010];
int xx[200010];
int yy[200010]; 

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

	for(int i = 0;i < n;i++){
		cin >> x[i] >> y[i];
		xx[i] = x[i] + y[i];
		yy[i] = x[i] - y[i];
	}

	sort(xx, xx + n);
	sort(yy, yy + n);

	cout << max(yy[n-1]-yy[0], xx[n-1]-xx[0]) << endl;
	return 0;
}


Measured memory_bytes: 9880
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
#include <stack>
using namespace std;
#define ll int64_t
const ll mod = 1000000007;


const ll LINF = 1e13;
const ll LLINF = 1e18;
const ll ALPHABET = 26;

template <class T>
void Swap(T& r, T& l) {
  T tmp = r;
  r = l;
  l = tmp;
}

template<typename T>
istream& operator >> (istream& is, vector<T>& vec) {
  for (T& x : vec) is >> x; //for(int i=0; i<vec.size(); i++) is >> x[i]; とかでもいい
  return is;
}


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

  ll ans = 0;

  ll dp4[10000][5][5][5];
  for (int i = 0; i < n; i++) {
    for (int a = 0; a < 5; a++) {//4個前
      for (int b = 0; b < 5; b++) {//3個前
        for (int c = 0; c < 5; c++) {//2個前
          dp4[i][a][b][c] = 0;
        }
      }
    }
  }


  dp4[0][4][4][4] = 1;
  // 位置,1こ前,2こ前,3こ前 ?
  // 1 - n文字目までのDP

  // 0 1 2 3 4
  // * A G C T

  for (int i = 0; i < n; i++) {
    for (int a = 0; a < 5; a++) {//4個前
      for (int b = 0; b < 5; b++) {//3個前
        for (int c = 0; c < 5; c++) {//2個前
          for (int d = 1; d < 5; d++) {//1個前

            //前の文字を確認して、違反していたら+しない
            //// AGC, A*GC, GAC, ACG, AG*C
            if (b == 1 && c == 2 && d == 3) continue; //AGC
            if (a == 1 && c == 2 && d == 3) continue; //A * GC
            if (b == 2 && c == 1 && d == 3) continue; //GAC
            if (b == 1 && c == 3 && d == 2) continue; //ACG
            if (a == 1 && b == 2 && d == 3) continue; //AG * C
            // 3  2  1            4  3  2
            dp4[i + 1][b][c][d] += dp4[i][a][b][c];
            dp4[i + 1][b][c][d] %= mod;
          }
        }
      }
    }
  }


  for (int a = 0; a < 5; a++)
    for (int b = 0; b < 5; b++)
      for (int c = 0; c < 5; c++)
        ans += dp4[n][a][b][c];

  cout << ans % mod << endl;

  // for (int a = 0; a < 5; a++)
  //   for (int b = 0; b < 5; b++)
  //     for (int c = 0; c < 5; c++)
  //       ans += dp4[n][a][b][c];
  //       ans %=mod;



  // cout << ans << endl;

}




















Measured memory_bytes: 384
#include <iostream>

int main() {
    int a, b, k;
    std::cin >> a >> b >> k;
    
    int i = a;
    for(int c = 0; c < k; i--) {
        if(a % i == 0 && b % i == 0) {
            c++;
        }
    }

    std::cout << i + 1 << std::endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100000000000
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define P pair<int, int>
#define PP pair<P,P>
#define T tuple<int,int,int> 
using namespace std;

int main(){
    int x; cin >> x;
    if(x) cout << 0 << endl;
    else cout << 1 << endl;
return 0;
}



Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define loop(i,x,z) for (int i=x;i<z;i++)
using ll = long long;
int x;
int main()
{
	cin >> x;
	for (ll i = -1000; i < 1001; i++)
	{
		for (ll j = -1000; j < 1001; j++)
		{
			if (i * i * i * i * i - j * j * j * j * j == x)
			{
				cout << i << " " << j;
				return 0;
			}
		}
	}
}

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

int main() {
	int a;
	cin >>a;
	int b=a/1000;
	int c=a%1000/100;
	int d=a%100/10;
	int e=a%10;
	if (c==d) {
      if(b==c||e==c){
        cout<<"Yes"<<endl;
      }else{
        cout<<"No"<<endl;
      }
    }else{
      cout<<"No"<<endl;
  	}
}

Measured memory_bytes: 256
#include <queue>
#include <cstdio>
#include <iostream>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <stack>
#include <time.h>
using namespace std;
typedef long long int ll;

#define EPS (1e-9)
#define INF (1e9)
#define PI (acos(-1))
#define REP(i,n) for(int i=0;i<n;i++)

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

ll beki(ll a, ll b) {
	ll tmp = 1;
	REP(i, b) tmp *= a;
	return tmp;
}

int N;
int H[100010];

int main() {
	cin >> N;
	REP(i, N) cin >> H[i];
	for (int i = N - 1; i >= 1; i--) {
		if (H[i - 1] > H[i])
		{
			H[i - 1]--;
			if (H[i - 1] > H[i]) {
				cout << "No" << endl;
				return 0;
			}
		}
	}
	cout << "Yes" << endl;
}

Measured memory_bytes: 640
def getN():
    return int(input())

def getlist():
    return [int(x) for x in input().split()]

n, q = getlist()
sin = " " + input() + " "
oprs = []
lsafe = 1
rsafe = n
lborder = sin[:2]
rborder = sin[-2:]

for i in range(q):
    oprs.append(input().split())
for opr in oprs[::-1]:
    #print(lsafe, lborder, rsafe, rborder, opr)
    if opr[1] == "L":
        if opr[0] == lborder[1]:
            lsafe += 1
            lborder = lborder[1] + sin[lsafe]
        if opr[0] == rborder[1]:
            rsafe += 1
            rborder = rborder[1] + sin[rsafe+1]
    else: #opr = R
        if opr[0] == rborder[0]:
            rsafe -= 1
            rborder = sin[rsafe] + rborder[0]
        if opr[0] == lborder[0]:
            lsafe -= 1
            lborder = sin[lsafe-1] + lborder[0]

    if rsafe < lsafe:
        break
print(rsafe-lsafe+1)


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

#define int long long

using namespace std;

int a[100001];
int b[100001];


 main () {
 	int n;
 	cin >> n;
 	for (int i = 1;i <= n;i ++) {
 		cin >> a[i] >> b[i];
 	}
 	int cur = 0, ans = 0;
 	for (int i = n;i >= 1;i --) {
 		a[i] += cur;
 		int x = a[i] / b[i];
 		if (a[i] % b[i] == 0) {
 			x = x * (b[i]);
 		} 
 		else x = (x + 1) * (b[i]);
 		ans += x - a[i];
 		cur += x - a[i];
 	}
 	cout << ans;
	return 0;
}

Measured memory_bytes: 1920
#![allow(
  non_snake_case,
  unused_variables,
  unused_assignments,
  unused_mut,
  unused_imports,
  unused_macros,
  dead_code
)]
use proconio::fastout;
use proconio::input;
use proconio::marker::*;
use std::cmp::*;
use std::collections::*;
//use std::collections::VecDeque;
macro_rules! debug {
  ($($a:expr),* $(,)*) => {
      #[cfg(debug_assertions)]
      eprintln!(concat!($("| ", stringify!($a), "={:?} "),*, "|"), $(&$a),*);
  };
}
#[fastout]
fn main() {
  input! {
    N:usize,
    XY:[(i64,i64);N]
  }
  // 傾き-1の線分の距離が最大になるケースと傾き1の線分のケースで考える。
  // 傾き1のケース
  let mut minV1 = std::i64::MAX;
  let mut maxV1 = std::i64::MIN;
  let mut minV2 = std::i64::MAX;
  let mut maxV2 = std::i64::MIN;
  for i in 0..N {
    let v1 = XY[i].0 + XY[i].1;
    let v2 = XY[i].0 - XY[i].1;
    minV1 = min(minV1, v1);
    minV2 = min(minV2, v2);
    maxV1 = max(maxV1, v1);
    maxV2 = max(maxV2, v2);
  }
  let mut ans = max(maxV1 - minV1, maxV2 - minV2);
  println!("{}", ans);
}


Measured memory_bytes: 8956
#include<stdio.h>

int main(void){

int x,y;
int xj,yj;

x=0;
y=0;

scanf("%d %d",&x,&y);

if(x == 2){
	xj = 1;

}else if(x == 4 || x == 6 ||  x == 9 || x == 11){
	xj = 2;

}else{
	xj = 3;

}

if(y == 2){
	yj = 1;

}else if(y == 4 || y == 6 ||  y == 9 || y == 11){
	yj = 2;

}else{
	yj = 3;

}

if(xj == yj){

	printf("Yes");

}else{
	printf("No");

}

return 0;

}

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

using namespace std;

#define ll long long
#define ull unsigned long long
#define vll vector<ll>
#define pii pair<int, int>
#define vii vector<pii>
#define vs vector<string>
#define vb vector<bool>
#define vi vector<int>
#define vd vector<double>
#define vvi vector< vector<int> >
#define vvii vector< vector< pii > >
#define ld long double
#define mapii map<int, int>
#define mapsi map<string, int>
#define erep(i, x, n) for (auto i = x; i<=(ll)(n); i++)
#define rep(i, x, n) for(auto i = x; i<(ll)(n); i++)
#define INF  LLONG_MAX
#define all(v) ((v).begin()), ((v).end())
#define sz(v) ((int)((v).size()))
#define pi  acos(-1)
#define mod(n,m) ((n % m + m) % m)
#define eps (1e-8)
#define reset(n, m) memset(n, m, sizeof n)
#define endl '\n'
#define output freopen("output.txt", "w", stdout)
#define mp(x, y, z) {x, {y, z}}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	ll a, b;
	cin >> a >> b;
	ll res = a*b;
	
	if (res&1)
		cout << "Odd";
	else cout << "Even";
	
	return 0;
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int x,a,b,a1=0,b1=0;
	cin>>x>>a>>b;
	a1=abs(x-a);
	b1=abs(x-b);
	if(a1>b1)
	cout<<"B";
	else
	cout<<"A";
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  public static void main(String args[]) throws Exception {
    Scanner scanner = new Scanner(System.in);
    int N = scanner.nextInt();
    int M = scanner.nextInt();
    int X = scanner.nextInt();
    int Y = scanner.nextInt();
    for(int i = 0; i < N; ++i) {
        int p = scanner.nextInt();
        if (X < p) X = p;
    }
    for(int i = 0; i < M; ++i) {
        int p = scanner.nextInt();
        if (p < Y) Y = p;
    }
    if(X < Y) {
        System.out.println("No War");
    } else {
        System.out.println("War");
    }
  }
}


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

int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	long long l, m, n, o;
	l = (long long)a * c;
	m = (long long)a * d;
	n = (long long)b * c;
	o = (long long)b * d;
	cout << (long long)max(max(l, n), max(m, o));
}

Measured memory_bytes: 3644
use std::io;
use std::collections::VecDeque;


fn main() {
    let q = read_one::<usize>();
    let mut vec = VecDeque::new();
    for _ in 0..q {
        let s = read::<isize>();
        match s[0] {
            0 => {
                if s[1] == 0 { vec.push_front(s[2]); }
                else { vec.push_back(s[2]); }
            },
            1 => { println!("{}", vec[s[1] as usize]); },
            _   => {
                if s[1] == 0 { vec.pop_front(); }
                else { vec.pop_back(); }
            },
        }
    }
}


#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
std::str::FromStr,
T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
std::str::FromStr,
T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}


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

int main(){
  int n; cin>>n;
  vector<int> d(n);
  for(int i=0; i<n; ++i)cin>>d[i];

  int sum=accumulate(d.begin(), d.end(), 0);

  int ans=0;
  for(int i=0; i<n-1; ++i){
    int x=d[i]; sum-=x;
    ans+=x*sum;
  }

  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;
typedef long long ll;
#define forr(i, n) for(ll i=0; i<n; i++)
//No change above here
const ll maxi = 302;
ll mod = (1e9 + 7);
int main()
{
	ll h, w, k;
	cin>>h>>w>>k;
	vector<string> str(h);
	forr(i, h)
	cin>>str[i];
	ll ans=0;
	forr(i1, (ll)pow(2, h))
	{
	    forr(j1, (ll)pow(2, w))
	    { 
	        ll nigger=0;
	        forr(i, h)
	        {
	            forr(j, w)
	            {
	                if(i1&(1<<i)||j1&(1<<j))
	                continue;
	                if(str[i][j]=='#')
	                nigger++;
	            }
	        }
	        if(nigger==k)
	        ans++;
	    }
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3960
#include<iostream>

using namespace std;

int n;
void solve() {
    int ans=0;
    int add[1003]={};
    for(int i=1;i<n;i++) {
        add[i]=add[i-1]+i;
    }
    for(int l=0;l<n;l++) {
        for(int r=l;r<n;r++) {
            int t = add[r]-add[l];
            if(t<0) t=-t;
            if(n==t) ans++;
        }
    }
    cout<<ans<<endl;
}
int main() {
    while(cin>>n) {
        if(n==0) return 0;
        solve();
    }

    return 0;

}

Measured memory_bytes: 1164
import sys,collections,math 
sys.setrecursionlimit(10**7)
def Is(): return [int(x) for x in sys.stdin.readline().split()]
def Ss(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N = I()
t = N
while 1:
    sqr = math.sqrt(t)
    if (sqr==int(sqr)):
        print(int(sqr**2))
        break
    else:
        t= t - 1
        

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

#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
const int inf = 1000000001;
const ll INF = 1e16;
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<<fixed<<p<<endl;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;
static const int N = 100010;

int n;
//i番目からadj[i].second番目はつながっていて、重みはadj[i].first
vector< vector< pair<int, int> > > adj(N, vector< pair<int, int> >());
vl d(N, INF);

void dijkstra(int s) {
	priority_queue< pair<int, int>, vector< pair<int, int> >, greater< pair<int, int> > > pq;
	int i;
	vi color(n, WHITE);

	d[s] = 0;
	pq.push(make_pair(0, s));
	color[s] = GRAY;

	while (!pq.empty()) {
		pair<int, int> f = pq.top();
		pq.pop();
		int u = f.second;
		color[u] = BLACK;
		if (d[u]<f.first) {
			continue;
		}
		for (i = 0; i < adj[u].size(); i++) {
			int v = adj[u][i].second;
			if (color[v] == BLACK) {
				continue;
			}
			if (d[v]>d[u] + adj[u][i].first) {
				d[v] = d[u] + adj[u][i].first;
				pq.push(make_pair(d[v], v));
				color[v] = GRAY;
			}
		}
	}
}


int main() {
	int i, j;
	cin >> n;
 	for (i = 0; i < n-1; i++) {
		int a, b, c;
		cin >> a >> b >> c;
		a--; b--;
		adj[a].push_back(make_pair(c, b));
		adj[b].push_back(make_pair(c, a));
	}
	int q, k;
	cin >> q >> k;
	k--;
	dijkstra(k);
	for (i = 0; i < q; i++) {
		int x, y;
		cin >> x >> y;
		x--; y--;
		cout << d[x] + d[y] << endl;
	}

}

Measured memory_bytes: 9204
#include<iostream>

using namespace std;

int main(){
  int w,h;
  int i,j;

  while(true){
    cin >> h >> w;
    if( h == 0 && w == 0) break;
  for(i = 0; i < h; i++){
    for(j = 0; j < w; j++){
      if( (0 < j && j < w-1) && (0 < i && i < h-1))
	cout << ".";
      else cout << "#";
    }
    cout << endl;
  }
  cout << endl;
  }
  return 0;
}

Measured memory_bytes: 1152
# include <bits/stdc++.h>
  typedef long long ll;
#define pii  pair<int,int>
#define vpii vector<pii>
#define vll  vector<ll>
#define vi  vector<int>
#define pb push_back
#define f  first
#define s  second
#define all v.begin(),v.end()
#define fio ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
typedef unsigned long long ulll;
 
using namespace std ;
int main () {

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

Measured memory_bytes: 256
def main():
    import sys
    from collections import Counter
    # readline = sys.stdin.readline
    readlines = sys.stdin.readlines
    H, W, N = map(int, input().split())
    P = set()
    for s in readlines():
        a, b = map(int, s.split())
        a -= 1; b -= 1
        P.add((a, b))

    cnt = Counter()
    for a, b in P:
        for oa in range(a - 2, a + 1):
            for ob in range(b - 2, b + 1):
                if 0 <= oa <= H - 3 and 0 <= ob <= W - 3:
                    cnt[(oa, ob)] += 1
    ans = Counter(cnt.values())
    ans[0] = (H - 2) * (W - 2) - sum(ans.values())

    for i in range(10):
        print(ans[i])


if __name__ == "__main__":
    main()


Measured memory_bytes: 169080
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;


int main() {
	LL N,Q;
	cin >> N >> Q;
	vector<LL> pos;
	pos.push_back(0);
	pos.push_back(N);
	for(int i=0; i<Q; i++) {
		LL q;
		cin >> q;
		while(q <= pos.back())
			pos.pop_back();
		pos.push_back(q);
	}
	
//	vector<LL> nums;
	priority_queue<PII> num;
	LL mult = 1;
//	num.push(ma);
	for(int i=pos.size()-2; i>=1; i--) {
		assert(pos[i+1] > pos[i]);
		num.push(PII(pos[i+1] % pos[i], mult));
		
		mult = mult * (pos[i+1] / pos[i]);
		while(true) {
			if(num.empty()) break;
			if(num.top().first < pos[i]) break;
			PII cur = num.top(); num.pop();
			mult += (cur.first / pos[i]) * cur.second;
			num.push(PII(cur.first % pos[i], cur.second));	
		}
	}
	
	vector<LL> imos(N+1, 0);
	while(!num.empty()) {
		PII cur = num.top(); num.pop();
		if(cur.first>0)
			imos[cur.first-1] += cur.second;
	}
	for(int i=N-1; i>=0; i--) {
		imos[i] += imos[i+1];
	}
	for(int i=0; i<pos[1]; i++)
		imos[i] += mult;
	LL sum = 0;
	for(int i=0; i<N; i++) {
		cout << imos[i] << endl;
		sum += imos[i];
	}
	assert(sum == pos.back());
	
	return 0;
}



Measured memory_bytes: 4848
#include<bits/stdc++.h>
#define rep(i,b) for(int i=1;i<=b;i++)
#define drep(i,b) for(int i=b;i>=1;i--)
#define Rep(i,a,b) for(int i=a;i<=b;i++)
#define pr pair<int,int>
#define ff first
#define ss second
#define int long long
#define endl '\n'
using namespace std;
const int N=2e5+5;
const int mod=1e9+7;
int n,m,k,t,x,y,z;

#define prr pair<pr,int>

int poww(int x,int k) {
    if(k==0) return 1;
    int t=poww(x,k/2);
    if(k&1) return t*t%mod*x%mod;
    else return t*t%mod;
}

void solve(int ans=1) {
    cin>>n;
    map<pr,int> mp;
    vector<pr> b;
    int _ans=0;
    rep(i,n) {
        cin>>x>>y;
        int t=__gcd(x,y);
        if(t) x/=t,y/=t;
        if(x==0&&y) y=1;
        if(x&&y==0) x=1;
        if(x<0) x*=-1,y*=-1;
        mp[pr(x,y)]++;
    }
    for(prr p:mp) if(p.ss) {
        int x=p.ff.ff,y=p.ff.ss;
        if(x==0&&y==0) continue;
        else if(x==0) {
            x=1,y=0;
        } else if(y==0) {
            x=0,y=1;
        } else swap(x,y),x=-x;
        if(x<0) y*=-1,x*=-1;
        int &t=mp[pr(x,y)],t2=p.ss;
        //cout<<x<<' '<<y<<' '<<t<<endl;
        if(t) b.push_back(pr(t,t2));
        else ans=(ans*poww(2,t2))%mod;
        t=0;
    }
    rep(i,b.size()) {
        int x=b[i-1].ff,y=b[i-1].ss;
        ans=ans*((poww(2,x)%mod+poww(2,y)%mod-1+mod)%mod)%mod;
    }
    cout<<(ans+mp[pr(0,0)]-1+mod)%mod<<endl;
}

#undef int
int main() {
    ios::sync_with_stdio(false);
    //int T;cin>>T;
    //while(T--)
        solve();
}


Measured memory_bytes: 28656
N, M = [int(_) for _ in input().split()]
P = [0 for _ in range(N)]

ans,pen = 0,0
for _ in range(M):
    p,s = input().rstrip().split(' ')
    p = int(p) - 1
    if P[p] == -1:
        continue
    if s == "WA":
        P[p] += 1
    else:
        ans += 1
        pen += P[p]
        P[p] = -1
print(ans,pen)

Measured memory_bytes: 3888
#include<stdio.h>

int wall[15][15], x, y, way, i, j, anyway;

int main(){
  for(i = 1;i <= 9;i++){
    for(j = 1;j <= 5 - (i % 2);j++){
      scanf("%1d", &wall[i][j]);
    }
  }
  x = 0;
  y = 0;
  way = 0;// 0:R, 1:D, 2:L, 3:U
  anyway = 0;
  do{
    if(way == 0){
      if(!anyway && wall[x * 2][y + 1] == 1){
	way = 3;
	anyway = 1;
      }
      else if(wall[x * 2 + 1][y + 1] == 1){
	y++;
	anyway = 0;
	putchar('R');
      }
      else{
	way = 1;
	anyway = 0;
      }
    }
    if(way == 1){
      if(!anyway && wall[x * 2 + 1][y + 1] == 1){
	way = 0;
	anyway = 1;
      }
      else if(wall[x * 2 + 2][y + 1] == 1){
	x++;
	anyway = 0;
	putchar('D');
      }
      else{
	way = 2;
	anyway = 0;
      }
    }
    if(way == 2){
      if(!anyway && wall[x * 2 + 2][y + 1] == 1){
	way = 1;
	anyway = 1;
      }
      else if(wall[x * 2 + 1][y] == 1){
        y--;
	anyway = 0;
	putchar('L');
      }
      else{
	way = 3;
	anyway = 0;
      }
    }
    if(way == 3){
      if(!anyway && wall[x * 2 + 1][y] == 1){
	way = 2;
	anyway = 1;
      }
      else if(wall[x * 2][y + 1] == 1){
	x--;
	anyway = 0;
	putchar('U');
      }
      else{
	way = 0;
	anyway = 0;
      }
    }
  }while(x != 0 || y != 0);
  puts("");
  return 0;
}

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

int main(){
	ll x,k,d;
	cin >> x >> k >> d;
	x = abs(x);
	ll ans = 0;
	if(x/d >= k){
		ans = x - d*k;
	}
	else{
		ll e = x/d;
		k -= e;
		x -= e*d;
		if(k%2 == 1) x = abs(x - d);
		ans = x;
	}
	cout << ans << endl;
}

Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>
#include <utility>
using namespace std;

typedef long long lint;

int main(){
    int W,H;
    int px=1,py=1;
    cin >> W >> H;
    pair<lint,bool> *edge;
    edge=new pair<lint,bool>[W+H];
    for(lint i=0;i<W+H;i++){
        lint L;
        cin >> L;
        edge[i]=make_pair(L,i<W);
    }
    sort(edge,edge+W+H);

    lint cost=0;
    for(int j=1;j<=W+H;j++){
        if(edge[W+H-j].second){
            cost+=edge[W+H-j].first*px;
            py++;
        }else{
            cost+=edge[W+H-j].first*py;
            px++;
        }
    }

    cout << cost << endl;

    return 0;
}

Measured memory_bytes: 3328
#include<iostream>
#include<vector>
#include<algorithm>
#include<stdlib.h>
#include<utility>
#include<functional>
#include<cfenv>
#include<cmath>
#include<string>
#include<queue>
#include<stack>
#include<map>
#include<set>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define vint vector<int>
#define vvint vector<vint>
#define P pair<ll,ll>
#define INT_MAX 2147483647
#define MOD 1000000007
#define PI 3.14159265358979323846
#define all(a) (a).begin(),(a).end()
using namespace std;
typedef long long ll;

#define MAX 1000000000000


int main(void) {
	int x, n; cin >> x >> n;
	map<int,int> mp;
	rep(i, n) {
		int y; cin >> y;
		mp[y]++;
	}
	
	for (int i = 0; i <= 100; i++) {
		if(mp[x-i]==0){
			cout << x - i << endl;
			break;
		}
		if (mp[x + i] == 0) {
			cout << x + i << endl;
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 3632
class Dice:
    def __init__(self, numbers):
        self.numbers = numbers
        self.number_dict = {1:numbers[0], 2:numbers[1], 3:numbers[2], -3:numbers[3], -2:numbers[4], -1: numbers[5]}
        self.top = 1
        self.front = 2
        self.right = 3

    def move(self, direction):
        if direction == 'N':
            self.top, self.front = self.front, -self.top
        elif direction == 'S':
            self.top, self.front = -self.front, self.top
        elif direction == 'E':
            self.top, self.right = -self.right, self.top
        else:
            self.top, self.right = self.right, -self.top

    def show_number(self):
        print(self.number_dict[self.top])

dice = Dice(list(map(int, input().split())))
move_cmd = input()
for char in move_cmd:
    dice.move(char)
dice.show_number()



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

int main(void) {

	for (int i = 1; i <10; i++) {
		for (int j = 1; j <10; j++) {
			cout << to_string(i) + "x" + to_string(j) + "=" + to_string(i*j) << endl;
		}
	}

}


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

using std::cin;
using std::cout;
using std::endl;
using std::vector;

int main(int argc, char* argv[]) {
  int n;
  cin >> n;

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

  double prod = 1;
  for (int b : a) {
    prod *= b;
  }

  double denom = 0;
  for (int b : a) {
    denom += prod / b;
  }

  cout << (prod / denom) << endl;

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    char s[100];
    int i;
    while(~scanf("%s",s))
    {
        int acm=0;
        for(i=0;i<3;i++)
            if(s[i]==s[i+1])
            {
                acm=1;
                break;
            }
        if(acm)
            printf("Bad\n");
        else
            printf("Good\n");
    }
    return 0;
}


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

using namespace std;

#define ll long long;

int main() {
  int n,k,x,y;
  cin >> n >> k >> x >> y;
  int ans=0;

  for(int i=0; i<n; ++i) {
    if(i>=k) {
      ans+=y;
    } else {
      ans+=x;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3612
#include<bits/stdc++.h>
#define For(a,b,c) for(int a=b;a<=c;++a)
#define Dor(a,b,c) for(int a=b;a>=c;--a)
#define LL long long
using namespace std;
const int N=100007;
int n,C[60];
LL A[N],S[60];
void ins(LL x) {
	Dor(i,59,0)
	if(x&(1LL<<i)) {
		if(!S[i]) {
			S[i]=x;
			break;
		}
		x^=S[i];
	}
}
int main() {
	scanf("%d",&n);
	For(i,1,n) scanf("%lld",&A[i]);
	For(i,1,n)
		For(j,0,59)
		if((A[i]&1LL<<j)) ++C[j];
	For(i,1,n)
		For(j,0,59)
		if((A[i]&1LL<<j)&&C[j]&1) A[i]^=1LL<<j;
	For(i,1,n) ins(A[i]);
	LL ans=0;
	Dor(i,59,0) ans=max(ans,ans^S[i]);
	ans<<=1;
	For(i,0,59)
	if(C[i]&1) ans+=1LL<<i;
	printf("%lld",ans);
	return 0;
}

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

int string_distance(const string s, const string t) {
	const auto n = s.size();
	const auto m = t.size();
	// dp[i][j]: distance between s[0..i-1] and t[0..j-1]
	vector<vector<int>>dp(n + 1, vector<int>(m + 1, 0));
	for (int i = 0; i <= n; i++) {
		dp[i][0] = i;
	}
	for (int j = 1; j <= m; j++) {
		dp[0][j] = j;
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			dp[i][j] = min({ dp[i - 1][j] + 1,dp[i][j - 1] + 1,dp[i - 1][j - 1] + (s[i - 1] == t[j - 1] ? 0 : 1) });
		}
	}
	return dp[n][m];
}

int main() {
	string s, t;
	cin >> s >> t;
	cout << string_distance(s, t) << endl;
	return 0;
}


Measured memory_bytes: 6900
n = int(input())
S = list(input().split())
str_list = []
for s in S:
  str_list.append(list(s))
a = str_list[0].count('W')
if a == 0:
  print(a)
  exit()
else:
  ans = str_list[0][-a:].count('R')
print(ans)

Measured memory_bytes: 12156
#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
#include <set>
#include <cmath>
#include <tuple>
#include <cstring>
#include <map>
#include <iomanip>
#include <ctime>
#include <complex>
#include <cassert>
#include <climits>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define _ << " " <<
#define all(X) (X).begin(), (X).end()
#define len(X) (X).size()
#define Pii pair<int, int>
#define Pll pair<ll, ll>
#define Tiii tuple<int, int, int>
#define Tlll tuple<ll, ll, ll>

int main() {
    string s;
    cin >> s;
    if (s == "AAA" || s == "BBB") {
        cout << "No" << endl;
    }
    else cout << "Yes" << endl;
}

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

int main() {
	// your code goes here
	int n;
	cin>>n;
	int a[n],b[n],c[n-1];
	for(int i=0;i<n;i++)
	{
	    cin>>a[i];
	}
	for(int i=0;i<n;i++)
	{
	    cin>>b[i];
	}
	for(int i=0;i<n-1;i++)
	{
	    cin>>c[i];
	}
	int total=0;
	for(int i=0;i<n;i++)
	{
	    if(i!=0)
	    {
	        if(a[i-1]==a[i]-1) { total+=b[a[i]-1]+c[a[i]-2];}
	         else total+=b[a[i]-1];
	    }
	    else total+=b[a[0]-1];

	}
	cout<<total<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REV(c) reverse((c).begin(),(c).end())
#define BITSEARCH(i,n) for(int i=0;i<(1<<(n));++i)
#define BITCHK(i,j) (i) & (1<<(j))

/* BITSEARCH 使い方
 
BITSEARCH(i,n){
  vector<int> h;
  REP(j,n){
    if (BITCHK(i,j)){
      h.push_back(j+1);
    }
  }
}

*/

using namespace std;

// 最大公約数
int64_t gcd(int64_t a, int64_t b) {
  return b != 0 ? gcd(b, a % b) : a;
}

// 最小公倍数
int64_t lcm(int64_t a, int64_t b) {
  return a * b / gcd(a, b);
}

int ctoi(char c){
  return c - '0';
}

struct UnionFind {
  vector< int > data;
 
  UnionFind(int sz) {
    data.assign(sz, -1);
  }
 
  bool unite(int x, int y) {
    x = find(x), y = find(y);
    if(x == y) return (false);
    if(data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return (true);
  }
 
  int find(int k) {
    if(data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }
 
  int size(int k) {
    return (-data[find(k)]);
  }
};

int64_t rec(auto t,auto p,auto c,auto k,auto path,auto fact){
  int64_t mod = 1000000007;
  auto v = path.at(c);
  if (p == 0){
    if (v.size() > 0){
      t = t * fact.at(v.size()) * k * (k-1) % mod;
      for(auto a:v){
        if (path.at(a).size() > 1){
          t = rec(t,c,a,k,path,fact);
        }else{
          t = t * fact.at(path.at(a).size()) % mod;
        }
      }
    }
  }else{
    if (v.size() > 1){
      t = t * fact.at(v.size()) % mod;
      for(auto a:v){
        if (a!=p){
          if (path.at(a).size() > 1){
            t = rec(t,c,a,k,path,fact);
          }else{
            t = t * fact.at(path.at(a).size()) % mod;
          }
        }
      }
    }
  }
  return t % mod;
}

int main(){
  int64_t mod = 1000000007;
  int64_t n, k;
  cin >> n >> k;
  vector<pair<int64_t, int64_t>> ab(n-1);
  vector<vector<int64_t>> path(n+1);
  REP(i,n-1){
    int64_t a,b;
    cin >> a >> b;
    ab.at(i).first = min(a,b);
    ab.at(i).second = max(a,b);
    path.at(a).push_back(b);
    path.at(b).push_back(a);
    if (path.at(a).size() > k - 1 || path.at(b).size() > k - 1){
      cout << 0 << endl;
      return 0;
    }
  }
  if (n > 2 && k <= 2){
    cout << 0 << endl;
    return 0;
  }else if (n==1){
    cout << k % mod << endl;
    return 0;
  }else if (n == 2 & k >= 2){
    cout << k * (k-1) % mod << endl;
    return 0;
  }else if (n== 2 && k == 1){
    cout << 0 << endl;
    return 0;
  }
  vector<int64_t> fact(k+2);
  int64_t sum=1;
  fact.at(1) = 1;
  for (int64_t i=0;i<k-1;i++){
    sum = sum * (k-2-i) % mod;
    fact.at(i+2) = sum;
  }
  int64_t t = 1;
  REP(i,n+1){
    if (i==0){
      continue;
    }else if(i==1){
      if (path.at(i).size() > 0){
        t = t * fact.at(path.at(i).size()) * k * (k-1) % mod;
      }
    }else{
      if (path.at(i).size() > 1){
        t = t * fact.at(path.at(i).size()) % mod;
      }
    }
  }
  //t = rec(t,0,1,k,path,fact);
  cout << t << endl;
  return 0;
}




Measured memory_bytes: 8820
/*input
3
6 10 16
*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
const int N = 1e6+1;
vector<int> cnt;
vector<bool> prime(N, true);
int a[N]={};
void init(){
	prime[1]=false;
	for(int i=2; i*i<N; ++i){
		if(prime[i]){
			for(int j=i*i; j<N; j+=i){
				prime[j]=false;
			}
		}
	}
}
	
signed main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	init();
	int n;
	cin>>n;
	for(int i=0; i<n; ++i){
		int x; cin>>x;
		if(x%2==0) a[2]++;
		while(x%2==0)
			x/=2;
		for(int i=3; i*i<=x; i+=2){
			if(x%i==0){
				a[i]++;
				while(x%i==0){
					x /= i;
				}
			}
		} 
		if(x>2)
			a[x]++;
	}
	int cnt=0;
	bool pairwise=true, setwise=true;
	for(int i=2; i<N; ++i){
		if(prime[i]){
			if(a[i]>1)
				pairwise=false;
			if(a[i]==n){
				setwise=false;
			}
		}
	}
	if(pairwise){
		cout<<"pairwise coprime";
	}
	else if(setwise){
		cout<<"setwise coprime";
	}
	else{
		cout<<"not coprime";
	}
	return 0;	
}

Measured memory_bytes: 11516
def d_cake_123_priority_queue(X, Y, Z, K, A, B, C):
    # editionalの解法3
    import heapq
    # 数列A, B, Cを降順ソート
    a, b, c = sorted(A, reverse=True), sorted(B, reverse=True), sorted(C, reverse=True)

    def evaluation(x, y, z):
        # heapqは最小値を取り出す方式なので、符号を反転させないといけない
        return (-(a[x] + b[y] + c[z]), x, y, z)

    # priority queue を定義し、(A_1 + B_1 + C_1, 1, 1, 1) を追加
    q = []
    heapq.heappush(q, evaluation(0, 0, 0))
    ans = []

    # priority queueに対するK回の操作の部分
    for _ in range(K):
        (e, x, y, z) = heapq.heappop(q)
        ans.append(-e)
        if x + 1 < X and evaluation(x + 1, y, z) not in q:
            heapq.heappush(q, evaluation(x + 1, y, z))
        if y + 1 < Y and evaluation(x, y + 1, z) not in q:
            heapq.heappush(q, evaluation(x, y + 1, z))
        if z + 1 < Z and evaluation(x, y, z + 1) not in q:
            heapq.heappush(q, evaluation(x, y, z + 1))
    return '\n'.join(map(str, ans[:K]))

X, Y, Z, K = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]
print(d_cake_123_priority_queue(X, Y, Z, K, A, B, C))

Measured memory_bytes: 4084
n=int(input())
score=[0,0,0]
for _ in range(n):
    tc,hc=map(str,input().split())
    if tc==hc:
        score[1]+=1
        score[-1]+=1
        continue
    i=0
    ml=min(len(tc),len(hc)) 
    while tc[i]==hc[i]:
        i+=1
        if i>=ml:
            tc+="0"
            hc+="0"
            break
    r=ord(tc[i])-ord(hc[i])
    r=r//abs(r)
    score[r]+=3

print("{} {}".format(score[1],score[-1]))


Measured memory_bytes: 5600
import java.util.Scanner;

public class Main {

    public static void main(String args[] ) throws Exception {


        Scanner s = new Scanner(System.in);


        int N = s.nextInt();    // Reading input from STDIN

        int i=1;

        String result = "YES";
        int count = 0;
        while(i<=N){
            int p = s.nextInt();
            count += i!=p?1:0;

            if(count>2){
                result = "NO";
                break;
            }
            i++;
        }
        System.out.println(result);

    }
}


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

int main()
{
    int N;
    cin >> N;
    double xi;
    string ui;
    double res = 0;
    for(int i=0;i<N;i++){
        cin >> xi >> ui;
        if     (ui=="JPY") res += xi;
        else if(ui=="BTC") res += 380000 * xi;
        else abort();
    }
    cout<<res<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>

int main(){
  int a, n;
  std::cin >> n;
  std::cin >> a;
  // if (n<500){
  //   if (n<=a)
  //     std::cout << "Yes" << std::endl;
  //   else
  //     std::cout << "No" << std::endl;
  // }else{
  //   while (n>500){
  //     n -= 500;
  //   }
  //   if (n<=a)
  //     std::cout << "Yes" << std::endl;
  //   else
  //     std::cout << "No" << std::endl;
  // }
  if (n%500<=a)
    std::cout << "Yes" << std::endl;
  else
    std::cout << "No" << std::endl;
  return 0;
}

Measured memory_bytes: 3624
#include<iostream>
#include<vector>
#include<string>
using namespace std;
int main() {
	int n;
	while (cin >> n){
		if (n == 0)break;
		vector<pair<char, char> >l;
		string s;
		for (int i = 0; i < n; i++){
			pair<char, char>c;
			cin >> c.first >> c.second;
			l.push_back(c);
		}
		cin >> n;
		for (int i = 0; i < n; i++){
			char c; cin >> c;
			for (int i = 0; i < l.size(); i++){
				if (c==l[i].first){
					c = l[i].second;
					goto h;
				}
			}
		h:
			s += c;
		}
		cout << s << endl;
	}
}

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


typedef long long ll;
int N, T, t[201010];
//-----------------------------------------------------------------------------------
int main() {
    cin >> N >> T;
    rep(i, 0, N) scanf("%d", &t[i]);

    ll ans = 0;
    int pre = t[0];
    rep(i, 1, N) {
        ans += min(T, t[i] - pre);
        pre = t[i];
    }
    ans += T;

    cout << ans << endl;
}

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

int main() {
	int N;
	std::cin >> N;
	std::string S;
	std::cin >> S;
	int change = 0;
	for (int i = 0; i < N; i++) {
		if (S[i] == 'E') {
			change++;
		}
	}
	int ans = change;
	for (int i = 0; i < N; i++) {
		if (S[i] == 'E')
		{
			change--;
		}
		if (i > 0 && S[i - 1] == 'W') {
			change++;
		}
		ans = std::min(ans, change);
	}
	std::cout << ans << std::endl;
}

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

int main() {
	int N, M;
	cin >> N >> M;
	vector<int> card(N);
	for (int i = 0; i < M; i++) {
		int L, R;
		cin >> L >> R;
		card.at(L - 1)++;
		if (R != N) {
			card.at(R)--;
		}
	}

	for (int i = 1; i < N; i++) {
		card.at(i) += card.at(i - 1);
	}

	int cnt = 0;
	for (int i = 0; i < N; i++) {
		if (card.at(i) == M) {
			cnt++;
		}
	}

	cout << cnt << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
typedef pair<double,double> P;
typedef pair<int,int> PP;
 
double D(P a,P b) {return sqrt((a.F-b.F)*(a.F-b.F)+(a.S-b.S)*(a.S-b.S));}
const int N=222222;
int p[N],r[N];
void init(){for(int i=0; i<N; i++) p[i]=i,r[i]=0;}
int find(int x){return (p[x]==x)?x:(p[x]=find(p[x]));}
void unite(int x,int y) {
  x=find(x),y=find(y);
  if(x==y)return;
  if(r[x]<r[y])p[x]=y;
  else{p[y]=x;if(r[x]==r[y])r[x]++;}
}
 
int main() {
  init();
  int n;
  double d;
  cin>>n>>d;
  P a[n];
  for(int i=0; i<n; i++) cin>>a[i].F>>a[i].S;
  map<PP,int> m;
  for(int i=0; i<n; i++) {
    int x=floor(a[i].F/d),y=floor(a[i].S/d);
    for(int dx=-1; dx<2; dx++)for(int dy=-1; dy<2; dy++)if(m.count(PP(x+dx,y+dy))) unite(i,m[PP(x+dx,y+dy)]);
    m[PP(x,y)]=i;
  }
  set<int> s;
  for(int i=0; i<n; i++) s.insert(find(i));
  cout<<s.size()<<endl;
  return 0;
}


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

int main() {
  int h, w, k, num = 0;
  cin >> h >> w >> k;
  vector<string> s(h);
  rep(i, h) cin >> s[i];

  vector<vector<int>> a(h, vector<int>(w));

  vector<int> cnt(h);
  rep(i, h) rep(j, w) if (s[i][j] == '#') cnt[i]++;

  auto solve = [&](int cl, int cr) {
    vector<int> P;
    for (int i = cl; i < cr; i++) rep(j, w) if (s[i][j] == '#') P.push_back(j);
    sort(P.begin(), P.end());

    rep(i, P.size()) {
      int v1 = 0, v2 = w;
      if (i >= 1) v1 = P[i - 1] + 1;
      if (i < P.size() - 1) v2 = P[i] + 1;
      num++;
      for (int j = cl; j < cr; j++)
        for (int k = v1; k < v2; k++) a[j][k] = num;
    }
  };

  vector<int> vec;
  rep(i, h) if (cnt[i] >= 1) vec.push_back(i);

  rep(i, vec.size()) {
    int v1 = 0, v2 = h;
    if (i >= 1) v1 = vec[i - 1] + 1;
    if (i < vec.size() - 1) v2 = vec[i] + 1;
    solve(v1, v2);
  }

  rep(i, h) rep(j, w) printf("%d%c", a[i][j], (j == w - 1 ? '\n' : ' '));

  return 0;
}


Measured memory_bytes: 4236
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n, m;
    char g[1001][1001], ws;
    scanf("%d%d%c", &n, &m, &ws);
    for (int i = 1; i <= n; i++){
        for (int j = 1; j <= m; j++)
            scanf("%c", &g[i][j]);
        scanf("%c", &ws);
    }
    long long dp[1001][1001];
    dp[1][1] = 1;
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++)
            if (i != 1 || j != 1){
                dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
                if (g[i][j] == '#')
                    dp[i][j] = 0;
                dp[i][j] %= (int) 1e9 + 7;  
            }
    
    printf("%lld\n", dp[n][m]);
    return 0;
}


Measured memory_bytes: 9088
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include <string.h>

using ll = long long;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, x) for(int i=1;i<=(int)(x);i++)
#define rrep(i, x) for(int i=((int)(x)-1);i>=0;i--)
#define rreps(i, x) for(int i=(int)(x);i>0;i--)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>
#define mod 1000000007
#define put2darr(arr, row, col) rep(i, row) { rep(j, col) { printf("%18d", arr[i][j]); } cout << endl; }

using namespace std;

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;
}

/* 1..10
 * rep:   0 1 2 3 4 5 6 7 8 9
 * reps:  1 2 3 4 5 6 7 8 9 10
 * rrep:  9 8 7 6 5 4 3 2 1 0
 * rreps: 10 9 8 7 6 5 4 3 2 1
 */

int main() {
    ll n, a[5];
    cin >> n;
    rep(i,5){
        cin >> a[i];
    }
    sort(a, a+5);
    ll ans = 5 + ceil((n-a[0]) * 1.0 / a[0]);
    cout <<ans << endl;
}



Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<vector>
#include<algorithm>
#include<map>
#include<string>
#define ll long long
using namespace std;
int main(){
     int A,B,T;
     int count = 0;
     cin >> A >> B >> T;
     for(int i = 1;i < T + 0.5; i++){
          if(i % A == 0){
               count += B;
          }
     }
     cout << count << endl;
     return 0;
}

Measured memory_bytes: 256
S = gets.chomp
len = S.length
center = len / 2
if len % 2 == 0
  s, t = center - 1, center
  ans = center
else
  s, t = center, center
  ans = center
end
mark = S[s]
if S[t] == mark
  while s >= 0
    if S[s] == mark && S[t] == mark
      ans += 1
      s -= 1
      t += 1
    else
      break
    end
  end
end
puts ans

Measured memory_bytes: 3836
A = int(input())
B = int(input())
C = int(input())
X = int(input())

counter = 0

for i in range(A+1):
  for j in range(B+1):
    for k in range(C+1):
      if 500*i + 100*j + 50*k == X:
        counter += 1

print(counter)

Measured memory_bytes: 3060