akhauriyash/Code-Regression huggingface dataset:
import java.lang.*;
import java.math.*;
import java.util.*;

public class Main {
	Scanner sc = new Scanner(System.in);
	public void run(){
		for(;;){
			int n = sc.nextInt();
			if(n == 0){
				break;
			}
			
			int[][] map = new int[400][400];
			for(int i=0;i<400;i++){
				Arrays.fill(map[i], -1);
			}
			map[200][200] = 0;
			
			
			for(int i = 1;i < n;i++){
				int o = sc.nextInt();
				int d = sc.nextInt();
			
				int x = 0;
				int y = 0;
				for(int k = 0; k < 400; k++){
					for(int z = 0;z <400;z++){
						if(map[k][z] == o){
							x = k;
							y = z;
						}
					}
				}
				if(d == 0){
					map[x][y-1] = i;
				}
				if(d == 1){
					map[x+1][y] = i;
				}
				if(d == 2){
					map[x][y+1] = i;
				}
				if(d == 3){
					map[x-1][y] = i;
				}
			}
			
			int minx = 400;
			int miny = 400;
			int maxx = 0;
			int maxy = 0;
			
			for(int i = 0; i < 400;i++){
				for(int j = 0; j < 400; j++){
					if(map[i][j] != -1){
						minx = Math.min(minx,i);
						miny = Math.min(miny,j);
						maxx = Math.max(maxx,i);
						maxy = Math.max(maxy,j);
					}
				}
			}
			System.out.println((maxy-miny + 1) +" " + (maxx -minx+1));
		}
		
	}
	
	public static void main(String args[]){
		Main m = new Main();
		m.run();
	}
}

Measured memory_bytes: 17000
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
const int inf = 1e9 + 7;
const ll INF = 1e18;
// int mod = 998244353;
int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll pow(ll a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; }
template<typename T> inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T, class T2> inline void add(T &a, T2 b) { a += b; if (a >= mod) a -= mod; }


void solve();

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(10);

  int T;
  // cin >> T;
  T = 1;

  while (T--) {
    solve();
  }
}

template<typename T>
vector<T> lis(vector<T> a) {
  vector<T> b;
  b.eb(a[0]);
  rep3(i, 1, sz(a)) {
    int it = ub(b, a[i]);
    if (it == sz(b)) {
      b.eb(a[i]);
    } else {
      b[it] = a[i];
    }
  }
  return b;
}

void solve() {
  int n;
  cin >> n;
  vector<int> a(n);
  cin >> a;
  reverse(all(a));
  auto v = lis(a);
  cout << sz(v) << endl;
}


Measured memory_bytes: 1660
using System;
using System.Linq;

namespace ABC148
{
    class B
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            string[] input = Console.ReadLine().Split();
            string S = input[0];
            string T = input[1];
            string res = "";
            for (int i = 0; i < N; i++)
            {
                res += S[i];
                res += T[i];
            }

            Console.WriteLine(res);

        }
    }
}


Measured memory_bytes: 11092
N = int(input())

s = N * (N+1) //2

M = N // 3
s3 = 3 * M * (M+1) // 2

M = N // 5
s5 = 5 * M * (M+1) // 2

M = N // 15
s15 = 15 * M * (M+1) // 2

print(s - s3 - s5 + s15)

Measured memory_bytes: 9184
N, M = map(int,input().split())
A = list(map(int,input().split()))
hyo = sum(A)

ans = 0
sait = hyo / (4*M)
for i in A:
    if i >= sait:
        ans +=1
    
if ans >= M:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
a, b, c = list(map(int, input().split()))

def foo(a, b, c):
    seen = set()
    m = a % b
    i = m
    while i not in seen :
        if i == c:
            print("YES")
            return 
        seen.add(i)
        i = (m + i) % b
    print("NO")
foo(a, b, c)


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
#define lp(i, x, y) for(ll i = x ; i < y ; i++)
#define lp_rev(i, x, y) for(int i = x ; i >= y ; i--)
#define ff first
#define ss second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(v)  v.begin(), v.end()
#define vll vector<long long int>
#define vi vector<int>
#define Fasttt ios_base::sync_with_stdio(NULL);cin.tie(NULL);cout.tie(NULL);
typedef unsigned long long ull;
typedef long long ll;
#define endl "\n"
ll mod = 1000000007;

int main()
{
	int n, k;
	cin>> n>> k;
	vi v(n), dp(n);
	lp(i, 0, n)
		cin>> v[i];
	dp[0] = 0;
	dp[1] = abs(v[1] - v[0]);
	lp(i, 2, n)
	{
		dp[i] = INT_MAX;
		lp(j, 1, k + 1)
			if(i - j >= 0)
				dp[i] = min(dp[i], dp[i - j] + abs(v[i] - v[i - j]));
	}
	cout<< dp[n - 1];
	return 0;
}		

Measured memory_bytes: 1024
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
#define P pair<int,int>
const int MOD=998244353;
const int MAX=1e5+10;
const double PI=acos(-1);


int main() {
    ios_base::sync_with_stdio(false);

    int n;
    cin >> n;
    vector<int> x(n);
    rep(i,n) cin >> x[i];
    int ans=100000000;
    repr(i,1,101) {
        int tans=0;
        rep(j,n) tans+=(x[j]-i)*(x[j]-i);
        ans=(tans<ans)?tans:ans;
    } 
    cout << ans << endl;
     
    return 0;   
}

Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <cmath>

using namespace std;

long long int dp[110][100010];

int main()
{
    int N, W;
    long long int w[110], v[110];

    cin >> N >> W;

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

    for (int i = 0; i < N; i++) {
        for (int j = 0; j <= W; j++) {
            if (j < w[i]) {
                dp[i+1][j] = dp[i][j];
            }
            else {
                dp[i+1][j] = max(dp[i][j], dp[i][j-w[i]]+v[i]);
            }
        }
    }

    cout << dp[N][W] << endl;
}



Measured memory_bytes: 79360
#include <bits/stdc++.h>
using namespace std;
 
 
int main() {
 

  // input
  string s,t;
  cin>>s>>t;

  // copy string to vector
  vector<char> s_c(s.size());
  vector<char> t_c(t.size());

  for(int i=0;i<s.size();i++){
    s_c.at(i)=s.at(i);
  }
  for(int i=0;i<t.size();i++){
    t_c.at(i)=t.at(i);
  }

  // arrange data
  sort(s_c.begin(),s_c.end());
  sort(t_c.begin(),t_c.end(),std::greater<char>());

  if(s.size()<t.size()){
    for(int i=s.size();i<t.size();i++){
      s_c.push_back('0');
    }
  }

  if(t.size()<s.size()){
    for(int i=t.size();i<s.size();i++){
      t_c.push_back('0');
    }
  }

  string s2,t2;
  for(int i=0;i<s_c.size();i++){
    s2.push_back(s_c.at(i));
    t2.push_back(t_c.at(i));
  }


  // output
  if(s2<t2)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;

	return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
const LL LINF=1LL<<62;
const LL mod=1e9+7;


int main(){
    int N;
    cin >> N;
    string s;
    cin >> s;
    LL ans=0;
    for(int i=1;i<N;i++){
        LL c[26],t[26];
        memset(c,0,sizeof(c));
        memset(t,0,sizeof(t));
        LL co=0;
        for(int j=0;j<i;j++){
            c[s[j]%26]++;
        }
        for(int j=N-1;j>=i;j--){
            t[s[j]%26]++;
        }
        for(int j=0;j<26;j++){
            if(c[j]&&t[j]) co++;
        }
        ans=max(ans,co);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
def main():
    a= input()

    if a[0] == a[1]:
        if a[2] == a[3] and a[0] !=  a[2]:
            print("Yes")
        else:
            print("No")
    elif a[0] == a[2]:
        if a[1] == a[3] and a[0] !=  a[1]:
            print("Yes")
        else:
            print("No")
    elif a[0] == a[3]:
        if a[2] == a[1] and a[0] !=  a[2]:
            print("Yes")
        else:
            print("No")
    else:
        print("No")


if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
#include <iostream>
#include <cmath>
#include <stdio.h>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <iomanip>
using ll = long long;
using namespace std;
//#define int long long

#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = 0; i <= (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int i = n; i >= 0; i--)
int factorical(int n) {
	int sum = 1;
	for (int i = 1; i <= n; ++i)
	{
		sum *= i;
	}
	return sum;
}

vector<int> divisors(int n) {
	vector<int> res;
	for (int i = 1; i * i <= n; ++i) {
		if (n % i != 0) continue;
		res.push_back(i);
		if (n / i == i) continue; // 上の行で追加済み。
		res.push_back(n / i);
	}
	return res;
}
vector<ll> divisors_ll(ll n) {
	vector<ll> res;
	for (ll i = 1; i * i <= n; ++i) {
		if (n % i != 0) continue;
		res.push_back(i);
		if (n / i == i) continue; // 上の行で追加済み。
		res.push_back(n / i);
	}
	return res;
}


void printVector(const vector<int>& vec) {
	for (int value : vec) {
		cout << value << " ";
	}
	cout << endl;
}



int main() {
	string S;
	cin >> S;
	string sout = "";
	rep(i, S.length()) {
		sout += "x";
	};
	cout << sout << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<queue>
#define ll long long
using namespace std;
int main()
{
    string a,b;
    cin>>a>>b;
    reverse(a.begin(),a.end());
    if(a == b)
        cout<<"YES";
    else
        cout<<"NO";
    return 0;
}

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

int main() {
  ll n,m,pw=10,ans=0;
  cin >> n;
  if(n%2 == 1){
    cout << 0 << endl;
    return 0;
  }
  while(1){
    m = n / (pw);
    if (m == 0) break;
    ans += m;
    pw *= 5;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define sort(vec) sort(vec.begin(),vec.end())
#define reverse(vec) reverse(vec.begin(),vec.end())
#define unsort(vec); sort(vec);reverse(vec);
#define int long long
long long ans;

int gcd(int x,int y){
	if(y==0) return x;
	else return gcd(y,x%y);
}

int lcm(int x,int y){
	return x/gcd(x,y)*y;
}
 
signed main(){
	int h,w,x,y;
	cin>>h>>w>>x>>y;
	cout<<(h-x)*(w-y)<<endl;
}


Measured memory_bytes: 764
// 参考 -> #5833462
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        String s;
        int p;
        Map<String, TreeMap<Integer, Integer>> tmp = new TreeMap<>();

        for (int i = 0; i < n; i++) {
            s = sc.next();
            p = sc.nextInt();
            if (tmp.containsKey(s)) {
                tmp.get(s).put(p, i+1);
            } else {
                TreeMap<Integer, Integer> hoge = new TreeMap<>();
                hoge.put(p, i+1);
                tmp.put(s, hoge);
            }
        }

        for (String key : tmp.keySet()) {
            TreeMap<Integer, Integer> tmp1 = new TreeMap<>();
            tmp1 = tmp.get(key);
            List<Integer> tmp2 = new LinkedList<>();

            for (int i : tmp1.keySet()) {
                int value = tmp1.get(i);
                tmp2.add(0, value);
            }

            for (int i : tmp2) {
                System.out.println(i);
            }
        }
    }
}

Measured memory_bytes: 21844
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long
int dp[110][100010]; // dp[i][j] := i個目を入れた時のjの価値を達成する最小の重さ

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, W;
    cin >> N >> W;
    int w[110], v[110];
    rep(i, N) cin >> w[i] >> v[i];
    rep(i, N + 1) rep(j, 100010) dp[i][j] = INF;
    dp[0][0] = 0;
    rep(i, N) {
        rep(j, 100010) {
            dp[i + 1][j] = dp[i][j];
            if (j - v[i] < 0) continue;
            dp[i + 1][j] = min(dp[i + 1][j], dp[i][j - v[i]] + w[i]);
        }
    }
    int ans = 0;
    //rep(j, 4) rep(i, 110) cout << j << " " << i << " " << dp[j][i] << endl;
    rep(i, 100010) if (dp[N][i] <= W) ans = max(ans, i);
    cout << ans << endl;

    return 0;
}


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

int main() {
  int n, d_i1, d_i2, res = 0, series = 0;
  cin >> n;
  for (int i = 0; (i < n) && (series != 3); ++i) {
    cin >> d_i1 >> d_i2; 
    series += (d_i1 == d_i2);
    if (d_i1 != d_i2)
      series = 0;
  }
  if (series == 3)
    cout << "Yes" << '\n';
  else
    cout << "No" << '\n';
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
using lint = long long;

string S;

int main()
{
    lint ans = 0;
    cin >> S;
    for (int i=0; i<(1 << (S.size()-1)); i++)
    {
        lint tmp = 0;
        for (int k=0; k<S.size(); k++)
        {
            tmp += S[k] - '0';
            if ((i >> k) & 1) tmp *= 10;
            else
            {
                ans += tmp;
                tmp = 0;
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
let rec find x uf =
  if uf.(x) < 0 then
    x
  else
    let x' = find uf.(x) uf in
    uf.(x) <- x';
    x'

let unite x y uf =
  let x, y = find x uf, find y uf in
  if x <> y then
    if uf.(x) < uf.(y) then begin
      uf.(x) <- uf.(x) + uf.(y);
      uf.(y) <- x
    end else begin
      uf.(y) <- uf.(x) + uf.(y);
      uf.(x) <- y
    end

module S = Set.Make(struct type t = int let compare = (-) end)
  
let () =
  Scanf.scanf "%d %d" @@ fun n m ->
  let uf = Array.make n (-1) in
  for i = 1 to m do Scanf.scanf " %d %d %d" @@ fun x y _ -> unite (x-1) (y-1) uf done;
  Array.init n (fun i -> find i uf)
  |> Array.fold_left (fun s x -> S.add x s) S.empty
  |> S.cardinal |> Printf.printf "%d\n"



Measured memory_bytes: 7296
#include <iostream>
#include <climits>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;
int main() {
	int n;
    cin >> n;
    int yen = ceil(n /1.08);
    if( (int)(yen * 1.08) == n ){
        cout << yen << endl;
    } else{
        cout << ":(" <<  endl;
    }
}


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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

int n;

int main(void) {
  // Here your code !
  scanf("%d", &n);

  vector<string> s(n + 1);

  cout << 0 << endl;
  cin >> s[0];
  if (s[0] == "Vacant") return 0;

  int left = 0;
  int right = n;

  s[n] = s[0];

  while (true) {
    int mid = (left + right) / 2;

    cout << mid << endl;
    cin >> s[mid];
    
    if (s[mid] == "Vacant") return 0;

    // if left part is valid, then right part must be
    // if right part is valid, then left part must be
    // (same, even), or, (diff, odd)
    if ((s[mid] == s[left]) ^ ((mid - left) % 2 == 1)) left = mid;
    else right = mid;
  }

  return 0;
}


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

int main() {
    int n;
    cin >> n;
    string ans = "No";
    for (int c = 0; c <= n; c += 4) {
        for (int d = 0; c + d <= n; d += 7) {
            if (c + d == n) ans = "Yes";
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long LL;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const LL N = 1000000007;

LL n,x,y;
LL sum[200005] = {0},a[200005];
LL dp[200005],l,r;

int main(){
	cin >> n >> x >> y;
	if(x > y) swap(x,y);
	for(LL i = 1;i <= n;i ++) cin >> a[i]; a[n + 1] = INF;
	
	for(LL i = 1;i < n - 1;i ++){
		if(a[i + 2] - a[i] < x){
			cout << 0 << endl;
			return 0;
		}
	}
	
	l = 0; r = 0;
	dp[0] = 1; sum[0] = 1;
	for(LL i = 1;i <= n + 1;i ++){
		while(a[i] - a[r + 1] >= y && r <= n) r ++;
		if(l <= r) dp[i] = ((dp[i] + sum[r] - (l ? sum[l - 1] : 0)) % N + N) % N;
		sum[i] = (sum[i - 1] + dp[i]) % N;
//		cout << i << ' ' << l << ' ' << r << ' ' << dp[i] << endl;
		if(a[i] - a[i - 1] < x) l = i - 1;
	}
	
	cout << dp[n + 1] << endl;
	return 0;
}

Measured memory_bytes: 3584
#include<bits/stdc++.h>
#include <tr1/unordered_map>
using namespace std;
typedef long long ll;
#define int ll
inline ll read(){
	ll res=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-f;ch=getchar();}
	while(ch>='0'&&ch<='9'){res=(res<<3)+(res<<1)+ch-'0';ch=getchar();}
	return res*f;
}
void write(ll x){
	if(x<0) putchar('-'),x=-x;
	if(x>9) write(x/10);
	putchar(x%10|'0');
}
bool check(int x){
	for(int i=2;i*i<=x;i++) if(x%i==0) return false;
	return true;
}

tr1::unordered_map <int, int> alb;

signed main(){
	int a=read(),b=read();
	int ans=0;
	for (int i = 2; i * i <= a; ++i) 
		if (a % i == 0) {
			alb[i] = 1;
			while (a % i == 0) a /= i;
		}
	if (a > 1) alb[a] = 1;
	for(int i=2;i*i<=b;i++){
		if(b%i==0){
			if(alb[i]) ans++;
			while(b%i==0) b/=i;
		}
	}
	if (b > 1) ans += alb[b];
	cout<<ans + 1<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define repR(i, n) for(ll i = n; i >= 0; i--)
#define For(i, m, n) for(ll i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()

using namespace std;

int main(int argc, char *argv[]) {
    ll N, L;
    cin >> N >> L;
    vector<ll> apples;
    rep(i, N){
        apples.push_back(L + i);
    }
    ll minAbs = 0;
    
    ll result = 0;
    For(i, 1, N){
        if(abs(apples[minAbs]) > abs(apples[i])){
            result += apples[minAbs];
            minAbs = i;
        }else{
            result += apples[i];
        }
    }
    
    cout << result << endl;
    return 0;
}



Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <iostream>
#include <set>
#include <algorithm>
#include <vector>
#include <map>
#include <cassert>
#include <string>
#include <cstring>
#include <queue>

using namespace std;

#define rep(i,a,b) for(int i = a; i < b; i++)
#define S(x) scanf("%d",&x)
#define S2(x,y) scanf("%d%d",&x,&y)
#define P(x) printf("%d\n",x)
#define all(v) v.begin(),v.end()
#define FF first
#define SS second
#define pb push_back
#define mp make_pair

typedef long long int LL;
typedef pair<int, int > pii;
typedef vector<int > vi;

int main() {
  LL x,y;
  scanf("%lld%lld",&x,&y);
  int ans = 0;
  while(x <= y) {
    x += x;
    ans++;
  }
  P(ans);
  return 0;
}


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

int main()
{
	using p = pair<int, bool>;
	vector<p> a(9);	// カード
	rep(i, 9)
	{
		cin >> a[i].first;
		a[i].second = false;
	}

	int n; cin >> n;	// 抽選番号の数

	vector<int> b(n);	// 抽選番号
	rep (i, n)
	{
		cin >> b[i];
	}

	for (int idxOfB = 0; idxOfB < n; idxOfB++)
	{
		for (int idxOfA = 0; idxOfA < 9; idxOfA++)
		{
			if (a[idxOfA].first == b[idxOfB])
			{
				a[idxOfA].second = true;
			}
		}
	}

	for (int y = 0; y < 3; y++)
	{
		if (a[y * 3 + 0].second && a[y * 3 + 1].second && a[y * 3 + 2].second)
		{
			cout << "Yes" << endl;
			return 0;
		}
	}

	for (int x = 0; x < 3; x++)
	{
		if (a[0 * 3 + x].second && a[1 * 3 + x].second && a[2 * 3 + x].second)
		{
			cout << "Yes" << endl;
			return 0;
		}
	}

	if (a[0 * 3 + 0].second && a[1 * 3 + 1].second && a[2 * 3 + 2].second)
	{
		cout << "Yes" << endl;
		return 0;
	}

	if (a[0 * 3 + 2].second && a[1 * 3 + 1].second && a[2 * 3 + 0].second)
	{
		cout << "Yes" << endl;
		return 0;
	}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define REP(i, a, b) for (int i = (a); i <= (b); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORD(i, a, b) for(int i = (a); i > (b); --i)
#define REPD(i, a, b) for(int i = (a); i >=(b); --i)
#define TR(it, a) for(__typeof(a.begin()) it = a.begin(); it != a.end(); ++it)
#define endl '\n'
#define mp make_pair
#define pb push_back
#define pf push_front
#define ins insert
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define SZ(x) ((int)(x).size())
#define unmap unordered_map
#define pq priority_queue
#define lb lower_bound //first pos >= val
#define ub upper_bound // first pos > val
#define bp __builtin_popcount
#define debug(a) cout << a << endl
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair <ll, ll> pll;
typedef pair <int, int> pii;
typedef pair <ll, ld> pld;
typedef pair <ll, pll> pllp;
typedef pair <pll, ll> ppll;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector <pll> vpll;
typedef vector <pii> vpii;
typedef string BigNum;

const ll maxN = 1e18;
const ll minN = -1e18;
const ll MOD = 1e9 + 7;
const ll MOD1 = 998244353;
const int baseHash = 331;
const int bigNumLength = 5000;
const ld PI = acos(-1);

//Remember limit for IT, etc..., and +1 in limit of any array
const ll limit = 2e5 + 5;
const ll limit1 = 1e6 + 5;
const ll limit2 = 1e3 + 5;
//If TLE let's use int instead of ll because it's as slow as your WPM :)))

/*----IMPORTANT THINGS----*/
pll dir[] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}, {1, 1}, {1, -1}, {-1, 1}, {-1, -1}};
/*------------------------*/

ll n, k;
ll a[limit];
ll f[limit];

void solveProblem() {
    REP(i, 1, n) f[i] = maxN;
    REP(i, 2, k + 1) {
        f[i] = abs(a[1] - a[i]);
    }

    //REP(i, 1, k + 1) cout << f[i] << endl;
    //cout << f[n] << endl;
    REP(i, k + 2, n) {
        REP(j, 1, k) {
            f[i] = min(f[i], f[i - j] + abs(a[i - j] - a[i]));
            //cout << j << " " << f[i] << endl;
        }
    }
    //REP(i, 1, 10) cout << f[i] << " ";cout << endl;

    cout << f[n] << endl;
}

void fastInput() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

void readInput() {
    cin >> n >> k;
    REP(i, 1, n) cin >> a[i];
}

int main() {
    fastInput();
    readInput();
    solveProblem();
}



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

typedef long long llint;
typedef long double ld;

#define inf 1e18
#define mod 1000000007
priority_queue<llint,vector<llint>,greater<llint> > que;
priority_queue<llint> Que;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

void solve(){
    string a,b;
    cin >> a >> b;
    string t=a+b;
    int x=stoi(t);
    int r=sqrt(x);
    if(r*r==x)cout << "Yes" << endl;
    else cout << "No" << endl;
    
}

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


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {


	public static void main(String[] args) throws IOException {
		Main myTools = new Main();

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String haiku = br.readLine();

		haiku = haiku.replaceAll(",", " ");

		System.out.println(haiku);

	}


}

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

using namespace std;

using pii = pair<int, int>;
using pll = pair<long long, long long>;

int main() {
    int n;
    cin >> n;
    int t = n % 10;
    if (t == 2 || t == 4 || t == 5 || t == 7 || t == 9) {
        cout << "hon" << endl;
    }
    else if (t == 0 || t == 1 || t == 6 || t == 8) {
        cout << "pon" << endl;
    }
    else {
        cout << "bon" << endl;
    }
}

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

vector<vector<int> > LP(1010, vector<int>(1010, 0));

int main(){
    string s, t;
    cin >> s >> t;
    for(int i = 1; i <= s.size(); i++){
        LP[i][0] = i;
    }
    for(int i = 1; i <= t.size(); i++){
        LP[0][i] = i;
    }

    for(int i = 1; i <= s.size(); i++){
        for(int l = 1; l <= t.size(); l++){
            int mid = min(LP[i-1][l] + 1, LP[i][l-1] + 1);
            if(s[i-1] == t[l-1]){ //文字列の配列参照してるから添え字違う 最後の文字
                mid = min(mid, LP[i-1][l-1]);
            }else{
                mid = min(mid, LP[i-1][l-1] + 1);
            }
            LP[i][l] = mid;
        }
    }
    cout << LP[s.size()][t.size()] << endl;
}


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

#define int long long
#define pii pair<int, int>
#define pb push_back
#define vi vector<int>

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int n;
    cin >> n;
    string s;
    cin >> s;
    int R = 0;
    for(auto x: s) {
        R += x == 'R';
    }
    int W = n - R;
    int ans = min(R, W);
    reverse(s.begin(), s.end());
    int res = W;
    for(int i = 0; i < W; i++) {
        res -= s[i] == 'W';
    }
    ans = min(ans, res);
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3764
# -*- coding: utf-8 -*-
  
a1, a2, a3 = map(int, input().split())

c1 = abs(a1 - a2)
c2 = abs(a2 - a3)
c3 = abs(a3 - a1)

min_c1_c2 = 0
max_c1_c2 = 0

if c1 < c2:
  min_c1_c2 = c1
  max_c1_c2 = c2
else:
  min_c1_c2 = c2
  max_c1_c2 = c1

if c3 < min_c1_c2:
  print(c3 + min_c1_c2)
elif c3 < max_c1_c2:
  print(c3 + min_c1_c2)
else:
  print(min_c1_c2 + max_c1_c2)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define pb          emplace_back
#define ll          long long
#define fi          first
#define se          second
#define mp          make_pair
#define sz(x)       int(x.size())
//#define int         long long

using namespace std;

typedef pair<int, int> pii;
const int N = int(2e5 + 5);
const int mod = (int)1e9 + 7;

int t[N];
void add(int& x, int y) {if((x += y) >= mod) x -= mod;}
void upd(int x, int val) {for(; x < N; x += (x & -x)) add(t[x], val);}
int get(int x) {int res = 0; for(; x > 0; x -= (x & -x)) add(res, t[x]); return res;}
int n, m, l[N], r[N], cur;
vector<int> val;
vector<pii> v;
pii x[N];

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    #define Task        "test"
    if(fopen(Task".inp", "r")) {
        freopen(Task".inp", "r", stdin);
        freopen(Task".out", "w", stdout);
    }
    cin >> n >> m;
    for(int i = 1; i <= n; ++i) {
        cin >> x[i].fi; x[i].se = 0;
    }
    for(int i = 1; i <= m; ++i) {
        cin >> x[i + n].fi; x[i + n].se = 1;
    }
    n += m; sort(x + 1, x + n + 1);
    for(int i = 1; i <= n; ++i) {
        if(x[i].se) cur = x[i].fi;
        else if(cur) l[i] = x[i].fi - cur;
    } cur = 0;
    for(int i = n; i >= 1; --i) {
        if(x[i].se) cur = x[i].fi;
        else if(cur) r[i] = cur - x[i].fi;
        if(l[i] && r[i]) {
            val.pb(r[i]);
            v.pb(l[i], r[i]);
        }
    } val.pb(0);
    sort(val.begin(), val.end()); val.erase(unique(val.begin(), val.end()), val.end());
    sort(v.begin(), v.end(), [&](const pii& a, const pii& b) {
            return a.fi < b.fi || (a.fi == b.fi && a.se > b.se);
         });
    v.erase(unique(v.begin(), v.end()), v.end());
    upd(1, 1);
    for(auto p: v) {
        p.se = lower_bound(val.begin(), val.end(), p.se) - val.begin();
        cur = get(p.se);
        upd(p.se + 1, cur);
    }
    cout << get(N - 1);
}


Measured memory_bytes: 4848
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.StringTokenizer;

public class Main {

    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner();
        PrintWriter pw = new PrintWriter(System.out);
        long r = Long.parseLong(sc.next());
        long d = Long.parseLong(sc.next());
        long x = Long.parseLong(sc.next());
        for (int i = 0; i < 10; i++) {
            System.out.println(x = r * x - d);
        }
    }

    static class Scanner {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer("");
        int spaces = 0;

        public String nextLine() throws IOException {
            if (spaces-- > 0) {
                return "";
            } else if (st.hasMoreTokens()) {
                return new StringBuilder(st.nextToken("\n")).toString();
            }
            return br.readLine();
        }

        public String next() throws IOException {
            spaces = 0;
            while (!st.hasMoreTokens()) {
                st = new StringTokenizer(br.readLine());
            }
            return st.nextToken();
        }

        public boolean hasNext() throws IOException {
            while (!st.hasMoreTokens()) {
                String line = br.readLine();
                if (line == null) {
                    return false;
                }
                if (line.equals("")) {
                    spaces = Math.max(spaces, 0) + 1;
                }
                st = new StringTokenizer(line);
            }
            return true;
        }
    }
}


Measured memory_bytes: 21204
#include<bits/stdc++.h> 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
using namespace std; 

#define TRACE
 
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
 
template <typename T>
using pbds = tree<T, null_type, less<T>, rb_tree_tag,
    tree_order_statistics_node_update>;


typedef     long long                            ll; 
typedef     long double                          ld; 
typedef     pair<ll, ll>                         pl; 
typedef     vector<ll>                           vl;
typedef     vector<char>                         vc;
typedef     vector<bool>                         vb; 
typedef     vector<vl>                           vvl; 
typedef     vector<pl>                           vll; 
typedef     map<ll, ll>                          dict; 
typedef     map<ll, ll, greater <ll> >           sdict; 
typedef     map<char, ll>                        mcl;
typedef     priority_queue<ll>                   pqi;
typedef     priority_queue<pl>                   pqii;
typedef     priority_queue<ll, vl, greater<ll>>  pqmini;
 
#define FOR(a, b, c) for (int(a) = (b); a < c; a++) 
#define FORD(a, b, c) for (int(a) = (b); a >= c; a--)  
 
#define rep(i, n) FOR(i, 0, n) 
#define repN(i, n) FOR(i, 1, n+1) 
#define repD(i, n) FORD(i, n-1, 0)
#define trav(i, a) for(auto i:a)
#define fi first 
#define se second 
#define mp make_pair 
#define pb push_back
#define pe pop_back
#define fill(a, b) memset(a, b, sizeof(a)
#define get(a) rep(i, sz(a))cin>>a[i];
#define sz(a) (ll)(a.size())
#define all(a) a.begin(), a.end()
#define mod 1000000007

int main(){
	int n, k; cin>>n>>k;
	vl h(n); get(h);
	vl dp(n,1e9); dp[0]=0; 
	rep(i,n-1)FOR(j,i+1,i+k+1)
		if(j<n)dp[j]=min(dp[j],dp[i]+abs(h[i]-h[j])); else break;
	cout<<dp[n-1]<<"\n";
	return 0;
}

Measured memory_bytes: 1792
/*2019/10/02 */
/*template*/
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#define MOD 1000000007
#define MIN 999999999
#define MAX -999999999
typedef long long int ll;
typedef unsigned long long int ull;
void llswap(ll *x,ll *y){ll tmp;tmp=*x;*x=*y;*y=tmp;}
void swap(int *x,int *y){int tmp;tmp=*x;*x=*y;*y=tmp;}
int rmax(int x,int y){return x>y?x:y;}
int rmin(int x,int y){return x>y?y:x;}
ll llrmax(ll x,ll y){return x>y?x:y;}
ll llrmin(ll x,ll y){return x>y?y:x;}
int asc(const void *a,const void *b){if(*(int*)a < *(int*)b)return -1;else if(*(int*)a == *(int*)b)return 0;else return 1;}
int desc(const void *a,const void *b){if(*(int*)a < *(int*)b)return 1;else if(*(int*)a == *(int*)b)return 0;else return -1;}
int llasc(const void *a,const void *b){if(*(ll*)a < *(ll*)b)return -1;else if(*(ll*)a == *(ll*)b)return 0;else return 1;}
int lldesc(const void *a,const void *b){if(*(ll*)a < *(ll*)b)return 1;else if(*(ll*)a == *(ll*)b)return 0;else return -1;}
int gcd(int x,int y){if(y==0)return x;return gcd(y,x%y);}

/*
int asc_t(const void *a,const void *b){if((pair_t*)a->d < (pair_t*)b->d)return -1;else if((pair_t*)a->d == (pair_t*)b->d)return 0;else return 1;}
int desc_t(const void *a,const void *b){if((pair_t*)a->d < (pair_t*)b->d)return 1;else if((pair_t*)a->d == (pair_t*)b->d)return 0;else return -1;}
*/
int main(){
    int n,m,x[200000];
    static ll d[200000];
    ll ans;

    scanf("%d %d",&n,&m);
    for(int i=0;i<m;i++){
        scanf("%d",&x[i]);
    }
    
    qsort(x,m,sizeof(int),asc);
    ans=x[m-1]-x[0];
    for(int i=1;i<m;i++){
        d[i-1]=x[i]-x[i-1];
    }
    qsort(d,m-1,sizeof(ll),lldesc);
    
    for(int i=0;i<m-1&&i<n-1;i++){
        ans-=d[i];
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 1908
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>

auto& in = std::cin;
auto& out = std::cout;

int32_t N, M;
std::multiset<int32_t> set;
int32_t V[200000];

int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);

	in >> N;
	for (int32_t i = 0; i < N; i++)
	{
		int32_t a;
		in >> a;
		set.insert(a);
	}
	in >> M;
	for (int32_t i = 0; i < M; i++)
	{
		in >> V[i];
	}
	for (int32_t i = 0; i < M; i++)
	{
		auto a = set.find(V[i]);
		if (a == set.end()) {
			out << "NO\n"; return 0;
		}
		else {
			set.erase(a);
		}
	}

	out << "YES\n"; return 0;


	return 0;
}
#endif


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

template <int mod = (int)(1e9 + 7)>
struct ModInt {
  int x;
  constexpr ModInt() : x(0) {}
  constexpr ModInt(int64_t y)
      : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
  constexpr ModInt &operator+=(const ModInt &p) noexcept {
    if ((x += p.x) >= mod) x -= mod;
    return *this;
  }
  constexpr ModInt &operator-=(const ModInt &p) noexcept {
    if ((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }
  constexpr ModInt &operator*=(const ModInt &p) noexcept {
    x = (int)(1LL * x * p.x % mod);
    return *this;
  }
  constexpr ModInt &operator/=(const ModInt &p) noexcept {
    *this *= p.inverse();
    return *this;
  }
  constexpr ModInt operator-() const { return ModInt(-x); }
  constexpr ModInt operator+(const ModInt &p) const noexcept {
    return ModInt(*this) += p;
  }
  constexpr ModInt operator-(const ModInt &p) const noexcept {
    return ModInt(*this) -= p;
  }
  constexpr ModInt operator*(const ModInt &p) const noexcept {
    return ModInt(*this) *= p;
  }
  constexpr ModInt operator/(const ModInt &p) const noexcept {
    return ModInt(*this) /= p;
  }
  constexpr bool operator==(const ModInt &p) const noexcept { return x == p.x; }
  constexpr bool operator!=(const ModInt &p) const noexcept { return x != p.x; }
  constexpr ModInt inverse() const noexcept {
    int a = x, b = mod, u = 1, v = 0, t = 0;
    while (b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }
  constexpr ModInt pow(int64_t n) const {
    ModInt res(1), mul(x);
    while (n) {
      if (n & 1) res *= mul;
      mul *= mul;
      n >>= 1;
    }
    return res;
  }
  friend constexpr ostream &operator<<(ostream &os, const ModInt &p) noexcept {
    return os << p.x;
  }
  friend constexpr istream &operator>>(istream &is, ModInt &a) noexcept {
    int64_t t = 0;
    is >> t;
    a = ModInt<mod>(t);
    return (is);
  }
  constexpr int get_mod() { return mod; }
};

long long n, lim;
vector<long long> w;
vector<ModInt<>> dp;

ModInt<> solve();

int main() {
  cin >> n >> lim;
  w.resize(n);
  for (auto &p : w) cin >> p;
  sort(w.begin(), w.end(), greater<long long>());
  cout << solve() << endl;
  return 0;
}

ModInt<> solve() {
  long long sum = 0;
  for (auto p : w) sum += p;
  ModInt<> res = 0;
  dp.assign(lim + 1, 0);
  dp[0] = 1;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j + sum <= lim; ++j) {
      res += dp[j];
      dp[j] = 0;
    }
    for (int j = lim; j >= w[i]; --j) dp[j] += dp[j - w[i]];
    sum -= w[i];
  }
  for (int i = 0; i <= lim; ++i) res += dp[i];
  return res;
}


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

import sys

debug = False

def log(text):
    if debug:
        print(text)

def parse_input(lines_as_string = None):

    global debug
    lines = []
    if lines_as_string is None:
        debug = False
        lines.append(input())
    else:
        debug = True
        lines = [e for e in lines_as_string.split("\n")][1:-1]

    tokens = lines[0].split(" ")
    n = int(tokens[0])
    l = int(tokens[1])

    return (n, l)


def solve(n, l):

    min_abs = abs(l)
    removed = l
    sum = 0
    for i in range(l, l+n):
        sum = sum + i
        if abs(i) < min_abs:
            min_abs = abs(i)
            removed = i

    return sum - removed


def main():
    # 出力

    print("%s" % solve(*parse_input()))

#    solve(*parse_input())

if __name__ == '__main__':

    main()


Measured memory_bytes: 3064
import collections
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
X=int(input())
for i in range(X):
  l=prime_factorize(X-i)
  c=collections.Counter(l)
  m=list(c.values())
  n=collections.Counter(m)
  if len(n)==1 and m[0]!=1:
    print(X-i)
    exit()
print(1)

Measured memory_bytes: 3316
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}

vector<vector<int>> g;
vector<ll> A,B;

ll ans;
vector<int> size;
vector<ll> dp;

void sizedfs(int now,int par){
    size[now]=1;
    for(auto nex:g[now]) if(nex!=par){
        sizedfs(nex,now);
        size[now]+=size[nex];
    }
}

void dfs(int now,int par){
    ll ma=0;
    for(auto nex:g[now]) if(nex!=par){
        dfs(nex,now);
        chmax(ma,-dp[nex]);
    }
    ans+=ma;
    dp[now]-=g[now].size()*ma;
    if(par!=-1) dp[par]+=ma;
    for(auto nex:g[now]) if(nex!=par){
        dp[nex]+=ma;
        ans+=dp[nex]*size[nex];
        dp[now]+=dp[nex];
        dp[nex]=0;
    }

    if(dp[now]>0){
        ans+=dp[now]*size[now];
        if(par!=-1) dp[par]+=dp[now];
        dp[now]=0;
    }
}


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

  int N;
  cin>>N;
  g.resize(N);
  rep(i,N-1){
      int a,b;
      cin>>a>>b;
      a--;b--;
      g[a].push_back(b);
      g[b].push_back(a);
  }
  A.resize(N);
  rep(i,N) cin>>A[i];
  B.resize(N);
  rep(i,N) cin>>B[i];

  int root=0;
  rep(i,N) if(g[i].size()==1) root=i;
  size.resize(N);
  sizedfs(root,-1);

  dp.resize(N);
  rep(i,N) dp[i]=A[i]-B[i];
  dfs(root,-1);

  cout<<ans<<endl;

  return 0;
}



Measured memory_bytes: 18912
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <iomanip>
using namespace std;
#define all(x) x.begin(), x.end()
typedef vector <int> vi;
typedef pair<int,int> ii;
typedef long long ll;
typedef long double ld;
const int mod = 1e9 + 7;
const ll inf = 3e18 + 5;
int add(int a, int b) { return (a += b) < mod ? a : a - mod; }
int mul(int a, int b) { return 1LL * a * b % mod; }
int sub(int a, int b) { return (a -= b) < 0 ? a + mod : a; }
int ctz(int x) { return __builtin_ctz(x); }
int clz(int x) { return __builtin_clz(x); }

int main(){
  ios_base::sync_with_stdio(false); cin.tie(0);
  #ifdef LOCAL
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  #endif

  int n, k, s;
  cin >> n >> k >> s;
  for(int i = 0; i < k; i++){
    cout << s << " ";
  }
  for(int i = 0; i < n - k; i++){
    if(s == 1e9) cout << 1 << " ";
    else{
      cout << int(1e9) << " ";
    }
  }
}

Measured memory_bytes: 1280
def main():
    INF = float('inf')
    H,N = map(int,input().split())
    AB = [list(map(int,input().split())) for _ in range(N)]
    maxA = max(A for A,B in AB)
    dp = [INF]*(H+maxA)
    dp[0] = 0
    for i in range(H+maxA):
        if i <= 0:
            dp[i] = 0
        else:
            dp[i] = min(dp[i-A]+B for A,B in AB)
    print(min(dp[H:]))

if __name__ == '__main__':
    main()


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

using ll=long long;

const int MAX = 2200000;
const long long MOD = 1000000007;
long long INF = 90000000001000;


int main() {

    int n;cin >> n;
    vector<int> x(n),y(n);
    double ave;
    double sum=0.0;
    for (int i = 0; i < n; ++i)
    {
       cin >> x[i] >> y[i];
    }
    auto dist = [&](int i,int j){
        double dx = x[i]-x[j];
        double dy = y[i]-y[j];
        return sqrt(dx*dx+dy*dy);
    };
    int cnt=0;
    vector<int> p(n);
    for (int i = 0; i < n; ++i)
    {
       p[i] = i;
    }
    do{
        for (int i = 0; i < n-1; ++i)
        {
           sum += dist(p[i],p[i+1]);
        }
        cnt++;
    } while(next_permutation(p.begin(),p.end()));

    ave = sum/cnt;
    printf("%.10f\n", ave);
return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  int a[n+1], b[n+1], c[n+1];
  for(int i=1;i<=n;i++) cin>>a[i]>>b[i]>>c[i];
  int dp[n+1][4];
  dp[1][1]=a[1];
  dp[1][2]=b[1];
  dp[1][3]=c[1];
  for(int i=2;i<=n;i++)
  {
    dp[i][1]=max(dp[i-1][2],dp[i-1][3])+a[i];
    dp[i][2]=max(dp[i-1][1],dp[i-1][3])+b[i];
    dp[i][3]=max(dp[i-1][1],dp[i-1][2])+c[i];
  }
  cout<<max(dp[n][1],max(dp[n][2],dp[n][3]));
}

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

typedef long long int ll;

int main()
{
    vector<ll> a(5);
    for(ll i = 0;i < 5;i++){
        cin >> a[i];
    }

    for(ll i = 0;i < 5;i++){
        if(a[i] == 0){
            cout << i + 1;

            return 0;
        }
    }

    return 0;
    
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(i,a,b) for (int i=a; i<b; ++i)
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int K,X;
    cin >> K >> X;
    for (int i=X-K+1; i<=X+K-1; i++) cout << i << " ";
    cout <<  "\n";
    return 0;
}

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


struct P{
  P(int a,double b){
    num=a;
    time=b;
  }
  int num;
  double time;
};

bool operator<(P a,P b){
  if(a.time!=b.time){
    return a.time<b.time;
  }else{
    return a.num<b.num;
  }
}

vector<P> g[3];
vector<P> all;
void solve(){
  for(int i=0;i<3;i++){
    for(int j=0;j<8;j++){
      int t1;
      double t2;
      cin>>t1>>t2;
      g[i].push_back(P(t1,t2));
    }
    sort(g[i].begin(),g[i].end());
  }
  for(int i=2;i<8;i++){
    for(int j=0;j<3;j++){
      all.push_back(g[j][i]);
    }
  }
  sort(all.begin(),all.end());

  for(int i=0;i<3;i++){
    for(int j=0;j<2;j++){
      cout<<g[i][j].num<<" "<<fixed<<setprecision(2)<<g[i][j].time<<endl;
    }
  }
  cout<<all[0].num<<" "<<fixed<<setprecision(2)<<all[0].time<<endl;
  cout<<all[1].num<<" "<<fixed<<setprecision(2)<<all[1].time<<endl;
}

int main(){
  solve();
}

Measured memory_bytes: 1300
import java.util.Scanner;

/** top-down syntax analysis (BNF) */
public class Main {
	private static int pos;
	private static int p;
	private static int q;
	private static int r;
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true){
			String input = sc.nextLine();
			if(input.equals(".")) break;
			
			int count = 0;
			for(p = 0; p < 3; p++){
				for(q = 0; q < 3; q++){
					for(r = 0; r < 3; r++){
						pos = 0;
						int ret = formula(input);
						if(ret == 2) count++;
					}
				}
			}
			System.out.println(count);
		}
	}

	private static int formula(String input){
		char c = input.charAt(pos++);
		
		if(c == '0') return 0;
		if(c == '1') return 1;
		if(c == '2') return 2;
		if(c == 'P') return p;
		if(c == 'Q') return q;
		if(c == 'R') return r;
		
		if(c == '-'){
			int ret = formula(input);
			return (2 - ret);
		}
		
		// c = '('
		int n1 = formula(input);
		boolean multi = (input.charAt(pos++) == '*');
		int n2 = formula(input);
		pos++;/*   next char   <-   c = ')' */
		if(multi){
			/* (2 * 2 = 2) , (1 * 1 = 1), (0 * 0 = 0) */
			if(n1 == n2) return n1;
			if(n1 * n2 > 0) return 1;/* (1 * 2 = 1) */
			return 0;/* (0 * ? = 0) */
		}else{
			return Math.max(n1, n2);/* n1 + n2 */
		}
	}
}

Measured memory_bytes: 27608
s = input()
K = int(input())
N = len(s)
substrs = []
for i in range(N):
    substrs.append(s[i:])
substrs.sort()
k = 0
prev = ''
for t in substrs:
    L = min(len(prev),len(t))
    i = 0
    while i < L and prev[i] == t[i]:
        i += 1
    for j in range(i+1,len(t)+1):
        k += 1
        if k == K:
            print(t[:j])
            exit()
    prev = t

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

int main(){
	int m;
	while(cin>>m&&m){
		int ans=1<<30;
		for(int i=0;i<=m/500;i++){
			int a=i/3*3*850*88/100;
			a += i%3*850;
			for(int j=0;j<=(m-i*500)/300;j++){
				int b=j/4*4*550*85/100;
				b += j%4*550;
				if((m-i*500-j*300)%200)continue;
				int k=(m-i*500-j*300+199)/200,c;
				c=k/5*5*380*80/100;
				c += k%5*380;
				ans=min(ans,a+b+c);
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}

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

using namespace std;

using ll = long long int;

int main() {
    // Input
    ll A;
    long double B;
    cin >> A >> B;

    // Process
    ll ans = (ll)(A * B);

    // Output
    cout << ans << endl;

    return 0;
}


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

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

#define rep(i,n) for(int i=1;i<=n;i++)
#define pb push_back 
#define inf INT_MAX/4 
#define ALL(v) v.begin(),v.end()
#define N 1001

int c[N][N];

int lcs(string X, string Y){
  int lx = X.size();
  int ly = Y.size();
  int ans = 0;

  X = ' ' + X;
  Y = ' ' + Y;

  rep(i,lx) rep(j,ly) c[i][j] = 0;

  rep(i,lx){
   rep(j,ly){
    if(X[i] == Y[j]){
      c[i][j] = c[i-1][j-1] + 1;
    }else{
      c[i][j] = max(c[i-1][j], c[i][j-1]);
    }
    ans = max(ans, c[i][j]);
   }
  }

  return ans;
}

int main(void){

  int q;

  cin >> q;

  while(q--){
    string X, Y;
    cin >> X >> Y;

    cout << lcs(X, Y) << endl;
  
  }

  return 0;
}


Measured memory_bytes: 7048