akhauriyash/Code-Regression huggingface dataset:
def solve():
    import bisect

    N = int(input())
    S = list(map(int, input().split()))
    Q = int(input())
    T = list(map(int, input().split()))

    S = set(S)
    T = set(T)
    C = 0
    for s in S:
        if s in T:
            C += 1
    print(C)





if __name__ == "__main__":
    solve()



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

using namespace std;

template< typename T >
struct edge {
  int src, to;
  T cost;

  edge(int to, T cost) : src(-1), to(to), cost(cost) {}

  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

  edge &operator=(const int &x) {
    to = x;
    return *this;
  }

  operator int() const { return to; }
};

template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WeightedGraph = vector< Edges< T > >;
using UnWeightedGraph = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;

template< typename T >
vector< T > shortest_path_faster_algorithm(WeightedGraph< T > &g, int s) {
  const auto INF = numeric_limits< T >::max();
  vector< T > dist(g.size(), INF);
  vector< int > pending(g.size(), 0), times(g.size(), 0);
  queue< int > que;

  que.emplace(s);
  pending[s] = true;
  ++times[s];
  dist[s] = 0;

  while(!que.empty()) {
    int p = que.front();
    que.pop();
    pending[p] = false;
    for(auto &e : g[p]) {
      T next_cost = dist[p] + e.cost;
      if(next_cost >= dist[e.to]) continue;
      dist[e.to] = next_cost;
      if(!pending[e.to]) {
        if(++times[e.to] >= g.size()) return vector< T >();
        pending[e.to] = true;
        que.emplace(e.to);
      }
    }
  }
  return dist;
}


int main() {
  int N, C;
  int A[200], O[200], B[200], S[200], D[200];

  cin >> N >> C;
  vector< int > undefined;
  for(int i = 0; i < C; i++) {
    string str;
    cin >> str;
    int tail = 0, a = 0, b = 0, o, s, d = 0;
    while(isdigit(str[tail])) a = a * 10 + str[tail++] - '0';
    if(str[tail] == '*') o = 2;
    else if(str[tail] == '<') o = 0, ++tail;
    else o = 1, ++tail;
    ++tail;
    while(isdigit(str[tail])) b = b * 10 + str[tail++] - '0';
    if(str[tail] == '+') s = 0;
    else s = 1;
    ++tail;
    while(tail < str.size()) d = d * 10 + str[tail++] - '0';
    A[i] = --a, B[i] = --b, O[i] = o, S[i] = s, D[i] = d;
    if(o == 2) undefined.push_back(i);
  }
  int ret = -1;
  for(int i = 0; i < (1 << undefined.size()); i++) {
    for(int j = 0; j < undefined.size(); j++) O[undefined[j]] = (i >> j) & 1;

    WeightedGraph< int > g(N);
    for(int k = 0; k < C; k++) {
      if(O[k] == 1) swap(A[k], B[k]);
      g[B[k]].emplace_back(A[k], 0);
      if(S[k] == 0) g[B[k]].emplace_back(A[k], -D[k]);
      else g[A[k]].emplace_back(B[k], D[k]);
      if(O[k] == 1) swap(A[k], B[k]);
    }
    auto dists = shortest_path_faster_algorithm(g, 0);
    if(dists.empty() || *min_element(begin(dists), end(dists)) < 0) continue;
    ret = max(ret, *max_element(begin(dists), end(dists)));
  }

  if(ret >= numeric_limits< int >::max()) cout << "inf" << endl;
  else cout << ret << endl;
}


Measured memory_bytes: 3232
n, a, b, c, d = map(int, input().split())
s = input()

def solveSimple(s, a, b, c, d):     
    if '##' in s[b-1:d]:
        return False 
    if '##' in s[a-1:c]:
        return False
    return True

# simple 
if c < d:
    ans = solveSimple(s, a, b, c, d)
    
# solveDifficult
else:
    ans = solveSimple(s, a, b, c, d) and '...' in s[b-2:d+1]

if ans:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3572
#include <iostream>
#include <string>
#include <stdio.h>
#include <cmath>
#include <cfloat>
#include <algorithm>
#include <numeric>
#include <vector>
#include <iterator>
#include <set>
#include <map>
using namespace std;

const double PI=acos(-1);

int main(){
    long c[3][3], sum = 0, b21[3] = {0}, b32[3] = {0};
    for(int i = 0; i < 3; i++){
        for(int j = 0; j < 3; j++){
            cin >> c[i][j];
            sum += c[i][j];
        }
    }
    for(int i = 0; i < 3; i++){
        b21[i] = c[i][1] - c[i][0];
        b32[i] = c[i][2] - c[i][1];
    }
    if(sum%3 == 0) {
        if(b21[0] == b21[1] && b21[0] == b21[2] && b32[0] == b32[1] && b32[0] == b32[2])
            cout << "Yes" << endl;
        else
            cout << "No" << endl;
    }else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

   
    public static void main(String[] args) {
       Scanner scanner = new Scanner(System.in);
       int x = scanner.nextInt();
       if(x == 0){
           System.out.println("1");
       } else if( x==1){
           System.out.println("0");
       }
        
    }
    
}


Measured memory_bytes: 35660
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<n;i++)
#define why(n,x) int n;while(cin >>n,n!=x)
#define iFOR(i,x,n)for(int i=x;i<n;i++)
#define unless(flg) if ( !(flg) )
#define read cin<<
#define echo cout<<
#define fin <<'\n'
#define __ <<" "<<
#define ___ <<" "
#define bash push_back
#define ALL(x) x.begin(),x.end()
#define SWAP(a,b) ((a != b) && (a += b,b = a - b,a -= b))
#define cinf(n,x) for(int UNCH=0;UNCH<(n);UNCH++) cin >> x[UNCH];
#define fcin(n,x) for(int UNCH=1;UNCH<=(n);UNCH++) cin>> x[UNCH];
#define memmin(x) memset((x),-1,sizeof((x)))
#define memzer(x) memset((x), 0,sizeof((x)))
#define meminf(x) memset((x),0x3f,sizeof((x)))
#define int long long
typedef long long ll;
typedef pair < int , int >  pii;
typedef vector < int > vit;
typedef map < string , int > mstit;
typedef vector < pii > vpi ;
typedef greater < pii > gpi;
typedef priority_queue < pii , vpi , gpi > dijk ;
static const signed int INF = 0x3f3f3f3f;
static const signed long long LINF = 0x3f3f3f3f3f3f3f3fLL;
static const signed int SMOD = 1000000007;
static const signed int NMOD = 1000000009;
static const signed int dx[]={1,0,-1,0,1,1,-1,-1};
static const signed int dy[]={0,-1,0,1,-1,1,-1,1};

bool inside(int x,int y,int w,int h){return (x>=0 && y>=0 && x<w && y<h);}
template<class T>T abs(T &x){return x<0 ? -x : x;}
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 qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}



signed main(){
    int n,a[100005];
    cin >> n;
    FOR(i,n){
        cin >> a[i];
    }
    sort(a,a+n,greater<int>());
    int ans = a[0];
    FOR(i,n){
        ans = gcd(ans,a[i]);
    }
    cout << ans fin;
  
  return 0;
}



struct xyz{ xyz(){ cin.tie(0), ios::sync_with_stdio(false); cout <<fixed<<setprecision(12);};}xyzzy;




Measured memory_bytes: 1024
'use strict'

function main(input) {

    const datas = input.split(/\n|\s/).map(v => ~~v)
    const n = datas[0]
    const days = datas[1]
    const remain = datas[2]
    const eat = datas.slice(3)
    let cnt = 0;
    let tmp = 0;
    for (let i = 0; i < n; i++) {

        tmp = Math.floor((days - 1) / eat[i])
        cnt += tmp

    }

    const ans = remain + n + cnt

    console.log(ans)
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7500
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func scanInt(sc *bufio.Scanner) int {
	if !sc.Scan() {
		panic(nil)
	}

	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}

	return i
}

func check() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	mod := make([]int, 0, 5)

	var ret int

	for i := 0; i < 5; i++ {
		v := scanInt(sc)
		ret += v / 10
		if tmp := v % 10; tmp != 0 {
			mod = append(mod, tmp)
		}
	}

	min := 10
	for i := 0; i < len(mod); i++ {
		if mod[i] < min {
			min = mod[i]
		}
	}
	fmt.Printf("%d\n", ret*10+(len(mod)-1)*10+min)

}

func main() {
	check()
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;;
#define ll long long
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define INF 1<<30
#define LINF 1LL<<62
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
    ll h,w,a,b; cin >> h >> w >> a >> b;
    COMinit();
    ll ans = 0;
    REP(i,h-a){
        ans += COM(i+b-1,i) * COM(h-i+w-b-2, w-b-1) % MOD;
        ans = ans%MOD;
    }
    cout << ans << endl; 

}

Measured memory_bytes: 12160
import java.util.*;
public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
 
   double N = sc.nextDouble();

   double sq = Math.sqrt(N);
   sq = Math.floor(sq);
   
   int anssq = (int) sq;
   
   System.out.println(anssq*anssq);
 }
}

Measured memory_bytes: 23124
#include<bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (int)n; i++)
#define all(x) x.begin(), x.end()
#define MOD 1000000007//1e9+7
typedef long long ll;
using namespace std;
int main()
{
  int a, b, k;
  cin >> a>> b>> k;
  if(a + k - 1 < b - k + 1){
    for(int i = 1; i <= k; i++){
      int tmp = a + i - 1;
      cout << tmp << endl;
    }
    for(int i = 1; i <= k; i++){
      int tmp = b - k + i;
      cout << tmp << endl;
    }
  }else{
    for(int i = a; i <= b ; i ++ ){
      cout << i << endl;
    }

  }
}

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

int main() {
  string S;
  int a=0;
  cin >> S;
  sort(S.begin(), S.end());
  rep (i, S.size()-1){
    if(S.at(i)==S.at(i+1)){
      a=1;
      break;
    }
  }
  if(a==1) cout << "no" << endl;
  else cout << "yes" << endl;
} 

Measured memory_bytes: 256
#include <iostream>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;

int main() {
  int N;
  cin >> N;
  
  for ( int i = 0; i < N; i++){
    string s;
    cin >> s;
    if (s == "Y"){
      cout << "Four" << endl; 
      break;  
    }
    else if (i == N-1)
    {
      cout << "Three" << endl;
    }
    
  }
  
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
class cell{
    int x;
    int y;
    int distance;
    cell(int x, int y, int distance){
        this.x = x; 
        this.y = y;
        this.distance = distance;
    }
    public int getDistance(){
        return this.distance;
    }
}
public class Main
{
    static int n;
    static int m;
    static int[][] visited;
    static int[][] dist;
    public static boolean isValid(int x, int y){
        return (x >= 0 && y >= 0 && x < n && y < m);
    } 
    
    
	public static void main(String[] args) throws Exception{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] in = br.readLine().trim().split(" ");
        n = Integer.parseInt(in[0]);
        m = Integer.parseInt(in[1]);
	    in = br.readLine().trim().split(" ");
        int s1 = Integer.parseInt(in[0]);
        int s2 = Integer.parseInt(in[1]);
        s1--;
        s2--;
	    in = br.readLine().trim().split(" ");
        
        int e1 = (Integer.parseInt(in[0]));
        int e2 = (Integer.parseInt(in[1]));
        e1--;
        e2--;
	    char[][] grid = new char[n][m];
	    dist = new int[n][m];
	    for(int i = 0; i < n; i++){
            grid[i] = br.readLine().trim().toCharArray();
            Arrays.fill(dist[i], Integer.MAX_VALUE);
        }
	    dist[s1][s2] = 0;
	    visited = new int[n][m];
	    Comparator<cell> cmp = Comparator.comparing(cell::getDistance);
	    PriorityQueue<cell> pq = new PriorityQueue<>(cmp);
	    cell c1 = new cell(s1, s2, 0);
	    int[] dx = {0, 1, 0, -1};
	    int[] dy = {-1, 0, 1, 0};
	    pq.add(c1);
	    while(!pq.isEmpty()){
	        cell c = pq.poll();
	        int x = c.x;
	        int y = c.y;
	        int d = c.distance;
	        visited[x][y] = 1;
	        for(int i = 0; i < 4; i++){
	            int newx = x+dx[i];
	            int newy = y+dy[i];
	            if(isValid(newx, newy) && grid[newx][newy] == '.' && visited[newx][newy] != 1){
	                int newd = dist[x][y];
	                if(newd < dist[newx][newy]){
	                    dist[newx][newy] = newd;
	                    pq.add(new cell(newx, newy, newd));
	                }
	            }
	        }
	        int irow = x-2;
	        int jcol = y-2;
	        for(int i = irow; i < irow+5; i++){
	            for(int j = jcol; j < jcol+5; j++){
	                if(isValid(i, j) && grid[i][j] == '.' && visited[i][j] != 1){
    	                int newd = dist[x][y] + 1;
    	                if(newd < dist[i][j]){
    	                    dist[i][j] = newd;
    	                    pq.add(new cell(i, j, newd));
    	                }
    	            }
	            }
	        }
	    }
	    if(dist[e1][e2] != Integer.MAX_VALUE){
	        System.out.println(dist[e1][e2]);
	    }
	    else{
	        System.out.println(-1);
	    }
	}
	
}

Measured memory_bytes: 70060
/* Dynamic Programming implementation of LCS problem */
#include<iostream>
#include<cstring>
#include<cstdlib>
using namespace std;

/* Returns length of LCS for X[0..m-1], Y[0..n-1] */
void lcs( char *X, char *Y, int m, int n )
{
   int L[m+1][n+1];

   /* Following steps build L[m+1][n+1] in bottom up fashion. Note
      that L[i][j] contains length of LCS of X[0..i-1] and Y[0..j-1] */
   for (int i=0; i<=m; i++)
   {
     for (int j=0; j<=n; j++)
     {
       if (i == 0 || j == 0)
         L[i][j] = 0;
       else if (X[i-1] == Y[j-1])
         L[i][j] = L[i-1][j-1] + 1;
       else
         L[i][j] = max(L[i-1][j], L[i][j-1]);
     }
   }

   // Following code is used to print LCS
   int index = L[m][n];

   // Create a character array to store the lcs string
   char lcs[index+1];
   lcs[index] = '\0'; // Set the terminating character

   // Start from the right-most-bottom-most corner and
   // one by one store characters in lcs[]
   int i = m, j = n;
   while (i > 0 && j > 0)
   {
      // If current character in X[] and Y are same, then
      // current character is part of LCS
      if (X[i-1] == Y[j-1])
      {
          lcs[index-1] = X[i-1]; // Put current character in result
          i--; j--; index--;     // reduce values of i, j and index
      }

      // If not same, then find the larger of two and
      // go in the direction of larger value
      else if (L[i-1][j] > L[i][j-1])
         i--;
      else
         j--;
   }

   // Print the lcs
   cout << lcs<<endl;
}

/* Driver program to test above function */
int main()
{
  char X[3005];
  char Y[3005];
  scanf("%s %s",X,Y);
  int m = strlen(X);
  int n = strlen(Y);
  lcs(X, Y, m, n);
  return 0;
}


Measured memory_bytes: 35456
class FastPriorityQueue
  attr_reader :size

  def initialize
    @size = 0
    @nodes = []
  end

  def empty?
    @size.zero?
  end

  def push(node)
    index = size
    @size += 1

    while index > 0
      parent = (index - 1) / 2

      break if @nodes[parent].last <= node.last

      @nodes[index] = @nodes[parent]
      index = parent
    end

    @nodes[index] = node
  end

  alias_method :<<, :push

  def pop
    node = @nodes.first
    root = @nodes[size - 1]
    @size -= 1
    index = 0

    while index * 2 + 1 < @size
      left = 2 * index + 1
      right = left + 1

      if right < size && @nodes[right].last < @nodes[left].last
        left = right
      end

      break if @nodes[left].last >= root.last

      @nodes[index] = @nodes[left]
      index = left
    end

    @nodes[index] = root
    node
  end

  def top
    @nodes.first
  end
end

X, Y, Z, K = gets.split.map(&:to_i)
A = gets.split.map(&:to_i)
B = gets.split.map(&:to_i)
C = gets.split.map(&:to_i).sort.reverse

AB = A.product(B).map { |a, b| a + b }.sort.reverse
pque = FastPriorityQueue.new

C.each_with_index do |c, i|
  v = AB[0] + c
  pque.push([[0, i], -v])
end

K.times do
  (i, j), v = pque.pop
  puts -v

  if i + 1 < AB.size
    nv = AB[i + 1] + C[j]
    pque.push([[i + 1, j], -nv])
  end
end



Measured memory_bytes: 80836
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <algorithm>

using namespace std;

vector<int> votes;

bool comp(int i, int j) {
  return votes[i] > votes[j];
}

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

  map<string, int> m;
  set<string> unique;

  for (int i = 0; i < N; ++i) {
    string s;
    cin >> s;
    if (m.find(s) == m.end())
      m[s] = 0;
    ++m[s];
    unique.insert(s);
  }

  vector<string> s;
  vector<int> indices;
  int count = 0;
  for (set<string>::iterator i = unique.begin(); i != unique.end(); ++i) {
    s.push_back(*i);
    votes.push_back(m[*i]);
    indices.push_back(count++);
  }

  sort(indices.begin(), indices.end(), comp);

  vector<string> tops;

  for (int i = 0; i < indices.size(); ++i) {
    if (i == 0)
      tops.push_back(s[indices[i]]);
    else if (votes[indices[i]] == votes[indices[i - 1]])
      tops.push_back(s[indices[i]]);
    else
      break;
  }

  sort(tops.begin(), tops.end());

  for (int i = 0; i < tops.size(); ++i)
    cout << tops[i] << endl;

  return 0;
}

Measured memory_bytes: 41588
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
using namespace std;
typedef long long int lli;
#define urept(soeji, start, n) for (int soeji = start; soeji < n; soeji++)
#define drept(soeji, start, n) for (int soeji = start; soeji > n; soeji--)
struct CT
{
    int cost;
    int time;
    /* data */
};

int main(void)
{
    int N, T;
    cin >> N >> T;
    CT *x;
    x = new CT[N];
    for (int i = 0; i < N; i++)
    {
        cin >> x[i].cost >> x[i].time;
    }
    sort(x, x + N, [](const CT &x, const CT &y) { return x.cost < y.cost; });
    for (int i = 0; i < N; i++)
    {
        if (x[i].time <= T)
        {
            cout << x[i].cost << endl;
          	return 0;
        }
    }
  	cout << "TLE" <<endl;
    return 0;
}

Measured memory_bytes: 256
int main(){
int S,h,m,s;
    scanf("%d",&S);
    h = S /3600;
    m = (S - h * 3600) / 60;
    s = S - h * 3600 - m * 60;
    printf("%d:%d:%d\n",h,m,s);
    return 0;
}


Measured memory_bytes: 2128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int h[200010], n, k, x, e;
long long w = 0;
int main() {
	scanf("%d%d", &n, &k);
    for (register int i=1; i<=n; ++i) {
        scanf("%d", &h[i]);
    }
    std :: sort(h+1, h+n+1);
    for (register int i=1; i<=n-k; ++i)
        w += 1ll*h[i];
	cout << w;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    map<string, char> code;
    code["101"] =      ' ';
    code["000000"] =   '\'';
    code["000011"] =   ',';
    code["10010001"] = '-';
    code["010001"] =   '.';
    code["000001"] =   '?';
    code["100101"] =   'A';
    code["10011010"] = 'B';
    code["0101"] =     'C';
    code["0001"] =     'D';
    code["110"] =      'E';
    code["01001"] =    'F';
    code["10011011"] = 'G';
    code["010000"] =   'H';
    code["0111"] =     'I';
    code["10011000"] = 'J';
    code["0110"] =     'K';
    code["00100"] =    'L';
    code["10011001"] = 'M';
    code["10011110"] = 'N';
    code["00101"] =    'O';
    code["111"] =      'P';
    code["10011111"] = 'Q';
    code["1000"] =     'R';
    code["00110"] =    'S';
    code["00111"] =    'T';
    code["10011100"] = 'U';
    code["10011101"] = 'V';
    code["000010"] =   'W';
    code["10010010"] = 'X';
    code["10010011"] = 'Y';
    code["10010000"] = 'Z';

    for(;;){
        string s;
        if(!getline(cin, s))
            return 0;

        int n = s.size();
        string s1;
        for(int i=0; i<n; ++i){
            if('A' <= s[i] && s[i] <= 'Z')
                s1 += bitset<5>(s[i]-'A').to_string();
            else if(s[i] == ' ')
                s1 += "11010";
            else if(s[i] == '.')
                s1 += "11011";
            else if(s[i] == ',')
                s1 += "11100";
            else if(s[i] == '-')
                s1 += "11101";
            else if(s[i] == '\'')
                s1 += "11110";
            else
                s1 += "11111";
        }

        n = s1.size();
        int i = 0;
        int j = 0;
        while(j < n){
            map<string, char>::iterator it;
            it = code.find(s1.substr(i, j-i+1));
            if(it == code.end())
                ++ j;
            else{
                cout << it->second;
                i = ++ j;
            }
        }
        cout << endl;
    }
}

Measured memory_bytes: 0
#include <stdio.h>

int main()
{
    int w,h,x,y,r;

    scanf("%d %d %d %d %d",&w,&h,&x,&y,&r);

    if(x-r<0||x+r>w||y-r<0||y+r>h) puts("No");
    else puts("Yes");

    return 0;
}

Measured memory_bytes: 580
#include<iostream>
#include<deque>

int main(){
    int K;
    std::cin >> K;
    
    if(K < 10){
        std::cout << K << std::endl;
        return 0;
    }
    
    std::deque< long long > pre;
    for(int i=1; i<10; i++){
        pre.push_back(i);
    }
    long long current;
    int plus = -1;
    for(int i=10; i<=K; i++){
        int mod = pre[0] % 10;
        if(mod == 0 && plus == -1){
            plus = 0;
        }
        long long tmp = pre[0] * 10 + mod + plus;
        pre.push_back(tmp);
        plus++;
        if(mod == 9 && plus == 1 ||mod != 9 && plus == 2){
            pre.pop_front();
            plus = -1;
        }
    }
    
    std::cout <<  pre[pre.size()-1] << std::endl;
    
    return 0;
    
}



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

int main(){
    string a,b,c;
    cin >> a >> b >> c;
    if(a[a.length() - 1] == b[0] && b[b.length() - 1] == c[0]){
      cout << "YES" << endl;
    }else{
      cout << "NO" << endl;
     }
}

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

using namespace std;


void solve()
{
	int J, Y;
	cin >> J >> Y;
	string s;
	if (J >= 5 || Y >= 5)
	{
		if (J == 5 && Y == 5)
		{
			for (int i = 0; i < 4; ++i)
			{
				s += 'A';
			}
			for (int i = 0; i < 4; ++i)
			{
				s += 'B';
			}
			do
			{
				cout << s << "AB" << endl;
				cout << s << "BA" << endl;
			} while (next_permutation(s.begin(), s.end()));
		}
		else if (J >= 5 && Y < 5)
		{
			for (int i = 0; i < 4; ++i)
			{
				s += 'A';
			}
			for (int i = 0; i < Y; ++i)
			{
				s += 'B';
			}
			do
			{
				cout << s;
				for (int i = 0; i < J - 4; ++i)
				{
					cout << 'A';
				}
				cout << endl;
			} while (next_permutation(s.begin(), s.end()));
		}
		else if (J < 5 && Y >= 5)
		{
			for (int i = 0; i < J; ++i)
			{
				s += 'A';
			}
			for (int i = 0; i < 4; ++i)
			{
				s += 'B';
			}
			do
			{
				cout << s;
				for (int i = 0; i < Y - 4; ++i)
				{
					cout << 'B';
				}
				cout << endl;
			} while (next_permutation(s.begin(), s.end()));
		}
	}
	else
	{
		for (int i = 0; i < J; ++i)
		{
			s += 'A';
		}
		for (int i = 0; i < Y; ++i)
		{
			s += 'B';
		}
		do
		{
			cout << s << endl;
		} while (next_permutation(s.begin(), s.end()));
	}
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 1196
public class Main {
  private static void solve() {
    int a = ni();
    int b = ni();
    int c = ni();
    int x = ni();
    int y = ni();
    
    int ret = Integer.MAX_VALUE;
    for (int k = 0; k <= Math.max(x, y); k ++) {
      int lastA = Math.max(0, x - k);
      int lastB = Math.max(0, y - k);
      
      int now = k * 2 * c + lastA * a + lastB * b;
      ret = Math.min(now, ret);
    }
    System.out.println(ret);
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}




Measured memory_bytes: 21460
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
const int maxn=1e5+5;
template<typename T>
inline T read(T&x){
    x=0;int _f=0;char ch=getchar();
    while(ch<'0'||ch>'9')_f|=(ch=='-'),ch=getchar();
    while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
    return x=_f?-x:x;
}
struct Edge{
    int u,v,w;
    Edge(int _,int __,int ___):u(_),v(__),w(___){}

    int To(int x){return x==u?v:u;}
};
int n,q,k;
int parent[maxn][20];
ll dis[maxn],dep[maxn];
vector<Edge>edges;
vector<int>G[maxn];
void dfs(int u,int f){
    dep[u]=(f==-1?1:dep[f]+1);
    for (int i=0;i<(int)G[u].size();i++){
        Edge&e=edges[G[u][i]];
        int v=e.To(u);
        if (v==f) continue;
        dis[v]=dis[u]+1LL*e.w;
        parent[v][0]=u;
        dfs(v,u);
    }
}
void initLCA(){
    for (int k=0;k<19;k++){
        for (int v=1;v<=n;v++){
            if (parent[v][k]<0) continue;
            parent[v][k+1]=parent[parent[v][k]][k];
        }
    }
}
int lca(int u,int v){
    if (dep[u]>dep[v]) swap(u,v);
    for (int k=0;k<20;k++){
        if (((dep[v]-dep[u])>>k)&1) v=parent[v][k];
    }
    if (u==v) return u;
    for (int k=19;k>=0;k--){
        if (parent[u][k]!=parent[v][k]){
            u=parent[u][k];
            v=parent[v][k];
        }
    }
    return parent[u][0];
}
int main(){
    read(n);
    for (int i=1;i<=n-1;i++){
        int u,v,w;read(u),read(v),read(w);
        edges.push_back(Edge(u,v,w));
        int m=edges.size();
        G[u].push_back(m-1);
        G[v].push_back(m-1);
    }
    dis[1]=0;
    dfs(1,-1);
    initLCA();
    read(q),read(k);
    for (int i=1;i<=q;i++){
        int u,v;read(u),read(v);
        ll dis1=dis[u]+dis[k]-2*dis[lca(u,k)];
        ll dis2=dis[v]+dis[k]-2*dis[lca(v,k)];
        printf("%lld\n",dis1+dis2);
    }
    return 0;
}


Measured memory_bytes: 25652
n=int(input())
lst=list(map(int,input().split()))
ball=[0 for x in range(n)]
for i in range(n):
  idx=n-1-i
  if idx==n-1:
    ball[idx]=lst[idx]
  else:
    num=int(n/(idx+1)-1)
    sum_ball=0
    for j in range(2,num+2):
      sum_ball+=ball[(idx+1)*j-1]
    if sum_ball%2==lst[idx]:
      continue
    else:
      ball[idx]=1
      
indexes=[i+1 for i,x in enumerate(ball) if x==1]
if len(indexes):
  print(len(indexes))
  for i,x in enumerate(indexes):
    if i!=0:
      print(" ",end="")
      print(x,end="")
    else:
      print(x,end='')
  print()
else:
  print(0)

Measured memory_bytes: 12468
def main():
    import sys
    input = sys.stdin.readline

    N, A, B, C = map(int, input().split())
    s = [input().rstrip() for _ in range(N)]

    ans = []
    for i, op in enumerate(s):
        # print(op)
        if op == 'AB':
            if A == B == 0:
                print('No')
                return

            if A > B:
                A -= 1
                B += 1
                ans.append('B')
            else:
                if A == B and i < N - 1:
                    if s[i + 1] == 'AC' and A == 1:
                        A += 1
                        B -= 1
                        ans.append('A')
                        continue
                    elif s[i + 1] == 'BC' and B == 1:
                        A -= 1
                        B += 1
                        ans.append('B')
                        continue
                A += 1
                B -= 1
                ans.append('A')
        elif op == 'AC':
            if A == C == 0:
                print('No')
                return

            if A > C:
                A -= 1
                C += 1
                ans.append('C')
            else:
                if A == C and i < N - 1:
                    if s[i + 1] == 'AB' and A == 1:
                        A += 1
                        C -= 1
                        ans.append('A')
                        continue
                    elif s[i + 1] == 'BC' and C == 1:
                        A -= 1
                        C += 1
                        ans.append('C')
                        continue
                A += 1
                C -= 1
                ans.append('A')
        else:
            if B == C == 0:
                print('No')
                return

            if B > C:
                B -= 1
                C += 1
                ans.append('C')
            else:
                if B == C and i < N - 1:
                    if s[i + 1] == 'AB' and B == 1:
                        B += 1
                        C -= 1
                        ans.append('B')
                        continue
                    elif s[i + 1] == 'AC' and C == 1:
                        B -= 1
                        C += 1
                        ans.append('C')
                        continue
                B += 1
                C -= 1
                ans.append('B')
        # print(A, B, C)

    print('Yes')
    print(*ans, sep='\n')


if __name__ == '__main__':
    main()

# import sys
# input = sys.stdin.readline
# 
# sys.setrecursionlimit(10 ** 7)
# 
# (int(x)-1 for x in input().split())
# rstrip()
#
# def binary_search(*, ok, ng, func):
#     while abs(ok - ng) > 1:
#         mid = (ok + ng) // 2
#         if func(mid):
#             ok = mid
#         else:
#             ng = mid
#     return ok


Measured memory_bytes: 18416
#include "bits/stdc++.h"
using namespace std;

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9;                          const LL LINF = 1e18;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2017/11/11  Problem: ABC 085 B / Link: http://arc085.contest.atcoder.jp/tasks/arc085_b  ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */

LL N, Z, W;

LL ans = 0LL;
LL dp[2003][2];
// turn に bf ,teときたとき

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

	cin >> N >> Z >> W;
	VL a(N + 1, 0);
	FOR(i, 0, N) {
		cin >> a[i + 1];
	}
	a[0] = W;
	
	FORR(i, N, 0 - 1) {
		if (i == N) {
			dp[N][0] = LINF;
			dp[N][1] = -LINF;
		}
		else {
			dp[i][0] = abs(a[i] - a[N]);
			dp[i][1] = abs(a[i] - a[N]);
		}
		FOR(j, i + 1, N + 1) {
			dp[i][0] = max(dp[i][0], dp[j][1]);
			dp[i][1] = min(dp[i][1],dp[j][0]);
		}
	}
	ans = dp[0][0];
	cout << ans << "\n";

	return 0;
}


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

typedef vector<int> vi;

int n;
int b[10][10];
stack<vi> ans;
int sx[] = {-1,0,1,0}, sy[] = {1,1,1,2};
int mx[] = {1,2,0,1,2,0,1,2}, my[] = {0,0,1,1,1,2,2,2};
int lx[] = {-1,0,1,-2,-1,0,1,2,-1,0,1,0}, ly[] = {1,1,1,2,2,2,2,2,3,3,3,4};

bool rec(int d){
  if(d==n){
    rep(i,10)rep(j,10)if(b[i][j])return false;
    return true;
  }

  rep(i,10)rep(j,10){
    if(b[i][j]){
      b[i][j]--;
      bool flag = false;
      if(i<6 && j>1 && j<8){
	bool f = true;
	rep(k,12){
	  if(!b[i+ly[k]][j+lx[k]]){ f = false; break; }
	}
	
	if(f){
	  rep(k,12)b[i+ly[k]][j+lx[k]]--;
	  vi v(3); v[0] = j; v[1] = i+2; v[2] = 3;
	  ans.push(v);
	  if(rec(d+1))return true;
	  ans.pop();
	  rep(k,12)b[i+ly[k]][j+lx[k]]++;
	  flag = true;
	}
      }

      if(i<8 && j<8){
	bool f = true;
	rep(k,8){
	  if(!b[i+my[k]][j+mx[k]]){ f = false; break; }
	}
	
	if(f){
	  rep(k,8)b[i+my[k]][j+mx[k]]--;
	  vi v(3); v[0] = j+1; v[1] = i+1; v[2] = 2;
	  ans.push(v);
	  if(rec(d+1))return true;
	  ans.pop();
	  rep(k,8)b[i+my[k]][j+mx[k]]++;
	  flag = true;
	}
      }

      if(i<8 && j>0 && j<9){
	bool f = true;
	rep(k,4){
	  if(!b[i+sy[k]][j+sx[k]]){ f = false; break; }
	}
	
	if(f){
	  rep(k,4)b[i+sy[k]][j+sx[k]]--;
	  vi v(3); v[0] = j; v[1] = i+1; v[2] = 1;
	  ans.push(v);
	  if(rec(d+1))return true;
	  ans.pop();
	  rep(k,4)b[i+sy[k]][j+sx[k]]++;
	  flag = true;
	}
      }
      b[i][j]++;
      if(!flag)return false;
    }
  }
  return false;
}

int main(){
  cin >> n;
  rep(i,10)rep(j,10)cin >> b[i][j];

  rec(0);

  while(ans.size()){
    vi v = ans.top(); ans.pop();
    cout << v[0] << " " << v[1] << " " << v[2] << endl;
  }
}

Measured memory_bytes: 1224
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  cout << (a - c) * (b - d) << endl;
}


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

const ll MAXN = 200000;
const ll INF = 1001001001;
const ll MOD = 1000000007;

ll N, K, ans=0, tmp=0;
vector<ll> A;

ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

signed main(){
    cin >> N >> K;
    A.resize(K+1);
    for(int i=K;i>0;i--) {
        A[i] = modpow(K/i, N, MOD);
        for(int j=2*i;j<=K;j+=i) {
            A[i] -= A[j];
        }
        ans += i*A[i];
        ans %= MOD;
        if(ans<0) ans += MOD;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3980
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define pb push_back
typedef long double ld ;
const int N = 101;
ll dp[N][11][4][2];
int n,k;
int s[N];
ll go(int idx, int num,int cnt, int fl){
    if(idx==n-1){
        if(cnt==k)return 1;
        else return 0;
    }
    ll &ret = dp[idx][num][cnt][fl];
    if(ret!=-1)return ret;
    ret = 0;
    for(int i=0;i<=9;i++){
        if(fl){
            int zr = 0;
            if(i>0)zr = 1;
            if(cnt+zr>k)break;
            ret+=go(idx+1,i,cnt+zr,fl);
        }
        else{
            int zr = 0;
            if(i>0)zr = 1;
            int bg = 0;
            if(i<s[idx+1])bg = 1;
            if(i>s[idx+1])break;
            if(cnt+zr>k)break;
            ret+=go(idx+1,i,cnt+zr,bg);
        }
    }
    return ret;
}
void solve(){
    memset(dp,-1,sizeof dp);
    string ss;
    cin>>ss;
    n = ss.size();
    for(int i=0;i<n;i++)s[i] = ss[i]-'0';
    cin>>k;
    ll ans = 0;
    for(int i=0;i<=s[0];i++){
        ans+=go(0,i,int(i>0),int(i<s[0]));
    }
    cout<<ans<<endl;
}
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int t=1;
//	cin>>t;
	while(t--)solve();
	return 0;
}


Measured memory_bytes: 384
import java.util.*;


public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
        String ans = "ABD";
        
        if(n<1000){
            ans = "ABC";
        }
        
		System.out.println(ans);
    }
}


Measured memory_bytes: 35628
from fractions import gcd
T,*L = map(int, open(0).read().split())
for a,b,c,d in zip(*[iter(L)]*4):
  if b>d:
    print('No')
    continue
  if a<b:
    print('No')
    continue
  g = gcd(b,d)
  x = a-b
  M = ((c-x)//g+1)*g+x
  if M>=b:
    print('Yes')
  else:
    print('No')

Measured memory_bytes: 5212
#include <iostream>
using namespace std;
typedef long long ll;
ll Q,A,B;

int main(){
	cin >> Q;
	for(int i=0;i<Q;i++){
		cin >> A >> B;
		if(A==B) cout << 2*A-2 << endl;
		else if(A==B+1) cout << 2*B-2 << endl;
		else if(B==A+1) cout << 2*A-2 << endl;
		else{
			ll l = 0,r = max(A,B);
			while(l+1<r){
				ll m = (l+r)/2;
				if(m*m<A*B) l = m;
				else r = m;
			}
			if(l*(l+1)<A*B) cout << 2*l-1 << endl;
			else cout << 2*l-2 << endl;
		}
	}
}

Measured memory_bytes: 256
ans=0

n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
x=sum(a)
z=n

r=0

for l in range(n):
    
        while r<m and x+b[r]<=k:
            x+=b[r]
            r+=1
            z+=1
        if x<=k:ans=max(z,ans)
        #show(a,z,r)
        x-=a.pop()
        z-=1

while r<m and x+b[r]<=k:
    x+=b[r]
    r+=1
    z+=1
ans=max(z,ans)

print(ans)



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

const int mod=(int)1e9+7;
const int maxn=1010;
int dp[maxn][maxn];
char s[maxn][maxn];

int main()
{
	int w,h;
	scanf("%d %d",&h, &w);
	for(int i=1;i<=h;i++)
		scanf("%s",s[i]+1);
	dp[0][1]=1;
	for(int i=1;i<=h;i++)
	{
		for(int j=1;j<=w;j++)
		{
			if(s[i][j]=='#')
				continue;
			dp[i][j]=(dp[i-1][j]+dp[i][j-1])%mod;
		}
	}
	printf("%d",dp[h][w]);
}

Measured memory_bytes: 5120
class Stack():
    def __init__(self, n):
        self.S = [0 for i in range(n)]
        self.top = 0
        self.Max = n + 1

    def isEmpty(self):
        return self.top == 0

    def isFull(self):
        return self.top >= self.Max - 1

    def push(self, x):
        tf = self.isFull()
        if not tf:
            self.top += 1
            self.S[self.top] = x

    def pop(self):
        tf = self.isEmpty()
        if not tf:
            self.top -= 1
            return self.S[self.top + 1]


l = list(input().split())
n = len(l)
st = Stack(n)

for i in l:
    if i != "+" and i != "-" and i != "*":
        st.push(int(i))
    else:
        b = st.pop()
        a = st.pop()
        if i == "+":
            st.push(a+b)
        elif i == "-":
            st.push(a-b)
        elif i == "*":
            st.push(a*b)

print(st.S[1])



Measured memory_bytes: 5608
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;
 
int main() {
    ll N, K; cin >> N >> K;
    N %= K;
    set<ll> S;
    S.emplace(N);

    while(true) {
        N = abs(N - K);
        if(S.count(N)) break;
        else S.emplace(N);
    }

    cout << *S.begin() << endl;
    return 0;
}


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

vector<ll> to[100010];
ll n;


int main(){
    cin>>n;
    rep(i,0,n-1){
        ll a,b;cin>>a>>b;
        a--;b--;
        to[a].push_back(b);
        to[b].push_back(a);
    }
    queue<ll> q;
    q.push(0);
    vector<ll> dist1(n,-1);
    vector<ll> dist2(n,-1);
    dist1[0]=0;dist2[n-1]=0;
    while(!q.empty()){
        ll now=q.front();
        q.pop();
        for(auto nx:to[now]){
            if(dist1[nx]!=-1)continue;
            dist1[nx]=dist1[now]+1;
            q.push(nx);
        }
    }
    q.push(n-1);
    while(!q.empty()){
        ll now=q.front();
        q.pop();
        for(auto nx:to[now]){
            if(dist2[nx]!=-1)continue;
            dist2[nx]=dist2[now]+1;
            q.push(nx);
        }
    }
    ll c1=0,c2=0;
    rep(i,0,n){
        if(dist1[i]<=dist2[i])c1++;
        else c2++;
    }
    if(c1>c2)cout<<"Fennec"<<endl;
    else cout<<"Snuke"<<endl;
}

    









Measured memory_bytes: 7936
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		// Sの入力
		String S = sc.next();
		
		// 結果の出力
		switch (S) {
		case "SAT":
			System.out.println(1);
			break;
		case "FRI":
			System.out.println(2);
			break;
		case "THU":
			System.out.println(3);
			break;
		case "WED":
			System.out.println(4);
			break;
		case "TUE":
			System.out.println(5);
			break;
		case "MON":
			System.out.println(6);
			break;
		case "SUN":
			System.out.println(7);
			break;
		}
		
		sc.close();
	}

}


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

int main(){
    int n;
    cin >> n;
    bool ans = false;
    for(int i = 0; i <= n/4; i++){
        for(int j = 0; j <= n/7; j++){
            if(4*i+7*j==n){
                ans = true;
                break;
            }
        }
    }
    if(ans) puts("Yes");
    else puts("No");
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#ifndef FAST_IO
 #define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);
#endif

#define FILE_IO freopen("input.txt","r",stdin)
//#define int long long
#define f first
#define s second
#define endl '\n'
#define all(c) c.begin(),c.end()
#define bp __builtin_popcount
#define debug(x) cerr << #x << " = " << x << endl;

const int MOD = 1e9 + 7;
//const int INF = 1e18;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T>void print(T t){for(auto &it : t)cout<<it<<" ";}
inline int powerexp(int a, int b, int m = MOD){ int res = 1;while(b){if(b&1)res = res * a % m;a = a * a % m,b >>= 1;}return res % m;}
inline int modinv(int a){ return powerexp(a,MOD-2,MOD);}
inline int lcm(int a, int b){ int g = __gcd(a,b);return a/g*b;}
inline int add(int x, int y){ x += y; if (x >= MOD) x -=  MOD; return x;}
inline int mul(int x, int y){ return (x * 1ll * y) % MOD;}
inline int sub(int x, int y){ x -= y; if (x<0) x += MOD; return x ;}

//-------------------< start here >-------------------------// 

void solve(){
    int a[4], b[4];
    int hit , blow;
    while(scanf("%d%d%d%d%d%d%d%d",&a[0],&a[1],&a[2],&a[3],&b[0],&b[1],&b[2],&b[3]) != EOF){   
    hit = 0, blow = 0;
    for(int i = 0; i < 4; i++){
	  for(int j = 0; j < 4; j++){
		  if (a[i] == b[j]){
			  if (i != j) blow++;
			  else hit++;  
			} 
		 }	
	  }
	cout << hit << " " << blow << endl;
  }
}

//-----------------------------
//comment from here for TOPCODER 
int32_t main(){
   IOS;
   solve();
   //find();
   #ifdef LOCAL_DEFINE
   cerr << "time elapsed " << (double)clock()/CLOCKS_PER_SEC << endl;
   #endif
}



Measured memory_bytes: 3156
// {{{
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <complex>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <algorithm>
#include <numeric>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define FOR(i, a, b) for(ll i = static_cast<ll>(a); i < static_cast<ll>(b); i++)
#define FORR(i, a, b) for(ll i = static_cast<ll>(a); i >= static_cast<ll>(b); i--)
#define REP(i, n) for(ll i = 0ll; i < static_cast<ll>(n); i++)
#define REPR(i, n) for(ll i = static_cast<ll>(n); i >= 0ll; i--)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> IP;
typedef pair<ll, LP> LLP;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, 1, -1};

constexpr int INF = 100000000;
constexpr ll LINF = 10000000000000000ll;
constexpr int MOD = static_cast<int>(1e9 + 7);
constexpr double EPS = 1e-9;

static inline ll mod(ll x, ll m)
{
    ll y = x % m;
    return (y >= 0 ? y : y+m);
}

// }}}

ll N;

void solve()
{
    ll ans = 0;
    //FOR(i, 1, N+1){
    //    ans += i % (i+1 <= N ? i+1 : 1);
    //}
    ans = N * (N-1) / 2;
    cout << ans << endl;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    solve();
    return 0;
}

// vim:set foldmethod=marker:


Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;
 
using ll = long long;
using vll = vector<ll>;
using pll = pair<ll, ll>;
#define rep(i,n) for(long long i(0);(i)<(n);(i)++)
 
bool C(ll x, vll &A, vll &F, ll K){
    ll n = A.size(), cnt = 0;
    rep(i, n){
        cnt += max(0LL, (A[i]*F[i]-x + F[i]-1)/F[i]);
    }
    if(cnt <= K)
        return true;
    else
        return false;
}
void solve(long long N, long long K, vll A, vll F){
    ll sum = 0;
    rep(i, N)
        sum += A[i];
    if( K >= sum){
        std::cout << 0 << endl;
        return;
    }
 
    sort(F.begin(), F.end());
    reverse(F.begin(), F.end());
    sort(A.begin(), A.end());
    ll ub = 0LL;
    rep(i, N){
        ub = max(ub, A[i]*F[i]);
    }
 
    ll lb = 0;
    while(ub - lb > 1){
        ll mid = (lb + ub )/2;
        if(C(mid, A, F, K)) ub = mid;
        else lb = mid;
    }

    cout << ub << endl;

}

int main(){
    long long N;
    scanf("%lld",&N);
    long long K;
    scanf("%lld",&K);
    vll A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    vll F(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&F[i]);
    }
    solve(N, K, std::move(A), std::move(F));
    return 0;
}


Measured memory_bytes: 3328