akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
using namespace std;
int a[200010],mx[200010],mn[200010];
int l[200010],r[200010];
long long ans;
int n;
int lowbit(int x)
{
	return x&(-x);
}
int addmx(int x,int k)
{
	while(x<=n)
	{
		mx[x]=max(mx[x],k);
		x+=lowbit(x);
	}
}
int querymx(int x)
{
	int res=0;
	while(x>0)
	{
		res=max(res,mx[x]);
		x-=lowbit(x);
	}
	return res;
}
int addmn(int x,int k)
{
	while(x<=n)
	{
		mn[x]=min(mn[x],k);
		x+=lowbit(x);
	}
}
int querymn(int x)
{
	int res=n+1;
	while(x>0)
	{
		res=min(res,mn[x]);
		x-=lowbit(x);
	}
	return res;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)mn[i]=n+1;
	for(int i=1;i<=n;i++)scanf("%d",a+i);
	for(int i=1;i<=n;i++)
	{
		l[i]=querymx(a[i]-1);
		addmx(a[i],i);
	}
	for(int i=n;i>=1;i--)
	{
		r[i]=querymn(a[i]-1);
		addmn(a[i],i);
	}
	for(int i=1;i<=n;i++)ans+=1LL*(i-l[i])*(r[i]-i)*a[i];
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 4096
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <string>
#include <functional>
#include <set>
#include <map>
#include <random>
/* All our base are belong to AC */
#define DB cerr<<"D"<<endl
#define pb push_back
using namespace std; using ll=long long; using ld=long double; const int INF=1e9; const ll LINF=1e18; const double dINF = 1e18; const ld ldINF = 1e18; const double EPS = 1e-6;
template<typename T, typename U, typename O> void caut(T a, U b, O c){cout<<"("<<a<<","<<b<<","<<c<<") ";} template<typename T, typename U> void caut(T a, U b){cout<<"("<<a<<","<<b<<") ";} template<typename T> void caut(T a){cout<<"("<<a<<") ";}
using P=pair<int,int>;
const ll M = 1e9+7;
void add(ll& x, ll y) {x+=y; x%=M;}; void mul(ll& x, ll y) {x*=y; x%=M;}; template<typename T, typename U> void chmax(T& x, U y) {if (x<y) x=y;}; template<typename T, typename U> void chmin(T& x, U y) {if (x>y) x=y;};
ll mod_pow(ll x, ll a) { ll an = 1; while(a > 0) { if (a&1) an = an * x % M; x = x * x % M; a >>= 1;} return an;}

namespace r {
    random_device rd;
    mt19937 mt(rd());
    //mt19937 mt(time(NULL));
    int nd(int max) {return mt() % max + 1;}
    int nd2(int min, int max) {return mt() % (max - min + 1) + min;}
}

int main() {
  int d; cin>>d;
  ll c[26];
  for(int i=0;i<26;i++) {
    cin>>c[i];
  }
  ll s[d][26];
  for(int i=0;i<d;i++) {
    for(int j=0;j<26;j++) {
      cin>>s[i][j];
    }
  }
  int t[d];
  for(int i=0;i<d;i++) {
    cin>>t[i]; t[i]--;
  }
  ll an = 0;
  int l[26]; fill(l,l+26,-1);
  for(int i=0;i<d;i++) {
    l[t[i]]=i;
    an+=s[i][t[i]];
    for(int j=0;j<26;j++) {
      an-=(i-l[j])*c[j];
    }
    cout<<an<<endl;
  }
}

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


Measured memory_bytes: 256
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter
import kotlin.math.max
import kotlin.math.min

val br = BufferedReader(InputStreamReader(System.`in`))
val out = PrintWriter(System.out)

fun main() {
    br.use { out.use {
        solve()
        out.flush()
    } }
}

fun solve() {
    val (h, w, k) = readIntegerList()
    val cake = Array(h) { br.readLine()!! }

    //　各行に何個あるかをみて、一つでもあればその行の下でカットする
    val cutGroup = IntArray(h)
    var cutNum = 0
    for (i in 0 until h) {
        if (cake[i].contains('#')) cutNum++
        cutGroup[i] = if (cutNum == 0) 1 else cutNum
    }

    // 各行を横に見て一つでもあればそこで切る
    val ans = Array(h) { IntArray(w) }
    var c = 0
    var rowStart = 0
    while (rowStart < h) {
        var rowEnd = rowStart
        while (rowEnd < h && cutGroup[rowEnd] == cutGroup[rowStart]) rowEnd++

        var lastC = c
        for (i in 0 until w) {
            var f = false
            for (j in rowStart until rowEnd) {
                if (cake[j][i] == '#') {
                    f = true
                }
            }

            if (f) c++

            for (j in rowStart until rowEnd) {
                ans[j][i] = if (c == lastC) lastC + 1 else c
            }
        }

        rowStart = rowEnd
    }

    for (row in ans) {
        out.println(row.joinToString(" "))
    }
}

/**
O(n^(1/2)) // n * n <= Long.MAX_VALUE n <= 10^8 or more
if n == 1, return emptyMap
 */
fun primeFactor(n: Long): Map<Long, Long> {
    val factorMap = mutableMapOf<Long, Long>()
    var target = n
    var i = 2L
    while (i * i <= target) {
        while (target % i == 0L) {
            factorMap[i] = factorMap.getOrElse(i) { 0L } + 1L
            target /= i
        }
        i++
    }

    if (target != 1L) { factorMap[target] = 1 }
    return factorMap
}

fun readInteger() = Integer.parseInt(br.readLine())
fun readLong() = java.lang.Long.parseLong(br.readLine())
fun readStringList() = br.readLine()!!.split(' ')
fun readIntegerList() = readStringList().map(Integer::parseInt)
fun readLongList() = readStringList().map(java.lang.Long::parseLong)
fun readDoubleList() = readStringList().map(java.lang.Double::parseDouble)


Measured memory_bytes: 48796
#include<iostream>
#include<cmath>
#include<vector>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	vector<int> vec;
	rep(i,1000001){
		vec.push_back(0);
	}
	rep(i,20){
		rep(j,13){
			rep(k,9){
				long long num=pow(2,i)*pow(3,j)*pow(5,k);
				if(num<=1000000)vec[num]=1;
			}
		}
	}
	long long start,end;
	while(cin>>start){
		if(start==0)break;
		cin>>end;
		int cnt=0;
		loop(i,start,end+1){
			if(vec[i]==1)cnt++;
		}
		cout<<cnt<<endl;
	}
	return 0;
}

Measured memory_bytes: 7168
function main(input){
  input = input.split("\n");
  var n = parseInt(input[0].split(" ")[0]);
  var d = parseInt(input[0].split(" ")[1]);

  var number = 1 + 2 * d ;
  number =  n / number; 
  console.log(Math.ceil(number));
}
 
 
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 21064
import Control.Arrow

main = interact $ 
  lines >>> head >>> solve

solve :: String -> String
solve s
  | let len = length s in 
      and [isPalin s, 
        isPalin $ take (div len 2) s,
        isPalin $ drop (1 + (div len 2)) s]
         = "Yes"
  | otherwise = "No"

isPalin :: String -> Bool
isPalin s = s == reverse s

Measured memory_bytes: 508
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

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

/*
 freopen("input","r",stdin);
 freopen("output","w",stdout);
*/

ll B = 1E18;

ll DP[100010];
ll H[100010];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int N;
    cin >> N;
    for (int i = 0;i < N;i++) cin >> H[i];
    for (int i = 0;i < N;i++) DP[i] = B;
    DP[0] = 0;
    for (int i = 0;i < N;i++) {
        if (i + 1 < N) {
            DP[i + 1] = min(DP[i + 1], DP[i] + abs(H[i] - H[i + 1]));
        }
        if (i + 2 < N) {
            DP[i + 2] = min(DP[i + 2], DP[i] + abs(H[i] - H[i + 2]));
        }
    }
    cout << DP[N - 1] << endl;
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int gcd(int x, int y)
{
    if (x == 0)
        return y;
    return gcd(y % x, x);
}

int n;
int a[N];
int main()
{
    cin >> n;
    for (int i = 1; i <= n; ++i)
        cin >> a[i];
    int ans = a[1];
    for (int i = 2; i <= n; ++i)
        ans = gcd(ans, a[i]);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
#include <iostream>

using namespace std;

int main() {
    int c[3][3] = {
            {0, 0, 0},
            {0, 0, 0},
            {0, 0, 0}
    };

    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            cin >> c[i][j];
        }
    }

    int a[3];
    for (int i = 1; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            int diff = c[i][j] - c[i - 1][j];
            if (j == 0) {
                a[i] = diff;
            } else {
                if (diff != a[i]) {
                    cout << "No" << endl;
                    return 0;
                }
            }
        }
    }

    int b[3];
    for (int j = 1; j < 3; j++) {
        for (int i = 0; i < 3; i++) {
            int diff = c[i][j] - c[i][j - 1];
            if (i == 0) {
                b[j] = diff;
            } else {
                if (diff != b[j]) {
                    cout << "No" << endl;
                    return 0;
                }
            }
        }
    }

    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.Map.Entry;

public class Main {
	public static void main(String[] args) throws NumberFormatException,
			IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(
				System.in));
		StringBuilder builder = new StringBuilder();
		String line;
		int rectangles = 0;
		int lozenges = 0;
		while ((line = reader.readLine()) != null) {
			if (line.isEmpty()) {
				break;
			}
			StringTokenizer tokenizer = new StringTokenizer(line, ",");
			int a = Integer.parseInt(tokenizer.nextToken());
			int b = Integer.parseInt(tokenizer.nextToken());
			int c = Integer.parseInt(tokenizer.nextToken());
			if(a == b){
				lozenges++;
			}
			else if(a*a+b*b==c*c){
				rectangles++;
			}
				
		}
		System.out.println(rectangles);
		System.out.println(lozenges);
	}
}

Measured memory_bytes: 15020
#include<iostream>
#include<cstring>
#define INF 1<<20
using namespace std;

int w, h;
int data[22][22];
int memo[22][22];

int solve(int x, int y){

  if(x < 0 || x == w || data[y][x]&1) return 0;
  if(y > h-2) return 1;
  if(memo[y][x]) return memo[y][x];

  int ret = 0;
  if(data[y][x] == 2) ret += solve(x, y+2);
  else{
    if(!data[y+1][x-1]) ret += solve(x-1, y+1);
    if(!data[y+1][x+1]) ret += solve(x+1, y+1);
    ret += solve(x, y+1);
  }
  
  return memo[y][x] = ret;
}

int main(){

  while(cin >> w >> h, w+h){

    for(int i=0;i<h;i++) for(int j=0;j<w;j++) cin >> data[i][j];

    memset(memo, 0, sizeof(memo));
    int ans = 0;
    for(int i=0;i<w;i++) ans += solve(i, 0);

    cout << ans << endl;
  }

}

Measured memory_bytes: 1164
#include<cstdio>
using namespace std;
long long GET()
{
    long long x=0,f=1;
    char c;
    c=getchar();
    if (c==' ') return x*f;
    while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
    while (c>='0'&&c<='9') {x=x*10+c-'0';c=getchar();}
    return x*f;
}
int main()
{
	long long n,m,ans=0;
	n=GET();
	m=GET();
	ans=m-n*2;
	if(ans<0)
	{
		printf("%lld\n",m>>1);
	} 
	else
	printf("%lld\n",n+(ans>>2));
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b,c;
    cin>>a>>b>>c;
    vector<int>vec(3);
    vec[0]=a;
    vec[1]=b;
    vec[2]=c;
    sort(vec.begin(), vec.end());
    cout<<vec[2]-vec[0]<<endl;
    
}

Measured memory_bytes: 256
// Author: getharshkumar

#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
const ll N = 1e6 + 6, M = 1e9 + 7;
int main()
{
    ios::sync_with_stdio(false), cin.tie(nullptr);
    string s;
    cin >> s;
    for (ll i = 0; i < s.size(); i++)
    {
        if ((i % 2 && s[i] == 'R') || (i % 2 == 0 && s[i] == 'L'))
            return cout << "No", 0;
    }
    cout << "Yes";
    return 0;
}

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

bool IsPrime(int num)
{
    if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}

int main() {
  long long N;
  cin >> N;
  bool ans=false;
  int pre=N;
  if(IsPrime(pre) == true){cout << pre << endl;return 0;}
  while(ans == false){
    pre++;
    ans = IsPrime(pre);
    
    
  }
  cout << pre << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int sum=0;
    while(1){
        string str;
        cin>>str;
        if(str=="0") break;
        
        sum=0;
        for(int i=0;i<(int)str.size();i++){
            sum+=str[i]-'0';
        }
        cout<<sum<<endl;
    }
    return 0;
}


Measured memory_bytes: 3224
fn get_line() -> String {
    use std::io;
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.pop().unwrap();
    buf
}

fn main() {
    let n = get_line().parse::<i64>().unwrap();
    let mut abcde = [0; 5];
    for i in abcde.iter_mut() {
        *i = get_line().parse::<i64>().unwrap();
    }

    let (mut min, mut idx) = (abcde[0], 0);
    for index in 1..5 {
        if abcde[index] < min {
            min = abcde[index];
            idx = index as i64;
        }
    }

    let bottle = n / min + if n % min == 0 { 0 } else { 1 };

    println!("{}", idx + bottle + 4 - idx);
}


Measured memory_bytes: 4352
import sys
input = sys.stdin.readline
def main():
    X, Y, A, B, C = map(int, input().split())
    p = list(map(int, input().split()))
    p.sort(reverse=True)
    q = list(map(int, input().split()))
    q.sort(reverse=True)
    r = list(map(int, input().split()))
    r.sort(reverse=True)
    target = p[:X] + q[:Y] + r
    target.sort(reverse=True)
    ans = sum(target[:X+Y])
    print(ans)
if __name__ == "__main__":
    main()

Measured memory_bytes: 94956
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author silviase
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CLinearApproximation solver = new CLinearApproximation();
        solver.solve(1, in, out);
        out.close();
    }

    static class CLinearApproximation {
        public void solve(int testNumber, Scanner in, PrintWriter out) {

            // b + iの大小が丁度n/2位になるとき
            int n = in.nextInt();
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = in.nextInt() - i - 1;
            }
            long sum = 0;
            Arrays.sort(a);
            long res = a[n / 2];
            for (int i = 0; i < n; i++) {
                sum += Math.abs(a[i] - res);
            }

            out.println(sum);

        }

    }
}



Measured memory_bytes: 64724
import java.util.*;
import java.io.*;
import static java.lang.Math.*;

public class Main {
    public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		String s = sc.next();
		String t = sc.next();
		
		// 計算
		String result = "No";
		if(t.substring(0, t.length()-1).equals(s)) result = "Yes";
		
		// 出力
		System.out.println(result);
	}
	
	public static class Scanner {
		private BufferedReader br; private StringTokenizer tok;
		public Scanner(InputStream is) throws IOException { br = new BufferedReader(new InputStreamReader(is));}
		private void getLine() throws IOException { while(!hasNext()) tok = new StringTokenizer(br.readLine());}
		private boolean hasNext() { return tok != null && tok.hasMoreTokens();}
		public String next() throws IOException { getLine(); return tok.nextToken();}
		public int nextInt() throws IOException { return Integer.parseInt(next());}
		public long nextLong() throws IOException { return Long.parseLong(next());}
		public double nextDouble() throws IOException { return Double.parseDouble(next());}
	}
}



Measured memory_bytes: 25404
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int a,b;
int fie[101][101];

int main(void){
	scanf("%d%d",&a,&b);
	int vi=min(a,b);
	int va=max(a,b);
	printf("%d %d\n",100,100);
	int nx=0,ny=0;
	for(int i=0;i<va;i++){
		for(int j=0;j<3;j++){
			for(int k=0;k<3;k++){
				fie[ny+j][nx+k]=1;
			}
		}
		nx+=4;
		if(nx==100){
			ny+=4;
			nx=0;
		}
	}
	nx=1;
	ny=1;
	for(int i=0;i<vi-1;i++){
		fie[ny][nx]=0;
		nx+=4;
		if(nx==101){
			ny+=4;
			nx=1;
		}
	}
	for(int i=0;i<100;i++){
		for(int j=0;j<100;j++){
			if(a<=b){
				printf("%c",fie[i][j]==1?'#':'.');
			}else{
				printf("%c",fie[i][j]==0?'#':'.');
			}
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define EPS (1e-8)
using namespace std;
typedef complex<double> point;

vector<point> CrossPoints_CC(point a,double ra,point b,double rb){
  vector<point> res;
  b-=a;

  double k= abs(b);
  double Cos = ( k*k + ra*ra - rb*rb ) / ( 2.0 * ra * k  );
  double  d = ra*Cos;
  double  c = sqrt( ra*ra - d*d );

  res.push_back(point(d,c));
  res.push_back(point(d,-c));  
  for(int i=0;i<(int)res.size();i++)res[i]=res[i]*b/abs(b)+a;
  return res;
}


int main(){
  point c1,c2;
  double a,b,r1,r2;
  cin>>a>>b>>r1;
  c1=point(a,b);
  cin>>a>>b>>r2;
  c2=point(a,b);
  vector<point> ans=CrossPoints_CC(c1,r1,c2,r2);
  if(ans[0].real()>ans[1].real())swap(ans[0],ans[1]);
  if(ans[0].real()==ans[1].real())
    if(ans[0].imag()>ans[1].imag())swap(ans[0],ans[1]);
  for(int i=0;i<2;i++){
    if(i)cout<<' ';
    printf("%.8f %.8f",ans[i].real(),ans[i].imag());
  }
  cout<<endl;
  return 0;
}

Measured memory_bytes: 1300
#include<bits/stdc++.h>
using namespace std;
#define s sqrt
#define int long long
signed main(){
    int a,b,c;
    cin >> a >> b >> c;
    cout << (0 < c - a - b && (c - a - b) * (c - a - b) > 4 * a * b ? "Yes" : "No") << "\n";
}

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

using namespace std;

int main(void)
{
	vector<unsigned long long> input;
	input.resize(3);

	cin >> input[0];
	cin >> input[1];
	cin >> input[2];

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

	if( input[2] % 2 == 0 )
		cout << 0;
	else
		cout << input[0] * input[1];

	return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static String Y = "Yes";
	public static String N = "No";
	public static long MOD = (long) (Math.pow(10, 9) + 7);
	public static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {

		char[] s = nc();
		char[] t = nc();

		int n = s.length;

		int ans = 0;

		for (int i = 0; i < n; i++) {
			if (s[i] != t[i]) {
				ans++;
			}
		}

		out(ans);

	}

	/*
	 * 以下メソッド集
	 */
	static int[] sort(int[] n) {
		Arrays.sort(n);
		return n;
	}

	static long[] sort(long[] n) {
		Arrays.sort(n);
		return n;
	}

	static int ketasuu(int n) {
		String str = "" + n;
		return str.length();
	}

	static int account(String str) {
		String target = "AC";
		int count = 0;
		int len = str.length();
		for (int i = 0; i < len - 1; i++) {
			if (target.equals(str.substring(i, i + target.length()))) {
				count++;
			}
		}
		return count;
	}

	static int ni() {
		return sc.nextInt();
	}

	static long nl() {
		return sc.nextLong();
	}

	static double nd() {
		return sc.nextDouble();
	}

	static String n() {
		return sc.next();
	}

	static char[] nc() {
		return sc.next().toCharArray();
	}

	static int kaijo(int n) {
		if (n == 0 || n == 1) {
			return 1;
		} else {
			return n * kaijo(n - 1);
		}
	}

	static int fib(int n) {
		return (n == 1 || n == 0) ? n : fib(n - 2) + fib(n - 1);
	}

	static long lcm(long m, long n) {

		return m * n / gcd(m, n);
	}

	static int lcm(int m, int n) {

		return m * n / gcd(m, n);
	}

	static long gcd(long a, long b) {
		return (b == 0) ? a : gcd(b, a % b);
	}

	static int gcd(int a, int b) {
		return (b == 0) ? a : gcd(b, a % b);
	}

	static void out(String info) {
		System.out.println(info);
	}

	static void out(int info) {
		System.out.println(info);
	}

	static void out(double info) {
		System.out.println(info);
	}

	static void out(long info) {
		System.out.println(info);
	}

	static void out(char info) {
		System.out.println(info);
	}

	static void out(Object obj) {
		System.out.println(obj.toString());
	}

	static void outn(String info) {
		System.out.print(info);
	}

	static void outn(int info) {
		System.out.print(info);
	}

	static void outn(double info) {
		System.out.print(info);
	}

	static void outn(long info) {
		System.out.print(info);
	}

	static void outn(char info) {
		System.out.print(info);
	}

	static double max(double d, double e) {
		return Math.max(d, e);
	}

	static long max(long a, long b) {
		return Math.max(a, b);
	}

	static long min(long d, long e) {
		return Math.min(d, e);
	}

	static int min(int a, int b) {
		return (int) Math.min(a, b);
	}
}

class XY {
	int h;
	int c;

	XY(int h, int c) {
		this.h = h;
		this.c = c;
	}
}


Measured memory_bytes: 41896
#include <bits/stdc++.h>
using namespace std;
long long inf = 10000000000, N, W, val[101], weight[101], dp[101][100001];

int main(){
  cin >> N >> W;
  int total;
  for(int i = 1; i <= N; i++){
    cin >> weight[i] >> val[i];
    total += val[i];
  }

  for(int v = 0; v <= total; v++)
    dp[0][v] = inf;

  for(int i = 0; i <= N; i++)
    dp[i][0] = 0;

  for(int i = 1; i <= N; i++){
    for(int v = 1; v <= total; v++){
      if(val[i] <= v){
        dp[i][v] = min(dp[i-1][v], dp[i-1][v - val[i]] + weight[i]);
      }
      else{
        dp[i][v] = dp[i-1][v];
      }
    }
  }
  long long maximum = 0;

  for(int v = 0; v <= total; v++){
    for(int i = 0; i <= N; i++){
      if(dp[i][v] <= W){
        maximum = v;
        break;
      }
    }
  }
  cout << maximum << endl;
}

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

int main()
{
    vector<int> v1, v2, v3;
    int n;
    cin >> n;
    while (n--)
    {
        int x;
        cin >> x;
        v1.push_back(x);
    }
    int m;
    cin >> m;
    while (m--)
    {
        int x;
        cin >> x;
        v2.push_back(x);
    }
    set_difference(v1.begin(), v1.end(), v2.begin(), v2.end(), back_inserter(v3));
    int i;
    for (i = 0; i < v3.size(); i++)
    {
        cout << v3[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 6040
import scala.io.StdIn

object Main extends App {
  
   val s1 = StdIn.readLine()
   val s2 = StdIn.readLine()
   println(
      if(s1(0) == s2(2) &&
        s1(2) == s2(0) &&
        s1(1) == s2(1)) "YES"
      else "NO"
   )
}


Measured memory_bytes: 27308
import sys

officalhouse = [0]*4*3*10

n = int( sys.stdin.readline() )
for i in range( n ):
	b, f, r, v = [ int( val ) for val in sys.stdin.readline().split( " " ) ]
	bfr = (b-1)*30+(f-1)*10+(r-1)
	officalhouse[bfr] = officalhouse[bfr] + v;
	
output = []
for b in range( 4 ):
	for f in range( 3 ):
		for r in range( 10 ):
			output.append( " {:d}".format( officalhouse[ b*30 + f*10 + r ] ) )
		output.append( "\n" )
	if b < 3:
		output.append( "####################\n" )

print( "".join( output ), end="" )

Measured memory_bytes: 6724
/**
 *    author:  morato
 *    created: 25.08.2020 20:00:17
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a, b, c;
  cin >> a >> b >> c;
  int f = 0;
  if (a == b) {
    f = (c != a);
  } else {
    if (b == c) {
      f = (c != a);
    } else {
      if (a == c) {
        f = (c != b);
      }
    }
  }
  cout << (f ? "Yes\n" : "No\n");
  return 0;
}

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

typedef long long   ll;
const ll mod = 1e9 + 7;

#define speedup_IO      ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define forn(i,a,n)     for(ll i = a; i < n; i++)
#define ford(i,n,a)     for(ll i = n-1; i >= a; i--)
#define pb              push_back
#define lb              lower_bound
#define ub              upper_bound
#define pll             pair<ll,ll>
#define all(a)          (a).begin(),(a).end()
#define reset(a,x)      memset(a,x,sizeof(a))

ll mypow(ll base, ll exp) {ll res = 1; while (exp) {if (exp & 1) res = (res * base) % mod; exp >>= 1, base = (base * base) % mod;} return res;}
ll gcd(ll a, ll b)  { return b ? gcd(b, a % b) : a;            }
ll mult(ll a, ll b) { return ((a % mod) * (b % mod)) % mod;    }
ll add(ll a, ll b)  { return (a % mod + b % mod) % mod;        }
ll sub(ll a, ll b)  { return (a % mod + mod - b % mod) % mod;  }

const ll inf = 1e18;
const int nax = 1e5 + 5;

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

	set<ll>s;
	ll a;
	forn(i,0,n)
	{
		cin>>a;
		s.insert(a);
	}

	if((ll)s.size() == n)
	{
		cout<<"YES";
	}
	else{
		cout<<"NO";
	}

	return 0;
}

Measured memory_bytes: 9600
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

int main(){
  int n;
  int s,i,h;
  int cnt = 0;

  scanf("%d %d", &h, &n);

  for(i = 0;i < n;i++){
    scanf("%d", &s);
    cnt += s;
  }

  if(h <= cnt) printf("Yes\n");

  else printf("No\n");

  return 0;
}

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

int main()
{
	long long num;
	cin>>num;
	int tail=0,a,sum=0;
	bool flag=0;
	for(tail=0; num; tail++){
		a=num%10;
		sum+=a;
		num/=10;
		if(a!=9)flag=1;
	}
	if(!flag){
		cout<<9*tail<<endl;
	}
	else
		if(tail!=1){
			int ans=9*(tail-1)+(a-1);
			ans=max(ans,sum);
			printf("%d\n",ans);
		}
		else{
			cout<<a<<endl;
		}
    return 0;
}


Measured memory_bytes: 256
A = [list(map(int, input().split())) for i in range(3)]
n = int(input())
for k in range(n):
    b = int(input())
    for i in range(3):
        for j in range(3):
            if A[i][j] == b:
                A[i][j] = 0

bingo = [
    [[0, 0], [0, 1], [0, 2]],
    [[1, 0], [1, 1], [1, 2]],
    [[2, 0], [2, 1], [2, 2]],
    [[0, 0], [1, 0], [2, 0]],
    [[0, 1], [1, 1], [2, 1]],
    [[0, 2], [1, 2], [2, 2]],
    [[0, 0], [1, 1], [2, 2]],
    [[0, 2], [1, 1], [2, 0]]]

for B in bingo:
    for b in B:
        if A[b[0]][b[1]] != 0:
            break
    else:
        print('Yes')
        break
else:
    print('No')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ll long long int
#define endl "\n"
using namespace std;

void hehe()
{
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll x = max({a, b});
    ll y = max({c, d});
    ll ans = LLONG_MIN;
    if (a <= 0 && b >= 0)
    {
        ans = max(0ll, ans);
    }
    if (c <= 0 && d >= 0)
    {
        ans = max(0ll, ans);
    }
    ans = max({ans, a * c, a * d, b * c, b * d});
    cout << ans;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t = 1;
    // cin >> t;
    while (t--)
    {
        hehe();
    }

    return 0;
}


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

#define ms(s, n) memset(s, n, sizeof(s))
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define FORd(i, a, b) for (int i = (a) - 1; i >= (b); i--)
#define FORall(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define sz(a) int((a).size())
#define present(t, x) (t.find(x) != t.end())
#define all(a) (a).begin(), (a).end()
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define prec(n) fixed<<setprecision(n)
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<pi> vii;
const int MOD = (int) 1e9 + 7;
const int MOD2 = (int) 1e8 + 7;
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
const ld PI = acos((ld) -1);
const ld EPS = 1e-9;
inline ll gcd(ll a, ll b) {ll r; while (b) {r = a % b; a = b; b = r;} return a;}
inline ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
inline ll fpow(ll n, ll k, int p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n % p; n = n * n % p;} return r;}
template<class T> inline int chkmin(T& a, const T& val) {return val < a ? a = val, 1 : 0;}
template<class T> inline int chkmax(T& a, const T& val) {return a < val ? a = val, 1 : 0;}
inline ll isqrt(ll k) {ll r = sqrt(k) + 1; while (r * r > k) r--; return r;}
inline ll icbrt(ll k) {ll r = cbrt(k) + 1; while (r * r * r > k) r--; return r;}
inline void addmod(int& a, int val, int p = MOD) {if ((a = (a + val)) >= p) a -= p;}
inline void submod(int& a, int val, int p = MOD) {if ((a = (a - val)) < 0) a += p;}
inline int mult(int a, int b, int p = MOD) {return (ll) a * b % p;}
inline int inv(int a, int p = MOD) {return fpow(a, p - 2, p);}
inline int sign(ld x) {return x < -EPS ? -1 : x > +EPS;}
inline int sign(ld x, ld y) {return sign(x - y);}
#define db(x) cerr << #x << " = " << (x) << ", ";
#define endln cerr << "\n";

void solve() {
    string s; cin >> s;
    FORd(i, sz(s) + 1, 1) {
        int ok = 0;
        FOR(c, 0, 26) {
            int mx = 0;
            FOR(j, 0, i) {
                int mn = INF;
                FOR(k, j, sz(s)) if (s[k] == 'a' + c) {
                    chkmin(mn, abs(k - j));
                }
                chkmax(mx, mn);
            }
            if (mx <= sz(s) - i) {
                ok = 1;
                break;
            }
        }
        if (ok) {
            cout << sz(s) - i << "\n";
            return;
        }
    }
}

int main() {
    int JUDGE_ONLINE = 1;
    if (fopen("in.txt", "r")) {
        JUDGE_ONLINE = 0;
        assert(freopen("in.txt", "r", stdin));
        //assert(freopen("out.txt", "w", stdout));
    }
    else {
        ios_base::sync_with_stdio(0), cin.tie(0);
    }
    solve();
    if (!JUDGE_ONLINE) {
        //cout << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string.h>
#include <algorithm>
#include <cstring>
#include <math.h>
#define ll long long
using namespace std;
int main()
{
	string s;
	cin>>s;
	if(s.length()==6&&s[2]==s[3]&&s[4]==s[5])
	cout<<"Yes";
	else
	cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
const int N=10000;
int main()
{
    int n,m;
    while(~scanf("%d%d",&n,&m))
        printf("%d\n",(n-1)*(m-1));
        
    
    return 0;
}


Measured memory_bytes: 256
def solve(h):
    if h == 1:
        return 1
    else:
        return 2 * solve(h // 2) + 1


def main():
    h = int(input())
    res = solve(h)
    print(res)


def test():
    assert solve(2) == 3
    assert solve(4) == 7
    assert solve(1000000000000) == 1099511627775


if __name__ == "__main__":
    test()
    main()


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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//==================================

set<ll> st;

void dfs(ll x) {
    if (st.find(x) != st.end()) {
        return;
    }
    st.insert(x);

    int nd = 0;
    ll x_tmp = x;
    while (x_tmp > 0) {
        ++nd;
        x_tmp /= 10;
    }
    if (nd >= 11) return;

    int l = x % 10;
    if (l == 9) {
        dfs(10 * x + l - 1);
        dfs(10 * x + l);
    }
    else if (l == 0) {
        dfs(10 * x + l);
        dfs(10 * x + l + 1);
    }
    else {
        dfs(10 * x + l - 1);
        dfs(10 * x + l);
        dfs(10 * x + l + 1);
    }
}

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif

    int K;
    cin >> K;

    for (int i = 1; i <= 9; i++) {
        dfs(i);
    }

    cout << *next(st.begin(), K - 1) << endl;

    return 0;
}

Measured memory_bytes: 27580
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define All(V) v.begin(), v.end()
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD = 1e9+7, INF = 1e9;

int main()
{
  int n; cin >> n;
  vector<int> v(n);
  rep(i, n) cin >> v[i];
  int j = v[0], ans = 0;
  bool f = false;
  for(int i = 1; i < n; i++){
    if(j == 2) f = true;
    else {
      j = v[j-1];
      ans++;
    }
  }
  if(f)cout << ans+1 << endl;
  else cout << -1 << endl;
  system("pause");
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long a,b;
  cin>>a>>b;
  if(a<=0 && b>=0){
    cout<<"Zero"<<endl;
    return 0;
  }
  if(a<=0 && b<0 && (b-a+1)%2==1){
    cout<<"Negative"<<endl;
    return 0;
  }
  else{
    cout<<"Positive"<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
from itertools import product


def makelist(BIT):
    LIST, tmp = [], s[0]
    for si, bi in zip(s[1:], BIT):
        if bi == 1:
            LIST.append(tmp)
            tmp = si
        elif bi == 0:
            tmp = [t + sij for t, sij in zip(tmp, si)]
    else:
        LIST.append(tmp)
    return LIST


def solve(LIST):
    CNT, tmp = 0, [li[0] for li in LIST]
    if any(num > k for num in tmp):
        return h * w
    for j in range(1, w):
        cal = [t + li[j] for t, li in zip(tmp, LIST)]
        if any(num > k for num in cal):
            CNT += 1
            tmp = [li[j] for li in LIST]
        else:
            tmp = cal[:]
    return CNT


h, w, k = map(int, input().split())
s = [[int(sij) for sij in input()] for _ in range(h)]

ans = h * w
for bit in product([0, 1], repeat=(h - 1)):
    numlist = makelist(bit)
    ans = min(ans, solve(numlist) + sum(bit))
print(ans)


Measured memory_bytes: 76668
dances = input()
for i in range(len(dances)):
    if (i+1) % 2 == 0:
        if dances[i] not in ['L', 'U', 'D']:
            print('No')
            break
    else:
        if dances[i] not in ['R', 'U', 'D']:
            print('No')
            break
    
    if i+1 == len(dances):
        print('Yes')

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

int main() {
	int a, b, c, x;
	cin >> a >> b >> c >> x;
	int ans = 0;
	for (int i = 0;i <= a;i++) {
		for (int j = 0;j <= b;j++) {
			for (int k = 0;k <= c;k++) {
				if (500 * i + 100 * j + 50 * k == x)ans++;
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#define mod 1000000007
#define MN 1010

int a[MN], b[MN];

bool cmp(int a, int b) {return a > b;}

int main()
{
	int n, m; scanf("%d%d", &n, &m);
	
	for(int i = 1; i <= n; i++) scanf("%d", &a[i]);
	for(int j = 1; j <= m; j++) scanf("%d", &b[j]);

	std::sort(a + 1, a + n + 1, cmp);
	std::sort(b + 1, b + m + 1, cmp);
	
	for(int i = 1; i <= n; i++) if(a[i] == a[i - 1]) return 0 * puts("0");
	for(int j = 1; j <= m; j++) if(b[j] == b[j - 1]) return 0 * puts("0");
	
	int j = 0, k = 0;
	long long Ans = 1;
	int cnt = 0;
	for(int i = n * m; i >= 1; i--)
	{
		if(a[j + 1] == i && b[k + 1] == i) cnt += j + k, j++, k++;
		else if(a[j + 1] == i) 
		{
			if(!k) return 0 * puts("0");
			Ans = Ans * k % mod; cnt += k - 1; j++;
		}
		else if(b[k + 1] == i)
		{
			if(!j) return 0 * puts("0");
			Ans = Ans * j % mod; cnt += j - 1; k++;
		} 
		else
		{
			if(!cnt) return 0 * puts("0");
			Ans = Ans * cnt % mod; cnt--;
		}
	}
	printf("%lld\n", Ans);
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
#include <iomanip>
#include <utility>
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
using namespace std;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n;
    cin>>n;
    int a[n+5],nasu=1,sum=0;

    reps(i,n){
      cin>>a[i];
    }

    reps(i,n){
      if(a[i]!=nasu){
	sum++;
      }
      else{
	nasu++;
      }
    }

    if(sum==n){
      sum=-1;
    }
    cout<<sum<<'\n';
    return 0;
}


Measured memory_bytes: 1024
public class Main{
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
/*answer*/
    int n;
    double[] x, y;
    double d1, d2, d3, di, a;
    int i;

    n = sc.nextInt();
    x = new double[n];
    y = new double[n];

    for(i = 0;i < n;i++){
      x[i] = sc.nextDouble();
    }
    for(i = 0;i < n;i++){
      y[i] = sc.nextDouble();
    }

    d1 = 0.0;
    d2 = 0.0;
    d3 = 0.0;
    di = 0.0;
    for(i = 0;i < n;i++){
      a = Math.abs(x[i] - y[i]);
      d1 += a;
      d2 += a * a;
      d3 += a * a * a;
      if(di < a)di = a;
    }

    System.out.println(d1);
    System.out.println(Math.sqrt(d2));
    System.out.println(Math.cbrt(d3));
    System.out.println(di);


    sc.close();
  }
  public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  }
}

Measured memory_bytes: 21280
import heapq
N = int(input())
A = sorted(list(map(int,input().split())))
heap = []
for i in range(N):
    a = A[i]
    heapq.heappush(heap,(a,1))
while len(heap)>1:
    a,n1 = heapq.heappop(heap)
    b,n2 = heapq.heappop(heap)
    if b<=2*a:
        a += b
        heapq.heappush(heap,(a,n1+n2))
    else:
        a += b
        heapq.heappush(heap,(a,n2))
a,n = heapq.heappop(heap)
print(n)

Measured memory_bytes: 87920
n = int(input())

xu = [[i for i in input().split()] for j in range(n)]

ans = 0

for i in range(n):
    if xu[i][1] == 'JPY':
        ans += int(xu[i][0])
    else:
        ans += 380000*float(xu[i][0])
        
print(ans)

Measured memory_bytes: 3060
import java.io.*;
import java.util.*;
public class Main {
    static int[] dp, a;
    static int m, L;
    public static void main(String[] args)throws IOException {
        Scanner sc = new Scanner(System.in);
        //BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        int a = sc.nextInt(), b =sc.nextInt(), c = sc.nextInt();
        boolean flag = a==b&&a==c;
        String ans = flag?"Yes":"No";
        System.out.println(ans);
    }
}

Measured memory_bytes: 21716
#define _DEBUG
#include "bits/stdc++.h"
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,a4,x,...) x
#define debug_1(x1) cout<<#x1<<": "<<x1<<endl
#define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl
#define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl
#define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl
#define debug_5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl
#ifdef _DEBUG
#define debug(...) CHOOSE((__VA_ARGS__,debug_5,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__)
#else
#define debug(...)
#endif
#define rep(index,num) for(int index=0;index<(int)num;index++)
#define rep1(index,num) for(int index=1;index<=(int)num;index++)
#define brep(index,num) for(int index=(int)num-1;index>=0;index--)
#define brep1(index,num) for(int index=(int)num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=(ll)1e+18+1;
int INF=1e+9+1;
int main(){
	ll a,b,c,d;
	scan(a>>b>>c>>d);
	prin(max({a*c,a*d,b*c,b*d}));
	return 0;
}


Measured memory_bytes: 3636
import java.util.*;

public class Main{
  public static void main(String...args){
    Scanner s = new Scanner(System.in);
    int n = s.nextInt(); int r = s.nextInt();
    if(n < 10){
      System.out.println(r + 100 * (10 - n));
    }else{
      System.out.println(r);
    }
  }
}

Measured memory_bytes: 23764
import sys


def input():
    return sys.stdin.readline().strip()


K, N = map(int, input().split())
A = list(map(int, input().split()))
Diff = []
for i in range(N - 1):
    Diff.append(A[i + 1] - A[i])
Diff.append(K - A[-1] + A[0])
print(K - max(Diff))


Measured memory_bytes: 26444
import sys
input = sys.stdin.readline
n,k = map(int,input().split())
edge = [[] for i in range(n)]
alledge = []
for i in range(n-1):
    a,b = map(int,input().split())
    edge[a-1].append(b-1)
    edge[b-1].append(a-1)
    alledge.append((a-1,b-1))

def f(x,y,c):
    global tmp
    c += 1
    for e in edge[x]:
        if e == y:
            continue
        if c > d:
            tmp +=1
        f(e,x,c)

sys.setrecursionlimit(4100000)

if k % 2 == 0:
    d = k//2
    ass = 2001
    for i in range(n):
        tmp = 0
        f(i,-1,0)
        ass = min(ass,tmp)
    print(ass)
else:
    d = (k-1)//2
    ass = 2001
    for e1 in alledge:
        tmp = 0
        f(e1[0],e1[1],0)
        f(e1[1],e1[0],0)
        ass = min(ass,tmp)
    print(ass)


Measured memory_bytes: 124380
n, k = map(int, input().split())
s = [[0] * k for _ in range(2 * k + 1)]
for _ in range(n):
    x, y, c = input().split()
    x, y = int(x), int(y)
    x -= (x // (2 * k)) * (2 * k)
    y -= (y // (2 * k)) * (2 * k)
    if x >= k and y >= k:
        x -= k
        y -= k
    elif y >= k:
        x += k
        y -= k
    if c == "B":
        if x >= k:
            x -= k
        else:
            x += k
    s[x + 1][y] += 1
for i in range(2 * k):
    for j in range(k):
        s[i + 1][j] += s[i][j]
ans = 0
for i in range(k):
    cnt = 0
    for j in range(k):
        cnt += (s[i + k][j] - s[i][j])
    ans = max(ans, cnt, n - cnt)
    for j in range(k):
        cnt -= (2 * (s[i + k][j] - s[i][j]))
        cnt += s[2 * k][j]
        ans = max(ans, cnt, n - cnt)
print(ans)

Measured memory_bytes: 24796
n = int(input())
c = [0]*4
for i in range(n):
    s = input()
    if s == "AC":
        c[0] += 1
    elif s == "WA":
        c[1] += 1
    elif s == "TLE":
        c[2] += 1
    elif s == "RE":
        c[3] += 1

print("AC x ", c[0])
print("WA x ", c[1])
print("TLE x ", c[2])
print("RE x ", c[3], end='')


Measured memory_bytes: 9212
#include <stdio.h>
#include <algorithm>
using namespace std;
struct segment_tree
{
    int seg[524288];
    segment_tree()
    {
        for (int i=0;i<262144;++i)
            seg[262144+i]=i?1000000000:0;
        for (int i=262144-1;i;--i)
            seg[i]=min(seg[i<<1],seg[(i<<1)^1]);
    }
    int query(int id,int il,int ir,int l,int r)
    {
        if (il>=l&&ir<=r)
            return seg[id];
        if (r<=il||l>=ir)
            return 1000000000;
        return min(query(id<<1,il,(il+ir)>>1,l,r),query((id<<1)^1,(il+ir)>>1,ir,l,r));
    }
    void update(int p,int v)
    {
        if (v>=seg[262144+p])
            return;
        seg[262144+p]=v;
        for (int id=(262144+p)>>1;id;id>>=1)
            seg[id]=min(seg[id<<1],seg[(id<<1)^1]);
    }
};
segment_tree orig,added;
int p[200001];
pair<int,int> q[200001];
bool cmp(pair<int,int> a,pair<int,int> b)
{
    return a.second<b.second;
}
int main()
{
    int n;
    scanf("%d",&n);
    int num1=0;
    for (int i=1;i<=n;++i)
    {
        int x;
        scanf("%d",&x);
        p[i]=p[i-1]+(x==0?1:-1);
        num1+=x;
    }
    int nq;
    scanf("%d",&nq);
    for (int i=1;i<=nq;++i)
        scanf("%d%d",&q[i].first,&q[i].second);
    sort(q+1,q+nq+1);
    int mindelta=0;
    for (int i=1;i<=nq;++i)
    {
        int s=q[i].first,e=q[i].second;
        int curv=min(orig.query(1,0,262144,0,s)+p[e]-p[s-1],added.query(1,0,262144,s,e+1)+p[e]);
        if (curv<mindelta)
            mindelta=curv;
        orig.update(e,curv);
        added.update(e,curv-p[e]);
    }
    printf("%d\n",mindelta+num1);
    return 0;
}


Measured memory_bytes: 6656
import java.util.HashMap;
import java.util.Scanner;

public class Main{
	public static void main(String args[]){
		
		HashMap<String, Integer> day = new HashMap<String, Integer>();
		day.put("SUN",7);
		day.put("MON",6);
		day.put("TUE",5);
		day.put("WED",4);
		day.put("THU",3);
		day.put("FRI",2);
		day.put("SAT",1);

		Scanner sc = new Scanner(System.in);
		System.out.println(day.get(sc.next()));
	}
}


Measured memory_bytes: 22608
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
typedef pair<LL, LL> pii;
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)

int n;
vector<int> g[101010];
int a, b;
LL c[101010];
int d[101010];
int ans[101010];
bool vis[101010];

int main(){
    cin >> n;
    LL ans2 = 0;
    REP(i, n - 1){
        cin >> a >> b;
        a--, b--;
        g[a].emplace_back(b);
        g[b].emplace_back(a);
    }
    LL maxnum = 0;
    REP(i, n){
        cin >> c[i];
        ans2 += c[i];
        maxnum = max(maxnum, c[i]);
    }
    ans2 -= maxnum;
    sort(c, c + n);
    reverse(c,c + n);

    int idx = 0;
    REP(i, n){
        if((int)g[i].size() == 1 && vis[i] == false){
            queue<int> q;
            q.push(i);
            while(!q.empty()){
                int p = q.front();
                q.pop();
                vis[p] = true;
                ans[p] = c[idx];
                idx++;
                REP(j, (int)g[p].size()){
                    if(vis[g[p][j]] == false){
                        q.push(g[p][j]);
                    }
                }
            }
        }
    }

    cout << ans2 << endl;
    REP(i, n){
        if(i)cout << " ";
        cout << ans[i];
    }
    cout << endl;
}

Measured memory_bytes: 3200
#include <iostream>
#include <string>
using namespace std;
int main(){
  int r;
  cin >> r;
  if(0 <= r && r < 1200) cout << "ABC" << endl;
  else if(1200 <= r && r < 2800) cout << "ARC" << endl;
  else cout << "AGC" << endl;
  return 0; 
}


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

typedef long long ll;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const ll INF = 1<<21;
// static const ll MOD = 1e9 + 7;

// bool compPair(const pair<int, int>& arg1, const pair<int, int>& arg2) {
//     return arg1.first > arg2.first;
// }

int main(void) {
    int x, y, z, k;
    cin >> x >> y >> z >> k;

    vector<ll> a(x);
    vector<ll> b(y);
    vector<ll> c(z);
    for(int ix=0;ix<x;ix++) {
        cin >> a.at(ix);
    }
    for(int iy=0;iy<y;iy++) {
        cin >> b.at(iy);
    }
    for(int iz=0;iz<z;iz++) {
        cin >> c.at(iz);
    }

    sort(a.begin(), a.end(), greater<ll>());
    sort(b.begin(), b.end(), greater<ll>());
    sort(c.begin(), c.end(), greater<ll>());

    vector<ll> ans;
    for(int ix=0;ix<x;ix++) {
        for(int iy=0;iy<y;iy++) {
            for(int iz=0;iz<z;iz++) {
                if((ix+1)*(iy+1)*(iz+1)<=3000) ans.push_back((ll)a.at(ix)+(ll)b.at(iy)+(ll)c.at(iz));
            }
        }
    }

    sort(ans.begin(), ans.end(), greater<ll>());

    for(int ik=0;ik<k;ik++) {
        cout << ans.at(ik) << endl;
    }

    return 0;
}


Measured memory_bytes: 1532