akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;
import java.util.StringTokenizer;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;




public class Main{
	static class MyScanner {
	    BufferedReader br;
	    StringTokenizer st;

	    public MyScanner() {
	       br = new BufferedReader(new InputStreamReader(System.in));
	    }

	    String next() {
	        while (st == null || !st.hasMoreElements()) {
	            try {
	                st = new StringTokenizer(br.readLine());
	            } catch (IOException e) {
	                e.printStackTrace();
	            }
	        }
	        return st.nextToken();
	    } 

	    int nextInt() { return Integer.parseInt(next());}

	    long nextLong() {return Long.parseLong(next());}

	    double nextDouble() {return Double.parseDouble(next());}

	    String nextLine(){
	        String str = "";
		  try {
		     str = br.readLine();
		  } catch (IOException e) {
		     e.printStackTrace();
		  }
		  return str;
	    }
	}
		
	
		 public static void main(String[] args) throws IOException {
			 	PrintWriter out = new PrintWriter(System.out);
			    MyScanner sc = new MyScanner();
			 	Main solver = new Main();
				solver.solve(out, sc);
				out.flush();
				out.close();
			
		 }
	
		
		 
		 
		
 		void solve(PrintWriter out, MyScanner sc) throws IOException{	
 			
 			int a = sc.nextInt();
 			int b = sc.nextInt();
 			int c = sc.nextInt();
 			int k = sc.nextInt();
 			
 			while(k-- > 0) {
 				int max = Math.max(a, Math.max(c, b));
 				if(max == a) a *= 2;
 				else if(max == b) b *= 2;
 				else c *= 2;
 			}
 			out.print(a + b + c);
 			
 				
 			
 			
 			
 		
 		}
 		
 		

 	
		
	
			
		
		
		
		
		
		
		
		
	
	
}



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

int main(){
  char a[4],b[4];
  int x,y,hit,blow;
  int tmp;
  int i,j;

  while(1){
    cin >> x >> y;
    if(!x && !y)break;

    hit = 0;blow = 0;
    tmp = 1000;
    for(i=0;i<4;i++){
      a[i] = x/tmp;
      b[i] = y/tmp;
      x -= a[i] * tmp;
      y -= b[i] * tmp;
      tmp /= 10;
    }
    
    for(i=0;i<4;i++){
      for(j=0;j<4;j++){
	if(a[i] == b[j]){
	  if(i == j)hit++;
	  else blow++;
	}
      }
    }
    cout << hit << " " << blow <<endl;
  }
}

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

int main() {
    ll n;
    cin >> n;
    ll a[n+1];
    rep(i, n+1) cin >> a[i];

    ll ans = 0;
    rep(i, n) {
        ll b;
        cin >> b;
        ll t = min(b, a[i] + a[i+1]);
        ans += t;
        a[i+1] -= t - min(b, a[i]);
    }

    cout << ans << endl;
    return 0;
}


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

int64_t dp[20001];
void chmax(int64_t& a, int64_t b){
    a = max(a, b);
}

int main(){
    int N, W[1000], S[1000], V[1000];
    cin >> N;
    for(int i=0; i<N; i++) cin >> W[i] >> S[i] >> V[i];
    vector<int> order;
    for(int i=0; i<N; i++) order.push_back(i);
    sort(order.begin(), order.end(), [&](int i, int j){ return S[i] + W[i] < S[j] + W[j];});

    for(int i=0; i<N; i++){
        int k = order[i];
        for(int j=20000; j>=0; j--){
            if(j<=S[k]) chmax(dp[j+W[k]], dp[j] + V[k]);
        }
    }
    int64_t ans = 0;
    for(int j=0; j<=20000; j++) chmax(ans, dp[j]);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
import static java.lang.Integer.*;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args)
			throws NumberFormatException, IOException {
		BufferedReader br =
				new BufferedReader(new InputStreamReader(System.in));
		for (int c=1; ; c++) {
			int W = parseInt(br.readLine());
			if (W == 0) break;
			int N = parseInt(br.readLine());
			Item[] it = new Item[N];
			for (int i=0; i < N; i++) {
				it[i] = new Item(br.readLine());
			}
			int[][][] memo = makememo(N, W);
			int[] ans = knapsack(it, N-1, W, memo);
			System.out.println("Case " + c + ":");
			System.out.println(ans[0]);
			System.out.println(ans[1]);
		}
	}

	public static class Item {
		int value;
		int weight;

		public Item(String data) {
			String[] temp = data.split(",");
			value = parseInt(temp[0]);
			weight = parseInt(temp[1]);
		}
	}

	/*
	 * Item[] it?????????index i???????????§?????????????????????????????§
	 * ?????????????¨????w??\?????¨????????????????????§??????v????????§???????????????????????????
	 * ??????????????¨??????????¨??????????
	 */
	public static int[] knapsack(Item[] it, int i, int w, int[][][] memo) {
		int iv = it[i].value;
		int iw = it[i].weight;
		int[] ret = new int[2]; // {value, weight}

		if (memo[i][w][0] != -1) {
			return memo[i][w];
		}

		if (i == 0) {
			if (iw <= w) {
				ret[0] = iv;
				ret[1] = iw;
				return memo[i][w] = ret;
			} else {
				ret[0] = ret[1] = 0;
				return memo[i][w] = ret;
			}
		}

		if (iw > w) {
			return memo[i][w] = knapsack(it, i-1, w, memo);
		}

		int loadedv = knapsack(it, i-1, w-iw, memo)[0] + iv;
		int loadedw = knapsack(it, i-1, w-iw, memo)[1] + iw;
		int notloadedv = knapsack(it, i-1, w, memo)[0];
		int notloadedw = knapsack(it, i-1, w, memo)[1];
		if (loadedv > notloadedv) {
			ret[0] = loadedv;
			ret[1] = loadedw;
		} else if (notloadedv > loadedv) {
			ret[0] = notloadedv;
			ret[1] = notloadedw;
		} else {
			ret[1] = Math.min(loadedw, notloadedw);
			ret[0] = loadedv; // == notloadedv
		}
		return memo[i][w] = ret;
	}

	public static int[][][] makememo(int N, int W) {
		int[][][] memo = new int[N][W+1][2];
		for (int i=0; i < N; i++) {
			for (int j=0; j < W+1; j++) {
				memo[i][j][0] = -1;
			}
		}
		return memo;
	}
}

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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;
typedef tuple<ll, ll, ll, ll, ll> t5;

#define rep(a,n) for(ll a = 0;a < n;a++)
#define repi(a,b,n) for(ll a = b;a < n;a++)

#include <bits/stdc++.h>
using namespace std;

static const ll INF = 1e15;

static const ll mod= 1e9 + 7;

vector<vector<ll>> dp;

int dfs(ll x, ll y) {
	if (x > y) { return dfs(y, x); }
	if (dp[x][y] >= 0) {
		return dp[x][y];
	}
	for (int i = 2; i <= x; i+=2) {
		int lose = dfs(x - i, y + i / 2);
		if (!lose) {
			dp[x][y] = 1;
			return 1;
		}
	}
	for (int i = 2; i <= y; i += 2) {
		int lose = dfs(x + i /2, y -  i);
		if (!lose) {
			dp[x][y] = 1;
			return 1;
		}
	}
	dp[x][y] = 0;
	return 0;
}

int main() {
	ll x, y;
	cin >> x >> y;

	ll u = max(x, y);
	ll l = min(x, y);
	if (abs(u - l) <= 1) {
		cout << "Brown" << endl;
	}
	else {
		cout << "Alice" << endl;
	}

	//dp.assign(100, vector<ll>(100, -1));
	//for (int i = 0; i < 30; i++) {
	//	for (int j = 0; j < 30; j++) {
	//		cout << dfs(i, j) << ",";
	//	}
	//	cout << endl;
	//}


	return 0;
}
	

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

#define rep(i, a, b) for (ll i = (a); i < (b); i++)
typedef uint64_t ull;
typedef int64_t ll;
typedef pair<ll, ll> PLL;

ll N,M;

struct item {
    ll x,y,z;
};

ll f(vector<item> v, ll sx, ll sy, ll sz){
    rep(i,0,N){
        v[i].x *= sx;
        v[i].y *= sy;
        v[i].z *= sz;
    }
    sort(begin(v),end(v),[](const item &p, const item &q){
                return p.x+p.y+p.z > q.x+q.y+q.z;
            });
    ll res = 0;
    rep(i,0,M){
        res += v[i].x + v[i].y + v[i].z;
    }
    return res;
}

signed main() {
    cin>>N>>M;
    vector<item> v;
    rep(i,0,N){
        ll x,y,z;
        cin>>x>>y>>z;
        v.push_back({x,y,z});
    }
    ll ans = -1e10;
    for (auto sx: vector<ll>{-1,1})
        for (auto sy: vector<ll>{-1,1})
            for (auto sz: vector<ll>{-1,1})
                ans = max(ans, f(v,sx,sy,sz));
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int check =0;
    for (int i=0; i<26; i++) {
      for (int j=0; j<15; j++) {
        if (4 * i + 7 * j == N) {
          check++;
        }
      }
    }
    if (check != 0) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }
  }
}

Measured memory_bytes: 22868
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int result = 0;
    for(int j = 1; j <= n; j += 2){
      int count = 0;
      for(int i = 1; i <= j; i += 2){
        if(j % i == 0)
          count++;
      }
      if(count == 8)
        result++;
    }
    System.out.println(result);
  }
}

Measured memory_bytes: 21588
//#include <bits/stdc++.h>
//#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>


#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LLINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979
#define MAXI 7500000

using namespace std;
typedef long long int ll;
typedef pair< long long int, long long  int> P;
typedef string::const_iterator State;

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


int main(void) {

	int r;

	cin >> r;

	if (r < 1200) {
		cout << "ABC" << endl;
	}
	else if (r < 2800) {
		cout << "ARC" << endl;
	}
	else {
		cout << "AGC" << endl;
	}

	return 0;
}

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

struct BFS
{
  size_t N;
  size_t M;
  std::vector<std::vector<size_t>> Graph;
  std::vector<size_t> dist;
  std::vector<std::vector<size_t>> distMap;
  std::deque<size_t> que;
  std::vector<size_t> arrow;

  BFS()
  {
    std::cin >> N;
    std::cin >> M;

    Graph.assign(N, std::vector<size_t>());
    for (size_t i = 0; i != M; i++)
    {
      size_t j1, j2;
      std::cin >> j1 >> j2;
      j1--;
      j2--;
      Graph[j1].push_back(j2);
      Graph[j2].push_back(j1);
    }

    dist.assign(N, -1);
    distMap.assign(N, std::vector<size_t>());
    arrow.assign(N, -1);
  }

  void find(size_t pos)
  {
    dist[pos] = 0;
    distMap[dist[pos]].push_back(pos);
    que.push_back(pos);

    while (que.empty() == false)
    {
      pos = que.front();
      que.pop_front();

      for (size_t i = 0; i != Graph[pos].size(); i++)
      {
        size_t nextPos = Graph[pos][i];

        if (dist[nextPos] != -1)
          continue;

        dist[nextPos] = dist[pos] + 1;
        distMap[dist[nextPos]].push_back(nextPos);
        que.push_back(nextPos);
        arrow[nextPos] = pos;
      }
    }
  }
};

int main()
{
  BFS f;
  f.find(0);

  for (size_t i = 1; i != f.arrow.size(); i++)
  {
    if (f.arrow[i] == -1)
    {
      std::cout << "No" << std::endl;
      return 0;
    }
  }

  std::cout << "Yes" << std::endl;
  for (size_t i = 1; i != f.arrow.size(); i++)
  {
    std::cout << f.arrow[i] + 1 << std::endl;
  }

  return 0;
}


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

using namespace std;

int main()
{
	int N;
	cin >> N;
	for(size_t i = 0; i < N; i++)
	{
		long double p , q;
		cin >> p >> q;
		int count=0;
		for(long double m = 0; m < 145; m++)
		{
			for(long double n = 0; n < 145; n++)
			{
				if(m||n)
				{
					long double x=(m*q-p*n)/(m*m+n*n);
					long double y=(p*m+n*q)/(m*m+n*n);
					if(x==(long long int)x&&y == ( long long int )y)
					{
						count++;
					}
				}
			}
		}
		if(count>4)
		{
			cout<<'C'<<endl;
		} else
		{
			cout<<'P'<<endl;
		}
	}
}

Measured memory_bytes: 1224
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 = new long[n];
		long[] b = new long[n];
		for(int i = 0 ; i < n ; i++) {
			a[i] = sc.nextLong();
			b[i] = sc.nextLong();
		}
		long c = 1;
		long d = 1;
		for(int i = 0 ; i < n ; i++) {
			// c <= x * a[i] & d <= x * b[i]なる最小のxを求める
			// x = 3, c/a[i] = 2.5の場合、切り上げが必要なことに注意
			long x = Math.max((c + a[i] - 1) / a[i], (d + b[i] - 1) / b[i]);
			c = a[i] * x;
			d = b[i] * x;
		}
		System.out.println(c + d);
	}
}


Measured memory_bytes: 25448
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define LLINF (1e18)
#define PI (acos(-1))
#define MOD (1000000007)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    for (ll i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    vector<ll> rui(n + 1, 0);
    for (ll i = 0; i < n; i++)
    {
        rui[i + 1] = rui[i] + a[i];
    }
    vector<ll> kouho;
    for (ll i = 0; i <= n; i++)
    {
        for (ll j = i + 1; j <= n; j++)
        {
            kouho.push_back(rui[j] - rui[i]);
        }
    }
    sort(RALL(kouho));
    vector<ll> now = kouho;
    for (ll i = 63; i >= 0; i--)
    {
        vector<ll> next;
        for (ll j = 0; j < (ll)now.size(); j++)
        {
            if (now[j] & (1LL << i))
            {
                next.push_back(now[j]);
            }
        }
        if ((ll)next.size() >= k)
        {
            now = next;
        }
    }
    ll ans;
    for (ll i = 0; i < k; i++)
    {
        i == 0 ? ans = now[i] : ans &= now[i];
    }
    cout << ans << endl;
}


Measured memory_bytes: 9964
N,K=map(int,input().split())
p=list(map(int,input().split()))
p = [0]+p
for i in range(1,N+1):
  p[i]=p[i-1]+p[i]
ret = 0
for i in range(1,N-K+2):
  ret = max(p[i+K-1]-p[i-1],ret)
ret = (ret+K)/2
print(ret)

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

using namespace std;

int main()
{
	int n;

	std::cin >> n;
	
	vector<int> p(n);

	for (int i = 0; i < n; i++) {
		cin >> p[i];
	}
	int count = 0;
	for (int i = 0; i < n; i++) {
		if (p[i] != i + 1)
			count++;
	}
	
	if (count < 3)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <iomanip>
#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 <cstdio>        // printf
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <cctype>        // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <numeric>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
const int INF = 1001001001;

int main()
{
    int N;
    cin >> N;
    vector<int> v(N);
    rep(i, N) cin >> v.at(i);

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

    int d = 0;

    rep(i, N-1)
    {
        d += (v.at(i+1)-v.at(i));
    }
    cout << d << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<bitset>
#include<cstdio>
#include<cmath>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<string>
#include<tuple>
#include<utility>
#include<vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<vector<int>> vvi;

#define rep(i, a, n)  for(int i=a; i<n; i++)
#define REP(i, n)  for(int i=0; i<(int)(n); i++)
#define REPS(i, n)  for(int i=1; i<=(int)(n); i++)
#define PER(i, n) for(int i=(int)(n)-1; i>= 0; i--)
#define PERS(i, n)  for(int i=(int)(n)-1; i>0; i--)
#define FOR(i, c) for(__typeof((c).begin()) i = (c).begin(); i!=(c).end(); i++)
#define RFOR(i, c)  for(__typeof((c).rbegin()) i=(c).rbegin(); i!=(c).end(); i++)
#define ALL(container)  (container).begin(), (container).end()
#define RALL(container) (container).rbegin(), (container).rend()
#define SZ(container) (container).size()
#define FILL0(n)  setfill('0') << right << setw(n)
#define mp(a, b)  make_pair(a, b)
#define toLower(c)  c+0x20
#define toUpper(c)  c-0x20
#define pb  push_back
#define eb  emplace_back

const int INF = 1e9;
const long long LLINF = 1e18;
const int MOD = 1000000007;

int main(){
  int n;  cin >> n;
  vector<int> p(n);
  REP(i, n) cin >> p[i];
  int ans = 0;
  rep(i, 1, n-1){
    int m = min({p[i-1], p[i], p[i+1]}), M = max({p[i-1], p[i], p[i+1]});
    if(p[i] != m && p[i] != M)  ans ++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
const int MAXN=317;
const int BASE=29;
using namespace std;

#pragma GCC optimize("O3")
#pragma GCC target("sse4")

int n;
string s;
unsigned long long h[MAXN][MAXN], h1[MAXN][MAXN];
string col[MAXN], row[MAXN];
void mainp()
{
    for(int i=0; i<MAXN; i++) col[i]="";
    
    cin>>n;
    for(int i=0; i<n; i++)
    {
        cin>>row[i];
        for(int j=0; j<n; j++) col[j]+=row[i][j];
    }
    
    for(int i=0; i<n; i++)
        for(int j=0; j<n; j++)
        {
            unsigned long long temp=0;
            for(int jj=0; jj<n; jj++)
            {
                temp*=BASE;
                temp+=row[i][(j+jj)%n]-'a'+1;
            }
            h[i][j]=temp;
            //cout<<i<<" "<<j<<" "<<temp<<endl;
        }
    //cout<<endl;
    
    for(int i=0; i<n; i++) //number of the column
        for(int j=0; j<n; j++) //rotation number
        {
            unsigned long long temp=0;
            for(int jj=0; jj<n; jj++)
            {
                temp*=BASE;
                temp+=col[i][(j+jj)%n]-'a'+1;
            }
            h1[i][j]=temp;
            //cout<<i<<" "<<j<<" "<<temp<<endl;
        }
    //cout<<endl;
    
    int ans=0;
    for(int a=0; a<n; a++)
        for(int b=0; b<n; b++)
        {
            int fl=1;
            for(int num=0; num<n; num++) if(h[(num+a)%n][b]!=h1[(num+b)%n][a]) fl=0;
            
            if(fl) ans++;
        }
        
    cout<<ans<<endl;
}

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


Measured memory_bytes: 2048
import Control.Applicative
import Control.Monad
import Data.List
import Text.Printf
rInt s = read s :: Int
 
main = do
   [a, b] <- map rInt . words <$> getLine
   putStr $ unwords $ (map show [div a b, mod a b]) 
   putChar ' '
   printf "%.8f\n" ((fromIntegral a) / (fromIntegral b) :: Double)

Measured memory_bytes: 4080
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits.h>
#include <climits>
#include <map>
#include <unordered_map>
#include <cmath>
#include <set>
#include <unordered_set>
#include <iterator>
#include <deque>
#include <assert.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
ull min(ull x, ull y){ if (x<y) return x; return y;}
ull max(ull x, ull y){ if (x<y) return y; return x;}
ll min(ll x, ll y){ if (x<y) return x; return y;}
ll max(ll x, ll y){ if (x<y) return y; return x;}
double min(double x, double y){ if (x<y) return x; return y;}
double max(double x, double y){ if (x<y) return y; return x;}
ull gcd(ull x, ull y){
    if (!x) return y;
    if (!y) return x;
    if (x>y) swap(x,y);
    return gcd(x, y%x);
}
ull inv(ull a, ull c){ // a,c are coprime and a<c
    if (a==1){
        return 1;
    }
    return ((c-(c/a))*inv(c%a,c))%c;
}


int main(){
 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    int a, b, c, d;
    cin>>a>>b>>c>>d;
    if ((c+b-1)/b<=(a+d-1)/d){
        cout<<"Yes\n";
    }
    else{
        cout<<"No\n";
    }
    

    return 0;
}





Measured memory_bytes: 3108
#include <bits/stdc++.h>
#include <tuple>
using namespace std;
using ll = long long;

int main()
{
  ll n, k;
  cin >> n >> k;
  vector<pair<int, int>> ab(n);
  for (int i = 0; i < n; ++i)
  {
    cin >> ab[i].first >> ab[i].second;
  }
  sort(ab.begin(), ab.end());
  ll res = 0;
  for (ll i = 0; i < ab.size(); ++i)
  {
    res += ab[i].second;
    if (res >= k)
    {
      cout << ab[i].first << endl;
      return 0;
    }
  }

  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll INF =1e9+7;
#define ii pair<ll,ll>;
#define f(i,a,b) for(ll i = a;i < b;i++)
#define rf(i,a,b) for(ll i=a;i>=b;i--)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define w(t) while(t--)
#define c(n); cin>>n;
#define p(n) cout<<n;
#define pl(n) cout<<n<<endl;
#define ps(n); cout<<n<<" ";

int main(){
    ll n;
    c(n);
    f(i,1,10){
        f(j,1,10){
            if(i*j == n){
                cout<<"Yes";
                return 0;
            }
        }
    }
    cout<<"No";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a) for(int i=0;i<(a);i++)
const ll MOD=1000000007;
//const ll MOD=998244353;

int to[1<<12],from[1<<12];

int main(){
  int N,M; cin>>N>>M;
  int A[M],B[M];
  vector<vector<int>> V(M);
  rep(i,M){
    cin>>A[i]>>B[i];
    rep(j,B[i]){
      int c; cin>>c; c--;
      V[i].push_back(c);
    }
  }
  rep(i,1<<N) from[i]=to[i]=1e9;
  from[0]=0;
  rep(i,M){
    rep(j,(1<<N)){
      to[j]=min(to[j],from[j]);
      int bit=j;
      for(int c:V[i]) bit|=1<<c;
      to[bit]=min(to[bit],from[j]+A[i]);
    }
    swap(to,from);
  }
  if(from[(1<<N)-1]==1e9) cout<<"-1\n";
  else cout<<from[(1<<N)-1]<<endl;
  return 0;
}

Measured memory_bytes: 3692
from bisect import bisect

N, K, Q = map(int, input().split())
A = [int(input()) for _ in range(Q)]

A.sort()

for i in range(N):
    if bisect(A, i + 1) - bisect(A, i) > Q - K:
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 62808
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
int main()
{
    string s;
    cin>>s;
    int c=0;
    for(int i=0;i<3;i++) if(s[i]=='R') c++;
    if(c==2)
    {
                if(s[0]=='R'&&s[1]=='R') cout<<"2\n";
                else if(s[2]=='R'&&s[1]=='R') cout<<"2\n";
                else cout<<"1\n";
    }
    else
    {
        cout<<c<<endl;
    }
    

}

Measured memory_bytes: 3624
l=[]
for i in range(int(input())):
    n=i+1
    if n%15==0:
        a="FizzBuzz"
    elif n%3==0:
        a="Fizz"
    elif n%5==0:
        a="Buzz"
    else:
        a=n
        l.append(a)
    
print(sum(l))

Measured memory_bytes: 30024
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long int64;
 
int main()
{
  int64 K;
  cin >> K;

  vector< int64 > vs(50, 50);
  vector< vector< int64 > > st;
  while(*max_element(begin(vs), end(vs)) >= 50) {
    auto p = *max_element(begin(vs), end(vs));
    for(int i = 0; i < vs.size(); i++) {
      if(vs[i] == p) {
        vs[i] -= 51;
        break;
      }
    }
    for(int i = 0; i < vs.size(); i++) vs[i]++;
    st.push_back(vs);
  }
  reverse(begin(st), end(st));

  vector< int64 > stt;
  cout << 50 << endl;
  for(int i = 0; i < 50; i++)  cout << st[K % 50][i] + K / 50 << " ";  
  cout << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python

n = int(input())

if n == 0:
    print(0)
    exit()

ans = ''
while abs(n) > 0:
    r = n%2 
    ans = str(r) + ans 
    
    if r == 1:
        n -= 1
    n //= (-2)

print(ans)


Measured memory_bytes: 9168
# Problem C - Candies

# input
N = int(input())
candie_board = [[0]*N for i in range(2)]
for i in range(2):
    a_list = list(map(int, input().split()))
    for j in range(len(a_list)):
        candie_board[i][j] = a_list[j]

# initialization
cost_board = [[0]*N for i in range(2)]
cost_board[0][0] = candie_board[0][0]
visit_queue = []
visit_queue.append([0, 0])

# search
while len(visit_queue)>0:
    v = visit_queue.pop(0)
    x = v[0]
    y = v[1]

    # right
    if y+1<N:
        cost_board[x][y+1] = max(cost_board[x][y+1], cost_board[x][y] + candie_board[x][y+1])
        visit_queue.append([x, y+1])

    # down
    if x+1<2:
        cost_board[x+1][y] = max(cost_board[x+1][y], cost_board[x][y] + candie_board[x+1][y])
        visit_queue.append([x+1, y])

# output
print(cost_board[1][N-1])


Measured memory_bytes: 39024
#include <bits/stdc++.h>
using namespace std;
#ifdef _DEBUG
#define dlog(str) cout << "====" << str << endl;
#else
#define dlog(str)
#endif
#define INF 999999999
#define MOD 1000000007
#define REP(i, n) for(int i = 0, i##_l = (n); i < i##_l; i++)
#define FOR(i, s, e) for(int i = s, i##_l = (e); i < i##_l; i++)
#define LLI long long int
#define _min(a, b) ((a < b) ? a : b)
#define _max(a, b) ((a < b) ? b : a)
#define chmax(a, b) a = _max(a, b)
#define chmin(a, b) a = _min(a, b)
#define bit(a, shift) ((a>>shift)&1))
#define pm(a) ((a) ? 1 : -1)
#define SORT(v) sort(v.begin(), v.end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
// int 2.14E±9    lli 9.2E±18    double 1.7E±380
int main() {
    const int MN = 1001;
    int N, i, j;
    int a[MN][MN];
    int days = -1;
    int idx[MN];
    bool use[MN];
    bool fin = true;
    cin >> N;
    for(i = 1; i <= N; i++) {
        for(j = 0; j < N - 1; j++) {
            cin >> a[i][j];
        }
    }
    while(fin) {
        days++;
        fin = false;
        for(int i = 1; i <= N; i++) {
            use[i] = false;
        }
        for(int i = 1; i <= N; i++) {
            if(idx[i] != N - 1) {
                j = a[i][idx[i]];
                if(!use[i] && !use[j] && a[j][idx[j]] == i) {
                    idx[i]++;
                    idx[j]++;
                    use[i] = true;
                    use[j] = true;
                    fin = true;
                }
            }
        }
    }
    for(i = 1; i <= N; i++)
        if(idx[i] != N - 1)
            break;
    if(i == N + 1)
        cout << days << endl;
    else
        cout << -1 << endl;
    return 0;
}


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

int N,M,k[15],s[15][15],p[15],ans;

bool check(int x)
{
	for(int i = 1; i <= M; i++){
		int res = 0;
		for(int j = 0; j < k[i]; j++){
			res ^= (x >> s[i][j]) & 1;
		}
		if(res != p[i]) return 0;
	}
	return 1;
}

int main()
{
	cin >> N >> M;
	for(int i = 1; i <= M; i++){
		cin >> k[i];
		for(int j = 0; j < k[i]; j++){
			cin >> s[i][j];
			s[i][j]--;
		}
	}
	for(int i = 1; i <= M; i++) cin >> p[i];
	for(int i = 0; i < (1<<N); i++){
		if(check(i)) ans++;
	}
	cout << ans << endl;
	return 0;
}

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

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;
}

// define a positive infinity value as INF
const long long INF = 1LL << 60;

int main()
{
  // DP table
  long long dp[100010];

  // initilize DP table with INF
  for ( int i = 0; i < 100010; i++ ) dp[i] = INF;

  // initilize the cost of the first position with 0 
  dp[0] = 0;

  // input
  int N; std::cin >> N;
  long long h[100010];
  for ( int i = 0; i < N; i++ ) std::cin >> h[i];

  dp[1] = dp[0] + std::abs(h[1] - h[0]);
  for ( int i = 2; i < N; i++ ) {
    chmin(dp[i], dp[i-1] + std::abs(h[i] - h[i-1]));
    chmin(dp[i], dp[i-2] + std::abs(h[i] - h[i-2]));
  }
  for ( int i = 0; i < N; i++ ) std::cerr << dp[i] << std::endl;

  std::cout << dp[N-1] << std::endl;
  return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>

using namespace std;
int main() {
	string s;
	cin>> s;
	int a[26] = {0};
	int sum = 0;
	for (int i = 0; i < s.size(); i++) {
		a[s[i] - 'a']++;
	}
	for (int i = 0; i < 26; i++) {
		if (a[i] % 2) {
			cout << "No" << endl;
			return 0;
		}
	}
	
	cout << "Yes" << endl;
	

	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <iostream>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
typedef long long ll;

const ll LIMIT = 1000000000000000000LL;

int main(void) {
  int n;
  scanf("%d", &n);
  ll r = 1;
  bool over = false;
  REP(i, n) {
    ll a;
    scanf("%lld", &a);
    if(a == 0) {
      r = 0;
      break;
    }
    if(r > LIMIT / a) {
      over = true;
    } else {
      r *= a;
    }
  }
  if(r != 0 && over) {
    r = -1;
  }
  cout << r << endl;
  return 0;
}


Measured memory_bytes: 3256
n, m = gets.strip.split.map(&:to_i)
a = gets.strip.split.map(&:to_i)
bc = []
m.times do
  bc << gets.strip.split.map(&:to_i)
end
a.sort!
bc.sort_by!{|b,c|-c}
i = 0

m.times do |index|
  bc[index][0].times do
    if bc[index][1] > a[i]
      a[i] = bc[index][1]
      i += 1
      if i == n
        i = 0
        break
      end
    else
      i = 0
      break
    end
  end
  if i == 0
    break
  end
end
puts a.inject(:+)

Measured memory_bytes: 21952
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int a = sc.nextInt();
        int b = sc.nextInt();
        String c[] = new String[a];
        String cc[][] = new String[a][b];
        int tate[] = new int[a];
        int yoko[] = new int[b];
        Arrays.fill(tate,0);
        Arrays.fill(yoko,0);
        int i,j;
      	for(i = 0;i < a;i++){
          c[i] = sc.next();
          cc[i] = c[i].split("");
        }
        for(i = 0;i < a;i++){
          for(j = 0;j < b;j++){
            if(cc[i][j].equals("#")){
            tate[i] = 1;
            yoko[j] = 1;
            }
          }
        }
      	for(i = 0;i < a;i++){
          if(tate[i] == 1){
          	for(j = 0;j < b;j++){
            	if(yoko[j] == 1){
             		 System.out.print(cc[i][j]);
           		}
          	}
          System.out.println("");            
          }
        }
    }
}

Measured memory_bytes: 39912
import sys; input = sys.stdin.buffer.readline
from collections import defaultdict
con = 998244353; INF = float("inf")

def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	N, S = getlist()
	A = getlist()
	DP = [[0] * (S + 1) for i in range(N + 1)]
	DP[0][0] = 1
	for i in range(N):
		for j in range(S + 1):
			DP[i + 1][j] += 2 * DP[i][j]
			DP[i + 1][j] %= con
			w = A[i]
			if j + w <= S:
				DP[i + 1][j + w] += DP[i][j]
				DP[i + 1][j + w] %= con

	print(DP[-1][-1])


if __name__ == '__main__':
	main()

Measured memory_bytes: 139768
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long
int dp[110][100010];

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

    return 0;
}


Measured memory_bytes: 79360
#include <bits/stdc++.h>
 
using namespace std;
 
typedef string::const_iterator State;
class ParseError {};
 
typedef unsigned long long ull;
#define loop(i,a,b) for(int i=(a);i<ull(b);++i)
#define rep(i,n) loop(i,0,n)
#define all(a) (a).begin(), (a).end()
 
const double eps = 1e-10;
const double pi  = acos(-1.0);
const double inf = (int)1e8;
 
int expression(State &begin);
int term(State &begin);
int number(State &begin);
int factor(State &begin);
 
int number(State &begin) {
    int ret = 0;
 
    while (isdigit(*begin)) {
        ret *= 10;
        ret += *begin - '0';
        begin++;
    }
    return ret;
}
 
int term(State &begin) {
    int ret = factor(begin);
 
    for (;;) {
        if (*begin == '*') {
            begin++;
            ret *= factor(begin);
        } else if (*begin == '/') {
            begin++;
            ret /= factor(begin);
        } else {
            break;
        }
    }
    return ret;
}
 
int expression(State &begin) {
    int ret = term(begin);
 
    for (;;) {
        if (*begin == '+') {
            begin++;
            ret += term(begin);
        } else if (*begin == '-') {
            begin++;
            ret -= term(begin);
        } else {
            break;
        }
    }
 
    return ret;
}
 
int factor(State &begin) {
    if (*begin == '(') {
        begin++; // '('?????£???????´\????????£????´???£??????°?????£?????????£?????
        int ret = expression(begin);
        begin++; // ')'?????£???????´\????????£????´???£??????°?????£?????????£?????
        return ret;
    } else {
        return number(begin);
    }
}
 
int main(void) {
    int N;
    cin >> N;
    cin.ignore();
    for (int i = 0; i < N; i++) {
        string s;
        getline(cin, s);
        State begin = s.begin();
        cout << expression(begin) << endl;
    }
    return 0;
}

Measured memory_bytes: 1212
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<math.h>
// #include<bits/stdc++.h>
using namespace std;
#define ll long long
constexpr long long int INFLL = 1001001001001001LL;
constexpr int INFI = 1000000007;


int main(){
  int N;
  cin >> N;
  vector<vector<int>> G(2,vector<int> (N));
  for(int i=0; i<2; i++){
    for(int j=0; j<N; j++){
      cin >> G[i][j];
    }
  }
  int ans=0;
  for(int i=0; i<N; i++){
    int sum_up=0;
    for(int j=0;j<=i; j++){
      sum_up += G[0][j];
    }
    int sum_down=0;
    for(int j=N-1; j>=i; j--){
      sum_down += G[1][j];
    }
    ans = max(ans,sum_up+sum_down);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"math"
	"math/big"
)

func main() {
	solve()
}

func solve() {
	var a, b int
	fmt.Scan(&a, &b)
	res := "No"
	if a <= b {
		res = "Yes"
	}
	fmt.Print(res)
}

func max(x int, y ...int) int {
	res := float64(x)
	for _, z := range y {
		res = math.Max(res, float64(z))
	}
	return int(res)
}

func min(x int, y ...int) int {
	res := float64(x)
	for _, z := range y {
		res = math.Min(res, float64(z))
	}
	return int(res)
}

func abs(x int) int {
	return int(math.Abs(float64(x)))
}

func sqrt(x int) int {
	return int(math.Sqrt(float64(x)))
}

func int2Int(x int) big.Int {
	var res big.Int
	res.SetInt64(int64(x))
	return res
}


Measured memory_bytes: 640
package main

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

func IsSafety(s int, w int) string {
	var isSafe string
	if w >= s {
		isSafe = "unsafe"
	} else {
		isSafe = "safe"
	}
	return isSafe
}

func main() {
	stdin := bufio.NewScanner(os.Stdin)
	stdin.Scan()
	args := strings.Split(stdin.Text(), " ")
	s, _ := strconv.Atoi(args[0])
	w, _ := strconv.Atoi(args[1])
	isSafe := IsSafety(s, w)
	fmt.Println(isSafe)
}


Measured memory_bytes: 1760
# from itertools import accumulate
import numpy as np

N = int(input())
P = list(map(int, input().split()))

ans = 0

"""
for i, p in enumerate(P):
    # if np.any(P[0:i] < p): あまり以下と変わらなかった
    # if any([True for p2 in P[0:i] if p2 < p]): # 2回のループが☓ O(n^2)なので
        pass
    else:
        ans += 1
"""

"""
自分のラスト回答
P_min = list(accumulate(P, min))

for p, p_min in zip(P, P_min):
    if p == p_min:
        ans += 1
"""

P_min = np.minimum.accumulate(P)

print(np.count_nonzero(P <= P_min))

Measured memory_bytes: 34140
import math
 
A, B, H, M = map(int, input().split())
 
angle = (30 * H + 0.5 * M) - (6 * M)
if angle < 0:
    angle *= -1
 
cos = math.cos(math.radians(angle))
 
x = A ** 2 + B ** 2 - (2 * A * B * cos)
 
print(math.sqrt(x))

Measured memory_bytes: 9512
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int z=n%10;
	if(z==2||z==4||z==5||z==7||z==9)
	cout<<"hon";
	else if(z==0||z==1||z==6||z==8)
	cout<<"pon";
	else
	cout<<"bon";
}

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

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, a, b) for (ll i = (a); i < (b); i++)
#define chmax(x, v) do { x = max(x, v); } while(0)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;

using namespace std;

signed main() {
  ll m1,d1,m2,d2;
  cin>>m1>>d1>>m2>>d2;
  cout << (d1+1!=d2) << endl;
}


Measured memory_bytes: 256
def solve(l, r, A, dp):
    if r - l < 2:
        return max(A[l:r + 1])

    x1 = dp[l + 2][r] if dp[l + 2][r] != -1 else solve(l + 2, r, A, dp)
    x2 = dp[l + 1][r - 1] if dp[l + 1][r - 1] != -1 else solve(l + 1, r - 1, A, dp)
    x3 = dp[l][r - 2] if dp[l][r - 2] != -1 else solve(l, r - 2, A, dp)

    dp[l][r] = max(min(x1, x2) + A[l], min(x2, x3) + A[r])

    return dp[l][r]


N = int(input())
A = [int(i) for i in input().split()]
dp = [[-1] * N for i in range(N)]
print(2*solve(0, N-1, A, dp)-sum(A))


Measured memory_bytes: 186120
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF=100000000000000005;
const int maxn=1e6+5;
const int mod=433494437;
ll n,m;
char str[maxn];
char cop[maxn];
map<char,ll>mp;
int main()
{
    ll r,s,p;// rock s paper
    scanf("%lld%lld",&n,&m);
    scanf("%lld%lld%lld%s",&r,&s,&p,str+1);
    mp['r']=r;
    mp['s']=s;
    mp['p']=p;
    for(int i=1;i<=n;i++)
    {
        if(str[i]=='r') cop[i]='p';
        if(str[i]=='p') cop[i]='s';
        if(str[i]=='s') cop[i]='r';
    }
    ll res=0;
    for(int i=1;i<=m;i++)
    {
        res+=mp[cop[i]];
        for(int k=i+m;k<=n;k+=m)
        {
            if(cop[k]!=cop[k-m])
                res+=mp[cop[k]];
            else
                cop[k]='.';
        }
    }
    printf("%lld\n",res);
    return 0;
}


Measured memory_bytes: 384
//Author : Nishit Patel
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef double db;
typedef long long ll;
#define pb push_back
#define FAST cin.sync_with_stdio(0); cin.tie(0);
#define rep(i, n)      for(int i = 0; i < (n); ++i)
#define arep(i, a, n)  for(int i = a; i <= (n); ++i)
#define drep(i, a, n)  for(int i = a; i >= (n); --i)
#define trav(a, x)     for(auto& a : x)
#define all(x) x.begin(), x.end()
typedef pair<int, int> pii;
typedef vector<ll> vl;
typedef map<ll, ll> ml;
typedef unordered_map<ll, ll> hash;
#define deb_1(A)                     {cerr << "[" << #A << "] : " << A << endl;}
#define deb_2(A,B)                   {cerr << "[" << #A << "] : " << A << endl<< "[" << #B << "] : " << B << endl;}
#define deb_3(A,B,C)                 {cerr << "[" << #A << "] : " << A << endl<< "[" << #B << "] : " << B << endl\
									   << "[" << #C << "] : " << C << endl;}
#define deb_4(A,B,C,D)               {cerr << "[" << #A << "] : " << A << endl<< "[" << #B << "] : " << B << endl\
									   << "[" << #C << "] : " << C << endl<< "[" << #D << "] : " << D << endl;}
#define deb_X(x,A,B,C,D,FUNC, ...)  FUNC  
#define deb(...)                    deb_X(,##__VA_ARGS__,\
                                          deb_4(__VA_ARGS__),\
                                          deb_3(__VA_ARGS__),\
                                          deb_2(__VA_ARGS__),\
                                          deb_1(__VA_ARGS__),\
                                         )
                                         
                                         
#define L 1000005
ll memo[1000005];
map<ll, list<ll>> v;
ll dfs(ll curr)
{
	 if(memo[curr] != -1)
	 {
		 return memo[curr];
	 }
	 int toogle = 0;
	 ll logest_depth =0;
	 for(auto i: v[curr])
	 {
		toogle = 1;
		logest_depth = max(logest_depth,dfs(i));
	 }
	 if(toogle ==0)return memo[curr]=0;
	 
	 return memo[curr] = logest_depth + 1;
}
int main() {
	FAST
	ll n,m,x,y;
	cin>>n>>m;
	rep(i,m)
	{
		cin>>x>>y;
		v[x].pb(y);
	}
	ll depth = INT_MIN;
	memset(memo, -1, sizeof(memo));
	arep(i,1,n)
	{
		if(memo[i] == -1)
		{
			depth= max(depth,dfs(i));
		}
			
	}
	cout<<depth<<endl;
}


Measured memory_bytes: 26384
#define _USE_MATH_DEFINES
#include<iostream>
#include<algorithm>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<deque>
#include<queue>
#include<map>
#include<set>
#define ll long long
#define str string
#define ld long double
#define vec vector
#define vll vec<ll>
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,b,a) for(ll i=b;i>=a;i--)
#define ALL(a) a.begin(),a.end()
#define rALL(a) a.rbegin(),a.rend()
#define kai "\n"
#define yuque priority_queue
#define ryuque(t) priority_queue<t,vec<t>,greater<t>>
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define mie min_element
#define mae max_element
#define tos to_string
#define sep setprecision
#define MOD 1000000007ll
using namespace std;
void solve();
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed;
	solve();
}

//nCk(mod p)
const ll NUM = 2;
ll fac[NUM], finv[NUM], inv[NUM];
void cmodf(ll p = MOD) {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	rep(i, 2, NUM) {
		fac[i] = fac[i - 1] * i%p;
		inv[i] = p - inv[p%i] * (p / i) % p;
		finv[i] = finv[i - 1] * inv[i] % p;
	}
}
ll cmod(ll n, ll k, ll p = MOD) {
	return fac[n] * (finv[k] * finv[n - k] % p) % p;
}

//最大公約数
ll gcd(ll n, ll m) {
	ll k = n % m;
	while (k != 0) { n = m; m = k; k = n % m; }
	return m;
}
ll gcd(vector<ll> a) {
	rep(i, 1, a.size()) {
		ll k = a[i - 1] % a[i];
		while (k != 0) {
			a[i - 1] = a[i];
			a[i] = k;
			k = a[i - 1] % a[i];
		}
	}
	return a.back();
}

//最小公倍数
ll lcm(ll n, ll m) {
	ll t = n * m, k = n % m;
	while (k != 0) { n = m; m = k; k = n % m; }
	return t / m;
}
ll lcm(vector<ll> a) {
	ll n;
	rep(i, 1, a.size()) {
		n = a[i - 1] * a[i];
		ll k = a[i - 1] % a[i];
		while (k != 0) {
			a[i - 1] = a[i];
			a[i] = k;
			k = a[i - 1] % a[i];
		}
		n /= a[i];
		a[i] = n;
	}
	return n;
}

//keyの小さい方から探していった時に初めてvalueがjoken以上になる時のkey（keyが増えたらvalueも増えるか同じになるとき）
ll value(ll key) {
	/*変更*/
	return 0;
}
ll mink(ll lkey, ll rkey/*ここも調べる*/, ll joken) {
	ll mkey;
	while (lkey != rkey) {
		mkey = (lkey + rkey) / 2;
		if (value(mkey) >= joken)rkey = mkey;
		else lkey = mkey + 1;
	}
	return rkey;
}

//ペア配列の整理
struct pea {
	ll f, s;
	bool operator<(const pea &c)const {
		return f != c.f ? f < c.f : s < c.s;
	};
};

//変数定義

//再帰関数

//アルゴリズム
void solve() {
	ll n; cin >> n;
	vec<vll> c(n, vll(n));
	rep(i, 0, n)rep(j, 0, n)cin >> c[i][j];
	ll ans = MOD;
	rep(i, 0, 1) {
		vec<vll> a(n, vll(n));
		rep(j, 0, n)rep(k, 0, n)a[j][k] = c[j][k];
		ll t = 0;
		vll b; b.pub(i);
		rep(j, 0, n)a[j][i] = -1;
		while (b.size() != n) {
			ll m = MOD, kk;
			rep(j, 0, b.size()) {
				rep(k, 0, n) {
					if (a[b[j]][k] != -1 && a[b[j]][k] < m) {
						kk = k;
						m = a[b[j]][kk];
					}
				}
			}
			t += m;
			b.pub(kk);
			rep(j, 0, n)a[j][kk] = -1;
		}
		ans = min(ans, t);
	}
	cout << ans << kai;
}


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

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL 9223372036854775
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 1000000007
#define MOD9 998244353
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

using II = pair<int, int>;

int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
int extgcd(int a, int b, int &x, int &y) { int g = a; x = 1; y = 0; if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x; return g; }

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a)  begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

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

signed main()
{
  string a; cin >> a;
  REP(n,100) {
    if(S[n] == a) {
      cout << 7 - n << endl;
      return 0;
    }
  }
  return 0;
}


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

N,M = map(int, input().split())

lst_ans = [0] * N
lst_correct = [False]*N

correct = 0
penalty = 0
for _ in range(M):

	p, S = input().split()
	p = int(p)
	if (S == 'AC' and lst_correct[p-1]==False):
		penalty += lst_ans[p-1]
		lst_correct[p-1]=True
		correct += 1
	else :
		lst_ans[p-1]+=1

print(correct, penalty)

Measured memory_bytes: 42476
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int count = scanner.nextInt();
        int stepSize = scanner.nextInt();

        int[] dp = new int[count];
        int[] arr = new int[count];
        for (int i = 0; i < count; ++i) {
            arr[i] = scanner.nextInt();
        }

        for (int i = 1; i < count; ++i) {
            dp[i] = Integer.MAX_VALUE;
            for (int j = 1; j <= Math.min(i, stepSize); ++j) {
                dp[i] = Math.min(dp[i - j] + Math.abs(arr[i] - arr[i - j]), dp[i]);
            }
        }
        System.out.println(dp[count - 1]);
    }
}


Measured memory_bytes: 62508
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce


sys.setrecursionlimit(2147483647)
INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().rstrip().split()
def S(): return sys.stdin.readline().rstrip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]

mod=10**9+7

n=I()
A=LI()
c=1
for i in range(2,n+1):
    c=c*i%mod

C=[0]*(n+2)
ret=c
for i in range(2,n+1):
    C[i]=c*pow(i,mod-2,mod)%mod
    ret+=C[i]
    ret%=mod

ans=0
for j in range(n):
    ans+=ret*A[j]%mod
    ans%=mod
    ret-=C[n-j]
    ret+=C[j+2]

print(ans)

Measured memory_bytes: 98724
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int M=3010;
char s[M],t[M];
int dp[M][M],n,m,l,r;
int main()
{
    scanf("%s%s",s+1,t+1);
    n=strlen(s+1);
    m=strlen(t+1);
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
        {
            if(s[i]==t[j])
                dp[i][j]=dp[i-1][j-1]+1;
            else
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
        }
    string ans="";
    for(int x=n,y=m;x && y;)
    {
        if(dp[x][y]==dp[x-1][y]) x--;
        else if(dp[x][y]==dp[x][y-1]) y--;
        else ans+=s[x],x--,y--;
    }
    reverse(ans.begin(),ans.end());
    cout<<ans<<'\n';
    return 0;
}


Measured memory_bytes: 35584