akhauriyash/Code-Regression huggingface dataset:
# -*- coding:utf-8 -*-

def solve():
    N, K = list(map(int, input().split(" ")))
    S = input()

    # 累積和で解く
    i = 0
    ruiseki = [0]
    while True:
        if i >= N:
            break
        
        num = 0
        if S[i] == "1":
            while i < N and S[i] == "1":
                num += 1
                i += 1
            ruiseki.append(num + ruiseki[-1])
        else:
            while i < N and S[i] == "0":
                num += 1
                i += 1
            ruiseki.append(num + ruiseki[-1])

    import math
    if S[0] == "1":
        zero_num = math.floor((len(ruiseki)-1)/2)
    else:
        zero_num = math.ceil((len(ruiseki)-1)/2)

    if K >= zero_num:
        print(ruiseki[-1])
        return

    ans = 0
    if S[0] == "1":
        for i in range(2, len(ruiseki), 2):
            end = i + 2*(K-1)
            if end >= len(ruiseki):
                break
            if end+1 < len(ruiseki):
                # 後ろが"1"のとき
                end += 1

            ans = max(ruiseki[end]-ruiseki[i-2], ans)

    else:
        for i in range(1, len(ruiseki), 2):
            end = i + 2*(K-1)
            if end >= len(ruiseki):
                break
            if end+1 < len(ruiseki):
                end += 1

            if i-2 >= 0:              
                ans = max(ruiseki[end]-ruiseki[i-2], ans)
            else:
                ans = max(ruiseki[end]-ruiseki[i-1], ans)

    print(ans)            




if __name__ == "__main__":
    solve()

Measured memory_bytes: 7188
// #define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = (ll)(x)-1;0 <= i; i--)
#define reps(i,x) for(ll i = 1; i < (ll)(x)+1; i++)
#define rreps(i,x) for(ll i = (ll)(x); 1 <= i; i--)
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const int n_max = 1e5+10;
#define int ll

void YES(bool ok){
    cout << (ok ? "No" : "Yes") << endl;
}

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    ll a,b; cin >> a >> b;
    ll c,d; cin >> c >> d;
    bool ok = true;
    ll turn = 0;
    while(a > 0 && c > 0){
        if(turn & 1)a -= d;
        else c -= b;
        turn++;
        // debug(a);debug(c);
    }
    if(c <= 0)ok = false;
    YES(ok);
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <utility>
using namespace std;
typedef long long int lli;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
char dir[] = "RDLU";
const int inf = 1e9;

int main(){
    int h,w,n;
    cin >> h >> w >> n;
    int sy,sx;
    cin >> sy >> sx;
    string s,t;
    cin >> s >> t;
    int rem[4] = {w-sx, h-sy, sx-1, sy-1};
    for(int d=0; d<4; d++){
        int curr = 0;
        for(int i=0; i<n; i++){
            if(dir[d] == s[i]) curr++;
            if(curr > rem[d]){
                cout << "NO" << endl;
                return 0;
            }
            if(dir[(d+2)%4] == t[i]){
                if(curr > -rem[(d+2)%4]) curr--;
            }
        }
    }
    cout << "YES" << endl;
    return 0;
}

Measured memory_bytes: 776
import collections
import math
import operator as op
from functools import reduce
import numpy as np
import math
import bisect
import heapq


MOD = 1000000007


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


def lcm(a, b):
    return a * b // gcd(a, b)


def get_inputs(cast_func=None):
    if cast_func is None:
        return input().split()
    else:
        return list(map(cast_func, input().split()))


def get_input(cast_func=None):
    if cast_func is None:
        return input()
    else:
        return cast_func(input())


def is_prime(n):
    if n == 1:
        return False
    for i in range(2, int(n**0.5)+1):
        if n % i == 0:
            return False
    return True


def main():
    # H, A = get_inputs(int)

    # ans = 0
    # while H > 0:
    #     H -= A
    #     ans += 1
    # print(ans)

    H, N = get_inputs(int)
    A = get_inputs(int)

    if sum(sorted(A)[-N:]) >= H:
        print('Yes')
    else:
        print('No')


    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 23012
#include<stdio.h>
int main()
{
  int i,n,k,atari,total,kai;

  for(i=0; i<10000; i++){
    scanf("%d",&n);

    if(n==0) break;

      kai=n/4;
      total=0;
      
      for(k=0; k<kai; k++){
	scanf("%d",&atari);

	total+=atari;
    }
    printf("%d\n",total);
  }
  return 0;
}

Measured memory_bytes: 600
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split("\n");
  
    var N = parseInt(input[0], 10);
	//文字列から10進数に変換するときはparseIntを使います
    var a = input[1].split(" ");
  
    var count = 0;
    var x = true;

    while(x == true){
      for(i=0; i<N; i++){
        var A = parseInt(a[i], 10);
         if((A) %2 == 1){
           x = false;
           break;
         }
         a[i] = a[i]/2;
      }
      if(x == true){
        count += 1;
      }
    }
	//出力
    console.log('%d', count);
}

//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
'use strict'
function main(input) {
    const tmp = input.split(' ');
    const PQR = tmp.map((t) => parseInt(t, 10));

    const longest = PQR.reduce((max, dist) => Math.max(max, dist));
    PQR.splice(PQR.indexOf(longest), 1);
    console.log(PQR.reduce((sum, dist) => sum + dist));

}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
  ll a,b,c;
  cin>>a>>b>>c;
  if(a==b&&a!=c||b==c&&b!=a||a==c&&a!=b)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
}

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

public class Main {

  public static void main(String[] args) throws IOException {
    
    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      int n = Integer.parseInt( br.readLine() );
      String[] line = br.readLine().split(" ");

      int[] a = new int[n];
      for (int i = 0; i < n; i++) {
        a[i] = Integer.parseInt(line[i]);
      }

      insertionSort(a, n);
    }
  }

  public static void insertionSort(int a[], int max) {
    for (int i=0,j=0,v=0; i < max; i++) {
      for( j = i-1, v = a[i]; j>=0 && a[j]>v; j-- ) {
        a[j+1] = a[j];
      }
      a[j+1] = v;
      dispIntArray(a);
    }
  }
  public static void dispIntArray(int a[]) {
    StringBuilder line = new StringBuilder(a.length*4);
    for (int i=0, max = a.length-1; i < max; i++) {
     line.append(a[i]).append(" ");
    }
    System.out.println( line.append(a[a.length-1]) );
  }
}


Measured memory_bytes: 26528
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author ExplodingFreeze
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
#define int long long
#define f(i,a,b) for(int i=(a);i<(b);i++)
const int MOD=1e9+7;
using pii=std::pair<int,int>;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); <-- PUT IN main()/solve()!

using namespace std;

int n,x[10],y[10];
class CAverageLength {
public:
	void solve(std::istream& in, std::ostream& out) {
		in >> n;
		f(i,0,n)
			in >> x[i] >> y[i];
		vector<int> order;
		f(i,0,n)
			order.push_back(i);
		int nfact=1;
		f(i,1,n+1)
			nfact*=i;
		double ans=0;
		do
		{
			f(i,0,n-1)
				ans+=getdist(order[i],order[i+1]);
		}while(next_permutation(order.begin(),order.end()));
		out << setprecision(12) << ans/nfact << "\n";
	}
	double getdist(int a, int b)
	{
		return sqrt(pow(x[a]-x[b],2)+pow(y[a]-y[b],2));
	}
};


int32_t main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	CAverageLength solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
/*jai_ganeshdeva*/

#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define pu push  //  adds the value to the last of the queue 
#define lld long long int
#define ins insert /// used in set to insert the values 
#define adv advance  /// used to increment the iterator
#define mp make_pair
#define fi first
#define se second
#define all(c) c.begin(),c.end()
#define PI 3.1415926
#define INF (lld)1e18
#define vl  vector<long long int >
#define vpll vector< pair<lld ,lld> >
#define vvl vector<vector<lld> > 
#define pll pair <lld,lld>
lld p1=1e9 + 7,p2=998244353;

void judge(){
    #ifndef ONLINE_JUDGE
    // for getting input from input.
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
    #endif
    
}

void fastio(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}


long long int modp(lld a,lld p,lld n)
{
    lld d[100];
    lld i,j,k,l;
    if(n==0) return 1;
    for(i=0;n>=1;i++)
    {
        d[i]=n%2;
        n/=2;
    }
    l=i;
    long long int e=1;
    if(d[0]==1) e*=(a%p);
    for(i=1;i<l;i++)
    {
        a*=a;
        a=a%p;
        if(d[i]==1) 
        {
            e*=a;
            e=e%p;
        }
    }
    return e%p;
}
lld modInverse(lld n, lld p) 
{ 
    return modp(n, p, p-2); 
}

// lld fac[500005]; 

// void getfac(lld p)
// {
//     fac[0] = 1; 
//     for (lld i=1 ; i<=500005; i++) 
//         fac[i] = fac[i-1]*i%p; 
// }    

// long long int nCrmodp(lld n, lld r,lld p) 
// { 
//    // Base case 
//    if (r==0) 
//       return 1; 
     
//     return (fac[n]* modInverse(fac[r], p) % p * 
//             modInverse(fac[n-r], p) % p) % p; 
// }


lld l,r,mid,ans=0;
lld n,i,j,k,g,m;
lld x,y,n1,n2,h,z,c;
lld aa=1;
lld ss=1;
void solve()
{  
    string s,t;
    cin>>s>>t;
    lld l1,l2;
    l1 =s.size();
    l2 = t.size();
    ans = l2;
    for(i=0;i<=(l1-l2);i++)
    {
        x=0;
        for(j=0;j<l2;j++)
        {
            if(s[i+j] != t[j]) x+=1;
        }
        ans = min(ans ,x);
    }
    cout<<ans;
}

int main()
{
    // judge();
    fastio();
    lld t=1;
    // cin>>t;
    // lld p1 = 1e9 + 7;
    // getfac(p1);
    for(int i=0;i<t;i++)
    {
        // cout<<"Case #"<<i+1<<": ";
        solve();
        // cout<<"\n";
    }
    return 0;
}


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

using namespace std;

#define forit(it, s) for(__typeof(s.begin()) it = s.begin(); it != s.end(); it++)
#define np(v) next_permutation(v.begin(), v.end())
#define pll pair < long long, long long>
#define all(a) a.begin(), a.end()
#define ull unsigned long long
#define vll vector <long long>
#define pii pair < int, int >
#define sz(a) (int)a.size()
#define sqr(x) ((x) * (x))
#define y1 stupid_cmath
#define vi vector <int>
#define pb push_back
#define mp make_pair
#define ll long long
#define f first
#define s second

const int inf = (int)1e9 + 100;
const int mod = (int)1e9 + 7;
const double eps = 1e-9;
const double pi = acos(-1.0);

int n;
int a[100100];
vector <int> v1, v2;
set <pii> s1, s2;
int cnt1[100100], cnt2[100100];

int main(){
    ios_base::sync_with_stdio(0), cin.tie(0);
	cin >> n;
	for(int i = 1; i <= n; ++i){
		cin >> a[i];
		if(i & 1) v1.pb(a[i]);
		else v2.pb(a[i]);
	}
	for(int i = 0; i < v1.size(); ++i){
		cnt1[v1[i]]++;
	}
	for(int i = 0; i < v1.size(); ++i){
		s1.insert(mp(cnt1[v1[i]], v1[i]));
	}
	for(int i = 0; i < v2.size(); ++i){
		cnt2[v2[i]]++;
	}
	for(int i = 0; i < v2.size(); ++i){
		s2.insert(mp(cnt2[v2[i]], v2[i]));
	}
	int x = s1.rbegin()->s;
	int y = s2.rbegin()->s;
	int ans = 0;
	if(x != y){
		for(int i = 0; i < v1.size(); ++i){
			if(v1[i] != x) ans++;
		}
		for(int i = 0; i < v2.size(); ++i){
			if(v2[i] != y) ans++;
		}
		cout << ans << endl;
		return 0;
	}
	s1.erase(mp(cnt1[x], x));
	s2.erase(mp(cnt2[y], y));
	if(s1.size() && s2.size()){
		int cur1 = 0, cur2 = 0, d1 = 0, d2 = 0;
		int xx = s1.rbegin()->s;
		int yy = s2.rbegin()->s;
		for(int i = 0; i < v1.size(); ++i){
			if(v1[i] != xx) cur1++;	
			if(v1[i] != x) d1++;
		}
		for(int i = 0; i < v2.size(); ++i){
			if(v2[i] != yy) cur2++;
			if(v2[i] != y) d2++;
		}
		ans = min(cur1 + d2, cur2 + d1);
		cout << ans << endl;
		return 0;
	}
	if(!s1.size() && s2.size()){
		int cur1 = 0, cur2 = 0, d1 = 0, d2 = 0;
		int yy = s2.rbegin()->s;
		for(int i = 0; i < v2.size(); ++i){
			if(v2[i] != yy) cur2++;
			if(v2[i] != y) d2++;
		}
		ans = min(n / 2 + d2, cur2);
		cout << ans << endl;
	}
	if(s1.size() && !s2.size()){
		int cur1 = 0, cur2 = 0, d1 = 0, d2 = 0;
		int xx = s1.rbegin()->s;
		for(int i = 0; i < v1.size(); ++i){
			if(v1[i] != xx) cur1++;
			if(v1[i] != x) d1++;
		}
		ans = min(n / 2 + d1, cur1);
		cout << ans << endl;
		return 0;
	}
	cout << n / 2 << endl;
}

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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(int i=0;i<n;++i)
#define ALL(name) name.begin(),name.end()
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 100010

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

    int N;
    cin >> N;

    double sum = 0;
    REP(i, N) {
        double a;
        cin >> a;
        sum += 1.0 / a;
    }

    printf("%.6f\n", 1.0 / sum);

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef long long ll;
const int N = 100005;
const ll INF = 1000000000000000000;
int x,y,z;
int n;
ii A[N];
ll l[N], r[N];
bool cmp(ii a, ii b){
    return a.first-a.second > b.first-b.second;
}
int main(){
    scanf("%d%d%d",&x,&y,&z);
    n = x+y+z;
    ll ans = 0;
    for (int i = 0; i < n; i++){
        int a,b,c;
        scanf("%d%d%d",&a,&b,&c);
        ans += c;
        A[i] = ii(a-c,b-c);
    }
    sort(A,A+n,cmp);
    priority_queue<int,vector<int> ,greater<int> > pq;
    ll sum = 0;
    for (int i = 0; i < n; i++){
        pq.push(A[i].first);
        sum += A[i].first;
        if (pq.size() > x){
            sum -= pq.top();
            pq.pop();
        }
        if (pq.size() == x) l[i] = sum;
        else l[i] = -INF;
    }
    while (pq.size()) pq.pop();
    sum = 0;
    for (int i = n-1; i >= 0; i--){
        pq.push(A[i].second);
        sum += A[i].second;
        if (pq.size() > y){
            sum -= pq.top();
            pq.pop();
        }
        if (pq.size() == y) r[i] = sum;
        else r[i] = -INF;
    }
    ll mx = -INF;
    for (int i = 0; i < n-1; i++){
        //printf("%lld %lld\n",l[i],r[i+1]);
        mx = max(mx,l[i]+r[i+1]);
    }
    printf("%lld",ans+mx);

}


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

int main(){
    int A,B,X;
    cin >> X >> A >> B;
    if(B-A > X){
        cout << "dangerous" << endl;
    }
    else if((B-A <= X)&&(B-A >0)){
        cout << "safe" << endl;
    }
    else if(B-A <= 0){
        cout << "delicious" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int h1, h2, k1, k2, a, b, c, d, hiroshi, kenjiro;
  scanf("%d %d %d %d", &h1, &h2, &k1, &k2);
  scanf("%d %d %d %d", &a, &b, &c, &d);
  hiroshi = h1*a + h2*b + (h1/10)*c + (h2/20)*d;
  kenjiro = k1*a + k2*b + (k1/10)*c + (k2/20)*d;

  if ( hiroshi > kenjiro ) printf("hiroshi\n");
  else if ( hiroshi < kenjiro ) printf("kenjiro\n");
  else printf("even\n");

  return 0;
}



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

using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
#define all(x) x.begin(), x.end()

template <typename T1, typename T2> inline void chkmin(T1 &x, const T2 & y) {if (x > y) x = y;}
template <typename T1, typename T2> inline void chkmax(T1 &x, const T2 & y) {if (x < y) x = y;}

void read() {
	int a, b, c;
	cin >> a >> b >> c;
	cout << c << " " << a << " " << b << endl;
}

void run() {

}

void write() {

}

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	read();
	run();
	write();
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int n, tail;
char group[128][1024];
char list[1024][1024];
char groupName[128][16];
char visited[128];

void insert(char *str)
{
    strcpy(list[tail++], str);
}


int notInList(char *str)
{
    int i;
    
    for (i = 0; i < tail; i++){
        if (strcmp(list[i], str) == 0){
            return (0);
        }
    }
    insert(str);
    
    return (1);
}
int countGroup(int vertex)
{
    int flag;
    int ans;
    int pos;
    int i;
    char node[16];
    
    pos = 0;
    
    while (group[vertex][pos] != ':'){
        pos++;
    }
    pos++;
    
    ans = 0;
    while (group[vertex][pos] != '.'){
        
        i = 0;
        while (group[vertex][pos] != ',' && group[vertex][pos] != '.'){
            node[i++] = group[vertex][pos++];
        }
        node[i] = '\0';
        
        flag = 1;
        for (i = 0; i < n; i++){
            if (strcmp(node, groupName[i]) == 0){
                flag = 0;
                if (visited[i] == 0){
                    visited[i] = 1;
                    ans += countGroup(i);
                }
            }
        }
        if (flag && notInList(node)){
            ans++;
        }
        if (group[vertex][pos] != '.'){
            pos++;
        }
    }
    
    return (ans);
}

int main(void)
{
    int i, j;
    
    while (1){
        scanf("%d", &n);
        
        if (n == 0){
            break;
        }
        
        memset(list, 0, sizeof(list));
        memset(visited, 0, sizeof(visited));
        tail = 0;
        
        for (i = 0; i < n; i++){
            scanf("%s", group[i]);
            
            j = 0;
            while (group[i][j] != ':'){
                groupName[i][j] = group[i][j];
                j++;
            }
            groupName[i][j] = '\0';
        }
        
        visited[0] = 1;
        printf("%d\n", countGroup(0));
        
    }
    
    return (0);
}

Measured memory_bytes: 0
import java.util.Scanner;

/**
 * @program: leetcode
 * @description:
 * @author: wangtengke
 * @create: 2019-06-16
 **/
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        long w = scanner.nextInt();
        long h = scanner.nextInt();
        int x = scanner.nextInt();
        int y = scanner.nextInt();
        System.out.print((double)(h*w)/2 + " ");
        if(w==2*x && h==2*y) {
            System.out.println("1");
        }
        else System.out.println("0");
    }

}


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

int main() {
	using namespace std;
	ios_base::sync_with_stdio(false), cin.tie(nullptr);
	int N; cin >> N;
	struct constraint {
		bool z;
		uint64_t v;
	};
	vector<constraint> rows[2] = {vector<constraint>(N), vector<constraint>(N)};
	for (int d = 0; d < 2; d++) {
		for (int i = 0; i < N; i++) {
			cin >> rows[d][i].z;
		}
	}

	for (int d = 0; d < 2; d++) {
		for (int i = 0; i < N; i++) {
			cin >> rows[d][i].v;
		}
	}

	auto id = [](bool z) -> uint64_t { return z ? uint64_t(0) : ~uint64_t(0); };
	auto op = [](bool z, uint64_t a, uint64_t b) -> uint64_t { return z ? (a | b) : (a & b); };

	uint64_t accum[2][2] = {{id(0), id(1)}, {id(0), id(1)}};
	for (int d = 0; d < 2; d++) {
		for (int i = 0; i < N; i++) {
			for (int z = 0; z < 2; z++) {
				accum[d][z] = op(z, accum[d][z], rows[d][i].v);
			}
		}
	}

	vector<bool> parity[2] = {vector<bool>(N), vector<bool>(N)};
	for (int d = 0; d < 2; d++) {
		bool cur_parity[2] = {true, true};
		for (int i = 0; i < N; i++) {
			parity[d][i] = (cur_parity[rows[d][i].z] ^= 1);
		}
	}

	auto get_cell = [&](int i, int j) -> uint64_t {
		const auto& [rz, rv] = rows[0][i];
		const auto& [cz, cv] = rows[1][j];
		if (rz == cz) {
			return op(!rz, rv, cv);
		} else {
			if (parity[0][i] ^ parity[1][j]) {
				return op(!cz, cv, op(!rz, ~accum[0][cz], rv));
			} else {
				return op(!rz, rv, op(!cz, ~accum[1][rz], cv));
			}
		}
	};

	vector<vector<uint64_t>> ans(N, vector<uint64_t>(N));
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			ans[i][j] = get_cell(i, j);
		}
	}

	vector<uint64_t> ansVal[2] = {vector<uint64_t>(N), vector<uint64_t>(N)};
	for (int d = 0; d < 2; d++) {
		for (int i = 0; i < N; i++) {
			ansVal[d][i] = id(rows[d][i].z);
		}
	}
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			ansVal[0][i] = op(rows[0][i].z, ansVal[0][i], ans[i][j]);
			ansVal[1][j] = op(rows[1][j].z, ansVal[1][j], ans[i][j]);
		}
	}
	for (int d = 0; d < 2; d++) {
		for (int i = 0; i < N; i++) {
			if (ansVal[d][i] != rows[d][i].v) {
				cout << -1 << '\n';
				exit(0);
			}
		}
	}

	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			cout << ans[i][j] << " \n"[j+1==N];
		}
	}

	return 0;
}


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

using ll = long long;

constexpr ll MOD = 1e9+7;
constexpr ll INF = 1ll<<60;

#define FOR(i,a,b) for (ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

char F[2010][2010];
ll L[2010][2010];
ll R[2010][2010];
ll U[2010][2010];
ll D[2010][2010];

int main(int argc, char **argv)
{
	ll H, W; cin >> H >> W;
	REP(h, H)REP(w, W) cin >> F[h][w];

	REP(h, H)
	{
		REP(w, W)
		{
			if (F[h][w] == '#')
				L[h][w] = 0;
			else
			{
				if (w == 0)
					L[h][w] = 1;
				else
					L[h][w] = L[h][w-1] + 1;
			}
		}

		for (ll w = W-1; w >= 0; --w)
		{
			if (F[h][w] == '#')
				R[h][w] = 0;
			else
			{
				if (w == W-1)
					R[h][w] = 1;
				else
					R[h][w] = R[h][w+1] + 1;
			}
		}
	}

	REP(w, W)
	{
		REP(h, H)
		{
			if (F[h][w] == '#')
				U[h][w] = 0;
			else
			{
				if (h == 0)
					U[h][w] = 1;
				else
					U[h][w] = U[h-1][w] + 1;
			}
		}

		for (ll h = H-1; h >= 0; --h)
		{
			if (F[h][w] == '#')
				D[h][w] = 0;
			else
			{
				if (h == H-1)
					D[h][w] = 1;
				else
					D[h][w] = D[h+1][w] + 1;
			}
		}
	}

	ll res{0};
	REP(h, H)REP(w, W)
	{
		res = max(res, U[h][w] + D[h][w] + R[h][w] + L[h][w] - 3);
	}

	std::cout << res << std::endl;
}


Measured memory_bytes: 130432
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
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> void drop(const T &x){cout<<x<<endl;exit(0);}

//INSERT ABOVE HERE
signed main(){
  string s;
  cin>>s;
  for(int i=0;i<(int)s.size();i++){
    if(~i&1) if(s[i]=='L') drop("No");
    if( i&1) if(s[i]=='R') drop("No");
  }
  drop("Yes");
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <limits.h>
#include <vector>
#include <queue>

using namespace std;

struct Node {
    int id;
    int cost;
    bool done;
    vector<int> next_node;
    vector<int> len_cost;

    bool operator<(const Node& right) const {
        return cost > right.cost;
    }
} node[10000];

int main() {
    int n, id, k;

    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> id >> k;
        node[id].id = id;
        node[id].cost = INT_MAX;
        node[id].done = false;
        node[id].next_node.resize(k);
        node[id].len_cost.resize(k);
        for (int j = 0; j < k; j++) {
            cin >> node[id].next_node[j] >> node[id].len_cost[j];
        }
    }

    priority_queue<Node> q;
    node[0].cost = 0;
    q.push(node[0]);
    while (!q.empty()) {
        Node temp = q.top();
        q.pop();

        if (temp.done == true) {
            continue;
        }
        node[temp.id].done = true;

        for (int i = 0; i < temp.next_node.size(); i++) {
            int to = temp.next_node[i];
            int cost = temp.cost + temp.len_cost[i];
            if (node[to].cost > cost) {
                node[to].cost = cost;
                if (node[to].done == false) {
                    q.push(node[to]);
                }
            }
        }
    }

    for (int i = 0; i < n; i++) {
        cout << i << " " << node[i].cost << endl;
    }
    
    return 0;
}

Measured memory_bytes: 39272
#include <bits/stdc++.h>
using namespace std;
#define Rep(i,N) for(int i = 0; i < N; i++)
#define INF 1 << 28
#define S second
#define F first
typedef pair<int,int> Pi;

inline void chmax(int &a, int b) { a = max(a,b); }
inline void chmin(int &a, int b) { a = min(a,b); }

int main()
{
  int N;
  int A, B, C;
  int topi[105];
  cin >> N >> A >> B >> C;
  Rep(i,N) cin >> topi[i];
  sort( topi, topi + N, greater<int>() );
  int sum = C;
  int maxv = C / A;
  Rep(i,N) {
    sum += topi[i];
    chmax(maxv,sum / (A + (i + 1) * B));
  }
  cout << maxv << endl;
  return 0;
}

Measured memory_bytes: 3128
#include <stdio.h>

int main()
{
    int a[3], b[3], c[9];
    int flag = 0;
    int i, j;

    for(i=0; i<9; i++)
    {
        scanf("%d", &c[i]);
    }

    for(i=c[0]; i >= 0; i--)
    {
        a[0] = i;
        b[0] = c[0] - a[0];
        b[1] = c[1] - a[0];
        b[2] = c[2] - a[0];
        a[1] = c[3] - b[0];
        a[2] = c[6] - b[0];
        if(a[1], a[2], b[0], b[1], b[2]>=0)
        {
            if(a[1]+b[1]==c[4] && a[1]+b[2]==c[5]
            && a[2]+b[1]==c[7] && a[2]+b[2]==c[8])
            {
                flag = 1;
            }
        }
    }

    if(flag == 1)
    {
        printf("Yes\n");
    }
    else
    {
        printf("No\n");
    }
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    string s;
    cin >> s;
    int n = s.size();
    vector<vector<ll>> dp(n, vector<ll>(2, 0));
    dp[0][0] = 2;
    dp[0][1] = 1;
    ll mod = 1000000007;
    for(int i = 1; i < n; i++){
        if(s[i] == '0'){
            dp[i][0] = dp[i-1][0];
            dp[i][1] = dp[i-1][1] * 3 % mod;
        }else{
            dp[i][0] = dp[i-1][0] * 2 % mod;
            dp[i][1] = dp[i-1][0] + dp[i-1][1] * 3 % mod;
            dp[i][1] %= mod;
        }
    }
    cout << (dp[n-1][0] + dp[n-1][1]) % mod << endl;
}

Measured memory_bytes: 5760
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define MP make_pair
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define PLI pair<ll, int>
#define PIL pair<int, ll>
#define STR string
#define Fst first
#define Snd second
#define SHN 1e9
#define LSHN 1e18
using namespace std;
char c;
int main()
{
	cin >>c;
	if (isupper(c)) cout <<"A";
	else cout <<"a";
	return 0;
} 

Measured memory_bytes: 3592
import sys

stdin = sys.stdin

ns = lambda : stdin.readline().rstrip()
ni = lambda : int(ns())
na = lambda : list(map(int, stdin.readline().split()))
sys.setrecursionlimit(10 ** 7)

def main():
    a, b, k = na()

    newa = max(0, a - k)
    k = max(0, k - a)
    
    print(newa, max(0, b-k))

if __name__ == '__main__':
    main()

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

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


Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import numpy


def main():
  n, _, c = map(int, input().split())
  b = numpy.array(list(map(int, input().split())), dtype=numpy.int32)
  a = [numpy.array(list(map(int, input().split())), dtype=numpy.int32) for _ in range(n)]
  z = 0

  for x in a:
    if numpy.sum(x * b) + c > 0:
      z += 1

  print(z, flush=True)


if __name__ == '__main__':
  main()



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

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define MOD 1000000007
#define el endl
#define INF 1e8
typedef long long ll;
typedef long double ld;

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



Measured memory_bytes: 256
require 'pp'

# 入力値を数値で返却する
def gets_i()
  gets.chomp.to_i
end

# 空白区切の入力値を数値の配列で返却する
def gets_i_list()
  gets.chomp.split(" ").map(&:to_i)
end

N = gets_i
a_list = gets_i_list

count = 0
type = 0

a_list.each_with_index do |a, i|
  next_a = a_list[i+1]
  break if next_a.nil?
  case type
  when 0
    type = next_a <=> a
  when -1
    # 減少
    if next_a <= a
      next
    else
      count += 1
      type = 0
    end
  when 1
    # 増加
    if next_a >= a
      next
    else
      count += 1
      type = 0
    end
  end
end

puts count + 1


Measured memory_bytes: 9736
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <iomanip>

using namespace std;

int main(void){
    int A[5],k;
    for(int i=0;i<5;i++){
        cin >> A[i];
    }
    cin >> k;
    for(int i=0;i<5;i++){
        for(int j=0;j<5;j++){
            if(abs(A[i] - A[j]) > k){
                cout << ":(" << endl;
                return 0;
            }
        }
    }
    cout << "Yay!" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int a[N];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    sort(a+1,a+1+n);
    if(a[1]==a[n]&&a[1]==0||n%3==0&&(a[1]^a[n/3+1]^a[n])==0&&a[1]==a[n/3]&&a[n/3+1]==a[n/3*2]&&a[n/3*2+1]==a[n]) printf("Yes\n");
    else printf("No\n");
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(false), cout << fixed << setprecision(20);
#define int long long
#define gcd __gcd
#define all(x) (x).begin(), (x).end()
template<class T>
bool chmax(T& a, T b){return (a = max(a, b)) == b;}
template<class T>
bool chmin(T& a, T b){return (a = min(a, b)) == b;}
#define _overload(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(...) _overload(__VA_ARGS__, repi, _rep)(__VA_ARGS__)
#define _rev(i, n) revi(i, n, 0)
#define revi(i, a, b) for(int i = (int)(a - 1); i >= (int)(b); i--)
#define rev(...) _overload(__VA_ARGS__, revi, _rev)(__VA_ARGS__)
#define each(i, n) for(auto&& i: n)
const int INF = 1e18, MOD = 1e9 + 7;
signed main() {
    INCANT;
    int n[4];
    cin>>n[0]>>n[1]>>n[2]>>n[3];
    sort(n, n + 4);
    if(n[0] != n[1] || n[2] != n[3]){
        cout<<"no"<<endl;
    }else{
        cout<<"yes"<<endl;
    }
}



Measured memory_bytes: 3148
s = input()

t, a = 0, 1
mod = [0]*2019
mod[0] = 1
s = s[::-1]
n = len(s)
for i in range(n):
    t += int(s[i]) * a
    t %= 2019
    a *= 10  #a *= 2019 <- TLE
    a %= 2019
    mod[t] += 1
ans = 0

for i in range(2019):
    ans += mod[i]*(mod[i]-1)//2
print(ans)

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

c = [[0]*(10) for _ in range(10)]

for k in range(1, n+1):
    h = int(str(k)[0])
    t = int(str(k)[-1])
    c[h][t] += 1

ans = 0
for i in range(0, 10):
    for j in range(0, 10):
        ans += c[i][j]*c[j][i]

print(ans)


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

using namespace std;

#define MAX 1000000
#define SQRT 1000

bool np[MAX];

int main()
{
    np[0] = np[1] = true;
    for(int p=2; p<SQRT; p++)
    {
        if(!np[p])
        {
            for(int i=2*p; i<MAX; i+=p) np[i] = true;
        }
    }

    int a, d, n;
    while(cin >> a >> d >> n, a|d|n)
    {
        for(int x=a; n;x+=d)
        {
            if(!np[x] && !--n)
            {
                cout << x << endl;
            }
        }
    }
}

Measured memory_bytes: 4020
#include<bits/stdc++.h>
using namespace std;
int INF=1e9;
int s,n,m,t,p;
int x[2000];
vector<int> A;
int dp[2005][2005];
int mem[2005][2005];

int main(){
  scanf("%d %d %d",&s,&n,&m);
  for(int i=0;i<s;i++)scanf("%d",&x[i]);
  for(int i=0;i<n;i++){
    scanf("%d %d",&t,&p);
    A.push_back(t-x[p-1]);
  }
  A.push_back(-INF);
  sort(A.begin(),A.end());
  A[0]=0;

  int size=A.size()-1,base=A[1];
  for(int i=1;i<=size;i++)A[i]-=base;
  fill(dp[1],dp[2005],1e9);
  for(int i=1;i<=size;i++){ 
    for(int j=1;j<=m;j++){
      int sum=0;
      for(int k=i-1;k>=mem[i][j-1];k--){
        if(dp[i][j]>dp[k][j-1]+sum){
          dp[i][j]=dp[k][j-1]+sum;
          mem[i][j]=k;
        }
        sum+=(A[i]-A[k]);
        if(sum>dp[i][j])break;
      }
    }
  }
  cout<<dp[size][m]<<endl;
  return 0;
}

Measured memory_bytes: 32624
#include <iostream>
#include <cmath>
#include <limits>

using namespace std;

int main(void)
{
  int n,k;
  cin >> n >> k;

  double a = (1.0/n);
  double f = 0.0;
  for(int i = 1; i <= n; ++i) {
    int r = k%i ? (k/i) + 1 : (k/i);
    int l = log2(r) + 0.999999999 ;
    double z = a * pow(0.5, l);
    f += z;
  }
 
  cout.precision(20); 
  cout << f << endl;
  return 0;
}


Measured memory_bytes: 256
line = input()
niti = line.split()
linit_time = int(niti[0])


line2 = input()
time =line2.split()
total_time =0

for i in range(int(niti[1])):
  total_time +=int(time[i])

if linit_time - total_time < 0:
  print(-1)
else:
  print(linit_time - total_time)

Measured memory_bytes: 9688
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

ll dfs(ll h, ll w, ll ch, ll cw, ll dh, ll dw, vector<string> &s){
    // {{y, x}, ワープ回数
    deque<pair<pair<ll, ll>, ll>> que;
    
    que.push_front(make_pair(make_pair(ch, cw), 0));
    
    // 最小壁抜け回数（-1なら未訪問）
    vvi chk(h, vi(w, -1));
    chk[ch][cw] = 0;

    // 4方向（左、右、上、下）（左上を0, 0とした場合）
    vector<long long> dx = {-1, 1, 0, 0};
    vector<long long> dy = { 0, 0,-1, 1};

    // warp
    vector<long long> wdx = {-2, -1, 0, 1, 2, -2, -1, 1, 2, -2, 2, -2, -1, 1, 2, -2, -1, 0, 1, 2};
    vector<long long> wdy = {2, 2, 2, 2, 2, 1, 1, 1, 1, 0, 0, -1, -1, -1, -1, -2, -2, -2, -2, -2};

    while(que.size()){
        auto f = que.front();
        que.pop_front();
        // 場所と壁抜け回数
        ll y = f.first.first;
        ll x = f.first.second;
        ll cnt = f.second;
        if(chk[y][x] < cnt) continue;

        // 移動1
        ll dcnt = 0;
        for(ll d=0; d<4; d++){
            ll tx = x + dx[d];
            ll ty = y + dy[d];
            if(tx < 0 || ty < 0 || tx >= w || ty >= h) continue;
            if(s[ty][tx] == '#') continue;
            if(chk[ty][tx] > cnt || chk[ty][tx] == -1){
                chk[ty][tx] = cnt;
                que.push_front(make_pair(make_pair(ty, tx), cnt));
            }
        }

        // 移動2
        for(ll d=0; d<20; d++){
            ll tx = x + wdx[d];
            ll ty = y + wdy[d];
            if(tx < 0 || ty < 0 || tx >= w || ty >= h) continue;
            if(s[ty][tx] == '#') continue;
            if(chk[ty][tx] > cnt+1 || chk[ty][tx] == -1){
                chk[ty][tx] = cnt+1;
                que.push_back(make_pair(make_pair(ty, tx), cnt+1));
            }
        }
    }
    return chk[dh][dw];
}

int main(){
    Init();
    ll h, w, ch, cw, dh, dw;
    cin >> h >> w >> ch >> cw >> dh >> dw;
    ch--, cw--, dh--, dw--;
    vector<string> s(h);
    rep(i, h) cin >> s[i];

    // スタート地点がch, cw　ゴールがdh, dw;
    cout << dfs(h, w, ch, cw, dh, dw, s) << endl;
}

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

using namespace std;
using ll = long long int;
constexpr ll M = 1e9 + 7;
inline ll sum_1(const ll n) { return ((n * (n + 1)) / 2) % M; }
inline ll sum_2(const ll n) { return ((n * (n + 1) * (2 * n + 1)) / 6) % M; }
inline ll sum_3(const ll n) { return (((n * (n + 1)) / 2) % M * ((n * (n + 1)) / 2) % M) % M; }
inline ll sum_1(const ll i, const ll j) { return (sum_1(j) - sum_1(i - 1) + M) % M; }
inline ll sum_2(const ll i, const ll j) { return (sum_2(j) - sum_2(i - 1) + M) % M; }
inline ll sum_3(const ll i, const ll j) { return (sum_3(j) - sum_3(i - 1) + M) % M; }

ll pow_f(ll b, ll e) {
    ll ans = 1;
    b = b % M;
    while (e) {
        if (e&1) {
            ans = (ans * b) % M;
        }
        b = (b * b) % M;
        e >>= 1;
    }
    return ans;
}

ll nCr(ll n, ll r) {
    if (r > n || n < 0 || r < 0) { return 0; }
    if (n == r || r == 0) { return 1; }
    r = min(r, n-r);
    ll ans = 1;
    for (ll i = 1; i <= r; ++i) {
        ans = (ans * (n-i+1))/(i); 
    }
    return ans;
}

ll nCr(tuple<ll,ll> t) {
    auto n = get<0>(t);
    auto k = get<1>(t);
    return nCr(n+k-1, k);
}

void solve() {
    int s, w;
    cin >> s >> w;
    if (w >= s) {
        cout << "unsafe" << endl;
    } else {
        cout << "safe" << endl;
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    #ifdef D_LOCAL
        freopen("in.in", "r", stdin);
        freopen("out.out", "w", stdout);
    #endif

    solve();

    return 0;
}

Measured memory_bytes: 3676
#include <bits/stdc++.h>   
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll mod = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
     
ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * B / gcd(A, B);
}
template <typename T>
T pow(T a, ll n, T e = 1) {
    T ret = e;
    while (n) {
        if (n & 1) ret *= a;
        a *= a;
        n >>= 1;
    }
    return ret;
}
 
template <int mod>
struct ModInt {
    int x;
    ModInt() : x(0) {}
    ModInt(long long x_) {
        if ((x = x_ % mod + mod) >= mod) x -= mod;
    }
    ModInt& operator+=(ModInt rhs) {
        if ((x += rhs.x) >= mod) x -= mod;
        return *this;
    }
    ModInt& operator-=(ModInt rhs) {
        if ((x -= rhs.x) < 0) x += mod;
        return *this;
    }
    ModInt& operator*=(ModInt rhs) {
        x = (unsigned long long)x * rhs.x % mod;
        return *this;
    }
    ModInt& operator/=(ModInt rhs) {
        x = (unsigned long long)x * rhs.inv().x % mod;
        return *this;
    }
 
    ModInt operator-() const { return -x < 0 ? mod - x : -x; }
    ModInt operator+(ModInt rhs) const { return ModInt(*this) += rhs; }
    ModInt operator-(ModInt rhs) const { return ModInt(*this) -= rhs; }
    ModInt operator*(ModInt rhs) const { return ModInt(*this) *= rhs; }
    ModInt operator/(ModInt rhs) const { return ModInt(*this) /= rhs; }
    bool operator==(ModInt rhs) const { return x == rhs.x; }
    bool operator!=(ModInt rhs) const { return x != rhs.x; }
    ModInt inv() const { return pow(*this, mod - 2); }
 
    friend ostream& operator<<(ostream& s, ModInt<mod> a) {
        s << a.x;
        return s;
    }
    friend istream& operator>>(istream& s, ModInt<mod>& a) {
        s >> a.x;
        return s;
    }
};
 
using mint = ModInt<1000000007>;
using Graph = vector<vector<int>>;
Graph G;
/*------------------------------------------------------------------*/
vector<int> memo;

int dp(const Graph &G, int v){
    if(memo[v] != -1) return memo[v];
    int res = 0;
    for(auto next_v : G[v]){
        res = max(res, dp(G, next_v) + 1);
    }
    return memo[v] = res;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n, m; cin >> n >> m;
    Graph G(n);
    rep(i, m){
        int a, b; cin >> a >> b;
        a--, b--;
        G[a].push_back(b);
    }
    memo.resize(n, -1);
    int ans = 0;
    rep(i, n) ans = max(ans, dp(G, i));
    cout << ans << endl;
}

Measured memory_bytes: 10908
#include <bits/stdc++.h>
using namespace std;
typedef  long long LL;
typedef  unsigned long long ULL;
typedef  double db;
typedef  long double ld;
#pragma comment(linker, "/STACK:102400000,102400000")
#define fuck(x) cout<<x<<endl
#define fuck1(x,y) cout<<x<<" "<<y<<endl
#define lson root<<1,l,mid
#define rson root<<1|1,mid+1,r
#define MP(a,b) make_pair(a,b)
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define MP make_pair
#define se second
#define fi first
#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
const int INF = 0x3f3f3f3f3f,mod = 1e9+7;
const double eps  =1e-6,PI = acos(-1);
template<typename T> inline void read(T &x){
    x=0;T f=1;char ch;do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');do x=x*10+ch-'0',ch=getchar();while(ch<='9'&&ch>='0');x*=f;
}
int N,L;
int main(){
    cin>>N>>L;
    int ans = 0;
    for(int i = 1;i<=N;i++)ans+=L+i-1;
    int err = INF,fina = 0;
    for(int i = 1;i<=N;i++){
        int ans1 = 0;
        for(int j = 1;j<=N;j++){
            if(i==j)continue;
            ans1+=L+j-1;
        }
        //cout<<ans1<<endl;
        if(abs(ans-ans1)<err){
            err = abs(ans-ans1);
            fina = ans1;
        }
    }
    cout<<fina<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <string>
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <math.h>
 
using namespace std;
int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
 
    int x,y;
    cin >> x >> y;
    if(4*x<y){
      cout << "No";
      return 0;
    }
    if(2*x>y){
      cout << "No";
      return 0;
    }
    if(y%2==1){
      cout << "No";
      return 0;
    }
   int z = (4*x-y)/2;
   int p = (y-2*x)/2;
    if(2*z+4*(x-z)==y){
      cout << "Yes";
      return 0;
    }else if(4*p+2*(x-p)==y){
      cout << "Yes";
      return 0;
    }else{
      cout << "No";
      return 0;
    }
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std ;
int main()
{
    int a , b, c , k  , g, l ,j;
    cin>> a>>b>>c >>k ;
    g=max(a,b);
    l=max(b,c);
    j=max(g,l);
    cout << c+b+a-j+ j*pow(2,k);

    return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<vector>
using namespace std;


int solve(){
  map<string, int> mp;
  int n;  cin >> n;
  for(int i=0; i<n; i++){
    string s; cin >> s;
    mp[s]++;
  }
  int mv = 0;
  for(auto it=mp.begin(); it!=mp.end(); it++){
    mv = max(mv, it->second);
  }
  for(auto it=mp.begin(); it!=mp.end(); it++){
    if(mv==it->second) cout << it->first << endl;
  }
  return 0;
}

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


Measured memory_bytes: 25216
#define _USE_MATH_DEFINES
#include <iostream>
#include <stdio.h>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <math.h>
#include <complex>
#include <cassert>
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define case(i) cout<<"Case #"<<i<<": "
using namespace std;
typedef long long int ll;
typedef complex<double> com;
const int mod = 1e9 + 7;
const int MOD = 998244353;
const ll INF = 4e18;

int gcd(int x, int y) {
	while (true) {
		if (x < y) swap(x, y);
		if (!y) break;
		x %= y;
	}
	return x;
}

int main(){
	int n; cin >> n;
	vector<int> a(n),b,c;
	rep(i, 0, n) cin >> a[i];
	int g = a[n - 1]; c.push_back(g);
	rep(i, 1, n-1) {
		int idx = n - 1 - i;
		g = gcd(g, a[idx]);
		c.push_back(g);
	}
	reverse(c.begin(), c.end());
	b.push_back(c[0]);
	g = a[0]; b.push_back(a[0]);
	rep(i, 1, n - 1) {
		g = gcd(g, a[i]);
		b.push_back(g);
	}
	c.push_back(*b.rbegin());
	int ans = 0;
	rep(i, 0, n) {
		ans = max(ans, gcd(b[i], c[i]));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1784
#include <iostream>
using namespace std;
#include<string>
#define ll long long

#define fr(i,a,b) for(ll i=a;i<b;i++)
#define ffr(i,a,b) for(ll i=a;i>=b;i--)
#include<bits/stdc++.h>
#include<vector>
#define vl vector<ll>
//const ll N=1e5+5;




int main(){
    ll x,n;
    cin>>x>>n;
    ll y=x;
    map<ll,ll> ml;
    ll p[n];
    fr(i,0,n){
        cin>>p[i];
        ml[p[i]]++;
    }
    ml[x]++;
    if(n==0||ml[x]==1)
    cout<<x;
    else{
        while(1){
            x--;
            y++;
            ml[x]++;
            ml[y]++;
            if(ml[x]==1){
               cout<<x;
               break;
            }
            if(ml[y]==1){
                cout<<y;
                break;
            }
        }
    }
	return 0;
}

Measured memory_bytes: 3636
import java.util.Scanner;

public class Main { 
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String[] line = sc.nextLine().split(" ");
		int age = Integer.parseInt(line[0]);
		int price = Integer.parseInt(line[1]);
		
		int result =0 ;
		if(age <= 5) {
			result = 0;
		}else if(6<= age && age <= 12) {
			result = price/2;
		}else if(13 <= age) {
			result = price;
		}
		
		System.out.println(result);

		
		
		
	}
}
	
	

Measured memory_bytes: 21844
#include <stdio.h>
#include <iostream>
#include <fstream>
#include <queue>
#include <algorithm>
#include <functional>
#include <vector>

using std::cin;
using std::cout;
using std::endl;
using std::terminate;
using std::priority_queue;
using std::sort;
using std::greater;
using std::vector;

void solve() {
    long X, Y, A, B, C; cin >> X >> Y >> A >> B >> C;
    long p[A];
    for (int i = 0; i < A; ++i) {
        cin >> p[i];
    }
    sort(p, p + A, greater<long>());

    long q[B];
    for (int i = 0; i < B; ++i) {
        cin >> q[i];
    }
    sort(q, q + B, greater<long>());

    long r[C];
    for (int i = 0; i < C; ++i) {
        cin >> r[i];
    }
    sort(r, r + C, greater<long>());

    priority_queue<
        long,
        vector<long>,
        greater<long> > quex;
    for (int i = 0; i < X; ++i) {
        quex.push(p[i]);
    }

    priority_queue<
        long,
        vector<long>,
        greater<long> > quey;
    for (int i = 0; i < Y; ++i) {
        quey.push(q[i]);
    }

    for (int i = 0; i < C; ++i) {
        int x = quex.top();
        int y = quey.top();
        if (x > y) {
            if (r[i] > y) {
                quey.pop();
                quey.push(r[i]);
            } else {
                break;
            }
        } else {
            if (r[i] > x) {
                quex.pop();
                quex.push(r[i]);
            }
        }
    }

    long ans = 0;
    for (int i = 0; i < X; ++i) {
        ans += quex.top(); quex.pop();
    }
    for (int i = 0; i < Y; ++i) {
        ans += quey.top(); quey.pop();
    }

    cout << ans << endl;

}

int main() {

#ifdef DEV
    std::ifstream in("input");
    cin.rdbuf(in.rdbuf());

    int t; cin >> t;
    for (int x = 1; x <= t; ++x) {
        solve();
    }
#else
    solve();
#endif

    return 0;
}


Measured memory_bytes: 7972
#include<stdio.h>
int main(void)
{
	int k,x,i;
	scanf("%d %d", &k, &x);
	i=x-k+1;
	while(i<x+k)
	{
		printf("%d", i);
		i++;
		if(i<x+k)
		printf(" ");
		else
		printf("\n");
	}
	
	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>

int dp[50];

int fib(int n){
  if(n==0||n==1)return dp[n]=1;
  if(dp[n]!=-1)return dp[n];
  return dp[n]=fib(n-1)+fib(n-2);
}

int main()
{
  int n=0,i;
  for(i=0;i<50;i++) dp[i]=-1;
  
  scanf("%d",&n);
  printf("%d\n",fib(n));

  return 0;
}




Measured memory_bytes: 2112