akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
#define pq_pair_tB priority_queue <pair<ll,ll>, vector<pair<ll,ll> > , greater<pair<ll,ll> > > 
#define pq_pair_ts priority_queue <pair<ll,ll> > //第二成分の大きさが関係ない
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll A, B , T;
    cin >> A >> B >> T;
    
    cout << (T / A ) * B << endl;
    
    
    //cout << fixed << setprecision(16) << ans << endl;
    return 0;
}


Measured memory_bytes: 256
using System;

class Program
{
    static void Main(string[] args)
    {
        string[] num = Console.ReadLine().Split(' ');

        int w, h, x, y, r;
        w = int.Parse(num[0]);
        h = int.Parse(num[1]);
        x = int.Parse(num[2]);
        y = int.Parse(num[3]);
        r = int.Parse(num[4]);

        if (x - r < 0 || x + r > w)
        {
            Console.WriteLine("No");
        }else if (y - r < 0 || y + r > h)
        {
            Console.WriteLine("No");
        }
        else if (x - r >= 0 && x + r <= w)
        {
            Console.WriteLine("Yes");
        }else if (y - r >= 0 && y + r <= h)
        {
            Console.WriteLine("Yes");
        }
    }
}



Measured memory_bytes: 8912
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using building = vector<vector<vector<int>>>;

int main() {
  int n_b = 4, n_f = 3, n_r = 10;
  building B(n_b, vector<vector<int>>(n_f, vector<int>(n_r)));

  int n;
  cin >> n;

  rep(i, n) {
    int b, f, r, v;
    cin >> b >> f >> r >> v;
    --b, --f, --r;
    B[b][f][r] += v;
  }

  rep(i, n_b) {
    if (i != 0)
      cout << string(2 * n_r, '#') << endl;
    rep(j, n_f) {
      rep(k, n_r) cout << " " << max(B[i][j][k], 0);
      cout << endl;
    }
  }
}


Measured memory_bytes: 3160
N, A, B, C, D = map(int, input().split())
S = input()
S = '.' + S
if C < D:
    ans = (
        'Yes' if '##' not in S[A:(D + 1)] else
        'No'
    )
else:
    i = A
    j = B
    while i < C:
        if i + 1 == C or i + 2 == C:
            ans = 'Yes'
            break
        elif i + 1 <= C and S[i + 1] == '.' and i + 1 != j:
            i += 1
        elif i + 2 <= C and S[i + 2] == '.' and i + 2 != j:
            i += 2
        else:
            if j + 1 <= D and S[j + 1] == '.':
                j += 1
            elif j + 2 <= D and S[j + 2] == '.':
                j += 2
            else:
                ans = 'No'
                break

print(ans)


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

#define rep(i,n) for(int i=0 ; i<(n) ; i++)
#define repr(i,n) for(int i=(n) ; i>=0 ; i--)
#define ALL(x) (x).begin(),(x).end()

using ll = long long;
using ull = unsigned long long;
 
const ll INF = 1LL<<60;
const int MINF = 1e9;
const int MOD = 1e9+7;

using vi = vector<int>;
using vii = vector<vi>;

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

template<typename T>
T GCD(T a,T b){ return b ? GCD(b,a%b) : a ;}
template<typename T>
T LCM(T a,T b){ return a*b / GCD(a,b) ;}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int k;cin >> k;
    deque<ll> que;
    rep(i,9)que.push_back(i+1);

    if(k <= 9){
        cout << k << endl;
        return 0;
    }

    int size = 9;
    while(size < k){
        ll fst = que.front();que.pop_front();
        if(fst%10 == 0){
            que.push_back(fst*10+fst%10);
            que.push_back(fst*10+fst%10+1);
            size += 2;
        }else if(fst%10 == 9){
            que.push_back(fst*10+fst%10-1);
            que.push_back(fst*10+fst%10);
            size += 2;
        }else{
            que.push_back(fst*10+fst%10-1);
            que.push_back(fst*10+fst%10);
            que.push_back(fst*10+fst%10+1);
            size += 3;
        }
    }
    
    cout << que[que.size()-(size-k)-1] << endl;
    return 0;
}

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


int main(){
	
	string str,ans;
	ans="";
	cin>>str;
	for(int i=0;i<str.size();i++){
		if(str[i]=='B'){
			if(ans.empty()==0){
				ans.pop_back();
			}
		}
		else{
			ans+=str[i];
		}
	}
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 256
@n = gets.to_i
S = gets.split(' ').map(&:to_i)
q = gets.to_i
T = gets.split(' ').map(&:to_i)

def binary_search(arr, key)
  left = 0
  right = @n
  while left < right
    mid = (left + right) / 2
    if arr[mid] == key
      return mid
    elsif key < arr[mid]
      right = mid
    else
      left = mid + 1
    end
  end
  nil
end

count = 0

T.each do |t|
  count += 1 if binary_search(S, t)
end

puts count


Measured memory_bytes: 15332
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int n = sc.nextInt();
        int[] arr = new int[n];
        for(int i = 0; i < n; i++) {
            arr[i] = sc.nextInt();
        }

        int[] min = new int[n];
        min[0] = 0;
        min[1] = Math.abs(arr[1] - arr[0]);


        for(int i = 2; i < n; i++) {
            min[i] = Math.min(Math.abs(arr[i-2] - arr[i]) + min[i-2], Math.abs(arr[i-1] - arr[i]) + min[i-1]);
            //System.out.println(min[i]);
        }

        System.out.println(min[n-1]);


    }
}


Measured memory_bytes: 52704
using System;

class program
{
  static void Main(){
    var input=Console.ReadLine().Split(' ');
    Console.WriteLine(
      input[1] == "+" ? 
      int.Parse(input[0]) + int.Parse(input[2]) :
      int.Parse(input[0]) - int.Parse(input[2])
      );
  }
}

Measured memory_bytes: 11092
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

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

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

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        s: chars,
        mut t: chars
    }
    t.pop();
    println!("{}", if s == t {"Yes"} else {"No"});
}


Measured memory_bytes: 2088
def main():
    from itertools import combinations_with_replacement
    n, m, q, *abcd = map(int, open(0).read().split())

    x = zip(*[iter(abcd)] * 4)

    x = list(x)

    y = range(1, m + 1)
    ans = 0
    for v in combinations_with_replacement(y, n):
        temp = 0
        v = list(v)
        v.sort()
        for (a, b, c, d) in x:
            if v[b - 1] - v[a - 1] == c:
                temp += d

        ans = max(ans, temp)

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9208
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC optimize(3)
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC target("sse3","sse2","sse")
#pragma GCC target("avx","sse4","sse4.1","sse4.2","ssse3")
#pragma GCC target("f16c")
#pragma GCC optimize("inline","fast-math","unroll-loops","no-stack-protector")
#pragma GCC diagnostic error "-fwhole-program"
#pragma GCC diagnostic error "-fcse-skip-blocks"
#pragma GCC diagnostic error "-funsafe-loop-optimizations"
#pragma GCC diagnostic error "-std=c++14"
#include "bits/stdc++.h"
//#include "ext/pb_ds/tree_policy.hpp"
//#include "ext/pb_ds/assoc_container.hpp"
#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
#define fr(x) freopen(x,"r",stdin)
#define fw(x) freopen(x,"w",stdout)
#define iout(x) printf("%d\n",x)
#define lout(x) printf("%lld\n",x)
#define REP(x,l,u) for(ll x = l;x<u;x++)
#define RREP(x,l,u) for(ll x = l;x>=u;x--)
#define complete_unique(a) a.erase(unique(a.begin(),a.end()),a.end())
#define mst(x,a) memset(x,a,sizeof(x))
#define all(a) a.begin(),a.end()
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define MP make_pair
#define sqr(x) ((x)*(x))
#define lowbit(x) (x&(-x))
#define lson (ind<<1)
#define rson (ind<<1|1)
#define se second
#define fi first
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl;
#define sz(x) ((int)x.size())
#define EX0 exit(0);

typedef  long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
using namespace std;
typedef vector<ll> VLL;
typedef vector<int> VI;
const int block_size = 320;
typedef complex<ll> point;
const ll mod = 1e9+7;
const ll inf = 1e9+7;
const ld eps = 1e-9;
const db PI = atan(1)*4;
template<typename T>
inline int sign(const T&a) {
    if(a<0)return -1;
    if(a>0)return 1;
    return 0;
}

template<typename T,typename S>inline bool upmin(T&a,const S&b){return a>b?a=b,1:0;}
template<typename T,typename S>inline bool upmax(T&a,const S&b){return a<b?a=b,1:0;}

template<typename T> inline void in(T &x) {
    x = 0;
    T f = 1;
    char ch = getchar();
    while (!isdigit(ch)) {
        if (ch == '-') f = -1;
        ch = getchar();
    }
    while (isdigit(ch))  {
        x = x * 10 + ch - '0';
        ch = getchar();
    }
    x *= f;
}

ll twop(int x) {
    return 1LL<<x;
}

template<typename A,typename B > inline void in(A&x,B&y) {
    in(x);
    in(y);
}
template<typename A,typename B,typename C>inline void in(A&x,B&y,C&z) {
    in(x);
    in(y);
    in(z);
}
template<typename A,typename B,typename C,typename D> inline void in(A&x,B&y,C&z,D&d) {
    in(x);
    in(y);
    in(z);
    in(d);
}

namespace SOLVE {
    void main(){
        int n,a,b;cin>>n>>a>>b;
        if((b-a)%2 != 0){
            cout<<"Borys\n";
        }else{
            cout<<"Alice\n";
        }
    }
}


int main() {

    
    
    
    
    
    
    
    SOLVE::main();
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>
#include <bitset>
#include<assert.h>

using namespace std;
#define int long long

#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(), (x).end()

template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; abort();}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }




void solve(void)
{
  int N;
  cin>>N;
  if(N ==3)
  {
    cout<<"2 5 63"<<endl;
    return;
  }
  else if(N == 4)
  {
    cout<<"2 5 20 63"<<endl;
    return;
  }
  else if(N == 5)
  {
    cout<<"2 5 20 30 63"<<endl;
  }
  else
  {
    vector<int> vec;
    int MSIX = 0;
    for (int i = 0; i < N; i++)
    {
      if(i%4 == 0)
      {
        vec.push_back(6*(i/4) + 2);
      }
      else if( i %4 == 1)
      {
        vec.push_back(6*(i/4) + 3);
      }
      else if( i %4 == 2)
      {
        vec.push_back(6*(i/4) + 4);
      }
      else if( i %4 == 3)
      {
        vec.push_back(6*(i/4) + 6);
        chmax(MSIX,vec.back());
      }
    }

    int SUM = 0;
    for (int i = 0; i < N; i++)
    {
      SUM += vec[i];
    }
    if(SUM%6 == 2)
    {
      vec[4] = MSIX+6;
    }
    else if(SUM%6 == 3)
    {
      vec[5] = MSIX +6;
    }
    else if(SUM%6 == 5)
    {
      vec[5] = MSIX + 4;
    }

  for (int i = 0; i < N; i++)
  {
    if(i != 0)cout<<" ";
    cout<<vec[i];
  }
  cout<<endl;
      
    
  }

  
  
  
  return;
}
int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(11);
  solve();

  return 0;
}


Measured memory_bytes: 640
#include<stdio.h>
int main(){
	int x[3000],y[3000],z,i,j;
	i=j=1;
	 while(i<=3000)
	{
		scanf("%d%d",&x[i],&y[i]);
		if(x[i]==0 && y[i]==0)
		{
			break;
		
		}
		else if(x[i]>y[i])
		{
			z=x[i];
			x[i]=y[i];
			y[i]=z;
				
		
		}
	
		i++;
		j++;
	}
	
	i = 1;
	
	while(i<=j)
	{
	if(x[i]==0 && y[i]==0)
	{
		break;
	}
	else{
		
	printf("%d %d\n",x[i],y[i]);
	i++;
	}
	}
	
	return 0;
	


}

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

using namespace std;

int main()
{
    int h_1, h_2, k_1, k_2;
    cin >> h_1 >> h_2 >> k_1 >> k_2;
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    
    int hiroshi = (h_1 * a) + (h_2 * b) + (h_1 / 10) * c + (h_2 / 20) * d;
    int kenjiro = (k_1 * a) + (k_2 * b) + (k_1 / 10) * c + (k_2 / 20) * d;

    if (hiroshi == kenjiro) cout << "even" << endl;
    else if (hiroshi > kenjiro) cout << "hiroshi" << endl;
    else if (hiroshi < kenjiro) cout << "kenjiro" << endl;
}


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

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

typedef long long ll;
typedef vector<ll> vl;
typedef long double ld;
typedef vector<ld> vd;
typedef bool bl;
typedef vector<bl> vb;

const ll e5 = 1 << 20;
const ll mod = 998244353;
const ll e3 = 1 << 13;
const ll INF = 1ll << 60;

int main() {
  int r, g, b, n;
  cin >> r >> g >> b >> n;

  int max_r = n / r;
  int cnt = 0;
  rep(i, max_r + 1) {
    int max_g = (n-i*r) / g;
    rep(j, max_g + 1) {
      int remain = n-i*r-j*g;
      if (remain % b == 0) {
        cnt++;
        // cout << "r: " << i << " g: " << j << " b: " << remain / b << endl;
      }
    }
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 256
n, m = map(int,input().split())
h = list(map(int, input().split()))
x = [1] * n
c = []
for i in range(m):
    a, b = map(int, input().split())
    if h[a-1] > h[b-1] and x[a-1] != 0:
        x[a-1] = 1
        x[b-1] = 0
    elif h[a-1] < h[b-1] and x[b-1] != 0:
        x[a-1] = 0
        x[b-1] = 1
    else:
        x[a-1] = 0
        x[b-1] = 0

cnt = 0
for j in x:
    if j == 1:
        cnt += 1
print(cnt)

Measured memory_bytes: 19992
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.container;
import std.array;
import std.math;
import std.range;
import std.typecons;
import std.ascii;
import std.format;

void main()
{
  int[101] imos;
  auto d = readln.chomp.split.map!(to!int);
  imos[d[0]]++;
  imos[d[1]]--;
  imos[d[2]]++;
  imos[d[3]]--;
  int cnt = 0;
  int ite = 0;
  for (int i = 0; i <= 100; ++i) {
    ite += imos[i];
    if (ite == 2) {
      ++cnt;
    }
  }
  writeln = cnt;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using LP = pair<ll, ll>;
const double PI = 3.1415926535897932;

int main()
{
	long long H;
	cin >> H;
	ll score = 0;
	ll split = 1;
	while (H != 1) {
		score += split;
		H = H / 2;
		split *= 2;
	}
	score += split;

	cout << score << endl;
	return 0;
} 

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll n;cin>>n;
  //ll ans=1000 *(n/500) + ;
  ll ans=(n/500*(1000))+5 *((n % 500)/5);
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
def resolve():

    s = input()
    n = len(s)

    dp = [[0] * 13 for _ in range(100010)]
    dp[0][0] = 1

    for i in range(n):

        if s[i] == '?':
            c = -1
        else:
            c = int(s[i])

        for j in range(10):

            if c != -1 and c != j:
                continue

            for k in range(13):
                dp[i+1][(k*10+j) % 13] += dp[i][k]
        for j in range(13):
            dp[i+1][j] %= 1000000007

    print(dp[n][5])
    
resolve()

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<setprecision(std::numeric_limits<float>::max_digits10);
  int n;
  cin>>n;
  ll x=1,y=1;
  rep(i,n) {
    ll t,a;
    cin>>t>>a;
    ll c = max((x+(t-1))/t, (y+(a-1))/a);
    x = t*c,y=a*c;
  }
  cout << x+y << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int partition(int*, int, int);
main(){
  int a[100001],i,n,han;
  scanf("%d",&n);
  for(i=0;i<n;i++)
    {
      scanf("%d", &a[i]);
    }
  han = partition(a,0,n-1);
  for(i=0;i<n;i++)
    {
      if(i == han)
	{
	  printf("[%d]",a[i]);
	}
      else
	{
          printf("%d",a[i]);
	}
	if(i!=n-1)
	  {
	  printf(" ");
	  }
     }
  printf("\n");
  return 0;
}

int partition(int *a, int p, int r)
{
  int x, i, j, tem;
  x = a[r];
  i = p-1;
  for(j=p;j<r;j++)
    {
      if(a[j] <= x)
	{
	  i = i+1;
          tem =  a[i];
          a[i] = a[j];
          a[j] = tem;
	}
    }
      tem = a[i+1];
      a[i+1] = a[r];
      a[r] = tem;
      return i+1;
}

Measured memory_bytes: 996
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;

int dh[] = {1, 0, -1, 0}, dw[] = {0, 1, 0, -1};

int main(){
  int H, W;
  cin >> H >> W;

  vector<string> s(H);
  for(auto& x: s){
    cin >> x;
  }

  vector<vector<int>> dists(H, vector<int>(W, INT_MAX));
  queue<pair<int, int>> que;
  que.push(make_pair(0, 0));
  dists[0][0] = 0;

  int black_cnt = 0;
  for(const auto& ss: s){
    for(const auto& sss: ss){
      if(sss == '#'){
        black_cnt++;
      }
    }
  }
  
  while(!que.empty()){
    auto now = que.front();
    que.pop();

    int h = now.first, w = now.second;
    for(int i = 0; i < 4; i++){
      int h_ = h + dh[i], w_ = w + dw[i];
      if(h_ >= 0 && h_ < H && w_ >= 0 && w_ < W && s[h_][w_] == '.' && dists[h_][w_] > dists[h][w] + 1){
        que.push(make_pair(h_, w_));
        dists[h_][w_] = dists[h][w] + 1;
      }
    }
  }
  if(dists[H - 1][W - 1] == INT_MAX){
    cout << -1 << endl;
  }else{
    cout << H * W - black_cnt - (dists[H - 1][W - 1] + 1) << endl;
  }
  
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <map>
#include <set>
#include <cstring>
#include <string>
#include <cctype>
#include <cassert>

using namespace std;

#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repr(i,b,e) for(int i = (b); i <= (e); i++)
#define INF (1001001001)
#define EPS (1e-15)

#define pr(x) do{cout << (#x) << " = " << (x) << endl;}while(0)
#define pri(x,i) do{cout << (#x) << "[" << i << "] = " << (x[i]) << endl;}while(0)
#define pra(x,n) rep(__i,n) pri(x,__i);
#define prar(x,b,e) repr(__i,b,e) pri(x,__i);

typedef long long llint;
typedef pair<int, int> pint;
typedef vector<int> vint;

int in() {
	int a;
	scanf("%d ", &a);
	return a;
}

int main() {
	int N = in();
	int M = in();
	vint hoge(N + 5);
	for (int i = 0; i < M; i++) {
		int a = in();
		int b = in();
		hoge[a]++;
		hoge[b]++;
	}
	bool ok = true;
	for (int i = 0; i < N; i++) {
		if (hoge[i] % 2) {
			ok = false;
			break;
		}
	}
	cout << (ok ? "YES" : "NO") << endl;
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

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

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

int main(int argc, char const *argv[]) {
    ll n,k; cin>>n>>k;
    vector<ll> a(n);
    rep(i,n) cin>>a[i];
    queue<ll> q;
    for (int i = 0; i < k; ++i) {
        q.push(a[i]);
    }
    for (int i = k; i < n; ++i) {
        ll x = q.front(); q.pop();
        if (x < a[i]) {
            cout << "Yes" << '\n';
        }
        else {
            cout << "No" << '\n';
        }
        q.push(a[i]);
    }
    return 0;
}

Measured memory_bytes: 6372
#include<cstdio>
using namespace std;
int x,y;
int main()
{
	scanf("%d%d",&x,&y);
	if(x%y==0)
	{
		puts("-1");
	}
	else
	{
		printf("%lld\n",1ll*(y-1)*x);
	}
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
  int n;
  long sum=0;
  cin >> n;
  int a[3*n];
  for(int i=0; i<(3*n); i++){
    cin >> a[i];
  }
  sort(a,a+(3*n));
  for(int i=1; i<=n; i++){
    sum += a[3*n - 2*i];
  }
  cout << sum << endl;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
char s[100000+10];
ll zs[100000+10][15];
int p[100000+10];
const ll mod =1000000007;
int my_min(int a,int b)
{
	return a<b?a:b;
}
int main()
{
//	printf("%d\n",70000000%13);
	scanf("%s",s);
	int sum=1;
	int len=strlen(s);
	int js=0;
	int last=-1;
	for(int i=len-1;i>=0;i--)
	{
		if(s[i]!='?')
			js=(js+sum*(s[i]-'0'))%13;
		else
		{
			if(last==-1)
			{
				for(int k=0;k<10;k++)
				{
					int ns=(js+sum*k)%13;
					zs[i][ns]++;
					
				//	printf("%d %d\n",js,ns);
				}
			}
			else
			{
				for(int k=0;k<10;k++)
				{
					for(int qm=0;qm<13;qm++)
					{
						int ns=(js+sum*k)%13;
						int w=(qm-ns+13)%13;
						zs[i][qm]=(zs[i][qm]+zs[last][w])%mod;
					}
				}
			}
			last=i;
			js=0;
		}
		p[i]=sum;
		sum=(sum*10)%13;
	/*	for(int k=0;k<13;k++)
			printf("%d\n",zs[i][k]);*/
	}
	if(last==-1)
	{
		if(js==5)
			printf("1\n");
		else
			printf("0\n");
	}
	else
	{
	ll qqqq=0;
	 qqqq=zs[last][(5-js+13)%13];
	printf("%d\n",qqqq);
	}
	return 0;
}

Measured memory_bytes: 12416
n=int(input())
x=[int(i) for i in input().split()]
y=[]
for i in x:
    y.append(i)
x.sort()

c=int(n/2)
a=x[c]
b=x[c-1]

for i in y:
    if i<=b:
        print(a)
    else:
        print(b)



Measured memory_bytes: 25472
/*Author : Prokash
           JU CSE 48
           CF: epiprokash
           UVa: epiprokash
*/

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

typedef long long ll;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int a,b;
    cin>>a>>b;
    cout<<6-(a+b)<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n-1); i >= 0; i--)
#define all(v) (v).begin(),(v).end()
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; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <class T> T lcm(T a, T b) { return a/gcd(a,b)*b; }
typedef pair<int, int> P;
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const ll MOD = 1e9+7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
	int k, a, b;
	cin >> k >> a >> b;
    string ans = "NG";
    for (int i = a; i <= b; i++) {
        if (i%k==0) {
            ans = "OK";
            break;
        }
    }
	cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 3536
N,K=map(int, input().split())
a=[]
for _ in range(K):
  tmp = input()
  a.append((list(map(int, input().split()))))

b=[]
for t in a:
  for tt in t:
    b.append(tt)

a = set(b)
n = 0

for i in range(1, N+1):
  if i not in a:
    n += 1

print(n)

Measured memory_bytes: 9236
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

template <typename T>
using vector2 = vector<vector<T>>;
template <typename T>
vector2<T> initVec2(size_t n0, size_t n1, T e = T()){
    return vector2<T>(n0, vector<T>(n1, e));
}

template <typename T>
using vector3 = vector<vector<vector<T>>>;
template <typename T>
vector3<T> initVec3(size_t n0, size_t n1, size_t n2, T e = T()){
    return vector3<T>(n0, vector2<T>(n1, vector<T>(n2, e)));
}

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

    int n;
    cin >> n;
    vector<P> p(n);
    rep(i, n){
        int x;
        cin >> x;
        p[i] = {x, i + 1};
    }
    sort(ALL(p), greater<P>());

    set<int> s;
    s.insert(-1);
    s.insert(0);
    s.insert(n+1);
    s.insert(n+2);
    s.insert(p[0].second);

    int ans = 0;
    for(int i = 1; i < n; i++){
        int pos = p[i].second;
        auto it = s.lower_bound(pos);
        int r = *it;
        it++;
        int rr = *it;
        it--;
        it--;
        int l = *it;
        it--;
        int ll = *it;
        int cnt = 0;

        if(r < n + 1){
            cnt += (pos - l) * (rr - r);
        }
        if(l > 0){
            cnt += (r - pos) * (l - ll);
        }
        ans += p[i].first * cnt;
        s.insert(pos);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 6528
n = int(input())
a = [int(val) for val in input().split()]
mp = dict()
ans = 0
for i in range(n):
    addval = a[i] + (i + 1)
    subval = (i + 1) - a[i]
    if subval in mp.keys():
        ans += mp[subval]
    mp[addval] = mp.get(addval, 0) + 1

print(ans)


Measured memory_bytes: 40428
from collections import defaultdict, deque


def pair(a, b):
    return (a, b) if a < b else (b, a)


N = int(input())
E = []
V = defaultdict(list)
C = {}
for i in range(N - 1):
    a, b = map(lambda s: int(s) - 1, input().split())
    E.append((a, b))
    V[a].append(b)
    V[b].append(a)
    C[(a, b)] = 0

K = 1
Q = deque([1])
visited = [False] * N
while Q:
    v = Q.popleft()
    visited[v] = True
    used = []
    to_paint = []
    for nb in V[v]:
        if visited[nb]:
            used.append(C[pair(v, nb)])
        else:
            Q.append(nb)
            to_paint.append(nb)
    i = 0
    for tp in to_paint:
        i += 1
        while i in used:
            i += 1
        C[pair(v, tp)] = i
    K = max(i, K)

print(K)
for e in E:
    print(C[e])


Measured memory_bytes: 48636
def divisor_list(x):
    return tuple([i for i in range(1, x+1) if x % i == 0])

N = int(input())
t = [int(input()) for _ in range(N)]
div = divisor_list(max(t))
di = 0
for i in range(N):
    j = 0
    while div[j] < t[i]:
        j += 1
    else:
        di += div[j] - t[i]
print(di)


Measured memory_bytes: 9572
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

N = inp()
#dp[n][i][j][k] 全体でn文字あってn-1,n-2,n-3文字目がk,j,iであるパターン数
#0:A 1:C 2:G 3:T
dp = [[[[0 for i in range(4)] for j in range(4)] for k in range(4)] for l in range(N+5)]
for i in range(4):
    for j in range(4):
        for k in range(4):
            if (i,j,k) == (0,2,1) or (i,j,k) == (0,1,2) or (i,j,k) == (2,0,1):
                continue
            dp[3][i][j][k] = 1
# pprint.pprint(dp)
if N == 3:
    print(61)
    quit()
for n in range(4,N+1):
    for i in range(4):
        for j in range(4):
            for k in range(4):
                for l in range(4):
                    if (j,k,l) == (0,2,1) or (i,k,l) == (0,2,1) or (i,j,l) == (0,2,1) or (j,k,l) == (2,0,1) or (j,k,l) == (0,1,2):
                        continue
                    dp[n][j][k][l] += dp[n-1][i][j][k]
                    dp[n][j][k][l] %= mod
res = 0
for i in range(4):
    for j in range(4):
        for k in range(4):
            res += dp[N][i][j][k]
            res %= mod
print(res)
# pprint.pprint(dp)


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

int main() {
	int x,y,z,n,a;
  	cin>>n;
  	x=y=z=a=0;
  	for (int i = 0; i < n; i++) {
      string s;
      cin >> s;
      int m = s.length();
      if (s[0]=='B' && s[m-1]=='A')
        z++;
      else if (s[0]=='B')
        x++;
      else if (s[m-1]=='A')
        y++;
      for (int j = 1; j < m; j++)
        if (s[j-1]=='A'&&s[j]=='B')
          a++;
    }
  	if (z) {
    	a += z-1;
      	if (x) x--,a++;
      	if (y) y--,a++;
    }
  	cout << a + min(x,y) << endl;
}

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

int main() {
  int n;
  long long k;
  cin >> n >> k;
  vector<pair<int, int>> ab(n);
  int i;
  for (i = 0; i < n; i++) {
    cin >> ab[i].first >> ab[i].second;
  }
  sort(ab.begin(), ab.end());
  for (i = 0; i < ab.size(); i++) {
    k -= ab[i].second;
    if (k <= 0) {
      cout << ab[i].first << endl;
      break;
    }
  }
  return 0;
}


Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            var ss = Console.ReadLine().Split();
            var x1 = int.Parse(ss[0]);
            var y1 = int.Parse(ss[1]);
            var x2 = int.Parse(ss[2]);
            var y2 = int.Parse(ss[3]);

            var vecX = x2 - x1;
            var vecY = y2 - y1;

            var x3 = x2 - vecY;
            var y3 = y2 + vecX;
            var x4 = x3 - vecX;
            var y4 = y3 - vecY;

            Console.WriteLine(x3 + " " + y3 + " " + x4 + " " + y4);
        }
    }
}

Measured memory_bytes: 11092
package main

import (
	"fmt"
	"sort"
)

func main() {
	var a, b, c int
	var k uint
	fmt.Scan(&a, &b, &c, &k)
	nums := []int{a, b, c}
	sort.Ints(nums)
	fmt.Println(nums[2] * (1 << k) + nums[0] + nums[1])
}

Measured memory_bytes: 512
/*
贪心，二分答案即可。
*/
#include<cmath>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<numeric>
#include<deque>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
const int INF=1e9+7;
const int MOD=998244353;
const int N = 1e6 + 5;
const ll inv2=499122177;
const double pi=acos(-1);
ll a[1000005],f[1000005];
ll n,k,ans;
bool cmp(ll a,ll b)
{
	return a>b;
}
int solve(ll o)
{
	ll sum=0;
	for(ll i=0;i<n;i++)
	{
		ll p=o/f[i];
		if(p<a[i])
			sum+=a[i]-p;
	}
	if(sum<k)
		return -1;
	else if(sum>k)
		return 1;
	else
		return 0;
}
int main()
{
	ll sum=0;
	scanf("%lld%lld",&n,&k);
	for(ll i=0;i<n;i++)
	{
		scanf("%lld",&a[i]);
		sum+=a[i];
	}
	sort(a,a+n);
	for(ll i=0;i<n;i++)
	{
		scanf("%lld",&f[i]);
	}
	sort(f,f+n,cmp);
	ll L=0,R=1e12,mid;
	while(L<=R)
	{
		mid=(L+R)/2;
		if(solve(mid)==-1)
		{
			R=mid-1;
		}
		else if(solve(mid)==1)
		{
			L=mid+1;
		}
		else
		{
			break;
		}
	}
	while(solve(mid)==0||mid==-1)
		mid--;
	while(solve(mid)==1)
		mid++;
	if(k>=sum)
		mid=0;
	printf("%lld\n",mid);
    return 0;
}



Measured memory_bytes: 5888
#include<cstdio>
#include<algorithm>
int K,N,A[200010];
int main(){
	scanf("%d%d",&N,&K);
	for(int i=0;i<N;i++){
		int x;scanf("%d",&x);
		A[x]++;
	}
	std::sort(A+1,A+N+1);
	int ans=0;
	for(int i=1;i<=N-K;i++)ans+=A[i];
	printf("%d\n",ans);
}

Measured memory_bytes: 896
#define _GLIBCXX_DEBUG
#include"bits/stdc++.h"

using namespace std;

//loops
#define REP(i,n) for(int i=0;i<(ll)(n);i++)
#define REPD(i,n) for(int i=(ll)(n)-1;i>=0;i--)
#define OneToN(i,n) for(int i=1;i<(ll)(n+1);i++)
#define ZeroToN(i,n) for(int i=0;i<(ll)(n+1);i++)
#define AToB(i,a,b) for(int i=a;i<(ll)(b+1);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)

//bitsearch
#define BITSEARCH(bit, n) for (int bit = 0; bit < (1<<n); ++bit)
#define isOne(bit, i) bit & (1<<i)

//arrays
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define add push_back


#define remove_unique(v) v.erase(unique(ALL(v)), v.end())

//pair
#define fir first
#define sec second

//types
#define ll long long
#define vec vector
#define cord2d pair<int,int>
//UNCOMMENT WHEN NEEDED
//#define int ll

//input
template <class T> T get(){ T s; cin >> s; return(s);}
#define gi get<int>()
#define gs get<string>()

template <class T> vector<T> getv(int n) { vec<T> v(n); REP(i, n) cin >> v[i]; return v; }
#define gim(n) getv<int>(n)
#define gsm(n) getv<string>(n)

//output
void print(int a){ cout << a << endl; }
void print(string a){ cout << a << endl; }
void print(char a){ cout << a << endl; }
void print(double a){ cout << a << endl; }
void print(double a, int dig){ cout << std::setprecision(dig) << a << endl; }

template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

template <class T = int>
void print(vec<T> v){ cout << v << endl; }

template <class T = int>
void print2dVec(vec<vec<T>> v2d){for(vec<T> v: v2d) {print(v);}}

void YesNo1(bool i = true){ return print(i?"Yes":"No"); }
void YESNO2(bool i = true){ return print(i?"YES":"NO"); }

//debug output
#define var_name(var) #var
template <class T> void debug(T &var, int nest = 0, string before = "") { cout << string("          ", nest) << before; print(var); }

//name replacement
#define y0 y0__
#define y1 y1__
#define j0 j0__
#define j1 j1__
#define next next__
#define prev prev__

//bool lambdas
#define lamb(exp) [](auto i){return exp;}
#define isEven [](int i){return i % 2 == 0;}
#define isOdd [](int i){return i % 2 != 0;}

//constants
const ll INF = 1e18;
const int MOD = 10000007;

//maths
int factorial(int k){ int sum = 1; for (int i = 1; i <= k; ++i) { sum *= i; } return sum; }

void Main() {
    //code here
    int n = gi;
    vec<cord2d> towns;
    REP(i,n) {
        int x = gi, y = gi;
        towns.add(make_pair(x,y));
    }
    sort(ALL(towns));
    double distSum = 0;
    do {
        double dist = 0;
        REP(i, n-1) {
            distSum += sqrt(pow(towns[i].first - towns[i+1].first, 2) + pow(towns[i].second - towns[i+1].second, 2));
        }
        //print(dist);
        //distSum += dist;
    } while (next_permutation(ALL(towns)));
    print(distSum/(double)factorial(n), 10);
}

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    Main();
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <cstdio>
#include <cmath>
using namespace std;
int main() {
	int n;
	long long power = 1;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		power = power*i % 1000000007;
	}
	cout << power << endl;
	return 0;
}

Measured memory_bytes: 256
def nasu(n):
  L = [0] * N
  for i in range(N):
    if n >> i & 1:
      L[i] = 1
  ans = 0
  t = a[0]
  for i in range(1, N):
    if L[i] == 1:
      if t >= a[i]:
        ans += t - a[i] + 1
        t = t + 1
      else:
        t = a[i]
    else:
      t = max(t, a[i])
  return ans

N, K = list(map(int, input().split()))
a = list(map(int, input().split()))

ans = 15 * 10 ** 9 

n = (1 << K) - 1
while n < (1 << N):
  ans = min(ans, nasu(n))

  x = n & -n
  y = n + x
  n = ((n & ~y) // x >> 1) | y

print(ans)

Measured memory_bytes: 74512
#include <stdio.h>
#include <vector>
#include <set>
#include <utility>
using namespace std;
typedef long long ll;

int main(void) {
  ll i, j, k, n, m, u, v, a;
  scanf("%lld%lld", &n, &m);
  vector<ll> vec[n];
  ll d[n][3];
  for(i = 0; i < m; ++i) {
    scanf("%lld%lld", &u, &v);
    vec[--u].push_back(--v);
  }
  set< pair<ll, pair<ll, ll> > > s;
  pair<ll, ll> now;
  scanf("%lld%lld", &u, &v), --u, --v;
  for(i = 0; i < n; ++i) for(j = 0; j < 3; ++j) d[i][j] = 1e9;
  d[u][0] = 0;
  for(i = 0; i < n; ++i) for(j = 0; j < 3; ++j) 
    s.insert(make_pair(d[i][j], make_pair(i, j)));
  while(s.size()) {
    a = (*s.begin()).first, now = (*s.begin()).second, s.erase(s.begin());
    now.second++;
    now.second %= 3;
    if(!now.second) a++;
    for(i = 0; i < vec[now.first].size(); ++i) {
      j = vec[now.first][i];
      if(d[j][now.second] > a) {
        s.erase(make_pair(d[j][now.second], make_pair(j, now.second)));
        d[j][now.second] = a;
        s.insert(make_pair(a, make_pair(j, now.second)));
      }
    }
  }
  printf("%lld", d[v][0] == 1e9 ? -1 : d[v][0]);
  return 0;
}

Measured memory_bytes: 26880
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main(){
  int N, M;
  cin >> N >> M;
  int L, R;
  int Lmax = 0;
  int Rmin = INF;
  rep(i, M){
    cin >> L >> R;
    Lmax = max(Lmax, L);
    Rmin = min(Rmin, R);
  }
  int res = max(Rmin - Lmax + 1, 0);
  cout << res << endl;
}


Measured memory_bytes: 3644
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;

int main(void){
    int a, b, C;
    double S, L, h;

    cin >> a >> b >> C;
    double c = C * M_PI / 180;
    S = (double) a * b * sin(c) / 2;
    L = (double) a + b + sqrt(pow(a, 2) + pow(b, 2) - 2 * a * b * cos(c));
    h = (double) b * sin(c);

    cout << fixed << setprecision(4) << S << endl << L << endl << h << endl;
}



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

typedef long long ll;
ll n;
ll pw[51];
int b[51],c[51],top,len;
int m,num,mx=50;

void init()
{
	pw[0]=1;
	for(int i=1;i<=50;i++) pw[i]=pw[i-1]<<1;
}

int main()
{
	scanf("%lld",&n);
	init(); 
	while(pw[mx]>n) mx--;
	n-=pw[mx];
	m=mx;
	c[++top]=mx+1,c[++top]=mx+1;
	len=2*m+2;
	num=m+1;
	while(n)
	{
		while(pw[mx]>n) mx--;
		n-=pw[mx];
		c[++top]=++num;
		b[mx]=num;
		len+=2;
	}
	printf("%d\n",len);
	for(int i=0;i<=m;i++)
	{
		if(i) printf("%d ",i);
		if(b[i]) printf("%d ",b[i]);
	}
	for(int i=1;i<=m;i++) printf("%d ",i);
	for(int i=1;i<=top;i++) printf("%d ",c[i]); 
	
	return 0;
}

Measured memory_bytes: 256
n = int(input())
a = [int(x) for x in input().split()]
res = 0
c = 0
for i in range(n-1):
  #print(c,res)
  if a[i] >= a[i+1]:
    c += 1
  else:
    res = max(res,c)
    c = 0
res = max(res,c)
print(res)

Measured memory_bytes: 20132
/**********************************************************************
   File hoge.cpp
   Author  harunaya
   Date   2020-04-29(Wed)
   note   
**********************************************************************/

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

int main() {
  string S; 
  cin >> S;
  sort(S.begin(), S.end());
  //cout << S << endl;

  if (S.at(0) == S.at(1) && S.at(1) != S.at(2) && S.at(2) == S.at(3)){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ld;
#define vec(s) vector

#define vvec(s) vector<vector
>
typedef vector<lli> vi;
typedef vector<vi> vvi;
typedef pair<lli,lli> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Yes(x) cout<<(x?"Yes":"No")<<endl;
#define YES(x) cout<<(x?"YES":"NO")<<endl;
#define out(s) cout<<s<<endl;
#define pb(s) push_back(s);
#define sp " " 
#define INF 10000000000
#define LINF 9000000000000000000
#define all(s) s.begin(),s.end()
void vout(vi v){
    for(lli i=0;i<v.size();i++)
    cout<<v.at(i)<<endl;
}
int main(){
    cout << std::fixed << std::setprecision(10);
    lli r, d, x;
    cin>>r>>d>>x;
    rep(i,10){
        x=r*x-d;
        out(x);
    }
}

Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <functional>
#include <vector>
using namespace std;
int main(){
	int A, B, K;
	cin >> A >> B >> K;
	int M = min(A,B);
	for(int i = B;i>0;i--){
		if(A % i == 0 && B % i ==0){
			K--;
			if(K == 0){
				cout << i << endl;
			}
		}
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int r[10];
	for(int i=0;i<10;i++)
		cin>>r[i];
	sort(r,r+10);
	cout<<r[9]<<endl;
	cout<<r[8]<<endl;
	cout<<r[7]<<endl;
    return 0;
}

Measured memory_bytes: 1176
use std::io;
use std::cmp;

fn main() {
   
   loop {
        let mut e = String::new();

        io::stdin().read_line(&mut e)
            .expect("Failed to read");

        let e: i32 = e.trim().parse().unwrap();

        if e == 0 {break;}

        println!("{}", solve(e));
    }
}

fn solve(e: i32) -> i32 {
   let mut m: i32 = 1000000000;

   for z in 0.. {
       let z3: i32 = z * z * z;

       if z3 > e {break;}
       
       for y in 0.. {
           let y2: i32 = y * y;
           let x = e - z3 - y2;
           
           if x < 0 {break;}

           m = cmp::min(m, x + y + z);
       }
   }

   m
}



Measured memory_bytes: 5032
# = map(int, input().split())
# = list(map(int, input().split()))
n, x, y = map(int, input().split())
x -= 1
y -= 1
ans = [0] * n
for i in range(n):
    for j in range(i+1, n):
        dist = min([j-i, abs(x-i)+abs(y-j)+1, abs(y-i)+abs(x-j)+1]) 
        ans[dist] += 1
for k in range(1, n):
    print(ans[k])


Measured memory_bytes: 47324
#include <bits/stdc++.h>
using namespace std;
#define SELECTER(_1, _2, _3, SELECT, ...) SELECT
#define REP1(i, n) for(int (i)=0; (i)<(n); (i)++)
#define REP2(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
#define REP(...) SELECTER(__VA_ARGS__, REP2, REP1,) (__VA_ARGS__)
#define MOD 1'000'000'007

template <class T> ostream& operator<<(ostream& os, const vector<T>& v){ os << "{"; for(size_t i=0; i<v.size(); i++) os << v[i] << (i+1==v.size() ? "" : ", "); os << "}"; return os; }
template <class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p){ return os << "{" << p.first << ", " << p.second << "}"; }

int main(){
    string S;
    long long K;
    cin >> S >> K;

    string T = "";
    if(K <= 3){
        long long cnt = 0;
        REP(i, K) T += S;
        REP(i, 1, T.size())
            if(T[i] == T[i-1]){
                cnt++;
                T[i] = '-';
            }
        cout << cnt << endl;
        return 0;
    }
    long long cnt = 0;
    long long a[3];
    T += S + S + S;
    REP(i, 1, T.size()){
        if(i % S.size() == 0){
            a[i/S.size()-1] = cnt;
            cnt = 0;
        }
        if(T[i] == T[i-1]){
            cnt++;
            T[i] = '-';
        }
    }
    a[2] = cnt;
    if(a[1] != a[2]){
        long long y = K / 2;
        long long x = K - y;
        long long ans = x * a[0] + y * a[1];
        cout << ans << endl;
    }else{
        long long ans = a[0] + (K-1) * a[1];
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import sys
N, Y = map(int, input().split())

for x in range(N+1)[::-1]:
  for y in range(N+1)[::-1]:
    if x+y <= N:
      z = N-(x+y)
      if 10000*x + 5000*y + 1000*z == Y:
        print(x,y,z)
        sys.exit()

print(-1,-1,-1)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  int s=N;
  int sum = 0;
  while(s>0){
    sum += s%10;
    s /= 10;
  }
 
  if(N%sum==0){
    cout<<"Yes"<<endl;
  }
  else cout<<"No"<<endl;
}


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

int main(){
    int N, K; cin >> N >> K;
    vector<int> A(N);
    for(int i = 0; i < N; i++) cin >> A[i];
    cout <<  (N - 1 + K - 1 - 1) / (K - 1)  << endl;
}

Measured memory_bytes: 640