akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cassert>
#include <limits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <array>
#include <map>
#include <set>
#include <deque>
#include <list>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cstring>
#include <bitset>
#include <stack>
#include <queue>

#define MOD (1e9 + 7);

using ll = int64_t;
using ull = uint64_t;

using namespace std;

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

    int a, b;
    char op;
    cin >> a; cin >> op; cin >> b;
    if (op == '+') {
        cout << a + b << endl;
    }
    else {
        cout << a - b << endl;
    }

    return 0;
}


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

using namespace std;
#define REP(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(long long i=(a),i##Len_=(b);i<i##Len_;i++)
typedef long long ll;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;



int main()
{
    ll N,D;
    cin >> N >> D;
    ll cnt = 0;

    ll X[N][D];

    ll ruto[127];

    REP(i,126)
    {
        ruto[i] = i*i;
    }

    REP(i,N)
    {
        REP(j,D)
        {
            cin >> X[i][j];
        }
    }

    ll kyori = 0;
    ll tmp;
    for(ll i = 0; i < N; ++i)
    {
        for(ll j = i+1; j < N; ++j)
        {
            if(i == j)continue;
            kyori = 0;
            for(ll t = 0; t < D; ++t)
            {
                tmp = (X[i][t] - X[j][t]);
                kyori += tmp * tmp;
            }
            for(ll s = 0; s < 127; ++s)
            {
                if(kyori == ruto[s])
                {
                    cnt++;
                }
            }
        }
    } 

    cout << cnt << endl;
    return 0;
}



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

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
const int MAXN = 666*1000 + 1;

int dp2[MAXN];
int p[6] = {1,5,10,50,100,500};
int count_c(int Y, int c[]){
	int res = 0;
	for(int i = 5 ; i >= 0; i--){
		int t = min(c[i], Y / p[i]);
		Y -= t * p[i];
		res += t;
	}
	if(Y == 0) return res;
	else return INF;
}
int main(){
	int Y;
	fill(dp2, dp2 + MAXN, INF);
	dp2[0] = 0;
	REP(i,6){
		FOR(j,p[i],MAXN){
			dp2[j] = min(dp2[j], dp2[j-p[i]] + 1);
		}
	}
	while(cin>>Y,Y){
		int c[6];
		REP(i,6)cin>>c[i];
		int MY = 0;
		REP(i,6)MY += c[i] * p[i];
		int ans = INF;
		for(int i = MY; i >= Y; i--){
			ans = min(ans, count_c(i,c) + dp2[i-Y]);
		}
		cout<<ans<<endl;
	}
	return 0;
}

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

class Program
{
    static void Main(string[] args)
    {
        var s = ReadInt();

        var hash = new HashSet<int>();
        hash.Add(s);

        while (true)
        {
            if (s % 2 == 0)
            {
                s /= 2;
            }
            else
            {
                s = 3 * s + 1;
            }

            if (hash.Contains(s)) break;
            hash.Add(s);
        }

        Console.WriteLine(hash.Count + 1);
    }

    public static string Read() { return Console.ReadLine(); }
    public static int ReadInt() { return int.Parse(Read()); }
    public static long ReadLong() { return long.Parse(Read()); }
    public static double ReadDouble() { return double.Parse(Read()); }

    public static string[] Reads() { return Console.ReadLine().Split(' '); }
    public static int[] ReadInts() { return Reads().Select(_ => int.Parse(_)).ToArray(); }
    public static long[] ReadLongs() { return Reads().Select(_ => long.Parse(_)).ToArray(); }
    public static double[] ReadDoubles() { return Reads().Select(_ => double.Parse(_)).ToArray(); }
}



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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int N = 2 * 1e5 + 3;

int main() {
  string s;
  int q, x, f, cnt = 0;
  char c;
  cin >> s >> q;

  deque<int> que;
  rep(i, s.size()) que.push_back(s[i]);

  rep(i, q) {
    cin >> x;
    if (x == 1)
      cnt++;
    else {
      cin >> f >> c;
      if (cnt % 2 == 0) {
        if (f == 1) {
          que.push_front(c);
        } else {
          que.push_back(c);
        }
      } else {
        if (f == 1) {
          que.push_back(c);
        } else {
          que.push_front(c);
        }
      }
    }
  }

  char ac;
  while (que.size()) {
    if (cnt % 2 == 1)
      ac = que.back(), que.pop_back();
    else
      ac = que.front(), que.pop_front();
    cout << ac;
  }
  cout << endl;

  return 0;
}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(long i = 0; i < n; i++)
#define erep(i, n) for(long i = 1; i <= n; i++)
#define all(a) a.begin(), a.end()
#define show(ans)  cout << ans << endl;
const long MOD = 1000000007;


int main() {long N, M;
cin >> N >> M;
vector<long> a(N+1);
erep(i, N) cin >> a[i];
erep(i, N){
    a[i] += a[i-1];
    a[i] = a[i] % M;
} 
map<long, long> mp;
vector<long> vec;

rep(i, N+1){
    if(mp[a[i]] == 0) vec.push_back(a[i]);
    mp[a[i]]++;
}
long ans = 0;
rep(i, vec.size()){
    if(mp[vec[i]] >= 2){
        long s = mp[vec[i]];
        ans += s*(s-1)/2;
    }
}
show(ans);

  return 0;
 
}



Measured memory_bytes: 5496
#include <bits/stdc++.h>
#define rep(i,l,n) for(int i=l;i<n;i++)
#define rer(i,l,n) for(int i=l;i<=n;i++)
#define repb(i,n,l) for(int i=n;i>=0;i--)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define pb(a) push_back(a)
#define mk(a,b) make_pair(a,b)
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

int main(){
	char c[8][8]={};
	rep(i,0,8){
		rep(j,0,8){
			cin>>c[i][j];
		}
	}
	o(90);
	rep(i,0,8){
		repb(j,7,0){
			cout<<c[j][i];
		}
		cout<<endl;
	}
	o(180);
	repb(i,7,0){
		repb(j,7,0){
			cout<<c[i][j];
		}
		cout<<endl;
	}
	o(270);
	repb(i,7,0){
		rep(j,0,8){
			cout<<c[j][i];
		}
		cout<<endl;
	}

}

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

typedef long long int   ll;
typedef long double     ld;
typedef pair<ll, ll>    pll;

#define all(x)          x.begin(), x.end()
#define kill(x)         return cout << x << endl, 0;
#define X               first
#define Y               second
#define sep             ' '
#define endl            '\n'
#define fastio          ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define file_io         freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout);
#define ld_io           cout << setprecision(10) << fixed;

ll pw(ll a, ll b, ll mod) {
    if (!b)    return 1;
    if (b & 1) return a * pw(a * a % mod, b / 2, mod) % mod;
    return pw(a * a % mod, b / 2, mod) % mod;
}

const ll MAXN  = 1e5 + 10;
const ll INF   = 8e18;
const ll MOD   = 1e9 + 7; // 998244353;
const ll LOG   = 32;      // log2(1e9)
const ll BLOCK = 320;     // sqrt(1e5)

string s, a[] = {"SAT", "FRI", "THU", "WED", "TUE", "MON", "SUN"};

int main() {
    fastio
    cin >> s;
    for (ll i = 0; i < 7; i++) {
        if (s == a[i])
            kill(i + 1);
    }
    return 0;
}




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

int main()
{
    int n,k,i,x,s=0;
    priority_queue <int,vector <int>,greater <int> >pq;
    cin>>n>>k;
    for(i=0;i<n;i++)
    {
        cin>>x;
        pq.push(x);
    }
     for(i=0;i<k;i++)
     {
         s+=pq.top();
         pq.pop();
     }
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 3592
#include<iostream>
#include<string>
#include<cmath>
#include<iomanip>
using namespace std;

int main(){

	long double x1;
	long double x2;
	long double y1;
	long double y2;
	long double X, Y;

	cin >> x1 >> y1 >> x2 >> y2;

	X = -(x1 - x2);
	Y = -(y1 - y2);

	long double A = pow(X, 2);
	long double B = pow(Y, 2);

	

	long double C = A + B;

	cout <<fixed<< sqrt(C) << endl;












	return 0;
}

Measured memory_bytes: 3244
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial
from bisect import bisect_left #bisect_left(list, value)
#from fractions import gcd
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
def pri(x): print('\n'.join(map(str, x)))

A, B = map(int, input().split())

if A<=8 and B<=8:
    print('Yay!')
else:
    print(':(')




Measured memory_bytes: 3316
#include<bits/stdc++.h>
 using namespace std;
#define INF 1000000000
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
typedef long long LL;
int N;
int main(){
	string S;
	cin>>S;
	LL ans=100000;
	REP(i,S.size()-2){
		LL a=(S[i]-'0')*100+(S[i+1]-'0')*10+(S[i+2]-'0');
		ans=min(ans,abs(753-a));
	}
	cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
# ABC096C - Grid Repainting 2
def main():
    H, W, *S = open(0).read().split()
    H, W = int(H), int(W)
    dxy = [(1, 0), (-1, 0), (0, 1), (0, -1)]
    for x, s in enumerate(S):
        for y, a in enumerate(s):
            if a == "#":
                for dx, dy in dxy:
                    nx, ny = x + dx, y + dy
                    if 0 <= nx < H and 0 <= ny < W and S[nx][ny] == "#":
                        break
                else:
                    print("No")
                    return
    print("Yes")


if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
#include<stdio.h>
int main(){
int i,n,a[10000];
scanf("%d",&n);
for(i=0;i<n;i++){
scanf("%d",&a[i]);
}
int min=a[0],max=a[0];
long long int sum=0;
for(i=0;i<n;i++){
if(a[i]<min){
min=a[i];
}
else if(a[i]>max){
max=a[i];
}
sum+=a[i];
}
printf("%d %d %ld\n",min,max,sum);
return 0;
}

Measured memory_bytes: 640
# AtCoder Beginner Contest 122
# B - ATCoder
# https://atcoder.jp/contests/abc122/tasks/abc122_b

S = input()
n = len(S)

maxl = 0
for i in range(n):
    for j in range(i, n):
        for s in S[i:j+1]:
            if s not in 'ACGT':
                break
        else:
            if maxl < j-i+1:
                maxl = j-i+1

print(maxl)

Measured memory_bytes: 2940
import java.util.Scanner;

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

		String dh = sc.next();

		if (dh.equals("A")) {
			System.out.println("T");
		} else if (dh.equals("T")) {
			System.out.println("A");
		} else if (dh.equals("G")) {
			System.out.println("C");
		} else {
			System.out.println("G");
		}
	}
}

Measured memory_bytes: 21716
#include <stdio.h>          // printf(), scanf()
#include <math.h>           // fabs()
#include <stdbool.h>

const double EPS = 1e-10;

typedef struct line_tbl
{
	double x1, y1;
	double x2, y2;
} line_t;

bool
isorthogonal(line_t a, line_t b)
{
	double ax = a.x2 - a.x1;
	double ay = a.y2 - a.y1;
	double bx = b.x2 - b.x1;
	double by = b.y2 - b.y1;

	if (fabs(ax * bx + ay * by) < EPS)
		return true;
	else
		return false;
}

int
main(int argc, char **argv)
{
	line_t a, b;

	while (scanf("%lf %lf %lf %lf %lf %lf %lf %lf", &a.x1, &a.y1, &a.x2, &a.y2, &b.x1, &b.y1, &b.x2, &b.y2) != EOF)
		printf("%s\n", isorthogonal(a, b) ? "YES" : "NO");

	return 0;
}

Measured memory_bytes: 612
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AtCoder
{
    class Program
    {
        private const int MODULO = 1000000007;
        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        static int Solve2(int A, int B, int C)
        {
            int max = new[] { A, B, C }.Max();
            return (max * 3 - (A + B + C)) / 2;
        }
        static int Solve1(int A, int B, int C)
        {
            if ((A & 1) != (B & 1) && (A & 1) != (C & 1))
            {
                return Solve2(A, B + 1, C + 1) + 1;
            }
            if ((B & 1) != (A & 1) && (B & 1) != (C & 1))
            {
                return Solve2(A + 1, B, C + 1) + 1;
            }
            if ((C & 1) != (A & 1) && (C & 1) != (B & 1))
            {
                return Solve2(A + 1, B + 1, C) + 1;
            }
            return Solve2(A, B, C);
        }
        static void Main(string[] args)
        {
            var V = ReadInts();
            Console.WriteLine(Solve1(V[0], V[1], V[2]));
        }
    }
}


Measured memory_bytes: 13268
import numpy as np

m = 1e9+7

N = int(input())

def culc_mod(a, b, md):
    """a^b (mod md)"""
    tmp = 1
    for _ in range(b):
        tmp *= a
        tmp = tmp%md
    return tmp
    
a = culc_mod(10, N, m)
b = culc_mod(9, N, m)
c = culc_mod(8, N, m)

print(int((a-2*b+c)%m))

Measured memory_bytes: 27148
using System;
using System.Collections.Generic;
using System.Linq;
using static Scanner;

class Program
{
    static void Main() => new Program().Solve();

    public void Solve()
    {
        int n = ReadInt();
        string c = Read();
        int a = c.Count(x => x == 'R');
        int b = c[..a].Count(x => x == 'W');
        Console.WriteLine(b);
    }
}

static class Scanner
{
    static Queue<string> que = new Queue<string>();
    public static string Read() { if (!que.Any()) foreach (var s in Console.ReadLine().Split()) que.Enqueue(s); return que.Dequeue(); }
    public static int ReadInt() => int.Parse(Read());
    public static IEnumerable<string> Read(long n) { for (long i = 0; i < n; i++) yield return Read(); }
    public static IEnumerable<int> ReadInt(long n) => Read(n).Select(int.Parse);
}


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

int main (void) {
  string s;
  cin >> s;
  int count1 = 0, count0 = 0;
  for (const auto &ch : s) {
    if (ch == '1') count1++;
    else count0++;
  }
  cout << 2 * min(count1, count0) << endl;
  return 0;
}


Measured memory_bytes: 512
N = gets.to_i
as = gets.split.map(&:to_i)

hash = {}
as.each do |a|
    hash[a] ||= 0
    hash[a] += 1
end

pat = 0
if N % 2 == 1
    if hash[0] != 1
        puts 0
        exit
    end
    (1..N/2).each do |i|
        if hash[i*2] == 2
            pat += 1
        else
            puts 0
            exit
        end
    end
else
    (0...N/2).each do |i|
        if hash[i*2+1] == 2
            pat += 1
        else
            puts 0
            exit
        end
    end
end

p (2**pat) % (10**9+7)

Measured memory_bytes: 12172
import java.util.*;
import java.util.stream.*;
class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int H,W;
        while(true){
            H = input.nextInt();
            W = input.nextInt();
            if (H == 0 && W == 0){
                break;
            } else {
                for (int i = 0; i < H; i++){
                    if (i == 0 || i == H-1){
                        for (int j = 0; j < W; j++){
                            System.out.printf("#");
                        }
                    } else {
                        System.out.printf("#");
                        for (int j = 1; j < W-1; j++){
                            System.out.printf(".");
                        }
                        System.out.printf("#");
                    }
                    System.out.printf("\n");
                }
                System.out.printf("\n");
            }
        }
    }
}


Measured memory_bytes: 59260
import java.io.*;
import java.util.*;
public class Main
{
	
	private void solve()throws IOException
	{
		int n=nextInt();
		int m=nextInt();
		boolean white[][]=new boolean[n+1][m+1];
		for(int i=1;i<=n;i++)
		{
			String s=nextLine();
			for(int j=1;j<=m;j++)
				white[i][j]=s.charAt(j-1)=='.';
		}
		int dp[][][]=new int[n+1][m+1][2];
		//dp[i][j][flag]=min no of operations to make path from i,j to n,m such that first operation is free if flag=1
		final int inf=(int)(1e9+1);
		for(int i=n;i>=1;i--)
			for(int j=m;j>=1;j--)
			{
				if(i==n && j==m)
				{
					dp[i][j][0]=white[i][j]?0:1;
					dp[i][j][1]=0;
				}
				else
				{
					if(white[i][j])
					{
						dp[i][j][0]=Math.min(i==n?inf:dp[i+1][j][0],j==m?inf:dp[i][j+1][0]);
						dp[i][j][1]=Math.min(i==n?inf:dp[i+1][j][0],j==m?inf:dp[i][j+1][0]);
					}
					else
					{
						dp[i][j][0]=1+Math.min(i==n?inf:dp[i+1][j][1],j==m?inf:dp[i][j+1][1]);
						dp[i][j][1]=Math.min(i==n?inf:dp[i+1][j][1],j==m?inf:dp[i][j+1][1]);
					}
				}
			}
		out.println(dp[1][1][0]);
	}

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

	public void run()throws IOException
	{
		br=new BufferedReader(new InputStreamReader(System.in));
		st=null;
		out=new PrintWriter(System.out);

		solve();
		
		br.close();
		out.close();
	}
	public static void main(String args[])throws IOException{
		new Main().run();
	}
	BufferedReader br;
	StringTokenizer st;
	PrintWriter out;
	String nextToken()throws IOException{
		while(st==null || !st.hasMoreTokens())
		st=new StringTokenizer(br.readLine());
		return st.nextToken();
	}
	String nextLine()throws IOException{
		return br.readLine();
	}
	int nextInt()throws IOException{
		return Integer.parseInt(nextToken());
	}
	long nextLong()throws IOException{
		return Long.parseLong(nextToken());
	}
	double nextDouble()throws IOException{
		return Double.parseDouble(nextToken());
	}
}

Measured memory_bytes: 23380
import Control.Monad
import Control.Applicative
import Data.Functor
import Data.List
import Data.Char

dist p xs ys = (**(1/p)) . sum . map ((**p) . abs) $ zipWith (-) xs ys
distInf xs ys = maximum . map abs $ zipWith (-) xs ys

main = do
  getLine
  xs <- map read . words <$> getLine
  ys <- map read . words <$> getLine
  print $ dist 1 xs ys
  print $ dist 2 xs ys
  print $ dist 3 xs ys
  print $ distInf xs ys

Measured memory_bytes: 4476
N = input()
S = raw_input()
T = [0]*8
for i in range(8):
    if i&1 and i>>"JOI".index(S[0])&1:
        T[i] = 1
for s in S[1:]:
    P = T
    T = [0]*8
    for i in range(8):
        for j in range(8):
            if j>>"JOI".index(s)&1 and i&j:
                T[j] += P[i]
print sum(T)%10007

Measured memory_bytes: 6460
/**************************************************************************
Coded by: Saba Karimi(_VINTAGE)
Institution: AIT PUNE
***************************************************************************/
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back 
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define ld long double
#define int long long int 
/***************************************************************************/
signed main()
{   
    fast; 
    int a,b;
    cin>>a>>b;
    cout<<max(a+b,max(a-b,a*b));
}   

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

using namespace std;
using ll = long long;
using Lll = list<ll>;
using Vll = vector<ll>;

#define rep(a,x,i,f) for(ll a = i; a < f; a+=x )
#define repR(a,x,i,f) for(ll a = i; a > f; a-=x )

ll frog(Vll& s, Vll& ci, int cur)
{
  ll p1,p2;

  if(cur < 2)
  {
    return ci[cur];
  }
  
  p1 = abs(s[cur] - s[cur-1]) + (ci[cur-1] != -1 ? ci[cur-1] : frog(s,ci,cur-1));
  p2 = abs(s[cur] - s[cur-2]) + (ci[cur-2] != -1 ? ci[cur-2] : frog(s,ci,cur-2));
  
  ci[cur] = p1 < p2 ? p1 : p2;

  return ci[cur];
}

int main() 
{
  ll n,m;
  cin >> n;
  Vll s(n);
  Vll ci(n,-1);

  rep(i,1,0,n)
    cin >> s[i];

  ci[0] = 0;
  ci[1] = abs(s[0] - s[1]);

  m = frog(s,ci,n-1);

  cout << m << endl;
}

Measured memory_bytes: 9600
use std::io;
use std::str::FromStr;

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

fn input_vec() -> Vec<i64> {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    line.split_whitespace().map(|s| s.parse().unwrap()).collect()
}

fn main() {
    let n: usize = input();
    let mut a_vec = input_vec();
    a_vec.push(0);
    a_vec.insert(0, 0);
    let mut sum = 0;
    let mut dists: Vec<i64> = Vec::new();
    for i in 0..n+1 {
        let dist = (a_vec[i+1] - a_vec[i]).abs();
        sum += dist;
        dists.push(dist);
    }
    // println!("{:?}", dists);
    for i in 1..(n+1) {
        println!("{}", sum - dists[i-1] - dists[i] + (a_vec[i+1] - a_vec[i-1]).abs());
    }
}


Measured memory_bytes: 4068
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1LL << 60;
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)

int H, W, N;
int check(int len,int ini,string S,string T,string c) {
	int curmi = 1;
	int curma = len;
	for (int i = N - 1; i >= 0; i--) {
		if (T[i] == c[0]) {
			curma = min(len, curma + 1);
		}
		else if (T[i] == c[1]) {
			curmi = max(1, curmi - 1);
		}
		if (S[i] == c[0]) {
			curmi = curmi + 1;
		}
		else if (S[i] == c[1]) {
			curma = curma - 1;
		}
		if (curmi > curma)return 0;
		if (curmi > len)return 0;
		if (curma < 1)return 0;
	}
	if (curmi <= ini && ini <= curma)return 1;
	else return 0;
}

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

	cin >> H >> W >> N;
	int sr, sc;
	cin >> sr >> sc;
	string S, T;
	cin >> S >> T;

	int c1 = check(H,sr,S,T,"UD");
	int c2 = check(W,sc,S,T,"LR");
	if (!c1 || !c2)puts("NO");
	else puts("YES");
	

	return 0;
}



Measured memory_bytes: 1176
from sys import stdin
import re

n = [int(x) for x in stdin.readline().rstrip().split()]
s = stdin.readline().rstrip().split()
s = s[0]
k = [int(x) for x in stdin.readline().rstrip().split()]
k = k[0]

ast = ''
for i in range(len(s)):
    if i+1 == k:
        ast = s[i]

print(re.sub('[^' + ast + ']', '*', s))


Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define int long long
#define ld long double
#define endl "\n"
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define ms(v,x) memset(v,x,sizeof(v))
#define ff first
#define ss second
#define rep(i,l,r) for(int i = (int)l;i<(int)r;i++)
#define td(v) v.begin(),v.end()
//#define M   1000000007 // 1e9 + 7
#define MAXN 100100
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
inline int mod(int n, int m){ int ret = n%m; if(ret < 0) ret += m; return ret; }
int gcd(int a, int b){return (b == 0 ? a : gcd(b, a%b));}
int exp(int a,int b,int m){
	
    if(b==0) return 1;
    if(b==1) return mod(a,m);
    int k = mod(exp(a,b/2,m),m);
    if(b&1){
        return mod(a*mod(k*k,m),m);
    }
    else return mod(k*k,m);

}


int dp[110][100100];
int w[110],v[110];

int32_t main(){
	fastio;
	int n,p;
	cin>>n>>p;
	int sum=0;
	for(int i=1;i<=n;i++){
		cin>>w[i]>>v[i];
		sum+=v[i];
	}
	
	for(int i=0;i<110;i++){
		for(int j=0;j<100100;j++){
			dp[i][j] = 1e9 + 100;
		}
	}
	dp[0][0] = 0;
	for(int i=1;i<=n;i++){
		for(int j=sum-v[i];j>=0;j--){
			dp[i][j] = dp[i-1][j];
			if(dp[i-1][j]+w[i]<=p)dp[i][j+v[i]] = min(dp[i][j+v[i]],dp[i-1][j] + w[i]);
		}
	}
	int r=0;
	for(int i=sum;i>=0;i--){
		if(dp[n][i]<=p){
			r = i;
			break;
		}
	}
	cout<<r<<endl;
}

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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////
#define r3 0.57735026918962576450914878050196
//#define s3 1.7320508075688772935274463415059
#define INF 1e12
#define pdl pair<double,ll>
ll n, K,x[10101],y[10101];
pdl av[10101], bv[10101];
//vector<ll> cv;
ll i, j,mk[101010];
double ans;

int main(){
    double s3 = sqrt(3);
    //printf("a%lld", n);
    while(true){
        ans = INF;
        scanf("%lld",&n);
        if(n==0)
            break;
        scanf("%lld", &K);
        K = n - K;
        //av.resize(n);
        //bv.resize(n);
        //cv.resize(n);
        fornum(i,0,n){
            scanf("%lld%lld", &x[i], &y[i]);
            av[i] = mp(x[i] - y[i]/s3, i);
            bv[i] = mp(x[i] + y[i]/s3, i);
            //cv[i] = y[i];
        }
        sort(av, av + n);
        sort(bv, bv + n);
        //sort(cv.begin(), cv.end());
        /*fornum(i,0,n){
            printf("%lld,%lf,%lf\n",i, av[i].first, bv[i].first);
        }*/
        //printf("a\n");
        fornum(i,0,n){
            ll l = 0, r = 0,kk=0;
            ll yy = y[i];
            fornum(j,0,n){
                mk[j] = 0;
            }
            fornum(l, 0, n){
                if (y[av[l].second] < yy)
                    continue;
                while(r<n&&kk<K){
                    ll ii = bv[r].second;
                    if(yy<=y[ii]&&mk[ii]!=2){
                        mk[ii] = 1;
                        kk++;
                    }
                    r++;
                }
                if(kk<K)
                    break;
                ll li = av[l].second;
                if(mk[li]==1){
                    ll ri = bv[r-1].second;
                    double aaa = (x[ri] + (y[ri] - yy) / s3) - (x[li] - (y[li] - yy) / s3);
                    if(aaa<ans)
                        ans = aaa;
                    kk--;
                }else{
                    double aaa = (x[li] + (y[li] - yy) / s3) - (x[li] - (y[li] - yy) / s3);
                    if(aaa<ans)
                        ans = aaa;
                }
                //printf("%lld,%lf,%lf,%lld,%lf\n", yy, av[l].first, bv[r-1].first,mk[av[l].second], ans);
                mk[li] = 2;
                
            }
        }

        printf("%.10lf\n", ans*3);
    }
    return 0;
}


Measured memory_bytes: 3696
#include<bits/stdc++.h>
#define pii pair<int,int>

using namespace std;

int pr[200005] , pr2[200005];
map<pii,int>mp;

int find(int u)
{
    if(pr[u]==u)return u;
    return pr[u] = find(pr[u]);
}
int find2(int u)
{
    if(pr2[u]==u)return u;
    return pr2[u] = find2(pr2[u]);
}
int main()
{
    int n,m,r;
    cin >> n >> m >> r;
    for(int i=1; i<=n; i++)
    {
        pr[i] = i;
        pr2[i] = i;
    }
    for(int i=0; i<m; i++)
    {
        int u,v;
        cin >> u >> v;
        int a,b;
        a = find(u);
        b = find(v);
        if(a > b)
            swap(a,b);
        pr[a] = b;
    }
    for(int i=0; i<r; i++)
    {
        int u,v;
        cin >> u >> v;
        int a,b;
        a = find2(u);
        b = find2(v);
        if(a > b)
            swap(a,b);
        pr2[a] = b;
    }
    for(int i=1;i<=n;i++)
        mp[{find(i),find2(i)}]++;

    for(int i=1; i<=n; i++)cout << mp[{pr[i],pr2[i]}] << " ";
    cout << endl;
}


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

int main(){
  int a,b;
  cin >> a >> b;
  if ((a+b)%2 == 0){
    cout << (a+b)/2 << endl;
  }
  else {
    cout << (a+b)/2+1 << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define RREP(i,a,b) for(int i=(a);i>=(b);i--)
#define pq priority_queue
#define P pair<int,int>
#define P2 pair<int,P>
#define P3 pair<int,P2>
typedef long long ll; typedef long double ld;
using namespace std;
const int INF=1e9, MOD=1e9+7, around[]={0,1,1,-1,-1,0,-1,1,0,0};
const ll LINF=1e18;
const ld PI=abs(acos(-1));
int n,a[210];

int main(){
	cin >> n;
	REP(i,0,2*n) cin >> a[i]; sort(a,a+2*n);
	
	int s=0;
	REP(i,0,2*n) s+=min(a[i],a[i+1]),i++;
	cout << s << endl;
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
     
    using namespace std;
     
    int main() {
    	int a, b, c, d;
    	cin >> a >> b >> c >> d;
    	int i = 0;
    	while (a>0&&c>0) {
    		if (i % 2 == 0)
    			c -= b;
    		else
    			a -= d;
    		i++;
    	}
    	cout << (a > 0 ? "Yes" : "No");
    	cin >> a;
    	return 0;
    }

Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
int main(){
  int n,ans=0;cin>>n;
  ll a[n],b=0,c[n];fill(c,c+n,0);c[0]=1;
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  sort(a,a+n);
  for(int i=0;i<n-1;i++){
    if(a[i]==a[i+1]){
      c[b]++;c[b]%=2;
    }else{
      b++;
      c[b]++;
    }
  }
  for(int i=0;i<n;i++){
    if(c[i]==1){ans++;}
  }
  cout<< ans<<endl;
}
  
  

Measured memory_bytes: 5200
#pragma region Header
#ifdef DEBUG
#include "debug.hpp"
#else
#define debug(...)
#define IFD(...)
#ifndef NDEBUG
#define NDEBUG
#endif
#endif
#include <utility>
#include <cstdint>
#include <cmath>
#include <cassert>
#include <vector>
#include <array>
#include <deque>
#include <queue>
#include <stack>
#include <tuple>
#include <set>
#include <map>
#include <unordered_map>
#include <bitset>
#include <string>
#include <functional>
#include <algorithm>
#include <numeric>
#include <stdexcept>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <boost/hana/functional/fix.hpp>
using boost::hana::fix;
using namespace std;
using i32 = int32_t;
using i64 = int64_t;
using u32 = uint32_t;
using u64 = uint64_t;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repd(i, n) for (int i = (n)-1; i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define FORD(i, b, a) for (int i = (b); i >= (a); --i)
template <typename T>
int SZ(T const &x)
{
    return static_cast<int>(x.size());
}
template <class T>
bool chmax(T &a, T const &b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
bool chmin(T &a, T const &b)
{
    if (b < a)
    {
        a = b;
        return true;
    }
    return false;
}
#pragma endregion

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);

    int n;
    cin >> n;
    vector<double> p_s(n);
    rep(i, n)
    {
        cin >> p_s[i];
    }

    vector<double> dp(n + 1), dptmp(n + 1);
    dp[0] = 1;
    rep(i, n)
    {
        auto p = p_s[i];
        dptmp[0] = dp[0] * (1 - p);
        rep(j, n)
        {
            dptmp[j + 1] = dp[j] * p + dp[j + 1] * (1 - p);
        }

        swap(dp, dptmp);
    }

    double ans = 0;
    FOR(i, (n + 2) / 2, n)
    {
        ans += dp[i];
    }
    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 3868
M = int(input())
A = [int(_) for _ in input().split()]
N = 1000
if all(a >= b for a, b in zip(A, A[1:])):
    print(N)
else:
    kabu = 0
    if A[0] < A[1]:
        kabu, N = divmod(N, A[0])
    for a, b, c in zip(A, A[1:], A[2:]):
        if a <= b >= c:
            N += kabu * b
            kabu = 0
        elif a >= b <= c:
            dkabu, N = divmod(N, b)
            kabu += dkabu
    N += kabu * A[-1]
    print(N)


Measured memory_bytes: 9124
#include <bits/stdc++.h> 
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(vec) vec.begin(), vec.end()
#define tmax(x,y,z) max((x),max((y),(z)))
#define tmin(x,y,z) min((x),min((y),(z)))
typedef long long ll;ll MM = 1000000000;ll mod = MM + 7; ll MMM=9223372036854775807;//2^63 -1
typedef vector<ll> lvec;typedef vector<double> dvec;typedef vector<string> svec;
ll GCD(ll x, ll y) {if (y == 0) return x;else return GCD(y, x % y);}
ll LCM(ll x, ll y) { return x / GCD(x, y) * y;}
//cout << fixed << setprecision(10);

int main(){
  ll x1, y1, x2, y2; cin>>x1>>y1>>x2>>y2;
  ll dx=x2-x1, dy=y2-y1;
  ll x3=x2-dy, y3=y2+dx, x4=x3-dx, y4=y3-dy;
  cout<<x3<<' '<<y3<<' '<<x4<<' '<<y4<<endl;
}

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

s = [[0 for _ in range(w)] for _ in range(h)]

num = [0, 1]
flag = True
for i in range(h):
    for j in range(w):
        if b <= i and flag:
            num.reverse()
            flag = False
        if j < a:
            s[i][j] = num[0]
        else:
            s[i][j] = num[1]


for row in s:
    tmp = list(map(str, row))
    print("".join(tmp))

Measured memory_bytes: 12916
/*
    WRITER:kakitamasziru
*/
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <iomanip>
#include <limits>
//#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
//#include <unordered_map> // unordered_map
//#include <unordered_set> // unordered_set
#include <bitset> // bitset
//#include <cctype> // isupper, islower, isdigit, toupper, tolower
//It is so troublesome that I include bits/stdc++.h !
using namespace std;

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const int INF = 1001001000;
const int MOD = 1000000007;
typedef pair<long,long> P;
//NのM乗を求める(繰り返し二乗法)
long long mod_pow(long long N, long long M) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % MOD, M / 2);
    //最下位ビット(*N)が1の時は単独でNをかける
    if (M & 1) res = (res * N) % MOD;

    return res %= MOD;
}
long long nCr(long long n, long long r) {
    long long A = 1, B = 1;
    //Aが分子Bが1/r!
    //n!はi = 1;i<=nでする
    for (long long i = n-r+1; i <= n; i++) {
        A = A * i % MOD;
    }
    for (long long i = 1; i <= r; i++) {
        B = B * i % MOD;
    }
    B = mod_pow(B, MOD - 2);
    B %= MOD;
    //Bは割るのではなく掛ける
    return (A * B) % MOD;
}

int main() {

    double N;cin >> N;
    int K;cin >> K;
    double ans = 0;
    for(int i = 1;i<=N;i++){
        double count = 1;
        int dice = i;
        while(true){
            if(dice >= K) break;
            dice *= 2;
            count *= 2;
        }
        ans += (1.000000000/(count*N));
    }
    cout << fixed << setprecision(10) << ans << endl;

    /*
    g++ abc.cpp
    ./a.out
    */
    return 0;
}

Measured memory_bytes: 256
H,W = list(map(int,input().split()))
N=input()
a=list(map(int,input().split()))

c=[[0 for j in range(W)] for i in range(H)]
b=[]
for i in range(len(a)):
    b = b + [i+1 for _ in range(a[i])]

f = 0
cnt = 0
for i in range(H):
    f = i % 2
    for j in range(W):
        if f==0:
            c[i][j] = b[cnt]
        else:
            c[i][W-1-j] = b[cnt]
        cnt += 1

        
for i in range(H):
    ans =""

    for j in range(W-1):
        ans += str(c[i][j]) + " " 
    ans += str(c[i][W-1]) 
    print(ans)

Measured memory_bytes: 3792
n = str(input())
n_arr = list(str(n))
arr = list(map(int, n_arr))
zero = []
one = []
for i in range(len(arr)):
    if i % 2 == 0:
        zero.append(0)
        one.append(1)
    else:
        zero.append(1)
        one.append(0)
zero_diff = 0
one_diff = 0
for i in range(len(arr)):
    if arr[i] != zero[i]:
        zero_diff += 1
for i in range(len(arr)):
    if arr[i] != one[i]:
        one_diff += 1
print(min([one_diff,zero_diff]))

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

int solve(std::vector<int> v, int n, int k)
{
	std::vector<int> dp(n + 1);
	dp[1] = 0;

	for (int i = 2; i <= n; i++)
	{
		dp[i] = INT_MAX;
		for (int j = i - 1; j >= 1 and (i - j <= k) ; j--)
		{
			dp[i] = min(dp[i], abs(v[i] - v[j]) + dp[j]);
		}
	}
	return dp[n];
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n, k;
	cin >> n >> k;
	vector<int> v(n + 1);
	for (int i = 1; i <= n; i++)
		cin >> v[i];
	cout << solve(v, n, k);
}

Measured memory_bytes: 4460
import java.util.Scanner;

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

        int first = Integer.parseInt(str.substring(0, 2));
        int second = Integer.parseInt(str.substring(2, 4));
        //System.out.println(first +" " + second);
        if((first <=12 && first >0) && (second<=12 && second>0))
            System.out.println("AMBIGUOUS");
        else
            if(first <=12 && first >0)
                System.out.println("MMYY");
            else
                if(second<=12 && second>0)
                    System.out.println("YYMM");
                else
                    System.out.println("NA");

    }
}


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

int main(void){
    int a,b,c;
    cin>>a>>b>>c;
    rep(i,b){
        if((a*(i+1))%b==c){
            cout<<"YES"<<endl;
            return 0;
        }
    }
    cout<<"NO"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define chadd(x, y) x = (x + y) % mod

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

    int n, a, b;
    cin >> n >> a >> b;
    vector<int> x(n);
    for(int i = 0; i < n; ++i)  cin >> x[i];
    
    ll ans = 0;
    for(int i = 0; i + 1 < n; ++i){
        if((ll)a * (x[i + 1] - x[i]) >= b)  ans += b;
        else    ans += a * (x[i + 1] - x[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
# get Alice's card A and Bob's card B
a, b = map(int, raw_input().split())

# adjust for card strength, 1 > 13
if a == 1:
	a = 14
if b == 1:
	b = 14

if a > b:
	print ("Alice")
elif a < b:
	print ("Bob")
else:
	print ("Draw")

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

using namespace std;
typedef long long lint;

int main() {
  int N;
  cin >> N;
  vector<int> ps(N);
  for (int i = 0; i < N; i++) {
    cin >> ps[i];
    --ps[i];
  }
  int ans = 0;
  for (int i = 0; i < N-1; i++) {
    if (ps[i] == i) {
      ++ans;
      swap(ps[i], ps[i+1]);
    }
  }
  if (ps[N-1] == N-1) ++ans;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 640
#include <iostream>
using namespace std;
int main()
{
    int H, N;
    do
    {
        cin >> H >> N;
    } while (H > 1000000000 || H < 1 || N > 100000 || N < 1);
    int A[N];
    int sum = 0;
    for (int i = 0; i < N; i++)
    {
        do
        {
            cin >> A[i];
        } while (A[i] > 10000 || A[i] < 1);
        sum += A[i];
    }
    if (H - sum > 0)
    {
        cout << "No" << endl;
    }
    else
    {
        cout << "Yes" << endl;
    }
    return 0;
}

Measured memory_bytes: 640
// reference: https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
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")
    };
}


use std::cmp;
use std::collections::VecDeque;


fn main(){
    input! {
        n: usize, m: usize,
        xy: [(usize1, usize1); m],
    }

    let mut indeg = vec![0;n];
    let mut e = vec![vec![]; n];
    for (x, y) in xy {
        e[x].push(y);
        indeg[y] += 1;
    }

    let mut q = VecDeque::new();
    for i in 0 .. n {
        if indeg[i] == 0 {
            q.push_front(i);
        }
    }

    let mut topo = Vec::new();
    while let Some(v) = q.pop_back() {
        topo.push(v);
        for &i in &e[v] {
            indeg[i] -= 1;
            if indeg[i] == 0 {
                q.push_front(i);
            }
        }
    }

    let mut dp = vec![0; n];
    for i in topo.into_iter().rev() {
        let mut m = 0;
        for &j in &e[i] {
            m = cmp::max(m, dp[j]+1);
        }
        dp[i] = m;
    }

    println!("{}", dp.into_iter().max().unwrap());
}




Measured memory_bytes: 14588
#include <bits/stdc++.h>
#define L long long
#define LL long long
#define SS string
#define PB push_back
#define pp pair<L,L>
using namespace std;
int main() 
{ 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    L n;
    cin >> n;
    L a[n+1];
    L h[n+1];
    L i;
    for (i = 1 ; i <= n ; i++)
    {
        cin >> h[i];
    }
    a[1] = 0;
    if (n > 1)
    {
        a[2] = abs(h[2]-h[1]);
        for (i = 3 ; i<= n ; i++)
        {
            a[i] = min(a[i-1] + abs(h[i]-h[i-1]),a[i-2]+abs(h[i]-h[i-2]));
        }
        cout << a[n];
    }
    else
    cout << 0;
        return 0; 
}

Measured memory_bytes: 1792
#include <iostream>
#include <cstdint>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <algorithm>
#include <cassert>

using namespace std;
typedef int64_t SI;
typedef uint64_t UI;

class SumABC {
public:
  SumABC(SI _s,UI _a, UI _b, UI _c) :s(_s),a(_a),b(_b),c(_c) {
  }
  SI s;
  UI a, b, c;
  bool operator<(const SumABC& other) const {
    return s < other.s;
  }
};

int main() {
  UI X,Y,Z,K;
  cin >> X >> Y >> Z >> K;
  vector<SI> A(X),B(Y),C(Z);
  for(SI i=0; i<X; i++) { cin >> A[i]; }
  for(SI i=0; i<Y; i++) { cin >> B[i]; }
  for(SI i=0; i<Z; i++) { cin >> C[i]; }

  sort(A.begin(), A.end());
  reverse(A.begin(), A.end());
  sort(B.begin(), B.end());
  reverse(B.begin(), B.end());
  sort(C.begin(), C.end());
  reverse(C.begin(), C.end());
  A.push_back(-1000000000);
  B.push_back(-1000000000);
  C.push_back(-1000000000);

  SumABC ini( A[0]+B[0]+C[0], 0, 0, 0 );
  priority_queue<SumABC> pq;
  set<UI> used;
  used.insert(0);
  pq.push(ini);
  vector<UI> ans;
  while(ans.size() < K) {
    SumABC x = pq.top();
    pq.pop();
    ans.push_back(x.s);
    for (int i = 0; i < 3; i++) {
      UI a = x.a;
      UI b = x.b;
      UI c = x.c;
      if (i == 0) { a++; }
      else if (i == 1) { b++; }
      else if (i == 2) { c++; }
      // hash
      UI hash = (a << 20) + (b << 10) + c;
      if(used.find(hash) == used.end()) {
        used.insert(hash);
        pq.push(SumABC(A[a] + B[b] + C[c], a, b, c));
      }
    }
  }

  for(size_t i=0; i<K; i++) {
    cout << ans[i] << std::endl;
  }

  return 0;
}



Measured memory_bytes: 768
//stringray

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

/*#ifndef __LOCAL__ 
#pragma comment(linker,"/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#endif*/ 

using namespace std;
using namespace __gnu_pbds;

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ost;

typedef pair<int,int> pii;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
typedef vector<set<int>> vsi;

#define endl "\n"
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(),x.end()
#define pb emplace_back
#define F first
#define S second
#define fori(i,n) for(int i=1;i<=n;++i)
#define forn(i,n) for(int i=0;i<n;++i)
#define sz(x) int(x.size())
#define error(x) cout<<#x<<" "<<x<<endl
#define IOS  ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(0)


const int N=100*1000;
const int mod=1e9+7;

int min3(int a,int b,int c){return min(a,min(b,c));}
int max3(int a,int b,int c){return max(a,max(b,c));}
int min4(int a,int b,int c,int d){return min(min(a,b),min(c,d));}
int max4(int a,int b,int c,int d){return max(max(a,b),max(c,d));}

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
template<typename T>
istream& operator >> (istream& is,vector<T>& vec){
  for(T &x:vec)is>>x;
  //for(int i=0;i<vec.size();++i)is>>x[i];
  return is;
}

template<typename T>
ostream& operator << (ostream& os,vector<T>& vec){
  for(int i=0;i<vec.size();++i){
    os<<vec[i]<<(i+1==vec.size()?"":" ");
  }
  return os;
}

ll mpow(ll a, ll b){
  ll ret=1;
  while(b>0){
    if(b&1)ret=(ret*a)%mod;
    (a=a*a)%=mod;
    b>>=1LL;
  }
  return ret;
}

#define int int64_t
//int a[N+2];
int ret=1;
int k;
vi e[N+2];
void dfs(int u,int p,int num){
  ret=(ret*num)%mod;
  num=k-1;
  if(p!=-1)num--;
  for(int v:e[u]){
    if(v==p)continue;
    dfs(v,u,num);
    num--;
  }
}
void solve(){
  int n;cin>>n;
  cin>>k;
  fori(i,n-1){
    int u,v;cin>>u>>v;
    u--,v--;
    e[u].pb(v);
    e[v].pb(u);
  }
  dfs(0,-1,k);
  cout<<ret<<endl;
    
}
int32_t  main(){
  IOS;
  solve();
  return 0;
}



Measured memory_bytes: 9216
#include <stdio.h>

void Dice(int num[6], char cmd);

int main(){
    int num[6];
    int i;
    char cmd[101];
    
    for(i=0; i<6; i++) scanf("%d", &num[i]);
    scanf("%s", cmd);
    for(i=0; cmd[i]!='\0'; i++){
        Dice(num, cmd[i]);
    }
    printf("%d\n", num[0]);
    return 0;
}

void Dice(int num[6], char cmd)
{
    int tmp = num[0];
    switch(cmd){
        case 'N':
            num[0] = num[1];
            num[1] = num[5];
            num[5] = num[4];
            num[4] = tmp;
            break;
        case 'S':
            num[0] = num[4];
            num[4] = num[5];
            num[5] = num[1];
            num[1] = tmp;
            break;
        case 'W':
            num[0] = num[2];
            num[2] = num[5];
            num[5] = num[3];
            num[3] = tmp;
            break;
        case 'E':
            num[0] = num[3];
            num[3] = num[5];
            num[5] = num[2];
            num[2] = tmp;
            break;
        default:
            break;
    }
}

Measured memory_bytes: 596
using System;
using System.Linq;
using System.Diagnostics;
using System.Collections.Generic;
using static System.Math;

class P
{
    static void Main()
    {
        Console.WriteLine(Min(int.Parse(Console.ReadLine()), int.Parse(Console.ReadLine())) + Min(int.Parse(Console.ReadLine()), int.Parse(Console.ReadLine())));
    }
}

Measured memory_bytes: 13140