akhauriyash/Code-Regression huggingface dataset:
from itertools import product

n = int(input())

d = {}
for i in range(n):
  a = int(input())
  for _ in range(a):
    x, y = map(int, input().split())
    if i + 1 not in d:
      d[i + 1] = []
    d[i + 1].append((x, y))

ret = 0
for x in product((0, 1), repeat=n):
  ok = True
  for i in range(n):
    if x[i] == 0 or i + 1 not in d:
      continue
    for p, tf in d[i + 1]:
      if x[p - 1] != tf:
        ok = False
        break
    if not ok:
      break
  if ok:
    ret = max(ret, sum(x))

print(ret)

Measured memory_bytes: 9164
import sys
n=int(input())
s=[input() for i in range(n)]
t=[2*(i.count("("))-len(i) for i in s]
if sum(t)!=0:
    print("No")
    sys.exit()
st=[[t[i]] for i in range(n)]

for i in range(n):
    now,mi=0,0
    for j in s[i]:
        if j=="(":
            now+=1
        else:
            now-=1
        mi=min(mi,now)
    st[i].append(mi)
#st.sort(reverse=True,key=lambda z:z[1])
u,v,w=list(filter(lambda x:x[1]>=0,st)),list(filter(lambda x:x[1]<0 and x[0]>=0,st)),list(filter(lambda x:x[1]<0 and x[0]<0,st))
v.sort(reverse=True)
v.sort(reverse=True,key=lambda z:z[1])
w.sort(key=lambda z:z[0]-z[1],reverse=True)
lu=len(u)
lv=len(v)
now2=0
for i in range(n):
    if i<lu:
        now2+=u[i][0]
    elif i<lu+lv:
        if now2+v[i-lu][1]<0:
            print("No")
            break
        now2+=v[i-lu][0]
    else:
        #いや、間違ってるのここなんかーーい
        if now2+w[i-lu-lv][1]<0:
            print("No")
            break
        now2+=w[i-lu-lv][0]
else:
    print("Yes")

Measured memory_bytes: 332896
#include"bits/stdc++.h"
using namespace std;
int powf(int a)
{
	int s=1;
	for(int i=0;i<a;i++)
		s*=2;
	return s;
}
int main()
{
	int a,b,c,k;
	int sum=0,cmax;
	scanf("%d%d%d%d",&a,&b,&c,&k);
	cmax=max(max(a,b),c);
	sum=a+b+c-cmax+cmax*powf(k);
	printf("%d",sum);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
    #define fast {ios_base::sync_with_stdio(false);cin.tie(NULL);}
    #define pb push_back
    typedef long long int ll;
    using namespace std;
    int main(void){
    	fast;
    	ll n;
    	cin>>n;
    	string ans="";
    	while(n!=0){
    		n--;
    		char c=(char)(n%26+'a');
    		string add(1,c);
    		ans=add+ans;
    		n/=26;
    	}
    	cout<<ans<<endl;
    }


Measured memory_bytes: 3612
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int f[605][605];
int a[605],b[605];
int h[605],fc[605];
const int mod=1e9+7;
int main(){
	int n,k;
	scanf("%d%d",&n,&k);
	n*=2;
	for(int i=1;i<=k;i++){
		scanf("%d%d",&a[i],&b[i]);
		h[a[i]]=1;
		h[b[i]]=1;
	}
	fc[0]=1;
	for(int i=1;i<=n;i++)fc[i]=1ll*(i-1)*fc[i-2]%mod;
	for(int i=1;i<=n;i++)h[i]+=h[i-1];
	int ans=0;
	for(int i=1;i<=n;i++){
		for(int j=i+1;j<=n;j++){
			bool ok=1;
			for(int p=1;p<=k;p++)if((i<=a[p]&&a[p]<=j)^(i<=b[p]&&b[p]<=j))ok=0;
			if(!ok)continue;
			f[i][j]=fc[j-i+1-(h[j]-h[i-1])];
			for(int p=i+1;p<j;p++)f[i][j]=(f[i][j]-1ll*f[i][p]*fc[j-p-(h[j]-h[p])]%mod+mod)%mod;
			ans=(ans+1ll*f[i][j]*fc[n-2*k-(j-i+1-(h[j]-h[i-1]))])%mod;
			// printf("%d %d %d %d\n",i,j,f[i][j],ans);
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 1536
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
)

const Inf = math.MaxInt32

type Edge struct {
	From int
	To   int
	Cost int
}

func main() {
	N, M, P := ReadInt(), ReadInt(), ReadInt()
	edges := make([]Edge, M)
	to := make([][]int, N)
	from := make([][]int, N)
	for i := 0; i < M; i++ {
		a, b, c := ReadInt(), ReadInt(), ReadInt()
		a--
		b--
		edges[i] = Edge{From: a, To: b, Cost: P - c}
		to[a] = append(to[a], b)
		from[b] = append(from[b], a)
	}

	reachableFromStart := make([]bool, N)
	var dfs func(v int)
	dfs = func(v int) {
		if reachableFromStart[v] {
			return
		}
		reachableFromStart[v] = true
		for _, t := range to[v] {
			dfs(t)
		}
	}
	dfs(0)

	reachableToGoal := make([]bool, N)
	var rdfs func(v int)
	rdfs = func(v int) {
		if reachableToGoal[v] {
			return
		}
		reachableToGoal[v] = true
		for _, t := range from[v] {
			rdfs(t)
		}
	}
	rdfs(N - 1)

	ok := make([]bool, N)
	for i := 0; i < N; i++ {
		ok[i] = reachableFromStart[i] && reachableToGoal[i]
	}

	// bellman-ford
	d := make([]int, N)
	for i := 0; i < N; i++ {
		d[i] = Inf
	}
	d[0] = 0
	step := 0
	for {
		update := false
		for i := 0; i < M; i++ {
			edge := edges[i]
			if !ok[edge.From] || !ok[edge.To] {
				continue
			}
			newD := d[edge.From] + edge.Cost
			if newD < d[edge.To] {
				update = true
				d[edge.To] = newD
			}
		}
		step++
		if step > N {
			fmt.Println(-1)
			return
		}
		if !update {
			break
		}
	}

	ans := -d[N-1]
	if ans < 0 {
		ans = 0
	}
	fmt.Println(ans)
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int) { Scan(&i); return }


Measured memory_bytes: 2764
import java.math.*;
import java.io.*;
import java.util.*;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner(System.in);
		int t = 1;
		while (t-->0) {
		    long x = sc.nextLong();
		    long ans = 1000L*(x/500);
		    x%=500;
		    ans+=(5*(x/5));
		    System.out.println(ans);
		}
	}
	static ArrayList<Integer> key;
	static int n1;
	static void insert(int key1){
		key.add(key1);
		n1++;
		swim(n1);
	}
	static void swim(int k){
		while (k>1 && less(k/2, k)) {
			swap(k/2, k);
			k/=2;
		}
	}
	static int deleteMax(){
		int max = key.get(1);
		key.set(1,key.get(n1--));
		sink(1);
		key.remove(n1+1);
		return max;
	}
	static void sink(int k){
		while (2*k<=n1) {
			int j = 2*k;
			if (j<n1 && less(j,j+1)) {
				j++;
			}
			if (!less(k, j)) {
				break;
			}
			swap(k,j);
			k=j;
		}
	}
	static boolean less(int a, int b){
		return key.get(a)<key.get(b);
	}
	static void swap(int a, int b){
		int c=key.get(a);
		key.set(a,key.get(b));
		key.set(b,c);
	}
	static String getit(String s, String b){
	    StringBuilder temp=new StringBuilder(" ");
        temp.append(s);
        temp.append("#");
        temp.append(b);
	    int n = temp.length()-1;
	    String p = temp.toString();
	    int[] pi = new int[n+1];
	    pi[0] = -1;
	    int k = -1;
	    for (int i=1;i<=n ;i++ ){
	        while(k>=0 && p.charAt(k+1)!=p.charAt(i)) k = pi[k];
	        pi[i] = ++k;
	    } 
	    return s.substring(1,pi[n]);
	}
	static class Query {
		int x1, x2, y, id;
		public Query(int c, int d, int e, int a){
			x1 = c;
			x2 = d;
			y = e;
			id = a;
		}
	}
	static class Compare1 implements Comparator<Query>{
		@Override
		public int compare(Query q1, Query q2){
			if(q1.x2==q2.x2) return q1.x1-q2.x1;
			return q1.x2-q2.x2;
		}
	}
	static class Pair implements Comparable<Pair>{
		int a, b;
		public Pair(int c, int d){
			a = c;
			b = d;
		}
		public int compareTo(Pair p){
		    return a-p.a;
		}
	}
	static class FastScanner {
		BufferedReader br;
		StringTokenizer st;
		FastScanner(File f) {
			try {
				br = new BufferedReader(new FileReader(f));
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			}
		}
		FastScanner(InputStream f) {
			br = new BufferedReader(new InputStreamReader(f));
		}
		String nextLine() {
			try {
				return br.readLine();
			} catch (IOException e) {
				return null;
			}
		}
		String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}
		int nextInt() {
			return Integer.parseInt(next());
		}
		long nextLong() {
			return Long.parseLong(next());
		}
		double nextDouble() {
			return Double.parseDouble(next());
		}
	}
}

Measured memory_bytes: 22612
#include <algorithm>
#include <climits>
#include <cmath>
#include <csignal>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

using ll = long long;
using namespace std;

int main() {
    double n = 0;
    cin >> n;
    if ((int)n%2 == 0) {
        cout << 0.5 << endl;
    }
    else {
        cout << fixed;
        cout << setprecision(10) << (n-(int)n/2)/n << endl;
    }
    return 0;
}


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

using namespace std;

typedef long long ll;

int main()
{
  int n;
  cin >> n;
  vector<int> table(9);
  fill(table.begin(), table.end(), 0);

  for(int i = 0; i < n; i++)
  {
	int v;
	cin >> v;
	v = min(v, 3200);
	table[v / 400]++;
  }

  int mn = 0, mx = 0;
  for(int i = 0; i < 8; i++)
  {
	if(table[i] > 0)
	{
	  mn++;
	  mx++;
	}
  }
  
  mx = mx + table[8];
  if(mn == 0)
  {
	mn = 1;
  }
  
  cout << mn << " " << mx << endl;
  
  return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(N: int, D: int):
    from math import ceil
    return ceil(N / (2 * D + 1))


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    D = int(next(tokens))  # type: int
    print(solve(N, D))

if __name__ == '__main__':
    main()


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

bool comparing(pair<int,int>a,pair<int,int>b){
	if(a.second != b.second){
		return a.second < b.second;
	}
	else{
		return a.first < b.first;
	}
}

int main(){
	int N,M;
	cin>>N>>M;
	priority_queue<int>q;
	vector<pair<int,int> >arr;
	pair<int,int>tmp;
	for(int i=0;i<N;++i){
		cin>>tmp.first>>tmp.second;
		arr.push_back(tmp);
	}
	sort(arr.begin(),arr.end());
	/*
	for(int i=0;i<N;++i){
		cout<<arr[i].first<<" "<<arr[i].second<<endl;
	}
	*/
	int index = 0;
	long ans = 0;
	for(int i=1;i<=M;++i){
		while(arr[index].first<=i && index<N){
			q.push(arr[index].second);
			index++;
		}
		if(!q.empty()){
			ans += q.top();
			q.pop();
		}
	}
	cout<<ans<<endl;
}


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

/*int rec(int arr[], int n, int mem[])
{
  	if(n<=0)
    	return INT_MAX;
    if(n==1)
      	return 0;
  	if(mem[0]!=-1)
      	return mem[0];
    int a=rec(arr+1,n-1,mem+1);
    if(a!=INT_MAX)
    	a+=abs(arr[0]-arr[1]);
  	int b=rec(arr+2,n-2,mem+2);
  	if(b!=INT_MAX)
  		b+=abs(arr[0]-arr[2]);
  	mem[0]=min(a,b);
  	return mem[0];
}*/

int main(){
	int n;
  	cin>>n;
  	int arr[n],dp[n];/*mem[n];*/
  	for(int i=0;i<n;i++)
      	cin>>arr[i];
  
  	/*for(int i=0;i<n;i++)
      	mem[i]=-1;
 	cout<<rec(arr,n,mem)<<endl;*/
  	
  	dp[0]=0;
  	dp[1]=abs(arr[1]-arr[0]);
  	for(int i=2;i<n;i++)
    {
      	int a=abs(arr[i]-arr[i-1])+dp[i-1];
      	int b=abs(arr[i]-arr[i-2])+dp[i-2];
   		dp[i]=min(a,b);
    }
    cout<<dp[n-1]<<endl;
}

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

int main(){
    int a,b,c,x,y;
    int ans = 0;
    cin >> a >> b >> c >> x >> y;
    if(a+b>=2*c){
        if(x>y){
            ans = min(c*2*x,c*y*2 + (x-y)*a);
        }
        else{
            ans = min(c*2*y,c*x*2 + (y-x)*b);
        }
    }
    else{
        ans = a*x + b*y;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import scala.io.StdIn

object Main {
	def main(args: Array[String]): Unit = {
		val num = StdIn.readLine.split(" ").map(_.toInt)
		val H = num(0)
		val W = num(1)

		val whiteLine = "....................................................................................................".substring(0, W)

		val gridRows = (1 to H).foldLeft(Seq.empty[String]) { (seq, n) =>
			seq :+ StdIn.readLine
		}

		val grsReducedRows = gridRows.filter(_ != whiteLine)
		// 数字を使ってないが、うまくかけるのか？

		val whiteColomns = grsReducedRows.foldLeft(whiteLine.toCharArray) { (res, str) =>
			res.zip(str.toCharArray).map { tuple =>
				if (tuple._1 == '.' && tuple._2 == '.') '.' else '#'
			}
		}

		grsReducedRows.foreach { str =>
			val resultRow = str.zip(whiteColomns).filter(_._2 == '#').map(_._1).foldLeft("")(_ + _)
			println(resultRow)
		}
	}
}

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

using namespace std;

struct distandindex{
    int dist;
    int index;
};

bool cmp(const distandindex &a, const distandindex &b){
    return a.dist > b.dist;
}

int main(){
    int N, M;
    cin >> N >> M;
    vector<int> x(M);
    for(int i=0;i<M;i++){
        cin >> x[i];
    }
    std::sort(x.begin(), x.end());

    if(M == 1 || N >= M){
        cout << 0 << endl;
        return 0;
    }
    if(N == 1){
        cout << x[M-1] - x[0] << endl;
        return 0;
    }
    vector<distandindex> kaisa(M-1);
    for(int i=0; i<M-1;i++){
        distandindex d = {x[i+1]-x[i], i};
        kaisa[i] = d;
    }
    std::sort(kaisa.begin(), kaisa.end(), cmp);

    vector<int> index(N-1);
    for(int i=0;i<N-1;i++){
        index[i] = kaisa[i].index;
    }
    int start = 0;
    int sum = 0;
    for(int i = 0; i<N-1;i++){
        sum += x[index[i]] - x[start];
        start = index[i] + 1;
    }
    sum += x[M-1] - x[start];
    cout << sum << endl;

    return 0;
}



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

int main() {
  int N, M, sum, x;
  cin >> N;
  M = N;
  for (int i = 0; i < 8  ; i++) {
    x = M%10; // 最小の桁の数
    sum += x; // 格桁の和
    M /= 10; // 最小の桁を除く
  }
    if (N % sum == 0) {
      cout << "Yes" << endl;
    }
  else {cout << "No" << endl;
       }
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const double PI=acos(-1.0);
#define t1(x)             cerr<<#x<<"="<<x<<endl
#define t2(x, y)          cerr<<#x<<"="<<x<<" "<<#y<<"="<<y<<endl
#define t3(x, y, z)       cerr<<#x<<"=" <<x<<" "<<#y<<"="<<y<<" "<<#z<<"="<<z<<endl
#define t4(a,b,c,d)       cerr<<#a<<"="<<a<<" "<<#b<<"="<<b<<" "<<#c<<"="<<c<<" "<<#d<<"="<<d<<endl
#define t5(a,b,c,d,e)     cerr<<#a<<"="<<a<<" "<<#b<<"="<<b<<" "<<#c<<"="<<c<<" "<<#d<<"="<<d<<" "<<#e<<"="<<e<<endl
#define t6(a,b,c,d,e,f)   cerr<<#a<<"="<<a<<" "<<#b<<"="<<b<<" "<<#c<<"="<<c<<" "<<#d<<"="<<d<<" "<<#e<<"="<<e<<" "<<#f<<"="<<f<<endl
#define GET_MACRO(_1,_2,_3,_4,_5,_6,NAME,...) NAME
#define t(...) GET_MACRO(__VA_ARGS__,t6,t5, t4, t3, t2, t1)(__VA_ARGS__)
#define __ freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define fastio() ios::sync_with_stdio(0);cin.tie(0)
#define MEMS(x,t) memset(x,t,sizeof(x));
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
/*-------------------------------------------------------------------------------------------------------------------------------------*/
#define MOD 1000000007
#define endl "\n" 
#define int long long
#define inf 1e18
#define ld long double
/*-------------------------------------------------------------------------------------------------------------------------------------*/

bool check(string s)
{
	int n=s.length();
	for(int i=0;i<n;i++){
		if(s[i]!=s[n-1-i])return false;
	}	
	return true;
}
int32_t main()
{
	fastio();
	string s;
	cin>>s;
	int n=s.length();
	int flag=check(s)&check(s.substr(0,n/2))&check(s.substr((n+1)/2,n/2));
	if(flag)
	{
		cout<<"Yes\n";
	}
	else cout<<"No\n";
}


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

#define times(n, i) uptil(0, n, i)
#define upto(f, t, i) for(auto _##i = (t), i = decltype(_##i)(f) poi i <= _##i poi i++)
#define uptil(f, t, i) for(auto _##i = (t), i = decltype(_##i)(f) poi i < _##i poi i++)
#define downto(f, t, i) for(auto i = (f), _##i = decltype(i)(t) poi i >= _##i poi i--)
#define downtil(f, t, i) for(auto i = (f), _##i = decltype(i)(t) poi i > _##i poi i--)

#define unless(c) if(!(c))
#define until(c) while(!(c))
#define loop while(true)

#define poi ;
#define poipoi << "\n"

using namespace std;

int main(){
    int a, b poi
    while(cin >> a >> b){
        int sum = a + b, i = 0 poi
        while(sum){
            sum /= 10 poi
            i++ poi
        }
        cout << i poipoi poi
    }
    return 0 poi
}

Measured memory_bytes: 1152
#include <stdio.h>
#include <stdlib.h>
int comp(const void *a, const void *b){
	return *(int *)a-*(int *)b;
}
int main(){
	int N;
	int M;
	int X[100000];
	scanf("%d",&N);
	scanf("%d",&M);
	if(N>=M){
		printf("0");
		return 0;
	}
	int i;
	int Y[100000];
	for(i=0;i<M;i++){
		scanf("%d",&X[i]);
	}
	qsort(X,M,sizeof(int),comp);
	for(i=0;i<M-1;i++){
		Y[i]=X[i+1]-X[i];
	}
	qsort(Y,M-1,sizeof(int),comp);
	int ans;
	ans=X[M-1]-X[0];
	for(i=0;i<N-1;i++){
		ans=ans-Y[M-2-i];
	}
	printf("%d",ans);
}

Measured memory_bytes: 1396
#include <string>
#include <vector>
#include <iostream>

using namespace std;

bool compare(string S1, string S2)
{
	if (S1.size() != S2.size()) { return S1.size() > S2.size(); }

	return S1 > S2;
}

int main()
{
	int H, W;

	while (true)
	{
		cin >> W >> H;

		if (H == 0 && W == 0) { break; }

		vector<string> R(H);

		for (int i = 0; i < H; i++)
		{
			cin >> R[i];
		}

		vector<vector<string> > dp(H, vector<string>(W, ""));

		for (int i = 0; i < H; i++)
		{
			for (int j = 0; j < W; j++)
			{
				if (isdigit(R[i][j]))
				{
					if (R[i][j] != '0')
					{
						dp[i][j] = R[i][j];
					}

					if (i != 0)
					{
						if (R[i][j] != '0')
						{
							if (compare(dp[i - 1][j] + R[i][j], dp[i][j]))
							{
								dp[i][j] = dp[i - 1][j] + R[i][j];
							}
						}
						else
						{
							if (compare(dp[i - 1][j] + R[i][j], dp[i][j]) && dp[i - 1][j] != "")
							{
								dp[i][j] = dp[i - 1][j] + R[i][j];
							}
						}
					}

					if (j != 0)
					{
						if (R[i][j] != '0')
						{
							if (compare(dp[i][j - 1] + R[i][j], dp[i][j]))
							{
								dp[i][j] = dp[i][j - 1] + R[i][j];
							}
						}
						else
						{
							if (compare(dp[i][j - 1] + R[i][j], dp[i][j]) && dp[i][j - 1] != "")
							{
								dp[i][j] = dp[i][j - 1] + R[i][j];
							}
						}
					}
				}
			}
		}

		string ret = "";

		for (int i = 0; i < H; i++)
		{
			for (int j = 0; j < W; j++)
			{
				if (compare(dp[i][j], ret))
				{
					ret = dp[i][j];
				}
			}
		}

		cout << ret << endl;
	}

	return 0;
}

Measured memory_bytes: 3312
#z-algolithm

n = int(input())
s_ = input()
ans = 0
for i in range(n-2):
    l = 1 #1から
    r = 1
    s = s_[i:]
    z = [0]*(n-i)
    z[0] = n-i
    while l<n-i:
        while r<n-i and s[r] == s[r-l] : #r<n
            r += 1
        if r == l:
            r+=1;l+=1;continue
        z[l] = r-l
        k = 1
        while l+k<r and z[k]<r-l-k:
            z[l+k] = z[k]
            k+=1
        l = l+k
    for i in range(n-i):###ここで処理
        z[i] = min(z[i],i)
    ans = max(ans,max(z))
print(ans)

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

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

long long MOD = 10000000000 + 7;

int main(){
  cout << setprecision(10);
  ll K; int N; cin >> K >> N;


  ll max_val = 0;

  vector<ll> v(N);
  for(int i = 0; i < N; i++){
    cin >> v[i];
  }

  for(int i = 1; i < N; i++){
    max_val = max(max_val, abs(v[i] - v[i-1]));
  }

  max_val = max(max_val, v[0] + K - v[N-1]);

  cout << K - max_val << endl;
}



Measured memory_bytes: 4840
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill(0).map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill(0).map(x=>"+r+")";return eval(r);}
function upper_bound(d,a,b,e){for(var c;1<b-a;)d[c=0|(a+b)/2]<=e?a=c:b=c;return d[a]<=e?b:a};

console.log(main());
function main(){
  var n = o.a();
  var a = o.r(n);
  var ans = [1];
  for(var i = 0; i < n; i++){
    var t = -a[i];
    var l = upper_bound(ans,0,ans.length,t);
    ans[l] = t;
  }
  return ans.length;
}

Measured memory_bytes: 32008
#include<stdio.h>
 
int main(void)
{
int n,a,i,min=1000,max=0;
scanf("%d",&n);

for(i=0; i<n;i++){
scanf("%d",&a);
if(a<min)min=a; 
if(a>max)max=a;
}
 printf("%d\n",max-min);
 
 
return 0;
}

Measured memory_bytes: 128
n = int(input())
a = list(map(int, input().split()))

s = 0
ss = 0
for i in range(n):
    j = n - i - 1
    s += (a[j] * ss % (10**9 + 7))
    s %= (10**9 + 7)
    ss += a[j]

print(s)


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

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

ll n,a,b,maxd[N];
vector<int> G[N];
map<ull,ll> S;
ull A[N];

int get_maxd(int x,int d){
  int res=d;
  rep(i,G[x].size())
    res=max(res,get_maxd(G[x][i],d+1));
  return maxd[x]=res;
}

P dfs(int x,int d){
  ull res1=0;
  int res2=d;
  
  rep(i,G[x].size()){
    P r=dfs(G[x][i],d+1);
    res1+=r.first*A[maxd[x]-r.second];
    res2=max(res2,r.second);
  }
  res1+=A[res2-d];
  
  if(S.count(res1))S[res1]++;
  else S[res1]=1;
  
  return P(res1,res2);
}

int main(){
  cin>>n;

  rep(i,n-1){
    cin>>a>>b;
    G[a-1].push_back(b-1);
  }
  
  A[0]=1;
  for(int i=1;i<N;i++)A[i]=A[i-1]*M;
  
  get_maxd(0,0);
  
  dfs(0,0);

  ll ans=0;
  
  map<ull,ll>::iterator ite=S.begin();
  
  while(ite!=S.end()){
    if((*ite).second>=2)
      ans+=(*ite).second*((*ite).second-1)/2;
    ite++;
  }
  
  cout<<ans<<endl;
  
  return 0;
}

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

using namespace std;
using ll = long long;
using ld = long double;

int main() {
    int N, K;
    cin >> N >> K;

    if(N % K == 0){
        cout << 0 << endl;
    } else{
        cout << 1 << endl;
    }

    return 0;
}

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

using namespace std;
using   ll=long long;

#define fast        	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

#define endl        	"\n"
#define pb          	push_back
#define mp          	make_pair
#define F           	first
#define S           	second
#define int             long long int
#define pll				pair<int , int>

#define ALL(v)      	v.begin(),v.end()
#define ALLR(v)     	v.rbegin(),v.rend()
#define pii         	3.14159265358979323
#define inf     		LLONG_MAX
#define ones(x)     	__builtin_popcount(x)
#define fill(a,b)   	memset(a,b,sizeof(a))
#define mod 			1000000007
#define hell            998244353 

ll mod_pow(ll a,ll b,ll m) 
{
    ll res = 1;
    while(b)	
    {
        if(b&1) 	
        {
        	res=(res*a) % m;
        }
        a=(a*a) % m;
        b>>=1;
    }
    return res;
}

ll mod_inverse(ll a) 
{
	return mod_pow(a , mod-2 , mod);
}

void solve()
{
	int a , b;
	
	cin >> a >> b;
	
	cout << 2*b - a;
}

signed main() {
    fast;
    
    int t = 1;
    
	//cin >> t;
    
    while(t--) {
        solve();
    }
 
    return 0;
}


Measured memory_bytes: 3564
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
typedef pair<int, int> ii;
vector<int> adjlist[200000];
ii furthestnode(int v, int p) {
    ii ans = ii(v, 0);
    for (int i: adjlist[v]) {
        if (i == p) continue;
        ii k = furthestnode(i, v);
        if (k.second + 1 > ans.second) ans = ii(k.first, k.second + 1);
    }
    return ans;
}
int main() {
    int N, a, b;
    scanf("%d", &N);
    for (int i = 1; i < N; ++i) {
        scanf("%d %d", &a, &b);
        adjlist[a - 1].push_back(b - 1);
        adjlist[b - 1].push_back(a - 1);
    }
    int diam = furthestnode(furthestnode(0, -1).first, -1).second + 1;
    if (diam % 3 == 2) printf("Second");
    else printf("First");
    return 0;
}

Measured memory_bytes: 23680
<?php /*atcoder.php*/

$at = new Atcoder();
$at->main();
unset($at);

class Atcoder{
	private function lineIn(){
		$buf = fgets(STDIN);
		return $this->killNewLine($buf);
	}
	private function killNewLine($buf = null){
		$buf = str_replace("\r\n", "", $buf);
		$buf = str_replace("\n", "", $buf);
		$buf = str_replace("\r", "", $buf);
		return $buf;
	}

	public function main(){
		$n = $this->lineIn();
		$h = $this->lineIn();
		$w = $this->lineIn();
	
		$af = range(1, $n);
		rsort($af);

		$ans = $af[($h - 1)] * $af[($w - 1)];

		echo $ans . "\n";

	}
}
?>

Measured memory_bytes: 4728
#include <bits/stdc++.h>
using namespace std;
using ll = long long; 
int main() {
    ll s;
    cin >> s;
  	int l=0;
    ll si;
    ll ans = 0;
  	for(ll k=s; k>0; k/=10){
      l++;
    }
    for(int i=0; i<(1<<l-1);i++){
        si = s;
        int jp = 0;
        for(int j=0; j<l-1;j++){
            if(i&(1<<j)){
                ans += (si % (ll)pow(10,j+1-jp));
                si = (si / (ll)pow(10,j+1-jp));
                jp = j+1;
            }
        }
      	ans += si;
      
    }
  	cout<<ans<<endl;

} 

Measured memory_bytes: 4076
#include "bits/stdc++.h"
#include "atcoder/all"
using namespace atcoder;
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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; }

class union_find {
    private:
        vector<int> par;
        vector<int> ran;
        vector<ll> size;
    public:
        union_find(int n);
        int find(int x);
        void unite(int x, int y);
        bool same(int x, int y);
        ll show_size(int x);
};

union_find::union_find(int n){
    par.resize(n);
    ran.resize(n);
    size.resize(n);
    rep(i,n) par[i] = i;
    rep(i,n) ran[i] = 0;
    rep(i,n) size[i] = 1;
};

int union_find::find(int x) {
    if(par[x] == x) return x;
    else return par[x] = find(par[x]);
};

void union_find::unite(int x, int y) {
    x = find(x);
    y = find(y);
    if(x == y) return;
    ll t = show_size(x)+show_size(y);
    size[x] = size[y] = t;
    if(ran[x] < ran[y]){
        par[x] = y;
        //size[y] += size[x];
    }
    else{
        par[y] = x;
        //size[x] += size[y];
        if(ran[x] == ran[y]) ran[x]++;
    }
};

ll union_find::show_size(int x) {
    if(par[x] == x) return size[x];
    return show_size(par[x] = find(par[x]));
}

bool union_find::same(int x, int y) {
    return (find(x) == find(y));
};

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	union_find uf(n);
	int ans = n-1;
	rep(i,m){
		int a, b;
		cin >> a >> b;
		--a; --b;
		if(!uf.same(a, b)) --ans;
		uf.unite(a, b);
	}
	cout << ans << endl;
	return 0;
}

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

n = int(input())
xx = list([i, x] for i, x in enumerate(map(int, input().split())))
xx.sort(key=lambda x: x[1])

mid1 = xx[n // 2][1]
mid2 = xx[n // 2 - 1][1]
for i in range(n // 2):
    xx[i][1] = mid1
for i in range(n // 2, n):
    xx[i][1] = mid2

xx.sort()
print('\n'.join(str(x[1]) for x in xx))


Measured memory_bytes: 55492
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vs = vector<string>;
using vll = vector<long long>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
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 (b<a) {a=b; return 1;} return 0;}

vector<long long> enum_div(long long n) {
    vector<long long> res;
    for (long long i = 1; i*i <= n; i++) {
        if (n % i == 0) {
            res.push_back(i);
            if (i*i != n) {
                res.push_back(n/i);
            }
        }
    }
    sort(res.begin(), res.end());
    return res;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    ll n;
    cin >> n;

    auto d1 = enum_div(n-1);
    auto d2 = enum_div(n);

    int ans = d1.size() - 1;
    for (auto x : d2) {
        if (x == 1) continue;
        ll m = n;
        while (m%x == 0) {
            m /= x;
        }
        if (m % x == 1) ans++;
    }
    cout << ans << endl;
    
}

Measured memory_bytes: 384
A,B,K = map(int,input().split())

Z = []
for i in range(K):
    Z.append(A)
    A += 1
    if A > B:
        break
    
for i in range(K):
    Z.append(B)
    B -= 1
    if B < A:
        break

S = (set(Z))
for i in sorted(S):
    print(i)

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

int main() {
  int a,b;
  cin >> a >> b;
   
  int seki;
  seki = a * b;
  
  if ( seki % 2 == 0) {
    cout << "Even" << endl;
  }
  else {
    cout << "Odd" << endl;
  }
}

Measured memory_bytes: 256
N = int(input())
S1 = input()
S2 = input()
p = 10 ** 9 + 7
dp = [0] * N
if S1[0] == S2[0]:
  dp[0] = 3
else:
  dp[0] = 6
for i in range(1, N):
  if S1[i] == S1[i - 1]:
    dp[i] = dp[i - 1]
  elif S1[i - 1] == S2[i - 1]:
    dp[i] = dp[i - 1] * 2 % p
  elif S1[i] == S2[i]:
    dp[i] = dp[i - 1]
  else:
    dp[i] = dp[i - 1] * 3 % p
print(dp[-1])

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define OP_IO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define fo(i,a,b) for(int i = a; i < b; i++)
#define foi(i,a,b) for(int i = a; i>=b; i--)
#define fi first
#define si second
#define pb push_back
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef vector<pii> vpii;

const ll INF = 1e18L + 5;
const int MAXN = 1005;
const ll modn = 1e9+7;

int main(){
  OP_IO;
  int n,k;
  cin>>n>>k;
  vi inp(n);
  fo(i,0,n){
    cin>>inp[i];
  }
  vb dp(k+1, false);
  fo(stones, 0, k+1){
    for(int x : inp){
      if (stones >= x && !dp[stones-x]){
	dp[stones] = true;
      }
    }
  }
  cout<<(dp[k]?"First":"Second")<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int a,b,c;
int main()
{
	cin>>a>>b>>c;
	for(int i=1;i<=100000;i++)
	{
		if((a*i)%b==c%b)
		{
			cout<<"YES";
			return 0;
		}
	}
	cout<<"NO";
}

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

typedef long long ll;

/*
const ll M = 1000000007;
vector<ll> fac(3001);
vector<ll> ifac(3001);
ll mpow(ll x, ll n){
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % M;
        x = x*x % M;
        n = n >> 1;
    }
    return ans;
}
 
ll comb(ll a, ll b){
    if(a == 0 && b == 0)return 1;
    if(a < b || a < 0 || b < 0)return 0;
    ll tmp = ifac[a-b]* ifac[b] % M;
    return tmp * fac[a] % M;
}
*/

ll gd(ll num){
    ll digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}

ll lcm(ll a,ll b){
 
  ll r, x, tmp;
  x = a * b;
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }
 
  r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
  return x/b;
}

ll gcd(ll a ,ll b){
    if(a==0){return b;}
    else if(b==0){return a;}
    else{
    ll tmp,r;
    if(a<b){
        tmp = a;
        a = b;
        b = tmp;
    }
    
    r = a % b;
    while(r!=0){
        a = b;
        b = r;
        r = a % b;
    }
    return b;
    }
}




int main(void){
    const ll M = 1000000007;
    ll n,a,b,c;
    string ans;
    string s;
    cin >> n;
    cin >> a;
    if(n%500<=a)ans = "Yes";
    else ans = "No";
    
    cout << ans << endl;
    return 0;
}


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

#a = [input() for i in range(N)]
#print a # [a1, a2, a3, ..., aN]

import sys

a = []
for line in sys.stdin:
    a.append(int(line))
#print a # [a1, a2, a3, ...]
a.sort(reverse=True)
print(a[0])
print(a[1])
print(a[2])

Measured memory_bytes: 7656
import sys
from collections import deque

N,M=map(int, sys.stdin.readline().split()) 

I=[ 0 for i in range(N+1) ]   #In: Nyujisuu
nl=[ []  for i in range(N+1) ] 

for i in range(N-1+M):
	a,b=map(int, sys.stdin.readline().split())
	I[b]+=1
	nl[a].append(b)


q=deque([])
start=I[1:].index(0)+1
q.append(start)

par=[ 0  for i in range(N+1) ] 

while q:
	n=q.popleft()
	for m in nl[n]:
		I[m]-=1
		if I[m]==0:
			q.append(m)
			par[m]=n


for x in par[1:]:
	print x


Measured memory_bytes: 48412
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
#define endl "\n"
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);

int main() {
    int n;
    cin >> n;
    vector<ll> A(n, 0);
    vector<ll> B(n, 0);
    for(auto& val: A)
        cin >> val;
    for(auto& val: B)
        cin >> val;
    ll acc_a = accumulate(A.begin(), A.end(), 0LL);
    ll acc_b = accumulate(B.begin(), B.end(), 0LL);
    if (acc_a < acc_b) {
        cout << -1 << endl;
        return 0;
    }
    vector<ll> diff(n, 0);
    for(int i = 0; i < n; i++) {
        diff[i] = (A[i]-B[i]);
    }
    sort(diff.begin(), diff.end());
    int l = 0, r = n-1;
    ll balance = 0;
    
    while(diff[l] < 0) {
        balance += diff[l++];
        while(balance < 0) {
            balance += diff[r--];
        }
    }
    // cout << "l = " << l << ", r = " << r << endl;
    cout << (l+(n-1-r)) << endl;
    return 0;
}


Measured memory_bytes: 5508
a,v = list(map(int,input().split()))
b,w = list(map(int,input().split()))
t = int(input())

import sys
dis = abs(a-b)
tume = v-w 
if v <= w:
  print("NO")
  sys.exit()

if dis%tume == 0 and dis//tume <= t:
  print("YES")
elif dis <= (t-1)*tume:
  print("YES")
else:
  print("NO")

Measured memory_bytes: 9196
#include <iostream>

using namespace std;

int main() {
	string n;
	cin >> n;
	unsigned long long k;
	cin >> k;
	
	if (k == 1) {
		cout << n[0] << endl;
	} else {
		bool ok = false;
		string ans = "1";
		for (unsigned long long i = 0; i < k && !ok; ++i) {
			if (n[i] != '1') {
				ans = n.substr(i, 1);
				ok = true;
			}
		}
	
		cout << ans << endl;
	}
}

Measured memory_bytes: 256
a, b, c = gets.split.map(&:to_i)

s, m, l = [a, b, c].sort

q1, r1 = (l - s).divmod(2)
q2, r2 = (l - m).divmod(2)

total = q1 + q2

if r1==0 && r2==0
  total += 0
elsif r1==1 && r2==1
  total += 1
else
  total += 2
end

p total


Measured memory_bytes: 1788
#include<iostream>
#include<algorithm>
#include<math.h>
using namespace std;
const int N=1e5+2;
int ar[N];
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n,i,j,k,l,now,sum=0;
	cin>>n;
	for(i=1;i<=n;i++){
		cin>>ar[i];	
		sum+=abs(ar[i]);
	}
	sort(ar+1,ar+1+n);
	if(ar[1]<=0&&ar[n]>=0){
		i=2;
		cout<<sum<<endl;
		while(ar[i]<=0&&i<n){
			cout<<ar[n]<<" "<<ar[i]<<endl;
			ar[n]-=ar[i];
			i++;
		}
		for(;i<n;i++){
			cout<<ar[1]<<" "<<ar[i]<<endl;
			ar[1]-=ar[i];
		}
		cout<<ar[n]<<" "<<ar[1]<<endl;
	}
	else{
		if(ar[1]<0||ar[n]<0){
			cout<<sum+2*ar[n]<<endl;
			for(i=1;i<n;i++){
				cout<<ar[n]<<" "<<ar[i]<<endl;
				ar[n]-=ar[i];
			}
		}
		else{
			cout<<sum-2*ar[1]<<endl;
			for(i=2;i<n;i++){
				cout<<ar[1]<<" "<<ar[i]<<endl;
				ar[1]-=ar[i];
			}
			cout<<ar[n]<<" "<<ar[1]<<endl;
		}
	}
}

Measured memory_bytes: 2304
#include <iostream>
#include <string>
using namespace std ; 
int main ()
{
	int l,j=0 ;
	string s; 
	cin>>l>>s;
	for ( int i=0 ; i<l;i++)
	{
		if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C')
			j=j+1;
	}
	cout<<j;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    int k,s;
    cin >> k >> s;
    int cnt = 0;
    for(int i = 0; i < k+1; i++){
        for(int j = 0; j < k+1;j++){
            if(0 <= s-i-j && s-i-j < k+1) cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}

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

ll inf=9223372036854775806;

int main()
{
	//freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
	ios_base::sync_with_stdio(false); cin.tie(0);
	int a,b,i,j;
	char d;
	bool q=false;
	string s,t;
	cin>>s>>t;
	for (i=0;i<s.size();i++){
		if (s==t){
			q=true;
			break;
		}
		else {
			d=s[0];
			for (j=0;j<s.size()-1;j++){
				s[j]=s[j+1];
			}
			s[s.size()-1]=d;
		}
	}
	if (q==true){
		cout<<"Yes";
	}
	else {
		cout<<"No";
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void){
    int H, W;
    int white, black;
    cin >> H >> W;
    int h, w;
    cin >> h >> w;
    black = h*W+w*H-h*w;
    white = H*W - black;    
    cout << white << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
//#pragma GCC optimize("Ofast","no-stack-protector","unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx")
//#include<bits/extc++.h>
//using namespace __gnu_pbds;
using namespace std;
#define int long long
#define F(i,L,R) for(int i=L;i<R;++i)
#define FE(i,L,R) for(int i=L;i<=R;++i)
#define getI(a) scanf("%lld",&a)
#define getII(a,b) scanf("%lld%lld",&a,&b)
#define getIII(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define VgetI(n) int (n); scanf("%lld",&(n))
#define VgetII(n,m) int (n),(m); scanf("%lld%lld",&(n),&(m))
#define VgetIII(n,m,k) int (n),(m),(k); scanf("%lld%lld%lld",&(n),&(m),&(k))
#define debug(x) cout<<(#x)<<"="<<x<<"\n";
#define qq cout<<"QQ\n";
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define f first
#define s second
#define INF 2000000000
main(){
	char in[5];
	while(~scanf("%s",in)){
		puts(in[0]>='a'&&in[0]<='z'?"a":"A");
	}
}


Measured memory_bytes: 3736
import sys
N,M = map(int, input().split())
X = list(map(int, input().split()))
# N,M = 2,4
# X = [1,2, 4, 9]
X.sort()
if N>=M: 
    print(0)
    sys.exit()
dif = [X[i+1]-X[i] for i in range(M-1)]
if N==1: print(sum(dif))
else: print(sum(sorted(dif)[:-N+1]))

Measured memory_bytes: 57512
//110 B - 1 Dimensional World's Tale 2018/09/23
#include <bits/stdc++.h>
#define rep(i ,n) for(int i=0;i<(int)(n);++i)
using namespace std;
typedef long long int int64;
typedef unsigned long long uint64;

int main(){
    int n , m , X , Y;
    cin >> n >> m >> X >> Y;
    vector<int> x(n);
    vector<int> y(m);
    rep(i ,n) cin >> x[i];
    rep(i ,m) cin >> y[i];
    sort(x.begin(),x.end());
    sort(y.begin(),y.end());

    bool war=true;
    for(int Z=-100 ; Z<=100 ; ++Z){
        if(Z>X && Z<=Y && x[n-1]<Z && y[0]>=Z){ war = false; break; }
    }        
    cout << ( war ? "War" : "No War" ) << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

int main(void)
{
    int a,b,h,m;
    double alpha,beta,ans;

    scanf("%d %d %d %d",&a,&b,&h,&m);

    alpha=(h+m/60.0)*M_PI/6.0;
    beta=m*M_PI/30.0;

    ans=a*a+b*b-2*a*b*cos(alpha-beta);
    ans=sqrt(ans);

    printf("%15.11f",ans);

    return 0;
}

Measured memory_bytes: 2552
n,x,y = gets.chomp.split(' ').map(&:to_i)
x -= 1
y -= 1
path = Array.new(n){Array.new(n){0}}
(n-1).times do |i|
    path[i][i+1] = 1
    path[i+1][i] = 1
end
path[x][y] = 1
path[y][x] = 1
ans = Array.new(n){0}

(n-1).times do |i|
    (i+1).upto(n-1) do |j|
        k = [(j-i),(x-i).abs + 1 + (y-j).abs,(x-j).abs + 1 + (y-i).abs]
        temp = k.min
        ans[temp] = ans[temp] + 1
    end
end
ans.shift
ans.each do |a|
    puts a
end

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

using namespace std;

int N, M;
int DpTotal[50][3];

int solve() {
	int totalW, totalB, totalR, total;

	for (int i = 1; i < N; ++i) {
		for (int k = 0; k < 3; ++k) {
			DpTotal[i][k] += DpTotal[i - 1][k];
		}
	}

	total = 2501;
	for (int i = 0; i < N - 2; ++i) {
		totalW = DpTotal[i][1] + DpTotal[i][2];
		for (int j = i + 1; j < N - 1; ++j) {
			totalB = DpTotal[j][0] - DpTotal[i][0] + DpTotal[j][2] - DpTotal[i][2];
			totalR = DpTotal[N - 1][0] - DpTotal[j][0] + DpTotal[N - 1][1] - DpTotal[j][1];
			total = min(total, totalW + totalB + totalR);
		}
	}

	return total;
}

int main() {
	char ch;

	memset(DpTotal, 0, sizeof(DpTotal));
	cin >> N >> M;
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < M; ++j) {
			cin >> ch;
			if (ch == 'W') {
				++DpTotal[i][0];
			}
			else if (ch == 'B') {
				++DpTotal[i][1];
			}
			else if (ch == 'R') {
				++DpTotal[i][2];
			}
		}
	}
	cout << solve() << endl;
	
	return 0;
}


Measured memory_bytes: 3088
// Code for C - Tax Increase
#include <iostream>
using namespace std;

int main() {
	uint A, B;
	cin >> A >> B;
	uint meA = (A * 100) / 8;
	while ((meA * 8) / 100 != A){
		meA ++;
	}
	uint meB = (B * 100) / 10;
	while ((meB * 10) / 100 != B){
		meB ++;
	}
	//cout << meA << "," << meB << endl;
	uint maA = meA;
	while ((maA * 8) / 100 == A){
		maA ++;
	}
	maA --;
	uint maB = meB;
	while ((maB * 10) / 100 == B){
		maB ++;
	}
	maB --;
	uint miA = meA;
	while ((miA * 8) / 100 == A){
		miA --;
	}
	miA ++;
	uint miB = meB;
	while ((miB * 10) / 100 == B){
		miB --;
	}
	miB ++;
	//cout << miA <<" "<< maA <<" "<< miB <<" "<< maB;
	if(miB > maA) cout << -1;
	else if (miA > maB) cout << -1;
	else{
		cout << max(miA, miB);
	}
	return 0;
}

Measured memory_bytes: 256
# ABC138D - Ki
from collections import deque


def main():
    # Ai (A[i][0]) may be not a parent of Bi (A[i][1])
    global T, cnt
    N, Q, *A = map(int, open(0).read().split())
    E, P = A[: (N - 1) * 2], A[(N - 1) * 2 :]
    T = [[] for _ in range(N + 1)]
    for v, u in zip(*[iter(E)] * 2):
        T[v].append(u), T[u].append(v)
    cnt = [0] * (N + 1)
    for p, x in zip(*[iter(P)] * 2):
        cnt[p] += x  # increase vertex p by x
    stack = deque([(1, -1)])
    while stack:
        v, p = stack.popleft()
        x = cnt[v]
        for u in T[v]:
            if u != p:
                cnt[u] += x
                stack.append((u, v))
    print(*cnt[1:])


if __name__ == "__main__":
    main()

Measured memory_bytes: 93048
import java.util.*;
 
public class Main {
    public static void main(String args[]){
        Scanner stdIn = new Scanner(System.in);
 
        int n = stdIn.nextInt();
        int k = stdIn.nextInt();
        int s = stdIn.nextInt();
        //int x = stdIn.nextInt();
        //int x[] = new int[n];
        //int l[] = new int[n];
        //String s = stdIn.next();
        //String t = stdIn.next();
        //char c[] = s.toCharArray();
        
        //c[0] += 1;
        //int sum = 0;
        //boolean flag = true;
        
        for(int i = 0; i < n - 1; i++){
            if(i < k){
                System.out.print(s + " ");
            }else if(s == 1000000000){
                System.out.print((s - 1) + " ");
            }else{
                System.out.print((s + 1) + " ");
            }
            
        }
        
        for(int i = n - 1; i < n; i++){
            if(i < k){
                System.out.println(s);
            }else if(s == 1000000000){
                System.out.println(s - 1);
            }else {
                System.out.println(s + 1);
            }
        }
        
        //System.out.println();
        //System.out.print();
 
        stdIn.close();
    }
}

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

// Ans
// 有向グラフの先の出次数が0のところから取り除いて、出力する

#define N 21

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

int main() {
	int m, n, x, y, deg[N];
	bool e[N][N];
	memset(deg, 0, sizeof(deg));
	memset(e, 0, sizeof(e));
	cin >> m >> n;
	rep(i, n) {
		cin >> x >> y; --x; --y;
		e[x][y] = true;
		++deg[y];
	}
	rep(i, m) {
		rep(j, m) {
			if(deg[j]==0) {
				deg[j] = -1;
				cout << j+1 << endl;
				rep(k, m) {
					if(e[j][k]) --deg[k];
				}
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1160
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <utility>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define mp make_pair
#define INF (1<<28)
typedef long long Int;

int N, B[64], C[64];
string A[64], D[64][64];
int g[64][64], vis[64];
int r[64], p[64];
Int f[64];

void collect(vector<int>& q, int at) {
    if (vis[at]) return ;
    vis[at] = 1;
    q.push_back(at);
    rep (i, N) if (g[at][i]) collect(q, i);
}

void prepare(vector<int>& q) {
    const int n = q.size();
    vector<pair<int, int> > ps;
    rep (i, n) ps.push_back(mp(C[q[i]], q[i]));
    sort(ps.begin(), ps.end());
    rep (i, n) r[i] = ps[n-1-i].second;
    rep (i, n) p[i] = B[r[i]];
    rep (i, n) {
        f[i] = 0;
        rep (j, n) if (g[r[i]][r[j]]) f[i] |= 1LL<<j;
    }
}

int rec(int n, int k, Int u) {
    if (k == n) return 0;
    rep (i, k) if (!(u&(1LL<<i)) && !(f[i]&u)) return -INF;
    int ans = -INF;
    const int mask = (1LL<<n) - 1;
    if (u&(1LL<<k)) ans = max(ans, rec(n, k+1, u&(mask-f[k])) + p[k]);
    if (r[k]) ans = max(ans, rec(n, k+1, u&(mask-(1LL<<k))));
    return ans;
}

int solve() {
    memset(vis, 0, sizeof(vis));
    int ans = 0;
    rep (i, N) if (!vis[i]) {
        vector<int> q;
        collect(q, i);
        prepare(q);
        ans += rec(q.size(), 0, (1LL<<q.size())-1);
    }
    return ans;
}

int main() {
    for (;;) {
        cin >> N;
        if (N == 0) return 0;
        map<string, int> of;
        rep (i, N) {
            cin >> A[i] >> B[i] >> C[i];
            of[A[i]] = i;
            rep (j, C[i]) cin >> D[i][j];
        }
        memset(g, 0, sizeof(g));
        rep (i, N) rep (j, C[i]) g[i][of[D[i][j]]] = 1;
        printf("%d\n", solve());
    }
}

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

#define int long long
#define flash ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define all(x) begin(x),end(x)

int mod = 1e9+7;
int inf = 4e18;
const int N = 3e5+5;
int xf[N] , yf[N];
int x[N] , y[N];
unordered_set<int> st[N];		
signed main()
{
    flash
    int tt = 1;
    //cin>>tt;
    while(tt--)
    {
		int n,m,k;
		cin>>n>>m>>k;
		
		int maxx = 0,maxy = 0;
		for(int i=0,xx,yy;i<k;++i)
		{
			cin>>xx>>yy;
			st[yy].insert(xx);
			xf[xx]++;
			yf[yy]++;
			maxx = max(maxx,xf[xx]);
			maxy = max(maxy,yf[yy]);
			x[i] = xx;
			y[i] = yy;
		}
		unordered_set<int> tempx,tempy;
		for(int i=1;i<=n;++i)
		{
			if(xf[i]==maxx)
			tempx.insert(i);
		}
		for(int i=1;i<=m;++i)
		{
			if(yf[i]==maxy)
			{
				tempy.insert(i);
			}
		}
		int ans = maxx;
		for(auto it:tempy)
		{
			for(auto it1:tempx)
			{
				if(!st[it].count(it1))
				{
					cout<<ans+maxy;
					return 0;
				}
			}
		}
		cout<<ans+maxy-1;
		
		
    }
    return 0;
}


Measured memory_bytes: 75204
import java.util.Scanner;

public class Main{
  public static void main(String args[]){
    Scanner scanner = new Scanner(System.in);
    int a = scanner.nextInt();
    int result = 0;
    for(int i = 1;i < 4;i++){
    	result += Math.pow(a,i);
  	}
    System.out.println(result);
  }
}

Measured memory_bytes: 35904
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<queue>
#include<numeric>
#define all(x) (x).begin(),(x).end()
typedef long long ll;
 
using namespace std;

int main()
{
    int A, B, C, K; cin >> A >> B >> C >> K;
    int cnt = 0;
    for(int i=0; i<K; i++){
        if(A >= B){
            B *= 2;
            cnt++;
        }else   break;
    }
    for(int i=cnt; i<K; i++){
        if(B >= C){
            C *= 2;
        }
        if(C > B){
            cout << "Yes";
            return 0;
        }
    }
    cout << "No";
}

Measured memory_bytes: 3624