akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;
int main()
{
	char a,b,c,d;
	cin >> a >> b >> c >> d;
	if(a==b || b==c || c==d){
		cout << "Bad" << endl;
		return 0;
	}
	cout << "Good" << endl;
	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
string A,B,C;
int main()
{
	cin>>A>>B>>C;
	char a=A[0]-32;
	char b=B[0]-32;
	char c=C[0]-32;
	cout<<a<<b<<c<<endl;
}


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

using namespace std;

int main(void) {
  int A, B;
  cin >> A >> B;

  vector<int> a(A), b(B);
  for (int i = 0; i < A; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < B; i++) {
    cin >> b[i];
  }

  int ans = 0;
  for (int i = 0; i < B; i++) {
    int pos = 0;
    for (int j = i; j < B; j++) {
      while (pos < A && a[pos] != b[j]) pos++;
      if (a[pos] != b[j]) {
        ans = max(ans, j - i);
        break;
      }
      pos++;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3092
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Queue;
import java.util.Scanner;
 


public class Main {
	static int a1[]= {0,-1,0,1};
	static int b1[]= {-1,0,1,0};
	private static         Scanner sc = new Scanner(System.in);
	//result = Math.pow(num1, num3)
	//StringBuffer str = new StringBuffer(hoge1);
	//String hoge2 = str.reverse().toString();
	//map.containsKey(A)

	//Map<String, Integer> map = new HashMap<String, Integer>(n);
	/*for ( キーのデータ型 key : マップの名前.keySet() ) {
		データのデータ型 data = マップの名前.get( key );
		
		// keyやdataを使った処理;
	}*/
	//int i = Integer.parseInt(s);
	//Queue<String> qq=new ArrayDeque<>(); //add,poll,peek
	//Deque<String> qq=new ArrayDeque<>();//push,pop,peek
	//ArrayList<String> cc = new ArrayList<>(n);
	//Collections.sort(list);
	//Array.sort(list);   cc.contains(tmp)
	//Arrays.asList(c).contains("a")
	//list.set(1,"walk");//1 1 2 3 5
	static int K,N;
	static long mod =1000000007;

	public static void main(String[] args) {

		long X=sc.nextLong();
		long Y=sc.nextLong();
		
		long ans=0;
		while(X<=Y) {
			ans++;
			X*=2;
		}
		p(ans);
	}
	//N==S
	//E==W
//83 S 
	//69E
	//78N
	//87W
	
	//static ArrayList<Integer> cc = new ArrayList<>(10001);
	
	static void p(String ans) {System.out.println(ans);};
	static void p(int ans) {System.out.println(ans);};
	static void p() {System.out.println();};
	static void p(long ans) {System.out.println(ans);};
	static void p(double ans) {System.out.println(ans);};
	public static int gcd(int a, int b) {
        return b == 0 ? a: gcd(b, a % b);
	}
	static String nextPermutation(String s) {
		ArrayList<Character> list=new ArrayList<>();
		for(int i=0;i<s.length();i++) {
			list.add(s.charAt(i));
		}
		int pivotPos=-1;
		char pivot=0;
		for(int i=list.size()-2;i>=0;i--) {
			if(list.get(i)<list.get(i+1)) {
				pivotPos=i;
				pivot=list.get(i);
				break;
			}
		}
		if(pivotPos==-1&&pivot==0) {
			return "Final";
		}
		int L=pivotPos+1,R=list.size()-1;
		
		
		
		int minPos=-1;
		char min =Character.MAX_VALUE;
		
		for(int i=R;i>=L;i--) {
			if(pivot<list.get(i)) {
				if(list.get(i)<min) {
					min=list.get(i);
					minPos=i;
				}
			}
		}
		
		Collections.swap(list, pivotPos, minPos);
		Collections.sort(list.subList(L, R+1));
		
		
		StringBuilder sb=new StringBuilder();
		for(int i=0;i<list.size();i++) {
			sb.append(list.get(i));
		}
		return sb.toString();
	}
}
	


Measured memory_bytes: 23124
#include <bits/stdc++.h>
#define repr(i,from,to) for(int (i)=(from);(i)<(to);(i)++)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
#define vprint(x) for(auto a:(x)) cout << x << endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;

int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;cin>>n;
    int h[n]={};
    rep(i,n){
        cin>>h[i];
    }
    int res=0,now=0;
    repr(i,1,n){
        if(h[i-1]>=h[i]){
            now++;
        }else{
            now=0;
        }
        res = max(res,now);
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
typedef pair<ll, ll> P;
#define ALL(v) v.begin(),v.end()

const int MOD = 1000000007;
const int MAX = 5100000;
ll gcd(ll a, ll b) {
    return (b==0) ? a : gcd(b, a%b);
}

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

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

// 以下から
const int MAX_N = 100000;
struct Edge {
    int to;
    int id;
};

const int D = 80 * 160 + 10;
const int D2 = D*2;
typedef bitset<D2> bs;
int a[100][100];
bs dp[90][90];



const int N = 20;
int h;
int w;
vector<vector<char>> maze(N, vector<char>(N,'#'));

const int MAX_WH = 21;
int d[MAX_WH][MAX_WH];
int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};
const int INF = 100000;
int bfs(int x, int y) {
    queue<P> que;
    rep(i,MAX_WH) {
       rep(j,MAX_WH) {
            d[j][i] = INF;
        }
    }
    que.push(P(x,y));
    d[x][y] = 0;

    while (que.size()) {
        P p = que.front(); que.pop();
        for (int i=0; i< 4; i++) {
            int nx = p.first + dx[i];
            int ny = p.second + dy[i];
            if (0 <= nx && nx < w && 0 <= ny && ny < h && maze[nx][ny] != '#' && d[nx][ny] == INF) {
                que.push(P(nx,ny));
                d[nx][ny] = d[p.first][p.second] + 1;
            }
        }
    }
    int mx = 0;
    rep(i,h) rep(j,w) {
        if (d[j][i] == INF) continue;
        mx = max(mx, d[j][i]);
    }
    return mx;
}
int main(){
    int h,w,n; cin >> h >> w >> n;
    int ans = 0;
    int sum = 0;
    while (true) {
        sum += h > w ? h : w;
        ans++;
        if (sum >= n) break;
    }
    cout << ans << endl;
    return 0;
}


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

buf = c - a - b

#if pow(a, 2) + pow(b, 2) + pow(c, 2) - 2*a*b - 2*b*c - 2*c*a > 0 :
if buf > 0 and buf ** 2 > 4 * a * b :
    print('Yes')
else :
    print('No')


Measured memory_bytes: 3060
<?php
	fscanf(STDIN, "%d %d", $N, $K);

	if($N < $K){
		echo "1";
	} elseif($N === $K) {
		echo "0";
	} elseif($N > $K) {
 		$quo = $N / $K;
 		$rem = $N % $K;
		if($rem === 0){
			echo "0";
		}else{
			echo "1";
		}
	}

?>

Measured memory_bytes: 3700
#include<bits/stdc++.h>
#define ll long long
#define debug(x) {cerr<<#x<<" = "<<(x)<<endl;}
#define M(x) memset(x,0,sizeof(x))
using namespace std;
vector<int>v[100005];
int n,m,ltk=0;
bool vis[100005];
void bfs(int s)
{
    queue<int>q;
    q.push(s);
    vis[s]=true;
    while(!q.empty())
    {
        int now=q.front();
        q.pop();
        for(int i=0;i<v[now].size();i++)
        {
            int nxt=v[now][i];
            if(!vis[nxt])
            {
                vis[nxt]=true;
                q.push(nxt);
            }
        }
    }
}
int main()
{
    ios::sync_with_stdio(false);
    cin>>n>>m;
    M(vis);
    for(int i=1;i<=m;i++)
    {
        int x,y;
        cin>>x>>y;
        v[x].push_back(y);
        v[y].push_back(x);
    }
    for(int i=1;i<=n;i++)
    {
        if(!vis[i])
        {
            bfs(i);
            ltk++;
        }
    }
    cout<<ltk-1;
    return 0;
}


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

const int N = 5005, MOD = 1e9 + 7;
ll dp[N][N][2], w[N], dp2[N][N][2];
vector<int> g[N];
int sz[N];

void dfs(int node, int anc) {
	sz[node] = 1;

	int q = 0;

	for (int to : g[node]) {
		if (to != anc) {
			dfs(to, node);
		}
	}

	for (int i = 0; i <= g[node].size(); i++) {
		for (int j = 0; j < N; j++) {
			dp2[i][j][0] = dp2[i][j][1];
		}
	}

	dp2[0][1][0] = 1;

	for (int to : g[node]) {
		if (to != anc) {
			for (int i = sz[node]; i > 0; i--) {
				for (int j = 0; j < 2; j++) {
					for (int k = 1; k <= sz[to]; k++) {
						for (int h = 0; h < 2; h++) {
							dp2[q + 1][i + k][j ^ h] = 
								(dp2[q + 1][i + k][j ^ h] + dp2[q][i][j] * dp[to][k][h]) % MOD;
							if (!(k & 1)) {
								/*if (node == 1 && dp2[q][i][j] && k == 2 && h == 0) {
									cout << 
								}*/
								dp2[q + 1][i][j ^ h ^ 1] = (dp2[q + 1][i][j ^ h ^ 1] + 
									dp2[q][i][j] * dp[to][k][h] % MOD * w[k]) % MOD;
							}
						}
					}
				}
			}
			sz[node] += sz[to];
			q++;
		}
	}

	for (int i = 1; i <= sz[node]; i++) {
		for (int j = 0; j < 2; j++) {
			dp[node][i][j] = dp2[q][i][j];
		}
	}
}

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

    int n;
    cin >> n;

    for (int i = 0; i < n - 1; i++) {
    	int x, y;
    	cin >> x >> y;
    	x--, y--;
    	g[x].push_back(y);
    	g[y].push_back(x);
    }

    w[0] = 1;
    for (int i = 2; i <= n; i += 2) {
    	w[i] = w[i - 2] * (i - 1) % MOD;
    }

    dfs(0, -1);

    ll ans = 0;

    for (int i = 2; i <= n; i += 2) {
    	for (int j = 0; j < 2; j++) {
    		ll cur = dp[0][i][j] * w[i] % MOD;

    		// if (dp[0][i][j]) {
    		// 	cout << i << " " << j << " " << dp[0][i][j] << "\n";
    		// }

    		if (j)
    			ans = (ans + MOD - cur) % MOD;
    		else
    			ans = (ans + cur) % MOD;
    	}
    }

    cout << ans;

    return 0;   
}

Measured memory_bytes: 782848
n = int(input())
c = []
for i in range(1,n+1):
    k = []
    for j in range(1,i+1):
        if i % j == 0:
            k.append(j)

    if len(k) == 8:
        if i % 2 != 0:
            c.append(i)
print(len(c))

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

primes = [2]
for x in range(3, 55556):
    chk = True
    for tmp in primes:
        if tmp ** 2 > x:
            break
        if x % tmp == 0:
            chk = False
    if chk:
        primes.append(x)

p2 = []
for prime in primes:
    if prime % 5 == 1:
        p2.append(prime)

p3 = p2[:n]

print(' '.join([str(pp) for pp in p3]))


Measured memory_bytes: 40940
#include <bits/stdc++.h>
#include <math.h>//pow(x,y)=x^y
#include <algorithm>//sort(a.begin(), a.end());reverse(a.begin(), a.end());
#define rep(init,i,n) for (int i=init; i <(n);i++)
#define ll long long
using namespace std;


int main() {
int n,x,t;
cin>>n>>x>>t;
if(n%x==0){
    cout<<(n/x)*t;
}else{
    cout<<(n/x+1)*t;
}

}

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

using namespace std;

char s[100010];
int a[100010];
int N;

int main()
{
    scanf("%s",s + 1);
    N = strlen(s + 1);
    for (char c='a';c<='z';c++)
    {
        for (int i=1;i<=N;i++)a[i] = (s[i] == c ? 1 : -1);
        int S = 0, last = 1;
        bool debug = (c == 'e');
        for (int i=1;i<=N;i++)
        {
            S += a[i];
            //printf("%d %d %d\n",last,i,S);
            if (i > last && S > 0)
            {
                printf("%d %d\n",last,i);
                return 0;
            }
            if (S < 0)
            {
                last = i + 1;
                S = 0;
            }
        }
    }
    puts("-1 -1");
}


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

using namespace std;
typedef long long ll ;
const int N = 1e5 + 2 , OO = 0x3f3f3f3f ;
ll arr1[N]  , arr2[N] , arr3[N], mem[102][N];
int n , w ;
ll solve(int idx , int value){
    if(value <=0 )
        return 0;
    if(idx == n)
        return OO;
    ll &ret = mem[idx][value];
    if(~ret)
        return ret;
    ret  = OO;
   ret = min(ret , min(solve(idx +1 , value) , solve(idx +1 , value - arr2[idx]) + arr1[idx]));
    return ret;
}
int main()
{
    cin >> n >> w ;
    for(int i = 0 ; i < n ; ++i) cin >> arr1[i] >> arr2[i];
    memset(mem , -1 , sizeof mem);
    for(int i = 100001 ; i>=0 ; --i){
        if(solve(0 , i) <= w){
            cout << i ;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 82176
package main

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

var scanner = bufio.NewScanner(os.Stdin)

type Point struct {
	x, y float64
}
func main() {
	for scanner.Scan() {
		buf1 := strings.Split(scanner.Text(), " ")
		line1 := make([]float64, len(buf1))
		for i := range line1 {
			line1[i], _ = strconv.ParseFloat(buf1[i], 64)
		}
		if line1[0] == 0 && line1[1] == 0 &&
			line1[2] == 0 && line1[3] == 0 {
				break
		}
		scanner.Scan()
		buf2 := strings.Split(scanner.Text(), " ")
		line2 := make([]float64, len(buf2))
		for i := range line2 {
			line2[i], _ = strconv.ParseFloat(buf2[i], 64)
		}
		scanner.Scan()
		buf3 := strings.Split(scanner.Text(), " ")
		line3 := make([]float64, len(buf3))
		for i := range line2 {
			line3[i], _ = strconv.ParseFloat(buf3[i], 64)
		}
		if !intersect(line1[0], line1[1], line1[2], line1[3], line2[0], line2[1], line2[2], line2[3]) ||
			!intersect(line2[0], line2[1], line2[2], line2[3], line3[0], line3[1], line3[2], line3[3]) ||
			!intersect(line3[0], line3[1], line3[2], line3[3], line1[0], line1[1], line1[2], line1[3]) {
				fmt.Println("kyo")
		} else {
			p1 := intersection(line1[0], line1[1], line1[2], line1[3], line2[0], line2[1], line2[2], line2[3])
			p2 := intersection(line2[0], line2[1], line2[2], line2[3], line3[0], line3[1], line3[2], line3[3])
			p3 := intersection(line3[0], line3[1], line3[2], line3[3], line1[0], line1[1], line1[2], line1[3])
			area := math.Abs((p2.x - p1.x) * (p3.y - p1.y) - (p2.y - p1.y) * (p3.x - p1.x))/2
			if area < 0.00000001 {
				fmt.Println("kyo")
			} else if 1899999.99999999 < area {
				fmt.Println("dai-kichi")
			} else if 999999.99999999 < area {
				fmt.Println("chu-kichi")
			} else if 99999.99999999 < area {
				fmt.Println("kichi")
			} else {
				fmt.Println("syo-kichi")
			}
		}
	}
}

func cross(x1, y1, x2, y2 float64) int {
	z :=  x1 * y2 - y1 * x2
	if 0 < z {
		return 1
	} else if z < 0 {
		return -1
	} else {
		return 0
	}
}

func intersect(x1, y1, x2, y2, x3, y3, x4, y4 float64) bool {
	if 0 <= cross(x2-x1, y2-y1, x3-x1, y3-y1) *
		cross(x2-x1, y2-y1, x4-x1, y4-y1) {
			return false
	}
	if 0 <= cross(x4-x3, y4-y3, x1-x3, y1-y3) *
		cross(x4-x3, y4-y3, x2-x3, y2-y3) {
			return false
	}
	return true
}

func intersection(x1, y1, x2, y2, x3, y3, x4, y4 float64) Point {
	if x3 == x4 {
		x1, x3 = x3, x1
		y1, y3 = y3, y1
		x2, x4 = x4, x2
		y2, y4 = y4, y2
	}
	ret := Point{}
	if x1 == x2 {
		// y軸に平行な直線の場合
		c := (y4 - y3) / (x4 - x3)
		d := y3 - c * x3
		x := x1
		y := c * x + d
		ret.x, ret.y = x, y
	} else {
		a := (y2 - y1) / (x2 - x1)
		b := y1 - a * x1
		c := (y4 - y3) / (x4 - x3)
		d := y3 - c * x3
		x := (d - b) / (a - c)
		y := a * x + b
		ret.x, ret.y = x, y
	}
	return ret
}


Measured memory_bytes: 1088
#include <bits/stdc++.h>
using namespace std;
long long  x,y,a,b,c,p[100005],q[100005],top,ans,k;
priority_queue<long long > pq3;
priority_queue <long long , vector<long long >, greater<long long > > pq1,pq2;
bool cmp(long long  a, long long  b){return a>b;}
int  main(){
    cin>>x>>y>>a>>b>>c;
    for(long long  i =1;i<=a;i++){
        cin>>p[i];
    }
    for(long long  i =1;i<=b;i++)cin>>q[i];
    for(long long  i =1;i<=c;i++){
        cin>>k;
        pq3.push(k);
    }
    sort(p+1,p+a+1,cmp);
    sort(q+1,q+b+1,cmp);
    for(long long  i =1;i<=min(x,a);i++)pq1.push(p[i]);
    for(long long  i =1;i<=min(b,y);i++)pq2.push(q[i]);
    // if(x-pq1.size()>y-pq.size()){
    while(pq1.size()<x&&pq3.empty()){
        pq1.push(pq3.top());
        pq3.pop();
    }
    while(pq2.size()<y&&!pq3.empty()){
        pq2.push(pq3.top());
        pq3.pop();
    }
    while(!pq3.empty()&&pq3.top()>min(pq1.top(),pq2.top())){
        top = pq3.top();
        if(pq1.top()>pq2.top()){
            pq2.pop();
            pq2.push(top);
        }
        else{
            pq1.pop();
            pq1.push(top);
        }
        pq3.pop();
    }
    while(!pq1.empty()){
        ans+=pq1.top();
        pq1.pop();
    }
    while(!pq2.empty()){
        ans+=pq2.top();
        pq2.pop();
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 4852
#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 chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define out(a) cout << a << endl
#define SZ(v) (int)v.size()
#define inf (int)(1e9+7)

int main() {
    string s, t; cin >> s >> t;
    string ss = s, tt = t;
    reverse(all(s));
    reverse(all(t));
    if (tt == s && ss == t) out("YES");
    else out("NO");
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<climits>
#include<set>
#include<utility>
#include<typeinfo>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD=1e9+7;

int main(){

	string s;
	cin >> s;
	int ans=0;
	for(int i=0; i<s.size(); i++){
		cout << s[i];
		if(i==3){
			cout << " ";
		}
	}
	cout << endl;

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
int a[10001];
int main()
{
	int n,m,i,j,k,p,l=1,s=0;
	for(i=0;i<=9;i++)
	{
		for(k=0;k<=9;k++)
	    {
	    	for(j=0;j<=9;j++)
	        {
	        	for(p=0;p<=9;p++)
	            {
		             a[l]=i+k+j+p;
		             l++;
	            }
		
	        }
	    }
	}
	while(cin>>n)
	{
		s=0;
		for(i=1;i<=10000;i++)
		{
			if(a[i]==n)s++;
		}
		cout<<s<<endl;
	}
	return 0;
}

Measured memory_bytes: 3104
import fractions as frac

A,B,K = [int(i) for i in input().split()]

cd_list = []
for i in range(1,max(A,B)+1) :
    if (A % i == 0 and B % i == 0) :
        cd_list.append(i)
        # if (len(cd_list) >= K) :
        #     break

print(cd_list[-K])

Measured memory_bytes: 5048
X = int(input())
mod = X % 100
q = int(X //100)
sum = 0
ans = 0
if q >= 20:
    ans = 1
else:
    for i in range (0,q+1):
        for j in range (0,q+1-i):
            for k in range (0,q+1-i-j):
                for l in range (0,q+1-i-k-j):
                    for m in range (0,q+1-i-j-k-l):
                        sum = i+(2*j)+(3*k)+(4*l)+(5*m)
                        if sum == mod:
                            ans = 1
print(ans)


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

using namespace std;

int main(int argc, char const *argv[]) {
    int nodes;
    cin >> nodes;
    vector<vector<pair<int, int>>> tree(nodes + 1);
    int node_1, node_2;
    for (auto i = 1; i < nodes; ++i)
    {
        cin >> node_1 >> node_2;
        tree[node_1].emplace_back(make_pair(node_2, i));
        tree[node_2].emplace_back(make_pair(node_1, i));
    }
    queue<pair<int, int>> flood;
    flood.emplace(make_pair(1, 0));
    vector<int> ans(nodes);
    while (!flood.empty())
    {
        // auto [node, in] = flood.front();
        auto flood_x = flood.front();
        auto node = flood_x.first, in = flood_x.second;
        flood.pop();
        decltype(in) i = 0;
        // for (auto [child, ans_idx]: tree[node])
        for (auto tree_x: tree[node])
        {
            auto child = tree_x.first, ans_idx = tree_x.second;
            if (!ans[ans_idx])
            {
                ++i;
                if (i == in)
                    ++i;
                ans[0] = i > ans[0] ? i : ans[0];
                ans[ans_idx] = i;
                flood.emplace(make_pair(child, i));
            }
        }
    }

    for (auto x: ans)
        cout << x << "\n";

    return 0;
}


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

#define INF 1001001001
#define LINF 1001001001001001001
#define MOD 1000000007
#define MOD2 998244353

template<class T,class U>bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U>bool chmin(T &a, const U &b){if(b<a){a=b;return 1;}return 0;}

#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define rep1(i,a,b) for(int a_=(a),b_=(b),i=a_;i<b_;++i)
#define repr(i,n) for(int _i=(n),i=_i;i>0;--i)

#define db(x) cerr<<#x<<" = "<<x<<" ";
#define db2(x,y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<") ";
#define db3(x,y,z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = ("<<x<<", "<<y<<", "<<z<<") ";
#define ln cout<<endl;

#define all(a)  (a).begin(),(a).end()
#define dig(n)  to_string(n).length()

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define se second
#define fi first

typedef long long ll;

typedef pair<int,int> P;
typedef pair<int,P> iP;
typedef pair<P,P> PP;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return (a*b)/gcd(a,b);}

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

int main(){

    bool flag=false;
    ll ans=0,sum=0;

    string s;
    cin>>s;
    int l = s.length();

    rep1(i,1,l+1){
        rep1(j,0,(l+1-i)){
            string tmp = s;
            tmp.erase(i,j);

            if(tmp=="keyence"){flag=true;break;}
        }
    }

    //cout <<fixed<<setprecision(16)<< << endl;
    if(flag)cout << "YES" <<endl;
    else cout << "NO" <<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i];if(i<len-1) s<<" ";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i]<<endl;
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){
	s<<"{ ";
	for(auto itr=v.begin();itr!=v.end();++itr) {
		if (itr!=v.begin()) {s<< ", ";}
		s<<(*itr);
	}
	s<<" }";
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){
	s<<"{"<<endl;
	for(auto itr=m.begin();itr!=m.end();++itr){
		s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;
	}
	s<<"}"<<endl;
	return s;
}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

template<typename Monoid,typename F>
struct SegmentTree{
	int sz;
	vector<Monoid> node;
	const F op;//演算
	const Monoid e;//単位元
	SegmentTree(int n,const F op,const Monoid &e):op(op),e(e){
		sz=1;
		while(sz<n) sz*=2;
		node.assign(2*sz,e);
	}
	void build(const vector<Monoid> &v){
		int n=v.size();
		for(int i=0;i<n;i++) node[i+sz-1]=v[i];
		for(int i=sz-2;i>=0;i--) node[i]=op(node[2*i+1],node[2*i+2]);
	}
	void update(int k,const Monoid &x){
		k+=sz-1;
		node[k]=x;
		while(k>0){
			k=(k-1)/2;
			node[k]=op(node[2*k+1],node[2*k+2]);
		}
	}
	Monoid query(int a,int b,int k=0,int l=0,int r=-1){
		if(r<0) r=sz;
		if(r<=a || b<=l) return e;
		if(a<=l && r<=b) return node[k];
		else{
			Monoid vl=query(a,b,2*k+1,l,(l+r)/2);
			Monoid vr=query(a,b,2*k+2,(l+r)/2,r);
			return op(vl,vr);
		}
	}
	Monoid operator[](const int &k)const{
		return node[k+sz-1];
	}
};

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin>>n;
	string s;
	cin>>s;
	auto op=[](int a,int b){return a+b;};
	SegmentTree<int,decltype(op)> seg1(n+10,op,0),seg2(n+10,op,0);
	rep(i,n){
		if(s[i]=='E') seg1.update(i,1);
		else seg2.update(i,1);
	}
	int ans=INF;
	rep(i,n){
		chmin(ans,seg2.query(0,i)+seg1.query(i+1,n));
	}
	cout<<ans<<endl;
}

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

int main(){
    int k,a,b;
    cin >> k >> a >> b;
    bool flag = false;
    for(int i = a; i <= b; i++) {
        if(i % k == 0) flag = true;
    }
    cout << (flag ? "OK" : "NG") << endl;
}


Measured memory_bytes: 3612
import sys
import math
import queue
import copy
import bisect#2分探索
from collections import deque #popleft(), appendleft(x)
##listでqueの代用をするとO(N)の計算量がかかってしまうので注意

def input(): return sys.stdin.readline()[:-1]
def printl(li): print(*li, sep="\n")
def argsort(s): return sorted(range(len(s)), key=lambda k: s[k])

#mod = 10**9+7

N = int(input())
#N, K = map(int, input().split())
#L = [int(input()) for i in range(N)]
#A = list(map(int, input().split()))
#S = [inputl() for i in range(H)]
#q = queue.Queue() #q.put(i) #q.get() 
#q = queue.LifoQueue() #q.put(i) #q.get() 

#a= [[0]*3 for i in range(5)] #2次元配列はこう準備、[[0]*3]*5だとだめ
#b=copy.deepcopy(a)  #2次元配列はこうコピーする
#w.sort(key=lambda x:x[1],reverse=True)  #二個目の要素で降順並び替え

#素数リスト
# n = 100
# primes = set(range(2, n+1))
# for i in range(2, int(n**0.5+1)):
#     primes.difference_update(range(i*2, n+1, i))
# primes=list(primes)

#bisect.bisect_left(a, 4)#aはソート済みである必要あり。aの中から4未満の位置を返す。rightだと以下
#bisect.insort_left(a, 4)#挿入
a=set()
for i in range(N):
    s=input()
    a.add(s)
print(len(a))

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

int main() {

	int H, W, N;

	cin >> N >> H >> W;

	int t = 0;
	int A, B;

	for (int i = 0; i < N; i++) {
		cin >> A >> B;

		if (A >= H && B >= W) {
			t++;
		}
	}

	cout << t << endl;

	return 0;
}

Measured memory_bytes: 256
import sys
import bisect
input = sys.stdin.readline

A, B, Q = map(int, input().split())
tera = [int(input()) for _ in range(A)]
sha = [int(input()) for _ in range(B)]
query = [int(input()) for _ in range(Q)]
res = []

for x in query:
    tl = bisect.bisect_left(tera, x)
    tr = bisect.bisect_right(tera, x)
    sl = bisect.bisect_left(sha, x)
    sr = bisect.bisect_right(sha, x)

    if tl == 0:
        temple = [tera[0]]
    elif tr == A:
        temple = [tera[A - 1]]
    else:
        temple = [tera[tl-1], tera[tl]]

    if sl == 0:
        shrine = [sha[0]]
    elif sr == B:
        shrine = [sha[B - 1]]
    else:
        shrine = [sha[sl-1], sha[sl]]

    ans = 10**18
    for t in temple:
        for s in shrine:
            tx = t - x
            sx = s - x
            if tx * sx >= 0:
                a = max(abs(tx), abs(sx))
            else:
                a = min(2 * abs(tx) + abs(sx), 2 * abs(sx) + abs(tx))
            ans = min(ans, a)
    res.append(ans)

print(*res, sep="\n")


Measured memory_bytes: 21780
#include <iostream>
using namespace std;
int n,m,x;
int a[100001];
int main(){
    cin>>n>>m;
    for(int i=0;i<2*m;i++){
        cin>>x;
        a[x]++;
    }
    for(int i=1;i<=n;i++){
        if(a[i]%2){
            cout<<"NO\n";
            return 0;
        }
    }
    cout<<"YES\n";
    return 0;
}

Measured memory_bytes: 640
import sys

N = int(input())
a = [0 for i in range(N)]
b = [0 for i in range(N)]
c = [0 for i in range(N)]

for i in range(N):
    a[i], b[i], c[i] = list(map(int, input().split()))

sa = [0 for i in range(N)]
sb = [0 for i in range(N)]
sc = [0 for i in range(N)]

sa[0] = a[0]
sb[0] = b[0]
sc[0] = c[0]

for i in range(1,N):
    sa[i] = max(sb[i-1], sc[i-1]) + a[i]
    sb[i] = max(sa[i-1], sc[i-1]) + b[i]
    sc[i] = max(sa[i-1], sb[i-1]) + c[i]

#print(max(af[N-1],bf[N-1],cf[N-1],ab[N-1],bb[N-1],cb[N-1]))
print(max(sa[N-1], sb[N-1], sc[N-1]))

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

int main() {
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  
  for(;;){
    c -= b;
    if(c<=0){
      cout << "Yes" << endl;
      break;
    }
    
    a -= d;
    if(a<=0){
      cout << "No" << endl;
      break;
    }
    
  }
}

Measured memory_bytes: 3640
macro_rules! input {
        (source = $s:expr, $($r:tt)*) => {
            let mut iter = $s.split_whitespace();
            input_inner!{iter, $($r)*}
        };
        ($($r:tt)*) => {
            let mut s = {
                use std::io::Read;
                let mut s = String::new();
                std::io::stdin().read_to_string(&mut s).unwrap();
                s
            };
            let mut iter = s.split_whitespace();
            input_inner!{iter, $($r)*}
        };
    }
     
    macro_rules! input_inner {
        ($iter:expr) => {};
        ($iter:expr, ) => {};
     
        ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
            let $var = read_value!($iter, $t);
            input_inner!{$iter $($r)*}
        };
    }
     
    macro_rules! read_value {
        ($iter:expr, ( $($t:tt),* )) => {
            ( $(read_value!($iter, $t)),* )
        };
     
        ($iter:expr, [ $t:tt ; $len:expr ]) => {
            (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
        };
     
        ($iter:expr, chars) => {
            read_value!($iter, String).chars().collect::<Vec<char>>()
        };
     
        ($iter:expr, usize1) => {
            read_value!($iter, usize) - 1
        };
     
        ($iter:expr, $t:ty) => {
            $iter.next().unwrap().parse::<$t>().expect("Parse error")
        };
    }
     
    fn main() {
    	input!{
        	a: u32,
            b: u32,
        }
		if (a + b) % 2 == 0 {
        	println!("{}", (a + b) / 2);
        } else {
			println!("{}", "IMPOSSIBLE");
        }
    }

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

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

#define MAX_E 2010
#define MAX_V 1010

struct edge {
	ll from, to, cost;
};
ll d[MAX_V];
int V, E;

edge es[MAX_E];

void shortest_path(int s) {
	rep(i, 0, V) d[i] = INF;
	d[s] = 0;
	while(true) {
		bool update = false;
		rep(i, 0, E) {
			edge e = es[i];
			if(d[e.from] != INF && d[e.to] > d[e.from] + e.cost) {
				d[e.to] = d[e.from] + e.cost;
				update = true;
			}
		}
		if(!update) break;
	}
}

bool find_negative_loop(int s) {
	//memset(d, 0, sizeof(d));
	fill(d, d + V, INF);
	d[s] = 0;
	rep(i, 0, V) {
		rep(j, 0, E) {
			edge e = es[j];
			if(d[e.from] != INF && d[e.to] > d[e.from] + e.cost) {
				d[e.to] = d[e.from] + e.cost;
				if(i == V - 1 and e.to == V - 1) return true;
			}
		}
	}
	return false;
}

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

	cin >> V >> E;
	rep(i, 0, E) {
		int s, t, d;
		cin >> s >> t >> d;
		es[i].from = --s;
		es[i].to = --t;
		es[i].cost = -d;
	}

	if(find_negative_loop(0)) {
		cout << "inf" << endl;
		return 0;
	}

	if(d[V - 1] != INF) cout << -d[V - 1] << endl;
	else cout << "inf" << endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        var n = int.Parse(Console.ReadLine());
        var list = new List<int>();
        for (int i = 0; i < n; i++)
        {
            list.Add(int.Parse(Console.ReadLine()));
        }

        Console.WriteLine(list.Distinct().Count().ToString());
    }
}

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

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int[] arr = parceIntArray(br.readLine().split(" "));
		int r = arr[0];
		int c = arr[1];
		int[][] sheet = new int[r + 1][c + 1];
		for(int i = 0;i < r;i++){
			arr = parceIntArray(br.readLine().split(" "));
			for(int j = 0;j < arr.length;j++){
				sheet[i][j] = arr[j];
			}
		}
		arr = null;
		for(int i = 0;i < r;i++){
			for(int j = 0;j < c;j++){
				sheet[i][c] += sheet[i][j];
			}
		}
		for(int i = 0;i < c + 1;i++){
			for(int j = 0;j < r;j++){
				sheet[r][i] +=  sheet[j][i];
			}
		}
		for(int i = 0;i < r + 1;i++){
			write(sheet[i]);
		}
	}

	static int[] parceIntArray(String[] strArr){
		int[] arr = new int[strArr.length];
		for(int i = 0;i < arr.length;i++){
			arr[i] = Integer.parseInt(strArr[i]);
		}
		return arr;
	}
	
	static void write(int[] arr){
		StringBuilder sb = new StringBuilder();
		for(int i = 0;i < arr.length;i++){
			sb.append(arr[i]);
			if(i >= arr.length - 1){
				break;
			}
			sb.append(" ");
		}
		System.out.println(sb.toString());
	}
}

Measured memory_bytes: 23356
package main
import (
  "fmt"
  "container/list"
)
const INF = 1<<30
func main() {
  var n int
  var s string
  fmt.Scan(&n)
  g := make([][]int,n)
  d := make([][]int,n)
  for i:=0;i<n;i++ {
    d[i] = make([]int,n)
    fmt.Scan(&s)
    for j,r := range s {
      d[i][j] = INF
      if r == '1' {
        g[i] = append(g[i],j)
        g[j] = append(g[j],i)
        d[i][j] = 1
      }
    }
    d[i][i] = 0
  }
  color := make([]int,n)
  queue := list.New()
  color[0] = 1
  queue.PushBack(0)
  for queue.Len() > 0 {
    i,_ := queue.Remove(queue.Front()).(int)
    for _,j := range g[i] {
      if color[j] == color[i] { fmt.Println(-1);return }
      if color[j] == 0 {
        color[j] = -color[i]
        queue.PushBack(j)
      }
    }
  }
  for k:=0;k<n;k++ {
    for i:=0;i<n;i++ {
      for j:=0;j<n;j++ {
        if d[i][j] > d[i][k]+d[k][j] { d[i][j] = d[i][k]+d[k][j] }
      }
    }
  }
  m := 0
  for i:=0;i<n;i++ {
    for j:=0;j<n;j++ {
      if m < d[i][j] { m = d[i][j] }
    }
  }
  fmt.Println(m+1)
}

Measured memory_bytes: 2688
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <set> 
#include <map>
#include <bitset>
#include <cctype>
#include <cmath>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
typedef long long ll;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

int main () {
    

    int a,b,x; cin >>a>>b>>x;

    if(a <= x && x <= a+b) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    } 

    return 0;
}



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

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

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

int main() {
  int n, pt = 0, px = 0, py = 0, f = 1, t, x, y, r;
  cin >> n;
  for(int i = 0; i < n; i++) {
    cin >> t >> x >> y;
    r = t - pt - abs(x - px) - abs(y - py);
    if(r < 0 || r & 1)
      f = 0;
    pt = t;
    px = x;
    py = y;
  }
  if(f)
    printf("Yes\n");
  else
    printf("No\n");
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
		public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long a =0;
        for(int i=0; i<=N; i++){
           if(i%3==0 && i%5==0){
           }else if(i%3==0 && i%5!=0){
           }else if(i%3!=0 && i%5==0){
           }else if(i%3!=0 || i%5!=0){
           a +=i;		 
           }
        }
          System.out.println(a);
	}
}

Measured memory_bytes: 35776
#include <bits/stdc++.h>
//#include <boost/functional/hash.hpp>
//example: unordered_set< pair<int,int>,boost::hash< std::pair<int, int> > > used;
//priority_queue< pair<int,pair<int,int> >, vector<pair<int,pair<int,int>>>, greater<pair<int,pair<int,int> > > > pqueue;    //cost, vertex(行き先)
using namespace std;

#define MODULE 1000000007
#define MP make_pair
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second

template<class T,class U>inline void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>inline void chmax(T &t,U f){if(t<f)t=f;}
template<typename A, size_t N, typename T>
inline void Fill(A (&array)[N], const T &val){ //usage: int dp[10][10]; Fill(dp,INF);
    std::fill( (T*)array, (T*)(array+N), val );
}

typedef pair<int, int> P;
typedef long long LL;
const int INF = INT_MAX / 2;    //int_max->2*e+9 LLの時はLLONG_MAX
/*const int MAXN = 100001;

struct edge {
    edge(int to, int cost) : to(to), cost(cost) {}
    int to, cost;
};
vector<edge> graph[MAXN];
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, -1, 0, 1};*/

//-----Template---------

LL f(LL a,LL b){
    if(a==0 || b==0)
        return 0;
    if(a>b){
        return f(a%b,b)+b*(a/b)*2;
    }else{
        return f(a,b%a)+a*(b/a)*2;
    }
}
LL n;
LL x;
int main(){
    ios::sync_with_stdio(false); //cout<< fixed << setprecision(10);
    cin>>n>>x;
    LL ans=f(x,n-x)+n-__gcd(n,x);
    cout<<ans<<endl;
}

Measured memory_bytes: 256
a=int(input())
b=int(input())
c=int(input())
x=int(input())
cnt = 0
for i in range(a + 1):
    for j in range(b + 1):
        for k in range(c + 1):
            if x == i * 500 + j * 100 + k * 50:
                cnt += 1
print(cnt)

Measured memory_bytes: 3060
#include <ctime>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <map>
using namespace std;

typedef long long ll;
typedef double lf;
typedef long double Lf;
typedef pair <int,int> pii;
typedef pair <ll, ll> pll;

#define TRACE(x) cerr << #x << "  " << x << endl
#define FOR(i, a, b) for (int i = (a); i < int(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define _ << " " <<

#define fi first
#define sec second
#define mp make_pair

ll n, a, b;

int main() {
  cin >> n >> a >> b;
  if (a > b || n == 1 && a != b) cout << 0 << endl;
  else cout << (b - a) * (n - min(n, 2LL)) + 1 << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  int a, b, c, k;
  scanf("%d%d%d%d", &a, &b, &c, &k);
  if(k<=a){
    printf("%d", k);
  }
  else if(k<=a+b){
    printf("%d", a);
  }
  else{
    printf("%d", 2*a+b-k);
  }
  return 0;
}
    

Measured memory_bytes: 1732
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
char len1[1001], len2[1001];
 
LCS(int x, int y){
  int i,j,c[1001][1001];
 
   for(i=0;i<=x;i++){
      c[i][0]=0;
  }
 
  for(j=0;j<=y;j++){
    c[0][j]=0;
  }
 
  for(i=1;i<=x;i++){
    for(j=1;j<=y;j++){
      if(len1[i-1]==len2[j-1]){
    c[i][j]=c[i-1][j-1]+1;
      }else if(c[i-1][j-1]>=c[i][j-1]){
    c[i][j] = c[i-1][j];
      }else{
    c[i][j] = c[i][j-1];
      }
    }
  }
 
  if(i==0 || j==0){
    return 0;
  }else if(i>0 && j>0 && x == y){
    return c[i-1][j-1];
  }else if(i>0 && j>0 && x!=y){
    return c[x][y];
  }
}
 
main(){
  int n,i,l1,l2,result;
 
  scanf("%d", &n);
   
  for(i=0;i<n;i++){
    scanf("%s",len1);
    scanf("%s",len2);
    l1=strlen(len1);
    l2=strlen(len2);
    
    result=LCS(l1,l2);
    printf("%d\n",result);
  }
  return 0;
}

Measured memory_bytes: 4512
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
int INF = 1000000009;
int main()
{
    int n,m;
    cin >> n >> m;
    vector<int> c(m);
    rep(i, m)
    {
        cin >> c[i];
    }
    int dp[n+1];
    fill(dp,dp+n+1, INF);
    dp[0] = 0;
    rep(i, m)
    {
        rep(j,n+1){
            if(dp[j]==INF)continue;
            if(j+c[i]<=n){
                dp[j + c[i]] = min(dp[j + c[i]], dp[j] + 1);
            }
        }    
    }
    cout << dp[n] << endl;
}


Measured memory_bytes: 3296
#include<stdio.h>

int a[25][3], pre[25], in[25], post[25], p = 0, q = 0, r = 0, list[25] = {0};

int preoder(int x){
	if(x == -1){

	}else {
		pre[p++] = x;
		if(a[x][1] != -1){
			preoder(a[x][1]);
		}
		preoder(a[x][2]);
	}
}

int inoder(int x){
	if(x == -1){

	}else if(a[x][1] != -1){
		inoder(a[x][1]);
		in[q++] = x;
		inoder(a[x][2]);
	} else {
		in[q++] = x;
		inoder(a[x][2]);
	}
}

int postoder(int x){
	if(x == -1){

	}else if(a[x][1] != -1){
		postoder(a[x][1]);
		postoder(a[x][2]);
		post[r++] = x;
	} else {
		postoder(a[x][2]);
		post[r++] = x;
	}
}

int main(){
	int n, i, j, k, c, top;

	scanf("%d", &n);
	for(i = 0; i < n; i++){
		scanf("%d %d %d", &a[i][0], &a[i][1], &a[i][2]);
		list[a[i][1]] = list[a[i][2]] = 1;
	}

	for(i = 0; i < n; i++){
		if(list[i] == 0){
			top = i;
		}
	}

	for(i = 0; i < n; i++){
		for(j = i; j < n; j++){
			if(a[i][0] > a[j][0]){
				for(k = 0; k < 3; k++){
					c = a[i][k];
					a[i][k] = a[j][k];
					a[j][k] = c;
				}
			}
		}
	}

	preoder(top);
	inoder(top);
	postoder(top);

	printf("Preorder\n");
	for(i = 0; i < n; i++){
		printf(" %d", pre[i]);
	}
	printf("\n");

	printf("Inorder\n");
    for(i = 0; i < n; i++){
		printf(" %d", in[i]);
	}
	printf("\n");

	printf("Postorder\n");
    for(i = 0; i < n; i++){
		printf(" %d", post[i]);
	}
	printf("\n");
	
	return 0;
}


Measured memory_bytes: 2056
#include <bits/stdc++.h>
using namespace std;
 
#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) # VariableName
#define LOG(x) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<endl;
#define LOG2(x,y) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<endl;
#define LOG3(x,y,z) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
#define LOG4(w,x,y,z) if(DEBUG)cout<<TO_STRING(w)<<"="<<w<<" "<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
 
template<class T>bool chmax(T & a, const T & b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
 
 
 
void func(long long N, long long K, std::vector<long long> V){
 
    lli ans = -INF;
    for(lli a = 0; a<= min(N,K) ;a++){
        for(lli b=0;a+b <= min(N,K);b++){
            LOG2(a,b);
            priority_queue<lli,vector<lli>,greater<lli>> q;
            REP(i,0,a)q.push(V[i]);
            REP(i,0,b)q.push(V[N-1-i]);
 
            lli leftK = K - (a+b);
            REP(i,0,leftK){
                if(q.size()==0)break;
                if(q.top()<0){
                    q.pop();
                }
            }
            lli sum = 0;
            while(q.size()){
                sum += q.top();
                q.pop();
            }
            chmax(ans,sum);
        }
    }
    cout<<ans<<endl;
 
}
 
int main(){
    // cout << fixed << setprecision(5);
 
    long long N;
    scanf("%lld",&N);
    long long K;
    scanf("%lld",&K);
    std::vector<long long> V(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&V[i]);
    }
    func(N, K, std::move(V));
    return 0;
}

Measured memory_bytes: 256
import scala.math._

object Main extends App {

  val YES = "YES"
  val Yes = "Yes"
  val NO = "NO"
  val No = "No"
  ///////////////////////////////////////////

  val sc = new java.util.Scanner(System.in)
    val n, d = sc.nextInt
  val list = List.fill(n, d)(sc.nextInt)

  def isGoodDistance(l1: List[Int], l2: List[Int]): Boolean = {
    val zipped = l1.zip(l2)
    val tm = zipped.foldLeft(0D){(acc, e) => acc + pow(abs(e._1 - e._2), 2)}
    if (sqrt(tm) % 1 == 0) true else false
  }

  val ans = list.combinations(2).foldLeft(0) {(acc, e) => if (isGoodDistance(e.head, e.last)) acc + 1 else acc}

  println(ans)

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

  def bigIterator(start: BigInt, end: BigInt, step: BigInt = 1) =
    Iterator.iterate(start)(_ + step).takeWhile(_ <= end)

  def lcm(a :Int, b :Int): Int =
    a / gcd(a, b) * b

  def lcm(a :Long, b :Long): Long =
    a / gcd(a, b) * b

  def gcd(a: Int, b: Int): Int =
    if (b == 0) a else gcd(b, a % b)

  def gcd(a: Long, b: Long): Long =
    if (b == 0) a else gcd(b, a % b)

  def setOrUpdated[A, B](a: Map[A, B], key: A, value: B, f: (B, B) => B) =
    a.get(key) match {
      case Some(v) => a.updated(key, f(value, v))
      case _ => a + (key -> value)
    }
}

Measured memory_bytes: 27328
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define debug(x) cout << #x << " = " << (x) << endl;
#define SUM(x) accumulate(rng(x),0)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = 1<<30;
const ll INFLL = 1LL<<60;
//cout << fixed << setprecision(10);

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main () {
  int n;
  cin >> n;
  vi h(n);
  rep(i,n) cin >> h[i];
  
  int ans = 0;
  int active = 0;
  rep(i,n) {
    if (active >= h[i]) {
      active = h[i];
    }
    else
    {
        ans += h[i] - active;
        active = h[i];
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
def solve(n, x, y):
    z = [u + v for u, v in zip(x, y)]
    w = [u - v for u, v in zip(x, y)]
    return max([max(z) - min(z), max(w) - min(w)])

n = int(input())
x, y = zip(*[map(int, input().split()) for i in range(n)])
print(solve(n, x, y))

Measured memory_bytes: 113500
#include<bits/stdc++.h>
#include<vector>
#include<math.h>
#include<string.h>
using namespace std;
#define MAX 200005
#define MOD 998244353
#define NIN -100000000
#define EPS 0.0000000001
int A[MAX],B[MAX];
int main()
{
    int N,i,j;
    long long ans=1;
    scanf("%d",&N);
    for(i=0;i<N;i++)
    {
        scanf("%d %d",&A[i],&B[i]);
    }
    sort(A,A+N);
    sort(B,B+N);
    if(N%2)
    {
        ans=ans+B[N/2];
        ans=ans-A[N/2];
    }
    else
    {
        ans=ans+B[N/2];
        ans=ans-A[N/2];
        ans=ans+B[N/2-1];
        ans=ans-A[N/2-1];
    }
    printf("%lld",ans);
    return 0;
}


Measured memory_bytes: 5384
#include<iostream>
#include<sstream>
#include<string>
#include<string.h>
#include<algorithm>
#include<stdio.h>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<stack>
#define debug(a) cout << "*" << a << "*" << endl
using namespace std;
typedef long long ll; 
map<ll, ll> mp;
ll d[200005];
ll x, n, k, a, s, ans;
int main()
{
	while (~scanf("%lld%lld", &n, &k))
	{
		ans = s = 0;
		mp.clear();
		mp[0] = 1;
		for (ll i = 1; i <= n; i++)
		{
			if (i - k >= 0)
				mp[d[i - k]]--;
			scanf("%lld", &a);
			s += a;
			x = (s - i) % k;
			ans += mp[x];
			mp[x]++;
			d[i] = x;
		}
		printf("%lld\n", ans);
	}
}

Measured memory_bytes: 14336
import math

dp = [0,1,2,4]
for j in range(3,30):
    dp.append(dp[j]+dp[j-1]+dp[j-2])

for i in range(30):
    n = int(input())
    if n==0:
        break
    else:
        print(math.ceil(dp[n]/3650))


Measured memory_bytes: 5668
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define ll long long
#define endl '\n'
using namespace std;
int dy[4] = {1,0,-1,0},dx[4] = {0,1,0,-1};
typedef pair<ll, ll> P;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b, c;
    cin >> a >> b >> c;
    if ((a < c && c < b) || (b < c && c < a)) {
        puts("Yes");
    } else {
        puts("No");
    }
    return 0;
}

Measured memory_bytes: 256