akhauriyash/Code-Regression huggingface dataset:
public class Main {


  private static void solve() {
    int x = ni();
    int y = ni();
    System.out.println(x + y / 2);
  }

  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: 22864
import java.util.Scanner;
public class Main{
    int high;
    int low;
    int sa;
    
    public void soleve(){
        Scanner sc = new Scanner(System.in);
        for(int i=1;i<8;i++){
			high = sc.nextInt();
        	low = sc.nextInt();
        	sa = high - low;
			System.out.println(sa);
        }
        
    }
    
    public static void main(String[] args){
        Main obj = new Main();
        obj.soleve();
    }
}

Measured memory_bytes: 17364
import collections
import sys
n,m,k = map(int,sys.stdin.readline().split())
parent = range(n+1)
sizes = [1] * (n + 1)
hd = [1] * (n + 1) 

def f(parent, u):
	if parent[u] != u:  parent[u] = f(parent, parent[u])
	return parent[u]

while(m):
	m-=1
	a,b = map(int,sys.stdin.readline().split())
	pa,pb = f(parent, a), f(parent, b)
	hd[a] +=1
	hd[b] +=1

	if pa != pb:
		if sizes[pa] <= sizes[pb]: pa,pb = pb,pa
		parent[pb] = pa
		sizes[pa] += sizes[pb]
		
while(k):
	k-=1
	a,b= map(int,sys.stdin.readline().split())
	pa,pb = f(parent, a), f(parent,b)
	if (pa == pb):
		hd[a] += 1
		hd[b] += 1
for u in range(1,n+1):
	print str(sizes[f(parent,u)] - hd[u]) ,

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


int main(){
  int n;
  cin >> n;
  vector<int> h(n);
  for(int i=0; i<n; i++){
    cin >> h[i];
  }
  for(int i=n-1; i>0; i--){
    if(h[i-1]-h[i] == 1){
      h[i-1]--;
    }else if(h[i] >= h[i-1]){
      continue;
    }else{
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 640
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)

	result := "No"
	for i := 1; i <= 9; i++ {
		for j := 1; j <= 9; j++ {
			if i*j == n {
				result = "Yes"
				break
			}
		}
	}
	fmt.Println(result)
}


Measured memory_bytes: 1768
#!/usr/bin/perl

$s = <>;
chomp;

$m = 9999;

sub abs($) {
        ($a) = @_;

        if ($a < 0) {
                return -$a;
        } else {
                return $a;
        }
}

for ($i = 0; $i < length($s)-2; ++$i) {
        $x = substr($s, $i, 3);
        if ($m > abs($x - 753)) {
                $m = abs($x - 753);
        }
}
print "$m\n";

Measured memory_bytes: 384
x,y=map(int,input().split())
if x*y>0:
  if y>x:
    print(y-x)
  elif y<x:
    print(x-y+2)
elif x==0:
  if y>0:
    print(y)
  else:
    print(-y+1)
elif y==0:
  if x>0:
    print(x+1)
  else:
    print(-x)
elif x>0:
  print(abs(x+y)+1)
else:
  print(abs(-x-y)+1)


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

int main() {
    string S;
    string T;
    cin >> S;
    cin >> T;

    int count = 0;

    for (int i = 0; i < S.size(); i++) {
        if (S.at(i) != T.at(i)) {
            count++;
        }
    }

    cout << count << endl; 
}


Measured memory_bytes: 3848
N = int(input())
A = list(map(int,input().split()))
B = list(range(N))
i = 0
n = 0
while True:
    for i in range(N):
        B[i] =A[i]%2
        A[i] =A[i]/2
    if B.count(1) != 0:
        break
    else:
        n +=1
print(n)

  

Measured memory_bytes: 3060
//=================================
// Created on: 2018/07/06 03:06:59
//=================================
#include <bits/stdc++.h>
#define show(x) cerr << #x << " = " << (x) << endl
using namespace std;
constexpr int INF = 1 << 30;
struct CostGraph
{
    CostGraph(const int n) : V{n}, edge(n) {}
    struct Edge
    {
        Edge(const int from, const int to, const int cost) : from(from), to(to), cost(cost) {}
        const int from, to, cost;
    };
    void addEdge(const int from, const int to, const int cost) { edge[from].push_back(Edge{from, to, cost}), edge[to].push_back(Edge{to, from, cost}); }
    const int V;
    vector<vector<Edge>> edge;
};
vector<int> Dijkstra(const CostGraph& g, const int s)
{
    vector<int> d(g.V, INF);
    using P = pair<int, int>;
    priority_queue<P, vector<P>, greater<P>> q;
    d[s] = 0, q.push({0, s});
    while (not q.empty()) {
        const int cost = q.top().first, v = q.top().second;
        q.pop();
        if (d[v] < cost) { continue; }
        for (const auto& e : g.edge[v]) {
            if (d[e.to] <= d[v] + e.cost) { continue; }
            d[e.to] = d[v] + e.cost, q.push({d[e.to], e.to});
        }
    }
    return d;
}
int main()
{
    int N, T;
    string a, b;
    cin >> N >> T >> a >> b;
    map<string, int> mp;
    vector<vector<string>> s(N);
    vector<vector<int>> t(N);
    int sum = 0;
    for (int i = 0, a; i < N; i++) {
        cin >> a;
        for (int j = 0; j < a; j++) {
            string ss;
            cin >> ss;
            if (mp.find(ss) == mp.end()) {
                const int sz = mp.size();
                mp[ss] = sz;
            }
            s[i].push_back(ss), sum++;
        }
        for (int j = 0, tt; j < a - 1; j++) { cin >> tt, t[i].push_back(tt); }
    }
    vector<vector<int>> st(N);
    for (int i = 0; i < N; i++) {
        for (const string& n : s[i]) { st[i].push_back(mp[n]); }
    }
    CostGraph g(sum + mp.size());
    auto root = [&](const int s_) { return s_ + sum; };
    for (int i = 0, num = 0; i < N; i++) {
        for (int j = 0; j < st[i].size() - 1; j++) { g.addEdge(num, num + 1, 2 * t[i][j]), g.addEdge(root(st[i][j]), num, T), num++; }
        g.addEdge(root(st[i].back()), num, T), num++;
    }
    const int A = root(mp[a]), B = root(mp[b]);
    const auto d = Dijkstra(g, A);
    const int ans = d[B] - 2 * T;
    if (ans == INF - 2 * T) {
        cout << -1 << endl;
        return 0;
    }
    cout << ans / 2 << " ";
    auto dfs = [&, A, B](auto&& self, const int s) -> int {
        if (s == B) { return 0; }
        int ans = INF;
        for (const auto& e : g.edge[s]) {
            if (d[e.to] == d[s] + e.cost) { ans = min(ans, (e.to >= sum ? 1 : 0) + self(self, e.to)); }
        }
        return ans;
    };
    cout << dfs(dfs, A) - 1 << endl;
    return 0;
}



Measured memory_bytes: 28744
//PDF解説より、ある範囲で全探索すれば解けるのでそれを実直に実装
import Foundation
var X: String = readLine()!
var x: Int = Int(X)!
var flag = false
for i in -200...200{
  for j in -200...200{
    if pow(Double(i),5)-pow(Double(j),5)==Double(x){
      flag = true
      print(i,j)
      break
    }
  }
  if flag{
    break
  }
}

Measured memory_bytes: 13424
#include <stdio.h>
	
int main(void) {
	int dlist[3], i;
	for (i = 0; i < 3; i++) {
		scanf("%d", &dlist[i]);
	}
	for (i = 0; i < 2; i++) {
		if(dlist[i+1] <= dlist[i]) {
		    printf("No\n");
		    return 0;
		}
	}
	printf("Yes\n");
	return 0;
}

Measured memory_bytes: 580
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdio>
#include <queue>
#include <stack>
#include <map>
#include <set>

#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define all(v) (v).begin(), (v).end()
#define rev(s) string((s).rbegin(), (s).rend())
#define MP make_pair
#define X first
#define Y second

using namespace std;

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


bool isPrime[1000001];

void setPrime(){
	fill(isPrime, isPrime+1000001, true);
	for(int i = 4; i < 1000001; i+=2){
		isPrime[i] = false;
	}
	isPrime[0] = isPrime[1] = 0;
	for(int i = 3; i < 1000001; i+=2){
		if(isPrime[i] == true){
			for(int j = i*2; j < 1000001; j+=i){
				isPrime[j] = false;
			}
		}
	}
}

int dp[1000001];

int solve(vector<int> menu, int x){
	fill(dp, dp+1000001, -1);
	dp[0] = 0;

	int best = 0;
	for(int i = 0; i < menu.size(); i++){
		for(int j = 0; j+menu[i] <= x; j++){
			if(dp[j] != -1){
				dp[j+menu[i]] = true;
				if(isPrime[j+menu[i]]){
					best = max(best, j+menu[i]);
				}
			}
		}
	}

	return best;
}

int main(){
	setPrime();

	while(1){
		int n, x;
		cin >> n >> x;
		if(!n && !x) break;
		vector<int> menu(n);
		rep(i, n){
			cin >> menu[i];
		}

		int cost = solve(menu, x);
		if(cost){
			cout << cost << endl;
		}else{
			cout << "NA" << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 6096
def gcd(a, b):
	if (b == 0): return a
	return gcd(b, a % b)

x, y = map(int, input().split())
d = gcd(x, y)
a = x // d
b = y // d

if (b == 1):
	print(-1)
else:
	print (a * (b - 1) * d)

Measured memory_bytes: 3060
import itertools
N=int(input())
P=tuple(map(int,input().split()))
Q=tuple(map(int,input().split()))
change=list(itertools.permutations(range(1,N+1),N))
for i in range(len(change)):
  if change[i]==P:
    a=i
  if change[i]==Q:
    b=i
ans=abs(a-b)
print(ans)

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

// lib/square.hpp
#ifndef SQUARE_HPP
#define SQUARE_HPP

/*
usage:

tools::square(5) => 25
*/

namespace tools {
  template <typename T>
  constexpr T square(const T x) {
    return x * x;
  }
}

#endif

// main.cpp

int main() {
  std::int_fast64_t n;
  std::cin >> n;
  std::cout << tools::square(static_cast<std::int_fast64_t>(std::floor(std::sqrt(n)))) << std::endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <unordered_set>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
	int N;
	cin >> N;
	vector<int> dp(N + 1, 1000000);
	dp[0] = 0;
	int n;
	for (int i = 1; i <= N; i++) {
		dp[i] = dp[i - 1] + 1;
		for (int j = 1; ; j++) {
			if (i - pow(6, j) >= 0) {
				chmin(dp[i], dp[i - pow(6, j)] + 1);
			}
			else break;
			if (i - pow(9, j) >= 0) {
				chmin(dp[i], dp[i - pow(9, j)] + 1);
			}
		}
	}
	cout << dp[N] << endl;
}

Measured memory_bytes: 4196
use std::vec::Vec;
use std::cmp::*;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
  let n: usize = read();
  println!("ABC{}", n);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const int INT_INF = 1e9;
const ll MOD = 1e9 + 7;
const int INT_MOD=1e9+7;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, n) for(int i = 0; i <= n; i++)
#define rrep(i,n) for(int i=n;i>0;i--)
#define RREP(i,n) for(int i=n;i>=0;i--)
typedef pair<int, int> Pi;
typedef pair<double, double> P;
signed main(){
    int n;cin>>n;
    string str;cin>>str;
    char x=str[0];
    int ans=1;
    for(int i=1;i<n;i++){
        if(x!=str[i]){
            ans++;
            x=str[i];
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define all(v) v.begin(), v.end() 
using namespace std;

typedef long long ll;
const int NAX = 1e5 + 5;
int res[NAX];

int main() {
    string s; cin >> s;
    int n = s.length();
    deque<int> l, r;
    for(int i=0; i<n; ++i) {
        if(s[i] == 'L')
            l.push_back(i);
    }
    for(int i=n-1; i>=0; --i) {
        if(s[i] == 'R')
            r.push_back(i);
    }
    int last_lo = -1, lo = l.front();
    for(int i=0; i<n; ++i) {
        if(s[i] == 'R') {
            while(last_lo < i) {
              lo = l.front();
              l.pop_front();
              last_lo = lo;
            }
            int diff = lo - i;
            if(diff & 1)
                ++res[lo - 1];
            else
                ++res[lo];
          //  cout << "i: " << i << " lo: " << lo << " diff: " << diff << "\n";
            //for(int p=0; p<n; ++p)
              //  cout << res[p] << " ";
             //cout << "\n";
        }
    }
    reverse(all(r));
    int last_r = NAX, ri = r.back();
//    cout <<  "sgS: " << ri << "\n";
    for(int i=n-1; i>=0; --i) {
        if(s[i] == 'L') {
            while(last_r > i) {
               ri = r.back();
               r.pop_back();
               last_r = ri;
            }
            int diff = i - ri;
            if(diff & 1)
                ++res[ri+1];
            else
                ++res[ri];
           // cout << "i: " << i << " ri: " << ri << " diff: " << diff << "\n";
            //for(int p=0; p<n; ++p)
              //  cout << res[p] << " ";
             //cout << "\n";
        }
    } 
    for(int i=0; i<n; ++i)
        cout << res[i] << " ";
    cout << "\n";
    return 0;
} 


Measured memory_bytes: 1280
#include <bits/stdc++.h>
 
using namespace std;
 
#define ss second
#define ff first
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define all(a) (a).begin(),(a).end()
#define rep(i,a,b) for(int (i) = (a); (i) < (b); (i)++)
#define debug(x) cout << #x << " = " << x << endl
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using ll = long long;
using ii = pair<int,int>;
using vi = vector<int>;
using vll = vector<ll>;
using vii = vector<pair<int,int>>;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3fLL;
const int maxn = 1e5+10;

int p[maxn],sz[maxn];

int find_set(int x){
	return p[x] == x ? x : p[x] = find_set(p[x]);
}

void union_set(int a,int b){
	a = find_set(a);
	b = find_set(b);

	if(a == b) return;

	if(sz[a] > sz[b]) swap(a,b);

	p[a] = b;
	sz[b] += sz[a];
}

int main(int argc,const char** argv){

	fastio;

	int N, M;

	cin >> N >> M;

	for(int i=1;i<=N;++i){
		p[i] = i;
		sz[i] = 1;
	}

	for(int i=0;i<M;++i){
		int axi,ayi,zi;
		cin >> axi >> ayi >> zi;
		union_set(axi,ayi);
	}

	int ans = 0;

	for(int i=1;i<=N;++i){
		if(find_set(i) == i) ans++;
	}

	cout << ans << '\n';

	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S, T;
  cin >> S >> T;
  int A, B;
  cin >> A >> B;
  
  string U;
  cin >> U;
  if (U == S) A--;
  if (U == T) B--;
  
  cout << A << " " << B << endl;
  
}


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

int main() {
    int N = 0;
    cin >> N;
    
    int f_x = 0;
    int t = N;
    while(t > 0) {
        f_x += t%10;
        t /= 10;
    } 

    if(N % f_x == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3592
#include<cstdio>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>

using namespace std;

int findSumOfDigits(int n) {
	int sum = 0;
	while (n > 0) {
		sum += n % 10;
		n /= 10;
	}
	return sum;
}

int main() {
	int N, A, B;
	cin >> N >> A >> B;
	int total = 0;

	for (int i = 1; i <= N; ++i) {
		int sum = findSumOfDigits(i);

		if (sum >= A && sum <= B)
			total += i;
	}

	cout << total << endl;
}

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

int divisors(int x)
{
    int sum = 0;
    for (int i=1; i<=x/2; i++)
        if (x%i==0)
            sum++;
    return sum+1;
}

int main() 
{
    int n, sum=0;
    cin >> n;
    for (int i=1; i<=n; i+=2)
        if (divisors(i) == 8)
            sum++;
    cout << sum;
    return 0;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;

int main(){
  string s,t;
  cin>>s>>t;
  int ans=0;
  REP(i,3)if(s[i]==t[i])ans++;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
typedef long long ll;
#define REP(i,n) for(int i=0;i<(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define ZREP(i,n) for(int i=1;i<(n);++i)
#define int ll
#define Endl endl

signed main(){
    int K;
    int A[114514];
    cin >> K;
    REP(i,K){
        cin >> A[K-i-1];
    }
    int Nmin=2,Nmax=2;
    int D;
    REP(i,K){
        Nmin=(((Nmin-1)/A[i])+1)*A[i];
        
        D=(((Nmax)/A[i])+1)*A[i]-1;
        if(i!=K-1){
            D-=D%A[i+1];
        }
        
        if(A[i]>D){
            cout << -1 << endl;
            return 0;
        }
        Nmax=D;
        
        if((Nmin/A[i])*A[i]>Nmax){
            cout << -1 << endl;
            return 0;
        }
        
        //cout << Nmax <<" ";
    }
    cout << Nmin << " " << Nmax << endl;
    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 1000000007
#define LINF 100000000000000007
#define MOD 1000000007
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long  ll;
typedef pair<int,int> P;
struct edge{int to,cost;};

//�ő����
int ans;
int a[111111];
int p[111111];
int cnt[111111];
signed main(){
    int n,k,q;
    cin>>n>>k>>q;
    rep(i,q){
        cin>>a[i];
        cnt[a[i]-1]++;
    }
    rep(i,n)p[i]=k;
    rep(i,n){
        p[i]-=q;
        if(cnt[i]){
            p[i]+=cnt[i];
        }
    }
    rep(i,n){
        if(p[i]>0)cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
}

Measured memory_bytes: 2944
// テ・ツ淞コテヲツ慊ャテ」ツδ?」ツδウテ」ツδ療」ツδャテ」ツδシテ」ツδ?

#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 <functional>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int 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;}

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

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

int N, U, V, M;
int rab[1000010], cat[1000010];
int cat_row[510], cat_column[510], cat_diag[2];
int rab_row[510], rab_column[510], rab_diag[2];

signed main() {
    cin >> N >> U >> V >> M;
    memset(rab, -1, sizeof(rab));
    memset(cat, -1, sizeof(cat));
    rep(i,0,N) rep(j,0,N) {
        int num; cin >> num;
        rab[num] = i*N + j;
    }
    rep(i,0,N) rep(j,0,N) {
        int num; cin >> num;
        cat[num] = i*N + j;
    }

    int rab_cnt = 0, cat_cnt = 0;
    rep(i,0,M) {
        int num; cin >> num;

        if(~rab[num]) {
            int rx = rab[num] / N, ry = rab[num] % N;

            if(++rab_row[rx] == N) rab_cnt++;
            if(++rab_column[ry] == N) rab_cnt++;

            if(rx == ry && ++rab_diag[0] == N) rab_cnt++;
            if(rx + ry == N-1 && ++rab_diag[1] == N) rab_cnt++;
        }

        if(~cat[num]) {
            int cx = cat[num] / N, cy = cat[num] % N;

            if(++cat_row[cx] == N) cat_cnt++;
            if(++cat_column[cy] == N) cat_cnt++;

            if(cx == cy && ++cat_diag[0] == N) cat_cnt++;
            if(cx + cy == N-1 && ++cat_diag[1] == N) cat_cnt++;
        }

        if(N == 1) chmin(rab_cnt, 1LL), chmin(cat_cnt, 1LL);

        if(rab_cnt >= U && cat_cnt >= V) {
            cout << "DRAW" << endl;
            return 0;
        }
        if(rab_cnt >= U) {
            cout << "USAGI" << endl;
            return 0;
        }
        if(cat_cnt >= V) {
            cout << "NEKO" << endl;
            return 0;
        }
    }
    cout << "DRAW" << endl;
    return 0;
}

Measured memory_bytes: 18740
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E17;

#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
///////////////////////////////////////

int main(){fastio
    ll a,b,c;cin>>a>>b>>c;
    if(a==b&&b==c){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    
    return 0;
}






Measured memory_bytes: 256
// clang-format off
	#define BADSEED random_device{}()
	#include <bits/stdc++.h>
	using namespace std;
	using ll = long long;
	using uint = unsigned int;
	ostream &operator<<(ostream &os, int8_t c) { return os << short(c); }
	istream &operator>>(istream &is, int8_t &c) { short x; is >> x; c = x; return is; }
	#define TM_(...) template <class __VA_ARGS__>
	namespace narut {
	TM_(T) using TupSz = tuple_size<decay_t<T>>;
	TM_(T) constexpr auto spc(T const &t, int) -> decltype((cout << t), 'a') { return ' '; }
	constexpr auto spc(string const &s, int) { return '\n'; }
	TM_(T) constexpr auto spc(T const &t, char) { return '\n'; }
	struct IO {
		TM_(T) static auto out_(ostream &os, T const &t, int) -> decltype(void(os << t)) { os << t; }
		TM_(T, class OS) static auto out_(OS &os, T const &t, int) -> decltype(void(begin(t))) {
			auto it = begin(t), e = end(t);
			if (it != e) out_(os, *it++, 0);
			for (; it != e; out_(os, *it++, 0)) os << spc(*it, 0);
		}
		TM_(T, size_t... Is) static void out_tup(ostream &os, T const &t, index_sequence<Is...>) { (void)initializer_list<int>{0, ((Is == 0) ? 0 : ((os << ' '), 0), (os << get<Is>(t)), 0)...}; }
		TM_(T) static decltype(void(TupSz<T>{})) out_(ostream &os, T const &t, char) { out_tup(os, t, make_index_sequence<TupSz<T>::value>{}); }
		TM_(Sep, class F, class... Ts) static ostream &print(ostream &os, Sep sep, F const &f, Ts const &... ts) { return void(initializer_list<int>{(out_(os, f, 0), 0), (out_(os << sep, ts, 0), 0)...}), os; }
		TM_(T) static auto in_(istream &is, T &t, int) -> decltype(void(is >> t)) { is >> t; }
		TM_(T, class IS) static auto in_(IS &is, T &t, int) -> decltype(void(begin(t))) { for (auto &x : t) in_(is, x, 0); }
		TM_(T, size_t... Is) static void in_tup(istream &is, T &t, index_sequence<Is...>) { (void)initializer_list<int>{0, (in_(is, get<Is>(t), 0), 0)...}; }
		TM_(T) static decltype(void(TupSz<T>{})) in_(istream &is, T &t, char) { in_tup(is, t, make_index_sequence<TupSz<T>::value>{}); }
	};
	} // namespace narut
	#define Cout(...) narut::IO::print(cout, ' ', __VA_ARGS__) << '\n'
	#ifdef NARUT_LOCAL
	#define Debug(...) narut::IO::print(cerr << "\033[0;31m", ", ", __VA_ARGS__) << "\033[0m\n"
	#else
	#define Debug(...) 0
	#endif
	[[maybe_unused]] struct Cin { 
		template <class T> Cin const &operator>>(T &t) const { return narut::IO::in_(cin, t, 0), *this; }
		template <class T> operator T() const { T t; return *this >> t, t;  }	
	} Cin;
	TM_(T) auto operator%(T &t, size_t n) -> decltype(t.resize(n), t)& { return t.resize(n), t; }
	#define FOR(i, j, n) for (int i = int(j); i < int(n); ++i)
	#define ROF(i, j, n) for (int i = int(n) - 1; i >= int(j); --i)

// clang-format on





auto Main() {
	int a,b,c,k;
	cin>>a>>b>>c>>k;
	
	if (k<=a) return k;
	if (k<=a+b) return a;

	auto to_sub = k-a-b;
	return a-to_sub;	
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout << fixed << setprecision(10);
#ifdef NARUT_LOCAL
	assert(freopen("io/test.in", "r", stdin));
	cin.exceptions(cin.badbit | cin.failbit);
	cerr << fixed << setprecision(10);
#endif

	cout<<Main();
}


Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ull = unsigned long long;

ull dp[101][100010];

int main(){
  int n, W;
  cin>>n>>W;
  vector<int> w(n), v(n);
  for(int i = 0; i < n; i++)
    cin>>w[i]>>v[i];

  for(int j = 0; j <= W; j++)
    dp[0][j] = 0;
  for(int i = 0; i < n; i++){
    for(int j = 0; j <= W; j++){
      if(j >= w[i])
        dp[i+1][j] = max(dp[i][j], v[i]+dp[i][j-w[i]]);
      else
        dp[i+1][j] = dp[i][j];
    }
  }
  cout<<dp[n][W]<<"\n";
  return 0;
}


Measured memory_bytes: 79104
import sys

def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [A, B, C, X, Y] = [int(input_raw[0]), int(input_raw[1]), int(input_raw[2]), int(input_raw[3]), int(input_raw[4])]

    min_cost = sys.maxint
    for c in range(max(X, Y) * 2 + 1):
        a = max(int((X - 0.5 * c) + 0.5), 0)
        b = max(int((Y - 0.5 * c) + 0.5), 0)
        cost = a * A + b * B + c * C
        if cost < min_cost:
            min_cost = cost
    print min_cost

if __name__ == '__main__':
    main()

Measured memory_bytes: 10628
from collections import deque

N,Q = map(int,input().split())
deque_name = deque()
deque_time = deque()

for _ in range(N):
    a = list(input().split())
    deque_name.append(a[0])
    deque_time.append(int(a[1]))

now = 0
num=0
finished={}

while deque_name:

    name = deque_name.popleft()
    time = deque_time.popleft()

    if time<=Q:
        now+=time
        num+=1
        lst = [name,now]
        finished[num] = lst

    else:
        now+=Q
        time-=Q
        deque_name.append(name)
        deque_time.append(time)
    
for i in range(1,num+1):
    value = finished[i]
    print(' '.join(map(str,value)))



Measured memory_bytes: 19624
#include <iostream>
#include <iosfwd>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <cassert>
#include <cctype>
#include <climits>
#include <vector>
#include <bitset>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <deque>
#include <string>
#include <list>
#include <iterator>
#include <sstream>
#include <complex>
#include <fstream>
#include <functional>
#include <numeric>
#include <utility>
#include <algorithm>
#include <assert.h>
#include <unordered_map>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector < long long > vll;
typedef pair <long long, long long> pll;
typedef pair <int, int> pii;
typedef vector < int > vii;
typedef complex < double > Point;

#define csl ios_base::sync_with_stdio(false); cin.tie(NULL)
#define mp make_pair
#define fst first
#define snd second

ll t, n, m, u, v, q, r, ql, qr, k, l,  w, x, y, d, p, c, b, a, s;
const int N = 1e6 + 600;
const int T = 101;
const long long mod = 1e9 + 7;
const long long INF = 1LL << 52LL;

vii adj[N];
int Dfs(int v) {
  vector <int> res;
  for (int i = 0; i < adj[v].size(); ++i) {
    res.push_back(Dfs(adj[v][i]));
  }
  sort(res.begin(), res.end());
  int cMin = 0;
  for (int i = 0; i < res.size(); ++i) {
    cMin = max(cMin, res[i] + ((int)res.size() - i));
  }
 // cout << v << " " << cMin << endl;
  return cMin;
}
int main() {
  csl;
  cin >> n;
  for (int i = 2; i <= n; ++i) {
    cin >> u;
    adj[u].push_back(i);
  }
  
  cout << Dfs(1) << endl;
  return 0;
}























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

#define st first
#define nd second
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int N = 2e5 + 10;
char s[50];
vector<int> ig;
vector<pii> m2, m5, req;

int qs[10][10], sum[10];
bool isTos[N];
int isInt(int len){
	bool force = false;
	int pos = -1;
	for(int i = 0; i < len; i++){
		if(s[i] == '.'){
			pos = i;
			force = true;
		}
		else if(force && s[i] != '0'){
			return -pos;
		}
	}
	if(pos == -1) pos = len;
	return pos;
}
ll toInt(int beg, int tar){
	ll num = 0;
	for(int i = beg; i < tar; i++){
		if(s[i] == '.') continue;
		num *= 10LL;
		num += s[i] - '0';
	}
	return num;
}
int main()
{
	int n, cnt = 0;
	scanf("%d" ,&n);
	for(int i = 1; i <= n; i++){
		scanf("%s", s);
		int k = strlen(s);
		int pos = isInt(k);
		if(pos > 0){
			cnt++;
			ig.push_back(toInt(0, pos));
		}
		else{
			pos *= -1;
			ll x = toInt(0, k);
			int len = k - pos - 1;
			pii p = {len, len};
			for(int i = 0; i < len; i++){
				if(x % 2 == 0){
					x /= 2;
					p.st --;
				}
				else break;
			}
			for(int i = 0; i < len; i++){
				if(x % 5 != 0) break;
				x /= 5;
				p.nd --;
			}
			if(x % 2 == 0){
				for(int i = 1; i <= 9; i++){
					if(x % 2 != 0) break;
					p.st ++;
					x /= 2;
				}
				m2.push_back(p);
			}
			else if(x % 5 == 0){
				for(int i = 1; i <= 9; i++){
					if(x % 5 != 0) break;
					p.nd ++;
					x /= 5;
				}
				m5.push_back(p);
			}
			else req.push_back(p);
		}
	}
	int bi = 1;
	for(int i = 0; i <= 9; i++){
		int val = bi;
		for(int j = 0; j <= 9; j++){
			for(auto it: ig){
				if(it % val == 0) {
					qs[i][j] ++;
				}

			}
			if(qs[i][j] == 0) break;
			val *= 5;
		}
		if(qs[i][0] == 0) break;
		bi *= 2;
	}
	ll ans = 1LL * cnt * (cnt - 1) / 2;
	for(auto it: req){
		ans += qs[it.st][it.nd];

	}
	sort(m2.begin(), m2.end());
	sort(m5.begin(), m5.end());
	int pt = 0;
	for(auto it: m2){
		for(; pt < m5.size() && m5[pt].st <= it.st; pt++){
			for(int i = m5[pt].nd; i > 0; i--){
				sum[i]++;
			}
		}			
		ans += sum[it.nd] + qs[0][it.nd];

	}
	for(auto it: m5){
		ans += qs[it.st][0];
	}
	printf("%lld", ans);
}

Measured memory_bytes: 5600
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;

public class Main {
    static int sum;
    static List<LinkedList<Integer>> graph;
    static boolean[] isVisited;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int m = Integer.parseInt(sc.next());
        graph = new ArrayList<LinkedList<Integer>>();
        isVisited = new boolean[n];
        int s ,t;
        for(int i=0;i<n;i++)graph.add(new LinkedList<>());
        for(int i=0;i<m;i++){
            s = Integer.parseInt(sc.next())-1;
            t = Integer.parseInt(sc.next())-1;
            graph.get(s).add(t);
            graph.get(t).add(s);
        }
        sc.close();
        sum = 0;
        bfs(0,n,0);
        System.out.println(sum);

    }

    public static void bfs(int pos,int n,int v){
        if(pos == n-1){
            sum++;
        }else{
            isVisited[v] = true;
            for(Integer i : graph.get(v)){
                if(!isVisited[i]){
                    bfs(pos+1,n,i);
                }
            }
            isVisited[v] = false;
        }
    }
}

Measured memory_bytes: 24148
#include <iostream>

int main()
{
	int a, b;
	std::cin >> a >> b;
	if (a < b)
		std::cout << "a < b" << std::endl;
	else if (a > b)
		std::cout << "a > b" << std::endl;
	else
		std::cout << "a == b" << std::endl;
	
	return 0;
}

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

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define foru(i, a, b) for(int i = a; i <= b; i++)
#define ford(i, a, b) for(int i = a; i >= b; i--)
#define endl "\n"
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
#define com(a, b) a ## b
#define scv(a, b, c) #a#b#c
#define db(x) cerr << "[" << #x << ": " << (x) << "] " << endl;
#define run cerr << 1 << endl; 
template<class T> void printvec(vector<T>& x, int a, int b) {foru (i, a, b) cout << x[i] << " "; cout << endl;}

typedef long long ll;
typedef double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vii;
typedef vector<pll> v2l;
typedef pair<char, int> pci;
typedef vector<pci> vci;

const ld PI = acos((ld) -1);
const ld EPS = 1e-6;
const int N = 1e6 + 1;
const int NN = 1e3 + 1;
const ll MOD = 1e9 + 7;
const ll oo = 1e18 + 7;
const int BASE = 10000;

void solve() {
    ll n;
    cin >> n;
    ll div3 = n / 3;
    ll div5 = n / 5;
    ll div15 = n / 15;
    ll sum = (div3 + 1) * div3 / 2 * 3 + (div5 + 1) * div5 / 2 * 5 - (div15 + 1) * div15 / 2 * 15;
    cout << (n + 1) * n / 2 - sum; 
}

int main() {
    #ifdef DEBUG
        com(fre, open) (scv(solve, ., inp), "r", stdin);
        com(fre, open) (scv(solve, ., out), "w", stdout);
    #endif
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cout.precision(10);
    solve();
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    return 0;
} 

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

vector<string> weather = {"Sunny", "Cloudy", "Rainy"};
int main(void) {
    string S;
    int pos;
    cin >> S;

    for(vector<string>::iterator it = weather.begin();it<weather.end();it++) { 
        if(S == *it) {
            pos = (distance(weather.begin(),it) + 1) % weather.size();
            cout << weather[pos] << "\n";
        }
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define MAX 510000
#define rrep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define dcout cout<<fixed<<setprecision(15);
#define pb push_back
#define mp make_pair 

using namespace std;
typedef long long int  ll;
typedef pair<ll, ll> P;

constexpr int MOD = 1e9 + 7;
constexpr ll inf = 1LL << 60;

template< typename S, typename T >
inline void chmax(S &a, const T &b) { if(a < b) a = b; }
 
template< typename S, typename T >
inline void chmin(S &a, const T &b) { if(a > b) a = b; }
 

//lcm//
ll gcd(ll x, ll y) {
	if (x == 0) return y;
	return gcd(y%x, x);
}
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

//a^n mod p//
ll modpow(ll a, ll n, ll p) {
  if (n == 1) return a % p;
  if (n % 2 == 1) return (a * modpow(a, n - 1, p)) % p;
  ll t = modpow(a, n / 2, p);
  return (t * t) % p;
}

//inversemod//
ll modinv(ll a, ll m) {
	if(m==0)return (ll)1;
	ll b = m, u = 1, v = 0;
	while (b) {
		ll t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

//Cmonp//
ll 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;
	}
}

// 
ll COM(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

//LARGE n
ll com(ll n,ll m){
    if(n<m || n<=0 ||m<0){
		return 0;
	}
	if( m==0 || n==m){
		return 1;
	}
	ll k=1;
	for(ll i=1;i<=m;i++){
       k*=(n-i+1); 
	   k%=MOD;
	   k*=modinv(i,MOD);
	   k%=MOD;
	}
	return k;
}

//radP
ll rad(ll u, ll p){
ll cnt=0;
	while(u%p==0){
		u/=p;
		cnt++;
	}
	return cnt;
}


////////////////////////////////////////////////////////////////////

int main(){
ll h,w,n;
cin>>h>>w>>n;
vector<P> vec{};
rep(i,n){
	ll x,y;
	cin>>x>>y;
	vec.pb(mp(x,y));
}
sort(ALL(vec));

ll ans=h;
ll val=0;
ll lim[h+1];
rep(i,h){
	lim[i]=-1;
}

rep(i,n){
ll x,y;
x=vec[i-1].first;
y=vec[i-1].second;
lim[x]=max(lim[x],x-y);
}

for(int i=2;i<=h;i++){
lim[i]=max(lim[i],lim[i-1]);
}

rep(i,n){
	ll x,y;
x=vec[i-1].first;
y=vec[i-1].second;
	if(x==1)continue;
	if(lim[x-1]<(x-y-1)) ans=min(ans,x-1);
}


cout<<ans<<endl;
return 0;

}










Measured memory_bytes: 6128
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int Y = sc.nextInt();
        for(int a=0;a<=N;a++){
            for(int b=0;b<=N-a;b++){
                int c = N-a-b;
                int total = 10000*a+5000*b+1000*c;
                if(total==Y){
                    System.out.println(a+" "+b+" "+c);
                    return;
                }
            }
        }
        System.out.println("-1 -1 -1");
    }
}

Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;
  cin >> S;
  
  bool hitachi = true;
  
  int l = S.length();
  if(l & 1) hitachi = false;
  l /= 2;
  
  int idx = 0;
  for(int i = 0; i < l; i++){
  	if(S[idx+0] != 'h' || S[idx+1] != 'i'){hitachi = false; break;}
  	idx+=2;
  }
  
  cout << (hitachi ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
a = list(map(int, input().split()))
d = dict()
for x in a:
    try: d[x] += 1
    except: d[x] = 1
l = sorted(list(d.values()))
if len(l) <= k: print(0)
else: print(sum([l[i] for i in range(len(l) - k)]))

Measured memory_bytes: 33152
#!usr/bin/env python3
from collections import defaultdict, deque, Counter, OrderedDict
from bisect import bisect_left, bisect_right
from functools import reduce, lru_cache
from heapq import heappush, heappop, heapify

import itertools, bisect
import math, fractions
import sys, copy

def L(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline().rstrip())
def S(): return list(sys.stdin.readline().rstrip())
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return [list(x) for x in sys.stdin.readline().split()]
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def LIR1(n): return [LI1() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
def LR(n): return [L() for _ in range(n)]

alphabets = "abcdefghijklmnopqrstuvwxyz"
ALPHABETS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

sys.setrecursionlimit(1000000)
dire = [[1, 0], [0, 1], [-1, 0], [0, -1]]
dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]
MOD = 1000000007
INF = float("inf")

def main():
    N, M, S = LI()
    UVAB = LIR(M)
    CD = LIR(N)

    edge = [[] for _ in range(N)]
    for u, v, a, b in UVAB:
        edge[u - 1].append((v - 1, a, b))
        edge[v - 1].append((u - 1, a, b))

    dist = [[INF] * 2500 for _ in range(N)]
    heap = [(0, 0, min(2500, S))]

    while heap:
        cost, u, s = heappop(heap)
        c, d = CD[u]

        if s + c < 2500 and dist[u][s + c] > cost + d:
            dist[u][s + c] = cost + d
            heappush(heap, (cost + d, u, s + c))
        for v, a, b in edge[u]:
            if s - a >= 0 and dist[v][s - a] > cost + b:
                dist[v][s - a] = cost + b
                heappush(heap, (cost + b, v, s - a))

        # print(heap)

    for i in range(1, N):
        print(min(dist[i]))

if __name__ == '__main__':
    main()

Measured memory_bytes: 105044
package main

import "fmt"

func main() {
	var X, Y int
	fmt.Scan(&X, &Y)
	var ans, mul int
	mul = X
	if X == Y || 2*X > Y {
		ans = 1
	} else {
		ans = 1
		for {
			if mul*2 <= Y {
				mul *= 2
				ans++
			} else {
				break
			}
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long int a, b, c, d;
    cin>>a>>b>>c>>d;
    if(a*c>b*d && a*c>a*d && a*c>b*c)
        cout<<a*c;
    else if(b*c>b*d && b*c>a*d && b*c>a*c)
        cout<<b*c;
    else if(a*d>b*d && a*d>b*c && a*d>a*c)
        cout<<a*d;
    else
        cout<<b*d;
    return 0;
}

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

using namespace std;
//FILE *fi=freopen("1.txt","r",stdin);
string s;
int main()
{
    cin>>s;
    for(auto c:s)
    {
            if(c=='7')
            {
                cout<<"Yes";
                return 0;
            }
    }
    cout<<"No";
    return 0;
}


Measured memory_bytes: 3620
# -*- coding: utf-8 -*-

import math

# スペース区切りの整数の入力
a, b, x = map(int, input().split())

#三角形
if x/a <= (a*b)/2 : 
  Theta = math.atan2( b, (2*x)/(a*b) )
  
#台形
else :
  Theta = math.atan2( (2*b) - ((2*x)/(a*a)) , a )
  
print (math.degrees(Theta))

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,d;
  cin >>a >>b >>c >>d;
  if(a+b>c+d){
    cout <<"Left"<<endl;
  }
  else if(a+b<c+d){
    cout <<"Right"<<endl;
  }
  else if(a+b==c+d){
    cout <<"Balanced"<<endl;
  }
  
}

Measured memory_bytes: 256
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<sstream>
#include<stack>
#include<string>
#include<unordered_set>
#include<vector>

#define ll long long
#define P pair<int,int>
#define FOR(i,N) for(int i=0;i<(int)N;i++)
#define FORIN(i,a,b) for(int i=a;i<(int)b;i++)
#define ALL(x) (x).begin(),(x).end()
#define LAST(x) (x)[(x).size()-1]
#define GI(name) int (name);scanf("%d",&(name))
#define GI2(name1,name2) int (name1),(name2);scanf("%d %d",&(name1),&(name2))
#define GI3(name1,name2,name3) int (name1),(name2),(name3);scanf("%d %d %d",&(name1),&(name2),&(name3))
#define GVI(name,size) vector<int> (name)(size);FOR(i,(size)scanf("%d",&(name)[i])

using namespace std;

string to_hex(int x){
    stringstream ss;
    ss<<hex<<x;
    return ss.str();
}

inline int get_int(){
    int ret;
    scanf("%d",&ret);
    return ret;
}

inline vector<int> get_ints(int n){
    vector<int> ret(n);
    FOR(i,n){
        scanf("%d",&ret[i]);
    }
    return ret;
}

inline string get_str(){
    string ret;
    cin>>ret;
    return ret;
}

bool is_prime(int n){
    int s=sqrt(n)+1;
    for(int i=2;i<=s;++i){
        if(n%i==0){
            return 0;
        }
    }
    return 1;
}

vector<P> prime_division(int n){
    vector<P> ret;
    int s=sqrt(n)+1;
    int c=0;
    for(int i=2;i<=s;++i){
        if(n%i==0){
            c=0;
            do{
                ++c;
                n/=i;
            }while(n%i==0);
            ret.push_back(P(i,c));
        }
    }
    return ret;
}

string to_string(string s){
    return s;
}

template<class T>
string to_string(vector<T> v){
    string ret="{";
    FOR(i,v.size()-1){
        ret+=to_string(v[i])+",";
    }
    if(v.size()>0){
        ret+=to_string(LAST(v));
    }
    ret+="}";
    return ret;
}

void debug_print(){
    cerr<<endl;
}

template<class Head,class... Tail>
void debug_print(Head head,Tail... tail){
    cerr<<to_string(head)<<" ";
    debug_print(tail...);
}

template<class... T>
void debug(T... args){
    cerr<<"["<<__LINE__<<"]: ";
    debug_print(args...);
}

void print(){
    cout<<endl;
}

template<class Head,class... Tail>
void print(Head head,Tail... tail){
    cout<<to_string(head);
    print(tail...);
}

int main(){
    GI3(a,b,c);
    print(b-a==c-b?"YES":"NO");
    return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<queue>

using namespace std;

typedef long long ll;

int N, M;
ll A[100000 + 10];

bool f(ll price) {
	int cpyM = M;
	for (int i = 0; i < N; i++) {
		ll tmp = A[i];
		while (cpyM > 0 && tmp > price) {
			cpyM--;
			tmp /= 2;
			//cout << i << " " << cpyM << " " << tmp << endl;
		}
		if (cpyM == 0 && tmp > price) {
			return false;
		}
	}
	return true;
}

int main() {
	cin >> N >> M;
	for (int i = 0; i < N; i++)cin >> A[i];
	
	ll u = 1145141919, l = 0;
	while (u - l > 1) {
		ll mid = (u + l) / 2;
		if (f(mid))u = mid;
		else l = mid;
	}
	
	ll ans = 0;

	if (f(l)) {
		for (int i = 0; i < N; i++) {
			while (M > 0 && A[i] > l) {
				M--;
				A[i] /= 2;
			}
		}

	}
	else {
		for (int i = 0; i < N; i++) {
			while (M > 0 && A[i] > u) {
				M--;
				A[i] /= 2;
			}
		}
	}
	priority_queue<ll> item;
	for (int i = 0; i < N; i++) {
		item.push(A[i]);
	}
	while (M--) {
		ll tmp = item.top(); item.pop();
		item.push(tmp / 2);
	}
	while (item.size()) {
		ans += item.top();
		item.pop();
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 2168
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		String s = sc.next();
		
		for(int i = 0; i < s.length(); i++) {
			if (i % 2 == 0)
				System.out.print(s.charAt(i));
		}
		System.out.println();
		sc.close();
	}
}

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

using namespace std;

int main(void) {
  string s;
  cin >> s;

  if (s.front() == s.back()) {
    cout << (s.size() & 1 ? "Second" : "First") << endl;
  } else {
    cout << (s.size() & 1 ? "First" : "Second") << endl;
  }

  return 0;
}

Measured memory_bytes: 512
import java.io.*;
import java.util.*;
import java.util.ArrayList;
 
class Main
{
  public static void main (String[] arg)
  {
    Scanner scan = new Scanner(System.in);
    
    int K = Integer.parseInt(scan.next()); //K
    
    int[] foo = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    
    System.out.println(foo[K-1]);
  }
}


Measured memory_bytes: 23764